Reference firmware for PixArt's PMT9123 sensor and evaluation board. "Hello World" and "Library" contain the exact same files. Please import just one of the two into your mBed compiler as a new program and not as a library.
main.cpp@1:1d99f5c9581f, 2018-07-18 (annotated)
- Committer:
- PixArtVY
- Date:
- Wed Jul 18 18:36:29 2018 +0000
- Revision:
- 1:1d99f5c9581f
- Parent:
- 0:71ff24e8c21e
Added Apache License notice.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
PixArtVY | 0:71ff24e8c21e | 1 | // PMT9123QS: Low Power Right-Angle Optical Track Sensor |
PixArtVY | 1:1d99f5c9581f | 2 | // Version: 1.1 |
PixArtVY | 1:1d99f5c9581f | 3 | // Latest Revision Date: 18 July 2018 |
PixArtVY | 0:71ff24e8c21e | 4 | // By PixArt Imaging Inc. |
PixArtVY | 0:71ff24e8c21e | 5 | // Primary Engineer: Vincent Yeh (PixArt USA) |
PixArtVY | 0:71ff24e8c21e | 6 | |
PixArtVY | 1:1d99f5c9581f | 7 | // Copyright [2018] [Vincent Yeh] |
PixArtVY | 1:1d99f5c9581f | 8 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: |
PixArtVY | 1:1d99f5c9581f | 9 | // http://www.apache.org/licenses/LICENSE-2.0 |
PixArtVY | 1:1d99f5c9581f | 10 | |
PixArtVY | 1:1d99f5c9581f | 11 | |
PixArtVY | 0:71ff24e8c21e | 12 | /* |
PixArtVY | 0:71ff24e8c21e | 13 | //======================= |
PixArtVY | 0:71ff24e8c21e | 14 | //Revision History |
PixArtVY | 0:71ff24e8c21e | 15 | //======================= |
PixArtVY | 1:1d99f5c9581f | 16 | Version 1.1 -- 18 July 2018 |
PixArtVY | 1:1d99f5c9581f | 17 | Added apache license notice. |
PixArtVY | 1:1d99f5c9581f | 18 | |
PixArtVY | 0:71ff24e8c21e | 19 | Version 1.0 -- 9 Apr. 2018 |
PixArtVY | 0:71ff24e8c21e | 20 | First release. |
PixArtVY | 0:71ff24e8c21e | 21 | */ |
PixArtVY | 0:71ff24e8c21e | 22 | |
PixArtVY | 0:71ff24e8c21e | 23 | #include "mbed.h" |
PixArtVY | 0:71ff24e8c21e | 24 | #include "registerArrays.h" |
PixArtVY | 0:71ff24e8c21e | 25 | #include "I2CcommFunctions.h" |
PixArtVY | 0:71ff24e8c21e | 26 | |
PixArtVY | 0:71ff24e8c21e | 27 | int main() |
PixArtVY | 0:71ff24e8c21e | 28 | { |
PixArtVY | 0:71ff24e8c21e | 29 | pc.baud(115200); // Set baud rate to 115200. Remember to sync serial terminal baud rate to the same value. |
PixArtVY | 0:71ff24e8c21e | 30 | i2c.frequency(400000); // Set frequency for I2C communication. |
PixArtVY | 0:71ff24e8c21e | 31 | startup(); |
PixArtVY | 0:71ff24e8c21e | 32 | |
PixArtVY | 0:71ff24e8c21e | 33 | pc.printf("Program START\n\r"); |
PixArtVY | 0:71ff24e8c21e | 34 | pc.printf("ID Check: %2X\n\r", readRegister(0x00)); //Checks product ID to make sure communication protocol is working properly. |
PixArtVY | 0:71ff24e8c21e | 35 | if(readRegister(0x00) != 0x41) |
PixArtVY | 0:71ff24e8c21e | 36 | { |
PixArtVY | 0:71ff24e8c21e | 37 | pc.printf("Communication protocol error! Terminating program.\n\r"); |
PixArtVY | 0:71ff24e8c21e | 38 | return 0; |
PixArtVY | 0:71ff24e8c21e | 39 | } |
PixArtVY | 0:71ff24e8c21e | 40 | |
PixArtVY | 0:71ff24e8c21e | 41 | initialize(); |
PixArtVY | 0:71ff24e8c21e | 42 | load(optimize, optimize_size); //Load register settings from the "initialize" array |
PixArtVY | 0:71ff24e8c21e | 43 | |
PixArtVY | 0:71ff24e8c21e | 44 | while(1) |
PixArtVY | 0:71ff24e8c21e | 45 | { |
PixArtVY | 0:71ff24e8c21e | 46 | //pc.printf("MOTION bit: %2X\n\r", (readRegister(0x02) & 0x80) >> 7); //Prints motion bit for debugging. 1 = motion detected. 0 = no motion detected. |
PixArtVY | 0:71ff24e8c21e | 47 | |
PixArtVY | 0:71ff24e8c21e | 48 | if(readRegister(0x02) & 0x80) |
PixArtVY | 0:71ff24e8c21e | 49 | { |
PixArtVY | 0:71ff24e8c21e | 50 | grabData(); |
PixArtVY | 0:71ff24e8c21e | 51 | printData(); |
PixArtVY | 0:71ff24e8c21e | 52 | } |
PixArtVY | 0:71ff24e8c21e | 53 | } |
PixArtVY | 0:71ff24e8c21e | 54 | } |