Skip to content

Commit

Permalink
Add RGB/BGR colour options for TFT displays
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Dawson committed Oct 25, 2024
1 parent 581ecf8 commit 6db565c
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 32 deletions.
27 changes: 15 additions & 12 deletions ili934x.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ void ILI934X::init()
_write(_VMCTRL1, (uint8_t *)"\x3e\x28", 2);
_write(_VMCTRL2, (uint8_t *)"\x86", 1);

_setRotation(_rotation);
_setRotation(_rotation, _invert_colours);

_write(_PIXSET, (uint8_t *)"\x55", 1);
_write(_FRMCTR1, (uint8_t *)"\x00\x18", 2);
Expand All @@ -111,9 +111,10 @@ void ILI934X::init()
_write(_DISPON);
}

void ILI934X::setRotation(ILI934X_ROTATION rotation)
void ILI934X::setRotation(ILI934X_ROTATION rotation, bool invert_colours)
{
_rotation = rotation;
_invert_colours = invert_colours;
}

void ILI934X::powerOn(bool power_on)
Expand All @@ -128,48 +129,50 @@ void ILI934X::powerOn(bool power_on)
}
}

void ILI934X::_setRotation(ILI934X_ROTATION rotation)
void ILI934X::_setRotation(ILI934X_ROTATION rotation, bool invert_colours)
{
uint8_t mode = MADCTL_MX | MADCTL_RGB;

uint8_t colour_flags = invert_colours?MADCTL_BGR:MADCTL_RGB;
uint8_t mode = MADCTL_MX | colour_flags;
switch (rotation)
{
case R0DEG:
mode = MADCTL_MX | MADCTL_RGB;
mode = MADCTL_MX | colour_flags;
this->_width = this->_init_width;
this->_height = this->_init_height;
break;
case R90DEG:
mode = MADCTL_MV | MADCTL_RGB;
mode = MADCTL_MV | colour_flags;
this->_width = this->_init_width;
this->_height = this->_init_height;
break;
case R180DEG:
mode = MADCTL_MY | MADCTL_RGB;
mode = MADCTL_MY | colour_flags;
this->_width = this->_init_width;
this->_height = this->_init_height;
break;
case R270DEG:
mode = MADCTL_MY | MADCTL_MX | MADCTL_MV | MADCTL_RGB;
mode = MADCTL_MY | MADCTL_MX | MADCTL_MV | colour_flags;
this->_width = this->_init_width;
this->_height = this->_init_height;
break;
case MIRRORED0DEG:
mode = MADCTL_MY | MADCTL_MX | MADCTL_RGB;
mode = MADCTL_MY | MADCTL_MX | colour_flags;
this->_width = this->_init_width;
this->_height = this->_init_height;
break;
case MIRRORED90DEG:
mode = MADCTL_MX | MADCTL_MV | MADCTL_RGB;
mode = MADCTL_MX | MADCTL_MV | colour_flags;
this->_width = this->_init_width;
this->_height = this->_init_height;
break;
case MIRRORED180DEG:
mode = MADCTL_RGB;
mode = colour_flags;
this->_width = this->_init_width;
this->_height = this->_init_height;
break;
case MIRRORED270DEG:
mode = MADCTL_MY | MADCTL_MV | MADCTL_RGB;
mode = MADCTL_MY | MADCTL_MV | colour_flags;
this->_width = this->_init_width;
this->_height = this->_init_height;
break;
Expand Down
5 changes: 3 additions & 2 deletions ili934x.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class ILI934X

void reset();
void init();
void setRotation(ILI934X_ROTATION rotation = R0DEG);
void setRotation(ILI934X_ROTATION rotation, bool invert_colours);
void setPixel(uint16_t x, uint16_t y, uint16_t colour);
void writeHLine(uint16_t x, uint16_t y, uint16_t w, uint16_t line[]);
void writeVLine(uint16_t x, uint16_t y, uint16_t h, uint16_t line[]);
Expand All @@ -128,7 +128,7 @@ class ILI934X
uint16_t colour565(uint8_t r, uint8_t g, uint8_t b);
void powerOn(bool power_on);
private:
void _setRotation(ILI934X_ROTATION rotation = R0DEG);
void _setRotation(ILI934X_ROTATION rotation, bool invert_colours);
void _write(uint8_t cmd, uint8_t *data = NULL, size_t dataLen = 0);
void _data(uint8_t *data, size_t dataLen = 0);
void _writeBlock(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint8_t *data = NULL, size_t dataLen = 0);
Expand All @@ -146,6 +146,7 @@ class ILI934X
uint16_t _init_width;
uint16_t _init_height;
uint8_t _init_rotation;
uint8_t _invert_colours;
};

#endif //__ILI934X_H__
Expand Down
32 changes: 25 additions & 7 deletions ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1155,7 +1155,9 @@ void ui::autorestore()
u8g2_SetFlipMode(&u8g2, (settings[idx_hw_setup] >> flag_flip_oled) & 1);
update_display_type();
u8g2_SetContrast(&u8g2, 17 * (settings[idx_hw_setup] & mask_display_contrast) >> flag_display_contrast);
waterfall_inst.configure_display((settings[idx_hw_setup] & mask_tft_settings) >> flag_tft_settings);
waterfall_inst.configure_display(
(settings[idx_hw_setup] & mask_tft_settings) >> flag_tft_settings,
(settings[idx_hw_setup] & mask_tft_colour) >> flag_tft_colour);

}

Expand Down Expand Up @@ -2172,7 +2174,7 @@ bool ui::configuration_menu(bool &ok)
//chose menu item
if(ui_state == select_menu_item)
{
if(menu_entry("HW Config", "Display\nTimeout#Regulator\nMode#Reverse\nEncoder#Encoder\nResolution#Swap IQ#Gain Cal#Freq Cal#Flip OLED#OLED Type#Display\nContrast#TFT\nSettings#Bands#USB\nUpload#", &menu_selection, ok))
if(menu_entry("HW Config", "Display\nTimeout#Regulator\nMode#Reverse\nEncoder#Encoder\nResolution#Swap IQ#Gain Cal#Freq Cal#Flip OLED#OLED Type#Display\nContrast#TFT\nSettings#TFT Colour#Bands#USB\nUpload#", &menu_selection, ok))
{
if(ok)
{
Expand Down Expand Up @@ -2256,18 +2258,34 @@ bool ui::configuration_menu(bool &ok)
break;

case 10:
setting_word = (settings[idx_hw_setup] & mask_tft_settings) >> flag_tft_settings;
done = enumerate_entry("TFT\nSettings", "Off#Rotation 1#Rotation 2#Rotation 3#Rotation 4#Rotation 5#Rotation 6#Rotation 7#Rotation 8#", &setting_word, ok);
{
static uint32_t rotation, colour;
rotation = (settings[idx_hw_setup] & mask_tft_settings) >> flag_tft_settings;
colour = (settings[idx_hw_setup] & mask_tft_colour) >> flag_tft_colour;
done = enumerate_entry("TFT\nSettings", "Off#Rotation 1#Rotation 2#Rotation 3#Rotation 4#Rotation 5#Rotation 6#Rotation 7#Rotation 8#", &rotation, ok);
settings[idx_hw_setup] &= ~mask_tft_settings;
settings[idx_hw_setup] |= setting_word << flag_tft_settings;
if(done && ok) waterfall_inst.configure_display(setting_word);
settings[idx_hw_setup] |= rotation << flag_tft_settings;
if(done && ok) waterfall_inst.configure_display(rotation, colour);
break;
}

case 11:
{
static uint32_t rotation, colour;
rotation = (settings[idx_hw_setup] & mask_tft_settings) >> flag_tft_settings;
colour = (settings[idx_hw_setup] & mask_tft_colour) >> flag_tft_colour;
done = enumerate_entry("TFT\nColour", "RGB#BGR#", &colour, ok);
settings[idx_hw_setup] &= ~mask_tft_colour;
settings[idx_hw_setup] |= colour << flag_tft_colour;
if(done && ok) waterfall_inst.configure_display(rotation, colour);
break;
}

case 12:
done = bands_menu(ok);
break;

case 12:
case 13:
setting_word = 0;
enumerate_entry("USB Upload", "Back#Memory#Firmware#", &setting_word, ok);
if(setting_word==1) {
Expand Down
4 changes: 3 additions & 1 deletion ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ const uint8_t PIN_DISPLAY_SCL = 19;
#define mask_display_contrast (0xf << flag_display_contrast)
#define flag_tft_settings 11 // bits 11-14
#define mask_tft_settings (0xf << flag_tft_settings)
#define flag_encoder_res 15
#define flag_tft_colour 15 // bits 15
#define mask_tft_colour (0x1 << flag_tft_colour)
#define flag_encoder_res 16
#define flag_ppm 24 // bits 24-31
#define mask_ppm (0xff << flag_ppm)

Expand Down
18 changes: 9 additions & 9 deletions waterfall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ waterfall::~waterfall()
delete display;
}

void waterfall::configure_display(uint8_t settings)
void waterfall::configure_display(uint8_t settings, bool invert_colours)
{
if(settings == 0)
{
Expand All @@ -52,42 +52,42 @@ void waterfall::configure_display(uint8_t settings)
else if(settings == 1)
{
enabled = true;
display->setRotation(R0DEG);
display->setRotation(R0DEG, invert_colours);
}
else if(settings == 2)
{
enabled = true;
display->setRotation(R180DEG);
display->setRotation(R180DEG, invert_colours);
}
else if(settings == 3)
{
enabled = true;
display->setRotation(MIRRORED0DEG);
display->setRotation(MIRRORED0DEG, invert_colours);
}
else if(settings == 4)
{
enabled = true;
display->setRotation(MIRRORED180DEG);
display->setRotation(MIRRORED180DEG, invert_colours);
}
else if(settings == 5)
{
enabled = true;
display->setRotation(R90DEG);
display->setRotation(R90DEG, invert_colours);
}
else if(settings == 6)
{
enabled = true;
display->setRotation(R270DEG);
display->setRotation(R270DEG, invert_colours);
}
else if(settings == 7)
{
enabled = true;
display->setRotation(MIRRORED90DEG);
display->setRotation(MIRRORED90DEG, invert_colours);
}
else if(settings == 8)
{
enabled = true;
display->setRotation(MIRRORED270DEG);
display->setRotation(MIRRORED270DEG, invert_colours);
}

display->init();
Expand Down
2 changes: 1 addition & 1 deletion waterfall.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class waterfall
waterfall();
~waterfall();
void update_spectrum(rx &receiver, rx_settings &settings, rx_status &status, uint8_t spectrum[], uint8_t dB10);
void configure_display(uint8_t settings);
void configure_display(uint8_t settings, bool invert_colours);
void powerOn(bool state);

private:
Expand Down

0 comments on commit 6db565c

Please sign in to comment.