Port to esp32

This commit is contained in:
GHOSCHT 2022-04-09 21:31:18 +02:00
parent c43e0d926a
commit e8d042091e
5 changed files with 41 additions and 87 deletions

View file

@ -1,7 +1,10 @@
{ {
// See http://go.microsoft.com/fwlink/?LinkId=827846 // See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format // for the documentation about the extensions.json format
"recommendations": [ "recommendations": [
"platformio.platformio-ide" "platformio.platformio-ide"
] ],
} "unwantedRecommendations": [
"ms-vscode.cpptools-extension-pack"
]
}

View file

@ -2,6 +2,7 @@
#include <string.h> #include <string.h>
#include <Arduino.h> #include <Arduino.h>
#include <EEPROM.h> #include <EEPROM.h>
#include <analogWrite.h>
LightController::LightController(const int bjtPins[], __SIZE_TYPE__ bjtCount) LightController::LightController(const int bjtPins[], __SIZE_TYPE__ bjtCount)
{ {
@ -112,7 +113,7 @@ int LightController::clampState(int stateValue)
void LightController::commitState(int index) void LightController::commitState(int index)
{ {
commitPinState(index); commitPinState(index);
EEPROM.update(index, bjtState[index]); EEPROM.write(index, bjtState[index]);
} }
void LightController::commitPinState(int index) void LightController::commitPinState(int index)

View file

@ -0,0 +1,10 @@
#define LEDR 16
#define LEDG 17
#define LEDB 18
#define EXTDTR 22
#define EXTRTS 23
#define MUX 27
#define SIG1A 32
#define SIG1B 33
#define SIG2A 34
#define SIG2B 35

View file

@ -1,77 +1,20 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[platformio] [platformio]
default_envs = Upload_UART ; Default build target default_envs = Upload_UART
; Common settings for all environments
[env]
platform = atmelavr
framework = arduino
; TARGET SETTINGS
; Chip in use
board = ATmega328P
; Clock frequency in [Hz]
board_build.f_cpu = 16000000L
; BUILD OPTIONS
; Comment out to enable LTO (this line unflags it)
build_unflags = -flto
; Extra build flags
build_flags =
; SERIAL MONITOR OPTIONS
; Serial monitor port defined in the Upload_UART environment
monitor_port = ${env:Upload_UART.upload_port}
; Serial monitor baud rate
monitor_speed = 9600
; Run the following command to upload with this environment
; pio run -e Upload_UART -t upload
[env:Upload_UART] [env:Upload_UART]
; Serial bootloader protocol platform = espressif32
upload_protocol = custom board = az-delivery-devkit-v4
; Serial upload port framework = arduino
upload_port = COM5 upload_port = COM8
; Get upload baud rate defined in the fuses_bootloader environment monitor_port = COM8
board_upload.speed = ${env:fuses_bootloader.board_bootloader.speed} lib_deps = erropix/ESP32 AnalogWrite@^0.2
upload_flags =
-C$PROJECT_PACKAGES_DIR/tool-avrdude/avrdude.conf
-p$BOARD_MCU
-P${env:Upload_UART.upload_port}
-carduino
-v
-V
-D
upload_command = python enableReset.py ${env:Upload_UART.upload_port} && avrdude $UPLOAD_FLAGS -U flash:w:$SOURCE:i
; Run the following command to upload with this environment
; pio run -e Upload_ISP -t upload
[env:Upload_ISP]
; Custom upload procedure
upload_protocol = custom
; Avrdude upload flags
upload_flags =
-C$PROJECT_PACKAGES_DIR/tool-avrdude/avrdude.conf
-p$BOARD_MCU
-PUSB
-cusbasp
-D
; Avrdude upload command
upload_command = avrdude $UPLOAD_FLAGS -U flash:w:$SOURCE:i
; Run the following command to set fuses
; pio run -e fuses_bootloader -t fuses
; Run the following command to set fuses + burn bootloader
; pio run -e fuses_bootloader -t bootloader
[env:fuses_bootloader]
board_hardware.oscillator = external ; Oscillator type
board_hardware.uart = uart0 ; Set UART to use for serial upload
board_bootloader.speed = 115200 ; Set bootloader baud rate
board_hardware.bod = 2.7v ; Set brown-out detection
board_hardware.eesave = yes ; Preserve EEPROM when uploading using programmer
upload_protocol = usbasp ; Use the USBasp as programmer
upload_flags = ; Select USB as upload port and divide the SPI clock by 8
-PUSB
-B8

View file

@ -2,26 +2,23 @@
#include <LightController.h> #include <LightController.h>
#include <SerialCommunicator.h> #include <SerialCommunicator.h>
#include <I2CCommunicator.h> #include <I2CCommunicator.h>
#include <PinMap.h>
StreamCommunicator *computer; StreamCommunicator *computer;
StreamCommunicator *console;
LightController *light; LightController *light;
const int STEPS = 5; const int STEPS = 5;
void setup() void setup()
{ {
int bjtCount = 4; int bjtCount = 4;
const int bjtPin[bjtCount] = {6, 5, 3, 10}; const int bjtPin[bjtCount] = {SIG1A, SIG1B, SIG2A, SIG2B};
computer = new SerialCommunicator(Serial, 9600, 5, 50); computer = new SerialCommunicator(Serial, 9600, 5, 50);
console = new I2CCommunicator(Wire, 9, 5, 50);
light = new LightController(bjtPin, bjtCount); light = new LightController(bjtPin, bjtCount);
} }
void loop() void loop()
{ {
light->updateState(console->receiveMessage(), STEPS);
light->updateState(computer->receiveMessage(), STEPS); light->updateState(computer->receiveMessage(), STEPS);
computer->sendMessage(light->getBjtState(), light->getBjtCount()); computer->sendMessage(light->getBjtState(), light->getBjtCount());
computer->clearBuffer(); computer->clearBuffer();
console->clearBuffer();
} }