@@ -562,17 +562,35 @@ static void ili9341_selectarea(FAR struct ili9341_lcd_s *lcd,
562562 *
563563 * Input Parameters:
564564 * lcd_dev - The lcd device
565- * row - Starting row to write to (range: 0 <= row < yres)
566- * col - Starting column to write to (range: 0 <= col <= xres-npixels )
565+ * row - Row to write to (range: 0 <= row < yres)
566+ * col - Starting column to write to (range: 0 <= col < xres)
567567 * buffer - The buffer containing the run to be written to the LCD
568- * npixels - The number of pixels to write to the
569- * (range: 0 < npixels <= xres- col)
568+ * npixels - The number of pixels to write to the LCD, limited by col
569+ * (range: 1 <= npixels <= xres - col)
570570 *
571571 * Returned Value:
572572 *
573573 * On success - OK
574574 * On error - -EINVAL
575575 *
576+ * NOTE: This procedure could be used as putarea's fallback when putarea is
577+ * not implemented. In such a case, the input to the putarea, i.e.:
578+ *
579+ * - row_start (0 <= row_start < yres)
580+ * - row_end (row_start <= row_end < yres)
581+ * - col_start (0 <= col_start < xres)
582+ * - col_end (col_start <= col_end < xres)
583+ *
584+ * needs to be converted to multiple calls to putrun:
585+ *
586+ * col = col_start;
587+ * npixels = col_end - col_start + 1;
588+ *
589+ * for (row = row_start; row <= row_end; row++)
590+ * {
591+ * putrun(lcd_dev, row, col, buffer, npixels);
592+ * }
593+ *
576594 ****************************************************************************/
577595
578596static int ili9341_putrun (FAR struct lcd_dev_s * lcd_dev , fb_coord_t row ,
@@ -585,11 +603,37 @@ static int ili9341_putrun(FAR struct lcd_dev_s *lcd_dev, fb_coord_t row,
585603
586604 DEBUGASSERT (buffer && ((uintptr_t )buffer & 1 ) == 0 );
587605
588- /* Check if position outside of area */
606+ /* Check if position outside of the LCD's area. Fix when possible. */
589607
590- if (col + npixels > ili9341_getxres ( dev ) || row > ili9341_getyres (dev ))
608+ if (row >= ili9341_getyres (dev ))
591609 {
592- return - EINVAL ;
610+ lcderr ("row >= yres: %d >= %d" , row , ili9341_getyres (dev ));
611+ row = ili9341_getyres (dev ) - 1 ;
612+ lcdinfo ("row set to %d" , row );
613+ }
614+
615+ if (npixels < 1 )
616+ {
617+ lcderr ("npixels needs to be at least one, it is %d" , npixels );
618+ npixels = 1 ;
619+ lcdinfo ("npixels set to %d" , npixels );
620+ }
621+
622+ if (col + npixels > ili9341_getxres (dev ))
623+ {
624+ lcderr ("col + npixels is %d but must be at most %d" ,
625+ (col + npixels ),
626+ ili9341_getxres (dev ));
627+ npixels = ili9341_getxres (dev ) - col ;
628+ if (npixels < 1 )
629+ {
630+ lcderr ("failed to fix npixels" );
631+ return - EINVAL ;
632+ }
633+ else
634+ {
635+ lcdinfo ("col is %d, npixels set to %d" , col , npixels );
636+ }
593637 }
594638
595639 /* Select lcd driver */
0 commit comments