2 Copyright 2018 Massdrop Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include "config_led.h"
27 #endif //MD_BOOTLOADER
29 #define PLL_RATIO 47 //mcu frequency ((X+1)MHz)
30 #define FREQ_DFLL_DEFAULT 48000000 //DFLL frequency / usb clock
31 #define FREQ_SPI_DEFAULT 1000000 //spi to 595 shift regs
32 #define FREQ_I2C0_DEFAULT 100000 //i2c to hub
33 #define FREQ_I2C1_DEFAULT I2C_HZ //i2c to LED drivers
34 #define FREQ_TC45_DEFAULT 1000000 //1 usec resolution
36 //I2C1 Set ~Result PWM Time (2x Drivers)
38 // 900000 1000000 3.82ms
42 // 580000 615000 6.08ms
45 #define FREQ_XOSC0 16000000
47 #define CHAN_SERCOM_SPI 2 //shift regs
48 #define CHAN_SERCOM_I2C0 0 //hub
49 #define CHAN_SERCOM_I2C1 1 //led drivers
50 #define CHAN_SERCOM_UART 3 //debug util
52 //Generator clock channels
57 #define SERCOM_COUNT 5
60 typedef struct clk_s {
62 uint32_t freq_dpll[2];
63 uint32_t freq_sercom[SERCOM_COUNT];
64 uint32_t freq_gclk[GCLK_COUNT];
73 extern volatile clk_t system_clks;
74 extern volatile uint64_t ms_clk;
76 void CLK_oscctrl_init(void);
77 void CLK_reset_time(void);
78 uint32_t CLK_set_gclk_freq(uint8_t gclkn, uint32_t freq);
79 uint32_t CLK_enable_timebase(void);
80 uint32_t CLK_get_ms(void);
81 uint64_t CLK_get_us(void);
82 void CLK_delay_us(uint16_t usec);
83 void CLK_delay_ms(uint64_t msec);
85 uint32_t CLK_set_spi_freq(uint8_t sercomn, uint32_t freq);
86 uint32_t CLK_set_i2c0_freq(uint8_t sercomn, uint32_t freq);
87 uint32_t CLK_set_i2c1_freq(uint8_t sercomn, uint32_t freq);