Paparazzi UAS  v5.2.2_stable-0-gd6b9f29
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures 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  electrical.vsupply = 0;
52  electrical.current = 0;
53 
56 }
57 
61  }
62 }
63 
64 #define Uint16FromBuf(_buf,_idx) ((uint16_t)((_buf[_idx+1]<<8) | _buf[_idx]))
65 #define Int16FromBuf(_buf,_idx) ((int16_t)((_buf[_idx+1]<<8) | _buf[_idx]))
66 
67 void ezcurrent_read_event( void ) {
69  /* voltage of EzOSD sensor is provided in mV, convert to deciVolt */
71  /* consumed ? in mAh */
73  /* sensor provides current in 1e-1 Ampere, convert to mA */
75 
76  // Transaction has been read
78  } else if ( ezcurrent_i2c_trans.status == I2CTransFailed ) {
80  // ezcurrent_i2c_trans.slave_addr++;
81  }
82 }
83 
#define EZCURRENT_ADDR
Definition: ezcurrent.c:42
transaction successfully finished by I2C driver
Definition: i2c.h:57
#define EZCURRENT_I2C_DEV
Definition: ezcurrent.c:45
I2C transaction structure.
Definition: i2c.h:93
uint16_t vsupply
supply voltage in decivolts
Definition: electrical.h:48
void ezcurrent_read_event(void)
Definition: ezcurrent.c:67
uint8_t slave_addr
Slave address.
Definition: i2c.h:104
#define Int16FromBuf(_buf, _idx)
Definition: ezcurrent.c:65
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
enum I2CTransactionStatus status
Transaction status.
Definition: i2c.h:126
volatile uint8_t buf[I2C_BUF_LEN]
Transaction buffer With I2C_BUF_LEN number of bytes.
Definition: i2c.h:122
int32_t current
current in milliamps
Definition: electrical.h:49
#define Uint16FromBuf(_buf, _idx)
Definition: ezcurrent.c:64
struct Electrical electrical
int32_t consumed
consumption in mAh
Definition: electrical.h:50
void ezcurrent_read_periodic(void)
Definition: ezcurrent.c:58
bool_t 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:248
Architecture independent I2C (Inter-Integrated Circuit Bus) API.