From 389077d580b6c976c9578b13462aef074581f205 Mon Sep 17 00:00:00 2001 From: 7m4mon <7m4mon@gmail.com> Date: Fri, 17 Dec 2021 10:59:19 +0900 Subject: [PATCH] Add support for STM32F1 boards. (#114) --- .../K3NG_PS2Keyboard/K3NG_PS2Keyboard.cpp | 21 +++++++++++++++++-- libraries/K3NG_PS2Keyboard/K3NG_PS2Keyboard.h | 11 +++++++++- libraries/K3NG_PS2Keyboard/library.properties | 2 +- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/libraries/K3NG_PS2Keyboard/K3NG_PS2Keyboard.cpp b/libraries/K3NG_PS2Keyboard/K3NG_PS2Keyboard.cpp index 281a8f1..1f9cdec 100755 --- a/libraries/K3NG_PS2Keyboard/K3NG_PS2Keyboard.cpp +++ b/libraries/K3NG_PS2Keyboard/K3NG_PS2Keyboard.cpp @@ -46,7 +46,7 @@ // K3NG Version 2017.05.12.01 -#if !defined(ARDUINO_SAM_DUE) +#if !defined(ARDUINO_SAM_DUE) && !defined (__STM32F1__) #include #include #include @@ -64,6 +64,10 @@ static volatile uint8_t head, tail; static uint8_t ps2Keyboard_DataPin; static char ps2Keyboard_CharBuffer=0; +#if defined (__STM32F1__) // < 2017/01/14 modified by Tamakichi + #define gpio_read(pin) gpio_read_bit(PIN_MAP[pin].gpio_device, PIN_MAP[pin].gpio_bit)?HIGH:LOW +#endif + // The ISR for the external interrupt void k3ng_ps2interrupt(void) { @@ -72,8 +76,13 @@ void k3ng_ps2interrupt(void) static uint32_t prev_ms=0; uint32_t now_ms; uint8_t n, val; - + +#if defined (__STM32F1__) + val = gpio_read(ps2Keyboard_DataPin); +#else val = digitalRead(ps2Keyboard_DataPin); +#endif + now_ms = millis(); if (now_ms - prev_ms > 250) { bitcount = 0; @@ -474,6 +483,13 @@ void K3NG_PS2Keyboard::begin(uint8_t dataPin, uint8_t irq_pin) { ps2Keyboard_DataPin = dataPin; + // initialize the pins +#if defined (__STM32F1__) // < 2017/01/14 modified by Tamakichi + irq_num = irq_pin; + pinMode(irq_pin, INPUT); + pinMode(ps2Keyboard_DataPin, INPUT); +#else // end> + // initialize the pins #ifdef INPUT_PULLUP pinMode(irq_pin, INPUT_PULLUP); @@ -530,6 +546,7 @@ void K3NG_PS2Keyboard::begin(uint8_t dataPin, uint8_t irq_pin) { irq_num = 0; break; } +#endif // __STM32F1__ 2017/01/14 modified by Tamakichi head = 0; tail = 0; attachInterrupt(irq_num, k3ng_ps2interrupt, FALLING); diff --git a/libraries/K3NG_PS2Keyboard/K3NG_PS2Keyboard.h b/libraries/K3NG_PS2Keyboard/K3NG_PS2Keyboard.h index 429d3bd..7853e7e 100755 --- a/libraries/K3NG_PS2Keyboard/K3NG_PS2Keyboard.h +++ b/libraries/K3NG_PS2Keyboard/K3NG_PS2Keyboard.h @@ -34,6 +34,9 @@ K3NG Updates 2015101401 Fixed issues with CTRL and ALT key combinations with German and French keyboards +7M4MON Updates + 20210215 + Add support for STM32F1 boards. (Marged from "https://github.com/Tamakichi/Arduino_PS2Keyboard" by Tamakichi. Tested with STM32F103C Boads). */ @@ -50,12 +53,18 @@ K3NG Updates // #define OPTION_PS2_KEYBOARD_GERMAN // #define OPTION_PS2_KEYBOARD_FRENCH -#if !defined(ARDUINO_SAM_DUE) +#if !defined(ARDUINO_SAM_DUE) && !defined (__STM32F1__) #include #include #include #endif +#if defined(ARDUINO) && ARDUINO >= 100 +#include "Arduino.h" // for attachInterrupt, FALLING +#else +#include "WProgram.h" +#endif + // Every call to read() returns a single byte for each // keystroke. These configure what byte will be returned // for each "special" key. To ignore a key, use zero. diff --git a/libraries/K3NG_PS2Keyboard/library.properties b/libraries/K3NG_PS2Keyboard/library.properties index 2a091c2..40eca8d 100644 --- a/libraries/K3NG_PS2Keyboard/library.properties +++ b/libraries/K3NG_PS2Keyboard/library.properties @@ -6,5 +6,5 @@ sentence=For use with the K3NG CW Keyer for PS2 keyboard support paragraph=For use with the K3NG CW Keyer for PS2 keyboard support category=Uncategorized url=https://github.com/k3ng/k3ng_cw_keyer -architectures=avr +architectures=avr,STM32F1 includes=K3NG_PS2Keyboard.h \ No newline at end of file