diff --git a/RebundDemo/CMakeLists.txt b/RebundDemo/CMakeLists.txt new file mode 100644 index 0000000..2aa16fe --- /dev/null +++ b/RebundDemo/CMakeLists.txt @@ -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) diff --git a/RebundDemo/README.md b/RebundDemo/README.md new file mode 100644 index 0000000..6af2023 --- /dev/null +++ b/RebundDemo/README.md @@ -0,0 +1,2 @@ +# ReboundDemo for SSD1306 + diff --git a/RebundDemo/main/CMakeLists.txt b/RebundDemo/main/CMakeLists.txt new file mode 100644 index 0000000..647a294 --- /dev/null +++ b/RebundDemo/main/CMakeLists.txt @@ -0,0 +1,4 @@ +set(COMPONENT_SRCS "main.c") +set(COMPONENT_ADD_INCLUDEDIRS "") + +register_component() diff --git a/RebundDemo/main/component.mk b/RebundDemo/main/component.mk new file mode 100644 index 0000000..61f8990 --- /dev/null +++ b/RebundDemo/main/component.mk @@ -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. +# diff --git a/RebundDemo/main/main.c b/RebundDemo/main/main.c new file mode 100644 index 0000000..d929fc0 --- /dev/null +++ b/RebundDemo/main/main.c @@ -0,0 +1,101 @@ +#include +#include +#include +#include +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "esp_random.h" +#include "esp_log.h" + +#include "ssd1306.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" + +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_SSD1306_128x64 + ESP_LOGI(tag, "Panel is 128x64"); + ssd1306_init(&dev, 128, 64); + int xmax = 127; + int ymax = 63; +#endif // CONFIG_SSD1306_128x64 +#if CONFIG_SSD1306_128x32 + ESP_LOGI(tag, "Panel is 128x32"); + ssd1306_init(&dev, 128, 32); + int xmax = 127; + int ymax = 31; +#endif // CONFIG_SSD1306_128x32 + + int radius = 4; + uint32_t xrand = esp_random(); + uint32_t yrand = esp_random(); + ESP_LOGD(tag, "xrand=%"PRIu32" yrand=%"PRIu32, xrand, yrand); + //int x_current = 10; + //int y_current = 10; + int x_current = xrand % xmax; + int y_current = yrand % ymax; + ESP_LOGD(tag, "x_current=%d", x_current); + ESP_LOGD(tag, "y_current=%d", y_current); + int x_previus = x_current; + int y_previus = y_current; + int x_direction = 1; + int y_direction = 1; + ssd1306_clear_screen(&dev, false); + ssd1306_contrast(&dev, 0xff); + + while(1) { + _ssd1306_circle(&dev, x_previus, y_previus, radius, true); + _ssd1306_circle(&dev, x_current, y_current, radius, false); + ssd1306_show_buffer(&dev); + x_previus = x_current; + y_previus = y_current; + x_current = x_current + x_direction; + y_current = y_current + y_direction; + if ( (x_current + radius) >= xmax) { + x_direction = -1; + } else if ( (x_current - radius) <= 0) { + x_direction = 1; + } else if ( (y_current + radius) >= ymax) { + y_direction = -1; + } else if ( (y_current - radius) <= 0) { + y_direction = 1; + } + vTaskDelay(1); + } +} diff --git a/RebundDemo/sdkconfig.defaults b/RebundDemo/sdkconfig.defaults new file mode 100644 index 0000000..27d6f75 --- /dev/null +++ b/RebundDemo/sdkconfig.defaults @@ -0,0 +1,18 @@ +# +# ESP32-specific +# +CONFIG_ESP32_DEFAULT_CPU_FREQ_240=y +CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ=240 + +# +# ESP32S2-specific +# +CONFIG_ESP32S2_DEFAULT_CPU_FREQ_240=y +CONFIG_ESP32S2_DEFAULT_CPU_FREQ_MHZ=240 + +# +# ESP32S3-specific +# +CONFIG_ESP32S3_DEFAULT_CPU_FREQ_240=y +CONFIG_ESP32S3_DEFAULT_CPU_FREQ_MHZ=240 +