Arduino TKJHAT
Arduino library for Pico HAT extension board
Loading...
Searching...
No Matches
ssd1306.h
Go to the documentation of this file.
1/*
2MIT License
3
4Copyright (c) 2021 David Schramm
5
6Permission is hereby granted, free of charge, to any person obtaining a copy
7of this software and associated documentation files (the "Software"), to deal
8in the Software without restriction, including without limitation the rights
9to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10copies of the Software, and to permit persons to whom the Software is
11furnished to do so, subject to the following conditions:
12
13The above copyright notice and this permission notice shall be included in all
14copies or substantial portions of the Software.
15
16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22SOFTWARE.
23*/
24
30
31#ifndef _inc_ssd1306
32#define _inc_ssd1306
33#include <pico/stdlib.h>
34#include <hardware/i2c.h>
35
39typedef 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
62typedef struct {
63 uint8_t width;
64 uint8_t height;
65 uint8_t pages;
66 uint8_t address;
67 i2c_inst_t *i2c_i;
69 uint8_t *buffer;
70 size_t bufsize;
71} ssd1306_t;
72
86bool ssd1306_init(ssd1306_t *p, uint16_t width, uint16_t height, uint8_t address, i2c_inst_t *i2c_instance);
87
95
103
111
119void ssd1306_contrast(ssd1306_t *p, uint8_t val);
120
128void ssd1306_invert(ssd1306_t *p, uint8_t inv);
129
137
145
153void ssd1306_clear_pixel(ssd1306_t *p, uint32_t x, uint32_t y);
154
162void ssd1306_draw_pixel(ssd1306_t *p, uint32_t x, uint32_t y);
163
173void ssd1306_draw_line(ssd1306_t *p, int32_t x1, int32_t y1, int32_t x2, int32_t y2);
174
184void ssd1306_clear_square(ssd1306_t *p, uint32_t x, uint32_t y, uint32_t width, uint32_t height);
185
195void ssd1306_draw_square(ssd1306_t *p, uint32_t x, uint32_t y, uint32_t width, uint32_t height);
196
206void ssd1306_draw_empty_square(ssd1306_t *p, uint32_t x, uint32_t y, uint32_t width, uint32_t height);
207
217void ssd1306_bmp_show_image_with_offset(ssd1306_t *p, const uint8_t *data, const long size, uint32_t x_offset, uint32_t y_offset);
218
226void ssd1306_bmp_show_image(ssd1306_t *p, const uint8_t *data, const long size);
227
238void ssd1306_draw_char_with_font(ssd1306_t *p, uint32_t x, uint32_t y, uint32_t scale, const uint8_t *font, char c);
239
249void ssd1306_draw_char(ssd1306_t *p, uint32_t x, uint32_t y, uint32_t scale, char c);
250
261void ssd1306_draw_string_with_font(ssd1306_t *p, uint32_t x, uint32_t y, uint32_t scale, const uint8_t *font, const char *s );
262
272void ssd1306_draw_string(ssd1306_t *p, uint32_t x, uint32_t y, uint32_t scale, const char *s);
273
274#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
void ssd1306_poweron(ssd1306_t *p)
turn on display
void ssd1306_invert(ssd1306_t *p, uint8_t inv)
set invert display
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
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
void ssd1306_draw_string(ssd1306_t *p, uint32_t x, uint32_t y, uint32_t scale, const char *s)
draw string with builtin font
bool ssd1306_init(ssd1306_t *p, uint16_t width, uint16_t height, uint8_t address, i2c_inst_t *i2c_instance)
initialize display
void ssd1306_draw_line(ssd1306_t *p, int32_t x1, int32_t y1, int32_t x2, int32_t y2)
draw line on buffer
void ssd1306_draw_char(ssd1306_t *p, uint32_t x, uint32_t y, uint32_t scale, char c)
draw char with builtin font
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
void ssd1306_draw_pixel(ssd1306_t *p, uint32_t x, uint32_t y)
draw pixel on buffer
void ssd1306_clear(ssd1306_t *p)
clear display buffer
void ssd1306_bmp_show_image(ssd1306_t *p, const uint8_t *data, const long size)
draw monochrome bitmap
void ssd1306_deinit(ssd1306_t *p)
deinitialize display
void ssd1306_contrast(ssd1306_t *p, uint8_t val)
set contrast of display
void ssd1306_poweroff(ssd1306_t *p)
turn off display
void ssd1306_clear_square(ssd1306_t *p, uint32_t x, uint32_t y, uint32_t width, uint32_t height)
clear square at given position with given size
void ssd1306_clear_pixel(ssd1306_t *p, uint32_t x, uint32_t y)
clear pixel on buffer
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
void ssd1306_show(ssd1306_t *p)
display buffer, should be called on change
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