-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdriver_init.c
144 lines (107 loc) · 3 KB
/
driver_init.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*
* Code generated from Atmel Start.
*
* This file will be overwritten when reconfiguring your Atmel Start project.
* Please copy examples or other code you want to keep to a separate file
* to avoid losing it when reconfiguring.
*/
#include "driver_init.h"
#include <peripheral_clk_config.h>
#include <utils.h>
#include <hal_init.h>
#include <hpl_adc_base.h>
#include <hpl_rtc_base.h>
struct timer_descriptor TIMER_0;
struct adc_sync_descriptor ADC_0;
struct usart_sync_descriptor USART_0;
struct pwm_descriptor PWM_0;
struct temp_sync_descriptor TEMPERATURE_SENSOR_0;
void ADC_0_PORT_init(void)
{
// Disable digital pin circuitry
gpio_set_pin_direction(ANALOG_IN, GPIO_DIRECTION_OFF);
gpio_set_pin_function(ANALOG_IN, PINMUX_PA02B_ADC0_AIN0);
// Disable digital pin circuitry
gpio_set_pin_direction(ADC_NEG, GPIO_DIRECTION_OFF);
gpio_set_pin_function(ADC_NEG, PINMUX_PA05B_ADC0_AIN5);
// Disable digital pin circuitry
gpio_set_pin_direction(ADC_POS, GPIO_DIRECTION_OFF);
gpio_set_pin_function(ADC_POS, PINMUX_PA03B_ADC0_VREFP);
}
void ADC_0_CLOCK_init(void)
{
hri_mclk_set_APBCMASK_ADC0_bit(MCLK);
hri_gclk_write_PCHCTRL_reg(GCLK, ADC0_GCLK_ID, CONF_GCLK_ADC0_SRC | (1 << GCLK_PCHCTRL_CHEN_Pos));
}
void ADC_0_init(void)
{
ADC_0_CLOCK_init();
ADC_0_PORT_init();
adc_sync_init(&ADC_0, ADC0, _adc_get_adc_sync());
}
/**
* \brief Timer initialization function
*
* Enables Timer peripheral, clocks and initializes Timer driver
*/
static void TIMER_0_init(void)
{
hri_mclk_set_APBAMASK_RTC_bit(MCLK);
timer_init(&TIMER_0, RTC, _rtc_get_timer());
}
void USART_0_PORT_init(void)
{
gpio_set_pin_function(UART_RX, PINMUX_PA09C_SERCOM0_PAD1);
gpio_set_pin_function(UART_TX, PINMUX_PA10C_SERCOM0_PAD2);
}
void USART_0_CLOCK_init(void)
{
hri_gclk_write_PCHCTRL_reg(GCLK, SERCOM0_GCLK_ID_CORE, CONF_GCLK_SERCOM0_CORE_SRC | (1 << GCLK_PCHCTRL_CHEN_Pos));
hri_gclk_write_PCHCTRL_reg(GCLK, SERCOM0_GCLK_ID_SLOW, CONF_GCLK_SERCOM0_SLOW_SRC | (1 << GCLK_PCHCTRL_CHEN_Pos));
hri_mclk_set_APBCMASK_SERCOM0_bit(MCLK);
}
void USART_0_init(void)
{
USART_0_CLOCK_init();
usart_sync_init(&USART_0, SERCOM0, (void *)NULL);
USART_0_PORT_init();
}
void delay_driver_init(void)
{
delay_init(SysTick);
}
void PWM_0_PORT_init(void)
{
gpio_set_pin_function(LED, PINMUX_PA15E_TC4_WO1);
}
void PWM_0_CLOCK_init(void)
{
hri_mclk_set_APBCMASK_TC4_bit(MCLK);
hri_gclk_write_PCHCTRL_reg(GCLK, TC4_GCLK_ID, CONF_GCLK_TC4_SRC | (1 << GCLK_PCHCTRL_CHEN_Pos));
}
void PWM_0_init(void)
{
PWM_0_CLOCK_init();
PWM_0_PORT_init();
pwm_init(&PWM_0, TC4, _tc_get_pwm());
}
void TEMPERATURE_SENSOR_0_CLOCK_init(void)
{
hri_mclk_set_APBAMASK_TSENS_bit(MCLK);
hri_gclk_write_PCHCTRL_reg(GCLK, TSENS_GCLK_ID, CONF_GCLK_TSENS_SRC | (1 << GCLK_PCHCTRL_CHEN_Pos));
}
void TEMPERATURE_SENSOR_0_init(void)
{
TEMPERATURE_SENSOR_0_CLOCK_init();
temp_sync_init(&TEMPERATURE_SENSOR_0, TSENS);
}
void system_init(void)
{
init_mcu();
ADC_0_init();
TIMER_0_init();
USART_0_init();
delay_driver_init();
PWM_0_init();
TEMPERATURE_SENSOR_0_init();
}