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.

Committer:
PixArtVY
Date:
Wed Jul 18 18:33:03 2018 +0000
Revision:
1:efa5e5a1e308
Parent:
0:5a34a4387fb0
Added Apache License notice.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
PixArtVY 0:5a34a4387fb0 1 // PAT9130EW: Optical Tracking Miniature Chip reference code.
PixArtVY 1:efa5e5a1e308 2 // Version: 1.1
PixArtVY 1:efa5e5a1e308 3 // Latest Revision Date: 18 July 2018
PixArtVY 0:5a34a4387fb0 4 // By PixArt Imaging Inc.
PixArtVY 0:5a34a4387fb0 5 // Primary Engineer: Vincent Yeh (PixArt USA)
PixArtVY 0:5a34a4387fb0 6
PixArtVY 1:efa5e5a1e308 7 // Copyright [2018] [Vincent Yeh]
PixArtVY 1:efa5e5a1e308 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:efa5e5a1e308 9 // http://www.apache.org/licenses/LICENSE-2.0
PixArtVY 1:efa5e5a1e308 10
PixArtVY 1:efa5e5a1e308 11
PixArtVY 0:5a34a4387fb0 12 /*
PixArtVY 0:5a34a4387fb0 13 //=======================
PixArtVY 0:5a34a4387fb0 14 //Revision History
PixArtVY 0:5a34a4387fb0 15 //=======================
PixArtVY 1:efa5e5a1e308 16 Version 1.1 -- 18 July 2018
PixArtVY 1:efa5e5a1e308 17 Added apache license notice.
PixArtVY 1:efa5e5a1e308 18
PixArtVY 0:5a34a4387fb0 19 Version 1.0 -- 16 Apr. 2018
PixArtVY 0:5a34a4387fb0 20 First release.
PixArtVY 0:5a34a4387fb0 21 */
PixArtVY 0:5a34a4387fb0 22
PixArtVY 0:5a34a4387fb0 23 #include "mbed.h"
PixArtVY 0:5a34a4387fb0 24 #include "registerArrays.h"
PixArtVY 0:5a34a4387fb0 25 #include "SPIcommFunctions.h"
PixArtVY 0:5a34a4387fb0 26
PixArtVY 0:5a34a4387fb0 27 int main()
PixArtVY 0:5a34a4387fb0 28 {
PixArtVY 0:5a34a4387fb0 29 pc.baud(115200); // Set baud rate to 115200. Remember to sync serial terminal baud rate to the same value.
PixArtVY 0:5a34a4387fb0 30
PixArtVY 0:5a34a4387fb0 31 spi.format(8,3); // Set SPI to 8 bits with inverted polarity and phase-shifted to second edge.
PixArtVY 0:5a34a4387fb0 32 spi.frequency(1000000); // Set frequency for SPI communication.
PixArtVY 0:5a34a4387fb0 33 cs = 1; // Initialize chip select as inactive.
PixArtVY 0:5a34a4387fb0 34
PixArtVY 0:5a34a4387fb0 35 pc.printf("Program START\n\r");
PixArtVY 0:5a34a4387fb0 36
PixArtVY 0:5a34a4387fb0 37 pc.printf("ID Check: %2X\n\r", readRegister(0x00)); //Checks product ID to make sure communication protocol is working properly.
PixArtVY 0:5a34a4387fb0 38 if(readRegister(0x00) != 0x31)
PixArtVY 0:5a34a4387fb0 39 {
PixArtVY 0:5a34a4387fb0 40 pc.printf("Communication protocol error! Terminating program.\n\r");
PixArtVY 0:5a34a4387fb0 41 return 0;
PixArtVY 0:5a34a4387fb0 42 }
PixArtVY 0:5a34a4387fb0 43
PixArtVY 0:5a34a4387fb0 44 writeRegister(0x06, 0x80); //Software reset (i.e. set bit7 to 1)
PixArtVY 0:5a34a4387fb0 45 wait_ms(1); //Delay 1 ms for chip reset timing.
PixArtVY 0:5a34a4387fb0 46
PixArtVY 0:5a34a4387fb0 47 pc.printf("ID Check #2: %2X\n\r", readRegister(0x00)); //Checks product ID after resetting to make sure communication protocol is working properly.
PixArtVY 0:5a34a4387fb0 48 if(readRegister(0x00) != 0x31)
PixArtVY 0:5a34a4387fb0 49 {
PixArtVY 0:5a34a4387fb0 50 pc.printf("Communication protocol error! Terminating program.\n\r");
PixArtVY 0:5a34a4387fb0 51 return 0;
PixArtVY 0:5a34a4387fb0 52 }
PixArtVY 0:5a34a4387fb0 53
PixArtVY 0:5a34a4387fb0 54 load(initialize, initialize_size); //Load register settings from the "initialize" array (see registerArrays.h)
PixArtVY 0:5a34a4387fb0 55
PixArtVY 0:5a34a4387fb0 56 while(1)
PixArtVY 0:5a34a4387fb0 57 {
PixArtVY 0:5a34a4387fb0 58 //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:5a34a4387fb0 59
PixArtVY 0:5a34a4387fb0 60 if(readRegister(0x02) & 0x80)
PixArtVY 0:5a34a4387fb0 61 {
PixArtVY 0:5a34a4387fb0 62 grabData();
PixArtVY 0:5a34a4387fb0 63 printData();
PixArtVY 0:5a34a4387fb0 64 }
PixArtVY 0:5a34a4387fb0 65 }
PixArtVY 0:5a34a4387fb0 66 }