From d8d2a096742f611e3ade527e7224e8281867c563 Mon Sep 17 00:00:00 2001 From: Joel Challis Date: Tue, 13 Aug 2019 18:23:14 +0100 Subject: Fix LT() crashing some ARM keyboards (#6529) --- tmk_core/common/wait.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tmk_core/common/wait.h') diff --git a/tmk_core/common/wait.h b/tmk_core/common/wait.h index a77840bcef..9aed372b7f 100644 --- a/tmk_core/common/wait.h +++ b/tmk_core/common/wait.h @@ -13,8 +13,8 @@ extern "C" { # define wait_us(us) _delay_us(us) #elif defined PROTOCOL_CHIBIOS # include "ch.h" -# define wait_ms(ms) chThdSleepMilliseconds(ms) -# define wait_us(us) chThdSleepMicroseconds(us) +# define wait_ms(ms) do { if (ms != 0) { chThdSleepMilliseconds(ms); } else { chThdSleepMicroseconds(1); } } while (0) +# define wait_us(us) do { if (us != 0) { chThdSleepMicroseconds(us); } else { chThdSleepMicroseconds(1); } } while (0) #elif defined PROTOCOL_ARM_ATSAM # include "clks.h" # define wait_ms(ms) CLK_delay_ms(ms) -- cgit v1.2.3 From b624f32f944acdc59dcb130674c09090c5c404cb Mon Sep 17 00:00:00 2001 From: skullY Date: Fri, 30 Aug 2019 11:19:03 -0700 Subject: clang-format changes --- tmk_core/common/wait.h | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) (limited to 'tmk_core/common/wait.h') diff --git a/tmk_core/common/wait.h b/tmk_core/common/wait.h index 9aed372b7f..cb1f386a61 100644 --- a/tmk_core/common/wait.h +++ b/tmk_core/common/wait.h @@ -8,22 +8,36 @@ extern "C" { #endif #if defined(__AVR__) -# include -# define wait_ms(ms) _delay_ms(ms) -# define wait_us(us) _delay_us(us) +# include +# define wait_ms(ms) _delay_ms(ms) +# define wait_us(us) _delay_us(us) #elif defined PROTOCOL_CHIBIOS -# include "ch.h" -# define wait_ms(ms) do { if (ms != 0) { chThdSleepMilliseconds(ms); } else { chThdSleepMicroseconds(1); } } while (0) -# define wait_us(us) do { if (us != 0) { chThdSleepMicroseconds(us); } else { chThdSleepMicroseconds(1); } } while (0) +# include "ch.h" +# define wait_ms(ms) \ + do { \ + if (ms != 0) { \ + chThdSleepMilliseconds(ms); \ + } else { \ + chThdSleepMicroseconds(1); \ + } \ + } while (0) +# define wait_us(us) \ + do { \ + if (us != 0) { \ + chThdSleepMicroseconds(us); \ + } else { \ + chThdSleepMicroseconds(1); \ + } \ + } while (0) #elif defined PROTOCOL_ARM_ATSAM -# include "clks.h" -# define wait_ms(ms) CLK_delay_ms(ms) -# define wait_us(us) CLK_delay_us(us) +# include "clks.h" +# define wait_ms(ms) CLK_delay_ms(ms) +# define wait_us(us) CLK_delay_us(us) #elif defined(__arm__) -# include "wait_api.h" +# include "wait_api.h" #else // Unit tests void wait_ms(uint32_t ms); -#define wait_us(us) wait_ms(us / 1000) +# define wait_us(us) wait_ms(us / 1000) #endif #ifdef __cplusplus -- cgit v1.2.3 From 071eb2478f039e21effb981a8a98e6181238b53b Mon Sep 17 00:00:00 2001 From: Joel Challis Date: Wed, 11 Dec 2019 19:36:00 +0000 Subject: Remove mbed files (#7605) * Remove mbed files * Remove mbed files - fix comment * Remove mbed logic blocks --- tmk_core/common/wait.h | 2 -- 1 file changed, 2 deletions(-) (limited to 'tmk_core/common/wait.h') diff --git a/tmk_core/common/wait.h b/tmk_core/common/wait.h index cb1f386a61..c82cd2d65a 100644 --- a/tmk_core/common/wait.h +++ b/tmk_core/common/wait.h @@ -33,8 +33,6 @@ extern "C" { # include "clks.h" # define wait_ms(ms) CLK_delay_ms(ms) # define wait_us(us) CLK_delay_us(us) -#elif defined(__arm__) -# include "wait_api.h" #else // Unit tests void wait_ms(uint32_t ms); # define wait_us(us) wait_ms(us / 1000) -- cgit v1.2.3 From 501f2fdef115314713e94428d409e5c3b5bfc1c2 Mon Sep 17 00:00:00 2001 From: Ryan Date: Fri, 11 Dec 2020 13:45:24 +1100 Subject: Normalise include statements in core code (#11153) * Normalise include statements in core code * Missed one --- tmk_core/common/wait.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tmk_core/common/wait.h') diff --git a/tmk_core/common/wait.h b/tmk_core/common/wait.h index c82cd2d65a..f5ef12ac07 100644 --- a/tmk_core/common/wait.h +++ b/tmk_core/common/wait.h @@ -12,7 +12,7 @@ extern "C" { # define wait_ms(ms) _delay_ms(ms) # define wait_us(us) _delay_us(us) #elif defined PROTOCOL_CHIBIOS -# include "ch.h" +# include # define wait_ms(ms) \ do { \ if (ms != 0) { \ -- cgit v1.2.3 From 1d1d5da43f86d9dded47c66afec94991d623f114 Mon Sep 17 00:00:00 2001 From: Ryan Date: Sat, 26 Dec 2020 15:56:11 +1100 Subject: Change include guards in tmk_core/ and drivers/ to pragma once (#11240) --- tmk_core/common/wait.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'tmk_core/common/wait.h') diff --git a/tmk_core/common/wait.h b/tmk_core/common/wait.h index f5ef12ac07..89128e9daf 100644 --- a/tmk_core/common/wait.h +++ b/tmk_core/common/wait.h @@ -1,5 +1,4 @@ -#ifndef WAIT_H -#define WAIT_H +#pragma once #include @@ -41,5 +40,3 @@ void wait_ms(uint32_t ms); #ifdef __cplusplus } #endif - -#endif -- cgit v1.2.3 From 302b35c2a0ac90208e523944e8cc4b44a793d8d5 Mon Sep 17 00:00:00 2001 From: Takeshi ISHII <2170248+mtei@users.noreply.github.com> Date: Wed, 13 Jan 2021 10:46:22 +0900 Subject: fix matrix_io_delay() timing in quantum/matrix.c (#9603) * fix matrix_io_delay() timing in quantum/matrix.c * Updated comments explaining the need for matrix_io_delay() in quantum/matrix.c * fix matrix_io_delay() timing in quantum/split_common/matrix.c * Update quantum/matrix.c Co-authored-by: Ryan * Update quantum/split_common/matrix.c Co-authored-by: Ryan * Update quantum/matrix.c Co-authored-by: Ryan * Update quantum/split_common/matrix.c Co-authored-by: Ryan * add waitOutputPinValid() and wait_cpuclock() into quantum/quantum.h and tmk_core/common/wait.h * add matrix_output_select_delay() and matrix_output_unselect_delay() * fix quantum/matrix_common.c, tmk_core/common/matrix.h * fix tmk_core/common/wait.h * fix quantum/quantum.h, tmk_core/common/wait.h * waitOutputPinValid() rename to waitInputPinDelay() in quantum/quantum.h. * waitOutputPinValid() rename to waitInputPinDelay() in quantum/matrix_common.c * update tmk_core/common/wait.h * update comment in quantum/matrix.c, quantum/split_common/matrix.c * update quantum/quantum.h: Make more margin in the GPIO_INPUT_PIN_DELAY default value. Co-authored-by: Ryan --- tmk_core/common/wait.h | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 'tmk_core/common/wait.h') diff --git a/tmk_core/common/wait.h b/tmk_core/common/wait.h index 89128e9daf..0b3fd755a9 100644 --- a/tmk_core/common/wait.h +++ b/tmk_core/common/wait.h @@ -6,10 +6,62 @@ extern "C" { #endif +#if defined(__ARMEL__) || defined(__ARMEB__) +# ifndef __OPTIMIZE__ +# pragma message "Compiler optimizations disabled; wait_cpuclock() won't work as designed" +# endif + +# define wait_cpuclock(x) wait_cpuclock_allnop(x) + +# define CLOCK_DELAY_NOP8 "nop\n\t nop\n\t nop\n\t nop\n\t nop\n\t nop\n\t nop\n\t nop\n\t" + +__attribute__((always_inline)) +static inline void wait_cpuclock_allnop(unsigned int n) { /* n: 1..135 */ + /* The argument n must be a constant expression. + * That way, compiler optimization will remove unnecessary code. */ + if (n < 1) { return; } + if (n > 8) { + unsigned int n8 = n/8; + n = n - n8*8; + switch (n8) { + case 16: asm volatile (CLOCK_DELAY_NOP8::: "memory"); + case 15: asm volatile (CLOCK_DELAY_NOP8::: "memory"); + case 14: asm volatile (CLOCK_DELAY_NOP8::: "memory"); + case 13: asm volatile (CLOCK_DELAY_NOP8::: "memory"); + case 12: asm volatile (CLOCK_DELAY_NOP8::: "memory"); + case 11: asm volatile (CLOCK_DELAY_NOP8::: "memory"); + case 10: asm volatile (CLOCK_DELAY_NOP8::: "memory"); + case 9: asm volatile (CLOCK_DELAY_NOP8::: "memory"); + case 8: asm volatile (CLOCK_DELAY_NOP8::: "memory"); + case 7: asm volatile (CLOCK_DELAY_NOP8::: "memory"); + case 6: asm volatile (CLOCK_DELAY_NOP8::: "memory"); + case 5: asm volatile (CLOCK_DELAY_NOP8::: "memory"); + case 4: asm volatile (CLOCK_DELAY_NOP8::: "memory"); + case 3: asm volatile (CLOCK_DELAY_NOP8::: "memory"); + case 2: asm volatile (CLOCK_DELAY_NOP8::: "memory"); + case 1: asm volatile (CLOCK_DELAY_NOP8::: "memory"); + case 0: break; + } + } + switch (n) { + case 8: asm volatile ("nop"::: "memory"); + case 7: asm volatile ("nop"::: "memory"); + case 6: asm volatile ("nop"::: "memory"); + case 5: asm volatile ("nop"::: "memory"); + case 4: asm volatile ("nop"::: "memory"); + case 3: asm volatile ("nop"::: "memory"); + case 2: asm volatile ("nop"::: "memory"); + case 1: asm volatile ("nop"::: "memory"); + case 0: break; + } +} +#endif + #if defined(__AVR__) # include # define wait_ms(ms) _delay_ms(ms) # define wait_us(us) _delay_us(us) +# define wait_cpuclock(x) __builtin_avr_delay_cycles(x) #elif defined PROTOCOL_CHIBIOS # include # define wait_ms(ms) \ -- cgit v1.2.3 From 31c57aab35e6fd49c4c8336f449419afe7630e93 Mon Sep 17 00:00:00 2001 From: Nick Brassel Date: Mon, 18 Jan 2021 05:12:15 +1100 Subject: `qmk cformat` --- tmk_core/common/wait.h | 89 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 58 insertions(+), 31 deletions(-) (limited to 'tmk_core/common/wait.h') diff --git a/tmk_core/common/wait.h b/tmk_core/common/wait.h index 0b3fd755a9..28224fe3aa 100644 --- a/tmk_core/common/wait.h +++ b/tmk_core/common/wait.h @@ -15,44 +15,71 @@ extern "C" { # define CLOCK_DELAY_NOP8 "nop\n\t nop\n\t nop\n\t nop\n\t nop\n\t nop\n\t nop\n\t nop\n\t" -__attribute__((always_inline)) -static inline void wait_cpuclock_allnop(unsigned int n) { /* n: 1..135 */ +__attribute__((always_inline)) static inline void wait_cpuclock_allnop(unsigned int n) { /* n: 1..135 */ /* The argument n must be a constant expression. * That way, compiler optimization will remove unnecessary code. */ - if (n < 1) { return; } + if (n < 1) { + return; + } if (n > 8) { - unsigned int n8 = n/8; - n = n - n8*8; + unsigned int n8 = n / 8; + n = n - n8 * 8; switch (n8) { - case 16: asm volatile (CLOCK_DELAY_NOP8::: "memory"); - case 15: asm volatile (CLOCK_DELAY_NOP8::: "memory"); - case 14: asm volatile (CLOCK_DELAY_NOP8::: "memory"); - case 13: asm volatile (CLOCK_DELAY_NOP8::: "memory"); - case 12: asm volatile (CLOCK_DELAY_NOP8::: "memory"); - case 11: asm volatile (CLOCK_DELAY_NOP8::: "memory"); - case 10: asm volatile (CLOCK_DELAY_NOP8::: "memory"); - case 9: asm volatile (CLOCK_DELAY_NOP8::: "memory"); - case 8: asm volatile (CLOCK_DELAY_NOP8::: "memory"); - case 7: asm volatile (CLOCK_DELAY_NOP8::: "memory"); - case 6: asm volatile (CLOCK_DELAY_NOP8::: "memory"); - case 5: asm volatile (CLOCK_DELAY_NOP8::: "memory"); - case 4: asm volatile (CLOCK_DELAY_NOP8::: "memory"); - case 3: asm volatile (CLOCK_DELAY_NOP8::: "memory"); - case 2: asm volatile (CLOCK_DELAY_NOP8::: "memory"); - case 1: asm volatile (CLOCK_DELAY_NOP8::: "memory"); - case 0: break; + case 16: + asm volatile(CLOCK_DELAY_NOP8::: "memory"); + case 15: + asm volatile(CLOCK_DELAY_NOP8::: "memory"); + case 14: + asm volatile(CLOCK_DELAY_NOP8::: "memory"); + case 13: + asm volatile(CLOCK_DELAY_NOP8::: "memory"); + case 12: + asm volatile(CLOCK_DELAY_NOP8::: "memory"); + case 11: + asm volatile(CLOCK_DELAY_NOP8::: "memory"); + case 10: + asm volatile(CLOCK_DELAY_NOP8::: "memory"); + case 9: + asm volatile(CLOCK_DELAY_NOP8::: "memory"); + case 8: + asm volatile(CLOCK_DELAY_NOP8::: "memory"); + case 7: + asm volatile(CLOCK_DELAY_NOP8::: "memory"); + case 6: + asm volatile(CLOCK_DELAY_NOP8::: "memory"); + case 5: + asm volatile(CLOCK_DELAY_NOP8::: "memory"); + case 4: + asm volatile(CLOCK_DELAY_NOP8::: "memory"); + case 3: + asm volatile(CLOCK_DELAY_NOP8::: "memory"); + case 2: + asm volatile(CLOCK_DELAY_NOP8::: "memory"); + case 1: + asm volatile(CLOCK_DELAY_NOP8::: "memory"); + case 0: + break; } } switch (n) { - case 8: asm volatile ("nop"::: "memory"); - case 7: asm volatile ("nop"::: "memory"); - case 6: asm volatile ("nop"::: "memory"); - case 5: asm volatile ("nop"::: "memory"); - case 4: asm volatile ("nop"::: "memory"); - case 3: asm volatile ("nop"::: "memory"); - case 2: asm volatile ("nop"::: "memory"); - case 1: asm volatile ("nop"::: "memory"); - case 0: break; + case 8: + asm volatile("nop" ::: "memory"); + case 7: + asm volatile("nop" ::: "memory"); + case 6: + asm volatile("nop" ::: "memory"); + case 5: + asm volatile("nop" ::: "memory"); + case 4: + asm volatile("nop" ::: "memory"); + case 3: + asm volatile("nop" ::: "memory"); + case 2: + asm volatile("nop" ::: "memory"); + case 1: + asm volatile("nop" ::: "memory"); + case 0: + break; } } #endif -- cgit v1.2.3