altos/stm32f4: Working on USB
[fw/altos] / src / stm32f4 / ao_usb_gen.h
1 /*
2  * Copyright © 2018 Keith Packard <keithp@keithp.com>
3  *
4  * This program 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 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  */
14
15 #ifndef _AO_USB_GEN_H_
16 #define _AO_USB_GEN_H_
17
18 #include "ao.h"
19 #include "ao_usb.h"
20 #include "ao_product.h"
21 #include <stdint.h>
22
23 #define USB_ECHO        0
24
25 #ifndef USE_USB_STDIO
26 #define USE_USB_STDIO   1
27 #endif
28
29 #if USE_USB_STDIO
30 #define AO_USB_OUT_SLEEP_ADDR   (&ao_stdin_ready)
31 #else
32 #define AO_USB_OUT_SLEEP_ADDR   (&ao_usb_out_avail)
33 #endif
34
35 struct ao_usb_setup {
36         uint8_t         dir_type_recip;
37         uint8_t         request;
38         uint16_t        value;
39         uint16_t        index;
40         uint16_t        length;
41 } ao_usb_setup;
42
43 #define AO_USB_EP0_GOT_RESET    1
44 #define AO_USB_EP0_GOT_SETUP    2
45 #define AO_USB_EP0_GOT_RX_DATA  4
46 #define AO_USB_EP0_GOT_TX_ACK   8
47
48 /*
49  * End point register indices
50  */
51
52 #define AO_USB_CONTROL_EPR      0
53 #define AO_USB_INT_EPR          1
54 #define AO_USB_OUT_EPR          2
55 #define AO_USB_IN_EPR           3
56
57 /* Device interfaces required */
58
59 /* Queue IN bytes to EP0 */
60 void
61 ao_usb_dev_ep0_init(void);
62
63 void
64 ao_usb_dev_ep0_in(const void *data, uint16_t len);
65
66 bool
67 ao_usb_dev_ep0_in_busy(void);
68
69 /* Receive OUT bytes from EP0 */
70 uint16_t
71 ao_usb_dev_ep0_out(void *data, uint16_t len);
72
73 /* Set device address */
74 void
75 ao_usb_dev_set_address(uint8_t address);
76
77 void
78 ao_usb_dev_enable(void);
79
80 void
81 ao_usb_dev_disable(void);
82
83 void
84 ao_usb_dev_init(void);
85
86 /* Queue IN bytes to EPn */
87 void
88 ao_usb_dev_ep_in(uint8_t ep, const void *data, uint16_t len);
89
90 bool
91 ao_usb_dev_ep_in_busy(uint8_t ep);
92
93 /* Receive OUT bytes from EPn */
94 uint16_t
95 ao_usb_dev_ep_out(uint8_t ep, void *data, uint16_t len);
96
97
98 /* General interfaces provided */
99
100 void
101 ao_usb_ep0_interrupt(uint8_t mask);
102
103 void
104 ao_usb_in_interrupt(uint32_t mask);
105
106 void
107 ao_usb_out_interrupt(uint32_t mask);
108
109 void
110 ao_usb_int_interrupt(uint32_t mask);
111
112 #endif /* _AO_USB_GEN_H_ */
113