@@ -34,15 +34,15 @@ DisplayHardware::DisplayHardware() {
3434 The display type to set.
3535*/
3636void DisplayHardware::setType (wippersnapper_display_v1_DisplayType type) {
37- _type = type;
37+ _type = type;
3838}
3939
4040/* !
4141 @brief Gets the hardware's display type.
4242 @return The current display type.
4343*/
4444wippersnapper_display_v1_DisplayType DisplayHardware::getType () {
45- return _type;
45+ return _type;
4646}
4747
4848/* !
@@ -53,37 +53,106 @@ wippersnapper_display_v1_DisplayType DisplayHardware::getType() {
5353 Pointer to the SPI configuration structure for EPD.
5454 @return True if configuration was successful, False otherwise.
5555*/
56- bool DisplayHardware::beginEPD (wippersnapper_display_v1_EPDConfig *config, wippersnapper_display_v1_EpdSpiConfig *spi_config) {
57- // Convert pins in config to int16_t instances
58- int16_t dc = -1 , rst = -1 , cs = -1 , srcs = -1 , busy = -1 ;
59- dc = (int16_t )atoi (spi_config->pin_dc + 1 );
60- rst = (int16_t )atoi (spi_config->pin_rst + 1 );
61- cs = (int16_t )atoi (spi_config->pin_cs + 1 );
62- srcs = (int16_t )atoi (spi_config->pin_sram_cs + 1 );
63- busy = (int16_t )atoi (spi_config->pin_busy + 1 );
64-
65- // Configure EPD mode
66- thinkinkmode_t epd_mode;
67- if (config->mode == wippersnapper_display_v1_EPDMode_EPD_MODE_GRAYSCALE4) {
68- epd_mode = THINKINK_GRAYSCALE4;
69- } else if (config->mode == wippersnapper_display_v1_EPDMode_EPD_MODE_MONO) {
70- epd_mode = THINKINK_MONO;
71- } else {
72- epd_mode = THINKINK_MONO; // Default to mono
73- }
74-
75- // Assign driver instance based on panel type
76- if (config->panel == wippersnapper_display_v1_EPDThinkInkPanel_EPD_THINK_INK_PANEL_213_GRAYSCALE4_MFGN) {
77- _disp_thinkink_grayscale4_eaamfgn = new ThinkInk_290_Grayscale4_EAAMFGN (dc, rst, cs, srcs, busy);
78- _disp_thinkink_grayscale4_eaamfgn->begin (epd_mode);
79- } else if (config->panel == wippersnapper_display_v1_EPDThinkInkPanel_EPD_THINK_INK_PANEL_213_GRAYSCALE4_T5) {
80- _disp_thinkink_grayscale4_t5 = new ThinkInk_290_Grayscale4_T5 (dc, rst, cs, srcs, busy);
81- _disp_thinkink_grayscale4_t5->begin (epd_mode);
82- } else {
83- return false ; // Unsupported panel type
84- }
85-
86- return true ; // Configuration successful
56+ bool DisplayHardware::beginEPD (
57+ wippersnapper_display_v1_EPDConfig *config,
58+ wippersnapper_display_v1_EpdSpiConfig *spi_config) {
59+ // Validate pointers
60+ if (config == nullptr || spi_config == nullptr ) {
61+ return false ;
62+ }
63+
64+ // Validate panel type
65+ if (config->panel ==
66+ wippersnapper_display_v1_EPDThinkInkPanel_EPD_THINK_INK_PANEL_UNSPECIFIED) {
67+ return false ; // Unsupported panel type
68+ }
69+
70+ // Validate mode is a correct EPD mode
71+ if (config->mode == wippersnapper_display_v1_EPDMode_EPD_MODE_UNSPECIFIED) {
72+ return false ; // Unsupported mode
73+ }
74+
75+ // If we already have a display driver assigned to this hardware instance,
76+ // clean it up!
77+ if (_thinkink_driver ==
78+ wippersnapper_display_v1_EPDThinkInkPanel_EPD_THINK_INK_PANEL_290_GRAYSCALE4_MFGN) {
79+ delete _disp_thinkink_grayscale4_eaamfgn;
80+ _disp_thinkink_grayscale4_eaamfgn = nullptr ;
81+ _thinkink_driver =
82+ wippersnapper_display_v1_EPDThinkInkPanel_EPD_THINK_INK_PANEL_UNSPECIFIED;
83+ } else if (
84+ _thinkink_driver ==
85+ wippersnapper_display_v1_EPDThinkInkPanel_EPD_THINK_INK_PANEL_290_GRAYSCALE4_T5) {
86+ delete _disp_thinkink_grayscale4_t5;
87+ _disp_thinkink_grayscale4_t5 = nullptr ;
88+ _thinkink_driver =
89+ wippersnapper_display_v1_EPDThinkInkPanel_EPD_THINK_INK_PANEL_UNSPECIFIED;
90+ }
91+
92+ // Parse all SPI bus pins
93+ // Check length
94+ if (strlen (spi_config->pin_dc ) < 2 || strlen (spi_config->pin_rst ) < 2 ||
95+ strlen (spi_config->pin_cs ) < 2 ) {
96+ return false ;
97+ }
98+ // SPI pins must start with 'D'
99+ if (spi_config->pin_dc [0 ] != ' D' || spi_config->pin_rst [0 ] != ' D' ||
100+ spi_config->pin_cs [0 ] != ' D' ) {
101+ return false ;
102+ }
103+
104+ // Parse and assign pins
105+ int16_t srcs = -1 , busy = -1 ;
106+ int16_t dc = (int16_t )atoi (spi_config->pin_dc + 1 );
107+ int16_t rst = (int16_t )atoi (spi_config->pin_rst + 1 );
108+ int16_t cs = (int16_t )atoi (spi_config->pin_cs + 1 );
109+
110+ // Optionally parse SRAM CS and BUSY pins
111+ if (strlen (spi_config->pin_sram_cs ) >= 2 &&
112+ spi_config->pin_sram_cs [0 ] == ' D' ) {
113+ srcs = (int16_t )atoi (spi_config->pin_sram_cs + 1 );
114+ }
115+ if (strlen (spi_config->pin_busy ) >= 2 && spi_config->pin_busy [0 ] == ' D' ) {
116+ busy = (int16_t )atoi (spi_config->pin_busy + 1 );
117+ }
118+
119+ // TODO: Configure SPI bus selection (UNUSED AS OF RIGHT NOW)
120+
121+ // Configure EPD mode
122+ thinkinkmode_t epd_mode;
123+ if (config->mode == wippersnapper_display_v1_EPDMode_EPD_MODE_GRAYSCALE4) {
124+ epd_mode = THINKINK_GRAYSCALE4;
125+ } else if (config->mode == wippersnapper_display_v1_EPDMode_EPD_MODE_MONO) {
126+ epd_mode = THINKINK_MONO;
127+ }
128+
129+ // Assign driver instance based on panel type
130+ if (config->panel ==
131+ wippersnapper_display_v1_EPDThinkInkPanel_EPD_THINK_INK_PANEL_290_GRAYSCALE4_MFGN) {
132+ _disp_thinkink_grayscale4_eaamfgn =
133+ new ThinkInk_290_Grayscale4_EAAMFGN (dc, rst, cs, srcs, busy);
134+ if (!_disp_thinkink_grayscale4_eaamfgn)
135+ return false ; // Allocation failed
136+ // Initialize the display
137+ _disp_thinkink_grayscale4_eaamfgn->begin (epd_mode);
138+ _thinkink_driver =
139+ wippersnapper_display_v1_EPDThinkInkPanel_EPD_THINK_INK_PANEL_290_GRAYSCALE4_MFGN;
140+ } else if (
141+ config->panel ==
142+ wippersnapper_display_v1_EPDThinkInkPanel_EPD_THINK_INK_PANEL_290_GRAYSCALE4_T5) {
143+ _disp_thinkink_grayscale4_t5 =
144+ new ThinkInk_290_Grayscale4_T5 (dc, rst, cs, srcs, busy);
145+ if (!_disp_thinkink_grayscale4_t5)
146+ return false ; // Allocation failed
147+ // Initialize the display
148+ _disp_thinkink_grayscale4_t5->begin (epd_mode);
149+ _thinkink_driver =
150+ wippersnapper_display_v1_EPDThinkInkPanel_EPD_THINK_INK_PANEL_290_GRAYSCALE4_T5;
151+ } else {
152+ return false ; // Unsupported panel type
153+ }
154+
155+ return true ; // Configuration successful
87156}
88157
89158/* !
@@ -93,7 +162,7 @@ bool DisplayHardware::beginEPD(wippersnapper_display_v1_EPDConfig *config, wippe
93162 @return True if initialization was successful, false otherwise.
94163*/
95164bool DisplayHardware::begin (bool reset) {
96- return true ; // Placeholder for actual initialization logic
165+ return true ; // Placeholder for actual initialization logic
97166}
98167
99168/* !
@@ -102,6 +171,5 @@ bool DisplayHardware::begin(bool reset) {
102171 The size of the text to set.
103172*/
104173void setTextSize (uint8_t sz) {
105- // Placeholder for setting text size on the display TODO
174+ // Placeholder for setting text size on the display TODO
106175}
107-
0 commit comments