Skip to content

Commit ccf5af2

Browse files
author
Amanda Butler
authored
Merge pull request #1258 from mprse/update_examples
Update links to examples
2 parents 4695453 + 6b36a22 commit ccf5af2

21 files changed

+27
-546
lines changed

docs/api/io/I2CSlave.md

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,36 +12,4 @@ Synchronization level: not protected.
1212

1313
Try this example to see how an I2C responder works.
1414

15-
```c++ TODO
16-
#include <mbed.h>
17-
18-
#if !DEVICE_I2CSLAVE
19-
#error [NOT_SUPPORTED] I2C Slave is not supported
20-
#endif
21-
22-
I2CSlave slave(p9, p10);
23-
24-
int main() {
25-
char buf[10];
26-
char msg[] = "Slave!";
27-
28-
slave.address(0xA0);
29-
while (1) {
30-
int i = slave.receive();
31-
switch (i) {
32-
case I2CSlave::ReadAddressed:
33-
slave.write(msg, strlen(msg) + 1); // Includes null char
34-
break;
35-
case I2CSlave::WriteGeneral:
36-
slave.read(buf, 10);
37-
printf("Read G: %s\n", buf);
38-
break;
39-
case I2CSlave::WriteAddressed:
40-
slave.read(buf, 10);
41-
printf("Read A: %s\n", buf);
42-
break;
43-
}
44-
for(int i = 0; i < 10; i++) buf[i] = 0; // Clear buffer
45-
}
46-
}
47-
```
15+
[![View code](https://www.mbed.com/embed/?url=https://github.com/ARMmbed/mbed-os-examples-docs_only/blob/master/APIs_Drivers/I2CSlave)](https://github.com/ARMmbed/mbed-os-examples-docs_only/blob/master/APIs_Drivers/I2CSlave/main.cpp)

docs/api/io/SPI.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ The SPI master generates a clock to synchronously drive a serial bit stream slav
3131

3232
The following example uses the WHOAMI register. The WHOAMI register is an ID register of the slave device. In other words, it's just an example that you can write to a slave's register. In this example, Mbed OS acts as the SPI master, and DigitalOut acts as the slave chip select (cs).
3333

34-
[![View code](https://www.mbed.com/embed/?url=https://github.com/ARMmbed/mbed-os-examples-docs_only/blob/master/APIs_Drivers/SPI_HelloWorld)](https://github.com/ARMmbed/mbed-os-examples-docs_only/blob/master/APIs_Drivers/SPI_HelloWorld/main.cpp)
34+
[![View code](https://www.mbed.com/embed/?url=https://github.com/ARMmbed/mbed-os-examples-docs_only/blob/master/APIs_Drivers/SPI_HelloWorld/)](https://github.com/ARMmbed/mbed-os-examples-docs_only/blob/master/APIs_Drivers/SPI_HelloWorld/main.cpp)

docs/api/io/SPISlave.md

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,4 @@ The default format is set to 8 bits, mode 0 and a clock frequency of 1MHz. Synch
1212

1313
## SPISlave example
1414

15-
Reply to a SPI master as slave:
16-
17-
```c++
18-
#include "mbed.h"
19-
20-
SPISlave device(D9, D11, D12, D13); // mosi, miso, sclk, ssel
21-
22-
int main() {
23-
device.reply(0x00); // Prime SPI with first reply
24-
while(1) {
25-
if(device.receive()) {
26-
int v = device.read(); // Read byte from master
27-
v = (v + 1) % 0x100; // Add one to it, modulo 256
28-
device.reply(v); // Make this the next reply
29-
}
30-
}
31-
}
32-
```
15+
[![View code](https://www.mbed.com/embed/?url=https://github.com/ARMmbed/mbed-os-examples-docs_only/blob/master/APIs_Drivers/SPISlave)](https://github.com/ARMmbed/mbed-os-examples-docs_only/blob/master/APIs_Drivers/SPISlave/main.cpp)

docs/api/networkinterfaces/CellularInterface.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ To bring up the network interface:
6565

6666
This example establishes connection with the cellular network using Mbed OS CellularInterface.
6767

68-
[![View code](https://www.mbed.com/embed/?url=https://github.com/ARMmbed/mbed-os-example-cellular)](https://github.com/ARMmbed/mbed-os-example-cellular/blob/mbed-os-5.15/main.cpp)
68+
69+
[![View code](https://www.mbed.com/embed/?url=https://github.com/ARMmbed/mbed-os-example-cellular)](https://github.com/ARMmbed/mbed-os-example-cellular/blob/master/main.cpp)
6970

7071
## Related content
7172

docs/api/networksocket/CellularNonIPSocket.md

Lines changed: 1 addition & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -34,59 +34,4 @@ You can request Control Plane optimization mode either with CellularDevice's [`c
3434

3535
The following code demonstrates how to create and use a cellular non-IP socket:
3636

37-
```
38-
39-
#include "mbed.h"
40-
#include "CellularNonIPSocket.h"
41-
#include "CellularDevice.h"
42-
43-
// Network interface
44-
NetworkInterface *iface;
45-
46-
int main() {
47-
// Bring up the cellular interface
48-
iface = CellularContext::get_default_nonip_instance();
49-
MBED_ASSERT(iface);
50-
51-
// sim pin, apn, credentials and possible plmn are taken automatically from json when using NetworkInterface::set_default_parameters()
52-
iface->set_default_parameters();
53-
54-
printf("Cellular Non-IP Socket example\n");
55-
if(NSAPI_ERROR_OK != iface->connect() || NSAPI_STATUS_GLOBAL_UP != iface->get_connection_status()) {
56-
printf("Error connecting\n");
57-
return -1;
58-
}
59-
60-
CellularNonIPSocket sock;
61-
62-
nsapi_error_t retcode = sock.open((CellularContext*)iface);
63-
64-
if (retcode != NSAPI_ERROR_OK) {
65-
printf("CellularNonIPSocket.open() fails, code: %d\n", retcode);
66-
return -1;
67-
}
68-
69-
const char *send_string = "TEST";
70-
71-
if(0 > sock.send((void*) send_string, sizeof(send_string))) {
72-
printf("Error sending data\n");
73-
return -1;
74-
}
75-
76-
printf("Success sending data\n");
77-
78-
char recv_buf[4];
79-
if(0 > sock.recv((void *)recv_buf, sizeof(recv_buf))) {
80-
printf("Error receiving data\n");
81-
return -1;
82-
}
83-
84-
printf("Success receiving data\n");
85-
86-
// Close the socket and bring down the network interface
87-
sock.close();
88-
iface->disconnect();
89-
return 0;
90-
}
91-
92-
```
37+
[![View code](https://www.mbed.com/embed/?url=https://github.com/ARMmbed/mbed-os-examples-docs_only/blob/master/APIs_networksocket/CellularNonIPSocket)](https://github.com/ARMmbed/mbed-os-examples-docs_only/blob/master/APIs_networksocket/CellularNonIPSocket/main.cpp)

docs/api/nfc/MessageBuilder.md

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,7 @@ Mbed OS provides this API to construct NDEF messages, the common data format exc
88

99
## MessageBuilder example
1010

11-
```
12-
#include "nfc/ndef/MessageBuilder.h"
13-
14-
using mbed::nfc::ndef::MessageBuilder;
15-
using mbed::nfc::ndef::common::Text;
16-
using mbed::nfc::ndef::common::URI;
17-
18-
size_t build_ndef_message(const Span<uint8_t> &buffer) {
19-
MessageBuilder builder(buffer);
20-
21-
URI uri(URI::HTTPS_WWW, span_from_cstr("mbed.com"));
22-
Text text(Text::UTF8, span_from_cstr("en-US"), span_from_cstr("Mbed website"));
23-
24-
uri.append_as_record(builder);
25-
text.append_as_record(builder, /* last record */ true);
26-
27-
return builder.get_message().size();
28-
}
29-
```
11+
[![View code](https://www.mbed.com/embed/?url=https://github.com/ARMmbed/mbed-os-examples-docs_only/blob/master/APIs_NFC/MessageBuilder)](https://github.com/ARMmbed/mbed-os-examples-docs_only/blob/master/APIs_NFC/MessageBuilder/main.cpp)
3012

3113
## Related content
3214

docs/api/nfc/NFCController.md

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,7 @@ To use an NFC controller, you must initiate the instance with a driver instance,
1212

1313
## NFCController example
1414

15-
```cpp TODO
16-
#include "stdint.h"
17-
18-
#include "NFC.h"
19-
#include "events/EventQueue.h"
20-
#include "nfc/controllers/PN512Driver.h"
21-
#include "nfc/controllers/PN512SPITransportDriver.h"
22-
23-
static uint8_t ndef_buffer[1024] = {0};
24-
25-
int main() {
26-
mbed::nfc::PN512SPITransportDriver pn512_transport(D11, D12, D13, D10, A1, A0);
27-
mbed::nfc::PN512Driver pn512_driver(&pn512_transport);
28-
events::EventQueue queue;
29-
mbed::nfc::NFCController nfc(&pn512_driver, &queue, ndef_buffer);
30-
31-
...
32-
}
33-
```
15+
[![View code](https://www.mbed.com/embed/?url=https://github.com/ARMmbed/mbed-os-examples-docs_only/blob/master/APIs_NFC/NFCController)](https://github.com/ARMmbed/mbed-os-examples-docs_only/blob/master/APIs_NFC/NFCController/main.cpp)
3416

3517
A delegate mechanism handles events throughout the API.
3618

docs/api/nfc/NFCEEPROM.md

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,7 @@ To use an NFC EEPROM, you must initiate the instance with a driver instance, an
1212

1313
## NFCEEPROM example
1414

15-
```cpp TODO
16-
#include "stdint.h"
17-
18-
#include "NFC.h"
19-
#include "events/EventQueue.h"
20-
#include "m24sr_driver.h"
21-
22-
static uint8_t ndef_buffer[1024] = {0};
23-
24-
int main() {
25-
mbed::nfc::vendor::ST::M24srDriver m24sr_driver(p10, p11);
26-
events::EventQueue queue;
27-
mbed::nfc::NFCEEPROM nfc(&m24sr_driver, &queue, ndef_buffer);
28-
29-
...
30-
nfc.write_ndef_message();
31-
}
32-
```
15+
[![View code](https://www.mbed.com/embed/?url=https://github.com/ARMmbed/mbed-os-examples-docs_only/blob/master/APIs_NFC/NFC_EEPROM)](https://github.com/ARMmbed/mbed-os-examples-docs_only/blob/master/APIs_NFC/NFC_EEPROM/main.cpp)
3316

3417
## Related content
3518

docs/api/nfc/SimpleMessageParser.md

Lines changed: 1 addition & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -10,72 +10,7 @@ The SimpleMessageParser class is a more integrated parser than the MessageParser
1010

1111
## SimpleMessageParser example
1212

13-
```
14-
#include "nfc/ndef/common/SimpleMessageParser.h"
15-
16-
using mbed::nfc::ndef::Record;
17-
using mbed::nfc::ndef::RecordType;
18-
using mbed::nfc::ndef::RecordID;
19-
using mbed::nfc::ndef::MessageParser;
20-
using mbed::nfc::ndef::common::Text;
21-
using mbed::nfc::ndef::common::URI;
22-
using mbed::nfc::ndef::common::Mime;
23-
24-
using mbed::nfc::ndef::common::SimpleMessageParser;
25-
26-
void parse_ndef_message(const Span<const uint8_t> &buffer) {
27-
SimpleMessageParser parser;
28-
struct : SimpleMessageParser::Delegate {
29-
virtual void on_parsing_started() {
30-
printf("parsing started\r\n");
31-
}
32-
33-
virtual void on_text_parsed(const Text &text, const RecordID &) {
34-
printf("Text record parsed.\r\n");
35-
printf(
36-
"\tlanguage: %.*s\r\n",
37-
text.get_language_code().size(), text.get_language_code().data()
38-
);
39-
printf("\ttext: %.*s\r\n", text.get_text().size(), text.get_text().data());
40-
}
41-
42-
virtual void on_uri_parsed(const URI &uri, const RecordID &) {
43-
printf("URI parsed.\r\n");
44-
printf("\tid: %d\r\n", uri.get_id());
45-
printf("\tvalue: %.*s\r\n", uri.get_uri_field().size(), uri.get_uri_field().data());
46-
}
47-
48-
virtual void on_mime_parsed(const Mime &mime, const RecordID &) {
49-
printf("Mime object parsed.\r\n");
50-
printf("\ttype: %.*s\r\n", mime.get_mime_type().size(), mime.get_mime_type().data());
51-
printf("\tcontent size: %d\r\n", mime.get_mime_content().size());
52-
}
53-
54-
virtual void on_unknown_record_parsed(const Record &record) {
55-
printf("Unknown record parsed.\r\n");
56-
printf(
57-
"\ttype: %d, type_value: %.*s\r\n",
58-
record.type.tnf, record.type.value.size(), record.type.value.data()
59-
);
60-
printf(
61-
"\tpayload size: %d, payload: %.*s\r\n",
62-
record.payload.size(), record.payload.size(), record.payload.data()
63-
);
64-
}
65-
66-
virtual void on_parsing_terminated() {
67-
printf("parsing terminated\r\n");
68-
}
69-
70-
virtual void on_parsing_error(MessageParser::error_t error) {
71-
printf("Parsing error: %d\r\n", error);
72-
}
73-
} delegate;
74-
75-
parser.set_delegate(&delegate);
76-
parser.parse(buffer);
77-
}
78-
```
13+
[![View code](https://www.mbed.com/embed/?url=https://github.com/ARMmbed/mbed-os-examples-docs_only/blob/master/APIs_NFC/SimpleMessageParser)](https://github.com/ARMmbed/mbed-os-examples-docs_only/blob/master/APIs_NFC/SimpleMessageParser/main.cpp)
7914

8015
An application can extend capabilities of `SimpleMessageParser` by adding new record parsers (`mbed::nfc::ndef::RecordParser`) at runtime.
8116

docs/api/platform/Callback.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,4 @@ The Callback API provides a convenient way to pass arguments to spawned threads.
4545

4646
Here is an example that uses everything discussed in the [introduction to callbacks](platform.html#callbacks) document in the form of a minimal Sonar class. This example uses a C++ class and method in the Callback.
4747

48-
[![View code](https://www.mbed.com/embed/?url=https://os.mbed.com/teams/mbed_example/code/callback-sonar-example/)](https://os.mbed.com/teams/mbed_example/code/callback-sonar-example/file/1713cdc51510/main.cpp)
48+
[![View code](https://www.mbed.com/embed/?url=github.com/ARMmbed/mbed-os-examples-docs_only/blob/master/APIs_RTOS/Sonar/)](github.com/ARMmbed/mbed-os-examples-docs_only/blob/master/APIs_RTOS/Sonar/main.cpp)

docs/api/platform/FileHandle.md

Lines changed: 2 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -185,84 +185,11 @@ As such, you can only use `Stream`-based devices for blocking I/O, such as throu
185185

186186
## FileHandle using C library example
187187

188-
```
189-
// Continuously monitor a serial device, and every time it outputs a
190-
// character, send it to the console and toggle LED2. Can use the C library
191-
// to access the device as only using blocking I/O.
192-
//
193-
// Note that the console is accessed using putchar - this will be accessing
194-
// a FileHandle-based device under the surface, but the particular device can be
195-
// target-dependent. This makes the program portable to different devices
196-
// with different console types, with the only target-dependence being
197-
// knowledge of which pins the serial device we're monitoring is attached to,
198-
// which can be configured using JSON.
199-
200-
static DigitalOut led2(LED2);
201-
202-
// UARTSerial derives from FileHandle
203-
static UARTSerial device(MBED_CONF_APP_DEVICE_TX, MBED_CONF_APP_DEVICE_RX);
204-
205-
int main()
206-
{
207-
// Perform device-specific setup
208-
device.set_baud(19200);
209-
210-
// Once set up, access through the C library
211-
FILE *devin = fdopen(&device, "r");
212-
213-
while (1) {
214-
putchar(fgetc(devin));
215-
led2 = !led2;
216-
}
217-
}
218-
```
188+
[![View code](https://www.mbed.com/embed/?url=https://github.com/ARMmbed/mbed-os-examples-docs_only/blob/master/APIs_Platform/FileHandle)](https://github.com/ARMmbed/mbed-os-examples-docs_only/blob/master/APIs_Platform/FileHandle/main.cpp)
219189

220190
## FileHandle sigio example
221191

222-
```
223-
// Main thread flashes LED1, while we monitor a serial-attached device
224-
// in the background. Every time that device outputs a character, we echo
225-
// it to the console and toggle LED2.
226-
#include "mbed.h"
227-
228-
static DigitalOut led1(LED1);
229-
static DigitalOut led2(LED2);
230-
231-
static UARTSerial device(MBED_CONF_APP_DEVICE_TX, MBED_CONF_APP_DEVICE_RX);
232-
233-
static void callback_ex()
234-
{
235-
// always read until data is exhausted - we may not get another
236-
// sigio otherwise
237-
while (1) {
238-
char c;
239-
if (device.read(&c, 1) != 1) {
240-
break;
241-
}
242-
putchar(c);
243-
led2 = !led2;
244-
}
245-
}
246-
247-
int main()
248-
{
249-
// UARTSerial-specific method - all others are from FileHandle base class
250-
device.set_baud(19200);
251-
252-
// Ensure that device.read() returns -EAGAIN when out of data
253-
device.set_blocking(false);
254-
255-
// sigio callback is deferred to event queue, as we cannot in general
256-
// perform read() calls directly from the sigio() callback.
257-
device.sigio(mbed_event_queue()->event(callback_ex));
258-
259-
while (1) {
260-
led1 = !led1;
261-
wait(0.5);
262-
}
263-
}
264-
265-
```
192+
[![View code](https://www.mbed.com/embed/?url=https://github.com/ARMmbed/mbed-os-examples-docs_only/blob/master/APIs_Platform/FileHandle_sigio)](https://github.com/ARMmbed/mbed-os-examples-docs_only/blob/master/APIs_Platform/FileHandle_sigio/main.cpp)
266193

267194
## Related content
268195

0 commit comments

Comments
 (0)