Cleanup warnings in serial_usb_vcp.c
[betaflight.git] / src / main / drivers / serial_usb_vcp.c
blob2aab5ad9a7c9ffd438b19177a4054ebb83209dd7
1 /*
2 * This file is part of Cleanflight.
4 * Cleanflight 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.
9 * Cleanflight 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.
14 * You should have received a copy of the GNU General Public License
15 * along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
18 #include <stdint.h>
19 #include <stdlib.h>
20 #include <stdbool.h>
21 #include <string.h>
23 #include "platform.h"
25 #include "build_config.h"
27 #include "usb_core.h"
28 #include "usb_init.h"
29 #include "hw_config.h"
31 #include "drivers/system.h"
33 #include "serial.h"
34 #include "serial_usb_vcp.h"
37 #define USB_TIMEOUT 50
39 static vcpPort_t vcpPort;
41 void usbVcpSetBaudRate(serialPort_t *instance, uint32_t baudRate)
43 UNUSED(instance);
44 UNUSED(baudRate);
46 // TODO implement
49 void usbVcpSetMode(serialPort_t *instance, portMode_t mode)
51 UNUSED(instance);
52 UNUSED(mode);
54 // TODO implement
57 bool isUsbVcpTransmitBufferEmpty(serialPort_t *instance)
59 UNUSED(instance);
60 return true;
63 uint8_t usbVcpAvailable(serialPort_t *instance)
65 UNUSED(instance);
67 return receiveLength & 0xFF; // FIXME use uint32_t return type everywhere
70 uint8_t usbVcpRead(serialPort_t *instance)
72 UNUSED(instance);
74 uint8_t buf[1];
76 uint32_t rxed = 0;
78 while (rxed < 1) {
79 rxed += CDC_Receive_DATA((uint8_t*)buf + rxed, 1 - rxed);
82 return buf[0];
85 void usbVcpWrite(serialPort_t *instance, uint8_t c)
87 UNUSED(instance);
89 uint32_t txed;
90 uint32_t start = millis();
92 if (!(usbIsConnected() && usbIsConfigured())) {
93 return;
96 do {
97 txed = CDC_Send_DATA((uint8_t*)&c, 1);
98 } while (txed < 1 && (millis() - start < USB_TIMEOUT));
102 const struct serialPortVTable usbVTable[] = { { usbVcpWrite, usbVcpAvailable, usbVcpRead, usbVcpSetBaudRate, isUsbVcpTransmitBufferEmpty, usbVcpSetMode } };
104 serialPort_t *usbVcpOpen(void)
106 vcpPort_t *s;
108 Set_System();
109 Set_USBClock();
110 USB_Interrupts_Config();
111 USB_Init();
113 s = &vcpPort;
114 s->port.vTable = usbVTable;
116 return (serialPort_t *)s;