LPC11U35 ADC Tick & USBSerial

Dependencies:   mbed

Dependents:   SmallDoseMeter_SingleCH_AE_lpc11u35_V1_00

Committer:
H_Tsunemoto
Date:
Mon Feb 19 09:09:52 2018 +0000
Revision:
1:b1a3be5f48ab
Parent:
0:871ab6846b18
test

Who changed what in which revision?

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