1717/* !
1818 @brief Lambda function to create a dispDrvBase instance
1919*/
20- using FnCreateDispDrv =
20+ using FnCreateDispDrvEpd =
2121 std::function<dispDrvBase *(int16_t , int16_t , int16_t , int16_t , int16_t )>;
2222
2323// Factory for creating a new display drivers
2424// 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 = {
2626 {" thinkink-gs4-eaamfgn" ,
2727 [](int16_t dc, int16_t rst, int16_t cs, int16_t sram_cs,
2828 int16_t busy) -> dispDrvBase * {
@@ -35,7 +35,29 @@ static const std::map<std::string, FnCreateDispDrv> FactoryDrvDisp = {
3535 }}};
3636
3737/* !
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.
3961 @param driver_name
4062 The name of the display driver to create.
4163 @param dc
@@ -51,16 +73,32 @@ static const std::map<std::string, FnCreateDispDrv> FactoryDrvDisp = {
5173 @return Pointer to the created display driver instance, or nullptr if the
5274 driver name is not recognized.
5375*/
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 ())
5981 return nullptr ;
6082
6183 return it->second (dc, rst, cs, sram_cs, busy);
6284}
6385
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+
64102/* !
65103 @brief Constructs a new DisplayHardware object
66104 @param name
@@ -106,14 +144,13 @@ wippersnapper_display_v1_DisplayType DisplayHardware::getType() {
106144 The pin string to parse.
107145 @return The pin number, or -1 if the string is invalid.
108146*/
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 );
114152}
115153
116-
117154/* !
118155 @brief Configures the EPD display with the provided configuration.
119156 @param config
@@ -179,7 +216,7 @@ bool DisplayHardware::beginEPD(
179216 }
180217
181218 // 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);
183220 if (!_drvDisp) {
184221 WS_DEBUG_PRINTLN (" [display] Failed to create display driver!" );
185222 return false ; // Failed to create display driver
@@ -210,7 +247,9 @@ bool DisplayHardware::beginEPD(
210247 Pointer to the SPI configuration structure for TFT.
211248 @return True if configuration was successful, False otherwise.
212249*/
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) {
214253 // Validate pointers
215254 if (config == nullptr || spi_config == nullptr ) {
216255 WS_DEBUG_PRINTLN (" [display] EPD config or SPI config is null!" );
@@ -239,7 +278,7 @@ bool DisplayHardware::beginTft(wippersnapper_display_v1_TftConfig *config, wippe
239278 miso = parsePin (spi_config->pin_miso );
240279 }
241280
242- return false ;
281+ return false ;
243282}
244283
245284/* !
0 commit comments