Skip to content

Commit a19505c

Browse files
authored
OLED tweaks part 2: Electric Boogaloo (ExpressLRS#1050)
* Fix OLED definitions for supported targets Fix Ghost TX and TX Lite includes * Fixed missed references to the old OLED defines Added define macros to the XBMStrings Moved includes into the header file * Reverted OLED includes to the implementation file
1 parent 87e1a3e commit a19505c

15 files changed

Lines changed: 202 additions & 205 deletions

src/include/target/BETAFPV_2400_TX_MICRO.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#define DEVICE_NAME "BETAFPV 2400TX Micro"
22

33
// Any device features
4-
#define HAS_OLED
5-
#define HAS_OLED_I2C
4+
#define USE_OLED_I2C
65
#define OLED_REVERSED
76

87
// There is some special handling for this target

src/include/target/BETAFPV_900_TX_MICRO.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
#define TARGET_TX_BETAFPV_900_MICRO_V1
55

66
// Any device features
7-
#define HAS_OLED
8-
#define HAS_OLED_I2C
7+
#define USE_OLED_I2C
98
#define OLED_REVERSED
109

1110
// GPIO pin definitions

src/include/target/DIY_2400_TX_ESP32_SX1280_E28.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
#endif
44

55
// Any device features
6-
#define HAS_OLED
7-
#define HAS_OLED_SPI
6+
#define USE_OLED_SPI
87

98
// GPIO pin definitions
109
#define GPIO_PIN_NSS 5

src/include/target/DIY_900_TX_TTGO_V1_SX127x.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
#define DEVICE_NAME "DIY900 TTGO V1"
33

44
// Any device features
5-
#define HAS_OLED
6-
#define HAS_OLED_I2C
5+
#define USE_OLED_I2C
76

87
// GPIO pin definitions
98
#define GPIO_PIN_NSS 18

src/include/target/DIY_900_TX_TTGO_V2_SX127x.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
#define DEVICE_NAME "DIY900 TTGO V2"
33

44
// Any device features
5-
#define HAS_OLED
6-
#define HAS_OLED_I2C
5+
#define USE_OLED_I2C
76

87
// GPIO pin definitions
98
#define GPIO_PIN_NSS 18

src/include/target/GHOST_2400_TX.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
#define DEVICE_NAME "Ghost 24TX"
2-
1+
#if !defined(DEVICE_NAME)
2+
#define DEVICE_NAME "Ghost 24TX"
3+
#endif
34
// There is some special handling for this target
45
#define TARGET_TX_GHOST
56

67
// Any device features
7-
#define HAS_OLED
8-
#define HAS_OLED_SPI
8+
#if !defined(USE_OLED_SPI_SMALL)
9+
#define USE_OLED_SPI
10+
#endif
911

1012
// GPIO pin definitions
1113
#define GPIO_PIN_NSS PA15
@@ -37,5 +39,4 @@
3739
#define MaxPower PWR_250mW
3840
#define POWER_OUTPUT_VALUES {-16,-14,-11,-8,-4}
3941

40-
#define HAS_OLED
4142
#define Regulatory_Domain_ISM_2400 1
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
// This target extends the GHOST_2400_TX target
2-
3-
#undef DEVICE_NAME
42
#define DEVICE_NAME "Ghost 24TX Lite"
53

64
// There is some special handling for this target
75
#define TARGET_TX_GHOST_LITE
8-
9-
#undef HAS_OLED_SPI // We are extending ghost tx full so we have to remote this
10-
#define HAS_OLED_SPI_SMALL
6+
#define USE_OLED_SPI_SMALL

src/include/target/NamimnoRC_FLASH_2400_OLED_TX.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
// Features
44
#define USE_TX_BACKPACK
5-
#define USE_OLED
5+
#define USE_OLED_SPI
66

77
// GPIO pin definitions
88
#define GPIO_PIN_RST 21

src/include/target/NamimnoRC_VOYAGER_900_OLED_TX.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
// Features
44
#define USE_TX_BACKPACK
5-
#define USE_OLED
5+
#define USE_OLED_SPI
66

77
// GPIO pin definitions
88
#define GPIO_PIN_RST 21

src/lib/OLED/OLED.cpp

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,40 +14,42 @@
1414
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1515
*/
1616

17-
#ifdef HAS_OLED // This code will not be used if the hardware does not have a OLED display. Maybe a better way to blacklist it in platformio.ini?
17+
#if defined(USE_OLED_SPI) || defined(USE_OLED_SPI_SMALL) || defined(USE_OLED_I2C) // This code will not be used if the hardware does not have a OLED display. Maybe a better way to blacklist it in platformio.ini?
1818

1919
// Default header files for Express LRS
2020
#include "targets.h"
21-
// OLED specific header files
21+
// OLED specific header files.
2222
#include "OLED.h"
2323
#include <U8g2lib.h> // Needed for the OLED drivers, this is a arduino package. It is maintained by platformIO
24-
#include "XBMStrings.h" // Contains all the express logos and animation for UI
24+
#include "XBMStrings.h" // Contains all the ELRS logos and animations for the UI
2525

26-
#ifdef HAS_OLED_SPI_SMALL
27-
U8G2_SSD1306_128X32_UNIVISION_F_4W_SW_SPI u8g2(U8G2_R0, GPIO_PIN_OLED_SCK, GPIO_PIN_OLED_MOSI, GPIO_PIN_OLED_CS, GPIO_PIN_OLED_DC, GPIO_PIN_OLED_RST);
26+
#ifdef OLED_REVERSED
27+
#define OLED_ROTATION U8G2_R2
28+
#else
29+
#define OLED_ROTATION U8G2_R0
2830
#endif
2931

30-
#ifdef HAS_OLED_SPI
31-
U8G2_SSD1306_128X64_NONAME_F_4W_SW_SPI u8g2(U8G2_R0, GPIO_PIN_OLED_SCK, GPIO_PIN_OLED_MOSI, GPIO_PIN_OLED_CS, GPIO_PIN_OLED_DC, GPIO_PIN_OLED_RST);
32+
#ifdef USE_OLED_SPI_SMALL
33+
U8G2_SSD1306_128X32_UNIVISION_F_4W_SW_SPI u8g2(OLED_ROTATION, GPIO_PIN_OLED_SCK, GPIO_PIN_OLED_MOSI, GPIO_PIN_OLED_CS, GPIO_PIN_OLED_DC, GPIO_PIN_OLED_RST);
3234
#endif
3335

34-
#ifdef HAS_OLED_I2C
35-
#ifdef OLED_REVERSED
36-
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R2, GPIO_PIN_OLED_RST, GPIO_PIN_OLED_SCK, GPIO_PIN_OLED_SDA);
37-
#else
38-
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, GPIO_PIN_OLED_RST, GPIO_PIN_OLED_SCK, GPIO_PIN_OLED_SDA);
36+
#ifdef USE_OLED_SPI
37+
U8G2_SSD1306_128X64_NONAME_F_4W_SW_SPI u8g2(OLED_ROTATION, GPIO_PIN_OLED_SCK, GPIO_PIN_OLED_MOSI, GPIO_PIN_OLED_CS, GPIO_PIN_OLED_DC, GPIO_PIN_OLED_RST);
3938
#endif
40-
#endif
4139

40+
#ifdef USE_OLED_I2C
41+
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(OLED_ROTATION, GPIO_PIN_OLED_RST, GPIO_PIN_OLED_SCK, GPIO_PIN_OLED_SDA);
42+
#endif
4243

44+
#ifdef TARGET_TX_GHOST
4345
/**
4446
* helper function is used to draw xbmp on the OLED.
4547
* x = x position of the image
4648
* y = y position of the image
4749
* size = demensions of the box size x size, this only works for square images 1:1
4850
* image = XBM character string
4951
*/
50-
void helper(int x, int y, int size, const unsigned char * image){
52+
static void helper(int x, int y, int size, const unsigned char * image){
5153
u8g2.clearBuffer();
5254
u8g2.drawXBMP(x, y, size, size, image);
5355
u8g2.sendBuffer();
@@ -56,7 +58,7 @@ void helper(int x, int y, int size, const unsigned char * image){
5658
/**
5759
* ghostChase will only be called for ghost TX hardware.
5860
*/
59-
void ghostChase(){
61+
static void ghostChase(){
6062
// Using i < 16 and (i*4) to get 64 total pixels. Change to i < 32 (i*2) to slow animation.
6163
for(int i = 0; i < 20; i++){
6264
u8g2.clearBuffer();
@@ -74,12 +76,13 @@ void ghostChase(){
7476
* helper function just draw's the XBM strings.
7577
*/
7678
#ifndef TARGET_TX_GHOST_LITE
77-
helper(38,12,40,elrs40);
78-
helper(36,8,48,elrs48);
79-
helper(34,4,56,elrs56);
80-
helper(32,0,64,elrs64);
79+
helper(38,12,40,elrs40);
80+
helper(36,8,48,elrs48);
81+
helper(34,4,56,elrs56);
82+
helper(32,0,64,elrs64);
8183
#endif
8284
}
85+
#endif
8386

8487
/**
8588
* Displays the ExpressLRS logo
@@ -90,10 +93,10 @@ void ghostChase(){
9093
void OLED::displayLogo(){
9194
u8g2.begin();
9295
u8g2.clearBuffer();
93-
#if defined TARGET_TX_GHOST
96+
#ifdef TARGET_TX_GHOST
9497
ghostChase();
9598
#else
96-
#if defined HAS_OLED_SPI_SMALL
99+
#ifdef USE_OLED_SPI_SMALL
97100
u8g2.drawXBM(48, 0, 32, 32, elrs32);
98101
#else
99102
u8g2.drawXBM(32, 0, 64, 64, elrs64);
@@ -113,27 +116,22 @@ void OLED::displayLogo(){
113116
void OLED::updateScreen(const char * power, const char * rate, const char * ratio, const char * commitStr){
114117
u8g2.clearBuffer();
115118

116-
#if defined HAS_OLED_SPI_SMALL
119+
#ifdef USE_OLED_SPI_SMALL
117120
u8g2.setFont(u8g2_font_courR10_tr);
118121
u8g2.drawStr(0,15, rate);
119-
u8g2.setFont(u8g2_font_courR10_tr);
120122
u8g2.drawStr(70,15 , ratio);
121123
u8g2.drawStr(0,32, power);
122-
u8g2.setFont(u8g2_font_courR10_tr);
123124
u8g2.drawStr(70,32, commitStr);
124125
#else
125126
u8g2.setFont(u8g2_font_courR10_tr);
126127
u8g2.drawStr(0,10, "ExpressLRS");
127-
u8g2.setFont(u8g2_font_courR08_tr);
128-
u8g2.drawStr(0,24, "Ver: ");
129-
u8g2.drawStr(38,24, commitStr);
130-
u8g2.setFont(u8g2_font_courR10_tr);
131128
u8g2.drawStr(0,42, rate);
132-
u8g2.setFont(u8g2_font_courR10_tr);
133129
u8g2.drawStr(70,42 , ratio);
134130
u8g2.drawStr(0,57, power);
135131
u8g2.setFont(u8g2_font_courR08_tr);
136132
u8g2.drawStr(70,53, "TLM");
133+
u8g2.drawStr(0,24, "Ver: ");
134+
u8g2.drawStr(38,24, commitStr);
137135
#endif
138136
u8g2.sendBuffer();
139137
}

0 commit comments

Comments
 (0)