I2C: Device probe function I wrote, didn't need, but thought might be useful in the future.

This commit is contained in:
Jared Boone
2018-12-27 21:11:35 -08:00
parent b35ec285b6
commit 2e6153a653
2 changed files with 13 additions and 0 deletions

View File

@ -66,3 +66,14 @@ void i2c_lpc_transfer(i2c_bus_t* const bus,
i2c_stop(port);
}
bool i2c_probe(i2c_bus_t* const bus, const uint_fast8_t device_address) {
const uint32_t port = (uint32_t)bus->obj;
i2c_tx_start(port);
i2c_tx_byte(port, (device_address << 1) | I2C_WRITE);
const bool detected = (I2C_STAT(port) == 0x18);
i2c_stop(port);
return detected;
}

View File

@ -24,6 +24,7 @@
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#include "i2c_bus.h"
@ -38,5 +39,6 @@ void i2c_lpc_transfer(i2c_bus_t* const bus,
const uint8_t* const data_tx, const size_t count_tx,
uint8_t* const data_rx, const size_t count_rx
);
bool i2c_probe(i2c_bus_t* const bus, const uint_fast8_t device_address);
#endif/*__I2C_LPC_H__*/