You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
135 lines
3.3 KiB
C
135 lines
3.3 KiB
C
3 years ago
|
/*
|
||
|
* 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>
|
||
|
|
||
|
/*! The buffer size for USART */
|
||
|
#define USART_0_BUFFER_SIZE 16
|
||
|
|
||
|
struct usart_async_descriptor USART_0;
|
||
|
struct timer_descriptor TIMER_0;
|
||
|
|
||
|
static uint8_t USART_0_buffer[USART_0_BUFFER_SIZE];
|
||
|
|
||
|
struct i2c_m_sync_desc I2C_0;
|
||
|
|
||
|
void EXTERNAL_IRQ_0_init(void)
|
||
|
{
|
||
|
hri_gclk_write_PCHCTRL_reg(GCLK, EIC_GCLK_ID, CONF_GCLK_EIC_SRC | (1 << GCLK_PCHCTRL_CHEN_Pos));
|
||
|
hri_mclk_set_APBAMASK_EIC_bit(MCLK);
|
||
|
|
||
|
ext_irq_init();
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* \brief USART Clock initialization function
|
||
|
*
|
||
|
* Enables register interface and peripheral clock
|
||
|
*/
|
||
|
void USART_0_CLOCK_init()
|
||
|
{
|
||
|
|
||
|
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_APBAMASK_SERCOM0_bit(MCLK);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* \brief USART pinmux initialization function
|
||
|
*
|
||
|
* Set each required pin to USART functionality
|
||
|
*/
|
||
|
void USART_0_PORT_init()
|
||
|
{
|
||
|
|
||
|
gpio_set_pin_function(PA04, PINMUX_PA04D_SERCOM0_PAD0);
|
||
|
|
||
|
gpio_set_pin_function(PA05, PINMUX_PA05D_SERCOM0_PAD1);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* \brief USART initialization function
|
||
|
*
|
||
|
* Enables USART peripheral, clocks and initializes USART driver
|
||
|
*/
|
||
|
void USART_0_init(void)
|
||
|
{
|
||
|
USART_0_CLOCK_init();
|
||
|
usart_async_init(&USART_0, SERCOM0, USART_0_buffer, USART_0_BUFFER_SIZE, (void *)NULL);
|
||
|
USART_0_PORT_init();
|
||
|
}
|
||
|
|
||
|
void I2C_0_PORT_init(void)
|
||
|
{
|
||
|
|
||
|
gpio_set_pin_pull_mode(PA22,
|
||
|
// <y> Pull configuration
|
||
|
// <id> pad_pull_config
|
||
|
// <GPIO_PULL_OFF"> Off
|
||
|
// <GPIO_PULL_UP"> Pull-up
|
||
|
// <GPIO_PULL_DOWN"> Pull-down
|
||
|
GPIO_PULL_OFF);
|
||
|
|
||
|
gpio_set_pin_function(PA22, PINMUX_PA22C_SERCOM3_PAD0);
|
||
|
|
||
|
gpio_set_pin_pull_mode(PA23,
|
||
|
// <y> Pull configuration
|
||
|
// <id> pad_pull_config
|
||
|
// <GPIO_PULL_OFF"> Off
|
||
|
// <GPIO_PULL_UP"> Pull-up
|
||
|
// <GPIO_PULL_DOWN"> Pull-down
|
||
|
GPIO_PULL_OFF);
|
||
|
|
||
|
gpio_set_pin_function(PA23, PINMUX_PA23C_SERCOM3_PAD1);
|
||
|
}
|
||
|
|
||
|
void I2C_0_CLOCK_init(void)
|
||
|
{
|
||
|
hri_gclk_write_PCHCTRL_reg(GCLK, SERCOM3_GCLK_ID_CORE, CONF_GCLK_SERCOM3_CORE_SRC | (1 << GCLK_PCHCTRL_CHEN_Pos));
|
||
|
hri_gclk_write_PCHCTRL_reg(GCLK, SERCOM3_GCLK_ID_SLOW, CONF_GCLK_SERCOM3_SLOW_SRC | (1 << GCLK_PCHCTRL_CHEN_Pos));
|
||
|
|
||
|
hri_mclk_set_APBBMASK_SERCOM3_bit(MCLK);
|
||
|
}
|
||
|
|
||
|
void I2C_0_init(void)
|
||
|
{
|
||
|
I2C_0_CLOCK_init();
|
||
|
i2c_m_sync_init(&I2C_0, SERCOM3);
|
||
|
I2C_0_PORT_init();
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* \brief Timer initialization function
|
||
|
*
|
||
|
* Enables Timer peripheral, clocks and initializes Timer driver
|
||
|
*/
|
||
|
static void TIMER_0_init(void)
|
||
|
{
|
||
|
hri_mclk_set_APBAMASK_TC0_bit(MCLK);
|
||
|
hri_gclk_write_PCHCTRL_reg(GCLK, TC0_GCLK_ID, CONF_GCLK_TC0_SRC | (1 << GCLK_PCHCTRL_CHEN_Pos));
|
||
|
|
||
|
timer_init(&TIMER_0, TC0, _tc_get_timer());
|
||
|
}
|
||
|
|
||
|
void system_init(void)
|
||
|
{
|
||
|
init_mcu();
|
||
|
|
||
|
EXTERNAL_IRQ_0_init();
|
||
|
|
||
|
USART_0_init();
|
||
|
|
||
|
I2C_0_init();
|
||
|
|
||
|
TIMER_0_init();
|
||
|
}
|