This library provides a small API to encode a range of supported ASCII characters into the individual segment values that the downstream can then use to drive a 7-segment display. This can be used in pretty much any environment and is written conforming to C99.
See ascii7seg.h
for the types and API, but to repeat them briefly here, the primary type you'll work with is Ascii7Seg_Encoding_U
(a union type), which will give you the individual segment values or the entire encoding as a single variable (hence the union type), and the following API is available to you:
bool Ascii7Seg_ConvertChar( char ascii_char, union Ascii7Seg_Encoding_U * buf );
size_t Ascii7Seg_ConvertWord( const char * str,
size_t str_len,
union Ascii7Seg_Encoding_U * buf );
bool Ascii7Seg_IsSupportedChar( char ascii_char );
The macros present within ascii7seg_config.h
allow you to configure which of the following 3 ranges you want this library to support (at compile time). The smaller the range, the better the speed and space performance. By default, the maximum range is what is supported if you choose to do nothing in ascii7seg_config.h
.
- Numerical Digits Only:
0
to9
- Numerical Digits +
"Error"
(both capital and lowercase) - Full Range: (72 characters supported)
0 - 9
A - Z
anda - z
(not every character will be rendered beautifully)- Symbols:
[ ] ( ) _ - | = > <
In addition, the internal implementation of the encoding is optionally configurable (at compile-time), using the macros present within ascii7seg_config.h
. Specifically, you can change
- the range of supported characters,
- whether a lookup table is used or a computation (speed vs space) - see benchmark/profiling section,
- and how you want the encoding available to you within
Ascii7Seg_Encoding_U
(bit-packed or separatebool
's)
You'd simply set the macros as you like and then rebuild the library for your architecture. The idea behind this flexibility is to allow you, the user, to prioritize speed vs space. Again, this is optional and by default, speed is prioritized (lookup tables are used and the encoding is not bit-packed) for the full range of conceivable ASCII characters on a 7-segment display.
In the near future, I will place the various build artifacts produced here into a package and publish that to some package management system that you can then conveniently pull in, but for now, you may:
-
Download the static library file for your target in the Releases page of this repository. I try to include as many possible target environments as I can there, but this is not exhaustive.
-
Build the Static Library Yourself: Clone this repo and run
make lib
if you are building for a desktop environment ormake libmcu
to build for an MCU target (you'll need to configuremcu_opts.mk
).- Presently, only ARM-based MCUs are supported, but you may also just copy the necessary files into your own build environment and build away 🏗️.
- You'll need GCC to build for a desktop environment and the Arm GNU Toolchain to build for the ARM MCU targets.
- Make
- Additionally, to utilize the full build process I am using, you'll need:
- Python3
- cppcheck
-
Copy the Necessary Files / Git Submodule: You'll want
ascii7seg.c
,ascii7seg.h
, andascii7seg_config.h
(modified to your needs if desired). See theascii7seg_config.h
for details on the configuration supported.
TODO
Please see the CODING_PRINCIPLES.md
file for my philosophy and the software engineering principles/practices that help me produce what I see as quality code.
- Run the unit tests by running
make test
- Run a build of all variations for an ARM mcu using
make test-mcu-builds
- TODO: Run a build against non-GCC compilers against all variants using
make test-compiler-builds
-
I would like to give a shoutout to @dmadison for the very useful images that he provided in
dmadison/LED-Segment-ASCII
. I specifically borrowedSegment-Labels.png
and7-Segment - All Supported Chars.png
. -
Shoutout as well to the Linux Handbook. I borrowed their image of the ASCII table:
ASCII Table - The Linux Handbook.png
.