Skip to content

Commit 6887371

Browse files
committed
Update for deprecation of non-Chrono timing APIs
1 parent a7ca7a1 commit 6887371

File tree

64 files changed

+280
-157
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+280
-157
lines changed

APIs_Drivers/AnalogIn_ex_2/main.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
#include "mbed.h"
77

8+
using namespace std::chrono_literals;
9+
810
AnalogIn input(A0);
911

1012
#define NUM_SAMPLES 1024
@@ -15,7 +17,7 @@ int main()
1517

1618
for (int i = 0; i < NUM_SAMPLES; i++) {
1719
samples[i] = input.read_u16();
18-
ThisThread::sleep_for(1);
20+
ThisThread::sleep_for(1ms);
1921
}
2022

2123
printf("Results:\n");

APIs_Drivers/AnalogIn_ex_3/main.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
#include "mbed.h"
77

8+
using namespace std::chrono_literals;
9+
810
// Initialize a pins to perform analog input and digital output functions
911
AnalogIn ain(A0);
1012
DigitalOut dout(LED1);
@@ -24,6 +26,6 @@ int main(void)
2426
// print the percentage and 16 bit normalized values
2527
printf("percentage: %3.3f%%\n", ain.read() * 100.0f);
2628
printf("normalized: 0x%04X \n", ain.read_u16());
27-
ThisThread::sleep_for(200);
29+
ThisThread::sleep_for(200ms);
2830
}
2931
}

APIs_Drivers/AnalogOut_ex_2/main.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
#include "mbed.h"
77

8+
using namespace std::chrono_literals;
9+
810
// Initialize a pins to perform analog and digital output functions
911
// Adjust analog output pin name to your board spec.
1012
AnalogOut aout(A5);
@@ -20,7 +22,7 @@ int main(void)
2022
printf("aout = %1.2f volts\n", aout.read() * 3.3f);
2123
// turn on the led if the voltage is greater than 0.5f * VCC
2224
dout = (aout > 0.5f) ? 1 : 0;
23-
ThisThread::sleep_for(1000);
25+
ThisThread::sleep_for(1s);
2426
}
2527
}
26-
}
28+
}

APIs_Drivers/BusInOut_ex_1/main.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@
55

66
#include "mbed.h"
77

8+
using namespace std::chrono_literals;
9+
810
BusInOut pins(D0, D1, D2); // Change these pins to buttons on your board.
911

1012
int main() {
1113
while(1) {
1214
pins.output();
1315
pins = 0x3;
14-
ThisThread::sleep_for(1000);
16+
ThisThread::sleep_for(1s);
1517
pins.input();
16-
ThisThread::sleep_for(1000);
18+
ThisThread::sleep_for(1s);
1719
if(pins == 0x6) {
1820
printf("Hello!\n");
1921
}

APIs_Drivers/BusIn_ex_1/main.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
#include "mbed.h"
77

8+
using namespace std::chrono_literals;
9+
810
BusIn nibble(D0, D1, D2, D3); // Change these pins to buttons on your board.
911

1012
int main()
@@ -48,6 +50,6 @@ int main()
4850
printf("0b1111, D3,D2,D1,D0 are high \n\r");
4951
break;
5052
}
51-
ThisThread::sleep_for(1000);
53+
ThisThread::sleep_for(1s);
5254
}
5355
}

APIs_Drivers/BusOut_ex_1/main.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@
55

66
#include "mbed.h"
77

8+
using namespace std::chrono_literals;
9+
810
BusOut myleds(LED1, LED2, LED3, LED4);
911

1012
int main()
1113
{
1214
while (1) {
1315
for (int i = 0; i < 16; i++) {
1416
myleds = i;
15-
ThisThread::sleep_for(250);
17+
ThisThread::sleep_for(250ms);
1618
}
1719
}
1820
}

APIs_Drivers/CAN_ex_1/main.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include "mbed.h"
1212

13+
using namespace std::chrono_literals;
1314

1415
Ticker ticker;
1516
DigitalOut led1(LED1);
@@ -43,7 +44,7 @@ int main()
4344
printf("Message received: %d\n", msg.data[0]);
4445
led2 = !led2;
4546
}
46-
ThisThread::sleep_for(200);
47+
ThisThread::sleep_for(200ms);
4748
}
4849
}
4950

APIs_Drivers/DigitalInOut_ex_1/main.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
#include "mbed.h"
77

8+
using namespace std::chrono_literals;
9+
810
DigitalInOut mypin(LED1);
911

1012
int main()
@@ -21,11 +23,11 @@ int main()
2123
// write to pin as output
2224
mypin.output();
2325
mypin = !mypin; // toggle output
24-
ThisThread::sleep_for(500);
26+
ThisThread::sleep_for(500ms);
2527

2628
// read from pin as input
2729
mypin.input();
2830
printf("mypin.read() = %d \n\r", mypin.read());
29-
ThisThread::sleep_for(500);
31+
ThisThread::sleep_for(500ms);
3032
}
3133
}

APIs_Drivers/DigitalIn_ex_1/main.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
#include "mbed.h"
77

8+
using namespace std::chrono_literals;
9+
810
DigitalIn mypin(SW2); // change this to the button on your board
911
DigitalOut myled(LED1);
1012

@@ -22,6 +24,6 @@ int main()
2224
while (1) {
2325
printf("mypin has value : %d \n\r", mypin.read());
2426
myled = mypin; // toggle led based on value of button
25-
ThisThread::sleep_for(250);
27+
ThisThread::sleep_for(250ms);
2628
}
2729
}

APIs_Drivers/DigitalOut_ex_1/main.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
#include "mbed.h"
77

8+
using namespace std::chrono_literals;
9+
810
DigitalOut myled(LED1);
911

1012
int main()
@@ -18,10 +20,10 @@ int main()
1820
while (1) {
1921
myled = 1; // set LED1 pin to high
2022
printf("myled = %d \n\r", (uint8_t)myled);
21-
ThisThread::sleep_for(500);
23+
ThisThread::sleep_for(500ms);
2224

2325
myled.write(0); // set LED1 pin to low
2426
printf("myled = %d \n\r", myled.read());
25-
ThisThread::sleep_for(500);
27+
ThisThread::sleep_for(500ms);
2628
}
2729
}

APIs_Drivers/I2C_ex_1/main.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
#include "mbed.h"
77

8+
using namespace std::chrono_literals;
9+
810
// Read temperature from LM75BD
911

1012
I2C i2c(I2C_SDA, I2C_SCL);
@@ -20,7 +22,7 @@ int main()
2022
cmd[1] = 0x00;
2123
i2c.write(addr8bit, cmd, 2);
2224

23-
ThisThread::sleep_for(500);
25+
ThisThread::sleep_for(500ms);
2426

2527
cmd[0] = 0x00;
2628
i2c.write(addr8bit, cmd, 1);

APIs_Drivers/InterruptIn_ex_1/main.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
#include "mbed.h"
77

8+
using namespace std::chrono_literals;
9+
810
class Counter {
911
public:
1012
Counter(PinName pin) : _interrupt(pin) // create the InterruptIn on the pin specified to Counter
@@ -33,6 +35,6 @@ int main()
3335
{
3436
while (1) {
3537
printf("Count so far: %d\n", counter.read());
36-
ThisThread::sleep_for(2000);
38+
ThisThread::sleep_for(2s);
3739
}
3840
}

APIs_Drivers/InterruptIn_ex_2/main.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
#include "mbed.h"
77

8+
using namespace std::chrono_literals;
9+
810
InterruptIn button(SW2);
911
DigitalOut led(LED1);
1012
DigitalOut flash(LED4);
@@ -19,6 +21,6 @@ int main()
1921
button.rise(&flip); // attach the address of the flip function to the rising edge
2022
while (1) { // wait around, interrupts will interrupt this!
2123
flash = !flash;
22-
ThisThread::sleep_for(250);
24+
ThisThread::sleep_for(250ms);
2325
}
2426
}

APIs_Drivers/PortIn_ex_1/main.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
#include "mbed.h"
77

8+
using namespace std::chrono_literals;
9+
810
// Toggle all four LEDs
911
// LED1 = P1.18 LED2 = P1.20 LED3 = P1.21 LED4 = P1.23
1012
#define LED_MASK 0x00B40000
@@ -17,8 +19,8 @@ int main()
1719
ledport.output();
1820
while (1) {
1921
ledport = LED_MASK;
20-
ThisThread::sleep_for(500);
22+
ThisThread::sleep_for(500ms);
2123
ledport = 0;
22-
ThisThread::sleep_for(1000);
24+
ThisThread::sleep_for(1s);
2325
}
2426
}

APIs_Drivers/PortOut_ex_1/main.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
#include "mbed.h"
77

8+
using namespace std::chrono_literals;
9+
810
// Toggle all four LEDs
911
// LED1 = P1.18 LED2 = P1.20 LED3 = P1.21 LED4 = P1.23
1012
#define LED_MASK 0x00B40000
@@ -15,8 +17,8 @@ int main()
1517
{
1618
while (1) {
1719
ledport = LED_MASK;
18-
ThisThread::sleep_for(1000);
20+
ThisThread::sleep_for(1s);
1921
ledport = 0;
20-
ThisThread::sleep_for(1000);
22+
ThisThread::sleep_for(1s);
2123
}
2224
}

APIs_Drivers/QSPI/main.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include "mbed.h"
2222
#include "drivers/QSPI.h"
2323

24+
using namespace std::chrono_literals;
25+
2426
// For Nordic platforms, use fast read. The QSPI flash memory start address,
2527
// along with the total buffer size, needs to be 4-byte aligned, or divisible by 4.
2628
#if TARGET_NORDIC
@@ -53,7 +55,7 @@ static bool mem_ready()
5355
if (QSPI_STATUS_OK != qspi_device.command_transfer(CMD_RDSR, -1, NULL, 0, status_value, STATUS_REG_SIZE)) {
5456
printf("Reading Status Register failed \n");
5557
}
56-
ThisThread::sleep_for(1);
58+
ThisThread::sleep_for(1ms);
5759
} while ((status_value[0] & BIT_WIP) != 0 && retries);
5860

5961
if ((status_value[0] & BIT_WIP) != 0) {

APIs_Drivers/Ticker_Example/main.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
*/
55
#include "mbed.h"
66

7+
using namespace std::chrono_literals;
8+
79
// A class for flip()-ing a DigitalOut
810
class Flipper {
911
public:
@@ -26,11 +28,11 @@ Ticker t;
2628
int main()
2729
{
2830
// the address of the object, member function, and interval
29-
t.attach(callback(&f, &Flipper::flip), 2.0);
31+
t.attach(callback(&f, &Flipper::flip), 2s);
3032

3133
// spin in a main loop. flipper will interrupt it to call flip
3234
while (1) {
3335
led1 = !led1;
34-
ThisThread::sleep_for(200);
36+
ThisThread::sleep_for(200ms);
3537
}
3638
}

APIs_Drivers/Ticker_HelloWorld/main.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
*/
55
#include "mbed.h"
66

7+
using namespace std::chrono_literals;
8+
79
Ticker flipper;
810
DigitalOut led1(LED1);
911
DigitalOut led2(LED2);
@@ -16,11 +18,11 @@ void flip()
1618
int main()
1719
{
1820
led2 = 1;
19-
flipper.attach(&flip, 2.0); // the address of the function to be attached (flip) and the interval (2 seconds)
21+
flipper.attach(&flip, 2s); // the address of the function to be attached (flip) and the interval (2 seconds)
2022

2123
// spin in a main loop. flipper will interrupt it to call flip
2224
while (1) {
2325
led1 = !led1;
24-
ThisThread::sleep_for(200);
26+
ThisThread::sleep_for(200ms);
2527
}
2628
}

APIs_Drivers/Timeout_Example/main.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
*/
55
#include "mbed.h"
66

7+
using namespace std::chrono_literals;
8+
79
// A class for flip()-ing a DigitalOut
810
class Flipper {
911
public:
@@ -26,11 +28,11 @@ Timeout t;
2628
int main()
2729
{
2830
// the address of the object, member function, and interval
29-
t.attach(callback(&f, &Flipper::flip), 2.0);
31+
t.attach(callback(&f, &Flipper::flip), 2s);
3032

3133
// spin in a main loop. flipper will interrupt it to call flip
3234
while (1) {
3335
led1 = !led1;
34-
ThisThread::sleep_for(200);
36+
ThisThread::sleep_for(200ms);
3537
}
3638
}

APIs_Drivers/Timeout_HelloWorld/main.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
*/
55
#include "mbed.h"
66

7+
using namespace std::chrono_literals;
8+
79
Timeout flipper;
810
DigitalOut led1(LED1);
911
DigitalOut led2(LED2);
@@ -16,11 +18,11 @@ void flip()
1618
int main()
1719
{
1820
led2 = 1;
19-
flipper.attach(&flip, 2.0); // setup flipper to call flip after 2 seconds
21+
flipper.attach(&flip, 2s); // setup flipper to call flip after 2 seconds
2022

2123
// spin in a main loop. flipper will interrupt it to call flip
2224
while (1) {
2325
led1 = !led1;
24-
ThisThread::sleep_for(200);
26+
ThisThread::sleep_for(200ms);
2527
}
2628
}

APIs_Drivers/Timer_HelloWorld/main.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ int main()
1212
t.start();
1313
printf("Hello World!\n");
1414
t.stop();
15-
printf("The time taken was %f seconds\n", t.read());
15+
int us = t.elapsed_time().count();
16+
printf("The time taken was %d microseconds\n", us);
1617
}

0 commit comments

Comments
 (0)