37static const char*
s_tag =
"USBHHUB";
48typedef enum : uint8_t {
63typedef enum : uint8_t {
83typedef enum : uint16_t {
97typedef enum : uint8_t {
175 .w_value = (uint16_t)address,
202 .w_value = (uint16_t)config_value,
259 s_state.device.product_id = 0U;
423 if (
s_state.attach_cb !=
nullptr) {
538 *count =
s_state.device.port_count;
566 .w_index = (uint16_t)port,
593 .w_value = (uint16_t)feature,
594 .w_index = (uint16_t)port,
621 .w_value = (uint16_t)feature,
622 .w_index = (uint16_t)port,
static const char * s_tag
Logging / check tag.
Annotation-attribute framework macros for ra8-firmware.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
Validation and Error-Checking Macros for ra8-firmware.
#define RA8_CHECK_NULL_PTR(ptr, tag, message)
Reject nullptr pointer, returning k_ra8_err_null_ptr.
Error Code Definitions for ra8-firmware.
@ k_ra8_err_hw_init_failed
Hardware peripheral failed to initialise.
@ k_ra8_err_invalid_arg
Invalid function argument.
@ k_ra8_err_invalid_state
Module in wrong state for requested operation.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Lightweight Logging Interface for ra8-firmware.
#define ra8_log_info_val(tag, message, value)
RA8 log info val.
#define ra8_log_error_val(tag, message, value)
RA8 log error val.
Native USB controller driver public API (device + host modes).
ra8_err_t ra8_usb_set_address(ra8_usb_speed_t speed, uint8_t address)
Program the device USB address into USBADDR.
ra8_usb_speed_t
Selects which controller instance the call targets.
@ k_ra8_usb_speed_hs
High-Speed controller (USBHS @ 0x40351000).
@ k_ra8_usb_speed_fs
Full-Speed controller (USBFS @ 0x40250000).
static ra8_err_t internal_do_get_hub_desc(void)
Internal helper.
static ra8_err_t internal_do_set_address(void)
Internal helper.
static ra8_err_t internal_setup_set_config(uint8_t config_value)
Stage a SET_CONFIGURATION SETUP request.
static ra8_err_t internal_do_idle(void)
Internal helper.
ra8_err_t ra8_usb_hhub_set_port_feature(uint8_t port, ra8_usb_hhub_feature_t feature)
Issue SET_PORT_FEATURE (USB 2.0 sec 11.24.2.13) over the DCP.
static ra8_err_t internal_step_advance(void)
Drive the enumeration step machine forward by one step.
static ra8_err_t internal_do_set_config(void)
Internal helper.
ra8_err_t ra8_usb_hhub_step(void)
Drive the enumeration step machine forward by one step.
static ra8_err_t internal_setup_get_descriptor(uint8_t desc_type, uint16_t length)
Stage a chapter-9 GET_DESCRIPTOR SETUP request.
ra8_usb_hhub_size_t
Standard descriptor sizes / payload sizes.
@ k_ra8_hhub_port_status_len
GET_PORT_STATUS data length.
@ k_ra8_hhub_default_ports
Stub default port count.
@ k_ra8_hhub_assigned_address
First assigned device addr.
@ k_ra8_hhub_dev_desc_len
USB DEVICE descriptor.
@ k_ra8_hhub_hub_desc_len
Min HUB class descriptor.
@ k_ra8_hhub_cfg_desc_len
CONFIG descriptor header.
@ k_ra8_hhub_default_config
bConfigurationValue = 1.
ra8_err_t ra8_usb_hhub_close(void)
Tear down the host-HUB driver and release the controller.
static ra8_err_t internal_do_bus_reset(void)
Internal helper.
static ra8_err_t internal_do_get_dev_desc(void)
Internal helper.
static ra8_err_t internal_setup_get_hub_descriptor(void)
Stage a GET_DESCRIPTOR(HUB) class request.
static bool internal_port_ok(uint8_t port)
Validate port is within [1, port_count].
ra8_err_t ra8_usb_hhub_attach_callback(ra8_usb_hhub_attach_fn_t on_attach, void *ctx)
Register (or detach) the HUB attach callback.
ra8_err_t ra8_usb_hhub_init(ra8_usb_speed_t speed)
Bring up the host-HUB driver on a chosen USB controller.
ra8_err_t ra8_usb_hhub_clear_port_feature(uint8_t port, ra8_usb_hhub_feature_t feature)
Issue CLEAR_PORT_FEATURE (USB 2.0 sec 11.24.2.2) over the DCP.
ra8_usb_hhub_setup_field_t
Standard chapter-9 + HUB class request encodings.
@ k_ra8_hhub_bm_std_dev_out
Std | Device | Out.
@ k_ra8_hhub_bm_class_other_out
Class | Other | Out.
@ k_ra8_hhub_bm_std_dev_in
Std | Device | In.
@ k_ra8_hhub_breq_set_config
SET_CONFIGURATION.
@ k_ra8_hhub_breq_set_address
SET_ADDRESS.
@ k_ra8_hhub_breq_get_desc
GET_DESCRIPTOR.
@ k_ra8_hhub_bm_class_dev_in
Class | Device | In.
@ k_ra8_hhub_bm_class_other_in
Class | Other | In.
@ k_ra8_hhub_desc_configuration
CONFIG descriptor.
@ k_ra8_hhub_desc_device
DEVICE descriptor.
ra8_usb_hhub_step_t
Enumeration step machine states.
@ k_ra8_hhub_step_bus_reset
Drive USBRST then release.
@ k_ra8_hhub_step_get_hub_desc
GET_DESCRIPTOR(HUB) class.
@ k_ra8_hhub_step_set_address
SET_ADDRESS to assigned 1.
@ k_ra8_hhub_step_get_cfg_desc
GET_CONFIGURATION_DESCRIPTOR.
@ k_ra8_hhub_step_set_config
SET_CONFIGURATION (1).
@ k_ra8_hhub_step_get_dev_desc
GET_DEVICE_DESCRIPTOR.
@ k_ra8_hhub_step_idle
Pre-attach.
@ k_ra8_hhub_step_done
Attach callback fires.
static void internal_populate_device_defaults(void)
Populate s_state.device with stub descriptor data.
ra8_err_t ra8_usb_hhub_get_port_status(uint8_t port, uint32_t *status)
Issue GET_PORT_STATUS (USB 2.0 sec 11.24.2.7) over the DCP.
ra8_usb_hhub_byte_shift_t
Per-byte left-shift constants for wValue layout.
@ k_ra8_hhub_shift_byte1
Shift to high byte of a 16-bit field.
ra8_err_t ra8_usb_hhub_get_port_count(uint8_t *count)
Read the cached downstream port count from the HUB descriptor.
static ra8_err_t internal_setup_set_address(uint8_t address)
Stage a SET_ADDRESS SETUP request.
static ra8_err_t internal_do_get_cfg_desc(void)
Internal helper.
Native USB host-side HUB class layer.
void(* ra8_usb_hhub_attach_fn_t)(void *ctx, const ra8_usb_hhub_device_t *device)
Attach-callback signature.
ra8_usb_hhub_feature_t
HUB port feature selectors (USB 2.0 Table 11-17).
@ k_ra8_hhub_req_clear_feature
CLEAR_FEATURE.
@ k_ra8_hhub_req_set_feature
SET_FEATURE.
@ k_ra8_hhub_req_get_descriptor
GET_DESCRIPTOR.
@ k_ra8_hhub_req_get_status
GET_STATUS.
@ k_ra8_hhub_desc_hub
HUB class descriptor type.
@ k_ra8_hhub_first_port
Port numbering starts at 1.
ra8_err_t ra8_usb_host_bus_reset(ra8_usb_speed_t speed, bool assert_reset)
Drive (or release) the bus reset line.
ra8_err_t ra8_usb_host_init(ra8_usb_speed_t speed)
Bring up a USB controller in HOST mode.
ra8_err_t ra8_usb_host_deinit(ra8_usb_speed_t speed)
Tear down a host-mode controller and drop its MSTP reference.
ra8_err_t ra8_usb_host_setup_request(ra8_usb_speed_t speed, const ra8_usb_setup_t *setup)
Issue a SETUP packet through the DCP (host -> peripheral).
ra8_err_t ra8_usb_host_set_uact(ra8_usb_speed_t speed, bool enable)
Enable / disable SOF (Start-of-Frame) generation on the bus.
Snapshot of the attached HUB device, passed to the attach callback.
Singleton shadow state for the host-HUB driver.
ra8_usb_speed_t speed
Underlying controller.
void * attach_ctx
Attach callback ctx.
ra8_usb_hhub_device_t device
Snapshot of attached HUB.
bool initialized
True after ra8_usb_hhub_init.
bool attached
True after enumeration done.
ra8_usb_hhub_step_t step
Current enumeration step.
ra8_usb_hhub_attach_fn_t attach_cb
Attach callback, or NULL.
Decoded 8-byte USB SETUP packet.