菜鸟求教如何MT6582上面添加一个呼吸灯模块
请各位大神多多指教,非常感谢!
比方呼吸灯芯片自身的寄存器,你可以自己写函数
比如我这个3218的
/*////////////////////////////////////////////////////////////////////////////////////////////////////
// SW SN3218
////////////////////////////////////////////////////////////////////////////////////////////////////*/
static void Sn3218_Cmd_Reset(void)
{
Sn3218_I2c_Write(SN3218_REG_SW_RST, 0X00); // sw reset
}
static void Sn3218_Cmd_ChipEnable(void)
{
Sn3218_I2c_Write(SN3218_REG_CHIP_SSD, 0x01); // 0:chip off 1: work mode
}
static void Sn3218_Init(void)
{
Sn3218_Cmd_Reset();
Sn3218_Cmd_ChipEnable();
}
static void Sn3218_Cmd_Channel_Pwm(unsigned char Channel, unsigned char level) // brightness = 0-255
{
switch(Channel)
{
case SN3218_REG_PWM_CH1: case SN3218_REG_PWM_CH2: case SN3218_REG_PWM_CH3:
case SN3218_REG_PWM_CH4: case SN3218_REG_PWM_CH5: case SN3218_REG_PWM_CH6:
case SN3218_REG_PWM_CH7: case SN3218_REG_PWM_CH8: case SN3218_REG_PWM_CH9:
case SN3218_REG_PWM_CH10: case SN3218_REG_PWM_CH11: case SN3218_REG_PWM_CH12:
case SN3218_REG_PWM_CH13: case SN3218_REG_PWM_CH14: case SN3218_REG_PWM_CH15:
case SN3218_REG_PWM_CH16: case SN3218_REG_PWM_CH17: case SN3218_REG_PWM_CH18:
Sn3218_I2c_Write(Channel, level);
break;
default:
break;
}
}
static unsigned char g_Ledctrl_reg1=0x3f; // default is all on when in lk
static unsigned char g_Ledctrl_reg2=0x3f; // default is all on when in lk
static unsigned char g_Ledctrl_reg3=0x3f; // default is all on when in lk
static void Sn3218_Cmd_Channel_OnOff(unsigned char Channel, unsigned char onoff)
{
switch(Channel)
{
case SN3218_REG_PWM_CH1: case SN3218_REG_PWM_CH2: case SN3218_REG_PWM_CH3:
case SN3218_REG_PWM_CH4: case SN3218_REG_PWM_CH5: case SN3218_REG_PWM_CH6:
if(onoff)
g_Ledctrl_reg1|=(1<<(Channel-SN3218_REG_PWM_CH1));
else
g_Ledctrl_reg1&=(~(1<<(Channel-SN3218_REG_PWM_CH1)));
//DEBUG_SN3218_TEST("g_Ledctrl_reg1=0x%x.\n",g_Ledctrl_reg1);
Sn3218_I2c_Write(SN3218_REG_CH_ONOFF_CTRL1, g_Ledctrl_reg1);
break;
case SN3218_REG_PWM_CH7: case SN3218_REG_PWM_CH8: case SN3218_REG_PWM_CH9:
case SN3218_REG_PWM_CH10: case SN3218_REG_PWM_CH11: case SN3218_REG_PWM_CH12:
if(onoff)
g_Ledctrl_reg2|=(1<<(Channel-SN3218_REG_PWM_CH7));
else
g_Ledctrl_reg2&=(~(1<<(Channel-SN3218_REG_PWM_CH7)));
//DEBUG_SN3218_TEST("g_Ledctrl_reg2=0x%x.\n",g_Ledctrl_reg2);
Sn3218_I2c_Write(SN3218_REG_CH_ONOFF_CTRL2, g_Ledctrl_reg2);
break;
case SN3218_REG_PWM_CH13: case SN3218_REG_PWM_CH14: case SN3218_REG_PWM_CH15:
case SN3218_REG_PWM_CH16: case SN3218_REG_PWM_CH17: case SN3218_REG_PWM_CH18:
if(onoff)
g_Ledctrl_reg3|=(1<<(Channel-SN3218_REG_PWM_CH13));
else
g_Ledctrl_reg3&=(~(1<<(Channel-SN3218_REG_PWM_CH13)));
//DEBUG_SN3218_TEST("g_Ledctrl_reg3=0x%x.\n",g_Ledctrl_reg3);
Sn3218_I2c_Write(SN3218_REG_CH_ONOFF_CTRL3, g_Ledctrl_reg3); // 13-18channel
break;
default:
break;
}
}
static void Sn3218_Cmd_Update(void)
{
Sn3218_I2c_Write(SN3218_REG_DATA_UPDATE,0x00); // update, make data to be valid
}
i2c设备而已啊,参考其他I2C设备
可是其他I2C设备没有相关的宏,找不着相关的东西
mtdev.c添加平台设备
注册平台驱动,注册I2C资源等等
还是不懂。
刚接触MTK智能机,好多东西都还不懂,多多指教,谢谢了!
static int breathled_probe(struct platform_device *pdev)
{
DEBUG_SN3218_FUNC();
if(i2c_add_driver(&sn3218_i2c_driver))
{
DEBUG_SN3218_TEST("breathled_probe add driver error\n");
return -1;
}
return 0;
}
static int breathled_remove(struct platform_device *pdev)
{
i2c_del_driver(&sn3218_i2c_driver);
return 0;
}
static int breathled_suspend(struct platform_device *pdev)
{
DEBUG_SN3218_FUNC();
return 0;
}
static int breathled_resume(struct platform_device *pdev)
{
DEBUG_SN3218_FUNC();
return 0;
}
static struct platform_driver breathled_driver =
{
.probe = breathled_probe,
.remove = breathled_remove,
.suspend = breathled_suspend,
.resume = breathled_resume,
.driver = {
.name = BREATHLED_DEV_NAME,
//.owner = THIS_MODULE,
}
};
/*////////////////////////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////////////////////////*/
static struct i2c_board_info __initdata i2c_sn3218={ I2C_BOARD_INFO(SN3218_I2C_NAME, SN3218_I2C_ADDR)};
static int __init breathled_device_init(void)
{
i2c_register_board_info(3, &i2c_sn3218, 1);
if(platform_driver_register(&breathled_driver))
{
DEBUG_SN3218_ERROR("failed to register sn3218_driver");
return -ENODEV;
}
if( misc_register(&sn3218_device))
{
DEBUG_SN3218_ERROR("failed to register sn3218_device");
platform_driver_unregister(&breathled_driver);
return -1;
}
return 0;
}
static void __exit breathled_device_exit(void)
{
platform_driver_unregister(&breathled_driver);
}
MODULE_AUTHOR("");
MODULE_LICENSE("Dual BSD/GPL");
module_init(breathled_device_init);
module_exit(breathled_device_exit);
就是这么个框架,其他的你自己加
太感谢了,问题已经解决
能不能分享一下驱动?