PwmIn library by Simon Ford updated and revisited to mbed OS 5.
PwmIn.cpp@0:3f89bf958c96, 2017-10-18 (annotated)
- Committer:
- Musashi91
- Date:
- Wed Oct 18 00:09:12 2017 +0000
- Revision:
- 0:3f89bf958c96
PwmIn library by Simon Ford updated and revisited to mbed OS 5.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Musashi91 | 0:3f89bf958c96 | 1 | /* mbed PwmIn Library UPDATED |
Musashi91 | 0:3f89bf958c96 | 2 | * Copyright (c) 2008-2010, sford |
Musashi91 | 0:3f89bf958c96 | 3 | *------------------------------------------------------------------------------ |
Musashi91 | 0:3f89bf958c96 | 4 | *Rise and Fall libraries were giving warning: "mbed::InterruptIn::rise(T *, M) |
Musashi91 | 0:3f89bf958c96 | 5 | *[with T=PwmIn, M=void (PwmIn::*)()] was declared deprecated". As of that , |
Musashi91 | 0:3f89bf958c96 | 6 | *I updated the code with the proper functions. |
Musashi91 | 0:3f89bf958c96 | 7 | *_p.rise(this, &PwmIn::rise); changed with _p.rise(callback(this, &PwmIn::rise)); |
Musashi91 | 0:3f89bf958c96 | 8 | *_p.fall(this, &PwmIn::rise); changed with _p.fall(callback(this, &PwmIn::rise)); |
Musashi91 | 0:3f89bf958c96 | 9 | *I also changed some methods names beacause I think they could generate some |
Musashi91 | 0:3f89bf958c96 | 10 | *confusion while progamming together with PwmOut. |
Musashi91 | 0:3f89bf958c96 | 11 | *-------------------------------------------------------------dpalombi |
Musashi91 | 0:3f89bf958c96 | 12 | * |
Musashi91 | 0:3f89bf958c96 | 13 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
Musashi91 | 0:3f89bf958c96 | 14 | * of this software and associated documentation files (the "Software"), to deal |
Musashi91 | 0:3f89bf958c96 | 15 | * in the Software without restriction, including without limitation the rights |
Musashi91 | 0:3f89bf958c96 | 16 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
Musashi91 | 0:3f89bf958c96 | 17 | * copies of the Software, and to permit persons to whom the Software is |
Musashi91 | 0:3f89bf958c96 | 18 | * furnished to do so, subject to the following conditions: |
Musashi91 | 0:3f89bf958c96 | 19 | * |
Musashi91 | 0:3f89bf958c96 | 20 | * The above copyright notice and this permission notice shall be included in |
Musashi91 | 0:3f89bf958c96 | 21 | * all copies or substantial portions of the Software. |
Musashi91 | 0:3f89bf958c96 | 22 | * |
Musashi91 | 0:3f89bf958c96 | 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
Musashi91 | 0:3f89bf958c96 | 24 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
Musashi91 | 0:3f89bf958c96 | 25 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
Musashi91 | 0:3f89bf958c96 | 26 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
Musashi91 | 0:3f89bf958c96 | 27 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
Musashi91 | 0:3f89bf958c96 | 28 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
Musashi91 | 0:3f89bf958c96 | 29 | * THE SOFTWARE. |
Musashi91 | 0:3f89bf958c96 | 30 | */ |
Musashi91 | 0:3f89bf958c96 | 31 | #include "PwmIn.h" |
Musashi91 | 0:3f89bf958c96 | 32 | |
Musashi91 | 0:3f89bf958c96 | 33 | PwmIn::PwmIn(PinName p) : _p(p) { |
Musashi91 | 0:3f89bf958c96 | 34 | _p.rise(callback(this, &PwmIn::rise)); |
Musashi91 | 0:3f89bf958c96 | 35 | _p.fall(callback(this, &PwmIn::fall)); |
Musashi91 | 0:3f89bf958c96 | 36 | _period = 0.0; |
Musashi91 | 0:3f89bf958c96 | 37 | _pulsewidth = 0.0; |
Musashi91 | 0:3f89bf958c96 | 38 | _t.start(); |
Musashi91 | 0:3f89bf958c96 | 39 | } |
Musashi91 | 0:3f89bf958c96 | 40 | |
Musashi91 | 0:3f89bf958c96 | 41 | float PwmIn::periodIn() { |
Musashi91 | 0:3f89bf958c96 | 42 | return _period; |
Musashi91 | 0:3f89bf958c96 | 43 | } |
Musashi91 | 0:3f89bf958c96 | 44 | |
Musashi91 | 0:3f89bf958c96 | 45 | float PwmIn::pulsewidthIn() { |
Musashi91 | 0:3f89bf958c96 | 46 | return _pulsewidth; |
Musashi91 | 0:3f89bf958c96 | 47 | } |
Musashi91 | 0:3f89bf958c96 | 48 | |
Musashi91 | 0:3f89bf958c96 | 49 | float PwmIn::dutycycleIn() { |
Musashi91 | 0:3f89bf958c96 | 50 | return _pulsewidth / _period; |
Musashi91 | 0:3f89bf958c96 | 51 | } |
Musashi91 | 0:3f89bf958c96 | 52 | |
Musashi91 | 0:3f89bf958c96 | 53 | void PwmIn::rise() { |
Musashi91 | 0:3f89bf958c96 | 54 | _period = _t.read(); |
Musashi91 | 0:3f89bf958c96 | 55 | _t.reset(); |
Musashi91 | 0:3f89bf958c96 | 56 | } |
Musashi91 | 0:3f89bf958c96 | 57 | |
Musashi91 | 0:3f89bf958c96 | 58 | void PwmIn::fall() { |
Musashi91 | 0:3f89bf958c96 | 59 | _pulsewidth = _t.read(); |
Musashi91 | 0:3f89bf958c96 | 60 | } |