tmk_keyboard icon indicating copy to clipboard operation
tmk_keyboard copied to clipboard

Chibios/Cortex-M: wait API

Open tmk opened this issue 7 years ago • 0 comments

With ChibiOS wait_us() doesn't provide enough resolution or just doens't work. Probably wait_ms() is not enough also. Some of keyboard protocol converters require microsecond resoution to handle signals. We simply need our own real busy wait implementation instead of using Chibios function.

https://github.com/tmk/tmk_keyboard/blob/a976ecc846af749f564fb8f96cb902c93973c47c/tmk_core/common/wait.h#L15

#ifndef WAIT_H
#define WAIT_H

#ifdef __cplusplus
extern "C" {
#endif

#if defined(__AVR__)
#   include <util/delay.h>
#   define wait_ms(ms)  _delay_ms(ms)
#   define wait_us(us)  _delay_us(us)
#elif defined(PROTOCOL_CHIBIOS) /* __AVR__ */
#   include "ch.h"
#   define wait_ms(ms) chThdSleepMilliseconds(ms)
#   define wait_us(us) chThdSleepMicroseconds(us)
#elif defined(__arm__) /* __AVR__ */
#   include "wait_api.h"
#endif /* __AVR__ */

#ifdef __cplusplus
}
#endif

#endif

mbed.org wait_api.h works well with PS/2 converter, we can refer its code. https://github.com/tmk/tmk_keyboard/blob/a976ecc846af749f564fb8f96cb902c93973c47c/tmk_core/common/wait.h#L17

And... https://techoverflow.net/2015/09/09/accurate-short-long-delays-on-microcontrollers-using-chibios/ https://stackoverflow.com/questions/32719767/cycles-per-instruction-in-delay-loop-on-arm

tmk avatar Jun 15 '17 04:06 tmk