mirror of
https://github.com/Klipper3d/klipper.git
synced 2025-07-23 06:33:59 -06:00
avr: implement i2c_read
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
parent
b28df43b26
commit
5fe9dd5a50
2 changed files with 19 additions and 2 deletions
|
@ -84,6 +84,14 @@ i2c_send_byte(uint8_t b, uint32_t timeout)
|
|||
i2c_wait(timeout);
|
||||
}
|
||||
|
||||
static void
|
||||
i2c_receive_byte(uint8_t *read, uint32_t timeout, uint8_t send_ack)
|
||||
{
|
||||
TWCR = (1<<TWEN) | (1<<TWINT) | ((send_ack?1:0)<<TWEA);
|
||||
i2c_wait(timeout);
|
||||
*read = TWDR;
|
||||
}
|
||||
|
||||
static void
|
||||
i2c_stop(uint32_t timeout)
|
||||
{
|
||||
|
@ -106,5 +114,14 @@ void
|
|||
i2c_read(struct i2c_config config, uint8_t reg_len, uint8_t *reg
|
||||
, uint8_t read_len, uint8_t *read)
|
||||
{
|
||||
shutdown("i2c_read not supported on avr");
|
||||
uint32_t timeout = timer_read_time() + timer_from_us(5000);
|
||||
i2c_start(timeout);
|
||||
i2c_send_byte(config.addr, timeout);
|
||||
while (reg_len--)
|
||||
i2c_send_byte(*reg++, timeout);
|
||||
i2c_start(timeout);
|
||||
i2c_send_byte(config.addr | 0x1, timeout);
|
||||
while (read_len--)
|
||||
i2c_receive_byte(read++, timeout, read_len);
|
||||
i2c_stop(timeout);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue