]> git.earman.xyz Git - sensor-watch.git/commitdiff
use atmel studio's configuration and init
authorJoey Castillo <jose.castillo@gmail.com>
Fri, 30 Jul 2021 17:49:09 +0000 (13:49 -0400)
committerJoey Castillo <jose.castillo@gmail.com>
Fri, 30 Jul 2021 17:49:09 +0000 (13:49 -0400)
Sensor Watch Starter Project/hw/atmel_start_pins.h [new file with mode: 0644]
Sensor Watch Starter Project/hw/driver_init.c [new file with mode: 0644]
Sensor Watch Starter Project/hw/driver_init.h [new file with mode: 0644]
Sensor Watch Starter Project/main.c
Sensor Watch Starter Project/make/Makefile

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 (file)
index 0000000..36fe6bf
--- /dev/null
@@ -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 <hal_gpio.h>
+
+// 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 (file)
index 0000000..e69de29
diff --git a/Sensor Watch Starter Project/hw/driver_init.h b/Sensor Watch Starter Project/hw/driver_init.h
new file mode 100644 (file)
index 0000000..1e53f9a
--- /dev/null
@@ -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 <hal_atomic.h>
+#include <hal_delay.h>
+#include <hal_gpio.h>
+#include <hal_init.h>
+#include <hal_io.h>
+#include <hal_sleep.h>
+
+#include <hal_adc_sync.h>
+
+#include <hal_ext_irq.h>
+
+#include <hal_calendar.h>
+
+#include <hal_i2c_m_sync.h>
+
+#include <hal_delay.h>
+#include <hpl_tc_base.h>
+#include <hal_pwm.h>
+#include <hpl_tc_base.h>
+
+#include <hal_pwm.h>
+#include <hpl_tcc.h>
+#include <hal_slcd_sync.h>
+
+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
index 2ced056038d3cf6eca0060ba20e7af4bbab91db9..07f3be901ddd322c8757fa101b19c31daa39a9fc 100755 (executable)
@@ -33,6 +33,8 @@
 #include <stdbool.h>
 #include <string.h>
 #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();
 }
 
 //-----------------------------------------------------------------------------
index b3920644ed5dff1dfa3263bd56040d4006301a14..7a40252433803960e832d25203231380999b703c 100755 (executable)
@@ -55,6 +55,7 @@ INCLUDES += \
   -I../hpl/tc/ \\r
   -I../hri/ \\r
   -I../config/ \\r
+  -I../hw/ \\r
   -I..\r
 \r
 SRCS += \\r
@@ -95,8 +96,7 @@ SRCS += \
 \r
 DEFINES += \\r
   -D__SAML22J18A__ \\r
-  -DDONT_USE_CMSIS_INIT \\r
-  -DF_CPU=16000000\r
+  -DDONT_USE_CMSIS_INIT\r
 \r
 CFLAGS += $(INCLUDES) $(DEFINES)\r
 \r