PPM library based on teensy 3 PulsePostion library. uses k64f FTM0 PWM pins.

Dependents:   k64f_ppmtst

PPM library based on teensy 3 PulsePostion library. uses k64f FTM0 PWM pins.

https://www.pjrc.com/teensy/td_libs_PulsePosition.html

Committer:
manitou
Date:
Thu Apr 21 17:04:15 2016 +0000
Revision:
1:cb791d277230
Parent:
0:3b67d4bc53ca
fix alt selection for pin mux

Who changed what in which revision?

UserRevisionLine numberNew contents of line
manitou 0:3b67d4bc53ca 1 /* PulsePosition Library for Teensy 3.1
manitou 0:3b67d4bc53ca 2 * High resolution input and output of PPM encoded signals
manitou 0:3b67d4bc53ca 3 * http://www.pjrc.com/teensy/td_libs_PulsePosition.html
manitou 0:3b67d4bc53ca 4 * Copyright (c) 2014, Paul Stoffregen, paul@pjrc.com
manitou 0:3b67d4bc53ca 5 *
manitou 0:3b67d4bc53ca 6 * Development of this library was funded by PJRC.COM, LLC by sales of Teensy
manitou 0:3b67d4bc53ca 7 * boards. Please support PJRC's efforts to develop open source software by
manitou 0:3b67d4bc53ca 8 * purchasing Teensy or other PJRC products.
manitou 0:3b67d4bc53ca 9 *
manitou 0:3b67d4bc53ca 10 * Permission is hereby granted, free of charge, to any person obtaining a copy
manitou 0:3b67d4bc53ca 11 * of this software and associated documentation files (the "Software"), to deal
manitou 0:3b67d4bc53ca 12 * in the Software without restriction, including without limitation the rights
manitou 0:3b67d4bc53ca 13 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
manitou 0:3b67d4bc53ca 14 * copies of the Software, and to permit persons to whom the Software is
manitou 0:3b67d4bc53ca 15 * furnished to do so, subject to the following conditions:
manitou 0:3b67d4bc53ca 16 *
manitou 0:3b67d4bc53ca 17 * The above copyright notice, development funding notice, and this permission
manitou 0:3b67d4bc53ca 18 * notice shall be included in all copies or substantial portions of the Software.
manitou 0:3b67d4bc53ca 19 *
manitou 0:3b67d4bc53ca 20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
manitou 0:3b67d4bc53ca 21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
manitou 0:3b67d4bc53ca 22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
manitou 0:3b67d4bc53ca 23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
manitou 0:3b67d4bc53ca 24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
manitou 0:3b67d4bc53ca 25 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
manitou 0:3b67d4bc53ca 26 * THE SOFTWARE.
manitou 0:3b67d4bc53ca 27 */
manitou 0:3b67d4bc53ca 28 #include "mbed.h"
manitou 0:3b67d4bc53ca 29
manitou 0:3b67d4bc53ca 30 #define PULSEPOSITION_MAXCHANNELS 16
manitou 0:3b67d4bc53ca 31 #define FALLING 2
manitou 0:3b67d4bc53ca 32 #define RISING 3
manitou 0:3b67d4bc53ca 33
manitou 0:3b67d4bc53ca 34 struct ftm_channel_struct {
manitou 0:3b67d4bc53ca 35 uint32_t csc;
manitou 0:3b67d4bc53ca 36 uint32_t cv;
manitou 0:3b67d4bc53ca 37 };
manitou 0:3b67d4bc53ca 38
manitou 0:3b67d4bc53ca 39 class PulsePositionOutput
manitou 0:3b67d4bc53ca 40 {
manitou 0:3b67d4bc53ca 41 public:
manitou 0:3b67d4bc53ca 42 PulsePositionOutput(void);
manitou 0:3b67d4bc53ca 43 PulsePositionOutput(int polarity);
manitou 0:3b67d4bc53ca 44 bool begin(PinName txPin); // txPin can be 5,6,9,10,20,21,22,23
manitou 0:3b67d4bc53ca 45 bool begin(PinName txPin, PinName framePin);
manitou 0:3b67d4bc53ca 46 bool write(uint8_t channel, float microseconds);
manitou 0:3b67d4bc53ca 47 friend void ftm0_isr(void);
manitou 0:3b67d4bc53ca 48 private:
manitou 0:3b67d4bc53ca 49 void isr(void);
manitou 0:3b67d4bc53ca 50 uint32_t pulse_width[PULSEPOSITION_MAXCHANNELS+1];
manitou 0:3b67d4bc53ca 51 uint32_t pulse_buffer[PULSEPOSITION_MAXCHANNELS+1];
manitou 0:3b67d4bc53ca 52 uint32_t pulse_remaining;
manitou 0:3b67d4bc53ca 53 DigitalOut *framePinReg;
manitou 0:3b67d4bc53ca 54 volatile uint8_t framePinMask;
manitou 0:3b67d4bc53ca 55 struct ftm_channel_struct *ftm;
manitou 0:3b67d4bc53ca 56 uint8_t state;
manitou 0:3b67d4bc53ca 57 uint8_t current_channel;
manitou 0:3b67d4bc53ca 58 uint8_t total_channels;
manitou 0:3b67d4bc53ca 59 uint8_t total_channels_buffer;
manitou 0:3b67d4bc53ca 60 uint8_t cscSet;
manitou 0:3b67d4bc53ca 61 uint8_t cscClear;
manitou 0:3b67d4bc53ca 62 static PulsePositionOutput *list[8];
manitou 0:3b67d4bc53ca 63 static uint8_t channelmask;
manitou 0:3b67d4bc53ca 64 };
manitou 0:3b67d4bc53ca 65
manitou 0:3b67d4bc53ca 66
manitou 0:3b67d4bc53ca 67 class PulsePositionInput
manitou 0:3b67d4bc53ca 68 {
manitou 0:3b67d4bc53ca 69 public:
manitou 0:3b67d4bc53ca 70 PulsePositionInput(void);
manitou 0:3b67d4bc53ca 71 PulsePositionInput(int polarity);
manitou 0:3b67d4bc53ca 72 bool begin(PinName rxPin); // rxPin can be 5,6,9,10,20,21,22,23
manitou 0:3b67d4bc53ca 73 int available(void);
manitou 0:3b67d4bc53ca 74 float read(uint8_t channel);
manitou 0:3b67d4bc53ca 75 friend void ftm0_isr(void);
manitou 0:3b67d4bc53ca 76 private:
manitou 0:3b67d4bc53ca 77 void isr(void);
manitou 0:3b67d4bc53ca 78 struct ftm_channel_struct *ftm;
manitou 0:3b67d4bc53ca 79 uint32_t pulse_width[PULSEPOSITION_MAXCHANNELS];
manitou 0:3b67d4bc53ca 80 uint32_t pulse_buffer[PULSEPOSITION_MAXCHANNELS];
manitou 0:3b67d4bc53ca 81 uint32_t prev;
manitou 0:3b67d4bc53ca 82 uint8_t write_index;
manitou 0:3b67d4bc53ca 83 uint8_t total_channels;
manitou 0:3b67d4bc53ca 84 uint8_t cscEdge;
manitou 0:3b67d4bc53ca 85 bool available_flag;
manitou 0:3b67d4bc53ca 86 static bool overflow_inc;
manitou 0:3b67d4bc53ca 87 static uint16_t overflow_count;
manitou 0:3b67d4bc53ca 88 static PulsePositionInput *list[8];
manitou 0:3b67d4bc53ca 89 static uint8_t channelmask;
manitou 0:3b67d4bc53ca 90 };
manitou 0:3b67d4bc53ca 91
manitou 0:3b67d4bc53ca 92