Commit c6f7d871 authored by Emil Obalski's avatar Emil Obalski Committed by Carles Cufi
Browse files

samples: openthread: Call usb_enable() by the app.



This commit updates openthread sample to call usb_enable() from
the application.

Signed-off-by: default avatarEmil Obalski <emil.obalski@nordicsemi.no>
parent 57084f32
Loading
Loading
Loading
Loading
+31 −0
Original line number Diff line number Diff line
@@ -10,10 +10,41 @@
LOG_MODULE_REGISTER(ot_br, LOG_LEVEL_DBG);

#include <zephyr.h>
#include <usb/usb_device.h>
#include <drivers/uart.h>

#define APP_BANNER "***** OpenThread NCP on Zephyr %s *****"

void main(void)
{
#if defined(CONFIG_OPENTHREAD_NCP_SPINEL_ON_UART_ACM)
	struct device *dev;
	uint32_t baudrate = 0U;
	int ret;

	dev = device_get_binding(
		CONFIG_OPENTHREAD_NCP_SPINEL_ON_UART_DEV_NAME);
	if (!dev) {
		LOG_ERR("UART device not found");
		return;
	}

	ret = usb_enable(NULL);
	if (ret != 0) {
		LOG_ERR("Failed to enable USB");
		return;
	}

	LOG_INF("Wait for host to settle");
	k_sleep(K_SECONDS(1));

	ret = uart_line_ctrl_get(dev, UART_LINE_CTRL_BAUD_RATE, &baudrate);
	if (ret) {
		LOG_WRN("Failed to get baudrate, ret code %d", ret);
	} else {
		LOG_INF("Baudrate detected: %d", baudrate);
	}
#endif /* CONFIG_OPENTHREAD_NCP_SPINEL_ON_UART_ACM */

	LOG_INF(APP_BANNER, CONFIG_NET_SAMPLE_APPLICATION_VERSION);
}
+0 −22
Original line number Diff line number Diff line
@@ -155,28 +155,6 @@ otError otPlatUartEnable(void)
		return OT_ERROR_FAILED;
	}

#ifdef CONFIG_OPENTHREAD_NCP_SPINEL_ON_UART_ACM
	int ret = usb_enable(NULL);
	uint32_t baudrate = 0U;

	if (ret != 0) {
		LOG_ERR("Failed to enable USB");
		return OT_ERROR_FAILED;
	}

	LOG_INF("Wait for host to settle");
	k_sleep(K_SECONDS(1));

	ret = uart_line_ctrl_get(ot_uart.dev,
				 UART_LINE_CTRL_BAUD_RATE,
				 &baudrate);
	if (ret) {
		LOG_WRN("Failed to get baudrate, ret code %d", ret);
	} else {
		LOG_INF("Baudrate detected: %d", baudrate);
	}
#endif

	uart_irq_callback_user_data_set(ot_uart.dev,
					uart_callback,
					(void *)&ot_uart);