upload
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
このリポジトリはアーカイブされています。 ファイルの閲覧とクローンは可能ですが、プッシュや、課題・プルリクエストのオープンはできません。

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. Bluefruit Protocol for TMK firmware
  3. Author: Benjamin Gould, 2013
  4. Based on code Copyright 2011 Jun Wako <[email protected]>
  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 "usb.h"
  24. #include "host.h"
  25. #include "timer.h"
  26. #include "print.h"
  27. #include "debug.h"
  28. #include "sendchar.h"
  29. #include "suspend.h"
  30. #include "bluefruit.h"
  31. #include "pjrc.h"
  32. #define CPU_PRESCALE(n) (CLKPR = 0x80, CLKPR = (n))
  33. #define HOST_DRIVER_NOT_SET 0
  34. #define BLUEFRUIT_HOST_DRIVER 1
  35. #define PJRC_HOST_DRIVER 2
  36. int main(void)
  37. {
  38. CPU_PRESCALE(0);
  39. // DDRD = _BV(PD5);
  40. // DDRB = _BV(PB0);
  41. // PORTD = _BV(PD5);
  42. // PORTB = _BV(PB0);
  43. print_set_sendchar(sendchar);
  44. // usb_init();
  45. // _delay_ms(2000);
  46. // while (!usb_configured()) /* wait */
  47. dprintf("Initializing keyboard...\n");
  48. keyboard_init();
  49. // This implementation is pretty simplistic... if the USB connection
  50. // is not configured, choose the Bluefruit, otherwise use USB
  51. // Definitely would prefer to have this driven by an input pin and make
  52. // it switch dynamically - BCG
  53. // if (!usb_configured()) {
  54. // // Send power to Bluefruit... Adafruit says it takes 27 mA, I think
  55. // // the pins should provide 40 mA, but just in case I switch the
  56. // // Bluefruit using a transistor - BCG
  57. // DDRB = _BV(PB6);
  58. // PORTB |= _BV(PB6);
  59. dprintf("Setting host driver to bluefruit...\n");
  60. host_set_driver(bluefruit_driver());
  61. dprintf("Initializing serial...\n");
  62. serial_init();
  63. // char swpa[] = "+++\r\n";
  64. // for (int i = 0; i < 5; i++) {
  65. // serial_send(swpa[i]);
  66. // }
  67. // char ble_enable[] = "AT+BLEKEYBOARDEN=1\r\n";
  68. // for (int i = 0; i < 20; i++) {
  69. // serial_send(ble_enable[i]);
  70. // }
  71. // char reset[] = "ATZ\r\n";
  72. // for (int i = 0; i < 5; i++) {
  73. // serial_send(reset[i]);
  74. // }
  75. // for (int i = 0; i < 5; i++) {
  76. // serial_send(swpa[i]);
  77. // }
  78. // wait an extra second for the PC's operating system
  79. // to load drivers and do whatever it does to actually
  80. // be ready for input
  81. _delay_ms(1000);
  82. // PORTD = ~_BV(PD5);
  83. dprintf("Starting main loop");
  84. while (1) {
  85. keyboard_task();
  86. }
  87. // } else {
  88. // // I'm not smart enough to get this done with LUFA - BCG
  89. // dprintf("Setting host driver to PJRC...\n");
  90. // host_set_driver(pjrc_driver());
  91. // #ifdef SLEEP_LED_ENABLE
  92. // sleep_led_init();
  93. // #endif
  94. // // wait an extra second for the PC's operating system
  95. // // to load drivers and do whatever it does to actually
  96. // // be ready for input
  97. // _delay_ms(1000);
  98. // PORTB = ~_BV(PB0);
  99. // dprintf("Starting main loop");
  100. // while (1) {
  101. // while (suspend) {
  102. // suspend_power_down();
  103. // if (remote_wakeup && suspend_wakeup_condition()) {
  104. // usb_remote_wakeup();
  105. // }
  106. // }
  107. // keyboard_task();
  108. // }
  109. // }
  110. }