Przeglądaj źródła

option to set mouse sensor angle

Thomas Buck 1 rok temu
rodzic
commit
42f217de7b

+ 1
- 0
firmware/include/config.h Wyświetl plik

@@ -15,6 +15,7 @@
15 15
 #define INVERT_MOUSE_X_AXIS false
16 16
 #define INVERT_MOUSE_Y_AXIS true
17 17
 #define DEFAULT_MOUSE_SENSITIVITY PMW_CPI_TO_SENSE(500)
18
+#define DEFAULT_MOUSE_ANGLE -30
18 19
 
19 20
 #define INVERT_SCROLL_X_AXIS false
20 21
 #define INVERT_SCROLL_Y_AXIS false

+ 3
- 0
firmware/include/pmw3360.h Wyświetl plik

@@ -33,6 +33,9 @@ uint8_t pmw_get_sensitivity(void);
33 33
 #define PMW_SENSE_TO_CPI(sense) (100 + (sense * 100))
34 34
 #define PMW_CPI_TO_SENSE(cpi) ((cpi / 100) - 1)
35 35
 
36
+void pmw_set_angle(int8_t angle);
37
+int8_t pmw_get_angle(void);
38
+
36 39
 void pmw_print_status(char *buff, size_t len);
37 40
 void pmw_dump_data(bool serial);
38 41
 

+ 15
- 0
firmware/src/console.c Wyświetl plik

@@ -53,6 +53,8 @@ static void cnsl_interpret(const char *line) {
53 53
         println("Trackball Firmware Usage:");
54 54
         println("    cpi - print current sensitivity");
55 55
         println("  cpi N - set sensitivity");
56
+        println("  angle - print current angle");
57
+        println("angle N - set angle");
56 58
         println("   pmws - print PMW3360 status");
57 59
         println("   pmwf - print PMW3360 frame capture");
58 60
         println("   pmwd - print PMW3360 data dump");
@@ -107,6 +109,19 @@ static void cnsl_interpret(const char *line) {
107 109
             println("setting cpi to 0x%02llX", num);
108 110
             pmw_set_sensitivity(num);
109 111
         }
112
+    } else if (strcmp(line, "angle") == 0) {
113
+        int8_t angle = pmw_get_angle();
114
+        println("current angle: %d", angle);
115
+    } else if (str_startswith(line, "angle ")) {
116
+        const char *num_str = line + 6;
117
+        intmax_t num = strtoimax(num_str, NULL, 10);
118
+        if ((num < -128) || (num > 127)) {
119
+            println("invalid angle %lld, needs to be %d <= cpi <= %d", num, -128, 127);
120
+        } else {
121
+            int8_t tmp = num;
122
+            println("setting angle to %d", tmp);
123
+            pmw_set_angle(num);
124
+        }
110 125
     } else if (strcmp(line, "reset") == 0) {
111 126
         reset_to_main();
112 127
     } else if ((strcmp(line, "stats") == 0) || (strcmp(line, "data") == 0)) {

+ 33
- 4
firmware/src/pmw3360.c Wyświetl plik

@@ -310,32 +310,59 @@ static void pmw_motion_irq(void) {
310 310
     }
311 311
 }
312 312
 
313
+static void pmw_irq_start(void) {
314
+    gpio_set_irq_enabled(PMW_MOTION_PIN, GPIO_IRQ_LEVEL_LOW, true);
315
+}
316
+
317
+static void pmw_irq_stop(void) {
318
+    gpio_set_irq_enabled(PMW_MOTION_PIN, GPIO_IRQ_LEVEL_LOW, false);
319
+}
320
+
313 321
 void pmw_set_sensitivity(uint8_t sens) {
314 322
     if (sens > 0x77) {
315 323
         debug("invalid sense, clamping (0x%X > 0x77)", sens);
316 324
         sens = 0x77;
317 325
     }
318 326
 
327
+    pmw_irq_stop();
328
+
319 329
     pmw_write_register(REG_CONFIG1, sens);
320 330
     pmw_write_register(REG_CONFIG5, sens);
331
+
332
+    pmw_irq_start();
321 333
 }
322 334
 
323 335
 uint8_t pmw_get_sensitivity(void) {
336
+    pmw_irq_stop();
337
+
324 338
     uint8_t sense_y = pmw_read_register(REG_CONFIG1);
325 339
     uint8_t sense_x = pmw_read_register(REG_CONFIG5);
326 340
     if (sense_y != sense_x) {
327 341
         debug("sensitivity differs for x (0x%02X) and y (0x%02X). resetting.", sense_x, sense_y);
328 342
         pmw_write_register(REG_CONFIG5, sense_y);
329 343
     }
344
+
345
+    pmw_irq_start();
330 346
     return sense_y;
331 347
 }
332 348
 
333
-static void pmw_irq_start(void) {
334
-    gpio_set_irq_enabled(PMW_MOTION_PIN, GPIO_IRQ_LEVEL_LOW, true);
349
+void pmw_set_angle(int8_t angle) {
350
+    pmw_irq_stop();
351
+
352
+    uint8_t tmp = *((uint8_t *)(&angle));
353
+    pmw_write_register(REG_ANGLE_TUNE, tmp);
354
+
355
+    pmw_irq_start();
335 356
 }
336 357
 
337
-static void pmw_irq_stop(void) {
338
-    gpio_set_irq_enabled(PMW_MOTION_PIN, GPIO_IRQ_LEVEL_LOW, false);
358
+int8_t pmw_get_angle(void) {
359
+    pmw_irq_stop();
360
+
361
+    uint8_t tmp = pmw_read_register(REG_ANGLE_TUNE);
362
+    int8_t angle = *((int8_t *)(&tmp));
363
+
364
+    pmw_irq_start();
365
+    return angle;
339 366
 }
340 367
 
341 368
 static void pmw_irq_init(void) {
@@ -528,6 +555,8 @@ int pmw_init(void) {
528 555
     // Set lift-detection threshold to 3mm (max)
529 556
     pmw_write_register(REG_LIFT_CONFIG, 0x03);
530 557
 
558
+    pmw_set_angle(DEFAULT_MOUSE_ANGLE);
559
+
531 560
     pmw_irq_init();
532 561
 
533 562
     return 0;

Ładowanie…
Anuluj
Zapisz