@@ -112,7 +112,7 @@ static bool st7567_bus_ready_dbi(const struct device *dev)
112112static int st7567_write_cmd_bus_dbi (const struct device * dev , const uint8_t * buf , size_t len )
113113{
114114 const struct st7567_config * config = dev -> config ;
115- int ret ;
115+ int ret = 0 ;
116116
117117 for (size_t i = 0 ; i < len ; i ++ ) {
118118 ret = mipi_dbi_command_write (config -> bus .dbi .mipi_dev , & config -> bus .dbi .dbi_config ,
@@ -285,22 +285,34 @@ static int st7567_suspend(const struct device *dev)
285285}
286286
287287static int st7567_write_default (const struct device * dev , const uint16_t x , const uint16_t y ,
288- const struct display_buffer_descriptor * desc , const void * buf ,
289- const size_t buf_len )
288+ const uint8_t * buf , const size_t buf_len )
290289{
290+ const struct st7567_config * config = dev -> config ;
291291 int ret ;
292292 uint8_t cmd_buf [3 ];
293+ uint16_t column = x + config -> column_offset ;
294+
295+ cmd_buf [0 ] = ST7567_COLUMN_LSB | (column & 0xF );
296+ cmd_buf [1 ] = ST7567_COLUMN_MSB | ((column >> 4 ) & 0xF );
297+ cmd_buf [2 ] = ST7567_PAGE | (y >> 3 );
298+
299+ ret = st7567_write_cmd_bus (dev , cmd_buf , sizeof (cmd_buf ));
300+ if (ret < 0 ) {
301+ return ret ;
302+ }
303+
304+ return st7567_write_pixels_bus (dev , buf , buf_len );
305+ }
306+
307+ static int st7567_write_desc (const struct device * dev , const uint16_t x , const uint16_t y ,
308+ const struct display_buffer_descriptor * desc , const void * buf ,
309+ const size_t buf_len )
310+ {
311+ int ret = 0 ;
293312
294313 for (int i = 0 ; i < desc -> height / 8 ; i ++ ) {
295- cmd_buf [0 ] = ST7567_COLUMN_LSB | (x & 0xF );
296- cmd_buf [1 ] = ST7567_COLUMN_MSB | ((x >> 4 ) & 0xF );
297- cmd_buf [2 ] = ST7567_PAGE | ((y >> 3 ) + i );
298- ret = st7567_write_cmd_bus (dev , cmd_buf , sizeof (cmd_buf ));
299- if (ret < 0 ) {
300- return ret ;
301- }
302- ret = st7567_write_pixels_bus (dev , ((const uint8_t * )buf + i * desc -> pitch ),
303- desc -> pitch );
314+ ret = st7567_write_default (dev , x , y + (i << 3 ),
315+ ((const uint8_t * )buf + i * desc -> pitch ), desc -> pitch );
304316 if (ret < 0 ) {
305317 return ret ;
306318 }
@@ -340,7 +352,7 @@ static int st7567_write(const struct device *dev, const uint16_t x, const uint16
340352 LOG_DBG ("x %u, y %u, pitch %u, width %u, height %u, buf_len %u" , x , y , desc -> pitch ,
341353 desc -> width , desc -> height , buf_len );
342354
343- return st7567_write_default (dev , x , y , desc , buf , buf_len );
355+ return st7567_write_desc (dev , x , y , desc , buf , buf_len );
344356}
345357
346358static int st7567_set_contrast (const struct device * dev , const uint8_t contrast )
@@ -420,23 +432,9 @@ static int st7567_clear(const struct device *dev)
420432 int ret = 0 ;
421433 uint8_t buf = 0 ;
422434
423- uint8_t cmd_buf [] = {
424- ST7567_COLUMN_LSB ,
425- ST7567_COLUMN_MSB ,
426- ST7567_PAGE ,
427- };
428-
429435 for (int y = 0 ; y < config -> height ; y += 8 ) {
430436 for (int x = 0 ; x < config -> width ; x ++ ) {
431- cmd_buf [0 ] = ST7567_COLUMN_LSB | (x & 0xF );
432- cmd_buf [1 ] = ST7567_COLUMN_MSB | ((x >> 4 ) & 0xF );
433- cmd_buf [2 ] = ST7567_PAGE | (y >> 3 );
434- ret = st7567_write_cmd_bus (dev , cmd_buf , sizeof (cmd_buf ));
435- if (ret < 0 ) {
436- LOG_ERR ("Error clearing display" );
437- return ret ;
438- }
439- ret = st7567_write_pixels_bus (dev , (uint8_t * )& buf , 1 );
437+ ret = st7567_write_default (dev , x , y , & buf , 1 );
440438 if (ret < 0 ) {
441439 LOG_ERR ("Error clearing display" );
442440 return ret ;
0 commit comments