Skip to content

Commit

Permalink
add Arduino_ESP32S2PAR8 data bus
Browse files Browse the repository at this point in the history
  • Loading branch information
moononournation committed Oct 2, 2021
1 parent 80c89c4 commit e14fcfa
Show file tree
Hide file tree
Showing 3 changed files with 366 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Arduino_GFX_Library.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "databus/Arduino_ESP32PAR16.h"
#include "databus/Arduino_ESP32PAR16Q.h"
#include "databus/Arduino_ESP32PAR16QQ.h"
#include "databus/Arduino_ESP32S2PAR8.h"
#include "databus/Arduino_ESP32S2PAR16.h"
#include "databus/Arduino_ESP32S2PAR16Q.h"
#include "databus/Arduino_ESP32SPI.h"
Expand Down
300 changes: 300 additions & 0 deletions src/databus/Arduino_ESP32S2PAR8.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,300 @@
#include "Arduino_ESP32S2PAR8.h"

#if CONFIG_IDF_TARGET_ESP32S2

Arduino_ESP32S2PAR8::Arduino_ESP32S2PAR8(int8_t dc, int8_t cs, int8_t wr, int8_t rd)
: _dc(dc), _cs(cs), _wr(wr), _rd(rd)
{
}

void Arduino_ESP32S2PAR8::begin(int32_t speed, int8_t dataMode)
{
pinMode(_dc, OUTPUT);
digitalWrite(_dc, HIGH); // Data mode
if (_dc >= 32)
{
_dcPinMask = digitalPinToBitMask(_dc);
_dcPortSet = (PORTreg_t)&GPIO.out1_w1ts.val;
_dcPortClr = (PORTreg_t)&GPIO.out1_w1tc.val;
}
else if (_dc >= 0)
{
_dcPinMask = digitalPinToBitMask(_dc);
_dcPortSet = (PORTreg_t)&GPIO.out_w1ts;
_dcPortClr = (PORTreg_t)&GPIO.out_w1tc;
}

if (_cs >= 0)
{
pinMode(_cs, OUTPUT);
digitalWrite(_cs, HIGH); // disable chip select
}
if (_cs >= 32)
{
_csPinMask = digitalPinToBitMask(_cs);
_csPortSet = (PORTreg_t)&GPIO.out1_w1ts.val;
_csPortClr = (PORTreg_t)&GPIO.out1_w1tc.val;
}
else if (_cs >= 0)
{
_csPinMask = digitalPinToBitMask(_cs);
_csPortSet = (PORTreg_t)&GPIO.out_w1ts;
_csPortClr = (PORTreg_t)&GPIO.out_w1tc;
}
else
{
_csPinMask = 0;
_csPortSet = _dcPortSet;
_csPortClr = _dcPortClr;
}

pinMode(_wr, OUTPUT);
digitalWrite(_wr, HIGH); // Set write strobe high (inactive)
if (_wr >= 32)
{
_wrPinMask = digitalPinToBitMask(_wr);
_wrPortSet = (PORTreg_t)&GPIO.out1_w1ts.val;
_wrPortClr = (PORTreg_t)&GPIO.out1_w1tc.val;
}
else if (_wr >= 0)
{
_wrPinMask = digitalPinToBitMask(_wr);
_wrPortSet = (PORTreg_t)&GPIO.out_w1ts;
_wrPortClr = (PORTreg_t)&GPIO.out_w1tc;
}

if (_rd >= 0)
{
pinMode(_rd, OUTPUT);
digitalWrite(_rd, HIGH);
}
if (_rd >= 32)
{
_rdPinMask = digitalPinToBitMask(_rd);
_rdPortSet = (PORTreg_t)&GPIO.out1_w1ts.val;
_rdPortClr = (PORTreg_t)&GPIO.out1_w1tc.val;
}
else if (_rd >= 0)
{
_rdPinMask = digitalPinToBitMask(_rd);
_rdPortSet = (PORTreg_t)&GPIO.out_w1ts;
_rdPortClr = (PORTreg_t)&GPIO.out_w1tc;
}
else
{
_rdPinMask = 0;
_rdPortSet = _dcPortSet;
_rdPortClr = _dcPortClr;
}

pinMode(0, OUTPUT);
pinMode(1, OUTPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);

// INIT 8-bit mask
_dataClrMask = 0xFF;
_dataPortSet = (PORTreg_t)&GPIO.out_w1ts;
_dataPortClr = (PORTreg_t)&GPIO.out_w1tc;
*_dataPortClr = _dataClrMask;
}

void Arduino_ESP32S2PAR8::beginWrite()
{
DC_HIGH();
CS_LOW();
}

void Arduino_ESP32S2PAR8::endWrite()
{
CS_HIGH();
}

void Arduino_ESP32S2PAR8::writeCommand(uint8_t c)
{
DC_LOW();

WRITE(c);

DC_HIGH();
}

void Arduino_ESP32S2PAR8::writeCommand16(uint16_t c)
{
DC_LOW();

_data16.value = c;
WRITE(_data16.msb);
WRITE(_data16.lsb);

DC_HIGH();
}

void Arduino_ESP32S2PAR8::write(uint8_t d)
{
WRITE(d);
}

void Arduino_ESP32S2PAR8::write16(uint16_t d)
{
_data16.value = d;
WRITE(_data16.msb);
WRITE(_data16.lsb);
}

void Arduino_ESP32S2PAR8::writeRepeat(uint16_t p, uint32_t len)
{
_data16.value = p;
if (_data16.msb == _data16.lsb)
{
*_dataPortClr = _dataClrMask;
*_dataPortSet = p;
while (len--)
{
*_wrPortClr = _wrPinMask;
*_wrPortSet = _wrPinMask;
*_wrPortClr = _wrPinMask;
*_wrPortSet = _wrPinMask;
}
}
else
{
while (len--)
{
*_dataPortClr = _dataClrMask;
*_dataPortSet = _data16.msb;
*_wrPortClr = _wrPinMask;
*_wrPortSet = _wrPinMask;

*_dataPortClr = _dataClrMask;
*_dataPortSet = _data16.lsb;
*_wrPortClr = _wrPinMask;
*_wrPortSet = _wrPinMask;
}
}
}

void Arduino_ESP32S2PAR8::writePixels(uint16_t *data, uint32_t len)
{
while (len--)
{
_data16.value = *data++;
WRITE(_data16.msb);
WRITE(_data16.lsb);
}
}

void Arduino_ESP32S2PAR8::writeC8D8(uint8_t c, uint8_t d)
{
DC_LOW();

WRITE(c);

DC_HIGH();

WRITE(d);
}

void Arduino_ESP32S2PAR8::writeC8D16(uint8_t c, uint16_t d)
{
DC_LOW();

WRITE(c);

DC_HIGH();

_data16.value = d;
WRITE(_data16.msb);
WRITE(_data16.lsb);
}

void Arduino_ESP32S2PAR8::writeC8D16D16(uint8_t c, uint16_t d1, uint16_t d2)
{
DC_LOW();

WRITE(c);

DC_HIGH();

_data16.value = d1;
WRITE(_data16.msb);
WRITE(_data16.lsb);

_data16.value = d2;
WRITE(_data16.msb);
WRITE(_data16.lsb);
}

void Arduino_ESP32S2PAR8::writeBytes(uint8_t *data, uint32_t len)
{
while (len--)
{
WRITE(*data++);
}
}

void Arduino_ESP32S2PAR8::writePattern(uint8_t *data, uint8_t len, uint32_t repeat)
{
while (repeat--)
{
writeBytes(data, len);
}
}

void Arduino_ESP32S2PAR8::writeIndexedPixels(uint8_t *data, uint16_t *idx, uint32_t len)
{
while (len--)
{
_data16.value = idx[*data++];
WRITE(_data16.msb);
WRITE(_data16.lsb);
}
}

void Arduino_ESP32S2PAR8::writeIndexedPixelsDouble(uint8_t *data, uint16_t *idx, uint32_t len)
{
while (len--)
{
_data16.value = idx[*data++];
WRITE(_data16.msb);
WRITE(_data16.lsb);
WRITE(_data16.msb);
WRITE(_data16.lsb);
}
}

INLINE void Arduino_ESP32S2PAR8::WRITE(uint8_t d)
{
*_dataPortClr = _dataClrMask;
*_dataPortSet = d;
*_wrPortClr = _wrPinMask;
*_wrPortSet = _wrPinMask;
}

/******** low level bit twiddling **********/

INLINE void Arduino_ESP32S2PAR8::DC_HIGH(void)
{
*_dcPortSet = _dcPinMask;
}

INLINE void Arduino_ESP32S2PAR8::DC_LOW(void)
{
*_dcPortClr = _dcPinMask;
}

INLINE void Arduino_ESP32S2PAR8::CS_HIGH(void)
{
*_csPortSet = _csPinMask;
}

INLINE void Arduino_ESP32S2PAR8::CS_LOW(void)
{
*_csPortClr = _csPinMask;
}

#endif // #if CONFIG_IDF_TARGET_ESP32S2
65 changes: 65 additions & 0 deletions src/databus/Arduino_ESP32S2PAR8.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#include "Arduino_DataBus.h"

#if CONFIG_IDF_TARGET_ESP32S2

#ifndef _ARDUINO_ESP32S2PAR8_H_
#define _ARDUINO_ESP32S2PAR8_H_

class Arduino_ESP32S2PAR8 : public Arduino_DataBus
{
public:
Arduino_ESP32S2PAR8(int8_t dc, int8_t cs, int8_t wr, int8_t rd); // Constructor

void begin(int32_t speed = 0, int8_t dataMode = 0) override;
void beginWrite() override;
void endWrite() override;
void writeCommand(uint8_t) override;
void writeCommand16(uint16_t) override;
void write(uint8_t) override;
void write16(uint16_t) override;
void writeRepeat(uint16_t p, uint32_t len) override;
void writePixels(uint16_t *data, uint32_t len) override;

void writeC8D8(uint8_t c, uint8_t d) override;
void writeC8D16(uint8_t c, uint16_t d) override;
void writeC8D16D16(uint8_t c, uint16_t d1, uint16_t d2) override;
void writeBytes(uint8_t *data, uint32_t len) override;
void writePattern(uint8_t *data, uint8_t len, uint32_t repeat) override;

void writeIndexedPixels(uint8_t *data, uint16_t *idx, uint32_t len) override;
void writeIndexedPixelsDouble(uint8_t *data, uint16_t *idx, uint32_t len) override;

protected:
private:
INLINE void WRITE(uint8_t d);
INLINE void DC_HIGH(void);
INLINE void DC_LOW(void);
INLINE void CS_HIGH(void);
INLINE void CS_LOW(void);

int8_t _dc, _cs, _wr, _rd;

PORTreg_t _dcPortSet; ///< PORT register SET
PORTreg_t _dcPortClr; ///< PORT register CLEAR
uint32_t _dcPinMask; ///< Bitmask

PORTreg_t _csPortSet; ///< PORT register SET
PORTreg_t _csPortClr; ///< PORT register CLEAR
uint32_t _csPinMask; ///< Bitmask

PORTreg_t _wrPortSet; ///< PORT register SET
PORTreg_t _wrPortClr; ///< PORT register CLEAR
uint32_t _wrPinMask; ///< Bitmask

PORTreg_t _rdPortSet; ///< PORT register SET
PORTreg_t _rdPortClr; ///< PORT register CLEAR
uint32_t _rdPinMask; ///< Bitmask

PORTreg_t _dataPortSet; ///< PORT register SET
PORTreg_t _dataPortClr; ///< PORT register CLEAR
uint32_t _dataClrMask;
};

#endif // _ARDUINO_ESP32S2PAR8_H_

#endif // #if CONFIG_IDF_TARGET_ESP32S2

0 comments on commit e14fcfa

Please sign in to comment.