eink  2.0.0.0
eink.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright© 2020 MikroElektronika d.o.o.
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without restriction,
8  * including without limitation the rights to use, copy, modify, merge,
9  * publish, distribute, sublicense, and/or sell copies of the Software,
10  * and to permit persons to whom the Software is furnished to do so,
11  * subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22  * OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef EINK_H
36 #define EINK_H
37 
38 #include "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_spi_master.h"
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
63 #define EINK_MAP_MIKROBUS( cfg, mikrobus ) \
64  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
65  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
66  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
67  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
68  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
69  cfg.dc = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
70  cfg.bsy = MIKROBUS( mikrobus, MIKROBUS_INT )
71 
77 #define EINK_OK 0
78 #define EINK_ERROR -1
79 
85 #define EINK_DISPLAY_WIDTH 72
86 #define EINK_DISPLAY_HEIGHT 172
87 #define EINK_DISPLAY_RESOLUTION 3096
88 
94 #define EINK_COMMUNICATION_SPI 0
95 #define EINK_COMMUNICATION_I2C 1
96 
102 #define EINK_SCREEN_COLOR_WHITE 0xFF
103 #define EINK_SCREEN_COLOR_BLACK 0x00
104 #define EINK_SCREEN_COLOR_LIGHT_GREY 0xAA
105 #define EINK_SCREEN_COLOR_DARK_GREY 0x55
106 
107 #define EINK_FO_HORIZONTAL 0x00
108 #define EINK_FO_VERTICAL 0x01
109 #define EINK_FO_VERTICAL_COLUMN 0x02
110 
116 #define EINK_CMD_DRIVER_OUTPUT_CONTROL 0x01
117 #define EINK_CMD_GATE_VOLTAGE_CONTROL 0x03
118 #define EINK_CMD_SOURCE_VOLTAGE_CONTROL 0x04
119 #define EINK_CMD_DISPLAY_CONTROL 0x07
120 #define EINK_CMD_NONOVERLAP_PERIOD 0x0B
121 #define EINK_CMD_GATE_SCAN_START_POSITION 0x0F
122 #define EINK_CMD_DEEP_SLEEP_MODE 0x10
123 #define EINK_CMD_DATA_ENTRY_MODE_SETTING 0x11
124 #define EINK_CMD_SW_RESET 0x12
125 #define EINK_CMD_TEMPERATURE_SENSOR_CONTROL 0x1A
126 #define EINK_CMD_TEMPERATURE_LOAD 0x1D
127 #define EINK_CMD_MASTER_ACTIVATION 0x20
128 #define EINK_CMD_DISPLAY_UPDATE_CONTROL_1 0x21
129 #define EINK_CMD_DISPLAY_UPDATE_CONTROL_2 0x22
130 #define EINK_CMD_WRITE_RAM 0x24
131 #define EINK_CMD_VCOM_SENSE 0x28
132 #define EINK_CMD_VCOM_SENSE_DURATION 0x29
133 #define EINK_CMD_VCOM_PROG_OTP 0x2A
134 #define EINK_CMD_WRITE_VCOM_REGISTER 0x2C
135 #define EINK_CMD_OTP_WAVEFORM_SETTINGS 0x30
136 #define EINK_CMD_WRITE_LUT_REGISTER 0x32
137 #define EINK_CMD_OTP_PROGRAM 0x36
138 #define EINK_CMD_OTP_SELECTION 0x37
139 #define EINK_CMD_SET_DUMMY_LINE_PERIOD 0x3A
140 #define EINK_CMD_SET_GATE_TIME 0x3B
141 #define EINK_CMD_BORDER_WAVEFORM_CONTROL 0x3C
142 #define EINK_CMD_SET_RAM_X_ADDRESS_START_END_POSITION 0x44
143 #define EINK_CMD_SET_RAM_Y_ADDRESS_START_END_POSITION 0x45
144 #define EINK_CMD_SET_RAM_X_ADDRESS_COUNTER 0x4E
145 #define EINK_CMD_SET_RAM_Y_ADDRESS_COUNTER 0x4F
146 #define EINK_CMD_BOOSTER_FEEDBACK_SELECTION 0xF0
147 #define EINK_CMD_TERMINATE_FRAME_READ_WRITE 0xFF
148 
154 #define EINK_DEVICE_SLAVE_ADDRESS_000 0x28
155 #define EINK_DEVICE_SLAVE_ADDRESS_001 0x29
156 #define EINK_DEVICE_SLAVE_ADDRESS_010 0x2A
157 #define EINK_DEVICE_SLAVE_ADDRESS_011 0x2B
158 #define EINK_DEVICE_SLAVE_ADDRESS_100 0x2C
159 #define EINK_DEVICE_SLAVE_ADDRESS_101 0x2D
160 #define EINK_DEVICE_SLAVE_ADDRESS_110 0x2E
161 #define EINK_DEVICE_SLAVE_ADDRESS_111 0x2F
162  // End group macro
165 // --------------------------------------------------------------- PUBLIC TYPES
171 typedef struct
172 {
173  const uint8_t *p_font;
174  uint16_t color;
175  uint8_t orientation;
176  uint16_t first_char;
177  uint16_t last_char;
178  uint16_t height;
179 
181 
182 typedef struct
183 {
184  uint16_t x;
185  uint16_t y;
186 
188 
189 typedef struct
190 {
191  uint8_t x_start;
192  uint8_t y_start;
193  uint8_t x_end;
194  uint8_t y_end;
195 
196 } eink_xy_t;
197 
198 typedef struct
199 {
200  uint8_t text_x;
201  uint8_t text_y;
202  uint8_t n_char;
203 
205 
209 typedef struct
210 {
211  // Output pins
212  digital_out_t cs;
213  digital_out_t rst;
214  digital_out_t dc;
215 
216  // Input pins
217  digital_in_t bsy;
218 
219  // Modules
220  spi_master_t spi;
221  pin_name_t chip_select;
222 
225 #ifndef IMAGE_MODE_ONLY
226  uint8_t p_frame[EINK_DISPLAY_RESOLUTION];
227 #endif
228 } eink_t;
229 
233 typedef struct
234 {
235  // Communication gpio pins
236  pin_name_t miso;
237  pin_name_t mosi;
238  pin_name_t sck;
239  pin_name_t cs;
240 
241  // Additional gpio pins
242  pin_name_t rst;
243  pin_name_t dc;
244  pin_name_t bsy;
245 
246  // static variable
247  uint32_t spi_speed;
248  spi_master_mode_t spi_mode;
249  spi_master_chip_select_polarity_t cs_polarity;
250 
252 
253 } eink_cfg_t;
254  // End types group
256 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
257 
262 #ifdef __cplusplus
263 extern "C"{
264 #endif
265 
275 
284 err_t eink_init ( eink_t *ctx, eink_cfg_t *cfg );
285 
292 void eink_send_cmd ( eink_t *ctx, uint8_t command );
293 
300 void eink_send_data ( eink_t *ctx, uint8_t c_data );
301 
307 void eink_reset( eink_t *ctx );
308 
314 void eink_sleep_mode ( eink_t *ctx );
315 
321 void eink_start_config ( eink_t *ctx );
322 
332 void eink_set_lut ( eink_t *ctx, const uint8_t *lut, uint8_t n_bytes );
333 
341 void eink_set_mem_pointer ( eink_t *ctx, uint8_t x, uint8_t y );
342 
349 void eink_set_mem_area ( eink_t *ctx, eink_xy_t *xy );
350 
357 
370 void eink_fill_screen ( eink_t *ctx, uint8_t color );
371 
380 void eink_display_image ( eink_t *ctx, const uint8_t* image_buffer );
381 
390 void eink_text ( eink_t *ctx, uint8_t *text, eink_text_set_t *text_set );
391 
398 void eink_set_font ( eink_t *ctx, eink200inch_font_t *cfg_font );
399 
400 #ifdef __cplusplus
401 }
402 #endif
403 #endif // _EINK_H_
404  // End public_function group
407 
408 // ------------------------------------------------------------------------- END
eink200inch_font_t::orientation
uint8_t orientation
Definition: eink.h:175
eink_cordinate_t
Definition: eink.h:183
eink_set_mem_pointer
void eink_set_mem_pointer(eink_t *ctx, uint8_t x, uint8_t y)
Setting pointers in memory.
eink_fill_screen
void eink_fill_screen(eink_t *ctx, uint8_t color)
Function that fills the screen.
eink_cfg_t::font_cfg
eink200inch_font_t font_cfg
Definition: eink.h:251
eink_text_set_t::text_x
uint8_t text_x
Definition: eink.h:200
eink_cfg_t::spi_speed
uint32_t spi_speed
Definition: eink.h:247
eink200inch_font_t::last_char
uint16_t last_char
Definition: eink.h:177
eink_cfg_t::sck
pin_name_t sck
Definition: eink.h:238
eink_t::dev_font
eink200inch_font_t dev_font
Definition: eink.h:223
eink_t::spi
spi_master_t spi
Definition: eink.h:220
eink_update_display
void eink_update_display(eink_t *ctx)
Update dispaly.
eink_reset
void eink_reset(eink_t *ctx)
Reset chip.
eink_cfg_t::mosi
pin_name_t mosi
Definition: eink.h:237
eink_t::dc
digital_out_t dc
Definition: eink.h:214
eink_cordinate_t::x
uint16_t x
Definition: eink.h:184
EINK_DISPLAY_RESOLUTION
#define EINK_DISPLAY_RESOLUTION
Definition: eink.h:87
eink_t::chip_select
pin_name_t chip_select
Definition: eink.h:221
eink_xy_t
Definition: eink.h:190
eink_cfg_setup
void eink_cfg_setup(eink_cfg_t *cfg)
Config Object Initialization function.
eink_t::dev_cord
eink_cordinate_t dev_cord
Definition: eink.h:224
eink_cfg_t::rst
pin_name_t rst
Definition: eink.h:242
eink_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: eink.h:248
eink_text_set_t::text_y
uint8_t text_y
Definition: eink.h:201
eink200inch_font_t::p_font
const uint8_t * p_font
Definition: eink.h:173
eink_xy_t::x_start
uint8_t x_start
Definition: eink.h:191
eink_send_data
void eink_send_data(eink_t *ctx, uint8_t c_data)
Sending data.
eink_set_lut
void eink_set_lut(eink_t *ctx, const uint8_t *lut, uint8_t n_bytes)
Set LUT table.
eink_init
err_t eink_init(eink_t *ctx, eink_cfg_t *cfg)
Initialization function.
eink_sleep_mode
void eink_sleep_mode(eink_t *ctx)
Sleep mode.
eink_set_mem_area
void eink_set_mem_area(eink_t *ctx, eink_xy_t *xy)
Setting area in memory.
eink200inch_font_t::height
uint16_t height
Definition: eink.h:178
eink_start_config
void eink_start_config(eink_t *ctx)
Configuration display.
eink_set_font
void eink_set_font(eink_t *ctx, eink200inch_font_t *cfg_font)
Set text font.
eink_display_image
void eink_display_image(eink_t *ctx, const uint8_t *image_buffer)
Displays image.
eink_xy_t::y_start
uint8_t y_start
Definition: eink.h:192
eink_xy_t::x_end
uint8_t x_end
Definition: eink.h:193
eink_t::rst
digital_out_t rst
Definition: eink.h:213
eink_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: eink.h:249
eink200inch_font_t::color
uint16_t color
Definition: eink.h:174
eink_t::cs
digital_out_t cs
Definition: eink.h:212
eink_text_set_t::n_char
uint8_t n_char
Definition: eink.h:202
eink200inch_font_t
Definition: eink.h:172
eink_cfg_t::bsy
pin_name_t bsy
Definition: eink.h:244
eink_text
void eink_text(eink_t *ctx, uint8_t *text, eink_text_set_t *text_set)
Draw text on the screen.
eink_t::bsy
digital_in_t bsy
Definition: eink.h:217
eink_text_set_t
Definition: eink.h:199
eink_cfg_t
Click configuration structure definition.
Definition: eink.h:234
eink_t
Click ctx object definition.
Definition: eink.h:210
eink_cordinate_t::y
uint16_t y
Definition: eink.h:185
eink_cfg_t::miso
pin_name_t miso
Definition: eink.h:236
eink_cfg_t::dc
pin_name_t dc
Definition: eink.h:243
eink200inch_font_t::first_char
uint16_t first_char
Definition: eink.h:176
eink_cfg_t::cs
pin_name_t cs
Definition: eink.h:239
eink_xy_t::y_end
uint8_t y_end
Definition: eink.h:194
eink_send_cmd
void eink_send_cmd(eink_t *ctx, uint8_t command)
Sending a command.