mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-19 23:22:16 +03:00
Merge branch 'master' into master
This commit is contained in:
commit
1569b3ba5d
21
.travis.yml
21
.travis.yml
@ -3,7 +3,20 @@ language: bash
|
|||||||
os:
|
os:
|
||||||
- linux
|
- linux
|
||||||
|
|
||||||
|
addons:
|
||||||
|
apt:
|
||||||
|
sources:
|
||||||
|
- ubuntu-toolchain-r-test
|
||||||
|
packages:
|
||||||
|
- g++-4.8
|
||||||
|
|
||||||
script:
|
script:
|
||||||
|
- set -e
|
||||||
|
- export CXX="g++-4.8" CC="gcc-4.8" GCOV="gcov-4.8"
|
||||||
|
- pushd $TRAVIS_BUILD_DIR/tests/host
|
||||||
|
- make
|
||||||
|
- make clean-objects
|
||||||
|
- popd
|
||||||
- wget -O arduino.tar.xz https://www.arduino.cc/download.php?f=/arduino-nightly-linux64.tar.xz
|
- wget -O arduino.tar.xz https://www.arduino.cc/download.php?f=/arduino-nightly-linux64.tar.xz
|
||||||
- tar xf arduino.tar.xz
|
- tar xf arduino.tar.xz
|
||||||
- mv arduino-nightly $HOME/arduino_ide
|
- mv arduino-nightly $HOME/arduino_ide
|
||||||
@ -20,10 +33,12 @@ script:
|
|||||||
- which arduino
|
- which arduino
|
||||||
- cd $TRAVIS_BUILD_DIR
|
- cd $TRAVIS_BUILD_DIR
|
||||||
- source tests/common.sh
|
- source tests/common.sh
|
||||||
- arduino --board esp8266com:esp8266:generic --save-prefs
|
|
||||||
- arduino --get-pref sketchbook.path
|
|
||||||
- install_libraries
|
- install_libraries
|
||||||
- build_sketches arduino $TRAVIS_BUILD_DIR
|
- build_sketches $HOME/arduino_ide $TRAVIS_BUILD_DIR "python tools/build.py -l $HOME/Arduino/libraries -b generic -v"
|
||||||
|
|
||||||
|
after_success:
|
||||||
|
- pushd $TRAVIS_BUILD_DIR/tests/host
|
||||||
|
- bash <(curl -s https://codecov.io/bash) -X gcov
|
||||||
|
|
||||||
notifications:
|
notifications:
|
||||||
email:
|
email:
|
||||||
|
@ -8,7 +8,7 @@ ESP8266 Arduino core comes with libraries to communicate over WiFi using TCP and
|
|||||||
# Contents
|
# Contents
|
||||||
- Installing options:
|
- Installing options:
|
||||||
- [Using Boards Manager](#installing-with-boards-manager)
|
- [Using Boards Manager](#installing-with-boards-manager)
|
||||||
- [Using git version](#using-git-version-)
|
- [Using git version](#using-git-version)
|
||||||
- [Using stable version with PlatformIO](#using-stable-version-with-platformio)
|
- [Using stable version with PlatformIO](#using-stable-version-with-platformio)
|
||||||
- [Building with make](#building-with-make)
|
- [Building with make](#building-with-make)
|
||||||
- [Documentation](#documentation)
|
- [Documentation](#documentation)
|
||||||
@ -41,7 +41,8 @@ Boards manager link: `http://arduino.esp8266.com/staging/package_esp8266com_inde
|
|||||||
|
|
||||||
Documentation: [http://esp8266.github.io/Arduino/versions/2.1.0-rc2/](http://esp8266.github.io/Arduino/versions/2.1.0-rc2/)
|
Documentation: [http://esp8266.github.io/Arduino/versions/2.1.0-rc2/](http://esp8266.github.io/Arduino/versions/2.1.0-rc2/)
|
||||||
|
|
||||||
### Using git version [](https://travis-ci.org/esp8266/Arduino)
|
### Using git version
|
||||||
|
[](https://travis-ci.org/esp8266/Arduino) [](https://codecov.io/github/esp8266/Arduino?branch=master)
|
||||||
|
|
||||||
- Install Arduino 1.6.7
|
- Install Arduino 1.6.7
|
||||||
- Go to Arduino directory
|
- Go to Arduino directory
|
||||||
|
@ -248,7 +248,7 @@ espduino.build.mcu=esp8266
|
|||||||
espduino.build.f_cpu=80000000L
|
espduino.build.f_cpu=80000000L
|
||||||
espduino.build.board=ESP8266_ESP13
|
espduino.build.board=ESP8266_ESP13
|
||||||
espduino.build.core=esp8266
|
espduino.build.core=esp8266
|
||||||
espduino.build.variant=espduino
|
espduino.build.variant=ESPDuino
|
||||||
espduino.build.flash_mode=dio
|
espduino.build.flash_mode=dio
|
||||||
espduino.build.flash_size=4M
|
espduino.build.flash_size=4M
|
||||||
espduino.build.flash_freq=40
|
espduino.build.flash_freq=40
|
||||||
|
@ -123,6 +123,12 @@ public:
|
|||||||
else if (path.endsWith(".jpg")) return "image/jpeg";
|
else if (path.endsWith(".jpg")) return "image/jpeg";
|
||||||
else if (path.endsWith(".ico")) return "image/x-icon";
|
else if (path.endsWith(".ico")) return "image/x-icon";
|
||||||
else if (path.endsWith(".svg")) return "image/svg+xml";
|
else if (path.endsWith(".svg")) return "image/svg+xml";
|
||||||
|
else if (path.endsWith(".ttf")) return "application/x-font-ttf";
|
||||||
|
else if (path.endsWith(".otf")) return "application/x-font-opentype";
|
||||||
|
else if (path.endsWith(".woff")) return "application/font-woff";
|
||||||
|
else if (path.endsWith(".woff2")) return "application/font-woff2";
|
||||||
|
else if (path.endsWith(".eot")) return "application/vnd.ms-fontobject";
|
||||||
|
else if (path.endsWith(".sfnt")) return "application/font-sfnt";
|
||||||
else if (path.endsWith(".xml")) return "text/xml";
|
else if (path.endsWith(".xml")) return "text/xml";
|
||||||
else if (path.endsWith(".pdf")) return "application/pdf";
|
else if (path.endsWith(".pdf")) return "application/pdf";
|
||||||
else if (path.endsWith(".zip")) return "application/zip";
|
else if (path.endsWith(".zip")) return "application/zip";
|
||||||
|
@ -4,20 +4,34 @@ function build_sketches()
|
|||||||
{
|
{
|
||||||
local arduino=$1
|
local arduino=$1
|
||||||
local srcpath=$2
|
local srcpath=$2
|
||||||
|
local build_cmd=$3
|
||||||
|
echo $build_cmd
|
||||||
local sketches=$(find $srcpath -name *.ino)
|
local sketches=$(find $srcpath -name *.ino)
|
||||||
|
export ARDUINO_IDE_PATH=$arduino
|
||||||
for sketch in $sketches; do
|
for sketch in $sketches; do
|
||||||
local sketchdir=$(dirname $sketch)
|
local sketchdir=$(dirname $sketch)
|
||||||
|
local sketchdirname=$(basename $sketchdir)
|
||||||
|
local sketchname=$(basename $sketch)
|
||||||
|
if [[ "${sketchdirname}.ino" != "$sketchname" ]]; then
|
||||||
|
echo "Skipping $sketch, beacause it is not the main sketch file";
|
||||||
|
continue
|
||||||
|
fi;
|
||||||
if [[ -f "$sketchdir/.test.skip" ]]; then
|
if [[ -f "$sketchdir/.test.skip" ]]; then
|
||||||
echo -e "\n\n ------------ Skipping $sketch ------------ \n\n";
|
echo -e "\n ------------ Skipping $sketch ------------ \n";
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
echo -e "\n\n ------------ Building $sketch ------------ \n\n";
|
echo -e "\n ------------ Building $sketch ------------ \n";
|
||||||
$arduino --verify $sketch;
|
# $arduino --verify $sketch;
|
||||||
|
echo "$build_cmd $sketch"
|
||||||
|
time ($build_cmd $sketch >build.log)
|
||||||
local result=$?
|
local result=$?
|
||||||
if [ $result -ne 0 ]; then
|
if [ $result -ne 0 ]; then
|
||||||
echo "Build failed ($1)"
|
echo "Build failed ($1)"
|
||||||
|
echo "Build log:"
|
||||||
|
cat build.log
|
||||||
return $result
|
return $result
|
||||||
fi
|
fi
|
||||||
|
rm build.log
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
97
tests/host/Makefile
Normal file
97
tests/host/Makefile
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
OBJECT_DIRECTORY := obj
|
||||||
|
BINARY_DIRECTORY := bin
|
||||||
|
OUTPUT_BINARY := $(BINARY_DIRECTORY)/host_tests
|
||||||
|
CORE_PATH := ../../cores/esp8266
|
||||||
|
|
||||||
|
# I wasn't able to build with clang when -coverage flag is enabled, forcing GCC on OS X
|
||||||
|
ifeq ($(shell uname -s),Darwin)
|
||||||
|
CC := gcc
|
||||||
|
CXX := g++
|
||||||
|
endif
|
||||||
|
GCOV ?= gcov
|
||||||
|
|
||||||
|
CORE_CPP_FILES := $(addprefix $(CORE_PATH)/,\
|
||||||
|
StreamString.cpp \
|
||||||
|
Stream.cpp \
|
||||||
|
WString.cpp \
|
||||||
|
Print.cpp \
|
||||||
|
FS.cpp \
|
||||||
|
spiffs_api.cpp \
|
||||||
|
)
|
||||||
|
|
||||||
|
CORE_C_FILES := $(addprefix $(CORE_PATH)/,\
|
||||||
|
core_esp8266_noniso.c \
|
||||||
|
spiffs/spiffs_cache.c \
|
||||||
|
spiffs/spiffs_check.c \
|
||||||
|
spiffs/spiffs_gc.c \
|
||||||
|
spiffs/spiffs_hydrogen.c \
|
||||||
|
spiffs/spiffs_nucleus.c \
|
||||||
|
)
|
||||||
|
|
||||||
|
MOCK_CPP_FILES := $(addprefix common/,\
|
||||||
|
Arduino.cpp \
|
||||||
|
spiffs_mock.cpp \
|
||||||
|
WMath.cpp \
|
||||||
|
)
|
||||||
|
|
||||||
|
INC_PATHS += $(addprefix -I, \
|
||||||
|
common \
|
||||||
|
$(CORE_PATH) \
|
||||||
|
)
|
||||||
|
|
||||||
|
TEST_CPP_FILES := \
|
||||||
|
fs/test_fs.cpp \
|
||||||
|
|
||||||
|
CXXFLAGS += -std=c++11 -Wall -coverage -O0
|
||||||
|
CFLAGS += -std=c99 -Wall -coverage -O0
|
||||||
|
LDFLAGS += -coverage -O0
|
||||||
|
|
||||||
|
remduplicates = $(strip $(if $1,$(firstword $1) $(call remduplicates,$(filter-out $(firstword $1),$1))))
|
||||||
|
|
||||||
|
C_SOURCE_FILES = $(CORE_C_FILES)
|
||||||
|
CPP_SOURCE_FILES = $(MOCK_CPP_FILES) $(CORE_CPP_FILES) $(TEST_CPP_FILES)
|
||||||
|
C_OBJECTS = $(C_SOURCE_FILES:.c=.c.o)
|
||||||
|
|
||||||
|
CPP_OBJECTS = $(CPP_SOURCE_FILES:.cpp=.cpp.o)
|
||||||
|
|
||||||
|
OBJECTS = $(C_OBJECTS) $(CPP_OBJECTS)
|
||||||
|
COVERAGE_FILES = $(OBJECTS:.o=.gc*)
|
||||||
|
|
||||||
|
all: build-info $(OUTPUT_BINARY) test gcov
|
||||||
|
|
||||||
|
test: $(OUTPUT_BINARY)
|
||||||
|
$(OUTPUT_BINARY)
|
||||||
|
|
||||||
|
clean: clean-objects clean-coverage
|
||||||
|
rm -rf $(BINARY_DIRECTORY)
|
||||||
|
|
||||||
|
clean-objects:
|
||||||
|
rm -rf $(OBJECTS)
|
||||||
|
|
||||||
|
clean-coverage:
|
||||||
|
rm -rf $(COVERAGE_FILES) *.gcov
|
||||||
|
|
||||||
|
gcov: test
|
||||||
|
find $(CORE_PATH) -name "*.gcno" -exec $(GCOV) -r -pb {} +
|
||||||
|
|
||||||
|
build-info:
|
||||||
|
echo "-------- build tools info --------"
|
||||||
|
echo "CC: " $(CC)
|
||||||
|
$(CC) -v
|
||||||
|
echo "CXX: " $(CXX)
|
||||||
|
$(CXX) -v
|
||||||
|
echo "GCOV: " $(GCOV)
|
||||||
|
$(GCOV) -v
|
||||||
|
echo "----------------------------------"
|
||||||
|
|
||||||
|
$(BINARY_DIRECTORY):
|
||||||
|
mkdir -p $@
|
||||||
|
|
||||||
|
$(C_OBJECTS): %.c.o: %.c
|
||||||
|
$(CC) $(CFLAGS) $(INC_PATHS) -c -o $@ $<
|
||||||
|
|
||||||
|
$(CPP_OBJECTS): %.cpp.o: %.cpp
|
||||||
|
$(CXX) $(CXXFLAGS) $(INC_PATHS) -c -o $@ $<
|
||||||
|
|
||||||
|
$(OUTPUT_BINARY): $(BINARY_DIRECTORY) $(OBJECTS)
|
||||||
|
$(CXX) $(LDFLAGS) $(OBJECTS) $(LIBS) -o $(OUTPUT_BINARY)
|
37
tests/host/common/Arduino.cpp
Normal file
37
tests/host/common/Arduino.cpp
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
Arduino.cpp - Mocks for common Arduino APIs
|
||||||
|
Copyright © 2016 Ivan Grokhotkov
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define CATCH_CONFIG_MAIN
|
||||||
|
#include <catch.hpp>
|
||||||
|
#include <sys/time.h>
|
||||||
|
#include "Arduino.h"
|
||||||
|
|
||||||
|
|
||||||
|
extern "C" unsigned long millis()
|
||||||
|
{
|
||||||
|
timeval time;
|
||||||
|
gettimeofday(&time, NULL);
|
||||||
|
return (time.tv_sec * 1000) + (time.tv_usec / 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
extern "C" void yield()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
extern "C" void __panic_func(const char* file, int line, const char* func) {
|
||||||
|
abort();
|
||||||
|
}
|
282
tests/host/common/Arduino.h
Normal file
282
tests/host/common/Arduino.h
Normal file
@ -0,0 +1,282 @@
|
|||||||
|
/*
|
||||||
|
Arduino.h - Main include file for the Arduino SDK
|
||||||
|
Copyright (c) 2005-2013 Arduino Team. All right reserved.
|
||||||
|
|
||||||
|
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 Arduino_h
|
||||||
|
#define Arduino_h
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
#include "binary.h"
|
||||||
|
#include "twi.h"
|
||||||
|
#include "core_esp8266_features.h"
|
||||||
|
|
||||||
|
#define HIGH 0x1
|
||||||
|
#define LOW 0x0
|
||||||
|
|
||||||
|
#define PWMRANGE 1023
|
||||||
|
|
||||||
|
//GPIO FUNCTIONS
|
||||||
|
#define INPUT 0x00
|
||||||
|
#define INPUT_PULLUP 0x02
|
||||||
|
#define INPUT_PULLDOWN_16 0x04 // PULLDOWN only possible for pin16
|
||||||
|
#define OUTPUT 0x01
|
||||||
|
#define OUTPUT_OPEN_DRAIN 0x03
|
||||||
|
#define WAKEUP_PULLUP 0x05
|
||||||
|
#define WAKEUP_PULLDOWN 0x07
|
||||||
|
#define SPECIAL 0xF8 //defaults to the usable BUSes uart0rx/tx uart1tx and hspi
|
||||||
|
#define FUNCTION_0 0x08
|
||||||
|
#define FUNCTION_1 0x18
|
||||||
|
#define FUNCTION_2 0x28
|
||||||
|
#define FUNCTION_3 0x38
|
||||||
|
#define FUNCTION_4 0x48
|
||||||
|
|
||||||
|
#define PI 3.1415926535897932384626433832795
|
||||||
|
#define HALF_PI 1.5707963267948966192313216916398
|
||||||
|
#define TWO_PI 6.283185307179586476925286766559
|
||||||
|
#define DEG_TO_RAD 0.017453292519943295769236907684886
|
||||||
|
#define RAD_TO_DEG 57.295779513082320876798154814105
|
||||||
|
#define EULER 2.718281828459045235360287471352
|
||||||
|
|
||||||
|
#define SERIAL 0x0
|
||||||
|
#define DISPLAY 0x1
|
||||||
|
|
||||||
|
#define LSBFIRST 0
|
||||||
|
#define MSBFIRST 1
|
||||||
|
|
||||||
|
//Interrupt Modes
|
||||||
|
#define DISABLED 0x00
|
||||||
|
#define RISING 0x01
|
||||||
|
#define FALLING 0x02
|
||||||
|
#define CHANGE 0x03
|
||||||
|
#define ONLOW 0x04
|
||||||
|
#define ONHIGH 0x05
|
||||||
|
#define ONLOW_WE 0x0C
|
||||||
|
#define ONHIGH_WE 0x0D
|
||||||
|
|
||||||
|
#define DEFAULT 1
|
||||||
|
#define EXTERNAL 0
|
||||||
|
|
||||||
|
//timer dividers
|
||||||
|
#define TIM_DIV1 0 //80MHz (80 ticks/us - 104857.588 us max)
|
||||||
|
#define TIM_DIV16 1 //5MHz (5 ticks/us - 1677721.4 us max)
|
||||||
|
#define TIM_DIV265 3 //312.5Khz (1 tick = 3.2us - 26843542.4 us max)
|
||||||
|
//timer int_types
|
||||||
|
#define TIM_EDGE 0
|
||||||
|
#define TIM_LEVEL 1
|
||||||
|
//timer reload values
|
||||||
|
#define TIM_SINGLE 0 //on interrupt routine you need to write a new value to start the timer again
|
||||||
|
#define TIM_LOOP 1 //on interrupt the counter will start with the same value again
|
||||||
|
|
||||||
|
#define timer1_read() (T1V)
|
||||||
|
#define timer1_enabled() ((T1C & (1 << TCTE)) != 0)
|
||||||
|
#define timer1_interrupted() ((T1C & (1 << TCIS)) != 0)
|
||||||
|
|
||||||
|
typedef void(*timercallback)(void);
|
||||||
|
|
||||||
|
void timer1_isr_init(void);
|
||||||
|
void timer1_enable(uint8_t divider, uint8_t int_type, uint8_t reload);
|
||||||
|
void timer1_disable(void);
|
||||||
|
void timer1_attachInterrupt(timercallback userFunc);
|
||||||
|
void timer1_detachInterrupt(void);
|
||||||
|
void timer1_write(uint32_t ticks); //maximum ticks 8388607
|
||||||
|
|
||||||
|
// timer0 is a special CPU timer that has very high resolution but with
|
||||||
|
// limited control.
|
||||||
|
// it uses CCOUNT (ESP.GetCycleCount()) as the non-resetable timer counter
|
||||||
|
// it does not support divide, type, or reload flags
|
||||||
|
// it is auto-disabled when the compare value matches CCOUNT
|
||||||
|
// it is auto-enabled when the compare value changes
|
||||||
|
#define timer0_interrupted() (ETS_INTR_PENDING() & (_BV(ETS_COMPARE0_INUM)))
|
||||||
|
#define timer0_read() ((__extension__({uint32_t count;__asm__ __volatile__("esync; rsr %0,ccompare0":"=a" (count));count;})))
|
||||||
|
#define timer0_write(count) __asm__ __volatile__("wsr %0,ccompare0; esync"::"a" (count) : "memory")
|
||||||
|
|
||||||
|
void timer0_isr_init(void);
|
||||||
|
void timer0_attachInterrupt(timercallback userFunc);
|
||||||
|
void timer0_detachInterrupt(void);
|
||||||
|
|
||||||
|
// undefine stdlib's abs if encountered
|
||||||
|
#ifdef abs
|
||||||
|
#undef abs
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define abs(x) ((x)>0?(x):-(x))
|
||||||
|
#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
|
||||||
|
#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
|
||||||
|
#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();
|
||||||
|
|
||||||
|
#ifndef __STRINGIFY
|
||||||
|
#define __STRINGIFY(a) #a
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// these low level routines provide a replacement for SREG interrupt save that AVR uses
|
||||||
|
// but are esp8266 specific. A normal use pattern is like
|
||||||
|
//
|
||||||
|
//{
|
||||||
|
// uint32_t savedPS = xt_rsil(1); // this routine will allow level 2 and above
|
||||||
|
// // do work here
|
||||||
|
// xt_wsr_ps(savedPS); // restore the state
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
// level (0-15), interrupts of the given level and above will be active
|
||||||
|
// level 15 will disable ALL interrupts,
|
||||||
|
// level 0 will enable ALL interrupts,
|
||||||
|
//
|
||||||
|
#define xt_rsil(level) (__extension__({uint32_t state; __asm__ __volatile__("rsil %0," __STRINGIFY(level) : "=a" (state)); state;}))
|
||||||
|
#define xt_wsr_ps(state) __asm__ __volatile__("wsr %0,ps; isync" :: "a" (state) : "memory")
|
||||||
|
|
||||||
|
#define interrupts() xt_rsil(0)
|
||||||
|
#define noInterrupts() xt_rsil(15)
|
||||||
|
|
||||||
|
|
||||||
|
#define clockCyclesPerMicrosecond() ( F_CPU / 1000000L )
|
||||||
|
#define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() )
|
||||||
|
#define microsecondsToClockCycles(a) ( (a) * clockCyclesPerMicrosecond() )
|
||||||
|
|
||||||
|
#define lowByte(w) ((uint8_t) ((w) & 0xff))
|
||||||
|
#define highByte(w) ((uint8_t) ((w) >> 8))
|
||||||
|
|
||||||
|
#define bitRead(value, bit) (((value) >> (bit)) & 0x01)
|
||||||
|
#define bitSet(value, bit) ((value) |= (1UL << (bit)))
|
||||||
|
#define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
|
||||||
|
#define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit))
|
||||||
|
|
||||||
|
// avr-libc defines _NOP() since 1.6.2
|
||||||
|
#ifndef _NOP
|
||||||
|
#define _NOP() do { __asm__ volatile ("nop"); } while (0)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef unsigned int word;
|
||||||
|
|
||||||
|
#define bit(b) (1UL << (b))
|
||||||
|
#define _BV(b) (1UL << (b))
|
||||||
|
|
||||||
|
typedef uint8_t boolean;
|
||||||
|
typedef uint8_t byte;
|
||||||
|
|
||||||
|
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);
|
||||||
|
int analogRead(uint8_t pin);
|
||||||
|
void analogReference(uint8_t mode);
|
||||||
|
void analogWrite(uint8_t pin, int val);
|
||||||
|
void analogWriteFreq(uint32_t freq);
|
||||||
|
void analogWriteRange(uint32_t range);
|
||||||
|
|
||||||
|
unsigned long millis(void);
|
||||||
|
unsigned long micros(void);
|
||||||
|
void delay(unsigned long);
|
||||||
|
void delayMicroseconds(unsigned int us);
|
||||||
|
unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout);
|
||||||
|
unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout);
|
||||||
|
|
||||||
|
void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val);
|
||||||
|
uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder);
|
||||||
|
|
||||||
|
void attachInterrupt(uint8_t pin, void (*)(void), int mode);
|
||||||
|
void detachInterrupt(uint8_t pin);
|
||||||
|
|
||||||
|
void setup(void);
|
||||||
|
void loop(void);
|
||||||
|
|
||||||
|
void yield(void);
|
||||||
|
void optimistic_yield(uint32_t interval_us);
|
||||||
|
|
||||||
|
#define digitalPinToPort(pin) (0)
|
||||||
|
#define digitalPinToBitMask(pin) (1UL << (pin))
|
||||||
|
#define digitalPinToTimer(pin) (0)
|
||||||
|
#define portOutputRegister(port) ((volatile uint32_t*) &GPO)
|
||||||
|
#define portInputRegister(port) ((volatile uint32_t*) &GPI)
|
||||||
|
#define portModeRegister(port) ((volatile uint32_t*) &GPE)
|
||||||
|
|
||||||
|
#define NOT_A_PIN -1
|
||||||
|
#define NOT_A_PORT -1
|
||||||
|
#define NOT_AN_INTERRUPT -1
|
||||||
|
#define NOT_ON_TIMER 0
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} // extern "C"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
|
||||||
|
#include "pgmspace.h"
|
||||||
|
|
||||||
|
#include "WCharacter.h"
|
||||||
|
#include "WString.h"
|
||||||
|
|
||||||
|
#include "HardwareSerial.h"
|
||||||
|
#include "Esp.h"
|
||||||
|
#include "Updater.h"
|
||||||
|
#include "debug.h"
|
||||||
|
|
||||||
|
#ifndef _GLIBCXX_VECTOR
|
||||||
|
// arduino is not compatible with std::vector
|
||||||
|
#define min(a,b) ((a)<(b)?(a):(b))
|
||||||
|
#define max(a,b) ((a)>(b)?(a):(b))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define _min(a,b) ((a)<(b)?(a):(b))
|
||||||
|
#define _max(a,b) ((a)>(b)?(a):(b))
|
||||||
|
|
||||||
|
uint16_t makeWord(uint16_t w);
|
||||||
|
uint16_t makeWord(byte h, byte l);
|
||||||
|
|
||||||
|
#define word(...) makeWord(__VA_ARGS__)
|
||||||
|
|
||||||
|
unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L);
|
||||||
|
unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L);
|
||||||
|
|
||||||
|
void tone(uint8_t _pin, unsigned int frequency, unsigned long duration = 0);
|
||||||
|
void noTone(uint8_t _pin);
|
||||||
|
|
||||||
|
// WMath prototypes
|
||||||
|
long random(long);
|
||||||
|
long random(long, long);
|
||||||
|
void randomSeed(unsigned long);
|
||||||
|
long map(long, long, long, long, long);
|
||||||
|
|
||||||
|
extern "C" void configTime(long timezone, int daylightOffset_sec,
|
||||||
|
const char* server1, const char* server2 = nullptr, const char* server3 = nullptr);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "pins_arduino.h"
|
||||||
|
|
||||||
|
#endif /* Arduino_h */
|
61
tests/host/common/WMath.cpp
Normal file
61
tests/host/common/WMath.cpp
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
/* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
||||||
|
|
||||||
|
/*
|
||||||
|
Part of the Wiring project - http://wiring.org.co
|
||||||
|
Copyright (c) 2004-06 Hernando Barragan
|
||||||
|
Modified 13 August 2006, David A. Mellis for Arduino - http://www.arduino.cc/
|
||||||
|
|
||||||
|
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., 59 Temple Place, Suite 330,
|
||||||
|
Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
|
$Id$
|
||||||
|
*/
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
#include <stdlib.h>
|
||||||
|
}
|
||||||
|
|
||||||
|
void randomSeed(unsigned long seed) {
|
||||||
|
if(seed != 0) {
|
||||||
|
srand(seed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
long random(long howbig) {
|
||||||
|
if(howbig == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return (rand()) % howbig;
|
||||||
|
}
|
||||||
|
|
||||||
|
long random(long howsmall, long howbig) {
|
||||||
|
if(howsmall >= howbig) {
|
||||||
|
return howsmall;
|
||||||
|
}
|
||||||
|
long diff = howbig - howsmall;
|
||||||
|
return random(diff) + howsmall;
|
||||||
|
}
|
||||||
|
|
||||||
|
long map(long x, long in_min, long in_max, long out_min, long out_max) {
|
||||||
|
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int makeWord(unsigned int w) {
|
||||||
|
return w;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int makeWord(unsigned char h, unsigned char l) {
|
||||||
|
return (h << 8) | l;
|
||||||
|
}
|
9460
tests/host/common/catch.hpp
Normal file
9460
tests/host/common/catch.hpp
Normal file
File diff suppressed because it is too large
Load Diff
78
tests/host/common/pgmspace.h
Normal file
78
tests/host/common/pgmspace.h
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
/*
|
||||||
|
pgmspace.cpp - PROGMEM stubs for host-side tests
|
||||||
|
Copyright © 2016 Ivan Grokhotkov
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
*/
|
||||||
|
#ifndef __PGMSPACE_H_
|
||||||
|
#define __PGMSPACE_H_
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#define PROGMEM
|
||||||
|
#define PGM_P const char *
|
||||||
|
#define PGM_VOID_P const void *
|
||||||
|
#define PSTR(s) (s)
|
||||||
|
|
||||||
|
|
||||||
|
#define _SFR_BYTE(n) (n)
|
||||||
|
|
||||||
|
typedef void prog_void;
|
||||||
|
typedef char prog_char;
|
||||||
|
typedef unsigned char prog_uchar;
|
||||||
|
typedef int8_t prog_int8_t;
|
||||||
|
typedef uint8_t prog_uint8_t;
|
||||||
|
typedef int16_t prog_int16_t;
|
||||||
|
typedef uint16_t prog_uint16_t;
|
||||||
|
typedef int32_t prog_int32_t;
|
||||||
|
typedef uint32_t prog_uint32_t;
|
||||||
|
|
||||||
|
#define memcmp_P memcmp
|
||||||
|
#define memccpy_P memccpy
|
||||||
|
#define memmem_P memmem
|
||||||
|
#define memcpy_P memcpy
|
||||||
|
|
||||||
|
#define strncpy_P strncpy
|
||||||
|
#define strcpy_P strcpy
|
||||||
|
|
||||||
|
#define strncat_P strncat
|
||||||
|
#define strcat_P strcat
|
||||||
|
|
||||||
|
#define strncmp_P strncmp
|
||||||
|
#define strcmp_P strcmp
|
||||||
|
|
||||||
|
#define strncasecmp_P strncasecmp
|
||||||
|
#define strcasecmp_P strcasecmp
|
||||||
|
|
||||||
|
#define strnlen_P strnlen
|
||||||
|
#define strlen_P strlen
|
||||||
|
|
||||||
|
#define printf_P printf
|
||||||
|
#define sprintf_P sprintf
|
||||||
|
#define snprintf_P snprintf
|
||||||
|
#define vsnprintf_P vsnprintf
|
||||||
|
|
||||||
|
#define pgm_read_byte(addr) (*reinterpret_cast<const uint8_t*>(addr))
|
||||||
|
#define pgm_read_word(addr) (*reinterpret_cast<const uint16_t*>(addr))
|
||||||
|
#define pgm_read_float(addr) (*reinterpret_cast<const float*>(addr))
|
||||||
|
#define pgm_read_dword(addr) (*reinterpret_cast<const uint32_t*>(addr))
|
||||||
|
|
||||||
|
#define pgm_read_byte_near(addr) pgm_read_byte(addr)
|
||||||
|
#define pgm_read_word_near(addr) pgm_read_word(addr)
|
||||||
|
#define pgm_read_dword_near(addr) pgm_read_dword(addr)
|
||||||
|
#define pgm_read_float_near(addr) pgm_read_float(addr)
|
||||||
|
#define pgm_read_byte_far(addr) pgm_read_byte(addr)
|
||||||
|
#define pgm_read_word_far(addr) pgm_read_word(addr)
|
||||||
|
#define pgm_read_dword_far(addr) pgm_read_dword(addr)
|
||||||
|
#define pgm_read_float_far(addr) pgm_read_float(addr)
|
||||||
|
|
||||||
|
#endif //__PGMSPACE_H_
|
19
tests/host/common/pins_arduino.h
Normal file
19
tests/host/common/pins_arduino.h
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
/*
|
||||||
|
pins_arduino.h
|
||||||
|
Copyright © 2016 Ivan Grokhotkov
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
*/
|
||||||
|
#ifndef pins_arduino_h
|
||||||
|
#define pins_arduino_h
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* pins_arduino_h */
|
83
tests/host/common/spiffs_mock.cpp
Normal file
83
tests/host/common/spiffs_mock.cpp
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
/*
|
||||||
|
spiffs_mock.cpp - SPIFFS HAL mock for host side testing
|
||||||
|
Copyright © 2016 Ivan Grokhotkov
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "spiffs_mock.h"
|
||||||
|
#include "spiffs/spiffs.h"
|
||||||
|
#include "debug.h"
|
||||||
|
#include <flash_utils.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include <spiffs_api.h>
|
||||||
|
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
static uint32_t s_phys_addr = 0;
|
||||||
|
uint32_t s_phys_size = 0;
|
||||||
|
uint32_t s_phys_page = 0;
|
||||||
|
uint32_t s_phys_block = 0;
|
||||||
|
uint8_t* s_phys_data = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
FS SPIFFS(nullptr);
|
||||||
|
|
||||||
|
SpiffsMock::SpiffsMock(size_t fs_size, size_t fs_block, size_t fs_page)
|
||||||
|
{
|
||||||
|
m_fs.resize(fs_size, 0xff);
|
||||||
|
s_phys_addr = 0;
|
||||||
|
s_phys_size = static_cast<uint32_t>(fs_size);
|
||||||
|
s_phys_page = static_cast<uint32_t>(fs_page);
|
||||||
|
s_phys_block = static_cast<uint32_t>(fs_block);
|
||||||
|
s_phys_data = m_fs.data();
|
||||||
|
reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SpiffsMock::reset()
|
||||||
|
{
|
||||||
|
SPIFFS = FS(FSImplPtr(new SPIFFSImpl(0, s_phys_size, s_phys_page, s_phys_block, 5)));
|
||||||
|
}
|
||||||
|
|
||||||
|
SpiffsMock::~SpiffsMock()
|
||||||
|
{
|
||||||
|
s_phys_addr = 0;
|
||||||
|
s_phys_size = 0;
|
||||||
|
s_phys_page = 0;
|
||||||
|
s_phys_block = 0;
|
||||||
|
s_phys_data = nullptr;
|
||||||
|
SPIFFS = FS(FSImplPtr(nullptr));
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t spiffs_hal_read(uint32_t addr, uint32_t size, uint8_t *dst) {
|
||||||
|
memcpy(dst, s_phys_data + addr, size);
|
||||||
|
return SPIFFS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t spiffs_hal_write(uint32_t addr, uint32_t size, uint8_t *src) {
|
||||||
|
memcpy(s_phys_data + addr, src, size);
|
||||||
|
return SPIFFS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t spiffs_hal_erase(uint32_t addr, uint32_t size) {
|
||||||
|
if ((size & (FLASH_SECTOR_SIZE - 1)) != 0 ||
|
||||||
|
(addr & (FLASH_SECTOR_SIZE - 1)) != 0) {
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
const uint32_t sector = addr / FLASH_SECTOR_SIZE;
|
||||||
|
const uint32_t sectorCount = size / FLASH_SECTOR_SIZE;
|
||||||
|
for (uint32_t i = 0; i < sectorCount; ++i) {
|
||||||
|
memset(s_phys_data + (sector + i) * FLASH_SECTOR_SIZE, 0xff, FLASH_SECTOR_SIZE);
|
||||||
|
}
|
||||||
|
return SPIFFS_OK;
|
||||||
|
}
|
38
tests/host/common/spiffs_mock.h
Normal file
38
tests/host/common/spiffs_mock.h
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
spiffs_mock.h - SPIFFS HAL mock for host side testing
|
||||||
|
Copyright © 2016 Ivan Grokhotkov
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef spiffs_mock_hpp
|
||||||
|
#define spiffs_mock_hpp
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <vector>
|
||||||
|
#include <FS.h>
|
||||||
|
|
||||||
|
class SpiffsMock {
|
||||||
|
public:
|
||||||
|
SpiffsMock(size_t fs_size, size_t fs_block, size_t fs_page);
|
||||||
|
void reset();
|
||||||
|
~SpiffsMock();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
std::vector<uint8_t> m_fs;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define SPIFFS_MOCK_DECLARE(size_kb, block_kb, page_b) SpiffsMock spiffs_mock(size_kb * 1024, block_kb * 1024, page_b)
|
||||||
|
#define SPIFFS_MOCK_RESET() spiffs_mock.reset()
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* spiffs_mock_hpp */
|
80
tests/host/fs/test_fs.cpp
Normal file
80
tests/host/fs/test_fs.cpp
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
/*
|
||||||
|
test_fs.cpp - host side file system tests
|
||||||
|
Copyright © 2016 Ivan Grokhotkov
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <catch.hpp>
|
||||||
|
#include <FS.h>
|
||||||
|
#include "../common/spiffs_mock.h"
|
||||||
|
|
||||||
|
|
||||||
|
TEST_CASE("FS can begin","[fs]")
|
||||||
|
{
|
||||||
|
SPIFFS_MOCK_DECLARE(1024, 8, 512);
|
||||||
|
REQUIRE(SPIFFS.begin());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("FS can create file","[fs]")
|
||||||
|
{
|
||||||
|
SPIFFS_MOCK_DECLARE(1024, 8, 512);
|
||||||
|
REQUIRE(SPIFFS.begin());
|
||||||
|
{
|
||||||
|
File f = SPIFFS.open("config.txt", "w");
|
||||||
|
REQUIRE(f);
|
||||||
|
}
|
||||||
|
REQUIRE(SPIFFS.exists("config.txt"));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Files can be written and appended to","[fs]")
|
||||||
|
{
|
||||||
|
SPIFFS_MOCK_DECLARE(1024, 8, 512);
|
||||||
|
REQUIRE(SPIFFS.begin());
|
||||||
|
{
|
||||||
|
File f = SPIFFS.open("config1.txt", "w");
|
||||||
|
REQUIRE(f);
|
||||||
|
f.println("file 1");
|
||||||
|
}
|
||||||
|
{
|
||||||
|
File f = SPIFFS.open("config1.txt", "a");
|
||||||
|
REQUIRE(f);
|
||||||
|
f.println("file 1 again");
|
||||||
|
}
|
||||||
|
{
|
||||||
|
File f = SPIFFS.open("config1.txt", "r");
|
||||||
|
REQUIRE(f);
|
||||||
|
char buf[128];
|
||||||
|
size_t len = f.read((uint8_t*)buf, sizeof(buf));
|
||||||
|
buf[len] = 0;
|
||||||
|
REQUIRE(strcmp(buf, "file 1\r\nfile 1 again\r\n") == 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Files persist after reset", "[fs]")
|
||||||
|
{
|
||||||
|
SPIFFS_MOCK_DECLARE(1024, 8, 512);
|
||||||
|
REQUIRE(SPIFFS.begin());
|
||||||
|
{
|
||||||
|
File f = SPIFFS.open("config1.txt", "w");
|
||||||
|
REQUIRE(f);
|
||||||
|
f.println("file 1");
|
||||||
|
}
|
||||||
|
SPIFFS_MOCK_RESET();
|
||||||
|
REQUIRE(SPIFFS.begin());
|
||||||
|
{
|
||||||
|
File f = SPIFFS.open("config1.txt", "r");
|
||||||
|
REQUIRE(f);
|
||||||
|
REQUIRE(f.readString() == "file 1\r\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
138
tools/build.py
Executable file
138
tools/build.py
Executable file
@ -0,0 +1,138 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
#
|
||||||
|
# build.py — build a sketch using arduino-builder
|
||||||
|
#
|
||||||
|
# Wrapper script around arduino-builder which accepts some ESP8266-specific
|
||||||
|
# options and translates them into FQBN
|
||||||
|
#
|
||||||
|
# Copyright © 2016 Ivan Grokhotkov
|
||||||
|
#
|
||||||
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
# of this software and associated documentation files (the "Software"), to deal
|
||||||
|
# in the Software without restriction, including without limitation the rights
|
||||||
|
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
# copies of the Software, and to permit persons to whom the Software is
|
||||||
|
# furnished to do so, subject to the following conditions:
|
||||||
|
#
|
||||||
|
# The above copyright notice and this permission notice shall be included in
|
||||||
|
# all copies or substantial portions of the Software.
|
||||||
|
#
|
||||||
|
#
|
||||||
|
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
import argparse
|
||||||
|
import subprocess
|
||||||
|
import tempfile
|
||||||
|
import shutil
|
||||||
|
|
||||||
|
def compile(tmp_dir, sketch, tools_dir, hardware_dir, ide_path, f, args):
|
||||||
|
cmd = ide_path + '/arduino-builder '
|
||||||
|
cmd += '-compile -logger=human '
|
||||||
|
for lib_dir in args.library_path:
|
||||||
|
cmd += '-libraries "' + lib_dir + '" '
|
||||||
|
cmd += '-build-path "' + tmp_dir + '" '
|
||||||
|
cmd += '-hardware "' + ide_path + '/hardware" '
|
||||||
|
cmd += '-hardware ' + hardware_dir + ' '
|
||||||
|
cmd += '-tools "' + ide_path + '/tools-builder" '
|
||||||
|
# Debug=Serial,DebugLevel=Core____
|
||||||
|
cmd += '-fqbn=esp8266com:esp8266:{board_name}:' \
|
||||||
|
'UploadTool=esptool,' \
|
||||||
|
'CpuFrequency={cpu_freq},' \
|
||||||
|
'FlashFreq={flash_freq},' \
|
||||||
|
'FlashMode={flash_mode},' \
|
||||||
|
'UploadSpeed=921600,' \
|
||||||
|
'FlashSize={flash_size},' \
|
||||||
|
'ResetMethod=nodemcu'.format(**vars(args))
|
||||||
|
if args.debug_port and args.debug_level:
|
||||||
|
cmd += 'Debug={debug_port},DebugLevel={debug_level}'.format(**vars(args))
|
||||||
|
cmd += ' '
|
||||||
|
cmd += '-ide-version=10607 '
|
||||||
|
cmd += '-warnings={warnings} '.format(**vars(args))
|
||||||
|
if args.verbose:
|
||||||
|
cmd += '-verbose '
|
||||||
|
cmd += sketch
|
||||||
|
|
||||||
|
if args.verbose:
|
||||||
|
print('Building: ' + cmd, file=f)
|
||||||
|
|
||||||
|
cmds = cmd.split(' ')
|
||||||
|
p = subprocess.Popen(cmds, stdout=f, stderr=subprocess.STDOUT)
|
||||||
|
p.wait()
|
||||||
|
return p.returncode
|
||||||
|
|
||||||
|
def parse_args():
|
||||||
|
parser = argparse.ArgumentParser(description='Sketch build helper')
|
||||||
|
parser.add_argument('-v', '--verbose', help='Enable verbose output',
|
||||||
|
action='store_true')
|
||||||
|
parser.add_argument('-i', '--ide_path', help='Arduino IDE path')
|
||||||
|
parser.add_argument('-p', '--build_path', help='Build directory')
|
||||||
|
parser.add_argument('-l', '--library_path', help='Additional library path',
|
||||||
|
action='append')
|
||||||
|
parser.add_argument('-b', '--board_name', help='Board name', default='generic')
|
||||||
|
parser.add_argument('-s', '--flash_size', help='Flash size', default='512K64',
|
||||||
|
choices=['512K0', '512K64', '1M512', '4M1M', '4M3M'])
|
||||||
|
parser.add_argument('-f', '--cpu_freq', help='CPU frequency', default=80,
|
||||||
|
choices=[80, 160], type=int)
|
||||||
|
parser.add_argument('-m', '--flash_mode', help='Flash mode', default='qio',
|
||||||
|
choices=['dio', 'qio'])
|
||||||
|
parser.add_argument('-w', '--warnings', help='Compilation warnings level',
|
||||||
|
default='none', choices=['none', 'all', 'more'])
|
||||||
|
parser.add_argument('-o', '--output_binary', help='File name for output binary')
|
||||||
|
parser.add_argument('-k', '--keep', action='store_true',
|
||||||
|
help='Don\'t delete temporary build directory')
|
||||||
|
parser.add_argument('--flash_freq', help='Flash frequency', default=40,
|
||||||
|
type=int, choices=[40, 80])
|
||||||
|
parser.add_argument('--debug_port', help='Debug port',
|
||||||
|
choices=['Serial', 'Serial1'])
|
||||||
|
parser.add_argument('--debug_level', help='Debug level')
|
||||||
|
parser.add_argument('sketch_path', help='Sketch file path')
|
||||||
|
return parser.parse_args()
|
||||||
|
|
||||||
|
def main():
|
||||||
|
args = parse_args()
|
||||||
|
|
||||||
|
ide_path = args.ide_path
|
||||||
|
if not ide_path:
|
||||||
|
ide_path = os.environ.get('ARDUINO_IDE_PATH')
|
||||||
|
if not ide_path:
|
||||||
|
print("Please specify Arduino IDE path via --ide_path option"
|
||||||
|
"or ARDUINO_IDE_PATH environment variable.", file=sys.stderr)
|
||||||
|
return 2
|
||||||
|
|
||||||
|
sketch_path = args.sketch_path
|
||||||
|
tmp_dir = args.build_path
|
||||||
|
created_tmp_dir = False
|
||||||
|
if not tmp_dir:
|
||||||
|
tmp_dir = tempfile.mkdtemp()
|
||||||
|
created_tmp_dir = True
|
||||||
|
|
||||||
|
tools_dir = os.path.dirname(os.path.realpath(__file__)) + '/../tools'
|
||||||
|
hardware_dir = os.path.dirname(os.path.realpath(__file__)) + '/../cores'
|
||||||
|
|
||||||
|
output_name = tmp_dir + '/' + os.path.basename(sketch_path) + '.bin'
|
||||||
|
if args.verbose:
|
||||||
|
print("Sketch: ", sketch_path)
|
||||||
|
print("Build dir: ", tmp_dir)
|
||||||
|
print("Output: ", output_name)
|
||||||
|
|
||||||
|
if args.verbose:
|
||||||
|
f = sys.stdout
|
||||||
|
else:
|
||||||
|
f = open(tmp_dir + '/build.log', 'w')
|
||||||
|
|
||||||
|
res = compile(tmp_dir, sketch_path, tools_dir, hardware_dir, ide_path, f, args)
|
||||||
|
if res != 0:
|
||||||
|
return res
|
||||||
|
|
||||||
|
if args.output_binary is not None:
|
||||||
|
shutil.copy(output_name, args.output_binary)
|
||||||
|
|
||||||
|
if created_tmp_dir and not args.keep:
|
||||||
|
shutil.rmtree(tmp_dir, ignore_errors=True)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
sys.exit(main())
|
Loading…
x
Reference in New Issue
Block a user