]> git.friedersdorff.com Git - max/tmk_keyboard.git/blobdiff - keyboard.c
added copyright and license notice.
[max/tmk_keyboard.git] / keyboard.c
index 25948ddf7198681449bdfe61c74576d4aa129761..9bba409f1d41e8c137652a9483a40ff4e1815c7e 100644 (file)
@@ -1,7 +1,23 @@
+/*
+Copyright 2011 Jun Wako <wakojun@gmail.com>
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
 #include "keyboard.h"
 #include "host.h"
 #include "layer.h"
-#include "matrix_skel.h"
+#include "matrix.h"
 #include "led.h"
 #include "usb_keycodes.h"
 #include "timer.h"
@@ -11,6 +27,9 @@
 #ifdef MOUSEKEY_ENABLE
 #include "mousekey.h"
 #endif
+#ifdef USB_EXTRA_ENABLE
+#include <util/delay.h>
+#endif
 
 
 static uint8_t last_leds = 0;
@@ -28,6 +47,9 @@ void keyboard_init(void)
 void keyboard_proc(void)
 {
     uint8_t fn_bits = 0;
+#ifdef USB_EXTRA_ENABLE
+    uint16_t consumer_code = 0;
+#endif
 
     matrix_scan();
 
@@ -61,29 +83,69 @@ void keyboard_proc(void)
                 fn_bits |= FN_BIT(code);
             }
 #ifdef USB_EXTRA_ENABLE
-/* TODO: use new API
-            // audio control & system control
-            else if (code == KB_MUTE) {
-                usb_extra_audio_send(AUDIO_MUTE);
-                usb_extra_audio_send(0);
-                _delay_ms(500);
-            } else if (code == KB_VOLU) {
-                usb_extra_audio_send(AUDIO_VOL_UP);
-                usb_extra_audio_send(0);
-                _delay_ms(200);
-            } else if (code == KB_VOLD) {
-                usb_extra_audio_send(AUDIO_VOL_DOWN);
-                usb_extra_audio_send(0);
-                _delay_ms(200);
-            } else if (code == KB_PWR) {
+            // System Control
+            else if (code == KB_SYSTEM_POWER) {
+#ifdef HOST_PJRC
                 if (suspend && remote_wakeup) {
                     usb_remote_wakeup();
                 } else {
-                    usb_extra_system_send(SYSTEM_POWER_DOWN);
+                    host_system_send(SYSTEM_POWER_DOWN);
                 }
-                _delay_ms(1000);
+#else
+                host_system_send(SYSTEM_POWER_DOWN);
+#endif
+                host_system_send(0);
+                _delay_ms(500);
+            } else if (code == KB_SYSTEM_SLEEP) {
+                host_system_send(SYSTEM_SLEEP);
+                host_system_send(0);
+                _delay_ms(500);
+            } else if (code == KB_SYSTEM_WAKE) {
+                host_system_send(SYSTEM_WAKE_UP);
+                host_system_send(0);
+                _delay_ms(500);
+            }
+            // Consumer Page
+            else if (code == KB_AUDIO_MUTE) {
+                consumer_code = AUDIO_MUTE;
+            } else if (code == KB_AUDIO_VOL_UP) {
+                consumer_code = AUDIO_VOL_UP;
+            } else if (code == KB_AUDIO_VOL_DOWN) {
+                consumer_code = AUDIO_VOL_DOWN;
+            }
+            else if (code == KB_MEDIA_NEXT_TRACK) {
+                consumer_code = TRANSPORT_NEXT_TRACK;
+            } else if (code == KB_MEDIA_PREV_TRACK) {
+                consumer_code = TRANSPORT_PREV_TRACK;
+            } else if (code == KB_MEDIA_STOP) {
+                consumer_code = TRANSPORT_STOP;
+            } else if (code == KB_MEDIA_PLAY_PAUSE) {
+                consumer_code = TRANSPORT_PLAY_PAUSE;
+            } else if (code == KB_MEDIA_SELECT) {
+                consumer_code = AL_CC_CONFIG;
+            }
+            else if (code == KB_MAIL) {
+                consumer_code = AL_EMAIL;
+            } else if (code == KB_CALCULATOR) {
+                consumer_code = AL_CALCULATOR;
+            } else if (code == KB_MY_COMPUTER) {
+                consumer_code = AL_LOCAL_BROWSER;
+            }
+            else if (code == KB_WWW_SEARCH) {
+                consumer_code = AC_SEARCH;
+            } else if (code == KB_WWW_HOME) {
+                consumer_code = AC_HOME;
+            } else if (code == KB_WWW_BACK) {
+                consumer_code = AC_BACK;
+            } else if (code == KB_WWW_FORWARD) {
+                consumer_code = AC_FORWARD;
+            } else if (code == KB_WWW_STOP) {
+                consumer_code = AC_STOP;
+            } else if (code == KB_WWW_REFRESH) {
+                consumer_code = AC_REFRESH;
+            } else if (code == KB_WWW_FAVORITES) {
+                consumer_code = AC_BOOKMARKS;
             }
-*/
 #endif
             else if (IS_KEY(code)) {
                 host_add_key(code);
@@ -102,13 +164,15 @@ void keyboard_proc(void)
     layer_switching(fn_bits);
 
     if (command_proc()) {
-        // not send report
         return;
     }
 
     // TODO: should send only when changed from last report
     if (matrix_is_modified()) {
         host_send_keyboard_report();
+#ifdef USB_EXTRA_ENABLE
+        host_consumer_send(consumer_code);
+#endif
 #ifdef DEBUG_LED
         // LED flash for debug
         DEBUG_LED_CONFIG;