32static const char*
s_tag =
"USBPPRN";
48typedef enum : uint8_t {
60typedef enum : uint8_t {
62 (uint8_t)((1U << 4U) | (1U << 3U)),
241 const uint8_t* device_id,
242 uint16_t device_id_len)
248 if (desc_len == 0U) {
252 const bool id_ptr_set = (device_id !=
nullptr);
253 const bool id_len_set = (device_id_len != 0U);
254 if (id_ptr_set != id_len_set) {
260 s_state.device_id_len = device_id_len;
279 uint16_t inout_len = max_len;
283 *got_len = inout_len;
295 if ((data ==
nullptr) && (len != 0U)) {
298 if ((len == 0U) || (len >
s_state.bulk_max_packet)) {
314 s_state.port_status = status_byte;
324 *out_status =
s_state.port_status;
364 if (
s_state.setup_cb !=
nullptr) {
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_not_supported
Requested feature not compiled in, not wired, or not supported by this MCU variant.
@ 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_bulk
Bulk 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_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.
ra8_err_t ra8_usb_pprn_get_port_status(uint8_t *out_status)
Read the current port-status byte.
ra8_err_t ra8_usb_pprn_set_descriptors(const uint8_t *desc, uint16_t desc_len, const uint8_t *device_id, uint16_t device_id_len)
Install the caller-supplied descriptor blob and IEEE 1284 device-ID string.
ra8_err_t ra8_usb_pprn_handle_setup(const ra8_usb_setup_t *setup)
Process a class-specific SETUP packet on EP0.
ra8_usb_pprn_default_status_t
Spec defaults the class layer seeds at init.
@ k_ra8_pprn_default_port_status
RA8 pprn default port status.
ra8_err_t ra8_usb_pprn_recv(uint8_t *buf, uint16_t max_len, uint16_t *got_len)
Drain inbound print-job data from the bulk-OUT endpoint.
ra8_usb_pprn_setup_field_t
Constants used to recognise printer class-specific SETUPs.
@ k_ra8_pprn_bm_class_iface_in
Class | Iface | In.
@ k_ra8_pprn_bm_class_iface_out
Class | Iface | Out.
ra8_err_t ra8_usb_pprn_attach_setup_handler(ra8_usb_pprn_setup_fn_t setup_fn, void *ctx)
Register the application's printer class-setup handler.
static void internal_reset_shadow(ra8_usb_speed_t speed)
Reset shadow state to spec defaults.
static bool internal_is_known_class_request(uint8_t b_request)
Recognise a printer class request code we forward.
ra8_err_t ra8_usb_pprn_init(ra8_usb_speed_t speed)
Bring up the device-Printer function on a chosen USB controller.
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_pprn_set_port_status(uint8_t status_byte)
Update the local port-status byte returned by GET_PORT_STATUS.
ra8_err_t ra8_usb_pprn_close(void)
Tear down the device-Printer function and release the controller.
ra8_err_t ra8_usb_pprn_send(const uint8_t *data, uint16_t len)
Push outbound printer-status bytes on the bulk-IN endpoint.
Native USB device-side Printer class layer.
@ k_ra8_pprn_pipe_bulk_in
PIPE4 -> EP2 IN (status).
@ k_ra8_pprn_pipe_bulk_out
PIPE3 -> EP1 OUT (print data).
ra8_err_t(* ra8_usb_pprn_setup_fn_t)(void *ctx, const ra8_usb_setup_t *setup)
Caller-supplied printer class-setup handler signature.
@ k_ra8_pprn_bulk_max_packet_fs
Bulk size at FS.
@ k_ra8_pprn_bulk_max_packet_hs
Bulk size at HS.
@ k_ra8_pprn_ep_bulk_in_addr
EP2 IN address.
@ k_ra8_pprn_ep_bulk_out_addr
EP1 OUT address.
@ k_ra8_pprn_req_soft_reset
SOFT_RESET.
@ k_ra8_pprn_req_get_device_id
GET_DEVICE_ID.
@ k_ra8_pprn_req_get_port_status
GET_PORT_STATUS.
Singleton shadow state for the device-Printer function.
bool initialized
True after init.
uint16_t desc_len
Descriptor blob byte len.
void * setup_ctx
Class handler context.
uint8_t port_status
Current port-status byte.
const uint8_t * device_id
Cached device-ID payload.
uint16_t device_id_len
Device-ID byte length.
ra8_usb_pprn_setup_fn_t setup_cb
Application class handler.
ra8_usb_speed_t speed
Underlying controller.
const uint8_t * desc
Cached descriptor blob.
uint16_t bulk_max_packet
Pipe max-packet size.
Decoded 8-byte USB SETUP packet.
uint8_t b_request
bRequest code.
uint8_t bm_request_type
Request direction / type / recipient.