Sound Byte Libs 1ee2ca6
C++ firmware library for audio applications on 32-bit ARM Cortex-M processors
Loading...
Searching...
No Matches
handle.hpp
Go to the documentation of this file.
1/**
2 * @file handle.hpp
3 * @brief GPIO handle type for hardware abstraction
4 * @ingroup hal
5 *
6 * Canonical definition of GpioHandle - the primary way to reference
7 * GPIO pins in SBL. Used by drivers, generated hardware configs, and
8 * user code.
9 */
10
11#ifndef SBL_HAL_GPIO_HANDLE_HPP_
12#define SBL_HAL_GPIO_HANDLE_HPP_
13
14#include <cstdint>
15
16namespace sbl {
17
18/**
19 * @brief GPIO pin handle with port, pin number, and polarity
20 *
21 * Represents a GPIO pin as resolved from hardware manifests.
22 * Used to pass pin configuration to driver functions.
23 *
24 * Examples:
25 * - RP2040 GPIO25: GpioHandle{0, 25, false} - Single port MCU
26 * - STM32 PC7: GpioHandle{2, 7, false} - Port C (2), pin 7
27 * - Active-low LED: GpioHandle{0, 25, true} - write(true) drives LOW
28 */
29struct GpioHandle {
30 uint32_t port; ///< GPIO port number (0 for single-port MCUs)
31 uint32_t pin; ///< Pin number within port
32 bool active_low; ///< True if signal is active-low (inverted)
33
34 /**
35 * @brief Get the effective physical level accounting for active_low
36 * @param logical_state Logical state (true = active/on, false = inactive/off)
37 * @return Physical level to write to hardware
38 */
39 [[nodiscard]] constexpr bool effective_level(bool logical_state) const noexcept {
40 return active_low ? !logical_state : logical_state;
41 }
42};
43
44} // namespace sbl
45
46#endif // SBL_HAL_GPIO_HANDLE_HPP_
Root namespace for all Sound Byte Libs functionality.
Definition aliases.hpp:24
GPIO pin handle with port, pin number, and polarity.
Definition handle.hpp:29
uint32_t port
GPIO port number (0 for single-port MCUs)
Definition handle.hpp:30
uint32_t pin
Pin number within port.
Definition handle.hpp:31
constexpr bool effective_level(bool logical_state) const noexcept
Get the effective physical level accounting for active_low.
Definition handle.hpp:39
bool active_low
True if signal is active-low (inverted)
Definition handle.hpp:32