drivers: Add support for BBC micro:bit LED display

Adds a simple driver to access the 5x5 LED display found on BBC
micro:bit boards. The display is so limited that no effort is done to
try to integrate with the existing console (which would likely make
the display unusable). Instead, dedicated mb_display_* APIs are added
that are specific to this display.

References:

 https://www.microbit.co.uk/device/screen
 https://lancaster-university.github.io/microbit-docs/ubit/display/

Jira: ZEP-1990
Change-Id: I431b5b358b5f07592a60d3aed87eaab6ac20ce25
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
Johan Hedberg 2017-04-02 20:54:23 +03:00
commit 380d24de1d
17 changed files with 1068 additions and 0 deletions

View file

@ -0,0 +1,134 @@
/** @file
* @brief BBC micro:bit display APIs.
*/
/*
* Copyright (c) 2017 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef __MB_DISPLAY_H
#define __MB_DISPLAY_H
/**
* @brief BBC micro:bit display APIs
* @defgroup mb_display BBC micro:bit display APIs
* @{
*/
#include <stdint.h>
#include <misc/util.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Representation of a BBC micro:bit display image.
*
* This struct should normally not be used directly, rather created
* using the MB_IMAGE() macro.
*/
struct mb_image {
union {
struct {
uint8_t c1:1,
c2:1,
c3:1,
c4:1,
c5:1;
} r[5];
uint8_t row[5];
};
};
/**
* @def MB_IMAGE
* @brief Generate an image object from a given array rows/columns.
*
* This helper takes an array of 5 rows, each consisting of 5 0/1 values which
* correspond to the columns of that row. The value 0 means the pixel is
* disabled whereas a 1 means the pixel is enabled.
*
* The pixels go from left to right and top to bottom, i.e. top-left corner
* is the first row's first value, top-right is the first rows last value,
* and bottom-right corner is the last value of the last (5th) row. As an
* example, the following would create a smiley face image:
*
* <pre>
* static const struct mb_image smiley = MB_IMAGE({ 0, 1, 0, 1, 0 },
* { 0, 1, 0, 1, 0 },
* { 0, 0, 0, 0, 0 },
* { 1, 0, 0, 0, 1 },
* { 0, 1, 1, 1, 0 });
* </pre>
*
* @param _rows Each of the 5 rows represented as a 5-value column array.
*
* @return Image bitmap that can be passed e.g. to mb_display_image().
*/
#define MB_IMAGE(_rows...) { .r = { _rows } }
/**
* @brief Opaque struct representing the BBC micro:bit display.
*
* For more information see the following links:
*
* https://www.microbit.co.uk/device/screen
*
* https://lancaster-university.github.io/microbit-docs/ubit/display/
*/
struct mb_display;
/**
* @brief Get a pointer to the BBC micro:bit display object.
*
* @return Pointer to display object.
*/
struct mb_display *mb_display_get(void);
/**
* @brief Display an image on the BBC micro:bit LED display.
*
* @param disp Display object.
* @param img Bitmap of pixels.
* @param duration Duration how long to show the image (in milliseconds).
*/
void mb_display_image(struct mb_display *disp, const struct mb_image *img,
int32_t duration);
/**
* @brief Display a character on the BBC micro:bit LED display.
*
* @param disp Display object.
* @param chr Character to display.
* @param duration Duration how long to show the character (in milliseconds).
*/
void mb_display_char(struct mb_display *disp, char chr, int32_t duration);
/**
* @brief Display a string of characters on the BBC micro:bit LED display.
*
* @param disp Display object.
* @param str String to display.
* @param duration Duration how long to show each character (in milliseconds).
*/
void mb_display_str(struct mb_display *disp, const char *str, int32_t duration);
/**
* @brief Stop the ongoing display of an image.
*
* @param disp Display object.
*/
void mb_display_stop(struct mb_display *disp);
#ifdef __cplusplus
}
#endif
/**
* @}
*/
#endif /* __MB_DISPLAY_H */