33 #include "freertos/FreeRTOS.h"
34 #include "freertos/task.h"
36 #include "driver/i2c.h"
41 #define tag CONFIG_SSD1306_I2C_TAG
52 i2c_config_t i2c_config = {
53 .mode = I2C_MODE_MASTER,
56 .sda_pullup_en = GPIO_PULLUP_ENABLE,
57 .scl_pullup_en = GPIO_PULLUP_ENABLE,
58 .master.clk_speed = 1000000};
59 i2c_param_config(I2C_NUM_0, &i2c_config);
60 i2c_driver_install(I2C_NUM_0, I2C_MODE_MASTER, 0, 0, 0);
64 gpio_pad_select_gpio(reset);
65 gpio_set_direction(reset, GPIO_MODE_OUTPUT);
66 gpio_set_level(reset, 0);
67 vTaskDelay(50 / portTICK_PERIOD_MS);
68 gpio_set_level(reset, 1);
88 i2c_cmd_handle_t cmd = i2c_cmd_link_create();
90 i2c_master_start(cmd);
91 i2c_master_write_byte(cmd, (
dev->
_address << 1) | I2C_MASTER_WRITE,
true);
96 i2c_master_write_byte(cmd, 0x3F,
true);
98 i2c_master_write_byte(cmd, 0x1F,
true);
100 i2c_master_write_byte(cmd, 0x00,
true);
113 i2c_master_write_byte(cmd, 0x80,
true);
116 i2c_master_write_byte(cmd, 0x12,
true);
118 i2c_master_write_byte(cmd, 0x02,
true);
120 i2c_master_write_byte(cmd, 0xFF,
true);
123 i2c_master_write_byte(cmd, 0x40,
true);
128 i2c_master_write_byte(cmd, 0x00,
true);
130 i2c_master_write_byte(cmd, 0x10,
true);
132 i2c_master_write_byte(cmd, 0x14,
true);
137 i2c_master_stop(cmd);
139 esp_err_t espRc = i2c_master_cmd_begin(I2C_NUM_0, cmd, 10 / portTICK_PERIOD_MS);
142 ESP_LOGI(
tag,
"OLED configured successfully");
146 ESP_LOGE(
tag,
"OLED configuration failed. code: 0x%.2X", espRc);
148 i2c_cmd_link_delete(cmd);
161 i2c_cmd_handle_t cmd;
168 int _seg = seg + CONFIG_OFFSETX;
169 uint8_t columLow = _seg & 0x0F;
170 uint8_t columHigh = (_seg >> 4) & 0x0F;
178 cmd = i2c_cmd_link_create();
179 i2c_master_start(cmd);
180 i2c_master_write_byte(cmd, (
dev->
_address << 1) | I2C_MASTER_WRITE,
true);
184 i2c_master_write_byte(cmd, (0x00 + columLow),
true);
186 i2c_master_write_byte(cmd, (0x10 + columHigh),
true);
188 i2c_master_write_byte(cmd, 0xB0 | _page,
true);
190 i2c_master_stop(cmd);
191 i2c_master_cmd_begin(I2C_NUM_0, cmd, 10 / portTICK_PERIOD_MS);
192 i2c_cmd_link_delete(cmd);
194 cmd = i2c_cmd_link_create();
195 i2c_master_start(cmd);
196 i2c_master_write_byte(cmd, (
dev->
_address << 1) | I2C_MASTER_WRITE,
true);
199 i2c_master_write(cmd, images, width,
true);
201 i2c_master_stop(cmd);
202 i2c_master_cmd_begin(I2C_NUM_0, cmd, 10 / portTICK_PERIOD_MS);
203 i2c_cmd_link_delete(cmd);
213 i2c_cmd_handle_t cmd;
214 int _contrast = contrast;
220 cmd = i2c_cmd_link_create();
221 i2c_master_start(cmd);
222 i2c_master_write_byte(cmd, (
dev->
_address << 1) | I2C_MASTER_WRITE,
true);
225 i2c_master_write_byte(cmd, _contrast,
true);
226 i2c_master_stop(cmd);
227 i2c_master_cmd_begin(I2C_NUM_0, cmd, 10 / portTICK_PERIOD_MS);
228 i2c_cmd_link_delete(cmd);
240 i2c_cmd_handle_t cmd = i2c_cmd_link_create();
241 i2c_master_start(cmd);
243 i2c_master_write_byte(cmd, (
dev->
_address << 1) | I2C_MASTER_WRITE,
true);
249 i2c_master_write_byte(cmd, 0x00,
true);
250 i2c_master_write_byte(cmd, 0x00,
true);
251 i2c_master_write_byte(cmd, CONFIG_SSD1306_FRAME_FREQ,
true);
252 i2c_master_write_byte(cmd, 0x07,
true);
253 i2c_master_write_byte(cmd, 0x00,
true);
254 i2c_master_write_byte(cmd, 0xFF,
true);
261 i2c_master_write_byte(cmd, 0x00,
true);
262 i2c_master_write_byte(cmd, 0x00,
true);
263 i2c_master_write_byte(cmd, CONFIG_SSD1306_FRAME_FREQ,
true);
264 i2c_master_write_byte(cmd, 0x07,
true);
265 i2c_master_write_byte(cmd, 0x00,
true);
266 i2c_master_write_byte(cmd, 0xFF,
true);
273 i2c_master_write_byte(cmd, 0x00,
true);
274 i2c_master_write_byte(cmd, 0x00,
true);
275 i2c_master_write_byte(cmd, CONFIG_SSD1306_FRAME_FREQ,
true);
277 i2c_master_write_byte(cmd, 0x00,
true);
278 i2c_master_write_byte(cmd, 0x3F,
true);
281 i2c_master_write_byte(cmd, 0x00,
true);
284 i2c_master_write_byte(cmd, 0x40,
true);
286 i2c_master_write_byte(cmd, 0x20,
true);
293 i2c_master_write_byte(cmd, 0x00,
true);
294 i2c_master_write_byte(cmd, 0x00,
true);
295 i2c_master_write_byte(cmd, CONFIG_SSD1306_FRAME_FREQ,
true);
297 i2c_master_write_byte(cmd, 0x00,
true);
298 i2c_master_write_byte(cmd, 0x01,
true);
301 i2c_master_write_byte(cmd, 0x00,
true);
304 i2c_master_write_byte(cmd, 0x40,
true);
306 i2c_master_write_byte(cmd, 0x20,
true);
315 i2c_master_stop(cmd);
316 espRc = i2c_master_cmd_begin(I2C_NUM_0, cmd, 10 / portTICK_PERIOD_MS);
319 ESP_LOGD(
tag,
"Scroll command succeeded");
323 ESP_LOGE(
tag,
"Scroll command failed. code: 0x%.2X", espRc);
326 i2c_cmd_link_delete(cmd);
339 i2c_cmd_handle_t cmd = i2c_cmd_link_create();
340 i2c_master_start(cmd);
342 i2c_master_write_byte(cmd, (
dev->
_address << 1) | I2C_MASTER_WRITE,
true);
348 i2c_master_write_byte(cmd, 0x00,
true);
349 i2c_master_write_byte(cmd, page,
true);
350 i2c_master_write_byte(cmd, CONFIG_SSD1306_FRAME_FREQ,
true);
351 i2c_master_write_byte(cmd, page,
true);
352 i2c_master_write_byte(cmd, 0x00,
true);
353 i2c_master_write_byte(cmd, 0xFF,
true);
360 i2c_master_write_byte(cmd, 0x00,
true);
361 i2c_master_write_byte(cmd, page,
true);
362 i2c_master_write_byte(cmd, CONFIG_SSD1306_FRAME_FREQ,
true);
363 i2c_master_write_byte(cmd, page,
true);
364 i2c_master_write_byte(cmd, 0x00,
true);
365 i2c_master_write_byte(cmd, 0xFF,
true);
374 i2c_master_stop(cmd);
375 espRc = i2c_master_cmd_begin(I2C_NUM_0, cmd, 10 / portTICK_PERIOD_MS);
378 ESP_LOGD(
tag,
"Scroll command succeeded");
382 ESP_LOGE(
tag,
"Scroll command failed. code: 0x%.2X", espRc);
385 i2c_cmd_link_delete(cmd);
SSD1306_t dev
device for oled
defininitions for setting up, interacting with and sending commands to an ssd1306 driven screen via i...
#define OLED_CMD_SET_DISPLAY_OFFSET
#define OLED_CMD_ACTIVE_SCROLL
#define OLED_CMD_SET_CHARGE_PUMP
#define OLED_CMD_DISPLAY_ON
#define OLED_CMD_DISPLAY_OFF
#define OLED_CONTROL_BYTE_CMD_STREAM
#define OLED_CMD_SET_MUX_RATIO
#define OLED_CMD_DISPLAY_NORMAL
#define OLED_CMD_SET_SEGMENT_REMAP_0
#define OLED_CMD_SET_SEGMENT_REMAP_1
#define OLED_CMD_SET_COM_PIN_MAP
#define OLED_CMD_HORIZONTAL_LEFT
#define OLED_CMD_SET_CONTRAST
#define OLED_CONTROL_BYTE_DATA_STREAM
#define OLED_CMD_SET_COM_SCAN_MODE
#define OLED_CMD_HORIZONTAL_RIGHT
#define OLED_CMD_SET_DISPLAY_CLK_DIV
#define OLED_CMD_SET_PAGE_ADDR_MODE
#define OLED_CMD_DISPLAY_RAM
#define OLED_CMD_DEACTIVE_SCROLL
#define OLED_CMD_VERTICAL
#define OLED_CMD_SET_VCOMH_DESELCT
#define OLED_CMD_SET_MEMORY_ADDR_MODE
#define OLED_CMD_CONTINUOUS_SCROLL
void i2c_contrast(SSD1306_t *dev, int contrast)
void i2c_master_init(SSD1306_t *dev, int16_t sda, int16_t scl, int16_t reset)
void i2c_init(SSD1306_t *dev, int width, int height)
void i2c_hardware_scroll_line(SSD1306_t *dev, int page, ssd1306_scroll_type_t scroll)
void i2c_display_image(SSD1306_t *dev, int page, int seg, uint8_t *images, int width)
void i2c_hardware_scroll(SSD1306_t *dev, ssd1306_scroll_type_t scroll)
#define tag
tag for logging library