mirror of
https://github.com/candle-usb/candleLight_fw.git
synced 2025-01-28 06:02:52 +08:00
rename USBD_StrDesc to USBD_DescBuf
(will reuse not only for strings)
This commit is contained in:
parent
c3efe48018
commit
f380b5eafd
@ -29,4 +29,5 @@ THE SOFTWARE.
|
||||
#include "usbd_def.h"
|
||||
|
||||
extern USBD_DescriptorsTypeDef FS_Desc;
|
||||
extern uint8_t USBD_StrDesc[USBD_MAX_STR_DESC_SIZ];
|
||||
extern uint8_t USBD_DescBuf[USBD_DESC_BUF_SIZE];
|
||||
|
||||
|
@ -30,7 +30,7 @@ THE SOFTWARE.
|
||||
|
||||
#define USBD_MAX_NUM_INTERFACES 1
|
||||
#define USBD_MAX_NUM_CONFIGURATION 1
|
||||
#define USBD_MAX_STR_DESC_SIZ 128
|
||||
#define USBD_DESC_BUF_SIZE 128
|
||||
#define USBD_SUPPORT_USER_STRING_DESC 1
|
||||
#define USBD_SELF_POWERED 0
|
||||
#define DEVICE_FS 0
|
||||
|
@ -39,7 +39,7 @@ uint8_t *USBD_FS_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *lengt
|
||||
|
||||
#ifdef USB_SUPPORT_USER_STRING_DESC
|
||||
uint8_t *USBD_FS_USRStringDesc(USBD_SpeedTypeDef speed, uint8_t idx, uint16_t *length);
|
||||
#endif /* USB_SUPPORT_USER_STRING_DESC */
|
||||
#endif /* USB_SUPPORT_USER_STRING_DESC */
|
||||
|
||||
USBD_DescriptorsTypeDef FS_Desc = {
|
||||
USBD_FS_DeviceDescriptor,
|
||||
@ -82,7 +82,7 @@ __ALIGN_BEGIN uint8_t USBD_LangIDDesc[USB_LEN_LANGID_STR_DESC] __ALIGN_END =
|
||||
HIBYTE(USBD_LANGID_STRING),
|
||||
};
|
||||
|
||||
__ALIGN_BEGIN uint8_t USBD_StrDesc[USBD_MAX_STR_DESC_SIZ] __ALIGN_END;
|
||||
__ALIGN_BEGIN uint8_t USBD_DescBuf[USBD_DESC_BUF_SIZE] __ALIGN_END;
|
||||
|
||||
uint8_t *USBD_FS_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
||||
{
|
||||
@ -101,15 +101,15 @@ uint8_t *USBD_FS_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
||||
uint8_t *USBD_FS_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
||||
{
|
||||
UNUSED(speed);
|
||||
USBD_GetString(USBD_PRODUCT_STRING_FS, USBD_StrDesc, length);
|
||||
return USBD_StrDesc;
|
||||
USBD_GetString(USBD_PRODUCT_STRING_FS, USBD_DescBuf, length);
|
||||
return USBD_DescBuf;
|
||||
}
|
||||
|
||||
uint8_t *USBD_FS_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
||||
{
|
||||
UNUSED(speed);
|
||||
USBD_GetString (USBD_MANUFACTURER_STRING, USBD_StrDesc, length);
|
||||
return USBD_StrDesc;
|
||||
USBD_GetString (USBD_MANUFACTURER_STRING, USBD_DescBuf, length);
|
||||
return USBD_DescBuf;
|
||||
}
|
||||
|
||||
uint8_t *USBD_FS_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
||||
@ -122,20 +122,20 @@ uint8_t *USBD_FS_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
||||
hex32(buf + 8, *(uint32_t*)(UID_BASE + 4));
|
||||
hex32(buf + 16, *(uint32_t*)(UID_BASE + 8));
|
||||
|
||||
USBD_GetString((uint8_t*)buf, USBD_StrDesc, length);
|
||||
return USBD_StrDesc;
|
||||
USBD_GetString((uint8_t*)buf, USBD_DescBuf, length);
|
||||
return USBD_DescBuf;
|
||||
}
|
||||
|
||||
uint8_t *USBD_FS_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
||||
{
|
||||
UNUSED(speed);
|
||||
USBD_GetString(USBD_CONFIGURATION_STRING_FS, USBD_StrDesc, length);
|
||||
return USBD_StrDesc;
|
||||
USBD_GetString(USBD_CONFIGURATION_STRING_FS, USBD_DescBuf, length);
|
||||
return USBD_DescBuf;
|
||||
}
|
||||
|
||||
uint8_t *USBD_FS_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
||||
{
|
||||
UNUSED(speed);
|
||||
USBD_GetString(USBD_INTERFACE_STRING_FS, USBD_StrDesc, length);
|
||||
return USBD_StrDesc;
|
||||
USBD_GetString(USBD_INTERFACE_STRING_FS, USBD_DescBuf, length);
|
||||
return USBD_DescBuf;
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ typedef struct {
|
||||
queue_t *q_frame_pool;
|
||||
queue_t *q_from_host;
|
||||
|
||||
struct gs_host_frame *from_host_buf;
|
||||
struct gs_host_frame *from_host_buf;
|
||||
|
||||
can_data_t *channels[NUM_CAN_CHANNEL];
|
||||
|
||||
@ -62,7 +62,8 @@ typedef struct {
|
||||
bool timestamps_enabled;
|
||||
uint32_t sof_timestamp_us;
|
||||
|
||||
bool pad_pkts_to_max_pkt_size;
|
||||
bool pad_pkts_to_max_pkt_size;
|
||||
|
||||
} USBD_GS_CAN_HandleTypeDef __attribute__ ((aligned (4)));
|
||||
|
||||
static uint8_t USBD_GS_CAN_Start(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
||||
@ -286,6 +287,7 @@ static const struct gs_device_bt_const USBD_GS_CAN_btconst = {
|
||||
1, // brp increment;
|
||||
};
|
||||
|
||||
|
||||
uint8_t USBD_GS_CAN_Init(USBD_HandleTypeDef *pdev, queue_t *q_frame_pool, queue_t *q_from_host, led_data_t *leds)
|
||||
{
|
||||
uint8_t ret = USBD_FAIL;
|
||||
@ -306,16 +308,18 @@ uint8_t USBD_GS_CAN_Init(USBD_HandleTypeDef *pdev, queue_t *q_frame_pool, queue_
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static uint8_t USBD_GS_CAN_Start(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||
{
|
||||
UNUSED(cfgidx);
|
||||
uint8_t ret = USBD_FAIL;
|
||||
|
||||
if (pdev->pClassData) {
|
||||
USBD_GS_CAN_HandleTypeDef *hcan = (USBD_GS_CAN_HandleTypeDef*) pdev->pClassData;
|
||||
USBD_GS_CAN_HandleTypeDef *hcan = (USBD_GS_CAN_HandleTypeDef*) pdev->pClassData;
|
||||
USBD_LL_OpenEP(pdev, GSUSB_ENDPOINT_IN, USBD_EP_TYPE_BULK, CAN_DATA_MAX_PACKET_SIZE);
|
||||
USBD_LL_OpenEP(pdev, GSUSB_ENDPOINT_OUT, USBD_EP_TYPE_BULK, CAN_DATA_MAX_PACKET_SIZE);
|
||||
hcan->from_host_buf = queue_pop_front(hcan->q_frame_pool);
|
||||
hcan->from_host_buf = queue_pop_front(hcan->q_frame_pool);
|
||||
USBD_GS_CAN_PrepareReceive(pdev);
|
||||
ret = USBD_OK;
|
||||
} else {
|
||||
@ -350,9 +354,9 @@ void USBD_GS_CAN_SetChannel(USBD_HandleTypeDef *pdev, uint8_t channel, can_data_
|
||||
}
|
||||
|
||||
static led_seq_step_t led_identify_seq[] = {
|
||||
{ .state = 0x01, .time_in_10ms = 10 },
|
||||
{ .state = 0x02, .time_in_10ms = 10 },
|
||||
{ .state = 0x00, .time_in_10ms = 0 }
|
||||
{ .state = 0x01, .time_in_10ms = 10 },
|
||||
{ .state = 0x02, .time_in_10ms = 10 },
|
||||
{ .state = 0x00, .time_in_10ms = 0 }
|
||||
};
|
||||
|
||||
static uint8_t USBD_GS_CAN_EP0_RxReady(USBD_HandleTypeDef *pdev) {
|
||||
@ -366,35 +370,35 @@ static uint8_t USBD_GS_CAN_EP0_RxReady(USBD_HandleTypeDef *pdev) {
|
||||
|
||||
USBD_SetupReqTypedef *req = &hcan->last_setup_request;
|
||||
|
||||
switch (req->bRequest) {
|
||||
switch (req->bRequest) {
|
||||
|
||||
case GS_USB_BREQ_HOST_FORMAT:
|
||||
// TODO process host data (expect 0x0000beef in byte_order)
|
||||
memcpy(&hcan->host_config, hcan->ep0_buf, sizeof(hcan->host_config));
|
||||
break;
|
||||
case GS_USB_BREQ_HOST_FORMAT:
|
||||
// TODO process host data (expect 0x0000beef in byte_order)
|
||||
memcpy(&hcan->host_config, hcan->ep0_buf, sizeof(hcan->host_config));
|
||||
break;
|
||||
|
||||
case GS_USB_BREQ_IDENTIFY:
|
||||
memcpy(¶m_u32, hcan->ep0_buf, sizeof(param_u32));
|
||||
if (param_u32) {
|
||||
led_run_sequence(hcan->leds, led_identify_seq, -1);
|
||||
} else {
|
||||
ch = hcan->channels[req->wValue]; // TODO verify wValue input data (implement getChannelData() ?)
|
||||
led_set_mode(hcan->leds, can_is_enabled(ch) ? led_mode_normal : led_mode_off);
|
||||
}
|
||||
break;
|
||||
case GS_USB_BREQ_IDENTIFY:
|
||||
memcpy(¶m_u32, hcan->ep0_buf, sizeof(param_u32));
|
||||
if (param_u32) {
|
||||
led_run_sequence(hcan->leds, led_identify_seq, -1);
|
||||
} else {
|
||||
ch = hcan->channels[req->wValue]; // TODO verify wValue input data (implement getChannelData() ?)
|
||||
led_set_mode(hcan->leds, can_is_enabled(ch) ? led_mode_normal : led_mode_off);
|
||||
}
|
||||
break;
|
||||
|
||||
case GS_USB_BREQ_SET_USER_ID:
|
||||
memcpy(¶m_u32, hcan->ep0_buf, sizeof(param_u32));
|
||||
if (flash_set_user_id(req->wValue, param_u32)) {
|
||||
flash_flush();
|
||||
}
|
||||
break;
|
||||
case GS_USB_BREQ_SET_USER_ID:
|
||||
memcpy(¶m_u32, hcan->ep0_buf, sizeof(param_u32));
|
||||
if (flash_set_user_id(req->wValue, param_u32)) {
|
||||
flash_flush();
|
||||
}
|
||||
break;
|
||||
|
||||
case GS_USB_BREQ_MODE:
|
||||
if (req->wValue < NUM_CAN_CHANNEL) {
|
||||
case GS_USB_BREQ_MODE:
|
||||
if (req->wValue < NUM_CAN_CHANNEL) {
|
||||
|
||||
mode = (struct gs_device_mode*)hcan->ep0_buf;
|
||||
ch = hcan->channels[req->wValue];
|
||||
mode = (struct gs_device_mode*)hcan->ep0_buf;
|
||||
ch = hcan->channels[req->wValue];
|
||||
|
||||
if (mode->mode == GS_CAN_MODE_RESET) {
|
||||
|
||||
@ -416,11 +420,11 @@ static uint8_t USBD_GS_CAN_EP0_RxReady(USBD_HandleTypeDef *pdev) {
|
||||
led_set_mode(hcan->leds, led_mode_normal);
|
||||
}
|
||||
}
|
||||
break;
|
||||
break;
|
||||
|
||||
case GS_USB_BREQ_BITTIMING:
|
||||
timing = (struct gs_device_bittiming*)hcan->ep0_buf;
|
||||
if (req->wValue < NUM_CAN_CHANNEL) {
|
||||
case GS_USB_BREQ_BITTIMING:
|
||||
timing = (struct gs_device_bittiming*)hcan->ep0_buf;
|
||||
if (req->wValue < NUM_CAN_CHANNEL) {
|
||||
can_set_bittiming(
|
||||
hcan->channels[req->wValue],
|
||||
timing->brp,
|
||||
@ -428,12 +432,12 @@ static uint8_t USBD_GS_CAN_EP0_RxReady(USBD_HandleTypeDef *pdev) {
|
||||
timing->phase_seg2,
|
||||
timing->sjw
|
||||
);
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
req->bRequest = 0xFF;
|
||||
return USBD_OK;
|
||||
@ -494,7 +498,7 @@ static uint8_t USBD_GS_CAN_Config_Request(USBD_HandleTypeDef *pdev, USBD_SetupRe
|
||||
case GS_USB_BREQ_TIMESTAMP:
|
||||
memcpy(hcan->ep0_buf, &hcan->sof_timestamp_us, sizeof(hcan->sof_timestamp_us));
|
||||
USBD_CtlSendData(pdev, hcan->ep0_buf, sizeof(hcan->sof_timestamp_us));
|
||||
break;
|
||||
break;
|
||||
|
||||
case GS_USB_BREQ_GET_USER_ID:
|
||||
if (req->wValue < NUM_CAN_CHANNEL) {
|
||||
@ -555,6 +559,7 @@ bool USBD_GS_CAN_CustomDeviceRequest(USBD_HandleTypeDef *pdev, USBD_SetupReqType
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -611,20 +616,20 @@ static uint8_t USBD_GS_CAN_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum) {
|
||||
|
||||
uint32_t rxlen = USBD_LL_GetRxDataSize(pdev, epnum);
|
||||
if (rxlen >= (sizeof(struct gs_host_frame)-4)) {
|
||||
struct gs_host_frame *frame = queue_pop_front_i(hcan->q_frame_pool);
|
||||
struct gs_host_frame *frame = queue_pop_front_i(hcan->q_frame_pool);
|
||||
if(frame){
|
||||
queue_push_back_i(hcan->q_from_host, hcan->from_host_buf);
|
||||
hcan->from_host_buf = frame;
|
||||
|
||||
retval = USBD_OK;
|
||||
queue_push_back_i(hcan->q_from_host, hcan->from_host_buf);
|
||||
hcan->from_host_buf = frame;
|
||||
|
||||
retval = USBD_OK;
|
||||
}
|
||||
else{
|
||||
// Discard current packet from host if we have no place
|
||||
// to put the next one
|
||||
// Discard current packet from host if we have no place
|
||||
// to put the next one
|
||||
}
|
||||
}
|
||||
USBD_GS_CAN_PrepareReceive(pdev);
|
||||
return retval;
|
||||
return retval;
|
||||
}
|
||||
|
||||
static uint8_t *USBD_GS_CAN_GetCfgDesc(uint16_t *len)
|
||||
@ -675,21 +680,21 @@ uint8_t USBD_GS_CAN_GetPadPacketsToMaxPacketSize(USBD_HandleTypeDef *pdev)
|
||||
|
||||
uint8_t USBD_GS_CAN_SendFrame(USBD_HandleTypeDef *pdev, struct gs_host_frame *frame)
|
||||
{
|
||||
uint8_t buf[CAN_DATA_MAX_PACKET_SIZE],*send_addr;
|
||||
|
||||
uint8_t buf[CAN_DATA_MAX_PACKET_SIZE],*send_addr;
|
||||
|
||||
USBD_GS_CAN_HandleTypeDef *hcan = (USBD_GS_CAN_HandleTypeDef*)pdev->pClassData;
|
||||
size_t len = sizeof(struct gs_host_frame);
|
||||
|
||||
if (!hcan->timestamps_enabled)
|
||||
len -= 4;
|
||||
len -= 4;
|
||||
|
||||
send_addr = (uint8_t *)frame;
|
||||
|
||||
|
||||
if(hcan->pad_pkts_to_max_pkt_size){
|
||||
// When talking to WinUSB it seems to help a lot if the
|
||||
// When talking to WinUSB it seems to help a lot if the
|
||||
// size of packet you send equals the max packet size.
|
||||
// In this mode, fill packets out to max packet size and
|
||||
// then send.
|
||||
// In this mode, fill packets out to max packet size and
|
||||
// then send.
|
||||
memcpy(buf, frame, len);
|
||||
|
||||
// zero rest of buffer
|
||||
@ -697,7 +702,7 @@ uint8_t USBD_GS_CAN_SendFrame(USBD_HandleTypeDef *pdev, struct gs_host_frame *fr
|
||||
send_addr = buf;
|
||||
len = sizeof(buf);
|
||||
}
|
||||
|
||||
|
||||
return USBD_GS_CAN_Transmit(pdev, send_addr, len);
|
||||
}
|
||||
|
||||
@ -707,8 +712,8 @@ uint8_t *USBD_GS_CAN_GetStrDesc(USBD_HandleTypeDef *pdev, uint8_t index, uint16_
|
||||
|
||||
switch (index) {
|
||||
case DFU_INTERFACE_STR_INDEX:
|
||||
USBD_GetString(DFU_INTERFACE_STRING_FS, USBD_StrDesc, length);
|
||||
return USBD_StrDesc;
|
||||
USBD_GetString(DFU_INTERFACE_STRING_FS, USBD_DescBuf, length);
|
||||
return USBD_DescBuf;
|
||||
case 0xEE:
|
||||
*length = sizeof(USBD_GS_CAN_WINUSB_STR);
|
||||
return USBD_GS_CAN_WINUSB_STR;
|
||||
@ -724,3 +729,4 @@ bool USBD_GS_CAN_DfuDetachRequested(USBD_HandleTypeDef *pdev)
|
||||
USBD_GS_CAN_HandleTypeDef *hcan = (USBD_GS_CAN_HandleTypeDef*)pdev->pClassData;
|
||||
return hcan->dfu_detach_requested;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user