BLE temperature profile using digital DS1820 or analog LM35 sensors

Dependencies:   DS1820

Committer:
gkroussos
Date:
Sat Mar 07 16:23:41 2015 +0000
Revision:
0:637031152314
Working version 1.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gkroussos 0:637031152314 1 /* mbed Microcontroller Library
gkroussos 0:637031152314 2 * Copyright (c) 2006-2013 ARM Limited
gkroussos 0:637031152314 3 *
gkroussos 0:637031152314 4 * Licensed under the Apache License, Version 2.0 (the "License");
gkroussos 0:637031152314 5 * you may not use this file except in compliance with the License.
gkroussos 0:637031152314 6 * You may obtain a copy of the License at
gkroussos 0:637031152314 7 *
gkroussos 0:637031152314 8 * http://www.apache.org/licenses/LICENSE-2.0
gkroussos 0:637031152314 9 *
gkroussos 0:637031152314 10 * Unless required by applicable law or agreed to in writing, software
gkroussos 0:637031152314 11 * distributed under the License is distributed on an "AS IS" BASIS,
gkroussos 0:637031152314 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
gkroussos 0:637031152314 13 * See the License for the specific language governing permissions and
gkroussos 0:637031152314 14 * limitations under the License.
gkroussos 0:637031152314 15 */
gkroussos 0:637031152314 16 #ifndef MBED_SERIALBASE_H
gkroussos 0:637031152314 17 #define MBED_SERIALBASE_H
gkroussos 0:637031152314 18
gkroussos 0:637031152314 19 #include "platform.h"
gkroussos 0:637031152314 20
gkroussos 0:637031152314 21 #if DEVICE_SERIAL
gkroussos 0:637031152314 22
gkroussos 0:637031152314 23 #include "Stream.h"
gkroussos 0:637031152314 24 #include "FunctionPointer.h"
gkroussos 0:637031152314 25 #include "serial_api.h"
gkroussos 0:637031152314 26
gkroussos 0:637031152314 27 namespace mbed {
gkroussos 0:637031152314 28
gkroussos 0:637031152314 29 /** A base class for serial port implementations
gkroussos 0:637031152314 30 * Can't be instantiated directly (use Serial or RawSerial)
gkroussos 0:637031152314 31 */
gkroussos 0:637031152314 32 class SerialBase {
gkroussos 0:637031152314 33
gkroussos 0:637031152314 34 public:
gkroussos 0:637031152314 35 /** Set the baud rate of the serial port
gkroussos 0:637031152314 36 *
gkroussos 0:637031152314 37 * @param baudrate The baudrate of the serial port (default = 9600).
gkroussos 0:637031152314 38 */
gkroussos 0:637031152314 39 void baud(int baudrate);
gkroussos 0:637031152314 40
gkroussos 0:637031152314 41 enum Parity {
gkroussos 0:637031152314 42 None = 0,
gkroussos 0:637031152314 43 Odd,
gkroussos 0:637031152314 44 Even,
gkroussos 0:637031152314 45 Forced1,
gkroussos 0:637031152314 46 Forced0
gkroussos 0:637031152314 47 };
gkroussos 0:637031152314 48
gkroussos 0:637031152314 49 enum IrqType {
gkroussos 0:637031152314 50 RxIrq = 0,
gkroussos 0:637031152314 51 TxIrq
gkroussos 0:637031152314 52 };
gkroussos 0:637031152314 53
gkroussos 0:637031152314 54 enum Flow {
gkroussos 0:637031152314 55 Disabled = 0,
gkroussos 0:637031152314 56 RTS,
gkroussos 0:637031152314 57 CTS,
gkroussos 0:637031152314 58 RTSCTS
gkroussos 0:637031152314 59 };
gkroussos 0:637031152314 60
gkroussos 0:637031152314 61 /** Set the transmission format used by the serial port
gkroussos 0:637031152314 62 *
gkroussos 0:637031152314 63 * @param bits The number of bits in a word (5-8; default = 8)
gkroussos 0:637031152314 64 * @param parity The parity used (SerialBase::None, SerialBase::Odd, SerialBase::Even, SerialBase::Forced1, SerialBase::Forced0; default = SerialBase::None)
gkroussos 0:637031152314 65 * @param stop The number of stop bits (1 or 2; default = 1)
gkroussos 0:637031152314 66 */
gkroussos 0:637031152314 67 void format(int bits=8, Parity parity=SerialBase::None, int stop_bits=1);
gkroussos 0:637031152314 68
gkroussos 0:637031152314 69 /** Determine if there is a character available to read
gkroussos 0:637031152314 70 *
gkroussos 0:637031152314 71 * @returns
gkroussos 0:637031152314 72 * 1 if there is a character available to read,
gkroussos 0:637031152314 73 * 0 otherwise
gkroussos 0:637031152314 74 */
gkroussos 0:637031152314 75 int readable();
gkroussos 0:637031152314 76
gkroussos 0:637031152314 77 /** Determine if there is space available to write a character
gkroussos 0:637031152314 78 *
gkroussos 0:637031152314 79 * @returns
gkroussos 0:637031152314 80 * 1 if there is space to write a character,
gkroussos 0:637031152314 81 * 0 otherwise
gkroussos 0:637031152314 82 */
gkroussos 0:637031152314 83 int writeable();
gkroussos 0:637031152314 84
gkroussos 0:637031152314 85 /** Attach a function to call whenever a serial interrupt is generated
gkroussos 0:637031152314 86 *
gkroussos 0:637031152314 87 * @param fptr A pointer to a void function, or 0 to set as none
gkroussos 0:637031152314 88 * @param type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty)
gkroussos 0:637031152314 89 */
gkroussos 0:637031152314 90 void attach(void (*fptr)(void), IrqType type=RxIrq);
gkroussos 0:637031152314 91
gkroussos 0:637031152314 92 /** Attach a member function to call whenever a serial interrupt is generated
gkroussos 0:637031152314 93 *
gkroussos 0:637031152314 94 * @param tptr pointer to the object to call the member function on
gkroussos 0:637031152314 95 * @param mptr pointer to the member function to be called
gkroussos 0:637031152314 96 * @param type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty)
gkroussos 0:637031152314 97 */
gkroussos 0:637031152314 98 template<typename T>
gkroussos 0:637031152314 99 void attach(T* tptr, void (T::*mptr)(void), IrqType type=RxIrq) {
gkroussos 0:637031152314 100 if((mptr != NULL) && (tptr != NULL)) {
gkroussos 0:637031152314 101 _irq[type].attach(tptr, mptr);
gkroussos 0:637031152314 102 serial_irq_set(&_serial, (SerialIrq)type, 1);
gkroussos 0:637031152314 103 }
gkroussos 0:637031152314 104 }
gkroussos 0:637031152314 105
gkroussos 0:637031152314 106 /** Generate a break condition on the serial line
gkroussos 0:637031152314 107 */
gkroussos 0:637031152314 108 void send_break();
gkroussos 0:637031152314 109
gkroussos 0:637031152314 110 #if DEVICE_SERIAL_FC
gkroussos 0:637031152314 111 /** Set the flow control type on the serial port
gkroussos 0:637031152314 112 *
gkroussos 0:637031152314 113 * @param type the flow control type (Disabled, RTS, CTS, RTSCTS)
gkroussos 0:637031152314 114 * @param flow1 the first flow control pin (RTS for RTS or RTSCTS, CTS for CTS)
gkroussos 0:637031152314 115 * @param flow2 the second flow control pin (CTS for RTSCTS)
gkroussos 0:637031152314 116 */
gkroussos 0:637031152314 117 void set_flow_control(Flow type, PinName flow1=NC, PinName flow2=NC);
gkroussos 0:637031152314 118 #endif
gkroussos 0:637031152314 119
gkroussos 0:637031152314 120 static void _irq_handler(uint32_t id, SerialIrq irq_type);
gkroussos 0:637031152314 121
gkroussos 0:637031152314 122 protected:
gkroussos 0:637031152314 123 SerialBase(PinName tx, PinName rx);
gkroussos 0:637031152314 124
gkroussos 0:637031152314 125 int _base_getc();
gkroussos 0:637031152314 126 int _base_putc(int c);
gkroussos 0:637031152314 127
gkroussos 0:637031152314 128 serial_t _serial;
gkroussos 0:637031152314 129 FunctionPointer _irq[2];
gkroussos 0:637031152314 130 int _baud;
gkroussos 0:637031152314 131 };
gkroussos 0:637031152314 132
gkroussos 0:637031152314 133 } // namespace mbed
gkroussos 0:637031152314 134
gkroussos 0:637031152314 135 #endif
gkroussos 0:637031152314 136
gkroussos 0:637031152314 137 #endif