1 /* vim: set sts=4:sw=4:ts=4:noexpandtab */
8 void usb_init(void); // initialize everything
9 uint8_t usb_configured(void); // is the USB port configured
12 int16_t usb_serial_getchar(void); // receive a character (-1 if timeout/error)
13 uint8_t usb_serial_available(void); // number of bytes in receive buffer
14 void usb_serial_flush_input(void); // discard any buffered input
17 int8_t usb_serial_putchar(uint8_t c); // transmit a character
18 int8_t usb_serial_putchar_nowait(uint8_t c); // transmit a character, do not wait
19 int8_t usb_serial_write(const uint8_t *buffer, uint16_t size); // transmit a buffer
20 void usb_serial_flush_output(void); // immediately transmit any buffered output
23 uint32_t usb_serial_get_baud(void); // get the baud rate
24 uint8_t usb_serial_get_stopbits(void); // get the number of stop bits
25 uint8_t usb_serial_get_paritytype(void);// get the parity type
26 uint8_t usb_serial_get_numbits(void); // get the number of data bits
27 uint8_t usb_serial_get_control(void); // get the RTS and DTR signal state
28 int8_t usb_serial_set_control(uint8_t signals); // set DSR, DCD, RI, etc
30 // constants corresponding to the various serial parameters
31 #define USB_SERIAL_DTR 0x01
32 #define USB_SERIAL_RTS 0x02
33 #define USB_SERIAL_1_STOP 0
34 #define USB_SERIAL_1_5_STOP 1
35 #define USB_SERIAL_2_STOP 2
36 #define USB_SERIAL_PARITY_NONE 0
37 #define USB_SERIAL_PARITY_ODD 1
38 #define USB_SERIAL_PARITY_EVEN 2
39 #define USB_SERIAL_PARITY_MARK 3
40 #define USB_SERIAL_PARITY_SPACE 4
41 #define USB_SERIAL_DCD 0x01
42 #define USB_SERIAL_DSR 0x02
43 #define USB_SERIAL_BREAK 0x04
44 #define USB_SERIAL_RI 0x08
45 #define USB_SERIAL_FRAME_ERR 0x10
46 #define USB_SERIAL_PARITY_ERR 0x20
47 #define USB_SERIAL_OVERRUN_ERR 0x40
49 // This file does not include the HID debug functions, so these empty
50 // macros replace them with nothing, so users can compile code that
51 // has calls to these functions.
52 #define usb_debug_putchar(c)
53 #define usb_debug_flush_output()
57 // Everything below this point is only intended for usb_serial.c
58 #ifdef USB_SERIAL_PRIVATE_INCLUDE
60 #include <avr/pgmspace.h>
61 #include <avr/interrupt.h>
63 #define EP_TYPE_CONTROL 0x00
64 #define EP_TYPE_BULK_IN 0x81
65 #define EP_TYPE_BULK_OUT 0x80
66 #define EP_TYPE_INTERRUPT_IN 0xC1
67 #define EP_TYPE_INTERRUPT_OUT 0xC0
68 #define EP_TYPE_ISOCHRONOUS_IN 0x41
69 #define EP_TYPE_ISOCHRONOUS_OUT 0x40
70 #define EP_SINGLE_BUFFER 0x02
71 #define EP_DOUBLE_BUFFER 0x06
72 #define EP_SIZE(s) ((s) == 64 ? 0x30 : \
77 #define MAX_ENDPOINT 4
79 #define LSB(n) (n & 255)
80 #define MSB(n) ((n >> 8) & 255)
82 #if defined(__AVR_AT90USB162__)
84 #define PLL_CONFIG() (PLLCSR = ((1<<PLLE)|(1<<PLLP0)))
85 #define USB_CONFIG() (USBCON = (1<<USBE))
86 #define USB_FREEZE() (USBCON = ((1<<USBE)|(1<<FRZCLK)))
87 #elif defined(__AVR_ATmega32U4__)
88 #define HW_CONFIG() (UHWCON = 0x01)
89 #define PLL_CONFIG() (PLLCSR = 0x12)
90 #define USB_CONFIG() (USBCON = ((1<<USBE)|(1<<OTGPADE)))
91 #define USB_FREEZE() (USBCON = ((1<<USBE)|(1<<FRZCLK)))
92 #elif defined(__AVR_AT90USB646__)
93 #define HW_CONFIG() (UHWCON = 0x81)
94 #define PLL_CONFIG() (PLLCSR = 0x1A)
95 #define USB_CONFIG() (USBCON = ((1<<USBE)|(1<<OTGPADE)))
96 #define USB_FREEZE() (USBCON = ((1<<USBE)|(1<<FRZCLK)))
97 #elif defined(__AVR_AT90USB1286__)
98 #define HW_CONFIG() (UHWCON = 0x81)
99 #define PLL_CONFIG() (PLLCSR = 0x16)
100 #define USB_CONFIG() (USBCON = ((1<<USBE)|(1<<OTGPADE)))
101 #define USB_FREEZE() (USBCON = ((1<<USBE)|(1<<FRZCLK)))
104 // standard control endpoint request types
106 #define CLEAR_FEATURE 1
107 #define SET_FEATURE 3
108 #define SET_ADDRESS 5
109 #define GET_DESCRIPTOR 6
110 #define GET_CONFIGURATION 8
111 #define SET_CONFIGURATION 9
112 #define GET_INTERFACE 10
113 #define SET_INTERFACE 11
114 // HID (human interface device)
115 #define HID_GET_REPORT 1
116 #define HID_GET_PROTOCOL 3
117 #define HID_SET_REPORT 9
118 #define HID_SET_IDLE 10
119 #define HID_SET_PROTOCOL 11
120 // CDC (communication class device)
121 #define CDC_SET_LINE_CODING 0x20
122 #define CDC_GET_LINE_CODING 0x21
123 #define CDC_SET_CONTROL_LINE_STATE 0x22