Skip to content

Commit 28fc018

Browse files
committed
Fixed I2S, added support for Inkplate 6 FLICK hardware.
1 parent b7fb354 commit 28fc018

13 files changed

+233
-220
lines changed

src/Inkplate.cpp

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,29 @@ int Inkplate::einkOn()
127127
Wire.endTransmission();
128128
#endif
129129

130+
// TEST PUROSE ONLY, REMOVE LATER - OVERRIDE VCOM VALUE!
131+
uint8_t _vcomreg;
132+
uint16_t _vcomMillivolts = (uint16_t)(abs(-2.35 * 100));
133+
Wire.beginTransmission(0x48);
134+
Wire.write(0x04);
135+
Wire.endTransmission();
136+
137+
Wire.requestFrom(0x48, 1);
138+
_vcomreg = Wire.read() & 0b11111110;
139+
140+
Wire.beginTransmission(0x48);
141+
Wire.write(0x03);
142+
Wire.write(_vcomMillivolts & 0xff);
143+
Wire.write(_vcomMillivolts >> 8 | _vcomreg);
144+
Wire.endTransmission();
145+
// END
146+
130147
PWRUP_SET;
131148

132149
pinsAsOutputs();
133150
LE_CLEAR;
134151
OE_CLEAR;
135-
#if !defined(ARDUINO_ESP32_DEV) && !defined(ARDUINO_INKPLATE6V2) // Not used on Inkplate6 anymore.
152+
#if !defined(ARDUINO_ESP32_DEV) && !defined(ARDUINO_INKPLATE6V2) && !defined(ARDUINO_INKPLATE6FLICK)
136153
CL_CLEAR;
137154
#endif
138155
SPH_SET;
@@ -170,7 +187,7 @@ void Inkplate::einkOff()
170187
return;
171188
OE_CLEAR;
172189
GMOD_CLEAR;
173-
#if !defined(ARDUINO_ESP32_DEV) && !defined(ARDUINO_INKPLATE6V2) // Not used on Inkplate6 anymore.
190+
#if !defined(ARDUINO_ESP32_DEV) && !defined(ARDUINO_INKPLATE6V2) && !defined(ARDUINO_INKPLATE6FLICK)
174191
GPIO.out &= ~(DATA | LE | CL);
175192
#else
176193
LE_CLEAR;
@@ -302,8 +319,7 @@ void Inkplate::pinsZstate()
302319
pinMode(26, INPUT);
303320
pinMode(27, INPUT);
304321

305-
#if defined(ARDUINO_ESP32_DEV) || defined(ARDUINO_INKPLATE6V2) || defined(ARDUINO_INKPLATE5V2) || \
306-
defined(ARDUINO_INKPLATE6FLICK)
322+
#if defined(ARDUINO_ESP32_DEV) || defined(ARDUINO_INKPLATE6V2) || defined(ARDUINO_INKPLATE5V2) || defined(ARDUINO_INKPLATE6FLICK)
307323
// Disable clock for the EPD.
308324
myI2S->conf1.tx_stop_en = 0;
309325
#endif
@@ -321,8 +337,7 @@ void Inkplate::pinsAsOutputs()
321337
pinModeInternal(IO_INT_ADDR, ioRegsInt, GMOD, OUTPUT);
322338
pinModeInternal(IO_INT_ADDR, ioRegsInt, SPV, OUTPUT);
323339

324-
#if defined(ARDUINO_ESP32_DEV) || defined(ARDUINO_INKPLATE6V2) || defined(ARDUINO_INKPLATE5V2) || \
325-
defined(ARDUINO_INKPLATE6FLICK)
340+
#if defined(ARDUINO_ESP32_DEV) || defined(ARDUINO_INKPLATE6V2) || defined(ARDUINO_INKPLATE5V2) || defined(ARDUINO_INKPLATE6FLICK)
326341
// Set up the EPD Data and CL pins for I2S.
327342
setI2S1pin(0, I2S1O_BCK_OUT_IDX, 0);
328343
setI2S1pin(4, I2S1O_DATA_OUT0_IDX, 0);

src/boards/Inkplate5V2.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,8 @@ bool Inkplate::begin(void)
114114
return 0;
115115
}
116116

117-
// Init the I2S driver. It will allocate the memory for the I2S DMA descriptor and line buffer and setup a I2S
118-
// driver.
119-
I2SInit(myI2S, NULL, NULL);
117+
// Init the I2S driver. It will setup a I2S driver.
118+
I2SInit(myI2S);
120119

121120
// Battery voltage Switch MOSFET
122121
pinModeInternal(IO_INT_ADDR, ioRegsInt, 9, OUTPUT);

src/boards/Inkplate6.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,8 @@ bool Inkplate::begin(void)
127127
return 0;
128128
}
129129

130-
// Init the I2S driver. It will allocate the memory for the I2S DMA descriptor and line buffer and setup a I2S
131-
// driver.
132-
I2SInit(myI2S, NULL, NULL);
130+
// Init the I2S driver. It will setup a I2S driver.
131+
I2SInit(myI2S);
133132

134133
#ifndef ARDUINO_INKPLATE6V2
135134
// TOUCHPAD PINS

src/boards/Inkplate6FLICK.cpp

Lines changed: 44 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -88,22 +88,23 @@ bool Inkplate::begin(void)
8888
if (_beginDone == 1)
8989
return 0;
9090

91+
// Initialize Wire (I2C) library. Needed for I/O expander, RTC and ePaper PMIC.
9192
Wire.begin();
9293

93-
digitalWriteInternal(IO_INT_ADDR, ioRegsInt, 9, LOW);
94-
94+
// Clear registers for both I/O expanders.
9595
memset(ioRegsInt, 0, 22);
9696
memset(ioRegsEx, 0, 22);
9797

98+
// Initialize both I/O expanders.
9899
ioBegin(IO_INT_ADDR, ioRegsInt);
99100
ioBegin(IO_EXT_ADDR, ioRegsEx);
100101

102+
// Set control pins for ePaper PMIC to outputs.
101103
pinModeInternal(IO_INT_ADDR, ioRegsInt, VCOM, OUTPUT);
102104
pinModeInternal(IO_INT_ADDR, ioRegsInt, PWRUP, OUTPUT);
103105
pinModeInternal(IO_INT_ADDR, ioRegsInt, WAKEUP, OUTPUT);
104-
pinModeInternal(IO_INT_ADDR, ioRegsInt, GPIO0_ENABLE, OUTPUT);
105-
digitalWriteInternal(IO_INT_ADDR, ioRegsInt, GPIO0_ENABLE, HIGH);
106106

107+
// Enable ePaper PMIC to set proper power up sequence.
107108
WAKEUP_SET;
108109
delay(1);
109110
Wire.beginTransmission(0x48);
@@ -118,14 +119,25 @@ bool Inkplate::begin(void)
118119

119120
// To reduce power consumption in deep sleep, unused pins of
120121
// first I/O expander have to be also set as output with pulled low.
121-
pinModeInternal(IO_INT_ADDR, ioRegsInt, 11, OUTPUT);
122-
pinModeInternal(IO_INT_ADDR, ioRegsInt, 12, OUTPUT);
122+
// VBAT measurement MOSFET switch.
123+
pinModeInternal(IO_INT_ADDR, ioRegsInt, 9, OUTPUT);
124+
pinModeInternal(IO_INT_ADDR, ioRegsInt, TOUCHSCREEN_EN, OUTPUT);
125+
pinModeInternal(IO_INT_ADDR, ioRegsInt, TS_RST, OUTPUT);
126+
127+
// Frontlight.
123128
pinModeInternal(IO_INT_ADDR, ioRegsInt, 13, OUTPUT);
129+
130+
// Unused pins on internal GPIO expander.
124131
pinModeInternal(IO_INT_ADDR, ioRegsInt, 14, OUTPUT);
125132
pinModeInternal(IO_INT_ADDR, ioRegsInt, 15, OUTPUT);
126-
digitalWriteInternal(IO_INT_ADDR, ioRegsInt, 11, LOW);
127-
digitalWriteInternal(IO_INT_ADDR, ioRegsInt, 12, LOW);
128-
digitalWriteInternal(IO_INT_ADDR, ioRegsInt, 13, LOW);
133+
134+
// Disable touchscreen.
135+
tsInit(false);
136+
137+
// Disable frontlight.
138+
frontlight(false);
139+
140+
// Unused pins on internal GPIO expander.
129141
digitalWriteInternal(IO_INT_ADDR, ioRegsInt, 14, LOW);
130142
digitalWriteInternal(IO_INT_ADDR, ioRegsInt, 15, LOW);
131143

@@ -138,30 +150,29 @@ bool Inkplate::begin(void)
138150
// And also disable uSD card supply
139151
pinModeInternal(IO_INT_ADDR, ioRegsInt, SD_PMOS_PIN, INPUT);
140152

141-
// CONTROL PINS
153+
// Control pins for ePaper.
142154
pinMode(2, OUTPUT);
143155
pinMode(32, OUTPUT);
144156
pinMode(33, OUTPUT);
145157
pinModeInternal(IO_INT_ADDR, ioRegsInt, OE, OUTPUT);
146158
pinModeInternal(IO_INT_ADDR, ioRegsInt, GMOD, OUTPUT);
147159
pinModeInternal(IO_INT_ADDR, ioRegsInt, SPV, OUTPUT);
148160

149-
// Use only myI2S
161+
// Use only I2S1.
150162
myI2S = &I2S1;
151163

152164
// Allocate memory for DMA descriptor and line buffer.
153165
_dmaLineBuffer = (uint8_t *)heap_caps_malloc((E_INK_WIDTH / 4) + 16, MALLOC_CAP_DMA);
154166
_dmaI2SDesc = (lldesc_s *)heap_caps_malloc(sizeof(lldesc_t), MALLOC_CAP_DMA);
155167

156-
168+
// Check for successfull DMA allocation.
157169
if (_dmaLineBuffer == NULL || _dmaI2SDesc == NULL)
158170
{
159171
return 0;
160172
}
161173

162-
// Init the I2S driver. It will allocate the memory for the I2S DMA descriptor and line buffer and setup a I2S
163-
// driver.
164-
I2SInit(myI2S, NULL, NULL);
174+
// Init the I2S driver. It will setup a I2S driver.
175+
I2SInit(myI2S, 4);
165176

166177
// Battery voltage Switch MOSFET
167178
pinModeInternal(IO_INT_ADDR, ioRegsInt, 9, OUTPUT);
@@ -291,19 +302,19 @@ void Inkplate::display1b(bool leaveOn)
291302
if (!einkOn())
292303
return;
293304

294-
// Clear the screen.
295-
clean(0, 1);
296-
clean(1, 12);
305+
// Clear the screen (clear sequence).
306+
clean(0, 5);
307+
clean(1, 22);
297308
clean(2, 1);
298-
clean(0, 12);
309+
clean(0, 22);
299310
clean(2, 1);
300-
clean(1, 12);
311+
clean(1, 22);
301312
clean(2, 1);
302-
clean(0, 12);
313+
clean(0, 22);
303314
clean(2, 1);
304315

305316
// Write only black pixels.
306-
for (int k = 0; k < 4; ++k)
317+
for (int k = 0; k < 4; k++)
307318
{
308319
uint8_t *DMemoryNewPtr = DMemoryNew + (E_INK_WIDTH * E_INK_HEIGHT / 8) - 1;
309320
vscan_start();
@@ -326,7 +337,7 @@ void Inkplate::display1b(bool leaveOn)
326337
}
327338

328339
// Now write both black and white pixels.
329-
for (int k = 0; k < 1; ++k)
340+
for (int k = 0; k < 1; k++)
330341
{
331342
uint8_t *DMemoryNewPtr = DMemoryNew + (E_INK_WIDTH * E_INK_HEIGHT / 8) - 1;
332343
vscan_start();
@@ -350,7 +361,7 @@ void Inkplate::display1b(bool leaveOn)
350361
}
351362

352363
// Discharge sequence.
353-
for (int k = 0; k < 1; ++k)
364+
for (int k = 0; k < 1; k++)
354365
{
355366
vscan_start();
356367
for (int i = 0; i < E_INK_HEIGHT; ++i)
@@ -392,19 +403,18 @@ void Inkplate::display3b(bool leaveOn)
392403
return;
393404

394405
// Clear the screen (clear sequence).
395-
clean(0, 1);
396-
clean(1, 12);
406+
clean(0, 5);
407+
clean(1, 22);
397408
clean(2, 1);
398-
clean(0, 12);
409+
clean(0, 22);
399410
clean(2, 1);
400-
clean(1, 12);
411+
clean(1, 22);
401412
clean(2, 1);
402-
clean(0, 12);
413+
clean(0, 22);
403414
clean(2, 1);
404415

405-
// Update the screen with new image by using custom waveform for the grayscale (can be found in Inkplate6FLICK.h
406-
// file).
407-
for (int k = 0; k < 9; ++k)
416+
// Update the screen with new image by using custom waveform for the grayscale (can be found in Inkplate6FLICK.h file).
417+
for (int k = 0; k < 9; k++)
408418
{
409419
uint8_t *dp = DMemory4Bit + E_INK_WIDTH * E_INK_HEIGHT / 2;
410420

@@ -423,7 +433,7 @@ void Inkplate::display3b(bool leaveOn)
423433
}
424434
}
425435

426-
// Set ePapaer drivers into HiZ state.
436+
// Set ePapaer drivers into HiZ state.
427437
clean(3, 1);
428438

429439
// Keep the ePaper supply enabled if needed.
@@ -501,7 +511,7 @@ uint32_t Inkplate::partialUpdate(bool _forced, bool leaveOn)
501511
if (!einkOn())
502512
return 0;
503513

504-
for (int k = 0; k < 4; ++k)
514+
for (int k = 0; k < 4; k++)
505515
{
506516
vscan_start();
507517
n = (E_INK_WIDTH * E_INK_HEIGHT / 4) - 1;

src/boards/Inkplate6FLICK.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@
3131
#define FRONTLIGHT_EN 11
3232

3333
// Touchscreen defines
34-
#define TOUCHSCREEN_EN 12
35-
#define TS_RST 10
34+
#define TOUCHSCREEN_EN IO_PIN_B4
35+
#define TS_RST IO_PIN_B2
3636
#define TS_INT 36
3737
#define TOUCHSCREEN_IO_EXPANDER IO_INT_ADDR
3838
#define TOUCHSCREEN_IO_REGS ioRegsInt
3939

4040
#define WAVEFORM3BIT \
41-
{{0, 0, 0, 1, 2, 1, 1, 1, 0}, {0, 0, 1, 2, 1, 1, 2, 1, 0}, {0, 0, 0, 1, 1, 1, 1, 2, 0}, \
42-
{0, 1, 2, 2, 1, 1, 1, 2, 0}, {0, 1, 2, 1, 2, 1, 1, 2, 0}, {1, 1, 1, 2, 1, 2, 1, 2, 0}, \
43-
{0, 0, 1, 2, 1, 2, 1, 2, 0}, {0, 0, 0, 0, 0, 0, 0, 2, 0}};
41+
{{0, 0, 0, 0, 0, 1, 1, 1, 0}, {0, 0, 1, 2, 1, 1, 2, 1, 0}, {0, 1, 1, 2, 1, 1, 1, 2, 0}, \
42+
{1, 1, 1, 2, 2, 1, 1, 2, 0}, {1, 1, 1, 2, 1, 2, 1, 2, 0}, {0, 1, 1, 2, 1, 2, 1, 2, 0}, \
43+
{1, 2, 1, 1, 2, 2, 1, 2, 0}, {0, 0, 0, 0, 0, 0, 0, 2, 0}};
4444

4545
#endif

src/include/Esp.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*
2727
* @note Function must be declared static to fit into Instruction RAM of the ESP32.
2828
*/
29-
void IRAM_ATTR I2SInit(i2s_dev_t *_i2sDev, volatile lldesc_s **_dmaDecs, uint8_t **_buffer)
29+
void IRAM_ATTR I2SInit(i2s_dev_t *_i2sDev, uint8_t _clockDivider)
3030
{
3131
// Enable I2S peripheral and reset it.
3232
periph_module_enable(PERIPH_I2S1_MODULE);
@@ -62,12 +62,12 @@ void IRAM_ATTR I2SInit(i2s_dev_t *_i2sDev, volatile lldesc_s **_dmaDecs, uint8_t
6262
_i2sDev->sample_rate_conf.rx_bck_div_num = 2;
6363
_i2sDev->sample_rate_conf.tx_bck_div_num = 2;
6464

65-
// Do not use APLL, divide by 5, BCK should be ~16MHz.
65+
// Do not use APLL, divide by 5 by default, BCK should be ~16MHz.
6666
_i2sDev->clkm_conf.val = 0;
6767
_i2sDev->clkm_conf.clka_en = 0;
6868
_i2sDev->clkm_conf.clkm_div_b = 0;
6969
_i2sDev->clkm_conf.clkm_div_a = 1;
70-
_i2sDev->clkm_conf.clkm_div_num = 5;
70+
_i2sDev->clkm_conf.clkm_div_num = _clockDivider;
7171

7272
// FIFO buffer setup. Byte packing for FIFO: 0A0B_0B0C = 0, 0A0B_0C0D = 1, 0A00_0B00 = 3. Use dual mono single data
7373
_i2sDev->fifo_conf.val = 0;

src/include/Esp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#include "soc/rtc.h"
3030
#include "soc/soc.h"
3131

32-
void IRAM_ATTR I2SInit(volatile i2s_dev_t *_i2sDev, volatile lldesc_s **_dmaDecs, uint8_t **_buffer);
32+
void IRAM_ATTR I2SInit(volatile i2s_dev_t *_i2sDev, uint8_t _clockDivider = 5);
3333
void IRAM_ATTR sendDataI2S(volatile i2s_dev_t *_i2sDev, volatile lldesc_s *_dmaDecs);
3434
void IRAM_ATTR setI2S1pin(uint32_t _pin, uint32_t _function, uint32_t _inv);
3535

src/include/Frontlight.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
#include "Frontlight.h"
2020
#include "defines.h"
2121

22-
#if defined(ARDUINO_INKPLATE6PLUS) || defined(ARDUINO_INKPLATE6PLUSV2) || defined(ARDUINO_INKPLATE4TEMPERA) || \
23-
defined(ARDUINO_INKPLATE6FLICK)
22+
#if defined(ARDUINO_INKPLATE6PLUS) || defined(ARDUINO_INKPLATE6PLUSV2) || defined(ARDUINO_INKPLATE4TEMPERA) || defined(ARDUINO_INKPLATE6FLICK)
2423

2524
/**
2625
* @brief setFrontlight function sets frontlight intensity for inkplate

src/include/Frontlight.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
#ifndef __FRONTLIGHT_H__
1919
#define __FRONTLIGHT_H__
2020

21-
#if defined(ARDUINO_INKPLATE6PLUS) || defined(ARDUINO_INKPLATE6PLUSV2) || defined(ARDUINO_INKPLATE4TEMPERA) || \
22-
defined(ARDUINO_INKPLATE6FLICK)
21+
#if defined(ARDUINO_INKPLATE6PLUS) || defined(ARDUINO_INKPLATE6PLUSV2) || defined(ARDUINO_INKPLATE4TEMPERA) || defined(ARDUINO_INKPLATE6FLICK)
2322

2423
#include "Arduino.h"
2524
#include "Wire.h"

src/include/System.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@
7676
#define RTC_7PF 0
7777
#define RTC_12_5PF 1
7878

79-
#if defined(ARDUINO_INKPLATE6PLUS) || defined(ARDUINO_INKPLATE6PLUSV2) || defined(ARDUINO_INKPLATE4TEMPERA) || \
80-
defined(ARDUINO_INKPLATE6FLICK)
79+
#if defined(ARDUINO_INKPLATE6PLUS) || defined(ARDUINO_INKPLATE6PLUSV2) || defined(ARDUINO_INKPLATE4TEMPERA) || defined(ARDUINO_INKPLATE6FLICK)
8180
#include "Frontlight.h"
8281
#ifdef ARDUINO_INKPLATE6FLICK
8382
#include "TouchCypress.h"
@@ -107,8 +106,7 @@ class System : public Esp,
107106
virtual public Expander,
108107
#endif
109108

110-
#if defined(ARDUINO_INKPLATE6PLUS) || defined(ARDUINO_INKPLATE6PLUSV2) || defined(ARDUINO_INKPLATE4TEMPERA) || \
111-
defined(ARDUINO_INKPLATE6FLICK)
109+
#if defined(ARDUINO_INKPLATE6PLUS) || defined(ARDUINO_INKPLATE6PLUSV2) || defined(ARDUINO_INKPLATE4TEMPERA) || defined(ARDUINO_INKPLATE6FLICK)
112110
public Touch,
113111
public Frontlight,
114112
#endif

0 commit comments

Comments
 (0)