-
Notifications
You must be signed in to change notification settings - Fork 0
/
stm32f4xx_usb.c
222 lines (178 loc) · 4.55 KB
/
stm32f4xx_usb.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#include "autoconf.h"
#include "api/usb.h"
#include "libc/stdio.h"
#include "libc/nostd.h"
/*
* This should be replaced in Kconfig and source:
* - both fs and hs mode in the same driver
*/
#ifdef CONFIG_USR_DRV_USB
#include "stm32f4xx_usb_fs.h"
#endif
#ifdef CONFIG_USR_DRV_USB_HS
#include "stm32f4xx_usb_hs.h"
#endif
/* usb_driver_init - Initialize the USB layer
* @data_received: callback called when data is received. The parameter is the
* size of received data.
* @data_sent: callback called when data has been sent
*/
void usb_driver_init(void)
{
#ifdef CONFIG_USR_DRV_USB_FS
usb_fs_driver_init();
#endif
#ifdef CONFIG_USR_DRV_USB_HS
usb_hs_driver_init();
#endif
}
/* usb_driver_init - Initialize the USB layer
* @data_received: callback called when data is received. The parameter is the
* size of received data.
* @data_sent: callback called when data has been sent
*/
void usb_driver_early_init(void (*data_received)(uint32_t), void (*data_sent)(void)){
#ifdef CONFIG_USR_DRV_USB_FS
usb_fs_driver_early_init(data_received, data_sent);
#endif
#ifdef CONFIG_USR_DRV_USB_HS
usb_hs_driver_early_init(data_received, data_sent);
#endif
}
void usb_driver_map(void)
{
#ifdef CONFIG_USR_DRV_USB_HS
printf("Mapping usb-otg-fs device into address space\n");
usb_hs_driver_map();
#endif
}
/**
* \brief Send acknowledgment.
*
* @param status Discarded.
*/
void usb_driver_setup_send_status(int status){
#ifdef CONFIG_USR_DRV_USB_FS
if (!status) {
usb_fs_driver_send(NULL, 0, EP0);
}
#endif
#ifdef CONFIG_USR_DRV_USB_HS
if (!status) {
usb_hs_driver_send(NULL, 0, EP0);
}
#endif
}
void usb_driver_setup_read_status(void){
// XXX We should handle error status in order to reemit lost packet
#ifdef CONFIG_USR_DRV_USB_FS
usb_driver_setup_read(NULL, 0, EP0);
#endif
#ifdef CONFIG_USR_DRV_USB_HS
usb_driver_setup_read(NULL, 0, EP0);
#endif
}
void usb_driver_setup_send_zlp(uint8_t ep){
#ifdef CONFIG_USR_DRV_USB_FS
usb_fs_driver_send_zlp(ep);
#endif
#ifdef CONFIG_USR_DRV_USB_HS
usb_hs_driver_send_zlp(ep);
#endif
}
/**
* usb_driver_send - Send data throw USB
* @src: address of the data to send. The buffer's size must be at least @size.
* @size: number of bytes to send.
* @ep: endpoint on which send data.
*/
void usb_driver_send(const void *src, uint32_t size, uint8_t ep){
#ifdef CONFIG_USR_DRV_USB_FS
usb_fs_driver_send(src, size, ep);
#endif
#ifdef CONFIG_USR_DRV_USB_HS
usb_hs_driver_send(src, size, ep);
#endif
}
/**
* usb_driver_setup_send - Send data throw USB
* @src: address of the data to send. The buffer's size must be at least @size.
* @size: number of bytes to send.
* @ep: endpoint on which send data.
*/
void usb_driver_setup_send(const void *src, uint32_t size, uint8_t ep){
#ifdef CONFIG_USR_DRV_USB_FS
usb_fs_driver_send(src, size, ep);
#endif
#ifdef CONFIG_USR_DRV_USB_HS
usb_hs_driver_send(src, size, ep);
#endif
}
/**
* usb_driver_setup_read - Read data from USB
* @dst: buffer in which read data will be written.
* @size: number of bytes to read.
* @ep: endpoint on which read data.
*/
void usb_driver_setup_read(void *dst, uint32_t size, uint8_t ep){
#ifdef CONFIG_USR_DRV_USB_FS
usb_fs_driver_read(dst, size, ep);
#endif
#ifdef CONFIG_USR_DRV_USB_HS
usb_hs_driver_read(dst, size, ep);
#endif
}
/**
* usb_driver_set_address - Set the address of the device
* @addr: Device's address
*/
void usb_driver_set_address(uint16_t addr){
#ifdef CONFIG_USR_DRV_USB_FS
usb_fs_driver_set_address(addr);
#endif
#ifdef CONFIG_USR_DRV_USB_HS
usb_hs_driver_set_address(addr);
#endif
}
/**
* \brief Stall IN endpoint
*
* @param ep Endpoint
*/
usb_ep_error_t usb_driver_stall_in(uint8_t ep){
#ifdef CONFIG_USR_DRV_USB_FS
return usb_fs_driver_stall_in(ep);
#endif
#ifdef CONFIG_USR_DRV_USB_HS
return usb_hs_driver_stall_in(ep);
#endif
}
void usb_driver_stall_in_clear(uint8_t ep, uint8_t type, uint8_t start_data_toggle){
#ifdef CONFIG_USR_DRV_USB_FS
usb_fs_driver_stall_in_clear(ep, type, start_data_toggle);
#endif
#ifdef CONFIG_USR_DRV_USB_HS
usb_hs_driver_stall_in_clear(ep, type, start_data_toggle);
#endif
}
/**
* \brief Stall OUT endpoint
*
* @param ep Endpoint
*/
void usb_driver_stall_out(uint8_t ep){
#ifdef CONFIG_USR_DRV_USB_FS
usb_fs_driver_stall_out(ep);
#endif
#ifdef CONFIG_USR_DRV_USB_HS
usb_hs_driver_stall_out(ep);
#endif
}
void usb_driver_stall_out_clear(uint8_t ep, uint8_t type, uint8_t start_data_toggle){
#ifdef CONFIG_USR_DRV_USB_FS
usb_fs_driver_stall_out_clear(ep, type, start_data_toggle);
#endif
#ifdef CONFIG_USR_DRV_USB_HS
usb_hs_driver_stall_out_clear(ep, type, start_data_toggle);
#endif
}