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@0:71ff24e8c21e, 2018-04-10 (annotated)
- Committer:
- PixArtVY
- Date:
- Tue Apr 10 20:17:47 2018 +0000
- Revision:
- 0:71ff24e8c21e
- Child:
- 1:1d99f5c9581f
First revision.
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 | 0:71ff24e8c21e | 2 | // Version: 1.0 |
PixArtVY | 0:71ff24e8c21e | 3 | // Latest Revision Date: 9 Apr. 2018 |
PixArtVY | 0:71ff24e8c21e | 4 | // By PixArt Imaging Inc. |
PixArtVY | 0:71ff24e8c21e | 5 | // Primary Engineer: Vincent Yeh (PixArt USA) |
PixArtVY | 0:71ff24e8c21e | 6 | |
PixArtVY | 0:71ff24e8c21e | 7 | /* |
PixArtVY | 0:71ff24e8c21e | 8 | //======================= |
PixArtVY | 0:71ff24e8c21e | 9 | //Revision History |
PixArtVY | 0:71ff24e8c21e | 10 | //======================= |
PixArtVY | 0:71ff24e8c21e | 11 | Version 1.0 -- 9 Apr. 2018 |
PixArtVY | 0:71ff24e8c21e | 12 | First release. |
PixArtVY | 0:71ff24e8c21e | 13 | */ |
PixArtVY | 0:71ff24e8c21e | 14 | |
PixArtVY | 0:71ff24e8c21e | 15 | #include "mbed.h" |
PixArtVY | 0:71ff24e8c21e | 16 | #include "registerArrays.h" |
PixArtVY | 0:71ff24e8c21e | 17 | #include "I2CcommFunctions.h" |
PixArtVY | 0:71ff24e8c21e | 18 | |
PixArtVY | 0:71ff24e8c21e | 19 | int main() |
PixArtVY | 0:71ff24e8c21e | 20 | { |
PixArtVY | 0:71ff24e8c21e | 21 | pc.baud(115200); // Set baud rate to 115200. Remember to sync serial terminal baud rate to the same value. |
PixArtVY | 0:71ff24e8c21e | 22 | i2c.frequency(400000); // Set frequency for I2C communication. |
PixArtVY | 0:71ff24e8c21e | 23 | startup(); |
PixArtVY | 0:71ff24e8c21e | 24 | |
PixArtVY | 0:71ff24e8c21e | 25 | pc.printf("Program START\n\r"); |
PixArtVY | 0:71ff24e8c21e | 26 | pc.printf("ID Check: %2X\n\r", readRegister(0x00)); //Checks product ID to make sure communication protocol is working properly. |
PixArtVY | 0:71ff24e8c21e | 27 | if(readRegister(0x00) != 0x41) |
PixArtVY | 0:71ff24e8c21e | 28 | { |
PixArtVY | 0:71ff24e8c21e | 29 | pc.printf("Communication protocol error! Terminating program.\n\r"); |
PixArtVY | 0:71ff24e8c21e | 30 | return 0; |
PixArtVY | 0:71ff24e8c21e | 31 | } |
PixArtVY | 0:71ff24e8c21e | 32 | |
PixArtVY | 0:71ff24e8c21e | 33 | initialize(); |
PixArtVY | 0:71ff24e8c21e | 34 | load(optimize, optimize_size); //Load register settings from the "initialize" array |
PixArtVY | 0:71ff24e8c21e | 35 | |
PixArtVY | 0:71ff24e8c21e | 36 | while(1) |
PixArtVY | 0:71ff24e8c21e | 37 | { |
PixArtVY | 0:71ff24e8c21e | 38 | //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 | 39 | |
PixArtVY | 0:71ff24e8c21e | 40 | if(readRegister(0x02) & 0x80) |
PixArtVY | 0:71ff24e8c21e | 41 | { |
PixArtVY | 0:71ff24e8c21e | 42 | grabData(); |
PixArtVY | 0:71ff24e8c21e | 43 | printData(); |
PixArtVY | 0:71ff24e8c21e | 44 | } |
PixArtVY | 0:71ff24e8c21e | 45 | } |
PixArtVY | 0:71ff24e8c21e | 46 | } |