From 811031cbd69ed352b4f8d6f041dc8c5d7aea63d5 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Mon, 26 Jan 2015 02:08:26 +0300 Subject: [PATCH] Add functions for direct IO register access --- cores/esp8266/Arduino.h | 8 ++++--- cores/esp8266/core_esp8266_wiring_digital.c | 26 +++++++++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/cores/esp8266/Arduino.h b/cores/esp8266/Arduino.h index 0393ed9b4..afa27de10 100644 --- a/cores/esp8266/Arduino.h +++ b/cores/esp8266/Arduino.h @@ -137,10 +137,12 @@ void loop(void); // Get the bit location within the hardware port of the given virtual pin. // This comes from the pins_*.c file for the active board configuration. +uint32_t digitalPinToPort(uint32_t pin); +uint32_t digitalPinToBitMask(uint32_t pin); #define analogInPinToBit(P) (P) - -// On the ATmega1280, the addresses of some of the port registers are -// greater than 255, so we can't store them in uint8_t's. +volatile uint32_t* portOutputRegister(uint32_t port); +volatile uint32_t* portInputRegister(uint32_t port); +volatile uint32_t* portModeRegister(uint32_t port); #define NOT_A_PIN 0 diff --git a/cores/esp8266/core_esp8266_wiring_digital.c b/cores/esp8266/core_esp8266_wiring_digital.c index 9de02d96b..f3cac6cb4 100644 --- a/cores/esp8266/core_esp8266_wiring_digital.c +++ b/cores/esp8266/core_esp8266_wiring_digital.c @@ -67,6 +67,32 @@ static const uint32_t g_pin_funcs[PINCOUNT] = { }; +uint32_t digitalPinToPort(uint32_t pin) +{ + return 0; +} + +uint32_t digitalPinToBitMask(uint32_t pin) +{ + return 1 << pin; +} + +volatile uint32_t* portOutputRegister(uint32_t port) +{ + return (volatile uint32_t*) (PERIPHS_GPIO_BASEADDR + GPIO_OUT_ADDRESS); +} + +volatile uint32_t* portInputRegister(uint32_t port) +{ + return (volatile uint32_t*) (PERIPHS_GPIO_BASEADDR + GPIO_IN_ADDRESS); +} + +volatile uint32_t* portModeRegister(uint32_t port) +{ + return (volatile uint32_t*) (PERIPHS_GPIO_BASEADDR + GPIO_ENABLE_ADDRESS); +} + + enum PinFunction { GPIO, PWM }; static uint32_t g_gpio_function[PINCOUNT] = { GPIO