From 2fd626b629e7bab16eac6461c6ba262aefaf37b3 Mon Sep 17 00:00:00 2001 From: Johannes Date: Mon, 5 Aug 2019 18:18:25 +0200 Subject: [PATCH 01/15] ps2_mouse on ARM: an interrupt-version of the ps2-mouse code ported to ARM/chibios --- docs/feature_ps2_mouse.md | 27 +++++++- tmk_core/protocol.mk | 8 +++ tmk_core/protocol/ps2_interrupt.c | 104 +++++++++++++++++++++++++++-- tmk_core/protocol/ps2_io_chibios.c | 69 +++++++++++++++++++ tmk_core/protocol/ps2_mouse.c | 22 ++++-- 5 files changed, 217 insertions(+), 13 deletions(-) create mode 100644 tmk_core/protocol/ps2_io_chibios.c diff --git a/docs/feature_ps2_mouse.md b/docs/feature_ps2_mouse.md index d138967991fe..83d2876a8447 100644 --- a/docs/feature_ps2_mouse.md +++ b/docs/feature_ps2_mouse.md @@ -50,7 +50,7 @@ In your keyboard config.h: #endif ``` -### Interrupt Version +### Interrupt Version (AVR/ATMega32u4) The following example uses D2 for clock and D5 for data. You can use any INT or PCINT pin for clock, and any pin for data. @@ -88,6 +88,31 @@ In your keyboard config.h: #endif ``` +### Interrupt Version (ARM chibios) + +pretty much any two pins can be used for the (software) interrupt variant on ARM cores, the example below uses A8 for clock, and A9 for data. + + +In rules.mk: + +``` +PS2_MOUSE_ENABLE = yes +PS2_USE_INT = yes +``` + +In your keyboard config.h: + +``` +#define PS2_LINE_CLOCK PAL_LINE(GPIOB, 8U) +#define PS2_LINE_DATA PAL_LINE(GPIOA, 9U) +``` + +And in the chibios specifig halconf.h: +``` +#define HAL_USE_EXT TRUE +``` + + ### USART Version To use USART on the ATMega32u4, you have to use PD5 for clock and PD2 for data. If one of those are unavailable, you need to use interrupt version. diff --git a/tmk_core/protocol.mk b/tmk_core/protocol.mk index 0c41642b9be8..1b6a3810e1a2 100644 --- a/tmk_core/protocol.mk +++ b/tmk_core/protocol.mk @@ -14,13 +14,21 @@ endif ifeq ($(strip $(PS2_USE_INT)), yes) SRC += protocol/ps2_interrupt.c + ifeq ($(PLATFORM),AVR) SRC += protocol/ps2_io_avr.c + else ifeq ($(PLATFORM),CHIBIOS) + SRC += protocol/ps2_io_chibios.c + endif OPT_DEFS += -DPS2_USE_INT endif ifeq ($(strip $(PS2_USE_USART)), yes) SRC += protocol/ps2_usart.c + ifeq ($(PLATFORM),AVR) SRC += protocol/ps2_io_avr.c + else ifeq ($(PLATFORM),CHIBIOS) + SRC += protocol/ps2_io_chibios.c + endif OPT_DEFS += -DPS2_USE_USART endif diff --git a/tmk_core/protocol/ps2_interrupt.c b/tmk_core/protocol/ps2_interrupt.c index 5afc8a82e471..79c6944018aa 100644 --- a/tmk_core/protocol/ps2_interrupt.c +++ b/tmk_core/protocol/ps2_interrupt.c @@ -40,8 +40,20 @@ POSSIBILITY OF SUCH DAMAGE. */ #include + +#if defined(__AVR__) #include #include +#define DELAY_MS(x) _delay_ms(x) +#define DELAY_US(x) _delay_us(x) +#elif defined(PROTOCOL_CHIBIOS) //TODO: or STM32 ? +// chibiOS headers +#include "ch.h" +#include "hal.h" +#define DELAY_MS(x) chThdSleepMilliseconds(x) +#define DELAY_US(x) chThdSleepMicroseconds(x) +#endif + #include "ps2.h" #include "ps2_io.h" #include "print.h" @@ -61,12 +73,58 @@ static inline void pbuf_enqueue(uint8_t data); static inline bool pbuf_has_data(void); static inline void pbuf_clear(void); +#if defined(PROTOCOL_CHIBIOS) +//------------------------------------------------ +// LEGACY EXT driver, for external interrupts +// (with newer chibios we could use palLineEnableEvent and so forth...) +#define PS2_INT_INIT() {} while(0) + +void ps2_interrupt_service_routine(void); +void extcb(EXTDriver *extp, expchannel_t channel) { + ps2_interrupt_service_routine(); +} + +/* + 16 slots, one for each pin... + currently configured to listen on external changes on pad A8 + */ +static const EXTConfig extcfg = { + { + {EXT_CH_MODE_DISABLED, NULL}, //0 + {EXT_CH_MODE_DISABLED, NULL}, + {EXT_CH_MODE_DISABLED, NULL}, + {EXT_CH_MODE_DISABLED, NULL}, + {EXT_CH_MODE_DISABLED, NULL}, + {EXT_CH_MODE_DISABLED, NULL}, //5 + {EXT_CH_MODE_DISABLED, NULL}, + {EXT_CH_MODE_DISABLED, NULL}, + {EXT_CH_MODE_FALLING_EDGE | EXT_CH_MODE_AUTOSTART | EXT_MODE_GPIOA, extcb}, //GPIOA 8 = clock + {EXT_CH_MODE_DISABLED, NULL}, + {EXT_CH_MODE_DISABLED, NULL}, //10 + {EXT_CH_MODE_DISABLED, NULL}, + {EXT_CH_MODE_DISABLED, NULL}, + {EXT_CH_MODE_DISABLED, NULL}, + {EXT_CH_MODE_DISABLED, NULL}, + {EXT_CH_MODE_DISABLED, NULL} + } +}; +#define PS2_INT_ON() { \ + extStart(&EXTD1, &extcfg); \ + } while(0) +#define PS2_INT_OFF() { \ + extStop(&EXTD1); \ + } while(0) +#endif + + + + void ps2_host_init(void) { idle(); PS2_INT_INIT(); PS2_INT_ON(); // POR(150-2000ms) plus BAT(300-500ms) may take 2.5sec([3]p.20) - //_delay_ms(2500); + //DELAY_MS(2500); } uint8_t ps2_host_send(uint8_t data) { @@ -77,7 +135,7 @@ uint8_t ps2_host_send(uint8_t data) { /* terminate a transmission if we have */ inhibit(); - _delay_us(100); // 100us [4]p.13, [5]p.50 + DELAY_US(100); // 100us [4]p.13, [5]p.50 /* 'Request to Send' and Start bit */ data_lo(); @@ -86,7 +144,6 @@ uint8_t ps2_host_send(uint8_t data) { /* Data bit[2-9] */ for (uint8_t i = 0; i < 8; i++) { - _delay_us(15); if (data & (1 << i)) { parity = !parity; data_hi(); @@ -98,7 +155,7 @@ uint8_t ps2_host_send(uint8_t data) { } /* Parity bit */ - _delay_us(15); + DELAY_US(15); if (parity) { data_hi(); } else { @@ -108,7 +165,7 @@ uint8_t ps2_host_send(uint8_t data) { WAIT(clock_lo, 50, 5); /* Stop bit */ - _delay_us(15); + DELAY_US(15); data_hi(); /* Ack */ @@ -132,7 +189,7 @@ uint8_t ps2_host_recv_response(void) { // Command may take 25ms/20ms at most([5]p.46, [3]p.21) uint8_t retry = 25; while (retry-- && !pbuf_has_data()) { - _delay_ms(1); + DELAY_MS(1); } return pbuf_dequeue(); } @@ -148,7 +205,8 @@ uint8_t ps2_host_recv(void) { } } -ISR(PS2_INT_VECT) { +void ps2_interrupt_service_routine(void) +{ static enum { INIT, START, @@ -218,6 +276,16 @@ ISR(PS2_INT_VECT) { return; } + +#if defined(__AVR__) +ISR(PS2_INT_VECT) +{ + ps2_interrupt_service_routine(); +} +#endif + + + /* send LED state to keyboard */ void ps2_host_set_led(uint8_t led) { ps2_host_send(0xED); @@ -232,8 +300,11 @@ static uint8_t pbuf[PBUF_SIZE]; static uint8_t pbuf_head = 0; static uint8_t pbuf_tail = 0; static inline void pbuf_enqueue(uint8_t data) { +#if defined(__AVR__) uint8_t sreg = SREG; cli(); +#endif + uint8_t next = (pbuf_head + 1) % PBUF_SIZE; if (next != pbuf_tail) { pbuf[pbuf_head] = data; @@ -241,31 +312,50 @@ static inline void pbuf_enqueue(uint8_t data) { } else { print("pbuf: full\n"); } + +#if defined(__AVR__) SREG = sreg; +#endif } static inline uint8_t pbuf_dequeue(void) { uint8_t val = 0; +#if defined(__AVR__) uint8_t sreg = SREG; cli(); +#endif + if (pbuf_head != pbuf_tail) { val = pbuf[pbuf_tail]; pbuf_tail = (pbuf_tail + 1) % PBUF_SIZE; } + +#if defined(__AVR__) SREG = sreg; +#endif return val; } static inline bool pbuf_has_data(void) { +#if defined(__AVR__) uint8_t sreg = SREG; cli(); +#endif + bool has_data = (pbuf_head != pbuf_tail); +#if defined(__AVR__) SREG = sreg; +#endif return has_data; } static inline void pbuf_clear(void) { +#if defined(__AVR__) uint8_t sreg = SREG; cli(); +#endif + pbuf_head = pbuf_tail = 0; +#if defined(__AVR__) SREG = sreg; +#endif } diff --git a/tmk_core/protocol/ps2_io_chibios.c b/tmk_core/protocol/ps2_io_chibios.c new file mode 100644 index 000000000000..3098eda730e0 --- /dev/null +++ b/tmk_core/protocol/ps2_io_chibios.c @@ -0,0 +1,69 @@ +#include +#include "ps2_io.h" + + +// chibiOS headers +#include "ch.h" +#include "hal.h" + + +/* Check port settings for clock and data line */ +#if !(defined(PS2_LINE_CLOCK)) +# error "PS/2 clock setting is required in config.h" +#endif + +#if !(defined(PS2_LINE_DATA)) +# error "PS/2 data setting is required in config.h" +#endif + + + +/* + * Clock + */ +void clock_init(void) +{ +} + +void clock_lo(void) +{ + palSetLineMode(PS2_LINE_CLOCK, PAL_MODE_OUTPUT_OPENDRAIN); + palWriteLine(PS2_LINE_CLOCK, PAL_LOW); +} + +void clock_hi(void) +{ + palSetLineMode(PS2_LINE_CLOCK, PAL_MODE_OUTPUT_OPENDRAIN); + palWriteLine(PS2_LINE_CLOCK, PAL_HIGH); +} + +bool clock_in(void) +{ + palSetLineMode(PS2_LINE_CLOCK, PAL_MODE_INPUT); + return palReadLine(PS2_LINE_CLOCK); +} + +/* + * Data + */ +void data_init(void) +{ +} + +void data_lo(void) +{ + palSetLineMode(PS2_LINE_DATA, PAL_MODE_OUTPUT_OPENDRAIN); + palWriteLine(PS2_LINE_DATA, PAL_LOW); +} + +void data_hi(void) +{ + palSetLineMode(PS2_LINE_DATA, PAL_MODE_OUTPUT_OPENDRAIN); + palWriteLine(PS2_LINE_DATA, PAL_HIGH); +} + +bool data_in(void) +{ + palSetLineMode(PS2_LINE_DATA, PAL_MODE_INPUT); + return palReadLine(PS2_LINE_DATA); +} diff --git a/tmk_core/protocol/ps2_mouse.c b/tmk_core/protocol/ps2_mouse.c index aa3a307ebfab..0901ea643e74 100644 --- a/tmk_core/protocol/ps2_mouse.c +++ b/tmk_core/protocol/ps2_mouse.c @@ -16,8 +16,20 @@ along with this program. If not, see . */ #include -#include -#include + +#if defined(__AVR__) + #include + #include + #define DELAY_MS(x) _delay_ms(x) + #define DELAY_US(x) _delay_us(x) +#elif defined(PROTOCOL_CHIBIOS) //TODO: or STM32 ? + // chibiOS headers +//NOTE: no delays needed in the chibios case + #define DELAY_MS(x) + #define DELAY_US(x) +#endif + + #include "ps2_mouse.h" #include "host.h" #include "timer.h" @@ -42,7 +54,7 @@ static inline void ps2_mouse_scroll_button_task(report_mouse_t *mouse_report); void ps2_mouse_init(void) { ps2_host_init(); - _delay_ms(PS2_MOUSE_INIT_DELAY); // wait for powering up + DELAY_MS(PS2_MOUSE_INIT_DELAY); // wait for powering up PS2_MOUSE_SEND(PS2_MOUSE_RESET, "ps2_mouse_init: sending reset"); @@ -190,7 +202,7 @@ static inline void ps2_mouse_enable_scrolling(void) { PS2_MOUSE_SEND(PS2_MOUSE_SET_SAMPLE_RATE, "Set sample rate"); PS2_MOUSE_SEND(80, "80"); PS2_MOUSE_SEND(PS2_MOUSE_GET_DEVICE_ID, "Finished enabling scroll wheel"); - _delay_ms(20); + DELAY_MS(20); } #define PRESS_SCROLL_BUTTONS mouse_report->buttons |= (PS2_MOUSE_SCROLL_BTN_MASK) @@ -232,7 +244,7 @@ static inline void ps2_mouse_scroll_button_task(report_mouse_t *mouse_report) { if (scroll_state == SCROLL_BTN && timer_elapsed(scroll_button_time) < PS2_MOUSE_SCROLL_BTN_SEND) { PRESS_SCROLL_BUTTONS; host_mouse_send(mouse_report); - _delay_ms(100); + DELAY_MS(100); RELEASE_SCROLL_BUTTONS; } #endif From c6ece46ad316a8bfdc1777d13bb569e5303d513f Mon Sep 17 00:00:00 2001 From: Johannes Date: Mon, 5 Aug 2019 19:38:30 +0200 Subject: [PATCH 02/15] ps2_mouse on ARM: link EXT callback-channel selection to the user defined PS2_LINE_CLOCK --- docs/feature_ps2_mouse.md | 1 + tmk_core/protocol/ps2_interrupt.c | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/docs/feature_ps2_mouse.md b/docs/feature_ps2_mouse.md index 83d2876a8447..c3733711fb64 100644 --- a/docs/feature_ps2_mouse.md +++ b/docs/feature_ps2_mouse.md @@ -92,6 +92,7 @@ In your keyboard config.h: pretty much any two pins can be used for the (software) interrupt variant on ARM cores, the example below uses A8 for clock, and A9 for data. +NOTE: due to implementation details of the EXT config, "any two pins", is currently limited to the Port-A (see tmk_core/protocol/ps2_interrupt.c) In rules.mk: diff --git a/tmk_core/protocol/ps2_interrupt.c b/tmk_core/protocol/ps2_interrupt.c index 79c6944018aa..d0a265cd2613 100644 --- a/tmk_core/protocol/ps2_interrupt.c +++ b/tmk_core/protocol/ps2_interrupt.c @@ -77,7 +77,6 @@ static inline void pbuf_clear(void); //------------------------------------------------ // LEGACY EXT driver, for external interrupts // (with newer chibios we could use palLineEnableEvent and so forth...) -#define PS2_INT_INIT() {} while(0) void ps2_interrupt_service_routine(void); void extcb(EXTDriver *extp, expchannel_t channel) { @@ -88,7 +87,7 @@ void extcb(EXTDriver *extp, expchannel_t channel) { 16 slots, one for each pin... currently configured to listen on external changes on pad A8 */ -static const EXTConfig extcfg = { +static EXTConfig extcfg = { { {EXT_CH_MODE_DISABLED, NULL}, //0 {EXT_CH_MODE_DISABLED, NULL}, @@ -98,7 +97,7 @@ static const EXTConfig extcfg = { {EXT_CH_MODE_DISABLED, NULL}, //5 {EXT_CH_MODE_DISABLED, NULL}, {EXT_CH_MODE_DISABLED, NULL}, - {EXT_CH_MODE_FALLING_EDGE | EXT_CH_MODE_AUTOSTART | EXT_MODE_GPIOA, extcb}, //GPIOA 8 = clock + {EXT_CH_MODE_DISABLED, NULL}, {EXT_CH_MODE_DISABLED, NULL}, {EXT_CH_MODE_DISABLED, NULL}, //10 {EXT_CH_MODE_DISABLED, NULL}, @@ -108,6 +107,11 @@ static const EXTConfig extcfg = { {EXT_CH_MODE_DISABLED, NULL} } }; +static EXTChannelConfig ext_clock_channel_config = {EXT_CH_MODE_FALLING_EDGE | EXT_CH_MODE_AUTOSTART | EXT_MODE_GPIOA, extcb}; // NOTE: hardcoded/limited to Port-A +#define PS2_INT_INIT() { \ + extStart(&EXTD1, &extcfg); /*activate config, to be able to select the appropriate channel */ \ + extSetChannelModeI(&EXTD1, PAL_PAD(PS2_LINE_CLOCK), &ext_clock_channel_config); \ + } while(0) #define PS2_INT_ON() { \ extStart(&EXTD1, &extcfg); \ } while(0) From 29b234ed33ad751807637e724dcf19d18f8177ce Mon Sep 17 00:00:00 2001 From: Johannes Date: Tue, 6 Aug 2019 21:04:29 +0200 Subject: [PATCH 03/15] ps2_mouse on ARM: replace DELAY_X defines with hardware-agnostic wait_X --- tmk_core/protocol/ps2_interrupt.c | 14 +++++--------- tmk_core/protocol/ps2_mouse.c | 17 +++++------------ 2 files changed, 10 insertions(+), 21 deletions(-) diff --git a/tmk_core/protocol/ps2_interrupt.c b/tmk_core/protocol/ps2_interrupt.c index d0a265cd2613..1a9869f4d95b 100644 --- a/tmk_core/protocol/ps2_interrupt.c +++ b/tmk_core/protocol/ps2_interrupt.c @@ -44,14 +44,10 @@ POSSIBILITY OF SUCH DAMAGE. #if defined(__AVR__) #include #include -#define DELAY_MS(x) _delay_ms(x) -#define DELAY_US(x) _delay_us(x) #elif defined(PROTOCOL_CHIBIOS) //TODO: or STM32 ? // chibiOS headers #include "ch.h" #include "hal.h" -#define DELAY_MS(x) chThdSleepMilliseconds(x) -#define DELAY_US(x) chThdSleepMicroseconds(x) #endif #include "ps2.h" @@ -128,7 +124,7 @@ void ps2_host_init(void) { PS2_INT_INIT(); PS2_INT_ON(); // POR(150-2000ms) plus BAT(300-500ms) may take 2.5sec([3]p.20) - //DELAY_MS(2500); + //wait_ms(2500); } uint8_t ps2_host_send(uint8_t data) { @@ -139,7 +135,7 @@ uint8_t ps2_host_send(uint8_t data) { /* terminate a transmission if we have */ inhibit(); - DELAY_US(100); // 100us [4]p.13, [5]p.50 + wait_us(100); // 100us [4]p.13, [5]p.50 /* 'Request to Send' and Start bit */ data_lo(); @@ -159,7 +155,7 @@ uint8_t ps2_host_send(uint8_t data) { } /* Parity bit */ - DELAY_US(15); + wait_us(15); if (parity) { data_hi(); } else { @@ -169,7 +165,7 @@ uint8_t ps2_host_send(uint8_t data) { WAIT(clock_lo, 50, 5); /* Stop bit */ - DELAY_US(15); + wait_us(15); data_hi(); /* Ack */ @@ -193,7 +189,7 @@ uint8_t ps2_host_recv_response(void) { // Command may take 25ms/20ms at most([5]p.46, [3]p.21) uint8_t retry = 25; while (retry-- && !pbuf_has_data()) { - DELAY_MS(1); + wait_ms(1); } return pbuf_dequeue(); } diff --git a/tmk_core/protocol/ps2_mouse.c b/tmk_core/protocol/ps2_mouse.c index 0901ea643e74..aa601d319a33 100644 --- a/tmk_core/protocol/ps2_mouse.c +++ b/tmk_core/protocol/ps2_mouse.c @@ -18,15 +18,8 @@ along with this program. If not, see . #include #if defined(__AVR__) - #include - #include - #define DELAY_MS(x) _delay_ms(x) - #define DELAY_US(x) _delay_us(x) -#elif defined(PROTOCOL_CHIBIOS) //TODO: or STM32 ? - // chibiOS headers -//NOTE: no delays needed in the chibios case - #define DELAY_MS(x) - #define DELAY_US(x) + #include + #include #endif @@ -54,7 +47,7 @@ static inline void ps2_mouse_scroll_button_task(report_mouse_t *mouse_report); void ps2_mouse_init(void) { ps2_host_init(); - DELAY_MS(PS2_MOUSE_INIT_DELAY); // wait for powering up + wait_ms(PS2_MOUSE_INIT_DELAY); // wait for powering up PS2_MOUSE_SEND(PS2_MOUSE_RESET, "ps2_mouse_init: sending reset"); @@ -202,7 +195,7 @@ static inline void ps2_mouse_enable_scrolling(void) { PS2_MOUSE_SEND(PS2_MOUSE_SET_SAMPLE_RATE, "Set sample rate"); PS2_MOUSE_SEND(80, "80"); PS2_MOUSE_SEND(PS2_MOUSE_GET_DEVICE_ID, "Finished enabling scroll wheel"); - DELAY_MS(20); + wait_ms(20); } #define PRESS_SCROLL_BUTTONS mouse_report->buttons |= (PS2_MOUSE_SCROLL_BTN_MASK) @@ -244,7 +237,7 @@ static inline void ps2_mouse_scroll_button_task(report_mouse_t *mouse_report) { if (scroll_state == SCROLL_BTN && timer_elapsed(scroll_button_time) < PS2_MOUSE_SCROLL_BTN_SEND) { PRESS_SCROLL_BUTTONS; host_mouse_send(mouse_report); - DELAY_MS(100); + wait_ms(100); RELEASE_SCROLL_BUTTONS; } #endif From 93f32d36b64c208e7a6ff96126f6a656adcc34cc Mon Sep 17 00:00:00 2001 From: Johannes Date: Thu, 8 Aug 2019 18:24:17 +0200 Subject: [PATCH 04/15] ps2_mouse on ARM: replace chibios-specific defines for the pins/lines with defines from quantum/config_common.h and drop the '_LINE' component from teh define name --- docs/feature_ps2_mouse.md | 4 ++-- tmk_core/protocol/ps2_interrupt.c | 2 +- tmk_core/protocol/ps2_io_chibios.c | 28 ++++++++++++++-------------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/docs/feature_ps2_mouse.md b/docs/feature_ps2_mouse.md index c3733711fb64..9d98d7031bf4 100644 --- a/docs/feature_ps2_mouse.md +++ b/docs/feature_ps2_mouse.md @@ -104,8 +104,8 @@ PS2_USE_INT = yes In your keyboard config.h: ``` -#define PS2_LINE_CLOCK PAL_LINE(GPIOB, 8U) -#define PS2_LINE_DATA PAL_LINE(GPIOA, 9U) +#define PS2_CLOCK A8 +#define PS2_DATA A9 ``` And in the chibios specifig halconf.h: diff --git a/tmk_core/protocol/ps2_interrupt.c b/tmk_core/protocol/ps2_interrupt.c index 1a9869f4d95b..1e8e0434f6f3 100644 --- a/tmk_core/protocol/ps2_interrupt.c +++ b/tmk_core/protocol/ps2_interrupt.c @@ -106,7 +106,7 @@ static EXTConfig extcfg = { static EXTChannelConfig ext_clock_channel_config = {EXT_CH_MODE_FALLING_EDGE | EXT_CH_MODE_AUTOSTART | EXT_MODE_GPIOA, extcb}; // NOTE: hardcoded/limited to Port-A #define PS2_INT_INIT() { \ extStart(&EXTD1, &extcfg); /*activate config, to be able to select the appropriate channel */ \ - extSetChannelModeI(&EXTD1, PAL_PAD(PS2_LINE_CLOCK), &ext_clock_channel_config); \ + extSetChannelModeI(&EXTD1, PAL_PAD(PS2_CLOCK), &ext_clock_channel_config); \ } while(0) #define PS2_INT_ON() { \ extStart(&EXTD1, &extcfg); \ diff --git a/tmk_core/protocol/ps2_io_chibios.c b/tmk_core/protocol/ps2_io_chibios.c index 3098eda730e0..822d4309c3ba 100644 --- a/tmk_core/protocol/ps2_io_chibios.c +++ b/tmk_core/protocol/ps2_io_chibios.c @@ -8,11 +8,11 @@ /* Check port settings for clock and data line */ -#if !(defined(PS2_LINE_CLOCK)) +#if !(defined(PS2_CLOCK)) # error "PS/2 clock setting is required in config.h" #endif -#if !(defined(PS2_LINE_DATA)) +#if !(defined(PS2_DATA)) # error "PS/2 data setting is required in config.h" #endif @@ -27,20 +27,20 @@ void clock_init(void) void clock_lo(void) { - palSetLineMode(PS2_LINE_CLOCK, PAL_MODE_OUTPUT_OPENDRAIN); - palWriteLine(PS2_LINE_CLOCK, PAL_LOW); + palSetLineMode(PS2_CLOCK, PAL_MODE_OUTPUT_OPENDRAIN); + palWriteLine(PS2_CLOCK, PAL_LOW); } void clock_hi(void) { - palSetLineMode(PS2_LINE_CLOCK, PAL_MODE_OUTPUT_OPENDRAIN); - palWriteLine(PS2_LINE_CLOCK, PAL_HIGH); + palSetLineMode(PS2_CLOCK, PAL_MODE_OUTPUT_OPENDRAIN); + palWriteLine(PS2_CLOCK, PAL_HIGH); } bool clock_in(void) { - palSetLineMode(PS2_LINE_CLOCK, PAL_MODE_INPUT); - return palReadLine(PS2_LINE_CLOCK); + palSetLineMode(PS2_CLOCK, PAL_MODE_INPUT); + return palReadLine(PS2_CLOCK); } /* @@ -52,18 +52,18 @@ void data_init(void) void data_lo(void) { - palSetLineMode(PS2_LINE_DATA, PAL_MODE_OUTPUT_OPENDRAIN); - palWriteLine(PS2_LINE_DATA, PAL_LOW); + palSetLineMode(PS2_DATA, PAL_MODE_OUTPUT_OPENDRAIN); + palWriteLine(PS2_DATA, PAL_LOW); } void data_hi(void) { - palSetLineMode(PS2_LINE_DATA, PAL_MODE_OUTPUT_OPENDRAIN); - palWriteLine(PS2_LINE_DATA, PAL_HIGH); + palSetLineMode(PS2_DATA, PAL_MODE_OUTPUT_OPENDRAIN); + palWriteLine(PS2_DATA, PAL_HIGH); } bool data_in(void) { - palSetLineMode(PS2_LINE_DATA, PAL_MODE_INPUT); - return palReadLine(PS2_LINE_DATA); + palSetLineMode(PS2_DATA, PAL_MODE_INPUT); + return palReadLine(PS2_DATA); } From e6c6732cc8e4c0d7f6b8cdf59cc8c3dfe1ca88bd Mon Sep 17 00:00:00 2001 From: Johannes Date: Fri, 9 Aug 2019 14:15:02 +0200 Subject: [PATCH 05/15] ps2_mouse on ARM: expose the software-intterupt port as a user editable define --- docs/feature_ps2_mouse.md | 4 ++-- tmk_core/protocol/ps2_interrupt.c | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/docs/feature_ps2_mouse.md b/docs/feature_ps2_mouse.md index 9d98d7031bf4..3123c5fa14c9 100644 --- a/docs/feature_ps2_mouse.md +++ b/docs/feature_ps2_mouse.md @@ -92,8 +92,6 @@ In your keyboard config.h: pretty much any two pins can be used for the (software) interrupt variant on ARM cores, the example below uses A8 for clock, and A9 for data. -NOTE: due to implementation details of the EXT config, "any two pins", is currently limited to the Port-A (see tmk_core/protocol/ps2_interrupt.c) - In rules.mk: ``` @@ -106,7 +104,9 @@ In your keyboard config.h: ``` #define PS2_CLOCK A8 #define PS2_DATA A9 +#define PS2_CLOCK_PORT EXT_MODE_GPIOA ``` +the last define is used to select wich port DATA and CLOCK lines are wired to, and therefor the software-pin-interrupt should be configured for (replace the 'A' with your port-of-wiring-choice) And in the chibios specifig halconf.h: ``` diff --git a/tmk_core/protocol/ps2_interrupt.c b/tmk_core/protocol/ps2_interrupt.c index 1e8e0434f6f3..6e102073e4f5 100644 --- a/tmk_core/protocol/ps2_interrupt.c +++ b/tmk_core/protocol/ps2_interrupt.c @@ -73,7 +73,8 @@ static inline void pbuf_clear(void); //------------------------------------------------ // LEGACY EXT driver, for external interrupts // (with newer chibios we could use palLineEnableEvent and so forth...) - +// see: http://www.chibios.com/forum/viewtopic.php?t=3355#p25518 https://www.playembedded.org/blog/buttons-stm32/ 3.2.3 event/callback +// void ps2_interrupt_service_routine(void); void extcb(EXTDriver *extp, expchannel_t channel) { ps2_interrupt_service_routine(); @@ -103,7 +104,7 @@ static EXTConfig extcfg = { {EXT_CH_MODE_DISABLED, NULL} } }; -static EXTChannelConfig ext_clock_channel_config = {EXT_CH_MODE_FALLING_EDGE | EXT_CH_MODE_AUTOSTART | EXT_MODE_GPIOA, extcb}; // NOTE: hardcoded/limited to Port-A +static EXTChannelConfig ext_clock_channel_config = {EXT_CH_MODE_FALLING_EDGE | EXT_CH_MODE_AUTOSTART | PS2_CLOCK_PORT , extcb}; #define PS2_INT_INIT() { \ extStart(&EXTD1, &extcfg); /*activate config, to be able to select the appropriate channel */ \ extSetChannelModeI(&EXTD1, PAL_PAD(PS2_CLOCK), &ext_clock_channel_config); \ From 155fca1617142d489d81f1c38425930392f8e19f Mon Sep 17 00:00:00 2001 From: JohSchneider Date: Wed, 9 Oct 2019 16:48:24 +0000 Subject: [PATCH 06/15] Update docs/feature_ps2_mouse.md Co-Authored-By: Hugo van Kemenade --- docs/feature_ps2_mouse.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/feature_ps2_mouse.md b/docs/feature_ps2_mouse.md index 3123c5fa14c9..fa9315109e16 100644 --- a/docs/feature_ps2_mouse.md +++ b/docs/feature_ps2_mouse.md @@ -90,7 +90,7 @@ In your keyboard config.h: ### Interrupt Version (ARM chibios) -pretty much any two pins can be used for the (software) interrupt variant on ARM cores, the example below uses A8 for clock, and A9 for data. +Pretty much any two pins can be used for the (software) interrupt variant on ARM cores. The example below uses A8 for clock, and A9 for data. In rules.mk: From b6a93db285145c9871323ee98801f51d3a0b1b5e Mon Sep 17 00:00:00 2001 From: JohSchneider Date: Wed, 9 Oct 2019 16:52:33 +0000 Subject: [PATCH 07/15] Update feature_ps2_mouse.md --- docs/feature_ps2_mouse.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/feature_ps2_mouse.md b/docs/feature_ps2_mouse.md index fa9315109e16..0991de8895e4 100644 --- a/docs/feature_ps2_mouse.md +++ b/docs/feature_ps2_mouse.md @@ -101,7 +101,7 @@ PS2_USE_INT = yes In your keyboard config.h: -``` +```c #define PS2_CLOCK A8 #define PS2_DATA A9 #define PS2_CLOCK_PORT EXT_MODE_GPIOA @@ -109,7 +109,7 @@ In your keyboard config.h: the last define is used to select wich port DATA and CLOCK lines are wired to, and therefor the software-pin-interrupt should be configured for (replace the 'A' with your port-of-wiring-choice) And in the chibios specifig halconf.h: -``` +```c #define HAL_USE_EXT TRUE ``` From edd39412a1e84de13946a41dc7feee3689273f4d Mon Sep 17 00:00:00 2001 From: JohSchneider Date: Mon, 21 Oct 2019 07:33:01 +0000 Subject: [PATCH 08/15] use a define to deduce the PS_DATA_PORT instead --- docs/feature_ps2_mouse.md | 1 - tmk_core/protocol/ps2_interrupt.c | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/feature_ps2_mouse.md b/docs/feature_ps2_mouse.md index 0991de8895e4..41996e32f4e7 100644 --- a/docs/feature_ps2_mouse.md +++ b/docs/feature_ps2_mouse.md @@ -104,7 +104,6 @@ In your keyboard config.h: ```c #define PS2_CLOCK A8 #define PS2_DATA A9 -#define PS2_CLOCK_PORT EXT_MODE_GPIOA ``` the last define is used to select wich port DATA and CLOCK lines are wired to, and therefor the software-pin-interrupt should be configured for (replace the 'A' with your port-of-wiring-choice) diff --git a/tmk_core/protocol/ps2_interrupt.c b/tmk_core/protocol/ps2_interrupt.c index 6e102073e4f5..01ed4d7e4984 100644 --- a/tmk_core/protocol/ps2_interrupt.c +++ b/tmk_core/protocol/ps2_interrupt.c @@ -104,7 +104,8 @@ static EXTConfig extcfg = { {EXT_CH_MODE_DISABLED, NULL} } }; -static EXTChannelConfig ext_clock_channel_config = {EXT_CH_MODE_FALLING_EDGE | EXT_CH_MODE_AUTOSTART | PS2_CLOCK_PORT , extcb}; +#define ExtModePort(pin) (((uint32_t)PAL_PORT(pin) & 0x0000FF00U) >> 6) +static EXTChannelConfig ext_clock_channel_config = {EXT_CH_MODE_FALLING_EDGE | EXT_CH_MODE_AUTOSTART | ExtModePort(PS2_CLOCK) , extcb}; #define PS2_INT_INIT() { \ extStart(&EXTD1, &extcfg); /*activate config, to be able to select the appropriate channel */ \ extSetChannelModeI(&EXTD1, PAL_PAD(PS2_CLOCK), &ext_clock_channel_config); \ From 1b18702d646275dec542d6829cf8b0aeb7d7b427 Mon Sep 17 00:00:00 2001 From: JohSchneider Date: Mon, 21 Oct 2019 07:37:43 +0000 Subject: [PATCH 09/15] reduce all-zero extcfg to oneliner --- tmk_core/protocol/ps2_interrupt.c | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/tmk_core/protocol/ps2_interrupt.c b/tmk_core/protocol/ps2_interrupt.c index 01ed4d7e4984..94a09084cc17 100644 --- a/tmk_core/protocol/ps2_interrupt.c +++ b/tmk_core/protocol/ps2_interrupt.c @@ -84,26 +84,8 @@ void extcb(EXTDriver *extp, expchannel_t channel) { 16 slots, one for each pin... currently configured to listen on external changes on pad A8 */ -static EXTConfig extcfg = { - { - {EXT_CH_MODE_DISABLED, NULL}, //0 - {EXT_CH_MODE_DISABLED, NULL}, - {EXT_CH_MODE_DISABLED, NULL}, - {EXT_CH_MODE_DISABLED, NULL}, - {EXT_CH_MODE_DISABLED, NULL}, - {EXT_CH_MODE_DISABLED, NULL}, //5 - {EXT_CH_MODE_DISABLED, NULL}, - {EXT_CH_MODE_DISABLED, NULL}, - {EXT_CH_MODE_DISABLED, NULL}, - {EXT_CH_MODE_DISABLED, NULL}, - {EXT_CH_MODE_DISABLED, NULL}, //10 - {EXT_CH_MODE_DISABLED, NULL}, - {EXT_CH_MODE_DISABLED, NULL}, - {EXT_CH_MODE_DISABLED, NULL}, - {EXT_CH_MODE_DISABLED, NULL}, - {EXT_CH_MODE_DISABLED, NULL} - } -}; +static EXTConfig extcfg = {0}; + #define ExtModePort(pin) (((uint32_t)PAL_PORT(pin) & 0x0000FF00U) >> 6) static EXTChannelConfig ext_clock_channel_config = {EXT_CH_MODE_FALLING_EDGE | EXT_CH_MODE_AUTOSTART | ExtModePort(PS2_CLOCK) , extcb}; #define PS2_INT_INIT() { \ From 4b2c918557d53b18ed56a381fa0ad70703bc5930 Mon Sep 17 00:00:00 2001 From: JohSchneider Date: Tue, 22 Oct 2019 15:26:46 +0000 Subject: [PATCH 10/15] ps2_mouse: use generic wait instead of avr-delay --- tmk_core/protocol/ps2_interrupt.c | 4 ++-- tmk_core/protocol/ps2_mouse.c | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/tmk_core/protocol/ps2_interrupt.c b/tmk_core/protocol/ps2_interrupt.c index 94a09084cc17..9f81a9f88f59 100644 --- a/tmk_core/protocol/ps2_interrupt.c +++ b/tmk_core/protocol/ps2_interrupt.c @@ -43,7 +43,6 @@ POSSIBILITY OF SUCH DAMAGE. #if defined(__AVR__) #include -#include #elif defined(PROTOCOL_CHIBIOS) //TODO: or STM32 ? // chibiOS headers #include "ch.h" @@ -52,7 +51,8 @@ POSSIBILITY OF SUCH DAMAGE. #include "ps2.h" #include "ps2_io.h" -#include "print.h" + #include "print.h" + #include "wait.h" #define WAIT(stat, us, err) \ do { \ diff --git a/tmk_core/protocol/ps2_mouse.c b/tmk_core/protocol/ps2_mouse.c index aa601d319a33..8eb688232278 100644 --- a/tmk_core/protocol/ps2_mouse.c +++ b/tmk_core/protocol/ps2_mouse.c @@ -19,11 +19,10 @@ along with this program. If not, see . #if defined(__AVR__) #include - #include #endif - #include "ps2_mouse.h" +#include "wait.h" #include "host.h" #include "timer.h" #include "print.h" From c0a2dd971ca23ec2dbc63e2cb67c9c6d51720473 Mon Sep 17 00:00:00 2001 From: JohSchneider Date: Tue, 22 Oct 2019 15:28:58 +0000 Subject: [PATCH 11/15] Update docs/feature_ps2_mouse.md --- docs/feature_ps2_mouse.md | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/feature_ps2_mouse.md b/docs/feature_ps2_mouse.md index 41996e32f4e7..e0b39e9b7e5e 100644 --- a/docs/feature_ps2_mouse.md +++ b/docs/feature_ps2_mouse.md @@ -105,7 +105,6 @@ In your keyboard config.h: #define PS2_CLOCK A8 #define PS2_DATA A9 ``` -the last define is used to select wich port DATA and CLOCK lines are wired to, and therefor the software-pin-interrupt should be configured for (replace the 'A' with your port-of-wiring-choice) And in the chibios specifig halconf.h: ```c From 119e23e947caf2b69f3b94ab85d3cb8b3cf8ac2f Mon Sep 17 00:00:00 2001 From: Johannes Date: Tue, 3 Mar 2020 15:17:05 +0100 Subject: [PATCH 12/15] ps2_mouse: changes for new chibios version (17.6.0 -> 19.1.0) replacing the legacy externa-interrupt driver with pal-callbacks --- docs/feature_ps2_mouse.md | 2 +- tmk_core/protocol/ps2_interrupt.c | 36 ++++++++++--------------------- 2 files changed, 12 insertions(+), 26 deletions(-) diff --git a/docs/feature_ps2_mouse.md b/docs/feature_ps2_mouse.md index e0b39e9b7e5e..f442013a078a 100644 --- a/docs/feature_ps2_mouse.md +++ b/docs/feature_ps2_mouse.md @@ -108,7 +108,7 @@ In your keyboard config.h: And in the chibios specifig halconf.h: ```c -#define HAL_USE_EXT TRUE +#define PAL_USE_CALLBACKS TRUE ``` diff --git a/tmk_core/protocol/ps2_interrupt.c b/tmk_core/protocol/ps2_interrupt.c index 9f81a9f88f59..fe97af361bfb 100644 --- a/tmk_core/protocol/ps2_interrupt.c +++ b/tmk_core/protocol/ps2_interrupt.c @@ -51,8 +51,8 @@ POSSIBILITY OF SUCH DAMAGE. #include "ps2.h" #include "ps2_io.h" - #include "print.h" - #include "wait.h" +#include "print.h" +#include "wait.h" #define WAIT(stat, us, err) \ do { \ @@ -70,36 +70,22 @@ static inline bool pbuf_has_data(void); static inline void pbuf_clear(void); #if defined(PROTOCOL_CHIBIOS) -//------------------------------------------------ -// LEGACY EXT driver, for external interrupts -// (with newer chibios we could use palLineEnableEvent and so forth...) -// see: http://www.chibios.com/forum/viewtopic.php?t=3355#p25518 https://www.playembedded.org/blog/buttons-stm32/ 3.2.3 event/callback -// void ps2_interrupt_service_routine(void); -void extcb(EXTDriver *extp, expchannel_t channel) { +void palCallback(void *arg) { ps2_interrupt_service_routine(); } -/* - 16 slots, one for each pin... - currently configured to listen on external changes on pad A8 - */ -static EXTConfig extcfg = {0}; - -#define ExtModePort(pin) (((uint32_t)PAL_PORT(pin) & 0x0000FF00U) >> 6) -static EXTChannelConfig ext_clock_channel_config = {EXT_CH_MODE_FALLING_EDGE | EXT_CH_MODE_AUTOSTART | ExtModePort(PS2_CLOCK) , extcb}; -#define PS2_INT_INIT() { \ - extStart(&EXTD1, &extcfg); /*activate config, to be able to select the appropriate channel */ \ - extSetChannelModeI(&EXTD1, PAL_PAD(PS2_CLOCK), &ext_clock_channel_config); \ +#define PS2_INT_INIT() { \ + palSetLineMode(PS2_CLOCK, PAL_MODE_INPUT); \ } while(0) -#define PS2_INT_ON() { \ - extStart(&EXTD1, &extcfg); \ +#define PS2_INT_ON(){ \ + palEnableLineEvent(PS2_CLOCK, PAL_EVENT_MODE_FALLING_EDGE); \ + palSetLineCallback(PS2_CLOCK, palCallback, NULL); \ } while(0) -#define PS2_INT_OFF() { \ - extStop(&EXTD1); \ +#define PS2_INT_OFF() { \ + palDisableLineEvent(PS2_CLOCK); \ } while(0) -#endif - +#endif // PROTOCOL_CHIBIOS From 63bd3894536f6f6051afcc40d6db743abb1328e2 Mon Sep 17 00:00:00 2001 From: JohSchneider Date: Tue, 28 Apr 2020 16:44:21 +0000 Subject: [PATCH 13/15] ps2_mouse: use PLATFORM_KEY Co-Authored-By: Joel Challis --- tmk_core/protocol.mk | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/tmk_core/protocol.mk b/tmk_core/protocol.mk index 1b6a3810e1a2..703ee558948b 100644 --- a/tmk_core/protocol.mk +++ b/tmk_core/protocol.mk @@ -14,21 +14,13 @@ endif ifeq ($(strip $(PS2_USE_INT)), yes) SRC += protocol/ps2_interrupt.c - ifeq ($(PLATFORM),AVR) - SRC += protocol/ps2_io_avr.c - else ifeq ($(PLATFORM),CHIBIOS) - SRC += protocol/ps2_io_chibios.c - endif + SRC += protocol/ps2_io_$(PLATFORM_KEY).c OPT_DEFS += -DPS2_USE_INT endif ifeq ($(strip $(PS2_USE_USART)), yes) SRC += protocol/ps2_usart.c - ifeq ($(PLATFORM),AVR) - SRC += protocol/ps2_io_avr.c - else ifeq ($(PLATFORM),CHIBIOS) - SRC += protocol/ps2_io_chibios.c - endif + SRC += protocol/ps2_io_$(PLATFORM_KEY).c OPT_DEFS += -DPS2_USE_USART endif From 8d10fdaf45fa9603cab4e873f78c71c5069f2055 Mon Sep 17 00:00:00 2001 From: Johannes Date: Tue, 28 Apr 2020 18:56:22 +0200 Subject: [PATCH 14/15] ps2_mouse: clang-format corrections --- tmk_core/protocol/ps2_interrupt.c | 59 +++++++++++++----------------- tmk_core/protocol/ps2_io_chibios.c | 34 +++++------------ tmk_core/protocol/ps2_mouse.c | 4 +- 3 files changed, 37 insertions(+), 60 deletions(-) diff --git a/tmk_core/protocol/ps2_interrupt.c b/tmk_core/protocol/ps2_interrupt.c index fe97af361bfb..ef9710e88a11 100644 --- a/tmk_core/protocol/ps2_interrupt.c +++ b/tmk_core/protocol/ps2_interrupt.c @@ -42,11 +42,11 @@ POSSIBILITY OF SUCH DAMAGE. #include #if defined(__AVR__) -#include -#elif defined(PROTOCOL_CHIBIOS) //TODO: or STM32 ? +# include +#elif defined(PROTOCOL_CHIBIOS) // TODO: or STM32 ? // chibiOS headers -#include "ch.h" -#include "hal.h" +# include "ch.h" +# include "hal.h" #endif #include "ps2.h" @@ -71,30 +71,28 @@ static inline void pbuf_clear(void); #if defined(PROTOCOL_CHIBIOS) void ps2_interrupt_service_routine(void); -void palCallback(void *arg) { - ps2_interrupt_service_routine(); -} - -#define PS2_INT_INIT() { \ - palSetLineMode(PS2_CLOCK, PAL_MODE_INPUT); \ - } while(0) -#define PS2_INT_ON(){ \ - palEnableLineEvent(PS2_CLOCK, PAL_EVENT_MODE_FALLING_EDGE); \ - palSetLineCallback(PS2_CLOCK, palCallback, NULL); \ - } while(0) -#define PS2_INT_OFF() { \ - palDisableLineEvent(PS2_CLOCK); \ - } while(0) -#endif // PROTOCOL_CHIBIOS - - +void palCallback(void *arg) { ps2_interrupt_service_routine(); } + +# define PS2_INT_INIT() \ + { palSetLineMode(PS2_CLOCK, PAL_MODE_INPUT); } \ + while (0) +# define PS2_INT_ON() \ + { \ + palEnableLineEvent(PS2_CLOCK, PAL_EVENT_MODE_FALLING_EDGE); \ + palSetLineCallback(PS2_CLOCK, palCallback, NULL); \ + } \ + while (0) +# define PS2_INT_OFF() \ + { palDisableLineEvent(PS2_CLOCK); } \ + while (0) +#endif // PROTOCOL_CHIBIOS void ps2_host_init(void) { idle(); PS2_INT_INIT(); PS2_INT_ON(); // POR(150-2000ms) plus BAT(300-500ms) may take 2.5sec([3]p.20) - //wait_ms(2500); + // wait_ms(2500); } uint8_t ps2_host_send(uint8_t data) { @@ -105,7 +103,7 @@ uint8_t ps2_host_send(uint8_t data) { /* terminate a transmission if we have */ inhibit(); - wait_us(100); // 100us [4]p.13, [5]p.50 + wait_us(100); // 100us [4]p.13, [5]p.50 /* 'Request to Send' and Start bit */ data_lo(); @@ -175,8 +173,7 @@ uint8_t ps2_host_recv(void) { } } -void ps2_interrupt_service_routine(void) -{ +void ps2_interrupt_service_routine(void) { static enum { INIT, START, @@ -246,16 +243,10 @@ void ps2_interrupt_service_routine(void) return; } - #if defined(__AVR__) -ISR(PS2_INT_VECT) -{ - ps2_interrupt_service_routine(); -} +ISR(PS2_INT_VECT) { ps2_interrupt_service_routine(); } #endif - - /* send LED state to keyboard */ void ps2_host_set_led(uint8_t led) { ps2_host_send(0xED); @@ -314,7 +305,7 @@ static inline bool pbuf_has_data(void) { bool has_data = (pbuf_head != pbuf_tail); #if defined(__AVR__) - SREG = sreg; + SREG = sreg; #endif return has_data; } @@ -326,6 +317,6 @@ static inline void pbuf_clear(void) { pbuf_head = pbuf_tail = 0; #if defined(__AVR__) - SREG = sreg; + SREG = sreg; #endif } diff --git a/tmk_core/protocol/ps2_io_chibios.c b/tmk_core/protocol/ps2_io_chibios.c index 822d4309c3ba..b672bd1f47fa 100644 --- a/tmk_core/protocol/ps2_io_chibios.c +++ b/tmk_core/protocol/ps2_io_chibios.c @@ -1,44 +1,35 @@ #include #include "ps2_io.h" - // chibiOS headers #include "ch.h" #include "hal.h" - /* Check port settings for clock and data line */ #if !(defined(PS2_CLOCK)) -# error "PS/2 clock setting is required in config.h" +# error "PS/2 clock setting is required in config.h" #endif #if !(defined(PS2_DATA)) -# error "PS/2 data setting is required in config.h" +# error "PS/2 data setting is required in config.h" #endif - - /* * Clock */ -void clock_init(void) -{ -} +void clock_init(void) {} -void clock_lo(void) -{ +void clock_lo(void) { palSetLineMode(PS2_CLOCK, PAL_MODE_OUTPUT_OPENDRAIN); palWriteLine(PS2_CLOCK, PAL_LOW); } -void clock_hi(void) -{ +void clock_hi(void) { palSetLineMode(PS2_CLOCK, PAL_MODE_OUTPUT_OPENDRAIN); palWriteLine(PS2_CLOCK, PAL_HIGH); } -bool clock_in(void) -{ +bool clock_in(void) { palSetLineMode(PS2_CLOCK, PAL_MODE_INPUT); return palReadLine(PS2_CLOCK); } @@ -46,24 +37,19 @@ bool clock_in(void) /* * Data */ -void data_init(void) -{ -} +void data_init(void) {} -void data_lo(void) -{ +void data_lo(void) { palSetLineMode(PS2_DATA, PAL_MODE_OUTPUT_OPENDRAIN); palWriteLine(PS2_DATA, PAL_LOW); } -void data_hi(void) -{ +void data_hi(void) { palSetLineMode(PS2_DATA, PAL_MODE_OUTPUT_OPENDRAIN); palWriteLine(PS2_DATA, PAL_HIGH); } -bool data_in(void) -{ +bool data_in(void) { palSetLineMode(PS2_DATA, PAL_MODE_INPUT); return palReadLine(PS2_DATA); } diff --git a/tmk_core/protocol/ps2_mouse.c b/tmk_core/protocol/ps2_mouse.c index c23901a01a78..13e840be6a3f 100644 --- a/tmk_core/protocol/ps2_mouse.c +++ b/tmk_core/protocol/ps2_mouse.c @@ -18,7 +18,7 @@ along with this program. If not, see . #include #if defined(__AVR__) - #include +# include #endif #include "ps2_mouse.h" @@ -46,7 +46,7 @@ static inline void ps2_mouse_scroll_button_task(report_mouse_t *mouse_report); void ps2_mouse_init(void) { ps2_host_init(); - wait_ms(PS2_MOUSE_INIT_DELAY); // wait for powering up + wait_ms(PS2_MOUSE_INIT_DELAY); // wait for powering up PS2_MOUSE_SEND(PS2_MOUSE_RESET, "ps2_mouse_init: sending reset"); From 33f99188f62d5aabea04dc9ddbf3188c1cf49d4d Mon Sep 17 00:00:00 2001 From: Johannes Date: Wed, 20 May 2020 18:58:48 +0200 Subject: [PATCH 15/15] ps2_mouse: add systemlocks using the chibios equivalent to AVRs cli: chSys[Unl|L]ock --- tmk_core/protocol/ps2_interrupt.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tmk_core/protocol/ps2_interrupt.c b/tmk_core/protocol/ps2_interrupt.c index ef9710e88a11..780040d1526c 100644 --- a/tmk_core/protocol/ps2_interrupt.c +++ b/tmk_core/protocol/ps2_interrupt.c @@ -264,6 +264,8 @@ static inline void pbuf_enqueue(uint8_t data) { #if defined(__AVR__) uint8_t sreg = SREG; cli(); +#elif defined(PROTOCOL_CHIBIOS) + chSysLockFromISR(); #endif uint8_t next = (pbuf_head + 1) % PBUF_SIZE; @@ -276,6 +278,8 @@ static inline void pbuf_enqueue(uint8_t data) { #if defined(__AVR__) SREG = sreg; +#elif defined(PROTOCOL_CHIBIOS) + chSysUnlockFromISR(); #endif } static inline uint8_t pbuf_dequeue(void) { @@ -284,6 +288,8 @@ static inline uint8_t pbuf_dequeue(void) { #if defined(__AVR__) uint8_t sreg = SREG; cli(); +#elif defined(PROTOCOL_CHIBIOS) + chSysLock(); #endif if (pbuf_head != pbuf_tail) { @@ -293,6 +299,8 @@ static inline uint8_t pbuf_dequeue(void) { #if defined(__AVR__) SREG = sreg; +#elif defined(PROTOCOL_CHIBIOS) + chSysUnlock(); #endif return val; @@ -301,11 +309,16 @@ static inline bool pbuf_has_data(void) { #if defined(__AVR__) uint8_t sreg = SREG; cli(); +#elif defined(PROTOCOL_CHIBIOS) + chSysLock(); #endif bool has_data = (pbuf_head != pbuf_tail); + #if defined(__AVR__) SREG = sreg; +#elif defined(PROTOCOL_CHIBIOS) + chSysUnlock(); #endif return has_data; } @@ -313,10 +326,15 @@ static inline void pbuf_clear(void) { #if defined(__AVR__) uint8_t sreg = SREG; cli(); +#elif defined(PROTOCOL_CHIBIOS) + chSysLock(); #endif pbuf_head = pbuf_tail = 0; + #if defined(__AVR__) SREG = sreg; +#elif defined(PROTOCOL_CHIBIOS) + chSysUnlock(); #endif }