mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/sta-core.git
synced 2025-06-12 01:25:59 +00:00
Added address scan and verification for STM32 I2C
This commit is contained in:
parent
82baae62ad
commit
54a8ecf6c7
@ -25,6 +25,8 @@ namespace sta
|
|||||||
void transfer16(uint16_t value) override;
|
void transfer16(uint16_t value) override;
|
||||||
void transfer(const uint8_t * buffer, size_t size) override;
|
void transfer(const uint8_t * buffer, size_t size) override;
|
||||||
void receive(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 fill(uint8_t value, size_t count) override;
|
||||||
void scanAddresses() override;
|
void scanAddresses() override;
|
||||||
|
@ -2,8 +2,12 @@
|
|||||||
|
|
||||||
#include <sta/debug/debug.hpp>
|
#include <sta/debug/debug.hpp>
|
||||||
#include <sta/debug/assert.hpp>
|
#include <sta/debug/assert.hpp>
|
||||||
|
#include <sta/debug/debug.hpp>
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
|
#include <i2c.h>
|
||||||
|
|
||||||
#ifdef STA_STM32_I2C_ENABLED
|
#ifdef STA_STM32_I2C_ENABLED
|
||||||
|
|
||||||
namespace sta
|
namespace sta
|
||||||
@ -117,16 +121,19 @@ namespace sta
|
|||||||
delete [] buffer;
|
delete [] buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void STM32I2C::scanAddresses()
|
bool STM32I2C::hasAddress(int address)
|
||||||
{
|
{
|
||||||
for (uint8_t i = 0; i < 128; ++i)
|
return HAL_I2C_IsDeviceReady(handle_, (uint16_t)(address << 1), 3, 5) == HAL_OK;
|
||||||
{
|
}
|
||||||
uint8_t ret = HAL_I2C_IsDeviceReady(handle_, (uint16_t)(i << 1), 3, 5);
|
|
||||||
|
|
||||||
if (ret != HAL_OK)
|
void STM32I2C::addressScan()
|
||||||
STA_DEBUG_PRINTF("Address %d is available", i);
|
{
|
||||||
else
|
for(uint8_t i = 1; i < 128; i++)
|
||||||
STA_DEBUG_PRINTF("Address %d is unavailable", 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. */
|
/* 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)
|
||||||
{
|
{
|
||||||
|
intf->acquire();
|
||||||
|
STA_ASSERT(intf->hasAddress(address));
|
||||||
|
intf->release();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace sta
|
} // namespace sta
|
||||||
|
Loading…
x
Reference in New Issue
Block a user