Skip to content

Commit 920533d

Browse files
authored
Merge pull request #4768 from ivanyangcn/ivan_dev_20210607
fixed bug of lcd_draw_line function when y1 == y2. need to consider u…
2 parents 2884700 + 1e82e40 commit 920533d

File tree

1 file changed

+18
-3
lines changed
  • bsp/stm32/stm32l475-atk-pandora/board/ports

1 file changed

+18
-3
lines changed

bsp/stm32/stm32l475-atk-pandora/board/ports/drv_lcd.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -446,18 +446,33 @@ void lcd_draw_line(rt_uint16_t x1, rt_uint16_t y1, rt_uint16_t x2, rt_uint16_t y
446446
if (y1 == y2)
447447
{
448448
/* fast draw transverse line */
449-
lcd_address_set(x1, y1, x2, y2);
449+
rt_uint32_t x_offset = 0;
450+
if (x1 < x2)
451+
{
452+
x_offset = x2 - x1;
453+
lcd_address_set(x1, y1, x2, y2);
454+
}
455+
else if (x1 > x2)
456+
{
457+
x_offset = x1 - x2;
458+
lcd_address_set(x2, y2, x1, y1);
459+
}
460+
else
461+
{
462+
lcd_draw_point(x1, y1);
463+
return;
464+
}
450465

451466
rt_uint8_t line_buf[480] = {0};
452467

453-
for (i = 0; i < x2 - x1; i++)
468+
for (i = 0; i < x_offset; i++)
454469
{
455470
line_buf[2 * i] = FORE_COLOR >> 8;
456471
line_buf[2 * i + 1] = FORE_COLOR;
457472
}
458473

459474
rt_pin_write(LCD_DC_PIN, PIN_HIGH);
460-
rt_spi_send(spi_dev_lcd, line_buf, (x2 - x1) * 2);
475+
rt_spi_send(spi_dev_lcd, line_buf, x_offset * 2);
461476

462477
return ;
463478
}

0 commit comments

Comments
 (0)