feat: initial commit

This commit is contained in:
2025-01-28 20:37:48 +01:00
commit 82835d3712
6 changed files with 202 additions and 0 deletions

6
.gitignore vendored Normal file
View File

@@ -0,0 +1,6 @@
build/
cmake-*/
sdkconfig
sdkconfig.old
.idea/
managed_components/

6
CMakeLists.txt Normal file
View File

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

64
dependencies.lock Normal file
View File

@@ -0,0 +1,64 @@
dependencies:
espressif/button:
component_hash: a405a99689f636e84cd67da34a85a88d0d3a1aa514a28f60d18bd370c1378e0b
dependencies:
- name: espressif/cmake_utilities
registry_url: https://components.espressif.com
require: private
version: 0.*
- name: idf
require: private
version: '>=4.0'
source:
registry_url: https://components.espressif.com/
type: service
version: 4.0.0
espressif/cmake_utilities:
component_hash: 351350613ceafba240b761b4ea991e0f231ac7a9f59a9ee901f751bddc0bb18f
dependencies:
- name: idf
require: private
version: '>=4.1'
source:
registry_url: https://components.espressif.com
type: service
version: 0.5.3
espressif/led_indicator:
component_hash: f1fbe20fba9313986c32b1b6b7a4ae4822103ab928b51e9bd77215470cb70d98
dependencies:
- name: espressif/led_strip
registry_url: https://components.espressif.com
require: public
version: 2.5.5
- name: idf
require: private
version: '>=4.0'
- name: espressif/cmake_utilities
registry_url: https://components.espressif.com
require: private
version: 0.*
source:
registry_url: https://components.espressif.com/
type: service
version: 1.0.0
espressif/led_strip:
component_hash: 28c6509a727ef74925b372ed404772aeedf11cce10b78c3f69b3c66799095e2d
dependencies:
- name: idf
require: private
version: '>=4.4'
source:
registry_url: https://components.espressif.com
type: service
version: 2.5.5
idf:
source:
type: idf
version: 5.4.0
direct_dependencies:
- espressif/button
- espressif/led_indicator
- idf
manifest_hash: 9a01da739f55fc5600aeafe862007ef4157320d199d58dacf66dd6881108d26e
target: esp32
version: 2.0.0

2
main/CMakeLists.txt Normal file
View File

@@ -0,0 +1,2 @@
idf_component_register(SRCS "hello_world_main.c"
INCLUDE_DIRS "")

106
main/hello_world_main.c Normal file
View File

@@ -0,0 +1,106 @@
/*
* SPDX-FileCopyrightText: 2010-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: CC0-1.0
*/
#include <stdio.h>
#include <inttypes.h>
#include "sdkconfig.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_chip_info.h"
#include "esp_flash.h"
#include "esp_system.h"
#include "driver/gpio.h"
#include "iot_button.h"
#include "button_gpio.h"
#include "led_gpio.h"
#include "led_indicator.h"
#include "led_indicator_blink_default.h"
#define IO_PIN GPIO_NUM_2
static const char* TAG = "Btn";
static led_indicator_handle_t led_handle = NULL;
static button_handle_t button_handle = NULL;
void init_led() {
led_indicator_gpio_config_t led_indicator_gpio_config = {
.is_active_level_high = 1,
.gpio_num = IO_PIN,
};
led_indicator_config_t led_indicator_config = {
.mode = LED_GPIO_MODE,
.led_indicator_gpio_config = &led_indicator_gpio_config,
.blink_lists = (void*)NULL,
.blink_list_num = 0,
};
led_handle = led_indicator_create(&led_indicator_config);
if (led_handle == NULL) {
printf("Could not init LED indicator");
abort();
}
led_indicator_start(led_handle, BLINK_CONNECTING);
}
static void button_single_click_cb(void* arg, void* usr_data) {
printf("Button clicked from %p %p", arg, usr_data);
led_indicator_start(led_handle, BLINK_CONNECTED);
}
void setup_buttons() {
button_gpio_config_t gpio_config = {
.gpio_num = 0,
.active_level = 0,
};
button_config_t button_0_cfg = {
.long_press_time = CONFIG_BUTTON_LONG_PRESS_TIME_MS,
.short_press_time = CONFIG_BUTTON_SHORT_PRESS_TIME_MS,
};
ESP_ERROR_CHECK(iot_button_new_gpio_device(&button_0_cfg, &gpio_config, &button_handle));
ESP_ERROR_CHECK(iot_button_register_cb(button_handle, BUTTON_SINGLE_CLICK, NULL, button_single_click_cb, NULL));
}
void app_main(void)
{
printf("Hello world!\n");
setup_buttons();
init_led();
/* Print chip information */
esp_chip_info_t chip_info;
uint32_t flash_size;
esp_chip_info(&chip_info);
printf("This is %s chip with %d CPU core(s), %s%s%s%s, ",
CONFIG_IDF_TARGET,
chip_info.cores,
(chip_info.features & CHIP_FEATURE_WIFI_BGN) ? "WiFi/" : "",
(chip_info.features & CHIP_FEATURE_BT) ? "BT" : "",
(chip_info.features & CHIP_FEATURE_BLE) ? "BLE" : "",
(chip_info.features & CHIP_FEATURE_IEEE802154) ? ", 802.15.4 (Zigbee/Thread)" : "");
unsigned major_rev = chip_info.revision / 100;
unsigned minor_rev = chip_info.revision % 100;
printf("silicon revision v%d.%d, ", major_rev, minor_rev);
if(esp_flash_get_size(NULL, &flash_size) != ESP_OK) {
printf("Get flash size failed");
return;
}
printf("%" PRIu32 "MB %s flash\n", flash_size / (uint32_t)(1024 * 1024),
(chip_info.features & CHIP_FEATURE_EMB_FLASH) ? "embedded" : "external");
printf("Minimum free heap size: %" PRIu32 " bytes\n", esp_get_minimum_free_heap_size());
for (int i = 10; i >= 0; i--) {
printf("Restarting in %d seconds...\n", i);
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
printf("Restarting now.\n");
fflush(stdout);
esp_restart();
}

18
main/idf_component.yml Normal file
View File

@@ -0,0 +1,18 @@
## IDF Component Manager Manifest File
dependencies:
espressif/button: ^4.0.0
## 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/led_indicator: ^1.0.0