mirror of
https://github.com/candle-usb/candleLight_fw.git
synced 2025-01-28 06:02:52 +08:00
usbd_gs_can: add support for GS_USB_BREQ_DATA_BITTIMING and GS_USB_BREQ_BT_CONST_EXT
This commit is contained in:
parent
4dad6a10d2
commit
4ae1a7c2ad
@ -29,6 +29,7 @@ THE SOFTWARE.
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "gs_usb.h"
|
||||
#include "hal_include.h"
|
||||
#include "led.h"
|
||||
@ -47,9 +48,24 @@ typedef struct {
|
||||
} can_data_t;
|
||||
|
||||
extern const struct gs_device_bt_const CAN_btconst;
|
||||
extern const struct gs_device_bt_const_extended CAN_btconst_ext;
|
||||
|
||||
void can_init(can_data_t *channel, CAN_TypeDef *instance);
|
||||
void can_set_bittiming(can_data_t *channel, const struct gs_device_bittiming *timing);
|
||||
|
||||
#ifdef CONFIG_CANFD
|
||||
void can_set_data_bittiming(can_data_t *channel, const struct gs_device_bittiming *timing);
|
||||
#else
|
||||
static inline bool can_set_data_bittiming(can_data_t *channel,
|
||||
const struct gs_device_bittiming *timing)
|
||||
{
|
||||
(void)channel;
|
||||
(void)timing;
|
||||
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
void can_enable(can_data_t *channel, uint32_t mode);
|
||||
void can_disable(can_data_t *channel);
|
||||
bool can_is_enabled(can_data_t *channel);
|
||||
|
@ -29,6 +29,10 @@ THE SOFTWARE.
|
||||
#include "timer.h"
|
||||
#include "usbd_gs_can.h"
|
||||
|
||||
#ifndef CONFIG_CANFD
|
||||
const struct gs_device_bt_const_extended CAN_btconst_ext;
|
||||
#endif
|
||||
|
||||
bool can_check_bittiming_ok(const struct can_bittiming_const *btc,
|
||||
const struct gs_device_bittiming *timing)
|
||||
{
|
||||
|
@ -323,6 +323,14 @@ static uint8_t USBD_GS_CAN_Config_Request(USBD_HandleTypeDef *pdev, USBD_SetupRe
|
||||
}
|
||||
}
|
||||
|
||||
if (!IS_ENABLED(CONFIG_CANFD)) {
|
||||
switch (req->bRequest) {
|
||||
case GS_USB_BREQ_DATA_BITTIMING:
|
||||
case GS_USB_BREQ_BT_CONST_EXT:
|
||||
goto out_fail;
|
||||
}
|
||||
}
|
||||
|
||||
switch (req->bRequest) {
|
||||
// Host -> Device
|
||||
case GS_USB_BREQ_HOST_FORMAT:
|
||||
@ -349,6 +357,13 @@ static uint8_t USBD_GS_CAN_Config_Request(USBD_HandleTypeDef *pdev, USBD_SetupRe
|
||||
case GS_USB_BREQ_IDENTIFY:
|
||||
len = sizeof(struct gs_identify_mode);
|
||||
break;
|
||||
case GS_USB_BREQ_DATA_BITTIMING:
|
||||
len = sizeof(struct gs_device_bittiming);
|
||||
break;
|
||||
case GS_USB_BREQ_BT_CONST_EXT:
|
||||
src = &CAN_btconst_ext;
|
||||
len = sizeof(CAN_btconst_ext);
|
||||
break;
|
||||
case GS_USB_BREQ_SET_TERMINATION:
|
||||
if (get_term(req->wValue) == GS_CAN_TERMINATION_UNSUPPORTED) {
|
||||
goto out_fail;
|
||||
@ -382,6 +397,7 @@ static uint8_t USBD_GS_CAN_Config_Request(USBD_HandleTypeDef *pdev, USBD_SetupRe
|
||||
case GS_USB_BREQ_BITTIMING:
|
||||
case GS_USB_BREQ_MODE:
|
||||
case GS_USB_BREQ_IDENTIFY:
|
||||
case GS_USB_BREQ_DATA_BITTIMING:
|
||||
case GS_USB_BREQ_SET_TERMINATION:
|
||||
if (req->wLength > sizeof(hcan->ep0_buf)) {
|
||||
goto out_fail;
|
||||
@ -395,6 +411,7 @@ static uint8_t USBD_GS_CAN_Config_Request(USBD_HandleTypeDef *pdev, USBD_SetupRe
|
||||
case GS_USB_BREQ_BT_CONST:
|
||||
case GS_USB_BREQ_DEVICE_CONFIG:
|
||||
case GS_USB_BREQ_TIMESTAMP:
|
||||
case GS_USB_BREQ_BT_CONST_EXT:
|
||||
case GS_USB_BREQ_GET_TERMINATION:
|
||||
USBD_CtlSendData(pdev, (uint8_t *)src, len);
|
||||
break;
|
||||
@ -527,6 +544,15 @@ static uint8_t USBD_GS_CAN_EP0_RxReady(USBD_HandleTypeDef *pdev) {
|
||||
}
|
||||
break;
|
||||
}
|
||||
case GS_USB_BREQ_DATA_BITTIMING: {
|
||||
const struct gs_device_bittiming *timing = (struct gs_device_bittiming *)hcan->ep0_buf;
|
||||
|
||||
if (!can_check_bittiming_ok(&CAN_btconst_ext.dbtc, timing))
|
||||
goto out_fail;
|
||||
|
||||
can_set_data_bittiming(channel, timing);
|
||||
break;
|
||||
}
|
||||
case GS_USB_BREQ_SET_TERMINATION: {
|
||||
if (get_term(req->wValue) != GS_CAN_TERMINATION_UNSUPPORTED) {
|
||||
struct gs_device_termination_state *term_state;
|
||||
|
Loading…
x
Reference in New Issue
Block a user