first submission
This commit is contained in:
@@ -0,0 +1,145 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
|
||||
<storageModule moduleId="org.eclipse.cdt.core.settings">
|
||||
<cconfiguration id="ilg.gnumcueclipse.managedbuild.cross.riscv.config.elf.release.1008047074">
|
||||
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="ilg.gnumcueclipse.managedbuild.cross.riscv.config.elf.release.1008047074" moduleId="org.eclipse.cdt.core.settings" name="obj">
|
||||
<externalSettings/>
|
||||
<extensions>
|
||||
<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
|
||||
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||
</extensions>
|
||||
</storageModule>
|
||||
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
|
||||
<configuration artifactName="${ProjName}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe,org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.release" cleanCommand="${cross_rm} -rf" description="" id="ilg.gnumcueclipse.managedbuild.cross.riscv.config.elf.release.1008047074" name="obj" parent="ilg.gnumcueclipse.managedbuild.cross.riscv.config.elf.release">
|
||||
<folderInfo id="ilg.gnumcueclipse.managedbuild.cross.riscv.config.elf.release.1008047074." name="/" resourcePath="">
|
||||
<toolChain id="ilg.gnumcueclipse.managedbuild.cross.riscv.toolchain.elf.release.231146001" name="RISC-V Cross GCC" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.toolchain.elf.release">
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.addtools.createflash.1311852988" name="Create flash image" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.addtools.createflash" useByScannerDiscovery="false" value="true" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.addtools.createlisting.1983282875" name="Create extended listing" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.addtools.createlisting" useByScannerDiscovery="false" value="true" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.addtools.printsize.1000761142" name="Print size" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.addtools.printsize" useByScannerDiscovery="false" value="true" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.level.514997414" name="Optimization Level" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.level" useByScannerDiscovery="true" value="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.level.size" valueType="enumerated"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.messagelength.1008570639" name="Message length (-fmessage-length=0)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.messagelength" useByScannerDiscovery="true" value="true" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.signedchar.467272439" name="'char' is signed (-fsigned-char)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.signedchar" useByScannerDiscovery="true" value="true" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.functionsections.2047756949" name="Function sections (-ffunction-sections)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.functionsections" useByScannerDiscovery="true" value="true" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.datasections.207613650" name="Data sections (-fdata-sections)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.datasections" useByScannerDiscovery="true" value="true" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.debugging.level.1204865254" name="Debug level" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.debugging.level" useByScannerDiscovery="true"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.debugging.format.867779652" name="Debug format" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.debugging.format" useByScannerDiscovery="true"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.isa.base.1900297968" name="Architecture" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.isa.base" useByScannerDiscovery="false" value="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.arch.rv32i" valueType="enumerated"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.abi.integer.387605487" name="Integer ABI" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.abi.integer" useByScannerDiscovery="false" value="ilg.gnumcueclipse.managedbuild.cross.riscv.option.abi.integer.ilp32" valueType="enumerated"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.isa.multiply.1509705449" name="Multiply extension (RVM)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.isa.multiply" useByScannerDiscovery="false" value="true" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.isa.compressed.1038505275" name="Compressed extension (RVC)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.isa.compressed" useByScannerDiscovery="false" value="true" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.toolchain.name.1218760634" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.toolchain.name" useByScannerDiscovery="false" value="GNU MCU RISC-V GCC" valueType="string"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.prefix.103341323" name="Prefix" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.prefix" useByScannerDiscovery="false" value="riscv-none-embed-" valueType="string"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.c.487601824" name="C compiler" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.c" useByScannerDiscovery="false" value="gcc" valueType="string"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.cpp.1062130429" name="C++ compiler" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.cpp" useByScannerDiscovery="false" value="g++" valueType="string"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.ar.1194282993" name="Archiver" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.ar" useByScannerDiscovery="false" value="ar" valueType="string"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.objcopy.1529355265" name="Hex/Bin converter" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.objcopy" useByScannerDiscovery="false" value="objcopy" valueType="string"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.objdump.1053750745" name="Listing generator" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.objdump" useByScannerDiscovery="false" value="objdump" valueType="string"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.size.1441326233" name="Size command" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.size" useByScannerDiscovery="false" value="size" valueType="string"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.make.550105535" name="Build command" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.make" useByScannerDiscovery="false" value="make" valueType="string"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.rm.719280496" name="Remove command" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.rm" useByScannerDiscovery="false" value="rm" valueType="string"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.toolchain.id.226017994" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.toolchain.id" useByScannerDiscovery="false" value="512258282" valueType="string"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.isa.atomic.1590833110" name="Atomic extension (RVA)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.isa.atomic" useByScannerDiscovery="false" value="true" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.warnings.unused.1961191588" name="Warn on various unused elements (-Wunused)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.warnings.unused" useByScannerDiscovery="true" value="true" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.warnings.uninitialized.929829166" name="Warn on uninitialized variables (-Wuninitialised)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.warnings.uninitialized" useByScannerDiscovery="true" value="true" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.nocommon.820102679" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.nocommon" value="true" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.isa.xw.249472487" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.isa.xw" value="true" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.saverestore.1882553019" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.saverestore" value="true" valueType="boolean"/>
|
||||
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="ilg.gnumcueclipse.managedbuild.cross.riscv.targetPlatform.1944008784" isAbstract="false" osList="all" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.targetPlatform"/>
|
||||
<builder buildPath="${workspace_loc:/USART_DMA}/obj" id="ilg.gnumcueclipse.managedbuild.cross.riscv.builder.1421508906" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" parallelBuildOn="true" parallelizationNumber="optimal" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.builder"/>
|
||||
<tool id="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.assembler.1244756189" name="GNU RISC-V Cross Assembler" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.assembler">
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.assembler.usepreprocessor.1692176068" name="Use preprocessor" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.assembler.usepreprocessor" useByScannerDiscovery="false" value="true" valueType="boolean"/>
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.assembler.include.paths.1034038285" name="Include paths (-I)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.assembler.include.paths" useByScannerDiscovery="true" valueType="includePath">
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/Startup}""/>
|
||||
</option>
|
||||
<inputType id="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.assembler.input.126366858" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.assembler.input"/>
|
||||
</tool>
|
||||
<tool id="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.compiler.1731377187" name="GNU RISC-V Cross C Compiler" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.compiler">
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.include.paths.1567947810" name="Include paths (-I)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.include.paths" useByScannerDiscovery="true" valueType="includePath">
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/Debug}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/Core}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/User}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/Peripheral/inc}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/User/USBLIB/CONFIG}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/User/USBLIB/USB-Driver/inc}""/>
|
||||
</option>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.std.2020844713" name="Language standard" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.std" useByScannerDiscovery="true" value="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.std.gnu99" valueType="enumerated"/>
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="true" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.defs.177116515" name="Defined symbols (-D)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.defs" useByScannerDiscovery="true" valueType="definedSymbols"/>
|
||||
<inputType id="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.compiler.input.2036806839" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.compiler.input"/>
|
||||
</tool>
|
||||
<tool id="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.cpp.compiler.1610882921" name="GNU RISC-V Cross C++ Compiler" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.cpp.compiler"/>
|
||||
<tool id="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.linker.1620074387" name="GNU RISC-V Cross C Linker" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.linker">
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.gcsections.194760422" name="Remove unused sections (-Xlinker --gc-sections)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.gcsections" useByScannerDiscovery="false" value="true" valueType="boolean"/>
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="true" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.paths.2057340378" name="Library search path (-L)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.paths" useByScannerDiscovery="false" valueType="libPaths"/>
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.scriptfile.1390103472" name="Script files (-T)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.scriptfile" useByScannerDiscovery="false" valueType="stringList">
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/Ld/Link.ld}""/>
|
||||
</option>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.nostart.913830613" name="Do not use standard start files (-nostartfiles)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.nostart" useByScannerDiscovery="false" value="true" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.usenewlibnano.239404511" name="Use newlib-nano (--specs=nano.specs)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.usenewlibnano" useByScannerDiscovery="false" value="true" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.usenewlibnosys.351964161" name="Do not use syscalls (--specs=nosys.specs)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.usenewlibnosys" useByScannerDiscovery="false" value="true" valueType="boolean"/>
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="true" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.otherobjs.16994550" name="Other objects" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.otherobjs" useByScannerDiscovery="false" valueType="userObjs"/>
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="true" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.flags.1125808200" name="Linker flags (-Xlinker [option])" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.flags" useByScannerDiscovery="false" valueType="stringList"/>
|
||||
<inputType id="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.linker.input.1859223768" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.linker.input">
|
||||
<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
|
||||
<additionalInput kind="additionalinput" paths="$(LIBS)"/>
|
||||
</inputType>
|
||||
</tool>
|
||||
<tool id="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.cpp.linker.1947503520" name="GNU RISC-V Cross C++ Linker" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.cpp.linker">
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.gcsections.1689063433" name="Remove unused sections (-Xlinker --gc-sections)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.gcsections" value="true" valueType="boolean"/>
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.paths.1029177148" name="Library search path (-L)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.paths" valueType="libPaths">
|
||||
<listOptionValue builtIn="false" value=""../LD""/>
|
||||
</option>
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.scriptfile.1751226764" name="Script files (-T)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.scriptfile" valueType="stringList">
|
||||
<listOptionValue builtIn="false" value="Link.ld"/>
|
||||
</option>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.nostart.642896175" name="Do not use standard start files (-nostartfiles)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.nostart" value="true" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.usenewlibnano.1540675679" name="Use newlib-nano (--specs=nano.specs)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.usenewlibnano" value="true" valueType="boolean"/>
|
||||
</tool>
|
||||
<tool id="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.archiver.1292785366" name="GNU RISC-V Cross Archiver" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.archiver"/>
|
||||
<tool id="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.createflash.1801165667" name="GNU RISC-V Cross Create Flash Image" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.createflash"/>
|
||||
<tool id="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.createlisting.1356766765" name="GNU RISC-V Cross Create Listing" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.createlisting">
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createlisting.source.2052761852" name="Display source (--source|-S)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createlisting.source" useByScannerDiscovery="false" value="false" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createlisting.allheaders.439659821" name="Display all headers (--all-headers|-x)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createlisting.allheaders" useByScannerDiscovery="false" value="true" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createlisting.demangle.67111865" name="Demangle names (--demangle|-C)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createlisting.demangle" useByScannerDiscovery="false" value="true" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createlisting.linenumbers.1549373929" name="Display line numbers (--line-numbers|-l)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createlisting.linenumbers" useByScannerDiscovery="false" value="false" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createlisting.wide.1298918921" name="Wide lines (--wide|-w)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createlisting.wide" useByScannerDiscovery="false" value="false" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createlisting.disassemble.1859590835" name="Disassemble (--disassemble|-d)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createlisting.disassemble" useByScannerDiscovery="false" value="true" valueType="boolean"/>
|
||||
</tool>
|
||||
<tool id="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.printsize.712424314" name="GNU RISC-V Cross Print Size" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.printsize">
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.printsize.format.1404031980" name="Size format" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.printsize.format" useByScannerDiscovery="false"/>
|
||||
</tool>
|
||||
</toolChain>
|
||||
</folderInfo>
|
||||
<sourceEntries>
|
||||
<entry excluding="USB-Driver|Startup|Peripheral|Ld|Debug|Core" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
|
||||
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Core"/>
|
||||
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Debug"/>
|
||||
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Ld"/>
|
||||
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Peripheral"/>
|
||||
<entry excluding="startup_ch32v20x_D8W.S|startup_ch32v20x_D8.S" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Startup"/>
|
||||
</sourceEntries>
|
||||
</configuration>
|
||||
</storageModule>
|
||||
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
|
||||
<storageModule moduleId="ilg.gnumcueclipse.managedbuild.packs"/>
|
||||
</cconfiguration>
|
||||
</storageModule>
|
||||
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
|
||||
<project id="999.ilg.gnumcueclipse.managedbuild.cross.riscv.target.elf.275846018" name="Executable file" projectType="ilg.gnumcueclipse.managedbuild.cross.riscv.target.elf"/>
|
||||
</storageModule>
|
||||
<storageModule moduleId="scannerConfiguration">
|
||||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
|
||||
<scannerConfigBuildInfo instanceId="ilg.gnumcueclipse.managedbuild.cross.riscv.config.elf.debug.767917625;ilg.gnumcueclipse.managedbuild.cross.riscv.config.elf.debug.767917625.;ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.compiler.1375371130;ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.compiler.input.1473381709">
|
||||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
|
||||
</scannerConfigBuildInfo>
|
||||
<scannerConfigBuildInfo instanceId="ilg.gnumcueclipse.managedbuild.cross.riscv.config.elf.release.1008047074;ilg.gnumcueclipse.managedbuild.cross.riscv.config.elf.release.1008047074.;ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.compiler.1731377187;ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.compiler.input.2036806839">
|
||||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
|
||||
</scannerConfigBuildInfo>
|
||||
</storageModule>
|
||||
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
|
||||
<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets"/>
|
||||
|
||||
</cproject>
|
||||
@@ -0,0 +1,64 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<projectDescription>
|
||||
<name>CompositeKM</name>
|
||||
<comment/>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
|
||||
<triggers>clean,full,incremental,</triggers>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
|
||||
<triggers>full,incremental,</triggers>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.cdt.core.cnature</nature>
|
||||
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
|
||||
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
|
||||
</natures>
|
||||
<linkedResources>
|
||||
<link>
|
||||
<name>Core</name>
|
||||
<type>2</type>
|
||||
<locationURI>PARENT-3-PROJECT_LOC/SRC/Core</locationURI>
|
||||
</link>
|
||||
<link>
|
||||
<name>Debug</name>
|
||||
<type>2</type>
|
||||
<locationURI>PARENT-3-PROJECT_LOC/SRC/Debug</locationURI>
|
||||
</link>
|
||||
<link>
|
||||
<name>Ld</name>
|
||||
<type>2</type>
|
||||
<locationURI>PARENT-3-PROJECT_LOC/SRC/Ld</locationURI>
|
||||
</link>
|
||||
<link>
|
||||
<name>Peripheral</name>
|
||||
<type>2</type>
|
||||
<locationURI>PARENT-3-PROJECT_LOC/SRC/Peripheral</locationURI>
|
||||
</link>
|
||||
<link>
|
||||
<name>Startup</name>
|
||||
<type>2</type>
|
||||
<locationURI>PARENT-3-PROJECT_LOC/SRC/Startup</locationURI>
|
||||
</link>
|
||||
</linkedResources>
|
||||
<filteredResources>
|
||||
<filter>
|
||||
<id>1595986042669</id>
|
||||
<name/>
|
||||
<type>22</type>
|
||||
<matcher>
|
||||
<id>org.eclipse.ui.ide.multiFilter</id>
|
||||
<arguments>1.0-name-matches-false-false-*.wvproj</arguments>
|
||||
</matcher>
|
||||
</filter>
|
||||
</filteredResources>
|
||||
</projectDescription>
|
||||
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<project>
|
||||
<configuration id="ilg.gnumcueclipse.managedbuild.cross.riscv.config.elf.release.1008047074" name="obj">
|
||||
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
|
||||
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
|
||||
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
|
||||
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
|
||||
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-1424566145179774836" id="ilg.gnumcueclipse.managedbuild.cross.riscv.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT RISC-V Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
|
||||
<language-scope id="org.eclipse.cdt.core.gcc"/>
|
||||
<language-scope id="org.eclipse.cdt.core.g++"/>
|
||||
</provider>
|
||||
</extension>
|
||||
</configuration>
|
||||
</project>
|
||||
@@ -0,0 +1,2 @@
|
||||
eclipse.preferences.version=1
|
||||
encoding//User/Main.c=UTF-8
|
||||
@@ -0,0 +1,16 @@
|
||||
Mcu Type=CH32V20x
|
||||
Address=0x08000000
|
||||
Target Path=obj\CompositeKM.hex
|
||||
Erase All=true
|
||||
Program=true
|
||||
Verify=true
|
||||
Reset=true
|
||||
|
||||
Vendor=WCH
|
||||
Link=WCH-Link
|
||||
Toolchain=RISC-V
|
||||
Series=CH32V203
|
||||
Description=ROM(byte): 64K, SRAM(byte): 20K, CHIP PINS: 32, GPIO PORTS: 27.\nWCH CH32V2 series of mainstream MCUs covers the needs of a large variety of applications in the industrial,medical and consumer markets. High performance with first-class peripherals and low-power,low-voltage operation is paired with a high level of integration at accessible prices with a simple architecture and easy-to-use tools.
|
||||
|
||||
PeripheralVersion=1.0
|
||||
MCU=CH32V203RBT6
|
||||
@@ -0,0 +1,2 @@
|
||||
�i“CZ ?"Ç�¸rŸ�F<Fy8E9Y‡½„%Pa³D¶La†%Ã'y€¡]Ç;’¶ŸS)1†1+R4><‚.„ÇÅ¿º°?/£XO©Ä¿ChQN$*¢”»EÅBk‹!2tŒ+buh†nUb]xl‹l|
|
||||
+"Ÿ<“¯AH42}z8p;m€u1Ž-¦eh»Od¼Âwµª7x{5�CqEx©=;¦¢e¢º»2£Š ‚«*BPMš"
|
||||
@@ -0,0 +1,93 @@
|
||||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : main.c
|
||||
* Author : WCH
|
||||
* Version : V1.0.0
|
||||
* Date : 2021/08/08
|
||||
* Description : Main program body.
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
* Attention: This software (modified or not) and binary are used for
|
||||
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
|
||||
*******************************************************************************/
|
||||
|
||||
/*
|
||||
* @Note
|
||||
* Composite Keyboard and Mouse Example:
|
||||
* This example uses PA4-PA7 and PB12-PB15 to simulate mouse movement and keyboard
|
||||
* key pressing respectively, active low. At the same time, it also uses USART2
|
||||
* to receive data sent from the host to simulate keyboard key pressing and releasing.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "debug.h"
|
||||
#include "usb_lib.h"
|
||||
#include "usb_desc.h"
|
||||
#include "usb_pwr.h"
|
||||
#include "usb_prop.h"
|
||||
#include "usbd_composite_km.h"
|
||||
/* Global define */
|
||||
|
||||
/* Global Variable */
|
||||
|
||||
/*********************************************************************
|
||||
* @fn main
|
||||
*
|
||||
* @brief Main program.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
int main(void)
|
||||
{
|
||||
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
|
||||
Delay_Init();
|
||||
USART_Printf_Init( 115200 );
|
||||
printf("SystemClk:%d\r\n",SystemCoreClock);
|
||||
printf("USBD Keyboard&Mouse Demo\r\n");
|
||||
|
||||
/* Initialize USART2 for receiving the specified keyboard data */
|
||||
USART2_Init( 115200 );
|
||||
printf( "USART2 Init OK!\r\n" );
|
||||
|
||||
/* Initialize GPIO for keyboard scan */
|
||||
KB_Scan_Init( );
|
||||
KB_Sleep_Wakeup_Cfg( );
|
||||
printf( "KB Scan Init OK!\r\n" );
|
||||
|
||||
/* Initialize GPIO for mouse scan */
|
||||
MS_Scan_Init( );
|
||||
MS_Sleep_Wakeup_Cfg( );
|
||||
printf( "MS Scan Init OK!\r\n" );
|
||||
|
||||
/* Initialize timer for Keyboard and mouse scan timing */
|
||||
TIM3_Init( 1, 7199 );
|
||||
printf( "TIM3 Init OK!\r\n" );
|
||||
|
||||
Set_USBConfig();
|
||||
USB_Init();
|
||||
USB_Interrupts_Config();
|
||||
|
||||
while(1)
|
||||
{
|
||||
if( bDeviceState == CONFIGURED )
|
||||
{
|
||||
/* Handle keyboard scan data */
|
||||
KB_Scan_Handle( );
|
||||
|
||||
/* Handle keyboard lighting */
|
||||
KB_LED_Handle( );
|
||||
|
||||
/* Handle mouse scan data */
|
||||
MS_Scan_Handle( );
|
||||
|
||||
/* Handle USART2 receiving data */
|
||||
USART2_Receive_Handle( );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,176 @@
|
||||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : hw_config.c
|
||||
* Author : WCH
|
||||
* Version : V1.0.0
|
||||
* Date : 2021/08/08
|
||||
* Description : USB configuration file.
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
* Attention: This software (modified or not) and binary are used for
|
||||
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
|
||||
*******************************************************************************/
|
||||
#include "usb_lib.h"
|
||||
#include "usb_prop.h"
|
||||
#include "usb_desc.h"
|
||||
#include "usb_istr.h"
|
||||
#include "hw_config.h"
|
||||
#include "usb_pwr.h"
|
||||
#include "string.h"
|
||||
#include "stdarg.h"
|
||||
#include "stdio.h"
|
||||
#include "usbd_composite_km.h"
|
||||
|
||||
void USBWakeUp_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
|
||||
void USB_LP_CAN1_RX0_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn USBWakeUp_IRQHandler
|
||||
*
|
||||
* @brief This function handles USB wake up exception.
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
void USBWakeUp_IRQHandler(void)
|
||||
{
|
||||
EXTI_ClearITPendingBit(EXTI_Line18);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn USB_LP_CAN1_RX0_IRQHandler
|
||||
*
|
||||
* @brief This function handles USB exception.
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
void USB_LP_CAN1_RX0_IRQHandler(void)
|
||||
{
|
||||
USB_Istr();
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn Set_USBConfig
|
||||
*
|
||||
* @brief Set_USBConfig .
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
void Set_USBConfig( )
|
||||
{
|
||||
if( SystemCoreClock == 144000000 )
|
||||
{
|
||||
RCC_USBCLKConfig( RCC_USBCLKSource_PLLCLK_Div3 );
|
||||
}
|
||||
else if( SystemCoreClock == 96000000 )
|
||||
{
|
||||
RCC_USBCLKConfig( RCC_USBCLKSource_PLLCLK_Div2 );
|
||||
}
|
||||
else if( SystemCoreClock == 48000000 )
|
||||
{
|
||||
RCC_USBCLKConfig( RCC_USBCLKSource_PLLCLK_Div1 );
|
||||
}
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USB, ENABLE);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn Enter_LowPowerMode
|
||||
*
|
||||
* @brief Enter low power mode.
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
void Enter_LowPowerMode(void)
|
||||
{
|
||||
printf("usb enter low power mode\r\n");
|
||||
USBD_Sleep_Status |= 0x02;
|
||||
if (USBD_Sleep_Status == 0x03)
|
||||
{
|
||||
MCU_Sleep_Wakeup_Operate();
|
||||
}
|
||||
bDeviceState = SUSPENDED;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn Leave_LowPowerMode
|
||||
*
|
||||
* @brief Leave low power mode.
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
void Leave_LowPowerMode(void)
|
||||
{
|
||||
DEVICE_INFO *pInfo=&Device_Info;
|
||||
printf("usb leave low power mode\r\n");
|
||||
USBD_Sleep_Status &= ~0x02;
|
||||
if (pInfo->Current_Configuration!=0)bDeviceState=CONFIGURED;
|
||||
else bDeviceState = ATTACHED;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn USB_Interrupts_Config
|
||||
*
|
||||
* @brief Configrate USB interrupt.
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
void USB_Interrupts_Config(void)
|
||||
{
|
||||
NVIC_InitTypeDef NVIC_InitStructure;
|
||||
EXTI_InitTypeDef EXTI_InitStructure;
|
||||
|
||||
EXTI_ClearITPendingBit(EXTI_Line18);
|
||||
EXTI_InitStructure.EXTI_Line = EXTI_Line18;
|
||||
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
|
||||
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling;
|
||||
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
|
||||
EXTI_Init(&EXTI_InitStructure);
|
||||
|
||||
NVIC_InitStructure.NVIC_IRQChannel = USB_LP_CAN1_RX0_IRQn;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||
NVIC_Init(&NVIC_InitStructure);
|
||||
|
||||
NVIC_InitStructure.NVIC_IRQChannel = USBWakeUp_IRQn;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
|
||||
NVIC_Init(&NVIC_InitStructure);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn USB_Port_Set
|
||||
*
|
||||
* @brief Set USB IO port.
|
||||
*
|
||||
* @param NewState: DISABLE or ENABLE.
|
||||
* Pin_In_IPU: Enables or Disables intenal pull-up resistance.
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
void USB_Port_Set(FunctionalState NewState, FunctionalState Pin_In_IPU)
|
||||
{
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
|
||||
|
||||
if(NewState) {
|
||||
_SetCNTR(_GetCNTR()&(~(1<<1)));
|
||||
GPIOA->CFGHR&=0XFFF00FFF;
|
||||
GPIOA->OUTDR&=~(3<<11); //PA11/12=0
|
||||
GPIOA->CFGHR|=0X00044000; //float
|
||||
}
|
||||
else
|
||||
{
|
||||
_SetCNTR(_GetCNTR()|(1<<1));
|
||||
GPIOA->CFGHR&=0XFFF00FFF;
|
||||
GPIOA->OUTDR&=~(3<<11); //PA11/12=0
|
||||
GPIOA->CFGHR|=0X00033000; // LOW
|
||||
}
|
||||
|
||||
if(Pin_In_IPU) (EXTEN->EXTEN_CTR) |= EXTEN_USBD_PU_EN;
|
||||
else (EXTEN->EXTEN_CTR) &= ~EXTEN_USBD_PU_EN;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : hw_config.h
|
||||
* Author : WCH
|
||||
* Version : V1.0.0
|
||||
* Date : 2021/08/08
|
||||
* Description : Configuration file for USB.
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
* Attention: This software (modified or not) and binary are used for
|
||||
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
|
||||
*******************************************************************************/
|
||||
#ifndef __HW_CONFIG_H
|
||||
#define __HW_CONFIG_H
|
||||
|
||||
#include "usb_type.h"
|
||||
|
||||
#ifdef DEBUG
|
||||
#define printf_usb(X...) printf(X)
|
||||
#else
|
||||
#define printf_usb(X...)
|
||||
#endif
|
||||
|
||||
|
||||
void Set_USBConfig(void);
|
||||
void Enter_LowPowerMode(void);
|
||||
void Leave_LowPowerMode(void);
|
||||
void USB_Interrupts_Config(void);
|
||||
void USB_Port_Set(FunctionalState NewState, FunctionalState Pin_In_IPU);
|
||||
|
||||
#endif /* __HW_CONFIG_H */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : usb_conf.h
|
||||
* Author : WCH
|
||||
* Version : V1.0.0
|
||||
* Date : 2022/08/20
|
||||
* Description : This file contains all the functions prototypes for the
|
||||
* USB configration firmware library.
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
* Attention: This software (modified or not) and binary are used for
|
||||
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
|
||||
*******************************************************************************/
|
||||
#ifndef __USB_CONF_H
|
||||
#define __USB_CONF_H
|
||||
|
||||
|
||||
#define EP_NUM (3)
|
||||
|
||||
/* Buffer Description Table */
|
||||
/* buffer table base address */
|
||||
/* buffer table base address */
|
||||
#define BTABLE_ADDRESS (0x00)
|
||||
|
||||
/* EP0 */
|
||||
/* rx/tx buffer base address */
|
||||
#define ENDP0_RXADDR (0x40)
|
||||
#define ENDP0_TXADDR (0x80)
|
||||
|
||||
/* EP1 */
|
||||
/* tx buffer base address */
|
||||
#define ENDP1_TXADDR (0xC0)
|
||||
#define ENDP2_TXADDR (ENDP1_TXADDR + 0x10)
|
||||
|
||||
/* ISTR events */
|
||||
/* IMR_MSK */
|
||||
/* mask defining which events has to be handled */
|
||||
/* by the device application software */
|
||||
#define IMR_MSK (CNTR_CTRM | CNTR_WKUPM | CNTR_SUSPM | CNTR_ERRM | CNTR_SOFM \
|
||||
| CNTR_ESOFM | CNTR_RESETM )
|
||||
|
||||
/* #define CTR_CALLBACK */
|
||||
/* #define DOVR_CALLBACK */
|
||||
/* #define ERR_CALLBACK */
|
||||
/* #define WKUP_CALLBACK */
|
||||
/* #define SUSP_CALLBACK */
|
||||
/* #define RESET_CALLBAC K*/
|
||||
/* #define SOF_CALLBACK */
|
||||
/* #define ESOF_CALLBACK */
|
||||
|
||||
|
||||
/* CTR service routines */
|
||||
/* associated to defined endpoints */
|
||||
// #define EP1_IN_Callback NOP_Process
|
||||
// #define EP2_IN_Callback NOP_Process
|
||||
#define EP3_IN_Callback NOP_Process
|
||||
#define EP4_IN_Callback NOP_Process
|
||||
#define EP5_IN_Callback NOP_Process
|
||||
#define EP6_IN_Callback NOP_Process
|
||||
#define EP7_IN_Callback NOP_Process
|
||||
|
||||
#define EP1_OUT_Callback NOP_Process
|
||||
#define EP2_OUT_Callback NOP_Process
|
||||
#define EP3_OUT_Callback NOP_Process
|
||||
#define EP4_OUT_Callback NOP_Process
|
||||
#define EP5_OUT_Callback NOP_Process
|
||||
#define EP6_OUT_Callback NOP_Process
|
||||
#define EP7_OUT_Callback NOP_Process
|
||||
|
||||
#endif /* __USB_CONF_H */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,200 @@
|
||||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : usb_desc.c
|
||||
* Author : WCH
|
||||
* Version : V1.0.0
|
||||
* Date : 2019/10/15
|
||||
* Description : USB Descriptors.
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
* Attention: This software (modified or not) and binary are used for
|
||||
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
|
||||
*******************************************************************************/
|
||||
#include "usb_lib.h"
|
||||
#include "usb_desc.h"
|
||||
|
||||
/* USB Device Descriptors */
|
||||
const uint8_t USBD_DeviceDescriptor[] = {
|
||||
USBD_SIZE_DEVICE_DESC, // bLength
|
||||
0x01, // bDescriptorType
|
||||
0x10, 0x01, // bcdUSB
|
||||
0x00, // bDeviceClass
|
||||
0x00, // bDeviceSubClass
|
||||
0x00, // bDeviceProtocol
|
||||
DEF_USBD_UEP0_SIZE, // bMaxPacketSize0
|
||||
0x86, 0x1A, // idVendor
|
||||
0x00, 0xFE, // idProduct
|
||||
0x00, 0x01, // bcdDevice
|
||||
0x01, // iManufacturer
|
||||
0x02, // iProduct
|
||||
0x00, // iSerialNumber
|
||||
0x01, // bNumConfigurations
|
||||
};
|
||||
|
||||
/* USB Configration Descriptors */
|
||||
const uint8_t USBD_ConfigDescriptor[] = {
|
||||
/* Configuration Descriptor */
|
||||
0x09, // bLength
|
||||
0x02, // bDescriptorType
|
||||
USBD_SIZE_CONFIG_DESC & 0xFF, USBD_SIZE_CONFIG_DESC >> 8, // wTotalLength
|
||||
0x02, // bNumInterfaces
|
||||
0x01, // bConfigurationValue
|
||||
0x00, // iConfiguration
|
||||
0xA0, // bmAttributes: Bus Powered; Remote Wakeup
|
||||
0x32, // MaxPower: 100mA
|
||||
|
||||
/* Interface Descriptor (Keyboard) */
|
||||
0x09, // bLength
|
||||
0x04, // bDescriptorType
|
||||
0x00, // bInterfaceNumber
|
||||
0x00, // bAlternateSetting
|
||||
0x01, // bNumEndpoints
|
||||
0x03, // bInterfaceClass
|
||||
0x01, // bInterfaceSubClass
|
||||
0x01, // bInterfaceProtocol: Keyboard
|
||||
0x00, // iInterface
|
||||
|
||||
/* HID Descriptor (Keyboard) */
|
||||
0x09, // bLength
|
||||
0x21, // bDescriptorType
|
||||
0x11, 0x01, // bcdHID
|
||||
0x00, // bCountryCode
|
||||
0x01, // bNumDescriptors
|
||||
0x22, // bDescriptorType
|
||||
USBD_SIZE_REPORT_DESC_KB & 0xFF, USBD_SIZE_REPORT_DESC_KB >> 8, // wDescriptorLength
|
||||
|
||||
/* Endpoint Descriptor (Keyboard) */
|
||||
0x07, // bLength
|
||||
0x05, // bDescriptorType
|
||||
0x81, // bEndpointAddress: IN Endpoint 1
|
||||
0x03, // bmAttributes
|
||||
DEF_ENDP_SIZE_KB & 0xFF, DEF_ENDP_SIZE_KB >> 8, // wMaxPacketSize
|
||||
0x0A, // bInterval: 10mS
|
||||
|
||||
/* Interface Descriptor (Mouse) */
|
||||
0x09, // bLength
|
||||
0x04, // bDescriptorType
|
||||
0x01, // bInterfaceNumber
|
||||
0x00, // bAlternateSetting
|
||||
0x01, // bNumEndpoints
|
||||
0x03, // bInterfaceClass
|
||||
0x01, // bInterfaceSubClass
|
||||
0x02, // bInterfaceProtocol: Mouse
|
||||
0x00, // iInterface
|
||||
|
||||
/* HID Descriptor (Mouse) */
|
||||
0x09, // bLength
|
||||
0x21, // bDescriptorType
|
||||
0x10, 0x01, // bcdHID
|
||||
0x00, // bCountryCode
|
||||
0x01, // bNumDescriptors
|
||||
0x22, // bDescriptorType
|
||||
USBD_SIZE_REPORT_DESC_MS & 0xFF, USBD_SIZE_REPORT_DESC_MS >> 8, // wItemLength
|
||||
|
||||
/* Endpoint Descriptor (Mouse) */
|
||||
0x07, // bLength
|
||||
0x05, // bDescriptorType
|
||||
0x82, // bEndpointAddress: IN Endpoint 2
|
||||
0x03, // bmAttributes
|
||||
DEF_ENDP_SIZE_MS & 0xFF, DEF_ENDP_SIZE_MS >> 8, // wMaxPacketSize
|
||||
0x01 // bInterval: 1mS /* Endpoint Descriptor */
|
||||
};
|
||||
|
||||
/* USB String Descriptors */
|
||||
const uint8_t USBD_StringLangID[USBD_SIZE_STRING_LANGID] = {
|
||||
USBD_SIZE_STRING_LANGID,
|
||||
USB_STRING_DESCRIPTOR_TYPE,
|
||||
0x09,
|
||||
0x04
|
||||
};
|
||||
|
||||
/* USB Device String Vendor */
|
||||
const uint8_t USBD_StringVendor[USBD_SIZE_STRING_VENDOR] = {
|
||||
USBD_SIZE_STRING_VENDOR,
|
||||
USB_STRING_DESCRIPTOR_TYPE,
|
||||
'w',0,'c',0,'h',0,'.',0,'c',0,'n',0
|
||||
};
|
||||
|
||||
/* USB Device String Product */
|
||||
const uint8_t USBD_StringProduct[USBD_SIZE_STRING_PRODUCT] = {
|
||||
USBD_SIZE_STRING_PRODUCT,
|
||||
USB_STRING_DESCRIPTOR_TYPE,
|
||||
'C', 0, 'H', 0, '3', 0, '2', 0, 'F', 0, '2', 0 , '0', 0, 'x', 0
|
||||
};
|
||||
|
||||
/* USB Device String Serial */
|
||||
uint8_t USBD_StringSerial[USBD_SIZE_STRING_SERIAL] = {
|
||||
USBD_SIZE_STRING_SERIAL,
|
||||
USB_STRING_DESCRIPTOR_TYPE,
|
||||
'0', 0, '1', 0, '2', 0, '3', 0, '4', 0, '5', 0 , '6', 0, '7', 0, '8', 0, '9', 0
|
||||
};
|
||||
|
||||
/* HID Report Descriptor */
|
||||
const uint8_t USBD_KeyRepDesc[USBD_SIZE_REPORT_DESC_KB] =
|
||||
{
|
||||
0x05, 0x01, // Usage Page (Generic Desktop)
|
||||
0x09, 0x06, // Usage (Keyboard)
|
||||
0xA1, 0x01, // Collection (Application)
|
||||
0x05, 0x07, // Usage Page (Key Codes)
|
||||
0x19, 0xE0, // Usage Minimum (224)
|
||||
0x29, 0xE7, // Usage Maximum (231)
|
||||
0x15, 0x00, // Logical Minimum (0)
|
||||
0x25, 0x01, // Logical Maximum (1)
|
||||
0x75, 0x01, // Report Size (1)
|
||||
0x95, 0x08, // Report Count (8)
|
||||
0x81, 0x02, // Input (Data,Variable,Absolute)
|
||||
0x95, 0x01, // Report Count (1)
|
||||
0x75, 0x08, // Report Size (8)
|
||||
0x81, 0x01, // Input (Constant)
|
||||
0x95, 0x03, // Report Count (3)
|
||||
0x75, 0x01, // Report Size (1)
|
||||
0x05, 0x08, // Usage Page (LEDs)
|
||||
0x19, 0x01, // Usage Minimum (1)
|
||||
0x29, 0x03, // Usage Maximum (3)
|
||||
0x91, 0x02, // Output (Data,Variable,Absolute)
|
||||
0x95, 0x05, // Report Count (5)
|
||||
0x75, 0x01, // Report Size (1)
|
||||
0x91, 0x01, // Output (Constant,Array,Absolute)
|
||||
0x95, 0x06, // Report Count (6)
|
||||
0x75, 0x08, // Report Size (8)
|
||||
0x26, 0xFF, 0x00, // Logical Maximum (255)
|
||||
0x05, 0x07, // Usage Page (Key Codes)
|
||||
0x19, 0x00, // Usage Minimum (0)
|
||||
0x29, 0x91, // Usage Maximum (145)
|
||||
0x81, 0x00, // Input(Data,Array,Absolute)
|
||||
0xC0 // End Collection
|
||||
};
|
||||
const uint8_t USBD_MouseRepDesc[USBD_SIZE_REPORT_DESC_MS] =
|
||||
{
|
||||
0x05, 0x01, // Usage Page (Generic Desktop)
|
||||
0x09, 0x02, // Usage (Mouse)
|
||||
0xA1, 0x01, // Collection (Application)
|
||||
0x09, 0x01, // Usage (Pointer)
|
||||
0xA1, 0x00, // Collection (Physical)
|
||||
0x05, 0x09, // Usage Page (Button)
|
||||
0x19, 0x01, // Usage Minimum (Button 1)
|
||||
0x29, 0x03, // Usage Maximum (Button 3)
|
||||
0x15, 0x00, // Logical Minimum (0)
|
||||
0x25, 0x01, // Logical Maximum (1)
|
||||
0x75, 0x01, // Report Size (1)
|
||||
0x95, 0x03, // Report Count (3)
|
||||
0x81, 0x02, // Input (Data,Variable,Absolute)
|
||||
0x75, 0x05, // Report Size (5)
|
||||
0x95, 0x01, // Report Count (1)
|
||||
0x81, 0x01, // Input (Constant,Array,Absolute)
|
||||
0x05, 0x01, // Usage Page (Generic Desktop)
|
||||
0x09, 0x30, // Usage (X)
|
||||
0x09, 0x31, // Usage (Y)
|
||||
0x09, 0x38, // Usage (Wheel)
|
||||
0x15, 0x81, // Logical Minimum (-127)
|
||||
0x25, 0x7F, // Logical Maximum (127)
|
||||
0x75, 0x08, // Report Size (8)
|
||||
0x95, 0x03, // Report Count (3)
|
||||
0x81, 0x06, // Input (Data,Variable,Relative)
|
||||
0xC0, // End Collection
|
||||
0xC0 // End Collection
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : usb_desc.h
|
||||
* Author : WCH
|
||||
* Version : V1.0.0
|
||||
* Date : 2021/08/08
|
||||
* Description : This file contains all the functions prototypes for the
|
||||
* USB description firmware library.
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
* Attention: This software (modified or not) and binary are used for
|
||||
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
|
||||
*******************************************************************************/
|
||||
#ifndef __USB_DESC_H
|
||||
#define __USB_DESC_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "ch32v20x.h"
|
||||
|
||||
|
||||
#define USB_DEVICE_DESCRIPTOR_TYPE 0x01
|
||||
#define USB_CONFIGURATION_DESCRIPTOR_TYPE 0x02
|
||||
#define USB_STRING_DESCRIPTOR_TYPE 0x03
|
||||
#define USB_INTERFACE_DESCRIPTOR_TYPE 0x04
|
||||
#define USB_ENDPOINT_DESCRIPTOR_TYPE 0x05
|
||||
|
||||
#define DEF_USBD_UEP0_SIZE 64
|
||||
#define DEF_ENDP_SIZE_KB 8
|
||||
#define DEF_ENDP_SIZE_MS 4
|
||||
|
||||
|
||||
#define USBD_SIZE_DEVICE_DESC 18
|
||||
#define USBD_SIZE_CONFIG_DESC 59
|
||||
#define USBD_SIZE_REPORT_DESC_KB 62
|
||||
#define USBD_SIZE_REPORT_DESC_MS 52
|
||||
#define USBD_SIZE_STRING_LANGID 4
|
||||
#define USBD_SIZE_STRING_VENDOR 14
|
||||
#define USBD_SIZE_STRING_PRODUCT 18
|
||||
#define USBD_SIZE_STRING_SERIAL 22
|
||||
|
||||
|
||||
#define STANDARD_ENDPOINT_DESC_SIZE 0x09
|
||||
|
||||
|
||||
extern const uint8_t USBD_DeviceDescriptor[USBD_SIZE_DEVICE_DESC];
|
||||
extern const uint8_t USBD_ConfigDescriptor[USBD_SIZE_CONFIG_DESC];
|
||||
|
||||
extern const uint8_t USBD_StringLangID [USBD_SIZE_STRING_LANGID];
|
||||
extern const uint8_t USBD_StringVendor [USBD_SIZE_STRING_VENDOR];
|
||||
extern const uint8_t USBD_StringProduct[USBD_SIZE_STRING_PRODUCT];
|
||||
extern uint8_t USBD_StringSerial [USBD_SIZE_STRING_SERIAL];
|
||||
extern const uint8_t USBD_KeyRepDesc[USBD_SIZE_REPORT_DESC_KB];
|
||||
extern const uint8_t USBD_MouseRepDesc[USBD_SIZE_REPORT_DESC_MS];
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USB_DESC_H */
|
||||
@@ -0,0 +1,85 @@
|
||||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : usb_endp.c
|
||||
* Author : WCH
|
||||
* Version : V1.0.0
|
||||
* Date : 2021/08/08
|
||||
* Description : Endpoint routines
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
* Attention: This software (modified or not) and binary are used for
|
||||
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
|
||||
*******************************************************************************/
|
||||
#include "usb_lib.h"
|
||||
#include "usb_desc.h"
|
||||
#include "usb_mem.h"
|
||||
#include "hw_config.h"
|
||||
#include "usb_istr.h"
|
||||
#include "usb_pwr.h"
|
||||
|
||||
uint8_t USBD_Endp1_Busy,USBD_Endp2_Busy;
|
||||
u16 USB_Rx_Cnt=0;
|
||||
|
||||
/*********************************************************************
|
||||
* @fn EP1_IN_Callback
|
||||
*
|
||||
* @brief Endpoint 1 IN.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void EP1_IN_Callback (void)
|
||||
{
|
||||
USBD_Endp1_Busy = 0;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn EP2_IN_Callback
|
||||
*
|
||||
* @brief Endpoint 2 IN.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void EP2_IN_Callback (void)
|
||||
{
|
||||
USBD_Endp2_Busy = 0;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn USBD_ENDPx_DataUp
|
||||
*
|
||||
* @brief USBD ENDPx DataUp Function
|
||||
*
|
||||
* @param endp - endpoint num.
|
||||
* *pbuf - A pointer points to data.
|
||||
* len - data length to transmit.
|
||||
*
|
||||
* @return data up status.
|
||||
*/
|
||||
uint8_t USBD_ENDPx_DataUp( uint8_t endp, uint8_t *pbuf, uint16_t len )
|
||||
{
|
||||
if( endp == ENDP1 )
|
||||
{
|
||||
if (USBD_Endp1_Busy)
|
||||
{
|
||||
return USB_ERROR;
|
||||
}
|
||||
USB_SIL_Write( EP1_IN, pbuf, len );
|
||||
USBD_Endp1_Busy = 1;
|
||||
SetEPTxStatus( ENDP1, EP_TX_VALID );
|
||||
|
||||
}
|
||||
else if( endp == ENDP2 )
|
||||
{
|
||||
if (USBD_Endp2_Busy)
|
||||
{
|
||||
return USB_ERROR;
|
||||
}
|
||||
USB_SIL_Write( EP2_IN, pbuf, len );
|
||||
USBD_Endp2_Busy = 1;
|
||||
SetEPTxStatus( ENDP2, EP_TX_VALID );
|
||||
}
|
||||
else
|
||||
{
|
||||
return USB_ERROR;
|
||||
}
|
||||
return USB_SUCCESS;
|
||||
}
|
||||
@@ -0,0 +1,196 @@
|
||||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : usb_istr.c
|
||||
* Author : WCH
|
||||
* Version : V1.0.1
|
||||
* Date : 2022/12/28
|
||||
* Description : ISTR events interrupt service routines
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
* Attention: This software (modified or not) and binary are used for
|
||||
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
|
||||
*******************************************************************************/
|
||||
#include "usb_lib.h"
|
||||
#include "usb_prop.h"
|
||||
#include "usb_pwr.h"
|
||||
#include "usb_istr.h"
|
||||
|
||||
uint16_t Ep0RxBlks;
|
||||
|
||||
/* Private variables */
|
||||
__IO uint16_t wIstr;
|
||||
__IO uint8_t bIntPackSOF = 0;
|
||||
__IO uint32_t esof_counter =0;
|
||||
__IO uint32_t wCNTR=0;
|
||||
|
||||
/* function pointers to non-control endpoints service routines */
|
||||
void (*pEpInt_IN[7])(void) ={
|
||||
EP1_IN_Callback,
|
||||
EP2_IN_Callback,
|
||||
EP3_IN_Callback,
|
||||
EP4_IN_Callback,
|
||||
EP5_IN_Callback,
|
||||
EP6_IN_Callback,
|
||||
EP7_IN_Callback,
|
||||
};
|
||||
|
||||
void (*pEpInt_OUT[7])(void) ={
|
||||
EP1_OUT_Callback,
|
||||
EP2_OUT_Callback,
|
||||
EP3_OUT_Callback,
|
||||
EP4_OUT_Callback,
|
||||
EP5_OUT_Callback,
|
||||
EP6_OUT_Callback,
|
||||
EP7_OUT_Callback,
|
||||
};
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn USB_Istr
|
||||
*
|
||||
* @brief ISTR events interrupt service routine
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void USB_Istr(void)
|
||||
{
|
||||
uint32_t i=0;
|
||||
__IO uint32_t EP[8];
|
||||
if ((*_pEPRxCount(0) & 0xFC00 )!= Ep0RxBlks)
|
||||
{
|
||||
*_pEPRxCount(0) |= (Ep0RxBlks & 0xFC00);
|
||||
}
|
||||
wIstr = _GetISTR();
|
||||
#if (IMR_MSK & ISTR_SOF)
|
||||
if (wIstr & ISTR_SOF & wInterrupt_Mask)
|
||||
{
|
||||
_SetISTR((uint16_t)CLR_SOF);
|
||||
bIntPackSOF++;
|
||||
|
||||
#ifdef SOF_CALLBACK
|
||||
SOF_Callback();
|
||||
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#if (IMR_MSK & ISTR_CTR)
|
||||
if (wIstr & ISTR_CTR & wInterrupt_Mask)
|
||||
{
|
||||
CTR_LP();
|
||||
#ifdef CTR_CALLBACK
|
||||
CTR_Callback();
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (IMR_MSK & ISTR_RESET)
|
||||
if (wIstr & ISTR_RESET & wInterrupt_Mask)
|
||||
{
|
||||
_SetISTR((uint16_t)CLR_RESET);
|
||||
Device_Property.Reset();
|
||||
|
||||
#ifdef RESET_CALLBACK
|
||||
RESET_Callback();
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (IMR_MSK & ISTR_DOVR)
|
||||
if (wIstr & ISTR_DOVR & wInterrupt_Mask)
|
||||
{
|
||||
_SetISTR((uint16_t)CLR_DOVR);
|
||||
#ifdef DOVR_CALLBACK
|
||||
DOVR_Callback();
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (IMR_MSK & ISTR_ERR)
|
||||
if (wIstr & ISTR_ERR & wInterrupt_Mask)
|
||||
{
|
||||
_SetISTR((uint16_t)CLR_ERR);
|
||||
#ifdef ERR_CALLBACK
|
||||
ERR_Callback();
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (IMR_MSK & ISTR_WKUP)
|
||||
if (wIstr & ISTR_WKUP & wInterrupt_Mask)
|
||||
{
|
||||
_SetISTR((uint16_t)CLR_WKUP);
|
||||
Resume(RESUME_EXTERNAL);
|
||||
#ifdef WKUP_CALLBACK
|
||||
WKUP_Callback();
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
#if (IMR_MSK & ISTR_SUSP)
|
||||
if (wIstr & ISTR_SUSP & wInterrupt_Mask)
|
||||
{
|
||||
if (fSuspendEnabled)
|
||||
{
|
||||
Suspend();
|
||||
}
|
||||
else
|
||||
{
|
||||
Resume(RESUME_LATER);
|
||||
}
|
||||
_SetISTR((uint16_t)CLR_SUSP);
|
||||
#ifdef SUSP_CALLBACK
|
||||
SUSP_Callback();
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (IMR_MSK & ISTR_ESOF)
|
||||
if (wIstr & ISTR_ESOF & wInterrupt_Mask)
|
||||
{
|
||||
_SetISTR((uint16_t)CLR_ESOF);
|
||||
|
||||
if ((_GetFNR()&FNR_RXDP)!=0)
|
||||
{
|
||||
esof_counter ++;
|
||||
|
||||
if ((esof_counter >3)&&((_GetCNTR()&CNTR_FSUSP)==0))
|
||||
{
|
||||
|
||||
wCNTR = _GetCNTR();
|
||||
|
||||
for (i=0;i<8;i++) EP[i] = _GetENDPOINT(i);
|
||||
|
||||
wCNTR|=CNTR_FRES;
|
||||
_SetCNTR(wCNTR);
|
||||
|
||||
wCNTR&=~CNTR_FRES;
|
||||
_SetCNTR(wCNTR);
|
||||
|
||||
while((_GetISTR()&ISTR_RESET) == 0);
|
||||
|
||||
_SetISTR((uint16_t)CLR_RESET);
|
||||
|
||||
for (i=0;i<8;i++)
|
||||
_SetENDPOINT(i, EP[i]);
|
||||
|
||||
esof_counter = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
esof_counter = 0;
|
||||
}
|
||||
|
||||
Resume(RESUME_ESOF);
|
||||
|
||||
#ifdef ESOF_CALLBACK
|
||||
ESOF_Callback();
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
} /* USB_Istr */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : usb_istr.h
|
||||
* Author : WCH
|
||||
* Version : V1.0.0
|
||||
* Date : 2021/08/08
|
||||
* Description : This file includes the peripherals header files in the
|
||||
* user application.
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
* Attention: This software (modified or not) and binary are used for
|
||||
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
|
||||
*******************************************************************************/
|
||||
#ifndef __USB_ISTR_H
|
||||
#define __USB_ISTR_H
|
||||
|
||||
#include "usb_conf.h"
|
||||
|
||||
|
||||
void USB_Istr(void);
|
||||
void EP1_IN_Callback(void);
|
||||
void EP2_IN_Callback(void);
|
||||
void EP3_IN_Callback(void);
|
||||
void EP4_IN_Callback(void);
|
||||
void EP5_IN_Callback(void);
|
||||
void EP6_IN_Callback(void);
|
||||
void EP7_IN_Callback(void);
|
||||
|
||||
void EP1_OUT_Callback(void);
|
||||
void EP2_OUT_Callback(void);
|
||||
void EP3_OUT_Callback(void);
|
||||
void EP4_OUT_Callback(void);
|
||||
void EP5_OUT_Callback(void);
|
||||
void EP6_OUT_Callback(void);
|
||||
void EP7_OUT_Callback(void);
|
||||
|
||||
#ifdef CTR_CALLBACK
|
||||
void CTR_Callback(void);
|
||||
#endif
|
||||
|
||||
#ifdef DOVR_CALLBACK
|
||||
void DOVR_Callback(void);
|
||||
#endif
|
||||
|
||||
#ifdef ERR_CALLBACK
|
||||
void ERR_Callback(void);
|
||||
#endif
|
||||
|
||||
#ifdef WKUP_CALLBACK
|
||||
void WKUP_Callback(void);
|
||||
#endif
|
||||
|
||||
#ifdef SUSP_CALLBACK
|
||||
void SUSP_Callback(void);
|
||||
#endif
|
||||
|
||||
#ifdef RESET_CALLBACK
|
||||
void RESET_Callback(void);
|
||||
#endif
|
||||
|
||||
#ifdef SOF_CALLBACK
|
||||
void SOF_Callback(void);
|
||||
#endif
|
||||
|
||||
#ifdef ESOF_CALLBACK
|
||||
void ESOF_Callback(void);
|
||||
#endif
|
||||
|
||||
|
||||
#endif /*__USB_ISTR_H*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,555 @@
|
||||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : usb_prop.c
|
||||
* Author : WCH
|
||||
* Version : V1.0.0
|
||||
* Date : 2022/08/20
|
||||
* Description : USB Processing
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
* Attention: This software (modified or not) and binary are used for
|
||||
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
|
||||
*******************************************************************************/
|
||||
#include "usb_lib.h"
|
||||
#include "usb_conf.h"
|
||||
#include "usb_prop.h"
|
||||
#include "usb_desc.h"
|
||||
#include "usb_pwr.h"
|
||||
#include "hw_config.h"
|
||||
#include "usbd_composite_km.h"
|
||||
|
||||
|
||||
uint8_t Request = 0;
|
||||
|
||||
extern uint8_t USBD_Endp1_Busy,USBD_Endp2_Busy;
|
||||
volatile uint8_t HIDReportOut[8] = {0};
|
||||
volatile uint8_t USBD_Sleep_Status = 0x00;
|
||||
volatile uint8_t HID_Idle_Value[2] = {0};
|
||||
volatile uint8_t HID_Protocol_Value[2] = {0};
|
||||
|
||||
DEVICE Device_Table =
|
||||
{
|
||||
EP_NUM,
|
||||
1
|
||||
};
|
||||
|
||||
DEVICE_PROP Device_Property =
|
||||
{
|
||||
USBD_init,
|
||||
USBD_Reset,
|
||||
USBD_Status_In,
|
||||
USBD_Status_Out,
|
||||
USBD_Data_Setup,
|
||||
USBD_NoData_Setup,
|
||||
USBD_Get_Interface_Setting,
|
||||
USBD_GetDeviceDescriptor,
|
||||
USBD_GetConfigDescriptor,
|
||||
USBD_GetStringDescriptor,
|
||||
0,
|
||||
DEF_USBD_UEP0_SIZE
|
||||
};
|
||||
|
||||
USER_STANDARD_REQUESTS User_Standard_Requests =
|
||||
{
|
||||
USBD_GetConfiguration,
|
||||
USBD_SetConfiguration,
|
||||
USBD_GetInterface,
|
||||
USBD_SetInterface,
|
||||
USBD_GetStatus,
|
||||
USBD_ClearFeature,
|
||||
USBD_SetEndPointFeature,
|
||||
USBD_SetDeviceFeature,
|
||||
USBD_SetDeviceAddress
|
||||
};
|
||||
|
||||
ONE_DESCRIPTOR Device_Descriptor =
|
||||
{
|
||||
(uint8_t*)USBD_DeviceDescriptor,
|
||||
USBD_SIZE_DEVICE_DESC
|
||||
};
|
||||
|
||||
ONE_DESCRIPTOR Config_Descriptor =
|
||||
{
|
||||
(uint8_t*)USBD_ConfigDescriptor,
|
||||
USBD_SIZE_CONFIG_DESC
|
||||
};
|
||||
|
||||
ONE_DESCRIPTOR String_Descriptor[4] =
|
||||
{
|
||||
{(uint8_t*)USBD_StringLangID, USBD_SIZE_STRING_LANGID},
|
||||
{(uint8_t*)USBD_StringVendor, USBD_SIZE_STRING_VENDOR},
|
||||
{(uint8_t*)USBD_StringProduct,USBD_SIZE_STRING_PRODUCT},
|
||||
{(uint8_t*)USBD_StringSerial, USBD_SIZE_STRING_SERIAL}
|
||||
};
|
||||
|
||||
ONE_DESCRIPTOR Report_Descriptor[2] =
|
||||
{
|
||||
{(uint8_t*)USBD_KeyRepDesc, USBD_SIZE_REPORT_DESC_KB},
|
||||
{(uint8_t*)USBD_MouseRepDesc, USBD_SIZE_REPORT_DESC_MS},
|
||||
};
|
||||
|
||||
ONE_DESCRIPTOR Hid_Descriptor[2] =
|
||||
{
|
||||
{(uint8_t*)&USBD_ConfigDescriptor[18], 0x09},
|
||||
{(uint8_t*)&USBD_ConfigDescriptor[43], 0x09},
|
||||
};
|
||||
|
||||
|
||||
/*********************************************************************
|
||||
* @fn USBD_SetConfiguration.
|
||||
*
|
||||
* @brief Update the device state to configured.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void USBD_SetConfiguration(void)
|
||||
{
|
||||
DEVICE_INFO *pInfo = &Device_Info;
|
||||
|
||||
if (pInfo->Current_Configuration != 0)
|
||||
{
|
||||
bDeviceState = CONFIGURED;
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn USBD_SetDeviceAddress.
|
||||
*
|
||||
* @brief Update the device state to addressed.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void USBD_SetDeviceAddress (void)
|
||||
{
|
||||
bDeviceState = ADDRESSED;
|
||||
}
|
||||
|
||||
|
||||
/*********************************************************************
|
||||
* @fn USBD_SetDeviceFeature.
|
||||
*
|
||||
* @brief SetDeviceFeature Routine.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void USBD_SetDeviceFeature (void)
|
||||
{
|
||||
USBD_Sleep_Status |= 0x01;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*********************************************************************
|
||||
* @fn USBD_ClearFeature.
|
||||
*
|
||||
* @brief ClearFeature Routine.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void USBD_ClearFeature(void)
|
||||
{
|
||||
USBD_Sleep_Status &= ~0x01;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*********************************************************************
|
||||
* @fn USBD_Status_In.
|
||||
*
|
||||
* @brief USBD Status In Routine.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void USBD_Status_In(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn USBD_Status_Out
|
||||
*
|
||||
* @brief USBD Status OUT Routine.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void USBD_Status_Out(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn USB_init.
|
||||
*
|
||||
* @brief init routine.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void USBD_init(void)
|
||||
{
|
||||
uint8_t i;
|
||||
|
||||
pInformation->Current_Configuration = 0;
|
||||
PowerOn();
|
||||
for (i=0;i<8;i++) _SetENDPOINT(i,_GetENDPOINT(i) & 0x7F7F & EPREG_MASK);//all clear
|
||||
_SetISTR((uint16_t)0x00FF);//all clear
|
||||
USB_SIL_Init();
|
||||
bDeviceState = UNCONNECTED;
|
||||
|
||||
USB_Port_Set(DISABLE, DISABLE);
|
||||
Delay_Ms(20);
|
||||
USB_Port_Set(ENABLE, ENABLE);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn USBD_Reset
|
||||
*
|
||||
* @brief Virtual_Com_Port Mouse reset routine
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void USBD_Reset(void)
|
||||
{
|
||||
pInformation->Current_Configuration = 0;
|
||||
pInformation->Current_Feature = USBD_ConfigDescriptor[7];
|
||||
pInformation->Current_Interface = 0;
|
||||
|
||||
SetBTABLE(BTABLE_ADDRESS);
|
||||
|
||||
SetEPType(ENDP0, EP_CONTROL);
|
||||
SetEPTxStatus(ENDP0, EP_TX_STALL);
|
||||
SetEPRxAddr(ENDP0, ENDP0_RXADDR);
|
||||
SetEPTxAddr(ENDP0, ENDP0_TXADDR);
|
||||
Clear_Status_Out(ENDP0);
|
||||
SetEPRxCount(ENDP0, Device_Property.MaxPacketSize);
|
||||
SetEPRxValid(ENDP0);
|
||||
_ClearDTOG_RX(ENDP0);
|
||||
_ClearDTOG_TX(ENDP0);
|
||||
|
||||
SetEPType(ENDP1, EP_INTERRUPT);
|
||||
SetEPTxAddr(ENDP1, ENDP1_TXADDR);
|
||||
SetEPTxStatus(ENDP1, EP_TX_NAK);
|
||||
_ClearDTOG_TX(ENDP1);
|
||||
_ClearDTOG_RX(ENDP1);
|
||||
|
||||
SetEPType(ENDP2, EP_INTERRUPT);
|
||||
SetEPTxAddr(ENDP2, ENDP2_TXADDR);
|
||||
SetEPTxStatus(ENDP2, EP_TX_NAK);
|
||||
_ClearDTOG_TX(ENDP2);
|
||||
_ClearDTOG_RX(ENDP2);
|
||||
|
||||
SetDeviceAddress(0);
|
||||
|
||||
bDeviceState = ATTACHED;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn USBD_GetDeviceDescriptor.
|
||||
*
|
||||
* @brief Gets the device descriptor.
|
||||
*
|
||||
* @param Length.
|
||||
*
|
||||
* @return The address of the device descriptor.
|
||||
*/
|
||||
uint8_t *USBD_GetDeviceDescriptor(uint16_t Length)
|
||||
{
|
||||
return Standard_GetDescriptorData(Length, &Device_Descriptor);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn USBD_GetConfigDescriptor.
|
||||
*
|
||||
* @brief get the configuration descriptor.
|
||||
*
|
||||
* @param Length.
|
||||
*
|
||||
* @return The address of the configuration descriptor.
|
||||
*/
|
||||
uint8_t *USBD_GetConfigDescriptor(uint16_t Length)
|
||||
{
|
||||
return Standard_GetDescriptorData(Length, &Config_Descriptor);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn USBD_GetStringDescriptor
|
||||
*
|
||||
* @brief Gets the string descriptors according to the needed index
|
||||
*
|
||||
* @param Length.
|
||||
*
|
||||
* @return The address of the string descriptors.
|
||||
*/
|
||||
uint8_t *USBD_GetStringDescriptor(uint16_t Length)
|
||||
{
|
||||
uint8_t wValue0 = pInformation->USBwValue0;
|
||||
|
||||
if (wValue0 > 4)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Standard_GetDescriptorData(Length, &String_Descriptor[wValue0]);
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn USBD_GetReportDescriptor
|
||||
*
|
||||
* @brief Gets the report descriptors according to the needed index
|
||||
*
|
||||
* @param Length.
|
||||
*
|
||||
* @return The address of the device descriptor.
|
||||
*/
|
||||
uint8_t *USBD_GetReportDescriptor(uint16_t Length)
|
||||
{
|
||||
uint8_t wIndex0 = pInformation->USBwIndexs.bw.bb0;
|
||||
if (wIndex0 > 2)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Standard_GetDescriptorData(Length, &Report_Descriptor[wIndex0]);
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn USBD_GetHidDescriptor
|
||||
*
|
||||
* @brief Gets the report descriptors according to the needed index
|
||||
*
|
||||
* @param Length.
|
||||
*
|
||||
* @return The address of the device descriptor.
|
||||
*/
|
||||
uint8_t *USBD_GetHidDescriptor(uint16_t Length)
|
||||
{
|
||||
uint8_t wIndex0 = pInformation->USBwIndexs.bw.bb0;
|
||||
if (wIndex0 > 2)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Standard_GetDescriptorData(Length, &Hid_Descriptor[wIndex0]);
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn USBD_Get_Interface_Setting.
|
||||
*
|
||||
* @brief test the interface and the alternate setting according to the
|
||||
* supported one.
|
||||
*
|
||||
* @param Interface: interface number.
|
||||
* AlternateSetting: Alternate Setting number.
|
||||
*
|
||||
* @return USB_UNSUPPORT or USB_SUCCESS.
|
||||
*/
|
||||
RESULT USBD_Get_Interface_Setting(uint8_t Interface, uint8_t AlternateSetting)
|
||||
{
|
||||
if (AlternateSetting > 0)
|
||||
{
|
||||
return USB_UNSUPPORT;
|
||||
}
|
||||
else if (Interface > 1)
|
||||
{
|
||||
return USB_UNSUPPORT;
|
||||
}
|
||||
|
||||
return USB_SUCCESS;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn USBD_Data_Setup
|
||||
*
|
||||
* @brief handle the data class specific requests
|
||||
*
|
||||
* @param Request Nb.
|
||||
*
|
||||
* @return USB_UNSUPPORT or USB_SUCCESS.
|
||||
*/
|
||||
RESULT USBD_Data_Setup(uint8_t RequestNo)
|
||||
{
|
||||
uint8_t *(*CopyRoutine)(uint16_t);
|
||||
uint32_t Request_No = pInformation->USBbRequest;
|
||||
uint32_t wOffset;
|
||||
CopyRoutine = NULL;
|
||||
wOffset = 0;
|
||||
|
||||
|
||||
if (Type_Recipient == (STANDARD_REQUEST | INTERFACE_RECIPIENT))
|
||||
{
|
||||
uint8_t wValue1 = pInformation->USBwValue1;
|
||||
|
||||
if (wValue1 == HID_REPORT_DESCRIPTOR)
|
||||
{
|
||||
CopyRoutine = USBD_GetReportDescriptor;
|
||||
}
|
||||
else if (wValue1 == HID_DESCRIPTOR)
|
||||
{
|
||||
CopyRoutine = USBD_GetHidDescriptor;
|
||||
}
|
||||
if (CopyRoutine)
|
||||
{
|
||||
pInformation->Ctrl_Info.Usb_wOffset = wOffset;
|
||||
pInformation->Ctrl_Info.CopyData = CopyRoutine;
|
||||
(*CopyRoutine)(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
return USB_UNSUPPORT;
|
||||
}
|
||||
|
||||
}
|
||||
else if (Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT) )
|
||||
{
|
||||
if (Request_No == HID_GET_REPORT)
|
||||
{
|
||||
/* HID Get Report */
|
||||
}
|
||||
else if (Request_No == HID_GET_IDLE)
|
||||
{
|
||||
pInformation->Ctrl_Info.Usb_wLength = 1;
|
||||
pInformation->Ctrl_Info.CopyData = &HID_Get_Idle;
|
||||
}
|
||||
else if (Request_No == HID_GET_PROTOCOL)
|
||||
{
|
||||
pInformation->Ctrl_Info.Usb_wLength = 1;
|
||||
pInformation->Ctrl_Info.CopyData = &HID_Get_Protocol;
|
||||
}
|
||||
else if (Request_No == HID_SET_REPORT)
|
||||
{
|
||||
if (pInformation->USBwLengths.w > 1)
|
||||
{
|
||||
return USB_UNSUPPORT;
|
||||
}
|
||||
else
|
||||
{
|
||||
pInformation->Ctrl_Info.Usb_wLength = pInformation->USBwLengths.w;
|
||||
pInformation->Ctrl_Info.CopyData = &HID_Set_Report;
|
||||
pInformation->ControlState = OUT_DATA;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return USB_UNSUPPORT;
|
||||
}
|
||||
}
|
||||
return USB_SUCCESS;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn USBD_NoData_Setup.
|
||||
*
|
||||
* @brief handle the no data class specific requests.
|
||||
*
|
||||
* @param Request Nb.
|
||||
*
|
||||
* @return USB_UNSUPPORT or USB_SUCCESS.
|
||||
*/
|
||||
RESULT USBD_NoData_Setup(uint8_t RequestNo)
|
||||
{
|
||||
uint32_t Request_No = pInformation->USBbRequest;
|
||||
uint8_t wIndex0 = pInformation->USBwIndexs.bw.bb0;
|
||||
if (Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT))
|
||||
{
|
||||
if (Request_No == HID_SET_IDLE)
|
||||
{
|
||||
if (wIndex0 > 2)
|
||||
{
|
||||
return USB_UNSUPPORT;
|
||||
}
|
||||
else
|
||||
{
|
||||
HID_Idle_Value[wIndex0] = pInformation->USBwValues.bw.bb1;
|
||||
}
|
||||
|
||||
}
|
||||
else if (Request_No == HID_SET_PROTOCOL)
|
||||
{
|
||||
if (wIndex0 > 2)
|
||||
{
|
||||
return USB_UNSUPPORT;
|
||||
}
|
||||
else
|
||||
{
|
||||
HID_Protocol_Value[wIndex0] = pInformation->USBwValues.bw.bb0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return USB_UNSUPPORT;
|
||||
}
|
||||
}
|
||||
return USB_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
/*********************************************************************
|
||||
* @fn HID_Set_Report.
|
||||
*
|
||||
* @brief HID Set Report.
|
||||
*
|
||||
* @param
|
||||
*
|
||||
* @return HIDReportOut.
|
||||
*/
|
||||
uint8_t *HID_Set_Report(uint16_t Length)
|
||||
{
|
||||
uint8_t wIndex0 = pInformation->USBwIndexs.bw.bb0;
|
||||
if (wIndex0 > 1)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
return (uint8_t *)&KB_LED_Cur_Status;
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn HID_Get_Idle.
|
||||
*
|
||||
* @brief HID Save Report Data.
|
||||
*
|
||||
* @param
|
||||
*
|
||||
* @return HIDReportOut.
|
||||
*/
|
||||
uint8_t *HID_Get_Idle(uint16_t Length)
|
||||
{
|
||||
uint8_t wIndex0 = pInformation->USBwIndexs.bw.bb0;
|
||||
if (wIndex0 > 2)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
return (uint8_t*)&HID_Idle_Value[wIndex0];
|
||||
}
|
||||
}
|
||||
/*********************************************************************
|
||||
* @fn HID_Get_Protocol.
|
||||
*
|
||||
* @brief HID Save Report Data.
|
||||
*
|
||||
* @param
|
||||
*
|
||||
* @return HIDReportOut.
|
||||
*/
|
||||
uint8_t *HID_Get_Protocol(uint16_t Length)
|
||||
{
|
||||
uint8_t wIndex0 = pInformation->USBwIndexs.bw.bb0;
|
||||
if (wIndex0 > 2)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
return (uint8_t*)&HID_Protocol_Value[wIndex0];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : usb_prop.h
|
||||
* Author : WCH
|
||||
* Version : V1.0.0
|
||||
* Date : 2022/08/20
|
||||
* Description : USB processing.
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
* Attention: This software (modified or not) and binary are used for
|
||||
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
|
||||
*******************************************************************************/
|
||||
#ifndef __usb_prop_H
|
||||
#define __usb_prop_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "ch32v20x.h"
|
||||
|
||||
#define USBD_GetConfiguration NOP_Process
|
||||
//#define USBD_SetConfiguration NOP_Process
|
||||
#define USBD_GetInterface NOP_Process
|
||||
#define USBD_SetInterface NOP_Process
|
||||
#define USBD_GetStatus NOP_Process
|
||||
// #define USBD_ClearFeature NOP_Process
|
||||
#define USBD_SetEndPointFeature NOP_Process
|
||||
// #define USBD_SetDeviceFeature NOP_Process
|
||||
//#define USBD_SetDeviceAddress NOP_Process
|
||||
|
||||
#define SEND_ENCAPSULATED_COMMAND 0x00
|
||||
#define GET_ENCAPSULATED_RESPONSE 0x01
|
||||
#define SET_COMM_FEATURE 0x02
|
||||
#define GET_COMM_FEATURE 0x03
|
||||
#define CLEAR_COMM_FEATURE 0x04
|
||||
#define SET_LINE_CODING 0x20
|
||||
#define GET_LINE_CODING 0x21
|
||||
#define SET_CONTROL_LINE_STATE 0x22
|
||||
#define SEND_BREAK 0x23
|
||||
|
||||
|
||||
/* Definition of HID */
|
||||
|
||||
#define HID_GET_REPORT 0x01
|
||||
#define HID_GET_IDLE 0x02
|
||||
#define HID_GET_PROTOCOL 0x03
|
||||
#define HID_SET_REPORT 0x09
|
||||
#define HID_SET_IDLE 0x0A
|
||||
#define HID_SET_PROTOCOL 0x0B
|
||||
|
||||
#define HID_DESCRIPTOR 0x21
|
||||
#define HID_REPORT_DESCRIPTOR 0x22
|
||||
|
||||
#define HID_SET_REPORT_DEAL_OVER 0x00
|
||||
#define HID_SET_REPORT_WAIT_DEAL 0x01
|
||||
|
||||
|
||||
extern volatile uint8_t USBD_Sleep_Status;
|
||||
|
||||
void USBD_init(void);
|
||||
void USBD_Reset(void);
|
||||
void USBD_SetConfiguration(void);
|
||||
void USBD_SetDeviceAddress (void);
|
||||
void USBD_SetDeviceFeature (void);
|
||||
void USBD_ClearFeature (void);
|
||||
void USBD_Status_In (void);
|
||||
void USBD_Status_Out (void);
|
||||
RESULT USBD_Data_Setup(uint8_t);
|
||||
RESULT USBD_NoData_Setup(uint8_t);
|
||||
RESULT USBD_Get_Interface_Setting(uint8_t Interface, uint8_t AlternateSetting);
|
||||
uint8_t *USBD_GetDeviceDescriptor(uint16_t );
|
||||
uint8_t *USBD_GetConfigDescriptor(uint16_t);
|
||||
uint8_t *USBD_GetStringDescriptor(uint16_t);
|
||||
uint8_t *USBD_GetReportDescriptor(uint16_t);
|
||||
uint8_t *HID_Set_Report(uint16_t);
|
||||
uint8_t *HID_Get_Idle(uint16_t);
|
||||
uint8_t *HID_Get_Protocol(uint16_t);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __usb_prop_H */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,215 @@
|
||||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : usb_pwr.c
|
||||
* Author : WCH
|
||||
* Version : V1.0.0
|
||||
* Date : 2021/08/08
|
||||
* Description : Connection/disconnection & power management
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
* Attention: This software (modified or not) and binary are used for
|
||||
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
|
||||
*******************************************************************************/
|
||||
#include "usb_lib.h"
|
||||
#include "usb_conf.h"
|
||||
#include "usb_pwr.h"
|
||||
#include "hw_config.h"
|
||||
|
||||
__IO uint32_t bDeviceState = UNCONNECTED;
|
||||
__IO bool fSuspendEnabled = TRUE;
|
||||
__IO uint32_t EP[8];
|
||||
|
||||
struct
|
||||
{
|
||||
__IO RESUME_STATE eState;
|
||||
__IO uint8_t bESOFcnt;
|
||||
}
|
||||
ResumeS;
|
||||
|
||||
__IO uint32_t remotewakeupon=0;
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn PowerOn
|
||||
*
|
||||
* @brief Enable power on.
|
||||
*
|
||||
* @return USB_SUCCESS.
|
||||
*/
|
||||
RESULT PowerOn(void)
|
||||
{
|
||||
uint16_t wRegVal;
|
||||
|
||||
wRegVal = CNTR_FRES;
|
||||
_SetCNTR(wRegVal);
|
||||
wInterrupt_Mask = 0;
|
||||
_SetCNTR(wInterrupt_Mask);
|
||||
_SetISTR(0);
|
||||
wInterrupt_Mask = CNTR_RESETM | CNTR_SUSPM | CNTR_WKUPM;
|
||||
_SetCNTR(wInterrupt_Mask);
|
||||
|
||||
return USB_SUCCESS;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn PowerOff
|
||||
*
|
||||
* @brief handles switch-off conditions
|
||||
*
|
||||
* @return USB_SUCCESS.
|
||||
*/
|
||||
RESULT PowerOff()
|
||||
{
|
||||
_SetCNTR(CNTR_FRES);
|
||||
_SetISTR(0);
|
||||
_SetCNTR(CNTR_FRES + CNTR_PDWN);
|
||||
|
||||
return USB_SUCCESS;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn Suspend
|
||||
*
|
||||
* @brief sets suspend mode operating conditions
|
||||
*
|
||||
* @return USB_SUCCESS.
|
||||
*/
|
||||
void Suspend(void)
|
||||
{
|
||||
uint32_t i =0;
|
||||
uint16_t wCNTR;
|
||||
|
||||
wCNTR = _GetCNTR();
|
||||
for (i=0;i<8;i++) EP[i] = _GetENDPOINT(i);
|
||||
|
||||
wCNTR|=CNTR_RESETM;
|
||||
_SetCNTR(wCNTR);
|
||||
|
||||
wCNTR|=CNTR_FRES;
|
||||
_SetCNTR(wCNTR);
|
||||
|
||||
wCNTR&=~CNTR_FRES;
|
||||
_SetCNTR(wCNTR);
|
||||
|
||||
while((_GetISTR()&ISTR_RESET) == 0);
|
||||
|
||||
_SetISTR((uint16_t)CLR_RESET);
|
||||
|
||||
for (i=0;i<8;i++)
|
||||
_SetENDPOINT(i, EP[i]);
|
||||
|
||||
wCNTR |= CNTR_FSUSP;
|
||||
_SetCNTR(wCNTR);
|
||||
|
||||
wCNTR = _GetCNTR();
|
||||
wCNTR |= CNTR_LPMODE;
|
||||
_SetCNTR(wCNTR);
|
||||
|
||||
Enter_LowPowerMode();
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn Resume_Init
|
||||
*
|
||||
* @brief Handles wake-up restoring normal operations
|
||||
*
|
||||
* @return USB_SUCCESS.
|
||||
*/
|
||||
void Resume_Init(void)
|
||||
{
|
||||
uint16_t wCNTR;
|
||||
|
||||
wCNTR = _GetCNTR();
|
||||
wCNTR &= (~CNTR_LPMODE);
|
||||
_SetCNTR(wCNTR);
|
||||
Leave_LowPowerMode();
|
||||
_SetCNTR(IMR_MSK);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn Resume
|
||||
*
|
||||
* @brief This is the state machine handling resume operations and
|
||||
* timing sequence. The control is based on the Resume structure
|
||||
* variables and on the ESOF interrupt calling this subroutine
|
||||
* without changing machine state.
|
||||
*
|
||||
* @param a state machine value (RESUME_STATE)
|
||||
* RESUME_ESOF doesn't change ResumeS.eState allowing
|
||||
* decrementing of the ESOF counter in different states.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void Resume(RESUME_STATE eResumeSetVal)
|
||||
{
|
||||
uint16_t wCNTR;
|
||||
|
||||
if (eResumeSetVal != RESUME_ESOF)
|
||||
{
|
||||
ResumeS.eState = eResumeSetVal;
|
||||
}
|
||||
|
||||
switch (ResumeS.eState)
|
||||
{
|
||||
case RESUME_EXTERNAL:
|
||||
if (remotewakeupon ==0)
|
||||
{
|
||||
Resume_Init();
|
||||
ResumeS.eState = RESUME_OFF;
|
||||
}
|
||||
else
|
||||
{
|
||||
ResumeS.eState = RESUME_ON;
|
||||
}
|
||||
break;
|
||||
|
||||
case RESUME_INTERNAL:
|
||||
Resume_Init();
|
||||
ResumeS.eState = RESUME_START;
|
||||
remotewakeupon = 1;
|
||||
break;
|
||||
|
||||
case RESUME_LATER:
|
||||
ResumeS.bESOFcnt = 2;
|
||||
ResumeS.eState = RESUME_WAIT;
|
||||
break;
|
||||
|
||||
case RESUME_WAIT:
|
||||
ResumeS.bESOFcnt--;
|
||||
if (ResumeS.bESOFcnt == 0)
|
||||
ResumeS.eState = RESUME_START;
|
||||
break;
|
||||
|
||||
case RESUME_START:
|
||||
wCNTR = _GetCNTR();
|
||||
wCNTR |= CNTR_RESUME;
|
||||
_SetCNTR(wCNTR);
|
||||
ResumeS.eState = RESUME_ON;
|
||||
ResumeS.bESOFcnt = 10;
|
||||
break;
|
||||
|
||||
case RESUME_ON:
|
||||
ResumeS.bESOFcnt--;
|
||||
if (ResumeS.bESOFcnt == 0)
|
||||
{
|
||||
wCNTR = _GetCNTR();
|
||||
wCNTR &= (~CNTR_RESUME);
|
||||
_SetCNTR(wCNTR);
|
||||
ResumeS.eState = RESUME_OFF;
|
||||
remotewakeupon = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case RESUME_OFF:
|
||||
|
||||
case RESUME_ESOF:
|
||||
|
||||
default:
|
||||
ResumeS.eState = RESUME_OFF;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : usb_pwr.h
|
||||
* Author : WCH
|
||||
* Version : V1.0.0
|
||||
* Date : 2021/08/08
|
||||
* Description : Connection/disconnection & power management header
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
* Attention: This software (modified or not) and binary are used for
|
||||
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
|
||||
*******************************************************************************/
|
||||
#ifndef __USB_PWR_H
|
||||
#define __USB_PWR_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "ch32v20x.h"
|
||||
typedef enum _RESUME_STATE
|
||||
{
|
||||
RESUME_EXTERNAL,
|
||||
RESUME_INTERNAL,
|
||||
RESUME_LATER,
|
||||
RESUME_WAIT,
|
||||
RESUME_START,
|
||||
RESUME_ON,
|
||||
RESUME_OFF,
|
||||
RESUME_ESOF
|
||||
} RESUME_STATE;
|
||||
|
||||
typedef enum _DEVICE_STATE
|
||||
{
|
||||
UNCONNECTED,
|
||||
ATTACHED,
|
||||
POWERED,
|
||||
SUSPENDED,
|
||||
ADDRESSED,
|
||||
CONFIGURED
|
||||
} DEVICE_STATE;
|
||||
|
||||
|
||||
void Suspend(void);
|
||||
void Resume_Init(void);
|
||||
void Resume(RESUME_STATE eResumeSetVal);
|
||||
RESULT PowerOn(void);
|
||||
RESULT PowerOff(void);
|
||||
|
||||
extern __IO uint32_t bDeviceState; /* USB device status */
|
||||
extern __IO bool fSuspendEnabled; /* true when suspend is possible */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*__USB_PWR_H*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,191 @@
|
||||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : usb_core.h
|
||||
* Author : WCH
|
||||
* Version : V1.0.0
|
||||
* Date : 2021/08/08
|
||||
* Description : This file contains all the functions prototypes for the
|
||||
* USB cor firmware library.
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
* Attention: This software (modified or not) and binary are used for
|
||||
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
|
||||
*******************************************************************************/
|
||||
#ifndef __USB_CORE_H
|
||||
#define __USB_CORE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "ch32v20x.h"
|
||||
|
||||
|
||||
typedef enum _CONTROL_STATE
|
||||
{
|
||||
WAIT_SETUP, /* 0 */
|
||||
SETTING_UP, /* 1 */
|
||||
IN_DATA, /* 2 */
|
||||
OUT_DATA, /* 3 */
|
||||
LAST_IN_DATA, /* 4 */
|
||||
LAST_OUT_DATA, /* 5 */
|
||||
WAIT_STATUS_IN, /* 7 */
|
||||
WAIT_STATUS_OUT, /* 8 */
|
||||
STALLED, /* 9 */
|
||||
PAUSE /* 10 */
|
||||
} CONTROL_STATE; /* The state machine states of a control pipe */
|
||||
|
||||
typedef struct OneDescriptor
|
||||
{
|
||||
uint8_t *Descriptor;
|
||||
uint16_t Descriptor_Size;
|
||||
}
|
||||
ONE_DESCRIPTOR, *PONE_DESCRIPTOR;
|
||||
|
||||
typedef enum _RESULT
|
||||
{
|
||||
USB_SUCCESS = 0, /* Process successfully */
|
||||
USB_ERROR,
|
||||
USB_UNSUPPORT,
|
||||
USB_NOT_READY /* The process has not been finished, endpoint will be
|
||||
NAK to further request */
|
||||
} RESULT;
|
||||
|
||||
|
||||
/* Definitions for endpoint level */
|
||||
typedef struct _ENDPOINT_INFO
|
||||
{
|
||||
uint16_t Usb_wLength;
|
||||
uint16_t Usb_wOffset;
|
||||
uint16_t PacketSize;
|
||||
uint8_t *(*CopyData)(uint16_t Length);
|
||||
}ENDPOINT_INFO;
|
||||
|
||||
/* Definitions for device level */
|
||||
typedef struct _DEVICE
|
||||
{
|
||||
uint8_t Total_Endpoint; /* Number of endpoints that are used */
|
||||
uint8_t Total_Configuration;/* Number of configuration available */
|
||||
}
|
||||
DEVICE;
|
||||
|
||||
typedef union
|
||||
{
|
||||
uint16_t w;
|
||||
struct BW
|
||||
{
|
||||
uint8_t bb1;
|
||||
uint8_t bb0;
|
||||
}
|
||||
bw;
|
||||
} uint16_t_uint8_t;
|
||||
|
||||
typedef struct _DEVICE_INFO
|
||||
{
|
||||
uint8_t USBbmRequestType; /* bmRequestType */
|
||||
uint8_t USBbRequest; /* bRequest */
|
||||
uint16_t_uint8_t USBwValues; /* wValue */
|
||||
uint16_t_uint8_t USBwIndexs; /* wIndex */
|
||||
uint16_t_uint8_t USBwLengths; /* wLength */
|
||||
|
||||
uint8_t ControlState; /* of type CONTROL_STATE */
|
||||
uint8_t Current_Feature;
|
||||
uint8_t Current_Configuration; /* Selected configuration */
|
||||
uint8_t Current_Interface; /* Selected interface of current configuration */
|
||||
uint8_t Current_AlternateSetting;/* Selected Alternate Setting of current
|
||||
interface*/
|
||||
|
||||
ENDPOINT_INFO Ctrl_Info;
|
||||
}DEVICE_INFO;
|
||||
|
||||
typedef struct _DEVICE_PROP
|
||||
{
|
||||
void (*Init)(void); /* Initialize the device */
|
||||
void (*Reset)(void); /* Reset routine of this device */
|
||||
void (*Process_Status_IN)(void);
|
||||
void (*Process_Status_OUT)(void);
|
||||
|
||||
RESULT (*Class_Data_Setup)(uint8_t RequestNo);
|
||||
|
||||
RESULT (*Class_NoData_Setup)(uint8_t RequestNo);
|
||||
|
||||
RESULT (*Class_Get_Interface_Setting)(uint8_t Interface, uint8_t AlternateSetting);
|
||||
|
||||
uint8_t* (*GetDeviceDescriptor)(uint16_t Length);
|
||||
uint8_t* (*GetConfigDescriptor)(uint16_t Length);
|
||||
uint8_t* (*GetStringDescriptor)(uint16_t Length);
|
||||
|
||||
void* RxEP_buffer;
|
||||
|
||||
uint8_t MaxPacketSize;
|
||||
|
||||
}DEVICE_PROP;
|
||||
|
||||
typedef struct _USER_STANDARD_REQUESTS
|
||||
{
|
||||
void (*User_GetConfiguration)(void); /* Get Configuration */
|
||||
void (*User_SetConfiguration)(void); /* Set Configuration */
|
||||
void (*User_GetInterface)(void); /* Get Interface */
|
||||
void (*User_SetInterface)(void); /* Set Interface */
|
||||
void (*User_GetStatus)(void); /* Get Status */
|
||||
void (*User_ClearFeature)(void); /* Clear Feature */
|
||||
void (*User_SetEndPointFeature)(void); /* Set Endpoint Feature */
|
||||
void (*User_SetDeviceFeature)(void); /* Set Device Feature */
|
||||
void (*User_SetDeviceAddress)(void); /* Set Device Address */
|
||||
}
|
||||
USER_STANDARD_REQUESTS;
|
||||
|
||||
|
||||
#define Type_Recipient (pInformation->USBbmRequestType & (REQUEST_TYPE | RECIPIENT))
|
||||
|
||||
#define Usb_rLength Usb_wLength
|
||||
#define Usb_rOffset Usb_wOffset
|
||||
|
||||
#define USBwValue USBwValues.w
|
||||
#define USBwValue0 USBwValues.bw.bb0
|
||||
#define USBwValue1 USBwValues.bw.bb1
|
||||
#define USBwIndex USBwIndexs.w
|
||||
#define USBwIndex0 USBwIndexs.bw.bb0
|
||||
#define USBwIndex1 USBwIndexs.bw.bb1
|
||||
#define USBwLength USBwLengths.w
|
||||
#define USBwLength0 USBwLengths.bw.bb0
|
||||
#define USBwLength1 USBwLengths.bw.bb1
|
||||
|
||||
|
||||
uint8_t Setup0_Process(void);
|
||||
uint8_t Post0_Process(void);
|
||||
uint8_t Out0_Process(void);
|
||||
uint8_t In0_Process(void);
|
||||
|
||||
RESULT Standard_SetEndPointFeature(void);
|
||||
RESULT Standard_SetDeviceFeature(void);
|
||||
|
||||
uint8_t *Standard_GetConfiguration(uint16_t Length);
|
||||
RESULT Standard_SetConfiguration(void);
|
||||
uint8_t *Standard_GetInterface(uint16_t Length);
|
||||
RESULT Standard_SetInterface(void);
|
||||
uint8_t *Standard_GetDescriptorData(uint16_t Length, PONE_DESCRIPTOR pDesc);
|
||||
|
||||
uint8_t *Standard_GetStatus(uint16_t Length);
|
||||
RESULT Standard_ClearFeature(void);
|
||||
void SetDeviceAddress(uint8_t);
|
||||
void NOP_Process(void);
|
||||
|
||||
extern DEVICE_PROP Device_Property;
|
||||
extern USER_STANDARD_REQUESTS User_Standard_Requests;
|
||||
extern DEVICE Device_Table;
|
||||
extern DEVICE_INFO Device_Info;
|
||||
|
||||
/* cells saving status during interrupt servicing */
|
||||
extern __IO uint16_t SaveRState;
|
||||
extern __IO uint16_t SaveTState;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USB_CORE_H */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : usb_def.h
|
||||
* Author : WCH
|
||||
* Version : V1.0.0
|
||||
* Date : 2021/08/08
|
||||
* Description : This file contains all the functions prototypes for the
|
||||
* USB definition firmware library.
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
* Attention: This software (modified or not) and binary are used for
|
||||
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
|
||||
*******************************************************************************/
|
||||
#ifndef __USB_DEF_H
|
||||
#define __USB_DEF_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "ch32v20x.h"
|
||||
|
||||
typedef enum _RECIPIENT_TYPE
|
||||
{
|
||||
DEVICE_RECIPIENT,
|
||||
INTERFACE_RECIPIENT,
|
||||
ENDPOINT_RECIPIENT,
|
||||
OTHER_RECIPIENT
|
||||
} RECIPIENT_TYPE;
|
||||
|
||||
typedef enum _STANDARD_REQUESTS
|
||||
{
|
||||
GET_STATUS = 0,
|
||||
CLEAR_FEATURE,
|
||||
RESERVED1,
|
||||
SET_FEATURE,
|
||||
RESERVED2,
|
||||
SET_ADDRESS,
|
||||
GET_DESCRIPTOR,
|
||||
SET_DESCRIPTOR,
|
||||
GET_CONFIGURATION,
|
||||
SET_CONFIGURATION,
|
||||
GET_INTERFACE,
|
||||
SET_INTERFACE,
|
||||
TOTAL_sREQUEST,
|
||||
SYNCH_FRAME = 12
|
||||
} STANDARD_REQUESTS;
|
||||
|
||||
/* Definition of "USBwValue" */
|
||||
typedef enum _DESCRIPTOR_TYPE
|
||||
{
|
||||
DEVICE_DESCRIPTOR = 1,
|
||||
CONFIG_DESCRIPTOR,
|
||||
STRING_DESCRIPTOR,
|
||||
INTERFACE_DESCRIPTOR,
|
||||
ENDPOINT_DESCRIPTOR
|
||||
} DESCRIPTOR_TYPE;
|
||||
|
||||
/* Feature selector of a SET_FEATURE or CLEAR_FEATURE */
|
||||
typedef enum _FEATURE_SELECTOR
|
||||
{
|
||||
ENDPOINT_STALL,
|
||||
DEVICE_REMOTE_WAKEUP
|
||||
} FEATURE_SELECTOR;
|
||||
|
||||
/* Definition of "USBbmRequestType" */
|
||||
#define REQUEST_TYPE 0x60
|
||||
#define STANDARD_REQUEST 0x00
|
||||
#define CLASS_REQUEST 0x20
|
||||
#define VENDOR_REQUEST 0x40
|
||||
#define RECIPIENT 0x1F
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USB_DEF_H */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : usb_init.h
|
||||
* Author : WCH
|
||||
* Version : V1.0.0
|
||||
* Date : 2021/08/08
|
||||
* Description : This file contains all the functions prototypes for the
|
||||
* USB Initialization firmware library.
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
* Attention: This software (modified or not) and binary are used for
|
||||
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
|
||||
*******************************************************************************/
|
||||
#ifndef __USB_INIT_H
|
||||
#define __USB_INIT_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "ch32v20x.h"
|
||||
|
||||
|
||||
void USB_Init(void);
|
||||
extern uint8_t EPindex;
|
||||
extern DEVICE_INFO* pInformation;
|
||||
extern DEVICE_PROP* pProperty;
|
||||
extern USER_STANDARD_REQUESTS *pUser_Standard_Requests;
|
||||
extern uint16_t SaveState ;
|
||||
extern uint16_t wInterrupt_Mask;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* __USB_INIT_H */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : usb_int.h
|
||||
* Author : WCH
|
||||
* Version : V1.0.0
|
||||
* Date : 2021/08/08
|
||||
* Description : This file contains all the functions prototypes for the
|
||||
* USB Endpoint firmware library.
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
* Attention: This software (modified or not) and binary are used for
|
||||
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
|
||||
*******************************************************************************/
|
||||
#ifndef __USB_INT_H
|
||||
#define __USB_INT_H
|
||||
|
||||
void CTR_LP(void);
|
||||
void CTR_HP(void);
|
||||
|
||||
#endif /* __USB_INT_H */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : usb_lib.h
|
||||
* Author : WCH
|
||||
* Version : V1.0.0
|
||||
* Date : 2021/08/08
|
||||
* Description : Library configuration file for USB.
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
* Attention: This software (modified or not) and binary are used for
|
||||
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
|
||||
*******************************************************************************/
|
||||
#ifndef __USB_LIB_H
|
||||
#define __USB_LIB_H
|
||||
|
||||
#include "hw_config.h"
|
||||
#include "usb_type.h"
|
||||
#include "usb_regs.h"
|
||||
#include "usb_def.h"
|
||||
#include "usb_core.h"
|
||||
#include "usb_init.h"
|
||||
#include "usb_sil.h"
|
||||
#include "usb_mem.h"
|
||||
#include "usb_int.h"
|
||||
//#include "ch32f20x_usb.h"
|
||||
|
||||
#endif /* __USB_LIB_H */
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : usb_mem.h
|
||||
* Author : WCH
|
||||
* Version : V1.0.0
|
||||
* Date : 2021/08/08
|
||||
* Description : This file contains all the functions prototypes for the
|
||||
* USB Initialization firmware library.
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
* Attention: This software (modified or not) and binary are used for
|
||||
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
|
||||
*******************************************************************************/
|
||||
#ifndef __USB_MEM_H
|
||||
#define __USB_MEM_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "ch32v20x.h"
|
||||
|
||||
void UserToPMABufferCopy(uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes);
|
||||
void PMAToUserBufferCopy(uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*__USB_MEM_H*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,675 @@
|
||||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : usb_regs.h
|
||||
* Author : WCH
|
||||
* Version : V1.0.1
|
||||
* Date : 2022/12/28
|
||||
* Description : This file contains all the functions prototypes for the
|
||||
* USB cell registers firmware library.
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
* Attention: This software (modified or not) and binary are used for
|
||||
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
|
||||
*******************************************************************************/
|
||||
#ifndef __USB_REGS_H
|
||||
#define __USB_REGS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "ch32v20x.h"
|
||||
|
||||
typedef enum _EP_DBUF_DIR
|
||||
{
|
||||
EP_DBUF_ERR,
|
||||
EP_DBUF_OUT,
|
||||
EP_DBUF_IN
|
||||
}EP_DBUF_DIR;
|
||||
|
||||
/* endpoint buffer number */
|
||||
enum EP_BUF_NUM
|
||||
{
|
||||
EP_NOBUF,
|
||||
EP_BUF0,
|
||||
EP_BUF1
|
||||
};
|
||||
|
||||
extern uint16_t Ep0RxBlks;
|
||||
|
||||
#define RegBase (0x40005C00L)
|
||||
#define PMAAddr (0x40006000L)
|
||||
|
||||
/******************************************************************************/
|
||||
/* General registers */
|
||||
/******************************************************************************/
|
||||
|
||||
/* Control register */
|
||||
#define CNTLR ((__IO unsigned *)(RegBase + 0x40))
|
||||
/* Interrupt status register */
|
||||
#define ISTR ((__IO unsigned *)(RegBase + 0x44))
|
||||
/* Frame number register */
|
||||
#define FNR ((__IO unsigned *)(RegBase + 0x48))
|
||||
/* Device address register */
|
||||
#define DADDR ((__IO unsigned *)(RegBase + 0x4C))
|
||||
/* Buffer Table address register */
|
||||
#define BTABLE ((__IO unsigned *)(RegBase + 0x50))
|
||||
/******************************************************************************/
|
||||
/* Endpoint registers */
|
||||
/******************************************************************************/
|
||||
#define EP0REG ((__IO unsigned *)(RegBase)) /* endpoint 0 register address */
|
||||
|
||||
/* Endpoint Addresses (w/direction) */
|
||||
#define EP0_OUT ((uint8_t)0x00)
|
||||
#define EP0_IN ((uint8_t)0x80)
|
||||
#define EP1_OUT ((uint8_t)0x01)
|
||||
#define EP1_IN ((uint8_t)0x81)
|
||||
#define EP2_OUT ((uint8_t)0x02)
|
||||
#define EP2_IN ((uint8_t)0x82)
|
||||
#define EP3_OUT ((uint8_t)0x03)
|
||||
#define EP3_IN ((uint8_t)0x83)
|
||||
#define EP4_OUT ((uint8_t)0x04)
|
||||
#define EP4_IN ((uint8_t)0x84)
|
||||
#define EP5_OUT ((uint8_t)0x05)
|
||||
#define EP5_IN ((uint8_t)0x85)
|
||||
#define EP6_OUT ((uint8_t)0x06)
|
||||
#define EP6_IN ((uint8_t)0x86)
|
||||
#define EP7_OUT ((uint8_t)0x07)
|
||||
#define EP7_IN ((uint8_t)0x87)
|
||||
|
||||
/* endpoints enumeration */
|
||||
#define ENDP0 ((uint8_t)0)
|
||||
#define ENDP1 ((uint8_t)1)
|
||||
#define ENDP2 ((uint8_t)2)
|
||||
#define ENDP3 ((uint8_t)3)
|
||||
#define ENDP4 ((uint8_t)4)
|
||||
#define ENDP5 ((uint8_t)5)
|
||||
#define ENDP6 ((uint8_t)6)
|
||||
#define ENDP7 ((uint8_t)7)
|
||||
|
||||
/******************************************************************************/
|
||||
/* ISTR interrupt events */
|
||||
/******************************************************************************/
|
||||
#define ISTR_CTR (0x8000) /* Correct TRansfer (clear-only bit) */
|
||||
#define ISTR_DOVR (0x4000) /* DMA OVeR/underrun (clear-only bit) */
|
||||
#define ISTR_ERR (0x2000) /* ERRor (clear-only bit) */
|
||||
#define ISTR_WKUP (0x1000) /* WaKe UP (clear-only bit) */
|
||||
#define ISTR_SUSP (0x0800) /* SUSPend (clear-only bit) */
|
||||
#define ISTR_RESET (0x0400) /* RESET (clear-only bit) */
|
||||
#define ISTR_SOF (0x0200) /* Start Of Frame (clear-only bit) */
|
||||
#define ISTR_ESOF (0x0100) /* Expected Start Of Frame (clear-only bit) */
|
||||
|
||||
|
||||
#define ISTR_DIR (0x0010) /* DIRection of transaction (read-only bit) */
|
||||
#define ISTR_EP_ID (0x000F) /* EndPoint IDentifier (read-only bit) */
|
||||
|
||||
#define CLR_CTR (~ISTR_CTR) /* clear Correct TRansfer bit */
|
||||
#define CLR_DOVR (~ISTR_DOVR) /* clear DMA OVeR/underrun bit*/
|
||||
#define CLR_ERR (~ISTR_ERR) /* clear ERRor bit */
|
||||
#define CLR_WKUP (~ISTR_WKUP) /* clear WaKe UP bit */
|
||||
#define CLR_SUSP (~ISTR_SUSP) /* clear SUSPend bit */
|
||||
#define CLR_RESET (~ISTR_RESET) /* clear RESET bit */
|
||||
#define CLR_SOF (~ISTR_SOF) /* clear Start Of Frame bit */
|
||||
#define CLR_ESOF (~ISTR_ESOF) /* clear Expected Start Of Frame bit */
|
||||
|
||||
/******************************************************************************/
|
||||
/* CNTR control register bits definitions */
|
||||
/******************************************************************************/
|
||||
#define CNTR_CTRM (0x8000) /* Correct TRansfer Mask */
|
||||
#define CNTR_DOVRM (0x4000) /* DMA OVeR/underrun Mask */
|
||||
#define CNTR_ERRM (0x2000) /* ERRor Mask */
|
||||
#define CNTR_WKUPM (0x1000) /* WaKe UP Mask */
|
||||
#define CNTR_SUSPM (0x0800) /* SUSPend Mask */
|
||||
#define CNTR_RESETM (0x0400) /* RESET Mask */
|
||||
#define CNTR_SOFM (0x0200) /* Start Of Frame Mask */
|
||||
#define CNTR_ESOFM (0x0100) /* Expected Start Of Frame Mask */
|
||||
|
||||
|
||||
#define CNTR_RESUME (0x0010) /* RESUME request */
|
||||
#define CNTR_FSUSP (0x0008) /* Force SUSPend */
|
||||
#define CNTR_LPMODE (0x0004) /* Low-power MODE */
|
||||
#define CNTR_PDWN (0x0002) /* Power DoWN */
|
||||
#define CNTR_FRES (0x0001) /* Force USB RESet */
|
||||
|
||||
/******************************************************************************/
|
||||
/* FNR Frame Number Register bit definitions */
|
||||
/******************************************************************************/
|
||||
#define FNR_RXDP (0x8000) /* status of D+ data line */
|
||||
#define FNR_RXDM (0x4000) /* status of D- data line */
|
||||
#define FNR_LCK (0x2000) /* LoCKed */
|
||||
#define FNR_LSOF (0x1800) /* Lost SOF */
|
||||
#define FNR_FN (0x07FF) /* Frame Number */
|
||||
/******************************************************************************/
|
||||
/* DADDR Device ADDRess bit definitions */
|
||||
/******************************************************************************/
|
||||
#define DADDR_EF (0x80)
|
||||
#define DADDR_ADD (0x7F)
|
||||
/******************************************************************************/
|
||||
/* Endpoint register */
|
||||
/******************************************************************************/
|
||||
/* bit positions */
|
||||
#define EP_CTR_RX (0x8000) /* EndPoint Correct TRansfer RX */
|
||||
#define EP_DTOG_RX (0x4000) /* EndPoint Data TOGGLE RX */
|
||||
#define EPRX_STAT (0x3000) /* EndPoint RX STATus bit field */
|
||||
#define EP_SETUP (0x0800) /* EndPoint SETUP */
|
||||
#define EP_T_FIELD (0x0600) /* EndPoint TYPE */
|
||||
#define EP_KIND (0x0100) /* EndPoint KIND */
|
||||
#define EP_CTR_TX (0x0080) /* EndPoint Correct TRansfer TX */
|
||||
#define EP_DTOG_TX (0x0040) /* EndPoint Data TOGGLE TX */
|
||||
#define EPTX_STAT (0x0030) /* EndPoint TX STATus bit field */
|
||||
#define EPADDR_FIELD (0x000F) /* EndPoint ADDRess FIELD */
|
||||
|
||||
/* EndPoint REGister MASK (no toggle fields) */
|
||||
#define EPREG_MASK (EP_CTR_RX|EP_SETUP|EP_T_FIELD|EP_KIND|EP_CTR_TX|EPADDR_FIELD)
|
||||
|
||||
/* EP_TYPE[1:0] EndPoint TYPE */
|
||||
#define EP_TYPE_MASK (0x0600) /* EndPoint TYPE Mask */
|
||||
#define EP_BULK (0x0000) /* EndPoint BULK */
|
||||
#define EP_CONTROL (0x0200) /* EndPoint CONTROL */
|
||||
#define EP_ISOCHRONOUS (0x0400) /* EndPoint ISOCHRONOUS */
|
||||
#define EP_INTERRUPT (0x0600) /* EndPoint INTERRUPT */
|
||||
#define EP_T_MASK (~EP_T_FIELD & EPREG_MASK)
|
||||
|
||||
|
||||
/* EP_KIND EndPoint KIND */
|
||||
#define EPKIND_MASK (~EP_KIND & EPREG_MASK)
|
||||
|
||||
/* STAT_TX[1:0] STATus for TX transfer */
|
||||
#define EP_TX_DIS (0x0000) /* EndPoint TX DISabled */
|
||||
#define EP_TX_STALL (0x0010) /* EndPoint TX STALLed */
|
||||
#define EP_TX_NAK (0x0020) /* EndPoint TX NAKed */
|
||||
#define EP_TX_VALID (0x0030) /* EndPoint TX VALID */
|
||||
#define EPTX_DTOG1 (0x0010) /* EndPoint TX Data TOGgle bit1 */
|
||||
#define EPTX_DTOG2 (0x0020) /* EndPoint TX Data TOGgle bit2 */
|
||||
#define EPTX_DTOGMASK (EPTX_STAT|EPREG_MASK)
|
||||
|
||||
/* STAT_RX[1:0] STATus for RX transfer */
|
||||
#define EP_RX_DIS (0x0000) /* EndPoint RX DISabled */
|
||||
#define EP_RX_STALL (0x1000) /* EndPoint RX STALLed */
|
||||
#define EP_RX_NAK (0x2000) /* EndPoint RX NAKed */
|
||||
#define EP_RX_VALID (0x3000) /* EndPoint RX VALID */
|
||||
#define EPRX_DTOG1 (0x1000) /* EndPoint RX Data TOGgle bit1 */
|
||||
#define EPRX_DTOG2 (0x2000) /* EndPoint RX Data TOGgle bit1 */
|
||||
#define EPRX_DTOGMASK (EPRX_STAT|EPREG_MASK)
|
||||
|
||||
/* SetCNTR */
|
||||
#define _SetCNTR(wRegValue) (*CNTLR = (uint16_t)wRegValue)
|
||||
|
||||
/* SetISTR */
|
||||
#define _SetISTR(wRegValue) (*ISTR = (uint16_t)wRegValue)
|
||||
|
||||
/* SetDADDR */
|
||||
#define _SetDADDR(wRegValue) (*DADDR = (uint16_t)wRegValue)
|
||||
|
||||
/* SetBTABLE */
|
||||
#define _SetBTABLE(wRegValue)(*BTABLE = (uint16_t)(wRegValue & 0xFFF8))
|
||||
|
||||
/* GetCNTR */
|
||||
#define _GetCNTR() ((uint16_t) *CNTLR)
|
||||
|
||||
/* GetISTR */
|
||||
#define _GetISTR() ((uint16_t) *ISTR)
|
||||
|
||||
/* GetFNR */
|
||||
#define _GetFNR() ((uint16_t) *FNR)
|
||||
|
||||
/* GetDADDR */
|
||||
#define _GetDADDR() ((uint16_t) *DADDR)
|
||||
|
||||
/* GetBTABLE */
|
||||
#define _GetBTABLE() ((uint16_t) *BTABLE)
|
||||
|
||||
/* SetENDPOINT */
|
||||
#define _SetENDPOINT(bEpNum,wRegValue) (*(EP0REG + bEpNum)= \
|
||||
(uint16_t)wRegValue)
|
||||
|
||||
/* GetENDPOINT */
|
||||
#define _GetENDPOINT(bEpNum) ((uint16_t)(*(EP0REG + bEpNum)))
|
||||
|
||||
#define _SetEPType(bEpNum,wType) (_SetENDPOINT(bEpNum,\
|
||||
((_GetENDPOINT(bEpNum) & EP_T_MASK) | wType )))
|
||||
|
||||
#define _GetEPType(bEpNum) (_GetENDPOINT(bEpNum) & EP_T_FIELD)
|
||||
|
||||
/*******************************************************************************
|
||||
* Macro Name : SetEPTxStatus
|
||||
* Description : sets the status for tx transfer (bits STAT_TX[1:0]).
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* wState: new state
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
#define _SetEPTxStatus(bEpNum,wState) {\
|
||||
register uint16_t _wRegVal; \
|
||||
_wRegVal = _GetENDPOINT(bEpNum) & EPTX_DTOGMASK;\
|
||||
/* toggle first bit ? */ \
|
||||
if((EPTX_DTOG1 & wState)!= 0) \
|
||||
_wRegVal ^= EPTX_DTOG1; \
|
||||
/* toggle second bit ? */ \
|
||||
if((EPTX_DTOG2 & wState)!= 0) \
|
||||
_wRegVal ^= EPTX_DTOG2; \
|
||||
_SetENDPOINT(bEpNum, (_wRegVal | EP_CTR_RX|EP_CTR_TX)); \
|
||||
while( ( _GetENDPOINT(bEpNum) & EPTX_STAT ) != wState ) \
|
||||
{ \
|
||||
_SetENDPOINT(bEpNum, (_wRegVal | EP_CTR_RX|EP_CTR_TX)); \
|
||||
}; \
|
||||
} /* _SetEPTxStatus */
|
||||
|
||||
/*******************************************************************************
|
||||
* Macro Name : SetEPRxStatus
|
||||
* Description : sets the status for rx transfer (bits STAT_TX[1:0])
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* wState: new state.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
#define _SetEPRxStatus(bEpNum,wState) {\
|
||||
register uint16_t _wRegVal; \
|
||||
\
|
||||
_wRegVal = _GetENDPOINT(bEpNum) & EPRX_DTOGMASK;\
|
||||
/* toggle first bit ? */ \
|
||||
if((EPRX_DTOG1 & wState)!= 0) \
|
||||
_wRegVal ^= EPRX_DTOG1; \
|
||||
/* toggle second bit ? */ \
|
||||
if((EPRX_DTOG2 & wState)!= 0) \
|
||||
_wRegVal ^= EPRX_DTOG2; \
|
||||
_SetENDPOINT(bEpNum, (_wRegVal | EP_CTR_RX|EP_CTR_TX)); \
|
||||
while( ( _GetENDPOINT(bEpNum) & EPRX_STAT ) != wState ) \
|
||||
{ \
|
||||
_SetENDPOINT(bEpNum, (_wRegVal | EP_CTR_RX|EP_CTR_TX)); \
|
||||
} \
|
||||
} /* _SetEPRxStatus */
|
||||
|
||||
/*******************************************************************************
|
||||
* Macro Name : SetEPRxTxStatus
|
||||
* Description : sets the status for rx & tx (bits STAT_TX[1:0] & STAT_RX[1:0])
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* wStaterx: new state.
|
||||
* wStatetx: new state.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
#define _SetEPRxTxStatus(bEpNum,wStaterx,wStatetx) {\
|
||||
register uint32_t _wRegVal_T, _wRegVal_R; \
|
||||
\
|
||||
_wRegVal_T = _GetENDPOINT(bEpNum) & EPTX_DTOGMASK; \
|
||||
_wRegVal_R = _GetENDPOINT(bEpNum) & EPRX_DTOGMASK; \
|
||||
/* toggle first bit ? */ \
|
||||
if((EPRX_DTOG1 & wStaterx)!= 0) \
|
||||
_wRegVal_R ^= EPRX_DTOG1; \
|
||||
/* toggle second bit ? */ \
|
||||
if((EPRX_DTOG2 & wStaterx)!= 0) \
|
||||
_wRegVal_R ^= EPRX_DTOG2; \
|
||||
/* toggle first bit ? */ \
|
||||
if((EPTX_DTOG1 & wStatetx)!= 0) \
|
||||
_wRegVal_T ^= EPTX_DTOG1; \
|
||||
/* toggle second bit ? */ \
|
||||
if((EPTX_DTOG2 & wStatetx)!= 0) \
|
||||
_wRegVal_T ^= EPTX_DTOG2; \
|
||||
_SetENDPOINT(bEpNum, _wRegVal_T |_wRegVal_R | EP_CTR_RX | EP_CTR_TX); \
|
||||
while( ( _GetENDPOINT(bEpNum) & EPTX_STAT ) != wStatetx ) \
|
||||
{ \
|
||||
_SetENDPOINT(bEpNum, _wRegVal_T | EP_CTR_RX | EP_CTR_TX); \
|
||||
} \
|
||||
while( ( _GetENDPOINT(bEpNum) & EPRX_STAT ) != wStaterx ) \
|
||||
{ \
|
||||
_SetENDPOINT(bEpNum, _wRegVal_R | EP_CTR_RX | EP_CTR_TX); \
|
||||
} \
|
||||
} /* _SetEPRxTxStatus */
|
||||
|
||||
/*******************************************************************************
|
||||
* Macro Name : GetEPTxStatus / GetEPRxStatus
|
||||
* Description : gets the status for tx/rx transfer (bits STAT_TX[1:0]
|
||||
* /STAT_RX[1:0])
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* Return : status .
|
||||
*******************************************************************************/
|
||||
#define _GetEPTxStatus(bEpNum) ((uint16_t)_GetENDPOINT(bEpNum) & EPTX_STAT)
|
||||
|
||||
#define _GetEPRxStatus(bEpNum) ((uint16_t)_GetENDPOINT(bEpNum) & EPRX_STAT)
|
||||
|
||||
/*******************************************************************************
|
||||
* Macro Name : SetEPTxValid / SetEPRxValid
|
||||
* Description : sets directly the VALID tx/rx-status into the enpoint register
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
#define _SetEPTxValid(bEpNum) (_SetEPTxStatus(bEpNum, EP_TX_VALID))
|
||||
|
||||
#define _SetEPRxValid(bEpNum) (_SetEPRxStatus(bEpNum, EP_RX_VALID))
|
||||
|
||||
/*******************************************************************************
|
||||
* Macro Name : GetTxStallStatus / GetRxStallStatus.
|
||||
* Description : checks stall condition in an endpoint.
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* Return : TRUE = endpoint in stall condition.
|
||||
*******************************************************************************/
|
||||
#define _GetTxStallStatus(bEpNum) (_GetEPTxStatus(bEpNum) \
|
||||
== EP_TX_STALL)
|
||||
#define _GetRxStallStatus(bEpNum) (_GetEPRxStatus(bEpNum) \
|
||||
== EP_RX_STALL)
|
||||
|
||||
/*******************************************************************************
|
||||
* Macro Name : SetEP_KIND / ClearEP_KIND.
|
||||
* Description : set & clear EP_KIND bit.
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
#define _SetEP_KIND(bEpNum) (_SetENDPOINT(bEpNum, \
|
||||
(EP_CTR_RX|EP_CTR_TX|((_GetENDPOINT(bEpNum) | EP_KIND) & EPREG_MASK))))
|
||||
#define _ClearEP_KIND(bEpNum) (_SetENDPOINT(bEpNum, \
|
||||
(EP_CTR_RX|EP_CTR_TX|(_GetENDPOINT(bEpNum) & EPKIND_MASK))))
|
||||
|
||||
/*******************************************************************************
|
||||
* Macro Name : Set_Status_Out / Clear_Status_Out.
|
||||
* Description : Sets/clears directly STATUS_OUT bit in the endpoint register.
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
#define _Set_Status_Out(bEpNum) _SetEP_KIND(bEpNum)
|
||||
#define _Clear_Status_Out(bEpNum) _ClearEP_KIND(bEpNum)
|
||||
|
||||
/*******************************************************************************
|
||||
* Macro Name : SetEPDoubleBuff / ClearEPDoubleBuff.
|
||||
* Description : Sets/clears directly EP_KIND bit in the endpoint register.
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
#define _SetEPDoubleBuff(bEpNum) _SetEP_KIND(bEpNum)
|
||||
#define _ClearEPDoubleBuff(bEpNum) _ClearEP_KIND(bEpNum)
|
||||
|
||||
/*******************************************************************************
|
||||
* Macro Name : ClearEP_CTR_RX / ClearEP_CTR_TX.
|
||||
* Description : Clears bit CTR_RX / CTR_TX in the endpoint register.
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
#define _ClearEP_CTR_RX(bEpNum) (_SetENDPOINT(bEpNum,\
|
||||
_GetENDPOINT(bEpNum) & 0x7FFF & EPREG_MASK))
|
||||
#define _ClearEP_CTR_TX(bEpNum) (_SetENDPOINT(bEpNum,\
|
||||
_GetENDPOINT(bEpNum) & 0xFF7F & EPREG_MASK))
|
||||
|
||||
/*******************************************************************************
|
||||
* Macro Name : ToggleDTOG_RX / ToggleDTOG_TX .
|
||||
* Description : Toggles DTOG_RX / DTOG_TX bit in the endpoint register.
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
#define _ToggleDTOG_RX(bEpNum) (_SetENDPOINT(bEpNum, \
|
||||
EP_CTR_RX|EP_CTR_TX|EP_DTOG_RX | (_GetENDPOINT(bEpNum) & EPREG_MASK)))
|
||||
#define _ToggleDTOG_TX(bEpNum) (_SetENDPOINT(bEpNum, \
|
||||
EP_CTR_RX|EP_CTR_TX|EP_DTOG_TX | (_GetENDPOINT(bEpNum) & EPREG_MASK)))
|
||||
|
||||
/*******************************************************************************
|
||||
* Macro Name : ClearDTOG_RX / ClearDTOG_TX.
|
||||
* Description : Clears DTOG_RX / DTOG_TX bit in the endpoint register.
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
#define _ClearDTOG_RX(bEpNum) if((_GetENDPOINT(bEpNum) & EP_DTOG_RX) != 0)\
|
||||
_ToggleDTOG_RX(bEpNum)
|
||||
#define _ClearDTOG_TX(bEpNum) if((_GetENDPOINT(bEpNum) & EP_DTOG_TX) != 0)\
|
||||
_ToggleDTOG_TX(bEpNum)
|
||||
/*******************************************************************************
|
||||
* Macro Name : SetEPAddress.
|
||||
* Description : Sets address in an endpoint register.
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* bAddr: Address.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
#define _SetEPAddress(bEpNum,bAddr) _SetENDPOINT(bEpNum,\
|
||||
EP_CTR_RX|EP_CTR_TX|(_GetENDPOINT(bEpNum) & EPREG_MASK) | bAddr)
|
||||
|
||||
/*******************************************************************************
|
||||
* Macro Name : GetEPAddress.
|
||||
* Description : Gets address in an endpoint register.
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
#define _GetEPAddress(bEpNum) ((uint8_t)(_GetENDPOINT(bEpNum) & EPADDR_FIELD))
|
||||
|
||||
#define _pEPTxAddr(bEpNum) ((uint32_t *)((_GetBTABLE()+bEpNum*8 )*2 + PMAAddr))
|
||||
#define _pEPTxCount(bEpNum) ((uint32_t *)((_GetBTABLE()+bEpNum*8+2)*2 + PMAAddr))
|
||||
#define _pEPRxAddr(bEpNum) ((uint32_t *)((_GetBTABLE()+bEpNum*8+4)*2 + PMAAddr))
|
||||
#define _pEPRxCount(bEpNum) ((uint32_t *)((_GetBTABLE()+bEpNum*8+6)*2 + PMAAddr))
|
||||
|
||||
/*******************************************************************************
|
||||
* Macro Name : SetEPTxAddr / SetEPRxAddr.
|
||||
* Description : sets address of the tx/rx buffer.
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* wAddr: address to be set (must be word aligned).
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
#define _SetEPTxAddr(bEpNum,wAddr) (*_pEPTxAddr(bEpNum) = ((wAddr >> 1) << 1))
|
||||
#define _SetEPRxAddr(bEpNum,wAddr) (*_pEPRxAddr(bEpNum) = ((wAddr >> 1) << 1))
|
||||
|
||||
/*******************************************************************************
|
||||
* Macro Name : GetEPTxAddr / GetEPRxAddr.
|
||||
* Description : Gets address of the tx/rx buffer.
|
||||
* Input : bEpNum: Endpoint Number.
|
||||
* Return : address of the buffer.
|
||||
*******************************************************************************/
|
||||
#define _GetEPTxAddr(bEpNum) ((uint16_t)*_pEPTxAddr(bEpNum))
|
||||
#define _GetEPRxAddr(bEpNum) ((uint16_t)*_pEPRxAddr(bEpNum))
|
||||
|
||||
/*******************************************************************************
|
||||
* Macro Name : SetEPCountRxReg.
|
||||
* Description : Sets counter of rx buffer with no. of blocks.
|
||||
* Input : pdwReg: pointer to counter.
|
||||
* wCount: Counter.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
#define _BlocksOf32(dwReg,wCount,wNBlocks) {\
|
||||
wNBlocks = wCount >> 5;\
|
||||
if((wCount & 0x1f) == 0)\
|
||||
wNBlocks--;\
|
||||
*pdwReg = (uint32_t)((wNBlocks << 10) | 0x8000);\
|
||||
}/* _BlocksOf32 */
|
||||
|
||||
#define _BlocksOf2(dwReg,wCount,wNBlocks) {\
|
||||
wNBlocks = wCount >> 1;\
|
||||
if((wCount & 0x1) != 0)\
|
||||
wNBlocks++;\
|
||||
*pdwReg = (uint32_t)(wNBlocks << 10);\
|
||||
}/* _BlocksOf2 */
|
||||
|
||||
#define _SetEPCountRxReg(dwReg,wCount) {\
|
||||
uint16_t wNBlocks;\
|
||||
if(wCount > 62){_BlocksOf32(dwReg,wCount,wNBlocks);}\
|
||||
else {_BlocksOf2(dwReg,wCount,wNBlocks);}\
|
||||
}/* _SetEPCountRxReg */
|
||||
|
||||
#define _GetNumBlock(wCount,wValue) {\
|
||||
uint16_t wNBlocks;\
|
||||
if(wCount > 62){\
|
||||
wNBlocks = wCount >> 5;\
|
||||
if((wCount & 0x1f) == 0) wNBlocks--;\
|
||||
wValue = (uint32_t)((wNBlocks << 10) | 0x8000);\
|
||||
}\
|
||||
else {wNBlocks = wCount >> 1;\
|
||||
if((wCount & 0x1) != 0) wNBlocks++;\
|
||||
wValue = (uint32_t)(wNBlocks << 10);\
|
||||
}\
|
||||
}
|
||||
|
||||
#define _SetEPRxDblBuf0Count(bEpNum,wCount) {\
|
||||
uint32_t *pdwReg = _pEPTxCount(bEpNum); \
|
||||
_SetEPCountRxReg(pdwReg, wCount);\
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Macro Name : SetEPTxCount / SetEPRxCount.
|
||||
* Description : sets counter for the tx/rx buffer.
|
||||
* Input : bEpNum: endpoint number.
|
||||
* wCount: Counter value.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
#define _SetEPTxCount(bEpNum,wCount) (*_pEPTxCount(bEpNum) = wCount)
|
||||
#define _SetEPRxCount(bEpNum,wCount) {\
|
||||
uint32_t *pdwReg = _pEPRxCount(bEpNum); \
|
||||
_SetEPCountRxReg(pdwReg, wCount);\
|
||||
if (bEpNum == ENDP0) \
|
||||
_GetNumBlock(Device_Property.MaxPacketSize,Ep0RxBlks);\
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Macro Name : GetEPTxCount / GetEPRxCount.
|
||||
* Description : gets counter of the tx buffer.
|
||||
* Input : bEpNum: endpoint number.
|
||||
* Return : Counter value.
|
||||
*******************************************************************************/
|
||||
#define _GetEPTxCount(bEpNum)((uint16_t)(*_pEPTxCount(bEpNum)) & 0x3ff)
|
||||
#define _GetEPRxCount(bEpNum)((uint16_t)(*_pEPRxCount(bEpNum)) & 0x3ff)
|
||||
|
||||
/*******************************************************************************
|
||||
* Macro Name : SetEPDblBuf0Addr / SetEPDblBuf1Addr.
|
||||
* Description : Sets buffer 0/1 address in a double buffer endpoint.
|
||||
* Input : bEpNum: endpoint number.
|
||||
* : wBuf0Addr: buffer 0 address.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
#define _SetEPDblBuf0Addr(bEpNum,wBuf0Addr) {_SetEPTxAddr(bEpNum, wBuf0Addr);}
|
||||
#define _SetEPDblBuf1Addr(bEpNum,wBuf1Addr) {_SetEPRxAddr(bEpNum, wBuf1Addr);}
|
||||
|
||||
/*******************************************************************************
|
||||
* Macro Name : SetEPDblBuffAddr.
|
||||
* Description : Sets addresses in a double buffer endpoint.
|
||||
* Input : bEpNum: endpoint number.
|
||||
* : wBuf0Addr: buffer 0 address.
|
||||
* : wBuf1Addr = buffer 1 address.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
#define _SetEPDblBuffAddr(bEpNum,wBuf0Addr,wBuf1Addr) { \
|
||||
_SetEPDblBuf0Addr(bEpNum, wBuf0Addr);\
|
||||
_SetEPDblBuf1Addr(bEpNum, wBuf1Addr);\
|
||||
} /* _SetEPDblBuffAddr */
|
||||
|
||||
/*******************************************************************************
|
||||
* Macro Name : GetEPDblBuf0Addr / GetEPDblBuf1Addr.
|
||||
* Description : Gets buffer 0/1 address of a double buffer endpoint.
|
||||
* Input : bEpNum: endpoint number.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
#define _GetEPDblBuf0Addr(bEpNum) (_GetEPTxAddr(bEpNum))
|
||||
#define _GetEPDblBuf1Addr(bEpNum) (_GetEPRxAddr(bEpNum))
|
||||
|
||||
/*******************************************************************************
|
||||
* Macro Name : SetEPDblBuffCount / SetEPDblBuf0Count / SetEPDblBuf1Count.
|
||||
* Description : Gets buffer 0/1 address of a double buffer endpoint.
|
||||
* Input : bEpNum: endpoint number.
|
||||
* : bDir: endpoint dir EP_DBUF_OUT = OUT
|
||||
* EP_DBUF_IN = IN
|
||||
* : wCount: Counter value
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
#define _SetEPDblBuf0Count(bEpNum, bDir, wCount) { \
|
||||
if(bDir == EP_DBUF_OUT)\
|
||||
/* OUT endpoint */ \
|
||||
{_SetEPRxDblBuf0Count(bEpNum,wCount);} \
|
||||
else if(bDir == EP_DBUF_IN)\
|
||||
/* IN endpoint */ \
|
||||
*_pEPTxCount(bEpNum) = (uint32_t)wCount; \
|
||||
} /* SetEPDblBuf0Count*/
|
||||
|
||||
#define _SetEPDblBuf1Count(bEpNum, bDir, wCount) { \
|
||||
if(bDir == EP_DBUF_OUT)\
|
||||
/* OUT endpoint */ \
|
||||
{_SetEPRxCount(bEpNum,wCount);}\
|
||||
else if(bDir == EP_DBUF_IN)\
|
||||
/* IN endpoint */\
|
||||
*_pEPRxCount(bEpNum) = (uint32_t)wCount; \
|
||||
} /* SetEPDblBuf1Count */
|
||||
|
||||
#define _SetEPDblBuffCount(bEpNum, bDir, wCount) {\
|
||||
_SetEPDblBuf0Count(bEpNum, bDir, wCount); \
|
||||
_SetEPDblBuf1Count(bEpNum, bDir, wCount); \
|
||||
} /* _SetEPDblBuffCount */
|
||||
|
||||
/*******************************************************************************
|
||||
* Macro Name : GetEPDblBuf0Count / GetEPDblBuf1Count.
|
||||
* Description : Gets buffer 0/1 rx/tx counter for double buffering.
|
||||
* Input : bEpNum: endpoint number.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
#define _GetEPDblBuf0Count(bEpNum) (_GetEPTxCount(bEpNum))
|
||||
#define _GetEPDblBuf1Count(bEpNum) (_GetEPRxCount(bEpNum))
|
||||
|
||||
|
||||
extern __IO uint16_t wIstr; /* ISTR register last read value */
|
||||
|
||||
|
||||
void SetCNTR(uint16_t /*wRegValue*/);
|
||||
void SetISTR(uint16_t /*wRegValue*/);
|
||||
void SetDADDR(uint16_t /*wRegValue*/);
|
||||
void SetBTABLE(uint16_t /*wRegValue*/);
|
||||
void SetBTABLE(uint16_t /*wRegValue*/);
|
||||
uint16_t GetCNTR(void);
|
||||
uint16_t GetISTR(void);
|
||||
uint16_t GetFNR(void);
|
||||
uint16_t GetDADDR(void);
|
||||
uint16_t GetBTABLE(void);
|
||||
void SetENDPOINT(uint8_t /*bEpNum*/, uint16_t /*wRegValue*/);
|
||||
uint16_t GetENDPOINT(uint8_t /*bEpNum*/);
|
||||
void SetEPType(uint8_t /*bEpNum*/, uint16_t /*wType*/);
|
||||
uint16_t GetEPType(uint8_t /*bEpNum*/);
|
||||
void SetEPTxStatus(uint8_t /*bEpNum*/, uint16_t /*wState*/);
|
||||
void SetEPRxStatus(uint8_t /*bEpNum*/, uint16_t /*wState*/);
|
||||
void SetDouBleBuffEPStall(uint8_t /*bEpNum*/, uint8_t bDir);
|
||||
uint16_t GetEPTxStatus(uint8_t /*bEpNum*/);
|
||||
uint16_t GetEPRxStatus(uint8_t /*bEpNum*/);
|
||||
void SetEPTxValid(uint8_t /*bEpNum*/);
|
||||
void SetEPRxValid(uint8_t /*bEpNum*/);
|
||||
uint16_t GetTxStallStatus(uint8_t /*bEpNum*/);
|
||||
uint16_t GetRxStallStatus(uint8_t /*bEpNum*/);
|
||||
void SetEP_KIND(uint8_t /*bEpNum*/);
|
||||
void ClearEP_KIND(uint8_t /*bEpNum*/);
|
||||
void Set_Status_Out(uint8_t /*bEpNum*/);
|
||||
void Clear_Status_Out(uint8_t /*bEpNum*/);
|
||||
void SetEPDoubleBuff(uint8_t /*bEpNum*/);
|
||||
void ClearEPDoubleBuff(uint8_t /*bEpNum*/);
|
||||
void ClearEP_CTR_RX(uint8_t /*bEpNum*/);
|
||||
void ClearEP_CTR_TX(uint8_t /*bEpNum*/);
|
||||
void ToggleDTOG_RX(uint8_t /*bEpNum*/);
|
||||
void ToggleDTOG_TX(uint8_t /*bEpNum*/);
|
||||
void ClearDTOG_RX(uint8_t /*bEpNum*/);
|
||||
void ClearDTOG_TX(uint8_t /*bEpNum*/);
|
||||
void SetEPAddress(uint8_t /*bEpNum*/, uint8_t /*bAddr*/);
|
||||
uint8_t GetEPAddress(uint8_t /*bEpNum*/);
|
||||
void SetEPTxAddr(uint8_t /*bEpNum*/, uint16_t /*wAddr*/);
|
||||
void SetEPRxAddr(uint8_t /*bEpNum*/, uint16_t /*wAddr*/);
|
||||
uint16_t GetEPTxAddr(uint8_t /*bEpNum*/);
|
||||
uint16_t GetEPRxAddr(uint8_t /*bEpNum*/);
|
||||
void SetEPCountRxReg(uint32_t * /*pdwReg*/, uint16_t /*wCount*/);
|
||||
void SetEPTxCount(uint8_t /*bEpNum*/, uint16_t /*wCount*/);
|
||||
void SetEPRxCount(uint8_t /*bEpNum*/, uint16_t /*wCount*/);
|
||||
uint16_t GetEPTxCount(uint8_t /*bEpNum*/);
|
||||
uint16_t GetEPRxCount(uint8_t /*bEpNum*/);
|
||||
void SetEPDblBuf0Addr(uint8_t /*bEpNum*/, uint16_t /*wBuf0Addr*/);
|
||||
void SetEPDblBuf1Addr(uint8_t /*bEpNum*/, uint16_t /*wBuf1Addr*/);
|
||||
void SetEPDblBuffAddr(uint8_t /*bEpNum*/, uint16_t /*wBuf0Addr*/, uint16_t /*wBuf1Addr*/);
|
||||
uint16_t GetEPDblBuf0Addr(uint8_t /*bEpNum*/);
|
||||
uint16_t GetEPDblBuf1Addr(uint8_t /*bEpNum*/);
|
||||
void SetEPDblBuffCount(uint8_t /*bEpNum*/, uint8_t /*bDir*/, uint16_t /*wCount*/);
|
||||
void SetEPDblBuf0Count(uint8_t /*bEpNum*/, uint8_t /*bDir*/, uint16_t /*wCount*/);
|
||||
void SetEPDblBuf1Count(uint8_t /*bEpNum*/, uint8_t /*bDir*/, uint16_t /*wCount*/);
|
||||
uint16_t GetEPDblBuf0Count(uint8_t /*bEpNum*/);
|
||||
uint16_t GetEPDblBuf1Count(uint8_t /*bEpNum*/);
|
||||
EP_DBUF_DIR GetEPDblBufDir(uint8_t /*bEpNum*/);
|
||||
void FreeUserBuffer(uint8_t bEpNum/*bEpNum*/, uint8_t bDir);
|
||||
uint16_t ToWord(uint8_t, uint8_t);
|
||||
uint16_t ByteSwap(uint16_t);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* __USB_REGS_H */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : usb_sil.h
|
||||
* Author : WCH
|
||||
* Version : V1.0.0
|
||||
* Date : 2021/08/08
|
||||
* Description : This file contains all the functions prototypes for the
|
||||
* USB Simplified Interface Layer firmware library.
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
* Attention: This software (modified or not) and binary are used for
|
||||
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
|
||||
*******************************************************************************/
|
||||
#ifndef __USB_SIL_H
|
||||
#define __USB_SIL_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "ch32v20x.h"
|
||||
|
||||
uint32_t USB_SIL_Init(void);
|
||||
uint32_t USB_SIL_Write(uint8_t bEpAddr, uint8_t* pBufferPointer, uint32_t wBufferSize);
|
||||
uint32_t USB_SIL_Read(uint8_t bEpAddr, uint8_t* pBufferPointer);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* __USB_SIL_H */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : usb_type.h
|
||||
* Author : WCH
|
||||
* Version : V1.0.0
|
||||
* Date : 2021/08/08
|
||||
* Description : This file contains all the functions prototypes for the
|
||||
* USB types firmware library.
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
* Attention: This software (modified or not) and binary are used for
|
||||
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
|
||||
*******************************************************************************/
|
||||
#ifndef __USB_TYPE_H
|
||||
#define __USB_TYPE_H
|
||||
#include "debug.h"
|
||||
#include "usb_conf.h"
|
||||
|
||||
#ifndef NULL
|
||||
#define NULL ((void *)0)
|
||||
#endif
|
||||
|
||||
typedef enum
|
||||
{
|
||||
FALSE = 0, TRUE = !FALSE
|
||||
}
|
||||
bool;
|
||||
|
||||
#endif /* __USB_TYPE_H */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,954 @@
|
||||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : usb_core.c
|
||||
* Author : WCH
|
||||
* Version : V1.0.0
|
||||
* Date : 2021/08/08
|
||||
* Description : Standard protocol processing (USB v2.0)
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
* Attention: This software (modified or not) and binary are used for
|
||||
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
|
||||
*******************************************************************************/
|
||||
#include "usb_lib.h"
|
||||
|
||||
/* Global define */
|
||||
#define ValBit(VAR,Place) (VAR & (1 << Place))
|
||||
#define SetBit(VAR,Place) (VAR |= (1 << Place))
|
||||
#define ClrBit(VAR,Place) (VAR &= ((1 << Place) ^ 255))
|
||||
#define Send0LengthData() { _SetEPTxCount(ENDP0, 0); \
|
||||
vSetEPTxStatus(EP_TX_VALID); \
|
||||
}
|
||||
|
||||
#define vSetEPRxStatus(st) (SaveRState = st)
|
||||
#define vSetEPTxStatus(st) (SaveTState = st)
|
||||
|
||||
#define USB_StatusIn() Send0LengthData()
|
||||
#define USB_StatusOut() vSetEPRxStatus(EP_RX_VALID)
|
||||
|
||||
#define StatusInfo0 StatusInfo.bw.bb1
|
||||
#define StatusInfo1 StatusInfo.bw.bb0
|
||||
|
||||
uint16_t_uint8_t StatusInfo;
|
||||
|
||||
bool Data_Mul_MaxPacketSize = FALSE;
|
||||
|
||||
static void DataStageOut(void);
|
||||
static void DataStageIn(void);
|
||||
static void NoData_Setup0(void);
|
||||
static void Data_Setup0(void);
|
||||
|
||||
/*********************************************************************
|
||||
* @fn Standard_GetConfiguration
|
||||
*
|
||||
* @brief Return the current configuration variable address.
|
||||
*
|
||||
* @param Length - How many bytes are needed.
|
||||
*
|
||||
* @return Return 1 - if the request is invalid when "Length" is 0.
|
||||
* Return "Buffer" if the "Length" is not 0.
|
||||
*/
|
||||
uint8_t *Standard_GetConfiguration(uint16_t Length)
|
||||
{
|
||||
if (Length == 0)
|
||||
{
|
||||
pInformation->Ctrl_Info.Usb_wLength = sizeof(pInformation->Current_Configuration);
|
||||
return 0;
|
||||
}
|
||||
pUser_Standard_Requests->User_GetConfiguration();
|
||||
|
||||
return (uint8_t *)&pInformation->Current_Configuration;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn Standard_SetConfiguration
|
||||
*
|
||||
* @brief This routine is called to set the configuration value
|
||||
* Then each class should configure device itself.
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @return Return USB_SUCCESS - if the request is performed.
|
||||
* Return USB_UNSUPPORT - if the request is invalid.
|
||||
*/
|
||||
RESULT Standard_SetConfiguration(void)
|
||||
{
|
||||
if ((pInformation->USBwValue0 <=
|
||||
Device_Table.Total_Configuration) && (pInformation->USBwValue1 == 0)
|
||||
&& (pInformation->USBwIndex == 0))
|
||||
{
|
||||
pInformation->Current_Configuration = pInformation->USBwValue0;
|
||||
pUser_Standard_Requests->User_SetConfiguration();
|
||||
return USB_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
return USB_UNSUPPORT;
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn Standard_GetInterface
|
||||
*
|
||||
* @brief Return the Alternate Setting of the current interface.
|
||||
*
|
||||
* @param Length - How many bytes are needed.
|
||||
*
|
||||
* @return Return 0 - if the request is invalid when "Length" is 0.
|
||||
* Return "Buffer" if the "Length" is not 0.
|
||||
*/
|
||||
uint8_t *Standard_GetInterface(uint16_t Length)
|
||||
{
|
||||
if (Length == 0)
|
||||
{
|
||||
pInformation->Ctrl_Info.Usb_wLength = sizeof(pInformation->Current_AlternateSetting);
|
||||
return 0;
|
||||
}
|
||||
pUser_Standard_Requests->User_GetInterface();
|
||||
|
||||
return (uint8_t *)&pInformation->Current_AlternateSetting;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn Standard_SetInterface
|
||||
*
|
||||
* @brief This routine is called to set the interface.
|
||||
* Then each class should configure the interface them self.
|
||||
*
|
||||
* @param None
|
||||
*
|
||||
* @return Return USB_SUCCESS - if the request is performed.
|
||||
* Return USB_UNSUPPORT - if the request is invalid.
|
||||
*/
|
||||
RESULT Standard_SetInterface(void)
|
||||
{
|
||||
RESULT Re;
|
||||
Re = (*pProperty->Class_Get_Interface_Setting)(pInformation->USBwIndex0, pInformation->USBwValue0);
|
||||
|
||||
if (pInformation->Current_Configuration != 0)
|
||||
{
|
||||
if ((Re != USB_SUCCESS) || (pInformation->USBwIndex1 != 0)
|
||||
|| (pInformation->USBwValue1 != 0))
|
||||
{
|
||||
return USB_UNSUPPORT;
|
||||
}
|
||||
else if (Re == USB_SUCCESS)
|
||||
{
|
||||
pUser_Standard_Requests->User_SetInterface();
|
||||
pInformation->Current_Interface = pInformation->USBwIndex0;
|
||||
pInformation->Current_AlternateSetting = pInformation->USBwValue0;
|
||||
return USB_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
return USB_UNSUPPORT;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn Standard_GetStatus
|
||||
*
|
||||
* @brief Copy the device request data to "StatusInfo buffer".
|
||||
*
|
||||
* @param Length - How many bytes are needed.
|
||||
*
|
||||
* @return Return 0 - if the request is at end of data block,
|
||||
* or is invalid when "Length" is 0.
|
||||
*/
|
||||
uint8_t *Standard_GetStatus(uint16_t Length)
|
||||
{
|
||||
if (Length == 0)
|
||||
{
|
||||
pInformation->Ctrl_Info.Usb_wLength = 2;
|
||||
return 0;
|
||||
}
|
||||
StatusInfo.w = 0;
|
||||
|
||||
if (Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT))
|
||||
{
|
||||
uint8_t Feature = pInformation->Current_Feature;
|
||||
|
||||
if (ValBit(Feature, 5))
|
||||
{
|
||||
SetBit(StatusInfo0, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
ClrBit(StatusInfo0, 1);
|
||||
}
|
||||
if (ValBit(Feature, 6))
|
||||
{
|
||||
SetBit(StatusInfo0, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
ClrBit(StatusInfo0, 0);
|
||||
}
|
||||
}
|
||||
else if (Type_Recipient == (STANDARD_REQUEST | INTERFACE_RECIPIENT))
|
||||
{
|
||||
return (uint8_t *)&StatusInfo;
|
||||
}
|
||||
else if (Type_Recipient == (STANDARD_REQUEST | ENDPOINT_RECIPIENT))
|
||||
{
|
||||
uint8_t Related_Endpoint;
|
||||
uint8_t wIndex0 = pInformation->USBwIndex0;
|
||||
|
||||
Related_Endpoint = (wIndex0 & 0x0f);
|
||||
if (ValBit(wIndex0, 7))
|
||||
{
|
||||
if (_GetTxStallStatus(Related_Endpoint))
|
||||
{
|
||||
SetBit(StatusInfo0, 0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_GetRxStallStatus(Related_Endpoint))
|
||||
{
|
||||
SetBit(StatusInfo0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
pUser_Standard_Requests->User_GetStatus();
|
||||
|
||||
return (uint8_t *)&StatusInfo;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn Standard_ClearFeature
|
||||
*
|
||||
* @brief Clear or disable a specific feature.
|
||||
*
|
||||
* @return Return USB_SUCCESS - if the request is performed.
|
||||
* Return USB_UNSUPPORT - if the request is invalid.
|
||||
*/
|
||||
RESULT Standard_ClearFeature(void)
|
||||
{
|
||||
uint32_t Type_Rec = Type_Recipient;
|
||||
uint32_t Status;
|
||||
|
||||
if (Type_Rec == (STANDARD_REQUEST | DEVICE_RECIPIENT))
|
||||
{
|
||||
ClrBit(pInformation->Current_Feature, 5);
|
||||
return USB_SUCCESS;
|
||||
}
|
||||
else if (Type_Rec == (STANDARD_REQUEST | ENDPOINT_RECIPIENT))
|
||||
{
|
||||
DEVICE* pDev;
|
||||
uint32_t Related_Endpoint;
|
||||
uint32_t wIndex0;
|
||||
uint32_t rEP;
|
||||
|
||||
if ((pInformation->USBwValue != ENDPOINT_STALL)
|
||||
|| (pInformation->USBwIndex1 != 0))
|
||||
{
|
||||
return USB_UNSUPPORT;
|
||||
}
|
||||
|
||||
pDev = &Device_Table;
|
||||
wIndex0 = pInformation->USBwIndex0;
|
||||
rEP = wIndex0 & ~0x80;
|
||||
Related_Endpoint = ENDP0 + rEP;
|
||||
|
||||
if (ValBit(pInformation->USBwIndex0, 7))
|
||||
{
|
||||
Status = _GetEPTxStatus(Related_Endpoint);
|
||||
}
|
||||
else
|
||||
{
|
||||
Status = _GetEPRxStatus(Related_Endpoint);
|
||||
}
|
||||
|
||||
if ((rEP >= pDev->Total_Endpoint) || (Status == 0)
|
||||
|| (pInformation->Current_Configuration == 0))
|
||||
{
|
||||
return USB_UNSUPPORT;
|
||||
}
|
||||
|
||||
if (wIndex0 & 0x80)
|
||||
{
|
||||
if (_GetTxStallStatus(Related_Endpoint ))
|
||||
{
|
||||
ClearDTOG_TX(Related_Endpoint);
|
||||
SetEPTxStatus(Related_Endpoint, EP_TX_VALID);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_GetRxStallStatus(Related_Endpoint))
|
||||
{
|
||||
if (Related_Endpoint == ENDP0)
|
||||
{
|
||||
SetEPRxCount(Related_Endpoint, Device_Property.MaxPacketSize);
|
||||
_SetEPRxStatus(Related_Endpoint, EP_RX_VALID);
|
||||
}
|
||||
else
|
||||
{
|
||||
ClearDTOG_RX(Related_Endpoint);
|
||||
_SetEPRxStatus(Related_Endpoint, EP_RX_VALID);
|
||||
}
|
||||
}
|
||||
}
|
||||
pUser_Standard_Requests->User_ClearFeature();
|
||||
return USB_SUCCESS;
|
||||
}
|
||||
|
||||
return USB_UNSUPPORT;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn Standard_SetEndPointFeature
|
||||
*
|
||||
* @brief Set or enable a specific feature of EndPoint
|
||||
*
|
||||
* @return Return USB_SUCCESS - if the request is performed.
|
||||
* Return USB_UNSUPPORT - if the request is invalid.
|
||||
*/
|
||||
RESULT Standard_SetEndPointFeature(void)
|
||||
{
|
||||
uint32_t wIndex0;
|
||||
uint32_t Related_Endpoint;
|
||||
uint32_t rEP;
|
||||
uint32_t Status;
|
||||
|
||||
wIndex0 = pInformation->USBwIndex0;
|
||||
rEP = wIndex0 & ~0x80;
|
||||
Related_Endpoint = ENDP0 + rEP;
|
||||
|
||||
if (ValBit(pInformation->USBwIndex0, 7))
|
||||
{
|
||||
Status = _GetEPTxStatus(Related_Endpoint);
|
||||
}
|
||||
else
|
||||
{
|
||||
Status = _GetEPRxStatus(Related_Endpoint);
|
||||
}
|
||||
|
||||
if (Related_Endpoint >= Device_Table.Total_Endpoint
|
||||
|| pInformation->USBwValue != 0 || Status == 0
|
||||
|| pInformation->Current_Configuration == 0)
|
||||
{
|
||||
return USB_UNSUPPORT;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (wIndex0 & 0x80)
|
||||
{
|
||||
_SetEPTxStatus(Related_Endpoint, EP_TX_STALL);
|
||||
}
|
||||
else
|
||||
{
|
||||
_SetEPRxStatus(Related_Endpoint, EP_RX_STALL);
|
||||
}
|
||||
}
|
||||
pUser_Standard_Requests->User_SetEndPointFeature();
|
||||
|
||||
return USB_SUCCESS;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn Standard_SetDeviceFeature
|
||||
*
|
||||
* @brief Set or enable a specific feature of Device.
|
||||
*
|
||||
* @return Return USB_SUCCESS - if the request is performed.
|
||||
* Return USB_UNSUPPORT - if the request is invalid.
|
||||
*/
|
||||
RESULT Standard_SetDeviceFeature(void)
|
||||
{
|
||||
SetBit(pInformation->Current_Feature, 5);
|
||||
pUser_Standard_Requests->User_SetDeviceFeature();
|
||||
|
||||
return USB_SUCCESS;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn Standard_GetDescriptorData
|
||||
*
|
||||
* @brief This routine is used for the descriptors resident in Flash
|
||||
* or RAM pDesc can be in either Flash or RAM
|
||||
* The purpose of this routine is to have a versatile way to
|
||||
* response descriptors request. It allows user to generate
|
||||
* certain descriptors with software or read descriptors from
|
||||
* external storage part by part.
|
||||
*
|
||||
* @param Length - Length of the data in this transfer.
|
||||
* pDesc - A pointer points to descriptor struct.
|
||||
* The structure gives the initial address of the descriptor and
|
||||
* its original size.
|
||||
*
|
||||
* @return Address of a part of the descriptor pointed by the Usb_
|
||||
* wOffset The buffer pointed by this address contains at least
|
||||
* Length bytes.
|
||||
*/
|
||||
uint8_t *Standard_GetDescriptorData(uint16_t Length, ONE_DESCRIPTOR *pDesc)
|
||||
{
|
||||
uint32_t wOffset;
|
||||
|
||||
wOffset = pInformation->Ctrl_Info.Usb_wOffset;
|
||||
|
||||
if (Length == 0)
|
||||
{
|
||||
pInformation->Ctrl_Info.Usb_wLength = pDesc->Descriptor_Size - wOffset;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return pDesc->Descriptor + wOffset;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn DataStageOut
|
||||
*
|
||||
* @brief Data stage of a Control Write Transfer.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void DataStageOut(void)
|
||||
{
|
||||
ENDPOINT_INFO *pEPinfo = &pInformation->Ctrl_Info;
|
||||
uint32_t save_rLength;
|
||||
|
||||
save_rLength = pEPinfo->Usb_rLength;
|
||||
|
||||
if (pEPinfo->CopyData && save_rLength)
|
||||
{
|
||||
uint8_t *Buffer;
|
||||
uint32_t Length;
|
||||
|
||||
Length = pEPinfo->PacketSize;
|
||||
|
||||
if (Length > save_rLength)
|
||||
{
|
||||
Length = save_rLength;
|
||||
}
|
||||
|
||||
Buffer = (*pEPinfo->CopyData)(Length);
|
||||
pEPinfo->Usb_rLength -= Length;
|
||||
pEPinfo->Usb_rOffset += Length;
|
||||
PMAToUserBufferCopy(Buffer, GetEPRxAddr(ENDP0), Length);
|
||||
}
|
||||
|
||||
if (pEPinfo->Usb_rLength != 0)
|
||||
{
|
||||
vSetEPRxStatus(EP_RX_VALID);
|
||||
SetEPTxCount(ENDP0, 0);
|
||||
vSetEPTxStatus(EP_TX_VALID);
|
||||
}
|
||||
|
||||
if (pEPinfo->Usb_rLength >= pEPinfo->PacketSize)
|
||||
{
|
||||
pInformation->ControlState = OUT_DATA;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (pEPinfo->Usb_rLength > 0)
|
||||
{
|
||||
pInformation->ControlState = LAST_OUT_DATA;
|
||||
}
|
||||
else if (pEPinfo->Usb_rLength == 0)
|
||||
{
|
||||
pInformation->ControlState = WAIT_STATUS_IN;
|
||||
USB_StatusIn();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn DataStageIn
|
||||
*
|
||||
* @brief Data stage of a Control Read Transfer.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void DataStageIn(void)
|
||||
{
|
||||
ENDPOINT_INFO *pEPinfo = &pInformation->Ctrl_Info;
|
||||
uint32_t save_wLength = pEPinfo->Usb_wLength;
|
||||
uint32_t ControlState = pInformation->ControlState;
|
||||
|
||||
uint8_t *DataBuffer;
|
||||
uint32_t Length;
|
||||
|
||||
if ((save_wLength == 0) && (ControlState == LAST_IN_DATA))
|
||||
{
|
||||
if(Data_Mul_MaxPacketSize == TRUE)
|
||||
{
|
||||
Send0LengthData();
|
||||
ControlState = LAST_IN_DATA;
|
||||
Data_Mul_MaxPacketSize = FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
ControlState = WAIT_STATUS_OUT;
|
||||
vSetEPTxStatus(EP_TX_STALL);
|
||||
|
||||
}
|
||||
|
||||
goto Expect_Status_Out;
|
||||
}
|
||||
|
||||
Length = pEPinfo->PacketSize;
|
||||
ControlState = (save_wLength <= Length) ? LAST_IN_DATA : IN_DATA;
|
||||
|
||||
if (Length > save_wLength)
|
||||
{
|
||||
Length = save_wLength;
|
||||
}
|
||||
|
||||
DataBuffer = (*pEPinfo->CopyData)(Length);
|
||||
|
||||
UserToPMABufferCopy(DataBuffer, GetEPTxAddr(ENDP0), Length);
|
||||
|
||||
SetEPTxCount(ENDP0, Length);
|
||||
|
||||
pEPinfo->Usb_wLength -= Length;
|
||||
pEPinfo->Usb_wOffset += Length;
|
||||
vSetEPTxStatus(EP_TX_VALID);
|
||||
|
||||
USB_StatusOut();
|
||||
|
||||
Expect_Status_Out:
|
||||
pInformation->ControlState = ControlState;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn NoData_Setup0
|
||||
*
|
||||
* @brief Proceed the processing of setup request without data stage.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void NoData_Setup0(void)
|
||||
{
|
||||
RESULT Result = USB_UNSUPPORT;
|
||||
uint32_t RequestNo = pInformation->USBbRequest;
|
||||
uint32_t ControlState;
|
||||
|
||||
if (Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT))
|
||||
{
|
||||
if (RequestNo == SET_CONFIGURATION)
|
||||
{
|
||||
Result = Standard_SetConfiguration();
|
||||
}
|
||||
else if (RequestNo == SET_ADDRESS)
|
||||
{
|
||||
if ((pInformation->USBwValue0 > 127) || (pInformation->USBwValue1 != 0)
|
||||
|| (pInformation->USBwIndex != 0)
|
||||
|| (pInformation->Current_Configuration != 0))
|
||||
{
|
||||
ControlState = STALLED;
|
||||
goto exit_NoData_Setup0;
|
||||
}
|
||||
else
|
||||
{
|
||||
Result = USB_SUCCESS;
|
||||
}
|
||||
}
|
||||
else if (RequestNo == SET_FEATURE)
|
||||
{
|
||||
if ((pInformation->USBwValue0 == DEVICE_REMOTE_WAKEUP) \
|
||||
&& (pInformation->USBwIndex == 0))
|
||||
{
|
||||
Result = Standard_SetDeviceFeature();
|
||||
}
|
||||
else
|
||||
{
|
||||
Result = USB_UNSUPPORT;
|
||||
}
|
||||
}
|
||||
else if (RequestNo == CLEAR_FEATURE)
|
||||
{
|
||||
if (pInformation->USBwValue0 == DEVICE_REMOTE_WAKEUP
|
||||
&& pInformation->USBwIndex == 0
|
||||
&& ValBit(pInformation->Current_Feature, 5))
|
||||
{
|
||||
Result = Standard_ClearFeature();
|
||||
}
|
||||
else
|
||||
{
|
||||
Result = USB_UNSUPPORT;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else if (Type_Recipient == (STANDARD_REQUEST | INTERFACE_RECIPIENT))
|
||||
{
|
||||
if (RequestNo == SET_INTERFACE)
|
||||
{
|
||||
Result = Standard_SetInterface();
|
||||
}
|
||||
}
|
||||
|
||||
else if (Type_Recipient == (STANDARD_REQUEST | ENDPOINT_RECIPIENT))
|
||||
{
|
||||
if (RequestNo == CLEAR_FEATURE)
|
||||
{
|
||||
Result = Standard_ClearFeature();
|
||||
}
|
||||
else if (RequestNo == SET_FEATURE)
|
||||
{
|
||||
Result = Standard_SetEndPointFeature();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Result = USB_UNSUPPORT;
|
||||
}
|
||||
|
||||
if (Result != USB_SUCCESS)
|
||||
{
|
||||
Result = (*pProperty->Class_NoData_Setup)(RequestNo);
|
||||
if (Result == USB_NOT_READY)
|
||||
{
|
||||
ControlState = PAUSE;
|
||||
goto exit_NoData_Setup0;
|
||||
}
|
||||
}
|
||||
|
||||
if (Result != USB_SUCCESS)
|
||||
{
|
||||
ControlState = STALLED;
|
||||
goto exit_NoData_Setup0;
|
||||
}
|
||||
|
||||
ControlState = WAIT_STATUS_IN;
|
||||
|
||||
USB_StatusIn();
|
||||
|
||||
exit_NoData_Setup0:
|
||||
pInformation->ControlState = ControlState;
|
||||
return;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn Data_Setup0
|
||||
*
|
||||
* @brief Proceed the processing of setup request with data stage.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void Data_Setup0(void)
|
||||
{
|
||||
uint8_t *(*CopyRoutine)(uint16_t);
|
||||
RESULT Result;
|
||||
uint32_t Request_No = pInformation->USBbRequest;
|
||||
uint32_t Related_Endpoint, Reserved;
|
||||
uint32_t wOffset, Status;
|
||||
|
||||
CopyRoutine = NULL;
|
||||
wOffset = 0;
|
||||
|
||||
if (Request_No == GET_DESCRIPTOR)
|
||||
{
|
||||
if (Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT))
|
||||
{
|
||||
uint8_t wValue1 = pInformation->USBwValue1;
|
||||
if (wValue1 == DEVICE_DESCRIPTOR)
|
||||
{
|
||||
CopyRoutine = pProperty->GetDeviceDescriptor;
|
||||
}
|
||||
else if (wValue1 == CONFIG_DESCRIPTOR)
|
||||
{
|
||||
CopyRoutine = pProperty->GetConfigDescriptor;
|
||||
}
|
||||
else if (wValue1 == STRING_DESCRIPTOR)
|
||||
{
|
||||
CopyRoutine = pProperty->GetStringDescriptor;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ((Request_No == GET_STATUS) && (pInformation->USBwValue == 0)
|
||||
&& (pInformation->USBwLength == 0x0002)
|
||||
&& (pInformation->USBwIndex1 == 0))
|
||||
{
|
||||
|
||||
if ((Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT))
|
||||
&& (pInformation->USBwIndex == 0))
|
||||
{
|
||||
CopyRoutine = Standard_GetStatus;
|
||||
}
|
||||
else if (Type_Recipient == (STANDARD_REQUEST | INTERFACE_RECIPIENT))
|
||||
{
|
||||
if (((*pProperty->Class_Get_Interface_Setting)(pInformation->USBwIndex0, 0) == USB_SUCCESS)
|
||||
&& (pInformation->Current_Configuration != 0))
|
||||
{
|
||||
CopyRoutine = Standard_GetStatus;
|
||||
}
|
||||
}
|
||||
else if (Type_Recipient == (STANDARD_REQUEST | ENDPOINT_RECIPIENT))
|
||||
{
|
||||
Related_Endpoint = (pInformation->USBwIndex0 & 0x0f);
|
||||
Reserved = pInformation->USBwIndex0 & 0x70;
|
||||
|
||||
if (ValBit(pInformation->USBwIndex0, 7))
|
||||
{
|
||||
Status = _GetEPTxStatus(Related_Endpoint);
|
||||
}
|
||||
else
|
||||
{
|
||||
Status = _GetEPRxStatus(Related_Endpoint);
|
||||
}
|
||||
|
||||
if ((Related_Endpoint < Device_Table.Total_Endpoint) && (Reserved == 0)
|
||||
&& (Status != 0))
|
||||
{
|
||||
CopyRoutine = Standard_GetStatus;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else if (Request_No == GET_CONFIGURATION)
|
||||
{
|
||||
if (Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT))
|
||||
{
|
||||
CopyRoutine = Standard_GetConfiguration;
|
||||
}
|
||||
}
|
||||
else if (Request_No == GET_INTERFACE)
|
||||
{
|
||||
if ((Type_Recipient == (STANDARD_REQUEST | INTERFACE_RECIPIENT))
|
||||
&& (pInformation->Current_Configuration != 0) && (pInformation->USBwValue == 0)
|
||||
&& (pInformation->USBwIndex1 == 0) && (pInformation->USBwLength == 0x0001)
|
||||
&& ((*pProperty->Class_Get_Interface_Setting)(pInformation->USBwIndex0, 0) == USB_SUCCESS))
|
||||
{
|
||||
CopyRoutine = Standard_GetInterface;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (CopyRoutine)
|
||||
{
|
||||
pInformation->Ctrl_Info.Usb_wOffset = wOffset;
|
||||
pInformation->Ctrl_Info.CopyData = CopyRoutine;
|
||||
(*CopyRoutine)(0);
|
||||
Result = USB_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
Result = (*pProperty->Class_Data_Setup)(pInformation->USBbRequest);
|
||||
|
||||
if (Result == USB_NOT_READY)
|
||||
{
|
||||
pInformation->ControlState = PAUSE;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (pInformation->Ctrl_Info.Usb_wLength == 0xFFFF)
|
||||
{
|
||||
pInformation->ControlState = PAUSE;
|
||||
return;
|
||||
}
|
||||
|
||||
if ((Result == USB_UNSUPPORT) || (pInformation->Ctrl_Info.Usb_wLength == 0))
|
||||
{
|
||||
pInformation->ControlState = STALLED;
|
||||
return;
|
||||
}
|
||||
|
||||
if (ValBit(pInformation->USBbmRequestType, 7))
|
||||
{
|
||||
__IO uint32_t wLength = pInformation->USBwLength;
|
||||
if (pInformation->Ctrl_Info.Usb_wLength > wLength)
|
||||
{
|
||||
pInformation->Ctrl_Info.Usb_wLength = wLength;
|
||||
}
|
||||
else if (pInformation->Ctrl_Info.Usb_wLength < pInformation->USBwLength)
|
||||
{
|
||||
if (pInformation->Ctrl_Info.Usb_wLength < pProperty->MaxPacketSize)
|
||||
{
|
||||
Data_Mul_MaxPacketSize = FALSE;
|
||||
}
|
||||
else if ((pInformation->Ctrl_Info.Usb_wLength % pProperty->MaxPacketSize) == 0)
|
||||
{
|
||||
Data_Mul_MaxPacketSize = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
pInformation->Ctrl_Info.PacketSize = pProperty->MaxPacketSize;
|
||||
DataStageIn();
|
||||
}
|
||||
else
|
||||
{
|
||||
pInformation->ControlState = OUT_DATA;
|
||||
vSetEPRxStatus(EP_RX_VALID);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn Setup0_Process
|
||||
*
|
||||
* @brief Get the device request data and dispatch to individual process.
|
||||
*
|
||||
* @return Post0_Process.
|
||||
*/
|
||||
uint8_t Setup0_Process(void)
|
||||
{
|
||||
union
|
||||
{
|
||||
uint8_t* b;
|
||||
uint16_t* w;
|
||||
} pBuf;
|
||||
uint16_t offset = 1;
|
||||
|
||||
pBuf.b = PMAAddr + (uint8_t *)(_GetEPRxAddr(ENDP0) * 2); /* *2 for 32 bits addr */
|
||||
|
||||
if (pInformation->ControlState != PAUSE)
|
||||
{
|
||||
pInformation->USBbmRequestType = *pBuf.b++; /* bmRequestType */
|
||||
pInformation->USBbRequest = *pBuf.b++; /* bRequest */
|
||||
pBuf.w += offset; /* word not accessed because of 32 bits addressing */
|
||||
pInformation->USBwValue = ByteSwap(*pBuf.w++); /* wValue */
|
||||
pBuf.w += offset; /* word not accessed because of 32 bits addressing */
|
||||
pInformation->USBwIndex = ByteSwap(*pBuf.w++); /* wIndex */
|
||||
pBuf.w += offset; /* word not accessed because of 32 bits addressing */
|
||||
pInformation->USBwLength = *pBuf.w; /* wLength */
|
||||
}
|
||||
pInformation->ControlState = SETTING_UP;
|
||||
|
||||
if (pInformation->USBwLength == 0)
|
||||
{
|
||||
NoData_Setup0();
|
||||
}
|
||||
else
|
||||
{
|
||||
Data_Setup0();
|
||||
}
|
||||
return Post0_Process();
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn In0_Process
|
||||
*
|
||||
* @brief Process the IN token on all default endpoint.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
uint8_t In0_Process(void)
|
||||
{
|
||||
uint32_t ControlState = pInformation->ControlState;
|
||||
|
||||
if ((ControlState == IN_DATA) || (ControlState == LAST_IN_DATA))
|
||||
{
|
||||
DataStageIn();
|
||||
ControlState = pInformation->ControlState;
|
||||
}
|
||||
else if (ControlState == WAIT_STATUS_IN)
|
||||
{
|
||||
if ((pInformation->USBbRequest == SET_ADDRESS) &&
|
||||
(Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT)))
|
||||
{
|
||||
SetDeviceAddress(pInformation->USBwValue0);
|
||||
pUser_Standard_Requests->User_SetDeviceAddress();
|
||||
}
|
||||
(*pProperty->Process_Status_IN)();
|
||||
ControlState = STALLED;
|
||||
}
|
||||
else
|
||||
{
|
||||
ControlState = STALLED;
|
||||
}
|
||||
|
||||
pInformation->ControlState = ControlState;
|
||||
|
||||
return Post0_Process();
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn Out0_Process
|
||||
*
|
||||
* @brief Process the OUT token on all default endpoint.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
uint8_t Out0_Process(void)
|
||||
{
|
||||
uint32_t ControlState = pInformation->ControlState;
|
||||
|
||||
if ((ControlState == IN_DATA) || (ControlState == LAST_IN_DATA))
|
||||
{
|
||||
ControlState = STALLED;
|
||||
}
|
||||
else if ((ControlState == OUT_DATA) || (ControlState == LAST_OUT_DATA))
|
||||
{
|
||||
DataStageOut();
|
||||
ControlState = pInformation->ControlState;
|
||||
}
|
||||
else if (ControlState == WAIT_STATUS_OUT)
|
||||
{
|
||||
(*pProperty->Process_Status_OUT)();
|
||||
ControlState = STALLED;
|
||||
}
|
||||
else
|
||||
{
|
||||
ControlState = STALLED;
|
||||
}
|
||||
|
||||
pInformation->ControlState = ControlState;
|
||||
|
||||
return Post0_Process();
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn Post0_Process
|
||||
*
|
||||
* @brief Stall the Endpoint 0 in case of error.
|
||||
*
|
||||
* @return 0 - if the control State is in PAUSE
|
||||
* 1 - if not.
|
||||
*/
|
||||
uint8_t Post0_Process(void)
|
||||
{
|
||||
SetEPRxCount(ENDP0, Device_Property.MaxPacketSize);
|
||||
|
||||
if (pInformation->ControlState == STALLED)
|
||||
{
|
||||
vSetEPRxStatus(EP_RX_STALL);
|
||||
vSetEPTxStatus(EP_TX_STALL);
|
||||
}
|
||||
|
||||
return (pInformation->ControlState == PAUSE);
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn SetDeviceAddress
|
||||
*
|
||||
* @brief Set the device and all the used Endpoints addresses.
|
||||
*
|
||||
* @param Val - device address.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void SetDeviceAddress(uint8_t Val)
|
||||
{
|
||||
uint32_t i;
|
||||
uint32_t nEP = Device_Table.Total_Endpoint;
|
||||
|
||||
for (i = 0; i < nEP; i++)
|
||||
{
|
||||
_SetEPAddress((uint8_t)i, (uint8_t)i);
|
||||
}
|
||||
|
||||
_SetDADDR(Val | DADDR_EF);
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn NOP_Process
|
||||
*
|
||||
* @brief No operation function.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void NOP_Process(void)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : usb_init.c
|
||||
* Author : WCH
|
||||
* Version : V1.0.0
|
||||
* Date : 2021/08/08
|
||||
* Description : Initialization routines & global variables
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
* Attention: This software (modified or not) and binary are used for
|
||||
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
|
||||
*******************************************************************************/
|
||||
#include "usb_lib.h"
|
||||
|
||||
uint8_t EPindex;
|
||||
DEVICE_INFO *pInformation;
|
||||
DEVICE_PROP *pProperty;
|
||||
uint16_t SaveState ;
|
||||
uint16_t wInterrupt_Mask;
|
||||
DEVICE_INFO Device_Info;
|
||||
USER_STANDARD_REQUESTS *pUser_Standard_Requests;
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn USB_Init
|
||||
*
|
||||
* @brief USB system initialization
|
||||
*
|
||||
* @return None.
|
||||
*
|
||||
*/
|
||||
void USB_Init(void)
|
||||
{
|
||||
pInformation = &Device_Info;
|
||||
pInformation->ControlState = 2;
|
||||
pProperty = &Device_Property;
|
||||
pUser_Standard_Requests = &User_Standard_Requests;
|
||||
pProperty->Init();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,133 @@
|
||||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : usb_int.c
|
||||
* Author : WCH
|
||||
* Version : V1.0.0
|
||||
* Date : 2021/08/08
|
||||
* Description : Endpoint CTR (Low and High) interrupt's service routines
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
* Attention: This software (modified or not) and binary are used for
|
||||
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
|
||||
*******************************************************************************/
|
||||
#include "usb_lib.h"
|
||||
|
||||
/* Private variables */
|
||||
__IO uint16_t SaveRState;
|
||||
__IO uint16_t SaveTState;
|
||||
|
||||
/* Extern variables */
|
||||
extern void (*pEpInt_IN[7])(void); /* Handles IN interrupts */
|
||||
extern void (*pEpInt_OUT[7])(void); /* Handles OUT interrupts */
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn CTR_LP.
|
||||
*
|
||||
* @brief Low priority Endpoint Correct Transfer interrupt's service
|
||||
* routine.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void CTR_LP(void)
|
||||
{
|
||||
__IO uint16_t wEPVal = 0;
|
||||
|
||||
while (((wIstr = _GetISTR()) & ISTR_CTR) != 0)
|
||||
{
|
||||
EPindex = (uint8_t)(wIstr & ISTR_EP_ID);
|
||||
|
||||
if (EPindex == 0)
|
||||
{
|
||||
SaveRState = _GetENDPOINT(ENDP0);
|
||||
SaveTState = SaveRState & EPTX_STAT;
|
||||
SaveRState &= EPRX_STAT;
|
||||
|
||||
_SetEPRxTxStatus(ENDP0,EP_RX_NAK,EP_TX_NAK);
|
||||
|
||||
if ((wIstr & ISTR_DIR) == 0)
|
||||
{
|
||||
_ClearEP_CTR_TX(ENDP0);
|
||||
In0_Process();
|
||||
|
||||
_SetEPRxTxStatus(ENDP0,SaveRState,SaveTState);
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
wEPVal = _GetENDPOINT(ENDP0);
|
||||
|
||||
if ((wEPVal &EP_SETUP) != 0)
|
||||
{
|
||||
_ClearEP_CTR_RX(ENDP0);
|
||||
Setup0_Process();
|
||||
_SetEPRxTxStatus(ENDP0,SaveRState,SaveTState);
|
||||
|
||||
return;
|
||||
}
|
||||
else if ((wEPVal & EP_CTR_RX) != 0)
|
||||
{
|
||||
_ClearEP_CTR_RX(ENDP0);
|
||||
Out0_Process();
|
||||
_SetEPRxTxStatus(ENDP0,SaveRState,SaveTState);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
wEPVal = _GetENDPOINT(EPindex);
|
||||
if ((wEPVal & EP_CTR_RX) != 0)
|
||||
{
|
||||
_ClearEP_CTR_RX(EPindex);
|
||||
(*pEpInt_OUT[EPindex-1])();
|
||||
}
|
||||
|
||||
if ((wEPVal & EP_CTR_TX) != 0)
|
||||
{
|
||||
_ClearEP_CTR_TX(EPindex);
|
||||
(*pEpInt_IN[EPindex-1])();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn CTR_HP.
|
||||
*
|
||||
* @brief High Priority Endpoint Correct Transfer interrupt's service
|
||||
* routine.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void CTR_HP(void)
|
||||
{
|
||||
uint32_t wEPVal = 0;
|
||||
|
||||
while (((wIstr = _GetISTR()) & ISTR_CTR) != 0)
|
||||
{
|
||||
_SetISTR((uint16_t)CLR_CTR);
|
||||
EPindex = (uint8_t)(wIstr & ISTR_EP_ID);
|
||||
wEPVal = _GetENDPOINT(EPindex);
|
||||
|
||||
if ((wEPVal & EP_CTR_RX) != 0)
|
||||
{
|
||||
_ClearEP_CTR_RX(EPindex);
|
||||
(*pEpInt_OUT[EPindex-1])();
|
||||
}
|
||||
else if ((wEPVal & EP_CTR_TX) != 0)
|
||||
{
|
||||
_ClearEP_CTR_TX(EPindex);
|
||||
(*pEpInt_IN[EPindex-1])();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : usb_mem.c
|
||||
* Author : WCH
|
||||
* Version : V1.0.0
|
||||
* Date : 2021/08/08
|
||||
* Description : Utility functions for memory transfers to/from PMA
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
* Attention: This software (modified or not) and binary are used for
|
||||
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
|
||||
*******************************************************************************/
|
||||
#include "usb_lib.h"
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn UserToPMABufferCopy
|
||||
*
|
||||
* @brief Copy a buffer from user memory area to packet memory area (PMA)
|
||||
*
|
||||
* @param pbUsrBuf: pointer to user memory area.
|
||||
* wPMABufAddr: address into PMA.
|
||||
* wNBytes: no. of bytes to be copied.
|
||||
*
|
||||
* @param None .
|
||||
*/
|
||||
void UserToPMABufferCopy(uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes)
|
||||
{
|
||||
uint32_t n = (wNBytes + 1) >> 1;
|
||||
uint32_t i, temp1, temp2;
|
||||
uint16_t *pdwVal;
|
||||
pdwVal = (uint16_t *)(wPMABufAddr * 2 + PMAAddr);
|
||||
|
||||
for (i = n; i != 0; i--)
|
||||
{
|
||||
temp1 = (uint16_t) * pbUsrBuf;
|
||||
pbUsrBuf++;
|
||||
temp2 = temp1 | (uint16_t) * pbUsrBuf << 8;
|
||||
*pdwVal++ = temp2;
|
||||
pdwVal++;
|
||||
pbUsrBuf++;
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn PMAToUserBufferCopy
|
||||
*
|
||||
* @brief Copy a buffer from user memory area to packet memory area (PMA)
|
||||
*
|
||||
* @param pbUsrBuf: pointer to user memory area.
|
||||
* wPMABufAddr: address into PMA.
|
||||
* wNBytes: no. of bytes to be copied.
|
||||
*
|
||||
* @param None.
|
||||
*/
|
||||
void PMAToUserBufferCopy(uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes)
|
||||
{
|
||||
uint32_t n = (wNBytes + 1) >> 1;
|
||||
uint32_t i;
|
||||
uint32_t *pdwVal;
|
||||
|
||||
pdwVal = (uint32_t *)(wPMABufAddr * 2 + PMAAddr);
|
||||
|
||||
for (i = n; i != 0; i--)
|
||||
{
|
||||
*(uint16_t*)pbUsrBuf++ = *pdwVal++;
|
||||
pbUsrBuf++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,852 @@
|
||||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : usb_regs.c
|
||||
* Author : WCH
|
||||
* Version : V1.0.0
|
||||
* Date : 2021/08/08
|
||||
* Description : Interface functions to USB cell registers
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
* Attention: This software (modified or not) and binary are used for
|
||||
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
|
||||
*******************************************************************************/
|
||||
#include "usb_lib.h"
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn SetCNTR.
|
||||
*
|
||||
* @brief Set the CNTR register value.
|
||||
*
|
||||
* @param wRegValue: new register value.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void SetCNTR(uint16_t wRegValue)
|
||||
{
|
||||
_SetCNTR(wRegValue);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn GetCNTR.
|
||||
*
|
||||
* @brief returns the CNTR register value.
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @return CNTR register Value.
|
||||
*/
|
||||
uint16_t GetCNTR(void)
|
||||
{
|
||||
return(_GetCNTR());
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn SetISTR.
|
||||
*
|
||||
* @brief Set the ISTR register value.
|
||||
*
|
||||
* @param wRegValue: new register value.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void SetISTR(uint16_t wRegValue)
|
||||
{
|
||||
_SetISTR(wRegValue);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn GetISTR
|
||||
*
|
||||
* @brief Returns the ISTR register value.
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @return ISTR register Value
|
||||
*/
|
||||
uint16_t GetISTR(void)
|
||||
{
|
||||
return(_GetISTR());
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn GetFNR
|
||||
*
|
||||
* @brief Returns the FNR register value.
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @return FNR register Value
|
||||
*/
|
||||
uint16_t GetFNR(void)
|
||||
{
|
||||
return(_GetFNR());
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn SetDADDR
|
||||
*
|
||||
* @brief Set the DADDR register value.
|
||||
*
|
||||
* @param wRegValue: new register value.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void SetDADDR(uint16_t wRegValue)
|
||||
{
|
||||
_SetDADDR(wRegValue);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn GetDADDR
|
||||
*
|
||||
* @brief Returns the DADDR register value.
|
||||
*
|
||||
* @return DADDR register Value
|
||||
*
|
||||
*/
|
||||
uint16_t GetDADDR(void)
|
||||
{
|
||||
return(_GetDADDR());
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn SetBTABLE
|
||||
*
|
||||
* @brief Set the BTABLE.
|
||||
*
|
||||
* @param wRegValue: New register value.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void SetBTABLE(uint16_t wRegValue)
|
||||
{
|
||||
_SetBTABLE(wRegValue);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn GetBTABLE.
|
||||
*
|
||||
* @param Returns the BTABLE register value.
|
||||
*
|
||||
* @return BTABLE address.
|
||||
*/
|
||||
uint16_t GetBTABLE(void)
|
||||
{
|
||||
return(_GetBTABLE());
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn SetENDPOINT
|
||||
*
|
||||
* @brief Set the Endpoint register value.
|
||||
*
|
||||
* @param bEpNum: Endpoint Number.
|
||||
* wRegValue.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void SetENDPOINT(uint8_t bEpNum, uint16_t wRegValue)
|
||||
{
|
||||
_SetENDPOINT(bEpNum, wRegValue);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn GetENDPOINT
|
||||
*
|
||||
* @brief Return the Endpoint register value.
|
||||
*
|
||||
* @param bEpNum: Endpoint Number.
|
||||
*
|
||||
* @return Endpoint register value.
|
||||
*/
|
||||
uint16_t GetENDPOINT(uint8_t bEpNum)
|
||||
{
|
||||
return(_GetENDPOINT(bEpNum));
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn SetEPType
|
||||
*
|
||||
* @brief sets the type in the endpoint register.
|
||||
*
|
||||
* @param bEpNum: Endpoint Number.
|
||||
* wType: type definition.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void SetEPType(uint8_t bEpNum, uint16_t wType)
|
||||
{
|
||||
_SetEPType(bEpNum, wType);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn GetEPType
|
||||
*
|
||||
* @brief Returns the endpoint type.
|
||||
*
|
||||
* @param bEpNum: Endpoint Number.
|
||||
*
|
||||
* @return Endpoint Type
|
||||
*/
|
||||
uint16_t GetEPType(uint8_t bEpNum)
|
||||
{
|
||||
return(_GetEPType(bEpNum));
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn SetEPTxStatus
|
||||
*
|
||||
* @brief Set the status of Tx endpoint.
|
||||
*
|
||||
* @param bEpNum: Endpoint Number.
|
||||
* wState: new state.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void SetEPTxStatus(uint8_t bEpNum, uint16_t wState)
|
||||
{
|
||||
_SetEPTxStatus(bEpNum, wState);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn SetEPRxStatus
|
||||
*
|
||||
* @brief Set the status of Rx endpoint.
|
||||
*
|
||||
* @param bEpNum: Endpoint Number.
|
||||
* wState: new state.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void SetEPRxStatus(uint8_t bEpNum, uint16_t wState)
|
||||
{
|
||||
_SetEPRxStatus(bEpNum, wState);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn SetDouBleBuffEPStall
|
||||
*
|
||||
* @brief sets the status for Double Buffer Endpoint to STALL
|
||||
*
|
||||
* @param bEpNum: Endpoint Number.
|
||||
* bDir: Endpoint direction.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void SetDouBleBuffEPStall(uint8_t bEpNum, uint8_t bDir)
|
||||
{
|
||||
uint16_t Endpoint_DTOG_Status;
|
||||
|
||||
Endpoint_DTOG_Status = GetENDPOINT(bEpNum);
|
||||
|
||||
if (bDir == EP_DBUF_OUT)
|
||||
{
|
||||
_SetENDPOINT(bEpNum, Endpoint_DTOG_Status & ~EPRX_DTOG1);
|
||||
}
|
||||
else if (bDir == EP_DBUF_IN)
|
||||
{
|
||||
_SetENDPOINT(bEpNum, Endpoint_DTOG_Status & ~EPTX_DTOG1);
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn GetEPTxStatus
|
||||
*
|
||||
* @brief Returns the endpoint Tx status.
|
||||
*
|
||||
* @param bEpNum: Endpoint Number.
|
||||
*
|
||||
* @return Endpoint TX Status
|
||||
*/
|
||||
uint16_t GetEPTxStatus(uint8_t bEpNum)
|
||||
{
|
||||
return(_GetEPTxStatus(bEpNum));
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn GetEPRxStatus
|
||||
*
|
||||
* @brief Returns the endpoint Rx status.
|
||||
*
|
||||
* @param bEpNum: Endpoint Number.
|
||||
*
|
||||
* @return Endpoint RX Status
|
||||
*/
|
||||
uint16_t GetEPRxStatus(uint8_t bEpNum)
|
||||
{
|
||||
return(_GetEPRxStatus(bEpNum));
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn SetEPTxValid
|
||||
*
|
||||
* @brief Valid the endpoint Tx Status.
|
||||
*
|
||||
* @param bEpNum: Endpoint Number.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void SetEPTxValid(uint8_t bEpNum)
|
||||
{
|
||||
_SetEPTxStatus(bEpNum, EP_TX_VALID);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn SetEPRxValid
|
||||
*
|
||||
* @brief Valid the endpoint Rx Status.
|
||||
*
|
||||
* @param bEpNum: Endpoint Number.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void SetEPRxValid(uint8_t bEpNum)
|
||||
{
|
||||
_SetEPRxStatus(bEpNum, EP_RX_VALID);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn SetEP_KIND
|
||||
*
|
||||
* @brief Clear the EP_KIND bit.
|
||||
*
|
||||
* @param bEpNum: Endpoint Number.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void SetEP_KIND(uint8_t bEpNum)
|
||||
{
|
||||
_SetEP_KIND(bEpNum);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn ClearEP_KIND
|
||||
*
|
||||
* @brief set the EP_KIND bit.
|
||||
*
|
||||
* @param bEpNum: Endpoint Number.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void ClearEP_KIND(uint8_t bEpNum)
|
||||
{
|
||||
_ClearEP_KIND(bEpNum);
|
||||
}
|
||||
/*******************************************************************************
|
||||
* @fn Clear_Status_Out
|
||||
*
|
||||
* @brief Clear the Status Out of the related Endpoint
|
||||
*
|
||||
* @param bEpNum: Endpoint Number.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void Clear_Status_Out(uint8_t bEpNum)
|
||||
{
|
||||
_ClearEP_KIND(bEpNum);
|
||||
}
|
||||
/*******************************************************************************
|
||||
* @fn Set_Status_Out
|
||||
*
|
||||
* @brief Set the Status Out of the related Endpoint
|
||||
*
|
||||
* @param bEpNum: Endpoint Number.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void Set_Status_Out(uint8_t bEpNum)
|
||||
{
|
||||
_SetEP_KIND(bEpNum);
|
||||
}
|
||||
/*******************************************************************************
|
||||
* @fn SetEPDoubleBuff
|
||||
*
|
||||
* @brief Enable the double buffer feature for the endpoint.
|
||||
*
|
||||
* @param bEpNum: Endpoint Number.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void SetEPDoubleBuff(uint8_t bEpNum)
|
||||
{
|
||||
_SetEP_KIND(bEpNum);
|
||||
}
|
||||
/*******************************************************************************
|
||||
* @fn ClearEPDoubleBuff
|
||||
*
|
||||
* @brief Disable the double buffer feature for the endpoint.
|
||||
*
|
||||
* @param bEpNum: Endpoint Number.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void ClearEPDoubleBuff(uint8_t bEpNum)
|
||||
{
|
||||
_ClearEP_KIND(bEpNum);
|
||||
}
|
||||
/*******************************************************************************
|
||||
* @fn GetTxStallStatus
|
||||
*
|
||||
* @brief Returns the Stall status of the Tx endpoint.
|
||||
*
|
||||
* @param bEpNum: Endpoint Number.
|
||||
*
|
||||
* @return Tx Stall status.
|
||||
*/
|
||||
uint16_t GetTxStallStatus(uint8_t bEpNum)
|
||||
{
|
||||
return(_GetTxStallStatus(bEpNum));
|
||||
}
|
||||
/*******************************************************************************
|
||||
* @fn GetRxStallStatus
|
||||
*
|
||||
* @brief Returns the Stall status of the Rx endpoint.
|
||||
*
|
||||
* @param bEpNum: Endpoint Number.
|
||||
*
|
||||
* @return Rx Stall status.
|
||||
*/
|
||||
uint16_t GetRxStallStatus(uint8_t bEpNum)
|
||||
{
|
||||
return(_GetRxStallStatus(bEpNum));
|
||||
}
|
||||
/*******************************************************************************
|
||||
* @fn ClearEP_CTR_RX
|
||||
*
|
||||
* @brief Clear the CTR_RX bit.
|
||||
*
|
||||
* @param bEpNum: Endpoint Number.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void ClearEP_CTR_RX(uint8_t bEpNum)
|
||||
{
|
||||
_ClearEP_CTR_RX(bEpNum);
|
||||
}
|
||||
/*******************************************************************************
|
||||
* @fn ClearEP_CTR_TX
|
||||
*
|
||||
* @brief Clear the CTR_TX bit.
|
||||
*
|
||||
* @param bEpNum: Endpoint Number.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void ClearEP_CTR_TX(uint8_t bEpNum)
|
||||
{
|
||||
_ClearEP_CTR_TX(bEpNum);
|
||||
}
|
||||
/*******************************************************************************
|
||||
* @fn ToggleDTOG_RX
|
||||
*
|
||||
* @brief Toggle the DTOG_RX bit.
|
||||
*
|
||||
* @param bEpNum: Endpoint Number.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void ToggleDTOG_RX(uint8_t bEpNum)
|
||||
{
|
||||
_ToggleDTOG_RX(bEpNum);
|
||||
}
|
||||
/*******************************************************************************
|
||||
* @fn ToggleDTOG_TX
|
||||
*
|
||||
* @brief Toggle the DTOG_TX bit.
|
||||
*
|
||||
* @param bEpNum: Endpoint Number.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void ToggleDTOG_TX(uint8_t bEpNum)
|
||||
{
|
||||
_ToggleDTOG_TX(bEpNum);
|
||||
}
|
||||
/*******************************************************************************
|
||||
* @fn ClearDTOG_RX.
|
||||
*
|
||||
* @brief Clear the DTOG_RX bit.
|
||||
*
|
||||
* @param bEpNum: Endpoint Number.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void ClearDTOG_RX(uint8_t bEpNum)
|
||||
{
|
||||
_ClearDTOG_RX(bEpNum);
|
||||
}
|
||||
/*******************************************************************************
|
||||
* @fn ClearDTOG_TX.
|
||||
*
|
||||
* @brief Clear the DTOG_TX bit.
|
||||
*
|
||||
* @param bEpNum: Endpoint Number.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void ClearDTOG_TX(uint8_t bEpNum)
|
||||
{
|
||||
_ClearDTOG_TX(bEpNum);
|
||||
}
|
||||
/*******************************************************************************
|
||||
* @fn SetEPAddress
|
||||
*
|
||||
* @brief Set the endpoint address.
|
||||
*
|
||||
* @param bEpNum: Endpoint Number.
|
||||
* bAddr: New endpoint address.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void SetEPAddress(uint8_t bEpNum, uint8_t bAddr)
|
||||
{
|
||||
_SetEPAddress(bEpNum, bAddr);
|
||||
}
|
||||
/*******************************************************************************
|
||||
* @fn GetEPAddress
|
||||
*
|
||||
* @brief Get the endpoint address.
|
||||
*
|
||||
* @param bEpNum: Endpoint Number.
|
||||
*
|
||||
* @return Endpoint address.
|
||||
*/
|
||||
uint8_t GetEPAddress(uint8_t bEpNum)
|
||||
{
|
||||
return(_GetEPAddress(bEpNum));
|
||||
}
|
||||
/*******************************************************************************
|
||||
* @fn SetEPTxAddr
|
||||
*
|
||||
* @brief Set the endpoint Tx buffer address.
|
||||
*
|
||||
* @param bEpNum: Endpoint Number.
|
||||
* wAddr: new address.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void SetEPTxAddr(uint8_t bEpNum, uint16_t wAddr)
|
||||
{
|
||||
_SetEPTxAddr(bEpNum, wAddr);
|
||||
}
|
||||
/*******************************************************************************
|
||||
* @fn SetEPRxAddr
|
||||
*
|
||||
* @brief Set the endpoint Rx buffer address.
|
||||
*
|
||||
* @param bEpNum: Endpoint Number.
|
||||
* wAddr: new address.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void SetEPRxAddr(uint8_t bEpNum, uint16_t wAddr)
|
||||
{
|
||||
_SetEPRxAddr(bEpNum, wAddr);
|
||||
}
|
||||
/*******************************************************************************
|
||||
* @fn GetEPTxAddr
|
||||
*
|
||||
* @brief Returns the endpoint Tx buffer address.
|
||||
*
|
||||
* @param bEpNum: Endpoint Number.
|
||||
*
|
||||
* @return Rx buffer address.
|
||||
*/
|
||||
uint16_t GetEPTxAddr(uint8_t bEpNum)
|
||||
{
|
||||
return(_GetEPTxAddr(bEpNum));
|
||||
}
|
||||
/*******************************************************************************
|
||||
* @fn GetEPRxAddr.
|
||||
*
|
||||
* @brief Returns the endpoint Rx buffer address.
|
||||
*
|
||||
* @param bEpNum: Endpoint Number.
|
||||
*
|
||||
* @returnRx buffer address.
|
||||
*/
|
||||
uint16_t GetEPRxAddr(uint8_t bEpNum)
|
||||
{
|
||||
return(_GetEPRxAddr(bEpNum));
|
||||
}
|
||||
/*******************************************************************************
|
||||
* @fn SetEPTxCount.
|
||||
*
|
||||
* @brief Set the Tx count.
|
||||
*
|
||||
* @param bEpNum: Endpoint Number.
|
||||
* wCount: new count value.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void SetEPTxCount(uint8_t bEpNum, uint16_t wCount)
|
||||
{
|
||||
_SetEPTxCount(bEpNum, wCount);
|
||||
}
|
||||
/*******************************************************************************
|
||||
* @fn SetEPCountRxReg.
|
||||
*
|
||||
* @brief Set the Count Rx Register value.
|
||||
*
|
||||
* @param *pdwReg: point to the register.
|
||||
* wCount: the new register value.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void SetEPCountRxReg(uint32_t *pdwReg, uint16_t wCount)
|
||||
{
|
||||
_SetEPCountRxReg(dwReg, wCount);
|
||||
}
|
||||
/*******************************************************************************
|
||||
* @fn SetEPRxCount
|
||||
*
|
||||
* @brief Set the Rx count.
|
||||
*
|
||||
* @param bEpNum: Endpoint Number.
|
||||
* wCount: the new count value.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void SetEPRxCount(uint8_t bEpNum, uint16_t wCount)
|
||||
{
|
||||
_SetEPRxCount(bEpNum, wCount);
|
||||
}
|
||||
/*******************************************************************************
|
||||
* @fn GetEPTxCount
|
||||
*
|
||||
* @brief Get the Tx count.
|
||||
*
|
||||
* @param bEpNum: Endpoint Number.
|
||||
*
|
||||
* @return Tx count value.
|
||||
*/
|
||||
uint16_t GetEPTxCount(uint8_t bEpNum)
|
||||
{
|
||||
return(_GetEPTxCount(bEpNum));
|
||||
}
|
||||
/*******************************************************************************
|
||||
* @fn GetEPRxCount
|
||||
*
|
||||
* @brief Get the Rx count.
|
||||
*
|
||||
* @param bEpNum: Endpoint Number.
|
||||
*
|
||||
* @return Rx count value.
|
||||
*/
|
||||
uint16_t GetEPRxCount(uint8_t bEpNum)
|
||||
{
|
||||
return(_GetEPRxCount(bEpNum));
|
||||
}
|
||||
/*******************************************************************************
|
||||
* @fn SetEPDblBuffAddr
|
||||
*
|
||||
* @brief Set the addresses of the buffer 0 and 1.
|
||||
*
|
||||
* @param bEpNum: Endpoint Number.
|
||||
* wBuf0Addr: new address of buffer 0.
|
||||
* wBuf1Addr: new address of buffer 1.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void SetEPDblBuffAddr(uint8_t bEpNum, uint16_t wBuf0Addr, uint16_t wBuf1Addr)
|
||||
{
|
||||
_SetEPDblBuffAddr(bEpNum, wBuf0Addr, wBuf1Addr);
|
||||
}
|
||||
/*******************************************************************************
|
||||
* @fn SetEPDblBuf0Addr
|
||||
*
|
||||
* @brief Set the Buffer 1 address.
|
||||
*
|
||||
* @param bEpNum: Endpoint Number
|
||||
* wBuf0Addr: new address.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void SetEPDblBuf0Addr(uint8_t bEpNum, uint16_t wBuf0Addr)
|
||||
{
|
||||
_SetEPDblBuf0Addr(bEpNum, wBuf0Addr);
|
||||
}
|
||||
/*******************************************************************************
|
||||
* @fn SetEPDblBuf1Addr
|
||||
*
|
||||
* @brief Set the Buffer 1 address.
|
||||
*
|
||||
* @param bEpNum: Endpoint Number
|
||||
* wBuf1Addr: new address.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void SetEPDblBuf1Addr(uint8_t bEpNum, uint16_t wBuf1Addr)
|
||||
{
|
||||
_SetEPDblBuf1Addr(bEpNum, wBuf1Addr);
|
||||
}
|
||||
/*******************************************************************************
|
||||
* @fn GetEPDblBuf0Addr
|
||||
*
|
||||
* @brief Returns the address of the Buffer 0.
|
||||
*
|
||||
* @param bEpNum: Endpoint Number.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
uint16_t GetEPDblBuf0Addr(uint8_t bEpNum)
|
||||
{
|
||||
return(_GetEPDblBuf0Addr(bEpNum));
|
||||
}
|
||||
/*******************************************************************************
|
||||
* @fn GetEPDblBuf1Addr
|
||||
*
|
||||
* @brief Returns the address of the Buffer 1.
|
||||
*
|
||||
* @param bEpNum: Endpoint Number.
|
||||
*
|
||||
* @return Address of the Buffer 1.
|
||||
*/
|
||||
uint16_t GetEPDblBuf1Addr(uint8_t bEpNum)
|
||||
{
|
||||
return(_GetEPDblBuf1Addr(bEpNum));
|
||||
}
|
||||
/*******************************************************************************
|
||||
* @fn SetEPDblBuffCount
|
||||
*
|
||||
* @brief Set the number of bytes for a double Buffer
|
||||
* endpoint.
|
||||
*
|
||||
* @param bEpNum,bDir, wCount
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void SetEPDblBuffCount(uint8_t bEpNum, uint8_t bDir, uint16_t wCount)
|
||||
{
|
||||
_SetEPDblBuffCount(bEpNum, bDir, wCount);
|
||||
}
|
||||
/*******************************************************************************
|
||||
* @fn SetEPDblBuf0Count
|
||||
*
|
||||
* @brief Set the number of bytes in the buffer 0 of a double Buffer
|
||||
* endpoint.
|
||||
*
|
||||
* @param bEpNum, bDir, wCount
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void SetEPDblBuf0Count(uint8_t bEpNum, uint8_t bDir, uint16_t wCount)
|
||||
{
|
||||
_SetEPDblBuf0Count(bEpNum, bDir, wCount);
|
||||
}
|
||||
/*******************************************************************************
|
||||
* @fn SetEPDblBuf1Count
|
||||
*
|
||||
* @brief Set the number of bytes in the buffer 0 of a double Buffer
|
||||
* endpoint.
|
||||
*
|
||||
* @param bEpNum, bDir, wCount
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void SetEPDblBuf1Count(uint8_t bEpNum, uint8_t bDir, uint16_t wCount)
|
||||
{
|
||||
_SetEPDblBuf1Count(bEpNum, bDir, wCount);
|
||||
}
|
||||
/*******************************************************************************
|
||||
* @fn GetEPDblBuf0Count
|
||||
*
|
||||
* @brief Returns the number of byte received in the buffer 0 of a double
|
||||
* Buffer endpoint.
|
||||
*
|
||||
* @param bEpNum: Endpoint Number.
|
||||
*
|
||||
* @return Endpoint Buffer 0 count
|
||||
*/
|
||||
uint16_t GetEPDblBuf0Count(uint8_t bEpNum)
|
||||
{
|
||||
return(_GetEPDblBuf0Count(bEpNum));
|
||||
}
|
||||
/*******************************************************************************
|
||||
* @fn GetEPDblBuf1Count
|
||||
*
|
||||
* @brief Returns the number of data received in the buffer 1 of a double
|
||||
* Buffer endpoint.
|
||||
*
|
||||
* @param bEpNum: Endpoint Number.
|
||||
*
|
||||
* @return Endpoint Buffer 1 count.
|
||||
*/
|
||||
uint16_t GetEPDblBuf1Count(uint8_t bEpNum)
|
||||
{
|
||||
return(_GetEPDblBuf1Count(bEpNum));
|
||||
}
|
||||
/*******************************************************************************
|
||||
* @fn GetEPDblBufDir
|
||||
*
|
||||
* @brief gets direction of the double buffered endpoint
|
||||
*
|
||||
* @param bEpNum: Endpoint Number.
|
||||
*
|
||||
* @return EP_DBUF_OUT, EP_DBUF_IN,
|
||||
* EP_DBUF_ERR if the endpoint counter not yet programmed.
|
||||
*/
|
||||
EP_DBUF_DIR GetEPDblBufDir(uint8_t bEpNum)
|
||||
{
|
||||
if ((uint16_t)(*_pEPRxCount(bEpNum) & 0xFC00) != 0)
|
||||
return(EP_DBUF_OUT);
|
||||
else if (((uint16_t)(*_pEPTxCount(bEpNum)) & 0x03FF) != 0)
|
||||
return(EP_DBUF_IN);
|
||||
else
|
||||
return(EP_DBUF_ERR);
|
||||
}
|
||||
/*******************************************************************************
|
||||
* @fn FreeUserBuffer
|
||||
*
|
||||
* @brief free buffer used from the application realizing it to the line
|
||||
toggles bit SW_BUF in the double buffered endpoint register
|
||||
*
|
||||
* @param bEpNum, bDir
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void FreeUserBuffer(uint8_t bEpNum, uint8_t bDir)
|
||||
{
|
||||
if (bDir == EP_DBUF_OUT)
|
||||
{
|
||||
_ToggleDTOG_TX(bEpNum);
|
||||
}
|
||||
else if (bDir == EP_DBUF_IN)
|
||||
{
|
||||
_ToggleDTOG_RX(bEpNum);
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn ToWord
|
||||
*
|
||||
* @brief merge two byte in a word.
|
||||
*
|
||||
* @param bh: byte high, bl: bytes low.
|
||||
*
|
||||
* @return resulted word.
|
||||
*/
|
||||
uint16_t ToWord(uint8_t bh, uint8_t bl)
|
||||
{
|
||||
uint16_t wRet;
|
||||
wRet = (uint16_t)bl | ((uint16_t)bh << 8);
|
||||
|
||||
return(wRet);
|
||||
}
|
||||
/*******************************************************************************
|
||||
* @fn ByteSwap
|
||||
*
|
||||
* @brief Swap two byte in a word.
|
||||
*
|
||||
* @param wSwW: word to Swap.
|
||||
*
|
||||
* @return resulted word.
|
||||
*/
|
||||
uint16_t ByteSwap(uint16_t wSwW)
|
||||
{
|
||||
uint8_t bTemp;
|
||||
uint16_t wRet;
|
||||
bTemp = (uint8_t)(wSwW & 0xff);
|
||||
wRet = (wSwW >> 8) | ((uint16_t)bTemp << 8);
|
||||
|
||||
return(wRet);
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : usb_sil.c
|
||||
* Author : WCH
|
||||
* Version : V1.0.0
|
||||
* Date : 2021/08/08
|
||||
* Description : Simplified Interface Layer for Global Initialization and
|
||||
* Endpoint Rea/Write operations.
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
* Attention: This software (modified or not) and binary are used for
|
||||
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
|
||||
*******************************************************************************/
|
||||
#include "usb_lib.h"
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn USB_SIL_Init
|
||||
*
|
||||
* @brief Initialize the USB Device IP and the Endpoint 0.
|
||||
*
|
||||
* @return Status.
|
||||
*/
|
||||
uint32_t USB_SIL_Init(void)
|
||||
{
|
||||
_SetISTR(0);
|
||||
wInterrupt_Mask = IMR_MSK;
|
||||
_SetCNTR(wInterrupt_Mask);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn USB_SIL_Write
|
||||
*
|
||||
* @brief Write a buffer of data to a selected endpoint.
|
||||
*
|
||||
* @param bEpAddr: The address of the non control endpoint.
|
||||
* pBufferPointer: The pointer to the buffer of data to be written
|
||||
* to the endpoint.
|
||||
* wBufferSize: Number of data to be written (in bytes).
|
||||
*
|
||||
* @return Status.
|
||||
*/
|
||||
uint32_t USB_SIL_Write(uint8_t bEpAddr, uint8_t* pBufferPointer, uint32_t wBufferSize)
|
||||
{
|
||||
UserToPMABufferCopy(pBufferPointer, GetEPTxAddr(bEpAddr & 0x7F), wBufferSize);
|
||||
SetEPTxCount((bEpAddr & 0x7F), wBufferSize);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn USB_SIL_Read
|
||||
*
|
||||
* @brief Write a buffer of data to a selected endpoint.
|
||||
*
|
||||
* @param bEpAddr: The address of the non control endpoint.
|
||||
* pBufferPointer: The pointer to which will be saved the
|
||||
* received data buffer.
|
||||
*
|
||||
* @return Number of received data (in Bytes).
|
||||
*/
|
||||
uint32_t USB_SIL_Read(uint8_t bEpAddr, uint8_t* pBufferPointer)
|
||||
{
|
||||
uint32_t DataLength = 0;
|
||||
|
||||
DataLength = GetEPRxCount(bEpAddr & 0x7F);
|
||||
PMAToUserBufferCopy(pBufferPointer, GetEPRxAddr(bEpAddr & 0x7F), DataLength);
|
||||
|
||||
return DataLength;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : ch32v20x_conf.h
|
||||
* Author : WCH
|
||||
* Version : V1.0.0
|
||||
* Date : 2021/06/06
|
||||
* Description : Library configuration file.
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
* Attention: This software (modified or not) and binary are used for
|
||||
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
|
||||
*******************************************************************************/
|
||||
#ifndef __CH32V20x_CONF_H
|
||||
#define __CH32V20x_CONF_H
|
||||
|
||||
#include "ch32v20x_adc.h"
|
||||
#include "ch32v20x_bkp.h"
|
||||
#include "ch32v20x_can.h"
|
||||
#include "ch32v20x_crc.h"
|
||||
#include "ch32v20x_dbgmcu.h"
|
||||
#include "ch32v20x_dma.h"
|
||||
#include "ch32v20x_exti.h"
|
||||
#include "ch32v20x_flash.h"
|
||||
#include "ch32v20x_gpio.h"
|
||||
#include "ch32v20x_i2c.h"
|
||||
#include "ch32v20x_iwdg.h"
|
||||
#include "ch32v20x_pwr.h"
|
||||
#include "ch32v20x_rcc.h"
|
||||
#include "ch32v20x_rtc.h"
|
||||
#include "ch32v20x_spi.h"
|
||||
#include "ch32v20x_tim.h"
|
||||
#include "ch32v20x_usart.h"
|
||||
#include "ch32v20x_wwdg.h"
|
||||
#include "ch32v20x_it.h"
|
||||
#include "ch32v20x_misc.h"
|
||||
|
||||
|
||||
#endif /* __CH32V20x_CONF_H */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : ch32v20x_it.c
|
||||
* Author : WCH
|
||||
* Version : V1.0.0
|
||||
* Date : 2021/06/06
|
||||
* Description : Main Interrupt Service Routines.
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
* Attention: This software (modified or not) and binary are used for
|
||||
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
|
||||
*******************************************************************************/
|
||||
#include "ch32v20x_it.h"
|
||||
|
||||
void NMI_Handler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
|
||||
void HardFault_Handler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
|
||||
|
||||
/*********************************************************************
|
||||
* @fn NMI_Handler
|
||||
*
|
||||
* @brief This function handles NMI exception.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void NMI_Handler(void)
|
||||
{
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn HardFault_Handler
|
||||
*
|
||||
* @brief This function handles Hard Fault exception.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void HardFault_Handler(void)
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : ch32v20x_it.h
|
||||
* Author : WCH
|
||||
* Version : V1.0.0
|
||||
* Date : 2021/06/06
|
||||
* Description : This file contains the headers of the interrupt handlers.
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
* Attention: This software (modified or not) and binary are used for
|
||||
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
|
||||
*******************************************************************************/
|
||||
#ifndef __CH32V20x_IT_H
|
||||
#define __CH32V20x_IT_H
|
||||
|
||||
#include "debug.h"
|
||||
|
||||
|
||||
#endif /* __CH32V20x_IT_H */
|
||||
|
||||
|
||||
@@ -0,0 +1,986 @@
|
||||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : system_ch32v20x.c
|
||||
* Author : WCH
|
||||
* Version : V1.0.0
|
||||
* Date : 2021/06/06
|
||||
* Description : CH32V20x Device Peripheral Access Layer System Source File.
|
||||
* For HSE = 32Mhz (CH32V208x/CH32V203RBT6)
|
||||
* For HSE = 8Mhz (other CH32V203x)
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
* Attention: This software (modified or not) and binary are used for
|
||||
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
|
||||
*******************************************************************************/
|
||||
#include "ch32v20x.h"
|
||||
|
||||
/*
|
||||
* Uncomment the line corresponding to the desired System clock (SYSCLK) frequency (after
|
||||
* reset the HSI is used as SYSCLK source).
|
||||
* If none of the define below is enabled, the HSI is used as System clock source.
|
||||
*/
|
||||
//#define SYSCLK_FREQ_HSE HSE_VALUE
|
||||
//#define SYSCLK_FREQ_48MHz_HSE 48000000
|
||||
//#define SYSCLK_FREQ_56MHz_HSE 56000000
|
||||
//#define SYSCLK_FREQ_72MHz_HSE 72000000
|
||||
#define SYSCLK_FREQ_96MHz_HSE 96000000
|
||||
//#define SYSCLK_FREQ_120MHz_HSE 120000000
|
||||
//#define SYSCLK_FREQ_144MHz_HSE 144000000
|
||||
//#define SYSCLK_FREQ_HSI HSI_VALUE
|
||||
//#define SYSCLK_FREQ_48MHz_HSI 48000000
|
||||
//#define SYSCLK_FREQ_56MHz_HSI 56000000
|
||||
//#define SYSCLK_FREQ_72MHz_HSI 72000000
|
||||
//#define SYSCLK_FREQ_96MHz_HSI 96000000
|
||||
//#define SYSCLK_FREQ_120MHz_HSI 120000000
|
||||
//#define SYSCLK_FREQ_144MHz_HSI 144000000
|
||||
|
||||
/* Clock Definitions */
|
||||
#ifdef SYSCLK_FREQ_HSE
|
||||
uint32_t SystemCoreClock = SYSCLK_FREQ_HSE; /* System Clock Frequency (Core Clock) */
|
||||
#elif defined SYSCLK_FREQ_48MHz_HSE
|
||||
uint32_t SystemCoreClock = SYSCLK_FREQ_48MHz_HSE; /* System Clock Frequency (Core Clock) */
|
||||
#elif defined SYSCLK_FREQ_56MHz_HSE
|
||||
uint32_t SystemCoreClock = SYSCLK_FREQ_56MHz_HSE; /* System Clock Frequency (Core Clock) */
|
||||
#elif defined SYSCLK_FREQ_72MHz_HSE
|
||||
uint32_t SystemCoreClock = SYSCLK_FREQ_72MHz_HSE; /* System Clock Frequency (Core Clock) */
|
||||
#elif defined SYSCLK_FREQ_96MHz_HSE
|
||||
uint32_t SystemCoreClock = SYSCLK_FREQ_96MHz_HSE; /* System Clock Frequency (Core Clock) */
|
||||
#elif defined SYSCLK_FREQ_120MHz_HSE
|
||||
uint32_t SystemCoreClock = SYSCLK_FREQ_120MHz_HSE; /* System Clock Frequency (Core Clock) */
|
||||
#elif defined SYSCLK_FREQ_144MHz_HSE
|
||||
uint32_t SystemCoreClock = SYSCLK_FREQ_144MHz_HSE; /* System Clock Frequency (Core Clock) */
|
||||
#elif defined SYSCLK_FREQ_48MHz_HSI
|
||||
uint32_t SystemCoreClock = SYSCLK_FREQ_48MHz_HSI; /* System Clock Frequency (Core Clock) */
|
||||
#elif defined SYSCLK_FREQ_56MHz_HSI
|
||||
uint32_t SystemCoreClock = SYSCLK_FREQ_56MHz_HSI; /* System Clock Frequency (Core Clock) */
|
||||
#elif defined SYSCLK_FREQ_72MHz_HSI
|
||||
uint32_t SystemCoreClock = SYSCLK_FREQ_72MHz_HSI; /* System Clock Frequency (Core Clock) */
|
||||
#elif defined SYSCLK_FREQ_96MHz_HSI
|
||||
uint32_t SystemCoreClock = SYSCLK_FREQ_96MHz_HSI; /* System Clock Frequency (Core Clock) */
|
||||
#elif defined SYSCLK_FREQ_120MHz_HSI
|
||||
uint32_t SystemCoreClock = SYSCLK_FREQ_120MHz_HSI; /* System Clock Frequency (Core Clock) */
|
||||
#elif defined SYSCLK_FREQ_144MHz_HSI
|
||||
uint32_t SystemCoreClock = SYSCLK_FREQ_144MHz_HSI; /* System Clock Frequency (Core Clock) */
|
||||
#else
|
||||
uint32_t SystemCoreClock = HSI_VALUE; /* System Clock Frequency (Core Clock) */
|
||||
|
||||
#endif
|
||||
|
||||
__I uint8_t AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9};
|
||||
|
||||
|
||||
/* system_private_function_proto_types */
|
||||
static void SetSysClock(void);
|
||||
|
||||
#ifdef SYSCLK_FREQ_HSE
|
||||
static void SetSysClockToHSE( void );
|
||||
#elif defined SYSCLK_FREQ_48MHz_HSE
|
||||
static void SetSysClockTo48_HSE( void );
|
||||
#elif defined SYSCLK_FREQ_56MHz_HSE
|
||||
static void SetSysClockTo56_HSE( void );
|
||||
#elif defined SYSCLK_FREQ_72MHz_HSE
|
||||
static void SetSysClockTo72_HSE( void );
|
||||
#elif defined SYSCLK_FREQ_96MHz_HSE
|
||||
static void SetSysClockTo96_HSE( void );
|
||||
#elif defined SYSCLK_FREQ_120MHz_HSE
|
||||
static void SetSysClockTo120_HSE( void );
|
||||
#elif defined SYSCLK_FREQ_144MHz_HSE
|
||||
static void SetSysClockTo144_HSE( void );
|
||||
#elif defined SYSCLK_FREQ_48MHz_HSI
|
||||
static void SetSysClockTo48_HSI( void );
|
||||
#elif defined SYSCLK_FREQ_56MHz_HSI
|
||||
static void SetSysClockTo56_HSI( void );
|
||||
#elif defined SYSCLK_FREQ_72MHz_HSI
|
||||
static void SetSysClockTo72_HSI( void );
|
||||
#elif defined SYSCLK_FREQ_96MHz_HSI
|
||||
static void SetSysClockTo96_HSI( void );
|
||||
#elif defined SYSCLK_FREQ_120MHz_HSI
|
||||
static void SetSysClockTo120_HSI( void );
|
||||
#elif defined SYSCLK_FREQ_144MHz_HSI
|
||||
static void SetSysClockTo144_HSI( void );
|
||||
|
||||
#endif
|
||||
|
||||
/*********************************************************************
|
||||
* @fn SystemInit
|
||||
*
|
||||
* @brief Setup the microcontroller system Initialize the Embedded Flash Interface,
|
||||
* the PLL and update the SystemCoreClock variable.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void SystemInit (void)
|
||||
{
|
||||
RCC->CTLR |= (uint32_t)0x00000001;
|
||||
RCC->CFGR0 &= (uint32_t)0xF8FF0000;
|
||||
RCC->CTLR &= (uint32_t)0xFEF6FFFF;
|
||||
RCC->CTLR &= (uint32_t)0xFFFBFFFF;
|
||||
RCC->CFGR0 &= (uint32_t)0xFF80FFFF;
|
||||
RCC->INTR = 0x009F0000;
|
||||
SetSysClock();
|
||||
}
|
||||
|
||||
|
||||
/*********************************************************************
|
||||
* @fn SystemCoreClockUpdate
|
||||
*
|
||||
* @brief Update SystemCoreClock variable according to Clock Register Values.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void SystemCoreClockUpdate (void)
|
||||
{
|
||||
uint32_t tmp = 0, pllmull = 0, pllsource = 0, Pll_6_5 = 0;
|
||||
|
||||
tmp = RCC->CFGR0 & RCC_SWS;
|
||||
|
||||
switch (tmp)
|
||||
{
|
||||
case 0x00:
|
||||
SystemCoreClock = HSI_VALUE;
|
||||
break;
|
||||
case 0x04:
|
||||
SystemCoreClock = HSE_VALUE;
|
||||
break;
|
||||
case 0x08:
|
||||
pllmull = RCC->CFGR0 & RCC_PLLMULL;
|
||||
pllsource = RCC->CFGR0 & RCC_PLLSRC;
|
||||
pllmull = ( pllmull >> 18) + 2;
|
||||
|
||||
if(pllmull == 17) pllmull = 18;
|
||||
|
||||
if (pllsource == 0x00)
|
||||
{
|
||||
if(EXTEN->EXTEN_CTR & EXTEN_PLL_HSI_PRE){
|
||||
SystemCoreClock = HSI_VALUE * pllmull;
|
||||
}
|
||||
else{
|
||||
SystemCoreClock = (HSI_VALUE >> 1) * pllmull;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
#if defined (CH32V20x_D8W)
|
||||
if((RCC->CFGR0 & (3<<22)) == (3<<22))
|
||||
{
|
||||
SystemCoreClock = ((HSE_VALUE>>1)) * pllmull;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
if ((RCC->CFGR0 & RCC_PLLXTPRE) != (uint32_t)RESET)
|
||||
{
|
||||
#if defined (CH32V20x_D8) || defined (CH32V20x_D8W)
|
||||
SystemCoreClock = ((HSE_VALUE>>2) >> 1) * pllmull;
|
||||
#else
|
||||
SystemCoreClock = (HSE_VALUE >> 1) * pllmull;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
#if defined (CH32V20x_D8) || defined (CH32V20x_D8W)
|
||||
SystemCoreClock = (HSE_VALUE>>2) * pllmull;
|
||||
#else
|
||||
SystemCoreClock = HSE_VALUE * pllmull;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
if(Pll_6_5 == 1) SystemCoreClock = (SystemCoreClock / 2);
|
||||
|
||||
break;
|
||||
default:
|
||||
SystemCoreClock = HSI_VALUE;
|
||||
break;
|
||||
}
|
||||
|
||||
tmp = AHBPrescTable[((RCC->CFGR0 & RCC_HPRE) >> 4)];
|
||||
SystemCoreClock >>= tmp;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn SetSysClock
|
||||
*
|
||||
* @brief Configures the System clock frequency, HCLK, PCLK2 and PCLK1 prescalers.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
static void SetSysClock(void)
|
||||
{
|
||||
#ifdef SYSCLK_FREQ_HSE
|
||||
SetSysClockToHSE();
|
||||
#elif defined SYSCLK_FREQ_48MHz_HSE
|
||||
SetSysClockTo48_HSE();
|
||||
#elif defined SYSCLK_FREQ_56MHz_HSE
|
||||
SetSysClockTo56_HSE();
|
||||
#elif defined SYSCLK_FREQ_72MHz_HSE
|
||||
SetSysClockTo72_HSE();
|
||||
#elif defined SYSCLK_FREQ_96MHz_HSE
|
||||
SetSysClockTo96_HSE();
|
||||
#elif defined SYSCLK_FREQ_120MHz_HSE
|
||||
SetSysClockTo120_HSE();
|
||||
#elif defined SYSCLK_FREQ_144MHz_HSE
|
||||
SetSysClockTo144_HSE();
|
||||
#elif defined SYSCLK_FREQ_48MHz_HSI
|
||||
SetSysClockTo48_HSI();
|
||||
#elif defined SYSCLK_FREQ_56MHz_HSI
|
||||
SetSysClockTo56_HSI();
|
||||
#elif defined SYSCLK_FREQ_72MHz_HSI
|
||||
SetSysClockTo72_HSI();
|
||||
#elif defined SYSCLK_FREQ_96MHz_HSI
|
||||
SetSysClockTo96_HSI();
|
||||
#elif defined SYSCLK_FREQ_120MHz_HSI
|
||||
SetSysClockTo120_HSI();
|
||||
#elif defined SYSCLK_FREQ_144MHz_HSI
|
||||
SetSysClockTo144_HSI();
|
||||
|
||||
#endif
|
||||
|
||||
/* If none of the define above is enabled, the HSI is used as System clock
|
||||
* source (default after reset)
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
#ifdef SYSCLK_FREQ_HSE
|
||||
|
||||
/*********************************************************************
|
||||
* @fn SetSysClockToHSE
|
||||
*
|
||||
* @brief Sets HSE as System clock source and configure HCLK, PCLK2 and PCLK1 prescalers.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
static void SetSysClockToHSE(void)
|
||||
{
|
||||
__IO uint32_t StartUpCounter = 0, HSEStatus = 0;
|
||||
|
||||
|
||||
RCC->CTLR |= ((uint32_t)RCC_HSEON);
|
||||
|
||||
/* Wait till HSE is ready and if Time out is reached exit */
|
||||
do
|
||||
{
|
||||
HSEStatus = RCC->CTLR & RCC_HSERDY;
|
||||
StartUpCounter++;
|
||||
} while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
|
||||
|
||||
if ((RCC->CTLR & RCC_HSERDY) != RESET)
|
||||
{
|
||||
HSEStatus = (uint32_t)0x01;
|
||||
}
|
||||
else
|
||||
{
|
||||
HSEStatus = (uint32_t)0x00;
|
||||
}
|
||||
|
||||
if (HSEStatus == (uint32_t)0x01)
|
||||
{
|
||||
/* HCLK = SYSCLK */
|
||||
RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1;
|
||||
/* PCLK2 = HCLK */
|
||||
RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1;
|
||||
/* PCLK1 = HCLK */
|
||||
RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV1;
|
||||
|
||||
/* Select HSE as system clock source
|
||||
* CH32V20x_D6 (HSE=8MHZ)
|
||||
* CH32V20x_D8 (HSE=32MHZ)
|
||||
* CH32V20x_D8W (HSE=32MHZ)
|
||||
*/
|
||||
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW));
|
||||
RCC->CFGR0 |= (uint32_t)RCC_SW_HSE;
|
||||
|
||||
/* Wait till HSE is used as system clock source */
|
||||
while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x04)
|
||||
{
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* If HSE fails to start-up, the application will have wrong clock
|
||||
* configuration. User can add here some code to deal with this error
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
#elif defined SYSCLK_FREQ_48MHz_HSE
|
||||
|
||||
/*********************************************************************
|
||||
* @fn SetSysClockTo48_HSE
|
||||
*
|
||||
* @brief Sets System clock frequency to 48MHz and configure HCLK, PCLK2 and PCLK1 prescalers.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
static void SetSysClockTo48_HSE(void)
|
||||
{
|
||||
__IO uint32_t StartUpCounter = 0, HSEStatus = 0;
|
||||
|
||||
|
||||
RCC->CTLR |= ((uint32_t)RCC_HSEON);
|
||||
/* Wait till HSE is ready and if Time out is reached exit */
|
||||
do
|
||||
{
|
||||
HSEStatus = RCC->CTLR & RCC_HSERDY;
|
||||
StartUpCounter++;
|
||||
} while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
|
||||
|
||||
if ((RCC->CTLR & RCC_HSERDY) != RESET)
|
||||
{
|
||||
HSEStatus = (uint32_t)0x01;
|
||||
}
|
||||
else
|
||||
{
|
||||
HSEStatus = (uint32_t)0x00;
|
||||
}
|
||||
|
||||
if (HSEStatus == (uint32_t)0x01)
|
||||
{
|
||||
/* HCLK = SYSCLK */
|
||||
RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1;
|
||||
/* PCLK2 = HCLK */
|
||||
RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1;
|
||||
/* PCLK1 = HCLK */
|
||||
RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2;
|
||||
|
||||
/* CH32V20x_D6-PLL configuration: PLLCLK = HSE * 6 = 48 MHz (HSE=8MHZ)
|
||||
* CH32V20x_D8-PLL configuration: PLLCLK = HSE/4 * 6 = 48 MHz (HSE=32MHZ)
|
||||
* CH32V20x_D8W-PLL configuration: PLLCLK = HSE/4 * 6 = 48 MHz (HSE=32MHZ)
|
||||
*/
|
||||
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_PLLSRC | RCC_PLLXTPRE | RCC_PLLMULL));
|
||||
|
||||
RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSE | RCC_PLLXTPRE_HSE | RCC_PLLMULL6);
|
||||
|
||||
/* Enable PLL */
|
||||
RCC->CTLR |= RCC_PLLON;
|
||||
/* Wait till PLL is ready */
|
||||
while((RCC->CTLR & RCC_PLLRDY) == 0)
|
||||
{
|
||||
}
|
||||
/* Select PLL as system clock source */
|
||||
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW));
|
||||
RCC->CFGR0 |= (uint32_t)RCC_SW_PLL;
|
||||
/* Wait till PLL is used as system clock source */
|
||||
while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08)
|
||||
{
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* If HSE fails to start-up, the application will have wrong clock
|
||||
* configuration. User can add here some code to deal with this error
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
#elif defined SYSCLK_FREQ_56MHz_HSE
|
||||
|
||||
/*********************************************************************
|
||||
* @fn SetSysClockTo56_HSE
|
||||
*
|
||||
* @brief Sets System clock frequency to 56MHz and configure HCLK, PCLK2 and PCLK1 prescalers.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
static void SetSysClockTo56_HSE(void)
|
||||
{
|
||||
__IO uint32_t StartUpCounter = 0, HSEStatus = 0;
|
||||
|
||||
RCC->CTLR |= ((uint32_t)RCC_HSEON);
|
||||
|
||||
/* Wait till HSE is ready and if Time out is reached exit */
|
||||
do
|
||||
{
|
||||
HSEStatus = RCC->CTLR & RCC_HSERDY;
|
||||
StartUpCounter++;
|
||||
} while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
|
||||
|
||||
if ((RCC->CTLR & RCC_HSERDY) != RESET)
|
||||
{
|
||||
HSEStatus = (uint32_t)0x01;
|
||||
}
|
||||
else
|
||||
{
|
||||
HSEStatus = (uint32_t)0x00;
|
||||
}
|
||||
|
||||
if (HSEStatus == (uint32_t)0x01)
|
||||
{
|
||||
/* HCLK = SYSCLK */
|
||||
RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1;
|
||||
/* PCLK2 = HCLK */
|
||||
RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1;
|
||||
/* PCLK1 = HCLK */
|
||||
RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2;
|
||||
|
||||
/* CH32V20x_D6-PLL configuration: PLLCLK = HSE * 7 = 56 MHz (HSE=8MHZ)
|
||||
* CH32V20x_D8-PLL configuration: PLLCLK = HSE/4 * 7 = 56 MHz (HSE=32MHZ)
|
||||
* CH32V20x_D8W-PLL configuration: PLLCLK = HSE/4 * 7 = 56 MHz (HSE=32MHZ)
|
||||
*/
|
||||
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_PLLSRC | RCC_PLLXTPRE | RCC_PLLMULL));
|
||||
|
||||
RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSE | RCC_PLLXTPRE_HSE | RCC_PLLMULL7);
|
||||
|
||||
/* Enable PLL */
|
||||
RCC->CTLR |= RCC_PLLON;
|
||||
/* Wait till PLL is ready */
|
||||
while((RCC->CTLR & RCC_PLLRDY) == 0)
|
||||
{
|
||||
}
|
||||
|
||||
/* Select PLL as system clock source */
|
||||
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW));
|
||||
RCC->CFGR0 |= (uint32_t)RCC_SW_PLL;
|
||||
/* Wait till PLL is used as system clock source */
|
||||
while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08)
|
||||
{
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* If HSE fails to start-up, the application will have wrong clock
|
||||
* configuration. User can add here some code to deal with this error
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
#elif defined SYSCLK_FREQ_72MHz_HSE
|
||||
|
||||
/*********************************************************************
|
||||
* @fn SetSysClockTo72_HSE
|
||||
*
|
||||
* @brief Sets System clock frequency to 72MHz and configure HCLK, PCLK2 and PCLK1 prescalers.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
static void SetSysClockTo72_HSE(void)
|
||||
{
|
||||
__IO uint32_t StartUpCounter = 0, HSEStatus = 0;
|
||||
|
||||
RCC->CTLR |= ((uint32_t)RCC_HSEON);
|
||||
|
||||
/* Wait till HSE is ready and if Time out is reached exit */
|
||||
do
|
||||
{
|
||||
HSEStatus = RCC->CTLR & RCC_HSERDY;
|
||||
StartUpCounter++;
|
||||
} while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
|
||||
|
||||
if ((RCC->CTLR & RCC_HSERDY) != RESET)
|
||||
{
|
||||
HSEStatus = (uint32_t)0x01;
|
||||
}
|
||||
else
|
||||
{
|
||||
HSEStatus = (uint32_t)0x00;
|
||||
}
|
||||
|
||||
if (HSEStatus == (uint32_t)0x01)
|
||||
{
|
||||
/* HCLK = SYSCLK */
|
||||
RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1;
|
||||
/* PCLK2 = HCLK */
|
||||
RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1;
|
||||
/* PCLK1 = HCLK */
|
||||
RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2;
|
||||
|
||||
/* CH32V20x_D6-PLL configuration: PLLCLK = HSE * 9 = 72 MHz (HSE=8MHZ)
|
||||
* CH32V20x_D8-PLL configuration: PLLCLK = HSE/4 * 9 = 72 MHz (HSE=32MHZ)
|
||||
* CH32V20x_D8W-PLL configuration: PLLCLK = HSE/4 * 9 = 72 MHz (HSE=32MHZ)
|
||||
*/
|
||||
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_PLLSRC | RCC_PLLXTPRE |
|
||||
RCC_PLLMULL));
|
||||
|
||||
RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSE | RCC_PLLXTPRE_HSE | RCC_PLLMULL9);
|
||||
|
||||
/* Enable PLL */
|
||||
RCC->CTLR |= RCC_PLLON;
|
||||
/* Wait till PLL is ready */
|
||||
while((RCC->CTLR & RCC_PLLRDY) == 0)
|
||||
{
|
||||
}
|
||||
/* Select PLL as system clock source */
|
||||
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW));
|
||||
RCC->CFGR0 |= (uint32_t)RCC_SW_PLL;
|
||||
/* Wait till PLL is used as system clock source */
|
||||
while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08)
|
||||
{
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* If HSE fails to start-up, the application will have wrong clock
|
||||
* configuration. User can add here some code to deal with this error
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#elif defined SYSCLK_FREQ_96MHz_HSE
|
||||
|
||||
/*********************************************************************
|
||||
* @fn SetSysClockTo96_HSE
|
||||
*
|
||||
* @brief Sets System clock frequency to 96MHz and configure HCLK, PCLK2 and PCLK1 prescalers.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
static void SetSysClockTo96_HSE(void)
|
||||
{
|
||||
__IO uint32_t StartUpCounter = 0, HSEStatus = 0;
|
||||
|
||||
RCC->CTLR |= ((uint32_t)RCC_HSEON);
|
||||
|
||||
/* Wait till HSE is ready and if Time out is reached exit */
|
||||
do
|
||||
{
|
||||
HSEStatus = RCC->CTLR & RCC_HSERDY;
|
||||
StartUpCounter++;
|
||||
} while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
|
||||
|
||||
if ((RCC->CTLR & RCC_HSERDY) != RESET)
|
||||
{
|
||||
HSEStatus = (uint32_t)0x01;
|
||||
}
|
||||
else
|
||||
{
|
||||
HSEStatus = (uint32_t)0x00;
|
||||
}
|
||||
|
||||
if (HSEStatus == (uint32_t)0x01)
|
||||
{
|
||||
/* HCLK = SYSCLK */
|
||||
RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1;
|
||||
/* PCLK2 = HCLK */
|
||||
RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1;
|
||||
/* PCLK1 = HCLK */
|
||||
RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2;
|
||||
|
||||
/* CH32V20x_D6-PLL configuration: PLLCLK = HSE * 12 = 96 MHz (HSE=8MHZ)
|
||||
* CH32V20x_D8-PLL configuration: PLLCLK = HSE/4 * 12 = 96 MHz (HSE=32MHZ)
|
||||
* CH32V20x_D8W-PLL configuration: PLLCLK = HSE/4 * 12 = 96 MHz (HSE=32MHZ)
|
||||
*/
|
||||
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_PLLSRC | RCC_PLLXTPRE |
|
||||
RCC_PLLMULL));
|
||||
|
||||
RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSE | RCC_PLLXTPRE_HSE | RCC_PLLMULL12);
|
||||
|
||||
/* Enable PLL */
|
||||
RCC->CTLR |= RCC_PLLON;
|
||||
/* Wait till PLL is ready */
|
||||
while((RCC->CTLR & RCC_PLLRDY) == 0)
|
||||
{
|
||||
}
|
||||
/* Select PLL as system clock source */
|
||||
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW));
|
||||
RCC->CFGR0 |= (uint32_t)RCC_SW_PLL;
|
||||
/* Wait till PLL is used as system clock source */
|
||||
while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08)
|
||||
{
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* If HSE fails to start-up, the application will have wrong clock
|
||||
* configuration. User can add here some code to deal with this error
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#elif defined SYSCLK_FREQ_120MHz_HSE
|
||||
|
||||
/*********************************************************************
|
||||
* @fn SetSysClockTo120_HSE
|
||||
*
|
||||
* @brief Sets System clock frequency to 120MHz and configure HCLK, PCLK2 and PCLK1 prescalers.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
static void SetSysClockTo120_HSE(void)
|
||||
{
|
||||
__IO uint32_t StartUpCounter = 0, HSEStatus = 0;
|
||||
|
||||
RCC->CTLR |= ((uint32_t)RCC_HSEON);
|
||||
|
||||
/* Wait till HSE is ready and if Time out is reached exit */
|
||||
do
|
||||
{
|
||||
HSEStatus = RCC->CTLR & RCC_HSERDY;
|
||||
StartUpCounter++;
|
||||
} while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
|
||||
|
||||
if((RCC->CTLR & RCC_HSERDY) != RESET)
|
||||
{
|
||||
HSEStatus = (uint32_t)0x01;
|
||||
}
|
||||
else
|
||||
{
|
||||
HSEStatus = (uint32_t)0x00;
|
||||
}
|
||||
|
||||
if(HSEStatus == (uint32_t)0x01)
|
||||
{
|
||||
#if defined (CH32V20x_D8W)
|
||||
RCC->CFGR0 |= (uint32_t)(3<<22);
|
||||
/* HCLK = SYSCLK/2 */
|
||||
RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV2;
|
||||
#else
|
||||
/* HCLK = SYSCLK */
|
||||
RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1;
|
||||
#endif
|
||||
/* PCLK2 = HCLK */
|
||||
RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1;
|
||||
/* PCLK1 = HCLK */
|
||||
RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2;
|
||||
|
||||
/* CH32V20x_D6-PLL configuration: PLLCLK = HSE * 15 = 120 MHz (HSE=8MHZ)
|
||||
* CH32V20x_D8-PLL configuration: PLLCLK = HSE/4 * 15 = 120 MHz (HSE=32MHZ)
|
||||
* CH32V20x_D8W-PLL configuration: PLLCLK = HSE/2 * 15 = 240 MHz (HSE=32MHZ)
|
||||
*/
|
||||
RCC->CFGR0 &= (uint32_t)((uint32_t) ~(RCC_PLLSRC | RCC_PLLXTPRE |
|
||||
RCC_PLLMULL));
|
||||
|
||||
RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSE | RCC_PLLXTPRE_HSE | RCC_PLLMULL15);
|
||||
|
||||
/* Enable PLL */
|
||||
RCC->CTLR |= RCC_PLLON;
|
||||
/* Wait till PLL is ready */
|
||||
while((RCC->CTLR & RCC_PLLRDY) == 0)
|
||||
{
|
||||
}
|
||||
/* Select PLL as system clock source */
|
||||
RCC->CFGR0 &= (uint32_t)((uint32_t) ~(RCC_SW));
|
||||
RCC->CFGR0 |= (uint32_t)RCC_SW_PLL;
|
||||
/* Wait till PLL is used as system clock source */
|
||||
while((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08)
|
||||
{
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* If HSE fails to start-up, the application will have wrong clock
|
||||
* configuration. User can add here some code to deal with this error
|
||||
*/
|
||||
}
|
||||
}
|
||||
#elif defined SYSCLK_FREQ_144MHz_HSE
|
||||
|
||||
/*********************************************************************
|
||||
* @fn SetSysClockTo144_HSE
|
||||
*
|
||||
* @brief Sets System clock frequency to 144MHz and configure HCLK, PCLK2 and PCLK1 prescalers.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
static void SetSysClockTo144_HSE(void)
|
||||
{
|
||||
__IO uint32_t StartUpCounter = 0, HSEStatus = 0;
|
||||
|
||||
RCC->CTLR |= ((uint32_t)RCC_HSEON);
|
||||
|
||||
/* Wait till HSE is ready and if Time out is reached exit */
|
||||
do
|
||||
{
|
||||
HSEStatus = RCC->CTLR & RCC_HSERDY;
|
||||
StartUpCounter++;
|
||||
} while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
|
||||
|
||||
if ((RCC->CTLR & RCC_HSERDY) != RESET)
|
||||
{
|
||||
HSEStatus = (uint32_t)0x01;
|
||||
}
|
||||
else
|
||||
{
|
||||
HSEStatus = (uint32_t)0x00;
|
||||
}
|
||||
|
||||
if (HSEStatus == (uint32_t)0x01)
|
||||
{
|
||||
/* HCLK = SYSCLK */
|
||||
RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1;
|
||||
/* PCLK2 = HCLK */
|
||||
RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1;
|
||||
/* PCLK1 = HCLK */
|
||||
RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2;
|
||||
|
||||
/* CH32V20x_D6-PLL configuration: PLLCLK = HSE * 18 = 144 MHz (HSE=8MHZ)
|
||||
* CH32V20x_D8-PLL configuration: PLLCLK = HSE/4 * 18 = 144 MHz (HSE=32MHZ)
|
||||
* CH32V20x_D8W-PLL configuration: PLLCLK = HSE/4 * 18 = 144 MHz (HSE=32MHZ)
|
||||
*/
|
||||
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_PLLSRC | RCC_PLLXTPRE |
|
||||
RCC_PLLMULL));
|
||||
|
||||
RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSE | RCC_PLLXTPRE_HSE | RCC_PLLMULL18);
|
||||
|
||||
/* Enable PLL */
|
||||
RCC->CTLR |= RCC_PLLON;
|
||||
/* Wait till PLL is ready */
|
||||
while((RCC->CTLR & RCC_PLLRDY) == 0)
|
||||
{
|
||||
}
|
||||
/* Select PLL as system clock source */
|
||||
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW));
|
||||
RCC->CFGR0 |= (uint32_t)RCC_SW_PLL;
|
||||
/* Wait till PLL is used as system clock source */
|
||||
while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08)
|
||||
{
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* If HSE fails to start-up, the application will have wrong clock
|
||||
* configuration. User can add here some code to deal with this error
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
#elif defined SYSCLK_FREQ_48MHz_HSI
|
||||
|
||||
/*********************************************************************
|
||||
* @fn SetSysClockTo48_HSI
|
||||
*
|
||||
* @brief Sets System clock frequency to 48MHz and configure HCLK, PCLK2 and PCLK1 prescalers.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
static void SetSysClockTo48_HSI(void)
|
||||
{
|
||||
EXTEN->EXTEN_CTR |= EXTEN_PLL_HSI_PRE;
|
||||
|
||||
/* HCLK = SYSCLK */
|
||||
RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1;
|
||||
/* PCLK2 = HCLK */
|
||||
RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1;
|
||||
/* PCLK1 = HCLK */
|
||||
RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2;
|
||||
|
||||
/* PLL configuration: PLLCLK = HSI * 6 = 48 MHz */
|
||||
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_PLLSRC | RCC_PLLXTPRE | RCC_PLLMULL));
|
||||
|
||||
RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSI_Div2 | RCC_PLLMULL6);
|
||||
|
||||
/* Enable PLL */
|
||||
RCC->CTLR |= RCC_PLLON;
|
||||
/* Wait till PLL is ready */
|
||||
while((RCC->CTLR & RCC_PLLRDY) == 0)
|
||||
{
|
||||
}
|
||||
/* Select PLL as system clock source */
|
||||
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW));
|
||||
RCC->CFGR0 |= (uint32_t)RCC_SW_PLL;
|
||||
/* Wait till PLL is used as system clock source */
|
||||
while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
#elif defined SYSCLK_FREQ_56MHz_HSI
|
||||
|
||||
/*********************************************************************
|
||||
* @fn SetSysClockTo56_HSI
|
||||
*
|
||||
* @brief Sets System clock frequency to 56MHz and configure HCLK, PCLK2 and PCLK1 prescalers.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
static void SetSysClockTo56_HSI(void)
|
||||
{
|
||||
EXTEN->EXTEN_CTR |= EXTEN_PLL_HSI_PRE;
|
||||
|
||||
/* HCLK = SYSCLK */
|
||||
RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1;
|
||||
/* PCLK2 = HCLK */
|
||||
RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1;
|
||||
/* PCLK1 = HCLK */
|
||||
RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2;
|
||||
|
||||
/* PLL configuration: PLLCLK = HSI * 7 = 48 MHz */
|
||||
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_PLLSRC | RCC_PLLXTPRE | RCC_PLLMULL));
|
||||
|
||||
RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSI_Div2 | RCC_PLLMULL7);
|
||||
|
||||
/* Enable PLL */
|
||||
RCC->CTLR |= RCC_PLLON;
|
||||
/* Wait till PLL is ready */
|
||||
while((RCC->CTLR & RCC_PLLRDY) == 0)
|
||||
{
|
||||
}
|
||||
/* Select PLL as system clock source */
|
||||
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW));
|
||||
RCC->CFGR0 |= (uint32_t)RCC_SW_PLL;
|
||||
/* Wait till PLL is used as system clock source */
|
||||
while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
#elif defined SYSCLK_FREQ_72MHz_HSI
|
||||
|
||||
/*********************************************************************
|
||||
* @fn SetSysClockTo72_HSI
|
||||
*
|
||||
* @brief Sets System clock frequency to 72MHz and configure HCLK, PCLK2 and PCLK1 prescalers.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
static void SetSysClockTo72_HSI(void)
|
||||
{
|
||||
EXTEN->EXTEN_CTR |= EXTEN_PLL_HSI_PRE;
|
||||
|
||||
/* HCLK = SYSCLK */
|
||||
RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1;
|
||||
/* PCLK2 = HCLK */
|
||||
RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1;
|
||||
/* PCLK1 = HCLK */
|
||||
RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2;
|
||||
|
||||
/* PLL configuration: PLLCLK = HSI * 9 = 72 MHz */
|
||||
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_PLLSRC | RCC_PLLXTPRE | RCC_PLLMULL));
|
||||
|
||||
RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSI_Div2 | RCC_PLLMULL9);
|
||||
|
||||
/* Enable PLL */
|
||||
RCC->CTLR |= RCC_PLLON;
|
||||
/* Wait till PLL is ready */
|
||||
while((RCC->CTLR & RCC_PLLRDY) == 0)
|
||||
{
|
||||
}
|
||||
/* Select PLL as system clock source */
|
||||
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW));
|
||||
RCC->CFGR0 |= (uint32_t)RCC_SW_PLL;
|
||||
/* Wait till PLL is used as system clock source */
|
||||
while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#elif defined SYSCLK_FREQ_96MHz_HSI
|
||||
|
||||
/*********************************************************************
|
||||
* @fn SetSysClockTo96_HSI
|
||||
*
|
||||
* @brief Sets System clock frequency to 96MHz and configure HCLK, PCLK2 and PCLK1 prescalers.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
static void SetSysClockTo96_HSI(void)
|
||||
{
|
||||
EXTEN->EXTEN_CTR |= EXTEN_PLL_HSI_PRE;
|
||||
|
||||
/* HCLK = SYSCLK */
|
||||
RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1;
|
||||
/* PCLK2 = HCLK */
|
||||
RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1;
|
||||
/* PCLK1 = HCLK */
|
||||
RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2;
|
||||
|
||||
/* PLL configuration: PLLCLK = HSI * 12 = 96 MHz */
|
||||
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_PLLSRC | RCC_PLLXTPRE | RCC_PLLMULL));
|
||||
|
||||
RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSI_Div2 | RCC_PLLMULL12);
|
||||
|
||||
/* Enable PLL */
|
||||
RCC->CTLR |= RCC_PLLON;
|
||||
/* Wait till PLL is ready */
|
||||
while((RCC->CTLR & RCC_PLLRDY) == 0)
|
||||
{
|
||||
}
|
||||
/* Select PLL as system clock source */
|
||||
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW));
|
||||
RCC->CFGR0 |= (uint32_t)RCC_SW_PLL;
|
||||
/* Wait till PLL is used as system clock source */
|
||||
while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#elif defined SYSCLK_FREQ_120MHz_HSI
|
||||
|
||||
/*********************************************************************
|
||||
* @fn SetSysClockTo120_HSI
|
||||
*
|
||||
* @brief Sets System clock frequency to 120MHz and configure HCLK, PCLK2 and PCLK1 prescalers.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
static void SetSysClockTo120_HSI(void)
|
||||
{
|
||||
EXTEN->EXTEN_CTR |= EXTEN_PLL_HSI_PRE;
|
||||
|
||||
/* HCLK = SYSCLK */
|
||||
RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1;
|
||||
/* PCLK2 = HCLK */
|
||||
RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1;
|
||||
/* PCLK1 = HCLK */
|
||||
RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2;
|
||||
|
||||
/* PLL configuration: PLLCLK = HSI * 15 = 120 MHz */
|
||||
RCC->CFGR0 &= (uint32_t)((uint32_t) ~(RCC_PLLSRC | RCC_PLLXTPRE |
|
||||
RCC_PLLMULL));
|
||||
|
||||
RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSI_Div2 | RCC_PLLMULL15);
|
||||
|
||||
/* Enable PLL */
|
||||
RCC->CTLR |= RCC_PLLON;
|
||||
/* Wait till PLL is ready */
|
||||
while((RCC->CTLR & RCC_PLLRDY) == 0)
|
||||
{
|
||||
}
|
||||
/* Select PLL as system clock source */
|
||||
RCC->CFGR0 &= (uint32_t)((uint32_t) ~(RCC_SW));
|
||||
RCC->CFGR0 |= (uint32_t)RCC_SW_PLL;
|
||||
/* Wait till PLL is used as system clock source */
|
||||
while((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08)
|
||||
{
|
||||
}
|
||||
}
|
||||
#elif defined SYSCLK_FREQ_144MHz_HSI
|
||||
|
||||
/*********************************************************************
|
||||
* @fn SetSysClockTo144_HSI
|
||||
*
|
||||
* @brief Sets System clock frequency to 144MHz and configure HCLK, PCLK2 and PCLK1 prescalers.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
static void SetSysClockTo144_HSI(void)
|
||||
{
|
||||
EXTEN->EXTEN_CTR |= EXTEN_PLL_HSI_PRE;
|
||||
|
||||
/* HCLK = SYSCLK */
|
||||
RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1;
|
||||
/* PCLK2 = HCLK */
|
||||
RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1;
|
||||
/* PCLK1 = HCLK */
|
||||
RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2;
|
||||
|
||||
/* PLL configuration: PLLCLK = HSI * 18 = 144 MHz */
|
||||
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_PLLSRC | RCC_PLLXTPRE | RCC_PLLMULL));
|
||||
|
||||
RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSI_Div2 | RCC_PLLMULL18);
|
||||
|
||||
/* Enable PLL */
|
||||
RCC->CTLR |= RCC_PLLON;
|
||||
/* Wait till PLL is ready */
|
||||
while((RCC->CTLR & RCC_PLLRDY) == 0)
|
||||
{
|
||||
}
|
||||
/* Select PLL as system clock source */
|
||||
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW));
|
||||
RCC->CFGR0 |= (uint32_t)RCC_SW_PLL;
|
||||
/* Wait till PLL is used as system clock source */
|
||||
while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,32 @@
|
||||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : system_ch32v20x.h
|
||||
* Author : WCH
|
||||
* Version : V1.0.0
|
||||
* Date : 2021/06/06
|
||||
* Description : CH32V20x Device Peripheral Access Layer System Header File.
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
* Attention: This software (modified or not) and binary are used for
|
||||
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
|
||||
*******************************************************************************/
|
||||
#ifndef __SYSTEM_ch32v20x_H
|
||||
#define __SYSTEM_ch32v20x_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern uint32_t SystemCoreClock; /* System Clock Frequency (Core Clock) */
|
||||
|
||||
/* System_Exported_Functions */
|
||||
extern void SystemInit(void);
|
||||
extern void SystemCoreClockUpdate(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*__CH32V20x_SYSTEM_H */
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : usbd_composite_km.h
|
||||
* Author : WCH
|
||||
* Version : V1.0.0
|
||||
* Date : 2022/07/04
|
||||
* Description :
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
* Attention: This software (modified or not) and binary are used for
|
||||
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
|
||||
*******************************************************************************/
|
||||
|
||||
|
||||
#ifndef __USBD_COMPOSITE_KM_H
|
||||
#define __USBD_COMPOSITE_KM_H
|
||||
|
||||
/*******************************************************************************/
|
||||
/* Included Header Files */
|
||||
#include "debug.h"
|
||||
#include "string.h"
|
||||
#include "usb_lib.h"
|
||||
#include "usb_desc.h"
|
||||
#include "usb_prop.h"
|
||||
#include "usb_pwr.h"
|
||||
/*******************************************************************************/
|
||||
/* Keyboard Key Value Macro Definition */
|
||||
#define DEF_KEY_CHAR_W 0x1A /* "W" */
|
||||
#define DEF_KEY_CHAR_A 0x04 /* "A" */
|
||||
#define DEF_KEY_CHAR_S 0x16 /* "S" */
|
||||
#define DEF_KEY_CHAR_D 0x07 /* "D" */
|
||||
|
||||
/*******************************************************************************/
|
||||
/* Global Variable Declaration */
|
||||
extern volatile uint8_t KB_LED_Cur_Status;
|
||||
/*******************************************************************************/
|
||||
/* Function Declaration */
|
||||
extern void TIM3_Init( uint16_t arr, uint16_t psc );
|
||||
extern void USART2_Init( uint32_t baudrate );
|
||||
extern void USART2_Receive_Handle( void );
|
||||
extern void KB_Scan_Init( void );
|
||||
extern void KB_Sleep_Wakeup_Cfg( void );
|
||||
extern void KB_Scan( void );
|
||||
extern void KB_Scan_Handle( void );
|
||||
extern void MS_Scan_Init( void );
|
||||
extern void MS_Sleep_Wakeup_Cfg( void );
|
||||
extern void MS_Scan( void );
|
||||
extern void MS_Scan_Handle( void );
|
||||
extern void KB_LED_Handle( void );
|
||||
extern void MCU_Sleep_Wakeup_Operate( void );
|
||||
#endif
|
||||
@@ -0,0 +1,684 @@
|
||||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : usbd_composite_km.c
|
||||
* Author : WCH
|
||||
* Version : V1.0.0
|
||||
* Date : 2022/08/20
|
||||
* Description : USB keyboard and mouse processing.
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
* Attention: This software (modified or not) and binary are used for
|
||||
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
|
||||
*******************************************************************************/
|
||||
|
||||
|
||||
/*******************************************************************************/
|
||||
/* Header Files */
|
||||
#include "usbd_composite_km.h"
|
||||
|
||||
uint8_t USBD_ENDPx_DataUp( uint8_t endp, uint8_t *pbuf, uint16_t len );
|
||||
|
||||
/*******************************************************************************/
|
||||
/* Variable Definition */
|
||||
|
||||
/* Mouse */
|
||||
volatile uint8_t MS_Scan_Done = 0x00; // Mouse Movement Scan Done
|
||||
volatile uint16_t MS_Scan_Result = 0x00F0; // Mouse Movement Scan Result
|
||||
uint8_t MS_Data_Pack[ DEF_ENDP_SIZE_MS ] = { 0x00 }; // Mouse IN Data Packet
|
||||
|
||||
/* Keyboard */
|
||||
volatile uint8_t KB_Scan_Done = 0x00; // Keyboard Keys Scan Done
|
||||
volatile uint16_t KB_Scan_Result = 0xF000; // Keyboard Keys Current Scan Result
|
||||
volatile uint16_t KB_Scan_Last_Result = 0xF000; // Keyboard Keys Last Scan Result
|
||||
uint8_t KB_Data_Pack[ DEF_ENDP_SIZE_KB ] = { 0x00 }; // Keyboard IN Data Packet
|
||||
volatile uint8_t KB_LED_Last_Status = 0x00; // Keyboard LED Last Result
|
||||
volatile uint8_t KB_LED_Cur_Status = 0x00; // Keyboard LED Current Result
|
||||
|
||||
/* USART */
|
||||
volatile uint8_t USART_Recv_Dat = 0x00;
|
||||
volatile uint8_t USART_Send_Flag = 0x00;
|
||||
volatile uint8_t USART_Send_Cnt = 0x00;
|
||||
|
||||
/*******************************************************************************/
|
||||
/* Interrupt Function Declaration */
|
||||
void TIM3_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
|
||||
void USART2_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
|
||||
|
||||
/*********************************************************************
|
||||
* @fn TIM3_Init
|
||||
*
|
||||
* @brief Initialize timer3 for keyboard and mouse scan.
|
||||
*
|
||||
* @param arr - The specific period value
|
||||
* psc - The specifies prescaler value
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void TIM3_Init( uint16_t arr, uint16_t psc )
|
||||
{
|
||||
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure = { 0 };
|
||||
NVIC_InitTypeDef NVIC_InitStructure = { 0 };
|
||||
|
||||
/* Enable Timer3 Clock */
|
||||
RCC_APB1PeriphClockCmd( RCC_APB1Periph_TIM3, ENABLE );
|
||||
|
||||
/* Initialize Timer3 */
|
||||
TIM_TimeBaseStructure.TIM_Period = arr;
|
||||
TIM_TimeBaseStructure.TIM_Prescaler = psc;
|
||||
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
|
||||
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
|
||||
TIM_TimeBaseInit( TIM3, &TIM_TimeBaseStructure );
|
||||
|
||||
TIM_ITConfig( TIM3, TIM_IT_Update, ENABLE );
|
||||
|
||||
NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||
NVIC_Init( &NVIC_InitStructure );
|
||||
|
||||
/* Enable Timer3 */
|
||||
TIM_Cmd( TIM3, ENABLE );
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn TIM3_IRQHandler
|
||||
*
|
||||
* @brief This function handles TIM3 global interrupt request.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void TIM3_IRQHandler( void )
|
||||
{
|
||||
if( TIM_GetITStatus( TIM3, TIM_IT_Update ) != RESET )
|
||||
{
|
||||
/* Clear interrupt flag */
|
||||
TIM_ClearITPendingBit( TIM3, TIM_IT_Update );
|
||||
|
||||
/* Handle keyboard scan */
|
||||
KB_Scan( );
|
||||
|
||||
/* Handle mouse scan */
|
||||
MS_Scan( );
|
||||
|
||||
/* Start timing for uploading the key value received from USART2 */
|
||||
if( USART_Send_Flag )
|
||||
{
|
||||
USART_Send_Cnt++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn USART2_Init
|
||||
*
|
||||
* @brief Initialize UART2 to receive keyboard data sent through the
|
||||
* PC serial software.
|
||||
*
|
||||
* @param baudrate - Serial baud rate
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void USART2_Init( uint32_t baudrate )
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure = { 0 };
|
||||
USART_InitTypeDef USART_InitStructure = { 0 };
|
||||
NVIC_InitTypeDef NVIC_InitStructure = { 0 };
|
||||
|
||||
RCC_APB1PeriphClockCmd( RCC_APB1Periph_USART2, ENABLE );
|
||||
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA, ENABLE );
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
|
||||
GPIO_Init( GPIOA, &GPIO_InitStructure );
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
|
||||
GPIO_Init( GPIOA, &GPIO_InitStructure );
|
||||
|
||||
NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||
NVIC_Init( &NVIC_InitStructure );
|
||||
|
||||
USART_InitStructure.USART_BaudRate = baudrate;
|
||||
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
|
||||
USART_InitStructure.USART_StopBits = USART_StopBits_1;
|
||||
USART_InitStructure.USART_Parity = USART_Parity_No;
|
||||
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
|
||||
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
|
||||
|
||||
USART_Init( USART2, &USART_InitStructure );
|
||||
USART_ITConfig( USART2, USART_IT_RXNE, ENABLE );
|
||||
USART_Cmd( USART2, ENABLE );
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn USART2_IRQHandler
|
||||
*
|
||||
* @brief This function handles USART2 global interrupt request.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void USART2_IRQHandler( void )
|
||||
{
|
||||
if( USART_GetITStatus( USART2, USART_IT_RXNE) != RESET )
|
||||
{
|
||||
/* Save the key value received from USART2 */
|
||||
USART_Recv_Dat = USART_ReceiveData( USART2 ) & 0xFF;
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn USART2_Receive_Handle
|
||||
*
|
||||
* @brief This function handles the key value received from USART2.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void USART2_Receive_Handle( void )
|
||||
{
|
||||
uint8_t status;
|
||||
static uint8_t flag = 0x00;
|
||||
|
||||
if( flag == 0 )
|
||||
{
|
||||
/* Store the received specified key value into the keyboard data buffer */
|
||||
if( ( USART_Recv_Dat == DEF_KEY_CHAR_A ) ||
|
||||
( USART_Recv_Dat == DEF_KEY_CHAR_W ) ||
|
||||
( USART_Recv_Dat == DEF_KEY_CHAR_S ) ||
|
||||
( USART_Recv_Dat == DEF_KEY_CHAR_D ) )
|
||||
{
|
||||
memset( KB_Data_Pack, 0x00, DEF_ENDP_SIZE_KB );
|
||||
KB_Data_Pack[ 2 ] = USART_Recv_Dat;
|
||||
flag = 1;
|
||||
}
|
||||
}
|
||||
else if( flag == 1 )
|
||||
{
|
||||
/* Load keyboard data to endpoint 1 */
|
||||
status = USBD_ENDPx_DataUp(ENDP1, KB_Data_Pack, DEF_ENDP_SIZE_KB);
|
||||
|
||||
if( status == USB_SUCCESS )
|
||||
{
|
||||
/* Enable timing for uploading the key value */
|
||||
USART_Send_Cnt = 0;
|
||||
USART_Send_Flag = 1;
|
||||
flag = 2;
|
||||
}
|
||||
}
|
||||
else if( flag == 2 )
|
||||
{
|
||||
/* Delay 10ms to ensure that the key value is successfully uploaded,
|
||||
* and prepare the data packet indicating the key release.
|
||||
*/
|
||||
if( USART_Send_Cnt >= 50 )
|
||||
{
|
||||
USART_Send_Flag = 0;
|
||||
memset( KB_Data_Pack, 0x00, DEF_ENDP_SIZE_KB );
|
||||
flag = 3;
|
||||
}
|
||||
}
|
||||
else if( flag == 3 )
|
||||
{
|
||||
/* Load keyboard data to endpoint 1 */
|
||||
status = USBD_ENDPx_DataUp(ENDP1, KB_Data_Pack, DEF_ENDP_SIZE_KB);
|
||||
/* Clear variables for next reception */
|
||||
if( status == USB_SUCCESS )
|
||||
{
|
||||
USART_Recv_Dat = 0;
|
||||
flag = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn KB_Scan_Init
|
||||
*
|
||||
* @brief Initialize IO for keyboard scan.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void KB_Scan_Init( void )
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure = { 0 };
|
||||
|
||||
/* Enable GPIOB clock */
|
||||
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB, ENABLE );
|
||||
|
||||
/* Initialize GPIOB (Pin4-Pin7) for the keyboard scan */
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_Init( GPIOB, &GPIO_InitStructure );
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn KB_Sleep_Wakeup_Cfg
|
||||
*
|
||||
* @brief Configure keyboard wake up mode.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void KB_Sleep_Wakeup_Cfg( void )
|
||||
{
|
||||
EXTI_InitTypeDef EXTI_InitStructure = { 0 };
|
||||
|
||||
/* Enable GPIOB clock */
|
||||
RCC_APB2PeriphClockCmd( RCC_APB2Periph_AFIO, ENABLE );
|
||||
|
||||
GPIO_EXTILineConfig( GPIO_PortSourceGPIOB, GPIO_PinSource12 );
|
||||
EXTI_InitStructure.EXTI_Line = EXTI_Line12;
|
||||
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Event;
|
||||
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
|
||||
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
|
||||
EXTI_Init( &EXTI_InitStructure );
|
||||
|
||||
GPIO_EXTILineConfig( GPIO_PortSourceGPIOB, GPIO_PinSource13 );
|
||||
EXTI_InitStructure.EXTI_Line = EXTI_Line13;
|
||||
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Event;
|
||||
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
|
||||
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
|
||||
EXTI_Init( &EXTI_InitStructure );
|
||||
|
||||
GPIO_EXTILineConfig( GPIO_PortSourceGPIOB, GPIO_PinSource14 );
|
||||
EXTI_InitStructure.EXTI_Line = EXTI_Line14;
|
||||
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Event;
|
||||
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
|
||||
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
|
||||
EXTI_Init( &EXTI_InitStructure );
|
||||
|
||||
GPIO_EXTILineConfig( GPIO_PortSourceGPIOB, GPIO_PinSource15 );
|
||||
EXTI_InitStructure.EXTI_Line = EXTI_Line15;
|
||||
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Event;
|
||||
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
|
||||
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
|
||||
EXTI_Init( &EXTI_InitStructure );
|
||||
|
||||
EXTI->INTENR |= EXTI_INTENR_MR12 | EXTI_INTENR_MR13 | EXTI_INTENR_MR14 | EXTI_INTENR_MR15;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn KB_Scan
|
||||
*
|
||||
* @brief Perform keyboard scan.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void KB_Scan( void )
|
||||
{
|
||||
static uint16_t scan_cnt = 0;
|
||||
static uint16_t scan_result = 0;
|
||||
|
||||
scan_cnt++;
|
||||
if( ( scan_cnt % 10 ) == 0 )
|
||||
{
|
||||
scan_cnt = 0;
|
||||
|
||||
/* Determine whether the two scan results are consistent */
|
||||
if( scan_result == ( GPIO_ReadInputData( GPIOB ) & 0xF000 ) )
|
||||
{
|
||||
KB_Scan_Done = 1;
|
||||
KB_Scan_Result = scan_result;
|
||||
}
|
||||
}
|
||||
else if( ( scan_cnt % 5 ) == 0 )
|
||||
{
|
||||
/* Save the first scan result */
|
||||
scan_result = ( GPIO_ReadInputData( GPIOB ) & 0xF000 );
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn KB_Scan_Handle
|
||||
*
|
||||
* @brief Handle keyboard scan data.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void KB_Scan_Handle( void )
|
||||
{
|
||||
uint8_t i, j;
|
||||
uint8_t status;
|
||||
static uint8_t key_cnt = 0x00;
|
||||
static uint8_t flag = 0x00;
|
||||
if( KB_Scan_Done )
|
||||
{
|
||||
KB_Scan_Done = 0;
|
||||
|
||||
if( KB_Scan_Result != KB_Scan_Last_Result )
|
||||
{
|
||||
for( i = 12; i < 16; i++ )
|
||||
{
|
||||
/* Determine that there is at least one key is pressed or released */
|
||||
if( ( KB_Scan_Result & ( 1 << i ) ) != ( KB_Scan_Last_Result & ( 1 << i ) ) )
|
||||
{
|
||||
if( ( KB_Scan_Result & ( 1 << i ) ) ) // Key press
|
||||
{
|
||||
if( i == 12 )
|
||||
{
|
||||
for( j = 2; j < 8; j++ )
|
||||
{
|
||||
if( KB_Data_Pack[ j ] == DEF_KEY_CHAR_W )
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if( i == 13 )
|
||||
{
|
||||
for( j = 2; j < 8; j++ )
|
||||
{
|
||||
if( KB_Data_Pack[ j ] == DEF_KEY_CHAR_A )
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if( i == 14 )
|
||||
{
|
||||
for( j = 2; j < 8; j++ )
|
||||
{
|
||||
if( KB_Data_Pack[ j ] == DEF_KEY_CHAR_S )
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if( i == 15 )
|
||||
{
|
||||
for( j = 2; j < 8; j++ )
|
||||
{
|
||||
if( KB_Data_Pack[ j ] == DEF_KEY_CHAR_D )
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( j == 8 )
|
||||
{
|
||||
KB_Data_Pack[ 5 ] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
memcpy( &KB_Data_Pack[ j ], &KB_Data_Pack[ j + 1 ], ( 8 - j - 1 ) );
|
||||
KB_Data_Pack[ 7 ] = 0;
|
||||
}
|
||||
key_cnt--;
|
||||
}
|
||||
else // Key release
|
||||
{
|
||||
if( i == 12 )
|
||||
{
|
||||
KB_Data_Pack[ 2 + key_cnt ] = DEF_KEY_CHAR_W;
|
||||
}
|
||||
else if( i == 13 )
|
||||
{
|
||||
KB_Data_Pack[ 2 + key_cnt ] = DEF_KEY_CHAR_A;
|
||||
}
|
||||
else if( i == 14 )
|
||||
{
|
||||
KB_Data_Pack[ 2 + key_cnt ] = DEF_KEY_CHAR_S;
|
||||
}
|
||||
else if( i == 15 )
|
||||
{
|
||||
KB_Data_Pack[ 2 + key_cnt ] = DEF_KEY_CHAR_D;
|
||||
}
|
||||
key_cnt++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Copy the keyboard data to the buffer of endpoint 1 and set the data uploading flag */
|
||||
KB_Scan_Last_Result = KB_Scan_Result;
|
||||
flag = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if( flag )
|
||||
{
|
||||
/* Load keyboard data to endpoint 1 */
|
||||
status = USBD_ENDPx_DataUp(ENDP1, KB_Data_Pack, DEF_ENDP_SIZE_KB);
|
||||
if( status == USB_SUCCESS )
|
||||
{
|
||||
/* Clear flag after successful loading */
|
||||
flag = 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*********************************************************************
|
||||
* @fn KB_LED_Handle
|
||||
*
|
||||
* @brief Handle keyboard lighting.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void KB_LED_Handle( void )
|
||||
{
|
||||
if( KB_LED_Cur_Status != KB_LED_Last_Status )
|
||||
{
|
||||
if( ( KB_LED_Cur_Status & 0x01 ) != ( KB_LED_Last_Status & 0x01 ) )
|
||||
{
|
||||
if( KB_LED_Cur_Status & 0x01 )
|
||||
{
|
||||
printf("Turn on the NUM LED\r\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Turn off the NUM LED\r\n");
|
||||
}
|
||||
}
|
||||
if( ( KB_LED_Cur_Status & 0x02 ) != ( KB_LED_Last_Status & 0x02 ) )
|
||||
{
|
||||
if( KB_LED_Cur_Status & 0x02 )
|
||||
{
|
||||
printf("Turn on the CAPS LED\r\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Turn off the CAPS LED\r\n");
|
||||
}
|
||||
}
|
||||
if( ( KB_LED_Cur_Status & 0x04 ) != ( KB_LED_Last_Status & 0x04 ) )
|
||||
{
|
||||
if( KB_LED_Cur_Status & 0x04 )
|
||||
{
|
||||
printf("Turn on the SCROLL LED\r\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Turn off the SCROLL LED\r\n");
|
||||
}
|
||||
}
|
||||
KB_LED_Last_Status = KB_LED_Cur_Status;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*********************************************************************
|
||||
* @fn MS_Scan_Init
|
||||
*
|
||||
* @brief Initialize IO for mouse scan.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void MS_Scan_Init( void )
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure = { 0 };
|
||||
|
||||
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA, ENABLE );
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_Init( GPIOA, &GPIO_InitStructure );
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn MS_Sleep_Wakeup_Cfg
|
||||
*
|
||||
* @brief Configure mouse wake up mode.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void MS_Sleep_Wakeup_Cfg( void )
|
||||
{
|
||||
EXTI_InitTypeDef EXTI_InitStructure = { 0 };
|
||||
|
||||
RCC_APB2PeriphClockCmd( RCC_APB2Periph_AFIO, ENABLE );
|
||||
|
||||
GPIO_EXTILineConfig( GPIO_PortSourceGPIOA, GPIO_PinSource4 );
|
||||
EXTI_InitStructure.EXTI_Line = EXTI_Line4;
|
||||
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Event;
|
||||
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
|
||||
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
|
||||
EXTI_Init( &EXTI_InitStructure );
|
||||
|
||||
GPIO_EXTILineConfig( GPIO_PortSourceGPIOA, GPIO_PinSource5 );
|
||||
EXTI_InitStructure.EXTI_Line = EXTI_Line5;
|
||||
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Event;
|
||||
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
|
||||
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
|
||||
EXTI_Init( &EXTI_InitStructure );
|
||||
|
||||
GPIO_EXTILineConfig( GPIO_PortSourceGPIOA, GPIO_PinSource6 );
|
||||
EXTI_InitStructure.EXTI_Line = EXTI_Line6;
|
||||
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Event;
|
||||
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
|
||||
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
|
||||
EXTI_Init( &EXTI_InitStructure );
|
||||
|
||||
GPIO_EXTILineConfig( GPIO_PortSourceGPIOA, GPIO_PinSource7 );
|
||||
EXTI_InitStructure.EXTI_Line = EXTI_Line7;
|
||||
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Event;
|
||||
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
|
||||
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
|
||||
EXTI_Init( &EXTI_InitStructure );
|
||||
|
||||
EXTI->INTENR |= EXTI_INTENR_MR4 | EXTI_INTENR_MR5 | EXTI_INTENR_MR6 | EXTI_INTENR_MR7;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn MS_Scan
|
||||
*
|
||||
* @brief Perform mouse scan.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void MS_Scan( void )
|
||||
{
|
||||
static uint16_t scan_cnt = 0;
|
||||
static uint16_t scan_result = 0;
|
||||
|
||||
scan_cnt++;
|
||||
if( scan_cnt >= 2 )
|
||||
{
|
||||
scan_cnt = 0;
|
||||
|
||||
/* Determine whether the two scan results are consistent */
|
||||
if( scan_result == ( GPIO_ReadInputData( GPIOA ) & 0x00F0 ) )
|
||||
{
|
||||
MS_Scan_Result = scan_result;
|
||||
MS_Scan_Done = 1;
|
||||
}
|
||||
}
|
||||
else if( scan_cnt >= 1 )
|
||||
{
|
||||
/* Save the first scan result */
|
||||
scan_result = ( GPIO_ReadInputData( GPIOA ) & 0x00F0 );
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn MS_Scan_Handle
|
||||
*
|
||||
* @brief Handle mouse scan data.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void MS_Scan_Handle( void )
|
||||
{
|
||||
uint8_t i;
|
||||
uint8_t status;
|
||||
static uint8_t flag = 0x00;
|
||||
|
||||
if( MS_Scan_Done )
|
||||
{
|
||||
MS_Scan_Done = 0;
|
||||
|
||||
memset( MS_Data_Pack, 0x00, DEF_ENDP_SIZE_MS );
|
||||
|
||||
for( i = 4; i < 8; i++ )
|
||||
{
|
||||
/* Determine that the mouse is moved */
|
||||
if( ( MS_Scan_Result & ( 1 << i ) ) == 0 )
|
||||
{
|
||||
if( i == 4 )
|
||||
{
|
||||
MS_Data_Pack[ 1 ] += 0x02;
|
||||
}
|
||||
else if( i == 5 )
|
||||
{
|
||||
MS_Data_Pack[ 1 ] += 0xFE;
|
||||
}
|
||||
else if( i == 6 )
|
||||
{
|
||||
MS_Data_Pack[ 2 ] += 0x02;
|
||||
}
|
||||
else if( i == 7 )
|
||||
{
|
||||
MS_Data_Pack[ 2 ] += 0xFE;
|
||||
}
|
||||
|
||||
/* Set the data uploading flag */
|
||||
flag = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
if( flag )
|
||||
{
|
||||
/* Load mouse data to endpoint 2 */
|
||||
status = USBD_ENDPx_DataUp(ENDP2, MS_Data_Pack, DEF_ENDP_SIZE_MS);
|
||||
if( status == USB_SUCCESS )
|
||||
{
|
||||
/* Clear flag after successful loading */
|
||||
flag = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn MCU_Sleep_Wakeup_Operate
|
||||
*
|
||||
* @brief Perform sleep operation
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void MCU_Sleep_Wakeup_Operate( void )
|
||||
{
|
||||
EXTI_ClearFlag( EXTI_Line12 | EXTI_Line13 | EXTI_Line14 | EXTI_Line15 );
|
||||
EXTI_ClearFlag( EXTI_Line4 | EXTI_Line5 | EXTI_Line6 | EXTI_Line7 );
|
||||
|
||||
// printf( "Sleep\r\n" );
|
||||
__WFE( );
|
||||
|
||||
if( EXTI_GetFlagStatus( EXTI_Line12 | EXTI_Line13 | EXTI_Line14 | EXTI_Line15 ) != RESET )
|
||||
{
|
||||
EXTI_ClearFlag( EXTI_Line12 | EXTI_Line13 | EXTI_Line14 | EXTI_Line15 );
|
||||
Resume(RESUME_INTERNAL);
|
||||
}
|
||||
else if( EXTI_GetFlagStatus( EXTI_Line4 | EXTI_Line5 | EXTI_Line6 | EXTI_Line7 ) != RESET )
|
||||
{
|
||||
EXTI_ClearFlag( EXTI_Line4 | EXTI_Line5 | EXTI_Line6 | EXTI_Line7 );
|
||||
Resume(RESUME_INTERNAL);
|
||||
}
|
||||
// printf( "Wake\r\n" );
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user