mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/sta-core.git
synced 2025-06-14 02:06:00 +00:00
Added address scan and verification for STM32 I2C
This commit is contained in:
parent
7f5d918c96
commit
48cb90c64b
@ -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;
|
||||||
private:
|
private:
|
||||||
|
@ -1,8 +1,12 @@
|
|||||||
#include <sta/devices/stm32/bus/i2c.hpp>
|
#include <sta/devices/stm32/bus/i2c.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
|
||||||
@ -116,11 +120,29 @@ namespace sta
|
|||||||
delete [] buffer;
|
delete [] buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool STM32I2C::hasAddress(int address)
|
||||||
|
{
|
||||||
|
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)
|
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)
|
||||||
{
|
{
|
||||||
|
intf->acquire();
|
||||||
|
STA_ASSERT(intf->hasAddress(address));
|
||||||
|
intf->release();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace sta
|
} // namespace sta
|
||||||
|
Loading…
x
Reference in New Issue
Block a user