17
17
/* !
18
18
@brief Lambda function to create a dispDrvBase instance
19
19
*/
20
- using FnCreateDispDrv =
20
+ using FnCreateDispDrvEpd =
21
21
std::function<dispDrvBase *(int16_t , int16_t , int16_t , int16_t , int16_t )>;
22
22
23
23
// Factory for creating a new display drivers
24
24
// NOTE: When you add a new display driver, make sure to add it to the factory!
25
- static const std::map<std::string, FnCreateDispDrv> FactoryDrvDisp = {
25
+ static const std::map<std::string, FnCreateDispDrvEpd> FactoryDrvDispEpd = {
26
26
{" thinkink-gs4-eaamfgn" ,
27
27
[](int16_t dc, int16_t rst, int16_t cs, int16_t sram_cs,
28
28
int16_t busy) -> dispDrvBase * {
@@ -35,7 +35,29 @@ static const std::map<std::string, FnCreateDispDrv> FactoryDrvDisp = {
35
35
}}};
36
36
37
37
/* !
38
- @brief Creates a new display driver instance based on the driver name.
38
+ @brief Lambda function to create a dispDrvBase SPI TFT instance
39
+ */
40
+ using FnCreateDispDrvTft = std::function<dispDrvBase *(
41
+ int16_t , int16_t , int16_t , int16_t , int16_t , int16_t )>;
42
+
43
+ // Factory for creating a new SPI TFT display driver
44
+ // NOTE: When you add a new SPI TFT display driver, make sure to add it to the
45
+ // factory!
46
+ static const std::map<std::string, FnCreateDispDrvTft> FactoryDrvDispTft = {
47
+ {" st7735" ,
48
+ [](int16_t cs, int16_t dc, int16_t mosi, int16_t sck, int16_t rst,
49
+ int16_t miso) -> dispDrvBase * {
50
+ return new dispDrvSt7789 (cs, dc, mosi, sck, rst, miso);
51
+ }},
52
+ {" st7789" ,
53
+ [](int16_t cs, int16_t dc, int16_t mosi, int16_t sck, int16_t rst,
54
+ int16_t miso) -> dispDrvBase * {
55
+ return new dispDrvSt7789 (cs, dc, mosi, sck, rst, miso);
56
+ }}};
57
+
58
+ /* !
59
+ @brief Creates a new E-Ink display driver instance based on the driver
60
+ name.
39
61
@param driver_name
40
62
The name of the display driver to create.
41
63
@param dc
@@ -51,16 +73,32 @@ static const std::map<std::string, FnCreateDispDrv> FactoryDrvDisp = {
51
73
@return Pointer to the created display driver instance, or nullptr if the
52
74
driver name is not recognized.
53
75
*/
54
- dispDrvBase *CreateDrvDisp (const char *driver_name, int16_t dc, int16_t rst,
55
- int16_t cs, int16_t sram_cs = -1 ,
56
- int16_t busy = -1 ) {
57
- auto it = FactoryDrvDisp .find (driver_name);
58
- if (it == FactoryDrvDisp .end ())
76
+ dispDrvBase *CreateDrvDispEpd (const char *driver_name, int16_t dc, int16_t rst,
77
+ int16_t cs, int16_t sram_cs = -1 ,
78
+ int16_t busy = -1 ) {
79
+ auto it = FactoryDrvDispEpd .find (driver_name);
80
+ if (it == FactoryDrvDispEpd .end ())
59
81
return nullptr ;
60
82
61
83
return it->second (dc, rst, cs, sram_cs, busy);
62
84
}
63
85
86
+ /* !
87
+ @brief Creates a new SPI TFT display driver instance based on the driver
88
+ name.
89
+ @param driver_name
90
+ The name of the SPI TFT display driver to create.
91
+ */
92
+ dispDrvBase *CreateDrvDispTft (const char *driver_name, int16_t cs, int16_t dc,
93
+ int16_t mosi, int16_t sck, int16_t rst = -1 ,
94
+ int16_t miso = -1 ) {
95
+ auto it = FactoryDrvDispTft.find (driver_name);
96
+ if (it == FactoryDrvDispTft.end ())
97
+ return nullptr ;
98
+
99
+ return it->second (cs, dc, mosi, sck, rst, miso);
100
+ }
101
+
64
102
/* !
65
103
@brief Constructs a new DisplayHardware object
66
104
@param name
@@ -106,14 +144,13 @@ wippersnapper_display_v1_DisplayType DisplayHardware::getType() {
106
144
The pin string to parse.
107
145
@return The pin number, or -1 if the string is invalid.
108
146
*/
109
- int16_t DisplayHardware::parsePin (const char * pinStr) {
110
- if (!pinStr || strlen (pinStr) < 2 || pinStr[0 ] != ' D' ) {
111
- return -1 ;
112
- }
113
- return atoi (pinStr + 1 );
147
+ int16_t DisplayHardware::parsePin (const char * pinStr) {
148
+ if (!pinStr || strlen (pinStr) < 2 || pinStr[0 ] != ' D' ) {
149
+ return -1 ;
150
+ }
151
+ return atoi (pinStr + 1 );
114
152
}
115
153
116
-
117
154
/* !
118
155
@brief Configures the EPD display with the provided configuration.
119
156
@param config
@@ -179,7 +216,7 @@ bool DisplayHardware::beginEPD(
179
216
}
180
217
181
218
// Create display driver object using the factory function
182
- _drvDisp = CreateDrvDisp (_name, dc, rst, cs, srcs, busy);
219
+ _drvDisp = CreateDrvDispEpd (_name, dc, rst, cs, srcs, busy);
183
220
if (!_drvDisp) {
184
221
WS_DEBUG_PRINTLN (" [display] Failed to create display driver!" );
185
222
return false ; // Failed to create display driver
@@ -210,7 +247,9 @@ bool DisplayHardware::beginEPD(
210
247
Pointer to the SPI configuration structure for TFT.
211
248
@return True if configuration was successful, False otherwise.
212
249
*/
213
- bool DisplayHardware::beginTft (wippersnapper_display_v1_TftConfig *config, wippersnapper_display_v1_TftSpiConfig *spi_config) {
250
+ bool DisplayHardware::beginTft (
251
+ wippersnapper_display_v1_TftConfig *config,
252
+ wippersnapper_display_v1_TftSpiConfig *spi_config) {
214
253
// Validate pointers
215
254
if (config == nullptr || spi_config == nullptr ) {
216
255
WS_DEBUG_PRINTLN (" [display] EPD config or SPI config is null!" );
@@ -239,7 +278,7 @@ bool DisplayHardware::beginTft(wippersnapper_display_v1_TftConfig *config, wippe
239
278
miso = parsePin (spi_config->pin_miso );
240
279
}
241
280
242
- return false ;
281
+ return false ;
243
282
}
244
283
245
284
/* !
0 commit comments