ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_io_stream_usbcdc.c
Go to the documentation of this file.
1
16
18
19#include <stdint.h>
20
21#include "ra8_attributes.h"
22#include "ra8_check.h"
23#include "ra8_err.h"
25#include "ra8_usb_pal.h"
26
28static const char* const s_tag = "ra8_io_stream_usbcdc";
29
36typedef enum : uint32_t {
39
67internal_usbcdc_write(void* ctx, const uint8_t* buf, uint32_t len, uint32_t* out_written)
68{
69 RA8_CHECK_NULL_PTR(ctx, s_tag, "ctx must not be nullptr");
70 RA8_CHECK_NULL_PTR(buf, s_tag, "buf must not be nullptr");
72 uint32_t done = 0;
73 while (done < len) {
74 const uint32_t rem = len - done;
75 const uint32_t chunk =
76 (rem > (uint32_t)k_usbcdc_max_chunk) ? (uint32_t)k_usbcdc_max_chunk : rem;
77 const ra8_err_t e = ra8_usb_pal_ep_send(st->ep_addr, &buf[done], (uint16_t)chunk);
78 if (e != k_ra8_ok) {
79 if (out_written != nullptr) {
80 *out_written = done;
81 }
82 return e;
83 }
84 done += chunk;
85 }
86 if (out_written != nullptr) {
87 *out_written = len;
88 }
89 return k_ra8_ok;
90}
91
95 .write = internal_usbcdc_write,
96 .flush = nullptr,
97};
98
101{
102 RA8_CHECK_NULL_PTR(s, s_tag, "s must not be nullptr");
103 RA8_CHECK_NULL_PTR(state, s_tag, "state must not be nullptr");
104 state->ep_addr = ep_addr;
105 return ra8_io_stream_bind(s, &s_usbcdc_iface, state);
106}
static const char * s_tag
Logging / check tag.
Definition ra8_app.c:17
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.
Definition ra8_check.h:243
Error Code Definitions for ra8-firmware.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
Definition ra8_err.h:119
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Definition ra8_err.h:546
struct ra8_io_stream_iface ra8_io_stream_iface_t
Public implementer contract for ra8_io byte-stream backends.
ra8_err_t ra8_io_stream_bind(ra8_io_stream_t *stream, const ra8_io_stream_iface_t *iface, void *context)
Bind a backend vtable and caller-owned state into a stream handle.
ra8_err_t ra8_io_stream_usbcdc_init(ra8_io_stream_t *s, ra8_io_stream_usbcdc_state_t *state, uint8_t ep_addr)
Bind a USB-CDC stream sink into a caller-owned stream handle.
static ra8_err_t internal_usbcdc_write(void *ctx, const uint8_t *buf, uint32_t len, uint32_t *out_written)
USB-CDC sink: send all bytes through the bulk-IN endpoint.
static const ra8_io_stream_iface_t s_usbcdc_iface
USB-CDC stream sink vtable.
ra8_io_usbcdc_const_t
USB-CDC sink constants.
@ k_usbcdc_max_chunk
Largest single ra8_usb_pal_ep_send length.
ra8_io byte-stream sink over a USB-CDC endpoint.
USB device-mode Platform Abstraction Layer.
ra8_err_t ra8_usb_pal_ep_send(uint8_t ep_addr, const uint8_t *data, uint16_t len)
Submit data on an IN endpoint (device -> host).
Caller-allocated byte-stream handle binding a sink to its context.
Caller-owned private state for a USB-CDC stream sink.
uint8_t ep_addr
USB bulk-IN endpoint address (private).