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 
31 #include "drv_digital_out.h"
32 #include "drv_i2c_master.h"
33 #include "drv_spi_master.h"
34 
35 // -------------------------------------------------------------- PUBLIC MACROS
45 #define OLEDB_LCDWIDTH 96
46 #define OLEDB_LCDHEIGHT 39
47 #define OLEDB_DISPLAYOFF 0xAE
48 #define OLEDB_SETDISPLAYCLOCKDIV 0xD5
49 #define OLEDB_SETMULTIPLEX 0xA8
50 #define OLEDB_SETDISPLAYOFFSET 0xD3
51 #define OLEDB_SETSTARTLINE 0x40
52 #define OLEDB_CHARGEPUMP 0x8D
53 #define OLEDB_SETSEGMENTREMAP 0xA1
54 #define OLEDB_SEGREMAP 0xA0
55 #define OLEDB_COMSCANDEC 0xC8
56 #define OLEDB_SETCOMPINS 0xDA
57 #define OLEDB_SETCONTRAST 0x81
58 #define OLEDB_SETPRECHARGE 0xD9
59 #define OLEDB_SETVCOMDETECT 0xDB
60 #define OLEDB_DISPLAYALLON_RESUME 0xA4
61 #define OLEDB_NORMALDISPLAY 0xA6
62 #define OLEDB_DISPLAYON 0xAF
63 #define OLEDB_DISPLAYALLON 0xA5
64 #define OLEDB_INVERTDISPLAY 0xA7
65 #define OLEDB_SETLOWCOLUMN 0x00
66 #define OLEDB_SETHIGHCOLUMN 0x10
67 #define OLEDB_MEMORYMODE 0x20
68 #define OLEDB_COLUMNADDR 0x21
69 #define OLEDB_PAGEADDR 0x22
70 #define OLEDB_COMSCANINC 0xC0
71 #define OLEDB_EXTERNALVCC 0x1
72 #define OLEDB_SWITCHCAPVCC 0x2
73 #define OLEDB_ACTIVATE_SCROLL 0x2F
74 #define OLEDB_DEACTIVATE_SCROLL 0x2E
75 #define OLEDB_SET_VERTICAL_SCROLL_AREA 0xA3
76 #define OLEDB_RIGHT_HORIZONTAL_SCROLL 0x26
77 #define OLEDB_LEFT_HORIZONTAL_SCROLL 0x27
78 #define OLEDB_VERTICAL_AND_RIGHT_HORIZONTAL_SCROLL 0x29
79 #define OLEDB_VERTICAL_AND_LEFT_HORIZONTAL_SCROLL 0x2A
80 
86 #define OLEDB_COMMAND 0x3C
87 #define OLEDB_DATA 0x3D
88 
94 #define OLEDB_MASTER_I2C 0
95 #define OLEDB_MASTER_SPI 1
96 
107 #define err_t uint8_t
108 
114 #define OLEDB_OK 0x00
115 #define OLEDB_INIT_ERROR 0xFF
116 #define OLEDB_INVALID_DATA_MODE 0xFE
117 #define OLEDB_INVALID_DRIVER_SELECTOR 0xFD
118  // End error group
121 
126 #define OLEDB_MAP_MIKROBUS( cfg, mikrobus ) \
127  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
128  cfg.dc = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
129  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
130  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
131  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
132  cfg.sdi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
133  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
134  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
135  // End macros group
138 // --------------------------------------------------------------- PUBLIC TYPES
144 typedef uint8_t oledb_drv_select_t;
145 
146 typedef uint8_t oledb_data_t;
147 typedef uint8_t oledb_data_mode_t;
148 
149 typedef const uint8_t oledb_resources_t;
150 
155 typedef uint8_t oledb_select_t;
156 
160 typedef struct oledb_s
161 {
162  // Click mikrobus DRV objects.
163  digital_out_t cs;
164  digital_out_t rst;
165  digital_out_t dc;
166 
167  // Modules
168  spi_master_t spi;
169  i2c_master_t i2c;
170 
171  // ctx variable
172 
173  uint8_t slave_address;
174  pin_name_t chip_select;
175 
176  // Click send function pointer.
179 
181 
185 typedef struct
186 {
187  // Used mikrobus pins.
188  pin_name_t rst;
189  pin_name_t dc;
190  pin_name_t cs;
191  pin_name_t sck;
192  pin_name_t sdi;
193  pin_name_t scl;
194  pin_name_t sda;
195  pin_name_t miso;
196 
197  // static variable
198 
199  uint32_t i2c_speed;
200  uint8_t i2c_address;
201  uint32_t spi_speed;
202  spi_master_mode_t spi_mode;
203  spi_master_chip_select_polarity_t cs_polarity;
204 
211 
212 } oledb_cfg_t;
213  // End types group
215 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
221 #ifdef __cplusplus
222 extern "C"{
223 #endif
224 
236 
250 
264 
273 
282 void oledb_set_page( oledb_t *ctx, oledb_data_t page_addr );
283 
292 void oledb_set_column( oledb_t *ctx, oledb_data_t col_addr );
293 
304 
314 
324 void oledb_scroll_right( oledb_t *ctx, oledb_data_t start_page_addr, oledb_data_t end_page_addr );
325 
335 void oledb_scroll_left( oledb_t *ctx, oledb_data_t start_page_addr, oledb_data_t end_page_addr );
336 
346 void oledb_scroll_diag_right( oledb_t *ctx, oledb_data_t start_page_addr, oledb_data_t end_page_addr );
347 
357 void oledb_scroll_diag_left( oledb_t *ctx, oledb_data_t start_page_addr, oledb_data_t end_page_addr );
358 
367 
368 #ifdef __cplusplus
369 }
370 #endif
371 #endif // OLEDB_H
372  // oledb
374 
375 // ------------------------------------------------------------------------ END
oledb_init
err_t oledb_init(oledb_t *ctx, oledb_cfg_t *cfg)
Click Initialization function.
oledb_s::spi
spi_master_t spi
Definition: oledb.h:168
oledb_set_column
void oledb_set_column(oledb_t *ctx, oledb_data_t col_addr)
Column Setting function.
oledb_scroll_left
void oledb_scroll_left(oledb_t *ctx, oledb_data_t start_page_addr, oledb_data_t end_page_addr)
Scroll Left function.
oledb_send
err_t oledb_send(oledb_t *ctx, oledb_data_t tx_data, oledb_data_mode_t data_mode)
Send function.
oledb_s::slave_address
uint8_t slave_address
Definition: oledb.h:173
oledb_s::dc
digital_out_t dc
Definition: oledb.h:165
oledb_cfg_t::spi_speed
uint32_t spi_speed
Definition: oledb.h:201
oledb_data_t
uint8_t oledb_data_t
Definition: oledb.h:146
oledb_t
struct oledb_s oledb_t
Click context object definition.
oledb_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: oledb.h:202
oledb_cfg_t::sel
oledb_select_t sel
Definition: oledb.h:210
oledb_cfg_setup
void oledb_cfg_setup(oledb_cfg_t *cfg)
Configuration Object Setup function.
oledb_s::chip_select
pin_name_t chip_select
Definition: oledb.h:174
oledb_cfg_t
Click configuration structure definition.
Definition: oledb.h:186
oledb_display_picture
void oledb_display_picture(oledb_t *ctx, oledb_resources_t *pic)
Display Picture function.
oledb_cfg_t::sda
pin_name_t sda
Definition: oledb.h:194
oledb_cfg_t::scl
pin_name_t scl
Definition: oledb.h:193
oledb_s::cs
digital_out_t cs
Definition: oledb.h:163
oledb_s::master_sel
oledb_select_t master_sel
Definition: oledb.h:178
oledb_cfg_t::sdi
pin_name_t sdi
Definition: oledb.h:192
oledb_cfg_t::dc
pin_name_t dc
Definition: oledb.h:189
oledb_cfg_t::miso
pin_name_t miso
Definition: oledb.h:195
oledb_select_t
uint8_t oledb_select_t
Communication type.
Definition: oledb.h:155
oledb_scroll_diag_left
void oledb_scroll_diag_left(oledb_t *ctx, oledb_data_t start_page_addr, oledb_data_t end_page_addr)
Scroll Diagonally Left function.
oledb_scroll_right
void oledb_scroll_right(oledb_t *ctx, oledb_data_t start_page_addr, oledb_data_t end_page_addr)
Scroll Right function.
oledb_set_page
void oledb_set_page(oledb_t *ctx, oledb_data_t page_addr)
Page Setting function.
oledb_stop_scroll
void oledb_stop_scroll(oledb_t *ctx)
Stop Scrolling function.
oledb_s
Click context object definition.
Definition: oledb.h:161
oledb_s::send
oledb_master_write_t send
Definition: oledb.h:177
oledb_cfg_t::i2c_address
uint8_t i2c_address
Definition: oledb.h:200
oledb_data_mode_t
uint8_t oledb_data_mode_t
Definition: oledb.h:147
oledb_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: oledb.h:199
oledb_drv_select_t
uint8_t oledb_drv_select_t
Definition: oledb.h:144
oledb_s::rst
digital_out_t rst
Definition: oledb.h:164
oledb_cfg_t::cs
pin_name_t cs
Definition: oledb.h:190
oledb_master_write_t
err_t(* oledb_master_write_t)(struct oledb_s *, oledb_data_t, oledb_data_mode_t)
Definition: oledb.h:151
oledb_scroll_diag_right
void oledb_scroll_diag_right(oledb_t *ctx, oledb_data_t start_page_addr, oledb_data_t end_page_addr)
Scroll Diagonally Right function.
oledb_cfg_t::sck
pin_name_t sck
Definition: oledb.h:191
oledb_default_cfg
void oledb_default_cfg(oledb_t *ctx)
Click Default Configuration function.
oledb_cfg_t::rst
pin_name_t rst
Definition: oledb.h:188
err_t
#define err_t
Definition: oledb.h:107
oledb_s::i2c
i2c_master_t i2c
Definition: oledb.h:169
oledb_set_contrast
void oledb_set_contrast(oledb_t *ctx, oledb_data_t value)
Contrast Setting function.
oledb_resources_t
const uint8_t oledb_resources_t
Definition: oledb.h:149
oledb_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: oledb.h:203