Paparazzi UAS v7.1_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
pwm_input_arch.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2015 Gautier Hattenberger <gautier.hattenberger@enac.fr>
3 *
4 * This file is part of paparazzi.
5 *
6 * paparazzi is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
9 * any later version.
10 *
11 * paparazzi is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with paparazzi; see the file COPYING. If not, write to
18 * the Free Software Foundation, 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
20 */
21
30#include "mcu_periph/gpio.h"
31#include <hal.h>
32#include BOARD_CONFIG
33
34#define ONE_MHZ_CLK 1000000
35
36#ifdef USE_PWM_INPUT1
37static void input1_period_cb(ICUDriver *icup) {
38 pwm_input_period_tics[PWM_INPUT1] = icuGetPeriodX(icup);
40}
41
42static void input1_width_cb(ICUDriver *icup) {
43 pwm_input_duty_tics[PWM_INPUT1] = icuGetWidthX(icup);
45}
46
47static ICUConfig pwm_input1_cfg = {
48#if USE_PWM_INPUT1 == PWM_PULSE_TYPE_ACTIVE_LOW
49 ICU_INPUT_ACTIVE_LOW,
50#elif USE_PWM_INPUT1 == PWM_PULSE_TYPE_ACTIVE_HIGH
51 ICU_INPUT_ACTIVE_HIGH,
52#else
53#error "Unknown PWM_INPUT1_PULSE_TYPE"
54#endif
56 input1_width_cb,
57 input1_period_cb,
58 NULL,
60 0,
61 0xFFFFFFFFU
62};
63#endif
64
65#ifdef USE_PWM_INPUT2
66static void input2_period_cb(ICUDriver *icup) {
67 pwm_input_period_tics[PWM_INPUT2] = icuGetPeriodX(icup);
69}
70
71static void input2_width_cb(ICUDriver *icup) {
72 pwm_input_duty_tics[PWM_INPUT2] = icuGetWidthX(icup);
74}
75
76static ICUConfig pwm_input2_cfg = {
77#if USE_PWM_INPUT2 == PWM_PULSE_TYPE_ACTIVE_LOW
78 ICU_INPUT_ACTIVE_LOW,
79#elif USE_PWM_INPUT2 == PWM_PULSE_TYPE_ACTIVE_HIGH
80 ICU_INPUT_ACTIVE_HIGH,
81#else
82#error "Unknown PWM_INPUT2_PULSE_TYPE"
83#endif
85 input2_width_cb,
86 input2_period_cb,
87 NULL,
89 0,
90 0xFFFFFFFFU
91};
92#endif
93
95{
96 int i;
97 // initialize the arrays to 0
98 for (i = 0; i < PWM_INPUT_NB; i++) {
103 }
104
105#ifdef USE_PWM_INPUT1
106 icuStart(&PWM_INPUT1_ICU, &pwm_input1_cfg);
108 icuStartCapture(&PWM_INPUT1_ICU);
109 icuEnableNotifications(&PWM_INPUT1_ICU);
110#endif
111
112#ifdef USE_PWM_INPUT2
113 icuStart(&PWM_INPUT2_ICU, &pwm_input2_cfg);
115 icuStartCapture(&PWM_INPUT2_ICU);
116 icuEnableNotifications(&PWM_INPUT2_ICU);
117#endif
118
119}
120
#define PWM_INPUT2_GPIO_PORT
Definition board.h:430
#define PWM_INPUT2_GPIO_AF
Definition board.h:432
#define PWM_INPUT2_GPIO_PIN
Definition board.h:431
#define PWM_INPUT2_ICU
Definition board.h:428
#define PWM_INPUT2_CHANNEL
Definition board.h:429
void gpio_setup_pin_af(ioportid_t port, uint16_t pin, uint8_t af, bool is_output)
Setup a gpio for input or output with alternate function.
Definition gpio_arch.c:65
#define PWM_INPUT1_GPIO_PORT
#define PWM_INPUT1_CHANNEL
#define PWM_INPUT1_GPIO_AF
#define PWM_INPUT1_ICU
#define PWM_INPUT1_GPIO_PIN
Some architecture independent helper functions for GPIOs.
volatile uint32_t pwm_input_duty_tics[PWM_INPUT_NB]
Definition pwm_input.c:34
volatile uint8_t pwm_input_period_valid[PWM_INPUT_NB]
Definition pwm_input.c:37
volatile uint8_t pwm_input_duty_valid[PWM_INPUT_NB]
Definition pwm_input.c:35
volatile uint32_t pwm_input_period_tics[PWM_INPUT_NB]
Definition pwm_input.c:36
arch independent PWM input capture API
void pwm_input_init(void)
#define ONE_MHZ_CLK
handling of smt32 PWM input using a timer with capture.
@ PWM_INPUT1
@ PWM_INPUT_NB
@ PWM_INPUT2
#define PWM_INPUT2_TICKS_PER_USEC
#define PWM_INPUT1_TICKS_PER_USEC
The default pwm counter is set-up to have 1/6 us resolution.