2 * This file is part of Cleanflight and Betaflight.
4 * Cleanflight and Betaflight are free software. You can redistribute
5 * this software and/or modify this software under the terms of the
6 * GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option)
10 * Cleanflight and Betaflight are distributed in the hope that they
11 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software.
18 * If not, see <http://www.gnu.org/licenses/>.
23 #include "drivers/serial.h"
25 #define SMARTAUDIO_SERIAL_OPTIONS SERIAL_NOT_INVERTED | SERIAL_BIDIR_NOPULL | SERIAL_STOPBITS_2
26 #define SMARTAUDIO_DEFAULT_BAUD 4900
27 #define SMARTAUDIO_MIN_BAUD 4800
28 #define SMARTAUDIO_MAX_BAUD 4950
30 typedef struct smartaudioSettings_s
{
36 uint16_t pitmodeFrequency
;
37 bool userFrequencyMode
;
39 bool pitmodeInRangeActive
;
40 bool pitmodeOutRangeActive
;
41 } smartaudioSettings_t
;
43 typedef struct smartaudioFrameHeader_s
{
47 } __attribute__((packed
)) smartaudioFrameHeader_t
;
49 typedef struct smartaudioCommandOnlyFrame_s
{
50 smartaudioFrameHeader_t header
;
52 } __attribute__((packed
)) smartaudioCommandOnlyFrame_t
;
54 typedef struct smartaudioU8Frame_s
{
55 smartaudioFrameHeader_t header
;
58 } __attribute__((packed
)) smartaudioU8Frame_t
;
60 typedef struct smartaudioU16Frame_s
{
61 smartaudioFrameHeader_t header
;
64 } __attribute__((packed
)) smartaudioU16Frame_t
;
66 typedef struct smartaudioU8ResponseFrame_s
{
67 smartaudioFrameHeader_t header
;
71 } __attribute__((packed
)) smartaudioU8ResponseFrame_t
;
73 typedef struct smartaudioU16ResponseFrame_s
{
74 smartaudioFrameHeader_t header
;
78 } __attribute__((packed
)) smartaudioU16ResponseFrame_t
;
80 typedef struct smartaudioSettingsResponseFrame_s
{
81 smartaudioFrameHeader_t header
;
84 uint8_t operationMode
;
87 } __attribute__((packed
)) smartaudioSettingsResponseFrame_t
;
89 typedef union smartaudioFrame_u
{
90 smartaudioCommandOnlyFrame_t commandOnlyFrame
;
91 smartaudioU8Frame_t u8RequestFrame
;
92 smartaudioU16Frame_t u16RequestFrame
;
93 } __attribute__((packed
)) smartaudioFrame_t
;
95 size_t smartaudioFrameGetSettings(smartaudioFrame_t
*smartaudioFrame
);
96 size_t smartaudioFrameGetPitmodeFrequency(smartaudioFrame_t
*smartaudioFrame
);
97 size_t smartaudioFrameSetPower(smartaudioFrame_t
*smartaudioFrame
, const uint8_t power
);
98 size_t smartaudioFrameSetBandChannel(smartaudioFrame_t
*smartaudioFrame
, const uint8_t band
, const uint8_t channel
);
99 size_t smartaudioFrameSetFrequency(smartaudioFrame_t
*smartaudioFrame
, const uint16_t frequency
, const bool pitmodeFrequency
);
100 size_t smartaudioFrameSetOperationMode(smartaudioFrame_t
*smartaudioFrame
, const smartaudioSettings_t
*settings
);
101 bool smartaudioParseResponseBuffer(smartaudioSettings_t
*settings
, const uint8_t *buffer
);