You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
2.2 KiB

  1. /* Copyright 2021 QMK
  2. *
  3. * This program is free software: you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation, either version 3 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #pragma once
  17. #include <ch.h>
  18. #include <hal.h>
  19. /* chThdSleepX of zero maps to infinite - so we map to a tiny delay to still yield */
  20. #define wait_ms(ms) \
  21. do { \
  22. if (ms != 0) { \
  23. chThdSleepMilliseconds(ms); \
  24. } else { \
  25. chThdSleepMicroseconds(1); \
  26. } \
  27. } while (0)
  28. #ifdef WAIT_US_TIMER
  29. void wait_us(uint16_t duration);
  30. #else
  31. # define wait_us(us) \
  32. do { \
  33. if (us != 0) { \
  34. chThdSleepMicroseconds(us); \
  35. } else { \
  36. chThdSleepMicroseconds(1); \
  37. } \
  38. } while (0)
  39. #endif
  40. #include "_wait.c"
  41. /* For GPIOs on ARM-based MCUs, the input pins are sampled by the clock of the bus
  42. * to which the GPIO is connected.
  43. * The connected buses differ depending on the various series of MCUs.
  44. * And since the instruction execution clock of the CPU and the bus clock of GPIO are different,
  45. * there is a delay of several clocks to read the change of the input signal.
  46. *
  47. * Define this delay with the GPIO_INPUT_PIN_DELAY macro.
  48. * If the GPIO_INPUT_PIN_DELAY macro is not defined, the following default values will be used.
  49. * (A fairly large value of 0.25 microseconds is set.)
  50. */
  51. #ifndef GPIO_INPUT_PIN_DELAY
  52. # define GPIO_INPUT_PIN_DELAY (CPU_CLOCK / 1000000L / 4)
  53. #endif
  54. #define waitInputPinDelay() wait_cpuclock(GPIO_INPUT_PIN_DELAY)