From 6d2e5cd69754b45ec0aa7b4559709a461e376578 Mon Sep 17 00:00:00 2001 From: Joey Castillo Date: Fri, 30 Jul 2021 13:49:09 -0400 Subject: use atmel studio's configuration and init --- Sensor Watch Starter Project/hw/atmel_start_pins.h | 67 ++++++++++++++++++ Sensor Watch Starter Project/hw/driver_init.c | 0 Sensor Watch Starter Project/hw/driver_init.h | 80 ++++++++++++++++++++++ Sensor Watch Starter Project/main.c | 11 ++- Sensor Watch Starter Project/make/Makefile | 4 +- 5 files changed, 153 insertions(+), 9 deletions(-) create mode 100644 Sensor Watch Starter Project/hw/atmel_start_pins.h create mode 100644 Sensor Watch Starter Project/hw/driver_init.c create mode 100644 Sensor Watch Starter Project/hw/driver_init.h diff --git a/Sensor Watch Starter Project/hw/atmel_start_pins.h b/Sensor Watch Starter Project/hw/atmel_start_pins.h new file mode 100644 index 00000000..36fe6bf4 --- /dev/null +++ b/Sensor Watch Starter Project/hw/atmel_start_pins.h @@ -0,0 +1,67 @@ +/* + * 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. + */ +#ifndef ATMEL_START_PINS_H_INCLUDED +#define ATMEL_START_PINS_H_INCLUDED + +#include + +// SAML22 has 9 pin functions + +#define GPIO_PIN_FUNCTION_A 0 +#define GPIO_PIN_FUNCTION_B 1 +#define GPIO_PIN_FUNCTION_C 2 +#define GPIO_PIN_FUNCTION_D 3 +#define GPIO_PIN_FUNCTION_E 4 +#define GPIO_PIN_FUNCTION_F 5 +#define GPIO_PIN_FUNCTION_G 6 +#define GPIO_PIN_FUNCTION_H 7 +#define GPIO_PIN_FUNCTION_I 8 + +#define VBUS_DET GPIO(GPIO_PORTA, 2) +#define SEG1 GPIO(GPIO_PORTA, 4) +#define SEG2 GPIO(GPIO_PORTA, 5) +#define SEG3 GPIO(GPIO_PORTA, 6) +#define SEG4 GPIO(GPIO_PORTA, 7) +#define SEG5 GPIO(GPIO_PORTA, 8) +#define SEG6 GPIO(GPIO_PORTA, 9) +#define SEG7 GPIO(GPIO_PORTA, 10) +#define SEG8 GPIO(GPIO_PORTA, 11) +#define SEG14 GPIO(GPIO_PORTA, 12) +#define SEG15 GPIO(GPIO_PORTA, 13) +#define SEG16 GPIO(GPIO_PORTA, 14) +#define SEG17 GPIO(GPIO_PORTA, 15) +#define SEG18 GPIO(GPIO_PORTA, 16) +#define SEG19 GPIO(GPIO_PORTA, 17) +#define SEG20 GPIO(GPIO_PORTA, 18) +#define SEG21 GPIO(GPIO_PORTA, 19) +#define RED GPIO(GPIO_PORTA, 20) +#define GREEN GPIO(GPIO_PORTA, 21) +#define BTN_LIGHT GPIO(GPIO_PORTA, 22) +#define BTN_MODE GPIO(GPIO_PORTA, 23) +#define BUZZER GPIO(GPIO_PORTA, 27) +#define D1 GPIO(GPIO_PORTB, 0) +#define A1 GPIO(GPIO_PORTB, 1) +#define A2 GPIO(GPIO_PORTB, 2) +#define D0 GPIO(GPIO_PORTB, 3) +#define A0 GPIO(GPIO_PORTB, 4) +#define BTN_ALARM GPIO(GPIO_PORTB, 5) +#define COM0 GPIO(GPIO_PORTB, 6) +#define COM1 GPIO(GPIO_PORTB, 7) +#define COM2 GPIO(GPIO_PORTB, 8) +#define SEG0 GPIO(GPIO_PORTB, 9) +#define SEG9 GPIO(GPIO_PORTB, 11) +#define SEG10 GPIO(GPIO_PORTB, 12) +#define SEG11 GPIO(GPIO_PORTB, 13) +#define SEG12 GPIO(GPIO_PORTB, 14) +#define SEG13 GPIO(GPIO_PORTB, 15) +#define SEG22 GPIO(GPIO_PORTB, 16) +#define SEG23 GPIO(GPIO_PORTB, 17) +#define SDA GPIO(GPIO_PORTB, 30) +#define SCL GPIO(GPIO_PORTB, 31) + +#endif // ATMEL_START_PINS_H_INCLUDED diff --git a/Sensor Watch Starter Project/hw/driver_init.c b/Sensor Watch Starter Project/hw/driver_init.c new file mode 100644 index 00000000..e69de29b diff --git a/Sensor Watch Starter Project/hw/driver_init.h b/Sensor Watch Starter Project/hw/driver_init.h new file mode 100644 index 00000000..1e53f9a0 --- /dev/null +++ b/Sensor Watch Starter Project/hw/driver_init.h @@ -0,0 +1,80 @@ +/* + * 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. + */ +#ifndef DRIVER_INIT_INCLUDED +#define DRIVER_INIT_INCLUDED + +#include "atmel_start_pins.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include +#include +#include +#include + +#include + +#include + +#include + +#include + +#include +#include +#include +#include + +#include +#include +#include + +extern struct adc_sync_descriptor ADC_0; + +extern struct calendar_descriptor CALENDAR_0; + +extern struct i2c_m_sync_desc I2C_0; + +extern struct pwm_descriptor PWM_0; + +extern struct pwm_descriptor PWM_1; +extern struct slcd_sync_descriptor SEGMENT_LCD_0; + +void ADC_0_PORT_init(void); +void ADC_0_CLOCK_init(void); +void ADC_0_init(void); + +void CALENDAR_0_CLOCK_init(void); +void CALENDAR_0_init(void); + +void I2C_0_CLOCK_init(void); +void I2C_0_init(void); +void I2C_0_PORT_init(void); + +void delay_driver_init(void); + +void PWM_0_PORT_init(void); +void PWM_0_CLOCK_init(void); +void PWM_0_init(void); + +void PWM_1_PORT_init(void); +void PWM_1_CLOCK_init(void); +void PWM_1_init(void); + +void EXTERNAL_IRQ_0_init(void); + +void SEGMENT_LCD_0_init(void); + +#ifdef __cplusplus +} +#endif +#endif // DRIVER_INIT_INCLUDED diff --git a/Sensor Watch Starter Project/main.c b/Sensor Watch Starter Project/main.c index 2ced0560..07f3be90 100755 --- a/Sensor Watch Starter Project/main.c +++ b/Sensor Watch Starter Project/main.c @@ -33,6 +33,8 @@ #include #include #include "saml22.h" +#include "hal_init.h" +#include "peripheral_clk_config.h" #include "hal_gpio.h" //----------------------------------------------------------------------------- @@ -42,7 +44,7 @@ HAL_GPIO_PIN(UART_RX, B, 2) //----------------------------------------------------------------------------- static void uart_init(uint32_t baud) { - uint64_t br = (uint64_t)65536 * (F_CPU - 16 * baud) / F_CPU; + uint64_t br = (uint64_t)65536 * (CONF_CPU_FREQUENCY - 16 * baud) / CONF_CPU_FREQUENCY; HAL_GPIO_UART_TX_out(); HAL_GPIO_UART_TX_pmuxen(HAL_GPIO_PMUX_C); @@ -79,12 +81,7 @@ static void uart_puts(char *s) { //----------------------------------------------------------------------------- static void sys_init(void) { - // Switch to 16MHz clock (disable prescaler) - OSCCTRL->OSC16MCTRL.reg = OSCCTRL_OSC16MCTRL_ENABLE | OSCCTRL_OSC16MCTRL_FSEL_16; - // Switch to the highest performance level - PM->INTFLAG.reg = PM_INTFLAG_PLRDY; - PM->PLCFG.reg = PM_PLCFG_PLSEL_PL2_Val; - while (!PM->INTFLAG.reg); + init_mcu(); } //----------------------------------------------------------------------------- diff --git a/Sensor Watch Starter Project/make/Makefile b/Sensor Watch Starter Project/make/Makefile index b3920644..7a402524 100755 --- a/Sensor Watch Starter Project/make/Makefile +++ b/Sensor Watch Starter Project/make/Makefile @@ -55,6 +55,7 @@ INCLUDES += \ -I../hpl/tc/ \ -I../hri/ \ -I../config/ \ + -I../hw/ \ -I.. SRCS += \ @@ -95,8 +96,7 @@ SRCS += \ DEFINES += \ -D__SAML22J18A__ \ - -DDONT_USE_CMSIS_INIT \ - -DF_CPU=16000000 + -DDONT_USE_CMSIS_INIT CFLAGS += $(INCLUDES) $(DEFINES) -- cgit v1.2.3