Paparazzi UAS  v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
config_mkk_v2.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2013 Christophe De Wagter
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 
23 #include "config_mkk_v2.h"
24 #include "generated/airframe.h"
25 #include "subsystems/actuators.h"
26 
28 
30 
32 {
35 
37 
38 }
39 
41 
43 {
44  // Read Config
45  if (config_mkk_v2.read_config > 0) {
46  switch (config_mkk_v2.trans.status) {
47  case I2CTransFailed:
49  break;
50  case I2CTransSuccess:
51  case I2CTransDone:
54  break;
55  default:
56  return;
57  }
58  }
59 }
60 
61 #include "mcu_periph/uart.h"
62 #include "pprzlink/messages.h"
64 
65 
67 {
68  static uint8_t send_nr = 0;
69 
70  DOWNLINK_SEND_MKK(DefaultChannel, DefaultDevice, &send_nr, &actuators_mkk_v2.data[send_nr].MaxPWM,
72 
73  send_nr++;
74  if (send_nr >= ACTUATORS_MKK_V2_NB) {
75  send_nr = 0;
76  }
77 }
78 
79 
80 
82 // MKK Config
83 
85 
86 // Following 2 structs are known from: http://mikrokopter.de/mikrosvn/FlightCtrl/tags/V0.88n/twimaster.h
87 
88 /*
89 typedef struct
90 {
91  uint8_t revision; // must be BL_revision
92  uint8_t SetMask; // settings mask
93  uint8_t PwmScaling; // maximum value of control pwm, acts like a thrust limit
94  uint8_t CurrentLimit; // current limit in A
95  uint8_t TempLimit; // in °C
96  uint8_t CurrentScaling; // scaling factor for current measurement
97  uint8_t BitConfig; // see defines above
98  uint8_t crc; // checksum
99 } __attribute__((packed)) config_mkk_v2_eeprom_t;
100 
101 extern config_mkk_v2_eeprom_t config_mkk_v2_eeprom;
102 */
103 
105 {
106  uint8_t crc = 0xaa;
107  for (int i = offset; i < (offset + 7); i++) {
108  crc += config_mkk_v2.trans.buf[i];
109  }
110  return crc;
111 }
112 
113 
115 
116 
117 #define BL_READMODE_CONFIG 16
118 #define config_mkk_v2_EEPROM_REVISION 2
119 
120 
121 #define RETURN_IF_NOT_KILLMODE() \
122  { \
123  if (!actuators_delay_done) \
124  return; \
125  }
126 
128 {
129  // Activate decoder
131 
132  // Do not read config while running
134 
135  // New I2C Write/Read Transaction
139  config_mkk_v2.trans.buf[0] = 0;
142 
143  i2c_submit(&ACTUATORS_MKK_V2_I2C_DEV, &config_mkk_v2.trans);
144 }
145 
147 {
151  } else {
152  config_mkk_v2_eeprom.revision = config_mkk_v2.trans.buf[0]; // must be BL_revision
153  config_mkk_v2_eeprom.SetMask = config_mkk_v2.trans.buf[1]; // settings mask
155  config_mkk_v2.trans.buf[2]; // maximum value of control pwm, acts like a thrust limit
156  config_mkk_v2_eeprom.CurrentLimit = config_mkk_v2.trans.buf[3]; // current limit in A
158  config_mkk_v2_eeprom.CurrentScaling = config_mkk_v2.trans.buf[5]; // scaling factor for current measurement
159  config_mkk_v2_eeprom.BitConfig = config_mkk_v2.trans.buf[6]; // see defines above
160  }
161 }
162 
164 {
165  // Do not upload while running
167 
168  // Do not upload bad data:
170  return;
171  }
172 
173  // New I2C Write Transaction
177  config_mkk_v2.trans.buf[0] = 0;
179 
188 
189  i2c_submit(&ACTUATORS_MKK_V2_I2C_DEV, &config_mkk_v2.trans);
190 
191 }
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
config_mkk_v2_eeprom_t::BitConfig
uint8_t BitConfig
Definition: config_mkk_v2.h:60
i2c_transaction::len_r
uint16_t len_r
Number of bytes to read/receive.
Definition: i2c.h:110
config_mkk_v2
struct config_mkk_v2_struct config_mkk_v2
Definition: config_mkk_v2.c:29
actuators_mkk_v2_telemetry_struct::Temperature
int8_t Temperature
Definition: actuators_mkk_v2.h:38
config_mkk_v2_struct::nb_err
int nb_err
Definition: config_mkk_v2.h:39
I2CTransTx
@ I2CTransTx
transmit only transaction
Definition: i2c.h:47
config_mkk_v2_EEPROM_REVISION
#define config_mkk_v2_EEPROM_REVISION
Definition: config_mkk_v2.c:118
config_mkk_v2_periodic_read_status
void config_mkk_v2_periodic_read_status(void)
Definition: config_mkk_v2.c:42
config_mkk_v2_eeprom_t::CurrentLimit
uint8_t CurrentLimit
Definition: config_mkk_v2.h:57
I2CTransFailed
@ I2CTransFailed
transaction failed
Definition: i2c.h:58
config_mkk_v2_eeprom_t::crc
uint8_t crc
Definition: config_mkk_v2.h:61
actuators_mkk_v2_telemetry_struct::Current
uint8_t Current
Definition: actuators_mkk_v2.h:36
RETURN_IF_NOT_KILLMODE
#define RETURN_IF_NOT_KILLMODE()
Definition: config_mkk_v2.c:121
actuators_mkk_v2_struct::data
struct actuators_mkk_v2_telemetry_struct data[ACTUATORS_MKK_V2_NB]
Definition: actuators_mkk_v2.h:45
config_mkk_v2_periodic_telemetry
void config_mkk_v2_periodic_telemetry(void)
Definition: config_mkk_v2.c:66
config_mkk_v2_eeprom
config_mkk_v2_eeprom_t config_mkk_v2_eeprom
Definition: config_mkk_v2.c:114
config_mkk_v2_init
void config_mkk_v2_init(void)
Definition: config_mkk_v2.c:31
i2c_transaction::len_w
uint8_t len_w
Number of bytes to write/transmit.
Definition: i2c.h:116
config_mkk_v2_crc
uint8_t config_mkk_v2_crc(uint8_t offset)
Definition: config_mkk_v2.c:104
I2CTransSuccess
@ I2CTransSuccess
transaction successfully finished by I2C driver
Definition: i2c.h:57
config_mkk_v2_eeprom_t::TempLimit
uint8_t TempLimit
Definition: config_mkk_v2.h:58
config_mkk_v2_eeprom_t::revision
uint8_t revision
Definition: config_mkk_v2.h:54
uart.h
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
config_mkk_v2.h
config_mkk_v2_eeprom_t
Definition: config_mkk_v2.h:53
config_mkk_v2_read_eeprom
void config_mkk_v2_read_eeprom(void)
Definition: config_mkk_v2.c:127
config_mkk_v2_struct::trans
struct i2c_transaction trans
Definition: config_mkk_v2.h:41
config_mkk_v2_parse_eeprom
void config_mkk_v2_parse_eeprom(void)
Definition: config_mkk_v2.c:146
uint8_t
unsigned char uint8_t
Definition: types.h:14
config_mkk_v2_eeprom_t::PwmScaling
uint8_t PwmScaling
Definition: config_mkk_v2.h:56
i2c_transaction::status
enum I2CTransactionStatus status
Transaction status.
Definition: i2c.h:126
actuators_mkk_v2
struct actuators_mkk_v2_struct actuators_mkk_v2
Definition: actuators_mkk_v2.c:34
config_mkk_v2_struct::read_config
uint8_t read_config
Definition: config_mkk_v2.h:36
I2CTransTxRx
@ I2CTransTxRx
transmit and receive transaction
Definition: i2c.h:49
i2c_transaction::slave_addr
uint8_t slave_addr
Slave address.
Definition: i2c.h:104
config_mkk_v2_eeprom_t::SetMask
uint8_t SetMask
Definition: config_mkk_v2.h:55
offset
static const float offset[]
Definition: dw1000_arduino.c:199
BL_READMODE_CONFIG
#define BL_READMODE_CONFIG
Definition: config_mkk_v2.c:117
actuators_mkk_v2.h
I2CTransDone
@ I2CTransDone
transaction set to done by user level
Definition: i2c.h:59
i2c_submit
static bool i2c_submit(struct i2c_periph *p, struct i2c_transaction *t)
Submit a I2C transaction.
Definition: i2c.h:266
config_mkk_v2_eeprom_t::CurrentScaling
uint8_t CurrentScaling
Definition: config_mkk_v2.h:59
i2c_transaction::type
enum I2CTransactionType type
Transaction type.
Definition: i2c.h:98
config_mkk_v2_struct
Definition: config_mkk_v2.h:35
config_mkk_v2_send_eeprom
void config_mkk_v2_send_eeprom(void)
Definition: config_mkk_v2.c:163
config_mkk_v2_struct::addr
uint8_t addr
Definition: config_mkk_v2.h:37
actuators.h