Compare commits
28 Commits
Author | SHA1 | Date | |
---|---|---|---|
25b4564a8b | |||
e2bb406139 | |||
96b6a8bec9 | |||
509b57fedb | |||
75b51f0c7c | |||
74404b1a44 | |||
9140ba5fb4 | |||
c9ec16d70c | |||
5c61fbd378 | |||
8636de8f2f | |||
6493988324 | |||
64d817e362 | |||
b3d830cdeb | |||
670a523a16 | |||
cc5bffd1e7 | |||
03784ac097 | |||
9e912048ab | |||
0743fc4a5e | |||
046dfbb6e6 | |||
ef7a027cf0 | |||
2dd099f26e | |||
8aaed133e8 | |||
58a83590ca | |||
dd5335815c | |||
e9d5ef46d1 | |||
356d8ccd9a | |||
4063921340 | |||
043fa2fabb |
4
esp/cpp/06_i2c-scanner/.gitignore
vendored
Normal file
4
esp/cpp/06_i2c-scanner/.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
build
|
||||
managed_components
|
||||
dependencies.lock
|
||||
sdkconfig.old
|
17
esp/cpp/06_i2c-scanner/CMakeLists.txt
Normal file
17
esp/cpp/06_i2c-scanner/CMakeLists.txt
Normal file
@ -0,0 +1,17 @@
|
||||
# For more information about build system see
|
||||
# https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/build-system.html
|
||||
# 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.26)
|
||||
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
|
||||
project(
|
||||
#[[NAME]] i2c-scanner
|
||||
VERSION 0.1
|
||||
DESCRIPTION "Simple I2C device scanner"
|
||||
LANGUAGES CXX
|
||||
)
|
||||
# For writing pure cmake components, see the documentation
|
||||
# https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-guides/build-system.html#writing-pure-cmake-components
|
||||
idf_build_set_property(COMPILE_OPTIONS "-Wno-error" APPEND)
|
32
esp/cpp/06_i2c-scanner/README.md
Normal file
32
esp/cpp/06_i2c-scanner/README.md
Normal file
@ -0,0 +1,32 @@
|
||||
# 06_i2c-scanner
|
||||
|
||||

|
||||
|
||||
Simple I2C device scanner.
|
||||
|
||||
For this example I used this [SSD1306 OLED display](https://www.digikey.com/en/products/detail/winstar-display/WEA012864DWPP3N00003/20533255).
|
||||
|
||||
To build the example run the following commands.
|
||||
|
||||
```bash
|
||||
source ~/path/to/esp-idf/export.sh
|
||||
|
||||
mkdir build
|
||||
cd build
|
||||
cmake ..
|
||||
make -j $(nproc)
|
||||
|
||||
# Flash to ESP32
|
||||
make flash
|
||||
|
||||
# Open Serial Monitor, press CTRL+] to exit.
|
||||
make monitor
|
||||
```
|
||||
|
||||
Expected output in serial monitor at 115200 baud
|
||||
|
||||
```bash
|
||||
Scanning I2C devices...
|
||||
[0x3c]: Device found with clock rate 100000 and timeout 50
|
||||
Done.
|
||||
```
|
4
esp/cpp/06_i2c-scanner/main/CMakeLists.txt
Normal file
4
esp/cpp/06_i2c-scanner/main/CMakeLists.txt
Normal file
@ -0,0 +1,4 @@
|
||||
idf_component_register(
|
||||
SRCS "main.cpp"
|
||||
INCLUDE_DIRS "."
|
||||
)
|
17
esp/cpp/06_i2c-scanner/main/idf_component.yml
Normal file
17
esp/cpp/06_i2c-scanner/main/idf_component.yml
Normal file
@ -0,0 +1,17 @@
|
||||
## IDF Component Manager Manifest File
|
||||
dependencies:
|
||||
## Required IDF version
|
||||
idf:
|
||||
version: '>=4.1.0'
|
||||
# # Put list of dependencies here
|
||||
# # For components maintained by Espressif:
|
||||
# component: "~1.0.0"
|
||||
# # For 3rd party components:
|
||||
# username/component: ">=1.0.0,<2.0.0"
|
||||
# username2/component2:
|
||||
# version: "~1.0.0"
|
||||
# # For transient dependencies `public` flag can be set.
|
||||
# # `public` flag doesn't have an effect dependencies of the `main` component.
|
||||
# # All dependencies of `main` are public by default.
|
||||
# public: true
|
||||
espressif/arduino-esp32: ^3.1.1
|
35
esp/cpp/06_i2c-scanner/main/main.cpp
Normal file
35
esp/cpp/06_i2c-scanner/main/main.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
#include "Arduino.h"
|
||||
#include "Wire.h"
|
||||
|
||||
[[maybe_unused]] static const char *TAG = "i2c-scanner";
|
||||
|
||||
void i2c_scan()
|
||||
{
|
||||
uint8_t device_num = 0;
|
||||
Serial.println("Scanning I2C devices...");
|
||||
for (byte address = 1; address < 127; address++) {
|
||||
Wire.beginTransmission(address);
|
||||
byte error = Wire.endTransmission();
|
||||
if (error == 0) {
|
||||
Serial.printf(
|
||||
"[0x%.2x]: Device found with clock rate %lu and timeout %u\n",
|
||||
address,
|
||||
Wire.getClock(), Wire.getTimeOut());
|
||||
device_num++;
|
||||
} else if (error == 4) {
|
||||
Serial.printf("[0x%.2x]: Unknown error.\n", address);
|
||||
}
|
||||
}
|
||||
Serial.println(device_num > 0 ? "Done.\n" : "No I2C devices found.\n");
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Wire.begin();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
i2c_scan();
|
||||
}
|
BIN
esp/cpp/06_i2c-scanner/schematic.png
Normal file
BIN
esp/cpp/06_i2c-scanner/schematic.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 227 KiB |
2405
esp/cpp/06_i2c-scanner/sdkconfig
Normal file
2405
esp/cpp/06_i2c-scanner/sdkconfig
Normal file
File diff suppressed because it is too large
Load Diff
4
esp/cpp/07_lcd-panel-i2c/.gitignore
vendored
Normal file
4
esp/cpp/07_lcd-panel-i2c/.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
build
|
||||
managed_components
|
||||
dependencies.lock
|
||||
sdkconfig.old
|
17
esp/cpp/07_lcd-panel-i2c/CMakeLists.txt
Normal file
17
esp/cpp/07_lcd-panel-i2c/CMakeLists.txt
Normal file
@ -0,0 +1,17 @@
|
||||
# For more information about build system see
|
||||
# https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/build-system.html
|
||||
# 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.26)
|
||||
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
|
||||
project(
|
||||
#[[NAME]] lcd-panel-i2c
|
||||
VERSION 0.1
|
||||
DESCRIPTION "Using the SSD1306 LCD display with ESP-IDF and LVGL over I2C"
|
||||
LANGUAGES CXX
|
||||
)
|
||||
# For writing pure cmake components, see the documentation
|
||||
# https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-guides/build-system.html#writing-pure-cmake-components
|
||||
idf_build_set_property(COMPILE_OPTIONS "-Wno-error" APPEND)
|
29
esp/cpp/07_lcd-panel-i2c/README.md
Normal file
29
esp/cpp/07_lcd-panel-i2c/README.md
Normal file
@ -0,0 +1,29 @@
|
||||
# 07_lcd-panel-i2c
|
||||
|
||||
Using the ESP IDF for drawing to a LCD screen over I2C.
|
||||
|
||||
For instructions on setting up the ESP-IDF see [04_-esp-idf-arduino](./../04_esp-idf-arduino)
|
||||
|
||||
[ESP IDF - I2C](https://docs.espressif.com/projects/esp-idf/en/v5.3.2/esp32/api-reference/peripherals/i2c.html)
|
||||
|
||||
[ESP IDF - LCD](https://docs.espressif.com/projects/esp-idf/en/v5.3.2/esp32/api-reference/peripherals/lcd/index.html)
|
||||
|
||||
[ESP IDF - FreeRTOS](https://docs.espressif.com/projects/esp-idf/en/v5.3.2/esp32/api-reference/system/freertos.html)
|
||||
|
||||

|
||||
|
||||
Temperature and humidity sensor served on a web page within the local network.
|
||||
|
||||

|
||||
|
||||
To build this example run the following commands.
|
||||
|
||||
```bash
|
||||
source ~/path/to/esp-idf/export.sh
|
||||
|
||||
mkdir build
|
||||
cd build
|
||||
cmake ..
|
||||
make -j $(nproc)
|
||||
make flash
|
||||
```
|
BIN
esp/cpp/07_lcd-panel-i2c/example.gif
Normal file
BIN
esp/cpp/07_lcd-panel-i2c/example.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 887 KiB |
5
esp/cpp/07_lcd-panel-i2c/main/CMakeLists.txt
Normal file
5
esp/cpp/07_lcd-panel-i2c/main/CMakeLists.txt
Normal file
@ -0,0 +1,5 @@
|
||||
idf_component_register(
|
||||
SRCS main.cpp display.cpp ssd1306.cpp i2c.h time_keeper.h panel.h panel_device.h
|
||||
INCLUDE_DIRS .
|
||||
REQUIRES driver
|
||||
)
|
177
esp/cpp/07_lcd-panel-i2c/main/display.cpp
Normal file
177
esp/cpp/07_lcd-panel-i2c/main/display.cpp
Normal file
@ -0,0 +1,177 @@
|
||||
|
||||
#include <esp_timer.h>
|
||||
|
||||
#include <lv_init.h>
|
||||
|
||||
#include <mutex>
|
||||
|
||||
#include "display.h"
|
||||
|
||||
// TODO: Remove this dependency by relocating SSD1306::oledb_buffer_
|
||||
#include "ssd1306.h"
|
||||
|
||||
// LVGL library is not thread-safe, this example calls LVGL APIs from tasks.
|
||||
// We must use a mutex to protect it.
|
||||
_lock_t Display::ScopedLock::lv_lock_;
|
||||
|
||||
// Static TimeKeeper for managing ESP timers across all displays.
|
||||
TimeKeeper Display::timers_;
|
||||
|
||||
/// Tag used for ESP logging.
|
||||
const char * TAG = "Display";
|
||||
|
||||
Display::Display(IPanelDevice &device) :
|
||||
panel_(device),
|
||||
lv_buf_(nullptr)
|
||||
{
|
||||
if (!lv_is_initialized()) {
|
||||
ESP_LOGI(TAG, "Initialize LVGL");
|
||||
lv_init();
|
||||
}
|
||||
|
||||
ESP_LOGI(TAG, "Creating LVGL display");
|
||||
lv_display_ = panel_.device_->create_display();
|
||||
// associate the i2c panel handle to the display
|
||||
lv_display_set_user_data(lv_display_, panel_.esp_panel_);
|
||||
|
||||
register_draw_buffer();
|
||||
register_lvgl_tick_timer();
|
||||
|
||||
ESP_LOGI(TAG, "Create LVGL FreeRTOS task");
|
||||
xTaskCreate(Display::lvgl_port_task, "LVGL", LVGL_TASK_STACK_SIZE,
|
||||
nullptr, LVGL_TASK_PRIORITY, nullptr);
|
||||
}
|
||||
|
||||
void Display::set_text(const char *text,
|
||||
const char *name,
|
||||
lv_label_long_mode_t long_mode,
|
||||
lv_align_t align)
|
||||
{
|
||||
// Lock the mutex due to the LVGL APIs are not thread-safe.
|
||||
ScopedLock lock;
|
||||
|
||||
ESP_LOGI(TAG, "Display LVGL Scroll Text");
|
||||
lv_obj_t *scr = lv_display_get_screen_active(lv_display_);
|
||||
|
||||
// Create the label if it's `name` doesn't already exist in the map keys.
|
||||
if (!lv_objects_.count(name)) {
|
||||
lv_objects_[name] = lv_label_create(scr);
|
||||
}
|
||||
auto obj = lv_objects_[name];
|
||||
|
||||
// Circular scroll.
|
||||
lv_label_set_long_mode(obj, long_mode);
|
||||
lv_label_set_text(obj, text);
|
||||
|
||||
// Set the size of the screen.
|
||||
// If you use rotation 90 or 270 use lv_display_get_vertical_resolution.
|
||||
lv_obj_set_width(obj, lv_display_get_horizontal_resolution(lv_display_));
|
||||
lv_obj_align(obj, align, 0, 0);
|
||||
}
|
||||
|
||||
bool Display::lvgl_flush_ready_cb(esp_lcd_panel_io_handle_t,
|
||||
esp_lcd_panel_io_event_data_t *,
|
||||
void *user_ctx)
|
||||
{
|
||||
auto *disp = (lv_display_t *) user_ctx;
|
||||
lv_display_flush_ready(disp);
|
||||
return false;
|
||||
}
|
||||
|
||||
void Display::lvgl_flush_cb(lv_display_t *display, const lv_area_t *area,
|
||||
uint8_t *px_map) // NOLINT(*-non-const-parameter)
|
||||
{
|
||||
auto panel_handle =
|
||||
(esp_lcd_panel_handle_t) lv_display_get_user_data(display);
|
||||
|
||||
// Necessary because LVGL reserves 2x4 bytes in the buffer for a palette.
|
||||
// For more information about the monochrome, please refer to:
|
||||
// https://docs.lvgl.io/9.2/porting/display.html#monochrome-displays
|
||||
// Skip the palette here.
|
||||
px_map += LVGL_PALETTE_SIZE;
|
||||
|
||||
uint16_t hor_res = lv_display_get_physical_horizontal_resolution(display);
|
||||
int32_t x1 = area->x1;
|
||||
int32_t x2 = area->x2;
|
||||
int32_t y1 = area->y1;
|
||||
int32_t y2 = area->y2;
|
||||
|
||||
for (int32_t y = y1; y <= y2; y++) {
|
||||
for (int32_t x = x1; x <= x2; x++) {
|
||||
/* The order of bits is MSB first.
|
||||
MSB LSB
|
||||
bits 7 6 5 4 3 2 1 0
|
||||
pixels 0 1 2 3 4 5 6 7
|
||||
Left Right
|
||||
*/
|
||||
bool chroma_color = (px_map[(hor_res >> 3) * y + (x >> 3)] &
|
||||
1 << (7 - x % 8));
|
||||
|
||||
// Write to the buffer as required for the display.
|
||||
// It writes only 1-bit for monochrome displays mapped vertically.
|
||||
uint8_t *buf = SSD1306::oled_buffer_ + hor_res * (y >> 3) + (x);
|
||||
if (chroma_color) {
|
||||
(*buf) &= ~(1 << (y % 8));
|
||||
} else {
|
||||
(*buf) |= (1 << (y % 8));
|
||||
}
|
||||
}
|
||||
}
|
||||
// Pass the draw buffer to the driver.
|
||||
ESP_ERROR_CHECK(
|
||||
esp_lcd_panel_draw_bitmap(panel_handle, x1, y1, x2 + 1, y2 + 1,
|
||||
SSD1306::oled_buffer_));
|
||||
}
|
||||
|
||||
void Display::lvgl_increase_tick_cb(void *)
|
||||
{
|
||||
// Tell LVGL how many milliseconds has elapsed
|
||||
lv_tick_inc(LVGL_TICK_PERIOD_MS);
|
||||
}
|
||||
|
||||
[[noreturn]] void Display::lvgl_port_task(void *)
|
||||
{
|
||||
ESP_LOGI(TAG, "Starting LVGL task");
|
||||
for (uint32_t time_to_next_ms = 0; true; usleep(1000 * time_to_next_ms)) {
|
||||
ScopedLock lock;
|
||||
time_to_next_ms = lv_timer_handler();
|
||||
}
|
||||
}
|
||||
|
||||
void Display::register_draw_buffer()
|
||||
{
|
||||
// Create draw buffer.
|
||||
ESP_LOGI(TAG, "Allocate separate LVGL draw buffers");
|
||||
lv_buf_ = heap_caps_calloc(1, panel_.device_->lv_buf_size_,
|
||||
MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
|
||||
assert(lv_buf_);
|
||||
|
||||
ESP_LOGI(TAG, "Set LVGL draw buffers");
|
||||
// Color format must be set first, LVGL9 suooprt new monochromatic format.
|
||||
lv_display_set_color_format(lv_display_, LV_COLOR_FORMAT_I1);
|
||||
lv_display_set_buffers(lv_display_, lv_buf_, nullptr,
|
||||
panel_.device_->lv_buf_size_,
|
||||
LV_DISPLAY_RENDER_MODE_FULL);
|
||||
lv_display_set_rotation(lv_display_, LV_DISPLAY_ROTATION_0);
|
||||
|
||||
ESP_LOGI(TAG, "Set LVGL callback for flushing to the display");
|
||||
lv_display_set_flush_cb(lv_display_, Display::lvgl_flush_cb);
|
||||
|
||||
ESP_LOGI(TAG, "Register io panel callback for LVGL flush ready notification");
|
||||
const esp_lcd_panel_io_callbacks_t cbs = {
|
||||
.on_color_trans_done = Display::lvgl_flush_ready_cb,
|
||||
};
|
||||
ESP_ERROR_CHECK(
|
||||
esp_lcd_panel_io_register_event_callbacks(panel_.esp_io_, &cbs,
|
||||
lv_display_));
|
||||
}
|
||||
|
||||
void Display::register_lvgl_tick_timer()
|
||||
{
|
||||
ESP_LOGI(TAG, "Use esp_timer to increase LVGL tick");
|
||||
const esp_timer_create_args_t esp_timer_args = {
|
||||
.callback = &Display::lvgl_increase_tick_cb,
|
||||
.name = "lvgl_tick"
|
||||
};
|
||||
timers_.start_new_timer_periodic(esp_timer_args, LVGL_TICK_PERIOD_MS * 1000);
|
||||
}
|
143
esp/cpp/07_lcd-panel-i2c/main/display.h
Normal file
143
esp/cpp/07_lcd-panel-i2c/main/display.h
Normal file
@ -0,0 +1,143 @@
|
||||
#ifndef DISPLAY_H
|
||||
#define DISPLAY_H
|
||||
|
||||
|
||||
#include <widgets/label/lv_label.h>
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
#include "time_keeper.h"
|
||||
#include "panel.h"
|
||||
|
||||
#define LVGL_TICK_PERIOD_MS 5
|
||||
#define LVGL_TASK_STACK_SIZE (4 * 1024)
|
||||
#define LVGL_TASK_PRIORITY 2
|
||||
|
||||
/**
|
||||
* Encapsulates lv_display handle and related LVGL operations.
|
||||
* Contains helper methods that wrap basic LVGL operations such as drawing text.
|
||||
* The underlying lv_display can be obtained for manual LVGL operations.
|
||||
* @sa ScopedLock
|
||||
* @sa Display::get()
|
||||
*/
|
||||
class Display {
|
||||
public:
|
||||
/**
|
||||
* Construct a new Display using an object that implements IPanelDevice.
|
||||
*
|
||||
* @param device An object that implements the IPanelDevice interface.
|
||||
*/
|
||||
explicit Display(IPanelDevice &device);
|
||||
|
||||
~Display() = default;
|
||||
|
||||
Display(const Display &) = delete;
|
||||
|
||||
Display(Display &) = delete;
|
||||
|
||||
Display &operator=(Display &) = delete;
|
||||
|
||||
//
|
||||
// GETTERS
|
||||
|
||||
/**
|
||||
* Getter for accessing LVGL display handle.
|
||||
*
|
||||
* @sa ScopedLock for calling custom LVGL API's not implemented by Display.
|
||||
*/
|
||||
[[nodiscard]] inline const lv_display_t *get() const { return lv_display_; }
|
||||
|
||||
/**
|
||||
* Getter for accessing LVGL display handle.
|
||||
*
|
||||
* @sa ScopedLock for calling custom LVGL API's not implemented by Display.
|
||||
*/
|
||||
[[nodiscard]] inline lv_display_t *get() { return lv_display_; }
|
||||
|
||||
/// Dereference operator for accessing LVGL display handle.
|
||||
[[nodiscard]] inline const lv_display_t *operator*() const { return get(); }
|
||||
|
||||
/// Dereference operator for accessing LVGL display handle.
|
||||
[[nodiscard]] inline lv_display_t *operator*() { return get(); }
|
||||
|
||||
//
|
||||
// LVGL OPERATIONS
|
||||
|
||||
/**
|
||||
* Create a LVGL label with some given text on the current display.
|
||||
* The name of the object can be reused to change text on this label later.
|
||||
*
|
||||
* @param text Text to write to the display.
|
||||
* @param name Name for the LVGL label object associated with this text.
|
||||
* @param long_mode LVGL long mode for text wider than the current display.
|
||||
* @param align LVGL alignment to use for placing the label on the display.
|
||||
*/
|
||||
void set_text(const char *text,
|
||||
const char *name,
|
||||
lv_label_long_mode_t long_mode = LV_LABEL_LONG_SCROLL_CIRCULAR,
|
||||
lv_align_t align = LV_ALIGN_TOP_MID);
|
||||
|
||||
//
|
||||
// TYPE DEFINITIONS
|
||||
|
||||
/**
|
||||
* Obtains LVGL API mutex lock for the duration of local scope.
|
||||
*
|
||||
* LVGL library is not thread-safe, this example calls LVGL APIs from tasks.
|
||||
*/
|
||||
struct ScopedLock {
|
||||
explicit ScopedLock() { _lock_acquire(&lv_lock_); }
|
||||
|
||||
~ScopedLock() { _lock_release(&lv_lock_); }
|
||||
|
||||
/// Mutex used to protect LVGL API calls.
|
||||
static _lock_t lv_lock_;
|
||||
};
|
||||
|
||||
//
|
||||
// PUBLIC STATIC MEMBERS
|
||||
|
||||
/// Public static TimeKeeper for managing ESP timers across all displays.
|
||||
static TimeKeeper timers_;
|
||||
|
||||
private:
|
||||
/// Registers LVGL draw buffers for this display.
|
||||
void register_draw_buffer();
|
||||
|
||||
/// Registers LVGL ticker timer callback for rendering this display.
|
||||
static void register_lvgl_tick_timer();
|
||||
|
||||
static bool lvgl_flush_ready_cb(esp_lcd_panel_io_handle_t panel,
|
||||
esp_lcd_panel_io_event_data_t *data,
|
||||
void *user_ctx);
|
||||
|
||||
static void lvgl_flush_cb(lv_display_t *display,
|
||||
const lv_area_t *area,
|
||||
uint8_t *px_map);
|
||||
|
||||
static void lvgl_increase_tick_cb(void *arg);
|
||||
|
||||
[[noreturn]] static void lvgl_port_task(void *arg);
|
||||
|
||||
//
|
||||
// PRIVATE MEMBERS
|
||||
|
||||
/// Panel associated with this Display.
|
||||
Panel panel_;
|
||||
|
||||
/// LVGL display handle.
|
||||
lv_display_t *lv_display_;
|
||||
|
||||
/// LVGL draw buffer associated with this Display's lv_display_t.
|
||||
void *lv_buf_;
|
||||
|
||||
/**
|
||||
* LVGL object handles stored in the LVGL screen associated with this Display.
|
||||
*
|
||||
* @sa Display::set_text
|
||||
* @sa lv_display_get_screen_active
|
||||
*/
|
||||
std::unordered_map<const char *, lv_obj_t *> lv_objects_;
|
||||
};
|
||||
|
||||
#endif // DISPLAY_H
|
74
esp/cpp/07_lcd-panel-i2c/main/i2c.h
Normal file
74
esp/cpp/07_lcd-panel-i2c/main/i2c.h
Normal file
@ -0,0 +1,74 @@
|
||||
#ifndef I2C_H
|
||||
#define I2C_H
|
||||
|
||||
#define I2C_BUS_PORT 0
|
||||
|
||||
#include <driver/i2c_master.h>
|
||||
|
||||
/**
|
||||
* Encapsulates ESP I2C creation and usage.
|
||||
*/
|
||||
struct I2C {
|
||||
/**
|
||||
* Construct and initialize an ESP I2C master bus.
|
||||
* An I2C constructor may only be called one time in any application.
|
||||
*
|
||||
* @param sda GPIO pin number for SDA
|
||||
* @param scl GPIO pin number for SCL
|
||||
* @param rst GPIO pin number for RST
|
||||
*/
|
||||
I2C(gpio_num_t sda, gpio_num_t scl, int rst = -1) :
|
||||
I2C((i2c_master_bus_config_t) {
|
||||
.i2c_port = I2C_BUS_PORT,
|
||||
.sda_io_num = sda,
|
||||
.scl_io_num = scl,
|
||||
.clk_source = I2C_CLK_SRC_DEFAULT,
|
||||
.glitch_ignore_cnt = 7,
|
||||
.flags {
|
||||
.enable_internal_pullup = true,
|
||||
},
|
||||
},
|
||||
rst
|
||||
) { }
|
||||
|
||||
/**
|
||||
* Construct an ESP I2C master bus given a specific ESP I2C configuration.
|
||||
* An I2C constructor may only be called one time in any application.
|
||||
*
|
||||
* @param config ESP I2C master bus configuration.
|
||||
* @param rst GPIO pin number for RST
|
||||
*/
|
||||
explicit I2C(i2c_master_bus_config_t config, int rst = -1) :
|
||||
esp_bus_config_(config),
|
||||
rst_num_(rst)
|
||||
{
|
||||
i2c_master_bus_handle_t i2c;
|
||||
ESP_LOGI(TAG, "Initializing new master I2C bus");
|
||||
ESP_ERROR_CHECK(i2c_new_master_bus(&esp_bus_config_, &i2c));
|
||||
}
|
||||
|
||||
~I2C() = default;
|
||||
|
||||
/**
|
||||
* ESP I2C master bus handle getter.
|
||||
* This will fail if an I2C instance was never constructed.
|
||||
*/
|
||||
static i2c_master_bus_handle_t get()
|
||||
{
|
||||
i2c_master_bus_handle_t i2c = nullptr;
|
||||
ESP_ERROR_CHECK(i2c_master_get_bus_handle(0, &i2c));
|
||||
return i2c;
|
||||
}
|
||||
|
||||
/// ESP I2C master bus configuration used during initialization.
|
||||
i2c_master_bus_config_t esp_bus_config_;
|
||||
|
||||
/// RST GPIO pin number.
|
||||
int rst_num_;
|
||||
|
||||
private:
|
||||
/// Tag used for ESP logging.
|
||||
const char * TAG = "I2C";
|
||||
};
|
||||
|
||||
#endif //I2C_H
|
5
esp/cpp/07_lcd-panel-i2c/main/idf_component.yml
Normal file
5
esp/cpp/07_lcd-panel-i2c/main/idf_component.yml
Normal file
@ -0,0 +1,5 @@
|
||||
## IDF Component Manager Manifest File
|
||||
dependencies:
|
||||
espressif/arduino-esp32: ^3.1.1
|
||||
lvgl/lvgl: "9.2.0"
|
||||
esp_lcd_sh1107: "^1"
|
34
esp/cpp/07_lcd-panel-i2c/main/main.cpp
Normal file
34
esp/cpp/07_lcd-panel-i2c/main/main.cpp
Normal file
@ -0,0 +1,34 @@
|
||||
#include "display.h"
|
||||
#include "ssd1306.h"
|
||||
|
||||
// Pin may vary based on your schematic.
|
||||
#define PIN_SDA GPIO_NUM_21
|
||||
#define PIN_SCL GPIO_NUM_22
|
||||
#define PIN_RST (-1)
|
||||
|
||||
I2C i2c(PIN_SDA, PIN_SCL, PIN_RST);
|
||||
|
||||
void setup()
|
||||
{
|
||||
SSD1306 ssd1306(i2c);
|
||||
Display d(ssd1306);
|
||||
|
||||
d.set_text("Test test 12345678910",
|
||||
"test-text1",
|
||||
LV_LABEL_LONG_SCROLL,
|
||||
LV_ALIGN_CENTER);
|
||||
|
||||
d.set_text("Test test changing text",
|
||||
"test-text1",
|
||||
LV_LABEL_LONG_SCROLL,
|
||||
LV_ALIGN_CENTER);
|
||||
|
||||
d.set_text("Hello hello hello hello hello hello hello hello!", "test-text2");
|
||||
|
||||
d.set_text("A random sentence with no meaning at all.",
|
||||
"test-text3",
|
||||
LV_LABEL_LONG_CLIP,
|
||||
LV_ALIGN_BOTTOM_MID);
|
||||
}
|
||||
|
||||
void loop() { }
|
62
esp/cpp/07_lcd-panel-i2c/main/panel.h
Normal file
62
esp/cpp/07_lcd-panel-i2c/main/panel.h
Normal file
@ -0,0 +1,62 @@
|
||||
#ifndef PANEL_H
|
||||
#define PANEL_H
|
||||
|
||||
#include "panel_device.h"
|
||||
|
||||
/**
|
||||
* Encapsulates esp_lcd_panel handles and operations.
|
||||
* The only exception is esp_lcd_panel_io_i2c_config_t owned by IPanelDevice.
|
||||
* This structure requires details specific to the implementing device.
|
||||
*
|
||||
* Panel is an implementation detail of Display, not meant to be used directly.
|
||||
*/
|
||||
struct Panel {
|
||||
/**
|
||||
* Construct a new Panel using an object that implements IPanelDevice.
|
||||
*
|
||||
* @param device An object that implements the IPanelDevice interface.
|
||||
*/
|
||||
explicit Panel(IPanelDevice &device) :
|
||||
device_(&device),
|
||||
esp_io_(nullptr),
|
||||
esp_panel_(nullptr),
|
||||
esp_panel_config_(
|
||||
(esp_lcd_panel_dev_config_t) {
|
||||
.reset_gpio_num = device_->rst_num_,
|
||||
.bits_per_pixel = 1,
|
||||
.vendor_config = device_->vendor_config(),
|
||||
}
|
||||
)
|
||||
{
|
||||
esp_io_ = device_->create_io_handle();
|
||||
|
||||
device_->create_panel(esp_panel_config_, esp_io_, esp_panel_);
|
||||
|
||||
ESP_LOGI(TAG, "Resetting panel display");
|
||||
ESP_ERROR_CHECK(esp_lcd_panel_reset(esp_panel_));
|
||||
ESP_LOGI(TAG, "Initializing panel display");
|
||||
ESP_ERROR_CHECK(esp_lcd_panel_init(esp_panel_));
|
||||
ESP_LOGI(TAG, "Turning on panel display");
|
||||
ESP_ERROR_CHECK(esp_lcd_panel_disp_on_off(esp_panel_, true));
|
||||
}
|
||||
|
||||
~Panel() = default;
|
||||
|
||||
/// Pointer to object using known interface for IPanelDevice.
|
||||
IPanelDevice *device_;
|
||||
|
||||
/// ESP LCD panel IO handle.
|
||||
esp_lcd_panel_io_handle_t esp_io_;
|
||||
|
||||
/// ESP LCD panel handle.
|
||||
esp_lcd_panel_handle_t esp_panel_;
|
||||
|
||||
/// ESP LCD panel configuration structure.
|
||||
esp_lcd_panel_dev_config_t esp_panel_config_;
|
||||
|
||||
private:
|
||||
/// Tag used for ESP logging.
|
||||
const char * TAG = "Panel";
|
||||
};
|
||||
|
||||
#endif //PANEL_H
|
154
esp/cpp/07_lcd-panel-i2c/main/panel_device.h
Normal file
154
esp/cpp/07_lcd-panel-i2c/main/panel_device.h
Normal file
@ -0,0 +1,154 @@
|
||||
#ifndef PANEL_DEVICE_H
|
||||
#define PANEL_DEVICE_H
|
||||
|
||||
#include <esp_lcd_panel_dev.h>
|
||||
#include <esp_lcd_panel_ops.h>
|
||||
#include <esp_lcd_panel_io.h>
|
||||
#include <esp_log.h>
|
||||
|
||||
#include <display/lv_display.h>
|
||||
|
||||
#include "i2c.h"
|
||||
|
||||
// LVGL reserves 2x4 bytes in the buffer to be used as a palette.
|
||||
// This additional space must be added to the IPanelDevice::buf_size_.
|
||||
#define LVGL_PALETTE_SIZE 8
|
||||
|
||||
/**
|
||||
* Encapsulates vendor specific ESP LCD pabel initialization logic.
|
||||
* This pure virtual interface can be inherited from for using new LCD devices.
|
||||
* See the SSD1306 example for implementing a PanelDevice for NT35510 or ST7789.
|
||||
*
|
||||
* At this time only I2C is supported.
|
||||
* Classes that inherit from this interface should likely be marked final.
|
||||
*/
|
||||
class IPanelDevice {
|
||||
public:
|
||||
/**
|
||||
* Construct an IPanelDevice.
|
||||
*
|
||||
* @param i2c I2C object. Eventually this will mature to IProtocol or similar.
|
||||
* @param config I2C configuration for this device.
|
||||
* @param height Height of the device screen in pixels.
|
||||
* @param width Width of the device screen in pixels.
|
||||
*/
|
||||
explicit IPanelDevice(I2C &i2c,
|
||||
esp_lcd_panel_io_i2c_config_t config,
|
||||
int width,
|
||||
int height) :
|
||||
IPanelDevice(i2c, config, width, height,
|
||||
width * height / 8 + LVGL_PALETTE_SIZE) { }
|
||||
|
||||
/**
|
||||
* Construct an IPanelDevice.
|
||||
*
|
||||
* @param i2c I2C object. Eventually this will mature to IProtocol or similar.
|
||||
* @param config I2C configuration for this device.
|
||||
* @param height Height of the device screen in pixels.
|
||||
* @param width Width of the device screen in pixels.
|
||||
* @param draw_buf_size Size of the draw buffer for this device.
|
||||
*/
|
||||
explicit IPanelDevice(I2C &i2c,
|
||||
esp_lcd_panel_io_i2c_config_t io_config,
|
||||
int width,
|
||||
int height,
|
||||
size_t draw_buf_size) :
|
||||
width_(width),
|
||||
height_(height),
|
||||
rst_num_(i2c.rst_num_),
|
||||
lv_buf_size_(draw_buf_size),
|
||||
esp_io_config_(io_config) { }
|
||||
|
||||
virtual ~IPanelDevice() = default;
|
||||
|
||||
/**
|
||||
* Create an LVGL display using the width and height of this device.
|
||||
*
|
||||
* @return Handle to the created LVGL display.
|
||||
*/
|
||||
[[nodiscard]] lv_display_t *create_display() const
|
||||
{
|
||||
auto display = lv_display_create(width_, height_);
|
||||
assert(display);
|
||||
return display;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an ESP LCD panel IO handle.
|
||||
*
|
||||
* @return The created ESP LCD panel IO handle.
|
||||
*/
|
||||
[[nodiscard]] esp_lcd_panel_io_handle_t create_io_handle()
|
||||
{
|
||||
ESP_LOGI(TAG, "Creating panel IO handle");
|
||||
esp_lcd_panel_io_handle_t handle = nullptr;
|
||||
ESP_ERROR_CHECK(
|
||||
esp_lcd_new_panel_io_i2c(I2C::get(), &esp_io_config_, &handle));
|
||||
return handle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create and initialize an ESP panel handle.
|
||||
* IPanelDevice implementors must initialize the panel within init_panel.
|
||||
*
|
||||
* @param config ESP LCD panel configuration.
|
||||
* @param io ESP LCD panel IO handle.
|
||||
* @param [out] panel ESP LCD panel handle output pointer location.
|
||||
*/
|
||||
void create_panel(esp_lcd_panel_dev_config_t &config,
|
||||
esp_lcd_panel_io_handle_t io,
|
||||
esp_lcd_panel_handle_t &panel)
|
||||
{
|
||||
// If the passed handle is already allocated, delete it.
|
||||
if (panel != nullptr) {
|
||||
ESP_LOGI(TAG, "Removing unused panel");
|
||||
esp_lcd_panel_del(panel);
|
||||
}
|
||||
|
||||
ESP_LOGI(TAG, "Install SSD1306 panel driver");
|
||||
// Call pure virtual method responsible for initializing the panel handle.
|
||||
init_panel(config, io, panel);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the device specific vendor configuration structure.
|
||||
*
|
||||
* @return Address of vendor configuration structure.
|
||||
* @sa SSD1306::vendor_config
|
||||
*/
|
||||
virtual void *vendor_config() = 0;
|
||||
|
||||
/// Width of the device screen in pixels.
|
||||
int32_t width_;
|
||||
|
||||
/// Height of the device screen in pixels.
|
||||
int32_t height_;
|
||||
|
||||
/// RST GPIO pin number.
|
||||
int rst_num_;
|
||||
|
||||
/// LVGL draw buffer size for the device.
|
||||
size_t lv_buf_size_;
|
||||
|
||||
/// ESP LCD panel IO configuration.
|
||||
esp_lcd_panel_io_i2c_config_t esp_io_config_;
|
||||
|
||||
private:
|
||||
/**
|
||||
* Initializes the ESP panel using vendor specific APIs and configurations.
|
||||
* This method should implement any setup logic specific to the device.
|
||||
*
|
||||
* @param config ESP LCD panel configuration.
|
||||
* @param io ESP LCD panel IO handle.
|
||||
* @param [out] panel ESP LCD panel handle output pointer location.
|
||||
*/
|
||||
virtual void init_panel(esp_lcd_panel_dev_config_t &config,
|
||||
esp_lcd_panel_io_handle_t io,
|
||||
esp_lcd_panel_handle_t &panel) = 0;
|
||||
|
||||
/// Tag used for ESP logging.
|
||||
const char * TAG = "IPanelDevice";
|
||||
};
|
||||
|
||||
#endif // PANEL_DEVICE_H
|
6
esp/cpp/07_lcd-panel-i2c/main/ssd1306.cpp
Normal file
6
esp/cpp/07_lcd-panel-i2c/main/ssd1306.cpp
Normal file
@ -0,0 +1,6 @@
|
||||
|
||||
#include "ssd1306.h"
|
||||
|
||||
// To use LV_COLOR_FORMAT_I1 we need an extra buffer to hold the converted data.
|
||||
// TODO: Remove this and SSD1306 can be header only.
|
||||
uint8_t SSD1306::oled_buffer_[LCD_H_RES * LCD_V_RES / 8];
|
110
esp/cpp/07_lcd-panel-i2c/main/ssd1306.h
Normal file
110
esp/cpp/07_lcd-panel-i2c/main/ssd1306.h
Normal file
@ -0,0 +1,110 @@
|
||||
/*
|
||||
* https://docs.espressif.com/projects/esp-idf/en/v5.3.2/esp32/api-reference/peripherals/lcd/index.html#functional-overview
|
||||
*
|
||||
* Implementing the interface draw to an LCD using various interface modes.
|
||||
* I2C interface mode is SSD1306
|
||||
* SPI interface mode is ST7789
|
||||
* I80 interface mode is NT35510 or ST7789
|
||||
*
|
||||
* Actually, I think any driver can be used with any interface mode
|
||||
* Along with additional third party drivers via the component manager
|
||||
* https://github.com/espressif/esp-idf/tree/0d6099ec533c4b647fb7a7b0b8942bc7aeb82f90/examples/peripherals/lcd/spi_lcd_touch#spi-lcd-and-touch-panel-example
|
||||
*/
|
||||
|
||||
#ifndef SSD1306_H
|
||||
#define SSD1306_H
|
||||
|
||||
#include <esp_lcd_panel_ssd1306.h>
|
||||
|
||||
#include "panel_device.h"
|
||||
|
||||
// According to specific display hardware.
|
||||
// https://www.digikey.com/en/products/detail/winstar-display/WEA012864DWPP3N00003/20533255
|
||||
#define SCREEN_WIDTH 128 // OLED display width, in pixels.
|
||||
#define SCREEN_HEIGHT 64 // OLED display height, in pixels.
|
||||
|
||||
// According to SSD1306 datasheet.
|
||||
// https://cdn-shop.adafruit.com/datasheets/SSD1306.pdf
|
||||
#define LCD_H_RES 128
|
||||
#define LCD_V_RES 64
|
||||
#define I2C_HW_ADDR 0x3C
|
||||
#define LCD_PIXEL_CLOCK_HZ (400 * 1000)
|
||||
// Bit number used to represent command and parameter
|
||||
#define LCD_CMD_BITS 8
|
||||
#define LCD_PARAM_BITS 8
|
||||
|
||||
/**
|
||||
* Example of implementing the IPanelDevice interface for SSD1306 LCD device.
|
||||
*/
|
||||
class SSD1306 final : public IPanelDevice {
|
||||
public:
|
||||
/**
|
||||
* Construct a new SSD1306 device.
|
||||
*
|
||||
* @param i2c I2C master bus to manage this device.
|
||||
*/
|
||||
explicit SSD1306(I2C &i2c) :
|
||||
SSD1306(i2c, {.height = SCREEN_HEIGHT}) { }
|
||||
|
||||
/**
|
||||
* Construct a new SSD1306 device given a specific SSD1306 configuration.
|
||||
*
|
||||
* @param i2c I2C master bus to manage this device.
|
||||
* @param config SSD1306 vendor configuration.
|
||||
* @param width Width of the device screen in pixels.
|
||||
* @param height Height of the device screen in pixels.
|
||||
*/
|
||||
SSD1306(I2C &i2c,
|
||||
esp_lcd_panel_ssd1306_config_t config,
|
||||
int width = SCREEN_WIDTH,
|
||||
int height = SCREEN_HEIGHT
|
||||
) :
|
||||
IPanelDevice(i2c,
|
||||
(esp_lcd_panel_io_i2c_config_t) {
|
||||
.dev_addr = I2C_HW_ADDR,
|
||||
.control_phase_bytes = 1,
|
||||
.dc_bit_offset = 6,
|
||||
.lcd_cmd_bits = LCD_CMD_BITS,
|
||||
.lcd_param_bits = LCD_PARAM_BITS,
|
||||
.scl_speed_hz = LCD_PIXEL_CLOCK_HZ,
|
||||
},
|
||||
width,
|
||||
height
|
||||
),
|
||||
ssd1306_config_(config) { }
|
||||
|
||||
~SSD1306() final = default;
|
||||
|
||||
/**
|
||||
* Provides the SSD1306 vendor configuration to IPanelDevice consumers.
|
||||
*
|
||||
* @return Address of the SSD1306 vendor configuration structure.
|
||||
*/
|
||||
void *vendor_config() override
|
||||
{
|
||||
return &ssd1306_config_;
|
||||
}
|
||||
|
||||
/// SSD1306 configuration structure.
|
||||
esp_lcd_panel_ssd1306_config_t ssd1306_config_;
|
||||
|
||||
/**
|
||||
* Draw buffer for this panel device.
|
||||
* For LV_COLOR_FORMAT_I1 we need an extra buffer to hold the converted data.
|
||||
*/
|
||||
static uint8_t oled_buffer_[LCD_H_RES * LCD_V_RES / 8];
|
||||
|
||||
private:
|
||||
/// Initializes the ESP LCD panel handle for the SSD1306 device.
|
||||
void init_panel(esp_lcd_panel_dev_config_t &config,
|
||||
esp_lcd_panel_io_handle_t io,
|
||||
esp_lcd_panel_handle_t &panel) override
|
||||
{
|
||||
ESP_ERROR_CHECK(esp_lcd_new_panel_ssd1306(io, &config, &panel));
|
||||
}
|
||||
|
||||
/// Tag used for ESP logging.
|
||||
const char * TAG = "SSD1306";
|
||||
};
|
||||
|
||||
#endif // SSD1306_H
|
138
esp/cpp/07_lcd-panel-i2c/main/time_keeper.h
Normal file
138
esp/cpp/07_lcd-panel-i2c/main/time_keeper.h
Normal file
@ -0,0 +1,138 @@
|
||||
|
||||
#ifndef TIME_KEEPER_H
|
||||
#define TIME_KEEPER_H
|
||||
|
||||
#include <esp_log.h>
|
||||
#include <esp_timer.h>
|
||||
|
||||
#include "i2c.h"
|
||||
|
||||
/**
|
||||
* Stores arguments and ESP timer handle for a Timer.
|
||||
* In general Timers should be used via the TimeKeeper interface only.
|
||||
*
|
||||
* Timers cannot be copied, and are only created by a TimeKeeper instance.
|
||||
* The public way to access a Timer is by obtaining a TimerHandle (Timer *).
|
||||
* The TimeKeeper can delete existing Timers, calling it's destructor.
|
||||
* The ESP timer will be deleted when this class desctructor is called.
|
||||
*/
|
||||
struct Timer {
|
||||
explicit Timer(esp_timer_create_args_t args) :
|
||||
args_(args), esp_timer_(nullptr)
|
||||
{
|
||||
ESP_LOGI(TAG, "Creating esp_timer with name: %s", args_.name);
|
||||
ESP_ERROR_CHECK(esp_timer_create(&args, &esp_timer_));
|
||||
}
|
||||
|
||||
~Timer()
|
||||
{
|
||||
ESP_LOGI(TAG, "Destroying esp_timer with name: %s", args_.name);
|
||||
ESP_ERROR_CHECK(esp_timer_delete(esp_timer_));
|
||||
}
|
||||
|
||||
Timer(const Timer &) = delete;
|
||||
|
||||
Timer(Timer &) = delete;
|
||||
|
||||
Timer &operator=(Timer &) = delete;
|
||||
|
||||
/// Arguments passed to ESP API during timer creation.
|
||||
esp_timer_create_args_t args_;
|
||||
|
||||
/// ESP timer handle.
|
||||
esp_timer_handle_t esp_timer_;
|
||||
|
||||
private:
|
||||
/// Tag used for ESP logging.
|
||||
const char * TAG = "Timer";
|
||||
};
|
||||
|
||||
/**
|
||||
* ESP timer mananger class.
|
||||
*
|
||||
* Timers should only be accessed using the get_handle method.
|
||||
* If the Timer destructor is called the underlying ESP timer will be deleted.
|
||||
*/
|
||||
struct TimeKeeper {
|
||||
/// Timer handle type used for referring to Timers.
|
||||
using TimerHandle = Timer *;
|
||||
|
||||
TimerHandle get_handle(const char *name)
|
||||
{
|
||||
return &managed_timers_.at(name);
|
||||
}
|
||||
|
||||
TimerHandle operator[](const char *name) { return get_handle(name); }
|
||||
|
||||
/**
|
||||
* Create a new managed Timer with the provided ESP arguments.
|
||||
* The timer can be retrieved later using the args.name field value.
|
||||
*
|
||||
* @param args ESP timer creation arguments.
|
||||
* @return TimerHandle Handle to a Timer managed by this TimeKeeper.
|
||||
* @sa get_handle
|
||||
* @sa operator[](const char*)
|
||||
*/
|
||||
TimerHandle create_timer(esp_timer_create_args_t args)
|
||||
{
|
||||
auto rt = managed_timers_.emplace(args.name, args);
|
||||
if (!rt.second) {
|
||||
ESP_LOGE(TAG, "Display::Timer already exists with name %s", args.name);
|
||||
return nullptr;
|
||||
}
|
||||
return &rt.first->second;
|
||||
}
|
||||
|
||||
/// Stop a Timer with the given name.
|
||||
[[maybe_unused]] void stop_timer(const char *name)
|
||||
{
|
||||
ESP_ERROR_CHECK(esp_timer_stop(get_handle(name)->esp_timer_));
|
||||
}
|
||||
|
||||
/// Delete a Timer with the given name.
|
||||
[[maybe_unused]] void delete_timer(const char *name)
|
||||
{
|
||||
managed_timers_.erase(name);
|
||||
}
|
||||
|
||||
/// Create a Timer with the ESP args and call esp_timer_start_periodic.
|
||||
[[maybe_unused]] void
|
||||
start_new_timer_periodic(esp_timer_create_args_t args,
|
||||
uint64_t period)
|
||||
{
|
||||
start_timer_periodic(create_timer(args)->args_.name, period);
|
||||
}
|
||||
|
||||
/// Calls esp_timer_start_periodic on the Timer with the given name.
|
||||
[[maybe_unused]] void start_timer_periodic(const char *name,
|
||||
uint64_t period)
|
||||
{
|
||||
ESP_ERROR_CHECK(
|
||||
esp_timer_start_periodic(get_handle(name)->esp_timer_, period));
|
||||
}
|
||||
|
||||
/// Create a Timer with the ESP args and call esp_timer_start_once.
|
||||
[[maybe_unused]] void
|
||||
start_new_timer_once(esp_timer_create_args_t args,
|
||||
uint64_t timeout_us)
|
||||
{
|
||||
start_timer_once(create_timer(args)->args_.name, timeout_us);
|
||||
}
|
||||
|
||||
/// Calls esp_timer_start_once on the Timer with the given name.
|
||||
[[maybe_unused]] void start_timer_once(const char *name,
|
||||
uint64_t timeout_us)
|
||||
{
|
||||
ESP_ERROR_CHECK(
|
||||
esp_timer_start_once(get_handle(name)->esp_timer_, timeout_us));
|
||||
}
|
||||
|
||||
private:
|
||||
/// Existing ESP timers created for this TimeKeeper instance.
|
||||
std::unordered_map<const char *, Timer> managed_timers_;
|
||||
|
||||
/// Tag used for ESP logging.
|
||||
const char * TAG = "TimeKeeper";
|
||||
};
|
||||
|
||||
#endif // TIME_KEEPER_H
|
BIN
esp/cpp/07_lcd-panel-i2c/schematic.png
Normal file
BIN
esp/cpp/07_lcd-panel-i2c/schematic.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 227 KiB |
2783
esp/cpp/07_lcd-panel-i2c/sdkconfig
Normal file
2783
esp/cpp/07_lcd-panel-i2c/sdkconfig
Normal file
File diff suppressed because it is too large
Load Diff
@ -7,6 +7,8 @@ shaunrd0/klips/esp/
|
||||
├── 03_temp-humidity-web # Temperature and humidity sensor within a web browser.
|
||||
├── 04_esp-idf-arduino # CMake example instead of Arduino IDE for ESP development.
|
||||
├── 05_temp-humidity-web # Temperature and humidity sensor within a web browser.
|
||||
├── 06_i2c-scanner # Simple I2C device scanner.
|
||||
├── 07_lcd-panel-i2c # Drawing to a LCD display with LVGL over I2C.
|
||||
├── ESP32-basic-starter-kit.pdf # PDF for tutorials in ESP32 starter kit.
|
||||
├── ESP32-dev-module.png
|
||||
└── README.md
|
||||
|
Loading…
x
Reference in New Issue
Block a user