From 3d0dafcbc0066b71b8e601d69e8feeccec5780c5 Mon Sep 17 00:00:00 2001 From: ficeto Date: Sun, 3 May 2015 17:51:06 +0300 Subject: [PATCH] fix UART RX PullUps and TWI --- cores/esp8266/Arduino.h | 2 +- cores/esp8266/{si2c.c => core_esp8266_si2c.c} | 40 +++++++++---------- cores/esp8266/core_esp8266_wiring_digital.c | 2 + cores/esp8266/{si2c.h => twi.h} | 18 ++++++--- 4 files changed, 36 insertions(+), 26 deletions(-) rename cores/esp8266/{si2c.c => core_esp8266_si2c.c} (84%) rename cores/esp8266/{si2c.h => twi.h} (69%) diff --git a/cores/esp8266/Arduino.h b/cores/esp8266/Arduino.h index dc2e95100..e3d8a718d 100644 --- a/cores/esp8266/Arduino.h +++ b/cores/esp8266/Arduino.h @@ -37,7 +37,7 @@ extern "C" { #include "binary.h" #include "pgmspace.h" #include "esp8266_peri.h" -#include "si2c.h" +#include "twi.h" void yield(void); diff --git a/cores/esp8266/si2c.c b/cores/esp8266/core_esp8266_si2c.c similarity index 84% rename from cores/esp8266/si2c.c rename to cores/esp8266/core_esp8266_si2c.c index f9bdda52c..36c3db510 100644 --- a/cores/esp8266/si2c.c +++ b/cores/esp8266/core_esp8266_si2c.c @@ -18,12 +18,12 @@ License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "si2c.h" +#include "twi.h" #include "pins_arduino.h" #include "wiring_private.h" -uint8_t twi_dcount = 18; -static uint8_t twi_sda, twi_scl; +unsigned char twi_dcount = 18; +static unsigned char twi_sda, twi_scl; #define SDA_LOW() (GPES = (1 << twi_sda)) //Enable SDA (becomes output and since GPO is 0 for the pin, it will pull the line low) #define SDA_HIGH() (GPEC = (1 << twi_sda)) //Disable SDA (becomes input and since it has pullup it will go high) @@ -42,7 +42,7 @@ static uint8_t twi_sda, twi_scl; #define TWI_CLOCK_STRETCH 400 #endif -void twi_setClock(uint32_t freq){ +void twi_setClock(unsigned int freq){ #if F_CPU == FCPU80 if(freq <= 100000) twi_dcount = 18;//about 100KHz else if(freq <= 200000) twi_dcount = 8;//about 200KHz @@ -58,7 +58,7 @@ void twi_setClock(uint32_t freq){ #endif } -void twi_init(uint8_t sda, uint8_t scl){ +void twi_init(unsigned char sda, unsigned char scl){ twi_sda = sda; twi_scl = scl; pinMode(twi_sda, INPUT_PULLUP); @@ -71,9 +71,9 @@ void twi_stop(void){ pinMode(twi_scl, INPUT); } -static void twi_delay(uint8_t v){ - uint8_t i; - uint32_t reg; +static void twi_delay(unsigned char v){ + unsigned char i; + unsigned int reg; for(i=0;i> 4) & 0x07); + if(pin == 13 && mode == FUNCTION_4) GPF(pin) |= (1 << GPFPU);//enable pullup on RX } else if(mode == OUTPUT){ GPF(pin) = GPFFS(GPFFS_GPIO(pin));//Set mode to GPIO GPC(pin) = (GPC(pin) & (0xF << GPCI)); //SOURCE(GPIO) | DRIVER(NORMAL) | INT_TYPE(UNCHANGED) | WAKEUP_ENABLE(DISABLED) diff --git a/cores/esp8266/si2c.h b/cores/esp8266/twi.h similarity index 69% rename from cores/esp8266/si2c.h rename to cores/esp8266/twi.h index e237233de..9e661e88e 100644 --- a/cores/esp8266/si2c.h +++ b/cores/esp8266/twi.h @@ -1,5 +1,5 @@ /* - si2c.h - Software I2C library for esp8266 + twi.h - Software I2C library for esp8266 Copyright (c) 2015 Hristo Gochkov. All rights reserved. This file is part of the esp8266 core for Arduino environment. @@ -22,10 +22,18 @@ #define SI2C_h #include "Arduino.h" -void twi_init(uint8_t sda, uint8_t scl); +#ifdef __cplusplus +extern "C" { +#endif + +void twi_init(unsigned char sda, unsigned char scl); void twi_stop(void); -void twi_setClock(uint32_t freq); -uint8_t twi_writeTo(uint8_t address, uint8_t * buf, uint32_t len, uint8_t sendStop); -uint8_t twi_readFrom(uint8_t address, uint8_t * buf, uint32_t len, uint8_t sendStop); +void twi_setClock(unsigned int freq); +uint8_t twi_writeTo(unsigned char address, unsigned char * buf, unsigned int len, unsigned char sendStop); +uint8_t twi_readFrom(unsigned char address, unsigned char * buf, unsigned int len, unsigned char sendStop); + +#ifdef __cplusplus +} +#endif #endif \ No newline at end of file