]> git.donarmstrong.com Git - kiibohd-controller.git/blobdiff - Scan/Tandy1000/scan_loop.c
Merge branch 'master' of github.com:kiibohd/controller
[kiibohd-controller.git] / Scan / Tandy1000 / scan_loop.c
index 519dd92905f8c37f9c3f6f2f45e01f99f6e00c26..828875001946c737bc66c9bb9a5b3926c93cd88e 100644 (file)
@@ -1,15 +1,15 @@
-/* Copyright (C) 2011 by Jacob Alexander
- * 
+/* Copyright (C) 2011,2014 by Jacob Alexander
+ *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
  * in the Software without restriction, including without limitation the rights
  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  * copies of the Software, and to permit persons to whom the Software is
  * furnished to do so, subject to the following conditions:
- * 
+ *
  * The above copyright notice and this permission notice shall be included in
  * all copies or substantial portions of the Software.
- * 
+ *
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -21,8 +21,8 @@
 
 // ----- Includes -----
 
-// AVR Includes
-#include <avr/interrupt.h>
+// Compiler Includes
+#include <Lib/ScanLib.h>
 
 // Project Includes
 #include <led.h>
@@ -53,6 +53,7 @@
 
 
 // ----- Macros -----
+
 #define READ_CLK       CLK_READ &   (1 <<  CLK_PIN) ? 1 : 0
 #define READ_DATA     DATA_READ &   (1 << DATA_PIN) ? 0 : 1
 
 
 // ----- Variables -----
 
-uint8_t KeyIndex_Array[KEYBOARD_SIZE + 1];
+// Buffer used to inform the macro processing module which keys have been detected as pressed
+volatile uint8_t KeyIndex_Buffer[KEYBOARD_BUFFER];
+volatile uint8_t KeyIndex_BufferUsed;
+
 
 // Scan Code Retrieval Variables
 uint8_t inputData    = 0xFF;
@@ -74,8 +78,14 @@ uint8_t packet_index = 0;
 // ----- Functions -----
 
 // Setup
-inline void scan_setup()
+inline void Scan_setup()
 {
+       // Initially reset the keyboard (just in case we are in a wierd state)
+       Scan_resetKeyboard();
+
+       // Setup SPI for data input using the clock and data inputs
+       // TODO
+       /*
        // Setup inputs
        CLK_DDR  &= ~(1 << CLK_PIN);
        DATA_DDR &= ~(1 << DATA_PIN);
@@ -83,27 +93,19 @@ inline void scan_setup()
        // Setup Pull-up's
        CLK_PORT  &= ~(1 << CLK_PIN);  // (CLK)
        DATA_PORT &= ~(1 << DATA_PIN); // (/DATA)
+       */
 
        // Setup Keyboard Interrupt
        INTR_DDR  &= ~(1 << INTR_PIN);
        INTR_PORT &= ~(1 << INTR_PIN);
 
-       /* Interrupt Style (Not working fully)
-       cli();
-       // Setup interrupt on the CLK pin TODO Better defines
-       EICRA |= 0x03; // Rising Edge Interrupt
-       EIMSK |= (1 << INT0);
-
-       // Setup interrupt on the DATA pin TODO Better defines
-       EICRA |= 0x08; // Falling Edge Interrupt
-       EIMSK |= (1 << INT1);
-       sei();
-       */
+       // Setup Keyboard Reset Line
+       // TODO
 }
 
 
 // Main Detection Loop
-inline uint8_t scan_loop()
+inline uint8_t Scan_loop()
 {
        /*
        // Packet Read
@@ -145,6 +147,8 @@ inline uint8_t scan_loop()
        // Disable keyboard interrupt (does nothing if already off)
        UNSET_INTR();
 
+       /* XXX OLD CODE - Somewhat worked, has glitches, and is not compatible with the current API
+
        // Read the clock 8 times
        if ( READ_CLK )
        {
@@ -206,34 +210,48 @@ inline uint8_t scan_loop()
                while ( READ_CLK );
        }
 
+       */
+
        // Interrupt keyboard if there is no pending packet
        SET_INTR();
 
        return packet_index;
 }
 
-// Detection interrupt, signalled by a clock pulse from CLK_PIN
-ISR(INT0_vect)
+// Send data
+// XXX Not used with the Tandy1000
+uint8_t Scan_sendData( uint8_t dataPayload )
 {
-       //cli(); // Disable Interrupts
-
-       // Append 1 bit of data
-       //inputData &= ~(READ_DATA << packet_index);
-       packet_index++;
+       return 0;
+}
 
-       //sei(); // Re-enable Interrupts
+// Signal KeyIndex_Buffer that it has been properly read
+// TODO
+void Scan_finishedWithBuffer( uint8_t sentKeys )
+{
 }
 
-// Data Detected
-ISR(INT1_vect)
+// Signal that the keys have been properly sent over USB
+void Scan_finishedWithUSBBuffer( uint8_t sentKeys )
 {
-       // Append 1 bit of data
-       inputData &= ~(1 << packet_index);
-       packet_index++;
+}
 
-       // Disable Clk Signal (Not needed if there's a data signal)
-       EIFR |= (1 << INTF0);
+// Reset/Hold keyboard
+// Warning! This will cause the keyboard to not send any data, so you can't disable with a keypress
+// The Tandy 1000 keyboard has a dedicated hold/processor interrupt line
+void Scan_lockKeyboard( void )
+{
+       UNSET_INTR();
 }
 
+void Scan_unlockKeyboard( void )
+{
+       SET_INTR();
+}
 
+// Reset Keyboard
+void Scan_resetKeyboard( void )
+{
+       // TODO Tandy1000 has a dedicated reset line
+}