Module17: removed screen contrast setting, added screen brightness setting

Module17 uses an OLED display, which does not have contrast regulation. The
contrast control register, however, allows to change the brightness of the
display.
pull/238/head
Silvano Seva 2024-01-30 22:37:48 +01:00
rodzic 202a199442
commit fdd08d4bcb
5 zmienionych plików z 36 dodań i 42 usunięć

Wyświetl plik

@ -108,13 +108,8 @@ enum backupRestoreItems
enum displayItems enum displayItems
{ {
#ifdef CONFIG_SCREEN_CONTRAST D_BRIGHTNESS = 0,
D_CONTRAST = 0 D_TIMER
,D_TIMER
#endif
#ifndef CONFIG_SCREEN_CONTRAST
D_TIMER = 0
#endif
}; };
#ifdef CONFIG_GPS #ifdef CONFIG_GPS

Wyświetl plik

@ -88,9 +88,7 @@ const char *settings_items[] =
const char *display_items[] = const char *display_items[] =
{ {
#ifdef CONFIG_SCREEN_CONTRAST "Brightness",
"Contrast",
#endif
"Timer" "Timer"
}; };
@ -502,15 +500,18 @@ void _ui_fsm_insertVFONumber(kbd_msg_t msg, bool *sync_rtx)
} }
} }
void _ui_changeContrast(int variation) static void _ui_changeBrightness(int variation)
{ {
if(variation >= 0) // Avoid rollover if current value is zero.
state.settings.contrast = if((state.settings.brightness == 0) && (variation < 0))
(255 - state.settings.contrast < variation) ? 255 : state.settings.contrast + variation; return;
else
state.settings.contrast = // Cap max brightness to 100
(state.settings.contrast < -variation) ? 0 : state.settings.contrast + variation; if((state.settings.brightness == 100) && (variation > 0))
display_setContrast(state.settings.contrast); return;
state.settings.brightness += variation;
display_setBacklightLevel(state.settings.brightness);
} }
void _ui_changeTimer(int variation) void _ui_changeTimer(int variation)
@ -929,11 +930,9 @@ void ui_updateFSM(bool *sync_rtx)
{ {
switch(ui_state.menu_selected) switch(ui_state.menu_selected)
{ {
#ifdef CONFIG_SCREEN_CONTRAST case D_BRIGHTNESS:
case D_CONTRAST: _ui_changeBrightness(-5);
_ui_changeContrast(-4);
break; break;
#endif
case D_TIMER: case D_TIMER:
_ui_changeTimer(-1); _ui_changeTimer(-1);
break; break;
@ -945,11 +944,9 @@ void ui_updateFSM(bool *sync_rtx)
{ {
switch(ui_state.menu_selected) switch(ui_state.menu_selected)
{ {
#ifdef CONFIG_SCREEN_CONTRAST case D_BRIGHTNESS:
case D_CONTRAST: _ui_changeBrightness(+5);
_ui_changeContrast(+4);
break; break;
#endif
case D_TIMER: case D_TIMER:
_ui_changeTimer(+1); _ui_changeTimer(+1);
break; break;

Wyświetl plik

@ -177,11 +177,9 @@ int _ui_getDisplayValueName(char *buf, uint8_t max_len, uint8_t index)
uint8_t value = 0; uint8_t value = 0;
switch(index) switch(index)
{ {
#ifdef CONFIG_SCREEN_CONTRAST case D_BRIGHTNESS:
case D_CONTRAST: value = last_state.settings.brightness;
value = last_state.settings.contrast;
break; break;
#endif
case D_TIMER: case D_TIMER:
snprintf(buf, max_len, "%s", snprintf(buf, max_len, "%s",
display_timer_values[last_state.settings.display_timer]); display_timer_values[last_state.settings.display_timer]);

Wyświetl plik

@ -122,16 +122,24 @@ void display_render(void *fb)
void display_setContrast(uint8_t contrast) void display_setContrast(uint8_t contrast)
{ {
gpio_clearPin(LCD_CS); /* OLED display do not have contrast regulation */
(void) contrast;
gpio_clearPin(LCD_RS); /* RS low -> command mode */
(void) spi2_sendRecv(0x81); /* Set Electronic Volume */
(void) spi2_sendRecv(contrast); /* Controller contrast range is 0 - 63 */
gpio_setPin(LCD_CS);
} }
void display_setBacklightLevel(uint8_t level) void display_setBacklightLevel(uint8_t level)
{ {
(void) level; /*
* Module17 uses an OLED display, so contrast channel is actually controlling
* the brightness. The usable range is 0 - 128, above which there is no
* noticeable change in the brightness level (already at maximum).
*/
uint16_t bl = (level * 128) / 100;
gpio_clearPin(LCD_CS);
gpio_clearPin(LCD_RS); /* RS low -> command mode */
(void) spi2_sendRecv(0x81); /* Contrast control register */
(void) spi2_sendRecv(bl);
gpio_setPin(LCD_CS);
} }

Wyświetl plik

@ -29,10 +29,6 @@
#define CONFIG_SCREEN_WIDTH 128 #define CONFIG_SCREEN_WIDTH 128
#define CONFIG_SCREEN_HEIGHT 64 #define CONFIG_SCREEN_HEIGHT 64
/* Screen has adjustable contrast */
#define CONFIG_SCREEN_CONTRAST
#define CONFIG_DEFAULT_CONTRAST 91
/* Screen pixel format */ /* Screen pixel format */
#define CONFIG_PIX_FMT_BW #define CONFIG_PIX_FMT_BW