summaryrefslogtreecommitdiffstats
path: root/keyboards/crkbd/keymaps/vlukash_trackpad_right/trackpad.c
diff options
context:
space:
mode:
authorVolodymyr Lukashevych <vlukash@users.noreply.github.com>2019-06-11 15:18:14 -0700
committerDrashna Jaelre <drashna@live.com>2019-06-11 15:18:14 -0700
commitb92387b7499e21603e241d136db92c6e716b0cba (patch)
tree98626a4cd72b4fbd043a24a5c63b731c3ce0cd89 /keyboards/crkbd/keymaps/vlukash_trackpad_right/trackpad.c
parent2558466d78a2c2436dedeff593491bdb20780cfc (diff)
[Keymap] Add BB8520 trackpad support for CrKbd (#5925)
* Add vlukash CrKbd keymap to support trackpad adapter. The trackpad adapter uses Elite-C board that has five extra pins. Also SPI pins are taken for trackpad, keymap config updates column data pins for matrix scan. * Update vlukash keymap * Enable pointing devide, configure mouse BTN1 * Set TAPPING_TERM to 300 * Add support for the BlackBerry 8520 trackpad * Add vlukash keymap for master-right no-trackpad version * Remap backspace * Set EXTRAKEY_ENABLE = yes * Update thumb keys mappings * Set bootloader to atmel-dfu * Sync keymap * Add scrolling support * Make debug LEDS conditional * Add support for both flex and no-flex PCBs * Add readme and rename root folders * Update readme file with blog link * Fix readme file formatting * Remove ADJUST keycode, code cleanup. * Add Win key to the keymap.
Diffstat (limited to 'keyboards/crkbd/keymaps/vlukash_trackpad_right/trackpad.c')
-rw-r--r--keyboards/crkbd/keymaps/vlukash_trackpad_right/trackpad.c78
1 files changed, 78 insertions, 0 deletions
diff --git a/keyboards/crkbd/keymaps/vlukash_trackpad_right/trackpad.c b/keyboards/crkbd/keymaps/vlukash_trackpad_right/trackpad.c
new file mode 100644
index 0000000000..afccb8c7ed
--- /dev/null
+++ b/keyboards/crkbd/keymaps/vlukash_trackpad_right/trackpad.c
@@ -0,0 +1,78 @@
+#include "trackpad.h"
+
+// bool isScrollingMode = false;
+bool isScrollMode = false;
+
+void pointing_device_init(void){
+
+ SPI_Init(SPI_SPEED_FCPU_DIV_8 | SPI_MODE_MASTER);
+
+ // Set as output
+ TP_RESET_INIT;
+ TP_SHUTDOWN_INIT;
+ TP_CS_INIT;
+ LVL_SHIFT_EN_INIT;
+
+ // Reset level shifter
+ LVL_SHIFT_EN_LO;
+ wait_ms(100);
+ LVL_SHIFT_EN_HI;
+
+ // Force a BB-8520 reset
+ TP_RESET_HI;
+ wait_ms(100);
+ TP_RESET_LO;
+
+ // Turn on BB-8520 trackpad
+ TP_SHUTDOWN_LO;
+
+ TP_CS_HI;
+}
+
+uint8_t readRegister(uint8_t address) {
+ uint8_t data;
+
+ TP_CS_LO;
+
+ // Read the data
+ SPI_TransferByte(address);
+ data = SPI_TransferByte(0x00);
+
+ TP_CS_HI;
+
+ return data;
+}
+
+void pointing_device_task(void){
+ uint8_t motion = readRegister(0x02);
+
+ // Motion has occurred on the trackpad
+ if (motion > 127) {
+
+ int8_t dx, dy;
+
+ if(TRACKPAD_CONNECTOR_VER == 1) {
+ dx = readRegister(0x03);
+ dy = -readRegister(0x04);
+ }
+ else {
+ dy = -readRegister(0x03);
+ dx = -readRegister(0x04);
+ }
+
+ report_mouse_t currentReport = pointing_device_get_report();
+ if (isScrollMode)
+ {
+ currentReport.h = dx/SCROLL_SPEED_DIVIDER;
+ currentReport.v = dy/SCROLL_SPEED_DIVIDER;
+ }
+ else
+ {
+ currentReport.x = dx * POINTER_SPEED_MULTIPLIER;
+ currentReport.y = dy * POINTER_SPEED_MULTIPLIER;
+ }
+
+ pointing_device_set_report(currentReport);
+ pointing_device_send();
+ }
+}