libxr  1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
ch32_i2c_def.hpp
1#pragma once
2
3#include "libxr.hpp"
4#include DEF2STR(LIBXR_CH32_CONFIG_FILE)
5
9typedef enum
10{
11#if defined(I2C1)
12 CH32_I2C1,
13#endif
14#if defined(I2C2)
15 CH32_I2C2,
16#endif
17 CH32_I2C_NUMBER,
18 CH32_I2C_ID_ERROR
19} ch32_i2c_id_t;
20
21static constexpr uint32_t CH32_I2C_RCC_PERIPH_MAP[] = {
22#if defined(I2C1)
23 RCC_APB1Periph_I2C1,
24#endif
25#if defined(I2C2)
26 RCC_APB1Periph_I2C2,
27#endif
28};
29
30static constexpr uint32_t CH32_I2C_RCC_PERIPH_MAP_DMA[] = {
31#if defined(I2C1)
32 RCC_AHBPeriph_DMA1,
33#endif
34#if defined(I2C2)
35 RCC_AHBPeriph_DMA1,
36#endif
37};
38
39// DMA channel mapping follows the common CH32F1-compatible layout:
40// I2C1_TX=CH6, I2C1_RX=CH7, I2C2_TX=CH4, I2C2_RX=CH5.
41static DMA_Channel_TypeDef* const CH32_I2C_TX_DMA_CHANNEL_MAP[] = {
42#if defined(I2C1)
43 DMA1_Channel6,
44#endif
45#if defined(I2C2)
46 DMA1_Channel4,
47#endif
48};
49
50static DMA_Channel_TypeDef* const CH32_I2C_RX_DMA_CHANNEL_MAP[] = {
51#if defined(I2C1)
52 DMA1_Channel7,
53#endif
54#if defined(I2C2)
55 DMA1_Channel5,
56#endif
57};
58
59static constexpr uint32_t CH32_I2C_TX_DMA_IT_MAP[] = {
60#if defined(I2C1)
61 DMA1_IT_TC6,
62#endif
63#if defined(I2C2)
64 DMA1_IT_TC4,
65#endif
66};
67
68static constexpr uint32_t CH32_I2C_RX_DMA_IT_MAP[] = {
69#if defined(I2C1)
70 DMA1_IT_TC7,
71#endif
72#if defined(I2C2)
73 DMA1_IT_TC5,
74#endif
75};
76
77static constexpr IRQn_Type CH32_I2C_ER_IRQ_MAP[] = {
78#if defined(I2C1)
79 I2C1_ER_IRQn,
80#endif
81#if defined(I2C2)
82 I2C2_ER_IRQn,
83#endif
84};
85
86ch32_i2c_id_t ch32_i2c_get_id(I2C_TypeDef* addr);
87I2C_TypeDef* ch32_i2c_get_instance_id(ch32_i2c_id_t id);