fix nrf51822 i2c & spi conflict
Dependencies: BLE_API eMPL_MPU6050 nRF51822
Fork of Seeed_Tiny_BLE_Flash by
mbed-src/api/PwmOut.h@5:b8c02645e6af, 2015-11-17 (annotated)
- Committer:
- yihui
- Date:
- Tue Nov 17 07:48:56 2015 +0000
- Revision:
- 5:b8c02645e6af
fix i2c & spi conflict
Who changed what in which revision?
User | Revision | Line number | New 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_PWMOUT_H |
yihui | 5:b8c02645e6af | 17 | #define MBED_PWMOUT_H |
yihui | 5:b8c02645e6af | 18 | |
yihui | 5:b8c02645e6af | 19 | #include "platform.h" |
yihui | 5:b8c02645e6af | 20 | |
yihui | 5:b8c02645e6af | 21 | #if DEVICE_PWMOUT |
yihui | 5:b8c02645e6af | 22 | #include "pwmout_api.h" |
yihui | 5:b8c02645e6af | 23 | |
yihui | 5:b8c02645e6af | 24 | namespace mbed { |
yihui | 5:b8c02645e6af | 25 | |
yihui | 5:b8c02645e6af | 26 | /** A pulse-width modulation digital output |
yihui | 5:b8c02645e6af | 27 | * |
yihui | 5:b8c02645e6af | 28 | * Example |
yihui | 5:b8c02645e6af | 29 | * @code |
yihui | 5:b8c02645e6af | 30 | * // Fade a led on. |
yihui | 5:b8c02645e6af | 31 | * #include "mbed.h" |
yihui | 5:b8c02645e6af | 32 | * |
yihui | 5:b8c02645e6af | 33 | * PwmOut led(LED1); |
yihui | 5:b8c02645e6af | 34 | * |
yihui | 5:b8c02645e6af | 35 | * int main() { |
yihui | 5:b8c02645e6af | 36 | * while(1) { |
yihui | 5:b8c02645e6af | 37 | * led = led + 0.01; |
yihui | 5:b8c02645e6af | 38 | * wait(0.2); |
yihui | 5:b8c02645e6af | 39 | * if(led == 1.0) { |
yihui | 5:b8c02645e6af | 40 | * led = 0; |
yihui | 5:b8c02645e6af | 41 | * } |
yihui | 5:b8c02645e6af | 42 | * } |
yihui | 5:b8c02645e6af | 43 | * } |
yihui | 5:b8c02645e6af | 44 | * @endcode |
yihui | 5:b8c02645e6af | 45 | * |
yihui | 5:b8c02645e6af | 46 | * @note |
yihui | 5:b8c02645e6af | 47 | * On the LPC1768 and LPC2368, the PWMs all share the same |
yihui | 5:b8c02645e6af | 48 | * period - if you change the period for one, you change it for all. |
yihui | 5:b8c02645e6af | 49 | * Although routines that change the period maintain the duty cycle |
yihui | 5:b8c02645e6af | 50 | * for its PWM, all other PWMs will require their duty cycle to be |
yihui | 5:b8c02645e6af | 51 | * refreshed. |
yihui | 5:b8c02645e6af | 52 | */ |
yihui | 5:b8c02645e6af | 53 | class PwmOut { |
yihui | 5:b8c02645e6af | 54 | |
yihui | 5:b8c02645e6af | 55 | public: |
yihui | 5:b8c02645e6af | 56 | |
yihui | 5:b8c02645e6af | 57 | /** Create a PwmOut connected to the specified pin |
yihui | 5:b8c02645e6af | 58 | * |
yihui | 5:b8c02645e6af | 59 | * @param pin PwmOut pin to connect to |
yihui | 5:b8c02645e6af | 60 | */ |
yihui | 5:b8c02645e6af | 61 | PwmOut(PinName pin) { |
yihui | 5:b8c02645e6af | 62 | pwmout_init(&_pwm, pin); |
yihui | 5:b8c02645e6af | 63 | } |
yihui | 5:b8c02645e6af | 64 | |
yihui | 5:b8c02645e6af | 65 | /** Set the ouput duty-cycle, specified as a percentage (float) |
yihui | 5:b8c02645e6af | 66 | * |
yihui | 5:b8c02645e6af | 67 | * @param value A floating-point value representing the output duty-cycle, |
yihui | 5:b8c02645e6af | 68 | * specified as a percentage. The value should lie between |
yihui | 5:b8c02645e6af | 69 | * 0.0f (representing on 0%) and 1.0f (representing on 100%). |
yihui | 5:b8c02645e6af | 70 | * Values outside this range will be saturated to 0.0f or 1.0f. |
yihui | 5:b8c02645e6af | 71 | */ |
yihui | 5:b8c02645e6af | 72 | void write(float value) { |
yihui | 5:b8c02645e6af | 73 | pwmout_write(&_pwm, value); |
yihui | 5:b8c02645e6af | 74 | } |
yihui | 5:b8c02645e6af | 75 | |
yihui | 5:b8c02645e6af | 76 | /** Return the current output duty-cycle setting, measured as a percentage (float) |
yihui | 5:b8c02645e6af | 77 | * |
yihui | 5:b8c02645e6af | 78 | * @returns |
yihui | 5:b8c02645e6af | 79 | * A floating-point value representing the current duty-cycle being output on the pin, |
yihui | 5:b8c02645e6af | 80 | * measured as a percentage. The returned value will lie between |
yihui | 5:b8c02645e6af | 81 | * 0.0f (representing on 0%) and 1.0f (representing on 100%). |
yihui | 5:b8c02645e6af | 82 | * |
yihui | 5:b8c02645e6af | 83 | * @note |
yihui | 5:b8c02645e6af | 84 | * This value may not match exactly the value set by a previous <write>. |
yihui | 5:b8c02645e6af | 85 | */ |
yihui | 5:b8c02645e6af | 86 | float read() { |
yihui | 5:b8c02645e6af | 87 | return pwmout_read(&_pwm); |
yihui | 5:b8c02645e6af | 88 | } |
yihui | 5:b8c02645e6af | 89 | |
yihui | 5:b8c02645e6af | 90 | /** Set the PWM period, specified in seconds (float), keeping the duty cycle the same. |
yihui | 5:b8c02645e6af | 91 | * |
yihui | 5:b8c02645e6af | 92 | * @note |
yihui | 5:b8c02645e6af | 93 | * The resolution is currently in microseconds; periods smaller than this |
yihui | 5:b8c02645e6af | 94 | * will be set to zero. |
yihui | 5:b8c02645e6af | 95 | */ |
yihui | 5:b8c02645e6af | 96 | void period(float seconds) { |
yihui | 5:b8c02645e6af | 97 | pwmout_period(&_pwm, seconds); |
yihui | 5:b8c02645e6af | 98 | } |
yihui | 5:b8c02645e6af | 99 | |
yihui | 5:b8c02645e6af | 100 | /** Set the PWM period, specified in milli-seconds (int), keeping the duty cycle the same. |
yihui | 5:b8c02645e6af | 101 | */ |
yihui | 5:b8c02645e6af | 102 | void period_ms(int ms) { |
yihui | 5:b8c02645e6af | 103 | pwmout_period_ms(&_pwm, ms); |
yihui | 5:b8c02645e6af | 104 | } |
yihui | 5:b8c02645e6af | 105 | |
yihui | 5:b8c02645e6af | 106 | /** Set the PWM period, specified in micro-seconds (int), keeping the duty cycle the same. |
yihui | 5:b8c02645e6af | 107 | */ |
yihui | 5:b8c02645e6af | 108 | void period_us(int us) { |
yihui | 5:b8c02645e6af | 109 | pwmout_period_us(&_pwm, us); |
yihui | 5:b8c02645e6af | 110 | } |
yihui | 5:b8c02645e6af | 111 | |
yihui | 5:b8c02645e6af | 112 | /** Set the PWM pulsewidth, specified in seconds (float), keeping the period the same. |
yihui | 5:b8c02645e6af | 113 | */ |
yihui | 5:b8c02645e6af | 114 | void pulsewidth(float seconds) { |
yihui | 5:b8c02645e6af | 115 | pwmout_pulsewidth(&_pwm, seconds); |
yihui | 5:b8c02645e6af | 116 | } |
yihui | 5:b8c02645e6af | 117 | |
yihui | 5:b8c02645e6af | 118 | /** Set the PWM pulsewidth, specified in milli-seconds (int), keeping the period the same. |
yihui | 5:b8c02645e6af | 119 | */ |
yihui | 5:b8c02645e6af | 120 | void pulsewidth_ms(int ms) { |
yihui | 5:b8c02645e6af | 121 | pwmout_pulsewidth_ms(&_pwm, ms); |
yihui | 5:b8c02645e6af | 122 | } |
yihui | 5:b8c02645e6af | 123 | |
yihui | 5:b8c02645e6af | 124 | /** Set the PWM pulsewidth, specified in micro-seconds (int), keeping the period the same. |
yihui | 5:b8c02645e6af | 125 | */ |
yihui | 5:b8c02645e6af | 126 | void pulsewidth_us(int us) { |
yihui | 5:b8c02645e6af | 127 | pwmout_pulsewidth_us(&_pwm, us); |
yihui | 5:b8c02645e6af | 128 | } |
yihui | 5:b8c02645e6af | 129 | |
yihui | 5:b8c02645e6af | 130 | #ifdef MBED_OPERATORS |
yihui | 5:b8c02645e6af | 131 | /** A operator shorthand for write() |
yihui | 5:b8c02645e6af | 132 | */ |
yihui | 5:b8c02645e6af | 133 | PwmOut& operator= (float value) { |
yihui | 5:b8c02645e6af | 134 | write(value); |
yihui | 5:b8c02645e6af | 135 | return *this; |
yihui | 5:b8c02645e6af | 136 | } |
yihui | 5:b8c02645e6af | 137 | |
yihui | 5:b8c02645e6af | 138 | PwmOut& operator= (PwmOut& rhs) { |
yihui | 5:b8c02645e6af | 139 | write(rhs.read()); |
yihui | 5:b8c02645e6af | 140 | return *this; |
yihui | 5:b8c02645e6af | 141 | } |
yihui | 5:b8c02645e6af | 142 | |
yihui | 5:b8c02645e6af | 143 | /** An operator shorthand for read() |
yihui | 5:b8c02645e6af | 144 | */ |
yihui | 5:b8c02645e6af | 145 | operator float() { |
yihui | 5:b8c02645e6af | 146 | return read(); |
yihui | 5:b8c02645e6af | 147 | } |
yihui | 5:b8c02645e6af | 148 | #endif |
yihui | 5:b8c02645e6af | 149 | |
yihui | 5:b8c02645e6af | 150 | protected: |
yihui | 5:b8c02645e6af | 151 | pwmout_t _pwm; |
yihui | 5:b8c02645e6af | 152 | }; |
yihui | 5:b8c02645e6af | 153 | |
yihui | 5:b8c02645e6af | 154 | } // namespace mbed |
yihui | 5:b8c02645e6af | 155 | |
yihui | 5:b8c02645e6af | 156 | #endif |
yihui | 5:b8c02645e6af | 157 | |
yihui | 5:b8c02645e6af | 158 | #endif |