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

Merge pull request #10 from esp8266/esp8266

Esp8266
This commit is contained in:
Me No Dev 2015-06-26 12:16:06 +03:00
commit f8895d1a61
8 changed files with 51 additions and 42 deletions

View File

@ -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.wdtEnable()```, ```ESP.wdtDisable()```, and ```ESP.wdtFeed()``` provide some control over the watchdog timer.
```ESP.reset()``` resets the CPU.
```ESP.restart()``` restarts the CPU.
```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.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) ####

View File

@ -32,12 +32,6 @@ extern struct rst_info resetInfo;
// #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
@ -85,30 +79,20 @@ unsigned long long operator"" _GB(unsigned long long x) {
EspClass ESP;
EspClass::EspClass()
{
}
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)
{
wdtEnable((uint32_t) timeout_ms);
}
void EspClass::wdtDisable(void)
{
ets_wdt_disable();
}
void EspClass::wdtFeed(void)
{
wdt_feed();
}
void EspClass::deepSleep(uint32_t time_us, WakeMode mode)
@ -117,14 +101,20 @@ void EspClass::deepSleep(uint32_t time_us, WakeMode mode)
system_deep_sleep(time_us);
}
extern "C" void esp_yield();
extern "C" void __real_system_restart_local();
void EspClass::reset(void)
{
((void (*)(void))0x40000080)();
__real_system_restart_local();
}
void EspClass::restart(void)
{
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)

View File

@ -61,6 +61,15 @@ enum RFMode {
#define WAKE_NO_RFCAL RF_NO_CAL
#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 {
FM_QIO = 0x00,
FM_QOUT = 0x01,
@ -71,8 +80,6 @@ typedef enum {
class EspClass {
public:
EspClass();
// TODO: figure out how to set WDT timeout
void wdtEnable(uint32_t timeout_ms = 0);
// note: setting the timeout value is not implemented at the moment

View File

@ -224,6 +224,7 @@ static uint8_t phy_init_data[128] =
extern int __real_register_chipv6_phy(uint8_t* init_data);
extern int __wrap_register_chipv6_phy(uint8_t* unused) {
phy_init_data[107] = __get_adc_mode();
return __real_register_chipv6_phy(phy_init_data);
}
@ -243,6 +244,10 @@ extern int __get_rf_mode()
return 0; // default mode
}
extern int __get_adc_mode() __attribute__((weak));
extern int __get_adc_mode()
{
return 33; // default ADC mode
}

View File

@ -17,17 +17,18 @@
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
18/06/2015 analogRead bugfix by Testato
*/
#include "wiring_private.h"
#include "pins_arduino.h"
extern uint16_t readvdd33(void);
void analogReference(uint8_t mode) {}
extern int __analogRead(uint8_t pin) {
if(pin == 17){
return readvdd33() >> 2; // readvdd33 is 12 bit
return system_adc_read();
}
return digitalRead(pin) * 1023;
}

View File

@ -115,7 +115,7 @@ void ESP8266WebServer::handleClient()
_handleRequest();
}
void ESP8266WebServer::sendHeader(String name, String value, bool first) {
void ESP8266WebServer::sendHeader(const String& name, const String& value, bool first) {
String headerLine = name;
headerLine += ": ";
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 ";
response += String(code);
response += " ";
@ -155,15 +155,15 @@ void ESP8266WebServer::send(int code, const char* content_type, String content)
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);
}
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);
}
void ESP8266WebServer::sendContent(String content) {
void ESP8266WebServer::sendContent(const String& content) {
size_t size_to_send = content.length();
size_t size_sent = 0;
while(size_to_send) {

View File

@ -77,15 +77,15 @@ public:
// code - HTTP response code, can be 200 or 404
// content_type - HTTP content type, like "text/plain" or "image/png"
// content - actual content body
void send(int code, const char* content_type = NULL, String content = String(""));
void send(int code, char* content_type, String content);
void send(int code, String content_type, String content);
void send(int code, const char* content_type = NULL, const String& content = String(""));
void send(int code, char* content_type, const String& content);
void send(int code, const String& content_type, const String& content);
void setContentLength(size_t contentLength) { _contentLength = contentLength; }
void sendHeader(String name, String value, bool first = false);
void sendContent(String content);
void sendHeader(const String& name, const String& value, bool first = false);
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());
if (String(file.name()).endsWith(".gz") &&
contentType != "application/x-gzip" &&

View File

@ -9,14 +9,12 @@ public:
protected:
static void _add(T* self) {
DEBUGV("%s %08x %08x\n", __func__, (uint32_t) self, (uint32_t) _s_first);
T* tmp = _s_first;
_s_first = self;
self->_next = tmp;
}
static void _remove(T* self) {
DEBUGV("%s %08x %08x\n", __func__, (uint32_t) self, (uint32_t) _s_first);
if (_s_first == self) {
_s_first = self->_next;
self->_next = 0;