Skip to content

Commit

Permalink
check ESP32 CONFIG_IDF_TARGET #63
Browse files Browse the repository at this point in the history
  • Loading branch information
moononournation committed Jun 14, 2021
1 parent 47c5dee commit 38bbf95
Show file tree
Hide file tree
Showing 16 changed files with 113 additions and 71 deletions.
2 changes: 1 addition & 1 deletion examples/PDQgraphicstest/PDQgraphicstest.ino
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ Arduino_GFX *gfx = new Arduino_ST7789(bus, -1 /* RST */, 2 /* rotation */, true
Arduino_DataBus *bus = new Arduino_NRFXSPI(TFT_DC, TFT_CS, 13 /* SCK */, 11 /* MOSI */, 12 /* MISO */);
#elif defined(ARDUINO_RASPBERRY_PI_PICO)
Arduino_DataBus *bus = new Arduino_RPiPicoSPI(TFT_DC, TFT_CS, PIN_SPI0_SCK /* SCK */, PIN_SPI0_MOSI /* MOSI */, PIN_SPI0_MISO /* MISO */, spi0 /* spi */);
#elif defined(ESP32)
#elif CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4
Arduino_DataBus *bus = new Arduino_ESP32SPI(TFT_DC, TFT_CS, 18 /* SCK */, 23 /* MOSI */, -1 /* MISO */, VSPI /* spi_num */);
#elif defined(ESP8266)
Arduino_DataBus *bus = new Arduino_ESP8266SPI(TFT_DC, TFT_CS);
Expand Down
2 changes: 1 addition & 1 deletion src/Arduino_GFX_Library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Arduino_DataBus *create_default_Arduino_DataBus()
return new Arduino_NRFXSPI(TFT_DC, TFT_CS, TFT_SCK, TFT_MOSI, TFT_MISO);
#elif defined(ARDUINO_RASPBERRY_PI_PICO)
return new Arduino_RPiPicoSPI(TFT_DC, TFT_CS, TFT_SCK, TFT_MOSI, TFT_MISO, spi0);
#elif defined(ESP32)
#elif CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4
return new Arduino_ESP32SPI(TFT_DC, TFT_CS, TFT_SCK, TFT_MOSI, TFT_MISO);
#elif defined(ESP8266)
return new Arduino_ESP8266SPI(TFT_DC, TFT_CS);
Expand Down
9 changes: 6 additions & 3 deletions src/databus/Arduino_ESP32I2S8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
* start rewrite from:
* https://github.com/lovyan03/LovyanGFX/blob/master/src/lgfx/v0/platforms/LGFX_PARALLEL_ESP32.hpp
*/
#ifdef ESP32

#include "Arduino_DataBus.h"

#if CONFIG_IDF_TARGET_ESP32

#include "soc/dport_reg.h"

#include "Arduino_ESP32I2S8.h"

// #define SET_DATA_AND_WR_AT_THE_SAME_TIME
Expand Down Expand Up @@ -328,4 +331,4 @@ INLINE void Arduino_ESP32I2S8::CS_LOW(void)
}
}

#endif
#endif // #if CONFIG_IDF_TARGET_ESP32
10 changes: 6 additions & 4 deletions src/databus/Arduino_ESP32I2S8.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
* start rewrite from:
* https://github.com/lovyan03/LovyanGFX/blob/master/src/lgfx/v0/platforms/LGFX_PARALLEL_ESP32.hpp
*/
#ifdef ESP32
#include "Arduino_DataBus.h"

#if CONFIG_IDF_TARGET_ESP32

#ifndef _ARDUINO_ESP32I2S8_H_
#define _ARDUINO_ESP32I2S8_H_

#include <driver/i2s.h>
#include <soc/i2s_reg.h>

#include "Arduino_DataBus.h"

#define SAFE_I2S_FIFO_WR_REG(i) (0x6000F000 + ((i)*0x1E000))
#define SPI_MAX_PIXELS_AT_ONCE 32

Expand Down Expand Up @@ -63,4 +64,5 @@ class Arduino_ESP32I2S8 : public Arduino_DataBus
};

#endif // _ARDUINO_ESP32I2S8_H_
#endif // #ifdef ESP32

#endif // #if CONFIG_IDF_TARGET_ESP32
8 changes: 5 additions & 3 deletions src/databus/Arduino_ESP32PAR16.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifdef ESP32

#include "Arduino_DataBus.h"

#if CONFIG_IDF_TARGET_ESP32

#include "Arduino_ESP32PAR16.h"

Arduino_ESP32PAR16::Arduino_ESP32PAR16(
Expand Down Expand Up @@ -385,4 +386,5 @@ INLINE void Arduino_ESP32PAR16::CS_LOW(void)
*_csPortClr = _csPinMask;
}

#endif // #ifdef ESP32
#endif // #if CONFIG_IDF_TARGET_ESP32

8 changes: 4 additions & 4 deletions src/databus/Arduino_ESP32PAR16.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#ifdef ESP32
#include "Arduino_DataBus.h"

#if CONFIG_IDF_TARGET_ESP32

#ifndef _ARDUINO_ESP32PAR16_H_
#define _ARDUINO_ESP32PAR16_H_

#include "Arduino_DataBus.h"

class Arduino_ESP32PAR16 : public Arduino_DataBus
{
public:
Expand Down Expand Up @@ -71,4 +71,4 @@ class Arduino_ESP32PAR16 : public Arduino_DataBus

#endif // _ARDUINO_ESP32PAR16_H_

#endif // #ifdef ESP32
#endif // #if CONFIG_IDF_TARGET_ESP32
7 changes: 4 additions & 3 deletions src/databus/Arduino_ESP32PAR16Q.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifdef ESP32

#include "Arduino_DataBus.h"

#if CONFIG_IDF_TARGET_ESP32

#include "Arduino_ESP32PAR16Q.h"

Arduino_ESP32PAR16Q::Arduino_ESP32PAR16Q(
Expand Down Expand Up @@ -377,4 +378,4 @@ INLINE void Arduino_ESP32PAR16Q::CS_LOW(void)
*_csPortClr = _csPinMask;
}

#endif // #ifdef ESP32
#endif // #if CONFIG_IDF_TARGET_ESP32
8 changes: 4 additions & 4 deletions src/databus/Arduino_ESP32PAR16Q.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#ifdef ESP32
#include "Arduino_DataBus.h"

#if CONFIG_IDF_TARGET_ESP32

#ifndef _ARDUINO_ESP32PAR16Q_H_
#define _ARDUINO_ESP32PAR16Q_H_

#include "Arduino_DataBus.h"

class Arduino_ESP32PAR16Q : public Arduino_DataBus
{
public:
Expand Down Expand Up @@ -71,4 +71,4 @@ class Arduino_ESP32PAR16Q : public Arduino_DataBus

#endif // _ARDUINO_ESP32PAR16Q_H_

#endif // #ifdef ESP32
#endif // #if CONFIG_IDF_TARGET_ESP32
7 changes: 4 additions & 3 deletions src/databus/Arduino_ESP32PAR8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
* start rewrite from:
* https://github.com/daumemo/IPS_LCD_R61529_FT6236_Arduino_eSPI_Test
*/
#ifdef ESP32

#include "Arduino_DataBus.h"

#if CONFIG_IDF_TARGET_ESP32

#include "Arduino_ESP32PAR8.h"

Arduino_ESP32PAR8::Arduino_ESP32PAR8(
Expand Down Expand Up @@ -352,4 +353,4 @@ INLINE void Arduino_ESP32PAR8::CS_LOW(void)
*_csPortClr = _csPinMask;
}

#endif // #ifdef ESP32
#endif // #if CONFIG_IDF_TARGET_ESP32
8 changes: 4 additions & 4 deletions src/databus/Arduino_ESP32PAR8.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
* start rewrite from:
* https://github.com/daumemo/IPS_LCD_R61529_FT6236_Arduino_eSPI_Test
*/
#ifdef ESP32
#include "Arduino_DataBus.h"

#if CONFIG_IDF_TARGET_ESP32

#ifndef _ARDUINO_ESP32PAR8_H_
#define _ARDUINO_ESP32PAR8_H_

#include "Arduino_DataBus.h"

class Arduino_ESP32PAR8 : public Arduino_DataBus
{
public:
Expand Down Expand Up @@ -71,4 +71,4 @@ class Arduino_ESP32PAR8 : public Arduino_DataBus

#endif // _ARDUINO_ESP32PAR8_H_

#endif // #ifdef ESP32
#endif // #if CONFIG_IDF_TARGET_ESP32
7 changes: 4 additions & 3 deletions src/databus/Arduino_ESP32PAR8Q.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
* start rewrite from:
* https://github.com/daumemo/IPS_LCD_R61529_FT6236_Arduino_eSPI_Test
*/
#ifdef ESP32

#include "Arduino_DataBus.h"

#if CONFIG_IDF_TARGET_ESP32

#include "Arduino_ESP32PAR8Q.h"

Arduino_ESP32PAR8Q::Arduino_ESP32PAR8Q(
Expand Down Expand Up @@ -345,4 +346,4 @@ INLINE void Arduino_ESP32PAR8Q::CS_LOW(void)
*_csPortClr = _csPinMask;
}

#endif // #ifdef ESP32
#endif // #if CONFIG_IDF_TARGET_ESP32
8 changes: 4 additions & 4 deletions src/databus/Arduino_ESP32PAR8Q.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
* start rewrite from:
* https://github.com/daumemo/IPS_LCD_R61529_FT6236_Arduino_eSPI_Test
*/
#ifdef ESP32
#include "Arduino_DataBus.h"

#if CONFIG_IDF_TARGET_ESP32

#ifndef _ARDUINO_ESP32PAR8Q_H_
#define _ARDUINO_ESP32PAR8Q_H_

#include "Arduino_DataBus.h"

class Arduino_ESP32PAR8Q : public Arduino_DataBus
{
public:
Expand Down Expand Up @@ -71,4 +71,4 @@ class Arduino_ESP32PAR8Q : public Arduino_DataBus

#endif // _ARDUINO_ESP32PAR8Q_H_

#endif // #ifdef ESP32
#endif // #if CONFIG_IDF_TARGET_ESP32
25 changes: 5 additions & 20 deletions src/databus/Arduino_ESP32SPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
* start rewrite from:
* https://github.com/espressif/arduino-esp32.git
*/
#ifdef ESP32

#include "Arduino_DataBus.h"

#if CONFIG_IDF_TARGET_ESP32

#include "Arduino_ESP32SPI.h"

#define WAIT_SPI_NOT_BUSY while (_spi->dev->cmd.usr)
Expand Down Expand Up @@ -141,23 +142,7 @@ void Arduino_ESP32SPI::begin(int32_t speed, int8_t dataMode)
}
#endif

#if CONFIG_IDF_TARGET_ESP32S2
if (_spi_num == FSPI)
{
DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_SPI2_CLK_EN);
DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_SPI2_RST);
}
else if (_spi_num == HSPI)
{
DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_SPI3_CLK_EN);
DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_SPI3_RST);
}
else
{
DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_SPI01_CLK_EN);
DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_SPI01_RST);
}
#elif defined(DPORT_SPI2_CLK_EN)
#if defined(DPORT_SPI2_CLK_EN)
if (_spi_num == HSPI)
{
DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_SPI2_CLK_EN);
Expand Down Expand Up @@ -900,4 +885,4 @@ INLINE void Arduino_ESP32SPI::CS_LOW(void)
*_csPortClr = _csPinMask;
}

#endif // #ifdef ESP32
#endif // #if CONFIG_IDF_TARGET_ESP32
8 changes: 4 additions & 4 deletions src/databus/Arduino_ESP32SPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
* start rewrite from:
* https://github.com/espressif/arduino-esp32.git
*/
#ifdef ESP32
#include "Arduino_DataBus.h"

#if CONFIG_IDF_TARGET_ESP32

#ifndef _ARDUINO_ESP32SPI_H_
#define _ARDUINO_ESP32SPI_H_

#include "soc/spi_struct.h"
#include "soc/dport_reg.h"

#include "Arduino_DataBus.h"

#define SPI_MAX_PIXELS_AT_ONCE 32

#define SPI_SPI_SS_IDX(n) ((n == 0) ? SPICS0_OUT_IDX : ((n == 1) ? SPICS1_OUT_IDX : ((n == 2) ? SPICS2_OUT_IDX : SPICS0_OUT_IDX)))
Expand Down Expand Up @@ -80,4 +80,4 @@ class Arduino_ESP32SPI : public Arduino_DataBus

#endif // _ARDUINO_ESP32SPI_H_

#endif // #ifdef ESP32
#endif // #if CONFIG_IDF_TARGET_ESP32
22 changes: 21 additions & 1 deletion src/databus/Arduino_HWSPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,27 @@ void Arduino_HWSPI::begin(int32_t speed, int8_t dataMode)
_csPortClr = (PORTreg_t)_dcPortClr;
_csPinMask = 0;
}
#elif defined(ESP32)
#elif CONFIG_IDF_TARGET_ESP32C3
_dcPinMask = digitalPinToBitMask(_dc);
_dcPortSet = (PORTreg_t)&GPIO.out_w1ts;
_dcPortClr = (PORTreg_t)&GPIO.out_w1tc;
if (_cs >= 0)
{
_csPinMask = digitalPinToBitMask(_cs);
_csPortSet = (PORTreg_t)&GPIO.out_w1ts;
_csPortClr = (PORTreg_t)&GPIO.out_w1tc;
}
else
{
// No chip-select line defined; might be permanently tied to GND.
// Assign a valid GPIO register (though not used for CS), and an
// empty pin bitmask...the nonsense bit-twiddling might be faster
// than checking _cs and possibly branching.
_csPortSet = _dcPortSet;
_csPortClr = _dcPortClr;
_csPinMask = 0;
}
#elif defined(ESP32)
_dcPinMask = digitalPinToBitMask(_dc);
if (_dc >= 32)
{
Expand Down
45 changes: 36 additions & 9 deletions src/databus/Arduino_SWSPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,42 @@ void Arduino_SWSPI::begin(int32_t speed, int8_t dataMode)
_misoPinMask = 0;
_misoPort = (PORTreg_t)portInputRegister(digitalPinToPort(_sck));
}
#elif CONFIG_IDF_TARGET_ESP32C3
_sckPinMask = digitalPinToBitMask(_sck);
_sckPortSet = (PORTreg_t)&GPIO.out_w1ts;
_sckPortClr = (PORTreg_t)&GPIO.out_w1tc;
_mosiPinMask = digitalPinToBitMask(_mosi);
_mosiPortSet = (PORTreg_t)&GPIO.out_w1ts;
_mosiPortClr = (PORTreg_t)&GPIO.out_w1tc;
_dcPinMask = digitalPinToBitMask(_dc);
_dcPortSet = (PORTreg_t)&GPIO.out_w1ts;
_dcPortClr = (PORTreg_t)&GPIO.out_w1tc;
if (_cs >= 0)
{
_csPinMask = digitalPinToBitMask(_cs);
_csPortSet = (PORTreg_t)&GPIO.out_w1ts;
_csPortClr = (PORTreg_t)&GPIO.out_w1tc;
}
else
{
// No chip-select line defined; might be permanently tied to GND.
// Assign a valid GPIO register (though not used for CS), and an
// empty pin bitmask...the nonsense bit-twiddling might be faster
// than checking _cs and possibly branching.
_csPortSet = _dcPortSet;
_csPortClr = _dcPortClr;
_csPinMask = 0;
}
if (_miso >= 0)
{
_misoPinMask = digitalPinToBitMask(_miso);
_misoPort = (PORTreg_t)GPIO_IN_REG;
}
else
{
_misoPinMask = 0;
_misoPort = (PORTreg_t)GPIO_IN_REG;
}
#elif defined(ESP32)
_sckPinMask = digitalPinToBitMask(_sck);
_mosiPinMask = digitalPinToBitMask(_mosi);
Expand Down Expand Up @@ -174,15 +210,6 @@ void Arduino_SWSPI::begin(int32_t speed, int8_t dataMode)
_csPinMask = 0;
}
if (_miso >= 0)
{
_misoPort = portInputRegister(_miso);
_misoPinMask = digitalPinToBitMask(_miso);
}
else
{
_misoPort = portInputRegister(_miso);
}
if (_miso >= 0)
{
_misoPinMask = digitalPinToBitMask(_miso);
_misoPort = (PORTreg_t)portInputRegister(digitalPinToPort(_miso));
Expand Down

0 comments on commit 38bbf95

Please sign in to comment.