ads1115 only
Fork of mbed by
RawSerial.h@68:f37f3b9c9f0b, 2013-10-23 (annotated)
- Committer:
- bogdanm
- Date:
- Wed Oct 23 16:23:06 2013 +0300
- Revision:
- 68:f37f3b9c9f0b
- Child:
- 75:dc225afb6914
Bug fixes and new features
Many changes in this release, including:
- The new RawSerial class is a simple wrapper over the serial HAL that can
be safely used from an interrupt handler.
- Interrupt chaining code was removed from InterruptIn, Serial and Ticker
because it caused lots of issues with the RTOS. Interrupt chaining is
still possible using the InterruptManager class.
- InterruptIn has two new methods (enable and disable irq)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bogdanm | 68:f37f3b9c9f0b | 1 | /* mbed Microcontroller Library |
bogdanm | 68:f37f3b9c9f0b | 2 | * Copyright (c) 2006-2013 ARM Limited |
bogdanm | 68:f37f3b9c9f0b | 3 | * |
bogdanm | 68:f37f3b9c9f0b | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
bogdanm | 68:f37f3b9c9f0b | 5 | * you may not use this file except in compliance with the License. |
bogdanm | 68:f37f3b9c9f0b | 6 | * You may obtain a copy of the License at |
bogdanm | 68:f37f3b9c9f0b | 7 | * |
bogdanm | 68:f37f3b9c9f0b | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
bogdanm | 68:f37f3b9c9f0b | 9 | * |
bogdanm | 68:f37f3b9c9f0b | 10 | * Unless required by applicable law or agreed to in writing, software |
bogdanm | 68:f37f3b9c9f0b | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
bogdanm | 68:f37f3b9c9f0b | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
bogdanm | 68:f37f3b9c9f0b | 13 | * See the License for the specific language governing permissions and |
bogdanm | 68:f37f3b9c9f0b | 14 | * limitations under the License. |
bogdanm | 68:f37f3b9c9f0b | 15 | */ |
bogdanm | 68:f37f3b9c9f0b | 16 | #ifndef MBED_RAW_SERIAL_H |
bogdanm | 68:f37f3b9c9f0b | 17 | #define MBED_RAW_SERIAL_H |
bogdanm | 68:f37f3b9c9f0b | 18 | |
bogdanm | 68:f37f3b9c9f0b | 19 | #include "platform.h" |
bogdanm | 68:f37f3b9c9f0b | 20 | |
bogdanm | 68:f37f3b9c9f0b | 21 | #if DEVICE_SERIAL |
bogdanm | 68:f37f3b9c9f0b | 22 | |
bogdanm | 68:f37f3b9c9f0b | 23 | #include "SerialBase.h" |
bogdanm | 68:f37f3b9c9f0b | 24 | #include "serial_api.h" |
bogdanm | 68:f37f3b9c9f0b | 25 | |
bogdanm | 68:f37f3b9c9f0b | 26 | namespace mbed { |
bogdanm | 68:f37f3b9c9f0b | 27 | |
bogdanm | 68:f37f3b9c9f0b | 28 | /** A serial port (UART) for communication with other serial devices |
bogdanm | 68:f37f3b9c9f0b | 29 | * This is a variation of the Serial class that doesn't use streams, |
bogdanm | 68:f37f3b9c9f0b | 30 | * thus making it safe to use in interrupt handlers with the RTOS. |
bogdanm | 68:f37f3b9c9f0b | 31 | * |
bogdanm | 68:f37f3b9c9f0b | 32 | * Can be used for Full Duplex communication, or Simplex by specifying |
bogdanm | 68:f37f3b9c9f0b | 33 | * one pin as NC (Not Connected) |
bogdanm | 68:f37f3b9c9f0b | 34 | * |
bogdanm | 68:f37f3b9c9f0b | 35 | * Example: |
bogdanm | 68:f37f3b9c9f0b | 36 | * @code |
bogdanm | 68:f37f3b9c9f0b | 37 | * // Send a char to the PC |
bogdanm | 68:f37f3b9c9f0b | 38 | * |
bogdanm | 68:f37f3b9c9f0b | 39 | * #include "mbed.h" |
bogdanm | 68:f37f3b9c9f0b | 40 | * |
bogdanm | 68:f37f3b9c9f0b | 41 | * RawSerial pc(USBTX, USBRX); |
bogdanm | 68:f37f3b9c9f0b | 42 | * |
bogdanm | 68:f37f3b9c9f0b | 43 | * int main() { |
bogdanm | 68:f37f3b9c9f0b | 44 | * pc.putc('A'); |
bogdanm | 68:f37f3b9c9f0b | 45 | * } |
bogdanm | 68:f37f3b9c9f0b | 46 | * @endcode |
bogdanm | 68:f37f3b9c9f0b | 47 | */ |
bogdanm | 68:f37f3b9c9f0b | 48 | class RawSerial: public SerialBase { |
bogdanm | 68:f37f3b9c9f0b | 49 | |
bogdanm | 68:f37f3b9c9f0b | 50 | public: |
bogdanm | 68:f37f3b9c9f0b | 51 | /** Create a RawSerial port, connected to the specified transmit and receive pins |
bogdanm | 68:f37f3b9c9f0b | 52 | * |
bogdanm | 68:f37f3b9c9f0b | 53 | * @param tx Transmit pin |
bogdanm | 68:f37f3b9c9f0b | 54 | * @param rx Receive pin |
bogdanm | 68:f37f3b9c9f0b | 55 | * |
bogdanm | 68:f37f3b9c9f0b | 56 | * @note |
bogdanm | 68:f37f3b9c9f0b | 57 | * Either tx or rx may be specified as NC if unused |
bogdanm | 68:f37f3b9c9f0b | 58 | */ |
bogdanm | 68:f37f3b9c9f0b | 59 | RawSerial(PinName tx, PinName rx); |
bogdanm | 68:f37f3b9c9f0b | 60 | |
bogdanm | 68:f37f3b9c9f0b | 61 | /** Write a char to the serial port |
bogdanm | 68:f37f3b9c9f0b | 62 | * |
bogdanm | 68:f37f3b9c9f0b | 63 | * @param c The char to write |
bogdanm | 68:f37f3b9c9f0b | 64 | * |
bogdanm | 68:f37f3b9c9f0b | 65 | * @returns The written char or -1 if an error occured |
bogdanm | 68:f37f3b9c9f0b | 66 | */ |
bogdanm | 68:f37f3b9c9f0b | 67 | int putc(int c); |
bogdanm | 68:f37f3b9c9f0b | 68 | |
bogdanm | 68:f37f3b9c9f0b | 69 | /** Read a char from the serial port |
bogdanm | 68:f37f3b9c9f0b | 70 | * |
bogdanm | 68:f37f3b9c9f0b | 71 | * @returns The char read from the serial port |
bogdanm | 68:f37f3b9c9f0b | 72 | */ |
bogdanm | 68:f37f3b9c9f0b | 73 | int getc(); |
bogdanm | 68:f37f3b9c9f0b | 74 | }; |
bogdanm | 68:f37f3b9c9f0b | 75 | |
bogdanm | 68:f37f3b9c9f0b | 76 | } // namespace mbed |
bogdanm | 68:f37f3b9c9f0b | 77 | |
bogdanm | 68:f37f3b9c9f0b | 78 | #endif |
bogdanm | 68:f37f3b9c9f0b | 79 | |
bogdanm | 68:f37f3b9c9f0b | 80 | #endif |