APM:Libraries
pwm_in.h
Go to the documentation of this file.
1 /******************************************************************************
2  * The GPLv3 License
3  *
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without
8  * restriction, including without limitation the rights to use, copy,
9  * modify, merge, publish, distribute, sublicense, and/or sell copies
10  * of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23  * SOFTWARE.
24  *****************************************************************************/
25 
26 #ifndef _PWM_IN_H_
27 #define _PWM_IN_H_
28 
29 #include <hal.h>
30 #include "hal_types.h"
31 #include <stdbool.h>
32 #include <strings.h>
33 #include "timer.h"
34 
35 
36 #ifdef __cplusplus
37  extern "C" {
38 #endif
39 
40 typedef struct PULSE {
41  unsigned int length:15;
42  bool state:1;
43 } Pulse;
44 
45 #define PULSES_QUEUE_SIZE (25*12*2) // 1 full frame by 25 bytes (12 bits, 2 measures per bit) each
46 
47 #include "ring_buffer_pulse.h"
48 
49 
50 struct PPM_State {
52  uint32_t last_pulse; // time of edge
53  volatile pulse_buffer pulses; // ring buffer
54  uint16_t last_val; // length
55  uint8_t state; // 1 or 0
56  Pulse pulse_mem[PULSES_QUEUE_SIZE]; // memory
57 };
58 
59 extern struct PPM_State PPM_Inputs[];
60 
61 
62 struct TIM_Channel {
63  uint8_t pin; // pin number
64 };
65 
66 extern const struct TIM_Channel PWM_Channels[];
67 #define PWM_CHANNELS (sizeof(PWM_Channels) / sizeof(struct TIM_Channel) )
68 
69 
70 void pwmInit(bool ppmsum);
71 
72 bool getPPM_Pulse(Pulse *p, uint8_t ch);
73 uint16_t getPPM_count(uint8_t ch);
74 
75 static inline void pwm_setHandler(Handler handler, uint8_t ch){
76  PPM_Inputs[ch].handler = handler;
77 }
78 
79 #ifdef __cplusplus
80  }
81 #endif
82 
83 #endif
84 
Handler handler
Definition: pwm_in.h:51
uint32_t last_pulse
Definition: pwm_in.h:52
bool state
Definition: pwm_in.h:42
Simple circular buffer for PEM input.
volatile pulse_buffer pulses
Definition: pwm_in.h:53
bool getPPM_Pulse(Pulse *p, uint8_t ch)
Definition: pwm_in.c:183
static void pwm_setHandler(Handler handler, uint8_t ch)
Definition: pwm_in.h:75
timer interface.
uint16_t last_val
Definition: pwm_in.h:54
#define PULSES_QUEUE_SIZE
Definition: pwm_in.h:45
const struct TIM_Channel PWM_Channels[]
uint16_t getPPM_count(uint8_t ch)
Definition: pwm_in.c:193
struct PPM_State PPM_Inputs[]
uint8_t pin
Definition: pwm_in.h:63
struct PULSE Pulse
Definition: pwm_in.h:40
uint8_t state
Definition: pwm_in.h:55
unsigned int length
Definition: pwm_in.h:41
uint64_t Handler
Definition: hal_types.h:19
void pwmInit(bool ppmsum)
Definition: pwm_in.c:165