LibDriver SSD1309
Loading...
Searching...
No Matches
driver_ssd1309_advance.c
Go to the documentation of this file.
1
36
38
39static ssd1309_handle_t gs_handle;
40
51{
52 uint8_t res;
53
54 /* link functions */
70
71 /* set interface */
72 res = ssd1309_set_interface(&gs_handle, interface);
73 if (res != 0)
74 {
75 ssd1309_interface_debug_print("ssd1309: set interface failed.\n");
76
77 return 1;
78 }
79
80 /* set addr pin */
81 res = ssd1309_set_addr_pin(&gs_handle, addr);
82 if (res != 0)
83 {
84 ssd1309_interface_debug_print("ssd1309: set addr failed.\n");
85
86 return 1;
87 }
88
89 /* ssd1309 init */
90 res = ssd1309_init(&gs_handle);
91 if (res != 0)
92 {
93 ssd1309_interface_debug_print("ssd1309: init failed.\n");
94
95 return 1;
96 }
97
98 /* disable mcu interface lock */
100 if (res != 0)
101 {
102 ssd1309_interface_debug_print("ssd1309: set mcu interface lock failed.\n");
103 (void)ssd1309_deinit(&gs_handle);
104
105 return 1;
106 }
107
108 /* set default gpio config */
110 if (res != 0)
111 {
112 ssd1309_interface_debug_print("ssd1309: set gpio failed.\n");
113 (void)ssd1309_deinit(&gs_handle);
114
115 return 1;
116 }
117
118 /* close display */
119 res = ssd1309_set_display(&gs_handle, SSD1309_DISPLAY_OFF);
120 if (res != 0)
121 {
122 ssd1309_interface_debug_print("ssd1309: set display failed.\n");
123 (void)ssd1309_deinit(&gs_handle);
124
125 return 1;
126 }
127
128 /* set column address range */
130 if (res != 0)
131 {
132 ssd1309_interface_debug_print("ssd1309: set column address range failed.\n");
133 (void)ssd1309_deinit(&gs_handle);
134
135 return 1;
136 }
137
138 /* set page address range */
140 if (res != 0)
141 {
142 ssd1309_interface_debug_print("ssd1309: set page address range failed.\n");
143 (void)ssd1309_deinit(&gs_handle);
144
145 return 1;
146 }
147
148 /* set low column start address */
150 if (res != 0)
151 {
152 ssd1309_interface_debug_print("ssd1309: set low column start address failed.\n");
153 (void)ssd1309_deinit(&gs_handle);
154
155 return 1;
156 }
157
158 /* set high column start address */
160 if (res != 0)
161 {
162 ssd1309_interface_debug_print("ssd1309: set high column start address failed.\n");
163 (void)ssd1309_deinit(&gs_handle);
164
165 return 1;
166 }
167
168 /* set display start line */
170 if (res != 0)
171 {
172 ssd1309_interface_debug_print("ssd1309: set display start line failed.\n");
173 (void)ssd1309_deinit(&gs_handle);
174
175 return 1;
176 }
177
178 /* deactivate scroll */
179 res = ssd1309_deactivate_scroll(&gs_handle);
180 if (res != 0)
181 {
182 ssd1309_interface_debug_print("ssd1309: set deactivate scroll failed.\n");
183 (void)ssd1309_deinit(&gs_handle);
184
185 return 1;
186 }
187
188 /* set contrast */
190 if (res != 0)
191 {
192 ssd1309_interface_debug_print("ssd1309: set contrast failed.\n");
193 (void)ssd1309_deinit(&gs_handle);
194
195 return 1;
196 }
197
198 /* set segment remap */
200 if (res != 0)
201 {
202 ssd1309_interface_debug_print("ssd1309: set segment remap failed.\n");
203 (void)ssd1309_deinit(&gs_handle);
204
205 return 1;
206 }
207
208 /* set scan direction */
210 if (res != 0)
211 {
212 ssd1309_interface_debug_print("ssd1309: set scan direction failed.\n");
213 (void)ssd1309_deinit(&gs_handle);
214
215 return 1;
216 }
217
218 /* set display mode */
220 if (res != 0)
221 {
222 ssd1309_interface_debug_print("ssd1309: set display mode failed.\n");
223 (void)ssd1309_deinit(&gs_handle);
224
225 return 1;
226 }
227
228 /* set multiplex ratio */
230 if (res != 0)
231 {
232 ssd1309_interface_debug_print("ssd1309: set multiplex ratio failed.\n");
233 (void)ssd1309_deinit(&gs_handle);
234
235 return 1;
236 }
237
238 /* set display offset */
240 if (res != 0)
241 {
242 ssd1309_interface_debug_print("ssd1309: set display offset failed.\n");
243 (void)ssd1309_deinit(&gs_handle);
244
245 return 1;
246 }
247
248 /* set display clock */
250 if (res != 0)
251 {
252 ssd1309_interface_debug_print("ssd1309: set display clock failed.\n");
253 (void)ssd1309_deinit(&gs_handle);
254
255 return 1;
256 }
257
258 /* set pre charge period */
260 if (res != 0)
261 {
262 ssd1309_interface_debug_print("ssd1309: set pre charge period failed.\n");
263 (void)ssd1309_deinit(&gs_handle);
264
265 return 1;
266 }
267
268 /* set hardware pins conf */
270 if (res != 0)
271 {
272 ssd1309_interface_debug_print("ssd1309: set com pins hardware conf failed.\n");
273 (void)ssd1309_deinit(&gs_handle);
274
275 return 1;
276 }
277
278 /* set deselect level 0.77 */
280 if (res != 0)
281 {
282 ssd1309_interface_debug_print("ssd1309: set deselect level failed.\n");
283 (void)ssd1309_deinit(&gs_handle);
284
285 return 1;
286 }
287
288 /* set page memory addressing mode */
290 if (res != 0)
291 {
292 ssd1309_interface_debug_print("ssd1309: set memory addressing level failed.\n");
293 (void)ssd1309_deinit(&gs_handle);
294
295 return 1;
296 }
297
298 /* entire display off */
300 if (res != 0)
301 {
302 ssd1309_interface_debug_print("ssd1309: set entire display failed.\n");
303 (void)ssd1309_deinit(&gs_handle);
304
305 return 1;
306 }
307
308 /* enable display */
309 res = ssd1309_set_display(&gs_handle, SSD1309_DISPLAY_ON);
310 if (res != 0)
311 {
312 ssd1309_interface_debug_print("ssd1309: set display failed.\n");
313 (void)ssd1309_deinit(&gs_handle);
314
315 return 1;
316 }
317
318 /* clear screen */
319 res = ssd1309_clear(&gs_handle);
320 if (res != 0)
321 {
322 ssd1309_interface_debug_print("ssd1309: clear failed.\n");
323 (void)ssd1309_deinit(&gs_handle);
324
325 return 1;
326 }
327
328 return 0;
329}
330
339{
340 /* deinit ssd1309 */
341 if (ssd1309_deinit(&gs_handle) != 0)
342 {
343 return 1;
344 }
345
346 return 0;
347}
348
357{
358 uint8_t res;
359
360 /* display on */
361 res = ssd1309_set_display(&gs_handle, SSD1309_DISPLAY_ON);
362 if (res != 0)
363 {
364 return 1;
365 }
366
367 return 0;
368}
369
378{
379 uint8_t res;
380
381 /* display off */
382 res = ssd1309_set_display(&gs_handle, SSD1309_DISPLAY_OFF);
383 if (res != 0)
384 {
385 return 1;
386 }
387
388 return 0;
389}
390
399{
400 /* clear */
401 if (ssd1309_clear(&gs_handle) != 0)
402 {
403 return 1;
404 }
405
406 return 0;
407}
408
419uint8_t ssd1309_advance_write_point(uint8_t x, uint8_t y, uint8_t data)
420{
421 uint8_t res;
422
423 /* write point */
424 res = ssd1309_write_point(&gs_handle, x, y, data);
425 if (res != 0)
426 {
427 return 1;
428 }
429
430 return 0;
431}
432
443uint8_t ssd1309_advance_read_point(uint8_t x, uint8_t y, uint8_t *data)
444{
445 uint8_t res;
446
447 /* read point in gram */
448 res = ssd1309_read_point(&gs_handle, x, y, data);
449 if (res != 0)
450 {
451 return 1;
452 }
453
454 return 0;
455}
456
470uint8_t ssd1309_advance_string(uint8_t x, uint8_t y, char *str, uint16_t len, uint8_t color, ssd1309_font_t font)
471{
472 uint8_t res;
473
474 /* write string in gram */
475 res = ssd1309_gram_write_string(&gs_handle, x, y, str, len, color, font);
476 if (res != 0)
477 {
478 return 1;
479 }
480
481 /* update gram */
482 if (ssd1309_gram_update(&gs_handle) != 0)
483 {
484 return 1;
485 }
486
487 return 0;
488}
489
502uint8_t ssd1309_advance_rect(uint8_t left, uint8_t top, uint8_t right, uint8_t bottom, uint8_t color)
503{
504 uint8_t res;
505
506 /* fill rect in gram */
507 res = ssd1309_gram_fill_rect(&gs_handle, left, top, right, bottom, color);
508 if (res != 0)
509 {
510 return 1;
511 }
512
513 /* update gram */
514 if (ssd1309_gram_update(&gs_handle) != 0)
515 {
516 return 1;
517 }
518
519 return 0;
520}
521
534uint8_t ssd1309_advance_picture(uint8_t left, uint8_t top, uint8_t right, uint8_t bottom, uint8_t *img)
535{
536 uint8_t res;
537
538 /* draw picture in gram */
539 res = ssd1309_gram_draw_picture(&gs_handle, left, top, right, bottom, img);
540 if (res != 0)
541 {
542 return 1;
543 }
544
545 /* update gram */
546 if (ssd1309_gram_update(&gs_handle) != 0)
547 {
548 return 1;
549 }
550
551 return 0;
552}
553
562{
563 uint8_t res;
564
565 /* deactivate scroll */
566 res = ssd1309_deactivate_scroll(&gs_handle);
567 if (res != 0)
568 {
569 return 1;
570 }
571
572 return 0;
573}
574
593uint8_t ssd1309_advance_vertical_left_horizontal_scroll(ssd1309_bool_t horizontal_scroll, uint8_t start_page_addr,
594 uint8_t end_page_addr, uint8_t rows, ssd1309_scroll_frame_t frames,
595 uint8_t start_column_addr, uint8_t end_column_addr)
596{
597 uint8_t res;
598
599 /* deactivate scroll */
600 res = ssd1309_deactivate_scroll(&gs_handle);
601 if (res != 0)
602 {
603 return 1;
604 }
605
606 /* set vertical left horizontal scroll */
607 res = ssd1309_set_vertical_left_horizontal_scroll(&gs_handle, horizontal_scroll, start_page_addr,
608 end_page_addr, rows, frames, start_column_addr, end_column_addr);
609 if (res != 0)
610 {
611 return 1;
612 }
613
614 /* activate scroll */
615 res = ssd1309_activate_scroll(&gs_handle);
616 if (res != 0)
617 {
618 return 1;
619 }
620
621 return 0;
622}
623
642uint8_t ssd1309_advance_vertical_right_horizontal_scroll(ssd1309_bool_t horizontal_scroll, uint8_t start_page_addr,
643 uint8_t end_page_addr, uint8_t rows, ssd1309_scroll_frame_t frames,
644 uint8_t start_column_addr, uint8_t end_column_addr)
645{
646 uint8_t res;
647
648 /* deactivate scroll */
649 res = ssd1309_deactivate_scroll(&gs_handle);
650 if (res != 0)
651 {
652 return 1;
653 }
654
655 /* set vertical right horizontal scroll */
656 res = ssd1309_set_vertical_right_horizontal_scroll(&gs_handle, horizontal_scroll, start_page_addr, end_page_addr,
657 rows, frames, start_column_addr, end_column_addr);
658 if (res != 0)
659 {
660 return 1;
661 }
662
663 /* activate scroll */
664 res = ssd1309_activate_scroll(&gs_handle);
665 if (res != 0)
666 {
667 return 1;
668 }
669
670 return 0;
671}
driver ssd1309 advance header file
ssd1309_bool_t
ssd1309 bool enumeration definition
uint8_t ssd1309_set_vertical_left_horizontal_scroll(ssd1309_handle_t *handle, ssd1309_bool_t horizontal_scroll, uint8_t start_page_addr, uint8_t end_page_addr, uint8_t rows, ssd1309_scroll_frame_t frames, uint8_t start_column_addr, uint8_t end_column_addr)
set the vertical left horizontal scroll
uint8_t ssd1309_read_point(ssd1309_handle_t *handle, uint8_t x, uint8_t y, uint8_t *data)
read a point
uint8_t ssd1309_set_mcu_interface_lock(ssd1309_handle_t *handle, ssd1309_bool_t enable)
enable or disable mcu interface lock
uint8_t ssd1309_deactivate_scroll(ssd1309_handle_t *handle)
deactivate the scroll
uint8_t ssd1309_set_column_address_range(ssd1309_handle_t *handle, uint8_t start_addr, uint8_t end_addr)
set the column address range
ssd1309_interface_t
ssd1309 interface enumeration definition
uint8_t ssd1309_deinit(ssd1309_handle_t *handle)
close the chip
uint8_t ssd1309_gram_write_string(ssd1309_handle_t *handle, uint8_t x, uint8_t y, char *str, uint16_t len, uint8_t color, ssd1309_font_t font)
draw a string in the gram
uint8_t ssd1309_set_display_clock(ssd1309_handle_t *handle, uint8_t oscillator_frequency, uint8_t clock_divide)
set the display clock
uint8_t ssd1309_set_high_column_start_address(ssd1309_handle_t *handle, uint8_t addr)
set the high column start address
uint8_t ssd1309_set_display(ssd1309_handle_t *handle, ssd1309_display_t on_off)
enable or disable the display
uint8_t ssd1309_set_addr_pin(ssd1309_handle_t *handle, ssd1309_address_t addr_pin)
set the chip iic address
uint8_t ssd1309_init(ssd1309_handle_t *handle)
initialize the chip
uint8_t ssd1309_set_memory_addressing_mode(ssd1309_handle_t *handle, ssd1309_memory_addressing_mode_t mode)
set the memory addressing mode
struct ssd1309_handle_s ssd1309_handle_t
ssd1309 handle structure definition
uint8_t ssd1309_set_gpio(ssd1309_handle_t *handle, ssd1309_gpio_t gpio)
set gpio
uint8_t ssd1309_set_display_offset(ssd1309_handle_t *handle, uint8_t offset)
set the display offset
uint8_t ssd1309_write_point(ssd1309_handle_t *handle, uint8_t x, uint8_t y, uint8_t data)
write a point
uint8_t ssd1309_set_interface(ssd1309_handle_t *handle, ssd1309_interface_t interface)
set the chip interface
uint8_t ssd1309_set_entire_display(ssd1309_handle_t *handle, ssd1309_entire_display_t enable)
enable or disable the entire display
uint8_t ssd1309_gram_draw_picture(ssd1309_handle_t *handle, uint8_t left, uint8_t top, uint8_t right, uint8_t bottom, uint8_t *img)
draw a picture in the gram
uint8_t ssd1309_activate_scroll(ssd1309_handle_t *handle)
activate the scroll
uint8_t ssd1309_set_scan_direction(ssd1309_handle_t *handle, ssd1309_scan_direction_t dir)
set the scan direction
uint8_t ssd1309_set_display_start_line(ssd1309_handle_t *handle, uint8_t l)
set the display start line
uint8_t ssd1309_set_deselect_level(ssd1309_handle_t *handle, ssd1309_deselect_level_t level)
set the deselect level
uint8_t ssd1309_set_low_column_start_address(ssd1309_handle_t *handle, uint8_t addr)
set the low column start address
ssd1309_address_t
ssd1309 address pin enumeration definition
uint8_t ssd1309_set_page_address_range(ssd1309_handle_t *handle, uint8_t start_addr, uint8_t end_addr)
set the page address range
uint8_t ssd1309_set_display_mode(ssd1309_handle_t *handle, ssd1309_display_mode_t mode)
set the display mode
uint8_t ssd1309_set_multiplex_ratio(ssd1309_handle_t *handle, uint8_t multiplex)
set the multiplex ratio
uint8_t ssd1309_set_vertical_right_horizontal_scroll(ssd1309_handle_t *handle, ssd1309_bool_t horizontal_scroll, uint8_t start_page_addr, uint8_t end_page_addr, uint8_t rows, ssd1309_scroll_frame_t frames, uint8_t start_column_addr, uint8_t end_column_addr)
set the vertical right horizontal scroll
uint8_t ssd1309_set_contrast(ssd1309_handle_t *handle, uint8_t contrast)
set the display contrast
uint8_t ssd1309_set_com_pins_hardware_conf(ssd1309_handle_t *handle, ssd1309_pin_conf_t conf, ssd1309_left_right_remap_t remap)
set the hardware com pins
uint8_t ssd1309_gram_fill_rect(ssd1309_handle_t *handle, uint8_t left, uint8_t top, uint8_t right, uint8_t bottom, uint8_t color)
fill a rectangle in the gram
ssd1309_scroll_frame_t
ssd1309 scroll frame enumeration definition
uint8_t ssd1309_clear(ssd1309_handle_t *handle)
clear the screen
uint8_t ssd1309_set_precharge_period(ssd1309_handle_t *handle, uint8_t phase1_period, uint8_t phase2_period)
set the pre charge period
uint8_t ssd1309_gram_update(ssd1309_handle_t *handle)
update the gram data
uint8_t ssd1309_set_segment_remap(ssd1309_handle_t *handle, ssd1309_segment_column_remap_t remap)
set the segment remap
ssd1309_font_t
ssd1309 font enumeration definition
@ SSD1309_BOOL_FALSE
@ SSD1309_MEMORY_ADDRESSING_MODE_PAGE
@ SSD1309_DISPLAY_ON
@ SSD1309_DISPLAY_OFF
@ SSD1309_ENTIRE_DISPLAY_OFF
#define SSD1309_ADVANCE_DEFAULT_DISPLAY_START_LINE
#define SSD1309_ADVANCE_DEFAULT_COLUMN_ADDRESS_RANGE_END
#define SSD1309_ADVANCE_DEFAULT_PHASE2_PERIOD
#define SSD1309_ADVANCE_DEFAULT_HIGH_COLUMN_START_ADDRESS
#define SSD1309_ADVANCE_DEFAULT_SCAN_DIRECTION
#define SSD1309_ADVANCE_DEFAULT_PAGE_ADDRESS_RANGE_END
#define SSD1309_ADVANCE_DEFAULT_LEFT_RIGHT_REMAP
#define SSD1309_ADVANCE_DEFAULT_DESELECT_LEVEL
ssd1309 advance example default definition
uint8_t ssd1309_advance_clear(void)
advance example clear
#define SSD1309_ADVANCE_DEFAULT_SEGMENT
uint8_t ssd1309_advance_picture(uint8_t left, uint8_t top, uint8_t right, uint8_t bottom, uint8_t *img)
advance example draw a picture
uint8_t ssd1309_advance_vertical_left_horizontal_scroll(ssd1309_bool_t horizontal_scroll, uint8_t start_page_addr, uint8_t end_page_addr, uint8_t rows, ssd1309_scroll_frame_t frames, uint8_t start_column_addr, uint8_t end_column_addr)
advance example enable the left horizontal scroll
uint8_t ssd1309_advance_deinit(void)
advance example deinit
#define SSD1309_ADVANCE_DEFAULT_CLOCK_DIVIDE
uint8_t ssd1309_advance_rect(uint8_t left, uint8_t top, uint8_t right, uint8_t bottom, uint8_t color)
advance example fill a rectangle
#define SSD1309_ADVANCE_DEFAULT_GPIO_CONFIG
#define SSD1309_ADVANCE_DEFAULT_DISPLAY_OFFSET
uint8_t ssd1309_advance_read_point(uint8_t x, uint8_t y, uint8_t *data)
advance example read a point
#define SSD1309_ADVANCE_DEFAULT_CONTRAST
uint8_t ssd1309_advance_init(ssd1309_interface_t interface, ssd1309_address_t addr)
advance example init
uint8_t ssd1309_advance_display_off(void)
advance example display off
#define SSD1309_ADVANCE_DEFAULT_PHASE1_PERIOD
#define SSD1309_ADVANCE_DEFAULT_LOW_COLUMN_START_ADDRESS
#define SSD1309_ADVANCE_DEFAULT_DISPLAY_MODE
#define SSD1309_ADVANCE_DEFAULT_COLUMN_ADDRESS_RANGE_START
uint8_t ssd1309_advance_display_on(void)
advance example display on
#define SSD1309_ADVANCE_DEFAULT_MULTIPLEX_RATIO
uint8_t ssd1309_advance_deactivate_scroll(void)
advance example deactivate the scroll
#define SSD1309_ADVANCE_DEFAULT_PIN_CONF
#define SSD1309_ADVANCE_DEFAULT_PAGE_ADDRESS_RANGE_START
uint8_t ssd1309_advance_vertical_right_horizontal_scroll(ssd1309_bool_t horizontal_scroll, uint8_t start_page_addr, uint8_t end_page_addr, uint8_t rows, ssd1309_scroll_frame_t frames, uint8_t start_column_addr, uint8_t end_column_addr)
advance example enable the right horizontal scroll
uint8_t ssd1309_advance_string(uint8_t x, uint8_t y, char *str, uint16_t len, uint8_t color, ssd1309_font_t font)
advance example draw a string
#define SSD1309_ADVANCE_DEFAULT_OSCILLATOR_FREQUENCY
uint8_t ssd1309_advance_write_point(uint8_t x, uint8_t y, uint8_t data)
advance example write a point
uint8_t ssd1309_interface_spi_cmd_data_gpio_init(void)
interface command && data gpio init
uint8_t ssd1309_interface_iic_init(void)
interface iic bus init
uint8_t ssd1309_interface_spi_cmd_data_gpio_deinit(void)
interface command && data gpio deinit
void ssd1309_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t ssd1309_interface_reset_gpio_init(void)
interface reset gpio init
uint8_t ssd1309_interface_iic_deinit(void)
interface iic bus deinit
uint8_t ssd1309_interface_spi_cmd_data_gpio_write(uint8_t value)
interface command && data gpio write
uint8_t ssd1309_interface_reset_gpio_deinit(void)
interface reset gpio deinit
uint8_t ssd1309_interface_iic_write(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus write
uint8_t ssd1309_interface_reset_gpio_write(uint8_t value)
interface reset gpio write
uint8_t ssd1309_interface_spi_write_cmd(uint8_t *buf, uint16_t len)
interface spi bus write
void ssd1309_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t ssd1309_interface_spi_init(void)
interface spi bus init
uint8_t ssd1309_interface_spi_deinit(void)
interface spi bus deinit