/*
*问题:硬件torch控制芯片需要PWM控制ENM调节亮度,但是硬件连接GPIO不支持PWM;
*解决方法:使用hrtimer模拟pwm;
*注释:linux kernel对ktime_set(0, 5000)第二个参数不能小于5000ns,小于5000系统默认赋值为*5000ns,
*具体代码看clockevents.c文件“clockevents_increase_min_delta”函数;
*/
//(1)定义
+static struct hrtimer g_timeOutTimerTorch;
//(2)初始化
void timerInit(void)//在初始化部分直接调用
+{
+ //torch timer
+ hrtimer_init( &g_timeOutTimerTorch, CLOCK_MONOTONIC, HRTIMER_MODE_REL_PINNED );
+ g_timeOutTimerTorch.function=torchTimeOutCallback;
+
+}
//模拟pwm部分:high:low=18:5
+static enum hrtimer_restart torchTimeOutCallback(struct hrtimer *timer)
+{
+ mt_set_gpio_out(GPIO_FLASH_LED_ENM, GPIO_OUT_ONE);
+ //udelay:lumen=1:1.4/5:15/8:16/20:24/(original lumen:30)
+ udelay(18); //调整占空比宽度
+ mt_set_gpio_out(GPIO_FLASH_LED_ENM, GPIO_OUT_ZERO);
+ hrtimer_forward_now(&g_timeOutTimerTorch,ktime_set(0, 5000)); //5000ns是最小值
+ return HRTIMER_RESTART;
+}
//(3)使用:在使用定时器代码调用
+ktime = ktime_set(0, 5000);//5000ns是kernel限制最小值,小于5000ns会赋值为5000ns;
+hrtimer_start( &g_timeOutTimerTorch, ktime, HRTIMER_MODE_REL_PINNED );
//(4)注销定时器
+hrtimer_cancel( &g_timeOutTimerTorch );