Paparazzi UAS  v5.0.5_stable-7-g4b8bbb7
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
servos_4017_hw.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006 Antoine Drouin
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  */
22 #include "subsystems/actuators.h"
23 
24 #include "paparazzi.h"
25 #include "generated/airframe.h"
26 
28 
29 #define START_TIMEOUT 0xFFFF;
30 
31 void actuators_4017_init ( void ) {
32  /* select clock pin as MAT0.1 output */
33  IO0DIR |= _BV(SERVO_CLOCK_PIN);
35 
36  /* select reset pin as GPIO output */
37  IO1DIR |= _BV(SERVO_RESET_PIN);
38  PINSEL2 &= ~(_BV(3)); /* P1.25-16 are used as GPIO */
39  // SERVO_RESET_PINSEL |= SERVO_RESET_PINSEL_VAL << SERVO_RESET_PINSEL_BIT;
40  /* assert RESET */
41  IO1SET = _BV(SERVO_RESET_PIN);
42 
43  /* enable match 1 interrupt */
44  T0MCR |= TMCR_MR1_I;
45 
46 #ifndef SERVOS_4017_CLOCK_FALLING
47  /* lower clock */
48  T0EMR &= ~TEMR_EM1;
49  /* set high on match 1 */
50  T0EMR |= TEMR_EMC1_2;
51 #else
52  /* assert clock */
53  T0EMR |= TEMR_EM1;
54  /* set low on match 1 */
55  T0EMR |= TEMR_EMC1_1;
56 #endif
57  /* set first pulse in a while */
60  /* Set all servos at their midpoints */
61  /* compulsory for unaffected servos */
62  uint8_t i;
63  for( i=0 ; i < _4017_NB_CHANNELS ; i++ )
65 #ifdef SERVO_MOTOR
66  servos_values[SERVO_MOTOR] = SERVOS_TICS_OF_USEC(SERVO_MOTOR_NEUTRAL);
67 #endif
68 #ifdef SERVO_MOTOR_LEFT
69  servos_values[SERVO_MOTOR_LEFT] = SERVOS_TICS_OF_USEC(SERVO_MOTOR_LEFT_NEUTRAL);
70 #endif
71 #ifdef SERVO_MOTOR_RIGHT
72  servos_values[SERVO_MOTOR_RIGHT] = SERVOS_TICS_OF_USEC(SERVO_MOTOR_RIGHT_NEUTRAL);
73 #endif
74 #ifdef SERVO_HATCH
75  servos_values[SERVO_HATCH] = SERVOS_TICS_OF_USEC(SERVO_HATCH_NEUTRAL);
76 #endif
77 }
78 
79 
81 
unsigned short uint16_t
Definition: types.h:16
#define IO1SET
Definition: LPC21xx.h:338
#define START_TIMEOUT
#define SERVO_CLOCK_PINSEL
Definition: hb_1.1.h:56
#define SERVOS_TICS_OF_USEC(s)
#define SERVO_CLOCK_PINSEL_BIT
Definition: hb_1.1.h:58
#define T0MCR
Definition: LPC21xx.h:55
#define TMCR_MR1_I
Definition: lpcTMR.h:62
#define SERVO_CLOCK_PIN
Definition: hb_1.1.h:55
#define TEMR_EMC1_1
Definition: lpcTMR.h:158
uint16_t servos_values[_4017_NB_CHANNELS]
Hardware independent API for actuators (servos, motor controllers).
#define T0EMR
Definition: LPC21xx.h:65
#define T0MR1
Definition: LPC21xx.h:57
#define IO0DIR
Definition: LPC21xx.h:335
uint8_t servos_4017_idx
unsigned char uint8_t
Definition: types.h:14
#define PINSEL2
Definition: LPC21xx.h:349
#define TEMR_EMC1_2
Definition: lpcTMR.h:159
#define TEMR_EM1
Definition: lpcTMR.h:150
#define SERVO_RESET_PIN
Definition: hb_1.1.h:60
#define _4017_NB_CHANNELS
void actuators_4017_init(void)
#define SERVO_CLOCK_PINSEL_VAL
Definition: hb_1.1.h:57
#define IO1DIR
Definition: LPC21xx.h:339