rcbench
Servo and ESC test bench: panel, IOmcu and shared C
Loading...
Searching...
No Matches
ui_pinlist.h File Reference

A pin's name and a set of pins as text for a screen label or a report: "GPIO 13", "GPIO 2 GPIO 4 +2". More...

#include <stddef.h>
#include <stdint.h>

Go to the source code of this file.

Macros

#define UI_PINLIST_PINS   64u
 Pins the formatter can name: bit n of the mask is GPIO n, n = 0 to 63.
#define UI_PIN_WORD   "GPIO"
 The word a pin's name starts with, the same in every language.
#define UI_PIN_NAME_SIZE   8u
 The bytes the longest pin name takes, "GPIO 63" and its NUL.

Functions

size_t ui_pin_name (char *out, size_t size, unsigned gpio)
 Writes the name of pin gpio into out: the pin word, a space and the number, "GPIO 13".
size_t ui_pinlist (char *out, size_t size, uint64_t mask, unsigned cells)
 Writes the pins of mask, lowest first, as "GPIO 2 GPIO 4 GPIO 5", each as ui_pin_name() names it, into out.
unsigned ui_pinlist_count (uint64_t mask)
 The number of pins in mask.

Detailed Description

A pin's name and a set of pins as text for a screen label or a report: "GPIO 13", "GPIO 2 GPIO 4 +2".

Pure functions, no drawing and no I/O (input/output). Every screen and report that names a pin formats it here, so a pin reads the same everywhere. A text table entry that names a pin writes the same form, "GPIO %u": test_text fails on any entry of ui_text.def, English or German, with "GP" directly followed by a digit or a conversion.

SPDX-License-Identifier: MIT

Function Documentation

◆ ui_pin_name()

size_t ui_pin_name ( char * out,
size_t size,
unsigned gpio )

Writes the name of pin gpio into out: the pin word, a space and the number, "GPIO 13".

The text is cut to size - 1 characters, as snprintf() cuts it.

Parameters
outWhere the text goes; NULL writes nothing.
sizeThe bytes at out; 0 writes nothing.
gpioThe pin, 0 to UI_PINLIST_PINS - 1. A higher number (a screen's NO_PIN, 0xFF) is no pin and writes "".
Returns
The length of the text written, not counting the terminator; 0 for no pin, a NULL out or a size of 0.

◆ ui_pinlist()

size_t ui_pinlist ( char * out,
size_t size,
uint64_t mask,
unsigned cells )

Writes the pins of mask, lowest first, as "GPIO 2 GPIO 4 GPIO 5", each as ui_pin_name() names it, into out.

The text is at most cells characters (one character is one cell of the monospaced face the caller draws it in: a TARGET row in 8 x 16 or 10 x 20, ui_target_row_cells()) and at most size - 1 characters. When all pins do not fit, the list shows as many leading pins as fit, then "+N" with N the pins left out: "GPIO 2 GPIO 4 +2". When not even one pin and the count fit, the text is "+N" alone. When "+N" itself is wider than cells, the text is cut to cells characters.

Parameters
outWhere the text goes; NULL writes nothing.
sizeThe bytes at out; 0 writes nothing.
maskThe pins, bit n for GPIO n; 0 writes "".
cellsThe cells the text may take.
Returns
The length of the text written, not counting the terminator; 0 for an empty mask, a NULL out or a size of 0.

◆ ui_pinlist_count()

unsigned ui_pinlist_count ( uint64_t mask)

The number of pins in mask.

Parameters
maskThe pins, bit n for GPIO n.
Returns
Its set bits.