PwmIn library by Simon Ford updated and revisited to mbed OS 5.
PwmIn.h@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 | |
Musashi91 | 0:3f89bf958c96 | 32 | #ifndef MBED_PWMIN_H |
Musashi91 | 0:3f89bf958c96 | 33 | #define MBED_PWMIN_H |
Musashi91 | 0:3f89bf958c96 | 34 | |
Musashi91 | 0:3f89bf958c96 | 35 | #include "mbed.h" |
Musashi91 | 0:3f89bf958c96 | 36 | |
Musashi91 | 0:3f89bf958c96 | 37 | /** PwmIn class to read PWM inputs |
Musashi91 | 0:3f89bf958c96 | 38 | * |
Musashi91 | 0:3f89bf958c96 | 39 | * Uses InterruptIn to measure the changes on the input |
Musashi91 | 0:3f89bf958c96 | 40 | * and record the time they occur |
Musashi91 | 0:3f89bf958c96 | 41 | * |
Musashi91 | 0:3f89bf958c96 | 42 | * @note uses InterruptIn, so not available on p19/p20 |
Musashi91 | 0:3f89bf958c96 | 43 | */ |
Musashi91 | 0:3f89bf958c96 | 44 | class PwmIn { |
Musashi91 | 0:3f89bf958c96 | 45 | public: |
Musashi91 | 0:3f89bf958c96 | 46 | /** Create a PwmIn |
Musashi91 | 0:3f89bf958c96 | 47 | * |
Musashi91 | 0:3f89bf958c96 | 48 | * @param p The pwm input pin (must support InterruptIn) |
Musashi91 | 0:3f89bf958c96 | 49 | */ |
Musashi91 | 0:3f89bf958c96 | 50 | PwmIn(PinName p); |
Musashi91 | 0:3f89bf958c96 | 51 | |
Musashi91 | 0:3f89bf958c96 | 52 | /** Read the current period |
Musashi91 | 0:3f89bf958c96 | 53 | * |
Musashi91 | 0:3f89bf958c96 | 54 | * @returns the period in seconds |
Musashi91 | 0:3f89bf958c96 | 55 | */ |
Musashi91 | 0:3f89bf958c96 | 56 | float periodIn(); |
Musashi91 | 0:3f89bf958c96 | 57 | |
Musashi91 | 0:3f89bf958c96 | 58 | /** Read the current pulsewidth |
Musashi91 | 0:3f89bf958c96 | 59 | * |
Musashi91 | 0:3f89bf958c96 | 60 | * @returns the pulsewidth in seconds |
Musashi91 | 0:3f89bf958c96 | 61 | */ |
Musashi91 | 0:3f89bf958c96 | 62 | float pulsewidthIn(); |
Musashi91 | 0:3f89bf958c96 | 63 | |
Musashi91 | 0:3f89bf958c96 | 64 | /** Read the current dutycycle |
Musashi91 | 0:3f89bf958c96 | 65 | * |
Musashi91 | 0:3f89bf958c96 | 66 | * @returns the dutycycle as a percentage, represented between 0.0-1.0 |
Musashi91 | 0:3f89bf958c96 | 67 | */ |
Musashi91 | 0:3f89bf958c96 | 68 | float dutycycleIn(); |
Musashi91 | 0:3f89bf958c96 | 69 | |
Musashi91 | 0:3f89bf958c96 | 70 | protected: |
Musashi91 | 0:3f89bf958c96 | 71 | void rise(); |
Musashi91 | 0:3f89bf958c96 | 72 | void fall(); |
Musashi91 | 0:3f89bf958c96 | 73 | |
Musashi91 | 0:3f89bf958c96 | 74 | InterruptIn _p; |
Musashi91 | 0:3f89bf958c96 | 75 | Timer _t; |
Musashi91 | 0:3f89bf958c96 | 76 | float _pulsewidth, _period; |
Musashi91 | 0:3f89bf958c96 | 77 | }; |
Musashi91 | 0:3f89bf958c96 | 78 | |
Musashi91 | 0:3f89bf958c96 | 79 | #endif |