瀏覽代碼

second post

Pierre Bourdin 2 月之前
父節點
當前提交
dbee31c2b5
共有 4 個文件被更改,包括 297 次插入193 次删除
  1. 34 10
      src/main.cpp
  2. 227 170
      src/sx1262.cpp
  3. 27 13
      src/sx1262.h
  4. 9 0
      src/sx1262regs.h

+ 34 - 10
src/main.cpp

@@ -8,18 +8,47 @@
 TinyGPSPlus gps;
 Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS,  TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);
 logging::Logger logger;
-Sx1262 radio = Sx1262(SX1262_RST, SX1262_SCK, SX1262_MOSI, SX1262_MISO, SX1262_NSS ,SX1262_DIO1);
+Sx1262 radio = Sx1262(SX1262_RST, SX1262_SCK, SX1262_MOSI, SX1262_MISO, SX1262_NSS ,SX1262_DIO1, SX1262_BUSY);
 
 void setup_radio()
 {
-    radio.beginSPI();
     tft.setTextColor(ST77XX_GREEN, ST77XX_BLACK);
     tft.setCursor(0, 12);
     tft.print("[Sx1262] ");
     tft.setTextColor(ST77XX_WHITE, ST77XX_BLACK);
-    delay(3000);
-    logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "[SX1262]", "Setup done");
-   
+    delay(1500);
+
+    radio.beginSPI();
+    radio.reset();
+    //radio.readStatusCommand(SX126X_GET_STATUS);
+    //radio.SetSleep();
+    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);
+
+    /*
+     * Table 13-40: SetTxParams SPI Transaction
+     */
+    radio.SetTxParams(0x0A, 0x09);
+
+    /*
+     * Table 13-74: SetBufferBaseAddress SPI Transaction
+     * De toute façon le bousin ne fera que du Tx
+     */
+    radio.SetBufferBaseAddress(0x00, 0x00);
+
+    /*
+     * Table 13-42: Set Modulation Prameters in GFSK Mode
+     */
+    radio.SetModulationParams(48000, 0x09, 0x16, 0x10);
+
+
 }
 
 void setup_gps()
@@ -70,13 +99,8 @@ void setup()
     setup_radio();
     
     digitalWrite(LED_BUILTIN, LOW);
-    delay(3000);
     tft.fillScreen(ST77XX_BLACK);
-    delay(1000);
     tft.fillCircle(150, 10, 2, ST77XX_WHITE);
-    
-
-
 }
 
 void read_nmea(uint32_t ms)

+ 227 - 170
src/sx1262.cpp

@@ -1,13 +1,6 @@
 /**
  * @file sx1262.cpp
  * @brief implementation file for the SX1262 transceiver class.
- *
- * @author Julia CABARBAYE (Student, ENSIL-ENSCI [ELT], France)
- * @author Adrien CHEVRIER (Student, ENSIL-ENSCI [ELT], France)
- *
- * @date Created on: 2024-11-25
- * @date Last updated: 2025-01-05
- *
  * @see sx1262.h
  * @see { @link https://www.semtech.fr/products/wireless-rf/lora-connect/sx1262 }
  * for detailed information about the SX1262.  
@@ -28,6 +21,7 @@ void Sx1262::beginSPI() const
   SPI.begin(Sx1262::getSclk(), Sx1262::getMiso(), Sx1262::getMosi(), Sx1262::getCs());
   pinMode(Sx1262::getCs(), OUTPUT);
   digitalWrite(Sx1262::getCs(), HIGH);
+  pinMode(Sx1262::getBusy(), INPUT);
 };
 
 /**
@@ -93,6 +87,16 @@ uint8_t Sx1262::getCs() const
   return _cs;
 };
 
+/**
+ * @brief Get the busy pin.
+ * @return The busy pin number.
+ */
+uint8_t Sx1262::getBusy() const
+{
+  return _busy;
+};
+
+
 /**
  * @brief Reset the Sx1262 device.
  */
@@ -109,29 +113,6 @@ void Sx1262::reset() const
   }
 };
 
-/**
- * @brief Introduce an uninterruptible delay.
- *
- * @details This member calls `digitalRead()` to read the SX1276 RST pin value.
- * `digitalRead()` utilizes interrupts to work. When calling `wait()`,
- * this ensures that other interrupt events are temporarily blocked,
- * allowing the SX1276 registers to be configured without interference.
- *
- * @warning This member should only be used within other members of the
- * Sx1276 class, as blocking interrupts may cause issues with FreeRTOS.
- * Make sure that the delay remains short if you plan to use them in
- * members that would be executed in a FreeRTOS task.
- *
- * @param delay The delay duration in loop rounds.
- */
-void Sx1262::wait(uint32_t delay) const
-{
-  for (uint32_t i = 0; i < delay; i++)
-  {
-    digitalRead(_rst);
-  }
-};
-
 /**
  * @brief Read a register value.
  * @param reg The register address.
@@ -177,6 +158,32 @@ void Sx1262::regWrite(uint16_t reg, uint8_t val) const
   digitalWrite(_cs, HIGH);  ///< Raise Chip Select pin
 };
 
+void Sx1262::setOpMode(uint8_t opcode, uint8_t *payload, uint8_t size) const
+{
+  digitalWrite(_cs, LOW);
+  SPI.transfer(opcode);
+  for (uint8_t i = 0; i < size; i++) {
+    SPI.transfer(payload[i]);
+  }
+  digitalWrite(_cs, HIGH);
+
+  // parce que pendant moins de 1us busy pin est à 0 après que le CS soit à 1
+  // le while qui suit est donc inutile ... :)
+  usleep(10);
+
+  // on attend que le busy pin soit à 0, temps de traîtement tout ça
+  // 8.3.1 BUSY Control Line in datasheet SX1261-2
+  while (digitalRead(_busy) == HIGH) {
+    usleep(10);
+  }
+  logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "SX1262", "setOpMode with opcode 0x%02X", opcode);
+  for (uint8_t i=0; i < size; i++) {
+    USBSerial.print("0x");
+    USBSerial.println(payload[i], HEX);
+    USBSerial.print(" ");
+  }
+};
+
 /*
  * @brief Method to read the Status Command Communication
  * 11.5 Status Commands in datasheet SX1261-2
@@ -189,41 +196,24 @@ void Sx1262::regWrite(uint16_t reg, uint8_t val) const
  * puis on va lire le reste de la réponse
  * 
  */
-uint8_t Sx1262::readStatusCommand(uint8_t opcode) const
+uint8_t Sx1262::getStatusCommand(uint8_t opcode) const
 {
   digitalWrite(_cs, LOW);
   SPI.transfer(opcode);
   uint8_t statusByte = SPI.transfer(0x00);
-
-  // Le 1er byte de réponse c'est le statusCode
-  // on va parser tout ça
-  uint8_t cmdStatus = (statusByte & 0x0E) >> 1;
-  uint8_t cmdChipMode = (statusByte & 0x70) >> 4;
-  logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "SX1262", "cmdStatus : 0x%02X", cmdStatus);
-  logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "SX1262", "cmdChipMode : 0x%02X", cmdChipMode);
-
-  //on parse le status byte pour vérifier que tout s'est bien passé
-  if (cmdStatus == 0x02) logger.log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, "[SX1262]", "cmdStatus : Data is available to host");
-  else if (cmdStatus == 0x03) logger.log(logging::LoggerLevel::LOGGER_LEVEL_WARN, "[SX1262]", "cmdStatus : Command timeout");
-  else if (cmdStatus == 0x04) logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, "[SX1262]", "cmdStatus : Command processing error");
-  else if (cmdStatus == 0x05) logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, "[SX1262]", "cmdStatus : Failure to execute command");
-  else if (cmdStatus == 0x06) logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "[SX1262]", "cmdStatus : Command TX done");
-  else return -1; 
-  
-  // on parse le mode du chip pour vérifier que tout s'est bien passé
-  if (cmdChipMode == 0x02) logger.log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, "[SX1262]", "cmdChipMode : STBY_RC ");
-  else if (cmdChipMode == 0x03) logger.log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, "[SX1262]", "cmdChipMode : STBY_XOSC ");
-  else if (cmdChipMode == 0x04) logger.log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, "[SX1262]", "cmdChipMode : FS");
-  else if (cmdChipMode == 0x05) logger.log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, "[SX1262]", "cmdChipMode : RX");
-  else if (cmdChipMode == 0x06) logger.log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, "[SX1262]", "cmdChipMode : TX");
-  else return -1;
-
   switch (opcode) {
+
+    case (SX126X_GET_STATUS): {
+      digitalWrite(_cs, HIGH);
+      break;
+    }
+    
+    
     case (SX126X_GET_RX_BUFFER_STATUS): {
       uint8_t rxBufferStatus = SPI.transfer(0x00);
       uint8_t rxBufferPayloadLenghtRx = SPI.transfer(0x00);
       uint8_t rxBufferRxStartBufferPointer = SPI.transfer(0x00);
-      // todo print the log
+      digitalWrite(_cs, HIGH);
       break;
     }
 
@@ -231,13 +221,13 @@ uint8_t Sx1262::readStatusCommand(uint8_t opcode) const
       uint8_t rxStatus = SPI.transfer(0x00);
       uint8_t rssiSync = SPI.transfer(0x00);
       uint8_t rssiAvg = SPI.transfer(0x00);
-      // todo print the log
+      digitalWrite(_cs, HIGH);
       break;
     }
 
     case (SX126X_GET_RSSI_INST): {
       uint8_t rssiValue = SPI.transfer(0x00);
-      // todo print the log 
+      digitalWrite(_cs, HIGH);
       break;
     }
 
@@ -248,146 +238,213 @@ uint8_t Sx1262::readStatusCommand(uint8_t opcode) const
       uint8_t statsPktError1 = SPI.transfer(0x00);
       uint8_t NbPktLengthError2 = SPI.transfer(0x00);
       uint8_t NbPktLengthError1 = SPI.transfer(0x00);
-      // todo print the log
+      digitalWrite(_cs, HIGH);
       break;
     }
 
-    default:
-      return -1;
-    
   }
+
+
   // hé oui, on lache le trig ;)
-  digitalWrite(_cs, HIGH);
+
+ // Le 1er byte de réponse c'est le statusCode
+  // on va parser tout ça
+  uint8_t cmdStatus = 0;
+  uint8_t cmdChipMode = 0;
+  cmdStatus = (statusByte & 0x0E) >> 1;
+  cmdChipMode = (statusByte & 0x70) >> 4;
+  logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "SX1262", "cmdStatus : 0x%02X", cmdStatus);
+  logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "SX1262", "cmdChipMode : 0x%02X", cmdChipMode);
+
+  //on parse le status byte pour vérifier que tout s'est bien passé
+  if (cmdStatus == 0x02) logger.log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, "SX1262", "cmdStatus : Data is available to host");
+  else if (cmdStatus == 0x03) logger.log(logging::LoggerLevel::LOGGER_LEVEL_WARN, "SX1262", "cmdStatus : Command timeout");
+  else if (cmdStatus == 0x04) logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, "SX1262", "cmdStatus : Command processing error");
+  else if (cmdStatus == 0x05) logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, "SX1262", "cmdStatus : Failure to execute command");
+  else if (cmdStatus == 0x06) logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "SX1262", "cmdStatus : Command TX done");
+  else return -1; 
+  
+  // on parse le mode du chip pour vérifier que tout s'est bien passé
+  if (cmdChipMode == 0x02) logger.log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, "SX1262", "cmdChipMode : STBY_RC ");
+  else if (cmdChipMode == 0x03) logger.log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, "SX1262", "cmdChipMode : STBY_XOSC ");
+  else if (cmdChipMode == 0x04) logger.log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, "SX1262", "cmdChipMode : FS");
+  else if (cmdChipMode == 0x05) logger.log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, "SX1262", "cmdChipMode : RX");
+  else if (cmdChipMode == 0x06) logger.log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, "SX1262", "cmdChipMode : TX");
+  else return -1;
+
+
+
   return 0;
 };
 
 /**
- * @brief Set the transceiver carrier frequency to work on.
- * @param freq The carrier frequency in Hz.
- * @return `0` if successful, `-1` otherwise.
+ * @brief Set the transceiver in SLEEP mode
+ * Table 13-2: Sleep Mode Definition in datasheet
  */
-int8_t Sx1262::setFreq(uint32_t freq) const
+void Sx1262::SetSleep() const
 {
-  int8_t exitCode = 0;
-  /**
-   * @details Carrier frequency conversion for the SX1262 registers
-   * as specified into the datasheet. The covertyed frequency
-   * must stands on 24 bits.
-   */
-  /*
-  uint32_t tmpFreq = static_cast<uint32_t>(
-    round(freq * sx1262::radio_div / sx1262::radio_clk)
-  );
-  if (tmpFreq > 0x00FFFFFF)
-  {
-    /// Handeling too high converted carrier frequency
-    tmpFreq = 0x00FFFFFF;
-    exitCode = -1;
-  }
-  */
-  /**
-   * @details Extract the frequency bytes (MSB, MID, LSB) using bitwise masks.
-   * 
-   * @example With the carrier frequency MSB
-   *
-   * tempFreq: 0x0012AC7E
-   *       &   0x00FF0000 (bitwise AND to take the MSB)
-   *       --------------
-   *           0x00120000
-   *       >> 16          (right shifting on 16 bits)
-   *       --------------
-   *           0x00000012 => REG_FRFMSB
-   */
-  /*
-  uint8_t msb = (tmpFreq & 0x00FF0000) >> 16;
-  regWrite(REG_FRFMSB, msb);
-  uint8_t mid = (tmpFreq & 0x0000FF00) >> 8;
-  regWrite(REG_FRFMID, mid);
-  uint8_t lsb = tmpFreq & 0x000000FF;
-  regWrite(REG_FRFLSB, lsb);
-  */
-  return exitCode;
+  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));
 };
 
-
 /**
- * @brief Get the FIFO buffer size.
- * @return The FIFO size in bytes.
+ * @brief Set the transceiver in STANDBY_RC mode
+ * Table 13-3: Standby_RC Mode Definition in datasheet
  */
-uint8_t Sx1262::getFifoSize() const
+void Sx1262::SetStandby() const
 {
-  return 0; //regRead(SX126X_REG_RXTX_PAYLOAD_LEN);
+  uint8_t *buffer = new uint8_t[1];
+  buffer[0] = 0x00;
+  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
+{
+  logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "SX1262", "SetFS with opcode 0x%02X", SX126X_SET_FS);
+  uint8_t *buffer = new uint8_t[1];
+  setOpMode(SX126X_SET_FS, buffer, 0);
+};
 
 /**
- * @brief Perform a FIFO read/write operation.
- *
- * @param mode The operation mode (0x00 to read, 0xFF to write).
- * @param buff The buffer to read/write (as a span of bytes).
- *
- * @return `0` if successful.
- * @return `-1` if the buffer is too short.
- * @return `-2` if the operation mode is wrong.
- *
- * @note A writting should be performed only if the SX1276 is in idle mode.
- * @see At namespace sx1276: fifo_read and fifo_write
- * @see rxToStdby() 
+ * @brief Set the Packet Type of the transceiver
+ * Table 13-4-2: Packet Type Definition in datasheet
+ * 
  */
-int8_t Sx1262::fifo(uint8_t mode, uint8_t *buff) const
+void Sx1262::SetPacketType(uint8_t type) const
 {
-  int8_t exitCode = 0;
-  /*
-  uint8_t sz = getFifoSize();
-  if (mode == sx1262::fifo_read)
-  {
-    if (sz + 1 <= sizeof(buff))
-    {
-      /// Reading by using special internal FIFO buffer SPI burst method
-      digitalWrite(_cs, LOW);
-      SPI.transfer(REG_FIFO);
-      for (uint8_t i = 0; i < sz; i++)
-      {
-        /// Byte-per-byte reading without the need to reselect the address
-        buff[i] = SPI.transfer(0x00);
-      }
-      digitalWrite(_cs, HIGH);
-    }
-    else
-      /// Handeling too short buffer
-      exitCode = -1;
-  }
-  else if (mode == sx1262::fifo_write)
-  {
-    /// Writting by using special internal FIFO buffer SPI burst method
-    regWrite(REG_OPMODE, 0x01);
-    wait(0xFFFF);
-    digitalWrite(_cs, LOW);
-    SPI.transfer(REG_FIFO | 0x80);
-    for (uint8_t i = 0; i < sz; i++)
-    {
-      /// Byte-per-byte writting without the need to reselect the address
-      SPI.transfer(buff[i]);
-    }
-    digitalWrite(_cs, HIGH);
-  }
-  else
-    /// Handeling wrong modes
-    exitCode = -2;
+  uint8_t *parameter = new uint8_t[1];
+  parameter[0] = type;
+  setOpMode(SX126X_SET_PKT_TYPE, parameter, 1);
+  logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "SX1262", "SetPacketType with opcode 0x%02X and parameter 0x%02X", SX126X_SET_PKT_TYPE, parameter[0]);
+};
 
-  */
-  return exitCode;
+/*
+ * @brief Get the Packet Type of the transceiver
+ * Table 13-4-3: Packet Type Definition in datashee
+ */
+void Sx1262::GetPacketType() const
+{
+  // define an array of uint8_t of 2 bytes
+  uint8_t *parameter = new uint8_t[2];
+  parameter[0] = 0x00;
+  parameter[1] = 0x00;
+  setOpMode(SX126X_GET_PKT_TYPE, parameter, 2);
 };
 
 
+/**
+ * @brief Set frequency
+ * Table 13-36: SetRfFrequency SPI Transaction in datasheet
+*/
+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);
+
+  setOpMode(SX126X_SET_RF_FREQUENCY, buffer, 4);
+}
+
+/**
+ * @brief Set PaConfig
+ * Table 13-20: SetPaConfig SPI Transaction in datasheet
+ */
+void Sx1262::SetPaConfig(uint8_t paDutyCycle, uint8_t hpMax, uint8_t deviceSel, uint8_t paLut) const
+{
+  uint8_t *buffer = new uint8_t[4];
+  buffer[0] = paDutyCycle;
+  buffer[1] = hpMax;
+  buffer[2] = deviceSel;
+  buffer[3] = paLut;
+  logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "SX1262", "SetPaConfig with opcode 0x%02X and parameters :", SX126X_SET_PA_CFG);
+  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);
+  USBSerial.println();
+  setOpMode(SX126X_SET_PA_CFG, buffer, 4);
+}
+
+/**
+ * @brief Set TxParams
+ * Table 13-40: SetTxParams SPI Transaction
+ */
+void Sx1262::SetTxParams(uint8_t power, uint8_t rampTime) const
+{
+  uint8_t *buffer = new uint8_t[2];
+  buffer[0] = power;
+  buffer[1] = rampTime;
+  logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "SX1262", "SetTxParams with opcode 0x%02X and parameters :", SX126X_SET_TX_PARAMS);
+  USBSerial.print("0x");
+  USBSerial.print(buffer[0], HEX);
+  USBSerial.print(" 0x");
+  USBSerial.print(buffer[1], HEX);
+  USBSerial.println();
+  setOpMode(SX126X_SET_TX_PARAMS, buffer, 2);
+}
 
-int8_t Sx1262::setTxConfig(uint32_t freq, uint8_t debug) const
+/*
+ * @brief Set BufferBaseAddress
+  * Table 13-4-8: SetBufferBaseAddress SPI Transaction
+  */
+void Sx1262::SetBufferBaseAddress(uint8_t txBaseAddress, uint8_t rxBaseAddress) const
 {
-  int8_t exitCode = 0;
-  regWrite(0x01, 0x01);
-  wait(0xFFFF);
+  uint8_t *buffer = new uint8_t[2];
+  buffer[0] = txBaseAddress;
+  buffer[1] = rxBaseAddress;
+  logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "SX1262", "SetBufferBaseAddress with opcode 0x%02X and parameters :", SX126X_SET_BUFFER_BASE_ADDRESS);
+  USBSerial.print("0x");
+  USBSerial.print(buffer[0], HEX);
+  USBSerial.print(" 0x");
+  USBSerial.print(buffer[1], HEX);
+  USBSerial.println();
+  setOpMode(SX126X_SET_BUFFER_BASE_ADDRESS, buffer, 2);
+}
 
+/**
+ * @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);
+}
 
-  return exitCode;
-};
+/*
+ * @brief Set ModulationParams
+ */
+void Sx1262::SetModulationParams(uint32_t bitrate, uint8_t pulseShape, uint8_t bandwidht, uint32_t fdev) const
+{
+  uint8_t *buffer = new uint8_t[8];
+  buffer[0] = (bitrate >> 16) & 0xFF;
+  buffer[1] = (bitrate >> 8) & 0xFF;
+  buffer[2] = bitrate & 0xFF;
+  buffer[3] = pulseShape;
+  buffer[4] = bandwidht;
+  buffer[5] = (fdev >> 16) & 0xFF;
+  buffer[6] = (fdev >> 8) & 0xFF;
+  buffer[7] = fdev & 0xFF;
+  
+  setOpMode(SX126X_SET_MODULATION_PARAMS, buffer, 8);
 
+}

+ 27 - 13
src/sx1262.h

@@ -68,7 +68,7 @@ class Sx1262
      * @param miso SPI MISO pin.
      * @param cs Chip select pin.
      * @param dio1 Digital Input/Output pin DIO1.
-     * 
+     * @param busy Digital Input/Output pin BUSY.
      */
     Sx1262(
       uint8_t rst,
@@ -76,14 +76,16 @@ class Sx1262
       uint8_t mosi,
       uint8_t miso,
       uint8_t cs,
-      uint8_t dio1
+      uint8_t dio1,
+      uint8_t busy
     ) : 
       _rst(rst),
       _sclk(sclk),
       _mosi(mosi),
       _miso(miso),
       _cs(cs),
-      _dio1(dio1)
+      _dio1(dio1),
+      _busy(busy)
     { }
 
 
@@ -94,20 +96,31 @@ class Sx1262
     uint8_t getMosi() const;
     uint8_t getMiso() const;
     uint8_t getCs() const;
+    uint8_t getBusy() const;
+
     void reset() const;
-    void wait(uint32_t delay) const;
+
     uint8_t regRead(uint16_t reg) const;
     void regWrite(uint16_t reg, uint8_t val) const;
-    uint8_t readStatusCommand(uint8_t opcode) const;
-    int8_t setFreq(uint32_t freq) const;
-    uint32_t getFreq() const;
-    uint8_t getFifoSize() const;
-    int8_t getRssi() const;
-    int8_t fifo(uint8_t mode, uint8_t *buff) const;
-    int8_t setTxConfig(uint32_t freq, uint8_t debug) const;
-    int8_t txToStdby(uint8_t debug) const;
-    int8_t stdbyToTx(uint8_t debug) const;
+    void setOpMode(uint8_t opcode, uint8_t *payload, uint8_t size) const;
+    uint8_t getStatusCommand(uint8_t opcode) const;
+
+    void SetSleep() const;
+    void SetStandby() const;
+    void SetFS() const;
+    void SetPacketType(uint8_t type) const;
+    void GetPacketType() const;
+    void SetRfFrequency(uint32_t freq) const;
+            
     void freqUpdate(uint32_t freq,uint8_t debug) const;
+    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 SetModulationParams(uint32_t bitrate, uint8_t pulseShape, uint8_t bandwidht, uint32_t fdev) const;
+
+
 
   private:
     uint8_t _rst;  ///< Reset pin.
@@ -118,6 +131,7 @@ class Sx1262
     uint8_t _dio1; ///< DIO1 pin.
     uint8_t _dio2; ///< DIO2 pin.
     uint8_t _dio3; ///< DIO3 pin.
+    uint8_t _busy; ///< BUSY pin.
 };
 
 #endif //SX1262_H

+ 9 - 0
src/sx1262regs.h

@@ -56,6 +56,15 @@
 #define SX126X_CLR_DEVICE_ERRORS            0x07
 
 
+
+// Table 13-38: PacketType Definition
+#define SX126X_PACKET_TYPE_GFSK              0x00
+#define SX126X_PACKET_TYPE_LORA              0x01
+#define SX126X_PACKET_TYPE_LR_FHSS           0x03
+
+
+
+
 /* et la suite des registres ici */
 /**
  * @brief The address of the register holding the first byte defining the CRC seed