Skip to content
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
41 changes: 41 additions & 0 deletions APIs_Platform/Callback_SerialPassthrough/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (c) 2020 Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*/

#include "mbed.h"

static UnbufferedSerial pc(USBTX, USBRX);
static UnbufferedSerial uart(D1, D0);
DigitalOut led1(LED1);
DigitalOut led4(LED4);
char *pc2uart = new char[1];
char *uart2pc = new char[1];

void uart_recv()
{
led1 = !led1;
while (uart.readable()) {
uart.read(uart2pc, sizeof(uart2pc));
pc.write(uart2pc, sizeof(uart2pc));
}
}

void pc_recv()
{
while (pc.readable()) {
led4 = !led4;
pc.read(pc2uart, sizeof(pc2uart));
uart.write(pc2uart, sizeof(pc2uart));
}
}

int main()
{
pc.attach(&pc_recv, UnbufferedSerial::RxIrq);
uart.attach(&uart_recv, UnbufferedSerial::RxIrq);

while (1) {
sleep();
}
}
25 changes: 25 additions & 0 deletions APIs_Platform/PlatfromOverview_Callbacks/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright (c) 2020 Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*/

#include "mbed.h"

// Create a serial object
static UnbufferedSerial serial(USBTX, USBRX);
char *c = new char[1];

// A function that echoes any received data back
void echo()
{
while (serial.readable()) {
serial.read(c, sizeof(c));
serial.write(c, sizeof(c));
}
}

int main(void)
{
// Call our function echo whenever the serial line receives data
serial.attach(&echo, UnbufferedSerial::RxIrq);
}
19 changes: 19 additions & 0 deletions Tutorials_Debugging/DebugPrintf_BlinksLED/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright (c) 2020 Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*/

#include "mbed.h"

DigitalOut led1(LED1);

int main()
{
while (true) {
led1 = !led1;

// Print something over the serial connection
printf("Blink! LED is now %d\r\n", led1.read());
ThisThread::sleep_for(500);
}
}
15 changes: 15 additions & 0 deletions Tutorials_Debugging/DebugPrintf_SetBaudRate/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright (c) 2020 Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*/

#include "mbed.h"

BufferedSerial pc(USBTX, USBRX);

int main()
{
pc.set_baud(9600);
char msg[] = "Hello World!\r\n";
pc.write(msg, sizeof(msg));
}
19 changes: 19 additions & 0 deletions Tutorials_SerialComm/Serial_EchoBack/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright (c) 2006-2020 Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*/

#include "mbed.h"

static BufferedSerial pc(USBTX, USBRX);

int main()
{
char msg[] = "Echoes back to the screen anything you type\n";
char *buff = new char[1];
pc.write(msg, sizeof(msg));
while (1) {
pc.read(buff, sizeof(buff));
pc.write(buff, sizeof(buff));
}
}
15 changes: 15 additions & 0 deletions Tutorials_SerialComm/Serial_HelloWorld/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright (c) 2006-2020 Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*/

#include "mbed.h"

static BufferedSerial pc(USBTX, USBRX); // tx, rx

int main()
{
char msg[] = "Hello World!\n";
pc.write(msg, sizeof(msg));
while (1);
}
32 changes: 32 additions & 0 deletions Tutorials_SerialComm/Serial_LEDControl/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2006-2020 Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*/

#include "mbed.h"

static BufferedSerial pc(USBTX, USBRX); // tx, rx
PwmOut led(LED1);

float brightness = 0.0;

int main()
{
char msg[] = "Press 'u' to turn LED1 brightness up, 'd' to turn it down\n";
char *c = new char[1];
pc.write(msg, sizeof(msg));

while (1) {
pc.read(c, sizeof(c));
pc.write(c, sizeof(c));
if ((*c == 'u') && (brightness < 0.5)) {
brightness += 0.01;
led = brightness;
}
if ((*c == 'd') && (brightness > 0.0)) {
brightness -= 0.01;
led = brightness;
}
}

}
30 changes: 30 additions & 0 deletions Tutorials_SerialComm/Serial_PassCharacters/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2006-2020 Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*/

#include "mbed.h"

static BufferedSerial pc(USBTX, USBRX);
static BufferedSerial uart(D1, D0);

DigitalOut pc_activity(LED1);
DigitalOut uart_activity(LED2);

int main()
{
char *pc2uart = new char[1];
char *uart2pc = new char[1];
while (1) {
if (pc.readable()) {
pc.read(pc2uart, sizeof(pc2uart));
uart.write(pc2uart, sizeof(pc2uart));
pc_activity = !pc_activity;
}
if (uart.readable()) {
uart.read(uart2pc, sizeof(uart2pc));
pc.write(uart2pc, sizeof(uart2pc));
uart_activity = !uart_activity;
}
}
}
21 changes: 21 additions & 0 deletions Tutorials_SerialComm/Serial_ReadToBuffer/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright (c) 2020 Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*/

#include "mbed.h"

// Create a serial object
static BufferedSerial pc(USBTX, USBRX);

int main(void)
{
char buffer[10] = {};
while (1) {
if (pc.readable()) {
ThisThread::sleep_for(100);
pc.read(buffer, 10);
printf("I got '%s'\n", buffer);
}
}
}
12 changes: 12 additions & 0 deletions Tutorials_SerialComm/Serial_STDOUT/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* Copyright (c) 2006-2020 Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*/

#include "mbed.h"

int main()
{
printf("Hello World!\n");
while (1);
}