libxr  1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
ch32_i2c_def.cpp
1// NOLINTBEGIN(cppcoreguidelines-pro-type-cstyle-cast,performance-no-int-to-ptr)
2#include "ch32_i2c_def.hpp"
3
4ch32_i2c_id_t ch32_i2c_get_id(I2C_TypeDef* addr)
5{
6 if (addr == nullptr)
7 {
8 return ch32_i2c_id_t::CH32_I2C_ID_ERROR;
9 }
10#if defined(I2C1)
11 if (addr == I2C1)
12 {
13 return ch32_i2c_id_t::CH32_I2C1;
14 }
15#endif
16#if defined(I2C2)
17 if (addr == I2C2)
18 {
19 return ch32_i2c_id_t::CH32_I2C2;
20 }
21#endif
22 return ch32_i2c_id_t::CH32_I2C_ID_ERROR;
23}
24
25I2C_TypeDef* ch32_i2c_get_instance_id(ch32_i2c_id_t id)
26{
27 switch (id)
28 {
29#if defined(I2C1)
30 case CH32_I2C1:
31 {
32 return I2C1;
33 }
34#endif
35#if defined(I2C2)
36 case CH32_I2C2:
37 {
38 return I2C2;
39 }
40#endif
41 default:
42 return nullptr;
43 }
44}
45
46// NOLINTEND(cppcoreguidelines-pro-type-cstyle-cast,performance-no-int-to-ptr)