mirror of
https://github.com/ByteWelder/Tactility.git
synced 2026-10-17 19:05:07 +00:00
- Create `USB_HOST_TYPE` base driver in TactilityKernel - Refactor esp32_usbhost dts format, and create child devices dynamically - Use PSRAM for task stacks where possible: saving 20 kB from just the task stacks, but roughly 30 kB when nothing is connected. - Allow the user to disable USB host interface in the USB settings app, saving an additionaly 20 kB of IRAM when nothing was connected. - Change listener-based APIs to subscribe and poll/await pattern. This avoids callstacks of apps and services leaking into the USB API This results in big IRAM savings: 30 kB when USB host is on and nothing is connected, and 50 kB total when USB host is disabled. This brings the total free IRAM after boot from roughly 170 kB to 200 kB (host enabled) or 220 kB (host disabled).
67 lines
2.4 KiB
C
67 lines
2.4 KiB
C
// SPDX-License-Identifier: Apache-2.0
|
|
#pragma once
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <tactility/error.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
struct Device;
|
|
struct DeviceType;
|
|
|
|
enum UsbClass {
|
|
USB_HOST_CLASS_HID,
|
|
USB_HOST_CLASS_MIDI,
|
|
USB_HOST_CLASS_MSC,
|
|
USB_HOST_CLASS_AUDIO,
|
|
};
|
|
|
|
struct UsbHostApi {
|
|
/**
|
|
* Works while the host is stopped.
|
|
* @param[in] device the USB host device
|
|
* @param[in] usb_class the class to check
|
|
* @param[out] supported non-null, set to true when the hardware and the device configuration support the class
|
|
* @retval ERROR_NONE on success
|
|
* @retval ERROR_INVALID_ARGUMENT @a usb_class is out of range
|
|
*/
|
|
error_t (*is_class_supported)(struct Device* device, enum UsbClass usb_class, bool* supported);
|
|
/**
|
|
* @param[in] device the USB host device
|
|
* @param[in] usb_class the class to check
|
|
* @param[out] enabled non-null, set to true when the class is enabled and its driver is running
|
|
* @retval ERROR_NONE on success
|
|
* @retval ERROR_INVALID_ARGUMENT @a usb_class is out of range
|
|
* @retval ERROR_INVALID_STATE the host is not started
|
|
*/
|
|
error_t (*is_class_enabled)(struct Device* device, enum UsbClass usb_class, bool* enabled);
|
|
/**
|
|
* Starts or stops the detection of a class. Stopping removes the devices connected for that class.
|
|
* Restarting the host enables all supported classes again.
|
|
* @param[in] device the USB host device
|
|
* @param[in] usb_class the class to change
|
|
* @param[in] enabled true to start detecting the class
|
|
* @retval ERROR_NONE on success, also when the class already was in the requested state
|
|
* @retval ERROR_INVALID_ARGUMENT @a usb_class is out of range
|
|
* @retval ERROR_NOT_SUPPORTED the class is not supported
|
|
* @retval ERROR_INVALID_STATE the host is not started
|
|
* @return any other error when the class failed to start or stop
|
|
*/
|
|
error_t (*set_class_enabled)(struct Device* device, enum UsbClass usb_class, bool enabled);
|
|
};
|
|
|
|
extern const struct DeviceType USB_HOST_TYPE;
|
|
|
|
error_t usb_host_is_class_supported(struct Device* host, enum UsbClass usb_class, bool* supported);
|
|
|
|
error_t usb_host_is_class_enabled(struct Device* host, enum UsbClass usb_class, bool* enabled);
|
|
|
|
error_t usb_host_set_class_enabled(struct Device* host, enum UsbClass usb_class, bool enabled);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|