56static const char*
s_tag =
"USBCOMP";
64typedef enum : uint16_t {
76typedef enum : uint8_t {
92typedef enum : uint8_t {
103typedef enum : uint8_t {
115typedef enum : uint8_t {
132typedef enum : uint8_t {
145typedef enum : uint8_t {
199 s_state.if_owner_plus_one[i] = 0U;
262 if (
s_state.if_owner_plus_one[idx] != 0U) {
289 s_state.if_owner_plus_one[idx] = (uint8_t)(class_index + 1U);
316 const uint8_t slot =
s_state.if_owner_plus_one[if_num];
320 *out_idx = (uint8_t)(slot - 1U);
355 const uint16_t addr16 = setup->
w_value;
465 for (uint8_t i =
s_state.class_count; i > 0U; --i) {
466 const uint8_t idx = (uint8_t)(i - 1U);
468 if (cl->
close !=
nullptr) {
510 const uint8_t slot =
s_state.class_count;
511 s_state.classes[slot] = *class_layer;
513 s_state.class_count = (uint8_t)(slot + 1U);
541 s_state.device_desc = device_desc;
542 s_state.config_desc = config_desc;
604 uint8_t class_idx = 0U;
609 s_state.last_handler_class = class_idx;
610 *out_handler_class = class_idx;
621 *out_count =
s_state.class_count;
632 *out_desc =
s_state.device_desc;
643 *out_desc =
s_state.config_desc;
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_no_mem
Static buffer exhausted (no dynamic memory on this project).
@ k_ra8_err_invalid_arg
Invalid function argument.
@ k_ra8_err_exists
Item already exists – cannot create again.
@ k_ra8_err_invalid_state
Module in wrong state for requested operation.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
@ k_ra8_err_null_ptr
Pointer was NULL where a valid pointer was required.
@ k_ra8_err_not_found
Requested item not found (lookup / search missed).
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.
#define ra8_log_info(tag, message)
RA8 log info.
Native USB controller driver public API (device + host modes).
static ra8_err_t internal_handle_standard(const ra8_usb_setup_t *setup)
Handle a STANDARD chapter-9 request internally.
ra8_err_t ra8_usb_composite_dispatch_setup(const ra8_usb_setup_t *setup, uint8_t *out_handler_class)
Inject a SETUP packet directly into the dispatch logic.
ra8_err_t ra8_usb_composite_get_class_count(uint8_t *out_count)
Read back the number of currently-registered class layers.
ra8_err_t ra8_usb_composite_init(ra8_usb_speed_t speed)
Bring up the composite-class driver on a chosen USB controller.
ra8_usb_composite_request_type_t
bmRequestType type-field values (USB 2.0 sec 9.3.1).
@ k_ra8_usb_composite_req_type_standard
STANDARD request.
@ k_ra8_usb_composite_req_type_mask
Mask for type field.
@ k_ra8_usb_composite_req_type_class
CLASS request.
@ k_ra8_usb_composite_req_type_vendor
VENDOR request.
ra8_err_t ra8_usb_composite_step(void)
Drive the composite dispatch state machine forward by one step.
ra8_usb_composite_std_request_t
Standard bRequest codes the composite layer answers (USB 2.0 sec 9.4 Table 9-4).
@ k_ra8_usb_composite_std_set_descriptor
SET_DESCRIPTOR.
@ k_ra8_usb_composite_std_get_configuration
GET_CONFIGURATION.
@ k_ra8_usb_composite_std_get_descriptor
GET_DESCRIPTOR.
@ k_ra8_usb_composite_std_set_configuration
SET_CONFIGURATION.
@ k_ra8_usb_composite_std_clear_feature
CLEAR_FEATURE.
@ k_ra8_usb_composite_std_set_address
SET_ADDRESS.
@ k_ra8_usb_composite_std_set_feature
SET_FEATURE.
@ k_ra8_usb_composite_std_get_status
GET_STATUS.
@ k_ra8_usb_composite_std_get_interface
GET_INTERFACE.
@ k_ra8_usb_composite_std_set_interface
SET_INTERFACE.
ra8_usb_composite_handler_sentinel_t
Marker the dispatch helper writes when the composite layer itself answered (no class fired).
@ k_ra8_usb_composite_handler_self
RA8 USB composite handler self.
usbc_mask_t
Low-byte mask for the setup-packet wIndex.
@ k_usbc_byte_mask
Usbc byte mask.
static void internal_clear_if_owners(void)
Reset every IF-ownership slot to "unowned".
static ra8_err_t internal_lookup_class_for_if(uint8_t if_num, uint8_t *out_idx)
Find the registered class that owns interface if_num.
ra8_err_t ra8_usb_composite_get_device_descriptor(const uint8_t **out_desc)
Read back the cached device descriptor pointer.
ra8_usb_composite_state_t
Composite dispatch state-machine phases.
@ k_ra8_usb_composite_state_std_dispatch
Standard request handler.
@ k_ra8_usb_composite_state_done
Reply staged.
@ k_ra8_usb_composite_state_idle
No SETUP in flight.
@ k_ra8_usb_composite_state_setup_rx
SETUP arrived.
@ k_ra8_usb_composite_state_class_dispatch
Class-routed dispatch.
ra8_usb_composite_address_limit_t
USB address ceiling (USB 2.0 sec 9.4.6).
@ k_ra8_usb_composite_max_address
7-bit USB address.
ra8_err_t ra8_usb_composite_set_descriptors(const uint8_t *device_desc, const uint8_t *config_desc)
Cache caller-owned device + configuration descriptor pointers.
ra8_err_t ra8_usb_composite_get_config_descriptor(const uint8_t **out_desc)
Read back the cached configuration descriptor pointer.
static ra8_err_t internal_require_init(void)
Pre-init guard helper used by every public entry point that is not init itself.
static ra8_err_t internal_route_class(const ra8_usb_setup_t *setup, uint8_t *out_idx)
Route a CLASS or VENDOR SETUP request to the registered class whose IF range covers setup->w_index.
static ra8_err_t internal_check_collision(const ra8_usb_composite_class_t *cl)
Detect IF-range overlap with already-registered classes.
static ra8_err_t internal_validate_class(const ra8_usb_composite_class_t *cl)
Validate caller-supplied class-layer record.
ra8_usb_composite_recipient_t
bmRequestType recipient-field values (USB 2.0 sec 9.3.1).
@ k_ra8_usb_composite_recipient_device
Device recipient.
@ k_ra8_usb_composite_recipient_mask
Mask for recipient.
@ k_ra8_usb_composite_recipient_endpoint
Endpoint recipient.
@ k_ra8_usb_composite_recipient_interface
Interface recipient.
ra8_err_t ra8_usb_composite_close(void)
Tear down the composite-class driver and release the controller.
ra8_err_t ra8_usb_composite_register_class(const ra8_usb_composite_class_t *class_layer)
Register a single class layer with the composite driver.
static void internal_mark_ownership(const ra8_usb_composite_class_t *cl, uint8_t class_index)
Mark each IF in a class's range as owned by class_index.
Native USB device-side composite-class layer.
@ k_ra8_usb_composite_max_classes
Registered class ceiling.
@ k_ra8_usb_composite_max_ifs
Highest IF number tracked.
ra8_err_t ra8_usb_device_init(ra8_usb_speed_t speed)
Bring up a USB controller in device mode.
ra8_err_t ra8_usb_set_address(ra8_usb_speed_t speed, uint8_t address)
Program the device USB address into USBADDR.
ra8_err_t ra8_usb_device_deinit(ra8_usb_speed_t speed)
Tear down a USB controller and drop its MSTP reference.
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).
Caller-owned class-layer registration record.
ra8_usb_composite_setup_fn_t handle_setup
setup callback (non-NULL).
uint8_t interface_number_count
IF count (CDC=2, HID=1...).
ra8_usb_composite_init_fn_t init
init callback (non-NULL).
void * ctx
Opaque context.
uint8_t interface_number_first
First IF this class owns.
ra8_usb_composite_close_fn_t close
close callback (non-NULL).
Singleton shadow state for the composite-class driver.
ra8_usb_composite_class_t classes[k_ra8_usb_composite_max_classes]
Table.
const uint8_t * device_desc
Cached device descriptor.
ra8_usb_composite_state_t state
Dispatch state machine phase.
ra8_usb_speed_t speed
Underlying controller.
bool initialized
True after init.
const uint8_t * config_desc
Cached config descriptor.
uint8_t class_count
Registered classes count.
uint8_t last_handler_class
Last dispatched class index.
uint8_t if_owner_plus_one[k_ra8_usb_composite_max_ifs]
IF -> class index + 1 (0 = unowned).
Decoded 8-byte USB SETUP packet.
uint8_t b_request
bRequest code.
uint8_t bm_request_type
Request direction / type / recipient.