StepperII
Dual Axis Stepper Controller

usb_serial.h

00001 #ifndef usb_serial_h__
00002 #define usb_serial_h__
00003 
00004 #include <stdint.h>
00005 
00006 // setup
00007 void usb_init(void);                    // initialize everything
00008 uint8_t usb_configured(void);           // is the USB port configured
00009 void usb_detach(void);                          // Detach USB interface
00010 
00011 // receiving data
00012 int16_t usb_serial_getchar(void);       // receive a character (-1 if timeout/error)
00013 uint8_t usb_serial_available(void);     // number of bytes in receive buffer
00014 void usb_serial_flush_input(void);      // discard any buffered input
00015 
00016 // transmitting data
00017 int8_t usb_serial_putchar(uint8_t c);   // transmit a character
00018 int8_t usb_serial_putchar_nowait(uint8_t c);  // transmit a character, do not wait
00019 int8_t usb_serial_write(const uint8_t *buffer, uint16_t size); // transmit a buffer
00020 void usb_serial_flush_output(void);     // immediately transmit any buffered output
00021 
00022 // serial parameters
00023 uint32_t usb_serial_get_baud(void);     // get the baud rate
00024 uint8_t usb_serial_get_stopbits(void);  // get the number of stop bits
00025 uint8_t usb_serial_get_paritytype(void);// get the parity type
00026 uint8_t usb_serial_get_numbits(void);   // get the number of data bits
00027 uint8_t usb_serial_get_control(void);   // get the RTS and DTR signal state
00028 int8_t usb_serial_set_control(uint8_t signals); // set DSR, DCD, RI, etc
00029 
00030 // constants corresponding to the various serial parameters
00031 #define USB_SERIAL_DTR                  0x01
00032 #define USB_SERIAL_RTS                  0x02
00033 #define USB_SERIAL_1_STOP               0
00034 #define USB_SERIAL_1_5_STOP             1
00035 #define USB_SERIAL_2_STOP               2
00036 #define USB_SERIAL_PARITY_NONE          0
00037 #define USB_SERIAL_PARITY_ODD           1
00038 #define USB_SERIAL_PARITY_EVEN          2
00039 #define USB_SERIAL_PARITY_MARK          3
00040 #define USB_SERIAL_PARITY_SPACE         4
00041 #define USB_SERIAL_DCD                  0x01
00042 #define USB_SERIAL_DSR                  0x02
00043 #define USB_SERIAL_BREAK                0x04
00044 #define USB_SERIAL_RI                   0x08
00045 #define USB_SERIAL_FRAME_ERR            0x10
00046 #define USB_SERIAL_PARITY_ERR           0x20
00047 #define USB_SERIAL_OVERRUN_ERR          0x40
00048 
00049 // This file does not include the HID debug functions, so these empty
00050 // macros replace them with nothing, so users can compile code that
00051 // has calls to these functions.
00052 #define usb_debug_putchar(c)
00053 #define usb_debug_flush_output()
00054 
00055 
00056 
00057 // Everything below this point is only intended for usb_serial.c
00058 #ifdef USB_SERIAL_PRIVATE_INCLUDE
00059 #include <avr/io.h>
00060 #include <avr/pgmspace.h>
00061 #include <avr/interrupt.h>
00062 
00063 #define EP_TYPE_CONTROL                 0x00
00064 #define EP_TYPE_BULK_IN                 0x81
00065 #define EP_TYPE_BULK_OUT                0x80
00066 #define EP_TYPE_INTERRUPT_IN            0xC1
00067 #define EP_TYPE_INTERRUPT_OUT           0xC0
00068 #define EP_TYPE_ISOCHRONOUS_IN          0x41
00069 #define EP_TYPE_ISOCHRONOUS_OUT         0x40
00070 #define EP_SINGLE_BUFFER                0x02
00071 #define EP_DOUBLE_BUFFER                0x06
00072 #define EP_SIZE(s)      ((s) == 64 ? 0x30 :     \
00073                         ((s) == 32 ? 0x20 :     \
00074                         ((s) == 16 ? 0x10 :     \
00075                                      0x00)))
00076 
00077 #define MAX_ENDPOINT            4
00078 
00079 #define LSB(n) (n & 255)
00080 #define MSB(n) ((n >> 8) & 255)
00081 
00082 #if defined(__AVR_AT90USB162__)
00083 #define HW_CONFIG() 
00084 #define PLL_CONFIG() (PLLCSR = ((1<<PLLE)|(1<<PLLP0)))
00085 #define USB_CONFIG() (USBCON = (1<<USBE))
00086 #define USB_FREEZE() (USBCON = ((1<<USBE)|(1<<FRZCLK)))
00087 #elif defined(__AVR_ATmega32U4__)
00088 #define HW_CONFIG() (UHWCON = 0x01)
00089 #define PLL_CONFIG() (PLLCSR = 0x12)
00090 #define USB_CONFIG() (USBCON = ((1<<USBE)|(1<<OTGPADE)))
00091 #define USB_FREEZE() (USBCON = ((1<<USBE)|(1<<FRZCLK)))
00092 #elif defined(__AVR_AT90USB646__)
00093 #define HW_CONFIG() (UHWCON = 0x81)
00094 #define PLL_CONFIG() (PLLCSR = 0x1A)
00095 #define USB_CONFIG() (USBCON = ((1<<USBE)|(1<<OTGPADE)))
00096 #define USB_FREEZE() (USBCON = ((1<<USBE)|(1<<FRZCLK)))
00097 #elif defined(__AVR_AT90USB1286__)
00098 #define HW_CONFIG() (UHWCON = 0x81)
00099 #define PLL_CONFIG() (PLLCSR = 0x16)
00100 #define USB_CONFIG() (USBCON = ((1<<USBE)|(1<<OTGPADE)))
00101 #define USB_FREEZE() (USBCON = ((1<<USBE)|(1<<FRZCLK)))
00102 #endif
00103 
00104 // standard control endpoint request types
00105 #define GET_STATUS                      0
00106 #define CLEAR_FEATURE                   1
00107 #define SET_FEATURE                     3
00108 #define SET_ADDRESS                     5
00109 #define GET_DESCRIPTOR                  6
00110 #define GET_CONFIGURATION               8
00111 #define SET_CONFIGURATION               9
00112 #define GET_INTERFACE                   10
00113 #define SET_INTERFACE                   11
00114 // HID (human interface device)
00115 #define HID_GET_REPORT                  1
00116 #define HID_GET_PROTOCOL                3
00117 #define HID_SET_REPORT                  9
00118 #define HID_SET_IDLE                    10
00119 #define HID_SET_PROTOCOL                11
00120 // CDC (communication class device)
00121 #define CDC_SET_LINE_CODING             0x20
00122 #define CDC_GET_LINE_CODING             0x21
00123 #define CDC_SET_CONTROL_LINE_STATE      0x22
00124 #endif
00125 #endif
 All Classes Files Functions Variables Defines