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

emulation on host: minor updates (#8454)

* emulation on host: minor fixes
merge MockDigital.cpp and HostWiring.cpp

* emulation: share mockverbose between CI-on-host and emulation

* mock: add missing recently overridden method

* remove extern variable, use weak function
This commit is contained in:
david gauchard 2022-02-20 14:27:52 +01:00 committed by GitHub
parent 7356cd1ef1
commit 15e7d35d6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 51 additions and 61 deletions

View File

@ -111,7 +111,7 @@ void ESP8266HTTPUpdateServerTemplate<ServerType>::setup(ESP8266WebServerTemplate
} }
} else if(_authenticated && upload.status == UPLOAD_FILE_END && !_updaterError.length()){ } else if(_authenticated && upload.status == UPLOAD_FILE_END && !_updaterError.length()){
if(Update.end(true)){ //true to set the size to the current progress if(Update.end(true)){ //true to set the size to the current progress
if (_serial_output) Serial.printf("Update Success: %u\nRebooting...\n", upload.totalSize); if (_serial_output) Serial.printf("Update Success: %zu\nRebooting...\n", upload.totalSize);
} else { } else {
_setUpdaterError(); _setUpdaterError();
} }

View File

@ -136,7 +136,7 @@ MOCK_CPP_FILES_COMMON := \
MockUART.cpp \ MockUART.cpp \
MockTools.cpp \ MockTools.cpp \
MocklwIP.cpp \ MocklwIP.cpp \
MockDigital.cpp \ HostWiring.cpp \
) )
MOCK_CPP_FILES := $(MOCK_CPP_FILES_COMMON) \ MOCK_CPP_FILES := $(MOCK_CPP_FILES_COMMON) \
@ -356,7 +356,6 @@ MOCK_ARDUINO_LIBS := \
MockWiFiServerSocket.cpp \ MockWiFiServerSocket.cpp \
MockWiFiServer.cpp \ MockWiFiServer.cpp \
UdpContextSocket.cpp \ UdpContextSocket.cpp \
HostWiring.cpp \
MockEsp.cpp \ MockEsp.cpp \
MockEEPROM.cpp \ MockEEPROM.cpp \
MockSPI.cpp \ MockSPI.cpp \

View File

@ -111,3 +111,11 @@ cont_t* g_pcont = NULL;
extern "C" void cont_suspend(cont_t*) extern "C" void cont_suspend(cont_t*)
{ {
} }
extern "C" int __mockverbose (const char* fmt, ...)
{
(void)fmt;
return 0;
}
int mockverbose (const char* fmt, ...) __attribute__ ((weak, alias("__mockverbose"), format (printf, 1, 2)));

View File

@ -37,6 +37,11 @@
#define VERBOSE(x...) mockverbose(x) #define VERBOSE(x...) mockverbose(x)
#endif #endif
#define GPIONUM 17
static uint8_t _mode[GPIONUM];
static uint8_t _gpio[GPIONUM];
void pinMode (uint8_t pin, uint8_t mode) void pinMode (uint8_t pin, uint8_t mode)
{ {
#define xxx(mode) case mode: m=STRHELPER(mode); break #define xxx(mode) case mode: m=STRHELPER(mode); break
@ -53,11 +58,19 @@ void pinMode (uint8_t pin, uint8_t mode)
default: m="(special)"; default: m="(special)";
} }
VERBOSE("gpio%d: mode='%s'\n", pin, m); VERBOSE("gpio%d: mode='%s'\n", pin, m);
if (pin < GPIONUM)
{
_mode[pin] = mode;
}
} }
void digitalWrite(uint8_t pin, uint8_t val) void digitalWrite(uint8_t pin, uint8_t val)
{ {
VERBOSE("digitalWrite(pin=%d val=%d)\n", pin, val); VERBOSE("digitalWrite(pin=%d val=%d)\n", pin, val);
if (pin < GPIONUM) {
_gpio[pin] = val;
}
} }
void analogWrite(uint8_t pin, int val) void analogWrite(uint8_t pin, int val)
@ -80,6 +93,9 @@ int digitalRead(uint8_t pin)
{ {
VERBOSE("digitalRead(%d)\n", pin); VERBOSE("digitalRead(%d)\n", pin);
// pin 0 is most likely a low active input if (pin < GPIONUM) {
return pin ? 0 : 1; return _gpio[pin] != 0;
} else {
return 0;
}
} }

View File

@ -1,56 +0,0 @@
/*
digital.c - wiring digital implementation for esp8266
Copyright (c) 2015 Hristo Gochkov. 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
*/
#define ARDUINO_MAIN
#include "wiring_private.h"
#include "pins_arduino.h"
#include "c_types.h"
#include "eagle_soc.h"
#include "ets_sys.h"
#include "user_interface.h"
#include "core_esp8266_waveform.h"
#include "interrupts.h"
extern "C" {
static uint8_t _mode[17];
static uint8_t _gpio[17];
extern void pinMode(uint8_t pin, uint8_t mode) {
if (pin < 17) {
_mode[pin] = mode;
}
}
extern void digitalWrite(uint8_t pin, uint8_t val) {
if (pin < 17) {
_gpio[pin] = val;
}
}
extern int digitalRead(uint8_t pin) {
if (pin < 17) {
return _gpio[pin] != 0;
} else {
return 0;
}
}
};

View File

@ -142,6 +142,15 @@ void EspClass::getHeapStats(uint32_t* hfree, uint16_t* hmax, uint8_t* hfrag) {
if (hfrag) *hfrag = 100 - (sqrt(hm) * 100) / hf; if (hfrag) *hfrag = 100 - (sqrt(hm) * 100) / hf;
} }
void EspClass::getHeapStats(uint32_t* hfree, uint32_t* hmax, uint8_t* hfrag) {
uint32_t hf = 10 * 1024;
float hm = 1 * 1024;
if (hfree) *hfree = hf;
if (hmax) *hmax = hm;
if (hfrag) *hfrag = 100 - (sqrt(hm) * 100) / hf;
}
bool EspClass::flashEraseSector(uint32_t sector) bool EspClass::flashEraseSector(uint32_t sector)
{ {
(void) sector; (void) sector;
@ -263,3 +272,8 @@ void EspClass::setExternalHeap()
void EspClass::resetHeap() void EspClass::resetHeap()
{ {
} }
void EspClass::reset ()
{
abort();
}

View File

@ -78,3 +78,12 @@ void configTime(int timezone, int daylightOffset_sec,
mockverbose("configTime: TODO (tz=%dH offset=%dS) (time will be host's)\n", timezone, daylightOffset_sec); mockverbose("configTime: TODO (tz=%dH offset=%dS) (time will be host's)\n", timezone, daylightOffset_sec);
} }
void configTime(const char* tz, const char* server1, const char* server2, const char* server3)
{
(void)server1;
(void)server2;
(void)server3;
mockverbose("configTime: TODO (tz='%s') (time will be host's)\n", tz);
}