Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
PAJ7620U2.cpp
00001 #include "mbed.h" 00002 #include "PAJ7620U2.h" 00003 00004 bool PAJ7620U2::RegisterWrite(uint8_t address, uint8_t value) 00005 { 00006 uint8_t sendData[2]; 00007 sendData[0] = address; 00008 sendData[1] = value; 00009 if (_I2c->write(_SlaveAddress, (const char*)sendData, sizeof(sendData), false) != 0) return false; 00010 00011 return true; 00012 } 00013 00014 bool PAJ7620U2::RegisterWrite(uint8_t address, const uint8_t* data, int dataSize) 00015 { 00016 uint8_t* sendData = (uint8_t*)alloca(1 + dataSize); 00017 sendData[0] = address; 00018 memcpy(&sendData[1], data, dataSize); 00019 if (_I2c->write(_SlaveAddress, (const char*)sendData, 1 + dataSize, false) != 0) return false; 00020 00021 return true; 00022 } 00023 00024 bool PAJ7620U2::RegisterRead(uint8_t address, uint8_t* value) 00025 { 00026 uint8_t sendData[1]; 00027 sendData[0] = address; 00028 if (_I2c->write(_SlaveAddress, (const char*)sendData, sizeof(sendData), true) != 0) return false; 00029 00030 uint8_t recvData[1]; 00031 if (_I2c->read(_SlaveAddress, (char*)recvData, sizeof(recvData)) != 0) return false; 00032 *value = recvData[0]; 00033 00034 return true; 00035 } 00036 00037 bool PAJ7620U2::RegisterRead(uint8_t address, uint8_t* data, int dataSize) 00038 { 00039 uint8_t sendData[1]; 00040 sendData[0] = address; 00041 if (_I2c->write(_SlaveAddress, (const char*)sendData, sizeof(sendData), true) != 0) return false; 00042 00043 if (_I2c->read(_SlaveAddress, (char*)data, dataSize) != 0) return false; 00044 00045 return true; 00046 } 00047 00048 const PAJ7620U2::RegisterAddressValue PAJ7620U2::_InitRegisterArray[] = { 00049 { 0xEF, 0x00, }, 00050 { 0x32, 0x29, }, 00051 { 0x33, 0x01, }, 00052 { 0x34, 0x00, }, 00053 { 0x35, 0x01, }, 00054 { 0x36, 0x00, }, 00055 { 0x37, 0x07, }, 00056 { 0x38, 0x17, }, 00057 { 0x39, 0x06, }, 00058 { 0x3A, 0x12, }, 00059 { 0x3F, 0x00, }, 00060 { 0x40, 0x02, }, 00061 { 0x41, 0xFF, }, 00062 { 0x42, 0x01, }, 00063 { 0x46, 0x2D, }, 00064 { 0x47, 0x0F, }, 00065 { 0x48, 0x3C, }, 00066 { 0x49, 0x00, }, 00067 { 0x4A, 0x1E, }, 00068 { 0x4B, 0x00, }, 00069 { 0x4C, 0x20, }, 00070 { 0x4D, 0x00, }, 00071 { 0x4E, 0x1A, }, 00072 { 0x4F, 0x14, }, 00073 { 0x50, 0x00, }, 00074 { 0x51, 0x10, }, 00075 { 0x52, 0x00, }, 00076 { 0x5C, 0x02, }, 00077 { 0x5D, 0x00, }, 00078 { 0x5E, 0x10, }, 00079 { 0x5F, 0x3F, }, 00080 { 0x60, 0x27, }, 00081 { 0x61, 0x28, }, 00082 { 0x62, 0x00, }, 00083 { 0x63, 0x03, }, 00084 { 0x64, 0xF7, }, 00085 { 0x65, 0x03, }, 00086 { 0x66, 0xD9, }, 00087 { 0x67, 0x03, }, 00088 { 0x68, 0x01, }, 00089 { 0x69, 0xC8, }, 00090 { 0x6A, 0x40, }, 00091 { 0x6D, 0x04, }, 00092 { 0x6E, 0x00, }, 00093 { 0x6F, 0x00, }, 00094 { 0x70, 0x80, }, 00095 { 0x71, 0x00, }, 00096 { 0x72, 0x00, }, 00097 { 0x73, 0x00, }, 00098 { 0x74, 0xF0, }, 00099 { 0x75, 0x00, }, 00100 { 0x80, 0x42, }, 00101 { 0x81, 0x44, }, 00102 { 0x82, 0x04, }, 00103 { 0x83, 0x20, }, 00104 { 0x84, 0x20, }, 00105 { 0x85, 0x00, }, 00106 { 0x86, 0x10, }, 00107 { 0x87, 0x00, }, 00108 { 0x88, 0x05, }, 00109 { 0x89, 0x18, }, 00110 { 0x8A, 0x10, }, 00111 { 0x8B, 0x01, }, 00112 { 0x8C, 0x37, }, 00113 { 0x8D, 0x00, }, 00114 { 0x8E, 0xF0, }, 00115 { 0x8F, 0x81, }, 00116 { 0x90, 0x06, }, 00117 { 0x91, 0x06, }, 00118 { 0x92, 0x1E, }, 00119 { 0x93, 0x0D, }, 00120 { 0x94, 0x0A, }, 00121 { 0x95, 0x0A, }, 00122 { 0x96, 0x0C, }, 00123 { 0x97, 0x05, }, 00124 { 0x98, 0x0A, }, 00125 { 0x99, 0x41, }, 00126 { 0x9A, 0x14, }, 00127 { 0x9B, 0x0A, }, 00128 { 0x9C, 0x3F, }, 00129 { 0x9D, 0x33, }, 00130 { 0x9E, 0xAE, }, 00131 { 0x9F, 0xF9, }, 00132 { 0xA0, 0x48, }, 00133 { 0xA1, 0x13, }, 00134 { 0xA2, 0x10, }, 00135 { 0xA3, 0x08, }, 00136 { 0xA4, 0x30, }, 00137 { 0xA5, 0x19, }, 00138 { 0xA6, 0x10, }, 00139 { 0xA7, 0x08, }, 00140 { 0xA8, 0x24, }, 00141 { 0xA9, 0x04, }, 00142 { 0xAA, 0x1E, }, 00143 { 0xAB, 0x1E, }, 00144 { 0xCC, 0x19, }, 00145 { 0xCD, 0x0B, }, 00146 { 0xCE, 0x13, }, 00147 { 0xCF, 0x64, }, 00148 { 0xD0, 0x21, }, 00149 { 0xD1, 0x0F, }, 00150 { 0xD2, 0x88, }, 00151 { 0xE0, 0x01, }, 00152 { 0xE1, 0x04, }, 00153 { 0xE2, 0x41, }, 00154 { 0xE3, 0xD6, }, 00155 { 0xE4, 0x00, }, 00156 { 0xE5, 0x0C, }, 00157 { 0xE6, 0x0A, }, 00158 { 0xE7, 0x00, }, 00159 { 0xE8, 0x00, }, 00160 { 0xE9, 0x00, }, 00161 { 0xEE, 0x07, }, 00162 { 0xEF, 0x01, }, 00163 { 0x00, 0x1E, }, 00164 { 0x01, 0x1E, }, 00165 { 0x02, 0x0F, }, 00166 { 0x03, 0x10, }, 00167 { 0x04, 0x02, }, 00168 { 0x05, 0x00, }, 00169 { 0x06, 0xB0, }, 00170 { 0x07, 0x04, }, 00171 { 0x08, 0x0D, }, 00172 { 0x09, 0x0E, }, 00173 { 0x0A, 0x9C, }, 00174 { 0x0B, 0x04, }, 00175 { 0x0C, 0x05, }, 00176 { 0x0D, 0x0F, }, 00177 { 0x0E, 0x02, }, 00178 { 0x0F, 0x12, }, 00179 { 0x10, 0x02, }, 00180 { 0x11, 0x02, }, 00181 { 0x12, 0x00, }, 00182 { 0x13, 0x01, }, 00183 { 0x14, 0x05, }, 00184 { 0x15, 0x07, }, 00185 { 0x16, 0x05, }, 00186 { 0x17, 0x07, }, 00187 { 0x18, 0x01, }, 00188 { 0x19, 0x04, }, 00189 { 0x1A, 0x05, }, 00190 { 0x1B, 0x0C, }, 00191 { 0x1C, 0x2A, }, 00192 { 0x1D, 0x01, }, 00193 { 0x1E, 0x00, }, 00194 { 0x21, 0x00, }, 00195 { 0x22, 0x00, }, 00196 { 0x23, 0x00, }, 00197 { 0x25, 0x01, }, 00198 { 0x26, 0x00, }, 00199 { 0x27, 0x39, }, 00200 { 0x28, 0x7F, }, 00201 { 0x29, 0x08, }, 00202 { 0x30, 0x03, }, 00203 { 0x31, 0x00, }, 00204 { 0x32, 0x1A, }, 00205 { 0x33, 0x1A, }, 00206 { 0x34, 0x07, }, 00207 { 0x35, 0x07, }, 00208 { 0x36, 0x01, }, 00209 { 0x37, 0xFF, }, 00210 { 0x38, 0x36, }, 00211 { 0x39, 0x07, }, 00212 { 0x3A, 0x00, }, 00213 { 0x3E, 0xFF, }, 00214 { 0x3F, 0x00, }, 00215 { 0x40, 0x77, }, 00216 { 0x41, 0x40, }, 00217 { 0x42, 0x00, }, 00218 { 0x43, 0x30, }, 00219 { 0x44, 0xA0, }, 00220 { 0x45, 0x5C, }, 00221 { 0x46, 0x00, }, 00222 { 0x47, 0x00, }, 00223 { 0x48, 0x58, }, 00224 { 0x4A, 0x1E, }, 00225 { 0x4B, 0x1E, }, 00226 { 0x4C, 0x00, }, 00227 { 0x4D, 0x00, }, 00228 { 0x4E, 0xA0, }, 00229 { 0x4F, 0x80, }, 00230 { 0x50, 0x00, }, 00231 { 0x51, 0x00, }, 00232 { 0x52, 0x00, }, 00233 { 0x53, 0x00, }, 00234 { 0x54, 0x00, }, 00235 { 0x57, 0x80, }, 00236 { 0x59, 0x10, }, 00237 { 0x5A, 0x08, }, 00238 { 0x5B, 0x94, }, 00239 { 0x5C, 0xE8, }, 00240 { 0x5D, 0x08, }, 00241 { 0x5E, 0x3D, }, 00242 { 0x5F, 0x99, }, 00243 { 0x60, 0x45, }, 00244 { 0x61, 0x40, }, 00245 { 0x63, 0x2D, }, 00246 { 0x64, 0x02, }, 00247 { 0x65, 0x96, }, 00248 { 0x66, 0x00, }, 00249 { 0x67, 0x97, }, 00250 { 0x68, 0x01, }, 00251 { 0x69, 0xCD, }, 00252 { 0x6A, 0x01, }, 00253 { 0x6B, 0xB0, }, 00254 { 0x6C, 0x04, }, 00255 { 0x6D, 0x2C, }, 00256 { 0x6E, 0x01, }, 00257 { 0x6F, 0x32, }, 00258 { 0x71, 0x00, }, 00259 { 0x72, 0x01, }, 00260 { 0x73, 0x35, }, 00261 { 0x74, 0x00, }, 00262 { 0x75, 0x33, }, 00263 { 0x76, 0x31, }, 00264 { 0x77, 0x01, }, 00265 { 0x7C, 0x84, }, 00266 { 0x7D, 0x03, }, 00267 { 0x7E, 0x01, }, 00268 }; 00269 00270 PAJ7620U2::PAJ7620U2(I2C* i2c, uint8_t slaveAddress) 00271 { 00272 _I2c = i2c; 00273 _SlaveAddress = slaveAddress; 00274 _Initialized = false; 00275 } 00276 00277 bool PAJ7620U2::Init() 00278 { 00279 // Wake up. 00280 wait_us(700); 00281 RegisterWrite(0xEF, 0); // R_RegBankSel 00282 wait_us(400); 00283 00284 if (!RegisterWrite(0xEF, 0)) return false; // R_RegBankSel 00285 00286 uint16_t partId; 00287 if (!RegisterRead(0x00, (uint8_t*)&partId, sizeof(partId))) return false; // PartID 00288 00289 if (partId == 0x7620) { 00290 for (int i = 0; i < (int)(sizeof(_InitRegisterArray) / sizeof(_InitRegisterArray[0])); i++) { 00291 if (!RegisterWrite(_InitRegisterArray[i].Address, _InitRegisterArray[i].Value)) return false; 00292 } 00293 } 00294 00295 if (!RegisterWrite(0xEF, 0)) return false; // R_RegBankSel 00296 00297 _Initialized = true; 00298 00299 return true; 00300 } 00301 00302 bool PAJ7620U2::GetGesture(PAJ7620U2::GestureFlag* flag) 00303 { 00304 if (!_Initialized) return false; 00305 00306 uint16_t data; 00307 if (!RegisterRead(0x43, (uint8_t*)&data, sizeof(data))) { // IntFlag_1, IntFlag_2 00308 *flag = GESTURE_NONE; 00309 return false; 00310 } 00311 00312 *flag = (GestureFlag)data; 00313 00314 return true; 00315 }
Generated on Sun Jul 17 2022 10:52:12 by
1.7.2