drv_serial.h
Go to the documentation of this file.
1 /*
2  drv_serial.h : serial support for STM32F103CB
3 
4  Adapted from https://github.com/multiwii/baseflight/blob/master/src/drv_serial.h
5 
6  This file is part of BreezySTM32.
7 
8  BreezySTM32 is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 3 of the License, or
11  (at your option) any later version.
12 
13  BreezySTM32 is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with BreezySTM32. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 #pragma once
23 
24 typedef void (*serialReceiveCallbackPtr)(uint16_t data); // used by serial drivers to return frames to app
25 
26 typedef enum portMode_t {
27  MODE_RX = 1 << 0,
28  MODE_TX = 1 << 1,
30  MODE_SBUS = 1 << 2
31 } portMode_t;
32 
33 typedef struct serialPort {
34 
35  const struct serialPortVTable *vTable;
36 
38  uint32_t baudRate;
39 
40  uint32_t rxBufferSize;
41  uint32_t txBufferSize;
42  volatile uint8_t *rxBuffer;
43  volatile uint8_t *txBuffer;
44  uint32_t rxBufferHead;
45  uint32_t rxBufferTail;
46  uint32_t txBufferHead;
47  uint32_t txBufferTail;
48 
49  // FIXME rename member to rxCallback
51 } serialPort_t;
52 
54  void (*serialWrite)(serialPort_t *instance, uint8_t ch);
55 
56  uint8_t (*serialTotalBytesWaiting)(serialPort_t *instance);
57 
58  uint8_t (*serialRead)(serialPort_t *instance);
59 
60  // Specified baud rate may not be allowed by an implementation, use serialGetBaudRate to determine actual baud rate in use.
61  void (*serialSetBaudRate)(serialPort_t *instance, uint32_t baudRate);
62 
64 
65  void (*setMode)(serialPort_t *instance, portMode_t mode);
66 };
67 
68 void serialWrite(serialPort_t *instance, uint8_t ch);
69 uint8_t serialTotalBytesWaiting(serialPort_t *instance);
70 uint8_t serialRead(serialPort_t *instance);
71 void serialSetBaudRate(serialPort_t *instance, uint32_t baudRate);
72 void serialSetMode(serialPort_t *instance, portMode_t mode);
74 void serialPrint(serialPort_t *instance, const char *str);
75 uint32_t serialGetBaudRate(serialPort_t *instance);
uint32_t txBufferSize
Definition: drv_serial.h:41
volatile uint8_t * txBuffer
Definition: drv_serial.h:43
uint8_t serialRead(serialPort_t *instance)
Definition: drv_serial.c:50
portMode_t
Definition: drv_serial.h:26
volatile uint8_t * rxBuffer
Definition: drv_serial.h:42
uint32_t rxBufferSize
Definition: drv_serial.h:40
void serialPrint(serialPort_t *instance, const char *str)
Definition: drv_serial.c:27
const struct serialPortVTable * vTable
Definition: drv_serial.h:35
struct serialPort serialPort_t
uint32_t rxBufferTail
Definition: drv_serial.h:45
void(* serialReceiveCallbackPtr)(uint16_t data)
Definition: drv_serial.h:24
uint32_t rxBufferHead
Definition: drv_serial.h:44
uint32_t baudRate
Definition: drv_serial.h:38
void serialSetMode(serialPort_t *instance, portMode_t mode)
Definition: drv_serial.c:65
bool isSerialTransmitBufferEmpty(serialPort_t *instance)
Definition: drv_serial.c:60
void serialSetBaudRate(serialPort_t *instance, uint32_t baudRate)
Definition: drv_serial.c:55
uint32_t serialGetBaudRate(serialPort_t *instance)
Definition: drv_serial.c:35
serialReceiveCallbackPtr callback
Definition: drv_serial.h:50
portMode_t mode
Definition: drv_serial.h:37
void serialWrite(serialPort_t *instance, uint8_t ch)
Definition: drv_serial.c:40
uint8_t serialTotalBytesWaiting(serialPort_t *instance)
Definition: drv_serial.c:45
uint32_t txBufferTail
Definition: drv_serial.h:47
uint32_t txBufferHead
Definition: drv_serial.h:46


rosflight_firmware
Author(s): Daniel Koch , James Jackson
autogenerated on Thu Apr 15 2021 05:07:46