KSM edits to RA8875

Dependents:   Liz_Test_Code

Revision:
71:dcac8efd842d
Parent:
68:ab08efabfc88
Child:
72:ecffe56af969
--- a/RA8875.cpp	Sun Aug 31 15:58:15 2014 +0000
+++ b/RA8875.cpp	Sat Oct 04 17:45:50 2014 +0000
@@ -238,6 +238,52 @@
 }
 // #### end of touch panel code additions
 
+
+RetCode_t RA8875::KeypadInit(bool scanEnable, bool longDetect, uint8_t sampleTime, uint8_t scanFrequency, 
+    uint8_t longTimeAdjustment, bool interruptEnable, bool wakeupEnable)
+{
+    uint8_t value = 0;
+    
+    if (sampleTime > 3 || scanFrequency > 7 || longTimeAdjustment  > 3)
+        return bad_parameter;
+    value |= (scanEnable) ? 0x80 : 0x00;
+    value |= (longDetect) ? 0x40 : 0x00;
+    value |= (sampleTime & 0x03) << 4;
+    value |= (scanFrequency & 0x07);
+    WriteCommand(0xC0, value);   // Enable Key Scan (and ignore possibility of an error)
+    
+    value = 0;
+    value |= (wakeupEnable) ? 0x80 : 0x00;
+    value |= (longTimeAdjustment & 0x03) << 2;
+    WriteCommand(0xC1, value);  // (and ignore possibility of an error)
+    
+    value = ReadCommand(0xF0);  // (and ignore possibility of an error)
+    value &= ~0x10;
+    value |= (interruptEnable) ? 0x10 : 0x00;
+    return WriteCommand(0xF0, value);
+}
+
+bool RA8875::_kbhit(void)
+{
+    return (ReadCommand(0xF1) & 0x10);  // check KS status - true if kbhit
+}
+
+uint8_t RA8875::_getch(void)
+{
+    while (!_kbhit()) {
+        wait_us(POLLWAITuSec);
+        COUNTIDLETIME(POLLWAITuSec);
+    }
+
+    // read the key press number
+    uint8_t keyNumReg = ReadCommand(0xC1) & 0x03;
+    // read the key code
+    uint8_t keyCode = ReadCommand(0xC2 + keyNumReg);
+    // Clear KS status
+    WriteCommand(0xF1, 0x10);
+    return keyCode;
+}
+
 #ifdef PERF_METRICS
 void RA8875::ClearPerformance()
 {