periph_conf.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2023 Gunar Schorcht <gunar@schorcht.net>
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
9 #pragma once
10 
21 #include "macros/units.h"
22 
23 #ifndef CONFIG_BOARD_HAS_HXTAL
24 #define CONFIG_BOARD_HAS_HXTAL 1
25 #endif
26 
27 #ifndef CONFIG_BOARD_HAS_LXTAL
28 #define CONFIG_BOARD_HAS_LXTAL 1
29 #endif
30 
31 #ifndef CONFIG_CLOCK_HXTAL
32 #define CONFIG_CLOCK_HXTAL MHZ(8)
33 #endif
34 
35 #ifndef I2C_DEV_1_USED
36 #define I2C_DEV_1_USED 1
37 #endif
38 
39 #include "periph_cpu.h"
40 #include "periph_common_conf.h"
41 
42 #include "cfg_spi_default.h"
43 #include "cfg_uart_default.h"
44 #include "cfg_usbdev_default.h"
45 
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49 
62 static const i2c_conf_t i2c_config[] = {
63  {
64  .dev = I2C1,
65  .speed = I2C_SPEED_NORMAL,
66  .scl_pin = GPIO_PIN(PORT_B, 10),
67  .sda_pin = GPIO_PIN(PORT_B, 11),
68  .rcu_mask = RCU_APB1EN_I2C1EN_Msk,
69  .irqn = I2C1_EV_IRQn,
70  }
71 };
72 
73 #define I2C_NUMOF ARRAY_SIZE(i2c_config)
80 static const adc_conf_t adc_config[] = {
81  { .pin = GPIO_PIN(PORT_A, 1), .dev = 0, .chan = 1 },
82  { .pin = GPIO_PIN(PORT_A, 2), .dev = 0, .chan = 2 },
83  { .pin = GPIO_PIN(PORT_A, 3), .dev = 0, .chan = 3 },
84  { .pin = GPIO_PIN(PORT_A, 4), .dev = 0, .chan = 4 },
85  { .pin = GPIO_PIN(PORT_A, 5), .dev = 0, .chan = 5 },
86  { .pin = GPIO_PIN(PORT_A, 6), .dev = 0, .chan = 6 },
87  /* ADC Temperature channel */
88  { .pin = GPIO_UNDEF, .dev = 0, .chan = 16 },
89  /* ADC VREF channel */
90  { .pin = GPIO_UNDEF, .dev = 0, .chan = 17 },
91 };
92 
93 #define ADC_NUMOF ARRAY_SIZE(adc_config)
100 static const timer_conf_t timer_config[] = {
101  {
102  .dev = TIMER0,
103  .max = 0x0000ffff,
104  .rcu_mask = RCU_APB2EN_TIMER0EN_Msk,
105  .bus = APB2,
106  .irqn = TIMER0_Channel_IRQn
107  },
108  {
109  .dev = TIMER1,
110  .max = 0x0000ffff,
111  .rcu_mask = RCU_APB1EN_TIMER1EN_Msk,
112  .bus = APB1,
113  .irqn = TIMER1_IRQn
114  },
115  /* TIMER2 and TIMER3 are used for PWM pins */
116  {
117  .dev = TIMER4,
118  .max = 0x0000ffff,
119  .rcu_mask = RCU_APB1EN_TIMER4EN_Msk,
120  .bus = APB1,
121  .irqn = TIMER4_IRQn
122  }
123 };
124 
125 #define TIMER_0_IRQN TIMER0_Channel_IRQn
126 #define TIMER_1_IRQN TIMER1_IRQn
127 #define TIMER_2_IRQN TIMER4_IRQn
128 
129 #define TIMER_NUMOF ARRAY_SIZE(timer_config)
136 static const pwm_conf_t pwm_config[] = {
137  {
138  .dev = TIMER2,
139  .rcu_mask = RCU_APB1EN_TIMER2EN_Msk,
140  .chan = {
141  { .pin = GPIO_PIN(PORT_B, 5), .cc_chan = 1 },
142  { .pin = GPIO_PIN(PORT_B, 0), .cc_chan = 2 },
143  /* unused channels have to be defined by GPIO_UNDEF */
144  { .pin = GPIO_UNDEF, .cc_chan = 0 },
145  { .pin = GPIO_UNDEF, .cc_chan = 3 },
146  },
147  .af = GPIO_AF_OUT_PP,
148  .bus = APB1,
149  },
150  {
151  .dev = TIMER3,
152  .rcu_mask = RCU_APB1EN_TIMER3EN_Msk,
153  .chan = {
154  { .pin = GPIO_PIN(PORT_B, 7), .cc_chan = 1 },
155  { .pin = GPIO_PIN(PORT_B, 8), .cc_chan = 2 },
156  /* unused channels have to be defined by GPIO_UNDEF */
157  { .pin = GPIO_UNDEF, .cc_chan = 0 },
158  { .pin = GPIO_UNDEF, .cc_chan = 3 },
159  },
160  .af = GPIO_AF_OUT_PP,
161  .bus = APB1,
162  },
163 };
164 
165 #define PWM_NUMOF ARRAY_SIZE(pwm_config)
168 #ifdef __cplusplus
169 }
170 #endif
171 
@ PORT_B
port B
Definition: periph_cpu.h:47
@ PORT_A
port A
Definition: periph_cpu.h:46
#define GPIO_PIN(x, y)
Define a CPU specific GPIO pin generator macro.
Definition: periph_cpu.h:45
#define GPIO_UNDEF
Definition of a fitting UNDEF value.
static const timer_conf_t timer_config[]
All timers on board.
Definition: periph_conf.h:39
static const i2c_conf_t i2c_config[]
PB10/PB11 (D15/D14) as I2C for Arduino UNO compatibility.
Definition: periph_conf.h:62
static const adc_conf_t adc_config[]
ADC configuration.
Definition: periph_conf.h:250
static const pwm_conf_t pwm_config[]
Actual PWM configuration.
Definition: periph_conf.h:221
@ 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:277
Common peripheral configuration for GD32VF103 boards.
ADC device configuration.
Definition: periph_cpu.h:377
gpio_t pin
pin connected to the channel
Definition: periph_cpu.h:287
I2C configuration structure.
Definition: periph_cpu.h:298
TWI_t * dev
Pointer to hardware module registers.
Definition: periph_cpu.h:299
PWM device configuration.
mini_timer_t * dev
Timer used.
Timer device configuration.
Definition: periph_cpu.h:263
TC0_t * dev
Pointer to the used as Timer device.
Definition: periph_cpu.h:264
Unit helper macros.