diff --git a/.travis.yml b/.travis.yml index c64877dd..0afe6bfe 100644 --- a/.travis.yml +++ b/.travis.yml @@ -75,4 +75,4 @@ install: script: - platformio ci --lib="." --board=uno --board=due --board=genuino101 --board=teensy30 --board=teensy31 --board=teensy35 --board=teensy36 --board=teensylc - - platformio ci --lib="." --board=esp12e --board=nodemcu --project-option="build_flags=-Wno-unused-function" # Workaround https://github.com/esp8266/Arduino/pull/2881 + - platformio ci --lib="." --board=esp12e --board=nodemcu --board=esp32dev --project-option="build_flags=-Wno-unused-function" # Workaround https://github.com/esp8266/Arduino/pull/2881 diff --git a/README.md b/README.md index 9a42558e..69970546 100644 --- a/README.md +++ b/README.md @@ -128,6 +128,8 @@ Currently the following boards are supported by the library: * Also please be aware that: * GPIO16 is **NOT** usable, as it will be used for some other purposes. For example, reset the SoC itself from sleep mode. * GPIO6 to 11 is also **NOT** usable, as they are used to connect SPI flash chip and it is used for storing the executable binary content. +* ESP32 is supported using the [arduino-esp32](https://github.com/espressif/arduino-esp32/) + * GPIO5 : SS, GPIO17 : INT, GPIO18 : SCK, GPIO19 : MISO, GPIO23 : MOSI The following boards need to be activated manually in [settings.h](settings.h): diff --git a/UsbCore.h b/UsbCore.h index efa20da9..dc0cffd7 100644 --- a/UsbCore.h +++ b/UsbCore.h @@ -41,6 +41,8 @@ typedef MAX3421e MAX3421E; // Balanduino typedef MAX3421e MAX3421E; // The Intel Galileo supports much faster read and write speed at pin 2 and 3 #elif defined(ESP8266) typedef MAX3421e MAX3421E; // ESP8266 boards +#elif defined(ESP32) +typedef MAX3421e MAX3421E; // ESP32 boards #else typedef MAX3421e MAX3421E; // Official Arduinos (UNO, Duemilanove, Mega, 2560, Leonardo, Due etc.), Intel Edison, Intel Galileo 2 or Teensy 2.0 and 3.x #endif diff --git a/avrpins.h b/avrpins.h index 8f329fa4..1f57bd48 100644 --- a/avrpins.h +++ b/avrpins.h @@ -1326,9 +1326,8 @@ MAKE_PIN(P13, 13); // #undef MAKE_PIN -#elif defined(ESP8266) +#elif defined(ESP8266) || defined(ESP32) -#define pgm_read_pointer(p) pgm_read_ptr(p) #define MAKE_PIN(className, pin) \ class className { \ @@ -1350,6 +1349,10 @@ public: \ } \ }; +#if defined(ESP8266) + +#define pgm_read_pointer(p) pgm_read_ptr(p) + // Pinout for ESP-12 module // 0 .. 16 - Digital pins // GPIO 6 to 11 and 16 are not usable in this library. @@ -1365,6 +1368,24 @@ MAKE_PIN(P13, 13); // MOSI MAKE_PIN(P14, 14); // SCK MAKE_PIN(P15, 15); // SS +#elif defined(ESP32) + +// Pinout for ESP32 dev module + +MAKE_PIN(P0, 0); +MAKE_PIN(P1, 1); // TX0 +MAKE_PIN(P10, 10); // TX1 +MAKE_PIN(P3, 3); // RX0 +MAKE_PIN(P21, 21); // SDA +MAKE_PIN(P22, 22); // SCL +MAKE_PIN(P19, 19); // MISO +MAKE_PIN(P23, 23); // MOSI +MAKE_PIN(P18, 18); // SCK +MAKE_PIN(P5, 5); // SS +MAKE_PIN(P17, 17); // INT + +#endif + #undef MAKE_PIN #else diff --git a/controllerEnums.h b/controllerEnums.h index e51f15ca..631825b2 100644 --- a/controllerEnums.h +++ b/controllerEnums.h @@ -18,6 +18,10 @@ #ifndef _controllerenums_h #define _controllerenums_h +#if defined(ESP32) +#undef PS +#endif + /** * This header file is used to store different enums for the controllers, * This is necessary so all the different libraries can be used at once. diff --git a/library.json b/library.json index f69007b1..06c385be 100644 --- a/library.json +++ b/library.json @@ -51,6 +51,7 @@ "atmelsam", "nordicnrf51", "ststm32", - "espressif8266" + "espressif8266", + "espressif32" ] } diff --git a/usbhost.h b/usbhost.h index 9f17217f..ef1c2583 100644 --- a/usbhost.h +++ b/usbhost.h @@ -111,6 +111,8 @@ typedef SPi< P76, P75, P74, P10 > spi; typedef SPi< P16, P18, P17, P10 > spi; #elif defined(ESP8266) typedef SPi< P14, P13, P12, P15 > spi; +#elif defined(ESP32) +typedef SPi< P18, P23, P19, P5 > spi; #else #error "No SPI entry in usbhost.h" #endif @@ -176,7 +178,7 @@ void MAX3421e< SPI_SS, INTR >::regWr(uint8_t reg, uint8_t data) { c[0] = reg | 0x02; c[1] = data; spi4teensy3::send(c, 2); -#elif defined(SPI_HAS_TRANSACTION) && !defined(ESP8266) +#elif defined(SPI_HAS_TRANSACTION) && !defined(ESP8266) && !defined(ESP32) uint8_t c[2]; c[0] = reg | 0x02; c[1] = data; @@ -186,7 +188,7 @@ void MAX3421e< SPI_SS, INTR >::regWr(uint8_t reg, uint8_t data) { c[0] = reg | 0x02; c[1] = data; HAL_SPI_Transmit(&SPI_Handle, c, 2, HAL_MAX_DELAY); -#elif !defined(SPDR) // ESP8266 +#elif !defined(SPDR) // ESP8266, ESP32 USB_SPI.transfer(reg | 0x02); USB_SPI.transfer(data); #else @@ -218,7 +220,7 @@ uint8_t* MAX3421e< SPI_SS, INTR >::bytesWr(uint8_t reg, uint8_t nbytes, uint8_t* spi4teensy3::send(reg | 0x02); spi4teensy3::send(data_p, nbytes); data_p += nbytes; -#elif defined(SPI_HAS_TRANSACTION) && !defined(ESP8266) +#elif defined(SPI_HAS_TRANSACTION) && !defined(ESP8266) && !defined(ESP32) USB_SPI.transfer(reg | 0x02); USB_SPI.transfer(data_p, nbytes); data_p += nbytes; @@ -231,7 +233,7 @@ uint8_t* MAX3421e< SPI_SS, INTR >::bytesWr(uint8_t reg, uint8_t nbytes, uint8_t* HAL_SPI_Transmit(&SPI_Handle, &data, 1, HAL_MAX_DELAY); HAL_SPI_Transmit(&SPI_Handle, data_p, nbytes, HAL_MAX_DELAY); data_p += nbytes; -#elif !defined(SPDR) // ESP8266 +#elif !defined(SPDR) // ESP8266, ESP32 USB_SPI.transfer(reg | 0x02); while(nbytes) { USB_SPI.transfer(*data_p); @@ -320,7 +322,7 @@ uint8_t* MAX3421e< SPI_SS, INTR >::bytesRd(uint8_t reg, uint8_t nbytes, uint8_t* spi4teensy3::send(reg); spi4teensy3::receive(data_p, nbytes); data_p += nbytes; -#elif defined(SPI_HAS_TRANSACTION) && !defined(ESP8266) +#elif defined(SPI_HAS_TRANSACTION) && !defined(ESP8266) && !defined(ESP32) USB_SPI.transfer(reg); memset(data_p, 0, nbytes); // Make sure we send out empty bytes USB_SPI.transfer(data_p, nbytes); @@ -334,7 +336,7 @@ uint8_t* MAX3421e< SPI_SS, INTR >::bytesRd(uint8_t reg, uint8_t nbytes, uint8_t* memset(data_p, 0, nbytes); // Make sure we send out empty bytes HAL_SPI_Receive(&SPI_Handle, data_p, nbytes, HAL_MAX_DELAY); data_p += nbytes; -#elif !defined(SPDR) // ESP8266 +#elif !defined(SPDR) // ESP8266, ESP32 USB_SPI.transfer(reg); while(nbytes) { *data_p++ = USB_SPI.transfer(0);