22
22
23
23
#ifdef ARDUINO_INKPLATE4
24
24
25
- SPISettings epdSpiSettings (1000000UL , MSBFIRST, SPI_MODE0);
25
+ SPISettings epdSpiSettings (4000000UL , MSBFIRST, SPI_MODE0);
26
26
27
27
/* *
28
28
* @brief begin function initialize Inkplate object with predefined
@@ -54,12 +54,15 @@ bool Inkplate::begin()
54
54
return false ;
55
55
}
56
56
57
+ // Init TwoWire and GPIO expander
58
+ setIOExpanderForLowPower ();
59
+
60
+ // Set the default text color
61
+ setTextColor (INKPLATE_BLACK);
62
+
57
63
// Clear frame buffer
58
64
clearDisplay ();
59
65
60
- // Set default rotation
61
- setRotation (0 );
62
-
63
66
_beginDone = 1 ;
64
67
}
65
68
@@ -150,7 +153,7 @@ void Inkplate::display(bool leaveOn) // Leave on does nothing
150
153
sendCommand (0x20 ); // Activate Display Update Sequence
151
154
152
155
delayMicroseconds (500 ); // Wait at least 200 uS
153
- waitForEpd (60000 );
156
+ waitForEpd (24000 );
154
157
}
155
158
156
159
/* *
@@ -165,15 +168,42 @@ void Inkplate::setPanelDeepSleep(bool _state)
165
168
166
169
if (_panelState)
167
170
{
171
+ // Set SPI pins
172
+ SPI.begin (EPAPER_CLK, -1 , EPAPER_DIN, -1 );
173
+
174
+ // Set up EPD communication pins
175
+ pinMode (EPAPER_CS_PIN, OUTPUT);
176
+ pinMode (EPAPER_DC_PIN, OUTPUT);
177
+ pinMode (EPAPER_RST_PIN, OUTPUT);
178
+ pinMode (EPAPER_BUSY_PIN, INPUT_PULLUP);
179
+
180
+ delay (10 );
181
+
168
182
// Send commands to power up panel. According to the datasheet, it can be
169
183
// powered up from deep sleep only by reseting it and doing reinit.
170
184
begin ();
171
185
}
172
186
else
173
187
{
174
- sendCommand (0x10 );
175
- sendData (0x01 );
176
- delay (100 );
188
+ sendCommand (0X50 ); // VCOM and data interval setting
189
+ sendData (0xf7 );
190
+
191
+ sendCommand (0X02 ); // Power EPD off
192
+ waitForEpd (BUSY_TIMEOUT_MS);
193
+ sendCommand (0X07 ); // Put EPD in deep sleep
194
+ sendData (0xA5 );
195
+ delay (1 );
196
+
197
+ // Disable SPI
198
+ SPI.end ();
199
+
200
+ // To reduce power consumption, set SPI pins as outputs
201
+ pinMode (EPAPER_RST_PIN, INPUT);
202
+ pinMode (EPAPER_DC_PIN, INPUT);
203
+ pinMode (EPAPER_CS_PIN, INPUT);
204
+ pinMode (EPAPER_BUSY_PIN, INPUT);
205
+ pinMode (EPAPER_CLK, INPUT);
206
+ pinMode (EPAPER_DIN, INPUT);
177
207
}
178
208
}
179
209
@@ -295,19 +325,22 @@ void Graphics::writePixel(int16_t x0, int16_t y0, uint16_t _color)
295
325
{
296
326
if (x0 > width () - 1 || y0 > height () - 1 || x0 < 0 || y0 < 0 )
297
327
return ;
328
+
298
329
if (_color > 2 )
299
330
return ;
300
331
301
332
switch (rotation)
302
333
{
303
334
case 0 :
304
335
x0 = width () - 1 - x0;
336
+ y0 = y0 + 1 ;
305
337
break ;
306
338
case 1 :
307
339
_swap_int16_t (x0, y0);
308
340
break ;
309
341
case 2 :
310
342
y0 = height () - y0 - 1 ;
343
+ x0 = x0 + 1 ;
311
344
break ;
312
345
case 3 :
313
346
_swap_int16_t (x0, y0);
@@ -323,14 +356,64 @@ void Graphics::writePixel(int16_t x0, int16_t y0, uint16_t _color)
323
356
// half is for red pixels only
324
357
if (_color < 2 )
325
358
{
359
+ // Draw the Black/White pixel and clear the red pixel
326
360
*(DMemory4Bit + E_INK_WIDTH / 8 * y0 + _x) |= (pixelMaskLUT[7 - _x_sub]);
327
361
*(DMemory4Bit + E_INK_WIDTH / 8 * y0 + _x) &= ~(_color << (7 - _x_sub));
328
362
*(DMemory4Bit + (E_INK_WIDTH * E_INK_HEIGHT / 8 ) + E_INK_WIDTH / 8 * y0 + _x) &= ~(pixelMaskLUT[7 - _x_sub]);
329
363
}
330
364
else
331
365
{
366
+ // Draw a red pixel in the set coordinates
332
367
*(DMemory4Bit + (E_INK_WIDTH * E_INK_HEIGHT / 8 ) + E_INK_WIDTH / 8 * y0 + _x) |= (pixelMaskLUT[7 - _x_sub]);
333
368
}
334
369
}
335
370
371
+ /* *
372
+ * @brief setIOExpanderForLowPower initiates I/O Expander pins for low power, and puts
373
+ * them in OUTPUT LOW because they are using least amount of current in deep
374
+ * sleep that way
375
+ */
376
+ void Inkplate::setIOExpanderForLowPower ()
377
+ {
378
+ Wire.begin ();
379
+ memset (ioRegsInt, 0 , 22 );
380
+ ioBegin (IO_INT_ADDR, ioRegsInt);
381
+
382
+ // TOUCHPAD PINS
383
+ pinModeInternal (IO_INT_ADDR, ioRegsInt, IO_PIN_B2, INPUT);
384
+ pinModeInternal (IO_INT_ADDR, ioRegsInt, IO_PIN_B3, INPUT);
385
+ pinModeInternal (IO_INT_ADDR, ioRegsInt, IO_PIN_B4, INPUT);
386
+
387
+ // Battery voltage Switch MOSFET
388
+ pinModeInternal (IO_INT_ADDR, ioRegsInt, IO_PIN_B1, OUTPUT);
389
+
390
+ // Rest of pins go to OUTPUT LOW state because in deepSleep mode they are
391
+ // using least amount of power
392
+ pinModeInternal (IO_INT_ADDR, ioRegsInt, IO_PIN_A0, OUTPUT);
393
+ pinModeInternal (IO_INT_ADDR, ioRegsInt, IO_PIN_A1, OUTPUT);
394
+ pinModeInternal (IO_INT_ADDR, ioRegsInt, IO_PIN_A2, OUTPUT);
395
+ pinModeInternal (IO_INT_ADDR, ioRegsInt, IO_PIN_A3, OUTPUT);
396
+ pinModeInternal (IO_INT_ADDR, ioRegsInt, IO_PIN_A4, OUTPUT);
397
+ pinModeInternal (IO_INT_ADDR, ioRegsInt, IO_PIN_A5, OUTPUT);
398
+ pinModeInternal (IO_INT_ADDR, ioRegsInt, IO_PIN_A6, OUTPUT);
399
+ pinModeInternal (IO_INT_ADDR, ioRegsInt, IO_PIN_A7, OUTPUT);
400
+ pinModeInternal (IO_INT_ADDR, ioRegsInt, IO_PIN_B0, OUTPUT);
401
+ pinModeInternal (IO_INT_ADDR, ioRegsInt, IO_PIN_B5, OUTPUT);
402
+ pinModeInternal (IO_INT_ADDR, ioRegsInt, IO_PIN_B6, OUTPUT);
403
+ pinModeInternal (IO_INT_ADDR, ioRegsInt, IO_PIN_B7, OUTPUT);
404
+
405
+ digitalWriteInternal (IO_INT_ADDR, ioRegsInt, IO_PIN_A0, LOW);
406
+ digitalWriteInternal (IO_INT_ADDR, ioRegsInt, IO_PIN_A1, LOW);
407
+ digitalWriteInternal (IO_INT_ADDR, ioRegsInt, IO_PIN_A2, LOW);
408
+ digitalWriteInternal (IO_INT_ADDR, ioRegsInt, IO_PIN_A3, LOW);
409
+ digitalWriteInternal (IO_INT_ADDR, ioRegsInt, IO_PIN_A4, LOW);
410
+ digitalWriteInternal (IO_INT_ADDR, ioRegsInt, IO_PIN_A5, LOW);
411
+ digitalWriteInternal (IO_INT_ADDR, ioRegsInt, IO_PIN_A6, LOW);
412
+ digitalWriteInternal (IO_INT_ADDR, ioRegsInt, IO_PIN_A7, LOW);
413
+ digitalWriteInternal (IO_INT_ADDR, ioRegsInt, IO_PIN_B0, LOW);
414
+ digitalWriteInternal (IO_INT_ADDR, ioRegsInt, IO_PIN_B5, LOW);
415
+ digitalWriteInternal (IO_INT_ADDR, ioRegsInt, IO_PIN_B6, LOW);
416
+ digitalWriteInternal (IO_INT_ADDR, ioRegsInt, IO_PIN_B7, LOW);
417
+ }
418
+
336
419
#endif
0 commit comments