Skip to content

Commit

Permalink
USB: Add basic USB sample
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryzee119 committed Mar 24, 2021
1 parent 6a0d677 commit 3f420c0
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
5 changes: 5 additions & 0 deletions samples/usb/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
XBE_TITLE = nxdk\ sample\ -\ usb
GEN_XISO = $(XBE_TITLE).iso
SRCS = $(CURDIR)/main.c
NXDK_DIR = $(CURDIR)/../..
include $(NXDK_DIR)/Makefile
38 changes: 38 additions & 0 deletions samples/usb/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include <hal/debug.h>
#include <hal/video.h>
#include <windows.h>
#include <usbh_lib.h>

/*
* This demo will initialise the usb stack, detect events on the usb ports
* and print the device PID and VID.
*/
void device_connection_callback(UDEV_T *udev, int status)
{
debugPrint("Device connected on port %u (PID: %04x VID: %04x)\n", udev->port_num,
udev->descriptor.idProduct,
udev->descriptor.idVendor);
}

void device_disconnect_callback(UDEV_T *udev, int status)
{
debugPrint("Device disconnected on port %u (PID: %04x VID: %04x)\n", udev->port_num,
udev->descriptor.idProduct,
udev->descriptor.idVendor);
}

int main(void)
{
XVideoSetMode(640, 480, 32, REFRESH_DEFAULT);

usbh_core_init();
usbh_install_conn_callback(&device_connection_callback, &device_disconnect_callback);
debugPrint("== ochi usb test ==\n");
debugPrint("== Plug and unplug USB devices to test ==\n");
while (1) {
usbh_pooling_hubs();
Sleep(1);
}
usbh_core_deinit();
return 0;
}

0 comments on commit 3f420c0

Please sign in to comment.