From 7e728263817d0bc1495f352211c87fde27472527 Mon Sep 17 00:00:00 2001 From: Ricardo Quesada Date: Sun, 10 Dec 2023 21:12:11 -0800 Subject: [PATCH] CLion fixes --- README.md | 15 ++++++---- examples/esp32/CMakeLists.txt | 2 +- src/CMakeLists.txt | 2 +- src/components/bluepad32/uni_hid_device.c | 12 ++++---- .../bluepad32/uni_mouse_quadrature.c | 28 +++++++++---------- 5 files changed, 31 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index e108eb81..ec0b9480 100644 --- a/README.md +++ b/README.md @@ -13,18 +13,17 @@ Add Bluetooth gamepad, mouse and keyboard support to your projects easily. Choose your target platform: | Platform | Start here | Further info | Community projects | -| ----------------------------------- | ----------------------------------------------------------------- | ------------------------ | --------------------------------------------------------------------------------------------------------- | +|-------------------------------------|-------------------------------------------------------------------|--------------------------|-----------------------------------------------------------------------------------------------------------| | Arduino IDE | [![Watch the video][youtube_image]](https://youtu.be/0jnY-XXiD8Q) | [Doc][plat_arduino] | [Controller for Tello drone][tello] | | Arduino using ESP-IDF toolchain | [Template project][esp-idf-bluepad32-arduino] | [Doc][plat_arduino] | [Lego Robot][esp32_example] ([video][esp32_video]), [gbaHD Shield][esp32_example2] (a GameBoy consolizer) | | Arduino + NINA coprocessor | [Arduino Library][bp32-arduino] | [Doc][plat_nina] | [Philips CD-i meets Bluetooth][nina_example] | | CircuitPython + AirLift coprocessor | [CircuitPython Library][bp32-circuitpython] | [Doc][plat_airlift] | [Quico console][airlift_example], Controlling 4 servos ([video][airlift_video]) | -| Pico W | [Pico W example][pico-w-example] | [Doc][plat_custom] | | -| ESP-IDF | [ESP32 example][esp32-example] | [Doc][plat_custom] | | -| Linux | [Linux example][linux-example] | [Doc][plat_custom] | | +| Pico W | [Pico W example][pico-w-example] | [Doc][plat_custom] | | +| ESP-IDF | [ESP32 example][esp32-example] | [Doc][plat_custom] | | +| Linux | [Linux example][linux-example] | [Doc][plat_custom] | | | Unijoysticle | [Unijoysticle2][unijoysticle2] | [Doc][plat_unijoysticle] | | | MightyMiggy | [Unijoysticle for Amiga][unijoysticle_sukko] | [Doc][plat_mightymiggy] | | - [airlift_example]: https://gitlab.com/ricardoquesada/quico [airlift_video]: https://twitter.com/makermelissa/status/1482596378282913793 [bp32-arduino]: https://gitlab.com/ricardoquesada/bluepad32-arduino @@ -48,6 +47,8 @@ Choose your target platform: ## Features * Supports most, if not all, modern Bluetooth gamepads, mice and keyboards (see below) +* Supports ESP32 and Pico W +* Supported APIs: ESP-IDF, Pico-SDK, Arduino and CircuitPython * Fast (very low latency) * Small footprint * Uses only one core (CPU0). The remaining one is free to use. @@ -78,7 +79,8 @@ Choose your target platform: * Keyboards * And more -NOTE: Original **ESP32** and **Pico W** support all listed controllers. **ESP32-S3** and **ESP32-C3** support only a subset. +NOTE: Original **ESP32** and **Pico W** support all listed controllers. **ESP32-S3** and **ESP32-C3** support only a +subset. See: [Supported gamepads][gamepads], [supported mice][mice] and [supported keyboards][keyboards] @@ -101,6 +103,7 @@ See the examples folder which includes examples for: * [Bluepad32 for Linux][linux-example] Arduino examples are in: + * [Bluepad32 for Arduino IDE][arduino-ide-example] * [Bluepad32 for Arduino + ESP-IDF][arduino-esp-idf-example] diff --git a/examples/esp32/CMakeLists.txt b/examples/esp32/CMakeLists.txt index a22aa264..988399ce 100644 --- a/examples/esp32/CMakeLists.txt +++ b/examples/esp32/CMakeLists.txt @@ -4,4 +4,4 @@ cmake_minimum_required(VERSION 3.5) set(EXTRA_COMPONENT_DIRS ../../src/components) include($ENV{IDF_PATH}/tools/cmake/project.cmake) -project(bluepad32-example-esp32-app) +project(bluepad32_esp32_example_app) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index bc0d988b..06289c95 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -3,4 +3,4 @@ cmake_minimum_required(VERSION 3.5) include($ENV{IDF_PATH}/tools/cmake/project.cmake) -project(bluepad32-app) +project(bluepad32_app) diff --git a/src/components/bluepad32/uni_hid_device.c b/src/components/bluepad32/uni_hid_device.c index 13a6a74e..122cd9a5 100644 --- a/src/components/bluepad32/uni_hid_device.c +++ b/src/components/bluepad32/uni_hid_device.c @@ -118,7 +118,7 @@ uni_hid_device_t* uni_hid_device_create_virtual(uni_hid_device_t* parent) { g_devices[i].controller_type = parent->controller_type; g_devices[i].controller_subtype = parent->controller_subtype; - // All virtual devices has a "controller type", which is known by the parent. + // All virtual devices have a "controller type", which is known by the parent. g_devices[i].flags |= FLAGS_HAS_CONTROLLER_TYPE; snprintf(g_devices[i].name, sizeof(g_devices[i].name), "virtual-%d", i); @@ -548,7 +548,7 @@ bool uni_hid_device_guess_controller_type_from_name(uni_hid_device_t* d, const c // Try with the different matchers. // But don't include Xbox here yet, since we should try to get the HID descriptor first. - // This is because there Xbox Wireless has 3 different types of HID descriptors. + // This is because the Xbox Wireless has 3 different types of HID descriptors. bool ret = uni_hid_parser_ds3_does_name_match(d, name); ret = ret || uni_hid_parser_switch_does_name_match(d, name); @@ -796,7 +796,7 @@ void uni_hid_device_send_report(uni_hid_device_t* d, uint16_t cid, const uint8_t l2cap_request_can_send_now_event(cid); } -// Sends an interrupt-report. If it can't it will queue it and try again later. +// Sends an interrupt-report. If it can't, it will queue it and try again later. void uni_hid_device_send_intr_report(uni_hid_device_t* d, const uint8_t* report, uint16_t len) { if (d == NULL) { loge("Invalid device\n"); @@ -844,7 +844,7 @@ bool uni_hid_device_does_require_hid_descriptor(uni_hid_device_t* d) { } // If the parser has a "parse_usage" functions, it is safe to assume that a HID descriptor - // is needed. "parse_usage" cannot work without a HID descriptor. + // is needed. "Parse_usage" cannot work without a HID descriptor. return (d->report_parser.parse_usage != NULL); } @@ -892,7 +892,7 @@ static void misc_button_enable_callback(btstack_timer_source_t* ts) { // process_mic_button_system static void process_misc_button_system(uni_hid_device_t* d) { if ((d->controller.gamepad.misc_buttons & MISC_BUTTON_SYSTEM) == 0) { - // System button released ? + // System button released? d->misc_button_wait_release &= ~MISC_BUTTON_SYSTEM; return; } @@ -927,7 +927,7 @@ static void process_misc_button_system(uni_hid_device_t* d) { // process_misc_button_home dumps uni_hid_device debug info in the console. static void process_misc_button_home(uni_hid_device_t* d) { if ((d->controller.gamepad.misc_buttons & MISC_BUTTON_START) == 0) { - // Home button released ? Clear "wait" flag. + // Home button released? Clear "wait" flag. d->misc_button_wait_release &= ~MISC_BUTTON_START; return; } diff --git a/src/components/bluepad32/uni_mouse_quadrature.c b/src/components/bluepad32/uni_mouse_quadrature.c index 8dc7fc89..55b453e6 100644 --- a/src/components/bluepad32/uni_mouse_quadrature.c +++ b/src/components/bluepad32/uni_mouse_quadrature.c @@ -24,8 +24,8 @@ limitations under the License. #include #include -#include #include +#include #include #include @@ -36,7 +36,7 @@ limitations under the License. #include "uni_property.h" // Probably I could use a smaller divider, and only do "1 tick per 80us". -// That would work Ok except that it will loose resolution when we divide "128 steps by delta". +// That would work Ok except that it will lose resolution when we divide "128 steps by delta". // APB clock runs at 80Mhz. // Option A: // 80Mhz / 80 = 1Mhz = tick every 1us @@ -140,8 +140,8 @@ static void process_quadrature(struct quadrature_state* q) { logd("value: %d, quadrature phase: %d, a=%d, b=%d (%d,%d)\n", q->value, q->phase, a, b, gpio_a, gpio_b); } -// Don't be confused that is is just one task. -// Actually this callback is called from 4 different tasks. +// Don't be confused, that is just one task. +// Actually, this callback is called from 4 different tasks. static void timer_task(void* arg) { uint32_t a = (uint32_t)arg; uint16_t port_idx = (a >> 16); @@ -213,8 +213,8 @@ static void process_update(struct quadrature_state* q, int32_t delta) { q->value = abs_delta; q->dir = (delta < 0) ? PHASE_DIRECTION_NEG : PHASE_DIRECTION_POS; - // SmallyMouse2 mentions that 100-120 reports are recevied per second. - // According to my test they are ~90, which is in the same order. + // SmallyMouse2 mentions that 100-120 reports are received per second. + // According to my test, they are ~90, which is in the same order. // For simplicity, I'll use 100. It means that, at most, reports are received // every 10ms (1 second / 100 reports = 10ms per report). // @@ -224,7 +224,7 @@ static void process_update(struct quadrature_state* q, int32_t delta) { // So the ESP32 timer is configured as: // - down timer // - ticks every 1us - // - when it reaches 0, triggers the ISR + // - when it reaches 0, triggers the ISR. // // But a quadrature has 4 states (hence the name). So takes 4 "ticks" to have // complete "state.", which is represented with "s_scale_factor", @@ -232,15 +232,15 @@ static void process_update(struct quadrature_state* q, int32_t delta) { // // The smaller "units" is, the faster the mouse moves. // - // But in order to avoid a "division" in the mouse driver, and a multiplication here, - // (which will loose precision), we just use a "s_scale_factor" of 1 instead of 4, + // But to avoid a "division" in the mouse driver, and a multiplication here, + // (which will lose precision), we just use a "s_scale_factor" of 1 instead of 4, // and we don't divide by 4 here. // Alternative: Do not divide the time, and use a constant "tick" time. But if we do so, // the movement will have "jank". // Perhaps for small deltas we can have a predefined "unit time". // // s_scale_factor is used as a divisor to honor the "scale" name: - // smaller numers make it slower, high number faster + // smaller numbers make it slower, high number faster float max_ticks = 128 * TICKS_PER_80US; float delta_f = abs_delta; float units_f = max_ticks / (delta_f * s_scale_factor); @@ -265,7 +265,7 @@ void uni_mouse_quadrature_init(int cpu_id) { } } - // Default value that can be overriden from the console + // Default value that can be overridden from the console s_scale_factor = uni_mouse_quadrature_get_scale_factor(); // Create tasks @@ -351,8 +351,8 @@ void uni_mouse_quadrature_update(int port_idx, int32_t dx, int32_t dy) { return; } process_update(&s_quadratures[port_idx][UNI_MOUSE_QUADRATURE_ENCODER_H], dx); - // Invert delta Y so that mouse goes the the right direction. - // This is based on emperic evidence. Also, it seems that SmallyMouse is doing the same thing + // Invert delta Y so that mouse goes the right direction. + // This is based on empiric evidence. Also, it seems that SmallyMouse is doing the same thing process_update(&s_quadratures[port_idx][UNI_MOUSE_QUADRATURE_ENCODER_V], -dy); } @@ -368,7 +368,7 @@ float uni_mouse_quadrature_get_scale_factor(void) { uni_property_value_t value; uni_property_value_t def; - def.f32 = 1.0; + def.f32 = 1.0f; value = uni_property_get(UNI_PROPERTY_KEY_MOUSE_SCALE, UNI_PROPERTY_TYPE_FLOAT, def); s_scale_factor = value.f32;