Merged in f5soh/librepilot/update_credits (pull request #529)
[librepilot.git] / flight / pios / inc / pios_rfm22b.h
blobd2d43533ca636f9be3803f24450b49ed781b5427
1 /**
2 ******************************************************************************
3 * @addtogroup PIOS PIOS Core hardware abstraction layer
4 * @{
5 * @addtogroup PIOS_RFM22B Radio Functions
6 * @brief PIOS interface for RFM22B Radio
7 * @{
9 * @file pios_rfm22b.h
10 * @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2016.
11 * The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
12 * @brief RFM22B functions header.
13 * @see The GNU Public License (GPL) Version 3
15 *****************************************************************************/
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 3 of the License, or
20 * (at your option) any later version.
22 * This program is distributed in the hope that it will be useful, but
23 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
24 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25 * for more details.
27 * You should have received a copy of the GNU General Public License along
28 * with this program; if not, write to the Free Software Foundation, Inc.,
29 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 #ifndef PIOS_RFM22B_H
33 #define PIOS_RFM22B_H
35 #include <uavobjectmanager.h>
36 #include <oplinksettings.h>
38 /* Constant definitions */
39 enum gpio_direction { GPIO0_TX_GPIO1_RX, GPIO0_RX_GPIO1_TX };
40 #define RFM22B_PPM_NUM_CHANNELS 8
42 /* Global Types */
43 struct pios_rfm22b_cfg {
44 const struct pios_spi_cfg *spi_cfg; /* Pointer to SPI interface configuration */
45 const struct pios_exti_cfg *exti_cfg; /* Pointer to the EXTI configuration */
46 uint8_t RFXtalCap;
47 uint8_t slave_num;
48 enum gpio_direction gpio_direction;
50 typedef void (*PPMReceivedCallback)(uint32_t context, const int16_t *channels);
52 enum rfm22b_tx_power {
53 RFM22_tx_pwr_txpow_0 = 0x00, // +1dBm .. 1.25mW
54 RFM22_tx_pwr_txpow_1 = 0x01, // +2dBm .. 1.6mW
55 RFM22_tx_pwr_txpow_2 = 0x02, // +5dBm .. 3.16mW
56 RFM22_tx_pwr_txpow_3 = 0x03, // +8dBm .. 6.3mW
57 RFM22_tx_pwr_txpow_4 = 0x04, // +11dBm .. 12.6mW
58 RFM22_tx_pwr_txpow_5 = 0x05, // +14dBm .. 25mW
59 RFM22_tx_pwr_txpow_6 = 0x06, // +17dBm .. 50mW
60 RFM22_tx_pwr_txpow_7 = 0x07 // +20dBm .. 100mW
63 enum rfm22b_datarate {
64 RFM22_datarate_9600 = 0,
65 RFM22_datarate_19200 = 1,
66 RFM22_datarate_32000 = 2,
67 RFM22_datarate_57600 = 3,
68 RFM22_datarate_64000 = 4,
69 RFM22_datarate_100000 = 5,
70 RFM22_datarate_128000 = 6,
71 RFM22_datarate_192000 = 7,
72 RFM22_datarate_256000 = 8,
75 typedef enum {
76 PIOS_RFM22B_INT_FAILURE,
77 PIOS_RFM22B_INT_SUCCESS,
78 PIOS_RFM22B_TX_COMPLETE,
79 PIOS_RFM22B_RX_COMPLETE
80 } pios_rfm22b_int_result;
82 struct rfm22b_stats {
83 uint16_t packets_per_sec;
84 uint16_t tx_byte_count;
85 uint16_t rx_byte_count;
86 uint16_t tx_seq;
87 uint16_t rx_seq;
88 uint8_t rx_good;
89 uint8_t rx_corrected;
90 uint8_t rx_error;
91 uint8_t rx_missed;
92 uint8_t rx_failure;
93 uint8_t tx_dropped;
94 uint8_t tx_failure;
95 uint8_t resets;
96 uint8_t timeouts;
97 uint8_t link_quality;
98 int8_t rssi;
99 int32_t afc_correction;
100 uint8_t link_state;
103 /* Public Functions */
104 extern int32_t PIOS_RFM22B_Init(uint32_t *rfb22b_id, uint32_t spi_id, uint32_t slave_num, const struct pios_rfm22b_cfg *cfg, OPLinkSettingsRFBandOptions band);
105 extern void PIOS_RFM22B_Reinit(uint32_t rfb22b_id);
106 extern void PIOS_RFM22B_SetTxPower(uint32_t rfm22b_id, enum rfm22b_tx_power tx_pwr);
107 extern void PIOS_RFM22B_SetChannelConfig(uint32_t rfm22b_id, enum rfm22b_datarate datarate, uint8_t min_chan, uint8_t max_chan, bool coordinator, bool ppm_mode, bool ppm_only);
108 extern void PIOS_RFM22B_SetXtalCap(uint32_t rfm22b_id, uint8_t xtal_cap);
109 extern void PIOS_RFM22B_SetCoordinatorID(uint32_t rfm22b_id, uint32_t coord_id);
110 extern void PIOS_RFM22B_SetDeviceID(uint32_t rfm22b_id, uint32_t device_id);
111 extern uint32_t PIOS_RFM22B_DeviceID(uint32_t rfb22b_id);
112 extern void PIOS_RFM22B_GetStats(uint32_t rfm22b_id, struct rfm22b_stats *stats);
113 extern bool PIOS_RFM22B_InRxWait(uint32_t rfb22b_id);
114 extern bool PIOS_RFM22B_LinkStatus(uint32_t rfm22b_id);
115 extern bool PIOS_RFM22B_ReceivePacket(uint32_t rfm22b_id, uint8_t *p);
116 extern bool PIOS_RFM22B_TransmitPacket(uint32_t rfm22b_id, uint8_t *p, uint8_t len);
117 extern pios_rfm22b_int_result PIOS_RFM22B_ProcessTx(uint32_t rfm22b_id);
118 extern pios_rfm22b_int_result PIOS_RFM22B_ProcessRx(uint32_t rfm22b_id);
119 extern void PIOS_RFM22B_SetPPMCallback(uint32_t rfm22b_id, PPMReceivedCallback cb, uint32_t cb_context);
120 extern void PIOS_RFM22B_PPMSet(uint32_t rfm22b_id, int16_t *channels, uint8_t nchan);
121 extern void PIOS_RFM22B_PPMGet(uint32_t rfm22b_id, int16_t *channels, uint8_t nchan);
123 /* Global Variables */
124 extern const struct pios_com_driver pios_rfm22b_com_driver;
126 #endif /* PIOS_RFM22B_H */
129 * @}
130 * @}