add enable macro for CCID interface
This commit is contained in:
parent
ccd9a04146
commit
3b4c154fd1
@ -4,6 +4,7 @@
|
|||||||
#include "usbd_cdc.h"
|
#include "usbd_cdc.h"
|
||||||
#include "usbd_ccid.h"
|
#include "usbd_ccid.h"
|
||||||
#include "usbd_ctlreq.h"
|
#include "usbd_ctlreq.h"
|
||||||
|
#include "app.h"
|
||||||
|
|
||||||
static uint8_t USBD_Composite_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
static uint8_t USBD_Composite_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
||||||
|
|
||||||
@ -27,20 +28,29 @@ static uint8_t *USBD_Composite_GetOtherSpeedCfgDesc (uint16_t *length);
|
|||||||
|
|
||||||
static uint8_t *USBD_Composite_GetDeviceQualifierDescriptor (uint16_t *length);
|
static uint8_t *USBD_Composite_GetDeviceQualifierDescriptor (uint16_t *length);
|
||||||
|
|
||||||
|
#ifdef ENABLE_CCID
|
||||||
|
#define CCID_SIZE 84
|
||||||
|
#define CCID_NUM_INTERFACE 1
|
||||||
|
#else
|
||||||
|
#define CCID_NUM_INTERFACE 0
|
||||||
|
#define CCID_SIZE 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if DEBUG_LEVEL > 0
|
||||||
|
#define CDC_SIZE (49 + 8 + 9 + 4)
|
||||||
|
#define CDC_NUM_INTERFACE 2
|
||||||
|
#else
|
||||||
|
#define CDC_SIZE 0
|
||||||
|
#define CDC_NUM_INTERFACE 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define HID_SIZE 41
|
||||||
|
|
||||||
|
#define COMPOSITE_CDC_HID_DESCRIPTOR_SIZE (HID_SIZE + CDC_SIZE + CCID_SIZE)
|
||||||
|
#define NUM_INTERFACES (1 + CDC_NUM_INTERFACE + CCID_NUM_INTERFACE)
|
||||||
#define NUM_CLASSES 3
|
#define NUM_CLASSES 3
|
||||||
|
|
||||||
|
|
||||||
#if NUM_CLASSES>2
|
|
||||||
#define COMPOSITE_CDC_HID_DESCRIPTOR_SIZE (90 + 8+9 + 4 + 84)
|
|
||||||
#define NUM_INTERFACES 4
|
|
||||||
#elif NUM_CLASSES>1
|
|
||||||
#define COMPOSITE_CDC_HID_DESCRIPTOR_SIZE (90 + 8+9 + 4)
|
|
||||||
#define NUM_INTERFACES 3
|
|
||||||
#else
|
|
||||||
#define COMPOSITE_CDC_HID_DESCRIPTOR_SIZE (41)
|
|
||||||
#define NUM_INTERFACES 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define HID_INTF_NUM 0
|
#define HID_INTF_NUM 0
|
||||||
#define CDC_MASTER_INTF_NUM 1
|
#define CDC_MASTER_INTF_NUM 1
|
||||||
#define CDC_SLAVE_INTF_NUM 2
|
#define CDC_SLAVE_INTF_NUM 2
|
||||||
@ -101,7 +111,7 @@ __ALIGN_BEGIN uint8_t COMPOSITE_CDC_HID_DESCRIPTOR[COMPOSITE_CDC_HID_DESCRIPTOR_
|
|||||||
0x00,
|
0x00,
|
||||||
HID_BINTERVAL, /*bInterval: Polling Interval */
|
HID_BINTERVAL, /*bInterval: Polling Interval */
|
||||||
|
|
||||||
#if NUM_INTERFACES > 2
|
#if DEBUG_LEVEL > 0
|
||||||
|
|
||||||
/* */
|
/* */
|
||||||
/* CDC */
|
/* CDC */
|
||||||
@ -199,7 +209,7 @@ __ALIGN_BEGIN uint8_t COMPOSITE_CDC_HID_DESCRIPTOR[COMPOSITE_CDC_HID_DESCRIPTOR_
|
|||||||
0x04,
|
0x04,
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if NUM_INTERFACES>3
|
#ifdef ENABLE_CCID
|
||||||
|
|
||||||
/* CCID Interface Descriptor */
|
/* CCID Interface Descriptor */
|
||||||
9, /* bLength: Interface Descriptor size */
|
9, /* bLength: Interface Descriptor size */
|
||||||
@ -295,16 +305,21 @@ USBD_ClassTypeDef USBD_Composite =
|
|||||||
USBD_Composite_GetDeviceQualifierDescriptor,
|
USBD_Composite_GetDeviceQualifierDescriptor,
|
||||||
};
|
};
|
||||||
|
|
||||||
static USBD_ClassTypeDef *USBD_Classes[MAX_CLASSES];
|
static USBD_ClassTypeDef * USBD_Classes[MAX_CLASSES];
|
||||||
|
|
||||||
int in_endpoint_to_class[MAX_ENDPOINTS];
|
int in_endpoint_to_class[MAX_ENDPOINTS];
|
||||||
|
|
||||||
int out_endpoint_to_class[MAX_ENDPOINTS];
|
int out_endpoint_to_class[MAX_ENDPOINTS];
|
||||||
|
|
||||||
void USBD_Composite_Set_Classes(USBD_ClassTypeDef *hid_class, USBD_ClassTypeDef *ccid_class, USBD_ClassTypeDef *cdc_class) {
|
void USBD_Composite_Set_Classes(USBD_ClassTypeDef *hid_class, USBD_ClassTypeDef *ccid_class, USBD_ClassTypeDef *cdc_class) {
|
||||||
|
memset(USBD_Classes, 0 , sizeof(USBD_Classes));
|
||||||
USBD_Classes[0] = hid_class;
|
USBD_Classes[0] = hid_class;
|
||||||
|
#ifdef ENABLE_CCID
|
||||||
USBD_Classes[1] = ccid_class;
|
USBD_Classes[1] = ccid_class;
|
||||||
|
#endif
|
||||||
|
#if DEBUG_LEVEL > 0
|
||||||
USBD_Classes[2] = cdc_class;
|
USBD_Classes[2] = cdc_class;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static USBD_ClassTypeDef * getClass(uint8_t index)
|
static USBD_ClassTypeDef * getClass(uint8_t index)
|
||||||
@ -313,12 +328,15 @@ static USBD_ClassTypeDef * getClass(uint8_t index)
|
|||||||
{
|
{
|
||||||
case HID_INTF_NUM:
|
case HID_INTF_NUM:
|
||||||
return USBD_Classes[0];
|
return USBD_Classes[0];
|
||||||
|
#ifdef ENABLE_CCID
|
||||||
case CCID_INTF_NUM:
|
case CCID_INTF_NUM:
|
||||||
return USBD_Classes[1];
|
return USBD_Classes[1];
|
||||||
|
#endif
|
||||||
|
#if DEBUG_LEVEL > 0
|
||||||
case CDC_MASTER_INTF_NUM:
|
case CDC_MASTER_INTF_NUM:
|
||||||
case CDC_SLAVE_INTF_NUM:
|
case CDC_SLAVE_INTF_NUM:
|
||||||
return USBD_Classes[2];
|
return USBD_Classes[2];
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -326,7 +344,7 @@ static USBD_ClassTypeDef * getClass(uint8_t index)
|
|||||||
static uint8_t USBD_Composite_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx) {
|
static uint8_t USBD_Composite_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx) {
|
||||||
int i;
|
int i;
|
||||||
for(i = 0; i < NUM_CLASSES; i++) {
|
for(i = 0; i < NUM_CLASSES; i++) {
|
||||||
if (USBD_Classes[i]->Init(pdev, cfgidx) != USBD_OK) {
|
if (USBD_Classes[i] != NULL && USBD_Classes[i]->Init(pdev, cfgidx) != USBD_OK) {
|
||||||
return USBD_FAIL;
|
return USBD_FAIL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -337,7 +355,7 @@ static uint8_t USBD_Composite_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx) {
|
|||||||
static uint8_t USBD_Composite_DeInit (USBD_HandleTypeDef *pdev, uint8_t cfgidx) {
|
static uint8_t USBD_Composite_DeInit (USBD_HandleTypeDef *pdev, uint8_t cfgidx) {
|
||||||
int i;
|
int i;
|
||||||
for(i = 0; i < NUM_CLASSES; i++) {
|
for(i = 0; i < NUM_CLASSES; i++) {
|
||||||
if (USBD_Classes[i]->DeInit(pdev, cfgidx) != USBD_OK) {
|
if (USBD_Classes[i] != NULL && USBD_Classes[i]->DeInit(pdev, cfgidx) != USBD_OK) {
|
||||||
return USBD_FAIL;
|
return USBD_FAIL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -363,7 +381,7 @@ static uint8_t USBD_Composite_Setup (USBD_HandleTypeDef *pdev, USBD_SetupReqType
|
|||||||
|
|
||||||
case USB_REQ_GET_DESCRIPTOR :
|
case USB_REQ_GET_DESCRIPTOR :
|
||||||
for(i = 0; i < NUM_CLASSES; i++) {
|
for(i = 0; i < NUM_CLASSES; i++) {
|
||||||
if (USBD_Classes[i]->Setup(pdev, req) != USBD_OK) {
|
if (USBD_Classes[i] != NULL && USBD_Classes[i]->Setup(pdev, req) != USBD_OK) {
|
||||||
return USBD_FAIL;
|
return USBD_FAIL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -386,6 +404,8 @@ static uint8_t USBD_Composite_DataIn (USBD_HandleTypeDef *pdev, uint8_t epnum) {
|
|||||||
|
|
||||||
i = in_endpoint_to_class[epnum];
|
i = in_endpoint_to_class[epnum];
|
||||||
|
|
||||||
|
if (USBD_Classes[i] == NULL) return USBD_FAIL;
|
||||||
|
|
||||||
return USBD_Classes[i]->DataIn(pdev, epnum);
|
return USBD_Classes[i]->DataIn(pdev, epnum);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -394,6 +414,8 @@ static uint8_t USBD_Composite_DataOut (USBD_HandleTypeDef *pdev, uint8_t epnum)
|
|||||||
|
|
||||||
i = out_endpoint_to_class[epnum];
|
i = out_endpoint_to_class[epnum];
|
||||||
|
|
||||||
|
if (USBD_Classes[i] == NULL) return USBD_FAIL;
|
||||||
|
|
||||||
return USBD_Classes[i]->DataOut(pdev, epnum);
|
return USBD_Classes[i]->DataOut(pdev, epnum);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -401,7 +423,7 @@ static uint8_t USBD_Composite_DataOut (USBD_HandleTypeDef *pdev, uint8_t epnum)
|
|||||||
static uint8_t USBD_Composite_EP0_RxReady (USBD_HandleTypeDef *pdev) {
|
static uint8_t USBD_Composite_EP0_RxReady (USBD_HandleTypeDef *pdev) {
|
||||||
int i;
|
int i;
|
||||||
for(i = 0; i < NUM_CLASSES; i++) {
|
for(i = 0; i < NUM_CLASSES; i++) {
|
||||||
if (USBD_Classes[i]->EP0_RxReady != NULL) {
|
if (USBD_Classes[i] != NULL && USBD_Classes[i]->EP0_RxReady != NULL) {
|
||||||
if (USBD_Classes[i]->EP0_RxReady(pdev) != USBD_OK) {
|
if (USBD_Classes[i]->EP0_RxReady(pdev) != USBD_OK) {
|
||||||
return USBD_FAIL;
|
return USBD_FAIL;
|
||||||
}
|
}
|
||||||
|
@ -12,9 +12,13 @@
|
|||||||
#define DEBUG_UART USART1
|
#define DEBUG_UART USART1
|
||||||
|
|
||||||
#ifndef DEBUG_LEVEL
|
#ifndef DEBUG_LEVEL
|
||||||
|
// Enable the CDC ACM USB interface & debug logs (DEBUG_LEVEL > 0)
|
||||||
#define DEBUG_LEVEL 0
|
#define DEBUG_LEVEL 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Enable the CCID USB interface
|
||||||
|
// #define ENABLE_CCID
|
||||||
|
|
||||||
#define NON_BLOCK_PRINTING 0
|
#define NON_BLOCK_PRINTING 0
|
||||||
|
|
||||||
|
|
||||||
|
@ -707,7 +707,6 @@ void init_usb()
|
|||||||
// Enable USB Clock
|
// Enable USB Clock
|
||||||
SET_BIT(RCC->APB1ENR1, RCC_APB1ENR1_USBFSEN);
|
SET_BIT(RCC->APB1ENR1, RCC_APB1ENR1_USBFSEN);
|
||||||
|
|
||||||
#if DEBUG_LEVEL > 0
|
|
||||||
USBD_Composite_Set_Classes(&USBD_HID, &USBD_CCID, &USBD_CDC);
|
USBD_Composite_Set_Classes(&USBD_HID, &USBD_CCID, &USBD_CDC);
|
||||||
in_endpoint_to_class[HID_EPIN_ADDR & 0x7F] = 0;
|
in_endpoint_to_class[HID_EPIN_ADDR & 0x7F] = 0;
|
||||||
out_endpoint_to_class[HID_EPOUT_ADDR & 0x7F] = 0;
|
out_endpoint_to_class[HID_EPOUT_ADDR & 0x7F] = 0;
|
||||||
@ -720,17 +719,10 @@ void init_usb()
|
|||||||
|
|
||||||
USBD_Init(&Solo_USBD_Device, &Solo_Desc, 0);
|
USBD_Init(&Solo_USBD_Device, &Solo_Desc, 0);
|
||||||
USBD_RegisterClass(&Solo_USBD_Device, &USBD_Composite);
|
USBD_RegisterClass(&Solo_USBD_Device, &USBD_Composite);
|
||||||
// USBD_RegisterClass(&Solo_USBD_Device, &USBD_HID);
|
#if DEBUG_LEVEL > 0
|
||||||
//
|
|
||||||
// USBD_RegisterClass(&Solo_USBD_Device, &USBD_CDC);
|
|
||||||
USBD_CDC_RegisterInterface(&Solo_USBD_Device, &USBD_Interface_fops_FS);
|
USBD_CDC_RegisterInterface(&Solo_USBD_Device, &USBD_Interface_fops_FS);
|
||||||
#else
|
|
||||||
USBD_Init(&Solo_USBD_Device, &Solo_Desc, 0);
|
|
||||||
USBD_RegisterClass(&Solo_USBD_Device, &USBD_HID);
|
|
||||||
#endif
|
#endif
|
||||||
//Y
|
|
||||||
USBD_Start(&Solo_USBD_Device);
|
USBD_Start(&Solo_USBD_Device);
|
||||||
//Y
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void init_pwm(void)
|
void init_pwm(void)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user