LDL  0.5.0
Function List | Typedefs
Chip Interface

Description

The Radio uses chip interface function pointers to control the hardware:

Implementations of these functions must be assigned to the radio driver during initialisation. Use the examples in the function pointer documentation as a guide. These functions will need to interact with IO connected to the radio chip.

The Radio driver can receive an interrupt from the radio via the LDL_Radio_handleInterrupt() function.

The following connections are required for SX1272 and SX1276:

signal direction on host type polarity
MOSI output push-pull
MISO input hiz with opt. pull-up
SCK output push-pull
NSS output push-pull active-low
Reset input/output hiz/push-pull active-high
DIO0 input hiz with opt. pull-down active-high
DIO1 input hiz with opt. pull-down active-high

The following connections are required for SX1261 and SX1262:

signal direction on host type polarity
MOSI output push-pull
MISO input hiz with opt. pull-up
SCK output push-pull
NSS output push-pull active-low
Reset input/output hiz/push-pull active-low
Busy input hiz active-high
DIO1 input hiz with opt. pull-down active-high

Note that SX126X reset is active-low, while SX127X reset is active-high.

Function List

void LDL_Radio_handleInterrupt (struct ldl_radio *self, uint8_t n)
 

Typedefs

typedef void(* ldl_chip_set_mode_fn) (void *self, enum ldl_chip_mode mode)
 
typedef bool(* ldl_chip_write_fn) (void *self, const void *opcode, size_t opcode_size, const void *data, size_t size)
 
typedef bool(* ldl_chip_read_fn) (void *self, const void *opcode, size_t opcode_size, void *data, size_t size)
 

Functions

◆ LDL_Radio_handleInterrupt()

void LDL_Radio_handleInterrupt ( struct ldl_radio self,
uint8_t  n 
)

Receive an interrupt from the chip

Parameters
[in]selfldl_radio
[in]nDIO number

This function will typically be called from an ISR like this:

extern ldl_radio radio;
void dio0_rising_edge_isr(void)
{
}
void dio1_rising_edge_isr(void)
{
}

Typedef Documentation

◆ ldl_chip_set_mode_fn

typedef void(* ldl_chip_set_mode_fn) (void *self, enum ldl_chip_mode mode)

Use this function to configure the transceiver and associated hardware.

Parameters
[in]self
[in]modeldl_chip_mode
#include "ldl_chip.h"
/* this example is for an SX1276 */
void LDL_Chip_reset(bool state)
{
if(state){
// drive high
}
else{
// hiz
}
}
/* On more sophisticated hardware you may also need to switch:
*
* - on/off an oscillator
* - rfi circuit
* - rfo circuit
* - boost circuit
*
* */
void LDL_Chip_setMode(void *self, enum ldl_chip_mode mode)
{
switch(mode){
LDL_Chip_reset(true);
break;
LDL_Chip_reset(false);
break;
break;
break;
break;
break;
}
}

◆ ldl_chip_write_fn

typedef bool(* ldl_chip_write_fn) (void *self, const void *opcode, size_t opcode_size, const void *data, size_t size)

Write opcode and write payload

Parameters
[in]self
[in]opcodeopcode data that must be written
[in]opcode_sizesize of opcode data
[in]databuffer to write
[in]sizesize of buffer in bytes
Return values
trueoperation complete
falsechip is still busy after timeout

This function must handle:

  • busy polling & timeout (SX126X series)
  • chip selection
  • data transfer
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
extern void spi_chip_select(void);
extern void spi_chip_release(void);
extern void spi_write(uint8_t byte);
extern bool read_busy_pin(void);
bool LDL_Chip_write(void *self, const void *opcode, size_t opcode_size, const void *data, size_t size)
{
/* unused in this example */
(void)self;
size_t i;
spi_chip_select();
{
/* required for the SX126X series but not the SX127X series
*
* This must occur after selecting the chip since NSS is
* used to wake from sleep, during which busy pin will be set.
*
* consider adding a timeout to recover from a faulty chip */
while(read_busy_pin());
for(i=0U; i < opcode_size; i++){
spi_write(((const uint8_t *)opcode)[i]);
}
for(i=0U; i < size; i++){
spi_write(((const uint8_t *)data)[i]);
}
}
spi_chip_release();
/* this would return false if there was a busy timeout */
return true;
}

◆ ldl_chip_read_fn

typedef bool(* ldl_chip_read_fn) (void *self, const void *opcode, size_t opcode_size, void *data, size_t size)

Write opcode and read payload

Parameters
[in]self
[in]opcodeopcode data that must be written
[in]opcode_sizesize of opcode data
[out]dataread into this buffer
[in]sizenumber of bytes to read (and size of buffer in bytes)
Return values
trueoperation complete
falsechip is still busy after timeout

This function must handle:

  • busy polling & timeout (SX126X series)
  • chip selection
  • data transfer

For example:

#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
extern void spi_chip_select(void);
extern void spi_chip_release(void);
extern void spi_write(uint8_t byte);
extern uint8_t spi_read(void);
extern bool read_busy_pin(void);
bool LDL_Chip_read(void *self, const void *opcode, size_t opcode_size, void *data, size_t size)
{
/* unused in this example */
(void)self;
size_t i;
spi_chip_select();
{
/* required for the SX126X series but not the SX127X series
*
* This must occur after selecting the chip since NSS is
* used to wake from sleep, during which busy pin will be set.
*
* consider adding a timeout to recover from a faulty chip */
while(read_busy_pin());
for(i=0U; i < opcode_size; i++){
spi_write(((const uint8_t *)opcode)[i]);
}
for(i=0U; i < size; i++){
((uint8_t *)data)[i] = spi_read();
}
}
spi_chip_release();
/* this would return false if there was a busy timeout */
return true;
}

Enumeration Type Documentation

◆ ldl_chip_mode

chip mode tells the chip interface code what to do with various IO lines.

Enumerator
LDL_CHIP_MODE_RESET 

assert reset line

LDL_CHIP_MODE_SLEEP 

oscillator is off

LDL_CHIP_MODE_STANDBY 

oscillator is on

LDL_CHIP_MODE_RX 

receiving

LDL_CHIP_MODE_TX_RFO 

transmit using RFO PA

LDL_CHIP_MODE_TX_BOOST 

transmit using BOOST PA