rtt的io设备框架面向对象学习-电阻屏LCD设备

目录

    • 1.8080通信的电阻屏LCD设备
      • 1.1 构造流程
      • 1.2 使用
        • 2.i2c和spi通信的电阻屏LCD

电阻屏LCD通信接口有支持I2c、SPI和8080通信接口的。

1.8080通信的电阻屏LCD设备

rtt没有实现的设备驱动框架层,那么是在驱动层直接实现的,以stm32f407-atk-explorer为例,在/bsp / stm32 / stm32f407-atk-explorer / board / ports /drv_lcd.c中定义了该设备类:

cpp 复制代码
struct drv_lcd_device
{
    struct rt_device parent;
    struct rt_device_graphic_info lcd_info;
};

其中struct rt_device_graphic_info是在/ components / drivers / include / drivers /classes/graphic.h定义的:

cpp 复制代码
struct rt_device_graphic_info
{
    rt_uint8_t  pixel_format;                           /**< graphic format */
    rt_uint8_t  bits_per_pixel;                         /**< bits per pixel */
    rt_uint16_t pitch;                                  /**< bytes per line */

    rt_uint16_t width;                                  /**< width of graphic device */
    rt_uint16_t height;                                 /**< height of graphic device */

    rt_uint8_t *framebuffer;                            /**< frame buffer */
    rt_uint32_t smem_len;                               /**< allocated frame buffer size */
};

然后实例化了该设备类

cpp 复制代码
static struct drv_lcd_device _lcd;

1.1 构造流程

并实现了其构造函数drv_lcd_hw_init:

cpp 复制代码
int drv_lcd_hw_init(void)
{
    rt_err_t result = RT_EOK;
    struct rt_device *device = &_lcd.parent;
    /* memset _lcd to zero */
    memset(&_lcd, 0x00, sizeof(_lcd));

    _lcd.lcd_info.bits_per_pixel = 16;
    _lcd.lcd_info.pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB565;

    device->type = RT_Device_Class_Graphic;
#ifdef RT_USING_DEVICE_OPS
    device->ops = &lcd_ops;
#else
    device->init = drv_lcd_init;
    device->control = drv_lcd_control;
#endif
    device->user_data = &fsmc_lcd_ops;
    /* register lcd device */
    rt_device_register(device, "lcd", RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_STANDALONE);

    return result;
}
INIT_DEVICE_EXPORT(drv_lcd_hw_init);

可以看到其重写了父类------设备基类的方法------但是只是重写了init方法和control方法。

其对象图如下

从上面代码可以知道它是调用在/ components / drivers / core /device.c中设备基类的构造函数rt_device_register,将电阻屏LCD设备对象放到对象容器里管理。

详细参见io设备管理层

https://blog.csdn.net/yhb1206/article/details/136440373

1.2 使用

在/bsp / stm32 / stm32f407-atk-explorer / board / ports / touch /drv_xpt2046_init.c中,

cpp 复制代码
static int touch_xpt2046_init(void)
{
    xpt2046_init_hw();
    rt_thread_t tid = rt_thread_create("xpt2046", xpt2046_entry, RT_NULL, 1024, 8, 20);
    RT_ASSERT(tid != RT_NULL);
    rt_thread_startup(tid);
    return RT_EOK;
}
INIT_COMPONENT_EXPORT(touch_xpt2046_init);
cpp 复制代码
void xpt2046_init_hw(void)
{
  	......
    lcd = rt_device_find("lcd");
    rt_device_init(lcd);
}

rtt的io设备框架面向对象学习-touch设备中说过,因为此bsp的LCD是电阻触摸LCD屏,所以在xpt2046_init_hw中初始化触摸设备,最后也初始化了LCD,如上代码。

在xpt2046_entry线程中,读取到触摸坐标点,若开启了lvgl绘图,则通知lvgl绘图,否则直接调用rt_graphix_ops(lcd)->set_pixel在LCD上绘制点的轨迹。

lvgl对接有lcd的绘点接口,暂忽略。

rt_graphix_ops(lcd)->set_pixel是/ components / drivers / include / drivers /classes/graphic.h定义的lcd操作接口:

cpp 复制代码
struct rt_device_graphic_ops
{
    void (*set_pixel) (const char *pixel, int x, int y);
    void (*get_pixel) (char *pixel, int x, int y);

    void (*draw_hline)(const char *pixel, int x1, int x2, int y);
    void (*draw_vline)(const char *pixel, int x, int y1, int y2);

    void (*blit_line) (const char *pixel, int x, int y, rt_size_t size);
};
#define rt_graphix_ops(device)          ((struct rt_device_graphic_ops *)(device->user_data))

而之前drv_lcd.c中实现了该接口:

cpp 复制代码
struct rt_device_graphic_ops fsmc_lcd_ops =
    {
        LCD_Fast_DrawPoint,
        LCD_ReadPoint,
        LCD_HLine,
        LCD_VLine,
        LCD_BlitLine,
};

并在构造函数drv_lcd_hw_init中赋给了设备基类的user_data 成员

cpp 复制代码
device->user_data = &fsmc_lcd_ops;

这样就能直接操作lcd绘图。

2.i2c和spi通信的电阻屏LCD

至于i2c和spi通信的电阻屏LCD是怎么操作的,通过查找,是没有新的对象的,都是直接对i2c总线和spi设备关联,直接包装发送数据即可,没有上面8080通信口那样子的新的设备框架对象。

spi的LCD屏可以参照官方开发板麻雀一号开发板。

i2c未找到参照物,但是应该是spi一样。

相关推荐
易连EDI—EasyLink2 小时前
易连EDI–EasyLink实现OCR智能数据采集
网络·人工智能·安全·汽车·ocr·edi
酿情师2 小时前
yihan:一款面向连续网页学习的智能侧边栏插件
学习·学习方法·工具·学习工具
@insist1232 小时前
信息安全工程师考点精讲:身份认证核心原理与分类体系(上篇)
大数据·网络·分类·信息安全工程师·软件水平考试
SmartRadio3 小时前
ESP32-S3 双模式切换实现:兼顾手机_路由器连接与WiFi长距离通信
开发语言·网络·智能手机·esp32·长距离wifi
_.Switch3 小时前
东方财富股票数据JS逆向:secids字段和AES加密实战
开发语言·前端·javascript·网络·爬虫·python·ecmascript
瞎某某Blinder3 小时前
DFT学习记录[6]基于 HES06的能带计算+有效质量计算
python·学习·程序人生·数据挖掘·云计算·学习方法
金色光环4 小时前
FreeModbus释放底层的 TCP 监听端口
服务器·网络·tcp/ip
数智化精益手记局4 小时前
拆解物料管理erp系统的核心功能,看物料管理erp系统如何解决库存积压与缺料难题
大数据·网络·人工智能·安全·信息可视化·精益工程
love在水一方4 小时前
VLN 入门学习计划 —— 基于 InternNav
学习
灰子学技术6 小时前
Envoy HTTP 过滤器处理技术文档
网络·网络协议·http