Skip to content

Commit 2867b18

Browse files
author
Kimmo Vaisanen
committed
Lora: Replace deprecated methods with new ones in Semtech drivers
1 parent 68beebf commit 2867b18

File tree

3 files changed

+47
-38
lines changed

3 files changed

+47
-38
lines changed

SX126X/SX126X_LoRaRadio.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ SPDX-License-Identifier: BSD-3-Clause
2323
*/
2424

2525
#include <math.h>
26+
#include "ThisThread.h"
2627
#include "mbed_wait_api.h"
2728
#include "Timer.h"
2829
#include "SX126X_LoRaRadio.h"
@@ -34,8 +35,9 @@ SPDX-License-Identifier: BSD-3-Clause
3435
#endif
3536

3637
using namespace mbed;
37-
#ifdef MBED_CONF_RTOS_PRESENT
3838
using namespace rtos;
39+
40+
#ifdef MBED_CONF_RTOS_PRESENT
3941
/**
4042
* Signals
4143
*/
@@ -202,7 +204,7 @@ bool SX126X_LoRaRadio::perform_carrier_sense(radio_modems_t modem,
202204
receive();
203205

204206
// hold on a bit, radio turn-around time
205-
wait_ms(1);
207+
ThisThread::sleep_for(1);
206208

207209
Timer elapsed_time;
208210
elapsed_time.start();
@@ -503,10 +505,10 @@ void SX126X_LoRaRadio::radio_reset()
503505
_reset_ctl.output();
504506
_reset_ctl = 0;
505507
// should be enough, required is 50-100 us
506-
wait_ms(2);
508+
ThisThread::sleep_for(2);
507509
_reset_ctl.input();
508510
// give some time for automatic image calibration
509-
wait_ms(6);
511+
ThisThread::sleep_for(6);
510512
}
511513

512514
void SX126X_LoRaRadio::wakeup()
@@ -540,7 +542,7 @@ void SX126X_LoRaRadio::sleep(void)
540542
#endif
541543

542544
write_opmode_command(RADIO_SET_SLEEP, &sleep_state, 1);
543-
wait_ms(2);
545+
ThisThread::sleep_for(2);
544546
}
545547

546548
uint32_t SX126X_LoRaRadio::random(void)
@@ -552,7 +554,7 @@ uint32_t SX126X_LoRaRadio::random(void)
552554
_reception_mode = RECEPTION_MODE_OTHER;
553555
_rx_timeout = 0xFFFFFFFF;
554556
receive();
555-
wait_ms(1);
557+
ThisThread::sleep_for(1);
556558
read_register(RANDOM_NUMBER_GENERATORBASEADDR, buf, 4);
557559
standby();
558560

SX1272/SX1272_LoRaRadio.cpp

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,20 @@ Copyright (c) 2017, Arm Limited and affiliates.
2323
SPDX-License-Identifier: BSD-3-Clause
2424
*/
2525

26-
#include <stdio.h>
27-
#include <math.h> //rint
28-
#include <string.h>
29-
#include "mbed.h"
30-
3126
#include "SX1272_LoRaRadio.h"
3227
#include "sx1272Regs-Fsk.h"
3328
#include "sx1272Regs-LoRa.h"
3429

30+
#include "rtos/ThisThread.h"
31+
#include "platform/Callback.h"
32+
#include "drivers/Timer.h"
33+
#include "platform/mbed_wait_api.h"
34+
35+
#include <math.h> //rint
36+
37+
using namespace mbed;
38+
using namespace rtos;
39+
3540
#ifdef MBED_CONF_SX1272_LORA_DRIVER_SPI_FREQUENCY
3641
#define SPI_FREQUENCY MBED_CONF_SX1272_LORA_DRIVER_SPI_FREQUENCY
3742
#else
@@ -383,9 +388,9 @@ void SX1272_LoRaRadio::radio_reset()
383388
{
384389
_reset_ctl.output();
385390
_reset_ctl = 0;
386-
wait_ms(2);
391+
ThisThread::sleep_for(2);
387392
_reset_ctl.input();
388-
wait_ms(6);
393+
ThisThread::sleep_for(6);
389394
}
390395

391396
/**
@@ -720,7 +725,7 @@ void SX1272_LoRaRadio::send(uint8_t *buffer, uint8_t size)
720725
// FIFO operations can not take place in Sleep mode
721726
if ((read_register(REG_OPMODE) & ~RF_OPMODE_MASK) == RF_OPMODE_SLEEP) {
722727
standby();
723-
wait_ms(1);
728+
ThisThread::sleep_for(1);
724729
}
725730

726731
if (_rf_settings.fsk.fix_len == false) {
@@ -770,7 +775,7 @@ void SX1272_LoRaRadio::send(uint8_t *buffer, uint8_t size)
770775
// FIFO operations can not take place in Sleep mode
771776
if ((read_register(REG_OPMODE) & ~RF_OPMODE_MASK) == RF_OPMODE_SLEEP) {
772777
standby();
773-
wait_ms(1);
778+
ThisThread::sleep_for(1);
774779
}
775780
// write payload buffer
776781
write_fifo(buffer, size);
@@ -1043,7 +1048,7 @@ bool SX1272_LoRaRadio::perform_carrier_sense(radio_modems_t modem,
10431048
set_operation_mode(RF_OPMODE_RECEIVER);
10441049

10451050
// hold on a bit, radio turn-around time
1046-
wait_ms(1);
1051+
ThisThread::sleep_for(1);
10471052

10481053
Timer elapsed_time;
10491054
elapsed_time.start();
@@ -1161,7 +1166,7 @@ uint32_t SX1272_LoRaRadio::random()
11611166
set_operation_mode(RF_OPMODE_RECEIVER);
11621167

11631168
for (i = 0; i < 32; i++) {
1164-
wait_ms(1);
1169+
ThisThread::sleep_for(1);
11651170
// Unfiltered RSSI value reading. Only takes the LSB value
11661171
rnd |= ((uint32_t) read_register(REG_LR_RSSIWIDEBAND) & 0x01) << i;
11671172
}
@@ -1454,14 +1459,14 @@ void SX1272_LoRaRadio::set_sx1272_variant_type()
14541459
{
14551460
if (_rf_ctrls.ant_switch != NC){
14561461
_ant_switch.input();
1457-
wait_ms(1);
1462+
ThisThread::sleep_for(1);
14581463
if (_ant_switch == 1) {
14591464
radio_variant = SX1272MB1DCS;
14601465
} else {
14611466
radio_variant = SX1272MB2XAS;
14621467
}
14631468
_ant_switch.output();
1464-
wait_ms(1);
1469+
ThisThread::sleep_for(1);
14651470
} else {
14661471
radio_variant = MBED_CONF_SX1272_LORA_DRIVER_RADIO_VARIANT;
14671472
}
@@ -1560,8 +1565,9 @@ void SX1272_LoRaRadio::setup_spi()
15601565
// otherwise use default SPI frequency which is 8 MHz
15611566
_spi.frequency(spi_freq);
15621567
#endif
1568+
15631569
// 100 us wait to settle down
1564-
wait(0.1);
1570+
wait_us(100);
15651571
}
15661572

15671573
/**

SX1276/SX1276_LoRaRadio.cpp

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,21 @@ Copyright (c) 2017, Arm Limited and affiliates.
2222
SPDX-License-Identifier: BSD-3-Clause
2323
*/
2424

25-
#include <stdio.h>
26-
#include <math.h> //rint
27-
#include <string.h>
2825
#include "PinNames.h"
29-
#include "Callback.h"
30-
#include "mbed_wait_api.h"
31-
#include "Timer.h"
32-
#ifdef MBED_CONF_RTOS_PRESENT
33-
#include "ThisThread.h"
34-
using namespace rtos;
35-
#endif
26+
#include "platform/Callback.h"
27+
#include "platform/mbed_wait_api.h"
28+
#include "drivers/Timer.h"
29+
#include "rtos/ThisThread.h"
30+
3631
#include "SX1276_LoRaRadio.h"
3732
#include "sx1276Regs-Fsk.h"
3833
#include "sx1276Regs-LoRa.h"
3934

35+
#include <math.h> //rint
36+
37+
using namespace rtos;
38+
using namespace mbed;
39+
4040
/*!
4141
* Sync word for Private LoRa networks
4242
*/
@@ -289,9 +289,9 @@ void SX1276_LoRaRadio::radio_reset()
289289
{
290290
_reset_ctl.output();
291291
_reset_ctl = 0;
292-
wait_ms(2);
292+
ThisThread::sleep_for(2);
293293
_reset_ctl.input();
294-
wait_ms(6);
294+
ThisThread::sleep_for(6);
295295
}
296296

297297
/**
@@ -358,7 +358,7 @@ uint32_t SX1276_LoRaRadio::random( void )
358358
set_operation_mode(RF_OPMODE_RECEIVER);
359359

360360
for (i = 0; i < 32; i++) {
361-
wait_ms(1);
361+
ThisThread::sleep_for(1);
362362
// Unfiltered RSSI value reading. Only takes the LSB value
363363
rnd |= ((uint32_t) read_register( REG_LR_RSSIWIDEBAND) & 0x01) << i;
364364
}
@@ -806,7 +806,7 @@ void SX1276_LoRaRadio::send(uint8_t *buffer, uint8_t size)
806806
// FIFO operations can not take place in Sleep mode
807807
if ((read_register( REG_OPMODE) & ~RF_OPMODE_MASK) == RF_OPMODE_SLEEP) {
808808
standby();
809-
wait_ms(1);
809+
ThisThread::sleep_for(1);
810810
}
811811
// write_to_register payload buffer
812812
write_fifo(buffer, size);
@@ -1026,7 +1026,7 @@ bool SX1276_LoRaRadio::perform_carrier_sense(radio_modems_t modem,
10261026
set_operation_mode(RF_OPMODE_RECEIVER);
10271027

10281028
// hold on a bit, radio turn-around time
1029-
wait_ms(1);
1029+
ThisThread::sleep_for(1);
10301030

10311031
Timer elapsed_time;
10321032
elapsed_time.start();
@@ -1329,14 +1329,14 @@ void SX1276_LoRaRadio::set_sx1276_variant_type()
13291329
{
13301330
if (_rf_ctrls.ant_switch != NC) {
13311331
_ant_switch.input();
1332-
wait_ms(1);
1332+
ThisThread::sleep_for(1);
13331333
if (_ant_switch == 1) {
13341334
radio_variant = SX1276MB1LAS;
13351335
} else {
13361336
radio_variant = SX1276MB1MAS;
13371337
}
13381338
_ant_switch.output();
1339-
wait_ms(1);
1339+
ThisThread::sleep_for(1);
13401340
} else {
13411341
radio_variant = MBED_CONF_SX1276_LORA_DRIVER_RADIO_VARIANT;
13421342
}
@@ -1362,8 +1362,9 @@ void SX1276_LoRaRadio::setup_spi()
13621362
// otherwise use default SPI frequency which is 8 MHz
13631363
_spi.frequency(spi_freq);
13641364
#endif
1365+
13651366
// 100 us wait to settle down
1366-
wait(0.1);
1367+
wait_us(100);
13671368
}
13681369

13691370
/**

0 commit comments

Comments
 (0)