From: Keith Packard Date: Sun, 28 Jan 2024 00:03:20 +0000 (-0800) Subject: altos: Add support for backlight control in ao_lco_bits X-Git-Tag: 1.9.18~2^2~34 X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=commitdiff_plain;h=5506b6c1f75d639e2d952213a53bc9ee34e5a79c altos: Add support for backlight control in ao_lco_bits Signed-off-by: Keith Packard --- diff --git a/src/drivers/ao_lco.h b/src/drivers/ao_lco.h index 50ed068a..42f4e6d8 100644 --- a/src/drivers/ao_lco.h +++ b/src/drivers/ao_lco.h @@ -51,10 +51,19 @@ extern struct ao_pad_query ao_pad_query; /* Last received QUERY from pad */ #define AO_LCO_BOX_FIRST AO_LCO_BOX_DRAG #else #define AO_LCO_LCO_VOLTAGE 0 /* Box number to show LCO voltage */ +# ifdef AO_LCO_HAS_BACKLIGHT +# define AO_LCO_BACKLIGHT -2 +# ifndef AO_LCO_BOX_FIRST +# define AO_LCO_BOX_FIRST AO_LCO_BACKLIGHT +# endif +# endif # ifdef AO_LCO_HAS_CONTRAST # define AO_LCO_CONTRAST -1 -# define AO_LCO_BOX_FIRST AO_LCO_CONTRAST -# else +# ifndef AO_LCO_BOX_FIRST +# define AO_LCO_BOX_FIRST AO_LCO_CONTRAST +# endif +# endif +# ifndef AO_LCO_BOX_FIRST # define AO_LCO_BOX_FIRST AO_LCO_LCO_VOLTAGE # endif #endif @@ -75,6 +84,10 @@ ao_lco_box_pseudo(int16_t box) #ifdef AO_LCO_CONTRAST case AO_LCO_CONTRAST: return true; +#endif +#ifdef AO_LCO_BACKLIGHT + case AO_LCO_BACKLIGHT: + return true; #endif default: return false; @@ -182,12 +195,20 @@ ao_lco_box_present(int16_t box); #ifdef AO_LCO_HAS_CONTRAST void -ao_lco_set_contrast(int16_t contrast); +ao_lco_set_contrast(int32_t contrast); -int16_t +int32_t ao_lco_get_contrast(void); #endif +#ifdef AO_LCO_HAS_BACKLIGHT +void +ao_lco_set_backlight(int32_t backlight); + +int32_t +ao_lco_get_backlight(void); +#endif + #ifdef AO_LCO_SEARCH_API void diff --git a/src/drivers/ao_lco_bits.c b/src/drivers/ao_lco_bits.c index 8e9ea09b..7dd63615 100644 --- a/src/drivers/ao_lco_bits.c +++ b/src/drivers/ao_lco_bits.c @@ -254,15 +254,31 @@ ao_lco_step_pad(int8_t dir) #ifdef AO_LCO_HAS_CONTRAST if (ao_lco_box == AO_LCO_CONTRAST) { - int16_t contrast = ao_lco_get_contrast(); + int32_t contrast = ao_lco_get_contrast(); - contrast += (int16_t) (dir * AO_LCO_CONTRAST_STEP); + contrast = (contrast + AO_LCO_CONTRAST_STEP - 1) / AO_LCO_CONTRAST_STEP; + contrast += dir; + contrast *= AO_LCO_CONTRAST_STEP; if (contrast < AO_LCO_MIN_CONTRAST) contrast = AO_LCO_MIN_CONTRAST; if (contrast > AO_LCO_MAX_CONTRAST) contrast = AO_LCO_MAX_CONTRAST; ao_lco_set_contrast(contrast); } +#endif +#ifdef AO_LCO_HAS_BACKLIGHT + if (ao_lco_box == AO_LCO_BACKLIGHT) { + int32_t backlight = ao_lco_get_backlight(); + + backlight = (backlight + AO_LCO_BACKLIGHT_STEP - 1) / AO_LCO_BACKLIGHT_STEP; + backlight += dir; + backlight *= AO_LCO_BACKLIGHT_STEP; + if (backlight < AO_LCO_MIN_BACKLIGHT) + backlight = AO_LCO_MIN_BACKLIGHT; + if (backlight > AO_LCO_MAX_BACKLIGHT) + backlight = AO_LCO_MAX_BACKLIGHT; + ao_lco_set_backlight(backlight); + } #endif new_pad = (int16_t) ao_lco_pad; do { @@ -297,11 +313,7 @@ ao_lco_step_box(int8_t dir) new_box += dir; if (new_box > ao_lco_max_box) new_box = AO_LCO_BOX_FIRST; -#ifdef AO_LCO_HAS_CONTRAST - else if (new_box < AO_LCO_CONTRAST) -#else - else if (new_box < 0) -#endif + else if (new_box < AO_LCO_BOX_FIRST) new_box = ao_lco_max_box; if (new_box == ao_lco_box) break;