1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-21 10:26:06 +03:00

Implement digital IO functions

This commit is contained in:
Ivan Grokhotkov 2014-11-21 21:23:27 +03:00
parent e21371d6d0
commit 66cac95b4b
4 changed files with 83 additions and 40 deletions

View File

@ -67,5 +67,5 @@ void delayMicroseconds(unsigned int us)
void init()
{
// system_timer_reinit();
initPins();
}

View File

@ -27,19 +27,90 @@
#define ARDUINO_MAIN
#include "wiring_private.h"
#include "pins_arduino.h"
#include "eagle_soc.h"
#include "gpio.h"
#define PINCOUNT 16
static const uint32_t g_pin_muxes[PINCOUNT] = {
[0] = PERIPHS_IO_MUX_GPIO0_U,
[1] = PERIPHS_IO_MUX_U0TXD_U,
[2] = PERIPHS_IO_MUX_GPIO2_U,
[3] = PERIPHS_IO_MUX_U0RXD_U,
[4] = PERIPHS_IO_MUX_GPIO4_U,
[5] = PERIPHS_IO_MUX_GPIO5_U,
// These 6 pins are used for SPI flash interface
[6] = 0,
[7] = 0,
[8] = 0,
[9] = 0,
[10] = 0,
[11] = 0,
[12] = PERIPHS_IO_MUX_MTDI_U,
[13] = PERIPHS_IO_MUX_MTCK_U,
[14] = PERIPHS_IO_MUX_MTMS_U,
[15] = PERIPHS_IO_MUX_MTDO_U,
};
static const uint32_t g_pin_funcs[PINCOUNT] = {
[0] = FUNC_GPIO0,
[1] = FUNC_GPIO1,
[2] = FUNC_GPIO2,
[3] = FUNC_GPIO3,
[4] = FUNC_GPIO4,
[5] = FUNC_GPIO5,
[12] = FUNC_GPIO12,
[13] = FUNC_GPIO13,
[14] = FUNC_GPIO14,
[15] = FUNC_GPIO15,
};
void pinMode(uint8_t pin, uint8_t mode)
{
uint32_t mux = g_pin_muxes[pin];
if (mode == INPUT)
{
gpio_output_set(0, 0, 0, 1 << pin);
PIN_PULLUP_DIS(mux);
}
else if (mode == INPUT_PULLUP)
{
gpio_output_set(0, 0, 0, 1 << pin);
PIN_PULLUP_EN(mux);
}
else
{
gpio_output_set(0, 0, 1 << pin, 0);
}
}
void digitalWrite(uint8_t pin, uint8_t val)
{
uint32_t set = ((val & 1) << pin);
uint32_t clr = (((~val) & 1) << pin);
gpio_output_set(set, clr, 0, 0);
}
int digitalRead(uint8_t pin)
{
return LOW;
return ((gpio_input_get() >> pin) & 1);
}
void initPins()
{
gpio_init();
for (int i = 0; i < PINCOUNT; ++i)
{
uint32_t mux = g_pin_muxes[i];
if (mux)
{
uint32_t func = g_pin_funcs[i];
PIN_FUNC_SELECT(mux, func);
}
}
}

View File

@ -34,13 +34,6 @@
extern "C"{
#endif
#ifndef cbi
#define cbi(sfr, bit)
#endif
#ifndef sbi
#define sbi(sfr, bit)
#endif
#define EXTERNAL_INT_0 0
#define EXTERNAL_INT_1 1
#define EXTERNAL_INT_2 2
@ -54,6 +47,8 @@ extern "C"{
typedef void (*voidFuncPtr)(void);
void initPins();
#ifdef __cplusplus
} // extern "C"
#endif

View File

@ -27,40 +27,17 @@
#define PROGMEM
#define NUM_DIGITAL_PINS 30
#define NUM_ANALOG_INPUTS 12
#define NUM_DIGITAL_PINS 16
#define NUM_ANALOG_INPUTS 1
#define TX_RX_LED_INIT
#define TXLED0
#define TXLED1
#define RXLED0
#define RXLED1
static const uint8_t SDA = 0;
static const uint8_t SCL = 2;
static const uint8_t SDA = 2;
static const uint8_t SCL = 3;
#define LED_BUILTIN 13
// Map SPI port to 'new' pins D14..D17
static const uint8_t SS = 17;
static const uint8_t MOSI = 16;
static const uint8_t SS = 12;
static const uint8_t MOSI = 13;
static const uint8_t MISO = 14;
static const uint8_t SCK = 15;
// Mapping of analog pins as digital I/O
// A6-A11 share with digital pins
static const uint8_t A0 = 18;
static const uint8_t A1 = 19;
static const uint8_t A2 = 20;
static const uint8_t A3 = 21;
static const uint8_t A4 = 22;
static const uint8_t A5 = 23;
static const uint8_t A6 = 24; // D4
static const uint8_t A7 = 25; // D6
static const uint8_t A8 = 26; // D8
static const uint8_t A9 = 27; // D9
static const uint8_t A10 = 28; // D10
static const uint8_t A11 = 29; // D12
// These serial port names are intended to allow libraries and architecture-neutral