Skip to content

Update links to examples #1258

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Mar 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 1 addition & 33 deletions docs/api/io/I2CSlave.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,4 @@ Synchronization level: not protected.

Try this example to see how an I2C responder works.

```c++ TODO
#include <mbed.h>

#if !DEVICE_I2CSLAVE
#error [NOT_SUPPORTED] I2C Slave is not supported
#endif

I2CSlave slave(p9, p10);

int main() {
char buf[10];
char msg[] = "Slave!";

slave.address(0xA0);
while (1) {
int i = slave.receive();
switch (i) {
case I2CSlave::ReadAddressed:
slave.write(msg, strlen(msg) + 1); // Includes null char
break;
case I2CSlave::WriteGeneral:
slave.read(buf, 10);
printf("Read G: %s\n", buf);
break;
case I2CSlave::WriteAddressed:
slave.read(buf, 10);
printf("Read A: %s\n", buf);
break;
}
for(int i = 0; i < 10; i++) buf[i] = 0; // Clear buffer
}
}
```
[![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)
2 changes: 1 addition & 1 deletion docs/api/io/SPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ The SPI master generates a clock to synchronously drive a serial bit stream slav

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).

[![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)
[![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)
19 changes: 1 addition & 18 deletions docs/api/io/SPISlave.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,4 @@ The default format is set to 8 bits, mode 0 and a clock frequency of 1MHz. Synch

## SPISlave example

Reply to a SPI master as slave:

```c++
#include "mbed.h"

SPISlave device(D9, D11, D12, D13); // mosi, miso, sclk, ssel

int main() {
device.reply(0x00); // Prime SPI with first reply
while(1) {
if(device.receive()) {
int v = device.read(); // Read byte from master
v = (v + 1) % 0x100; // Add one to it, modulo 256
device.reply(v); // Make this the next reply
}
}
}
```
[![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)
3 changes: 2 additions & 1 deletion docs/api/networkinterfaces/CellularInterface.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ To bring up the network interface:

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

[![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)

[![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)

## Related content

Expand Down
57 changes: 1 addition & 56 deletions docs/api/networksocket/CellularNonIPSocket.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,59 +34,4 @@ You can request Control Plane optimization mode either with CellularDevice's [`c

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

```

#include "mbed.h"
#include "CellularNonIPSocket.h"
#include "CellularDevice.h"

// Network interface
NetworkInterface *iface;

int main() {
// Bring up the cellular interface
iface = CellularContext::get_default_nonip_instance();
MBED_ASSERT(iface);

// sim pin, apn, credentials and possible plmn are taken automatically from json when using NetworkInterface::set_default_parameters()
iface->set_default_parameters();

printf("Cellular Non-IP Socket example\n");
if(NSAPI_ERROR_OK != iface->connect() || NSAPI_STATUS_GLOBAL_UP != iface->get_connection_status()) {
printf("Error connecting\n");
return -1;
}

CellularNonIPSocket sock;

nsapi_error_t retcode = sock.open((CellularContext*)iface);

if (retcode != NSAPI_ERROR_OK) {
printf("CellularNonIPSocket.open() fails, code: %d\n", retcode);
return -1;
}

const char *send_string = "TEST";

if(0 > sock.send((void*) send_string, sizeof(send_string))) {
printf("Error sending data\n");
return -1;
}

printf("Success sending data\n");

char recv_buf[4];
if(0 > sock.recv((void *)recv_buf, sizeof(recv_buf))) {
printf("Error receiving data\n");
return -1;
}

printf("Success receiving data\n");

// Close the socket and bring down the network interface
sock.close();
iface->disconnect();
return 0;
}

```
[![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)
20 changes: 1 addition & 19 deletions docs/api/nfc/MessageBuilder.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,7 @@ Mbed OS provides this API to construct NDEF messages, the common data format exc

## MessageBuilder example

```
#include "nfc/ndef/MessageBuilder.h"

using mbed::nfc::ndef::MessageBuilder;
using mbed::nfc::ndef::common::Text;
using mbed::nfc::ndef::common::URI;

size_t build_ndef_message(const Span<uint8_t> &buffer) {
MessageBuilder builder(buffer);

URI uri(URI::HTTPS_WWW, span_from_cstr("mbed.com"));
Text text(Text::UTF8, span_from_cstr("en-US"), span_from_cstr("Mbed website"));

uri.append_as_record(builder);
text.append_as_record(builder, /* last record */ true);

return builder.get_message().size();
}
```
[![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)

## Related content

Expand Down
20 changes: 1 addition & 19 deletions docs/api/nfc/NFCController.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,7 @@ To use an NFC controller, you must initiate the instance with a driver instance,

## NFCController example

```cpp TODO
#include "stdint.h"

#include "NFC.h"
#include "events/EventQueue.h"
#include "nfc/controllers/PN512Driver.h"
#include "nfc/controllers/PN512SPITransportDriver.h"

static uint8_t ndef_buffer[1024] = {0};

int main() {
mbed::nfc::PN512SPITransportDriver pn512_transport(D11, D12, D13, D10, A1, A0);
mbed::nfc::PN512Driver pn512_driver(&pn512_transport);
events::EventQueue queue;
mbed::nfc::NFCController nfc(&pn512_driver, &queue, ndef_buffer);

...
}
```
[![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)

A delegate mechanism handles events throughout the API.

Expand Down
19 changes: 1 addition & 18 deletions docs/api/nfc/NFCEEPROM.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,7 @@ To use an NFC EEPROM, you must initiate the instance with a driver instance, an

## NFCEEPROM example

```cpp TODO
#include "stdint.h"

#include "NFC.h"
#include "events/EventQueue.h"
#include "m24sr_driver.h"

static uint8_t ndef_buffer[1024] = {0};

int main() {
mbed::nfc::vendor::ST::M24srDriver m24sr_driver(p10, p11);
events::EventQueue queue;
mbed::nfc::NFCEEPROM nfc(&m24sr_driver, &queue, ndef_buffer);

...
nfc.write_ndef_message();
}
```
[![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)

## Related content

Expand Down
67 changes: 1 addition & 66 deletions docs/api/nfc/SimpleMessageParser.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,72 +10,7 @@ The SimpleMessageParser class is a more integrated parser than the MessageParser

## SimpleMessageParser example

```
#include "nfc/ndef/common/SimpleMessageParser.h"

using mbed::nfc::ndef::Record;
using mbed::nfc::ndef::RecordType;
using mbed::nfc::ndef::RecordID;
using mbed::nfc::ndef::MessageParser;
using mbed::nfc::ndef::common::Text;
using mbed::nfc::ndef::common::URI;
using mbed::nfc::ndef::common::Mime;

using mbed::nfc::ndef::common::SimpleMessageParser;

void parse_ndef_message(const Span<const uint8_t> &buffer) {
SimpleMessageParser parser;
struct : SimpleMessageParser::Delegate {
virtual void on_parsing_started() {
printf("parsing started\r\n");
}

virtual void on_text_parsed(const Text &text, const RecordID &) {
printf("Text record parsed.\r\n");
printf(
"\tlanguage: %.*s\r\n",
text.get_language_code().size(), text.get_language_code().data()
);
printf("\ttext: %.*s\r\n", text.get_text().size(), text.get_text().data());
}

virtual void on_uri_parsed(const URI &uri, const RecordID &) {
printf("URI parsed.\r\n");
printf("\tid: %d\r\n", uri.get_id());
printf("\tvalue: %.*s\r\n", uri.get_uri_field().size(), uri.get_uri_field().data());
}

virtual void on_mime_parsed(const Mime &mime, const RecordID &) {
printf("Mime object parsed.\r\n");
printf("\ttype: %.*s\r\n", mime.get_mime_type().size(), mime.get_mime_type().data());
printf("\tcontent size: %d\r\n", mime.get_mime_content().size());
}

virtual void on_unknown_record_parsed(const Record &record) {
printf("Unknown record parsed.\r\n");
printf(
"\ttype: %d, type_value: %.*s\r\n",
record.type.tnf, record.type.value.size(), record.type.value.data()
);
printf(
"\tpayload size: %d, payload: %.*s\r\n",
record.payload.size(), record.payload.size(), record.payload.data()
);
}

virtual void on_parsing_terminated() {
printf("parsing terminated\r\n");
}

virtual void on_parsing_error(MessageParser::error_t error) {
printf("Parsing error: %d\r\n", error);
}
} delegate;

parser.set_delegate(&delegate);
parser.parse(buffer);
}
```
[![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)

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

Expand Down
2 changes: 1 addition & 1 deletion docs/api/platform/Callback.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ The Callback API provides a convenient way to pass arguments to spawned threads.

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.

[![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)
[![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)
77 changes: 2 additions & 75 deletions docs/api/platform/FileHandle.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,84 +185,11 @@ As such, you can only use `Stream`-based devices for blocking I/O, such as throu

## FileHandle using C library example

```
// Continuously monitor a serial device, and every time it outputs a
// character, send it to the console and toggle LED2. Can use the C library
// to access the device as only using blocking I/O.
//
// Note that the console is accessed using putchar - this will be accessing
// a FileHandle-based device under the surface, but the particular device can be
// target-dependent. This makes the program portable to different devices
// with different console types, with the only target-dependence being
// knowledge of which pins the serial device we're monitoring is attached to,
// which can be configured using JSON.

static DigitalOut led2(LED2);

// UARTSerial derives from FileHandle
static UARTSerial device(MBED_CONF_APP_DEVICE_TX, MBED_CONF_APP_DEVICE_RX);

int main()
{
// Perform device-specific setup
device.set_baud(19200);

// Once set up, access through the C library
FILE *devin = fdopen(&device, "r");

while (1) {
putchar(fgetc(devin));
led2 = !led2;
}
}
```
[![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)

## FileHandle sigio example

```
// Main thread flashes LED1, while we monitor a serial-attached device
// in the background. Every time that device outputs a character, we echo
// it to the console and toggle LED2.
#include "mbed.h"

static DigitalOut led1(LED1);
static DigitalOut led2(LED2);

static UARTSerial device(MBED_CONF_APP_DEVICE_TX, MBED_CONF_APP_DEVICE_RX);

static void callback_ex()
{
// always read until data is exhausted - we may not get another
// sigio otherwise
while (1) {
char c;
if (device.read(&c, 1) != 1) {
break;
}
putchar(c);
led2 = !led2;
}
}

int main()
{
// UARTSerial-specific method - all others are from FileHandle base class
device.set_baud(19200);

// Ensure that device.read() returns -EAGAIN when out of data
device.set_blocking(false);

// sigio callback is deferred to event queue, as we cannot in general
// perform read() calls directly from the sigio() callback.
device.sigio(mbed_event_queue()->event(callback_ex));

while (1) {
led1 = !led1;
wait(0.5);
}
}

```
[![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)

## Related content

Expand Down
Loading