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.
DigitalPinCapture.h@0:c6f86d422a7e, 2014-09-27 (annotated)
- 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?
| User | Revision | Line number | New 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 __DIGITALPINCAPTURE_H__ |
| taylorza | 0:c6f86d422a7e | 5 | #define __DIGITALPINCAPTURE_H__ |
| taylorza | 0:c6f86d422a7e | 6 | |
| taylorza | 0:c6f86d422a7e | 7 | /** Captures the digital wave form of a pin into a timing buffer. */ |
| taylorza | 0:c6f86d422a7e | 8 | class DigitalPinCapture |
| taylorza | 0:c6f86d422a7e | 9 | { |
| taylorza | 0:c6f86d422a7e | 10 | public: |
| taylorza | 0:c6f86d422a7e | 11 | /** Create an instance of DigitalPinCapture connected to the specified pin |
| taylorza | 0:c6f86d422a7e | 12 | * @note The DigitalPinCapture class polls the state of the pin and therefore might be less accurate than |
| taylorza | 0:c6f86d422a7e | 13 | * using InterruptPinCapture. However, it has the advantage that it does not require an interrupt capable pin. |
| taylorza | 0:c6f86d422a7e | 14 | */ |
| taylorza | 0:c6f86d422a7e | 15 | DigitalPinCapture(PinName pin, PinMode mode); |
| taylorza | 0:c6f86d422a7e | 16 | |
| taylorza | 0:c6f86d422a7e | 17 | /** Maximum time to wait for waveform data to arrive or completely fill the timing buffer. |
| taylorza | 0:c6f86d422a7e | 18 | * @param us Timeout specified in microseconds |
| taylorza | 0:c6f86d422a7e | 19 | */ |
| taylorza | 0:c6f86d422a7e | 20 | void setReadTimeout(uint32_t us); |
| taylorza | 0:c6f86d422a7e | 21 | |
| taylorza | 0:c6f86d422a7e | 22 | /** Waits for the pin to transition to the trigger state and proceeds to capture the |
| taylorza | 0:c6f86d422a7e | 23 | * pins transition timing into the timing buffer. |
| taylorza | 0:c6f86d422a7e | 24 | * @param triggerState State that the pin must transistion to before the readings are captured |
| taylorza | 0:c6f86d422a7e | 25 | * @param pReadings Pointer to the timing buffer that will contain the readings in microseconds |
| taylorza | 0:c6f86d422a7e | 26 | * @param count The maximum number of readings that can be held in the buffer |
| taylorza | 0:c6f86d422a7e | 27 | * @returns The number of timings captured in the buffer. |
| taylorza | 0:c6f86d422a7e | 28 | */ |
| taylorza | 0:c6f86d422a7e | 29 | int read(bool triggerState, uint32_t *pReadings, int count); |
| taylorza | 0:c6f86d422a7e | 30 | |
| taylorza | 0:c6f86d422a7e | 31 | /** Immediately start capturing the pin transition timing into the timing buffer. |
| taylorza | 0:c6f86d422a7e | 32 | * @param pInitialState Pointer to a bool that will have the initial state of the pin at the time the capture started. |
| taylorza | 0:c6f86d422a7e | 33 | * @param pReadings Pointer to the timing buffer that will contain the readings in microseconds |
| taylorza | 0:c6f86d422a7e | 34 | * @param count The maximum number of readings that can be held in the buffer |
| taylorza | 0:c6f86d422a7e | 35 | * @returns The number of timings captured in the buffer. |
| taylorza | 0:c6f86d422a7e | 36 | */ |
| taylorza | 0:c6f86d422a7e | 37 | int read(bool *pInitialState, uint32_t *pReadings, int count); |
| taylorza | 0:c6f86d422a7e | 38 | |
| taylorza | 0:c6f86d422a7e | 39 | private: |
| taylorza | 0:c6f86d422a7e | 40 | int readInternal(bool *pPinState, uint32_t *pReadings, int count, bool waitForTrigger); |
| taylorza | 0:c6f86d422a7e | 41 | |
| taylorza | 0:c6f86d422a7e | 42 | private: |
| taylorza | 0:c6f86d422a7e | 43 | DigitalIn _signalPin; |
| taylorza | 0:c6f86d422a7e | 44 | uint32_t _readTimeout; |
| taylorza | 0:c6f86d422a7e | 45 | }; |
| taylorza | 0:c6f86d422a7e | 46 | #endif //__DIGITALPINCAPTURE_H__ |