2 Bluefruit Protocol for TMK firmware
3 Author: Benjamin Gould, 2013
4 Based on code Copyright 2011 Jun Wako <wakojun@gmail.com>
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.
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.
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/>.
21 #include <avr/interrupt.h>
23 #include <avr/sleep.h>
24 #include <util/delay.h>
25 #include "../serial.h"
34 #include "bluefruit.h"
37 #define CPU_PRESCALE(n) (CLKPR = 0x80, CLKPR = (n))
39 #define HOST_DRIVER_NOT_SET 0
40 #define BLUEFRUIT_HOST_DRIVER 1
41 #define PJRC_HOST_DRIVER 2
55 print_set_sendchar(sendchar);
59 // while (!usb_configured()) /* wait */
64 dprintf("Initializing keyboard...\n");
67 // This implementation is pretty simplistic... if the USB connection
68 // is not configured, choose the Bluefruit, otherwise use USB
69 // Definitely would prefer to have this driven by an input pin and make
70 // it switch dynamically - BCG
71 // if (!usb_configured()) {
73 // // Send power to Bluefruit... Adafruit says it takes 27 mA, I think
74 // // the pins should provide 40 mA, but just in case I switch the
75 // // Bluefruit using a transistor - BCG
79 dprintf("Setting host driver to bluefruit...\n");
80 host_set_driver(bluefruit_driver());
82 dprintf("Initializing serial...\n");
85 // char swpa[] = "+++\r\n";
86 // for (int i = 0; i < 5; i++) {
87 // serial_send(swpa[i]);
90 // char ble_enable[] = "AT+BLEKEYBOARDEN=1\r\n";
91 // for (int i = 0; i < 20; i++) {
92 // serial_send(ble_enable[i]);
95 // char reset[] = "ATZ\r\n";
96 // for (int i = 0; i < 5; i++) {
97 // serial_send(reset[i]);
100 // for (int i = 0; i < 5; i++) {
101 // serial_send(swpa[i]);
104 // wait an extra second for the PC's operating system
105 // to load drivers and do whatever it does to actually
106 // be ready for input
108 // PORTD = ~_BV(PD5);
109 dprintf("Starting main loop");
116 // // I'm not smart enough to get this done with LUFA - BCG
117 // dprintf("Setting host driver to PJRC...\n");
118 // host_set_driver(pjrc_driver());
119 // #ifdef SLEEP_LED_ENABLE
122 // // wait an extra second for the PC's operating system
123 // // to load drivers and do whatever it does to actually
124 // // be ready for input
126 // PORTB = ~_BV(PB0);
127 // dprintf("Starting main loop");
130 // suspend_power_down();
131 // if (remote_wakeup && suspend_wakeup_condition()) {
132 // usb_remote_wakeup();