Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: SerialInterface USBDevice max32625pico
Fork of PICO_USB_I2C_SPI by
main.cpp
- Committer:
- switches
- Date:
- 2016-12-08
- Revision:
- 3:aa55728c8e09
- Parent:
- 2:57500e991166
- Child:
- 5:2436ae0a9eb1
File content as of revision 3:aa55728c8e09:
#include "mbed.h"
#include "max32630fthr.h"
#include "USBSerial.h"
#include "SerialInterface.h"
#define UART_MAX_RESP_LENGTH 255
#define UART_MAX_CMD_LENGTH 255
#define USB_MAX_RESP_LENGTH 255
#define USB_MAX_CMD_LENGTH 255
MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3);
// Hardware serial port over DAPLink
Serial daplink(P2_1, P2_0);
// Virtual serial port over USB
USBSerial microUSB;
// Serial Interface Adapter
SerialInterface serInt;
// Serial Interfaces
I2C i2c(P3_4, P3_5);
SPI spi(P5_1, P5_2, P5_0, P5_3);
// Threads
Thread threadUSB;
Thread threadUART;
DigitalOut rLED(LED1);
DigitalOut gLED(LED2);
DigitalOut bLED(LED3);
void usb_thread()
{
char obuf[USB_MAX_RESP_LENGTH+1];
char ibuf[USB_MAX_CMD_LENGTH+1];
int i = 0;
while(1) {
if (microUSB.readable()) {
ibuf[i]=microUSB.getc();
if (ibuf[i]!='\r') {
if (i < USB_MAX_CMD_LENGTH) {
i += 1;
}
} else {
rLED = LED_ON;
if (i < USB_MAX_CMD_LENGTH) {
ibuf[i]=0;
// microUSB.printf("UART CMD: %s=", ibuf);
serInt.call(ibuf, obuf);
microUSB.printf("%s\r\n", obuf);
} else {
microUSB.printf("[-1]\r\n");
}
i=0;
rLED = LED_OFF;
}
}
}
}
void uart_thread()
{
char obuf[UART_MAX_RESP_LENGTH+1];
char ibuf[UART_MAX_CMD_LENGTH+1];
int i = 0;
while(1) {
if (daplink.readable()) {
ibuf[i]=daplink.getc();
if (ibuf[i]!='\r') {
if (i < UART_MAX_CMD_LENGTH) {
i += 1;
}
} else {
bLED = LED_ON;
if (i < UART_MAX_CMD_LENGTH) {
ibuf[i]=0;
// daplink.printf("UART CMD: %s=", ibuf);
serInt.call(ibuf, obuf);
daplink.printf("%s\r\n", obuf);
} else {
daplink.printf("[-1]\r\n");
}
i=0;
bLED = LED_OFF;
}
}
}
}
// main() runs in its own thread in the OS
// (note the calls to Thread::wait below for delays)
int main()
{
daplink.printf("daplink serial port\r\n");
microUSB.printf("micro USB serial port\r\n");
rLED = LED_ON;
gLED = LED_ON;
bLED = LED_OFF;
// Board Initialization
pegasus.init();
// Serial Interface Setup
serInt.init(&i2c, &spi);
rLED = LED_OFF;
// Start USB serial thread
threadUSB.start(usb_thread);
// Start UART serial thread
threadUART.start(uart_thread);
// Start main loop
while(1) {
Thread::wait(500);
gLED = !gLED;
}
}
