Skip to content

memphis242/ascii7seg

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

96 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ASCII to 7-Segment Library libascii7seg 🔠 🔢

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 );

Range of Characters Supported

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.

  1. Numerical Digits Only: 0 to 9
  2. Numerical Digits + "Error" (both capital and lowercase)
  3. Full Range: (72 characters supported)
    • 0 - 9
    • A - Z and a - z (not every character will be rendered beautifully)
    • Symbols: [ ] ( ) _ - | = > <

Compile-Time Configuration

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 separate bool'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.

Usage

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:

  1. 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.

  2. Build the Static Library Yourself: Clone this repo and run make lib if you are building for a desktop environment or make libmcu to build for an MCU target (you'll need to configure mcu_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
  3. Copy the Necessary Files / Git Submodule: You'll want ascii7seg.c, ascii7seg.h, and ascii7seg_config.h (modified to your needs if desired). See the ascii7seg_config.h for details on the configuration supported.

Profiling & Benchmarking Space + Speed

TODO

Code Quality

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.

Testing Feedback While Contributing

  1. Run the unit tests by running make test
  2. Run a build of all variations for an ARM mcu using make test-mcu-builds
  3. TODO: Run a build against non-GCC compilers against all variants using make test-compiler-builds

Acknowledgements

  1. I would like to give a shoutout to @dmadison for the very useful images that he provided in dmadison/LED-Segment-ASCII. I specifically borrowed Segment-Labels.png and 7-Segment - All Supported Chars.png.

  2. Shoutout as well to the Linux Handbook. I borrowed their image of the ASCII table: ASCII Table - The Linux Handbook.png.

About

ASCII character input → 7-segment display ABCDEFG outputs.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •