Skip to content

Commit 620f7b1

Browse files
committed
Set link to example code (examples NFC, network, storage)
1 parent 3934019 commit 620f7b1

File tree

8 files changed

+8
-257
lines changed

8 files changed

+8
-257
lines changed

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/storage/BufferedBlockDevice.md

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,7 @@ To configure this class, please see our [BlockDevice configuration documentation
1818

1919
This BufferedBlockDevice example takes a [HeapBlockDevice](heapblockdevice.html), whose read size is 256 bytes and program size is 512 bytes, and shows how one can read or program this block device with much smaller read/program sizes, using BufferedBlockDevice.
2020

21-
```C++ TODO
22-
23-
HeapBlockDevice heap_bd(1024, 256, 512, 512);
24-
BufferedBlockDevice buf_bd(&heap_bd);
25-
26-
// This initializes the buffered block device (as well as the underlying heap block device)
27-
int err = buf_bd.init();
28-
29-
uint8_t buf[8];
30-
for (int i = 0; i < sizeof(buf); i++) {
31-
buf[i] = i;
32-
}
33-
34-
// Now we can program an 8 byte buffer (couldn't do that in underlying BD, having 512-byte program size)
35-
err = buf_bd.program(buf, 0, sizeof(buf));
36-
37-
// Now we can also read one byte
38-
err = buf_bd.read(buf, 0, 1);
39-
40-
// Ensure programmed data is flushed to the underlying block device
41-
err = buf_bd.sync();
42-
```
21+
[![View code](https://www.mbed.com/embed/?url=https://github.com/ARMmbed/mbed-os-examples-docs_only/blob/master/APIs_Storage/BufferedBlockDevice)](https://github.com/ARMmbed/mbed-os-examples-docs_only/blob/master/APIs_Storage/BufferedBlockDevice/main.cpp)
4322

4423
## Related content
4524

docs/api/storage/DataFlashBlockDevice.md

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -18,41 +18,7 @@ To configure this class, please see our [BlockDevice configuration documentation
1818

1919
## DataFlashBlockDevice example
2020

21-
``` cpp TODO
22-
// Here's an example using the AT45DB on the K64F
23-
#include "mbed.h"
24-
#include "DataFlashBlockDevice.h"
25-
26-
// Create DataFlash on SPI bus with PTE5 as chip select
27-
DataFlashBlockDevice dataflash(PTE2, PTE4, PTE1, PTE5);
28-
29-
// Create DataFlash on SPI bus with PTE6 as write-protect
30-
DataFlashBlockDevice dataflash2(PTE2, PTE4, PTE1, PTE5, PTE6);
31-
32-
int main() {
33-
printf("dataflash test\n");
34-
35-
// Initialize the SPI flash device and print the memory layout
36-
dataflash.init();
37-
printf("dataflash size: %llu\n", dataflash.size());
38-
printf("dataflash read size: %llu\n", dataflash.get_read_size());
39-
printf("dataflash program size: %llu\n", dataflash.get_program_size());
40-
printf("dataflash erase size: %llu\n", dataflash.get_erase_size());
41-
42-
// Write "Hello World!" to the first block
43-
char *buffer = (char*)malloc(dataflash.get_erase_size());
44-
sprintf(buffer, "Hello World!\n");
45-
dataflash.erase(0, dataflash.get_erase_size());
46-
dataflash.program(buffer, 0, dataflash.get_erase_size());
47-
48-
// Read back what was stored
49-
dataflash.read(buffer, 0, dataflash.get_erase_size());
50-
printf("%s", buffer);
51-
52-
// Deinitialize the device
53-
dataflash.deinit();
54-
}
55-
```
21+
[![View code](https://www.mbed.com/embed/?url=https://github.com/ARMmbed/mbed-os-examples-docs_only/blob/master/APIs_Storage/DataFlashBlockDevice)](https://github.com/ARMmbed/mbed-os-examples-docs_only/blob/master/APIs_Storage/DataFlashBlockDevice/main.cpp)
5622

5723
## Related content
5824

docs/api/storage/FlashSimBlockDevice.md

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,7 @@ To configure this class, please see our [BlockDevice configuration documentation
2323

2424
This FlashSimBlockDevice example takes a [HeapBlockDevice](heapblockdevice.html) and turns it into a simulated flash BD.
2525

26-
```C++ TODO
27-
int erase_unit_size = 512;
28-
HeapBlockDevice heap_bd(4 * erase_unit_size, 1, 4, erase_unit_size);
29-
FlashSimBlockDevice flash_bd(&heap_bd, blank);
30-
31-
// This initializes the flash simulator block device (as well as the underlying heap block device)
32-
int err = flash_bd.init();
33-
34-
uint8_t buf[16];
35-
for (int i = 0; i < sizeof(buf); i++) {
36-
buf[i] = i;
37-
}
38-
39-
// This will fail, as erase unit in address 0 has not been erased
40-
err = flash_bd.program(buf, 0, sizeof(buf));
41-
42-
// Erase the erase unit at address 0
43-
err = flash_bd.erase(0, erase_unit_size);
44-
45-
// This will succeed now after erasing
46-
err = flash_bd.program(buf, 0, sizeof(buf));
47-
```
26+
[![View code](https://www.mbed.com/embed/?url=https://github.com/ARMmbed/mbed-os-examples-docs_only/blob/master/APIs_Storage/FlashSimBlockDevice)](https://github.com/ARMmbed/mbed-os-examples-docs_only/blob/master/APIs_Storage/FlashSimBlockDevice/main.cpp)
4827

4928
## Related content
5029

0 commit comments

Comments
 (0)