32 #ifdef PIOS_INCLUDE_OPENLRS
40 #include <uavtalkreceiver.h>
42 #define PIOS_OPENLRS_RCVR_TIMEOUT_MS 100
45 static int32_t PIOS_OpenLRS_Rcvr_Get(uintptr_t rcvr_id, uint8_t channel);
46 static void PIOS_OpenLRS_Rcvr_Supervisor(uintptr_t ppm_id);
49 .
read = PIOS_OpenLRS_Rcvr_Get,
53 enum pios_openlrs_rcvr_dev_magic {
54 PIOS_OPENLRS_RCVR_DEV_MAGIC = 0x07ac9e2144ff5329,
57 struct pios_openlrs_rcvr_dev {
58 enum pios_openlrs_rcvr_dev_magic
magic;
59 int16_t channels[OPENLRS_PPM_NUM_CHANNELS];
64 static bool PIOS_OpenLRS_Rcvr_Validate(
struct pios_openlrs_rcvr_dev
67 return openlrs_rcvr_dev->magic == PIOS_OPENLRS_RCVR_DEV_MAGIC;
70 static struct pios_openlrs_rcvr_dev *PIOS_OpenLRS_Rcvr_alloc(
void)
72 struct pios_openlrs_rcvr_dev *openlrs_rcvr_dev;
75 (
struct pios_openlrs_rcvr_dev *)
77 if (!openlrs_rcvr_dev) {
81 openlrs_rcvr_dev->magic = PIOS_OPENLRS_RCVR_DEV_MAGIC;
82 openlrs_rcvr_dev->fresh =
false;
83 openlrs_rcvr_dev->supv_timer = 0;
85 return openlrs_rcvr_dev;
89 pios_openlrs_t openlrs_id)
91 struct pios_openlrs_rcvr_dev *openlrs_rcvr_dev;
95 (
struct pios_openlrs_rcvr_dev *)PIOS_OpenLRS_Rcvr_alloc();
96 if (!openlrs_rcvr_dev) {
102 *openlrs_rcvr_id = (uintptr_t) openlrs_rcvr_dev;
103 PIOS_OpenLRS_RegisterRcvr(openlrs_id, *openlrs_rcvr_id);
107 (PIOS_OpenLRS_Rcvr_Supervisor, *openlrs_rcvr_id)) {
122 struct pios_openlrs_rcvr_dev *openlrs_rcvr_dev =
123 (
struct pios_openlrs_rcvr_dev *)openlrs_rcvr_id;
125 if (!PIOS_OpenLRS_Rcvr_Validate(openlrs_rcvr_dev)) {
130 for (
int i = 0;
i < OPENLRS_PPM_NUM_CHANNELS;
i++) {
131 openlrs_rcvr_dev->channels[
i] = channels[
i];
138 openlrs_rcvr_dev->fresh =
true;
146 UAVTalkReceiverData urcvr = {};
148 for (
int i = 0; (
i < UAVTALKRECEIVER_CHANNEL_NUMELEM) &&
149 (
i < OPENLRS_PPM_NUM_CHANNELS) ;
i++) {
150 urcvr.Channel[
i] = channels[
i];
153 UAVTalkReceiverSet(&urcvr);
166 static int32_t PIOS_OpenLRS_Rcvr_Get(uintptr_t openlrs_rcvr_id, uint8_t channel)
168 if (channel >= OPENLRS_PPM_NUM_CHANNELS) {
174 struct pios_openlrs_rcvr_dev *openlrs_rcvr_dev =
175 (
struct pios_openlrs_rcvr_dev *)openlrs_rcvr_id;
177 if (!PIOS_OpenLRS_Rcvr_Validate(openlrs_rcvr_dev)) {
182 return openlrs_rcvr_dev->channels[channel];
185 static void PIOS_OpenLRS_Rcvr_Supervisor(uintptr_t openlrs_rcvr_id)
188 struct pios_openlrs_rcvr_dev *openlrs_rcvr_dev =
189 (
struct pios_openlrs_rcvr_dev *)openlrs_rcvr_id;
191 if (!PIOS_OpenLRS_Rcvr_Validate(openlrs_rcvr_dev)) {
199 if (++(openlrs_rcvr_dev->supv_timer) <
200 (PIOS_OPENLRS_RCVR_TIMEOUT_MS * 1000 / 625)) {
203 openlrs_rcvr_dev->supv_timer = 0;
205 if (!openlrs_rcvr_dev->fresh) {
206 for (int32_t
i = 0;
i < OPENLRS_PPM_NUM_CHANNELS;
i++) {
212 openlrs_rcvr_dev->fresh =
false;
int32_t(* read)(uintptr_t id, uint8_t channel)
Main PiOS header to include all the compiled in PiOS options.
#define PIOS_DEBUG_Assert(test)
void * PIOS_malloc(size_t size)
int32_t PIOS_OpenLRS_Rcvr_UpdateChannels(uintptr_t openlrs_rcvr_id, int16_t *channels)
bool PIOS_RTC_RegisterTickCallback(void(*fn)(uintptr_t id), uintptr_t data)
const struct pios_rcvr_driver pios_openlrs_rcvr_driver
Implements an OpenLRS driver for the RFM22B.
int32_t PIOS_OpenLRS_Rcvr_Init(uintptr_t *openlrs_rcvr_id, pios_openlrs_t openlrs_id)