-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
146 lines (113 loc) · 4.61 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*******************************************************************************
Copyright 2015 Microchip Technology Inc. (www.microchip.com)
Modifications 2015 Omar Andrés Trevizo Rascón
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
To request to license the code under the MLA license (www.microchip.com/mla_license),
please contact mla_licensing@microchip.com
*******************************************************************************/
/** INCLUDES *******************************************************/
#include <system.h>
#include <system_config.h>
#include <usb.h>
#include <usb_device_hid.h>
#include <app_device_custom_hid.h>
#include <ModeSelect.h>
asm("goto 0x100"); //start address on program memory for ModeSelect function
MAIN_RETURN main(void)
{
//This is only to declare MS_Psect, if not it will not compile.
if(0)
{
ModeSelect();//This function never gets called by C code
}
SYSTEM_Initialize(SYSTEM_STATE_USB_START);
USBDeviceInit();
USBDeviceAttach();
IPR1 = 0; //All others interrupt sources will be Low priority
IPR2 = 32; //USB interrupt is High priority
RCONbits.IPEN = 1; //Enabling interrupt priority
ADCON1bits.PCFG = 0x0F; //By default all I/O digital
CMCONbits.CM = 7; //Comparators off by default
while(1)
{
SYSTEM_Tasks();
#if defined(USB_POLLING)
// Interrupt or polling method. If using polling, must call
// this function periodically. This function will take care
// of processing and responding to SETUP transactions
// (such as during the enumeration process when you first
// plug in). USB hosts require that USB devices should accept
// and process SETUP packets in a timely fashion. Therefore,
// when using polling, this function should be called
// regularly (such as once every 1.8ms or faster** [see
// inline code comments in usb_device.c for explanation when
// "or faster" applies]) In most cases, the USBDeviceTasks()
// function does not take very long to execute (ex: <100
// instruction cycles) before it returns.
USBDeviceTasks();
#endif
/* If the USB device isn't configured yet, we can't really do anything
* else since we don't have a host to talk to. So jump back to the
* top of the while loop. */
if( USBGetDeviceState() < CONFIGURED_STATE )
{
/* Jump back to the top of the while loop. */
continue;
}
/* If we are currently suspended, then we need to see if we need to
* issue a remote wakeup. In either case, we shouldn't process any
* keyboard commands since we aren't currently communicating to the host
* thus just continue back to the start of the while loop. */
if( USBIsDeviceSuspended() == true )
{
/* Jump back to the top of the while loop. */
continue;
}
//Application specific tasks
APP_DeviceCustomHIDTasks();
}//end while
}//end main
bool USER_USB_CALLBACK_EVENT_HANDLER(USB_EVENT event, void *pdata, uint16_t size)
{
switch((int)event)
{
case EVENT_TRANSFER:
break;
case EVENT_SOF://MODDED
break;
case EVENT_SUSPEND://MODDED
break;
case EVENT_RESUME://MODDED
break;
case EVENT_CONFIGURED:
/* When the device is configured, we can (re)initialize the demo
* code. */
APP_DeviceCustomHIDInitialize();
break;
case EVENT_SET_DESCRIPTOR:
break;
case EVENT_EP0_REQUEST:
/* We have received a non-standard USB request. The HID driver
* needs to check to see if the request was for it. */
USBCheckHIDRequest();
break;
case EVENT_BUS_ERROR:
break;
case EVENT_TRANSFER_TERMINATED:
break;
default:
break;
}
return true;
}
/*******************************************************************************
End of File
*/