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