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

usb: samples: Application calling usb_enable by itself



User app is reponsible for issuing usb_enable and
making USB hardware operative.

Signed-off-by: default avatarEmil Obalski <emil.obalski@nordicsemi.no>
parent e3619d50
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@
#ifdef CONFIG_UART_CONSOLE_MCUMGR
#include "mgmt/serial.h"
#endif
#include <usb/usb_device.h>

static struct device *uart_console_dev;

@@ -596,6 +597,13 @@ static int uart_console_init(struct device *arg)
	uart_console_dev = device_get_binding(CONFIG_UART_CONSOLE_ON_DEV_NAME);

#if defined(CONFIG_USB_UART_CONSOLE) && defined(CONFIG_USB_UART_DTR_WAIT)
	int ret;

	ret = usb_enable();
	if (ret != 0) {
		return ret;
	}

	while (1) {
		u32_t dtr = 0U;

+8 −5
Original line number Diff line number Diff line
@@ -217,12 +217,15 @@ int usb_set_config(const u8_t *usb_descriptor);
int usb_deconfig(void);

/**
 * @brief Enable USB for host/device connection
 * @brief Enable the USB subsystem and associated hardware
 *
 * Function to enable USB for host/device connection.
 * Upon success, the USB module is no longer clock gated in hardware,
 * it is now capable of transmitting and receiving on the USB bus and
 * of generating interrupts.
 * This function initializes the USB core subsystem and enables the
 * corresponding hardware so that it can begin transmitting and receiving
 * on the USB bus, as well as generating interrupts.
 *
 * Class-specific initialization and registration must be performed by the user
 * before invoking this, so that any data or events on the bus are processed
 * correctly by the associated class handling code.
 *
 * @return 0 on success, negative errno code on fail.
 */
+9 −0
Original line number Diff line number Diff line
@@ -6,8 +6,17 @@

#include <zephyr.h>
#include <sys/printk.h>
#include <usb/usb_device.h>

void main(void)
{
	int ret;

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

	printk("Bluetooth over USB sample\n");
}
+8 −0
Original line number Diff line number Diff line
@@ -82,6 +82,8 @@ static struct device *hid_device;

int usb_transport_init(usb_transport_receive_callback_t callback)
{
	int ret;

	hid_device = device_get_binding("HID_0");

	if (hid_device == NULL) {
@@ -96,6 +98,12 @@ int usb_transport_init(usb_transport_receive_callback_t callback)

	receive_data_cb = callback;

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

	/* initialize USB interface and HID class */
	return usb_hid_init(hid_device);
}
+6 −0
Original line number Diff line number Diff line
@@ -401,6 +401,7 @@ out:

void main(void)
{
	int ret;
	LOG_INF("Starting wpanusb");

	ieee802154_dev = device_get_binding(CONFIG_NET_CONFIG_IEEE802154_DEV_NAME);
@@ -417,6 +418,11 @@ void main(void)

	radio_api = (struct ieee802154_radio_api *)ieee802154_dev->driver_api;

	ret = usb_enable(NULL);
	if (ret != 0) {
		LOG_ERR("Failed to enable USB");
		return;
	}
	/* TODO: Initialize more */

	LOG_DBG("radio_api %p initialized", radio_api);
Loading