From 23a5f7fbe4383a7d1bc7cf49dc942af2efcad975 Mon Sep 17 00:00:00 2001 From: philippe44 Date: Sat, 26 Feb 2022 17:37:08 -0800 Subject: [PATCH] tweak muse color + add "invert" option --- components/display/ST77xx.c | 6 ++++-- components/services/accessors.c | 5 +++-- components/services/accessors.h | 1 + components/targets/muse/muse.c | 17 ++++++++++------- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/components/display/ST77xx.c b/components/display/ST77xx.c index 8661feb4..4d84178b 100644 --- a/components/display/ST77xx.c +++ b/components/display/ST77xx.c @@ -34,6 +34,7 @@ struct PrivateSpace { } Offset; uint8_t MADCtl, PageSize; uint8_t Model; + bool Invert; }; // Functions are not declared to minimize # of lines @@ -255,7 +256,7 @@ static bool Init( struct GDS_Device* Device ) { else WriteByte( Device, Device->Depth == 24 ? 0x06 : 0x05 ); // no Display Inversion - Device->WriteCommand( Device, Private->Model == ST7735 ? 0x20 : 0x21 ); + Device->WriteCommand( Device, Private->Invert ? 0x21 : 0x20 ); // gone with the wind Device->DisplayOn( Device ); @@ -286,7 +287,7 @@ struct GDS_Device* ST77xx_Detect(char *Driver, struct GDS_Device* Device) { struct PrivateSpace* Private = (struct PrivateSpace*) Device->Private; Private->Model = Model; - + if (Model == ST7735) { sscanf(Driver, "%*[^:]%*[^x]%*[^=]=%hu", &Private->Offset.Height); sscanf(Driver, "%*[^:]%*[^y]%*[^=]=%hu", &Private->Offset.Width); @@ -298,6 +299,7 @@ struct GDS_Device* ST77xx_Detect(char *Driver, struct GDS_Device* Device) { Device->Update = Update24; } + if (Model == ST7789 || strcasestr(Driver, "invert")) Private->Invert = true; if (Model == ST7789) Device->SetContrast = SetContrast; return Device; diff --git a/components/services/accessors.c b/components/services/accessors.c index 683870d3..7d36b289 100644 --- a/components/services/accessors.c +++ b/components/services/accessors.c @@ -462,7 +462,8 @@ const display_config_t * config_display_get(){ .hflip = false, .type = NULL, .speed = 0, - .rotate = false + .rotate = false, + .invert = false, }; char *config = config_alloc_get(NVS_TYPE_STR, "display_config"); if (!config) { @@ -482,7 +483,6 @@ const display_config_t * config_display_get(){ PARSE_PARAM(config, "address", '=', dstruct.address); PARSE_PARAM(config, "cs", '=', dstruct.CS_pin); PARSE_PARAM(config, "speed", '=', dstruct.speed); - PARSE_PARAM(config, "back", '=', dstruct.back); if (strstr(config, "I2C") ) dstruct.type=i2c_name_type; if (strstr(config, "SPI") ) dstruct.type=spi_name_type; @@ -490,6 +490,7 @@ const display_config_t * config_display_get(){ dstruct.hflip= strcasestr(config, "HFlip") ? true : false; dstruct.vflip= strcasestr(config, "VFlip") ? true : false; dstruct.rotate= strcasestr(config, "rotate") ? true : false; + dstruct.rotate= strcasestr(config, "invert") ? true : false; return &dstruct; } diff --git a/components/services/accessors.h b/components/services/accessors.h index 444a3cd8..ac8cd745 100644 --- a/components/services/accessors.h +++ b/components/services/accessors.h @@ -31,6 +31,7 @@ typedef struct { int depth; const char *type; bool rotate; + bool invert; } display_config_t; typedef struct eth_config_struct { diff --git a/components/targets/muse/muse.c b/components/targets/muse/muse.c index 87cf38f0..33521d92 100644 --- a/components/targets/muse/muse.c +++ b/components/targets/muse/muse.c @@ -7,7 +7,6 @@ #include #include #include -//#include #include "driver/rmt.h" #include "monitor.h" #include "targets.h" @@ -24,14 +23,18 @@ // These values are determined by measuring pulse timing with logic analyzer and adjusting to match datasheet. #define T0H 14 // 0 bit high time -#define T1H 52 // 1 bit high time +#define T1H 52 // 1 bit high time #define TL 52 // low time for either bit -#define GREEN 0xFF0000 -#define RED 0x00FF00 -#define BLUE 0x0000FF -#define WHITE 0xFFFFFF -#define YELLOW 0xE0F060 +// sets a color based on RGB from 0..255 and a brightness in % from 0..100 +#define RGB(R,G,B,BR) (((G*BR)/100) << 16) | (((R*BR)/100) << 8) | ((B*BR)/100) + +#define RED RGB(255,0,0,10) +#define GREEN RGB(0,255,0,10) +#define BLUE RGB(0,0,255,10) +#define WHITE RGB(255,255,255,10) +#define YELLOW RGB(255,118,13,10) + struct led_state { uint32_t leds[NUM_LEDS]; };