aboutsummaryrefslogtreecommitdiff
path: root/drivers/sensors/adns9800.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/sensors/adns9800.c')
-rw-r--r--drivers/sensors/adns9800.c83
1 files changed, 53 insertions, 30 deletions
diff --git a/drivers/sensors/adns9800.c b/drivers/sensors/adns9800.c
index d5e2ca625a..0dbc528351 100644
--- a/drivers/sensors/adns9800.c
+++ b/drivers/sensors/adns9800.c
@@ -15,7 +15,6 @@
*/
#include "spi_master.h"
-#include "adns9800_srom_A6.h"
#include "adns9800.h"
#include "wait.h"
@@ -78,6 +77,21 @@
#define MSB1 0x80
// clang-format on
+const pointing_device_driver_t adns9800_pointing_device_driver = {
+ .init = adns9800_init,
+ .get_report = adns9800_get_report_driver,
+ .set_cpi = adns9800_set_cpi,
+ .get_cpi = adns9800_get_cpi,
+};
+
+uint16_t __attribute__((weak)) adns9800_srom_get_length(void) {
+ return 0;
+}
+
+uint8_t __attribute__((weak)) adns9800_srom_get_byte(uint16_t position) {
+ return 0;
+}
+
void adns9800_spi_start(void) {
spi_start(ADNS9800_CS_PIN, false, ADNS9800_SPI_MODE, ADNS9800_SPI_DIVISOR);
}
@@ -117,47 +131,47 @@ void adns9800_init(void) {
adns9800_read(REG_Delta_Y_L);
adns9800_read(REG_Delta_Y_H);
-#ifdef ADNS9800_UPLOAD_SROM
- // upload firmware
-
- // 3k firmware mode
- adns9800_write(REG_Configuration_IV, 0x02);
+ if (adns9800_srom_get_length() != 0) {
+ // upload firmware
- // enable initialisation
- adns9800_write(REG_SROM_Enable, 0x1d);
+ // 3k firmware mode
+ adns9800_write(REG_Configuration_IV, 0x02);
- // wait a frame
- wait_ms(10);
+ // enable initialisation
+ adns9800_write(REG_SROM_Enable, 0x1d);
- // start SROM download
- adns9800_write(REG_SROM_Enable, 0x18);
+ // wait a frame
+ wait_ms(10);
- // write the SROM file
+ // start SROM download
+ adns9800_write(REG_SROM_Enable, 0x18);
- adns9800_spi_start();
+ // write the SROM file
- spi_write(REG_SROM_Load_Burst | 0x80);
- wait_us(15);
+ adns9800_spi_start();
- // send all bytes of the firmware
- for (uint16_t i = 0; i < FIRMWARE_LENGTH; i++) {
- spi_write(pgm_read_byte(firmware_data + i));
+ spi_write(REG_SROM_Load_Burst | 0x80);
wait_us(15);
- }
- spi_stop();
+ // send all bytes of the firmware
+ for (uint16_t i = 0; i < adns9800_srom_get_length(); i++) {
+ spi_write(adns9800_srom_get_byte(i));
+ wait_us(15);
+ }
+
+ spi_stop();
- wait_ms(10);
-#else
- // write reset value to REG_Configuration_IV
- adns9800_write(REG_Configuration_IV, 0x0);
+ wait_ms(10);
+ } else {
+ // write reset value to REG_Configuration_IV
+ adns9800_write(REG_Configuration_IV, 0x0);
- // write reset value to REG_SROM_Enable
- adns9800_write(REG_SROM_Enable, 0x0);
+ // write reset value to REG_SROM_Enable
+ adns9800_write(REG_SROM_Enable, 0x0);
- // wait a frame
- wait_ms(10);
-#endif
+ // wait a frame
+ wait_ms(10);
+ }
// enable laser
uint8_t laser_ctrl0 = adns9800_read(REG_LASER_CTRL0);
@@ -229,3 +243,12 @@ report_adns9800_t adns9800_get_report(void) {
return report;
}
+
+report_mouse_t adns9800_get_report_driver(report_mouse_t mouse_report) {
+ report_adns9800_t sensor_report = adns9800_get_report();
+
+ mouse_report.x = CONSTRAIN_HID_XY(sensor_report.x);
+ mouse_report.y = CONSTRAIN_HID_XY(sensor_report.y);
+
+ return mouse_report;
+}