oledswitch  2.0.0.0
oledswitch.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 OLEDSWITCH_H
36 #define OLEDSWITCH_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 // -------------------------------------------------------------- PUBLIC MACROS
63 #define OLEDSWITCH_MAP_MIKROBUS( cfg, mikrobus ) \
64  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
65  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
66  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
67  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
68  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
69  cfg.cd = MIKROBUS( mikrobus, MIKROBUS_PWM )
70 
76 #define OLEDSWITCH_RETVAL uint8_t
77 
78 #define OLEDSWITCH_OK 0x00
79 #define OLEDSWITCH_INIT_ERROR 0xFF
80 
86 #define OLEDSWITCH_15_CONTRAST_FOR_COLOR_A_1 0x81
87 #define OLEDSWITCH_15_CONTRAST_FOR_COLOR_A_2 0x19
88 #define OLEDSWITCH_15_CONTRAST_FOR_COLOR_B_1 0x82
89 #define OLEDSWITCH_15_CONTRAST_FOR_COLOR_B_2 0x14
90 #define OLEDSWITCH_15_CONTRAST_FOR_COLOR_C_1 0x83
91 #define OLEDSWITCH_15_CONTRAST_FOR_COLOR_C_2 0x24
92 
93 #define OLEDSWITCH_30_CONTRAST_FOR_COLOR_A_1 0x81
94 #define OLEDSWITCH_30_CONTRAST_FOR_COLOR_A_2 0x15
95 #define OLEDSWITCH_30_CONTRAST_FOR_COLOR_B_1 0x82
96 #define OLEDSWITCH_30_CONTRAST_FOR_COLOR_B_2 0x1A
97 #define OLEDSWITCH_30_CONTRAST_FOR_COLOR_C_1 0x83
98 #define OLEDSWITCH_30_CONTRAST_FOR_COLOR_C_2 0x17
99 
100 #define OLEDSWITCH_MASTER_CURRENT_CONTROL_1 0x87
101 #define OLEDSWITCH_MASTER_CURRENT_CONTROL_2 0x0F
102 
103 #define OLEDSWITCH_REMAP_AND_COLOR_DEPTH_SETTING_1 0xA0
104 #define OLEDSWITCH_REMAP_AND_COLOR_DEPTH_SETTING_2 0x70
105 
106 #define OLEDSWITCH_SET_DISPLAY_START_LINE_1 0xA1
107 #define OLEDSWITCH_SET_DISPLAY_START_LINE_2 0x00
108 
109 #define OLEDSWITCH_SET_DISPLAY_OFFSET_1 0xA2
110 #define OLEDSWITCH_SET_DISPLAY_OFFSET_2 0x10
111 
112 #define OLEDSWITCH_NORMAL_DISPLAY 0xA4
113 
114 #define OLEDSWITCH_MULTIPLEX_RATIO_1 0xA8
115 #define OLEDSWITCH_MULTIPLEX_RATIO_2 0x2F
116 
117 #define OLEDSWITCH_DIM_MODE_SETTING_FOR_COLOR_A_B_C_1 0xAB
118 #define OLEDSWITCH_DIM_MODE_SETTING_FOR_COLOR_A_B_C_2 0x00
119 #define OLEDSWITCH_DIM_MODE_SETTING_FOR_COLOR_A_B_C_3 0x12
120 #define OLEDSWITCH_DIM_MODE_SETTING_FOR_COLOR_A_B_C_4 0x0C
121 #define OLEDSWITCH_DIM_MODE_SETTING_FOR_COLOR_A_B_C_5 0x14
122 #define OLEDSWITCH_DIM_MODE_SETTING_FOR_COLOR_A_B_C_6 0x12
123 
124 #define OLEDSWITCH_MASTER_CONFIGURATION_1 0xAD
125 #define OLEDSWITCH_MASTER_CONFIGURATION_2 0x8E
126 
127 #define OLEDSWITCH_POWER_SAVE_MODE_1 0xB0
128 #define OLEDSWITCH_POWER_SAVE_MODE_2 0x0B
129 
130 #define OLEDSWITCH_PHASE_1_AND_2_PERIOD_ADJUSTMENT_1 0xB1
131 #define OLEDSWITCH_PHASE_1_AND_2_PERIOD_ADJUSTMENT_2 0x44
132 
133 #define OLEDSWITCH_DISPLAY_CLOCK_DIVIDER_OSCILLATOR_FREQUENCY_1 0xB3
134 #define OLEDSWITCH_DISPLAY_CLOCK_DIVIDER_OSCILLATOR_FREQUENCY_2 0xA0
135 
136 #define OLEDSWITCH_ENABLE_LINEAR_GRAY_SCALE 0xB9
137 
138 #define OLEDSWITCH_PRE_CHARGE_LEVEL_1 0xBB
139 #define OLEDSWITCH_PRE_CHARGE_LEVEL_2 0x12
140 
141 #define OLEDSWITCH_15_SET_VCOMH_1 0xBE
142 #define OLEDSWITCH_15_SET_VCOMH_2 0x28
143 
144 #define OLEDSWITCH_30_SET_VCOMH_1 0xBE
145 #define OLEDSWITCH_30_SET_VCOMH_2 0x3E
146 
147 #define OLEDSWITCH_DISPLAY_ON_IN_NORMAL_MODE 0xAF
148 
154 #define OLEDSWITCH_BUFFER_SIZE_BIG 0x00
155 #define OLEDSWITCH_BUFFER_SIZE_SMALL 0x01
156 
157 #define OLEDSWITCH_FILL_ENABLE_DISABLE 0x26
158 
159 #define OLEDSWITCH_ROW_RANGE 0x75
160 
161 #define OLEDSWITCH_COLUMN_RANGE 0x15
162 
163 #define OLEDSWITCH_CLEAR_WINDOW 0x25
164 
165 #define OLEDSWITCH_DEACTIVATE_SCROLLING 0x2E
166 
167 #define OLEDSWITCH_ACTIVATE_SCROLLING 0x2F
168 
169 #define OLEDSWITCH_SCROLLING_SETUP 0x27
170 
171 #define OLEDSWITCH_IMG_SIZE_NORMAL 6144
172 #define OLEDSWITCH_IMG_SIZE_BIG 12288
173  // End group macro
183 // --------------------------------------------------------------- PUBLIC TYPES
192 typedef struct
193 {
197  uint8_t row_offset;
198  uint8_t interval;
199 
201 
205 typedef struct
206 {
207  uint8_t column_start;
208  uint8_t column_end;
209  uint8_t row_start;
210  uint8_t row_end;
211 
213 
217 typedef struct
218 {
219  uint8_t r;
220  uint8_t g;
221  uint8_t b;
222 
224 
228 typedef struct
229 {
230  uint8_t a;
231  uint8_t b;
232  uint8_t c;
233 
235 
239 typedef struct
240 {
241  // Output pins
242 
243  digital_out_t rst;
244  digital_out_t cd;
245  digital_out_t cs;
246 
247  // Modules
248 
249  spi_master_t spi;
250  pin_name_t chip_select;
251 
256 
257 } oledswitch_t;
258 
262 typedef struct
263 {
264  // Communication gpio pins
265 
266  pin_name_t miso;
267  pin_name_t mosi;
268  pin_name_t sck;
269  pin_name_t cs;
270 
271  // Additional gpio pins
272 
273  pin_name_t rst;
274  pin_name_t cd;
275 
276  // static variable
277 
278  uint32_t spi_speed;
279  spi_master_mode_t spi_mode;
280  spi_master_chip_select_polarity_t cs_polarity;
281 
283  // End types group
285 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
286 
291 #ifdef __cplusplus
292 extern "C"{
293 #endif
294 
304 
313 
321 void oledswitch_default_cfg ( oledswitch_t *ctx, uint8_t buffer_size );
322 
332 void oledswitch_reg_write ( oledswitch_t *ctx, uint8_t *write_buf, uint8_t len );
333 
343 void oledswitch_draw_image ( oledswitch_t *ctx, const uint8_t *image_buf, uint16_t image_size );
344 
353 
362 
371 
380 
389 
398 
407 
416 
425 
434 
443 
453 
462 
471 
480 
489 
499 void oledswitch_set_row_range ( oledswitch_t *ctx, uint8_t start, uint8_t end );
500 
510 void oledswitch_set_column_range ( oledswitch_t *ctx, uint8_t start, uint8_t end );
511 
521 
530 
539 
548 
557 
565 void oledswitch_digital_write_pwm ( oledswitch_t *ctx, uint8_t signal );
566 
574 void oledswitch_digital_write_rst ( oledswitch_t *ctx, uint8_t signal );
575 
576 #ifdef __cplusplus
577 }
578 #endif
579 #endif // _OLEDSWITCH_H_
580  // End public_function group
583 
584 // ------------------------------------------------------------------------- END
oledswitch_cfg_t::rst
pin_name_t rst
Definition: oledswitch.h:273
oledswitch_set_column_range
void oledswitch_set_column_range(oledswitch_t *ctx, uint8_t start, uint8_t end)
Set column range function.
oledswitch_set_multiplex_ratio
void oledswitch_set_multiplex_ratio(oledswitch_t *ctx)
Set multiplex ratio function.
OLEDSWITCH_RETVAL
#define OLEDSWITCH_RETVAL
Definition: oledswitch.h:76
oledswitch_set_phase_period_adjustment
void oledswitch_set_phase_period_adjustment(oledswitch_t *ctx)
Set phase period adjustment function.
oledswitch_coordinate_t
Coordinate structure.
Definition: oledswitch.h:206
oledswitch_scroll_t::row_offset
uint8_t row_offset
Definition: oledswitch.h:197
oledswitch_demo_scrolling_setup
void oledswitch_demo_scrolling_setup(oledswitch_t *ctx)
Demo scroling setup function.
oledswitch_coordinate_t::column_end
uint8_t column_end
Definition: oledswitch.h:208
oledswitch_reg_write
void oledswitch_reg_write(oledswitch_t *ctx, uint8_t *write_buf, uint8_t len)
Register write function.
oledswitch_scroll_t::interval
uint8_t interval
Definition: oledswitch.h:198
oledswitch_t::spi
spi_master_t spi
Definition: oledswitch.h:249
oledswitch_display_clock_divider_oscillator_frequency
void oledswitch_display_clock_divider_oscillator_frequency(oledswitch_t *ctx)
Display clock divider oscillator frequency function.
oledswitch_pre_charge_level
void oledswitch_pre_charge_level(oledswitch_t *ctx)
Set pre-charge level function.
oledswitch_contrast_t::a
uint8_t a
Definition: oledswitch.h:230
oledswitch_color_t::g
uint8_t g
Definition: oledswitch.h:220
oledswitch_clear_window
void oledswitch_clear_window(oledswitch_t *ctx)
Clear window function.
oledswitch_set_row_range
void oledswitch_set_row_range(oledswitch_t *ctx, uint8_t start, uint8_t end)
Set row range function.
oledswitch_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: oledswitch.h:279
oledswitch_set_dim_mode
void oledswitch_set_dim_mode(oledswitch_t *ctx)
Set dim mode function.
oledswitch_color_t::r
uint8_t r
Definition: oledswitch.h:219
oledswitch_contrast_t::c
uint8_t c
Definition: oledswitch.h:232
oledswitch_cfg_t::miso
pin_name_t miso
Definition: oledswitch.h:266
oledswitch_init
OLEDSWITCH_RETVAL oledswitch_init(oledswitch_t *ctx, oledswitch_cfg_t *cfg)
Initialization function.
oledswitch_set_display_offset
void oledswitch_set_display_offset(oledswitch_t *ctx)
Set display offset function.
oledswitch_set_contrast
void oledswitch_set_contrast(oledswitch_t *ctx)
Set contrast function.
oledswitch_set_vcomh
void oledswitch_set_vcomh(oledswitch_t *ctx)
Set vcomh function.
oledswitch_contrast_t
Contrast structure.
Definition: oledswitch.h:229
oledswitch_t::cs
digital_out_t cs
Definition: oledswitch.h:245
oledswitch_cfg_setup
void oledswitch_cfg_setup(oledswitch_cfg_t *cfg)
Config Object Initialization function.
oledswitch_coordinate_t::column_start
uint8_t column_start
Definition: oledswitch.h:207
oledswitch_software_reset
void oledswitch_software_reset(oledswitch_t *ctx)
Software reset function.
oledswitch_t::coordinate
oledswitch_coordinate_t coordinate
Definition: oledswitch.h:252
oledswitch_t
Click ctx object definition.
Definition: oledswitch.h:240
oledswitch_set_master_current
void oledswitch_set_master_current(oledswitch_t *ctx)
Set master current function.
oledswitch_display_normal_mode
void oledswitch_display_normal_mode(oledswitch_t *ctx)
Display normal mode function.
oledswitch_set_master_config
void oledswitch_set_master_config(oledswitch_t *ctx)
Set master config function.
oledswitch_cfg_t::sck
pin_name_t sck
Definition: oledswitch.h:268
oledswitch_default_cfg
void oledswitch_default_cfg(oledswitch_t *ctx, uint8_t buffer_size)
Click Default Configuration function.
oledswitch_coordinate_t::row_end
uint8_t row_end
Definition: oledswitch.h:210
oledswitch_cfg_t::cd
pin_name_t cd
Definition: oledswitch.h:274
oledswitch_t::color
oledswitch_color_t color
Definition: oledswitch.h:255
oledswitch_scroll_t
Scroll structure.
Definition: oledswitch.h:193
oledswitch_scroll_t::column_horizontal_shift
uint8_t column_horizontal_shift
Definition: oledswitch.h:194
oledswitch_set_display_start_line
void oledswitch_set_display_start_line(oledswitch_t *ctx)
Set display start line function.
oledswitch_digital_write_pwm
void oledswitch_digital_write_pwm(oledswitch_t *ctx, uint8_t signal)
Digital write pwm function.
oledswitch_cfg_t::mosi
pin_name_t mosi
Definition: oledswitch.h:267
oledswitch_activate_scrolling
void oledswitch_activate_scrolling(oledswitch_t *ctx)
Activate scrolling function.
oledswitch_coordinate_t::row_start
uint8_t row_start
Definition: oledswitch.h:209
oledswitch_deactivate_scrolling
void oledswitch_deactivate_scrolling(oledswitch_t *ctx)
Deactivate scrolling function.
oledswitch_t::cd
digital_out_t cd
Definition: oledswitch.h:244
oledswitch_contrast_t::b
uint8_t b
Definition: oledswitch.h:231
oledswitch_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: oledswitch.h:280
oledswitch_color_t::b
uint8_t b
Definition: oledswitch.h:221
oledswitch_cfg_t::spi_speed
uint32_t spi_speed
Definition: oledswitch.h:278
oledswitch_digital_write_rst
void oledswitch_digital_write_rst(oledswitch_t *ctx, uint8_t signal)
Digital write reset function.
oledswitch_draw_image
void oledswitch_draw_image(oledswitch_t *ctx, const uint8_t *image_buf, uint16_t image_size)
Register write function.
oledswitch_scroll_t::row_vertical_shift
uint8_t row_vertical_shift
Definition: oledswitch.h:196
oledswitch_scroll_t::row_horizontal_shift
uint8_t row_horizontal_shift
Definition: oledswitch.h:195
oledswitch_set_normal_display
void oledswitch_set_normal_display(oledswitch_t *ctx)
Set normal display function.
oledswitch_set_remap_color_depth
void oledswitch_set_remap_color_depth(oledswitch_t *ctx)
Set remap color depth function.
oledswitch_set_power_save_mode
void oledswitch_set_power_save_mode(oledswitch_t *ctx)
Set power save mode function.
oledswitch_color_t
Color structure.
Definition: oledswitch.h:218
oledswitch_cfg_t
Click configuration structure definition.
Definition: oledswitch.h:263
oledswitch_cfg_t::cs
pin_name_t cs
Definition: oledswitch.h:269
oledswitch_enable_linear_gray_scale
void oledswitch_enable_linear_gray_scale(oledswitch_t *ctx)
Enable linear gray scale function.
oledswitch_t::contrast
oledswitch_contrast_t contrast
Definition: oledswitch.h:253
oledswitch_t::chip_select
pin_name_t chip_select
Definition: oledswitch.h:250
oledswitch_t::rst
digital_out_t rst
Definition: oledswitch.h:243
oledswitch_t::scroll
oledswitch_scroll_t scroll
Definition: oledswitch.h:254