mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/sta-core.git
synced 2025-06-12 01:25:59 +00:00
Added I2C address scan
This commit is contained in:
parent
7efa3c333e
commit
9578485117
@ -35,6 +35,11 @@ namespace sta
|
|||||||
*/
|
*/
|
||||||
void setSettings(uint16_t address, bool master, bool blocking);
|
void setSettings(uint16_t address, bool master, bool blocking);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Prints all available addresses via the debug printable.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
virtual void scanAddresses() = 0;
|
||||||
protected:
|
protected:
|
||||||
/// @brief The peripheral's address to communicate with.
|
/// @brief The peripheral's address to communicate with.
|
||||||
uint16_t address_;
|
uint16_t address_;
|
||||||
|
@ -27,6 +27,7 @@ namespace sta
|
|||||||
void receive(uint8_t * buffer, size_t size) override;
|
void receive(uint8_t * buffer, size_t size) override;
|
||||||
|
|
||||||
void fill(uint8_t value, size_t count) override;
|
void fill(uint8_t value, size_t count) override;
|
||||||
|
void scanAddresses() override;
|
||||||
private:
|
private:
|
||||||
I2C_HandleTypeDef * handle_;
|
I2C_HandleTypeDef * handle_;
|
||||||
const uint32_t timeout_ = 1000;
|
const uint32_t timeout_ = 1000;
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include <sta/devices/stm32/bus/i2c.hpp>
|
#include <sta/devices/stm32/bus/i2c.hpp>
|
||||||
|
|
||||||
|
#include <sta/debug/debug.hpp>
|
||||||
#include <sta/debug/assert.hpp>
|
#include <sta/debug/assert.hpp>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
@ -116,6 +117,19 @@ namespace sta
|
|||||||
delete [] buffer;
|
delete [] buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void STM32I2C::scanAddresses()
|
||||||
|
{
|
||||||
|
for (uint8_t i = 0; i < 128; ++i)
|
||||||
|
{
|
||||||
|
uint8_t ret = HAL_I2C_IsDeviceReady(handle_, (uint16_t)(i << 1), 3, 5);
|
||||||
|
|
||||||
|
if (ret != HAL_OK)
|
||||||
|
STA_DEBUG_PRINTF("Address %d is available", i);
|
||||||
|
else
|
||||||
|
STA_DEBUG_PRINTF("Address %d is unavailable", i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
STM32I2CDevice::STM32I2CDevice(STM32I2C * intf, int address, bool master, bool blocking)
|
STM32I2CDevice::STM32I2CDevice(STM32I2C * intf, int address, bool master, bool blocking)
|
||||||
/* The address is bit-shifted by one to work properly for the STM32 HAL. */
|
/* The address is bit-shifted by one to work properly for the STM32 HAL. */
|
||||||
: I2CDevice(intf, address << 1, master, blocking)
|
: I2CDevice(intf, address << 1, master, blocking)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user