Skip to content

Commit a6c02bc

Browse files
committed
Add some missing defines
fixes: espressif#76 fixes: espressif#5 fixes: espressif#91
1 parent 54b1b8b commit a6c02bc

File tree

11 files changed

+28
-18
lines changed

11 files changed

+28
-18
lines changed

cores/esp32/Arduino.h

+16-1
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,20 @@ extern "C" {
100100
#define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
101101
#define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit))
102102

103+
// avr-libc defines _NOP() since 1.6.2
104+
#ifndef _NOP
105+
#define _NOP() do { __asm__ volatile ("nop"); } while (0)
106+
#endif
107+
108+
typedef unsigned int word;
109+
103110
#define bit(b) (1UL << (b))
104111
#define _BV(b) (1UL << (b))
105112

106113
#define digitalPinToPort(pin) (((pin)>31)?1:0)
107-
#define digitalPinToBitMask(pin) (1UL << (pin))
114+
#define digitalPinToBitMask(pin) (1UL << (((pin)>31)?((pin)-31):(pin)))
108115
#define digitalPinToTimer(pin) (0)
116+
#define analogInPinToBit(P) (P)
109117
#define portOutputRegister(port) ((volatile uint32_t*)((port)?GPIO_OUT1_REG:GPIO_OUT_REG))
110118
#define portInputRegister(port) ((volatile uint32_t*)((port)?GPIO_IN1_REG:GPIO_IN_REG))
111119
#define portModeRegister(port) ((volatile uint32_t*)((port)?GPIO_ENABLE1_REG:GPIO_ENABLE_REG))
@@ -118,6 +126,13 @@ extern "C" {
118126
typedef bool boolean;
119127
typedef uint8_t byte;
120128

129+
void init(void);
130+
void initVariant(void);
131+
void initArduino(void);
132+
133+
void setup(void);
134+
void loop(void);
135+
121136
uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder);
122137
void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val);
123138

cores/esp32/esp32-hal-gpio.c

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
#define ETS_GPIO_INUM 12
2828

29+
const int8_t esp32_adc2gpio[20] = {36, -1, -1, 39, 32, 33, 34, 35, -1, -1, 4, 0, 2, 15, 13, 12, 14, 27, 25, 26};
30+
2931
const DRAM_ATTR esp32_gpioMux_t esp32_gpioMux[GPIO_PIN_COUNT]={
3032
{0x44, 11, 11, 1},
3133
{0x88, -1, -1, -1},

cores/esp32/esp32-hal-gpio.h

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ typedef struct {
6565
} esp32_gpioMux_t;
6666

6767
extern const esp32_gpioMux_t esp32_gpioMux[40];
68+
extern const int8_t esp32_adc2gpio[20];
6869

6970
#define digitalPinIsValid(pin) ((pin) < 40 && esp32_gpioMux[(pin)].reg)
7071
#define digitalPinCanOutput(pin) ((pin) < 34 && esp32_gpioMux[(pin)].reg)

cores/esp32/main.cpp

+2-10
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
11
#include "freertos/FreeRTOS.h"
22
#include "freertos/task.h"
3-
#include "esp32-hal.h"
3+
#include "Arduino.h"
44

55
#if CONFIG_AUTOSTART_ARDUINO
66

7-
extern "C" void initArduino();
8-
extern void loop();
9-
extern void setup();
10-
117
void loopTask(void *pvParameters)
128
{
13-
bool setup_done = false;
9+
setup();
1410
for(;;) {
15-
if(!setup_done) {
16-
setup();
17-
setup_done = true;
18-
}
1911
loop();
2012
}
2113
}

variants/esp32/pins_arduino.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#define NUM_DIGITAL_PINS 40
66
#define NUM_ANALOG_INPUTS 16
77

8-
#define analogInputToDigitalPin(p)
8+
#define analogInputToDigitalPin(p) (((p)<20)?(esp32_adc2gpio[(p)]):-1)
99
#define digitalPinToInterrupt(p) (((p)<40)?(p):-1)
1010
#define digitalPinHasPWM(p) (p < 34)
1111

variants/esp320/pins_arduino.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#define NUM_DIGITAL_PINS 12
66
#define NUM_ANALOG_INPUTS 5
77

8-
#define analogInputToDigitalPin(p)
8+
#define analogInputToDigitalPin(p) (((p)<20)?(esp32_adc2gpio[(p)]):-1)
99
#define digitalPinToInterrupt(p) (((p)<40)?(p):-1)
1010
#define digitalPinHasPWM(p) (p < 34)
1111

variants/espea32/pins_arduino.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#define NUM_DIGITAL_PINS 40
66
#define NUM_ANALOG_INPUTS 16
77

8-
#define analogInputToDigitalPin(p)
8+
#define analogInputToDigitalPin(p) (((p)<20)?(esp32_adc2gpio[(p)]):-1)
99
#define digitalPinToInterrupt(p) (((p)<40)?(p):-1)
1010
#define digitalPinHasPWM(p) (p < 34)
1111

variants/lolin32/pins_arduino.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#define NUM_DIGITAL_PINS 40
66
#define NUM_ANALOG_INPUTS 16
77

8-
#define analogInputToDigitalPin(p)
8+
#define analogInputToDigitalPin(p) (((p)<20)?(esp32_adc2gpio[(p)]):-1)
99
#define digitalPinToInterrupt(p) (((p)<40)?(p):-1)
1010
#define digitalPinHasPWM(p) (p < 34)
1111

variants/nano32/pins_arduino.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#define NUM_DIGITAL_PINS 38
66
#define NUM_ANALOG_INPUTS 16
77

8-
#define analogInputToDigitalPin(p)
8+
#define analogInputToDigitalPin(p) (((p)<20)?(esp32_adc2gpio[(p)]):-1)
99
#define digitalPinToInterrupt(p) (((p)<40)?(p):-1)
1010
#define digitalPinHasPWM(p) (p < 34)
1111

variants/node32s/pins_arduino.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#define NUM_DIGITAL_PINS 40
66
#define NUM_ANALOG_INPUTS 16
77

8-
#define analogInputToDigitalPin(p)
8+
#define analogInputToDigitalPin(p) (((p)<20)?(esp32_adc2gpio[(p)]):-1)
99
#define digitalPinToInterrupt(p) (((p)<40)?(p):-1)
1010
#define digitalPinHasPWM(p) (p < 34)
1111

variants/quantum/pins_arduino.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#define NUM_DIGITAL_PINS 40
66
#define NUM_ANALOG_INPUTS 16
77

8-
#define analogInputToDigitalPin(p)
8+
#define analogInputToDigitalPin(p) (((p)<20)?(esp32_adc2gpio[(p)]):-1)
99
#define digitalPinToInterrupt(p) (((p)<40)?(p):-1)
1010
#define digitalPinHasPWM(p) (p < 34)
1111

0 commit comments

Comments
 (0)