VL6180X_ATY.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599
  1. /**
  2. * @file VL6180X_ATY.c
  3. *
  4. * @param Project DEVICE_GENERAL_ATY_LIB
  5. *
  6. * @author ATY
  7. *
  8. * @copyright
  9. * - Copyright 2017 - 2025 MZ-ATY
  10. * - This code follows:
  11. * - MZ-ATY Various Contents Joint Statement -
  12. * <a href="https://mengze.top/MZ-ATY_VCJS">
  13. * https://mengze.top/MZ-ATY_VCJS</a>
  14. * - CC 4.0 BY-NC-SA -
  15. * <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/">
  16. * https://creativecommons.org/licenses/by-nc-sa/4.0/</a>
  17. * - Your use will be deemed to have accepted the terms of this statement.
  18. *
  19. * @brief Familiar functions of VL6180 for all embedded device
  20. *
  21. * @version
  22. * - 1_01_231228 > ATY
  23. * -# Preliminary version, first Release
  24. * - 1_01_240104 > ATY
  25. * -# base tested VL6180
  26. * - 1_01_240111 > ATY
  27. * -# add lock
  28. ********************************************************************************
  29. */
  30. #ifndef __VL6180X_ATY_C
  31. #define __VL6180X_ATY_C
  32. #include "VL6180X_ATY.h"
  33. /******************************* For user *************************************/
  34. /******************************************************************************/
  35. /**
  36. * @brief
  37. *
  38. * @param reg
  39. * @param data
  40. * @param dev
  41. * @return uint8_t
  42. */
  43. uint8_t VL6180X_WriteByte(uint16_t reg, uint8_t data, struct VL6180X_ATY_Dev* dev)
  44. {
  45. uint8_t groupRegData[3], errCode = 0;
  46. __ATY_LOCK(dev);
  47. groupRegData[0] = (reg >> 8) & 0xFF; // MSB of register address
  48. groupRegData[1] = reg & 0xFF; // LSB of register address
  49. groupRegData[2] = data & 0xFF;
  50. errCode = dev->i2cProcess(dev->addr, groupRegData, 3, _ATY_RW_W);
  51. __ATY_UNLOCK(dev);
  52. return errCode;
  53. }
  54. /**
  55. * @brief
  56. *
  57. * @param reg
  58. * @param data
  59. * @param bytes num to write
  60. * @param dev
  61. * @return uint8_t
  62. */
  63. uint8_t VL6180X_WriteBytes(uint16_t reg, uint8_t* data, uint8_t bytes, struct VL6180X_ATY_Dev* dev)
  64. {
  65. uint8_t groupRegData[3], i = 0, errCode = 0;
  66. __ATY_LOCK(dev);
  67. groupRegData[0] = (reg >> 8) & 0xFF; // MSB of register address
  68. groupRegData[1] = reg & 0xFF; // LSB of register address
  69. for(i = 0; i < bytes; i++)
  70. groupRegData[2 + i] = data[i] & 0xFF;
  71. errCode = dev->i2cProcess(dev->addr, groupRegData, 2 + bytes, _ATY_RW_W);
  72. __ATY_UNLOCK(dev);
  73. return errCode;
  74. }
  75. /**
  76. * @brief
  77. *
  78. * @param reg
  79. * @param data
  80. * @param dev
  81. * @return uint8_t
  82. */
  83. uint8_t VL6180X_ReadByte(uint16_t reg, uint8_t* data, struct VL6180X_ATY_Dev* dev)
  84. {
  85. uint8_t groupReg[2], errCode = 0;
  86. __ATY_LOCK(dev);
  87. groupReg[0] = (reg >> 8) & 0xFF; // MSB of register address
  88. groupReg[1] = reg & 0xFF; // LSB of register address
  89. errCode = dev->i2cProcess(dev->addr, groupReg, 2, _ATY_RW_W);
  90. if(errCode){ __ATY_UNLOCK(dev); return errCode; }
  91. errCode = dev->i2cProcess(dev->addr, data, 1, _ATY_RW_R);
  92. __ATY_UNLOCK(dev);
  93. return errCode;
  94. }
  95. /**
  96. * @brief
  97. *
  98. * @param reg
  99. * @param data
  100. * @param bytes num to read
  101. * @param dev
  102. * @return uint8_t
  103. */
  104. uint8_t VL6180X_ReadBytes(uint16_t reg, uint8_t* data, uint8_t bytes, struct VL6180X_ATY_Dev* dev)
  105. {
  106. uint8_t groupReg[2], errCode = 0;
  107. __ATY_LOCK(dev);
  108. groupReg[0] = (reg >> 8) & 0xFF; // MSB of register address
  109. groupReg[1] = reg & 0xFF; // LSB of register address
  110. errCode = dev->i2cProcess(dev->addr, groupReg, 2, _ATY_RW_W);
  111. if(errCode){ __ATY_UNLOCK(dev); return errCode; }
  112. errCode = dev->i2cProcess(dev->addr, data, bytes, _ATY_RW_R);
  113. __ATY_UNLOCK(dev);
  114. return errCode;
  115. }
  116. /**
  117. * @brief get ids
  118. *
  119. * @param id need 9 size array
  120. * @param dev device
  121. * @return uint8_t
  122. */
  123. uint8_t VL6180X_GetId(uint8_t* id, struct VL6180X_ATY_Dev* dev)
  124. {
  125. uint8_t errCode = 0;
  126. errCode = 0x00 & VL6180X_ReadByte(VL6180X_REG_IDENTIFICATION_MODEL_ID, &id[0], dev);
  127. errCode = 0x10 & VL6180X_ReadByte(VL6180X_REG_IDENTIFICATION_MODEL_REV_MAJOR, &id[1], dev);
  128. errCode = 0x20 & VL6180X_ReadByte(VL6180X_REG_IDENTIFICATION_MODEL_REV_MINOR, &id[2], dev);
  129. errCode = 0x30 & VL6180X_ReadByte(VL6180X_REG_IDENTIFICATION_MODULE_REV_MAJOR, &id[3], dev);
  130. errCode = 0x40 & VL6180X_ReadByte(VL6180X_REG_IDENTIFICATION_MODULE_REV_MINOR, &id[4], dev);
  131. errCode = 0x50 & VL6180X_ReadByte(VL6180X_REG_IDENTIFICATION_DATE_HI, &id[5], dev);
  132. errCode = 0x60 & VL6180X_ReadByte(VL6180X_REG_IDENTIFICATION_DATE_LO, &id[6], dev);
  133. errCode = 0x70 & VL6180X_ReadBytes(VL6180X_REG_IDENTIFICATION_TIME, &id[7], 2, dev);
  134. if(dev->debugEnable == 1){
  135. uint8_t i = 0;
  136. for(i = 0; i < 9; i++)
  137. dev->LOG("%02X ", id[i]);
  138. dev->LOG("\r\n");
  139. }
  140. if(id[0] != 0x84){ return 0x81; }
  141. return errCode;
  142. }
  143. /**
  144. * @brief set offset
  145. *
  146. * @param offset
  147. * @param dev
  148. * @return uint8_t
  149. */
  150. uint8_t VL6180X_SetOffset(uint8_t offset, struct VL6180X_ATY_Dev* dev)
  151. {
  152. return VL6180X_WriteByte(VL6180X_REG_SYSRANGE_PART_TO_PART_RANGE_OFFSET, offset, dev);
  153. }
  154. /**
  155. * @brief write new addr
  156. *
  157. * @param newAddr
  158. * @param dev
  159. * @note not real tested
  160. * @return uint8_t
  161. */
  162. uint8_t VL6180X_SetAddress(uint8_t newAddr, struct VL6180X_ATY_Dev* dev)
  163. {
  164. if(VL6180X_WriteByte(VL6180X_REG_SLAVE_DEVICE_ADDRESS, newAddr & 0x7F, dev) == 1)
  165. return 1;
  166. dev->addr = newAddr;
  167. return 0;
  168. }
  169. /**
  170. * @brief
  171. *
  172. * @param dev
  173. * @return uint8_t
  174. */
  175. uint8_t VL6180X_ClearInterrupts(struct VL6180X_ATY_Dev* dev)
  176. {
  177. if(VL6180X_WriteByte(VL6180X_REG_SYSTEM_INTERRUPT_CLEAR, 0x07, dev) == 1)
  178. return 1;
  179. return 0;
  180. }
  181. /**
  182. * @brief
  183. *
  184. * @return uint8_t 1 for ready
  185. */
  186. uint8_t VL6180X_IsDeviceReady(struct VL6180X_ATY_Dev* dev)
  187. {
  188. uint8_t byte = 0;
  189. if(VL6180X_ReadByte(VL6180X_REG_RESULT_INTERRUPT_STATUS_GPIO, &byte, dev) == 1)
  190. return 2;
  191. if((byte & 0x01))
  192. return 1;
  193. return 0;
  194. }
  195. /**
  196. * @brief
  197. *
  198. * @return uint8_t 1 for ready
  199. */
  200. uint8_t VL6180X_WaitDeviceReady(struct VL6180X_ATY_Dev* dev)
  201. {
  202. uint16_t errCount = 0;
  203. while(VL6180X_IsDeviceReady(dev) != 1){
  204. errCount++;
  205. if(errCount > 100) return 2;
  206. }
  207. return 1;
  208. }
  209. /**
  210. * @brief
  211. *
  212. * @return uint8_t 1 for complete
  213. */
  214. uint8_t VL6180X_IsRangeComplete(struct VL6180X_ATY_Dev* dev)
  215. {
  216. uint8_t status = 0;
  217. if(VL6180X_ReadByte(VL6180X_REG_RESULT_INTERRUPT_STATUS_GPIO, &status, dev) == 1)
  218. return 2;
  219. status &= 0x07;
  220. if((status & 0x04))
  221. return 1;
  222. return 0;
  223. }
  224. /**
  225. * @brief
  226. *
  227. * @return uint8_t 1 for complete
  228. */
  229. uint8_t VL6180X_WaitRangeComplete(struct VL6180X_ATY_Dev* dev)
  230. {
  231. uint16_t errCount = 0;
  232. while(VL6180X_IsRangeComplete(dev) != 1){
  233. errCount++;
  234. if(errCount > 100) return 2;
  235. }
  236. return 1;
  237. }
  238. /**
  239. * @brief request ranging success/error message (retreive after ranging)
  240. *
  241. * @param value
  242. * @param dev
  243. * @return uint8_t one of possible VL6180X_ERROR_* values
  244. */
  245. uint8_t VL6180X_ReadRangeStatus(uint8_t* status, struct VL6180X_ATY_Dev* dev)
  246. {
  247. if(VL6180X_ReadByte(VL6180X_REG_RESULT_RANGE_STATUS, status, dev) == 1)
  248. return 1;
  249. return 0;
  250. }
  251. /**
  252. * @brief
  253. *
  254. * @param dev
  255. * @return uint8_t
  256. * @note Return results of read reqyest also clears out the interrupt
  257. Be sure to check the return of {@link readRangeStatus} to before using
  258. the return value!
  259. */
  260. uint8_t VL6180X_ReadRangeResult(uint8_t* range, struct VL6180X_ATY_Dev* dev)
  261. {
  262. if(VL6180X_ReadByte(VL6180X_REG_RESULT_RANGE_VAL, range, dev) == 1)
  263. return 1;
  264. if(dev->debugEnable == 1)
  265. dev->LOG("%d\r\n", *range);
  266. return 0;
  267. }
  268. /**
  269. * @brief
  270. *
  271. * @param dev
  272. * @return uint8_t
  273. */
  274. uint8_t VL6180X_StartRange(struct VL6180X_ATY_Dev* dev)
  275. {
  276. if(VL6180X_WriteByte(VL6180X_REG_SYSRANGE_START, 0x01, dev) == 1)
  277. return 1;
  278. return 0;
  279. }
  280. /**
  281. * @brief start continuous ranging
  282. *
  283. * @param period_msOptional Period between ranges in ms.
  284. Values will be rounded down to 10ms units with minimum of 10ms.
  285. Default is 50
  286. * @param dev
  287. * @return uint8_t
  288. */
  289. uint8_t VL6180X_StartRangeContinuous(uint16_t period_ms, struct VL6180X_ATY_Dev* dev)
  290. {
  291. uint8_t period_reg = 0;
  292. if(period_ms > 10) {
  293. if(period_ms < 2550)
  294. period_reg = (period_ms / 10) - 1;
  295. else
  296. period_reg = 254;
  297. }
  298. // Set ranging inter-measurement
  299. if(VL6180X_WriteByte(SYSRANGE__INTERMEASUREMENT_PERIOD, period_reg, dev) == 1)
  300. return 1;
  301. // Start a continuous range measurement
  302. if(VL6180X_WriteByte(VL6180X_REG_SYSRANGE_START, 0x03, dev) == 1)
  303. return 1;
  304. return 0;
  305. }
  306. /**
  307. * @brief stop continuous range operation
  308. *
  309. * @param dev
  310. * @return uint8_t
  311. * @note stop the continuous range operation, by setting the range register
  312. back to 1, Page 7 of appication notes
  313. */
  314. uint8_t VL6180X_StopRangeContinuous(struct VL6180X_ATY_Dev* dev)
  315. {
  316. if(VL6180X_WriteByte(VL6180X_REG_SYSRANGE_START, 0x01, dev) == 1)
  317. return 1;
  318. return 0;
  319. }
  320. /**
  321. * @brief initializes I2C interface, checks that VL6180X is found and resets chip
  322. *
  323. * @param dev
  324. * @return uint8_t
  325. */
  326. uint8_t VL6180X_Init(struct VL6180X_ATY_Dev* dev)
  327. {
  328. uint8_t reset;
  329. if(VL6180X_ReadByte(VL6180X_REG_SYSTEM_FRESH_OUT_OF_RESET, &reset, dev) == 1)
  330. return 1;
  331. // check to see has it be Initialised already
  332. if(reset == 1){
  333. if(VL6180X_Config(dev))
  334. return 3;
  335. //change fresh out of set status to 0
  336. if(VL6180X_WriteByte(VL6180X_REG_SYSTEM_FRESH_OUT_OF_RESET, 0x00, dev) == 1)
  337. return 2;
  338. }
  339. return 0;
  340. }
  341. /**
  342. * @brief
  343. *
  344. * @param range
  345. * @param dev
  346. * @return uint8_t distance in millimeters if valid
  347. */
  348. uint8_t VL6180X_MeasureRangeOnce(uint8_t* range, struct VL6180X_ATY_Dev* dev)
  349. {
  350. uint8_t errCode = 0;
  351. errCode = 0x00 & VL6180X_WaitDeviceReady(dev); // slower
  352. errCode = 0x10 & VL6180X_StartRange(dev);
  353. errCode = 0x20 & VL6180X_WaitRangeComplete(dev);
  354. errCode = 0x30 & VL6180X_ReadRangeResult(range, dev);
  355. errCode = 0x40 & VL6180X_ClearInterrupts(dev);
  356. return errCode;
  357. }
  358. /**
  359. * @brief
  360. *
  361. * @param range
  362. * @param dev
  363. * @return uint8_t distance in millimeters if valid(100ms cycle tested)
  364. */
  365. uint8_t VL6180X_MeasureRangeOnceFast(uint8_t* range, struct VL6180X_ATY_Dev* dev)
  366. {
  367. uint8_t errCode = 0;
  368. // errCode = 0x00 & VL6180X_WaitDeviceReady(dev);
  369. errCode = 0x10 & VL6180X_StartRange(dev);
  370. // errCode = 0x10 & VL6180X_StartRangeContinuous(10, dev);
  371. errCode = 0x20 & VL6180X_WaitRangeComplete(dev);
  372. errCode = 0x30 & VL6180X_ReadRangeResult(range, dev);
  373. errCode = 0x40 & VL6180X_ClearInterrupts(dev);
  374. return errCode;
  375. }
  376. /**
  377. * @brief single shot lux measurement
  378. *
  379. * @param gain gain setting, one of VL6180X_ALS_GAIN_*
  380. * @param lux
  381. * @param dev
  382. * @return uint8_t
  383. * @note only for VL6180X
  384. */
  385. uint8_t VL6180X_ReadLux(uint8_t gain, float* lux, struct VL6180X_ATY_Dev* dev)
  386. {
  387. uint16_t errCount = 0;
  388. uint8_t byte = 0;
  389. if(VL6180X_ReadByte(VL6180X_REG_SYSTEM_INTERRUPT_CONFIG, &byte, dev) == 1)
  390. return 1;
  391. byte &= ~0x38;
  392. byte |= (0x4 << 3); // IRQ on ALS ready
  393. if(VL6180X_WriteByte(VL6180X_REG_SYSTEM_INTERRUPT_CONFIG, byte, dev) == 1)
  394. return 2;
  395. // 100 ms integration period
  396. if(VL6180X_WriteByte(VL6180X_REG_SYSALS_INTEGRATION_PERIOD_HI, 0, dev) == 1)
  397. return 3;
  398. if(VL6180X_WriteByte(VL6180X_REG_SYSALS_INTEGRATION_PERIOD_LO, 100, dev) == 1)
  399. return 4;
  400. // analog gain
  401. if(gain > VL6180X_ALS_GAIN_40) {
  402. gain = VL6180X_ALS_GAIN_40;
  403. }
  404. if(VL6180X_WriteByte(VL6180X_REG_SYSALS_ANALOGUE_GAIN, 0x40 | gain, dev) == 1)
  405. return 5;
  406. // start ALS
  407. if(VL6180X_WriteByte(VL6180X_REG_SYSALS_START, 0x01, dev) == 1)
  408. return 6;
  409. if(VL6180X_ReadByte(VL6180X_REG_RESULT_INTERRUPT_STATUS_GPIO, &byte, dev) == 1)
  410. return 7;
  411. // Poll until "New Sample Ready threshold event" is set
  412. while(4 != ((byte >> 3) & 0x7)){
  413. if(VL6180X_ReadByte(VL6180X_REG_RESULT_INTERRUPT_STATUS_GPIO, &byte, dev) == 1)
  414. return 8;
  415. errCount++;
  416. if(errCount > 1000) return 9;
  417. }
  418. // read lux!
  419. uint8_t luxBytes[2] = {0};
  420. if(VL6180X_ReadBytes(VL6180X_REG_RESULT_ALS_VAL, luxBytes, 2, dev) == 1)
  421. return 10;
  422. *lux = ((luxBytes[0] << 8) | luxBytes[1]);
  423. // clear interrupt
  424. if(VL6180X_WriteByte(VL6180X_REG_SYSTEM_INTERRUPT_CLEAR, 0x07, dev) == 1)
  425. return 11;
  426. *lux *= 0.32; // calibrated count/lux
  427. switch(gain) {
  428. case VL6180X_ALS_GAIN_1:
  429. break;
  430. case VL6180X_ALS_GAIN_1_25:
  431. *lux /= 1.25;
  432. break;
  433. case VL6180X_ALS_GAIN_1_67:
  434. *lux /= 1.67;
  435. break;
  436. case VL6180X_ALS_GAIN_2_5:
  437. *lux /= 2.5;
  438. break;
  439. case VL6180X_ALS_GAIN_5:
  440. *lux /= 5;
  441. break;
  442. case VL6180X_ALS_GAIN_10:
  443. *lux /= 10;
  444. break;
  445. case VL6180X_ALS_GAIN_20:
  446. *lux /= 20;
  447. break;
  448. case VL6180X_ALS_GAIN_40:
  449. *lux /= 40;
  450. break;
  451. }
  452. *lux *= 100;
  453. *lux /= 100; // integration time in ms
  454. return 0;
  455. }
  456. /**
  457. * @brief
  458. *
  459. * @param dev
  460. * @return uint8_t
  461. */
  462. uint8_t VL6180X_Config(struct VL6180X_ATY_Dev* dev)
  463. {
  464. uint8_t errCode = 0;
  465. // Mandatory : private registers
  466. errCode = 0x10 & VL6180X_WriteByte(0x0207, 0x01, dev);
  467. errCode = 0x10 & VL6180X_WriteByte(0x0208, 0x01, dev);
  468. errCode = 0x10 & VL6180X_WriteByte(0x0096, 0x00, dev);
  469. errCode = 0x10 & VL6180X_WriteByte(0x0097, 0xfd, dev);
  470. errCode = 0x10 & VL6180X_WriteByte(0x00e3, 0x01, dev);
  471. errCode = 0x10 & VL6180X_WriteByte(0x00e4, 0x03, dev);
  472. errCode = 0x10 & VL6180X_WriteByte(0x00e5, 0x02, dev);
  473. errCode = 0x10 & VL6180X_WriteByte(0x00e6, 0x01, dev);
  474. errCode = 0x10 & VL6180X_WriteByte(0x00e7, 0x03, dev);
  475. errCode = 0x10 & VL6180X_WriteByte(0x00f5, 0x02, dev);
  476. errCode = 0x10 & VL6180X_WriteByte(0x00d9, 0x05, dev);
  477. errCode = 0x10 & VL6180X_WriteByte(0x00db, 0xce, dev);
  478. errCode = 0x10 & VL6180X_WriteByte(0x00dc, 0x03, dev);
  479. errCode = 0x10 & VL6180X_WriteByte(0x00dd, 0xf8, dev);
  480. errCode = 0x10 & VL6180X_WriteByte(0x009f, 0x00, dev);
  481. errCode = 0x10 & VL6180X_WriteByte(0x00a3, 0x3c, dev);
  482. errCode = 0x10 & VL6180X_WriteByte(0x00b7, 0x00, dev);
  483. errCode = 0x10 & VL6180X_WriteByte(0x00bb, 0x3c, dev);
  484. errCode = 0x10 & VL6180X_WriteByte(0x00b2, 0x09, dev);
  485. errCode = 0x10 & VL6180X_WriteByte(0x00ca, 0x09, dev);
  486. errCode = 0x10 & VL6180X_WriteByte(0x0198, 0x01, dev);
  487. errCode = 0x10 & VL6180X_WriteByte(0x01b0, 0x17, dev);
  488. errCode = 0x10 & VL6180X_WriteByte(0x01ad, 0x00, dev);
  489. errCode = 0x10 & VL6180X_WriteByte(0x00ff, 0x05, dev);
  490. errCode = 0x10 & VL6180X_WriteByte(0x0100, 0x05, dev);
  491. errCode = 0x10 & VL6180X_WriteByte(0x0199, 0x05, dev);
  492. errCode = 0x10 & VL6180X_WriteByte(0x01a6, 0x1b, dev);
  493. errCode = 0x10 & VL6180X_WriteByte(0x01ac, 0x3e, dev);
  494. errCode = 0x10 & VL6180X_WriteByte(0x01a7, 0x1f, dev);
  495. errCode = 0x10 & VL6180X_WriteByte(0x0030, 0x00, dev);
  496. // Recommended : Public registers - See data sheet for more detail
  497. errCode = 0x20 & VL6180X_WriteByte(0x0011, 0x10, dev); // Enables polling for "New Sample ready" when measurement completes
  498. errCode = 0x20 & VL6180X_WriteByte(0x010a, 0x30, dev); // Set the averaging sample period (compromise between lower noise and increased execution time)
  499. errCode = 0x20 & VL6180X_WriteByte(0x003f, 0x46, dev); // Sets the light and dark gain (upper nibble). Dark gain should not be changed.
  500. errCode = 0x20 & VL6180X_WriteByte(0x0031, 0xFF, dev); // sets the # of range measurements after which auto calibration of system is performed
  501. errCode = 0x20 & VL6180X_WriteByte(0x0041, 0x63, dev); // Set ALS integration time to 100ms
  502. errCode = 0x20 & VL6180X_WriteByte(0x002e, 0x01, dev); // perform a single temperature calibration of the ranging sensor
  503. // Optional: Public registers - See data sheet for more detail
  504. errCode = 0x30 & VL6180X_WriteByte(0x001b, 0x09, dev); // Set default ranging inter-measurement period to 100ms
  505. errCode = 0x30 & VL6180X_WriteByte(0x003e, 0x31, dev); // Set default ALS inter-measurement period to 500ms
  506. errCode = 0x30 & VL6180X_WriteByte(0x0014, 0x24, dev); // Configures interrupt on "New Sample Ready threshold event"
  507. return errCode;
  508. }
  509. #endif /* __VL6180X_ATY_C */
  510. /************************************ etc *************************************/
  511. /* init */
  512. // uint8_t VL6180X_1_I2C(uint8_t addr, uint8_t* data_t, uint8_t len, uint8_t rw){
  513. // if(rw == _ATY_RW_W)
  514. // return I2C_Write(addr, data_t, len, &HW_I2C_ATY_Dev_1);
  515. // else if(rw == _ATY_RW_R)
  516. // return I2C_Read(addr, data_t, len, &HW_I2C_ATY_Dev_1);
  517. // }
  518. // uint8_t VL6180X_1_I2C(uint8_t addr, uint8_t* data_t, uint8_t len, uint8_t rw){
  519. // if(rw == _ATY_RW_W)
  520. // return (uint8_t)HAL_I2C_Master_Transmit(&hi2c1, (addr << 1 | 0), data_t, len, 1000);
  521. // else if(rw == _ATY_RW_R)
  522. // return (uint8_t)HAL_I2C_Master_Receive(&hi2c1, (addr << 1 | 1), data_t, len, 1000);
  523. // }
  524. // struct VL6180X_ATY_Dev VL6180X_ATY_t_1 = {
  525. // .addr = VL6180X_ADDRESS,
  526. // .i2cProcess = VL6180X_1_I2C,
  527. // .lock = _ATY_UNLOCKED,
  528. // .debugEnable = 0,
  529. // .LOG = printf
  530. // };
  531. // VL6180X_Init(&VL6180X_ATY_t_1);
  532. /* use */
  533. // VL6180X_ATY_t_1.debugEnable = 1;
  534. // uint8_t idGroup[9] = {0};
  535. // VL6180X_GetId(idGroup, &VL6180X_ATY_t_1);
  536. // VL6180X_SetOffset(10, &VL6180X_ATY_t_1);
  537. // VL6180X_SetAddress(0x10, &VL6180X_ATY_t_1);
  538. // VL6180X_MeasureRangeOnce(&range, &VL6180X_ATY_t_1);
  539. // VL6180X_MeasureRangeOnceFast(&range, &VL6180X_ATY_t_1);
  540. // only for VL6180X
  541. // VL6180X_ReadLux(VL6180X_ALS_GAIN_40, &lux, &VL6180X_ATY_t_1);
  542. // rcPara_t rcParam_VL6180 = {0.028, 0};
  543. // rcLpFilter(&rcParam_VL6180, value);
  544. /******************************************************************************/
  545. /******************************** End Of File *********************************/