|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Native USB device-side Vendor-defined class layer implementation. More...
#include "ra8_usb_pvnd.h"#include <stdint.h>#include "ra8_attributes.h"#include "ra8_check.h"#include "ra8_err.h"#include "ra8_log.h"#include "ra8_usb.h"Go to the source code of this file.
Data Structures | |
| struct | ra8_usb_pvnd_state_t |
| Singleton shadow state for the device-Vendor function. More... | |
Functions | |
| static uint16_t | internal_bulk_max_packet (ra8_usb_speed_t speed) |
| Pick the bulk-max-packet ceiling matching the negotiated speed. | |
| static void | internal_configure_pipes (ra8_usb_speed_t speed) |
| Configure the two bulk pipes. | |
| static void | internal_reset_shadow (ra8_usb_speed_t speed) |
| Reset shadow state to spec defaults. | |
| static bool | internal_is_vendor_envelope (uint8_t bm) |
| Recognise a vendor-recipient SETUP envelope. | |
| ra8_err_t | ra8_usb_pvnd_init (ra8_usb_speed_t speed) |
| Bring up the device-Vendor function on a chosen USB controller. | |
| ra8_err_t | ra8_usb_pvnd_close (void) |
| Tear down the device-Vendor function and release the controller. | |
| ra8_err_t | ra8_usb_pvnd_set_descriptors (const uint8_t *desc, uint16_t desc_len) |
| Install the caller-supplied descriptor blob. | |
| ra8_err_t | ra8_usb_pvnd_send (const uint8_t *data, uint16_t len) |
| Push a payload on the vendor bulk-IN endpoint. | |
| ra8_err_t | ra8_usb_pvnd_recv (uint8_t *buf, uint16_t max_len, uint16_t *got_len) |
| Drain a payload from the vendor bulk-OUT endpoint. | |
| ra8_err_t | ra8_usb_pvnd_attach_setup_handler (ra8_usb_pvnd_setup_fn_t setup_fn, void *ctx) |
| Register the application's vendor setup handler. | |
| ra8_err_t | ra8_usb_pvnd_handle_setup (const ra8_usb_setup_t *setup) |
| Process a vendor-specific SETUP packet on EP0. | |
Variables | |
| static const char * | s_tag = "USBPVND" |
| static ra8_usb_pvnd_state_t | s_state = {} |
Native USB device-side Vendor-defined class layer implementation.
Glues the device-mode ra8_usb driver to a vendor-defined function (class 0xFF) so the EK-RA8D2 can carry application-specific protocols over raw bulk pipes. This file is the native peripheral- Vendor class layer; FSP's r_usb_vendor_descriptor.c.template is reference material only.
Reference: USB 2.0 sec 9.3 "USB Device Requests" (vendor request envelope encoding).
Definition in file ra8_usb_pvnd.c.
|
static |
Pick the bulk-max-packet ceiling matching the negotiated speed.
See implementation.
| [in] | speed | See implementation. |
speed. | k_ra8_pvnd_bulk_max_packet_hs | speed is k_ra8_usb_speed_hs. |
| k_ra8_pvnd_bulk_max_packet_fs | Any other speed. |
Definition at line 76 of file ra8_usb_pvnd.c.
References k_ra8_pvnd_bulk_max_packet_fs, k_ra8_pvnd_bulk_max_packet_hs, and k_ra8_usb_speed_hs.
Referenced by internal_configure_pipes(), and internal_reset_shadow().
|
static |
Configure the two bulk pipes.
See implementation.
| [in] | speed | See implementation. |
Definition at line 95 of file ra8_usb_pvnd.c.
References internal_bulk_max_packet(), k_ra8_pvnd_ep_bulk_in_addr, k_ra8_pvnd_ep_bulk_out_addr, k_ra8_pvnd_pipe_bulk_in, k_ra8_pvnd_pipe_bulk_out, k_ra8_usb_ep_dir_in, k_ra8_usb_ep_dir_out, k_ra8_usb_ep_type_bulk, and ra8_usb_configure_endpoint().
|
static |
Recognise a vendor-recipient SETUP envelope.
Per USB 2.0 sec 9.3 "USB Device Requests", the type field is bits 6:5 of bmRequestType. 0b10 = vendor.
| [in] | bm | See implementation. |
| k_ra8_ok | Operation succeeded. |
Definition at line 155 of file ra8_usb_pvnd.c.
References k_ra8_pvnd_bm_vendor_dev_in, k_ra8_pvnd_bm_vendor_dev_out, k_ra8_pvnd_bm_vendor_ep_in, k_ra8_pvnd_bm_vendor_ep_out, k_ra8_pvnd_bm_vendor_iface_in, and k_ra8_pvnd_bm_vendor_iface_out.
Referenced by ra8_usb_pvnd_handle_setup().
|
static |
Reset shadow state to spec defaults.
See implementation.
| [in] | speed | See implementation. |
Definition at line 128 of file ra8_usb_pvnd.c.
References internal_bulk_max_packet(), and s_state.
Referenced by ra8_usb_pvnd_init().
|
nodiscard |
Register the application's vendor setup handler.
Pass NULL for setup_fn to detach. The class layer pre-decodes the SETUP envelope and forwards it if its bmRequestType indicates a vendor-recipient request.
| [in] | setup_fn | Application's handler. NULL detaches. |
| [in] | ctx | Context pointer threaded back into setup_fn. |
| k_ra8_ok | Handler installed. |
| k_ra8_err_invalid_state | Driver not initialized. |
Definition at line 263 of file ra8_usb_pvnd.c.
References k_ra8_err_invalid_state, k_ra8_ok, and s_state.
Referenced by demo_usb_bringup().
|
nodiscard |
Tear down the device-Vendor function and release the controller.
| k_ra8_ok | Released. |
| k_ra8_err_invalid_state | Driver was never initialized. |
Definition at line 185 of file ra8_usb_pvnd.c.
References k_ra8_err_invalid_state, ra8_usb_device_attach(), ra8_usb_device_deinit(), and s_state.
|
nodiscard |
Process a vendor-specific SETUP packet on EP0.
The class layer accepts every bmRequestType whose type field is 0b10 (vendor) and forwards the SETUP to the registered application handler. If no handler is registered, the SETUP is stalled. Standard / class SETUPs are rejected with k_ra8_err_not_supported so the caller can fall back to its own standard / class handler.
| [in] | setup | The SETUP packet returned by ra8_usb_read_setup_if_valid. |
| k_ra8_ok | SETUP handled (status stage queued internally). |
| k_ra8_err_invalid_state | Driver not initialized. |
| k_ra8_err_null_ptr | setup was NULL. |
| k_ra8_err_not_supported | bmRequestType is not a vendor envelope. |
Definition at line 278 of file ra8_usb_pvnd.c.
References ra8_usb_setup_t::bm_request_type, internal_is_vendor_envelope(), k_ra8_err_invalid_state, k_ra8_err_not_supported, k_ra8_ok, RA8_CHECK_NULL_PTR, ra8_usb_control_response(), s_state, and s_tag.
Referenced by demo_dispatch_setup().
|
nodiscard |
Bring up the device-Vendor function on a chosen USB controller.
Initialises the underlying ra8_usb driver in DEVICE mode for speed, configures PIPE5 (bulk IN) and PIPE1 (bulk OUT), and leaves the D+ pull-up dropped. The caller raises it via ra8_usb_device_attach once descriptors are set.
| [in] | speed | Which USB controller (FS or HS). |
| k_ra8_ok | Device-Vendor ready. |
| k_ra8_err_invalid_arg | speed out of range. |
| k_ra8_err_hw_init_failed | Underlying ra8_usb_device_init failed. |
Definition at line 167 of file ra8_usb_pvnd.c.
References internal_configure_pipes(), internal_reset_shadow(), k_ra8_err_hw_init_failed, k_ra8_err_invalid_arg, k_ra8_ok, k_ra8_usb_speed_fs, k_ra8_usb_speed_hs, ra8_log_error_val, ra8_log_info_val, ra8_usb_device_init(), s_state, and s_tag.
Referenced by demo_usb_bringup().
|
nodiscard |
Drain a payload from the vendor bulk-OUT endpoint.
| [out] | buf | Receive buffer. |
| [in] | max_len | Capacity of buf, > 0. |
| [out] | got_len | Receives the number of bytes actually placed. |
| k_ra8_ok | Bytes drained. |
| k_ra8_err_no_data | Pipe was empty. |
| k_ra8_err_null_ptr | buf or got_len was NULL. |
| k_ra8_err_invalid_state | Driver not initialized. |
| k_ra8_err_invalid_arg | max_len == 0. |
Definition at line 237 of file ra8_usb_pvnd.c.
References k_ra8_err_invalid_arg, k_ra8_err_invalid_state, k_ra8_ok, k_ra8_pvnd_pipe_bulk_out, RA8_CHECK_NULL_PTR, ra8_usb_queue_out(), s_state, and s_tag.
Referenced by demo_drain_vendor().
|
nodiscard |
Push a payload on the vendor bulk-IN endpoint.
| [in] | data | Payload buffer. |
| [in] | len | Payload byte length. |
| k_ra8_ok | Bytes queued onto bulk-IN. |
| k_ra8_err_invalid_state | Driver not initialized. |
| k_ra8_err_null_ptr | data was NULL with len > 0. |
| k_ra8_err_invalid_arg | len == 0 or larger than the pipe max. |
Definition at line 223 of file ra8_usb_pvnd.c.
References k_ra8_err_invalid_arg, k_ra8_err_invalid_state, k_ra8_err_null_ptr, k_ra8_pvnd_pipe_bulk_in, ra8_usb_queue_in(), and s_state.
Referenced by demo_drain_vendor().
|
nodiscard |
Install the caller-supplied descriptor blob.
The blob is concatenation of configuration / interface / bulk EP descriptors. The class layer keeps just a pointer + length pair; the caller owns the storage.
| [in] | desc | Pointer to the caller-owned descriptor blob. |
| [in] | desc_len | Byte length of desc. |
| k_ra8_ok | Pointer + length stored. |
| k_ra8_err_invalid_state | Driver not initialized. |
| k_ra8_err_null_ptr | desc was NULL. |
| k_ra8_err_invalid_arg | desc_len == 0. |
Definition at line 204 of file ra8_usb_pvnd.c.
References k_ra8_err_invalid_arg, k_ra8_err_invalid_state, k_ra8_ok, RA8_CHECK_NULL_PTR, s_state, and s_tag.
Referenced by demo_usb_bringup().
|
static |
Definition at line 53 of file ra8_usb_pvnd.c.
|
static |
Definition at line 32 of file ra8_usb_pvnd.c.