Skip to content

Commit bc2d4ec

Browse files
earlephilhowerdevyte
authored andcommittedSep 18, 2018
Allow GPIO 9 and 10 for waveform generation (#5055)
* Allow GPIO 9 and 10 for waveform generation While most ESP8266 modules use quad-io mode for their SPI flash ROM, there are some which only use dual-io mode. Allow the unused pins (GPIO 9 and 10) to have waveforms generated on them. Should the user try this on a quad-io mode board, expect very bad things to happen. * Add variant for 8285 to init GPIO 9/10 The 8285 only has 2-bit flash IO, so the other two pins can be used as inputs (9/10). Set them to input to mirror the way other pins are set up. * Update waveform gen to only allow 9/10 on 8285 Update the common.h in both generic (remove TODO, it's done!) and the 8285 variant to make isFlashInterfacePin macro correct. Use that macro to disable pins 9 and 10 in the common, non-8285 case.
1 parent cd43337 commit bc2d4ec

File tree

7 files changed

+143
-3
lines changed

7 files changed

+143
-3
lines changed
 

‎boards.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ generic.menu.baud.921600.upload.speed=921600
360360
##############################################################
361361
esp8285.name=Generic ESP8285 Module
362362
esp8285.build.board=ESP8266_ESP01
363+
esp8285.build.variant=esp8285
363364
esp8285.upload.tool=esptool
364365
esp8285.upload.maximum_data_size=81920
365366
esp8285.upload.wait_for_upload_port=true
@@ -368,7 +369,6 @@ esp8285.serial.disableDTR=true
368369
esp8285.serial.disableRTS=true
369370
esp8285.build.mcu=esp8266
370371
esp8285.build.core=esp8266
371-
esp8285.build.variant=generic
372372
esp8285.build.spiffs_pagesize=256
373373
esp8285.build.debug_port=
374374
esp8285.build.debug_level=

‎cores/esp8266/core_esp8266_waveform.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,13 @@ static Waveform waveform[] = {
7979
{0, 0, 1<<3, 0, 0, 0, 0, 0},
8080
{0, 0, 1<<4, 0, 0, 0, 0, 0},
8181
{0, 0, 1<<5, 0, 0, 0, 0, 0},
82-
// GPIOS 6-11 not allowed, used for flash
82+
// GPIOS 6-8 not allowed, used for flash
83+
// GPIO 9 and 10 only allowed in 2-bit flash mode
84+
#if !isFlashInterfacePin(9)
85+
{0, 0, 1<<9, 0, 0, 0, 0, 0},
86+
{0, 0, 1<<10, 0, 0, 0, 0, 0},
87+
#endif
88+
// GPIO 11 not allowed, used for flash
8389
{0, 0, 1<<12, 0, 0, 0, 0, 0},
8490
{0, 0, 1<<13, 0, 0, 0, 0, 0},
8591
{0, 0, 1<<14, 0, 0, 0, 0, 0},

‎tools/boards.txt.py

+1
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@
271271
'name': 'Generic ESP8285 Module',
272272
'opts': {
273273
'.build.board': 'ESP8266_ESP01',
274+
'.build.variant': 'esp8285'
274275
},
275276
'macro': [
276277
'resetmethod_menu',

‎variants/esp8285/common.h

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
common.h - Commoon pin definition functions for ESP8266 boards
3+
Part of Arduino - http://www.arduino.cc/
4+
5+
Copyright (c) 2007 David A. Mellis
6+
Modified for ESP8266 platform by Ivan Grokhotkov, 2014-2016.
7+
8+
This library is free software; you can redistribute it and/or
9+
modify it under the terms of the GNU Lesser General Public
10+
License as published by the Free Software Foundation; either
11+
version 2.1 of the License, or (at your option) any later version.
12+
13+
This library is distributed in the hope that it will be useful,
14+
but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16+
Lesser General Public License for more details.
17+
18+
You should have received a copy of the GNU Lesser General
19+
Public License along with this library; if not, write to the
20+
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
21+
Boston, MA 02111-1307 USA
22+
23+
$Id: wiring.h 249 2007-02-03 16:52:51Z mellis $
24+
*/
25+
26+
#ifndef GENERIC_COMMON_H
27+
#define GENERIC_COMMON_H
28+
29+
#define EXTERNAL_NUM_INTERRUPTS 16
30+
#define NUM_DIGITAL_PINS 17
31+
#define NUM_ANALOG_INPUTS 1
32+
33+
// Pins 9 and 10 are available, go to positive logic since it's clearer
34+
#define isFlashInterfacePin(p) ((p) == 6 || (p) == 7 || (p) == 8 || (p) == 11)
35+
36+
#define analogInputToDigitalPin(p) ((p > 0) ? NOT_A_PIN : 0)
37+
#define digitalPinToInterrupt(p) (((p) < EXTERNAL_NUM_INTERRUPTS)? (p) : NOT_AN_INTERRUPT)
38+
#define digitalPinHasPWM(p) (((p) < NUM_DIGITAL_PINS && !isFlashInterfacePin(p))? 1 : 0)
39+
40+
#define PIN_SPI_SS (15)
41+
#define PIN_SPI_MOSI (13)
42+
#define PIN_SPI_MISO (12)
43+
#define PIN_SPI_SCK (14)
44+
45+
static const uint8_t SS = PIN_SPI_SS;
46+
static const uint8_t MOSI = PIN_SPI_MOSI;
47+
static const uint8_t MISO = PIN_SPI_MISO;
48+
static const uint8_t SCK = PIN_SPI_SCK;
49+
50+
#ifndef PIN_A0
51+
#define PIN_A0 (17)
52+
#endif /* PIN_A0 */
53+
54+
static const uint8_t A0 = PIN_A0;
55+
56+
// These serial port names are intended to allow libraries and architecture-neutral
57+
// sketches to automatically default to the correct port name for a particular type
58+
// of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,
59+
// the first hardware serial port whose RX/TX pins are not dedicated to another use.
60+
//
61+
// SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor
62+
//
63+
// SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
64+
//
65+
// SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library
66+
//
67+
// SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins.
68+
//
69+
// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
70+
// pins are NOT connected to anything by default.
71+
#define SERIAL_PORT_MONITOR Serial
72+
#define SERIAL_PORT_USBVIRTUAL Serial
73+
#define SERIAL_PORT_HARDWARE Serial
74+
#define SERIAL_PORT_HARDWARE_OPEN Serial1
75+
76+
#ifdef LED_BUILTIN
77+
#ifdef __cplusplus
78+
extern "C"
79+
#endif
80+
const int BUILTIN_LED __attribute__((deprecated, weak)) = LED_BUILTIN;
81+
#endif
82+
83+
#endif /* GENERIC_COMMON_H */

‎variants/esp8285/initD9D10Pins.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include "Arduino.h"
2+
3+
// The 8285 allows the use of GPIO pins 9 and 10, so set them to inputs
4+
// on startup just like the other pins. This allows their use for interrupts
5+
// as well
6+
void initVariant() {
7+
pinMode(9, INPUT);
8+
pinMode(10, INPUT);
9+
}
10+

‎variants/esp8285/pins_arduino.h

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
pins_arduino.h - Pin definition functions for Arduino
3+
Part of Arduino - http://www.arduino.cc/
4+
5+
Copyright (c) 2007 David A. Mellis
6+
Modified for ESP8266 platform by Ivan Grokhotkov, 2014-2015.
7+
8+
This library is free software; you can redistribute it and/or
9+
modify it under the terms of the GNU Lesser General Public
10+
License as published by the Free Software Foundation; either
11+
version 2.1 of the License, or (at your option) any later version.
12+
13+
This library is distributed in the hope that it will be useful,
14+
but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16+
Lesser General Public License for more details.
17+
18+
You should have received a copy of the GNU Lesser General
19+
Public License along with this library; if not, write to the
20+
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
21+
Boston, MA 02111-1307 USA
22+
23+
$Id: wiring.h 249 2007-02-03 16:52:51Z mellis $
24+
*/
25+
26+
#ifndef Pins_Arduino_h
27+
#define Pins_Arduino_h
28+
29+
#define PIN_WIRE_SDA (4)
30+
#define PIN_WIRE_SCL (5)
31+
32+
static const uint8_t SDA = PIN_WIRE_SDA;
33+
static const uint8_t SCL = PIN_WIRE_SCL;
34+
35+
#ifndef LED_BUILTIN
36+
#define LED_BUILTIN 1
37+
#endif
38+
39+
#include "common.h"
40+
41+
#endif /* Pins_Arduino_h */

‎variants/generic/common.h

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
#define NUM_DIGITAL_PINS 17
3131
#define NUM_ANALOG_INPUTS 1
3232

33-
// TODO: this should be <= 9 if flash is in DIO mode
3433
#define isFlashInterfacePin(p) ((p) >= 6 && (p) <= 11)
3534

3635
#define analogInputToDigitalPin(p) ((p > 0) ? NOT_A_PIN : 0)

0 commit comments

Comments
 (0)