libxr  1.0
Want to be the best embedded framework
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
18class MSPM0GPIO : public GPIO
19{
20 public:
21 explicit MSPM0GPIO(GPIO_Regs* port, uint32_t pin_mask, uint32_t pincm);
22
23 bool Read() override;
24
25 void Write(bool value) override;
26
27 ErrorCode EnableInterrupt() override;
28
29 ErrorCode DisableInterrupt() override;
30
31 ErrorCode SetConfig(Configuration config) override;
32
33 static inline void OnInterrupt(GPIO_Regs* port)
34 {
35 const int idx = GetPortIndex(reinterpret_cast<uint32_t>(port)); // NOLINT
36 OnInterruptDispatch(port, idx);
37 }
38
39 private:
40 static void OnInterruptDispatch(GPIO_Regs* port, int port_idx);
41
42 static constexpr int GetPortIndex(uint32_t base_addr)
43 {
44#ifdef GPIOA_BASE
45 if (base_addr == GPIOA_BASE)
46 {
47 return 0;
48 }
49#endif
50#ifdef GPIOB_BASE
51 if (base_addr == GPIOB_BASE)
52 {
53 return 1;
54 }
55#endif
56#ifdef GPIOC_BASE
57 if (base_addr == GPIOC_BASE)
58 {
59 return 2;
60 }
61#endif
62 return -1;
63 }
64
65 GPIO_Regs* port_;
66 uint32_t pin_mask_;
67 uint32_t pincm_;
69
70 // 安全的编译时nullptr数组初始化 / Safe compile-time initialization of nullptr array
71 // NOLINTNEXTLINE(bugprone-dynamic-static-initializers)
72 static MSPM0GPIO* instance_map_[MAX_PORTS][32];
73};
74
75} // namespace LibXR
通用输入输出(GPIO)接口类。General Purpose Input/Output (GPIO) interface class.
Definition gpio.hpp:13
Direction
定义 GPIO 引脚的方向类型。Defines the direction types for GPIO pins.
Definition gpio.hpp:20
@ INPUT
输入模式。Input mode.
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 命名空间
Definition ch32_can.hpp:14
ErrorCode
定义错误码枚举
存储 GPIO 配置参数的结构体。Structure storing GPIO configuration parameters.
Definition gpio.hpp:46