|
| 1 | +#ifndef _USB_CDC_HID_CORE_H_ |
| 2 | +#define _USB_CDC_HID_CORE_H_ |
| 3 | + |
| 4 | +#include "usbd_ioreq.h" |
| 5 | + |
| 6 | +// CDC and HID packet sizes |
| 7 | +#define CDC_DATA_FS_MAX_PACKET_SIZE (64) // endpoint IN & OUT packet size |
| 8 | + |
| 9 | +#if 0 |
| 10 | +// CDC |
| 11 | +#define USB_CDC_HID_CONFIG_DESC_SIZ (75) |
| 12 | +#define USB_CDC_HID_NUM_INTERFACES (2) |
| 13 | +#define USB_CDC_HID_USE_CDC (1) |
| 14 | +#define USB_CDC_HID_USE_HID (0) |
| 15 | +#define CDC_IN_EP 0x81 /* EP1 for data IN */ |
| 16 | +#define CDC_OUT_EP 0x01 /* EP1 for data OUT */ |
| 17 | +#define CDC_CMD_EP 0x82 /* EP2 for CDC commands */ |
| 18 | +#define HID_IN_EP (0x83) |
| 19 | +#define HID_OUT_EP (0x03) |
| 20 | +#elif 0 |
| 21 | +// HID |
| 22 | +#define USB_CDC_HID_CONFIG_DESC_SIZ (32) |
| 23 | +#define USB_CDC_HID_NUM_INTERFACES (1) |
| 24 | +#define USB_CDC_HID_USE_CDC (0) |
| 25 | +#define USB_CDC_HID_USE_HID (1) |
| 26 | +#define CDC_IN_EP 0x81 /* EP1 for data IN */ |
| 27 | +#define CDC_OUT_EP 0x01 /* EP1 for data OUT */ |
| 28 | +#define CDC_CMD_EP 0x82 /* EP2 for CDC commands */ |
| 29 | +#define HID_IFACE_NUM (0) |
| 30 | +#define HID_IN_EP (0x81) |
| 31 | +#define HID_OUT_EP (0x01) |
| 32 | +#else |
| 33 | +// HID + CDC |
| 34 | +#define USB_CDC_HID_CONFIG_DESC_SIZ (100) |
| 35 | +#define USB_CDC_HID_NUM_INTERFACES (3) |
| 36 | +#define USB_CDC_HID_USE_CDC (1) |
| 37 | +#define USB_CDC_HID_USE_HID (1) |
| 38 | +#define CDC_IFACE_NUM (1) |
| 39 | +#define CDC_IN_EP (0x83) |
| 40 | +#define CDC_OUT_EP (0x03) |
| 41 | +#define CDC_CMD_EP (0x82) |
| 42 | +#define HID_IFACE_NUM (0) |
| 43 | +#define HID_IN_EP (0x81) |
| 44 | +#endif |
| 45 | + |
| 46 | +typedef struct { |
| 47 | + uint32_t bitrate; |
| 48 | + uint8_t format; |
| 49 | + uint8_t paritytype; |
| 50 | + uint8_t datatype; |
| 51 | +} USBD_CDC_LineCodingTypeDef; |
| 52 | + |
| 53 | +typedef struct _USBD_CDC_Itf { |
| 54 | + int8_t (* Init) (void); |
| 55 | + int8_t (* DeInit) (void); |
| 56 | + int8_t (* Control) (uint8_t, uint8_t * , uint16_t); |
| 57 | + int8_t (* Receive) (uint8_t *, uint32_t *); |
| 58 | +} USBD_CDC_ItfTypeDef; |
| 59 | + |
| 60 | +typedef struct { |
| 61 | + uint32_t data[CDC_DATA_FS_MAX_PACKET_SIZE/4]; /* Force 32bits alignment */ |
| 62 | + uint8_t CmdOpCode; |
| 63 | + uint8_t CmdLength; |
| 64 | + uint8_t *RxBuffer; |
| 65 | + uint8_t *TxBuffer; |
| 66 | + uint32_t RxLength; |
| 67 | + uint32_t TxLength; |
| 68 | + |
| 69 | + __IO uint32_t TxState; |
| 70 | + __IO uint32_t RxState; |
| 71 | +} USBD_CDC_HandleTypeDef; |
| 72 | + |
| 73 | +extern USBD_ClassTypeDef USBD_CDC_HID; |
| 74 | + |
| 75 | +uint8_t USBD_CDC_RegisterInterface(USBD_HandleTypeDef *pdev, USBD_CDC_ItfTypeDef *fops); |
| 76 | +uint8_t USBD_CDC_SetTxBuffer(USBD_HandleTypeDef *pdev, uint8_t *pbuff, uint16_t length); |
| 77 | +uint8_t USBD_CDC_SetRxBuffer(USBD_HandleTypeDef *pdev, uint8_t *pbuff); |
| 78 | +uint8_t USBD_CDC_ReceivePacket(USBD_HandleTypeDef *pdev); |
| 79 | +uint8_t USBD_CDC_TransmitPacket(USBD_HandleTypeDef *pdev); |
| 80 | + |
| 81 | +uint8_t USBD_HID_SendReport(USBD_HandleTypeDef *pdev, uint8_t *report, uint16_t len); |
| 82 | + |
| 83 | +#endif // _USB_CDC_HID_CORE_H_ |
0 commit comments