drv_serial.c
Go to the documentation of this file.
1 /*
2  drv_serial.c : serial support for STM32F103CB
3 
4  Adapted from https://github.com/multiwii/baseflight/blob/master/src/drv_serial.c
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 #include <stdint.h>
23 #include <stdbool.h>
24 
25 #include "drv_serial.h"
26 
27 void serialPrint(serialPort_t *instance, const char *str)
28 {
29  uint8_t ch;
30  while ((ch = *(str++)) != 0) {
31  serialWrite(instance, ch);
32  }
33 }
34 
35 uint32_t serialGetBaudRate(serialPort_t *instance)
36 {
37  return instance->baudRate;
38 }
39 
40 void serialWrite(serialPort_t *instance, uint8_t ch)
41 {
42  instance->vTable->serialWrite(instance, ch);
43 }
44 
46 {
47  return instance->vTable->serialTotalBytesWaiting(instance);
48 }
49 
50 uint8_t serialRead(serialPort_t *instance)
51 {
52  return instance->vTable->serialRead(instance);
53 }
54 
55 void serialSetBaudRate(serialPort_t *instance, uint32_t baudRate)
56 {
57  instance->vTable->serialSetBaudRate(instance, baudRate);
58 }
59 
61 {
62  return instance->vTable->isSerialTransmitBufferEmpty(instance);
63 }
64 
65 inline void serialSetMode(serialPort_t *instance, portMode_t mode)
66 {
67  instance->vTable->setMode(instance, mode);
68 }
69 
portMode_t
Definition: drv_serial.h:26
const struct serialPortVTable * vTable
Definition: drv_serial.h:35
void(* setMode)(serialPort_t *instance, portMode_t mode)
Definition: drv_serial.h:65
void(* serialWrite)(serialPort_t *instance, uint8_t ch)
Definition: drv_serial.h:54
void serialPrint(serialPort_t *instance, const char *str)
Definition: drv_serial.c:27
void(* serialSetBaudRate)(serialPort_t *instance, uint32_t baudRate)
Definition: drv_serial.h:61
bool isSerialTransmitBufferEmpty(serialPort_t *instance)
Definition: drv_serial.c:60
uint8_t(* serialTotalBytesWaiting)(serialPort_t *instance)
Definition: drv_serial.h:56
uint32_t serialGetBaudRate(serialPort_t *instance)
Definition: drv_serial.c:35
uint8_t(* serialRead)(serialPort_t *instance)
Definition: drv_serial.h:58
bool(* isSerialTransmitBufferEmpty)(serialPort_t *instance)
Definition: drv_serial.h:63
void serialSetBaudRate(serialPort_t *instance, uint32_t baudRate)
Definition: drv_serial.c:55
uint32_t baudRate
Definition: drv_serial.h:38
void serialWrite(serialPort_t *instance, uint8_t ch)
Definition: drv_serial.c:40
void serialSetMode(serialPort_t *instance, portMode_t mode)
Definition: drv_serial.c:65
uint8_t serialRead(serialPort_t *instance)
Definition: drv_serial.c:50
uint8_t serialTotalBytesWaiting(serialPort_t *instance)
Definition: drv_serial.c:45


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