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 
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 
53 // -------------------------------------------------------------- PUBLIC MACROS
64 #define OLEDC_MAP_MIKROBUS( cfg, mikrobus ) \
65  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
66  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
67  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
68  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
69  cfg.rw = MIKROBUS( mikrobus, MIKROBUS_AN ); \
70  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
71  cfg.dc = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
72  cfg.en = MIKROBUS( mikrobus, MIKROBUS_INT );
73 
79 #define OLEDC_RETVAL uint8_t
80 
81 #define OLEDC_OK 0x00
82 #define OLEDC_INIT_ERROR 0xFF
83 
89 #define OLEDC_FO_HORIZONTAL 0x00
90 #define OLEDC_FO_VERTICAL 0x01
91 #define OLEDC_FO_VERTICAL_COLUMN 0x02
92 
98 #define OLEDC_RMP_INC_HOR 0x00
99 #define OLEDC_RMP_INC_VER 0x01
100 #define OLEDC_RMP_COLOR_NOR 0x00
101 #define OLEDC_RMP_COLOR_REV 0x02
102 #define OLEDC_RMP_SEQ_RGB 0x00
103 #define OLEDC_RMP_SEQ_BGR 0x04
104 #define OLEDC_RMP_SCAN_NOR 0x00
105 #define OLEDC_RMP_SCAN_REV 0x10
106 #define OLEDC_RMP_SPLIT_DISABLE 0x00
107 #define OLEDC_RMP_SPLIT_ENABLE 0x20
108 #define OLEDC_COLOR_65K 0x00
109 #define OLEDC_COLOR_262K 0x80
110 #define OLEDC_IMG_HEAD 0x06
111 
117 #define OLEDC_SCREEN_WIDTH 0x60
118 #define OLEDC_SCREEN_HEIGHT 0x60
119 #define OLEDC_SCREEN_SIZE 0x2400
120 #define OLEDC_ROW_OFF 0x00
121 #define OLEDC_COL_OFF 0x10
122 
128 #define OLEDC_SET_COL_ADDRESS 0x15
129 #define OLEDC_SET_ROW_ADDRESS 0x75
130 #define OLEDC_WRITE_RAM 0x5C
131 #define OLEDC_READ_RAM 0x5D
132 #define OLEDC_SET_REMAP 0xA0
133 #define OLEDC_SET_START_LINE 0xA1
134 #define OLEDC_SET_OFFSET 0xA2
135 #define OLEDC_MODE_OFF 0xA4
136 #define OLEDC_MODE_ON 0xA5
137 #define OLEDC_MODE_NORMAL 0xA6
138 #define OLEDC_MODE_INVERSE 0xA7
139 #define OLEDC_FUNCTION 0xAB
140 #define OLEDC_SLEEP_ON 0xAE
141 #define OLEDC_SLEEP_OFF 0xAF
142 #define OLEDC_NOP 0xB0
143 #define OLEDC_SET_RESET_PRECH 0xB1
144 #define OLEDC_ENHANCEMENT 0xB2
145 #define OLEDC_CLOCK_DIV 0xB3
146 #define OLEDC_VSL 0xB4
147 #define OLEDC_GPIO 0xB5
148 #define OLEDC_SETSEC_PRECH 0xB6
149 #define OLEDC_GREY_SCALE 0xB8
150 #define OLEDC_LUT 0xB9
151 #define OLEDC_PRECH_VOL 0xBB
152 #define OLEDC_VCOMH 0xBE
153 #define OLEDC_CONTRAST 0xC1
154 #define OLEDC_MASTER_CONTRAST 0xC7
155 #define OLEDC_MUX_RATIO 0xCA
156 #define OLEDC_COMMAND_LOCK 0xFD
157 #define OLEDC_SCROLL_HOR 0x96
158 #define OLEDC_START_MOV 0x9E
159 #define OLEDC_STOP_MOV 0x9F
160 
161 
162 #define OLEDC_DEFAULT_MUX_RATIO 95
163 #define OLEDC_DEFAULT_START_LINE 0x80
164 #define OLEDC_DEFAULT_OFFSET 0x20
165 
166 #define OLEDC_DEFAULT_OLED_LOCK 0x12
167 #define OLEDC_DEFAULT_CMD_LOCK 0xB1
168 #define OLEDC_DEFAULT_DIVSET 0xF1
169 #define OLEDC_DEFAULT_PRECHARGE 0x32
170 #define OLEDC_DEFAULT_VCOMH 0x05
171 #define OLEDC_DEFAULT_MASTER_CONT 0xCF
172 #define OLEDC_DEFAULT_PRECHARGE_2 0x01
173  // End group macro
178 // --------------------------------------------------------------- PUBLIC TYPES
187 typedef struct
188 {
189  // Output pins
190 
191  digital_out_t rw;
192  digital_out_t rst;
193  digital_out_t dc;
194  digital_out_t en;
195  digital_out_t cs;
196 
197  // Modules
198 
199  spi_master_t spi;
200  pin_name_t chip_select;
201 
202  const uint8_t* font_obj;
203  uint16_t font_color;
205  uint16_t font_first_char;
206  uint16_t font_last_char;
207  uint16_t font_height;
208  uint16_t x_cord;
209  uint16_t y_cord;
210 
211 } oledc_t;
212 
216 typedef struct
217 {
218  // Communication gpio pins
219 
220  pin_name_t miso;
221  pin_name_t mosi;
222  pin_name_t sck;
223  pin_name_t cs;
224 
225  // Additional gpio pins
226 
227  pin_name_t rw;
228  pin_name_t rst;
229  pin_name_t dc;
230  pin_name_t en;
231 
232  // static variable
233 
234  uint32_t spi_speed;
235  spi_master_mode_t spi_mode;
236  spi_master_chip_select_polarity_t cs_polarity;
237 
238 } oledc_cfg_t;
239  // End types group
241 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
242 
247 #ifdef __cplusplus
248 extern "C"{
249 #endif
250 
260 
269 
278 
287 void oledc_enable ( oledc_t *ctx, uint8_t state );
288 
296 void oledc_reset( oledc_t *ctx );
297 
308 void oledc_more_arg_commands ( oledc_t *ctx, uint8_t command, uint8_t *args, uint16_t args_len );
309 
319 void oledc_one_arg_commands ( oledc_t *ctx, uint8_t command, uint8_t args );
320 
329 void oledc_fill_screen ( oledc_t *ctx, uint16_t color );
330 
343 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 );
344 
357 void oledc_image( oledc_t *ctx, const uint8_t* img, uint8_t col_off, uint8_t row_off );
358 
369 void oledc_text( oledc_t *ctx, uint8_t *text, uint16_t x, uint16_t y );
370 
382 void oledc_set_font( oledc_t *ctx, const uint8_t *font_s, uint16_t color );
383 
384 #ifdef __cplusplus
385 }
386 #endif
387 #endif // _OLEDC_H_
388  // End public_function group
391 
392 // ------------------------------------------------------------------------- END
oledc_t::chip_select
pin_name_t chip_select
Definition: oledc.h:200
oledc_t::font_last_char
uint16_t font_last_char
Definition: oledc.h:206
oledc_cfg_t::miso
pin_name_t miso
Definition: oledc.h:220
oledc_t
Click ctx object definition.
Definition: oledc.h:188
oledc_reset
void oledc_reset(oledc_t *ctx)
Click Hardware Reset.
oledc_one_arg_commands
void oledc_one_arg_commands(oledc_t *ctx, uint8_t command, uint8_t args)
Command Send with one argument.
oledc_enable
void oledc_enable(oledc_t *ctx, uint8_t state)
Click Enable/Disable.
oledc_image
void oledc_image(oledc_t *ctx, const uint8_t *img, uint8_t col_off, uint8_t row_off)
Draw BMP Image.
oledc_cfg_t::spi_speed
uint32_t spi_speed
Definition: oledc.h:234
oledc_init
OLEDC_RETVAL oledc_init(oledc_t *ctx, oledc_cfg_t *cfg)
Initialization function.
oledc_t::dc
digital_out_t dc
Definition: oledc.h:193
oledc_more_arg_commands
void oledc_more_arg_commands(oledc_t *ctx, uint8_t command, uint8_t *args, uint16_t args_len)
Command Send with more argument.
oledc_cfg_t::cs
pin_name_t cs
Definition: oledc.h:223
oledc_cfg_t
Click configuration structure definition.
Definition: oledc.h:217
oledc_cfg_t::en
pin_name_t en
Definition: oledc.h:230
oledc_rectangle
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.
oledc_t::rw
digital_out_t rw
Definition: oledc.h:191
oledc_t::font_orientation
uint8_t font_orientation
Definition: oledc.h:204
oledc_t::rst
digital_out_t rst
Definition: oledc.h:192
oledc_t::spi
spi_master_t spi
Definition: oledc.h:199
oledc_cfg_t::rst
pin_name_t rst
Definition: oledc.h:228
oledc_t::font_height
uint16_t font_height
Definition: oledc.h:207
oledc_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: oledc.h:236
oledc_cfg_setup
void oledc_cfg_setup(oledc_cfg_t *cfg)
Config Object Initialization function.
oledc_cfg_t::mosi
pin_name_t mosi
Definition: oledc.h:221
oledc_fill_screen
void oledc_fill_screen(oledc_t *ctx, uint16_t color)
Fill Screen.
oledc_t::en
digital_out_t en
Definition: oledc.h:194
oledc_cfg_t::rw
pin_name_t rw
Definition: oledc.h:227
oledc_default_cfg
void oledc_default_cfg(oledc_t *ctx)
Click Default Configuration function.
oledc_set_font
void oledc_set_font(oledc_t *ctx, const uint8_t *font_s, uint16_t color)
Font Setup.
oledc_t::cs
digital_out_t cs
Definition: oledc.h:195
oledc_t::font_first_char
uint16_t font_first_char
Definition: oledc.h:205
oledc_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: oledc.h:235
oledc_t::y_cord
uint16_t y_cord
Definition: oledc.h:209
OLEDC_RETVAL
#define OLEDC_RETVAL
Definition: oledc.h:79
oledc_t::font_color
uint16_t font_color
Definition: oledc.h:203
oledc_cfg_t::sck
pin_name_t sck
Definition: oledc.h:222
oledc_t::font_obj
const uint8_t * font_obj
Definition: oledc.h:202
oledc_text
void oledc_text(oledc_t *ctx, uint8_t *text, uint16_t x, uint16_t y)
Draw Text.
oledc_t::x_cord
uint16_t x_cord
Definition: oledc.h:208
oledc_cfg_t::dc
pin_name_t dc
Definition: oledc.h:229