/**
  ******************************************************************************
  * @file    RFSettings.h
  * @author  Johan Zwarteveld
  * @version V1.0
  * @date    03-08-2015
  * @brief   Header file for the Radio configuration.
  ******************************************************************************
  *
  *
  ******************************************************************************
  */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef RFSETTINGS_H_
#define RFSETTINGS_H_

/* Includes ------------------------------------------------------------------*/
#include <stdint.h>
/* Exported types ------------------------------------------------------------*/
typedef struct
{
    uint8_t iocfg2;     // GDO2 Output Configuration
    uint8_t iocfg1;     // GDO1 Output Configuration
    uint8_t iocfg0;     // GDO0 Output Configuration
    uint8_t fifothr;    // RX FIFO and TX FIFO Thresholds
    uint8_t sync1;      // Sync Word, High Byte
    uint8_t sync0;      // Sync Word, Low Byte
    uint8_t pktlen;     // Packet Length
    uint8_t pktctrl1;   // Packet Automation Control
    uint8_t pktctrl0;   // Packet Automation Control
    uint8_t addr;       // Device Address
    uint8_t channr;     // Channel Number
    uint8_t fsctrl1;    // Frequency Synthesizer Control
    uint8_t fsctrl0;    // Frequency Synthesizer Control
    uint8_t freq2;      // Frequency Control Word, High Byte
    uint8_t freq1;      // Frequency Control Word, Middle Byte
    uint8_t freq0;      // Frequency Control Word, Low Byte
    uint8_t mdmcfg4;    // Modem Configuration
    uint8_t mdmcfg3;    // Modem Configuration
    uint8_t mdmcfg2;    // Modem Configuration
    uint8_t mdmcfg1;    // Modem Configuration
    uint8_t mdmcfg0;    // Modem Configuration
    uint8_t deviatn;    // Modem Deviation Setting
    uint8_t mcsm2;      // Main Radio Control State Machine Configuration
    uint8_t mcsm1;      // Main Radio Control State Machine Configuration
    uint8_t mcsm0;      // Main Radio Control State Machine Configuration
    uint8_t foccfg;     // Frequency Offset Compensation Configuration
    uint8_t bscfg;      // Bit Synchronization Configuration
    uint8_t agcctrl2;   // AGC Control
    uint8_t agcctrl1;   // AGC Control
    uint8_t agcctrl0;   // AGC Control
    uint8_t worevt1;    // High Byte Event0 Timeout
    uint8_t worevt0;    // Low Byte Event0 Timeout
    uint8_t worctrl;    // Wake On Radio Control
    uint8_t frend1;     // Front End RX Configuration
    uint8_t frend0;     // Front End TX Configuration
    uint8_t fscal3;     // Frequency Synthesizer Calibration
    uint8_t fscal2;     // Frequency Synthesizer Calibration
    uint8_t fscal1;     // Frequency Synthesizer Calibration
    uint8_t fscal0;     // Frequency Synthesizer Calibration
    uint8_t res_rcctrl1;// Reserved RC oscillator configuration
    uint8_t res_rcctrl0;// Reserved RC oscillator configuration
    uint8_t fstest;     // Frequency Synthesizer Calibration Control
    uint8_t ptest;      // Production Test
    uint8_t agctest;    // AGC Test
    uint8_t test2;      // Various Test Settings
    uint8_t test1;      // Various Test Settings
    uint8_t test0;      // Various Test Settings
} __attribute__((__packed__)) rfsettings;

/* Exported constants --------------------------------------------------------*/
/* PA table */
static const uint8_t patablesettings[8] = {0x51,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

static const rfsettings RadioSettings_868MHz_38kBaud =
{
	0x69,  // IOCFG2        GDO2 Output Configuration
	0x2E,  // IOCFG1        GDO1 Output Configuration
	0x06,  // IOCFG0        GDO0 Output Configuration
	0x47,  // FIFOTHR       RX FIFO and TX FIFO Thresholds
	0xD3,  // SYNC1         Sync Word, High Byte
	0x91,  // SYNC0         Sync Word, Low Byte
	0x3D,  // PKTLEN        Packet Length
	0x04,  // PKTCTRL1      Packet Automation Control
	0x05,  // PKTCTRL0      Packet Automation Control
	0x00,  // ADDR          Device Address
	0x00,  // CHANNR        Channel Number
	0x08,  // FSCTRL1       Frequency Synthesizer Control
	0x00,  // FSCTRL0       Frequency Synthesizer Control
	0x21,  // FREQ2         Frequency Control Word, High Byte
	0x62,  // FREQ1         Frequency Control Word, Middle Byte
	0x76,  // FREQ0         Frequency Control Word, Low Byte
	0xCA,  // MDMCFG4       Modem Configuration
	0x83,  // MDMCFG3       Modem Configuration
	0x93,  // MDMCFG2       Modem Configuration
	0x22,  // MDMCFG1       Modem Configuration
	0xF8,  // MDMCFG0       Modem Configuration
	0x35,  // DEVIATN       Modem Deviation Setting
	0x07,  // MCSM2         Main Radio Control State Machine Configuration
	0x30,  // MCSM1         Main Radio Control State Machine Configuration
	0x18,  // MCSM0         Main Radio Control State Machine Configuration
	0x16,  // FOCCFG        Frequency Offset Compensation Configuration
	0x6C,  // BSCFG         Bit Synchronization Configuration
	0x43,  // AGCCTRL2      AGC Control
	0x40,  // AGCCTRL1      AGC Control
	0x91,  // AGCCTRL0      AGC Control
	0x80,  // WOREVT1       High Byte Event0 Timeout
	0x00,  // WOREVT0       Low Byte Event0 Timeout
	0xF0,  // WORCTRL       Wake On Radio Control
	0x56,  // FREND1        Front End RX Configuration
	0x10,  // FREND0        Front End TX Configuration
	0xE9,  // FSCAL3        Frequency Synthesizer Calibration
	0x2A,  // FSCAL2        Frequency Synthesizer Calibration
	0x00,  // FSCAL1        Frequency Synthesizer Calibration
	0x1F,  // FSCAL0        Frequency Synthesizer Calibration
	0x00,  // RCCTRL1		Reserved RC oscillator configuration
	0x00,  // RCCTRL0		Reserved RC oscillator configuration
	0x59,  // FSTEST        Frequency Synthesizer Calibration Control
	0x7F,  // PTEST         Production Test
	0x3F,  // AGCTEST       AGC Test
	0x81,  // TEST2         Various Test Settings
	0x35,  // TEST1         Various Test Settings
	0x09,  // TEST0         Various Test Settings
};

/*
// Default radio setting (Power on Reset) do not alter
static const rfsettings RadioSettings_Default =
{
	0x29,  // IOCFG2        GDO2 Output Configuration
	0x2E,  // IOCFG1        GDO1 Output Configuration
	0x2E,  // IOCFG0        GDO0 Output Configuration
	0x07,  // FIFOTHR       RX FIFO and TX FIFO Thresholds
	0xD3,  // SYNC1         Sync Word, High Byte
	0x91,  // SYNC0         Sync Word, Low Byte
	0xFF,  // PKTLEN        Packet Length
	0x04,  // PKTCTRL1      Packet Automation Control
	0x45,  // PKTCTRL0      Packet Automation Control
	0x00,  // ADDR          Device Address
	0x00,  // CHANNR        Channel Number
	0x0F,  // FSCTRL1       Frequency Synthesizer Control
	0x00,  // FSCTRL0       Frequency Synthesizer Control
	0x1E,  // FREQ2         Frequency Control Word, High Byte
	0xC4,  // FREQ1         Frequency Control Word, Middle Byte
	0xEC,  // FREQ0         Frequency Control Word, Low Byte
	0x8C,  // MDMCFG4       Modem Configuration
	0x22,  // MDMCFG3       Modem Configuration
	0x02,  // MDMCFG2       Modem Configuration
	0x22,  // MDMCFG1       Modem Configuration
	0xF8,  // MDMCFG0       Modem Configuration
	0x47,  // DEVIATN       Modem Deviation Setting
	0x07,  // MCSM2         Main Radio Control State Machine Configuration
	0x30,  // MCSM1         Main Radio Control State Machine Configuration
	0x00,  // MCSM0         Main Radio Control State Machine Configuration
	0x36,  // FOCCFG        Frequency Offset Compensation Configuration
	0x6C,  // BSCFG         Bit Synchronization Configuration
	0x03,  // AGCCTRL2      AGC Control
	0x40,  // AGCCTRL1      AGC Control
	0x91,  // AGCCTRL0      AGC Control
	0x80,  // WOREVT1       High Byte Event0 Timeout
	0x00,  // WOREVT0       Low Byte Event0 Timeout
	0xF0,  // WORCTRL       Wake On Radio Control
	0x56,  // FREND1        Front End RX Configuration
	0x10,  // FREND0        Front End TX Configuration
	0xEA,  // FSCAL3        Frequency Synthesizer Calibration
	0x2A,  // FSCAL2        Frequency Synthesizer Calibration
	0x00,  // FSCAL1        Frequency Synthesizer Calibration
	0x1F,  // FSCAL0        Frequency Synthesizer Calibration
	0x59,  // FSTEST        Frequency Synthesizer Calibration Control
	0x7F,  // PTEST         Production Test
	0x3F,  // AGCTEST       AGC Test
	0x88,  // TEST2         Various Test Settings
	0x31,  // TEST1         Various Test Settings
	0x0B,  // TEST0         Various Test Settings
};*/
/* Exported macro ------------------------------------------------------------*/
/* Exported functions --------------------------------------------------------*/

#endif /* RFSETTINGS_H_ */
