Skip to content

Commit b25a620

Browse files
committed
Replace hal_gpio with gpio:: API and style fixes
Migrate code to use the new gpio wrapper: replace includes of hal_gpio.h with gpio.h and convert FUNC_PREFIX(Gpio*) calls to gpio:: functions (Fsel, SetPud, Set, Clr, Lev, Write, etc.). Apply small style/formatting cleanups across display and pixel DMX modules (brace and namespace formatting, header comment year bump, minor refactors in SPI/I2C display classes). Affects lib-display and lib-pixeldmx sources/headers.
1 parent be4010a commit b25a620

11 files changed

Lines changed: 87 additions & 116 deletions

File tree

lib-display/include/i2c/display.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
#include "displayset.h"
5151
#include "ansi_colour.h"
5252
#if defined(DISPLAYTIMEOUT_GPIO)
53-
#include "hal_gpio.h"
53+
#include "gpio.h"
5454
#endif
5555

5656
namespace display {
@@ -303,7 +303,7 @@ class Display {
303303

304304
if (is_sleep_) {
305305
#if defined(DISPLAYTIMEOUT_GPIO)
306-
if (__builtin_expect(((FUNC_PREFIX(GpioLev(DISPLAYTIMEOUT_GPIO)) == 0)), 0)) {
306+
if (__builtin_expect(((gpio::Lev(DISPLAYTIMEOUT_GPIO) == 0)), 0)) {
307307
SetSleep(false);
308308
}
309309
#endif

lib-display/include/spi/config.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@
2828

2929
#include <cstdint>
3030

31-
namespace config
32-
{
31+
namespace config {
3332
#if defined(SPI_LCD_240X240)
3433
inline constexpr uint32_t kWidth = 240;
3534
inline constexpr uint32_t kHeight = 240;
@@ -65,4 +64,4 @@ inline constexpr uint32_t kHeight = 160;
6564
#endif
6665
#endif
6766

68-
#endif // SPI_CONFIG_H_
67+
#endif // SPI_CONFIG_H_

lib-display/include/spi/display.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ using LcdDriver = ST7789;
6060
#include "spi/spilcd.h"
6161
#include "ansi_colour.h"
6262
#if defined(DISPLAYTIMEOUT_GPIO)
63-
#include "hal_gpio.h"
63+
#include "gpio.h"
6464
#endif
6565

6666
#if defined(SPI_LCD_HAVE_CS_GPIO)
@@ -85,8 +85,8 @@ class Display : public LcdDriver {
8585
cols_ = (GetWidth() / s_pFONT->kWidth);
8686
rows_ = (GetHeight() / s_pFONT->kHeight);
8787
#if defined(DISPLAYTIMEOUT_GPIO)
88-
FUNC_PREFIX(GpioFsel(DISPLAYTIMEOUT_GPIO, GPIO_FSEL_INPUT));
89-
FUNC_PREFIX(GpioSetPud(DISPLAYTIMEOUT_GPIO, GPIO_PULL_UP));
88+
gpio::Fsel(DISPLAYTIMEOUT_GPIO, gpio::Select::kInput);
89+
gpio::SetPud(DISPLAYTIMEOUT_GPIO, gpio::Pull::kUp);
9090
#endif
9191

9292
PrintInfo();
@@ -271,7 +271,7 @@ class Display : public LcdDriver {
271271

272272
if (is_sleep_) {
273273
#if defined(DISPLAYTIMEOUT_GPIO)
274-
if (__builtin_expect(((FUNC_PREFIX(GpioLev(DISPLAYTIMEOUT_GPIO)) == 0)), 0)) {
274+
if (__builtin_expect(((gpio::Lev(DISPLAYTIMEOUT_GPIO) == 0)), 0)) {
275275
SetSleep(false);
276276
}
277277
#endif

lib-display/include/spi/ili9341.h

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,9 @@
3030
#include <cassert>
3131

3232
#include "spi/config.h"
33-
#include "spi/spilcd.h"
3433

35-
namespace ili9341
36-
{
37-
namespace cmd
38-
{
34+
namespace ili9341 {
35+
namespace cmd {
3936
inline constexpr uint8_t kNop = 0x00;
4037
inline constexpr uint8_t SWRESET = 0x01;
4138
inline constexpr uint8_t RDDID = 0x04;
@@ -56,8 +53,7 @@ inline constexpr uint8_t PTLAR = 0x30;
5653
inline constexpr uint8_t MADCTL = 0x36;
5754
inline constexpr uint8_t PIXFMT = 0x3A;
5855
} // namespace cmd
59-
namespace data
60-
{
56+
namespace data {
6157
/**
6258
* Memory Data Access Control Register (0x36H)
6359
* MAP: D7 D6 D5 D4 D3 D2 D1 D0
@@ -72,8 +68,7 @@ inline constexpr uint8_t kMadctlRgb = 0x00; ///< Red-Green-Blue pixel order
7268
inline constexpr uint8_t kMadctlBgr = 0x08; ///< Blue-Green-Red pixel order
7369
} // namespace data
7470

75-
namespace colour
76-
{
71+
namespace colour {
7772
inline constexpr uint16_t kBlack = 0x0000;
7873
inline constexpr uint16_t kBlue = 0x001F;
7974
inline constexpr uint16_t kCyan = 0x07FF;
@@ -90,11 +85,9 @@ inline constexpr uint16_t kYellow = 0xFFE0;
9085

9186
#include "paint.h"
9287

93-
class ILI9341 : public Paint
94-
{
88+
class ILI9341 : public Paint {
9589
public:
96-
ILI9341(uint32_t nCS) : Paint(nCS)
97-
{
90+
ILI9341(uint32_t nCS) : Paint(nCS) {
9891
DEBUG_ENTRY();
9992

10093
#if defined(SPI_LCD_RST_GPIO)
@@ -174,18 +167,15 @@ class ILI9341 : public Paint
174167
DEBUG_EXIT();
175168
}
176169

177-
~ILI9341() override
178-
{
170+
~ILI9341() override {
179171
DEBUG_ENTRY();
180172
DEBUG_EXIT();
181173
}
182174

183-
void SetRotation(const uint32_t nRotation)
184-
{
175+
void SetRotation(const uint32_t nRotation) {
185176
WriteCommand(ili9341::cmd::MADCTL);
186177

187-
switch (nRotation)
188-
{
178+
switch (nRotation) {
189179
case 0:
190180
WriteDataByte(ili9341::data::kMadctlBgr);
191181
width_ = config::kWidth;
@@ -224,8 +214,7 @@ class ILI9341 : public Paint
224214
void EnableColourInversion(bool enable) { WriteCommand(enable ? ili9341::cmd::INVON : ili9341::cmd::INVOFF); }
225215

226216
private:
227-
void SetAddressWindow(uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1) override
228-
{
217+
void SetAddressWindow(uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1) override {
229218
WriteCommand(ili9341::cmd::kCaSet);
230219
{
231220
uint8_t data[] = {static_cast<uint8_t>(x0 >> 8), static_cast<uint8_t>(x0), static_cast<uint8_t>(x1 >> 8), static_cast<uint8_t>(x1)};
@@ -246,4 +235,4 @@ class ILI9341 : public Paint
246235
uint32_t shift_y_{0};
247236
};
248237

249-
#endif // SPI_ILI9341_H_
238+
#endif // SPI_ILI9341_H_

lib-display/include/spi/spilcd.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#include "timing.h"
3030
#include "spi/config.h"
3131
#include "spi.h"
32-
#include "hal_gpio.h"
32+
#include "gpio.h"
3333
#include "firmware/debug/debug_debug.h"
3434

3535
class SpiLcd {
@@ -44,12 +44,12 @@ class SpiLcd {
4444
spi::SetDataMode(spi::kMode0);
4545

4646
#if defined(SPI_LCD_RST_GPIO)
47-
FUNC_PREFIX(GpioFsel(SPI_LCD_RST_GPIO, GPIO_FSEL_OUTPUT));
47+
gpio::Fsel(SPI_LCD_RST_GPIO, gpio::Select::kOutput);
4848
#endif
49-
FUNC_PREFIX(GpioFsel(SPI_LCD_DC_GPIO, GPIO_FSEL_OUTPUT));
50-
FUNC_PREFIX(GpioFsel(SPI_LCD_BL_GPIO, GPIO_FSEL_OUTPUT));
49+
gpio::Fsel(SPI_LCD_DC_GPIO, gpio::Select::kOutput);
50+
gpio::Fsel(SPI_LCD_BL_GPIO, gpio::Select::kOutput);
5151
#if defined(SPI_LCD_HAVE_CS_GPIO)
52-
FUNC_PREFIX(GpioFsel(cs_, GPIO_FSEL_OUTPUT));
52+
gpio::Fsel(cs_, gpio::Select::kOutput);
5353
#endif
5454

5555
DEBUG_EXIT();
@@ -58,28 +58,28 @@ class SpiLcd {
5858
void HardwareReset() {
5959
#if defined(SPI_LCD_RST_GPIO)
6060
timing::DelayUs(1000 * 200);
61-
FUNC_PREFIX(GpioClr(SPI_LCD_RST_GPIO));
61+
gpio::Clr(SPI_LCD_RST_GPIO);
6262
timing::DelayUs(1000 * 200);
63-
FUNC_PREFIX(GpioSet(SPI_LCD_RST_GPIO));
63+
gpio::Set(SPI_LCD_RST_GPIO);
6464
timing::DelayUs(1000 * 200);
6565
#endif
6666
}
6767

6868
void SetCS() {
6969
#if defined(SPI_LCD_HAVE_CS_GPIO)
70-
FUNC_PREFIX(GpioSet(cs_));
70+
gpio::Set(cs_);
7171
#endif
7272
}
7373

7474
void ClearCS() {
7575
#if defined(SPI_LCD_HAVE_CS_GPIO)
76-
FUNC_PREFIX(GpioClr(cs_));
76+
gpio::Clr(cs_);
7777
#endif
7878
}
7979

80-
void SetDC() { FUNC_PREFIX(GpioSet(SPI_LCD_DC_GPIO)); }
80+
void SetDC() { gpio::Set(SPI_LCD_DC_GPIO); }
8181

82-
void ClearDC() { FUNC_PREFIX(GpioClr(SPI_LCD_DC_GPIO)); }
82+
void ClearDC() { gpio::Clr(SPI_LCD_DC_GPIO); }
8383

8484
void WriteCommand(uint8_t data) {
8585
ClearCS();

lib-display/include/spi/st7789.h

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,10 @@
3131

3232
#include "spi/config.h"
3333
#include "spi/st77xx.h"
34-
#include "firmware/debug/debug_debug.h"
34+
#include "firmware/debug/debug_debug.h"
3535

36-
namespace st7789
37-
{
38-
namespace cmd
39-
{
36+
namespace st7789 {
37+
namespace cmd {
4038
inline constexpr uint8_t kGctrl = 0xB7; ///< Gate Control
4139
inline constexpr uint8_t kVcoms = 0xBB; ///< VCOM Setting
4240
inline constexpr uint8_t kLcmctrl = 0xC0; ///< LCM Control
@@ -67,16 +65,13 @@ inline constexpr uint32_t kRotation3ShiftY = 0;
6765
#endif
6866
} // namespace st7789
6967

70-
class ST7789 : public ST77XX
71-
{
68+
class ST7789 : public ST77XX {
7269
public:
73-
explicit ST7789(uint32_t cs) : ST77XX(cs)
74-
{
70+
explicit ST7789(uint32_t cs) : ST77XX(cs) {
7571
DEBUG_ENTRY();
7672

7773
#if defined(SPI_LCD_RST_GPIO)
78-
if (s_instance == 0)
79-
{
74+
if (s_instance == 0) {
8075
HardwareReset();
8176
}
8277
s_instance++;
@@ -120,8 +115,7 @@ class ST7789 : public ST77XX
120115

121116
uint32_t arg_length = 0;
122117

123-
for (uint32_t i = 0; i < sizeof(kConfig); i += (arg_length + 2))
124-
{
118+
for (uint32_t i = 0; i < sizeof(kConfig); i += (arg_length + 2)) {
125119
arg_length = kConfig[i];
126120
DEBUG_PRINTF("i=%u, arg_length=%u", i, arg_length);
127121
WriteCommand(&kConfig[i + 1], arg_length);
@@ -135,14 +129,15 @@ class ST7789 : public ST77XX
135129
DEBUG_EXIT();
136130
}
137131

138-
~ST7789() override { DEBUG_ENTRY(); DEBUG_EXIT(); };
132+
~ST7789() override {
133+
DEBUG_ENTRY();
134+
DEBUG_EXIT();
135+
};
139136

140-
void SetRotation(uint32_t rotation)
141-
{
137+
void SetRotation(uint32_t rotation) {
142138
WriteCommand(st77xx::cmd::kMadctl);
143139

144-
switch (rotation)
145-
{
140+
switch (rotation) {
146141
case 0:
147142
WriteDataByte(st77xx::data::kMadctlMx | st77xx::data::kMadctlMy | st77xx::data::kMadctlRgb);
148143
shift_x_ = st7789::kRotation0ShiftX;
@@ -186,4 +181,4 @@ class ST7789 : public ST77XX
186181
#endif
187182
};
188183

189-
#endif // SPI_ST7789_H_
184+
#endif // SPI_ST7789_H_

lib-display/include/spi/st77xx.h

Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -29,40 +29,36 @@
2929
#include <cstdint>
3030

3131
#include "spi/paint.h"
32-
#include "spi/spilcd.h"
33-
#include "hal_gpio.h"
34-
#include "firmware/debug/debug_debug.h"
35-
36-
namespace st77xx
37-
{
38-
namespace cmd
39-
{
32+
#include "gpio.h"
33+
#include "firmware/debug/debug_debug.h"
34+
35+
namespace st77xx {
36+
namespace cmd {
4037
inline constexpr uint8_t kNop = 0x00;
4138
inline constexpr uint8_t kSwreset = 0x01; ///< Software Reset
4239
inline constexpr uint8_t kRddid = 0x04; ///< Read Display ID
4340
inline constexpr uint8_t kRddst = 0x09; ///< Read Display Status
44-
inline constexpr uint8_t kSlpin = 0x10; ///< Sleep In
45-
inline constexpr uint8_t kSlpout = 0x11; ///< Sleep Out
46-
inline constexpr uint8_t kPtlon = 0x12; ///< Partial Display Mode On
47-
inline constexpr uint8_t kNoron = 0x13; ///< Normal Display Mode On
48-
inline constexpr uint8_t kInvoff = 0x20; ///< Display Inversion Off
49-
inline constexpr uint8_t kInvon = 0x21; ///< Display Inversion On
50-
inline constexpr uint8_t kGamset = 0x26; ///< Gamma Set
51-
inline constexpr uint8_t kDispoff = 0x28; ///< Display Offs
52-
inline constexpr uint8_t kDispon = 0x29; ///< Display On
41+
inline constexpr uint8_t kSlpin = 0x10; ///< Sleep In
42+
inline constexpr uint8_t kSlpout = 0x11; ///< Sleep Out
43+
inline constexpr uint8_t kPtlon = 0x12; ///< Partial Display Mode On
44+
inline constexpr uint8_t kNoron = 0x13; ///< Normal Display Mode On
45+
inline constexpr uint8_t kInvoff = 0x20; ///< Display Inversion Off
46+
inline constexpr uint8_t kInvon = 0x21; ///< Display Inversion On
47+
inline constexpr uint8_t kGamset = 0x26; ///< Gamma Set
48+
inline constexpr uint8_t kDispoff = 0x28; ///< Display Offs
49+
inline constexpr uint8_t kDispon = 0x29; ///< Display On
5350
inline constexpr uint8_t kCaSet = 0x2A; ///< Column Address Set
54-
inline constexpr uint8_t kRaset = 0x2B; ///< Row Address Set
55-
inline constexpr uint8_t kRamwr = 0x2C; ///< Memory Write
56-
inline constexpr uint8_t kRamrd = 0x2E; ///< Memory Read
57-
inline constexpr uint8_t kPtlar = 0x30; ///< Partial Area
51+
inline constexpr uint8_t kRaset = 0x2B; ///< Row Address Set
52+
inline constexpr uint8_t kRamwr = 0x2C; ///< Memory Write
53+
inline constexpr uint8_t kRamrd = 0x2E; ///< Memory Read
54+
inline constexpr uint8_t kPtlar = 0x30; ///< Partial Area
5855
inline constexpr uint8_t kTeoff = 0x34; ///< Tearing Effect Line OFF
5956
inline constexpr uint8_t kTeon = 0x35; ///< Tearing Effect Line ON .
6057
inline constexpr uint8_t kMadctl = 0x36; ///< Memory Data Access Control.
6158
inline constexpr uint8_t kIdmoff = 0x38; ///< Idle Mode Off .
6259
inline constexpr uint8_t kColmod = 0x3A; ///< Interface Pixel Format
6360
} // namespace cmd
64-
namespace data
65-
{
61+
namespace data {
6662
/**
6763
* Memory Data Access Control Register (0x36H)
6864
* MAP: D7 D6 D5 D4 D3 D2 D1 D0
@@ -82,8 +78,7 @@ inline constexpr uint8_t kMadctlRgb = 0x00;
8278
inline constexpr uint8_t kMadctlBgr = 0x08;
8379
} // namespace data
8480

85-
namespace colour
86-
{
81+
namespace colour {
8782
inline constexpr uint16_t kBlack = 0x0000;
8883
inline constexpr uint16_t kBlue = 0x001F;
8984
inline constexpr uint16_t kCyan = 0x07FF;
@@ -99,11 +94,9 @@ inline constexpr uint16_t kYellow = 0xFFE0;
9994

10095
} // namespace st77xx
10196

102-
class ST77XX : public Paint
103-
{
97+
class ST77XX : public Paint {
10498
public:
105-
explicit ST77XX(uint32_t cs) : Paint(cs)
106-
{
99+
explicit ST77XX(uint32_t cs) : Paint(cs) {
107100
DEBUG_ENTRY();
108101
DEBUG_EXIT();
109102
}
@@ -114,10 +107,9 @@ class ST77XX : public Paint
114107

115108
void EnableSleep(bool enable) { WriteCommand(enable ? st77xx::cmd::kSlpin : st77xx::cmd::kSlpout); }
116109

117-
void SetBackLight(uint32_t value) { FUNC_PREFIX(GpioWrite(SPI_LCD_BL_GPIO, value == 0 ? 0 : 1)); }
110+
void SetBackLight(uint32_t value) { gpio::Write(SPI_LCD_BL_GPIO, value == 0 ? 0 : 1); }
118111

119-
void SetAddressWindow(uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1) override
120-
{
112+
void SetAddressWindow(uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1) override {
121113
const auto kStartX = x0 + shift_x_;
122114
const auto kEndX = x1 + shift_x_;
123115
const auto kStartY = y0 + shift_y_;
@@ -143,4 +135,4 @@ class ST77XX : public Paint
143135
uint32_t shift_y_{0};
144136
};
145137

146-
#endif // SPI_ST77XX_H_
138+
#endif // SPI_ST77XX_H_

0 commit comments

Comments
 (0)