usb_serial.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef usb_serial_h__
00039 #define usb_serial_h__
00040
00041 #include <stdint.h>
00042
00043
00044 void usb_init(void);
00045 uint8_t usb_configured(void);
00046
00047
00048 int16_t usb_serial_getchar(void);
00049 uint8_t usb_serial_available(void);
00050 void usb_serial_flush_input(void);
00051
00052
00053 int8_t usb_serial_putchar(uint8_t c);
00054 int8_t usb_serial_putchar_nowait(uint8_t c);
00055 int8_t usb_serial_write(const uint8_t *buffer, uint16_t size);
00056 void usb_serial_flush_output(void);
00057
00058
00059 uint32_t usb_serial_get_baud(void);
00060 uint8_t usb_serial_get_stopbits(void);
00061 uint8_t usb_serial_get_paritytype(void);
00062 uint8_t usb_serial_get_numbits(void);
00063 uint8_t usb_serial_get_control(void);
00064 int8_t usb_serial_set_control(uint8_t signals);
00065
00066
00067 #define USB_SERIAL_DTR 0x01
00068 #define USB_SERIAL_RTS 0x02
00069 #define USB_SERIAL_1_STOP 0
00070 #define USB_SERIAL_1_5_STOP 1
00071 #define USB_SERIAL_2_STOP 2
00072 #define USB_SERIAL_PARITY_NONE 0
00073 #define USB_SERIAL_PARITY_ODD 1
00074 #define USB_SERIAL_PARITY_EVEN 2
00075 #define USB_SERIAL_PARITY_MARK 3
00076 #define USB_SERIAL_PARITY_SPACE 4
00077 #define USB_SERIAL_DCD 0x01
00078 #define USB_SERIAL_DSR 0x02
00079 #define USB_SERIAL_BREAK 0x04
00080 #define USB_SERIAL_RI 0x08
00081 #define USB_SERIAL_FRAME_ERR 0x10
00082 #define USB_SERIAL_PARITY_ERR 0x20
00083 #define USB_SERIAL_OVERRUN_ERR 0x40
00084
00085
00086
00087
00088 #define usb_debug_putchar(c)
00089 #define usb_debug_flush_output()
00090
00091
00092
00093
00094 #ifdef USB_SERIAL_PRIVATE_INCLUDE
00095 #include <avr/io.h>
00096 #include <avr/pgmspace.h>
00097 #include <avr/interrupt.h>
00098
00099 #define EP_TYPE_CONTROL 0x00
00100 #define EP_TYPE_BULK_IN 0x81
00101 #define EP_TYPE_BULK_OUT 0x80
00102 #define EP_TYPE_INTERRUPT_IN 0xC1
00103 #define EP_TYPE_INTERRUPT_OUT 0xC0
00104 #define EP_TYPE_ISOCHRONOUS_IN 0x41
00105 #define EP_TYPE_ISOCHRONOUS_OUT 0x40
00106 #define EP_SINGLE_BUFFER 0x02
00107 #define EP_DOUBLE_BUFFER 0x06
00108 #define EP_SIZE(s) ((s) == 64 ? 0x30 : \
00109 ((s) == 32 ? 0x20 : \
00110 ((s) == 16 ? 0x10 : \
00111 0x00)))
00112
00113 #define MAX_ENDPOINT 4
00114
00115 #define LSB(n) (n & 255)
00116 #define MSB(n) ((n >> 8) & 255)
00117
00118 #if defined(__AVR_AT90USB162__)
00119 #define HW_CONFIG()
00120 #define PLL_CONFIG() (PLLCSR = ((1<<PLLE)|(1<<PLLP0)))
00121 #define USB_CONFIG() (USBCON = (1<<USBE))
00122 #define USB_FREEZE() (USBCON = ((1<<USBE)|(1<<FRZCLK)))
00123 #elif defined(__AVR_ATmega32U4__)
00124 #define HW_CONFIG() (UHWCON = 0x01)
00125 #define PLL_CONFIG() (PLLCSR = 0x12)
00126 #define USB_CONFIG() (USBCON = ((1<<USBE)|(1<<OTGPADE)))
00127 #define USB_FREEZE() (USBCON = ((1<<USBE)|(1<<FRZCLK)))
00128 #elif defined(__AVR_AT90USB646__)
00129 #define HW_CONFIG() (UHWCON = 0x81)
00130 #define PLL_CONFIG() (PLLCSR = 0x1A)
00131 #define USB_CONFIG() (USBCON = ((1<<USBE)|(1<<OTGPADE)))
00132 #define USB_FREEZE() (USBCON = ((1<<USBE)|(1<<FRZCLK)))
00133 #elif defined(__AVR_AT90USB1286__)
00134 #define HW_CONFIG() (UHWCON = 0x81)
00135 #define PLL_CONFIG() (PLLCSR = 0x16)
00136 #define USB_CONFIG() (USBCON = ((1<<USBE)|(1<<OTGPADE)))
00137 #define USB_FREEZE() (USBCON = ((1<<USBE)|(1<<FRZCLK)))
00138 #endif
00139
00140
00141 #define GET_STATUS 0
00142 #define CLEAR_FEATURE 1
00143 #define SET_FEATURE 3
00144 #define SET_ADDRESS 5
00145 #define GET_DESCRIPTOR 6
00146 #define GET_CONFIGURATION 8
00147 #define SET_CONFIGURATION 9
00148 #define GET_INTERFACE 10
00149 #define SET_INTERFACE 11
00150
00151 #define HID_GET_REPORT 1
00152 #define HID_GET_PROTOCOL 3
00153 #define HID_SET_REPORT 9
00154 #define HID_SET_IDLE 10
00155 #define HID_SET_PROTOCOL 11
00156
00157 #define CDC_SET_LINE_CODING 0x20
00158 #define CDC_GET_LINE_CODING 0x21
00159 #define CDC_SET_CONTROL_LINE_STATE 0x22
00160 #endif
00161 #endif