Sound Byte Libs 1ee2ca6
C++ firmware library for audio applications on 32-bit ARM Cortex-M processors
Loading...
Searching...
No Matches
SBL Namespace Guide

Sound Byte Libs uses a structured namespace hierarchy to separate generated code from static implementations.

Namespace Overview

Namespace Purpose Location
sbl::driver:: MCU driver implementations sbl-hardware/mcu/*/driver/
sbl::hw:: Generated hardware configuration build/generated/sbl/hw/config/
sbl::hw::gpio:: Generated GPIO handles build/generated/sbl/hw/config/gpio.hpp
sbl::hw::adc:: Generated ADC handles build/generated/sbl/hw/config/adc.hpp
sbl::hw::mcu:: MCU metadata build/generated/sbl/hw/config/mcu.hpp
sbl::gpio:: GPIO types (PinMode) src/sbl/hal/gpio/types.hpp
sbl::adc:: ADC convenience functions src/sbl/hal/adc/driver.hpp
sbl::log:: Logging utilities (Logger, Level) src/sbl/log/
sbl::defaults:: Sensible buffer size constants src/sbl/common/defaults.hpp
sbl::version:: Library version info (CMake-generated) build/include/sbl/version.hpp
sbl::meta:: Hardware metadata (sloth-generated) build/generated/sbl/hw/meta.hpp
sbl:: Non-generated types (handles) src/sbl/types.hpp

<tt>sbl::driver::</tt> - MCU Drivers

MCU-specific driver implementations. These are static files maintained in the sbl-hardware repository and included via CMake.

#include <sbl/hw/hw.hpp> // Single include for drivers + config
sbl::driver::init();
sbl::driver::Gpio::set_mode(sbl::hw::gpio::status_led, sbl::gpio::PinMode::Output);
sbl::driver::Gpio::write(sbl::hw::gpio::status_led, true);
sbl::driver::Gpio::toggle(sbl::hw::gpio::status_led);
sbl::driver::Timer::delay_ms(500);
sbl::driver::Uart::init(115200);
sbl::driver::Uart::write_byte('A');
Uber-umbrella header for all target-specific code.

Individual driver headers are also available:

#include <sbl/hw/driver/gpio.hpp>
#include <sbl/hw/driver/timer.hpp>
#include <sbl/hw/driver/uart.hpp>
#include <sbl/hw/driver/adc.hpp> // ADC driver (STM32H7)
#include <sbl/hw/driver/init.hpp>

Contents:

  • Gpio - GPIO read/write/mode/toggle operations (handle-first API)
  • Timer - Delay functions and millis counter
  • Uart - UART output for debugging
  • Adc - ADC initialization and reading (STM32H7)
  • init() - MCU initialization

<tt>sbl::adc::</tt> - ADC Convenience Functions

Convenience namespace for ADC operations:

// Template function that works with any validated ADC driver
uint16_t value = sbl::adc::read<sbl::driver::Adc>(sbl::hw::adc::knob1);
ADC driver interface - canonical types for MCU driver implementations.

<tt>sbl::gpio::</tt> - GPIO Types

GPIO-related types defined in src/sbl/hal/gpio/types.hpp:

sbl::gpio::PinMode::Output
sbl::gpio::PinMode::Input
sbl::gpio::PinMode::InputPullup
sbl::gpio::PinMode::InputPulldown

<tt>sbl::hw::</tt> - Generated Hardware Configuration

Build-time generated headers containing hardware-specific constants resolved from manifests by sloth.

Generated files in build/generated/sbl/hw/config/:

  • gpio.hpp - GPIO handles
  • adc.hpp - ADC handles (if any ADC claims)
  • mcu.hpp - MCU metadata
  • system.hpp - System configuration
#include <sbl/hw/hw.hpp> // Includes all config + drivers
constexpr auto led = sbl::hw::gpio::status_led; // GpioHandle{0, 25, false}

Sub-namespaces:

  • sbl::hw::gpio:: - GPIO handles (e.g., status_led)
  • sbl::hw::adc:: - ADC handles
  • sbl::hw::system:: - Configuration values (e.g., sysclk_mhz)
  • sbl::hw::mcu:: - MCU metadata (e.g., name, family)

<tt>sbl::</tt> - Non-Generated Types

Handle types defined in static headers for IDE/LSP support. These types are used by both generated and driver code.

#include <sbl/types.hpp>
// Handle types
sbl::GpioHandle // { port, pin, active_low }
sbl::AdcHandle // { adc, channel }
sbl::PwmHandle // { timer, channel }
ADC channel handle.
Definition handle.hpp:29
GPIO pin handle with port, pin number, and polarity.
Definition handle.hpp:29
PWM output handle.
Definition types.hpp:31
Common types for SBL hardware abstraction.

Handles are passed directly to driver functions (handle-first API):

// The driver handles active-low logic internally
sbl::driver::Gpio::write(sbl::hw::gpio::status_led, true); // LED on
sbl::driver::Gpio::toggle(sbl::hw::gpio::status_led); // Toggle LED

Optional Aliases

For shorter code, include <sbl/aliases.hpp>:

#include <sbl/aliases.hpp>
// Now available directly in sbl::
sbl::Gpio::set_mode(pin, sbl::PinMode::Output);
sbl::Timer::delay_ms(500);
sbl::init();
Optional convenience aliases for SBL namespaces.

This is opt-in. The explicit sbl::driver:: form is recommended for clarity in embedded code.

<tt>sbl::defaults::</tt> - Sensible Buffer Defaults

Pre-defined buffer size constants for embedded contexts:

sbl::defaults::SMALL_BUFFER // 12 bytes (short strings)
sbl::defaults::MEDIUM_BUFFER // 64 bytes (typical messages)
sbl::defaults::LARGE_BUFFER // 256 bytes (formatted output)
sbl::defaults::LOG_MESSAGE // 256 bytes (alias for log buffers)
Sensible default constants for embedded systems.
constexpr std::size_t LOG_MESSAGE
Maximum log message length.
Definition defaults.hpp:39
constexpr std::size_t LARGE_BUFFER
Large buffer size for log messages, etc.
Definition defaults.hpp:34
constexpr std::size_t SMALL_BUFFER
Small buffer size for number formatting, etc.
Definition defaults.hpp:24
constexpr std::size_t MEDIUM_BUFFER
Medium buffer size for string operations.
Definition defaults.hpp:29

<tt>sbl::version::</tt> - Library Version

CMake-generated version info from git tags:

#include <sbl/version.hpp>
sbl::version::major // 0
sbl::version::minor // 1
sbl::version::patch // 6
sbl::version::string // "0.1.6"
sbl::version::full_string // "0.1.6-48-g79632a7" (git describe)
sbl::version::git_hash // "79632a7"
sbl::version::git_dirty // true/false
sbl::version::number // 106 (for numeric comparisons)
sbl::version::is_at_least(0, 1, 5) // true

<tt>sbl::meta::</tt> - Hardware Metadata

sloth-generated metadata about the target hardware:

#include <sbl/hw/meta.hpp>
sbl::meta::manifest_schema // "0.1"
sbl::meta::target::name // "daisy-seed"
sbl::meta::target::manifest_version // "1.0.0"
sbl::meta::target::hw_revision // "1.0"
sbl::meta::mcu::name // "stm32h750"
sbl::meta::mcu::manifest_version // "1.0.0"

<tt>sbl::log::</tt> - Logging System

Lightweight, zero-overhead logging for embedded development:

#include <sbl/log/log.hpp>
// Define output sink and timestamp provider
struct UartOutput {
static void write(const char* str) { sbl::driver::Uart::puts(str); }
};
struct Timestamp {
static uint32_t millis() { return sbl::driver::Timer::millis(); }
};
// Create logger type
// Enable macros with compile-time level filtering
#define SBL_LOG_LEVEL SBL_LOG_LEVEL_INFO
#define SblLogger_ Logger
// Use in code
SBL_LOG_INFO("System started");
SBL_LOG_DEBUG("Debug info"); // Compiled out if level < DEBUG
SBL_LOG_ERROR("Error: %d", err);
Logger class with compile-time level filtering.
Definition logger.hpp:89
Logging system umbrella header.
Zero-overhead logging macros with file/line capture.
#define SBL_LOG_INFO(...)
Definition macros.hpp:93
#define SBL_LOG_DEBUG(...)
Definition macros.hpp:100
#define SBL_LOG_ERROR(...)
Main logging macros with compile-time level filtering.
Definition macros.hpp:79

Log levels (compile-time constants for #if compatibility):

  • SBL_LOG_LEVEL_OFF (0) - Disable all logging
  • SBL_LOG_LEVEL_ERROR (1)
  • SBL_LOG_LEVEL_WARN (2)
  • SBL_LOG_LEVEL_INFO (3)
  • SBL_LOG_LEVEL_DEBUG (4)
  • SBL_LOG_LEVEL_TRACE (5)

Output format: I 12345 main.cpp:42| Message

Include Path Summary

// Primary hardware include (drivers + generated config)
#include <sbl/hw/hw.hpp>
// Or individual includes:
#include <sbl/hw/driver/gpio.hpp> // GPIO driver
#include <sbl/hw/driver/timer.hpp> // Timer driver
#include <sbl/hw/driver/uart.hpp> // UART driver
#include <sbl/hw/driver/adc.hpp> // ADC driver (STM32H7)
#include <sbl/hw/driver/init.hpp> // MCU init
#include <sbl/hw/config/gpio.hpp> // Generated GPIO handles
#include <sbl/hw/config/adc.hpp> // Generated ADC handles
#include <sbl/hw/config/mcu.hpp> // Generated MCU metadata
#include <sbl/hw/meta.hpp> // Target/MCU metadata
// ADC convenience functions
#include <sbl/hal/adc/driver.hpp> // sbl::adc::read<>()
// Logging system
#include <sbl/log/log.hpp> // Logger class and Level enum
#include <sbl/log/macros.hpp> // SBL_LOG_* macros (after defining SblLogger_)
// Library version (CMake-generated)
#include <sbl/version.hpp>
// Types (from sound-byte-libs, static)
#include <sbl/types.hpp>
// Common utilities (from sound-byte-libs)
#include <sbl/common/defaults.hpp> // Buffer size constants
// Aliases (optional convenience)
#include <sbl/aliases.hpp>