fix nrf51822 i2c & spi conflict

Dependencies:   BLE_API eMPL_MPU6050 nRF51822

Fork of Seeed_Tiny_BLE_Flash by Darren Huang

Committer:
yihui
Date:
Tue Nov 17 07:48:56 2015 +0000
Revision:
5:b8c02645e6af
fix i2c & spi conflict

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yihui 5:b8c02645e6af 1 /* mbed Microcontroller Library
yihui 5:b8c02645e6af 2 * Copyright (c) 2006-2013 ARM Limited
yihui 5:b8c02645e6af 3 *
yihui 5:b8c02645e6af 4 * Licensed under the Apache License, Version 2.0 (the "License");
yihui 5:b8c02645e6af 5 * you may not use this file except in compliance with the License.
yihui 5:b8c02645e6af 6 * You may obtain a copy of the License at
yihui 5:b8c02645e6af 7 *
yihui 5:b8c02645e6af 8 * http://www.apache.org/licenses/LICENSE-2.0
yihui 5:b8c02645e6af 9 *
yihui 5:b8c02645e6af 10 * Unless required by applicable law or agreed to in writing, software
yihui 5:b8c02645e6af 11 * distributed under the License is distributed on an "AS IS" BASIS,
yihui 5:b8c02645e6af 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
yihui 5:b8c02645e6af 13 * See the License for the specific language governing permissions and
yihui 5:b8c02645e6af 14 * limitations under the License.
yihui 5:b8c02645e6af 15 */
yihui 5:b8c02645e6af 16 #ifndef MBED_ANALOGOUT_H
yihui 5:b8c02645e6af 17 #define MBED_ANALOGOUT_H
yihui 5:b8c02645e6af 18
yihui 5:b8c02645e6af 19 #include "platform.h"
yihui 5:b8c02645e6af 20
yihui 5:b8c02645e6af 21 #if DEVICE_ANALOGOUT
yihui 5:b8c02645e6af 22
yihui 5:b8c02645e6af 23 #include "analogout_api.h"
yihui 5:b8c02645e6af 24
yihui 5:b8c02645e6af 25 namespace mbed {
yihui 5:b8c02645e6af 26
yihui 5:b8c02645e6af 27 /** An analog output, used for setting the voltage on a pin
yihui 5:b8c02645e6af 28 *
yihui 5:b8c02645e6af 29 * Example:
yihui 5:b8c02645e6af 30 * @code
yihui 5:b8c02645e6af 31 * // Make a sawtooth output
yihui 5:b8c02645e6af 32 *
yihui 5:b8c02645e6af 33 * #include "mbed.h"
yihui 5:b8c02645e6af 34 *
yihui 5:b8c02645e6af 35 * AnalogOut tri(p18);
yihui 5:b8c02645e6af 36 * int main() {
yihui 5:b8c02645e6af 37 * while(1) {
yihui 5:b8c02645e6af 38 * tri = tri + 0.01;
yihui 5:b8c02645e6af 39 * wait_us(1);
yihui 5:b8c02645e6af 40 * if(tri == 1) {
yihui 5:b8c02645e6af 41 * tri = 0;
yihui 5:b8c02645e6af 42 * }
yihui 5:b8c02645e6af 43 * }
yihui 5:b8c02645e6af 44 * }
yihui 5:b8c02645e6af 45 * @endcode
yihui 5:b8c02645e6af 46 */
yihui 5:b8c02645e6af 47 class AnalogOut {
yihui 5:b8c02645e6af 48
yihui 5:b8c02645e6af 49 public:
yihui 5:b8c02645e6af 50
yihui 5:b8c02645e6af 51 /** Create an AnalogOut connected to the specified pin
yihui 5:b8c02645e6af 52 *
yihui 5:b8c02645e6af 53 * @param AnalogOut pin to connect to (18)
yihui 5:b8c02645e6af 54 */
yihui 5:b8c02645e6af 55 AnalogOut(PinName pin) {
yihui 5:b8c02645e6af 56 analogout_init(&_dac, pin);
yihui 5:b8c02645e6af 57 }
yihui 5:b8c02645e6af 58
yihui 5:b8c02645e6af 59 /** Set the output voltage, specified as a percentage (float)
yihui 5:b8c02645e6af 60 *
yihui 5:b8c02645e6af 61 * @param value A floating-point value representing the output voltage,
yihui 5:b8c02645e6af 62 * specified as a percentage. The value should lie between
yihui 5:b8c02645e6af 63 * 0.0f (representing 0v / 0%) and 1.0f (representing 3.3v / 100%).
yihui 5:b8c02645e6af 64 * Values outside this range will be saturated to 0.0f or 1.0f.
yihui 5:b8c02645e6af 65 */
yihui 5:b8c02645e6af 66 void write(float value) {
yihui 5:b8c02645e6af 67 analogout_write(&_dac, value);
yihui 5:b8c02645e6af 68 }
yihui 5:b8c02645e6af 69
yihui 5:b8c02645e6af 70 /** Set the output voltage, represented as an unsigned short in the range [0x0, 0xFFFF]
yihui 5:b8c02645e6af 71 *
yihui 5:b8c02645e6af 72 * @param value 16-bit unsigned short representing the output voltage,
yihui 5:b8c02645e6af 73 * normalised to a 16-bit value (0x0000 = 0v, 0xFFFF = 3.3v)
yihui 5:b8c02645e6af 74 */
yihui 5:b8c02645e6af 75 void write_u16(unsigned short value) {
yihui 5:b8c02645e6af 76 analogout_write_u16(&_dac, value);
yihui 5:b8c02645e6af 77 }
yihui 5:b8c02645e6af 78
yihui 5:b8c02645e6af 79 /** Return the current output voltage setting, measured as a percentage (float)
yihui 5:b8c02645e6af 80 *
yihui 5:b8c02645e6af 81 * @returns
yihui 5:b8c02645e6af 82 * A floating-point value representing the current voltage being output on the pin,
yihui 5:b8c02645e6af 83 * measured as a percentage. The returned value will lie between
yihui 5:b8c02645e6af 84 * 0.0f (representing 0v / 0%) and 1.0f (representing 3.3v / 100%).
yihui 5:b8c02645e6af 85 *
yihui 5:b8c02645e6af 86 * @note
yihui 5:b8c02645e6af 87 * This value may not match exactly the value set by a previous write().
yihui 5:b8c02645e6af 88 */
yihui 5:b8c02645e6af 89 float read() {
yihui 5:b8c02645e6af 90 return analogout_read(&_dac);
yihui 5:b8c02645e6af 91 }
yihui 5:b8c02645e6af 92
yihui 5:b8c02645e6af 93 #ifdef MBED_OPERATORS
yihui 5:b8c02645e6af 94 /** An operator shorthand for write()
yihui 5:b8c02645e6af 95 */
yihui 5:b8c02645e6af 96 AnalogOut& operator= (float percent) {
yihui 5:b8c02645e6af 97 write(percent);
yihui 5:b8c02645e6af 98 return *this;
yihui 5:b8c02645e6af 99 }
yihui 5:b8c02645e6af 100
yihui 5:b8c02645e6af 101 AnalogOut& operator= (AnalogOut& rhs) {
yihui 5:b8c02645e6af 102 write(rhs.read());
yihui 5:b8c02645e6af 103 return *this;
yihui 5:b8c02645e6af 104 }
yihui 5:b8c02645e6af 105
yihui 5:b8c02645e6af 106 /** An operator shorthand for read()
yihui 5:b8c02645e6af 107 */
yihui 5:b8c02645e6af 108 operator float() {
yihui 5:b8c02645e6af 109 return read();
yihui 5:b8c02645e6af 110 }
yihui 5:b8c02645e6af 111 #endif
yihui 5:b8c02645e6af 112
yihui 5:b8c02645e6af 113 protected:
yihui 5:b8c02645e6af 114 dac_t _dac;
yihui 5:b8c02645e6af 115 };
yihui 5:b8c02645e6af 116
yihui 5:b8c02645e6af 117 } // namespace mbed
yihui 5:b8c02645e6af 118
yihui 5:b8c02645e6af 119 #endif
yihui 5:b8c02645e6af 120
yihui 5:b8c02645e6af 121 #endif