Move optical sensor code to drivers folder (#13044)
This commit is contained in:
@ -19,20 +19,16 @@
|
||||
|
||||
|
||||
#include "adns5050.h"
|
||||
#include "quantum.h"
|
||||
#include "wait.h"
|
||||
|
||||
#ifdef CONSOLE_ENABLE
|
||||
# include "print.h"
|
||||
#endif
|
||||
#include "debug.h"
|
||||
#include "print.h"
|
||||
#include "gpio.h"
|
||||
|
||||
#ifndef OPTIC_ROTATED
|
||||
# define OPTIC_ROTATED false
|
||||
#endif
|
||||
|
||||
// Definitions for the ADNS serial line.
|
||||
// These really ought to be defined in your config.h, but defaults are
|
||||
// here if you're really lazy.
|
||||
#ifndef ADNS_SCLK_PIN
|
||||
# define ADNS_SCLK_PIN B7
|
||||
#endif
|
@ -17,7 +17,7 @@
|
||||
#include "spi_master.h"
|
||||
#include "quantum.h"
|
||||
#include "adns9800_srom_A6.h"
|
||||
#include "adns.h"
|
||||
#include "adns9800.h"
|
||||
|
||||
// registers
|
||||
#define REG_Product_ID 0x00
|
@ -26,8 +26,8 @@ static float precisionSpeed = 1;
|
||||
|
||||
static uint16_t i2c_timeout_timer;
|
||||
|
||||
#ifndef I2C_TIMEOUT
|
||||
# define I2C_TIMEOUT 100
|
||||
#ifndef PIMORONI_I2C_TIMEOUT
|
||||
# define PIMORONI_I2C_TIMEOUT 100
|
||||
#endif
|
||||
#ifndef I2C_WAITCHECK
|
||||
# define I2C_WAITCHECK 1000
|
||||
@ -38,7 +38,7 @@ static uint16_t i2c_timeout_timer;
|
||||
|
||||
void trackball_set_rgbw(uint8_t red, uint8_t green, uint8_t blue, uint8_t white) {
|
||||
uint8_t data[] = {0x00, red, green, blue, white};
|
||||
i2c_transmit(TRACKBALL_WRITE, data, sizeof(data), I2C_TIMEOUT);
|
||||
i2c_transmit(TRACKBALL_WRITE, data, sizeof(data), PIMORONI_I2C_TIMEOUT);
|
||||
}
|
||||
|
||||
int16_t mouse_offset(uint8_t positive, uint8_t negative, int16_t scale) {
|
||||
@ -68,59 +68,19 @@ __attribute__((weak)) void trackball_check_click(bool pressed, report_mouse_t* m
|
||||
}
|
||||
}
|
||||
|
||||
bool process_record_kb(uint16_t keycode, keyrecord_t* record) {
|
||||
if (true) {
|
||||
xprintf("KL: kc: %u, col: %u, row: %u, pressed: %u\n", keycode, record->event.key.col, record->event.key.row, record->event.pressed);
|
||||
}
|
||||
|
||||
|
||||
if (!process_record_user(keycode, record)) { return false; }
|
||||
|
||||
/* If Mousekeys is disabled, then use handle the mouse button
|
||||
* keycodes. This makes things simpler, and allows usage of
|
||||
* the keycodes in a consistent manner. But only do this if
|
||||
* Mousekeys is not enable, so it's not handled twice.
|
||||
*/
|
||||
#ifndef MOUSEKEY_ENABLE
|
||||
if (IS_MOUSEKEY_BUTTON(keycode)) {
|
||||
report_mouse_t currentReport = pointing_device_get_report();
|
||||
if (record->event.pressed) {
|
||||
currentReport.buttons |= 1 << (keycode - KC_MS_BTN1);
|
||||
} else {
|
||||
currentReport.buttons &= ~(1 << (keycode - KC_MS_BTN1));
|
||||
}
|
||||
pointing_device_set_report(currentReport);
|
||||
pointing_device_send();
|
||||
}
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void trackball_register_button(bool pressed, enum mouse_buttons button) {
|
||||
report_mouse_t currentReport = pointing_device_get_report();
|
||||
if (pressed) {
|
||||
currentReport.buttons |= button;
|
||||
} else {
|
||||
currentReport.buttons &= ~button;
|
||||
}
|
||||
pointing_device_set_report(currentReport);
|
||||
}
|
||||
|
||||
float trackball_get_precision(void) { return precisionSpeed; }
|
||||
void trackball_set_precision(float precision) { precisionSpeed = precision; }
|
||||
bool trackball_is_scrolling(void) { return scrolling; }
|
||||
void trackball_set_scrolling(bool scroll) { scrolling = scroll; }
|
||||
|
||||
|
||||
__attribute__((weak)) void pointing_device_init(void) { trackball_set_rgbw(0x80, 0x00, 0x00, 0x00); }
|
||||
__attribute__((weak)) void pointing_device_init(void) { i2c_init(); trackball_set_rgbw(0x00, 0x00, 0x00, 0x00); }
|
||||
|
||||
void pointing_device_task(void) {
|
||||
static bool debounce;
|
||||
static uint16_t debounce_timer;
|
||||
uint8_t state[5] = {};
|
||||
if (timer_elapsed(i2c_timeout_timer) > I2C_WAITCHECK) {
|
||||
if (i2c_readReg(TRACKBALL_WRITE, 0x04, state, 5, I2C_TIMEOUT) == I2C_STATUS_SUCCESS) {
|
||||
if (i2c_readReg(TRACKBALL_READ, 0x04, state, 5, PIMORONI_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) {
|
||||
if (!state[4] && !debounce) {
|
||||
if (scrolling) {
|
||||
#ifdef PIMORONI_TRACKBALL_INVERT_X
|
||||
@ -159,7 +119,10 @@ void pointing_device_task(void) {
|
||||
if (timer_elapsed(debounce_timer) > MOUSE_DEBOUNCE) debounce = false;
|
||||
|
||||
report_mouse_t mouse = pointing_device_get_report();
|
||||
// trackball_check_click(state[4] & (1 << 7), &mouse);
|
||||
|
||||
#ifdef PIMORONI_TRACKBALL_CLICK
|
||||
trackball_check_click(state[4] & (1 << 7), &mouse);
|
||||
#endif
|
||||
|
||||
#ifndef PIMORONI_TRACKBALL_ROTATE
|
||||
update_member(&mouse.x, &x_offset);
|
@ -16,8 +16,6 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef POINTING_DEVICE_ENABLE
|
||||
|
||||
#include "wait.h"
|
||||
#include "debug.h"
|
||||
#include "print.h"
|
||||
@ -29,17 +27,26 @@ bool _inBurst = false;
|
||||
#ifndef PMW_CPI
|
||||
# define PMW_CPI 1600
|
||||
#endif
|
||||
#ifndef PMW_CLOCK_SPEED
|
||||
# define PMW_CLOCK_SPEED 70000000
|
||||
#endif
|
||||
#ifndef SPI_MODE
|
||||
# define SPI_MODE 3
|
||||
#endif
|
||||
#ifndef SPI_DIVISOR
|
||||
# define SPI_DIVISOR 2
|
||||
# define SPI_DIVISOR (F_CPU / PMW_CLOCK_SPEED)
|
||||
#endif
|
||||
#ifndef ROTATIONAL_TRANSFORM_ANGLE
|
||||
# define ROTATIONAL_TRANSFORM_ANGLE 0x00
|
||||
#endif
|
||||
#ifndef PMW_CS_PIN
|
||||
# define PMW_CS_PIN SPI_SS_PIN
|
||||
#endif
|
||||
|
||||
void print_byte(uint8_t byte) { dprintf("%c%c%c%c%c%c%c%c|", (byte & 0x80 ? '1' : '0'), (byte & 0x40 ? '1' : '0'), (byte & 0x20 ? '1' : '0'), (byte & 0x10 ? '1' : '0'), (byte & 0x08 ? '1' : '0'), (byte & 0x04 ? '1' : '0'), (byte & 0x02 ? '1' : '0'), (byte & 0x01 ? '1' : '0')); }
|
||||
|
||||
bool spi_start_adv(void) {
|
||||
bool status = spi_start(SPI_SS_PIN, false, 3, SPI_DIVISOR);
|
||||
bool status = spi_start(PMW_CS_PIN, false, SPI_MODE, SPI_DIVISOR);
|
||||
wait_us(1);
|
||||
return status;
|
||||
}
|
||||
@ -57,7 +64,7 @@ spi_status_t spi_write_adv(uint8_t reg_addr, uint8_t data) {
|
||||
spi_start_adv();
|
||||
// send address of the register, with MSBit = 1 to indicate it's a write
|
||||
spi_status_t status = spi_write(reg_addr | 0x80);
|
||||
status = spi_write(data);
|
||||
status = spi_write(data);
|
||||
|
||||
// tSCLK-NCS for write operation
|
||||
wait_us(20);
|
||||
@ -86,14 +93,21 @@ uint8_t spi_read_adv(uint8_t reg_addr) {
|
||||
}
|
||||
|
||||
void pmw_set_cpi(uint16_t cpi) {
|
||||
int cpival = constrain((cpi / 100) - 1, 0, 0x77); // limits to 0--119
|
||||
uint8_t cpival = constrain((cpi / 100) - 1, 0, 0x77); // limits to 0--119
|
||||
|
||||
spi_start_adv();
|
||||
spi_write_adv(REG_Config1, cpival);
|
||||
spi_stop();
|
||||
}
|
||||
|
||||
uint16_t pmw_get_cpi(void) {
|
||||
uint8_t cpival = spi_read_adv(REG_Config1);
|
||||
return (uint16_t)(cpival & 0xFF) * 100;
|
||||
}
|
||||
|
||||
bool pmw_spi_init(void) {
|
||||
setPinOutput(PMW_CS_PIN);
|
||||
|
||||
spi_init();
|
||||
_inBurst = false;
|
||||
|
||||
@ -101,7 +115,7 @@ bool pmw_spi_init(void) {
|
||||
spi_start_adv();
|
||||
spi_stop();
|
||||
|
||||
spi_write_adv(REG_Shutdown, 0xb6); // Shutdown first
|
||||
spi_write_adv(REG_Shutdown, 0xb6); // Shutdown first
|
||||
wait_ms(300);
|
||||
|
||||
spi_start_adv();
|
||||
@ -127,14 +141,18 @@ bool pmw_spi_init(void) {
|
||||
|
||||
wait_ms(1);
|
||||
|
||||
return pmw_check_signature();
|
||||
}
|
||||
|
||||
void pmw_upload_firmware(void) {
|
||||
spi_write_adv(REG_Config2, 0x00);
|
||||
|
||||
spi_write_adv(REG_Angle_Tune, constrain(ROTATIONAL_TRANSFORM_ANGLE, -30, 30));
|
||||
|
||||
bool init_success = pmw_check_signature();
|
||||
|
||||
writePinLow(PMW_CS_PIN);
|
||||
|
||||
return init_success;
|
||||
}
|
||||
|
||||
void pmw_upload_firmware(void) {
|
||||
spi_write_adv(REG_SROM_Enable, 0x1d);
|
||||
|
||||
wait_ms(10);
|
||||
@ -217,5 +235,3 @@ report_pmw_t pmw_read_burst(void) {
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
#endif
|
@ -93,6 +93,7 @@ spi_status_t spi_write_adv(uint8_t reg_addr, uint8_t data);
|
||||
uint8_t spi_read_adv(uint8_t reg_addr);
|
||||
bool pmw_spi_init(void);
|
||||
void pmw_set_cpi(uint16_t cpi);
|
||||
uint16_t pmw_get_cpi(void);
|
||||
void pmw_upload_firmware(void);
|
||||
bool pmw_check_signature(void);
|
||||
report_pmw_t pmw_read_burst(void);
|
@ -16,7 +16,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include QMK_KEYBOARD_H
|
||||
#include "pimoroni_trackball.h"
|
||||
#include "drivers/sensors/pimoroni_trackball.h"
|
||||
#include "pointing_device.h"
|
||||
|
||||
|
||||
|
@ -1,35 +0,0 @@
|
||||
/* Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "quantum.h"
|
||||
#include "pointing_device.h"
|
||||
|
||||
#ifndef TRACKBALL_ADDRESS
|
||||
# define TRACKBALL_ADDRESS 0x0A
|
||||
#endif
|
||||
#define TRACKBALL_WRITE ((TRACKBALL_ADDRESS << 1) | I2C_WRITE)
|
||||
#define TRACKBALL_READ ((TRACKBALL_ADDRESS << 1) | I2C_READ)
|
||||
|
||||
void trackball_set_rgbw(uint8_t red, uint8_t green, uint8_t blue, uint8_t white);
|
||||
void trackball_check_click(bool pressed, report_mouse_t *mouse);
|
||||
void trackball_register_button(bool pressed, enum mouse_buttons button);
|
||||
|
||||
float trackball_get_precision(void);
|
||||
void trackball_set_precision(float precision);
|
||||
bool trackball_is_scrolling(void);
|
||||
void trackball_set_scrolling(bool scroll);
|
@ -1,6 +1,6 @@
|
||||
# only uncomment on the side you have your trackball on
|
||||
POINTING_DEVICE_ENABLE = yes
|
||||
SRC += pimoroni_trackball.c
|
||||
SRC += drivers/sensors/pimoroni_trackball.c
|
||||
QUANTUM_LIB_SRC += i2c_master.c
|
||||
OLED_DRIVER_ENABLE = yes
|
||||
MOUSEKEY_ENABLE = no
|
||||
|
@ -19,7 +19,7 @@
|
||||
#include "dactyl_manuform.h"
|
||||
#include "quantum.h"
|
||||
#include "spi_master.h"
|
||||
#include "pmw3360.h"
|
||||
#include "drivers/sensors/pmw3360.h"
|
||||
#include "pointing_device.h"
|
||||
|
||||
|
||||
|
@ -1,103 +0,0 @@
|
||||
/* Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
|
||||
* Copyright 2019 Sunjun Kim
|
||||
* Copyright 2020 Ploopy Corporation
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "spi_master.h"
|
||||
|
||||
// Registers
|
||||
#define REG_Product_ID 0x00
|
||||
#define REG_Revision_ID 0x01
|
||||
#define REG_Motion 0x02
|
||||
#define REG_Delta_X_L 0x03
|
||||
#define REG_Delta_X_H 0x04
|
||||
#define REG_Delta_Y_L 0x05
|
||||
#define REG_Delta_Y_H 0x06
|
||||
#define REG_SQUAL 0x07
|
||||
#define REG_Raw_Data_Sum 0x08
|
||||
#define REG_Maximum_Raw_data 0x09
|
||||
#define REG_Minimum_Raw_data 0x0A
|
||||
#define REG_Shutter_Lower 0x0B
|
||||
#define REG_Shutter_Upper 0x0C
|
||||
#define REG_Control 0x0D
|
||||
#define REG_Config1 0x0F
|
||||
#define REG_Config2 0x10
|
||||
#define REG_Angle_Tune 0x11
|
||||
#define REG_Frame_Capture 0x12
|
||||
#define REG_SROM_Enable 0x13
|
||||
#define REG_Run_Downshift 0x14
|
||||
#define REG_Rest1_Rate_Lower 0x15
|
||||
#define REG_Rest1_Rate_Upper 0x16
|
||||
#define REG_Rest1_Downshift 0x17
|
||||
#define REG_Rest2_Rate_Lower 0x18
|
||||
#define REG_Rest2_Rate_Upper 0x19
|
||||
#define REG_Rest2_Downshift 0x1A
|
||||
#define REG_Rest3_Rate_Lower 0x1B
|
||||
#define REG_Rest3_Rate_Upper 0x1C
|
||||
#define REG_Observation 0x24
|
||||
#define REG_Data_Out_Lower 0x25
|
||||
#define REG_Data_Out_Upper 0x26
|
||||
#define REG_Raw_Data_Dump 0x29
|
||||
#define REG_SROM_ID 0x2A
|
||||
#define REG_Min_SQ_Run 0x2B
|
||||
#define REG_Raw_Data_Threshold 0x2C
|
||||
#define REG_Config5 0x2F
|
||||
#define REG_Power_Up_Reset 0x3A
|
||||
#define REG_Shutdown 0x3B
|
||||
#define REG_Inverse_Product_ID 0x3F
|
||||
#define REG_LiftCutoff_Tune3 0x41
|
||||
#define REG_Angle_Snap 0x42
|
||||
#define REG_LiftCutoff_Tune1 0x4A
|
||||
#define REG_Motion_Burst 0x50
|
||||
#define REG_LiftCutoff_Tune_Timeout 0x58
|
||||
#define REG_LiftCutoff_Tune_Min_Length 0x5A
|
||||
#define REG_SROM_Load_Burst 0x62
|
||||
#define REG_Lift_Config 0x63
|
||||
#define REG_Raw_Data_Burst 0x64
|
||||
#define REG_LiftCutoff_Tune2 0x65
|
||||
|
||||
#ifdef CONSOLE_ENABLE
|
||||
void print_byte(uint8_t byte);
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
int8_t motion;
|
||||
bool isMotion; // True if a motion is detected.
|
||||
bool isOnSurface; // True when a chip is on a surface
|
||||
int16_t dx; // displacement on x directions. Unit: Count. (CPI * Count = Inch value)
|
||||
int8_t mdx;
|
||||
int16_t dy; // displacement on y directions.
|
||||
int8_t mdy;
|
||||
} report_pmw_t;
|
||||
|
||||
|
||||
|
||||
bool spi_start_adv(void);
|
||||
void spi_stop_adv(void);
|
||||
spi_status_t spi_write_adv(uint8_t reg_addr, uint8_t data);
|
||||
uint8_t spi_read_adv(uint8_t reg_addr);
|
||||
bool pmw_spi_init(void);
|
||||
void pmw_set_cpi(uint16_t cpi);
|
||||
void pmw_upload_firmware(void);
|
||||
bool pmw_check_signature(void);
|
||||
report_pmw_t pmw_read_burst(void);
|
||||
|
||||
|
||||
#define degToRad(angleInDegrees) ((angleInDegrees)*M_PI / 180.0)
|
||||
#define radToDeg(angleInRadians) ((angleInRadians)*180.0 / M_PI)
|
||||
#define constrain(amt, low, high) ((amt) < (low) ? (low) : ((amt) > (high) ? (high) : (amt)))
|
@ -27,5 +27,5 @@ MOUSE_SHARED_EP = no
|
||||
SPLIT_KEYBOARD = yes
|
||||
SPLIT_TRANSPORT = custom
|
||||
|
||||
SRC += pmw3360.c
|
||||
SRC += drivers/sensors/pmw3360.c
|
||||
QUANTUM_LIB_SRC += pointer_transport.c serial.c i2c_master.c i2c_slave.c spi_master.c
|
||||
|
@ -17,7 +17,7 @@
|
||||
/* common interface for opitcal sensors */
|
||||
|
||||
#if defined ADNS_9800
|
||||
#include "../adns/adns.h"
|
||||
#include "drivers/sensors/adns9800.h"
|
||||
#define config_optical_sensor_t config_adns_t
|
||||
#define report_optical_sensor_t report_adns_t
|
||||
#define optical_sensor_init adns_init
|
||||
|
@ -25,5 +25,5 @@ POINTING_DEVICE_ENABLE = yes
|
||||
DEFAULT_FOLDER = oddball/v1
|
||||
|
||||
SRC += spi_master.c
|
||||
SRC += adns/adns.c
|
||||
SRC += drivers/sensors/adns9800.c
|
||||
SRC += pmw/pmw.c
|
||||
|
@ -20,7 +20,7 @@
|
||||
|
||||
#include "quantum.h"
|
||||
#include "spi_master.h"
|
||||
#include "pmw3360.h"
|
||||
#include "drivers/sensors/pmw3360.h"
|
||||
#include "analog.h"
|
||||
#include "opt_encoder.h"
|
||||
#include "pointing_device.h"
|
||||
|
@ -27,4 +27,4 @@ POINTING_DEVICE_ENABLE = yes
|
||||
MOUSEKEY_ENABLE = yes # Mouse keys
|
||||
|
||||
QUANTUM_LIB_SRC += analog.c spi_master.c
|
||||
SRC += pmw3360.c opt_encoder.c
|
||||
SRC += drivers/sensors/pmw3360.c opt_encoder.c
|
||||
|
@ -1,218 +0,0 @@
|
||||
/* Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
|
||||
* Copyright 2019 Sunjun Kim
|
||||
* Copyright 2020 Ploopy Corporation
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "wait.h"
|
||||
#include "debug.h"
|
||||
#include "print.h"
|
||||
#include "pmw3360.h"
|
||||
#include "pmw3360_firmware.h"
|
||||
|
||||
bool _inBurst = false;
|
||||
|
||||
#ifndef PMW_CPI
|
||||
# define PMW_CPI 1600
|
||||
#endif
|
||||
#ifndef SPI_DIVISOR
|
||||
# define SPI_DIVISOR 2
|
||||
#endif
|
||||
#ifndef ROTATIONAL_TRANSFORM_ANGLE
|
||||
# define ROTATIONAL_TRANSFORM_ANGLE 0x00
|
||||
#endif
|
||||
|
||||
void print_byte(uint8_t byte) { dprintf("%c%c%c%c%c%c%c%c|", (byte & 0x80 ? '1' : '0'), (byte & 0x40 ? '1' : '0'), (byte & 0x20 ? '1' : '0'), (byte & 0x10 ? '1' : '0'), (byte & 0x08 ? '1' : '0'), (byte & 0x04 ? '1' : '0'), (byte & 0x02 ? '1' : '0'), (byte & 0x01 ? '1' : '0')); }
|
||||
|
||||
|
||||
bool spi_start_adv(void) {
|
||||
bool status = spi_start(SPI_SS_PIN, false, 3, SPI_DIVISOR);
|
||||
wait_us(1);
|
||||
return status;
|
||||
}
|
||||
|
||||
void spi_stop_adv(void) {
|
||||
wait_us(1);
|
||||
spi_stop();
|
||||
}
|
||||
|
||||
spi_status_t spi_write_adv(uint8_t reg_addr, uint8_t data) {
|
||||
if (reg_addr != REG_Motion_Burst) {
|
||||
_inBurst = false;
|
||||
}
|
||||
|
||||
spi_start_adv();
|
||||
// send address of the register, with MSBit = 1 to indicate it's a write
|
||||
spi_status_t status = spi_write(reg_addr | 0x80);
|
||||
status = spi_write(data);
|
||||
|
||||
// tSCLK-NCS for write operation
|
||||
wait_us(20);
|
||||
|
||||
// tSWW/tSWR (=120us) minus tSCLK-NCS. Could be shortened, but is looks like a safe lower bound
|
||||
wait_us(100);
|
||||
spi_stop();
|
||||
return status;
|
||||
}
|
||||
|
||||
uint8_t spi_read_adv(uint8_t reg_addr) {
|
||||
spi_start_adv();
|
||||
// send adress of the register, with MSBit = 0 to indicate it's a read
|
||||
spi_write(reg_addr & 0x7f);
|
||||
|
||||
uint8_t data = spi_read();
|
||||
|
||||
// tSCLK-NCS for read operation is 120ns
|
||||
wait_us(1);
|
||||
|
||||
// tSRW/tSRR (=20us) minus tSCLK-NCS
|
||||
wait_us(19);
|
||||
|
||||
spi_stop();
|
||||
return data;
|
||||
}
|
||||
|
||||
void pmw_set_cpi(uint16_t cpi) {
|
||||
int cpival = constrain((cpi / 100) - 1, 0, 0x77); // limits to 0--119
|
||||
|
||||
spi_start_adv();
|
||||
spi_write_adv(REG_Config1, cpival);
|
||||
spi_stop();
|
||||
}
|
||||
|
||||
bool pmw_spi_init(void) {
|
||||
spi_init();
|
||||
_inBurst = false;
|
||||
|
||||
spi_stop();
|
||||
spi_start_adv();
|
||||
spi_stop();
|
||||
|
||||
spi_write_adv(REG_Shutdown, 0xb6); // Shutdown first
|
||||
wait_ms(300);
|
||||
|
||||
spi_start_adv();
|
||||
wait_us(40);
|
||||
spi_stop_adv();
|
||||
wait_us(40);
|
||||
|
||||
spi_write_adv(REG_Power_Up_Reset, 0x5a);
|
||||
wait_ms(50);
|
||||
|
||||
spi_read_adv(REG_Motion);
|
||||
spi_read_adv(REG_Delta_X_L);
|
||||
spi_read_adv(REG_Delta_X_H);
|
||||
spi_read_adv(REG_Delta_Y_L);
|
||||
spi_read_adv(REG_Delta_Y_H);
|
||||
|
||||
pmw_upload_firmware();
|
||||
|
||||
spi_stop_adv();
|
||||
|
||||
wait_ms(10);
|
||||
pmw_set_cpi(PMW_CPI);
|
||||
|
||||
wait_ms(1);
|
||||
|
||||
return pmw_check_signature();
|
||||
}
|
||||
|
||||
void pmw_upload_firmware(void) {
|
||||
spi_write_adv(REG_Config2, 0x00);
|
||||
|
||||
spi_write_adv(REG_Angle_Tune, constrain(ROTATIONAL_TRANSFORM_ANGLE, -30, 30));
|
||||
|
||||
spi_write_adv(REG_SROM_Enable, 0x1d);
|
||||
|
||||
wait_ms(10);
|
||||
|
||||
spi_write_adv(REG_SROM_Enable, 0x18);
|
||||
|
||||
spi_start_adv();
|
||||
spi_write(REG_SROM_Load_Burst | 0x80);
|
||||
wait_us(15);
|
||||
|
||||
unsigned char c;
|
||||
for (int i = 0; i < firmware_length; i++) {
|
||||
c = (unsigned char)pgm_read_byte(firmware_data + i);
|
||||
spi_write(c);
|
||||
wait_us(15);
|
||||
}
|
||||
wait_us(200);
|
||||
|
||||
spi_read_adv(REG_SROM_ID);
|
||||
|
||||
spi_write_adv(REG_Config2, 0x00);
|
||||
|
||||
spi_stop();
|
||||
wait_ms(10);
|
||||
}
|
||||
|
||||
bool pmw_check_signature(void) {
|
||||
uint8_t pid = spi_read_adv(REG_Product_ID);
|
||||
uint8_t iv_pid = spi_read_adv(REG_Inverse_Product_ID);
|
||||
uint8_t SROM_ver = spi_read_adv(REG_SROM_ID);
|
||||
return (pid == 0x42 && iv_pid == 0xBD && SROM_ver == 0x04); // signature for SROM 0x04
|
||||
}
|
||||
|
||||
report_pmw_t pmw_read_burst(void) {
|
||||
if (!_inBurst) {
|
||||
dprintf("burst on");
|
||||
spi_write_adv(REG_Motion_Burst, 0x00);
|
||||
_inBurst = true;
|
||||
}
|
||||
|
||||
spi_start_adv();
|
||||
spi_write(REG_Motion_Burst);
|
||||
wait_us(35); // waits for tSRAD
|
||||
|
||||
report_pmw_t data;
|
||||
data.motion = 0;
|
||||
data.dx = 0;
|
||||
data.mdx = 0;
|
||||
data.dy = 0;
|
||||
data.mdx = 0;
|
||||
|
||||
data.motion = spi_read();
|
||||
spi_write(0x00); // skip Observation
|
||||
data.dx = spi_read();
|
||||
data.mdx = spi_read();
|
||||
data.dy = spi_read();
|
||||
data.mdy = spi_read();
|
||||
|
||||
spi_stop();
|
||||
|
||||
print_byte(data.motion);
|
||||
print_byte(data.dx);
|
||||
print_byte(data.mdx);
|
||||
print_byte(data.dy);
|
||||
print_byte(data.mdy);
|
||||
dprintf("\n");
|
||||
|
||||
data.isMotion = (data.motion & 0x80) != 0;
|
||||
data.isOnSurface = (data.motion & 0x08) == 0;
|
||||
data.dx |= (data.mdx << 8);
|
||||
data.dx = data.dx * -1;
|
||||
data.dy |= (data.mdy << 8);
|
||||
data.dy = data.dy * -1;
|
||||
|
||||
spi_stop();
|
||||
|
||||
if (data.motion & 0b111) { // panic recovery, sometimes burst mode works weird.
|
||||
_inBurst = false;
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -24,6 +24,6 @@ POINTING_DEVICE_ENABLE = yes
|
||||
MOUSEKEY_ENABLE = yes # Mouse keys
|
||||
|
||||
QUANTUM_LIB_SRC += analog.c spi_master.c
|
||||
SRC += pmw3360.c opt_encoder.c
|
||||
SRC += drivers/sensors/pmw3360.c opt_encoder.c
|
||||
|
||||
DEFAULT_FOLDER = ploopyco/trackball/rev1_005
|
||||
|
@ -20,7 +20,7 @@
|
||||
|
||||
#include "quantum.h"
|
||||
#include "spi_master.h"
|
||||
#include "pmw3360.h"
|
||||
#include "drivers/sensors/pmw3360.h"
|
||||
#include "analog.h"
|
||||
#include "opt_encoder.h"
|
||||
#include "pointing_device.h"
|
||||
|
@ -27,6 +27,6 @@ POINTING_DEVICE_ENABLE = yes
|
||||
MOUSEKEY_ENABLE = no # Mouse keys
|
||||
|
||||
QUANTUM_LIB_SRC += analog.c
|
||||
SRC += adns5050.c opt_encoder.c
|
||||
SRC += drivers/sensors/adns5050.c opt_encoder.c
|
||||
|
||||
DEFAULT_FOLDER = ploopyco/trackball_mini/rev1_001
|
||||
|
@ -20,7 +20,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "quantum.h"
|
||||
#include "adns5050.h"
|
||||
#include "drivers/sensors/adns5050.h"
|
||||
#include "analog.h"
|
||||
#include "opt_encoder.h"
|
||||
#include "pointing_device.h"
|
||||
|
@ -27,6 +27,6 @@ POINTING_DEVICE_ENABLE = yes
|
||||
MOUSEKEY_ENABLE = no # Mouse keys
|
||||
|
||||
QUANTUM_LIB_SRC += analog.c
|
||||
SRC += adns5050.c opt_encoder.c
|
||||
SRC += drivers/sensors/adns5050.c opt_encoder.c
|
||||
|
||||
DEFAULT_FOLDER = ploopyco/trackball_nano/rev1_001
|
||||
|
@ -20,7 +20,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "quantum.h"
|
||||
#include "adns5050.h"
|
||||
#include "drivers/sensors/adns5050.h"
|
||||
#include "analog.h"
|
||||
#include "opt_encoder.h"
|
||||
#include "pointing_device.h"
|
||||
|
@ -47,3 +47,4 @@
|
||||
|
||||
#define PIMORONI_TRACKBALL_INVERT_X
|
||||
#define PIMORONI_TRACKBALL_INVERT_Y
|
||||
#define PIMORONI_TRACKBALL_CLICK
|
||||
|
@ -33,7 +33,7 @@
|
||||
# include "oled_stuff.h"
|
||||
#endif
|
||||
#if defined(PIMORONI_TRACKBALL_ENABLE)
|
||||
# include "pimoroni_trackball.h"
|
||||
# include "drivers/sensors/pimoroni_trackball.h"
|
||||
#endif
|
||||
|
||||
/* Define layer names */
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user