periph_conf.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2023 Gunar Schorcht <gunar@schorcht.net>
3  * SPDX-License-Identifier: LGPL-2.1-only
4  */
5 
6 #pragma once
7 
18 #include "macros/units.h"
19 
20 #ifndef CONFIG_BOARD_HAS_HXTAL
21 #define CONFIG_BOARD_HAS_HXTAL 1
22 #endif
23 
24 #ifndef CONFIG_BOARD_HAS_LXTAL
25 #define CONFIG_BOARD_HAS_LXTAL 1
26 #endif
27 
28 #ifndef CONFIG_CLOCK_HXTAL
29 #define CONFIG_CLOCK_HXTAL MHZ(8)
30 #endif
31 
32 #ifndef I2C_DEV_1_USED
33 #define I2C_DEV_1_USED 1
34 #endif
35 
36 #include "periph_cpu.h"
37 #include "periph_common_conf.h"
38 
39 #include "cfg_spi_default.h"
40 #include "cfg_uart_default.h"
41 #include "cfg_usbdev_default.h"
42 
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46 
59 static const i2c_conf_t i2c_config[] = {
60  {
61  .dev = I2C1,
62  .speed = I2C_SPEED_NORMAL,
63  .scl_pin = GPIO_PIN(PORT_B, 10),
64  .sda_pin = GPIO_PIN(PORT_B, 11),
65  .rcu_mask = RCU_APB1EN_I2C1EN_Msk,
66  .irqn = I2C1_EV_IRQn,
67  }
68 };
69 
70 #define I2C_NUMOF ARRAY_SIZE(i2c_config)
77 static const adc_conf_t adc_config[] = {
78  { .pin = GPIO_PIN(PORT_A, 1), .dev = 0, .chan = 1 },
79  { .pin = GPIO_PIN(PORT_A, 2), .dev = 0, .chan = 2 },
80  { .pin = GPIO_PIN(PORT_A, 3), .dev = 0, .chan = 3 },
81  { .pin = GPIO_PIN(PORT_A, 4), .dev = 0, .chan = 4 },
82  { .pin = GPIO_PIN(PORT_A, 5), .dev = 0, .chan = 5 },
83  { .pin = GPIO_PIN(PORT_A, 6), .dev = 0, .chan = 6 },
84  /* ADC Temperature channel */
85  { .pin = GPIO_UNDEF, .dev = 0, .chan = 16 },
86  /* ADC VREF channel */
87  { .pin = GPIO_UNDEF, .dev = 0, .chan = 17 },
88 };
89 
90 #define ADC_NUMOF ARRAY_SIZE(adc_config)
97 static const timer_conf_t timer_config[] = {
98  {
99  .dev = TIMER0,
100  .max = 0x0000ffff,
101  .rcu_mask = RCU_APB2EN_TIMER0EN_Msk,
102  .bus = APB2,
103  .irqn = TIMER0_Channel_IRQn
104  },
105  {
106  .dev = TIMER1,
107  .max = 0x0000ffff,
108  .rcu_mask = RCU_APB1EN_TIMER1EN_Msk,
109  .bus = APB1,
110  .irqn = TIMER1_IRQn
111  },
112  /* TIMER2 and TIMER3 are used for PWM pins */
113  {
114  .dev = TIMER4,
115  .max = 0x0000ffff,
116  .rcu_mask = RCU_APB1EN_TIMER4EN_Msk,
117  .bus = APB1,
118  .irqn = TIMER4_IRQn
119  }
120 };
121 
122 #define TIMER_0_IRQN TIMER0_Channel_IRQn
123 #define TIMER_1_IRQN TIMER1_IRQn
124 #define TIMER_2_IRQN TIMER4_IRQn
125 
126 #define TIMER_NUMOF ARRAY_SIZE(timer_config)
133 static const pwm_conf_t pwm_config[] = {
134  {
135  .dev = TIMER2,
136  .rcu_mask = RCU_APB1EN_TIMER2EN_Msk,
137  .chan = {
138  { .pin = GPIO_PIN(PORT_B, 5), .cc_chan = 1 },
139  { .pin = GPIO_PIN(PORT_B, 0), .cc_chan = 2 },
140  /* unused channels have to be defined by GPIO_UNDEF */
141  { .pin = GPIO_UNDEF, .cc_chan = 0 },
142  { .pin = GPIO_UNDEF, .cc_chan = 3 },
143  },
144  .af = GPIO_AF_OUT_PP,
145  .bus = APB1,
146  },
147  {
148  .dev = TIMER3,
149  .rcu_mask = RCU_APB1EN_TIMER3EN_Msk,
150  .chan = {
151  { .pin = GPIO_PIN(PORT_B, 7), .cc_chan = 1 },
152  { .pin = GPIO_PIN(PORT_B, 8), .cc_chan = 2 },
153  /* unused channels have to be defined by GPIO_UNDEF */
154  { .pin = GPIO_UNDEF, .cc_chan = 0 },
155  { .pin = GPIO_UNDEF, .cc_chan = 3 },
156  },
157  .af = GPIO_AF_OUT_PP,
158  .bus = APB1,
159  },
160 };
161 
162 #define PWM_NUMOF ARRAY_SIZE(pwm_config)
165 #ifdef __cplusplus
166 }
167 #endif
168 
@ PORT_B
port B
Definition: periph_cpu.h:44
@ PORT_A
port A
Definition: periph_cpu.h:43
#define GPIO_PIN(x, y)
Define a CPU specific GPIO pin generator macro.
Definition: periph_cpu.h:42
#define GPIO_UNDEF
Definition of a fitting UNDEF value.
static const timer_conf_t timer_config[]
All timers on board.
Definition: periph_conf.h:36
static const i2c_conf_t i2c_config[]
PB10/PB11 (D15/D14) as I2C for Arduino UNO compatibility.
Definition: periph_conf.h:59
static const adc_conf_t adc_config[]
ADC configuration.
Definition: periph_conf.h:247
static const pwm_conf_t pwm_config[]
Actual PWM configuration.
Definition: periph_conf.h:218
@ GPIO_AF_OUT_PP
alternate function output - push-pull
Definition: periph_cpu.h:166
@ APB1
Advanced Peripheral Bus 1
Definition: periph_cpu.h:78
@ APB2
Advanced Peripheral Bus 2
Definition: periph_cpu.h:79
@ I2C_SPEED_NORMAL
normal mode: ~100 kbit/s
Definition: periph_cpu.h:274
Common peripheral configuration for GD32VF103 boards.
ADC device configuration.
Definition: periph_cpu.h:374
gpio_t pin
pin connected to the channel
Definition: periph_cpu.h:287
I2C configuration structure.
Definition: periph_cpu.h:295
TWI_t * dev
Pointer to hardware module registers.
Definition: periph_cpu.h:296
PWM device configuration.
mini_timer_t * dev
Timer used.
Timer device configuration.
Definition: periph_cpu.h:260
TC0_t * dev
Pointer to the used as Timer device.
Definition: periph_cpu.h:261
Unit helper macros.