altos: Clean up st7565 LCD driver
authorKeith Packard <keithp@keithp.com>
Thu, 16 Mar 2023 17:23:05 +0000 (10:23 -0700)
committerKeith Packard <keithp@keithp.com>
Thu, 1 Feb 2024 01:50:19 +0000 (17:50 -0800)
Get rid of AO_ prefix on chip-specific register values.
Declare ao_st7565_instructions to take const uint8_t * so
it can accept an array in flash.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/drivers/ao_st7565.c
src/drivers/ao_st7565.h

index 24b94076737b4b048924783bed84668145dab259..6893ccd41e4741c506eee35b7bd57c4225200c71 100644 (file)
@@ -67,7 +67,7 @@ ao_st7565_instruction_param(uint8_t cmd, uint8_t param)
 }
 
 static void
-ao_st7565_instructions(uint8_t *cmd, uint16_t len)
+ao_st7565_instructions(const uint8_t *cmd, uint16_t len)
 {
        ao_st7565_start(0);
        ao_spi_send(cmd, len, AO_ST7565_SPI_BUS);
@@ -85,7 +85,7 @@ ao_st7565_data(const void *base, uint16_t len)
 static void
 ao_st7565_set_brightness(uint8_t val)
 {
-       ao_st7565_instruction_param(AO_ST7565_ELECTRONIC_VOLUME_SET, val);
+       ao_st7565_instruction_param(ST7565_ELECTRONIC_VOLUME_SET, val);
 }
 
 static bool setup_done;
@@ -93,27 +93,30 @@ static bool setup_done;
 static void
 ao_st7565_setup(void)
 {
+       static const uint8_t init[] = {
+               /*
+                * Should be set to one of ST7565_LCD_BIAS_1_9 or
+                * ST7565_LCD_BIAS_1_7
+                */
+               AO_ST7565_BIAS,
+               ST7565_ADC_SELECT_NORMAL,
+               ST7565_COMMON_MODE_NORMAL,
+               ST7565_DISPLAY_START_LINE_SET(0),
+               ST7565_POWER_CONTROL_SET(0x4),
+       };
+
        if (setup_done)
                return;
        setup_done = true;
        ao_st7565_reset();
-       /*
-        * Should be set to one of AO_ST7565_LCD_BIAS_1_9 or
-        * AO_ST7565_LCD_BIAS_1_7
-        */
-       ao_st7565_instruction(AO_ST7565_BIAS);
-       ao_st7565_instruction(AO_ST7565_ADC_SELECT_NORMAL);
-
-       ao_st7565_instruction(AO_ST7565_COMMON_MODE_NORMAL);
-       ao_st7565_instruction(AO_ST7565_DISPLAY_START_LINE_SET(0));
-       ao_st7565_instruction(AO_ST7565_POWER_CONTROL_SET(0x4));
+       ao_st7565_instructions(init, sizeof(init));
        ao_delay(AO_MS_TO_TICKS(50));
-       ao_st7565_instruction(AO_ST7565_POWER_CONTROL_SET(0x6));
+       ao_st7565_instruction(ST7565_POWER_CONTROL_SET(0x6));
        ao_delay(AO_MS_TO_TICKS(50));
-       ao_st7565_instruction(AO_ST7565_POWER_CONTROL_SET(0x7));
+       ao_st7565_instruction(ST7565_POWER_CONTROL_SET(0x7));
        ao_delay(AO_MS_TO_TICKS(10));
-       ao_st7565_instruction(AO_ST7565_RESISTOR_RATIO_SET(5));
-       ao_st7565_instruction(AO_ST7565_DISPLAY_ON);
+       ao_st7565_instruction(ST7565_RESISTOR_RATIO_SET(5));
+       ao_st7565_instruction(ST7565_DISPLAY_ON);
        ao_st7565_set_brightness(0x10);
 }
 
@@ -132,10 +135,10 @@ ao_st7565_update(struct ao_bitmap *bitmap)
        line = bitmap->base;
        for (page = 0; page < 8; page++) {
                uint8_t         i[4] = {
-                       AO_ST7565_PAGE_ADDRESS_SET(7-page),
-                       AO_ST7565_COLUMN_ADDRESS_SET_MSN(0 >> 4),
-                       AO_ST7565_COLUMN_ADDRESS_SET_MSN(0 & 0xf),
-                       AO_ST7565_RMW
+                       ST7565_PAGE_ADDRESS_SET(7-page),
+                       ST7565_COLUMN_ADDRESS_SET_MSN(0 >> 4),
+                       ST7565_COLUMN_ADDRESS_SET_MSN(0 & 0xf),
+                       ST7565_RMW
                };
                memset(rotbuf, 0, sizeof(rotbuf));
                for (row = 7; row >= 0; row--) {
index c3f8f1bfcdf513c00eaeeecedecabd52f1f1c454..e1340f8ac819d7d47689d816df24ee7dd2423169 100644 (file)
 
 #include <ao_draw.h>
 
-#define AO_ST7565_DISPLAY_OFF                  0xae
-#define AO_ST7565_DISPLAY_ON                   0xaf
-#define AO_ST7565_DISPLAY_START_LINE_SET(line) (0x40 | (line))
-#define AO_ST7565_PAGE_ADDRESS_SET(page)       (0xb0 | (page))
-#define AO_ST7565_COLUMN_ADDRESS_SET_MSN(nib)  (0x10 | (nib))
-#define AO_ST7565_COLUMN_ADDRESS_SET_LSN(nib)  (0x00 | (nib))
-#define AO_ST7565_ADC_SELECT_NORMAL            0xa0
-#define AO_ST7565_ADC_SELECT_REVERSE           0xa1
-#define AO_ST7565_DISPLAY_NORMAL               0xa6
-#define AO_ST7565_DISPLAY_REVERSE              0xa7
-#define AO_ST7565_DISPLAY_ALL_POINTS_OFF       0xa4
-#define AO_ST7565_DISPLAY_ALL_POINTS_ON                0xa5
-#define AO_ST7565_LCD_BIAS_1_9                 0xa2
-#define AO_ST7565_LCD_BIAS_1_7                 0xa3
-#define AO_ST7565_RMW                          0xe0
-#define AO_ST7565_RMW_END                      0xee
-#define AO_ST7565_RESET                                0xe2
-#define AO_ST7565_COMMON_MODE_NORMAL           0xc0
-#define AO_ST7565_COMMON_MODE_REVERSE          0xc8
-#define AO_ST7565_POWER_CONTROL_SET(pc)                (0x28 | (pc))
-#define AO_ST7565_RESISTOR_RATIO_SET(rr)       (0x20 | (rr))
-#define AO_ST7565_ELECTRONIC_VOLUME_SET                0x81
-#define AO_ST7565_SLEEP_MODE                   0xac
-#define AO_ST7565_BOOSTER_RATIO_SET            0xf8
-#define AO_ST7565_NOP                          0xe3
+#define ST7565_DISPLAY_OFF                     0xae
+#define ST7565_DISPLAY_ON                      0xaf
+#define ST7565_DISPLAY_START_LINE_SET(line)    (0x40 | (line))
+#define ST7565_PAGE_ADDRESS_SET(page)          (0xb0 | (page))
+#define ST7565_COLUMN_ADDRESS_SET_MSN(nib)     (0x10 | (nib))
+#define ST7565_COLUMN_ADDRESS_SET_LSN(nib)     (0x00 | (nib))
+#define ST7565_ADC_SELECT_NORMAL               0xa0
+#define ST7565_ADC_SELECT_REVERSE              0xa1
+#define ST7565_DISPLAY_NORMAL                  0xa6
+#define ST7565_DISPLAY_REVERSE                 0xa7
+#define ST7565_DISPLAY_ALL_POINTS_OFF          0xa4
+#define ST7565_DISPLAY_ALL_POINTS_ON           0xa5
+#define ST7565_LCD_BIAS_1_9                    0xa2
+#define ST7565_LCD_BIAS_1_7                    0xa3
+#define ST7565_RMW                             0xe0
+#define ST7565_RMW_END                         0xee
+#define ST7565_RESET                           0xe2
+#define ST7565_COMMON_MODE_NORMAL              0xc0
+#define ST7565_COMMON_MODE_REVERSE             0xc8
+#define ST7565_POWER_CONTROL_SET(pc)           (0x28 | (pc))
+#define ST7565_RESISTOR_RATIO_SET(rr)          (0x20 | (rr))
+#define ST7565_ELECTRONIC_VOLUME_SET           0x81
+#define ST7565_SLEEP_MODE                      0xac
+#define ST7565_BOOSTER_RATIO_SET               0xf8
+#define ST7565_NOP                             0xe3
 
 #define AO_ST7565_SPI_SPEED                    ao_spi_speed(20000000)