MTK调试-马达
1、流程步骤
1.1 代码路径和分析:
\alps\wingcust\prj\base\custom\kernel\vibrator\vibrator\cust_vibrator.c
\alps\mediatek\platform\mt6572\kernel\driver\vibrator.c
\alps\hardware\libhardware\libhardware_legacy\vibrator.c
\alps\framworks\base\services\jni\com_android_server_VibratorService.cpp
\alps\framworks\base\services\java\com\android\server\ VibratorService.java
1)在 \alps\wingcust\prj\base\custom\kernel\vibrator\vibrator\cust_vibrator.c
static struct vibrator_hw cust_vibrator_hw =
{
.vib_timer = 50, // <=== 请根据需要加大这个时间, 适当延长震动的时间
.vib_limit = 10, // <=== 限制的最短时间
.vosel = VOL_2800, // <=== 请根据马达的物理spec,设置此电压 82 92平台直接使用的是数字 0 表示 1.2v ,1表示 1.3v ,2便是1.5V,3表示1.8V,4表示2.0V,5表示2.8V,6表示3.0V,7表示3.3V。
}
2)在 \alps\mediatek\platform\mt6572\kernel\driver\vibrator.c中,创建一个workqueue,workqueue管理马达的打开与关闭。注册了timed_output_dev, 就生成了/sys/class/timed_output/vibrator/enable节点。通过对/sys/class/timed_output/vibrator/enable节点的控制来控制马达。在\alps\hardware\libhardware\libhardware_legacy\vibrator.c 的vibrator_on,vibrator_off 中sendit函数通过向节点写值(时间参数)/sys/class/timed_output/vibrator/enable,来控制马达。在frameworks/base/services/java/com/android/server/VibratorService.java通过调用VibratorService JNI来实现com.android.server包中的VibratorService类。
1.2 调试与修改:
1)如果硬件将gpio不接在MTK参考设计的gpio上,就需要修改对应的代码。首先,在dct工具中选择对应的gpio,设置对应的模式为GPIO,输出,默认下拉等,最后定义相应的名字GPIO_VIBRATOR_ENABLE_PIN。
#ifdef WT_VIBRATOR_ENABLE_BY_GPIO
static void gpio_vibrator_enable(void)
{
mt_set_gpio_mode(GPIO_VIBRATOR_ENABLE_PIN,GPIO_VIBRATOR_ENABLE_PIN_M_GPIO);
mt_set_gpio_dir(GPIO_VIBRATOR_ENABLE_PIN,GPIO_DIR_OUT);
mt_set_gpio_out(GPIO_VIBRATOR_ENABLE_PIN,GPIO_OUT_ONE);
}
static void gpio_vibrator_disable(void)
{
mt_set_gpio_mode(GPIO_VIBRATOR_ENABLE_PIN,GPIO_VIBRATOR_ENABLE_PIN_M_GPIO);
mt_set_gpio_dir(GPIO_VIBRATOR_ENABLE_PIN,GPIO_DIR_OUT);
mt_set_gpio_out(GPIO_VIBRATOR_ENABLE_PIN,GPIO_OUT_ZERO);
}
#endif
这样,只需要把对应的马达的enable和disable函数换成 gpio_vibrator_enable,gpio_vibrator_disable就可以了。
2)调试:可以/sys/class/timeadb 对d_output/vibrator/enable赋值,这个值是震动的时间,如果可以震动,那说明下层对马达的操作有效果。可以让mmi检查上层。如果无效,则打log
<4>[ 1535.254095] (0)[560:InputReader][vibrator]vibrator_enable: vibrator first in value = 0
<4>[ 1535.255091]-(0)[560:InputReader][vibrator]vibrator_enable: shutdown_flag = 0
<4>[ 1535.255965] (0)[560:InputReader][vibrator]vibrator_enable: vibrator start: 0
<4>[ 1535.270196] (0)[3219:Thread-326][vibrator]vibrator_enable: vibrator first in value = 10
<4>[ 1535.272058]-(0)[3219:Thread-326][vibrator]vibrator_enable: vibrator cust timer: 50
<4>[ 1535.273433] (0)[3219:Thread-326][vibrator]vibrator_enable: vibrator start: 10
<4>[ 1535.274359] (0)[2855:kworker/u:1][vibrator]vibr_Enable before
<5>[ 1535.275088] (0)[2855:kworker/u:1][Power/PMIC] [hwPowerOn] acquire powerId:13 index:0
mod_name: VIBR powerVolt:2800
<6>[ 1535.277872] (0)[2855:kworker/u:1][Power/PMIC] [hwPowerOn] enable 13 by VIBR
<4>[ 1535.278808] (0)[2855:kworker/u:1]****[dct_pmic_VIBR_sel] value=2800
<5>[ 1535.279661] (0)[2855:kworker/u:1][Power/PMIC] [dct_pmic_VIBR_enable] 1
<4>[ 1535.280492] (0)[2855:kworker/u:1]vibrator enable register = 0x8004
<4>[ 1535.282634] (0)[2855:kworker/u:1][vibrator]vibr_Enable After
从log中可以看出已经进入enable函数,马达无效,就可以与硬件一起检查是否GPIO配置正确。若没有进入enable函数则中间代码调用关系。
2、注意事项
1)堵转时所有的输入功率都转化为热能(P=I2R),时间过长可能导致线圈温升偏高而变形,影响性能。(所以不能一直震动)
2)马达在其标称的额定电压下工作时综合性能优良,建议手机电路设计时工作电压尽量接近额定电压设计。
3)调节震动强度 通过调节结构体的电压可以调节震动的强度,但是电压必须在额定电压内