aboutsummaryrefslogtreecommitdiff
path: root/keyboards/converter/usb_usb/main.c
diff options
context:
space:
mode:
authorAkshay <[email protected]>2022-04-10 12:13:40 +0100
committerAkshay <[email protected]>2022-04-10 12:13:40 +0100
commitdc90387ce7d8ba7b607d9c48540bf6d8b560f14d (patch)
tree4ccb8fa5886b66fa9d480edef74236c27f035e16 /keyboards/converter/usb_usb/main.c
Diffstat (limited to 'keyboards/converter/usb_usb/main.c')
-rw-r--r--keyboards/converter/usb_usb/main.c102
1 files changed, 102 insertions, 0 deletions
diff --git a/keyboards/converter/usb_usb/main.c b/keyboards/converter/usb_usb/main.c
new file mode 100644
index 000000000..76e88922c
--- /dev/null
+++ b/keyboards/converter/usb_usb/main.c
@@ -0,0 +1,102 @@
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
38static 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
63int 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 debug("init: done\n");
91
92 for (;;) {
93 keyboard_task();
94
95#if !defined(INTERRUPT_CONTROL_ENDPOINT)
96 // LUFA Task for control request
97 USB_USBTask();
98#endif
99 }
100
101 return 0;
102}