summaryrefslogtreecommitdiff
path: root/protocol/usb_hid/main.cpp
blob: c292d458e21069804b0ffa6d18c182fcec5b18f3 (plain)
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
#include <util/delay.h>
#include <Arduino.h>
#include "Usb.h"
#include "hid.h"
#include "hidboot.h"
#include "parser.h"


USB     Usb;
HIDBoot<HID_PROTOCOL_KEYBOARD>    kbd(&Usb);
KBDReportParser Prs;

void usb_disable()
{
    USBCON &= ~(1<<VBUSTI);
    UDIEN = 0;
    USBINT = 0;
    UDINT = 0;
    UDCON |= (1<<DETACH);
    USBCON &= ~(1<<USBE);
    PLLCSR = 0;
    UHWCON &= ~(1<<UVREGE);
    USBCON &= ~(1<<OTGPADE);
}

void setup()
{
    usb_disable();

    // RX LED for debug
    DDRB |= (1<<0);

    Serial.begin( 115200 );
    while (!Serial) ;

    delay( 1000 );

    Serial.println("Start");

    if (Usb.Init() == -1) {
        Serial.println("OSC did not start.");
    }
      
    delay( 200 );
  
    kbd.SetReportParser(0, (HIDReportParser*)&Prs);
}

void loop()
{
    Usb.Task();
}

int main(void)
{
    // arduino/wiring.c(Timer initialize)
    init();

    setup();
    
    for (;;) {
        loop();
    }
        
    return 0;
}