mirror of
https://github.com/BotChain-Robots/firmware.git
synced 2026-07-08 17:47:21 +02:00
Display control code
This commit is contained in:
3
components/oled/CMakeLists.txt
Normal file
3
components/oled/CMakeLists.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
idf_component_register(INCLUDE_DIRS "include"
|
||||
PRIV_REQUIRES driver
|
||||
SRCS "Oled.cpp")
|
||||
159
components/oled/Oled.cpp
Normal file
159
components/oled/Oled.cpp
Normal file
@@ -0,0 +1,159 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "driver/gpio.h"
|
||||
#include "driver/i2c.h"
|
||||
#include "esp_err.h"
|
||||
#include "esp_log.h"
|
||||
#include "Oled.h"
|
||||
#include "font8x8_basic.h"
|
||||
#include "ssd1306.h"
|
||||
|
||||
#define TAG "OLED"
|
||||
|
||||
// 128x64 pixels
|
||||
// 8 pixels per byte
|
||||
// 128 bytes per page -> ((128*64)/8)/128 = 8 pages.
|
||||
#define DISPLAY_WIDTH 128
|
||||
#define DISPLAY_HEIGHT 64
|
||||
#define PAGE_SIZE 128
|
||||
#define PAGE_COUNT 8
|
||||
#define I2C_PORT I2C_NUM_0
|
||||
|
||||
void Oled::init(uint8_t sda_pin, uint8_t scl_pin) {
|
||||
i2c_config_t i2c_config = {
|
||||
.mode = I2C_MODE_MASTER,
|
||||
.sda_io_num = sda_pin,
|
||||
.scl_io_num = scl_pin,
|
||||
.sda_pullup_en = GPIO_PULLUP_ENABLE,
|
||||
.scl_pullup_en = GPIO_PULLUP_ENABLE,
|
||||
.master = {
|
||||
.clk_speed = 1000000
|
||||
},
|
||||
.clk_flags = 0,
|
||||
};
|
||||
i2c_param_config(I2C_PORT, &i2c_config);
|
||||
|
||||
i2c_driver_install(I2C_PORT, I2C_MODE_MASTER, 0, 0, 0);
|
||||
|
||||
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
|
||||
i2c_master_start(cmd);
|
||||
i2c_master_write_byte(cmd, (OLED_I2C_ADDRESS << 1) | I2C_MASTER_WRITE, true);
|
||||
i2c_master_write_byte(cmd, OLED_CONTROL_BYTE_CMD_STREAM, true);
|
||||
i2c_master_write_byte(cmd, OLED_CMD_SET_CHARGE_PUMP, true);
|
||||
i2c_master_write_byte(cmd, 0x14, true);
|
||||
i2c_master_write_byte(cmd, OLED_CMD_SET_SEGMENT_REMAP, true);
|
||||
i2c_master_write_byte(cmd, OLED_CMD_SET_COM_SCAN_MODE, true);
|
||||
i2c_master_write_byte(cmd, OLED_CMD_DISPLAY_ON, true);
|
||||
i2c_master_stop(cmd);
|
||||
|
||||
if (ESP_OK != i2c_master_cmd_begin(I2C_PORT, cmd, 10 / portTICK_PERIOD_MS)) {
|
||||
ESP_LOGE(TAG, "configuration failed");
|
||||
}
|
||||
|
||||
i2c_cmd_link_delete(cmd);
|
||||
|
||||
clear_display();
|
||||
}
|
||||
|
||||
void Oled::clear_display() {
|
||||
ESP_LOGI(TAG, "clear_display");
|
||||
i2c_cmd_handle_t cmd;
|
||||
|
||||
uint8_t page[PAGE_SIZE] = {0};
|
||||
for (uint8_t i = 0; i < PAGE_COUNT; i++) {
|
||||
cmd = i2c_cmd_link_create();
|
||||
i2c_master_start(cmd);
|
||||
i2c_master_write_byte(cmd, (OLED_I2C_ADDRESS << 1) | I2C_MASTER_WRITE, true);
|
||||
i2c_master_write_byte(cmd, OLED_CONTROL_BYTE_CMD_SINGLE, true);
|
||||
i2c_master_write_byte(cmd, 0xB0 | i, true);
|
||||
|
||||
i2c_master_write_byte(cmd, OLED_CONTROL_BYTE_DATA_STREAM, true);
|
||||
i2c_master_write(cmd, page, PAGE_SIZE, true);
|
||||
i2c_master_stop(cmd);
|
||||
i2c_master_cmd_begin(I2C_PORT, cmd, 10 / portTICK_PERIOD_MS);
|
||||
i2c_cmd_link_delete(cmd);
|
||||
}
|
||||
}
|
||||
|
||||
void Oled::set_contrast(uint8_t contrast) {
|
||||
i2c_cmd_handle_t cmd;
|
||||
cmd = i2c_cmd_link_create();
|
||||
i2c_master_start(cmd);
|
||||
i2c_master_write_byte(cmd, (OLED_I2C_ADDRESS << 1) | I2C_MASTER_WRITE, true);
|
||||
i2c_master_write_byte(cmd, OLED_CONTROL_BYTE_CMD_STREAM, true);
|
||||
i2c_master_write_byte(cmd, OLED_CMD_SET_CONTRAST, true);
|
||||
i2c_master_write_byte(cmd, contrast, true);
|
||||
i2c_master_stop(cmd);
|
||||
i2c_master_cmd_begin(I2C_NUM_0, cmd, 10 / portTICK_PERIOD_MS);
|
||||
i2c_cmd_link_delete(cmd);
|
||||
}
|
||||
|
||||
void Oled::display_text(const std::string& text) {
|
||||
ESP_LOGI(TAG, "display_text %s", text.c_str());
|
||||
i2c_cmd_handle_t cmd;
|
||||
|
||||
uint8_t cur_page = 0;
|
||||
uint8_t col = 0;
|
||||
auto col_width = DISPLAY_WIDTH / 8; // using an 8x8 font
|
||||
auto num_rows = DISPLAY_HEIGHT / 8; // using an 8x8 font
|
||||
auto max_size = col_width * num_rows;
|
||||
|
||||
cmd = i2c_cmd_link_create();
|
||||
i2c_master_start(cmd);
|
||||
i2c_master_write_byte(cmd, (OLED_I2C_ADDRESS << 1) | I2C_MASTER_WRITE, true);
|
||||
|
||||
i2c_master_write_byte(cmd, OLED_CONTROL_BYTE_CMD_STREAM, true);
|
||||
i2c_master_write_byte(cmd, 0x00, true); // reset column
|
||||
i2c_master_write_byte(cmd, 0x10, true);
|
||||
i2c_master_write_byte(cmd, 0xB0 | cur_page, true); // reset page
|
||||
|
||||
i2c_master_stop(cmd);
|
||||
i2c_master_cmd_begin(I2C_NUM_0, cmd, 10 / portTICK_PERIOD_MS);
|
||||
i2c_cmd_link_delete(cmd);
|
||||
|
||||
for (uint8_t i = 0; i < text.size() && i < max_size; i++) {
|
||||
ESP_LOGI(TAG, "%d: %c", i, text[i]);
|
||||
if (text[i] == '\n' || col >= col_width) {
|
||||
ESP_LOGI(TAG, "new line");
|
||||
cmd = i2c_cmd_link_create();
|
||||
i2c_master_start(cmd);
|
||||
i2c_master_write_byte(cmd, (OLED_I2C_ADDRESS << 1) | I2C_MASTER_WRITE, true);
|
||||
|
||||
i2c_master_write_byte(cmd, OLED_CONTROL_BYTE_CMD_STREAM, true);
|
||||
i2c_master_write_byte(cmd, 0x00, true); // reset column
|
||||
i2c_master_write_byte(cmd, 0x10, true);
|
||||
i2c_master_write_byte(cmd, 0xB0 | ++cur_page, true); // increment page
|
||||
|
||||
i2c_master_stop(cmd);
|
||||
i2c_master_cmd_begin(I2C_NUM_0, cmd, 10/portTICK_PERIOD_MS);
|
||||
i2c_cmd_link_delete(cmd);
|
||||
col = 0;
|
||||
} else {
|
||||
cmd = i2c_cmd_link_create();
|
||||
i2c_master_start(cmd);
|
||||
i2c_master_write_byte(cmd, (OLED_I2C_ADDRESS << 1) | I2C_MASTER_WRITE, true);
|
||||
|
||||
i2c_master_write_byte(cmd, OLED_CONTROL_BYTE_DATA_STREAM, true);
|
||||
uint8_t rotated[8];
|
||||
rotate8x8((uint8_t*)font8x8_basic[(uint8_t)text[i]], rotated);
|
||||
i2c_master_write(cmd, rotated, 8, true);
|
||||
|
||||
i2c_master_stop(cmd);
|
||||
i2c_master_cmd_begin(I2C_NUM_0, cmd, 10/portTICK_PERIOD_MS);
|
||||
i2c_cmd_link_delete(cmd);
|
||||
col++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Oled::rotate8x8(uint8_t in[8], uint8_t out[8]) {
|
||||
for (int x = 0; x < 8; x++) {
|
||||
out[x] = 0;
|
||||
for (int y = 0; y < 8; y++) {
|
||||
if (in[y] & (1 << x)) {
|
||||
out[x] |= (1 << (7 - y));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
23
components/oled/include/Oled.h
Normal file
23
components/oled/include/Oled.h
Normal file
@@ -0,0 +1,23 @@
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
#ifndef OLED_H
|
||||
#define OLED_H
|
||||
|
||||
class Oled {
|
||||
public:
|
||||
Oled(uint8_t sda_pin, uint8_t scl_pin) {
|
||||
init(sda_pin, scl_pin);
|
||||
};
|
||||
void clear_display();
|
||||
void set_contrast(uint8_t contrast);
|
||||
void display_text(const std::string& text);
|
||||
|
||||
private:
|
||||
void init(uint8_t sda_pin, uint8_t scl_pin);
|
||||
void rotate8x8(uint8_t in[8], uint8_t out[8]);
|
||||
|
||||
};
|
||||
|
||||
#endif // OLED_H
|
||||
163
components/oled/include/font8x8_basic.h
Normal file
163
components/oled/include/font8x8_basic.h
Normal file
@@ -0,0 +1,163 @@
|
||||
#ifndef FONT_H
|
||||
#define FONT_H
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
// Adapted from https://github.com/dhepper/font8x8/blob/master/font8x8_basic.h
|
||||
|
||||
/**
|
||||
* 8x8 monochrome bitmap fonts for rendering
|
||||
* Author: Daniel Hepper <daniel@hepper.net>
|
||||
*
|
||||
* License: Public Domain
|
||||
*
|
||||
* Based on:
|
||||
* // Summary: font8x8.h
|
||||
* // 8x8 monochrome bitmap fonts for rendering
|
||||
* //
|
||||
* // Author:
|
||||
* // Marcel Sondaar
|
||||
* // International Business Machines (public domain VGA fonts)
|
||||
* //
|
||||
* // License:
|
||||
* // Public Domain
|
||||
*
|
||||
* Fetched from: http://dimensionalrift.homelinux.net/combuster/mos3/?p=viewsource&file=/modules/gfx/font8_8.asm
|
||||
**/
|
||||
|
||||
// Constant: font8x8_basic
|
||||
// Contains an 8x8 font map for unicode points U+0000 - U+007F (basic latin)
|
||||
uint8_t font8x8_basic[128][8] = {
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0x00, 0x18, 0x00, 0x18, 0x18, 0x3C, 0x3C, 0x18 },
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x36 },
|
||||
{ 0x00, 0x36, 0x36, 0x7F, 0x36, 0x7F, 0x36, 0x36 },
|
||||
{ 0x00, 0x0C, 0x1F, 0x30, 0x1E, 0x03, 0x3E, 0x0C },
|
||||
{ 0x00, 0x63, 0x66, 0x0C, 0x18, 0x33, 0x63, 0x00 },
|
||||
{ 0x00, 0x6E, 0x33, 0x3B, 0x6E, 0x1C, 0x36, 0x1C },
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x06, 0x06 },
|
||||
{ 0x00, 0x18, 0x0C, 0x06, 0x06, 0x06, 0x0C, 0x18 },
|
||||
{ 0x00, 0x06, 0x0C, 0x18, 0x18, 0x18, 0x0C, 0x06 },
|
||||
{ 0x00, 0x00, 0x66, 0x3C, 0xFF, 0x3C, 0x66, 0x00 },
|
||||
{ 0x00, 0x00, 0x0C, 0x0C, 0x3F, 0x0C, 0x0C, 0x00 },
|
||||
{ 0x06, 0x0C, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x3F, 0x00, 0x00, 0x00 },
|
||||
{ 0x00, 0x0C, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0x00, 0x01, 0x03, 0x06, 0x0C, 0x18, 0x30, 0x60 },
|
||||
{ 0x00, 0x3E, 0x67, 0x6F, 0x7B, 0x73, 0x63, 0x3E },
|
||||
{ 0x00, 0x3F, 0x0C, 0x0C, 0x0C, 0x0C, 0x0E, 0x0C },
|
||||
{ 0x00, 0x3F, 0x33, 0x06, 0x1C, 0x30, 0x33, 0x1E },
|
||||
{ 0x00, 0x1E, 0x33, 0x30, 0x1C, 0x30, 0x33, 0x1E },
|
||||
{ 0x00, 0x78, 0x30, 0x7F, 0x33, 0x36, 0x3C, 0x38 },
|
||||
{ 0x00, 0x1E, 0x33, 0x30, 0x30, 0x1F, 0x03, 0x3F },
|
||||
{ 0x00, 0x1E, 0x33, 0x33, 0x1F, 0x03, 0x06, 0x1C },
|
||||
{ 0x00, 0x0C, 0x0C, 0x0C, 0x18, 0x30, 0x33, 0x3F },
|
||||
{ 0x00, 0x1E, 0x33, 0x33, 0x1E, 0x33, 0x33, 0x1E },
|
||||
{ 0x00, 0x0E, 0x18, 0x30, 0x3E, 0x33, 0x33, 0x1E },
|
||||
{ 0x00, 0x0C, 0x0C, 0x00, 0x00, 0x0C, 0x0C, 0x00 },
|
||||
{ 0x06, 0x0C, 0x0C, 0x00, 0x00, 0x0C, 0x0C, 0x00 },
|
||||
{ 0x00, 0x18, 0x0C, 0x06, 0x03, 0x06, 0x0C, 0x18 },
|
||||
{ 0x00, 0x00, 0x3F, 0x00, 0x00, 0x3F, 0x00, 0x00 },
|
||||
{ 0x00, 0x06, 0x0C, 0x18, 0x30, 0x18, 0x0C, 0x06 },
|
||||
{ 0x00, 0x0C, 0x00, 0x0C, 0x18, 0x30, 0x33, 0x1E },
|
||||
{ 0x00, 0x1E, 0x03, 0x7B, 0x7B, 0x7B, 0x63, 0x3E },
|
||||
{ 0x00, 0x33, 0x33, 0x3F, 0x33, 0x33, 0x1E, 0x0C },
|
||||
{ 0x00, 0x3F, 0x66, 0x66, 0x3E, 0x66, 0x66, 0x3F },
|
||||
{ 0x00, 0x3C, 0x66, 0x03, 0x03, 0x03, 0x66, 0x3C },
|
||||
{ 0x00, 0x1F, 0x36, 0x66, 0x66, 0x66, 0x36, 0x1F },
|
||||
{ 0x00, 0x7F, 0x46, 0x16, 0x1E, 0x16, 0x46, 0x7F },
|
||||
{ 0x00, 0x0F, 0x06, 0x16, 0x1E, 0x16, 0x46, 0x7F },
|
||||
{ 0x00, 0x7C, 0x66, 0x73, 0x03, 0x03, 0x66, 0x3C },
|
||||
{ 0x00, 0x33, 0x33, 0x33, 0x3F, 0x33, 0x33, 0x33 },
|
||||
{ 0x00, 0x1E, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x1E },
|
||||
{ 0x00, 0x1E, 0x33, 0x33, 0x30, 0x30, 0x30, 0x78 },
|
||||
{ 0x00, 0x67, 0x66, 0x36, 0x1E, 0x36, 0x66, 0x67 },
|
||||
{ 0x00, 0x7F, 0x66, 0x46, 0x06, 0x06, 0x06, 0x0F },
|
||||
{ 0x00, 0x63, 0x63, 0x6B, 0x7F, 0x7F, 0x77, 0x63 },
|
||||
{ 0x00, 0x63, 0x63, 0x73, 0x7B, 0x6F, 0x67, 0x63 },
|
||||
|
||||
{ 0x00, 0x1C, 0x36, 0x63, 0x63, 0x63, 0x36, 0x1C },
|
||||
{ 0x00, 0x0F, 0x06, 0x06, 0x3E, 0x66, 0x66, 0x3F },
|
||||
{ 0x00, 0x38, 0x1E, 0x3B, 0x33, 0x33, 0x33, 0x1E },
|
||||
{ 0x00, 0x67, 0x66, 0x36, 0x3E, 0x66, 0x66, 0x3F },
|
||||
{ 0x00, 0x1E, 0x33, 0x38, 0x0E, 0x07, 0x33, 0x1E },
|
||||
{ 0x00, 0x1E, 0x0C, 0x0C, 0x0C, 0x0C, 0x2D, 0x3F },
|
||||
{ 0x00, 0x3F, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33 },
|
||||
{ 0x00, 0x0C, 0x1E, 0x33, 0x33, 0x33, 0x33, 0x33 },
|
||||
{ 0x00, 0x63, 0x77, 0x7F, 0x6B, 0x63, 0x63, 0x63 },
|
||||
{ 0x00, 0x63, 0x36, 0x1C, 0x1C, 0x36, 0x63, 0x63 },
|
||||
{ 0x00, 0x1E, 0x0C, 0x0C, 0x1E, 0x33, 0x33, 0x33 },
|
||||
{ 0x00, 0x7F, 0x66, 0x4C, 0x18, 0x31, 0x63, 0x7F },
|
||||
{ 0x00, 0x1E, 0x06, 0x06, 0x06, 0x06, 0x06, 0x1E },
|
||||
{ 0x00, 0x40, 0x60, 0x30, 0x18, 0x0C, 0x06, 0x03 },
|
||||
{ 0x00, 0x1E, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1E },
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x63, 0x36, 0x1C, 0x08 },
|
||||
{ 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x0C, 0x0C },
|
||||
{ 0x00, 0x6E, 0x33, 0x3E, 0x30, 0x1E, 0x00, 0x00 },
|
||||
{ 0x00, 0x3B, 0x66, 0x66, 0x3E, 0x06, 0x06, 0x07 },
|
||||
{ 0x00, 0x1E, 0x33, 0x03, 0x33, 0x1E, 0x00, 0x00 },
|
||||
{ 0x00, 0x6E, 0x33, 0x33, 0x3E, 0x30, 0x30, 0x38 },
|
||||
{ 0x00, 0x1E, 0x03, 0x3F, 0x33, 0x1E, 0x00, 0x00 },
|
||||
{ 0x00, 0x0F, 0x06, 0x06, 0x0F, 0x06, 0x36, 0x1C },
|
||||
{ 0x1F, 0x30, 0x3E, 0x33, 0x33, 0x6E, 0x00, 0x00 },
|
||||
{ 0x00, 0x67, 0x66, 0x66, 0x6E, 0x36, 0x06, 0x07 },
|
||||
{ 0x00, 0x1E, 0x0C, 0x0C, 0x0C, 0x0E, 0x00, 0x0C },
|
||||
{ 0x1E, 0x33, 0x33, 0x30, 0x30, 0x30, 0x00, 0x30 },
|
||||
{ 0x00, 0x67, 0x36, 0x1E, 0x36, 0x66, 0x06, 0x07 },
|
||||
{ 0x00, 0x1E, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0E },
|
||||
{ 0x00, 0x63, 0x6B, 0x7F, 0x7F, 0x33, 0x00, 0x00 },
|
||||
{ 0x00, 0x33, 0x33, 0x33, 0x33, 0x1F, 0x00, 0x00 },
|
||||
{ 0x00, 0x1E, 0x33, 0x33, 0x33, 0x1E, 0x00, 0x00 },
|
||||
{ 0x0F, 0x06, 0x3E, 0x66, 0x66, 0x3B, 0x00, 0x00 },
|
||||
{ 0x78, 0x30, 0x3E, 0x33, 0x33, 0x6E, 0x00, 0x00 },
|
||||
{ 0x00, 0x0F, 0x06, 0x66, 0x6E, 0x3B, 0x00, 0x00 },
|
||||
{ 0x00, 0x1F, 0x30, 0x1E, 0x03, 0x3E, 0x00, 0x00 },
|
||||
{ 0x00, 0x18, 0x2C, 0x0C, 0x0C, 0x3E, 0x0C, 0x08 },
|
||||
{ 0x00, 0x6E, 0x33, 0x33, 0x33, 0x33, 0x00, 0x00 },
|
||||
{ 0x00, 0x0C, 0x1E, 0x33, 0x33, 0x33, 0x00, 0x00 },
|
||||
{ 0x00, 0x36, 0x7F, 0x7F, 0x6B, 0x63, 0x00, 0x00 },
|
||||
{ 0x00, 0x63, 0x36, 0x1C, 0x36, 0x63, 0x00, 0x00 },
|
||||
{ 0x1F, 0x30, 0x3E, 0x33, 0x33, 0x33, 0x00, 0x00 },
|
||||
{ 0x00, 0x3F, 0x26, 0x0C, 0x19, 0x3F, 0x00, 0x00 },
|
||||
{ 0x00, 0x38, 0x0C, 0x0C, 0x07, 0x0C, 0x0C, 0x38 },
|
||||
{ 0x00, 0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x18 },
|
||||
{ 0x00, 0x07, 0x0C, 0x0C, 0x38, 0x0C, 0x0C, 0x07 },
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3B, 0x6E },
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
|
||||
};
|
||||
|
||||
|
||||
#endif // FONT_H
|
||||
45
components/oled/include/ssd1306.h
Normal file
45
components/oled/include/ssd1306.h
Normal file
@@ -0,0 +1,45 @@
|
||||
#ifndef SSD_1306_H
|
||||
#define SSD_1306_H
|
||||
|
||||
// From http://robotcantalk.blogspot.com/2015/03/interfacing-arduino-with-ssd1306-driven.html
|
||||
|
||||
// SLA (0x3C) + WRITE_MODE (0x00) = 0x78 (0b01111000)
|
||||
#define OLED_I2C_ADDRESS 0x3C
|
||||
|
||||
// Control byte
|
||||
#define OLED_CONTROL_BYTE_CMD_SINGLE 0x80
|
||||
#define OLED_CONTROL_BYTE_CMD_STREAM 0x00
|
||||
#define OLED_CONTROL_BYTE_DATA_STREAM 0x40
|
||||
|
||||
// Fundamental commands (pg.28)
|
||||
#define OLED_CMD_SET_CONTRAST 0x81 // follow with 0x7F
|
||||
#define OLED_CMD_DISPLAY_RAM 0xA4
|
||||
#define OLED_CMD_DISPLAY_ALLON 0xA5
|
||||
#define OLED_CMD_DISPLAY_NORMAL 0xA6
|
||||
#define OLED_CMD_DISPLAY_INVERTED 0xA7
|
||||
#define OLED_CMD_DISPLAY_OFF 0xAE
|
||||
#define OLED_CMD_DISPLAY_ON 0xAF
|
||||
|
||||
// Addressing Command Table (pg.30)
|
||||
#define OLED_CMD_SET_MEMORY_ADDR_MODE 0x20 // follow with 0x00 = HORZ mode = Behave like a KS108 graphic LCD
|
||||
#define OLED_CMD_SET_COLUMN_RANGE 0x21 // can be used only in HORZ/VERT mode - follow with 0x00 and 0x7F = COL127
|
||||
#define OLED_CMD_SET_PAGE_RANGE 0x22 // can be used only in HORZ/VERT mode - follow with 0x00 and 0x07 = PAGE7
|
||||
|
||||
// Hardware Config (pg.31)
|
||||
#define OLED_CMD_SET_DISPLAY_START_LINE 0x40
|
||||
#define OLED_CMD_SET_SEGMENT_REMAP 0xA1
|
||||
#define OLED_CMD_SET_MUX_RATIO 0xA8 // follow with 0x3F = 64 MUX
|
||||
#define OLED_CMD_SET_COM_SCAN_MODE 0xC8
|
||||
#define OLED_CMD_SET_DISPLAY_OFFSET 0xD3 // follow with 0x00
|
||||
#define OLED_CMD_SET_COM_PIN_MAP 0xDA // follow with 0x12
|
||||
#define OLED_CMD_NOP 0xE3 // NOP
|
||||
|
||||
// Timing and Driving Scheme (pg.32)
|
||||
#define OLED_CMD_SET_DISPLAY_CLK_DIV 0xD5 // follow with 0x80
|
||||
#define OLED_CMD_SET_PRECHARGE 0xD9 // follow with 0xF1
|
||||
#define OLED_CMD_SET_VCOMH_DESELCT 0xDB // follow with 0x30
|
||||
|
||||
// Charge Pump (pg.62)
|
||||
#define OLED_CMD_SET_CHARGE_PUMP 0x8D // follow with 0x14
|
||||
|
||||
#endif // SSD_1306_H
|
||||
Reference in New Issue
Block a user