usb.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * This file is part of the MicroPython project, http://micropython.org/
  3. *
  4. * The MIT License (MIT)
  5. *
  6. * Copyright (c) 2013, 2014, 2015 Damien P. George
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to deal
  10. * in the Software without restriction, including without limitation the rights
  11. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. * copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in
  16. * all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. * THE SOFTWARE.
  25. */
  26. #ifndef MICROPY_INCLUDED_STM32_USB_H
  27. #define MICROPY_INCLUDED_STM32_USB_H
  28. #include "usbd_cdc_msc_hid0.h"
  29. #define PYB_USB_FLAG_USB_MODE_CALLED (0x0002)
  30. // Windows needs a different PID to distinguish different device configurations
  31. #define USBD_VID (0xf055)
  32. #define USBD_PID_CDC_MSC (0x9800)
  33. #define USBD_PID_CDC_HID (0x9801)
  34. #define USBD_PID_CDC (0x9802)
  35. #define USBD_PID_MSC (0x9803)
  36. #define USBD_PID_CDC2_MSC (0x9804)
  37. typedef enum {
  38. PYB_USB_STORAGE_MEDIUM_NONE = 0,
  39. PYB_USB_STORAGE_MEDIUM_FLASH,
  40. PYB_USB_STORAGE_MEDIUM_SDCARD,
  41. } pyb_usb_storage_medium_t;
  42. typedef enum {
  43. USB_PHY_FS_ID = 0,
  44. USB_PHY_HS_ID = 1,
  45. } USB_PHY_ID;
  46. extern mp_uint_t pyb_usb_flags;
  47. extern pyb_usb_storage_medium_t pyb_usb_storage_medium;
  48. extern const struct _mp_rom_obj_tuple_t pyb_usb_hid_mouse_obj;
  49. extern const struct _mp_rom_obj_tuple_t pyb_usb_hid_keyboard_obj;
  50. extern const mp_obj_type_t pyb_usb_vcp_type;
  51. extern const mp_obj_type_t pyb_usb_hid_type;
  52. MP_DECLARE_CONST_FUN_OBJ_KW(pyb_usb_mode_obj);
  53. MP_DECLARE_CONST_FUN_OBJ_0(pyb_have_cdc_obj); // deprecated
  54. MP_DECLARE_CONST_FUN_OBJ_1(pyb_hid_send_report_obj); // deprecated
  55. void pyb_usb_init0(void);
  56. bool pyb_usb_dev_init(uint16_t vid, uint16_t pid, usb_device_mode_t mode, USBD_HID_ModeInfoTypeDef *hid_info);
  57. void pyb_usb_dev_deinit(void);
  58. bool usb_vcp_is_enabled(void);
  59. int usb_vcp_recv_byte(uint8_t *c); // if a byte is available, return 1 and put the byte in *c, else return 0
  60. void usb_vcp_send_strn(const char* str, int len);
  61. void pyb_usb_host_init(void);
  62. void pyb_usb_host_process(void);
  63. uint pyb_usb_host_get_keyboard(void);
  64. #endif // MICROPY_INCLUDED_STM32_USB_H