diff options
Diffstat (limited to 'lib/chibios-contrib/os/hal/include/usbh/dev/ftdi.h')
-rw-r--r-- | lib/chibios-contrib/os/hal/include/usbh/dev/ftdi.h | 151 |
1 files changed, 151 insertions, 0 deletions
diff --git a/lib/chibios-contrib/os/hal/include/usbh/dev/ftdi.h b/lib/chibios-contrib/os/hal/include/usbh/dev/ftdi.h new file mode 100644 index 000000000..c27950693 --- /dev/null +++ b/lib/chibios-contrib/os/hal/include/usbh/dev/ftdi.h | |||
@@ -0,0 +1,151 @@ | |||
1 | /* | ||
2 | ChibiOS - Copyright (C) 2006..2017 Giovanni Di Sirio | ||
3 | Copyright (C) 2015..2019 Diego Ismirlian, (dismirlian(at)google's mail) | ||
4 | |||
5 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
6 | you may not use this file except in compliance with the License. | ||
7 | You may obtain a copy of the License at | ||
8 | |||
9 | http://www.apache.org/licenses/LICENSE-2.0 | ||
10 | |||
11 | Unless required by applicable law or agreed to in writing, software | ||
12 | distributed under the License is distributed on an "AS IS" BASIS, | ||
13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
14 | See the License for the specific language governing permissions and | ||
15 | limitations under the License. | ||
16 | */ | ||
17 | |||
18 | #ifndef USBH_FTDI_H_ | ||
19 | #define USBH_FTDI_H_ | ||
20 | |||
21 | #include "hal_usbh.h" | ||
22 | |||
23 | #if HAL_USE_USBH && HAL_USBH_USE_FTDI | ||
24 | |||
25 | /*===========================================================================*/ | ||
26 | /* Driver pre-compile time settings. */ | ||
27 | /*===========================================================================*/ | ||
28 | |||
29 | /*===========================================================================*/ | ||
30 | /* Derived constants and error checks. */ | ||
31 | /*===========================================================================*/ | ||
32 | #define USBHFTDI_FRAMING_DATABITS_7 (0x7 << 0) | ||
33 | #define USBHFTDI_FRAMING_DATABITS_8 (0x8 << 0) | ||
34 | #define USBHFTDI_FRAMING_PARITY_NONE (0x0 << 8) | ||
35 | #define USBHFTDI_FRAMING_PARITY_NONE (0x0 << 8) | ||
36 | #define USBHFTDI_FRAMING_PARITY_ODD (0x1 << 8) | ||
37 | #define USBHFTDI_FRAMING_PARITY_EVEN (0x2 << 8) | ||
38 | #define USBHFTDI_FRAMING_PARITY_MARK (0x3 << 8) | ||
39 | #define USBHFTDI_FRAMING_PARITY_SPACE (0x4 << 8) | ||
40 | #define USBHFTDI_FRAMING_STOP_BITS_1 (0x0 << 11) | ||
41 | #define USBHFTDI_FRAMING_STOP_BITS_15 (0x1 << 11) | ||
42 | #define USBHFTDI_FRAMING_STOP_BITS_2 (0x2 << 11) | ||
43 | |||
44 | #define USBHFTDI_HANDSHAKE_NONE (0x0) | ||
45 | #define USBHFTDI_HANDSHAKE_RTS_CTS (0x1) | ||
46 | #define USBHFTDI_HANDSHAKE_DTR_DSR (0x2) | ||
47 | #define USBHFTDI_HANDSHAKE_XON_XOFF (0x4) | ||
48 | |||
49 | |||
50 | |||
51 | /*===========================================================================*/ | ||
52 | /* Driver data structures and types. */ | ||
53 | /*===========================================================================*/ | ||
54 | typedef struct { | ||
55 | uint32_t speed; | ||
56 | uint16_t framing; | ||
57 | uint8_t handshake; | ||
58 | uint8_t xon_character; | ||
59 | uint8_t xoff_character; | ||
60 | } USBHFTDIPortConfig; | ||
61 | |||
62 | typedef enum { | ||
63 | USBHFTDI_TYPE_A, | ||
64 | USBHFTDI_TYPE_B, | ||
65 | USBHFTDI_TYPE_H, | ||
66 | } usbhftdi_type_t; | ||
67 | |||
68 | typedef enum { | ||
69 | USBHFTDIP_STATE_UNINIT = 0, | ||
70 | USBHFTDIP_STATE_STOP = 1, | ||
71 | USBHFTDIP_STATE_ACTIVE = 2, | ||
72 | USBHFTDIP_STATE_READY = 3 | ||
73 | } usbhftdip_state_t; | ||
74 | |||
75 | |||
76 | #define _ftdi_port_driver_methods \ | ||
77 | _base_asynchronous_channel_methods | ||
78 | |||
79 | struct FTDIPortDriverVMT { | ||
80 | _ftdi_port_driver_methods | ||
81 | }; | ||
82 | |||
83 | typedef struct USBHFTDIPortDriver USBHFTDIPortDriver; | ||
84 | typedef struct USBHFTDIDriver USBHFTDIDriver; | ||
85 | |||
86 | struct USBHFTDIPortDriver { | ||
87 | /* inherited from abstract asyncrhonous channel driver */ | ||
88 | const struct FTDIPortDriverVMT *vmt; | ||
89 | _base_asynchronous_channel_data | ||
90 | |||
91 | USBHFTDIDriver *ftdip; | ||
92 | |||
93 | usbhftdip_state_t state; | ||
94 | |||
95 | usbh_ep_t epin; | ||
96 | usbh_urb_t iq_urb; | ||
97 | threads_queue_t iq_waiting; | ||
98 | uint32_t iq_counter; | ||
99 | USBH_DECLARE_STRUCT_MEMBER(uint8_t iq_buff[64]); | ||
100 | uint8_t *iq_ptr; | ||
101 | |||
102 | |||
103 | usbh_ep_t epout; | ||
104 | usbh_urb_t oq_urb; | ||
105 | threads_queue_t oq_waiting; | ||
106 | uint32_t oq_counter; | ||
107 | USBH_DECLARE_STRUCT_MEMBER(uint8_t oq_buff[64]); | ||
108 | uint8_t *oq_ptr; | ||
109 | |||
110 | virtual_timer_t vt; | ||
111 | uint8_t ifnum; | ||
112 | |||
113 | USBHFTDIPortDriver *next; | ||
114 | }; | ||
115 | |||
116 | struct USBHFTDIDriver { | ||
117 | /* inherited from abstract class driver */ | ||
118 | _usbh_base_classdriver_data | ||
119 | |||
120 | usbhftdi_type_t type; | ||
121 | USBHFTDIPortDriver *ports; | ||
122 | |||
123 | mutex_t mtx; | ||
124 | }; | ||
125 | |||
126 | /*===========================================================================*/ | ||
127 | /* Driver macros. */ | ||
128 | /*===========================================================================*/ | ||
129 | #define usbhftdipGetState(ftdipp) ((ftdipp)->state) | ||
130 | #define usbhftdipGetHost(ftdipp) ((ftdipp)->ftdip->dev->host) | ||
131 | |||
132 | /*===========================================================================*/ | ||
133 | /* External declarations. */ | ||
134 | /*===========================================================================*/ | ||
135 | extern USBHFTDIDriver USBHFTDID[HAL_USBHFTDI_MAX_INSTANCES]; | ||
136 | extern USBHFTDIPortDriver FTDIPD[HAL_USBHFTDI_MAX_PORTS]; | ||
137 | |||
138 | #ifdef __cplusplus | ||
139 | extern "C" { | ||
140 | #endif | ||
141 | /* FTDI port driver */ | ||
142 | void usbhftdipStart(USBHFTDIPortDriver *ftdipp, const USBHFTDIPortConfig *config); | ||
143 | void usbhftdipStop(USBHFTDIPortDriver *ftdipp); | ||
144 | #ifdef __cplusplus | ||
145 | } | ||
146 | #endif | ||
147 | |||
148 | |||
149 | #endif | ||
150 | |||
151 | #endif /* USBH_FTDI_H_ */ | ||