forked from zephyrproject-rtos/zephyr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmb_display.h
171 lines (151 loc) · 4.58 KB
/
mb_display.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/** @file
* @brief BBC micro:bit display APIs.
*/
/*
* Copyright (c) 2017 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef ZEPHYR_INCLUDE_DISPLAY_MB_DISPLAY_H_
#define ZEPHYR_INCLUDE_DISPLAY_MB_DISPLAY_H_
/**
* @brief BBC micro:bit display APIs
* @defgroup mb_display BBC micro:bit display APIs
* @ingroup display_interfaces
* @{
*/
#include <stdio.h>
#include <zephyr/types.h>
#include <stdbool.h>
#include <sys/util.h>
#include <toolchain.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];
};
};
/**
* @brief Display mode.
*
* First 16 bits are reserved for modes, last 16 for flags.
*/
enum mb_display_mode {
/** Default mode ("single" for images, "scroll" for text). */
MB_DISPLAY_MODE_DEFAULT,
/** Display images sequentially, one at a time. */
MB_DISPLAY_MODE_SINGLE,
/** Display images by scrolling. */
MB_DISPLAY_MODE_SCROLL,
/* Display flags, i.e. modifiers to the chosen mode */
/** Loop back to the beginning when reaching the last image. */
MB_DISPLAY_FLAG_LOOP = BIT(16),
};
/**
* @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 one or more images on the BBC micro:bit LED display.
*
* This function takes an array of one or more images and renders them
* sequentially on the micro:bit display. The call is asynchronous, i.e.
* the processing of the display happens in the background. If there is
* another image being displayed it will be canceled and the new one takes
* over.
*
* @param disp Display object.
* @param mode One of the MB_DISPLAY_MODE_* options.
* @param duration Duration how long to show each image (in milliseconds), or
* @ref SYS_FOREVER_MS.
* @param img Array of image bitmaps (struct mb_image objects).
* @param img_count Number of images in 'img' array.
*/
void mb_display_image(struct mb_display *disp, uint32_t mode, int32_t duration,
const struct mb_image *img, uint8_t img_count);
/**
* @brief Print a string of characters on the BBC micro:bit LED display.
*
* This function takes a printf-style format string and outputs it in a
* scrolling fashion to the display.
*
* The call is asynchronous, i.e. the processing of the display happens in
* the background. If there is another image or string being displayed it
* will be canceled and the new one takes over.
*
* @param disp Display object.
* @param mode One of the MB_DISPLAY_MODE_* options.
* @param duration Duration how long to show each character (in milliseconds),
* or @ref SYS_FOREVER_MS.
* @param fmt printf-style format string
* @param ... Optional list of format arguments.
*/
__printf_like(4, 5) void mb_display_print(struct mb_display *disp,
uint32_t mode, int32_t duration,
const char *fmt, ...);
/**
* @brief Stop the ongoing display of an image.
*
* @param disp Display object.
*/
void mb_display_stop(struct mb_display *disp);
#ifdef __cplusplus
}
#endif
/**
* @}
*/
#endif /* ZEPHYR_INCLUDE_DISPLAY_MB_DISPLAY_H_ */