Pinscape Controller version 1 fork. This is a fork to allow for ongoing bug fixes to the original controller version, from before the major changes for the expansion board project.
Dependencies: FastIO FastPWM SimpleDMA mbed
Fork of Pinscape_Controller by
TSL1410R/tsl410r.cpp@68:edfecf67a931, 2016-02-15 (annotated)
- Committer:
- mjr
- Date:
- Mon Feb 15 23:03:55 2016 +0000
- Revision:
- 68:edfecf67a931
- Parent:
- 17:ab3cec0c8bf4
- Child:
- 35:e959ffba78fd
Finalize USB library updates to fix compatibility problems introduced in USBHAL_KL25Z overhaul.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mjr | 17:ab3cec0c8bf4 | 1 | #if 0 |
mjr | 17:ab3cec0c8bf4 | 2 | // this file is no longer used - the method bodies are no in the header, |
mjr | 17:ab3cec0c8bf4 | 3 | // which was necessary because of the change to a template class, which |
mjr | 17:ab3cec0c8bf4 | 4 | // itself was necessary because of the use of the FastIO library |
mjr | 17:ab3cec0c8bf4 | 5 | |
mjr | 2:c174f9ee414a | 6 | #include "mbed.h" |
mjr | 2:c174f9ee414a | 7 | #include "tsl1410r.h" |
mjr | 2:c174f9ee414a | 8 | |
mjr | 17:ab3cec0c8bf4 | 9 | template <PinName siPin, PinName clockPin> TSL1410R<siPin, clockPin>:: |
mjr | 17:ab3cec0c8bf4 | 10 | TSL1410R<siPin, clockPin>(PinName aoPort) : ao(aoPort) |
mjr | 2:c174f9ee414a | 11 | { |
mjr | 2:c174f9ee414a | 12 | // clear out power-on noise by clocking through all pixels twice |
mjr | 2:c174f9ee414a | 13 | clear(); |
mjr | 2:c174f9ee414a | 14 | clear(); |
mjr | 2:c174f9ee414a | 15 | } |
mjr | 2:c174f9ee414a | 16 | |
mjr | 17:ab3cec0c8bf4 | 17 | template <PinName siPin, PinName clockPin> void TSL1410R<siPin, clockPin>::clear() |
mjr | 2:c174f9ee414a | 18 | { |
mjr | 2:c174f9ee414a | 19 | // clock in an SI pulse |
mjr | 2:c174f9ee414a | 20 | si = 1; |
mjr | 2:c174f9ee414a | 21 | clock = 1; |
mjr | 2:c174f9ee414a | 22 | clock = 0; |
mjr | 2:c174f9ee414a | 23 | si = 0; |
mjr | 2:c174f9ee414a | 24 | |
mjr | 2:c174f9ee414a | 25 | // clock out all pixels |
mjr | 2:c174f9ee414a | 26 | for (int i = 0 ; i < nPix + 1 ; ++i) { |
mjr | 2:c174f9ee414a | 27 | clock = 1; |
mjr | 2:c174f9ee414a | 28 | clock = 0; |
mjr | 2:c174f9ee414a | 29 | } |
mjr | 2:c174f9ee414a | 30 | } |
mjr | 2:c174f9ee414a | 31 | |
mjr | 17:ab3cec0c8bf4 | 32 | template <PinName siPin, PinName clockPin> void TSL1410R<siPin, clockPin>:: |
mjr | 17:ab3cec0c8bf4 | 33 | read(uint16_t *pix, int n, void (*cb)(void *ctx), void *cbctx, int cbcnt) |
mjr | 2:c174f9ee414a | 34 | { |
mjr | 6:cc35eb643e8f | 35 | // start the next integration cycle by pulsing SI and one clock |
mjr | 2:c174f9ee414a | 36 | si = 1; |
mjr | 2:c174f9ee414a | 37 | clock = 1; |
mjr | 2:c174f9ee414a | 38 | clock = 0; |
mjr | 2:c174f9ee414a | 39 | si = 0; |
mjr | 2:c174f9ee414a | 40 | |
mjr | 2:c174f9ee414a | 41 | // figure how many pixels to skip on each read |
mjr | 2:c174f9ee414a | 42 | int skip = nPix/n - 1; |
mjr | 14:df700b22ca08 | 43 | |
mjr | 14:df700b22ca08 | 44 | // figure the callback interval |
mjr | 14:df700b22ca08 | 45 | int cbInterval = nPix; |
mjr | 14:df700b22ca08 | 46 | if (cb != 0) |
mjr | 14:df700b22ca08 | 47 | cbInterval = nPix/(cbcnt+1); |
mjr | 2:c174f9ee414a | 48 | |
mjr | 14:df700b22ca08 | 49 | // read all of the pixels |
mjr | 14:df700b22ca08 | 50 | for (int src = 0, dst = 0 ; src < nPix ; ) |
mjr | 2:c174f9ee414a | 51 | { |
mjr | 14:df700b22ca08 | 52 | // figure the end of this callback interval |
mjr | 14:df700b22ca08 | 53 | int srcEnd = src + cbInterval; |
mjr | 14:df700b22ca08 | 54 | if (srcEnd > nPix) |
mjr | 14:df700b22ca08 | 55 | srcEnd = nPix; |
mjr | 2:c174f9ee414a | 56 | |
mjr | 14:df700b22ca08 | 57 | // read one callback chunk of pixels |
mjr | 14:df700b22ca08 | 58 | for ( ; src < srcEnd ; ++src) |
mjr | 14:df700b22ca08 | 59 | { |
mjr | 14:df700b22ca08 | 60 | // read this pixel |
mjr | 14:df700b22ca08 | 61 | pix[dst++] = ao.read_u16(); |
mjr | 2:c174f9ee414a | 62 | |
mjr | 14:df700b22ca08 | 63 | // clock in the next pixel |
mjr | 2:c174f9ee414a | 64 | clock = 1; |
mjr | 2:c174f9ee414a | 65 | clock = 0; |
mjr | 14:df700b22ca08 | 66 | |
mjr | 14:df700b22ca08 | 67 | // clock skipped pixels |
mjr | 14:df700b22ca08 | 68 | for (int i = 0 ; i < skip ; ++i, ++src) |
mjr | 14:df700b22ca08 | 69 | { |
mjr | 14:df700b22ca08 | 70 | clock = 1; |
mjr | 14:df700b22ca08 | 71 | clock = 0; |
mjr | 14:df700b22ca08 | 72 | } |
mjr | 2:c174f9ee414a | 73 | } |
mjr | 14:df700b22ca08 | 74 | |
mjr | 14:df700b22ca08 | 75 | // call the callback, if we're not at the last pixel |
mjr | 14:df700b22ca08 | 76 | if (cb != 0 && src < nPix) |
mjr | 14:df700b22ca08 | 77 | (*cb)(cbctx); |
mjr | 2:c174f9ee414a | 78 | } |
mjr | 2:c174f9ee414a | 79 | |
mjr | 2:c174f9ee414a | 80 | // clock out one extra pixel to leave A1 in the high-Z state |
mjr | 2:c174f9ee414a | 81 | clock = 1; |
mjr | 2:c174f9ee414a | 82 | clock = 0; |
mjr | 2:c174f9ee414a | 83 | } |
mjr | 17:ab3cec0c8bf4 | 84 | |
mjr | 17:ab3cec0c8bf4 | 85 | #endif /* 0 */ |