2018-08-29 21:07:52 +02:00
|
|
|
/*
|
|
|
|
Copyright 2018 Massdrop Inc.
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _CLKS_H_
|
|
|
|
#define _CLKS_H_
|
|
|
|
|
|
|
|
#ifndef MD_BOOTLOADER
|
|
|
|
|
2019-08-30 20:19:03 +02:00
|
|
|
// From keyboard
|
|
|
|
# include "config_led.h"
|
|
|
|
# include "config.h"
|
2018-08-29 21:07:52 +02:00
|
|
|
|
2019-08-30 20:19:03 +02:00
|
|
|
#endif // MD_BOOTLOADER
|
2018-08-29 21:07:52 +02:00
|
|
|
|
2019-08-30 20:19:03 +02:00
|
|
|
#define PLL_RATIO 47 // mcu frequency ((X+1)MHz)
|
|
|
|
#define FREQ_DFLL_DEFAULT 48000000 // DFLL frequency / usb clock
|
|
|
|
#define FREQ_SPI_DEFAULT 1000000 // spi to 595 shift regs
|
|
|
|
#define FREQ_I2C0_DEFAULT 100000 // i2c to hub
|
|
|
|
#define FREQ_I2C1_DEFAULT I2C_HZ // i2c to LED drivers
|
|
|
|
#define FREQ_TC45_DEFAULT 1000000 // 1 usec resolution
|
2018-08-29 21:07:52 +02:00
|
|
|
|
2019-08-30 20:19:03 +02:00
|
|
|
// I2C1 Set ~Result PWM Time (2x Drivers)
|
2018-08-29 21:07:52 +02:00
|
|
|
// 1000000 1090000
|
|
|
|
// 900000 1000000 3.82ms
|
|
|
|
// 800000 860000
|
|
|
|
// 700000 750000
|
|
|
|
// 600000 630000
|
|
|
|
// 580000 615000 6.08ms
|
|
|
|
// 500000 522000
|
|
|
|
|
2019-08-30 20:19:03 +02:00
|
|
|
#define FREQ_XOSC0 16000000
|
2018-08-29 21:07:52 +02:00
|
|
|
|
2019-08-30 20:19:03 +02:00
|
|
|
#define CHAN_SERCOM_SPI 2 // shift regs
|
|
|
|
#define CHAN_SERCOM_I2C0 0 // hub
|
|
|
|
#define CHAN_SERCOM_I2C1 1 // led drivers
|
|
|
|
#define CHAN_SERCOM_UART 3 // debug util
|
2018-08-29 21:07:52 +02:00
|
|
|
|
2019-08-30 20:19:03 +02:00
|
|
|
// Generator clock channels
|
|
|
|
#define GEN_DPLL0 0
|
|
|
|
#define GEN_OSC0 1
|
|
|
|
#define GEN_TC45 2
|
2018-08-29 21:07:52 +02:00
|
|
|
|
|
|
|
#define SERCOM_COUNT 5
|
2019-08-30 20:19:03 +02:00
|
|
|
#define GCLK_COUNT 12
|
2018-08-29 21:07:52 +02:00
|
|
|
|
|
|
|
typedef struct clk_s {
|
|
|
|
uint32_t freq_dfll;
|
|
|
|
uint32_t freq_dpll[2];
|
|
|
|
uint32_t freq_sercom[SERCOM_COUNT];
|
|
|
|
uint32_t freq_gclk[GCLK_COUNT];
|
|
|
|
uint32_t freq_xosc0;
|
|
|
|
uint32_t freq_spi;
|
|
|
|
uint32_t freq_i2c0;
|
|
|
|
uint32_t freq_i2c1;
|
|
|
|
uint32_t freq_uart;
|
|
|
|
uint32_t freq_adc0;
|
|
|
|
} clk_t;
|
|
|
|
|
2019-08-30 20:19:03 +02:00
|
|
|
extern volatile clk_t system_clks;
|
2018-08-29 21:07:52 +02:00
|
|
|
extern volatile uint64_t ms_clk;
|
|
|
|
|
2019-08-30 20:19:03 +02:00
|
|
|
void CLK_oscctrl_init(void);
|
|
|
|
void CLK_reset_time(void);
|
2018-08-29 21:07:52 +02:00
|
|
|
uint32_t CLK_set_gclk_freq(uint8_t gclkn, uint32_t freq);
|
|
|
|
uint32_t CLK_enable_timebase(void);
|
2018-12-18 21:21:25 +01:00
|
|
|
uint64_t timer_read64(void);
|
2019-08-30 20:19:03 +02:00
|
|
|
void CLK_delay_us(uint32_t usec);
|
|
|
|
void CLK_delay_ms(uint64_t msec);
|
2018-08-29 21:07:52 +02:00
|
|
|
|
|
|
|
uint32_t CLK_set_spi_freq(uint8_t sercomn, uint32_t freq);
|
|
|
|
uint32_t CLK_set_i2c0_freq(uint8_t sercomn, uint32_t freq);
|
|
|
|
uint32_t CLK_set_i2c1_freq(uint8_t sercomn, uint32_t freq);
|
2019-08-30 20:19:03 +02:00
|
|
|
void CLK_init(void);
|
2018-08-29 21:07:52 +02:00
|
|
|
|
2019-08-30 20:19:03 +02:00
|
|
|
#endif // _CLKS_H_
|