From 47bd5e45f701ebcf18867492c217df83370372d9 Mon Sep 17 00:00:00 2001 From: finga Date: Tue, 14 Sep 2021 21:23:38 +0200 Subject: [PATCH] Create a function to move the cursor Create a function (`lcs_move_cursor()`) to move the cursor in order to reduce code repetition. --- firmware/src/main.c | 85 ++++++++++++--------------------------------- 1 file changed, 22 insertions(+), 63 deletions(-) diff --git a/firmware/src/main.c b/firmware/src/main.c index 08a9f30..311f91e 100644 --- a/firmware/src/main.c +++ b/firmware/src/main.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include @@ -201,13 +202,19 @@ static void lcd_update_backlight(void) { } } +static void lcd_move_cursor(const uint8_t column, const uint8_t row) { + assert(row < 16); + + SPI_PORT &= ~(1 << LCD_CD); + lcd_write(0x00 + (0x0F & column)); + lcd_write(0x10 + (column >> 4)); + lcd_write(0xB0 + row); + SPI_PORT |= (1 << LCD_CD); +} + static void lcd_fill(const uint8_t data) { for (uint8_t i = 0; i < 8; i++) { - SPI_PORT &= ~(1 << LCD_CD); - lcd_write(0x00); - lcd_write(0x10); - lcd_write(0xB0 + i); - SPI_PORT |= (1 << LCD_CD); + lcd_move_cursor(0, i); for (uint8_t j = 0; j < 102; j++) lcd_write(data); @@ -280,11 +287,7 @@ static void lcd_splash(void) { lcd_fill(0x00); for (uint8_t i = 0; i < 5; i++) { - SPI_PORT &= ~(1 << LCD_CD); - lcd_write(0x0F); - lcd_write(0x11); - lcd_write(0xB1 + i); - SPI_PORT |= (1 << LCD_CD); + lcd_move_cursor(31, 1 + i); for (uint8_t j = 0; j < 40; j++) lcd_write(sacred_chao[i * 40 + j]); @@ -292,11 +295,7 @@ static void lcd_splash(void) { } for (uint8_t i = 0; i < 2; i++) { - SPI_PORT &= ~(1 << LCD_CD); - lcd_write(0x0A); - lcd_write(0x11); - lcd_write(0xB6 + i); - SPI_PORT |= (1 << LCD_CD); + lcd_move_cursor(26, 6 + i); for (uint8_t j = 0; j < 48; j++) lcd_write(onders_org[i * 48 + j]); @@ -327,39 +326,19 @@ static void lcd_home(void) { } for (uint8_t i = 0; i < 2; i++) { - SPI_PORT &= ~(1 << LCD_CD); - lcd_write(0x00); - lcd_write(0x10); - lcd_write(0xB0 + i); - SPI_PORT |= (1 << LCD_CD); - + lcd_move_cursor(0, i); lcd_write_string_page("CH1\0", i, ch1_selected); lcd_write_kerning(2, ch1_selected); - SPI_PORT &= ~(1 << LCD_CD); - lcd_write(0x00); - lcd_write(0x10); - lcd_write(0xB2 + i); - SPI_PORT |= (1 << LCD_CD); - + lcd_move_cursor(0, 2 + i); lcd_write_string_page("CH2\0", i, ch2_selected); lcd_write_kerning(2, ch2_selected); - SPI_PORT &= ~(1 << LCD_CD); - lcd_write(0x00); - lcd_write(0x10); - lcd_write(0xB4 + i); - SPI_PORT |= (1 << LCD_CD); - + lcd_move_cursor(0, 4 + i); lcd_write_string_page("CH3\0", i, ch3_selected); lcd_write_kerning(2, ch3_selected); - SPI_PORT &= ~(1 << LCD_CD); - lcd_write(0x01); - lcd_write(0x12); - lcd_write(0xB6 + i); - SPI_PORT |= (1 << LCD_CD); - + lcd_move_cursor(33, 6 + i); lcd_write_string_page("SETUP\0", i, setup_selected); lcd_write_kerning(2, setup_selected); } @@ -393,24 +372,14 @@ static void lcd_setup(void) { } for (uint8_t i = 0; i < 2; i++) { - SPI_PORT &= ~(1 << LCD_CD); - lcd_write(0x00); - lcd_write(0x10); - lcd_write(0xB0 + i); - SPI_PORT |= (1 << LCD_CD); - + lcd_move_cursor(0, i); lcd_write_kerning(30, true); lcd_write_string_page("SETUP\0", i, true); lcd_write_kerning(33, true); } for (uint8_t i = 0; i < 2; i++) { - SPI_PORT &= ~(1 << LCD_CD); - lcd_write(0x00); - lcd_write(0x10); - lcd_write(0xB2 + i); - SPI_PORT |= (1 << LCD_CD); - + lcd_move_cursor(0, 2 + i); lcd_write_string_page("CONTRAST:\0", i, contrast_selected); lcd_write_kerning(2, contrast_selected); lcd_write_kerning(16, false); @@ -419,12 +388,7 @@ static void lcd_setup(void) { } for (uint8_t i = 0; i < 2; i++) { - SPI_PORT &= ~(1 << LCD_CD); - lcd_write(0x00); - lcd_write(0x10); - lcd_write(0xB4 + i); - SPI_PORT |= (1 << LCD_CD); - + lcd_move_cursor(0, 4 + i); lcd_write_string_page("BACKLIGHT:\0", i, backlight_selected); lcd_write_kerning(2, backlight_selected); lcd_write_kerning(5, false); @@ -433,12 +397,7 @@ static void lcd_setup(void) { } for (uint8_t i = 0; i < 2; i++) { - SPI_PORT &= ~(1 << LCD_CD); - lcd_write(0x01); - lcd_write(0x12); - lcd_write(0xB6 + i); - SPI_PORT |= (1 << LCD_CD); - + lcd_move_cursor(33, 6 + i); lcd_write_string_page("BACK:\0", i, back_selected); lcd_write_kerning(2, back_selected); }