Development mbed library for MAX32630FTHR

Dependents:   blinky_max32630fthr

Committer:
switches
Date:
Fri Nov 11 20:59:50 2016 +0000
Revision:
0:5c4d7b2438d3
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
switches 0:5c4d7b2438d3 1 /* mbed Microcontroller Library
switches 0:5c4d7b2438d3 2 * Copyright (c) 2006-2013 ARM Limited
switches 0:5c4d7b2438d3 3 *
switches 0:5c4d7b2438d3 4 * Licensed under the Apache License, Version 2.0 (the "License");
switches 0:5c4d7b2438d3 5 * you may not use this file except in compliance with the License.
switches 0:5c4d7b2438d3 6 * You may obtain a copy of the License at
switches 0:5c4d7b2438d3 7 *
switches 0:5c4d7b2438d3 8 * http://www.apache.org/licenses/LICENSE-2.0
switches 0:5c4d7b2438d3 9 *
switches 0:5c4d7b2438d3 10 * Unless required by applicable law or agreed to in writing, software
switches 0:5c4d7b2438d3 11 * distributed under the License is distributed on an "AS IS" BASIS,
switches 0:5c4d7b2438d3 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
switches 0:5c4d7b2438d3 13 * See the License for the specific language governing permissions and
switches 0:5c4d7b2438d3 14 * limitations under the License.
switches 0:5c4d7b2438d3 15 */
switches 0:5c4d7b2438d3 16 #ifndef MBED_BUSOUT_H
switches 0:5c4d7b2438d3 17 #define MBED_BUSOUT_H
switches 0:5c4d7b2438d3 18
switches 0:5c4d7b2438d3 19 #include "drivers/DigitalOut.h"
switches 0:5c4d7b2438d3 20 #include "platform/PlatformMutex.h"
switches 0:5c4d7b2438d3 21
switches 0:5c4d7b2438d3 22 namespace mbed {
switches 0:5c4d7b2438d3 23 /** \addtogroup drivers */
switches 0:5c4d7b2438d3 24 /** @{*/
switches 0:5c4d7b2438d3 25
switches 0:5c4d7b2438d3 26 /** A digital output bus, used for setting the state of a collection of pins
switches 0:5c4d7b2438d3 27 */
switches 0:5c4d7b2438d3 28 class BusOut {
switches 0:5c4d7b2438d3 29
switches 0:5c4d7b2438d3 30 public:
switches 0:5c4d7b2438d3 31
switches 0:5c4d7b2438d3 32 /** Create an BusOut, connected to the specified pins
switches 0:5c4d7b2438d3 33 *
switches 0:5c4d7b2438d3 34 * @param p<n> DigitalOut pin to connect to bus bit <n> (p5-p30, NC)
switches 0:5c4d7b2438d3 35 *
switches 0:5c4d7b2438d3 36 * @Note Synchronization level: Thread safe
switches 0:5c4d7b2438d3 37 *
switches 0:5c4d7b2438d3 38 * @note
switches 0:5c4d7b2438d3 39 * It is only required to specify as many pin variables as is required
switches 0:5c4d7b2438d3 40 * for the bus; the rest will default to NC (not connected)
switches 0:5c4d7b2438d3 41 */
switches 0:5c4d7b2438d3 42 BusOut(PinName p0, PinName p1 = NC, PinName p2 = NC, PinName p3 = NC,
switches 0:5c4d7b2438d3 43 PinName p4 = NC, PinName p5 = NC, PinName p6 = NC, PinName p7 = NC,
switches 0:5c4d7b2438d3 44 PinName p8 = NC, PinName p9 = NC, PinName p10 = NC, PinName p11 = NC,
switches 0:5c4d7b2438d3 45 PinName p12 = NC, PinName p13 = NC, PinName p14 = NC, PinName p15 = NC);
switches 0:5c4d7b2438d3 46
switches 0:5c4d7b2438d3 47 BusOut(PinName pins[16]);
switches 0:5c4d7b2438d3 48
switches 0:5c4d7b2438d3 49 virtual ~BusOut();
switches 0:5c4d7b2438d3 50
switches 0:5c4d7b2438d3 51 /** Write the value to the output bus
switches 0:5c4d7b2438d3 52 *
switches 0:5c4d7b2438d3 53 * @param value An integer specifying a bit to write for every corresponding DigitalOut pin
switches 0:5c4d7b2438d3 54 */
switches 0:5c4d7b2438d3 55 void write(int value);
switches 0:5c4d7b2438d3 56
switches 0:5c4d7b2438d3 57 /** Read the value currently output on the bus
switches 0:5c4d7b2438d3 58 *
switches 0:5c4d7b2438d3 59 * @returns
switches 0:5c4d7b2438d3 60 * An integer with each bit corresponding to associated DigitalOut pin setting
switches 0:5c4d7b2438d3 61 */
switches 0:5c4d7b2438d3 62 int read();
switches 0:5c4d7b2438d3 63
switches 0:5c4d7b2438d3 64 /** Binary mask of bus pins connected to actual pins (not NC pins)
switches 0:5c4d7b2438d3 65 * If bus pin is in NC state make corresponding bit will be cleared (set to 0), else bit will be set to 1
switches 0:5c4d7b2438d3 66 *
switches 0:5c4d7b2438d3 67 * @returns
switches 0:5c4d7b2438d3 68 * Binary mask of connected pins
switches 0:5c4d7b2438d3 69 */
switches 0:5c4d7b2438d3 70 int mask() {
switches 0:5c4d7b2438d3 71 // No lock needed since _nc_mask is not modified outside the constructor
switches 0:5c4d7b2438d3 72 return _nc_mask;
switches 0:5c4d7b2438d3 73 }
switches 0:5c4d7b2438d3 74
switches 0:5c4d7b2438d3 75 /** A shorthand for write()
switches 0:5c4d7b2438d3 76 */
switches 0:5c4d7b2438d3 77 BusOut& operator= (int v);
switches 0:5c4d7b2438d3 78 BusOut& operator= (BusOut& rhs);
switches 0:5c4d7b2438d3 79
switches 0:5c4d7b2438d3 80 /** Access to particular bit in random-iterator fashion
switches 0:5c4d7b2438d3 81 */
switches 0:5c4d7b2438d3 82 DigitalOut& operator[] (int index);
switches 0:5c4d7b2438d3 83
switches 0:5c4d7b2438d3 84 /** A shorthand for read()
switches 0:5c4d7b2438d3 85 */
switches 0:5c4d7b2438d3 86 operator int();
switches 0:5c4d7b2438d3 87
switches 0:5c4d7b2438d3 88 protected:
switches 0:5c4d7b2438d3 89 virtual void lock();
switches 0:5c4d7b2438d3 90 virtual void unlock();
switches 0:5c4d7b2438d3 91 DigitalOut* _pin[16];
switches 0:5c4d7b2438d3 92
switches 0:5c4d7b2438d3 93 /** Mask of bus's NC pins
switches 0:5c4d7b2438d3 94 * If bit[n] is set to 1 - pin is connected
switches 0:5c4d7b2438d3 95 * if bit[n] is cleared - pin is not connected (NC)
switches 0:5c4d7b2438d3 96 */
switches 0:5c4d7b2438d3 97 int _nc_mask;
switches 0:5c4d7b2438d3 98
switches 0:5c4d7b2438d3 99 PlatformMutex _mutex;
switches 0:5c4d7b2438d3 100
switches 0:5c4d7b2438d3 101 /* disallow copy constructor and assignment operators */
switches 0:5c4d7b2438d3 102 private:
switches 0:5c4d7b2438d3 103 BusOut(const BusOut&);
switches 0:5c4d7b2438d3 104 BusOut & operator = (const BusOut&);
switches 0:5c4d7b2438d3 105 };
switches 0:5c4d7b2438d3 106
switches 0:5c4d7b2438d3 107 } // namespace mbed
switches 0:5c4d7b2438d3 108
switches 0:5c4d7b2438d3 109 #endif
switches 0:5c4d7b2438d3 110
switches 0:5c4d7b2438d3 111 /** @}*/