/Designs/Measuring_instruments/ISMS01A/SW/button/HID_button/HardwareProfile.h
0,0 → 1,113
/************************************************************************
HardwareProfile.h
 
WFF USB Generic HID Demonstration 3
usbGenericHidCommunication reference firmware 3_0_0_0
Copyright (C) 2011 Simon Inns
 
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
 
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
 
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
 
Email: simon.inns@gmail.com
 
************************************************************************/
 
#ifndef HARDWAREPROFILE_H
#define HARDWAREPROFILE_H
 
// USB stack hardware selection options ----------------------------------------------------------------
 
// (This section is the set of definitions required by the MCHPFSUSB framework.)
 
// Uncomment the following define if you wish to use the self-power sense feature
// and define the port, pin and tris for the power sense pin below:
// #define USE_SELF_POWER_SENSE_IO
#define tris_self_power TRISAbits.TRISA2
#if defined(USE_SELF_POWER_SENSE_IO)
#define self_power PORTAbits.RA2
#else
#define self_power 1
#endif
 
// Uncomment the following define if you wish to use the bus-power sense feature
// and define the port, pin and tris for the power sense pin below:
//#define USE_USB_BUS_SENSE_IO
#define tris_usb_bus_sense TRISAbits.TRISA1
#if defined(USE_USB_BUS_SENSE_IO)
#define USB_BUS_SENSE PORTAbits.RA1
#else
#define USB_BUS_SENSE 1
#endif
 
// Uncomment the following line to make the output HEX of this project work with the MCHPUSB Bootloader
//#define PROGRAMMABLE_WITH_USB_MCHPUSB_BOOTLOADER
 
// Uncomment the following line to make the output HEX of this project work with the HID Bootloader
#define PROGRAMMABLE_WITH_USB_HID_BOOTLOADER
 
// Application specific hardware definitions ------------------------------------------------------------
 
// Oscillator frequency (48Mhz with a 20Mhz external oscillator)
#define CLOCK_FREQ 48000000
 
// Device Vendor Indentifier (VID) (0x04D8 is Microchip's VID)
#define USB_VID 0x04D8
 
// Device Product Indentifier (PID) (0x0042)
#define USB_PID 0x0042
 
// Manufacturer string descriptor
#define MSDLENGTH 10
#define MSD 'S','i','m','o','n',' ','I','n','n','s'
 
// Product String descriptor
#define PSDLENGTH 20
#define PSD 'W','F','F',' ','G','e','n','e','r','i','c',' ','H','I','D',' ','d','e','m','o'
 
// Device serial number string descriptor
#define DSNLENGTH 7
#define DSN 'W','F','F','_','3','.','0'
 
// Common useful definitions
#define INPUT_PIN 1
#define OUTPUT_PIN 0
#define FLAG_FALSE 0
#define FLAG_TRUE 1
 
// Comment out the following line if you do not want the debug
// feature of the firmware (saves code and RAM space when off)
//
// Note: if you use this feature you must compile with the large
// memory model on (for 24-bit pointers) so that the sprintf()
// function will work correctly. If you do not require debug it's
// recommended that you compile with the small memory model and
// remove any references to <strings.h> and sprintf().
#define DEBUGON
 
// PIC to hardware pin mapping and control macros
 
// Led control macros
#define mInitStatusLeds() LATA &= 0b00000001; TRISA &= 0b00000001;
#define mStatusLED0 LATAbits.LATA0
#define mStatusLED0_on() mStatusLED0 = 1;
#define mStatusLED0_off() mStatusLED0 = 0;
#define mStatusLED0_Toggle() mStatusLED0 = !mStatusLED0;
#define mStatusLED0_Get() mStatusLED0
 
// Switch macros
#define mInitAllSwitches() TRISAbits.TRISA1=1;
#define mInitSwitch0() TRISAbits.TRISA1=1;
#define sw0 PORTAbits.RA1
 
 
#endif
/Designs/Measuring_instruments/ISMS01A/SW/button/HID_button/WFF_GenericHID_Demo_3.mcp
0,0 → 1,118
[HEADER]
magic_cookie={66E99B07-E706-4689-9E80-9B2582898A13}
file_version=1.0
device=PIC18F4550
[PATH_INFO]
BuildDirPolicy=BuildDirIsProjectDir
dir_src=
dir_bin=
dir_tmp=
dir_sin=
dir_inc=..\Microchip Solutions v2011-07-14\Microchip\Include
dir_lib=
dir_lkr=
[CAT_FILTERS]
filter_src=*.asm;*.c
filter_inc=*.h;*.inc
filter_obj=*.o
filter_lib=*.lib
filter_lkr=*.lkr
[CAT_SUBFOLDERS]
subfolder_src=USB Stack
subfolder_inc=Common;USB Stack
subfolder_obj=
subfolder_lib=
subfolder_lkr=
[FILE_SUBFOLDERS]
file_000=.
file_001=.
file_002=USB Stack
file_003=.
file_004=USB Stack
file_005=Common
file_006=Common
file_007=.
file_008=USB Stack
file_009=USB Stack
file_010=USB Stack
file_011=USB Stack
file_012=USB Stack
file_013=USB Stack
file_014=USB Stack
file_015=.
file_016=.
file_017=.
[GENERATED_FILES]
file_000=no
file_001=no
file_002=no
file_003=no
file_004=no
file_005=no
file_006=no
file_007=no
file_008=no
file_009=no
file_010=no
file_011=no
file_012=no
file_013=no
file_014=no
file_015=no
file_016=no
file_017=no
[OTHER_FILES]
file_000=no
file_001=no
file_002=no
file_003=no
file_004=no
file_005=no
file_006=no
file_007=no
file_008=no
file_009=no
file_010=no
file_011=no
file_012=no
file_013=no
file_014=no
file_015=no
file_016=no
file_017=no
[FILE_INFO]
file_000=main.c
file_001=usb_descriptors.c
file_002=..\Microchip Solutions v2011-07-14\Microchip\USB\usb_device.c
file_003=debug.c
file_004=..\Microchip Solutions v2011-07-14\Microchip\USB\HID Device Driver\usb_function_hid.c
file_005=..\Microchip Solutions v2011-07-14\Microchip\Include\Compiler.h
file_006=..\Microchip Solutions v2011-07-14\Microchip\Include\GenericTypeDefs.h
file_007=HardwareProfile.h
file_008=..\Microchip Solutions v2011-07-14\Microchip\Include\USB\usb.h
file_009=..\Microchip Solutions v2011-07-14\Microchip\Include\USB\usb_ch9.h
file_010=..\Microchip Solutions v2011-07-14\Microchip\Include\USB\usb_common.h
file_011=..\Microchip Solutions v2011-07-14\Microchip\Include\USB\usb_device.h
file_012=..\Microchip Solutions v2011-07-14\Microchip\Include\USB\usb_hal.h
file_013=..\Microchip Solutions v2011-07-14\Microchip\Include\USB\usb_hal_pic18.h
file_014=..\Microchip Solutions v2011-07-14\Microchip\USB\usb_device_local.h
file_015=usb_config.h
file_016=debug.h
file_017=rm18f4550 - HID Bootload.lkr
[SUITE_INFO]
suite_guid={5B7D72DD-9861-47BD-9F60-2BE967BF8416}
suite_state=
[TOOL_SETTINGS]
TS{DD2213A8-6310-47B1-8376-9430CDFC013F}=
TS{BFD27FBA-4A02-4C0E-A5E5-B812F3E7707C}=/o"$(BINDIR_)$(TARGETBASE).cof" /M"$(BINDIR_)$(TARGETBASE).map" /W
TS{C2AF05E7-1416-4625-923D-E114DB6E2B96}=-mL -Ou- -Ot- -Ob- -Op- -Or- -Od- -Opa-
TS{ADE93A55-C7C7-4D4D-A4BA-59305F7D0391}=
[INSTRUMENTED_TRACE]
enable=0
transport=0
format=0
[CUSTOM_BUILD]
Pre-Build=
Pre-BuildEnabled=1
Post-Build=
Post-BuildEnabled=1
/Designs/Measuring_instruments/ISMS01A/SW/button/HID_button/debug.c
0,0 → 1,134
/************************************************************************
debug.c
 
WFF USB Generic HID Demonstration 3
usbGenericHidCommunication reference firmware 3_0_0_0
Copyright (C) 2011 Simon Inns
 
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
 
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
 
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
 
Email: simon.inns@gmail.com
 
************************************************************************/
 
#ifndef DEBUG_C
#define DEBUG_C
 
// Global includes
#include <string.h>
 
// Local includes
#include "HardwareProfile.h"
#include "debug.h"
 
// Microchip Application Library includes
// (expects V2.9a of the USB library from "Microchip Solutions v2011-07-14")
#include "./USB/usb.h"
#include "./USB/usb_function_hid.h"
 
// Only compile in the global debug variables if debugging is required
#if defined(DEBUGON)
 
// Buffer pointers
UINT debugBufferStart;
UINT debugBufferEnd;
UINT debugBufferLevel;
// The following array is the cyclic buffer
UINT8 debugBuffer[DEBUGBUFFERSIZE];
 
#endif
 
// Initialise the debugging log functionality
void debugInitialise(void)
{
#if defined(DEBUGON)
// Reset the buffer's pointers
debugBufferStart = 0;
debugBufferEnd = 0;
debugBufferLevel = 0;
#endif
}
 
// Send debug text to the debug log
void debugOut(char* debugString)
{
#if defined(DEBUGON)
UINT charNumber;
// Is there space in the debug buffer?
if (debugBufferLevel + strlen(debugString) >= DEBUGBUFFERSIZE - 2)
{
// Buffer does not have enough space... silently drop the debug string
}
else
{
// Buffer is not full, write the bytes and update the end pointer
for (charNumber = 0; charNumber < strlen(debugString); charNumber++)
{
debugBuffer[debugBufferEnd] = debugString[charNumber];
debugBufferEnd = (debugBufferEnd + 1) % DEBUGBUFFERSIZE;
// Increment the buffer level indicator
debugBufferLevel++;
}
// Add a return and new line to the end of the string
debugBuffer[debugBufferEnd] = '\r';
debugBufferEnd = (debugBufferEnd + 1) % DEBUGBUFFERSIZE;
debugBufferLevel++;
debugBuffer[debugBufferEnd] = '\n';
debugBufferEnd = (debugBufferEnd + 1) % DEBUGBUFFERSIZE;
debugBufferLevel++;
}
#endif
}
 
// Copy 63 bytes of the debug buffer to the USB send buffer
// The first byte is the number of characters transferred
void copyDebugToSendBuffer(BYTE* sendDataBuffer)
{
#if defined(DEBUGON)
UINT bytesToSend = 0;
UINT byteCounter;
// Determine the number of bytes to send
if (debugBufferLevel > 63) bytesToSend = 63;
else bytesToSend = debugBufferLevel;
// Place the number of sent bytes in byte[0] of the send buffer
sendDataBuffer[0] = bytesToSend - 1;
if (debugBufferLevel != 0)
{
for (byteCounter = 1; byteCounter < bytesToSend; byteCounter++)
{
// Send the next byte to the send buffer
sendDataBuffer[byteCounter] = debugBuffer[debugBufferStart];
// Update the cyclic buffer pointer
debugBufferStart = (debugBufferStart + 1) % DEBUGBUFFERSIZE;
// Decrement the buffer level indicator
debugBufferLevel--;
}
}
#else
// Ensure that we indicate there is nothing to send if the host
// requests debug
sendDataBuffer[0] = 0;
#endif
}
#endif
/Designs/Measuring_instruments/ISMS01A/SW/button/HID_button/debug.h
0,0 → 1,41
/************************************************************************
debug.h
 
WFF USB Generic HID Demonstration 3
usbGenericHidCommunication reference firmware 3_0_0_0
Copyright (C) 2011 Simon Inns
 
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
 
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
 
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
 
Email: simon.inns@gmail.com
 
************************************************************************/
 
#ifndef DEBUG_H
#define DEBUG_H
 
// Microchip Application Library includes
// (expects V2.9a of the USB library from "Microchip Solutions v2011-07-14")
#include "./USB/usb.h"
#include "./USB/usb_function_hid.h"
 
// Set the size of the debug information buffer in characters
#define DEBUGBUFFERSIZE 128
 
// Function prototypes
void debugInitialise(void);
void debugOut(char*);
void copyDebugToSendBuffer(BYTE* sendDataBuffer);
 
#endif
/Designs/Measuring_instruments/ISMS01A/SW/button/HID_button/main.c
0,0 → 1,484
/************************************************************************
main.c
 
WFF USB Generic HID Demonstration 3
usbGenericHidCommunication reference firmware 3_0_0_0
Copyright (C) 2011 Simon Inns
 
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
 
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
 
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
 
Email: simon.inns@gmail.com
 
************************************************************************/
 
#ifndef MAIN_C
#define MAIN_C
 
// Global includes
// Note: string.h is required for sprintf commands for debug
#include <string.h>
 
// Local includes
#include "HardwareProfile.h"
#include "debug.h"
 
// Microchip Application Library includes
// (expects V2.9a of the USB library from "Microchip Solutions v2011-07-14")
//
// The library location must be set in:
// Project -> Build Options Project -> Directories -> Include search path
// in order for the project to compile.
#include "./USB/usb.h"
#include "./USB/usb_function_hid.h"
 
// Ensure we have the correct target PIC device family
#if !defined(__18F4550) && !defined(__18F2550)
#error "This firmware only supports either the PIC18F4550 or PIC18F2550 microcontrollers."
#endif
 
// Define the globals for the USB data in the USB RAM of the PIC18F*550
#pragma udata
#pragma udata USB_VARIABLES=0x500
unsigned char ReceivedDataBuffer[64];
unsigned char ToSendDataBuffer[64];
#pragma udata
 
USB_HANDLE USBOutHandle = 0;
USB_HANDLE USBInHandle = 0;
BOOL blinkStatusValid = FLAG_TRUE;
 
// PIC18F4550/PIC18F2550 configuration for the WFF Generic HID test device
#pragma config PLLDIV = 5 // 20Mhz external oscillator
#pragma config CPUDIV = OSC1_PLL2
#pragma config USBDIV = 2 // Clock source from 96MHz PLL/2
#pragma config FOSC = HSPLL_HS
#pragma config FCMEN = OFF
#pragma config IESO = OFF
#pragma config PWRT = OFF
#pragma config BOR = ON
#pragma config BORV = 3
#pragma config VREGEN = ON
#pragma config WDT = OFF
#pragma config WDTPS = 32768
#pragma config MCLRE = ON
#pragma config LPT1OSC = OFF
#pragma config PBADEN = OFF
// #pragma config CCP2MX = ON
#pragma config STVREN = ON
#pragma config LVP = OFF
// #pragma config ICPRT = OFF
#pragma config XINST = OFF
#pragma config CP0 = OFF
#pragma config CP1 = OFF
// #pragma config CP2 = OFF
// #pragma config CP3 = OFF
#pragma config CPB = OFF
// #pragma config CPD = OFF
#pragma config WRT0 = OFF
#pragma config WRT1 = OFF
// #pragma config WRT2 = OFF
// #pragma config WRT3 = OFF
#pragma config WRTB = OFF
#pragma config WRTC = OFF
// #pragma config WRTD = OFF
#pragma config EBTR0 = OFF
#pragma config EBTR1 = OFF
// #pragma config EBTR2 = OFF
// #pragma config EBTR3 = OFF
#pragma config EBTRB = OFF
 
// Private function prototypes
static void initialisePic(void);
void processUsbCommands(void);
void applicationInit(void);
void USBCBSendResume(void);
void highPriorityISRCode();
void lowPriorityISRCode();
 
// Remap vectors for compatibilty with Microchip USB boot loaders
#if defined(PROGRAMMABLE_WITH_USB_HID_BOOTLOADER)
#define REMAPPED_RESET_VECTOR_ADDRESS 0x1000
#define REMAPPED_HIGH_INTERRUPT_VECTOR_ADDRESS 0x1008
#define REMAPPED_LOW_INTERRUPT_VECTOR_ADDRESS 0x1018
#elif defined(PROGRAMMABLE_WITH_USB_MCHPUSB_BOOTLOADER)
#define REMAPPED_RESET_VECTOR_ADDRESS 0x800
#define REMAPPED_HIGH_INTERRUPT_VECTOR_ADDRESS 0x808
#define REMAPPED_LOW_INTERRUPT_VECTOR_ADDRESS 0x818
#else
#define REMAPPED_RESET_VECTOR_ADDRESS 0x00
#define REMAPPED_HIGH_INTERRUPT_VECTOR_ADDRESS 0x08
#define REMAPPED_LOW_INTERRUPT_VECTOR_ADDRESS 0x18
#endif
 
#if defined(PROGRAMMABLE_WITH_USB_HID_BOOTLOADER) || defined(PROGRAMMABLE_WITH_USB_MCHPUSB_BOOTLOADER)
extern void _startup (void);
#pragma code REMAPPED_RESET_VECTOR = REMAPPED_RESET_VECTOR_ADDRESS
void _reset (void)
{
_asm goto _startup _endasm
}
#endif
 
#pragma code REMAPPED_HIGH_INTERRUPT_VECTOR = REMAPPED_HIGH_INTERRUPT_VECTOR_ADDRESS
void Remapped_High_ISR (void)
{
_asm goto highPriorityISRCode _endasm
}
 
#pragma code REMAPPED_LOW_INTERRUPT_VECTOR = REMAPPED_LOW_INTERRUPT_VECTOR_ADDRESS
void Remapped_Low_ISR (void)
{
_asm goto lowPriorityISRCode _endasm
}
 
#if defined(PROGRAMMABLE_WITH_USB_HID_BOOTLOADER) || defined(PROGRAMMABLE_WITH_USB_MCHPUSB_BOOTLOADER)
#pragma code HIGH_INTERRUPT_VECTOR = 0x08
void High_ISR (void)
{
_asm goto REMAPPED_HIGH_INTERRUPT_VECTOR_ADDRESS _endasm
}
 
#pragma code LOW_INTERRUPT_VECTOR = 0x18
void Low_ISR (void)
{
_asm goto REMAPPED_LOW_INTERRUPT_VECTOR_ADDRESS _endasm
}
#endif
 
#pragma code
 
// High-priority ISR handling function
#pragma interrupt highPriorityISRCode
void highPriorityISRCode()
{
// Application specific high-priority ISR code goes here
#if defined(USB_INTERRUPT)
// Perform USB device tasks
USBDeviceTasks();
#endif
 
}
 
// Low-priority ISR handling function
#pragma interruptlow lowPriorityISRCode
void lowPriorityISRCode()
{
// Application specific low-priority ISR code goes here
}
 
// String for creating debug messages
char debugString[64];
 
// Main program entry point
void main(void)
{
// Initialise and configure the PIC ready to go
initialisePic();
 
// If we are running in interrupt mode attempt to attach the USB device
#if defined(USB_INTERRUPT)
USBDeviceAttach();
#endif
// Initialise the debug log functions
debugInitialise();
// Show that we are up and running
mStatusLED0_on();
sprintf(debugString, "USB Generic HID Demonstration 3");
debugOut(debugString);
 
sprintf(debugString, "(C)2011 Simon Inns - http://www.waitingforfriday.com");
debugOut(debugString);
sprintf(debugString, "USB Device Initialised.");
debugOut(debugString);
// Main processing loop
while(1)
{
#if defined(USB_POLLING)
// If we are in polling mode the USB device tasks must be processed here
// (otherwise the interrupt is performing this task)
USBDeviceTasks();
#endif
// Process USB Commands
processUsbCommands();
// Note: Other application specific actions can be placed here
}
}
 
// Initialise the PIC
static void initialisePic(void)
{
// PIC port set up --------------------------------------------------------
 
// Default all pins to digital
ADCON1 = 0x0F;
 
// Configure ports as inputs (1) or outputs(0)
TRISA = 0b00000000;
TRISB = 0b00000000;
TRISC = 0b00000000;
#if defined(__18F4550)
TRISD = 0b00000000;
TRISE = 0b00000000;
#endif
 
// Clear all ports
PORTA = 0b00000000;
PORTB = 0b00000000;
PORTC = 0b00000000;
#if defined(__18F4550)
PORTD = 0b00000000;
PORTE = 0b00000000;
#endif
 
// If you have a VBUS sense pin (for self-powered devices when you
// want to detect if the USB host is connected) you have to specify
// your input pin in HardwareProfile.h
#if defined(USE_USB_BUS_SENSE_IO)
tris_usb_bus_sense = INPUT_PIN;
#endif
// In the case of a device which can be both self-powered and bus-powered
// the device must respond correctly to a GetStatus (device) request and
// tell the host how it is currently powered.
//
// To do this you must device a pin which is high when self powered and low
// when bus powered and define this in HardwareProfile.h
#if defined(USE_SELF_POWER_SENSE_IO)
tris_self_power = INPUT_PIN;
#endif
 
// Application specific initialisation
applicationInit();
// Initialise the USB device
USBDeviceInit();
}
 
// Application specific device initialisation
void applicationInit(void)
{
// Initialise the status LEDs
mInitStatusLeds();
// Initialise the switch
mInitAllSwitches();
// Initialize the variable holding the USB handle for the last transmission
USBOutHandle = 0;
USBInHandle = 0;
}
 
// Process USB commands
void processUsbCommands(void)
{
// Check if we are in the configured state; otherwise just return
if((USBDeviceState < CONFIGURED_STATE) || (USBSuspendControl == 1))
{
// We are not configured
return;
}
 
// Check if data was received from the host.
if(!HIDRxHandleBusy(USBOutHandle))
{
// Command mode
switch(ReceivedDataBuffer[0])
{
case 0x10: // Debug information request from host
// Copy any waiting debug text to the send data buffer
copyDebugToSendBuffer((BYTE*)&ToSendDataBuffer[0]);
// Transmit the response to the host
if(!HIDTxHandleBusy(USBInHandle))
{
USBInHandle = HIDTxPacket(HID_EP,(BYTE*)&ToSendDataBuffer[0],64);
}
break;
// Place application specific commands here:
case 0x80: // Toggle the LED
sprintf(debugString, "Received command 0x80 from host - Toggle LED");
debugOut(debugString);
 
// Toggle the LED0
mStatusLED0_Toggle();
break;
case 0x81: // Read the push switch status
ToSendDataBuffer[0] = sw0;
 
// Transmit the response to the host
if(!HIDTxHandleBusy(USBInHandle))
{
USBInHandle = HIDTxPacket(HID_EP,(BYTE*)&ToSendDataBuffer[0],64);
}
break;
case 0x82: // Read the LED status
// Get the LED state and put it in the send buffer
ToSendDataBuffer[0] = mStatusLED0_Get();
// Transmit the response to the host
if(!HIDTxHandleBusy(USBInHandle))
{
USBInHandle = HIDTxPacket(HID_EP,(BYTE*)&ToSendDataBuffer[0],64);
}
break;
 
default: // Unknown command received
break;
}
// Re-arm the OUT endpoint for the next packet
USBOutHandle = HIDRxPacket(HID_EP,(BYTE*)&ReceivedDataBuffer,64);
}
}
 
// USB Callback handling routines -----------------------------------------------------------
 
// Call back that is invoked when a USB suspend is detected
void USBCBSuspend(void)
{
}
 
// This call back is invoked when a wakeup from USB suspend is detected.
void USBCBWakeFromSuspend(void)
{
}
 
// The USB host sends out a SOF packet to full-speed devices every 1 ms.
void USBCB_SOF_Handler(void)
{
// No need to clear UIRbits.SOFIF to 0 here. Callback caller is already doing that.
}
 
// The purpose of this callback is mainly for debugging during development.
// Check UEIR to see which error causes the interrupt.
void USBCBErrorHandler(void)
{
// No need to clear UEIR to 0 here.
// Callback caller is already doing that.
}
 
// Check other requests callback
void USBCBCheckOtherReq(void)
{
USBCheckHIDRequest();
}
 
// Callback function is called when a SETUP, bRequest: SET_DESCRIPTOR request arrives.
void USBCBStdSetDscHandler(void)
{
// You must claim session ownership if supporting this request
}
 
//This function is called when the device becomes initialized
void USBCBInitEP(void)
{
// Enable the HID endpoint
USBEnableEndpoint(HID_EP,USB_IN_ENABLED|USB_OUT_ENABLED|USB_HANDSHAKE_ENABLED|USB_DISALLOW_SETUP);
// Re-arm the OUT endpoint for the next packet
USBOutHandle = HIDRxPacket(HID_EP,(BYTE*)&ReceivedDataBuffer,64);
}
 
// Send resume call-back
void USBCBSendResume(void)
{
static WORD delay_count;
// Verify that the host has armed us to perform remote wakeup.
if(USBGetRemoteWakeupStatus() == FLAG_TRUE)
{
// Verify that the USB bus is suspended (before we send remote wakeup signalling).
if(USBIsBusSuspended() == FLAG_TRUE)
{
USBMaskInterrupts();
// Bring the clock speed up to normal running state
USBCBWakeFromSuspend();
USBSuspendControl = 0;
USBBusIsSuspended = FLAG_FALSE;
 
// Section 7.1.7.7 of the USB 2.0 specifications indicates a USB
// device must continuously see 5ms+ of idle on the bus, before it sends
// remote wakeup signalling. One way to be certain that this parameter
// gets met, is to add a 2ms+ blocking delay here (2ms plus at
// least 3ms from bus idle to USBIsBusSuspended() == FLAG_TRUE, yeilds
// 5ms+ total delay since start of idle).
delay_count = 3600U;
do
{
delay_count--;
} while(delay_count);
// Start RESUME signaling for 1-13 ms
USBResumeControl = 1;
delay_count = 1800U;
do
{
delay_count--;
} while(delay_count);
USBResumeControl = 0;
 
USBUnmaskInterrupts();
}
}
}
 
// USB callback function handler
BOOL USER_USB_CALLBACK_EVENT_HANDLER(USB_EVENT event, void *pdata, WORD size)
{
switch(event)
{
case EVENT_TRANSFER:
// Application callback tasks and functions go here
break;
case EVENT_SOF:
USBCB_SOF_Handler();
break;
case EVENT_SUSPEND:
USBCBSuspend();
break;
case EVENT_RESUME:
USBCBWakeFromSuspend();
break;
case EVENT_CONFIGURED:
USBCBInitEP();
break;
case EVENT_SET_DESCRIPTOR:
USBCBStdSetDscHandler();
break;
case EVENT_EP0_REQUEST:
USBCBCheckOtherReq();
break;
case EVENT_BUS_ERROR:
USBCBErrorHandler();
break;
default:
break;
}
return FLAG_TRUE;
}
 
#endif
/Designs/Measuring_instruments/ISMS01A/SW/button/HID_button/rm18f4550 - HID Bootload.lkr
0,0 → 1,44
// File: Application_18f4550.lkr
 
// Use this linker for the USB application that will be self programmed by the HID bootloader.
// The HID bootloader project itself uses the BootModified.18f4450.lkr file instead.
 
// THIS LINKER SCRIPT HAS BEEN MODIFIED... This version is intended to be used
// with the "PROGRAMMABLE_WITH_USB_HID_BOOTLOADER" bootloader. The HID
// bootloader occupies memory ranges 0x000-0xFFF. In order for the code generated
// by this project to work with the bootloader, the linker must not put any code
// in the 0x00-0xFFF address range.
 
// This linker script was originated from the 18f4550.lkr file provided by
// the MCC18 distribution.
 
LIBPATH .
 
FILES c018i.o
FILES clib.lib
FILES p18f4550.lib
 
CODEPAGE NAME=bootloader START=0x0 END=0xFFF PROTECTED
CODEPAGE NAME=vectors START=0x1000 END=0x1029 PROTECTED
CODEPAGE NAME=page START=0x102A END=0x7FFF
CODEPAGE NAME=idlocs START=0x200000 END=0x200007 PROTECTED
CODEPAGE NAME=config START=0x300000 END=0x30000D PROTECTED
CODEPAGE NAME=devid START=0x3FFFFE END=0x3FFFFF PROTECTED
CODEPAGE NAME=eedata START=0xF00000 END=0xF000FF PROTECTED
 
ACCESSBANK NAME=accessram START=0x0 END=0x5F
DATABANK NAME=gpr0 START=0x60 END=0xFF
DATABANK NAME=gpr1 START=0x100 END=0x1FF
DATABANK NAME=gpr2 START=0x200 END=0x2FF
DATABANK NAME=gpr3 START=0x300 END=0x3FF
DATABANK NAME=usb4 START=0x400 END=0x4FF PROTECTED
DATABANK NAME=usb5 START=0x500 END=0x5FF PROTECTED
DATABANK NAME=usb6 START=0x600 END=0x6FF PROTECTED
DATABANK NAME=usb7 START=0x700 END=0x7FF PROTECTED
ACCESSBANK NAME=accesssfr START=0xF60 END=0xFFF PROTECTED
 
SECTION NAME=CONFIG ROM=config
 
STACK SIZE=0x100 RAM=gpr3
 
SECTION NAME=USB_VARS RAM=usb4
/Designs/Measuring_instruments/ISMS01A/SW/button/HID_button/usb_config.h
0,0 → 1,97
/************************************************************************
usb_config.c
 
WFF USB Generic HID Demonstration 3
usbGenericHidCommunication reference firmware 3_0_0_0
Copyright (C) 2011 Simon Inns
 
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
 
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
 
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
 
Email: simon.inns@gmail.com
 
************************************************************************/
 
#ifndef USBCONFIG_H
#define USBCONFIG_H
 
// Definitions
#define USB_EP0_BUFF_SIZE 8 // Valid Options are 8, 16, 32, or 64 bytes.
#define USB_MAX_NUM_INT 1
#define USB_MAX_EP_NUMBER 1
 
// USB device descriptor
#define USB_USER_DEVICE_DESCRIPTOR &device_dsc
#define USB_USER_DEVICE_DESCRIPTOR_INCLUDE extern ROM USB_DEVICE_DESCRIPTOR device_dsc
 
// Configuration descriptors
#define USB_USER_CONFIG_DESCRIPTOR USB_CD_Ptr
#define USB_USER_CONFIG_DESCRIPTOR_INCLUDE extern ROM BYTE *ROM USB_CD_Ptr[]
 
// Set the USB ping pong mode
#define USB_PING_PONG_MODE USB_PING_PONG__FULL_PING_PONG
 
// Uncomment either USB_POLLING or USB_INTERRUPT to set how the USB
// device is updated
#define USB_POLLING
//#define USB_INTERRUPT
 
// Set the USB pullup option for usb_device.h
#define USB_PULLUP_OPTION USB_PULLUP_ENABLE
//#define USB_PULLUP_OPTION USB_PULLUP_DISABLED
 
// Use the internal USB transceiver module
#define USB_TRANSCEIVER_OPTION USB_INTERNAL_TRANSCEIVER
 
// Set either full-speed or low-speed USB device mode
#define USB_SPEED_OPTION USB_FULL_SPEED
//#define USB_SPEED_OPTION USB_LOW_SPEED
 
// Option to enable auto-arming of the status stage of control transfers
#define USB_ENABLE_STATUS_STAGE_TIMEOUTS
 
// Section 9.2.6 of the USB 2.0 specifications state that:
// Control transfers with no data stage must complete within 50ms of the start of the control transfer.
// Control transfers with (IN) data stage must complete within 50ms of sending the last IN data packet in fullfilment of the data stage.
// Control transfers with (OUT) data stage have no specific status stage timing (but must not exceed 5 seconds)
#define USB_STATUS_STAGE_TIMEOUT (BYTE)45
 
#define USB_SUPPORT_DEVICE
 
#define USB_NUM_STRING_DESCRIPTORS 3
 
// Enable/disable event handlers
//#define USB_INTERRUPT_LEGACY_CALLBACKS
#define USB_ENABLE_ALL_HANDLERS
//#define USB_ENABLE_SUSPEND_HANDLER
//#define USB_ENABLE_WAKEUP_FROM_SUSPEND_HANDLER
//#define USB_ENABLE_SOF_HANDLER
//#define USB_ENABLE_ERROR_HANDLER
//#define USB_ENABLE_OTHER_REQUEST_HANDLER
//#define USB_ENABLE_SET_DESCRIPTOR_HANDLER
//#define USB_ENABLE_INIT_EP_HANDLER
//#define USB_ENABLE_EP0_DATA_HANDLER
//#define USB_ENABLE_TRANSFER_COMPLETE_HANDLER
 
// Set device type to USB HID
#define USB_USE_HID
 
// HID endpoint allocation
#define HID_INTF_ID 0x00
#define HID_EP 1
#define HID_INT_OUT_EP_SIZE 3
#define HID_INT_IN_EP_SIZE 3
#define HID_NUM_OF_DSC 1
#define HID_RPT01_SIZE 28
 
#endif
/Designs/Measuring_instruments/ISMS01A/SW/button/HID_button/usb_descriptors.c
0,0 → 1,159
/************************************************************************
usb_descriptors.c
 
WFF USB Generic HID Demonstration 3
usbGenericHidCommunication reference firmware 3_0_0_0
Copyright (C) 2011 Simon Inns
 
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
 
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
 
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
 
Email: simon.inns@gmail.com
 
************************************************************************/
 
#ifndef USB_DESCRIPTORS_C
#define USB_DESCRIPTORS_C
 
// Local includes
#include "HardwareProfile.h"
 
// Microchip Application Library includes
#include "./USB/usb.h"
#include "./USB/usb_function_hid.h"
 
// Device Descriptor
ROM USB_DEVICE_DESCRIPTOR device_dsc=
{
0x12, // Size of this descriptor in bytes
USB_DESCRIPTOR_DEVICE, // DEVICE descriptor type
0x0200, // USB Spec Release Number in BCD format
0x00, // Class Code
0x00, // Subclass code
0x00, // Protocol code
USB_EP0_BUFF_SIZE, // Max packet size for EP0, see usb_config.h
USB_VID, // Vendor ID
USB_PID, // Product ID
0x0002, // Device release number in BCD format
0x01, // Manufacturer string index
0x02, // Product string index
0x03, // Device serial number string index
0x01 // Number of possible configurations
};
 
// Configuration 1 Descriptor
ROM BYTE configDescriptor1[]=
{
// Configuration Descriptor
0x09, // Size of this descriptor in bytes (sizeof(USB_CFG_DSC))
USB_DESCRIPTOR_CONFIGURATION, // CONFIGURATION descriptor type
0x29,0x00, // Total length of data for this cfg
1, // Number of interfaces in this cfg
1, // Index value of this configuration
0, // Configuration string index
_DEFAULT | _SELF, // Attributes, see usb_device.h
50, // Max power consumption (2X mA)
// Interface Descriptor
0x09, // Size of this descriptor in bytes (sizeof(USB_INTF_DSC))
USB_DESCRIPTOR_INTERFACE, // INTERFACE descriptor type
0, // Interface Number
0, // Alternate Setting Number
2, // Number of endpoints in this intf
HID_INTF, // Class code
0, // Subclass code
0, // Protocol code
0, // Interface string index
 
// HID Class-Specific Descriptor
0x09, // Size of this descriptor in bytes (sizeof(USB_HID_DSC)+3)
DSC_HID, // HID descriptor type
0x11,0x01, // HID Spec Release Number in BCD format (1.11)
0x00, // Country Code (0x00 for Not supported)
HID_NUM_OF_DSC, // Number of class descriptors, see usbcfg.h
DSC_RPT, // Report descriptor type
HID_RPT01_SIZE,0x00, // Size of the report descriptor (sizeof(hid_rpt01))
// Endpoint Descriptor
0x07, // sizeof(USB_EP_DSC)
USB_DESCRIPTOR_ENDPOINT, // Endpoint Descriptor
HID_EP | _EP_IN, // Endpoint Address
_INTERRUPT, // Attributes
0x40,0x00, // size
0x01, // Interval
 
// Endpoint Descriptor
0x07, // sizeof(USB_EP_DSC)
USB_DESCRIPTOR_ENDPOINT, // Endpoint Descriptor
HID_EP | _EP_OUT, // EndpointAddress
_INTERRUPT, // Attributes
0x40,0x00, // size
0x01 // Interval
};
 
// Language code string descriptor
ROM struct{BYTE bLength;BYTE bDscType;WORD string[1];}sd000={
sizeof(sd000),USB_DESCRIPTOR_STRING,{0x0409
}};
 
// Manufacturer string descriptor (set in HardwareProfile.h)
ROM struct{BYTE bLength;BYTE bDscType;WORD string[MSDLENGTH];}sd001={
sizeof(sd001),USB_DESCRIPTOR_STRING,
{MSD}};
 
// Product string descriptor (set in HardwareProfile.h)
ROM struct{BYTE bLength;BYTE bDscType;WORD string[PSDLENGTH];}sd002={
sizeof(sd002),USB_DESCRIPTOR_STRING,
{PSD}};
 
// Device serial number string descriptor
ROM struct{BYTE bLength;BYTE bDscType;WORD string[DSNLENGTH];}sd003={
sizeof(sd003),USB_DESCRIPTOR_STRING,
{DSN}};
 
// Class specific descriptor - HID
ROM struct{BYTE report[HID_RPT01_SIZE];}hid_rpt01={
{
0x06, 0x00, 0xFF, // Usage Page = 0xFF00 (Vendor Defined Page 1)
0x09, 0x01, // Usage (Vendor Usage 1)
0xA1, 0x01, // Collection (Application)
0x19, 0x01, // Usage Minimum
0x29, 0x40, // Usage Maximum //64 input usages total (0x01 to 0x40)
0x15, 0x01, // Logical Minimum (data bytes in the report may have minimum value = 0x00)
0x25, 0x40, // Logical Maximum (data bytes in the report may have maximum value = 0x00FF = unsigned 255)
0x75, 0x08, // Report Size: 8-bit field size
0x95, 0x40, // Report Count: Make sixty-four 8-bit fields (the next time the parser hits an "Input", "Output", or "Feature" item)
0x81, 0x00, // Input (Data, Array, Abs): Instantiates input packet fields based on the above report size, count, logical min/max, and usage.
0x19, 0x01, // Usage Minimum
0x29, 0x40, // Usage Maximum //64 output usages total (0x01 to 0x40)
0x91, 0x00, // Output (Data, Array, Abs): Instantiates output packet fields. Uses same report size and count as "Input" fields, since nothing new/different was specified to the parser since the "Input" item.
0xC0} // End Collection
};
 
 
// Array of configuration descriptors
ROM BYTE *ROM USB_CD_Ptr[]=
{
(ROM BYTE *ROM)&configDescriptor1
};
 
// Array of string descriptors
ROM BYTE *ROM USB_SD_Ptr[]=
{
(ROM BYTE *ROM)&sd000,
(ROM BYTE *ROM)&sd001,
(ROM BYTE *ROM)&sd002,
(ROM BYTE *ROM)&sd003
};
 
#endif
/Designs/Measuring_instruments/ISMS01A/SW/button/README.txt
0,0 → 1,2
source http://www.waitingforfriday.com/?p=451