Software APIs
ssd1131_screen.h
1 // Copyright lowRISC contributors (OpenTitan project).
2 // Licensed under the Apache License, Version 2.0, see LICENSE for details.
3 // SPDX-License-Identifier: Apache-2.0
4 
5 #ifndef OPENTITAN_SW_DEVICE_LIB_PERIPHERALS_SSD1131_SCREEN_H_
6 #define OPENTITAN_SW_DEVICE_LIB_PERIPHERALS_SSD1131_SCREEN_H_
7 
8 #include "sw/device/examples/teacup_demos/data/bitmaps.h"
9 #include "sw/device/lib/base/status.h"
12 
13 /**
14  * Defined Constants.
15  */
16 enum {
17  // Max screen sizes.
18  kScreenMaxRows = 64,
19  kScreenMaxCols = 96,
20 
21  // Colors.
22  kScreenPixelColorWhite = 0xFFFF,
23  kScreenPixelColorBlack = 0x0,
24 };
25 
26 /**
27  * Screen Handle.
28  */
29 typedef struct screen {
30  /**
31  * GPIO handle to manipulate the data/command line.
32  */
33  dif_gpio_t *gpio;
34  /**
35  * SPI Host handle to send commands / data to the screen.
36  */
37  dif_spi_host_t *spi_host;
38  /**
39  * Data/Command control GPIO pin.
40  */
42 } screen_t;
43 
44 /**
45  * Screen operation type.
46  */
47 typedef enum screen_op_type {
48  kScreenOpTypeCommand = 0,
49  kScreenOpTypeData = 1,
50 } screen_op_type_t;
51 
52 /**
53  * Screen Commands.
54  */
55 typedef enum screen_commands {
56  // Toggle screen on and off.
57  kScreenSetDisplayOn = 0xAF,
58  kScreenSetDisplayOnDim = 0xAC,
59  kScreenSetDisplayOff = 0xAE,
60 
61  // Display modes.
62  kScreenAllPixelsNormal = 0xA4,
63  kScreenAllPixelsOn = 0xA5,
64  kScreenAllPixelsOff = 0xA6,
65  kScreenAllPixelsInverse = 0xA7,
66 
67  // Set column/row addresses.
68  kScreenSetColumnAddress = 0x15,
69  kScreenSetRowAddress = 0x75,
70 
71  // Set remap/color format.
72  kScreenSetRemapAndColorFormat = 0xA0,
73 
74  // Deactivate scrolling.
75  kScreenDeactivateScrolling = 0x2E,
76 } screen_commands_t;
77 
78 /**
79  * Screen pixel modes.
80  */
81 typedef enum screen_pixel_mode {
82  kScreenPixelModeNormal = kScreenAllPixelsNormal,
83  kScreenPixelModeAllOn = kScreenAllPixelsOn,
84  kScreenPixelModeAllOff = kScreenAllPixelsOff,
85  kScreenPixelModeInverse = kScreenAllPixelsInverse,
86 } screen_pixel_mode_t;
87 
88 /**
89  * Screen color formats.
90  */
91 typedef enum screen_color_format {
92  kScreenColorFormat256 = 0,
93  kScreenColorFormat65k2Byte = 1,
94  kScreenColorFormat65k3Byte = 2,
95 } screen_color_format_t;
96 
97 /**
98  * Transmits a command or data to the screen.
99  *
100  * @param screen Screen handle to communicate with the screen controller.
101  * @param data The command or data to send to the screen controller.
102  * @param op_type The transaction operation type (command or data).
103  */
105 status_t screen_tx_cmd_or_data(const screen_t *screen, uint8_t data,
106  screen_op_type_t op_type);
107 
108 /**
109  * Toggles the screen power on or off.
110  *
111  * @param screen Screen handle to communicate with the screen controller.
112  * @param on Whether to turn the screen on or off.
113  */
114 OT_WARN_UNUSED_RESULT status_t screen_toggle_power(const screen_t *screen,
115  bool on);
116 
117 /**
118  * Toggles the screen pixel mode.
119  *
120  * @param screen Screen handle to communicate with the screen controller.
121  * @param mode The pixel mode to set (all on, all off, inverse, or normal).
122  */
124 status_t screen_toggle_pixel_mode(const screen_t *screen,
125  screen_pixel_mode_t mode);
126 
127 /**
128  * Configures the color format for the screen.
129  *
130  * @param screen Screen handle to communicate with the screen controller.
131  * @param format Color format for the pixel data.
132  */
134 status_t screen_configure_color_format(const screen_t *screen,
135  screen_color_format_t format);
136 
137 /**
138  * Set the screen column address range.
139  *
140  * @param screen Screen handle to communicate with the screen controller.
141  * @param start_address Start column address of the screen RAM array.
142  * @param end_address End column address of the screen RAM array.
143  */
145 status_t screen_set_column_address_range(const screen_t *screen,
146  uint8_t start_address,
147  uint8_t end_address);
148 
149 /**
150  * Set the screen row address range.
151  *
152  * @param screen Screen handle to communicate with the screen controller.
153  * @param start_address Start row address of the screen RAM array.
154  * @param end_address End row address of the screen RAM array.
155  */
157 status_t screen_set_row_address_range(const screen_t *screen,
158  uint8_t start_address,
159  uint8_t end_address);
160 
161 /**
162  * Draw a bitmap on the screen.
163  *
164  * @param screen Screen handle to communicate with the screen controller.
165  * @param bitmap Bitmap to draw on the screen.
166  */
168 status_t screen_draw_bitmap(const screen_t *screen,
169  const screen_bitmap_t *bitmap);
170 
171 #endif // OPENTITAN_SW_DEVICE_LIB_PERIPHERALS_SSD1131_SCREEN_H_