1 #ifndef DISPLAY_7SEG_HEADER
2 #define DISPLAY_7SEG_HEADER
3 
4 /*
5  * Copyright (c) 2021 Titouan Christophe
6  *
7  * SPDX-License-Identifier: Apache-2.0
8  */
9 
10 #include <stdbool.h>
11 #include <stdint.h>
12 
13 /*
14  *    3
15  *   ---
16  * 1|   |5
17  *   -2-
18  * 0|   |6
19  *   ---
20  *    4
21  */
22 
23 #define CHAR_OFF        (0)
24 
25 #define CHAR_0          (BIT(0) | BIT(1) | BIT(3) | BIT(4) | BIT(5) | BIT(6))
26 #define CHAR_1          (BIT(5) | BIT(6))
27 #define CHAR_2          (BIT(0) | BIT(2) | BIT(3) | BIT(4) | BIT(5))
28 #define CHAR_3          (BIT(2) | BIT(3) | BIT(4) | BIT(5) | BIT(6))
29 #define CHAR_4          (BIT(1) | BIT(2) | BIT(5) | BIT(6))
30 #define CHAR_5          (BIT(1) | BIT(2) | BIT(3) | BIT(4) | BIT(6))
31 #define CHAR_6          (BIT(0) | BIT(1) | BIT(2) | BIT(3) | BIT(4) | BIT(6))
32 #define CHAR_7          (BIT(3) | BIT(5) | BIT(6))
33 #define CHAR_8          (BIT(0) | BIT(1) | BIT(2) | BIT(3) | BIT(4) | BIT(5) | BIT(6))
34 #define CHAR_9          (BIT(1) | BIT(2) | BIT(3) | BIT(4) | BIT(5) | BIT(6))
35 
36 #define CHAR_A          (BIT(0) | BIT(1) | BIT(2) | BIT(3) | BIT(5) | BIT(6))
37 #define CHAR_C          (BIT(0) | BIT(1) | BIT(3) | BIT(4))
38 #define CHAR_E          (BIT(0) | BIT(1) | BIT(2) | BIT(3) | BIT(4))
39 #define CHAR_F          (BIT(0) | BIT(1) | BIT(2) | BIT(3))
40 #define CHAR_H          (BIT(0) | BIT(1) | BIT(2) | BIT(5) | BIT(6))
41 #define CHAR_L          (BIT(0) | BIT(1) | BIT(4))
42 #define CHAR_P          (BIT(0) | BIT(1) | BIT(2) | BIT(3) | BIT(5))
43 #define CHAR_U          (BIT(0) | BIT(1) | BIT(4) | BIT(5) | BIT(6))
44 
45 #define CHAR_b          (BIT(0) | BIT(1) | BIT(2) | BIT(4) | BIT(6))
46 #define CHAR_d          (BIT(0) | BIT(2) | BIT(4) | BIT(5) | BIT(6))
47 #define CHAR_h          (BIT(0) | BIT(1) | BIT(2) | BIT(6))
48 #define CHAR_i          (BIT(6))
49 #define CHAR_o          (BIT(0) | BIT(2) | BIT(4) | BIT(6))
50 #define CHAR_r          (BIT(0) | BIT(2))
51 #define CHAR_t          (BIT(0) | BIT(1) | BIT(2) | BIT(4))
52 #define CHAR_u          (BIT(0) | BIT(4) | BIT(6))
53 
54 #define CHAR_DASH       (BIT(2))
55 #define CHAR_OVERLINE   (BIT(3))
56 #define CHAR_UNDERSCORE (BIT(4))
57 #define CHAR_PIPE       (BIT(0) | BIT(1))
58 
59 extern const uint8_t DISPLAY_OFF[4];
60 extern const uint8_t TEXT_Err[4];
61 
62 /**
63  * @brief      Display characters on the 4x7seg display
64  * @param[in]  chars  The characters to be displayed
65  * @return     0 on success, nonzero on error
66  */
67 int display_chars(const uint8_t chars[4]);
68 
69 /**
70  * @brief      Display a number on the 4x7seg display
71  * @param[in]  num   The number to be displayed
72  * @param[in]  base  The base into which the number shall be displayed
73  * @return     0 on success, nonzero on error
74  */
75 int display_number(int num, unsigned int base);
76 
77 #endif
78