Skip to content

Commit

Permalink
Merge pull request #263 from felis/ESP8266
Browse files Browse the repository at this point in the history
Added support for ESP8266
  • Loading branch information
Lauszus authored Jun 14, 2017
2 parents 255df0d + c8b7c9a commit ff8bdb2
Show file tree
Hide file tree
Showing 11 changed files with 139 additions and 34 deletions.
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ env:
- PLATFORMIO_CI_SRC=examples/Bluetooth/SPPMulti
- PLATFORMIO_CI_SRC=examples/Bluetooth/Wii
- PLATFORMIO_CI_SRC=examples/Bluetooth/WiiBalanceBoard
- PLATFORMIO_CI_SRC=examples/Bluetooth/WiiIRCamera
- PLATFORMIO_CI_SRC=examples/Bluetooth/WiiIRCamera PLATFORMIO_BUILD_FLAGS="-DWIICAMERA"
- PLATFORMIO_CI_SRC=examples/Bluetooth/WiiMulti
- PLATFORMIO_CI_SRC=examples/Bluetooth/WiiUProController
- PLATFORMIO_CI_SRC=examples/board_qc
Expand Down Expand Up @@ -63,7 +63,7 @@ env:

install:
- pip install -U platformio
- export PLATFORMIO_BUILD_FLAGS="-DDEBUG_USB_HOST -DWIICAMERA -Wall -Werror"
- export PLATFORMIO_BUILD_FLAGS="$PLATFORMIO_BUILD_FLAGS -DDEBUG_USB_HOST -Wall -Werror"

#
# Libraries from PlatformIO Library Registry:
Expand All @@ -74,4 +74,5 @@ install:
- platformio lib install 62 416 417

script:
- platformio ci --board=uno --board=due --board=genuino101 --board=teensy30 --board=teensy31 --board=teensy35 --board=teensy36 --board=teensylc --lib="."
- 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
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ Currently the following boards are supported by the library:
* Please see: <http://www.circuitsathome.com/mcu/usb/running-usb-host-code-on-digilent-chipkit-board>.
* STM32F4
* Currently the [NUCLEO-F446RE](http://www.st.com/web/catalog/tools/FM116/SC959/SS1532/LN1847/PF262063) is supported featuring the STM32F446. Take a look at the following example code: <https://github.com/Lauszus/Nucleo_F446RE_USBHost>.
* ESP8266 is supported using the [ESP8266 Arduino core](https://github.com/esp8266/Arduino)
* Note it uses pin 15 and 5 for SS and INT respectively
* 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.
The following boards need to be activated manually in [settings.h](settings.h):
Expand Down Expand Up @@ -317,11 +322,11 @@ HID devices are also supported by the library. However these require you to writ
### [MIDI Library](usbh_midi.cpp)
The library support MIDI devices.
The library support MIDI devices.
You can convert USB MIDI keyboard to legacy serial MIDI.
* [USB_MIDI_converter.ino](examples/USBH_MIDI/USB_MIDI_converter/USB_MIDI_converter.ino)
* [USB_MIDI_converter_multi.ino](examples/USBH_MIDI/USB_MIDI_converter_multi/USB_MIDI_converter_multi.ino)
* [USB_MIDI_converter.ino](examples/USBH_MIDI/USB_MIDI_converter/USB_MIDI_converter.ino)
* [USB_MIDI_converter_multi.ino](examples/USBH_MIDI/USB_MIDI_converter_multi/USB_MIDI_converter_multi.ino)
For information see the following page: <http://yuuichiakagawa.github.io/USBH_MIDI/>.
Expand Down
2 changes: 2 additions & 0 deletions UsbCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ typedef MAX3421e<P53, P54> MAX3421E; // Arduino Mega ADK
typedef MAX3421e<P20, P19> MAX3421E; // Balanduino
#elif defined(__ARDUINO_X86__) && PLATFORM_ID == 0x06
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
#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
Expand Down
41 changes: 41 additions & 0 deletions avrpins.h
Original file line number Diff line number Diff line change
Expand Up @@ -1326,6 +1326,47 @@ MAKE_PIN(P13, 13); //

#undef MAKE_PIN

#elif defined(ESP8266)

#define pgm_read_pointer(p) pgm_read_ptr(p)

#define MAKE_PIN(className, pin) \
class className { \
public: \
static void Set() { \
digitalWrite(pin, HIGH);\
} \
static void Clear() { \
digitalWrite(pin, LOW); \
} \
static void SetDirRead() { \
pinMode(pin, INPUT); \
} \
static void SetDirWrite() { \
pinMode(pin, OUTPUT); \
} \
static uint8_t IsSet() { \
return digitalRead(pin); \
} \
};

// Pinout for ESP-12 module
// 0 .. 16 - Digital pins
// GPIO 6 to 11 and 16 are not usable in this library.

MAKE_PIN(P0, 0);
MAKE_PIN(P1, 1); // TX0
MAKE_PIN(P2, 2); // TX1
MAKE_PIN(P3, 3); // RX0
MAKE_PIN(P4, 4); // SDA
MAKE_PIN(P5, 5); // SCL
MAKE_PIN(P12, 12); // MISO
MAKE_PIN(P13, 13); // MOSI
MAKE_PIN(P14, 14); // SCK
MAKE_PIN(P15, 15); // SS

#undef MAKE_PIN

#else
#error "Please define board in avrpins.h"

Expand Down
3 changes: 2 additions & 1 deletion examples/USBH_MIDI/USBH_MIDI_dump/USBH_MIDI_dump.ino
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ void MIDI_poll()
pid = Midi.pid;
}
if (Midi.RecvData( &rcvd, bufMidi) == 0 ) {
sprintf(buf, "%08lX: ", (uint32_t)millis());
uint32_t time = (uint32_t)millis();
sprintf(buf, "%04X%04X: ", (uint16_t)(time >> 16), (uint16_t)(time & 0xFFFF)); // Split variable to prevent warnings on the ESP8266 platform
Serial.print(buf);
Serial.print(rcvd);
Serial.print(':');
Expand Down
6 changes: 5 additions & 1 deletion examples/USB_desc/USB_desc.ino
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ void loop()
Usb.ForEachUsbDevice(&PrintAllDescriptors);
Usb.ForEachUsbDevice(&PrintAllAddresses);

while ( 1 ); //stop
while ( 1 ) { // stop
#ifdef ESP8266
yield(); // needed in order to reset the watchdog timer on the ESP8266
#endif
}
}
}

Expand Down
24 changes: 22 additions & 2 deletions examples/board_qc/board_qc.ino
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ void setup() {
uint8_t sample_rd = 0;
uint8_t gpinpol_copy = Usb.regRd(rGPINPOL);
for(uint8_t i = 0; i < 16; i++) {
#ifdef ESP8266
yield(); // needed in order to reset the watchdog timer on the ESP8266
#endif
for(uint16_t j = 0; j < 65535; j++) {
Usb.regWr(rGPINPOL, sample_wr);
sample_rd = Usb.regRd(rGPINPOL);
Expand All @@ -85,6 +88,9 @@ void setup() {
uint8_t tmpbyte;
E_Notify(PSTR("\r\nGPIO test. Connect GPIN0 to GPOUT7, GPIN1 to GPOUT6, and so on"), 0x80);
for(uint8_t sample_gpio = 0; sample_gpio < 255; sample_gpio++) {
#ifdef ESP8266
yield(); // needed in order to reset the watchdog timer on the ESP8266
#endif
Usb.gpioWr(sample_gpio);
tmpbyte = Usb.gpioRd();
/* bit reversing code copied vetbatim from http://graphics.stanford.edu/~seander/bithacks.html#BitReverseObvious */
Expand Down Expand Up @@ -112,6 +118,9 @@ void setup() {
/* Restart oscillator */
E_Notify(PSTR("\r\nResetting oscillator\r\n"), 0x80);
for(uint16_t i = 0; i < 100; i++) {
#ifdef ESP8266
yield(); // needed in order to reset the watchdog timer on the ESP8266
#endif
E_Notify(PSTR("\rReset number "), 0x80);
Serial.print(i, DEC);
Usb.regWr(rUSBCTL, bmCHIPRES); //reset
Expand Down Expand Up @@ -206,7 +215,11 @@ void loop() {
print_hex(buf.bNumConfigurations, 8);
/**/
E_Notify(PSTR("\r\n\nAll tests passed. Press RESET to restart test"), 0x80);
while(1);
while(1) {
#ifdef ESP8266
yield(); // needed in order to reset the watchdog timer on the ESP8266
#endif
}
}
break;
case( USB_STATE_ERROR):
Expand All @@ -228,6 +241,9 @@ void halt55() {

while(1) {
Usb.regWr(0x55, 0x55);
#ifdef ESP8266
yield(); // needed in order to reset the watchdog timer on the ESP8266
#endif
}
}

Expand All @@ -253,7 +269,11 @@ void print_hex(int v, int num_places) {
/* prints "Press any key" and returns when key is pressed */
void press_any_key() {
E_Notify(PSTR("\r\nPress any key to continue..."), 0x80);
while(Serial.available() <= 0); //wait for input
while(Serial.available() <= 0) { // wait for input
#ifdef ESP8266
yield(); // needed in order to reset the watchdog timer on the ESP8266
#endif
}
Serial.read(); //empty input buffer
return;
}
12 changes: 6 additions & 6 deletions examples/pl2303/pl2303_tinygps/pl2303_tinygps.ino
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,12 @@ void printFloat(double number, int16_t digits)

void gpsdump(TinyGPS &gps)
{
int32_t lat, lon;
long lat, lon;
float flat, flon;
uint32_t age, date, time, chars;
int16_t year;
unsigned long age, date, time, chars;
int year;
uint8_t month, day, hour, minute, second, hundredths;
uint16_t sentences, failed;
unsigned short sentences, failed;

gps.get_position(&lat, &lon, &age);
Serial.print("Lat/Long(10^-5 deg): "); Serial.print(lat); Serial.print(", "); Serial.print(lon);
Expand All @@ -175,7 +175,7 @@ void gpsdump(TinyGPS &gps)

feedgps();

gps.crack_datetime((int*)&year, &month, &day, &hour, &minute, &second, &hundredths, &age);
gps.crack_datetime(&year, &month, &day, &hour, &minute, &second, &hundredths, &age);
Serial.print("Date: "); Serial.print(static_cast<int>(month)); Serial.print("/"); Serial.print(static_cast<int>(day)); Serial.print("/"); Serial.print(year);
Serial.print(" Time: "); Serial.print(static_cast<int>(hour)); Serial.print(":"); Serial.print(static_cast<int>(minute)); Serial.print(":"); Serial.print(static_cast<int>(second)); Serial.print("."); Serial.print(static_cast<int>(hundredths));
Serial.print(" Fix age: "); Serial.print(age); Serial.println("ms.");
Expand All @@ -189,7 +189,7 @@ void gpsdump(TinyGPS &gps)

feedgps();

gps.stats(&chars, (unsigned short*)&sentences, (unsigned short*)&failed);
gps.stats(&chars, &sentences, &failed);
Serial.print("Stats: characters: "); Serial.print(chars); Serial.print(" sentences: "); Serial.print(sentences); Serial.print(" failed checksum: "); Serial.println(failed);
}

Expand Down
3 changes: 2 additions & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"teensy",
"atmelsam",
"nordicnrf51",
"ststm32"
"ststm32",
"espressif8266"
]
}
16 changes: 16 additions & 0 deletions settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,20 @@ extern SPI_HandleTypeDef SPI_Handle; // Needed to be declared in your main.cpp
#define MFK_CASTUINT8T
#endif

// Workaround issue: https://github.com/esp8266/Arduino/issues/2078
#ifdef ESP8266
#undef PROGMEM
#define PROGMEM
#undef PSTR
#define PSTR(s) (s)
#undef pgm_read_byte
#define pgm_read_byte(addr) (*reinterpret_cast<const uint8_t*>(addr))
#undef pgm_read_word
#define pgm_read_word(addr) (*reinterpret_cast<const uint16_t*>(addr))
#endif

#ifdef ARDUINO_ESP8266_WIFIO
#error "This board is currently not supported"
#endif

#endif /* SETTINGS_H */
Loading

0 comments on commit ff8bdb2

Please sign in to comment.