mbed-os/TEST_APPS/device/exampleapp/main.cpp

69 lines
2.0 KiB
C++
Raw Normal View History

2018-01-23 10:26:14 +00:00
/*
2018-08-20 07:38:44 +00:00
* Copyright (c) 2018 ARM Limited. All rights reserved.
2018-01-23 10:26:14 +00:00
* SPDX-License-Identifier: Apache-2.0
* Licensed under the Apache License, Version 2.0 (the License); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdio.h>
#include <stdarg.h>
#include "mbed.h"
#include "mbed-client-cli/ns_cmdline.h"
2018-08-31 07:22:55 +00:00
#ifndef ICETEA_EXAMPLE_ENABLED
#error [NOT_SUPPORTED] Skipping example application.
#endif
2018-01-23 10:26:14 +00:00
/**
* Macros for setting console flow control.
*/
#define CONSOLE_FLOWCONTROL_RTS 1
#define CONSOLE_FLOWCONTROL_CTS 2
#define CONSOLE_FLOWCONTROL_RTSCTS 3
#define mbed_console_concat_(x) CONSOLE_FLOWCONTROL_##x
#define mbed_console_concat(x) mbed_console_concat_(x)
#define CONSOLE_FLOWCONTROL mbed_console_concat(MBED_CONF_TARGET_CONSOLE_UART_FLOW_CONTROL)
2018-08-20 07:38:44 +00:00
#define SERIAL_CONSOLE_BAUD_RATE 115200
2018-01-23 10:26:14 +00:00
void cmd_ready_cb(int retcode)
{
cmd_next(retcode);
}
2018-08-21 07:49:03 +00:00
void wrap_printf(const char *f, va_list a)
{
2018-08-20 07:38:44 +00:00
vprintf(f, a);
2018-01-23 10:26:14 +00:00
}
int main()
{
2018-08-20 07:38:44 +00:00
cmd_init(&wrap_printf);
2018-01-23 10:26:14 +00:00
2018-08-20 07:38:44 +00:00
int c;
2018-08-21 07:49:03 +00:00
while ((c = getchar()) != EOF) {
2018-01-23 10:26:14 +00:00
cmd_char_input(c);
}
2018-08-20 07:38:44 +00:00
return 0;
2018-01-23 10:26:14 +00:00
}
2018-08-21 07:49:03 +00:00
FileHandle *mbed::mbed_override_console(int)
{
2018-08-20 07:38:44 +00:00
static UARTSerial console(STDIO_UART_TX, STDIO_UART_RX, SERIAL_CONSOLE_BAUD_RATE);
2018-01-23 10:26:14 +00:00
#if CONSOLE_FLOWCONTROL == CONSOLE_FLOWCONTROL_RTS
console.set_flow_control(SerialBase::RTS, STDIO_UART_RTS, NC);
#elif CONSOLE_FLOWCONTROL == CONSOLE_FLOWCONTROL_CTS
console.set_flow_control(SerialBase::CTS, NC, STDIO_UART_CTS);
#elif CONSOLE_FLOWCONTROL == CONSOLE_FLOWCONTROL_RTSCTS
console.set_flow_control(SerialBase::RTSCTS, STDIO_UART_RTS, STDIO_UART_CTS);
#endif
return &console;
}