|
| 1 | + |
| 2 | +#include <stdbool.h> |
| 3 | +#include <stdint.h> |
| 4 | + |
| 5 | +#ifndef CONF_USB_H_INCLUDED |
| 6 | +#define CONF_USB_H_INCLUDED |
| 7 | + |
| 8 | +#define USB_DEVICE_MAJOR_VERSION 1 |
| 9 | +#define USB_DEVICE_MINOR_VERSION 0 |
| 10 | +#define USB_DEVICE_POWER 100 // Consumption on Vbus line (mA) |
| 11 | +#define USB_DEVICE_ATTR \ |
| 12 | + (USB_CONFIG_ATTR_BUS_POWERED) |
| 13 | +// (USB_CONFIG_ATTR_REMOTE_WAKEUP|USB_CONFIG_ATTR_SELF_POWERED) |
| 14 | +// (USB_CONFIG_ATTR_REMOTE_WAKEUP|USB_CONFIG_ATTR_BUS_POWERED) |
| 15 | + |
| 16 | +//! USB Device string definitions (Optional) |
| 17 | +#ifndef USB_DEVICE_MANUFACTURE_NAME |
| 18 | +# define USB_DEVICE_MANUFACTURE_NAME "Adafruit Industries" |
| 19 | +#endif |
| 20 | + |
| 21 | +#ifndef USB_DEVICE_PRODUCT_NAME |
| 22 | +# define USB_DEVICE_PRODUCT_NAME "Feather M0 Adalogger" |
| 23 | +#endif |
| 24 | + |
| 25 | +#define USB_DEVICE_GET_SERIAL_NAME_POINTER serial_number |
| 26 | +#define USB_DEVICE_GET_SERIAL_NAME_LENGTH 32 |
| 27 | +extern char serial_number[USB_DEVICE_GET_SERIAL_NAME_LENGTH]; |
| 28 | + |
| 29 | +//! Control endpoint size |
| 30 | +#define USB_DEVICE_EP_CTRL_SIZE 64 |
| 31 | + |
| 32 | +//! Two interfaces for this device (CDC COM + CDC DATA + MSC) |
| 33 | +#define USB_DEVICE_NB_INTERFACE 3 |
| 34 | + |
| 35 | +// (3 | USB_EP_DIR_IN) // CDC Notify endpoint |
| 36 | +// (4 | USB_EP_DIR_IN) // CDC TX |
| 37 | +// (5 | USB_EP_DIR_OUT) // CDC RX |
| 38 | +// (1 | USB_EP_DIR_IN) // MSC IN |
| 39 | +// (2 | USB_EP_DIR_OUT) // MSC OUT |
| 40 | +#define USB_DEVICE_MAX_EP 5 |
| 41 | + |
| 42 | +#define UDI_CDC_PORT_NB 1 |
| 43 | +#define UDI_CDC_ENABLE_EXT(port) mp_cdc_enable(port) |
| 44 | +extern bool mp_cdc_enable(uint8_t port); |
| 45 | +#define UDI_CDC_DISABLE_EXT(port) mp_cdc_disable(port) |
| 46 | +extern void mp_cdc_disable(uint8_t port); |
| 47 | +#define UDI_CDC_LOW_RATE |
| 48 | + |
| 49 | +#define UDI_CDC_DEFAULT_RATE 115200 |
| 50 | +#define UDI_CDC_DEFAULT_STOPBITS CDC_STOP_BITS_1 |
| 51 | +#define UDI_CDC_DEFAULT_PARITY CDC_PAR_NONE |
| 52 | +#define UDI_CDC_DEFAULT_DATABITS 8 |
| 53 | + |
| 54 | +#define UDI_CDC_RX_NOTIFY(port) usb_rx_notify() |
| 55 | +void usb_rx_notify(void); |
| 56 | +#define UDI_CDC_SET_CODING_EXT(port,cfg) |
| 57 | +#define UDI_CDC_SET_DTR_EXT(port,set) |
| 58 | +#define UDI_CDC_SET_RTS_EXT(port,set) |
| 59 | + |
| 60 | +/** |
| 61 | + * USB CDC low level configuration |
| 62 | + * In standalone these configurations are defined by the CDC module. |
| 63 | + * For composite device, these configuration must be defined here |
| 64 | + * @{ |
| 65 | + */ |
| 66 | +//! Endpoint numbers definition |
| 67 | + |
| 68 | +#define UDI_CDC_COMM_EP_0 (3 | USB_EP_DIR_IN) // Notify endpoint |
| 69 | +#define UDI_CDC_DATA_EP_IN_0 (4 | USB_EP_DIR_IN) // TX |
| 70 | +#define UDI_CDC_DATA_EP_OUT_0 (5 | USB_EP_DIR_OUT) // RX |
| 71 | + |
| 72 | +//! Interface numbers |
| 73 | +#define UDI_CDC_COMM_IFACE_NUMBER_0 0 |
| 74 | +#define UDI_CDC_DATA_IFACE_NUMBER_0 1 |
| 75 | + |
| 76 | +/** |
| 77 | + * Configuration of MSC interface |
| 78 | + * @{ |
| 79 | + */ |
| 80 | +//! Vendor name and Product version of MSC interface |
| 81 | +#define UDI_MSC_GLOBAL_VENDOR_ID \ |
| 82 | + 'A', 'T', 'M', 'E', 'L', ' ', ' ', ' ' |
| 83 | +#define UDI_MSC_GLOBAL_PRODUCT_VERSION \ |
| 84 | + '1', '.', '0', '0' |
| 85 | + |
| 86 | +//! Interface callback definition |
| 87 | +#define UDI_MSC_ENABLE_EXT() mp_msc_enable() |
| 88 | +extern bool mp_msc_enable(); |
| 89 | +#define UDI_MSC_DISABLE_EXT() mp_msc_disable() |
| 90 | +extern void mp_msc_disable(); |
| 91 | + |
| 92 | +//! Enable id string of interface to add an extra USB string |
| 93 | +#define UDI_MSC_STRING_ID 5 |
| 94 | + |
| 95 | +/** |
| 96 | + * USB MSC low level configuration |
| 97 | + * In standalone these configurations are defined by the MSC module. |
| 98 | + * For composite device, these configuration must be defined here |
| 99 | + * @{ |
| 100 | + */ |
| 101 | +//! Endpoint numbers definition |
| 102 | +#define UDI_MSC_EP_IN (1 | USB_EP_DIR_IN) |
| 103 | +#define UDI_MSC_EP_OUT (2 | USB_EP_DIR_OUT) |
| 104 | + |
| 105 | +//! Interface number |
| 106 | +#define UDI_MSC_IFACE_NUMBER 2 |
| 107 | + |
| 108 | +/** |
| 109 | + * Description of Composite Device |
| 110 | + * @{ |
| 111 | + */ |
| 112 | +//! USB Interfaces descriptor structure |
| 113 | +#define UDI_COMPOSITE_DESC_T \ |
| 114 | + usb_iad_desc_t udi_cdc_iad; \ |
| 115 | + udi_cdc_comm_desc_t udi_cdc_comm; \ |
| 116 | + udi_cdc_data_desc_t udi_cdc_data; \ |
| 117 | + udi_msc_desc_t udi_msc |
| 118 | + |
| 119 | +//! USB Interfaces descriptor value for Full Speed |
| 120 | +#define UDI_COMPOSITE_DESC_FS \ |
| 121 | + .udi_cdc_iad = UDI_CDC_IAD_DESC_0, \ |
| 122 | + .udi_cdc_comm = UDI_CDC_COMM_DESC_0, \ |
| 123 | + .udi_cdc_data = UDI_CDC_DATA_DESC_0_FS, \ |
| 124 | + .udi_msc = UDI_MSC_DESC_FS |
| 125 | + |
| 126 | +//! USB Interfaces descriptor value for High Speed |
| 127 | +#define UDI_COMPOSITE_DESC_HS \ |
| 128 | + .udi_cdc_iad = UDI_CDC_IAD_DESC_0, \ |
| 129 | + .udi_cdc_comm = UDI_CDC_COMM_DESC_0, \ |
| 130 | + .udi_cdc_data = UDI_CDC_DATA_DESC_0_HS, \ |
| 131 | + .udi_msc = UDI_MSC_DESC_HS |
| 132 | + |
| 133 | +//! USB Interface APIs |
| 134 | +#define UDI_COMPOSITE_API \ |
| 135 | + &udi_api_cdc_comm, \ |
| 136 | + &udi_api_cdc_data, \ |
| 137 | + &udi_api_msc |
| 138 | +//@} |
| 139 | + |
| 140 | +/** |
| 141 | + * USB Device Driver Configuration |
| 142 | + * @{ |
| 143 | + */ |
| 144 | +//@} |
| 145 | + |
| 146 | +//! The includes of classes and other headers must be done at the end of this file to avoid compile error |
| 147 | +#include "udi_cdc.h" |
| 148 | +#include "udi_msc.h" |
| 149 | + |
| 150 | +#endif |
0 commit comments