C++ file for display control
Dependencies: 4DGL mbed ConfigFile
Fork of 4DGLtest by
Diff: keyboard.cpp
- Revision:
- 9:311b6676272d
- Parent:
- 8:dd258f9e24b0
- Child:
- 10:5706b75d40fa
--- a/keyboard.cpp Wed Jul 09 07:52:00 2014 +0000 +++ b/keyboard.cpp Fri Jul 11 11:08:02 2014 +0000 @@ -2,6 +2,10 @@ #include "mbed.h" #include "keyboard.h" +const int CDU_KB_ADRS = 0x68; //Base addrees TCA8418 keypad scanner +const int ACK = 0x00; +const int NACK = 0x01; + extern int key_hit_ID; //extern mbos CDU_OS; @@ -22,17 +26,68 @@ void CDU_KB_COMM_INIT() { //initialize communication with TCA84818 - CDU_I2C.write(CDU_KB_WRITE); //initiate write cycle - //intialize all registers from TCA8418 here - CDU_I2C.read(CDU_KB_READ); //start reading from TCA4818 + char cmd[2]; + cmd[0] = REG_CFG; //pointer byte to CFG register + cmd[1] = 0x01; //data for CFG register KE_IEN set to 1 + if ( CDU_I2C.write(CDU_KB_ADRS,cmd, 2) == ACK ) //initiate write cycle and check for ACK + { + //intialize all registers from TCA8418 here + cmd[0] = REG_INT_STAT; //pointer byte to Interrupt Status Register + cmd[1] = 0x01; //Reset KE-INT flag + CDU_I2C.write(CDU_KB_ADRS,cmd, 2 ); //Write to Interrupt Status Register from TCA4818 + + //Set TCA8418 to Keypad mode + cmd[0]=REG_KP_GPIO1; //KP_GIO1 + cmd[1]=0xFF; //Set to Keypad mode + CDU_I2C.write(CDU_KB_ADRS,cmd, 2); + + cmd[0]=REG_KP_GPIO2; //KP_GIO2 + cmd[1]=0xFF; //Set to Keypad mode + CDU_I2C.write(CDU_KB_ADRS,cmd, 2); + + cmd[0]=REG_KP_GPIO3; //KP_GIO3 + cmd[1]=0xFF; //Set to Keypad mode + CDU_I2C.write(CDU_KB_ADRS,cmd, 2); + + } + else + { + //No response from TCA8418 keyboard chip + FAIL = 1; //Switch on FAIL indicator + } } void CDU_KB_GET_KEY() { - CDU_I2C.write(CDU_KB_READ); //initiate read cycle - key_hit_ID = CDU_I2C.read(CDU_KB_READ) ; //read key value + EXEC = 1;//flash EXEC leds when key pressed.... + wait( 0.1 ); + EXEC = 0; + + char cmd[2]; + + //Read interrupt status flag + cmd[0] = REG_INT_STAT; //pointer byte to Interrupt Status Register + CDU_I2C.write(CDU_KB_ADRS, cmd, 1); //initiate read cycle + CDU_I2C.read(CDU_KB_ADRS, cmd, 1); //read key value + + //Read Key Lock and Event Counter + cmd[0] = REG_KEY_LCK_EC; //pointer byte KEY_LCK_EC + CDU_I2C.write(CDU_KB_ADRS, cmd, 1); //initiate read cycle + CDU_I2C.read(CDU_KB_ADRS, cmd, 1); //read key value + + //Keypress --> read data from keybuffer + cmd[0] = REG_KEY_EVENT_A; //pointer to Key Event Register KEY_EVENT_A + CDU_I2C.write(CDU_KB_ADRS, cmd, 1); //initiate read cycle + CDU_I2C.read(CDU_KB_ADRS, cmd, 2); //read key value (=2 words) + + //Reset interrupt flag + cmd[0] = REG_INT_STAT; //pointer byte to Interrupt Status Register + cmd[1] = 0x01; //Reset KE-INT flag + CDU_I2C.write(CDU_KB_ADRS,cmd, 2 ); + //CDU_OS.SetEvent(KEY_EVENT,SEND_KEYMESSAGE_TASK_ID ); //Set event key to wakeup task - } + +} void CDU_KB_INT_START() { @@ -67,7 +122,15 @@ case 255: { //calculate percentage from potmeter value - BGL_LED = ( 0.0 + 100*BGL_POT ); + if ( BGL_POT < 0.01 ) + { + BGL_LED = 0.0; //prevents flickering when low intensity + } + else + { + BGL_LED = BGL_POT; + } } } } +