Skip to content

Commit

Permalink
Minor updates and bugfixes
Browse files Browse the repository at this point in the history
- Mouse movements should be smoother on the other Pico
- Reworked CMakeLists with foreach to avoid duplication
- Increased WDT timeout
  • Loading branch information
Hrvoje Cavrak committed Jan 27, 2024
1 parent 15da60b commit 098aabf
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 41 deletions.
50 changes: 21 additions & 29 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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_BOARD=pico)

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)

project(deskhop_project C CXX ASM)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)

pico_sdk_init()

set(PICO_PIO_USB_DIR ${CMAKE_CURRENT_LIST_DIR}/Pico-PIO-USB)
Expand Down Expand Up @@ -66,38 +67,29 @@ set(COMMON_LINK_LIBRARIES
Pico-PIO-USB
)

# Pico A - Keyboard
add_executable(board_A)

target_sources(board_A PUBLIC ${COMMON_SOURCES})
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 A - Keyboard (board_role = 0)
# B - Mouse (board_role = 1)

pico_enable_stdio_usb(board_A 0)
pico_add_extra_outputs(board_A)
set(binaries board_A board_B)

foreach(board_role RANGE 0 1)
list (GET binaries ${board_role} binary)

# Pico B - Mouse
add_executable(board_B)
add_executable(${binary})

target_compile_definitions(board_B PRIVATE BOARD_ROLE=1 PIO_USB_USE_TINYUSB=1 PIO_USB_DP_PIN_DEFAULT=14)
target_sources(board_B PUBLIC ${COMMON_SOURCES})
target_include_directories(board_B PUBLIC ${COMMON_INCLUDES})
target_link_libraries(board_B PUBLIC ${COMMON_LINK_LIBRARIES})
target_sources(${binary} PUBLIC ${COMMON_SOURCES})
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})

pico_enable_stdio_usb(board_B 0)
pico_add_extra_outputs(board_B)
pico_enable_stdio_usb(${binary} 0)
pico_add_extra_outputs(${binary})

target_link_options(board_A PRIVATE
-Xlinker
--print-memory-usage
)
target_link_options(${binary} PRIVATE
-Xlinker
--print-memory-usage
)

target_link_options(board_B PRIVATE
-Xlinker
--print-memory-usage
)
pico_set_linker_script(${binary} ${CMAKE_SOURCE_DIR}/memory_map.ld)

pico_set_linker_script(board_A ${CMAKE_SOURCE_DIR}/memory_map.ld)
pico_set_linker_script(board_B ${CMAKE_SOURCE_DIR}/memory_map.ld)
endforeach()
Binary file modified binaries/board_A.uf2
Binary file not shown.
Binary file modified binaries/board_B.uf2
Binary file not shown.
2 changes: 1 addition & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ device_t *device = &global_state;
* ============== Main Program Loops ============== *
* ================================================== */

void main(void) {
int main(void) {
// Wait for the board to settle
sleep_ms(10);

Expand Down
8 changes: 4 additions & 4 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
#define NUM_SCREENS 2 // Will be more in the future
#define MOUSE_ZOOM_SCALING_FACTOR 2

#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
#define CURRENT_BOARD_IS_ACTIVE_OUTPUT (global_state.active_output == BOARD_ROLE)

/********* Pinout definitions **********/
Expand All @@ -77,9 +77,9 @@
#define SERIAL_PARITY UART_PARITY_NONE

/********* Watchdog definitions **********/
#define WATCHDOG_TIMEOUT 500 // In milliseconds => needs to be reset every 500 ms
#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 WATCHDOG_TIMEOUT 1000 // In milliseconds => needs to be reset every second
#define WATCHDOG_PAUSE_ON_DEBUG 1 // When using a debugger, disable watchdog
#define CORE1_HANG_TIMEOUT_US WATCHDOG_TIMEOUT * 1000 // Convert to microseconds

/********* Protocol definitions *********
*
Expand Down
3 changes: 1 addition & 2 deletions src/setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ void serial_init() {
/* We do want FIFO, will help us have fewer interruptions */
uart_set_fifo_enabled(SERIAL_UART, true);

/* Set the RX/TX pins, they differ based on the device role (A or B, check
/* schematics) */
/* Set the RX/TX pins, they differ based on the device role (A or B, check schematics) */
gpio_set_function(SERIAL_TX_PIN, GPIO_FUNC_UART);
gpio_set_function(SERIAL_RX_PIN, GPIO_FUNC_UART);
}
Expand Down
8 changes: 3 additions & 5 deletions src/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,11 @@ void handle_idle_state(uint8_t *raw_packet, device_t *state) {

/* 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) {
if (!uart_is_readable(SERIAL_UART)) {
return;
while (uart_is_readable(SERIAL_UART) && *count < PACKET_LENGTH) {
/* Read and store the incoming byte */
raw_packet[(*count)++] = uart_getc(SERIAL_UART);
}

/* Read and store the incoming byte */
raw_packet[(*count)++] = uart_getc(SERIAL_UART);

/* Check if a complete packet is received */
if (*count >= PACKET_LENGTH) {
state->receiver_state = PROCESSING_PACKET;
Expand Down

0 comments on commit 098aabf

Please sign in to comment.