Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
InterruptPinCapture.h
00001 /////////////////////////////////////////////////////////////////////////////// 00002 // Signal Capture Library 00003 // Author: Chris Taylor (taylorza) 00004 #ifndef __INTERRUPTPINCAPTURE_H__ 00005 #define __INTERRUPTPINCAPTURE_H__ 00006 00007 /** Captures the digital wave form of an interrupt capable pin into a timing buffer. */ 00008 class InterruptPinCapture 00009 { 00010 public: 00011 /** Create an instance of InterruptPinCapture connected to the specified pin */ 00012 InterruptPinCapture(PinName pin, PinMode mode); 00013 00014 /** Maximum time to wait for waveform data to arrive or completely fill the timing buffer. 00015 * @param us Timeout specified in microseconds 00016 */ 00017 void setReadTimeout(uint32_t us); 00018 00019 /** Waits for the pin to transition to the trigger state and proceeds to capture the 00020 * pins transition timing into the timing buffer. 00021 * @param triggerState State that the pin must transistion to before the readings are captured 00022 * @param pReadings Pointer to the timing buffer that will contain the readings in microseconds 00023 * @param count The maximum number of readings that can be held in the buffer 00024 * @returns The number of timings captured in the buffer. 00025 */ 00026 int read(bool triggerState, uint32_t *pReadings, int count); 00027 00028 /** Immediately start capturing the pin transition timing into the timing buffer. 00029 * @param pInitialState Pointer to a bool that will have the initial state of the pin at the time the capture started. 00030 * @param pReadings Pointer to the timing buffer that will contain the readings in microseconds 00031 * @param count The maximum number of readings that can be held in the buffer 00032 * @returns The number of timings captured in the buffer. 00033 */ 00034 int read(bool *pInitialState, uint32_t *pReadings, int count); 00035 00036 private: 00037 int readInternal(bool *pPinState, uint32_t *pReadings, int count, bool waitForTrigger); 00038 00039 private: 00040 void onPinTransition(); 00041 00042 enum State 00043 { 00044 Stopped, 00045 WaitForTrigger, 00046 StartCapturing, 00047 Capturing 00048 }; 00049 00050 private: 00051 bool _started; 00052 uint32_t _readTimeout; 00053 volatile State _state; 00054 InterruptIn _signalPin; 00055 00056 uint32_t *_pBuffer; 00057 int _bufferMaxCount; 00058 int _bufferIndex; 00059 int _startPinState; 00060 00061 int _triggerState; 00062 uint32_t _lastTransitionTime; 00063 Timer _timer; 00064 }; 00065 #endif //__INTERRUPTPINCAPTURE_H__
Generated on Fri Jul 15 2022 02:11:20 by
1.7.2