23 #ifndef RADIO_CONTROL_SPEKTRUM_ARCH_H
24 #define RADIO_CONTROL_SPEKTRUM_ARCH_H
29 #include RADIO_CONTROL_SPEKTRUM_MODEL_H
31 #define RC_SPK_SYNC_1 0x03
33 #define RC_SPK_STA_UNINIT 0
34 #define RC_SPK_STA_GOT_SYNC_1 1
35 #define RC_SPK_STA_GOT_SYNC_2 2
46 #define __RcLink(dev, _x) dev##_x
47 #define _RcLink(dev, _x) __RcLink(dev, _x)
48 #define RcLink(_x) _RcLink(RADIO_CONTROL_SPEKTRUM_PRIMARY_PORT, _x)
50 #define RcLinkChAvailable() RcLink(ChAvailable())
51 #define RcLinkGetCh() RcLink(Getch())
53 #define RadioControlEventImpl(_received_frame_handler) { \
54 while (RcLinkChAvailable()) { \
55 int8_t c = RcLinkGetCh(); \
56 switch (rc_spk_parser_status) { \
57 case RC_SPK_STA_UNINIT: \
58 if (c==RC_SPK_SYNC_1) \
59 rc_spk_parser_status = RC_SPK_STA_GOT_SYNC_1; \
61 case RC_SPK_STA_GOT_SYNC_1: \
62 if (c==RC_SPK_SYNC_2) { \
63 rc_spk_parser_status = RC_SPK_STA_GOT_SYNC_2; \
64 rc_spk_parser_idx = 0; \
67 rc_spk_parser_status = RC_SPK_STA_UNINIT; \
69 case RC_SPK_STA_GOT_SYNC_2: \
70 rc_spk_parser_buf[rc_spk_parser_idx] = c; \
71 rc_spk_parser_idx++; \
72 if (rc_spk_parser_idx >= 2*RADIO_CONTROL_NB_CHANNEL) { \
73 rc_spk_parser_status = RC_SPK_STA_UNINIT; \
74 radio_control.frame_cpt++; \
75 radio_control.time_since_last_frame = 0; \
76 radio_control.status = RC_OK; \
78 for (i=0;i<RADIO_CONTROL_NB_CHANNEL;i++) { \
79 const int16_t tmp = (rc_spk_parser_buf[2*i]<<8) + \
80 rc_spk_parser_buf[2*i+1]; \
82 const int16_t val = (tmp&0x03FF) - 512; \
83 radio_control.values[i] = val; \
84 radio_control.values[i] *= rc_spk_throw[i]; \
85 if (i==RADIO_CONTROL_THROTTLE) { \
86 radio_control.values[i] += MAX_PPRZ; \
87 radio_control.values[i] /= 2; \
90 _received_frame_handler(); \
94 rc_spk_parser_status = RC_SPK_STA_UNINIT; \
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
uint8_t rc_spk_parser_buf[RADIO_CONTROL_NB_CHANNEL *2]
#define RADIO_CONTROL_NB_CHANNEL
uint8_t rc_spk_parser_idx
const int16_t rc_spk_throw[RADIO_CONTROL_NB_CHANNEL]
bool rc_spk_parser_status