Paparazzi UAS  v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
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++) {
43  actuators_mkk_v2.trans[i].slave_addr = actuators_addr[i];
45 
50  }
51 
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_mkk_v2_read
static void actuators_mkk_v2_read(void)
Definition: actuators_mkk_v2.c:56
actuators_mkk_v2_telemetry_struct::MaxPWM
uint8_t MaxPWM
Definition: actuators_mkk_v2.h:37
i2c_transaction::buf
volatile uint8_t buf[I2C_BUF_LEN]
Transaction buffer With I2C_BUF_LEN number of bytes.
Definition: i2c.h:122
actuators_mkk_v2_telemetry_struct::Version
uint8_t Version
Definition: actuators_mkk_v2.h:35
i2c_transaction::len_r
uint16_t len_r
Number of bytes to read/receive.
Definition: i2c.h:110
actuators_mkk_v2_telemetry_struct::Temperature
int8_t Temperature
Definition: actuators_mkk_v2.h:38
I2CTransTx
@ I2CTransTx
transmit only transaction
Definition: i2c.h:47
actuators_mkk_v2_struct::setpoint
uint16_t setpoint[ACTUATORS_MKK_V2_NB]
Definition: actuators_mkk_v2.h:43
actuators_mkk_v2_telemetry_struct::Current
uint8_t Current
Definition: actuators_mkk_v2.h:36
actuators_mkk_v2_struct::data
struct actuators_mkk_v2_telemetry_struct data[ACTUATORS_MKK_V2_NB]
Definition: actuators_mkk_v2.h:45
SysTimeTimer
#define SysTimeTimer(_t)
Definition: sys_time.h:219
i2c_transaction::len_w
uint8_t len_w
Number of bytes to write/transmit.
Definition: i2c.h:116
I2CTransSuccess
@ I2CTransSuccess
transaction successfully finished by I2C driver
Definition: i2c.h:57
USEC_OF_SEC
#define USEC_OF_SEC(sec)
Definition: sys_time.h:210
sys_time.h
Architecture independent timing functions.
uint8_t
unsigned char uint8_t
Definition: types.h:14
i2c_transaction::status
enum I2CTransactionStatus status
Transaction status.
Definition: i2c.h:126
actuators_mkk_v2_init
void actuators_mkk_v2_init(void)
Definition: actuators_mkk_v2.c:36
actuators_mkk_v2_struct::trans
struct i2c_transaction trans[ACTUATORS_MKK_V2_NB]
Definition: actuators_mkk_v2.h:44
actuators_mkk_v2
struct actuators_mkk_v2_struct actuators_mkk_v2
Definition: actuators_mkk_v2.c:34
actuators_mkk_v2_struct::read_number
uint8_t read_number
Definition: actuators_mkk_v2.h:42
I2CTransTxRx
@ I2CTransTxRx
transmit and receive transaction
Definition: i2c.h:49
i2c_transaction::slave_addr
uint8_t slave_addr
Slave address.
Definition: i2c.h:104
actuators_mkk_v2_struct
Definition: actuators_mkk_v2.h:41
actuators_mkk_v2_set
void actuators_mkk_v2_set(void)
Definition: actuators_mkk_v2.c:67
actuators_mkk_v2.h
i2c_submit
static bool i2c_submit(struct i2c_periph *p, struct i2c_transaction *t)
Submit a I2C transaction.
Definition: i2c.h:266
i2c_transaction::type
enum I2CTransactionType type
Transaction type.
Definition: i2c.h:98
i2c.h
actuators.h