ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
usb_selftest_hid_console.c File Reference

USB HID self-loop console formatters (SCI8 -> J-Link OB CDC). More...

#include <stddef.h>
#include <stdint.h>
#include "ra8_board_ek_ra8d2.h"
#include "ra8_err.h"
#include "usb_selftest_hid_steps.h"
Include dependency graph for usb_selftest_hid_console.c:

Go to the source code of this file.

Enumerations

enum  hid_mask_t : uint32_t {
  k_hid_nibble_mask = 0xFU ,
  k_hid_dec_radix = 10U
}
 Bit-mask constants used by the text formatters. More...

Functions

static uint8_t hid_nibble_to_hex (uint32_t nibble)
 Format one nibble (0..15) into an uppercase hex character.
static uint32_t hid_str_len (const char *text)
 Bounded ASCII string length (cap k_hid_print_cap).
static ra8_err_t hid_sci_write (const uint8_t *data, uint32_t len)
 Push a literal block over SCI8 polled.
ra8_err_t hid_print (const char *text)
 Print a NUL-terminated ASCII string over the console.
ra8_err_t hid_print_dec (uint32_t value)
 Print a uint32_t as ASCII decimal.
ra8_err_t hid_print_hex (uint32_t value, uint8_t digits)
 Print a value as fixed-width uppercase hex.
ra8_err_t hid_print_fail (const char *what, ra8_err_t err)
 Print "FAIL <what> err=0xNNNNNNNN" on its own line.

Detailed Description

USB HID self-loop console formatters (SCI8 -> J-Link OB CDC).

Tag
[Ring 6 / APP] {World: S}

The console-formatter cluster split out of the usb_selftest_hid main translation unit: the polled SCI8 text helpers that stream verdicts over the J-Link OB CDC bridge. These are pure formatting routines (bounded decimal / fixed-width hex / one-line FAIL diagnostics) with no USBX or ThreadX dependency; they live behind the off-target guard solely because the application as a whole is hardware-only.

The public entry points (hid_print, hid_print_dec, hid_print_hex, hid_print_fail) are declared in usb_selftest_hid_steps.h and consumed by both main.c and the host cluster.

Author
Brighton Sikarskie
Date
2026-06-13
Since
0.1.0

Definition in file usb_selftest_hid_console.c.

Enumeration Type Documentation

◆ hid_mask_t

enum hid_mask_t : uint32_t

Bit-mask constants used by the text formatters.

Enumerator
k_hid_nibble_mask 

4-bit nibble mask.

k_hid_dec_radix 

Base for decimal conversion.

Definition at line 40 of file usb_selftest_hid_console.c.

Function Documentation

◆ hid_nibble_to_hex()

uint8_t hid_nibble_to_hex ( uint32_t nibble)
static

Format one nibble (0..15) into an uppercase hex character.

Standard '0'-'9' then 'A'-'F' mapping.

Parameters
[in]nibble4-bit value.
Returns
ASCII '0'..'9' or 'A'..'F'.
Return values
'0'For a zero nibble.
Precondition
Caller has masked the value to 4 bits.
None beyond the mask contract.
Postcondition
Returned byte is printable hex.
No state changes.
Note
Pure function.
Since
0.1.0

Definition at line 63 of file usb_selftest_hid_console.c.

References k_hid_hex_digit_split.

Referenced by hid_print_hex().

◆ hid_print()

ra8_err_t hid_print ( const char * text)
nodiscard

Print a NUL-terminated ASCII string over the console.

Parameters
[in]textString to print (CR/LF included by the caller).
Returns
ra8_err_t propagated from the SCI helper.
Return values
k_ra8_okAll bytes queued.
Precondition
SCI8 init already ran; text is non-NULL.
text is NUL-terminated within k_hid_print_cap bytes.
Postcondition
The string bytes are in the SCI8 TX FIFO.
No other state changes.
Note
Blocking polled TX.
Since
0.1.0

Definition at line 125 of file usb_selftest_hid_console.c.

References hid_sci_write(), hid_sci_write(), hid_str_len(), and hid_str_len().

Referenced by hid_host_pass(), hid_host_pass(), hid_print_enum(), hid_print_enum(), hid_print_fail(), hid_print_pass(), and hid_print_pass().

◆ hid_print_dec()

ra8_err_t hid_print_dec ( uint32_t value)
nodiscard

Print a uint32_t as ASCII decimal.

Parameters
[in]valueValue to print.
Returns
ra8_err_t propagated from the SCI helper.
Return values
k_ra8_okAll bytes queued.
Precondition
SCI8 init already ran.
None beyond console readiness.
Postcondition
One ASCII decimal token is in the SCI8 TX FIFO.
No other state changes.
Note
Blocking polled TX.
Since
0.1.0

Definition at line 130 of file usb_selftest_hid_console.c.

References hid_sci_write(), hid_sci_write(), k_hid_dec_chars_u32, and k_hid_dec_radix.

Referenced by hid_print_pass(), and hid_print_pass().

◆ hid_print_fail()

ra8_err_t hid_print_fail ( const char * what,
ra8_err_t err )
nodiscard

Print "FAIL <what> err=0xNNNNNNNN" on its own line.

Parameters
[in]whatShort description of the failed step.
[in]errError code returned by the step.
Returns
ra8_err_t propagated from the SCI helpers.
Return values
k_ra8_okThe diagnostic line is queued.
Precondition
SCI8 init already ran.
what is NUL-terminated within the print cap.
Postcondition
One diagnostic line is in the SCI8 TX FIFO.
No other state changes.
Note
Blocking polled TX.
Since
0.1.0

Definition at line 168 of file usb_selftest_hid_console.c.

References hid_print(), hid_print_hex(), k_hid_hex_chars_u32, and k_ra8_ok.

Referenced by hid_enumerate(), hid_enumerate(), hid_host_pass(), hid_host_pass(), hid_read_round(), and hid_read_round().

◆ hid_print_hex()

ra8_err_t hid_print_hex ( uint32_t value,
uint8_t digits )
nodiscard

Print a value as fixed-width uppercase hex.

Parameters
[in]valueValue to print.
[in]digitsHex digit count (4 for u16, 8 for u32).
Returns
ra8_err_t propagated from the SCI helper.
Return values
k_ra8_okAll bytes queued.
Precondition
SCI8 init already ran.
digits is at most k_hid_hex_chars_u32.
Postcondition
One fixed-width hex token is in the SCI8 TX FIFO.
No other state changes.
Note
Blocking polled TX.
Since
0.1.0

Definition at line 154 of file usb_selftest_hid_console.c.

References hid_nibble_to_hex(), hid_nibble_to_hex(), hid_sci_write(), hid_sci_write(), k_hid_hex_chars_u32, k_hid_nibble_bits, and k_hid_nibble_mask.

Referenced by hid_print_enum(), hid_print_enum(), and hid_print_fail().

◆ hid_sci_write()

ra8_err_t hid_sci_write ( const uint8_t * data,
uint32_t len )
staticnodiscard

Push a literal block over SCI8 polled.

Thin wrapper fixing the console channel.

Parameters
[in]dataBuffer to send.
[in]lenByte count.
Returns
ra8_err_t passthrough from ra8_board_uart_console_write.
Return values
k_ra8_okAll bytes queued.
Precondition
data is non-NULL; the BSP console init already ran.
len excludes any NUL terminator.
Postcondition
Bytes are in the SCI8 TX FIFO.
No other state changes.
Note
Blocking polled TX.
Since
0.1.0

Definition at line 120 of file usb_selftest_hid_console.c.

References ra8_board_uart_console_write().

Referenced by hid_print(), hid_print_dec(), and hid_print_hex().

◆ hid_str_len()

uint32_t hid_str_len ( const char * text)
static

Bounded ASCII string length (cap k_hid_print_cap).

Linear scan with a hard upper bound.

Parameters
[in]textNUL-terminated string.
Returns
Number of bytes before the NUL, capped.
Return values
0For an empty string.
Precondition
text is non-NULL.
text points to readable storage of at least the length.
Postcondition
No state changes.
Return value never exceeds k_hid_print_cap.
Note
Bounded scan.
Since
0.1.0

Definition at line 89 of file usb_selftest_hid_console.c.

References k_hid_print_cap.

Referenced by hid_print().