CE95394 - USB HID MOUSE WITH PSOC(R) 3/PSOC 5LP.pdf

CE95394 - USB HID Mouse with PSoC® 3/PSoC 5LP
Objective
This code example implements a standard USB HID mouse with a single button. The mouse cursor will move in the shape of a
box on the screen.
Overview
This project demonstrates the use of the USBFS Component to implement a HID mouse. Using the standard HID mouse
descriptor the PSoC enumerates as a mouse on the PC. When the enumeration is complete, the PSoC sends data about the
relative movement of the mouse to the PC. A single button is also implemented in the project to emulate the left button, or
button 1, on a standard mouse. You can hold down the button on the kit and watch the cursor highlight text or select items on
a desktop while it draws the box.
www.cypress.com
Document No. 001-95394 Rev.**
1
USB HID Mouse with PSoC® 3/PSoC 5LP
PSoC Resources
Cypress provides a wealth of data at www.cypress.com to help you to select the right PSoC device for your design, and
quickly and effectively integrate the device into your design. For a comprehensive list of resources, see KBA86521, How to
Design with PSoC 3, PSoC 4, and PSoC 5LP. The following is an abbreviated list for PSoC 5LP:





Overview: PSoC Portfolio, PSoC Roadmap
Product Selectors: PSoC 1, PSoC 3, PSoC 4, or
PSoC 5LP. In addition, PSoC Creator includes a
device selection tool.
Datasheets:
Describe
and
provide
electrical
specifications for the PSoC 5LP device family.
CapSense Design Guide: Learn how to design
capacitive touch-sensing applications with the
PSoC 5LP family of devices.
Application Notes and Code Examples: Cover a
broad range of topics, from basic to advanced level.
Many of the application notes include code examples.



Technical Reference Manuals (TRM): Provide
detailed descriptions of the architecture and registers
in each PSoC 5LP device family.
Development Kits:
 CY8CKIT-001 is a common development platform
for all PSoC family devices.
 CY8CKIT-050 is a development platform targeted
at analog intensive designs for PSoC 5LP.
The MiniProg3 device provides an interface for flash
programming and debug.
PSoC Creator
PSoC Creator is a free Windows-based Integrated Design Environment (IDE). It enables concurrent hardware and firmware
design of systems based on PSoC 3, PSoC 4, and PSoC 5LP. See Figure 1 – with PSoC Creator, you can:
1.
2.
Drag and drop Components to build your hardware
system design in the main design workspace
3.
Configure Components using configuration tools
4. Explore the library of 100+ Components
Codesign your application firmware with the PSoC
5. Review Component datasheets
hardware
Figure 1. PSoC Creator Features
www.cypress.com
Document No. 001-95394 Rev.**
2
USB HID Mouse with PSoC® 3/PSoC 5LP
Requirements
Tool: PSoC Creator 3.1 CP1
Programming Language: C (GCC 4.8.4)
Associated Parts: All PSoC 3 and PSoC 5LP parts
Related Hardware: CY8CKIT-059, CY8CKIT-001, CY8CKIT-050, and CY8CKIT-030
Design
Figure 2 shows the PSoC Creator schematic for the code example.
Figure 2. USB HID Mouse Code Example Schematic
The code example uses the USBFS Component to implement the HID mouse and a digital input pin configured in resistive
pull-up mode to implement the mouse button.
All of the firmware for the code example is implemented in main.c. The firmware performs the following functions:





Enumerates the PSoC as a HID mouse.
Sends a packet of data with the mouse movement and button status to the PC.
Waits for the last packet to be acknowledged by the PC.
Updates the position data and button data after a brief delay.
Loads the new mouse data into the USB end to be sent to the PC.
www.cypress.com
Document No. 001-95394 Rev.**
3
USB HID Mouse with PSoC® 3/PSoC 5LP
Design Considerations
The design can be extended to implement a functional mouse by adding real user input to load the X and Y position data with.
This can be a joystick or a trackball fed into the ADC.
Hardware Setup
Plug in a USB cable to the USB connector on your kit.
Software Setup
There is no special software setup to use this project. HID drivers come standard on most operating systems, which is the
benefit of creating a HID device.
Components
Table 1 lists the PSoC Creator Components used in this example, as well as the hardware resources used by each.
Table 1. List of PSoC Creator Components
Component or User Module
Hardware Resources
USBFS
USB
Pin
One pin for the mouse button
Parameter Settings
Table 2. Parameter Settings
Component
Non-default Parameter Settings
USBFS
HID Class Descriptor
Pin
Resistive Pull-up, Show External Terminal
Design-Wide Resources
Figure 3 and Figure 4 show the pin selections and the required clock settings for USB operation.
Figure 3. Pin Selections
www.cypress.com
Document No. 001-95394 Rev.**
4
USB HID Mouse with PSoC® 3/PSoC 5LP
Figure 4. Clock Settings for USB Operation
Operation
Program your kit with the code example and plug in a USB cable from your PC to the USB connection on the kit (not the
programming connection). Press the associated button to emulate a left click on the mouse.
www.cypress.com
Document No. 001-95394 Rev.**
5
USB HID Mouse with PSoC® 3/PSoC 5LP
Related Documents
Table 3 lists all relevant application notes, code examples, knowledge base articles, device datasheets, and Component
datasheets.
Table 3. Related Resources
Application Notes
AN57473
USB HID Basics with PSoC® 3 and PSoC 5LP
Introduction to USB HID with PSoC
AN58726
PSoC® 3 / PSoC 5LP USB HID Intermediate (with
Keyboard and Composite Device)
Intermediate level USB HID with PSoC
AN82072
PSoC® 3 and PSoC 5LP USB General Data Transfer
with Standard HID Drivers
General data transfer using HID drivers with PSoC
AN57294
USB 101: An Introduction to Universal Serial Bus 2.0
Introduction to USB
AN56377
PSoC® 3 and PSoC 5LP - Introduction to
Implementing USB Data Transfers
Introduction to USB transfer types
Code Examples
CE95390
USB Audio with PSoC 3/5LP
CE95393
USB Bulk Transfer with PSoC 3/5LP
CE95395
USB MIDI with PSoC 3/5LP
CE95396
USB UART with PSoC 3/5LP
PSoC Creator Component Datasheets
USBFS
Details use of the USBFS Component
Device Documentation
PSoC 3 Datasheets
PSoC 3 Technical Reference Manuals
PSoC 4 Datasheets
PSoC 4 Technical Reference Manuals
PSoC 5LP Datasheets
PSoC 5LP Technical Reference Manuals
Development Kit (DVK) Documentation
PSoC 3 and PSoC 5LP Kits
PSoC 4 Kits
www.cypress.com
Document No. 001-95394 Rev.**
6
USB HID Mouse with PSoC® 3/PSoC 5LP
Document History
Document Title: CE95394 - USB HID Mouse with PSoC® 3/PSoC 5LP
Document Number: 001-95394
Revision
ECN
**
4675951
www.cypress.com
Orig. of
Change
KLMZ
Submission
Date
03/04/2015
Description of Change
New code example
Document No. 001-95394 Rev.**
7
USB HID Mouse with PSoC® 3/PSoC 5LP
Worldwide Sales and Design Support
Cypress maintains a worldwide network of offices, solution centers, manufacturer’s representatives, and distributors. To find
the office closest to you, visit us at Cypress Locations.
PSoC® Solutions
Products
Automotive
cypress.com/go/automotive
psoc.cypress.com/solutions
Clocks & Buffers
cypress.com/go/clocks
PSoC 1 |PSoC 3 | PSoC 4 |PSoC 5LP
Interface
cypress.com/go/interface
Lighting & Power Control
cypress.com/go/powerpsoc
cypress.com/go/plc
Memory
cypress.com/go/memory
PSoC
cypress.com/go/psoc
Touch Sensing
cypress.com/go/touch
USB Controllers
cypress.com/go/usb
Wireless/RF
cypress.com/go/wireless
Cypress Developer Community
Community | Forums |Blogs | Video |Training
Technical Support
cypress.com/go/support
PSoC is a registered trademark and PSoC Creator is a trademark of Cypress Semiconductor Corp. All other trademarks or registered trademarks
referenced herein are the property of their respective owners.
Cypress Semiconductor
198 Champion Court
San Jose, CA 95134-1709
Phone
Fax
Website
: 408-943-2600
: 408-943-4730
: www.cypress.com
© Cypress Semiconductor Corporation, 2015. The information contained herein is subject to change without notice. Cypress Semiconductor
Corporation assumes no responsibility for the use of any circuitry other than circuitry embodied in a Cypress product. Nor does it convey or imply any
license under patent or other rights. Cypress products are not warranted nor intended to be used for medical, life support, life saving, critical control or
safety applications, unless pursuant to an express written agreement with Cypress. Furthermore, Cypress does not authorize its products for use as
critical components in life-support systems where a malfunction or failure may reasonably be expected to result in significant injury to the user. The
inclusion of Cypress products in life-support systems application implies that the manufacturer assumes all risk of such use and in doing so indemnifies
Cypress against all charges.
This Source Code (software and/or firmware) is owned by Cypress Semiconductor Corporation (Cypress) and is protected by and subject to worldwide
patent protection (United States and foreign), United States copyright laws and international treaty provisions. Cypress hereby grants to licensee a
personal, non-exclusive, non-transferable license to copy, use, modify, create derivative works of, and compile the Cypress Source Code and derivative
works for the sole purpose of creating custom software and or firmware in support of licensee product to be used only in conjunction with a Cypress
integrated circuit as specified in the applicable agreement. Any reproduction, modification, translation, compilation, or representation of this Source
Code except as specified above is prohibited without the express written permission of Cypress.
Disclaimer: CYPRESS MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, WITH REGARD TO THIS MATERIAL, INCLUDING, BUT
NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Cypress reserves the
right to make changes without further notice to the materials described herein. Cypress does not assume any liability arising out of the application or
use of any product or circuit described herein. Cypress does not authorize its products for use as critical components in life-support systems where a
malfunction or failure may reasonably be expected to result in significant injury to the user. The inclusion of Cypress’ product in a life-support systems
application implies that the manufacturer assumes all risk of such use and in doing so indemnifies Cypress against all charges.
Use may be limited by and subject to the applicable Cypress software license agreement.
www.cypress.com
Document No. 001-95394 Rev.**
8
Similar pages