/** library to communication with Semtech SX172x LoRa radio module using SPI * @file * @author King Kévin * @copyright SPDX-License-Identifier: GPL-3.0-or-later * @date 2020 * @note peripherals used: SPI @ref radio_sx172x_spi, GPIO @ref radio_sx172x_gpio * @note the interrupts and corresponding DIO should be handled directly by the user */ #pragma once /** register addresses */ enum radio_sx172x_register_t { RADIO_SX172X_REG_FIFO = 0x00, RADIO_SX172X_REG_OP_MODE = 0x01, RADIO_SX172X_REG_FSKOOK_BITRATE_MSB = 0x02, RADIO_SX172X_REG_FSKOOK_BITRATE_LSB = 0x03, RADIO_SX172X_REG_FSKOOK_FDEV_MSB = 0x04, RADIO_SX172X_REG_FSKOOK_FDEV_LSB = 0x05, RADIO_SX172X_REG_FRF_MSB = 0x06, RADIO_SX172X_REG_FRF_MID = 0x07, RADIO_SX172X_REG_FRF_LSB = 0x08, RADIO_SX172X_REG_PA_CONFIG = 0x09, RADIO_SX172X_REG_PA_RAMP = 0x0A, RADIO_SX172X_REG_OCP = 0x0B, RADIO_SX172X_REG_LNA = 0x0C, RADIO_SX172X_REG_FSKOOB_RX_CONFIG = 0x0D, RADIO_SX172X_REG_LORA_FIFO_ADDR_PTR = 0x0D, RADIO_SX172X_REG_FSKOOB_RSSI_CONFIG = 0x0E, RADIO_SX172X_REG_LORA_FIFO_TX_BASE_ADDR = 0x0E, RADIO_SX172X_REG_FSKOOB_RSSI_COLLISION = 0x0F, RADIO_SX172X_REG_LORA_FIFO_RX_BASE_ADDR = 0x0F, RADIO_SX172X_REG_FSKOOB_RSSI_THRESH = 0x10, RADIO_SX172X_REG_LORA_FIFO_RX_CURRENT_ADDR = 0x10, RADIO_SX172X_REG_FSKOOK_RSSI_VALUE = 0x11, RADIO_SX172X_REG_LORA_IRQ_FLAGS_MASK = 0x11, RADIO_SX172X_REG_FSKOOK_RX_BW = 0x12, RADIO_SX172X_REG_LORA_IRQ_FLAGS = 0x12, RADIO_SX172X_REG_FSKOOK_AFC_BW = 0x13, RADIO_SX172X_REG_LORA_RX_NB_BYTES = 0x13, RADIO_SX172X_REG_FSKOOK_OOK_PEAK = 0x14, RADIO_SX172X_REG_LORA_RX_HEADER_CNT_VALUE_MSB = 0x14, RADIO_SX172X_REG_FSKOOK_OOK_FIX = 0x15, RADIO_SX172X_REG_LORA_RX_HEADER_CNT_VALUE_LSB = 0x15, RADIO_SX172X_REG_FSKOOK_OOK_AVG = 0x16, RADIO_SX172X_REG_LORA_RX_PACKET_CNT_VALUE_MSB = 0x16, RADIO_SX172X_REG_LORA_RX_PACKET_CNT_VALUE_LSB = 0x17, RADIO_SX172X_REG_LORA_MODEM_STAT = 0x18, RADIO_SX172X_REG_LORA_PKT_SNR_VALUE = 0x19, RADIO_SX172X_REG_FSKOOK_AFC_FEI = 0x1A, RADIO_SX172X_REG_LORA_PKT_RSSI_VALUE = 0x1A, RADIO_SX172X_REG_FSKOOK_AFC_MSB = 0x1B, RADIO_SX172X_REG_LORA_RSSI_VALUE = 0x1B, RADIO_SX172X_REG_FSKOOK_AFC_LSB = 0x1C, RADIO_SX172X_REG_LORA_HOP_CHANNEL = 0x1C, RADIO_SX172X_REG_FSKOOK_FEI_MSB = 0x1D, RADIO_SX172X_REG_LORA_MODEM_CONFIG_1 = 0x1D, RADIO_SX172X_REG_FSKOOK_FEI_LSB = 0x1E, RADIO_SX172X_REG_LORA_MODEM_CONFIG_2 = 0x1E, RADIO_SX172X_REG_FSKOOK_PREAMBLE_DETECT = 0x1F, RADIO_SX172X_REG_LORA_SYMB_TIMEOUT_LSB = 0x1F, RADIO_SX172X_REG_FSKOOK_RX_TIMEOUT_1 = 0x20, RADIO_SX172X_REG_LORA_PREAMBLE_MSB = 0x20, RADIO_SX172X_REG_FSKOOK_RX_TIMEOUT_2 = 0x21, RADIO_SX172X_REG_LORA_PREAMBLE_LSB = 0x21, RADIO_SX172X_REG_FSKOOK_RX_TIMEOUT_3 = 0x22, RADIO_SX172X_REG_LORA_PAYLOAD_LENGTH = 0x22, RADIO_SX172X_REG_FSKOOK_RX_DELAY = 0x23, RADIO_SX172X_REG_LORA_MAX_PAYLOD_LENGTH = 0x23, RADIO_SX172X_REG_FSKOOK_OSC = 0x24, RADIO_SX172X_REG_LORA_HOP_PERIOD = 0x24, RADIO_SX172X_REG_FSKOOK_PREAMBLE_MSB = 0x25, RADIO_SX172X_REG_LORA_FIFO_RX_BYTE_ADDR = 0x25, RADIO_SX172X_REG_FSKOOK_PREAMBLE_LSB = 0x26, RADIO_SX172X_REG_LORA_MODEM_CONFIG_3 = 0x26, RADIO_SX172X_REG_FSKOOK_SYNC_CONFIG = 0x27, RADIO_SX172X_REG_FSKOOK_SYNC_VALUE_1 = 0x28, RADIO_SX172X_REG_LORA_FEI_MSB = 0x28, RADIO_SX172X_REG_FSKOOK_SYNC_VALUE_2 = 0x29, RADIO_SX172X_REG_LORA_FEI_MID = 0x29, RADIO_SX172X_REG_FSKOOK_SYNC_VALUE_3 = 0x2A, RADIO_SX172X_REG_LORA_FEI_LSB = 0x2A, RADIO_SX172X_REG_FSKOOK_SYNC_VALUE_4 = 0x2B, RADIO_SX172X_REG_FSKOOK_SYNC_VALUE_5 = 0x2C, RADIO_SX172X_REG_LORA_RSSI_WIDEBAND = 0x2C, RADIO_SX172X_REG_FSKOOK_SYNC_VALUE_6 = 0x2D, RADIO_SX172X_REG_FSKOOK_SYNC_VALUE_7 = 0x2E, RADIO_SX172X_REG_FSKOOK_SYNC_VALUE_8 = 0x2F, RADIO_SX172X_REG_LORA_IF_FREQ_1 = 0x2F, RADIO_SX172X_REG_FSKOOK_PACKET_CONFIG_1 = 0x30, RADIO_SX172X_REG_LORA_IF_FREQ_2 = 0x30, RADIO_SX172X_REG_FSKOOK_PACKET_CONFIG_2 = 0x31, RADIO_SX172X_REG_LORA_DETECT_OPTIMIZE = 0x31, RADIO_SX172X_REG_FSKOOK_PAYLOAD_LENGTH = 0x32, RADIO_SX172X_REG_FSKOOK_NODE_ADRS = 0x33, RADIO_SX172X_REG_LORA_INVERT_IQ = 0x33, RADIO_SX172X_REG_FSKOOK_BROADCAST_ADRS = 0x34, RADIO_SX172X_REG_FSKOOK_FIFO_THRESH = 0x35, RADIO_SX172X_REG_FSKOOK_SEQ_CONFIG_1 = 0x36, RADIO_SX172X_REG_LORA_HIGH_BW_OPTIMIZE_1 = 0x36, RADIO_SX172X_REG_FSKOOK_SEQ_CONFIG_2 = 0x37, RADIO_SX172X_REG_LORA_DETECTION_THRESHOLD = 0x37, RADIO_SX172X_REG_FSKOOK_TIMER_RESOLV = 0x38, RADIO_SX172X_REG_FSKOOK_TIMER_1_COEF = 0x39, RADIO_SX172X_REG_LORA_SYNC_WORD = 0x39, RADIO_SX172X_REG_FSKOOK_TIMER_2_COEF = 0x3A, RADIO_SX172X_REG_LORA_HIGH_BW_OPTIMIZE_2 = 0x3A, RADIO_SX172X_REG_FSKOOK_IMAGE_CAL = 0x3B, RADIO_SX172X_REG_LORA_INVERT_IQ_2 = 0x3B, RADIO_SX172X_REG_FSKOOK_TEMP = 0x3C, RADIO_SX172X_REG_FSKOOK_LOW_BAT = 0x3D, RADIO_SX172X_REG_FSKOOK_IRQ_FLAGS_1 = 0x3E, RADIO_SX172X_REG_FSKOOK_IRQ_FLAGS_2 = 0x3F, RADIO_SX172X_REG_DIO_MAPPING_1 = 0x40, RADIO_SX172X_REG_DIO_MAPPING_2 = 0x41, RADIO_SX172X_REG_VERSION = 0x42, RADIO_SX172X_REG_FSKOOK_PLL_HOP = 0x44, RADIO_SX172X_REG_TCX0 = 0x4B, RADIO_SX172X_REG_PA_DAC = 0x4D, RADIO_SX172X_REG_FORMER_TEMP = 0x5B, RADIO_SX172X_REG_FSKOOK_BIT_RATE_FRAC = 0x5D, RADIO_SX172X_REG_AGC_REF = 0x61, RADIO_SX172X_REG_AGC_THRESH_1 = 0x62, RADIO_SX172X_REG_AGC_THRESH_2 = 0x63, RADIO_SX172X_REG_AGC_THRESH_3 = 0x64, RADIO_SX172X_REG_PLL = 0x70, }; /** setup communication to SX172x * @return if SX172x is ready */ bool radio_sx172x_setup(void); /** release resources and peripherals used by communication */ void radio_sx172x_release(void); /** reset SX172x chip * @return if SX172x is ready */ bool radio_sx172x_reset(void); /** read register from SX172x * @param[in] name register name to read * @return register value read */ uint8_t radio_sx172x_read_register(enum radio_sx172x_register_t name); /** write register to SX172x * @param[in] name register name to write * @param[in} value register value to write */ void radio_sx172x_write_register(enum radio_sx172x_register_t name, uint8_t value); /** read FIFO data * @param[in] addr address of the data to be read in the FIFO buffer * @param[out] data buffer to store read data * @param[in] length number of byte to read * @warning puts device in standby mode when in sleep mode */ void radio_sx172x_read_fifo(uint8_t addr, uint8_t* data, uint8_t length); /** write FIFO data * @param[in] addr address of the data to be written in the FIFO buffer * @param[out] data data to be written in FIFO buffer * @param[in] length number of byte to written * @warning puts device in standby mode when in sleep mode */ void radio_sx172x_write_fifo(uint8_t addr, const uint8_t* data, uint8_t length);