|
47 | 47 | #include "../../libs/imageProcessing/ditherKernels.h" |
48 | 48 |
|
49 | 49 | // Defines for EPD GPIOs |
50 | | -#define EPD_DRIVER_PINS_OUTPUT 0 |
51 | | -#define EPD_DRIVER_PINS_H_ZI 1 |
| 50 | +#define EPD_DRIVER_PINS_OUTPUT 0 |
| 51 | +#define EPD_DRIVER_PINS_H_ZI 1 |
52 | 52 |
|
53 | 53 | // FMC address for sending data to the EPD. |
54 | | -#define EPD_FMC_ADDR 0x68000000 |
| 54 | +#define EPD_FMC_ADDR 0x68000000 |
55 | 55 |
|
56 | 56 | // Inplate Motion base class. |
57 | 57 | class Inkplate; |
@@ -93,7 +93,8 @@ static inline void vScanStart() |
93 | 93 | // Compiler be nice, please do not optimise this function. |
94 | 94 | __attribute__((optimize("O0"))) static inline void cycleDelay(uint32_t _cycles) |
95 | 95 | { |
96 | | - while(_cycles--); |
| 96 | + while (_cycles--) |
| 97 | + ; |
97 | 98 | } |
98 | 99 |
|
99 | 100 | // Start writing the first line into epaper display. |
@@ -125,157 +126,160 @@ __attribute__((always_inline)) static inline void vScanEnd() |
125 | 126 |
|
126 | 127 | class EPDDriver : public Helpers |
127 | 128 | { |
128 | | - public: |
129 | | - EPDDriver(); |
130 | | - int initDriver(Inkplate *_inkplatePtr); |
131 | | - void cleanFast(uint8_t *_clearWavefrom, uint8_t _wavefromPhases); |
132 | | - void clearDisplay(); |
133 | | - void partialUpdate(uint8_t _leaveOn = 0); |
134 | | - void display(uint8_t _leaveOn = 0); |
135 | | - int epdPSU(uint8_t _state); |
136 | | - bool loadWaveform(InkplateWaveform _customWaveform); |
137 | | - double readBattery(); |
138 | | - void selectDisplayMode(uint8_t _mode); |
139 | | - uint8_t getDisplayMode(); |
| 129 | + public: |
| 130 | + EPDDriver(); |
| 131 | + int initDriver(Inkplate *_inkplatePtr); |
| 132 | + void cleanFast(uint8_t *_clearWavefrom, uint8_t _wavefromPhases); |
| 133 | + void clearDisplay(); |
| 134 | + void partialUpdate(uint8_t _leaveOn = 0); |
| 135 | + void display(uint8_t _leaveOn = 0); |
| 136 | + int epdPSU(uint8_t _state); |
| 137 | + bool loadWaveform(InkplateWaveform _customWaveform); |
| 138 | + double readBattery(); |
| 139 | + void selectDisplayMode(uint8_t _mode); |
| 140 | + uint8_t getDisplayMode(); |
140 | 141 |
|
141 | | - // Set the automatic partial update. |
142 | | - void setFullUpdateTreshold(uint16_t _numberOfPartialUpdates); |
| 142 | + // Set the automatic partial update. |
| 143 | + void setFullUpdateTreshold(uint16_t _numberOfPartialUpdates); |
143 | 144 |
|
144 | | - // Should be moved into Inkplate.h or Graphics.h. |
145 | | - void drawBitmapFast(const uint8_t *_p); |
| 145 | + // Should be moved into Inkplate.h or Graphics.h. |
| 146 | + void drawBitmapFast(const uint8_t *_p); |
146 | 147 |
|
147 | | - // Initializer for microSD card. |
148 | | - bool microSDCardInit(); |
| 148 | + // Initializer for microSD card. |
| 149 | + bool microSDCardInit(); |
149 | 150 |
|
150 | | - // Enable selected peripherals. |
151 | | - void peripheralState(uint8_t _peripheral, bool _en); |
| 151 | + // Enable selected peripherals. |
| 152 | + void peripheralState(uint8_t _peripheral, bool _en); |
152 | 153 |
|
153 | | - // Object for ePaper power managment IC. |
154 | | - EpdPmic pmic; |
| 154 | + // Object for ePaper power managment IC. |
| 155 | + EpdPmic pmic; |
155 | 156 |
|
156 | | - // Object for GPIO expander. |
157 | | - IOExpander internalIO; |
| 157 | + // Object for GPIO expander. |
| 158 | + IOExpander internalIO; |
158 | 159 |
|
159 | | - // Object for the STM32 built-in RTC. |
160 | | - STM32H7RTC rtc; |
| 160 | + // Object for the STM32 built-in RTC. |
| 161 | + STM32H7RTC rtc; |
161 | 162 |
|
162 | | - // Object for the magnetic rotary encoder. |
163 | | - AS5600 rotaryEncoder; |
| 163 | + // Object for the magnetic rotary encoder. |
| 164 | + AS5600 rotaryEncoder; |
164 | 165 |
|
165 | | - // Object for NeoPixel LED. |
166 | | - Adafruit_NeoPixel led = Adafruit_NeoPixel(2, INKPLATE_WSLED_DIN, NEO_GRB + NEO_KHZ800); |
| 166 | + // Object for NeoPixel LED. |
| 167 | + Adafruit_NeoPixel led = Adafruit_NeoPixel(2, INKPLATE_WSLED_DIN, NEO_GRB + NEO_KHZ800); |
167 | 168 |
|
168 | | - // Object for SHTC3 temperature and humidity sensor. |
169 | | - SHTC3 shtc3; |
| 169 | + // Object for SHTC3 temperature and humidity sensor. |
| 170 | + SHTC3 shtc3; |
170 | 171 |
|
171 | | - // Object for the ADPS9960 Sensor. |
172 | | - SparkFun_APDS9960 apds9960; |
| 172 | + // Object for the ADPS9960 Sensor. |
| 173 | + SparkFun_APDS9960 apds9960; |
173 | 174 |
|
174 | | - // Object for LSM6DSO32 accelerometer & gyroscope. |
175 | | - Adafruit_LSM6DSO32 lsm6dso32; |
| 175 | + // Object for LSM6DSO32 accelerometer & gyroscope. |
| 176 | + Adafruit_LSM6DSO32 lsm6dso32; |
176 | 177 |
|
177 | | - // Object for the Inkplate on-board micro SD card. |
178 | | - SdFat sdFat; |
| 178 | + // Object for the Inkplate on-board micro SD card. |
| 179 | + SdFat sdFat; |
179 | 180 |
|
180 | | - // Inkplate Motion object, needed for drawPixel. |
181 | | - Inkplate *_inkplate; |
| 181 | + // Inkplate Motion object, needed for drawPixel. |
| 182 | + Inkplate *_inkplate; |
182 | 183 |
|
183 | | - // Class for image decode in Inkplate Motion library. |
184 | | - ImageDecoder image; |
| 184 | + // Class for image decode in Inkplate Motion library. |
| 185 | + ImageDecoder image; |
185 | 186 |
|
186 | | - // Class for the image processing (grayscale, color invert, dither). |
187 | | - ImageProcessing imgProcess; |
| 187 | + // Class for the image processing (grayscale, color invert, dither). |
| 188 | + ImageProcessing imgProcess; |
188 | 189 |
|
189 | | - // If needed, DMA buffers used in drivers can be used for something else. |
190 | | - volatile uint8_t *_dmaBuffer[3]; |
| 190 | + // If needed, DMA buffers used in drivers can be used for something else. |
| 191 | + volatile uint8_t *_dmaBuffer[3]; |
191 | 192 |
|
192 | | - protected: |
193 | | - // Function initializes all GPIO pins used on Inkplate for driving EPD. |
194 | | - void gpioInit(); |
| 193 | + protected: |
| 194 | + // Function initializes all GPIO pins used on Inkplate for driving EPD. |
| 195 | + void gpioInit(); |
195 | 196 |
|
196 | | - // External SRAM frame buffers astart addresses. Statically allocated due speed. |
197 | | - // Frame buffer for current image on the screen. 2MB in size (2097152 bytes). |
198 | | - volatile uint8_t *_currentScreenFB = (uint8_t *)0xD0000000; |
| 197 | + // External SRAM frame buffers astart addresses. Statically allocated due speed. |
| 198 | + // Frame buffer for current image on the screen. 2MB in size (2097152 bytes). |
| 199 | + volatile uint8_t *_currentScreenFB = (uint8_t *)0xD0000000; |
199 | 200 |
|
200 | | - // Frame buffer for the image that will be written to the screen on update. 2MB in size (2097152 bytes). |
201 | | - volatile uint8_t *_pendingScreenFB = (uint8_t *)0xD0200000; |
| 201 | + // Frame buffer for the image that will be written to the screen on update. 2MB in size (2097152 bytes). |
| 202 | + volatile uint8_t *_pendingScreenFB = (uint8_t *)0xD0200000; |
202 | 203 |
|
203 | | - // "Scratchpad memory" used for calculations (partial update for example). 2MB in size (2097152 bytes). |
204 | | - volatile uint8_t *_scratchpadMemory = (uint8_t *)0xD0400000; |
| 204 | + // "Scratchpad memory" used for calculations (partial update for example). 2MB in size (2097152 bytes). |
| 205 | + volatile uint8_t *_scratchpadMemory = (uint8_t *)0xD0400000; |
205 | 206 |
|
206 | | - // Buffer for downloading files from the web. 4MB in size (4194304 bytes). |
207 | | - volatile uint8_t *_downloadFileMemory = (uint8_t *)0xD0800000; |
| 207 | + // Buffer for downloading files from the web. 4MB in size (4194304 bytes). |
| 208 | + volatile uint8_t *_downloadFileMemory = (uint8_t *)0xD0800000; |
208 | 209 |
|
209 | | - private: |
210 | | - // Sets EPD control GPIO pins to the output or High-Z state. |
211 | | - void epdGpioState(uint8_t _state); |
| 210 | + private: |
| 211 | + // Sets EPD control GPIO pins to the output or High-Z state. |
| 212 | + void epdGpioState(uint8_t _state); |
212 | 213 |
|
213 | | - // Function calculates 4 pixels at once from 4 bit per pixel buffer on the fly (before start writing new frame). |
214 | | - // With this we can crate LUT that will take all 4 pixels from the frame buffer and convert them into waveform. |
215 | | - void calculateGLUTOnTheFly(uint8_t *_lut, uint8_t *_waveform); |
| 214 | + // Function calculates 4 pixels at once from 4 bit per pixel buffer on the fly (before start writing new frame). |
| 215 | + // With this we can crate LUT that will take all 4 pixels from the frame buffer and convert them into waveform. |
| 216 | + void calculateGLUTOnTheFly(uint8_t *_lut, uint8_t *_waveform); |
216 | 217 |
|
217 | | - // Function calculates the difference between tfo framebuffers (usually between current image on the screen and pending in the MCU memory). |
218 | | - void differenceMask(uint8_t *_currentScreenFB, uint8_t *_pendingScreenFB, uint8_t *_differenceMask); |
| 218 | + // Function calculates the difference between tfo framebuffers (usually between current image on the screen and |
| 219 | + // pending in the MCU memory). |
| 220 | + void differenceMask(uint8_t *_currentScreenFB, uint8_t *_pendingScreenFB, uint8_t *_differenceMask); |
219 | 221 |
|
220 | | - // Internal method for global 1 bit ePaper screen update. |
221 | | - void display1b(uint8_t _leaveOn); |
222 | | - |
223 | | - // Internal method for global 4 bit ePaper screen update. |
224 | | - void display4b(uint8_t _leaveOn); |
| 222 | + // Internal method for global 1 bit ePaper screen update. |
| 223 | + void display1b(uint8_t _leaveOn); |
225 | 224 |
|
226 | | - // Universal method fot the ePaper screen update. |
227 | | - void pixelsUpdate(volatile uint8_t *_frameBuffer, uint8_t *_waveformLut, void (*_pixelDecode)(void*, void*, void*), const uint8_t _prebufferedLines, uint8_t _bitsPerPx); |
| 225 | + // Internal method for global 4 bit ePaper screen update. |
| 226 | + void display4b(uint8_t _leaveOn); |
228 | 227 |
|
229 | | - // Mode dependant methods for conversion framebuffer data into waveforem data. Used by the pixelsUpdate. |
230 | | - static void pixelDecode4BitEPD(void *_out, void *_lut, void *_fb); |
231 | | - static void pixelDecode1BitEPDFull(void *_out, void *_lut, void *_fb); |
232 | | - static void pixelDecode1BitEPDPartial(void *_out, void *_lut, void *_fb); |
| 228 | + // Universal method fot the ePaper screen update. |
| 229 | + void pixelsUpdate(volatile uint8_t *_frameBuffer, uint8_t *_waveformLut, |
| 230 | + void (*_pixelDecode)(void *, void *, void *), const uint8_t _prebufferedLines, |
| 231 | + uint8_t _bitsPerPx); |
233 | 232 |
|
234 | | - // Internal 4 bit partial update method. |
235 | | - void partialUpdate4Bit(uint8_t _leaveOn); |
| 233 | + // Mode dependant methods for conversion framebuffer data into waveforem data. Used by the pixelsUpdate. |
| 234 | + static void pixelDecode4BitEPD(void *_out, void *_lut, void *_fb); |
| 235 | + static void pixelDecode1BitEPDFull(void *_out, void *_lut, void *_fb); |
| 236 | + static void pixelDecode1BitEPDPartial(void *_out, void *_lut, void *_fb); |
236 | 237 |
|
237 | | - // Internal 1 bit partial update method. |
238 | | - void partialUpdate1Bit(uint8_t _leaveOn); |
| 238 | + // Internal 4 bit partial update method. |
| 239 | + void partialUpdate4Bit(uint8_t _leaveOn); |
239 | 240 |
|
240 | | - // Object for the SdFat SPI STM32 library. |
241 | | - SdSpiConfig* _microSDCardSPIConf = nullptr; |
| 241 | + // Internal 1 bit partial update method. |
| 242 | + void partialUpdate1Bit(uint8_t _leaveOn); |
242 | 243 |
|
243 | | - // Typedef handles for Master DMA. |
244 | | - MDMA_HandleTypeDef *_epdMdmaHandle; |
245 | | - MDMA_HandleTypeDef *_sdramMdmaHandle; |
| 244 | + // Object for the SdFat SPI STM32 library. |
| 245 | + SdSpiConfig *_microSDCardSPIConf = nullptr; |
246 | 246 |
|
247 | | - // Default EPD PSU state is off. |
248 | | - uint8_t _epdPSUState = 0; |
| 247 | + // Typedef handles for Master DMA. |
| 248 | + MDMA_HandleTypeDef *_epdMdmaHandle; |
| 249 | + MDMA_HandleTypeDef *_sdramMdmaHandle; |
249 | 250 |
|
250 | | - // Current display mode. By defaul, set it to 1 bit B&W mode. |
251 | | - uint8_t _displayMode = INKPLATE_1BW; |
252 | | - |
253 | | - // Block partial update at startup, use full update. |
254 | | - uint8_t _blockPartial = 1; |
| 251 | + // Default EPD PSU state is off. |
| 252 | + uint8_t _epdPSUState = 0; |
255 | 253 |
|
256 | | - // Internal typedef for the 4 bit waveform - global update. |
257 | | - InkplateWaveform _waveform4BitInternal = default4BitWavefrom; |
| 254 | + // Current display mode. By defaul, set it to 1 bit B&W mode. |
| 255 | + uint8_t _displayMode = INKPLATE_1BW; |
258 | 256 |
|
259 | | - // Internal typedef for the 1 bit mode waveform - global update. |
260 | | - InkplateWaveform _waveform1BitInternal = default1BitWavefrom; |
| 257 | + // Block partial update at startup, use full update. |
| 258 | + uint8_t _blockPartial = 1; |
261 | 259 |
|
262 | | - // Internal typedef for the 4 bit waveform - partial update. |
263 | | - InkplateWaveform _waveform4BitPartialInternal = default4BitPartialUpdate; |
| 260 | + // Internal typedef for the 4 bit waveform - global update. |
| 261 | + InkplateWaveform _waveform4BitInternal = default4BitWavefrom; |
264 | 262 |
|
265 | | - // Internal typedef for the 1 bit waveform - partial update. |
266 | | - InkplateWaveform _waveform1BitPartialInternal = default1BitPartialUpdate; |
| 263 | + // Internal typedef for the 1 bit mode waveform - global update. |
| 264 | + InkplateWaveform _waveform1BitInternal = default1BitWavefrom; |
267 | 265 |
|
268 | | - // Variable keeps track on how many partial updates have been executed for automatic full update. |
269 | | - uint16_t _partialUpdateCounter = 0; |
| 266 | + // Internal typedef for the 4 bit waveform - partial update. |
| 267 | + InkplateWaveform _waveform4BitPartialInternal = default4BitPartialUpdate; |
270 | 268 |
|
271 | | - // Variable that set the user-defined treshold for the full update. If zero, automatic full update is disabled. |
272 | | - uint16_t _partialUpdateLimiter = 0; |
| 269 | + // Internal typedef for the 1 bit waveform - partial update. |
| 270 | + InkplateWaveform _waveform1BitPartialInternal = default1BitPartialUpdate; |
273 | 271 |
|
274 | | - // Variable keeps current status of the microSD card initializaton. |
275 | | - bool _microSdInit = false; |
| 272 | + // Variable keeps track on how many partial updates have been executed for automatic full update. |
| 273 | + uint16_t _partialUpdateCounter = 0; |
276 | 274 |
|
277 | | - // Fast LUT table for conversion from 2 * 4 bit grayscale pixel to EPD Wavefrom. |
278 | | - uint8_t _fastGLUT[65536]; |
| 275 | + // Variable that set the user-defined treshold for the full update. If zero, automatic full update is disabled. |
| 276 | + uint16_t _partialUpdateLimiter = 0; |
| 277 | + |
| 278 | + // Variable keeps current status of the microSD card initializaton. |
| 279 | + bool _microSdInit = false; |
| 280 | + |
| 281 | + // Fast LUT table for conversion from 2 * 4 bit grayscale pixel to EPD Wavefrom. |
| 282 | + uint8_t _fastGLUT[65536]; |
279 | 283 | }; |
280 | 284 |
|
281 | 285 | #endif |
|
0 commit comments