Skip to content

Commit

Permalink
Merge branch 'master' into universal-binding
Browse files Browse the repository at this point in the history
  • Loading branch information
CapnBry committed Feb 1, 2024
2 parents b10b911 + ff27651 commit 91876ea
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 41 deletions.
89 changes: 67 additions & 22 deletions src/lib/Backpack/devBackpack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

#define BACKPACK_TIMEOUT 20 // How often to check for backpack commands

extern Stream *TxBackpack;
extern char backpackVersion[];
extern bool headTrackingEnabled;

Expand All @@ -28,33 +27,55 @@ bool lastRecordingState = false;
#include "CRSF.h"
#include "hwTimer.h"

void startPassthrough()
[[noreturn]] void startPassthrough()
{
// stop everyhting
// stop everything
devicesStop();
Radio.End();
hwTimer::stop();
CRSF::End();

Stream *uplink = &CRSF::Port;

uint32_t baud = PASSTHROUGH_BAUD == -1 ? BACKPACK_LOGGING_BAUD : PASSTHROUGH_BAUD;
// get ready for passthrough
if (GPIO_PIN_RCSIGNAL_RX == GPIO_PIN_RCSIGNAL_TX)
{
#if defined(PLATFORM_ESP32_S3)
CRSF::Port.begin(baud, SERIAL_8N1, 44, 43); // 如果PLATFORM_ESP32_S3宏定义,则将引脚配置为44和43,If PLATFORM_ESP32_S3 macro is defined, pins are configured as 44 and 43
// if UART0 is connected to the backpack then use the USB for the uplink
if (GPIO_PIN_DEBUG_RX == 44 && GPIO_PIN_DEBUG_TX == 43)
{
uplink = &Serial;
Serial.setTxBufferSize(1024);
Serial.setRxBufferSize(16384);
}
else
{
CRSF::Port.begin(baud, SERIAL_8N1, 44, 43); // pins are configured as 44 and 43
CRSF::Port.setTxBufferSize(1024);
CRSF::Port.setRxBufferSize(16384);
}
#else
CRSF::Port.begin(baud, SERIAL_8N1, 3, 1); // 否则继续使用默认引脚配置3和1,Otherwise continue to use default pin configuration 3 and 1
CRSF::Port.begin(baud, SERIAL_8N1, 3, 1); // default pin configuration 3 and 1
CRSF::Port.setTxBufferSize(1024);
CRSF::Port.setRxBufferSize(16384);
#endif
}
else
{
CRSF::Port.begin(baud, SERIAL_8N1, GPIO_PIN_RCSIGNAL_RX, GPIO_PIN_RCSIGNAL_TX);
CRSF::Port.setTxBufferSize(1024);
CRSF::Port.setRxBufferSize(16384);
}
disableLoopWDT();

HardwareSerial &backpack = *(HardwareSerial*)TxBackpack;
auto backpack = (HardwareSerial*)TxBackpack;
if (baud != BACKPACK_LOGGING_BAUD)
{
backpack.begin(PASSTHROUGH_BAUD, SERIAL_8N1, GPIO_PIN_DEBUG_RX, GPIO_PIN_DEBUG_TX);
backpack->begin(PASSTHROUGH_BAUD, SERIAL_8N1, GPIO_PIN_DEBUG_RX, GPIO_PIN_DEBUG_TX);
}
backpack->setRxBufferSize(1024);
backpack->setTxBufferSize(16384);

// reset ESP8285 into bootloader mode
digitalWrite(GPIO_PIN_BACKPACK_BOOT, HIGH);
Expand All @@ -64,27 +85,29 @@ void startPassthrough()
digitalWrite(GPIO_PIN_BACKPACK_EN, HIGH);
delay(50);

CRSF::Port.flush();
backpack.flush();
uplink->flush();
backpack->flush();

uint8_t buf[64];
while (backpack.available())
backpack.readBytes(buf, sizeof(buf));
while (backpack->available())
{
backpack->readBytes(buf, sizeof(buf));
}

// go hard!
for (;;)
{
int r = CRSF::Port.available();
if (r > sizeof(buf))
r = sizeof(buf);
r = CRSF::Port.readBytes(buf, r);
backpack.write(buf, r);

r = backpack.available();
if (r > sizeof(buf))
r = sizeof(buf);
r = backpack.readBytes(buf, r);
CRSF::Port.write(buf, r);
int available_bytes = uplink->available();
if (available_bytes > sizeof(buf))
available_bytes = sizeof(buf);
auto bytes_read = uplink->readBytes(buf, available_bytes);
backpack->write(buf, bytes_read);

available_bytes = backpack->available();
if (available_bytes > sizeof(buf))
available_bytes = sizeof(buf);
bytes_read = backpack->readBytes(buf, available_bytes);
uplink->write(buf, bytes_read);
}
}
#endif
Expand All @@ -99,6 +122,28 @@ void checkBackpackUpdate()
startPassthrough();
}
}
#if defined(PLATFORM_ESP32_S3)
// Start passthrough mode if an Espressif resync packet is detected on the USB port
static const uint8_t resync[] = {
0xc0,0x00,0x08,0x24,0x00,0x00,0x00,0x00,0x00,0x07,0x07,0x12,0x20,0x55,0x55,0x55,0x55,
0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55, 0x55,0x55,
0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0xc0
};
static int resync_pos = 0;
while(Serial.available())
{
int byte = Serial.read();
if (byte == resync[resync_pos])
{
resync_pos++;
if (resync_pos == sizeof(resync)) startPassthrough();
}
else
{
resync_pos = 0;
}
}
#endif
#endif
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/SCREEN/TFT/tftdisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ void TFTDisplay::init()
pinMode(GPIO_PIN_TFT_BL, OUTPUT);
}
bus = new Arduino_ESP32SPI(GPIO_PIN_TFT_DC, GPIO_PIN_TFT_CS, GPIO_PIN_TFT_SCLK, GPIO_PIN_TFT_MOSI, GFX_NOT_DEFINED, HSPI);
gfx = new Arduino_ST7735(bus, GPIO_PIN_TFT_RST, 1 /* rotation */, true , 80, 160, 26, 1, 26, 1);
gfx = new Arduino_ST7735(bus, GPIO_PIN_TFT_RST, OPT_OLED_REVERSED ? 3 : 1 /* rotation */, true , 80, 160, 26, 1, 26, 1);

gfx->begin();
doScreenBackLight(SCREEN_BACKLIGHT_ON);
Expand Down
12 changes: 10 additions & 2 deletions src/lib/SX127xDriver/SX127xHal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,18 @@ void SX127xHal::reset(void)
if (GPIO_PIN_RST != UNDEF_PIN)
{
pinMode(GPIO_PIN_RST, OUTPUT);
delay(100);
digitalWrite(GPIO_PIN_RST, LOW);
delay(100);
if (GPIO_PIN_RST_2 != UNDEF_PIN)
{
pinMode(GPIO_PIN_RST_2, OUTPUT);
digitalWrite(GPIO_PIN_RST_2, LOW);
}
delay(50); // Safety buffer. Busy takes longer to go low than the 1ms timeout in WaitOnBusy().
pinMode(GPIO_PIN_RST, INPUT); // leave floating
if (GPIO_PIN_RST_2 != UNDEF_PIN)
{
pinMode(GPIO_PIN_RST_2, INPUT);
}
}

DBGLN("SX127x Ready!");
Expand Down
22 changes: 15 additions & 7 deletions src/lib/VTXSPI/devVTXSPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,21 @@ static void rtc6705WriteRegister(uint32_t regData)
digitalWrite(GPIO_PIN_SPI_VTX_NSS, LOW);
}

#if defined(PLATFORM_ESP32)
vtxSPI->transferBits(regData, nullptr, 25);
#else
uint8_t buf[BUF_PACKET_SIZE];
memcpy(buf, (byte *)&regData, BUF_PACKET_SIZE);
vtxSPI->transfer(buf, BUF_PACKET_SIZE);
#endif
// On some ESP32 MCUs there's a silicon bug which affects all 8n+1 bit and 1 bit transfers where the
// last bit sent is corrupt.
// See: https://github.com/ExpressLRS/ExpressLRS/pull/2406#issuecomment-1722573356
//
// To reproduce, use an ESP32S3 and 25 bit transfers, change from channel A4 to A1, then A1 to A4 (ok),
// then A4 to A3, then A3 to A4 (fail)
//
// 12816, 9286833 appears on the scope when changing from A:1->A:4
// 12816, 26064049 appears on the scope when changing from A:3->A:4
//
// 9286833 = 0_1000_1101_1011_0100_1011_0001
// 26064049 = 1_1000_1101_1011_0100_1011_0001
//
// Since the RTC6705 just ignores the extra bits, we send 32 bits and the RTC6705 ignores the last 7 bits.
vtxSPI->transfer32(regData);

if (GPIO_PIN_SPI_VTX_SCK == GPIO_PIN_SCK)
{
Expand Down
13 changes: 4 additions & 9 deletions src/targets/common.ini
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,8 @@ lib_ignore = SX127xDriver

# ------------------------- COMMON ESP32 DEFINITIONS -----------------

# platform 5.1.0 uses arduino core 2.0.4 which has a "major" problem with
# requiring the QIO bootloader on PICO devices, so upgrading older firmware
# will be problem using OTA, unless we have a mechanism for uploading a new
# bootloader first!

[env_common_esp32]
platform = espressif32@6.3.2
platform = espressif32@6.4.0
board = esp32dev
board_build.partitions = min_spiffs.csv
upload_speed = 460800
Expand Down Expand Up @@ -63,7 +58,7 @@ tft_lib_deps =
moononournation/GFX Library for Arduino @ 1.2.8

[env_common_esp32s3tx]
platform = espressif32@6.3.2
platform = espressif32@6.4.0
extends = env_common_esp32
board = esp32-s3-devkitc-1
build_flags =
Expand All @@ -72,7 +67,7 @@ build_flags =
-D ARDUINO_USB_CDC_ON_BOOT

[env_common_esp32rx]
platform = espressif32@6.3.2
platform = espressif32@6.4.0
board = esp32dev
board_build.partitions = min_spiffs.csv
upload_speed = 460800
Expand All @@ -96,7 +91,7 @@ lib_deps =
bblanchon/ArduinoJson @ 6.19.4

[env_common_esp32s3rx]
platform = espressif32@6.3.2
platform = espressif32@6.4.0
extends = env_common_esp32rx
board = esp32-s3-devkitc-1
build_flags =
Expand Down

0 comments on commit 91876ea

Please sign in to comment.