mirror of
				https://github.com/esp8266/Arduino.git
				synced 2025-11-03 14:33:37 +03:00 
			
		
		
		
	Allow test framework to use cores/esp8266/Arduino.h directly (#7377)
* Allow test framework to use cores/esp8266/Arduino.h directly * fix wps debugging * some more missing debug.h * Hunt down debug.h and roll-back TODO: rename it to something else... it is an internal header * Move abs+round checks to test/device/test_sw * Restore macros for C code * fixup! Move abs+round checks to test/device/test_sw * Fix bad c/p, actually try round with ints * tweak c macros per review * fix gcc-10 missing cerrno include
This commit is contained in:
		@@ -37,6 +37,7 @@ extern "C" {
 | 
			
		||||
#include "binary.h"
 | 
			
		||||
#include "esp8266_peri.h"
 | 
			
		||||
#include "twi.h"
 | 
			
		||||
 | 
			
		||||
#include "core_esp8266_features.h"
 | 
			
		||||
#include "core_esp8266_version.h"
 | 
			
		||||
 | 
			
		||||
@@ -125,15 +126,11 @@ void timer0_isr_init(void);
 | 
			
		||||
void timer0_attachInterrupt(timercallback userFunc);
 | 
			
		||||
void timer0_detachInterrupt(void);
 | 
			
		||||
 | 
			
		||||
// Use stdlib abs() and round() to avoid issues with the C++ libraries
 | 
			
		||||
#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
 | 
			
		||||
#define radians(deg) ((deg)*DEG_TO_RAD)
 | 
			
		||||
#define degrees(rad) ((rad)*RAD_TO_DEG)
 | 
			
		||||
#define sq(x) ((x)*(x))
 | 
			
		||||
 | 
			
		||||
void ets_intr_lock();
 | 
			
		||||
void ets_intr_unlock();
 | 
			
		||||
 | 
			
		||||
#define interrupts() xt_rsil(0)
 | 
			
		||||
#define noInterrupts() xt_rsil(15)
 | 
			
		||||
 | 
			
		||||
@@ -162,11 +159,12 @@ typedef uint16_t word;
 | 
			
		||||
typedef bool boolean;
 | 
			
		||||
typedef uint8_t byte;
 | 
			
		||||
 | 
			
		||||
void ets_intr_lock();
 | 
			
		||||
void ets_intr_unlock();
 | 
			
		||||
 | 
			
		||||
void init(void);
 | 
			
		||||
void initVariant(void);
 | 
			
		||||
 | 
			
		||||
int atexit(void (*func)()) __attribute__((weak));
 | 
			
		||||
 | 
			
		||||
void pinMode(uint8_t pin, uint8_t mode);
 | 
			
		||||
void digitalWrite(uint8_t pin, uint8_t val);
 | 
			
		||||
int digitalRead(uint8_t pin);
 | 
			
		||||
@@ -212,21 +210,20 @@ void optimistic_yield(uint32_t interval_us);
 | 
			
		||||
} // extern "C"
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
// undefine stdlib's definitions when encountered, provide abs that supports floating point for C code
 | 
			
		||||
#ifndef __cplusplus
 | 
			
		||||
#undef abs
 | 
			
		||||
#define abs(x) ({ __typeof__(x) _x = (x); _x > 0 ? _x : -_x; })
 | 
			
		||||
#undef round
 | 
			
		||||
#define round(x) ({ __typeof__(x) _x = (x); _x >= 0 ? (long)(_x + 0.5) : (long)(_x - 0.5); })
 | 
			
		||||
#endif // ifndef __cplusplus
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// from this point onward, we need to configure the c++ environment
 | 
			
		||||
#ifdef __cplusplus
 | 
			
		||||
 | 
			
		||||
#include <algorithm>
 | 
			
		||||
#include <cstdlib>
 | 
			
		||||
#include <cmath>
 | 
			
		||||
#include <pgmspace.h>
 | 
			
		||||
 | 
			
		||||
#include "WCharacter.h"
 | 
			
		||||
#include "WString.h"
 | 
			
		||||
 | 
			
		||||
#include "HardwareSerial.h"
 | 
			
		||||
#include "Esp.h"
 | 
			
		||||
#include "Updater.h"
 | 
			
		||||
#include "debug.h"
 | 
			
		||||
 | 
			
		||||
using std::min;
 | 
			
		||||
using std::max;
 | 
			
		||||
@@ -234,6 +231,10 @@ using std::round;
 | 
			
		||||
using std::isinf;
 | 
			
		||||
using std::isnan;
 | 
			
		||||
 | 
			
		||||
// Use float-compatible stl abs() and round(), we don't use Arduino macros to avoid issues with the C++ libraries
 | 
			
		||||
using std::abs;
 | 
			
		||||
using std::round;
 | 
			
		||||
 | 
			
		||||
#define _min(a,b) ({ decltype(a) _a = (a); decltype(b) _b = (b); _a < _b? _a : _b; })
 | 
			
		||||
#define _max(a,b) ({ decltype(a) _a = (a); decltype(b) _b = (b); _a > _b? _a : _b; })
 | 
			
		||||
 | 
			
		||||
@@ -273,8 +274,19 @@ inline void configTzTime(const char* tz, const char* server1,
 | 
			
		||||
    configTime(tz, server1, server2, server3);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Everything we expect to be implicitly loaded for the sketch
 | 
			
		||||
#include <pgmspace.h>
 | 
			
		||||
 | 
			
		||||
#include "WCharacter.h"
 | 
			
		||||
#include "WString.h"
 | 
			
		||||
 | 
			
		||||
#include "HardwareSerial.h"
 | 
			
		||||
#include "Esp.h"
 | 
			
		||||
#include "Updater.h"
 | 
			
		||||
 | 
			
		||||
#endif // __cplusplus
 | 
			
		||||
 | 
			
		||||
#include "debug.h"
 | 
			
		||||
#include "pins_arduino.h"
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
 
 | 
			
		||||
@@ -26,7 +26,9 @@
 | 
			
		||||
#include "MD5Builder.h"
 | 
			
		||||
#include "umm_malloc/umm_malloc.h"
 | 
			
		||||
#include "cont.h"
 | 
			
		||||
 | 
			
		||||
#include "coredecls.h"
 | 
			
		||||
#include <pgmspace.h>
 | 
			
		||||
 | 
			
		||||
extern "C" {
 | 
			
		||||
#include "user_interface.h"
 | 
			
		||||
 
 | 
			
		||||
@@ -22,6 +22,7 @@
 | 
			
		||||
#define ESP_H
 | 
			
		||||
 | 
			
		||||
#include <Arduino.h>
 | 
			
		||||
#include "core_esp8266_features.h"
 | 
			
		||||
#include "spi_vendors.h"
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 
 | 
			
		||||
@@ -18,7 +18,6 @@
 | 
			
		||||
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
#include <assert.h>
 | 
			
		||||
#include <debug.h>
 | 
			
		||||
#include <Arduino.h>
 | 
			
		||||
#include <cxxabi.h>
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -54,6 +54,7 @@
 | 
			
		||||
// level 0 will enable ALL interrupts,
 | 
			
		||||
//
 | 
			
		||||
#ifndef CORE_MOCK
 | 
			
		||||
 | 
			
		||||
#define xt_rsil(level) (__extension__({uint32_t state; __asm__ __volatile__("rsil %0," __STRINGIFY(level) : "=a" (state) :: "memory"); state;}))
 | 
			
		||||
#define xt_wsr_ps(state)  __asm__ __volatile__("wsr %0,ps; isync" :: "a" (state) : "memory")
 | 
			
		||||
 | 
			
		||||
@@ -73,6 +74,9 @@ inline uint32_t esp_get_program_counter() {
 | 
			
		||||
 | 
			
		||||
#else // CORE_MOCK
 | 
			
		||||
 | 
			
		||||
#define xt_rsil(level) (level)
 | 
			
		||||
#define xt_wsr_ps(state) do { (void)(state); } while (0)
 | 
			
		||||
 | 
			
		||||
inline uint32_t esp_get_program_counter() { return 0; }
 | 
			
		||||
 | 
			
		||||
#endif // CORE_MOCK
 | 
			
		||||
 
 | 
			
		||||
@@ -21,6 +21,9 @@
 | 
			
		||||
#ifndef ESP8266_PERI_H_INCLUDED
 | 
			
		||||
#define ESP8266_PERI_H_INCLUDED
 | 
			
		||||
 | 
			
		||||
// we expect mocking framework to provide these
 | 
			
		||||
#ifndef CORE_MOCK
 | 
			
		||||
 | 
			
		||||
#include "c_types.h"
 | 
			
		||||
#include "esp8266_undocumented.h"
 | 
			
		||||
 | 
			
		||||
@@ -847,4 +850,6 @@ extern volatile uint32_t* const esp8266_gpioToFn[16];
 | 
			
		||||
**/
 | 
			
		||||
#define RANDOM_REG32  ESP8266_DREG(0x20E44)
 | 
			
		||||
 | 
			
		||||
#endif // ifndef CORE_MOCK
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
 
 | 
			
		||||
@@ -127,6 +127,7 @@ void _exit(int status) {
 | 
			
		||||
    abort();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int atexit(void (*func)()) __attribute__((weak));
 | 
			
		||||
int atexit(void (*func)()) {
 | 
			
		||||
    (void) func;
 | 
			
		||||
    return 0;
 | 
			
		||||
 
 | 
			
		||||
@@ -17,9 +17,10 @@
 | 
			
		||||
#include <stdint.h>
 | 
			
		||||
#include <stddef.h>
 | 
			
		||||
#include <stdbool.h>
 | 
			
		||||
#include <debug.h>
 | 
			
		||||
 | 
			
		||||
#include <pgmspace.h>
 | 
			
		||||
#include <esp8266_undocumented.h>
 | 
			
		||||
#include "../debug.h"
 | 
			
		||||
#include "../esp8266_undocumented.h"
 | 
			
		||||
 | 
			
		||||
#ifdef __cplusplus
 | 
			
		||||
extern "C" {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user