Minor updates and bugfixes

- Mouse movements should be smoother on the other Pico
- Reworked CMakeLists with foreach to avoid duplication
- Increased WDT timeout
This commit is contained in:
Hrvoje Cavrak 2024-01-27 22:38:46 +01:00
parent 15da60bd95
commit 098aabfc57
7 changed files with 30 additions and 41 deletions

View File

@ -1,16 +1,17 @@
cmake_minimum_required(VERSION 3.13) cmake_minimum_required(VERSION 3.5)
set(PICO_SDK_FETCH_FROM_GIT off) set(PICO_SDK_FETCH_FROM_GIT off)
set(PICO_BOARD=pico) set(PICO_BOARD=pico)
include(pico_sdk_import.cmake) include(pico_sdk_import.cmake)
set(CMAKE_CXX_FLAGS "-Ofast -Wall -mcpu=cortex-m0plus -mtune=cortex-m0plus") set(CMAKE_C_FLAGS "-Ofast -Wall -mcpu=cortex-m0plus -mtune=cortex-m0plus -funroll-loops")
set(PICO_COPY_TO_RAM 1) set(PICO_COPY_TO_RAM 1)
project(deskhop_project C CXX ASM) project(deskhop_project C CXX ASM)
set(CMAKE_C_STANDARD 11) set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD 17)
pico_sdk_init() pico_sdk_init()
set(PICO_PIO_USB_DIR ${CMAKE_CURRENT_LIST_DIR}/Pico-PIO-USB) set(PICO_PIO_USB_DIR ${CMAKE_CURRENT_LIST_DIR}/Pico-PIO-USB)
@ -66,38 +67,29 @@ set(COMMON_LINK_LIBRARIES
Pico-PIO-USB Pico-PIO-USB
) )
# Pico A - Keyboard # Pico A - Keyboard (board_role = 0)
add_executable(board_A) # B - Mouse (board_role = 1)
target_sources(board_A PUBLIC ${COMMON_SOURCES}) set(binaries board_A board_B)
target_compile_definitions(board_A PRIVATE BOARD_ROLE=0 PIO_USB_USE_TINYUSB=1 PIO_USB_DP_PIN_DEFAULT=14)
target_include_directories(board_A PUBLIC ${COMMON_INCLUDES})
target_link_libraries(board_A PUBLIC ${COMMON_LINK_LIBRARIES})
pico_enable_stdio_usb(board_A 0) foreach(board_role RANGE 0 1)
pico_add_extra_outputs(board_A) list (GET binaries ${board_role} binary)
add_executable(${binary})
# Pico B - Mouse target_sources(${binary} PUBLIC ${COMMON_SOURCES})
add_executable(board_B) target_compile_definitions(${binary} PRIVATE BOARD_ROLE=${board_role} PIO_USB_USE_TINYUSB=1 PIO_USB_DP_PIN_DEFAULT=14)
target_include_directories(${binary} PUBLIC ${COMMON_INCLUDES})
target_link_libraries(${binary} PUBLIC ${COMMON_LINK_LIBRARIES})
target_compile_definitions(board_B PRIVATE BOARD_ROLE=1 PIO_USB_USE_TINYUSB=1 PIO_USB_DP_PIN_DEFAULT=14) pico_enable_stdio_usb(${binary} 0)
target_sources(board_B PUBLIC ${COMMON_SOURCES}) pico_add_extra_outputs(${binary})
target_include_directories(board_B PUBLIC ${COMMON_INCLUDES})
target_link_libraries(board_B PUBLIC ${COMMON_LINK_LIBRARIES})
pico_enable_stdio_usb(board_B 0) target_link_options(${binary} PRIVATE
pico_add_extra_outputs(board_B)
target_link_options(board_A PRIVATE
-Xlinker -Xlinker
--print-memory-usage --print-memory-usage
) )
target_link_options(board_B PRIVATE pico_set_linker_script(${binary} ${CMAKE_SOURCE_DIR}/memory_map.ld)
-Xlinker
--print-memory-usage
)
pico_set_linker_script(board_A ${CMAKE_SOURCE_DIR}/memory_map.ld) endforeach()
pico_set_linker_script(board_B ${CMAKE_SOURCE_DIR}/memory_map.ld)

Binary file not shown.

Binary file not shown.

View File

@ -25,7 +25,7 @@ device_t *device = &global_state;
* ============== Main Program Loops ============== * * ============== Main Program Loops ============== *
* ================================================== */ * ================================================== */
void main(void) { int main(void) {
// Wait for the board to settle // Wait for the board to settle
sleep_ms(10); sleep_ms(10);

View File

@ -77,9 +77,9 @@
#define SERIAL_PARITY UART_PARITY_NONE #define SERIAL_PARITY UART_PARITY_NONE
/********* Watchdog definitions **********/ /********* Watchdog definitions **********/
#define WATCHDOG_TIMEOUT 500 // In milliseconds => needs to be reset every 500 ms #define WATCHDOG_TIMEOUT 1000 // In milliseconds => needs to be reset every second
#define WATCHDOG_PAUSE_ON_DEBUG 1 // When using a debugger, disable watchdog #define WATCHDOG_PAUSE_ON_DEBUG 1 // When using a debugger, disable watchdog
#define CORE1_HANG_TIMEOUT_US 500000 // In microseconds, wait up to 0.5s to declare core1 dead #define CORE1_HANG_TIMEOUT_US WATCHDOG_TIMEOUT * 1000 // Convert to microseconds
/********* Protocol definitions ********* /********* Protocol definitions *********
* *

View File

@ -41,8 +41,7 @@ void serial_init() {
/* We do want FIFO, will help us have fewer interruptions */ /* We do want FIFO, will help us have fewer interruptions */
uart_set_fifo_enabled(SERIAL_UART, true); uart_set_fifo_enabled(SERIAL_UART, true);
/* Set the RX/TX pins, they differ based on the device role (A or B, check /* Set the RX/TX pins, they differ based on the device role (A or B, check schematics) */
/* schematics) */
gpio_set_function(SERIAL_TX_PIN, GPIO_FUNC_UART); gpio_set_function(SERIAL_TX_PIN, GPIO_FUNC_UART);
gpio_set_function(SERIAL_RX_PIN, GPIO_FUNC_UART); gpio_set_function(SERIAL_RX_PIN, GPIO_FUNC_UART);
} }

View File

@ -91,12 +91,10 @@ void handle_idle_state(uint8_t *raw_packet, device_t *state) {
/* Read a character off the line until we reach fixed packet length */ /* Read a character off the line until we reach fixed packet length */
void handle_reading_state(uint8_t *raw_packet, device_t *state, int *count) { void handle_reading_state(uint8_t *raw_packet, device_t *state, int *count) {
if (!uart_is_readable(SERIAL_UART)) { while (uart_is_readable(SERIAL_UART) && *count < PACKET_LENGTH) {
return;
}
/* Read and store the incoming byte */ /* Read and store the incoming byte */
raw_packet[(*count)++] = uart_getc(SERIAL_UART); raw_packet[(*count)++] = uart_getc(SERIAL_UART);
}
/* Check if a complete packet is received */ /* Check if a complete packet is received */
if (*count >= PACKET_LENGTH) { if (*count >= PACKET_LENGTH) {