⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mouse.c

📁 Cypress公司Cy7c6xxxx芯片的USB键盘及USB鼠标的firmware代码以及一些example代码。
💻 C
📖 第 1 页 / 共 3 页
字号:
/*
 * CYC Code Development System
 * USB mouse example
 * 	MOUSE.C
 * This code may be adapted for any purpose
 * when used with the CYC Code Development
 * System.  No warranty is implied or given
 * as to its usability for any purpose.
 * 
 * (c) Copyright 1999 Byte Craft Limited
 * 421 King St.N., Waterloo, ON, Canada, N2J 4E4
 * VOICE: 1 (519) 888 6911
 * FAX  : 1 (519) 746 6751
 * email: support@bytecraft.com
 * 
 * REVISION HISTORY
 * V0.90b  AL     99/06  Initial Version.
 ***/

#pragma option f0
#pragma option REGSAVEOFF;
#define DEBUG

#include <dev\c63100a.h>

const char hid_report_desc_table[] = 
{
 0x05, 0x01, /*usage page (generic desktop) */
 0x09, 0x02, /*usage (mouse) */
 0xA1, 0x01, /*collection (application) */
 0x09, 0x01, /*usage (pointer) */
 0xA1, 0x00, /*collection (linked) */
 0x05, 0x09, /*usage page (buttons) */
 0x19, 0x01, /*usage minimum (1) */
 0x29, 0x03, /*usage maximum (3) */
 0x15, 0x00, /*logical minimum (0) */
 0x25, 0x01, /*logical maximum (1) */
 0x95, 0x03, /*report count (3 bytes) */
 0x75, 0x01, /*report size (1) */
 0x81, 0x02, /*input (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 (2 position bytes X & Y) */
 0xC0, 0xC0  /* end collection, end collection */
};

const char Endpoint_Descriptor[] = 
{
 0x07, /* descriptor length (7 bytes) */
 0x05, /* descriptor type (ENDPOINT) */
 0x81, /* endpoint address (IN endpoint, endpoint 1) */
 0x03, /* endpoint attributes (interrupt) */
 0x03, 0x00, /* maximum packet size (8 bytes) */
 0x0A  /* polling interval (10ms) */
};

const char Class_Descriptor[] = 
{
 0x09, /* descriptor size (9 bytes) */
 0x21, /* descriptor type (HID) */
 0x00, 0x01, /* class specification (1.00) */
 0x00, /* hardware target country */
 0x01, /* number of hid class desriptors to follow (1) */
 0x22, /* report descriptor type (2) */
 sizeof(hid_report_desc_table),
 0x00
};

const char Interface_Descriptor[] = 
{
 0x09, /* length of descriptor (9 bytes) */
 0x04, /* descriptor type (INTERFACE) */
 0x00, /* interface number (0) */
 0x00, /* alternate setting (0) */
 0x01, /* number of endpoints (1) */
 0x03, /* interface class (3..defined by USB spec) */
 0x01, /* interface sub-class (1..defined by USB spec) */
 0x02, /* interface protocol (2..defined by USB spec) */
 0x05  /* interface string index (not supported) */
};

const char config_desc_table[] = 
{
 0x09, /* length of descriptor (9 bytes) */
 0x02, /* descriptor type (CONFIGURATION) */
 0x22, 0x00, /* total length of descriptor (33 bytes) */
 0x01, /* number of interfaces to configure (1) */
 0x01, /* configuration value (1) */
 0x04, /* configuration string index (not supported) */
 0xA0, /* configuration attributes (bus powered, remote wakeup) */
 0x32 /* maximum power (100mA) */
};

const char device_desc_table[] = 
{
 0x12, /* size of descriptor (18 bytes) */
 0x01, /* descriptor type (device descriptor) */
 0x00, 0x01, /* USB spec release (ver 1.0) */
 0x00, /* class code (each interface specifies class information) */
 0x00, /* device sub-class (must be set to 0 because class code is 0) */
 0x00, /* device protocol (no class specific protocol) */
 0x08, /* maximum packet size (8 bytes) */
 0xB4, 0x04, /* vendor ID (note Cypress vendor ID) */
 0x01, 0x00, /* product ID (Cypress USB mouse product ID) */
 0x00, 0x00, /* device release number */
 0x01, /* index of manufacturer string (not supported = 0x00) */
 0x02, /* index of product string (not supported = 0x00) */
 0x03, /* index of serial number string (not supported = 0x00) */
 0x01 /* number of configurations (1) */
};
/* These tables are the mechanism used to return status information to the 
 * host.  The status can be either device, interface, or endpoint.
 ***/
const char get_dev_status_table[] = 
{
 0x00, 0x00, /* remote wakeup disabled, bus powered */
 0x02, 0x00 /* remote wakeup enabled, bus powered */
};

const char get_interface_status_table[] = 
{
 0x00, 0x00 /* always return both bytes zero */
};

const char get_endpoint_status_table[] = 
{
 0x00, 0x00, /* not stalled */
 0x01, 0x00 /* stalled */
};

/* String Descriptors */
const char USBStringLanguageDescription[] = 
{
 0x04, /* Length */
 0x03, /* Type (3=string) */
 0x09, /* Language: English */
 0x04 /* Sub-language: Default */
};

const char USBStringDescription1[] = 
{
 0x10,0x03,'C',0,'y',0,'p',0,'r',0,'e',0,'s',0,'s',0
};

const char USBStringDescription2[] = 
{
 0x24, 0x03,
 'C',0,'y',0,'p',0,'r',0,'e',0,'s',0,'s',0,' ',0,
 'U',0,'S',0,'B',0,' ',0,'M',0,'o',0,'u',0,'s',0,'e',0
};

const char USBStringDescription3[] = 
{
 0x10,0x03,'0',0,'1',0,'2',0,'3',0,'4',0,'5',0,'6',0
};

/* is a serial number is used this number must be unique  */
/* for every device or else it may not enumerate properly */

const char USBStringDescription4[] = 
{
 0x14,
 0x03,
 'H',0,'I',0,'D',0,' ',0,'M',0,'o',0,'u',0,'s',0,'e',0
};

const char USBStringDescription5[] = 
{
 0x32,
 0x03,
 'E',0,'n',0,'d',0,'P',0,'o',0,'i',0,'n',0,'t',0,'1',0,' ',0,'I',0,
 'n',0,'t',0,'e',0,'r',0,'r',0,'u',0,'p',0,'t',0,'P',0,'i',0,'p',0,'e',0 
};

#define CONFIGURED                      0x01 /* configuration status values */
#define UNCONFIGURED                    0x00       

#define USB_GET_STATUS                  0x00
#define USB_CLEAR_FEATURE               0x01
#define USB_SET_FEATURE                 0x03
#define USB_SET_ADDRESS                 0x05
#define USB_GET_DESCRIPTOR              0x06
#define USB_SET_DESCRIPTOR              0x07
#define USB_GET_CONFIGURATION           0x08
#define USB_SET_CONFIGURATION           0x09
#define USB_GET_INTERFACE               0x0A
#define USB_SET_INTERFACE               0x0B
#define USB_SYNCH_FRAME                 0x0C

#define HOST_TO_DEVICE                  0b00000000
#define DEVICE_TO_HOST                  0b10000000
#define STANDARD                        0b00000000
#define CLASS                           0b00100000
#define VENDOR                          0b01000000
#define DEVICE                          0b00000000
#define INTERFACE                       0b00000001
#define ENDPOINT                        0b00000010
#define OTHER                           0b00000011

/* standard descriptor types */
#define USB_DEVICE                      0x01
#define USB_CONFIGURATION               0x02
#define USB_STRING                      0x03
#define USB_INTERFACE                   0x04
#define USB_ENDPOINT                    0x05

#define DISABLE_REMOTE_WAKEUP           0x00 /* bit[1] = 0 */
#define ENABLE_REMOTE_WAKEUP            0x02 /* bit[1] = 1 */

/* standard feature selectors */
#define USB_ENDPOINT_STALL              0x00 /* recipient endpoint */
#define USB_DEVICE_REMOTE_WAKEUP        0x01 /* recipient device */

/* from HID Class v1.0 Draft #4 
 * class specific descriptor types from section 7.1 Standard R ests
 ***/
#define USB_HID                         0x21
#define USB_REPORT                      0x22
#define USB_PHYSICAL                    0x23

/* class specific request codes from section 7.2 Class Specific R ests */
#define USB_GET_REPORT                  0x01
#define USB_GET_IDLE                    0x02
#define USB_GET_PROTOCOL                0x03
#define USB_SET_REPORT                  0x09
#define USB_SET_IDLE                    0x0A
#define USB_SET_PROTOCOL                0x0B

#define DATATOGGLE                      0x40 /* Data 0/1 bit */

#define PTR_CURRENT                     0x07 /* PORT0 current setting for PTR */
#define LED_CURRENT                     0x0F /* PORT1 current setting for LED */

#define BOOT_PROTOCOL                   0x00 /* protocol status values */
#define REPORT_PROTOCOL                 0x01

char far * USB_send_buffer_ptr;

unsigned int interrupt_mask;
char four_ms_counter = 4;
char button1_deb;

char button_flag;
char new_idle_flag;

struct mouse_report_buffer
{
        char buttons;
        char horizontal;
        char vertical;
}report_buffer;

/*
char report_buffer[3];
char buttons @ report_buffer[0];
char horizontal @ report_buffer[1];
char vertical @ report_buffer[2];
*/

char horiz_state;
char vert_state;

#define BUTTON_POSITION                 0x00
#define HORIZ_POSITION                  0x01
#define VERT_POSITION                   0x02

char data_start;

char wakeup_counter; /* used to count 10ms wakeup signal */
char wakeup_flag; /* indicates wakeup is in process */

char suspend_counter = 3;
char port_temp  = 0xf0;

char remote_wakeup_status = DISABLE_REMOTE_WAKEUP; /* remote wakeup request */
//char remote_wakeup_status = ENABLE_REMOTE_WAKEUP; /* remote wakeup request */

char disch_counter;

char idle_period_counter; 

char configuration_status; /* configuration status */
                           /* zero is unconfigured */
                           /* one is configured */

char endpoint_stall_status; /* zero is not stalled */
                            /* one is stalled */

char idle_period;
char prev_idle_period;  
char new_idle_period;

char protocol_status = BOOT_PROTOCOL; /* zero is boot protocol */
                                      /* one is report protocol */

char data_count;

char endp0_data_toggle;
char loop_counter;

char not_awake;

void USB_stage_one(void);
void USB_control_read(void);
void USB_control_read2(void);
void USB_no_data_control(void);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -