add some code

This commit is contained in:
2025-09-05 13:25:11 +08:00
parent 9ff0a99e7a
commit 3cf1229a85
8911 changed files with 2535396 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
# The following five 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.16)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(sh1106_lcd_example)

View File

@@ -0,0 +1,3 @@
# Example code
Example code for creating a SH1106 lcd screen object in ESP-IDF.

View File

@@ -0,0 +1,4 @@
idf_component_register(
SRCS "sh1106_lcd_example.c"
INCLUDE_DIRS "."
)

View File

@@ -0,0 +1,4 @@
dependencies:
pedrominatel/shtc3:
version: "*"
override_path: '../../../'

View File

@@ -0,0 +1,101 @@
/*
* SH1106 ESP-IDF Driver by TNY Robotics
*
* SPDX-FileCopyrightText: 2025 TNY Robotics
* SPDX-License-Identifier: MIT
*
*
* Copyright (C) 2025 TNY Robotics
*
* This file is part of the SH1106 ESP-IDF driver.
*
* License: MIT
* Repository: https://github.com/tny-robotics/sh1106-esp-idf
*
* Author: TNY Robotics
* Date: 13/02/2025
* Version: 1.0
*/
#include "freertos/FreeRTOS.h"
#include "esp_lcd_io_i2c.h"
#include "esp_lcd_panel_sh1106.h"
#include "esp_lcd_panel_io.h"
#include "esp_lcd_panel_ops.h"
#define I2C_SDA_GPIO GPIO_NUM_21
#define I2C_SCL_GPIO GPIO_NUM_22
#define I2C_HOST I2C_NUM_0
#ifdef __cplusplus
extern "C"
#endif
void app_main(void)
{
/* I2C CONFIGURATION */
// i2c bus configuration
i2c_master_bus_config_t bus_config = {
.i2c_port = I2C_HOST, // I2C port number
.sda_io_num = I2C_SDA_GPIO, // GPIO number for I2C sda signal
.scl_io_num = I2C_SCL_GPIO, // GPIO number for I2C scl signal
.clk_source = I2C_CLK_SRC_DEFAULT, // I2C clock source, just use the default
.glitch_ignore_cnt = 7, // glitch filter, again, just use the default
.intr_priority = 0, // interrupt priority, default to 0
.trans_queue_depth = 0, // transaction queue depth, default to 0
.flags = {
.enable_internal_pullup = true, // enable internal pullup resistors (oled screen does not have one)
.allow_pd = false, // just using the default value
},
};
// Create the i2c bus handle
i2c_master_bus_handle_t i2c_bus_handle = NULL;
ESP_ERROR_CHECK(i2c_new_master_bus(&bus_config, &i2c_bus_handle));
// Create the i2c io handle
esp_lcd_panel_io_handle_t io_handle = NULL;
esp_lcd_panel_io_i2c_config_t io_config = ESP_SH1106_DEFAULT_IO_CONFIG;
ESP_ERROR_CHECK(esp_lcd_new_panel_io_i2c(*i2c_bus_handle, &io_config, &io_handle));
/* SCREEN CONFIGURATION */
// sh1106 panel configuration (most of the values are not used, but must be set to avoid cpp warnings)
esp_lcd_panel_dev_config_t panel_config = {
.reset_gpio_num = -1, // sh1106 does not have a reset pin, so set to -1
.rgb_ele_order = LCD_RGB_ELEMENT_ORDER_RGB, // not even used, but must be set to avoid cpp warnings
.data_endian = LCD_RGB_DATA_ENDIAN_LITTLE, // not even used, but must be set to avoid cpp warnings
.bits_per_pixel = SH1106_PIXELS_PER_BYTE / 8, // bpp = 1 (monochrome, that's important)
.flags = {
.reset_active_high = false, // not even used, but must be set to avoid cpp warnings
},
.vendor_config = NULL, // no need for custom vendor config, not implemented
};
// Create the panel handle from the sh1106 driver
esp_lcd_panel_handle_t panel_handle = NULL;
ESP_ERROR_CHECK(esp_lcd_new_panel_sh1106(io_handle, &panel_config, &panel_handle));
// Reset the screen (no reset pin, so it's a no-op here, optional)
ESP_ERROR_CHECK(esp_lcd_panel_reset(panel_handle));
// Initialize the screen (this one isn't optional at all!)
ESP_ERROR_CHECK(esp_lcd_panel_init(panel_handle));
// Turn on the screen (Easier to see something, right?)
ESP_ERROR_CHECK(esp_lcd_panel_disp_on_off(panel_handle, true));
/* SCREEN PIXEL TEST */
// Create a buffer to hold the screen data
uint8_t buffer_data[SH1106_SCREEN_SIZE];
memset(buffer_data, 0, SH1106_SCREEN_SIZE);
// Just turn on the first top-left pixel
// NOTE : Refer to driver README.md file for more information about the screen buffer format
buffer_data[0] = 0b10000000;
// Send the buffer to the screen
ESP_ERROR_CHECK(esp_lcd_panel_draw_bitmap(panel_handle, 0, 0, SH1106_WIDTH, SH1106_HEIGHT, buffer_data));
}