mirror of
https://github.com/felis/USB_Host_Shield_2.0.git
synced 2024-03-22 11:31:26 +01:00
commit
03933edb41
8 changed files with 143 additions and 62 deletions
|
@ -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
|
||||
|
|
|
@ -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):
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
61
avrpins.h
61
avrpins.h
|
@ -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"
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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()
|
||||
|
@ -50,7 +59,6 @@ void setup()
|
|||
while (1); //halt
|
||||
}//if (Usb.Init() == -1...
|
||||
|
||||
|
||||
init_leds();
|
||||
init_buttons();
|
||||
b1 = digitalRead(BUTTON1);
|
||||
|
@ -63,7 +71,11 @@ void loop()
|
|||
Usb.Task();
|
||||
|
||||
if ( adk.isReady() == false ) {
|
||||
#ifdef ESP32
|
||||
ledcWrite(LED1_RED_CHANNEL, 255);
|
||||
#else
|
||||
analogWrite(LED1_RED, 255);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
uint16_t len = sizeof(msg);
|
||||
|
@ -78,7 +90,11 @@ void loop()
|
|||
if (msg[0] == 0x2) {
|
||||
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...
|
||||
|
|
|
@ -51,6 +51,7 @@
|
|||
"atmelsam",
|
||||
"nordicnrf51",
|
||||
"ststm32",
|
||||
"espressif8266"
|
||||
"espressif8266",
|
||||
"espressif32"
|
||||
]
|
||||
}
|
||||
|
|
14
usbhost.h
14
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);
|
||||
|
|
Loading…
Reference in a new issue