Skip to content

v1.8.8 - DAC Manager Module Refactoring (2025-11-24)

What Changed?

This release refactors the SPI DAC control module for clarity and efficiency. The module is renamed from spi_control to dac_manager to better reflect its responsibility (DAC management, not generic SPI operations). Function names are standardized with dac_* prefix, redundant channel-specific wrappers are removed, and the API is simplified by eliminating vestigial parameters. The SPI settings are now cached as a static object for improved memory efficiency.


What's New

Module Refactoring: SPI Control β†’ DAC Manager

What it does: Restructures the Digital-to-Analog Converter (DAC) management module with clearer naming, simpler API, and improved efficiency. No functional behavior changesβ€”all existing DAC operations work identically.

Key improvements:

  1. Module name clarity - spi_control β†’ dac_manager reflects true responsibility
  2. Unified function prefix - All functions use dac_* instead of mixed spi_* naming
  3. Simplified API - Removed unused clockSpeed parameter from dac_init()
  4. Memory efficiency - Static SPI settings cached, avoiding repeated object creation
  5. Better documentation - Added detailed parameter explanations for SPI configuration

Code example:

// Before (v1.8.7)
#include "spi_control.h"
spi_init(100000);  // Unused parameter

// After (v1.8.8)
#include "dac_manager.h"
dac_init();  // Cleaner API, fixed 100 kHz clock

// SPI settings now cached statically
// Arguments: clock speed (100 kHz), bit order (MSB first),
// data mode (SPI mode 0 - clock idle low, data sampled on rising edge)
static SPISettings g_dac_settings(100000, MSBFIRST, SPI_MODE0);

Installation

Quick Start

# Get the release
git checkout vX.Y.Z

# Build
task build

# Upload
task upload

# Check it works
task monitor

What's Different from the Last Version?

βœ… Added

  • Static SPI settings cache (g_dac_settings) for improved memory efficiency
  • Detailed parameter documentation for SPI configuration (clock speed, bit order, data mode)

πŸ”§ Changed

  • Module rename: spi_control.h β†’ dac_manager.h (file-level clarification of responsibility)
  • Function renames:
  • spi_init(clockSpeed) β†’ dac_init() (removed vestigial parameter)
  • spi_send_dac_command(ch, ...) β†’ dac_send(ch, ...) (unified naming)
  • Removed redundant spi_send_dac1/2/3() wrappers (use unified dac_send(channel, ...))
  • encode_dac_threshold() β†’ dac_encode_threshold() (consistent prefix)
  • Global variable renames: Applied g_ prefix convention for scope clarity
  • spi_vspi β†’ g_dac_spi
  • spi_clock_speed β†’ removed (hardcoded 100 kHz)
  • SPI transaction optimization: Each transaction now reuses cached SPISettings instead of creating temporary objects

πŸ› Fixed

  • Removed unused SPI_DEFAULT_CLOCK macro (hardcoded 100 kHz DAC requirement)
  • Eliminated compiler warnings for unused parameters via proper documentation

Is It Safe to Upgrade?

Backward Compatible: Partially (API changes required)

Impact on users:

  • Code using spi_control module must update includes: #include "dac_manager.h"
  • Function calls must use new names: dac_init(), dac_send(), dac_encode_threshold()
  • If directly calling spi_init(100000), change to dac_init() (no parameters)
  • If using channel-specific wrappers (spi_send_dac1/2/3), replace with unified: dac_send(channel, byte1, byte2)
  • Hardware behavior: Identicalβ€”only API and naming changed
  • Firmware size: Slightly improved (no repeated SPI settings object creation)

Tests Passed

  • βœ… Builds without errors (esp32dev-dev profile)
  • βœ… RAM usage: 7.3% (unchanged)
  • βœ… Flash usage: 24.0% (unchanged, optimized SPI settings offset by reduced code)
  • βœ… Serial communication: functional at 115200 baud
  • βœ… DAC threshold encoding: verified with protocol compliance

Release Details

  • Date: 2025-11-24
  • Version: v1.8.8
  • Files Changed: 5 (dac_manager.h, dac_manager.cpp, main.cpp, runtime_config.cpp, binary_protocol_handler.cpp, text_protocol_handler.cpp)
  • Commits: 83fc011 (refactor: simplify API and optimize), 90c094b (docs: parameter explanation)

Next Steps

  • Continue module-based refactoring of other SPI/I2C interfaces for consistency
  • Evaluate other modules for YAGNI principle application (remove vestigial parameters and unused configuration)
  • Consider applying g_ prefix convention to other global static variables throughout the codebase