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_PORTOUT_H
lypinator 0:bb348c97df44 17 #define MBED_PORTOUT_H
lypinator 0:bb348c97df44 18
lypinator 0:bb348c97df44 19 #include "platform/platform.h"
lypinator 0:bb348c97df44 20
lypinator 0:bb348c97df44 21 #if defined (DEVICE_PORTOUT) || defined(DOXYGEN_ONLY)
lypinator 0:bb348c97df44 22
lypinator 0:bb348c97df44 23 #include "hal/port_api.h"
lypinator 0:bb348c97df44 24 #include "platform/mbed_critical.h"
lypinator 0:bb348c97df44 25
lypinator 0:bb348c97df44 26 namespace mbed {
lypinator 0:bb348c97df44 27 /** \addtogroup drivers */
lypinator 0:bb348c97df44 28 /** A multiple pin digital out
lypinator 0:bb348c97df44 29 *
lypinator 0:bb348c97df44 30 * @note Synchronization level: Interrupt safe
lypinator 0:bb348c97df44 31 *
lypinator 0:bb348c97df44 32 * Example:
lypinator 0:bb348c97df44 33 * @code
lypinator 0:bb348c97df44 34 * // Toggle all four LEDs
lypinator 0:bb348c97df44 35 *
lypinator 0:bb348c97df44 36 * #include "mbed.h"
lypinator 0:bb348c97df44 37 *
lypinator 0:bb348c97df44 38 * // LED1 = P1.18 LED2 = P1.20 LED3 = P1.21 LED4 = P1.23
lypinator 0:bb348c97df44 39 * #define LED_MASK 0x00B40000
lypinator 0:bb348c97df44 40 *
lypinator 0:bb348c97df44 41 * PortOut ledport(Port1, LED_MASK);
lypinator 0:bb348c97df44 42 *
lypinator 0:bb348c97df44 43 * int main() {
lypinator 0:bb348c97df44 44 * while(1) {
lypinator 0:bb348c97df44 45 * ledport = LED_MASK;
lypinator 0:bb348c97df44 46 * wait(1);
lypinator 0:bb348c97df44 47 * ledport = 0;
lypinator 0:bb348c97df44 48 * wait(1);
lypinator 0:bb348c97df44 49 * }
lypinator 0:bb348c97df44 50 * }
lypinator 0:bb348c97df44 51 * @endcode
lypinator 0:bb348c97df44 52 * @ingroup drivers
lypinator 0:bb348c97df44 53 */
lypinator 0:bb348c97df44 54 class PortOut {
lypinator 0:bb348c97df44 55 public:
lypinator 0:bb348c97df44 56
lypinator 0:bb348c97df44 57 /** Create an PortOut, connected to the specified port
lypinator 0:bb348c97df44 58 *
lypinator 0:bb348c97df44 59 * @param port Port to connect to (Port0-Port5)
lypinator 0:bb348c97df44 60 * @param mask A bitmask to identify which bits in the port should be included (0 - ignore)
lypinator 0:bb348c97df44 61 */
lypinator 0:bb348c97df44 62 PortOut(PortName port, int mask = 0xFFFFFFFF)
lypinator 0:bb348c97df44 63 {
lypinator 0:bb348c97df44 64 core_util_critical_section_enter();
lypinator 0:bb348c97df44 65 port_init(&_port, port, mask, PIN_OUTPUT);
lypinator 0:bb348c97df44 66 core_util_critical_section_exit();
lypinator 0:bb348c97df44 67 }
lypinator 0:bb348c97df44 68
lypinator 0:bb348c97df44 69 /** Write the value to the output port
lypinator 0:bb348c97df44 70 *
lypinator 0:bb348c97df44 71 * @param value An integer specifying a bit to write for every corresponding PortOut pin
lypinator 0:bb348c97df44 72 */
lypinator 0:bb348c97df44 73 void write(int value)
lypinator 0:bb348c97df44 74 {
lypinator 0:bb348c97df44 75 port_write(&_port, value);
lypinator 0:bb348c97df44 76 }
lypinator 0:bb348c97df44 77
lypinator 0:bb348c97df44 78 /** Read the value currently output on the port
lypinator 0:bb348c97df44 79 *
lypinator 0:bb348c97df44 80 * @returns
lypinator 0:bb348c97df44 81 * An integer with each bit corresponding to associated PortOut pin setting
lypinator 0:bb348c97df44 82 */
lypinator 0:bb348c97df44 83 int read()
lypinator 0:bb348c97df44 84 {
lypinator 0:bb348c97df44 85 return port_read(&_port);
lypinator 0:bb348c97df44 86 }
lypinator 0:bb348c97df44 87
lypinator 0:bb348c97df44 88 /** A shorthand for write()
lypinator 0:bb348c97df44 89 * \sa PortOut::write()
lypinator 0:bb348c97df44 90 */
lypinator 0:bb348c97df44 91 PortOut &operator= (int value)
lypinator 0:bb348c97df44 92 {
lypinator 0:bb348c97df44 93 write(value);
lypinator 0:bb348c97df44 94 return *this;
lypinator 0:bb348c97df44 95 }
lypinator 0:bb348c97df44 96
lypinator 0:bb348c97df44 97 /** A shorthand for read()
lypinator 0:bb348c97df44 98 * \sa PortOut::read()
lypinator 0:bb348c97df44 99 */
lypinator 0:bb348c97df44 100 PortOut &operator= (PortOut &rhs)
lypinator 0:bb348c97df44 101 {
lypinator 0:bb348c97df44 102 write(rhs.read());
lypinator 0:bb348c97df44 103 return *this;
lypinator 0:bb348c97df44 104 }
lypinator 0:bb348c97df44 105
lypinator 0:bb348c97df44 106 /** A shorthand for read()
lypinator 0:bb348c97df44 107 * \sa PortOut::read()
lypinator 0:bb348c97df44 108 */
lypinator 0:bb348c97df44 109 operator int()
lypinator 0:bb348c97df44 110 {
lypinator 0:bb348c97df44 111 return read();
lypinator 0:bb348c97df44 112 }
lypinator 0:bb348c97df44 113
lypinator 0:bb348c97df44 114 private:
lypinator 0:bb348c97df44 115 port_t _port;
lypinator 0:bb348c97df44 116 };
lypinator 0:bb348c97df44 117
lypinator 0:bb348c97df44 118 } // namespace mbed
lypinator 0:bb348c97df44 119
lypinator 0:bb348c97df44 120 #endif
lypinator 0:bb348c97df44 121
lypinator 0:bb348c97df44 122 #endif