Skip to content

Commit

Permalink
Merge pull request #241 from DaveAtkinsonXMOS/fix/AN000129_on_linux
Browse files Browse the repository at this point in the history
Fix AN000129 on linux
  • Loading branch information
DaveAtkinsonXMOS authored Jul 16, 2021
2 parents e64b7f8 + 87859df commit 3d0bfb3
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 224 deletions.
8 changes: 3 additions & 5 deletions examples/AN00129_hid_class/Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# The APP_NAME variable determines the name of the final .xe file. It should
# not include the .xe postfix. If left blank the name will default to
# not include the .xe postfix. If left blank the name will default to
# the project name

APP_NAME = app_hid_mouse_demo

# The flags passed to xcc when building the application
# You can also set the following to override flags for a particular language:
#
# XCC_XC_FLAGS, XCC_C_FLAGS, XCC_ASM_FLAGS, XCC_CPP_FLAGS
#
# If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
# If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
# xcc for the final link (mapping) stage.

# These flags define two build configurations - one for xCORE-200 and one for
Expand All @@ -18,7 +19,6 @@ BUILD_FLAGS = -O3 -report
XCC_FLAGS_200 = $(BUILD_FLAGS) -DXUD_CORE_CLOCK=500
XCC_FLAGS_AI = $(BUILD_FLAGS) -DXUD_CORE_CLOCK=600

# The USED_MODULES variable lists other module used by the application.
USED_MODULES = lib_xud

# The TARGET variable determines what target system the application is
Expand All @@ -38,5 +38,3 @@ endif

XMOS_MAKE_PATH ?= ../..
include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common


16 changes: 5 additions & 11 deletions examples/AN00129_hid_class/doc/rst/AN00129.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,9 @@ To start using the USB library, you need to add ``lib_xud`` to your ``Makefile``

USED_MODULES = ... lib_xud

You also have to add a define to the build to say which variant of the
USB library you want. In this case, the example is for the U-Series
USB library. So the following is in the ``Makefile``::
You can then access the USB functions in your source code via the xud_device.h header file::

XCC_FLAGS = ... -DXUD_SERIES_SUPPORT=XUD_U_SERIES

You can then access the USB functions in your source code via the usb.h header file::

#include <usb_device.h>
#include "xud_device.h"

The application main() function
...............................
Expand Down Expand Up @@ -197,7 +191,7 @@ USB HID Class requests
Inside ``endpoint0.xc`` there is a function for handling the USB HID device class specific requests. The code for handling these requests is shown as follows:

.. literalinclude:: endpoint0.xc
:lines: 167-224
:lines: 142-198

These HID specific requests are implemented by the application as they do not form part of the standard requests which have to be accepted by all device classes via endpoint0.

Expand All @@ -209,7 +203,7 @@ USB HID Class Endpoint0
The function ``Endpoint0()`` contains the code for dealing with device requests made from the host to the standard endpoint0 which is present in all USB devices. In addition to requests required for all devices, the code handles the requests specific to the HID class.

.. literalinclude:: endpoint0.xc
:lines: 260-306
:lines: 201-301

|newpage|

Expand All @@ -219,7 +213,7 @@ Reporting HID mouse data to the host
The application endpoint for reporting mouse movement data to the host machine is implemented in the file ``main.xc``. This is contained within the function ``hid_mouse()`` which is shown below:

.. literalinclude:: main.xc
:lines: 22-81
:lines: 24-80

From this you can see the following.

Expand Down
112 changes: 38 additions & 74 deletions examples/AN00129_hid_class/src/endpoint0.xc
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,13 @@
#include <xs1.h>
#include "xud_device.h"
#include "hid.h"
#include "hid_defs.h"

/* USB HID Device Product Defines */
#define BCD_DEVICE 0x1000
#define VENDOR_ID 0x20B1
#define PRODUCT_ID 0x1010

/* Standard HID Request Defines */

/* 7. Requests */

/* 7.1 Standard Requests - Class Descriptor Types - High byte of wValue
* The following defines valid types of Class descriptors */

#define HID_HID 0x2100
#define HID_REPORT 0x2200
#define HID_PHYSICAL_DESCRIPTOR 0x2300
/* 0x24 - 0x2F: Reserved */

/* 7.2 Class-Specific Requests - bRequest values */
#define HID_GET_REPORT 0x01 /* Mandatory */
#define HID_GET_IDLE 0x02
#define HID_GET_PROTOCOL 0x03 /* Required only for boot devices */
/* Ox04 - 0x08 reserved */
#define HID_SET_REPORT 0x09
#define HID_SET_IDLE 0x0A
#define HID_SET_PROTOCOL 0x0B /* Required only for boot devices */

/* Device Descriptor */
static unsigned char devDesc[] =
{
Expand Down Expand Up @@ -81,12 +61,12 @@ static unsigned char cfgDesc[] = {
0x09, /* 0 bLength. Note this is currently
replicated in hidDescriptor[] below */
0x21, /* 1 bDescriptorType (HID) */
0x10, /* 2 bcdHID */
0x11, /* 3 bcdHID */
0x11, /* 2 bcdHID */
0x01, /* 3 bcdHID */
0x00, /* 4 bCountryCode */
0x01, /* 5 bNumDescriptors */
0x22, /* 6 bDescriptorType[0] (Report) */
0x48, /* 7 wDescriptorLength */
0x32, /* 7 wDescriptorLength */
0x00, /* 8 wDescriptorLength */

0x07, /* 0 bLength */
Expand All @@ -95,62 +75,51 @@ static unsigned char cfgDesc[] = {
0x03, /* 3 bmAttributes */
0x40, /* 4 wMaxPacketSize */
0x00, /* 5 wMaxPacketSize */
0x01 /* 6 bInterval */
0x0a /* 6 bInterval */
};

static unsigned char hidDescriptor[] =
{
0x09, /* 0 bLength */
0x21, /* 1 bDescriptorType (HID) */
0x10, /* 2 bcdHID */
0x11, /* 3 bcdHID */
0x11, /* 2 bcdHID */
0x01, /* 3 bcdHID */
0x00, /* 4 bCountryCode */
0x01, /* 5 bNumDescriptors */
0x22, /* 6 bDescriptorType[0] (Report) */
0x48, /* 7 wDescriptorLength */
0x32, /* 7 wDescriptorLength */
0x00, /* 8 wDescriptorLength */
};

/* HID Report Descriptor */
static unsigned char hidReportDescriptor[] =
{
0x05, 0x01, // Usage page (desktop)
0x09, 0x02, // Usage (mouse)
0xA1, 0x01, // Collection (app)
0x05, 0x09, // Usage page (buttons)
0x19, 0x01,
0x29, 0x03,
0x15, 0x00, // Logical min (0)
0x25, 0x01, // Logical max (1)
0x95, 0x03, // Report count (3)
0x75, 0x01, // Report size (1)
0x81, 0x02, // Input (Data, Absolute)
0x95, 0x01, // Report count (1)
0x75, 0x05, // Report size (5)
0x81, 0x03, // Input (Absolute, Constant)
0x05, 0x01, // Usage page (desktop)
0x09, 0x01, // Usage (pointer)
0xA1, 0x00, // Collection (phys)
0x09, 0x30, // Usage (x)
0x09, 0x31, // Usage (y)
0x15, 0x81, // Logical min (-127)
0x25, 0x7F, // Logical max (127)
0x75, 0x08, // Report size (8)
0x95, 0x02, // Report count (2)
0x81, 0x06, // Input (Data, Rel=0x6, Abs=0x2)
0xC0, // End collection
0x09, 0x38, // Usage (Wheel)
0x95, 0x01, // Report count (1)
0x81, 0x02, // Input (Data, Relative)
0x09, 0x3C, // Usage (Motion Wakeup)
0x15, 0x00, // Logical min (0)
0x25, 0x01, // Logical max (1)
0x75, 0x01, // Report size (1)
0x95, 0x01, // Report count (1)
0xB1, 0x22, // Feature (No preferred, Variable)
0x95, 0x07, // Report count (7)
0xB1, 0x01, // Feature (Constant)
0xC0 // End collection
0x05, 0x01, /* Usage Page (Generic Desktop) */
0x09, 0x02, /* Usage (Mouse) */
0xA1, 0x01, /* Collection (Application) */
0x09, 0x01, /* Usage (Pointer) */
0xA1, 0x00, /* Collection (Physical) */
0x05, 0x09, /* Usage Page (Buttons) */
0x19, 0x01, /* Usage Minimum (01) */
0x29, 0x03, /* Usage Maximum (03) */
0x15, 0x00, /* Logical Minimum (0) */
0x25, 0x01, /* Logical Maximum (1) */
0x95, 0x03, /* Report Count (3) */
0x75, 0x01, /* Report Size (1) */
0x81, 0x02, /* Input (Data,Variable,Absolute); 3 button bits */
0x95, 0x01, /* Report Count (1) */
0x75, 0x05, /* Report Size (5) */
0x81, 0x01, /* Input(Constant); 5 bit padding */
0x05, 0x01, /* Usage Page (Generic Desktop) */
0x09, 0x30, /* Usage (X) */
0x09, 0x31, /* Usage (Y) */
0x15, 0x81, /* Logical Minimum (-127) */
0x25, 0x7F, /* Logical Maximum (127) */
0x75, 0x08, /* Report Size (8) */
0x95, 0x02, /* Report Count (2) */
0x81, 0x06, /* Input (Data,Variable,Relative); 2 position bytes (X & Y) */
0xC0, /* End Collection */
0xC0 /* End Collection */
};

unsafe{
Expand All @@ -164,7 +133,10 @@ static char * unsafe stringDescriptors[]=
};
}

extern unsigned char g_reportBuffer[4];
/* It is essential that HID_REPORT_BUFFER_SIZE, defined in hid_defs.h, matches the */
/* infered length of the report described in hidReportDescriptor above. In this case */
/* it is three bytes, three button bits padded to a byte, plus a byte each for X & Y */
unsigned char g_reportBuffer[HID_REPORT_BUFFER_SIZE] = {0, 0, 0};

/* HID Class Requests */
XUD_Result_t HidInterfaceClassRequests(XUD_ep c_ep0_out, XUD_ep c_ep0_in, USB_SetupPacket_t sp)
Expand Down Expand Up @@ -327,11 +299,3 @@ void Endpoint0(chanend chan_ep0_out, chanend chan_ep0_in)
}
}
}
//:







14 changes: 14 additions & 0 deletions examples/AN00129_hid_class/src/hid_defs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright 2021 XMOS LIMITED.
// This Software is subject to the terms of the XMOS Public Licence: Version 1.

/*
* @brief Defines shared data for HID example threads.
*/
#ifndef HID_DEFS_H
#define HID_DEFS_H

/* Global report buffer */
#define HID_REPORT_BUFFER_SIZE 3
extern char g_reportBuffer[HID_REPORT_BUFFER_SIZE];

#endif // HID_DEFS_H
Loading

0 comments on commit 3d0bfb3

Please sign in to comment.