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