Skip to content

Commit 24f0759

Browse files
authored
Platform lib upgrade (ExpressLRS#1831)
* Upgrade ESP8285 platform and libs * Upgrade platform and libs for ESP32 devices * Wifi fixes after platform upgrade
1 parent 69825cd commit 24f0759

6 files changed

Lines changed: 89 additions & 36 deletions

File tree

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ jobs:
114114
esac
115115
# copy the common ESP32 files
116116
if [[ ${{matrix.target}} == *ESP32* ]] ; then
117-
cp ~/.platformio/packages/framework-arduinoespressif32/tools/sdk/bin/bootloader_dio_40m.bin ~/artifacts/firmware/
117+
cp ~/.platformio/packages/framework-arduinoespressif32/tools/sdk/esp32/bin/bootloader_dio_40m.bin ~/artifacts/firmware/
118118
cp ~/.platformio/packages/framework-arduinoespressif32/tools/partitions/boot_app0.bin ~/artifacts/firmware/
119119
mv .pio/build/${{ matrix.target }}/partitions.bin ~/artifacts/firmware/
120120
fi

src/lib/BLE/devBLE.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ void BluetoothJoystickUpdateValues()
3636

3737
for (uint8_t i = 0; i < 8; i++)
3838
{
39-
data[i] = map(CRSF::ChannelData[i], CRSF_CHANNEL_VALUE_MIN - 1, CRSF_CHANNEL_VALUE_MAX + 1, -32768, 32768);
39+
data[i] = map(CRSF::ChannelData[i], CRSF_CHANNEL_VALUE_MIN, CRSF_CHANNEL_VALUE_MAX, 0, 32767);
4040
}
4141

4242
bleGamepad->setX(data[0]);
@@ -60,8 +60,6 @@ void BluetoothJoystickBegin()
6060

6161
// construct the BLE immediately to prevent reentry from events/timeout
6262
bleGamepad = new BleGamepad("ExpressLRS Joystick", "ELRS", 100);
63-
bleGamepad->setAutoReport(false);
64-
bleGamepad->setControllerType(CONTROLLER_TYPE_GAMEPAD);
6563

6664
hwTimer::updateInterval(5000);
6765
CRSF::setSyncParams(5000); // 200hz
@@ -70,8 +68,15 @@ void BluetoothJoystickBegin()
7068
Radio.End();
7169
CRSF::RCdataCallback = BluetoothJoystickUpdateValues;
7270

71+
BleGamepadConfiguration *gamepadConfig = new BleGamepadConfiguration();
72+
gamepadConfig->setAutoReport(false);
73+
gamepadConfig->setButtonCount(0);
74+
gamepadConfig->setHatSwitchCount(0);
75+
gamepadConfig->setWhichAxes(enableX, enableY, enableZ, enableRX, enableRY, enableRZ, enableSlider1, enableSlider2);
76+
gamepadConfig->setWhichSimulationControls(enableRudder, enableThrottle, enableAccelerator, enableBrake, enableSteering);
77+
7378
DBGLN("Starting BLE Joystick!");
74-
bleGamepad->begin(numOfButtons, numOfHatSwitches, enableX, enableY, enableZ, enableRZ, enableRX, enableRY, enableSlider1, enableSlider2, enableRudder, enableThrottle, enableAccelerator, enableBrake, enableSteering);
79+
bleGamepad->begin(gamepadConfig);
7580
}
7681

7782
static int timeout()

src/lib/CRSF/CRSF.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "helpers.h"
88

99
#if defined(PLATFORM_ESP32)
10+
#include <soc/uart_reg.h>
1011
// UART0 is used since for DupleTX we can connect directly through IO_MUX and not the Matrix
1112
// for better performance, and on other targets (mostly using pin 13), it always uses Matrix
1213
HardwareSerial CRSF::Port(0);

src/lib/VTXSPI/devVTXSPI.cpp

Lines changed: 47 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include "logging.h"
99
#include <SPI.h>
1010
#if defined(PLATFORM_ESP32)
11-
#include <analogWrite.h>
11+
#include <pwmWrite.h>
1212
#endif
1313

1414
#define SYNTHESIZER_REGISTER_A 0x00
@@ -25,15 +25,13 @@
2525

2626
#define POWER_AMP_ON 0b00000100111110111111
2727
#define POWER_AMP_OFF 0x00
28-
#if defined(PLATFORM_ESP32)
29-
// ESP32 DAC pins are 0-4095
30-
#define MIN_PWM 1 // Testing required.
31-
#define MAX_PWM 250 // Absolute max is 4095. But above 250 does nothing.
32-
#else
33-
// ESP8285 PWM is 0-4095
28+
// ESP32 DAC pins are 0-255
29+
#define MIN_DAC 1 // Testing required.
30+
#define MAX_DAC 250 // Absolute max is 255. But above 250 does nothing.
31+
// PWM is 0-4095
3432
#define MIN_PWM 1000 // Testing required.
3533
#define MAX_PWM 3600 // Absolute max is 4095. But above 3500 does nothing.
36-
#endif
34+
3735
#define VPD_BUFFER 5
3836

3937
#define READ_BIT 0x00
@@ -52,6 +50,8 @@ static uint8_t vtxSPIPowerIdxCurrent = 0;
5250
uint8_t vtxSPIPitmode = 1;
5351
static uint8_t RfAmpVrefState = 0;
5452
static uint16_t vtxSPIPWM = MAX_PWM;
53+
static uint16_t vtxMinPWM = MAX_PWM;
54+
static uint16_t vtxMaxPWM = MIN_PWM;
5555
static uint16_t VpdSetPoint = 0;
5656
static uint16_t Vpd = 0;
5757

@@ -77,6 +77,9 @@ static const uint16_t freqTable[48] = {
7777
5333, 5373, 5413, 5453, 5493, 5533, 5573, 5613 // L
7878
};
7979

80+
#if defined(PLATFORM_ESP32)
81+
static Pwm pwm;
82+
#endif
8083
static SPIClass *vtxSPI;
8184
static void rtc6705WriteRegister(uint32_t regData)
8285
{
@@ -147,24 +150,40 @@ static void RfAmpVrefOff()
147150
RfAmpVrefState = 0;
148151
}
149152

153+
static void setPWM()
154+
{
155+
#if defined(PLATFORM_ESP32)
156+
if (GPIO_PIN_RF_AMP_PWM == 25 || GPIO_PIN_RF_AMP_PWM == 26)
157+
{
158+
dacWrite(GPIO_PIN_RF_AMP_PWM, vtxSPIPWM >> 4);
159+
}
160+
else
161+
{
162+
pwm.write(GPIO_PIN_RF_AMP_PWM, vtxSPIPWM);
163+
}
164+
#else
165+
analogWrite(GPIO_PIN_RF_AMP_PWM, vtxSPIPWM);
166+
#endif
167+
}
168+
150169
void VTxOutputMinimum()
151170
{
152171
RfAmpVrefOff();
153172

154-
vtxSPIPWM = MAX_PWM;
155-
analogWrite(GPIO_PIN_RF_AMP_PWM, vtxSPIPWM);
173+
vtxSPIPWM = vtxMaxPWM;
174+
setPWM();
156175
}
157176

158177
static void VTxOutputIncrease()
159178
{
160-
if (vtxSPIPWM > MIN_PWM) vtxSPIPWM -= 1;
161-
analogWrite(GPIO_PIN_RF_AMP_PWM, vtxSPIPWM);
179+
if (vtxSPIPWM > vtxMinPWM) vtxSPIPWM -= 1;
180+
setPWM();
162181
}
163182

164183
static void VTxOutputDecrease()
165184
{
166-
if (vtxSPIPWM < MAX_PWM) vtxSPIPWM += 1;
167-
analogWrite(GPIO_PIN_RF_AMP_PWM, vtxSPIPWM);
185+
if (vtxSPIPWM < vtxMaxPWM) vtxSPIPWM += 1;
186+
setPWM();
168187
}
169188

170189
static uint16_t LinearInterpVpdSetPointArray(const uint16_t VpdSetPointArray[])
@@ -275,11 +294,22 @@ static void initialize()
275294
#if defined(PLATFORM_ESP8266)
276295
pinMode(GPIO_PIN_RF_AMP_PWM, OUTPUT);
277296
analogWriteFreq(10000); // 10kHz
297+
analogWriteResolution(12); // 0 - 4095
278298
#else
279-
analogWriteFrequency(GPIO_PIN_RF_AMP_PWM, 10000); // 10kHz
299+
// If using a DAC pin then adjust min/max and initial value
300+
if (GPIO_PIN_RF_AMP_PWM == 25 || GPIO_PIN_RF_AMP_PWM == 26)
301+
{
302+
vtxMinPWM = MIN_DAC;
303+
vtxMaxPWM = MAX_DAC;
304+
vtxSPIPWM = vtxMaxPWM;
305+
}
306+
else
307+
{
308+
pwm.writeFrequency(GPIO_PIN_RF_AMP_PWM, 10000); // 10kHz
309+
pwm.writeResolution(12); // 0 - 4095
310+
}
280311
#endif
281-
analogWriteResolution(12); // 0 - 4095
282-
analogWrite(GPIO_PIN_RF_AMP_PWM, vtxSPIPWM);
312+
setPWM();
283313

284314
delay(RTC6705_BOOT_DELAY);
285315
}

src/lib/WIFI/devWIFI.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,13 @@ static void HandleWebUpdate()
902902
DBGLN("Changing to AP mode");
903903
WiFi.disconnect();
904904
wifiMode = WIFI_AP;
905+
#if defined(PLATFORM_ESP32)
906+
WiFi.setHostname(wifi_hostname); // hostname must be set before the mode is set to STA
907+
#endif
905908
WiFi.mode(wifiMode);
909+
#if defined(PLATFORM_ESP8266)
910+
WiFi.setHostname(wifi_hostname); // hostname must be set before the mode is set to STA
911+
#endif
906912
changeTime = now;
907913
WiFi.softAPConfig(ipAddress, ipAddress, netMsk);
908914
WiFi.softAP(wifi_ap_ssid, wifi_ap_password);
@@ -911,8 +917,13 @@ static void HandleWebUpdate()
911917
case WIFI_STA:
912918
DBGLN("Connecting to network '%s'", station_ssid);
913919
wifiMode = WIFI_STA;
920+
#if defined(PLATFORM_ESP32)
921+
WiFi.setHostname(wifi_hostname); // hostname must be set before the mode is set to STA
922+
#endif
914923
WiFi.mode(wifiMode);
924+
#if defined(PLATFORM_ESP8266)
915925
WiFi.setHostname(wifi_hostname); // hostname must be set after the mode is set to STA
926+
#endif
916927
changeTime = now;
917928
WiFi.begin(station_ssid, station_password);
918929
startServices();

src/targets/common.ini

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,14 @@ build_flags = -DRADIO_SX128X=1
2525
lib_ignore = SX127xDriver
2626

2727
# ------------------------- COMMON ESP32 DEFINITIONS -----------------
28+
29+
# platform 5.1.0 uses arduino core 2.0.4 which has a "major" problem with
30+
# requiring the QIO bootloader on PICO devices, so upgrading older firmware
31+
# will be problem using OTA, unless we have a mechanism for uploading a new
32+
# bootloader first!
33+
2834
[env_common_esp32]
29-
platform = espressif32@3.4.0
35+
platform = espressif32@5.1.1
3036
board = esp32dev
3137
board_build.partitions = min_spiffs.csv
3238
upload_speed = 460800
@@ -43,20 +49,20 @@ build_flags =
4349
-I ${PROJECTSRC_DIR}/hal
4450
build_src_filter = ${common_env_data.build_src_filter} -<ESP8266*.*> -<STM32*.*>
4551
lib_deps =
46-
makuna/NeoPixelBus @ 2.6.9
47-
ottowinter/ESPAsyncWebServer-esphome @ 2.1.0
48-
lemmingdev/ESP32-BLE-Gamepad @ 0.3.4
49-
h2zero/NimBLE-Arduino @ 1.3.6
52+
makuna/NeoPixelBus @ 2.7.0
53+
ottowinter/ESPAsyncWebServer-esphome @ 3.0.0
54+
lemmingdev/ESP32-BLE-Gamepad @ 0.5.1
55+
h2zero/NimBLE-Arduino @ 1.4.0
5056
bblanchon/ArduinoJson @ 6.19.4
5157
oled_lib_deps =
5258
${env_common_esp32.lib_deps}
53-
olikraus/U8g2 @ 2.32.10
59+
olikraus/U8g2 @ 2.33.15
5460
tft_lib_deps =
5561
${env_common_esp32.lib_deps}
56-
moononournation/GFX Library for Arduino @ 1.2.1
62+
moononournation/GFX Library for Arduino @ 1.2.8
5763

5864
[env_common_esp32rx]
59-
platform = espressif32@3.4.0
65+
platform = espressif32@5.1.1
6066
board = esp32dev
6167
board_build.partitions = min_spiffs.csv
6268
upload_speed = 460800
@@ -74,15 +80,15 @@ build_flags =
7480
-I ${PROJECTSRC_DIR}/hal
7581
build_src_filter = ${common_env_data.build_src_filter} -<ESP8266*.*> -<STM32*.*>
7682
lib_deps =
77-
makuna/NeoPixelBus @ 2.6.9
78-
ottowinter/ESPAsyncWebServer-esphome @ 2.1.0
83+
makuna/NeoPixelBus @ 2.7.0
84+
ottowinter/ESPAsyncWebServer-esphome @ 3.0.0
7985
bblanchon/ArduinoJson @ 6.19.4
8086
roboticsbrno/ServoESP32 @ 1.0.3
81-
dlloydev/ESP32 ESP32S2 AnalogWrite @ 2.0.9
87+
dlloydev/ESP32 ESP32S2 AnalogWrite @ 3.0.3
8288

8389
# ------------------------- COMMON ESP82xx DEFINITIONS -----------------
8490
[env_common_esp82xx]
85-
platform = espressif8266@3.2.0
91+
platform = espressif8266@4.0.1
8692
board = esp8285-8285
8793
build_flags =
8894
-D PLATFORM_ESP8266=1
@@ -100,8 +106,8 @@ extra_scripts =
100106
${env.extra_scripts}
101107
pre:python/build_html.py
102108
lib_deps =
103-
makuna/NeoPixelBus @ 2.6.9
104-
ottowinter/ESPAsyncWebServer-esphome @ 2.1.0
109+
makuna/NeoPixelBus @ 2.7.0
110+
ottowinter/ESPAsyncWebServer-esphome @ 3.0.0
105111
bblanchon/ArduinoJson @ 6.19.4
106112
upload_speed = 460800
107113
monitor_speed = 420000

0 commit comments

Comments
 (0)