added bootloader project - currently only able to be enumerated by USB host but doesn't do anything else yet
This commit is contained in:
113
bootloader/clubdance_v2_bootloader.X/Makefile
Normal file
113
bootloader/clubdance_v2_bootloader.X/Makefile
Normal file
@@ -0,0 +1,113 @@
|
||||
#
|
||||
# There exist several targets which are by default empty and which can be
|
||||
# used for execution of your targets. These targets are usually executed
|
||||
# before and after some main targets. They are:
|
||||
#
|
||||
# .build-pre: called before 'build' target
|
||||
# .build-post: called after 'build' target
|
||||
# .clean-pre: called before 'clean' target
|
||||
# .clean-post: called after 'clean' target
|
||||
# .clobber-pre: called before 'clobber' target
|
||||
# .clobber-post: called after 'clobber' target
|
||||
# .all-pre: called before 'all' target
|
||||
# .all-post: called after 'all' target
|
||||
# .help-pre: called before 'help' target
|
||||
# .help-post: called after 'help' target
|
||||
#
|
||||
# Targets beginning with '.' are not intended to be called on their own.
|
||||
#
|
||||
# Main targets can be executed directly, and they are:
|
||||
#
|
||||
# build build a specific configuration
|
||||
# clean remove built files from a configuration
|
||||
# clobber remove all built files
|
||||
# all build all configurations
|
||||
# help print help mesage
|
||||
#
|
||||
# Targets .build-impl, .clean-impl, .clobber-impl, .all-impl, and
|
||||
# .help-impl are implemented in nbproject/makefile-impl.mk.
|
||||
#
|
||||
# Available make variables:
|
||||
#
|
||||
# CND_BASEDIR base directory for relative paths
|
||||
# CND_DISTDIR default top distribution directory (build artifacts)
|
||||
# CND_BUILDDIR default top build directory (object files, ...)
|
||||
# CONF name of current configuration
|
||||
# CND_ARTIFACT_DIR_${CONF} directory of build artifact (current configuration)
|
||||
# CND_ARTIFACT_NAME_${CONF} name of build artifact (current configuration)
|
||||
# CND_ARTIFACT_PATH_${CONF} path to build artifact (current configuration)
|
||||
# CND_PACKAGE_DIR_${CONF} directory of package (current configuration)
|
||||
# CND_PACKAGE_NAME_${CONF} name of package (current configuration)
|
||||
# CND_PACKAGE_PATH_${CONF} path to package (current configuration)
|
||||
#
|
||||
# NOCDDL
|
||||
|
||||
|
||||
# Environment
|
||||
MKDIR=mkdir
|
||||
CP=cp
|
||||
CCADMIN=CCadmin
|
||||
RANLIB=ranlib
|
||||
|
||||
|
||||
# build
|
||||
build: .build-post
|
||||
|
||||
.build-pre:
|
||||
# Add your pre 'build' code here...
|
||||
|
||||
.build-post: .build-impl
|
||||
# Add your post 'build' code here...
|
||||
|
||||
|
||||
# clean
|
||||
clean: .clean-post
|
||||
|
||||
.clean-pre:
|
||||
# Add your pre 'clean' code here...
|
||||
# WARNING: the IDE does not call this target since it takes a long time to
|
||||
# simply run make. Instead, the IDE removes the configuration directories
|
||||
# under build and dist directly without calling make.
|
||||
# This target is left here so people can do a clean when running a clean
|
||||
# outside the IDE.
|
||||
|
||||
.clean-post: .clean-impl
|
||||
# Add your post 'clean' code here...
|
||||
|
||||
|
||||
# clobber
|
||||
clobber: .clobber-post
|
||||
|
||||
.clobber-pre:
|
||||
# Add your pre 'clobber' code here...
|
||||
|
||||
.clobber-post: .clobber-impl
|
||||
# Add your post 'clobber' code here...
|
||||
|
||||
|
||||
# all
|
||||
all: .all-post
|
||||
|
||||
.all-pre:
|
||||
# Add your pre 'all' code here...
|
||||
|
||||
.all-post: .all-impl
|
||||
# Add your post 'all' code here...
|
||||
|
||||
|
||||
# help
|
||||
help: .help-post
|
||||
|
||||
.help-pre:
|
||||
# Add your pre 'help' code here...
|
||||
|
||||
.help-post: .help-impl
|
||||
# Add your post 'help' code here...
|
||||
|
||||
|
||||
|
||||
# include project implementation makefile
|
||||
include nbproject/Makefile-impl.mk
|
||||
|
||||
# include project make variables
|
||||
include nbproject/Makefile-variables.mk
|
||||
@@ -0,0 +1,229 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configurationDescriptor version="65">
|
||||
<logicalFolder name="root" displayName="root" projectFiles="true">
|
||||
<logicalFolder name="f1" displayName="common_src" projectFiles="true">
|
||||
<logicalFolder name="framework" displayName="framework" projectFiles="true">
|
||||
<logicalFolder name="usb" displayName="usb" projectFiles="true">
|
||||
<logicalFolder name="inc" displayName="inc" projectFiles="true">
|
||||
<itemPath>../../common_src/framework/usb/inc/usb.h</itemPath>
|
||||
<itemPath>../../common_src/framework/usb/inc/usb_ch9.h</itemPath>
|
||||
<itemPath>../../common_src/framework/usb/inc/usb_common.h</itemPath>
|
||||
<itemPath>../../common_src/framework/usb/inc/usb_device.h</itemPath>
|
||||
<itemPath>../../common_src/framework/usb/inc/usb_device_hid.h</itemPath>
|
||||
<itemPath>../../common_src/framework/usb/inc/usb_hal.h</itemPath>
|
||||
<itemPath>../../common_src/framework/usb/inc/usb_hal_pic18.h</itemPath>
|
||||
</logicalFolder>
|
||||
<logicalFolder name="src" displayName="src" projectFiles="true">
|
||||
<itemPath>../../common_src/framework/usb/src/usb_device.c</itemPath>
|
||||
<itemPath>../../common_src/framework/usb/src/usb_device_hid.c</itemPath>
|
||||
</logicalFolder>
|
||||
</logicalFolder>
|
||||
</logicalFolder>
|
||||
<itemPath>../../common_src/system.c</itemPath>
|
||||
</logicalFolder>
|
||||
<logicalFolder name="HeaderFiles"
|
||||
displayName="Header Files"
|
||||
projectFiles="true">
|
||||
<itemPath>../src/usb_config.h</itemPath>
|
||||
</logicalFolder>
|
||||
<logicalFolder name="LinkerScript"
|
||||
displayName="Linker Files"
|
||||
projectFiles="true">
|
||||
</logicalFolder>
|
||||
<logicalFolder name="SourceFiles"
|
||||
displayName="Source Files"
|
||||
projectFiles="true">
|
||||
<itemPath>../src/usb_descriptors.c</itemPath>
|
||||
<itemPath>../src/usb_events.c</itemPath>
|
||||
<itemPath>../src/main.c</itemPath>
|
||||
</logicalFolder>
|
||||
<logicalFolder name="ExternalFiles"
|
||||
displayName="Important Files"
|
||||
projectFiles="false">
|
||||
<itemPath>Makefile</itemPath>
|
||||
</logicalFolder>
|
||||
</logicalFolder>
|
||||
<sourceRootList>
|
||||
<Elem>../../common_src</Elem>
|
||||
<Elem>../framework</Elem>
|
||||
<Elem>../src</Elem>
|
||||
</sourceRootList>
|
||||
<projectmakefile>Makefile</projectmakefile>
|
||||
<confs>
|
||||
<conf name="default" type="2">
|
||||
<toolsSet>
|
||||
<developmentServer>localhost</developmentServer>
|
||||
<targetDevice>PIC18F2550</targetDevice>
|
||||
<targetHeader></targetHeader>
|
||||
<targetPluginBoard></targetPluginBoard>
|
||||
<platformTool>PICkit3PlatformTool</platformTool>
|
||||
<languageToolchain>XC8</languageToolchain>
|
||||
<languageToolchainVersion>2.05</languageToolchainVersion>
|
||||
<platform>3</platform>
|
||||
</toolsSet>
|
||||
<packs>
|
||||
<pack name="PIC18Fxxxx_DFP" vendor="Microchip" version="1.0.9"/>
|
||||
</packs>
|
||||
<compileType>
|
||||
<linkerTool>
|
||||
<linkerLibItems>
|
||||
</linkerLibItems>
|
||||
</linkerTool>
|
||||
<archiverTool>
|
||||
</archiverTool>
|
||||
<loading>
|
||||
<useAlternateLoadableFile>false</useAlternateLoadableFile>
|
||||
<parseOnProdLoad>false</parseOnProdLoad>
|
||||
<alternateLoadableFile></alternateLoadableFile>
|
||||
</loading>
|
||||
<subordinates>
|
||||
</subordinates>
|
||||
</compileType>
|
||||
<makeCustomizationType>
|
||||
<makeCustomizationPreStepEnabled>false</makeCustomizationPreStepEnabled>
|
||||
<makeCustomizationPreStep></makeCustomizationPreStep>
|
||||
<makeCustomizationPostStepEnabled>false</makeCustomizationPostStepEnabled>
|
||||
<makeCustomizationPostStep></makeCustomizationPostStep>
|
||||
<makeCustomizationPutChecksumInUserID>false</makeCustomizationPutChecksumInUserID>
|
||||
<makeCustomizationEnableLongLines>false</makeCustomizationEnableLongLines>
|
||||
<makeCustomizationNormalizeHexFile>false</makeCustomizationNormalizeHexFile>
|
||||
</makeCustomizationType>
|
||||
<HI-TECH-COMP>
|
||||
<property key="additional-warnings" value="true"/>
|
||||
<property key="asmlist" value="true"/>
|
||||
<property key="default-bitfield-type" value="true"/>
|
||||
<property key="default-char-type" value="true"/>
|
||||
<property key="define-macros" value=""/>
|
||||
<property key="disable-optimizations" value="true"/>
|
||||
<property key="extra-include-directories"
|
||||
value="..\src;..\..\common_src\framework\usb\inc"/>
|
||||
<property key="favor-optimization-for" value="-speed,+space"/>
|
||||
<property key="garbage-collect-data" value="true"/>
|
||||
<property key="garbage-collect-functions" value="true"/>
|
||||
<property key="identifier-length" value="255"/>
|
||||
<property key="local-generation" value="false"/>
|
||||
<property key="operation-mode" value="pro"/>
|
||||
<property key="opt-xc8-compiler-strict_ansi" value="false"/>
|
||||
<property key="optimization-assembler" value="true"/>
|
||||
<property key="optimization-assembler-files" value="true"/>
|
||||
<property key="optimization-debug" value="false"/>
|
||||
<property key="optimization-invariant-enable" value="false"/>
|
||||
<property key="optimization-invariant-value" value="16"/>
|
||||
<property key="optimization-level" value="-O0"/>
|
||||
<property key="optimization-speed" value="false"/>
|
||||
<property key="optimization-stable-enable" value="false"/>
|
||||
<property key="pack-struct" value="true"/>
|
||||
<property key="preprocess-assembler" value="true"/>
|
||||
<property key="short-enums" value="true"/>
|
||||
<property key="undefine-macros" value=""/>
|
||||
<property key="use-cci" value="false"/>
|
||||
<property key="use-iar" value="false"/>
|
||||
<property key="verbose" value="false"/>
|
||||
<property key="warning-level" value="-3"/>
|
||||
<property key="what-to-do" value="require"/>
|
||||
</HI-TECH-COMP>
|
||||
<HI-TECH-LINK>
|
||||
<property key="additional-options-checksum" value=""/>
|
||||
<property key="additional-options-code-offset" value=""/>
|
||||
<property key="additional-options-command-line" value=""/>
|
||||
<property key="additional-options-errata" value=""/>
|
||||
<property key="additional-options-extend-address" value="false"/>
|
||||
<property key="additional-options-trace-type" value=""/>
|
||||
<property key="additional-options-use-response-files" value="false"/>
|
||||
<property key="backup-reset-condition-flags" value="false"/>
|
||||
<property key="calibrate-oscillator" value="false"/>
|
||||
<property key="calibrate-oscillator-value" value="0x3400"/>
|
||||
<property key="clear-bss" value="true"/>
|
||||
<property key="code-model-external" value="wordwrite"/>
|
||||
<property key="code-model-rom" value="default,-1400-7FFF"/>
|
||||
<property key="create-html-files" value="false"/>
|
||||
<property key="data-model-ram" value=""/>
|
||||
<property key="data-model-size-of-double" value="32"/>
|
||||
<property key="data-model-size-of-double-gcc" value="no-short-double"/>
|
||||
<property key="data-model-size-of-float" value="32"/>
|
||||
<property key="data-model-size-of-float-gcc" value="no-short-float"/>
|
||||
<property key="display-class-usage" value="false"/>
|
||||
<property key="display-hex-usage" value="false"/>
|
||||
<property key="display-overall-usage" value="true"/>
|
||||
<property key="display-psect-usage" value="false"/>
|
||||
<property key="extra-lib-directories" value=""/>
|
||||
<property key="fill-flash-options-addr" value=""/>
|
||||
<property key="fill-flash-options-const" value=""/>
|
||||
<property key="fill-flash-options-how" value="0"/>
|
||||
<property key="fill-flash-options-inc-const" value="1"/>
|
||||
<property key="fill-flash-options-increment" value=""/>
|
||||
<property key="fill-flash-options-seq" value=""/>
|
||||
<property key="fill-flash-options-what" value="0"/>
|
||||
<property key="format-hex-file-for-download" value="false"/>
|
||||
<property key="initialize-data" value="true"/>
|
||||
<property key="input-libraries" value="libm"/>
|
||||
<property key="keep-generated-startup.as" value="false"/>
|
||||
<property key="link-in-c-library" value="true"/>
|
||||
<property key="link-in-c-library-gcc" value="-mc90lib"/>
|
||||
<property key="link-in-peripheral-library" value="false"/>
|
||||
<property key="managed-stack" value="false"/>
|
||||
<property key="opt-xc8-linker-file" value="false"/>
|
||||
<property key="opt-xc8-linker-link_startup" value="false"/>
|
||||
<property key="opt-xc8-linker-serial" value=""/>
|
||||
<property key="program-the-device-with-default-config-words" value="true"/>
|
||||
<property key="remove-unused-sections" value="true"/>
|
||||
</HI-TECH-LINK>
|
||||
<PICkit3PlatformTool>
|
||||
<property key="AutoSelectMemRanges" value="auto"/>
|
||||
<property key="Freeze Peripherals" value="true"/>
|
||||
<property key="SecureSegment.SegmentProgramming" value="FullChipProgramming"/>
|
||||
<property key="ToolFirmwareFilePath"
|
||||
value="Press to browse for a specific firmware version"/>
|
||||
<property key="ToolFirmwareOption.UseLatestFirmware" value="true"/>
|
||||
<property key="debugoptions.useswbreakpoints" value="false"/>
|
||||
<property key="firmware.download.all" value="false"/>
|
||||
<property key="hwtoolclock.frcindebug" value="false"/>
|
||||
<property key="memories.aux" value="false"/>
|
||||
<property key="memories.bootflash" value="true"/>
|
||||
<property key="memories.configurationmemory" value="true"/>
|
||||
<property key="memories.configurationmemory2" value="true"/>
|
||||
<property key="memories.dataflash" value="true"/>
|
||||
<property key="memories.eeprom" value="true"/>
|
||||
<property key="memories.flashdata" value="true"/>
|
||||
<property key="memories.id" value="true"/>
|
||||
<property key="memories.instruction.ram" value="true"/>
|
||||
<property key="memories.instruction.ram.ranges"
|
||||
value="${memories.instruction.ram.ranges}"/>
|
||||
<property key="memories.programmemory" value="true"/>
|
||||
<property key="memories.programmemory.ranges" value="0-7fff"/>
|
||||
<property key="poweroptions.powerenable" value="false"/>
|
||||
<property key="programmertogo.imagename" value=""/>
|
||||
<property key="programoptions.donoteraseauxmem" value="false"/>
|
||||
<property key="programoptions.eraseb4program" value="true"/>
|
||||
<property key="programoptions.pgmspeed" value="2"/>
|
||||
<property key="programoptions.preservedataflash" value="false"/>
|
||||
<property key="programoptions.preservedataflash.ranges"
|
||||
value="${programoptions.preservedataflash.ranges}"/>
|
||||
<property key="programoptions.preserveeeprom" value="false"/>
|
||||
<property key="programoptions.preserveeeprom.ranges" value="0-ff"/>
|
||||
<property key="programoptions.preserveprogram.ranges" value=""/>
|
||||
<property key="programoptions.preserveprogramrange" value="false"/>
|
||||
<property key="programoptions.preserveuserid" value="false"/>
|
||||
<property key="programoptions.programcalmem" value="false"/>
|
||||
<property key="programoptions.programuserotp" value="false"/>
|
||||
<property key="programoptions.testmodeentrymethod" value="VDDFirst"/>
|
||||
<property key="programoptions.usehighvoltageonmclr" value="false"/>
|
||||
<property key="programoptions.uselvpprogramming" value="false"/>
|
||||
<property key="voltagevalue" value="5.0"/>
|
||||
</PICkit3PlatformTool>
|
||||
<XC8-config-global>
|
||||
<property key="advanced-elf" value="true"/>
|
||||
<property key="gcc-opt-driver-new" value="true"/>
|
||||
<property key="gcc-opt-std" value="-std=c90"/>
|
||||
<property key="gcc-output-file-format" value="dwarf-3"/>
|
||||
<property key="omit-pack-options" value="false"/>
|
||||
<property key="output-file-format" value="-mcof,+elf"/>
|
||||
<property key="stack-size-high" value="auto"/>
|
||||
<property key="stack-size-low" value="auto"/>
|
||||
<property key="stack-size-main" value="auto"/>
|
||||
<property key="stack-type" value="compiled"/>
|
||||
<property key="user-pack-device-support" value=""/>
|
||||
</XC8-config-global>
|
||||
</conf>
|
||||
</confs>
|
||||
</configurationDescriptor>
|
||||
31
bootloader/clubdance_v2_bootloader.X/nbproject/project.xml
Normal file
31
bootloader/clubdance_v2_bootloader.X/nbproject/project.xml
Normal file
@@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://www.netbeans.org/ns/project/1">
|
||||
<type>com.microchip.mplab.nbide.embedded.makeproject</type>
|
||||
<configuration>
|
||||
<data xmlns="http://www.netbeans.org/ns/make-project/1">
|
||||
<name>clubdance_v2_bootloader</name>
|
||||
<creation-uuid>83d0bbc4-5bc9-4994-8d56-e4dbd464f4f2</creation-uuid>
|
||||
<make-project-type>0</make-project-type>
|
||||
<c-extensions>c</c-extensions>
|
||||
<cpp-extensions/>
|
||||
<header-extensions>h</header-extensions>
|
||||
<asminc-extensions/>
|
||||
<sourceEncoding>ISO-8859-1</sourceEncoding>
|
||||
<make-dep-projects/>
|
||||
<sourceRootList>
|
||||
<sourceRootElem>../../common_src</sourceRootElem>
|
||||
<sourceRootElem>../framework</sourceRootElem>
|
||||
<sourceRootElem>../src</sourceRootElem>
|
||||
</sourceRootList>
|
||||
<confList>
|
||||
<confElem>
|
||||
<name>default</name>
|
||||
<type>2</type>
|
||||
</confElem>
|
||||
</confList>
|
||||
<formatting>
|
||||
<project-formatting-style>false</project-formatting-style>
|
||||
</formatting>
|
||||
</data>
|
||||
</configuration>
|
||||
</project>
|
||||
27
bootloader/src/main.c
Normal file
27
bootloader/src/main.c
Normal file
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* File: main.c
|
||||
* Author: justin
|
||||
*
|
||||
* Created on August 9, 2019, 6:14 PM
|
||||
*/
|
||||
|
||||
#include <xc.h>
|
||||
#include "usb.h"
|
||||
|
||||
void main(void) {
|
||||
// initialize the USB framework
|
||||
USBDeviceInit();
|
||||
USBDeviceAttach();
|
||||
|
||||
while(1)
|
||||
{
|
||||
USBDeviceTasks();
|
||||
|
||||
// do nothing if: not connected to USB host, or the host put us in suspend state
|
||||
if((USBGetDeviceState() < CONFIGURED_STATE) | USBIsDeviceSuspended())
|
||||
continue;
|
||||
|
||||
// run application specific tasks
|
||||
//DANCEPAD_Tasks();
|
||||
}
|
||||
}
|
||||
176
bootloader/src/usb_config.h
Normal file
176
bootloader/src/usb_config.h
Normal file
@@ -0,0 +1,176 @@
|
||||
/*************************************************************************
|
||||
* Copyright (C) 2019 by Justin Byers
|
||||
*
|
||||
* This file is part of clubdance_v2.
|
||||
*
|
||||
* clubdance_v2 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.
|
||||
*
|
||||
* clubdance_v2 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 clubdance_v2. If not, see <https://www.gnu.org/licenses/>.
|
||||
*************************************************************************/
|
||||
/**
|
||||
* @file usb_config.h
|
||||
* @author Justin Byers
|
||||
* @date 6 Aug 2019
|
||||
* @brief Configuration of the MLA USB framework.
|
||||
*
|
||||
* Descriptor specific type definitions are defined in: usbd.h
|
||||
*/
|
||||
#ifndef USBCFG_H
|
||||
#define USBCFG_H
|
||||
|
||||
#include <usb_ch9.h>
|
||||
|
||||
/** DEFINITIONS ****************************************************/
|
||||
#define USB_EP0_BUFF_SIZE 8 // Valid Options: 8, 16, 32, or 64 bytes.
|
||||
// Using larger options take more SRAM, but
|
||||
// does not provide much advantage in most types
|
||||
// of applications. Exceptions to this, are applications
|
||||
// that use EP0 IN or OUT for sending large amounts of
|
||||
// application related data.
|
||||
|
||||
#define USB_MAX_NUM_INT 1 //Set this number to match the maximum interface number used in the descriptors for this firmware project
|
||||
#define USB_MAX_EP_NUMBER 1 //Set this number to match the maximum endpoint number used in the descriptors for this firmware project
|
||||
|
||||
//Device descriptor - if these two definitions are not defined then
|
||||
// a const USB_DEVICE_DESCRIPTOR variable by the exact name of device_dsc
|
||||
// must exist.
|
||||
#define USB_USER_DEVICE_DESCRIPTOR &device_dsc
|
||||
#define USB_USER_DEVICE_DESCRIPTOR_INCLUDE extern const USB_DEVICE_DESCRIPTOR device_dsc
|
||||
|
||||
//Configuration descriptors - if these two definitions do not exist then
|
||||
// a const BYTE *const variable named exactly USB_CD_Ptr[] must exist.
|
||||
#define USB_USER_CONFIG_DESCRIPTOR USB_CD_Ptr
|
||||
#define USB_USER_CONFIG_DESCRIPTOR_INCLUDE extern const uint8_t *const USB_CD_Ptr[]
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//Select an endpoint ping-pong bufferring mode. Some microcontrollers only
|
||||
//support certain modes. For most applications, it is recommended to use either
|
||||
//the USB_PING_PONG__FULL_PING_PONG or USB_PING_PONG__EP0_OUT_ONLY options.
|
||||
//The other settings are supported on some devices, but they are not
|
||||
//recommended, as they offer inferior control transfer timing performance.
|
||||
//See inline code comments in usb_device.c for additional details.
|
||||
//Enabling ping pong bufferring on an endpoint generally increases firmware
|
||||
//overhead somewhat, but when both buffers are used simultaneously in the
|
||||
//firmware, can offer better sustained bandwidth, especially for OUT endpoints.
|
||||
//------------------------------------------------------
|
||||
//#define USB_PING_PONG_MODE USB_PING_PONG__NO_PING_PONG //Not recommended
|
||||
#define USB_PING_PONG_MODE USB_PING_PONG__FULL_PING_PONG //A good all around setting
|
||||
//#define USB_PING_PONG_MODE USB_PING_PONG__EP0_OUT_ONLY //Another good setting
|
||||
//#define USB_PING_PONG_MODE USB_PING_PONG__ALL_BUT_EP0 //Not recommended
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//Select a USB stack operating mode. In the USB_INTERRUPT mode, the USB stack
|
||||
//main task handler gets called only when necessary as an interrupt handler.
|
||||
//This can potentially minimize CPU utilization, but adds context saving
|
||||
//and restoring overhead associated with interrupts, which can potentially
|
||||
//decrease performance.
|
||||
//When the USB_POLLING mode is selected, the USB stack main task handler
|
||||
//(ex: USBDeviceTasks()) must be called periodically by the application firmware
|
||||
//at a minimum rate as described in the inline code comments in usb_device.c.
|
||||
//------------------------------------------------------
|
||||
#define USB_POLLING
|
||||
//#define USB_INTERRUPT
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/* Parameter definitions are defined in usb_device.h */
|
||||
#define USB_PULLUP_OPTION USB_PULLUP_ENABLE
|
||||
//#define USB_PULLUP_OPTION USB_PULLUP_DISABLED
|
||||
|
||||
#define USB_TRANSCEIVER_OPTION USB_INTERNAL_TRANSCEIVER
|
||||
//External Transceiver support is not available on all product families. Please
|
||||
// refer to the product family datasheet for more information if this feature
|
||||
// is available on the target processor.
|
||||
//#define USB_TRANSCEIVER_OPTION USB_EXTERNAL_TRANSCEIVER
|
||||
|
||||
#define USB_SPEED_OPTION USB_FULL_SPEED
|
||||
//#define USB_SPEED_OPTION USB_LOW_SPEED //(this mode is only supported on some microcontrollers)
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------
|
||||
//Option to enable auto-arming of the status stage of control transfers, if no
|
||||
//"progress" has been made for the USB_STATUS_STAGE_TIMEOUT value.
|
||||
//If progress is made (any successful transactions completing on EP0 IN or OUT)
|
||||
//the timeout counter gets reset to the USB_STATUS_STAGE_TIMEOUT value.
|
||||
//
|
||||
//During normal control transfer processing, the USB stack or the application
|
||||
//firmware will call USBCtrlEPAllowStatusStage() as soon as the firmware is finished
|
||||
//processing the control transfer. Therefore, the status stage completes as
|
||||
//quickly as is physically possible. The USB_ENABLE_STATUS_STAGE_TIMEOUTS
|
||||
//feature, and the USB_STATUS_STAGE_TIMEOUT value are only relevant, when:
|
||||
//1. The application uses the USBDeferStatusStage() API function, but never calls
|
||||
// USBCtrlEPAllowStatusStage(). Or:
|
||||
//2. The application uses host to device (OUT) control transfers with data stage,
|
||||
// and some abnormal error occurs, where the host might try to abort the control
|
||||
// transfer, before it has sent all of the data it claimed it was going to send.
|
||||
//
|
||||
//If the application firmware never uses the USBDeferStatusStage() API function,
|
||||
//and it never uses host to device control transfers with data stage, then
|
||||
//it is not required to enable the USB_ENABLE_STATUS_STAGE_TIMEOUTS feature.
|
||||
|
||||
#define USB_ENABLE_STATUS_STAGE_TIMEOUTS //Comment this out to disable this feature.
|
||||
|
||||
//Section 9.2.6 of the USB 2.0 specifications indicate that:
|
||||
//1. Control transfers with no data stage: Status stage must complete within
|
||||
// 50ms of the start of the control transfer.
|
||||
//2. Control transfers with (IN) data stage: Status stage must complete within
|
||||
// 50ms of sending the last IN data packet in fullfilment of the data stage.
|
||||
//3. Control transfers with (OUT) data stage: No specific status stage timing
|
||||
// requirement. However, the total time of the entire control transfer (ex:
|
||||
// including the OUT data stage and IN status stage) must not exceed 5 seconds.
|
||||
//
|
||||
//Therefore, if the USB_ENABLE_STATUS_STAGE_TIMEOUTS feature is used, it is suggested
|
||||
//to set the USB_STATUS_STAGE_TIMEOUT value to timeout in less than 50ms. If the
|
||||
//USB_ENABLE_STATUS_STAGE_TIMEOUTS feature is not enabled, then the USB_STATUS_STAGE_TIMEOUT
|
||||
//parameter is not relevant.
|
||||
|
||||
#define USB_STATUS_STAGE_TIMEOUT (uint8_t)45 //Approximate timeout in milliseconds, except when
|
||||
//USB_POLLING mode is used, and USBDeviceTasks() is called at < 1kHz
|
||||
//In this special case, the timeout becomes approximately:
|
||||
//Timeout(in milliseconds) = ((1000 * (USB_STATUS_STAGE_TIMEOUT - 1)) / (USBDeviceTasks() polling frequency in Hz))
|
||||
//------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
#define USB_SUPPORT_DEVICE
|
||||
|
||||
#define USB_NUM_STRING_DESCRIPTORS 3 //Set this number to match the total number of string descriptors that are implemented in the usb_descriptors.c file
|
||||
|
||||
/*******************************************************************
|
||||
* Event disable options
|
||||
* Enable a definition to suppress a specific event. By default
|
||||
* all events are sent.
|
||||
*******************************************************************/
|
||||
//#define USB_DISABLE_SUSPEND_HANDLER
|
||||
//#define USB_DISABLE_WAKEUP_FROM_SUSPEND_HANDLER
|
||||
//#define USB_DISABLE_SOF_HANDLER
|
||||
//#define USB_DISABLE_TRANSFER_TERMINATED_HANDLER
|
||||
//#define USB_DISABLE_ERROR_HANDLER
|
||||
//#define USB_DISABLE_NONSTANDARD_EP0_REQUEST_HANDLER
|
||||
//#define USB_DISABLE_SET_DESCRIPTOR_HANDLER
|
||||
//#define USB_DISABLE_SET_CONFIGURATION_HANDLER
|
||||
//#define USB_DISABLE_TRANSFER_COMPLETE_HANDLER
|
||||
|
||||
/** DEVICE CLASS USAGE *********************************************/
|
||||
#define USB_USE_HID
|
||||
|
||||
/** ENDPOINTS ALLOCATION *******************************************/
|
||||
|
||||
/* HID */
|
||||
#define HID_INTF_ID 0x00
|
||||
#define HID_INT_OUT_EP_SIZE 64
|
||||
#define HID_INT_IN_EP_SIZE 64
|
||||
#define HID_NUM_OF_DSC 1
|
||||
#define HID_RPT01_SIZE 29
|
||||
|
||||
/** DEFINITIONS ****************************************************/
|
||||
|
||||
#endif //USBCFG_H
|
||||
266
bootloader/src/usb_descriptors.c
Normal file
266
bootloader/src/usb_descriptors.c
Normal file
@@ -0,0 +1,266 @@
|
||||
/*******************************************************************************
|
||||
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
|
||||
*******************************************************************************/
|
||||
|
||||
/********************************************************************
|
||||
-usb_descriptors.c-
|
||||
-------------------------------------------------------------------
|
||||
Filling in the descriptor values in the usb_descriptors.c file:
|
||||
-------------------------------------------------------------------
|
||||
|
||||
[Device Descriptors]
|
||||
The device descriptor is defined as a USB_DEVICE_DESCRIPTOR type.
|
||||
This type is defined in usb_ch9.h Each entry into this structure
|
||||
needs to be the correct length for the data type of the entry.
|
||||
|
||||
[Configuration Descriptors]
|
||||
The configuration descriptor was changed in v2.x from a structure
|
||||
to a uint8_t array. Given that the configuration is now a byte array
|
||||
each byte of multi-byte fields must be listed individually. This
|
||||
means that for fields like the total size of the configuration where
|
||||
the field is a 16-bit value "64,0," is the correct entry for a
|
||||
configuration that is only 64 bytes long and not "64," which is one
|
||||
too few bytes.
|
||||
|
||||
The configuration attribute must always have the _DEFAULT
|
||||
definition at the minimum. Additional options can be ORed
|
||||
to the _DEFAULT attribute. Available options are _SELF and _RWU.
|
||||
These definitions are defined in the usb_device.h file. The
|
||||
_SELF tells the USB host that this device is self-powered. The
|
||||
_RWU tells the USB host that this device supports Remote Wakeup.
|
||||
|
||||
[Endpoint Descriptors]
|
||||
Like the configuration descriptor, the endpoint descriptors were
|
||||
changed in v2.x of the stack from a structure to a uint8_t array. As
|
||||
endpoint descriptors also has a field that are multi-byte entities,
|
||||
please be sure to specify both bytes of the field. For example, for
|
||||
the endpoint size an endpoint that is 64 bytes needs to have the size
|
||||
defined as "64,0," instead of "64,"
|
||||
|
||||
Take the following example:
|
||||
// Endpoint Descriptor //
|
||||
0x07, //the size of this descriptor //
|
||||
USB_DESCRIPTOR_ENDPOINT, //Endpoint Descriptor
|
||||
_EP02_IN, //EndpointAddress
|
||||
_INT, //Attributes
|
||||
0x08,0x00, //size (note: 2 bytes)
|
||||
0x02, //Interval
|
||||
|
||||
The first two parameters are self-explanatory. They specify the
|
||||
length of this endpoint descriptor (7) and the descriptor type.
|
||||
The next parameter identifies the endpoint, the definitions are
|
||||
defined in usb_device.h and has the following naming
|
||||
convention:
|
||||
_EP<##>_<dir>
|
||||
where ## is the endpoint number and dir is the direction of
|
||||
transfer. The dir has the value of either 'OUT' or 'IN'.
|
||||
The next parameter identifies the type of the endpoint. Available
|
||||
options are _BULK, _INT, _ISO, and _CTRL. The _CTRL is not
|
||||
typically used because the default control transfer endpoint is
|
||||
not defined in the USB descriptors. When _ISO option is used,
|
||||
addition options can be ORed to _ISO. Example:
|
||||
_ISO|_AD|_FE
|
||||
This describes the endpoint as an isochronous pipe with adaptive
|
||||
and feedback attributes. See usb_device.h and the USB
|
||||
specification for details. The next parameter defines the size of
|
||||
the endpoint. The last parameter in the polling interval.
|
||||
|
||||
-------------------------------------------------------------------
|
||||
Adding a USB String
|
||||
-------------------------------------------------------------------
|
||||
A string descriptor array should have the following format:
|
||||
|
||||
rom struct{byte bLength;byte bDscType;word string[size];}sdxxx={
|
||||
sizeof(sdxxx),DSC_STR,<text>};
|
||||
|
||||
The above structure provides a means for the C compiler to
|
||||
calculate the length of string descriptor sdxxx, where xxx is the
|
||||
index number. The first two bytes of the descriptor are descriptor
|
||||
length and type. The rest <text> are string texts which must be
|
||||
in the unicode format. The unicode format is achieved by declaring
|
||||
each character as a word type. The whole text string is declared
|
||||
as a word array with the number of characters equals to <size>.
|
||||
<size> has to be manually counted and entered into the array
|
||||
declaration. Let's study this through an example:
|
||||
if the string is "USB" , then the string descriptor should be:
|
||||
(Using index 02)
|
||||
rom struct{byte bLength;byte bDscType;word string[3];}sd002={
|
||||
sizeof(sd002),DSC_STR,'U','S','B'};
|
||||
|
||||
A USB project may have multiple strings and the firmware supports
|
||||
the management of multiple strings through a look-up table.
|
||||
The look-up table is defined as:
|
||||
rom const unsigned char *rom USB_SD_Ptr[]={&sd000,&sd001,&sd002};
|
||||
|
||||
The above declaration has 3 strings, sd000, sd001, and sd002.
|
||||
Strings can be removed or added. sd000 is a specialized string
|
||||
descriptor. It defines the language code, usually this is
|
||||
US English (0x0409). The index of the string must match the index
|
||||
position of the USB_SD_Ptr array, &sd000 must be in position
|
||||
USB_SD_Ptr[0], &sd001 must be in position USB_SD_Ptr[1] and so on.
|
||||
The look-up table USB_SD_Ptr is used by the get string handler
|
||||
function.
|
||||
|
||||
-------------------------------------------------------------------
|
||||
|
||||
The look-up table scheme also applies to the configuration
|
||||
descriptor. A USB device may have multiple configuration
|
||||
descriptors, i.e. CFG01, CFG02, etc. To add a configuration
|
||||
descriptor, user must implement a structure similar to CFG01.
|
||||
The next step is to add the configuration descriptor name, i.e.
|
||||
cfg01, cfg02,.., to the look-up table USB_CD_Ptr. USB_CD_Ptr[0]
|
||||
is a dummy place holder since configuration 0 is the un-configured
|
||||
state according to the definition in the USB specification.
|
||||
|
||||
********************************************************************/
|
||||
|
||||
/*********************************************************************
|
||||
* Descriptor specific type definitions are defined in:
|
||||
* usb_device.h
|
||||
*
|
||||
* Configuration options are defined in:
|
||||
* usb_config.h
|
||||
********************************************************************/
|
||||
|
||||
/** INCLUDES *******************************************************/
|
||||
#include "usb.h"
|
||||
#include "usb_device_hid.h"
|
||||
|
||||
/* Device Descriptor */
|
||||
const 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
|
||||
0x04D8, // Vendor ID, see usb_config.h
|
||||
0x003C, // Product ID, see usb_config.h
|
||||
0x0101, // Device release number in BCD format
|
||||
0x01, // Manufacturer string index
|
||||
0x02, // Product string index
|
||||
0x00, // Device serial number string index
|
||||
0x01 // Number of possible configurations
|
||||
};
|
||||
|
||||
/* Configuration 1 Descriptor */
|
||||
const uint8_t configDescriptor1[]={
|
||||
/* Configuration Descriptor */
|
||||
0x09,//sizeof(USB_CFG_DSC), // Size of this descriptor in bytes
|
||||
USB_DESCRIPTOR_CONFIGURATION, // CONFIGURATION descriptor type
|
||||
0x29, // Total length of data for this cfg - LSB
|
||||
0x00, // Total length of data for this cfg - MSB
|
||||
1, // Number of interfaces in this cfg
|
||||
1, // Index value of this configuration
|
||||
0, // Configuration string index
|
||||
_DEFAULT, // Attributes, see usb_device.h
|
||||
50, // Max power consumption (2X mA)
|
||||
|
||||
/* Interface Descriptor */
|
||||
0x09,//sizeof(USB_INTF_DSC), // Size of this descriptor in bytes
|
||||
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,//sizeof(USB_HID_DSC)+3, // Size of this descriptor in bytes RRoj hack
|
||||
DSC_HID, // HID descriptor type
|
||||
0x11, // HID Spec Release Number in BCD format (0x0111 = v1.11) - LSB
|
||||
0x01, // HID Spec Release Number in BCD format (0x0111 = v1.11) - MSB
|
||||
0x00, // Country Code (0x00 for Not supported)
|
||||
HID_NUM_OF_DSC, // Number of class descriptors, see usbcfg.h
|
||||
DSC_RPT, // Report descriptor type
|
||||
DESC_CONFIG_WORD(HID_RPT01_SIZE), //sizeof(hid_rpt01), // Size of the report descriptor
|
||||
|
||||
/* Endpoint Descriptor */
|
||||
0x07,/*sizeof(USB_EP_DSC)*/
|
||||
USB_DESCRIPTOR_ENDPOINT, //Endpoint Descriptor
|
||||
_EP01_IN, //EndpointAddress
|
||||
_INTERRUPT, //Attributes
|
||||
DESC_CONFIG_WORD(HID_INT_IN_EP_SIZE), //size
|
||||
0x01, //Interval
|
||||
|
||||
/* Endpoint Descriptor */
|
||||
0x07,/*sizeof(USB_EP_DSC)*/
|
||||
USB_DESCRIPTOR_ENDPOINT, //Endpoint Descriptor
|
||||
_EP01_OUT, //EndpointAddress
|
||||
_INTERRUPT, //Attributes
|
||||
DESC_CONFIG_WORD(HID_INT_OUT_EP_SIZE), //size
|
||||
0x01, //Interval
|
||||
};
|
||||
|
||||
|
||||
//Language code string descriptor
|
||||
const struct{uint8_t bLength;uint8_t bDscType;uint16_t string[1];}sd000={
|
||||
sizeof(sd000),USB_DESCRIPTOR_STRING,{0x0409
|
||||
}};
|
||||
|
||||
//Manufacturer string descriptor
|
||||
const struct{uint8_t bLength;uint8_t bDscType;uint16_t string[25];}sd001={
|
||||
sizeof(sd001),USB_DESCRIPTOR_STRING,
|
||||
{'M','i','c','r','o','c','h','i','p',' ',
|
||||
'T','e','c','h','n','o','l','o','g','y',' ','I','n','c','.'
|
||||
}};
|
||||
|
||||
//Product string descriptor
|
||||
const struct{uint8_t bLength;uint8_t bDscType;uint16_t string[18];}sd002={
|
||||
sizeof(sd002),USB_DESCRIPTOR_STRING,
|
||||
{'H','I','D',' ','U','S','B',' ','B','o','o',
|
||||
't','l','o','a','d','e','r'
|
||||
}};
|
||||
|
||||
//Array of configuration descriptors
|
||||
const uint8_t *const USB_CD_Ptr[]=
|
||||
{
|
||||
(const uint8_t *const)&configDescriptor1
|
||||
};
|
||||
|
||||
//Array of string descriptors
|
||||
const uint8_t *const USB_SD_Ptr[]=
|
||||
{
|
||||
(const uint8_t *const)&sd000,
|
||||
(const uint8_t *const)&sd001,
|
||||
(const uint8_t *const)&sd002
|
||||
};
|
||||
|
||||
const struct{uint8_t 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, 0x00, // Logical Minimum (data bytes in the report may have minimum value = 0x00)
|
||||
0x26, 0xFF, 0x00, // 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
|
||||
}
|
||||
};
|
||||
/** EOF usb_descriptors.c ***************************************************/
|
||||
|
||||
84
bootloader/src/usb_events.c
Normal file
84
bootloader/src/usb_events.c
Normal file
@@ -0,0 +1,84 @@
|
||||
#include "usb.h"
|
||||
#include "usb_device_hid.h"
|
||||
|
||||
/*******************************************************************
|
||||
* Function: bool USER_USB_CALLBACK_EVENT_HANDLER(
|
||||
* USB_EVENT event, void *pdata, uint16_t size)
|
||||
*
|
||||
* PreCondition: None
|
||||
*
|
||||
* Input: USB_EVENT event - the type of event
|
||||
* void *pdata - pointer to the event data
|
||||
* uint16_t size - size of the event data
|
||||
*
|
||||
* Output: None
|
||||
*
|
||||
* Side Effects: None
|
||||
*
|
||||
* Overview: This function is called from the USB stack to
|
||||
* notify a user application that a USB event
|
||||
* occured. This callback is in interrupt context
|
||||
* when the USB_INTERRUPT option is selected.
|
||||
*
|
||||
* Note: None
|
||||
*******************************************************************/
|
||||
bool USER_USB_CALLBACK_EVENT_HANDLER(USB_EVENT event, void *pdata, uint16_t size)
|
||||
{
|
||||
switch( (int) event )
|
||||
{
|
||||
case EVENT_TRANSFER:
|
||||
break;
|
||||
|
||||
case EVENT_SOF:
|
||||
break;
|
||||
|
||||
case EVENT_SUSPEND:
|
||||
//Call the hardware platform specific handler for suspend events for
|
||||
//possible further action (like optionally going reconfiguring the application
|
||||
//for lower power states and going to sleep during the suspend event). This
|
||||
//would normally be done in USB compliant bus powered applications, although
|
||||
//no further processing is needed for purely self powered applications that
|
||||
//don't consume power from the host.
|
||||
//asm("SLEEP"); // sleep right now, execution starts on next line when woken up
|
||||
// we have been woken up. if the watchdog was the cause go back to sleep
|
||||
//while ((PIR2bits.USBIF == 0) && (RCONbits.TO == 0))
|
||||
//{
|
||||
// asm("SLEEP");
|
||||
//}
|
||||
break;
|
||||
|
||||
case EVENT_RESUME:
|
||||
// restore any hardware states (i.e. IO pin config) that were changed on suspend
|
||||
break;
|
||||
|
||||
case EVENT_CONFIGURED:
|
||||
// When the device is configured, we should (re)initialize our state variables
|
||||
USBEnableEndpoint(1, USB_IN_ENABLED|USB_HANDSHAKE_ENABLED|USB_DISALLOW_SETUP);
|
||||
break;
|
||||
|
||||
case EVENT_SET_DESCRIPTOR:
|
||||
break;
|
||||
|
||||
case EVENT_EP0_REQUEST:
|
||||
/* We have received a non-standard USB request. The HID driver
|
||||
* needs to check to see if the request was for it. */
|
||||
USBCheckHIDRequest();
|
||||
break;
|
||||
|
||||
case EVENT_BUS_ERROR:
|
||||
break;
|
||||
|
||||
case EVENT_TRANSFER_TERMINATED:
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
End of File
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user