an SPI interface the cmu pixy camera

Dependents:   robotic_fish_ver_4_9_pixy UMO

Committer:
sandwich
Date:
Fri Jun 06 16:18:49 2014 +0000
Revision:
7:e57b18779bf1
Parent:
6:4bf8d39fc5ce
Child:
8:a915c5eff55a
added mutex to pixy

Who changed what in which revision?

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