bootloader now able to communicate with host application and can be reset by it
This commit is contained in:
@@ -26,7 +26,6 @@
|
|||||||
projectFiles="true">
|
projectFiles="true">
|
||||||
<itemPath>../src/usb_config.h</itemPath>
|
<itemPath>../src/usb_config.h</itemPath>
|
||||||
<itemPath>../src/bootloader.h</itemPath>
|
<itemPath>../src/bootloader.h</itemPath>
|
||||||
<itemPath>../src/typedefs.h</itemPath>
|
|
||||||
</logicalFolder>
|
</logicalFolder>
|
||||||
<logicalFolder name="LinkerScript"
|
<logicalFolder name="LinkerScript"
|
||||||
displayName="Linker Files"
|
displayName="Linker Files"
|
||||||
@@ -97,7 +96,7 @@
|
|||||||
<property key="default-bitfield-type" value="true"/>
|
<property key="default-bitfield-type" value="true"/>
|
||||||
<property key="default-char-type" value="true"/>
|
<property key="default-char-type" value="true"/>
|
||||||
<property key="define-macros" value=""/>
|
<property key="define-macros" value=""/>
|
||||||
<property key="disable-optimizations" value="true"/>
|
<property key="disable-optimizations" value="false"/>
|
||||||
<property key="extra-include-directories"
|
<property key="extra-include-directories"
|
||||||
value="..\src;..\..\common_src\framework\usb\inc"/>
|
value="..\src;..\..\common_src\framework\usb\inc"/>
|
||||||
<property key="favor-optimization-for" value="-speed,+space"/>
|
<property key="favor-optimization-for" value="-speed,+space"/>
|
||||||
@@ -105,14 +104,14 @@
|
|||||||
<property key="garbage-collect-functions" value="true"/>
|
<property key="garbage-collect-functions" value="true"/>
|
||||||
<property key="identifier-length" value="255"/>
|
<property key="identifier-length" value="255"/>
|
||||||
<property key="local-generation" value="false"/>
|
<property key="local-generation" value="false"/>
|
||||||
<property key="operation-mode" value="pro"/>
|
<property key="operation-mode" value="free"/>
|
||||||
<property key="opt-xc8-compiler-strict_ansi" value="false"/>
|
<property key="opt-xc8-compiler-strict_ansi" value="false"/>
|
||||||
<property key="optimization-assembler" value="true"/>
|
<property key="optimization-assembler" value="true"/>
|
||||||
<property key="optimization-assembler-files" value="true"/>
|
<property key="optimization-assembler-files" value="true"/>
|
||||||
<property key="optimization-debug" value="false"/>
|
<property key="optimization-debug" value="false"/>
|
||||||
<property key="optimization-invariant-enable" value="false"/>
|
<property key="optimization-invariant-enable" value="false"/>
|
||||||
<property key="optimization-invariant-value" value="16"/>
|
<property key="optimization-invariant-value" value="16"/>
|
||||||
<property key="optimization-level" value="-O0"/>
|
<property key="optimization-level" value="-O1"/>
|
||||||
<property key="optimization-speed" value="false"/>
|
<property key="optimization-speed" value="false"/>
|
||||||
<property key="optimization-stable-enable" value="false"/>
|
<property key="optimization-stable-enable" value="false"/>
|
||||||
<property key="pack-struct" value="true"/>
|
<property key="pack-struct" value="true"/>
|
||||||
@@ -138,13 +137,13 @@
|
|||||||
<property key="calibrate-oscillator-value" value="0x3400"/>
|
<property key="calibrate-oscillator-value" value="0x3400"/>
|
||||||
<property key="clear-bss" value="true"/>
|
<property key="clear-bss" value="true"/>
|
||||||
<property key="code-model-external" value="wordwrite"/>
|
<property key="code-model-external" value="wordwrite"/>
|
||||||
<property key="code-model-rom" value="default,-1400-7FFF"/>
|
<property key="code-model-rom" value="default,-1C00-7FFF"/>
|
||||||
<property key="create-html-files" value="false"/>
|
<property key="create-html-files" value="false"/>
|
||||||
<property key="data-model-ram" value=""/>
|
<property key="data-model-ram" value=""/>
|
||||||
<property key="data-model-size-of-double" value="32"/>
|
<property key="data-model-size-of-double" value="24"/>
|
||||||
<property key="data-model-size-of-double-gcc" value="no-short-double"/>
|
<property key="data-model-size-of-double-gcc" value="short-double"/>
|
||||||
<property key="data-model-size-of-float" value="32"/>
|
<property key="data-model-size-of-float" value="24"/>
|
||||||
<property key="data-model-size-of-float-gcc" value="no-short-float"/>
|
<property key="data-model-size-of-float-gcc" value="short-float"/>
|
||||||
<property key="display-class-usage" value="false"/>
|
<property key="display-class-usage" value="false"/>
|
||||||
<property key="display-hex-usage" value="false"/>
|
<property key="display-hex-usage" value="false"/>
|
||||||
<property key="display-overall-usage" value="true"/>
|
<property key="display-overall-usage" value="true"/>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#include "bootloader.h"
|
#include "bootloader.h"
|
||||||
#include "typedefs.h"
|
#include <xc.h>
|
||||||
#include "usb.h"
|
#include "usb.h"
|
||||||
#include "usb_device_hid.h"
|
#include "usb_device_hid.h"
|
||||||
|
|
||||||
@@ -143,8 +143,8 @@ typedef union
|
|||||||
};
|
};
|
||||||
} PacketToFromPC;
|
} PacketToFromPC;
|
||||||
|
|
||||||
PacketToFromPC PacketFromPC;
|
PacketToFromPC PacketFromPC __at(0x500);
|
||||||
PacketToFromPC PacketToPC;
|
PacketToFromPC PacketToPC __at(0x550);
|
||||||
unsigned char ProgrammingBuffer[ERASE_PAGE_SIZE];
|
unsigned char ProgrammingBuffer[ERASE_PAGE_SIZE];
|
||||||
unsigned char BootState;
|
unsigned char BootState;
|
||||||
unsigned int ErasePageTracker;
|
unsigned int ErasePageTracker;
|
||||||
@@ -170,7 +170,10 @@ void UserInit(void)
|
|||||||
BootState = IDLE;
|
BootState = IDLE;
|
||||||
ProgrammedPointer = INVALID_ADDRESS;
|
ProgrammedPointer = INVALID_ADDRESS;
|
||||||
BufferedDataIndex = 0;
|
BufferedDataIndex = 0;
|
||||||
ConfigsLockValue = TRUE;
|
ConfigsLockValue = 1;
|
||||||
|
|
||||||
|
USBEnableEndpoint(HID_EP, USB_IN_ENABLED|USB_OUT_ENABLED|USB_HANDSHAKE_ENABLED|USB_DISALLOW_SETUP);
|
||||||
|
rxHandle = HIDRxPacket(HID_EP, (char *)&PacketFromPC, USB_PACKET_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
@@ -193,7 +196,7 @@ void UserInit(void)
|
|||||||
void ProcessIO(void)
|
void ProcessIO(void)
|
||||||
{
|
{
|
||||||
static unsigned char i;
|
static unsigned char i;
|
||||||
static ROM uint8_t* pROM;
|
static const uint8_t* pROM;
|
||||||
|
|
||||||
//Checks for and processes application related USB packets (assuming the
|
//Checks for and processes application related USB packets (assuming the
|
||||||
//USB bus is in the CONFIGURED_STATE, which is the only state where
|
//USB bus is in the CONFIGURED_STATE, which is the only state where
|
||||||
@@ -216,7 +219,7 @@ void ProcessIO(void)
|
|||||||
{
|
{
|
||||||
//We received a new command from the host. Copy the OUT packet from
|
//We received a new command from the host. Copy the OUT packet from
|
||||||
//the host into a local buffer for processing.
|
//the host into a local buffer for processing.
|
||||||
rxHandle = HIDRxPacket(HID_IN_EP, (char *)&PacketFromPC, USB_PACKET_SIZE); //Also re-arms the OUT endpoint to be able to receive the next packet
|
rxHandle = HIDRxPacket(HID_EP, (char *)&PacketFromPC, USB_PACKET_SIZE); //Also re-arms the OUT endpoint to be able to receive the next packet
|
||||||
//HIDRxReport((char *)&PacketFromPC, USB_PACKET_SIZE); //Also re-arms the OUT endpoint to be able to receive the next packet
|
//HIDRxReport((char *)&PacketFromPC, USB_PACKET_SIZE); //Also re-arms the OUT endpoint to be able to receive the next packet
|
||||||
BootState = NOT_IDLE; //Set flag letting state machine know it has a command that needs processing.
|
BootState = NOT_IDLE; //Set flag letting state machine know it has a command that needs processing.
|
||||||
|
|
||||||
@@ -260,15 +263,15 @@ void ProcessIO(void)
|
|||||||
//Init pad bytes to 0x00... Already done after we received the QUERY_DEVICE command (just after calling HIDRxReport()).
|
//Init pad bytes to 0x00... Already done after we received the QUERY_DEVICE command (just after calling HIDRxReport()).
|
||||||
|
|
||||||
//Now send the packet to the USB host software, assuming the USB endpoint is available/ready to accept new data.
|
//Now send the packet to the USB host software, assuming the USB endpoint is available/ready to accept new data.
|
||||||
txHandle = HIDTxPacket(HID_OUT_EP, (char *)&PacketToPC, USB_PACKET_SIZE);
|
txHandle = HIDTxPacket(HID_EP, (char *)&PacketToPC, USB_PACKET_SIZE);
|
||||||
BootState = IDLE;
|
BootState = IDLE;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case UNLOCK_CONFIG:
|
case UNLOCK_CONFIG:
|
||||||
ConfigsLockValue = TRUE;
|
ConfigsLockValue = 1;
|
||||||
if(PacketFromPC.LockValue == UNLOCKCONFIG)
|
if(PacketFromPC.LockValue == UNLOCKCONFIG)
|
||||||
{
|
{
|
||||||
ConfigsLockValue = FALSE;
|
ConfigsLockValue = 0;
|
||||||
}
|
}
|
||||||
BootState = IDLE;
|
BootState = IDLE;
|
||||||
break;
|
break;
|
||||||
@@ -315,7 +318,7 @@ void ProcessIO(void)
|
|||||||
//Check if host is trying to program the config bits
|
//Check if host is trying to program the config bits
|
||||||
if(PacketFromPC.Contents[3] == 0x30) // //PacketFromPC.Contents[3] is bits 23:16 of the address.
|
if(PacketFromPC.Contents[3] == 0x30) // //PacketFromPC.Contents[3] is bits 23:16 of the address.
|
||||||
{ //0x30 implies config bits
|
{ //0x30 implies config bits
|
||||||
if(ConfigsLockValue == FALSE)
|
if(ConfigsLockValue == 0)
|
||||||
{
|
{
|
||||||
WriteConfigBits(); //Doesn't get reprogrammed if the UNLOCK_CONFIG (LockValue = UNLOCKCONFIG) command hasn't previously been sent
|
WriteConfigBits(); //Doesn't get reprogrammed if the UNLOCK_CONFIG (LockValue = UNLOCKCONFIG) command hasn't previously been sent
|
||||||
}
|
}
|
||||||
@@ -365,7 +368,7 @@ void ProcessIO(void)
|
|||||||
PacketToPC.Address = PacketFromPC.Address;
|
PacketToPC.Address = PacketFromPC.Address;
|
||||||
PacketToPC.Size = PacketFromPC.Size;
|
PacketToPC.Size = PacketFromPC.Size;
|
||||||
|
|
||||||
pROM = (ROM uint8_t*)PacketFromPC.Address;
|
pROM = (const uint8_t*)PacketFromPC.Address;
|
||||||
for(i = 0; i < PacketFromPC.Size; i++)
|
for(i = 0; i < PacketFromPC.Size; i++)
|
||||||
{
|
{
|
||||||
if(PacketFromPC.Contents[3] == 0xF0) //PacketFromPC.Contents[3] is bits 23:16 of the address.
|
if(PacketFromPC.Contents[3] == 0xF0) //PacketFromPC.Contents[3] is bits 23:16 of the address.
|
||||||
@@ -403,7 +406,7 @@ void ProcessIO(void)
|
|||||||
//in this firmware and is available for requesting by the host software.
|
//in this firmware and is available for requesting by the host software.
|
||||||
PacketToPC.Command = QUERY_EXTENDED_INFO; //Echo the command byte
|
PacketToPC.Command = QUERY_EXTENDED_INFO; //Echo the command byte
|
||||||
PacketToPC.BootloaderVersion = ((unsigned int)BOOTLOADER_VERSION_MAJOR << 8)| BOOTLOADER_VERSION_MINOR;
|
PacketToPC.BootloaderVersion = ((unsigned int)BOOTLOADER_VERSION_MAJOR << 8)| BOOTLOADER_VERSION_MINOR;
|
||||||
PacketToPC.ApplicationVersion = *(ROM unsigned int*)APP_VERSION_ADDRESS;
|
PacketToPC.ApplicationVersion = *(const unsigned int*)APP_VERSION_ADDRESS;
|
||||||
PacketToPC.SignatureAddress = APP_SIGNATURE_ADDRESS;
|
PacketToPC.SignatureAddress = APP_SIGNATURE_ADDRESS;
|
||||||
PacketToPC.SignatureValue = APP_SIGNATURE_VALUE;
|
PacketToPC.SignatureValue = APP_SIGNATURE_VALUE;
|
||||||
PacketToPC.ErasePageSize = ERASE_PAGE_SIZE;
|
PacketToPC.ErasePageSize = ERASE_PAGE_SIZE;
|
||||||
@@ -451,11 +454,11 @@ void ProcessIO(void)
|
|||||||
void SignFlash(void)
|
void SignFlash(void)
|
||||||
{
|
{
|
||||||
static unsigned char i;
|
static unsigned char i;
|
||||||
static ROM uint8_t* pROM;
|
static const uint8_t* pROM;
|
||||||
|
|
||||||
//First read in the erase page contents of the page with the signature WORD
|
//First read in the erase page contents of the page with the signature WORD
|
||||||
//in it, and temporarily store it in a RAM buffer.
|
//in it, and temporarily store it in a RAM buffer.
|
||||||
pROM = (ROM uint8_t*)(APP_SIGNATURE_ADDRESS & ERASE_PAGE_ADDRESS_MASK);
|
pROM = (const uint8_t*)(APP_SIGNATURE_ADDRESS & ERASE_PAGE_ADDRESS_MASK);
|
||||||
for(i = 0; i < ERASE_PAGE_SIZE; i++)
|
for(i = 0; i < ERASE_PAGE_SIZE; i++)
|
||||||
{
|
{
|
||||||
ProgrammingBuffer[i] = *pROM++;
|
ProgrammingBuffer[i] = *pROM++;
|
||||||
@@ -480,7 +483,7 @@ void SignFlash(void)
|
|||||||
//programmed (assuming the flash signature resides on the lowest address
|
//programmed (assuming the flash signature resides on the lowest address
|
||||||
//write page, which is recommended, so that it becomes the first page
|
//write page, which is recommended, so that it becomes the first page
|
||||||
//erased, and the last page programmed).
|
//erased, and the last page programmed).
|
||||||
pROM = (ROM uint8_t*)((APP_SIGNATURE_ADDRESS & ERASE_PAGE_ADDRESS_MASK) + ERASE_PAGE_SIZE - 1); //Point to last byte on the erase page
|
pROM = (const uint8_t*)((APP_SIGNATURE_ADDRESS & ERASE_PAGE_ADDRESS_MASK) + ERASE_PAGE_SIZE - 1); //Point to last byte on the erase page
|
||||||
//TBLPTR = (APP_SIGNATURE_ADDRESS & ERASE_PAGE_ADDRESS_MASK) + ERASE_PAGE_SIZE - 1; //Point to last byte on the erase page
|
//TBLPTR = (APP_SIGNATURE_ADDRESS & ERASE_PAGE_ADDRESS_MASK) + ERASE_PAGE_SIZE - 1; //Point to last byte on the erase page
|
||||||
i = ERASE_PAGE_SIZE - 1;
|
i = ERASE_PAGE_SIZE - 1;
|
||||||
while(1)
|
while(1)
|
||||||
@@ -527,7 +530,16 @@ void SignFlash(void)
|
|||||||
}
|
}
|
||||||
i--;
|
i--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void FugDisXD(unsigned int delay)
|
||||||
|
{
|
||||||
|
while (delay)
|
||||||
|
{
|
||||||
|
delay--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//Before resetting the microcontroller, we should shut down the USB module
|
//Before resetting the microcontroller, we should shut down the USB module
|
||||||
@@ -541,7 +553,10 @@ void SignFlash(void)
|
|||||||
//a new attachment event.
|
//a new attachment event.
|
||||||
void ResetDeviceCleanly(void)
|
void ResetDeviceCleanly(void)
|
||||||
{
|
{
|
||||||
//USBDisableWithLongDelay();
|
// detach USB peripheral & delay
|
||||||
|
USBSoftDetach();
|
||||||
|
FugDisXD(0xFFFF);
|
||||||
|
// reset the microcontroller
|
||||||
Reset();
|
Reset();
|
||||||
Nop();
|
Nop();
|
||||||
Nop();
|
Nop();
|
||||||
@@ -558,16 +573,12 @@ void WriteFlashBlock(void) //Use to write blocks of data to flash.
|
|||||||
static unsigned char BytesTakenFromBuffer;
|
static unsigned char BytesTakenFromBuffer;
|
||||||
static unsigned char CorrectionFactor;
|
static unsigned char CorrectionFactor;
|
||||||
|
|
||||||
#ifdef __XC8__
|
static const uint8_t* pROM;
|
||||||
static ROM uint8_t* pROM;
|
|
||||||
|
|
||||||
pROM = (ROM uint8_t*)(ProgrammedPointer - BufferedDataIndex);
|
pROM = (const uint8_t*)((uint8_t)ProgrammedPointer - BufferedDataIndex);
|
||||||
TBLPTRU = 0x00;
|
TBLPTRU = 0x00;
|
||||||
TBLPTRH = (uint8_t)((uint16_t)pROM >> 8);
|
TBLPTRH = (uint8_t)((uint16_t)pROM >> 8);
|
||||||
TBLPTRL = (uint8_t)pROM;
|
TBLPTRL = (uint8_t)pROM;
|
||||||
#else
|
|
||||||
TBLPTR = (ProgrammedPointer - BufferedDataIndex);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
BytesTakenFromBuffer = 0;
|
BytesTakenFromBuffer = 0;
|
||||||
|
|
||||||
@@ -763,7 +774,18 @@ void UnlockAndActivate(unsigned char UnlockKey)
|
|||||||
|
|
||||||
while(EECON1bits.WR); //Wait until complete (relevant when programming EEPROM, not important when programming flash since processor stalls during flash program)
|
while(EECON1bits.WR); //Wait until complete (relevant when programming EEPROM, not important when programming flash since processor stalls during flash program)
|
||||||
EECON1bits.WREN = 0; //Good practice now to clear the WREN bit, as further protection against any accidental activation of self write/erase operations.
|
EECON1bits.WREN = 0; //Good practice now to clear the WREN bit, as further protection against any accidental activation of self write/erase operations.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Helper function to reduce code size when built with C18. The ClrWdt() is an
|
||||||
|
//inline assembly macro, and on the C18 compiler, if you execute an inline asm
|
||||||
|
//instruction in a C function, it prevents the compiler from implementing
|
||||||
|
//optimizations to that particular function (since the compiler doesn't know what
|
||||||
|
//the user did in the inline asm). Therefore, inline asm is more efficient if
|
||||||
|
//implemented outside of large C functions, when using C18.
|
||||||
|
void ClearWatchdog(void)
|
||||||
|
{
|
||||||
|
ClrWdt();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//Note: The ClrWdt() and "_asm tblrdpostinc _endasm" are inline assembly language
|
//Note: The ClrWdt() and "_asm tblrdpostinc _endasm" are inline assembly language
|
||||||
|
|||||||
@@ -34,14 +34,14 @@ void DisableUSBandExecuteLongDelay(void);
|
|||||||
|
|
||||||
|
|
||||||
//Vector remapping/absolute address constants
|
//Vector remapping/absolute address constants
|
||||||
#define REMAPPED_APPLICATION_RESET_VECTOR 0x1400
|
#define REMAPPED_APPLICATION_RESET_VECTOR 0x1C00
|
||||||
//#define REMAPPED_APPLICATION_HIGH_ISR_VECTOR 0x1408 //See VectorRemap.asm
|
//#define REMAPPED_APPLICATION_HIGH_ISR_VECTOR 0x1C08 //See VectorRemap.asm
|
||||||
//#define REMAPPED_APPLICATION_LOW_ISR_VECTOR 0x1418 //See VectorRemap.asm
|
//#define REMAPPED_APPLICATION_LOW_ISR_VECTOR 0x1C18 //See VectorRemap.asm
|
||||||
#define BOOTLOADER_ABSOLUTE_ENTRY_ADDRESS 0x001C //Execute a "goto 0x001C" inline assembly instruction, if you want to enter the bootloader mode from the application via software
|
#define BOOTLOADER_ABSOLUTE_ENTRY_ADDRESS 0x001C //Execute a "goto 0x001C" inline assembly instruction, if you want to enter the bootloader mode from the application via software
|
||||||
|
|
||||||
#define APP_SIGNATURE_ADDRESS 0x1406 //0x1006 and 0x1007 contains the "signature" WORD, indicating successful erase/program/verify operation
|
#define APP_SIGNATURE_ADDRESS 0x1C06 //0x1C06 and 0x1C07 contains the "signature" WORD, indicating successful erase/program/verify operation
|
||||||
#define APP_SIGNATURE_VALUE 0x600D //leet "GOOD", implying that the erase/program was a success and the bootloader intentionally programmed the APP_SIGNATURE_ADDRESS with this value
|
#define APP_SIGNATURE_VALUE 0x600D //leet "GOOD", implying that the erase/program was a success and the bootloader intentionally programmed the APP_SIGNATURE_ADDRESS with this value
|
||||||
#define APP_VERSION_ADDRESS 0x1416 //0x1016 and 0x1017 should contain the application image firmware version number
|
#define APP_VERSION_ADDRESS 0x1C16 //0x1C16 and 0x1C17 should contain the application image firmware version number
|
||||||
|
|
||||||
#endif /* BOOTLOADER_ */
|
#endif /* BOOTLOADER_ */
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
#include "bootloader.h"
|
#include "bootloader.h"
|
||||||
|
|
||||||
void main(void) {
|
void main(void) {
|
||||||
UserInit();
|
//UserInit();
|
||||||
|
|
||||||
// initialize the USB framework
|
// initialize the USB framework
|
||||||
USBDeviceInit();
|
USBDeviceInit();
|
||||||
|
|||||||
@@ -1,426 +0,0 @@
|
|||||||
/*******************************************************************************
|
|
||||||
Copyright 2016 Microchip Technology Inc. (www.microchip.com)
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
|
|
||||||
To request to license the code under the MLA license (www.microchip.com/mla_license),
|
|
||||||
please contact mla_licensing@microchip.com
|
|
||||||
*******************************************************************************/
|
|
||||||
|
|
||||||
#ifndef __CUSTOMIZED_TYPE_DEFS_H_
|
|
||||||
#define __CUSTOMIZED_TYPE_DEFS_H_
|
|
||||||
|
|
||||||
#include <xc.h>
|
|
||||||
#define ROM const
|
|
||||||
#define rom
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
#ifndef Nop()
|
|
||||||
#define Nop() {asm("NOP");}
|
|
||||||
#endif
|
|
||||||
#ifndef ClrWdt()
|
|
||||||
#define ClrWdt() {asm("CLRWDT");}
|
|
||||||
#endif
|
|
||||||
#ifndef Reset()
|
|
||||||
#define Reset() {asm("RESET");}
|
|
||||||
#endif
|
|
||||||
#ifndef Sleep()
|
|
||||||
#define Sleep() {asm("SLEEP");}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define __EXTENSION
|
|
||||||
|
|
||||||
#if !defined(__PACKED)
|
|
||||||
#define __PACKED
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* get compiler defined type definitions (NULL, size_t, etc) */
|
|
||||||
#include <stddef.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#ifndef TRUE
|
|
||||||
#define TRUE 1
|
|
||||||
#endif
|
|
||||||
#ifndef FALSE
|
|
||||||
#define FALSE 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define PUBLIC /* Function attributes */
|
|
||||||
#define PROTECTED
|
|
||||||
#define PRIVATE static
|
|
||||||
|
|
||||||
/* INT is processor specific in length may vary in size */
|
|
||||||
typedef signed int INT;
|
|
||||||
typedef signed char INT8;
|
|
||||||
typedef signed short int INT16;
|
|
||||||
typedef signed long int INT32;
|
|
||||||
|
|
||||||
/* UINT is processor specific in length may vary in size */
|
|
||||||
typedef unsigned int UINT;
|
|
||||||
typedef unsigned char UINT8;
|
|
||||||
typedef unsigned short int UINT16;
|
|
||||||
typedef unsigned long int UINT32; /* other name for 32-bit integer */
|
|
||||||
|
|
||||||
|
|
||||||
typedef union
|
|
||||||
{
|
|
||||||
UINT8 Val;
|
|
||||||
struct
|
|
||||||
{
|
|
||||||
__EXTENSION UINT8 b0:1;
|
|
||||||
__EXTENSION UINT8 b1:1;
|
|
||||||
__EXTENSION UINT8 b2:1;
|
|
||||||
__EXTENSION UINT8 b3:1;
|
|
||||||
__EXTENSION UINT8 b4:1;
|
|
||||||
__EXTENSION UINT8 b5:1;
|
|
||||||
__EXTENSION UINT8 b6:1;
|
|
||||||
__EXTENSION UINT8 b7:1;
|
|
||||||
} bits;
|
|
||||||
} UINT8_VAL, UINT8_BITS;
|
|
||||||
|
|
||||||
typedef union
|
|
||||||
{
|
|
||||||
UINT16 Val;
|
|
||||||
UINT8 v[2] __PACKED;
|
|
||||||
struct __PACKED
|
|
||||||
{
|
|
||||||
UINT8 LB;
|
|
||||||
UINT8 HB;
|
|
||||||
} byte;
|
|
||||||
struct __PACKED
|
|
||||||
{
|
|
||||||
__EXTENSION UINT8 b0:1;
|
|
||||||
__EXTENSION UINT8 b1:1;
|
|
||||||
__EXTENSION UINT8 b2:1;
|
|
||||||
__EXTENSION UINT8 b3:1;
|
|
||||||
__EXTENSION UINT8 b4:1;
|
|
||||||
__EXTENSION UINT8 b5:1;
|
|
||||||
__EXTENSION UINT8 b6:1;
|
|
||||||
__EXTENSION UINT8 b7:1;
|
|
||||||
__EXTENSION UINT8 b8:1;
|
|
||||||
__EXTENSION UINT8 b9:1;
|
|
||||||
__EXTENSION UINT8 b10:1;
|
|
||||||
__EXTENSION UINT8 b11:1;
|
|
||||||
__EXTENSION UINT8 b12:1;
|
|
||||||
__EXTENSION UINT8 b13:1;
|
|
||||||
__EXTENSION UINT8 b14:1;
|
|
||||||
__EXTENSION UINT8 b15:1;
|
|
||||||
} bits;
|
|
||||||
} UINT16_VAL, UINT16_BITS;
|
|
||||||
|
|
||||||
typedef union
|
|
||||||
{
|
|
||||||
UINT32 Val;
|
|
||||||
UINT16 w[2] __PACKED;
|
|
||||||
UINT8 v[4] __PACKED;
|
|
||||||
struct __PACKED
|
|
||||||
{
|
|
||||||
UINT16 LW;
|
|
||||||
UINT16 HW;
|
|
||||||
} word;
|
|
||||||
struct __PACKED
|
|
||||||
{
|
|
||||||
UINT8 LB;
|
|
||||||
UINT8 HB;
|
|
||||||
UINT8 UB;
|
|
||||||
UINT8 MB;
|
|
||||||
} byte;
|
|
||||||
struct __PACKED
|
|
||||||
{
|
|
||||||
UINT16_VAL low;
|
|
||||||
UINT16_VAL high;
|
|
||||||
}wordUnion;
|
|
||||||
struct __PACKED
|
|
||||||
{
|
|
||||||
__EXTENSION UINT8 b0:1;
|
|
||||||
__EXTENSION UINT8 b1:1;
|
|
||||||
__EXTENSION UINT8 b2:1;
|
|
||||||
__EXTENSION UINT8 b3:1;
|
|
||||||
__EXTENSION UINT8 b4:1;
|
|
||||||
__EXTENSION UINT8 b5:1;
|
|
||||||
__EXTENSION UINT8 b6:1;
|
|
||||||
__EXTENSION UINT8 b7:1;
|
|
||||||
__EXTENSION UINT8 b8:1;
|
|
||||||
__EXTENSION UINT8 b9:1;
|
|
||||||
__EXTENSION UINT8 b10:1;
|
|
||||||
__EXTENSION UINT8 b11:1;
|
|
||||||
__EXTENSION UINT8 b12:1;
|
|
||||||
__EXTENSION UINT8 b13:1;
|
|
||||||
__EXTENSION UINT8 b14:1;
|
|
||||||
__EXTENSION UINT8 b15:1;
|
|
||||||
__EXTENSION UINT8 b16:1;
|
|
||||||
__EXTENSION UINT8 b17:1;
|
|
||||||
__EXTENSION UINT8 b18:1;
|
|
||||||
__EXTENSION UINT8 b19:1;
|
|
||||||
__EXTENSION UINT8 b20:1;
|
|
||||||
__EXTENSION UINT8 b21:1;
|
|
||||||
__EXTENSION UINT8 b22:1;
|
|
||||||
__EXTENSION UINT8 b23:1;
|
|
||||||
__EXTENSION UINT8 b24:1;
|
|
||||||
__EXTENSION UINT8 b25:1;
|
|
||||||
__EXTENSION UINT8 b26:1;
|
|
||||||
__EXTENSION UINT8 b27:1;
|
|
||||||
__EXTENSION UINT8 b28:1;
|
|
||||||
__EXTENSION UINT8 b29:1;
|
|
||||||
__EXTENSION UINT8 b30:1;
|
|
||||||
__EXTENSION UINT8 b31:1;
|
|
||||||
} bits;
|
|
||||||
} UINT32_VAL;
|
|
||||||
|
|
||||||
/***********************************************************************************/
|
|
||||||
|
|
||||||
/* Alternate definitions */
|
|
||||||
typedef void VOID;
|
|
||||||
|
|
||||||
typedef char CHAR8;
|
|
||||||
typedef unsigned char UCHAR8;
|
|
||||||
|
|
||||||
typedef unsigned char BYTE; /* 8-bit unsigned */
|
|
||||||
typedef unsigned short int WORD; /* 16-bit unsigned */
|
|
||||||
typedef unsigned long DWORD; /* 32-bit unsigned */
|
|
||||||
//typedef unsigned long long QWORD; /* 64-bit unsigned */
|
|
||||||
typedef signed char CHAR; /* 8-bit signed */
|
|
||||||
typedef signed short int SHORT; /* 16-bit signed */
|
|
||||||
typedef signed long LONG; /* 32-bit signed */
|
|
||||||
//typedef signed long long LONGLONG; /* 64-bit signed */
|
|
||||||
typedef union
|
|
||||||
{
|
|
||||||
BYTE Val;
|
|
||||||
struct __PACKED
|
|
||||||
{
|
|
||||||
__EXTENSION BYTE b0:1;
|
|
||||||
__EXTENSION BYTE b1:1;
|
|
||||||
__EXTENSION BYTE b2:1;
|
|
||||||
__EXTENSION BYTE b3:1;
|
|
||||||
__EXTENSION BYTE b4:1;
|
|
||||||
__EXTENSION BYTE b5:1;
|
|
||||||
__EXTENSION BYTE b6:1;
|
|
||||||
__EXTENSION BYTE b7:1;
|
|
||||||
} bits;
|
|
||||||
} BYTE_VAL, BYTE_BITS;
|
|
||||||
|
|
||||||
typedef union
|
|
||||||
{
|
|
||||||
WORD Val;
|
|
||||||
BYTE v[2] __PACKED;
|
|
||||||
struct __PACKED
|
|
||||||
{
|
|
||||||
BYTE LB;
|
|
||||||
BYTE HB;
|
|
||||||
} byte;
|
|
||||||
struct __PACKED
|
|
||||||
{
|
|
||||||
__EXTENSION BYTE b0:1;
|
|
||||||
__EXTENSION BYTE b1:1;
|
|
||||||
__EXTENSION BYTE b2:1;
|
|
||||||
__EXTENSION BYTE b3:1;
|
|
||||||
__EXTENSION BYTE b4:1;
|
|
||||||
__EXTENSION BYTE b5:1;
|
|
||||||
__EXTENSION BYTE b6:1;
|
|
||||||
__EXTENSION BYTE b7:1;
|
|
||||||
__EXTENSION BYTE b8:1;
|
|
||||||
__EXTENSION BYTE b9:1;
|
|
||||||
__EXTENSION BYTE b10:1;
|
|
||||||
__EXTENSION BYTE b11:1;
|
|
||||||
__EXTENSION BYTE b12:1;
|
|
||||||
__EXTENSION BYTE b13:1;
|
|
||||||
__EXTENSION BYTE b14:1;
|
|
||||||
__EXTENSION BYTE b15:1;
|
|
||||||
} bits;
|
|
||||||
} WORD_VAL, WORD_BITS;
|
|
||||||
|
|
||||||
typedef union
|
|
||||||
{
|
|
||||||
DWORD Val;
|
|
||||||
WORD w[2] __PACKED;
|
|
||||||
BYTE v[4] __PACKED;
|
|
||||||
struct __PACKED
|
|
||||||
{
|
|
||||||
WORD LW;
|
|
||||||
WORD HW;
|
|
||||||
} word;
|
|
||||||
struct __PACKED
|
|
||||||
{
|
|
||||||
BYTE LB;
|
|
||||||
BYTE HB;
|
|
||||||
BYTE UB;
|
|
||||||
BYTE MB;
|
|
||||||
} byte;
|
|
||||||
struct __PACKED
|
|
||||||
{
|
|
||||||
WORD_VAL low;
|
|
||||||
WORD_VAL high;
|
|
||||||
}wordUnion;
|
|
||||||
struct __PACKED
|
|
||||||
{
|
|
||||||
__EXTENSION BYTE b0:1;
|
|
||||||
__EXTENSION BYTE b1:1;
|
|
||||||
__EXTENSION BYTE b2:1;
|
|
||||||
__EXTENSION BYTE b3:1;
|
|
||||||
__EXTENSION BYTE b4:1;
|
|
||||||
__EXTENSION BYTE b5:1;
|
|
||||||
__EXTENSION BYTE b6:1;
|
|
||||||
__EXTENSION BYTE b7:1;
|
|
||||||
__EXTENSION BYTE b8:1;
|
|
||||||
__EXTENSION BYTE b9:1;
|
|
||||||
__EXTENSION BYTE b10:1;
|
|
||||||
__EXTENSION BYTE b11:1;
|
|
||||||
__EXTENSION BYTE b12:1;
|
|
||||||
__EXTENSION BYTE b13:1;
|
|
||||||
__EXTENSION BYTE b14:1;
|
|
||||||
__EXTENSION BYTE b15:1;
|
|
||||||
__EXTENSION BYTE b16:1;
|
|
||||||
__EXTENSION BYTE b17:1;
|
|
||||||
__EXTENSION BYTE b18:1;
|
|
||||||
__EXTENSION BYTE b19:1;
|
|
||||||
__EXTENSION BYTE b20:1;
|
|
||||||
__EXTENSION BYTE b21:1;
|
|
||||||
__EXTENSION BYTE b22:1;
|
|
||||||
__EXTENSION BYTE b23:1;
|
|
||||||
__EXTENSION BYTE b24:1;
|
|
||||||
__EXTENSION BYTE b25:1;
|
|
||||||
__EXTENSION BYTE b26:1;
|
|
||||||
__EXTENSION BYTE b27:1;
|
|
||||||
__EXTENSION BYTE b28:1;
|
|
||||||
__EXTENSION BYTE b29:1;
|
|
||||||
__EXTENSION BYTE b30:1;
|
|
||||||
__EXTENSION BYTE b31:1;
|
|
||||||
} bits;
|
|
||||||
} DWORD_VAL;
|
|
||||||
|
|
||||||
/* MPLAB C Compiler for PIC18 does not support 64-bit integers */
|
|
||||||
/*typedef union
|
|
||||||
{
|
|
||||||
QWORD Val;
|
|
||||||
DWORD d[2] __PACKED;
|
|
||||||
WORD w[4] __PACKED;
|
|
||||||
BYTE v[8] __PACKED;
|
|
||||||
struct __PACKED
|
|
||||||
{
|
|
||||||
DWORD LD;
|
|
||||||
DWORD HD;
|
|
||||||
} dword;
|
|
||||||
struct __PACKED
|
|
||||||
{
|
|
||||||
WORD LW;
|
|
||||||
WORD HW;
|
|
||||||
WORD UW;
|
|
||||||
WORD MW;
|
|
||||||
} word;
|
|
||||||
struct __PACKED
|
|
||||||
{
|
|
||||||
__EXTENSION BYTE b0:1;
|
|
||||||
__EXTENSION BYTE b1:1;
|
|
||||||
__EXTENSION BYTE b2:1;
|
|
||||||
__EXTENSION BYTE b3:1;
|
|
||||||
__EXTENSION BYTE b4:1;
|
|
||||||
__EXTENSION BYTE b5:1;
|
|
||||||
__EXTENSION BYTE b6:1;
|
|
||||||
__EXTENSION BYTE b7:1;
|
|
||||||
__EXTENSION BYTE b8:1;
|
|
||||||
__EXTENSION BYTE b9:1;
|
|
||||||
__EXTENSION BYTE b10:1;
|
|
||||||
__EXTENSION BYTE b11:1;
|
|
||||||
__EXTENSION BYTE b12:1;
|
|
||||||
__EXTENSION BYTE b13:1;
|
|
||||||
__EXTENSION BYTE b14:1;
|
|
||||||
__EXTENSION BYTE b15:1;
|
|
||||||
__EXTENSION BYTE b16:1;
|
|
||||||
__EXTENSION BYTE b17:1;
|
|
||||||
__EXTENSION BYTE b18:1;
|
|
||||||
__EXTENSION BYTE b19:1;
|
|
||||||
__EXTENSION BYTE b20:1;
|
|
||||||
__EXTENSION BYTE b21:1;
|
|
||||||
__EXTENSION BYTE b22:1;
|
|
||||||
__EXTENSION BYTE b23:1;
|
|
||||||
__EXTENSION BYTE b24:1;
|
|
||||||
__EXTENSION BYTE b25:1;
|
|
||||||
__EXTENSION BYTE b26:1;
|
|
||||||
__EXTENSION BYTE b27:1;
|
|
||||||
__EXTENSION BYTE b28:1;
|
|
||||||
__EXTENSION BYTE b29:1;
|
|
||||||
__EXTENSION BYTE b30:1;
|
|
||||||
__EXTENSION BYTE b31:1;
|
|
||||||
__EXTENSION BYTE b32:1;
|
|
||||||
__EXTENSION BYTE b33:1;
|
|
||||||
__EXTENSION BYTE b34:1;
|
|
||||||
__EXTENSION BYTE b35:1;
|
|
||||||
__EXTENSION BYTE b36:1;
|
|
||||||
__EXTENSION BYTE b37:1;
|
|
||||||
__EXTENSION BYTE b38:1;
|
|
||||||
__EXTENSION BYTE b39:1;
|
|
||||||
__EXTENSION BYTE b40:1;
|
|
||||||
__EXTENSION BYTE b41:1;
|
|
||||||
__EXTENSION BYTE b42:1;
|
|
||||||
__EXTENSION BYTE b43:1;
|
|
||||||
__EXTENSION BYTE b44:1;
|
|
||||||
__EXTENSION BYTE b45:1;
|
|
||||||
__EXTENSION BYTE b46:1;
|
|
||||||
__EXTENSION BYTE b47:1;
|
|
||||||
__EXTENSION BYTE b48:1;
|
|
||||||
__EXTENSION BYTE b49:1;
|
|
||||||
__EXTENSION BYTE b50:1;
|
|
||||||
__EXTENSION BYTE b51:1;
|
|
||||||
__EXTENSION BYTE b52:1;
|
|
||||||
__EXTENSION BYTE b53:1;
|
|
||||||
__EXTENSION BYTE b54:1;
|
|
||||||
__EXTENSION BYTE b55:1;
|
|
||||||
__EXTENSION BYTE b56:1;
|
|
||||||
__EXTENSION BYTE b57:1;
|
|
||||||
__EXTENSION BYTE b58:1;
|
|
||||||
__EXTENSION BYTE b59:1;
|
|
||||||
__EXTENSION BYTE b60:1;
|
|
||||||
__EXTENSION BYTE b61:1;
|
|
||||||
__EXTENSION BYTE b62:1;
|
|
||||||
__EXTENSION BYTE b63:1;
|
|
||||||
} bits;
|
|
||||||
} QWORD_VAL;
|
|
||||||
*/
|
|
||||||
#undef __EXTENSION
|
|
||||||
|
|
||||||
#ifndef uint24_t
|
|
||||||
#define uint24_t uint32_t
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef void(*pFunc)(void);
|
|
||||||
/*
|
|
||||||
typedef union _POINTER
|
|
||||||
{
|
|
||||||
struct
|
|
||||||
{
|
|
||||||
BYTE bLow;
|
|
||||||
BYTE bHigh;
|
|
||||||
//BYTE bUpper;
|
|
||||||
};
|
|
||||||
uint16_t _word; // bLow & bHigh
|
|
||||||
|
|
||||||
//pFunc _pFunc; // Usage: ptr.pFunc(); Init: ptr.pFunc = &<Function>;
|
|
||||||
|
|
||||||
BYTE* bRam; // Ram byte pointer: 2 bytes pointer pointing
|
|
||||||
// to 1 byte of data
|
|
||||||
uint16_t* wRam; // Ram word poitner: 2 bytes poitner pointing
|
|
||||||
// to 2 bytes of data
|
|
||||||
|
|
||||||
ROM BYTE* bRom; // Size depends on compiler setting
|
|
||||||
ROM WORD* wRom;
|
|
||||||
//ROM near BYTE* nbRom; // Near = 2 bytes pointer
|
|
||||||
//ROM near uint16_t* nwRom;
|
|
||||||
//ROM far BYTE* fbRom; // Far = 3 bytes pointer
|
|
||||||
//ROM far uint16_t* fwRom;
|
|
||||||
} POINTER;
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* __CUSTOMIZED_TYPE_DEFS_H_ */
|
|
||||||
@@ -171,8 +171,9 @@
|
|||||||
#define HID_NUM_OF_DSC 1
|
#define HID_NUM_OF_DSC 1
|
||||||
#define HID_RPT01_SIZE 29
|
#define HID_RPT01_SIZE 29
|
||||||
|
|
||||||
#define HID_IN_EP 0
|
#define HID_EP 1
|
||||||
#define HID_OUT_EP 1
|
#define HID_IN_EP HID_EP
|
||||||
|
#define HID_OUT_EP HID_EP
|
||||||
|
|
||||||
/** DEFINITIONS ****************************************************/
|
/** DEFINITIONS ****************************************************/
|
||||||
|
|
||||||
|
|||||||
@@ -55,8 +55,6 @@ bool USER_USB_CALLBACK_EVENT_HANDLER(USB_EVENT event, void *pdata, uint16_t size
|
|||||||
case EVENT_CONFIGURED:
|
case EVENT_CONFIGURED:
|
||||||
// When the device is configured, we should (re)initialize our state variables
|
// When the device is configured, we should (re)initialize our state variables
|
||||||
UserInit();
|
UserInit();
|
||||||
USBEnableEndpoint(HID_IN_EP, USB_IN_ENABLED|USB_HANDSHAKE_ENABLED|USB_DISALLOW_SETUP);
|
|
||||||
USBEnableEndpoint(HID_OUT_EP, USB_OUT_ENABLED|USB_HANDSHAKE_ENABLED|USB_DISALLOW_SETUP);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case EVENT_SET_DESCRIPTOR:
|
case EVENT_SET_DESCRIPTOR:
|
||||||
|
|||||||
Reference in New Issue
Block a user