-
Notifications
You must be signed in to change notification settings - Fork 280
Commit
The mcba_usb kernel driver in linux has support for configurable terminating resistors. This patch adds similar support to this firmware which the gs_usb USB driver would then activate via the netlink interface.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -206,6 +206,11 @@ THE SOFTWARE. | |
#define USB_Pin_DM GPIO_PIN_11 | ||
#define USB_Pin_DP GPIO_PIN_12 | ||
|
||
#define PIN_TERM_GPIO_Port GPIOB | ||
#define PIN_TERM_Pin GPIO_PIN_3 | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
Daniel-Trevitz
Author
Contributor
|
||
#define PIN_TERM_Mode GPIO_MODE_OUTPUT_PP | ||
#define PIN_TERM_Active_High 1 | ||
|
||
#else | ||
#error please define BOARD | ||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,6 +70,19 @@ void gpio_init(void) | |
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; | ||
HAL_GPIO_Init(LEDTX_GPIO_Port, &GPIO_InitStruct); | ||
|
||
#ifdef PIN_TERM_Pin | ||
#if (PIN_TERM_Active_High == 1) | ||
HAL_GPIO_WritePin(PIN_TERM_GPIO_Port, PIN_TERM_Pin, GPIO_PIN_RESET); | ||
#else | ||
HAL_GPIO_WritePin(PIN_TERM_GPIO_Port, PIN_TERM_Pin, GPIO_PIN_SET); | ||
#endif | ||
GPIO_InitStruct.Pin = PIN_TERM_Pin; | ||
GPIO_InitStruct.Mode = PIN_TERM_Mode; | ||
GPIO_InitStruct.Pull = GPIO_NOPULL; | ||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; | ||
HAL_GPIO_Init(PIN_TERM_GPIO_Port, &GPIO_InitStruct); | ||
#endif | ||
|
||
#if defined(BOARD_cannette) | ||
HAL_GPIO_WritePin(nCANSTBY_Port, nCANSTBY_Pin, GPIO_PIN_RESET); | ||
GPIO_InitStruct.Pin = nCANSTBY_Pin; | ||
|
@@ -104,3 +117,37 @@ void gpio_init(void) | |
HAL_GPIO_Init(USB_GPIO_Port, &GPIO_InitStruct); | ||
#endif | ||
} | ||
|
||
static int term_state = 0; | ||
|
||
void set_term(int channel, int state) | ||
{ | ||
if (state) | ||
This comment has been minimized.
Sorry, something went wrong.
marckleinebudde
Contributor
|
||
{ | ||
term_state |= 1 << channel; | ||
} | ||
else | ||
{ | ||
term_state &= ~(1 << channel); | ||
} | ||
|
||
// TODO add support for multiple channels | ||
#ifndef PIN_TERM_Pin | ||
(void)state; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
#else | ||
#if (PIN_TERM_Active_High == 1) | ||
# define TERM_ON GPIO_PIN_SET | ||
# define TERM_OFF GPIO_PIN_RESET | ||
#else | ||
# define TERM_ON GPIO_PIN_RESET | ||
# define TERM_OFF GPIO_PIN_SET | ||
#endif | ||
|
||
HAL_GPIO_WritePin(PIN_TERM_GPIO_Port, PIN_TERM_Pin, state ? TERM_ON : TERM_OFF); | ||
#endif | ||
} | ||
|
||
int is_term_on(unsigned int channel) | ||
{ | ||
return !!(term_state & (1 << channel)); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,7 @@ THE SOFTWARE. | |
#include "usbd_ioreq.h" | ||
#include "gs_usb.h" | ||
#include "can.h" | ||
#include "gpio.h" | ||
#include "timer.h" | ||
#include "flash.h" | ||
|
||
|
@@ -272,7 +273,11 @@ static const struct gs_device_bt_const USBD_GS_CAN_btconst = { | |
| GS_CAN_FEATURE_HW_TIMESTAMP | ||
| GS_CAN_FEATURE_IDENTIFY | ||
| GS_CAN_FEATURE_USER_ID | ||
| GS_CAN_FEATURE_PAD_PKTS_TO_MAX_PKT_SIZE, | ||
| GS_CAN_FEATURE_PAD_PKTS_TO_MAX_PKT_SIZE | ||
#ifdef PIN_TERM_Pin | ||
| GS_CAN_FEATURE_TERMINATION | ||
#endif | ||
, | ||
CAN_CLOCK_SPEED, // can timing base clock | ||
1, // tseg1 min | ||
16, // tseg1 max | ||
|
@@ -383,6 +388,11 @@ static uint8_t USBD_GS_CAN_EP0_RxReady(USBD_HandleTypeDef *pdev) { | |
} | ||
break; | ||
|
||
case GS_USB_BREQ_SET_TERMINATION: | ||
memcpy(¶m_u32, hcan->ep0_buf, sizeof(param_u32)); | ||
set_term(req->wValue, param_u32); | ||
This comment has been minimized.
Sorry, something went wrong.
marckleinebudde
Contributor
|
||
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)) { | ||
|
@@ -477,10 +487,17 @@ static uint8_t USBD_GS_CAN_Config_Request(USBD_HandleTypeDef *pdev, USBD_SetupRe | |
case GS_USB_BREQ_BITTIMING: | ||
case GS_USB_BREQ_IDENTIFY: | ||
case GS_USB_BREQ_SET_USER_ID: | ||
case GS_USB_BREQ_SET_TERMINATION: | ||
hcan->last_setup_request = *req; | ||
USBD_CtlPrepareRx(pdev, hcan->ep0_buf, req->wLength); | ||
break; | ||
|
||
case GS_USB_BREQ_GET_TERMINATION: | ||
d32 = is_term_on(req->wValue); | ||
memcpy(hcan->ep0_buf, &d32, sizeof(d32)); | ||
USBD_CtlSendData(pdev, hcan->ep0_buf, req->wLength); | ||
break; | ||
|
||
This comment has been minimized.
Sorry, something went wrong.
Daniel-Trevitz
Author
Contributor
|
||
case GS_USB_BREQ_DEVICE_CONFIG: | ||
memcpy(hcan->ep0_buf, &USBD_GS_CAN_dconf, sizeof(USBD_GS_CAN_dconf)); | ||
USBD_CtlSendData(pdev, hcan->ep0_buf, req->wLength); | ||
|
@@ -738,7 +755,7 @@ void USBD_GS_CAN_SuspendCallback(USBD_HandleTypeDef *pdev) | |
|
||
if(hcan != NULL && hcan->leds != NULL) | ||
led_set_mode(hcan->leds, led_mode_off); | ||
|
||
is_usb_suspend_cb = true; | ||
} | ||
|
||
|
the indention of
GPIO_PIN_3
looks strange