Sound Byte Libs 0.5.1-340-gab5b79a
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_HW_HAL_GPIO_HANDLE_HPP_
12#define SBL_HW_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 * - STM32 PC7: GpioHandle{2, 7, false} - Port C (2), pin 7
26 * - Active-low LED: GpioHandle{0, 25, true} - write(true) drives LOW
27 */
28struct GpioHandle {
29 uint32_t port; /**< GPIO port number (0 for single-port MCUs) */
30 uint32_t pin; /**< Pin number within port */
31 bool active_low; /**< True if signal is active-low (inverted) */
32
33 /**
34 * @brief Get the effective physical level accounting for active_low
35 * @param logical_state Logical state (true = active/on, false = inactive/off)
36 * @return Physical level to write to hardware
37 */
38 [[nodiscard]] constexpr bool effective_level(bool logical_state) const noexcept {
39 return active_low ? !logical_state : logical_state;
40 }
41};
42
43} // namespace sbl
44
45#endif // SBL_HW_HAL_GPIO_HANDLE_HPP_
Root namespace for all Sound Byte Libs code.
GPIO pin handle with port, pin number, and polarity.
Definition handle.hpp:28
uint32_t port
Definition handle.hpp:29
uint32_t pin
Definition handle.hpp:30
constexpr bool effective_level(bool logical_state) const noexcept
Get the effective physical level accounting for active_low.
Definition handle.hpp:38