From 6d2455e7fe71968da7437262691c7d573dc56125 Mon Sep 17 00:00:00 2001 From: demik Date: Wed, 18 Aug 2021 23:13:40 +0200 Subject: [PATCH] Licenses update + basic ADB to Bluetooth --- main/adb.c | 24 +++--- main/adb.h | 19 ++--- main/blue.c | 206 ++++++++++++++++++++++++++++++++++++++++++++++----- main/blue.h | 21 +++--- main/gpio.c | 19 ++--- main/gpio.h | 19 ++--- main/led.c | 19 ++--- main/led.h | 19 ++--- main/m4848.h | 70 +++++++++++++---- main/main.c | 19 ++--- main/quad.c | 19 ++--- main/quad.h | 19 ++--- 12 files changed, 330 insertions(+), 143 deletions(-) diff --git a/main/adb.c b/main/adb.c index 7359745..cf16a60 100644 --- a/main/adb.c +++ b/main/adb.c @@ -6,19 +6,16 @@ * Copyright (c) 2020 Michel DEPEIGE. * * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. + * it under the terms of the Apache License, Version 2.0 (the "License"); + * You may obtain a copy of the License at: * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * http://www.apache.org/licenses/LICENSE-2.0 * - * You should have received a copy of the GNU General Public License - * along with this program (see the file COPYING); if not, write to the - * Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + * 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. * */ @@ -44,6 +41,7 @@ /* globals */ rmt_config_t adb_rmt_rx = RMT_DEFAULT_CONFIG_RX(GPIO_ADB, RMT_RX_CHANNEL); +extern TaskHandle_t t_adb2hid; extern TaskHandle_t t_green, t_blue, t_yellow, t_red; extern TaskHandle_t t_click, t_qx, t_qy; @@ -217,6 +215,10 @@ void adb_task_host(void *pvParameters) { if (data) { last = 0; + /* split data for quad and (maybe) bluetooth */ + if (gpio_get_level(GPIO_BTOFF) == 1 && t_adb2hid != NULL) + xTaskNotify(t_adb2hid, data, eSetValueWithOverwrite); + /* click is active low */ if (! (data & ADB_CMP_B1) || (! (data & ADB_CMP_B2))) adb_handle_button(ADB_B_DOWN); diff --git a/main/adb.h b/main/adb.h index 3bcd34e..450990a 100644 --- a/main/adb.h +++ b/main/adb.h @@ -6,19 +6,16 @@ * Copyright (c) 2020 Michel DEPEIGE. * * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. + * it under the terms of the Apache License, Version 2.0 (the "License"); + * You may obtain a copy of the License at: * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * http://www.apache.org/licenses/LICENSE-2.0 * - * You should have received a copy of the GNU General Public License - * along with this program (see the file COPYING); if not, write to the - * Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + * 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. * */ diff --git a/main/blue.c b/main/blue.c index 1ce3a30..48b1a1b 100644 --- a/main/blue.c +++ b/main/blue.c @@ -1,7 +1,22 @@ -/* This example code is in the Public Domain (or CC0 licensed, at your option.) - Unless required by applicable law or agreed to in writing, this software is - distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - CONDITIONS OF ANY KIND, either express or implied. +/* + * blue.c + * quack + * + * Created by Michel DEPEIGE on 18/07/2021. + * Copyright (c) 2021 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 @@ -24,6 +39,7 @@ #include "esp_bt_main.h" #include "esp_bt_device.h" +#include "esp_hidd.h" #include "esp_hidh.h" #include "esp_hid_gap.h" @@ -37,19 +53,162 @@ static const char *TAG = "blue"; /* globals */ +TaskHandle_t t_adb2hid; extern TaskHandle_t t_click, t_qx, t_qy; +static esp_hidd_dev_t *hid_dev = NULL; /* private functions */ +static void blue_d_init(void); +static void blue_d_start(void); void blue_h_callback(void *handler_args, esp_event_base_t base, int32_t id, void *event_data); +static void blue_h_init(void); +static esp_hid_report_item_t blue_h_ri_find(esp_hidh_dev_t *d, esp_hid_usage_t u, uint8_t t, uint8_t p); static void blue_handle_button(uint8_t buttons); static esp_hid_raw_report_map_t *blue_hid_rm_get(esp_hidh_dev_t *dev); -static esp_hid_report_item_t blue_h_ri_find(esp_hidh_dev_t *d, esp_hid_usage_t u, uint8_t t, uint8_t p); -static void blue_set_boot_protocol(esp_hidh_dev_t *dev); +void blue_set_boot_protocol(esp_hidh_dev_t *dev); static bool blue_support_boot(esp_hidh_dev_t *dev); /* direct calls to bluedroid */ extern void BTA_HhSetProtoMode(uint8_t handle, uint8_t t_type); +/* Device specific functions blue_d_* */ +static void blue_d_callback(void *handler_args, esp_event_base_t base, int32_t id, void *event_data) +{ + esp_hidd_event_t event = (esp_hidd_event_t)id; + esp_hidd_event_data_t *param = (esp_hidd_event_data_t *)event_data; + + switch (event) { + case ESP_HIDD_START_EVENT: { + blue_d_start(); + break; + } + case ESP_HIDD_CONNECT_EVENT: { + ESP_LOGI(TAG, "CONNECT"); + xTaskNotify(t_blue, LED_ON, eSetValueWithOverwrite); + break; + } + case ESP_HIDD_PROTOCOL_MODE_EVENT: { + ESP_LOGI(TAG, "PROTOCOL MODE[%u]: %s", param->protocol_mode.map_index, param->protocol_mode.protocol_mode ? "REPORT" : "BOOT"); + break; + } + case ESP_HIDD_CONTROL_EVENT: { + ESP_LOGI(TAG, "CONTROL[%u]: %sSUSPEND", param->control.map_index, param->control.control ? "EXIT_" : ""); + break; + } + case ESP_HIDD_OUTPUT_EVENT: { + ESP_LOGI(TAG, "OUTPUT[%u]: %8s ID: %2u, Len: %d, Data:", param->output.map_index, esp_hid_usage_str(param->output.usage), param->output.report_id, param->output.length); + ESP_LOG_BUFFER_HEX(TAG, param->output.data, param->output.length); + break; + } + case ESP_HIDD_FEATURE_EVENT: { + ESP_LOGI(TAG, "FEATURE[%u]: %8s ID: %2u, Len: %d, Data:", param->feature.map_index, esp_hid_usage_str(param->feature.usage), param->feature.report_id, param->feature.length); + ESP_LOG_BUFFER_HEX(TAG, param->feature.data, param->feature.length); + break; + } + case ESP_HIDD_DISCONNECT_EVENT: { + ESP_LOGI(TAG, "DISCONNECT: %s", esp_hid_disconnect_reason_str(esp_hidd_dev_transport_get(param->disconnect.dev), param->disconnect.reason)); + esp_hid_ble_gap_adv_start(); + xTaskNotify(t_blue, LED_SLOW, eSetValueWithOverwrite); + break; + } + case ESP_HIDD_STOP_EVENT: { + ESP_LOGI(TAG, "STOP"); + break; + } + default: + break; + } + return; +} + +static void blue_d_init() { + esp_err_t ret; + + ret = esp_hid_ble_gap_adv_init(ESP_HID_APPEARANCE_MOUSE, m4848_config.device_name); + ESP_ERROR_CHECK( ret ); + + if ((ret = esp_ble_gatts_register_callback(esp_hidd_gatts_event_handler)) != ESP_OK) { + ESP_LOGE(TAG, "GATTS register callback failed: %d", ret); + return; + } + + ESP_ERROR_CHECK(esp_hidd_dev_init(&m4848_config, ESP_HID_TRANSPORT_BLE, blue_d_callback, &hid_dev)); + + vTaskDelay(10000 / portTICK_PERIOD_MS); + xTaskCreate(blue_adb2hid, "ADB2BT", 2 * 1024, NULL, tskIDLE_PRIORITY + 1, &t_adb2hid); +} + +/* + * Called when the ESP HIS stack is started + * Start advertising our Bluetooth stuff + */ + +static void blue_d_start() +{ + ESP_LOGD(TAG, "Bluetooth Mouse started"); + xTaskNotify(t_blue, LED_SLOW, eSetValueWithOverwrite); + esp_hid_ble_gap_adv_start(); +} + +/* + * Called by the ADB stack from adb_task_host on mouse activity + * Convert the 16bit ADB data to a 3 bytes HID INPUT REPORT matching the m4848 + */ + +void blue_adb2hid(void *pvParameters) { + uint16_t data = 0; + uint8_t buffer[3] = {0, 0, 0}; + int8_t move = 0; + unsigned int tmp; + + ESP_LOGD(TAG, "ADB2BT started on core %d", xPortGetCoreID()); + + while (true) { + xTaskNotifyWait(0, 0, &tmp, portMAX_DELAY); + data = (uint16_t)tmp; + + /* button pressed */ + if (! (data & ADB_CMP_B1) || (! (data & ADB_CMP_B2))) + buffer[0] = (1<<0); + else + buffer[0] = 0; + + /* + * cast negative signed 7 bits to signed 8 bits + * then apply a slight acceleration (x^1.2) + */ + + move = (data & ADB_CMP_MX) >> 0; + if (move & 0x40) { + move &= ~0x40; + move |= 0x80; + move += 64; + move *= -1; + buffer[1] = m4848_accel[move]; + buffer[1] = buffer[1] * -1; + } + else { + buffer[1] = m4848_accel[move]; + } + + move = (data & ADB_CMP_MY) >> 8; + if (move & 0x40) { + move &= ~0x40; + move |= 0x80; + move += 64; + move *= -1; + buffer[2] = m4848_accel[move]; + buffer[2] = buffer[2] * -1; + } + else { + buffer[2] = m4848_accel[move]; + } + + esp_hidd_dev_input_set(hid_dev, 1, 0, buffer, 3); + } +} + +/* Host specific functions blue_h_* */ void blue_h_callback(void *handler_args, esp_event_base_t base, int32_t id, void *event_data) { esp_hidh_event_t event = (esp_hidh_event_t)id; @@ -71,9 +230,8 @@ void blue_h_callback(void *handler_args, esp_event_base_t base, int32_t id, void } case ESP_HIDH_INPUT_EVENT: { bda = esp_hidh_dev_bda_get(param->input.dev); - //ESP_LOGD(TAG, ESP_BD_ADDR_STR " INPUT: %8s, MAP: %2u, ID: %3u, Len: %d, Data:", ESP_BD_ADDR_HEX(bda), esp_hid_usage_str(param->input.usage), param->input.map_index, param->input.report_id, param->input.length); - //ESP_LOG_BUFFER_HEX(TAG, param->input.data, param->input.length); - xTaskNotify(t_yellow, LED_ONCE, eSetValueWithOverwrite); + ESP_LOG_BUFFER_HEX(TAG, param->input.data, param->input.length); + xTaskNotify(t_yellow, LED_ONCE, eSetValueWithOverwrite); blue_h_input(param->input.dev, param->input.data, param->input.length); break; } @@ -131,6 +289,21 @@ static void blue_handle_button(uint8_t buttons) { } +static void blue_h_init(void) { + esp_hidh_config_t config = { + .callback = blue_h_callback, + .event_stack_size = 4096 + }; + + ESP_ERROR_CHECK(esp_hidh_init(&config)); + + xTaskCreatePinnedToCore(blue_scan, "blue_scan", 6 * 1024, NULL, 2, NULL, 0); +} + +/* + * Bluetooth common init: init module and various stuff + * Host or Device specific inits go in blue_d_init() or blue_h_init() + */ void blue_init(void) { esp_err_t ret; @@ -147,14 +320,7 @@ void blue_init(void) ESP_ERROR_CHECK(esp_hid_gap_init(ESP_BT_MODE_BTDM)); ESP_ERROR_CHECK(esp_ble_gattc_register_callback(esp_hidh_gattc_event_handler)); - esp_hidh_config_t config = { - .callback = blue_h_callback, - .event_stack_size = 4096 - }; - - ESP_ERROR_CHECK(esp_hidh_init(&config)); esp_log_level_set("event", ESP_LOG_INFO); - /* complains about wrong data len on BOOT mode and CCONTROL */ esp_log_level_set("BT_HIDH", ESP_LOG_ERROR); @@ -165,7 +331,11 @@ void blue_init(void) xTaskNotify(t_green, LED_ON, eSetValueWithOverwrite); xTaskNotify(t_blue, LED_FAST, eSetValueWithOverwrite); - xTaskCreatePinnedToCore(blue_scan, "blue_scan", 6 * 1024, NULL, 2, NULL, 0); + + if (adb_is_host()) + blue_d_init(); + else + blue_h_init(); } /* @@ -351,7 +521,7 @@ void blue_scan(void *pvParameters) { vTaskDelete(NULL); } -static void blue_set_boot_protocol(esp_hidh_dev_t *dev) { +void blue_set_boot_protocol(esp_hidh_dev_t *dev) { configASSERT(dev != NULL); /* diff --git a/main/blue.h b/main/blue.h index 33d0d79..1ac7975 100644 --- a/main/blue.h +++ b/main/blue.h @@ -6,19 +6,16 @@ * Copyright (c) 2020 Michel DEPEIGE. * * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. + * it under the terms of the Apache License, Version 2.0 (the "License"); + * You may obtain a copy of the License at: * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * http://www.apache.org/licenses/LICENSE-2.0 * - * You should have received a copy of the GNU General Public License - * along with this program (see the file COPYING); if not, write to the - * Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + * 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. * */ @@ -37,11 +34,13 @@ #define BLUE_BUTTON_E 0xF8 /* shouldn't happen */ /* prototypes */ +void blue_adb2hid(void *pvParameters); void blue_init(void); void blue_h_input(esp_hidh_dev_t *dev, uint8_t *data, uint16_t length); void blue_h_close(esp_hidh_event_data_t *p); void blue_h_open(esp_hidh_event_data_t *p); void blue_scan(void *pvParameters); +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; diff --git a/main/gpio.c b/main/gpio.c index a3c50d6..c5110f7 100644 --- a/main/gpio.c +++ b/main/gpio.c @@ -6,19 +6,16 @@ * Copyright (c) 2020 Michel DEPEIGE. * * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. + * it under the terms of the Apache License, Version 2.0 (the "License"); + * You may obtain a copy of the License at: * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * http://www.apache.org/licenses/LICENSE-2.0 * - * You should have received a copy of the GNU General Public License - * along with this program (see the file COPYING); if not, write to the - * Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + * 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. * */ diff --git a/main/gpio.h b/main/gpio.h index 27e4ae8..b16cc44 100644 --- a/main/gpio.h +++ b/main/gpio.h @@ -6,19 +6,16 @@ * Copyright (c) 2020 Michel DEPEIGE. * * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. + * it under the terms of the Apache License, Version 2.0 (the "License"); + * You may obtain a copy of the License at: * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * http://www.apache.org/licenses/LICENSE-2.0 * - * You should have received a copy of the GNU General Public License - * along with this program (see the file COPYING); if not, write to the - * Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + * 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. * */ diff --git a/main/led.c b/main/led.c index 61a3186..e835b88 100644 --- a/main/led.c +++ b/main/led.c @@ -6,19 +6,16 @@ * Copyright (c) 2020 Michel DEPEIGE. * * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. + * it under the terms of the Apache License, Version 2.0 (the "License"); + * You may obtain a copy of the License at: * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * http://www.apache.org/licenses/LICENSE-2.0 * - * You should have received a copy of the GNU General Public License - * along with this program (see the file COPYING); if not, write to the - * Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + * 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. * */ diff --git a/main/led.h b/main/led.h index e21cac7..ec55cb8 100644 --- a/main/led.h +++ b/main/led.h @@ -6,19 +6,16 @@ * Copyright (c) 2020 Michel DEPEIGE. * * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. + * it under the terms of the Apache License, Version 2.0 (the "License"); + * You may obtain a copy of the License at: * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * http://www.apache.org/licenses/LICENSE-2.0 * - * You should have received a copy of the GNU General Public License - * along with this program (see the file COPYING); if not, write to the - * Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + * 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. * */ diff --git a/main/m4848.h b/main/m4848.h index 4136c6e..740e6b9 100644 --- a/main/m4848.h +++ b/main/m4848.h @@ -2,32 +2,56 @@ * m4848.h * quack * - * Created by Michel DEPEIGE on 18/05/2021. + * Created by Michel DEPEIGE on 18/07/2021. * Copyright (c) 2021 Michel DEPEIGE. * * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. + * it under the terms of the Apache License, Version 2.0 (the "License"); + * You may obtain a copy of the License at: * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * http://www.apache.org/licenses/LICENSE-2.0 * - * You should have received a copy of the GNU General Public License - * along with this program (see the file COPYING); if not, write to the - * Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + * 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. * */ #ifndef M4848_H #define M4848_H +/* + * Dunno what this is for... The ESP-IDF stack freeze without it. + * See similar issue at: https://www.esp32.com/viewtopic.php?t=22661&p=81652 + */ + +const unsigned char m4848_APIRM[] = { + 0x06, 0x00, 0xFF, // Usage Page (Vendor Defined 0xFF00) + 0x0A, 0x00, 0x01, // Usage (0x0100) + 0xA1, 0x01, // Collection (Application) + 0x85, 0x01, // Report ID (1) + 0x15, 0x00, // Logical Minimum (0) + 0x26, 0xFF, 0x00, // Logical Maximum (255) + 0x75, 0x08, // Report Size (8) + 0x95, 0x08, // Report Count (8) + 0x09, 0x01, // Usage (0x01) + 0x82, 0x02, 0x01, // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Buffered Bytes) + 0x95, 0x08, // Report Count (8) + 0x09, 0x02, // Usage (0x02) + 0xB2, 0x02, 0x01, // Feature (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile,Buffered Bytes) + 0x95, 0x08, // Report Count (8) + 0x09, 0x03, // Usage (0x03) + 0x91, 0x02, // Output (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile) + 0xC0, // End Collection + + // 38 bytes +}; + /* * This is dumped from an Apple USB "Hockey Puck" Mouse - * + * https://en.wikipedia.org/wiki/Apple_USB_Mouse * We will use this HID Report Descriptor as it's the closer to an ADB Mouse */ @@ -63,6 +87,10 @@ const unsigned char m4848_HIDDD[] = { }; static esp_hid_raw_report_map_t m4848_report_maps[] = { + { + .data = m4848_APIRM, + .len = sizeof(m4848_APIRM) + }, { .data = m4848_HIDDD, .len = sizeof(m4848_HIDDD) @@ -73,11 +101,23 @@ static esp_hid_device_config_t m4848_config = { .vendor_id = 0x05ac, // Apple, Inc. .product_id = 0x0301, // USB Mouse [Mitsumi, M4848] .version = 0x0104, - .device_name = "Quack Mouse Adapter", + .device_name = "Quack ADB Mouse", .manufacturer_name = "68kmla", .serial_number = "0", .report_maps = m4848_report_maps, - .report_maps_len = 1 + .report_maps_len = 2 +}; + +/* precalculed table for 0-64 values to 0-127 with a slight acceleration of x^1.2 */ +const unsigned char m4848_accel[] = { + 0x00, 0x01, 0x02, 0x03, 0x05, 0x06, 0x08, 0x0A, + 0x0C, 0x0D, 0x0F, 0x11, 0x13, 0x15, 0x17, 0x19, + 0x1B, 0x1D, 0x20, 0x22, 0x24, 0x26, 0x28, 0x2B, + 0x2D, 0x2F, 0x31, 0x34, 0x36, 0x38, 0x3B, 0x3D, + 0x3F, 0x42, 0x44, 0x47, 0x49, 0x4C, 0x4E, 0x51, + 0x53, 0x56, 0x58, 0x5B, 0x5D, 0x60, 0x62, 0x65, + 0x68, 0x6A, 0x6D, 0x6F, 0x72, 0x75, 0x77, 0x7A, + 0x7D, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F }; #endif diff --git a/main/main.c b/main/main.c index 5b186b6..74e8e0c 100644 --- a/main/main.c +++ b/main/main.c @@ -6,19 +6,16 @@ * Copyright (c) 2020 Michel DEPEIGE. * * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. + * it under the terms of the Apache License, Version 2.0 (the "License"); + * You may obtain a copy of the License at: * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * http://www.apache.org/licenses/LICENSE-2.0 * - * You should have received a copy of the GNU General Public License - * along with this program (see the file COPYING); if not, write to the - * Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + * 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. * */ diff --git a/main/quad.c b/main/quad.c index fd484ae..afe560b 100644 --- a/main/quad.c +++ b/main/quad.c @@ -6,19 +6,16 @@ * Copyright (c) 2021 Michel DEPEIGE. * * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. + * it under the terms of the Apache License, Version 2.0 (the "License"); + * You may obtain a copy of the License at: * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * http://www.apache.org/licenses/LICENSE-2.0 * - * You should have received a copy of the GNU General Public License - * along with this program (see the file COPYING); if not, write to the - * Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + * 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. * */ diff --git a/main/quad.h b/main/quad.h index 0c7166a..d7cd188 100644 --- a/main/quad.h +++ b/main/quad.h @@ -6,19 +6,16 @@ * Copyright (c) 2021 Michel DEPEIGE. * * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. + * it under the terms of the Apache License, Version 2.0 (the "License"); + * You may obtain a copy of the License at: * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * http://www.apache.org/licenses/LICENSE-2.0 * - * You should have received a copy of the GNU General Public License - * along with this program (see the file COPYING); if not, write to the - * Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + * 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. * */