oledb 2.0.0.0
oledb.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2020 MikroElektronika d.o.o.
3** Contact: https://www.mikroe.com/contact
4**
5** Permission is hereby granted, free of charge, to any person obtaining a copy
6** of this software and associated documentation files (the "Software"), to deal
7** in the Software without restriction, including without limitation the rights
8** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9** copies of the Software, and to permit persons to whom the Software is
10** furnished to do so, subject to the following conditions:
11** The above copyright notice and this permission notice shall be
12** included in all copies or substantial portions of the Software.
13**
14** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20** USE OR OTHER DEALINGS IN THE SOFTWARE.
21****************************************************************************/
22
28#ifndef _OLEDB_H_
29#define _OLEDB_H_
30
35#ifdef PREINIT_SUPPORTED
36#include "preinit.h"
37#endif
38
39#ifdef MikroCCoreVersion
40 #if MikroCCoreVersion >= 1
41 #include "delays.h"
42 #endif
43#endif
44
45#include "drv_digital_out.h"
46#include "drv_i2c_master.h"
47#include "drv_spi_master.h"
48#include "oledb_resources.h"
49
50// -------------------------------------------------------------- PUBLIC MACROS
60#define OLEDB_SSD1306_WIDTH 128
61#define OLEDB_DISPLAY_WIDTH 96
62#define OLEDB_DISPLAY_HEIGHT 39
63#define OLEDB_DISPLAY_ROWS 5
64#define OLEDB_FONT_5X7 0
65#define OLEDB_FONT_6X8 1
66#define OLEDB_DISPLAYOFF 0xAE
67#define OLEDB_SETDISPLAYCLOCKDIV 0xD5
68#define OLEDB_SETMULTIPLEX 0xA8
69#define OLEDB_SETDISPLAYOFFSET 0xD3
70#define OLEDB_SETSTARTLINE 0x40
71#define OLEDB_CHARGEPUMP 0x8D
72#define OLEDB_SETSEGMENTREMAP 0xA1
73#define OLEDB_SEGREMAP 0xA0
74#define OLEDB_COMSCANDEC 0xC8
75#define OLEDB_SETCOMPINS 0xDA
76#define OLEDB_SETCONTRAST 0x81
77#define OLEDB_SETPRECHARGE 0xD9
78#define OLEDB_SETVCOMDETECT 0xDB
79#define OLEDB_DISPLAYALLON_RESUME 0xA4
80#define OLEDB_NORMALDISPLAY 0xA6
81#define OLEDB_DISPLAYON 0xAF
82#define OLEDB_DISPLAYALLON 0xA5
83#define OLEDB_INVERTDISPLAY 0xA7
84#define OLEDB_SETLOWCOLUMN 0x00
85#define OLEDB_SETHIGHCOLUMN 0x10
86#define OLEDB_MEMORYMODE 0x20
87#define OLEDB_COLUMNADDR 0x21
88#define OLEDB_PAGEADDR 0x22
89#define OLEDB_COMSCANINC 0xC0
90#define OLEDB_EXTERNALVCC 0x01
91#define OLEDB_SWITCHCAPVCC 0x02
92#define OLEDB_ACTIVATE_SCROLL 0x2F
93#define OLEDB_DEACTIVATE_SCROLL 0x2E
94#define OLEDB_SET_VERTICAL_SCROLL_AREA 0xA3
95#define OLEDB_RIGHT_HORIZONTAL_SCROLL 0x26
96#define OLEDB_LEFT_HORIZONTAL_SCROLL 0x27
97#define OLEDB_VERTICAL_AND_RIGHT_HORIZONTAL_SCROLL 0x29
98#define OLEDB_VERTICAL_AND_LEFT_HORIZONTAL_SCROLL 0x2A
105#define OLEDB_COMMAND 0x3C
106#define OLEDB_DATA 0x3D
113#define OLEDB_MASTER_I2C 0
114#define OLEDB_MASTER_SPI 1
126#define err_t uint8_t
133#define OLEDB_OK 0x00
134#define OLEDB_INIT_ERROR 0xFF
135#define OLEDB_INVALID_DATA_MODE 0xFE
136#define OLEDB_INVALID_DRIVER_SELECTOR 0xFD
139 // End error group
140
145#define OLEDB_MAP_MIKROBUS( cfg, mikrobus ) \
146 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
147 cfg.dc = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
148 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
149 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
150 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
151 cfg.sdi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
152 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
153 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
156 // End macros group
157// --------------------------------------------------------------- PUBLIC TYPES
163typedef uint8_t oledb_drv_select_t;
164
165typedef uint8_t oledb_data_t;
166
167typedef const uint8_t oledb_resources_t;
168
169typedef void ( *oledb_master_write_t )( struct oledb_s *, oledb_data_t *, uint8_t );
173typedef uint8_t oledb_select_t;
174
178typedef struct oledb_s
179{
180 // Click mikrobus DRV objects.
181 digital_out_t cs;
182 digital_out_t rst;
183 digital_out_t dc;
184
185 // Modules
186 spi_master_t spi;
187 i2c_master_t i2c;
188
189 // ctx variable
190
192 pin_name_t chip_select;
193
194 // Click send function pointer.
197
199
203typedef struct
204{
205 // Used mikrobus pins.
206 pin_name_t rst;
207 pin_name_t dc;
208 pin_name_t cs;
209 pin_name_t sck;
210 pin_name_t sdi;
211 pin_name_t scl;
212 pin_name_t sda;
213 pin_name_t miso;
214
215 // static variable
216
217 uint32_t i2c_speed;
218 uint8_t i2c_address;
219 uint32_t spi_speed;
220 spi_master_mode_t spi_mode;
221 spi_master_chip_select_polarity_t cs_polarity;
222
229
231
232 // End types group
233// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
239#ifdef __cplusplus
240extern "C"{
241#endif
242
254
268
277
286void oledb_send_data( oledb_t *ctx, oledb_data_t *tx_data, uint8_t data_len );
287
296
305void oledb_set_page( oledb_t *ctx, oledb_data_t page_addr );
306
315void oledb_set_column( oledb_t *ctx, oledb_data_t col_addr );
316
326
335
347void oledb_write_char( oledb_t *ctx, uint8_t font, uint8_t row, uint8_t position, uint8_t data_in );
348
360void oledb_write_string( oledb_t *ctx, uint8_t font, uint8_t row, uint8_t position, uint8_t *data_in );
361
371
381void oledb_scroll_right( oledb_t *ctx, oledb_data_t start_page_addr, oledb_data_t end_page_addr );
382
392void oledb_scroll_left( oledb_t *ctx, oledb_data_t start_page_addr, oledb_data_t end_page_addr );
393
403void oledb_scroll_diag_right( oledb_t *ctx, oledb_data_t start_page_addr, oledb_data_t end_page_addr );
404
414void oledb_scroll_diag_left( oledb_t *ctx, oledb_data_t start_page_addr, oledb_data_t end_page_addr );
415
424
425#ifdef __cplusplus
426}
427#endif
428#endif // OLEDB_H
429
430 // oledb
431
432// ------------------------------------------------------------------------ END
#define err_t
Definition oledb.h:126
void oledb_display_picture(oledb_t *ctx, oledb_resources_t *pic)
Display Picture function.
void oledb_send_data(oledb_t *ctx, oledb_data_t *tx_data, uint8_t data_len)
Send data function.
void oledb_write_char(oledb_t *ctx, uint8_t font, uint8_t row, uint8_t position, uint8_t data_in)
Write Char function.
void oledb_set_contrast(oledb_t *ctx, oledb_data_t value)
Contrast Setting function.
void oledb_send_cmd(oledb_t *ctx, oledb_data_t tx_cmd)
Send cmd function.
void oledb_stop_scroll(oledb_t *ctx)
Stop Scrolling function.
void oledb_scroll_right(oledb_t *ctx, oledb_data_t start_page_addr, oledb_data_t end_page_addr)
Scroll Right function.
err_t oledb_init(oledb_t *ctx, oledb_cfg_t *cfg)
Click Initialization function.
void oledb_default_cfg(oledb_t *ctx)
Click Default Configuration function.
void oledb_scroll_diag_left(oledb_t *ctx, oledb_data_t start_page_addr, oledb_data_t end_page_addr)
Scroll Diagonally Left function.
void oledb_clear_display(oledb_t *ctx)
Clear Display function.
void oledb_set_column(oledb_t *ctx, oledb_data_t col_addr)
Column Setting function.
void oledb_scroll_left(oledb_t *ctx, oledb_data_t start_page_addr, oledb_data_t end_page_addr)
Scroll Left function.
void oledb_write_string(oledb_t *ctx, uint8_t font, uint8_t row, uint8_t position, uint8_t *data_in)
Write String function.
void oledb_cfg_setup(oledb_cfg_t *cfg)
Configuration Object Setup function.
void oledb_set_page(oledb_t *ctx, oledb_data_t page_addr)
Page Setting function.
void oledb_scroll_diag_right(oledb_t *ctx, oledb_data_t start_page_addr, oledb_data_t end_page_addr)
Scroll Diagonally Right function.
uint8_t oledb_select_t
Communication type.
Definition oledb.h:173
const uint8_t oledb_resources_t
Definition oledb.h:167
struct oledb_s oledb_t
Click context object definition.
uint8_t oledb_drv_select_t
Definition oledb.h:163
uint8_t oledb_data_t
Definition oledb.h:165
void(* oledb_master_write_t)(struct oledb_s *, oledb_data_t *, uint8_t)
Definition oledb.h:169
Click configuration structure definition.
Definition oledb.h:204
pin_name_t sdi
Definition oledb.h:210
uint32_t i2c_speed
Definition oledb.h:217
oledb_select_t sel
Definition oledb.h:228
spi_master_chip_select_polarity_t cs_polarity
Definition oledb.h:221
pin_name_t sck
Definition oledb.h:209
spi_master_mode_t spi_mode
Definition oledb.h:220
pin_name_t dc
Definition oledb.h:207
uint32_t spi_speed
Definition oledb.h:219
pin_name_t scl
Definition oledb.h:211
pin_name_t miso
Definition oledb.h:213
pin_name_t sda
Definition oledb.h:212
pin_name_t rst
Definition oledb.h:206
pin_name_t cs
Definition oledb.h:208
uint8_t i2c_address
Definition oledb.h:218
Click context object definition.
Definition oledb.h:179
digital_out_t cs
Definition oledb.h:181
spi_master_t spi
Definition oledb.h:186
oledb_select_t master_sel
Definition oledb.h:196
digital_out_t dc
Definition oledb.h:183
oledb_master_write_t send
Definition oledb.h:195
i2c_master_t i2c
Definition oledb.h:187
digital_out_t rst
Definition oledb.h:182
uint8_t slave_address
Definition oledb.h:191
pin_name_t chip_select
Definition oledb.h:192