mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/sta-core.git
synced 2025-06-10 16:55:58 +00:00
Added address scan and verification for STM32 I2C
This commit is contained in:
parent
9578485117
commit
fc35796e45
@ -25,6 +25,8 @@ namespace sta
|
||||
void transfer16(uint16_t value) override;
|
||||
void transfer(const uint8_t * buffer, size_t size) override;
|
||||
void receive(uint8_t * buffer, size_t size) override;
|
||||
bool hasAddress(int address);
|
||||
void addressScan();
|
||||
|
||||
void fill(uint8_t value, size_t count) override;
|
||||
void scanAddresses() override;
|
||||
|
@ -2,8 +2,12 @@
|
||||
|
||||
#include <sta/debug/debug.hpp>
|
||||
#include <sta/debug/assert.hpp>
|
||||
#include <sta/debug/debug.hpp>
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include <i2c.h>
|
||||
|
||||
#ifdef STA_STM32_I2C_ENABLED
|
||||
|
||||
namespace sta
|
||||
@ -117,16 +121,19 @@ namespace sta
|
||||
delete [] buffer;
|
||||
}
|
||||
|
||||
void STM32I2C::scanAddresses()
|
||||
bool STM32I2C::hasAddress(int address)
|
||||
{
|
||||
for (uint8_t i = 0; i < 128; ++i)
|
||||
{
|
||||
uint8_t ret = HAL_I2C_IsDeviceReady(handle_, (uint16_t)(i << 1), 3, 5);
|
||||
return HAL_I2C_IsDeviceReady(handle_, (uint16_t)(address << 1), 3, 5) == HAL_OK;
|
||||
}
|
||||
|
||||
if (ret != HAL_OK)
|
||||
STA_DEBUG_PRINTF("Address %d is available", i);
|
||||
else
|
||||
STA_DEBUG_PRINTF("Address %d is unavailable", i);
|
||||
void STM32I2C::addressScan()
|
||||
{
|
||||
for(uint8_t i = 1; i < 128; i++)
|
||||
{
|
||||
if (hasAddress(i))
|
||||
{
|
||||
STA_DEBUG_PRINTF("Address %d exists", i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -134,7 +141,9 @@ namespace sta
|
||||
/* The address is bit-shifted by one to work properly for the STM32 HAL. */
|
||||
: I2CDevice(intf, address << 1, master, blocking)
|
||||
{
|
||||
|
||||
intf->acquire();
|
||||
STA_ASSERT(intf->hasAddress(address));
|
||||
intf->release();
|
||||
}
|
||||
|
||||
} // namespace sta
|
||||
|
Loading…
x
Reference in New Issue
Block a user