Add EEPROM EUI-48 device identity across firmware and API.
Read the factory 24AA025E48 serial after ADAU I2C boot, derive SoftAP SSID, BT name, STA hostname, and expose serialNumber on GET /api/health with graceful fallbacks. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -112,6 +112,19 @@ public:
|
||||
*/
|
||||
[[nodiscard]] bool isBooted() const noexcept;
|
||||
|
||||
/**
|
||||
* @brief i2cBusHandle — borrow the shared I2C master bus after boot.
|
||||
*
|
||||
* @dname i2cBusHandle
|
||||
* @return Opaque bus handle for the 24AA025E48 on the same bus, or null
|
||||
* before boot().
|
||||
* @pubstate reads i2cBus_.
|
||||
*
|
||||
* @author Michele Bigi
|
||||
* @date 2026-07-07
|
||||
*/
|
||||
[[nodiscard]] void* i2cBusHandle() const noexcept;
|
||||
|
||||
/**
|
||||
* @brief applyProfile — safeload mixer, EQ, and master from snapshot.
|
||||
*
|
||||
|
||||
@@ -122,6 +122,11 @@ bool Adau1701Driver::isBooted() const noexcept
|
||||
return booted_;
|
||||
}
|
||||
|
||||
void* Adau1701Driver::i2cBusHandle() const noexcept
|
||||
{
|
||||
return i2cBus_;
|
||||
}
|
||||
|
||||
std::expected<void, Adau1701Error> Adau1701Driver::ensureBooted() const
|
||||
{
|
||||
if (!booted_) {
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include "core/Bt1035At.hpp"
|
||||
|
||||
#include <expected>
|
||||
#include <string_view>
|
||||
|
||||
namespace bt1035 {
|
||||
|
||||
@@ -168,6 +169,20 @@ public:
|
||||
*/
|
||||
[[nodiscard]] std::expected<void, Bt1035Error> disconnectA2dp();
|
||||
|
||||
/**
|
||||
* @brief setDeviceName — set the module GAP friendly name (AT+NAME).
|
||||
*
|
||||
* @dname setDeviceName
|
||||
* @param name Bluetooth name (Feasycom FSC-BT1035 AT+NAME command).
|
||||
* @return Ok on success, or Bt1035Error.
|
||||
* @pubstate sends AT+NAME after boot; does not alter AT+AUXCFG=1 init.
|
||||
*
|
||||
* @author Michele Bigi
|
||||
* @date 2026-07-07
|
||||
*/
|
||||
[[nodiscard]] std::expected<void, Bt1035Error> setDeviceName(
|
||||
std::string_view name);
|
||||
|
||||
private:
|
||||
[[nodiscard]] std::expected<void, Bt1035Error> ensureBooted() const;
|
||||
[[nodiscard]] std::expected<void, Bt1035Error> runInitSequence();
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
|
||||
#include <array>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
namespace bt1035 {
|
||||
|
||||
@@ -161,6 +162,19 @@ std::expected<void, Bt1035Error> Bt1035Driver::disconnectA2dp()
|
||||
return sendCommand(core::Bt1035AtCommand::A2dpDisconnect);
|
||||
}
|
||||
|
||||
std::expected<void, Bt1035Error> Bt1035Driver::setDeviceName(
|
||||
std::string_view name)
|
||||
{
|
||||
if (auto ready = ensureBooted(); !ready) {
|
||||
return ready;
|
||||
}
|
||||
if (name.empty() || name.size() > 32U) {
|
||||
return std::unexpected(Bt1035Error::UnexpectedResponse);
|
||||
}
|
||||
std::string line = std::string("AT+NAME=") + std::string(name) + "\r\n";
|
||||
return transmitAndExpectOk(line);
|
||||
}
|
||||
|
||||
std::expected<void, Bt1035Error> Bt1035Driver::runInitSequence()
|
||||
{
|
||||
for (const core::Bt1035AtCommand command : core::bootInitSequence()) {
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
idf_component_register(
|
||||
SRCS "src/Eeprom24aa.cpp"
|
||||
INCLUDE_DIRS "include"
|
||||
REQUIRES core driver esp_driver_i2c
|
||||
)
|
||||
|
||||
target_compile_features(${COMPONENT_LIB} PUBLIC cxx_std_23)
|
||||
@@ -0,0 +1,68 @@
|
||||
/**
|
||||
* @file Eeprom24aa.hpp
|
||||
* @brief 24AA025E48 EEPROM driver — factory EUI-48 on the shared I2C bus.
|
||||
*
|
||||
* DigiRadio firmware — https://github.com/manvalan/DigiRadio
|
||||
*
|
||||
* Copyright 2026 Michele Bigi
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* @author Michele Bigi
|
||||
* @date 2026-07-07
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "core/IDeviceIdentitySource.hpp"
|
||||
|
||||
#include "driver/i2c_master.h"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace eeprom24aa {
|
||||
|
||||
/**
|
||||
* @brief Eeprom24aa — reads the factory EUI-48 from Microchip 24AA025E48.
|
||||
*
|
||||
* @dname Eeprom24aa
|
||||
* @return n/a (type)
|
||||
* @pubstate Borrows an existing I2C master bus (shared with ADAU1701). The
|
||||
* EUI-48 lives at word address 0xFA..0xFF per the 24AA025E48
|
||||
* datasheet (DS20001191).
|
||||
*
|
||||
* @author Michele Bigi
|
||||
* @date 2026-07-07
|
||||
*/
|
||||
class Eeprom24aa : public core::IDeviceIdentitySource {
|
||||
public:
|
||||
/**
|
||||
* @brief Eeprom24aa — bind to a running I2C master bus and 7-bit addr.
|
||||
*
|
||||
* @dname Eeprom24aa
|
||||
* @param bus Shared I2C bus handle from Adau1701Driver after boot.
|
||||
* @param addr7 7-bit EEPROM address (0x52 on DigiRadio).
|
||||
* @pubstate stores bus_ and addr7_; does not own the bus.
|
||||
*
|
||||
* @author Michele Bigi
|
||||
* @date 2026-07-07
|
||||
*/
|
||||
Eeprom24aa(i2c_master_bus_handle_t bus, std::uint8_t addr7) noexcept;
|
||||
|
||||
/**
|
||||
* @brief readDeviceIdentity — read EUI-48 and derive DeviceIdentity.
|
||||
*
|
||||
* @dname readDeviceIdentity
|
||||
* @return DeviceIdentity on success, or IdentityError.
|
||||
* @pubstate performs one I2C read of six bytes at word address 0xFA.
|
||||
*
|
||||
* @author Michele Bigi
|
||||
* @date 2026-07-07
|
||||
*/
|
||||
[[nodiscard]] std::expected<core::DeviceIdentity, core::IdentityError>
|
||||
readDeviceIdentity() override;
|
||||
|
||||
private:
|
||||
i2c_master_bus_handle_t bus_;
|
||||
std::uint8_t addr7_;
|
||||
};
|
||||
|
||||
} // namespace eeprom24aa
|
||||
@@ -0,0 +1,72 @@
|
||||
/**
|
||||
* @file Eeprom24aa.cpp
|
||||
* @brief Eeprom24aa implementation.
|
||||
*
|
||||
* DigiRadio firmware — https://github.com/manvalan/DigiRadio
|
||||
*
|
||||
* Copyright 2026 Michele Bigi
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* @author Michele Bigi
|
||||
* @date 2026-07-07
|
||||
*/
|
||||
|
||||
#include "eeprom24aa/Eeprom24aa.hpp"
|
||||
|
||||
#include "driver/i2c_master.h"
|
||||
#include "esp_log.h"
|
||||
|
||||
#include <array>
|
||||
|
||||
namespace eeprom24aa {
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr char kTag[] = "Eeprom24aa";
|
||||
/** EUI-48 word address per Microchip 24AA025E48 datasheet (DS20001191). */
|
||||
constexpr std::uint8_t kEui48WordAddress = 0xFAU;
|
||||
constexpr int kI2cTimeoutMs = 100;
|
||||
|
||||
} // namespace
|
||||
|
||||
Eeprom24aa::Eeprom24aa(i2c_master_bus_handle_t bus,
|
||||
std::uint8_t addr7) noexcept
|
||||
: bus_(bus)
|
||||
, addr7_(addr7)
|
||||
{
|
||||
}
|
||||
|
||||
std::expected<core::DeviceIdentity, core::IdentityError>
|
||||
Eeprom24aa::readDeviceIdentity()
|
||||
{
|
||||
if (bus_ == nullptr) {
|
||||
return std::unexpected(core::IdentityError::I2cFailed);
|
||||
}
|
||||
|
||||
i2c_device_config_t devCfg = {};
|
||||
devCfg.dev_addr_length = I2C_ADDR_BIT_LEN_7;
|
||||
devCfg.device_address = addr7_;
|
||||
devCfg.scl_speed_hz = 100000;
|
||||
|
||||
i2c_master_dev_handle_t dev = nullptr;
|
||||
if (i2c_master_bus_add_device(bus_, &devCfg, &dev) != ESP_OK) {
|
||||
ESP_LOGW(kTag, "i2c_master_bus_add_device failed");
|
||||
return std::unexpected(core::IdentityError::I2cFailed);
|
||||
}
|
||||
|
||||
const std::uint8_t wordAddress = kEui48WordAddress;
|
||||
std::array<std::uint8_t, 6> payload = {};
|
||||
const esp_err_t err = i2c_master_transmit_receive(
|
||||
dev, &wordAddress, 1U, payload.data(), payload.size(), kI2cTimeoutMs);
|
||||
|
||||
i2c_master_bus_rm_device(dev);
|
||||
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGW(kTag, "EUI-48 read failed (err=0x%x)", static_cast<unsigned>(err));
|
||||
return std::unexpected(core::IdentityError::ReadFailed);
|
||||
}
|
||||
|
||||
return core::DeviceIdentity::fromEui48(core::Eui48::fromBytes(payload));
|
||||
}
|
||||
|
||||
} // namespace eeprom24aa
|
||||
Reference in New Issue
Block a user