libxr
Embedded C++ framework for bare-metal, RTOS and Linux
Loading...
Searching...
No Matches
mspm0_gpio.hpp
1#pragma once
2
3#include <ti/driverlib/dl_gpio.h>
4
5#include "gpio.hpp"
6
7namespace LibXR
8{
9
10#ifdef GPIOC_BASE
11constexpr uint8_t MAX_PORTS = 3;
12#elif defined(GPIOB_BASE)
13constexpr uint8_t MAX_PORTS = 2;
14#else
15constexpr uint8_t MAX_PORTS = 1;
16#endif
17
25class MSPM0GPIO : public GPIO
26{
27 public:
28 explicit MSPM0GPIO(GPIO_Regs* port, uint32_t pin_mask, uint32_t pincm);
29
30 bool Read() override;
31
32 void Write(bool value) override;
33
34 ErrorCode EnableInterrupt() override;
35
36 ErrorCode DisableInterrupt() override;
37
38 ErrorCode SetConfig(Configuration config) override;
39
40 static inline void OnInterrupt(GPIO_Regs* port)
41 {
42 const int idx = GetPortIndex(reinterpret_cast<uint32_t>(port)); // NOLINT
43 OnInterruptDispatch(port, idx);
44 }
45
46 private:
47 static void OnInterruptDispatch(GPIO_Regs* port, int port_idx);
48
49 static constexpr int GetPortIndex(uint32_t base_addr)
50 {
51#ifdef GPIOA_BASE
52 if (base_addr == GPIOA_BASE)
53 {
54 return 0;
55 }
56#endif
57#ifdef GPIOB_BASE
58 if (base_addr == GPIOB_BASE)
59 {
60 return 1;
61 }
62#endif
63#ifdef GPIOC_BASE
64 if (base_addr == GPIOC_BASE)
65 {
66 return 2;
67 }
68#endif
69 return -1;
70 }
71
72 GPIO_Regs* port_;
73 uint32_t pin_mask_;
74 uint32_t pincm_;
76
77 // 安全的编译时nullptr数组初始化 / Safe compile-time initialization of nullptr array
78 // NOLINTNEXTLINE(bugprone-dynamic-static-initializers)
79 static MSPM0GPIO* instance_map_[MAX_PORTS][32];
80};
81
82} // namespace LibXR
通用输入输出(GPIO)接口类。 General Purpose Input/Output (GPIO) interface class.
Definition gpio.hpp:14
Direction
定义 GPIO 引脚的方向类型 / Defines the direction types for GPIO pins.
Definition gpio.hpp:21
@ INPUT
输入模式 / Input mode.
MSPM0 GPIO / MSPM0 GPIO.
ErrorCode DisableInterrupt() override
禁用 GPIO 引脚中断 / Disables the GPIO pin interrupt.
bool Read() override
读取 GPIO 引脚状态 / Reads the GPIO pin state.
ErrorCode EnableInterrupt() override
使能 GPIO 引脚中断 / Enables the GPIO pin interrupt.
void Write(bool value) override
写入 GPIO 引脚状态 / Writes the GPIO pin state.
ErrorCode SetConfig(Configuration config) override
配置 GPIO 引脚参数 / Configures the GPIO pin settings.
LibXR 命名空间 / LibXR namespace.
Definition ch32_can.hpp:14
ErrorCode
定义错误码枚举 / Defines an enumeration for error codes
存储 GPIO 配置参数的结构体 / Structure storing GPIO configuration parameters.
Definition gpio.hpp:47