SPI read Pixi Cam V1

Committer:
altb2
Date:
Mon Aug 23 11:26:37 2021 +0000
Revision:
4:478d4d9193a1
1st commit, reading pixi cam via SPI

Who changed what in which revision?

UserRevisionLine numberNew contents of line
altb2 4:478d4d9193a1 1 #pragma once
altb2 4:478d4d9193a1 2 #include "mbed.h"
altb2 4:478d4d9193a1 3
altb2 4:478d4d9193a1 4 #define INVALID_BLOCK 20
altb2 4:478d4d9193a1 5 #define CENTER_X 160
altb2 4:478d4d9193a1 6 #define CENTER_Y 100
altb2 4:478d4d9193a1 7 #define NUM_BLOCKS 10
altb2 4:478d4d9193a1 8 //a class to aid in SPI communication with the pixy camera
altb2 4:478d4d9193a1 9
altb2 4:478d4d9193a1 10 //this details the object block format of returned data as described in
altb2 4:478d4d9193a1 11 //http://www.cmucam.org/projects/cmucam5/wiki/Pixy_Serial_Protocol
altb2 4:478d4d9193a1 12
altb2 4:478d4d9193a1 13 //blatantly stole this from their code
altb2 4:478d4d9193a1 14 struct Block
altb2 4:478d4d9193a1 15 {
altb2 4:478d4d9193a1 16 uint16_t signature;
altb2 4:478d4d9193a1 17 uint16_t x;
altb2 4:478d4d9193a1 18 uint16_t y;
altb2 4:478d4d9193a1 19 uint16_t width;
altb2 4:478d4d9193a1 20 uint16_t height;
altb2 4:478d4d9193a1 21 };
altb2 4:478d4d9193a1 22
altb2 4:478d4d9193a1 23 class pixySPI
altb2 4:478d4d9193a1 24 {
altb2 4:478d4d9193a1 25 private:
altb2 4:478d4d9193a1 26 SPI spi;
altb2 4:478d4d9193a1 27 //SPI spi(p5, p6, p7); // mosi, miso, sclk
altb2 4:478d4d9193a1 28 short sync; //the block signature. 16 bits
altb2 4:478d4d9193a1 29 short readTwoBytesLSB();
altb2 4:478d4d9193a1 30 void readNBytes(char* buf, int num);
altb2 4:478d4d9193a1 31 Block blocks[NUM_BLOCKS]; //where the blocks are stored
altb2 4:478d4d9193a1 32 int numBlocks; //amt
altb2 4:478d4d9193a1 33 int bestX;
altb2 4:478d4d9193a1 34 int bestY;
altb2 4:478d4d9193a1 35 int i;
altb2 4:478d4d9193a1 36 public:
altb2 4:478d4d9193a1 37 pixySPI(PinName mosi,PinName miso,PinName sclk, int nBlocks);
altb2 4:478d4d9193a1 38 ~pixySPI();
altb2 4:478d4d9193a1 39 void capture(); //fills in the blocks pointer
altb2 4:478d4d9193a1 40 char getRawData();
altb2 4:478d4d9193a1 41 Block* getBlocks();
altb2 4:478d4d9193a1 42 int getNumBlocks();
altb2 4:478d4d9193a1 43 int getBestX();
altb2 4:478d4d9193a1 44 int getBestY();
altb2 4:478d4d9193a1 45 };