aboutsummaryrefslogtreecommitdiff
path: root/drivers/sensors/adns5050.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/sensors/adns5050.c')
-rw-r--r--drivers/sensors/adns5050.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/drivers/sensors/adns5050.c b/drivers/sensors/adns5050.c
index 97daa8db09..1768c9f3b4 100644
--- a/drivers/sensors/adns5050.c
+++ b/drivers/sensors/adns5050.c
@@ -21,6 +21,7 @@
#include "wait.h"
#include "debug.h"
#include "gpio.h"
+#include "pointing_device_internal.h"
// Registers
// clang-format off
@@ -45,6 +46,15 @@
#define REG_MOTION_BURST 0x63
// clang-format on
+const pointing_device_driver_t adns5050_pointing_device_driver = {
+ .init = adns5050_init,
+ .get_report = adns5050_get_report,
+ .set_cpi = adns5050_set_cpi,
+ .get_cpi = adns5050_get_cpi,
+};
+
+static bool powered_down = false;
+
void adns5050_init(void) {
// Initialize the ADNS serial pins.
gpio_set_pin_output(ADNS5050_SCLK_PIN);
@@ -59,6 +69,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 +175,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 +227,22 @@ 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);
+ }
+}
+
+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) {
+ 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;
+ }
+
+ return mouse_report;
+}