Output digital pulses of specified length and read the length of input pulses.

Dependents:   SeeedUltrasoundRangeFinder RangeFinder senplussd Sprint3_Sonar ... more

Committer:
NickRyder
Date:
Wed Jul 04 15:56:06 2012 +0000
Revision:
0:fb79a4637a64
Released under MIT license.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
NickRyder 0:fb79a4637a64 1 /* Copyright (c) 2012 Nick Ryder, University of Oxford
NickRyder 0:fb79a4637a64 2 * nick.ryder@physics.ox.ac.uk
NickRyder 0:fb79a4637a64 3 *
NickRyder 0:fb79a4637a64 4 * MIT License
NickRyder 0:fb79a4637a64 5 *
NickRyder 0:fb79a4637a64 6 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
NickRyder 0:fb79a4637a64 7 * and associated documentation files (the "Software"), to deal in the Software without restriction,
NickRyder 0:fb79a4637a64 8 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
NickRyder 0:fb79a4637a64 9 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
NickRyder 0:fb79a4637a64 10 * furnished to do so, subject to the following conditions:
NickRyder 0:fb79a4637a64 11 *
NickRyder 0:fb79a4637a64 12 * The above copyright notice and this permission notice shall be included in all copies or
NickRyder 0:fb79a4637a64 13 * substantial portions of the Software.
NickRyder 0:fb79a4637a64 14 *
NickRyder 0:fb79a4637a64 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
NickRyder 0:fb79a4637a64 16 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NickRyder 0:fb79a4637a64 17 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
NickRyder 0:fb79a4637a64 18 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
NickRyder 0:fb79a4637a64 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
NickRyder 0:fb79a4637a64 20 */
NickRyder 0:fb79a4637a64 21
NickRyder 0:fb79a4637a64 22 #ifndef MBED_PULSE_H
NickRyder 0:fb79a4637a64 23 #define MBED_PULSE_H
NickRyder 0:fb79a4637a64 24
NickRyder 0:fb79a4637a64 25 #include "mbed.h"
NickRyder 0:fb79a4637a64 26
NickRyder 0:fb79a4637a64 27 /** Pulse Input/Output Class(es)
NickRyder 0:fb79a4637a64 28 */
NickRyder 0:fb79a4637a64 29
NickRyder 0:fb79a4637a64 30 class PulseInOut {
NickRyder 0:fb79a4637a64 31 public:
NickRyder 0:fb79a4637a64 32 /** Create a PulseInOut object connected to the specified pin
NickRyder 0:fb79a4637a64 33 * @param pin i/o pin to connect to
NickRyder 0:fb79a4637a64 34 */
NickRyder 0:fb79a4637a64 35 PulseInOut(PinName);
NickRyder 0:fb79a4637a64 36 ~PulseInOut();
NickRyder 0:fb79a4637a64 37 /** Set the value of the pin
NickRyder 0:fb79a4637a64 38 * @param val Value to set, 0 for LOW, otherwise HIGH
NickRyder 0:fb79a4637a64 39 */
NickRyder 0:fb79a4637a64 40 void write(int val);
NickRyder 0:fb79a4637a64 41 /** Send a pulse of a given value for a specified time
NickRyder 0:fb79a4637a64 42 * @param val Value to set, 0 for LOW, otherwise HIGH
NickRyder 0:fb79a4637a64 43 * @param time Length of pulse in microseconds
NickRyder 0:fb79a4637a64 44 */
NickRyder 0:fb79a4637a64 45 void write_us(int val, int time);
NickRyder 0:fb79a4637a64 46 /** Return the length of the next HIGH pulse in microsconds
NickRyder 0:fb79a4637a64 47 */
NickRyder 0:fb79a4637a64 48 int read_high_us();
NickRyder 0:fb79a4637a64 49 /** Return the length of the next HIGH pulse in microseconds or -1 if longer than timeout
NickRyder 0:fb79a4637a64 50 * @param timeout Time before pulse reading aborts and returns -1, in microseconds
NickRyder 0:fb79a4637a64 51 */
NickRyder 0:fb79a4637a64 52 int read_high_us(int timeout);
NickRyder 0:fb79a4637a64 53 /** Return the length of the next LOW pulse in microsconds
NickRyder 0:fb79a4637a64 54 */
NickRyder 0:fb79a4637a64 55 int read_low_us();
NickRyder 0:fb79a4637a64 56 /** Return the length of the next LOW pulse in microseconds or -1 if longer than timeout
NickRyder 0:fb79a4637a64 57 * @param timeout Time before pulse reading aborts and returns -1, in microseconds
NickRyder 0:fb79a4637a64 58 */
NickRyder 0:fb79a4637a64 59 int read_low_us(int timeout);
NickRyder 0:fb79a4637a64 60 /** Return the length of the next pulse in microsconds
NickRyder 0:fb79a4637a64 61 */
NickRyder 0:fb79a4637a64 62 int read_us();
NickRyder 0:fb79a4637a64 63 /** Return the length of the next pulse in microseconds or -1 if longer than timeout
NickRyder 0:fb79a4637a64 64 * @param timeout Time before pulse reading aborts and returns -1, in microseconds
NickRyder 0:fb79a4637a64 65 */
NickRyder 0:fb79a4637a64 66 int read_us(int timeout);
NickRyder 0:fb79a4637a64 67 private:
NickRyder 0:fb79a4637a64 68 int startval;
NickRyder 0:fb79a4637a64 69 Timer pulsetime, runtime;
NickRyder 0:fb79a4637a64 70 DigitalInOut io;
NickRyder 0:fb79a4637a64 71 };
NickRyder 0:fb79a4637a64 72
NickRyder 0:fb79a4637a64 73 #endif