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: max32625pico SerialInterface USBDevice
main.cpp
- Committer:
- switches
- Date:
- 2017-04-13
- Revision:
- 13:fed6ff32bf5d
- Parent:
- 11:b9d7ab7626b5
- Child:
- 14:dd5a96c353ed
File content as of revision 13:fed6ff32bf5d:
#include "mbed.h"
#include "rtos.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
// Virtual serial port over USB
USBSerial microUSB;
// Hardware serial port over DAPLink
Serial daplink(P2_1, P2_0);
// Serial Interfaces
I2C i2c(P1_6, P1_7);
SPI spi(P1_5, P1_6, P1_4);
DigitalInOut gpio[] = {P0_0, P0_1, P0_2, P0_3, P4_4, P4_5, P4_6, P4_7};
AnalogIn ain[] = {AIN_0, AIN_1, AIN_2, AIN_3, AIN_4, AIN_5, AIN_6, AIN_7};
// Serial Interface Adapter
SerialInterface serInt(i2c, spi, gpio, ain);
// 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;
microUSB.printf("micro USB serial port\r\n");
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;
daplink.printf("daplink serial port\r\n");
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()
{
rLED = LED_ON;
gLED = LED_ON;
bLED = LED_OFF;
/* Board Initialization
* This is done automatically if you specify vio
* when you instantiate the MAX32630FTHR library
*/
// pegasus.init(MAX32630FTHR::VIO_3V3);
// Initialize primary SPI CS
gpio[0].write(1);
gpio[0].output();
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;
}
}