Modification of Mbed-dev library for LQFP48 package microcontrollers: STM32F103C8 (STM32F103C8T6) and STM32F103CB (STM32F103CBT6) (Bluepill boards, Maple mini etc. )

Fork of mbed-STM32F103C8_org by Nothing Special

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers RawSerial.h Source File

RawSerial.h

00001 /* mbed Microcontroller Library
00002  * Copyright (c) 2006-2013 ARM Limited
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 #ifndef MBED_RAW_SERIAL_H
00017 #define MBED_RAW_SERIAL_H
00018 
00019 #include "platform/platform.h"
00020 
00021 #if DEVICE_SERIAL
00022 
00023 #include "drivers/SerialBase.h"
00024 #include "hal/serial_api.h"
00025 
00026 
00027 namespace mbed {
00028 /** \addtogroup drivers */
00029 /** @{*/
00030 
00031 /** A serial port (UART) for communication with other serial devices
00032  * This is a variation of the Serial class that doesn't use streams,
00033  * thus making it safe to use in interrupt handlers with the RTOS.
00034  *
00035  * Can be used for Full Duplex communication, or Simplex by specifying
00036  * one pin as NC (Not Connected)
00037  *
00038  * @Note Synchronization level: Not protected
00039  *
00040  * Example:
00041  * @code
00042  * // Send a char to the PC
00043  *
00044  * #include "mbed.h"
00045  *
00046  * RawSerial pc(USBTX, USBRX);
00047  *
00048  * int main() {
00049  *     pc.putc('A');
00050  * }
00051  * @endcode
00052  */
00053 class RawSerial: public SerialBase {
00054 
00055 public:
00056     /** Create a RawSerial port, connected to the specified transmit and receive pins, with the specified baud.
00057      *
00058      *  @param tx Transmit pin
00059      *  @param rx Receive pin
00060      *  @param baud The baud rate of the serial port (optional, defaults to MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE)
00061      *
00062      *  @note
00063      *    Either tx or rx may be specified as NC if unused
00064      */
00065     RawSerial(PinName tx, PinName rx, int baud = MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE);
00066 
00067     /** Write a char to the serial port
00068      *
00069      * @param c The char to write
00070      *
00071      * @returns The written char or -1 if an error occured
00072      */
00073     int putc(int c);
00074 
00075     /** Read a char from the serial port
00076      *
00077      * @returns The char read from the serial port
00078      */
00079     int getc();
00080 
00081     /** Write a string to the serial port
00082      *
00083      * @param str The string to write
00084      *
00085      * @returns 0 if the write succeeds, EOF for error
00086      */
00087     int puts(const char *str);
00088 
00089     int printf(const char *format, ...);
00090 
00091 protected:
00092 
00093     /** Acquire exclusive access to this serial port
00094      */
00095     virtual void lock(void);
00096 
00097     /** Release exclusive access to this serial port
00098      */
00099     virtual void unlock(void);
00100 };
00101 
00102 } // namespace mbed
00103 
00104 #endif
00105 
00106 #endif
00107 
00108 /** @}*/