Paparazzi UAS  v4.2.2_stable-4-gcc32f65
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
servos_4017_hw.c
Go to the documentation of this file.
1 #include "actuators.h"
2 
3 #include "paparazzi.h"
4 #include "generated/airframe.h"
5 
7 
8 #define START_TIMEOUT 0xFFFF;
9 
10 void actuators_init ( void ) {
11  /* select clock pin as MAT0.1 output */
12  IO0DIR |= _BV(SERVO_CLOCK_PIN);
14 
15  /* select reset pin as GPIO output */
16  IO1DIR |= _BV(SERVO_RESET_PIN);
17  PINSEL2 &= ~(_BV(3)); /* P1.25-16 are used as GPIO */
18  // SERVO_RESET_PINSEL |= SERVO_RESET_PINSEL_VAL << SERVO_RESET_PINSEL_BIT;
19  /* assert RESET */
20  IO1SET = _BV(SERVO_RESET_PIN);
21 
22  /* enable match 1 interrupt */
23  T0MCR |= TMCR_MR1_I;
24 
25 #ifndef SERVOS_4017_CLOCK_FALLING
26  /* lower clock */
27  T0EMR &= ~TEMR_EM1;
28  /* set high on match 1 */
29  T0EMR |= TEMR_EMC1_2;
30 #else
31  /* assert clock */
32  T0EMR |= TEMR_EM1;
33  /* set low on match 1 */
34  T0EMR |= TEMR_EMC1_1;
35 #endif
36  /* set first pulse in a while */
39  /* Set all servos at their midpoints */
40  /* compulsory for unaffected servos */
41  uint8_t i;
42  for( i=0 ; i < _4017_NB_CHANNELS ; i++ )
44 #ifdef SERVO_MOTOR
45  servos_values[SERVO_MOTOR] = SERVOS_TICS_OF_USEC(SERVO_MOTOR_NEUTRAL);
46 #endif
47 #ifdef SERVO_MOTOR_LEFT
48  servos_values[SERVO_MOTOR_LEFT] = SERVOS_TICS_OF_USEC(SERVO_MOTOR_LEFT_NEUTRAL);
49 #endif
50 #ifdef SERVO_MOTOR_RIGHT
51  servos_values[SERVO_MOTOR_RIGHT] = SERVOS_TICS_OF_USEC(SERVO_MOTOR_RIGHT_NEUTRAL);
52 #endif
53 #ifdef SERVO_HATCH
54  servos_values[SERVO_HATCH] = SERVOS_TICS_OF_USEC(SERVO_HATCH_NEUTRAL);
55 #endif
56 }
57 
58 
60 
unsigned short uint16_t
Definition: types.h:16
#define IO1SET
Definition: LPC21xx.h:306
#define START_TIMEOUT
Definition: servos_4017_hw.c:8
#define SERVO_CLOCK_PINSEL
Definition: hb_1.1.h:56
#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
void actuators_init(void)
#define SERVOS_TICS_OF_USEC(s)
#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]
#define T0EMR
Definition: LPC21xx.h:65
#define T0MR1
Definition: LPC21xx.h:57
#define IO0DIR
Definition: LPC21xx.h:303
uint8_t servos_4017_idx
Definition: servos_4017_hw.c:6
#define _4017_NB_CHANNELS
unsigned char uint8_t
Definition: types.h:14
#define PINSEL2
Definition: LPC21xx.h:317
#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 SERVO_CLOCK_PINSEL_VAL
Definition: hb_1.1.h:57
#define IO1DIR
Definition: LPC21xx.h:307