Amazon

Monday 29 December 2008

HID Mouse in PSoC

Recently, I had to simulate a 3-button mouse with a PSoC connected to a CPU via the USB link.  The PSoC is a CY8C24894 and the CPU is a ICH-7 from Intel.

Here's the code I wrote to simulate the left, right, down, and up movements as well as the right and left click buttons. You need to had your own routine on how to determine the mouse actions.

First, you need to configure the USB module using the USB Setup Wizard in PSoC designer. You need to get the Vendor ID and Product ID of the ICH-7 CPU. In this case, Vendor ID is 8086h and the Product ID is 27CAh (this is in relation with which UHCI controller you are using). For the rest of the attributes, refer to the USBFS datasheet provided in PSoC designer.

//----------------------------------------------------------------------------
// HID Mouse
// with USBFS module
//----------------------------------------------------------------------------

#include        // part specific constants and macros
#include "PSoCAPI.h"    // PSoC API definitions for all User Modules
#include "psocgpioint.h"
#include "globalparams.h"
#include

int move_left;
int move_right;
int move_up;
int move_down;
int right_click;
int left_click;

BYTE Mouse_data[3] = {0,0,0}; 

void main()   
{   
M8C_EnableGInt;                       // Enable Global Interrupts

USBFS_1_Start(0, USB_3V_OPERATION); //Start USBFS Operation using device 0  
                                 //and with 3.3V operation  
 while (!USBFS_1_bGetConfiguration()); //Wait for Device to enumerate
//Enumeration is completed load endpoint 1. Do not toggle the first time
USBFS_1_LoadInEP(1, Mouse_data, 3, USB_NO_TOGGLE);

while(1) 
{

if (move_left) 
Mouse_data[1] = 0xFB; //Move cursor left 
while (!USBFS_1_bGetEPAckState(1)); //Wait for ACK before loading data
//ACK has occurred, load the endpoint and toggle the data bit
USBFS_1_LoadInEP(1, Mouse_data, 3, USB_TOGGLE); 
Mouse_data[1] = 0x00; //Stop cursor 
while (!USBFS_1_bGetEPAckState(1)); //Wait for ACK before loading data
//ACK has occurred, load the endpoint and toggle the data bit
USBFS_1_LoadInEP(1, Mouse_data, 3, USB_TOGGLE);

if (move_right) 
Mouse_data[1] = 0x05; //Move cursor right 
while (!USBFS_1_bGetEPAckState(1)); //Wait for ACK before loading data
//ACK has occurred, load the endpoint and toggle the data bit
USBFS_1_LoadInEP(1, Mouse_data, 3, USB_TOGGLE); 
Mouse_data[1] = 0x00; //Stop cursor 
while (!USBFS_1_bGetEPAckState(1)); //Wait for ACK before loading data
//ACK has occurred, load the endpoint and toggle the data bit
USBFS_1_LoadInEP(1, Mouse_data, 3, USB_TOGGLE); 

if (move_down) 
Mouse_data[2] = 0x05; //Move cursor down 
while (!USBFS_1_bGetEPAckState(1)); //Wait for ACK before loading data
//ACK has occurred, load the endpoint and toggle the data bit
USBFS_1_LoadInEP(1, Mouse_data, 3, USB_TOGGLE); 
Mouse_data[2] = 0x00; //Stop cursor 
while (!USBFS_1_bGetEPAckState(1)); //Wait for ACK before loading data
//ACK has occurred, load the endpoint and toggle the data bit
USBFS_1_LoadInEP(1, Mouse_data, 3, USB_TOGGLE); 
}

if (move_up) 
Mouse_data[2] = 0xFB; //Move cursor up 
while (!USBFS_1_bGetEPAckState(1)); //Wait for ACK before loading data
//ACK has occurred, load the endpoint and toggle the data bit
USBFS_1_LoadInEP(1, Mouse_data, 3, USB_TOGGLE); 
Mouse_data[2] = 0x00; //Stop cursor 
while (!USBFS_1_bGetEPAckState(1)); //Wait for ACK before loading data
//ACK has occurred, load the endpoint and toggle the data bit
USBFS_1_LoadInEP(1, Mouse_data, 3, USB_TOGGLE); 

if (left_click) 
Mouse_data[0] |= 0x01; //Left click 
while (!USBFS_1_bGetEPAckState(1)); //Wait for ACK before loading data
//ACK has occurred, load the endpoint and toggle the data bit
USBFS_1_LoadInEP(1, Mouse_data, 3, USB_TOGGLE); 
Mouse_data[0] = 0x00;
while (!USBFS_1_bGetEPAckState(1)); //Wait for ACK before loading data Mouse_data, 3, USB_TOGGLE); 

if (right_click) 
Mouse_data[0] |= 0x02; //Right click 
while (!USBFS_1_bGetEPAckState(1)); //Wait for ACK before loading data
//ACK has occurred, load the endpoint and toggle the data bit
USBFS_1_LoadInEP(1, Mouse_data, 3, USB_TOGGLE); 
Mouse_data[0] = 0x00;
while (!USBFS_1_bGetEPAckState(1)); //Wait for ACK before loading data
//ACK has occurred, load the endpoint and toggle the data bit
USBFS_1_LoadInEP(1, Mouse_data, 3, USB_TOGGLE); 
}
}
}

Wednesday 2 July 2008

Microchip MPLAB releases

Microchip has recently released new versions of MPLAB C compilers.

You have version v3.21 of MPLAB C compiler MPLAB C Compiler for PIC18 MCUs

and version v3.10c of MPLAB C Compiler for PIC24 and dsPIC DSCs device (you'll need to go to any of the three16-bit compiler pages linked here for the update).

See the Release Notes for full details on new device support and changes made to these interim releases.

Also there is the MPLAB IDE v8.14 interim release .

This release has the following new features:
- 64-bit USB Drivers. USB drivers for Windows Vista 64-bit operating system allows MPLAB ICD 2, MPLAB REAL ICE and other tools using USB interfaces to operate in both Windows 32-bit and 64-bit platforms (XP-64 and Vista-64).
- Shadow SFRs. Some parts contain banked SFR sets, such as devices with CAN peripherals. MPLAB IDE now allows full monitoring and write access to those registers for debugging.
- Fast Stepping with 32 kHz Oscillators. Debugging targets at 32 kHz can be slow, since data speeds between MPLAB IDE and the device are rates limited by the clock speed. MPLAB IDE will switch to a faster internal oscillator when communicating to the device to speed up debugging.
- Peripheral Pin Select support in MPLAB SIM.
- Interface for Difference Tool. A generic facility is provided to launch a file difference checker.
- Persistent Bookmarks. Bookmarks will now be stored with the workspace, so that a re-launch of the workspace will also restore all bookmarks.

See the MPLAB v8.14 Release Notes for more information and a list of devices supported.

Tuesday 1 July 2008

HI-TECH C PRO for the PIC32 MCU family

HI-TECH Software is pleased to announce the HI-TECH C PRO for the PIC32 MCU Family ANSI C compiler is due for release on the 23rd of July, 2008 to coincide with the Microchip MASTERs conference in Phoenix Arizona.

The HI-TECH C PRO for the PIC32 MCU Family will be the first from HI-TECH Software that supports 32-bit microcontrollers using Omniscient Code Generation™, and will be released in conjunction with the new MIPS-based PIC32 MCU family from Microchip Technology Inc.

Information on the new compiler supporting the new Microchip 32-bit MIPS-based microcontroller, can be found here.

Please note that the HI-TECH Enterprise Edition supporting Microchip Technology Inc. (currently PICC™ Enterprise Edition), will also include the new HI-TECH C PRO for the PIC32 MCU Family.

Updated pricelists including the new compiler can be found here.

HI-TECH Software will also be offering an introductory discount of 20% off the MSRP of the HI-TECH C PRO for the PIC32 MCU Family.

Monday 2 June 2008

HI-TECH PICmicro products now support 64-bit Windows Vista

HI-TECH Software has released a series of patch level updates which add support for 64-bit Windows Vista. Additionally, some other minor updates were made as well, such as bug fixes and support for new chips.

For more details:
PICC and PICC-Lite v9.60PL2
PICC-18 STD v9.51PL1
HI-TECH for dsPIC/PIC24 v9.60PL2

Tuesday 13 May 2008

DSP or FPGA?

Here is an interesting article from DSP DesignLine that explain how to choose between the two devices.

DSPs and FPGAs both offer advantages for signal processing. Here are the design guidelines you need to choose between DSPs, FPGAs, or a combination of the two. Topics covered include device cost, performance, NRE, and availability of application-specific features.

By Bamdad Afra and Amit Kapadiya, Nuvation
(read article)