71#include "ux_device_class_hid.h"
72#include "ux_device_stack.h"
142typedef enum : uint32_t {
150#ifndef RA8_OFF_TARGET
380typedef enum : uint8_t {
430 if (_ux_system_slave != UX_NULL) {
431 _ux_system_slave->ux_system_slave_device.ux_slave_device_state =
432 (
unsigned long)UX_DEVICE_CONFIGURED;
481 return _ux_device_stack_initialize((UCHAR*)UX_NULL,
517 hid_event->ux_device_class_hid_event_report_id = 0UL;
518 hid_event->ux_device_class_hid_event_report_type = (
ULONG)UX_DEVICE_CLASS_HID_REPORT_TYPE_INPUT;
520 hid_event->ux_device_class_hid_event_buffer[
k_hid_seq_idx] = 0U;
544 UX_SLAVE_CLASS_HID_PARAMETER hid_params = {
548 .ux_device_class_hid_parameter_report_id = 0UL,
550 .ux_device_class_hid_parameter_callback = UX_NULL,
553 static UCHAR s_class_name[] =
"ux_slave_class_hid";
555 return _ux_device_stack_class_register(s_class_name,
556 _ux_device_class_hid_entry,
583 if (_ux_system_slave != UX_NULL) {
584 _ux_system_slave->ux_system_slave_device.ux_slave_device_state =
585 (
unsigned long)UX_DEVICE_CONFIGURED;
587 UX_SLAVE_CLASS_HID_EVENT ev;
588 (void)
memset(&ev, 0,
sizeof(ev));
590 ev.ux_device_class_hid_event_report_id = 0UL;
591 ev.ux_device_class_hid_event_report_type = (
ULONG)UX_DEVICE_CLASS_HID_REPORT_TYPE_INPUT;
594 if (_ux_device_class_hid_event_set(
s_hid_class, &ev) == UX_SUCCESS) {
625 if (ux != UX_SUCCESS) {
631 if (ux != UX_SUCCESS) {
679 static CHAR s_semaphore_name[] =
"hid_active";
683 (void)first_unused_memory;
729 __asm__
volatile(
"wfi");
790 uint32_t cpuclk0_hz = 0U;
838#ifndef RA8_OFF_TARGET
void main(void)
Secure fallback main entry point.
void tx_application_define(void *first_unused_memory)
ThreadX system-define hook: build worker thread + byte pool.
void _tx_timer_interrupt(void)
void SysTick_Handler(void)
SysTick exception handler – tail-calls the ThreadX timer.
static volatile bool s_tx_kernel_up
Set in tx_application_define; gates ThreadX tick delivery.
static UCHAR s_host_stack[k_wlun_host_stack]
Stack backing storage for s_host_thread.
static TX_THREAD s_device_thread
ThreadX TCB for the USBX device-side worker thread.
static UCHAR s_string_framework[]
USBX string descriptor table (vendor / product / serial).
static UCHAR s_usbx_pool[k_wlun_usbx_pool_bytes]
USBX memory pool (USBX uses tx_byte_pool internally).
@ k_usb_langid_en_us_lo
LANGID 0x0409 low byte.
@ k_usb_langid_en_us_hi
LANGID 0x0409 high byte.
static CHAR s_host_thread_name[]
static TX_THREAD s_host_thread
ThreadX TCB for the host-side worker thread.
static UCHAR s_device_framework_fs[]
static UCHAR s_language_id_framework[]
USBX language-id table – US English.
static UCHAR s_device_stack[k_wlun_thread_stack]
Stack backing storage for s_device_thread.
static volatile uint32_t s_dbg_dev_step
Device worker progress: 1 stack, 2 class, 3 dcd, 4 attach, 5 parked.
static volatile uint32_t s_dbg_dev_err
Device worker first failing return code (0 = none).
static CHAR s_device_thread_name[]
static void hid_route_usb_or_halt(void)
Route both ports' pins: FS as device, HS as host.
static void hid_setup_or_halt(void)
Bring CGC + both USB clocks + SysTick + SCI8 + LEDs + pins up.
static const ra8_port_pin_t k_hid_pin_hs_vbus
USBHS_VBUS sense pin (P4_08, PSEL = 0x14).
static void hid_panic_halt(void)
Halt forever in WFI – panic stop on init failure.
static const ra8_port_pin_t k_hid_pin_fs_dm
USBFS D- (P8_15).
static const ra8_port_pin_t k_hid_pin_fs_vbusen
USBFS VBUSEN (P5_00) – GPIO LOW for the device role.
static const ra8_port_pin_t k_hid_pin_fs_dp
USBFS D+ (P8_14).
static VOID hid_host_worker(ULONG arg)
Host-side worker: retry the full pass until it succeeds.
static const ra8_port_pin_t k_hid_pin_hs_pwr
J7 host-power switch (PD07): HIGH = U18 supplies VBUS (UM 6.2).
static const ra8_port_pin_t k_hid_pin_fs_vbus
USBFS VBUS sense pin (P4_07, PSEL = 0x13).
static VOID hid_activate(VOID *hid_instance)
HID activate callback.
static UINT hid_class_register(void)
Register the HID class against configuration 1, interface 0.
static VOID hid_deactivate(VOID *hid_instance)
HID deactivate callback.
static UINT hid_usbx_stack_up(void)
Bring USBX system + device stack up with the HID framework.
static TX_SEMAPHORE s_hid_active_sem
Posted by the activate callback so the send worker blocks on it instead of polling s_hid_class with t...
static void hid_send_iter(uint32_t *seq)
One device send iteration: queue a fresh input report.
static VOID hid_device_worker(ULONG arg)
Device-side worker: bring the HID device up, then send reports.
static UINT hid_get_callback(UX_SLAVE_CLASS_HID *hid, UX_SLAVE_CLASS_HID_EVENT *hid_event)
HID GET_REPORT control-pipe callback: hand back a neutral report.
Board-support layer for the Renesas EK-RA8D2 v1 evaluation kit.
ra8_err_t ra8_board_led_toggle(ra8_board_led_id_t led)
Toggle led's output state.
ra8_err_t ra8_board_led_init(ra8_board_led_id_t led)
Configure led as a digital output, initial level low (off).
@ k_ra8_board_led2
LED2, GREEN, P303 (jumper E26).
@ k_ra8_board_led1
LED1, BLUE, P600 (jumper E27).
ra8_err_t ra8_board_io_expander_set_usbhs_host_mode(void)
Drive the U15 I/O expander to select USB-HS HOST mode.
ra8_err_t ra8_board_uart_console_init(uint32_t baud)
Configure SCI8 + PD02/PD03 as the debug-console UART.
@ k_ra8_board_usbhs_pin_pwr
PD07 J7 host-power switch (HIGH = U18 drives 5 V VBUS).
@ k_ra8_board_usbhs_pin_vbus
P4_08 USBHS_VBUS sense.
@ k_ra8_board_usbfs_pin_dm
P8_15 D-.
@ k_ra8_board_usbfs_pin_vbusen
P5_00 VBUSEN GPIO.
@ k_ra8_board_usbfs_pin_vbus
P4_07 VBUS sense.
@ k_ra8_board_usbfs_pin_dp
P8_14 D+.
Boot entry points shared between a vector table and its startup code.
High-level Clock Generation Circuit driver.
ra8_err_t ra8_cgc_get_clock_hz(ra8_clock_id_t id, uint32_t *out_hz)
Query the current frequency of a clock-tree domain.
@ k_ra8_clock_id_cpuclk0
Cortex-M85 CPUCLK0.
ra8_err_t ra8_cgc_init(void)
Configure the clock tree to a safe default.
ra8_err_t ra8_cgc_usbfs_clock_enable(void)
Bring up the USB-FS module clock (USBCKCR / USBCKDIVCR).
ra8_err_t ra8_cgc_usbhs_pll_enable(void)
Bring up the USBHS PHY reference clock + module clock.
Error Code Definitions for ra8-firmware.
@ 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.
void * memset(void *dst, int value, size_t n)
Fill memory with a constant byte value.
PSEL codes for peripheral pin routing on the RA8D2.
@ k_ra8_psel_usb_fs
10011b: USB Full-Speed.
@ k_ra8_psel_usb_hs
10100b: USB High-Speed (e.g.
NVIC + ICU IELSR allocator.
void ra8_isr_globals_enable(void)
Globally enable maskable interrupts (PRIMASK = 0).
Typed Port / Pin Constants for the RA8D2 IOPORT Module.
ra8_port_pin_t
Packed (port << 8) | pin pin identifier.
@ k_ra8_level_high
Drive or read 1.
@ k_ra8_level_low
Drive or read 0.
High-level GPIO helpers on top of the PORT + PFS register layer.
ra8_err_t ra8_gpio_output_init(ra8_port_pin_t pin, ra8_level_t init_level)
Configure a pin as a digital output and drive it to an initial level.
ra8_err_t ra8_pfs_route_peripheral(ra8_port_pin_t pin, ra8_psel_t psel, const char *owner)
Route a pin to a non-IRQ peripheral function via PFS.PSEL.
void ux_dcd_ra8_usb_irq_reenable(void)
Storm-guard recovery: zero the run counter and re-enable the USB IRQ.
SysTick-based tick counter, delay and timestamp helpers.
ra8_err_t ra8_time_init(uint32_t cpu_hz)
Initialise SysTick for a 1 kHz tick interrupt.
void ra8_time_on_tick(void)
SysTick IRQ handler – called from the vector table.
Native USB controller driver public API (device + host modes).
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_speed_fs
Full-Speed controller (USBFS @ 0x40250000).
unsigned int UINT
ThreadX-compatible unsigned int (host stub).
char CHAR
ThreadX-compatible CHAR (host stub).
unsigned long ULONG
ThreadX-compatible unsigned long (host stub).
Opaque thread stand-in for the host build.
hid_dev_step_t
J-Link probe values marking device-worker bring-up progress.
@ k_hid_dev_step_stack
USBX system + device stack up.
@ k_hid_dev_step_dcd
DCD bridge initialized.
@ k_hid_dev_step_send
Report-send loop running.
@ k_hid_dev_step_attach
Device attached (DPRPU).
@ k_hid_dev_step_class
HID class registered.
static VOID hid_activate(VOID *hid_instance)
HID activate callback.
static VOID hid_deactivate(VOID *hid_instance)
HID deactivate callback.
static UCHAR s_report_descriptor[]
static volatile uint32_t s_dbg_dev_sent
Device-side report-queue successes (one hid_event_set each).
static UINT hid_get_callback(UX_SLAVE_CLASS_HID *hid, UX_SLAVE_CLASS_HID_EVENT *hid_event)
HID GET_REPORT control-pipe callback: hand back a neutral report.
static UX_SLAVE_CLASS_HID * s_hid_class
Active HID class instance, captured by the activate callback.
VOID hid_device_worker(ULONG arg)
Device-side worker: bring the HID device up, then send reports.
void hid_fill_report_body(uint8_t *out, uint32_t len)
Fill the fixed body of a HID report (bytes 1..len-1).
@ k_hid_report_len
Vendor input report width (bytes).
@ k_hid_pat_bias
Pattern constant bias.
@ k_hid_pat_idx_mul
Per-index pattern multiplier.
@ k_hid_body_idx
Report body starts at byte 1.
@ k_hid_byte_mask
Byte mask.
@ k_hid_seq_idx
Report byte 0: modifier / rolling seq.
@ k_hid_thread_stack
Device worker stack (bytes).
@ k_hid_usbx_pool_bytes
USBX memory pool (bytes).
@ k_hid_host_stack
Host worker stack (bytes).
@ k_hid_host_priority
Host worker priority (below USBX).
@ k_hid_baud
J-Link OB CDC log baud.
@ k_hid_dev_priority
Device bring-up worker priority.
Shared contract for the USB HID self-loop console + host clusters.
USBX device-controller-driver (DCD) bridge to ra8_usb.
ra8_err_t ux_dcd_ra8_usb_initialize(ra8_usb_speed_t speed)
Register the ra8_usb bridge as the active USBX DCD.