42static const char*
s_tag =
"USBPHID";
58typedef enum : uint8_t {
70typedef enum : uint8_t {
79typedef enum : uint16_t {
247 const uint8_t duration =
315 uint16_t report_desc_len,
316 const uint8_t* hid_desc,
317 uint16_t hid_desc_len)
324 if ((report_desc_len == 0U) || (hid_desc_len == 0U)) {
327 s_state.report_desc = report_desc;
328 s_state.report_desc_len = report_desc_len;
330 s_state.hid_desc_len = hid_desc_len;
344 if ((payload ==
nullptr) && (len != 0U)) {
347 if ((report_id == 0U) && (len == 0U)) {
353 const uint16_t framed_len =
355 if (framed_len >
s_state.intr_max_packet) {
359 if (report_id != 0U) {
363 const uint8_t rid_byte = report_id;
387 uint16_t inout_len = max_len;
391 *got_len = inout_len;
435 if (
s_state.setup_cb !=
nullptr) {
455 *out_idle_rate =
s_state.idle_rate;
465 *out_protocol =
s_state.protocol;
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_RETURN_ON_ERROR(err, tag, message)
Early return on error, propagating the code upward.
#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_not_supported
Requested feature not compiled in, not wired, or not supported by this MCU variant.
@ 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.
@ k_ra8_err_null_ptr
Pointer was NULL where a valid pointer was required.
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_queue_out(ra8_usb_speed_t speed, uint8_t pipe_num, uint8_t *out_buf, uint16_t *inout_len, bool rearm)
Drain an OUT transfer (host -> device) from pipe_num.
@ k_ra8_usb_ep_type_intr
Interrupt transfer.
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_control_response(ra8_usb_speed_t speed, bool accept)
Issue a control-transfer status response on EP0.
ra8_err_t ra8_usb_device_deinit(ra8_usb_speed_t speed)
Tear down a USB controller and drop its MSTP reference.
ra8_err_t ra8_usb_configure_endpoint(ra8_usb_speed_t speed, uint8_t pipe_num, uint8_t ep_addr, ra8_usb_ep_dir_t dir, ra8_usb_ep_type_t type, uint16_t max_packet)
Configure a non-control PIPE for IN or OUT bulk / interrupt / iso transfers.
ra8_err_t ra8_usb_device_attach(ra8_usb_speed_t speed, bool attached)
Raise / drop the D+ pull-up to advertise the device to the host.
@ k_ra8_usb_ep_dir_in
Device -> host.
@ k_ra8_usb_ep_dir_out
Host -> device.
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).
ra8_err_t ra8_usb_queue_in(ra8_usb_speed_t speed, uint8_t pipe_num, const uint8_t *data, uint16_t len)
Queue an IN transfer (device -> host) on pipe_num.
static ra8_err_t internal_configure_pipes(void)
Configure the host-Audio iso pipes against the attached device's endpoints.
ra8_err_t ra8_usb_phid_recv_report(uint8_t report_id, uint8_t *buf, uint16_t max_len, uint16_t *got_len)
Drain a HID output report from the interrupt-OUT endpoint.
ra8_usb_phid_byte_mask_t
Per-byte mask constants for wValue decoding.
@ k_ra8_phid_mask_byte
RA8 phid mask byte.
ra8_err_t ra8_usb_phid_get_idle(uint8_t *out_idle_rate)
Read the most-recently negotiated idle rate.
ra8_usb_phid_byte_shift_t
Per-byte shift constants for wValue decoding.
@ k_ra8_phid_shift_byte1
RA8 phid shift byte1.
@ k_ra8_phid_shift_byte0
RA8 phid shift byte0.
static uint16_t internal_intr_max_packet(ra8_usb_speed_t speed)
Pick the interrupt-max-packet ceiling matching the negotiated speed.
ra8_err_t ra8_usb_phid_get_protocol(ra8_usb_phid_protocol_select_t *out_protocol)
Read the most-recently negotiated protocol.
ra8_err_t ra8_usb_phid_init(ra8_usb_speed_t speed)
Bring up the device-HID function on a chosen USB controller.
ra8_err_t ra8_usb_phid_handle_setup(const ra8_usb_setup_t *setup)
Process a class-specific SETUP packet on EP0.
static void internal_reset_shadow(ra8_usb_speed_t speed)
Reset shadow state to spec defaults.
ra8_err_t ra8_usb_phid_attach_setup_handler(ra8_usb_phid_setup_fn_t setup_fn, void *ctx)
Register the application's HID class-setup handler.
ra8_usb_phid_setup_field_t
Constants used to decode HID class-specific SETUPs.
@ k_ra8_phid_bm_class_iface_in
Class | Iface | In.
@ k_ra8_phid_default_protocol
Spec default = report.
@ k_ra8_phid_report_id_prepend_len
Report ID byte.
@ k_ra8_phid_bm_class_iface_out
Class | Iface | Out.
@ k_ra8_phid_default_idle_rate
Spec default idle.
ra8_err_t ra8_usb_phid_set_descriptors(const uint8_t *report_desc, uint16_t report_desc_len, const uint8_t *hid_desc, uint16_t hid_desc_len)
Install the caller-supplied HID Report descriptor and HID class descriptor.
static bool internal_is_known_class_request(uint8_t b_request)
Recognise a HID class request code we shadow / forward.
static void internal_apply_class_setup(const ra8_usb_setup_t *setup)
Apply SET_IDLE / SET_PROTOCOL to the local shadow.
ra8_err_t ra8_usb_phid_close(void)
Tear down the device-HID function and release the controller.
ra8_err_t ra8_usb_phid_send_report(uint8_t report_id, const uint8_t *payload, uint16_t len)
Push a HID input report on the interrupt-IN endpoint.
Native USB device-side HID (Human Interface Device) class layer.
ra8_usb_phid_protocol_select_t
wValue payload for SET_PROTOCOL.
@ k_ra8_phid_proto_boot
Boot protocol.
@ k_ra8_phid_proto_report
Report protocol.
@ k_ra8_phid_intr_max_packet_default
Boot-protocol default.
@ k_ra8_phid_intr_max_packet_hs
HS ceiling.
@ k_ra8_phid_req_set_idle
SET_IDLE.
@ k_ra8_phid_req_get_report
GET_REPORT.
@ k_ra8_phid_req_get_idle
GET_IDLE.
@ k_ra8_phid_req_set_report
SET_REPORT.
@ k_ra8_phid_req_set_protocol
SET_PROTOCOL.
@ k_ra8_phid_req_get_protocol
GET_PROTOCOL.
@ k_ra8_phid_ep_intr_in_addr
EP1 IN address.
@ k_ra8_phid_ep_intr_out_addr
EP2 OUT address.
ra8_err_t(* ra8_usb_phid_setup_fn_t)(void *ctx, const ra8_usb_setup_t *setup)
Caller-supplied HID class-setup handler signature.
@ k_ra8_phid_pipe_intr_out
PIPE7 -> EP2 OUT (intr).
@ k_ra8_phid_pipe_intr_in
PIPE6 -> EP1 IN (intr).
Singleton shadow state for the device-HID function.
uint8_t intr_in_ep
IN endpoint number.
uint16_t intr_max_packet
Pipe max-packet size.
bool initialized
True after ra8_usb_phid_init.
uint8_t intr_out_ep
OUT endpoint number.
uint16_t report_desc_len
Report descriptor byte len.
ra8_usb_phid_setup_fn_t setup_cb
Application class handler.
const uint8_t * hid_desc
Cached HID class descriptor.
void * setup_ctx
Class handler context.
uint16_t hid_desc_len
HID class descriptor byte len.
const uint8_t * report_desc
Cached Report descriptor.
ra8_usb_speed_t speed
Underlying controller.
uint8_t idle_rate
4 ms ticks (0 = on-change).
ra8_usb_phid_protocol_select_t protocol
Boot vs report.
Decoded 8-byte USB SETUP packet.
uint8_t b_request
bRequest code.
uint8_t bm_request_type
Request direction / type / recipient.