Skip to content

Commit

Permalink
Reimplement register and buffer operations
Browse files Browse the repository at this point in the history
  • Loading branch information
rasmuskleist committed Aug 7, 2023
1 parent 9889b0b commit 8179386
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions src/modm/driver/radio/sx128x_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,13 @@ template < class Transport, class Reset, class Busy >
modm::ResumableResult<bool>
Sx128x< Transport, Reset, Busy >::writeRegister(Register reg, std::span<const uint8_t> data)
{
uint16_t varg = modm::toBigEndian(i(reg));
Command command(Opcode::WriteRegister, std::span{(uint8_t *) &varg, sizeof(varg)});

RF_BEGIN();

buffer[0] = (i(reg) >> 8) & 0xFF;
buffer[1] = i(reg) & 0xFF;
RF_WAIT_WHILE(isBusy());

RF_END_RETURN_CALL(this->writeCommand(command, data));
RF_END_RETURN_CALL(this->writeCommand(Command(Opcode::WriteRegister, std::span{buffer, 2}), data));
}

// -----------------------------------------------------------------------------
Expand All @@ -98,14 +97,13 @@ template < class Transport, class Reset, class Busy >
modm::ResumableResult<bool>
Sx128x< Transport, Reset, Busy >::readRegister(Register reg, std::span<uint8_t> data)
{
uint16_t varg = modm::toBigEndian(i(reg));
Command command(Opcode::ReadRegister, std::span{(uint8_t *) &varg, sizeof(varg)});

RF_BEGIN();

buffer[0] = (i(reg) >> 8) & 0xFF;
buffer[1] = i(reg) & 0xFF;
RF_WAIT_WHILE(isBusy());

RF_END_RETURN_CALL(this->readCommand(command, data));
RF_END_RETURN_CALL(this->readCommand(Command(Opcode::ReadRegister, std::span{buffer, 2}), data));
}

// -----------------------------------------------------------------------------
Expand All @@ -114,13 +112,12 @@ template < class Transport, class Reset, class Busy >
modm::ResumableResult<bool>
Sx128x< Transport, Reset, Busy >::writeBuffer(uint8_t offset, std::span<const uint8_t> data)
{
Command command(Opcode::WriteBuffer, std::span{(uint8_t *) &offset, sizeof(offset)});

RF_BEGIN();

buffer[0] = offset;
RF_WAIT_WHILE(isBusy());

RF_END_RETURN_CALL(this->writeCommand(command, data));
RF_END_RETURN_CALL(this->writeCommand(Command(Opcode::WriteBuffer, std::span{buffer, 1}), data));
}

// -----------------------------------------------------------------------------
Expand All @@ -129,13 +126,12 @@ template < class Transport, class Reset, class Busy >
modm::ResumableResult<bool>
Sx128x< Transport, Reset, Busy >::readBuffer(uint8_t offset, std::span<uint8_t> data)
{
Command command(Opcode::ReadBuffer, std::span{(uint8_t *) &offset, sizeof(offset)});

RF_BEGIN();

buffer[0] = offset;
RF_WAIT_WHILE(isBusy());

RF_END_RETURN_CALL(this->readCommand(command, data));
RF_END_RETURN_CALL(this->readCommand(Command(Opcode::ReadBuffer, std::span{buffer, 1}), data));
}

// -----------------------------------------------------------------------------
Expand Down

0 comments on commit 8179386

Please sign in to comment.