I2C: Device probe function I wrote, didn't need, but thought might be useful in the future.
This commit is contained in:
@ -66,3 +66,14 @@ void i2c_lpc_transfer(i2c_bus_t* const bus,
|
|||||||
|
|
||||||
i2c_stop(port);
|
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;
|
||||||
|
}
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
#include "i2c_bus.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,
|
const uint8_t* const data_tx, const size_t count_tx,
|
||||||
uint8_t* const data_rx, const size_t count_rx
|
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__*/
|
#endif/*__I2C_LPC_H__*/
|
||||||
|
Reference in New Issue
Block a user