Direct copy of the library, but apparently I made a change?

Fork of SHTx by Roy van Dam

Committer:
NegativeBlack
Date:
Thu Nov 18 10:23:43 2010 +0000
Revision:
0:d55659b0c4a0
Child:
1:8465801be23f

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
NegativeBlack 0:d55659b0c4a0 1 /**
NegativeBlack 0:d55659b0c4a0 2 * Copyright (c) 2010 Roy van Dam <roy@negative-black.org>
NegativeBlack 0:d55659b0c4a0 3 * All rights reserved.
NegativeBlack 0:d55659b0c4a0 4 *
NegativeBlack 0:d55659b0c4a0 5 * Redistribution and use in source and binary forms, with or without
NegativeBlack 0:d55659b0c4a0 6 * modification, are permitted provided that the following conditions
NegativeBlack 0:d55659b0c4a0 7 * are met:
NegativeBlack 0:d55659b0c4a0 8 * 1. Redistributions of source code must retain the above copyright
NegativeBlack 0:d55659b0c4a0 9 * notice, this list of conditions and the following disclaimer.
NegativeBlack 0:d55659b0c4a0 10 * 2. Redistributions in binary form must reproduce the above copyright
NegativeBlack 0:d55659b0c4a0 11 * notice, this list of conditions and the following disclaimer in the
NegativeBlack 0:d55659b0c4a0 12 * documentation and/or other materials provided with the distribution.
NegativeBlack 0:d55659b0c4a0 13 *
NegativeBlack 0:d55659b0c4a0 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
NegativeBlack 0:d55659b0c4a0 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
NegativeBlack 0:d55659b0c4a0 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
NegativeBlack 0:d55659b0c4a0 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
NegativeBlack 0:d55659b0c4a0 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
NegativeBlack 0:d55659b0c4a0 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
NegativeBlack 0:d55659b0c4a0 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
NegativeBlack 0:d55659b0c4a0 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
NegativeBlack 0:d55659b0c4a0 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
NegativeBlack 0:d55659b0c4a0 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
NegativeBlack 0:d55659b0c4a0 24 * SUCH DAMAGE.
NegativeBlack 0:d55659b0c4a0 25 */
NegativeBlack 0:d55659b0c4a0 26
NegativeBlack 0:d55659b0c4a0 27 #ifndef _I2C_HPP_
NegativeBlack 0:d55659b0c4a0 28 #define _I2C_HPP_
NegativeBlack 0:d55659b0c4a0 29
NegativeBlack 0:d55659b0c4a0 30 #include "mbed.h"
NegativeBlack 0:d55659b0c4a0 31
NegativeBlack 0:d55659b0c4a0 32 namespace SHTx {
NegativeBlack 0:d55659b0c4a0 33 /**
NegativeBlack 0:d55659b0c4a0 34 * Class: I2C
NegativeBlack 0:d55659b0c4a0 35 * Humidity and Temperature Sensor - SHT15
NegativeBlack 0:d55659b0c4a0 36 * I2C Bit-bang master driver.
NegativeBlack 0:d55659b0c4a0 37 */
NegativeBlack 0:d55659b0c4a0 38 class I2C {
NegativeBlack 0:d55659b0c4a0 39 private:
NegativeBlack 0:d55659b0c4a0 40 DigitalInOut scl_pin;
NegativeBlack 0:d55659b0c4a0 41 DigitalInOut sda_pin;
NegativeBlack 0:d55659b0c4a0 42
NegativeBlack 0:d55659b0c4a0 43 uint32_t frequency;
NegativeBlack 0:d55659b0c4a0 44
NegativeBlack 0:d55659b0c4a0 45 public:
NegativeBlack 0:d55659b0c4a0 46 /**
NegativeBlack 0:d55659b0c4a0 47 * Constructor: SHTx::I2C
NegativeBlack 0:d55659b0c4a0 48 * Create an I2C Master interface, connected to the specified pins.
NegativeBlack 0:d55659b0c4a0 49 * Bit-bang I2C driver to get around the lousy I2C implementation in the
NegativeBlack 0:d55659b0c4a0 50 * SHTx interface...
NegativeBlack 0:d55659b0c4a0 51 *
NegativeBlack 0:d55659b0c4a0 52 * Variables:
NegativeBlack 0:d55659b0c4a0 53 * sda - I2C data line pin
NegativeBlack 0:d55659b0c4a0 54 * scl - I2C clock line pin
NegativeBlack 0:d55659b0c4a0 55 */
NegativeBlack 0:d55659b0c4a0 56 I2C(PinName sda, PinName scl);
NegativeBlack 0:d55659b0c4a0 57
NegativeBlack 0:d55659b0c4a0 58 /**
NegativeBlack 0:d55659b0c4a0 59 * Function: setFrequency
NegativeBlack 0:d55659b0c4a0 60 * Set the frequency of the SHTx::I2C interface
NegativeBlack 0:d55659b0c4a0 61 *
NegativeBlack 0:d55659b0c4a0 62 * Variables:
NegativeBlack 0:d55659b0c4a0 63 * hz - The bus frequency in hertz
NegativeBlack 0:d55659b0c4a0 64 */
NegativeBlack 0:d55659b0c4a0 65 void setFrequency(uint32_t hz);
NegativeBlack 0:d55659b0c4a0 66
NegativeBlack 0:d55659b0c4a0 67 /**
NegativeBlack 0:d55659b0c4a0 68 * Function: start
NegativeBlack 0:d55659b0c4a0 69 * Issue start condition on the SHTx::I2C bus
NegativeBlack 0:d55659b0c4a0 70 */
NegativeBlack 0:d55659b0c4a0 71 void start(void);
NegativeBlack 0:d55659b0c4a0 72
NegativeBlack 0:d55659b0c4a0 73 /**
NegativeBlack 0:d55659b0c4a0 74 * Function: stop
NegativeBlack 0:d55659b0c4a0 75 * Issue stop condition on the SHTx::I2C bus
NegativeBlack 0:d55659b0c4a0 76 */
NegativeBlack 0:d55659b0c4a0 77 void stop(void);
NegativeBlack 0:d55659b0c4a0 78
NegativeBlack 0:d55659b0c4a0 79 /**
NegativeBlack 0:d55659b0c4a0 80 * Function: wait
NegativeBlack 0:d55659b0c4a0 81 * Wait for SHT15 to complete measurement.
NegativeBlack 0:d55659b0c4a0 82 * Max timeout 500ms.
NegativeBlack 0:d55659b0c4a0 83 *
NegativeBlack 0:d55659b0c4a0 84 * Variables:
NegativeBlack 0:d55659b0c4a0 85 * returns - true if an ACK was received, false otherwise
NegativeBlack 0:d55659b0c4a0 86 */
NegativeBlack 0:d55659b0c4a0 87 bool wait(void);
NegativeBlack 0:d55659b0c4a0 88
NegativeBlack 0:d55659b0c4a0 89 /**
NegativeBlack 0:d55659b0c4a0 90 * Function: write
NegativeBlack 0:d55659b0c4a0 91 * Write single byte out on the SHTx::I2C bus
NegativeBlack 0:d55659b0c4a0 92 *
NegativeBlack 0:d55659b0c4a0 93 * Variables:
NegativeBlack 0:d55659b0c4a0 94 * data - data to write out on bus
NegativeBlack 0:d55659b0c4a0 95 * returns - true if an ACK was received, false otherwise
NegativeBlack 0:d55659b0c4a0 96 */
NegativeBlack 0:d55659b0c4a0 97 bool write(uint8_t data);
NegativeBlack 0:d55659b0c4a0 98
NegativeBlack 0:d55659b0c4a0 99 /**
NegativeBlack 0:d55659b0c4a0 100 * Function: write
NegativeBlack 0:d55659b0c4a0 101 * Read single byte form the I2C bus
NegativeBlack 0:d55659b0c4a0 102 *
NegativeBlack 0:d55659b0c4a0 103 * Variables:
NegativeBlack 0:d55659b0c4a0 104 * ack - indicates if the byte is to be acknowledged
NegativeBlack 0:d55659b0c4a0 105 * returns - the read byte
NegativeBlack 0:d55659b0c4a0 106 */
NegativeBlack 0:d55659b0c4a0 107 uint8_t read(bool ack);
NegativeBlack 0:d55659b0c4a0 108
NegativeBlack 0:d55659b0c4a0 109 private:
NegativeBlack 0:d55659b0c4a0 110 /**
NegativeBlack 0:d55659b0c4a0 111 * Function: output
NegativeBlack 0:d55659b0c4a0 112 * Configures sda pin as output
NegativeBlack 0:d55659b0c4a0 113 */
NegativeBlack 0:d55659b0c4a0 114 void output(void);
NegativeBlack 0:d55659b0c4a0 115
NegativeBlack 0:d55659b0c4a0 116 /**
NegativeBlack 0:d55659b0c4a0 117 * Function: input
NegativeBlack 0:d55659b0c4a0 118 * Configures sda pin as input
NegativeBlack 0:d55659b0c4a0 119 */
NegativeBlack 0:d55659b0c4a0 120 void input(void);
NegativeBlack 0:d55659b0c4a0 121
NegativeBlack 0:d55659b0c4a0 122 /**
NegativeBlack 0:d55659b0c4a0 123 * Function: sda
NegativeBlack 0:d55659b0c4a0 124 * Drive sda pin.
NegativeBlack 0:d55659b0c4a0 125 *
NegativeBlack 0:d55659b0c4a0 126 * Variables:
NegativeBlack 0:d55659b0c4a0 127 * value - drive pin high or low
NegativeBlack 0:d55659b0c4a0 128 */
NegativeBlack 0:d55659b0c4a0 129 void sda(bool value);
NegativeBlack 0:d55659b0c4a0 130
NegativeBlack 0:d55659b0c4a0 131 /**
NegativeBlack 0:d55659b0c4a0 132 * Function: scl
NegativeBlack 0:d55659b0c4a0 133 * Drive scl pin.
NegativeBlack 0:d55659b0c4a0 134 *
NegativeBlack 0:d55659b0c4a0 135 * Variables:
NegativeBlack 0:d55659b0c4a0 136 * value - drive pin high or low
NegativeBlack 0:d55659b0c4a0 137 */
NegativeBlack 0:d55659b0c4a0 138 void scl(bool value);
NegativeBlack 0:d55659b0c4a0 139
NegativeBlack 0:d55659b0c4a0 140 /**
NegativeBlack 0:d55659b0c4a0 141 * Function: shift_out
NegativeBlack 0:d55659b0c4a0 142 * Write single bit out on the SHTx::I2C bus
NegativeBlack 0:d55659b0c4a0 143 *
NegativeBlack 0:d55659b0c4a0 144 * Variables:
NegativeBlack 0:d55659b0c4a0 145 * bit - value of the bit to be written.
NegativeBlack 0:d55659b0c4a0 146 */
NegativeBlack 0:d55659b0c4a0 147 void shift_out(bool bit);
NegativeBlack 0:d55659b0c4a0 148
NegativeBlack 0:d55659b0c4a0 149 /**
NegativeBlack 0:d55659b0c4a0 150 * Function: shift_in
NegativeBlack 0:d55659b0c4a0 151 * Read single bit from the SHTx::I2C bus
NegativeBlack 0:d55659b0c4a0 152 *
NegativeBlack 0:d55659b0c4a0 153 * Variables:
NegativeBlack 0:d55659b0c4a0 154 * return - value of the bit read.
NegativeBlack 0:d55659b0c4a0 155 */
NegativeBlack 0:d55659b0c4a0 156 bool shift_in(void);
NegativeBlack 0:d55659b0c4a0 157 };
NegativeBlack 0:d55659b0c4a0 158 }
NegativeBlack 0:d55659b0c4a0 159
NegativeBlack 0:d55659b0c4a0 160 /* !_I2C_HPP_ */
NegativeBlack 0:d55659b0c4a0 161 #endif