Compare commits
3 Commits
dfe01e2958
...
922494beb2
Author | SHA1 | Date |
---|---|---|
Colin | 922494beb2 | |
Hrvoje Cavrak | 8aa5bf508b | |
Hrvoje Cavrak | f841035c09 |
|
@ -15,14 +15,14 @@ const config_t default_config = {
|
|||
},
|
||||
.screen_count = 1,
|
||||
.screen_index = 1,
|
||||
.os = OUTPUT_A_OS,
|
||||
// .os = OUTPUT_A_OS,
|
||||
.pos = RIGHT,
|
||||
.screensaver = {
|
||||
.mode = SCREENSAVER_A_MODE,
|
||||
.only_if_inactive = SCREENSAVER_A_ONLY_IF_INACTIVE,
|
||||
.idle_time_us = SCREENSAVER_A_IDLE_TIME_SEC * 1000000,
|
||||
.max_time_us = SCREENSAVER_A_MAX_TIME_SEC * 1000000,
|
||||
}
|
||||
// .screensaver = {
|
||||
// .mode = SCREENSAVER_A_MODE,
|
||||
// .only_if_inactive = SCREENSAVER_A_ONLY_IF_INACTIVE,
|
||||
// .idle_time_us = SCREENSAVER_A_IDLE_TIME_SEC * 1000000,
|
||||
// .max_time_us = SCREENSAVER_A_MAX_TIME_SEC * 1000000,
|
||||
// }
|
||||
},
|
||||
.output[OUTPUT_B] =
|
||||
{
|
||||
|
@ -35,14 +35,14 @@ const config_t default_config = {
|
|||
},
|
||||
.screen_count = 1,
|
||||
.screen_index = 1,
|
||||
.os = OUTPUT_B_OS,
|
||||
// .os = OUTPUT_B_OS,
|
||||
.pos = LEFT,
|
||||
.screensaver = {
|
||||
.mode = SCREENSAVER_B_MODE,
|
||||
.only_if_inactive = SCREENSAVER_B_ONLY_IF_INACTIVE,
|
||||
.idle_time_us = SCREENSAVER_B_IDLE_TIME_SEC * 1000000,
|
||||
.max_time_us = SCREENSAVER_B_MAX_TIME_SEC * 1000000,
|
||||
}
|
||||
// .screensaver = {
|
||||
// .mode = SCREENSAVER_B_MODE,
|
||||
// .only_if_inactive = SCREENSAVER_B_ONLY_IF_INACTIVE,
|
||||
// .idle_time_us = SCREENSAVER_B_IDLE_TIME_SEC * 1000000,
|
||||
// .max_time_us = SCREENSAVER_B_MAX_TIME_SEC * 1000000,
|
||||
// }
|
||||
},
|
||||
.enforce_ports = ENFORCE_PORTS,
|
||||
.force_kbd_boot_protocol = ENFORCE_KEYBOARD_BOOT_PROTOCOL,
|
||||
|
|
255
src/handlers.c
255
src/handlers.c
|
@ -24,11 +24,11 @@
|
|||
/* This is the main hotkey for switching outputs */
|
||||
void output_toggle_hotkey_handler(device_t *state, hid_keyboard_report_t *report) {
|
||||
/* If switching explicitly disabled, return immediately */
|
||||
if (state->switch_lock)
|
||||
return;
|
||||
// if (state->switch_lock)
|
||||
// return;
|
||||
|
||||
state->active_output ^= 1;
|
||||
switch_output(state, state->active_output);
|
||||
set_active_output(state, state->active_output);
|
||||
};
|
||||
|
||||
void _get_border_position(device_t *state, border_size_t *border) {
|
||||
|
@ -39,115 +39,115 @@ void _get_border_position(device_t *state, border_size_t *border) {
|
|||
border->top = state->pointer_y;
|
||||
}
|
||||
|
||||
void _screensaver_set(device_t *state, uint8_t value) {
|
||||
if (CURRENT_BOARD_IS_ACTIVE_OUTPUT)
|
||||
state->config.output[BOARD_ROLE].screensaver.mode = value;
|
||||
else
|
||||
send_value(value, SCREENSAVER_MSG);
|
||||
};
|
||||
// void _screensaver_set(device_t *state, uint8_t value) {
|
||||
// if (CURRENT_BOARD_IS_ACTIVE_OUTPUT)
|
||||
// state->config.output[BOARD_ROLE].screensaver.mode = value;
|
||||
// else
|
||||
// send_value(value, SCREENSAVER_MSG);
|
||||
// };
|
||||
|
||||
/* This key combo records switch y top coordinate for different-size monitors */
|
||||
void screen_border_hotkey_handler(device_t *state, hid_keyboard_report_t *report) {
|
||||
border_size_t *border = &state->config.output[state->active_output].border;
|
||||
if (CURRENT_BOARD_IS_ACTIVE_OUTPUT) {
|
||||
_get_border_position(state, border);
|
||||
save_config(state);
|
||||
}
|
||||
// /* This key combo records switch y top coordinate for different-size monitors */
|
||||
// void screen_border_hotkey_handler(device_t *state, hid_keyboard_report_t *report) {
|
||||
// border_size_t *border = &state->config.output[state->active_output].border;
|
||||
// if (CURRENT_BOARD_IS_ACTIVE_OUTPUT) {
|
||||
// _get_border_position(state, border);
|
||||
// save_config(state);
|
||||
// }
|
||||
|
||||
queue_packet((uint8_t *)border, SYNC_BORDERS_MSG, sizeof(border_size_t));
|
||||
};
|
||||
// queue_packet((uint8_t *)border, SYNC_BORDERS_MSG, sizeof(border_size_t));
|
||||
// };
|
||||
|
||||
/* This key combo puts board A in firmware upgrade mode */
|
||||
void fw_upgrade_hotkey_handler_A(device_t *state, hid_keyboard_report_t *report) {
|
||||
reset_usb_boot(1 << PICO_DEFAULT_LED_PIN, 0);
|
||||
};
|
||||
// /* This key combo puts board A in firmware upgrade mode */
|
||||
// void fw_upgrade_hotkey_handler_A(device_t *state, hid_keyboard_report_t *report) {
|
||||
// reset_usb_boot(1 << PICO_DEFAULT_LED_PIN, 0);
|
||||
// };
|
||||
|
||||
/* This key combo puts board B in firmware upgrade mode */
|
||||
void fw_upgrade_hotkey_handler_B(device_t *state, hid_keyboard_report_t *report) {
|
||||
send_value(ENABLE, FIRMWARE_UPGRADE_MSG);
|
||||
};
|
||||
// /* This key combo puts board B in firmware upgrade mode */
|
||||
// void fw_upgrade_hotkey_handler_B(device_t *state, hid_keyboard_report_t *report) {
|
||||
// send_value(ENABLE, FIRMWARE_UPGRADE_MSG);
|
||||
// };
|
||||
|
||||
/* This key combo prevents mouse from switching outputs */
|
||||
void switchlock_hotkey_handler(device_t *state, hid_keyboard_report_t *report) {
|
||||
state->switch_lock ^= 1;
|
||||
send_value(state->switch_lock, SWITCH_LOCK_MSG);
|
||||
}
|
||||
// /* This key combo prevents mouse from switching outputs */
|
||||
// void switchlock_hotkey_handler(device_t *state, hid_keyboard_report_t *report) {
|
||||
// state->switch_lock ^= 1;
|
||||
// send_value(state->switch_lock, SWITCH_LOCK_MSG);
|
||||
// }
|
||||
|
||||
/* This key combo toggles gaming mode */
|
||||
void toggle_gaming_mode_handler(device_t *state, hid_keyboard_report_t *report) {
|
||||
state->gaming_mode ^= 1;
|
||||
send_value(state->gaming_mode, GAMING_MODE_MSG);
|
||||
};
|
||||
// /* This key combo toggles gaming mode */
|
||||
// void toggle_gaming_mode_handler(device_t *state, hid_keyboard_report_t *report) {
|
||||
// state->gaming_mode ^= 1;
|
||||
// send_value(state->gaming_mode, GAMING_MODE_MSG);
|
||||
// };
|
||||
|
||||
/* This key combo locks both outputs simultaneously */
|
||||
void screenlock_hotkey_handler(device_t *state, hid_keyboard_report_t *report) {
|
||||
hid_keyboard_report_t lock_report = {0}, release_keys = {0};
|
||||
// /* This key combo locks both outputs simultaneously */
|
||||
// void screenlock_hotkey_handler(device_t *state, hid_keyboard_report_t *report) {
|
||||
// hid_keyboard_report_t lock_report = {0}, release_keys = {0};
|
||||
|
||||
for (int out = 0; out < NUM_SCREENS; out++) {
|
||||
switch (state->config.output[out].os) {
|
||||
case WINDOWS:
|
||||
case LINUX:
|
||||
lock_report.modifier = KEYBOARD_MODIFIER_LEFTGUI;
|
||||
lock_report.keycode[0] = HID_KEY_L;
|
||||
break;
|
||||
case MACOS:
|
||||
lock_report.modifier = KEYBOARD_MODIFIER_LEFTCTRL | KEYBOARD_MODIFIER_LEFTGUI;
|
||||
lock_report.keycode[0] = HID_KEY_Q;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
// for (int out = 0; out < NUM_SCREENS; out++) {
|
||||
// switch (state->config.output[out].os) {
|
||||
// case WINDOWS:
|
||||
// case LINUX:
|
||||
// lock_report.modifier = KEYBOARD_MODIFIER_LEFTGUI;
|
||||
// lock_report.keycode[0] = HID_KEY_L;
|
||||
// break;
|
||||
// case MACOS:
|
||||
// lock_report.modifier = KEYBOARD_MODIFIER_LEFTCTRL | KEYBOARD_MODIFIER_LEFTGUI;
|
||||
// lock_report.keycode[0] = HID_KEY_Q;
|
||||
// break;
|
||||
// default:
|
||||
// break;
|
||||
// }
|
||||
|
||||
if (BOARD_ROLE == out) {
|
||||
queue_kbd_report(&lock_report, state);
|
||||
release_all_keys(state);
|
||||
} else {
|
||||
queue_packet((uint8_t *)&lock_report, KEYBOARD_REPORT_MSG, KBD_REPORT_LENGTH);
|
||||
queue_packet((uint8_t *)&release_keys, KEYBOARD_REPORT_MSG, KBD_REPORT_LENGTH);
|
||||
}
|
||||
}
|
||||
}
|
||||
// if (BOARD_ROLE == out) {
|
||||
// queue_kbd_report(&lock_report, state);
|
||||
// release_all_keys(state);
|
||||
// } else {
|
||||
// queue_packet((uint8_t *)&lock_report, KEYBOARD_REPORT_MSG, KBD_REPORT_LENGTH);
|
||||
// queue_packet((uint8_t *)&release_keys, KEYBOARD_REPORT_MSG, KBD_REPORT_LENGTH);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
/* When pressed, erases stored config in flash and loads defaults on both boards */
|
||||
void wipe_config_hotkey_handler(device_t *state, hid_keyboard_report_t *report) {
|
||||
wipe_config();
|
||||
load_config(state);
|
||||
send_value(ENABLE, WIPE_CONFIG_MSG);
|
||||
}
|
||||
// /* When pressed, erases stored config in flash and loads defaults on both boards */
|
||||
// void wipe_config_hotkey_handler(device_t *state, hid_keyboard_report_t *report) {
|
||||
// wipe_config();
|
||||
// load_config(state);
|
||||
// send_value(ENABLE, WIPE_CONFIG_MSG);
|
||||
// }
|
||||
|
||||
/* When pressed, toggles the current mouse zoom mode state */
|
||||
void mouse_zoom_hotkey_handler(device_t *state, hid_keyboard_report_t *report) {
|
||||
state->mouse_zoom ^= 1;
|
||||
send_value(state->mouse_zoom, MOUSE_ZOOM_MSG);
|
||||
};
|
||||
// /* When pressed, toggles the current mouse zoom mode state */
|
||||
// void mouse_zoom_hotkey_handler(device_t *state, hid_keyboard_report_t *report) {
|
||||
// state->mouse_zoom ^= 1;
|
||||
// send_value(state->mouse_zoom, MOUSE_ZOOM_MSG);
|
||||
// };
|
||||
|
||||
/* When pressed, enables the screensaver on active output */
|
||||
void enable_screensaver_hotkey_handler(device_t *state, hid_keyboard_report_t *report) {
|
||||
uint8_t desired_mode = state->config.output[BOARD_ROLE].screensaver.mode;
|
||||
// /* When pressed, enables the screensaver on active output */
|
||||
// void enable_screensaver_hotkey_handler(device_t *state, hid_keyboard_report_t *report) {
|
||||
// uint8_t desired_mode = state->config.output[BOARD_ROLE].screensaver.mode;
|
||||
|
||||
/* If the user explicitly asks for screensaver to be active, ignore config and turn it on */
|
||||
if (desired_mode == DISABLED)
|
||||
desired_mode = PONG;
|
||||
// /* If the user explicitly asks for screensaver to be active, ignore config and turn it on */
|
||||
// if (desired_mode == DISABLED)
|
||||
// desired_mode = PONG;
|
||||
|
||||
_screensaver_set(state, desired_mode);
|
||||
}
|
||||
// _screensaver_set(state, desired_mode);
|
||||
// }
|
||||
|
||||
/* When pressed, disables the screensaver on active output */
|
||||
void disable_screensaver_hotkey_handler(device_t *state, hid_keyboard_report_t *report) {
|
||||
_screensaver_set(state, DISABLED);
|
||||
}
|
||||
// /* When pressed, disables the screensaver on active output */
|
||||
// void disable_screensaver_hotkey_handler(device_t *state, hid_keyboard_report_t *report) {
|
||||
// _screensaver_set(state, DISABLED);
|
||||
// }
|
||||
|
||||
/* Put the device into a special configuration mode */
|
||||
void config_enable_hotkey_handler(device_t *state, hid_keyboard_report_t *report) {
|
||||
/* If config mode is already active, skip this and reboot to return to normal mode */
|
||||
if (!state->config_mode_active) {
|
||||
watchdog_hw->scratch[5] = MAGIC_WORD_1;
|
||||
watchdog_hw->scratch[6] = MAGIC_WORD_2;
|
||||
}
|
||||
// /* Put the device into a special configuration mode */
|
||||
// void config_enable_hotkey_handler(device_t *state, hid_keyboard_report_t *report) {
|
||||
// /* If config mode is already active, skip this and reboot to return to normal mode */
|
||||
// if (!state->config_mode_active) {
|
||||
// watchdog_hw->scratch[5] = MAGIC_WORD_1;
|
||||
// watchdog_hw->scratch[6] = MAGIC_WORD_2;
|
||||
// }
|
||||
|
||||
release_all_keys(state);
|
||||
state->reboot_requested = true;
|
||||
};
|
||||
// release_all_keys(state);
|
||||
// state->reboot_requested = true;
|
||||
// };
|
||||
|
||||
|
||||
/**==================================================== *
|
||||
|
@ -181,15 +181,15 @@ void handle_output_select_msg(uart_packet_t *packet, device_t *state) {
|
|||
restore_leds(state);
|
||||
}
|
||||
|
||||
/* On firmware upgrade message, reboot into the BOOTSEL fw upgrade mode */
|
||||
void handle_fw_upgrade_msg(uart_packet_t *packet, device_t *state) {
|
||||
reset_usb_boot(1 << PICO_DEFAULT_LED_PIN, 0);
|
||||
}
|
||||
// /* On firmware upgrade message, reboot into the BOOTSEL fw upgrade mode */
|
||||
// void handle_fw_upgrade_msg(uart_packet_t *packet, device_t *state) {
|
||||
// reset_usb_boot(1 << PICO_DEFAULT_LED_PIN, 0);
|
||||
// }
|
||||
|
||||
/* Comply with request to turn mouse zoom mode on/off */
|
||||
void handle_mouse_zoom_msg(uart_packet_t *packet, device_t *state) {
|
||||
state->mouse_zoom = packet->data[0];
|
||||
}
|
||||
// /* Comply with request to turn mouse zoom mode on/off */
|
||||
// void handle_mouse_zoom_msg(uart_packet_t *packet, device_t *state) {
|
||||
// state->mouse_zoom = packet->data[0];
|
||||
// }
|
||||
|
||||
/* Process request to update keyboard LEDs */
|
||||
void handle_set_report_msg(uart_packet_t *packet, device_t *state) {
|
||||
|
@ -201,10 +201,10 @@ void handle_set_report_msg(uart_packet_t *packet, device_t *state) {
|
|||
restore_leds(state);
|
||||
}
|
||||
|
||||
/* Process request to block mouse from switching, update internal state */
|
||||
void handle_switch_lock_msg(uart_packet_t *packet, device_t *state) {
|
||||
state->switch_lock = packet->data[0];
|
||||
}
|
||||
// /* Process request to block mouse from switching, update internal state */
|
||||
// void handle_switch_lock_msg(uart_packet_t *packet, device_t *state) {
|
||||
// state->switch_lock = packet->data[0];
|
||||
// }
|
||||
|
||||
/* Handle border syncing message that lets the other device know about monitor height offset */
|
||||
void handle_sync_borders_msg(uart_packet_t *packet, device_t *state) {
|
||||
|
@ -224,16 +224,16 @@ void handle_flash_led_msg(uart_packet_t *packet, device_t *state) {
|
|||
blink_led(state);
|
||||
}
|
||||
|
||||
/* When this message is received, wipe the local flash config */
|
||||
void handle_wipe_config_msg(uart_packet_t *packet, device_t *state) {
|
||||
wipe_config();
|
||||
load_config(state);
|
||||
}
|
||||
// /* When this message is received, wipe the local flash config */
|
||||
// void handle_wipe_config_msg(uart_packet_t *packet, device_t *state) {
|
||||
// wipe_config();
|
||||
// load_config(state);
|
||||
// }
|
||||
|
||||
/* Update screensaver state after received message */
|
||||
void handle_screensaver_msg(uart_packet_t *packet, device_t *state) {
|
||||
state->config.output[BOARD_ROLE].screensaver.mode = packet->data[0];
|
||||
}
|
||||
// /* Update screensaver state after received message */
|
||||
// void handle_screensaver_msg(uart_packet_t *packet, device_t *state) {
|
||||
// state->config.output[BOARD_ROLE].screensaver.mode = packet->data[0];
|
||||
// }
|
||||
|
||||
/* Process consumer control message */
|
||||
void handle_consumer_control_msg(uart_packet_t *packet, device_t *state) {
|
||||
|
@ -255,10 +255,10 @@ void handle_proxy_msg(uart_packet_t *packet, device_t *state) {
|
|||
queue_packet(&packet->data[1], (enum packet_type_e)packet->data[0], PACKET_DATA_LENGTH - 1);
|
||||
}
|
||||
|
||||
/* Process relative mouse command */
|
||||
void handle_toggle_gaming_msg(uart_packet_t *packet, device_t *state) {
|
||||
state->gaming_mode = packet->data[0];
|
||||
}
|
||||
// /* Process relative mouse command */
|
||||
// void handle_toggle_gaming_msg(uart_packet_t *packet, device_t *state) {
|
||||
// state->gaming_mode = packet->data[0];
|
||||
// }
|
||||
|
||||
/* Process api communication messages */
|
||||
void handle_api_msgs(uart_packet_t *packet, device_t *state) {
|
||||
|
@ -320,7 +320,7 @@ void handle_response_byte_msg(uart_packet_t *packet, device_t *state) {
|
|||
uint32_t address = packet->data32[0];
|
||||
|
||||
if (address != state->fw.address) {
|
||||
state->fw.upgrade_in_progress = false;
|
||||
// state->fw.upgrade_in_progress = false;
|
||||
state->fw.address = 0;
|
||||
return;
|
||||
}
|
||||
|
@ -339,23 +339,24 @@ void handle_response_byte_msg(uart_packet_t *packet, device_t *state) {
|
|||
|
||||
/* Neeeeeeext byte, please! */
|
||||
state->fw.address += sizeof(uint32_t);
|
||||
state->fw.byte_done = true;
|
||||
// state->fw.byte_done = true;
|
||||
}
|
||||
|
||||
/* Process a request to read a firmware package from flash */
|
||||
void handle_heartbeat_msg(uart_packet_t *packet, device_t *state) {
|
||||
uint16_t other_running_version = packet->data16[0];
|
||||
|
||||
if (state->fw.upgrade_in_progress)
|
||||
return;
|
||||
// if (state->fw.upgrade_in_progress)
|
||||
// return;
|
||||
|
||||
/* If the other board isn't running a newer version, we are done */
|
||||
if (other_running_version <= state->_running_fw.version)
|
||||
return;
|
||||
|
||||
/* It is? Ok, kick off the firmware upgrade */
|
||||
state->fw = (fw_upgrade_state_t) {
|
||||
.upgrade_in_progress = true,
|
||||
// state->fw = (fw_upgrade_state_t) {
|
||||
state->fw = () {
|
||||
// .upgrade_in_progress = true,
|
||||
.byte_done = true,
|
||||
.address = 0,
|
||||
.checksum = 0xffffffff,
|
||||
|
@ -368,7 +369,7 @@ void handle_heartbeat_msg(uart_packet_t *packet, device_t *state) {
|
|||
* ==================================================== */
|
||||
|
||||
/* Update output variable, set LED on/off and notify the other board so they are in sync. */
|
||||
void switch_output(device_t *state, uint8_t new_output) {
|
||||
void set_active_output(device_t *state, uint8_t new_output) {
|
||||
state->active_output = new_output;
|
||||
restore_leds(state);
|
||||
send_value(new_output, OUTPUT_SELECT_MSG);
|
||||
|
|
|
@ -52,7 +52,7 @@
|
|||
#define TOUCH 2
|
||||
|
||||
#define MOUSE_BOOT_REPORT_LEN 4
|
||||
#define MOUSE_ZOOM_SCALING_FACTOR 2
|
||||
// #define MOUSE_ZOOM_SCALING_FACTOR 2
|
||||
#define NUM_SCREENS 2 // Will be more in the future
|
||||
#define CONFIG_MODE_TIMEOUT 300000000 // 5 minutes into the future
|
||||
|
||||
|
@ -116,16 +116,16 @@ enum packet_type_e {
|
|||
KEYBOARD_REPORT_MSG = 1,
|
||||
MOUSE_REPORT_MSG = 2,
|
||||
OUTPUT_SELECT_MSG = 3,
|
||||
FIRMWARE_UPGRADE_MSG = 4,
|
||||
MOUSE_ZOOM_MSG = 5,
|
||||
// FIRMWARE_UPGRADE_MSG = 4,
|
||||
// MOUSE_ZOOM_MSG = 5,
|
||||
KBD_SET_REPORT_MSG = 6,
|
||||
SWITCH_LOCK_MSG = 7,
|
||||
// SWITCH_LOCK_MSG = 7,
|
||||
SYNC_BORDERS_MSG = 8,
|
||||
FLASH_LED_MSG = 9,
|
||||
WIPE_CONFIG_MSG = 10,
|
||||
SCREENSAVER_MSG = 11,
|
||||
// WIPE_CONFIG_MSG = 10,
|
||||
// SCREENSAVER_MSG = 11,
|
||||
HEARTBEAT_MSG = 12,
|
||||
GAMING_MODE_MSG = 13,
|
||||
// GAMING_MODE_MSG = 13,
|
||||
CONSUMER_CONTROL_MSG = 14,
|
||||
SYSTEM_CONTROL_MSG = 15,
|
||||
SAVE_CONFIG_MSG = 18,
|
||||
|
@ -200,17 +200,18 @@ enum os_type_e {
|
|||
};
|
||||
|
||||
enum screen_pos_e {
|
||||
NONE = 0,
|
||||
LEFT = 1,
|
||||
RIGHT = 2,
|
||||
MIDDLE = 3,
|
||||
};
|
||||
|
||||
enum screensaver_mode_e {
|
||||
DISABLED = 0,
|
||||
PONG = 1,
|
||||
JITTER = 2,
|
||||
MAX_SS_VAL = JITTER,
|
||||
};
|
||||
// enum screensaver_mode_e {
|
||||
// DISABLED = 0,
|
||||
// PONG = 1,
|
||||
// JITTER = 2,
|
||||
// MAX_SS_VAL = JITTER,
|
||||
// };
|
||||
|
||||
#define ITF_NUM_HID 0
|
||||
#define ITF_NUM_HID_REL_M 1
|
||||
|
@ -223,13 +224,13 @@ typedef struct {
|
|||
// height
|
||||
} border_size_t;
|
||||
|
||||
/* Define screensaver parameters */
|
||||
typedef struct {
|
||||
uint8_t mode;
|
||||
uint8_t only_if_inactive;
|
||||
uint64_t idle_time_us;
|
||||
uint64_t max_time_us;
|
||||
} screensaver_t;
|
||||
// /* Define screensaver parameters */
|
||||
// typedef struct {
|
||||
// uint8_t mode;
|
||||
// uint8_t only_if_inactive;
|
||||
// uint64_t idle_time_us;
|
||||
// uint64_t max_time_us;
|
||||
// } screensaver_t;
|
||||
|
||||
/* Define output parameters */
|
||||
typedef struct {
|
||||
|
@ -242,7 +243,7 @@ typedef struct {
|
|||
uint8_t os; // Operating system on this output
|
||||
uint8_t pos; // Screen position on this output
|
||||
uint8_t mouse_park_pos; // Where the mouse goes after switch
|
||||
screensaver_t screensaver; // Screensaver parameters for this output
|
||||
// screensaver_t screensaver; // Screensaver parameters for this output
|
||||
} output_t;
|
||||
|
||||
/* Data structure defining how configuration is stored */
|
||||
|
@ -372,13 +373,13 @@ typedef struct {
|
|||
|
||||
typedef enum { IDLE, READING_PACKET, PROCESSING_PACKET } receiver_state_t;
|
||||
|
||||
typedef struct {
|
||||
uint32_t address; // Address we're sending to the other box
|
||||
uint32_t checksum;
|
||||
uint16_t version;
|
||||
bool byte_done; // Has the byte been successfully transferred
|
||||
bool upgrade_in_progress; // True if firmware transfer from the other box is in progress
|
||||
} fw_upgrade_state_t;
|
||||
// typedef struct {
|
||||
// uint32_t address; // Address we're sending to the other box
|
||||
// uint32_t checksum;
|
||||
// uint16_t version;
|
||||
// bool byte_done; // Has the byte been successfully transferred
|
||||
// bool upgrade_in_progress; // True if firmware transfer from the other box is in progress
|
||||
// } fw_upgrade_state_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t kbd_dev_addr; // Address of the keyboard device
|
||||
|
@ -410,7 +411,7 @@ typedef struct {
|
|||
uint32_t dma_tx_channel; // DMA TX channel we're using to send
|
||||
|
||||
/* Firmware */
|
||||
fw_upgrade_state_t fw; // State of the firmware upgrader
|
||||
// fw_upgrade_state_t fw; // State of the firmware upgrader
|
||||
firmware_metadata_t _running_fw; // RAM copy of running fw metadata
|
||||
bool reboot_requested; // If set, stop updating watchdog
|
||||
uint64_t config_mode_timer; // Counts how long are we to remain in config mode
|
||||
|
@ -422,11 +423,11 @@ typedef struct {
|
|||
bool keyboard_connected; // True when our keyboard is connected locally
|
||||
|
||||
/* Feature flags */
|
||||
bool mouse_zoom; // True when "mouse zoom" is enabled
|
||||
bool switch_lock; // True when device is prevented from switching
|
||||
// bool mouse_zoom; // True when "mouse zoom" is enabled
|
||||
// bool switch_lock; // True when device is prevented from switching
|
||||
bool onboard_led_state; // True when LED is ON
|
||||
bool relative_mouse; // True when relative mouse mode is used
|
||||
bool gaming_mode; // True when gaming mode is on (relative passthru + lock)
|
||||
// bool gaming_mode; // True when gaming mode is on (relative passthru + lock)
|
||||
bool config_mode_active; // True when config mode is active
|
||||
bool digitizer_active; // True when digitizer Win/Mac workaround is active
|
||||
|
||||
|
@ -509,8 +510,8 @@ void usb_device_task(device_t *);
|
|||
void kick_watchdog_task(device_t *);
|
||||
void usb_host_task(device_t *);
|
||||
void packet_receiver_task(device_t *);
|
||||
void screensaver_task(device_t *);
|
||||
void firmware_upgrade_task(device_t *);
|
||||
// void screensaver_task(device_t *);
|
||||
// void firmware_upgrade_task(device_t *);
|
||||
void heartbeat_output_task(device_t *);
|
||||
void led_blinking_task(device_t *);
|
||||
|
||||
|
@ -519,7 +520,7 @@ void task_scheduler(device_t *, task_t *);
|
|||
/********* Configuration **********/
|
||||
void load_config(device_t *);
|
||||
void save_config(device_t *);
|
||||
void wipe_config(void);
|
||||
// void wipe_config(void);
|
||||
void reset_config_timer(device_t *);
|
||||
|
||||
extern const field_map_t api_field_map[];
|
||||
|
@ -531,30 +532,30 @@ void queue_cfg_packet(uart_packet_t *, device_t *);
|
|||
|
||||
/********* Handlers **********/
|
||||
void output_toggle_hotkey_handler(device_t *, hid_keyboard_report_t *);
|
||||
void screen_border_hotkey_handler(device_t *, hid_keyboard_report_t *);
|
||||
void fw_upgrade_hotkey_handler_A(device_t *, hid_keyboard_report_t *);
|
||||
void fw_upgrade_hotkey_handler_B(device_t *, hid_keyboard_report_t *);
|
||||
void mouse_zoom_hotkey_handler(device_t *, hid_keyboard_report_t *);
|
||||
void all_keys_released_handler(device_t *);
|
||||
void switchlock_hotkey_handler(device_t *, hid_keyboard_report_t *);
|
||||
void toggle_gaming_mode_handler(device_t *, hid_keyboard_report_t *);
|
||||
void screenlock_hotkey_handler(device_t *, hid_keyboard_report_t *);
|
||||
void output_config_hotkey_handler(device_t *, hid_keyboard_report_t *);
|
||||
void wipe_config_hotkey_handler(device_t *, hid_keyboard_report_t *);
|
||||
void config_enable_hotkey_handler(device_t *, hid_keyboard_report_t *);
|
||||
void enable_screensaver_hotkey_handler(device_t *, hid_keyboard_report_t *);
|
||||
void disable_screensaver_hotkey_handler(device_t *, hid_keyboard_report_t *);
|
||||
// void screen_border_hotkey_handler(device_t *, hid_keyboard_report_t *);
|
||||
// void fw_upgrade_hotkey_handler_A(device_t *, hid_keyboard_report_t *);
|
||||
// void fw_upgrade_hotkey_handler_B(device_t *, hid_keyboard_report_t *);
|
||||
// void mouse_zoom_hotkey_handler(device_t *, hid_keyboard_report_t *);
|
||||
// void all_keys_released_handler(device_t *);
|
||||
// void switchlock_hotkey_handler(device_t *, hid_keyboard_report_t *);
|
||||
// void toggle_gaming_mode_handler(device_t *, hid_keyboard_report_t *);
|
||||
// void screenlock_hotkey_handler(device_t *, hid_keyboard_report_t *);
|
||||
// void output_config_hotkey_handler(device_t *, hid_keyboard_report_t *);
|
||||
// void wipe_config_hotkey_handler(device_t *, hid_keyboard_report_t *);
|
||||
// void config_enable_hotkey_handler(device_t *, hid_keyboard_report_t *);
|
||||
// void enable_screensaver_hotkey_handler(device_t *, hid_keyboard_report_t *);
|
||||
// void disable_screensaver_hotkey_handler(device_t *, hid_keyboard_report_t *);
|
||||
|
||||
void handle_keyboard_uart_msg(uart_packet_t *, device_t *);
|
||||
void handle_mouse_abs_uart_msg(uart_packet_t *, device_t *);
|
||||
void handle_output_select_msg(uart_packet_t *, device_t *);
|
||||
void handle_mouse_zoom_msg(uart_packet_t *, device_t *);
|
||||
// void handle_mouse_zoom_msg(uart_packet_t *, device_t *);
|
||||
void handle_set_report_msg(uart_packet_t *, device_t *);
|
||||
void handle_switch_lock_msg(uart_packet_t *, device_t *);
|
||||
// void handle_switch_lock_msg(uart_packet_t *, device_t *);
|
||||
void handle_sync_borders_msg(uart_packet_t *, device_t *);
|
||||
void handle_flash_led_msg(uart_packet_t *, device_t *);
|
||||
void handle_fw_upgrade_msg(uart_packet_t *, device_t *);
|
||||
void handle_wipe_config_msg(uart_packet_t *, device_t *);
|
||||
// void handle_fw_upgrade_msg(uart_packet_t *, device_t *);
|
||||
// void handle_wipe_config_msg(uart_packet_t *, device_t *);
|
||||
void handle_consumer_control_msg(uart_packet_t *, device_t *);
|
||||
void handle_read_config_msg(uart_packet_t *, device_t *);
|
||||
void handle_save_config_msg(uart_packet_t *, device_t *);
|
||||
|
@ -567,9 +568,9 @@ void handle_proxy_msg(uart_packet_t *, device_t *);
|
|||
void handle_api_msgs(uart_packet_t *, device_t *);
|
||||
void handle_api_read_all_msg(uart_packet_t *, device_t *);
|
||||
void handle_toggle_gaming_msg(uart_packet_t *, device_t *);
|
||||
void handle_screensaver_msg(uart_packet_t *, device_t *);
|
||||
// void handle_screensaver_msg(uart_packet_t *, device_t *);
|
||||
|
||||
void switch_output(device_t *, uint8_t);
|
||||
void set_active_output(device_t *, uint8_t);
|
||||
|
||||
/********* Global variables (don't judge) **********/
|
||||
extern device_t global_state;
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
*
|
||||
* */
|
||||
|
||||
#define HOTKEY_TOGGLE HID_KEY_CAPS_LOCK
|
||||
#define HOTKEY_TOGGLE KEYBOARD_MODIFIER_RIGHTSHIFT
|
||||
|
||||
/**================================================== *
|
||||
* ============== Mouse Speed Factor ============== *
|
||||
|
@ -113,8 +113,8 @@
|
|||
*
|
||||
**/
|
||||
|
||||
#define SCREENSAVER_A_MODE DISABLED
|
||||
#define SCREENSAVER_B_MODE DISABLED
|
||||
// #define SCREENSAVER_A_MODE DISABLED
|
||||
// #define SCREENSAVER_B_MODE DISABLED
|
||||
|
||||
/**================================================== *
|
||||
*
|
||||
|
@ -123,8 +123,8 @@
|
|||
*
|
||||
**/
|
||||
|
||||
#define SCREENSAVER_A_IDLE_TIME_SEC 240
|
||||
#define SCREENSAVER_B_IDLE_TIME_SEC 240
|
||||
// #define SCREENSAVER_A_IDLE_TIME_SEC 240
|
||||
// #define SCREENSAVER_B_IDLE_TIME_SEC 240
|
||||
|
||||
/**================================================== *
|
||||
*
|
||||
|
@ -133,8 +133,8 @@
|
|||
*
|
||||
**/
|
||||
|
||||
#define SCREENSAVER_A_MAX_TIME_SEC 0
|
||||
#define SCREENSAVER_B_MAX_TIME_SEC 0
|
||||
// #define SCREENSAVER_A_MAX_TIME_SEC 0
|
||||
// #define SCREENSAVER_B_MAX_TIME_SEC 0
|
||||
|
||||
/**================================================== *
|
||||
*
|
||||
|
@ -143,8 +143,8 @@
|
|||
*
|
||||
**/
|
||||
|
||||
#define SCREENSAVER_A_ONLY_IF_INACTIVE 0
|
||||
#define SCREENSAVER_B_ONLY_IF_INACTIVE 0
|
||||
// #define SCREENSAVER_A_ONLY_IF_INACTIVE 0
|
||||
// #define SCREENSAVER_B_ONLY_IF_INACTIVE 0
|
||||
|
||||
/**================================================== *
|
||||
* ================ Output OS Config =============== *
|
||||
|
@ -160,8 +160,8 @@
|
|||
*
|
||||
* */
|
||||
|
||||
#define OUTPUT_A_OS MACOS
|
||||
#define OUTPUT_B_OS LINUX
|
||||
// #define OUTPUT_A_OS MACOS
|
||||
// #define OUTPUT_B_OS LINUX
|
||||
|
||||
|
||||
/**================================================== *
|
||||
|
|
138
src/keyboard.c
138
src/keyboard.c
|
@ -23,89 +23,89 @@
|
|||
|
||||
hotkey_combo_t hotkeys[] = {
|
||||
/* Main keyboard switching hotkey */
|
||||
{.modifier = KEYBOARD_MODIFIER_LEFTCTRL,
|
||||
{.modifier = KEYBOARD_MODIFIER_RIGHTCTRL,
|
||||
.keys = {HOTKEY_TOGGLE},
|
||||
.key_count = 1,
|
||||
.pass_to_os = false,
|
||||
.action_handler = &output_toggle_hotkey_handler},
|
||||
.action_handler = &output_toggle_hotkey_handler}};
|
||||
|
||||
/* Pressing right ALT + right CTRL toggles the slow mouse mode */
|
||||
{.modifier = KEYBOARD_MODIFIER_RIGHTALT | KEYBOARD_MODIFIER_RIGHTCTRL,
|
||||
.keys = {},
|
||||
.key_count = 0,
|
||||
.pass_to_os = true,
|
||||
.acknowledge = true,
|
||||
.action_handler = &mouse_zoom_hotkey_handler},
|
||||
// /* Pressing right ALT + right CTRL toggles the slow mouse mode */
|
||||
// {.modifier = KEYBOARD_MODIFIER_RIGHTALT | KEYBOARD_MODIFIER_RIGHTCTRL,
|
||||
// .keys = {},
|
||||
// .key_count = 0,
|
||||
// .pass_to_os = true,
|
||||
// .acknowledge = true,
|
||||
// .action_handler = &mouse_zoom_hotkey_handler},
|
||||
|
||||
/* Switch lock */
|
||||
{.modifier = KEYBOARD_MODIFIER_RIGHTCTRL,
|
||||
.keys = {HID_KEY_K},
|
||||
.key_count = 1,
|
||||
.acknowledge = true,
|
||||
.action_handler = &switchlock_hotkey_handler},
|
||||
// /* Switch lock */
|
||||
// {.modifier = KEYBOARD_MODIFIER_RIGHTCTRL,
|
||||
// .keys = {HID_KEY_K},
|
||||
// .key_count = 1,
|
||||
// .acknowledge = true,
|
||||
// .action_handler = &switchlock_hotkey_handler},
|
||||
|
||||
/* Screen lock */
|
||||
{.modifier = KEYBOARD_MODIFIER_RIGHTCTRL,
|
||||
.keys = {HID_KEY_L},
|
||||
.key_count = 1,
|
||||
.acknowledge = true,
|
||||
.action_handler = &screenlock_hotkey_handler},
|
||||
// /* Screen lock */
|
||||
// {.modifier = KEYBOARD_MODIFIER_RIGHTCTRL,
|
||||
// .keys = {HID_KEY_L},
|
||||
// .key_count = 1,
|
||||
// .acknowledge = true,
|
||||
// .action_handler = &screenlock_hotkey_handler},
|
||||
|
||||
/* Toggle gaming mode */
|
||||
{.modifier = KEYBOARD_MODIFIER_LEFTCTRL | KEYBOARD_MODIFIER_RIGHTSHIFT,
|
||||
.keys = {HID_KEY_G},
|
||||
.key_count = 1,
|
||||
.acknowledge = true,
|
||||
.action_handler = &toggle_gaming_mode_handler},
|
||||
// /* Toggle gaming mode */
|
||||
// {.modifier = KEYBOARD_MODIFIER_LEFTCTRL | KEYBOARD_MODIFIER_RIGHTSHIFT,
|
||||
// .keys = {HID_KEY_G},
|
||||
// .key_count = 1,
|
||||
// .acknowledge = true,
|
||||
// .action_handler = &toggle_gaming_mode_handler},
|
||||
|
||||
/* Enable screensaver for active output */
|
||||
{.modifier = KEYBOARD_MODIFIER_LEFTCTRL | KEYBOARD_MODIFIER_RIGHTSHIFT,
|
||||
.keys = {HID_KEY_S},
|
||||
.key_count = 1,
|
||||
.acknowledge = true,
|
||||
.action_handler = &enable_screensaver_hotkey_handler},
|
||||
// /* Enable screensaver for active output */
|
||||
// {.modifier = KEYBOARD_MODIFIER_LEFTCTRL | KEYBOARD_MODIFIER_RIGHTSHIFT,
|
||||
// .keys = {HID_KEY_S},
|
||||
// .key_count = 1,
|
||||
// .acknowledge = true,
|
||||
// .action_handler = &enable_screensaver_hotkey_handler},
|
||||
|
||||
/* Disable screensaver for active output */
|
||||
{.modifier = KEYBOARD_MODIFIER_LEFTCTRL | KEYBOARD_MODIFIER_RIGHTSHIFT,
|
||||
.keys = {HID_KEY_X},
|
||||
.key_count = 1,
|
||||
.acknowledge = true,
|
||||
.action_handler = &disable_screensaver_hotkey_handler},
|
||||
// /* Disable screensaver for active output */
|
||||
// {.modifier = KEYBOARD_MODIFIER_LEFTCTRL | KEYBOARD_MODIFIER_RIGHTSHIFT,
|
||||
// .keys = {HID_KEY_X},
|
||||
// .key_count = 1,
|
||||
// .acknowledge = true,
|
||||
// .action_handler = &disable_screensaver_hotkey_handler},
|
||||
|
||||
/* Erase stored config */
|
||||
{.modifier = KEYBOARD_MODIFIER_RIGHTSHIFT,
|
||||
.keys = {HID_KEY_F12, HID_KEY_D},
|
||||
.key_count = 2,
|
||||
.acknowledge = true,
|
||||
.action_handler = &wipe_config_hotkey_handler},
|
||||
// /* Erase stored config */
|
||||
// {.modifier = KEYBOARD_MODIFIER_RIGHTSHIFT,
|
||||
// .keys = {HID_KEY_F12, HID_KEY_D},
|
||||
// .key_count = 2,
|
||||
// .acknowledge = true,
|
||||
// .action_handler = &wipe_config_hotkey_handler},
|
||||
|
||||
/* Record switch y coordinate */
|
||||
{.modifier = KEYBOARD_MODIFIER_RIGHTSHIFT,
|
||||
.keys = {HID_KEY_F12, HID_KEY_Y},
|
||||
.key_count = 2,
|
||||
.acknowledge = true,
|
||||
.action_handler = &screen_border_hotkey_handler},
|
||||
// /* Record switch y coordinate */
|
||||
// {.modifier = KEYBOARD_MODIFIER_RIGHTSHIFT,
|
||||
// .keys = {HID_KEY_F12, HID_KEY_Y},
|
||||
// .key_count = 2,
|
||||
// .acknowledge = true,
|
||||
// .action_handler = &screen_border_hotkey_handler},
|
||||
|
||||
/* Switch to configuration mode */
|
||||
{.modifier = KEYBOARD_MODIFIER_LEFTCTRL | KEYBOARD_MODIFIER_RIGHTSHIFT,
|
||||
.keys = {HID_KEY_C, HID_KEY_O},
|
||||
.key_count = 2,
|
||||
.acknowledge = true,
|
||||
.action_handler = &config_enable_hotkey_handler},
|
||||
// /* Switch to configuration mode */
|
||||
// {.modifier = KEYBOARD_MODIFIER_LEFTCTRL | KEYBOARD_MODIFIER_RIGHTSHIFT,
|
||||
// .keys = {HID_KEY_C, HID_KEY_O},
|
||||
// .key_count = 2,
|
||||
// .acknowledge = true,
|
||||
// .action_handler = &config_enable_hotkey_handler},
|
||||
|
||||
/* Hold down left shift + right shift + F12 + A ==> firmware upgrade mode for board A (kbd) */
|
||||
{.modifier = KEYBOARD_MODIFIER_RIGHTSHIFT | KEYBOARD_MODIFIER_LEFTSHIFT,
|
||||
.keys = {HID_KEY_A},
|
||||
.key_count = 1,
|
||||
.acknowledge = true,
|
||||
.action_handler = &fw_upgrade_hotkey_handler_A},
|
||||
// /* Hold down left shift + right shift + F12 + A ==> firmware upgrade mode for board A (kbd) */
|
||||
// {.modifier = KEYBOARD_MODIFIER_RIGHTSHIFT | KEYBOARD_MODIFIER_LEFTSHIFT,
|
||||
// .keys = {HID_KEY_A},
|
||||
// .key_count = 1,
|
||||
// .acknowledge = true,
|
||||
// .action_handler = &fw_upgrade_hotkey_handler_A},
|
||||
|
||||
/* Hold down left shift + right shift + F12 + B ==> firmware upgrade mode for board B (mouse) */
|
||||
{.modifier = KEYBOARD_MODIFIER_RIGHTSHIFT | KEYBOARD_MODIFIER_LEFTSHIFT,
|
||||
.keys = {HID_KEY_B},
|
||||
.key_count = 1,
|
||||
.acknowledge = true,
|
||||
.action_handler = &fw_upgrade_hotkey_handler_B}};
|
||||
// /* Hold down left shift + right shift + F12 + B ==> firmware upgrade mode for board B (mouse) */
|
||||
// {.modifier = KEYBOARD_MODIFIER_RIGHTSHIFT | KEYBOARD_MODIFIER_LEFTSHIFT,
|
||||
// .keys = {HID_KEY_B},
|
||||
// .key_count = 1,
|
||||
// .acknowledge = true,
|
||||
// .action_handler = &fw_upgrade_hotkey_handler_B}};
|
||||
|
||||
/* ============================================================ *
|
||||
* Detect if any hotkeys were pressed
|
||||
|
|
|
@ -47,7 +47,7 @@ int main(void) {
|
|||
initial_setup(device);
|
||||
|
||||
// Initial state, A is the default output
|
||||
switch_output(device, OUTPUT_A);
|
||||
set_active_output(device, OUTPUT_A);
|
||||
|
||||
while (true) {
|
||||
for (int i = 0; i < NUM_TASKS; i++)
|
||||
|
@ -60,8 +60,8 @@ void core1_main() {
|
|||
[0] = {.exec = &usb_host_task, .frequency = _TOP()}, // .-> USB host task, needs to run as often as possible
|
||||
[1] = {.exec = &packet_receiver_task, .frequency = _TOP()}, // | Receive data over serial from the other board
|
||||
[2] = {.exec = &led_blinking_task, .frequency = _HZ(30)}, // | Check if LED needs blinking
|
||||
[3] = {.exec = &screensaver_task, .frequency = _HZ(120)}, // | Handle "screensaver" movements
|
||||
[4] = {.exec = &firmware_upgrade_task, .frequency = _HZ(4000)}, // | Send firmware to the other board if needed
|
||||
// [3] = {.exec = &screensaver_task, .frequency = _HZ(120)}, // | Handle "screensaver" movements
|
||||
// [4] = {.exec = &firmware_upgrade_task, .frequency = _HZ(4000)}, // | Send firmware to the other board if needed
|
||||
[5] = {.exec = &heartbeat_output_task, .frequency = _HZ(1)}, // | Output periodic heartbeats
|
||||
}; // `----- then go back and repeat forever
|
||||
const int NUM_TASKS = ARRAY_SIZE(tasks_core1);
|
||||
|
|
79
src/mouse.c
79
src/mouse.c
|
@ -20,6 +20,17 @@
|
|||
#define MACOS_SWITCH_MOVE_X 10
|
||||
#define MACOS_SWITCH_MOVE_COUNT 5
|
||||
|
||||
/* Check if our upcoming mouse movement would result in having to switch outputs */
|
||||
enum screen_pos_e is_screen_switch_needed(int position, int offset) {
|
||||
if (position + offset < MIN_SCREEN_COORD - global_state.config.jump_treshold)
|
||||
return LEFT;
|
||||
|
||||
if (position + offset > MAX_SCREEN_COORD + global_state.config.jump_treshold)
|
||||
return RIGHT;
|
||||
|
||||
return NONE;
|
||||
}
|
||||
|
||||
/* Move mouse coordinate 'position' by 'offset', but don't fall off the screen */
|
||||
int32_t move_and_keep_on_screen(int position, int offset) {
|
||||
/* Lowest we can go is 0 */
|
||||
|
@ -63,24 +74,30 @@ int32_t accelerate(int32_t offset) {
|
|||
return offset * acceleration[6].factor;
|
||||
}
|
||||
|
||||
void update_mouse_position(device_t *state, mouse_values_t *values) {
|
||||
/* Returns LEFT if need to jump left, RIGHT if right, NONE otherwise */
|
||||
enum screen_pos_e update_mouse_position(device_t *state, mouse_values_t *values) {
|
||||
output_t *current = &state->config.output[state->active_output];
|
||||
uint8_t reduce_speed = 0;
|
||||
|
||||
/* Check if we are configured to move slowly */
|
||||
if (state->mouse_zoom)
|
||||
reduce_speed = MOUSE_ZOOM_SCALING_FACTOR;
|
||||
// /* Check if we are configured to move slowly */
|
||||
// if (state->mouse_zoom)
|
||||
// reduce_speed = MOUSE_ZOOM_SCALING_FACTOR;
|
||||
|
||||
/* Calculate movement */
|
||||
int offset_x = accelerate(values->move_x) * (current->speed_x >> reduce_speed);
|
||||
int offset_y = accelerate(values->move_y) * (current->speed_y >> reduce_speed);
|
||||
|
||||
/* Determine if our upcoming movement would stay within the screen */
|
||||
enum screen_pos_e switch_direction = is_screen_switch_needed(state->pointer_x, offset_x);
|
||||
|
||||
/* Update movement */
|
||||
state->pointer_x = move_and_keep_on_screen(state->pointer_x, offset_x);
|
||||
state->pointer_y = move_and_keep_on_screen(state->pointer_y, offset_y);
|
||||
|
||||
/* Update buttons state */
|
||||
state->mouse_buttons = values->buttons;
|
||||
|
||||
return switch_direction;
|
||||
}
|
||||
|
||||
/* If we are active output, queue packet to mouse queue, else send them through UART */
|
||||
|
@ -124,7 +141,7 @@ int16_t scale_y_coordinate(int screen_from, int screen_to, device_t *state) {
|
|||
return ((state->pointer_y - from->border.top) * MAX_SCREEN_COORD) / size_from;
|
||||
}
|
||||
|
||||
void switch_screen(
|
||||
void switch_to_another_pc(
|
||||
device_t *state, output_t *output, int output_to, int direction) {
|
||||
uint8_t *mouse_park_pos = &state->config.output[state->active_output].mouse_park_pos;
|
||||
|
||||
|
@ -135,12 +152,12 @@ void switch_screen(
|
|||
mouse_report_t hidden_pointer = {.y = mouse_y, .x = MAX_SCREEN_COORD};
|
||||
|
||||
output_mouse_report(&hidden_pointer, state);
|
||||
switch_output(state, output_to);
|
||||
set_active_output(state, output_to);
|
||||
state->pointer_x = (direction == LEFT) ? MAX_SCREEN_COORD : MIN_SCREEN_COORD;
|
||||
state->pointer_y = scale_y_coordinate(output->number, 1 - output->number, state);
|
||||
}
|
||||
|
||||
void switch_desktop_macos(device_t *state, int direction) {
|
||||
void switch_virtual_desktop_macos(device_t *state, int direction) {
|
||||
/* Fix for MACOS: Send relative mouse movement here, one or two pixels in the
|
||||
direction of movement, BEFORE absolute report sets X to 0 */
|
||||
uint16_t move = (direction == LEFT) ? -MACOS_SWITCH_MOVE_X : MACOS_SWITCH_MOVE_X;
|
||||
|
@ -151,10 +168,10 @@ void switch_desktop_macos(device_t *state, int direction) {
|
|||
output_mouse_report(&move_relative_one, state);
|
||||
}
|
||||
|
||||
void switch_desktop(device_t *state, output_t *output, int new_index, int direction) {
|
||||
void switch_virtual_desktop(device_t *state, output_t *output, int new_index, int direction) {
|
||||
switch (output->os) {
|
||||
case MACOS:
|
||||
switch_desktop_macos(state, direction);
|
||||
switch_virtual_desktop_macos(state, direction);
|
||||
break;
|
||||
|
||||
case WINDOWS:
|
||||
|
@ -182,22 +199,21 @@ void switch_desktop(device_t *state, output_t *output, int new_index, int direct
|
|||
'---------' '---------' | '---------' '---------' '---------'
|
||||
)___( )___( | )___( )___( )___(
|
||||
*/
|
||||
void check_screen_switch(const mouse_values_t *values, device_t *state) {
|
||||
int new_x = state->pointer_x + values->move_x;
|
||||
void do_screen_switch(device_t *state, int direction) {
|
||||
output_t *output = &state->config.output[state->active_output];
|
||||
|
||||
bool jump_left = new_x < MIN_SCREEN_COORD - state->config.jump_treshold;
|
||||
bool jump_right = new_x > MAX_SCREEN_COORD + state->config.jump_treshold;
|
||||
// bool jump_left = new_x < MIN_SCREEN_COORD - state->config.jump_treshold;
|
||||
// bool jump_right = new_x > MAX_SCREEN_COORD + state->config.jump_treshold;
|
||||
|
||||
int direction = jump_left ? LEFT : RIGHT;
|
||||
// int direction = jump_left ? LEFT : RIGHT;
|
||||
|
||||
/* No switching allowed if explicitly disabled or in gaming mode */
|
||||
if (state->switch_lock || state->gaming_mode)
|
||||
return;
|
||||
// /* No switching allowed if explicitly disabled or in gaming mode */
|
||||
// if (state->switch_lock)
|
||||
// return;
|
||||
|
||||
/* No jump condition met == nothing to do, return */
|
||||
if (!jump_left && !jump_right)
|
||||
return;
|
||||
// if (!jump_left && !jump_right)
|
||||
// return;
|
||||
|
||||
/* We want to jump in the direction of the other computer */
|
||||
if (output->pos != direction) {
|
||||
|
@ -206,16 +222,16 @@ void check_screen_switch(const mouse_values_t *values, device_t *state) {
|
|||
if (state->mouse_buttons)
|
||||
return;
|
||||
|
||||
switch_screen(state, output, 1 - state->active_output, direction);
|
||||
switch_to_another_pc(state, output, 1 - state->active_output, direction);
|
||||
}
|
||||
/* If here, this output has multiple desktops and we are not on the main one */
|
||||
else
|
||||
switch_desktop(state, output, output->screen_index - 1, direction);
|
||||
switch_virtual_desktop(state, output, output->screen_index - 1, direction);
|
||||
}
|
||||
|
||||
/* We want to jump away from the other computer, only possible if there is another screen to jump to */
|
||||
else if (output->screen_index < output->screen_count)
|
||||
switch_desktop(state, output, output->screen_index + 1, direction);
|
||||
switch_virtual_desktop(state, output, output->screen_index + 1, direction);
|
||||
}
|
||||
|
||||
void extract_report_values(uint8_t *raw_report, device_t *state, mouse_values_t *values, hid_interface_t *iface) {
|
||||
|
@ -252,12 +268,12 @@ mouse_report_t create_mouse_report(device_t *state, mouse_values_t *values) {
|
|||
.mode = ABSOLUTE,
|
||||
};
|
||||
|
||||
/* Workaround for Windows multiple desktops */
|
||||
if (state->relative_mouse || state->gaming_mode) {
|
||||
mouse_report.x = values->move_x;
|
||||
mouse_report.y = values->move_y;
|
||||
mouse_report.mode = RELATIVE;
|
||||
}
|
||||
// /* Workaround for Windows multiple desktops */
|
||||
// if (state->relative_mouse || state->gaming_mode) {
|
||||
// mouse_report.x = values->move_x;
|
||||
// mouse_report.y = values->move_y;
|
||||
// mouse_report.mode = RELATIVE;
|
||||
// }
|
||||
|
||||
return mouse_report;
|
||||
}
|
||||
|
@ -270,7 +286,7 @@ void process_mouse_report(uint8_t *raw_report, int len, uint8_t itf, hid_interfa
|
|||
extract_report_values(raw_report, state, &values, iface);
|
||||
|
||||
/* Calculate and update mouse pointer movement. */
|
||||
update_mouse_position(state, &values);
|
||||
enum screen_pos_e switch_direction = update_mouse_position(state, &values);
|
||||
|
||||
/* Create the report for the output PC based on the updated values */
|
||||
mouse_report_t report = create_mouse_report(state, &values);
|
||||
|
@ -278,8 +294,9 @@ void process_mouse_report(uint8_t *raw_report, int len, uint8_t itf, hid_interfa
|
|||
/* Move the mouse, depending where the output is supposed to go */
|
||||
output_mouse_report(&report, state);
|
||||
|
||||
/* We use the mouse to switch outputs, the logic is in check_screen_switch() */
|
||||
check_screen_switch(&values, state);
|
||||
/* We use the mouse to switch outputs, if switch_direction is LEFT or RIGHT */
|
||||
if (switch_direction != NONE)
|
||||
do_screen_switch(state, switch_direction);
|
||||
}
|
||||
|
||||
/* ==================================================== *
|
||||
|
|
|
@ -14,15 +14,15 @@ const field_map_t api_field_map[] = {
|
|||
{ 13, false, INT32, 4, offsetof(device_t, config.output[0].speed_y) },
|
||||
{ 14, false, INT32, 4, offsetof(device_t, config.output[0].border.top) },
|
||||
{ 15, false, INT32, 4, offsetof(device_t, config.output[0].border.bottom) },
|
||||
{ 16, false, UINT8, 1, offsetof(device_t, config.output[0].os) },
|
||||
// { 16, false, UINT8, 1, offsetof(device_t, config.output[0].os) },
|
||||
{ 17, false, UINT8, 1, offsetof(device_t, config.output[0].pos) },
|
||||
{ 18, false, UINT8, 1, offsetof(device_t, config.output[0].mouse_park_pos) },
|
||||
{ 19, false, UINT8, 1, offsetof(device_t, config.output[0].screensaver.mode) },
|
||||
{ 20, false, UINT8, 1, offsetof(device_t, config.output[0].screensaver.only_if_inactive) },
|
||||
// { 19, false, UINT8, 1, offsetof(device_t, config.output[0].screensaver.mode) },
|
||||
// { 20, false, UINT8, 1, offsetof(device_t, config.output[0].screensaver.only_if_inactive) },
|
||||
|
||||
/* Until we increase the payload size from 8 bytes, clamp to avoid exceeding the field size */
|
||||
{ 21, false, UINT64, 7, offsetof(device_t, config.output[0].screensaver.idle_time_us) },
|
||||
{ 22, false, UINT64, 7, offsetof(device_t, config.output[0].screensaver.max_time_us) },
|
||||
// { 21, false, UINT64, 7, offsetof(device_t, config.output[0].screensaver.idle_time_us) },
|
||||
// { 22, false, UINT64, 7, offsetof(device_t, config.output[0].screensaver.max_time_us) },
|
||||
|
||||
/* Output B */
|
||||
{ 40, false, UINT32, 4, offsetof(device_t, config.output[1].number) },
|
||||
|
@ -31,13 +31,13 @@ const field_map_t api_field_map[] = {
|
|||
{ 43, false, INT32, 4, offsetof(device_t, config.output[1].speed_y) },
|
||||
{ 44, false, INT32, 4, offsetof(device_t, config.output[1].border.top) },
|
||||
{ 45, false, INT32, 4, offsetof(device_t, config.output[1].border.bottom) },
|
||||
{ 46, false, UINT8, 1, offsetof(device_t, config.output[1].os) },
|
||||
// { 46, false, UINT8, 1, offsetof(device_t, config.output[1].os) },
|
||||
{ 47, false, UINT8, 1, offsetof(device_t, config.output[1].pos) },
|
||||
{ 48, false, UINT8, 1, offsetof(device_t, config.output[1].mouse_park_pos) },
|
||||
{ 49, false, UINT8, 1, offsetof(device_t, config.output[1].screensaver.mode) },
|
||||
{ 50, false, UINT8, 1, offsetof(device_t, config.output[1].screensaver.only_if_inactive) },
|
||||
{ 51, false, UINT64, 7, offsetof(device_t, config.output[1].screensaver.idle_time_us) },
|
||||
{ 52, false, UINT64, 7, offsetof(device_t, config.output[1].screensaver.max_time_us) },
|
||||
// { 49, false, UINT8, 1, offsetof(device_t, config.output[1].screensaver.mode) },
|
||||
// { 50, false, UINT8, 1, offsetof(device_t, config.output[1].screensaver.only_if_inactive) },
|
||||
// { 51, false, UINT64, 7, offsetof(device_t, config.output[1].screensaver.idle_time_us) },
|
||||
// { 52, false, UINT64, 7, offsetof(device_t, config.output[1].screensaver.max_time_us) },
|
||||
|
||||
/* Common config */
|
||||
{ 70, false, UINT32, 4, offsetof(device_t, config.version) },
|
||||
|
@ -54,7 +54,7 @@ const field_map_t api_field_map[] = {
|
|||
{ 79, true, UINT32, 4, offsetof(device_t, _running_fw.checksum) },
|
||||
|
||||
{ 80, true, UINT8, 1, offsetof(device_t, keyboard_connected) },
|
||||
{ 81, true, UINT8, 1, offsetof(device_t, switch_lock) },
|
||||
// { 81, true, UINT8, 1, offsetof(device_t, switch_lock) },
|
||||
{ 82, true, UINT8, 1, offsetof(device_t, relative_mouse) },
|
||||
};
|
||||
|
||||
|
|
|
@ -81,7 +81,7 @@ int32_t tud_msc_write10_cb(uint8_t lun, uint32_t lba, uint32_t offset, uint8_t *
|
|||
global_state.fw.checksum = 0xffffffff;
|
||||
|
||||
/* Make sure nobody else touches the flash during this operation, otherwise we get empty pages */
|
||||
global_state.fw.upgrade_in_progress = true;
|
||||
// global_state.fw.upgrade_in_progress = true;
|
||||
}
|
||||
|
||||
/* Update checksum continuously as blocks are being received */
|
||||
|
|
184
src/tasks.c
184
src/tasks.c
|
@ -59,92 +59,92 @@ void usb_host_task(device_t *state) {
|
|||
tuh_task();
|
||||
}
|
||||
|
||||
mouse_report_t *screensaver_pong(device_t *state) {
|
||||
static mouse_report_t report = {0};
|
||||
static int dx = 20, dy = 25;
|
||||
// mouse_report_t *screensaver_pong(device_t *state) {
|
||||
// static mouse_report_t report = {0};
|
||||
// static int dx = 20, dy = 25;
|
||||
|
||||
/* Check if we are bouncing off the walls and reverse direction in that case. */
|
||||
if (report.x + dx < MIN_SCREEN_COORD || report.x + dx > MAX_SCREEN_COORD)
|
||||
dx = -dx;
|
||||
// /* Check if we are bouncing off the walls and reverse direction in that case. */
|
||||
// if (report.x + dx < MIN_SCREEN_COORD || report.x + dx > MAX_SCREEN_COORD)
|
||||
// dx = -dx;
|
||||
|
||||
if (report.y + dy < MIN_SCREEN_COORD || report.y + dy > MAX_SCREEN_COORD)
|
||||
dy = -dy;
|
||||
// if (report.y + dy < MIN_SCREEN_COORD || report.y + dy > MAX_SCREEN_COORD)
|
||||
// dy = -dy;
|
||||
|
||||
report.x += dx;
|
||||
report.y += dy;
|
||||
// report.x += dx;
|
||||
// report.y += dy;
|
||||
|
||||
return &report;
|
||||
}
|
||||
// return &report;
|
||||
// }
|
||||
|
||||
mouse_report_t *screensaver_jitter(device_t *state) {
|
||||
const int16_t jitter_distance = 2;
|
||||
static mouse_report_t report = {
|
||||
.y = jitter_distance,
|
||||
.mode = RELATIVE,
|
||||
};
|
||||
report.y = -report.y;
|
||||
// mouse_report_t *screensaver_jitter(device_t *state) {
|
||||
// const int16_t jitter_distance = 2;
|
||||
// static mouse_report_t report = {
|
||||
// .y = jitter_distance,
|
||||
// .mode = RELATIVE,
|
||||
// };
|
||||
// report.y = -report.y;
|
||||
|
||||
return &report;
|
||||
}
|
||||
// return &report;
|
||||
// }
|
||||
|
||||
/* Have something fun and entertaining when idle. */
|
||||
void screensaver_task(device_t *state) {
|
||||
const uint32_t delays[] = {
|
||||
0, /* DISABLED, unused index 0 */
|
||||
5000, /* PONG, move mouse every 5 ms for a high framerate */
|
||||
10000000, /* JITTER, once every 10 sec is more than enough */
|
||||
};
|
||||
static int last_pointer_move = 0;
|
||||
screensaver_t *screensaver = &state->config.output[BOARD_ROLE].screensaver;
|
||||
uint64_t inactivity_period = time_us_64() - state->last_activity[BOARD_ROLE];
|
||||
// /* Have something fun and entertaining when idle. */
|
||||
// void screensaver_task(device_t *state) {
|
||||
// const uint32_t delays[] = {
|
||||
// 0, /* DISABLED, unused index 0 */
|
||||
// 5000, /* PONG, move mouse every 5 ms for a high framerate */
|
||||
// 10000000, /* JITTER, once every 10 sec is more than enough */
|
||||
// };
|
||||
// static int last_pointer_move = 0;
|
||||
// screensaver_t *screensaver = &state->config.output[BOARD_ROLE].screensaver;
|
||||
// uint64_t inactivity_period = time_us_64() - state->last_activity[BOARD_ROLE];
|
||||
|
||||
/* If we're not enabled, nothing to do here. */
|
||||
if (screensaver->mode == DISABLED)
|
||||
return;
|
||||
// /* If we're not enabled, nothing to do here. */
|
||||
// if (screensaver->mode == DISABLED)
|
||||
// return;
|
||||
|
||||
/* System is still not idle for long enough to activate or screensaver mode is not supported */
|
||||
if (inactivity_period < screensaver->idle_time_us || screensaver->mode > MAX_SS_VAL)
|
||||
return;
|
||||
// /* System is still not idle for long enough to activate or screensaver mode is not supported */
|
||||
// if (inactivity_period < screensaver->idle_time_us || screensaver->mode > MAX_SS_VAL)
|
||||
// return;
|
||||
|
||||
/* We exceeded the maximum permitted screensaver runtime */
|
||||
if (screensaver->max_time_us
|
||||
&& inactivity_period > (screensaver->max_time_us + screensaver->idle_time_us))
|
||||
return;
|
||||
// /* We exceeded the maximum permitted screensaver runtime */
|
||||
// if (screensaver->max_time_us
|
||||
// && inactivity_period > (screensaver->max_time_us + screensaver->idle_time_us))
|
||||
// return;
|
||||
|
||||
/* If we're the selected output and we can only run on inactive output, nothing to do here. */
|
||||
if (screensaver->only_if_inactive && CURRENT_BOARD_IS_ACTIVE_OUTPUT)
|
||||
return;
|
||||
// /* If we're the selected output and we can only run on inactive output, nothing to do here. */
|
||||
// if (screensaver->only_if_inactive && CURRENT_BOARD_IS_ACTIVE_OUTPUT)
|
||||
// return;
|
||||
|
||||
/* We're active! Now check if it's time to move the cursor yet. */
|
||||
if (time_us_32() - last_pointer_move < delays[screensaver->mode])
|
||||
return;
|
||||
// /* We're active! Now check if it's time to move the cursor yet. */
|
||||
// if (time_us_32() - last_pointer_move < delays[screensaver->mode])
|
||||
// return;
|
||||
|
||||
mouse_report_t *report;
|
||||
switch (screensaver->mode) {
|
||||
case PONG:
|
||||
report = screensaver_pong(state);
|
||||
break;
|
||||
// mouse_report_t *report;
|
||||
// switch (screensaver->mode) {
|
||||
// case PONG:
|
||||
// report = screensaver_pong(state);
|
||||
// break;
|
||||
|
||||
case JITTER:
|
||||
report = screensaver_jitter(state);
|
||||
break;
|
||||
// case JITTER:
|
||||
// report = screensaver_jitter(state);
|
||||
// break;
|
||||
|
||||
default:
|
||||
return;
|
||||
}
|
||||
// default:
|
||||
// return;
|
||||
// }
|
||||
|
||||
/* Move mouse pointer */
|
||||
queue_mouse_report(report, state);
|
||||
// /* Move mouse pointer */
|
||||
// queue_mouse_report(report, state);
|
||||
|
||||
/* Update timer of the last pointer move */
|
||||
last_pointer_move = time_us_32();
|
||||
}
|
||||
// /* Update timer of the last pointer move */
|
||||
// last_pointer_move = time_us_32();
|
||||
// }
|
||||
|
||||
/* Periodically emit heartbeat packets */
|
||||
void heartbeat_output_task(device_t *state) {
|
||||
/* If firmware upgrade is in progress, don't touch flash_cs */
|
||||
if (state->fw.upgrade_in_progress)
|
||||
return;
|
||||
// if (state->fw.upgrade_in_progress)
|
||||
// return;
|
||||
|
||||
if (state->config_mode_active) {
|
||||
/* Leave config mode if timeout expired and user didn't click exit */
|
||||
|
@ -191,40 +191,40 @@ void process_hid_queue_task(device_t *state) {
|
|||
queue_try_remove(&state->hid_queue_out, &packet);
|
||||
}
|
||||
|
||||
/* Task that handles copying firmware from the other device to ours */
|
||||
void firmware_upgrade_task(device_t *state) {
|
||||
if (!state->fw.upgrade_in_progress || !state->fw.byte_done)
|
||||
return;
|
||||
// /* Task that handles copying firmware from the other device to ours */
|
||||
// void firmware_upgrade_task(device_t *state) {
|
||||
// if (!state->fw.upgrade_in_progress || !state->fw.byte_done)
|
||||
// return;
|
||||
|
||||
if (queue_is_full(&state->uart_tx_queue))
|
||||
return;
|
||||
// if (queue_is_full(&state->uart_tx_queue))
|
||||
// return;
|
||||
|
||||
/* End condition, when reached the process is completed. */
|
||||
if (state->fw.address > STAGING_IMAGE_SIZE) {
|
||||
state->fw.upgrade_in_progress = 0;
|
||||
state->fw.checksum = ~state->fw.checksum;
|
||||
// /* End condition, when reached the process is completed. */
|
||||
// if (state->fw.address > STAGING_IMAGE_SIZE) {
|
||||
// state->fw.upgrade_in_progress = 0;
|
||||
// state->fw.checksum = ~state->fw.checksum;
|
||||
|
||||
/* Checksum mismatch, we wipe the stage 2 bootloader and rely on ROM recovery */
|
||||
if(calculate_firmware_crc32() != state->fw.checksum) {
|
||||
flash_range_erase((uint32_t)ADDR_FW_RUNNING - XIP_BASE, FLASH_SECTOR_SIZE);
|
||||
reset_usb_boot(1 << PICO_DEFAULT_LED_PIN, 0);
|
||||
}
|
||||
// /* Checksum mismatch, we wipe the stage 2 bootloader and rely on ROM recovery */
|
||||
// if(calculate_firmware_crc32() != state->fw.checksum) {
|
||||
// flash_range_erase((uint32_t)ADDR_FW_RUNNING - XIP_BASE, FLASH_SECTOR_SIZE);
|
||||
// reset_usb_boot(1 << PICO_DEFAULT_LED_PIN, 0);
|
||||
// }
|
||||
|
||||
else {
|
||||
state->_running_fw = _firmware_metadata;
|
||||
global_state.reboot_requested = true;
|
||||
}
|
||||
}
|
||||
// else {
|
||||
// state->_running_fw = _firmware_metadata;
|
||||
// global_state.reboot_requested = true;
|
||||
// }
|
||||
// }
|
||||
|
||||
/* If we're on the last element of the current page, page is done - write it. */
|
||||
if (TU_U32_BYTE0(state->fw.address) == 0x00) {
|
||||
// /* If we're on the last element of the current page, page is done - write it. */
|
||||
// if (TU_U32_BYTE0(state->fw.address) == 0x00) {
|
||||
|
||||
uint32_t page_start_addr = (state->fw.address - 1) & 0xFFFFFF00;
|
||||
write_flash_page((uint32_t)ADDR_FW_RUNNING + page_start_addr - XIP_BASE, state->page_buffer);
|
||||
}
|
||||
// uint32_t page_start_addr = (state->fw.address - 1) & 0xFFFFFF00;
|
||||
// write_flash_page((uint32_t)ADDR_FW_RUNNING + page_start_addr - XIP_BASE, state->page_buffer);
|
||||
// }
|
||||
|
||||
request_byte(state, state->fw.address);
|
||||
}
|
||||
// request_byte(state, state->fw.address);
|
||||
// }
|
||||
|
||||
void packet_receiver_task(device_t *state) {
|
||||
uint32_t current_pointer
|
||||
|
|
12
src/uart.c
12
src/uart.c
|
@ -71,17 +71,17 @@ const uart_handler_t uart_handler[] = {
|
|||
{.type = OUTPUT_SELECT_MSG, .handler = handle_output_select_msg},
|
||||
|
||||
/* Box control */
|
||||
{.type = MOUSE_ZOOM_MSG, .handler = handle_mouse_zoom_msg},
|
||||
// {.type = MOUSE_ZOOM_MSG, .handler = handle_mouse_zoom_msg},
|
||||
{.type = KBD_SET_REPORT_MSG, .handler = handle_set_report_msg},
|
||||
{.type = SWITCH_LOCK_MSG, .handler = handle_switch_lock_msg},
|
||||
// {.type = SWITCH_LOCK_MSG, .handler = handle_switch_lock_msg},
|
||||
{.type = SYNC_BORDERS_MSG, .handler = handle_sync_borders_msg},
|
||||
{.type = FLASH_LED_MSG, .handler = handle_flash_led_msg},
|
||||
{.type = GAMING_MODE_MSG, .handler = handle_toggle_gaming_msg},
|
||||
// {.type = GAMING_MODE_MSG, .handler = handle_toggle_gaming_msg},
|
||||
{.type = CONSUMER_CONTROL_MSG, .handler = handle_consumer_control_msg},
|
||||
{.type = SCREENSAVER_MSG, .handler = handle_screensaver_msg},
|
||||
// {.type = SCREENSAVER_MSG, .handler = handle_screensaver_msg},
|
||||
|
||||
/* Config */
|
||||
{.type = WIPE_CONFIG_MSG, .handler = handle_wipe_config_msg},
|
||||
// {.type = WIPE_CONFIG_MSG, .handler = handle_wipe_config_msg},
|
||||
{.type = SAVE_CONFIG_MSG, .handler = handle_save_config_msg},
|
||||
{.type = REBOOT_MSG, .handler = handle_reboot_msg},
|
||||
{.type = GET_VAL_MSG, .handler = handle_api_msgs},
|
||||
|
@ -91,7 +91,7 @@ const uart_handler_t uart_handler[] = {
|
|||
/* Firmware */
|
||||
{.type = REQUEST_BYTE_MSG, .handler = handle_request_byte_msg},
|
||||
{.type = RESPONSE_BYTE_MSG, .handler = handle_response_byte_msg},
|
||||
{.type = FIRMWARE_UPGRADE_MSG, .handler = handle_fw_upgrade_msg},
|
||||
// {.type = FIRMWARE_UPGRADE_MSG, .handler = handle_fw_upgrade_msg},
|
||||
|
||||
{.type = HEARTBEAT_MSG, .handler = handle_heartbeat_msg},
|
||||
{.type = PROXY_PACKET_MSG, .handler = handle_proxy_msg},
|
||||
|
|
14
src/utils.c
14
src/utils.c
|
@ -59,11 +59,11 @@ uint32_t calculate_firmware_crc32(void) {
|
|||
* Flash and config functions
|
||||
* ================================================== */
|
||||
|
||||
void wipe_config(void) {
|
||||
uint32_t ints = save_and_disable_interrupts();
|
||||
flash_range_erase((uint32_t)ADDR_CONFIG - XIP_BASE, FLASH_SECTOR_SIZE);
|
||||
restore_interrupts(ints);
|
||||
}
|
||||
// void wipe_config(void) {
|
||||
// uint32_t ints = save_and_disable_interrupts();
|
||||
// flash_range_erase((uint32_t)ADDR_CONFIG - XIP_BASE, FLASH_SECTOR_SIZE);
|
||||
// restore_interrupts(ints);
|
||||
// }
|
||||
|
||||
void write_flash_page(uint32_t target_addr, uint8_t *buffer) {
|
||||
/* Start of sector == first 256-byte page in a 4096 byte block */
|
||||
|
@ -150,7 +150,7 @@ void request_byte(device_t *state, uint32_t address) {
|
|||
.data32[0] = address,
|
||||
.type = REQUEST_BYTE_MSG,
|
||||
};
|
||||
state->fw.byte_done = false;
|
||||
// state->fw.byte_done = false;
|
||||
|
||||
queue_try_add(&global_state.uart_tx_queue, &packet);
|
||||
}
|
||||
|
@ -197,7 +197,7 @@ bool validate_packet(uart_packet_t *packet) {
|
|||
GET_VAL_MSG,
|
||||
GET_ALL_VALS_MSG,
|
||||
SET_VAL_MSG,
|
||||
WIPE_CONFIG_MSG,
|
||||
// WIPE_CONFIG_MSG,
|
||||
SAVE_CONFIG_MSG,
|
||||
REBOOT_MSG,
|
||||
PROXY_PACKET_MSG,
|
||||
|
|
Loading…
Reference in New Issue