A LED driver for embedded systems.
- Multiple-instance module
- Written in C
- Testability
- MIT license
- The implementation of LEDs is memory-mapped I/O and 8 bits
- The I/O address is writable and readable
- The bit value 1 is LED on and 0 is LED off
- Dynamic memory allocation
I recommend just copying LedDriver.h and LedDriver.c into your project. Then just #include "LedDriver.h" to use the LedDriver functions.
LedDriver LedDriver_Create(uint8_t* ioAddress, uint8_t (*decoder)(int));
Create a LedDriver instance.
Note: All LEDs will be off if successfully.
Inputs:
ioAddress
- The I/O address for LEDs.decoder
- The function to convert to bit from the LED number (1 to 8).
Returns the instance if created successfully, NULL if an error occurred.
void LedDriver_Destroy(LedDriver* self);
Destroy a LedDriver instance.
Note: All LEDs will be off if successfully.
Inputs:
self
- The pointer to LedDriver instance.
void LedDriver_TurnOn(LedDriver self, int ledNumber);
Turn on a LED.
Inputs:
self
- The LedDriver instance.ledNumber
- The number of LED to turn on.
void LedDriver_TurnOff(LedDriver self, int ledNumber);
Turn off a LED.
Inputs:
self
- The LedDriver instance.ledNumber
- The number of LED to turn off.
void LedDriver_TurnAllOn(LedDriver self);
Turn on all LEDs.
Inputs:
self
- The LedDriver instance.
void LedDriver_TurnAllOff(LedDriver self);
Turn off all LEDs.
Inputs:
self
- The LedDriver instance.
bool LedDriver_IsOn(LedDriver self, int ledNumber);
Check if the LED is on.
Inputs:
self
- The LedDriver instance.ledNumber
- The number of LED to check.
bool LedDriver_IsOff(LedDriver self, int ledNumber);
Check if the LED is off.
Inputs:
self
- The LedDriver instance.ledNumber
- The number of LED to check.
$ cd LedDriver
$ mkdir build
$ cd build
$ cmake ..
$ make
Either using ctest
or directly using bin/gtests
in the build directory.