Skip to content

Commit 098aabf

Browse files
author
Hrvoje Cavrak
committed
Minor updates and bugfixes
- Mouse movements should be smoother on the other Pico - Reworked CMakeLists with foreach to avoid duplication - Increased WDT timeout
1 parent 15da60b commit 098aabf

File tree

7 files changed

+30
-41
lines changed

7 files changed

+30
-41
lines changed

CMakeLists.txt

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
cmake_minimum_required(VERSION 3.13)
1+
cmake_minimum_required(VERSION 3.5)
22

33
set(PICO_SDK_FETCH_FROM_GIT off)
44
set(PICO_BOARD=pico)
55

66
include(pico_sdk_import.cmake)
7-
set(CMAKE_CXX_FLAGS "-Ofast -Wall -mcpu=cortex-m0plus -mtune=cortex-m0plus")
7+
set(CMAKE_C_FLAGS "-Ofast -Wall -mcpu=cortex-m0plus -mtune=cortex-m0plus -funroll-loops")
88

99
set(PICO_COPY_TO_RAM 1)
1010

1111
project(deskhop_project C CXX ASM)
1212
set(CMAKE_C_STANDARD 11)
1313
set(CMAKE_CXX_STANDARD 17)
14+
1415
pico_sdk_init()
1516

1617
set(PICO_PIO_USB_DIR ${CMAKE_CURRENT_LIST_DIR}/Pico-PIO-USB)
@@ -66,38 +67,29 @@ set(COMMON_LINK_LIBRARIES
6667
Pico-PIO-USB
6768
)
6869

69-
# Pico A - Keyboard
70-
add_executable(board_A)
71-
72-
target_sources(board_A PUBLIC ${COMMON_SOURCES})
73-
target_compile_definitions(board_A PRIVATE BOARD_ROLE=0 PIO_USB_USE_TINYUSB=1 PIO_USB_DP_PIN_DEFAULT=14)
74-
target_include_directories(board_A PUBLIC ${COMMON_INCLUDES})
75-
target_link_libraries(board_A PUBLIC ${COMMON_LINK_LIBRARIES})
70+
# Pico A - Keyboard (board_role = 0)
71+
# B - Mouse (board_role = 1)
7672

77-
pico_enable_stdio_usb(board_A 0)
78-
pico_add_extra_outputs(board_A)
73+
set(binaries board_A board_B)
7974

75+
foreach(board_role RANGE 0 1)
76+
list (GET binaries ${board_role} binary)
8077

81-
# Pico B - Mouse
82-
add_executable(board_B)
78+
add_executable(${binary})
8379

84-
target_compile_definitions(board_B PRIVATE BOARD_ROLE=1 PIO_USB_USE_TINYUSB=1 PIO_USB_DP_PIN_DEFAULT=14)
85-
target_sources(board_B PUBLIC ${COMMON_SOURCES})
86-
target_include_directories(board_B PUBLIC ${COMMON_INCLUDES})
87-
target_link_libraries(board_B PUBLIC ${COMMON_LINK_LIBRARIES})
80+
target_sources(${binary} PUBLIC ${COMMON_SOURCES})
81+
target_compile_definitions(${binary} PRIVATE BOARD_ROLE=${board_role} PIO_USB_USE_TINYUSB=1 PIO_USB_DP_PIN_DEFAULT=14)
82+
target_include_directories(${binary} PUBLIC ${COMMON_INCLUDES})
83+
target_link_libraries(${binary} PUBLIC ${COMMON_LINK_LIBRARIES})
8884

89-
pico_enable_stdio_usb(board_B 0)
90-
pico_add_extra_outputs(board_B)
85+
pico_enable_stdio_usb(${binary} 0)
86+
pico_add_extra_outputs(${binary})
9187

92-
target_link_options(board_A PRIVATE
93-
-Xlinker
94-
--print-memory-usage
95-
)
88+
target_link_options(${binary} PRIVATE
89+
-Xlinker
90+
--print-memory-usage
91+
)
9692

97-
target_link_options(board_B PRIVATE
98-
-Xlinker
99-
--print-memory-usage
100-
)
93+
pico_set_linker_script(${binary} ${CMAKE_SOURCE_DIR}/memory_map.ld)
10194

102-
pico_set_linker_script(board_A ${CMAKE_SOURCE_DIR}/memory_map.ld)
103-
pico_set_linker_script(board_B ${CMAKE_SOURCE_DIR}/memory_map.ld)
95+
endforeach()

binaries/board_A.uf2

25.5 KB
Binary file not shown.

binaries/board_B.uf2

25.5 KB
Binary file not shown.

src/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ device_t *device = &global_state;
2525
* ============== Main Program Loops ============== *
2626
* ================================================== */
2727

28-
void main(void) {
28+
int main(void) {
2929
// Wait for the board to settle
3030
sleep_ms(10);
3131

src/main.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
#define NUM_SCREENS 2 // Will be more in the future
5454
#define MOUSE_ZOOM_SCALING_FACTOR 2
5555

56-
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
56+
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
5757
#define CURRENT_BOARD_IS_ACTIVE_OUTPUT (global_state.active_output == BOARD_ROLE)
5858

5959
/********* Pinout definitions **********/
@@ -77,9 +77,9 @@
7777
#define SERIAL_PARITY UART_PARITY_NONE
7878

7979
/********* Watchdog definitions **********/
80-
#define WATCHDOG_TIMEOUT 500 // In milliseconds => needs to be reset every 500 ms
81-
#define WATCHDOG_PAUSE_ON_DEBUG 1 // When using a debugger, disable watchdog
82-
#define CORE1_HANG_TIMEOUT_US 500000 // In microseconds, wait up to 0.5s to declare core1 dead
80+
#define WATCHDOG_TIMEOUT 1000 // In milliseconds => needs to be reset every second
81+
#define WATCHDOG_PAUSE_ON_DEBUG 1 // When using a debugger, disable watchdog
82+
#define CORE1_HANG_TIMEOUT_US WATCHDOG_TIMEOUT * 1000 // Convert to microseconds
8383

8484
/********* Protocol definitions *********
8585
*

src/setup.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ void serial_init() {
4141
/* We do want FIFO, will help us have fewer interruptions */
4242
uart_set_fifo_enabled(SERIAL_UART, true);
4343

44-
/* Set the RX/TX pins, they differ based on the device role (A or B, check
45-
/* schematics) */
44+
/* Set the RX/TX pins, they differ based on the device role (A or B, check schematics) */
4645
gpio_set_function(SERIAL_TX_PIN, GPIO_FUNC_UART);
4746
gpio_set_function(SERIAL_RX_PIN, GPIO_FUNC_UART);
4847
}

src/uart.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,11 @@ void handle_idle_state(uint8_t *raw_packet, device_t *state) {
9191

9292
/* Read a character off the line until we reach fixed packet length */
9393
void handle_reading_state(uint8_t *raw_packet, device_t *state, int *count) {
94-
if (!uart_is_readable(SERIAL_UART)) {
95-
return;
94+
while (uart_is_readable(SERIAL_UART) && *count < PACKET_LENGTH) {
95+
/* Read and store the incoming byte */
96+
raw_packet[(*count)++] = uart_getc(SERIAL_UART);
9697
}
9798

98-
/* Read and store the incoming byte */
99-
raw_packet[(*count)++] = uart_getc(SERIAL_UART);
100-
10199
/* Check if a complete packet is received */
102100
if (*count >= PACKET_LENGTH) {
103101
state->receiver_state = PROCESSING_PACKET;

0 commit comments

Comments
 (0)