|
| 1 | + |
| 2 | +#include <stdbool.h> |
| 3 | +#include <stdint.h> |
| 4 | + |
| 5 | +#include "asf/common/services/usb/class/cdc/usb_protocol_cdc.h" |
| 6 | + |
| 7 | +#ifndef CONF_USB_H_INCLUDED |
| 8 | +#define CONF_USB_H_INCLUDED |
| 9 | + |
| 10 | +#define USB_DEVICE_MAJOR_VERSION 1 |
| 11 | +#define USB_DEVICE_MINOR_VERSION 0 |
| 12 | +#define USB_DEVICE_POWER 100 // Consumption on Vbus line (mA) |
| 13 | +#define USB_DEVICE_ATTR \ |
| 14 | + (USB_CONFIG_ATTR_BUS_POWERED) |
| 15 | +// (USB_CONFIG_ATTR_REMOTE_WAKEUP|USB_CONFIG_ATTR_SELF_POWERED) |
| 16 | +// (USB_CONFIG_ATTR_REMOTE_WAKEUP|USB_CONFIG_ATTR_BUS_POWERED) |
| 17 | + |
| 18 | +//! USB Device string definitions (Optional) |
| 19 | +#ifndef USB_DEVICE_MANUFACTURE_NAME |
| 20 | +# define USB_DEVICE_MANUFACTURE_NAME "Radomir Dopieralski" |
| 21 | +#endif |
| 22 | + |
| 23 | +#ifndef USB_DEVICE_PRODUCT_NAME |
| 24 | +# define USB_DEVICE_PRODUCT_NAME "uGame" |
| 25 | +#endif |
| 26 | +// #define USB_DEVICE_SERIAL_NAME "12...EF" |
| 27 | +#define USB_DEVICE_GET_SERIAL_NAME_POINTER serial_number |
| 28 | +#define USB_DEVICE_GET_SERIAL_NAME_LENGTH 32 |
| 29 | +extern char serial_number[USB_DEVICE_GET_SERIAL_NAME_LENGTH]; |
| 30 | + |
| 31 | +//! Control endpoint size |
| 32 | +#define USB_DEVICE_EP_CTRL_SIZE 64 |
| 33 | + |
| 34 | +//! Interfaces for this device (CDC COM + CDC DATA + MSC + HID mouse + HID kbd) |
| 35 | +#define USB_DEVICE_NB_INTERFACE 5 |
| 36 | + |
| 37 | +// (3 | USB_EP_DIR_IN) // CDC Notify endpoint |
| 38 | +// (4 | USB_EP_DIR_IN) // CDC TX |
| 39 | +// (5 | USB_EP_DIR_OUT) // CDC RX |
| 40 | +// (1 | USB_EP_DIR_IN) // MSC IN |
| 41 | +// (2 | USB_EP_DIR_OUT) // MSC OUT |
| 42 | +// (6 | USB_EP_DIR_IN) // HID mouse report |
| 43 | +// (7 | USB_EP_DIR_IN) // HID keyboard report |
| 44 | +#define USB_DEVICE_MAX_EP 7 |
| 45 | + |
| 46 | +#define UDI_CDC_PORT_NB 1 |
| 47 | +#define UDI_CDC_ENABLE_EXT(port) mp_cdc_enable(port) |
| 48 | +extern bool mp_cdc_enable(uint8_t port); |
| 49 | +#define UDI_CDC_DISABLE_EXT(port) mp_cdc_disable(port) |
| 50 | +extern void mp_cdc_disable(uint8_t port); |
| 51 | +#define UDI_CDC_LOW_RATE |
| 52 | + |
| 53 | +#define UDI_CDC_DEFAULT_RATE 115200 |
| 54 | +#define UDI_CDC_DEFAULT_STOPBITS CDC_STOP_BITS_1 |
| 55 | +#define UDI_CDC_DEFAULT_PARITY CDC_PAR_NONE |
| 56 | +#define UDI_CDC_DEFAULT_DATABITS 8 |
| 57 | + |
| 58 | +#define UDI_CDC_RX_NOTIFY(port) usb_rx_notify() |
| 59 | +void usb_rx_notify(void); |
| 60 | + |
| 61 | +#define UDI_CDC_SET_CODING_EXT(port,cfg) usb_coding_notify(port, cfg) |
| 62 | +void usb_coding_notify(uint8_t port, usb_cdc_line_coding_t* coding); |
| 63 | +#define UDI_CDC_SET_DTR_EXT(port,set) usb_dtr_notify(port, set) |
| 64 | +void usb_dtr_notify(uint8_t port, bool set); |
| 65 | +#define UDI_CDC_SET_RTS_EXT(port,set) usb_rts_notify(port, set) |
| 66 | +void usb_rts_notify(uint8_t port, bool set); |
| 67 | + |
| 68 | +/** |
| 69 | + * USB CDC low level configuration |
| 70 | + * In standalone these configurations are defined by the CDC module. |
| 71 | + * For composite device, these configuration must be defined here |
| 72 | + * @{ |
| 73 | + */ |
| 74 | +//! Endpoint numbers definition |
| 75 | + |
| 76 | +#define UDI_CDC_COMM_EP_0 (3 | USB_EP_DIR_IN) // Notify endpoint |
| 77 | +#define UDI_CDC_DATA_EP_IN_0 (4 | USB_EP_DIR_IN) // TX |
| 78 | +#define UDI_CDC_DATA_EP_OUT_0 (5 | USB_EP_DIR_OUT) // RX |
| 79 | + |
| 80 | +//! Interface numbers |
| 81 | +#define UDI_CDC_COMM_IFACE_NUMBER_0 0 |
| 82 | +#define UDI_CDC_DATA_IFACE_NUMBER_0 1 |
| 83 | + |
| 84 | +/** |
| 85 | + * Configuration of MSC interface |
| 86 | + * @{ |
| 87 | + */ |
| 88 | +//! Vendor name and Product version of MSC interface |
| 89 | +#define UDI_MSC_GLOBAL_VENDOR_ID \ |
| 90 | + 'A', 'T', 'M', 'E', 'L', ' ', ' ', ' ' |
| 91 | +#define UDI_MSC_GLOBAL_PRODUCT_VERSION \ |
| 92 | + '1', '.', '0', '0' |
| 93 | + |
| 94 | +//! Interface callback definition |
| 95 | +#define UDI_MSC_ENABLE_EXT() mp_msc_enable() |
| 96 | +extern bool mp_msc_enable(void); |
| 97 | +#define UDI_MSC_DISABLE_EXT() mp_msc_disable() |
| 98 | +extern void mp_msc_disable(void); |
| 99 | + |
| 100 | +//! Enable id string of interface to add an extra USB string |
| 101 | +#define UDI_MSC_STRING_ID 5 |
| 102 | + |
| 103 | +/** |
| 104 | + * USB MSC low level configuration |
| 105 | + * In standalone these configurations are defined by the MSC module. |
| 106 | + * For composite device, these configuration must be defined here |
| 107 | + * @{ |
| 108 | + */ |
| 109 | +//! Endpoint numbers definition |
| 110 | +#define UDI_MSC_EP_IN (1 | USB_EP_DIR_IN) |
| 111 | +#define UDI_MSC_EP_OUT (2 | USB_EP_DIR_OUT) |
| 112 | + |
| 113 | +//! Interface number |
| 114 | +#define UDI_MSC_IFACE_NUMBER 2 |
| 115 | +/** |
| 116 | + * Configuration of HID Mouse interface |
| 117 | + * @{ |
| 118 | + */ |
| 119 | +//! Interface callback definition |
| 120 | +#define UDI_HID_MOUSE_ENABLE_EXT() mp_mouse_enable() |
| 121 | +extern bool mp_mouse_enable(void); |
| 122 | +#define UDI_HID_MOUSE_DISABLE_EXT() mp_mouse_disable() |
| 123 | +extern void mp_mouse_disable(void); |
| 124 | + |
| 125 | +//! Enable id string of interface to add an extra USB string |
| 126 | +#define UDI_HID_MOUSE_STRING_ID 6 |
| 127 | + |
| 128 | +/** |
| 129 | + * USB HID Mouse low level configuration |
| 130 | + * In standalone these configurations are defined by the HID Mouse module. |
| 131 | + * For composite device, these configuration must be defined here |
| 132 | + * @{ |
| 133 | + */ |
| 134 | +//! Endpoint numbers definition |
| 135 | +#define UDI_HID_MOUSE_EP_IN (6 | USB_EP_DIR_IN) |
| 136 | + |
| 137 | +//! Interface number |
| 138 | +#define UDI_HID_MOUSE_IFACE_NUMBER 3 |
| 139 | +//@} |
| 140 | +//@} |
| 141 | + |
| 142 | +/** |
| 143 | + * Configuration of HID Keyboard interface |
| 144 | + * @{ |
| 145 | + */ |
| 146 | +//! Interface callback definition |
| 147 | +#define UDI_HID_KBD_ENABLE_EXT() mp_keyboard_enable() |
| 148 | +extern bool mp_keyboard_enable(void); |
| 149 | +#define UDI_HID_KBD_DISABLE_EXT() mp_keyboard_disable() |
| 150 | +extern void mp_keyboard_disable(void); |
| 151 | +#define UDI_HID_KBD_CHANGE_LED(value) mp_keyboard_led(value) |
| 152 | +extern void mp_keyboard_led(uint8_t); |
| 153 | + |
| 154 | +//! Enable id string of interface to add an extra USB string |
| 155 | +#define UDI_HID_KBD_STRING_ID 7 |
| 156 | + |
| 157 | +/** |
| 158 | + * USB HID Keyboard low level configuration |
| 159 | + * In standalone these configurations are defined by the HID Keyboard module. |
| 160 | + * For composite device, these configuration must be defined here |
| 161 | + * @{ |
| 162 | + */ |
| 163 | +//! Endpoint numbers definition |
| 164 | +#define UDI_HID_KBD_EP_IN (7 | USB_EP_DIR_IN) |
| 165 | + |
| 166 | +//! Interface number |
| 167 | +#define UDI_HID_KBD_IFACE_NUMBER 4 |
| 168 | + |
| 169 | +/** |
| 170 | + * Description of Composite Device |
| 171 | + * @{ |
| 172 | + */ |
| 173 | +//! USB Interfaces descriptor structure |
| 174 | +#define UDI_COMPOSITE_DESC_T \ |
| 175 | + usb_iad_desc_t udi_cdc_iad; \ |
| 176 | + udi_cdc_comm_desc_t udi_cdc_comm; \ |
| 177 | + udi_cdc_data_desc_t udi_cdc_data; \ |
| 178 | + udi_msc_desc_t udi_msc; \ |
| 179 | + udi_hid_mouse_desc_t udi_hid_mouse; \ |
| 180 | + udi_hid_kbd_desc_t udi_hid_kbd |
| 181 | + |
| 182 | +//! USB Interfaces descriptor value for Full Speed |
| 183 | +#define UDI_COMPOSITE_DESC_FS \ |
| 184 | + .udi_cdc_iad = UDI_CDC_IAD_DESC_0, \ |
| 185 | + .udi_cdc_comm = UDI_CDC_COMM_DESC_0, \ |
| 186 | + .udi_cdc_data = UDI_CDC_DATA_DESC_0_FS, \ |
| 187 | + .udi_msc = UDI_MSC_DESC_FS, \ |
| 188 | + .udi_hid_mouse = UDI_HID_MOUSE_DESC, \ |
| 189 | + .udi_hid_kbd = UDI_HID_KBD_DESC |
| 190 | + |
| 191 | +//! USB Interfaces descriptor value for High Speed |
| 192 | +#define UDI_COMPOSITE_DESC_HS \ |
| 193 | + .udi_cdc_iad = UDI_CDC_IAD_DESC_0, \ |
| 194 | + .udi_cdc_comm = UDI_CDC_COMM_DESC_0, \ |
| 195 | + .udi_cdc_data = UDI_CDC_DATA_DESC_0_HS, \ |
| 196 | + .udi_msc = UDI_MSC_DESC_HS, \ |
| 197 | + .udi_hid_mouse = UDI_HID_MOUSE_DESC, \ |
| 198 | + .udi_hid_kbd = UDI_HID_KBD_DESC |
| 199 | + |
| 200 | +//! USB Interface APIs |
| 201 | +#define UDI_COMPOSITE_API \ |
| 202 | + &udi_api_cdc_comm, \ |
| 203 | + &udi_api_cdc_data, \ |
| 204 | + &udi_api_msc, \ |
| 205 | + &udi_api_hid_mouse, \ |
| 206 | + &udi_api_hid_kbd |
| 207 | +//@} |
| 208 | + |
| 209 | +/** |
| 210 | + * USB Device Driver Configuration |
| 211 | + * @{ |
| 212 | + */ |
| 213 | +//@} |
| 214 | + |
| 215 | +//! The includes of classes and other headers must be done at the end of this file to avoid compile error |
| 216 | +#include "udi_cdc.h" |
| 217 | +#include "udi_msc.h" |
| 218 | +#include "udi_hid_mouse.h" |
| 219 | +#include "udi_hid_kbd.h" |
| 220 | + |
| 221 | +#endif |
0 commit comments