mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/sta-core.git
synced 2025-06-10 16:55:58 +00:00
Added I2C address scan
This commit is contained in:
parent
bbdfc29368
commit
0e44e257ee
@ -35,11 +35,19 @@ namespace sta
|
||||
*/
|
||||
void setSettings(uint16_t address, bool master, bool blocking);
|
||||
|
||||
/**
|
||||
* @brief Checks if a device with the given address is connected to the I2C bus.
|
||||
*
|
||||
* @param address The address to check availability for.
|
||||
* @return true if the address exists, false otherwise.
|
||||
*/
|
||||
virtual bool hasAddress(int address) = 0;
|
||||
|
||||
/**
|
||||
* @brief Prints all available addresses via the debug printable.
|
||||
*
|
||||
*/
|
||||
virtual void addressScan() = 0;
|
||||
void scanAddresses();
|
||||
protected:
|
||||
/// @brief The peripheral's address to communicate with.
|
||||
uint16_t address_;
|
||||
|
@ -28,8 +28,7 @@ namespace sta
|
||||
bool receive(uint8_t * buffer, size_t size, uint32_t timeout = STA_MAX_TIMEOUT) override;
|
||||
bool readMemory(uint8_t regAddr, uint8_t * buffer, size_t size, uint32_t timeout = STA_MAX_TIMEOUT) override;
|
||||
bool fill(uint8_t value, size_t count, uint32_t timeout = STA_MAX_TIMEOUT) override;
|
||||
bool hasAddress(int address);
|
||||
void addressScan();
|
||||
bool hasAddress(int address) override;
|
||||
private:
|
||||
I2C_HandleTypeDef * handle_;
|
||||
};
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include <sta/bus/i2c/i2c.hpp>
|
||||
|
||||
#include <sta/debug/debug.hpp>
|
||||
|
||||
namespace sta
|
||||
{
|
||||
@ -15,4 +15,15 @@ namespace sta
|
||||
master_ = master;
|
||||
blocking_ = blocking;
|
||||
}
|
||||
|
||||
void I2C::scanAddresses()
|
||||
{
|
||||
for (uint8_t i = 0; i < 128; ++i)
|
||||
{
|
||||
if (hasAddress(i))
|
||||
{
|
||||
STA_DEBUG_PRINTF("Address %d is available", i);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace sta
|
||||
|
@ -141,17 +141,6 @@ namespace sta
|
||||
return HAL_I2C_IsDeviceReady(handle_, (uint16_t)(address << 1), 3, 5) == HAL_OK;
|
||||
}
|
||||
|
||||
void STM32I2C::addressScan()
|
||||
{
|
||||
for(uint8_t i = 1; i < 128; i++)
|
||||
{
|
||||
if (hasAddress(i))
|
||||
{
|
||||
STA_DEBUG_PRINTF("Address %d exists", i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
STM32I2CDevice::STM32I2CDevice(STM32I2C * intf, int address, bool master, bool blocking)
|
||||
/* The address is bit-shifted by one to work properly for the STM32 HAL. */
|
||||
: I2CDevice(intf, address << 1, master, blocking)
|
||||
|
Loading…
x
Reference in New Issue
Block a user