MCU driver/HAL for the Picocell Gateway concentrator board. The firmware implements either a USB CDC protocol or a UART protocol to bridge commands coming from host to the SX1308 SPI interface.

Committer:
dgabino
Date:
Wed Apr 11 14:42:47 2018 +0000
Revision:
0:c76361bd82e8
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dgabino 0:c76361bd82e8 1 /* mbed Microcontroller Library
dgabino 0:c76361bd82e8 2 * Copyright (c) 2006-2013 ARM Limited
dgabino 0:c76361bd82e8 3 *
dgabino 0:c76361bd82e8 4 * Licensed under the Apache License, Version 2.0 (the "License");
dgabino 0:c76361bd82e8 5 * you may not use this file except in compliance with the License.
dgabino 0:c76361bd82e8 6 * You may obtain a copy of the License at
dgabino 0:c76361bd82e8 7 *
dgabino 0:c76361bd82e8 8 * http://www.apache.org/licenses/LICENSE-2.0
dgabino 0:c76361bd82e8 9 *
dgabino 0:c76361bd82e8 10 * Unless required by applicable law or agreed to in writing, software
dgabino 0:c76361bd82e8 11 * distributed under the License is distributed on an "AS IS" BASIS,
dgabino 0:c76361bd82e8 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
dgabino 0:c76361bd82e8 13 * See the License for the specific language governing permissions and
dgabino 0:c76361bd82e8 14 * limitations under the License.
dgabino 0:c76361bd82e8 15 */
dgabino 0:c76361bd82e8 16 #ifndef MBED_PWMOUT_H
dgabino 0:c76361bd82e8 17 #define MBED_PWMOUT_H
dgabino 0:c76361bd82e8 18
dgabino 0:c76361bd82e8 19 #include "platform.h"
dgabino 0:c76361bd82e8 20
dgabino 0:c76361bd82e8 21 #if DEVICE_PWMOUT
dgabino 0:c76361bd82e8 22 #include "pwmout_api.h"
dgabino 0:c76361bd82e8 23 #include "critical.h"
dgabino 0:c76361bd82e8 24
dgabino 0:c76361bd82e8 25 namespace mbed {
dgabino 0:c76361bd82e8 26
dgabino 0:c76361bd82e8 27 /** A pulse-width modulation digital output
dgabino 0:c76361bd82e8 28 *
dgabino 0:c76361bd82e8 29 * @Note Synchronization level: Interrupt safe
dgabino 0:c76361bd82e8 30 *
dgabino 0:c76361bd82e8 31 * Example
dgabino 0:c76361bd82e8 32 * @code
dgabino 0:c76361bd82e8 33 * // Fade a led on.
dgabino 0:c76361bd82e8 34 * #include "mbed.h"
dgabino 0:c76361bd82e8 35 *
dgabino 0:c76361bd82e8 36 * PwmOut led(LED1);
dgabino 0:c76361bd82e8 37 *
dgabino 0:c76361bd82e8 38 * int main() {
dgabino 0:c76361bd82e8 39 * while(1) {
dgabino 0:c76361bd82e8 40 * led = led + 0.01;
dgabino 0:c76361bd82e8 41 * wait(0.2);
dgabino 0:c76361bd82e8 42 * if(led == 1.0) {
dgabino 0:c76361bd82e8 43 * led = 0;
dgabino 0:c76361bd82e8 44 * }
dgabino 0:c76361bd82e8 45 * }
dgabino 0:c76361bd82e8 46 * }
dgabino 0:c76361bd82e8 47 * @endcode
dgabino 0:c76361bd82e8 48 *
dgabino 0:c76361bd82e8 49 * @note
dgabino 0:c76361bd82e8 50 * On the LPC1768 and LPC2368, the PWMs all share the same
dgabino 0:c76361bd82e8 51 * period - if you change the period for one, you change it for all.
dgabino 0:c76361bd82e8 52 * Although routines that change the period maintain the duty cycle
dgabino 0:c76361bd82e8 53 * for its PWM, all other PWMs will require their duty cycle to be
dgabino 0:c76361bd82e8 54 * refreshed.
dgabino 0:c76361bd82e8 55 */
dgabino 0:c76361bd82e8 56 class PwmOut {
dgabino 0:c76361bd82e8 57
dgabino 0:c76361bd82e8 58 public:
dgabino 0:c76361bd82e8 59
dgabino 0:c76361bd82e8 60 /** Create a PwmOut connected to the specified pin
dgabino 0:c76361bd82e8 61 *
dgabino 0:c76361bd82e8 62 * @param pin PwmOut pin to connect to
dgabino 0:c76361bd82e8 63 */
dgabino 0:c76361bd82e8 64 PwmOut(PinName pin) {
dgabino 0:c76361bd82e8 65 core_util_critical_section_enter();
dgabino 0:c76361bd82e8 66 pwmout_init(&_pwm, pin);
dgabino 0:c76361bd82e8 67 core_util_critical_section_exit();
dgabino 0:c76361bd82e8 68 }
dgabino 0:c76361bd82e8 69
dgabino 0:c76361bd82e8 70 /** Set the ouput duty-cycle, specified as a percentage (float)
dgabino 0:c76361bd82e8 71 *
dgabino 0:c76361bd82e8 72 * @param value A floating-point value representing the output duty-cycle,
dgabino 0:c76361bd82e8 73 * specified as a percentage. The value should lie between
dgabino 0:c76361bd82e8 74 * 0.0f (representing on 0%) and 1.0f (representing on 100%).
dgabino 0:c76361bd82e8 75 * Values outside this range will be saturated to 0.0f or 1.0f.
dgabino 0:c76361bd82e8 76 */
dgabino 0:c76361bd82e8 77 void write(float value) {
dgabino 0:c76361bd82e8 78 core_util_critical_section_enter();
dgabino 0:c76361bd82e8 79 pwmout_write(&_pwm, value);
dgabino 0:c76361bd82e8 80 core_util_critical_section_exit();
dgabino 0:c76361bd82e8 81 }
dgabino 0:c76361bd82e8 82
dgabino 0:c76361bd82e8 83 /** Return the current output duty-cycle setting, measured as a percentage (float)
dgabino 0:c76361bd82e8 84 *
dgabino 0:c76361bd82e8 85 * @returns
dgabino 0:c76361bd82e8 86 * A floating-point value representing the current duty-cycle being output on the pin,
dgabino 0:c76361bd82e8 87 * measured as a percentage. The returned value will lie between
dgabino 0:c76361bd82e8 88 * 0.0f (representing on 0%) and 1.0f (representing on 100%).
dgabino 0:c76361bd82e8 89 *
dgabino 0:c76361bd82e8 90 * @note
dgabino 0:c76361bd82e8 91 * This value may not match exactly the value set by a previous <write>.
dgabino 0:c76361bd82e8 92 */
dgabino 0:c76361bd82e8 93 float read() {
dgabino 0:c76361bd82e8 94 core_util_critical_section_enter();
dgabino 0:c76361bd82e8 95 float val = pwmout_read(&_pwm);
dgabino 0:c76361bd82e8 96 core_util_critical_section_exit();
dgabino 0:c76361bd82e8 97 return val;
dgabino 0:c76361bd82e8 98 }
dgabino 0:c76361bd82e8 99
dgabino 0:c76361bd82e8 100 /** Set the PWM period, specified in seconds (float), keeping the duty cycle the same.
dgabino 0:c76361bd82e8 101 *
dgabino 0:c76361bd82e8 102 * @note
dgabino 0:c76361bd82e8 103 * The resolution is currently in microseconds; periods smaller than this
dgabino 0:c76361bd82e8 104 * will be set to zero.
dgabino 0:c76361bd82e8 105 */
dgabino 0:c76361bd82e8 106 void period(float seconds) {
dgabino 0:c76361bd82e8 107 core_util_critical_section_enter();
dgabino 0:c76361bd82e8 108 pwmout_period(&_pwm, seconds);
dgabino 0:c76361bd82e8 109 core_util_critical_section_exit();
dgabino 0:c76361bd82e8 110 }
dgabino 0:c76361bd82e8 111
dgabino 0:c76361bd82e8 112 /** Set the PWM period, specified in milli-seconds (int), keeping the duty cycle the same.
dgabino 0:c76361bd82e8 113 */
dgabino 0:c76361bd82e8 114 void period_ms(int ms) {
dgabino 0:c76361bd82e8 115 core_util_critical_section_enter();
dgabino 0:c76361bd82e8 116 pwmout_period_ms(&_pwm, ms);
dgabino 0:c76361bd82e8 117 core_util_critical_section_exit();
dgabino 0:c76361bd82e8 118 }
dgabino 0:c76361bd82e8 119
dgabino 0:c76361bd82e8 120 /** Set the PWM period, specified in micro-seconds (int), keeping the duty cycle the same.
dgabino 0:c76361bd82e8 121 */
dgabino 0:c76361bd82e8 122 void period_us(int us) {
dgabino 0:c76361bd82e8 123 core_util_critical_section_enter();
dgabino 0:c76361bd82e8 124 pwmout_period_us(&_pwm, us);
dgabino 0:c76361bd82e8 125 core_util_critical_section_exit();
dgabino 0:c76361bd82e8 126 }
dgabino 0:c76361bd82e8 127
dgabino 0:c76361bd82e8 128 /** Set the PWM pulsewidth, specified in seconds (float), keeping the period the same.
dgabino 0:c76361bd82e8 129 */
dgabino 0:c76361bd82e8 130 void pulsewidth(float seconds) {
dgabino 0:c76361bd82e8 131 core_util_critical_section_enter();
dgabino 0:c76361bd82e8 132 pwmout_pulsewidth(&_pwm, seconds);
dgabino 0:c76361bd82e8 133 core_util_critical_section_exit();
dgabino 0:c76361bd82e8 134 }
dgabino 0:c76361bd82e8 135
dgabino 0:c76361bd82e8 136 /** Set the PWM pulsewidth, specified in milli-seconds (int), keeping the period the same.
dgabino 0:c76361bd82e8 137 */
dgabino 0:c76361bd82e8 138 void pulsewidth_ms(int ms) {
dgabino 0:c76361bd82e8 139 core_util_critical_section_enter();
dgabino 0:c76361bd82e8 140 pwmout_pulsewidth_ms(&_pwm, ms);
dgabino 0:c76361bd82e8 141 core_util_critical_section_exit();
dgabino 0:c76361bd82e8 142 }
dgabino 0:c76361bd82e8 143
dgabino 0:c76361bd82e8 144 /** Set the PWM pulsewidth, specified in micro-seconds (int), keeping the period the same.
dgabino 0:c76361bd82e8 145 */
dgabino 0:c76361bd82e8 146 void pulsewidth_us(int us) {
dgabino 0:c76361bd82e8 147 core_util_critical_section_enter();
dgabino 0:c76361bd82e8 148 pwmout_pulsewidth_us(&_pwm, us);
dgabino 0:c76361bd82e8 149 core_util_critical_section_exit();
dgabino 0:c76361bd82e8 150 }
dgabino 0:c76361bd82e8 151
dgabino 0:c76361bd82e8 152 /** A operator shorthand for write()
dgabino 0:c76361bd82e8 153 */
dgabino 0:c76361bd82e8 154 PwmOut& operator= (float value) {
dgabino 0:c76361bd82e8 155 // Underlying call is thread safe
dgabino 0:c76361bd82e8 156 write(value);
dgabino 0:c76361bd82e8 157 return *this;
dgabino 0:c76361bd82e8 158 }
dgabino 0:c76361bd82e8 159
dgabino 0:c76361bd82e8 160 PwmOut& operator= (PwmOut& rhs) {
dgabino 0:c76361bd82e8 161 // Underlying call is thread safe
dgabino 0:c76361bd82e8 162 write(rhs.read());
dgabino 0:c76361bd82e8 163 return *this;
dgabino 0:c76361bd82e8 164 }
dgabino 0:c76361bd82e8 165
dgabino 0:c76361bd82e8 166 /** An operator shorthand for read()
dgabino 0:c76361bd82e8 167 */
dgabino 0:c76361bd82e8 168 operator float() {
dgabino 0:c76361bd82e8 169 // Underlying call is thread safe
dgabino 0:c76361bd82e8 170 return read();
dgabino 0:c76361bd82e8 171 }
dgabino 0:c76361bd82e8 172
dgabino 0:c76361bd82e8 173 protected:
dgabino 0:c76361bd82e8 174 pwmout_t _pwm;
dgabino 0:c76361bd82e8 175 };
dgabino 0:c76361bd82e8 176
dgabino 0:c76361bd82e8 177 } // namespace mbed
dgabino 0:c76361bd82e8 178
dgabino 0:c76361bd82e8 179 #endif
dgabino 0:c76361bd82e8 180
dgabino 0:c76361bd82e8 181 #endif