LibDriver SSD1351  2.0.0
SSD1351 full function driver
driver_ssd1351_basic.c
Go to the documentation of this file.
1 
38 #include "driver_ssd1351_basic.h"
39 
40 static ssd1351_handle_t gs_handle;
41 static uint8_t gs_gamma[64] = { 0x02, 0x03, 0x04, 0x05,
42  0x06, 0x07, 0x08, 0x09,
43  0x0A, 0x0B, 0x0C, 0x0D,
44  0x0E, 0x0F, 0x10, 0x11,
45  0x12, 0x13, 0x15, 0x17,
46  0x19, 0x1B, 0x1D, 0x1F,
47  0x21, 0x23, 0x25, 0x27,
48  0x2A, 0x2D, 0x30, 0x33,
49  0x36, 0x39, 0x3C, 0x3F,
50  0x42, 0x45, 0x48, 0x4C,
51  0x50, 0x54, 0x58, 0x5C,
52  0x60, 0x64, 0x68, 0x6C,
53  0x70, 0x74, 0x78, 0x7D,
54  0x82, 0x87, 0x8C, 0x91,
55  0x96, 0x9B, 0xA0, 0xA5,
56  0xAA, 0xAF, 0xB4, 0x00 };
57 
65 uint8_t ssd1351_basic_init(void)
66 {
67  uint8_t res;
68 
69  /* link functions */
82 
83  /* ssd1351 init */
84  res = ssd1351_init(&gs_handle);
85  if (res != 0)
86  {
87  ssd1351_interface_debug_print("ssd1351: ssd1351 init.\n");
88 
89  return 1;
90  }
91 
92  /* unlock oled driver ic */
94  if (res != 0)
95  {
96  ssd1351_interface_debug_print("ssd1351: set command failed.\n");
97  (void)ssd1351_deinit(&gs_handle);
98 
99  return 1;
100  }
101 
102  /* enable command */
104  if (res != 0)
105  {
106  ssd1351_interface_debug_print("ssd1351: set command failed.\n");
107  (void)ssd1351_deinit(&gs_handle);
108 
109  return 1;
110  }
111 
112  /* enter sleep mode */
113  res = ssd1351_set_sleep_mode(&gs_handle, SSD1351_BOOL_TRUE);
114  if (res != 0)
115  {
116  ssd1351_interface_debug_print("ssd1351: set sleep mode failed.\n");
117  (void)ssd1351_deinit(&gs_handle);
118 
119  return 1;
120  }
121 
122  /* set default front clock oscillator frequency */
124  if (res != 0)
125  {
126  ssd1351_interface_debug_print("ssd1351: set front clock oscillator failed.\n");
127  (void)ssd1351_deinit(&gs_handle);
128 
129  return 1;
130  }
131 
132  /* set default mux ratio */
134  if (res != 0)
135  {
136  ssd1351_interface_debug_print("ssd1351: set mux ratio failed.\n");
137  (void)ssd1351_deinit(&gs_handle);
138 
139  return 1;
140  }
141 
142  /* set default display offset */
144  if (res != 0)
145  {
146  ssd1351_interface_debug_print("ssd1351: set display offset failed.\n");
147  (void)ssd1351_deinit(&gs_handle);
148 
149  return 1;
150  }
151 
152  /* set default display start line */
154  if (res != 0)
155  {
156  ssd1351_interface_debug_print("ssd1351: set display start line failed.\n");
157  (void)ssd1351_deinit(&gs_handle);
158 
159  return 1;
160  }
161 
162  /* set default address increment */
164  if (res != 0)
165  {
166  ssd1351_interface_debug_print("ssd1351: set address increment failed.\n");
167  (void)ssd1351_deinit(&gs_handle);
168 
169  return 1;
170  }
171 
172  /* set default color depth */
174  if (res != 0)
175  {
176  ssd1351_interface_debug_print("ssd1351: set color depth failed.\n");
177  (void)ssd1351_deinit(&gs_handle);
178 
179  return 1;
180  }
181 
182  /* set default seg0 map */
184  if (res != 0)
185  {
186  ssd1351_interface_debug_print("ssd1351: set seg0 map failed.\n");
187  (void)ssd1351_deinit(&gs_handle);
188 
189  return 1;
190  }
191 
192  /* set default color sequence */
194  if (res != 0)
195  {
196  ssd1351_interface_debug_print("ssd1351: set color sequence failed.\n");
197  (void)ssd1351_deinit(&gs_handle);
198 
199  return 1;
200  }
201 
202  /* set default scan mode */
204  if (res != 0)
205  {
206  ssd1351_interface_debug_print("ssd1351: set scan mode failed.\n");
207  (void)ssd1351_deinit(&gs_handle);
208 
209  return 1;
210  }
211 
212  /* set default com split odd even */
214  if (res != 0)
215  {
216  ssd1351_interface_debug_print("ssd1351: set com split odd even failed.\n");
217  (void)ssd1351_deinit(&gs_handle);
218 
219  return 1;
220  }
221 
222  /* set default gpio */
224  if (res != 0)
225  {
226  ssd1351_interface_debug_print("ssd1351: set gpio failed.\n");
227  (void)ssd1351_deinit(&gs_handle);
228 
229  return 1;
230  }
231 
232  /* set default select vdd */
234  if (res != 0)
235  {
236  ssd1351_interface_debug_print("ssd1351: set select vdd failed.\n");
237  (void)ssd1351_deinit(&gs_handle);
238 
239  return 1;
240  }
241 
242  /* set default parallel bits */
244  if (res != 0)
245  {
246  ssd1351_interface_debug_print("ssd1351: set parallel bits failed.\n");
247  (void)ssd1351_deinit(&gs_handle);
248 
249  return 1;
250  }
251 
252  /* set default segment low voltage */
254  if (res != 0)
255  {
256  ssd1351_interface_debug_print("ssd1351: set segment low voltage failed.\n");
257  (void)ssd1351_deinit(&gs_handle);
258 
259  return 1;
260  }
261 
262  /* set default contrast */
264  if (res != 0)
265  {
266  ssd1351_interface_debug_print("ssd1351: set contrast failed.\n");
267  (void)ssd1351_deinit(&gs_handle);
268 
269  return 1;
270  }
271 
272  /* set default master contrast current */
274  if (res != 0)
275  {
276  ssd1351_interface_debug_print("ssd1351: set master contrast failed.\n");
277  (void)ssd1351_deinit(&gs_handle);
278 
279  return 1;
280  }
281 
282  /* set default gray scale pulse width */
283  res = ssd1351_set_gray_scale_pulse_width(&gs_handle, (uint8_t *)gs_gamma);
284  if (res != 0)
285  {
286  ssd1351_interface_debug_print("ssd1351: set gray scale pulse width failed.\n");
287  (void)ssd1351_deinit(&gs_handle);
288 
289  return 1;
290  }
291 
292  /* set default phase period */
294  if (res != 0)
295  {
296  ssd1351_interface_debug_print("ssd1351: set phase period failed.\n");
297  (void)ssd1351_deinit(&gs_handle);
298 
299  return 1;
300  }
301 
302  /* set default pre charge voltage */
304  if (res != 0)
305  {
306  ssd1351_interface_debug_print("ssd1351: set pre charge voltage failed.\n");
307  (void)ssd1351_deinit(&gs_handle);
308 
309  return 1;
310  }
311 
312  /* set default vcomh voltage */
314  if (res != 0)
315  {
316  ssd1351_interface_debug_print("ssd1351: set vcomh voltage failed.\n");
317  (void)ssd1351_deinit(&gs_handle);
318 
319  return 1;
320  }
321 
322  /* set default second pre charge period */
324  if (res != 0)
325  {
326  ssd1351_interface_debug_print("ssd1351: set second pre charge period failed.\n");
327  (void)ssd1351_deinit(&gs_handle);
328 
329  return 1;
330  }
331 
332  /* set default display mode */
334  if (res != 0)
335  {
336  ssd1351_interface_debug_print("ssd1351: set display mode failed.\n");
337  (void)ssd1351_deinit(&gs_handle);
338 
339  return 1;
340  }
341 
342  /* exit sleep mode */
343  res = ssd1351_set_sleep_mode(&gs_handle, SSD1351_BOOL_FALSE);
344  if (res != 0)
345  {
346  ssd1351_interface_debug_print("ssd1351: set sleep mode failed.\n");
347  (void)ssd1351_deinit(&gs_handle);
348 
349  return 1;
350  }
351 
352  /* clear screen */
353  return ssd1351_clear(&gs_handle);
354 }
355 
363 uint8_t ssd1351_basic_deinit(void)
364 {
365  /* ssd1351 deinit */
366  if (ssd1351_deinit(&gs_handle) != 0)
367  {
368  return 1;
369  }
370  else
371  {
372  return 0;
373  }
374 }
375 
383 uint8_t ssd1351_basic_clear(void)
384 {
385  /* ssd1351 clear */
386  if (ssd1351_clear(&gs_handle) != 0)
387  {
388  return 1;
389  }
390  else
391  {
392  return 0;
393  }
394 }
395 
404 {
405  /* ssd1351 exit sleep mode */
406  if (ssd1351_set_sleep_mode(&gs_handle, SSD1351_BOOL_FALSE) != 0)
407  {
408  return 1;
409  }
410  else
411  {
412  return 0;
413  }
414 }
415 
424 {
425  /* ssd1351 enter sleep mode */
426  if (ssd1351_set_sleep_mode(&gs_handle, SSD1351_BOOL_TRUE) != 0)
427  {
428  return 1;
429  }
430  else
431  {
432  return 0;
433  }
434 }
435 
449 uint8_t ssd1351_basic_string(uint8_t x, uint8_t y, char *str, uint16_t len, uint32_t color, ssd1351_font_t font)
450 {
451  /* write string */
452  if (ssd1351_write_string(&gs_handle, x, y, str, len, color, font) != 0)
453  {
454  return 1;
455  }
456  else
457  {
458  return 0;
459  }
460 }
461 
472 uint8_t ssd1351_basic_write_point(uint8_t x, uint8_t y, uint32_t color)
473 {
474  /* draw point */
475  if (ssd1351_draw_point(&gs_handle, x, y, color) != 0)
476  {
477  return 1;
478  }
479  else
480  {
481  return 0;
482  }
483 }
484 
497 uint8_t ssd1351_basic_rect(uint8_t left, uint8_t top, uint8_t right, uint8_t bottom, uint32_t color)
498 {
499  /* fill rect */
500  if (ssd1351_fill_rect(&gs_handle, left, top, right, bottom, color) != 0)
501  {
502  return 1;
503  }
504  else
505  {
506  return 0;
507  }
508 }
509 
522 uint8_t ssd1351_basic_draw_picture(uint8_t left, uint8_t top, uint8_t right, uint8_t bottom, uint32_t *img)
523 {
524  /* draw picture */
525  if (ssd1351_draw_picture(&gs_handle, left, top, right, bottom, img) != 0)
526  {
527  return 1;
528  }
529  else
530  {
531  return 0;
532  }
533 }
534 
547 uint8_t ssd1351_basic_draw_picture_16bits(uint8_t left, uint8_t top, uint8_t right, uint8_t bottom, uint16_t *img)
548 {
549  /* draw picture in 16 bits */
550  if (ssd1351_draw_picture_16bits(&gs_handle, left, top, right, bottom, img) != 0)
551  {
552  return 1;
553  }
554  else
555  {
556  return 0;
557  }
558 }
driver ssd1351 basic header file
uint8_t ssd1351_set_master_contrast_current(ssd1351_handle_t *handle, uint8_t current)
set the master contrast current
uint8_t ssd1351_set_scan_mode(ssd1351_handle_t *handle, ssd1351_scan_mode_t mode)
set the scan mode
uint8_t ssd1351_fill_rect(ssd1351_handle_t *handle, uint8_t left, uint8_t top, uint8_t right, uint8_t bottom, uint32_t color)
fill the rect
uint8_t ssd1351_set_color_sequence(ssd1351_handle_t *handle, ssd1351_color_sequence_t color_sequence)
set the color sequence
uint8_t ssd1351_set_contrast(ssd1351_handle_t *handle, uint8_t a, uint8_t b, uint8_t c)
set the display contrast
uint8_t ssd1351_clear(ssd1351_handle_t *handle)
clear the display
uint8_t ssd1351_set_display_offset(ssd1351_handle_t *handle, uint8_t offset)
set the display offset
uint8_t ssd1351_set_command(ssd1351_handle_t *handle, ssd1351_command_t command)
set the command
uint8_t ssd1351_set_color_depth(ssd1351_handle_t *handle, ssd1351_color_depth_t color_depth)
set the display color depth
uint8_t ssd1351_init(ssd1351_handle_t *handle)
initialize the chip
uint8_t ssd1351_set_parallel_bits(ssd1351_handle_t *handle, ssd1351_select_parallel_bits_t parallel_bits)
set the interface parallel bits
ssd1351_font_t
ssd1351 font size enumeration definition
uint8_t ssd1351_set_gpio(ssd1351_handle_t *handle, ssd1351_gpio_pin_t gpio0, ssd1351_gpio_pin_t gpio1)
set the gpio pin
uint8_t ssd1351_set_com_split_odd_even(ssd1351_handle_t *handle, ssd1351_bool_t enable)
set the com split odd or even
uint8_t ssd1351_set_second_pre_charge_period(ssd1351_handle_t *handle, uint8_t period)
set the second pre charge period
uint8_t ssd1351_set_front_clock_oscillator_frequency(ssd1351_handle_t *handle, uint8_t d, uint8_t frequency)
set the front clock oscillator frequency
uint8_t ssd1351_set_pre_charge_voltage(ssd1351_handle_t *handle, uint8_t voltage_level)
set the pre charge voltage
uint8_t ssd1351_set_vcomh_voltage(ssd1351_handle_t *handle, uint8_t voltage_level)
set the vcomh voltage
uint8_t ssd1351_set_phase_period(ssd1351_handle_t *handle, uint8_t phase1_period, uint8_t phase2_period)
set the phase period
uint8_t ssd1351_draw_picture_16bits(ssd1351_handle_t *handle, uint8_t left, uint8_t top, uint8_t right, uint8_t bottom, uint16_t *image)
draw a 16 bits picture
uint8_t ssd1351_set_display_start_line(ssd1351_handle_t *handle, uint8_t l)
set the display start line
uint8_t ssd1351_write_string(ssd1351_handle_t *handle, uint8_t x, uint8_t y, char *str, uint16_t len, uint32_t color, ssd1351_font_t font)
write a string in the display
uint8_t ssd1351_set_display_mode(ssd1351_handle_t *handle, ssd1351_display_mode_t mode)
set the display mode
uint8_t ssd1351_set_select_vdd(ssd1351_handle_t *handle, ssd1351_select_vdd_t vdd)
set the select vdd
uint8_t ssd1351_set_seg0_map(ssd1351_handle_t *handle, ssd1351_seg0_mapped_t seg0_map)
set the seg0 map
uint8_t ssd1351_set_sleep_mode(ssd1351_handle_t *handle, ssd1351_bool_t enable)
set the sleep mode
uint8_t ssd1351_set_mux_ratio(ssd1351_handle_t *handle, uint8_t ratio)
set the mux ratio
uint8_t ssd1351_set_address_increment(ssd1351_handle_t *handle, ssd1351_address_increment_t increment)
set the address increment
uint8_t ssd1351_draw_point(ssd1351_handle_t *handle, uint8_t x, uint8_t y, uint32_t color)
draw a point in the display
uint8_t ssd1351_draw_picture(ssd1351_handle_t *handle, uint8_t left, uint8_t top, uint8_t right, uint8_t bottom, uint32_t *image)
draw a picture
uint8_t ssd1351_set_gray_scale_pulse_width(ssd1351_handle_t *handle, uint8_t gamma[63])
set the gray scale pulse width
uint8_t ssd1351_set_segment_low_voltage(ssd1351_handle_t *handle, ssd1351_segment_low_voltage_t segment)
set the segment low voltage
uint8_t ssd1351_deinit(ssd1351_handle_t *handle)
close the chip
@ SSD1351_COMMAND_A2_B1_B3_BB_BE_ACCESSIBLE
@ SSD1351_COMMAND_UNLOCK_OLED_DRIVER_IC
@ SSD1351_DISPLAY_MODE_NORMAL
@ SSD1351_BOOL_TRUE
@ SSD1351_BOOL_FALSE
uint8_t ssd1351_basic_display_off(void)
basic example display off
#define SSD1351_BASIC_DEFAULT_CONTRAST_A
uint8_t ssd1351_basic_string(uint8_t x, uint8_t y, char *str, uint16_t len, uint32_t color, ssd1351_font_t font)
basic example draw a string
#define SSD1351_BASIC_DEFAULT_CLOCK_DIV
ssd1351 basic example default definition
#define SSD1351_BASIC_DEFAULT_COLOR_SEQUENCE
#define SSD1351_BASIC_DEFAULT_CONTRAST_B
#define SSD1351_BASIC_DEFAULT_VCOMH_VOLTAGE
uint8_t ssd1351_basic_write_point(uint8_t x, uint8_t y, uint32_t color)
basic example write a point
#define SSD1351_BASIC_DEFAULT_SELECT_VDD
#define SSD1351_BASIC_DEFAULT_GPIO0_MODE
uint8_t ssd1351_basic_draw_picture_16bits(uint8_t left, uint8_t top, uint8_t right, uint8_t bottom, uint16_t *img)
basic example draw a 16 bits picture
uint8_t ssd1351_basic_rect(uint8_t left, uint8_t top, uint8_t right, uint8_t bottom, uint32_t color)
basic example fill a rectangle
#define SSD1351_BASIC_DEFAULT_PRE_CHARGE_VOLTAGE
#define SSD1351_BASIC_DEFAULT_SEG0_MAP
#define SSD1351_BASIC_DEFAULT_COLOR_DEPTH
#define SSD1351_BASIC_DEFAULT_PHASE2_PERIOD
uint8_t ssd1351_basic_deinit(void)
basic example deinit
#define SSD1351_BASIC_DEFAULT_SECOND_PRE_CHARGE_PERIOD
uint8_t ssd1351_basic_clear(void)
basic example clear
#define SSD1351_BASIC_DEFAULT_MASTER_CONTRAST_CURRENT
uint8_t ssd1351_basic_display_on(void)
basic example display on
#define SSD1351_BASIC_DEFAULT_CONTRAST_C
#define SSD1351_BASIC_DEFAULT_MUX_RATIO
uint8_t ssd1351_basic_draw_picture(uint8_t left, uint8_t top, uint8_t right, uint8_t bottom, uint32_t *img)
basic example draw a picture
#define SSD1351_BASIC_DEFAULT_DISPLAY_START_LINE
uint8_t ssd1351_basic_init(void)
basic example init
#define SSD1351_BASIC_DEFAULT_GPIO1_MODE
#define SSD1351_BASIC_DEFAULT_DISPLAY_OFFSET
#define SSD1351_BASIC_DEFAULT_ADDRESS_INCREMENT
#define SSD1351_BASIC_DEFAULT_SELECT_PARALLEL
#define SSD1351_BASIC_DEFAULT_COM_SPLIT_ODD_EVEN
#define SSD1351_BASIC_DEFAULT_OSCILLATOR_FREQUENCY
#define SSD1351_BASIC_DEFAULT_SEGMENT_LOW_VOLTAGE
#define SSD1351_BASIC_DEFAULT_SCAN_MODE
#define SSD1351_BASIC_DEFAULT_PHASE1_PERIOD
uint8_t ssd1351_interface_cmd_data_gpio_init(void)
interface command && data gpio init
void ssd1351_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t ssd1351_interface_reset_gpio_init(void)
interface reset gpio init
uint8_t ssd1351_interface_spi_init(void)
interface spi bus init
void ssd1351_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t ssd1351_interface_reset_gpio_deinit(void)
interface reset gpio deinit
uint8_t ssd1351_interface_cmd_data_gpio_write(uint8_t value)
interface command && data gpio write
uint8_t ssd1351_interface_reset_gpio_write(uint8_t value)
interface reset gpio write
uint8_t ssd1351_interface_spi_write_cmd(uint8_t *buf, uint16_t len)
interface spi bus write
uint8_t ssd1351_interface_spi_deinit(void)
interface spi bus deinit
uint8_t ssd1351_interface_cmd_data_gpio_deinit(void)
interface command && data gpio deinit
ssd1351 handle structure definition