mbed library for NZ32-SC151

Committer:
modtronix-com
Date:
Fri Aug 19 15:46:42 2016 +1000
Revision:
17:639ed60ce759
Parent:
1:71204b8406f2
Added tag v1.1 for changeset 076cbe3e55be

Who changed what in which revision?

UserRevisionLine numberNew contents of line
modtronix 1:71204b8406f2 1 /* mbed Microcontroller Library
modtronix 1:71204b8406f2 2 * Copyright (c) 2006-2013 ARM Limited
modtronix 1:71204b8406f2 3 *
modtronix 1:71204b8406f2 4 * Licensed under the Apache License, Version 2.0 (the "License");
modtronix 1:71204b8406f2 5 * you may not use this file except in compliance with the License.
modtronix 1:71204b8406f2 6 * You may obtain a copy of the License at
modtronix 1:71204b8406f2 7 *
modtronix 1:71204b8406f2 8 * http://www.apache.org/licenses/LICENSE-2.0
modtronix 1:71204b8406f2 9 *
modtronix 1:71204b8406f2 10 * Unless required by applicable law or agreed to in writing, software
modtronix 1:71204b8406f2 11 * distributed under the License is distributed on an "AS IS" BASIS,
modtronix 1:71204b8406f2 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
modtronix 1:71204b8406f2 13 * See the License for the specific language governing permissions and
modtronix 1:71204b8406f2 14 * limitations under the License.
modtronix 1:71204b8406f2 15 */
modtronix 1:71204b8406f2 16 #ifndef MBED_PORTOUT_H
modtronix 1:71204b8406f2 17 #define MBED_PORTOUT_H
modtronix 1:71204b8406f2 18
modtronix 1:71204b8406f2 19 #include "platform.h"
modtronix 1:71204b8406f2 20
modtronix 1:71204b8406f2 21 #if DEVICE_PORTOUT
modtronix 1:71204b8406f2 22
modtronix 1:71204b8406f2 23 #include "port_api.h"
modtronix 1:71204b8406f2 24
modtronix 1:71204b8406f2 25 namespace mbed {
modtronix 1:71204b8406f2 26 /** A multiple pin digital out
modtronix 1:71204b8406f2 27 *
modtronix 1:71204b8406f2 28 * Example:
modtronix 1:71204b8406f2 29 * @code
modtronix 1:71204b8406f2 30 * // Toggle all four LEDs
modtronix 1:71204b8406f2 31 *
modtronix 1:71204b8406f2 32 * #include "mbed.h"
modtronix 1:71204b8406f2 33 *
modtronix 1:71204b8406f2 34 * // LED1 = P1.18 LED2 = P1.20 LED3 = P1.21 LED4 = P1.23
modtronix 1:71204b8406f2 35 * #define LED_MASK 0x00B40000
modtronix 1:71204b8406f2 36 *
modtronix 1:71204b8406f2 37 * PortOut ledport(Port1, LED_MASK);
modtronix 1:71204b8406f2 38 *
modtronix 1:71204b8406f2 39 * int main() {
modtronix 1:71204b8406f2 40 * while(1) {
modtronix 1:71204b8406f2 41 * ledport = LED_MASK;
modtronix 1:71204b8406f2 42 * wait(1);
modtronix 1:71204b8406f2 43 * ledport = 0;
modtronix 1:71204b8406f2 44 * wait(1);
modtronix 1:71204b8406f2 45 * }
modtronix 1:71204b8406f2 46 * }
modtronix 1:71204b8406f2 47 * @endcode
modtronix 1:71204b8406f2 48 */
modtronix 1:71204b8406f2 49 class PortOut {
modtronix 1:71204b8406f2 50 public:
modtronix 1:71204b8406f2 51
modtronix 1:71204b8406f2 52 /** Create an PortOut, connected to the specified port
modtronix 1:71204b8406f2 53 *
modtronix 1:71204b8406f2 54 * @param port Port to connect to (Port0-Port5)
modtronix 1:71204b8406f2 55 * @param mask A bitmask to identify which bits in the port should be included (0 - ignore)
modtronix 1:71204b8406f2 56 */
modtronix 1:71204b8406f2 57 PortOut(PortName port, int mask = 0xFFFFFFFF) {
modtronix 1:71204b8406f2 58 port_init(&_port, port, mask, PIN_OUTPUT);
modtronix 1:71204b8406f2 59 }
modtronix 1:71204b8406f2 60
modtronix 1:71204b8406f2 61 /** Write the value to the output port
modtronix 1:71204b8406f2 62 *
modtronix 1:71204b8406f2 63 * @param value An integer specifying a bit to write for every corresponding PortOut pin
modtronix 1:71204b8406f2 64 */
modtronix 1:71204b8406f2 65 void write(int value) {
modtronix 1:71204b8406f2 66 port_write(&_port, value);
modtronix 1:71204b8406f2 67 }
modtronix 1:71204b8406f2 68
modtronix 1:71204b8406f2 69 /** Read the value currently output on the port
modtronix 1:71204b8406f2 70 *
modtronix 1:71204b8406f2 71 * @returns
modtronix 1:71204b8406f2 72 * An integer with each bit corresponding to associated PortOut pin setting
modtronix 1:71204b8406f2 73 */
modtronix 1:71204b8406f2 74 int read() {
modtronix 1:71204b8406f2 75 return port_read(&_port);
modtronix 1:71204b8406f2 76 }
modtronix 1:71204b8406f2 77
modtronix 1:71204b8406f2 78 /** A shorthand for write()
modtronix 1:71204b8406f2 79 */
modtronix 1:71204b8406f2 80 PortOut& operator= (int value) {
modtronix 1:71204b8406f2 81 write(value);
modtronix 1:71204b8406f2 82 return *this;
modtronix 1:71204b8406f2 83 }
modtronix 1:71204b8406f2 84
modtronix 1:71204b8406f2 85 PortOut& operator= (PortOut& rhs) {
modtronix 1:71204b8406f2 86 write(rhs.read());
modtronix 1:71204b8406f2 87 return *this;
modtronix 1:71204b8406f2 88 }
modtronix 1:71204b8406f2 89
modtronix 1:71204b8406f2 90 /** A shorthand for read()
modtronix 1:71204b8406f2 91 */
modtronix 1:71204b8406f2 92 operator int() {
modtronix 1:71204b8406f2 93 return read();
modtronix 1:71204b8406f2 94 }
modtronix 1:71204b8406f2 95
modtronix 1:71204b8406f2 96 private:
modtronix 1:71204b8406f2 97 port_t _port;
modtronix 1:71204b8406f2 98 };
modtronix 1:71204b8406f2 99
modtronix 1:71204b8406f2 100 } // namespace mbed
modtronix 1:71204b8406f2 101
modtronix 1:71204b8406f2 102 #endif
modtronix 1:71204b8406f2 103
modtronix 1:71204b8406f2 104 #endif