Compare commits
66
Commits
871fde8d3b
...
v0.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2ed8d3afeb | ||
|
|
d0d9957d2b | ||
|
|
f3c2013cdb | ||
|
|
68be452379 | ||
|
|
603494c105 | ||
|
|
df04669700 | ||
|
|
0813bb32f5 | ||
|
|
661fe6e013 | ||
|
|
5a0472e406 | ||
|
|
a9353e5c10 | ||
|
|
434b3c5df5 | ||
|
|
62cb4c6f06 | ||
|
|
28638b99f1 | ||
|
|
872e9bcb78 | ||
|
|
ac3a1f20b5 | ||
|
|
2537dba07a | ||
|
|
35602fb877 | ||
|
|
2ca785d6b2 | ||
|
|
192f2b1b21 | ||
|
|
2864c8289f | ||
|
|
be300f11ce | ||
|
|
fc4064d659 | ||
|
|
5fd7a23c38 | ||
|
|
a5d3120f3e | ||
|
|
dfba9a76d0 | ||
|
|
5973883a9b | ||
|
|
e47cf850e0 | ||
|
|
efb019f623 | ||
|
|
3d694be8a6 | ||
|
|
4b663faa7f | ||
|
|
2a4806eca5 | ||
|
|
e7553da18e | ||
|
|
b8ba94a78f | ||
|
|
415a64cba5 | ||
|
|
bd28b1a4b0 | ||
|
|
c6cb8fe2f0 | ||
|
|
134ac88cf0 | ||
|
|
2ef8fd4de8 | ||
|
|
33c4e1f8a2 | ||
|
|
be48b7601b | ||
|
|
ec4a0334f3 | ||
|
|
b8aac5c769 | ||
|
|
8de01c486c | ||
|
|
dbc20be3c7 | ||
|
|
c55952e84d | ||
|
|
d2413610ec | ||
|
|
c770c179b5 | ||
|
|
3cfa014200 | ||
|
|
d4eee81dba | ||
|
|
7acf008d8e | ||
|
|
a4e792b3c2 | ||
|
|
3ec593b2f6 | ||
|
|
20a7dc1d40 | ||
|
|
72f2566fe1 | ||
|
|
eeca3ea74d | ||
|
|
68909c4b73 | ||
|
|
e356794c79 | ||
|
|
a2c5d714bf | ||
|
|
69fbd04b53 | ||
|
|
eb62f27485 | ||
|
|
42dba0b758 | ||
|
|
f5fa26e196 | ||
|
|
6b37937b38 | ||
|
|
bf127eae13 | ||
|
|
dcbc700ce7 | ||
|
|
c387e27748 |
@@ -0,0 +1,62 @@
|
|||||||
|
name: "Espressif IoT Development Framework (ESP-IDF)"
|
||||||
|
description: "This action builds your firmware for ESP32 directly in GitHub using Espressif ESP-IDF Docker image."
|
||||||
|
branding:
|
||||||
|
color: red
|
||||||
|
icon: wifi
|
||||||
|
inputs:
|
||||||
|
path:
|
||||||
|
description: "Relative path under $GITHUB_WORKSPACE containing the project"
|
||||||
|
default: "."
|
||||||
|
required: false
|
||||||
|
esp_idf_version:
|
||||||
|
default: "latest"
|
||||||
|
required: false
|
||||||
|
esp_idf_docker_image:
|
||||||
|
default: "espressif/idf"
|
||||||
|
required: false
|
||||||
|
extra_docker_args:
|
||||||
|
default: ""
|
||||||
|
required: false
|
||||||
|
target:
|
||||||
|
default: "esp32"
|
||||||
|
required: false
|
||||||
|
command:
|
||||||
|
default: "idf.py build"
|
||||||
|
required: false
|
||||||
|
|
||||||
|
runs:
|
||||||
|
using: "composite"
|
||||||
|
steps:
|
||||||
|
- shell: bash
|
||||||
|
env:
|
||||||
|
INPUT_PATH: ${{ inputs.path }}
|
||||||
|
INPUT_TARGET: ${{ inputs.target }}
|
||||||
|
INPUT_VERSION: ${{ inputs.esp_idf_version }}
|
||||||
|
INPUT_IMAGE: ${{ inputs.esp_idf_docker_image }}
|
||||||
|
INPUT_EXTRA: ${{ inputs.extra_docker_args }}
|
||||||
|
INPUT_COMMAND: ${{ inputs.command }}
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
IDF_TARGET=$(echo "$INPUT_TARGET" | tr '[:upper:]' '[:lower:]' | tr -d '_-')
|
||||||
|
WORKDIR="/project/${INPUT_PATH}"
|
||||||
|
|
||||||
|
CID=$(docker create -t \
|
||||||
|
-e IDF_TARGET="$IDF_TARGET" \
|
||||||
|
-w "$WORKDIR" \
|
||||||
|
$INPUT_EXTRA \
|
||||||
|
"${INPUT_IMAGE}:${INPUT_VERSION}" \
|
||||||
|
/bin/bash -c "git config --global --add safe.directory '*' && ${INPUT_COMMAND}")
|
||||||
|
|
||||||
|
cleanup() { docker rm -f "$CID" >/dev/null 2>&1 || true; }
|
||||||
|
trap cleanup EXIT
|
||||||
|
|
||||||
|
docker cp "$GITHUB_WORKSPACE/." "$CID:/project"
|
||||||
|
|
||||||
|
status=0
|
||||||
|
docker start -a "$CID" || status=$?
|
||||||
|
|
||||||
|
# copy build output back so later steps (artifact upload etc.) can use it
|
||||||
|
mkdir -p "$GITHUB_WORKSPACE/${INPUT_PATH}"
|
||||||
|
docker cp "$CID:$WORKDIR/build/." "$GITHUB_WORKSPACE/${INPUT_PATH}/build" 2>/dev/null || true
|
||||||
|
|
||||||
|
exit $status
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
name: Build
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
pull_request:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
env:
|
||||||
|
PROJECT_BIN: "mcu-code.bin"
|
||||||
|
CHIP: esp32c6
|
||||||
|
steps:
|
||||||
|
- name: Checkout repo
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
submodules: 'recursive'
|
||||||
|
- name: esp-idf build
|
||||||
|
uses: ./.gitea/actions/esp-idf-ci-action
|
||||||
|
with:
|
||||||
|
esp_idf_version: v6.0.2
|
||||||
|
target: ${{env.CHIP}}
|
||||||
|
- name: Package firmware
|
||||||
|
if: startsWith(github.ref, 'refs/tags/')
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
NAME="firmware-${GITHUB_REF_NAME}"
|
||||||
|
|
||||||
|
mkdir -p "release/${NAME}/build/bootloader" "release/${NAME}/build/partition_table"
|
||||||
|
|
||||||
|
# Keep the build/ layout so "@flash_args" works after unzipping
|
||||||
|
cp build/bootloader/bootloader.bin "release/${NAME}/build/bootloader/"
|
||||||
|
cp build/partition_table/partition-table.bin "release/${NAME}/build/partition_table/"
|
||||||
|
cp "build/${PROJECT_BIN}" "release/${NAME}/build/"
|
||||||
|
cp build/flash_args "release/${NAME}/build/"
|
||||||
|
(cd release && zip -qr "${NAME}.zip" "${NAME}")
|
||||||
|
|
||||||
|
# Standalone copies
|
||||||
|
cp build/bootloader/bootloader.bin release/
|
||||||
|
cp build/partition_table/partition-table.bin release/
|
||||||
|
cp "build/${PROJECT_BIN}" release/
|
||||||
|
|
||||||
|
cat > release/notes.md <<EOF
|
||||||
|
## Flashing (${CHIP})
|
||||||
|
|
||||||
|
Requires [esptool](https://github.com/espressif/esptool) (\`pip install esptool\`).
|
||||||
|
|
||||||
|
**Option 1: with the individual files**
|
||||||
|
|
||||||
|
\`\`\`
|
||||||
|
python -m esptool --chip ${CHIP} -b 460800 --before default-reset --after hard-reset write-flash --flash-mode dio --flash-size 4MB --flash-freq 80m 0x0 build/bootloader/bootloader.bin 0x8000 build/partition_table/partition-table.bin 0x10000 build/${PROJECT_BIN}
|
||||||
|
\`\`\`
|
||||||
|
|
||||||
|
**Option 2: unzip \`${NAME}.zip\`, then from inside its \`build\` directory**
|
||||||
|
|
||||||
|
\`\`\`
|
||||||
|
python -m esptool --chip ${CHIP} -b 460800 --before default-reset --after hard-reset write-flash "@flash_args"
|
||||||
|
\`\`\`
|
||||||
|
EOF
|
||||||
|
|
||||||
|
- name: Create release
|
||||||
|
if: startsWith(github.ref, 'refs/tags/')
|
||||||
|
uses: actions/create-release@v1
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
with:
|
||||||
|
tag_name: ${{ github.ref }}
|
||||||
|
release_name: Release ${{ github.ref_name }}
|
||||||
|
body_path: release/notes.md
|
||||||
|
draft: false
|
||||||
|
prerelease: true
|
||||||
|
|
||||||
|
# actions/upload-release-asset relies on GitHub's templated upload_url, which Gitea
|
||||||
|
# doesn't provide, so attach the files through Gitea's API. The release ID is looked
|
||||||
|
# up by tag rather than taken from the step's outputs, because the old toolkit inside
|
||||||
|
# actions/create-release may emit outputs in a format Gitea's runner doesn't parse.
|
||||||
|
- name: Upload release assets
|
||||||
|
if: startsWith(github.ref, 'refs/tags/')
|
||||||
|
env:
|
||||||
|
TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
API="${GITHUB_API_URL:-${GITHUB_SERVER_URL}/api/v1}/repos/${GITHUB_REPOSITORY}"
|
||||||
|
|
||||||
|
RELEASE_ID=$(curl -fsS -H "Authorization: token ${TOKEN}" \
|
||||||
|
"${API}/releases/tags/${GITHUB_REF_NAME}" | jq -r .id)
|
||||||
|
|
||||||
|
for f in release/firmware-*.zip release/bootloader.bin release/partition-table.bin "release/${PROJECT_BIN}"; do
|
||||||
|
echo "Uploading $(basename "$f")"
|
||||||
|
curl -fsS -X POST "${API}/releases/${RELEASE_ID}/assets?name=$(basename "$f")" \
|
||||||
|
-H "Authorization: token ${TOKEN}" \
|
||||||
|
-F "attachment=@${f}" >/dev/null
|
||||||
|
done
|
||||||
+12
-1
@@ -1,2 +1,13 @@
|
|||||||
idf_component_register(SRCS mcu-code.cpp peripherals/usb_serial.cpp peripherals/usb_serial.h
|
idf_component_register(SRCS
|
||||||
|
mcu-code.cpp
|
||||||
|
peripherals/usb_serial.cpp
|
||||||
|
peripherals/usb_serial.h
|
||||||
|
peripherals/uart_serial.cpp
|
||||||
|
peripherals/uart_serial.h
|
||||||
|
peripherals/wireless_comms.cpp
|
||||||
|
peripherals/wireless_comms.h
|
||||||
|
peripherals/lp_uart_serial.cpp
|
||||||
|
peripherals/lp_uart_serial.h
|
||||||
|
oled_display/oled_display.cpp
|
||||||
|
oled_display/oled_display.h
|
||||||
INCLUDE_DIRS ".")
|
INCLUDE_DIRS ".")
|
||||||
|
|||||||
+60
-5
@@ -1,6 +1,8 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
|
#include "peripherals/uart_serial.h"
|
||||||
#include "peripherals/usb_serial.h"
|
#include "peripherals/usb_serial.h"
|
||||||
|
#include "peripherals/wireless_comms.h"
|
||||||
|
|
||||||
///
|
///
|
||||||
/// So i lost all the code from the previous version of this due to messing with git.
|
/// So i lost all the code from the previous version of this due to messing with git.
|
||||||
@@ -10,11 +12,64 @@
|
|||||||
/// Nicholas - 23/08/2026 @ 21:36
|
/// Nicholas - 23/08/2026 @ 21:36
|
||||||
///
|
///
|
||||||
|
|
||||||
const char* test = "amai zeg";
|
const char *test = "amai zeg\n";
|
||||||
|
|
||||||
|
#define NODE_NUMBER 1
|
||||||
|
#define TOTAL_NUMBER_OF_NODES 4
|
||||||
|
|
||||||
|
// release
|
||||||
|
|
||||||
|
|
||||||
extern "C" void app_main(void)
|
uint8_t node_mac[ESP_NOW_ETH_ALEN] = {0xDE, 0xD5, 0xEC, 0x00, 0x00, 0x02};
|
||||||
{
|
|
||||||
usb_serial::init();
|
uint8_t peer_mac[ESP_NOW_ETH_ALEN] = {0xDE, 0xD5, 0xEC, 0x00, 0x00, 0x01};
|
||||||
usb_serial::write(test,strlen(test));
|
|
||||||
|
uint8_t peer_list[TOTAL_NUMBER_OF_NODES][ESP_NOW_ETH_ALEN];
|
||||||
|
|
||||||
|
typedef struct communications {
|
||||||
|
uart_serial uart;
|
||||||
|
wireless_comms *wireless;
|
||||||
|
} communications;
|
||||||
|
|
||||||
|
|
||||||
|
void main_task(void *pvParameter) {
|
||||||
|
auto comms = reinterpret_cast<communications *>(pvParameter);
|
||||||
|
uart_serial uart = comms->uart;
|
||||||
|
char data;
|
||||||
|
while (true) {
|
||||||
|
if (usb_serial::read_byte(&data)) {
|
||||||
|
wireless_comms::send_byte(data);
|
||||||
|
uart.write_byte(&data);
|
||||||
|
}
|
||||||
|
if (uart.read_byte(&data)) {
|
||||||
|
ESP_LOGI("uart", "received data");
|
||||||
|
wireless_comms::send_byte(data);
|
||||||
|
usb_serial::write_byte(&data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" void app_main(void) {
|
||||||
|
esp_log_level_set("*", ESP_LOG_NONE);
|
||||||
|
usb_serial::init();
|
||||||
|
uart_serial uart(UART_NUM_0, GPIO_NUM_18, GPIO_NUM_19, 9600);
|
||||||
|
wireless_comms wireless;
|
||||||
|
|
||||||
|
//usb_serial::write(test,strlen(test));
|
||||||
|
communications comms = {.uart = uart, .wireless = &wireless};
|
||||||
|
/*
|
||||||
|
uint8_t peer_gen[ESP_NOW_ETH_ALEN] = {0xDE, 0xD5, 0xEC, 0x00, 0x00, 0x00};
|
||||||
|
for(int i=2;i<TOTAL_NUMBER_OF_NODES;i++) {
|
||||||
|
peer_gen[ESP_NOW_ETH_ALEN-1] = i;
|
||||||
|
memcpy(peer_list[i],peer_gen,ESP_NOW_ETH_ALEN);
|
||||||
|
test_comms.add_peer(peer_gen);
|
||||||
|
}*/
|
||||||
|
wireless_comms::add_peer(peer_mac);
|
||||||
|
//test_comms.add_peer(peer_mac);
|
||||||
|
wireless.create_rtos_task(uart);
|
||||||
|
wireless_comms::send_byte('e');
|
||||||
|
const char testchar = 'e';
|
||||||
|
uart.write_byte(&testchar);
|
||||||
|
|
||||||
|
xTaskCreate(main_task, "main_task", 4096, &comms, 5,NULL);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
//
|
||||||
|
// Created by nano on 9/25/26.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "oled_display.h"
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
//
|
||||||
|
// Created by nano on 9/25/26.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef MCU_CODE_OLED_DISPLAY_H
|
||||||
|
#define MCU_CODE_OLED_DISPLAY_H
|
||||||
|
|
||||||
|
|
||||||
|
class oled_display {
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif //MCU_CODE_OLED_DISPLAY_H
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
//
|
||||||
|
// Created by nano on 9/16/26.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "lp_uart_serial.h"
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
//
|
||||||
|
// Created by nano on 9/16/26.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef MCU_CODE_LP_UART_SERIAL_H
|
||||||
|
#define MCU_CODE_LP_UART_SERIAL_H
|
||||||
|
#include "lp_uart_serial.h"
|
||||||
|
#include "uart_serial.h"
|
||||||
|
|
||||||
|
|
||||||
|
class lp_uart_serial : public uart_serial {
|
||||||
|
public:
|
||||||
|
lp_uart_serial(const gpio_num_t tx = GPIO_NUM_NC,
|
||||||
|
const gpio_num_t rx = GPIO_NUM_NC,
|
||||||
|
int baudrate = 9600
|
||||||
|
) : uart_serial(LP_UART_NUM_0,tx,rx,baudrate) {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif //MCU_CODE_LP_UART_SERIAL_H
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
//
|
||||||
|
// Created by nano on 8/23/26.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "uart_serial.h"
|
||||||
|
|
||||||
|
#include "esp_err.h"
|
||||||
|
#include "driver/uart.h"
|
||||||
|
|
||||||
|
void uart_serial::init() {
|
||||||
|
ESP_ERROR_CHECK(uart_driver_install(uart_num, buffer_size * 2, buffer_size * 2, 10, &uart_queue, 0));
|
||||||
|
ESP_ERROR_CHECK(uart_param_config(uart_num, &uart_config));
|
||||||
|
|
||||||
|
ESP_ERROR_CHECK(
|
||||||
|
uart_set_pin(uart_num, tx_pin_num, rx_pin_num, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE,
|
||||||
|
UART_PIN_NO_CHANGE));
|
||||||
|
uart_flush(uart_num);
|
||||||
|
}
|
||||||
|
|
||||||
|
void uart_serial::write(const char* data, int len) {
|
||||||
|
uart_write_bytes(uart_num, data, len);
|
||||||
|
ESP_ERROR_CHECK(uart_wait_tx_done(uart_num, 100));
|
||||||
|
}
|
||||||
|
void uart_serial::write_byte(const char* data) {
|
||||||
|
uart_write_bytes(uart_num, data, 1);
|
||||||
|
ESP_ERROR_CHECK(uart_wait_tx_done(uart_num, 100));
|
||||||
|
}
|
||||||
|
|
||||||
|
int uart_serial::read(char* data, int size) {
|
||||||
|
int length = 0;
|
||||||
|
ESP_ERROR_CHECK(uart_get_buffered_data_len(uart_num,(size_t *) &length));
|
||||||
|
if (length > size) {
|
||||||
|
uart_read_bytes(uart_num,data,size,100);
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
uart_read_bytes(uart_num,data,length,100);
|
||||||
|
return length;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*int uart_serial::read_byte(char* data) {
|
||||||
|
int length = 0;
|
||||||
|
ESP_LOGI("sanity check","uart num: %d",uart_num);
|
||||||
|
ESP_ERROR_CHECK(uart_get_buffered_data_len(uart_num,(size_t *) &length));
|
||||||
|
if (length) {
|
||||||
|
uart_read_bytes(uart_num,data,1,100);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}*/
|
||||||
|
|
||||||
|
int uart_serial::read_byte(char* data) {
|
||||||
|
size_t length = 0;
|
||||||
|
esp_err_t err = uart_get_buffered_data_len(this->uart_num, &length);
|
||||||
|
if (err != ESP_OK) {
|
||||||
|
ESP_LOGE("uart_serial", "get_buffered_data_len failed on port %d: %s",
|
||||||
|
uart_num, esp_err_to_name(err));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (length > 0) {
|
||||||
|
int n = uart_read_bytes(uart_num, data, 1, pdMS_TO_TICKS(100));
|
||||||
|
return (n == 1) ? 1 : 0;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
//
|
||||||
|
// Created by nano on 8/23/26.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef MCU_CODE_UART_SERIAL_H
|
||||||
|
#define MCU_CODE_UART_SERIAL_H
|
||||||
|
#include "driver/uart.h"
|
||||||
|
#include "freertos/queue.h"
|
||||||
|
#include "hal/uart_types.h"
|
||||||
|
#include "freertos/FreeRTOS.h"
|
||||||
|
#include "freertos/task.h"
|
||||||
|
#include "driver/uart.h"
|
||||||
|
#include "driver/gpio.h"
|
||||||
|
#include "sdkconfig.h"
|
||||||
|
#include "esp_log.h"
|
||||||
|
|
||||||
|
class uart_serial {
|
||||||
|
public:
|
||||||
|
explicit uart_serial(uart_port_t uart_port_num = UART_NUM_0, const gpio_num_t tx = GPIO_NUM_NC,
|
||||||
|
const gpio_num_t rx = GPIO_NUM_NC, int baudrate = 9600) : uart_num(uart_port_num), tx_pin_num(tx),
|
||||||
|
rx_pin_num(rx) {
|
||||||
|
uart_config.baud_rate = baudrate;
|
||||||
|
uart_config.data_bits = UART_DATA_8_BITS;
|
||||||
|
uart_config.parity = UART_PARITY_DISABLE;
|
||||||
|
uart_config.stop_bits = UART_STOP_BITS_1;
|
||||||
|
uart_config.flow_ctrl = UART_HW_FLOWCTRL_DISABLE;
|
||||||
|
|
||||||
|
init();
|
||||||
|
};
|
||||||
|
|
||||||
|
void uart_serial_dtor() const {
|
||||||
|
uart_driver_delete(uart_num);
|
||||||
|
}
|
||||||
|
void write(const char* data, int len);
|
||||||
|
void write_byte(const char* data);
|
||||||
|
|
||||||
|
int read(char* data,int len);
|
||||||
|
int read_byte(char* data);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void init();
|
||||||
|
|
||||||
|
QueueHandle_t uart_queue = {};
|
||||||
|
const uart_port_t uart_num;
|
||||||
|
uart_config_t uart_config = {};
|
||||||
|
const gpio_num_t tx_pin_num;
|
||||||
|
const gpio_num_t rx_pin_num;
|
||||||
|
constexpr static int buffer_size = (1024);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif //MCU_CODE_UART_SERIAL_H
|
||||||
@@ -16,7 +16,6 @@ void usb_serial::init() {
|
|||||||
};
|
};
|
||||||
ESP_ERROR_CHECK(usb_serial_jtag_driver_install(&usb_serial_jtag_config));
|
ESP_ERROR_CHECK(usb_serial_jtag_driver_install(&usb_serial_jtag_config));
|
||||||
ESP_LOGI("usb_serial", "USB_SERIAL_JTAG init done");
|
ESP_LOGI("usb_serial", "USB_SERIAL_JTAG init done");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void usb_serial::write(const char* byte, int len) {
|
void usb_serial::write(const char* byte, int len) {
|
||||||
|
|||||||
@@ -9,12 +9,12 @@
|
|||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
namespace usb_serial {
|
namespace usb_serial {
|
||||||
static void write(const char* byte, int len);
|
void write(const char* byte, int len);
|
||||||
static int read(char* byte,int len);
|
int read(char* byte,int len);
|
||||||
|
|
||||||
static void write_byte(char* byte);
|
void write_byte(char* byte);
|
||||||
static int read_byte(char* byte);
|
int read_byte(char* byte);
|
||||||
static void init();
|
void init();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,283 @@
|
|||||||
|
//
|
||||||
|
// Created by nano on 8/23/26.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "wireless_comms.h"
|
||||||
|
|
||||||
|
#include "esp_err.h"
|
||||||
|
#include "esp_log.h"
|
||||||
|
#include "esp_netif.h"
|
||||||
|
#include "esp_now.h"
|
||||||
|
#include "esp_wifi.h"
|
||||||
|
#include "esp_crc.h"
|
||||||
|
#include "esp_mac.h"
|
||||||
|
#include "esp_random.h"
|
||||||
|
#include "usb_serial.h"
|
||||||
|
|
||||||
|
const char *TAG = "wireless_comms";
|
||||||
|
|
||||||
|
#define ESPNOW_MAXDELAY 512
|
||||||
|
|
||||||
|
static QueueHandle_t espnow_send_queue = NULL;
|
||||||
|
|
||||||
|
static uint8_t s_broadcast_mac[ESP_NOW_ETH_ALEN] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
|
||||||
|
extern uint8_t node_mac[ESP_NOW_ETH_ALEN];
|
||||||
|
|
||||||
|
void wireless_comms::wifi_init(int channel) {
|
||||||
|
ESP_ERROR_CHECK(esp_netif_init());
|
||||||
|
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
||||||
|
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||||
|
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
|
||||||
|
ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_RAM));
|
||||||
|
ESP_ERROR_CHECK(esp_wifi_set_mode(ESPNOW_WIFI_MODE));
|
||||||
|
ESP_ERROR_CHECK(esp_wifi_set_mac(ESPNOW_WIFI_IF,node_mac));
|
||||||
|
ESP_ERROR_CHECK(esp_wifi_start());
|
||||||
|
ESP_ERROR_CHECK(esp_wifi_set_channel(channel, WIFI_SECOND_CHAN_NONE));
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef CONFIG_ESPNOW_ENABLE_LONG_RANGE
|
||||||
|
ESP_ERROR_CHECK(
|
||||||
|
esp_wifi_set_protocol(ESPNOW_WIFI_IF, WIFI_PROTOCOL_11B|WIFI_PROTOCOL_11G|WIFI_PROTOCOL_11N|WIFI_PROTOCOL_LR));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void wireless_comms::espnow_send_callback(const esp_now_send_info_t *tx_info, esp_now_send_status_t status) {
|
||||||
|
espnow_event_t evt;
|
||||||
|
espnow_event_send_cb_t *send_cb = &evt.info.send_cb;
|
||||||
|
|
||||||
|
if (tx_info == NULL) {
|
||||||
|
ESP_LOGE(TAG, "Send cb arg error");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
evt.id = ESPNOW_SEND_CB;
|
||||||
|
memcpy(send_cb->mac_addr, tx_info->des_addr, ESP_NOW_ETH_ALEN);
|
||||||
|
send_cb->status = status;
|
||||||
|
if (xQueueSend(espnow_send_queue, &evt, ESPNOW_MAXDELAY) != pdTRUE) {
|
||||||
|
ESP_LOGW(TAG, "Send send queue fail");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void wireless_comms::espnow_recv_callback(const esp_now_recv_info_t *recv_info, const uint8_t *data, int len) {
|
||||||
|
espnow_event_t evt;
|
||||||
|
espnow_event_recv_cb_t *recv_cb = &evt.info.recv_cb;
|
||||||
|
uint8_t *mac_addr = recv_info->src_addr;
|
||||||
|
|
||||||
|
if (mac_addr == NULL || data == NULL || len <= 0) {
|
||||||
|
ESP_LOGE(TAG, "Receive cb arg error");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
evt.id = ESPNOW_RECV_CB;
|
||||||
|
memcpy(recv_cb->mac_addr, mac_addr, ESP_NOW_ETH_ALEN);
|
||||||
|
recv_cb->data = (uint8_t *) malloc(len);
|
||||||
|
if (recv_cb->data == NULL) {
|
||||||
|
ESP_LOGE(TAG, "Malloc receive data fail");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
memcpy(recv_cb->data, data, len);
|
||||||
|
recv_cb->data_len = len;
|
||||||
|
if (xQueueSend(espnow_send_queue, &evt, ESPNOW_MAXDELAY) != pdTRUE) {
|
||||||
|
ESP_LOGW(TAG, "Send receive queue fail");
|
||||||
|
free(recv_cb->data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Parse received ESPNOW data. */
|
||||||
|
int wireless_comms::espnow_data_parse(uint8_t *data, uint16_t data_len) {
|
||||||
|
auto *buf = (espnow_data_t *) data;
|
||||||
|
uint16_t crc, crc_cal = 0;
|
||||||
|
|
||||||
|
if (data_len < sizeof(espnow_data_t)) {
|
||||||
|
ESP_LOGE(TAG, "Receive ESPNOW data too short, len:%d", data_len);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
crc = buf->crc;
|
||||||
|
buf->crc = 0;
|
||||||
|
crc_cal = esp_crc16_le(UINT16_MAX, (uint8_t const *) buf, data_len);
|
||||||
|
|
||||||
|
if (crc_cal == crc) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Prepare ESPNOW data to be sent. */
|
||||||
|
void wireless_comms::espnow_send_data_prepare(espnow_send_param_t *send_param) {
|
||||||
|
espnow_data_t *buf = (espnow_data_t *) send_param->buffer;
|
||||||
|
assert(send_param->len >= sizeof(espnow_data_t));
|
||||||
|
buf->crc = 0;
|
||||||
|
buf->crc = esp_crc16_le(UINT16_MAX, (uint8_t const *) buf, send_param->len);
|
||||||
|
ESP_LOGI("espnow send_data_prepare", "%d %s", send_param->len - sizeof(espnow_data_t), buf->payload);
|
||||||
|
}
|
||||||
|
|
||||||
|
esp_err_t wireless_comms::espnow_init(int wifi_channel) {
|
||||||
|
// Create send queue
|
||||||
|
espnow_send_queue = xQueueCreate(ESPNOW_QUEUE_SIZE, sizeof(espnow_event_t));
|
||||||
|
if (espnow_send_queue == NULL) {
|
||||||
|
ESP_LOGE(TAG, "Create queue fail");
|
||||||
|
return ESP_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Initialize ESPNOW and register sending and receiving callback function. */
|
||||||
|
ESP_ERROR_CHECK(esp_now_init());
|
||||||
|
ESP_ERROR_CHECK(esp_now_register_send_cb(espnow_send_callback));
|
||||||
|
ESP_ERROR_CHECK(esp_now_register_recv_cb(espnow_recv_callback));
|
||||||
|
#if CONFIG_ESPNOW_ENABLE_POWER_SAVE
|
||||||
|
ESP_ERROR_CHECK(esp_now_set_wake_window(CONFIG_ESPNOW_WAKE_WINDOW));
|
||||||
|
ESP_ERROR_CHECK(esp_wifi_connectionless_module_set_wake_interval(CONFIG_ESPNOW_WAKE_INTERVAL));
|
||||||
|
#endif
|
||||||
|
/* Set primary master key. */
|
||||||
|
ESP_ERROR_CHECK(esp_now_set_pmk((uint8_t *)ESPNOW_PMK));
|
||||||
|
|
||||||
|
/* Add broadcast peer information to peer list. */
|
||||||
|
auto *peer = static_cast<esp_now_peer_info_t *>(malloc(sizeof(esp_now_peer_info_t)));
|
||||||
|
if (peer == NULL) {
|
||||||
|
ESP_LOGE(TAG, "Malloc peer information fail");
|
||||||
|
vQueueDelete(espnow_send_queue);
|
||||||
|
espnow_send_queue = NULL;
|
||||||
|
esp_now_deinit();
|
||||||
|
return ESP_FAIL;
|
||||||
|
}
|
||||||
|
memset(peer, 0, sizeof(esp_now_peer_info_t));
|
||||||
|
peer->channel = wifi_channel;
|
||||||
|
peer->ifidx = ESPNOW_WIFI_IF;
|
||||||
|
peer->encrypt = false;
|
||||||
|
memcpy(peer->peer_addr, s_broadcast_mac, ESP_NOW_ETH_ALEN);
|
||||||
|
ESP_ERROR_CHECK(esp_now_add_peer(peer));
|
||||||
|
free(peer);
|
||||||
|
|
||||||
|
/* Initialize sending parameters. */
|
||||||
|
send_param = (espnow_send_param_t *) malloc(sizeof(espnow_send_param_t));
|
||||||
|
if (send_param == NULL) {
|
||||||
|
ESP_LOGE(TAG, "Malloc send parameter fail");
|
||||||
|
vQueueDelete(espnow_send_queue);
|
||||||
|
espnow_send_queue = NULL;
|
||||||
|
esp_now_deinit();
|
||||||
|
return ESP_FAIL;
|
||||||
|
}
|
||||||
|
memset(send_param, 0, sizeof(espnow_send_param_t));
|
||||||
|
send_param->buffer = (uint8_t *) malloc(ESPNOW_SEND_LEN);
|
||||||
|
send_param->len = ESPNOW_SEND_LEN;
|
||||||
|
if (send_param->buffer == NULL) {
|
||||||
|
ESP_LOGE(TAG, "Malloc send buffer fail");
|
||||||
|
free(send_param);
|
||||||
|
vQueueDelete(espnow_send_queue);
|
||||||
|
espnow_send_queue = NULL;
|
||||||
|
esp_now_deinit();
|
||||||
|
return ESP_FAIL;
|
||||||
|
}
|
||||||
|
memcpy(send_param->dest_mac, s_broadcast_mac, ESP_NOW_ETH_ALEN);
|
||||||
|
espnow_send_data_prepare(send_param);
|
||||||
|
|
||||||
|
return ESP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wireless_comms::espnow_deinit(espnow_send_param_t *send_param) {
|
||||||
|
free(send_param->buffer);
|
||||||
|
free(send_param);
|
||||||
|
vQueueDelete(espnow_send_queue);
|
||||||
|
espnow_send_queue = NULL;
|
||||||
|
esp_now_deinit();
|
||||||
|
}
|
||||||
|
|
||||||
|
void wireless_comms::espnow_task(void *pvParameter) {
|
||||||
|
espnow_event_t evt;
|
||||||
|
int ret;
|
||||||
|
auto task_params = (espnow_task_params_t *) pvParameter;
|
||||||
|
espnow_send_param_t send_param = *task_params->send_param;
|
||||||
|
uart_serial uart = task_params->uart;
|
||||||
|
vTaskDelay(5000 / portTICK_PERIOD_MS);
|
||||||
|
|
||||||
|
while (xQueueReceive(espnow_send_queue, &evt, portMAX_DELAY) == pdPASS) {
|
||||||
|
switch (evt.id) {
|
||||||
|
case ESPNOW_SEND_CB: {
|
||||||
|
espnow_event_send_cb_t *send_cb = &evt.info.send_cb;
|
||||||
|
/* Delay a while before sending the next data. */
|
||||||
|
ESP_LOGI(TAG, "send data to " MACSTR "", MAC2STR(send_cb->mac_addr));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ESPNOW_RECV_CB: {
|
||||||
|
espnow_event_recv_cb_t *recv_cb = &evt.info.recv_cb;
|
||||||
|
|
||||||
|
ret = espnow_data_parse(recv_cb->data, recv_cb->data_len);
|
||||||
|
if (ret == 1) {
|
||||||
|
auto *rx = (espnow_data_t *) recv_cb->data;
|
||||||
|
ESP_LOGI(TAG, "Receive data from: " MACSTR ", len: %d, byte0: 0x%02x",
|
||||||
|
MAC2STR(recv_cb->mac_addr), recv_cb->data_len, rx->payload[0]);
|
||||||
|
usb_serial::write(reinterpret_cast<const char *>(&rx->payload), PAYLOAD_SIZE);
|
||||||
|
uart.write(reinterpret_cast<const char *>(&rx->payload), PAYLOAD_SIZE);
|
||||||
|
} else {
|
||||||
|
ESP_LOGI(TAG, "Receive error (bad CRC) from: " MACSTR "", MAC2STR(recv_cb->mac_addr));
|
||||||
|
}
|
||||||
|
free(recv_cb->data);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
ESP_LOGE(TAG, "Callback type error: %d", evt.id);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ESP_LOGI(TAG,"ENDED TASK WIRELESS");
|
||||||
|
}
|
||||||
|
|
||||||
|
void wireless_comms::set_dest_mac(const uint8_t dest_mac[ESP_NOW_ETH_ALEN]) {
|
||||||
|
ESP_ERROR_CHECK(add_peer(dest_mac));
|
||||||
|
memcpy(send_param->dest_mac, dest_mac, ESP_NOW_ETH_ALEN);
|
||||||
|
espnow_send_data_prepare(send_param);
|
||||||
|
}
|
||||||
|
|
||||||
|
esp_err_t wireless_comms::add_peer(const uint8_t dest_mac[ESP_NOW_ETH_ALEN]) {
|
||||||
|
auto *peer = static_cast<esp_now_peer_info_t *>(malloc(sizeof(esp_now_peer_info_t)));
|
||||||
|
if (peer == NULL) {
|
||||||
|
ESP_LOGE(TAG, "Malloc peer information fail");
|
||||||
|
vQueueDelete(espnow_send_queue);
|
||||||
|
espnow_send_queue = NULL;
|
||||||
|
esp_now_deinit();
|
||||||
|
return ESP_FAIL;
|
||||||
|
}
|
||||||
|
memset(peer, 0, sizeof(esp_now_peer_info_t));
|
||||||
|
peer->channel = ESPNOW_CHANNEL;
|
||||||
|
peer->ifidx = ESPNOW_WIFI_IF;
|
||||||
|
peer->encrypt = false;
|
||||||
|
memcpy(peer->peer_addr, dest_mac, ESP_NOW_ETH_ALEN);
|
||||||
|
ESP_ERROR_CHECK(esp_now_add_peer(peer));
|
||||||
|
free(peer);
|
||||||
|
ESP_LOGI(TAG, "Peer " MACSTR " added", MAC2STR(dest_mac));
|
||||||
|
return ESP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wireless_comms::delete_peer(const uint8_t dest_mac[ESP_NOW_ETH_ALEN]) {
|
||||||
|
ESP_ERROR_CHECK(esp_now_del_peer(dest_mac));
|
||||||
|
}
|
||||||
|
|
||||||
|
esp_err_t wireless_comms::send_byte(uint8_t data) {
|
||||||
|
auto send_parameters = (espnow_send_param_t *) malloc(sizeof(espnow_send_param_t));
|
||||||
|
memset(send_parameters, 0, sizeof(espnow_send_param_t));
|
||||||
|
send_parameters->len = sizeof(espnow_data_t);
|
||||||
|
send_parameters->buffer = (uint8_t *) malloc(sizeof(espnow_data_t));
|
||||||
|
if (send_parameters->buffer == NULL) {
|
||||||
|
ESP_LOGE(TAG, "Malloc send buffer fail");
|
||||||
|
free(send_parameters);
|
||||||
|
vQueueDelete(espnow_send_queue);
|
||||||
|
espnow_send_queue = NULL;
|
||||||
|
esp_now_deinit();
|
||||||
|
return ESP_FAIL;
|
||||||
|
}
|
||||||
|
((espnow_data_t *) (send_parameters->buffer))->payload[0] = data; // i am disgusted at myself
|
||||||
|
memset(((espnow_data_t *) (send_parameters->buffer))->payload + 1, 0,PAYLOAD_SIZE - 1);
|
||||||
|
// fill the rest of the payload with zeroes
|
||||||
|
|
||||||
|
memcpy(send_parameters->dest_mac, s_broadcast_mac, ESP_NOW_ETH_ALEN); // TODO: THIS IS IGNORED FOR NOW
|
||||||
|
espnow_send_data_prepare(send_parameters);
|
||||||
|
if (esp_now_send(NULL, send_parameters->buffer, send_parameters->len) != ESP_OK) {
|
||||||
|
// send to all peers
|
||||||
|
ESP_LOGE(TAG, "Send error");
|
||||||
|
espnow_deinit(send_parameters);
|
||||||
|
}
|
||||||
|
free(send_parameters);
|
||||||
|
ESP_LOGI(TAG, "SENT DATA");
|
||||||
|
return ESP_OK;
|
||||||
|
}
|
||||||
@@ -0,0 +1,137 @@
|
|||||||
|
//
|
||||||
|
// Created by nano on 8/23/26.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef MCU_CODE_WIRELESS_COMMS_H
|
||||||
|
#define MCU_CODE_WIRELESS_COMMS_H
|
||||||
|
#include "esp_now.h"
|
||||||
|
#include "nvs_flash.h"
|
||||||
|
#include "uart_serial.h"
|
||||||
|
#include "freertos/FreeRTOS.h"
|
||||||
|
#include "freertos/task.h"
|
||||||
|
|
||||||
|
#define PAYLOAD_SIZE 1
|
||||||
|
|
||||||
|
#define ESPNOW_PMK "pmk1234567890123" // ESPNOW primary master for the example to use. The length of ESPNOW primary master must be 16 bytes.
|
||||||
|
#define ESPNOW_LMK "lmk1234567890123" // ESPNOW local master for the example to use. The length of ESPNOW local master must be 16 bytes.
|
||||||
|
#define ESPNOW_SEND_COUNT 1 // range 1-65535; Total count of unicast ESPNOW data to be sent.
|
||||||
|
#define ESPNOW_SEND_DELAY 0 // range 0-65535; default 1000; Delay between sending two ESPNOW data, unit: ms.
|
||||||
|
#define ESPNOW_SEND_LEN (2 + PAYLOAD_SIZE) // range 10-1470; Length of ESPNOW data to be sent, unit: byte.
|
||||||
|
|
||||||
|
#define ESPNOW_CHANNEL 11
|
||||||
|
#define ESPNOW_QUEUE_SIZE 512
|
||||||
|
|
||||||
|
#define CONFIG_ESPNOW_ENABLE_LONG_RANGE
|
||||||
|
#define CONFIG_ESPNOW_WIFI_MODE_STATION
|
||||||
|
// #define CONFIG_ESPNOW_ENABLE_POWER_SAVE
|
||||||
|
|
||||||
|
#ifdef CONFIG_ESPNOW_WIFI_MODE_STATION
|
||||||
|
#define ESPNOW_WIFI_MODE WIFI_MODE_STA
|
||||||
|
#define ESPNOW_WIFI_IF WIFI_IF_STA
|
||||||
|
#else
|
||||||
|
#define ESPNOW_WIFI_MODE WIFI_MODE_AP
|
||||||
|
#define ESPNOW_WIFI_IF WIFI_IF_AP
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#define IS_BROADCAST_ADDR(addr) (memcmp(addr, s_broadcast_mac, ESP_NOW_ETH_ALEN) == 0)
|
||||||
|
|
||||||
|
enum {
|
||||||
|
ESPNOW_DATA_BROADCAST,
|
||||||
|
ESPNOW_DATA_UNICAST,
|
||||||
|
ESPNOW_DATA_MAX,
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
ESPNOW_SEND_CB,
|
||||||
|
ESPNOW_RECV_CB,
|
||||||
|
} espnow_event_id_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint8_t mac_addr[ESP_NOW_ETH_ALEN];
|
||||||
|
esp_now_send_status_t status;
|
||||||
|
} espnow_event_send_cb_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint8_t mac_addr[ESP_NOW_ETH_ALEN];
|
||||||
|
uint8_t *data;
|
||||||
|
int data_len;
|
||||||
|
} espnow_event_recv_cb_t;
|
||||||
|
|
||||||
|
typedef union {
|
||||||
|
espnow_event_send_cb_t send_cb;
|
||||||
|
espnow_event_recv_cb_t recv_cb;
|
||||||
|
} espnow_event_info_t;
|
||||||
|
|
||||||
|
/* When ESPNOW sending or receiving callback function is called, post event to ESPNOW task. */
|
||||||
|
typedef struct {
|
||||||
|
espnow_event_id_t id;
|
||||||
|
espnow_event_info_t info;
|
||||||
|
} espnow_event_t;
|
||||||
|
|
||||||
|
/* User defined field of ESPNOW data in this example. */
|
||||||
|
typedef struct {
|
||||||
|
uint16_t crc; //CRC16 value of ESPNOW data.
|
||||||
|
uint8_t payload[PAYLOAD_SIZE]; //Real payload of ESPNOW data.
|
||||||
|
} __attribute__((packed)) espnow_data_t;
|
||||||
|
|
||||||
|
/* Parameters of sending ESPNOW data. */
|
||||||
|
typedef struct {
|
||||||
|
int len; //Length of ESPNOW data to be sent, unit: byte.
|
||||||
|
uint8_t *buffer; //Buffer pointing to ESPNOW data.
|
||||||
|
uint8_t dest_mac[ESP_NOW_ETH_ALEN]; //MAC address of destination device.
|
||||||
|
} espnow_send_param_t;
|
||||||
|
|
||||||
|
typedef struct espnow_task_params_t {
|
||||||
|
espnow_send_param_t *send_param;
|
||||||
|
uart_serial uart;
|
||||||
|
|
||||||
|
} espnow_task_params_t;
|
||||||
|
|
||||||
|
class wireless_comms {
|
||||||
|
public:
|
||||||
|
wireless_comms(int wifi_channel = ESPNOW_CHANNEL) {
|
||||||
|
// Initialize NVS
|
||||||
|
esp_err_t ret = nvs_flash_init();
|
||||||
|
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
||||||
|
ESP_ERROR_CHECK( nvs_flash_erase() );
|
||||||
|
ret = nvs_flash_init();
|
||||||
|
}
|
||||||
|
ESP_ERROR_CHECK( ret );
|
||||||
|
|
||||||
|
wifi_init(wifi_channel);
|
||||||
|
espnow_init(wifi_channel);
|
||||||
|
}
|
||||||
|
void set_dest_mac(const uint8_t dest_mac[ESP_NOW_ETH_ALEN]);
|
||||||
|
void create_rtos_task(const uart_serial &uart) const {
|
||||||
|
auto *task_params = new espnow_task_params_t{.send_param = send_param, .uart = uart}; // heap, outlives this call
|
||||||
|
xTaskCreate(espnow_task, "espnow_task", 2048, task_params, 4, NULL);
|
||||||
|
// note: task_params is intentionally leaked for the task's lifetime;
|
||||||
|
// free it inside espnow_task if the task can ever exit
|
||||||
|
}
|
||||||
|
|
||||||
|
static esp_err_t add_peer(const uint8_t dest_mac[ESP_NOW_ETH_ALEN]);
|
||||||
|
static void delete_peer(const uint8_t dest_mac[ESP_NOW_ETH_ALEN]);
|
||||||
|
|
||||||
|
static esp_err_t send_byte(uint8_t data) ;
|
||||||
|
private:
|
||||||
|
|
||||||
|
espnow_send_param_t * send_param = nullptr;
|
||||||
|
static void wifi_init(int channel);
|
||||||
|
|
||||||
|
static void espnow_send_callback(const esp_now_send_info_t *tx_info, esp_now_send_status_t status);
|
||||||
|
|
||||||
|
static void espnow_recv_callback(const esp_now_recv_info_t *recv_info, const uint8_t *data, int len);
|
||||||
|
|
||||||
|
static int espnow_data_parse(uint8_t *data, uint16_t data_len);
|
||||||
|
|
||||||
|
static void espnow_send_data_prepare(espnow_send_param_t *send_param);
|
||||||
|
|
||||||
|
esp_err_t espnow_init(int wifi_channel);
|
||||||
|
|
||||||
|
static void espnow_deinit(espnow_send_param_t *send_param);
|
||||||
|
static void espnow_task(void *pvParameter);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif //MCU_CODE_WIRELESS_COMMS_H
|
||||||
@@ -792,20 +792,14 @@ CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_SIZE=y
|
|||||||
CONFIG_BOOTLOADER_LOG_VERSION_1=y
|
CONFIG_BOOTLOADER_LOG_VERSION_1=y
|
||||||
# default:
|
# default:
|
||||||
CONFIG_BOOTLOADER_LOG_VERSION=1
|
CONFIG_BOOTLOADER_LOG_VERSION=1
|
||||||
# default:
|
CONFIG_BOOTLOADER_LOG_LEVEL_NONE=y
|
||||||
# CONFIG_BOOTLOADER_LOG_LEVEL_NONE is not set
|
|
||||||
# default:
|
|
||||||
# CONFIG_BOOTLOADER_LOG_LEVEL_ERROR is not set
|
# CONFIG_BOOTLOADER_LOG_LEVEL_ERROR is not set
|
||||||
# default:
|
|
||||||
# CONFIG_BOOTLOADER_LOG_LEVEL_WARN is not set
|
# CONFIG_BOOTLOADER_LOG_LEVEL_WARN is not set
|
||||||
# default:
|
# CONFIG_BOOTLOADER_LOG_LEVEL_INFO is not set
|
||||||
CONFIG_BOOTLOADER_LOG_LEVEL_INFO=y
|
|
||||||
# default:
|
|
||||||
# CONFIG_BOOTLOADER_LOG_LEVEL_DEBUG is not set
|
# CONFIG_BOOTLOADER_LOG_LEVEL_DEBUG is not set
|
||||||
# default:
|
|
||||||
# CONFIG_BOOTLOADER_LOG_LEVEL_VERBOSE is not set
|
# CONFIG_BOOTLOADER_LOG_LEVEL_VERBOSE is not set
|
||||||
# default:
|
# default:
|
||||||
CONFIG_BOOTLOADER_LOG_LEVEL=3
|
CONFIG_BOOTLOADER_LOG_LEVEL=0
|
||||||
|
|
||||||
#
|
#
|
||||||
# Format
|
# Format
|
||||||
@@ -1008,24 +1002,16 @@ CONFIG_ESPTOOLPY_FLASHFREQ_80M=y
|
|||||||
# CONFIG_ESPTOOLPY_FLASHFREQ_20M is not set
|
# CONFIG_ESPTOOLPY_FLASHFREQ_20M is not set
|
||||||
# default:
|
# default:
|
||||||
CONFIG_ESPTOOLPY_FLASHFREQ="80m"
|
CONFIG_ESPTOOLPY_FLASHFREQ="80m"
|
||||||
# default:
|
|
||||||
# CONFIG_ESPTOOLPY_FLASHSIZE_1MB is not set
|
# CONFIG_ESPTOOLPY_FLASHSIZE_1MB is not set
|
||||||
# default:
|
# CONFIG_ESPTOOLPY_FLASHSIZE_2MB is not set
|
||||||
CONFIG_ESPTOOLPY_FLASHSIZE_2MB=y
|
CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
|
||||||
# default:
|
|
||||||
# CONFIG_ESPTOOLPY_FLASHSIZE_4MB is not set
|
|
||||||
# default:
|
|
||||||
# CONFIG_ESPTOOLPY_FLASHSIZE_8MB is not set
|
# CONFIG_ESPTOOLPY_FLASHSIZE_8MB is not set
|
||||||
# default:
|
|
||||||
# CONFIG_ESPTOOLPY_FLASHSIZE_16MB is not set
|
# CONFIG_ESPTOOLPY_FLASHSIZE_16MB is not set
|
||||||
# default:
|
|
||||||
# CONFIG_ESPTOOLPY_FLASHSIZE_32MB is not set
|
# CONFIG_ESPTOOLPY_FLASHSIZE_32MB is not set
|
||||||
# default:
|
|
||||||
# CONFIG_ESPTOOLPY_FLASHSIZE_64MB is not set
|
# CONFIG_ESPTOOLPY_FLASHSIZE_64MB is not set
|
||||||
# default:
|
|
||||||
# CONFIG_ESPTOOLPY_FLASHSIZE_128MB is not set
|
# CONFIG_ESPTOOLPY_FLASHSIZE_128MB is not set
|
||||||
# default:
|
# default:
|
||||||
CONFIG_ESPTOOLPY_FLASHSIZE="2MB"
|
CONFIG_ESPTOOLPY_FLASHSIZE="4MB"
|
||||||
# default:
|
# default:
|
||||||
# CONFIG_ESPTOOLPY_HEADER_FLASHSIZE_UPDATE is not set
|
# CONFIG_ESPTOOLPY_HEADER_FLASHSIZE_UPDATE is not set
|
||||||
# default:
|
# default:
|
||||||
@@ -1047,20 +1033,15 @@ CONFIG_ESPTOOLPY_MONITOR_BAUD=115200
|
|||||||
#
|
#
|
||||||
# Partition Table
|
# Partition Table
|
||||||
#
|
#
|
||||||
# default:
|
# CONFIG_PARTITION_TABLE_SINGLE_APP is not set
|
||||||
CONFIG_PARTITION_TABLE_SINGLE_APP=y
|
CONFIG_PARTITION_TABLE_SINGLE_APP_LARGE=y
|
||||||
# default:
|
|
||||||
# CONFIG_PARTITION_TABLE_SINGLE_APP_LARGE is not set
|
|
||||||
# default:
|
|
||||||
# CONFIG_PARTITION_TABLE_TWO_OTA is not set
|
# CONFIG_PARTITION_TABLE_TWO_OTA is not set
|
||||||
# default:
|
|
||||||
# CONFIG_PARTITION_TABLE_TWO_OTA_LARGE is not set
|
# CONFIG_PARTITION_TABLE_TWO_OTA_LARGE is not set
|
||||||
# default:
|
|
||||||
# CONFIG_PARTITION_TABLE_CUSTOM is not set
|
# CONFIG_PARTITION_TABLE_CUSTOM is not set
|
||||||
# default:
|
# default:
|
||||||
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv"
|
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv"
|
||||||
# default:
|
# default:
|
||||||
CONFIG_PARTITION_TABLE_FILENAME="partitions_singleapp.csv"
|
CONFIG_PARTITION_TABLE_FILENAME="partitions_singleapp_large_coredump.csv"
|
||||||
# default:
|
# default:
|
||||||
CONFIG_PARTITION_TABLE_OFFSET=0x8000
|
CONFIG_PARTITION_TABLE_OFFSET=0x8000
|
||||||
# default:
|
# default:
|
||||||
@@ -2261,12 +2242,25 @@ CONFIG_ESP_WIFI_ENTERPRISE_SUPPORT=y
|
|||||||
#
|
#
|
||||||
# Core dump
|
# Core dump
|
||||||
#
|
#
|
||||||
# default:
|
CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH=y
|
||||||
# CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH is not set
|
|
||||||
# default:
|
|
||||||
# CONFIG_ESP_COREDUMP_ENABLE_TO_UART is not set
|
# CONFIG_ESP_COREDUMP_ENABLE_TO_UART is not set
|
||||||
|
# CONFIG_ESP_COREDUMP_ENABLE_TO_NONE is not set
|
||||||
# default:
|
# default:
|
||||||
CONFIG_ESP_COREDUMP_ENABLE_TO_NONE=y
|
# CONFIG_ESP_COREDUMP_CAPTURE_DRAM is not set
|
||||||
|
# default:
|
||||||
|
CONFIG_ESP_COREDUMP_CHECK_BOOT=y
|
||||||
|
# default:
|
||||||
|
CONFIG_ESP_COREDUMP_ENABLE=y
|
||||||
|
# default:
|
||||||
|
CONFIG_ESP_COREDUMP_LOGS=y
|
||||||
|
# default:
|
||||||
|
CONFIG_ESP_COREDUMP_MAX_TASKS_NUM=64
|
||||||
|
# default:
|
||||||
|
# CONFIG_ESP_COREDUMP_FLASH_NO_OVERWRITE is not set
|
||||||
|
# default:
|
||||||
|
CONFIG_ESP_COREDUMP_STACK_SIZE=0
|
||||||
|
# default:
|
||||||
|
CONFIG_ESP_COREDUMP_SUMMARY_STACKDUMP_SIZE=1024
|
||||||
# end of Core dump
|
# end of Core dump
|
||||||
|
|
||||||
#
|
#
|
||||||
@@ -2448,7 +2442,7 @@ CONFIG_FREERTOS_TLSP_DELETION_CALLBACKS=y
|
|||||||
# default:
|
# default:
|
||||||
CONFIG_FREERTOS_CHECK_MUTEX_GIVEN_BY_OWNER=y
|
CONFIG_FREERTOS_CHECK_MUTEX_GIVEN_BY_OWNER=y
|
||||||
# default:
|
# default:
|
||||||
CONFIG_FREERTOS_ISR_STACKSIZE=1536
|
CONFIG_FREERTOS_ISR_STACKSIZE=2096
|
||||||
# default:
|
# default:
|
||||||
CONFIG_FREERTOS_INTERRUPT_BACKTRACE=y
|
CONFIG_FREERTOS_INTERRUPT_BACKTRACE=y
|
||||||
# default:
|
# default:
|
||||||
@@ -3409,11 +3403,11 @@ CONFIG_SD_ENABLE_SDIO_SUPPORT=y
|
|||||||
# MMU Config
|
# MMU Config
|
||||||
#
|
#
|
||||||
# default:
|
# default:
|
||||||
CONFIG_MMU_PAGE_SIZE_32KB=y
|
CONFIG_MMU_PAGE_SIZE_64KB=y
|
||||||
# default:
|
# default:
|
||||||
CONFIG_MMU_PAGE_MODE="32KB"
|
CONFIG_MMU_PAGE_MODE="64KB"
|
||||||
# default:
|
# default:
|
||||||
CONFIG_MMU_PAGE_SIZE=0x8000
|
CONFIG_MMU_PAGE_SIZE=0x10000
|
||||||
# end of MMU Config
|
# end of MMU Config
|
||||||
|
|
||||||
#
|
#
|
||||||
@@ -3581,12 +3575,25 @@ CONFIG_WS_BUFFER_SIZE=1024
|
|||||||
#
|
#
|
||||||
# Ultra Low Power (ULP) Co-processor
|
# Ultra Low Power (ULP) Co-processor
|
||||||
#
|
#
|
||||||
|
CONFIG_ULP_COPROC_ENABLED=y
|
||||||
# default:
|
# default:
|
||||||
# CONFIG_ULP_COPROC_ENABLED is not set
|
CONFIG_ULP_COPROC_TYPE_LP_CORE=y
|
||||||
|
# default:
|
||||||
|
CONFIG_ULP_COPROC_RESERVE_MEM=4096
|
||||||
|
# default:
|
||||||
|
CONFIG_ULP_SHARED_MEM=0x10
|
||||||
|
# default:
|
||||||
|
CONFIG_ULP_TRAP_WAKEUP=y
|
||||||
|
|
||||||
#
|
#
|
||||||
# ULP Debugging Options
|
# ULP Debugging Options
|
||||||
#
|
#
|
||||||
|
# default:
|
||||||
|
# CONFIG_ULP_PANIC_OUTPUT_ENABLE is not set
|
||||||
|
# default:
|
||||||
|
# CONFIG_ULP_HP_UART_CONSOLE_PRINT is not set
|
||||||
|
# default:
|
||||||
|
CONFIG_ULP_NORESET_UNDER_DEBUG=y
|
||||||
# end of ULP Debugging Options
|
# end of ULP Debugging Options
|
||||||
# end of Ultra Low Power (ULP) Co-processor
|
# end of Ultra Low Power (ULP) Co-processor
|
||||||
|
|
||||||
@@ -3660,13 +3667,13 @@ CONFIG_WL_SECTOR_SIZE=4096
|
|||||||
# CONFIG_NO_BLOBS is not set
|
# CONFIG_NO_BLOBS is not set
|
||||||
# CONFIG_APP_ROLLBACK_ENABLE is not set
|
# CONFIG_APP_ROLLBACK_ENABLE is not set
|
||||||
# CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_NONE is not set
|
# CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_NONE is not set
|
||||||
# CONFIG_LOG_BOOTLOADER_LEVEL_NONE is not set
|
CONFIG_LOG_BOOTLOADER_LEVEL_NONE=y
|
||||||
# CONFIG_LOG_BOOTLOADER_LEVEL_ERROR is not set
|
# CONFIG_LOG_BOOTLOADER_LEVEL_ERROR is not set
|
||||||
# CONFIG_LOG_BOOTLOADER_LEVEL_WARN is not set
|
# CONFIG_LOG_BOOTLOADER_LEVEL_WARN is not set
|
||||||
CONFIG_LOG_BOOTLOADER_LEVEL_INFO=y
|
# CONFIG_LOG_BOOTLOADER_LEVEL_INFO is not set
|
||||||
# CONFIG_LOG_BOOTLOADER_LEVEL_DEBUG is not set
|
# CONFIG_LOG_BOOTLOADER_LEVEL_DEBUG is not set
|
||||||
# CONFIG_LOG_BOOTLOADER_LEVEL_VERBOSE is not set
|
# CONFIG_LOG_BOOTLOADER_LEVEL_VERBOSE is not set
|
||||||
CONFIG_LOG_BOOTLOADER_LEVEL=3
|
CONFIG_LOG_BOOTLOADER_LEVEL=0
|
||||||
# CONFIG_FLASH_ENCRYPTION_ENABLED is not set
|
# CONFIG_FLASH_ENCRYPTION_ENABLED is not set
|
||||||
# CONFIG_FLASHMODE_QIO is not set
|
# CONFIG_FLASHMODE_QIO is not set
|
||||||
# CONFIG_FLASHMODE_QOUT is not set
|
# CONFIG_FLASHMODE_QOUT is not set
|
||||||
@@ -3784,9 +3791,12 @@ CONFIG_WPA_MBEDTLS_TLS_CLIENT=y
|
|||||||
# CONFIG_WPA_WPS_SOFTAP_REGISTRAR is not set
|
# CONFIG_WPA_WPS_SOFTAP_REGISTRAR is not set
|
||||||
# CONFIG_WPA_WPS_STRICT is not set
|
# CONFIG_WPA_WPS_STRICT is not set
|
||||||
# CONFIG_WPA_DEBUG_PRINT is not set
|
# CONFIG_WPA_DEBUG_PRINT is not set
|
||||||
# CONFIG_ESP32_ENABLE_COREDUMP_TO_FLASH is not set
|
CONFIG_ESP32_ENABLE_COREDUMP_TO_FLASH=y
|
||||||
# CONFIG_ESP32_ENABLE_COREDUMP_TO_UART is not set
|
# CONFIG_ESP32_ENABLE_COREDUMP_TO_UART is not set
|
||||||
CONFIG_ESP32_ENABLE_COREDUMP_TO_NONE=y
|
# CONFIG_ESP32_ENABLE_COREDUMP_TO_NONE is not set
|
||||||
|
CONFIG_ESP32_ENABLE_COREDUMP=y
|
||||||
|
CONFIG_ESP32_CORE_DUMP_MAX_TASKS_NUM=64
|
||||||
|
CONFIG_ESP32_CORE_DUMP_STACK_SIZE=0
|
||||||
CONFIG_TIMER_TASK_PRIORITY=1
|
CONFIG_TIMER_TASK_PRIORITY=1
|
||||||
CONFIG_TIMER_TASK_STACK_DEPTH=2048
|
CONFIG_TIMER_TASK_STACK_DEPTH=2048
|
||||||
CONFIG_TIMER_QUEUE_LENGTH=10
|
CONFIG_TIMER_QUEUE_LENGTH=10
|
||||||
|
|||||||
Reference in New Issue
Block a user