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 );
77 
83 #define OLEDC_RETVAL uint8_t
84 
85 #define OLEDC_OK 0x00
86 #define OLEDC_INIT_ERROR 0xFF
87 
93 #define OLEDC_FO_HORIZONTAL 0x00
94 #define OLEDC_FO_VERTICAL 0x01
95 #define OLEDC_FO_VERTICAL_COLUMN 0x02
96 
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
115 
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
126 
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
177  // End group macro
182 // --------------------------------------------------------------- PUBLIC TYPES
191 typedef 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;
209  uint16_t font_first_char;
210  uint16_t font_last_char;
211  uint16_t font_height;
212  uint16_t x_cord;
213  uint16_t y_cord;
214 
215 } oledc_t;
216 
220 typedef 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 
242 } oledc_cfg_t;
243  // End types group
245 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
246 
251 #ifdef __cplusplus
252 extern "C"{
253 #endif
254 
264 
273 
282 
291 void oledc_enable ( oledc_t *ctx, uint8_t state );
292 
300 void oledc_reset( oledc_t *ctx );
301 
312 void oledc_more_arg_commands ( oledc_t *ctx, uint8_t command, uint8_t *args, uint16_t args_len );
313 
323 void oledc_one_arg_commands ( oledc_t *ctx, uint8_t command, uint8_t args );
324 
333 void oledc_fill_screen ( oledc_t *ctx, uint16_t color );
334 
347 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 );
348 
361 void oledc_image( oledc_t *ctx, const uint8_t* img, uint8_t col_off, uint8_t row_off );
362 
373 void oledc_text( oledc_t *ctx, uint8_t *text, uint16_t x, uint16_t y );
374 
386 void 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  // End public_function group
395 
396 // ------------------------------------------------------------------------- END
oledc_t::chip_select
pin_name_t chip_select
Definition: oledc.h:204
oledc_t::font_last_char
uint16_t font_last_char
Definition: oledc.h:210
oledc_cfg_t::miso
pin_name_t miso
Definition: oledc.h:224
oledc_t
Click ctx object definition.
Definition: oledc.h:192
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:238
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:197
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:227
oledc_cfg_t
Click configuration structure definition.
Definition: oledc.h:221
oledc_cfg_t::en
pin_name_t en
Definition: oledc.h:234
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:195
oledc_t::font_orientation
uint8_t font_orientation
Definition: oledc.h:208
oledc_t::rst
digital_out_t rst
Definition: oledc.h:196
oledc_t::spi
spi_master_t spi
Definition: oledc.h:203
oledc_cfg_t::rst
pin_name_t rst
Definition: oledc.h:232
oledc_t::font_height
uint16_t font_height
Definition: oledc.h:211
oledc_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: oledc.h:240
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:225
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:198
oledc_cfg_t::rw
pin_name_t rw
Definition: oledc.h:231
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:199
oledc_t::font_first_char
uint16_t font_first_char
Definition: oledc.h:209
oledc_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: oledc.h:239
oledc_t::y_cord
uint16_t y_cord
Definition: oledc.h:213
OLEDC_RETVAL
#define OLEDC_RETVAL
Definition: oledc.h:83
oledc_t::font_color
uint16_t font_color
Definition: oledc.h:207
oledc_cfg_t::sck
pin_name_t sck
Definition: oledc.h:226
oledc_t::font_obj
const uint8_t * font_obj
Definition: oledc.h:206
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:212
oledc_cfg_t::dc
pin_name_t dc
Definition: oledc.h:233