Mbed SDK for XRange SX1272 LoRa module

Dependents:   XRangePingPong XRange-LoRaWAN-lmic-app lora-transceiver

SX1272 LoRa RF module

https://www.netblocks.eu/xrange-sx1272-lora-datasheet/

Committer:
netblocks
Date:
Thu Jan 07 13:01:25 2016 +0000
Revision:
339:ac6f3fd999f3
Parent:
336:1e18a06a987b
HSE_VALUE set for XTAL 16Mhz

Who changed what in which revision?

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