43static const char*
s_tag =
"USBHCDC";
59typedef enum : uint8_t {
75typedef enum : uint8_t {
97typedef enum : uint16_t {
112typedef enum : uint8_t {
123typedef enum : uint32_t {
131typedef enum : uint32_t {
279 .w_value = (uint16_t)address,
306 .w_value = (uint16_t)config_value,
363 s_state.device.bulk_in_ep = 1U;
364 s_state.device.bulk_out_ep = 2U;
365 s_state.device.intr_in_ep = 3U;
411 "hcdc: release bus reset");
436 "hcdc: set USBADDR");
542 if (
s_state.attach_cb !=
nullptr) {
662 if ((data ==
nullptr) && (len != 0U)) {
681 uint16_t inout_len = max_len;
685 *got_len = inout_len;
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.
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_bulk
Bulk transfer.
@ 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).
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.
ra8_err_t ra8_usb_hcdc_set_line_coding(uint32_t baud, ra8_usb_hcdc_parity_t parity, ra8_usb_hcdc_stop_bits_t stop_bits)
Issue SET_LINE_CODING to the attached CDC-ACM device.
static ra8_err_t internal_do_set_address(void)
Step handler – store assigned address + SETUP for GET_DEVICE_DESCRIPTOR.
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)
Step handler – bus-reset assert.
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.
ra8_usb_hcdc_byte_mask_t
Byte mask for little-endian baud serialisation.
@ k_ra8_hcdc_byte_mask
Single-byte extraction mask.
ra8_usb_hcdc_setup_field_t
Standard chapter-9 + CDC class request encodings.
@ k_ra8_hcdc_breq_set_config
SET_CONFIGURATION.
@ k_ra8_hcdc_bm_std_dev_in
Std | Device | In.
@ k_ra8_hcdc_bm_class_iface_out
Class | Interface | Out.
@ k_ra8_hcdc_breq_set_address
SET_ADDRESS.
@ k_ra8_hcdc_desc_endpoint
ENDPOINT descriptor.
@ k_ra8_hcdc_breq_get_descriptor
GET_DESCRIPTOR.
@ k_ra8_hcdc_breq_set_interface
SET_INTERFACE.
@ k_ra8_hcdc_desc_device
DEVICE descriptor.
@ k_ra8_hcdc_bm_std_dev_out
Std | Device | Out.
@ k_ra8_hcdc_bm_std_iface_out
Std | Interface | Out.
@ k_ra8_hcdc_desc_interface
INTERFACE descriptor.
@ k_ra8_hcdc_desc_configuration
CONFIGURATION descriptor.
static ra8_err_t internal_do_bus_reset(void)
Step handler – bus-reset release + SETUP for SET_ADDRESS.
ra8_err_t ra8_usb_hcdc_attach_callback(ra8_usb_hcdc_attach_fn_t on_attach, void *ctx)
Register (or detach) the attach callback.
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_err_t ra8_usb_hcdc_init(ra8_usb_speed_t speed)
Bring up the host-CDC driver on a chosen USB controller.
ra8_usb_hcdc_step_t
Enumeration step machine states.
@ k_ra8_hcdc_step_set_config
SET_CONFIGURATION (1).
@ k_ra8_hcdc_step_done
Attach callback fires.
@ k_ra8_hcdc_step_get_dev_desc
GET_DEVICE_DESCRIPTOR (18 B).
@ k_ra8_hcdc_step_walk_desc
Find CDC IFs; populate pipes.
@ k_ra8_hcdc_step_get_cfg_desc
GET_CONFIGURATION_DESCRIPTOR.
@ k_ra8_hcdc_step_set_interface
SET_INTERFACE (0).
@ k_ra8_hcdc_step_idle
Pre-attach.
@ k_ra8_hcdc_step_set_address
SET_ADDRESS to assigned 1.
@ k_ra8_hcdc_step_bus_reset
Drive USBRST then release.
ra8_usb_hcdc_baud_min_t
Minimum legal baud the host driver allows.
@ k_ra8_hcdc_baud_min
0 baud is rejected as bogus.
ra8_err_t ra8_usb_hcdc_step(void)
Drive the enumeration step machine forward by one step.
ra8_err_t ra8_usb_hcdc_send(const uint8_t *data, uint16_t len)
Send a chunk of bytes OUT to the attached CDC-ACM device.
ra8_usb_hcdc_byte_shift_t
Per-byte left-shift constants for little-endian baud serialisation.
@ k_ra8_hcdc_shift_byte3
RA8 hcdc shift byte3.
@ k_ra8_hcdc_shift_byte0
RA8 hcdc shift byte0.
@ k_ra8_hcdc_shift_byte2
RA8 hcdc shift byte2.
@ k_ra8_hcdc_shift_byte1
RA8 hcdc shift byte1.
static ra8_err_t internal_do_walk_desc(void)
Step handler – finalise pipes + fire attach callback.
ra8_err_t ra8_usb_hcdc_close(void)
Tear down the host-CDC driver and release the controller.
ra8_usb_hcdc_size_t
Standard descriptor sizes and request payload sizes.
@ k_ra8_hcdc_assigned_address
First assigned device addr.
@ k_ra8_hcdc_dev_desc_len
USB DEVICE descriptor.
@ k_ra8_hcdc_default_config
bConfigurationValue = 1.
@ k_ra8_hcdc_iface_desc_len
INTERFACE descriptor.
@ k_ra8_hcdc_line_coding_len
SET_LINE_CODING payload.
@ k_ra8_hcdc_ep_desc_len
ENDPOINT descriptor.
@ k_ra8_hcdc_cfg_desc_len
CONFIGURATION descriptor hdr.
static uint16_t internal_bulk_max_packet(ra8_usb_speed_t speed)
Pick the bulk-max-packet ceiling matching the negotiated speed.
ra8_err_t ra8_usb_hcdc_recv(uint8_t *out_buf, uint16_t max_len, uint16_t *got_len)
Drain a chunk of bytes IN from the attached CDC-ACM device.
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 three host-CDC pipes against the attached device's endpoints.
Native USB host-side CDC ACM (Communications Device Class -Abstract Control Model) class layer.
@ k_ra8_hcdc_intr_max_packet
Notification pipe size.
@ k_ra8_hcdc_bulk_max_packet_hs
Bulk size at high speed.
@ k_ra8_hcdc_bulk_max_packet_fs
Bulk size at full speed.
ra8_usb_hcdc_parity_t
Parity selector used by ra8_usb_hcdc_set_line_coding.
@ k_ra8_hcdc_parity_space
Space parity.
void(* ra8_usb_hcdc_attach_fn_t)(void *ctx, const ra8_usb_hcdc_device_t *device)
Attach-callback signature.
@ k_ra8_hcdc_pipe_bulk_in
PIPE1 -> attached EP bulk IN.
@ k_ra8_hcdc_pipe_intr_in
PIPE6 -> attached EP intr IN.
@ k_ra8_hcdc_pipe_bulk_out
PIPE2 -> attached EP bulk OUT.
ra8_usb_hcdc_stop_bits_t
Stop-bit selector used by ra8_usb_hcdc_set_line_coding.
@ k_ra8_hcdc_stop_2
2 stop bits.
@ k_ra8_hcdc_req_set_line_coding
7-byte payload.
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 CDC-ACM device, passed to the attach callback.
Singleton shadow state for the host-CDC driver.
ra8_usb_hcdc_device_t device
Snapshot of attached device.
void * attach_ctx
Attach callback ctx.
bool initialized
True after ra8_usb_hcdc_init.
bool attached
True after enumeration done.
ra8_usb_hcdc_attach_fn_t attach_cb
Attach callback, or NULL.
ra8_usb_hcdc_step_t step
Current enumeration step.
ra8_usb_speed_t speed
Underlying controller.
Decoded 8-byte USB SETUP packet.