From cc3bc2af11744fe22e063bfb8ed1b8dcf7562224 Mon Sep 17 00:00:00 2001 From: Colin Kinloch Date: Mon, 26 Aug 2024 21:06:53 +0100 Subject: [PATCH] Add ability to poweroff ADNS5050 sensor (#24223) * Add ability to poweroff ADNS5050 sensor * ploopyco/trackball_nano: Poweroff ADNS5050 on suspend --- drivers/sensors/adns5050.c | 15 +++++++++++++++ drivers/sensors/adns5050.h | 1 + .../trackball_nano/keymaps/default/keymap.c | 9 +++++++++ 3 files changed, 25 insertions(+) diff --git a/drivers/sensors/adns5050.c b/drivers/sensors/adns5050.c index 97daa8db099..f28a5dcc455 100644 --- a/drivers/sensors/adns5050.c +++ b/drivers/sensors/adns5050.c @@ -45,6 +45,8 @@ #define REG_MOTION_BURST 0x63 // clang-format on +static bool powered_down = false; + void adns5050_init(void) { // Initialize the ADNS serial pins. gpio_set_pin_output(ADNS5050_SCLK_PIN); @@ -59,6 +61,8 @@ void adns5050_init(void) { // this ensures that the adns is actuall ready after reset. wait_ms(55); + powered_down = false; + // read a burst from the adns and then discard it. // gets the adns ready for write commands // (for example, setting the dpi). @@ -163,6 +167,10 @@ report_adns5050_t adns5050_read_burst(void) { data.dx = 0; data.dy = 0; + if (powered_down) { + return data; + } + adns5050_serial_write(REG_MOTION_BURST); // We don't need a minimum tSRAD here. That's because a 4ms wait time is @@ -211,3 +219,10 @@ bool adns5050_check_signature(void) { return (pid == 0x12 && rid == 0x01 && pid2 == 0x26); } + +void adns5050_power_down(void) { + if (!powered_down) { + powered_down = true; + adns5050_write_reg(REG_MOUSE_CONTROL, 0b10); + } +} diff --git a/drivers/sensors/adns5050.h b/drivers/sensors/adns5050.h index 8ef0f7cc7ce..586f16b590b 100644 --- a/drivers/sensors/adns5050.h +++ b/drivers/sensors/adns5050.h @@ -83,3 +83,4 @@ void adns5050_set_cpi(uint16_t cpi); uint16_t adns5050_get_cpi(void); int8_t convert_twoscomp(uint8_t data); bool adns5050_check_signature(void); +void adns5050_power_down(void); diff --git a/keyboards/ploopyco/trackball_nano/keymaps/default/keymap.c b/keyboards/ploopyco/trackball_nano/keymaps/default/keymap.c index 871f8006eae..f13fbc5d945 100644 --- a/keyboards/ploopyco/trackball_nano/keymaps/default/keymap.c +++ b/keyboards/ploopyco/trackball_nano/keymaps/default/keymap.c @@ -20,3 +20,12 @@ // Dummy const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {{{ KC_NO }}}; + +void suspend_power_down_user(void) { + // Switch off sensor + LED making trackball unable to wake host + adns5050_power_down(); +} + +void suspend_wakeup_init_user(void) { + adns5050_init(); +}