Pārlūkot izejas kodu

continuation, on a presque un truc qui Tx :)

Pierre Bourdin 2 mēneši atpakaļ
vecāks
revīzija
d7f889a59e
5 mainītis faili ar 435 papildinājumiem un 82 dzēšanām
  1. 8 0
      src/Choucas_Kikiwi.code-workspace
  2. 159 43
      src/main.cpp
  3. 168 35
      src/sx1262.cpp
  4. 21 4
      src/sx1262.h
  5. 79 0
      src/sx1262regs.h

+ 8 - 0
src/Choucas_Kikiwi.code-workspace

@@ -0,0 +1,8 @@
+{
+	"folders": [
+		{
+			"path": ".."
+		}
+	],
+	"settings": {}
+}

+ 159 - 43
src/main.cpp

@@ -12,12 +12,10 @@ Sx1262 radio = Sx1262(SX1262_RST, SX1262_SCK, SX1262_MOSI, SX1262_MISO, SX1262_N
 
 void setup_radio()
 {
-    tft.setTextColor(ST77XX_GREEN, ST77XX_BLACK);
+    /*tft.setTextColor(ST77XX_GREEN, ST77XX_BLACK);
     tft.setCursor(0, 12);
     tft.print("[Sx1262] ");
-    tft.setTextColor(ST77XX_WHITE, ST77XX_BLACK);
-    delay(1500);
-
+    tft.setTextColor(ST77XX_WHITE, ST77XX_BLACK);*/
     /*
     C'est le bout trouvé dans le code kikiwi
     pour la config
@@ -39,53 +37,137 @@ void setup_radio()
 
     radio.beginSPI();
     radio.reset();
-    //radio.readStatusCommand(SX126X_GET_STATUS);
-    //radio.SetSleep();
+
+    /* 0x80 */
     radio.SetStandby();
-    radio.SetPacketType(SX126X_PACKET_TYPE_LORA);
-    logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "SX1262", "Setup done");
-    radio.GetPacketType();
-    radio.SetRfFrequency(868000000);
-    /*
-     * Table 13-21: PA Operating Modes with Optimal Settings
-     */
-    radio.SetPaConfig(0x02, 0x02, 0x00, 0x01);
+    /* 0x17 */    
+    radio.GetDeviceErrors();
+    /* 0x07 */
+    radio.ClearDeviceErrors();
 
     /*
-     * Table 13-40: SetTxParams SPI Transaction
+     * On veut que le DIO3 soit utilisé pour l'alimentation du TCXO
      */
-    radio.SetTxParams(0x0A, 0x09);
+    /* 0x97 */
+    radio.SetDIO3AsTCXOCtrl(0x00, 0x140);
 
     /*
      * Table 13-74: SetBufferBaseAddress SPI Transaction
      * De toute façon le bousin ne fera que du Tx
      */
+    /* 0x8f */
     radio.SetBufferBaseAddress(0x00, 0x00);
 
+    /* 0x8a */
+    radio.SetPacketType(SX126X_PACKET_TYPE_GFSK);
+
+    /* 0x93 */
+    radio.SetRxTxFallbackMode(SX126X_RX_TX_FALLBACK_MODE_STDBY_RC);
+    /* 0x88 */
+    radio.SetCadParams(0x03, 0x0d, 0x0a, 0x00, 0x00000000);
+    /* 0x02 */
+    radio.ClearIRQStatus();
+    /* 0x08 */
+    radio.SetDioIrqParams(0x0201, 0x0001, 0x0000, 0x0000);
+    /* 0x89 */
+    radio.Calibrate();
+
+    /* Long temp de LoRa BUSY, 9,1ms environs */
+
+
+    /* 0xc0 */
+    radio.getStatusCommand(SX126X_GET_STATUS);
+    /* 0x96 */
+    radio.SetRegulatorMode(SX126X_REGULATOR_MODE_DCDC);
+    /* 0x11 */
+    radio.GetPacketType();
+    /* 0x8b */
+    radio.SetModulationParams(1200, SX126X_GFSK_PULSE_SHAPE_BT_0_5 ,SX126X_GFSK_BANDWIDTH_156200, 0x00000010);
     /*
-     * Table 13-42: Set Modulation Prameters in GFSK Mode
+     * OCP Configuration
+     * Table 12-1: List of Registers Used for Over Current Protection
+     * 0x18 (60 mA) or 0x38 (140 mA) for SX1262
+     * 0x18 (60 mA) for SX1261
      */
-    radio.SetModulationParams(1200, 0x09, 0x16, 0x10);
-
+    /* 0x0d */
+    radio.regWrite(SX126X_REG_OCP, 0x18);
+    /* 0x11 */
+    radio.GetPacketType();
     /*
      * Table 13-36: SetRfFrequency SPI Transaction
-main/sx1276-Fsk.c:146:    SX1276->RegSyncConfig = RF_SYNCCONFIG_AUTORESTARTRXMODE_WAITPLL_ON | RF_SYNCCONFIG_PREAMBLEPOLARITY_AA |
-main/sx1276-Fsk.c:147:                            RF_SYNCCONFIG_SYNC_ON |
-main/sx1276-Fsk.c:148:                            RF_SYNCCONFIG_SYNCSIZE_4;
-main/sx1276-Fsk.c:150:    SX1276->RegSyncValue1 = 0x69;
-main/sx1276-Fsk.c:151:    SX1276->RegSyncValue2 = 0x81;
-main/sx1276-Fsk.c:152:    SX1276->RegSyncValue3 = 0x7E;
-main/sx1276-Fsk.c:153:    SX1276->RegSyncValue4 = 0x96;
+    main/sx1276-Fsk.c:146:    SX1276->RegSyncConfig = RF_SYNCCONFIG_AUTORESTARTRXMODE_WAITPLL_ON | RF_SYNCCONFIG_PREAMBLEPOLARITY_AA |
+    main/sx1276-Fsk.c:147:                            RF_SYNCCONFIG_SYNC_ON |
+    main/sx1276-Fsk.c:148:                            RF_SYNCCONFIG_SYNCSIZE_4;
      */
-
-    radio.SetPacketParams(0x100, 0x05, 4, 0x00, 0x00, 50, 1);
-    radio.SetDIO3AsTCXOCtrl(0x00, 0x140);
-    // on écrit les valeurs de sync_words voulu, comme dans kikiwi
+    /* 0x8c */
+    radio.SetPacketParams(0x100, 0x05, 4, 0x00, 0x00, 50, 1, 0);
+    /* 0x11 */
+    radio.GetPacketType();
+    /*
+     * on écrit les valeurs de sync_words voulu, comme dans kikiwi
+     Vu dans les sources :
+    main/sx1276-Fsk.c:150:    SX1276->RegSyncValue1 = 0x69;
+    main/sx1276-Fsk.c:151:    SX1276->RegSyncValue2 = 0x81;
+    main/sx1276-Fsk.c:152:    SX1276->RegSyncValue3 = 0x7E;
+    main/sx1276-Fsk.c:153:    SX1276->RegSyncValue4 = 0x96;
+     */
+    /*0x0d 4 fois*/
     radio.regWrite(0x06C0, 0x69);
     radio.regWrite(0x06C1, 0x81);
     radio.regWrite(0x06C2, 0x7E);
     radio.regWrite(0x06C3, 0x96);
+    /*
+     * On veut que le DIO2 soit utilisé pour le RF Switch
+     */
+    /* 0x9d */
+    radio.SetDIO2AsRfSwitchCtrl(1);
+    /* 0x98 */
+    radio.CalibrateImage(0x6b, 0x6f);   // DETERMINER CES VALEURS ?!
+
+    /* UN PEU LONG AUSSI LE LoRa BUSY, environs 6,59ms  */
 
+    /* 0x86 */
+    radio.SetRfFrequency(869450000);
+
+    
+
+    /* 0xc0 */
+    radio.getStatusCommand(SX126X_GET_STATUS);
+    /* 0x0d */
+    radio.regWrite(0x08d8, 0xde);       // A determiner aussi
+    /* 0x1d */
+    /* 0xc0 */
+    radio.getStatusCommand(SX126X_GET_STATUS);
+    /*
+     * Table 13-21: PA Operating Modes with Optimal Settings
+     */
+    /* 0x95 */
+    radio.SetPaConfig(0x02, 0x02, 0x00, 0x01);
+    /*
+     * Table 13-40: SetTxParams SPI Transaction
+     */
+    /* 0x8e */
+    radio.SetTxParams(SX126X_POWER_10_DBM, SX126X_RAMP_TIME_200_US);
+    /* 0x0d */
+    radio.regWrite(0x08e7, 0x18);       // A determiner aussi
+
+/*
+##################3
+JUSQUE IXI TOUT VA BIEN
+
+*/
+
+   /* 0x17 */    
+    radio.GetDeviceErrors();
+    /* 0xc0 */
+    radio.getStatusCommand(SX126X_GET_STATUS);
+    /*
+     * Table 13-42: Set Modulation Prameters in GFSK Mode
+     */
+ 
+    /* 0x11 */
+    radio.GetPacketType();
+    //logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "SX1262", "Setup done");
 }
 
 void setup_gps()
@@ -132,7 +214,7 @@ void setup()
     digitalWrite(VEXT_CTL, HIGH);
     
     setup_tft();
-    setup_gps();
+    //setup_gps();
     setup_radio();
     
     digitalWrite(LED_BUILTIN, LOW);
@@ -154,16 +236,7 @@ void read_nmea(uint32_t ms)
             USBSerial.write(c);
         }
     } while (millis() - start < ms);
-}
 
-void loop() 
-{
-    tft.setTextColor(ST7735_GREEN, ST77XX_BLACK);
-    tft.setCursor(0, 0);
-    tft.print("[GPS NMEA] ");
-    tft.setTextColor(ST7735_WHITE, ST77XX_BLACK);
-
-        
     if (gps.time.isUpdated())
     {
         tft.setCursor(0, 9);
@@ -185,10 +258,53 @@ void loop()
         tft.printf("Alt: %3.0fft ", gps.altitude.feet());
         logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "GPS", "Alt: %3.0fft", gps.altitude.feet());
     }
+    
+    USBSerial.println();
+
+}
+
+void loop() 
+{
+    /*
+    tft.setTextColor(ST7735_GREEN, ST77XX_BLACK);
+    tft.setCursor(0, 0);
+    tft.print("[GPS NMEA] ");
+    tft.setTextColor(ST7735_WHITE, ST77XX_BLACK);
+
+        
+
     tft.fillCircle(150, 10, 2, ST77XX_GREEN);
-    read_nmea(1000);
+    // read_nmea(1000);
     tft.fillCircle(150, 10, 2, ST77XX_WHITE);
-    
-    
+    */
+
+    /* 0x80 */
+    radio.SetStandby();
+
+    /*0x8C*/
+    radio.SetPacketParams(0x100, 0x05, 4, 0x00, 0x00, 50, 1, 0);
+    /*0x08*/
+    radio.SetDioIrqParams(0x0201, 0x0001, 0x0000, 0x0000);
+
+
+    /* 0x8f */
+    radio.SetBufferBaseAddress(0x00, 0x00);
+    /*0x0e*/
+    radio.WriteBuffer("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAB");
+    radio.ClearIRQStatus();
+    radio.regRead(0x0889);
+
+    radio.getStatusCommand(0);
+    radio.GetPacketType();
+
+    radio.regWrite(SX126X_REG_TX_MODULATION, 0x04);
+    radio.SetTx(0);
+
+
+    delay(250);
+
+// shutdown the ESP32 to save power
+
+
 
 }

+ 168 - 35
src/sx1262.cpp

@@ -19,10 +19,13 @@ void Sx1262::beginSPI() const
 {
   SPI.begin(Sx1262::getSclk(), Sx1262::getMiso(), Sx1262::getMosi(), Sx1262::getCs());
   pinMode(Sx1262::getCs(), OUTPUT);
+  pinMode(Sx1262::getRst(), OUTPUT);
   digitalWrite(Sx1262::getCs(), HIGH);
   pinMode(Sx1262::getBusy(), INPUT);
+  pinMode(Sx1262::getDio(1), INPUT);
 };
 
+
 /**
  * @brief Get the reset pin.
  * @return The reset pin number.
@@ -101,15 +104,12 @@ uint8_t Sx1262::getBusy() const
  */
 void Sx1262::reset() const
 {
-  for (uint32_t delay = 0; delay < 0xFFF; delay++)
-  {
-    /// The reset pin operates with inverted logic
     digitalWrite(_rst, LOW);
-  }
-  for (uint32_t delay = 0; delay < 0xFFFFF; delay++)
-  {
+    delay(250);
     digitalWrite(_rst, HIGH);
-  }
+    while (digitalRead(_busy) == HIGH) {
+      delay(1);
+    }
 };
 
 /**
@@ -127,6 +127,12 @@ uint8_t Sx1262::regRead(uint16_t reg) const
   SPI.transfer(SX126X_READ_REGISTER); ///< Write the register address with a read-enabled flag
   SPI.transfer((reg >> 8) & 0xFF);    ///< Write the register address bit [15:8]
   SPI.transfer(reg & 0xFF);           ///< Write the register address bit [7:0]
+
+  if (reg == 0x0889) {  //trash function
+    SPI.transfer(0x00);
+    SPI.transfer(0x00);
+    return 0x00;
+  }
   // read SPI.transfert until it equals 0x00
   if (SPI.transfer(0x00) == 0xAA) {
     ret = SPI.transfer(0x00); ///< Read the value at the register address
@@ -176,11 +182,12 @@ void Sx1262::setOpMode(uint8_t opcode, uint8_t *payload, uint8_t size) const
     usleep(10);
   }
   logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "SX1262", "setOpMode with opcode 0x%02X", opcode);
-  for (uint8_t i=0; i < size; i++) {
+  for (uint8_t i = 0; i < size; i++) {
     USBSerial.print("0x");
-    USBSerial.println(payload[i], HEX);
+    USBSerial.print(payload[i], HEX);
     USBSerial.print(" ");
   }
+  USBSerial.println();
 };
 
 /*
@@ -277,7 +284,6 @@ void Sx1262::SetSleep() const
 {
   uint8_t *buffer = new uint8_t[1];
   buffer[0] = 0x00;
-  logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "SX1262", "SetSleep with opcode 0x%02X and parameter 0x%02X", SX126X_SET_SLEEP, buffer[0]);
   setOpMode(SX126X_SET_SLEEP, buffer, sizeof(buffer));
 };
 
@@ -288,11 +294,9 @@ void Sx1262::SetSleep() const
 void Sx1262::SetStandby() const
 {
   uint8_t *buffer = new uint8_t[1];
-  buffer[0] = 0x00;
+  buffer[0] = 0x00 ;
+  // return le number of bytes written in the array buffer
   setOpMode(SX126X_SET_STANDBY, buffer , 1);
-  logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "SX1262", "SetStandby with opcode 0x%02X and parameter 0x%02X", SX126X_SET_STANDBY, buffer[0]);  
-  getStatusCommand(SX126X_GET_STATUS);
-
 };
 
 void Sx1262::SetFS() const
@@ -336,19 +340,16 @@ void Sx1262::GetPacketType() const
 void Sx1262::SetRfFrequency(uint32_t freq) const
 {
   uint8_t *buffer = new uint8_t[4];
+  /*
   buffer[0] = (freq >> 24) & 0xFF;
   buffer[1] = (freq >> 16) & 0xFF;
   buffer[2] = (freq >> 8) & 0xFF;
   buffer[3] = freq & 0xFF;
-  logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "SX1262", "SetRfFrequency with opcode 0x%02X and parameters :", SX126X_SET_RF_FREQUENCY);
-  USBSerial.print("0x");
-  USBSerial.print(buffer[0], HEX);
-  USBSerial.print(" 0x");
-  USBSerial.print(buffer[1], HEX);
-  USBSerial.print(" 0x");
-  USBSerial.print(buffer[2], HEX);
-  USBSerial.print(" 0x");
-  USBSerial.print(buffer[3], HEX);
+  */
+  buffer[3] = 0x80;
+  buffer[2] = 0x66;
+  buffer[1] = 0x58;
+  buffer[0] = 0x36;
   setOpMode(SX126X_SET_RF_FREQUENCY, buffer, 4);
 }
 
@@ -416,9 +417,17 @@ void Sx1262::SetBufferBaseAddress(uint8_t txBaseAddress, uint8_t rxBaseAddress)
  * @brief Set WriteBuffer
  * Table 13-26: WriteBuffer SPI Transaction in datasheee
  */
-void Sx1262::WriteBuffer(uint8_t *buffer, uint8_t size) const
-{
-  setOpMode(SX126X_WRITE_BUFFER, buffer, size);
+void Sx1262::WriteBuffer(const char* buffer) const
+{ 
+  size_t length = strlen(buffer);
+  // on veut ajouter un byte 0x00 au début de notre buffer
+  // qui indique l'offset du buffer pour écriture
+  uint8_t *payload = new uint8_t[length];
+  payload[0] = 0x00;
+  for (uint8_t i = 1; i <= length; i++) {
+    payload[i] = buffer[i-1];
+  }
+  setOpMode(SX126X_WRITE_BUFFER, (uint8_t*)payload, length+1);
 }
 
 /*
@@ -426,9 +435,11 @@ void Sx1262::WriteBuffer(uint8_t *buffer, uint8_t size) const
  */
 void Sx1262::SetModulationParams(uint32_t bitrate, uint8_t pulseShape, uint8_t bandwidht, uint32_t fdev) const
 {
+  // Table 13-43: Bitrate - GFSK ModParam1, ModParam2 & ModParam3
+  uint32_t newBr = (SX126X_CRYSTAL_FREQ * 1000000.0 * 32.0) / (bitrate * 1000.0);
   uint8_t *buffer = new uint8_t[8];
-  buffer[0] = (bitrate >> 16) & 0xFF;
-  buffer[1] = (bitrate >> 8) & 0xFF;
+  buffer[0] = (newBr >> 16) & 0xFF;
+  buffer[1] = (newBr >> 8) & 0xFF;
   buffer[2] = bitrate & 0xFF;
   buffer[3] = pulseShape;
   buffer[4] = bandwidht;
@@ -441,9 +452,9 @@ void Sx1262::SetModulationParams(uint32_t bitrate, uint8_t pulseShape, uint8_t b
 /*
  * @brief SetPacketParams
 */
-void Sx1262::SetPacketParams(uint16_t preambleLength, uint8_t PreambleDetectorLength, uint8_t SyncWordLength, uint8_t AddrComp, uint8_t PacketType, uint8_t PayloadLength, uint8_t CRCType) const
+void Sx1262::SetPacketParams(uint16_t preambleLength, uint8_t PreambleDetectorLength, uint8_t SyncWordLength, uint8_t AddrComp, uint8_t PacketType, uint8_t PayloadLength, uint8_t CRCType, uint8_t Whitening) const
 {
-  uint8_t *buffer = new uint8_t[8];
+  uint8_t *buffer = new uint8_t[9];
   buffer[0] = (preambleLength >> 8) & 0xFF;
   buffer[1] = preambleLength & 0xFF;
   buffer[2] = PreambleDetectorLength;
@@ -452,9 +463,21 @@ void Sx1262::SetPacketParams(uint16_t preambleLength, uint8_t PreambleDetectorLe
   buffer[5] = PacketType;
   buffer[6] = PayloadLength;
   buffer[7] = CRCType;
-  setOpMode(SX126X_SET_PKT_PARAMS, buffer, 8);
+  buffer[8] = 0x00;
+  setOpMode(SX126X_SET_PKT_PARAMS, buffer, 9);
 }
 
+/* 
+ * @brief SetDIO2AsRfSwitchCtrl
+ */
+void Sx1262::SetDIO2AsRfSwitchCtrl(uint8_t enable) const
+{
+  uint8_t *buffer = new uint8_t[1];
+  buffer[0] = enable;
+  setOpMode(SX126X_SET_DIO2_AS_RF_SWITCH_CTRL, buffer, 1);
+}
+
+
 /*
  * @brief SetDIO3AsTCXOCtrl
  */
@@ -471,8 +494,118 @@ void Sx1262::SetDIO3AsTCXOCtrl(uint8_t tcxoVoltage, uint32_t timeout) const
 /*
  * @brief SetTx
  */
-void Sx1262::SetTx() const
+void Sx1262::SetTx(uint32_t timeout) const
 {
-  uint8_t *buffer = new uint8_t[0];
-  setOpMode(SX126X_SET_TX, buffer, 0);
-}
+  uint8_t *buffer = new uint8_t[3];
+  buffer[0] = (timeout >> 16) & 0xFF;
+  buffer[1] = (timeout >> 8) & 0xFF;
+  buffer[2] = timeout & 0xFF;
+  setOpMode(SX126X_SET_TX, buffer, 3);
+}
+
+/*
+ * @brief GetDeviceErrors
+ */
+void Sx1262::GetDeviceErrors() const
+{
+  uint8_t *buffer = new uint8_t[3];
+  buffer[0] = 0x00;
+  buffer[1] = 0x00;
+  buffer[2] = 0x00;
+  setOpMode(SX126X_GET_DEVICE_ERRORS, buffer, 3);
+}
+
+/*
+ * @brief ClearDeviceErrors
+ */
+void Sx1262::ClearDeviceErrors() const
+{
+  uint8_t *buffer = new uint8_t[2];
+  buffer[0] = 0x00;
+  buffer[1] = 0x00;
+  setOpMode(SX126X_CLR_DEVICE_ERRORS, buffer, 2);
+}
+
+/*
+ * @brief SetRxTxFallbackMode
+ */
+void Sx1262::SetRxTxFallbackMode(uint8_t fallback_mode) const
+{
+  uint8_t *buffer = new uint8_t[1];
+  buffer[0] = fallback_mode;
+  setOpMode(SX126X_SET_RX_TX_FALLBACK_MODE, buffer, 1);
+}
+
+/*
+ * @brief ClearIRQStatus
+ */
+void Sx1262::ClearIRQStatus() const
+{
+  uint8_t *buffer = new uint8_t[2];
+  buffer[0] = 0x43;
+  buffer[1] = 0xff;
+  setOpMode(SX126X_CLR_IRQ_STATUS, buffer, 2);
+}
+
+/*
+ * @brief SetDioIrqParams
+ */
+void Sx1262::SetDioIrqParams(uint16_t irqMask, uint16_t dio1Mask, uint16_t dio2Mask, uint16_t dio3Mask) const
+{
+  uint8_t *buffer = new uint8_t[8];
+  buffer[0] = (irqMask >> 8) & 0xFF;
+  buffer[1] = irqMask & 0xFF;
+  buffer[2] = (dio1Mask >> 8) & 0xFF;
+  buffer[3] = dio1Mask & 0xFF;
+  buffer[4] = (dio2Mask >> 8) & 0xFF;
+  buffer[5] = dio2Mask & 0xFF;
+  buffer[6] = (dio3Mask >> 8) & 0xFF;
+  buffer[7] = dio3Mask & 0xFF;
+  setOpMode(SX126X_SET_DIO_IRQ_PARAMS, buffer, 8);
+}
+
+/*
+ * @brief Calibrate
+ */
+void Sx1262::Calibrate() const
+{
+  uint8_t *buffer = new uint8_t[1];
+  buffer[0] = 0x7f;
+  setOpMode(SX126X_CALIBRATE, buffer, 1);
+}
+
+/* @brief CalibrateImage */
+void Sx1262::CalibrateImage(uint8_t freq1, uint8_t freq2) const
+{
+  uint8_t *buffer = new uint8_t[2];
+  buffer[0] = freq1;
+  buffer[1] = freq2;
+  setOpMode(SX126X_CALIBRATE_IMAGE, buffer, 2);
+}
+
+/*
+ * @brief SetRegulatorMode
+ */
+void Sx1262::SetRegulatorMode(uint8_t mode) const
+{
+  uint8_t *buffer = new uint8_t[1];
+  buffer[0] = mode;
+  setOpMode(SX126X_SET_REGULATOR_MODE, buffer, 1);
+}
+
+/*
+ * @brief SetCadParams
+ */
+void Sx1262::SetCadParams(uint8_t cadSymbolNum, uint8_t cadDetPeak, uint8_t cadDetMin, uint8_t cadExitMode, uint32_t cadTimeout) const
+{
+  uint8_t *buffer = new uint8_t[6];
+  buffer[0] = cadSymbolNum;
+  buffer[1] = cadDetPeak;
+  buffer[2] = cadDetMin;
+  buffer[3] = cadExitMode;
+  buffer[4] = (cadTimeout >> 16) & 0xFF;
+  buffer[5] = (cadTimeout >> 8) & 0xFF;
+  buffer[6] = cadTimeout & 0xFF;
+  setOpMode(SX126X_SET_CAD_PARAMS, buffer, 6);
+}
+

+ 21 - 4
src/sx1262.h

@@ -116,12 +116,29 @@ class Sx1262
     void SetPaConfig(uint8_t paDutyCycle, uint8_t hpMax, uint8_t deviceSel, uint8_t paLut) const;
     void SetTxParams(uint8_t power, uint8_t rampTime) const;
     void SetBufferBaseAddress(uint8_t txBaseAddress, uint8_t rxBaseAddress) const;
-    void WriteBuffer(uint8_t *buffer, uint8_t size) const;
+    void WriteBuffer(const char* buffer) const;
 
     void SetModulationParams(uint32_t bitrate, uint8_t pulseShape, uint8_t bandwidht, uint32_t fdev) const;
-    void SetPacketParams(uint16_t preambleLength, uint8_t PreambleDetectorLength, uint8_t SyncWordLength, uint8_t AddrComp, uint8_t PacketType, uint8_t PayloadLength, uint8_t CRCType) const;
-    void SetDIO3AsTCXOCtrl(uint8_t tcxoVoltage, uint8_t timeout) const;
-    void SetTx() const;
+    void SetPacketParams(uint16_t preambleLength, uint8_t PreambleDetectorLength, uint8_t SyncWordLength, uint8_t AddrComp, uint8_t PacketType, uint8_t PayloadLength, uint8_t CRCType, uint8_t Whitening) const;
+    void SetDIO2AsRfSwitchCtrl(uint8_t enable) const;
+    void SetDIO3AsTCXOCtrl(uint8_t tcxoVoltage, uint32_t timeout) const;
+    void SetTx(uint32_t timeout) const;
+    void GetDeviceErrors() const;
+    void ClearDeviceErrors() const;
+    void SetRxTxFallbackMode(uint8_t fallback_mode) const;
+    void ClearIRQStatus() const;
+    void SetDioIrqParams(uint16_t irqMask, uint16_t dio1Mask, uint16_t dio2Mask, uint16_t dio3Mask) const;
+    void Calibrate() const;
+    void CalibrateImage(uint8_t freq1, uint8_t freq2) const;
+    void SetRegulatorMode(uint8_t mode) const;
+    void SetCadParams(uint8_t cadSymbolNum, uint8_t cadDetPeak, uint8_t cadDetMin, uint8_t cadExitMode, uint32_t cadTimeout) const;
+
+
+
+
+    
+
+
 
 
   private:

+ 79 - 0
src/sx1262regs.h

@@ -62,6 +62,85 @@
 #define SX126X_PACKET_TYPE_LORA              0x01
 #define SX126X_PACKET_TYPE_LR_FHSS           0x03
 
+// Table 13-23: Fallback Mode Definition
+#define SX126X_RX_TX_FALLBACK_MODE_FS        0x40
+#define SX126X_RX_TX_FALLBACK_MODE_STDBY_XOSC 0x30
+#define SX126X_RX_TX_FALLBACK_MODE_STDBY_RC  0x20
+
+// Table 13-16: SetRegulatorMode SPI Transaction
+#define SX126X_REGULATOR_MODE_LDO            0x00
+#define SX126X_REGULATOR_MODE_DCDC           0x01
+
+// Table 13-43: Bitrate - GFSK ModParam1, ModParam2 & ModParam3
+#define SX126X_CRYSTAL_FREQ                 32.0
+
+// Table 13-44: Set Modulation Prameters in GFSK Mode
+#define SX126X_GFSK_PULSE_SHAPE_NO_FILTER   0x00
+#define SX126X_GFSK_PULSE_SHAPE_BT_0_3      0x08
+#define SX126X_GFSK_PULSE_SHAPE_BT_0_5      0x09
+#define SX126X_GFSK_PULSE_SHAPE_BT_0_7      0x0A
+#define SX126X_GFSK_PULSE_SHAPE_BT_1_0      0x0B
+
+// Table 13-45: GFSK ModParam5 - Bandwidth
+#define SX126X_GFSK_BANDWIDTH_4800          0x1F
+#define SX126X_GFSK_BANDWIDTH_5800          0x17
+#define SX126X_GFSK_BANDWIDTH_7300          0x0F
+#define SX126X_GFSK_BANDWIDTH_9700          0x1E
+#define SX126X_GFSK_BANDWIDTH_11700         0x16
+#define SX126X_GFSK_BANDWIDTH_14600         0x0E
+#define SX126X_GFSK_BANDWIDTH_19500         0x1D
+#define SX126X_GFSK_BANDWIDTH_23400         0x15
+#define SX126X_GFSK_BANDWIDTH_29300         0x0D
+#define SX126X_GFSK_BANDWIDTH_39000         0x1C
+#define SX126X_GFSK_BANDWIDTH_46900         0x14
+#define SX126X_GFSK_BANDWIDTH_58600         0x0C
+#define SX126X_GFSK_BANDWIDTH_78000         0x1B
+#define SX126X_GFSK_BANDWIDTH_93800         0x13
+#define SX126X_GFSK_BANDWIDTH_117300        0x0B
+#define SX126X_GFSK_BANDWIDTH_156200        0x1A
+#define SX126X_GFSK_BANDWIDTH_187200        0x12
+#define SX126X_GFSK_BANDWIDTH_234300        0x0A
+#define SX126X_GFSK_BANDWIDTH_312000        0x19
+#define SX126X_GFSK_BANDWIDTH_373600        0x11
+#define SX126X_GFSK_BANDWIDTH_467000        0x09
+
+/*
+The output power is defined as power in dBm in a range of
+•
+ - 17 (0xEF) to +14 (0x0E) dBm by step of 1 dB if low power PA is selected
+•
+ - 9 (0xF7) to +22 (0x16) dBm by step of 1 dB if high power PA is selected
+*/
+// Table 13-40: SetTxParams SPI Transaction
+#define SX126X_POWER_22_DBM                 0x16
+#define SX126X_POWER_20_DBM                 0x14
+#define SX126X_POWER_17_DBM                 0x11
+#define SX126X_POWER_15_DBM                 0x0F
+#define SX126X_POWER_13_DBM                 0x0D
+#define SX126X_POWER_10_DBM                 0x0A
+#define SX126X_POWER_7_DBM                  0x07
+#define SX126X_POWER_5_DBM                  0x05
+#define SX126X_POWER_2_DBM                  0x02
+#define SX126X_POWER_0_DBM                  0x00
+#define SX126X_POWER_M3_DBM                 0xFD
+#define SX126X_POWER_M6_DBM                 0xFA
+#define SX126X_POWER_M9_DBM                 0xF7
+#define SX126X_POWER_M12_DBM                0xF4
+#define SX126X_POWER_M15_DBM                0xF1
+#define SX126X_POWER_M17_DBM                0xEF
+
+
+
+// Table 13-41: RampTime Definition
+#define SX126X_RAMP_TIME_10_US              0x00
+#define SX126X_RAMP_TIME_20_US              0x01
+#define SX126X_RAMP_TIME_40_US              0x02
+#define SX126X_RAMP_TIME_80_US              0x03
+#define SX126X_RAMP_TIME_200_US             0x04
+#define SX126X_RAMP_TIME_800_US             0x05
+#define SX126X_RAMP_TIME_1700_US            0x06
+#define SX126X_RAMP_TIME_3400_US            0x07
+