@@ -115,7 +115,7 @@ static volatile spi_status_t spi_status = SPI_STATUS_ERROR;
115115 * Number of column triplets. Each triplet is 3 columns of pixels, as detailed
116116 * below in the description of the display buffer.
117117 */
118- #define ST7586S_NUM_COL_TRIPLETS (60 )
118+ #define ST7586S_NUM_COL_TRIPLETS ((PBDRV_CONFIG_DISPLAY_NUM_COLS + 2) / 3 )
119119
120120/**
121121 * Number of rows. This is the same as the number of display rows.
@@ -132,7 +132,7 @@ static volatile spi_status_t spi_status = SPI_STATUS_ERROR;
132132 *
133133 * Non-atomic updated by the application are allowed.
134134 */
135- static uint8_t pbdrv_display_user_frame [PBDRV_CONFIG_DISPLAY_NUM_ROWS ][PBDRV_CONFIG_DISPLAY_NUM_COLS ] __attribute__((section (".noinit" ), used ));
135+ static uint8_t pbdrv_display_user_frame [PBDRV_CONFIG_DISPLAY_NUM_ROWS ][ST7586S_NUM_COL_TRIPLETS * 3 ] __attribute__((section (".noinit" ), used ));
136136
137137/**
138138 * Flag to indicate that the user frame has been updated and needs to be
@@ -244,6 +244,10 @@ static void pbdrv_display_load_indexed_bitmap(const uint16_t *indexed_bitmap) {
244244 }
245245 pbdrv_display_user_frame [r ][c ] = set ? 3 : 0 ;
246246 }
247+ // Fill unused columns out of screen.
248+ for (size_t c = PBDRV_CONFIG_DISPLAY_NUM_COLS ; c < ST7586S_NUM_COL_TRIPLETS * 3 ; c ++ ) {
249+ pbdrv_display_user_frame [r ][c ] = 0 ;
250+ }
247251 }
248252}
249253
@@ -256,9 +260,8 @@ void pbdrv_display_st7586s_encode_user_frame(void) {
256260 // Iterating ST7586S column-triplets, which are 3 columns each.
257261 for (size_t triplet = 0 ; triplet < ST7586S_NUM_COL_TRIPLETS ; triplet ++ ) {
258262 uint8_t p0 = pbdrv_display_user_frame [row ][triplet * 3 ];
259- // The last triplet has no second and third pixel.
260- uint8_t p1 = triplet == ST7586S_NUM_COL_TRIPLETS - 1 ? 0 : pbdrv_display_user_frame [row ][triplet * 3 + 1 ];
261- uint8_t p2 = triplet == ST7586S_NUM_COL_TRIPLETS - 1 ? 0 : pbdrv_display_user_frame [row ][triplet * 3 + 2 ];
263+ uint8_t p1 = pbdrv_display_user_frame [row ][triplet * 3 + 1 ];
264+ uint8_t p2 = pbdrv_display_user_frame [row ][triplet * 3 + 2 ];
262265 st7586s_send_buf [row * ST7586S_NUM_COL_TRIPLETS + triplet ] = encode_triplet (p0 , p1 , p2 );
263266 }
264267 }
@@ -522,7 +525,7 @@ pbio_image_t *pbdrv_display_get_image(void) {
522525 static pbio_image_t image ;
523526 pbio_image_init (& image , (uint8_t * )pbdrv_display_user_frame ,
524527 PBDRV_CONFIG_DISPLAY_NUM_COLS , PBDRV_CONFIG_DISPLAY_NUM_ROWS ,
525- PBDRV_CONFIG_DISPLAY_NUM_COLS );
528+ ST7586S_NUM_COL_TRIPLETS * 3 );
526529 return & image ;
527530}
528531
0 commit comments