/* common device interface */
rt_err_t (*init) (rt_device_t dev);
rt_err_t (*open) (rt_device_t dev, rt_uint16_t oflag);
rt_err_t (*close) (rt_device_t dev);
rt_size_t (*read) (rt_device_t dev, rt_off_t pos, void *buffer, rt_size_t size);
rt_size_t (*write) (rt_device_t dev, rt_off_t pos, const void *buffer, rt_size_t size);
rt_err_t (*control)(rt_device_t dev, int cmd, void *args);
/**
* graphic device control command
*/
#define RTGRAPHIC_CTRL_RECT_UPDATE 0
#define RTGRAPHIC_CTRL_POWERON 1
#define RTGRAPHIC_CTRL_POWEROFF 2
#define RTGRAPHIC_CTRL_GET_INFO 3
#define RTGRAPHIC_CTRL_SET_MODE 4
#define RTGRAPHIC_CTRL_GET_EXT 5
static rt_err_t imx6ull_lcd_control(rt_device_t dev, int cmd, void *args)
{
struct imx6ull_lcd *lcd_dev = (struct imx6ull_lcd *)dev;
switch(cmd)
{
case RTGRAPHIC_CTRL_RECT_UPDATE:
{
break;
}
case RTGRAPHIC_CTRL_POWERON:
{
rt_pin_write(IMX6ULL_LCD_BL_PIN, PIN_HIGH);
break;
}
case RTGRAPHIC_CTRL_POWEROFF:
{
rt_pin_write(IMX6ULL_LCD_BL_PIN, PIN_LOW);
break;
}
case RTGRAPHIC_CTRL_GET_INFO:
{
struct rt_device_graphic_info *info = (struct rt_device_graphic_info*)args;
RT_ASSERT(info != RT_NULL);
rt_memcpy(info, &lcd_dev->info, sizeof(lcd.info));
break;
}
}
return RT_EOK;
}
int rt_hw_lcd_init(void)
{
rt_err_t ret;
lcd.device.type = RT_Device_Class_Graphic;
#ifdef RT_USING_DEVICE_OPS
lcd.device.ops = &lcd_ops;
#else
lcd.device.init = imx6ull_lcd_init;
lcd.device.open = RT_NULL;
lcd.device.close = RT_NULL;
lcd.device.read = RT_NULL;
lcd.device.write = RT_NULL;
lcd.device.control = imx6ull_lcd_control;
#endif
lcd.device.user_data = (void *)&lcd.info;
ret = rt_device_register(&lcd.device, "lcd", RT_DEVICE_FLAG_RDWR);
return ret;
}
INIT_BOARD_EXPORT(rt_hw_lcd_init);
本文分享自 Rice 嵌入式开发技术分享 微信公众号,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。
本文参与 腾讯云自媒体同步曝光计划 ,欢迎热爱写作的你一起参与!