work in progress

Dependencies:   FastAnalogIn FastIO USBDevice mbed FastPWM SimpleDMA

Fork of Pinscape_Controller by Mike R

Committer:
mjr
Date:
Fri Sep 26 20:51:02 2014 +0000
Revision:
14:df700b22ca08
Parent:
2:c174f9ee414a
Child:
17:ab3cec0c8bf4
Reduce button input latency by reducing debounce time and polling during CCD read cycle

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mjr 2:c174f9ee414a 1 /*
mjr 2:c174f9ee414a 2 * TSL1410R interface class.
mjr 2:c174f9ee414a 3 *
mjr 2:c174f9ee414a 4 * This provides a high-level interface for the Taos TSL1410R linear CCD array sensor.
mjr 2:c174f9ee414a 5 */
mjr 2:c174f9ee414a 6
mjr 2:c174f9ee414a 7 #include "mbed.h"
mjr 2:c174f9ee414a 8
mjr 2:c174f9ee414a 9 #ifndef TSL1410R_H
mjr 2:c174f9ee414a 10 #define TSL1410R_H
mjr 2:c174f9ee414a 11
mjr 2:c174f9ee414a 12 class TSL1410R
mjr 2:c174f9ee414a 13 {
mjr 2:c174f9ee414a 14 public:
mjr 2:c174f9ee414a 15 // set up with the two DigitalOut ports (SI and clock), and the
mjr 2:c174f9ee414a 16 // analog in port for reading the currently selected pixel value
mjr 2:c174f9ee414a 17 TSL1410R(PinName siPort, PinName clockPort, PinName aoPort);
mjr 2:c174f9ee414a 18
mjr 2:c174f9ee414a 19 // Read the pixels. Fills in pix[] with the pixel values, scaled 0-0xffff.
mjr 2:c174f9ee414a 20 // n is the number of pixels to read; if this is less than the physical
mjr 2:c174f9ee414a 21 // array size (npix), we'll read every mth pixel, where m = npix/n. E.g.,
mjr 2:c174f9ee414a 22 // if you want 640 pixels out of 1280 on the sensor, we'll read every
mjr 2:c174f9ee414a 23 // other pixel. If you want 320, we'll read every fourth pixel.
mjr 2:c174f9ee414a 24 //
mjr 2:c174f9ee414a 25 // We clock an SI pulse at the beginning of the read. This starts the
mjr 2:c174f9ee414a 26 // next integration cycle: the pixel array will reset on the SI, and
mjr 2:c174f9ee414a 27 // the integration starts 18 clocks later. So by the time this returns,
mjr 2:c174f9ee414a 28 // the next sample will have been integrating for npix-18 clocks. In
mjr 2:c174f9ee414a 29 // many cases this is enough time to allow immediately reading the next
mjr 2:c174f9ee414a 30 // sample; if more integration time is required, the caller can simply
mjr 2:c174f9ee414a 31 // sleep/spin for the desired additional time, or can do other work that
mjr 2:c174f9ee414a 32 // takes the desired additional time.
mjr 2:c174f9ee414a 33 //
mjr 2:c174f9ee414a 34 // If the caller has other work to tend to that takes longer than the
mjr 2:c174f9ee414a 35 // desired maximum integration time, it can call clear() to clock out
mjr 2:c174f9ee414a 36 // the current pixels and start a fresh integration cycle.
mjr 14:df700b22ca08 37 void read(uint16_t *pix, int n) { read(pix, n, 0, 0, 0); }
mjr 14:df700b22ca08 38
mjr 14:df700b22ca08 39 // Read with interval callback. We'll call the callback the given
mjr 14:df700b22ca08 40 // number of times per read cycle.
mjr 14:df700b22ca08 41 void read(uint16_t *pix, int n, void (*cb)(void *ctx), void *cbctx, int cbcnt);
mjr 2:c174f9ee414a 42
mjr 2:c174f9ee414a 43 // Clock through all pixels to clear the array. Pulses SI at the
mjr 2:c174f9ee414a 44 // beginning of the operation, which starts a new integration cycle.
mjr 2:c174f9ee414a 45 // The caller can thus immediately call read() to read the pixels
mjr 2:c174f9ee414a 46 // integrated while the clear() was taking place.
mjr 2:c174f9ee414a 47 void clear();
mjr 2:c174f9ee414a 48
mjr 2:c174f9ee414a 49 // number of pixels in the array
mjr 2:c174f9ee414a 50 static const int nPix = 1280;
mjr 2:c174f9ee414a 51
mjr 2:c174f9ee414a 52
mjr 2:c174f9ee414a 53 private:
mjr 2:c174f9ee414a 54 DigitalOut si;
mjr 2:c174f9ee414a 55 DigitalOut clock;
mjr 2:c174f9ee414a 56 AnalogIn ao;
mjr 2:c174f9ee414a 57 };
mjr 2:c174f9ee414a 58
mjr 2:c174f9ee414a 59 #endif /* TSL1410R_H */