Paparazzi UAS  v5.10_stable-5-g83a0da5-dirty
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
actuators_mkk.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2009 Antoine Drouin <poinix@gmail.com>
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 
26 #include "subsystems/actuators.h"
28 
29 #include "mcu_periph/i2c.h"
30 #include "mcu_periph/sys_time.h"
31 
32 PRINT_CONFIG_VAR(ACTUATORS_MKK_I2C_DEV)
33 
35 
36 
38 {
39  actuators_mkk.submit_err_cnt = 0;
40 }
41 
42 
44 {
45  const uint8_t actuators_addr[ACTUATORS_MKK_NB] = ACTUATORS_MKK_ADDR;
46  static uint8_t last_idx = ACTUATORS_MKK_NB;
47 
48 #if defined ACTUATORS_START_DELAY && ! defined SITL
49  if (!actuators_delay_done) {
50  if (SysTimeTimer(actuators_delay_time) < USEC_OF_SEC(ACTUATORS_START_DELAY)) {
51  return;
52  } else {
53  actuators_delay_done = true;
54  }
55  }
56 #endif
57 
58  uint8_t cur_idx = last_idx;
59  for (uint8_t i = 0; i < ACTUATORS_MKK_NB; i++) {
60  if (cur_idx >= ACTUATORS_MKK_NB) {
61  cur_idx = 0;
62  }
63 #ifdef KILL_MOTORS
64  actuators_mkk.trans[cur_idx].buf[0] = 0;
65 #endif
66  if (!i2c_transmit(&ACTUATORS_MKK_I2C_DEV, &actuators_mkk.trans[cur_idx],
67  actuators_addr[cur_idx], 1)) {
69  last_idx = cur_idx;
70  return;
71  }
72  cur_idx++;
73  }
74  /* successfully submitted all transactions */
75  last_idx = ACTUATORS_MKK_NB;
76 }
volatile uint8_t buf[I2C_BUF_LEN]
Transaction buffer With I2C_BUF_LEN number of bytes.
Definition: i2c.h:122
struct ActuatorsMkk actuators_mkk
Definition: actuators_mkk.c:34
Hardware independent API for actuators (servos, motor controllers).
Actuators driver for Mikrokopter motor controllers.
Architecture independent timing functions.
void actuators_mkk_init(void)
Definition: actuators_mkk.c:37
struct i2c_transaction trans[ACTUATORS_MKK_NB]
Definition: actuators_mkk.h:36
#define USEC_OF_SEC(sec)
Definition: sys_time.h:210
bool i2c_transmit(struct i2c_periph *p, struct i2c_transaction *t, uint8_t s_addr, uint8_t len)
Submit a write only transaction.
Definition: i2c.c:258
#define SysTimeTimer(_t)
Definition: sys_time.h:219
uint16_t submit_err_cnt
Definition: actuators_mkk.h:37
unsigned char uint8_t
Definition: types.h:14
void actuators_mkk_set(void)
Definition: actuators_mkk.c:43
Architecture independent I2C (Inter-Integrated Circuit Bus) API.