From 7e3294dc52566f68ee3ba56f26297756b26a48a6 Mon Sep 17 00:00:00 2001 From: Stefan Kerkmann Date: Tue, 12 Jul 2022 22:02:42 +0200 Subject: [PATCH] Introduce pointing device specific debug messages As these can be come quite verbose, these can be enabled with POINTING_DEVICE_DEBUG define on a keyboard level. --- docs/feature_pointing_device.md | 10 ++++++++++ drivers/sensors/cirque_pinnacle_i2c.c | 9 +++------ drivers/sensors/cirque_pinnacle_spi.c | 9 +++------ drivers/sensors/pimoroni_trackball.c | 12 ++++++------ drivers/sensors/pmw33xx_common.c | 8 ++++---- quantum/pointing_device_drivers.c | 20 +++++++++----------- quantum/pointing_device_internal.h | 14 ++++++++++++++ 7 files changed, 49 insertions(+), 33 deletions(-) create mode 100644 quantum/pointing_device_internal.h diff --git a/docs/feature_pointing_device.md b/docs/feature_pointing_device.md index 607c74c56251..1df2ca5c02a9 100644 --- a/docs/feature_pointing_device.md +++ b/docs/feature_pointing_device.md @@ -437,3 +437,13 @@ report_mouse_t pointing_device_task_combined_user(report_mouse_t left_report, re } ``` ======= + +# Troubleshooting + +If you are having issues with pointing device drivers debug messages can be enabled that will give you insights in the inner workings. To enable these add to your keyboards `config.h` file: + +```c +#define POINTING_DEVICE_DEBUG +``` + +?> The messages will be printed out to the `CONSOLE` output. For additional information, refer to [Debugging/Troubleshooting QMK](faq_debug.md). diff --git a/drivers/sensors/cirque_pinnacle_i2c.c b/drivers/sensors/cirque_pinnacle_i2c.c index b328dd9a7a3b..8d69e280cf9a 100644 --- a/drivers/sensors/cirque_pinnacle_i2c.c +++ b/drivers/sensors/cirque_pinnacle_i2c.c @@ -1,5 +1,6 @@ // Copyright (c) 2018 Cirque Corp. Restrictions apply. See: www.cirque.com/sw-license #include "cirque_pinnacle.h" +#include "pointing_device_internal.h" #include "i2c_master.h" #include "print.h" #include "debug.h" @@ -18,9 +19,7 @@ void RAP_ReadBytes(uint8_t address, uint8_t* data, uint8_t count) { if (touchpad_init) { i2c_writeReg(CIRQUE_PINNACLE_ADDR << 1, cmdByte, NULL, 0, CIRQUE_PINNACLE_TIMEOUT); if (i2c_readReg(CIRQUE_PINNACLE_ADDR << 1, cmdByte, data, count, CIRQUE_PINNACLE_TIMEOUT) != I2C_STATUS_SUCCESS) { -#ifdef CONSOLE_ENABLE - dprintf("error cirque_pinnacle i2c_readReg\n"); -#endif + pd_dprintf("error cirque_pinnacle i2c_readReg\n"); touchpad_init = false; } i2c_stop(); @@ -33,9 +32,7 @@ void RAP_Write(uint8_t address, uint8_t data) { if (touchpad_init) { if (i2c_writeReg(CIRQUE_PINNACLE_ADDR << 1, cmdByte, &data, sizeof(data), CIRQUE_PINNACLE_TIMEOUT) != I2C_STATUS_SUCCESS) { -#ifdef CONSOLE_ENABLE - dprintf("error cirque_pinnacle i2c_writeReg\n"); -#endif + pd_dprintf("error cirque_pinnacle i2c_writeReg\n"); touchpad_init = false; } i2c_stop(); diff --git a/drivers/sensors/cirque_pinnacle_spi.c b/drivers/sensors/cirque_pinnacle_spi.c index bd980fc86334..9b812c2d4d52 100644 --- a/drivers/sensors/cirque_pinnacle_spi.c +++ b/drivers/sensors/cirque_pinnacle_spi.c @@ -1,5 +1,6 @@ // Copyright (c) 2018 Cirque Corp. Restrictions apply. See: www.cirque.com/sw-license #include "cirque_pinnacle.h" +#include "pointing_device_internal.h" #include "spi_master.h" #include "print.h" #include "debug.h" @@ -24,9 +25,7 @@ void RAP_ReadBytes(uint8_t address, uint8_t* data, uint8_t count) { data[i] = spi_write(FILLER_BYTE); // write filler, receive data on the third filler send } } else { -#ifdef CONSOLE_ENABLE - dprintf("error cirque_pinnacle spi_start read\n"); -#endif + pd_dprintf("error cirque_pinnacle spi_start read\n"); touchpad_init = false; } spi_stop(); @@ -42,9 +41,7 @@ void RAP_Write(uint8_t address, uint8_t data) { spi_write(cmdByte); spi_write(data); } else { -#ifdef CONSOLE_ENABLE - dprintf("error cirque_pinnacle spi_start write\n"); -#endif + pd_dprintf("error cirque_pinnacle spi_start write\n"); touchpad_init = false; } spi_stop(); diff --git a/drivers/sensors/pimoroni_trackball.c b/drivers/sensors/pimoroni_trackball.c index 88a351316b0c..c1ca8e32c189 100644 --- a/drivers/sensors/pimoroni_trackball.c +++ b/drivers/sensors/pimoroni_trackball.c @@ -15,6 +15,7 @@ * along with this program. If not, see . */ #include "pimoroni_trackball.h" +#include "pointing_device_internal.h" #include "i2c_master.h" #include "print.h" #include "debug.h" @@ -58,22 +59,21 @@ void pimoroni_trackball_set_rgbw(uint8_t r, uint8_t g, uint8_t b, uint8_t w) { uint8_t data[4] = {r, g, b, w}; __attribute__((unused)) i2c_status_t status = i2c_writeReg(PIMORONI_TRACKBALL_ADDRESS << 1, PIMORONI_TRACKBALL_REG_LED_RED, data, sizeof(data), PIMORONI_TRACKBALL_TIMEOUT); -#ifdef CONSOLE_ENABLE - if (debug_mouse) dprintf("Trackball RGBW i2c_status_t: %d\n", status); -#endif + if (debug_mouse) { + pd_dprintf("Trackball RGBW i2c_status_t: %d\n", status); + } } i2c_status_t read_pimoroni_trackball(pimoroni_data_t* data) { i2c_status_t status = i2c_readReg(PIMORONI_TRACKBALL_ADDRESS << 1, PIMORONI_TRACKBALL_REG_LEFT, (uint8_t*)data, sizeof(*data), PIMORONI_TRACKBALL_TIMEOUT); -#ifdef CONSOLE_ENABLE + if (debug_mouse) { static uint16_t d_timer; if (timer_elapsed(d_timer) > PIMORONI_TRACKBALL_DEBUG_INTERVAL) { - dprintf("Trackball READ i2c_status_t: %d L: %d R: %d Up: %d D: %d SW: %d\n", status, data->left, data->right, data->up, data->down, data->click); + pd_dprintf("Trackball READ i2c_status_t: %d L: %d R: %d Up: %d D: %d SW: %d\n", status, data->left, data->right, data->up, data->down, data->click); d_timer = timer_read(); } } -#endif return status; } diff --git a/drivers/sensors/pmw33xx_common.c b/drivers/sensors/pmw33xx_common.c index 538c40c4627c..4061d86cf7d5 100644 --- a/drivers/sensors/pmw33xx_common.c +++ b/drivers/sensors/pmw33xx_common.c @@ -153,7 +153,7 @@ bool pmw33xx_init(uint8_t sensor) { pmw33xx_read(sensor, REG_Delta_Y_H); if (!pmw33xx_upload_firmware(sensor)) { - dprintf("PMW33XX (%d): firmware upload failed!\n", sensor); + pd_dprintf("PMW33XX (%d): firmware upload failed!\n", sensor); return false; } @@ -169,7 +169,7 @@ bool pmw33xx_init(uint8_t sensor) { pmw33xx_write(sensor, REG_Lift_Config, PMW33XX_LIFTOFF_DISTANCE); if (!pmw33xx_check_signature(sensor)) { - dprintf("PMW33XX (%d): firmware signature verification failed!\n", sensor); + pd_dprintf("PMW33XX (%d): firmware signature verification failed!\n", sensor); return false; } @@ -184,7 +184,7 @@ pmw33xx_report_t pmw33xx_read_burst(uint8_t sensor) { } if (!in_burst[sensor]) { - dprintf("PMW33XX (%d): burst\n", sensor); + pd_dprintf("PMW33XX (%d): burst\n", sensor); if (!pmw33xx_write(sensor, REG_Motion_Burst, 0x00)) { return report; } @@ -208,7 +208,7 @@ pmw33xx_report_t pmw33xx_read_burst(uint8_t sensor) { spi_stop(); if (debug_config.mouse) { - dprintf("PMW33XX (%d): motion: 0x%x dx: %i dy: %i\n", sensor, report.motion.w, report.delta_x, report.delta_y); + pd_dprintf("PMW33XX (%d): motion: 0x%x dx: %i dy: %i\n", sensor, report.motion.w, report.delta_x, report.delta_y); } report.delta_x *= -1; diff --git a/quantum/pointing_device_drivers.c b/quantum/pointing_device_drivers.c index b7e98e897e4f..c152185f8323 100644 --- a/quantum/pointing_device_drivers.c +++ b/quantum/pointing_device_drivers.c @@ -17,6 +17,7 @@ */ #include "pointing_device.h" +#include "pointing_device_internal.h" #include "debug.h" #include "wait.h" #include "timer.h" @@ -31,10 +32,9 @@ report_mouse_t adns5050_get_report(report_mouse_t mouse_report) { report_adns5050_t data = adns5050_read_burst(); if (data.dx != 0 || data.dy != 0) { -# ifdef CONSOLE_ENABLE - if (debug_mouse) dprintf("Raw ] X: %d, Y: %d\n", data.dx, data.dy); -# endif - + if (debug_mouse) { + pd_dprintf("Raw ] X: %d, Y: %d\n", data.dx, data.dy); + } mouse_report.x = (mouse_xy_report_t)data.dx; mouse_report.y = (mouse_xy_report_t)data.dy; } @@ -75,9 +75,9 @@ const pointing_device_driver_t pointing_device_driver = { report_mouse_t analog_joystick_get_report(report_mouse_t mouse_report) { report_analog_joystick_t data = analog_joystick_read(); -# ifdef CONSOLE_ENABLE - if (debug_mouse) dprintf("Raw ] X: %d, Y: %d\n", data.x, data.y); -# endif + if (debug_mouse) { + pd_dprintf("Raw ] X: %d, Y: %d\n", data.x, data.y); + } mouse_report.x = data.x; mouse_report.y = data.y; @@ -142,11 +142,9 @@ report_mouse_t cirque_pinnacle_get_report(report_mouse_t mouse_report) { return mouse_report; } -# if CONSOLE_ENABLE if (debug_mouse && touchData.touchDown) { - dprintf("cirque_pinnacle touchData x=%4d y=%4d z=%2d\n", touchData.xValue, touchData.yValue, touchData.zValue); + pd_dprintf("cirque_pinnacle touchData x=%4d y=%4d z=%2d\n", touchData.xValue, touchData.yValue, touchData.zValue); } -# endif // Scale coordinates to arbitrary X, Y resolution cirque_pinnacle_scale_data(&touchData, cirque_pinnacle_get_scale(), cirque_pinnacle_get_scale()); @@ -285,7 +283,7 @@ report_mouse_t pmw33xx_get_report(report_mouse_t mouse_report) { if (!in_motion) { in_motion = true; - dprintf("PWM3360 (0): starting motion\n"); + pd_dprintf("PWM3360 (0): starting motion\n"); } mouse_report.x = CONSTRAIN_HID_XY(report.delta_x); diff --git a/quantum/pointing_device_internal.h b/quantum/pointing_device_internal.h new file mode 100644 index 000000000000..1846df7713a5 --- /dev/null +++ b/quantum/pointing_device_internal.h @@ -0,0 +1,14 @@ +// Copyright 2022 Stefan Kerkmann +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#ifdef POINTING_DEVICE_DEBUG +# include +# include +# define pd_dprintf(...) dprintf(__VA_ARGS__) +#else +# define pd_dprintf(...) \ + do { \ + } while (0) +#endif