This is the final version of Mini Gateway for Automation and Security desgined for Renesas GR Peach Design Contest

Dependencies:   GR-PEACH_video GraphicsFramework HTTPServer R_BSP mbed-rpc mbed-rtos Socket lwip-eth lwip-sys lwip FATFileSystem

Fork of mbed-os-example-mbed5-blinky by mbed-os-examples

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers PortOut.h Source File

PortOut.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_PORTOUT_H
00017 #define MBED_PORTOUT_H
00018 
00019 #include "platform/platform.h"
00020 
00021 #if DEVICE_PORTOUT
00022 
00023 #include "hal/port_api.h"
00024 #include "platform/critical.h"
00025 
00026 namespace mbed {
00027 /** \addtogroup drivers */
00028 /** @{*/
00029 /** A multiple pin digital out
00030  *
00031  * @Note Synchronization level: Interrupt safe
00032  *
00033  * Example:
00034  * @code
00035  * // Toggle all four LEDs
00036  *
00037  * #include "mbed.h"
00038  *
00039  * // LED1 = P1.18  LED2 = P1.20  LED3 = P1.21  LED4 = P1.23
00040  * #define LED_MASK 0x00B40000
00041  *
00042  * PortOut ledport(Port1, LED_MASK);
00043  *
00044  * int main() {
00045  *     while(1) {
00046  *         ledport = LED_MASK;
00047  *         wait(1);
00048  *         ledport = 0;
00049  *         wait(1);
00050  *     }
00051  * }
00052  * @endcode
00053  */
00054 class PortOut {
00055 public:
00056 
00057     /** Create an PortOut, connected to the specified port
00058      *
00059      *  @param port Port to connect to (Port0-Port5)
00060      *  @param mask A bitmask to identify which bits in the port should be included (0 - ignore)
00061      */
00062     PortOut(PortName port, int mask = 0xFFFFFFFF) {
00063         core_util_critical_section_enter();
00064         port_init(&_port, port, mask, PIN_OUTPUT);
00065         core_util_critical_section_exit();
00066     }
00067 
00068     /** Write the value to the output port
00069      *
00070      *  @param value An integer specifying a bit to write for every corresponding PortOut pin
00071      */
00072     void write(int value) {
00073         port_write(&_port, value);
00074     }
00075 
00076     /** Read the value currently output on the port
00077      *
00078      *  @returns
00079      *    An integer with each bit corresponding to associated PortOut pin setting
00080      */
00081     int read() {
00082         return port_read(&_port);
00083     }
00084 
00085     /** A shorthand for write()
00086      */
00087     PortOut& operator= (int value) {
00088         write(value);
00089         return *this;
00090     }
00091 
00092     PortOut& operator= (PortOut& rhs) {
00093         write(rhs.read());
00094         return *this;
00095     }
00096 
00097     /** A shorthand for read()
00098      */
00099     operator int() {
00100         return read();
00101     }
00102 
00103 private:
00104     port_t _port;
00105 };
00106 
00107 } // namespace mbed
00108 
00109 #endif
00110 
00111 #endif
00112 
00113 /** @}*/