aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Challis <git@zvecr.com>2021-09-14 03:18:36 +0100
committerGitHub <noreply@github.com>2021-09-14 12:18:36 +1000
commit0ca4a56a0449d17a497ba610d4cee41c914ff50e (patch)
tree5e10d1ced8cf84e673f5e3ae88457de32d4943dd
parent232bc23a89874d1a2e028a1414dd34cf0339f8d2 (diff)
downloadqmk_firmware-0ca4a56a0449d17a497ba610d4cee41c914ff50e.tar.gz
qmk_firmware-0ca4a56a0449d17a497ba610d4cee41c914ff50e.zip
Refactor use of STM32_SYSCLK (#14430)
* Refactor use of STM32_SYSCLK * clang
-rw-r--r--drivers/led/apa102.c2
-rw-r--r--platforms/chibios/drivers/serial.c2
-rw-r--r--platforms/chibios/drivers/ws2812.c2
-rw-r--r--platforms/chibios/drivers/ws2812_pwm.c2
-rw-r--r--tmk_core/common/chibios/_wait.h2
-rw-r--r--tmk_core/common/chibios/chibios_config.h16
6 files changed, 14 insertions, 12 deletions
diff --git a/drivers/led/apa102.c b/drivers/led/apa102.c
index 7396dc3c5..19e0bfc18 100644
--- a/drivers/led/apa102.c
+++ b/drivers/led/apa102.c
@@ -25,7 +25,7 @@
25 25
26# include "hal.h" 26# include "hal.h"
27# if defined(STM32F0XX) || defined(STM32F1XX) || defined(STM32F3XX) || defined(STM32F4XX) || defined(STM32L0XX) 27# if defined(STM32F0XX) || defined(STM32F1XX) || defined(STM32F3XX) || defined(STM32F4XX) || defined(STM32L0XX)
28# define APA102_NOPS (100 / (1000000000L / (STM32_SYSCLK / 4))) // This calculates how many loops of 4 nops to run to delay 100 ns 28# define APA102_NOPS (100 / (1000000000L / (CPU_CLOCK / 4))) // This calculates how many loops of 4 nops to run to delay 100 ns
29# else 29# else
30# error("APA102_NOPS configuration required") 30# error("APA102_NOPS configuration required")
31# define APA102_NOPS 0 // this just pleases the compile so the above error is easier to spot 31# define APA102_NOPS 0 // this just pleases the compile so the above error is easier to spot
diff --git a/platforms/chibios/drivers/serial.c b/platforms/chibios/drivers/serial.c
index f54fbcee4..ef6f0aa8d 100644
--- a/platforms/chibios/drivers/serial.c
+++ b/platforms/chibios/drivers/serial.c
@@ -19,7 +19,7 @@
19# error "chSysPolledDelayX method not supported on this platform" 19# error "chSysPolledDelayX method not supported on this platform"
20#else 20#else
21# undef wait_us 21# undef wait_us
22# define wait_us(x) chSysPolledDelayX(US2RTC(STM32_SYSCLK, x)) 22# define wait_us(x) chSysPolledDelayX(US2RTC(CPU_CLOCK, x))
23#endif 23#endif
24 24
25#ifndef SELECT_SOFT_SERIAL_SPEED 25#ifndef SELECT_SOFT_SERIAL_SPEED
diff --git a/platforms/chibios/drivers/ws2812.c b/platforms/chibios/drivers/ws2812.c
index 0d12e2fb7..ffcdcff24 100644
--- a/platforms/chibios/drivers/ws2812.c
+++ b/platforms/chibios/drivers/ws2812.c
@@ -23,7 +23,7 @@
23#endif 23#endif
24 24
25#define NUMBER_NOPS 6 25#define NUMBER_NOPS 6
26#define CYCLES_PER_SEC (STM32_SYSCLK / NUMBER_NOPS * NOP_FUDGE) 26#define CYCLES_PER_SEC (CPU_CLOCK / NUMBER_NOPS * NOP_FUDGE)
27#define NS_PER_SEC (1000000000L) // Note that this has to be SIGNED since we want to be able to check for negative values of derivatives 27#define NS_PER_SEC (1000000000L) // Note that this has to be SIGNED since we want to be able to check for negative values of derivatives
28#define NS_PER_CYCLE (NS_PER_SEC / CYCLES_PER_SEC) 28#define NS_PER_CYCLE (NS_PER_SEC / CYCLES_PER_SEC)
29#define NS_TO_CYCLES(n) ((n) / NS_PER_CYCLE) 29#define NS_TO_CYCLES(n) ((n) / NS_PER_CYCLE)
diff --git a/platforms/chibios/drivers/ws2812_pwm.c b/platforms/chibios/drivers/ws2812_pwm.c
index e6af55b6b..e7080b036 100644
--- a/platforms/chibios/drivers/ws2812_pwm.c
+++ b/platforms/chibios/drivers/ws2812_pwm.c
@@ -59,7 +59,7 @@
59 59
60/* --- PRIVATE CONSTANTS ---------------------------------------------------- */ 60/* --- PRIVATE CONSTANTS ---------------------------------------------------- */
61 61
62#define WS2812_PWM_FREQUENCY (STM32_SYSCLK / 2) /**< Clock frequency of PWM, must be valid with respect to system clock! */ 62#define WS2812_PWM_FREQUENCY (CPU_CLOCK / 2) /**< Clock frequency of PWM, must be valid with respect to system clock! */
63#define WS2812_PWM_PERIOD (WS2812_PWM_FREQUENCY / WS2812_PWM_TARGET_PERIOD) /**< Clock period in ticks. 1 / 800kHz = 1.25 uS (as per datasheet) */ 63#define WS2812_PWM_PERIOD (WS2812_PWM_FREQUENCY / WS2812_PWM_TARGET_PERIOD) /**< Clock period in ticks. 1 / 800kHz = 1.25 uS (as per datasheet) */
64 64
65/** 65/**
diff --git a/tmk_core/common/chibios/_wait.h b/tmk_core/common/chibios/_wait.h
index b740afbd2..2f36c64a2 100644
--- a/tmk_core/common/chibios/_wait.h
+++ b/tmk_core/common/chibios/_wait.h
@@ -43,8 +43,6 @@ void wait_us(uint16_t duration);
43 43
44#include "_wait.c" 44#include "_wait.c"
45 45
46#define CPU_CLOCK STM32_SYSCLK
47
48/* For GPIOs on ARM-based MCUs, the input pins are sampled by the clock of the bus 46/* For GPIOs on ARM-based MCUs, the input pins are sampled by the clock of the bus
49 * to which the GPIO is connected. 47 * to which the GPIO is connected.
50 * The connected buses differ depending on the various series of MCUs. 48 * The connected buses differ depending on the various series of MCUs.
diff --git a/tmk_core/common/chibios/chibios_config.h b/tmk_core/common/chibios/chibios_config.h
index 23c65f942..4515b025d 100644
--- a/tmk_core/common/chibios/chibios_config.h
+++ b/tmk_core/common/chibios/chibios_config.h
@@ -19,6 +19,11 @@
19# define SPLIT_USB_DETECT // Force this on when dedicated pin is not used 19# define SPLIT_USB_DETECT // Force this on when dedicated pin is not used
20#endif 20#endif
21 21
22// STM32 compatibility
23#if defined(MCU_STM32)
24# define CPU_CLOCK STM32_SYSCLK
25#endif
26
22#if defined(STM32F1XX) 27#if defined(STM32F1XX)
23# define USE_GPIOV1 28# define USE_GPIOV1
24#endif 29#endif
@@ -27,14 +32,13 @@
27# define USE_I2CV1 32# define USE_I2CV1
28#endif 33#endif
29 34
30// teensy 35// teensy compatibility
36#if defined(MCU_KINETIS)
37# define CPU_CLOCK KINETIS_SYSCLK_FREQUENCY
38#endif
39
31#if defined(K20x) || defined(KL2x) 40#if defined(K20x) || defined(KL2x)
32# define USE_I2CV1 41# define USE_I2CV1
33# define USE_I2CV1_CONTRIB // for some reason a bunch of ChibiOS-Contrib boards only have clock_speed 42# define USE_I2CV1_CONTRIB // for some reason a bunch of ChibiOS-Contrib boards only have clock_speed
34# define USE_GPIOV1 43# define USE_GPIOV1
35# define STM32_SYSCLK KINETIS_SYSCLK_FREQUENCY
36#endif
37
38#if defined(MK66F18)
39# define STM32_SYSCLK KINETIS_SYSCLK_FREQUENCY
40#endif 44#endif