got rid of gdo0/gdo2 for every board except esp8266, that needs to know which single pin to use bidirectionally

This commit is contained in:
Gábor Poczkodi 2024-02-29 00:53:24 +01:00
parent 87c3896a50
commit de51ae76f4
10 changed files with 30 additions and 100 deletions

View file

@ -6,7 +6,13 @@
It can be compiled with Arduino and esp-idf framework and should support any esphome compatible board through the SPI
Bus.
On ESP8266, you can use the same pin for GDO and GD2 (it is an optional parameter).
On ESP8266, you can use a single pin instead of GD0O and GD02 (gdo0 is an optional parameter). If assigned,
the pin direction will be reversed for the transfers.
On ESP32, this will not work, you must connect two separate pins. TX to GDO0, RX to GDO2.
If only TX works, they are probably switched.
Transferst must be surrounded with cc1101.begin_tx and cc1101.end_tx.
The source code is a mashup of the following github projects with some special esphome sauce:
@ -48,7 +54,6 @@ static const uint8_t PA_TABLE_915[10]{0x03, 0x0E, 0x1E, 0x27, 0x38, 0x8E, 0x84,
CC1101::CC1101() {
this->gdo0_ = nullptr;
this->gdo2_ = nullptr;
this->bandwidth_ = 200;
this->frequency_ = 433920;
this->rssi_sensor_ = nullptr;
@ -80,14 +85,7 @@ CC1101::CC1101() {
this->pa_table_[1] = 0xc0;
}
void CC1101::set_config_gdo0(InternalGPIOPin *pin) {
gdo0_ = pin;
if (gdo2_ == nullptr)
gdo2_ = pin;
}
void CC1101::set_config_gdo2(InternalGPIOPin *pin) { gdo2_ = pin; }
void CC1101::set_config_gdo0(InternalGPIOPin *pin) { gdo0_ = pin; }
void CC1101::set_config_bandwidth(uint32_t bandwidth) { bandwidth_ = bandwidth; }
@ -98,10 +96,10 @@ void CC1101::set_config_rssi_sensor(sensor::Sensor *rssi_sensor) { rssi_sensor_
void CC1101::set_config_lqi_sensor(sensor::Sensor *lqi_sensor) { lqi_sensor_ = lqi_sensor; }
void CC1101::setup() {
this->gdo0_->setup();
this->gdo2_->setup();
this->gdo0_->pin_mode(gpio::FLAG_OUTPUT);
this->gdo2_->pin_mode(gpio::FLAG_INPUT);
if (this->gdo0_ != nullptr) {
this->gdo0_->setup();
this->gdo0_->pin_mode(gpio::FLAG_INPUT);
}
this->spi_setup();
@ -184,7 +182,6 @@ void CC1101::dump_config() {
ESP_LOGCONFIG(TAG, "CC1101 partnum %02x version %02x:", this->partnum_, this->version_);
LOG_PIN(" CC1101 CS Pin: ", this->cs_);
LOG_PIN(" CC1101 GDO0: ", this->gdo0_);
LOG_PIN(" CC1101 GDO2: ", this->gdo2_);
ESP_LOGCONFIG(TAG, " CC1101 Bandwith: %d KHz", this->bandwidth_);
ESP_LOGCONFIG(TAG, " CC1101 Frequency: %d KHz", this->frequency_);
LOG_SENSOR(" ", "RSSI", this->rssi_sensor_);
@ -646,7 +643,7 @@ void CC1101::split_mdmcfg4_() {
void CC1101::begin_tx() {
this->set_tx_();
if (this->gdo0_ == this->gdo2_) {
if (this->gdo0_ != nullptr) {
#ifdef USE_ESP8266
#ifdef USE_ARDUINO
noInterrupts(); // NOLINT
@ -659,7 +656,7 @@ void CC1101::begin_tx() {
}
void CC1101::end_tx() {
if (this->gdo0_ == this->gdo2_) {
if (this->gdo0_ != nullptr) {
#ifdef USE_ESP8266
#ifdef USE_ARDUINO
interrupts(); // NOLINT

View file

@ -13,7 +13,6 @@ class CC1101 : public sensor::Sensor,
spi::DATA_RATE_1KHZ> {
protected:
InternalGPIOPin *gdo0_;
InternalGPIOPin *gdo2_;
uint32_t bandwidth_;
uint32_t frequency_;
sensor::Sensor *rssi_sensor_;
@ -78,7 +77,6 @@ class CC1101 : public sensor::Sensor,
CC1101();
void set_config_gdo0(InternalGPIOPin *pin);
void set_config_gdo2(InternalGPIOPin *pin);
void set_config_bandwidth(uint32_t bandwidth);
void set_config_frequency(uint32_t frequency);
void set_config_rssi_sensor(sensor::Sensor *rssi_sensor);

View file

@ -16,7 +16,6 @@ from esphome.const import (
DEPENDENCIES = ["spi"]
CONF_GDO0 = "gdo0"
CONF_GDO2 = "gdo2"
CONF_BANDWIDTH = "bandwidth"
# CONF_FREQUENCY = "frequency"
CONF_RSSI = "rssi"
@ -32,8 +31,7 @@ CONFIG_SCHEMA = (
cv.Schema(
{
cv.GenerateID(): cv.declare_id(CC1101),
cv.Required(CONF_GDO0): pins.gpio_output_pin_schema,
cv.Optional(CONF_GDO2): pins.gpio_input_pin_schema,
cv.Optional(CONF_GDO0): pins.gpio_output_pin_schema,
cv.Optional(CONF_BANDWIDTH, default=200): cv.uint32_t,
cv.Optional(CONF_FREQUENCY, default=433920): cv.uint32_t,
cv.Optional(CONF_RSSI): sensor.sensor_schema(
@ -73,11 +71,9 @@ async def to_code(config):
await cg.register_component(var, config)
await spi.register_spi_device(var, config)
gdo0 = await cg.gpio_pin_expression(config[CONF_GDO0])
cg.add(var.set_config_gdo0(gdo0))
if CONF_GDO2 in config:
gdo2 = await cg.gpio_pin_expression(config[CONF_GDO2])
cg.add(var.set_config_gdo2(gdo2))
if CONF_GDO0 in config:
gdo0 = await cg.gpio_pin_expression(config[CONF_GDO0])
cg.add(var.set_config_gdo0(gdo0))
cg.add(var.set_config_bandwidth(config[CONF_BANDWIDTH]))
cg.add(var.set_config_frequency(config[CONF_FREQUENCY]))
if CONF_RSSI in config:

View file

@ -7,12 +7,6 @@ sensor:
- platform: cc1101
id: transceiver
cs_pin: GPIO10
gdo0:
number: GPIO3
allow_other_uses: true
gdo2:
number: GPIO4
allow_other_uses: true
bandwidth: 200
frequency: 433920
rssi:
@ -28,16 +22,12 @@ remote_transmitter:
- pin: GPIO21 # TX pin
carrier_duty_percent: 100%
id: dummytx
- pin:
number: GPIO3 # GDO0
allow_other_uses: true
- pin: GPIO3 # GDO0
carrier_duty_percent: 100%
id: realtx
remote_receiver:
pin:
number: GPIO4 # GDO0
allow_other_uses: true
pin: GPIO4 # GDO2
dump:
- rc_switch
# Settings to optimize recognition of RF devices

View file

@ -7,12 +7,6 @@ sensor:
- platform: cc1101
id: transceiver
cs_pin: GPIO10
gdo0:
number: GPIO3
allow_other_uses: true
gdo2:
number: GPIO4
allow_other_uses: true
bandwidth: 200
frequency: 433920
rssi:
@ -28,16 +22,12 @@ remote_transmitter:
- pin: GPIO21 # TX pin
carrier_duty_percent: 100%
id: dummytx
- pin:
number: GPIO3 # GDO0
allow_other_uses: true
- pin: GPIO3 # GDO0
carrier_duty_percent: 100%
id: realtx
remote_receiver:
pin:
number: GPIO4 # GDO0
allow_other_uses: true
pin: GPIO4 # GDO2
dump:
- rc_switch
# Settings to optimize recognition of RF devices

View file

@ -7,12 +7,6 @@ sensor:
- platform: cc1101
id: transceiver
cs_pin: GPIO5
gdo0:
number: GPIO32
allow_other_uses: true
gdo2:
number: GPIO33
allow_other_uses: true
bandwidth: 200
frequency: 433920
rssi:
@ -21,15 +15,11 @@ sensor:
name: LQI
remote_transmitter:
- pin:
number: GPIO32 # GDO0
allow_other_uses: true
- pin: GPIO32 # GDO0
carrier_duty_percent: 100%
remote_receiver:
pin:
number: GPIO33 # GDO0
allow_other_uses: true
pin: GPIO33 # GDO2
dump:
- rc_switch
# Settings to optimize recognition of RF devices

View file

@ -7,12 +7,6 @@ sensor:
- platform: cc1101
id: transceiver
cs_pin: GPIO34
gdo0:
number: GPIO8
allow_other_uses: true
gdo2:
number: GPIO9
allow_other_uses: true
bandwidth: 200
frequency: 433920
rssi:
@ -21,15 +15,11 @@ sensor:
name: LQI
remote_transmitter:
- pin:
number: GPIO8 # GDO0
allow_other_uses: true
- pin: GPIO8 # GDO0
carrier_duty_percent: 100%
remote_receiver:
pin:
number: GPIO9 # GDO0
allow_other_uses: true
pin: GPIO9 # GDO2
dump:
- rc_switch
# Settings to optimize recognition of RF devices

View file

@ -7,12 +7,6 @@ sensor:
- platform: cc1101
id: transceiver
cs_pin: GPIO34
gdo0:
number: GPIO8
allow_other_uses: true
gdo2:
number: GPIO9
allow_other_uses: true
bandwidth: 200
frequency: 433920
rssi:
@ -21,15 +15,11 @@ sensor:
name: LQI
remote_transmitter:
- pin:
number: GPIO8 # GDO0
allow_other_uses: true
- pin: GPIO8 # GDO0
carrier_duty_percent: 100%
remote_receiver:
pin:
number: GPIO9 # GDO0
allow_other_uses: true
pin: GPIO9 # GDO2
dump:
- rc_switch
# Settings to optimize recognition of RF devices

View file

@ -7,12 +7,6 @@ sensor:
- platform: cc1101
id: transceiver
cs_pin: GPIO5
gdo0:
number: GPIO32
allow_other_uses: true
gdo2:
number: GPIO33
allow_other_uses: true
bandwidth: 200
frequency: 433920
rssi:
@ -21,15 +15,11 @@ sensor:
name: LQI
remote_transmitter:
- pin:
number: GPIO32 # GDO0
allow_other_uses: true
- pin: GPIO32 # GDO0
carrier_duty_percent: 100%
remote_receiver:
pin:
number: GPIO33 # GDO0
allow_other_uses: true
pin: GPIO33 # GDO2
dump:
- rc_switch
# Settings to optimize recognition of RF devices

View file

@ -10,7 +10,6 @@ sensor:
gdo0:
number: D1 # GPIO5
allow_other_uses: true
# gdo2: not used with ESP8266
bandwidth: 200
frequency: 433920
rssi: