oledc 2.0.0.0
oledc.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 OLEDC_H
36#define OLEDC_H
37
42#ifdef PREINIT_SUPPORTED
43#include "preinit.h"
44#endif
45
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
48 #include "delays.h"
49 #endif
50#endif
51
52#include "drv_digital_out.h"
53#include "drv_digital_in.h"
54#include "drv_spi_master.h"
55
56
57// -------------------------------------------------------------- PUBLIC MACROS
68#define OLEDC_MAP_MIKROBUS( cfg, mikrobus ) \
69 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
70 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
71 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
72 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
73 cfg.rw = MIKROBUS( mikrobus, MIKROBUS_AN ); \
74 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
75 cfg.dc = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
76 cfg.en = MIKROBUS( mikrobus, MIKROBUS_INT );
83#define OLEDC_RETVAL uint8_t
84
85#define OLEDC_OK 0x00
86#define OLEDC_INIT_ERROR 0xFF
93#define OLEDC_FO_HORIZONTAL 0x00
94#define OLEDC_FO_VERTICAL 0x01
95#define OLEDC_FO_VERTICAL_COLUMN 0x02
102#define OLEDC_RMP_INC_HOR 0x00
103#define OLEDC_RMP_INC_VER 0x01
104#define OLEDC_RMP_COLOR_NOR 0x00
105#define OLEDC_RMP_COLOR_REV 0x02
106#define OLEDC_RMP_SEQ_RGB 0x00
107#define OLEDC_RMP_SEQ_BGR 0x04
108#define OLEDC_RMP_SCAN_NOR 0x00
109#define OLEDC_RMP_SCAN_REV 0x10
110#define OLEDC_RMP_SPLIT_DISABLE 0x00
111#define OLEDC_RMP_SPLIT_ENABLE 0x20
112#define OLEDC_COLOR_65K 0x00
113#define OLEDC_COLOR_262K 0x80
114#define OLEDC_IMG_HEAD 0x06
121#define OLEDC_SCREEN_WIDTH 0x60
122#define OLEDC_SCREEN_HEIGHT 0x60
123#define OLEDC_SCREEN_SIZE 0x2400
124#define OLEDC_ROW_OFF 0x00
125#define OLEDC_COL_OFF 0x10
132#define OLEDC_SET_COL_ADDRESS 0x15
133#define OLEDC_SET_ROW_ADDRESS 0x75
134#define OLEDC_WRITE_RAM 0x5C
135#define OLEDC_READ_RAM 0x5D
136#define OLEDC_SET_REMAP 0xA0
137#define OLEDC_SET_START_LINE 0xA1
138#define OLEDC_SET_OFFSET 0xA2
139#define OLEDC_MODE_OFF 0xA4
140#define OLEDC_MODE_ON 0xA5
141#define OLEDC_MODE_NORMAL 0xA6
142#define OLEDC_MODE_INVERSE 0xA7
143#define OLEDC_FUNCTION 0xAB
144#define OLEDC_SLEEP_ON 0xAE
145#define OLEDC_SLEEP_OFF 0xAF
146#define OLEDC_NOP 0xB0
147#define OLEDC_SET_RESET_PRECH 0xB1
148#define OLEDC_ENHANCEMENT 0xB2
149#define OLEDC_CLOCK_DIV 0xB3
150#define OLEDC_VSL 0xB4
151#define OLEDC_GPIO 0xB5
152#define OLEDC_SETSEC_PRECH 0xB6
153#define OLEDC_GREY_SCALE 0xB8
154#define OLEDC_LUT 0xB9
155#define OLEDC_PRECH_VOL 0xBB
156#define OLEDC_VCOMH 0xBE
157#define OLEDC_CONTRAST 0xC1
158#define OLEDC_MASTER_CONTRAST 0xC7
159#define OLEDC_MUX_RATIO 0xCA
160#define OLEDC_COMMAND_LOCK 0xFD
161#define OLEDC_SCROLL_HOR 0x96
162#define OLEDC_START_MOV 0x9E
163#define OLEDC_STOP_MOV 0x9F
164
165
166#define OLEDC_DEFAULT_MUX_RATIO 95
167#define OLEDC_DEFAULT_START_LINE 0x80
168#define OLEDC_DEFAULT_OFFSET 0x20
169
170#define OLEDC_DEFAULT_OLED_LOCK 0x12
171#define OLEDC_DEFAULT_CMD_LOCK 0xB1
172#define OLEDC_DEFAULT_DIVSET 0xF1
173#define OLEDC_DEFAULT_PRECHARGE 0x32
174#define OLEDC_DEFAULT_VCOMH 0x05
175#define OLEDC_DEFAULT_MASTER_CONT 0xCF
176#define OLEDC_DEFAULT_PRECHARGE_2 0x01
181 // End group macro
182// --------------------------------------------------------------- PUBLIC TYPES
191typedef struct
192{
193 // Output pins
194
195 digital_out_t rw;
196 digital_out_t rst;
197 digital_out_t dc;
198 digital_out_t en;
199 digital_out_t cs;
200
201 // Modules
202
203 spi_master_t spi;
204 pin_name_t chip_select;
205
206 const uint8_t* font_obj;
207 uint16_t font_color;
211 uint16_t font_height;
212 uint16_t x_cord;
213 uint16_t y_cord;
214
215} oledc_t;
216
220typedef struct
221{
222 // Communication gpio pins
223
224 pin_name_t miso;
225 pin_name_t mosi;
226 pin_name_t sck;
227 pin_name_t cs;
228
229 // Additional gpio pins
230
231 pin_name_t rw;
232 pin_name_t rst;
233 pin_name_t dc;
234 pin_name_t en;
235
236 // static variable
237
238 uint32_t spi_speed;
239 spi_master_mode_t spi_mode;
240 spi_master_chip_select_polarity_t cs_polarity;
241
243
244 // End types group
245// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
246
251#ifdef __cplusplus
252extern "C"{
253#endif
254
264
273
282
291void oledc_enable ( oledc_t *ctx, uint8_t state );
292
300void oledc_reset( oledc_t *ctx );
301
312void oledc_more_arg_commands ( oledc_t *ctx, uint8_t command, uint8_t *args, uint16_t args_len );
313
323void oledc_one_arg_commands ( oledc_t *ctx, uint8_t command, uint8_t args );
324
333void oledc_fill_screen ( oledc_t *ctx, uint16_t color );
334
347void oledc_rectangle( oledc_t *ctx, uint8_t col_off, uint8_t row_off, uint8_t col_end, uint8_t row_end, uint16_t color );
348
361void oledc_image( oledc_t *ctx, const uint8_t* img, uint8_t col_off, uint8_t row_off );
362
373void oledc_text( oledc_t *ctx, uint8_t *text, uint16_t x, uint16_t y );
374
386void oledc_set_font( oledc_t *ctx, const uint8_t *font_s, uint16_t color );
387
388#ifdef __cplusplus
389}
390#endif
391#endif // _OLEDC_H_
392
393 // End public_function group
395
396// ------------------------------------------------------------------------- END
#define OLEDC_RETVAL
Definition oledc.h:83
void oledc_one_arg_commands(oledc_t *ctx, uint8_t command, uint8_t args)
Command Send with one argument.
void oledc_more_arg_commands(oledc_t *ctx, uint8_t command, uint8_t *args, uint16_t args_len)
Command Send with more argument.
OLEDC_RETVAL oledc_init(oledc_t *ctx, oledc_cfg_t *cfg)
Initialization function.
void oledc_fill_screen(oledc_t *ctx, uint16_t color)
Fill Screen.
void oledc_image(oledc_t *ctx, const uint8_t *img, uint8_t col_off, uint8_t row_off)
Draw BMP Image.
void oledc_reset(oledc_t *ctx)
Click Hardware Reset.
void oledc_default_cfg(oledc_t *ctx)
Click Default Configuration function.
void oledc_text(oledc_t *ctx, uint8_t *text, uint16_t x, uint16_t y)
Draw Text.
void oledc_enable(oledc_t *ctx, uint8_t state)
Click Enable/Disable.
void oledc_set_font(oledc_t *ctx, const uint8_t *font_s, uint16_t color)
Font Setup.
void oledc_rectangle(oledc_t *ctx, uint8_t col_off, uint8_t row_off, uint8_t col_end, uint8_t row_end, uint16_t color)
Draw Rectangle.
void oledc_cfg_setup(oledc_cfg_t *cfg)
Config Object Initialization function.
Click configuration structure definition.
Definition oledc.h:221
spi_master_chip_select_polarity_t cs_polarity
Definition oledc.h:240
pin_name_t sck
Definition oledc.h:226
spi_master_mode_t spi_mode
Definition oledc.h:239
pin_name_t dc
Definition oledc.h:233
pin_name_t mosi
Definition oledc.h:225
uint32_t spi_speed
Definition oledc.h:238
pin_name_t en
Definition oledc.h:234
pin_name_t miso
Definition oledc.h:224
pin_name_t rst
Definition oledc.h:232
pin_name_t rw
Definition oledc.h:231
pin_name_t cs
Definition oledc.h:227
Click ctx object definition.
Definition oledc.h:192
digital_out_t cs
Definition oledc.h:199
spi_master_t spi
Definition oledc.h:203
uint16_t font_first_char
Definition oledc.h:209
uint16_t y_cord
Definition oledc.h:213
digital_out_t dc
Definition oledc.h:197
uint16_t font_height
Definition oledc.h:211
digital_out_t en
Definition oledc.h:198
digital_out_t rst
Definition oledc.h:196
digital_out_t rw
Definition oledc.h:195
const uint8_t * font_obj
Definition oledc.h:206
uint16_t x_cord
Definition oledc.h:212
pin_name_t chip_select
Definition oledc.h:204
uint16_t font_color
Definition oledc.h:207
uint8_t font_orientation
Definition oledc.h:208
uint16_t font_last_char
Definition oledc.h:210