]> git.donarmstrong.com Git - qmk_firmware.git/blobdiff - tmk_core/common/keyboard.c
Add sidebar for ZH (#4533)
[qmk_firmware.git] / tmk_core / common / keyboard.c
index fd2cf74f57b0a6502e874f0dee7fcea1e116ddc1..a6a5fb56b16ea2e54be672b8fc47f1c80cd4feea 100644 (file)
@@ -66,6 +66,12 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #ifdef POINTING_DEVICE_ENABLE
 #   include "pointing_device.h"
 #endif
+#ifdef MIDI_ENABLE
+#   include "process_midi.h"
+#endif
+#ifdef HD44780_ENABLE
+#   include "hd44780.h"
+#endif
 
 #ifdef MATRIX_HAS_GHOST
 extern const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS];
@@ -114,19 +120,44 @@ static inline bool has_ghost_in_row(uint8_t row, matrix_row_t rowdata)
 
 #endif
 
+void disable_jtag(void) {
+// To use PORTF disable JTAG with writing JTD bit twice within four cycles.
+#if (defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__) || defined(__AVR_ATmega32U4__))
+    MCUCR |= _BV(JTD);
+    MCUCR |= _BV(JTD);
+#endif
+}
+
+/** \brief matrix_setup
+ *
+ * FIXME: needs doc
+ */
 __attribute__ ((weak))
 void matrix_setup(void) {
 }
 
+/** \brief keyboard_setup
+ *
+ * FIXME: needs doc
+ */
 void keyboard_setup(void) {
+    disable_jtag();
     matrix_setup();
 }
 
+/** \brief is_keyboard_master
+ *
+ * FIXME: needs doc
+ */
 __attribute__((weak))
 bool is_keyboard_master(void) {
     return true;
 }
 
+/** \brief keyboard_init
+ *
+ * FIXME: needs doc
+ */
 void keyboard_init(void) {
     timer_init();
     matrix_init();
@@ -164,8 +195,16 @@ void keyboard_init(void) {
 #endif
 }
 
-/*
- * Do keyboard routine jobs: scan mantrix, light LEDs, ...
+/** \brief Keyboard task: Do keyboard routine jobs
+ *
+ * Do routine keyboard jobs:
+ *
+ * * scan matrix
+ * * handle mouse movements
+ * * run visualizer code
+ * * handle midi commands
+ * * light LEDs
+ *
  * This is repeatedly called as fast as possible.
  */
 void keyboard_task(void)
@@ -177,6 +216,9 @@ void keyboard_task(void)
     static uint8_t led_status = 0;
     matrix_row_t matrix_row = 0;
     matrix_row_t matrix_change = 0;
+#ifdef QMK_KEYS_PER_SCAN
+    uint8_t keys_processed = 0;
+#endif
 
     matrix_scan();
     if (is_keyboard_master()) {
@@ -208,6 +250,10 @@ void keyboard_task(void)
                         });
                         // record a processed key
                         matrix_prev[r] ^= ((matrix_row_t)1<<c);
+#ifdef QMK_KEYS_PER_SCAN
+                        // only jump out if we have processed "enough" keys.
+                        if (++keys_processed >= QMK_KEYS_PER_SCAN)
+#endif
                         // process a key per task call
                         goto MATRIX_LOOP_END;
                     }
@@ -216,6 +262,10 @@ void keyboard_task(void)
         }
     }
     // call with pseudo tick event when no real key event.
+#ifdef QMK_KEYS_PER_SCAN
+    // we can get here with some keys processed now.
+    if (!keys_processed)
+#endif
     action_exec(TICK);
 
 MATRIX_LOOP_END:
@@ -249,6 +299,10 @@ MATRIX_LOOP_END:
     pointing_device_task();
 #endif
 
+#ifdef MIDI_ENABLE
+    midi_task();
+#endif
+
     // update LED
     if (led_status != host_keyboard_leds()) {
         led_status = host_keyboard_leds();
@@ -256,6 +310,10 @@ MATRIX_LOOP_END:
     }
 }
 
+/** \brief keyboard set leds
+ *
+ * FIXME: needs doc
+ */
 void keyboard_set_leds(uint8_t leds)
 {
     if (debug_keyboard) { debug("keyboard_set_led: "); debug_hex8(leds); debug("\n"); }