Chris Taylor / SignalCapture
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers DigitalPinCapture.h Source File

DigitalPinCapture.h

00001 ///////////////////////////////////////////////////////////////////////////////
00002 // Signal Capture Library
00003 // Author: Chris Taylor (taylorza)
00004 #ifndef __DIGITALPINCAPTURE_H__
00005 #define __DIGITALPINCAPTURE_H__
00006 
00007 /** Captures the digital wave form of a pin into a timing buffer. */
00008 class DigitalPinCapture
00009 {
00010     public:
00011         /** Create an instance of DigitalPinCapture connected to the specified pin 
00012          * @note The DigitalPinCapture class polls the state of the pin and therefore might be less accurate than
00013          * using InterruptPinCapture. However, it has the advantage that it does not require an interrupt capable pin.
00014         */
00015         DigitalPinCapture(PinName pin, PinMode mode);
00016         
00017         /** Maximum time to wait for waveform data to arrive or completely fill the timing buffer. 
00018          * @param us Timeout specified in microseconds
00019          */
00020         void setReadTimeout(uint32_t us);
00021         
00022         /** Waits for the pin to transition to the trigger state and proceeds to capture the
00023          * pins transition timing into the timing buffer.
00024          * @param triggerState State that the pin must transistion to before the readings are captured
00025          * @param pReadings Pointer to the timing buffer that will contain the readings in microseconds
00026          * @param count The maximum number of readings that can be held in the buffer
00027          * @returns The number of timings captured in the buffer.
00028          */      
00029         int read(bool triggerState, uint32_t *pReadings, int count);
00030         
00031         /** Immediately start capturing the pin transition timing into the timing buffer.
00032          * @param pInitialState Pointer to a bool that will have the initial state of the pin at the time the capture started.
00033          * @param pReadings Pointer to the timing buffer that will contain the readings in microseconds
00034          * @param count The maximum number of readings that can be held in the buffer
00035          * @returns The number of timings captured in the buffer.
00036          */      
00037         int read(bool *pInitialState, uint32_t *pReadings, int count);
00038         
00039     private:
00040         int readInternal(bool *pPinState, uint32_t *pReadings, int count, bool waitForTrigger);
00041         
00042     private:        
00043         DigitalIn _signalPin;            
00044         uint32_t _readTimeout;        
00045 };
00046 #endif //__DIGITALPINCAPTURE_H__