Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions _Boards/esp32s3.board.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"$schema": "./mfboard.schema.json",
"UsbDriveSettings": {},
"Connection": {
"ConnectionDelay": 1000,
"DelayAfterFirmwareUpdate": 1000,
"DtrEnable": true,
"EEPROMSize": 2048,
"ExtraConnectionRetry": false,
"ForceResetOnFirmwareUpdate": true,
"MessageSize": 90
},
"HardwareIds": ["^VID_303A&PID_1001"],
"Info": {
"CanInstallFirmware": true,
"CanResetBoard": true,
"FirmwareBaseName": "mobiflight_esp32s3",
"FirmwareExtension": "bin",
"FriendlyName": "Heltec Wireless Stick V3",
"LatestFirmwareVersion": "0.0.1",
"MobiFlightType": "MobiFlight ESP32-S3",
"ResetFirmwareFile": ""
},
"ModuleLimits": {
"MaxAnalogInputs": 4,
"MaxInputShifters": 4,
"MaxButtons": 20,
"MaxEncoders": 10,
"MaxLcdI2C": 2,
"MaxLedSegments": 6,
"MaxOutputs": 20,
"MaxServos": 6,
"MaxShifters": 4,
"MaxSteppers": 4,
"MaxInputMultiplexer": 4,
"MaxCustomDevices": 0
},
"Pins": [
{ "isAnalog": true, "isI2C": false, "isPWM": true, "Pin": 1 },
{ "isAnalog": true, "isI2C": false, "isPWM": true, "Pin": 2 },
{ "isAnalog": true, "isI2C": false, "isPWM": true, "Pin": 3 },
{ "isAnalog": true, "isI2C": false, "isPWM": true, "Pin": 4 },
{ "isAnalog": false, "isI2C": false, "isPWM": true, "Pin": 5 },
{ "isAnalog": false, "isI2C": false, "isPWM": true, "Pin": 6 },
{ "isAnalog": false, "isI2C": false, "isPWM": true, "Pin": 7 },
{ "isAnalog": false, "isI2C": false, "isPWM": true, "Pin": 8 },
{ "isAnalog": false, "isI2C": false, "isPWM": true, "Pin": 9 },
{ "isAnalog": false, "isI2C": false, "isPWM": true, "Pin": 10 },
{ "isAnalog": false, "isI2C": false, "isPWM": true, "Pin": 11 },
{ "isAnalog": false, "isI2C": false, "isPWM": true, "Pin": 12 },
{ "isAnalog": false, "isI2C": false, "isPWM": true, "Pin": 13 },
{ "isAnalog": false, "isI2C": false, "isPWM": true, "Pin": 14 },
{ "isAnalog": false, "isI2C": false, "isPWM": true, "Pin": 21 },
{ "isAnalog": false, "isI2C": false, "isPWM": true, "Pin": 33 },
{ "isAnalog": false, "isI2C": false, "isPWM": true, "Pin": 34 },
{ "isAnalog": false, "isI2C": false, "isPWM": true, "Pin": 35 },
{ "isAnalog": false, "isI2C": false, "isPWM": true, "Pin": 36 },
{ "isAnalog": false, "isI2C": false, "isPWM": true, "Pin": 37 },
{ "isAnalog": false, "isI2C": true, "isPWM": true, "Pin": 41 },
{ "isAnalog": false, "isI2C": true, "isPWM": true, "Pin": 42 }
]
}
6 changes: 5 additions & 1 deletion copy_fw_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ def copy_fw_files (source, target, env):
if os.path.exists(build_path_json) == False:
os.makedirs(build_path_json)

# Only convert bin to uf2 for Raspberry Pi Pico boards
if fw_file_name[-3:] == "bin":
fw_file_name=fw_file_name[0:-3] + "uf2"
# Check if this is a Pico board by looking at the environment name
env_name = env.get('PIOENV', '')
if 'pico' in env_name.lower():
fw_file_name=fw_file_name[0:-3] + "uf2"

# Copy build FW file
shutil.copy(fw_file_name, build_path_fw)
Expand Down
57 changes: 39 additions & 18 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@

; Common build settings across all devices
[env]
lib_deps =
lib_deps =
waspinator/AccelStepper @ 1.61
https://github.com/MobiFlight/LiquidCrystal_I2C#v1.1.5
https://github.com/miathedev/LiquidCrystal_I2C.git#master
https://github.com/MobiFlight/Arduino-CmdMessenger#4.2.2
custom_lib_deps_Atmel =
arduino-libraries/Servo @ 1.1.8
Expand Down Expand Up @@ -70,7 +70,7 @@ extra_scripts =
platform = atmelavr
board = megaatmega2560
framework = arduino
build_flags =
build_flags =
${env.build_flags}
'-DMOBIFLIGHT_TYPE="MobiFlight Mega"'
'-DMOBIFLIGHT_NAME="MobiFlight Mega"'
Expand All @@ -79,21 +79,21 @@ build_flags =
-DMF_MAX_DEVICEMEM=1600 ; max. memory size for devices
build_unflags =
;-DMF_STEPPER_SUPPORT ; this is just an example how to deactivate a device
build_src_filter =
build_src_filter =
${env.build_src_filter}
lib_deps =
lib_deps =
${env.lib_deps}
${env.custom_lib_deps_Atmel}
monitor_speed = 115200
extra_scripts =
extra_scripts =
${env.extra_scripts}

; Build settings for the Arduino Pro Micro
[env:mobiflight_micro]
platform = atmelavr
board = sparkfun_promicro16
framework = arduino
build_flags =
build_flags =
${env.build_flags}
'-DMOBIFLIGHT_TYPE="MobiFlight Micro"'
'-DMOBIFLIGHT_NAME="MobiFlight Micro"'
Expand All @@ -102,13 +102,13 @@ build_flags =
-DMF_MAX_DEVICEMEM=470 ; max. memory size for devices
build_unflags =
;-DMF_STEPPER_SUPPORT ; this is just an example how to deactivate a device
build_src_filter =
build_src_filter =
${env.build_src_filter}
lib_deps =
lib_deps =
${env.lib_deps}
${env.custom_lib_deps_Atmel}
monitor_speed = 115200
extra_scripts =
extra_scripts =
${env.extra_scripts}


Expand All @@ -117,7 +117,7 @@ extra_scripts =
platform = atmelavr
board = uno
framework = arduino
build_flags =
build_flags =
${env.build_flags}
'-DMOBIFLIGHT_TYPE="MobiFlight Uno"'
'-DMOBIFLIGHT_NAME="MobiFlight Uno"'
Expand All @@ -126,21 +126,21 @@ build_flags =
-DMF_MAX_DEVICEMEM=420 ; max. memory size for devices
build_unflags =
;-DMF_STEPPER_SUPPORT ; this is just an example how to deactivate a device
build_src_filter =
build_src_filter =
${env.build_src_filter}
lib_deps =
lib_deps =
${env.lib_deps}
${env.custom_lib_deps_Atmel}
monitor_speed = 115200
extra_scripts =
extra_scripts =
${env.extra_scripts}

; Build settings for the Arduino Nano
[env:mobiflight_nano]
platform = atmelavr
board = nanoatmega328
framework = arduino
build_flags =
build_flags =
${env.build_flags}
'-DMOBIFLIGHT_TYPE="MobiFlight Nano"'
'-DMOBIFLIGHT_NAME="MobiFlight Nano"'
Expand All @@ -150,13 +150,13 @@ build_flags =
-I./_Boards/Atmel/Board_Nano
build_unflags =
;-DMF_STEPPER_SUPPORT ; this is just an example how to deactivate a device
build_src_filter =
build_src_filter =
${env.build_src_filter}
lib_deps =
${env.lib_deps}
${env.custom_lib_deps_Atmel}
monitor_speed = 115200
extra_scripts =
extra_scripts =
${env.extra_scripts}

; Build settings for the Raspberry Pico original
Expand Down Expand Up @@ -185,5 +185,26 @@ lib_deps =
${env.lib_deps}
${env.custom_lib_deps_Pico}
monitor_speed = 115200
extra_scripts =
extra_scripts =
${env.extra_scripts}

; Build settings for the ESP32-S3
[env:mobiflight_esp32s3]
platform = espressif32
board = heltec_wifi_lora_32_V3
framework = arduino
build_flags =
${env.build_flags}
'-DMOBIFLIGHT_TYPE="MobiFlight ESP32-S3"'
'-DMOBIFLIGHT_NAME="MobiFlight ESP32-S3"'
-DMEMLEN_CONFIG=2048
-DMEMLEN_NAMES_BUFFER=1500
-DMF_MAX_DEVICEMEM=2048
build_src_filter =
${env.build_src_filter}
lib_deps =
${env.lib_deps}
ESP32Servo
monitor_speed = 115200
extra_scripts =
${env.extra_scripts}
34 changes: 30 additions & 4 deletions src/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@
#include "Button.h"
#include "Encoder.h"
#include "Output.h"

#if !defined(ARDUINO_ARCH_AVR)
#if defined(ARDUINO_ARCH_ESP32)
#include <esp_system.h>
#else
#include "ArduinoUniqueID.h"
#endif
#endif

#ifdef MF_ANALOG_SUPPORT
#include "Analog.h"
Expand Down Expand Up @@ -69,8 +74,11 @@ const uint8_t MEM_OFFSET_SERIAL = MEM_OFFSET_NAME + MEM_LEN_NAME;
const uint8_t MEM_LEN_SERIAL = 11;
const uint8_t MEM_OFFSET_CONFIG = MEM_OFFSET_NAME + MEM_LEN_NAME + MEM_LEN_SERIAL;

// Serial buffer for AVR and ESP32/other
#ifdef ARDUINO_ARCH_AVR
char serial[11]; // 3 characters for "SN-",7 characters for "xyz-zyx" plus terminating NULL
#elif defined(ARDUINO_ARCH_ESP32)
char serial[3 + 12 * 2 + 1]; // 3 for "SN-", 12 bytes MAC/ChipID as HEX, null term
#else
char serial[3 + UniqueIDsize * 2 + 1]; // 3 characters for "SN-", UniqueID as HEX String, terminating NULL
#endif
Expand All @@ -81,7 +89,7 @@ uint16_t configLengthEEPROM = 0;
boolean configActivated = false;
uint16_t pNameBuffer = 0; // pointer for nameBuffer during reading of config
const uint16_t configLengthFlash = sizeof(CustomDeviceConfig);
bool boardReady = false;
bool boardReady = false;

void resetConfig();
void readConfig();
Expand Down Expand Up @@ -518,10 +526,10 @@ void readConfigFromMemory(bool configFromFlash)
#ifdef MF_ANALOG_SUPPORT
case kTypeAnalogInputDeprecated:
case kTypeAnalogInput:
params[0] = readUint(&addrMem, configFromFlash); // pin number
params[1] = readUint(&addrMem, configFromFlash); // sensitivity
params[0] = readUint(&addrMem, configFromFlash); // pin number
params[1] = readUint(&addrMem, configFromFlash); // sensitivity
if (command == kTypeAnalogInputDeprecated)
Analog::Add(params[0], &nameBuffer[pNameBuffer], params[1], true); // MUST be before readName because readName returns the pointer for the NEXT Name
Analog::Add(params[0], &nameBuffer[pNameBuffer], params[1], true); // MUST be before readName because readName returns the pointer for the NEXT Name
else
Analog::Add(params[0], &nameBuffer[pNameBuffer], params[1], false); // MUST be before readName because readName returns the pointer for the NEXT Name
copy_success = readName(&addrMem, nameBuffer, &pNameBuffer, configFromFlash); // copy the NULL terminated name to to nameBuffer and set to next free memory location
Expand Down Expand Up @@ -679,6 +687,23 @@ void generateRandomSerial()
#endif

#if !defined(ARDUINO_ARCH_AVR)
#if defined(ARDUINO_ARCH_ESP32)
void readUniqueSerial()
{
serial[0] = 'S';
serial[1] = 'N';
serial[2] = '-';
uint8_t chipid[6];
esp_efuse_mac_get_default(chipid);
for (int i = 0; i < 6; ++i) {
serial[3 + i * 2] = ((chipid[i] >> 4) & 0x0F) + 48;
if (serial[3 + i * 2] >= 58) serial[3 + i * 2] += 7;
serial[3 + i * 2 + 1] = (chipid[i] & 0x0F) + 48;
if (serial[3 + i * 2 + 1] >= 58) serial[3 + i * 2 + 1] += 7;
}
serial[3 + 6 * 2] = 0x00;
}
#else
void readUniqueSerial()
{
serial[0] = 'S';
Expand All @@ -692,6 +717,7 @@ void readUniqueSerial()
}
}
#endif
#endif

void generateSerial(bool force)
{
Expand Down
5 changes: 4 additions & 1 deletion src/MF_Analog/MFAnalog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ void MFAnalog::attach(uint8_t pin, const char *name, uint8_t sensitivity, bool d
_sensitivity = sensitivity;
_pin = pin;
_name = name;
// Special analog pin handling for some boards
#ifdef ARDUINO_AVR_PROMICRO16
// ProMicro has a special pin assignment for analog pins
// therefore reading from A6 and A7 does not work
Expand All @@ -26,11 +27,13 @@ void MFAnalog::attach(uint8_t pin, const char *name, uint8_t sensitivity, bool d
_pin = A6;
else if (_pin == 6)
_pin = A7;
#elif defined(ARDUINO_ARCH_ESP32)
// ESP32 analog pins are just numbers, but check for deprecated mapping if needed
#endif
// enabling PullUp makes a nonlinear behaviour if pot is used
if (deprecated)
pinMode(_pin, INPUT_PULLUP);

// Fill averaging buffers with initial reading
for (uint8_t i = 0; i < ADC_MAX_AVERAGE; i++) {
readBuffer();
Expand Down
5 changes: 4 additions & 1 deletion src/MF_Output/MFOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ MFOutput::MFOutput()
void MFOutput::attach(uint8_t pin)
{
_pin = pin;
#ifdef ARDUINO_ARCH_RP2040
// Use OUTPUT_12MA for RP2040, OUTPUT for others, allow override for ESP32 if needed
#if defined(ARDUINO_ARCH_RP2040)
pinMode(_pin, OUTPUT_12MA);
#elif defined(ARDUINO_ARCH_ESP32)
pinMode(_pin, OUTPUT);
#else
pinMode(_pin, OUTPUT);
#endif
Expand Down
4 changes: 3 additions & 1 deletion src/MF_Servo/MFServo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ void MFServo::moveTo(int absolute)
if (_targetPos != newValue) {
_targetPos = newValue;
if (!_initialized) {
#ifdef ARDUINO_ARCH_RP2040
#if defined(ARDUINO_ARCH_RP2040)
_servo.attach(_pin, 544, 2400);
#elif defined(ARDUINO_ARCH_ESP32)
_servo.attach(_pin, 500, 2500); // ESP32 typical servo pulse range
#else
_servo.attach(_pin);
#endif
Expand Down
4 changes: 4 additions & 0 deletions src/MF_Servo/MFServo.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
#pragma once

#include <Arduino.h>
#if defined(ESP32) || defined(ARDUINO_ARCH_ESP32)
#include <ESP32Servo.h>
#else
#include <Servo.h>
#endif

class MFServo
{
Expand Down
5 changes: 3 additions & 2 deletions src/allocateMem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@
#include "allocateMem.h"
#include "commandmessenger.h"

#ifdef ARDUINO_ARCH_AVR
#if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_ESP32)
uint8_t deviceBuffer[MF_MAX_DEVICEMEM] = {0};
#else
std::size_t deviceBuffer[MF_MAX_DEVICEMEM] = {0};
#endif

uint16_t nextPointer = 0;

#ifdef ARDUINO_ARCH_AVR
// For ESP32 and AVR, use uint8_t* for compatibility
#if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_ESP32)
uint8_t *allocateMemory(uint16_t size)
#else
std::size_t *allocateMemory(uint16_t size)
Expand Down
2 changes: 1 addition & 1 deletion src/allocateMem.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <Arduino.h>
#include <new>

#ifdef ARDUINO_ARCH_AVR
#if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_ESP32)
uint8_t *allocateMemory(uint16_t size);
#else
std::size_t *allocateMemory(uint16_t size);
Expand Down