00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef __MSNP_H__
00013 #define __MSNP_H__
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #pragma systemFile
00036
00037 #ifndef __COMMON_H__
00038 #include "common.h"
00039 #endif
00040
00041 #define MSNP_I2C_ADDR 0xB4
00042 #define MSNP_DATA_REG 0x00
00043
00044 tByteArray MSNP_I2CRequest;
00045 tByteArray MSNP_I2CReply;
00046
00047
00048 #define KEY_STATUS_REG 0x00
00049
00050 const unsigned byte MSNP_KeyMap[] = { '#', '9', '6', '3', '0', '8', '2', '5', '*', '7', '1', '4' };
00051 const signed byte MSNP_NumMap[] = { -1, 9, 6, 3, 0, 8, 2, 5, -2, 7, 1, 4};
00052
00053 const unsigned byte MSNP_ConfigGroup1[] = {10, MSNP_I2C_ADDR, 0x2B, 0x01, 0x01, 0x00, 0x00, 0x01, 0x01, 0xFF, 0x02};
00054 const unsigned byte MSNP_ConfigGroup2[] = {16, MSNP_I2C_ADDR, 0x41, 0x0F, 0x0A, 0x0F, 0x0A, 0x0F, 0x0A, 0x0F, 0x0A, 0x0F, 0x0A, 0x0F, 0x0A, 0x0F, 0x0A};
00055 const unsigned byte MSNP_ConfigGroup3[] = {14, MSNP_I2C_ADDR, 0x4F, 0x0F, 0x0A, 0x0F, 0x0A, 0x0F, 0x0A, 0x0F, 0x0A, 0x0F, 0x0A, 0x0F, 0x0A};
00056 const unsigned byte MSNP_ConfigGroup4[] = { 5, MSNP_I2C_ADDR, 0x5C, 0x0B, 0x20, 0x0C};
00057 const unsigned byte MSNP_ConfigGroup5[] = { 3, MSNP_I2C_ADDR, 0x7B, 0x0B};
00058 const unsigned byte MSNP_ConfigGroup6[] = { 5, MSNP_I2C_ADDR, 0x7D, 0x9C, 0x65, 0x8C};
00059
00060 bool _MSNPinitialised[] = {false, false, false, false};
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070 bool _MSNPinit(tSensors link) {
00071
00072
00073 memcpy(MSNP_I2CRequest, MSNP_ConfigGroup1, sizeof(MSNP_ConfigGroup1));
00074 if (!writeI2C(link, MSNP_I2CRequest))
00075 return false;
00076
00077 memcpy(MSNP_I2CRequest, MSNP_ConfigGroup2, sizeof(MSNP_ConfigGroup2));
00078 if (!writeI2C(link, MSNP_I2CRequest))
00079 return false;
00080
00081 memcpy(MSNP_I2CRequest, MSNP_ConfigGroup3, sizeof(MSNP_ConfigGroup3));
00082 if (!writeI2C(link, MSNP_I2CRequest))
00083 return false;
00084
00085 memcpy(MSNP_I2CRequest, MSNP_ConfigGroup4, sizeof(MSNP_ConfigGroup4));
00086 if (!writeI2C(link, MSNP_I2CRequest))
00087 return false;
00088
00089 memcpy(MSNP_I2CRequest, MSNP_ConfigGroup5, sizeof(MSNP_ConfigGroup5));
00090 if (!writeI2C(link, MSNP_I2CRequest))
00091 return false;
00092
00093 memcpy(MSNP_I2CRequest, MSNP_ConfigGroup6, sizeof(MSNP_ConfigGroup6));
00094 if (!writeI2C(link, MSNP_I2CRequest))
00095 return false;
00096
00097 return true;
00098 }
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109 bool MSNPscanKeys(tSensors link, int &pressedKeys, unsigned byte &key, int &number) {
00110
00111
00112 if (!_MSNPinitialised[link]) {
00113 _MSNPinit(link);
00114 _MSNPinitialised[link] = true;
00115 wait1Msec(10);
00116 }
00117
00118 key = 'X';
00119 number = -255;
00120
00121 MSNP_I2CRequest[0] = 2;
00122 MSNP_I2CRequest[1] = MSNP_I2C_ADDR;
00123 MSNP_I2CRequest[2] = MSNP_DATA_REG;
00124
00125 if (!writeI2C(link, MSNP_I2CRequest, MSNP_I2CReply, 2))
00126 return false;
00127
00128 pressedKeys = MSNP_I2CReply[0] + (MSNP_I2CReply[1] * 256);
00129
00130 for (int i=0; i < 12; i++) {
00131 if (pressedKeys & (1<<i)) {
00132 key = MSNP_KeyMap[i];
00133 number = MSNP_NumMap[i];
00134 return true;
00135 }
00136 }
00137
00138 return true;
00139 }
00140
00141
00142
00143
00144
00145
00146
00147 int MSNPscanKeys(tSensors link) {
00148 int keyPress = 0;
00149
00150 if (!_MSNPinitialised[link]) {
00151 _MSNPinit(link);
00152 _MSNPinitialised[link] = true;
00153 wait1Msec(10);
00154 }
00155
00156
00157 MSNP_I2CRequest[0] = 2;
00158 MSNP_I2CRequest[1] = MSNP_I2C_ADDR;
00159 MSNP_I2CRequest[2] = MSNP_DATA_REG;
00160
00161 if (!writeI2C(link, MSNP_I2CRequest, MSNP_I2CReply, 2))
00162 return -255;
00163
00164 keyPress = MSNP_I2CReply[0] + (MSNP_I2CReply[1] * 256);
00165
00166 for (int i=0; i < 12; i++) {
00167 if (keyPress & (1<<i)) {
00168 return MSNP_NumMap[i];
00169 }
00170 }
00171
00172 return -255;
00173 }
00174
00175
00176 #endif // __MSNP_H__
00177
00178
00179
00180
00181
00182