Reference firmware for PixArt's ADBM-A350 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.
Welcome to the code repository for PixArt's ADBM-A350 sensor and evaluation board.
For general information about this product, please visit this product's components page here:
https://os.mbed.com/components/ADBM-A350-Finger-Navigation-Optical-Sens/
For guides and tips on how to setup and evaluate the ADBM-A350 sensor with the Nordic nRF52-DK microcontroller using this reference code, please visit this guide:
https://os.mbed.com/teams/PixArt/code/ADBM-A350_referenceCode/wiki/Guide-for-nRF52-DK-Platform
For guides and tips on how to setup and evaluate the ADBM-A350 sensor with any mBed-supported microcontroller using this reference code, please visit this guide:
https://os.mbed.com/teams/PixArt/code/ADBM-A350_referenceCode/wiki/Guide-for-Any-Platform
commHeaders/I2CcommFunctions.h@0:a051df82fcdf, 2018-06-25 (annotated)
- Committer:
- PixArtVY
- Date:
- Mon Jun 25 21:14:10 2018 +0000
- Revision:
- 0:a051df82fcdf
First release.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
PixArtVY | 0:a051df82fcdf | 1 | #define I2Cmode //Used to check if the sensor is in I2C mode or SPI mode. |
PixArtVY | 0:a051df82fcdf | 2 | #define I2C_Slave_ID 0x57 //Slave ID is 0x57 only if p22 and p23 are both HIGH. |
PixArtVY | 0:a051df82fcdf | 3 | |
PixArtVY | 0:a051df82fcdf | 4 | //========================================================================= |
PixArtVY | 0:a051df82fcdf | 5 | //Communication pinouts for serial COM port, I2C, and interrupts |
PixArtVY | 0:a051df82fcdf | 6 | //========================================================================= |
PixArtVY | 0:a051df82fcdf | 7 | static Serial pc(USBTX, USBRX); //PC comm |
PixArtVY | 0:a051df82fcdf | 8 | static I2C i2c(p26, p27); //SDA, SCL |
PixArtVY | 0:a051df82fcdf | 9 | static DigitalOut cs(p22); //CS pin for selecting slave address |
PixArtVY | 0:a051df82fcdf | 10 | static DigitalOut MOSI(p23); //MOSI pin for selecting slave address |
PixArtVY | 0:a051df82fcdf | 11 | static DigitalOut shutdown(p20); //Shutdown pin |
PixArtVY | 0:a051df82fcdf | 12 | static DigitalOut IO_sel(p19); //IO interface selection pin (I2C and SPI) |
PixArtVY | 0:a051df82fcdf | 13 | |
PixArtVY | 0:a051df82fcdf | 14 | |
PixArtVY | 0:a051df82fcdf | 15 | //========================================================================= |
PixArtVY | 0:a051df82fcdf | 16 | //Variables and arrays used for communications and data storage |
PixArtVY | 0:a051df82fcdf | 17 | //========================================================================= |
PixArtVY | 0:a051df82fcdf | 18 | int8_t deltaX, deltaY; //Stores the value of one individual motion report. |
PixArtVY | 0:a051df82fcdf | 19 | int totalX, totalY = 0; //Stores the total deltaX and deltaY moved during runtime. |
PixArtVY | 0:a051df82fcdf | 20 | |
PixArtVY | 0:a051df82fcdf | 21 | |
PixArtVY | 0:a051df82fcdf | 22 | //========================================================================= |
PixArtVY | 0:a051df82fcdf | 23 | //Functions used to communicate with the sensor and grab/print data |
PixArtVY | 0:a051df82fcdf | 24 | //========================================================================= |
PixArtVY | 0:a051df82fcdf | 25 | uint8_t readRegister(uint8_t addr); |
PixArtVY | 0:a051df82fcdf | 26 | //This function takes an 8-bit address in the form 0x00 and returns an 8-bit value in the form 0x00. |
PixArtVY | 0:a051df82fcdf | 27 | |
PixArtVY | 0:a051df82fcdf | 28 | void writeRegister(uint8_t addr, uint8_t data); |
PixArtVY | 0:a051df82fcdf | 29 | //This function takes an 8-bit address and 8-bit data. Writes the given data to the given address. |
PixArtVY | 0:a051df82fcdf | 30 | |
PixArtVY | 0:a051df82fcdf | 31 | void load(const uint8_t array[][2], uint8_t arraySize); |
PixArtVY | 0:a051df82fcdf | 32 | //Takes an array of registers/data (found in registerArrays.h) and their size and writes in all the values. |
PixArtVY | 0:a051df82fcdf | 33 | |
PixArtVY | 0:a051df82fcdf | 34 | void grabData(void); |
PixArtVY | 0:a051df82fcdf | 35 | //Grabs the deltaX and deltaY information from the proper registers and formats it into the proper format. |
PixArtVY | 0:a051df82fcdf | 36 | |
PixArtVY | 0:a051df82fcdf | 37 | void printData(void); |
PixArtVY | 0:a051df82fcdf | 38 | //Prints the data out to a serial terminal. |
PixArtVY | 0:a051df82fcdf | 39 | |
PixArtVY | 0:a051df82fcdf | 40 | |
PixArtVY | 0:a051df82fcdf | 41 | |
PixArtVY | 0:a051df82fcdf | 42 | |
PixArtVY | 0:a051df82fcdf | 43 | |
PixArtVY | 0:a051df82fcdf | 44 | //========================================================================= |
PixArtVY | 0:a051df82fcdf | 45 | //Functions definitions |
PixArtVY | 0:a051df82fcdf | 46 | //========================================================================= |
PixArtVY | 0:a051df82fcdf | 47 | uint8_t readRegister(uint8_t addr) |
PixArtVY | 0:a051df82fcdf | 48 | { |
PixArtVY | 0:a051df82fcdf | 49 | uint8_t data; |
PixArtVY | 0:a051df82fcdf | 50 | i2c.write((I2C_Slave_ID << 1), (const char*)&addr, 1, 0); //Send the address to the chip |
PixArtVY | 0:a051df82fcdf | 51 | i2c.read((I2C_Slave_ID << 1), (char*)&data, 1, 0); //Send the memory address where you want to store the read data |
PixArtVY | 0:a051df82fcdf | 52 | return(data); |
PixArtVY | 0:a051df82fcdf | 53 | } |
PixArtVY | 0:a051df82fcdf | 54 | |
PixArtVY | 0:a051df82fcdf | 55 | |
PixArtVY | 0:a051df82fcdf | 56 | //========================================================================= |
PixArtVY | 0:a051df82fcdf | 57 | void writeRegister(uint8_t addr, uint8_t data) |
PixArtVY | 0:a051df82fcdf | 58 | { |
PixArtVY | 0:a051df82fcdf | 59 | char data_write[2]; //Create an array to store the address/data to pass them at the same time. |
PixArtVY | 0:a051df82fcdf | 60 | data_write[0] = addr; //Store the address in the first byte |
PixArtVY | 0:a051df82fcdf | 61 | data_write[1] = data; //Store the data in the second byte |
PixArtVY | 0:a051df82fcdf | 62 | i2c.write((I2C_Slave_ID << 1), data_write, 2, 0); //Send both over at once |
PixArtVY | 0:a051df82fcdf | 63 | |
PixArtVY | 0:a051df82fcdf | 64 | pc.printf("R:%2X, D:%2X\n\r", addr, readRegister(addr)); |
PixArtVY | 0:a051df82fcdf | 65 | //Uncomment this line for debugging. Prints every register write operation. |
PixArtVY | 0:a051df82fcdf | 66 | } |
PixArtVY | 0:a051df82fcdf | 67 | |
PixArtVY | 0:a051df82fcdf | 68 | |
PixArtVY | 0:a051df82fcdf | 69 | //========================================================================= |
PixArtVY | 0:a051df82fcdf | 70 | void load(const uint8_t array[][2], uint8_t arraySize) |
PixArtVY | 0:a051df82fcdf | 71 | { |
PixArtVY | 0:a051df82fcdf | 72 | for(uint8_t q = 0; q < arraySize; q++) |
PixArtVY | 0:a051df82fcdf | 73 | { |
PixArtVY | 0:a051df82fcdf | 74 | writeRegister(array[q][0], array[q][1]); //Writes the given array of registers/data. |
PixArtVY | 0:a051df82fcdf | 75 | } |
PixArtVY | 0:a051df82fcdf | 76 | } |
PixArtVY | 0:a051df82fcdf | 77 | |
PixArtVY | 0:a051df82fcdf | 78 | |
PixArtVY | 0:a051df82fcdf | 79 | //========================================================================= |
PixArtVY | 0:a051df82fcdf | 80 | void grabData(void) |
PixArtVY | 0:a051df82fcdf | 81 | { |
PixArtVY | 0:a051df82fcdf | 82 | deltaX = readRegister(0x03); //Grabs data from the proper registers. |
PixArtVY | 0:a051df82fcdf | 83 | deltaY = readRegister(0x04); |
PixArtVY | 0:a051df82fcdf | 84 | writeRegister(0x02, 0x00); //Clear EVENT and motion registers. |
PixArtVY | 0:a051df82fcdf | 85 | } |
PixArtVY | 0:a051df82fcdf | 86 | |
PixArtVY | 0:a051df82fcdf | 87 | |
PixArtVY | 0:a051df82fcdf | 88 | //========================================================================= |
PixArtVY | 0:a051df82fcdf | 89 | void printData(void) |
PixArtVY | 0:a051df82fcdf | 90 | { |
PixArtVY | 0:a051df82fcdf | 91 | if((deltaX != 0) || (deltaY != 0)) //If there is deltaX or deltaY movement, print the data. |
PixArtVY | 0:a051df82fcdf | 92 | { |
PixArtVY | 0:a051df82fcdf | 93 | totalX += deltaX; |
PixArtVY | 0:a051df82fcdf | 94 | totalY += deltaY; |
PixArtVY | 0:a051df82fcdf | 95 | |
PixArtVY | 0:a051df82fcdf | 96 | pc.printf("deltaX: %d\t\t\tdeltaY: %d\n\r", deltaX, deltaY); //Prints each individual count of deltaX and deltaY. |
PixArtVY | 0:a051df82fcdf | 97 | pc.printf("X-axis Counts: %d\t\tY-axis Counts: %d\n\r", totalX, totalY); //Prints the total movement made during runtime. |
PixArtVY | 0:a051df82fcdf | 98 | } |
PixArtVY | 0:a051df82fcdf | 99 | |
PixArtVY | 0:a051df82fcdf | 100 | deltaX = 0; //Resets deltaX and Y values to zero, otherwise previous data is stored until overwritten. |
PixArtVY | 0:a051df82fcdf | 101 | deltaY = 0; |
PixArtVY | 0:a051df82fcdf | 102 | } |