Basic nvs init + bluetooth in the build

custom
jacqueline 2 years ago
parent d41de537a0
commit 955a8ce303
  1. 18
      sdkconfig.common
  2. 3
      src/drivers/CMakeLists.txt
  3. 11
      src/drivers/bluetooth.cpp
  4. 19
      src/drivers/include/bluetooth.hpp
  5. 27
      src/drivers/include/nvs.hpp
  6. 73
      src/drivers/nvs.cpp
  7. 4
      src/system_fsm/booting.cpp
  8. 2
      src/system_fsm/include/system_fsm.hpp
  9. 1
      src/system_fsm/system_fsm.cpp

@ -4,13 +4,23 @@ CONFIG_ESPTOOLPY_HEADER_FLASHSIZE_UPDATE=y
CONFIG_PARTITION_TABLE_CUSTOM=y CONFIG_PARTITION_TABLE_CUSTOM=y
CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE=y CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE=y
CONFIG_COMPILER_STACK_CHECK_MODE_NORM=y CONFIG_COMPILER_STACK_CHECK_MODE_NORM=y
CONFIG_BT_ENABLED=y
CONFIG_BT_CLASSIC_ENABLED=y
CONFIG_BT_A2DP_ENABLE=y
# CONFIG_BT_BLE_ENABLED is not set
# CONFIG_BT_MULTI_CONNECTION_ENBALE is not set
CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST=y
CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=y
# CONFIG_TWAI_ERRATA_FIX_BUS_OFF_REC is not set # CONFIG_TWAI_ERRATA_FIX_BUS_OFF_REC is not set
# CONFIG_TWAI_ERRATA_FIX_TX_INTR_LOST is not set # CONFIG_TWAI_ERRATA_FIX_TX_INTR_LOST is not set
# CONFIG_TWAI_ERRATA_FIX_RX_FRAME_INVALID is not set # CONFIG_TWAI_ERRATA_FIX_RX_FRAME_INVALID is not set
# CONFIG_TWAI_ERRATA_FIX_RX_FIFO_CORRUPT is not set # CONFIG_TWAI_ERRATA_FIX_RX_FIFO_CORRUPT is not set
CONFIG_I2S_ISR_IRAM_SAFE=y CONFIG_I2S_ISR_IRAM_SAFE=y
# CONFIG_ETH_USE_ESP32_EMAC is not set
# CONFIG_ETH_USE_SPI_ETHERNET is not set
CONFIG_ESP_HTTP_CLIENT_ENABLE_DIGEST_AUTH=y CONFIG_ESP_HTTP_CLIENT_ENABLE_DIGEST_AUTH=y
CONFIG_ESP32_REV_MIN_3=y CONFIG_ESP32_REV_MIN_3=y
CONFIG_ESP_PHY_REDUCE_TX_POWER=y
CONFIG_SPIRAM=y CONFIG_SPIRAM=y
CONFIG_SPIRAM_TRY_ALLOCATE_WIFI_LWIP=y CONFIG_SPIRAM_TRY_ALLOCATE_WIFI_LWIP=y
CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY=y CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY=y
@ -22,14 +32,18 @@ CONFIG_ESP_MAIN_TASK_STACK_SIZE=12000
CONFIG_ESP_INT_WDT_TIMEOUT_MS=1000 CONFIG_ESP_INT_WDT_TIMEOUT_MS=1000
CONFIG_ESP_TASK_WDT_TIMEOUT_S=10 CONFIG_ESP_TASK_WDT_TIMEOUT_S=10
CONFIG_ESP_IPC_TASK_STACK_SIZE=1536 CONFIG_ESP_IPC_TASK_STACK_SIZE=1536
CONFIG_ESP32_WIFI_STATIC_RX_BUFFER_NUM=10 CONFIG_ESP_WIFI_STATIC_RX_BUFFER_NUM=10
CONFIG_ESP32_WIFI_RX_BA_WIN=6 CONFIG_ESP_WIFI_RX_BA_WIN=6
CONFIG_ESP_WIFI_IRAM_OPT=y
CONFIG_ESP_WIFI_RX_IRAM_OPT=y
CONFIG_FATFS_VOLUME_COUNT=1
CONFIG_FATFS_LFN_HEAP=y CONFIG_FATFS_LFN_HEAP=y
CONFIG_FATFS_API_ENCODING_UTF_8=y CONFIG_FATFS_API_ENCODING_UTF_8=y
CONFIG_FATFS_USE_FASTSEEK=y CONFIG_FATFS_USE_FASTSEEK=y
CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK=y CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK=y
CONFIG_HEAP_POISONING_COMPREHENSIVE=y CONFIG_HEAP_POISONING_COMPREHENSIVE=y
CONFIG_HEAP_ABORT_WHEN_ALLOCATION_FAILS=y CONFIG_HEAP_ABORT_WHEN_ALLOCATION_FAILS=y
CONFIG_WIFI_PROV_BLE_FORCE_ENCRYPTION=y
CONFIG_LV_COLOR_16_SWAP=y CONFIG_LV_COLOR_16_SWAP=y
CONFIG_LV_COLOR_MIX_ROUND_OFS=0 CONFIG_LV_COLOR_MIX_ROUND_OFS=0
CONFIG_LV_MEM_CUSTOM=y CONFIG_LV_MEM_CUSTOM=y

@ -5,6 +5,7 @@
idf_component_register( idf_component_register(
SRCS "touchwheel.cpp" "i2s_dac.cpp" "gpios.cpp" "battery.cpp" "storage.cpp" "i2c.cpp" SRCS "touchwheel.cpp" "i2s_dac.cpp" "gpios.cpp" "battery.cpp" "storage.cpp" "i2c.cpp"
"spi.cpp" "display.cpp" "display_init.cpp" "samd.cpp" "relative_wheel.cpp" "wm8523.cpp" "spi.cpp" "display.cpp" "display_init.cpp" "samd.cpp" "relative_wheel.cpp" "wm8523.cpp"
"nvs.cpp" "bluetooth.cpp"
INCLUDE_DIRS "include" INCLUDE_DIRS "include"
REQUIRES "esp_adc" "fatfs" "result" "lvgl" "span" "tasks") REQUIRES "esp_adc" "fatfs" "result" "lvgl" "span" "tasks" "nvs_flash" "bt")
target_compile_options(${COMPONENT_LIB} PRIVATE ${EXTRA_WARNINGS}) target_compile_options(${COMPONENT_LIB} PRIVATE ${EXTRA_WARNINGS})

@ -0,0 +1,11 @@
#include "bluetooth.hpp"
#include "esp_bt.h"
namespace drivers {
auto Bluetooth::Enable() -> Bluetooth* {
return nullptr;
}
} // namespace drivers

@ -0,0 +1,19 @@
#pragma once
#include <vector>
namespace drivers {
class Bluetooth {
public:
static auto Enable() -> Bluetooth*;
Bluetooth();
~Bluetooth();
struct Device {};
auto Scan() -> std::vector<Device>;
private:
};
}

@ -0,0 +1,27 @@
/*
* Copyright 2023 jacqueline <me@jacqueline.id.au>
*
* SPDX-License-Identifier: GPL-3.0-only
*/
#pragma once
#include "esp_err.h"
#include "nvs.h"
namespace drivers {
class NvsStorage {
public:
static auto Open() -> NvsStorage*;
auto SchemaVersion() -> uint8_t;
explicit NvsStorage(nvs_handle_t);
~NvsStorage();
private:
nvs_handle_t handle_;
};
} // namespace drivers

@ -0,0 +1,73 @@
/*
* Copyright 2023 jacqueline <me@jacqueline.id.au>
*
* SPDX-License-Identifier: GPL-3.0-only
*/
#include "nvs.hpp"
#include <stdint.h>
#include <cstdint>
#include <memory>
#include "esp_log.h"
#include "nvs.h"
#include "nvs_flash.h"
namespace drivers {
static constexpr char kTag[] = "nvm";
static constexpr uint8_t kSchemaVersion = 1;
static constexpr char kKeyVersion[] = "ver";
auto NvsStorage::Open() -> NvsStorage* {
esp_err_t err = nvs_flash_init();
if (err == ESP_ERR_NVS_NO_FREE_PAGES) {
ESP_LOGW(kTag, "partition needs initialisation");
nvs_flash_erase();
err = nvs_flash_init();
}
if (err != ESP_OK) {
ESP_LOGE(kTag, "failed to init nvm");
return nullptr;
}
nvs_handle_t handle;
if ((err = nvs_open("tangara", NVS_READWRITE, &handle)) != ESP_OK) {
ESP_LOGE(kTag, "failed to open nvs namespace");
return nullptr;
}
std::unique_ptr<NvsStorage> instance = std::make_unique<NvsStorage>(handle);
if (instance->SchemaVersion() < kSchemaVersion) {
ESP_LOGW(kTag, "namespace needs downgrading");
nvs_erase_all(handle);
nvs_set_u8(handle, kKeyVersion, kSchemaVersion);
err = nvs_commit(handle);
if (err != ESP_OK) {
ESP_LOGW(kTag, "failed to init namespace");
return nullptr;
}
}
ESP_LOGI(kTag, "nvm storage initialised okay");
return instance.release();
}
NvsStorage::NvsStorage(nvs_handle_t handle) : handle_(handle) {}
NvsStorage::~NvsStorage() {
nvs_close(handle_);
nvs_flash_deinit();
}
auto NvsStorage::SchemaVersion() -> uint8_t {
uint8_t ret;
if (nvs_get_u8(handle_, kKeyVersion, &ret) != ESP_OK) {
return UINT8_MAX;
}
return ret;
}
} // namespace drivers

@ -13,6 +13,7 @@
#include "event_queue.hpp" #include "event_queue.hpp"
#include "gpios.hpp" #include "gpios.hpp"
#include "lvgl/lvgl.h" #include "lvgl/lvgl.h"
#include "nvs.hpp"
#include "relative_wheel.hpp" #include "relative_wheel.hpp"
#include "spi.hpp" #include "spi.hpp"
#include "system_events.hpp" #include "system_events.hpp"
@ -50,9 +51,10 @@ auto Booting::entry() -> void {
ESP_LOGI(kTag, "installing remaining drivers"); ESP_LOGI(kTag, "installing remaining drivers");
sSamd.reset(drivers::Samd::Create()); sSamd.reset(drivers::Samd::Create());
sBattery.reset(drivers::Battery::Create()); sBattery.reset(drivers::Battery::Create());
sNvs.reset(drivers::NvsStorage::Open());
sTagParser.reset(new database::TagParserImpl()); sTagParser.reset(new database::TagParserImpl());
if (!sSamd || !sBattery) { if (!sSamd || !sBattery || !sNvs) {
events::System().Dispatch(FatalError{}); events::System().Dispatch(FatalError{});
events::Ui().Dispatch(FatalError{}); events::Ui().Dispatch(FatalError{});
return; return;

@ -16,6 +16,7 @@
#include "relative_wheel.hpp" #include "relative_wheel.hpp"
#include "samd.hpp" #include "samd.hpp"
#include "storage.hpp" #include "storage.hpp"
#include "nvs.hpp"
#include "tag_parser.hpp" #include "tag_parser.hpp"
#include "tinyfsm.hpp" #include "tinyfsm.hpp"
#include "touchwheel.hpp" #include "touchwheel.hpp"
@ -54,6 +55,7 @@ class SystemState : public tinyfsm::Fsm<SystemState> {
protected: protected:
static std::shared_ptr<drivers::Gpios> sGpios; static std::shared_ptr<drivers::Gpios> sGpios;
static std::shared_ptr<drivers::Samd> sSamd; static std::shared_ptr<drivers::Samd> sSamd;
static std::shared_ptr<drivers::NvsStorage> sNvs;
static std::shared_ptr<drivers::TouchWheel> sTouch; static std::shared_ptr<drivers::TouchWheel> sTouch;
static std::shared_ptr<drivers::RelativeWheel> sRelativeTouch; static std::shared_ptr<drivers::RelativeWheel> sRelativeTouch;

@ -17,6 +17,7 @@ namespace system_fsm {
std::shared_ptr<drivers::Gpios> SystemState::sGpios; std::shared_ptr<drivers::Gpios> SystemState::sGpios;
std::shared_ptr<drivers::Samd> SystemState::sSamd; std::shared_ptr<drivers::Samd> SystemState::sSamd;
std::shared_ptr<drivers::NvsStorage> SystemState::sNvs;
std::shared_ptr<drivers::TouchWheel> SystemState::sTouch; std::shared_ptr<drivers::TouchWheel> SystemState::sTouch;
std::shared_ptr<drivers::RelativeWheel> SystemState::sRelativeTouch; std::shared_ptr<drivers::RelativeWheel> SystemState::sRelativeTouch;

Loading…
Cancel
Save