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-2013 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_SERIAL_API_H
skrawool 0:3954a906acc2 20 #define MBED_SERIAL_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 #include "hal/dma_api.h"
skrawool 0:3954a906acc2 25
skrawool 0:3954a906acc2 26 #if DEVICE_SERIAL
skrawool 0:3954a906acc2 27
skrawool 0:3954a906acc2 28 #define SERIAL_EVENT_TX_SHIFT (2)
skrawool 0:3954a906acc2 29 #define SERIAL_EVENT_RX_SHIFT (8)
skrawool 0:3954a906acc2 30
skrawool 0:3954a906acc2 31 #define SERIAL_EVENT_TX_MASK (0x00FC)
skrawool 0:3954a906acc2 32 #define SERIAL_EVENT_RX_MASK (0x3F00)
skrawool 0:3954a906acc2 33
skrawool 0:3954a906acc2 34 #define SERIAL_EVENT_ERROR (1 << 1)
skrawool 0:3954a906acc2 35
skrawool 0:3954a906acc2 36 /**
skrawool 0:3954a906acc2 37 * @defgroup SerialTXEvents Serial TX Events Macros
skrawool 0:3954a906acc2 38 *
skrawool 0:3954a906acc2 39 * @{
skrawool 0:3954a906acc2 40 */
skrawool 0:3954a906acc2 41 #define SERIAL_EVENT_TX_COMPLETE (1 << (SERIAL_EVENT_TX_SHIFT + 0))
skrawool 0:3954a906acc2 42 #define SERIAL_EVENT_TX_ALL (SERIAL_EVENT_TX_COMPLETE)
skrawool 0:3954a906acc2 43 /**@}*/
skrawool 0:3954a906acc2 44
skrawool 0:3954a906acc2 45 /**
skrawool 0:3954a906acc2 46 * @defgroup SerialRXEvents Serial RX Events Macros
skrawool 0:3954a906acc2 47 *
skrawool 0:3954a906acc2 48 * @{
skrawool 0:3954a906acc2 49 */
skrawool 0:3954a906acc2 50 #define SERIAL_EVENT_RX_COMPLETE (1 << (SERIAL_EVENT_RX_SHIFT + 0))
skrawool 0:3954a906acc2 51 #define SERIAL_EVENT_RX_OVERRUN_ERROR (1 << (SERIAL_EVENT_RX_SHIFT + 1))
skrawool 0:3954a906acc2 52 #define SERIAL_EVENT_RX_FRAMING_ERROR (1 << (SERIAL_EVENT_RX_SHIFT + 2))
skrawool 0:3954a906acc2 53 #define SERIAL_EVENT_RX_PARITY_ERROR (1 << (SERIAL_EVENT_RX_SHIFT + 3))
skrawool 0:3954a906acc2 54 #define SERIAL_EVENT_RX_OVERFLOW (1 << (SERIAL_EVENT_RX_SHIFT + 4))
skrawool 0:3954a906acc2 55 #define SERIAL_EVENT_RX_CHARACTER_MATCH (1 << (SERIAL_EVENT_RX_SHIFT + 5))
skrawool 0:3954a906acc2 56 #define SERIAL_EVENT_RX_ALL (SERIAL_EVENT_RX_OVERFLOW | SERIAL_EVENT_RX_PARITY_ERROR | \
skrawool 0:3954a906acc2 57 SERIAL_EVENT_RX_FRAMING_ERROR | SERIAL_EVENT_RX_OVERRUN_ERROR | \
skrawool 0:3954a906acc2 58 SERIAL_EVENT_RX_COMPLETE | SERIAL_EVENT_RX_CHARACTER_MATCH)
skrawool 0:3954a906acc2 59 /**@}*/
skrawool 0:3954a906acc2 60
skrawool 0:3954a906acc2 61 #define SERIAL_RESERVED_CHAR_MATCH (255)
skrawool 0:3954a906acc2 62
skrawool 0:3954a906acc2 63 typedef enum {
skrawool 0:3954a906acc2 64 ParityNone = 0,
skrawool 0:3954a906acc2 65 ParityOdd = 1,
skrawool 0:3954a906acc2 66 ParityEven = 2,
skrawool 0:3954a906acc2 67 ParityForced1 = 3,
skrawool 0:3954a906acc2 68 ParityForced0 = 4
skrawool 0:3954a906acc2 69 } SerialParity;
skrawool 0:3954a906acc2 70
skrawool 0:3954a906acc2 71 typedef enum {
skrawool 0:3954a906acc2 72 RxIrq,
skrawool 0:3954a906acc2 73 TxIrq
skrawool 0:3954a906acc2 74 } SerialIrq;
skrawool 0:3954a906acc2 75
skrawool 0:3954a906acc2 76 typedef enum {
skrawool 0:3954a906acc2 77 FlowControlNone,
skrawool 0:3954a906acc2 78 FlowControlRTS,
skrawool 0:3954a906acc2 79 FlowControlCTS,
skrawool 0:3954a906acc2 80 FlowControlRTSCTS
skrawool 0:3954a906acc2 81 } FlowControl;
skrawool 0:3954a906acc2 82
skrawool 0:3954a906acc2 83 typedef void (*uart_irq_handler)(uint32_t id, SerialIrq event);
skrawool 0:3954a906acc2 84
skrawool 0:3954a906acc2 85 #if DEVICE_SERIAL_ASYNCH
skrawool 0:3954a906acc2 86 /** Asynch serial HAL structure
skrawool 0:3954a906acc2 87 */
skrawool 0:3954a906acc2 88 typedef struct {
skrawool 0:3954a906acc2 89 struct serial_s serial; /**< Target specific serial structure */
skrawool 0:3954a906acc2 90 struct buffer_s tx_buff; /**< TX buffer */
skrawool 0:3954a906acc2 91 struct buffer_s rx_buff; /**< RX buffer */
skrawool 0:3954a906acc2 92 uint8_t char_match; /**< Character to be matched */
skrawool 0:3954a906acc2 93 uint8_t char_found; /**< State of the matched character */
skrawool 0:3954a906acc2 94 } serial_t;
skrawool 0:3954a906acc2 95
skrawool 0:3954a906acc2 96 #else
skrawool 0:3954a906acc2 97 /** Non-asynch serial HAL structure
skrawool 0:3954a906acc2 98 */
skrawool 0:3954a906acc2 99 typedef struct serial_s serial_t;
skrawool 0:3954a906acc2 100
skrawool 0:3954a906acc2 101 #endif
skrawool 0:3954a906acc2 102
skrawool 0:3954a906acc2 103 #ifdef __cplusplus
skrawool 0:3954a906acc2 104 extern "C" {
skrawool 0:3954a906acc2 105 #endif
skrawool 0:3954a906acc2 106
skrawool 0:3954a906acc2 107 /**
skrawool 0:3954a906acc2 108 * \defgroup hal_GeneralSerial Serial Configuration Functions
skrawool 0:3954a906acc2 109 * @{
skrawool 0:3954a906acc2 110 */
skrawool 0:3954a906acc2 111
skrawool 0:3954a906acc2 112 /** Initialize the serial peripheral. It sets the default parameters for serial
skrawool 0:3954a906acc2 113 * peripheral, and configures its specifieds pins.
skrawool 0:3954a906acc2 114 *
skrawool 0:3954a906acc2 115 * @param obj The serial object
skrawool 0:3954a906acc2 116 * @param tx The TX pin name
skrawool 0:3954a906acc2 117 * @param rx The RX pin name
skrawool 0:3954a906acc2 118 */
skrawool 0:3954a906acc2 119 void serial_init(serial_t *obj, PinName tx, PinName rx);
skrawool 0:3954a906acc2 120
skrawool 0:3954a906acc2 121 /** Release the serial peripheral, not currently invoked. It requires further
skrawool 0:3954a906acc2 122 * resource management.
skrawool 0:3954a906acc2 123 *
skrawool 0:3954a906acc2 124 * @param obj The serial object
skrawool 0:3954a906acc2 125 */
skrawool 0:3954a906acc2 126 void serial_free(serial_t *obj);
skrawool 0:3954a906acc2 127
skrawool 0:3954a906acc2 128 /** Configure the baud rate
skrawool 0:3954a906acc2 129 *
skrawool 0:3954a906acc2 130 * @param obj The serial object
skrawool 0:3954a906acc2 131 * @param baudrate The baud rate to be configured
skrawool 0:3954a906acc2 132 */
skrawool 0:3954a906acc2 133 void serial_baud(serial_t *obj, int baudrate);
skrawool 0:3954a906acc2 134
skrawool 0:3954a906acc2 135 /** Configure the format. Set the number of bits, parity and the number of stop bits
skrawool 0:3954a906acc2 136 *
skrawool 0:3954a906acc2 137 * @param obj The serial object
skrawool 0:3954a906acc2 138 * @param data_bits The number of data bits
skrawool 0:3954a906acc2 139 * @param parity The parity
skrawool 0:3954a906acc2 140 * @param stop_bits The number of stop bits
skrawool 0:3954a906acc2 141 */
skrawool 0:3954a906acc2 142 void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_bits);
skrawool 0:3954a906acc2 143
skrawool 0:3954a906acc2 144 /** The serial interrupt handler registration
skrawool 0:3954a906acc2 145 *
skrawool 0:3954a906acc2 146 * @param obj The serial object
skrawool 0:3954a906acc2 147 * @param handler The interrupt handler which will be invoked when the interrupt fires
skrawool 0:3954a906acc2 148 * @param id The SerialBase object
skrawool 0:3954a906acc2 149 */
skrawool 0:3954a906acc2 150 void serial_irq_handler(serial_t *obj, uart_irq_handler handler, uint32_t id);
skrawool 0:3954a906acc2 151
skrawool 0:3954a906acc2 152 /** Configure serial interrupt. This function is used for word-approach
skrawool 0:3954a906acc2 153 *
skrawool 0:3954a906acc2 154 * @param obj The serial object
skrawool 0:3954a906acc2 155 * @param irq The serial IRQ type (RX or TX)
skrawool 0:3954a906acc2 156 * @param enable Set to non-zero to enable events, or zero to disable them
skrawool 0:3954a906acc2 157 */
skrawool 0:3954a906acc2 158 void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable);
skrawool 0:3954a906acc2 159
skrawool 0:3954a906acc2 160 /** Get character. This is a blocking call, waiting for a character
skrawool 0:3954a906acc2 161 *
skrawool 0:3954a906acc2 162 * @param obj The serial object
skrawool 0:3954a906acc2 163 */
skrawool 0:3954a906acc2 164 int serial_getc(serial_t *obj);
skrawool 0:3954a906acc2 165
skrawool 0:3954a906acc2 166 /** Send a character. This is a blocking call, waiting for a peripheral to be available
skrawool 0:3954a906acc2 167 * for writing
skrawool 0:3954a906acc2 168 *
skrawool 0:3954a906acc2 169 * @param obj The serial object
skrawool 0:3954a906acc2 170 * @param c The character to be sent
skrawool 0:3954a906acc2 171 */
skrawool 0:3954a906acc2 172 void serial_putc(serial_t *obj, int c);
skrawool 0:3954a906acc2 173
skrawool 0:3954a906acc2 174 /** Check if the serial peripheral is readable
skrawool 0:3954a906acc2 175 *
skrawool 0:3954a906acc2 176 * @param obj The serial object
skrawool 0:3954a906acc2 177 * @return Non-zero value if a character can be read, 0 if nothing to read
skrawool 0:3954a906acc2 178 */
skrawool 0:3954a906acc2 179 int serial_readable(serial_t *obj);
skrawool 0:3954a906acc2 180
skrawool 0:3954a906acc2 181 /** Check if the serial peripheral is writable
skrawool 0:3954a906acc2 182 *
skrawool 0:3954a906acc2 183 * @param obj The serial object
skrawool 0:3954a906acc2 184 * @return Non-zero value if a character can be written, 0 otherwise.
skrawool 0:3954a906acc2 185 */
skrawool 0:3954a906acc2 186 int serial_writable(serial_t *obj);
skrawool 0:3954a906acc2 187
skrawool 0:3954a906acc2 188 /** Clear the serial peripheral
skrawool 0:3954a906acc2 189 *
skrawool 0:3954a906acc2 190 * @param obj The serial object
skrawool 0:3954a906acc2 191 */
skrawool 0:3954a906acc2 192 void serial_clear(serial_t *obj);
skrawool 0:3954a906acc2 193
skrawool 0:3954a906acc2 194 /** Set the break
skrawool 0:3954a906acc2 195 *
skrawool 0:3954a906acc2 196 * @param obj The serial object
skrawool 0:3954a906acc2 197 */
skrawool 0:3954a906acc2 198 void serial_break_set(serial_t *obj);
skrawool 0:3954a906acc2 199
skrawool 0:3954a906acc2 200 /** Clear the break
skrawool 0:3954a906acc2 201 *
skrawool 0:3954a906acc2 202 * @param obj The serial object
skrawool 0:3954a906acc2 203 */
skrawool 0:3954a906acc2 204 void serial_break_clear(serial_t *obj);
skrawool 0:3954a906acc2 205
skrawool 0:3954a906acc2 206 /** Configure the TX pin for UART function.
skrawool 0:3954a906acc2 207 *
skrawool 0:3954a906acc2 208 * @param tx The pin name used for TX
skrawool 0:3954a906acc2 209 */
skrawool 0:3954a906acc2 210 void serial_pinout_tx(PinName tx);
skrawool 0:3954a906acc2 211
skrawool 0:3954a906acc2 212 /** Configure the serial for the flow control. It sets flow control in the hardware
skrawool 0:3954a906acc2 213 * if a serial peripheral supports it, otherwise software emulation is used.
skrawool 0:3954a906acc2 214 *
skrawool 0:3954a906acc2 215 * @param obj The serial object
skrawool 0:3954a906acc2 216 * @param type The type of the flow control. Look at the available FlowControl types.
skrawool 0:3954a906acc2 217 * @param rxflow The TX pin name
skrawool 0:3954a906acc2 218 * @param txflow The RX pin name
skrawool 0:3954a906acc2 219 */
skrawool 0:3954a906acc2 220 void serial_set_flow_control(serial_t *obj, FlowControl type, PinName rxflow, PinName txflow);
skrawool 0:3954a906acc2 221
skrawool 0:3954a906acc2 222 #if DEVICE_SERIAL_ASYNCH
skrawool 0:3954a906acc2 223
skrawool 0:3954a906acc2 224 /**@}*/
skrawool 0:3954a906acc2 225
skrawool 0:3954a906acc2 226 /**
skrawool 0:3954a906acc2 227 * \defgroup hal_AsynchSerial Asynchronous Serial Hardware Abstraction Layer
skrawool 0:3954a906acc2 228 * @{
skrawool 0:3954a906acc2 229 */
skrawool 0:3954a906acc2 230
skrawool 0:3954a906acc2 231 /** Begin asynchronous TX transfer. The used buffer is specified in the serial object,
skrawool 0:3954a906acc2 232 * tx_buff
skrawool 0:3954a906acc2 233 *
skrawool 0:3954a906acc2 234 * @param obj The serial object
skrawool 0:3954a906acc2 235 * @param tx The transmit buffer
skrawool 0:3954a906acc2 236 * @param tx_length The number of bytes to transmit
skrawool 0:3954a906acc2 237 * @param tx_width Deprecated argument
skrawool 0:3954a906acc2 238 * @param handler The serial handler
skrawool 0:3954a906acc2 239 * @param event The logical OR of events to be registered
skrawool 0:3954a906acc2 240 * @param hint A suggestion for how to use DMA with this transfer
skrawool 0:3954a906acc2 241 * @return Returns number of data transfered, otherwise returns 0
skrawool 0:3954a906acc2 242 */
skrawool 0:3954a906acc2 243 int serial_tx_asynch(serial_t *obj, const void *tx, size_t tx_length, uint8_t tx_width, uint32_t handler, uint32_t event, DMAUsage hint);
skrawool 0:3954a906acc2 244
skrawool 0:3954a906acc2 245 /** Begin asynchronous RX transfer (enable interrupt for data collecting)
skrawool 0:3954a906acc2 246 * The used buffer is specified in the serial object - rx_buff
skrawool 0:3954a906acc2 247 *
skrawool 0:3954a906acc2 248 * @param obj The serial object
skrawool 0:3954a906acc2 249 * @param rx The receive buffer
skrawool 0:3954a906acc2 250 * @param rx_length The number of bytes to receive
skrawool 0:3954a906acc2 251 * @param rx_width Deprecated argument
skrawool 0:3954a906acc2 252 * @param handler The serial handler
skrawool 0:3954a906acc2 253 * @param event The logical OR of events to be registered
skrawool 0:3954a906acc2 254 * @param handler The serial handler
skrawool 0:3954a906acc2 255 * @param char_match A character in range 0-254 to be matched
skrawool 0:3954a906acc2 256 * @param hint A suggestion for how to use DMA with this transfer
skrawool 0:3954a906acc2 257 */
skrawool 0:3954a906acc2 258 void serial_rx_asynch(serial_t *obj, void *rx, size_t rx_length, uint8_t rx_width, uint32_t handler, uint32_t event, uint8_t char_match, DMAUsage hint);
skrawool 0:3954a906acc2 259
skrawool 0:3954a906acc2 260 /** Attempts to determine if the serial peripheral is already in use for TX
skrawool 0:3954a906acc2 261 *
skrawool 0:3954a906acc2 262 * @param obj The serial object
skrawool 0:3954a906acc2 263 * @return Non-zero if the RX transaction is ongoing, 0 otherwise
skrawool 0:3954a906acc2 264 */
skrawool 0:3954a906acc2 265 uint8_t serial_tx_active(serial_t *obj);
skrawool 0:3954a906acc2 266
skrawool 0:3954a906acc2 267 /** Attempts to determine if the serial peripheral is already in use for RX
skrawool 0:3954a906acc2 268 *
skrawool 0:3954a906acc2 269 * @param obj The serial object
skrawool 0:3954a906acc2 270 * @return Non-zero if the RX transaction is ongoing, 0 otherwise
skrawool 0:3954a906acc2 271 */
skrawool 0:3954a906acc2 272 uint8_t serial_rx_active(serial_t *obj);
skrawool 0:3954a906acc2 273
skrawool 0:3954a906acc2 274 /** The asynchronous TX and RX handler.
skrawool 0:3954a906acc2 275 *
skrawool 0:3954a906acc2 276 * @param obj The serial object
skrawool 0:3954a906acc2 277 * @return Returns event flags if an RX transfer termination condition was met; otherwise returns 0
skrawool 0:3954a906acc2 278 */
skrawool 0:3954a906acc2 279 int serial_irq_handler_asynch(serial_t *obj);
skrawool 0:3954a906acc2 280
skrawool 0:3954a906acc2 281 /** Abort the ongoing TX transaction. It disables the enabled interupt for TX and
skrawool 0:3954a906acc2 282 * flushes the TX hardware buffer if TX FIFO is used
skrawool 0:3954a906acc2 283 *
skrawool 0:3954a906acc2 284 * @param obj The serial object
skrawool 0:3954a906acc2 285 */
skrawool 0:3954a906acc2 286 void serial_tx_abort_asynch(serial_t *obj);
skrawool 0:3954a906acc2 287
skrawool 0:3954a906acc2 288 /** Abort the ongoing RX transaction. It disables the enabled interrupt for RX and
skrawool 0:3954a906acc2 289 * flushes the RX hardware buffer if RX FIFO is used
skrawool 0:3954a906acc2 290 *
skrawool 0:3954a906acc2 291 * @param obj The serial object
skrawool 0:3954a906acc2 292 */
skrawool 0:3954a906acc2 293 void serial_rx_abort_asynch(serial_t *obj);
skrawool 0:3954a906acc2 294
skrawool 0:3954a906acc2 295 /**@}*/
skrawool 0:3954a906acc2 296
skrawool 0:3954a906acc2 297 #endif
skrawool 0:3954a906acc2 298
skrawool 0:3954a906acc2 299 #ifdef __cplusplus
skrawool 0:3954a906acc2 300 }
skrawool 0:3954a906acc2 301 #endif
skrawool 0:3954a906acc2 302
skrawool 0:3954a906acc2 303 #endif
skrawool 0:3954a906acc2 304
skrawool 0:3954a906acc2 305 #endif
skrawool 0:3954a906acc2 306
skrawool 0:3954a906acc2 307 /** @}*/