Merge pull request #387 from flixr/i2c_convenience_functions

[i2c] replace convenience macros with functions
This commit is contained in:
Gautier Hattenberger
2013-03-04 23:54:37 -08:00
38 changed files with 151 additions and 133 deletions
+3 -3
View File
@@ -17,7 +17,7 @@ static inline void bmp085_write_reg(uint8_t addr, uint8_t value)
baro_trans.buf[0] = addr; baro_trans.buf[0] = addr;
baro_trans.buf[1] = value; baro_trans.buf[1] = value;
I2CTransmit(i2c2, baro_trans, BMP085_ADDR, 2); i2c_transmit(&i2c2, &baro_trans, BMP085_ADDR, 2);
// FIXME, no while loops without timeout!! // FIXME, no while loops without timeout!!
while (baro_trans.status == I2CTransPending || baro_trans.status == I2CTransRunning); while (baro_trans.status == I2CTransPending || baro_trans.status == I2CTransRunning);
@@ -26,7 +26,7 @@ static inline void bmp085_write_reg(uint8_t addr, uint8_t value)
static inline void bmp085_read_reg16(uint8_t addr) static inline void bmp085_read_reg16(uint8_t addr)
{ {
baro_trans.buf[0] = addr; baro_trans.buf[0] = addr;
I2CTransceive(i2c2, baro_trans, BMP085_ADDR, 1, 2); i2c_transceive(&i2c2, &baro_trans, BMP085_ADDR, 1, 2);
} }
static inline int16_t bmp085_read_reg16_blocking(uint8_t addr, uint32_t timeout) static inline int16_t bmp085_read_reg16_blocking(uint8_t addr, uint32_t timeout)
@@ -49,7 +49,7 @@ static inline int16_t bmp085_read_reg16_blocking(uint8_t addr, uint32_t timeout)
static inline void bmp085_read_reg24(uint8_t addr) static inline void bmp085_read_reg24(uint8_t addr)
{ {
baro_trans.buf[0] = addr; baro_trans.buf[0] = addr;
I2CTransceive(i2c2, baro_trans, BMP085_ADDR, 1, 3); i2c_transceive(&i2c2, &baro_trans, BMP085_ADDR, 1, 3);
} }
static void bmp085_baro_read_calibration(void) static void bmp085_baro_read_calibration(void)
+7 -7
View File
@@ -62,7 +62,7 @@ void baro_periodic(void) {
/* start D1 conversion */ /* start D1 conversion */
ms5611_status = MS5611_CONV_D1; ms5611_status = MS5611_CONV_D1;
ms5611_trans.buf[0] = MS5611_START_CONV_D1; ms5611_trans.buf[0] = MS5611_START_CONV_D1;
I2CTransmit(MS5611_I2C_DEV, ms5611_trans, MS5611_SLAVE_ADDR, 1); i2c_transmit(&MS5611_I2C_DEV, &ms5611_trans, MS5611_SLAVE_ADDR, 1);
#ifdef DEBUG #ifdef DEBUG
RunOnceEvery(60, { DOWNLINK_SEND_MS5611_COEFF(DefaultChannel, DefaultDevice, RunOnceEvery(60, { DOWNLINK_SEND_MS5611_COEFF(DefaultChannel, DefaultDevice,
&ms5611_c[0], &ms5611_c[1], &ms5611_c[2], &ms5611_c[3], &ms5611_c[0], &ms5611_c[1], &ms5611_c[2], &ms5611_c[3],
@@ -77,7 +77,7 @@ void baro_periodic(void) {
/* read D1 adc */ /* read D1 adc */
ms5611_status = MS5611_ADC_D1; ms5611_status = MS5611_ADC_D1;
ms5611_trans.buf[0] = MS5611_ADC_READ; ms5611_trans.buf[0] = MS5611_ADC_READ;
I2CTransceive(MS5611_I2C_DEV, ms5611_trans, MS5611_SLAVE_ADDR, 1, 3); i2c_transceive(&MS5611_I2C_DEV, &ms5611_trans, MS5611_SLAVE_ADDR, 1, 3);
} }
else if (ms5611_status == MS5611_CONV_D2) { else if (ms5611_status == MS5611_CONV_D2) {
/* assume D2 conversion is done */ /* assume D2 conversion is done */
@@ -87,19 +87,19 @@ void baro_periodic(void) {
/* read D2 adc */ /* read D2 adc */
ms5611_status = MS5611_ADC_D2; ms5611_status = MS5611_ADC_D2;
ms5611_trans.buf[0] = MS5611_ADC_READ; ms5611_trans.buf[0] = MS5611_ADC_READ;
I2CTransceive(MS5611_I2C_DEV, ms5611_trans, MS5611_SLAVE_ADDR, 1, 3); i2c_transceive(&MS5611_I2C_DEV, &ms5611_trans, MS5611_SLAVE_ADDR, 1, 3);
} }
else if (ms5611_status == MS5611_UNINIT) { else if (ms5611_status == MS5611_UNINIT) {
/* reset sensor */ /* reset sensor */
ms5611_status = MS5611_RESET; ms5611_status = MS5611_RESET;
ms5611_trans.buf[0] = MS5611_SOFT_RESET; ms5611_trans.buf[0] = MS5611_SOFT_RESET;
I2CTransmit(MS5611_I2C_DEV, ms5611_trans, MS5611_SLAVE_ADDR, 1); i2c_transmit(&MS5611_I2C_DEV, &ms5611_trans, MS5611_SLAVE_ADDR, 1);
} }
else if (ms5611_status == MS5611_RESET_OK) { else if (ms5611_status == MS5611_RESET_OK) {
/* start getting prom data */ /* start getting prom data */
ms5611_status = MS5611_PROM; ms5611_status = MS5611_PROM;
ms5611_trans.buf[0] = MS5611_PROM_READ | (prom_cnt << 1); ms5611_trans.buf[0] = MS5611_PROM_READ | (prom_cnt << 1);
I2CTransceive(MS5611_I2C_DEV, ms5611_trans, MS5611_SLAVE_ADDR, 1, 2); i2c_transceive(&MS5611_I2C_DEV, &ms5611_trans, MS5611_SLAVE_ADDR, 1, 2);
} }
} }
} }
@@ -122,7 +122,7 @@ void baro_event(void (*b_abs_handler)(void), void (*b_diff_handler)(void)){
if (prom_cnt < PROM_NB) {//8 bytes at PROM if (prom_cnt < PROM_NB) {//8 bytes at PROM
/* get next prom data */ /* get next prom data */
ms5611_trans.buf[0] = MS5611_PROM_READ | (prom_cnt << 1); ms5611_trans.buf[0] = MS5611_PROM_READ | (prom_cnt << 1);
I2CTransceive(MS5611_I2C_DEV, ms5611_trans, MS5611_SLAVE_ADDR, 1, 2); i2c_transceive(&MS5611_I2C_DEV, &ms5611_trans, MS5611_SLAVE_ADDR, 1, 2);
} }
else { else {
/* done reading prom */ /* done reading prom */
@@ -147,7 +147,7 @@ void baro_event(void (*b_abs_handler)(void), void (*b_diff_handler)(void)){
/* start D2 conversion */ /* start D2 conversion */
ms5611_status = MS5611_CONV_D2; ms5611_status = MS5611_CONV_D2;
ms5611_trans.buf[0] = MS5611_START_CONV_D2; ms5611_trans.buf[0] = MS5611_START_CONV_D2;
I2CTransmit(MS5611_I2C_DEV, ms5611_trans, MS5611_SLAVE_ADDR, 1); i2c_transmit(&MS5611_I2C_DEV, &ms5611_trans, MS5611_SLAVE_ADDR, 1);
break; break;
case MS5611_ADC_D2: { case MS5611_ADC_D2: {
+29
View File
@@ -69,3 +69,32 @@ void i2c_init(struct i2c_periph* p) {
} }
void i2c_transmit(struct i2c_periph* p, struct i2c_transaction* t,
uint8_t s_addr, uint8_t len)
{
t->type = I2CTransTx;
t->slave_addr = s_addr;
t->len_w = len;
t->len_r = 0;
i2c_submit(p, t);
}
void i2c_receive(struct i2c_periph* p, struct i2c_transaction* t,
uint8_t s_addr, uint16_t len)
{
t->type = I2CTransRx;
t->slave_addr = s_addr;
t->len_w = 0;
t->len_r = len;
i2c_submit(p, t);
}
void i2c_transceive(struct i2c_periph* p, struct i2c_transaction* t,
uint8_t s_addr, uint8_t len_w, uint16_t len_r)
{
t->type = I2CTransTxRx;
t->slave_addr = s_addr;
t->len_w = len_w;
t->len_r = len_r;
i2c_submit(p, t);
}
+11 -22
View File
@@ -172,30 +172,19 @@ extern bool_t i2c_submit(struct i2c_periph* p, struct i2c_transaction* t);
extern void i2c_setbitrate(struct i2c_periph* p, int bitrate); extern void i2c_setbitrate(struct i2c_periph* p, int bitrate);
extern void i2c_event(void); extern void i2c_event(void);
/*
* Convenience functions.
* Usually these are preferred over i2c_submit,
* as they explicitly set the transaction type again.
*/
extern void i2c_transmit(struct i2c_periph* p, struct i2c_transaction* t,
uint8_t s_addr, uint8_t len);
#define I2CReceive(_p, _t, _s_addr, _len) { \ extern void i2c_receive(struct i2c_periph* p, struct i2c_transaction* t,
_t.type = I2CTransRx; \ uint8_t s_addr, uint16_t len);
_t.slave_addr = _s_addr; \
_t.len_r = _len; \
_t.len_w = 0; \
i2c_submit(&(_p),&(_t)); \
}
#define I2CTransmit(_p, _t, _s_addr, _len) { \ extern void i2c_transceive(struct i2c_periph* p, struct i2c_transaction* t,
_t.type = I2CTransTx; \ uint8_t s_addr, uint8_t len_w, uint16_t len_r);
_t.slave_addr = _s_addr; \
_t.len_r = 0; \
_t.len_w = _len; \
i2c_submit(&(_p),&(_t)); \
}
#define I2CTransceive(_p, _t, _s_addr, _len_w, _len_r) { \
_t.type = I2CTransTxRx; \
_t.slave_addr = _s_addr; \
_t.len_r = _len_r; \
_t.len_w = _len_w; \
i2c_submit(&(_p),&(_t)); \
}
/** @}*/ /** @}*/
/** @}*/ /** @}*/
+3 -3
View File
@@ -91,7 +91,7 @@ static void MPPT_ask( void ) {
} }
mppt_trans.buf[0] = data_index; mppt_trans.buf[0] = data_index;
I2CTransmit(i2c0, mppt_trans, MPPT_SLAVE_ADDR, 1); i2c_transmit(&i2c0, &mppt_trans, MPPT_SLAVE_ADDR, 1);
MPPT_status = MPPT_STATUS_ASKING; MPPT_status = MPPT_STATUS_ASKING;
} }
@@ -105,7 +105,7 @@ void MPPT_periodic( void ) {
mppt_trans.buf[0] = MPPT_MODE_ADDR; mppt_trans.buf[0] = MPPT_MODE_ADDR;
mppt_trans.buf[1] = 0; mppt_trans.buf[1] = 0;
mppt_trans.buf[2] = MPPT_mode; mppt_trans.buf[2] = MPPT_mode;
I2CTransmit(i2c0, mppt_trans, MPPT_SLAVE_ADDR, 3); i2c_transmit(&i2c0, &mppt_trans, MPPT_SLAVE_ADDR, 3);
MPPT_mode = 0; MPPT_mode = 0;
MPPT_status = MPPT_STATUS_WRITING; MPPT_status = MPPT_STATUS_WRITING;
} else { } else {
@@ -119,7 +119,7 @@ void MPPT_periodic( void ) {
case MPPT_STATUS_ASKING: case MPPT_STATUS_ASKING:
/* The slave should send 2 bytes */ /* The slave should send 2 bytes */
I2CReceive(i2c0, mppt_trans, MPPT_SLAVE_ADDR, 2); i2c_receive(&i2c0, &mppt_trans, MPPT_SLAVE_ADDR, 2);
MPPT_status = MPPT_STATUS_READING; MPPT_status = MPPT_STATUS_READING;
break; break;
+2 -2
View File
@@ -83,7 +83,7 @@ void generic_com_periodic( void ) {
com_trans.buf[20] = pprz_mode; com_trans.buf[20] = pprz_mode;
com_trans.buf[21] = nav_block; com_trans.buf[21] = nav_block;
FillBufWith16bit(com_trans.buf, 22, autopilot_flight_time); FillBufWith16bit(com_trans.buf, 22, autopilot_flight_time);
I2CTransmit(GENERIC_COM_I2C_DEV, com_trans, GENERIC_COM_SLAVE_ADDR, NB_DATA); i2c_transmit(&GENERIC_COM_I2C_DEV, &com_trans, GENERIC_COM_SLAVE_ADDR, NB_DATA);
} }
@@ -102,6 +102,6 @@ void start_com( void ) {
void stop_com( void ) { void stop_com( void ) {
active_com = FALSE; active_com = FALSE;
com_trans.buf[0] = active_com; com_trans.buf[0] = active_com;
I2CTransmit(GENERIC_COM_I2C_DEV, com_trans, GENERIC_COM_SLAVE_ADDR, 1); i2c_transmit(&GENERIC_COM_I2C_DEV, &com_trans, GENERIC_COM_SLAVE_ADDR, 1);
} }
@@ -85,7 +85,7 @@ void atmega_i2c_cam_ctrl_send(uint8_t cmd)
// Send Command // Send Command
atmega_i2c_cam_ctrl_trans.buf[0] = cmd; atmega_i2c_cam_ctrl_trans.buf[0] = cmd;
I2CTransceive(ATMEGA_I2C_DEV, atmega_i2c_cam_ctrl_trans, ATMEGA_SLAVE_ADDR, 1, 1); i2c_transceive(&ATMEGA_I2C_DEV, &atmega_i2c_cam_ctrl_trans, ATMEGA_SLAVE_ADDR, 1, 1);
if (cmd == DC_SHOOT) if (cmd == DC_SHOOT)
{ {
+3 -3
View File
@@ -135,7 +135,7 @@ void ArduIMU_periodicGPS( void ) {
ardu_gps_trans.buf[26] = (uint8_t) (GPS_Data[6] >>8); ardu_gps_trans.buf[26] = (uint8_t) (GPS_Data[6] >>8);
ardu_gps_trans.buf[27] = (uint8_t) (GPS_Data[6] >>16); ardu_gps_trans.buf[27] = (uint8_t) (GPS_Data[6] >>16);
ardu_gps_trans.buf[28] = (uint8_t) (GPS_Data[6] >>24); ardu_gps_trans.buf[28] = (uint8_t) (GPS_Data[6] >>24);
I2CTransmit(ARDUIMU_I2C_DEV, ardu_gps_trans, ArduIMU_SLAVE_ADDR, 28); i2c_transmit(&ARDUIMU_I2C_DEV, &ardu_gps_trans, ArduIMU_SLAVE_ADDR, 28);
gps_daten_versendet_msg1 = TRUE; gps_daten_versendet_msg1 = TRUE;
messageNr =1; messageNr =1;
@@ -156,7 +156,7 @@ void ArduIMU_periodicGPS( void ) {
ardu_gps_trans.buf[11] = GPS_Data[9]; //status flags ardu_gps_trans.buf[11] = GPS_Data[9]; //status flags
ardu_gps_trans.buf[12] = GPS_Data[10]; //sol gps fix ardu_gps_trans.buf[12] = GPS_Data[10]; //sol gps fix
ardu_gps_trans.buf[13] = GPS_Data[11]; //sol flags ardu_gps_trans.buf[13] = GPS_Data[11]; //sol flags
I2CTransmit(ARDUIMU_I2C_DEV, ardu_gps_trans, ArduIMU_SLAVE_ADDR, 13); i2c_transmit(&ARDUIMU_I2C_DEV, &ardu_gps_trans, ArduIMU_SLAVE_ADDR, 13);
gps_daten_versendet_msg2 = TRUE; gps_daten_versendet_msg2 = TRUE;
messageNr = 0; messageNr = 0;
@@ -172,7 +172,7 @@ void ArduIMU_periodic( void ) {
if (imu_daten_angefordert == TRUE) { if (imu_daten_angefordert == TRUE) {
IMU_Daten_verarbeiten(); IMU_Daten_verarbeiten();
} }
I2CReceive(ARDUIMU_I2C_DEV, ardu_ins_trans, ArduIMU_SLAVE_ADDR, 12); i2c_receive(&ARDUIMU_I2C_DEV, &ardu_ins_trans, ArduIMU_SLAVE_ADDR, 12);
imu_daten_angefordert = TRUE; imu_daten_angefordert = TRUE;
/* /*
+2 -2
View File
@@ -132,7 +132,7 @@ void ArduIMU_periodicGPS( void ) {
ardu_gps_trans.buf[12] = gps.fix; // status gps fix ardu_gps_trans.buf[12] = gps.fix; // status gps fix
ardu_gps_trans.buf[13] = (uint8_t)arduimu_calibrate_neutrals; // calibration flag ardu_gps_trans.buf[13] = (uint8_t)arduimu_calibrate_neutrals; // calibration flag
ardu_gps_trans.buf[14] = (uint8_t)high_accel_flag; // high acceleration flag (disable accelerometers in the arduimu filter) ardu_gps_trans.buf[14] = (uint8_t)high_accel_flag; // high acceleration flag (disable accelerometers in the arduimu filter)
I2CTransmit(ARDUIMU_I2C_DEV, ardu_gps_trans, ArduIMU_SLAVE_ADDR, 15); i2c_transmit(&ARDUIMU_I2C_DEV, &ardu_gps_trans, ArduIMU_SLAVE_ADDR, 15);
// Reset calibration flag // Reset calibration flag
if (arduimu_calibrate_neutrals) arduimu_calibrate_neutrals = FALSE; if (arduimu_calibrate_neutrals) arduimu_calibrate_neutrals = FALSE;
@@ -142,7 +142,7 @@ void ArduIMU_periodic( void ) {
//Frequence defined in conf/modules/ins_arduimu.xml //Frequence defined in conf/modules/ins_arduimu.xml
if (ardu_ins_trans.status == I2CTransDone) { if (ardu_ins_trans.status == I2CTransDone) {
I2CReceive(ARDUIMU_I2C_DEV, ardu_ins_trans, ArduIMU_SLAVE_ADDR, NB_DATA*2); i2c_receive(&ARDUIMU_I2C_DEV, &ardu_ins_trans, ArduIMU_SLAVE_ADDR, NB_DATA*2);
} }
} }
+1 -1
View File
@@ -51,7 +51,7 @@ void charge_sens_init( void ) {
} }
void charge_sens_periodic( void ) { void charge_sens_periodic( void ) {
I2CReceive(CHARGE_SENS_DEV, charge_trans, CHARGE_SENS_I2C_ADDR, 2); i2c_receive(&CHARGE_SENS_DEV, &charge_trans, CHARGE_SENS_I2C_ADDR, 2);
} }
void charge_sens_event( void ) { void charge_sens_event( void ) {
+1 -1
View File
@@ -57,7 +57,7 @@ void dust_gp2y_init( void ) {
void dust_gp2y_periodic( void ) { void dust_gp2y_periodic( void ) {
if (dust_gp2y_status == DUST_GP2Y_IDLE) { if (dust_gp2y_status == DUST_GP2Y_IDLE) {
I2CReceive(GP2Y_I2C_DEV, gp2y_trans, GP2Y_SLAVE_ADDR, 2); i2c_receive(&GP2Y_I2C_DEV, &gp2y_trans, GP2Y_SLAVE_ADDR, 2);
} }
else if (dust_gp2y_status == DUST_GP2Y_UNINIT && sys_time.nb_sec > 1) { else if (dust_gp2y_status == DUST_GP2Y_UNINIT && sys_time.nb_sec > 1) {
dust_gp2y_status = DUST_GP2Y_IDLE; dust_gp2y_status = DUST_GP2Y_IDLE;
+1 -1
View File
@@ -49,7 +49,7 @@ void geiger_counter_init( void ) {
} }
void geiger_counter_periodic( void ) { void geiger_counter_periodic( void ) {
I2CReceive(GEIGER_CNT_DEV, geiger_trans, GEIGER_CNT_I2C_ADDR, 10); i2c_receive(&GEIGER_CNT_DEV, &geiger_trans, GEIGER_CNT_I2C_ADDR, 10);
} }
void geiger_counter_event( void ) { void geiger_counter_event( void ) {
+1 -1
View File
@@ -60,7 +60,7 @@ void dpicco_init( void ) {
void dpicco_periodic( void ) { void dpicco_periodic( void ) {
/* init read */ /* init read */
I2CReceive(DPICCO_I2C_DEV, dpicco_trans, DPICCO_SLAVE_ADDR, 4); i2c_receive(&DPICCO_I2C_DEV, &dpicco_trans, DPICCO_SLAVE_ADDR, 4);
} }
void dpicco_event( void ) { void dpicco_event( void ) {
+2 -2
View File
@@ -59,7 +59,7 @@ void humid_htm_init(void) {
void humid_htm_start( void ) { void humid_htm_start( void ) {
if (sys_time.nb_sec > 1) { if (sys_time.nb_sec > 1) {
/* measurement request: wake up sensor, sample temperature/humidity */ /* measurement request: wake up sensor, sample temperature/humidity */
I2CTransmit(HTM_I2C_DEV, htm_trans, HTM_SLAVE_ADDR, 0); i2c_transmit(&HTM_I2C_DEV, &htm_trans, HTM_SLAVE_ADDR, 0);
htm_status = HTM_MR; htm_status = HTM_MR;
} }
} }
@@ -69,7 +69,7 @@ void humid_htm_read( void ) {
if (htm_status == HTM_MR_OK) { if (htm_status == HTM_MR_OK) {
/* read humid and temp*/ /* read humid and temp*/
htm_status = HTM_READ_DATA; htm_status = HTM_READ_DATA;
I2CReceive(HTM_I2C_DEV, htm_trans, HTM_SLAVE_ADDR, 4); i2c_receive(&HTM_I2C_DEV, &htm_trans, HTM_SLAVE_ADDR, 4);
} }
} }
+5 -5
View File
@@ -58,7 +58,7 @@ void writePCAP01_SRAM(uint8_t data, uint16_t s_add)
pcap01_trans.buf[0] = 0x90+(unsigned char)(s_add>>8); pcap01_trans.buf[0] = 0x90+(unsigned char)(s_add>>8);
pcap01_trans.buf[1] = (unsigned char)(s_add); pcap01_trans.buf[1] = (unsigned char)(s_add);
pcap01_trans.buf[2] = data; pcap01_trans.buf[2] = data;
I2CTransmit(PCAP01_I2C_DEV, pcap01_trans, PCAP01_ADDR, 3); i2c_transmit(&PCAP01_I2C_DEV, &pcap01_trans, PCAP01_ADDR, 3);
} }
uint8_t readPCAP01_SRAM(uint16_t s_add) uint8_t readPCAP01_SRAM(uint16_t s_add)
@@ -67,7 +67,7 @@ uint8_t readPCAP01_SRAM(uint16_t s_add)
pcap01_trans.buf[0] = 0x10+(unsigned char)(s_add>>8); pcap01_trans.buf[0] = 0x10+(unsigned char)(s_add>>8);
pcap01_trans.buf[1] = (unsigned char)(s_add); pcap01_trans.buf[1] = (unsigned char)(s_add);
I2CTransceive(PCAP01_I2C_DEV, pcap01_trans, PCAP01_ADDR, 2, 1); i2c_transceive(&PCAP01_I2C_DEV, &pcap01_trans, PCAP01_ADDR, 2, 1);
while (pcap01_trans.status == I2CTransPending); while (pcap01_trans.status == I2CTransPending);
return pcap01_trans.buf[0]; return pcap01_trans.buf[0];
@@ -93,7 +93,7 @@ uint8_t readPCAP01_SRAM(uint16_t s_add)
pcap01_trans.buf[1] = 0; pcap01_trans.buf[1] = 0;
pcap01_trans.buf[2] = 0; pcap01_trans.buf[2] = 0;
pcap01_trans.buf[3] = 0; pcap01_trans.buf[3] = 0;
I2CTransmit(PCAP01_I2C_DEV, pcap01_trans, PCAP01_ADDR, 4); i2c_transmit(&PCAP01_I2C_DEV, &pcap01_trans, PCAP01_ADDR, 4);
} }
void pcap01writeRegister(uint8_t reg,uint32_t value) void pcap01writeRegister(uint8_t reg,uint32_t value)
@@ -104,7 +104,7 @@ uint8_t readPCAP01_SRAM(uint16_t s_add)
pcap01_trans.buf[1] = (unsigned char) (value>>16); pcap01_trans.buf[1] = (unsigned char) (value>>16);
pcap01_trans.buf[2] = (unsigned char) (value>>8); pcap01_trans.buf[2] = (unsigned char) (value>>8);
pcap01_trans.buf[3] = (unsigned char) (value); pcap01_trans.buf[3] = (unsigned char) (value);
I2CTransmit(PCAP01_I2C_DEV, pcap01_trans, PCAP01_ADDR, 4); i2c_transmit(&PCAP01_I2C_DEV, &pcap01_trans, PCAP01_ADDR, 4);
} }
#ifdef PCAP01_LOAD_FIRMWARE #ifdef PCAP01_LOAD_FIRMWARE
@@ -190,7 +190,7 @@ void pcap01readRegister(uint8_t reg)
{ {
uint16_t byte1 = 0x40 | reg; uint16_t byte1 = 0x40 | reg;
pcap01_trans.buf[0] = byte1; pcap01_trans.buf[0] = byte1;
I2CTransceive(PCAP01_I2C_DEV, pcap01_trans, PCAP01_ADDR, 1, 3); i2c_transceive(&PCAP01_I2C_DEV, &pcap01_trans, PCAP01_ADDR, 1, 3);
} }
/** /**
+7 -7
View File
@@ -79,7 +79,7 @@ void humid_sht_periodic_i2c( void ) {
/* do soft reset, then wait at least 15ms */ /* do soft reset, then wait at least 15ms */
sht_status = SHT2_RESET; sht_status = SHT2_RESET;
sht_trans.buf[0] = SHT2_SOFT_RESET; sht_trans.buf[0] = SHT2_SOFT_RESET;
I2CTransmit(SHT_I2C_DEV, sht_trans, SHT_SLAVE_ADDR, 1); i2c_transmit(&SHT_I2C_DEV, &sht_trans, SHT_SLAVE_ADDR, 1);
break; break;
case SHT2_SERIAL: case SHT2_SERIAL:
@@ -87,7 +87,7 @@ void humid_sht_periodic_i2c( void ) {
sht_status = SHT2_SERIAL1; sht_status = SHT2_SERIAL1;
sht_trans.buf[0] = 0xFA; sht_trans.buf[0] = 0xFA;
sht_trans.buf[1] = 0x0F; sht_trans.buf[1] = 0x0F;
I2CTransceive(SHT_I2C_DEV, sht_trans, SHT_SLAVE_ADDR, 2, 8); i2c_transceive(&SHT_I2C_DEV, &sht_trans, SHT_SLAVE_ADDR, 2, 8);
break; break;
case SHT2_SERIAL1: case SHT2_SERIAL1:
@@ -98,7 +98,7 @@ void humid_sht_periodic_i2c( void ) {
/* trigger temp measurement, no master hold */ /* trigger temp measurement, no master hold */
sht_trans.buf[0] = SHT2_TRIGGER_TEMP; sht_trans.buf[0] = SHT2_TRIGGER_TEMP;
sht_status = SHT2_TRIG_TEMP; sht_status = SHT2_TRIG_TEMP;
I2CTransmit(SHT_I2C_DEV, sht_trans, SHT_SLAVE_ADDR, 1); i2c_transmit(&SHT_I2C_DEV, &sht_trans, SHT_SLAVE_ADDR, 1);
/* send serial number every 30 seconds */ /* send serial number every 30 seconds */
RunOnceEvery((4*30), DOWNLINK_SEND_SHT_I2C_SERIAL(DefaultChannel, DefaultDevice, &sht_serial1, &sht_serial2)); RunOnceEvery((4*30), DOWNLINK_SEND_SHT_I2C_SERIAL(DefaultChannel, DefaultDevice, &sht_serial1, &sht_serial2));
break; break;
@@ -110,7 +110,7 @@ void humid_sht_p_temp( void ) {
if (sht_status == SHT2_GET_TEMP) { if (sht_status == SHT2_GET_TEMP) {
/* get temp */ /* get temp */
sht_status = SHT2_READ_TEMP; sht_status = SHT2_READ_TEMP;
I2CReceive(SHT_I2C_DEV, sht_trans, SHT_SLAVE_ADDR, 3); i2c_receive(&SHT_I2C_DEV, &sht_trans, SHT_SLAVE_ADDR, 3);
} }
} }
@@ -119,7 +119,7 @@ void humid_sht_p_humid( void ) {
if (sht_status == SHT2_GET_HUMID) { if (sht_status == SHT2_GET_HUMID) {
/* read humid */ /* read humid */
sht_status = SHT2_READ_HUMID; sht_status = SHT2_READ_HUMID;
I2CReceive(SHT_I2C_DEV, sht_trans, SHT_SLAVE_ADDR, 3); i2c_receive(&SHT_I2C_DEV, &sht_trans, SHT_SLAVE_ADDR, 3);
} }
} }
@@ -140,7 +140,7 @@ void humid_sht_event_i2c( void ) {
/* trigger humid measurement, no master hold */ /* trigger humid measurement, no master hold */
sht_trans.buf[0] = SHT2_TRIGGER_HUMID; sht_trans.buf[0] = SHT2_TRIGGER_HUMID;
sht_status = SHT2_TRIG_HUMID; sht_status = SHT2_TRIG_HUMID;
I2CTransmit(SHT_I2C_DEV, sht_trans, SHT_SLAVE_ADDR, 1); i2c_transmit(&SHT_I2C_DEV, &sht_trans, SHT_SLAVE_ADDR, 1);
} }
else { else {
/* checksum error, restart */ /* checksum error, restart */
@@ -184,7 +184,7 @@ void humid_sht_event_i2c( void ) {
sht_status = SHT2_SERIAL2; sht_status = SHT2_SERIAL2;
sht_trans.buf[0] = 0xFC; sht_trans.buf[0] = 0xFC;
sht_trans.buf[1] = 0xC9; sht_trans.buf[1] = 0xC9;
I2CTransceive(SHT_I2C_DEV, sht_trans, SHT_SLAVE_ADDR, 2, 6); i2c_transceive(&SHT_I2C_DEV, &sht_trans, SHT_SLAVE_ADDR, 2, 6);
break; break;
case SHT2_SERIAL2: case SHT2_SERIAL2:
+6 -6
View File
@@ -71,14 +71,14 @@ void ir_mlx_periodic( void ) {
if (ir_mlx_status >= IR_MLX_IDLE) { if (ir_mlx_status >= IR_MLX_IDLE) {
/* start two byte case temperature */ /* start two byte case temperature */
mlx_trans.buf[0] = MLX90614_TA; mlx_trans.buf[0] = MLX90614_TA;
I2CTransceive(MLX_I2C_DEV, mlx_trans, MLX90614_ADDR, 1, 2); i2c_transceive(&MLX_I2C_DEV, &mlx_trans, MLX90614_ADDR, 1, 2);
ir_mlx_status = IR_MLX_RD_CASE_TEMP; ir_mlx_status = IR_MLX_RD_CASE_TEMP;
/* send serial number every 30 seconds */ /* send serial number every 30 seconds */
RunOnceEvery((8*30), DOWNLINK_SEND_MLX_SERIAL(DefaultChannel, DefaultDevice, &ir_mlx_id_01, &ir_mlx_id_23)); RunOnceEvery((8*30), DOWNLINK_SEND_MLX_SERIAL(DefaultChannel, DefaultDevice, &ir_mlx_id_01, &ir_mlx_id_23));
} else if (ir_mlx_status == IR_MLX_UNINIT) { } else if (ir_mlx_status == IR_MLX_UNINIT) {
/* start two byte ID 0 */ /* start two byte ID 0 */
mlx_trans.buf[0] = MLX90614_ID_0; mlx_trans.buf[0] = MLX90614_ID_0;
I2CTransceive(MLX_I2C_DEV, mlx_trans, MLX90614_ADDR, 1, 2); i2c_transceive(&MLX_I2C_DEV, &mlx_trans, MLX90614_ADDR, 1, 2);
ir_mlx_status = IR_MLX_RD_ID_0; ir_mlx_status = IR_MLX_RD_ID_0;
} }
} }
@@ -94,7 +94,7 @@ void ir_mlx_event( void ) {
ir_mlx_id_01 |= mlx_trans.buf[1] << 8; ir_mlx_id_01 |= mlx_trans.buf[1] << 8;
/* start two byte ID 1 */ /* start two byte ID 1 */
mlx_trans.buf[0] = MLX90614_ID_1; mlx_trans.buf[0] = MLX90614_ID_1;
I2CTransceive(MLX_I2C_DEV, mlx_trans, MLX90614_ADDR, 1, 2); i2c_transceive(&MLX_I2C_DEV, &mlx_trans, MLX90614_ADDR, 1, 2);
ir_mlx_status = IR_MLX_RD_ID_1; ir_mlx_status = IR_MLX_RD_ID_1;
break; break;
@@ -104,7 +104,7 @@ void ir_mlx_event( void ) {
ir_mlx_id_01 |= mlx_trans.buf[1] << 24; ir_mlx_id_01 |= mlx_trans.buf[1] << 24;
/* start two byte ID 2 */ /* start two byte ID 2 */
mlx_trans.buf[0] = MLX90614_ID_2; mlx_trans.buf[0] = MLX90614_ID_2;
I2CTransceive(MLX_I2C_DEV, mlx_trans, MLX90614_ADDR, 1, 2); i2c_transceive(&MLX_I2C_DEV, &mlx_trans, MLX90614_ADDR, 1, 2);
ir_mlx_status = IR_MLX_RD_ID_2; ir_mlx_status = IR_MLX_RD_ID_2;
break; break;
@@ -114,7 +114,7 @@ void ir_mlx_event( void ) {
ir_mlx_id_23 |= mlx_trans.buf[1] << 8; ir_mlx_id_23 |= mlx_trans.buf[1] << 8;
/* start two byte ID 3 */ /* start two byte ID 3 */
mlx_trans.buf[0] = MLX90614_ID_3; mlx_trans.buf[0] = MLX90614_ID_3;
I2CTransceive(MLX_I2C_DEV, mlx_trans, MLX90614_ADDR, 1, 2); i2c_transceive(&MLX_I2C_DEV, &mlx_trans, MLX90614_ADDR, 1, 2);
ir_mlx_status = IR_MLX_RD_ID_3; ir_mlx_status = IR_MLX_RD_ID_3;
break; break;
@@ -135,7 +135,7 @@ void ir_mlx_event( void ) {
/* start two byte obj temperature */ /* start two byte obj temperature */
mlx_trans.buf[0] = MLX90614_TOBJ; mlx_trans.buf[0] = MLX90614_TOBJ;
I2CTransceive(MLX_I2C_DEV, mlx_trans, MLX90614_ADDR, 1, 2); i2c_transceive(&MLX_I2C_DEV, &mlx_trans, MLX90614_ADDR, 1, 2);
ir_mlx_status = IR_MLX_RD_OBJ_TEMP; ir_mlx_status = IR_MLX_RD_OBJ_TEMP;
break; break;
+1 -1
View File
@@ -58,7 +58,7 @@ void lm75_init(void) {
void lm75_periodic( void ) { void lm75_periodic( void ) {
lm75_trans.buf[0] = LM75_TEMP_REG; lm75_trans.buf[0] = LM75_TEMP_REG;
I2CTransceive(LM75_I2C_DEV, lm75_trans, LM75_SLAVE_ADDR, 1, 2); i2c_transceive(&LM75_I2C_DEV, &lm75_trans, LM75_SLAVE_ADDR, 1, 2);
} }
void lm75_event( void ) { void lm75_event( void ) {
+1 -1
View File
@@ -55,7 +55,7 @@ void temod_init(void) {
} }
void temod_periodic( void ) { void temod_periodic( void ) {
I2CReceive(TEMOD_I2C_DEV, tmd_trans, TEMOD_SLAVE_ADDR, 2); i2c_receive(&TEMOD_I2C_DEV, &tmd_trans, TEMOD_SLAVE_ADDR, 2);
} }
void temod_event( void ) { void temod_event( void ) {
+2 -2
View File
@@ -69,12 +69,12 @@ void tmp102_init(void) {
tmp_trans.buf[0] = TMP102_CONF_REG; tmp_trans.buf[0] = TMP102_CONF_REG;
tmp_trans.buf[1] = TMP102_CONF1; tmp_trans.buf[1] = TMP102_CONF1;
tmp_trans.buf[2] = TMP102_CONF2; tmp_trans.buf[2] = TMP102_CONF2;
I2CTransmit(TMP_I2C_DEV, tmp_trans, TMP102_SLAVE_ADDR, 3); i2c_transmit(&TMP_I2C_DEV, &tmp_trans, TMP102_SLAVE_ADDR, 3);
} }
void tmp102_periodic( void ) { void tmp102_periodic( void ) {
tmp_trans.buf[0] = TMP102_TEMP_REG; tmp_trans.buf[0] = TMP102_TEMP_REG;
I2CTransceive(TMP_I2C_DEV, tmp_trans, TMP102_SLAVE_ADDR, 1, 2); i2c_transceive(&TMP_I2C_DEV, &tmp_trans, TMP102_SLAVE_ADDR, 1, 2);
tmp_meas_started = TRUE; tmp_meas_started = TRUE;
} }
+5 -5
View File
@@ -64,7 +64,7 @@ void wind_gfi_periodic( void ) {
pcf_trans.buf[0] = 0xFF; pcf_trans.buf[0] = 0xFF;
pcf_trans.buf[1] = 0xBF; pcf_trans.buf[1] = 0xBF;
pcf_status = PCF_SET_OE_LSB; pcf_status = PCF_SET_OE_LSB;
I2CTransmit(PCF_I2C_DEV, pcf_trans, PCF_SLAVE_ADDR, 2); i2c_transmit(&PCF_I2C_DEV, &pcf_trans, PCF_SLAVE_ADDR, 2);
} }
void wind_gfi_event( void ) { void wind_gfi_event( void ) {
@@ -72,7 +72,7 @@ void wind_gfi_event( void ) {
if (pcf_status == PCF_SET_OE_LSB) { if (pcf_status == PCF_SET_OE_LSB) {
pcf_status = PCF_READ_LSB; pcf_status = PCF_READ_LSB;
I2CReceive(PCF_I2C_DEV, pcf_trans, PCF_SLAVE_ADDR, 2); i2c_receive(&PCF_I2C_DEV, &pcf_trans, PCF_SLAVE_ADDR, 2);
} }
else if (pcf_status == PCF_READ_LSB) { else if (pcf_status == PCF_READ_LSB) {
/* read lower byte direction info */ /* read lower byte direction info */
@@ -82,11 +82,11 @@ void wind_gfi_event( void ) {
pcf_trans.buf[0] = 0xFF; pcf_trans.buf[0] = 0xFF;
pcf_trans.buf[1] = 0x3F; pcf_trans.buf[1] = 0x3F;
pcf_status = PCF_SET_OE_MSB; pcf_status = PCF_SET_OE_MSB;
I2CTransmit(PCF_I2C_DEV, pcf_trans, PCF_SLAVE_ADDR, 2); i2c_transmit(&PCF_I2C_DEV, &pcf_trans, PCF_SLAVE_ADDR, 2);
} }
else if (pcf_status == PCF_SET_OE_MSB) { else if (pcf_status == PCF_SET_OE_MSB) {
pcf_status = PCF_READ_MSB; pcf_status = PCF_READ_MSB;
I2CReceive(PCF_I2C_DEV, pcf_trans, PCF_SLAVE_ADDR, 2); i2c_receive(&PCF_I2C_DEV, &pcf_trans, PCF_SLAVE_ADDR, 2);
} }
else if (pcf_status == PCF_READ_MSB) { else if (pcf_status == PCF_READ_MSB) {
float fpcf_direction; float fpcf_direction;
@@ -98,7 +98,7 @@ void wind_gfi_event( void ) {
pcf_trans.buf[0] = 0xFF; pcf_trans.buf[0] = 0xFF;
pcf_trans.buf[1] = 0xFF; pcf_trans.buf[1] = 0xFF;
pcf_status = PCF_IDLE; pcf_status = PCF_IDLE;
I2CTransmit(PCF_I2C_DEV, pcf_trans, PCF_SLAVE_ADDR, 2); i2c_transmit(&PCF_I2C_DEV, &pcf_trans, PCF_SLAVE_ADDR, 2);
/* 2048 digits per 360 degrees */ /* 2048 digits per 360 degrees */
fpcf_direction = fmod((pcf_direction * (360./2048.)) + ZERO_OFFSET_DEGREES, 360.); fpcf_direction = fmod((pcf_direction * (360./2048.)) + ZERO_OFFSET_DEGREES, 360.);
+2 -2
View File
@@ -99,9 +99,9 @@ void airspeed_amsys_read_periodic( void ) {
#ifndef SITL #ifndef SITL
if (airspeed_amsys_i2c_trans.status == I2CTransDone) if (airspeed_amsys_i2c_trans.status == I2CTransDone)
#ifndef MEASURE_AMSYS_TEMPERATURE #ifndef MEASURE_AMSYS_TEMPERATURE
I2CReceive(AIRSPEED_AMSYS_I2C_DEV, airspeed_amsys_i2c_trans, AIRSPEED_AMSYS_ADDR, 2); i2c_receive(&AIRSPEED_AMSYS_I2C_DEV, &airspeed_amsys_i2c_trans, AIRSPEED_AMSYS_ADDR, 2);
#else #else
I2CReceive(AIRSPEED_AMSYS_I2C_DEV, airspeed_amsys_i2c_trans, AIRSPEED_AMSYS_ADDR, 4); i2c_receive(&AIRSPEED_AMSYS_I2C_DEV, &airspeed_amsys_i2c_trans, AIRSPEED_AMSYS_ADDR, 4);
#endif #endif
#else // SITL #else // SITL
+1 -1
View File
@@ -110,7 +110,7 @@ void airspeed_ets_init( void ) {
void airspeed_ets_read_periodic( void ) { void airspeed_ets_read_periodic( void ) {
#ifndef SITL #ifndef SITL
if (airspeed_ets_i2c_trans.status == I2CTransDone) if (airspeed_ets_i2c_trans.status == I2CTransDone)
I2CReceive(AIRSPEED_ETS_I2C_DEV, airspeed_ets_i2c_trans, AIRSPEED_ETS_ADDR, 2); i2c_receive(&AIRSPEED_ETS_I2C_DEV, &airspeed_ets_i2c_trans, AIRSPEED_ETS_ADDR, 2);
#else // SITL #else // SITL
extern float sim_air_speed; extern float sim_air_speed;
stateSetAirspeed_f(&sim_air_speed); stateSetAirspeed_f(&sim_air_speed);
+6 -6
View File
@@ -57,12 +57,12 @@ void srf08_init(void)
srf_trans.buf[0] = 0x00; srf_trans.buf[0] = 0x00;
srf_trans.buf[1] = 0x51; srf_trans.buf[1] = 0x51;
I2CTransmit(SRF08_I2C_DEV, srf_trans, SRF08_UNIT_0, 2); i2c_transmit(&SRF08_I2C_DEV, &srf_trans, SRF08_UNIT_0, 2);
/** Setting the gain to the minimun value (to avoid echos ?) */ /** Setting the gain to the minimun value (to avoid echos ?) */
srf_trans.buf[0] = SRF08_SET_GAIN; srf_trans.buf[0] = SRF08_SET_GAIN;
srf_trans.buf[1] = SRF08_MIN_GAIN; srf_trans.buf[1] = SRF08_MIN_GAIN;
I2CTransmit(SRF08_I2C_DEV, srf_trans, SRF08_UNIT_0, 2); i2c_transmit(&SRF08_I2C_DEV, &srf_trans, SRF08_UNIT_0, 2);
return; return;
} }
@@ -72,7 +72,7 @@ void srf08_initiate_ranging(void) {
LED_ON(2); LED_ON(2);
srf_trans.buf[0] = SRF08_COMMAND; srf_trans.buf[0] = SRF08_COMMAND;
srf_trans.buf[1] = SRF08_CENTIMETERS; srf_trans.buf[1] = SRF08_CENTIMETERS;
I2CTransmit(SRF08_I2C_DEV, srf_trans, SRF08_UNIT_0, 2); i2c_transmit(&SRF08_I2C_DEV, &srf_trans, SRF08_UNIT_0, 2);
} }
/** Ask the value to the device */ /** Ask the value to the device */
@@ -80,13 +80,13 @@ void srf08_receive(void) {
LED_OFF(2); LED_OFF(2);
srf_trans.buf[0] = SRF08_ECHO_1; srf_trans.buf[0] = SRF08_ECHO_1;
srf08_received = TRUE; srf08_received = TRUE;
I2CTransmit(SRF08_I2C_DEV, srf_trans, SRF08_UNIT_0, 1); i2c_transmit(&SRF08_I2C_DEV, &srf_trans, SRF08_UNIT_0, 1);
} }
/** Read values on the bus */ /** Read values on the bus */
void srf08_read(void) { void srf08_read(void) {
srf08_got = TRUE; srf08_got = TRUE;
I2CReceive(SRF08_I2C_DEV, srf_trans, SRF08_UNIT_0, 2); i2c_receive(&SRF08_I2C_DEV, &srf_trans, SRF08_UNIT_0, 2);
} }
/** Copy the I2C buffer */ /** Copy the I2C buffer */
@@ -121,7 +121,7 @@ uint32_t srf08_read_register(uint8_t srf08_register)
else else
cnt = 1; cnt = 1;
I2CTransceive(SRF08_I2C_DEV, srf_trans, SRF08_UNIT_0, 1, cnt); i2c_transceive(&SRF08_I2C_DEV, &srf_trans, SRF08_UNIT_0, 1, cnt);
/* get high byte msb first */ /* get high byte msb first */
if(srf08_register>=2) { if(srf08_register>=2) {
+2 -2
View File
@@ -119,9 +119,9 @@ void baro_amsys_read_periodic( void ) {
#ifndef SITL #ifndef SITL
if (baro_amsys_i2c_trans.status == I2CTransDone){ if (baro_amsys_i2c_trans.status == I2CTransDone){
#ifndef MEASURE_AMSYS_TEMPERATURE #ifndef MEASURE_AMSYS_TEMPERATURE
I2CReceive(BARO_AMSYS_I2C_DEV, baro_amsys_i2c_trans, BARO_AMSYS_ADDR, 2); i2c_receive(&BARO_AMSYS_I2C_DEV, &baro_amsys_i2c_trans, BARO_AMSYS_ADDR, 2);
#else #else
I2CReceive(BARO_AMSYS_I2C_DEV, baro_amsys_i2c_trans, BARO_AMSYS_ADDR, 4); i2c_receive(&BARO_AMSYS_I2C_DEV, &baro_amsys_i2c_trans, BARO_AMSYS_ADDR, 4);
#endif #endif
} }
#else // SITL #else // SITL
+6 -6
View File
@@ -98,7 +98,7 @@ void baro_bmp_init( void ) {
baro_bmp_cnt = BARO_BMP_OFFSET_NBSAMPLES_INIT + BARO_BMP_OFFSET_NBSAMPLES_AVRG; baro_bmp_cnt = BARO_BMP_OFFSET_NBSAMPLES_INIT + BARO_BMP_OFFSET_NBSAMPLES_AVRG;
/* read calibration values */ /* read calibration values */
bmp_trans.buf[0] = BMP085_EEPROM_AC1; bmp_trans.buf[0] = BMP085_EEPROM_AC1;
I2CTransceive(BMP_I2C_DEV, bmp_trans, BMP085_SLAVE_ADDR, 1, 22); i2c_transceive(&BMP_I2C_DEV, &bmp_trans, BMP085_SLAVE_ADDR, 1, 22);
} }
void baro_bmp_periodic( void ) { void baro_bmp_periodic( void ) {
@@ -107,19 +107,19 @@ void baro_bmp_periodic( void ) {
/* start temp measurement (once) */ /* start temp measurement (once) */
bmp_trans.buf[0] = BMP085_CTRL_REG; bmp_trans.buf[0] = BMP085_CTRL_REG;
bmp_trans.buf[1] = BMP085_START_TEMP; bmp_trans.buf[1] = BMP085_START_TEMP;
I2CTransmit(BMP_I2C_DEV, bmp_trans, BMP085_SLAVE_ADDR, 2); i2c_transmit(&BMP_I2C_DEV, &bmp_trans, BMP085_SLAVE_ADDR, 2);
baro_bmp_status = BARO_BMP_START_TEMP; baro_bmp_status = BARO_BMP_START_TEMP;
} }
else if (baro_bmp_status == BARO_BMP_START_TEMP) { else if (baro_bmp_status == BARO_BMP_START_TEMP) {
/* read temp measurement */ /* read temp measurement */
bmp_trans.buf[0] = BMP085_DAT_MSB; bmp_trans.buf[0] = BMP085_DAT_MSB;
I2CTransceive(BMP_I2C_DEV, bmp_trans, BMP085_SLAVE_ADDR, 1, 2); i2c_transceive(&BMP_I2C_DEV, &bmp_trans, BMP085_SLAVE_ADDR, 1, 2);
baro_bmp_status = BARO_BMP_READ_TEMP; baro_bmp_status = BARO_BMP_READ_TEMP;
} }
else if (baro_bmp_status == BARO_BMP_START_PRESS) { else if (baro_bmp_status == BARO_BMP_START_PRESS) {
/* read press measurement */ /* read press measurement */
bmp_trans.buf[0] = BMP085_DAT_MSB; bmp_trans.buf[0] = BMP085_DAT_MSB;
I2CTransceive(BMP_I2C_DEV, bmp_trans, BMP085_SLAVE_ADDR, 1, 3); i2c_transceive(&BMP_I2C_DEV, &bmp_trans, BMP085_SLAVE_ADDR, 1, 3);
baro_bmp_status = BARO_BMP_READ_PRESS; baro_bmp_status = BARO_BMP_READ_PRESS;
} }
#else // SITL #else // SITL
@@ -155,7 +155,7 @@ void baro_bmp_event( void ) {
/* start high res pressure measurement */ /* start high res pressure measurement */
bmp_trans.buf[0] = BMP085_CTRL_REG; bmp_trans.buf[0] = BMP085_CTRL_REG;
bmp_trans.buf[1] = BMP085_START_P3; bmp_trans.buf[1] = BMP085_START_P3;
I2CTransmit(BMP_I2C_DEV, bmp_trans, BMP085_SLAVE_ADDR, 2); i2c_transmit(&BMP_I2C_DEV, &bmp_trans, BMP085_SLAVE_ADDR, 2);
baro_bmp_status = BARO_BMP_START_PRESS; baro_bmp_status = BARO_BMP_START_PRESS;
} }
else if (baro_bmp_status == BARO_BMP_READ_PRESS) { else if (baro_bmp_status == BARO_BMP_READ_PRESS) {
@@ -171,7 +171,7 @@ void baro_bmp_event( void ) {
/* start temp measurement */ /* start temp measurement */
bmp_trans.buf[0] = BMP085_CTRL_REG; bmp_trans.buf[0] = BMP085_CTRL_REG;
bmp_trans.buf[1] = BMP085_START_TEMP; bmp_trans.buf[1] = BMP085_START_TEMP;
I2CTransmit(BMP_I2C_DEV, bmp_trans, BMP085_SLAVE_ADDR, 2); i2c_transmit(&BMP_I2C_DEV, &bmp_trans, BMP085_SLAVE_ADDR, 2);
baro_bmp_status = BARO_BMP_START_TEMP; baro_bmp_status = BARO_BMP_START_TEMP;
/* compensate temperature */ /* compensate temperature */
+1 -1
View File
@@ -111,7 +111,7 @@ void baro_ets_read_periodic( void ) {
// Initiate next read // Initiate next read
#ifndef SITL #ifndef SITL
if (baro_ets_i2c_trans.status == I2CTransDone) if (baro_ets_i2c_trans.status == I2CTransDone)
I2CReceive(BARO_ETS_I2C_DEV, baro_ets_i2c_trans, BARO_ETS_ADDR, 2); i2c_receive(&BARO_ETS_I2C_DEV, &baro_ets_i2c_trans, BARO_ETS_ADDR, 2);
#else // SITL #else // SITL
/* fake an offset so sim works for under hmsl as well */ /* fake an offset so sim works for under hmsl as well */
if (!baro_ets_offset_init) { if (!baro_ets_offset_init) {
+1 -1
View File
@@ -60,7 +60,7 @@ void baro_hca_init( void ) {
void baro_hca_read_periodic( void ) { void baro_hca_read_periodic( void ) {
if (baro_hca_i2c_trans.status == I2CTransDone){ if (baro_hca_i2c_trans.status == I2CTransDone){
I2CReceive(BARO_HCA_I2C_DEV, baro_hca_i2c_trans, BARO_HCA_ADDR, 2); i2c_receive(&BARO_HCA_I2C_DEV, &baro_hca_i2c_trans, BARO_HCA_ADDR, 2);
} }
} }
@@ -93,7 +93,7 @@ void baro_ms5611_periodic( void ) {
/* start D1 conversion */ /* start D1 conversion */
ms5611_status = MS5611_CONV_D1; ms5611_status = MS5611_CONV_D1;
ms5611_trans.buf[0] = MS5611_START_CONV_D1; ms5611_trans.buf[0] = MS5611_START_CONV_D1;
I2CTransmit(MS5611_I2C_DEV, ms5611_trans, MS5611_SLAVE_ADDR, 1); i2c_transmit(&MS5611_I2C_DEV, &ms5611_trans, MS5611_SLAVE_ADDR, 1);
RunOnceEvery((4*30), DOWNLINK_SEND_MS5611_COEFF(DefaultChannel, DefaultDevice, RunOnceEvery((4*30), DOWNLINK_SEND_MS5611_COEFF(DefaultChannel, DefaultDevice,
&ms5611_c[0], &ms5611_c[1], &ms5611_c[2], &ms5611_c[3], &ms5611_c[0], &ms5611_c[1], &ms5611_c[2], &ms5611_c[3],
&ms5611_c[4], &ms5611_c[5], &ms5611_c[6], &ms5611_c[7])); &ms5611_c[4], &ms5611_c[5], &ms5611_c[6], &ms5611_c[7]));
@@ -102,13 +102,13 @@ void baro_ms5611_periodic( void ) {
/* reset sensor */ /* reset sensor */
ms5611_status = MS5611_RESET; ms5611_status = MS5611_RESET;
ms5611_trans.buf[0] = MS5611_SOFT_RESET; ms5611_trans.buf[0] = MS5611_SOFT_RESET;
I2CTransmit(MS5611_I2C_DEV, ms5611_trans, MS5611_SLAVE_ADDR, 1); i2c_transmit(&MS5611_I2C_DEV, &ms5611_trans, MS5611_SLAVE_ADDR, 1);
} }
else if (ms5611_status == MS5611_RESET_OK) { else if (ms5611_status == MS5611_RESET_OK) {
/* start getting prom data */ /* start getting prom data */
ms5611_status = MS5611_PROM; ms5611_status = MS5611_PROM;
ms5611_trans.buf[0] = MS5611_PROM_READ | (prom_cnt << 1); ms5611_trans.buf[0] = MS5611_PROM_READ | (prom_cnt << 1);
I2CTransceive(MS5611_I2C_DEV, ms5611_trans, MS5611_SLAVE_ADDR, 1, 2); i2c_transceive(&MS5611_I2C_DEV, &ms5611_trans, MS5611_SLAVE_ADDR, 1, 2);
} }
} }
} }
@@ -119,7 +119,7 @@ void baro_ms5611_d1( void ) {
/* read D1 adc */ /* read D1 adc */
ms5611_status = MS5611_ADC_D1; ms5611_status = MS5611_ADC_D1;
ms5611_trans.buf[0] = MS5611_ADC_READ; ms5611_trans.buf[0] = MS5611_ADC_READ;
I2CTransceive(MS5611_I2C_DEV, ms5611_trans, MS5611_SLAVE_ADDR, 1, 3); i2c_transceive(&MS5611_I2C_DEV, &ms5611_trans, MS5611_SLAVE_ADDR, 1, 3);
} }
} }
} }
@@ -130,7 +130,7 @@ void baro_ms5611_d2( void ) {
/* read D2 adc */ /* read D2 adc */
ms5611_status = MS5611_ADC_D2; ms5611_status = MS5611_ADC_D2;
ms5611_trans.buf[0] = MS5611_ADC_READ; ms5611_trans.buf[0] = MS5611_ADC_READ;
I2CTransceive(MS5611_I2C_DEV, ms5611_trans, MS5611_SLAVE_ADDR, 1, 3); i2c_transceive(&MS5611_I2C_DEV, &ms5611_trans, MS5611_SLAVE_ADDR, 1, 3);
} }
} }
} }
@@ -150,7 +150,7 @@ void baro_ms5611_event( void ) {
if (prom_cnt < PROM_NB) { if (prom_cnt < PROM_NB) {
/* get next prom data */ /* get next prom data */
ms5611_trans.buf[0] = MS5611_PROM_READ | (prom_cnt << 1); ms5611_trans.buf[0] = MS5611_PROM_READ | (prom_cnt << 1);
I2CTransceive(MS5611_I2C_DEV, ms5611_trans, MS5611_SLAVE_ADDR, 1, 2); i2c_transceive(&MS5611_I2C_DEV, &ms5611_trans, MS5611_SLAVE_ADDR, 1, 2);
} }
else { else {
/* done reading prom */ /* done reading prom */
@@ -182,7 +182,7 @@ void baro_ms5611_event( void ) {
/* start D2 conversion */ /* start D2 conversion */
ms5611_status = MS5611_CONV_D2; ms5611_status = MS5611_CONV_D2;
ms5611_trans.buf[0] = MS5611_START_CONV_D2; ms5611_trans.buf[0] = MS5611_START_CONV_D2;
I2CTransmit(MS5611_I2C_DEV, ms5611_trans, MS5611_SLAVE_ADDR, 1); i2c_transmit(&MS5611_I2C_DEV, &ms5611_trans, MS5611_SLAVE_ADDR, 1);
break; break;
case MS5611_CONV_D2: case MS5611_CONV_D2:
+4 -4
View File
@@ -39,7 +39,7 @@ static void baro_scp_start_high_res_measurement(void) {
/* switch to high resolution */ /* switch to high resolution */
scp_trans.buf[0] = SCP1000_OPERATION; scp_trans.buf[0] = SCP1000_OPERATION;
scp_trans.buf[1] = SCP1000_HIGH_RES; scp_trans.buf[1] = SCP1000_HIGH_RES;
I2CTransmit(SCP_I2C_DEV, scp_trans, SCP1000_SLAVE_ADDR, 2); i2c_transmit(&SCP_I2C_DEV, &scp_trans, SCP1000_SLAVE_ADDR, 2);
} }
void baro_scp_init( void ) { void baro_scp_init( void ) {
@@ -57,7 +57,7 @@ void baro_scp_periodic( void ) {
/* init: start two byte temperature */ /* init: start two byte temperature */
scp_trans.buf[0] = SCP1000_TEMPOUT; scp_trans.buf[0] = SCP1000_TEMPOUT;
baro_scp_status = BARO_SCP_RD_TEMP; baro_scp_status = BARO_SCP_RD_TEMP;
I2CTransceive(SCP_I2C_DEV, scp_trans, SCP1000_SLAVE_ADDR, 1, 2); i2c_transceive(&SCP_I2C_DEV, &scp_trans, SCP1000_SLAVE_ADDR, 1, 2);
} }
} }
@@ -78,7 +78,7 @@ void baro_scp_event( void ) {
/* start one byte msb pressure */ /* start one byte msb pressure */
scp_trans.buf[0] = SCP1000_DATARD8; scp_trans.buf[0] = SCP1000_DATARD8;
baro_scp_status = BARO_SCP_RD_PRESS_0; baro_scp_status = BARO_SCP_RD_PRESS_0;
I2CTransceive(SCP_I2C_DEV, scp_trans, SCP1000_SLAVE_ADDR, 1, 1); i2c_transceive(&SCP_I2C_DEV, &scp_trans, SCP1000_SLAVE_ADDR, 1, 1);
} }
else if (baro_scp_status == BARO_SCP_RD_PRESS_0) { else if (baro_scp_status == BARO_SCP_RD_PRESS_0) {
@@ -89,7 +89,7 @@ void baro_scp_event( void ) {
/* start two byte lsb pressure */ /* start two byte lsb pressure */
scp_trans.buf[0] = SCP1000_DATARD16; scp_trans.buf[0] = SCP1000_DATARD16;
baro_scp_status = BARO_SCP_RD_PRESS_1; baro_scp_status = BARO_SCP_RD_PRESS_1;
I2CTransceive(SCP_I2C_DEV, scp_trans, SCP1000_SLAVE_ADDR, 1, 2); i2c_transceive(&SCP_I2C_DEV, &scp_trans, SCP1000_SLAVE_ADDR, 1, 2);
} }
else if (baro_scp_status == BARO_SCP_RD_PRESS_1) { else if (baro_scp_status == BARO_SCP_RD_PRESS_1) {
+1 -1
View File
@@ -57,7 +57,7 @@ void ezcurrent_init( void ) {
void ezcurrent_read_periodic( void ) { void ezcurrent_read_periodic( void ) {
if (ezcurrent_i2c_trans.status == I2CTransDone) { if (ezcurrent_i2c_trans.status == I2CTransDone) {
I2CReceive(EZCURRENT_I2C_DEV, ezcurrent_i2c_trans, ezcurrent_i2c_trans.slave_addr, 10); i2c_receive(&EZCURRENT_I2C_DEV, &ezcurrent_i2c_trans, ezcurrent_i2c_trans.slave_addr, 10);
} }
} }
+7 -7
View File
@@ -70,7 +70,7 @@ void imu_impl_init(void)
// -switch to gyroX clock // -switch to gyroX clock
aspirin2_mpu60x0.buf[0] = MPU60X0_REG_PWR_MGMT_1; aspirin2_mpu60x0.buf[0] = MPU60X0_REG_PWR_MGMT_1;
aspirin2_mpu60x0.buf[1] = 0x01; aspirin2_mpu60x0.buf[1] = 0x01;
I2CTransmit(PPZUAVIMU_I2C_DEV, aspirin2_mpu60x0, MPU60X0_ADDR, 2); i2c_transmit(&PPZUAVIMU_I2C_DEV, &aspirin2_mpu60x0, MPU60X0_ADDR, 2);
while(aspirin2_mpu60x0.status == I2CTransPending); while(aspirin2_mpu60x0.status == I2CTransPending);
// MPU60X0_REG_PWR_MGMT_2: Nothing should be in standby: default OK // MPU60X0_REG_PWR_MGMT_2: Nothing should be in standby: default OK
@@ -90,28 +90,28 @@ void imu_impl_init(void)
#endif #endif
aspirin2_mpu60x0.buf[0] = MPU60X0_REG_CONFIG; aspirin2_mpu60x0.buf[0] = MPU60X0_REG_CONFIG;
aspirin2_mpu60x0.buf[1] = (2 << 3) | (3 << 0); aspirin2_mpu60x0.buf[1] = (2 << 3) | (3 << 0);
I2CTransmit(PPZUAVIMU_I2C_DEV, aspirin2_mpu60x0, MPU60X0_ADDR, 2); i2c_transmit(&PPZUAVIMU_I2C_DEV, &aspirin2_mpu60x0, MPU60X0_ADDR, 2);
while(aspirin2_mpu60x0.status == I2CTransPending); while(aspirin2_mpu60x0.status == I2CTransPending);
// MPU60X0_REG_SMPLRT_DIV // MPU60X0_REG_SMPLRT_DIV
// -100Hz output = 1kHz / (9 + 1) // -100Hz output = 1kHz / (9 + 1)
aspirin2_mpu60x0.buf[0] = MPU60X0_REG_SMPLRT_DIV; aspirin2_mpu60x0.buf[0] = MPU60X0_REG_SMPLRT_DIV;
aspirin2_mpu60x0.buf[1] = 9; aspirin2_mpu60x0.buf[1] = 9;
I2CTransmit(PPZUAVIMU_I2C_DEV, aspirin2_mpu60x0, MPU60X0_ADDR, 2); i2c_transmit(&PPZUAVIMU_I2C_DEV, &aspirin2_mpu60x0, MPU60X0_ADDR, 2);
while(aspirin2_mpu60x0.status == I2CTransPending); while(aspirin2_mpu60x0.status == I2CTransPending);
// MPU60X0_REG_GYRO_CONFIG // MPU60X0_REG_GYRO_CONFIG
// -2000deg/sec // -2000deg/sec
aspirin2_mpu60x0.buf[0] = MPU60X0_REG_GYRO_CONFIG; aspirin2_mpu60x0.buf[0] = MPU60X0_REG_GYRO_CONFIG;
aspirin2_mpu60x0.buf[1] = (3<<3); aspirin2_mpu60x0.buf[1] = (3<<3);
I2CTransmit(PPZUAVIMU_I2C_DEV, aspirin2_mpu60x0, MPU60X0_ADDR, 2); i2c_transmit(&PPZUAVIMU_I2C_DEV, &aspirin2_mpu60x0, MPU60X0_ADDR, 2);
while(aspirin2_mpu60x0.status == I2CTransPending); while(aspirin2_mpu60x0.status == I2CTransPending);
// MPU60X0_REG_ACCEL_CONFIG // MPU60X0_REG_ACCEL_CONFIG
// 16g, no HPFL // 16g, no HPFL
aspirin2_mpu60x0.buf[0] = MPU60X0_REG_ACCEL_CONFIG; aspirin2_mpu60x0.buf[0] = MPU60X0_REG_ACCEL_CONFIG;
aspirin2_mpu60x0.buf[1] = (3<<3); aspirin2_mpu60x0.buf[1] = (3<<3);
I2CTransmit(PPZUAVIMU_I2C_DEV, aspirin2_mpu60x0, MPU60X0_ADDR, 2); i2c_transmit(&PPZUAVIMU_I2C_DEV, &aspirin2_mpu60x0, MPU60X0_ADDR, 2);
while(aspirin2_mpu60x0.status == I2CTransPending); while(aspirin2_mpu60x0.status == I2CTransPending);
@@ -157,12 +157,12 @@ void imu_periodic( void )
{ {
// Start reading the latest gyroscope data // Start reading the latest gyroscope data
aspirin2_mpu60x0.buf[0] = MPU60X0_REG_INT_STATUS; aspirin2_mpu60x0.buf[0] = MPU60X0_REG_INT_STATUS;
I2CTransceive(PPZUAVIMU_I2C_DEV, aspirin2_mpu60x0, MPU60X0_ADDR, 1, 21); i2c_transceive(&PPZUAVIMU_I2C_DEV, &aspirin2_mpu60x0, MPU60X0_ADDR, 1, 21);
/* /*
// Start reading the latest accelerometer data // Start reading the latest accelerometer data
ppzuavimu_adxl345.buf[0] = ADXL345_REG_DATA_X0; ppzuavimu_adxl345.buf[0] = ADXL345_REG_DATA_X0;
I2CTransceive(PPZUAVIMU_I2C_DEV, ppzuavimu_adxl345, ADXL345_ADDR, 1, 6); i2c_transceive(&PPZUAVIMU_I2C_DEV, &ppzuavimu_adxl345, ADXL345_ADDR, 1, 6);
*/ */
// Start reading the latest magnetometer data // Start reading the latest magnetometer data
#if PERIODIC_FREQUENCY > 60 #if PERIODIC_FREQUENCY > 60
@@ -96,7 +96,7 @@ void pbn_periodic( void ) {
// Initiate next read // Initiate next read
pbn_trans.buf[0] = 0; pbn_trans.buf[0] = 0;
I2CTransceive(PBN_I2C_DEV, pbn_trans, PBN_I2C_ADDR, 1, 4); i2c_transceive(&PBN_I2C_DEV, &pbn_trans, PBN_I2C_ADDR, 1, 4);
} }
+3 -3
View File
@@ -41,7 +41,7 @@ void ads1114_init( void ) {
ads1114_1.trans.buf[0] = ADS1114_POINTER_CONFIG_REG; ads1114_1.trans.buf[0] = ADS1114_POINTER_CONFIG_REG;
ads1114_1.trans.buf[1] = ADS1114_1_CONFIG_MSB; ads1114_1.trans.buf[1] = ADS1114_1_CONFIG_MSB;
ads1114_1.trans.buf[2] = ADS1114_1_CONFIG_LSB; ads1114_1.trans.buf[2] = ADS1114_1_CONFIG_LSB;
I2CTransmit(ADS1114_I2C_DEV, ads1114_1.trans, ADS1114_1_I2C_ADDR, 3); i2c_transmit(&ADS1114_I2C_DEV, &ads1114_1.trans, ADS1114_1_I2C_ADDR, 3);
ads1114_1.config_done = FALSE; ads1114_1.config_done = FALSE;
ads1114_1.data_available = FALSE; ads1114_1.data_available = FALSE;
#endif #endif
@@ -52,7 +52,7 @@ void ads1114_init( void ) {
ads1114_2.trans.buf[0] = ADS1114_POINTER_CONFIG_REG; ads1114_2.trans.buf[0] = ADS1114_POINTER_CONFIG_REG;
ads1114_2.trans.buf[1] = ADS1114_2_CONFIG_MSB; ads1114_2.trans.buf[1] = ADS1114_2_CONFIG_MSB;
ads1114_2.trans.buf[2] = ADS1114_2_CONFIG_LSB; ads1114_2.trans.buf[2] = ADS1114_2_CONFIG_LSB;
I2CTransmit(ADS1114_I2C_DEV, ads1114_2.trans, ADS1114_2_I2C_ADDR, 3); i2c_transmit(&ADS1114_I2C_DEV, &ads1114_2.trans, ADS1114_2_I2C_ADDR, 3);
ads1114_2.config_done = FALSE; ads1114_2.config_done = FALSE;
ads1114_2.data_available = FALSE; ads1114_2.data_available = FALSE;
#endif #endif
@@ -64,7 +64,7 @@ void ads1114_read( struct ads1114_periph * p ) {
// start new reading when previous is done (and read if success) // start new reading when previous is done (and read if success)
if (p->config_done && p->trans.status == I2CTransDone) { if (p->config_done && p->trans.status == I2CTransDone) {
p->trans.buf[0] = ADS1114_POINTER_CONV_REG; p->trans.buf[0] = ADS1114_POINTER_CONV_REG;
I2CTransceive(ADS1114_I2C_DEV, p->trans, p->i2c_addr, 1, 2); i2c_transceive(&ADS1114_I2C_DEV, &(p->trans), p->i2c_addr, 1, 2);
} }
} }
+4 -4
View File
@@ -66,13 +66,13 @@ static void mpl3115_send_config(void)
case MPL_CONF_PT_DATA: case MPL_CONF_PT_DATA:
mpl3115_trans.buf[0] = MPL3115_REG_PT_DATA_CFG; mpl3115_trans.buf[0] = MPL3115_REG_PT_DATA_CFG;
mpl3115_trans.buf[1] = MPL3115_PT_DATA_CFG; mpl3115_trans.buf[1] = MPL3115_PT_DATA_CFG;
I2CTransmit(MPL3115_I2C_DEV, mpl3115_trans, MPL3115_I2C_ADDR, 2); i2c_transmit(&MPL3115_I2C_DEV, &mpl3115_trans, MPL3115_I2C_ADDR, 2);
mpl3115_init_status++; mpl3115_init_status++;
break; break;
case MPL_CONF_CTRL1: case MPL_CONF_CTRL1:
mpl3115_trans.buf[0] = MPL3115_REG_CTRL_REG1; mpl3115_trans.buf[0] = MPL3115_REG_CTRL_REG1;
mpl3115_trans.buf[1] = MPL3115_CTRL_REG1; mpl3115_trans.buf[1] = MPL3115_CTRL_REG1;
I2CTransmit(MPL3115_I2C_DEV, mpl3115_trans, MPL3115_I2C_ADDR, 2); i2c_transmit(&MPL3115_I2C_DEV, &mpl3115_trans, MPL3115_I2C_ADDR, 2);
mpl3115_init_status++; mpl3115_init_status++;
break; break;
case MPL_CONF_DONE: case MPL_CONF_DONE:
@@ -101,11 +101,11 @@ void mpl3115_read(void)
// ask for a reading and then prepare next conversion // ask for a reading and then prepare next conversion
if (mpl3115_initialized && mpl3115_trans.status == I2CTransDone) { if (mpl3115_initialized && mpl3115_trans.status == I2CTransDone) {
mpl3115_trans.buf[0] = MPL3115_REG_STATUS; mpl3115_trans.buf[0] = MPL3115_REG_STATUS;
I2CTransceive(MPL3115_I2C_DEV, mpl3115_trans, MPL3115_I2C_ADDR, 1, 6); i2c_transceive(&MPL3115_I2C_DEV, &mpl3115_trans, MPL3115_I2C_ADDR, 1, 6);
if (mpl3115_req_trans.status == I2CTransDone) { if (mpl3115_req_trans.status == I2CTransDone) {
mpl3115_req_trans.buf[0] = MPL3115_REG_CTRL_REG1; mpl3115_req_trans.buf[0] = MPL3115_REG_CTRL_REG1;
mpl3115_req_trans.buf[1] = MPL3115_CTRL_REG1 | MPL3115_OST_BIT; mpl3115_req_trans.buf[1] = MPL3115_CTRL_REG1 | MPL3115_OST_BIT;
I2CTransmit(MPL3115_I2C_DEV, mpl3115_req_trans, MPL3115_I2C_ADDR, 2); i2c_transmit(&MPL3115_I2C_DEV, &mpl3115_req_trans, MPL3115_I2C_ADDR, 2);
} }
} }
} }
@@ -120,7 +120,7 @@ void actuators_asctec_set(bool_t motors_on) {
} }
actuators_asctec.cmd = NONE; actuators_asctec.cmd = NONE;
I2CTransmit(ACTUATORS_ASCTEC_DEVICE, actuators_asctec.i2c_trans, i2c_transmit(&ACTUATORS_ASCTEC_DEVICE, &actuators_asctec.i2c_trans,
ACTUATORS_ASCTEC_SLAVE_ADDR, 4); ACTUATORS_ASCTEC_SLAVE_ADDR, 4);
} }
@@ -52,6 +52,6 @@ void actuators_mkk_set(void) {
actuators_mkk.trans[i].buf[0] = 0; actuators_mkk.trans[i].buf[0] = 0;
#endif #endif
I2CTransmit(ACTUATORS_MKK_DEVICE, actuators_mkk.trans[i], actuators_addr[i], 1); i2c_transmit(&ACTUATORS_MKK_DEVICE, &actuators_mkk.trans[i], actuators_addr[i], 1);
} }
} }
@@ -100,11 +100,11 @@ void infrared_i2c_update( void ) {
if (irh_trans.status == I2CTransDone && ir_i2c_hor_status == IR_I2C_IDLE) { if (irh_trans.status == I2CTransDone && ir_i2c_hor_status == IR_I2C_IDLE) {
if (ValidConfWord(ir_i2c_conf_word) && !ir_i2c_conf_hor_done) { if (ValidConfWord(ir_i2c_conf_word) && !ir_i2c_conf_hor_done) {
irh_trans.buf[0] = ir_i2c_conf_word | IR_HOR_OC_BIT | IR_START_CONV ; irh_trans.buf[0] = ir_i2c_conf_word | IR_HOR_OC_BIT | IR_START_CONV ;
I2CTransmit(i2c0, irh_trans, IR_HOR_I2C_ADDR, 1); i2c_transmit(&i2c0, &irh_trans, IR_HOR_I2C_ADDR, 1);
ir_i2c_hor_status = IR_I2C_CONFIGURE_HOR; ir_i2c_hor_status = IR_I2C_CONFIGURE_HOR;
} else { } else {
// Read next values // Read next values
I2CReceive(i2c0, irh_trans, IR_HOR_I2C_ADDR, 3); i2c_receive(&i2c0, &irh_trans, IR_HOR_I2C_ADDR, 3);
ir_i2c_data_hor_available = FALSE; ir_i2c_data_hor_available = FALSE;
ir_i2c_hor_status = IR_I2C_READ_IR1; ir_i2c_hor_status = IR_I2C_READ_IR1;
} }
@@ -113,10 +113,10 @@ void infrared_i2c_update( void ) {
if (irv_trans.status == I2CTransDone) { if (irv_trans.status == I2CTransDone) {
if (ValidConfWord(ir_i2c_conf_word) && !ir_i2c_conf_ver_done) { if (ValidConfWord(ir_i2c_conf_word) && !ir_i2c_conf_ver_done) {
irv_trans.buf[0] = ir_i2c_conf_word | IR_VER_OC_BIT; irv_trans.buf[0] = ir_i2c_conf_word | IR_VER_OC_BIT;
I2CTransmit(i2c0, irv_trans, IR_VER_I2C_ADDR, 1); i2c_transmit(&i2c0, &irv_trans, IR_VER_I2C_ADDR, 1);
} else { } else {
// Read next values // Read next values
I2CReceive(i2c0, irv_trans, IR_VER_I2C_ADDR, 2); i2c_receive(&i2c0, &irv_trans, IR_VER_I2C_ADDR, 2);
ir_i2c_data_ver_available = FALSE; ir_i2c_data_ver_available = FALSE;
} }
} }
@@ -133,7 +133,7 @@ void infrared_i2c_hor_event( void ) {
break; break;
case IR_I2C_READ_IR1 : case IR_I2C_READ_IR1 :
if (bit_is_set(irh_trans.buf[2],7)) { if (bit_is_set(irh_trans.buf[2],7)) {
I2CReceive(i2c0, irh_trans, IR_HOR_I2C_ADDR, 3); i2c_receive(&i2c0, &irh_trans, IR_HOR_I2C_ADDR, 3);
break; break;
} }
// Read IR1 value // Read IR1 value
@@ -142,18 +142,18 @@ void infrared_i2c_hor_event( void ) {
ir_i2c.ir1 = FilterIR(ir_i2c.ir1, ir1); ir_i2c.ir1 = FilterIR(ir_i2c.ir1, ir1);
// Select IR2 channel // Select IR2 channel
irh_trans.buf[0] = IR_HOR_I2C_SELECT_IR2 | IR_HOR_OC_BIT | ir_i2c_conf_word | IR_START_CONV; irh_trans.buf[0] = IR_HOR_I2C_SELECT_IR2 | IR_HOR_OC_BIT | ir_i2c_conf_word | IR_START_CONV;
I2CTransmit(i2c0, irh_trans, IR_HOR_I2C_ADDR, 1); i2c_transmit(&i2c0, &irh_trans, IR_HOR_I2C_ADDR, 1);
ir_i2c_hor_status = IR_I2C_IR2_SELECTED; ir_i2c_hor_status = IR_I2C_IR2_SELECTED;
break; break;
case IR_I2C_IR2_SELECTED : case IR_I2C_IR2_SELECTED :
// IR2 selected, asking for IR2 value // IR2 selected, asking for IR2 value
I2CReceive(i2c0, irh_trans, IR_HOR_I2C_ADDR, 3); i2c_receive(&i2c0, &irh_trans, IR_HOR_I2C_ADDR, 3);
ir_i2c_hor_status = IR_I2C_READ_IR2; ir_i2c_hor_status = IR_I2C_READ_IR2;
break; break;
case IR_I2C_READ_IR2 : case IR_I2C_READ_IR2 :
// Read IR2 value // Read IR2 value
if (bit_is_set(irh_trans.buf[2],7)) { if (bit_is_set(irh_trans.buf[2],7)) {
I2CReceive(i2c0, irh_trans, IR_HOR_I2C_ADDR, 3); i2c_receive(&i2c0, &irh_trans, IR_HOR_I2C_ADDR, 3);
break; break;
} }
int16_t ir2 = (irh_trans.buf[0]<<8) | irh_trans.buf[1]; int16_t ir2 = (irh_trans.buf[0]<<8) | irh_trans.buf[1];
@@ -170,7 +170,7 @@ void infrared_i2c_hor_event( void ) {
#endif #endif
// Select IR1 channel // Select IR1 channel
irh_trans.buf[0] = IR_HOR_I2C_SELECT_IR1 | IR_HOR_OC_BIT | ir_i2c_conf_word | IR_START_CONV; irh_trans.buf[0] = IR_HOR_I2C_SELECT_IR1 | IR_HOR_OC_BIT | ir_i2c_conf_word | IR_START_CONV;
I2CTransmit(i2c0, irh_trans, IR_HOR_I2C_ADDR, 1); i2c_transmit(&i2c0, &irh_trans, IR_HOR_I2C_ADDR, 1);
ir_i2c_hor_status = IR_I2C_IR1_SELECTED; ir_i2c_hor_status = IR_I2C_IR1_SELECTED;
break; break;
case IR_I2C_IR1_SELECTED : case IR_I2C_IR1_SELECTED :