Reference firmware for PixArt's PAT9130EW 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
00001 // PAT9130EW: Optical Tracking Miniature Chip reference code. 00002 // Version: 1.1 00003 // Latest Revision Date: 18 July 2018 00004 // By PixArt Imaging Inc. 00005 // Primary Engineer: Vincent Yeh (PixArt USA) 00006 00007 // Copyright [2018] [Vincent Yeh] 00008 // 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: 00009 // http://www.apache.org/licenses/LICENSE-2.0 00010 00011 00012 /* 00013 //======================= 00014 //Revision History 00015 //======================= 00016 Version 1.1 -- 18 July 2018 00017 Added apache license notice. 00018 00019 Version 1.0 -- 16 Apr. 2018 00020 First release. 00021 */ 00022 00023 #include "mbed.h" 00024 #include "registerArrays.h" 00025 #include "SPIcommFunctions.h" 00026 00027 int main() 00028 { 00029 pc.baud(115200); // Set baud rate to 115200. Remember to sync serial terminal baud rate to the same value. 00030 00031 spi.format(8,3); // Set SPI to 8 bits with inverted polarity and phase-shifted to second edge. 00032 spi.frequency(1000000); // Set frequency for SPI communication. 00033 cs = 1; // Initialize chip select as inactive. 00034 00035 pc.printf("Program START\n\r"); 00036 00037 pc.printf("ID Check: %2X\n\r", readRegister(0x00)); //Checks product ID to make sure communication protocol is working properly. 00038 if(readRegister(0x00) != 0x31) 00039 { 00040 pc.printf("Communication protocol error! Terminating program.\n\r"); 00041 return 0; 00042 } 00043 00044 writeRegister(0x06, 0x80); //Software reset (i.e. set bit7 to 1) 00045 wait_ms(1); //Delay 1 ms for chip reset timing. 00046 00047 pc.printf("ID Check #2: %2X\n\r", readRegister(0x00)); //Checks product ID after resetting to make sure communication protocol is working properly. 00048 if(readRegister(0x00) != 0x31) 00049 { 00050 pc.printf("Communication protocol error! Terminating program.\n\r"); 00051 return 0; 00052 } 00053 00054 load(initialize, initialize_size); //Load register settings from the "initialize" array (see registerArrays.h) 00055 00056 while(1) 00057 { 00058 //pc.printf("MOTION bit: %2X\n\r", (readRegister(0x02) & 0x80) >> 7); //Prints motion bit for debugging. 1 = motion detected. 0 = no motion detected. 00059 00060 if(readRegister(0x02) & 0x80) 00061 { 00062 grabData(); 00063 printData(); 00064 } 00065 } 00066 }
Generated on Fri Jul 15 2022 11:19:13 by 1.7.2