libxr  1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
ch32_spi_def.cpp
1// NOLINTBEGIN(cppcoreguidelines-pro-type-cstyle-cast,performance-no-int-to-ptr)
2#include "ch32_spi_def.hpp"
3
4ch32_spi_id_t ch32_spi_get_id(SPI_TypeDef* addr)
5{
6 if (addr == nullptr)
7 {
8 return ch32_spi_id_t::CH32_SPI_ID_ERROR;
9 }
10#if defined(SPI1)
11 else if (addr == SPI1)
12 {
13 return ch32_spi_id_t::CH32_SPI1;
14 }
15#endif
16#if defined(SPI2)
17 else if (addr == SPI2)
18 {
19 return ch32_spi_id_t::CH32_SPI2;
20 }
21#endif
22#if defined(SPI3)
23 else if (addr == SPI3)
24 {
25 return ch32_spi_id_t::CH32_SPI3;
26 }
27#endif
28
29 return ch32_spi_id_t::CH32_SPI_NUMBER;
30}
31
32SPI_TypeDef* ch32_spi_get_instance_id(ch32_spi_id_t id)
33{
34 switch (id)
35 {
36#if defined(SPI1)
37 case CH32_SPI1:
38 return SPI1;
39#endif
40#if defined(SPI2)
41 case CH32_SPI2:
42 return SPI2;
43#endif
44#if defined(SPI3)
45 case CH32_SPI3:
46 return SPI3;
47#endif
48 default:
49 return nullptr;
50 }
51}
52
53// NOLINTEND(cppcoreguidelines-pro-type-cstyle-cast,performance-no-int-to-ptr)