]> git.donarmstrong.com Git - qmk_firmware.git/blob - tmk_core/protocol/bluefruit/main.c
Merge pull request #1915 from dondelelcaro/ergodox_ez_left_leds
[qmk_firmware.git] / tmk_core / protocol / bluefruit / main.c
1 /*
2 Bluefruit Protocol for TMK firmware
3 Author: Benjamin Gould, 2013
4 Based on code Copyright 2011 Jun Wako <wakojun@gmail.com>
5
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include <stdint.h>
21 #include <avr/interrupt.h>
22 #include <avr/wdt.h>
23 #include <avr/sleep.h>
24 #include <util/delay.h>
25 #include "../serial.h"
26 #include "keyboard.h"
27 #include "usb.h"
28 #include "host.h"
29 #include "timer.h"
30 #include "print.h"
31 #include "debug.h"
32 #include "sendchar.h"
33 #include "suspend.h"
34 #include "bluefruit.h"
35 #include "pjrc.h"
36
37 #define CPU_PRESCALE(n)    (CLKPR = 0x80, CLKPR = (n))
38
39 #define HOST_DRIVER_NOT_SET     0
40 #define BLUEFRUIT_HOST_DRIVER   1
41 #define PJRC_HOST_DRIVER        2
42
43
44 int main(void)
45 {   
46
47     CPU_PRESCALE(0);
48
49     // DDRD  = _BV(PD5);
50     // DDRB  = _BV(PB0);
51     
52     // PORTD = _BV(PD5);
53     // PORTB = _BV(PB0);
54
55     print_set_sendchar(sendchar);
56
57     // usb_init();
58     // _delay_ms(2000);
59     // while (!usb_configured()) /* wait */
60
61
62
63     dprintf("Initializing keyboard...\n");
64     keyboard_init();
65     
66     // This implementation is pretty simplistic... if the USB connection
67     // is not configured, choose the Bluefruit, otherwise use USB
68     // Definitely would prefer to have this driven by an input pin and make
69     // it switch dynamically - BCG
70     // if (!usb_configured()) {
71     
72     //     // Send power to Bluefruit... Adafruit says it takes 27 mA, I think
73     //     // the pins should provide 40 mA, but just in case I switch the 
74     //     // Bluefruit using a transistor - BCG
75     //     DDRB   = _BV(PB6);
76     //     PORTB |= _BV(PB6);
77     
78         dprintf("Setting host driver to bluefruit...\n");
79         host_set_driver(bluefruit_driver());
80
81         dprintf("Initializing serial...\n");
82         serial_init();
83
84     // char swpa[] = "+++\r\n";
85     // for (int i = 0; i < 5; i++) {
86     //     serial_send(swpa[i]);
87     // }
88
89     // char ble_enable[] = "AT+BLEKEYBOARDEN=1\r\n";
90     // for (int i = 0; i < 20; i++) {
91     //     serial_send(ble_enable[i]);
92     // }
93
94     // char reset[] = "ATZ\r\n";
95     // for (int i = 0; i < 5; i++) {
96     //     serial_send(reset[i]);
97     // }
98
99     // for (int i = 0; i < 5; i++) {
100     //     serial_send(swpa[i]);
101     // }
102
103         // wait an extra second for the PC's operating system
104         // to load drivers and do whatever it does to actually
105         // be ready for input
106         _delay_ms(1000);
107         // PORTD = ~_BV(PD5);
108         dprintf("Starting main loop");
109         while (1) {
110             keyboard_task();
111         }
112
113 //     } else {
114
115 //         // I'm not smart enough to get this done with LUFA - BCG
116 //         dprintf("Setting host driver to PJRC...\n");
117 //         host_set_driver(pjrc_driver());
118 // #ifdef SLEEP_LED_ENABLE
119 //     sleep_led_init();
120 // #endif
121 //         // wait an extra second for the PC's operating system
122 //         // to load drivers and do whatever it does to actually
123 //         // be ready for input
124 //         _delay_ms(1000);
125 //         PORTB = ~_BV(PB0);
126 //         dprintf("Starting main loop");
127 //         while (1) {
128 //             while (suspend) {
129 //                 suspend_power_down();
130 //                 if (remote_wakeup && suspend_wakeup_condition()) {
131 //                     usb_remote_wakeup();
132 //                 }
133 //             }
134 //             keyboard_task(); 
135 //         }
136 //     }
137
138 }