Browse Source

stmhal: Add USB_VCP.setinterrupt method, to disable CTRL-C.

pull/995/head
Damien George 10 years ago
parent
commit
19fb1b4dd7
  1. 9
      docs/library/pyb.USB_VCP.rst
  2. 1
      docs/tutorial/pass_through.rst
  3. 1
      stmhal/qstrdefsport.h
  4. 7
      stmhal/usb.c
  5. 2
      stmhal/usbd_cdc_interface.c

9
docs/library/pyb.USB_VCP.rst

@ -17,6 +17,15 @@ Constructors
Methods Methods
------- -------
.. method:: usb_vcp.setinterrupt(chr)
Set the character which interrupts running Python code. This is set
to 3 (CTRL-C) by default, and when a CTRL-C character is received over
the USB VCP port, a KeyboardInterrupt exception is raised.
Set to -1 to disable this interrupt feature. This is useful when you
want to send raw bytes over the USB VCP port.
.. method:: usb_vcp.any() .. method:: usb_vcp.any()
Return ``True`` if any characters waiting, else ``False``. Return ``True`` if any characters waiting, else ``False``.

1
docs/tutorial/pass_through.rst

@ -7,6 +7,7 @@ It's as simple as::
import select import select
def pass_through(usb, uart): def pass_through(usb, uart):
usb.setinterrupt(-1)
while True: while True:
select.select([usb, uart], [], []) select.select([usb, uart], [], [])
if usb.any(): if usb.any():

1
stmhal/qstrdefsport.h

@ -85,6 +85,7 @@ Q(tell)
// for USB VCP class // for USB VCP class
Q(USB_VCP) Q(USB_VCP)
Q(setinterrupt)
Q(send) Q(send)
Q(recv) Q(recv)
Q(timeout) Q(timeout)

7
stmhal/usb.c

@ -174,6 +174,12 @@ STATIC mp_obj_t pyb_usb_vcp_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint
return (mp_obj_t)&pyb_usb_vcp_obj; return (mp_obj_t)&pyb_usb_vcp_obj;
} }
STATIC mp_obj_t pyb_usb_vcp_setinterrupt(mp_obj_t self_in, mp_obj_t int_chr_in) {
usb_vcp_set_interrupt_char(mp_obj_get_int(int_chr_in));
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_usb_vcp_setinterrupt_obj, pyb_usb_vcp_setinterrupt);
/// \method any() /// \method any()
/// Return `True` if any characters waiting, else `False`. /// Return `True` if any characters waiting, else `False`.
STATIC mp_obj_t pyb_usb_vcp_any(mp_obj_t self_in) { STATIC mp_obj_t pyb_usb_vcp_any(mp_obj_t self_in) {
@ -252,6 +258,7 @@ mp_obj_t pyb_usb_vcp___exit__(mp_uint_t n_args, const mp_obj_t *args) {
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_usb_vcp___exit___obj, 4, 4, pyb_usb_vcp___exit__); STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_usb_vcp___exit___obj, 4, 4, pyb_usb_vcp___exit__);
STATIC const mp_map_elem_t pyb_usb_vcp_locals_dict_table[] = { STATIC const mp_map_elem_t pyb_usb_vcp_locals_dict_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_setinterrupt), (mp_obj_t)&pyb_usb_vcp_setinterrupt_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_any), (mp_obj_t)&pyb_usb_vcp_any_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_any), (mp_obj_t)&pyb_usb_vcp_any_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_send), (mp_obj_t)&pyb_usb_vcp_send_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_send), (mp_obj_t)&pyb_usb_vcp_send_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_recv), (mp_obj_t)&pyb_usb_vcp_recv_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_recv), (mp_obj_t)&pyb_usb_vcp_recv_obj },

2
stmhal/usbd_cdc_interface.c

@ -482,7 +482,7 @@ int USBD_CDC_Rx(uint8_t *buf, uint32_t len, uint32_t timeout) {
for (uint32_t i = 0; i < len; i++) { for (uint32_t i = 0; i < len; i++) {
// Wait until we have at least 1 byte to read // Wait until we have at least 1 byte to read
uint32_t start = HAL_GetTick(); uint32_t start = HAL_GetTick();
while (!dev_is_connected || UserRxBufLen == UserRxBufCur) { while (UserRxBufLen == UserRxBufCur) {
// Wraparound of tick is taken care of by 2's complement arithmetic. // Wraparound of tick is taken care of by 2's complement arithmetic.
if (HAL_GetTick() - start >= timeout) { if (HAL_GetTick() - start >= timeout) {
// timeout // timeout

Loading…
Cancel
Save