altos: struct ao_log_mega doesn't have a ground temp value
[fw/altos] / src / core / ao_usb.h
1 /*
2  * Copyright © 2012 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; version 2 of the License.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program; if not, write to the Free Software Foundation, Inc.,
15  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
16  */
17
18 #ifndef _AO_USB_H_
19 #define _AO_USB_H_
20
21 /*
22  * ao_usb.c
23  */
24
25 /* Put one character to the USB output queue */
26 void
27 ao_usb_putchar(char c);
28
29 /* Get one character from the USB input queue */
30 char
31 ao_usb_getchar(void);
32
33 /* Poll for a charcter on the USB input queue.
34  * returns AO_READ_AGAIN if none are available
35  */
36 char
37 ao_usb_pollchar(void);
38
39 /* Flush the USB output queue */
40 void
41 ao_usb_flush(void);
42
43 /* Enable the USB controller */
44 void
45 ao_usb_enable(void);
46
47 /* Disable the USB controller */
48 void
49 ao_usb_disable(void);
50
51 /* Initialize the USB system */
52 void
53 ao_usb_init(void);
54
55 extern __code __at (0x00aa) uint8_t ao_usb_descriptors [];
56
57 #define AO_USB_SETUP_DIR_MASK   (0x01 << 7)
58 #define AO_USB_SETUP_TYPE_MASK  (0x03 << 5)
59 #define AO_USB_SETUP_RECIP_MASK (0x1f)
60
61 #define AO_USB_DIR_OUT                  0
62 #define AO_USB_DIR_IN                   (1 << 7)
63
64 #define AO_USB_TYPE_STANDARD            0
65 #define AO_USB_TYPE_CLASS               (1 << 5)
66 #define AO_USB_TYPE_VENDOR              (2 << 5)
67 #define AO_USB_TYPE_RESERVED            (3 << 5)
68
69 #define AO_USB_RECIP_DEVICE             0
70 #define AO_USB_RECIP_INTERFACE          1
71 #define AO_USB_RECIP_ENDPOINT           2
72 #define AO_USB_RECIP_OTHER              3
73
74 /* standard requests */
75 #define AO_USB_REQ_GET_STATUS           0x00
76 #define AO_USB_REQ_CLEAR_FEATURE        0x01
77 #define AO_USB_REQ_SET_FEATURE          0x03
78 #define AO_USB_REQ_SET_ADDRESS          0x05
79 #define AO_USB_REQ_GET_DESCRIPTOR       0x06
80 #define AO_USB_REQ_SET_DESCRIPTOR       0x07
81 #define AO_USB_REQ_GET_CONFIGURATION    0x08
82 #define AO_USB_REQ_SET_CONFIGURATION    0x09
83 #define AO_USB_REQ_GET_INTERFACE        0x0A
84 #define AO_USB_REQ_SET_INTERFACE        0x0B
85 #define AO_USB_REQ_SYNCH_FRAME          0x0C
86
87 #define AO_USB_DESC_DEVICE              1
88 #define AO_USB_DESC_CONFIGURATION       2
89 #define AO_USB_DESC_STRING              3
90 #define AO_USB_DESC_INTERFACE           4
91 #define AO_USB_DESC_ENDPOINT            5
92 #define AO_USB_DESC_DEVICE_QUALIFIER    6
93 #define AO_USB_DESC_OTHER_SPEED         7
94 #define AO_USB_DESC_INTERFACE_POWER     8
95
96 #define AO_USB_GET_DESC_TYPE(x)         (((x)>>8)&0xFF)
97 #define AO_USB_GET_DESC_INDEX(x)        ((x)&0xFF)
98
99 #define AO_USB_CONTROL_EP       0
100 #define AO_USB_CONTROL_SIZE     32
101
102 #define AO_USB_INT_EP           1
103 #define AO_USB_INT_SIZE         8
104
105 #define AO_USB_OUT_EP           4
106 #define AO_USB_IN_EP            5
107 /*
108  * USB bulk packets can only come in 8, 16, 32 and 64
109  * byte sizes, so we'll use 64 for everything
110  */
111 #define AO_USB_IN_SIZE          64
112 #define AO_USB_OUT_SIZE         64
113
114 #define AO_USB_EP0_IDLE         0
115 #define AO_USB_EP0_DATA_IN      1
116 #define AO_USB_EP0_DATA_OUT     2
117
118 #define LE_WORD(x)    ((x)&0xFF),((uint8_t) (((uint16_t) (x))>>8))
119
120 /* CDC definitions */
121 #define AO_USB_CS_INTERFACE             0x24
122 #define AO_USB_CS_ENDPOINT              0x25
123
124 #define AO_USB_SET_LINE_CODING          0x20
125 #define AO_USB_GET_LINE_CODING          0x21
126 #define AO_USB_SET_CONTROL_LINE_STATE   0x22
127
128 /* Data structure for GET_LINE_CODING / SET_LINE_CODING class requests */
129 struct ao_usb_line_coding {
130         uint32_t        rate;
131         uint8_t         char_format;
132         uint8_t         parity;
133         uint8_t         data_bits;
134 } ;
135
136 #endif /* _AO_USB_H_ */