Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,9 @@ build/
managed_components/
dependencies.lock

sdkconfig
sdkconfig.old
sdkconfig.*.vscode

main/images/

6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ popd
pushd apps/calculator
esptool.py --chip esp32s3 --baud 921600 --before default_reset --after hard_reset write_flash 0x7A0000 build/calculator.bin
popd
pushd apps/synth_piano
esptool.py --chip esp32s3 --baud 921600 --before default_reset --after hard_reset write_flash 0xA60000 build/synth_piano.bin
popd
pushd apps/game_of_life
esptool.py --chip esp32s3 --baud 921600 --before default_reset --after hard_reset write_flash 0xD20000 build/game_of_life.bin
popd
```

## Build
Expand Down
4 changes: 4 additions & 0 deletions apps/calculator/sdkconfig.defaults
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This file was generated using idf.py save-defconfig. It can be edited manually.
# Espressif IoT Development Framework (ESP-IDF) 5.4.0 Project Minimal Configuration
#
CONFIG_IDF_TARGET="esp32s3"
4 changes: 4 additions & 0 deletions apps/calculator/sdkconfig.defaults.esp-box
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This file was generated using idf.py save-defconfig. It can be edited manually.
# Espressif IoT Development Framework (ESP-IDF) 5.4.0 Project Minimal Configuration
#
CONFIG_IDF_TARGET="esp32s3"
4 changes: 4 additions & 0 deletions apps/calculator/sdkconfig.defaults.esp-box-3
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This file was generated using idf.py save-defconfig. It can be edited manually.
# Espressif IoT Development Framework (ESP-IDF) 5.4.0 Project Minimal Configuration
#
CONFIG_IDF_TARGET="esp32s3"
6 changes: 6 additions & 0 deletions apps/calculator/sdkconfig.defaults.m5stack_core_s3
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# This file was generated using idf.py save-defconfig. It can be edited manually.
# Espressif IoT Development Framework (ESP-IDF) 5.4.0 Project Minimal Configuration
#
CONFIG_IDF_TARGET="esp32s3"
CONFIG_ESPTOOLPY_FLASHSIZE_16MB=y
CONFIG_PARTITION_TABLE_CUSTOM=y
6 changes: 6 additions & 0 deletions apps/game_of_life/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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(game_of_life)
3 changes: 3 additions & 0 deletions apps/game_of_life/main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
idf_component_register(SRCS "game_of_life.c"
INCLUDE_DIRS "."
REQUIRES app_update)
164 changes: 164 additions & 0 deletions apps/game_of_life/main/game_of_life.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
#include <stdio.h>
// Conway's Game of Life for ESP32 using LVGL
#include <stdlib.h>
#include <stdbool.h>
#include <time.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_log.h"
#include "esp_system.h"
#include "lvgl.h"
#include "bsp/esp-bsp.h"
#include "esp_ota_ops.h"

#define TAG "GameOfLife"
#define GRID_SIZE 20
#define CELL_SIZE 10
#define CANVAS_WIDTH (GRID_SIZE * CELL_SIZE)
#define CANVAS_HEIGHT (GRID_SIZE * CELL_SIZE)

static bool grid[GRID_SIZE][GRID_SIZE];
static bool temp_grid[GRID_SIZE][GRID_SIZE];
static lv_obj_t *canvas;
lv_layer_t layer;

static void draw_grid();
static void update_grid();

static void randomize_grid() {
for (int row = 0; row < GRID_SIZE; ++row) {
for (int col = 0; col < GRID_SIZE; ++col) {
grid[row][col] = rand() % 2;
}
}
}

static void reset_btn_event_cb(lv_event_t *e) {
lv_event_code_t code = lv_event_get_code(e);
if (code == LV_EVENT_CLICKED) {
randomize_grid();
}
}

static void draw_grid() {
bsp_display_lock(0);

lv_draw_rect_dsc_t rect_dsc;
lv_draw_rect_dsc_init(&rect_dsc);

for (int row = 0; row < GRID_SIZE; ++row) {
for (int col = 0; col < GRID_SIZE; ++col) {
lv_area_t area;
area.x1 = col * CELL_SIZE;
area.y1 = row * CELL_SIZE;
area.x2 = area.x1 + CELL_SIZE - 1;
area.y2 = area.y1 + CELL_SIZE - 1;
rect_dsc.bg_color = grid[row][col] ? lv_palette_main(LV_PALETTE_BLUE) : lv_color_white();
lv_draw_rect(&layer, &rect_dsc, &area);
}
}

lv_canvas_finish_layer(canvas, &layer);
lv_obj_invalidate(canvas);
bsp_display_unlock();
}

static void update_grid() {
for (int row = 0; row < GRID_SIZE; ++row) {
for (int col = 0; col < GRID_SIZE; ++col) {
int live_neighbors = 0;
for (int i = -1; i <= 1; ++i) {
for (int j = -1; j <= 1; ++j) {
if (i == 0 && j == 0) continue;
int r = row + i;
int c = col + j;
if (r >= 0 && r < GRID_SIZE && c >= 0 && c < GRID_SIZE) {
live_neighbors += grid[r][c];
}
}
}

if (grid[row][col]) {
temp_grid[row][col] = live_neighbors == 2 || live_neighbors == 3;
} else {
temp_grid[row][col] = live_neighbors == 3;
}
}
}

for (int row = 0; row < GRID_SIZE; ++row) {
for (int col = 0; col < GRID_SIZE; ++col) {
grid[row][col] = temp_grid[row][col];
}
}
}

static void life_task(void *param) {
while (1) {
vTaskDelay(pdMS_TO_TICKS(100));
update_grid();
draw_grid();
}
}

void reset_to_factory_app() {
// Get the partition structure for the factory partition
const esp_partition_t *factory_partition = esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_FACTORY, NULL);
if (factory_partition != NULL) {
if (esp_ota_set_boot_partition(factory_partition) == ESP_OK) {
printf("Set boot partition to factory, restarting now.\n");
} else {
printf("Failed to set boot partition to factory.\n");
}
} else {
printf("Factory partition not found.\n");
}

fflush(stdout);
}

void app_main(void) {
// Reset to factory app for the next boot.
// It should return to graphical bootloader.
reset_to_factory_app();

// Initialize the BSP
bsp_i2c_init();
bsp_display_start();
lv_init();
srand(time(NULL));

bsp_display_lock(0);

LV_DRAW_BUF_DEFINE(draw_buf, CANVAS_WIDTH, CANVAS_HEIGHT, LV_COLOR_FORMAT_RGB565);

canvas = lv_canvas_create(lv_scr_act());
lv_canvas_set_draw_buf(canvas, &draw_buf);
lv_canvas_fill_bg(canvas, lv_color_hex3(0xccc), LV_OPA_COVER);
lv_obj_center(canvas);

lv_canvas_init_layer(canvas, &layer);

// Create a reset button
lv_obj_t *reset_btn = lv_btn_create(lv_scr_act());
lv_obj_t *label = lv_label_create(reset_btn);
lv_label_set_text(label, "Reset");
lv_obj_align(reset_btn, LV_ALIGN_BOTTOM_RIGHT, 0, -10);
lv_obj_add_event_cb(reset_btn, reset_btn_event_cb, LV_EVENT_CLICKED, NULL);

bsp_display_backlight_on();
bsp_display_unlock();

// Initialize grid
randomize_grid();
printf("Grid initialized\n");
draw_grid();
printf("Grid drawn\n");

// Create the life task
xTaskCreate(life_task, "life_task", 32768, NULL, 5, NULL);

while (1) {
vTaskDelay(pdMS_TO_TICKS(1000));
}
}
11 changes: 11 additions & 0 deletions apps/game_of_life/main/idf_component.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## IDF Component Manager Manifest File
dependencies:
espressif/esp-box: "^3.1.0"
#espressif/esp-box-3: "^1.2.0"
# Workaround for i2c: CONFLICT! driver_ng is not allowed to be used with this old driver
esp_codec_dev:
public: true
version: "==1.1.0"
## Required IDF version
idf:
version: ">=5.0.0"
4 changes: 4 additions & 0 deletions apps/game_of_life/sdkconfig.defaults
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This file was generated using idf.py save-defconfig. It can be edited manually.
# Espressif IoT Development Framework (ESP-IDF) 5.4.0 Project Minimal Configuration
#
CONFIG_IDF_TARGET="esp32s3"
4 changes: 4 additions & 0 deletions apps/game_of_life/sdkconfig.defaults.esp-box
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This file was generated using idf.py save-defconfig. It can be edited manually.
# Espressif IoT Development Framework (ESP-IDF) 5.4.0 Project Minimal Configuration
#
CONFIG_IDF_TARGET="esp32s3"
4 changes: 4 additions & 0 deletions apps/game_of_life/sdkconfig.defaults.esp-box-3
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This file was generated using idf.py save-defconfig. It can be edited manually.
# Espressif IoT Development Framework (ESP-IDF) 5.4.0 Project Minimal Configuration
#
CONFIG_IDF_TARGET="esp32s3"
6 changes: 6 additions & 0 deletions apps/game_of_life/sdkconfig.defaults.m5stack_core_s3
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# This file was generated using idf.py save-defconfig. It can be edited manually.
# Espressif IoT Development Framework (ESP-IDF) 5.4.0 Project Minimal Configuration
#
CONFIG_IDF_TARGET="esp32s3"
CONFIG_ESPTOOLPY_FLASHSIZE_16MB=y
CONFIG_PARTITION_TABLE_CUSTOM=y
6 changes: 6 additions & 0 deletions apps/synth_piano/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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(synth_piano)
3 changes: 3 additions & 0 deletions apps/synth_piano/main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
idf_component_register(SRCS "synth_piano.c"
INCLUDE_DIRS "."
REQUIRES app_update)
11 changes: 11 additions & 0 deletions apps/synth_piano/main/idf_component.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## IDF Component Manager Manifest File
dependencies:
espressif/esp-box: "^3.1.0"
#espressif/esp-box-3: "^1.2.0"
# Workaround for i2c: CONFLICT! driver_ng is not allowed to be used with this old driver
esp_codec_dev:
public: true
version: "==1.1.0"
## Required IDF version
idf:
version: ">=5.0.0"
Loading