NinjaFlight
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
serial.h
Go to the documentation of this file.
1 /*
2  * This file is part of Ninjaflight.
3  *
4  * Ninjaflight is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * Ninjaflight is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with Ninjaflight. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #pragma once
19 
20 // TODO: remove dependency on serial driver
21 #include "drivers/serial.h"
22 #include "target.h"
23 #include "../config/serial.h"
24 
25 extern const uint32_t baudRates[];
26 
28 
29 void serialInit(bool softserialEnabled);
30 
31 //
32 // runtime
33 //
34 
35 typedef struct serialPortUsage_s {
40 
41 serialPort_t *findSharedSerialPort(const struct serial_config *self, uint16_t functionMask, serialPortFunction_e sharedWithFunction);
42 serialPort_t *findNextSharedSerialPort(const struct serial_config *self, uint16_t functionMask, serialPortFunction_e sharedWithFunction);
43 
45 uint8_t serialGetAvailablePortCount(void);
47 bool isSerialConfigValid(const struct serial_config *serialConfig);
49 bool doesConfigurationUsePort(const struct serial_config *self, serialPortIdentifier_e portIdentifier);
50 
51 const struct serial_port_config *findSerialPortConfig(const struct serial_config *self, serialPortFunction_e function);
52 const struct serial_port_config *findNextSerialPortConfig(const struct serial_config *self, serialPortFunction_e function);
54 bool isSerialPortShared(const struct serial_port_config *portConfig, uint16_t functionMask, serialPortFunction_e sharedWithFunction);
55 bool isSerialPortOpen(const struct serial_port_config *portConfig);
56 
57 
58 //
59 // runtime
60 //
63  serialPortFunction_e function,
64  serialReceiveCallbackPtr callback,
65  uint32_t baudrate,
67  portOptions_t options
68 );
69 void closeSerialPort(serialPort_t *serialPort);
70 
72 
73 baudRate_e lookupBaudRateIndex(uint32_t baudRate);
74 
75 
76 //
77 // msp/cli/bootloader
78 //
79 void evaluateOtherData(serialPort_t *serialPort, uint8_t receivedChar);
80 void handleSerial(void);
serialPort_t * serialPort
Definition: serial.h:37
void handleSerial(void)
uint16_t functionMask
Definition: serial.h:32
portSharing_e
Definition: serial.h:41
void evaluateOtherData(serialPort_t *serialPort, uint8_t receivedChar)
serialPort_t * findSharedSerialPort(const struct serial_config *self, uint16_t functionMask, serialPortFunction_e sharedWithFunction)
Definition: serial.c:139
Definition: serial.h:35
#define SERIAL_PORT_COUNT
Definition: target.h:92
uint8_t serialGetAvailablePortCount(void)
Definition: serial.c:347
Definition: serial.h:71
baudRate_e lookupBaudRateIndex(uint32_t baudRate)
Definition: serial.c:52
serialPortIdentifier_e
serial port identifiers
Definition: serial.h:28
void closeSerialPort(serialPort_t *serialPort)
Definition: serial.c:295
uint8_t mode
Definition: gimbal.h:49
bool isSerialConfigValid(const struct serial_config *serialConfig)
Definition: serial.c:165
void waitForSerialPortToFinishTransmitting(serialPort_t *serialPort)
Definition: serial.c:362
serialPortIdentifier_e identifier
Definition: serial.h:36
serialPortFunction_e
Definition: serial.h:47
const struct serial_port_config * findSerialPortConfig(const struct serial_config *self, serialPortFunction_e function)
Definition: serial.c:95
portMode_t
Definition: serial.h:24
serialPortIdentifier_e identifier
Definition: serial.h:31
void serialInit(bool softserialEnabled)
Definition: serial.c:311
baudRate_e
Definition: serial.h:60
struct serialPortUsage_s serialPortUsage_t
portOptions_t
Definition: serial.h:30
Definition: serial.h:80
const struct serial_port_config * serialFindPortConfiguration(const struct serial_config *self, serialPortIdentifier_e identifier)
Definition: serial.c:208
const serialPortIdentifier_e serialPortIdentifiers[SERIAL_PORT_COUNT]
Definition: config.c:255
const uint32_t baudRates[]
Definition: serial.c:48
void(* serialReceiveCallbackPtr)(uint16_t data)
Definition: serial.h:41
void serialRemovePort(serialPortIdentifier_e identifier)
Definition: serial.c:337
bool isSerialPortOpen(const struct serial_port_config *portConfig)
Definition: serial.c:130
serialPort_t * findNextSharedSerialPort(const struct serial_config *self, uint16_t functionMask, serialPortFunction_e sharedWithFunction)
Definition: serial.c:146
serialPort_t * openSerialPort(serialPortIdentifier_e identifier, serialPortFunction_e function, serialReceiveCallbackPtr callback, uint32_t baudrate, portMode_t mode, portOptions_t options)
Definition: serial.c:226
portSharing_e determinePortSharing(const struct serial_port_config *portConfig, serialPortFunction_e function)
Definition: serial.c:117
bool doesConfigurationUsePort(const struct serial_config *self, serialPortIdentifier_e portIdentifier)
Definition: serial.c:220
bool serialIsPortAvailable(serialPortIdentifier_e identifier)
Definition: serial.c:352
const struct serial_port_config * findNextSerialPortConfig(const struct serial_config *self, serialPortFunction_e function)
Definition: serial.c:101
bool isSerialPortShared(const struct serial_port_config *portConfig, uint16_t functionMask, serialPortFunction_e sharedWithFunction)
Definition: serial.c:125
Definition: serial.h:43