39static const char*
s_tag =
"USBCDC";
45typedef enum : uint8_t {
71typedef enum : uint16_t {
79typedef enum : uint32_t {
88typedef enum : uint8_t {
99typedef enum : uint8_t {
165 const uint16_t bulk_mp =
186 "cdc: bulk-out cfg");
234 s_state.coding.dte_rate = baud;
308 if ((data ==
nullptr) && (len != 0U)) {
321 if (*inout_len == 0U) {
433 const uint16_t mask = setup->
w_value;
static const char * s_tag
Logging / check tag.
Annotation-attribute framework macros for ra8-firmware.
#define RA8_BOUNDED_LOOP(symbol)
NASA Power-of-10 Rule 2: every loop in a FUNCTION has a constant bound.
#define RA8_TEST_HELPER
Mark a symbol as externally-linked but only callable from tests.
#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_no_data
No application data available (e.g.
@ 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_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).
ra8_err_t ra8_usb_cdc_recv(uint8_t *out_buf, uint16_t *inout_len)
Drain a chunk of bytes OUT (host -> device).
static ra8_err_t internal_pull_data_stage(uint8_t *buf, uint16_t cap, uint16_t *out_len)
Pull the SET_LINE_CODING data stage off EP0 (DCP) once it lands.
ra8_usb_cdc_default_baud_t
9600 baud assembled from the two low bytes above.
@ k_ra8_cdc_default_baud
RA8 cdc default baud.
ra8_err_t ra8_usb_cdc_get_line_state(bool *out_dtr, bool *out_rts)
Get the most recently received DTR / RTS bits.
static void internal_default_coding(ra8_usb_cdc_line_coding_t *coding)
Internal helper.
ra8_err_t ra8_usb_cdc_handle_setup(const ra8_usb_setup_t *setup)
Process a class-specific SETUP packet.
static void internal_apply_line_coding(const uint8_t *data, uint16_t len)
Apply a host SET_LINE_CODING payload to the cached CDC line coding.
ra8_err_t ra8_usb_cdc_init(ra8_usb_speed_t speed)
Bring up the CDC ACM function on a chosen USB controller.
ra8_err_t ra8_usb_cdc_deinit(void)
Tear down the CDC function and release the underlying controller.
static ra8_err_t internal_dispatch_class_setup(const ra8_usb_setup_t *setup)
Decode a CDC class-specific SETUP packet body.
ra8_usb_cdc_data_stage_t
Bound on the polled control-OUT data-stage drain.
@ k_ra8_cdc_data_stage_polls
Max ra8_usb_dcp_out_read attempts.
ra8_err_t ra8_usb_cdc_get_line_coding(ra8_usb_cdc_line_coding_t *out)
Get the most recently negotiated line coding.
void ra8_usb_cdc_test_apply_line_coding(const uint8_t *data, uint16_t len)
Drive the private SET_LINE_CODING decoder from host tests.
ra8_err_t ra8_usb_cdc_attach(bool attached)
Raise / drop the D+ pull-up to advertise the CDC function.
ra8_err_t ra8_usb_cdc_send(const uint8_t *data, uint16_t len)
Send a chunk of bytes IN (device -> host).
ra8_usb_cdc_byte_idx_t
Indices into the 7-byte SET_LINE_CODING payload.
@ k_ra8_cdc_idx_data_bits
RA8 cdc index data bits.
@ k_ra8_cdc_idx_baud_b3
RA8 cdc index baud b3.
@ k_ra8_cdc_idx_char_format
RA8 cdc index char format.
@ k_ra8_cdc_idx_parity_type
RA8 cdc index parity type.
@ k_ra8_cdc_idx_baud_b2
RA8 cdc index baud b2.
@ k_ra8_cdc_idx_baud_b1
RA8 cdc index baud b1.
@ k_ra8_cdc_idx_baud_b0
RA8 cdc index baud b0.
ra8_usb_cdc_byte_shift_t
Per-byte left-shift constants for the little-endian baud accumulator in internal_apply_line_coding.
@ k_ra8_cdc_shift_byte2
RA8 cdc shift byte2.
@ k_ra8_cdc_shift_byte3
RA8 cdc shift byte3.
@ k_ra8_cdc_shift_byte0
RA8 cdc shift byte0.
@ k_ra8_cdc_shift_byte1
RA8 cdc shift byte1.
ra8_usb_cdc_setup_field_t
Constants used to decode CDC class-specific SETUPs.
@ k_ra8_cdc_default_stop_bits
1 stop bit.
@ k_ra8_cdc_default_data_bits
8 data bits.
@ k_ra8_cdc_bm_class_recip_in
Class | Interface | In.
@ k_ra8_cdc_line_coding_len
7-byte payload length.
@ k_ra8_cdc_bm_class_recip_iface
Class | Interface | Out.
@ k_ra8_cdc_default_parity_none
No parity.
Native USB CDC ACM (Communications Device Class - AbstractControl Model) class layer.
@ k_ra8_cdc_line_state_rts
Request to send.
@ k_ra8_cdc_line_state_dtr
Data terminal ready.
@ k_ra8_cdc_ep_bulk_in_addr
EP1 IN address.
@ k_ra8_cdc_ep_bulk_out_addr
EP2 OUT address.
@ k_ra8_cdc_ep_intr_in_addr
EP3 IN address.
@ k_ra8_cdc_pipe_intr_in
PIPE6 -> EP3 IN (interrupt).
@ k_ra8_cdc_pipe_bulk_in
PIPE1 -> EP1 IN (bulk).
@ k_ra8_cdc_pipe_bulk_out
PIPE2 -> EP2 OUT (bulk).
@ k_ra8_cdc_bulk_max_packet_fs
Bulk size at full speed.
@ k_ra8_cdc_bulk_max_packet_hs
Bulk size at high speed.
@ k_ra8_cdc_intr_max_packet
Notification pipe size.
@ k_ra8_cdc_req_set_line_coding
7-byte payload.
@ k_ra8_cdc_req_get_line_coding
7-byte payload.
@ k_ra8_cdc_req_set_control_line_state
0-byte payload.
Test-access surface for the USB CDC line-coding decoder.
ra8_err_t ra8_usb_dcp_out_arm(ra8_usb_speed_t speed)
Arm the DCP (EP0) to receive a host-to-device control data stage.
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_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_dcp_out_read(ra8_usb_speed_t speed, uint8_t *buf, uint16_t cap, uint16_t *out_rx)
Drain an armed control-OUT data stage from the DCP (EP0).
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.
7-byte payload of SET_LINE_CODING / GET_LINE_CODING.
uint32_t dte_rate
Baud rate in bits/sec.
uint8_t data_bits
5 / 6 / 7 / 8 / 16.
uint8_t parity_type
0=none, 1=odd, 2=even, ...
uint8_t char_format
0=1 stop, 1=1.5 stop, 2=2 stop.
Singleton shadow state for the CDC function.
bool initialized
True after ra8_usb_cdc_init.
ra8_usb_speed_t speed
Underlying controller.
ra8_usb_cdc_line_coding_t coding
Most recent line coding.
Decoded 8-byte USB SETUP packet.
uint8_t b_request
bRequest code.
uint8_t bm_request_type
Request direction / type / recipient.