main.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. Bluefruit Protocol for TMK firmware
  3. Author: Benjamin Gould, 2013
  4. Based on code Copyright 2011 Jun Wako <wakojun@gmail.com>
  5. This program is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include <stdint.h>
  17. #include <avr/interrupt.h>
  18. #include <avr/wdt.h>
  19. #include <avr/sleep.h>
  20. #include <util/delay.h>
  21. #include "../serial.h"
  22. #include "keyboard.h"
  23. #include "host.h"
  24. #include "timer.h"
  25. #include "print.h"
  26. #include "debug.h"
  27. #include "sendchar.h"
  28. #include "suspend.h"
  29. #include "bluefruit.h"
  30. #define CPU_PRESCALE(n) (CLKPR = 0x80, CLKPR = (n))
  31. int main(void) {
  32. CPU_PRESCALE(0);
  33. // DDRD = _BV(PD5);
  34. // DDRB = _BV(PB0);
  35. // PORTD = _BV(PD5);
  36. // PORTB = _BV(PB0);
  37. print_set_sendchar(sendchar);
  38. keyboard_setup();
  39. dprintf("Initializing keyboard...\n");
  40. keyboard_init();
  41. dprintf("Setting host driver to bluefruit...\n");
  42. host_set_driver(bluefruit_driver());
  43. dprintf("Initializing serial...\n");
  44. serial_init();
  45. // char swpa[] = "+++\r\n";
  46. // for (int i = 0; i < 5; i++) {
  47. // serial_send(swpa[i]);
  48. // }
  49. // char ble_enable[] = "AT+BLEKEYBOARDEN=1\r\n";
  50. // for (int i = 0; i < 20; i++) {
  51. // serial_send(ble_enable[i]);
  52. // }
  53. // char reset[] = "ATZ\r\n";
  54. // for (int i = 0; i < 5; i++) {
  55. // serial_send(reset[i]);
  56. // }
  57. // for (int i = 0; i < 5; i++) {
  58. // serial_send(swpa[i]);
  59. // }
  60. // wait an extra second for the PC's operating system
  61. // to load drivers and do whatever it does to actually
  62. // be ready for input
  63. _delay_ms(1000);
  64. // PORTD = ~_BV(PD5);
  65. dprintf("Starting main loop");
  66. while (1) {
  67. keyboard_task();
  68. }
  69. }