]> git.donarmstrong.com Git - qmk_firmware.git/blob - keyboards/sirius/unigo66/main.c
[Keyboard] UniGo66 keyboard added (#4913)
[qmk_firmware.git] / keyboards / sirius / unigo66 / main.c
1 #include <avr/io.h>
2 #include <avr/wdt.h>
3 #include <avr/power.h>
4 #include <util/delay.h>
5
6 // LUFA
7 #include "lufa.h"
8
9 #include "sendchar.h"
10 #include "debug.h"
11 #include "keyboard.h"
12 #include "led.h"
13
14
15 /* LED ping configuration */
16 #define TMK_LED
17 //#define LEONARDO_LED
18 #if defined(TMK_LED)
19 // For TMK converter and Teensy
20 #define LED_TX_INIT    (DDRD  |=  (1<<6))
21 #define LED_TX_ON      (PORTD |=  (1<<6))
22 #define LED_TX_OFF     (PORTD &= ~(1<<6))
23 #define LED_TX_TOGGLE  (PORTD ^=  (1<<6))
24 #elif defined(LEONARDO_LED)
25 // For Leonardo(TX LED)
26 #define LED_TX_INIT    (DDRD  |=  (1<<5))
27 #define LED_TX_ON      (PORTD &= ~(1<<5))
28 #define LED_TX_OFF     (PORTD |=  (1<<5))
29 #define LED_TX_TOGGLE  (PORTD ^=  (1<<5))
30 #else
31 #define LED_TX_INIT
32 #define LED_TX_ON
33 #define LED_TX_OFF
34 #define LED_TX_TOGGLE
35 #endif
36
37
38 static void LUFA_setup(void)
39 {
40     /* Disable watchdog if enabled by bootloader/fuses */
41     MCUSR &= ~(1 << WDRF);
42     wdt_disable();
43
44     /* Disable clock division */
45 #if (F_CPU == 8000000)
46     clock_prescale_set(clock_div_2);    // 16MHz crystal divided by 2
47 #else
48     clock_prescale_set(clock_div_1);
49 #endif
50
51     // Leonardo needs. Without this USB device is not recognized.
52     USB_Disable();
53
54     USB_Init();
55
56     // for Console_Task
57     USB_Device_EnableSOFEvents();
58     print_set_sendchar(sendchar);
59 }
60
61
62
63 int main(void)
64 {
65     // LED for debug
66     LED_TX_INIT;
67     LED_TX_ON;
68
69     debug_enable = true;
70     debug_keyboard = true;
71
72     host_set_driver(&lufa_driver);
73     keyboard_init();
74
75     LUFA_setup();
76
77     /* NOTE: Don't insert time consuming job here.
78      * It'll cause unclear initialization failure when DFU reset(worm start).
79      */
80     sei();
81
82 /* Some keyboards bootup quickly and cannot be initialized with this startup wait.*/
83     // wait for startup of sendchar routine
84     while (USB_DeviceState != DEVICE_STATE_Configured) ;
85     if (debug_enable) {
86         _delay_ms(1000);
87     }
88
89
90 /*  // wait for USB startup & debug output
91     uint8_t timeout=255
92     while (timeout-- && USB_DeviceState != DEVICE_STATE_Configured) {
93     wait_ms(4);
94 */
95
96     debug("init: done\n");
97
98     for (;;) {
99         keyboard_task();
100
101 #if !defined(INTERRUPT_CONTROL_ENDPOINT)
102         // LUFA Task for control request
103         USB_USBTask();
104 #endif
105     }
106
107     return 0;
108 }