mirror of
https://github.com/nopnop2002/esp-idf-ssd1306.git
synced 2024-10-03 18:18:47 -04:00
Added ImageDemo
This commit is contained in:
parent
5532a69737
commit
a532736e71
8
ImageDemo/CMakeLists.txt
Normal file
8
ImageDemo/CMakeLists.txt
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
# The following lines of boilerplate have to be in your project's CMakeLists
|
||||||
|
# in this exact order for cmake to work correctly
|
||||||
|
cmake_minimum_required(VERSION 3.5)
|
||||||
|
|
||||||
|
set(EXTRA_COMPONENT_DIRS ../components/ssd1306)
|
||||||
|
|
||||||
|
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||||
|
project(ssd1306)
|
8
ImageDemo/README.md
Normal file
8
ImageDemo/README.md
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
# ImageDemo for SSD1306
|
||||||
|
|
||||||
|
![ImageDemo-1](https://user-images.githubusercontent.com/6020549/165235302-6909f7c4-78e2-4c9d-8cb3-81eb9c920534.JPG)
|
||||||
|
![ImageDemo-2](https://user-images.githubusercontent.com/6020549/165235310-88430dc3-5bed-4190-99e4-fe268c449218.JPG)
|
||||||
|
|
||||||
|
|
||||||
|
I borrowed the BIT MAP data from [here](https://www.mischianti.org/2021/07/14/ssd1306-oled-display-draw-images-splash-and-animations-2/).
|
||||||
|
|
4
ImageDemo/main/CMakeLists.txt
Normal file
4
ImageDemo/main/CMakeLists.txt
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
set(COMPONENT_SRCS "main.c")
|
||||||
|
set(COMPONENT_ADD_INCLUDEDIRS "")
|
||||||
|
|
||||||
|
register_component()
|
211
ImageDemo/main/_
Normal file
211
ImageDemo/main/_
Normal file
@ -0,0 +1,211 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "freertos/FreeRTOS.h"
|
||||||
|
#include "freertos/task.h"
|
||||||
|
#include "esp_log.h"
|
||||||
|
|
||||||
|
#include "ssd1306.h"
|
||||||
|
#include "font8x8_basic.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
You have to set this config value with menuconfig
|
||||||
|
CONFIG_INTERFACE
|
||||||
|
|
||||||
|
for i2c
|
||||||
|
CONFIG_MODEL
|
||||||
|
CONFIG_SDA_GPIO
|
||||||
|
CONFIG_SCL_GPIO
|
||||||
|
CONFIG_RESET_GPIO
|
||||||
|
|
||||||
|
for SPI
|
||||||
|
CONFIG_CS_GPIO
|
||||||
|
CONFIG_DC_GPIO
|
||||||
|
CONFIG_RESET_GPIO
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define TAG "SSD1306"
|
||||||
|
|
||||||
|
// https://www.mischianti.org/2021/07/14/ssd1306-oled-display-draw-images-splash-and-animations-2/
|
||||||
|
uint8_t batman[] = {
|
||||||
|
0b11111111, 0b11111111, 0b11111111, 0b11111111,
|
||||||
|
0b11111111, 0b10011111, 0b11111001, 0b11111111,
|
||||||
|
0b11111110, 0b00111110, 0b01111100, 0b01111111,
|
||||||
|
0b11111000, 0b00111100, 0b00111100, 0b00011111,
|
||||||
|
0b11110000, 0b00011100, 0b00111000, 0b00001111,
|
||||||
|
0b11110000, 0b00000000, 0b00000000, 0b00001111,
|
||||||
|
0b11100000, 0b00000000, 0b00000000, 0b00000111,
|
||||||
|
0b11100000, 0b00000000, 0b00000000, 0b00000111,
|
||||||
|
0b11110000, 0b00000000, 0b00000000, 0b00001111,
|
||||||
|
0b11110000, 0b11000100, 0b00100011, 0b00001111,
|
||||||
|
0b11111001, 0b11111110, 0b01111111, 0b10011111,
|
||||||
|
0b11111100, 0b11111110, 0b01111111, 0b00111111,
|
||||||
|
0b11111111, 0b11111111, 0b11111111, 0b11111111
|
||||||
|
};
|
||||||
|
|
||||||
|
// https://www.mischianti.org/2021/07/14/ssd1306-oled-display-draw-images-splash-and-animations-2/
|
||||||
|
uint8_t logoMischianti [1024] = {
|
||||||
|
// 'logoBN128x64, 128x64px
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xe0, 0x07, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xe0, 0x07, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xf0, 0x07, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf3, 0xcf, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xe0, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xc0, 0x7f, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xe7, 0xc0, 0x7f, 0xe7, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xff, 0xe0, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x01, 0xf8, 0x0f, 0xff, 0xff, 0xf0, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x03, 0xe0, 0x03, 0xff, 0xff, 0xc0, 0x03, 0xc0, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x07, 0x80, 0x00, 0xff, 0xff, 0x00, 0x41, 0xe0, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x7f, 0xfe, 0x00, 0xe0, 0xf0, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x1f, 0xf8, 0x00, 0xe0, 0x70, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x0f, 0xf0, 0x00, 0xe0, 0x70, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x07, 0xe0, 0x00, 0xe0, 0x38, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x1c, 0x7f, 0xf0, 0x03, 0xe0, 0x00, 0xe0, 0x38, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x1c, 0x7f, 0xf0, 0x03, 0xc0, 0x1f, 0xff, 0x38, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x1c, 0x7f, 0xf0, 0x03, 0xe0, 0x1f, 0xff, 0x38, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x07, 0xe0, 0x00, 0x60, 0x38, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x0f, 0xf0, 0x00, 0xe0, 0x70, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x1f, 0xf8, 0x00, 0xe0, 0x70, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x7c, 0x3e, 0x00, 0xe0, 0xf0, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x07, 0x80, 0x00, 0xf8, 0x1f, 0x00, 0x61, 0xe0, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x03, 0xc0, 0x03, 0xe0, 0x07, 0xc0, 0x03, 0xc0, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x01, 0xf8, 0x0f, 0xc0, 0x03, 0xf0, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xe0, 0x07, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xf0, 0x0f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 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, 0x10, 0x00, 0x08, 0x10, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x46, 0x63, 0x31, 0x90, 0xff, 0x13, 0xc3, 0x8b, 0x91, 0xe5, 0xdc, 0x80, 0xf3, 0xbf, 0x00,
|
||||||
|
0x00, 0x66, 0x73, 0x39, 0x90, 0xcd, 0x92, 0x24, 0x4c, 0x92, 0x26, 0x48, 0x81, 0x13, 0x27, 0x00,
|
||||||
|
0x00, 0x2e, 0x57, 0x2b, 0x90, 0x88, 0x93, 0x04, 0x08, 0xd0, 0x24, 0x68, 0x81, 0x1a, 0x23, 0x00,
|
||||||
|
0x00, 0x2a, 0xd5, 0x6a, 0xb0, 0x88, 0x91, 0xcc, 0x08, 0xd3, 0xe4, 0x68, 0x83, 0x1a, 0x63, 0x00,
|
||||||
|
0x00, 0x2b, 0x95, 0xca, 0xe0, 0x88, 0x90, 0x64, 0x08, 0xd2, 0x24, 0x68, 0x81, 0x1a, 0x63, 0x00,
|
||||||
|
0x00, 0x39, 0x9c, 0xce, 0x60, 0x88, 0x96, 0x24, 0x48, 0xd6, 0x64, 0x68, 0x81, 0x12, 0x27, 0x00,
|
||||||
|
0x00, 0x11, 0x88, 0xc4, 0x6c, 0x88, 0x93, 0xc3, 0x88, 0xd3, 0xb4, 0x6e, 0x98, 0xf2, 0x3f, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x22, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x00
|
||||||
|
};
|
||||||
|
|
||||||
|
void app_main(void)
|
||||||
|
{
|
||||||
|
SSD1306_t dev;
|
||||||
|
|
||||||
|
#if CONFIG_I2C_INTERFACE
|
||||||
|
ESP_LOGI(TAG, "INTERFACE is i2c");
|
||||||
|
ESP_LOGI(TAG, "CONFIG_SDA_GPIO=%d",CONFIG_SDA_GPIO);
|
||||||
|
ESP_LOGI(TAG, "CONFIG_SCL_GPIO=%d",CONFIG_SCL_GPIO);
|
||||||
|
ESP_LOGI(TAG, "CONFIG_RESET_GPIO=%d",CONFIG_RESET_GPIO);
|
||||||
|
i2c_master_init(&dev, CONFIG_SDA_GPIO, CONFIG_SCL_GPIO, CONFIG_RESET_GPIO);
|
||||||
|
#endif // CONFIG_I2C_INTERFACE
|
||||||
|
|
||||||
|
#if CONFIG_SPI_INTERFACE
|
||||||
|
ESP_LOGI(TAG, "INTERFACE is SPI");
|
||||||
|
ESP_LOGI(TAG, "CONFIG_MOSI_GPIO=%d",CONFIG_MOSI_GPIO);
|
||||||
|
ESP_LOGI(TAG, "CONFIG_SCLK_GPIO=%d",CONFIG_SCLK_GPIO);
|
||||||
|
ESP_LOGI(TAG, "CONFIG_CS_GPIO=%d",CONFIG_CS_GPIO);
|
||||||
|
ESP_LOGI(TAG, "CONFIG_DC_GPIO=%d",CONFIG_DC_GPIO);
|
||||||
|
ESP_LOGI(TAG, "CONFIG_RESET_GPIO=%d",CONFIG_RESET_GPIO);
|
||||||
|
spi_master_init(&dev, CONFIG_MOSI_GPIO, CONFIG_SCLK_GPIO, CONFIG_CS_GPIO, CONFIG_DC_GPIO, CONFIG_RESET_GPIO);
|
||||||
|
#endif // CONFIG_SPI_INTERFACE
|
||||||
|
|
||||||
|
#if CONFIG_FLIP
|
||||||
|
dev._flip = true;
|
||||||
|
ESP_LOGW(TAG, "Flip upside down");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if CONFIG_SSD1306_128x64
|
||||||
|
ESP_LOGI(TAG, "Panel is 128x64");
|
||||||
|
ssd1306_init(&dev, 128, 64);
|
||||||
|
#endif // CONFIG_SSD1306_128x64
|
||||||
|
#if CONFIG_SSD1306_128x32
|
||||||
|
ESP_LOGI(TAG, "Panel is 128x32");
|
||||||
|
ssd1306_init(&dev, 128, 32);
|
||||||
|
#endif // CONFIG_SSD1306_128x32
|
||||||
|
|
||||||
|
ssd1306_clear_screen(&dev, false);
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
// for test code
|
||||||
|
int srcBits = 7;
|
||||||
|
int dstBits = 0;
|
||||||
|
for (int i=0;i<8;i++) {
|
||||||
|
uint8_t dst = 0;
|
||||||
|
dst = ssd1306_copy_bit(0xf0, srcBits, dst, dstBits);
|
||||||
|
ESP_LOGI(TAG, "dst=%02x", dst);
|
||||||
|
srcBits--;
|
||||||
|
dstBits++;
|
||||||
|
}
|
||||||
|
srcBits = 7;
|
||||||
|
dstBits = 0;
|
||||||
|
for (int i=0;i<8;i++) {
|
||||||
|
uint8_t dst = 0;
|
||||||
|
dst = ssd1306_copy_bit(0x0f, srcBits, dst, dstBits);
|
||||||
|
ESP_LOGI(TAG, "dst=%02x", dst);
|
||||||
|
srcBits--;
|
||||||
|
dstBits++;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
while(1) {
|
||||||
|
ssd1306_contrast(&dev, 0xff);
|
||||||
|
#if CONFIG_SSD1306_128x64
|
||||||
|
ssd1306_display_text(&dev, 0, "SSD1306 128x64", 14, false);
|
||||||
|
#endif // CONFIG_SSD1306_128x64
|
||||||
|
|
||||||
|
#if CONFIG_SSD1306_128x32
|
||||||
|
ssd1306_display_text(&dev, 0, "SSD1306 128x32", 14, false);
|
||||||
|
#endif // CONFIG_SSD1306_128x32
|
||||||
|
ssd1306_display_text(&dev, 1, "BATMAN", 6, false);
|
||||||
|
|
||||||
|
int bitmapWidth = 4*8;
|
||||||
|
int width = ssd1306_get_width(&dev);
|
||||||
|
int xpos = width / 2; // center of width
|
||||||
|
xpos = xpos - bitmapWidth/2;
|
||||||
|
int ypos = 16;
|
||||||
|
ESP_LOGI(TAG, "width=%d xpos=%d", width, xpos);
|
||||||
|
ssd1306_bitmaps(&dev, xpos, ypos, batman, 4, 12);
|
||||||
|
vTaskDelay(3000 / portTICK_PERIOD_MS);
|
||||||
|
|
||||||
|
for(int i=0;i<128;i++) {
|
||||||
|
ssd1306_rotate(&dev, SCROLL_RIGHT, 2, 3, 0);
|
||||||
|
}
|
||||||
|
vTaskDelay(2000 / portTICK_PERIOD_MS);
|
||||||
|
|
||||||
|
#if CONFIG_SSD1306_128x64
|
||||||
|
ssd1306_clear_screen(&dev, false);
|
||||||
|
ssd1306_bitmaps(&dev, 0, 0, logoMischianti, 16, 64);
|
||||||
|
vTaskDelay(2000 / portTICK_PERIOD_MS);
|
||||||
|
|
||||||
|
for(int i=0;i<64;i++) {
|
||||||
|
ssd1306_rotate(&dev, SCROLL_UP, 0, 127, 0);
|
||||||
|
}
|
||||||
|
vTaskDelay(2000 / portTICK_PERIOD_MS);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
8
ImageDemo/main/component.mk
Normal file
8
ImageDemo/main/component.mk
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#
|
||||||
|
# Main component makefile.
|
||||||
|
#
|
||||||
|
# This Makefile can be left empty. By default, it will take the sources in the
|
||||||
|
# src/ directory, compile them and link them into lib(subdirectory_name).a
|
||||||
|
# in the build directory. This behaviour is entirely configurable,
|
||||||
|
# please read the ESP-IDF documents if you need to do this.
|
||||||
|
#
|
211
ImageDemo/main/main.c
Normal file
211
ImageDemo/main/main.c
Normal file
@ -0,0 +1,211 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "freertos/FreeRTOS.h"
|
||||||
|
#include "freertos/task.h"
|
||||||
|
#include "esp_log.h"
|
||||||
|
|
||||||
|
#include "ssd1306.h"
|
||||||
|
#include "font8x8_basic.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
You have to set this config value with menuconfig
|
||||||
|
CONFIG_INTERFACE
|
||||||
|
|
||||||
|
for i2c
|
||||||
|
CONFIG_MODEL
|
||||||
|
CONFIG_SDA_GPIO
|
||||||
|
CONFIG_SCL_GPIO
|
||||||
|
CONFIG_RESET_GPIO
|
||||||
|
|
||||||
|
for SPI
|
||||||
|
CONFIG_CS_GPIO
|
||||||
|
CONFIG_DC_GPIO
|
||||||
|
CONFIG_RESET_GPIO
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define TAG "SSD1306"
|
||||||
|
|
||||||
|
// https://www.mischianti.org/2021/07/14/ssd1306-oled-display-draw-images-splash-and-animations-2/
|
||||||
|
uint8_t batman[] = {
|
||||||
|
0b11111111, 0b11111111, 0b11111111, 0b11111111,
|
||||||
|
0b11111111, 0b10011111, 0b11111001, 0b11111111,
|
||||||
|
0b11111110, 0b00111110, 0b01111100, 0b01111111,
|
||||||
|
0b11111000, 0b00111100, 0b00111100, 0b00011111,
|
||||||
|
0b11110000, 0b00011100, 0b00111000, 0b00001111,
|
||||||
|
0b11110000, 0b00000000, 0b00000000, 0b00001111,
|
||||||
|
0b11100000, 0b00000000, 0b00000000, 0b00000111,
|
||||||
|
0b11100000, 0b00000000, 0b00000000, 0b00000111,
|
||||||
|
0b11110000, 0b00000000, 0b00000000, 0b00001111,
|
||||||
|
0b11110000, 0b11000100, 0b00100011, 0b00001111,
|
||||||
|
0b11111001, 0b11111110, 0b01111111, 0b10011111,
|
||||||
|
0b11111100, 0b11111110, 0b01111111, 0b00111111,
|
||||||
|
0b11111111, 0b11111111, 0b11111111, 0b11111111
|
||||||
|
};
|
||||||
|
|
||||||
|
// https://www.mischianti.org/2021/07/14/ssd1306-oled-display-draw-images-splash-and-animations-2/
|
||||||
|
uint8_t logoMischianti [1024] = {
|
||||||
|
// 'logoBN128x64, 128x64px
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xe0, 0x07, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xe0, 0x07, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xf0, 0x07, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf3, 0xcf, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xe0, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xc0, 0x7f, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xe7, 0xc0, 0x7f, 0xe7, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xff, 0xe0, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x01, 0xf8, 0x0f, 0xff, 0xff, 0xf0, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x03, 0xe0, 0x03, 0xff, 0xff, 0xc0, 0x03, 0xc0, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x07, 0x80, 0x00, 0xff, 0xff, 0x00, 0x41, 0xe0, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x7f, 0xfe, 0x00, 0xe0, 0xf0, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x1f, 0xf8, 0x00, 0xe0, 0x70, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x0f, 0xf0, 0x00, 0xe0, 0x70, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x07, 0xe0, 0x00, 0xe0, 0x38, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x1c, 0x7f, 0xf0, 0x03, 0xe0, 0x00, 0xe0, 0x38, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x1c, 0x7f, 0xf0, 0x03, 0xc0, 0x1f, 0xff, 0x38, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x1c, 0x7f, 0xf0, 0x03, 0xe0, 0x1f, 0xff, 0x38, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x07, 0xe0, 0x00, 0x60, 0x38, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x0f, 0xf0, 0x00, 0xe0, 0x70, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x1f, 0xf8, 0x00, 0xe0, 0x70, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x7c, 0x3e, 0x00, 0xe0, 0xf0, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x07, 0x80, 0x00, 0xf8, 0x1f, 0x00, 0x61, 0xe0, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x03, 0xc0, 0x03, 0xe0, 0x07, 0xc0, 0x03, 0xc0, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x01, 0xf8, 0x0f, 0xc0, 0x03, 0xf0, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xe0, 0x07, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xf0, 0x0f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 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, 0x10, 0x00, 0x08, 0x10, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x46, 0x63, 0x31, 0x90, 0xff, 0x13, 0xc3, 0x8b, 0x91, 0xe5, 0xdc, 0x80, 0xf3, 0xbf, 0x00,
|
||||||
|
0x00, 0x66, 0x73, 0x39, 0x90, 0xcd, 0x92, 0x24, 0x4c, 0x92, 0x26, 0x48, 0x81, 0x13, 0x27, 0x00,
|
||||||
|
0x00, 0x2e, 0x57, 0x2b, 0x90, 0x88, 0x93, 0x04, 0x08, 0xd0, 0x24, 0x68, 0x81, 0x1a, 0x23, 0x00,
|
||||||
|
0x00, 0x2a, 0xd5, 0x6a, 0xb0, 0x88, 0x91, 0xcc, 0x08, 0xd3, 0xe4, 0x68, 0x83, 0x1a, 0x63, 0x00,
|
||||||
|
0x00, 0x2b, 0x95, 0xca, 0xe0, 0x88, 0x90, 0x64, 0x08, 0xd2, 0x24, 0x68, 0x81, 0x1a, 0x63, 0x00,
|
||||||
|
0x00, 0x39, 0x9c, 0xce, 0x60, 0x88, 0x96, 0x24, 0x48, 0xd6, 0x64, 0x68, 0x81, 0x12, 0x27, 0x00,
|
||||||
|
0x00, 0x11, 0x88, 0xc4, 0x6c, 0x88, 0x93, 0xc3, 0x88, 0xd3, 0xb4, 0x6e, 0x98, 0xf2, 0x3f, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x22, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x00
|
||||||
|
};
|
||||||
|
|
||||||
|
void app_main(void)
|
||||||
|
{
|
||||||
|
SSD1306_t dev;
|
||||||
|
|
||||||
|
#if CONFIG_I2C_INTERFACE
|
||||||
|
ESP_LOGI(TAG, "INTERFACE is i2c");
|
||||||
|
ESP_LOGI(TAG, "CONFIG_SDA_GPIO=%d",CONFIG_SDA_GPIO);
|
||||||
|
ESP_LOGI(TAG, "CONFIG_SCL_GPIO=%d",CONFIG_SCL_GPIO);
|
||||||
|
ESP_LOGI(TAG, "CONFIG_RESET_GPIO=%d",CONFIG_RESET_GPIO);
|
||||||
|
i2c_master_init(&dev, CONFIG_SDA_GPIO, CONFIG_SCL_GPIO, CONFIG_RESET_GPIO);
|
||||||
|
#endif // CONFIG_I2C_INTERFACE
|
||||||
|
|
||||||
|
#if CONFIG_SPI_INTERFACE
|
||||||
|
ESP_LOGI(TAG, "INTERFACE is SPI");
|
||||||
|
ESP_LOGI(TAG, "CONFIG_MOSI_GPIO=%d",CONFIG_MOSI_GPIO);
|
||||||
|
ESP_LOGI(TAG, "CONFIG_SCLK_GPIO=%d",CONFIG_SCLK_GPIO);
|
||||||
|
ESP_LOGI(TAG, "CONFIG_CS_GPIO=%d",CONFIG_CS_GPIO);
|
||||||
|
ESP_LOGI(TAG, "CONFIG_DC_GPIO=%d",CONFIG_DC_GPIO);
|
||||||
|
ESP_LOGI(TAG, "CONFIG_RESET_GPIO=%d",CONFIG_RESET_GPIO);
|
||||||
|
spi_master_init(&dev, CONFIG_MOSI_GPIO, CONFIG_SCLK_GPIO, CONFIG_CS_GPIO, CONFIG_DC_GPIO, CONFIG_RESET_GPIO);
|
||||||
|
#endif // CONFIG_SPI_INTERFACE
|
||||||
|
|
||||||
|
#if CONFIG_FLIP
|
||||||
|
dev._flip = true;
|
||||||
|
ESP_LOGW(TAG, "Flip upside down");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if CONFIG_SSD1306_128x64
|
||||||
|
ESP_LOGI(TAG, "Panel is 128x64");
|
||||||
|
ssd1306_init(&dev, 128, 64);
|
||||||
|
#endif // CONFIG_SSD1306_128x64
|
||||||
|
#if CONFIG_SSD1306_128x32
|
||||||
|
ESP_LOGI(TAG, "Panel is 128x32");
|
||||||
|
ssd1306_init(&dev, 128, 32);
|
||||||
|
#endif // CONFIG_SSD1306_128x32
|
||||||
|
|
||||||
|
ssd1306_contrast(&dev, 0xff);
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
// for test code
|
||||||
|
int srcBits = 7;
|
||||||
|
int dstBits = 0;
|
||||||
|
for (int i=0;i<8;i++) {
|
||||||
|
uint8_t dst = 0;
|
||||||
|
dst = ssd1306_copy_bit(0xf0, srcBits, dst, dstBits);
|
||||||
|
ESP_LOGI(TAG, "dst=%02x", dst);
|
||||||
|
srcBits--;
|
||||||
|
dstBits++;
|
||||||
|
}
|
||||||
|
srcBits = 7;
|
||||||
|
dstBits = 0;
|
||||||
|
for (int i=0;i<8;i++) {
|
||||||
|
uint8_t dst = 0;
|
||||||
|
dst = ssd1306_copy_bit(0x0f, srcBits, dst, dstBits);
|
||||||
|
ESP_LOGI(TAG, "dst=%02x", dst);
|
||||||
|
srcBits--;
|
||||||
|
dstBits++;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
while(1) {
|
||||||
|
ssd1306_clear_screen(&dev, false);
|
||||||
|
#if CONFIG_SSD1306_128x64
|
||||||
|
ssd1306_display_text(&dev, 0, "SSD1306 128x64", 14, false);
|
||||||
|
#endif // CONFIG_SSD1306_128x64
|
||||||
|
|
||||||
|
#if CONFIG_SSD1306_128x32
|
||||||
|
ssd1306_display_text(&dev, 0, "SSD1306 128x32", 14, false);
|
||||||
|
#endif // CONFIG_SSD1306_128x32
|
||||||
|
ssd1306_display_text(&dev, 1, "BATMAN", 6, false);
|
||||||
|
|
||||||
|
int bitmapWidth = 4*8;
|
||||||
|
int width = ssd1306_get_width(&dev);
|
||||||
|
int xpos = width / 2; // center of width
|
||||||
|
xpos = xpos - bitmapWidth/2;
|
||||||
|
int ypos = 16;
|
||||||
|
ESP_LOGD(TAG, "width=%d xpos=%d", width, xpos);
|
||||||
|
ssd1306_bitmaps(&dev, xpos, ypos, batman, 4, 12);
|
||||||
|
vTaskDelay(3000 / portTICK_PERIOD_MS);
|
||||||
|
|
||||||
|
for(int i=0;i<128;i++) {
|
||||||
|
ssd1306_rotate(&dev, SCROLL_RIGHT, 2, 3, 0);
|
||||||
|
}
|
||||||
|
vTaskDelay(2000 / portTICK_PERIOD_MS);
|
||||||
|
|
||||||
|
#if CONFIG_SSD1306_128x64
|
||||||
|
ssd1306_clear_screen(&dev, false);
|
||||||
|
ssd1306_bitmaps(&dev, 0, 0, logoMischianti, 16, 64);
|
||||||
|
vTaskDelay(2000 / portTICK_PERIOD_MS);
|
||||||
|
|
||||||
|
for(int i=0;i<64;i++) {
|
||||||
|
ssd1306_rotate(&dev, SCROLL_UP, 0, 127, 0);
|
||||||
|
}
|
||||||
|
vTaskDelay(2000 / portTICK_PERIOD_MS);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user