-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.c
94 lines (66 loc) · 2.2 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
This file is part of PICoBoot.
Copyright (C) 2021 ReimuNotMoe <[email protected]>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <PICoBoot/PICoBoot.h>
void CDC_RxDone(void *userp, uint8_t *buf, uint16_t len) {
PicoBoot_Protocol_ParseIncomingData(buf, len);
}
USBDeluxeDevice_CDC_ACM_IOps cdc_iops = {
.RxDone = CDC_RxDone
};
void DataLedTask() {
static uint16_t osc_count = 0;
const static uint16_t osc1 = 111;
const static uint16_t osc2 = 112;
osc_count += 1;
if (osc_count > (osc1 * osc2 * 2 - 1)) {
osc_count = 0;
}
uint8_t osc1_on = (osc_count / osc1) % 2;
uint8_t osc2_on = (osc_count / osc2) % 2;
PICoBoot_LED_1 = (osc1_on ^ osc2_on);
}
USBDeluxeDevice_CDCACMContext cdc_ctx = {0};
int main() {
PICoBoot_Board_PinInitialize();
if (RCONbits.POR) {
RCONbits.POR = 0;
} else {
PICoBoot_RuntimeEnvironment_Load();
picoboot_runtime_env.reset_count++;
picoboot_runtime_env.boot_reason = BootReason_RESET;
if (RCONbits.WDTO) {
RCONbits.WDTO = 0;
picoboot_runtime_env.boot_reason = BootReason_WDT;
picoboot_runtime_env.watchdog_failed_count++;
}
}
PICoBoot_StaticEnvironment_Load();
int boot_action = PICoBoot_Board_Reset_Action();
PICoBoot_RuntimeEnvironment_Save();
if (boot_action == ResetAction_RunUserApp) {
PicoBoot_StartUserApp(PICoBoot_App_Address);
} else {
PICoBoot_Board_SystemInitialize();
USBDeluxeDevice_CDC_ACM_Create(&cdc_ctx, NULL, 0, 1, 1, 2, &cdc_iops);
USBDeluxe_Device_Init();
while (1) {
PicoBoot_Tasks();
USBDeviceTasks();
USBDeluxe_Device_Tasks();
DataLedTask();
}
}
return 1;
}