diff options
Diffstat (limited to 'stm/usb.c')
| -rw-r--r-- | stm/usb.c | 24 |
1 files changed, 23 insertions, 1 deletions
@@ -8,9 +8,14 @@ #include "usbd_desc.h" #include "misc.h" +#include "mpconfig.h" +#include "qstr.h" +#include "obj.h" #include "usb.h" +#ifdef USE_DEVICE_MODE extern CDC_IF_Prop_TypeDef VCP_fops; +#endif USB_OTG_CORE_HANDLE USB_OTG_dev; @@ -22,8 +27,10 @@ static int rx_buf_out; void usb_init(void) { if (!is_enabled) { // only init USB once in the device's power-lifetime +#ifdef USE_DEVICE_MODE USBD_Init(&USB_OTG_dev, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_PYB_cb, &USR_cb); //USBD_Init(&USB_OTG_dev, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_PYB_HID_cb, &USR_cb); +#endif } rx_buf_in = 0; rx_buf_out = 0; @@ -76,7 +83,9 @@ void usb_vcp_send_str(const char *str) { void usb_vcp_send_strn(const char *str, int len) { if (is_enabled) { +#ifdef USE_DEVICE_MODE VCP_fops.pIf_DataTx((const uint8_t*)str, len); +#endif } } @@ -84,14 +93,17 @@ void usb_vcp_send_strn(const char *str, int len) { /* These are external variables imported from CDC core to be used for IN transfer management. */ +#ifdef USE_DEVICE_MODE extern uint8_t APP_Rx_Buffer []; /* Write CDC received data in this buffer. These data will be sent over USB IN endpoint in the CDC core functions. */ extern uint32_t APP_Rx_ptr_in; /* Increment this pointer or roll it back to start address when writing received data in the buffer APP_Rx_Buffer. */ +#endif void usb_vcp_send_strn_cooked(const char *str, int len) { +#ifdef USE_DEVICE_MODE for (const char *top = str + len; str < top; str++) { if (*str == '\n') { APP_Rx_Buffer[APP_Rx_ptr_in] = '\r'; @@ -100,10 +112,13 @@ void usb_vcp_send_strn_cooked(const char *str, int len) { APP_Rx_Buffer[APP_Rx_ptr_in] = *str; APP_Rx_ptr_in = (APP_Rx_ptr_in + 1) & (APP_RX_DATA_SIZE - 1); } +#endif } void usb_hid_send_report(uint8_t *buf) { +#ifdef USE_DEVICE_MODE USBD_HID_SendReport(&USB_OTG_dev, buf, 4); +#endif } /******************************************************************************/ @@ -114,6 +129,7 @@ void usb_hid_send_report(uint8_t *buf) { #include "lib-otg/usbh_core.h" #include "lib-otg/usbh_usr.h" #include "lib-otg/usbh_hid_core.h" +#include "lib-otg/usb_hcd_int.h" __ALIGN_BEGIN USBH_HOST USB_Host __ALIGN_END ; @@ -127,8 +143,14 @@ void pyb_usbh_init(void) { host_is_enabled = 1; } -void pyb_usbh_process(void) { +mp_obj_t pyb_usbh_process(void) { USBH_Process(&USB_OTG_dev, &USB_Host); + return mp_const_none; +} + +mp_obj_t pyb_usbh_connect(void) { + USBH_HCD_INT_fops->DevConnected(&USB_OTG_dev); + return mp_const_none; } #endif // USE_HOST_MODE |
