esp32 support, build_flags_{ENVNAME}.sh now can be used and edited in IDE!

This commit is contained in:
livello
2018-07-04 01:22:00 +03:00
parent 797ce5d4ce
commit 09726be883
12 changed files with 161 additions and 100 deletions

View File

@@ -1,32 +1,28 @@
#! /bin/bash #! /bin/bash
# usage: # usage:
# first make your own copy of template # first make your own copy of template
# cp build_flags_template.sh my_build_flags.sh # cp build_flags_template.sh build_flags_{ENVNAME}.sh
# then edit, change or comment something # then edit, change or comment something
# nano my_build_flags.sh
# and source it
# source my_build_flags.sh
echo "==============================================Custom build flags are:====================================================="
export FLAGS="-DMY_CONFIG_SERVER=lazyhome.ru" export FLAGS="-DMY_CONFIG_SERVER=lazyhome.ru"
export FLAGS="$FLAGS -DWATCH_DOG_TICKER_DISABLE" #export FLAGS="$FLAGS -DWATCH_DOG_TICKER_DISABLE"
export FLAGS="$FLAGS -DUSE_1W_PIN=12" #export FLAGS="$FLAGS -DUSE_1W_PIN=12"
export FLAGS="$FLAGS -DSD_CARD_INSERTED" #export FLAGS="$FLAGS -DSD_CARD_INSERTED"
export FLAGS="$FLAGS -DSERIAL_BAUD=115200" export FLAGS="$FLAGS -DSERIAL_BAUD=115200"
export FLAGS="$FLAGS -DWiz5500" #export FLAGS="$FLAGS -DWiz5500"
export FLAGS="$FLAGS -DDISABLE_FREERAM_PRINT" #export FLAGS="$FLAGS -DDISABLE_FREERAM_PRINT"
export FLAGS="$FLAGS -DCUSTOM_FIRMWARE_MAC=de:ad:be:ef:fe:00" export FLAGS="$FLAGS -DCUSTOM_FIRMWARE_MAC=de:ad:be:ef:fe:00"
export FLAGS="$FLAGS -DDMX_DISABLE" # export FLAGS="$FLAGS -DDMX_DISABLE"
export FLAGS="$FLAGS -DMODBUS_DISABLE" # export FLAGS="$FLAGS -DMODBUS_DISABLE"
export FLAGS="$FLAGS -DOWIRE_DISABLE" # export FLAGS="$FLAGS -DOWIRE_DISABLE"
export FLAGS="$FLAGS -DAVR_DMXOUT_PIN=18" # export FLAGS="$FLAGS -DAVR_DMXOUT_PIN=18"
export FLAGS="$FLAGS -DLAN_INIT_DELAY=2000" # export FLAGS="$FLAGS -DLAN_INIT_DELAY=2000"
export FLAGS="$FLAGS -DCONTROLLINO" # export FLAGS="$FLAGS -DCONTROLLINO"
export FLAGS="$FLAGS -DESP_WIFI_AP=MYAP" # export FLAGS="$FLAGS -DESP_WIFI_AP=MYAP"
export FLAGS="$FLAGS -DESP_WIFI_PWD=MYPWD" # export FLAGS="$FLAGS -DESP_WIFI_PWD=MYPWD"
export FLAGS="$FLAGS -DDHT_DISABLE" # export FLAGS="$FLAGS -DWIFI_MANAGER_DISABLE"
export FLAGS="$FLAGS -DRESET_PIN=5" # export FLAGS="$FLAGS -DDHT_DISABLE"
export FLAGS="$FLAGS -DDHCP_RETRY_INTERVAL=60000" # export FLAGS="$FLAGS -DRESET_PIN=5"
export PLATFORMIO_BUILD_FLAGS="$FLAGS" # export FLAGS="$FLAGS -DDHCP_RETRY_INTERVAL=60000"
echo PLATFORMIO_BUILD_FLAGS=$PLATFORMIO_BUILD_FLAGS # export FLAGS="$FLAGS -DRESTART_LAN_ON_MQTT_ERRORS"
echo "==============================================Custom build flags END=====================================================" export FLAGS="$FLAGS -DPIO_SRC_REV="$(git log --pretty=format:%h_%ad -1 --date=short)
unset FLAGS echo $FLAGS

View File

@@ -28,7 +28,7 @@ e-mail anklimov@gmail.com
#endif #endif
#endif #endif
#if defined(__ESP__) #if defined(ESP8266)
#ifndef DMX_DISABLE #ifndef DMX_DISABLE
DMXESPSerial dmxout; DMXESPSerial dmxout;
#endif #endif
@@ -236,7 +236,7 @@ void DMXoutSetup(int channels)
#endif #endif
#if defined(__ESP__) #if defined(ESP8266)
dmxout.init(channels); dmxout.init(channels);
#endif #endif

View File

@@ -38,7 +38,7 @@ e-mail anklimov@gmail.com
#define DmxWrite DmxSimple.write #define DmxWrite DmxSimple.write
#endif #endif
#if defined(__ESP__) #if defined(ESP8266)
#include <ESPDMX.h> #include <ESPDMX.h>
extern DMXESPSerial dmxout; extern DMXESPSerial dmxout;
#define DmxWrite dmxout.write #define DmxWrite dmxout.write

View File

@@ -33,6 +33,14 @@ extern PubSubClient mqttClient;
static volatile long encoder_value[6]; static volatile long encoder_value[6];
#endif #endif
#if defined(ESP8266)
static volatile long encoder_value[6];
#endif
#if defined(ARDUINO_ARCH_ESP32)
static volatile long encoder_value[6];
#endif
#if defined(__SAM3X8E__) #if defined(__SAM3X8E__)
static short encoder_irq_map[54]; static short encoder_irq_map[54];
static long encoder_value[54]; static long encoder_value[54];
@@ -216,7 +224,7 @@ void Input::dht22Poll() {
} }
void Input::printFloatValueToStr(float temp, char *valstr) { void Input::printFloatValueToStr(float temp, char *valstr) {
#if defined(__ESP__) #if defined(ESP8266)
sprintf(valstr, "%2.1f", temp); sprintf(valstr, "%2.1f", temp);
#endif #endif
#if defined(__AVR__) #if defined(__AVR__)

View File

@@ -186,7 +186,7 @@ void Item::copyPar (aJsonObject *itemV)
} }
*/ */
#ifdef ESP32 #if defined(ARDUINO_ARCH_ESP32)
void analogWrite(int pin, int val) void analogWrite(int pin, int val)
{ {
//TBD //TBD
@@ -218,6 +218,7 @@ int Item::Ctrl(char * payload, boolean send){
case -1: //Not known command case -1: //Not known command
case -2: //JSON input (not implemented yet case -2: //JSON input (not implemented yet
break; break;
#if not defined(ARDUINO_ARCH_ESP32) and not defined(ESP8266)
case -3: //RGB color in #RRGGBB notation case -3: //RGB color in #RRGGBB notation
{ {
CRGB rgb; CRGB rgb;
@@ -231,6 +232,7 @@ int Item::Ctrl(char * payload, boolean send){
} }
break; break;
} }
#endif
case CMD_ON: case CMD_ON:
// if (item.getEnableCMD(500) || lanStatus == 4) // if (item.getEnableCMD(500) || lanStatus == 4)

View File

@@ -77,12 +77,20 @@ EthernetClient ethClient;
EthernetClient ethClient; EthernetClient ethClient;
#endif #endif
#ifdef __ESP__ #ifdef ESP8266
#include <ESP8266WiFi.h> #include <ESP8266WiFi.h>
#include <user_interface.h> #include <user_interface.h>
WiFiClient ethClient; WiFiClient ethClient;
#endif #endif
#ifdef ARDUINO_ARCH_ESP32
#include <WiFiClient.h>
#include <WiFi.h>
#include <HTTPClient.h>
#include <EEPROM.h>
WiFiClient ethClient;
#endif
lan_status lanStatus = INITIAL_STATE; lan_status lanStatus = INITIAL_STATE;
const char outprefix[] PROGMEM = OUTTOPIC; const char outprefix[] PROGMEM = OUTTOPIC;
@@ -270,7 +278,7 @@ lan_status lanLoop() {
{ {
#ifndef __ESP__ #if defined(__AVR__) || defined(__SAM3X8E__)
wdt_dis(); wdt_dis();
if (lanStatus > 0) if (lanStatus > 0)
switch (Ethernet.maintain()) { switch (Ethernet.maintain()) {
@@ -395,8 +403,7 @@ void ip_ready_config_loaded_connecting_to_broker() {
} }
void onInitialStateInitLAN() { void onInitialStateInitLAN() {
#ifdef __ESP__ #if defined(ESP8266) and defined(WIFI_MANAGER_DISABLE)
#ifdef WIFI_MANAGER_DISABLE
if(!wifiInitialized) { if(!wifiInitialized) {
WiFi.mode(WIFI_STA); WiFi.mode(WIFI_STA);
Serial.print(F("WIFI AP/Password:")); Serial.print(F("WIFI AP/Password:"));
@@ -408,15 +415,40 @@ void onInitialStateInitLAN() {
wifiInitialized = true; wifiInitialized = true;
} }
#endif #endif
if (WiFi.status() == WL_CONNECTED) {
Serial.println("WiFi connected"); #ifdef ARDUINO_ARCH_ESP32
Serial.println("IP address: "); if(!wifiInitialized) {
Serial.println(WiFi.localIP()); WiFi.mode(WIFI_STA);
lanStatus=HAVE_IP_ADDRESS;//1; WiFi.disconnect();
Serial.print(F("WIFI AP/Password:"));
Serial.print(QUOTE(ESP_WIFI_AP));
Serial.print(F("/"));
Serial.println(QUOTE(ESP_WIFI_PWD));
WiFi.begin(QUOTE(ESP_WIFI_AP), QUOTE(ESP_WIFI_PWD));
int wifi_connection_wait = 10000;
while (WiFi.status() != WL_CONNECTED && wifi_connection_wait > 0) {
delay(500);
wifi_connection_wait -= 500;
Serial.print(".");
}
wifiInitialized = true;
} }
#endif #endif
#if not defined(__ESP__) #if defined(ARDUINO_ARCH_ESP32) || defined(ESP8266)
if (WiFi.status() == WL_CONNECTED) {
Serial.print(F("WiFi connected. IP address: "));
Serial.println(WiFi.localIP());
lanStatus = HAVE_IP_ADDRESS;//1;
} else
{
Serial.println(F("Problem with WiFi connected"));
nextLanCheckTime = millis() + DHCP_RETRY_INTERVAL/5;
}
#endif
#if defined(__AVR__) || defined(__SAM3X8E__)
IPAddress ip, dns, gw, mask; IPAddress ip, dns, gw, mask;
int res = 1; int res = 1;
Serial.println(F("Starting lan")); Serial.println(F("Starting lan"));
@@ -956,7 +988,7 @@ lan_status getConfig(int arg_cnt, char **args)
return READ_RE_CONFIG;//-11; //Load from NVRAM return READ_RE_CONFIG;//-11; //Load from NVRAM
} }
#endif #endif
#if defined(__ESP__) #if defined(ARDUINO_ARCH_ESP32) || defined(ESP8266)
HTTPClient httpClient; HTTPClient httpClient;
String fullURI = "http://"; String fullURI = "http://";
fullURI+=configServer; fullURI+=configServer;
@@ -1047,7 +1079,7 @@ void setup_main() {
ArtnetSetup(); ArtnetSetup();
#endif #endif
#if defined(__ESP__) and not defined(WIFI_MANAGER_DISABLE) #if defined(ESP8266) and not defined(WIFI_MANAGER_DISABLE)
WiFiManager wifiManager; WiFiManager wifiManager;
#if defined(ESP_WIFI_AP) and defined(ESP_WIFI_PWD) #if defined(ESP_WIFI_AP) and defined(ESP_WIFI_PWD)
wifiManager.autoConnect(QUOTE(ESP_WIFI_AP), QUOTE(ESP_WIFI_PWD)); wifiManager.autoConnect(QUOTE(ESP_WIFI_AP), QUOTE(ESP_WIFI_PWD));
@@ -1060,6 +1092,10 @@ void setup_main() {
//TODO: checkForRemoteSketchUpdate(); //TODO: checkForRemoteSketchUpdate();
} }
#ifdef MMMMMM
errro!!!
#endif
void printFirmwareVersionAndBuildOptions() { void printFirmwareVersionAndBuildOptions() {
Serial.print(F("\nLazyhome.ru LightHub controller ")); Serial.print(F("\nLazyhome.ru LightHub controller "));
Serial.println(F(QUOTE(PIO_SRC_REV))); Serial.println(F(QUOTE(PIO_SRC_REV)));

View File

@@ -14,18 +14,24 @@
#define DHCP_RETRY_INTERVAL 60000 #define DHCP_RETRY_INTERVAL 60000
#endif #endif
#if defined(__AVR__) #if defined(ESP8266)
#define wdt_en() wdt_enable(WDTO_8S) #define wdt_en() wdt_enable(WDTO_8S)
#define wdt_dis() wdt_disable() #define wdt_dis() wdt_disable()
#define wdt_res() wdt_reset() #define wdt_res() wdt_reset()
#endif #endif
#if defined(__ESP__) #ifdef ARDUINO_ARCH_ESP32
#define wdt_res() #define wdt_res()
#define wdt_en() #define wdt_en()
#define wdt_dis() #define wdt_dis()
#endif #endif
//#if defined(ESP8266)
//#define wdt_res()
//#define wdt_en()
//#define wdt_dis()
//#endif
#if defined(WATCH_DOG_TICKER_DISABLE) && defined(__AVR__) #if defined(WATCH_DOG_TICKER_DISABLE) && defined(__AVR__)
#define wdt_en() wdt_disable() #define wdt_en() wdt_disable()
#define wdt_dis() wdt_disable() #define wdt_dis() wdt_disable()
@@ -63,16 +69,13 @@
#include <EEPROM.h> #include <EEPROM.h>
#endif #endif
#if defined(__ESP__) #if defined(ESP8266)
#include <FS.h> //this needs to be first, or it all crashes and burns... #include <FS.h> //this needs to be first, or it all crashes and burns...
#include <EEPROM.h> #include <EEPROM.h>
#include <ESP8266HTTPClient.h> #include <ESP8266HTTPClient.h>
#ifndef WIFI_MANAGER_DISABLE
#include <WiFiManager.h> #include <WiFiManager.h>
#include <DNSServer.h> #include <DNSServer.h>
#include <ESP8266WebServer.h> #include <ESP8266WebServer.h>
#endif
#endif #endif
@@ -88,11 +91,19 @@
#endif #endif
#if defined(__AVR__) || defined(__SAM3X8E__) || defined(ESP8266)
#ifdef Wiz5500 #ifdef Wiz5500
#include <Ethernet2.h> #include <Ethernet2.h>
#else #else
#include <Ethernet.h> #include <Ethernet.h>
#endif #endif
#endif
#ifdef ARDUINO_ARCH_ESP32
#include <SPI.h>
#include <Ethernet3.h>
#endif
#ifdef _artnet #ifdef _artnet
#include <Artnet.h> #include <Artnet.h>
@@ -122,12 +133,9 @@ enum lan_status {
void mqttCallback(char *topic, byte *payload, unsigned int length); void mqttCallback(char *topic, byte *payload, unsigned int length);
//#ifndef __ESP__
void printIPAddress(IPAddress ipAddress); void printIPAddress(IPAddress ipAddress);
//#endif
void printMACAddress(); void printMACAddress();
void restoreState(); void restoreState();

View File

@@ -95,10 +95,6 @@
#define LAN_INIT_DELAY 500 #define LAN_INIT_DELAY 500
#endif #endif
#if defined(ESP8266)
#define __ESP__
#endif
#if defined(__AVR__) #if defined(__AVR__)
//All options available //All options available
#ifdef CONTROLLINO #ifdef CONTROLLINO
@@ -116,7 +112,7 @@
#define dmxin DmxDue1 #define dmxin DmxDue1
#endif #endif
#if defined(__ESP__) #if defined(ESP8266)
#undef _dmxin #undef _dmxin
#undef _modbus #undef _modbus
#ifndef DMX_DISABLE #ifndef DMX_DISABLE

View File

@@ -80,7 +80,7 @@ int getInt(char **chan) {
} }
#if defined(ESP8266) #if defined(ARDUINO_ARCH_ESP32) || defined(ESP8266)
unsigned long freeRam () unsigned long freeRam ()
{return system_get_free_heap_size();} {return system_get_free_heap_size();}
#endif #endif

View File

@@ -1,32 +0,0 @@
# from time import time
#
# from SCons.Script import DefaultEnvironment
#
# print("==============================================Custom build flags are:=====================================================")
# #FLAGS="-MY_CONFIG_SERVER=192.168.10.110"
# #FLAGS+=" -WATCH_DOG_TICKER_DISABLE"
# #FLAGS+=" -USE_1W_PIN=12"
# #FLAGS+=" -SD_CARD_INSERTED"
# #FLAGS+=" -SERIAL_BAUD=115200"
# #FLAGS+=" -Wiz5500"
# #FLAGS+=" -DISABLE_FREERAM_PRINT"
# #FLAGS+=" -CUSTOM_FIRMWARE_MAC=C4:3E:1f:03:1B:1B"
# #FLAGS+=" -DMX_DISABLE"
# FLAGS="MODBUS_DISABLE"
# #FLAGS+=" -OWIRE_DISABLE"
# #FLAGS+=" -ARTNET_ENABLE"
# #FLAGS+=" -CONTROLLINO"
# #FLAGS+=" -AVR_DMXOUT_PIN=18"
#
# print(FLAGS)
# print("==============================================Custom build flags END=====================================================")
#
# env = DefaultEnvironment()
# env.Append(CPPDEFINES=['MODBUS_DISABLE=1'])
from time import time
from SCons.Script import DefaultEnvironment
env = DefaultEnvironment()
env.Append(CPPDEFINES=['BUILD_TIMESTAMP=%d' % time()])

View File

@@ -14,19 +14,68 @@ env_default =
; megaatmega2560-net ; megaatmega2560-net
; due ; due
; esp8266 ; esp8266
; esp32
; megaatmega2560-5500 ; megaatmega2560-5500
; due-5500 ; due-5500
; controllino ; controllino
; stm32f407
build_dir = /tmp/pioenvs build_dir = /tmp/pioenvs
libdeps_dir = /tmp/piolibdeps libdeps_dir = /tmp/piolibdeps
[env:esp32]
platform = espressif32
framework = arduino
board = pico32
lib_ldf_mode = chain+
build_flags = !sh build_flags_esp32.sh
lib_deps =
https://github.com/anklimov/Arduino-Temperature-Control-Library.git
https://github.com/anklimov/DS2482_OneWire
ESP8266HTTPClient
Ethernet3
https://github.com/anklimov/aJson
https://github.com/anklimov/CmdArduino
https://github.com/anklimov/ModbusMaster
https://github.com/knolleary/pubsubclient.git
https://github.com/anklimov/Artnet.git
FastLED
Adafruit Unified Sensor
DHT sensor library for ESPx
DHT sensor library
[env:stm32f407]
platform = ststm32
framework = arduino
board = genericSTM32F407VET6
;lib_ldf_mode = chain+
build_flags = !sh build_flags_stm32f407.sh
lib_deps =
https://github.com/sebnil/DueFlashStorage
https://github.com/anklimov/Arduino-Temperature-Control-Library.git
https://github.com/anklimov/DS2482_OneWire
https://github.com/anklimov/DmxDue
https://github.com/anklimov/ArduinoHttpClient
https://github.com/anklimov/aJson
https://github.com/anklimov/CmdArduino
https://github.com/anklimov/ModbusMaster
https://github.com/anklimov/Ethernet
https://github.com/anklimov/Ethernet2
https://github.com/knolleary/pubsubclient.git
https://github.com/anklimov/Artnet.git
; FastLED
SD
SdFat
Adafruit Unified Sensor
DHT sensor library
[env:due] [env:due]
platform = atmelsam platform = atmelsam
framework = arduino framework = arduino
board = due board = due
lib_ldf_mode = chain+ lib_ldf_mode = chain+
extra_scripts = pre:my_build_flags.py build_flags = !sh build_flags_due.sh
build_flags = !echo -n "-DPIO_SRC_REV="$(git log --pretty=format:%h_%ad -1 --date=short)
lib_deps = lib_deps =
https://github.com/sebnil/DueFlashStorage https://github.com/sebnil/DueFlashStorage
https://github.com/anklimov/Arduino-Temperature-Control-Library.git https://github.com/anklimov/Arduino-Temperature-Control-Library.git
@@ -52,7 +101,7 @@ platform = atmelavr
board = megaatmega2560 board = megaatmega2560
framework = arduino framework = arduino
;lib_ldf_mode = chain+ ;lib_ldf_mode = chain+
build_flags = !echo -n "-DPIO_SRC_REV="$(git log --pretty=format:%h_%ad -1 --date=short) build_flags = !sh build_flags_mega2560.sh
lib_deps = lib_deps =
https://github.com/anklimov/Arduino-Temperature-Control-Library.git https://github.com/anklimov/Arduino-Temperature-Control-Library.git
https://github.com/anklimov/DS2482_OneWire https://github.com/anklimov/DS2482_OneWire
@@ -77,8 +126,7 @@ platform = espressif8266
framework = arduino framework = arduino
board = nodemcuv2 board = nodemcuv2
lib_ldf_mode = chain+ lib_ldf_mode = chain+
build_flags = !echo -n "-DMODBUS_DISABLE -DPIO_SRC_REV="$(git log --pretty=format:%h_%ad -1 --date=short) build_flags = !sh build_flags_esp8266.sh
;extra_scripts = pre:my_build_flags.py
lib_deps = lib_deps =
https://github.com/anklimov/Arduino-Temperature-Control-Library.git https://github.com/anklimov/Arduino-Temperature-Control-Library.git
https://github.com/anklimov/DS2482_OneWire https://github.com/anklimov/DS2482_OneWire
@@ -95,14 +143,13 @@ lib_deps =
DHT sensor library DHT sensor library
WifiManager WifiManager
[env:megaatmega2560-net] [env:megaatmega2560-net]
platform = atmelavr platform = atmelavr
board = megaatmega2560 board = megaatmega2560
framework = arduino framework = arduino
upload_port = net:192.168.88.2:23000 upload_port = net:192.168.88.2:23000
build_flags = !sh build_flags_mega2560-net.sh
;lib_ldf_mode = chain+ ;lib_ldf_mode = chain+
build_flags = !echo -n "-DPIO_SRC_REV="$(git rev-parse --short HEAD)
lib_deps = lib_deps =
https://github.com/anklimov/Arduino-Temperature-Control-Library.git https://github.com/anklimov/Arduino-Temperature-Control-Library.git
https://github.com/anklimov/DS2482_OneWire https://github.com/anklimov/DS2482_OneWire
@@ -124,9 +171,7 @@ lib_deps =
platform = atmelsam platform = atmelsam
framework = arduino framework = arduino
board = due board = due
lib_ldf_mode = chain+ ;lib_ldf_mode = chain+
extra_scripts = pre:my_build_flags.py
build_flags = !echo -n "-DPIO_SRC_REV="$(git log --pretty=format:%h_%ad -1 --date=short)
build_flags = -D Wiz5500 -D ARTNET_ENABLE build_flags = -D Wiz5500 -D ARTNET_ENABLE
lib_deps = lib_deps =
https://github.com/sebnil/DueFlashStorage https://github.com/sebnil/DueFlashStorage

2
prepareDue.sh Executable file
View File

@@ -0,0 +1,2 @@
#!/usr/bin/env bash
sed -i -- 's/void USART0_Handler(void)/void USART0_Handler(void ) __attribute__((weak));\nvoid USART0_Handler(void )/g' ~/.platformio/packages/framework-arduinosam/variants/arduino_due_x/variant.cpp