Skip to content

Commit

Permalink
Enabling ESP32 to use non-inverted SBUS
Browse files Browse the repository at this point in the history
  • Loading branch information
flybrianfly committed Sep 29, 2022
1 parent 1c353d1 commit b457d85
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 55 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## v8.0.1
- Enabling ESP32 to use non-inverted SBUS

## v8.0.0
- Fixed bug in SbusRx timing where the last packet waited for the start of the next packet before returning true
- Added option to specify a non-inverted signal for cases where that is a hardware option
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=Bolder Flight Systems SBUS
version=8.0.0
version=8.0.1
author=Brian Taylor <[email protected]>
maintainer=Brian Taylor <[email protected]>
sentence=Library for communicating with SBUS receivers and servos.
Expand Down
116 changes: 66 additions & 50 deletions src/sbus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,34 +35,42 @@
namespace bfs {

void SbusRx::Begin() {
if (!inv_) {
/* Start the bus */
/* Teensy 3.0 || Teensy 3.1/3.2 */
#if defined(__MK20DX128__) || defined(__MK20DX256__)
if (inv_) {
uart_->begin(BAUD_, SERIAL_8E1_RXINV_TXINV);
} else {
uart_->begin(BAUD_, SERIAL_8E1);
}
/*
* Teensy 3.5 || Teensy 3.6 ||
* Teensy LC || Teensy 4.0/4.1 ||
* Teensy 4.0 Beta
*/
#elif defined(__MK64FX512__) || defined(__MK66FX1M0__) || \
defined(__MKL26Z64__) || defined(__IMXRT1062__) || \
defined(__IMXRT1052__)
if (inv_){
uart_->begin(BAUD_, SERIAL_8E2_RXINV_TXINV);
} else {
uart_->begin(BAUD_, SERIAL_8E2);
}
/* STM32L4 */
#elif defined(STM32L496xx) || defined(STM32L476xx) || \
defined(STM32L433xx) || defined(STM32L432xx)
if (inv_) {
uart_->begin(BAUD_, SERIAL_8E2 | 0xC000ul);
} else {
/* Start the bus */
/* Teensy 3.0 || Teensy 3.1/3.2 */
#if defined(__MK20DX128__) || defined(__MK20DX256__)
uart_->begin(BAUD_, SERIAL_8E1_RXINV_TXINV);
/*
* Teensy 3.5 || Teensy 3.6 ||
* Teensy LC || Teensy 4.0/4.1 ||
* Teensy 4.0 Beta
*/
#elif defined(__MK64FX512__) || defined(__MK66FX1M0__) || \
defined(__MKL26Z64__) || defined(__IMXRT1062__) || \
defined(__IMXRT1052__)
uart_->begin(BAUD_, SERIAL_8E2_RXINV_TXINV);
/* STM32L4 */
#elif defined(STM32L496xx) || defined(STM32L476xx) || \
defined(STM32L433xx) || defined(STM32L432xx)
uart_->begin(BAUD_, SERIAL_8E2 | 0xC000ul);
/* ESP32 */
#elif defined(ESP32)
uart_->begin(BAUD_, SERIAL_8E2, rxpin_, txpin_, true);
/* Everything else, with a hardware inverter */
#else
uart_->begin(BAUD_, SERIAL_8E2);
#endif
uart_->begin(BAUD_, SERIAL_8E2);
}
/* ESP32 */
#elif defined(ESP32)
uart_->begin(BAUD_, SERIAL_8E2, rxpin_, txpin_, inv_);
/* Everything else, with a hardware inverter */
#else
uart_->begin(BAUD_, SERIAL_8E2);
#endif
/* flush the bus */
uart_->flush();
}
Expand Down Expand Up @@ -166,34 +174,42 @@ namespace {
#endif

void SbusTx::Begin() {
if (!inv_) {
/* Start the bus */
/* Teensy 3.0 || Teensy 3.1/3.2 */
#if defined(__MK20DX128__) || defined(__MK20DX256__)
if (inv_) {
uart_->begin(BAUD_, SERIAL_8E1_RXINV_TXINV);
} else {
uart_->begin(BAUD_, SERIAL_8E1);
}
/*
* Teensy 3.5 || Teensy 3.6 ||
* Teensy LC || Teensy 4.0/4.1 ||
* Teensy 4.0 Beta
*/
#elif defined(__MK64FX512__) || defined(__MK66FX1M0__) || \
defined(__MKL26Z64__) || defined(__IMXRT1062__) || \
defined(__IMXRT1052__)
if (inv_){
uart_->begin(BAUD_, SERIAL_8E2_RXINV_TXINV);
} else {
uart_->begin(BAUD_, SERIAL_8E2);
}
/* STM32L4 */
#elif defined(STM32L496xx) || defined(STM32L476xx) || \
defined(STM32L433xx) || defined(STM32L432xx)
if (inv_) {
uart_->begin(BAUD_, SERIAL_8E2 | 0xC000ul);
} else {
/* Start the bus */
/* Teensy 3.0 || Teensy 3.1/3.2 */
#if defined(__MK20DX128__) || defined(__MK20DX256__)
uart_->begin(BAUD_, SERIAL_8E1_RXINV_TXINV);
/*
* Teensy 3.5 || Teensy 3.6 ||
* Teensy LC || Teensy 4.0/4.1 ||
* Teensy 4.0 Beta
*/
#elif defined(__MK64FX512__) || defined(__MK66FX1M0__) || \
defined(__MKL26Z64__) || defined(__IMXRT1062__) || \
defined(__IMXRT1052__)
uart_->begin(BAUD_, SERIAL_8E2_RXINV_TXINV);
/* STM32L4 */
#elif defined(STM32L496xx) || defined(STM32L476xx) || \
defined(STM32L433xx) || defined(STM32L432xx)
uart_->begin(BAUD_, SERIAL_8E2 | 0xC000ul);
/* ESP32 */
#elif defined(ESP32)
uart_->begin(BAUD_, SERIAL_8E2, rxpin_, txpin_, true);
/* Everything else, with a hardware inverter */
#else
uart_->begin(BAUD_, SERIAL_8E2);
#endif
uart_->begin(BAUD_, SERIAL_8E2);
}
/* ESP32 */
#elif defined(ESP32)
uart_->begin(BAUD_, SERIAL_8E2, rxpin_, txpin_, inv_);
/* Everything else, with a hardware inverter */
#else
uart_->begin(BAUD_, SERIAL_8E2);
#endif
}

void SbusTx::Write() {
Expand Down
10 changes: 6 additions & 4 deletions src/sbus.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,13 @@ struct SbusData {

class SbusRx {
public:
explicit SbusRx(HardwareSerial *bus) : uart_(bus) {}
SbusRx(HardwareSerial *bus, const bool inv) : uart_(bus), inv_(inv) {}
#if defined(ESP32)
SbusRx(HardwareSerial *bus, const int8_t rxpin, const int8_t txpin,
const bool inv) : uart_(bus), inv_(inv), rxpin_(rxpin), txpin_(txpin)
{}
#else
explicit SbusRx(HardwareSerial *bus) : uart_(bus) {}
SbusRx(HardwareSerial *bus, const bool inv) : uart_(bus), inv_(inv) {}
#endif
void Begin();
bool Read();
Expand Down Expand Up @@ -92,12 +93,13 @@ class SbusRx {

class SbusTx {
public:
explicit SbusTx(HardwareSerial *bus) : uart_(bus) {}
SbusTx(HardwareSerial *bus, const bool inv) : uart_(bus), inv_(inv) {}
#if defined(ESP32)
SbusTx(HardwareSerial *bus, const int8_t rxpin, const int8_t txpin,
const bool inv) : uart_(bus), inv_(inv), rxpin_(rxpin), txpin_(txpin)
{}
#else
explicit SbusTx(HardwareSerial *bus) : uart_(bus) {}
SbusTx(HardwareSerial *bus, const bool inv) : uart_(bus), inv_(inv) {}
#endif
void Begin();
void Write();
Expand Down

0 comments on commit b457d85

Please sign in to comment.