Add BL0942 baudrate selection

This commit is contained in:
Theo Arends 2023-09-12 21:48:13 +02:00
parent ee43b43add
commit 088ac1815b
2 changed files with 8 additions and 3 deletions

View File

@ -488,6 +488,7 @@ const char kSensorNamesFixed[] PROGMEM =
#define MAX_DSB 4
#define MAX_BP1658CJ_DAT 16
#define MAX_DINGTIAN_SHIFT 4
#define MAX_BL0942_RX 4 // Baudrates 1 (4800), 2 (9600), 3 (19200), 4 (38400)
const uint16_t kGpioNiceList[] PROGMEM = {
GPIO_NONE, // Not used
@ -906,7 +907,7 @@ const uint16_t kGpioNiceList[] PROGMEM = {
#if defined(USE_BL0940) || defined(USE_BL09XX)
AGPIO(GPIO_BL0939_RX), // BL0939 Serial interface (Dual R3 v2)
AGPIO(GPIO_BL0940_RX), // BL0940 Serial interface
AGPIO(GPIO_BL0942_RX), // BL0940 Serial interface
AGPIO(GPIO_BL0942_RX) + MAX_BL0942_RX, // BL0942 Serial interface
#endif
#ifdef USE_IEM3000
AGPIO(GPIO_IEM3000_TX), // IEM3000 Serial interface

View File

@ -89,6 +89,7 @@ struct BL09XX {
int32_t power[2] = { 0, };
float temperature;
uint16_t tps1 = 0;
uint16_t baudrate;
uint8_t *rx_buffer = nullptr;
uint8_t buffer_size = 0;
uint8_t byte_counter = 0;
@ -285,7 +286,7 @@ void Bl09XXEverySecond(void) {
void Bl09XXInit(void) {
// Software serial init needs to be done here as earlier (serial) interrupts may lead to Exceptions
Bl09XXSerial = new TasmotaSerial(Bl09XX.rx_pin, Pin(GPIO_TXD), 1);
if (Bl09XXSerial->begin(4800)) {
if (Bl09XXSerial->begin(Bl09XX.baudrate)) {
if (Bl09XXSerial->hardwareSerial()) {
ClaimSerial();
}
@ -328,6 +329,7 @@ void Bl09XXInit(void) {
void Bl09XXPreInit(void) {
if (PinUsed(GPIO_TXD)) {
Bl09XX.model = BL09XX_MODEL;
Bl09XX.baudrate = 4800;
if (PinUsed(GPIO_BL0939_RX)) {
Bl09XX.model = BL0939_MODEL;
Bl09XX.rx_pin = Pin(GPIO_BL0939_RX);
@ -338,7 +340,9 @@ void Bl09XXPreInit(void) {
}
else if (PinUsed(GPIO_BL0942_RX)) {
Bl09XX.model = BL0942_MODEL;
Bl09XX.rx_pin = Pin(GPIO_BL0942_RX);
Bl09XX.rx_pin = Pin(GPIO_BL0942_RX, GPIO_ANY);
uint32_t baudrate = GetPin(Bl09XX.rx_pin) - AGPIO(GPIO_BL0942_RX); // 0 .. 3
Bl09XX.baudrate <<= baudrate; // Support 1 (4800), 2 (9600), 3 (19200), 4 (38400)
}
if (Bl09XX.model != BL09XX_MODEL) {
Bl09XX.address = bl09xx_address[Bl09XX.model];