Skip to content

Commit c69cc3f

Browse files
committed
added Mighty Mouse driver
1 parent fc213f3 commit c69cc3f

File tree

6 files changed

+147
-7
lines changed

6 files changed

+147
-7
lines changed

main/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ set(srcs "adb.c"
44
"gpio.c"
55
"led.c"
66
"main.c"
7+
"mighty.c"
78
"quad.c"
89
"wii.c")
910

main/blue.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
#include "gpio.h"
5555
#include "led.h"
5656
#include "m4848.h"
57+
#include "mighty.h"
5758
#include "wii.h"
5859

5960
/* debug tag */
@@ -427,6 +428,10 @@ void blue_h_input(esp_hidh_dev_t *dev, uint16_t id, uint8_t *data, uint16_t leng
427428
uint16_t vid = esp_hidh_dev_vendor_id_get(dev);
428429
uint16_t pid = esp_hidh_dev_product_id_get(dev);
429430

431+
if (mighty_is_mm(vid, pid)) {
432+
mighty_input(dev, id, data, length);
433+
return;
434+
}
430435
if (wii_is_wiimote(vid, pid)) {
431436
wii_input(dev, id, data, length);
432437
return;

main/blue.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
*
2020
*/
2121

22-
#ifndef BLUE_H
23-
#define BLUE_H
22+
#pragma once
2423

2524
/* defines */
2625
#define BLUE_SCAN_DURATION 6
@@ -47,5 +46,3 @@ void blue_set_boot_protocol(esp_hidh_dev_t *dev);
4746
/* global variables for tasks handles */
4847
extern TaskHandle_t t_green, t_blue, t_yellow, t_red;
4948

50-
#endif
51-

main/mighty.c

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/*
2+
* mighty.c
3+
* mighty
4+
*
5+
* Created by Michel DEPEIGE on 03/03/2025.
6+
* Copyright (c) 2025 Michel DEPEIGE.
7+
*
8+
* This program is free software; you can redistribute it and/or modify
9+
* it under the terms of the Apache License, Version 2.0 (the "License");
10+
* You may obtain a copy of the License at:
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*
20+
*/
21+
22+
#include <stdio.h>
23+
#include <string.h>
24+
#include "driver/gpio.h"
25+
#include "sdkconfig.h"
26+
#include "freertos/FreeRTOS.h"
27+
#include "freertos/queue.h"
28+
#include "freertos/semphr.h"
29+
#include "freertos/task.h"
30+
#include "esp_log.h"
31+
#include "esp_system.h"
32+
#include "esp_chip_info.h"
33+
#if !CONFIG_BT_NIMBLE_ENABLED
34+
#include "esp_bt_defs.h"
35+
#include "esp_bt_main.h"
36+
#include "esp_bt_device.h"
37+
#include "esp_gap_bt_api.h"
38+
#endif
39+
#include "esp_hid_common.h"
40+
#include "esp_hidh.h"
41+
#include "esp_hidh_api.h"
42+
43+
#include "blue.h"
44+
#include "led.h"
45+
#include "mighty.h"
46+
47+
/* functions */
48+
49+
/*
50+
* this function will decode a mighty frame and convert it for quadrature tasks
51+
*
52+
* Byte | Bits | Description
53+
* -----+------+---------------------------------------------------------------
54+
* 0 | 0 | Button 1 (left)
55+
* 0 | 1 | Button 2 (right)
56+
* 0 | 2 | Button 3 (middle)
57+
* 0 | 3-7 | unused
58+
* 1 | 0-7 | X Displacement
59+
* 2 | 0-7 | Y Displacement
60+
* 3 | 0-7 | Ball X Axis
61+
* 4 | 0-7 | Ball Y Axis
62+
* 5 | 0-7 | pressure sensor. Follow roughly (0)
63+
*
64+
* Original HID dump
65+
* +-------------------------------------------------+
66+
* | 05 01 09 02 a1 01 85 02 05 09 19 01 29 04 15 00 |
67+
* | 09 01 a1 00 15 81 25 7f 09 30 09 31 75 08 95 02 |
68+
* | 81 06 05 0c 0a 38 02 75 08 95 01 81 06 05 01 09 |
69+
* | 38 75 08 95 01 81 06 c0 05 ff 09 c0 75 08 95 01 |
70+
* | 81 02 05 06 09 20 85 47 15 00 25 64 75 08 95 01 |
71+
* | b1 a2 c0 |
72+
* +-------------------------------------------------+
73+
*/
74+
75+
void mighty_input(esp_hidh_dev_t *dev, uint16_t id, uint8_t *data, uint16_t length) {
76+
/*
77+
* Mighty Mouse reports are exactly 6 bytes. Check for size in case of random error
78+
* The button checks and handling follow the boot protocol
79+
*
80+
* Since the first 3 bytes are the same as boot, let's handle some errors here
81+
* and call the boot decoder with a truncated report (ignore pressure and ball)
82+
*/
83+
84+
if (length != 6) {
85+
xTaskNotify(t_red, LED_ONCE, eSetValueWithOverwrite);
86+
return;
87+
}
88+
if (data[3] || data[4]) {
89+
xTaskNotify(t_red, LED_ONCE, eSetValueWithOverwrite);
90+
}
91+
92+
blue_h_boot(data, 3);
93+
}
94+
95+
/*
96+
* this will tell us if the device is a supported Mighty Mouse
97+
* PID + VID provided by the HID stack
98+
*/
99+
bool mighty_is_mm(uint16_t vid, uint16_t pid) {
100+
if (vid != MIGHTY_VID)
101+
return false;
102+
if (pid != MIGHTY_PID)
103+
return false;
104+
105+
return true;
106+
}

main/mighty.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* wii.h
3+
* quack
4+
*
5+
* Created by Michel DEPEIGE on 03/03/2025.
6+
* Copyright (c) 2025 Michel DEPEIGE.
7+
*
8+
* This program is free software; you can redistribute it and/or modify
9+
* it under the terms of the Apache License, Version 2.0 (the "License");
10+
* You may obtain a copy of the License at:
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*
20+
*/
21+
22+
#pragma once
23+
24+
/* prototypes */
25+
void mighty_input(esp_hidh_dev_t *dev, uint16_t id, uint8_t *data, uint16_t length);
26+
bool mighty_is_mm(uint16_t vid, uint16_t pid);
27+
28+
/* defines */
29+
#define MIGHTY_VID 0x05ac
30+
#define MIGHTY_PID 0x030c
31+
32+
/* handled reports */
33+
#define MIGHTY_REPORT_INPUT 0x02

main/wii.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
*
2020
*/
2121

22-
#ifndef WII_H
23-
#define WII_H
22+
#pragma once
2423

2524
/* prototypes */
2625
uint8_t *wii_generate_pin(esp_bt_pin_code_t pin);
@@ -95,4 +94,3 @@ typedef struct wii_accel_s {
9594
uint16_t z;
9695
} wii_accel_t;
9796

98-
#endif

0 commit comments

Comments
 (0)