Removed Adafruit MCP23017 Library

- Removed Adafruit MCP23017 library. Instead, code for controlling MCP23017 is built into library and it uses memory buffer to store all registers data from MCP23017. MCP23017 is now working much faster.
- Example for MCP23017 is changed
- Code for cleaning screen is improved (no more weird black/white lines outside visible aread, which can affect picture quality)
- Better waveform for grayscale (better color pallete), no more weird gradient on one color.
- Improved monochrome mode (writing black color was to aggressive, hard to clean)
This commit is contained in:
BornaBiro 2020-08-27 10:48:26 +02:00
parent cb5e49da2c
commit a1578bed16
3 changed files with 336 additions and 93 deletions

View File

@ -4,7 +4,6 @@
#include "WiFi.h" #include "WiFi.h"
#include "HTTPClient.h" #include "HTTPClient.h"
#include "Inkplate.h" #include "Inkplate.h"
Adafruit_MCP23017 mcp;
SPIClass spi2(HSPI); SPIClass spi2(HSPI);
SdFat sd(&spi2); SdFat sd(&spi2);
@ -38,22 +37,21 @@ void Inkplate::begin(void)
if (_beginDone == 1) if (_beginDone == 1)
return; return;
Wire.begin(); Wire.begin();
mcp.begin(0); mcpBegin(MCP23017_ADDR, mcpRegsInt);
mcp.pinMode(VCOM, OUTPUT); pinModeMCP(VCOM, OUTPUT);
mcp.pinMode(PWRUP, OUTPUT); pinModeMCP(PWRUP, OUTPUT);
mcp.pinMode(WAKEUP, OUTPUT); pinModeMCP(WAKEUP, OUTPUT);
mcp.pinMode(GPIO0_ENABLE, OUTPUT); pinModeMCP(GPIO0_ENABLE, OUTPUT);
mcp.digitalWrite(GPIO0_ENABLE, HIGH); digitalWriteMCP(GPIO0_ENABLE, HIGH);
//CONTROL PINS //CONTROL PINS
pinMode(0, OUTPUT); pinMode(0, OUTPUT);
pinMode(2, OUTPUT); pinMode(2, OUTPUT);
pinMode(32, OUTPUT); pinMode(32, OUTPUT);
pinMode(33, OUTPUT); pinMode(33, OUTPUT);
mcp.pinMode(OE, OUTPUT); pinModeMCP(OE, OUTPUT);
mcp.pinMode(GMOD, OUTPUT); pinModeMCP(GMOD, OUTPUT);
mcp.pinMode(SPV, OUTPUT); pinModeMCP(SPV, OUTPUT);
//pinMode(SPV, OUTPUT);
//DATA PINS //DATA PINS
pinMode(4, OUTPUT); //D0 pinMode(4, OUTPUT); //D0
@ -66,12 +64,12 @@ void Inkplate::begin(void)
pinMode(27, OUTPUT); //D7 pinMode(27, OUTPUT); //D7
//TOUCHPAD PINS //TOUCHPAD PINS
mcp.pinMode(10, INPUT); pinModeMCP(10, INPUT);
mcp.pinMode(11, INPUT); pinModeMCP(11, INPUT);
mcp.pinMode(12, INPUT); pinModeMCP(12, INPUT);
//Battery voltage Switch MOSFET //Battery voltage Switch MOSFET
mcp.pinMode(9, OUTPUT); pinModeMCP(9, OUTPUT);
D_memory_new = (uint8_t *)ps_malloc(600 * 100); D_memory_new = (uint8_t *)ps_malloc(600 * 100);
_partial = (uint8_t *)ps_malloc(600 * 100); _partial = (uint8_t *)ps_malloc(600 * 100);
@ -699,7 +697,7 @@ uint8_t Inkplate::getPanelState()
uint8_t Inkplate::readTouchpad(uint8_t _pad) uint8_t Inkplate::readTouchpad(uint8_t _pad)
{ {
return mcp.digitalRead((_pad & 3) + 10); return digitalReadMCP((_pad & 3) + 10);
} }
int8_t Inkplate::readTemperature() int8_t Inkplate::readTemperature()
@ -709,10 +707,10 @@ int8_t Inkplate::readTemperature()
double Inkplate::readBattery() double Inkplate::readBattery()
{ {
mcp.digitalWrite(9, HIGH); digitalWriteMCP(9, HIGH);
delay(1); delay(1);
int adc = analogRead(35); int adc = analogRead(35);
mcp.digitalWrite(9, LOW); digitalWriteMCP(9, LOW);
return (double(adc) / 4095 * 3.3 * 2); return (double(adc) / 4095 * 3.3 * 2);
} }
@ -815,15 +813,15 @@ void Inkplate::cleanFast(uint8_t c, uint8_t rep)
data = B11111111; //Skip data = B11111111; //Skip
} }
uint32_t _send = ((data & B00000011) << 4) | (((data & B00001100) >> 2) << 18) | (((data & B00010000) >> 4) << 23) | (((data & B11100000) >> 5) << 25); uint32_t _send = ((data & B00000011) << 4) | (((data & B00001100) >> 2) << 18) | (((data & B00010000) >> 4) << 23) | (((data & B11100000) >> 5) << 25);;
for (int i = 0; i < rep; i++) for (int k = 0; k < rep; k++) {
{
unsigned int x, y;
vscan_start(); vscan_start();
for (y = 0; y < 600; y++) for (int i = 0; i < 600; i++)
{ {
hscan_start(_send); hscan_start(_send);
for (x = 0; x < 100; x++) GPIO.out_w1ts = (_send) | CL;
GPIO.out_w1tc = DATA | CL;
for (int j = 0; j < 99; j++)
{ {
GPIO.out_w1ts = (_send) | CL; GPIO.out_w1ts = (_send) | CL;
GPIO.out_w1tc = DATA | CL; GPIO.out_w1tc = DATA | CL;
@ -881,9 +879,9 @@ void Inkplate::pinsZstate()
pinMode(2, INPUT); pinMode(2, INPUT);
pinMode(32, INPUT); pinMode(32, INPUT);
pinMode(33, INPUT); pinMode(33, INPUT);
mcp.pinMode(OE, INPUT); pinModeMCP(OE, INPUT);
mcp.pinMode(GMOD, INPUT); pinModeMCP(GMOD, INPUT);
mcp.pinMode(SPV, INPUT); pinModeMCP(SPV, INPUT);
//DATA PINS //DATA PINS
pinMode(4, INPUT); //D0 pinMode(4, INPUT); //D0
@ -903,9 +901,9 @@ void Inkplate::pinsAsOutputs()
pinMode(2, OUTPUT); pinMode(2, OUTPUT);
pinMode(32, OUTPUT); pinMode(32, OUTPUT);
pinMode(33, OUTPUT); pinMode(33, OUTPUT);
mcp.pinMode(OE, OUTPUT); pinModeMCP(OE, OUTPUT);
mcp.pinMode(GMOD, OUTPUT); pinModeMCP(GMOD, OUTPUT);
mcp.pinMode(SPV, OUTPUT); pinModeMCP(SPV, OUTPUT);
//DATA PINS //DATA PINS
pinMode(4, OUTPUT); //D0 pinMode(4, OUTPUT); //D0
@ -918,6 +916,125 @@ void Inkplate::pinsAsOutputs()
pinMode(27, OUTPUT); //D7 pinMode(27, OUTPUT); //D7
} }
//----------------------------MCP23017 Functions----------------------------
void Inkplate::pinModeMCP(uint8_t _pin, uint8_t _mode)
{
uint8_t _port = (_pin / 8) & 1;
uint8_t _p = _pin % 8;
switch (_mode)
{
case INPUT:
mcpRegsInt[MCP23017_IODIRA + _port] |= 1 << _p; //Set it to input
mcpRegsInt[MCP23017_GPPUA + _port] &= ~(1 << _p); //Disable pullup on that pin
updateRegister(MCP23017_ADDR, MCP23017_IODIRA + _port, mcpRegsInt[MCP23017_IODIRA + _port]);
updateRegister(MCP23017_ADDR, MCP23017_GPPUA + _port, mcpRegsInt[MCP23017_GPPUA + _port]);
break;
case INPUT_PULLUP:
mcpRegsInt[MCP23017_IODIRA + _port] |= 1 << _p; //Set it to input
mcpRegsInt[MCP23017_GPPUA + _port] |= 1 << _p; //Enable pullup on that pin
updateRegister(MCP23017_ADDR, MCP23017_IODIRA + _port, mcpRegsInt[MCP23017_IODIRA + _port]);
updateRegister(MCP23017_ADDR, MCP23017_GPPUA + _port, mcpRegsInt[MCP23017_GPPUA + _port]);
break;
case OUTPUT:
mcpRegsInt[MCP23017_IODIRA + _port] &= ~(1 << _p); //Set it to output
mcpRegsInt[MCP23017_GPPUA + _port] &= ~(1 << _p); //Disable pullup on that pin
updateRegister(MCP23017_ADDR, MCP23017_IODIRA + _port, mcpRegsInt[MCP23017_IODIRA + _port]);
updateRegister(MCP23017_ADDR, MCP23017_GPPUA + _port, mcpRegsInt[MCP23017_GPPUA + _port]);
break;
}
}
void Inkplate::digitalWriteMCP(uint8_t _pin, uint8_t _state)
{
uint8_t _port = (_pin / 8) & 1;
uint8_t _p = _pin % 8;
if (mcpRegsInt[MCP23017_IODIRA + _port] & (1 << _p)) return; //Check if the pin is set as an output
_state ? (mcpRegsInt[MCP23017_GPIOA + _port] |= (1 << _p)) : (mcpRegsInt[MCP23017_GPIOA + _port] &= ~(1 << _p));
updateRegister(MCP23017_ADDR, MCP23017_GPIOA + _port, mcpRegsInt[MCP23017_GPIOA + _port]);
}
uint8_t Inkplate::digitalReadMCP(uint8_t _pin)
{
uint8_t _port = (_pin / 8) & 1;
uint8_t _p = _pin % 8;
readMCPRegister(MCP23017_ADDR, MCP23017_GPIOA + _port, mcpRegsInt);
return (mcpRegsInt[MCP23017_GPIOA + _port] & (1 << _p)) ? HIGH : LOW;
}
void Inkplate::setIntOutput(uint8_t intPort, uint8_t mirroring, uint8_t openDrain, uint8_t polarity)
{
intPort &= 1;
mirroring &= 1;
openDrain &= 1;
polarity &= 1;
mcpRegsInt[MCP23017_IOCONA + intPort] = (mcpRegsInt[MCP23017_IOCONA + intPort] & ~(1 << 6)) | (1 << mirroring);
mcpRegsInt[MCP23017_IOCONA + intPort] = (mcpRegsInt[MCP23017_IOCONA + intPort] & ~(1 << 6)) | (1 << openDrain);
mcpRegsInt[MCP23017_IOCONA + intPort] = (mcpRegsInt[MCP23017_IOCONA + intPort] & ~(1 << 6)) | (1 << polarity);
updateRegister(MCP23017_ADDR, MCP23017_IOCONA + intPort, mcpRegsInt[MCP23017_IOCONA + intPort]);
}
void Inkplate::setIntPin(uint8_t _pin, uint8_t _mode)
{
uint8_t _port = (_pin / 8) & 1;
uint8_t _p = _pin % 8;
switch (_mode)
{
case CHANGE:
mcpRegsInt[MCP23017_INTCONA + _port] &= ~(1 << _p);
break;
case FALLING:
mcpRegsInt[MCP23017_INTCONA + _port] |= (1 << _p);
mcpRegsInt[MCP23017_DEFVALA + _port] |= (1 << _p);
break;
case RISING:
mcpRegsInt[MCP23017_INTCONA + _port] |= (1 << _p);
mcpRegsInt[MCP23017_DEFVALA + _port] &= ~(1 << _p);
break;
}
mcpRegsInt[MCP23017_GPINTENA + _port] |= (1 << _p);
updateRegister(MCP23017_ADDR, MCP23017_GPINTENA, mcpRegsInt, 6);
}
void Inkplate::removeIntPin(uint8_t _pin)
{
uint8_t _port = (_pin / 8) & 1;
uint8_t _p = _pin % 8;
mcpRegsInt[MCP23017_GPINTENA + _port] &= ~(1 << _p);
updateRegister(MCP23017_ADDR, MCP23017_GPINTENA, mcpRegsInt, 2);
}
uint16_t Inkplate::getINT()
{
readMCPRegisters(MCP23017_ADDR, MCP23017_INTFA, mcpRegsInt, 2);
return ((mcpRegsInt[MCP23017_INTFB] << 8) | mcpRegsInt[MCP23017_INTFA]);
}
uint16_t Inkplate::getINTstate()
{
readMCPRegisters(MCP23017_ADDR, MCP23017_INTCAPA, mcpRegsInt, 2);
return ((mcpRegsInt[MCP23017_INTCAPB] << 8) | mcpRegsInt[MCP23017_INTCAPA]);
}
void Inkplate::setPorts(uint16_t _d)
{
mcpRegsInt[MCP23017_GPIOA] = _d & 0xff;
mcpRegsInt[MCP23017_GPIOB] = (_d >> 8) & 0xff;
updateRegister(MCP23017_ADDR, MCP23017_GPIOA, mcpRegsInt, 2);
}
uint16_t Inkplate::getPorts()
{
readMCPRegisters(MCP23017_ADDR, MCP23017_GPIOA, mcpRegsInt, 2);
return ((mcpRegsInt[MCP23017_GPIOB] << 8) | (mcpRegsInt[MCP23017_GPIOA]));
}
//--------------------------PRIVATE FUNCTIONS-------------------------------------------- //--------------------------PRIVATE FUNCTIONS--------------------------------------------
//Display content from RAM to display (1 bit per pixel,. monochrome picture). //Display content from RAM to display (1 bit per pixel,. monochrome picture).
void Inkplate::display1b() void Inkplate::display1b()
@ -941,7 +1058,7 @@ void Inkplate::display1b()
cleanFast(1, 12); cleanFast(1, 12);
cleanFast(2, 1); cleanFast(2, 1);
cleanFast(0, 11); cleanFast(0, 11);
for (int k = 0; k < 5; k++) for (int k = 0; k < 3; k++)
{ {
_pos = 59999; _pos = 59999;
vscan_start(); vscan_start();
@ -1007,31 +1124,30 @@ void Inkplate::display1b()
vscan_end(); vscan_end();
} }
delayMicroseconds(230); delayMicroseconds(230);
/*
for (int k = 0; k < 1; k++) {
vscan_start(); vscan_start();
hscan_start(); for (int i = 0; i < 600; i++)
_pos = 59999; {
for (int i = 0; i < 600; i++) { dram = *(D_memory_new + _pos);
for (int j = 0; j < 100; j++) { data = 0b00000000;;
data = discharge[(*(D_memory_new + _pos) >> 4)];
_send = ((data & B00000011) << 4) | (((data & B00001100) >> 2) << 18) | (((data & B00010000) >> 4) << 23) | (((data & B11100000) >> 5) << 25); _send = ((data & B00000011) << 4) | (((data & B00001100) >> 2) << 18) | (((data & B00010000) >> 4) << 23) | (((data & B11100000) >> 5) << 25);
hscan_start(_send);
data = 0b00000000;
GPIO.out_w1ts = (_send) | CL;
GPIO.out_w1tc = DATA | CL;
for (int j = 0; j < 99; j++)
{
GPIO.out_w1ts = (_send) | CL;
GPIO.out_w1tc = DATA | CL; GPIO.out_w1tc = DATA | CL;
GPIO.out_w1ts = (_send) | CL; GPIO.out_w1ts = (_send) | CL;
data = discharge[*(D_memory_new + _pos) & 0x0F];
_send = ((data & B00000011) << 4) | (((data & B00001100) >> 2) << 18) | (((data & B00010000) >> 4) << 23) | (((data & B11100000) >> 5) << 25);
GPIO.out_w1tc = DATA | CL; GPIO.out_w1tc = DATA | CL;
}
GPIO.out_w1ts = (_send) | CL; GPIO.out_w1ts = (_send) | CL;
_pos--; GPIO.out_w1tc = DATA | CL;
vscan_end();
} }
vscan_write();
}
CKV_CLEAR;
delayMicroseconds(230); delayMicroseconds(230);
}
*/
cleanFast(2, 2);
cleanFast(3, 1);
vscan_start(); vscan_start();
einkOff(); einkOff();
_blockPartial = 0; _blockPartial = 0;
@ -1050,7 +1166,7 @@ void Inkplate::display3b()
cleanFast(2, 1); cleanFast(2, 1);
cleanFast(0, 11); cleanFast(0, 11);
for (int k = 0; k < 7; k++) for (int k = 0; k < 8; k++)
{ {
uint8_t *dp = D_memory4Bit + 239999; uint8_t *dp = D_memory4Bit + 239999;
uint32_t _send; uint32_t _send;
@ -1854,3 +1970,80 @@ void Inkplate::precalculateGamma(uint8_t *c, float gamma)
c[i] = int(round((pow(i / 255.0, gamma)) * 15)); c[i] = int(round((pow(i / 255.0, gamma)) * 15));
} }
} }
//----------------------------MCP23017 Low Level Functions----------------------------
bool Inkplate::mcpBegin(uint8_t _addr, uint8_t* _r)
{
Wire.beginTransmission(_addr);
int error = Wire.endTransmission();
if (error) return false;
readMCPRegisters(_addr, _r);
_r[0] = 0xff;
_r[1] = 0xff;
updateAllRegisters(_addr, _r);
return true;
}
void Inkplate::readMCPRegisters(uint8_t _addr, uint8_t *k)
{
Wire.beginTransmission(_addr);
Wire.write(0x00);
Wire.endTransmission();
Wire.requestFrom(_addr, (uint8_t)22);
for (int i = 0; i < 22; i++)
{
k[i] = Wire.read();
}
}
void Inkplate::readMCPRegisters(uint8_t _addr, uint8_t _regName, uint8_t *k, uint8_t _n)
{
Wire.beginTransmission(_addr);
Wire.write(_regName);
Wire.endTransmission();
Wire.requestFrom(_addr, _n);
for (int i = 0; i < _n; i++)
{
k[_regName + i] = Wire.read();
}
}
void Inkplate::readMCPRegister(uint8_t _addr, uint8_t _regName, uint8_t *k)
{
Wire.beginTransmission(_addr);
Wire.write(_regName);
Wire.endTransmission();
Wire.requestFrom(_addr, (uint8_t)1);
k[_regName] = Wire.read();
}
void Inkplate::updateAllRegisters(uint8_t _addr, uint8_t *k)
{
Wire.beginTransmission(_addr);
Wire.write(0x00);
for (int i = 0; i < 22; i++)
{
Wire.write(k[i]);
}
Wire.endTransmission();
}
void Inkplate::updateRegister(uint8_t _addr, uint8_t _regName, uint8_t _d)
{
Wire.beginTransmission(_addr);
Wire.write(_regName);
Wire.write(_d);
Wire.endTransmission();
}
void Inkplate::updateRegister(uint8_t _addr, uint8_t _regName, uint8_t *k, uint8_t _n)
{
Wire.beginTransmission(_addr);
Wire.write(_regName);
for (int i = 0; i < _n; i++)
{
Wire.write(k[_regName + i]);
}
Wire.endTransmission();
}

View File

@ -13,11 +13,44 @@
#include "Adafruit_GFX.h" #include "Adafruit_GFX.h"
#include "Wire.h" #include "Wire.h"
#include "SPI.h" #include "SPI.h"
#include "Adafruit_MCP23017.h"
#include "SdFat.h" #include "SdFat.h"
#include "WiFiClient.h" #include "WiFiClient.h"
#include "Triangulate.h" #include "Triangulate.h"
#define MCP23017_ADDR 0x20
#define MCP23017_INT_PORTA 0x00
#define MCP23017_INT_PORTB 0x01
#define MCP23017_INT_NO_MIRROR false
#define MCP23017_INT_MIRROR true
#define MCP23017_INT_PUSHPULL false
#define MCP23017_INT_OPENDRAIN true
#define MCP23017_INT_ACTLOW false
#define MCP23017_INT_ACTHIGH true
#define MCP23017_IODIRA 0x00
#define MCP23017_IPOLA 0x02
#define MCP23017_GPINTENA 0x04
#define MCP23017_DEFVALA 0x06
#define MCP23017_INTCONA 0x08
#define MCP23017_IOCONA 0x0A
#define MCP23017_GPPUA 0x0C
#define MCP23017_INTFA 0x0E
#define MCP23017_INTCAPA 0x10
#define MCP23017_GPIOA 0x12
#define MCP23017_OLATA 0x14
#define MCP23017_IODIRB 0x01
#define MCP23017_IPOLB 0x03
#define MCP23017_GPINTENB 0x05
#define MCP23017_DEFVALB 0x07
#define MCP23017_INTCONB 0x09
#define MCP23017_IOCONB 0x0B
#define MCP23017_GPPUB 0x0D
#define MCP23017_INTFB 0x0F
#define MCP23017_INTCAPB 0x11
#define MCP23017_GPIOB 0x13
#define MCP23017_OLATB 0x15
#define INKPLATE_GAMMA 1.45 #define INKPLATE_GAMMA 1.45
#define E_INK_WIDTH 800 #define E_INK_WIDTH 800
#define E_INK_HEIGHT 600 #define E_INK_HEIGHT 600
@ -80,61 +113,61 @@
#define GMOD 1 //GPIOA1 #define GMOD 1 //GPIOA1
#define GMOD_SET \ #define GMOD_SET \
{ \ { \
mcp.digitalWrite(GMOD, HIGH); \ digitalWriteMCP(GMOD, HIGH); \
} }
#define GMOD_CLEAR \ #define GMOD_CLEAR \
{ \ { \
mcp.digitalWrite(GMOD, LOW); \ digitalWriteMCP(GMOD, LOW); \
} }
#define OE 0 //GPIOA0 #define OE 0 //GPIOA0
#define OE_SET \ #define OE_SET \
{ \ { \
mcp.digitalWrite(OE, HIGH); \ digitalWriteMCP(OE, HIGH); \
} }
#define OE_CLEAR \ #define OE_CLEAR \
{ \ { \
mcp.digitalWrite(OE, LOW); \ digitalWriteMCP(OE, LOW); \
} }
#define SPV 2 //GPIOA5 #define SPV 2 //GPIOA5
#define SPV_SET \ #define SPV_SET \
{ \ { \
mcp.digitalWrite(SPV, HIGH); \ digitalWriteMCP(SPV, HIGH); \
} }
#define SPV_CLEAR \ #define SPV_CLEAR \
{ \ { \
mcp.digitalWrite(SPV, LOW); \ digitalWriteMCP(SPV, LOW); \
} }
#define WAKEUP 3 //GPIOA3 #define WAKEUP 3 //GPIOA3
#define WAKEUP_SET \ #define WAKEUP_SET \
{ \ { \
mcp.digitalWrite(WAKEUP, HIGH); \ digitalWriteMCP(WAKEUP, HIGH); \
} }
#define WAKEUP_CLEAR \ #define WAKEUP_CLEAR \
{ \ { \
mcp.digitalWrite(WAKEUP, LOW); \ digitalWriteMCP(WAKEUP, LOW); \
} }
#define PWRUP 4 //GPIOA4 #define PWRUP 4 //GPIOA4
#define PWRUP_SET \ #define PWRUP_SET \
{ \ { \
mcp.digitalWrite(PWRUP, HIGH); \ digitalWriteMCP(PWRUP, HIGH); \
} }
#define PWRUP_CLEAR \ #define PWRUP_CLEAR \
{ \ { \
mcp.digitalWrite(PWRUP, LOW); \ digitalWriteMCP(PWRUP, LOW); \
} }
#define VCOM 5 //GPIOA6 #define VCOM 5 //GPIOA6
#define VCOM_SET \ #define VCOM_SET \
{ \ { \
mcp.digitalWrite(VCOM, HIGH); \ digitalWriteMCP(VCOM, HIGH); \
} }
#define VCOM_CLEAR \ #define VCOM_CLEAR \
{ \ { \
mcp.digitalWrite(VCOM, LOW); \ digitalWriteMCP(VCOM, LOW); \
} }
#define CKV_CLOCK ckvClock(); #define CKV_CLOCK ckvClock();
@ -148,7 +181,7 @@
} }
#endif #endif
extern Adafruit_MCP23017 mcp; //extern Adafruit_MCP23017 mcp;
extern SPIClass spi2; extern SPIClass spi2;
extern SdFat sd; extern SdFat sd;
static void ckvClock(); static void ckvClock();
@ -169,7 +202,7 @@ public:
const uint8_t discharge[16] = {B11111111, B11111100, B11110011, B11110000, B11001111, B11001100, B11000011, B11000000, B00111111, B00111100, B00110011, B00110000, B00001111, B00001100, B00000011, B00000000}; const uint8_t discharge[16] = {B11111111, B11111100, B11110011, B11110000, B11001111, B11001100, B11000011, B11000000, B00111111, B00111100, B00110011, B00110000, B00001111, B00001100, B00000011, B00000000};
//BLACK->WHITE //BLACK->WHITE
//THIS IS OKAYISH WAVEFORM FOR GRAYSCALE. IT CAN BE MUCH BETTER. //THIS IS OKAYISH WAVEFORM FOR GRAYSCALE. IT CAN BE MUCH BETTER.
const uint8_t waveform3Bit[8][7] = {{0, 0, 0, 0, 1, 1, 1}, {0, 0, 1, 1, 1, 2, 1}, {0, 1, 1, 2, 1, 2, 1}, {0, 0, 1, 1, 2, 1, 2}, {1, 1, 1, 2, 2, 1, 2}, {0, 0, 1, 1, 1, 2, 2}, {0, 1, 1, 2, 1, 2, 2}, {0, 0, 0, 0, 0, 0, 2}}; const uint8_t waveform3Bit[8][8] = {{0, 0, 0, 0, 1, 1, 1, 0}, {1, 2, 2, 2, 1, 1, 1, 0}, {0, 1, 2, 1, 1, 2, 1, 0}, {0, 2, 1, 2, 1, 2, 1, 0}, {0, 0, 0, 1, 1, 1, 2, 0}, {2, 1, 1, 1, 2, 1, 2, 0}, {1, 1, 1, 2, 1, 2, 2, 0}, {0, 0, 0, 0, 0, 0, 2, 0}};
//const uint8_t waveform3Bit[8][12] = {{3,3,3,1,1,1,1,1,1,1,2,0}, {3,3,3,3,1,1,1,1,1,1,2,0}, {3,3,3,3,3,1,1,1,1,1,2,0}, {3,3,3,3,3,3,1,1,1,1,2,0}, {3,3,3,3,3,3,3,1,1,1,2,0}, {3,3,3,3,3,3,3,2,1,1,2,0}, {3,3,3,3,3,3,3,3,3,1,2,0}, {3,3,3,3,3,3,3,3,3,3,2,0}}; //const uint8_t waveform3Bit[8][12] = {{3,3,3,1,1,1,1,1,1,1,2,0}, {3,3,3,3,1,1,1,1,1,1,2,0}, {3,3,3,3,3,1,1,1,1,1,2,0}, {3,3,3,3,3,3,1,1,1,1,2,0}, {3,3,3,3,3,3,3,1,1,1,2,0}, {3,3,3,3,3,3,3,2,1,1,2,0}, {3,3,3,3,3,3,3,3,3,1,2,0}, {3,3,3,3,3,3,3,3,3,3,2,0}};
//const uint8_t waveform3Bit[16][12] = {{0,0,0,0,0,0,1,2,1,1,0,3},{0,0,1,1,1,2,2,2,1,1,0,3},{0,0,0,1,1,2,2,2,1,1,0,3}, {0,0,0,1,2,1,2,1,2,1,3}, {0,0,2,1,2,1,2,1,2,1,3}, {0,0,1,2,2,1,1,1,1,2,0,3}, {0,0,0,2,1,1,1,1,0,2,0,3}, {0,0,2,1,2,2,1,1,1,2,0,3}, {0,0,0,2,2,2,1,1,1,2,0,3}, {0,0,0,0,0,0,2,1,1,2,0,3}, {0,0,0,0,0,2,2,1,1,2,0,3}, {0,0,0,0,0,1,1,1,2,2,0,3}, {0,0,0,0,1,2,1,2,1,2,0,3}, {0,0,0,0,1,1,2,2,1,2,0,3},{0,0,0,0,1,1,1,2,2,2,0,3}, {0,0,0,0,0,0,0,0,0,2,0,3}}; //const uint8_t waveform3Bit[16][12] = {{0,0,0,0,0,0,1,2,1,1,0,3},{0,0,1,1,1,2,2,2,1,1,0,3},{0,0,0,1,1,2,2,2,1,1,0,3}, {0,0,0,1,2,1,2,1,2,1,3}, {0,0,2,1,2,1,2,1,2,1,3}, {0,0,1,2,2,1,1,1,1,2,0,3}, {0,0,0,2,1,1,1,1,0,2,0,3}, {0,0,2,1,2,2,1,1,1,2,0,3}, {0,0,0,2,2,2,1,1,1,2,0,3}, {0,0,0,0,0,0,2,1,1,2,0,3}, {0,0,0,0,0,2,2,1,1,2,0,3}, {0,0,0,0,0,1,1,1,2,2,0,3}, {0,0,0,0,1,2,1,2,1,2,0,3}, {0,0,0,0,1,1,2,2,1,2,0,3},{0,0,0,0,1,1,1,2,2,2,0,3}, {0,0,0,0,0,0,0,0,0,2,0,3}};
//PVI waveform for cleaning screen, not sure if it is correct, but it cleans screen properly. //PVI waveform for cleaning screen, not sure if it is correct, but it cleans screen properly.
@ -226,9 +259,20 @@ public:
void cleanFast2(uint8_t c, uint8_t n, uint16_t d); void cleanFast2(uint8_t c, uint8_t n, uint16_t d);
void pinsZstate(); void pinsZstate();
void pinsAsOutputs(); void pinsAsOutputs();
void pinModeMCP(uint8_t _pin, uint8_t _mode);
void digitalWriteMCP(uint8_t _pin, uint8_t _state);
uint8_t digitalReadMCP(uint8_t _pin);
void setIntOutput(uint8_t intPort, uint8_t mirroring, uint8_t openDrain, uint8_t polarity);
void setIntPin(uint8_t _pin, uint8_t _mode);
void removeIntPin(uint8_t _pin);
uint16_t getINT();
uint16_t getINTstate();
void setPorts(uint16_t _d);
uint16_t getPorts();
private: private:
uint8_t gammaLUT[256]; uint8_t gammaLUT[256];
uint8_t mcpRegsInt[22];
uint8_t pixelBuffer[800 * 3 + 5]; uint8_t pixelBuffer[800 * 3 + 5];
uint8_t ditherBuffer[800 * 3 + 5][2]; uint8_t ditherBuffer[800 * 3 + 5][2];
int8_t _temperature; int8_t _temperature;
@ -260,6 +304,13 @@ private:
int drawGrayscaleBitmap8Web(WiFiClient *s, struct bitmapHeader bmpHeader, int x, int y, int len, bool dither, bool invert); int drawGrayscaleBitmap8Web(WiFiClient *s, struct bitmapHeader bmpHeader, int x, int y, int len, bool dither, bool invert);
int drawGrayscaleBitmap24Web(WiFiClient *s, struct bitmapHeader bmpHeader, int x, int y, int len, bool dither, bool invert); int drawGrayscaleBitmap24Web(WiFiClient *s, struct bitmapHeader bmpHeader, int x, int y, int len, bool dither, bool invert);
void precalculateGamma(uint8_t *c, float gamma); void precalculateGamma(uint8_t *c, float gamma);
bool mcpBegin(uint8_t _addr, uint8_t* _r);
void readMCPRegisters(uint8_t _addr, uint8_t *k);
void readMCPRegisters(uint8_t _addr, uint8_t _regName, uint8_t *k, uint8_t _n);
void readMCPRegister(uint8_t _addr, uint8_t _regName, uint8_t *k);
void updateAllRegisters(uint8_t _addr, uint8_t *k);
void updateRegister(uint8_t _addr, uint8_t _regName, uint8_t _d);
void updateRegister(uint8_t _addr, uint8_t _regName, uint8_t *k, uint8_t _n);
}; };
#endif #endif

View File

@ -28,16 +28,15 @@
#define LED_PIN 15 //We are going to use pin GPB7 (remember! GPA0 = 0, GPA1 = 1, ..., GPA7 = 7, GPB0 = 8, GBP1 = 9, ..., GPB7 = 15) #define LED_PIN 15 //We are going to use pin GPB7 (remember! GPA0 = 0, GPA1 = 1, ..., GPA7 = 7, GPB0 = 8, GBP1 = 9, ..., GPB7 = 15)
Inkplate display(INKPLATE_1BIT); //Create an object on Inkplate library and also set library into 1-bit mode (Monochrome) Inkplate display(INKPLATE_1BIT); //Create an object on Inkplate library and also set library into 1-bit mode (Monochrome)
extern Adafruit_MCP23017 mcp; //We are using mcp object used inside our Inkplate library
void setup() { void setup() {
display.begin(); //Init Inkplate library (you should call this function ONLY ONCE) display.begin(); //Init Inkplate library (you should call this function ONLY ONCE)
mcp.pinMode(LED_PIN, OUTPUT); //Set pin 15 (or GPB7) to output. On that pin, we sholud connect LED with current limiting resistor pinModeMCP(LED_PIN, OUTPUT); //Set pin 15 (or GPB7) to output. On that pin, we sholud connect LED with current limiting resistor
} }
void loop() { void loop() {
mcp.digitalWrite(LED_PIN, LOW); //Set output to low (LED does not light up) digitalWriteMCP(LED_PIN, LOW); //Set output to low (LED does not light up)
delay(1000); //Wait for one second delay(1000); //Wait for one second
mcp.digitalWrite(LED_PIN, HIGH); //Set output to high (LED lights up) digitalWriteMCP(LED_PIN, HIGH); //Set output to high (LED lights up)
delay(1000); //Wait for one second delay(1000); //Wait for one second
} }