Provides a simple way to capture the wave form of a pin. For example it can be used to capture the digital state transitions of a pin connected to an IR receiver. These signals can later be played back using the Signal Generator library to control IR devices. The library supports two means of capturing the signal. The signal can be captured on any digital pin using polling while for higher resolution and more accurate timing the interrupt driven capture feature can be used.

Committer:
taylorza
Date:
Sat Sep 27 04:04:16 2014 +0000
Revision:
0:c6f86d422a7e
Initial commit of the Signal Capture library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
taylorza 0:c6f86d422a7e 1 ///////////////////////////////////////////////////////////////////////////////
taylorza 0:c6f86d422a7e 2 // Signal Capture Library
taylorza 0:c6f86d422a7e 3 // Author: Chris Taylor (taylorza)
taylorza 0:c6f86d422a7e 4 #ifndef __INTERRUPTPINCAPTURE_H__
taylorza 0:c6f86d422a7e 5 #define __INTERRUPTPINCAPTURE_H__
taylorza 0:c6f86d422a7e 6
taylorza 0:c6f86d422a7e 7 /** Captures the digital wave form of an interrupt capable pin into a timing buffer. */
taylorza 0:c6f86d422a7e 8 class InterruptPinCapture
taylorza 0:c6f86d422a7e 9 {
taylorza 0:c6f86d422a7e 10 public:
taylorza 0:c6f86d422a7e 11 /** Create an instance of InterruptPinCapture connected to the specified pin */
taylorza 0:c6f86d422a7e 12 InterruptPinCapture(PinName pin, PinMode mode);
taylorza 0:c6f86d422a7e 13
taylorza 0:c6f86d422a7e 14 /** Maximum time to wait for waveform data to arrive or completely fill the timing buffer.
taylorza 0:c6f86d422a7e 15 * @param us Timeout specified in microseconds
taylorza 0:c6f86d422a7e 16 */
taylorza 0:c6f86d422a7e 17 void setReadTimeout(uint32_t us);
taylorza 0:c6f86d422a7e 18
taylorza 0:c6f86d422a7e 19 /** Waits for the pin to transition to the trigger state and proceeds to capture the
taylorza 0:c6f86d422a7e 20 * pins transition timing into the timing buffer.
taylorza 0:c6f86d422a7e 21 * @param triggerState State that the pin must transistion to before the readings are captured
taylorza 0:c6f86d422a7e 22 * @param pReadings Pointer to the timing buffer that will contain the readings in microseconds
taylorza 0:c6f86d422a7e 23 * @param count The maximum number of readings that can be held in the buffer
taylorza 0:c6f86d422a7e 24 * @returns The number of timings captured in the buffer.
taylorza 0:c6f86d422a7e 25 */
taylorza 0:c6f86d422a7e 26 int read(bool triggerState, uint32_t *pReadings, int count);
taylorza 0:c6f86d422a7e 27
taylorza 0:c6f86d422a7e 28 /** Immediately start capturing the pin transition timing into the timing buffer.
taylorza 0:c6f86d422a7e 29 * @param pInitialState Pointer to a bool that will have the initial state of the pin at the time the capture started.
taylorza 0:c6f86d422a7e 30 * @param pReadings Pointer to the timing buffer that will contain the readings in microseconds
taylorza 0:c6f86d422a7e 31 * @param count The maximum number of readings that can be held in the buffer
taylorza 0:c6f86d422a7e 32 * @returns The number of timings captured in the buffer.
taylorza 0:c6f86d422a7e 33 */
taylorza 0:c6f86d422a7e 34 int read(bool *pInitialState, uint32_t *pReadings, int count);
taylorza 0:c6f86d422a7e 35
taylorza 0:c6f86d422a7e 36 private:
taylorza 0:c6f86d422a7e 37 int readInternal(bool *pPinState, uint32_t *pReadings, int count, bool waitForTrigger);
taylorza 0:c6f86d422a7e 38
taylorza 0:c6f86d422a7e 39 private:
taylorza 0:c6f86d422a7e 40 void onPinTransition();
taylorza 0:c6f86d422a7e 41
taylorza 0:c6f86d422a7e 42 enum State
taylorza 0:c6f86d422a7e 43 {
taylorza 0:c6f86d422a7e 44 Stopped,
taylorza 0:c6f86d422a7e 45 WaitForTrigger,
taylorza 0:c6f86d422a7e 46 StartCapturing,
taylorza 0:c6f86d422a7e 47 Capturing
taylorza 0:c6f86d422a7e 48 };
taylorza 0:c6f86d422a7e 49
taylorza 0:c6f86d422a7e 50 private:
taylorza 0:c6f86d422a7e 51 bool _started;
taylorza 0:c6f86d422a7e 52 uint32_t _readTimeout;
taylorza 0:c6f86d422a7e 53 volatile State _state;
taylorza 0:c6f86d422a7e 54 InterruptIn _signalPin;
taylorza 0:c6f86d422a7e 55
taylorza 0:c6f86d422a7e 56 uint32_t *_pBuffer;
taylorza 0:c6f86d422a7e 57 int _bufferMaxCount;
taylorza 0:c6f86d422a7e 58 int _bufferIndex;
taylorza 0:c6f86d422a7e 59 int _startPinState;
taylorza 0:c6f86d422a7e 60
taylorza 0:c6f86d422a7e 61 int _triggerState;
taylorza 0:c6f86d422a7e 62 uint32_t _lastTransitionTime;
taylorza 0:c6f86d422a7e 63 Timer _timer;
taylorza 0:c6f86d422a7e 64 };
taylorza 0:c6f86d422a7e 65 #endif //__INTERRUPTPINCAPTURE_H__