-
Notifications
You must be signed in to change notification settings - Fork 370
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tinyusb: Make automatic start of USB optional
So far TinyUSB stack was starting during system init stage. Now it is possible for the application to start it at later time by manually call tinyusb_start() function. Additionally shell commands are added to test functionality: /usb start /usb stop Signed-off-by: Jerzy Kasenberg <[email protected]>
- Loading branch information
Showing
5 changed files
with
109 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you 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. | ||
# | ||
|
||
pkg.name: hw/usb/tinyusb/shell | ||
pkg.description: Shell for TinyUSB | ||
pkg.author: "Apache Mynewt <[email protected]>" | ||
pkg.homepage: "http://mynewt.apache.org/" | ||
pkg.keywords: | ||
- usb | ||
- tinyusb | ||
|
||
pkg.deps: | ||
- "@apache-mynewt-core/kernel/os" | ||
- "@apache-mynewt-core/hw/usb/tinyusb" | ||
|
||
pkg.init: | ||
tinyusb_cli_init: 'MYNEWT_VAL(SHELL_SYSINIT_STAGE) + 1' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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 <os/mynewt.h> | ||
#include <shell/shell.h> | ||
#include <tinyusb/tinyusb.h> | ||
#include <device/usbd.h> | ||
#include <tusb.h> | ||
|
||
static int | ||
usb_cli_start_cmd(const struct shell_cmd *cmd, int argc, char **argv, | ||
struct streamer *streamer) | ||
{ | ||
if (!tusb_inited()) { | ||
tinyusb_start(); | ||
} else if (!tud_connected()) { | ||
tud_connect(); | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
static int | ||
usb_cli_stop_cmd(const struct shell_cmd *cmd, int argc, char **argv, | ||
struct streamer *streamer) | ||
{ | ||
if (tud_connected()) { | ||
tud_disconnect(); | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
static const struct shell_cmd usb_cli_commands[] = { | ||
SHELL_CMD_EXT("start", usb_cli_start_cmd, NULL), | ||
SHELL_CMD_EXT("stop", usb_cli_stop_cmd, NULL), | ||
{ }, | ||
}; | ||
|
||
int | ||
tinyusb_cli_init(void) | ||
{ | ||
shell_register("usb", usb_cli_commands); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters