Skip to content

Commit 979ab4e

Browse files
committed
stmhal/usb: Always use the mp_kbd_exception object for VCP interrupt.
There's no need to store a separate pointer to this object.
1 parent f254cfd commit 979ab4e

3 files changed

Lines changed: 6 additions & 8 deletions

File tree

stmhal/usb.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ const mp_obj_tuple_t pyb_usb_hid_keyboard_obj = {
9696
};
9797

9898
void pyb_usb_init0(void) {
99-
USBD_CDC_SetInterrupt(-1, MP_STATE_PORT(mp_kbd_exception));
99+
USBD_CDC_SetInterrupt(-1);
100100
MP_STATE_PORT(pyb_hid_report_desc) = MP_OBJ_NULL;
101101
}
102102

@@ -146,7 +146,7 @@ void usb_vcp_set_interrupt_char(int c) {
146146
if (c != -1) {
147147
mp_obj_exception_clear_traceback(MP_STATE_PORT(mp_kbd_exception));
148148
}
149-
USBD_CDC_SetInterrupt(c, MP_STATE_PORT(mp_kbd_exception));
149+
USBD_CDC_SetInterrupt(c);
150150
}
151151
}
152152

stmhal/usbd_cdc_interface.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include "usbd_cdc_interface.h"
4242
#include "pendsv.h"
4343

44+
#include "py/mpstate.h"
4445
#include "py/obj.h"
4546
#include "irq.h"
4647
#include "timer.h"
@@ -79,7 +80,6 @@ static uint8_t UserTxBufPtrWaitCount = 0; // used to implement a timeout waiting
7980
static uint8_t UserTxNeedEmptyPacket = 0; // used to flush the USB IN endpoint if the last packet was exactly the endpoint packet size
8081

8182
static int user_interrupt_char = -1;
82-
static void *user_interrupt_data = NULL;
8383

8484
/* Private function prototypes -----------------------------------------------*/
8585
static int8_t CDC_Itf_Init (void);
@@ -152,7 +152,6 @@ static int8_t CDC_Itf_Init(void)
152152
* This can happen if the USB enumeration occurs after the call to
153153
* USBD_CDC_SetInterrupt.
154154
user_interrupt_char = -1;
155-
user_interrupt_data = NULL;
156155
*/
157156

158157
return (USBD_OK);
@@ -354,7 +353,7 @@ static int8_t CDC_Itf_Receive(uint8_t* Buf, uint32_t *Len) {
354353
if (*src == user_interrupt_char) {
355354
char_found = true;
356355
// raise exception when interrupts are finished
357-
pendsv_nlr_jump(user_interrupt_data);
356+
pendsv_nlr_jump(MP_STATE_PORT(mp_kbd_exception));
358357
} else {
359358
if (char_found) {
360359
*dest = *src;
@@ -386,9 +385,8 @@ int USBD_CDC_IsConnected(void) {
386385
return dev_is_connected;
387386
}
388387

389-
void USBD_CDC_SetInterrupt(int chr, void *data) {
388+
void USBD_CDC_SetInterrupt(int chr) {
390389
user_interrupt_char = chr;
391-
user_interrupt_data = data;
392390
}
393391

394392
int USBD_CDC_TxHalfEmpty(void) {

stmhal/usbd_cdc_interface.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
extern const USBD_CDC_ItfTypeDef USBD_CDC_fops;
3333

3434
int USBD_CDC_IsConnected(void);
35-
void USBD_CDC_SetInterrupt(int chr, void *data);
35+
void USBD_CDC_SetInterrupt(int chr);
3636

3737
int USBD_CDC_TxHalfEmpty(void);
3838
int USBD_CDC_Tx(const uint8_t *buf, uint32_t len, uint32_t timeout);

0 commit comments

Comments
 (0)