40
40
//| """Tuple of all active HID device interfaces.
41
41
//| The default set of devices is ``Device.KEYBOARD, Device.MOUSE, Device.CONSUMER_CONTROL``,
42
42
//| On boards where `usb_hid` is disabled by default, `devices` is an empty tuple.
43
+ //|
44
+ //| If a boot device is enabled by `usb_hid.enable)`, *and* the host has requested a boot device,
45
+ //| the `devices` tuple is *replaced* when ``code.py`` starts with a single-element tuple
46
+ //| containing a `Device` that describes the boot device chosen (keyboard or mouse).
47
+ //| The request for a boot device overrides any other HID devices.
43
48
//| """
44
49
//|
45
50
@@ -84,12 +89,12 @@ MP_DEFINE_CONST_FUN_OBJ_0(usb_hid_disable_obj, usb_hid_disable);
84
89
//| Boot devices implement a fixed, predefined report descriptor, defined in
85
90
//| https://www.usb.org/sites/default/files/hid1_12.pdf, Appendix B. A USB host
86
91
//| can request to use the boot device if the USB device says it is available.
87
- //| Usually only a BIOS or other kind of boot-time, limited-functionality
92
+ //| Usually only a BIOS or other kind of limited-functionality
88
93
//| host needs boot keyboard support.
89
94
//|
90
95
//| For example, to make a boot keyboard available, you can use this code::
91
96
//|
92
- //| usb_hid.enable((Device.KEYBOARD), boot_device=1)
97
+ //| usb_hid.enable((Device.KEYBOARD), boot_device=1) # 1 for a keyboard
93
98
//|
94
99
//| If the host requests the boot keyboard, the report descriptor provided by `Device.KEYBOARD`
95
100
//| will be ignored, and the predefined report descriptor will be used.
@@ -104,11 +109,11 @@ STATIC mp_obj_t usb_hid_enable(size_t n_args, const mp_obj_t *pos_args, mp_map_t
104
109
enum { ARG_devices , ARG_boot_device };
105
110
static const mp_arg_t allowed_args [] = {
106
111
{ MP_QSTR_devices , MP_ARG_REQUIRED | MP_ARG_OBJ },
107
- { MP_QSTR_boot_device , MP_ARG_OBJ , {.u_int = 0 } },
112
+ { MP_QSTR_boot_device , MP_ARG_INT , {.u_int = 0 } },
108
113
};
109
114
110
115
mp_arg_val_t args [MP_ARRAY_SIZE (allowed_args )];
111
- mp_arg_parse_all (n_args - 1 , pos_args + 1 , kw_args , MP_ARRAY_SIZE (allowed_args ), allowed_args , args );
116
+ mp_arg_parse_all (n_args , pos_args , kw_args , MP_ARRAY_SIZE (allowed_args ), allowed_args , args );
112
117
113
118
mp_obj_t devices = args [ARG_devices ].u_obj ;
114
119
const mp_int_t len = mp_obj_get_int (mp_obj_len (devices ));
@@ -128,18 +133,16 @@ STATIC mp_obj_t usb_hid_enable(size_t n_args, const mp_obj_t *pos_args, mp_map_t
128
133
129
134
return mp_const_none ;
130
135
}
131
- MP_DEFINE_CONST_FUN_OBJ_KW (usb_hid_enable_obj , 2 , usb_hid_enable );
136
+ MP_DEFINE_CONST_FUN_OBJ_KW (usb_hid_enable_obj , 1 , usb_hid_enable );
132
137
133
138
//| def get_boot_device() -> int:
134
139
//| """
135
140
//| :return: the boot device requested by the host, if any.
136
141
//| Returns 0 if the host did not request a boot device, or if `usb_hid.enable()`
137
142
//| was called with `boot_device=0`, the default, which disables boot device support.
138
- //| If the host did request aboot device,
143
+ //| If the host did request a boot device,
139
144
//| returns the value of ``boot_device`` set in `usb_hid.enable()`:
140
145
//| ``1`` for a boot keyboard, or ``2`` for boot mouse.
141
- //| Your device driver should check and act on this value if the keyboard or mouse
142
- //| device you specified provides reports that differ from the standard boot keyboard or mouse.
143
146
//| However, the standard devices provided by CircuitPython, `Device.KEYBOARD` and `Device.MOUSE`,
144
147
//| describe reports that match the boot device reports, so you don't need to check this
145
148
//| if you are using those devices.
0 commit comments