Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
d6ee170
supermini
Apr 30, 2024
d57d55c
Merge pull request #2 from mooiweertje/master
void-spark Apr 30, 2024
68ad22b
supermini
May 13, 2024
9f049a0
reset distance on mode long press
May 20, 2024
0ae164b
test
May 21, 2024
7d924b1
Merge pull request #3 from mooiweertje/master
void-spark May 21, 2024
2dd9bee
actions/upload-artifact@v4
Feb 18, 2025
871ebd2
Merge pull request #5 from mooiweertje/actions/upload-artifact@v4
void-spark Feb 22, 2025
eedc26d
KirianLifePo4 base
Mar 13, 2025
3e0f7c2
esp_idf_version
Oct 6, 2025
c70021b
Merge pull request #6 from mooiweertje/master
void-spark Oct 9, 2025
47dc290
esp_idf_version_5.5.1
Nov 7, 2025
b17c088
Merge pull request #7 from mooiweertje/master
void-spark Nov 8, 2025
805d1a8
ADCOptimization
Nov 11, 2025
6e0e2c4
spiffsToLittlefs
Nov 15, 2025
eb862e4
Merge pull request #9 from mooiweertje/spiffsToLittlefs
void-spark Nov 15, 2025
f4a4822
Merge branch 'master' into ADCOptimization
mooiweertje Nov 15, 2025
6b8eb18
heartBeat
Nov 15, 2025
946050f
Merge pull request #10 from mooiweertje/heartBeat
void-spark Nov 16, 2025
95a7983
Merge pull request #8 from mooiweertje/ADCOptimization
void-spark Nov 16, 2025
9e922f8
Add a bit of comments on the new adc code
void-spark Nov 16, 2025
e9c3b55
spiffsToLittlefs
Nov 19, 2025
0a0e7fe
heartBeat
mooiweertje Dec 17, 2025
f2dfaf1
esp_idf_version
Oct 6, 2025
c5deb27
LiFe8S
Oct 14, 2025
5aeae52
esp_idf_version_5.5.1
Nov 7, 2025
06250fe
quickMotorOff
Nov 6, 2025
7117dd5
ADCOptimization
Nov 11, 2025
7107f08
AmpADC1
Nov 15, 2025
3355c31
heartBeat
Nov 15, 2025
b1ce640
AmpADC2
Nov 21, 2025
c7b2d8c
AmpADC2
Nov 21, 2025
7945255
heartBeat
Nov 15, 2025
b426121
Add a bit of comments on the new adc code
void-spark Nov 16, 2025
ecd2030
heartBeat
mooiweertje Dec 17, 2025
dd0bbd1
Tesla config split
mooiweertje Dec 18, 2025
e542e69
backToSpiffsMergeFixes
mooiweertje Dec 22, 2025
41bde30
littlefs
mooiweertje Dec 22, 2025
e8ac218
heartBeat
mooiweertje Dec 23, 2025
2e36301
Merge branch 'heartBeat' into littlefs
mooiweertje Dec 23, 2025
20f848a
Merge pull request #11 from mooiweertje/spiffsToLittlefs
void-spark Dec 23, 2025
6fa0e5c
Merge pull request #13 from mooiweertje/heartBeat
void-spark Dec 23, 2025
872689e
littlefs
mooiweertje Dec 26, 2025
a0bc9e8
NVS
mooiweertje Dec 28, 2025
253d233
Amp measurement and more CU2v2
mooiweertje Jan 22, 2026
b814799
tinycleanup
mooiweertje Jul 31, 2026
733679f
bigShot
mooiweertje Jul 31, 2026
ac11139
bigShot
mooiweertje Jul 31, 2026
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
42 changes: 6 additions & 36 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,58 +15,28 @@ jobs:
matrix:
target: [esp32, esp32c3]
display: [cu2, cu3]
custom: [std]
include:
- target: esp32
display: cu3
custom: mike
- target: esp32
display: cu3
custom: wroom2xrelay
- target: esp32
display: cu2
custom: gpu7990
- target: esp32
display: cu3
custom: gpu7990
- target: esp32
display: cu2
custom: dvjcodec
- target: esp32
display: cu3
custom: dvjcodec
- target: esp32c3
display: cu2
custom: supermini
- target: esp32c3
display: cu3
custom: supermini
battery: [10Ah, 15Ah, 20Ah]
steps:
- name: Checkout repo
uses: actions/checkout@v3
with:
submodules: 'recursive'


# We should be able to use SDKCONFIG_DEFAULTS, but it seems to be broken, this also works.
# The echo makes sure there is a newline inbetween the original, and added part
- run: echo >> sdkconfig.defaults.${{ matrix.target }}; cat sdkconfig.${{ matrix.display }} >> sdkconfig.defaults.${{ matrix.target }}

- if: ${{ matrix.custom != 'std' }}
run: echo >> sdkconfig.defaults.${{ matrix.target }}; cat sdkconfig.${{ matrix.custom }} >> sdkconfig.defaults.${{ matrix.target }}
- run: echo >> sdkconfig.defaults.${{ matrix.target }}; cat sdkconfig.${{ matrix.display }} >> sdkconfig.defaults.${{ matrix.target }}; cat sdkconfig.${{ matrix.battery }} >> sdkconfig.defaults.${{ matrix.target }}

# Show used config
- run: cat sdkconfig.defaults.${{ matrix.target }}

- name: esp-idf build
uses: espressif/esp-idf-ci-action@v1
with:
esp_idf_version: latest
esp_idf_version: v5.5.1
target: ${{ matrix.target }}
path: ''
path: .

- uses: actions/upload-artifact@v4
with:
name: firmware-${{ matrix.target }}-${{ matrix.display }}-${{ matrix.custom }}
name: firmware-${{ matrix.target }}-${{ matrix.display }}-${{ matrix.battery }}
path: |
${{ github.workspace }}/build/bootloader/bootloader.bin
${{ github.workspace }}/build/partition_table/partition-table.bin
Expand Down
2 changes: 2 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
"includePath": [
"${workspaceFolder}/build/config",
"${workspaceFolder}/components/esp32-button/include",
"${workspaceFolder}/components/mqtt_helper/include",
"${workspaceFolder}/components/wifi_helper/include",
"${workspaceFolder}/main",
"${workspaceFolder}/sdk/idf/components/app_trace/include",
"${workspaceFolder}/sdk/idf/components/app_update/include",
Expand Down
1 change: 0 additions & 1 deletion buildscripts
Submodule buildscripts deleted from 2985ca
1 change: 0 additions & 1 deletion components/esp32-button
Submodule esp32-button deleted from d9154b
14 changes: 14 additions & 0 deletions components/esp32_button/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
if(IDF_VERSION_MAJOR GREATER_EQUAL 6)
idf_component_register(SRC_DIRS src
REQUIRES log driver esp_timer esp_driver_gpio
INCLUDE_DIRS include)
elseif(IDF_VERSION_MAJOR GREATER_EQUAL 4)
idf_component_register(SRC_DIRS src
REQUIRES log driver esp_timer
INCLUDE_DIRS include)
else()
set(COMPONENT_SRCDIRS src)
set(COMPONENT_ADD_INCLUDEDIRS include)
set(COMPONENT_REQUIRES log driver esp_timer)
register_component()
endif()
30 changes: 30 additions & 0 deletions components/esp32_button/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
menu "ESP32 Button"

config ESP32_BUTTON_LONG_PRESS_DURATION_MS
int "Button long press duration in ms"
default 2000
help
Defines how long a button has to be pressed to trigger BUTTON_HELD events.

config ESP32_BUTTON_LONG_PRESS_REPEAT_MS
int "Button long press repetition in ms"
default 50
help
Defines in which interval BUTTON_HELD events are generated while a button is long pressed.

config ESP32_BUTTON_QUEUE_SIZE
int "Size of the button event queue"
default 4
help
Defines how many button events the queue can store. If the queue is full because the events
are not retreived from the queue quickly enough, the button task has to wait and does not
process any button presses during this time.

config ESP32_BUTTON_TASK_STACK_SIZE
int "Button update task stack size"
default 1024
help
Configure the stack size of the button task in bytes. Reducing this value to 2048 should not
cause any problems.

endmenu
21 changes: 21 additions & 0 deletions components/esp32_button/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018 Craft Metrics Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
44 changes: 44 additions & 0 deletions components/esp32_button/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Button press detector

This implements a version of [THE ULTIMATE DEBOUNCER(TM) from hackaday](https://hackaday.com/2015/12/10/embed-with-elliot-debounce-your-noisy-buttons-part-ii/
).

It can monitor multiple pins, and sends button events over a queue for your application to process.

## Available input GPIO pins

Only the following pins can be used as inputs on the ESP32:

0-19, 21-23, 25-27, 32-39


## Example Usage

```c
button_event_t ev;
QueueHandle_t button_events = button_init(BIT64(BUTTON_1) | BIT64(BUTTON_2));
while (true) {
if (xQueueReceive(button_events, &ev, 1000/portTICK_PERIOD_MS)) {
if ((ev.pin == BUTTON_1) && (ev.event == BUTTON_DOWN)) {
// ...
}
if ((ev.pin == BUTTON_2) && (ev.event == BUTTON_DOWN)) {
// ...
}
}
}
```

## Event Types

### BUTTON_DOWN

Triggered when the button is first considered pressed.

### BUTTON_UP

Triggered when the button is considered released. In most cases you can use either the UP or DOWN event for your application, and ignore the other.

### BUTTON_HELD

Triggered starting after 2 seconds of long holding a button and then every 50ms thereafter.
2 changes: 2 additions & 0 deletions components/esp32_button/component.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
COMPONENT_ADD_INCLUDEDIRS = include
COMPONENT_SRCDIRS = src
43 changes: 43 additions & 0 deletions components/esp32_button/include/button.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#ifndef ESP32_BUTTON_H
#define ESP32_BUTTON_H

#include "freertos/queue.h"
#include "driver/gpio.h"

#ifndef CONFIG_ESP32_BUTTON_LONG_PRESS_DURATION_MS
#define CONFIG_ESP32_BUTTON_LONG_PRESS_DURATION_MS (2000)
#endif

#ifndef CONFIG_ESP32_BUTTON_LONG_PRESS_REPEAT_MS
#define CONFIG_ESP32_BUTTON_LONG_PRESS_REPEAT_MS (50)
#endif

#ifndef CONFIG_ESP32_BUTTON_QUEUE_SIZE
#define CONFIG_ESP32_BUTTON_QUEUE_SIZE (4)
#endif

#ifndef CONFIG_ESP32_BUTTON_TASK_STACK_SIZE
#define CONFIG_ESP32_BUTTON_TASK_STACK_SIZE 3072
#endif

#ifdef __cplusplus
extern "C" {
#endif

#define BUTTON_DOWN (1)
#define BUTTON_UP (2)
#define BUTTON_HELD (3)

typedef struct {
uint8_t pin;
uint8_t event;
} button_event_t;

QueueHandle_t button_init(unsigned long long pin_select);
QueueHandle_t pulled_button_init(unsigned long long pin_select, gpio_pull_mode_t pull_mode);

#ifdef __cplusplus
}
#endif

#endif
145 changes: 145 additions & 0 deletions components/esp32_button/src/button.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
#include <stdint.h>
#include <string.h>
#include <stdbool.h>
#include <stdio.h>

#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/queue.h"
#include "driver/gpio.h"
#include "esp_timer.h"
#include "esp_log.h"
#include "esp_timer.h"

#include "button.h"

#define TAG "BUTTON"

typedef struct {
uint8_t pin;
bool inverted;
uint16_t history;
uint32_t down_time;
uint32_t next_long_time;
} debounce_t;

static int pin_count = -1;
static debounce_t * debounce;
static QueueHandle_t queue;

static void update_button(debounce_t *d) {
d->history = (d->history << 1) | gpio_get_level(d->pin);
}

#define MASK 0b1111000000111111
static bool button_rose(debounce_t *d) {
if ((d->history & MASK) == 0b0000000000111111) {
d->history = 0xffff;
return 1;
}
return 0;
}
static bool button_fell(debounce_t *d) {
if ((d->history & MASK) == 0b1111000000000000) {
d->history = 0x0000;
return 1;
}
return 0;
}
static bool button_down(debounce_t *d) {
if (d->inverted) return button_fell(d);
return button_rose(d);
}
static bool button_up(debounce_t *d) {
if (d->inverted) return button_rose(d);
return button_fell(d);
}

static uint32_t millis() {
return esp_timer_get_time() / 1000;
}

static void send_event(debounce_t db, int ev) {
button_event_t event = {
.pin = db.pin,
.event = ev,
};
xQueueSend(queue, &event, portMAX_DELAY);
}

static void button_task(void *pvParameter)
{
for (;;) {
for (int idx=0; idx<pin_count; idx++) {
update_button(&debounce[idx]);
if (button_up(&debounce[idx])) {
debounce[idx].down_time = 0;
ESP_LOGD(TAG, "%d UP", debounce[idx].pin);
send_event(debounce[idx], BUTTON_UP);
} else if (debounce[idx].down_time && millis() >= debounce[idx].next_long_time) {
ESP_LOGD(TAG, "%d LONG", debounce[idx].pin);
debounce[idx].next_long_time = debounce[idx].next_long_time + CONFIG_ESP32_BUTTON_LONG_PRESS_REPEAT_MS;
send_event(debounce[idx], BUTTON_HELD);
} else if (button_down(&debounce[idx]) && debounce[idx].down_time == 0) {
debounce[idx].down_time = millis();
ESP_LOGD(TAG, "%d DOWN", debounce[idx].pin);
debounce[idx].next_long_time = debounce[idx].down_time + CONFIG_ESP32_BUTTON_LONG_PRESS_DURATION_MS;
send_event(debounce[idx], BUTTON_DOWN);
}
}
vTaskDelay(10/portTICK_PERIOD_MS);
}
}

QueueHandle_t button_init(unsigned long long pin_select) {
return pulled_button_init(pin_select, GPIO_FLOATING);
}


QueueHandle_t pulled_button_init(unsigned long long pin_select, gpio_pull_mode_t pull_mode)
{
if (pin_count != -1) {
ESP_LOGI(TAG, "Already initialized");
return NULL;
}

// Configure the pins
gpio_config_t io_conf;
io_conf.intr_type = GPIO_INTR_POSEDGE;
io_conf.mode = GPIO_MODE_INPUT;
io_conf.pull_up_en = (pull_mode == GPIO_PULLUP_ONLY || pull_mode == GPIO_PULLUP_PULLDOWN);
io_conf.pull_down_en = (pull_mode == GPIO_PULLDOWN_ONLY || pull_mode == GPIO_PULLUP_PULLDOWN);
io_conf.pin_bit_mask = pin_select;
io_conf.intr_type = GPIO_INTR_DISABLE;
gpio_config(&io_conf);

// Scan the pin map to determine number of pins
pin_count = 0;
for (int pin=0; pin<=39; pin++) {
if ((1ULL<<pin) & pin_select) {
pin_count++;
}
}

// Initialize global state and queue
debounce = calloc(pin_count, sizeof(debounce_t));
queue = xQueueCreate(CONFIG_ESP32_BUTTON_QUEUE_SIZE, sizeof(button_event_t));

// Scan the pin map to determine each pin number, populate the state
uint32_t idx = 0;
for (int pin=0; pin<=39; pin++) {
if ((1ULL<<pin) & pin_select) {
ESP_LOGI(TAG, "Registering button input: %d", pin);
debounce[idx].pin = pin;
debounce[idx].down_time = 0;
debounce[idx].inverted = true;
if (debounce[idx].inverted) debounce[idx].history = 0xffff;
idx++;
}
}

// Spawn a task to monitor the pins
xTaskCreate(&button_task, "button_task", CONFIG_ESP32_BUTTON_TASK_STACK_SIZE, NULL, 10, NULL);

return queue;
}
5 changes: 3 additions & 2 deletions main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
idf_component_register(SRC_DIRS "." "states"
PRIV_REQUIRES esp32-button nvs_flash esp_driver_uart esp_driver_gpio esp_adc esp_timer
INCLUDE_DIRS ".")
INCLUDE_DIRS "."
REQUIRES esp32_button driver esp_timer nvs_flash esp_adc
)
Loading
Loading