49 return (event_fn !=
nullptr) && (mask != none_value);
69 return (ep_addr == 0U) || (ep_addr > ep_max);
72static const char*
s_tag =
"USBPAL";
79typedef enum : uint16_t {
157 for (uint16_t i = 0U; i < len; ++i) {
221 if (usb_mask != 0U) {
528 if (
s_state.event_fn !=
nullptr) {
575 if (*inout_len == 0U) {
582 if (slot->
count == 0U) {
586 const uint16_t n = (pkt->
len < *inout_len) ? pkt->
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_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_no_mem
Static buffer exhausted (no dynamic memory on this project).
@ 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.
@ 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_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_device_init(ra8_usb_speed_t speed)
Bring up a USB controller in device mode.
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_device_attach(ra8_usb_speed_t speed, bool attached)
Raise / drop the D+ pull-up to advertise the device to the host.
void ra8_usb_attach_handler(ra8_usb_speed_t speed, ra8_usb_event_fn_t fn, void *ctx)
Install (or detach) the per-controller USB event handler.
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).
@ k_ra8_usb_pal_ep_table_len
Index 0..ep_max, 1-based EPs.
@ k_ra8_usb_pal_pkt_max
Per-packet capacity.
@ k_ra8_usb_pal_ring_slots
Per-EP queue depth.
bool priv_usb_pal_ep_out_of_range(uint8_t ep_addr, uint8_t ep_max)
Pure ep-out-of-range predicate – see header for full contract.
static void internal_usb_event(void *ctx, ra8_usb_speed_t speed, uint16_t status_mask)
ra8_usb event handler – translate + forward to the PAL callback.
ra8_err_t ra8_usb_pal_init(ra8_usb_speed_t speed)
Bring up the USB PAL singleton at the requested speed.
ra8_err_t ra8_usb_pal_attach(bool attached)
Drive the D+ pull-up to attach or detach the device.
static void internal_copy_bytes(uint8_t *dst, const uint8_t *src, uint16_t len)
Copy len bytes (string.h-free local memcpy substitute).
ra8_err_t ra8_usb_pal_ep_open(uint8_t ep_addr, ra8_usb_pal_ep_dir_t dir, ra8_usb_pal_ep_type_t type, uint16_t max_packet)
Open one endpoint and reserve a per-EP packet ring.
ra8_err_t ra8_usb_pal_get_state(ra8_usb_pal_state_t *out_state)
Read the current PAL state machine.
static uint16_t internal_translate(uint16_t usb_mask)
Translate ra8_usb status mask -> PAL event mask.
ra8_err_t ra8_usb_pal_ep_recv(uint8_t ep_addr, uint8_t *out_buf, uint16_t *inout_len)
Pull the next packet, if any, from an open OUT endpoint.
static void internal_reset_eps(void)
Reset every endpoint slot to empty / unopened.
ra8_err_t ra8_usb_pal_set_event_handler(ra8_usb_pal_event_fn_t fn, void *ctx)
Install a single event handler for bus and per-EP events.
ra8_err_t ra8_usb_pal_ep_send(uint8_t ep_addr, const uint8_t *data, uint16_t len)
Queue a packet for transmit on an open IN endpoint.
ra8_err_t ra8_usb_pal_deinit(void)
Tear down the USB PAL singleton.
bool priv_usb_pal_should_dispatch_event(const void *event_fn, uint16_t mask, uint16_t none_value)
Pure dispatch-event predicate – see header for full contract.
USB device-mode Platform Abstraction Layer.
ra8_usb_pal_ep_dir_t
Endpoint direction.
@ k_ra8_usb_pal_ep_dir_out
Host -> device.
@ k_ra8_usb_pal_ep_dir_in
Device -> host.
@ k_ra8_usb_pal_ep_addr_mask
Strip USB-IN dir bit (bit 7) from ep_addr.
@ k_ra8_usb_pal_xfer_max
Single-shot xfer cap.
@ k_ra8_usb_pal_ep_max
Maximum endpoint number.
ra8_usb_pal_ep_type_t
USB endpoint transfer type.
@ k_ra8_usb_pal_ep_type_control
RA8 USB pal ep type control.
@ k_ra8_usb_pal_ep_type_intr
RA8 USB pal ep type intr.
@ k_ra8_usb_pal_event_error
Controller error.
@ k_ra8_usb_pal_event_none
RA8 USB pal event none.
@ k_ra8_usb_pal_event_ep_in
IN endpoint complete.
void(* ra8_usb_pal_event_fn_t)(void *ctx, ra8_usb_speed_t speed, uint16_t event_mask)
Async event callback shape.
ra8_usb_pal_state_t
USB device state per chapter 9 of USB 2.0.
@ k_ra8_usb_pal_state_attached
D+ pull-up on, no reset.
@ k_ra8_usb_pal_state_detached
D+ pull-up off.
Test-access surface for ra8_usb_pal internal helpers (MC/DC).
Configuration + queue for one endpoint.
uint16_t count
In-flight packet count.
uint16_t head
Next slot to pop.
uint16_t max_packet
Stored max packet size.
ra8_usb_pal_packet_t ring[k_ra8_usb_pal_ring_slots]
Per-EP queue.
ra8_usb_pal_ep_type_t type
Stored transfer type.
uint16_t tail
Next slot to push.
ra8_usb_pal_ep_dir_t dir
Stored direction.
bool opened
True once ra8_usb_pal_ep_open fired.
One packet on a per-endpoint ring.
uint16_t len
0 == empty slot.
uint8_t data[k_ra8_usb_pal_pkt_max]
Packet payload bytes.
ra8_usb_pal_event_fn_t event_fn
Stack-installed callback.
ra8_usb_speed_t speed
FS or HS, set at init.
bool initialized
True after ra8_usb_pal_init.
ra8_usb_pal_state_t state
Detached/attached/...
ra8_usb_pal_ep_slot_t eps[k_ra8_usb_pal_ep_table_len]
Per-EP state.
void * event_ctx
Callback context.