SSD1306 oled屏驱动失败 程序跑飞
Posted: Mon Mar 14, 2022 3:34 pm
程序在进入lcd初始化阶段就跑飞,仔细阅读的源代码发现一个问题,
在这个函数内部
给出了interface_i2c的处理函数地址
配置lcd初始化参数时
使用这个参数对lcd进行初始化
#define LCD_WRITE_COMMAND(data, length) g_lcd_handle.interface_drv->write_command(g_lcd_handle.interface_drv, (data), (length))
static inline esp_err_t LCD_WRITE_CMD(uint8_t cmd)
{
return LCD_WRITE_COMMAND((uint8_t*)&cmd, 1);
}
在interface_drv_def.h文件中,把LCD_WRITE_CMD指向了LCD_WRITE_COMMAND
而LCD_WRITE_COMMAND 指向的是 g_lcd_handle.interface_drv->write_command
根据前面的参数我认为,LCD_WRITE_COMMAND 应该指向。 g_lcd_handle.interface_drv->write_cmd
write_command 前面根本就没有赋值,所以一调用就跑飞。(这个地方解释起来真是自己都觉得很绕,不知道是否说清楚了)
不知道我的理解是否正确。还是我理解存在问题,还请大家指点
- scr_interface_create(SCREEN_IFACE_I2C , &iface_cfg, &iface_drv);
- interface_i2c->interface_drv.type = type;
- interface_i2c->interface_drv.write_cmd = i2c_lcd_write_cmd;
- interface_i2c->interface_drv.write_data = i2c_lcd_write_data;
- interface_i2c->interface_drv.write = i2c_lcd_write;
- interface_i2c->interface_drv.read = i2c_lcd_read;
- interface_i2c->interface_drv.bus_acquire = i2c_lcd_acquire;
- interface_i2c->interface_drv.bus_release = i2c_lcd_release;
配置lcd初始化参数时
- lcd_cfg.interface_drv = iface_drv
- esp_err_t lcd_ssd1306_init(const scr_controller_config_t *lcd_conf)
- {
- //////////////////////////////////////////////
- g_lcd_handle.interface_drv = lcd_conf->interface_drv; //这个时候传递给了 g_lcd_handle
- ///////////////////////////////////////////////////
- LCD_WRITE_CMD(0xAE); //--turn off oled panel
- ////////////////////////////////////////////////
static inline esp_err_t LCD_WRITE_CMD(uint8_t cmd)
{
return LCD_WRITE_COMMAND((uint8_t*)&cmd, 1);
}
在interface_drv_def.h文件中,把LCD_WRITE_CMD指向了LCD_WRITE_COMMAND
而LCD_WRITE_COMMAND 指向的是 g_lcd_handle.interface_drv->write_command
根据前面的参数我认为,LCD_WRITE_COMMAND 应该指向。 g_lcd_handle.interface_drv->write_cmd
write_command 前面根本就没有赋值,所以一调用就跑飞。(这个地方解释起来真是自己都觉得很绕,不知道是否说清楚了)
不知道我的理解是否正确。还是我理解存在问题,还请大家指点