Paparazzi UAS  v5.12_stable-4-g9b43e9b
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
ezcurrent.c
Go to the documentation of this file.
1 
38 #include "sensors/ezcurrent.h"
39 #include "mcu_periph/i2c.h"
40 #include "subsystems/electrical.h"
41 
42 #define EZCURRENT_ADDR 0xEF
43 
44 #ifndef EZCURRENT_I2C_DEV
45 #define EZCURRENT_I2C_DEV i2c1
46 #endif
47 
49 
50 void ezcurrent_init(void)
51 {
52  electrical.vsupply = 0;
53  electrical.current = 0;
54 
57 }
58 
60 {
63  }
64 }
65 
66 #define Uint16FromBuf(_buf,_idx) ((uint16_t)((_buf[_idx+1]<<8) | _buf[_idx]))
67 #define Int16FromBuf(_buf,_idx) ((int16_t)((_buf[_idx+1]<<8) | _buf[_idx]))
68 
70 {
72  /* voltage of EzOSD sensor is provided in mV, convert to deciVolt */
74  /* consumed ? in mAh */
76  /* sensor provides current in 1e-1 Ampere, convert to mA */
78 
79  // Transaction has been read
83  // ezcurrent_i2c_trans.slave_addr++;
84  }
85 }
86 
int32_t current
current in milliamps
Definition: electrical.h:49
#define EZCURRENT_ADDR
Definition: ezcurrent.c:42
volatile uint8_t buf[I2C_BUF_LEN]
Transaction buffer With I2C_BUF_LEN number of bytes.
Definition: i2c.h:122
transaction successfully finished by I2C driver
Definition: i2c.h:57
#define EZCURRENT_I2C_DEV
Definition: ezcurrent.c:45
void ezcurrent_read_event(void)
Definition: ezcurrent.c:69
#define Int16FromBuf(_buf, _idx)
Definition: ezcurrent.c:67
struct i2c_transaction ezcurrent_i2c_trans
Definition: ezcurrent.c:48
transaction set to done by user level
Definition: i2c.h:59
Interface for electrical status: supply voltage, current, battery status, etc.
void ezcurrent_init(void)
Definition: ezcurrent.c:50
transaction failed
Definition: i2c.h:58
I2C transaction structure.
Definition: i2c.h:93
enum I2CTransactionStatus status
Transaction status.
Definition: i2c.h:126
uint8_t slave_addr
Slave address.
Definition: i2c.h:104
#define Uint16FromBuf(_buf, _idx)
Definition: ezcurrent.c:66
uint16_t vsupply
supply voltage in decivolts
Definition: electrical.h:48
bool i2c_receive(struct i2c_periph *p, struct i2c_transaction *t, uint8_t s_addr, uint16_t len)
Submit a read only transaction.
Definition: i2c.c:268
int32_t consumed
consumption in mAh
Definition: electrical.h:50
struct Electrical electrical
Definition: electrical.c:65
void ezcurrent_read_periodic(void)
Definition: ezcurrent.c:59
Architecture independent I2C (Inter-Integrated Circuit Bus) API.