work in progress
Dependencies: FastAnalogIn FastIO USBDevice mbed FastPWM SimpleDMA
Fork of Pinscape_Controller by
TSL1410R/tsl1410r.h@2:c174f9ee414a, 2014-07-22 (annotated)
- Committer:
- mjr
- Date:
- Tue Jul 22 04:33:47 2014 +0000
- Revision:
- 2:c174f9ee414a
- Child:
- 14:df700b22ca08
Before change to ISR for accelerometer
Who changed what in which revision?
User | Revision | Line number | New 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 | 2:c174f9ee414a | 37 | void read(uint16_t *pix, int n); |
mjr | 2:c174f9ee414a | 38 | |
mjr | 2:c174f9ee414a | 39 | // Clock through all pixels to clear the array. Pulses SI at the |
mjr | 2:c174f9ee414a | 40 | // beginning of the operation, which starts a new integration cycle. |
mjr | 2:c174f9ee414a | 41 | // The caller can thus immediately call read() to read the pixels |
mjr | 2:c174f9ee414a | 42 | // integrated while the clear() was taking place. |
mjr | 2:c174f9ee414a | 43 | void clear(); |
mjr | 2:c174f9ee414a | 44 | |
mjr | 2:c174f9ee414a | 45 | // number of pixels in the array |
mjr | 2:c174f9ee414a | 46 | static const int nPix = 1280; |
mjr | 2:c174f9ee414a | 47 | |
mjr | 2:c174f9ee414a | 48 | |
mjr | 2:c174f9ee414a | 49 | private: |
mjr | 2:c174f9ee414a | 50 | DigitalOut si; |
mjr | 2:c174f9ee414a | 51 | DigitalOut clock; |
mjr | 2:c174f9ee414a | 52 | AnalogIn ao; |
mjr | 2:c174f9ee414a | 53 | }; |
mjr | 2:c174f9ee414a | 54 | |
mjr | 2:c174f9ee414a | 55 | #endif /* TSL1410R_H */ |