Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kornev/add c flags and fix FW issues #148

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# SPDX-License-Identifier: GPL-2.0-only
# Copyright (C) 2022, Input Labs Oy.
# Copyright (C) 2022-2024, Input Labs Oy.

cmake_minimum_required(VERSION 3.16)

Expand All @@ -21,6 +21,8 @@ add_executable(${PROJECT}
src/main.c
)

target_compile_options(${PROJECT} PRIVATE -Wall -Werror)

target_link_libraries(${PROJECT}
pico_stdlib
pico_multicore
Expand Down
4 changes: 3 additions & 1 deletion src/bus.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-2.0-only
// Copyright (C) 2022, Input Labs Oy.
// Copyright (C) 2022-2024, Input Labs Oy.

#include <stdio.h>
#include <stdlib.h>
Expand Down Expand Up @@ -50,6 +50,8 @@ Tristate bus_i2c_io_tristate(uint8_t index) {
if ( up != down) return TRIESTATE_FLOAT;
if (!up && !down) return TRIESTATE_DOWN;
if ( up && down) return TRIESTATE_UP;
// default TRIESTATE_UP??
return TRIESTATE_UP;
}

void bus_i2c_io_pcb_gen_determine() {
Expand Down
4 changes: 3 additions & 1 deletion src/button.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-2.0-only
// Copyright (C) 2022, Input Labs Oy.
// Copyright (C) 2022-2024, Input Labs Oy.

#include <stdio.h>
#include <string.h>
Expand Down Expand Up @@ -36,6 +36,8 @@ bool Button__is_pressed(Button *self) {
else if (is_between(self->pin, PIN_GROUP_IO_1, PIN_GROUP_IO_1_END)) {
return bus_i2c_io_cache_read(1, self->pin - PIN_GROUP_IO_1);
}
// default false??
return false;
}

void Button__report(Button *self) {
Expand Down
14 changes: 7 additions & 7 deletions src/glyph.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-2.0-only
// Copyright (C) 2022, Input Labs Oy.
// Copyright (C) 2022-2024, Input Labs Oy.

/*
In the alphanumeric input (keyboard emulation) implemented in the thumbstick,
Expand All @@ -26,15 +26,15 @@ uint8_t glyph_encode(Glyph glyph) {
// represent the 4 directions, and thus skipping DIR4_NONE.
encoded += glyph[0] - 1;
// Termination bit.
encoded += 1 << 1+len;
encoded += 1 << (1 + len);
// Remaining directions.
for(uint8_t i=1; i<len; i++) {
// Each subsequent direction is either clockwise or anticlockwise, so
// it is encoded in a single bit.
if (glyph[i-1] == DIR4_UP && glyph[i] == DIR4_RIGHT) encoded += (1 << 1+i);
if (glyph[i-1] == DIR4_RIGHT && glyph[i] == DIR4_DOWN) encoded += (1 << 1+i);
if (glyph[i-1] == DIR4_DOWN && glyph[i] == DIR4_LEFT) encoded += (1 << 1+i);
if (glyph[i-1] == DIR4_LEFT && glyph[i] == DIR4_UP) encoded += (1 << 1+i);
if (glyph[i-1] == DIR4_UP && glyph[i] == DIR4_RIGHT) encoded += (1 << (1 + i));
if (glyph[i-1] == DIR4_RIGHT && glyph[i] == DIR4_DOWN) encoded += (1 << (1 + i));
if (glyph[i-1] == DIR4_DOWN && glyph[i] == DIR4_LEFT) encoded += (1 << (1 + i));
if (glyph[i-1] == DIR4_LEFT && glyph[i] == DIR4_UP) encoded += (1 << (1 + i));
}
return encoded;
}
Expand All @@ -53,7 +53,7 @@ void glyph_decode(Glyph glyph, uint8_t encoded) {
glyph[0] = (encoded & 0b00000011) + 1;
// Remaining directions.
for(uint8_t i=1; i<len; i++) {
if (encoded & (1<<i+1)) {
if (encoded & (1 << (i + 1))) {
// Clockwise.
if (glyph[i-1] == DIR4_UP) glyph[i] = DIR4_RIGHT;
if (glyph[i-1] == DIR4_RIGHT) glyph[i] = DIR4_DOWN;
Expand Down
5 changes: 1 addition & 4 deletions src/hid.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-2.0-only
// Copyright (C) 2022, Input Labs Oy.
// Copyright (C) 2022-2024, Input Labs Oy.

/*
HID layer is responsible for managing all the outputs that are sent to the
Expand Down Expand Up @@ -428,7 +428,6 @@ void hid_gamepad_reset() {
}

void hid_report() {
static bool is_tud_ready = false;
static bool is_tud_ready_logged = false;
static uint8_t priority_mouse = 0;
static uint8_t priority_gamepad = 0;
Expand All @@ -443,7 +442,6 @@ void hid_report() {
if (!hid_allow_communication) return;
tud_task();
if (tud_ready()) {
is_tud_ready = true;
if (!is_tud_ready_logged) {
is_tud_ready_logged = true;
info("USB: tud_ready TRUE\n");
Expand Down Expand Up @@ -477,7 +475,6 @@ void hid_report() {
// aggregated with the next cycle.
hid_gamepad_reset();
} else {
is_tud_ready = false;
if (is_tud_ready_logged) {
is_tud_ready_logged = false;
info("USB: tud_ready FALSE\n");
Expand Down
4 changes: 2 additions & 2 deletions src/imu.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-2.0-only
// Copyright (C) 2022, Input Labs Oy.
// Copyright (C) 2022-2024, Input Labs Oy.

#include <stdio.h>
#include <stdlib.h>
Expand Down Expand Up @@ -132,7 +132,7 @@ Vector imu_read_accel() {
};
}

Vector imu_calibrate_single(uint8_t cs, bool mode, double* x, double* y, double* z) {
void imu_calibrate_single(uint8_t cs, bool mode, double* x, double* y, double* z) {
char *mode_str = mode ? "accel" : "gyro";
info("IMU: cs=%i calibrating %s...\n", cs, mode_str);
double sum_x = 0;
Expand Down
3 changes: 1 addition & 2 deletions src/thumbstick.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-2.0-only
// Copyright (C) 2022, Input Labs Oy.
// Copyright (C) 2022-2024, Input Labs Oy.

#include <stdio.h>
#include <math.h>
Expand Down Expand Up @@ -173,7 +173,6 @@ void Thumbstick__config_glyphstick(Thumbstick *self, Actions actions, Glyph glyp
}

void Thumbstick__report_glyphstick(Thumbstick *self, Glyph input) {
bool matched = false;
// Iterate over all defined glyphs.
uint8_t nglyphs = self->glyphstick_index;
for(uint8_t i=0; i<nglyphs; i++) {
Expand Down
4 changes: 2 additions & 2 deletions src/tusb_config.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-2.0-only
// Copyright (C) 2022, Input Labs Oy.
// Copyright (C) 2022-2024, Input Labs Oy.

#include <tusb_config.h>
#include <tusb.h>
Expand Down Expand Up @@ -87,7 +87,7 @@ const uint16_t *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
static uint16_t response[64];
const char *string = descriptor_string[index];
uint8_t i = 0;
for (i; string[i]; i++) {
for (; string[i]; i++) {
response[i + 1] = string[i];
}
response[0] = TUSB_DESC_STRING << 8; // String type.
Expand Down
11 changes: 6 additions & 5 deletions src/webusb.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-2.0-only
// Copyright (C) 2022, Input Labs Oy.
// Copyright (C) 2022-2024, Input Labs Oy.

#include <stdio.h>
#include <stdbool.h>
Expand All @@ -14,7 +14,7 @@
#include "common.h"
#include "logging.h"

char webusb_buffer[WEBUSB_BUFFER_SIZE] = {0,};
uint8_t webusb_buffer[WEBUSB_BUFFER_SIZE] = {0,};
uint16_t webusb_ptr_in = 0;
uint16_t webusb_ptr_out = 0;
bool webusb_timedout = false;
Expand Down Expand Up @@ -50,7 +50,7 @@ bool webusb_transfer(Ctrl ctrl) {
// Claim USB endpoint.
if (!usbd_edpt_claim(0, ADDR_WEBUSB_IN)) return false;
// Transfer data.
if (!usbd_edpt_xfer(0, ADDR_WEBUSB_IN, (char*)&ctrl, ctrl.len+4)) return false;
if (!usbd_edpt_xfer(0, ADDR_WEBUSB_IN, (uint8_t*)&ctrl, ctrl.len+4)) return false;
// Release USB endpoint.
usbd_edpt_release(0, ADDR_WEBUSB_IN);
return true;
Expand Down Expand Up @@ -108,13 +108,14 @@ bool webusb_flush() {

// Queue data to be sent (flushed) to the app later.
void webusb_write(char *msg) {
uint16_t len = strlen(msg);
const size_t len = strlen(msg);
// If the buffer is full, ignore the latest messages.
if (webusb_ptr_in + len >= WEBUSB_BUFFER_SIZE-64-1) {
return;
}
// Add message to the buffer.
strncpy(webusb_buffer + webusb_ptr_in, msg, len);
memcpy((char*)(webusb_buffer + webusb_ptr_in), msg, len);
webusb_buffer[webusb_ptr_in + len] = '\0';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will have to try if this creates problems, the WebUSB buffer is not string based, but takes fixed size chunks.

webusb_ptr_in += len;
// If the configuration is still running (still not in the main loop), and
// the webusb connection has not been flagged as timed out, then force
Expand Down