PIR grove sensor that sends the sensed data to Thingspeak.com through the wifi module ESP 8266

Dependencies:   mbed

Committer:
skrawool
Date:
Mon Dec 05 16:39:27 2016 +0000
Revision:
0:3954a906acc2
PIR grove sensor that sends the sensed data to thingspeak through the wifi module ESP 8266

Who changed what in which revision?

UserRevisionLine numberNew contents of line
skrawool 0:3954a906acc2 1
skrawool 0:3954a906acc2 2 /** \addtogroup hal */
skrawool 0:3954a906acc2 3 /** @{*/
skrawool 0:3954a906acc2 4 /* mbed Microcontroller Library
skrawool 0:3954a906acc2 5 * Copyright (c) 2006-2015 ARM Limited
skrawool 0:3954a906acc2 6 *
skrawool 0:3954a906acc2 7 * Licensed under the Apache License, Version 2.0 (the "License");
skrawool 0:3954a906acc2 8 * you may not use this file except in compliance with the License.
skrawool 0:3954a906acc2 9 * You may obtain a copy of the License at
skrawool 0:3954a906acc2 10 *
skrawool 0:3954a906acc2 11 * http://www.apache.org/licenses/LICENSE-2.0
skrawool 0:3954a906acc2 12 *
skrawool 0:3954a906acc2 13 * Unless required by applicable law or agreed to in writing, software
skrawool 0:3954a906acc2 14 * distributed under the License is distributed on an "AS IS" BASIS,
skrawool 0:3954a906acc2 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
skrawool 0:3954a906acc2 16 * See the License for the specific language governing permissions and
skrawool 0:3954a906acc2 17 * limitations under the License.
skrawool 0:3954a906acc2 18 */
skrawool 0:3954a906acc2 19 #ifndef MBED_I2C_API_H
skrawool 0:3954a906acc2 20 #define MBED_I2C_API_H
skrawool 0:3954a906acc2 21
skrawool 0:3954a906acc2 22 #include "device.h"
skrawool 0:3954a906acc2 23 #include "hal/buffer.h"
skrawool 0:3954a906acc2 24
skrawool 0:3954a906acc2 25 #if DEVICE_I2C_ASYNCH
skrawool 0:3954a906acc2 26 #include "hal/dma_api.h"
skrawool 0:3954a906acc2 27 #endif
skrawool 0:3954a906acc2 28
skrawool 0:3954a906acc2 29 #if DEVICE_I2C
skrawool 0:3954a906acc2 30
skrawool 0:3954a906acc2 31 /**
skrawool 0:3954a906acc2 32 * @defgroup hal_I2CEvents I2C Events Macros
skrawool 0:3954a906acc2 33 *
skrawool 0:3954a906acc2 34 * @{
skrawool 0:3954a906acc2 35 */
skrawool 0:3954a906acc2 36 #define I2C_EVENT_ERROR (1 << 1)
skrawool 0:3954a906acc2 37 #define I2C_EVENT_ERROR_NO_SLAVE (1 << 2)
skrawool 0:3954a906acc2 38 #define I2C_EVENT_TRANSFER_COMPLETE (1 << 3)
skrawool 0:3954a906acc2 39 #define I2C_EVENT_TRANSFER_EARLY_NACK (1 << 4)
skrawool 0:3954a906acc2 40 #define I2C_EVENT_ALL (I2C_EVENT_ERROR | I2C_EVENT_TRANSFER_COMPLETE | I2C_EVENT_ERROR_NO_SLAVE | I2C_EVENT_TRANSFER_EARLY_NACK)
skrawool 0:3954a906acc2 41
skrawool 0:3954a906acc2 42 /**@}*/
skrawool 0:3954a906acc2 43
skrawool 0:3954a906acc2 44 #if DEVICE_I2C_ASYNCH
skrawool 0:3954a906acc2 45 /** Asynch I2C HAL structure
skrawool 0:3954a906acc2 46 */
skrawool 0:3954a906acc2 47 typedef struct {
skrawool 0:3954a906acc2 48 struct i2c_s i2c; /**< Target specific I2C structure */
skrawool 0:3954a906acc2 49 struct buffer_s tx_buff; /**< Tx buffer */
skrawool 0:3954a906acc2 50 struct buffer_s rx_buff; /**< Rx buffer */
skrawool 0:3954a906acc2 51 } i2c_t;
skrawool 0:3954a906acc2 52
skrawool 0:3954a906acc2 53 #else
skrawool 0:3954a906acc2 54 /** Non-asynch I2C HAL structure
skrawool 0:3954a906acc2 55 */
skrawool 0:3954a906acc2 56 typedef struct i2c_s i2c_t;
skrawool 0:3954a906acc2 57
skrawool 0:3954a906acc2 58 #endif
skrawool 0:3954a906acc2 59
skrawool 0:3954a906acc2 60 enum {
skrawool 0:3954a906acc2 61 I2C_ERROR_NO_SLAVE = -1,
skrawool 0:3954a906acc2 62 I2C_ERROR_BUS_BUSY = -2
skrawool 0:3954a906acc2 63 };
skrawool 0:3954a906acc2 64
skrawool 0:3954a906acc2 65 #ifdef __cplusplus
skrawool 0:3954a906acc2 66 extern "C" {
skrawool 0:3954a906acc2 67 #endif
skrawool 0:3954a906acc2 68
skrawool 0:3954a906acc2 69 /**
skrawool 0:3954a906acc2 70 * \defgroup hal_GeneralI2C I2C Configuration Functions
skrawool 0:3954a906acc2 71 * @{
skrawool 0:3954a906acc2 72 */
skrawool 0:3954a906acc2 73
skrawool 0:3954a906acc2 74 /** Initialize the I2C peripheral. It sets the default parameters for I2C
skrawool 0:3954a906acc2 75 * peripheral, and configures its specifieds pins.
skrawool 0:3954a906acc2 76 *
skrawool 0:3954a906acc2 77 * @param obj The I2C object
skrawool 0:3954a906acc2 78 * @param sda The sda pin
skrawool 0:3954a906acc2 79 * @param scl The scl pin
skrawool 0:3954a906acc2 80 */
skrawool 0:3954a906acc2 81 void i2c_init(i2c_t *obj, PinName sda, PinName scl);
skrawool 0:3954a906acc2 82
skrawool 0:3954a906acc2 83 /** Configure the I2C frequency
skrawool 0:3954a906acc2 84 *
skrawool 0:3954a906acc2 85 * @param obj The I2C object
skrawool 0:3954a906acc2 86 * @param hz Frequency in Hz
skrawool 0:3954a906acc2 87 */
skrawool 0:3954a906acc2 88 void i2c_frequency(i2c_t *obj, int hz);
skrawool 0:3954a906acc2 89
skrawool 0:3954a906acc2 90 /** Send START command
skrawool 0:3954a906acc2 91 *
skrawool 0:3954a906acc2 92 * @param obj The I2C object
skrawool 0:3954a906acc2 93 */
skrawool 0:3954a906acc2 94 int i2c_start(i2c_t *obj);
skrawool 0:3954a906acc2 95
skrawool 0:3954a906acc2 96 /** Send STOP command
skrawool 0:3954a906acc2 97 *
skrawool 0:3954a906acc2 98 * @param obj The I2C object
skrawool 0:3954a906acc2 99 */
skrawool 0:3954a906acc2 100 int i2c_stop(i2c_t *obj);
skrawool 0:3954a906acc2 101
skrawool 0:3954a906acc2 102 /** Blocking reading data
skrawool 0:3954a906acc2 103 *
skrawool 0:3954a906acc2 104 * @param obj The I2C object
skrawool 0:3954a906acc2 105 * @param address 7-bit address (last bit is 1)
skrawool 0:3954a906acc2 106 * @param data The buffer for receiving
skrawool 0:3954a906acc2 107 * @param length Number of bytes to read
skrawool 0:3954a906acc2 108 * @param stop Stop to be generated after the transfer is done
skrawool 0:3954a906acc2 109 * @return Number of read bytes
skrawool 0:3954a906acc2 110 */
skrawool 0:3954a906acc2 111 int i2c_read(i2c_t *obj, int address, char *data, int length, int stop);
skrawool 0:3954a906acc2 112
skrawool 0:3954a906acc2 113 /** Blocking sending data
skrawool 0:3954a906acc2 114 *
skrawool 0:3954a906acc2 115 * @param obj The I2C object
skrawool 0:3954a906acc2 116 * @param address 7-bit address (last bit is 0)
skrawool 0:3954a906acc2 117 * @param data The buffer for sending
skrawool 0:3954a906acc2 118 * @param length Number of bytes to write
skrawool 0:3954a906acc2 119 * @param stop Stop to be generated after the transfer is done
skrawool 0:3954a906acc2 120 * @return Number of written bytes
skrawool 0:3954a906acc2 121 */
skrawool 0:3954a906acc2 122 int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop);
skrawool 0:3954a906acc2 123
skrawool 0:3954a906acc2 124 /** Reset I2C peripheral. TODO: The action here. Most of the implementation sends stop()
skrawool 0:3954a906acc2 125 *
skrawool 0:3954a906acc2 126 * @param obj The I2C object
skrawool 0:3954a906acc2 127 */
skrawool 0:3954a906acc2 128 void i2c_reset(i2c_t *obj);
skrawool 0:3954a906acc2 129
skrawool 0:3954a906acc2 130 /** Read one byte
skrawool 0:3954a906acc2 131 *
skrawool 0:3954a906acc2 132 * @param obj The I2C object
skrawool 0:3954a906acc2 133 * @param last Acknoledge
skrawool 0:3954a906acc2 134 * @return The read byte
skrawool 0:3954a906acc2 135 */
skrawool 0:3954a906acc2 136 int i2c_byte_read(i2c_t *obj, int last);
skrawool 0:3954a906acc2 137
skrawool 0:3954a906acc2 138 /** Write one byte
skrawool 0:3954a906acc2 139 *
skrawool 0:3954a906acc2 140 * @param obj The I2C object
skrawool 0:3954a906acc2 141 * @param data Byte to be written
skrawool 0:3954a906acc2 142 * @return 0 if NAK was received, 1 if ACK was received, 2 for timeout.
skrawool 0:3954a906acc2 143 */
skrawool 0:3954a906acc2 144 int i2c_byte_write(i2c_t *obj, int data);
skrawool 0:3954a906acc2 145
skrawool 0:3954a906acc2 146 /**@}*/
skrawool 0:3954a906acc2 147
skrawool 0:3954a906acc2 148 #if DEVICE_I2CSLAVE
skrawool 0:3954a906acc2 149
skrawool 0:3954a906acc2 150 /**
skrawool 0:3954a906acc2 151 * \defgroup SynchI2C Synchronous I2C Hardware Abstraction Layer for slave
skrawool 0:3954a906acc2 152 * @{
skrawool 0:3954a906acc2 153 */
skrawool 0:3954a906acc2 154
skrawool 0:3954a906acc2 155 /** Configure I2C as slave or master.
skrawool 0:3954a906acc2 156 * @param obj The I2C object
skrawool 0:3954a906acc2 157 * @return non-zero if a value is available
skrawool 0:3954a906acc2 158 */
skrawool 0:3954a906acc2 159 void i2c_slave_mode(i2c_t *obj, int enable_slave);
skrawool 0:3954a906acc2 160
skrawool 0:3954a906acc2 161 /** Check to see if the I2C slave has been addressed.
skrawool 0:3954a906acc2 162 * @param obj The I2C object
skrawool 0:3954a906acc2 163 * @return The status - 1 - read addresses, 2 - write to all slaves,
skrawool 0:3954a906acc2 164 * 3 write addressed, 0 - the slave has not been addressed
skrawool 0:3954a906acc2 165 */
skrawool 0:3954a906acc2 166 int i2c_slave_receive(i2c_t *obj);
skrawool 0:3954a906acc2 167
skrawool 0:3954a906acc2 168 /** Configure I2C as slave or master.
skrawool 0:3954a906acc2 169 * @param obj The I2C object
skrawool 0:3954a906acc2 170 * @return non-zero if a value is available
skrawool 0:3954a906acc2 171 */
skrawool 0:3954a906acc2 172 int i2c_slave_read(i2c_t *obj, char *data, int length);
skrawool 0:3954a906acc2 173
skrawool 0:3954a906acc2 174 /** Configure I2C as slave or master.
skrawool 0:3954a906acc2 175 * @param obj The I2C object
skrawool 0:3954a906acc2 176 * @return non-zero if a value is available
skrawool 0:3954a906acc2 177 */
skrawool 0:3954a906acc2 178 int i2c_slave_write(i2c_t *obj, const char *data, int length);
skrawool 0:3954a906acc2 179
skrawool 0:3954a906acc2 180 /** Configure I2C address.
skrawool 0:3954a906acc2 181 * @param obj The I2C object
skrawool 0:3954a906acc2 182 * @param idx Currently not used
skrawool 0:3954a906acc2 183 * @param address The address to be set
skrawool 0:3954a906acc2 184 * @param mask Currently not used
skrawool 0:3954a906acc2 185 */
skrawool 0:3954a906acc2 186 void i2c_slave_address(i2c_t *obj, int idx, uint32_t address, uint32_t mask);
skrawool 0:3954a906acc2 187
skrawool 0:3954a906acc2 188 #endif
skrawool 0:3954a906acc2 189
skrawool 0:3954a906acc2 190 /**@}*/
skrawool 0:3954a906acc2 191
skrawool 0:3954a906acc2 192 #if DEVICE_I2C_ASYNCH
skrawool 0:3954a906acc2 193
skrawool 0:3954a906acc2 194 /**
skrawool 0:3954a906acc2 195 * \defgroup hal_AsynchI2C Asynchronous I2C Hardware Abstraction Layer
skrawool 0:3954a906acc2 196 * @{
skrawool 0:3954a906acc2 197 */
skrawool 0:3954a906acc2 198
skrawool 0:3954a906acc2 199 /** Start I2C asynchronous transfer
skrawool 0:3954a906acc2 200 *
skrawool 0:3954a906acc2 201 * @param obj The I2C object
skrawool 0:3954a906acc2 202 * @param tx The transmit buffer
skrawool 0:3954a906acc2 203 * @param tx_length The number of bytes to transmit
skrawool 0:3954a906acc2 204 * @param rx The receive buffer
skrawool 0:3954a906acc2 205 * @param rx_length The number of bytes to receive
skrawool 0:3954a906acc2 206 * @param address The address to be set - 7bit or 9bit
skrawool 0:3954a906acc2 207 * @param stop If true, stop will be generated after the transfer is done
skrawool 0:3954a906acc2 208 * @param handler The I2C IRQ handler to be set
skrawool 0:3954a906acc2 209 * @param hint DMA hint usage
skrawool 0:3954a906acc2 210 */
skrawool 0:3954a906acc2 211 void i2c_transfer_asynch(i2c_t *obj, const void *tx, size_t tx_length, void *rx, size_t rx_length, uint32_t address, uint32_t stop, uint32_t handler, uint32_t event, DMAUsage hint);
skrawool 0:3954a906acc2 212
skrawool 0:3954a906acc2 213 /** The asynchronous IRQ handler
skrawool 0:3954a906acc2 214 *
skrawool 0:3954a906acc2 215 * @param obj The I2C object which holds the transfer information
skrawool 0:3954a906acc2 216 * @return Event flags if a transfer termination condition was met, otherwise return 0.
skrawool 0:3954a906acc2 217 */
skrawool 0:3954a906acc2 218 uint32_t i2c_irq_handler_asynch(i2c_t *obj);
skrawool 0:3954a906acc2 219
skrawool 0:3954a906acc2 220 /** Attempts to determine if the I2C peripheral is already in use
skrawool 0:3954a906acc2 221 *
skrawool 0:3954a906acc2 222 * @param obj The I2C object
skrawool 0:3954a906acc2 223 * @return Non-zero if the I2C module is active or zero if it is not
skrawool 0:3954a906acc2 224 */
skrawool 0:3954a906acc2 225 uint8_t i2c_active(i2c_t *obj);
skrawool 0:3954a906acc2 226
skrawool 0:3954a906acc2 227 /** Abort asynchronous transfer
skrawool 0:3954a906acc2 228 *
skrawool 0:3954a906acc2 229 * This function does not perform any check - that should happen in upper layers.
skrawool 0:3954a906acc2 230 * @param obj The I2C object
skrawool 0:3954a906acc2 231 */
skrawool 0:3954a906acc2 232 void i2c_abort_asynch(i2c_t *obj);
skrawool 0:3954a906acc2 233
skrawool 0:3954a906acc2 234 #endif
skrawool 0:3954a906acc2 235
skrawool 0:3954a906acc2 236 /**@}*/
skrawool 0:3954a906acc2 237
skrawool 0:3954a906acc2 238 #ifdef __cplusplus
skrawool 0:3954a906acc2 239 }
skrawool 0:3954a906acc2 240 #endif
skrawool 0:3954a906acc2 241
skrawool 0:3954a906acc2 242 #endif
skrawool 0:3954a906acc2 243
skrawool 0:3954a906acc2 244 #endif
skrawool 0:3954a906acc2 245
skrawool 0:3954a906acc2 246 /** @}*/