2017-05-02 18:25:06 -04:00
|
|
|
/*
|
2017-08-27 15:02:50 -04:00
|
|
|
* This file is part of the MicroPython project, http://micropython.org/
|
2017-05-02 18:25:06 -04:00
|
|
|
*
|
|
|
|
* The MIT License (MIT)
|
|
|
|
*
|
2018-10-19 21:46:22 -04:00
|
|
|
* Copyright (c) 2018 hathach for Adafruit Industries
|
2017-05-02 18:25:06 -04:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2019-07-24 05:46:31 -04:00
|
|
|
#include "lib/tinyusb/src/tusb.h"
|
2021-04-19 23:24:18 -04:00
|
|
|
|
|
|
|
#if CIRCUITPY_USB_CDC
|
|
|
|
#include "shared-module/storage/__init__.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if CIRCUITPY_USB_HID
|
|
|
|
#include "shared-module/usb_hid/__init__.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if CIRCUITPY_USB_MIDI
|
|
|
|
#include "shared-module/usb_midi/__init__.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if CIRCUITPY_USB_MSC
|
|
|
|
#include "shared-module/storage/__init__.h"
|
|
|
|
#endif
|
|
|
|
|
2018-10-19 21:46:22 -04:00
|
|
|
#include "shared-module/usb_hid/Device.h"
|
2017-05-12 21:26:14 -04:00
|
|
|
|
2018-10-19 21:46:22 -04:00
|
|
|
#include "genhdr/autogen_usb_descriptor.h"
|
2017-05-02 18:25:06 -04:00
|
|
|
|
2021-04-19 23:24:18 -04:00
|
|
|
static uint8_t *config_desc;
|
|
|
|
|
2019-07-24 05:46:31 -04:00
|
|
|
// Invoked when received GET DEVICE DESCRIPTOR
|
|
|
|
// Application return pointer to descriptor
|
2021-03-15 09:57:36 -04:00
|
|
|
uint8_t const *tud_descriptor_device_cb(void) {
|
2019-07-24 05:46:31 -04:00
|
|
|
return usb_desc_dev;
|
|
|
|
}
|
2017-05-12 21:26:14 -04:00
|
|
|
|
2019-07-24 05:46:31 -04:00
|
|
|
// Invoked when received GET CONFIGURATION DESCRIPTOR
|
|
|
|
// Application return pointer to descriptor
|
|
|
|
// Descriptor contents must exist long enough for transfer to complete
|
2021-03-15 09:57:36 -04:00
|
|
|
uint8_t const *tud_descriptor_configuration_cb(uint8_t index) {
|
|
|
|
(void)index; // for multiple configurations
|
2021-04-19 23:24:18 -04:00
|
|
|
|
|
|
|
size_t total_descriptor_length = 0;
|
|
|
|
|
|
|
|
// CDC should be first, for compatibility with Adafruit Windows 7 drivers.
|
|
|
|
// In the past, the order has been CDC, MSC, MIDI, HID, so preserve
|
|
|
|
// that order.
|
|
|
|
#if CIRCUITPY_USB_CDC
|
|
|
|
if (usb_cdc_repl_enabled) {
|
|
|
|
total_descriptor_length += usb_cdc_desc_length();
|
|
|
|
}
|
|
|
|
if (usb_cdc_data_enabled) {
|
|
|
|
total_descriptor_length += usb_cdc_desc_length();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if CIRCUITPY_USB_MSC
|
|
|
|
if (storage_usb_enabled) {
|
|
|
|
total_descriptor_length += storage_usb_desc_length();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if CIRCUITPY_USB_MIDI
|
|
|
|
if (usb_midi_enabled) {
|
|
|
|
total_descriptor_length += usb_midi_desc_length();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if CIRCUITPY_USB_HID
|
|
|
|
if (usb_hid_enabled) {
|
|
|
|
total_descriptor_length += usb_hid_desc_length();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Now we now how big the configuration descriptor will be.
|
|
|
|
config_desc = m_malloc(total_descriptor_length, false);
|
|
|
|
|
|
|
|
// Number interfaces and endpoints.
|
|
|
|
// Endpoint 0 is already used for USB control
|
|
|
|
uint8_t current_interface = 0;
|
|
|
|
uint8_t current_endpoint = 1;
|
|
|
|
uint16_t current_interface_string = 1;
|
|
|
|
|
|
|
|
uint8_t *desc_buf_remaining = config_desc;
|
|
|
|
|
|
|
|
#if CIRCUITPY_USB_CDC
|
|
|
|
if (usb_cdc_repl_enabled) {
|
|
|
|
// Concatenate and fix up the CDC REPL descriptor.
|
|
|
|
}
|
|
|
|
if (usb_cdc_data_enabled) {
|
|
|
|
// Concatenate and fix up the CDC data descriptor.
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if CIRCUITPY_USB_MSC
|
|
|
|
if (storage_usb_enabled) {
|
|
|
|
// Concatenate and fix up the MSC descriptor.
|
|
|
|
desc_buf_remaining += storage_usb_add_desc(
|
|
|
|
desc_buf_remaining, current_interface,
|
|
|
|
current_endpoint, // in
|
|
|
|
current_endpoint, // out
|
|
|
|
current_interface_string_index);
|
|
|
|
current_interface++;
|
|
|
|
current_endpoint++;
|
|
|
|
current_interface_string++;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if CIRCUITPY_USB_MIDI
|
|
|
|
if (usb_midi_enabled) {
|
|
|
|
// Concatenate and fix up the MIDI descriptor.
|
|
|
|
desc_buf_remaining += usb_midi_add_desc(
|
|
|
|
desc_buf_remaining,
|
|
|
|
current_interface, // audio control
|
|
|
|
current_interface + 1, // MIDI streaming
|
|
|
|
current_endpoint, // in
|
|
|
|
current_endpoint, // out
|
|
|
|
current_interface_string, // audio control
|
|
|
|
current_interface_string + 1 // MIDI streaming
|
|
|
|
);
|
|
|
|
current_interface += 2;
|
|
|
|
current_endpoint++;
|
|
|
|
current_interface_string += 2;
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if CIRCUITPY_USB_HID
|
|
|
|
if (usb_hid_enabled) {
|
|
|
|
// Concatenate and fix up the HID descriptor (not the report descriptors).
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
return config_desc;
|
2019-07-24 05:46:31 -04:00
|
|
|
}
|
|
|
|
|
2021-02-11 18:50:02 -05:00
|
|
|
#if CIRCUITPY_USB_HID
|
2019-07-24 05:46:31 -04:00
|
|
|
// Invoked when received GET HID REPORT DESCRIPTOR
|
|
|
|
// Application return pointer to descriptor
|
|
|
|
// Descriptor contents must exist long enough for transfer to complete
|
2021-03-15 09:57:36 -04:00
|
|
|
uint8_t const *tud_hid_descriptor_report_cb(uint8_t itf) {
|
|
|
|
(void)itf;
|
2021-02-24 13:09:17 -05:00
|
|
|
return hid_report_descriptor;
|
2019-07-24 05:46:31 -04:00
|
|
|
}
|
2021-02-11 18:50:02 -05:00
|
|
|
#endif
|
2019-07-24 05:46:31 -04:00
|
|
|
|
|
|
|
// Invoked when received GET STRING DESCRIPTOR request
|
|
|
|
// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete
|
2021-03-15 09:57:36 -04:00
|
|
|
uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
|
|
|
|
uint8_t const max_index = sizeof(string_desc_arr) / sizeof(string_desc_arr[0]);
|
2019-07-24 05:46:31 -04:00
|
|
|
return (index < max_index) ? string_desc_arr[index] : NULL;
|
|
|
|
}
|