oledc  2.0.0.0
oledc.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright (c) 2019, MikroElektronika - www.mikroe.com
4  * All rights reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef OLEDC_H
36 #define OLEDC_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_spi_master.h"
41 
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
54 #define OLEDC_MAP_MIKROBUS( cfg, mikrobus ) \
55  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
56  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
57  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
58  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
59  cfg.rw = MIKROBUS( mikrobus, MIKROBUS_AN ); \
60  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
61  cfg.dc = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
62  cfg.en = MIKROBUS( mikrobus, MIKROBUS_INT );
63 
69 #define OLEDC_RETVAL uint8_t
70 
71 #define OLEDC_OK 0x00
72 #define OLEDC_INIT_ERROR 0xFF
73 
79 #define OLEDC_FO_HORIZONTAL 0x00
80 #define OLEDC_FO_VERTICAL 0x01
81 #define OLEDC_FO_VERTICAL_COLUMN 0x02
82 
88 #define OLEDC_RMP_INC_HOR 0x00
89 #define OLEDC_RMP_INC_VER 0x01
90 #define OLEDC_RMP_COLOR_NOR 0x00
91 #define OLEDC_RMP_COLOR_REV 0x02
92 #define OLEDC_RMP_SEQ_RGB 0x00
93 #define OLEDC_RMP_SEQ_BGR 0x04
94 #define OLEDC_RMP_SCAN_NOR 0x00
95 #define OLEDC_RMP_SCAN_REV 0x10
96 #define OLEDC_RMP_SPLIT_DISABLE 0x00
97 #define OLEDC_RMP_SPLIT_ENABLE 0x20
98 #define OLEDC_COLOR_65K 0x00
99 #define OLEDC_COLOR_262K 0x80
100 #define OLEDC_IMG_HEAD 0x06
101 
107 #define OLEDC_SCREEN_WIDTH 0x60
108 #define OLEDC_SCREEN_HEIGHT 0x60
109 #define OLEDC_SCREEN_SIZE 0x2400
110 #define OLEDC_ROW_OFF 0x00
111 #define OLEDC_COL_OFF 0x10
112 
118 #define OLEDC_SET_COL_ADDRESS 0x15
119 #define OLEDC_SET_ROW_ADDRESS 0x75
120 #define OLEDC_WRITE_RAM 0x5C
121 #define OLEDC_READ_RAM 0x5D
122 #define OLEDC_SET_REMAP 0xA0
123 #define OLEDC_SET_START_LINE 0xA1
124 #define OLEDC_SET_OFFSET 0xA2
125 #define OLEDC_MODE_OFF 0xA4
126 #define OLEDC_MODE_ON 0xA5
127 #define OLEDC_MODE_NORMAL 0xA6
128 #define OLEDC_MODE_INVERSE 0xA7
129 #define OLEDC_FUNCTION 0xAB
130 #define OLEDC_SLEEP_ON 0xAE
131 #define OLEDC_SLEEP_OFF 0xAF
132 #define OLEDC_NOP 0xB0
133 #define OLEDC_SET_RESET_PRECH 0xB1
134 #define OLEDC_ENHANCEMENT 0xB2
135 #define OLEDC_CLOCK_DIV 0xB3
136 #define OLEDC_VSL 0xB4
137 #define OLEDC_GPIO 0xB5
138 #define OLEDC_SETSEC_PRECH 0xB6
139 #define OLEDC_GREY_SCALE 0xB8
140 #define OLEDC_LUT 0xB9
141 #define OLEDC_PRECH_VOL 0xBB
142 #define OLEDC_VCOMH 0xBE
143 #define OLEDC_CONTRAST 0xC1
144 #define OLEDC_MASTER_CONTRAST 0xC7
145 #define OLEDC_MUX_RATIO 0xCA
146 #define OLEDC_COMMAND_LOCK 0xFD
147 #define OLEDC_SCROLL_HOR 0x96
148 #define OLEDC_START_MOV 0x9E
149 #define OLEDC_STOP_MOV 0x9F
150 
151 
152 #define OLEDC_DEFAULT_MUX_RATIO 95
153 #define OLEDC_DEFAULT_START_LINE 0x80
154 #define OLEDC_DEFAULT_OFFSET 0x20
155 
156 #define OLEDC_DEFAULT_OLED_LOCK 0x12
157 #define OLEDC_DEFAULT_CMD_LOCK 0xB1
158 #define OLEDC_DEFAULT_DIVSET 0xF1
159 #define OLEDC_DEFAULT_PRECHARGE 0x32
160 #define OLEDC_DEFAULT_VCOMH 0x05
161 #define OLEDC_DEFAULT_MASTER_CONT 0xCF
162 #define OLEDC_DEFAULT_PRECHARGE_2 0x01
163  // End group macro
168 // --------------------------------------------------------------- PUBLIC TYPES
177 typedef struct
178 {
179  // Output pins
180 
181  digital_out_t rw;
182  digital_out_t rst;
183  digital_out_t dc;
184  digital_out_t en;
185 
186  // Modules
187 
188  spi_master_t spi;
189 
190  const uint8_t* font_obj;
191  uint16_t font_color;
193  uint16_t font_first_char;
194  uint16_t font_last_char;
195  uint16_t font_height;
196  uint16_t x_cord;
197  uint16_t y_cord;
198 
199 } oledc_t;
200 
204 typedef struct
205 {
206  // Communication gpio pins
207 
208  pin_name_t miso;
209  pin_name_t mosi;
210  pin_name_t sck;
211  pin_name_t cs;
212 
213  // Additional gpio pins
214 
215  pin_name_t rw;
216  pin_name_t rst;
217  pin_name_t dc;
218  pin_name_t en;
219 
220  // static variable
221 
222  hal_spi_speed_t spi_speed;
223  hal_spi_mode_t spi_mode;
224 
225 } oledc_cfg_t;
226  // End types group
228 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
229 
234 #ifdef __cplusplus
235 extern "C"{
236 #endif
237 
246 void oledc_cfg_setup ( oledc_cfg_t *cfg );
247 
256 
264 void oledc_default_cfg ( oledc_t *ctx );
265 
274 void oledc_enable ( oledc_t *ctx, uint8_t state );
275 
283 void oledc_reset( oledc_t *ctx );
284 
295 void oledc_more_arg_commands ( oledc_t *ctx, uint8_t command, uint8_t *args, uint16_t args_len );
296 
306 void oledc_one_arg_commands ( oledc_t *ctx, uint8_t command, uint8_t args );
307 
316 void oledc_fill_screen ( oledc_t *ctx, uint16_t color );
317 
330 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 );
331 
344 void oledc_image( oledc_t *ctx, const uint8_t* img, uint8_t col_off, uint8_t row_off );
345 
356 void oledc_text( oledc_t *ctx, uint8_t *text, uint16_t x, uint16_t y );
357 
369 void oledc_set_font( oledc_t *ctx, const uint8_t *font_s, uint16_t color );
370 
371 #ifdef __cplusplus
372 }
373 #endif
374 #endif // _OLEDC_H_
375  // End public_function group
378 
379 // ------------------------------------------------------------------------- END
spi_master_t spi
Definition: oledc.h:188
uint16_t y_cord
Definition: oledc.h:197
pin_name_t rst
Definition: oledc.h:216
pin_name_t dc
Definition: oledc.h:217
void oledc_text(oledc_t *ctx, uint8_t *text, uint16_t x, uint16_t y)
Draw Text.
void oledc_fill_screen(oledc_t *ctx, uint16_t color)
Fill Screen.
pin_name_t rw
Definition: oledc.h:215
uint8_t font_orientation
Definition: oledc.h:192
hal_spi_mode_t spi_mode
Definition: oledc.h:223
digital_out_t rst
Definition: oledc.h:182
digital_out_t dc
Definition: oledc.h:183
uint16_t x_cord
Definition: oledc.h:196
digital_out_t en
Definition: oledc.h:184
OLEDC_RETVAL oledc_init(oledc_t *ctx, oledc_cfg_t *cfg)
Initialization function.
void oledc_cfg_setup(oledc_cfg_t *cfg)
Config Object Initialization function.
const uint8_t * font_obj
Definition: oledc.h:190
pin_name_t mosi
Definition: oledc.h:209
hal_spi_speed_t spi_speed
Definition: oledc.h:222
pin_name_t miso
Definition: oledc.h:208
pin_name_t cs
Definition: oledc.h:211
uint16_t font_height
Definition: oledc.h:195
void oledc_enable(oledc_t *ctx, uint8_t state)
Click Enable/Disable.
uint16_t font_color
Definition: oledc.h:191
void oledc_set_font(oledc_t *ctx, const uint8_t *font_s, uint16_t color)
Font Setup.
void oledc_one_arg_commands(oledc_t *ctx, uint8_t command, uint8_t args)
Command Send with one argument.
#define OLEDC_RETVAL
Definition: oledc.h:69
pin_name_t sck
Definition: oledc.h:210
pin_name_t en
Definition: oledc.h:218
void oledc_image(oledc_t *ctx, const uint8_t *img, uint8_t col_off, uint8_t row_off)
Draw BMP Image.
void oledc_default_cfg(oledc_t *ctx)
Click Default Configuration function.
digital_out_t rw
Definition: oledc.h:181
uint16_t font_last_char
Definition: oledc.h:194
void oledc_more_arg_commands(oledc_t *ctx, uint8_t command, uint8_t *args, uint16_t args_len)
Command Send with more argument.
void oledc_reset(oledc_t *ctx)
Click Hardware Reset.
Click ctx object definition.
Definition: oledc.h:177
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.
Click configuration structure definition.
Definition: oledc.h:204
uint16_t font_first_char
Definition: oledc.h:193