mirror of
https://github.com/demik/quack.git
synced 2025-04-10 02:39:31 +00:00
added Mighty Mouse driver
This commit is contained in:
parent
fc213f398f
commit
c69cc3fc89
@ -4,6 +4,7 @@ set(srcs "adb.c"
|
||||
"gpio.c"
|
||||
"led.c"
|
||||
"main.c"
|
||||
"mighty.c"
|
||||
"quad.c"
|
||||
"wii.c")
|
||||
|
||||
|
@ -54,6 +54,7 @@
|
||||
#include "gpio.h"
|
||||
#include "led.h"
|
||||
#include "m4848.h"
|
||||
#include "mighty.h"
|
||||
#include "wii.h"
|
||||
|
||||
/* debug tag */
|
||||
@ -427,6 +428,10 @@ void blue_h_input(esp_hidh_dev_t *dev, uint16_t id, uint8_t *data, uint16_t leng
|
||||
uint16_t vid = esp_hidh_dev_vendor_id_get(dev);
|
||||
uint16_t pid = esp_hidh_dev_product_id_get(dev);
|
||||
|
||||
if (mighty_is_mm(vid, pid)) {
|
||||
mighty_input(dev, id, data, length);
|
||||
return;
|
||||
}
|
||||
if (wii_is_wiimote(vid, pid)) {
|
||||
wii_input(dev, id, data, length);
|
||||
return;
|
||||
|
@ -19,8 +19,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef BLUE_H
|
||||
#define BLUE_H
|
||||
#pragma once
|
||||
|
||||
/* defines */
|
||||
#define BLUE_SCAN_DURATION 6
|
||||
@ -47,5 +46,3 @@ void blue_set_boot_protocol(esp_hidh_dev_t *dev);
|
||||
/* global variables for tasks handles */
|
||||
extern TaskHandle_t t_green, t_blue, t_yellow, t_red;
|
||||
|
||||
#endif
|
||||
|
||||
|
106
main/mighty.c
Normal file
106
main/mighty.c
Normal file
@ -0,0 +1,106 @@
|
||||
/*
|
||||
* mighty.c
|
||||
* mighty
|
||||
*
|
||||
* Created by Michel DEPEIGE on 03/03/2025.
|
||||
* Copyright (c) 2025 Michel DEPEIGE.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the Apache License, Version 2.0 (the "License");
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "driver/gpio.h"
|
||||
#include "sdkconfig.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/queue.h"
|
||||
#include "freertos/semphr.h"
|
||||
#include "freertos/task.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_system.h"
|
||||
#include "esp_chip_info.h"
|
||||
#if !CONFIG_BT_NIMBLE_ENABLED
|
||||
#include "esp_bt_defs.h"
|
||||
#include "esp_bt_main.h"
|
||||
#include "esp_bt_device.h"
|
||||
#include "esp_gap_bt_api.h"
|
||||
#endif
|
||||
#include "esp_hid_common.h"
|
||||
#include "esp_hidh.h"
|
||||
#include "esp_hidh_api.h"
|
||||
|
||||
#include "blue.h"
|
||||
#include "led.h"
|
||||
#include "mighty.h"
|
||||
|
||||
/* functions */
|
||||
|
||||
/*
|
||||
* this function will decode a mighty frame and convert it for quadrature tasks
|
||||
*
|
||||
* Byte | Bits | Description
|
||||
* -----+------+---------------------------------------------------------------
|
||||
* 0 | 0 | Button 1 (left)
|
||||
* 0 | 1 | Button 2 (right)
|
||||
* 0 | 2 | Button 3 (middle)
|
||||
* 0 | 3-7 | unused
|
||||
* 1 | 0-7 | X Displacement
|
||||
* 2 | 0-7 | Y Displacement
|
||||
* 3 | 0-7 | Ball X Axis
|
||||
* 4 | 0-7 | Ball Y Axis
|
||||
* 5 | 0-7 | pressure sensor. Follow roughly (0)
|
||||
*
|
||||
* Original HID dump
|
||||
* +-------------------------------------------------+
|
||||
* | 05 01 09 02 a1 01 85 02 05 09 19 01 29 04 15 00 |
|
||||
* | 09 01 a1 00 15 81 25 7f 09 30 09 31 75 08 95 02 |
|
||||
* | 81 06 05 0c 0a 38 02 75 08 95 01 81 06 05 01 09 |
|
||||
* | 38 75 08 95 01 81 06 c0 05 ff 09 c0 75 08 95 01 |
|
||||
* | 81 02 05 06 09 20 85 47 15 00 25 64 75 08 95 01 |
|
||||
* | b1 a2 c0 |
|
||||
* +-------------------------------------------------+
|
||||
*/
|
||||
|
||||
void mighty_input(esp_hidh_dev_t *dev, uint16_t id, uint8_t *data, uint16_t length) {
|
||||
/*
|
||||
* Mighty Mouse reports are exactly 6 bytes. Check for size in case of random error
|
||||
* The button checks and handling follow the boot protocol
|
||||
*
|
||||
* Since the first 3 bytes are the same as boot, let's handle some errors here
|
||||
* and call the boot decoder with a truncated report (ignore pressure and ball)
|
||||
*/
|
||||
|
||||
if (length != 6) {
|
||||
xTaskNotify(t_red, LED_ONCE, eSetValueWithOverwrite);
|
||||
return;
|
||||
}
|
||||
if (data[3] || data[4]) {
|
||||
xTaskNotify(t_red, LED_ONCE, eSetValueWithOverwrite);
|
||||
}
|
||||
|
||||
blue_h_boot(data, 3);
|
||||
}
|
||||
|
||||
/*
|
||||
* this will tell us if the device is a supported Mighty Mouse
|
||||
* PID + VID provided by the HID stack
|
||||
*/
|
||||
bool mighty_is_mm(uint16_t vid, uint16_t pid) {
|
||||
if (vid != MIGHTY_VID)
|
||||
return false;
|
||||
if (pid != MIGHTY_PID)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
33
main/mighty.h
Normal file
33
main/mighty.h
Normal file
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* wii.h
|
||||
* quack
|
||||
*
|
||||
* Created by Michel DEPEIGE on 03/03/2025.
|
||||
* Copyright (c) 2025 Michel DEPEIGE.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the Apache License, Version 2.0 (the "License");
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
/* prototypes */
|
||||
void mighty_input(esp_hidh_dev_t *dev, uint16_t id, uint8_t *data, uint16_t length);
|
||||
bool mighty_is_mm(uint16_t vid, uint16_t pid);
|
||||
|
||||
/* defines */
|
||||
#define MIGHTY_VID 0x05ac
|
||||
#define MIGHTY_PID 0x030c
|
||||
|
||||
/* handled reports */
|
||||
#define MIGHTY_REPORT_INPUT 0x02
|
@ -19,8 +19,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef WII_H
|
||||
#define WII_H
|
||||
#pragma once
|
||||
|
||||
/* prototypes */
|
||||
uint8_t *wii_generate_pin(esp_bt_pin_code_t pin);
|
||||
@ -95,4 +94,3 @@ typedef struct wii_accel_s {
|
||||
uint16_t z;
|
||||
} wii_accel_t;
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user