Revert SPI to hardware on ESP32 platforms

This commit is contained in:
jacob.eva 2024-01-20 22:40:28 +00:00
parent a304b892b7
commit fcba036c01
No known key found for this signature in database
GPG Key ID: 0B92E083BBCCAA1E
4 changed files with 49 additions and 43 deletions

View File

@ -297,6 +297,7 @@
#define HAS_NP false #define HAS_NP false
#define HAS_SD false #define HAS_SD false
#define HAS_TCXO true #define HAS_TCXO true
#define HAS_RXEN_BUSY true
#define MODEM SX1262 #define MODEM SX1262
#define CONFIG_UART_BUFFER_SIZE 6144 #define CONFIG_UART_BUFFER_SIZE 6144
@ -329,12 +330,14 @@
#define PMU_IRQ 35 #define PMU_IRQ 35
#endif #endif
#define eeprom_addr(a) (a+EEPROM_OFFSET) #define eeprom_addr(a) (a+EEPROM_OFFSET)
#if MODEM == SX1276 || MODEM == SX1278 #ifndef HAS_RXEN_BUSY
SPIClass spiModem(pin_miso, pin_sclk, pin_mosi); const int pin_rxen = -1;
#elif MODEM == SX1262 const int pin_busy = -1;
#endif
#if MODEM == SX1262
SPIClass spiModem(NRF_SPIM2, pin_miso, pin_sclk, pin_mosi); SPIClass spiModem(NRF_SPIM2, pin_miso, pin_sclk, pin_mosi);
#endif #endif

View File

@ -89,6 +89,8 @@
int fifo_tx_addr_ptr = 0; int fifo_tx_addr_ptr = 0;
int fifo_rx_addr_ptr = 0; int fifo_rx_addr_ptr = 0;
uint8_t packet[256] = {0}; uint8_t packet[256] = {0};
extern SPIClass spiModem;
#define SPI spiModem
#elif MODEM == SX1276 || MODEM == SX1278 #elif MODEM == SX1276 || MODEM == SX1278
@ -150,7 +152,7 @@
#define MAX_PKT_LENGTH 255 #define MAX_PKT_LENGTH 255
extern SPIClass spiModem; extern SPIClass SPI;
bool lora_preinit_done = false; bool lora_preinit_done = false;
@ -180,7 +182,7 @@ bool LoRaClass::preInit() {
// set SS high // set SS high
digitalWrite(_ss, HIGH); digitalWrite(_ss, HIGH);
spiModem.begin(); SPI.begin();
// check version (retry for up to 2 seconds) // check version (retry for up to 2 seconds)
#if MODEM == SX1276 || MODEM == SX1278 #if MODEM == SX1276 || MODEM == SX1278
@ -239,10 +241,10 @@ bool LoRaClass::preInit() {
digitalWrite(_ss, LOW); digitalWrite(_ss, LOW);
spiModem.beginTransaction(_spiSettings); SPI.beginTransaction(_spiSettings);
spiModem.transfer(address); SPI.transfer(address);
response = spiModem.transfer(value); response = SPI.transfer(value);
spiModem.endTransaction(); SPI.endTransaction();
digitalWrite(_ss, HIGH); digitalWrite(_ss, HIGH);
@ -267,15 +269,15 @@ bool LoRaClass::preInit() {
digitalWrite(_ss, LOW); digitalWrite(_ss, LOW);
spiModem.beginTransaction(_spiSettings); SPI.beginTransaction(_spiSettings);
spiModem.transfer(opcode); SPI.transfer(opcode);
spiModem.transfer((address & 0xFF00) >> 8); SPI.transfer((address & 0xFF00) >> 8);
spiModem.transfer(address & 0x00FF); SPI.transfer(address & 0x00FF);
if (opcode == OP_READ_REGISTER) { if (opcode == OP_READ_REGISTER) {
spiModem.transfer(0x00); SPI.transfer(0x00);
} }
response = spiModem.transfer(value); response = SPI.transfer(value);
spiModem.endTransaction(); SPI.endTransaction();
digitalWrite(_ss, HIGH); digitalWrite(_ss, HIGH);
@ -316,15 +318,15 @@ bool LoRaClass::preInit() {
digitalWrite(_ss, LOW); digitalWrite(_ss, LOW);
spiModem.beginTransaction(_spiSettings); SPI.beginTransaction(_spiSettings);
spiModem.transfer(opcode); SPI.transfer(opcode);
for (int i = 0; i < size; i++) for (int i = 0; i < size; i++)
{ {
spiModem.transfer(buffer[i]); SPI.transfer(buffer[i]);
} }
spiModem.endTransaction(); SPI.endTransaction();
digitalWrite(_ss, HIGH); digitalWrite(_ss, HIGH);
} }
@ -335,16 +337,16 @@ bool LoRaClass::preInit() {
digitalWrite(_ss, LOW); digitalWrite(_ss, LOW);
spiModem.beginTransaction(_spiSettings); SPI.beginTransaction(_spiSettings);
spiModem.transfer(opcode); SPI.transfer(opcode);
spiModem.transfer(0x00); SPI.transfer(0x00);
for (int i = 0; i < size; i++) for (int i = 0; i < size; i++)
{ {
buffer[i] = spiModem.transfer(0x00); buffer[i] = SPI.transfer(0x00);
} }
spiModem.endTransaction(); SPI.endTransaction();
digitalWrite(_ss, HIGH); digitalWrite(_ss, HIGH);
} }
@ -355,17 +357,17 @@ bool LoRaClass::preInit() {
digitalWrite(_ss, LOW); digitalWrite(_ss, LOW);
spiModem.beginTransaction(_spiSettings); SPI.beginTransaction(_spiSettings);
spiModem.transfer(OP_FIFO_WRITE); SPI.transfer(OP_FIFO_WRITE);
spiModem.transfer(fifo_tx_addr_ptr); SPI.transfer(fifo_tx_addr_ptr);
for (int i = 0; i < size; i++) for (int i = 0; i < size; i++)
{ {
spiModem.transfer(buffer[i]); SPI.transfer(buffer[i]);
fifo_tx_addr_ptr++; fifo_tx_addr_ptr++;
} }
spiModem.endTransaction(); SPI.endTransaction();
digitalWrite(_ss, HIGH); digitalWrite(_ss, HIGH);
} }
@ -376,17 +378,17 @@ bool LoRaClass::preInit() {
digitalWrite(_ss, LOW); digitalWrite(_ss, LOW);
spiModem.beginTransaction(_spiSettings); SPI.beginTransaction(_spiSettings);
spiModem.transfer(OP_FIFO_READ); SPI.transfer(OP_FIFO_READ);
spiModem.transfer(fifo_rx_addr_ptr); SPI.transfer(fifo_rx_addr_ptr);
spiModem.transfer(0x00); SPI.transfer(0x00);
for (int i = 0; i < size; i++) for (int i = 0; i < size; i++)
{ {
buffer[i] = spiModem.transfer(0x00); buffer[i] = SPI.transfer(0x00);
} }
spiModem.endTransaction(); SPI.endTransaction();
digitalWrite(_ss, HIGH); digitalWrite(_ss, HIGH);
} }
@ -516,8 +518,8 @@ void LoRaClass::end()
// put in sleep mode // put in sleep mode
sleep(); sleep();
// stop spiModem // stop SPI
spiModem.end(); SPI.end();
lora_preinit_done = false; lora_preinit_done = false;
} }
@ -964,13 +966,13 @@ void LoRaClass::onReceive(void(*callback)(int))
executeOpcode(OP_SET_IRQ_FLAGS, buf, 8); executeOpcode(OP_SET_IRQ_FLAGS, buf, 8);
#endif #endif
#ifdef SPI_HAS_NOTUSINGINTERRUPT #ifdef SPI_HAS_NOTUSINGINTERRUPT
spiModem.usingInterrupt(digitalPinToInterrupt(_dio0)); SPI.usingInterrupt(digitalPinToInterrupt(_dio0));
#endif #endif
attachInterrupt(digitalPinToInterrupt(_dio0), LoRaClass::onDio0Rise, RISING); attachInterrupt(digitalPinToInterrupt(_dio0), LoRaClass::onDio0Rise, RISING);
} else { } else {
detachInterrupt(digitalPinToInterrupt(_dio0)); detachInterrupt(digitalPinToInterrupt(_dio0));
#ifdef SPI_HAS_NOTUSINGINTERRUPT #ifdef SPI_HAS_NOTUSINGINTERRUPT
spiModem.notUsingInterrupt(digitalPinToInterrupt(_dio0)); SPI.notUsingInterrupt(digitalPinToInterrupt(_dio0));
#endif #endif
} }
} }

View File

@ -93,7 +93,7 @@ firmware-featheresp32:
arduino-cli compile --fqbn esp32:esp32:featheresp32 -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x34\"" arduino-cli compile --fqbn esp32:esp32:featheresp32 -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x34\""
firmware-genericesp32: firmware-genericesp32:
arduino-cli compile --fqbn esp32:esp32:esp32 -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x35\"" arduino-cli compile --fqbn esp32:esp32:esp32 -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x35\" \"-DMODEM=0x01\""
firmware-rak4630: firmware-rak4630:
arduino-cli compile --fqbn rakwireless:nrf52:WisCoreRAK4631Board -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x51\" \"-DMODEM=0x03\"" arduino-cli compile --fqbn rakwireless:nrf52:WisCoreRAK4631Board -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x51\" \"-DMODEM=0x03\""

View File

@ -13,6 +13,8 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include "Config.h"
#if HAS_EEPROM #if HAS_EEPROM
#include <EEPROM.h> #include <EEPROM.h>
#elif PLATFORM == PLATFORM_NRF52 #elif PLATFORM == PLATFORM_NRF52
@ -20,7 +22,6 @@
int written_bytes = 0; int written_bytes = 0;
#endif #endif
#include <stddef.h> #include <stddef.h>
#include "Config.h"
#include "LoRa.h" #include "LoRa.h"
#include "ROM.h" #include "ROM.h"
#include "Framing.h" #include "Framing.h"