PixArt Optical Finger Navigation, OFN, demo program for A350 sensor with library. Alternative porting style in C++. Initial release v1.0.
Dependencies: Pixart_OFN_A
Fork of OFN_A350_Demo by
main.cpp@0:a051df82fcdf, 2018-06-25 (annotated)
- Committer:
- PixArtVY
- Date:
- Mon Jun 25 21:14:10 2018 +0000
- Revision:
- 0:a051df82fcdf
- Child:
- 1:67d6484416a6
First release.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
PixArtVY | 0:a051df82fcdf | 1 | // ADBM-A350: Finger navigation chip. |
PixArtVY | 0:a051df82fcdf | 2 | // Version: 1.0 |
PixArtVY | 0:a051df82fcdf | 3 | // Latest Revision Date: 14 June 2018 |
PixArtVY | 0:a051df82fcdf | 4 | // By PixArt Imaging Inc. |
PixArtVY | 0:a051df82fcdf | 5 | // Primary Engineer: Vincent Yeh (PixArt USA) |
PixArtVY | 0:a051df82fcdf | 6 | |
PixArtVY | 0:a051df82fcdf | 7 | /* |
PixArtVY | 0:a051df82fcdf | 8 | //======================= |
PixArtVY | 0:a051df82fcdf | 9 | //Revision History |
PixArtVY | 0:a051df82fcdf | 10 | //======================= |
PixArtVY | 0:a051df82fcdf | 11 | Version 1.0 -- 14 June 2018 |
PixArtVY | 0:a051df82fcdf | 12 | First release. |
PixArtVY | 0:a051df82fcdf | 13 | */ |
PixArtVY | 0:a051df82fcdf | 14 | |
PixArtVY | 0:a051df82fcdf | 15 | #include "mbed.h" |
PixArtVY | 0:a051df82fcdf | 16 | #include "registerArrays.h" |
PixArtVY | 0:a051df82fcdf | 17 | //#include "I2CcommFunctions.h" |
PixArtVY | 0:a051df82fcdf | 18 | #include "SPIcommFunctions.h" |
PixArtVY | 0:a051df82fcdf | 19 | //Make sure you only have one of either SPIcommFunctions or I2CcommFunctions enabled. You cannot include both headers. |
PixArtVY | 0:a051df82fcdf | 20 | |
PixArtVY | 0:a051df82fcdf | 21 | int main() |
PixArtVY | 0:a051df82fcdf | 22 | { |
PixArtVY | 0:a051df82fcdf | 23 | pc.baud(115200); // Set baud rate to 115200. Remember to sync serial terminal baud rate to the same value. |
PixArtVY | 0:a051df82fcdf | 24 | |
PixArtVY | 0:a051df82fcdf | 25 | #ifdef SPImode |
PixArtVY | 0:a051df82fcdf | 26 | IO_sel = 1; // Set IO_select pin to be HIGH for SPI. |
PixArtVY | 0:a051df82fcdf | 27 | spi.format(8,3); // Set SPI to 8 bits with inverted polarity and phase-shifted to second edge. |
PixArtVY | 0:a051df82fcdf | 28 | spi.frequency(100000); // Set frequency for SPI communication. |
PixArtVY | 0:a051df82fcdf | 29 | cs = 1; // Initialize chip select as inactive. |
PixArtVY | 0:a051df82fcdf | 30 | #endif |
PixArtVY | 0:a051df82fcdf | 31 | |
PixArtVY | 0:a051df82fcdf | 32 | #ifdef I2Cmode |
PixArtVY | 0:a051df82fcdf | 33 | IO_sel = 0; // Set IO_select pin to be LOW for I2C. |
PixArtVY | 0:a051df82fcdf | 34 | i2c.frequency(400000); // Set frequency for I2C communication. |
PixArtVY | 0:a051df82fcdf | 35 | cs = 1; // These two pins are used to determine the device's slave ID. |
PixArtVY | 0:a051df82fcdf | 36 | MOSI = 1; |
PixArtVY | 0:a051df82fcdf | 37 | #endif |
PixArtVY | 0:a051df82fcdf | 38 | |
PixArtVY | 0:a051df82fcdf | 39 | shutdown = 0; |
PixArtVY | 0:a051df82fcdf | 40 | writeRegister(0x3A, 0x5A); //Soft-reset the chip. |
PixArtVY | 0:a051df82fcdf | 41 | |
PixArtVY | 0:a051df82fcdf | 42 | pc.printf("Program START\n\r"); |
PixArtVY | 0:a051df82fcdf | 43 | |
PixArtVY | 0:a051df82fcdf | 44 | pc.printf("ID Check: %2X\n\r", readRegister(0x00)); //Checks product ID to make sure communication protocol is working properly. |
PixArtVY | 0:a051df82fcdf | 45 | if(readRegister(0x00) != 0x88) |
PixArtVY | 0:a051df82fcdf | 46 | { |
PixArtVY | 0:a051df82fcdf | 47 | pc.printf("Communication protocol error! Terminating program.\n\r"); |
PixArtVY | 0:a051df82fcdf | 48 | return 0; |
PixArtVY | 0:a051df82fcdf | 49 | } |
PixArtVY | 0:a051df82fcdf | 50 | |
PixArtVY | 0:a051df82fcdf | 51 | load(initialize, initialize_size); //Load register settings from the "initialize" array (see registerArrays.h) |
PixArtVY | 0:a051df82fcdf | 52 | |
PixArtVY | 0:a051df82fcdf | 53 | while(1) |
PixArtVY | 0:a051df82fcdf | 54 | { |
PixArtVY | 0:a051df82fcdf | 55 | //pc.printf("MOTION bit: %2X\n\r", readRegister(0x02)); //Prints EVENT register for debugging. |
PixArtVY | 0:a051df82fcdf | 56 | |
PixArtVY | 0:a051df82fcdf | 57 | if(readRegister(0x02) & 0x80) |
PixArtVY | 0:a051df82fcdf | 58 | { |
PixArtVY | 0:a051df82fcdf | 59 | grabData(); |
PixArtVY | 0:a051df82fcdf | 60 | printData(); |
PixArtVY | 0:a051df82fcdf | 61 | } |
PixArtVY | 0:a051df82fcdf | 62 | } |
PixArtVY | 0:a051df82fcdf | 63 | } |