Initial commit

Dependencies:   FastPWM

Committer:
lypinator
Date:
Wed Sep 16 01:11:49 2020 +0000
Revision:
0:bb348c97df44
Added PWM

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lypinator 0:bb348c97df44 1 /* mbed Microcontroller Library
lypinator 0:bb348c97df44 2 * Copyright (c) 2006-2013 ARM Limited
lypinator 0:bb348c97df44 3 *
lypinator 0:bb348c97df44 4 * Licensed under the Apache License, Version 2.0 (the "License");
lypinator 0:bb348c97df44 5 * you may not use this file except in compliance with the License.
lypinator 0:bb348c97df44 6 * You may obtain a copy of the License at
lypinator 0:bb348c97df44 7 *
lypinator 0:bb348c97df44 8 * http://www.apache.org/licenses/LICENSE-2.0
lypinator 0:bb348c97df44 9 *
lypinator 0:bb348c97df44 10 * Unless required by applicable law or agreed to in writing, software
lypinator 0:bb348c97df44 11 * distributed under the License is distributed on an "AS IS" BASIS,
lypinator 0:bb348c97df44 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
lypinator 0:bb348c97df44 13 * See the License for the specific language governing permissions and
lypinator 0:bb348c97df44 14 * limitations under the License.
lypinator 0:bb348c97df44 15 */
lypinator 0:bb348c97df44 16 #ifndef MBED_SERIAL_H
lypinator 0:bb348c97df44 17 #define MBED_SERIAL_H
lypinator 0:bb348c97df44 18
lypinator 0:bb348c97df44 19 #include "platform/platform.h"
lypinator 0:bb348c97df44 20
lypinator 0:bb348c97df44 21 #if defined (DEVICE_SERIAL) || defined(DOXYGEN_ONLY)
lypinator 0:bb348c97df44 22
lypinator 0:bb348c97df44 23 #include "Stream.h"
lypinator 0:bb348c97df44 24 #include "SerialBase.h"
lypinator 0:bb348c97df44 25 #include "PlatformMutex.h"
lypinator 0:bb348c97df44 26 #include "serial_api.h"
lypinator 0:bb348c97df44 27 #include "platform/NonCopyable.h"
lypinator 0:bb348c97df44 28
lypinator 0:bb348c97df44 29 namespace mbed {
lypinator 0:bb348c97df44 30 /** \addtogroup drivers */
lypinator 0:bb348c97df44 31
lypinator 0:bb348c97df44 32 /** A serial port (UART) for communication with other serial devices
lypinator 0:bb348c97df44 33 *
lypinator 0:bb348c97df44 34 * Can be used for Full Duplex communication, or Simplex by specifying
lypinator 0:bb348c97df44 35 * one pin as NC (Not Connected)
lypinator 0:bb348c97df44 36 *
lypinator 0:bb348c97df44 37 * @note Synchronization level: Thread safe
lypinator 0:bb348c97df44 38 *
lypinator 0:bb348c97df44 39 * Example:
lypinator 0:bb348c97df44 40 * @code
lypinator 0:bb348c97df44 41 * // Print "Hello World" to the PC
lypinator 0:bb348c97df44 42 *
lypinator 0:bb348c97df44 43 * #include "mbed.h"
lypinator 0:bb348c97df44 44 *
lypinator 0:bb348c97df44 45 * Serial pc(USBTX, USBRX);
lypinator 0:bb348c97df44 46 *
lypinator 0:bb348c97df44 47 * int main() {
lypinator 0:bb348c97df44 48 * pc.printf("Hello World\n");
lypinator 0:bb348c97df44 49 * }
lypinator 0:bb348c97df44 50 * @endcode
lypinator 0:bb348c97df44 51 * @ingroup drivers
lypinator 0:bb348c97df44 52 */
lypinator 0:bb348c97df44 53 class Serial : public SerialBase, public Stream, private NonCopyable<Serial> {
lypinator 0:bb348c97df44 54
lypinator 0:bb348c97df44 55 public:
lypinator 0:bb348c97df44 56 #if DEVICE_SERIAL_ASYNCH
lypinator 0:bb348c97df44 57 using SerialBase::read;
lypinator 0:bb348c97df44 58 using SerialBase::write;
lypinator 0:bb348c97df44 59 #endif
lypinator 0:bb348c97df44 60
lypinator 0:bb348c97df44 61 /** Create a Serial port, connected to the specified transmit and receive pins
lypinator 0:bb348c97df44 62 *
lypinator 0:bb348c97df44 63 * @param tx Transmit pin
lypinator 0:bb348c97df44 64 * @param rx Receive pin
lypinator 0:bb348c97df44 65 * @param name The name of the stream associated with this serial port (optional)
lypinator 0:bb348c97df44 66 * @param baud The baud rate of the serial port (optional, defaults to MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE)
lypinator 0:bb348c97df44 67 *
lypinator 0:bb348c97df44 68 * @note
lypinator 0:bb348c97df44 69 * Either tx or rx may be specified as NC if unused
lypinator 0:bb348c97df44 70 */
lypinator 0:bb348c97df44 71 Serial(PinName tx, PinName rx, const char *name = NULL, int baud = MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE);
lypinator 0:bb348c97df44 72
lypinator 0:bb348c97df44 73
lypinator 0:bb348c97df44 74 /** Create a Serial port, connected to the specified transmit and receive pins, with the specified baud
lypinator 0:bb348c97df44 75 *
lypinator 0:bb348c97df44 76 * @param tx Transmit pin
lypinator 0:bb348c97df44 77 * @param rx Receive pin
lypinator 0:bb348c97df44 78 * @param baud The baud rate of the serial port
lypinator 0:bb348c97df44 79 *
lypinator 0:bb348c97df44 80 * @note
lypinator 0:bb348c97df44 81 * Either tx or rx may be specified as NC if unused
lypinator 0:bb348c97df44 82 */
lypinator 0:bb348c97df44 83 Serial(PinName tx, PinName rx, int baud);
lypinator 0:bb348c97df44 84
lypinator 0:bb348c97df44 85 /* Stream gives us a FileHandle with non-functional poll()/readable()/writable. Pass through
lypinator 0:bb348c97df44 86 * the calls from the SerialBase instead for backwards compatibility. This problem is
lypinator 0:bb348c97df44 87 * part of why Stream and Serial should be deprecated.
lypinator 0:bb348c97df44 88 */
lypinator 0:bb348c97df44 89 bool readable()
lypinator 0:bb348c97df44 90 {
lypinator 0:bb348c97df44 91 return SerialBase::readable();
lypinator 0:bb348c97df44 92 }
lypinator 0:bb348c97df44 93 bool writable()
lypinator 0:bb348c97df44 94 {
lypinator 0:bb348c97df44 95 return SerialBase::writeable();
lypinator 0:bb348c97df44 96 }
lypinator 0:bb348c97df44 97 bool writeable()
lypinator 0:bb348c97df44 98 {
lypinator 0:bb348c97df44 99 return SerialBase::writeable();
lypinator 0:bb348c97df44 100 }
lypinator 0:bb348c97df44 101
lypinator 0:bb348c97df44 102 protected:
lypinator 0:bb348c97df44 103 virtual int _getc();
lypinator 0:bb348c97df44 104 virtual int _putc(int c);
lypinator 0:bb348c97df44 105 virtual void lock();
lypinator 0:bb348c97df44 106 virtual void unlock();
lypinator 0:bb348c97df44 107
lypinator 0:bb348c97df44 108 PlatformMutex _mutex;
lypinator 0:bb348c97df44 109 };
lypinator 0:bb348c97df44 110
lypinator 0:bb348c97df44 111 } // namespace mbed
lypinator 0:bb348c97df44 112
lypinator 0:bb348c97df44 113 #endif
lypinator 0:bb348c97df44 114
lypinator 0:bb348c97df44 115 #endif