Merge pull request #341 from felis/ESP32

Added support for ESP32
This commit is contained in:
Kristian Sloth Lauszus 2018-01-15 09:58:09 +01:00 committed by GitHub
commit 03933edb41
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 143 additions and 62 deletions

View file

@ -74,5 +74,4 @@ install:
- platformio lib install 62 416 417
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=uno --board=due --board=genuino101 --board=teensy30 --board=teensy31 --board=teensy35 --board=teensy36 --board=teensylc --board=esp12e --board=nodemcu --board=esp32dev

View file

@ -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):

View file

@ -41,6 +41,8 @@ typedef MAX3421e<P20, P19> MAX3421E; // Balanduino
typedef MAX3421e<P3, P2> MAX3421E; // The Intel Galileo supports much faster read and write speed at pin 2 and 3
#elif defined(ESP8266)
typedef MAX3421e<P15, P5> MAX3421E; // ESP8266 boards
#elif defined(ESP32)
typedef MAX3421e<P5, P17> MAX3421E; // ESP32 boards
#else
typedef MAX3421e<P10, P9> MAX3421E; // Official Arduinos (UNO, Duemilanove, Mega, 2560, Leonardo, Due etc.), Intel Edison, Intel Galileo 2 or Teensy 2.0 and 3.x
#endif

View file

@ -1326,9 +1326,7 @@ MAKE_PIN(P13, 13); //
#undef MAKE_PIN
#elif defined(ESP8266)
#define pgm_read_pointer(p) pgm_read_ptr(p)
#elif defined(ESP8266) || defined(ESP32)
#define MAKE_PIN(className, pin) \
class className { \
@ -1350,6 +1348,8 @@ public: \
} \
};
#if defined(ESP8266)
// Pinout for ESP-12 module
// 0 .. 16 - Digital pins
// GPIO 6 to 11 and 16 are not usable in this library.
@ -1365,8 +1365,63 @@ MAKE_PIN(P13, 13); // MOSI
MAKE_PIN(P14, 14); // SCK
MAKE_PIN(P15, 15); // SS
#elif defined(ESP32)
// Workaround strict-aliasing warnings
#ifdef pgm_read_word
#undef pgm_read_word
#endif
#ifdef pgm_read_dword
#undef pgm_read_dword
#endif
#ifdef pgm_read_float
#undef pgm_read_float
#endif
#ifdef pgm_read_ptr
#undef pgm_read_ptr
#endif
#define pgm_read_word(addr) ({ \
typeof(addr) _addr = (addr); \
*(const unsigned short *)(_addr); \
})
#define pgm_read_dword(addr) ({ \
typeof(addr) _addr = (addr); \
*(const unsigned long *)(_addr); \
})
#define pgm_read_float(addr) ({ \
typeof(addr) _addr = (addr); \
*(const float *)(_addr); \
})
#define pgm_read_ptr(addr) ({ \
typeof(addr) _addr = (addr); \
*(void * const *)(_addr); \
})
// 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
// pgm_read_ptr is not defined in the ESP32, so we have to undef the diffinition from version_helper.h
#ifdef pgm_read_pointer
#undef pgm_read_pointer
#endif
#define pgm_read_pointer(p) pgm_read_ptr(p)
#else
#error "Please define board in avrpins.h"

View file

@ -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.

View file

@ -10,7 +10,7 @@
USB Usb;
USBHub hub0(&Usb);
USBHub hub1(&Usb);
ADK adk(&Usb,"Google, Inc.",
ADK adk(&Usb, "Google, Inc.",
"DemoKit",
"DemoKit Arduino Board",
"1.0",
@ -22,6 +22,10 @@ uint8_t b, b1;
#define LED1_RED 3
#define BUTTON1 2
#ifdef ESP32
#define LED1_RED_CHANNEL 0
#endif
void init_buttons()
{
pinMode(BUTTON1, INPUT);
@ -34,7 +38,12 @@ void init_leds()
{
digitalWrite(LED1_RED, 0);
#ifdef ESP32
ledcAttachPin(LED1_RED, LED1_RED_CHANNEL); // Assign LED pin to channel 0
ledcSetup(LED1_RED_CHANNEL, 12000, 8); // 12 kHz PWM, 8-bit resolution
#else
pinMode(LED1_RED, OUTPUT);
#endif
}
void setup()
@ -47,10 +56,9 @@ void setup()
if (Usb.Init() == -1) {
Serial.println("OSCOKIRQ failed to assert");
while(1); //halt
while (1); //halt
}//if (Usb.Init() == -1...
init_leds();
init_buttons();
b1 = digitalRead(BUTTON1);
@ -62,23 +70,31 @@ void loop()
uint8_t msg[3] = { 0x00 };
Usb.Task();
if( adk.isReady() == false ) {
if ( adk.isReady() == false ) {
#ifdef ESP32
ledcWrite(LED1_RED_CHANNEL, 255);
#else
analogWrite(LED1_RED, 255);
#endif
return;
}
uint16_t len = sizeof(msg);
rcode = adk.RcvData(&len, msg);
if( rcode ) {
if ( rcode ) {
USBTRACE2("Data rcv. :", rcode );
}
if(len > 0) {
if (len > 0) {
USBTRACE("\r\nData Packet.");
// assumes only one command per packet
if (msg[0] == 0x2) {
switch( msg[1] ) {
switch ( msg[1] ) {
case 0:
#ifdef ESP32
ledcWrite(LED1_RED_CHANNEL, 255 - msg[2]);
#else
analogWrite(LED1_RED, 255 - msg[2]);
#endif
break;
}//switch( msg[1]...
}//if (msg[0] == 0x2...
@ -92,7 +108,7 @@ void loop()
msg[1] = 0;
msg[2] = b ? 0 : 1;
rcode = adk.SndData( 3, msg );
if( rcode ) {
if ( rcode ) {
USBTRACE2("Button send: ", rcode );
}
b1 = b;

View file

@ -51,6 +51,7 @@
"atmelsam",
"nordicnrf51",
"ststm32",
"espressif8266"
"espressif8266",
"espressif32"
]
}

View file

@ -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);