pico-ssd1306  0.1
Simple library for using ssd1306 displays with the Raspberry Pi Pico and the pico-sdk.
ssd1306.h
Go to the documentation of this file.
1 /*
2 MIT License
3 
4 Copyright (c) 2021 David Schramm
5 
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to deal
8 in the Software without restriction, including without limitation the rights
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12 
13 The above copyright notice and this permission notice shall be included in all
14 copies or substantial portions of the Software.
15 
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 SOFTWARE.
23 */
24 
31 #ifndef _inc_ssd1306
32 #define _inc_ssd1306
33 #include <pico/stdlib.h>
34 #include <hardware/i2c.h>
35 
39 typedef enum {
40  SET_CONTRAST = 0x81,
41  SET_ENTIRE_ON = 0xA4,
42  SET_NORM_INV = 0xA6,
43  SET_DISP = 0xAE,
44  SET_MEM_ADDR = 0x20,
45  SET_COL_ADDR = 0x21,
46  SET_PAGE_ADDR = 0x22,
47  SET_DISP_START_LINE = 0x40,
48  SET_SEG_REMAP = 0xA0,
49  SET_MUX_RATIO = 0xA8,
50  SET_COM_OUT_DIR = 0xC0,
51  SET_DISP_OFFSET = 0xD3,
52  SET_COM_PIN_CFG = 0xDA,
53  SET_DISP_CLK_DIV = 0xD5,
54  SET_PRECHARGE = 0xD9,
55  SET_VCOM_DESEL = 0xDB,
56  SET_CHARGE_PUMP = 0x8D
58 
62 typedef struct {
63  uint8_t width;
64  uint8_t height;
65  uint8_t pages;
66  uint8_t address;
67  i2c_inst_t *i2c_i;
68  bool external_vcc;
69  uint8_t *buffer;
70  size_t bufsize;
71 } ssd1306_t;
72 
86 bool ssd1306_init(ssd1306_t *p, uint16_t width, uint16_t height, uint8_t address, i2c_inst_t *i2c_instance);
87 
94 void ssd1306_deinit(ssd1306_t *p);
95 
102 void ssd1306_poweroff(ssd1306_t *p);
103 
110 void ssd1306_poweron(ssd1306_t *p);
111 
119 void ssd1306_contrast(ssd1306_t *p, uint8_t val);
120 
128 void ssd1306_invert(ssd1306_t *p, uint8_t inv);
129 
136 void ssd1306_show(ssd1306_t *p);
137 
144 void ssd1306_clear(ssd1306_t *p);
145 
153 void ssd1306_clear_pixel(ssd1306_t *p, uint32_t x, uint32_t y);
154 
162 void ssd1306_draw_pixel(ssd1306_t *p, uint32_t x, uint32_t y);
163 
173 void ssd1306_draw_line(ssd1306_t *p, int32_t x1, int32_t y1, int32_t x2, int32_t y2);
174 
184 void ssd1306_draw_square(ssd1306_t *p, uint32_t x, uint32_t y, uint32_t width, uint32_t height);
185 
195 void ssd1306_draw_empty_square(ssd1306_t *p, uint32_t x, uint32_t y, uint32_t width, uint32_t height);
196 
206 void ssd1306_bmp_show_image_with_offset(ssd1306_t *p, const uint8_t *data, const long size, uint32_t x_offset, uint32_t y_offset);
207 
215 void ssd1306_bmp_show_image(ssd1306_t *p, const uint8_t *data, const long size);
216 
227 void ssd1306_draw_char_with_font(ssd1306_t *p, uint32_t x, uint32_t y, uint32_t scale, const uint8_t *font, char c);
228 
238 void ssd1306_draw_char(ssd1306_t *p, uint32_t x, uint32_t y, uint32_t scale, char c);
239 
250 void ssd1306_draw_string_with_font(ssd1306_t *p, uint32_t x, uint32_t y, uint32_t scale, const uint8_t *font, const char *s );
251 
261 void ssd1306_draw_string(ssd1306_t *p, uint32_t x, uint32_t y, uint32_t scale, const char *s);
262 
263 #endif
void ssd1306_bmp_show_image_with_offset(ssd1306_t *p, const uint8_t *data, const long size, uint32_t x_offset, uint32_t y_offset)
draw monochrome bitmap with offset
Definition: ssd1306.c:239
void ssd1306_poweron(ssd1306_t *p)
turn on display
Definition: ssd1306.c:126
void ssd1306_invert(ssd1306_t *p, uint8_t inv)
set invert display
Definition: ssd1306.c:135
void ssd1306_draw_char_with_font(ssd1306_t *p, uint32_t x, uint32_t y, uint32_t scale, const uint8_t *font, char c)
draw char with given font
Definition: ssd1306.c:191
void ssd1306_draw_empty_square(ssd1306_t *p, uint32_t x, uint32_t y, uint32_t width, uint32_t height)
draw empty square at given position with given size
Definition: ssd1306.c:184
void ssd1306_draw_string(ssd1306_t *p, uint32_t x, uint32_t y, uint32_t scale, const char *s)
draw string with builtin font
Definition: ssd1306.c:221
bool ssd1306_init(ssd1306_t *p, uint16_t width, uint16_t height, uint8_t address, i2c_inst_t *i2c_instance)
initialize display
Definition: ssd1306.c:61
void ssd1306_draw_line(ssd1306_t *p, int32_t x1, int32_t y1, int32_t x2, int32_t y2)
draw pixel on buffer
Definition: ssd1306.c:155
void ssd1306_draw_char(ssd1306_t *p, uint32_t x, uint32_t y, uint32_t scale, char c)
draw char with builtin font
Definition: ssd1306.c:217
void ssd1306_draw_square(ssd1306_t *p, uint32_t x, uint32_t y, uint32_t width, uint32_t height)
draw filled square at given position with given size
Definition: ssd1306.c:177
void ssd1306_draw_pixel(ssd1306_t *p, uint32_t x, uint32_t y)
draw pixel on buffer
Definition: ssd1306.c:149
void ssd1306_clear(ssd1306_t *p)
clear display buffer
Definition: ssd1306.c:139
void ssd1306_bmp_show_image(ssd1306_t *p, const uint8_t *data, const long size)
draw monochrome bitmap
Definition: ssd1306.c:283
void ssd1306_deinit(ssd1306_t *p)
deinitialize display
Definition: ssd1306.c:118
void ssd1306_contrast(ssd1306_t *p, uint8_t val)
set contrast of display
Definition: ssd1306.c:130
void ssd1306_poweroff(ssd1306_t *p)
turn off display
Definition: ssd1306.c:122
void ssd1306_clear_pixel(ssd1306_t *p, uint32_t x, uint32_t y)
clear pixel on buffer
Definition: ssd1306.c:143
ssd1306_command_t
defines commands used in ssd1306
Definition: ssd1306.h:39
void ssd1306_draw_string_with_font(ssd1306_t *p, uint32_t x, uint32_t y, uint32_t scale, const uint8_t *font, const char *s)
draw string with given font
Definition: ssd1306.c:211
void ssd1306_show(ssd1306_t *p)
display buffer, should be called on change
Definition: ssd1306.c:287
holds the configuration
Definition: ssd1306.h:62
uint8_t * buffer
Definition: ssd1306.h:69
uint8_t pages
Definition: ssd1306.h:65
size_t bufsize
Definition: ssd1306.h:70
i2c_inst_t * i2c_i
Definition: ssd1306.h:67
uint8_t width
Definition: ssd1306.h:63
bool external_vcc
Definition: ssd1306.h:68
uint8_t height
Definition: ssd1306.h:64
uint8_t address
Definition: ssd1306.h:66