Skip to content

Commit 055c6f2

Browse files
committed
[driver] vl53 fixup
1 parent 752496d commit 055c6f2

File tree

3 files changed

+9
-26
lines changed

3 files changed

+9
-26
lines changed

examples/nucleo_h723zg/vl53/vl53l8_spi/main.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ extern "C" {
2626

2727
using namespace Board;
2828

29-
// using SpiMaster = SpiMaster2_Dma<Dma1::Channel0, Dma1::Channel1>;
30-
using SpiMaster = SpiMaster2;
29+
using SpiMaster = SpiMaster2_Dma<Dma1::Channel0, Dma1::Channel1>;
3130
using Cs = GpioC0;
3231
using Mosi = GpioB15;
3332
using Miso = GpioC2;

ext/vl53/vl53_transport.hpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ class Vl53SpiTransport : public modm::SpiDevice<SpiMaster>, public Vl53Transport
8282
resetSensor() override;
8383

8484
private:
85+
uint8_t addr_buffer[2];
8586
uint8_t rx_buffer[VL53LMZ_COMMS_CHUNK_SIZE + 2];
8687

8788
static uint16_t
@@ -98,23 +99,16 @@ class Vl53SpiTransport : public modm::SpiDevice<SpiMaster>, public Vl53Transport
9899
};
99100

100101
template<typename I2cMaster, typename Lpn>
101-
class Vl53I2cTransport : public modm::I2cDevice<I2cMaster>, public Vl53TransportBase, private I2cEeprom<I2cMaster, 2>
102+
class Vl53I2cTransport : public I2cEeprom<I2cMaster, 2>, public Vl53TransportBase
102103
{
103104
public:
104-
Vl53I2cTransport(const uint8_t address) : I2cDevice<I2cMaster>{address}, I2cEeprom<I2cMaster,2>{address} {};
105+
Vl53I2cTransport(const uint8_t address) : I2cEeprom<I2cMaster,2>{address} {};
105106

106107
Vl53I2cTransport(const Vl53I2cTransport &) = delete;
107108

108109
Vl53I2cTransport &
109110
operator=(const Vl53I2cTransport &) = delete;
110111

111-
void
112-
setAddress(const uint8_t address)
113-
{
114-
I2cEeprom<I2cMaster,2>::transaction.setAddress(address);
115-
I2cDevice<I2cMaster>::transaction.setAddress(address);
116-
};
117-
118112
uint8_t
119113
writeMulti(uint16_t register_address, const uint8_t *p_values, uint32_t size) override;
120114

ext/vl53/vl53_transport_impl.hpp

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ Vl53SpiTransport<SpiMaster, Cs, Lpn, VL53LMZ_COMMS_CHUNK_SIZE>::writeMulti(uint1
4141

4242
const uint16_t temp = RegisterAddress + position;
4343

44-
uint8_t addr_buffer[2];
4544
addr_buffer[0] = SPI_WRITE_MASK(temp) >> 8;
4645
addr_buffer[1] = SPI_WRITE_MASK(temp) & 0xFF;
4746

@@ -82,13 +81,12 @@ Vl53SpiTransport<SpiMaster, Cs, Lpn, VL53LMZ_COMMS_CHUNK_SIZE>::readMulti(uint16
8281
const uint16_t temp = RegisterAddress + position;
8382

8483
uint8_t addr_buffer[2];
85-
addr_buffer[0] = SPI_WRITE_MASK(temp) >> 8;
86-
addr_buffer[1] = SPI_WRITE_MASK(temp) & 0xFF;
84+
addr_buffer[0] = SPI_READ_MASK(temp) >> 8;
85+
addr_buffer[1] = SPI_READ_MASK(temp) & 0xFF;
8786

8887
modm::this_fiber::poll([&] { return this->acquireMaster(); });
8988
Cs::reset();
9089
SpiMaster::transfer(&addr_buffer[0], &rx_buffer[0], data_size + 2);
91-
// SpiMaster::transfer(nullptr, p_values + position, data_size);
9290
if (this->releaseMaster()) { Cs::set(); }
9391

9492
std::memcpy(p_values + position, &rx_buffer[2], data_size);
@@ -126,7 +124,7 @@ Vl53I2cTransport<I2cMaster, Lpn>::readMulti(uint16_t RegisterAddress, uint8_t *p
126124
data_write[0] = (RegisterAddress >> 8) & 0xFF;
127125
data_write[1] = RegisterAddress & 0xFF;
128126

129-
const auto status = I2cDevice<I2cMaster>::writeRead(&data_write[0], 2, p_values, size);
127+
const auto status = this->writeRead(&data_write[0], 2, p_values, size);
130128
return static_cast<uint8_t>(not status);
131129
};
132130

@@ -135,13 +133,11 @@ uint8_t
135133
Vl53I2cTransport<I2cMaster, Lpn>::readByte(uint16_t RegisterAddress, uint8_t *p_value)
136134
{
137135
uint8_t data_write[2];
138-
uint8_t data_read[1];
139136

140137
data_write[0] = (RegisterAddress >> 8) & 0xFF;
141138
data_write[1] = RegisterAddress & 0xFF;
142139

143-
const auto status = I2cDevice<I2cMaster>::writeRead(&data_write[0], 2, &data_read[0], 1);
144-
*p_value = data_read[0];
140+
const auto status = this->writeRead(&data_write[0], 2, p_value, 1);
145141

146142
return static_cast<uint8_t>(not status);
147143
}
@@ -150,13 +146,7 @@ template<typename I2cMaster, typename Lpn>
150146
uint8_t
151147
Vl53I2cTransport<I2cMaster, Lpn>::writeByte(uint16_t RegisterAddress, uint8_t value)
152148
{
153-
uint8_t data_write[3];
154-
155-
data_write[0] = (RegisterAddress >> 8) & 0xFF;
156-
data_write[1] = RegisterAddress & 0xFF;
157-
data_write[2] = value & 0xFF;
158-
159-
const auto status = I2cDevice<I2cMaster>::write(&data_write[0], 3);
149+
const auto status = I2cEeprom<I2cMaster,2>::write(RegisterAddress, &value, 1);
160150
return static_cast<uint8_t>(not status);
161151
}
162152

0 commit comments

Comments
 (0)