Reference firmware for PixArt's PAA5100 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:782127a132a3, 2018-07-18 (annotated)
- Committer:
- PixArtVY
- Date:
- Wed Jul 18 18:37:03 2018 +0000
- Revision:
- 1:782127a132a3
- Parent:
- 0:c8a2256e02c2
Added Apache License notice.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
PixArtVY | 0:c8a2256e02c2 | 1 | // PAA5100JE-Q: Optical Tracking Chip reference code. |
PixArtVY | 1:782127a132a3 | 2 | // Version: 1.1 |
PixArtVY | 1:782127a132a3 | 3 | // Latest Revision Date: 18 July 2018 |
PixArtVY | 0:c8a2256e02c2 | 4 | // By PixArt Imaging Inc. |
PixArtVY | 0:c8a2256e02c2 | 5 | // Primary Engineer: Vincent Yeh (PixArt USA) |
PixArtVY | 0:c8a2256e02c2 | 6 | |
PixArtVY | 1:782127a132a3 | 7 | // Copyright [2018] [Vincent Yeh] |
PixArtVY | 1:782127a132a3 | 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:782127a132a3 | 9 | // http://www.apache.org/licenses/LICENSE-2.0 |
PixArtVY | 1:782127a132a3 | 10 | |
PixArtVY | 1:782127a132a3 | 11 | |
PixArtVY | 0:c8a2256e02c2 | 12 | /* |
PixArtVY | 0:c8a2256e02c2 | 13 | //======================= |
PixArtVY | 0:c8a2256e02c2 | 14 | //Revision History |
PixArtVY | 0:c8a2256e02c2 | 15 | //======================= |
PixArtVY | 1:782127a132a3 | 16 | Version 1.1 -- 18 July 2018 |
PixArtVY | 1:782127a132a3 | 17 | Added apache license notice. |
PixArtVY | 1:782127a132a3 | 18 | |
PixArtVY | 0:c8a2256e02c2 | 19 | Version 1.0 -- 4 Apr. 2018 |
PixArtVY | 0:c8a2256e02c2 | 20 | First release. |
PixArtVY | 0:c8a2256e02c2 | 21 | */ |
PixArtVY | 0:c8a2256e02c2 | 22 | |
PixArtVY | 0:c8a2256e02c2 | 23 | #include "mbed.h" |
PixArtVY | 0:c8a2256e02c2 | 24 | #include "SPIcommFunctions.h" |
PixArtVY | 0:c8a2256e02c2 | 25 | |
PixArtVY | 0:c8a2256e02c2 | 26 | int main() |
PixArtVY | 0:c8a2256e02c2 | 27 | { |
PixArtVY | 0:c8a2256e02c2 | 28 | pc.baud(115200); // Set baud rate to 115200. Remember to sync serial terminal baud rate to the same value. |
PixArtVY | 0:c8a2256e02c2 | 29 | |
PixArtVY | 0:c8a2256e02c2 | 30 | spi.format(8,3); // Set SPI to 8 bits with inverted polarity and phase-shifted to second edge. |
PixArtVY | 0:c8a2256e02c2 | 31 | spi.frequency(1000000); // Set frequency for SPI communication. |
PixArtVY | 0:c8a2256e02c2 | 32 | cs = 1; // Initialize chip select as inactive. |
PixArtVY | 0:c8a2256e02c2 | 33 | |
PixArtVY | 0:c8a2256e02c2 | 34 | pc.printf("Program START\n\r"); |
PixArtVY | 0:c8a2256e02c2 | 35 | |
PixArtVY | 0:c8a2256e02c2 | 36 | pc.printf("ID Check: %2X\n\r", readRegister(0x00)); //Checks product ID to make sure communication protocol is working properly. |
PixArtVY | 0:c8a2256e02c2 | 37 | if(readRegister(0x00) != 0x49) |
PixArtVY | 0:c8a2256e02c2 | 38 | { |
PixArtVY | 0:c8a2256e02c2 | 39 | pc.printf("Communication protocol error! Terminating program.\n\r"); |
PixArtVY | 0:c8a2256e02c2 | 40 | return 0; |
PixArtVY | 0:c8a2256e02c2 | 41 | } |
PixArtVY | 0:c8a2256e02c2 | 42 | |
PixArtVY | 0:c8a2256e02c2 | 43 | |
PixArtVY | 0:c8a2256e02c2 | 44 | startupCheck(); |
PixArtVY | 0:c8a2256e02c2 | 45 | if(startupFail == 3) |
PixArtVY | 0:c8a2256e02c2 | 46 | { |
PixArtVY | 0:c8a2256e02c2 | 47 | pc.printf("Start-up failed! Power cycle the chip and try again.\n\r"); |
PixArtVY | 0:c8a2256e02c2 | 48 | return 0; |
PixArtVY | 0:c8a2256e02c2 | 49 | } |
PixArtVY | 0:c8a2256e02c2 | 50 | |
PixArtVY | 0:c8a2256e02c2 | 51 | initializeSensor(); |
PixArtVY | 0:c8a2256e02c2 | 52 | |
PixArtVY | 0:c8a2256e02c2 | 53 | while(1) |
PixArtVY | 0:c8a2256e02c2 | 54 | { |
PixArtVY | 0:c8a2256e02c2 | 55 | //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:c8a2256e02c2 | 56 | |
PixArtVY | 0:c8a2256e02c2 | 57 | if(readRegister(0x02) & 0x80) |
PixArtVY | 0:c8a2256e02c2 | 58 | { |
PixArtVY | 0:c8a2256e02c2 | 59 | grabData(); |
PixArtVY | 0:c8a2256e02c2 | 60 | printData(); |
PixArtVY | 0:c8a2256e02c2 | 61 | } |
PixArtVY | 0:c8a2256e02c2 | 62 | } |
PixArtVY | 0:c8a2256e02c2 | 63 | } |