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 
29 #include "usbd_cdc_msc_hid0.h"
30 
31 #define PYB_USB_FLAG_USB_MODE_CALLED    (0x0002)
32 
33 typedef enum {
34     PYB_USB_STORAGE_MEDIUM_NONE = 0,
35     PYB_USB_STORAGE_MEDIUM_FLASH,
36     PYB_USB_STORAGE_MEDIUM_SDCARD,
37 } pyb_usb_storage_medium_t;
38 
39 typedef enum {
40     USB_PHY_FS_ID = 0,
41     USB_PHY_HS_ID = 1,
42 } USB_PHY_ID;
43 
44 typedef struct _pyb_usb_vcp_obj_t pyb_usb_vcp_obj_t;
45 
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 
53 MP_DECLARE_CONST_FUN_OBJ_KW(pyb_usb_mode_obj);
54 MP_DECLARE_CONST_FUN_OBJ_0(pyb_have_cdc_obj); // deprecated
55 MP_DECLARE_CONST_FUN_OBJ_1(pyb_hid_send_report_obj); // deprecated
56 
57 void pyb_usb_init0(void);
58 int pyb_usb_dev_detect(void);
59 bool pyb_usb_dev_init(int dev_id, uint16_t vid, uint16_t pid, uint8_t mode, size_t msc_n, const void *msc_unit, USBD_HID_ModeInfoTypeDef *hid_info);
60 void pyb_usb_dev_deinit(void);
61 bool usb_vcp_is_enabled(void);
62 int usb_vcp_recv_byte(uint8_t *c); // if a byte is available, return 1 and put the byte in *c, else return 0
63 void usb_vcp_send_strn(const char *str, int len);
64 void usb_vcp_attach_to_repl(const pyb_usb_vcp_obj_t *self, bool attached);
65 
66 void pyb_usb_host_init(void);
67 void pyb_usb_host_process(void);
68 uint pyb_usb_host_get_keyboard(void);
69 
70 #endif // MICROPY_INCLUDED_STM32_USB_H
71