mirror of
https://github.com/paparazzi/paparazzi.git
synced 2026-06-06 16:58:48 +08:00
remove i2c stop_after_transmit flag
always do a stop after transmit (previous default behavior)
This commit is contained in:
@@ -28,7 +28,6 @@
|
||||
#include "interrupt_hw.h"
|
||||
#include BOARD_CONFIG
|
||||
|
||||
|
||||
///////////////////
|
||||
// I2C Automaton //
|
||||
///////////////////
|
||||
@@ -56,22 +55,18 @@ __attribute__ ((always_inline)) static inline void I2cEndOfTransaction(struct i2
|
||||
}
|
||||
}
|
||||
|
||||
__attribute__ ((always_inline)) static inline void I2cFinished(struct i2c_periph* p, struct i2c_transaction* t) {
|
||||
__attribute__ ((always_inline)) static inline void I2cSendStop(struct i2c_periph* p, struct i2c_transaction* t) {
|
||||
((i2cRegs_t *)(p->reg_addr))->conset = _BV(STO);
|
||||
// transaction finished with success
|
||||
t->status = I2CTransSuccess;
|
||||
I2cEndOfTransaction(p);
|
||||
}
|
||||
|
||||
__attribute__ ((always_inline)) static inline void I2cSendStop(struct i2c_periph* p, struct i2c_transaction* t) {
|
||||
((i2cRegs_t *)(p->reg_addr))->conset = _BV(STO);
|
||||
I2cFinished(p,t);
|
||||
}
|
||||
|
||||
__attribute__ ((always_inline)) static inline void I2cFail(struct i2c_periph* p, struct i2c_transaction* t) {
|
||||
((i2cRegs_t *)(p->reg_addr))->conset = _BV(STO);
|
||||
// transaction failed
|
||||
t->status = I2CTransFailed;
|
||||
p->status = I2CFailed;
|
||||
// FIXME I2C should be reseted here
|
||||
// FIXME I2C should be reseted here ?
|
||||
I2cEndOfTransaction(p);
|
||||
}
|
||||
|
||||
@@ -122,13 +117,20 @@ __attribute__ ((always_inline)) static inline void I2cAutomaton(int32_t state, s
|
||||
I2cSendStop(p,trans);
|
||||
}
|
||||
break;
|
||||
case I2C_MR_DATA_NACK:
|
||||
if (p->idx_buf < trans->len_r) {
|
||||
trans->buf[p->idx_buf] = ((i2cRegs_t *)(p->reg_addr))->dat;
|
||||
}
|
||||
I2cSendStop(p,trans);
|
||||
break;
|
||||
case I2C_MR_SLA_ACK: /* At least one char */
|
||||
/* Wait and reply with ACK or NACK */
|
||||
I2cReceive(p->reg_addr,p->idx_buf < trans->len_r - 1);
|
||||
break;
|
||||
case I2C_MR_SLA_NACK:
|
||||
case I2C_MT_SLA_NACK:
|
||||
I2cSendStart(p);
|
||||
/* Slave is not responding, transaction is failed */
|
||||
I2cFail(p,trans);
|
||||
break;
|
||||
case I2C_MT_SLA_ACK:
|
||||
case I2C_MT_DATA_ACK:
|
||||
@@ -137,28 +139,17 @@ __attribute__ ((always_inline)) static inline void I2cAutomaton(int32_t state, s
|
||||
p->idx_buf++;
|
||||
} else {
|
||||
if (trans->type == I2CTransTxRx) {
|
||||
trans->type = I2CTransRx; /* FIXME should not change type */
|
||||
//trans->type = I2CTransRx; /* FIXME should not change type */
|
||||
p->idx_buf = 0;
|
||||
trans->slave_addr |= 1;
|
||||
I2cSendStart(p);
|
||||
} else {
|
||||
if (trans->stop_after_transmit) {
|
||||
I2cSendStop(p,trans);
|
||||
} else {
|
||||
I2cFinished(p,trans);
|
||||
}
|
||||
I2cSendStop(p,trans);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case I2C_MR_DATA_NACK:
|
||||
if (p->idx_buf < trans->len_r) {
|
||||
trans->buf[p->idx_buf] = ((i2cRegs_t *)(p->reg_addr))->dat;
|
||||
}
|
||||
I2cSendStop(p,trans);
|
||||
break;
|
||||
default:
|
||||
I2cSendStop(p,trans);
|
||||
//I2cFail(p,trans);
|
||||
I2cFail(p,trans);
|
||||
/* FIXME log error */
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -43,7 +43,6 @@ void actuators_init(void) {
|
||||
actuators_mkk.trans[i].type = I2CTransTx;
|
||||
actuators_mkk.trans[i].len_w = 1;
|
||||
actuators_mkk.trans[i].slave_addr = actuators_addr[i];
|
||||
actuators_mkk.trans[i].stop_after_transmit = TRUE;
|
||||
actuators_mkk.trans[i].status = I2CTransSuccess;
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,6 @@ struct i2c_transaction {
|
||||
uint8_t slave_addr;
|
||||
uint16_t len_r;
|
||||
uint8_t len_w;
|
||||
bool_t stop_after_transmit;
|
||||
volatile uint8_t buf[I2C_BUF_LEN];
|
||||
volatile enum I2CTransactionStatus status;
|
||||
};
|
||||
@@ -136,40 +135,28 @@ extern bool_t i2c_idle(struct i2c_periph* p);
|
||||
extern bool_t i2c_submit(struct i2c_periph* p, struct i2c_transaction* t);
|
||||
|
||||
#define I2CReceive(_p, _t, _s_addr, _len) { \
|
||||
_t.type = I2CTransRx; \
|
||||
_t.slave_addr = _s_addr; \
|
||||
_t.len_r = _len; \
|
||||
_t.len_w = 0; \
|
||||
_t.stop_after_transmit = TRUE; \
|
||||
i2c_submit(&(_p),&(_t)); \
|
||||
}
|
||||
_t.type = I2CTransRx; \
|
||||
_t.slave_addr = _s_addr; \
|
||||
_t.len_r = _len; \
|
||||
_t.len_w = 0; \
|
||||
i2c_submit(&(_p),&(_t)); \
|
||||
}
|
||||
|
||||
#define I2CTransmit(_p, _t, _s_addr, _len) { \
|
||||
_t.type = I2CTransTx; \
|
||||
_t.slave_addr = _s_addr; \
|
||||
_t.len_r = 0; \
|
||||
_t.len_w = _len; \
|
||||
_t.stop_after_transmit = TRUE; \
|
||||
i2c_submit(&(_p),&(_t)); \
|
||||
}
|
||||
_t.type = I2CTransTx; \
|
||||
_t.slave_addr = _s_addr; \
|
||||
_t.len_r = 0; \
|
||||
_t.len_w = _len; \
|
||||
i2c_submit(&(_p),&(_t)); \
|
||||
}
|
||||
|
||||
#define I2CTransmitNoStop(_p, _t, _s_addr, _len) { \
|
||||
_t.type = I2CTransTx; \
|
||||
_t.slave_addr = _s_addr; \
|
||||
_t.len_r = 0; \
|
||||
_t.len_w = _len; \
|
||||
_t.stop_after_transmit = FALSE; \
|
||||
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; \
|
||||
_t.stop_after_transmit = TRUE; \
|
||||
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)); \
|
||||
}
|
||||
|
||||
|
||||
#endif /* I2C_H */
|
||||
|
||||
@@ -17,7 +17,6 @@ void ami601_init( void ) {
|
||||
}
|
||||
ami601_i2c_trans.status = I2CTransSuccess;
|
||||
ami601_i2c_trans.slave_addr = AMI601_SLAVE_ADDR;
|
||||
ami601_i2c_trans.stop_after_transmit = TRUE;
|
||||
ami601_nb_err = 0;
|
||||
ami601_status = AMI601_IDLE;
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@ void hmc5843_init(void)
|
||||
{
|
||||
hmc5843.i2c_trans.status = I2CTransSuccess;
|
||||
hmc5843.i2c_trans.slave_addr = HMC5843_ADDR;
|
||||
hmc5843.i2c_trans.stop_after_transmit = TRUE;
|
||||
|
||||
hmc5843_arch_init();
|
||||
}
|
||||
|
||||
@@ -59,7 +59,6 @@ static inline void main_periodic_task( void ) {
|
||||
trans.buf[0] = 0x04;
|
||||
trans.len_w = 1;
|
||||
trans.slave_addr = 0x58;
|
||||
trans.stop_after_transmit = TRUE;
|
||||
i2c_submit(&ACTUATORS_MKK_DEV,&trans);
|
||||
|
||||
LED_PERIODIC();
|
||||
|
||||
Reference in New Issue
Block a user