Skip to content

Commit e9d0c6e

Browse files
committed
Add simple logic to some commands
1 parent ad965a2 commit e9d0c6e

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

src/modm/driver/radio/sx128x_impl.hpp

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,16 @@ Sx128x< Transport, Busy >::setTx(PeriodBase periodBase, uint16_t periodBaseCount
166166
{
167167
RF_BEGIN();
168168

169+
// Clear IRQ status before using this command
170+
RF_CALL(clearIrqStatus(Irq_t(0xFF)));
171+
169172
buffer[0] = uint8_t(periodBase);
170173
buffer[1] = (periodBaseCount >> 8) & 0xFF;
171174
buffer[2] = periodBaseCount & 0xFF;
172175
RF_WAIT_WHILE(isBusy());
173176

177+
/// TODO: Determine if ranging role should be set here
178+
174179
RF_END_RETURN_CALL(this->writeCommand(Opcode::SetTx, std::span{buffer, 3}));
175180
}
176181

@@ -182,11 +187,16 @@ Sx128x< Transport, Busy >::setRx(PeriodBase periodBase, uint16_t periodBaseCount
182187
{
183188
RF_BEGIN();
184189

190+
// Clear IRQ status before using this command
191+
RF_CALL(clearIrqStatus(Irq_t(0xFF)));
192+
185193
buffer[0] = uint8_t(periodBase);
186194
buffer[1] = (periodBaseCount >> 8) & 0xFF;
187195
buffer[2] = periodBaseCount & 0xFF;
188196
RF_WAIT_WHILE(isBusy());
189197

198+
/// TODO: Determine if ranging role should be set here
199+
190200
RF_END_RETURN_CALL(this->writeCommand(Opcode::SetRx, std::span{buffer, 3}) );
191201
}
192202

@@ -302,7 +312,8 @@ Sx128x< Transport, Busy >::setTxParams(uint8_t power, RampTime rampTime)
302312
{
303313
RF_BEGIN();
304314

305-
buffer[0] = power;
315+
// Compenstate for offset Pout = 18 – power
316+
buffer[0] = 18 + power;
306317
buffer[1] = uint8_t(rampTime);
307318
RF_WAIT_WHILE(isBusy());
308319

@@ -374,6 +385,8 @@ Sx128x< Transport, Busy >::getRxBufferStatus(RxBufferStatus *rxBufferStatus)
374385

375386
RF_WAIT_WHILE(isBusy());
376387

388+
/// TODO: Determine if logic is different for different packet types
389+
377390
RF_END_RETURN_CALL(this->readCommand(Opcode::GetRxBufferStatus, std::span{(uint8_t *) rxBufferStatus, 2}));
378391
}
379392

@@ -387,6 +400,8 @@ Sx128x< Transport, Busy >::getPacketStatus(PacketStatus *packetStatus)
387400

388401
RF_WAIT_WHILE(isBusy());
389402

403+
/// TODO: Determine if logic is different for different packet types
404+
390405
RF_END_RETURN_CALL(this->readCommand(Opcode::GetPacketStatus, std::span{(uint8_t *) packetStatus, 5}));
391406
}
392407

@@ -509,10 +524,13 @@ template < class Transport, class Busy >
509524
modm::ResumableResult<bool>
510525
Sx128x< Transport, Busy >::setAutoTx(uint16_t time)
511526
{
527+
/// The delay between reception end and transmission start is offset by 33 us
528+
uint16_t delay = time - 33;
529+
512530
RF_BEGIN();
513531

514-
buffer[0] = (time >> 8) & 0xFF;
515-
buffer[1] = time & 0xFF;
532+
buffer[0] = (delay >> 8) & 0xFF;
533+
buffer[1] = delay & 0xFF;
516534
RF_WAIT_WHILE(isBusy());
517535

518536
RF_END_RETURN_CALL(this->writeCommand(Opcode::SetAutoTx, std::span{buffer, 2}));

0 commit comments

Comments
 (0)