mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-22 21:23:07 +03:00
commit
f8895d1a61
14
README.md
14
README.md
@ -153,9 +153,7 @@ APIs related to deep sleep and watchdog timer are available in the ```ESP``` obj
|
|||||||
|
|
||||||
```ESP.deepSleep(microseconds, mode)``` will put the chip into deep sleep. ```mode``` is one of ```WAKE_RF_DEFAULT```, ```WAKE_RFCAL```, ```WAKE_NO_RFCAL```, ```WAKE_RF_DISABLED```. (GPIO16 needs to be tied to RST to wake from deepSleep.)
|
```ESP.deepSleep(microseconds, mode)``` will put the chip into deep sleep. ```mode``` is one of ```WAKE_RF_DEFAULT```, ```WAKE_RFCAL```, ```WAKE_NO_RFCAL```, ```WAKE_RF_DISABLED```. (GPIO16 needs to be tied to RST to wake from deepSleep.)
|
||||||
|
|
||||||
```ESP.wdtEnable()```, ```ESP.wdtDisable()```, and ```ESP.wdtFeed()``` provide some control over the watchdog timer.
|
```ESP.restart()``` restarts the CPU.
|
||||||
|
|
||||||
```ESP.reset()``` resets the CPU.
|
|
||||||
|
|
||||||
```ESP.getFreeHeap()``` returns the free heap size.
|
```ESP.getFreeHeap()``` returns the free heap size.
|
||||||
|
|
||||||
@ -171,6 +169,16 @@ Several APIs may be used to get flash chip info:
|
|||||||
|
|
||||||
```ESP.getCycleCount()``` returns the cpu instruction cycle count since start as an unsigned 32-bit. This is useful for accurate timing of very short actions like bit banging.
|
```ESP.getCycleCount()``` returns the cpu instruction cycle count since start as an unsigned 32-bit. This is useful for accurate timing of very short actions like bit banging.
|
||||||
|
|
||||||
|
```ESP.getVcc()``` may be used to measure supply voltage. ESP needs to reconfigure the ADC
|
||||||
|
at startup in order for this feature to be available. Add the following line to the top
|
||||||
|
of your sketch to use ```getVcc```:
|
||||||
|
```
|
||||||
|
ADC_MODE(ADC_VCC);
|
||||||
|
```
|
||||||
|
TOUT pin has to be disconnected in this mode.
|
||||||
|
|
||||||
|
Note that by default ADC is configured to read from TOUT pin using ```analogRead(A0)```, and
|
||||||
|
```ESP.getVCC()``` is not available.
|
||||||
|
|
||||||
#### OneWire (from https://www.pjrc.com/teensy/td_libs_OneWire.html) ####
|
#### OneWire (from https://www.pjrc.com/teensy/td_libs_OneWire.html) ####
|
||||||
|
|
||||||
|
@ -32,12 +32,6 @@ extern struct rst_info resetInfo;
|
|||||||
|
|
||||||
// #define DEBUG_SERIAL Serial
|
// #define DEBUG_SERIAL Serial
|
||||||
|
|
||||||
//extern "C" void ets_wdt_init(uint32_t val);
|
|
||||||
extern "C" void ets_wdt_enable(void);
|
|
||||||
extern "C" void ets_wdt_disable(void);
|
|
||||||
extern "C" void wdt_feed(void) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User-defined Literals
|
* User-defined Literals
|
||||||
@ -85,46 +79,42 @@ unsigned long long operator"" _GB(unsigned long long x) {
|
|||||||
|
|
||||||
EspClass ESP;
|
EspClass ESP;
|
||||||
|
|
||||||
EspClass::EspClass()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void EspClass::wdtEnable(uint32_t timeout_ms)
|
void EspClass::wdtEnable(uint32_t timeout_ms)
|
||||||
{
|
{
|
||||||
//todo find doku for ets_wdt_init may set the timeout
|
|
||||||
ets_wdt_enable();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EspClass::wdtEnable(WDTO_t timeout_ms)
|
void EspClass::wdtEnable(WDTO_t timeout_ms)
|
||||||
{
|
{
|
||||||
wdtEnable((uint32_t) timeout_ms);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EspClass::wdtDisable(void)
|
void EspClass::wdtDisable(void)
|
||||||
{
|
{
|
||||||
ets_wdt_disable();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EspClass::wdtFeed(void)
|
void EspClass::wdtFeed(void)
|
||||||
{
|
{
|
||||||
wdt_feed();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EspClass::deepSleep(uint32_t time_us, WakeMode mode)
|
void EspClass::deepSleep(uint32_t time_us, WakeMode mode)
|
||||||
{
|
{
|
||||||
system_deep_sleep_set_option(static_cast<int>(mode));
|
system_deep_sleep_set_option(static_cast<int>(mode));
|
||||||
system_deep_sleep(time_us);
|
system_deep_sleep(time_us);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern "C" void esp_yield();
|
||||||
|
extern "C" void __real_system_restart_local();
|
||||||
void EspClass::reset(void)
|
void EspClass::reset(void)
|
||||||
{
|
{
|
||||||
((void (*)(void))0x40000080)();
|
__real_system_restart_local();
|
||||||
}
|
}
|
||||||
|
|
||||||
void EspClass::restart(void)
|
void EspClass::restart(void)
|
||||||
{
|
{
|
||||||
system_restart();
|
system_restart();
|
||||||
|
esp_yield();
|
||||||
|
// todo: provide an alternative code path if this was called
|
||||||
|
// from system context, not from continuation
|
||||||
|
// (implement esp_is_cont_ctx()?)
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t EspClass::getVcc(void)
|
uint16_t EspClass::getVcc(void)
|
||||||
|
@ -61,6 +61,15 @@ enum RFMode {
|
|||||||
#define WAKE_NO_RFCAL RF_NO_CAL
|
#define WAKE_NO_RFCAL RF_NO_CAL
|
||||||
#define WAKE_RF_DISABLED RF_DISABLED
|
#define WAKE_RF_DISABLED RF_DISABLED
|
||||||
|
|
||||||
|
enum ADCMode {
|
||||||
|
ADC_TOUT = 33,
|
||||||
|
ADC_TOUT_3V3 = 33,
|
||||||
|
ADC_VCC = 255,
|
||||||
|
ADC_VDD = 255
|
||||||
|
};
|
||||||
|
|
||||||
|
#define ADC_MODE(mode) extern "C" int __get_adc_mode() { return (int) (mode); }
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
FM_QIO = 0x00,
|
FM_QIO = 0x00,
|
||||||
FM_QOUT = 0x01,
|
FM_QOUT = 0x01,
|
||||||
@ -71,8 +80,6 @@ typedef enum {
|
|||||||
|
|
||||||
class EspClass {
|
class EspClass {
|
||||||
public:
|
public:
|
||||||
EspClass();
|
|
||||||
|
|
||||||
// TODO: figure out how to set WDT timeout
|
// TODO: figure out how to set WDT timeout
|
||||||
void wdtEnable(uint32_t timeout_ms = 0);
|
void wdtEnable(uint32_t timeout_ms = 0);
|
||||||
// note: setting the timeout value is not implemented at the moment
|
// note: setting the timeout value is not implemented at the moment
|
||||||
|
@ -224,6 +224,7 @@ static uint8_t phy_init_data[128] =
|
|||||||
|
|
||||||
extern int __real_register_chipv6_phy(uint8_t* init_data);
|
extern int __real_register_chipv6_phy(uint8_t* init_data);
|
||||||
extern int __wrap_register_chipv6_phy(uint8_t* unused) {
|
extern int __wrap_register_chipv6_phy(uint8_t* unused) {
|
||||||
|
phy_init_data[107] = __get_adc_mode();
|
||||||
return __real_register_chipv6_phy(phy_init_data);
|
return __real_register_chipv6_phy(phy_init_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -243,6 +244,10 @@ extern int __get_rf_mode()
|
|||||||
return 0; // default mode
|
return 0; // default mode
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern int __get_adc_mode() __attribute__((weak));
|
||||||
|
extern int __get_adc_mode()
|
||||||
|
{
|
||||||
|
return 33; // default ADC mode
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -17,17 +17,18 @@
|
|||||||
You should have received a copy of the GNU Lesser General Public
|
You should have received a copy of the GNU Lesser General Public
|
||||||
License along with this library; if not, write to the Free Software
|
License along with this library; if not, write to the Free Software
|
||||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
|
|
||||||
|
18/06/2015 analogRead bugfix by Testato
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "wiring_private.h"
|
#include "wiring_private.h"
|
||||||
#include "pins_arduino.h"
|
#include "pins_arduino.h"
|
||||||
|
|
||||||
extern uint16_t readvdd33(void);
|
|
||||||
|
|
||||||
void analogReference(uint8_t mode) {}
|
|
||||||
|
|
||||||
extern int __analogRead(uint8_t pin) {
|
extern int __analogRead(uint8_t pin) {
|
||||||
if(pin == 17){
|
if(pin == 17){
|
||||||
return readvdd33() >> 2; // readvdd33 is 12 bit
|
return system_adc_read();
|
||||||
}
|
}
|
||||||
return digitalRead(pin) * 1023;
|
return digitalRead(pin) * 1023;
|
||||||
}
|
}
|
||||||
|
@ -115,7 +115,7 @@ void ESP8266WebServer::handleClient()
|
|||||||
_handleRequest();
|
_handleRequest();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ESP8266WebServer::sendHeader(String name, String value, bool first) {
|
void ESP8266WebServer::sendHeader(const String& name, const String& value, bool first) {
|
||||||
String headerLine = name;
|
String headerLine = name;
|
||||||
headerLine += ": ";
|
headerLine += ": ";
|
||||||
headerLine += value;
|
headerLine += value;
|
||||||
@ -129,7 +129,7 @@ void ESP8266WebServer::sendHeader(String name, String value, bool first) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ESP8266WebServer::send(int code, const char* content_type, String content) {
|
void ESP8266WebServer::send(int code, const char* content_type, const String& content) {
|
||||||
String response = "HTTP/1.1 ";
|
String response = "HTTP/1.1 ";
|
||||||
response += String(code);
|
response += String(code);
|
||||||
response += " ";
|
response += " ";
|
||||||
@ -155,15 +155,15 @@ void ESP8266WebServer::send(int code, const char* content_type, String content)
|
|||||||
sendContent(response);
|
sendContent(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ESP8266WebServer::send(int code, char* content_type, String content) {
|
void ESP8266WebServer::send(int code, char* content_type, const String& content) {
|
||||||
send(code, (const char*)content_type, content);
|
send(code, (const char*)content_type, content);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ESP8266WebServer::send(int code, String content_type, String content) {
|
void ESP8266WebServer::send(int code, const String& content_type, const String& content) {
|
||||||
send(code, (const char*)content_type.c_str(), content);
|
send(code, (const char*)content_type.c_str(), content);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ESP8266WebServer::sendContent(String content) {
|
void ESP8266WebServer::sendContent(const String& content) {
|
||||||
size_t size_to_send = content.length();
|
size_t size_to_send = content.length();
|
||||||
size_t size_sent = 0;
|
size_t size_sent = 0;
|
||||||
while(size_to_send) {
|
while(size_to_send) {
|
||||||
|
@ -77,15 +77,15 @@ public:
|
|||||||
// code - HTTP response code, can be 200 or 404
|
// code - HTTP response code, can be 200 or 404
|
||||||
// content_type - HTTP content type, like "text/plain" or "image/png"
|
// content_type - HTTP content type, like "text/plain" or "image/png"
|
||||||
// content - actual content body
|
// content - actual content body
|
||||||
void send(int code, const char* content_type = NULL, String content = String(""));
|
void send(int code, const char* content_type = NULL, const String& content = String(""));
|
||||||
void send(int code, char* content_type, String content);
|
void send(int code, char* content_type, const String& content);
|
||||||
void send(int code, String content_type, String content);
|
void send(int code, const String& content_type, const String& content);
|
||||||
|
|
||||||
void setContentLength(size_t contentLength) { _contentLength = contentLength; }
|
void setContentLength(size_t contentLength) { _contentLength = contentLength; }
|
||||||
void sendHeader(String name, String value, bool first = false);
|
void sendHeader(const String& name, const String& value, bool first = false);
|
||||||
void sendContent(String content);
|
void sendContent(const String& content);
|
||||||
|
|
||||||
template<typename T> size_t streamFile(T &file, String contentType){
|
template<typename T> size_t streamFile(T &file, const String& contentType){
|
||||||
setContentLength(file.size());
|
setContentLength(file.size());
|
||||||
if (String(file.name()).endsWith(".gz") &&
|
if (String(file.name()).endsWith(".gz") &&
|
||||||
contentType != "application/x-gzip" &&
|
contentType != "application/x-gzip" &&
|
||||||
|
@ -9,14 +9,12 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
|
|
||||||
static void _add(T* self) {
|
static void _add(T* self) {
|
||||||
DEBUGV("%s %08x %08x\n", __func__, (uint32_t) self, (uint32_t) _s_first);
|
|
||||||
T* tmp = _s_first;
|
T* tmp = _s_first;
|
||||||
_s_first = self;
|
_s_first = self;
|
||||||
self->_next = tmp;
|
self->_next = tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _remove(T* self) {
|
static void _remove(T* self) {
|
||||||
DEBUGV("%s %08x %08x\n", __func__, (uint32_t) self, (uint32_t) _s_first);
|
|
||||||
if (_s_first == self) {
|
if (_s_first == self) {
|
||||||
_s_first = self->_next;
|
_s_first = self->_next;
|
||||||
self->_next = 0;
|
self->_next = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user