mirror of
https://github.com/rstrouse/ESPSomfy-RTS.git
synced 2026-10-31 13:52:15 +01:00
fix: stop the CC1101 driver's "IO is not set as GPIO" log spam
Arduino 3.x tracks which peripheral owns each pin and logs when a pin the SPI bus owns is used through digitalRead()/digitalWrite(). The vendored SmartRC-CC1101 driver does both: - Every register access waits for CHIP_RDYn with digitalRead(MISO): one "IO 19 is not set as GPIO" warning per access, about one every 4 s from the RSSI read in decodeFrame(). It now reads the pad with gpio_get_level(), which returns the same level without the ownership check. - Init() set SCK and MOSI with digitalWrite() after SpiStart(), which the core refused with an error each boot. The writes are gone; the bus idles them. The MISO wait also had no bound, so a missing or dead module hung the caller. It now gives up after 10 ms. No native test: the driver only builds for the ESP32. To check on hardware: the serial log should have no "is not set as GPIO" lines, and frames should still decode with an RSSI. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
108b2960c7
commit
9c1ec17e1a
1 changed files with 29 additions and 10 deletions
|
|
@ -16,6 +16,24 @@ cc1101 Driver for RC Switch. Mod by Little Satan. With permission to modify and
|
||||||
#include <SPI.h>
|
#include <SPI.h>
|
||||||
#include "ELECHOUSE_CC1101_SRC_DRV.h"
|
#include "ELECHOUSE_CC1101_SRC_DRV.h"
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
#ifdef ESP32
|
||||||
|
#include <driver/gpio.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// ESPSomfy-RTS: waits for the CC1101 to pull MISO low (CHIP_RDYn) before an
|
||||||
|
// SPI access. MISO belongs to the SPI bus by then, and Arduino 3.x logs a
|
||||||
|
// warning on every digitalRead() of a pin another peripheral owns, so on the
|
||||||
|
// ESP32 read the pad directly. Gives up after 10 ms so a missing or dead
|
||||||
|
// module can't hang the caller; the chip is ready within a few hundred us.
|
||||||
|
static void waitMisoLow(byte pin)
|
||||||
|
{
|
||||||
|
uint32_t start = micros();
|
||||||
|
#ifdef ESP32
|
||||||
|
while(gpio_get_level((gpio_num_t)pin) && micros() - start < 10000);
|
||||||
|
#else
|
||||||
|
while(digitalRead(pin) && micros() - start < 10000);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
/****************************************************************/
|
/****************************************************************/
|
||||||
#define WRITE_BURST 0x40 //write burst
|
#define WRITE_BURST 0x40 //write burst
|
||||||
|
|
@ -144,9 +162,9 @@ void ELECHOUSE_CC1101::Reset (void)
|
||||||
digitalWrite(SS_PIN, HIGH);
|
digitalWrite(SS_PIN, HIGH);
|
||||||
delay(1);
|
delay(1);
|
||||||
digitalWrite(SS_PIN, LOW);
|
digitalWrite(SS_PIN, LOW);
|
||||||
while(digitalRead(MISO_PIN));
|
waitMisoLow(MISO_PIN);
|
||||||
SPI.transfer(CC1101_SRES);
|
SPI.transfer(CC1101_SRES);
|
||||||
while(digitalRead(MISO_PIN));
|
waitMisoLow(MISO_PIN);
|
||||||
digitalWrite(SS_PIN, HIGH);
|
digitalWrite(SS_PIN, HIGH);
|
||||||
}
|
}
|
||||||
/****************************************************************
|
/****************************************************************
|
||||||
|
|
@ -160,8 +178,9 @@ void ELECHOUSE_CC1101::Init(void)
|
||||||
setSpi();
|
setSpi();
|
||||||
SpiStart(); //spi initialization
|
SpiStart(); //spi initialization
|
||||||
digitalWrite(SS_PIN, HIGH);
|
digitalWrite(SS_PIN, HIGH);
|
||||||
digitalWrite(SCK_PIN, HIGH);
|
// ESPSomfy-RTS: no digitalWrite() on SCK and MOSI here. SpiStart() has
|
||||||
digitalWrite(MOSI_PIN, LOW);
|
// handed them to the SPI bus, so Arduino 3.x refused the writes and logged
|
||||||
|
// an error; the bus already idles SCK and MOSI.
|
||||||
Reset(); //CC1101 reset
|
Reset(); //CC1101 reset
|
||||||
RegConfigSettings(); //CC1101 register config
|
RegConfigSettings(); //CC1101 register config
|
||||||
SpiEnd();
|
SpiEnd();
|
||||||
|
|
@ -176,7 +195,7 @@ void ELECHOUSE_CC1101::SpiWriteReg(byte addr, byte value)
|
||||||
{
|
{
|
||||||
SpiStart();
|
SpiStart();
|
||||||
digitalWrite(SS_PIN, LOW);
|
digitalWrite(SS_PIN, LOW);
|
||||||
while(digitalRead(MISO_PIN));
|
waitMisoLow(MISO_PIN);
|
||||||
SPI.transfer(addr);
|
SPI.transfer(addr);
|
||||||
SPI.transfer(value);
|
SPI.transfer(value);
|
||||||
digitalWrite(SS_PIN, HIGH);
|
digitalWrite(SS_PIN, HIGH);
|
||||||
|
|
@ -194,7 +213,7 @@ void ELECHOUSE_CC1101::SpiWriteBurstReg(byte addr, byte *buffer, byte num)
|
||||||
SpiStart();
|
SpiStart();
|
||||||
temp = addr | WRITE_BURST;
|
temp = addr | WRITE_BURST;
|
||||||
digitalWrite(SS_PIN, LOW);
|
digitalWrite(SS_PIN, LOW);
|
||||||
while(digitalRead(MISO_PIN));
|
waitMisoLow(MISO_PIN);
|
||||||
SPI.transfer(temp);
|
SPI.transfer(temp);
|
||||||
for (i = 0; i < num; i++)
|
for (i = 0; i < num; i++)
|
||||||
{
|
{
|
||||||
|
|
@ -213,7 +232,7 @@ void ELECHOUSE_CC1101::SpiStrobe(byte strobe)
|
||||||
{
|
{
|
||||||
SpiStart();
|
SpiStart();
|
||||||
digitalWrite(SS_PIN, LOW);
|
digitalWrite(SS_PIN, LOW);
|
||||||
while(digitalRead(MISO_PIN));
|
waitMisoLow(MISO_PIN);
|
||||||
SPI.transfer(strobe);
|
SPI.transfer(strobe);
|
||||||
digitalWrite(SS_PIN, HIGH);
|
digitalWrite(SS_PIN, HIGH);
|
||||||
SpiEnd();
|
SpiEnd();
|
||||||
|
|
@ -230,7 +249,7 @@ byte ELECHOUSE_CC1101::SpiReadReg(byte addr)
|
||||||
SpiStart();
|
SpiStart();
|
||||||
temp = addr| READ_SINGLE;
|
temp = addr| READ_SINGLE;
|
||||||
digitalWrite(SS_PIN, LOW);
|
digitalWrite(SS_PIN, LOW);
|
||||||
while(digitalRead(MISO_PIN));
|
waitMisoLow(MISO_PIN);
|
||||||
SPI.transfer(temp);
|
SPI.transfer(temp);
|
||||||
value=SPI.transfer(0);
|
value=SPI.transfer(0);
|
||||||
digitalWrite(SS_PIN, HIGH);
|
digitalWrite(SS_PIN, HIGH);
|
||||||
|
|
@ -250,7 +269,7 @@ void ELECHOUSE_CC1101::SpiReadBurstReg(byte addr, byte *buffer, byte num)
|
||||||
SpiStart();
|
SpiStart();
|
||||||
temp = addr | READ_BURST;
|
temp = addr | READ_BURST;
|
||||||
digitalWrite(SS_PIN, LOW);
|
digitalWrite(SS_PIN, LOW);
|
||||||
while(digitalRead(MISO_PIN));
|
waitMisoLow(MISO_PIN);
|
||||||
SPI.transfer(temp);
|
SPI.transfer(temp);
|
||||||
for(i=0;i<num;i++)
|
for(i=0;i<num;i++)
|
||||||
{
|
{
|
||||||
|
|
@ -272,7 +291,7 @@ byte ELECHOUSE_CC1101::SpiReadStatus(byte addr)
|
||||||
SpiStart();
|
SpiStart();
|
||||||
temp = addr | READ_BURST;
|
temp = addr | READ_BURST;
|
||||||
digitalWrite(SS_PIN, LOW);
|
digitalWrite(SS_PIN, LOW);
|
||||||
while(digitalRead(MISO_PIN));
|
waitMisoLow(MISO_PIN);
|
||||||
SPI.transfer(temp);
|
SPI.transfer(temp);
|
||||||
value=SPI.transfer(0);
|
value=SPI.transfer(0);
|
||||||
digitalWrite(SS_PIN, HIGH);
|
digitalWrite(SS_PIN, HIGH);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue