Code required to drive the microcontroller of the NMF Atlantis

Dependencies:   mbed WakeUp DHT

Committer:
nmf_atlantis
Date:
Mon Jan 20 15:47:07 2020 +0000
Revision:
0:dbaef09f6d82
NMF Atlantis final version

Who changed what in which revision?

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