2024-01-21 08:45:22 +08:00
|
|
|
/*
|
2024-01-03 17:48:34 +08:00
|
|
|
* This file is part of DeskHop (https://github.com/hrvach/deskhop).
|
|
|
|
* Copyright (c) 2024 Hrvoje Cavrak
|
2024-01-21 08:45:22 +08:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
2024-01-03 17:48:34 +08:00
|
|
|
* the Free Software Foundation, version 3.
|
|
|
|
*
|
2024-01-21 08:45:22 +08:00
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2024-01-03 17:48:34 +08:00
|
|
|
* General Public License for more details.
|
|
|
|
*
|
2024-01-21 08:45:22 +08:00
|
|
|
* You should have received a copy of the GNU General Public License
|
2024-01-03 17:48:34 +08:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2023-12-25 06:22:05 +08:00
|
|
|
#include "main.h"
|
|
|
|
|
|
|
|
/********* Global Variable **********/
|
2024-01-21 08:45:22 +08:00
|
|
|
device_t global_state = {0};
|
|
|
|
device_t *device = &global_state;
|
2023-12-25 06:22:05 +08:00
|
|
|
|
|
|
|
/**================================================== *
|
|
|
|
* ============== Main Program Loops ============== *
|
|
|
|
* ================================================== */
|
|
|
|
|
2024-01-28 05:38:46 +08:00
|
|
|
int main(void) {
|
2023-12-25 06:22:05 +08:00
|
|
|
// Wait for the board to settle
|
|
|
|
sleep_ms(10);
|
|
|
|
|
2024-01-03 17:48:34 +08:00
|
|
|
// Initial board setup
|
2024-01-21 08:45:22 +08:00
|
|
|
initial_setup(device);
|
2023-12-25 06:22:05 +08:00
|
|
|
|
|
|
|
// Initial state, A is the default output
|
2024-01-21 08:45:22 +08:00
|
|
|
switch_output(device, OUTPUT_A);
|
|
|
|
|
2023-12-25 06:22:05 +08:00
|
|
|
while (true) {
|
|
|
|
// USB device task, needs to run as often as possible
|
|
|
|
tud_task();
|
|
|
|
|
|
|
|
// Verify core1 is still running and if so, reset watchdog timer
|
2024-01-21 08:45:22 +08:00
|
|
|
kick_watchdog(device);
|
2024-01-03 17:48:34 +08:00
|
|
|
|
|
|
|
// Check if there were any keypresses and send them
|
2024-01-21 08:45:22 +08:00
|
|
|
process_kbd_queue_task(device);
|
2024-01-03 17:48:34 +08:00
|
|
|
|
|
|
|
// Check if there were any mouse movements and send them
|
2024-01-21 08:45:22 +08:00
|
|
|
process_mouse_queue_task(device);
|
2023-12-25 06:22:05 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void core1_main() {
|
|
|
|
uart_packet_t in_packet = {0};
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
// Update the timestamp, so core0 can figure out if we're dead
|
2024-01-21 08:45:22 +08:00
|
|
|
device->core1_last_loop_pass = time_us_64();
|
2023-12-25 06:22:05 +08:00
|
|
|
|
2024-01-03 17:48:34 +08:00
|
|
|
// USB host task, needs to run as often as possible
|
2024-01-17 01:38:24 +08:00
|
|
|
if (tuh_inited())
|
2024-01-06 07:21:01 +08:00
|
|
|
tuh_task();
|
2024-01-03 17:48:34 +08:00
|
|
|
|
|
|
|
// Receives data over serial from the other board
|
2024-01-21 08:45:22 +08:00
|
|
|
receive_char(&in_packet, device);
|
2024-01-17 01:38:24 +08:00
|
|
|
|
|
|
|
// Check if LED needs blinking
|
2024-01-21 08:45:22 +08:00
|
|
|
led_blinking_task(device);
|
|
|
|
|
|
|
|
// Mouse screensaver task
|
|
|
|
screensaver_task(device);
|
2023-12-25 06:22:05 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ======= End of Main Program Loops ======= */
|