Paparazzi UAS  v5.14.0_stable-0-g3f680d1
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
actuators_mkk_v2.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_V2_I2C_DEV)
33 
35 
37 {
38 
39  const uint8_t actuators_addr[ACTUATORS_MKK_V2_NB] = ACTUATORS_MKK_V2_ADDR;
40  for (uint8_t i = 0; i < ACTUATORS_MKK_V2_NB; i++) {
41  actuators_mkk_v2.trans[i].type = I2CTransTx;
42  actuators_mkk_v2.trans[i].len_w = 2;
43  actuators_mkk_v2.trans[i].slave_addr = actuators_addr[i];
44  actuators_mkk_v2.trans[i].status = I2CTransSuccess;
45 
46  actuators_mkk_v2.data[i].Version = 0;
47  actuators_mkk_v2.data[i].Current = 0;
48  actuators_mkk_v2.data[i].MaxPWM = 0;
49  actuators_mkk_v2.data[i].Temperature = 0;
50  }
51 
52  actuators_mkk_v2.read_number = 0;
53 
54 }
55 
56 static inline void actuators_mkk_v2_read(void)
57 {
59  if (actuators_mkk_v2.read_number >= ACTUATORS_MKK_V2_NB) {
61  }
62 
65 }
66 
68 {
69 #if defined ACTUATORS_START_DELAY && ! defined SITL
70  if (!actuators_delay_done) {
71  if (SysTimeTimer(actuators_delay_time) < USEC_OF_SEC(ACTUATORS_START_DELAY)) { return; }
72  else { actuators_delay_done = true; }
73  }
74 #endif
75 
76  // Read result
77  for (uint8_t i = 0; i < ACTUATORS_MKK_V2_NB; i++) {
80 
84  }
85  }
86 
87  RunOnceEvery(10, actuators_mkk_v2_read());
88 
89  for (uint8_t i = 0; i < ACTUATORS_MKK_V2_NB; i++) {
90 
91 #ifdef KILL_MOTORS
92  actuators_mkk_v2.trans[i].buf[0] = 0;
93  actuators_mkk_v2.trans[i].buf[1] = 0;
94 #else
97 #endif
98 
99  i2c_submit(&ACTUATORS_MKK_V2_I2C_DEV, &actuators_mkk_v2.trans[i]);
100  }
101 }
Actuators driver for Mikrokopter motor controllers.
volatile uint8_t buf[I2C_BUF_LEN]
Transaction buffer With I2C_BUF_LEN number of bytes.
Definition: i2c.h:122
uint16_t len_r
Number of bytes to read/receive.
Definition: i2c.h:110
transaction successfully finished by I2C driver
Definition: i2c.h:57
transmit and receive transaction
Definition: i2c.h:49
struct actuators_mkk_v2_struct actuators_mkk_v2
struct i2c_transaction trans[ACTUATORS_MKK_V2_NB]
uint8_t len_w
Number of bytes to write/transmit.
Definition: i2c.h:116
uint16_t setpoint[ACTUATORS_MKK_V2_NB]
Hardware independent API for actuators (servos, motor controllers).
Architecture independent timing functions.
bool i2c_submit(struct i2c_periph *p, struct i2c_transaction *t)
i2c_submit() function
Definition: i2c_arch.c:374
struct actuators_mkk_v2_telemetry_struct data[ACTUATORS_MKK_V2_NB]
enum I2CTransactionStatus status
Transaction status.
Definition: i2c.h:126
#define USEC_OF_SEC(sec)
Definition: sys_time.h:210
#define SysTimeTimer(_t)
Definition: sys_time.h:219
static void actuators_mkk_v2_read(void)
uint8_t slave_addr
Slave address.
Definition: i2c.h:104
unsigned char uint8_t
Definition: types.h:14
transmit only transaction
Definition: i2c.h:47
void actuators_mkk_v2_init(void)
enum I2CTransactionType type
Transaction type.
Definition: i2c.h:98
void actuators_mkk_v2_set(void)
Architecture independent I2C (Inter-Integrated Circuit Bus) API.