Kiibohd Controller
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.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #ifndef __DELAY_H
  2. #define __DELAY_H
  3. #include <stdint.h>
  4. // Convenience Macros, for delay compatibility with AVR-GCC
  5. #define _delay_ms(val) delay( val )
  6. #define _delay_us(val) delayMicroseconds( val )
  7. // the systick interrupt is supposed to increment this at 1 kHz rate
  8. extern volatile uint32_t systick_millis_count;
  9. static inline uint32_t millis(void) __attribute__((always_inline, unused));
  10. static inline uint32_t millis(void)
  11. {
  12. return systick_millis_count; // single aligned 32 bit is atomic;
  13. }
  14. static inline void delayMicroseconds(uint32_t) __attribute__((always_inline, unused));
  15. static inline void delayMicroseconds(uint32_t usec)
  16. {
  17. #if F_CPU == 96000000
  18. uint32_t n = usec << 5;
  19. #elif F_CPU == 48000000
  20. uint32_t n = usec << 4;
  21. #elif F_CPU == 24000000
  22. uint32_t n = usec << 3;
  23. #endif
  24. asm volatile(
  25. "L_%=_delayMicroseconds:" "\n\t"
  26. "subs %0, #1" "\n\t"
  27. "bne L_%=_delayMicroseconds" "\n"
  28. : "+r" (n) :
  29. );
  30. }
  31. void yield(void) __attribute__ ((weak));
  32. uint32_t micros(void);
  33. void delay(uint32_t ms);
  34. #endif