48static const char*
s_tag =
"USBHHID";
63typedef enum : uint8_t {
80typedef enum : uint8_t {
104typedef enum : uint16_t {
118typedef enum : uint8_t {
198 s_state.device.intr_in_max_packet);
201 if (
s_state.device.intr_out_ep != 0U) {
207 s_state.device.intr_out_max_packet);
260 .w_value = (uint16_t)address,
287 .w_value = (uint16_t)config_value,
345 .w_index = (uint16_t)
s_state.device.interface_number,
376 s_state.device.intr_in_ep = 1U;
377 s_state.device.intr_out_ep = 0U;
378 s_state.device.interface_number = 0U;
382 s_state.device.intr_out_max_packet = 0U;
383 s_state.device.report_descriptor_len = 0U;
429 "hhid: release bus reset");
454 "hhid: set USBADDR");
580 if (
s_state.attach_cb !=
nullptr) {
719typedef enum : uint16_t {
792 uint16_t take = (available < max_len) ? available : max_len;
799 const uint16_t even = (uint16_t)(take >> 1U);
800 for (uint16_t i = 0U; i < even; ++i) {
801 const uint16_t word = reg->
CFIFO;
802 out[(2U * i) + 0U] = (uint8_t)(word &
k_byte_mask);
805 if ((take & 1U) != 0U) {
806 const uint16_t word = reg->
CFIFO;
821 uint8_t target_report_id,
842 (uint16_t)target_report_id);
847 .w_index = (uint16_t)
s_state.device.interface_number,
860 if (reg !=
nullptr) {
871 uint8_t target_report_id,
872 const uint8_t* in_buf,
881 if ((in_buf ==
nullptr) && (len != 0U)) {
889 (uint16_t)target_report_id);
894 .w_index = (uint16_t)
s_state.device.interface_number,
918 const uint16_t value =
924 .w_index = (uint16_t)
s_state.device.interface_number,
949 .w_value = (uint16_t)boot_or_report,
950 .w_index = (uint16_t)
s_state.device.interface_number,
974 uint16_t inout_len = max_len;
978 *got_len = inout_len;
@ k_byte_bits
Bits per byte (SHPR field width).
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_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_set_address(ra8_usb_speed_t speed, uint8_t address)
Program the device USB address into USBADDR.
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.
@ 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).
static ra8_err_t internal_do_set_address(void)
Step handler – store assigned address + SETUP for GET_DEVICE_DESCRIPTOR.
static volatile r_usb_regs_t * internal_pick_regs(ra8_usb_speed_t speed)
Pick the controller register window for the active speed.
ra8_err_t ra8_usb_hhid_close(void)
Tear down the host-HID driver and release the controller.
static ra8_err_t internal_setup_set_config(uint8_t config_value)
Stage a SET_CONFIGURATION SETUP request.
ra8_err_t ra8_usb_hhid_set_report(ra8_usb_hhid_report_type_t target_report_type, uint8_t target_report_id, const uint8_t *in_buf, uint16_t len)
Issue SET_REPORT (USB HID 1.11 sec 7.2.2) over the DCP.
static ra8_err_t internal_do_idle(void)
Step handler – bus-reset assert.
ra8_usb_hhid_byte_shift_t
Per-byte left-shift constants for wValue layout.
@ k_ra8_hhid_shift_byte0
RA8 hhid shift byte0.
@ k_ra8_hhid_shift_byte1
RA8 hhid shift byte1.
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)
Step handler – SETUP for SET_INTERFACE.
static ra8_err_t internal_setup_set_interface(void)
Stage a SET_INTERFACE (alt 0, iface 0) SETUP request.
static ra8_err_t internal_setup_get_descriptor(uint8_t desc_type, uint16_t length)
Stage a chapter-9 GET_DESCRIPTOR SETUP request.
static uint16_t internal_intr_max_packet(ra8_usb_speed_t speed)
Pick the interrupt-max-packet ceiling for the negotiated speed.
ra8_usb_hhid_setup_field_t
Standard chapter-9 + HID class request encodings.
@ k_ra8_hhid_desc_configuration
CONFIGURATION descriptor.
@ k_ra8_hhid_bm_class_iface_in
Class | Interface | In.
@ k_ra8_hhid_breq_set_interface
SET_INTERFACE.
@ k_ra8_hhid_breq_set_address
SET_ADDRESS.
@ k_ra8_hhid_breq_set_config
SET_CONFIGURATION.
@ k_ra8_hhid_bm_class_iface_out
Class | Interface | Out.
@ k_ra8_hhid_desc_device
DEVICE descriptor.
@ k_ra8_hhid_breq_get_descriptor
GET_DESCRIPTOR.
@ k_ra8_hhid_desc_endpoint
ENDPOINT descriptor.
@ k_ra8_hhid_desc_interface
INTERFACE descriptor.
@ k_ra8_hhid_bm_std_dev_in
Std | Device | In.
@ k_ra8_hhid_bm_std_iface_out
Std | Interface | Out.
@ k_ra8_hhid_bm_std_dev_out
Std | Device | Out.
@ k_ra8_hhid_bm_std_iface_in
Std | Interface | In.
ra8_err_t ra8_usb_hhid_set_protocol(ra8_usb_hhid_protocol_select_t boot_or_report)
Issue SET_PROTOCOL (USB HID 1.11 sec 7.2.6) over the DCP.
static ra8_err_t internal_do_bus_reset(void)
Step handler – bus-reset release + SETUP for SET_ADDRESS.
static bool internal_report_type_ok(ra8_usb_hhid_report_type_t t)
Validate that a ra8_usb_hhid_report_type_t value is in range.
static ra8_err_t internal_do_get_dev_desc(void)
Step handler – SETUP for GET_CONFIGURATION_DESCRIPTOR.
static void internal_walk_config_descriptor(void)
Populate s_state.device with stub descriptor data.
static ra8_err_t internal_do_set_interface(void)
Step handler – pure software descriptor walk.
ra8_usb_hhid_step_t
Enumeration step machine states.
@ k_ra8_hhid_step_get_cfg_desc
GET_CONFIGURATION_DESCRIPTOR.
@ k_ra8_hhid_step_idle
Pre-attach.
@ k_ra8_hhid_step_get_dev_desc
GET_DEVICE_DESCRIPTOR (18 B).
@ k_ra8_hhid_step_get_report_desc
GET_DESCRIPTOR (Report).
@ k_ra8_hhid_step_set_address
SET_ADDRESS to assigned 1.
@ k_ra8_hhid_step_walk_desc
Find HID IF; populate pipes.
@ k_ra8_hhid_step_set_interface
SET_INTERFACE (0).
@ k_ra8_hhid_step_bus_reset
Drive USBRST then release.
@ k_ra8_hhid_step_done
Attach callback fires.
@ k_ra8_hhid_step_set_config
SET_CONFIGURATION (1).
static ra8_err_t internal_setup_get_report_descriptor(uint16_t length)
Stage a GET_DESCRIPTOR (Report descriptor) SETUP request.
ra8_usb_hhid_dcp_t
CFIFO programming constants used by the EP0 IN drain helper.
@ k_ra8_hhid_fifo_poll_lim
FRDY-poll budget.
@ k_ra8_hhid_dcp_pipe_dcp
DCP / EP0 select.
ra8_err_t ra8_usb_hhid_init(ra8_usb_speed_t speed)
Bring up the host-HID driver on a chosen USB controller.
ra8_err_t ra8_usb_hhid_set_idle(uint8_t duration, uint8_t report_id)
Issue SET_IDLE (USB HID 1.11 sec 7.2.4) over the DCP.
ra8_err_t ra8_usb_hhid_get_input_report(uint8_t *out_buf, uint16_t max_len, uint16_t *got_len)
Drain the next input report from the interrupt-IN pipe.
ra8_err_t ra8_usb_hhid_get_report(ra8_usb_hhid_report_type_t target_report_type, uint8_t target_report_id, uint8_t *out_buf, uint16_t max_len, uint16_t *got_len)
Issue GET_REPORT (USB HID 1.11 sec 7.2.1) over the DCP.
ra8_usb_hhid_size_t
Standard descriptor sizes and request payload sizes.
@ k_ra8_hhid_ep_desc_len
ENDPOINT descriptor.
@ k_ra8_hhid_iface_desc_len
INTERFACE descriptor.
@ k_ra8_hhid_dev_desc_len
USB DEVICE descriptor.
@ k_ra8_hhid_hid_desc_len
HID class descriptor (min).
@ k_ra8_hhid_cfg_desc_len
CONFIGURATION descriptor hdr.
@ k_ra8_hhid_assigned_address
First assigned device addr.
@ k_ra8_hhid_default_config
bConfigurationValue = 1.
static ra8_err_t internal_do_walk_desc(void)
Step handler – configure pipes + SETUP GET_DESCRIPTOR(Report).
static ra8_err_t internal_do_get_report_desc(void)
Step handler – finalise + fire attach callback.
ra8_err_t ra8_usb_hhid_step(void)
Drive the enumeration step machine forward by one step.
ra8_err_t ra8_usb_hhid_attach_callback(ra8_usb_hhid_attach_fn_t on_attach, void *ctx)
Register (or detach) the attach callback.
static uint16_t internal_dcp_in_drain(volatile r_usb_regs_t *reg, uint8_t *out, uint16_t max_len)
Drain the DCP (EP0) IN FIFO after a class GET_REPORT SETUP.
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)
Step handler – SETUP for SET_CONFIGURATION.
static ra8_err_t internal_configure_pipes(void)
Configure the host-HID interrupt-IN pipe against the attached device's endpoint.
Native USB host-side HID (Human Interface Device) class layer.
ra8_usb_hhid_report_type_t
HID report-type selector encoded in wValue's high byte for GET_REPORT / SET_REPORT.
@ k_ra8_hhid_report_type_input
Input report.
@ k_ra8_hhid_report_type_feature
Feature report.
@ k_ra8_hhid_report_type_output
Output report.
void(* ra8_usb_hhid_attach_fn_t)(void *ctx, const ra8_usb_hhid_device_t *device)
Attach-callback signature.
@ k_ra8_hhid_protocol_keyboard
Boot keyboard.
@ k_ra8_hhid_subclass_boot
Boot Interface Subclass.
@ k_ra8_hhid_desc_report
HID Report descriptor.
@ k_ra8_hhid_intr_max_packet_default
Boot-protocol default.
@ k_ra8_hhid_intr_max_packet_hs
HS ceiling.
@ k_ra8_hhid_report_desc_max
Cached Report desc max len.
@ k_ra8_hhid_req_set_report
SET_REPORT.
@ k_ra8_hhid_req_get_report
GET_REPORT.
@ k_ra8_hhid_req_set_protocol
SET_PROTOCOL.
@ k_ra8_hhid_req_set_idle
SET_IDLE.
ra8_usb_hhid_protocol_select_t
wValue payload for SET_PROTOCOL.
@ k_ra8_hhid_proto_boot
Boot protocol.
@ k_ra8_hhid_proto_report
Report protocol.
@ k_ra8_hhid_pipe_intr_out
PIPE7 -> attached EP intr OUT.
@ k_ra8_hhid_pipe_intr_in
PIPE6 -> attached EP intr IN.
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.
USB Full-Speed + High-Speed controller layout for the Renesas RA8D2.
@ k_ra8_fifoctr_frdy
FIFO ready.
@ k_ra8_fifoctr_bclr
Buffer clear.
@ k_ra8_fifoctr_dtln
Data length (write-bytes-rem).
@ k_ra8_fifosel_isel
CFIFO direction (DCP only).
@ k_ra8_fifosel_mbw_16
16-bit FIFO access width.
@ k_ra8_fifosel_curpipe
Current pipe select [3:0].
static volatile r_usb_regs_t * ra8_usb_hs(void)
Get pointer to the USB HS controller register block.
static volatile r_usb_regs_t * ra8_usb_fs(void)
Compile-time offset and size insurance for r_usb_regs_t.
USB FS / HS register window (device-mode subset).
volatile uint16_t CFIFOCTR
+0x022 Control FIFO control.
volatile uint16_t CFIFOSEL
+0x020 Control FIFO select.
volatile uint16_t CFIFO
+0x014 Control FIFO data port.
Snapshot of the attached HID device, passed to the attach callback.
Singleton shadow state for the host-HID driver.
ra8_usb_hhid_device_t device
Snapshot of attached device.
bool attached
True after enumeration done.
void * attach_ctx
Attach callback ctx.
uint8_t hid_desc[k_ra8_hhid_hid_desc_len]
HID class descriptor cache.
ra8_usb_speed_t speed
Underlying controller.
ra8_usb_hhid_attach_fn_t attach_cb
Attach callback, or NULL.
ra8_usb_hhid_step_t step
Current enumeration step.
uint8_t report_desc[k_ra8_hhid_report_desc_max]
HID Report descriptor cache.
bool initialized
True after ra8_usb_hhid_init.
Decoded 8-byte USB SETUP packet.