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

Merge remote-tracking branch 'remotes/esp8266/esp8266' into esp8266

This commit is contained in:
Markus Sattler 2015-04-11 10:16:19 +02:00
commit 56641b462f
9 changed files with 147 additions and 35 deletions

View File

@ -108,6 +108,14 @@ Before using I2C, pins for SDA and SCL need to be set by calling
An initial SPI support for the HSPI interface (GPIO12-15) was implemented by [Sermus](https://github.com/Sermus).
The implementation supports the entire Arduino SPI API including transactions, except setting phase and polarity as it's unclear how to set them in ESP8266 yet.
#### ESP-specific APIs ####
APIs related to deep sleep and watchdog timer are available in the ```ESP``` object.
```ESP.deepSleep(microseconds, mode)``` will put the chip into deep sleep. ```mode``` is one of ```WAKE_DEFAULT```, ```WAKE_RFCAL```, ```WAKE_NO_RFCAL```, ```WAKE_RF_DISABLED```.
```ESP.wdtEnable()```, ```ESP.wdtDisable()```, and ```ESP.wdtFeed()``` provide some control over the watchdog timer.
#### OneWire (from https://www.pjrc.com/teensy/td_libs_OneWire.html) ####
Library was adapted to work with ESP8266 by including register definitions into OneWire.h

View File

@ -158,6 +158,7 @@ volatile uint32_t* portModeRegister(uint32_t port);
#include "WString.h"
#include "HardwareSerial.h"
#include "Esp.h"
uint16_t makeWord(uint16_t w);
uint16_t makeWord(byte h, byte l);

57
cores/esp8266/Esp.cpp Normal file
View File

@ -0,0 +1,57 @@
/*
Esp.cpp - ESP8266-specific APIs
Copyright (c) 2015 Ivan Grokhotkov. All rights reserved.
This file is part of the esp8266 core for Arduino environment.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
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 "Arduino.h"
extern "C" {
#include "user_interface.h"
}
extern "C" void ets_wdt_enable (void);
extern "C" void ets_wdt_disable (void);
extern "C" void wdt_feed (void);
EspClass ESP;
EspClass::EspClass()
{
}
void EspClass::wdtEnable(int)
{
ets_wdt_enable();
}
void EspClass::wdtDisable()
{
ets_wdt_disable();
}
void EspClass::wdtFeed()
{
wdt_feed();
}
void EspClass::deepSleep(uint32_t time_us, WakeMode mode)
{
system_deep_sleep_set_option(static_cast<int>(mode));
system_deep_sleep(time_us);
}

46
cores/esp8266/Esp.h Normal file
View File

@ -0,0 +1,46 @@
/*
Esp.h - ESP8266-specific APIs
Copyright (c) 2015 Ivan Grokhotkov. All rights reserved.
This file is part of the esp8266 core for Arduino environment.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef ESP_H
#define ESP_H
enum WakeMode {
WAKE_RF_DEFAULT = 0, // RF_CAL or not after deep-sleep wake up, depends on init data byte 108.
WAKE_RFCAL = 1, // RF_CAL after deep-sleep wake up, there will be large current.
WAKE_NO_RFCAL = 2, // no RF_CAL after deep-sleep wake up, there will only be small current.
WAKE_RF_DISABLED = 4 // disable RF after deep-sleep wake up, just like modem sleep, there will be the smallest current.
};
class EspClass {
public:
EspClass();
void wdtEnable(int timeout_ms = 0);
// TODO: figure out how to set WDT timeout
void wdtDisable();
void wdtFeed();
void deepSleep(uint32_t time_us, WakeMode mode = WAKE_RF_DEFAULT);
};
extern EspClass ESP;
#endif //ESP_H

View File

@ -66,13 +66,13 @@ static inline void i2c_wait() {
delayMicroseconds(s_i2c_delay);
}
void i2c_freq(int freq_hz) {
void ICACHE_FLASH_ATTR i2c_freq(int freq_hz) {
s_i2c_delay = 1000000 / freq_hz / 4 - 1;
if(s_i2c_delay < 0)
s_i2c_delay = 0;
}
void i2c_init(int sda_pin, int scl_pin) {
void ICACHE_FLASH_ATTR i2c_init(int sda_pin, int scl_pin) {
s_sda_pin = sda_pin;
s_scl_pin = scl_pin;
pinMode(ESP_PINS_OFFSET + sda_pin, OUTPUT_OPEN_DRAIN);
@ -81,7 +81,7 @@ void i2c_init(int sda_pin, int scl_pin) {
i2c_wait();
}
void i2c_release() {
void ICACHE_FLASH_ATTR i2c_release() {
pinMode(ESP_PINS_OFFSET + s_sda_pin, INPUT);
pinMode(ESP_PINS_OFFSET + s_scl_pin, INPUT);
}
@ -151,7 +151,7 @@ void i2c_write(uint8_t val) {
i2c_set_sda(1);
}
size_t i2c_master_read_from(int address, uint8_t* data, size_t size, bool sendStop) {
size_t ICACHE_FLASH_ATTR i2c_master_read_from(int address, uint8_t* data, size_t size, bool sendStop) {
i2c_start();
i2c_write(address << 1 | 1);
int ack = i2c_get_ack();
@ -171,7 +171,7 @@ size_t i2c_master_read_from(int address, uint8_t* data, size_t size, bool sendSt
return size;
}
size_t i2c_master_write_to(int address, const uint8_t* data, size_t size, bool sendStop) {
size_t ICACHE_FLASH_ATTR i2c_master_write_to(int address, const uint8_t* data, size_t size, bool sendStop) {
i2c_start();
i2c_write(address << 1);
int ack = i2c_get_ack();
@ -193,11 +193,11 @@ void twi_init(void) {
void twi_setAddress(uint8_t) {
}
uint8_t twi_readFrom(uint8_t addr, uint8_t* data, uint8_t size, uint8_t sendStop) {
uint8_t ICACHE_FLASH_ATTR twi_readFrom(uint8_t addr, uint8_t* data, uint8_t size, uint8_t sendStop) {
return i2c_master_read_from(addr, data, size, sendStop);
}
uint8_t twi_writeTo(uint8_t addr, uint8_t* data, uint8_t size, uint8_t wait, uint8_t sendStop) {
uint8_t ICACHE_FLASH_ATTR twi_writeTo(uint8_t addr, uint8_t* data, uint8_t size, uint8_t wait, uint8_t sendStop) {
return i2c_master_write_to(addr, data, size, sendStop);
}

View File

@ -111,15 +111,15 @@ int strncmp(const char *s1, const char *s2, size_t len) {
return ets_strncmp(s1, s2, len);
}
char *strncpy(char * dest, const char * src, size_t n) {
char* strncpy(char * dest, const char * src, size_t n) {
return ets_strncpy(dest, src, n);
}
char *ets_strstr(const char *haystack, const char *needle) {
return strstr(haystack, needle);
char* strstr(const char *haystack, const char *needle) {
return ets_strstr(haystack, needle);
}
char * strchr(const char * str, int character) {
char* strchr(const char * str, int character) {
while(1) {
if(*str == 0x00) {
return NULL;
@ -144,11 +144,11 @@ char * strrchr(const char * str, int character) {
}
}
char * strcat(char * dest, const char * src) {
char* ICACHE_FLASH_ATTR strcat(char * dest, const char * src) {
return strncat(dest, src, strlen(src));
}
char * strncat(char * dest, const char * src, size_t n) {
char* ICACHE_FLASH_ATTR strncat(char * dest, const char * src, size_t n) {
uint32_t offset = strlen(dest);
for(uint32_t i = 0; i < n; i++) {
*(dest + i + offset) = *(src + i);
@ -159,7 +159,7 @@ char * strncat(char * dest, const char * src, size_t n) {
return dest;
}
char * strtok_r(char * str, const char * delimiters, char ** temp) {
char* ICACHE_FLASH_ATTR strtok_r(char * str, const char * delimiters, char ** temp) {
static char * ret = NULL;
char * start = NULL;
char * end = NULL;
@ -213,7 +213,7 @@ int strcasecmp(const char * str1, const char * str2) {
return d;
}
char * strdup(const char *str) {
char* ICACHE_FLASH_ATTR strdup(const char *str) {
size_t len = strlen(str) + 1;
char *cstr = malloc(len);
if(cstr) {
@ -441,7 +441,7 @@ int isblank(int c) {
static int errno_var = 0;
int * __errno(void) {
int* ICACHE_FLASH_ATTR __errno(void) {
os_printf("__errno is called last error: %d (not current)\n", errno_var);
return &errno_var;
}
@ -450,67 +450,67 @@ int * __errno(void) {
// __ieee754 functions
// ##########################################################################
double __ieee754_sinh(double x) {
double ICACHE_FLASH_ATTR __ieee754_sinh(double x) {
return sinh(x);
}
double __ieee754_hypot(double x, double y) {
double ICACHE_FLASH_ATTR __ieee754_hypot(double x, double y) {
return hypot(x, y);
}
float __ieee754_hypotf(float x, float y) {
float ICACHE_FLASH_ATTR __ieee754_hypotf(float x, float y) {
return hypotf(x, y);
}
float __ieee754_logf(float x) {
float ICACHE_FLASH_ATTR __ieee754_logf(float x) {
return logf(x);
}
double __ieee754_log10(double x) {
double ICACHE_FLASH_ATTR __ieee754_log10(double x) {
return log10(x);
}
double __ieee754_exp(double x) {
double ICACHE_FLASH_ATTR __ieee754_exp(double x) {
return exp(x);
}
double __ieee754_cosh(double x) {
double ICACHE_FLASH_ATTR __ieee754_cosh(double x) {
return cosh(x);
}
float __ieee754_expf(float x) {
float ICACHE_FLASH_ATTR __ieee754_expf(float x) {
return expf(x);
}
float __ieee754_log10f(float x) {
float ICACHE_FLASH_ATTR __ieee754_log10f(float x) {
return log10f(x);
}
double __ieee754_atan2(double x, double y) {
double ICACHE_FLASH_ATTR __ieee754_atan2(double x, double y) {
return atan2(x, y);
}
float __ieee754_sqrtf(float x) {
float ICACHE_FLASH_ATTR __ieee754_sqrtf(float x) {
return sqrtf(x);
}
float __ieee754_sinhf(float x) {
float ICACHE_FLASH_ATTR __ieee754_sinhf(float x) {
return sinhf(x);
}
double __ieee754_log(double x) {
double ICACHE_FLASH_ATTR __ieee754_log(double x) {
return log(x);
}
double __ieee754_sqrt(double x) {
double ICACHE_FLASH_ATTR __ieee754_sqrt(double x) {
return sqrt(x);
}
float __ieee754_coshf(float x) {
float ICACHE_FLASH_ATTR __ieee754_coshf(float x) {
return coshf(x);
}
float __ieee754_atan2f(float x, float y) {
float ICACHE_FLASH_ATTR __ieee754_atan2f(float x, float y) {
return atan2f(x, y);
}

View File

@ -5,7 +5,7 @@ extern "C"{
#include <ets_sys.h>
#include <os_type.h>
#include <osapi.h>
#include "driver\hspi.h"
#include "driver/hspi.h"
}
#define SWAPBYTES(i) ((i>>8) | (i<<8))

View File

@ -8,7 +8,7 @@ extern "C"
#include <c_types.h>
#include <osapi.h>
#include <gpio.h>
#include "driver\hspi.h"
#include "driver/hspi.h"
}
#define ILI9341_TFTWIDTH 240

View File

@ -1,4 +1,4 @@
#include "driver\hspi.h"
#include "driver/hspi.h"
/*
Pinout: