mirror of https://github.com/Desuuuu/klipper.git
atsam: Minor whitespace changes to i2c.c
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
6268c702e5
commit
5fe5f09244
|
@ -48,29 +48,25 @@ i2c_init(Twi *p_twi, uint32_t rate)
|
|||
p_twi->TWI_CR = TWI_CR_SVDIS;
|
||||
p_twi->TWI_CR = TWI_CR_MSEN;
|
||||
|
||||
uint32_t cldiv = 0;
|
||||
uint32_t chdiv = 0;
|
||||
uint32_t ckdiv = 0;
|
||||
|
||||
uint32_t cldiv = 0, chdiv = 0, ckdiv = 0;
|
||||
cldiv = SystemCoreClock / ((rate > 384000 ? 384000 : rate) * 4) - 4;
|
||||
|
||||
while((cldiv > 255) && (ckdiv < 7)) {
|
||||
while ((cldiv > 255) && (ckdiv < 7)) {
|
||||
ckdiv++;
|
||||
cldiv /= 2;
|
||||
}
|
||||
|
||||
if (rate > 348000) {
|
||||
chdiv = SystemCoreClock / ((2 * rate - 384000) * 4) - 4;
|
||||
while((chdiv > 255) && (ckdiv < 7)) {
|
||||
while ((chdiv > 255) && (ckdiv < 7)) {
|
||||
ckdiv++;
|
||||
chdiv /= 2;
|
||||
}
|
||||
} else {
|
||||
chdiv = cldiv;
|
||||
}
|
||||
p_twi->TWI_CWGR = TWI_CWGR_CLDIV(cldiv) | \
|
||||
TWI_CWGR_CHDIV(chdiv) | \
|
||||
TWI_CWGR_CKDIV(ckdiv);
|
||||
p_twi->TWI_CWGR = (TWI_CWGR_CLDIV(cldiv) | TWI_CWGR_CHDIV(chdiv)
|
||||
| TWI_CWGR_CKDIV(ckdiv));
|
||||
}
|
||||
|
||||
static uint32_t
|
||||
|
@ -102,14 +98,12 @@ i2c_setup(uint32_t bus, uint32_t rate, uint8_t addr)
|
|||
}
|
||||
|
||||
void
|
||||
i2c_write(struct i2c_config config,
|
||||
uint8_t write_len, uint8_t *write)
|
||||
i2c_write(struct i2c_config config, uint8_t write_len, uint8_t *write)
|
||||
{
|
||||
Twi *p_twi = config.twi;
|
||||
uint32_t status;
|
||||
uint32_t bytes_to_send = write_len;
|
||||
uint32_t status, bytes_to_send = write_len;
|
||||
p_twi->TWI_MMR = TWI_MMR_DADR(config.addr);
|
||||
for(;;) {
|
||||
for (;;) {
|
||||
status = p_twi->TWI_SR;
|
||||
if (status & TWI_SR_NACK)
|
||||
shutdown("I2C NACK error encountered!");
|
||||
|
@ -121,8 +115,8 @@ i2c_write(struct i2c_config config,
|
|||
bytes_to_send--;
|
||||
}
|
||||
p_twi->TWI_CR = TWI_CR_STOP;
|
||||
while(!(p_twi->TWI_SR& TWI_SR_TXCOMP)) {
|
||||
}
|
||||
while (!(p_twi->TWI_SR & TWI_SR_TXCOMP))
|
||||
;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -138,18 +132,15 @@ i2c_wait(Twi* p_twi, uint32_t bit, uint32_t timeout)
|
|||
}
|
||||
|
||||
void
|
||||
i2c_read(struct i2c_config config,
|
||||
uint8_t reg_len, uint8_t *reg,
|
||||
uint8_t read_len, uint8_t *read)
|
||||
i2c_read(struct i2c_config config, uint8_t reg_len, uint8_t *reg
|
||||
, uint8_t read_len, uint8_t *read)
|
||||
{
|
||||
Twi *p_twi = config.twi;
|
||||
uint32_t status;
|
||||
uint32_t bytes_to_send=read_len;
|
||||
uint32_t status, bytes_to_send = read_len;
|
||||
uint8_t stop = 0;
|
||||
p_twi->TWI_MMR = 0;
|
||||
p_twi->TWI_MMR = TWI_MMR_MREAD | TWI_MMR_DADR(config.addr) |
|
||||
((reg_len << TWI_MMR_IADRSZ_Pos) &
|
||||
TWI_MMR_IADRSZ_Msk);
|
||||
p_twi->TWI_MMR = (TWI_MMR_MREAD | TWI_MMR_DADR(config.addr)
|
||||
| ((reg_len << TWI_MMR_IADRSZ_Pos) & TWI_MMR_IADRSZ_Msk));
|
||||
p_twi->TWI_IADR = 0;
|
||||
p_twi->TWI_IADR = addr_to_u32(reg_len, reg);
|
||||
if (bytes_to_send == 1) {
|
||||
|
@ -169,12 +160,12 @@ i2c_read(struct i2c_config config,
|
|||
stop = 1;
|
||||
}
|
||||
i2c_wait(p_twi, TWI_SR_RXRDY, timer_read_time() + timer_from_us(5000));
|
||||
if (!(status & TWI_SR_RXRDY)) {
|
||||
if (!(status & TWI_SR_RXRDY))
|
||||
continue;
|
||||
}
|
||||
*read++ = p_twi->TWI_RHR;
|
||||
bytes_to_send--;
|
||||
}
|
||||
while (!(p_twi->TWI_SR & TWI_SR_TXCOMP)) {}
|
||||
while (!(p_twi->TWI_SR & TWI_SR_TXCOMP))
|
||||
;
|
||||
(void)p_twi->TWI_SR;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue