4
0
mirror of https://github.com/RT-Thread/rt-thread.git synced 2025-01-31 08:20:25 +08:00

fixed bug of lcd_draw_line function when y1 == y2. need to consider user case when x1 >= x2

This commit is contained in:
ivan 2021-06-07 11:37:12 +08:00
parent 2884700817
commit 1e82e40c82

View File

@ -446,18 +446,33 @@ void lcd_draw_line(rt_uint16_t x1, rt_uint16_t y1, rt_uint16_t x2, rt_uint16_t y
if (y1 == y2)
{
/* fast draw transverse line */
lcd_address_set(x1, y1, x2, y2);
rt_uint32_t x_offset = 0;
if (x1 < x2)
{
x_offset = x2 - x1;
lcd_address_set(x1, y1, x2, y2);
}
else if (x1 > x2)
{
x_offset = x1 - x2;
lcd_address_set(x2, y2, x1, y1);
}
else
{
lcd_draw_point(x1, y1);
return;
}
rt_uint8_t line_buf[480] = {0};
for (i = 0; i < x2 - x1; i++)
for (i = 0; i < x_offset; i++)
{
line_buf[2 * i] = FORE_COLOR >> 8;
line_buf[2 * i + 1] = FORE_COLOR;
}
rt_pin_write(LCD_DC_PIN, PIN_HIGH);
rt_spi_send(spi_dev_lcd, line_buf, (x2 - x1) * 2);
rt_spi_send(spi_dev_lcd, line_buf, x_offset * 2);
return ;
}