USB device-mode support (#613)
This commit is contained in:
@@ -10,10 +10,12 @@ extern "C" {
|
||||
error_t keyboard_read_key(Device* device, KeyboardKeyData* data) {
|
||||
const auto* driver = device_get_driver(device);
|
||||
|
||||
// Default the modifier fields here rather than in each driver: only drivers whose hardware can
|
||||
// report modifiers set them, and the rest would otherwise leave whatever the caller's stack held.
|
||||
// Default the modifier/HID fields here rather than in each driver: only drivers whose hardware
|
||||
// can report them set them, and the rest would otherwise leave whatever the caller's stack held.
|
||||
data->ctrl = false;
|
||||
data->alt = false;
|
||||
data->hid_keycode = 0;
|
||||
data->hid_modifier = 0;
|
||||
|
||||
return KEYBOARD_DRIVER_API(driver)->read_key(device, data);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
#include <tactility/drivers/usb_cdc_device.h>
|
||||
#include <tactility/device.h>
|
||||
#include <tactility/driver.h>
|
||||
|
||||
#define USB_CDC_DEVICE_API(device) ((const struct UsbCdcDeviceApi*)device_get_driver(device)->api)
|
||||
|
||||
extern "C" {
|
||||
|
||||
const struct DeviceType USB_CDC_DEVICE_TYPE = {
|
||||
.name = "usb-cdc-device",
|
||||
};
|
||||
|
||||
struct Device* usb_cdc_device_get() {
|
||||
struct Device* found = nullptr;
|
||||
device_get_first_active_by_type(&USB_CDC_DEVICE_TYPE, &found);
|
||||
return found;
|
||||
}
|
||||
|
||||
bool usb_cdc_device_is_present(struct Device* device) {
|
||||
return USB_CDC_DEVICE_API(device)->is_present(device);
|
||||
}
|
||||
|
||||
error_t usb_cdc_device_build_contribution(struct Device* device, struct Device* controller,
|
||||
uint8_t interface_string_index,
|
||||
struct UsbInterfaceContribution* out_contribution,
|
||||
const char** out_interface_string) {
|
||||
return USB_CDC_DEVICE_API(device)->build_contribution(device, controller, interface_string_index, out_contribution, out_interface_string);
|
||||
}
|
||||
|
||||
error_t usb_cdc_device_start_console(struct Device* device) {
|
||||
return USB_CDC_DEVICE_API(device)->start_console(device);
|
||||
}
|
||||
|
||||
error_t usb_cdc_device_stop_console(struct Device* device) {
|
||||
return USB_CDC_DEVICE_API(device)->stop_console(device);
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
@@ -0,0 +1,45 @@
|
||||
#include <tactility/drivers/usb_device_controller.h>
|
||||
#include <tactility/device.h>
|
||||
#include <tactility/driver.h>
|
||||
|
||||
#define USB_DEVICE_CONTROLLER_API(device) ((const struct UsbDeviceControllerApi*)device_get_driver(device)->api)
|
||||
|
||||
extern "C" {
|
||||
|
||||
const struct DeviceType USB_DEVICE_CONTROLLER_TYPE = {
|
||||
.name = "usb-device-controller",
|
||||
};
|
||||
|
||||
struct Device* usb_device_controller_get() {
|
||||
struct Device* found = nullptr;
|
||||
device_get_first_active_by_type(&USB_DEVICE_CONTROLLER_TYPE, &found);
|
||||
return found;
|
||||
}
|
||||
|
||||
error_t usb_device_controller_begin_claim(struct Device* device) {
|
||||
return USB_DEVICE_CONTROLLER_API(device)->begin_claim(device);
|
||||
}
|
||||
|
||||
error_t usb_device_controller_allocate_interfaces(struct Device* device, uint8_t interface_count,
|
||||
uint8_t in_endpoint_count, uint8_t out_endpoint_count,
|
||||
struct UsbInterfaceAllocation* out_allocation) {
|
||||
return USB_DEVICE_CONTROLLER_API(device)->allocate_interfaces(device, interface_count, in_endpoint_count, out_endpoint_count, out_allocation);
|
||||
}
|
||||
|
||||
error_t usb_device_controller_claim(struct Device* device, enum UsbDeviceClass usb_class, const struct UsbDeviceClaimConfig* config) {
|
||||
return USB_DEVICE_CONTROLLER_API(device)->claim(device, usb_class, config);
|
||||
}
|
||||
|
||||
error_t usb_device_controller_release(struct Device* device, enum UsbDeviceClass usb_class) {
|
||||
return USB_DEVICE_CONTROLLER_API(device)->release(device, usb_class);
|
||||
}
|
||||
|
||||
enum UsbDeviceClass usb_device_controller_get_active_class(struct Device* device) {
|
||||
return USB_DEVICE_CONTROLLER_API(device)->get_active_class(device);
|
||||
}
|
||||
|
||||
bool usb_device_controller_is_cdc_enabled(struct Device* device) {
|
||||
return USB_DEVICE_CONTROLLER_API(device)->is_cdc_enabled(device);
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
@@ -0,0 +1,51 @@
|
||||
#include <tactility/drivers/usb_hid_device.h>
|
||||
#include <tactility/device.h>
|
||||
#include <tactility/driver.h>
|
||||
|
||||
#define USB_HID_DEVICE_API(device) ((const struct UsbHidDeviceApi*)device_get_driver(device)->api)
|
||||
|
||||
extern "C" {
|
||||
|
||||
const struct DeviceType USB_HID_DEVICE_TYPE = {
|
||||
.name = "usb-hid-device",
|
||||
};
|
||||
|
||||
struct Device* usb_hid_device_get() {
|
||||
struct Device* found = nullptr;
|
||||
device_get_first_active_by_type(&USB_HID_DEVICE_TYPE, &found);
|
||||
return found;
|
||||
}
|
||||
|
||||
error_t usb_hid_device_start(struct Device* device, enum UsbHidDeviceMode mode) {
|
||||
return USB_HID_DEVICE_API(device)->start(device, mode);
|
||||
}
|
||||
|
||||
error_t usb_hid_device_stop(struct Device* device) {
|
||||
return USB_HID_DEVICE_API(device)->stop(device);
|
||||
}
|
||||
|
||||
error_t usb_hid_device_set_name(struct Device* device, const char* name) {
|
||||
return USB_HID_DEVICE_API(device)->set_name(device, name);
|
||||
}
|
||||
|
||||
error_t usb_hid_device_send_keyboard(struct Device* device, const uint8_t* report, size_t len) {
|
||||
return USB_HID_DEVICE_API(device)->send_keyboard(device, report, len);
|
||||
}
|
||||
|
||||
error_t usb_hid_device_send_consumer(struct Device* device, const uint8_t* report, size_t len) {
|
||||
return USB_HID_DEVICE_API(device)->send_consumer(device, report, len);
|
||||
}
|
||||
|
||||
error_t usb_hid_device_send_mouse(struct Device* device, const uint8_t* report, size_t len) {
|
||||
return USB_HID_DEVICE_API(device)->send_mouse(device, report, len);
|
||||
}
|
||||
|
||||
error_t usb_hid_device_send_gamepad(struct Device* device, const uint8_t* report, size_t len) {
|
||||
return USB_HID_DEVICE_API(device)->send_gamepad(device, report, len);
|
||||
}
|
||||
|
||||
bool usb_hid_device_is_connected(struct Device* device) {
|
||||
return USB_HID_DEVICE_API(device)->is_connected(device);
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
@@ -0,0 +1,39 @@
|
||||
#include <tactility/drivers/usb_midi_device.h>
|
||||
#include <tactility/device.h>
|
||||
#include <tactility/driver.h>
|
||||
|
||||
#define USB_MIDI_DEVICE_API(device) ((const struct UsbMidiDeviceApi*)device_get_driver(device)->api)
|
||||
|
||||
extern "C" {
|
||||
|
||||
const struct DeviceType USB_MIDI_DEVICE_TYPE = {
|
||||
.name = "usb-midi-device",
|
||||
};
|
||||
|
||||
struct Device* usb_midi_device_get() {
|
||||
struct Device* found = nullptr;
|
||||
device_get_first_active_by_type(&USB_MIDI_DEVICE_TYPE, &found);
|
||||
return found;
|
||||
}
|
||||
|
||||
error_t usb_midi_device_start(struct Device* device) {
|
||||
return USB_MIDI_DEVICE_API(device)->start(device);
|
||||
}
|
||||
|
||||
error_t usb_midi_device_stop(struct Device* device) {
|
||||
return USB_MIDI_DEVICE_API(device)->stop(device);
|
||||
}
|
||||
|
||||
error_t usb_midi_device_set_name(struct Device* device, const char* name) {
|
||||
return USB_MIDI_DEVICE_API(device)->set_name(device, name);
|
||||
}
|
||||
|
||||
error_t usb_midi_device_send(struct Device* device, const uint8_t* msg, size_t len) {
|
||||
return USB_MIDI_DEVICE_API(device)->send(device, msg, len);
|
||||
}
|
||||
|
||||
bool usb_midi_device_is_connected(struct Device* device) {
|
||||
return USB_MIDI_DEVICE_API(device)->is_connected(device);
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
@@ -0,0 +1,32 @@
|
||||
#include <tactility/drivers/usb_msc_device.h>
|
||||
#include <tactility/device.h>
|
||||
#include <tactility/driver.h>
|
||||
|
||||
#define USB_MSC_DEVICE_API(device) ((const struct UsbMscDeviceApi*)device_get_driver(device)->api)
|
||||
|
||||
extern "C" {
|
||||
|
||||
const struct DeviceType USB_MSC_DEVICE_TYPE = {
|
||||
.name = "usb-msc-device",
|
||||
};
|
||||
|
||||
struct Device* usb_msc_device_get() {
|
||||
struct Device* found = nullptr;
|
||||
device_get_first_active_by_type(&USB_MSC_DEVICE_TYPE, &found);
|
||||
return found;
|
||||
}
|
||||
|
||||
error_t usb_msc_device_start(struct Device* device, enum UsbMscDeviceSource source, void* source_handle,
|
||||
UsbMscDeviceMountChangedCallback mount_changed_cb, void* context) {
|
||||
return USB_MSC_DEVICE_API(device)->start(device, source, source_handle, mount_changed_cb, context);
|
||||
}
|
||||
|
||||
error_t usb_msc_device_stop(struct Device* device) {
|
||||
return USB_MSC_DEVICE_API(device)->stop(device);
|
||||
}
|
||||
|
||||
bool usb_msc_device_is_connected(struct Device* device) {
|
||||
return USB_MSC_DEVICE_API(device)->is_connected(device);
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
@@ -33,9 +33,13 @@
|
||||
#include <tactility/drivers/spi_controller.h>
|
||||
#include <tactility/drivers/trackball.h>
|
||||
#include <tactility/drivers/uart_controller.h>
|
||||
#include <tactility/drivers/usb_device_controller.h>
|
||||
#include <tactility/drivers/usb_hid_device.h>
|
||||
#include <tactility/drivers/usb_host_hid.h>
|
||||
#include <tactility/drivers/usb_host_midi.h>
|
||||
#include <tactility/drivers/usb_host_msc.h>
|
||||
#include <tactility/drivers/usb_midi_device.h>
|
||||
#include <tactility/drivers/usb_msc_device.h>
|
||||
#include <tactility/drivers/wifi.h>
|
||||
#include <tactility/error.h>
|
||||
#include <tactility/filesystem/file_mutex.h>
|
||||
@@ -422,6 +426,40 @@ const struct ModuleSymbol KERNEL_SYMBOLS[] = {
|
||||
// drivers/usb_host_msc
|
||||
DEFINE_MODULE_SYMBOL(usb_msc_eject),
|
||||
DEFINE_MODULE_SYMBOL(USB_HOST_MSC_TYPE),
|
||||
// drivers/usb_device_controller
|
||||
DEFINE_MODULE_SYMBOL(usb_device_controller_get),
|
||||
DEFINE_MODULE_SYMBOL(usb_device_controller_begin_claim),
|
||||
DEFINE_MODULE_SYMBOL(usb_device_controller_allocate_interfaces),
|
||||
DEFINE_MODULE_SYMBOL(usb_device_controller_claim),
|
||||
DEFINE_MODULE_SYMBOL(usb_device_controller_release),
|
||||
DEFINE_MODULE_SYMBOL(usb_device_controller_get_active_class),
|
||||
DEFINE_MODULE_SYMBOL(usb_device_controller_is_cdc_enabled),
|
||||
DEFINE_MODULE_SYMBOL(USB_DEVICE_CONTROLLER_TYPE),
|
||||
// drivers/usb_hid_device
|
||||
DEFINE_MODULE_SYMBOL(usb_hid_device_get),
|
||||
DEFINE_MODULE_SYMBOL(usb_hid_device_start),
|
||||
DEFINE_MODULE_SYMBOL(usb_hid_device_stop),
|
||||
DEFINE_MODULE_SYMBOL(usb_hid_device_set_name),
|
||||
DEFINE_MODULE_SYMBOL(usb_hid_device_send_keyboard),
|
||||
DEFINE_MODULE_SYMBOL(usb_hid_device_send_consumer),
|
||||
DEFINE_MODULE_SYMBOL(usb_hid_device_send_mouse),
|
||||
DEFINE_MODULE_SYMBOL(usb_hid_device_send_gamepad),
|
||||
DEFINE_MODULE_SYMBOL(usb_hid_device_is_connected),
|
||||
DEFINE_MODULE_SYMBOL(USB_HID_DEVICE_TYPE),
|
||||
// drivers/usb_msc_device
|
||||
DEFINE_MODULE_SYMBOL(usb_msc_device_get),
|
||||
DEFINE_MODULE_SYMBOL(usb_msc_device_start),
|
||||
DEFINE_MODULE_SYMBOL(usb_msc_device_stop),
|
||||
DEFINE_MODULE_SYMBOL(usb_msc_device_is_connected),
|
||||
DEFINE_MODULE_SYMBOL(USB_MSC_DEVICE_TYPE),
|
||||
// drivers/usb_midi_device
|
||||
DEFINE_MODULE_SYMBOL(usb_midi_device_get),
|
||||
DEFINE_MODULE_SYMBOL(usb_midi_device_start),
|
||||
DEFINE_MODULE_SYMBOL(usb_midi_device_stop),
|
||||
DEFINE_MODULE_SYMBOL(usb_midi_device_set_name),
|
||||
DEFINE_MODULE_SYMBOL(usb_midi_device_send),
|
||||
DEFINE_MODULE_SYMBOL(usb_midi_device_is_connected),
|
||||
DEFINE_MODULE_SYMBOL(USB_MIDI_DEVICE_TYPE),
|
||||
// concurrent/dispatcher
|
||||
DEFINE_MODULE_SYMBOL(dispatcher_alloc),
|
||||
DEFINE_MODULE_SYMBOL(dispatcher_free),
|
||||
|
||||
Reference in New Issue
Block a user