Browse Source

option to set mouse sensor angle

Thomas Buck 1 year ago
parent
commit
42f217de7b
4 changed files with 52 additions and 4 deletions
  1. 1
    0
      firmware/include/config.h
  2. 3
    0
      firmware/include/pmw3360.h
  3. 15
    0
      firmware/src/console.c
  4. 33
    4
      firmware/src/pmw3360.c

+ 1
- 0
firmware/include/config.h View File

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

+ 3
- 0
firmware/include/pmw3360.h View File

33
 #define PMW_SENSE_TO_CPI(sense) (100 + (sense * 100))
33
 #define PMW_SENSE_TO_CPI(sense) (100 + (sense * 100))
34
 #define PMW_CPI_TO_SENSE(cpi) ((cpi / 100) - 1)
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
 void pmw_print_status(char *buff, size_t len);
39
 void pmw_print_status(char *buff, size_t len);
37
 void pmw_dump_data(bool serial);
40
 void pmw_dump_data(bool serial);
38
 
41
 

+ 15
- 0
firmware/src/console.c View File

53
         println("Trackball Firmware Usage:");
53
         println("Trackball Firmware Usage:");
54
         println("    cpi - print current sensitivity");
54
         println("    cpi - print current sensitivity");
55
         println("  cpi N - set sensitivity");
55
         println("  cpi N - set sensitivity");
56
+        println("  angle - print current angle");
57
+        println("angle N - set angle");
56
         println("   pmws - print PMW3360 status");
58
         println("   pmws - print PMW3360 status");
57
         println("   pmwf - print PMW3360 frame capture");
59
         println("   pmwf - print PMW3360 frame capture");
58
         println("   pmwd - print PMW3360 data dump");
60
         println("   pmwd - print PMW3360 data dump");
107
             println("setting cpi to 0x%02llX", num);
109
             println("setting cpi to 0x%02llX", num);
108
             pmw_set_sensitivity(num);
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
     } else if (strcmp(line, "reset") == 0) {
125
     } else if (strcmp(line, "reset") == 0) {
111
         reset_to_main();
126
         reset_to_main();
112
     } else if ((strcmp(line, "stats") == 0) || (strcmp(line, "data") == 0)) {
127
     } else if ((strcmp(line, "stats") == 0) || (strcmp(line, "data") == 0)) {

+ 33
- 4
firmware/src/pmw3360.c View File

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
 void pmw_set_sensitivity(uint8_t sens) {
321
 void pmw_set_sensitivity(uint8_t sens) {
314
     if (sens > 0x77) {
322
     if (sens > 0x77) {
315
         debug("invalid sense, clamping (0x%X > 0x77)", sens);
323
         debug("invalid sense, clamping (0x%X > 0x77)", sens);
316
         sens = 0x77;
324
         sens = 0x77;
317
     }
325
     }
318
 
326
 
327
+    pmw_irq_stop();
328
+
319
     pmw_write_register(REG_CONFIG1, sens);
329
     pmw_write_register(REG_CONFIG1, sens);
320
     pmw_write_register(REG_CONFIG5, sens);
330
     pmw_write_register(REG_CONFIG5, sens);
331
+
332
+    pmw_irq_start();
321
 }
333
 }
322
 
334
 
323
 uint8_t pmw_get_sensitivity(void) {
335
 uint8_t pmw_get_sensitivity(void) {
336
+    pmw_irq_stop();
337
+
324
     uint8_t sense_y = pmw_read_register(REG_CONFIG1);
338
     uint8_t sense_y = pmw_read_register(REG_CONFIG1);
325
     uint8_t sense_x = pmw_read_register(REG_CONFIG5);
339
     uint8_t sense_x = pmw_read_register(REG_CONFIG5);
326
     if (sense_y != sense_x) {
340
     if (sense_y != sense_x) {
327
         debug("sensitivity differs for x (0x%02X) and y (0x%02X). resetting.", sense_x, sense_y);
341
         debug("sensitivity differs for x (0x%02X) and y (0x%02X). resetting.", sense_x, sense_y);
328
         pmw_write_register(REG_CONFIG5, sense_y);
342
         pmw_write_register(REG_CONFIG5, sense_y);
329
     }
343
     }
344
+
345
+    pmw_irq_start();
330
     return sense_y;
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
 static void pmw_irq_init(void) {
368
 static void pmw_irq_init(void) {
528
     // Set lift-detection threshold to 3mm (max)
555
     // Set lift-detection threshold to 3mm (max)
529
     pmw_write_register(REG_LIFT_CONFIG, 0x03);
556
     pmw_write_register(REG_LIFT_CONFIG, 0x03);
530
 
557
 
558
+    pmw_set_angle(DEFAULT_MOUSE_ANGLE);
559
+
531
     pmw_irq_init();
560
     pmw_irq_init();
532
 
561
 
533
     return 0;
562
     return 0;

Loading…
Cancel
Save