1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-17 22:23:10 +03:00

Define wiring functions as weak

This way they can be redefined in board variants, allowing for port expansion
This commit is contained in:
Ivan Grokhotkov
2015-01-16 22:46:43 +03:00
parent d3e4d6d9e3
commit 22b3aebdcd
3 changed files with 20 additions and 13 deletions

View File

@ -27,7 +27,7 @@ void analogReference(uint8_t mode)
{ {
} }
int analogRead(uint8_t pin) extern int __analogRead(uint8_t pin)
{ {
if (pin == 0) if (pin == 0)
return system_adc_read(); return system_adc_read();
@ -36,3 +36,4 @@ int analogRead(uint8_t pin)
} }
extern int analogRead(uint8_t pin) __attribute__ ((weak, alias("__analogRead")));

View File

@ -72,8 +72,7 @@ static uint32_t g_gpio_function[PINCOUNT] = {
GPIO GPIO
}; };
extern void __pinMode(uint8_t pin, uint8_t mode)
void pinMode(uint8_t pin, uint8_t mode)
{ {
if (pin == 16) if (pin == 16)
{ {
@ -112,7 +111,7 @@ void pinMode(uint8_t pin, uint8_t mode)
} }
} }
void digitalWrite(uint8_t pin, uint8_t val) extern void __digitalWrite(uint8_t pin, uint8_t val)
{ {
if (pin == 16) if (pin == 16)
{ {
@ -127,7 +126,7 @@ void digitalWrite(uint8_t pin, uint8_t val)
GPIO_REG_WRITE(GPIO_OUT_W1TC_ADDRESS, mask); GPIO_REG_WRITE(GPIO_OUT_W1TC_ADDRESS, mask);
} }
int digitalRead(uint8_t pin) extern int __digitalRead(uint8_t pin)
{ {
if (pin == 16) if (pin == 16)
return (READ_PERI_REG(RTC_GPIO_IN_DATA) & 1); return (READ_PERI_REG(RTC_GPIO_IN_DATA) & 1);
@ -135,12 +134,12 @@ int digitalRead(uint8_t pin)
return ((gpio_input_get() >> pin) & 1); return ((gpio_input_get() >> pin) & 1);
} }
void analogWrite(uint8_t pin, int val) extern void __analogWrite(uint8_t pin, int val)
{ {
} }
typedef void (*inthandler_t)(void); typedef void (*voidFuncPtr)(void);
static inthandler_t g_handlers[PINCOUNT] = { 0 }; static voidFuncPtr g_handlers[PINCOUNT] = { 0 };
void interrupt_handler(void *arg) void interrupt_handler(void *arg)
@ -156,7 +155,7 @@ void interrupt_handler(void *arg)
} }
} }
void attachInterrupt(uint8_t pin, inthandler_t handler, int mode) extern void __attachInterrupt(uint8_t pin, voidFuncPtr handler, int mode)
{ {
if (pin < 0 || pin > PINCOUNT) if (pin < 0 || pin > PINCOUNT)
return; return;
@ -181,13 +180,13 @@ void attachInterrupt(uint8_t pin, inthandler_t handler, int mode)
} }
} }
void detachInterrupt(uint8_t pin) extern void __detachInterrupt(uint8_t pin)
{ {
g_handlers[pin] = 0; g_handlers[pin] = 0;
gpio_pin_intr_state_set(pin, GPIO_PIN_INTR_DISABLE); gpio_pin_intr_state_set(pin, GPIO_PIN_INTR_DISABLE);
} }
void initPins() extern void __initPins()
{ {
gpio_init(); gpio_init();
for (int i = 0; i < PINCOUNT; ++i) for (int i = 0; i < PINCOUNT; ++i)
@ -202,4 +201,11 @@ void initPins()
ETS_GPIO_INTR_ATTACH(&interrupt_handler, NULL); ETS_GPIO_INTR_ATTACH(&interrupt_handler, NULL);
} }
extern void pinMode(uint8_t pin, uint8_t mode) __attribute__ ((weak, alias("__pinMode")));
extern void digitalWrite(uint8_t pin, uint8_t val) __attribute__ ((weak, alias("__digitalWrite")));
extern int digitalRead(uint8_t pin) __attribute__ ((weak, alias("__digitalRead")));
extern void analogWrite(uint8_t pin, int val) __attribute__ ((weak, alias("__analogWrite")));
extern void attachInterrupt(uint8_t pin, voidFuncPtr handler, int mode) __attribute__ ((weak, alias("__attachInterrupt")));
extern void detachInterrupt(uint8_t pin) __attribute__ ((weak, alias("__detachInterrupt")));
extern void initPins() __attribute__ ((weak, alias("__initPins")));

View File

@ -25,8 +25,6 @@
#ifndef Pins_Arduino_h #ifndef Pins_Arduino_h
#define Pins_Arduino_h #define Pins_Arduino_h
#define PROGMEM
#define NUM_DIGITAL_PINS 16 #define NUM_DIGITAL_PINS 16
#define NUM_ANALOG_INPUTS 1 #define NUM_ANALOG_INPUTS 1
@ -38,7 +36,9 @@ static const uint8_t MOSI = 13;
static const uint8_t MISO = 14; static const uint8_t MISO = 14;
static const uint8_t SCK = 15; static const uint8_t SCK = 15;
static const uint8_t BUILTIN_LED = 1;
static const uint8_t A0 = 0;
// These serial port names are intended to allow libraries and architecture-neutral // These serial port names are intended to allow libraries and architecture-neutral
// sketches to automatically default to the correct port name for a particular type // sketches to automatically default to the correct port name for a particular type