Initial commit
This commit is contained in:
13
.devcontainer/Dockerfile
Normal file
13
.devcontainer/Dockerfile
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
ARG DOCKER_TAG=latest
|
||||||
|
FROM espressif/idf:${DOCKER_TAG}
|
||||||
|
|
||||||
|
ENV LC_ALL=C.UTF-8
|
||||||
|
ENV LANG=C.UTF-8
|
||||||
|
|
||||||
|
RUN apt-get update -y && apt-get install udev -y
|
||||||
|
|
||||||
|
RUN echo "source /opt/esp/idf/export.sh > /dev/null 2>&1" >> ~/.bashrc
|
||||||
|
|
||||||
|
ENTRYPOINT [ "/opt/esp/entrypoint.sh" ]
|
||||||
|
|
||||||
|
CMD ["/bin/bash", "-c"]
|
||||||
19
.devcontainer/devcontainer.json
Normal file
19
.devcontainer/devcontainer.json
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"name": "ESP-IDF QEMU",
|
||||||
|
"build": {
|
||||||
|
"dockerfile": "Dockerfile"
|
||||||
|
},
|
||||||
|
"customizations": {
|
||||||
|
"vscode": {
|
||||||
|
"settings": {
|
||||||
|
"terminal.integrated.defaultProfile.linux": "bash",
|
||||||
|
"idf.gitPath": "/usr/bin/git"
|
||||||
|
},
|
||||||
|
"extensions": [
|
||||||
|
"espressif.esp-idf-extension",
|
||||||
|
"espressif.esp-idf-web"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"runArgs": ["--privileged"]
|
||||||
|
}
|
||||||
78
.gitignore
vendored
Normal file
78
.gitignore
vendored
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
# macOS
|
||||||
|
.DS_Store
|
||||||
|
.AppleDouble
|
||||||
|
.LSOverride
|
||||||
|
|
||||||
|
# Directory metadata
|
||||||
|
.directory
|
||||||
|
|
||||||
|
# Temporary files
|
||||||
|
*~
|
||||||
|
*.swp
|
||||||
|
*.swo
|
||||||
|
*.bak
|
||||||
|
*.tmp
|
||||||
|
|
||||||
|
# Log files
|
||||||
|
*.log
|
||||||
|
|
||||||
|
# Build artifacts and directories
|
||||||
|
**/build/
|
||||||
|
build/
|
||||||
|
*.o
|
||||||
|
*.a
|
||||||
|
*.out
|
||||||
|
*.exe # For any host-side utilities compiled on Windows
|
||||||
|
|
||||||
|
# ESP-IDF specific build outputs
|
||||||
|
*.bin
|
||||||
|
*.elf
|
||||||
|
*.map
|
||||||
|
flasher_args.json # Generated in build directory
|
||||||
|
sdkconfig.old
|
||||||
|
sdkconfig
|
||||||
|
|
||||||
|
# ESP-IDF dependencies
|
||||||
|
# For older versions or manual component management
|
||||||
|
/components/.idf/
|
||||||
|
**/components/.idf/
|
||||||
|
# For modern ESP-IDF component manager
|
||||||
|
managed_components/
|
||||||
|
# If ESP-IDF tools are installed/referenced locally to the project
|
||||||
|
.espressif/
|
||||||
|
|
||||||
|
# CMake generated files
|
||||||
|
CMakeCache.txt
|
||||||
|
CMakeFiles/
|
||||||
|
cmake_install.cmake
|
||||||
|
install_manifest.txt
|
||||||
|
CTestTestfile.cmake
|
||||||
|
|
||||||
|
# Python environment files
|
||||||
|
*.pyc
|
||||||
|
*.pyo
|
||||||
|
*.pyd
|
||||||
|
__pycache__/
|
||||||
|
*.egg-info/
|
||||||
|
dist/
|
||||||
|
|
||||||
|
# Virtual environment folders
|
||||||
|
venv/
|
||||||
|
.venv/
|
||||||
|
env/
|
||||||
|
|
||||||
|
# Language Servers
|
||||||
|
.clangd/
|
||||||
|
.ccls-cache/
|
||||||
|
compile_commands.json
|
||||||
|
|
||||||
|
# Windows specific
|
||||||
|
Thumbs.db
|
||||||
|
ehthumbs.db
|
||||||
|
Desktop.ini
|
||||||
|
|
||||||
|
# User-specific configuration files
|
||||||
|
*.user
|
||||||
|
*.workspace # General workspace files, can be from various tools
|
||||||
|
*.suo # Visual Studio Solution User Options
|
||||||
|
*.sln.docstates # Visual Studio
|
||||||
20
.vscode/c_cpp_properties.json
vendored
Normal file
20
.vscode/c_cpp_properties.json
vendored
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "ESP-IDF",
|
||||||
|
"compilerPath": "C:\\Espressif\\tools\\xtensa-esp-elf\\esp-15.2.0_20251204\\xtensa-esp-elf\\bin\\xtensa-esp32s3-elf-gcc.exe",
|
||||||
|
"compileCommands": "${config:idf.buildPath}/compile_commands.json",
|
||||||
|
"intelliSenseMode": "gcc-x86",
|
||||||
|
"includePath": [
|
||||||
|
"${workspaceFolder}/**"
|
||||||
|
],
|
||||||
|
"browse": {
|
||||||
|
"path": [
|
||||||
|
"${workspaceFolder}"
|
||||||
|
],
|
||||||
|
"limitSymbolsToIncludedHeaders": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"version": 4
|
||||||
|
}
|
||||||
10
.vscode/launch.json
vendored
Normal file
10
.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"type": "gdbtarget",
|
||||||
|
"request": "attach",
|
||||||
|
"name": "Eclipse CDT GDB Adapter"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
19
.vscode/settings.json
vendored
Normal file
19
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"C_Cpp.intelliSenseEngine": "default",
|
||||||
|
"idf.extensionActivationMode": "always",
|
||||||
|
"idf.openOcdConfigs": [
|
||||||
|
"board/esp32s3-builtin.cfg"
|
||||||
|
],
|
||||||
|
"idf.portWin": "COM10",
|
||||||
|
"idf.currentSetup": "C:\\esp\\v6.0.1\\esp-idf",
|
||||||
|
"idf.customExtraVars": {
|
||||||
|
"IDF_TARGET": "esp32s3"
|
||||||
|
},
|
||||||
|
"clangd.path": "C:\\Espressif\\tools\\esp-clang\\esp-20.1.1_20250829\\esp-clang\\bin\\clangd.exe",
|
||||||
|
"clangd.arguments": [
|
||||||
|
"--background-index",
|
||||||
|
"--query-driver=**",
|
||||||
|
"--compile-commands-dir=c:\\Users\\Jade\\ESP-IDF\\ESP32-TrainThing\\build"
|
||||||
|
],
|
||||||
|
"idf.flashType": "UART"
|
||||||
|
}
|
||||||
8
CMakeLists.txt
Normal file
8
CMakeLists.txt
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
# 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.22)
|
||||||
|
|
||||||
|
set(COMPONENTS main)
|
||||||
|
|
||||||
|
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||||
|
project(ESP32-TrainThing)
|
||||||
35
dependencies.lock
Normal file
35
dependencies.lock
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
dependencies:
|
||||||
|
espressif/button:
|
||||||
|
component_hash: d0afa32f0e50d60bc0c6fc23f7eea98adc6b02cfe70b590bc52c23c506745287
|
||||||
|
dependencies:
|
||||||
|
- name: espressif/cmake_utilities
|
||||||
|
registry_url: https://components.espressif.com
|
||||||
|
require: private
|
||||||
|
version: '*'
|
||||||
|
- name: idf
|
||||||
|
require: private
|
||||||
|
version: '>=4.0'
|
||||||
|
source:
|
||||||
|
registry_url: https://components.espressif.com/
|
||||||
|
type: service
|
||||||
|
version: 4.1.6
|
||||||
|
espressif/cmake_utilities:
|
||||||
|
component_hash: 05165f30922b422b4b90c08845e6d449329b97370fbd06309803d8cb539d79e3
|
||||||
|
dependencies:
|
||||||
|
- name: idf
|
||||||
|
require: private
|
||||||
|
version: '>=4.1'
|
||||||
|
source:
|
||||||
|
registry_url: https://components.espressif.com
|
||||||
|
type: service
|
||||||
|
version: 1.1.1
|
||||||
|
idf:
|
||||||
|
source:
|
||||||
|
type: idf
|
||||||
|
version: 6.0.1
|
||||||
|
direct_dependencies:
|
||||||
|
- espressif/button
|
||||||
|
- idf
|
||||||
|
manifest_hash: 3c0e2b99c6461e4de9aa94d1d88f9dd122de14a3060761adde6da132d918ca1a
|
||||||
|
target: esp32s3
|
||||||
|
version: 3.0.0
|
||||||
2
main/CMakeLists.txt
Normal file
2
main/CMakeLists.txt
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
idf_component_register(SRCS "main.c" "buttons/buttons.c"
|
||||||
|
INCLUDE_DIRS "." "buttons")
|
||||||
43
main/buttons/buttons.c
Normal file
43
main/buttons/buttons.c
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
#include "buttons.h"
|
||||||
|
#include "iot_button.h"
|
||||||
|
#include "button_gpio.h"
|
||||||
|
#include "esp_log.h"
|
||||||
|
#include "esp_err.h"
|
||||||
|
#include "esp_check.h"
|
||||||
|
|
||||||
|
static const char* TAG = "TrainThing/buttons";
|
||||||
|
|
||||||
|
const action actions[] = {
|
||||||
|
{.btnAcc = FRONT_LIGHT_INCREASE, .name = "FRONT_LIGHT_INCREASE", .pin = 1, .shortcut = 'a'},
|
||||||
|
{.btnAcc = FRONT_LIGHT_DECREASE, .name = "FRONT_LIGHT_DECREASE", .pin = 2, .shortcut = 'b'},
|
||||||
|
{.btnAcc = BACK_LIGHT_INCREASE, .name = "BACK_LIGHT_INCREASE", .pin = 3, .shortcut = 'c'},
|
||||||
|
{.btnAcc = BACK_LIGHT_DECREASE, .name = "BACK_LIGHT_DECREASE", .pin = 4, .shortcut = 'd'},
|
||||||
|
{.btnAcc = CAB_LIGHT, .name = "CAB_LIGHT", .pin = 5, .shortcut = 'e'},
|
||||||
|
{.btnAcc = WIPPERS, .name = "WIPPERS", .pin = 6, .shortcut = 'f'},
|
||||||
|
{.btnAcc = SANDER, .name = "SANDER", .pin = 7, .shortcut = 'g'},
|
||||||
|
{.btnAcc = STARTER, .name = "STARTER", .pin = 8, .shortcut = 'h'},
|
||||||
|
{.btnAcc = CUT, .name = "CUT", .pin = 9, .shortcut = 'i'},
|
||||||
|
{.btnAcc = HORN, .name = "HORN", .pin = 10, .shortcut = 'j'},
|
||||||
|
};
|
||||||
|
void button_event_cb(void *arg, void *data)
|
||||||
|
{
|
||||||
|
action *a = (action*)data;
|
||||||
|
|
||||||
|
button_event_t event = iot_button_get_event(arg);
|
||||||
|
ESP_LOGI(TAG, "%s pin:%d name:%s shortcut:%c", iot_button_get_event_str(event), (int)a->pin, (char*)a->name, (char)a->shortcut);
|
||||||
|
}
|
||||||
|
|
||||||
|
void initialize_buttons(){
|
||||||
|
const button_config_t btn_cfg = {0};
|
||||||
|
button_handle_t btns[5];
|
||||||
|
|
||||||
|
for (size_t i = 0; i < sizeof(actions) / sizeof(actions[0]); i++)
|
||||||
|
{
|
||||||
|
const button_gpio_config_t btn_gpio_cfg = {
|
||||||
|
.gpio_num = actions[i].pin,
|
||||||
|
.active_level = 0,
|
||||||
|
};
|
||||||
|
ESP_RETURN_VOID_ON_ERROR(iot_button_new_gpio_device(&btn_cfg, &btn_gpio_cfg, &btns[i]), TAG, "");
|
||||||
|
iot_button_register_cb(btns[i], BUTTON_PRESS_DOWN, NULL, button_event_cb, (void *) &actions[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
30
main/buttons/buttons.h
Normal file
30
main/buttons/buttons.h
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
#ifndef BUTTONS_H
|
||||||
|
|
||||||
|
#define BUTTONS_H
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
FRONT_LIGHT_INCREASE,
|
||||||
|
FRONT_LIGHT_DECREASE,
|
||||||
|
BACK_LIGHT_INCREASE,
|
||||||
|
BACK_LIGHT_DECREASE,
|
||||||
|
CAB_LIGHT,
|
||||||
|
WIPPERS,
|
||||||
|
SANDER,
|
||||||
|
STARTER,
|
||||||
|
CUT,
|
||||||
|
HORN,
|
||||||
|
}buttonAction;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
buttonAction btnAcc;
|
||||||
|
const char* name;
|
||||||
|
char shortcut;
|
||||||
|
int pin;
|
||||||
|
|
||||||
|
}action;
|
||||||
|
|
||||||
|
void button_event_cb(void *arg, void *data);
|
||||||
|
|
||||||
|
void initialize_buttons();
|
||||||
|
#endif // BUTTONS_H
|
||||||
17
main/idf_component.yml
Normal file
17
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/button: ^4.1.6
|
||||||
87
main/main.c
Normal file
87
main/main.c
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include "iot_button.h"
|
||||||
|
#include "button_gpio.h"
|
||||||
|
#include "esp_log.h"
|
||||||
|
#include "esp_err.h"
|
||||||
|
#include "esp_check.h"
|
||||||
|
#include "buttons/buttons.h"
|
||||||
|
|
||||||
|
static const char* TAG = "TrainThing";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
static void button_single_click_cb(void *arg,void *usr_data)
|
||||||
|
{
|
||||||
|
ESP_LOGI(TAG, "BUTTON_SINGLE_CLICK");
|
||||||
|
}
|
||||||
|
static void button_long_press_1_cb(void *arg,void *usr_data)
|
||||||
|
{
|
||||||
|
ESP_LOGI(TAG, "BUTTON_LONG_PRESS_START_1");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void button_long_press_2_cb(void *arg,void *usr_data)
|
||||||
|
{
|
||||||
|
ESP_LOGI(TAG, "BUTTON_LONG_PRESS_START_2");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void button_click_2_cb(void *arg,void *usr_data)
|
||||||
|
{
|
||||||
|
ESP_LOGI(TAG, "BUTTON 2 click");
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
void app_main(void)
|
||||||
|
{
|
||||||
|
initialize_buttons();
|
||||||
|
/*
|
||||||
|
for (size_t i = 0; i < sizeof(btn_name_table) / sizeof(btn_name_table[0]); ++i) {
|
||||||
|
ESP_LOGI(TAG, "%s %d %c", btn_name_table[i].name, btn_name_table[i].btnAcc, btn_name_table[i].shortcut );
|
||||||
|
|
||||||
|
}*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//ESP_RETURN_VOID_ON_ERROR(iot_button_new_gpio_device(&btn_cfg, &btn_gpio_cfg, &btn), TAG, "");
|
||||||
|
|
||||||
|
|
||||||
|
/*ESP_RETURN_VOID_ON_ERROR(iot_button_register_cb(gpio_btn, BUTTON_SINGLE_CLICK, NULL, button_event_cb,NULL), TAG, "");
|
||||||
|
|
||||||
|
button_event_args_t args ={.long_press.press_time = 2000};
|
||||||
|
ESP_RETURN_VOID_ON_ERROR(iot_button_register_cb(gpio_btn, BUTTON_LONG_PRESS_UP, NULL, button_event_cb, NULL), TAG, "");
|
||||||
|
|
||||||
|
args.long_press.press_time = 5000;
|
||||||
|
//ESP_RETURN_VOID_ON_ERROR(iot_button_register_cb(gpio_btn, BUTTON_LONG_PRESS_UP, &args, button_long_press_2_cb, NULL), TAG, "");
|
||||||
|
|
||||||
|
ESP_RETURN_VOID_ON_ERROR(iot_button_register_cb(gpio_btn, BUTTON_DOUBLE_CLICK, NULL, button_event_cb, NULL), TAG, "");
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
iot_button_register_cb(btn, BUTTON_PRESS_DOWN, NULL, button_event_cb, NULL);
|
||||||
|
iot_button_register_cb(btn, BUTTON_PRESS_UP, NULL, button_event_cb, NULL);
|
||||||
|
iot_button_register_cb(btn, BUTTON_PRESS_REPEAT, NULL, button_event_cb, NULL);
|
||||||
|
iot_button_register_cb(btn, BUTTON_PRESS_REPEAT_DONE, NULL, button_event_cb, NULL);
|
||||||
|
iot_button_register_cb(btn, BUTTON_SINGLE_CLICK, NULL, button_event_cb, NULL);
|
||||||
|
iot_button_register_cb(btn, BUTTON_DOUBLE_CLICK, NULL, button_event_cb, NULL);
|
||||||
|
|
||||||
|
|
||||||
|
button_event_args_t args = {
|
||||||
|
.multiple_clicks.clicks = 2,
|
||||||
|
};
|
||||||
|
iot_button_register_cb(btn, BUTTON_MULTIPLE_CLICK, &args, button_event_cb, (void *)2);
|
||||||
|
args.multiple_clicks.clicks = 3;
|
||||||
|
iot_button_register_cb(btn, BUTTON_MULTIPLE_CLICK, &args, button_event_cb, (void *)3);
|
||||||
|
|
||||||
|
iot_button_register_cb(btn, BUTTON_LONG_PRESS_START, NULL, button_event_cb, NULL);
|
||||||
|
iot_button_register_cb(btn, BUTTON_LONG_PRESS_HOLD, NULL, button_event_cb, NULL);
|
||||||
|
iot_button_register_cb(btn, BUTTON_LONG_PRESS_UP, NULL, button_event_cb, NULL);
|
||||||
|
iot_button_register_cb(btn, BUTTON_PRESS_END, NULL, button_event_cb, NULL);
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user