SSD1306 oled屏驱动失败 程序跑飞

Moderator: ESP_Bob

chenguozi
Posts: 1
Joined: Mon Mar 14, 2022 3:09 pm

SSD1306 oled屏驱动失败 程序跑飞

Postby chenguozi » Mon Mar 14, 2022 3:34 pm

程序在进入lcd初始化阶段就跑飞,仔细阅读的源代码发现一个问题,
  1. scr_interface_create(SCREEN_IFACE_I2C , &iface_cfg, &iface_drv);
在这个函数内部
  1.         interface_i2c->interface_drv.type        = type;
  2.         interface_i2c->interface_drv.write_cmd   = i2c_lcd_write_cmd;
  3.         interface_i2c->interface_drv.write_data  = i2c_lcd_write_data;
  4.         interface_i2c->interface_drv.write       = i2c_lcd_write;
  5.         interface_i2c->interface_drv.read        = i2c_lcd_read;
  6.         interface_i2c->interface_drv.bus_acquire = i2c_lcd_acquire;
  7.         interface_i2c->interface_drv.bus_release = i2c_lcd_release;
给出了interface_i2c的处理函数地址
配置lcd初始化参数时
  1. lcd_cfg.interface_drv = iface_drv
使用这个参数对lcd进行初始化
  1. esp_err_t lcd_ssd1306_init(const scr_controller_config_t *lcd_conf)
  2. {
  3.  
  4. //////////////////////////////////////////////
  5.     g_lcd_handle.interface_drv = lcd_conf->interface_drv; //这个时候传递给了 g_lcd_handle
  6.  
  7. ///////////////////////////////////////////////////
  8.  
  9.     LCD_WRITE_CMD(0xAE); //--turn off oled panel
  10.  
  11. ////////////////////////////////////////////////
#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 前面根本就没有赋值,所以一调用就跑飞。(这个地方解释起来真是自己都觉得很绕,不知道是否说清楚了)
不知道我的理解是否正确。还是我理解存在问题,还请大家指点

Who is online

Users browsing this forum: No registered users and 48 guests