diff options
| author | ivan <[email protected]> | 2021-06-07 11:37:12 +0800 |
|---|---|---|
| committer | ivan <[email protected]> | 2021-06-07 11:37:12 +0800 |
| commit | 1e82e40c82925059e1cb0115bc28224bee038dda (patch) | |
| tree | 40ddfc068e94a44819e025acb89164d1fd0b09bd /bsp | |
| parent | 28847008171ab7423b6b05b7157d3467f1525fda (diff) | |
fixed bug of lcd_draw_line function when y1 == y2. need to consider user case when x1 >= x2
Diffstat (limited to 'bsp')
| -rw-r--r-- | bsp/stm32/stm32l475-atk-pandora/board/ports/drv_lcd.c | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/bsp/stm32/stm32l475-atk-pandora/board/ports/drv_lcd.c b/bsp/stm32/stm32l475-atk-pandora/board/ports/drv_lcd.c index f80ca3a4b2..6ec90f880c 100644 --- a/bsp/stm32/stm32l475-atk-pandora/board/ports/drv_lcd.c +++ b/bsp/stm32/stm32l475-atk-pandora/board/ports/drv_lcd.c @@ -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 ; } |
