8000 stmhal: Pass USB handler as parameter to allow more than one USB handler · DFRobot/micropython@6adcf7b · GitHub
[go: up one dir, main page]

Skip to content

Commit 6adcf7b

Browse files
sylvainpelissierdpgeorge
authored andcommitted
stmhal: Pass USB handler as parameter to allow more than one USB handler
1 parent 7ecfbb8 commit 6adcf7b

File tree

4 files changed

+24
-24
lines changed

4 files changed

+24
-24
lines changed

stmhal/usbd_cdc_interface.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ static uint8_t UserTxBufPtrWaitCount = 0; // used to implement a timeout waiting
8282
static uint8_t UserTxNeedEmptyPacket = 0; // used to flush the USB IN endpoint if the last packet was exactly the endpoint packet size
8383

8484
/* Private function prototypes -----------------------------------------------*/
85-
static int8_t CDC_Itf_Init (void);
85+
static int8_t CDC_Itf_Init (USBD_HandleTypeDef *pdev);
8686
static int8_t CDC_Itf_DeInit (void);
8787
static int8_t CDC_Itf_Control (uint8_t cmd, uint8_t* pbuf, uint16_t length);
88-
static int8_t CDC_Itf_Receive (uint8_t* pbuf, uint32_t *Len);
88+
static int8_t CDC_Itf_Receive (USBD_HandleTypeDef *pdev, uint8_t* pbuf, uint32_t *Len);
8989

9090
const USBD_CDC_ItfTypeDef USBD_CDC_fops = {
9191
CDC_Itf_Init,
@@ -102,7 +102,7 @@ const USBD_CDC_ItfTypeDef USBD_CDC_fops = {
102102
* @param None
103103
* @retval Result of the opeartion: USBD_OK if all operations are OK else USBD_FAIL
104104
*/
105-
static int8_t CDC_Itf_Init(void)
105+
static int8_t CDC_Itf_Init(USBD_HandleTypeDef *pdev)
106106
{
107107
#if 0
108108
/*##-1- Configure the UART peripheral ######################################*/
@@ -141,8 +141,8 @@ static int8_t CDC_Itf_Init(void)
141141
#endif
142142

143143
/*##-5- Set Application Buffers ############################################*/
144-
USBD_CDC_SetTxBuffer(&hUSBDDevice, UserTxBuffer, 0);
145-
USBD_CDC_SetRxBuffer(&hUSBDDevice, cdc_rx_packet_buf);
144+
USBD_CDC_SetTxBuffer(pdev, UserTxBuffer, 0);
145+
USBD_CDC_SetRxBuffer(pdev, cdc_rx_packet_buf);
146146

147147
cdc_rx_buf_put = 0;
148148
cdc_rx_buf_get = 0;
@@ -317,7 +317,7 @@ void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd) {
317317
* @note The buffer we are passed here is just cdc_rx_packet_buf, so we are
318318
* free to modify it.
319319
*/
320-
static int8_t CDC_Itf_Receive(uint8_t* Buf, uint32_t *Len) {
320+
static int8_t CDC_Itf_Receive(USBD_HandleTypeDef *pdev, uint8_t* Buf, uint32_t *Len) {
321321
#if 0
322322
// this sends the data over the UART using DMA
323323
HAL_UART_Transmit_DMA(&UartHandle, Buf, *Len);
@@ -339,8 +339,8 @@ static int8_t CDC_Itf_Receive(uint8_t* Buf, uint32_t *Len) {
339339
}
340340

341341
// initiate next USB packet transfer
342-
USBD_CDC_SetRxBuffer(&hUSBDDevice, cdc_rx_packet_buf);
343-
USBD_CDC_ReceivePacket(&hUSBDDevice);
342+
USBD_CDC_SetRxBuffer(pdev, cdc_rx_packet_buf);
343+
USBD_CDC_ReceivePacket(pdev);
344344

345345
return USBD_OK;
346346
}

stmhal/usbd_hid_interface.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ static uint32_t last_read_len = 0; // length of last read
5151
static int8_t current_write_buffer = 0; // which buffer to write to
5252

5353
/* Private function prototypes -----------------------------------------------*/
54-
static int8_t HID_Itf_Init (void);
55-
static int8_t HID_Itf_Receive (uint8_t* pbuf, uint32_t Len);
54+
static int8_t HID_Itf_Init (USBD_HandleTypeDef *pdev);
55+
static int8_t HID_Itf_Receive (USBD_HandleTypeDef *pdev, uint8_t* pbuf, uint32_t Len);
5656

5757
const USBD_HID_ItfTypeDef USBD_HID_fops = {
5858
HID_Itf_Init,
@@ -65,12 +65,12 @@ const USBD_HID_ItfTypeDef USBD_HID_fops = {
6565
* @param None
6666
* @retval Result of the opeartion: USBD_OK if all operations are OK else USBD_FAIL
6767
*/
68-
static int8_t HID_Itf_Init(void)
68+
static int8_t HID_Itf_Init(USBD_HandleTypeDef *pdev)
6969
{
7070
current_read_buffer = 0;
7171
last_read_len = 0;
7272
current_write_buffer = 0;
73-
USBD_HID_SetRxBuffer(&hUSBDDevice, buffer[current_write_buffer]);
73+
USBD_HID_SetRxBuffer(pdev, buffer[current_write_buffer]);
7474
return USBD_OK;
7575
}
7676

@@ -83,14 +83,14 @@ static int8_t HID_Itf_Init(void)
8383
* @note The buffer we are passed here is just UserRxBuffer, so we are
8484
* free to modify it.
8585
*/
86-
static int8_t HID_Itf_Receive(uint8_t* Buf, uint32_t Len) {
86+
static int8_t HID_Itf_Receive(USBD_HandleTypeDef *pdev, uint8_t* Buf, uint32_t Len) {
8787
current_write_buffer = !current_write_buffer;
8888
last_read_len = Len;
8989
// initiate next USB packet transfer, to append to existing data in buffer
90-
USBD_HID_SetRxBuffer(&hUSBDDevice, buffer[current_write_buffer]);
91-
USBD_HID_ReceivePacket(&hUSBDDevice);
90+
USBD_HID_SetRxBuffer(pdev, buffer[current_write_buffer]);
91+
USBD_HID_ReceivePacket(pdev);
9292
// Set NAK to indicate we need to process read buffer
93-
USBD_HID_SetNAK(&hUSBDDevice);
93+
USBD_HID_SetNAK(pdev);
9494
return USBD_OK;
9595
}
9696

stmhal/usbdev/class/inc/usbd_cdc_msc_hid.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ typedef struct {
2828
} USBD_CDC_LineCodingTypeDef;
2929

3030
typedef struct _USBD_CDC_Itf {
31-
int8_t (* Init) (void);
31+
int8_t (* Init) (USBD_HandleTypeDef *pdev);
3232
int8_t (* DeInit) (void);
3333
int8_t (* Control) (uint8_t, uint8_t * , uint16_t);
34-
int8_t (* Receive) (uint8_t *, uint32_t *);
34+
int8_t (* Receive) (USBD_HandleTypeDef *pdev, uint8_t *, uint32_t *);
3535
} USBD_CDC_ItfTypeDef;
3636

3737
typedef struct {
@@ -48,8 +48,8 @@ typedef struct {
4848
} USBD_CDC_HandleTypeDef;
4949

5050
typedef struct _USBD_HID_Itf {
51-
int8_t (* Init) (void);
52-
int8_t (* Receive)(uint8_t *, uint32_t);
51+
int8_t (* Init) (USBD_HandleTypeDef *pdev);
52+
int8_t (* Receive)(USBD_HandleTypeDef *pdev, uint8_t *, uint32_t);
5353
} USBD_HID_ItfTypeDef;
5454

5555
typedef struct _USBD_STORAGE {

stmhal/usbdev/class/src/usbd_cdc_msc_hid.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ static uint8_t USBD_CDC_MSC_HID_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx) {
669669
CDC_CMD_PACKET_SIZE);
670670

671671
// Init physical Interface components
672-
CDC_fops->Init();
672+
CDC_fops->Init(pdev);
673673

674674
// Init Xfer states
675675
CDC_ClassData.TxState =0;
@@ -724,7 +724,7 @@ static uint8_t USBD_CDC_MSC_HID_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx) {
724724
USBD_EP_TYPE_INTR,
725725
mps_out);
726726

727-
HID_fops->Init();
727+
HID_fops->Init(pdev);
728728

729729
// Prepare Out endpoint to receive next packet
730730
USBD_LL_PrepareReceive(pdev, hid_out_ep, HID_ClassData.RxBuffer, mps_out);
@@ -963,15 +963,15 @@ static uint8_t USBD_CDC_MSC_HID_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum)
963963

964964
/* USB data will be immediately processed, this allow next USB traffic being
965965
NAKed till the end of the application Xfer */
966-
CDC_fops->Receive(CDC_ClassData.RxBuffer, &CDC_ClassData.RxLength);
966+
CDC_fops->Receive(pdev, CDC_ClassData.RxBuffer, &CDC_ClassData.RxLength);
967967

968968
return USBD_OK;
969969
} else if ((usbd_mode & USBD_MODE_MSC) && epnum == (MSC_OUT_EP & 0x7f)) {
970970
MSC_BOT_DataOut(pdev, epnum);
971971
return USBD_OK;
972972
} else if ((usbd_mode & USBD_MODE_HID) && epnum == (hid_out_ep & 0x7f)) {
973973
HID_ClassData.RxLength = USBD_LL_GetRxDataSize(pdev, epnum);
974-
HID_fops->Receive(HID_ClassData.RxBuffer, HID_ClassData.RxLength);
974+
HID_fops->Receive(pdev, HID_ClassData.RxBuffer, HID_ClassData.RxLength);
975975
}
976976

977977
return USBD_OK;

0 commit comments

Comments
 (0)
0