@@ -37,7 +37,10 @@ static lcd_ssd1306_ret_t lcd_send_cmd_args(LcdSsd1306 *self, uint8_t cmd, size_t
3737 va_start (args , nargs );
3838 while (nargs -- ) {
3939 uint8_t arg = va_arg (args , uint32_t );
40- lcd_send_cmd (self , arg );
40+ if (lcd_send_cmd (self , arg ) != LCD_SSD1306_RET_OK ) {
41+ va_end (args );
42+ return LCD_SSD1306_RET_FAILED ;
43+ }
4144 }
4245 va_end (args );
4346
@@ -68,27 +71,26 @@ static lcd_ssd1306_ret_t lcd_send_data(LcdSsd1306 *self) {
6871
6972
7073static lcd_ssd1306_ret_t lcd_init_controller (LcdSsd1306 * self ) {
71- lcd_send_cmd_args (self , SSD1306_DISPLAY_OFF , 0 );
72- lcd_send_cmd_args (self , SSD1306_SET_OSC_FREQ , 1 , 0x80 );
73- lcd_send_cmd_args (self , SSD1306_SET_MUX_RATIO , 1 , 0x3f );
74- lcd_send_cmd_args (self , SSD1306_DISPLAY_OFFSET , 1 , 0x00 );
75- lcd_send_cmd_args (self , SSD1306_SET_START_LINE , 0 );
76- lcd_send_cmd_args (self , SSD1306_DIS_NORMAL , 0 );
77- lcd_send_cmd_args (self , SSD1306_DIS_ENT_DISP_ON , 0 );
78- lcd_send_cmd_args (self , SSD1306_SEG_REMAP_OP , 0 );
79- lcd_send_cmd_args (self , SSD1306_COM_SCAN_DIR_OP , 0 );
80- lcd_send_cmd_args (self , SSD1306_COM_PIN_CONF , 1 , 0x12 );
81- lcd_send_cmd_args (self , SSD1306_SET_CONTRAST , 1 , 0x7f );
82- lcd_send_cmd_args (self , SSD1306_SET_PRECHARGE , 1 , 0xc2 );
83- lcd_send_cmd_args (self , SSD1306_VCOM_DESELECT , 1 , 0x40 );
84-
85- lcd_send_cmd_args (self , SSD1306_MEMORY_ADDR_MODE , 1 , 0x01 );
86- lcd_send_cmd_args (self , SSD1306_DEACT_SCROLL , 0 );
87-
88- lcd_send_cmd_args (self , SSD1306_SET_CHAR_REG , 1 , 0x14 );
89- lcd_send_cmd_args (self , SSD1306_DISPLAY_ON , 0 );
90-
91- return LCD_SSD1306_RET_OK ;
74+ if (lcd_send_cmd_args (self , SSD1306_DISPLAY_OFF , 0 ) == LCD_SSD1306_RET_OK &&
75+ lcd_send_cmd_args (self , SSD1306_SET_OSC_FREQ , 1 , 0x80 ) == LCD_SSD1306_RET_OK &&
76+ lcd_send_cmd_args (self , SSD1306_SET_MUX_RATIO , 1 , 0x3f ) == LCD_SSD1306_RET_OK &&
77+ lcd_send_cmd_args (self , SSD1306_DISPLAY_OFFSET , 1 , 0x00 ) == LCD_SSD1306_RET_OK &&
78+ lcd_send_cmd_args (self , SSD1306_SET_START_LINE , 0 ) == LCD_SSD1306_RET_OK &&
79+ lcd_send_cmd_args (self , SSD1306_DIS_NORMAL , 0 ) == LCD_SSD1306_RET_OK &&
80+ lcd_send_cmd_args (self , SSD1306_DIS_ENT_DISP_ON , 0 ) == LCD_SSD1306_RET_OK &&
81+ lcd_send_cmd_args (self , SSD1306_SEG_REMAP_OP , 0 ) == LCD_SSD1306_RET_OK &&
82+ lcd_send_cmd_args (self , SSD1306_COM_SCAN_DIR_OP , 0 ) == LCD_SSD1306_RET_OK &&
83+ lcd_send_cmd_args (self , SSD1306_COM_PIN_CONF , 1 , 0x12 ) == LCD_SSD1306_RET_OK &&
84+ lcd_send_cmd_args (self , SSD1306_SET_CONTRAST , 1 , 0x7f ) == LCD_SSD1306_RET_OK &&
85+ lcd_send_cmd_args (self , SSD1306_SET_PRECHARGE , 1 , 0xc2 ) == LCD_SSD1306_RET_OK &&
86+ lcd_send_cmd_args (self , SSD1306_VCOM_DESELECT , 1 , 0x40 ) == LCD_SSD1306_RET_OK &&
87+ lcd_send_cmd_args (self , SSD1306_MEMORY_ADDR_MODE , 1 , 0x01 ) == LCD_SSD1306_RET_OK &&
88+ lcd_send_cmd_args (self , SSD1306_DEACT_SCROLL , 0 ) == LCD_SSD1306_RET_OK &&
89+ lcd_send_cmd_args (self , SSD1306_SET_CHAR_REG , 1 , 0x14 ) == LCD_SSD1306_RET_OK &&
90+ lcd_send_cmd_args (self , SSD1306_DISPLAY_ON , 0 ) == LCD_SSD1306_RET_OK ) {
91+ return LCD_SSD1306_RET_OK ;
92+ }
93+ return LCD_SSD1306_RET_FAILED ;
9294}
9395
9496
@@ -173,7 +175,10 @@ lcd_ssd1306_ret_t lcd_ssd1306_init(LcdSsd1306 *self, I2cBus *i2c) {
173175
174176 self -> i2c = i2c ;
175177
176- lcd_init_controller (self );
178+ if (lcd_init_controller (self ) != LCD_SSD1306_RET_OK ) {
179+ u_log (system_log , LOG_TYPE_ERROR , U_LOG_MODULE_PREFIX ("controller not responding" ));
180+ return LCD_SSD1306_RET_FAILED ;
181+ }
177182
178183 /** @todo make the framebuffer size configurable, there are 128x32 displays too */
179184 self -> dmem_size = 128 * 64 / 8 ;
0 commit comments