diff --git a/.gitignore b/.gitignore index 30f4015..f38638b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,29 @@ -# Untracked files in MPLABX projects -/**/build/* -/**/nbproject/* -!/**/nbproject/*.xml -/**/dist/* -/**/.generated_files/* +.generated_files +build +dist +/*/nbproject/*.mk +/*/nbproject/*.bash +/*/nbproject/*.properties +/*/nbproject/private + +*ctu-file-list +*.ctu-info + +# Studio Folders +/*/[Dd]ebug/ +/*/[Rr]elease/ +/*/.vs/ + +#Build Artefacts +*.o +*.d +*.eep +*.elf +*.hex +*.lst +*.map +*.srec +/*/*.yml +/*/__pycache__ + + diff --git a/.main-meta/main.json b/.main-meta/main.json index 36026c3..7cd17b1 100644 --- a/.main-meta/main.json +++ b/.main-meta/main.json @@ -4,8 +4,8 @@ "content": { "metaDataVersion": "1.3.0", "name": "com.microchip.mcu8.mplabx.project.avr64du32-cnano-usb-vendor-mplab-mcc", - "version": " ", - "displayName": "", + "version": "1.0.0", + "displayName": "AVR64DU32 USB Vendor Class Example", "projectName": "avr64du32-cnano-usb-vendor-mplab-mcc", "shortDescription": "This code example demonstrates using the USB Vendor class to transfer data using the USB 2.0 device peripheral on the AVR DU family of MCUs.", "ide": { @@ -19,12 +19,12 @@ } ], "dfp": { - "name": "", - "semverRange": "" + "name": "AVR-Dx_DFP", + "semverRange": "^2.4.286" }, "configurator": { - "name": "", - "semverRange": "" + "name": "MCC", + "semverRange": ">=5.7.1" }, "device": { "metaDataVersion": "1.0.0", @@ -37,8 +37,24 @@ } }, "author": "Rebekka Alve", - "peripherals": [], - "keywords": [], + "peripherals": [ + "USB", + "USB Device Class", + "RTC", + "AC", + "VREF" + ], + "keywords": [ + "USB", + "USB-C", + "USB Protocol", + "USB 2.0", + "USB Device Class", + "Communication", + "MCC", + "Melody", + "Vendor Class" + ], "additionalData": { "longDescription": { "metaDataVersion": "1.0.0", diff --git a/README.md b/README.md index 8119718..8bb8f85 100644 --- a/README.md +++ b/README.md @@ -8,44 +8,114 @@ -# Update the title for avr64du32-cnano-usb-vendor-mplab-mcc here - - +# USB Vendor Data Transfer Demo +This example demonstrates how the Vendor class on the AVR® DU microcontroller (MCU), paired with the AVR64DU32 Curiosity Nano Board, enables data transfer to and from a PC through interrupt, bulk, and isochronous transfers. ## Related Documentation +- [AVR® DU Family Product Page](https://www.microchip.com/en-us/products/microcontrollers-and-microprocessors/8-bit-mcus/avr-mcus/avr-du?utm_source=GitHub&utm_medium=TextLink&utm_campaign=MCU8_AVR-DU&utm_content=avr64du32-cnano-usb-vendor-mplab-mcc-github&utm_bu=MCU08) +- [AVR64DU32 Chip](https://www.microchip.com/en-us/product/AVR64DU32?utm_source=GitHub&utm_medium=TextLink&utm_campaign=MCU8_AVR-DU&utm_content=avr64du32-cnano-usb-vendor-mplab-mcc-github&utm_bu=MCU08) - +### USB Specifications +- [USB 2.0 Specification](https://www.usb.org/document-library/usb-20-specification) ## Software Used - - -- MPLAB® X IDE 6.20.0 or newer [(MPLAB® X IDE 6.20)](https://www.microchip.com/en-us/development-tools-tools-and-software/mplab-x-ide) -- MPLAB® XC8 2.46.0 or newer compiler [(MPLAB® XC8 2.46)](https://www.microchip.com/en-us/tools-resources/develop/mplab-xc-compilers/xc8) +- [MPLAB® X IDE 6.20](https://www.microchip.com/en-us/tools-resources/develop/mplab-x-ide?utm_source=GitHub&utm_medium=TextLink&utm_campaign=MCU8_AVR-DU&utm_content=avr64du32-cnano-usb-vendor-mplab-mcc-github&utm_bu=MCU08) or newer +- [MPLAB® XC8 Compiler 2.46](https://www.microchip.com/en-us/tools-resources/develop/mplab-xc-compilers?utm_source=GitHub&utm_medium=TextLink&utm_campaign=MCU8_AVR-DU&utm_content=avr64du32-cnano-usb-vendor-mplab-mcc-github&utm_bu=MCU08) or newer +- [MPLAB® Code Configurator (MCC) 5.5.0](https://www.microchip.com/en-us/tools-resources/configure/mplab-code-configurator?utm_source=GitHub&utm_medium=TextLink&utm_campaign=MCU8_AVR-DU&utm_content=avr64du32-cnano-usb-vendor-mplab-mcc-github&utm_bu=MCU08) or newer ## Hardware Used - +- [AVR64DU32 Curiosity Nano (EV59F82A)](https://www.microchip.com/en-us/development-tool/EV59F82A?utm_source=GitHub&utm_medium=TextLink&utm_campaign=MCU8_AVR-DU&utm_content=avr64du32-cnano-usb-vendor-mplab-mcc-github&utm_bu=MCU08) + ## Setup - +### Physical Setup + +The AVR DU Curiosity Nano development board has two USB-C ports +1. The Debugger port programs the device with the code example +2. After programming, the cable connected to the Debugger may be disconnected, but it will not affect the example if it remains +3. The Target port must be connected to the PC in order to transfer data between the decive and the PC + +### MCC Setup + +This section shows how the example is set up using MPLAB® Code Configurator (MCC). + +### USB Device Stack Setup + +#### USB General Settings +Set the class configuration to Vendor, so that the AVR DU will use the USB vendor protocol to communicate with the PC. +

+ +#### USB Device Descriptors +The Device Descriptors can be left as default. +

+ +#### USB Interfaces +For this example, Interface 0 with Alternates 0-4 is required, click "Add Interface" to add them. Alternate 0 will remain as it is. +

+ +#### USB Vendor Endpoints +We must set up separate endpoints for the interrupt, bulk, and isochronous transfers. To configure the endpoints, click "Add Endpoint" and select the correct configurations corresponding to each Alternate, 1 to 4. +

+ +#### USB0 Power Settings +By default, the target voltage on the AVR64DU32 Curiosity Nano is 3.3V and VUSB is connected to 3.3V using the provided jumper. However, if 5V operation is preferred, the jumper must be removed and the internal USB voltage regulator must be enabled. +

+ +### Device Clock Setup +This example is configured to run on 24 MHz under *System Firmware -> CLKCTRL*. The minimum oscillator frequency available for USB on the AVR DU is 12 MHz. +

+ +### USB Voltage Detection Setup +To ensure that the USB peripheral only tries to attach to the bus when the Curiosity Nano is connected to the PC, the Analog Comparator will periodically check if the voltage is within the acceptable range for VBUS. + +#### Voltage Reference Setup (VREF) +The Voltage Reference is set to 2.048V. +

+ +#### Analog Comparator Setup (AC) + +##### Analog Comparator Hardware Settings +The Analog Comparator must be enabled by toggling Enable under Hardware Settings. +To measure the correct values, the positive input must be connected to AINP4, while the negative input is set to the DAC Reference. +The DACREF register must be set to a value that can detect the correct voltage level at a minimum of 0.4V. The reference voltage 0.48V (DACREF = 60) used in this project is a little higher to ensure a stable connection. Refer to the [AVR64DU32 Curiosity Nano User Guide](https://ww1.microchip.com/downloads/aemDocuments/documents/MCU08/ProductDocuments/UserGuides/AVR64DU32-Curiosity-Nano-UserGuide-DS50003671.pdf) to find the values for the voltage divider on Pin PC3. + +

+ +#### Real-Time Counter Setup (RTC) + +##### Real-Time Counter Periodic Interrupt Control Settings +The Periodic Interrupt Timer (PIT) is enabled for this example, and the period selection is set to RTC Clock Cycles 1024. This value must be changed according to the clock source selection. +The PIT's Interrupt Flag is also enabled to allow for an interrupt routine. +

+ +### Interrupt Manager +Global interrupts must be enabled for the RTC and the USB communication to work. +

+ + +### Device Pin-out Setup +One pin is used for this example: VBUS on PC3 set as input with "Digital Input Buffer disabled". This can be verified under *System Firmware -> Pins*. +

+

## Operation - +This example can be tested by following these steps: + +1. Generate the MCC code and replace the generated main.c file with the given main.c from the source code +2. Upload the c-code by connecting the Debugger plug on the Curiosity Nano Board (cnano) to the PC +3. Connect the PC to the Target plug on the cnano and install the libusbK driver as shown in [Driver Installation](#driver-installation) +4. Run the python script ``vendor_endpoints.py`` from the given python_test code and see the data transfer + +## Driver Installation +A USB driver is required to enumerate vendor devices. The LibusbK driver is recommended to handle isochronous transfers, it can be downloaded from here: https://zadig.akeo.ie/ (choose libusbK after downloading). +Make sure to select the correct device from the drop-down menu, with VID = 0X04D8 and PID = 0X0B0A. +If the device does not show up, select *List all devices->Options*. +

## Summary - +This example has shown how the USB Vencor class can be used on an AVR DU to transfer data to and from a PC, using interrupt, bulk and isocronous transfer. \ No newline at end of file diff --git a/avr64du32-cnano-usb-vendor-mplab-mcc.X/Makefile b/avr64du32-cnano-usb-vendor-mplab-mcc.X/Makefile new file mode 100644 index 0000000..fca8e2c --- /dev/null +++ b/avr64du32-cnano-usb-vendor-mplab-mcc.X/Makefile @@ -0,0 +1,113 @@ +# +# There exist several targets which are by default empty and which can be +# used for execution of your targets. These targets are usually executed +# before and after some main targets. They are: +# +# .build-pre: called before 'build' target +# .build-post: called after 'build' target +# .clean-pre: called before 'clean' target +# .clean-post: called after 'clean' target +# .clobber-pre: called before 'clobber' target +# .clobber-post: called after 'clobber' target +# .all-pre: called before 'all' target +# .all-post: called after 'all' target +# .help-pre: called before 'help' target +# .help-post: called after 'help' target +# +# Targets beginning with '.' are not intended to be called on their own. +# +# Main targets can be executed directly, and they are: +# +# build build a specific configuration +# clean remove built files from a configuration +# clobber remove all built files +# all build all configurations +# help print help mesage +# +# Targets .build-impl, .clean-impl, .clobber-impl, .all-impl, and +# .help-impl are implemented in nbproject/makefile-impl.mk. +# +# Available make variables: +# +# CND_BASEDIR base directory for relative paths +# CND_DISTDIR default top distribution directory (build artifacts) +# CND_BUILDDIR default top build directory (object files, ...) +# CONF name of current configuration +# CND_ARTIFACT_DIR_${CONF} directory of build artifact (current configuration) +# CND_ARTIFACT_NAME_${CONF} name of build artifact (current configuration) +# CND_ARTIFACT_PATH_${CONF} path to build artifact (current configuration) +# CND_PACKAGE_DIR_${CONF} directory of package (current configuration) +# CND_PACKAGE_NAME_${CONF} name of package (current configuration) +# CND_PACKAGE_PATH_${CONF} path to package (current configuration) +# +# NOCDDL + + +# Environment +MKDIR=mkdir +CP=cp +CCADMIN=CCadmin +RANLIB=ranlib + + +# build +build: .build-post + +.build-pre: +# Add your pre 'build' code here... + +.build-post: .build-impl +# Add your post 'build' code here... + + +# clean +clean: .clean-post + +.clean-pre: +# Add your pre 'clean' code here... +# WARNING: the IDE does not call this target since it takes a long time to +# simply run make. Instead, the IDE removes the configuration directories +# under build and dist directly without calling make. +# This target is left here so people can do a clean when running a clean +# outside the IDE. + +.clean-post: .clean-impl +# Add your post 'clean' code here... + + +# clobber +clobber: .clobber-post + +.clobber-pre: +# Add your pre 'clobber' code here... + +.clobber-post: .clobber-impl +# Add your post 'clobber' code here... + + +# all +all: .all-post + +.all-pre: +# Add your pre 'all' code here... + +.all-post: .all-impl +# Add your post 'all' code here... + + +# help +help: .help-post + +.help-pre: +# Add your pre 'help' code here... + +.help-post: .help-impl +# Add your post 'help' code here... + + + +# include project implementation makefile +include nbproject/Makefile-impl.mk + +# include project make variables +include nbproject/Makefile-variables.mk diff --git a/avr64du32-cnano-usb-vendor-mplab-mcc.X/avr64du32-cnano-usb-vendor-mplab-mcc.mc3 b/avr64du32-cnano-usb-vendor-mplab-mcc.X/avr64du32-cnano-usb-vendor-mplab-mcc.mc3 new file mode 100644 index 0000000..18ffc9a --- /dev/null +++ b/avr64du32-cnano-usb-vendor-mplab-mcc.X/avr64du32-cnano-usb-vendor-mplab-mcc.mc3 @@ -0,0 +1,416 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + AC0 + class com.microchip.mcc.melody.hw.module.HardwareModule + + + Application Builder + class com.microchip.mcc.melody.module.FrameworkModule + + + CLKCTRL + class com.microchip.mcc.melody.hw.module.HardwareModule + + + CPUINT + class com.microchip.mcc.melody.hw.module.HardwareModule + + + Configuration Bits + class com.microchip.mcc.melody.hw.module.HardwareModule + + + MAIN MANAGER + class com.microchip.mcc.melody.hw.module.HardwareModule + + + Pin Manager + class com.microchip.mcc.melody.hw.module.HardwareModule + + + RTC + class com.microchip.mcc.melody.hw.module.HardwareModule + + + SYSCFG + class com.microchip.mcc.melody.hw.module.HardwareModule + + + USB0 + class com.microchip.mcc.melody.hw.module.HardwareModule + + + VREF + class com.microchip.mcc.melody.hw.module.HardwareModule + + + meta + class com.microchip.mcc.melody.hw.module.HardwareModule + + + module0 + class com.microchip.mcc.melody.script.module.ScriptModule + + + module1 + class com.microchip.mcc.melody.script.module.ScriptModule + + + module15 + class com.microchip.mcc.melody.script.module.ScriptModule + + + module2 + class com.microchip.mcc.melody.script.module.ScriptModule + + + module28 + class com.microchip.mcc.melody.script.module.ScriptModule + + + module3 + class com.microchip.mcc.melody.script.module.ScriptModule + + + module31 + class com.microchip.mcc.melody.script.module.ScriptModule + + + module4 + class com.microchip.mcc.melody.script.module.ScriptModule + + + module41 + class com.microchip.mcc.melody.script.module.ScriptModule + + + module5 + class com.microchip.mcc.melody.script.module.ScriptModule + + + module6 + class com.microchip.mcc.melody.script.module.ScriptModule + + + module8 + class com.microchip.mcc.melody.script.module.ScriptModule + + + + + + + + + {"mccDevice":{"loc":"0 0","pos":"0 0"},"systemGroup":{"loc":"469.5 -333.5863037398476","pos":"469.5 -333.5863037398476"},"module5":{"loc":"195.5 69.5","pos":"195.5 69.5"},"module8":{"loc":"172.00000000000003 0","pos":"172.00000000000003 0"},"module28":{"loc":"329.5 -46","pos":"329.5 -46"},"module15":{"loc":"329.5 -11.5","pos":"329.5 -11.5"},"module31":{"loc":"489.5 20.5","pos":"489.5 20.5"},"module41":{"loc":"-0.5 -83.48984375","pos":"-0.5 -83.48984375"}} + + + + {"userAddedModules":["module5","module4","module6","module8","module28","module15","module1","module0","module3","module2","module31","module41"],"version":"CURRENT","modules":{"module5":{"scriptId":"@mchp-mcc/scf-avr8-syscfg-v1","imports":{"device_meta":{"interfaceId":{"name":"device-meta","version":"^1.0.0"},"handle":{"providerId":"mccDevice","exportId":"meta"}},"sys_init_basic_interface":{"interfaceId":{"name":"sys-init-basic-interface","version":"^1"},"handle":{"providerId":"module1","exportId":"sys_init_basic_interface"}},"scf_avr8_syscfg_v1":{"interfaceId":{"name":"scf-avr8-syscfg-v1","version":"1.0.0"},"handle":{"providerId":"mccDevice","exportId":"SYSCFG"}}},"framewSpecificState":{"userEditedImports":[]},"payload":{}},"module4":{"scriptId":"@mchp-mcc/scf-avr8-interrupt-v1","imports":{"device_meta":{"interfaceId":{"name":"device-meta","version":"1.0.0"},"handle":{"providerId":"mccDevice","exportId":"meta"}},"scf_avr8_interrupt_v1":{"interfaceId":{"name":"scf-avr8-interrupt-v1","version":"1.0.0"},"handle":{"providerId":"mccDevice","exportId":"CPUINT"}},"initializer_system":{"interfaceId":{"name":"initializer-system","version":"^0"},"handle":{"providerId":"module1","exportId":"initializer_system"}}},"framewSpecificState":{"userEditedImports":[]},"payload":{"main":{"interrupt":{"iSreg":true}}}},"module6":{"scriptId":"@mchp-mcc/scf-avr8-clkctrl-v3","imports":{"sys_init_basic_interface":{"interfaceId":{"name":"sys-init-basic-interface","version":"^1"},"handle":{"providerId":"module1","exportId":"sys_init_basic_interface"}},"pins_interface":{"interfaceId":{"name":"pins-interface","version":"^1"},"handle":{"providerId":"module3","exportId":"pins-interface"}},"scf_avr8_clkctrl_v3":{"interfaceId":{"name":"scf-avr8-clkctrl-v3","version":"^1.0.0"},"handle":{"providerId":"mccDevice","exportId":"CLKCTRL"}},"interrupt_standard":{"interfaceId":{"name":"interrupt-standard","version":"^1"},"handle":{"providerId":"module4","exportId":"interrupt"}},"device_meta":{"interfaceId":{"name":"device-meta","version":"1.0.0"},"handle":{"providerId":"mccDevice","exportId":"meta"}},"configbits_basic_interface":{"interfaceId":{"name":"configbits-basic-interface","version":"^1"},"handle":{"providerId":"module1","exportId":"configbits_basic_interface"}},"config_device":{"interfaceId":{"name":"config-device","version":"^1"},"handle":{"providerId":"module1","exportId":"config_device"}}},"framewSpecificState":{"userEditedImports":[]},"payload":{"main":{"hardware":{"frqselOschfctrla":"24 MHz system clock"}}}},"module8":{"scriptId":"@mchp-mcc/scf-avr8-usb-v1","imports":{"pins_interface":{"interfaceId":{"name":"pins-interface","version":"^1.*"},"handle":{"providerId":"module3","exportId":"pins-interface"}},"interrupt_standard":{"interfaceId":{"name":"interrupt-standard","version":"^1.*"},"handle":{"providerId":"module4","exportId":"interrupt"}},"device_meta":{"interfaceId":{"name":"device-meta","version":"1.0.0"},"handle":{"providerId":"mccDevice","exportId":"meta"}},"osc_clocks":{"interfaceId":{"name":"osc-clocks","version":"^0.*"},"handle":{"providerId":"module6","exportId":"osc_clocks"}},"syscfg_interface":{"interfaceId":{"name":"syscfg-usb-interface","version":"^1.*"},"handle":{"providerId":"module5","exportId":"syscfg_usb_interface"}},"scf_avr8_usb_v1":{"interfaceId":{"name":"scf-avr8-usb-v1","version":"1.0.0"},"handle":{"providerId":"mccDevice","exportId":"USB0"}},"initializer_system":{"interfaceId":{"name":"initializer-system","version":"^0.*"},"handle":{"providerId":"module1","exportId":"initializer_system"}}},"framewSpecificState":{"userEditedImports":[]},"payload":{}},"module28":{"scriptId":"@mchp-mcc/scf-avr8-vref-v1","imports":{"device_meta":{"interfaceId":{"name":"device-meta","version":"^1"},"handle":{"providerId":"mccDevice","exportId":"meta"}},"scf_avr8_vref_v1":{"interfaceId":{"name":"scf-avr8-vref-v1","version":"^1.0.0"},"handle":{"providerId":"mccDevice","exportId":"VREF"}},"initializer_system":{"interfaceId":{"name":"initializer-system","version":"^0"},"handle":{"providerId":"module1","exportId":"initializer_system"}}},"framewSpecificState":{"userEditedImports":[]},"payload":{"main":{"hardware":{"refselAcref":"Internal 2.048V reference"}}}},"module15":{"scriptId":"@mchp-mcc/scf-avr8-ac-v1","imports":{"pins_interface":{"interfaceId":{"name":"pins-interface","version":"^1"},"handle":{"providerId":"module3","exportId":"pins-interface"}},"VREF":{"interfaceId":{"name":"vref-general-parameters","version":"^0.1.0"},"handle":{"providerId":"module28","exportId":"VREF"}},"interrupt_standard":{"interfaceId":{"name":"interrupt-standard","version":"^1"},"handle":{"providerId":"module4","exportId":"interrupt"}},"device_meta":{"interfaceId":{"name":"device-meta","version":"^1.0.0"},"handle":{"providerId":"mccDevice","exportId":"meta"}},"scf_avr8_ac_v1":{"interfaceId":{"name":"scf-avr8-ac-v1","version":"^1.0.0"},"handle":{"providerId":"mccDevice","exportId":"AC0"}},"initializer_system":{"interfaceId":{"name":"initializer-system","version":"^0"},"handle":{"providerId":"module1","exportId":"initializer_system"}}},"framewSpecificState":{"userEditedImports":[]},"payload":{"main":{"hardware":{"muxposMuxctrl":"Positive Pin 4","muxnegMuxctrl":"DAC Reference","requestedVoltage":0.48}}}},"module1":{"scriptId":"@mchp-mcc/avr8-configuration-bits-v1","imports":{"device_meta":{"interfaceId":{"name":"device-meta","version":"1.0.0"},"handle":{"providerId":"mccDevice","exportId":"meta"}},"initializer_main":{"interfaceId":{"name":"initializer-main","version":"^0.*"},"handle":{"providerId":"module0","exportId":"initializer_main"}},"avr8_configuration_bits_v1":{"interfaceId":{"name":"avr8-configuration-bits-v1","version":"1.0.0"},"handle":{"providerId":"mccDevice","exportId":"Configuration Bits"}}},"framewSpecificState":{"userEditedImports":[]},"payload":{}},"module0":{"scriptId":"@mchp-mcc/main-manager","imports":{"main":{"interfaceId":{"name":"main-manager","version":"^1.*"},"handle":{"providerId":"mccDevice","exportId":"MAIN MANAGER"}}},"framewSpecificState":{"userEditedImports":[]},"payload":{}},"module3":{"scriptId":"@mchp-mcc/pin-content-processor","imports":{"device-meta":{"interfaceId":{"name":"device-meta","version":"1.0.0"},"handle":{"providerId":"mccDevice","exportId":"meta"}},"pin-architecture":{"interfaceId":{"name":"pin-architecture","version":"1.0.0"},"handle":{"providerId":"module2","exportId":"pin-architecture"}}},"framewSpecificState":{"userEditedImports":[]},"payload":{}},"module2":{"scriptId":"@mchp-mcc/avr8-pin-manager","imports":{"avr8-pin-manager":{"interfaceId":{"name":"avr8-pin-manager","version":"1.0.0"},"handle":{"providerId":"mccDevice","exportId":"Pin Manager"}},"initializer_system":{"interfaceId":{"name":"initializer-system","version":"^0.*"},"handle":{"providerId":"module1","exportId":"initializer_system"}}},"framewSpecificState":{"userEditedImports":[]},"payload":{}},"module31":{"scriptId":"@mchp-mcc/scf-avr8-rtc-v1","imports":{"interrupt_standard":{"interfaceId":{"name":"interrupt-standard","version":"^1"},"handle":{"providerId":"module4","exportId":"interrupt"}},"device_meta":{"interfaceId":{"name":"device-meta","version":"^1"},"handle":{"providerId":"mccDevice","exportId":"meta"}},"scf_avr8_rtc_v1":{"interfaceId":{"name":"scf-avr8-rtc-v1","version":"^1"},"handle":{"providerId":"mccDevice","exportId":"RTC"}},"initializer_system":{"interfaceId":{"name":"initializer-system","version":"^0"},"handle":{"providerId":"module1","exportId":"initializer_system"}}},"framewSpecificState":{"userEditedImports":[]},"payload":{"main":{"periodicIntTmr":{"pitenPitctrla":true,"periodPitctrla":"RTC Clock Cycles 1024"},"interrupt":{"ovf":false,"pit":true}}}},"module41":{"scriptId":"@mchp-mcc/usb-device-stack","imports":{"usb_interface":{"interfaceId":{"name":"usb-interface","version":"^1.*"},"handle":{"providerId":"module8","exportId":"usb_interface"}},"initializer_system":{"interfaceId":{"name":"initializer-system","version":"^0.*"},"handle":{"providerId":"module1","exportId":"initializer_system"}},"project_properties":{"interfaceId":{"name":"project-properties","version":"^1.*"},"handle":{"providerId":"com.microchip.mcc.melody.adapter.ProjectConfigurationAdapter","exportId":"project-properties"}}},"framewSpecificState":{"userEditedImports":[]},"payload":{"configs":{"interfaceTable":[{"intfKey":"intfGrp0","index":0.0,"rowId":0.0,"name":"Interface0Alternate0","interface":0.0,"altInterface":0.0},{"intfKey":"intfGrp1","index":1.0,"rowId":1.0,"name":"Interface0Alternate1","interface":0.0,"altInterface":1.0},{"intfKey":"intfGrp2","index":2.0,"rowId":2.0,"name":"Interface0Alternate2","interface":0.0,"altInterface":2.0},{"intfKey":"intfGrp3","index":3.0,"rowId":3.0,"name":"Interface0Alternate3","interface":0.0,"altInterface":3.0},{"intfKey":"intfGrp4","index":4.0,"rowId":4.0,"name":"Interface0Alternate4","interface":0.0,"altInterface":4.0}],"interfaceCount":5.0,"interfaces":[{"intfKey":"intfGrp0","index":0.0,"rowId":0.0,"name":"Interface0Alternate0","interface":0.0,"altInterface":0.0,"endpointTable":[],"endpointCount":0.0,"class":"Vendor"},{"intfKey":"intfGrp1","index":1.0,"rowId":1.0,"name":"Interface0Alternate1","interface":0.0,"altInterface":1.0,"endpointTable":[{"endptNum":1.0,"direction":"IN","transferType":"Interrupt","syncType":"None","usageType":"None","packetSize":"64","interval":1.0,"mpEnable":false,"autoZlp":false,"rowId":"intfgrp1endpt0"},{"endptNum":1.0,"direction":"OUT","transferType":"Interrupt","syncType":"None","usageType":"None","packetSize":"64","interval":1.0,"mpEnable":false,"autoZlp":false,"rowId":"intfgrp1endpt1"},{"endptNum":2.0,"direction":"IN","transferType":"Bulk","syncType":"None","usageType":"None","packetSize":"64","interval":0.0,"mpEnable":false,"autoZlp":false,"rowId":"intfgrp1endpt2"},{"endptNum":2.0,"direction":"OUT","transferType":"Bulk","syncType":"None","usageType":"None","packetSize":"64","interval":0.0,"mpEnable":false,"autoZlp":false,"rowId":"intfgrp1endpt3"}],"endpointCount":4.0,"class":"Vendor"},{"intfKey":"intfGrp2","index":2.0,"rowId":2.0,"name":"Interface0Alternate2","interface":0.0,"altInterface":2.0,"endpointTable":[{"endptNum":3.0,"direction":"IN","transferType":"Isochronous","syncType":"Asynchronous","usageType":"Data","packetSize":"512","interval":1.0,"mpEnable":false,"autoZlp":false,"rowId":"intfgrp2endpt0"},{"endptNum":3.0,"direction":"OUT","transferType":"Isochronous","syncType":"Asynchronous","usageType":"Data","packetSize":"512","interval":1.0,"mpEnable":false,"autoZlp":false,"rowId":"intfgrp2endpt1"}],"endpointCount":2.0,"class":"Vendor"},{"intfKey":"intfGrp3","index":3.0,"rowId":3.0,"name":"Interface0Alternate3","interface":0.0,"altInterface":3.0,"endpointTable":[{"endptNum":4.0,"direction":"OUT","transferType":"Isochronous","syncType":"Asynchronous","usageType":"Data","packetSize":"1023","interval":1.0,"mpEnable":false,"autoZlp":false,"rowId":"intfgrp3endpt0"}],"endpointCount":1.0,"class":"Vendor"},{"intfKey":"intfGrp4","index":4.0,"rowId":4.0,"name":"Interface0Alternate4","interface":0.0,"altInterface":4.0,"endpointTable":[{"endptNum":4.0,"direction":"IN","transferType":"Isochronous","syncType":"Asynchronous","usageType":"Data","packetSize":"1023","interval":1.0,"mpEnable":false,"autoZlp":false,"rowId":"intfgrp4endpt0"}],"endpointCount":1.0,"class":"Vendor"}]}}}},"content":{"@mchp-mcc/avr-8bit":"4.10.0","@mchp-mcc/scf-avr8-usb-v1":"1.0.0","@mchp-mcc/pin-content-processor":"3.8.0","@mchp-mcc/scf-avr8-syscfg-v1":"1.0.0","@mchp-mcc/avr8-pin-manager":"4.6.0","@mchp-mcc/scf-avr8-ac-v1":"4.1.1","@mchp-mcc/scf-avr8-vref-v1":"4.0.3","@mchp-mcc/scf-avr8-clkctrl-v3":"2.0.9","@mchp-mcc/scf-avr8-interrupt-v1":"5.0.12","@mchp-mcc/main-manager":"3.1.1","@mchp-mcc/usb-device-stack":"1.0.1","@mchp-mcc/scf-avr8-rtc-v1":"4.2.5","@mchp-mcc/avr8-configuration-bits-v1":"4.2.14"}} + + + + + main.c + ddff76d1c9effa71290b8afe7ef0bb9d7ffbf20e2e27d066d10d0fad342e0092 + + + mcc_generated_files\ac\ac0.h + cd0ef49419e9d21b1933bf3688ffbc1798b39dc92b7dcdcc01ffe40e2a136625 + + + mcc_generated_files\ac\src\ac0.c + c0eb72076f095833014e665f328777f3098b846cb1bde165fb3b044760db02d1 + + + mcc_generated_files\system\ccp.h + 00d4c7f49db8510d0ad35d5b65b82db98d0da655c1ea8e81b657e00f49f2640e + + + mcc_generated_files\system\clock.h + cea3203a5dedac02e4b1e0939a8afdf212c33e67790ca1011c171af898c2026c + + + mcc_generated_files\system\config_bits.h + cfb3dfe72760dc2066638db643962b2a7db39169cfda29327dcb4d3ec4a26be3 + + + mcc_generated_files\system\interrupt.h + 49902a470e198f90d0ea9db752f6313c7074811e1a4da98a4d1e8572db7378f5 + + + mcc_generated_files\system\pins.h + 120f5185997e5fe83c899ee5bbd4fefbb3c4332bd7157cb0a12c6766782221fc + + + mcc_generated_files\system\port.h + 216dd5007dd33ff76d8915f555ef2d9b8da82077aff425d6fec39f96780d5640 + + + mcc_generated_files\system\protected_io.h + 72f5b206c649b31773ab739c0828b1eb6f88d99a27e0fc63f6a9f4119e632370 + + + mcc_generated_files\system\src\clock.c + de1d7413e59ed5f8868c2e021f43469da264b3fcfb59f757953dec9603343810 + + + mcc_generated_files\system\src\config_bits.c + 29e8bde29f5a6b205803fc219dfa3a9e6e0971214673fd5ac9c3e661e111a26f + + + mcc_generated_files\system\src\interrupt.c + e27867b94747dfcde0538b371a10abd3f95c1516a59d4180fc07d5ccf28697a4 + + + mcc_generated_files\system\src\pins.c + fffcadbbad0ffab0258f915e963afbc7f2ed4a50f41adb3ee8a9e73295f7b2e4 + + + mcc_generated_files\system\src\protected_io.S + 4b140dbb376219b5a3da75f0eb4d64e14c8baef82193b7b562ad74cfed7d3348 + + + mcc_generated_files\system\src\syscfg.c + 1791dac307439281ed2b5ab537d64fde462eaad4a740193f9dbac39d85dfb826 + + + mcc_generated_files\system\src\system.c + c16c76a35ee248e1862e8454ec719fb71c24025d68ea8fadab9a286cc6d1d710 + + + mcc_generated_files\system\syscfg.h + 20cac2a6861d17a574bb94fdf74ce64280d4248bb902697bb5b005983b129258 + + + mcc_generated_files\system\system.h + 36152a6e836b6eb3322a3cf717617d3d18cda4e0c24a04726e46f4452db955a8 + + + mcc_generated_files\system\utils\assembler.h + ef3dab91390b4a198c234566994c23272765931378bb3d0aa94670e39e6e0d26 + + + mcc_generated_files\system\utils\assembler\gas.h + 667f6ffee6461d9ad79483b20b02a35dfc4ad60bf0418e2ecbd19df4991dc38d + + + mcc_generated_files\system\utils\assembler\iar.h + 53c9ca51da473f3a6ae6e42f4056df249a058f10ece6f749e5bdd1ea3ed7a385 + + + mcc_generated_files\system\utils\atomic.h + 19307b79f5a6af4e7cc53b21a4736a674bc97bdaa5b381d8f0bdfd008bd48b9a + + + mcc_generated_files\system\utils\compiler.h + 7b9b32dc17152d0780506dc95a87e10ba2f9238d1f2e9d7ad8f7493000036fc0 + + + mcc_generated_files\system\utils\interrupt_avr8.h + e4084c0e62035baf526b13eb8e403cde7b00331045cd04839520c845bb0707a6 + + + mcc_generated_files\system\utils\utils.h + 1c920a9d95628ccae7945d16093b8d2407f5a5f27dc63c6256b9c52d3ec363f2 + + + mcc_generated_files\system\utils\utils_assert.h + d347e0636652e48c7fb7c186ae4336f343801e0acdca339cc724db0807b4fff3 + + + mcc_generated_files\timer\rtc.h + 30de4216e54591b4ce33fa8b85e391383b5612c6040cabae2de0dd78b7a2160e + + + mcc_generated_files\timer\src\rtc.c + 9232e5bd2802526e0c07d6546e6a53041a8159fccfc834e7186ad7e29f57464f + + + mcc_generated_files\usb\src\usb0.c + 5da11d73f45d2538d9d4d75fc1a85d331460dca29da3f7992329591f3dba7770 + + + mcc_generated_files\usb\usb0.h + 220875fcea1586ca4690388015ab5629c4c815c9a43e74a58313b874d77c237f + + + mcc_generated_files\usb\usb_common\usb_common_elements.h + 0b253bab4de474643d111d19bb27b94ec7b9136f40de2746e2330b57bb82423d + + + mcc_generated_files\usb\usb_common\usb_core.c + 87f29f0fc84ecd54765eff03e2f46c2711d6e21734c6afaddf66d4dc0066fc02 + + + mcc_generated_files\usb\usb_common\usb_core.h + eda98246eaeefd29dd8e983c3b58ce3fb44936564d6e287eef6e5020947a3afa + + + mcc_generated_files\usb\usb_common\usb_core_descriptors.c + 910a3fd85157ecba31bfb291e5fdd9b2f9664cf5fe49e83bd679a2348db10ee2 + + + mcc_generated_files\usb\usb_common\usb_core_descriptors.h + ba57547394bdb8fadd716fe96e2b2a7cc969cee6d578f34ae11fd73ffee784ac + + + mcc_generated_files\usb\usb_common\usb_core_events.c + a43a2564616b338b664f169e64286b6812ed70e72ec375c066546de62e9183cc + + + mcc_generated_files\usb\usb_common\usb_core_events.h + 1c71d2d9f14e6a8b6fe35aa5f5adada7729ccd7b23835dcab425d395f8fa82c5 + + + mcc_generated_files\usb\usb_common\usb_core_requests.c + 6bd3ba8ec62f438ea9f430da43517a685a26ee06fe81eb3f89cc2082d6b338ff + + + mcc_generated_files\usb\usb_common\usb_core_requests.h + 0328d64365566933df21d0aeca6634bcbfcf9a18016875a886e208ee7a3780fe + + + mcc_generated_files\usb\usb_common\usb_core_requests_device.c + 03f834e007ec466d5fd629d28aea90a6620b8ff93a4944d2a98c62de71e4f41f + + + mcc_generated_files\usb\usb_common\usb_core_requests_device.h + f523945e8767ae2d44823aef83a852d07dc288830c11c9005187c7362dad6094 + + + mcc_generated_files\usb\usb_common\usb_core_requests_endpoint.c + 0a375dede570c36b4604fb47be9a988c43d24bb687109643087c0abaadc0273a + + + mcc_generated_files\usb\usb_common\usb_core_requests_endpoint.h + 3dcdcfc291967933a14ef33287eceb260b8e3485f7c86b868fec6d704ab4370f + + + mcc_generated_files\usb\usb_common\usb_core_requests_interface.c + a8ef16b763e5e112d8af736fb03d308d01ec797a27e7ecc8e30d77c84e2be4f0 + + + mcc_generated_files\usb\usb_common\usb_core_requests_interface.h + aef6572fa424d64fcc9ba1d0223aecdc713a96408a140d8205156aaf88e0cb4e + + + mcc_generated_files\usb\usb_common\usb_core_transfer.c + ae371faa0074161eb36dd98bfb35d8d0a09d679055f023c6f07c9ce9f307c0b3 + + + mcc_generated_files\usb\usb_common\usb_core_transfer.h + aa987571b524642479a060c738e094b9d9041325b5bc1e45a9972264c2e343ff + + + mcc_generated_files\usb\usb_common\usb_protocol_headers.h + ffd7043169b9c84ed1ba08b6b65487f88da524d72b170fae155d59826adafdda + + + mcc_generated_files\usb\usb_config.h + 0bb6e14cc54d24b08ba2fa85977886bb81f6119640b874dcca4df52f5db9283e + + + mcc_generated_files\usb\usb_descriptors.c + 5a2f35e1d9226d93d3e6fc692ebb5f63a9729c2d1ce847eb9edf844cd91cd767 + + + mcc_generated_files\usb\usb_descriptors.h + 7901eee0f0e75a722b1c44d0b0b5750f3973a55d9379b47329958c819209f8de + + + mcc_generated_files\usb\usb_device.c + ad00eab046400b4176898acbbbef50185f7fb47215fea6c6dd228139a82e7a2c + + + mcc_generated_files\usb\usb_device.h + 9228f908024a48b1a9a66561baf52930ca147d1e465a55056d9a5eab150fcb6e + + + mcc_generated_files\usb\usb_peripheral\usb_peripheral.c + 3969148f6f217cd9beb8f829ab3ca5da149e541def97bbfdea45cfa2a3273958 + + + mcc_generated_files\usb\usb_peripheral\usb_peripheral.h + 32b8d65e34d45f474398afdfec9f2a1bf571dcbfdd6b9499a8925858a8cdbdbb + + + mcc_generated_files\usb\usb_peripheral\usb_peripheral_avr_du.h + 25328772bf8e83d40ee2ea0f29a220af2268ae4cbcc5bd5787490b6ea6c9a8ce + + + mcc_generated_files\usb\usb_peripheral\usb_peripheral_endpoint.c + ca53923984b015e76b4ea46d66f15b5cf6c36abf0766a30540d0671b059d74ca + + + mcc_generated_files\usb\usb_peripheral\usb_peripheral_endpoint.h + 309496c9ba92b97f727abc3bb1b0b0516d0938cb6f270288360ea3465164622c + + + mcc_generated_files\usb\usb_peripheral\usb_peripheral_read_write.c + 46646204555a99e303bc5032be0bb19bc4c240800f973c7de50fe26d8bbf986c + + + mcc_generated_files\usb\usb_peripheral\usb_peripheral_read_write.h + 13c9d763e7e10070d41af7e13033ec7a167d4d2ad8bf0c102dd3964719aa8402 + + + mcc_generated_files\usb\usb_vendor\usb_vendor.c + b0cbbad99cc03556c31f8d332a8312c65409d24fc0620caa0af74ea958a22414 + + + mcc_generated_files\usb\usb_vendor\usb_vendor.h + 4bfb855dbd97167599877ea168b6fc44c1ea9686999a91cff89405bd18346ece + + + mcc_generated_files\vref\src\vref.c + 16cfdafad2c22706364c0bfc01d048f968564ee92a0744e5042fffee8ab05484 + + + mcc_generated_files\vref\vref.h + 45d7853bf4d55b39db01525bd3e376e180f317ac74992a5e49ca9436865cbc50 + + + \ No newline at end of file diff --git a/avr64du32-cnano-usb-vendor-mplab-mcc.X/main.c b/avr64du32-cnano-usb-vendor-mplab-mcc.X/main.c new file mode 100644 index 0000000..5f57414 --- /dev/null +++ b/avr64du32-cnano-usb-vendor-mplab-mcc.X/main.c @@ -0,0 +1,290 @@ + /* + * MAIN Generated Driver File + * + * @file main.c + * + * @defgroup main MAIN + * + * @brief Transfers data with USB Vendor Class + * + * @version MAIN Driver Version 1.0.0 +*/ + +/* +� [2024] Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip + software and any derivatives exclusively with Microchip products. + You are responsible for complying with 3rd party license terms + applicable to your use of 3rd party software (including open source + software) that may accompany Microchip software. SOFTWARE IS ?AS IS.? + NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS + SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, + MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT + WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY + KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF + MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE + FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S + TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT + EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR + THIS SOFTWARE. +*/ + +#include "mcc_generated_files/system/system.h" +#include "usb_core.h" +#include + +// USB Interface Number used by all Interfaces +#define INTERFACE_ENDPOINTS 0 + +// USB Alternate Interface Settings for the different transfer types +#define INTERFACE_ALTERNATE_CONTROL 0 +#define INTERFACE_ALTERNATE_BULKINT 1 +#define INTERFACE_ALTERNATE_ISO1 2 +#define INTERFACE_ALTERNATE_ISO1023_OUT 3 +#define INTERFACE_ALTERNATE_ISO1023_IN 4 + +// Vendor defines +#define VENDOR_DEFAULT_TRANSFER 4096ul +#define VENDOR_ISO_TRANSFER (((VENDOR_DEFAULT_TRANSFER) / INTERFACE0ALTERNATE4_ISOCHRONOUS_EP4_IN_SIZE) * INTERFACE0ALTERNATE4_ISOCHRONOUS_EP4_IN_SIZE) // taking 1023 into account +#define REQUEST_VENDOR_TEST_CONTROL 0 +#define REQUEST_VENDOR_CONFIGURE_BULKINT_ZLP 1 +#define REQUEST_VENDOR_CONFIGURE_BULKINT_SIZE 2 + +// Timer defines +#define CONSECUTIVE_EQUAL_PIT_INTERRUPTS 5 + +// USB connection variables +volatile RETURN_CODE_t status = SUCCESS; +volatile bool vbusFlag = false; +volatile bool prevVbusState = false; + +// Bulk transfer variables +uint8_t vendorBuffer[VENDOR_DEFAULT_TRANSFER] __attribute__((aligned(2))) = { 0 }; +volatile uint16_t bulkintTransferSize = VENDOR_DEFAULT_TRANSFER; +volatile bool bulkintUseZLP = false; + +// USB connection functions +void RTC_GetUSBState(void); +void CheckUSBConnection(void); + +// Data transfer Functions +void InterfaceEnabledCallback(USB_SETUP_REQUEST_t *setupRequestPtr); +RETURN_CODE_t VendorControlRequest(USB_SETUP_REQUEST_t *setupRequestPtr); +void VendorDataSent(USB_PIPE_t pipe, USB_TRANSFER_STATUS_t status, uint16_t bytesTransferred); +void VendorDataReceived(USB_PIPE_t pipe, USB_TRANSFER_STATUS_t status, uint16_t bytesTransferred); +void VendorIsoExtendedBuffer(USB_PIPE_t pipe, USB_TRANSFER_STATUS_t status, uint16_t bytesTransferred); + +int main(void) +{ + SYSTEM_Initialize(); + + RTC_SetPITIsrCallback(RTC_GetUSBState); + USB_DescriptorPointersSet(&descriptorPointers); + USB_VendorClassInit(InterfaceEnabledCallback, VendorControlRequest, NULL); + + while(1) + { + CheckUSBConnection(); + } +} + +void CheckUSBConnection(void) +{ + /* Handles USB transfers and events, + * when the AVR is connected to a device (i.e. there is voltage on vbus) + */ + USBDevice_Handle(); + bool currentVbusState = vbusFlag; + + // Handles USB connects and disconnects + if (currentVbusState != prevVbusState) + { + if(currentVbusState == true) + { + status = USB_Start(); + } + else + { + status = USB_Stop(); + } + prevVbusState = currentVbusState; + } + return; +} + +// Periodically measuring vbus voltage +void RTC_GetUSBState(void) +{ + static volatile uint8_t PIT_Counter = 0; + static volatile uint8_t AC_prevState = 0; + + uint8_t AC_currentState = AC0_Read(); // Saves the current state of the AC status register ('1' means above threshold) + + // Makes sure that the AC state has been the same for a certain number of PIT interrupts + if (PIT_Counter == CONSECUTIVE_EQUAL_PIT_INTERRUPTS) + { + if (AC_currentState) // 1 = High, which means that the VBUS is above the threshold and the pull-up on data+ should be enabled. + { + vbusFlag = true; + } + else + { + vbusFlag = false; + } + PIT_Counter++; // Increment the counter to not run start/stop multiple times without an actual state change + } + // Increments a counter if the AC has been in the same state for a certain number of PIT interrupts + else if (AC_currentState == AC_prevState) + { + if (PIT_Counter <= CONSECUTIVE_EQUAL_PIT_INTERRUPTS + 1) + { + PIT_Counter++; + } + else + { + ; // Stops counting if the AC has been in the same state for a while. + } + } + else + { + PIT_Counter = 0; // Resets the PIT counter if a state change has occurred. + } + AC_prevState = AC_currentState; + return; +} + +void InterfaceEnabledCallback(USB_SETUP_REQUEST_t *setupRequestPtr) +{ + // 32 interface numbers are supported, so masking out the wIndex + uint8_t interface = setupRequestPtr->wIndex & 0x1f; + // 256 alternate interface numers are supported, so masking out the wValue + uint8_t alternateInterface = setupRequestPtr->wValue & 0xff; + + if (interface == INTERFACE_ENDPOINTS) + { + switch (alternateInterface) + { + case INTERFACE_ALTERNATE_BULKINT: + { + // Start buffer transfer OUT for the bulk and interrupt endpoints, vendor_data_received will call a buffer transfer IN when finished + + USB_PIPE_t interrupt_out_pipe = { .address = INTERFACE0ALTERNATE1_INTERRUPT_EP1_OUT, .direction = USB_EP_DIR_OUT }; + USB_TransferReadStart(interrupt_out_pipe, vendorBuffer, bulkintTransferSize, bulkintUseZLP, VendorDataReceived); + + USB_PIPE_t bulk_out_pipe = { .address = INTERFACE0ALTERNATE1_BULK_EP2_OUT, .direction = USB_EP_DIR_OUT }; + USB_TransferReadStart(bulk_out_pipe, vendorBuffer, bulkintTransferSize, bulkintUseZLP, VendorDataReceived); + break; + } + case INTERFACE_ALTERNATE_ISO1: + { + // Start a parallel buffer transfer OUT for Iso endpoint with size <= 512 + USB_PIPE_t iso_out_pipe = { .address = INTERFACE0ALTERNATE2_ISOCHRONOUS_EP3_OUT, .direction = USB_EP_DIR_OUT }; + VendorIsoExtendedBuffer(iso_out_pipe, USB_PIPE_TRANSFER_OK, 0); + break; + } + case INTERFACE_ALTERNATE_ISO1023_OUT: + { + // Special OUT transfer for isochronous with 1023 byte endpoint size because OS drivers have difficulties allocating resources for 2x 1023 byte endpoints + USB_PIPE_t iso_out2_pipe = { .address = INTERFACE0ALTERNATE3_ISOCHRONOUS_EP4_OUT, .direction = USB_EP_DIR_OUT }; + USB_TransferReadStart(iso_out2_pipe, vendorBuffer, VENDOR_ISO_TRANSFER, false, NULL); + break; + } + case INTERFACE_ALTERNATE_ISO1023_IN: + { + // Special IN transfer for isochronous with 1023 byte endpoint size because OS drivers have difficulties allocating resources for 2x 1023 byte endpoints + USB_PIPE_t iso_in2_pipe = { .address = INTERFACE0ALTERNATE4_ISOCHRONOUS_EP4_IN, .direction = USB_EP_DIR_IN }; + USB_TransferWriteStart(iso_in2_pipe, vendorBuffer, VENDOR_ISO_TRANSFER, false, NULL); + break; + } + default: + break; + } + } +} + +RETURN_CODE_t VendorControlRequest(USB_SETUP_REQUEST_t *setupRequestPtr) +{ + RETURN_CODE_t status = SUCCESS; + + if (setupRequestPtr->wIndex == REQUEST_VENDOR_TEST_CONTROL) // endpoint control transfer + { + // Transfer up to VENDOR_DEFAULT_TRANSFER number of bytes to or from the host, + // USB_TransferControlDataSet is used for both IN and OUT control data transfers + if (setupRequestPtr->wLength > VENDOR_DEFAULT_TRANSFER) + { + USB_TransferControlDataSet(vendorBuffer, VENDOR_DEFAULT_TRANSFER, NULL); + } + else + { + USB_TransferControlDataSet(vendorBuffer, setupRequestPtr->wLength, NULL); + } + } + else if (setupRequestPtr->wIndex == REQUEST_VENDOR_CONFIGURE_BULKINT_ZLP) // configure use of zlp + { + bulkintUseZLP = setupRequestPtr->wValue & 0x0001; + + // Return an empty packet to acknowledge the request + USB_TransferControlDataSet(NULL, 0, NULL); + } + else if (setupRequestPtr->wIndex == REQUEST_VENDOR_CONFIGURE_BULKINT_SIZE) // update bulk transfer size + { + bulkintTransferSize = setupRequestPtr->wValue; + + // Read a full endpoint size if we are testing azlp, just to show that the transfer is successful in any case + if (bulkintUseZLP && (0u != (bulkintTransferSize % INTERFACE0ALTERNATE1_BULK_EP2_IN_SIZE))) + { + bulkintTransferSize = ((bulkintTransferSize / INTERFACE0ALTERNATE1_BULK_EP2_IN_SIZE) + 1) * INTERFACE0ALTERNATE1_BULK_EP2_IN_SIZE; + } + + // Return an empty packet to acknowledge the request + USB_TransferControlDataSet(NULL, 0, NULL); + } + else + { + status = UNSUPPORTED; + } + + /* Control requests must return SUCCESS, UNSUPPORTED or an error + * if returning UNSUPPORTED the core will stall the request + */ + return status; +} + +void VendorDataSent(USB_PIPE_t pipe, USB_TRANSFER_STATUS_t status, uint16_t bytesTransferred) +{ + if (USB_PIPE_TRANSFER_OK == status) + { + /* Data sent, expect new data on the IN endpoint, up to VENDOR_DEFAULT_TRANSFER. + * VendorDataReceived will call a buffer transfer IN when the transfer is finished + */ + pipe.direction = USB_EP_DIR_OUT; + USB_TransferReadStart(pipe, vendorBuffer, bulkintTransferSize, bulkintUseZLP, VendorDataReceived); + } +} + +void VendorDataReceived(USB_PIPE_t pipe, USB_TRANSFER_STATUS_t status, uint16_t bytesTransferred) +{ + if (USB_PIPE_TRANSFER_OK == status) + { + // Data received, return back the same data on the OUT endpoint + // vendor_data_sent will call a buffer transfer OUT when the transfer is finished + pipe.direction = USB_EP_DIR_IN; + USB_TransferWriteStart(pipe, vendorBuffer, bytesTransferred, bulkintUseZLP, VendorDataSent); + } +} + +void VendorIsoExtendedBuffer(USB_PIPE_t pipe, USB_TRANSFER_STATUS_t status, uint16_t bytesTransferred) +{ + // Start the in and out transfers in parallel, with VENDOR_ISO_TRANSFER size + // Requires the host to always have the OUT transfer one packet ahead of the IN transfer + if (USB_PIPE_TRANSFER_OK == status) + { + pipe.direction = USB_EP_DIR_IN; + USB_TransferWriteStart(pipe, vendorBuffer, VENDOR_DEFAULT_TRANSFER, false, VendorIsoExtendedBuffer); + + pipe.direction = USB_EP_DIR_OUT; + USB_TransferReadStart(pipe, vendorBuffer, VENDOR_DEFAULT_TRANSFER, false, NULL); + } +} \ No newline at end of file diff --git a/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/ac/ac0.h b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/ac/ac0.h new file mode 100644 index 0000000..f4b3bda --- /dev/null +++ b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/ac/ac0.h @@ -0,0 +1,100 @@ +/** + * AC0 Generated Driver API Header File + * + * @file ac0.h + * + * @defgroup ac0 AC0 + * + * @brief Contains the API prototypes for the AC0 driver. + * + * @version AC0 Driver Version 1.0.0 +*/ +/* +© [2024] Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip + software and any derivatives exclusively with Microchip products. + You are responsible for complying with 3rd party license terms + applicable to your use of 3rd party software (including open source + software) that may accompany Microchip software. SOFTWARE IS ?AS IS.? + NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS + SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, + MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT + WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY + KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF + MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE + FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S + TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT + EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR + THIS SOFTWARE. +*/ + + +#ifndef AC0_H_INCLUDED +#define AC0_H_INCLUDED + +#include "../system/utils/compiler.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @ingroup ac0 + * @brief Pointer to a function to be used as a callback handler when a comparator interrupt occurs. + * @param None. + * @return None. + */ +typedef void (*ac_cb_t)(void); + +/** + * @ingroup ac0 + * @brief Initializes the AC0. This routine is called only once during system initialization, before calling other APIs. + * @param None. + * @return None. +*/ +int8_t AC0_Initialize(void); + +/** + * @ingroup ac0 + * @brief Controls the input signal to the positive and negative inputs of the AC0. + * @pre Initialize the AC0 with AC0_Initialize() before calling this API. + * @param uint8_t Mode. + * @return None. + */ +void AC0_MuxSet(uint8_t); + +/** + * @ingroup ac0 + * @brief Returns the OUT signal state for the AC0. + * @pre Initialize the AC0 with AC0_Initialize() before calling this API. + * @param None. + * @retval True - The AC OUT signal is high. + * @retval False - the AC OUT signal is low. + */ +bool AC0_Read(void); + +/** + * @ingroup ac0 + * @brief Setter function for the AC0 comparator callback. + * @pre None. + * @param CallbackHandler - Pointer to custom callback. + * @return None. + */ +void AC0_CallbackRegister(ac_cb_t); + +/** + * @ingroup ac0 + * @brief Sets the DAC voltage reference (DACREF) data value for the AC0. + * @pre Initialize the AC0 with AC0_Initialize() before calling this API. + * @param uint8_t- Value to be written to the DACREF register. + * @return None. + */ +void AC0_DACRefValueSet(uint8_t); + +#ifdef __cplusplus +} +#endif + +#endif /* AC0_H_INCLUDED */ \ No newline at end of file diff --git a/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/ac/src/ac0.c b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/ac/src/ac0.c new file mode 100644 index 0000000..44c13c6 --- /dev/null +++ b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/ac/src/ac0.c @@ -0,0 +1,93 @@ +/** + * AC0 Generated Driver File + * + * @file ac0.c + * + * @ingroup ac0 + * + * @brief Contains the API implementation for the AC0 driver. + * + * @version AC0 Driver Version 1.0.0 +*/ +/* +© [2024] Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip + software and any derivatives exclusively with Microchip products. + You are responsible for complying with 3rd party license terms + applicable to your use of 3rd party software (including open source + software) that may accompany Microchip software. SOFTWARE IS ?AS IS.? + NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS + SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, + MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT + WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY + KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF + MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE + FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S + TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT + EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR + THIS SOFTWARE. +*/ + +#include +#include "../ac0.h" + +static ac_cb_t AC0_cb = NULL; + +int8_t AC0_Initialize(void) +{ + + //DACREF 60; + AC0.DACREF = 0x3C; + + //CMP disabled; INTMODE Positive and negative inputs crosses; + AC0.INTCTRL = 0x0; + + //INITVAL LOW; INVERT disabled; MUXNEG DAC Reference; MUXPOS Positive Pin 4; + AC0.MUXCTRL = 0x24; + + //ENABLE enabled; HYSMODE No hysteresis; OUTEN disabled; POWER Power profile 0, lowest consumption and highest response time.; RUNSTDBY disabled; + AC0.CTRLA = 0x1; + + return 0; +} + +ISR(AC0_AC_vect) +{ + /* Insert your AC interrupt handling code here */ + + /* The interrupt flag has to be cleared manually */ + AC0.STATUS = AC_CMPIF_bm; + if (AC0_cb != NULL) + { + AC0_cb(); + } +} + +void AC0_MuxSet(uint8_t Mode) +{ + uint8_t temp; + temp = AC0.MUXCTRL; + temp &= ~(AC_MUXPOS_gm | AC_MUXNEG_gm); + temp |= Mode; + AC0.MUXCTRL = temp; +} + +bool AC0_Read(void) +{ + return ((AC0.STATUS & AC_CMPSTATE_bm) != 0 ); +} + +void AC0_CallbackRegister(ac_cb_t comparator_cb) +{ + ATOMIC_BLOCK(ATOMIC_RESTORESTATE) + { + AC0_cb = comparator_cb; + } +} + +void AC0_DACRefValueSet (uint8_t value) +{ + AC0.DACREF = value; +} diff --git a/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/system/ccp.h b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/system/ccp.h new file mode 100644 index 0000000..9fb8a16 --- /dev/null +++ b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/system/ccp.h @@ -0,0 +1,72 @@ +/** + * CCP Header File + * + * @file ccp.h + * + * @ingroup config_bitsdriver + * + * @brief This file contains the Configuration Change Protection (CCP) header file for the Configuration bits driver. + * + * @version Driver Version 1.0.0 +*/ +/* +© [2024] Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip + software and any derivatives exclusively with Microchip products. + You are responsible for complying with 3rd party license terms + applicable to your use of 3rd party software (including open source + software) that may accompany Microchip software. SOFTWARE IS ?AS IS.? + NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS + SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, + MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT + WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY + KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF + MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE + FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S + TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT + EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR + THIS SOFTWARE. +*/ + + +#ifndef CPU_CCP_H +#define CPU_CCP_H + +#include "../system/utils/compiler.h" +#include "../system/protected_io.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Writes to a CCP-protected 8-bit I/O register. + * @param addr Address of the I/O register. + * @param value Value to be written. + * NOTE: Using IAR Embedded workbench, the choice of memory model has an impact on calling convention. + * Memory model must be defined in the Assembler preprocessor directives to be visible to the preprocessor. + */ +static inline void ccp_write_io(void *addr, uint8_t value) +{ + protected_write_io(addr, CCP_IOREG_gc, value); +} + +/** + * @brief Writes to a CCP-protected 8-bit SPM register. + * @param addr Address of the SPM register. + * @param value Value to be written. + * NOTE: Using IAR Embedded workbench, the choice of memory model has an impacton calling convention. + * Memory model must be defined in the Assembler preprocessor directives to be visible to the preprocessor. + */ +static inline void ccp_write_spm(void *addr, uint8_t value) +{ + protected_write_io(addr, CCP_SPM_gc, value); +} + +#ifdef __cplusplus +} +#endif + +#endif /* CPU_CCP_H */ diff --git a/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/system/clock.h b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/system/clock.h new file mode 100644 index 0000000..10c85c0 --- /dev/null +++ b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/system/clock.h @@ -0,0 +1,70 @@ + +/** + * CLKCTRL Generated Driver API Header File + * + * @file clkctrl.h + * + * @defgroup clkctrl CLKCTRL + * + * @brief This header file provides APIs for the CLKCTRL driver. + * + * @version CLKCTRL Driver Version 1.1.4 + * + * @version Package Version 2.0.9 +*/ +/* +© [2024] Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip + software and any derivatives exclusively with Microchip products. + You are responsible for complying with 3rd party license terms + applicable to your use of 3rd party software (including open source + software) that may accompany Microchip software. SOFTWARE IS ?AS IS.? + NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS + SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, + MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT + WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY + KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF + MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE + FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S + TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT + EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR + THIS SOFTWARE. +*/ + + +#ifndef CLOCK_H +#define CLOCK_H + +#ifndef F_CPU +#define F_CPU 24000000UL +#endif + +#include "ccp.h" + +/** + * @ingroup clkctrl + * @brief Initializes the CLKCTRL module. + * @param None. + * @return None. + */ +void CLOCK_Initialize(void); + +/** + * @ingroup clkctrl + * @brief Enables the Clock Failure Detection on the main clock. + * @param CLKCTRL_CFDSRC_t cfd_source - main clock source for CFD + * @return None. + */ +void CFD_Enable(CLKCTRL_CFDSRC_t cfd_source); + +/** + * @ingroup clkctrl + * @brief Disables the Clock Failure Detection on the main clock. + * @param None. + * @return None. + */ +void CFD_Disable(void); + +#endif // CLOCK_H \ No newline at end of file diff --git a/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/system/config_bits.h b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/system/config_bits.h new file mode 100644 index 0000000..4a4e1b6 --- /dev/null +++ b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/system/config_bits.h @@ -0,0 +1,44 @@ +/** + * CONFIGURATION BITS Generated Driver Header File + * + * @file config_bits.h + * + * @defgroup config_bitsdriver CONFIGBITS Driver + * + * @brief This file contains the API Prototypes for the Configuration Bits driver. + * + * @version Driver Version 1.0.5 + * + * @version Package Version 4.2.14 +*/ + +/* +© [2024] Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip + software and any derivatives exclusively with Microchip products. + You are responsible for complying with 3rd party license terms + applicable to your use of 3rd party software (including open source + software) that may accompany Microchip software. SOFTWARE IS ?AS IS.? + NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS + SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, + MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT + WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY + KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF + MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE + FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S + TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT + EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR + THIS SOFTWARE. +*/ + +#ifndef CONFIG_BITS_H +#define CONFIG_BITS_H + +#include "../system/clock.h" + +#endif //CONFIG_BITS_H +/** + End of File +*/ \ No newline at end of file diff --git a/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/system/interrupt.h b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/system/interrupt.h new file mode 100644 index 0000000..d2a9281 --- /dev/null +++ b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/system/interrupt.h @@ -0,0 +1,57 @@ +/** + * Interrupt Manager Generated Driver API Header File. + * + * @file interrupt.h + * + * @defgroup interrupt INTERRUPT + * + * @brief This file contains the API prototype for the Interrupt Manager. + * + * @version Interrupt Manager Driver Version 1.0.0 +*/ + +/* +© [2024] Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip + software and any derivatives exclusively with Microchip products. + You are responsible for complying with 3rd party license terms + applicable to your use of 3rd party software (including open source + software) that may accompany Microchip software. SOFTWARE IS ?AS IS.? + NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS + SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, + MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT + WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY + KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF + MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE + FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S + TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT + EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR + THIS SOFTWARE. +*/ + + +#ifndef INTERRUPT_H +#define INTERRUPT_H + +#include "../system/utils/compiler.h" +#include "ccp.h" +#include "../system/utils/atomic.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @ingroup interrupt + * @brief Initializes the Interrupt module. + * @retval 0 - Initialization is successful. + */ +int8_t CPUINT_Initialize(); + +#ifdef __cplusplus +} +#endif + +#endif /* INTERRUPT_H */ \ No newline at end of file diff --git a/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/system/pins.h b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/system/pins.h new file mode 100644 index 0000000..7ab6e91 --- /dev/null +++ b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/system/pins.h @@ -0,0 +1,88 @@ +/** + * Generated Pins header File + * + * @file pins.h + * + * @defgroup pinsdriver Pins Driver + * + * @brief This is generated driver header for pins. + * This header file provides APIs for all pins selected in the GUI. + * + * @version Driver Version 1.1.0 +*/ + +/* +© [2024] Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip + software and any derivatives exclusively with Microchip products. + You are responsible for complying with 3rd party license terms + applicable to your use of 3rd party software (including open source + software) that may accompany Microchip software. SOFTWARE IS ?AS IS.? + NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS + SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, + MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT + WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY + KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF + MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE + FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S + TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT + EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR + THIS SOFTWARE. +*/ + +#ifndef PINS_H_INCLUDED +#define PINS_H_INCLUDED + +#include +#include "./port.h" + +//get/set IO_PC3 aliases +#define IO_PC3_SetHigh() do { PORTC_OUTSET = 0x8; } while(0) +#define IO_PC3_SetLow() do { PORTC_OUTCLR = 0x8; } while(0) +#define IO_PC3_Toggle() do { PORTC_OUTTGL = 0x8; } while(0) +#define IO_PC3_GetValue() (VPORTC.IN & (0x1 << 3)) +#define IO_PC3_SetDigitalInput() do { PORTC_DIRCLR = 0x8; } while(0) +#define IO_PC3_SetDigitalOutput() do { PORTC_DIRSET = 0x8; } while(0) +#define IO_PC3_SetPullUp() do { PORTC_PIN3CTRL |= PORT_PULLUPEN_bm; } while(0) +#define IO_PC3_ResetPullUp() do { PORTC_PIN3CTRL &= ~PORT_PULLUPEN_bm; } while(0) +#define IO_PC3_SetInverted() do { PORTC_PIN3CTRL |= PORT_INVEN_bm; } while(0) +#define IO_PC3_ResetInverted() do { PORTC_PIN3CTRL &= ~PORT_INVEN_bm; } while(0) +#define IO_PC3_DisableInterruptOnChange() do { PORTC.PIN3CTRL = (PORTC.PIN3CTRL & ~PORT_ISC_gm) | 0x0 ; } while(0) +#define IO_PC3_EnableInterruptForBothEdges() do { PORTC.PIN3CTRL = (PORTC.PIN3CTRL & ~PORT_ISC_gm) | 0x1 ; } while(0) +#define IO_PC3_EnableInterruptForRisingEdge() do { PORTC.PIN3CTRL = (PORTC.PIN3CTRL & ~PORT_ISC_gm) | 0x2 ; } while(0) +#define IO_PC3_EnableInterruptForFallingEdge() do { PORTC.PIN3CTRL = (PORTC.PIN3CTRL & ~PORT_ISC_gm) | 0x3 ; } while(0) +#define IO_PC3_DisableDigitalInputBuffer() do { PORTC.PIN3CTRL = (PORTC.PIN3CTRL & ~PORT_ISC_gm) | 0x4 ; } while(0) +#define IO_PC3_EnableInterruptForLowLevelSensing() do { PORTC.PIN3CTRL = (PORTC.PIN3CTRL & ~PORT_ISC_gm) | 0x5 ; } while(0) +#define PC3_SetInterruptHandler IO_PC3_SetInterruptHandler + +/** + * @ingroup pinsdriver + * @brief GPIO and peripheral I/O initialization + * @param none + * @return none + */ +void PIN_MANAGER_Initialize(); + +/** + * @ingroup pinsdriver + * @brief Default Interrupt Handler for IO_PC3 pin. + * This is a predefined interrupt handler to be used together with the IO_PC3_SetInterruptHandler() method. + * This handler is called every time the IO_PC3 ISR is executed. + * @pre PIN_MANAGER_Initialize() has been called at least once + * @param none + * @return none + */ +void IO_PC3_DefaultInterruptHandler(void); + +/** + * @ingroup pinsdriver + * @brief Interrupt Handler Setter for IO_PC3 pin input-sense-config functionality. + * Allows selecting an interrupt handler for IO_PC3 at application runtime + * @pre PIN_MANAGER_Initialize() has been called at least once + * @param InterruptHandler function pointer. + * @return none + */ +void IO_PC3_SetInterruptHandler(void (* interruptHandler)(void)) ; +#endif /* PINS_H_INCLUDED */ diff --git a/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/system/port.h b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/system/port.h new file mode 100644 index 0000000..b5eacba --- /dev/null +++ b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/system/port.h @@ -0,0 +1,902 @@ +/** + * Generated Ports header File + * + * @file port.h + * + * @ingroup pinsdriver + * + * @brief This Source file provides APIs. + * + * @version Driver Version 1.0.1 +*/ + +/* +© [2024] Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip + software and any derivatives exclusively with Microchip products. + You are responsible for complying with 3rd party license terms + applicable to your use of 3rd party software (including open source + software) that may accompany Microchip software. SOFTWARE IS ?AS IS.? + NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS + SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, + MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT + WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY + KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF + MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE + FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S + TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT + EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR + THIS SOFTWARE. +*/ + + +#ifndef PORT_INCLUDED +#define PORT_INCLUDED + +#ifdef __cplusplus +extern "C" { +#endif + +#include "utils/compiler.h" + +/* @ingroup pinsdriver + * @enum port_pull_mode + * Defines the pullup modes. + */ +enum port_pull_mode { + PORT_PULL_OFF, + PORT_PULL_UP, +}; + +/* @ingroup pinsdriver + * @enum port_dir + * Defines the port directions. + */ +enum port_dir { + PORT_DIR_IN, + PORT_DIR_OUT, + PORT_DIR_OFF, +}; + +/** + * @ingroup pinsdriver + * @brief Set port pin pull mode, Configure pin to pull up, down or disable pull mode, supported pull modes are defined by device used. + * @param pin The pin number within port + * @param pull_mode Pin pull mode + * @return none + */ +static inline void PORTA_set_pin_pull_mode(const uint8_t pin, const enum port_pull_mode pull_mode) +{ + volatile uint8_t *port_pin_ctrl = ((uint8_t *)&PORTA + 0x10 + pin); + + if (pull_mode == PORT_PULL_UP) { + *port_pin_ctrl |= PORT_PULLUPEN_bm; + } else if (pull_mode == PORT_PULL_OFF) { + *port_pin_ctrl &= ~PORT_PULLUPEN_bm; + } +} + +/** + * @ingroup pinsdriver + * @brief Set port pin inverted mode, Configure pin invert I/O or not. + * @param pin The pin number within port + * @param inverted Pin inverted mode + * @return none + */ +static inline void PORTA_pin_set_inverted(const uint8_t pin, const bool inverted) +{ + volatile uint8_t *port_pin_ctrl = ((uint8_t *)&PORTA + 0x10 + pin); + + if (inverted) { + *port_pin_ctrl |= PORT_INVEN_bm; + } else { + *port_pin_ctrl &= ~PORT_INVEN_bm; + } +} + +/** + * @ingroup pinsdriver + * @brief Set port pin input/sense configuration, Enable/disable digital input buffer and pin change interrupt, + * select pin interrupt edge/level sensing mode + * @param The pin number within port + * @param isc PORT_ISC_t + * @return none + */ +static inline void PORTA_pin_set_isc(const uint8_t pin, const PORT_ISC_t isc) +{ + volatile uint8_t *port_pin_ctrl = ((uint8_t *)&PORTA + 0x10 + pin); + + *port_pin_ctrl = (*port_pin_ctrl & ~PORT_ISC_gm) | isc; +} + +/** + * @ingroup pinsdriver + * @brief Set port data direction, Select if the pin data direction is input, output or disabled. + * If disabled state is not possible, this function throws an assert. + * + * @param mask Bit mask where 1 means apply direction setting to the + * corresponding pin + * @param dir port_dir + * @return none + */ +static inline void PORTA_set_port_dir(const uint8_t mask, const enum port_dir dir) +{ + switch (dir) { + case PORT_DIR_IN: + VPORTA.DIR &= ~mask; + break; + case PORT_DIR_OUT: + VPORTA.DIR |= mask; + break; + case PORT_DIR_OFF: + /*/ should activate the pullup for power saving + but a bit costly to do it here */ + { + for (uint8_t i = 0; i < 8; i++) { + if (mask & 1 << i) { + *((uint8_t *)&PORTA + 0x10 + i) |= 1 << PORT_PULLUPEN_bp; + } + } + } + break; + default: + break; + } +} + +/** + * @ingroup pinsdriver + * @brief Set port pin data direction, Select if the pin data direction is input, output or disabled. + * If disabled state is not possible, this function throws an assert. + * + * @param pin The pin number within port + * @param dir port_dir + * @return none + */ +static inline void PORTA_set_pin_dir(const uint8_t pin, const enum port_dir dir) +{ + switch (dir) { + case PORT_DIR_IN: + VPORTA.DIR &= ~(1 << pin); + break; + case PORT_DIR_OUT: + VPORTA.DIR |= (1 << pin); + break; + case PORT_DIR_OFF: + *((uint8_t *)&PORTA + 0x10 + pin) |= 1 << PORT_PULLUPEN_bp; + break; + default: + break; + } +} + +/** + * @ingroup pinsdriver + * @brief Set port level, Sets output level on the pins defined by the bit mask. + * + * @param mask Bit mask where 1 means apply port level to the corresponding + * pin + * @param level -boolean value that defines the logic state of the pin level + * false = Pin levels set to "low" state + * @return none + */ +static inline void PORTA_set_port_level(const uint8_t mask, const bool level) +{ + if (level == true) { + VPORTA.OUT |= mask; + } else { + VPORTA.OUT &= ~mask; + } +} + +/** + * @ingroup pinsdriver + * @brief Set port level, Sets output level on a pin. + * + * @param pin The pin number within port + * @param level -boolean value that defines the logic state of the pin level + * @return none + */ +static inline void PORTA_set_pin_level(const uint8_t pin, const bool level) +{ + if (level == true) { + VPORTA.OUT |= (1 << pin); + } else { + VPORTA.OUT &= ~(1 << pin); + } +} + +/** + * @ingroup pinsdriver + * @brief Toggle out level on pins, Toggle the pin levels on pins defined by bit mask. + * + * @param mask Bit mask where 1 means toggle pin level to the corresponding + * pin + * @return none + */ +static inline void PORTA_toggle_port_level(const uint8_t mask) +{ + PORTA.OUTTGL = mask; +} + +/** + * @ingroup pinsdriver + * @brief Toggle output level on pin, Toggle the pin levels on pins defined by bit mask. + * + * @param pin The pin number within port + * @return none + */ +static inline void PORTA_toggle_pin_level(const uint8_t pin) +{ + PORTA.OUTTGL = 1 << pin; +} + +/** + * @ingroup pinsdriver + * @brief Get input level on pins, Read the input level on pins connected to a port. + * + * @param none + * @return none + */ +static inline uint8_t PORTA_get_port_level() +{ + return VPORTA.IN; +} + +/** + * @ingroup pinsdriver + * @brief Get level on pin, Reads the level on pins connected to a port. + * + * @param pin The pin number within port + * @return none + */ +static inline bool PORTA_get_pin_level(const uint8_t pin) +{ + return VPORTA.IN & (1 << pin); +} + +/** + * @ingroup pinsdriver + * @brief Write value to Port, Write directly to the port OUT register. + * + * @param value Value to write to the port register + * @return none + */ +static inline void PORTA_write_port(const uint8_t value) +{ + VPORTA.OUT = value; +} + +/** + * @ingroup pinsdriver + * @brief Set port pin pull mode, Configure pin to pull up, down or disable pull mode, supported pull modes are defined by device used. + * @param pin The pin number within port + * @param pull_mode Pin pull mode + * @return none + */ +static inline void PORTC_set_pin_pull_mode(const uint8_t pin, const enum port_pull_mode pull_mode) +{ + volatile uint8_t *port_pin_ctrl = ((uint8_t *)&PORTC + 0x10 + pin); + + if (pull_mode == PORT_PULL_UP) { + *port_pin_ctrl |= PORT_PULLUPEN_bm; + } else if (pull_mode == PORT_PULL_OFF) { + *port_pin_ctrl &= ~PORT_PULLUPEN_bm; + } +} + +/** + * @ingroup pinsdriver + * @brief Set port pin inverted mode, Configure pin invert I/O or not. + * @param pin The pin number within port + * @param inverted Pin inverted mode + * @return none + */ +static inline void PORTC_pin_set_inverted(const uint8_t pin, const bool inverted) +{ + volatile uint8_t *port_pin_ctrl = ((uint8_t *)&PORTC + 0x10 + pin); + + if (inverted) { + *port_pin_ctrl |= PORT_INVEN_bm; + } else { + *port_pin_ctrl &= ~PORT_INVEN_bm; + } +} + +/** + * @ingroup pinsdriver + * @brief Set port pin input/sense configuration, Enable/disable digital input buffer and pin change interrupt, + * select pin interrupt edge/level sensing mode + * @param The pin number within port + * @param isc PORT_ISC_t + * @return none + */ +static inline void PORTC_pin_set_isc(const uint8_t pin, const PORT_ISC_t isc) +{ + volatile uint8_t *port_pin_ctrl = ((uint8_t *)&PORTC + 0x10 + pin); + + *port_pin_ctrl = (*port_pin_ctrl & ~PORT_ISC_gm) | isc; +} + +/** + * @ingroup pinsdriver + * @brief Set port data direction, Select if the pin data direction is input, output or disabled. + * If disabled state is not possible, this function throws an assert. + * + * @param mask Bit mask where 1 means apply direction setting to the + * corresponding pin + * @param dir port_dir + * @return none + */ +static inline void PORTC_set_port_dir(const uint8_t mask, const enum port_dir dir) +{ + switch (dir) { + case PORT_DIR_IN: + VPORTC.DIR &= ~mask; + break; + case PORT_DIR_OUT: + VPORTC.DIR |= mask; + break; + case PORT_DIR_OFF: + /*/ should activate the pullup for power saving + but a bit costly to do it here */ + { + for (uint8_t i = 0; i < 8; i++) { + if (mask & 1 << i) { + *((uint8_t *)&PORTC + 0x10 + i) |= 1 << PORT_PULLUPEN_bp; + } + } + } + break; + default: + break; + } +} + +/** + * @ingroup pinsdriver + * @brief Set port pin data direction, Select if the pin data direction is input, output or disabled. + * If disabled state is not possible, this function throws an assert. + * + * @param pin The pin number within port + * @param dir port_dir + * @return none + */ +static inline void PORTC_set_pin_dir(const uint8_t pin, const enum port_dir dir) +{ + switch (dir) { + case PORT_DIR_IN: + VPORTC.DIR &= ~(1 << pin); + break; + case PORT_DIR_OUT: + VPORTC.DIR |= (1 << pin); + break; + case PORT_DIR_OFF: + *((uint8_t *)&PORTC + 0x10 + pin) |= 1 << PORT_PULLUPEN_bp; + break; + default: + break; + } +} + +/** + * @ingroup pinsdriver + * @brief Set port level, Sets output level on the pins defined by the bit mask. + * + * @param mask Bit mask where 1 means apply port level to the corresponding + * pin + * @param level -boolean value that defines the logic state of the pin level + * false = Pin levels set to "low" state + * @return none + */ +static inline void PORTC_set_port_level(const uint8_t mask, const bool level) +{ + if (level == true) { + VPORTC.OUT |= mask; + } else { + VPORTC.OUT &= ~mask; + } +} + +/** + * @ingroup pinsdriver + * @brief Set port level, Sets output level on a pin. + * + * @param pin The pin number within port + * @param level -boolean value that defines the logic state of the pin level + * @return none + */ +static inline void PORTC_set_pin_level(const uint8_t pin, const bool level) +{ + if (level == true) { + VPORTC.OUT |= (1 << pin); + } else { + VPORTC.OUT &= ~(1 << pin); + } +} + +/** + * @ingroup pinsdriver + * @brief Toggle out level on pins, Toggle the pin levels on pins defined by bit mask. + * + * @param mask Bit mask where 1 means toggle pin level to the corresponding + * pin + * @return none + */ +static inline void PORTC_toggle_port_level(const uint8_t mask) +{ + PORTC.OUTTGL = mask; +} + +/** + * @ingroup pinsdriver + * @brief Toggle output level on pin, Toggle the pin levels on pins defined by bit mask. + * + * @param pin The pin number within port + * @return none + */ +static inline void PORTC_toggle_pin_level(const uint8_t pin) +{ + PORTC.OUTTGL = 1 << pin; +} + +/** + * @ingroup pinsdriver + * @brief Get input level on pins, Read the input level on pins connected to a port. + * + * @param none + * @return none + */ +static inline uint8_t PORTC_get_port_level() +{ + return VPORTC.IN; +} + +/** + * @ingroup pinsdriver + * @brief Get level on pin, Reads the level on pins connected to a port. + * + * @param pin The pin number within port + * @return none + */ +static inline bool PORTC_get_pin_level(const uint8_t pin) +{ + return VPORTC.IN & (1 << pin); +} + +/** + * @ingroup pinsdriver + * @brief Write value to Port, Write directly to the port OUT register. + * + * @param value Value to write to the port register + * @return none + */ +static inline void PORTC_write_port(const uint8_t value) +{ + VPORTC.OUT = value; +} + +/** + * @ingroup pinsdriver + * @brief Set port pin pull mode, Configure pin to pull up, down or disable pull mode, supported pull modes are defined by device used. + * @param pin The pin number within port + * @param pull_mode Pin pull mode + * @return none + */ +static inline void PORTD_set_pin_pull_mode(const uint8_t pin, const enum port_pull_mode pull_mode) +{ + volatile uint8_t *port_pin_ctrl = ((uint8_t *)&PORTD + 0x10 + pin); + + if (pull_mode == PORT_PULL_UP) { + *port_pin_ctrl |= PORT_PULLUPEN_bm; + } else if (pull_mode == PORT_PULL_OFF) { + *port_pin_ctrl &= ~PORT_PULLUPEN_bm; + } +} + +/** + * @ingroup pinsdriver + * @brief Set port pin inverted mode, Configure pin invert I/O or not. + * @param pin The pin number within port + * @param inverted Pin inverted mode + * @return none + */ +static inline void PORTD_pin_set_inverted(const uint8_t pin, const bool inverted) +{ + volatile uint8_t *port_pin_ctrl = ((uint8_t *)&PORTD + 0x10 + pin); + + if (inverted) { + *port_pin_ctrl |= PORT_INVEN_bm; + } else { + *port_pin_ctrl &= ~PORT_INVEN_bm; + } +} + +/** + * @ingroup pinsdriver + * @brief Set port pin input/sense configuration, Enable/disable digital input buffer and pin change interrupt, + * select pin interrupt edge/level sensing mode + * @param The pin number within port + * @param isc PORT_ISC_t + * @return none + */ +static inline void PORTD_pin_set_isc(const uint8_t pin, const PORT_ISC_t isc) +{ + volatile uint8_t *port_pin_ctrl = ((uint8_t *)&PORTD + 0x10 + pin); + + *port_pin_ctrl = (*port_pin_ctrl & ~PORT_ISC_gm) | isc; +} + +/** + * @ingroup pinsdriver + * @brief Set port data direction, Select if the pin data direction is input, output or disabled. + * If disabled state is not possible, this function throws an assert. + * + * @param mask Bit mask where 1 means apply direction setting to the + * corresponding pin + * @param dir port_dir + * @return none + */ +static inline void PORTD_set_port_dir(const uint8_t mask, const enum port_dir dir) +{ + switch (dir) { + case PORT_DIR_IN: + VPORTD.DIR &= ~mask; + break; + case PORT_DIR_OUT: + VPORTD.DIR |= mask; + break; + case PORT_DIR_OFF: + /*/ should activate the pullup for power saving + but a bit costly to do it here */ + { + for (uint8_t i = 0; i < 8; i++) { + if (mask & 1 << i) { + *((uint8_t *)&PORTD + 0x10 + i) |= 1 << PORT_PULLUPEN_bp; + } + } + } + break; + default: + break; + } +} + +/** + * @ingroup pinsdriver + * @brief Set port pin data direction, Select if the pin data direction is input, output or disabled. + * If disabled state is not possible, this function throws an assert. + * + * @param pin The pin number within port + * @param dir port_dir + * @return none + */ +static inline void PORTD_set_pin_dir(const uint8_t pin, const enum port_dir dir) +{ + switch (dir) { + case PORT_DIR_IN: + VPORTD.DIR &= ~(1 << pin); + break; + case PORT_DIR_OUT: + VPORTD.DIR |= (1 << pin); + break; + case PORT_DIR_OFF: + *((uint8_t *)&PORTD + 0x10 + pin) |= 1 << PORT_PULLUPEN_bp; + break; + default: + break; + } +} + +/** + * @ingroup pinsdriver + * @brief Set port level, Sets output level on the pins defined by the bit mask. + * + * @param mask Bit mask where 1 means apply port level to the corresponding + * pin + * @param level -boolean value that defines the logic state of the pin level + * false = Pin levels set to "low" state + * @return none + */ +static inline void PORTD_set_port_level(const uint8_t mask, const bool level) +{ + if (level == true) { + VPORTD.OUT |= mask; + } else { + VPORTD.OUT &= ~mask; + } +} + +/** + * @ingroup pinsdriver + * @brief Set port level, Sets output level on a pin. + * + * @param pin The pin number within port + * @param level -boolean value that defines the logic state of the pin level + * @return none + */ +static inline void PORTD_set_pin_level(const uint8_t pin, const bool level) +{ + if (level == true) { + VPORTD.OUT |= (1 << pin); + } else { + VPORTD.OUT &= ~(1 << pin); + } +} + +/** + * @ingroup pinsdriver + * @brief Toggle out level on pins, Toggle the pin levels on pins defined by bit mask. + * + * @param mask Bit mask where 1 means toggle pin level to the corresponding + * pin + * @return none + */ +static inline void PORTD_toggle_port_level(const uint8_t mask) +{ + PORTD.OUTTGL = mask; +} + +/** + * @ingroup pinsdriver + * @brief Toggle output level on pin, Toggle the pin levels on pins defined by bit mask. + * + * @param pin The pin number within port + * @return none + */ +static inline void PORTD_toggle_pin_level(const uint8_t pin) +{ + PORTD.OUTTGL = 1 << pin; +} + +/** + * @ingroup pinsdriver + * @brief Get input level on pins, Read the input level on pins connected to a port. + * + * @param none + * @return none + */ +static inline uint8_t PORTD_get_port_level() +{ + return VPORTD.IN; +} + +/** + * @ingroup pinsdriver + * @brief Get level on pin, Reads the level on pins connected to a port. + * + * @param pin The pin number within port + * @return none + */ +static inline bool PORTD_get_pin_level(const uint8_t pin) +{ + return VPORTD.IN & (1 << pin); +} + +/** + * @ingroup pinsdriver + * @brief Write value to Port, Write directly to the port OUT register. + * + * @param value Value to write to the port register + * @return none + */ +static inline void PORTD_write_port(const uint8_t value) +{ + VPORTD.OUT = value; +} + +/** + * @ingroup pinsdriver + * @brief Set port pin pull mode, Configure pin to pull up, down or disable pull mode, supported pull modes are defined by device used. + * @param pin The pin number within port + * @param pull_mode Pin pull mode + * @return none + */ +static inline void PORTF_set_pin_pull_mode(const uint8_t pin, const enum port_pull_mode pull_mode) +{ + volatile uint8_t *port_pin_ctrl = ((uint8_t *)&PORTF + 0x10 + pin); + + if (pull_mode == PORT_PULL_UP) { + *port_pin_ctrl |= PORT_PULLUPEN_bm; + } else if (pull_mode == PORT_PULL_OFF) { + *port_pin_ctrl &= ~PORT_PULLUPEN_bm; + } +} + +/** + * @ingroup pinsdriver + * @brief Set port pin inverted mode, Configure pin invert I/O or not. + * @param pin The pin number within port + * @param inverted Pin inverted mode + * @return none + */ +static inline void PORTF_pin_set_inverted(const uint8_t pin, const bool inverted) +{ + volatile uint8_t *port_pin_ctrl = ((uint8_t *)&PORTF + 0x10 + pin); + + if (inverted) { + *port_pin_ctrl |= PORT_INVEN_bm; + } else { + *port_pin_ctrl &= ~PORT_INVEN_bm; + } +} + +/** + * @ingroup pinsdriver + * @brief Set port pin input/sense configuration, Enable/disable digital input buffer and pin change interrupt, + * select pin interrupt edge/level sensing mode + * @param The pin number within port + * @param isc PORT_ISC_t + * @return none + */ +static inline void PORTF_pin_set_isc(const uint8_t pin, const PORT_ISC_t isc) +{ + volatile uint8_t *port_pin_ctrl = ((uint8_t *)&PORTF + 0x10 + pin); + + *port_pin_ctrl = (*port_pin_ctrl & ~PORT_ISC_gm) | isc; +} + +/** + * @ingroup pinsdriver + * @brief Set port data direction, Select if the pin data direction is input, output or disabled. + * If disabled state is not possible, this function throws an assert. + * + * @param mask Bit mask where 1 means apply direction setting to the + * corresponding pin + * @param dir port_dir + * @return none + */ +static inline void PORTF_set_port_dir(const uint8_t mask, const enum port_dir dir) +{ + switch (dir) { + case PORT_DIR_IN: + VPORTF.DIR &= ~mask; + break; + case PORT_DIR_OUT: + VPORTF.DIR |= mask; + break; + case PORT_DIR_OFF: + /*/ should activate the pullup for power saving + but a bit costly to do it here */ + { + for (uint8_t i = 0; i < 8; i++) { + if (mask & 1 << i) { + *((uint8_t *)&PORTF + 0x10 + i) |= 1 << PORT_PULLUPEN_bp; + } + } + } + break; + default: + break; + } +} + +/** + * @ingroup pinsdriver + * @brief Set port pin data direction, Select if the pin data direction is input, output or disabled. + * If disabled state is not possible, this function throws an assert. + * + * @param pin The pin number within port + * @param dir port_dir + * @return none + */ +static inline void PORTF_set_pin_dir(const uint8_t pin, const enum port_dir dir) +{ + switch (dir) { + case PORT_DIR_IN: + VPORTF.DIR &= ~(1 << pin); + break; + case PORT_DIR_OUT: + VPORTF.DIR |= (1 << pin); + break; + case PORT_DIR_OFF: + *((uint8_t *)&PORTF + 0x10 + pin) |= 1 << PORT_PULLUPEN_bp; + break; + default: + break; + } +} + +/** + * @ingroup pinsdriver + * @brief Set port level, Sets output level on the pins defined by the bit mask. + * + * @param mask Bit mask where 1 means apply port level to the corresponding + * pin + * @param level -boolean value that defines the logic state of the pin level + * false = Pin levels set to "low" state + * @return none + */ +static inline void PORTF_set_port_level(const uint8_t mask, const bool level) +{ + if (level == true) { + VPORTF.OUT |= mask; + } else { + VPORTF.OUT &= ~mask; + } +} + +/** + * @ingroup pinsdriver + * @brief Set port level, Sets output level on a pin. + * + * @param pin The pin number within port + * @param level -boolean value that defines the logic state of the pin level + * @return none + */ +static inline void PORTF_set_pin_level(const uint8_t pin, const bool level) +{ + if (level == true) { + VPORTF.OUT |= (1 << pin); + } else { + VPORTF.OUT &= ~(1 << pin); + } +} + +/** + * @ingroup pinsdriver + * @brief Toggle out level on pins, Toggle the pin levels on pins defined by bit mask. + * + * @param mask Bit mask where 1 means toggle pin level to the corresponding + * pin + * @return none + */ +static inline void PORTF_toggle_port_level(const uint8_t mask) +{ + PORTF.OUTTGL = mask; +} + +/** + * @ingroup pinsdriver + * @brief Toggle output level on pin, Toggle the pin levels on pins defined by bit mask. + * + * @param pin The pin number within port + * @return none + */ +static inline void PORTF_toggle_pin_level(const uint8_t pin) +{ + PORTF.OUTTGL = 1 << pin; +} + +/** + * @ingroup pinsdriver + * @brief Get input level on pins, Read the input level on pins connected to a port. + * + * @param none + * @return none + */ +static inline uint8_t PORTF_get_port_level() +{ + return VPORTF.IN; +} + +/** + * @ingroup pinsdriver + * @brief Get level on pin, Reads the level on pins connected to a port. + * + * @param pin The pin number within port + * @return none + */ +static inline bool PORTF_get_pin_level(const uint8_t pin) +{ + return VPORTF.IN & (1 << pin); +} + +/** + * @ingroup pinsdriver + * @brief Write value to Port, Write directly to the port OUT register. + * + * @param value Value to write to the port register + * @return none + */ +static inline void PORTF_write_port(const uint8_t value) +{ + VPORTF.OUT = value; +} +#ifdef __cplusplus +} +#endif + +#endif /* PORT_INCLUDED */ \ No newline at end of file diff --git a/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/system/protected_io.h b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/system/protected_io.h new file mode 100644 index 0000000..74e1fb5 --- /dev/null +++ b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/system/protected_io.h @@ -0,0 +1,80 @@ +/** + * protected_io Header File + * + * @file protected_io.h + * + * @defgroup doc_driver_system_protected_io Protected IO + * + * @brief This file contains the generated prtected_io header file for the CONFIGURATION BITS. + * + * @version Driver Version 1.0.0 + * + *@{ +*/ +/* +© [2024] Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip + software and any derivatives exclusively with Microchip products. + You are responsible for complying with 3rd party license terms + applicable to your use of 3rd party software (including open source + software) that may accompany Microchip software. SOFTWARE IS ?AS IS.? + NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS + SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, + MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT + WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY + KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF + MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE + FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S + TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT + EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR + THIS SOFTWARE. +*/ + +#ifndef PROTECTED_IO_H +#define PROTECTED_IO_H + +#ifdef __cplusplus +extern "C" { +#endif + +#if defined(__DOXYGEN__) +//! \name IAR Memory Model defines. +//@{ + +/** + * @def CONFIG_MEMORY_MODEL_TINY + * @brief Configuration symbol to enable 8 bit pointers. + */ +#define CONFIG_MEMORY_MODEL_TINY + +/** + * @def CONFIG_MEMORY_MODEL_SMALL + * @brief Configuration symbol to enable 16 bit pointers. + * NOTE: If no memory model is defined, SMALL is default. + */ +#define CONFIG_MEMORY_MODEL_SMALL + +/** + * @def CONFIG_MEMORY_MODEL_LARGE + * @brief Configuration symbol to enable 24 bit pointers. + */ +#define CONFIG_MEMORY_MODEL_LARGE + +//@} +#endif + +/** + * @brief Writes to an 8-bit I/O register protected by CCP or a protection bit. + * @param addr Address of the I/O register. + * @param magic CCP magic value or Mask for protection bit. + * @param value Value to be written. + * NOTE: Using IAR Embedded workbench, the choice of memory model has an impact on calling convention. + * Memory model must be defined in the Assembler preprocessor directives to be visible to the preprocessor. + */ +extern void protected_write_io(void *addr, uint8_t magic, uint8_t value); + +/** @} */ + +#endif /* PROTECTED_IO_H */ diff --git a/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/system/src/clock.c b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/system/src/clock.c new file mode 100644 index 0000000..67f5bdc --- /dev/null +++ b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/system/src/clock.c @@ -0,0 +1,105 @@ + + +/** + * CLKCTRL Generated Driver File + * + * @file clkctrl.c + * + * @ingroup clkctrl + * + * @brief This file contains the driver code for CLKCTRL module. + * + * version CLKCTRL Driver Version 1.1.4 + * + * @version Package Version 2.0.9 +*/ +/* +© [2024] Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip + software and any derivatives exclusively with Microchip products. + You are responsible for complying with 3rd party license terms + applicable to your use of 3rd party software (including open source + software) that may accompany Microchip software. SOFTWARE IS ?AS IS.? + NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS + SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, + MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT + WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY + KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF + MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE + FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S + TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT + EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR + THIS SOFTWARE. +*/ + + +#include "../clock.h" + +void CLOCK_Initialize(void) +{ + ccp_write_io((void*)&(CLKCTRL.MCLKCTRLA),(0 << CLKCTRL_CLKOUT_bp) // CLKOUT disabled + | CLKCTRL_CLKSEL_OSCHF_gc // CLKSEL Internal high-frequency oscillator + ); + ccp_write_io((void*)&(CLKCTRL.MCLKCTRLB),CLKCTRL_PDIV_DIV2_gc // PDIV Divide by 2 + | (0 << CLKCTRL_PEN_bp) // PEN disabled + ); + ccp_write_io((void*)&(CLKCTRL.OSC32KCTRLA),(0 << CLKCTRL_RUNSTDBY_bp) // RUNSTDBY disabled + ); + ccp_write_io((void*)&(CLKCTRL.OSCHFCTRLA),CLKCTRL_AUTOTUNE_OFF_gc // AUTOTUNE OFF + | CLKCTRL_FRQSEL_24M_gc // FRQSEL 24 MHz system clock + | (0 << CLKCTRL_RUNSTDBY_bp) // RUNSTDBY disabled + | CLKCTRL_ALGSEL_BIN_gc // ALGSEL BIN + ); + ccp_write_io((void*)&(CLKCTRL.OSCHFTUNE),0x0 // TUNE 0x0 + ); + + ccp_write_io((void*)&(CLKCTRL.XOSC32KCTRLA),CLKCTRL_CSUT_1K_gc // CSUT 1k cycles + | (0 << CLKCTRL_ENABLE_bp) // ENABLE disabled + | (0 << CLKCTRL_LPMODE_bp) // LPMODE disabled + | (0 << CLKCTRL_RUNSTDBY_bp) // RUNSTDBY disabled + | CLKCTRL_SEL_XTAL_gc // SEL XTAL + ); + ccp_write_io((void*)&(CLKCTRL.MCLKCTRLC),(0 << CLKCTRL_CFDEN_bp) // CFDEN disabled + | CLKCTRL_CFDSRC_CLKMAIN_gc // CFDSRC CLKMAIN + | (0 << CLKCTRL_CFDTST_bp) // CFDTST disabled + ); + ccp_write_io((void*)&(CLKCTRL.MCLKINTCTRL),(0 << CLKCTRL_CFD_bp) // CFD disabled + | CLKCTRL_INTTYPE_INT_gc // INTTYPE INT + ); + ccp_write_io((void*)&(CLKCTRL.MCLKINTFLAGS),(0 << CLKCTRL_CFD_bp) // CFD disabled + ); + ccp_write_io((void*)&(CLKCTRL.XOSCHFCTRLA),CLKCTRL_CSUTHF_256_gc // CSUTHF 256 + | (0 << CLKCTRL_ENABLE_bp) // ENABLE disabled + | CLKCTRL_FRQRANGE_8M_gc // FRQRANGE 8M + | (0 << CLKCTRL_RUNSTBY_bp) // RUNSTBY disabled + | CLKCTRL_SELHF_XTAL_gc // SELHF XTAL + ); + + ccp_write_io((void*)&(CLKCTRL.MCLKTIMEBASE),0x18 // TIMEBASE 24 + ); + + // System clock stability check by polling the status register. + while(!(CLKCTRL.MCLKSTATUS & CLKCTRL_OSCHFS_bm)) + { + } + +} + +void CFD_Enable(CLKCTRL_CFDSRC_t cfd_source) +{ + /* Enable Clock Failure Detection on main clock */ + ccp_write_io((uint8_t *) & CLKCTRL.MCLKCTRLC, cfd_source | CLKCTRL_CFDEN_bm); +} + +void CFD_Disable(void) +{ + /* Disable Clock Failure Detection on main clock */ + ccp_write_io((uint8_t *) & CLKCTRL.MCLKCTRLC, CLKCTRL.MCLKCTRLC & ~CLKCTRL_CFDEN_bm); +} + + +/** + End of File +*/ \ No newline at end of file diff --git a/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/system/src/config_bits.c b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/system/src/config_bits.c new file mode 100644 index 0000000..f52a4f2 --- /dev/null +++ b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/system/src/config_bits.c @@ -0,0 +1,50 @@ +/** + * CONFIGURATION BITS Generated Driver Source File + * + * @file config_bits.c + * + * @ingroup config_bitsdriver + * + * @brief This file contains the API implementation for the Device Configuration Bits driver. + * + * @version Driver Version 1.0.5 + * + * @version Package Version 4.2.14 +*/ +/* +© [2024] Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip + software and any derivatives exclusively with Microchip products. + You are responsible for complying with 3rd party license terms + applicable to your use of 3rd party software (including open source + software) that may accompany Microchip software. SOFTWARE IS ?AS IS.? + NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS + SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, + MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT + WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY + KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF + MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE + FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S + TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT + EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR + THIS SOFTWARE. +*/ + +#include + +/** + * Configures the Fuse bits. + */ +FUSES = +{ + .BODCFG = ACTIVE_DISABLE_gc | LVL_BODLEVEL0_gc | SAMPFREQ_128Hz_gc | SLEEP_DISABLE_gc, + .BOOTSIZE = 0x0, + .CODESIZE = 0x0, + .OSCCFG = CLKSEL_OSCHF_gc, + .PDICFG = KEY_NOTACT_gc | LEVEL_BASIC_gc, + .SYSCFG0 = CRCSEL_CRC16_gc | CRCSRC_NOCRC_gc | RSTPINCFG_GPIO_gc | UPDIPINCFG_UPDI_gc, + .SYSCFG1 = SUT_0MS_gc | USBSINK_ENABLE_gc, + .WDTCFG = PERIOD_OFF_gc | WINDOW_OFF_gc, +}; diff --git a/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/system/src/interrupt.c b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/system/src/interrupt.c new file mode 100644 index 0000000..f5169f3 --- /dev/null +++ b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/system/src/interrupt.c @@ -0,0 +1,53 @@ +/** + * Interrupt Manager Generated Driver File. + * + * @file interrupt.c + * + * @ingroup interrupt + * + * @brief This file contains the API implementation for the Interrupt Manager. + * + * @version Interrupt Manager Driver Version 1.0.0 +*/ + +/* +© [2024] Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip + software and any derivatives exclusively with Microchip products. + You are responsible for complying with 3rd party license terms + applicable to your use of 3rd party software (including open source + software) that may accompany Microchip software. SOFTWARE IS ?AS IS.? + NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS + SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, + MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT + WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY + KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF + MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE + FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S + TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT + EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR + THIS SOFTWARE. +*/ + + +#include "../interrupt.h" + +int8_t CPUINT_Initialize() +{ + /* IVSEL and CVT are Configuration Change Protected */ + + //CVT disabled; IVSEL disabled; LVL0RR disabled; + ccp_write_io((void*)&(CPUINT.CTRLA),0x0); + + //LVL0PRI 0; + CPUINT.LVL0PRI = 0x0; + + //LVL1VEC 0; + CPUINT.LVL1VEC = 0x0; + + ENABLE_INTERRUPTS(); + + return 0; +} \ No newline at end of file diff --git a/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/system/src/pins.c b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/system/src/pins.c new file mode 100644 index 0000000..e858cf7 --- /dev/null +++ b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/system/src/pins.c @@ -0,0 +1,145 @@ +/** + * Generated Driver File + * + * @file pins.c + * + * @ingroup pinsdriver + * + * @brief This is generated driver implementation for pins. + * This file provides implementations for pin APIs for all pins selected in the GUI. + * + * @version Driver Version 1.1.0 +*/ + +/* +© [2024] Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip + software and any derivatives exclusively with Microchip products. + You are responsible for complying with 3rd party license terms + applicable to your use of 3rd party software (including open source + software) that may accompany Microchip software. SOFTWARE IS ?AS IS.? + NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS + SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, + MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT + WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY + KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF + MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE + FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S + TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT + EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR + THIS SOFTWARE. +*/ + +#include "../pins.h" + +static void (*IO_PC3_InterruptHandler)(void); + +void PIN_MANAGER_Initialize() +{ + + /* OUT Registers Initialization */ + PORTA.OUT = 0x0; + PORTC.OUT = 0x0; + PORTD.OUT = 0x0; + PORTF.OUT = 0x0; + + /* DIR Registers Initialization */ + PORTA.DIR = 0x0; + PORTC.DIR = 0x0; + PORTD.DIR = 0x0; + PORTF.DIR = 0x0; + + /* PINxCTRL registers Initialization */ + PORTA.PIN0CTRL = 0x0; + PORTA.PIN1CTRL = 0x0; + PORTA.PIN2CTRL = 0x0; + PORTA.PIN3CTRL = 0x0; + PORTA.PIN4CTRL = 0x0; + PORTA.PIN5CTRL = 0x0; + PORTA.PIN6CTRL = 0x0; + PORTA.PIN7CTRL = 0x0; + PORTC.PIN0CTRL = 0x0; + PORTC.PIN1CTRL = 0x0; + PORTC.PIN2CTRL = 0x0; + PORTC.PIN3CTRL = 0x4; + PORTC.PIN4CTRL = 0x0; + PORTC.PIN5CTRL = 0x0; + PORTC.PIN6CTRL = 0x0; + PORTC.PIN7CTRL = 0x0; + PORTD.PIN0CTRL = 0x0; + PORTD.PIN1CTRL = 0x0; + PORTD.PIN2CTRL = 0x0; + PORTD.PIN3CTRL = 0x0; + PORTD.PIN4CTRL = 0x0; + PORTD.PIN5CTRL = 0x0; + PORTD.PIN6CTRL = 0x0; + PORTD.PIN7CTRL = 0x0; + PORTF.PIN0CTRL = 0x0; + PORTF.PIN1CTRL = 0x0; + PORTF.PIN2CTRL = 0x0; + PORTF.PIN3CTRL = 0x0; + PORTF.PIN4CTRL = 0x0; + PORTF.PIN5CTRL = 0x0; + PORTF.PIN6CTRL = 0x0; + PORTF.PIN7CTRL = 0x0; + + /* PORTMUX Initialization */ + PORTMUX.CCLROUTEA = 0x0; + PORTMUX.EVSYSROUTEA = 0x0; + PORTMUX.SPIROUTEA = 0x0; + PORTMUX.TCAROUTEA = 0x0; + PORTMUX.TCBROUTEA = 0x0; + PORTMUX.TWIROUTEA = 0x0; + PORTMUX.USARTROUTEA = 0x0; + + // register default ISC callback functions at runtime; use these methods to register a custom function + IO_PC3_SetInterruptHandler(IO_PC3_DefaultInterruptHandler); +} + +/** + Allows selecting an interrupt handler for IO_PC3 at application runtime +*/ +void IO_PC3_SetInterruptHandler(void (* interruptHandler)(void)) +{ + IO_PC3_InterruptHandler = interruptHandler; +} + +void IO_PC3_DefaultInterruptHandler(void) +{ + // add your IO_PC3 interrupt custom code + // or set custom function using IO_PC3_SetInterruptHandler() +} +ISR(PORTA_PORT_vect) +{ + /* Clear interrupt flags */ + VPORTA.INTFLAGS = 0xff; +} + +ISR(PORTC_PORT_vect) +{ + // Call the interrupt handler for the callback registered at runtime + if(VPORTC.INTFLAGS & PORT_INT3_bm) + { + IO_PC3_InterruptHandler(); + } + /* Clear interrupt flags */ + VPORTC.INTFLAGS = 0xff; +} + +ISR(PORTD_PORT_vect) +{ + /* Clear interrupt flags */ + VPORTD.INTFLAGS = 0xff; +} + +ISR(PORTF_PORT_vect) +{ + /* Clear interrupt flags */ + VPORTF.INTFLAGS = 0xff; +} + +/** + End of File +*/ \ No newline at end of file diff --git a/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/system/src/protected_io.S b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/system/src/protected_io.S new file mode 100644 index 0000000..6aaf66e --- /dev/null +++ b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/system/src/protected_io.S @@ -0,0 +1,90 @@ +/** + * protected_io Source Code File + * + * @file protected_io.S + * + * @ingroup config_bitsdriver + * + * @brief This file contains the generated protected_io source code file for the CONFIGURATION BITS. + * + * @version Driver Version 1.0.0 +*/ +/* +© [2024] Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip + software and any derivatives exclusively with Microchip products. + You are responsible for complying with 3rd party license terms + applicable to your use of 3rd party software (including open source + software) that may accompany Microchip software. SOFTWARE IS ?AS IS.? + NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS + SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, + MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT + WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY + KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF + MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE + FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S + TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT + EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR + THIS SOFTWARE. +*/ + + +#include "../utils/assembler.h" + +/* + * GNU and IAR use different calling conventions. Since this is + * a very small and simple function to begin with, it's easier + * to implement it twice than to deal with the differences + * within a single implementation. + */ + + PUBLIC_FUNCTION(protected_write_io) + +#if defined(__GNUC__) + +#ifdef RAMPZ + out _SFR_IO_ADDR(RAMPZ), r1 // Clear bits 23:16 of Z +#endif + movw r30, r24 // Load addr into Z + out CCP, r22 // Start CCP handshake + st Z, r20 // Write value to I/O register + ret // Return to caller + +#elif defined(__IAR_SYSTEMS_ASM__) + +# if !defined(CONFIG_MEMORY_MODEL_TINY) && !defined(CONFIG_MEMORY_MODEL_SMALL) \ + && !defined(CONFIG_MEMORY_MODEL_LARGE) +# define CONFIG_MEMORY_MODEL_SMALL +# endif +# if defined(CONFIG_MEMORY_MODEL_LARGE) + ldi r20, 0 + out RAMPZ, r20 // Reset bits 23:16 of Z + movw r30, r16 // Load addr into Z +# elif defined(CONFIG_MEMORY_MODEL_TINY) + ldi r31, 0 // Reset bits 8:15 of Z + mov r30, r16 // Load addr into Z +# else + movw r30, r16 // Load addr into Z +# endif +# if defined(CONFIG_MEMORY_MODEL_TINY) + out CCP, r17 // Start CCP handshake + st Z, r18 // Write value to I/O register +# elif defined(CONFIG_MEMORY_MODEL_SMALL) + out CCP, r18 // Start CCP handshake + st Z, r19 // Write value to I/O register +# elif defined(CONFIG_MEMORY_MODEL_LARGE) + out CCP, r19 // Start CCP handshake + st Z, r20 // Write value to I/O register +# else +# error Unknown memory model in use, no idea how registers should be accessed +# endif + ret +#else +# error Unknown assembler +#endif + + END_FUNC(protected_write_io) + END_FILE() + diff --git a/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/system/src/syscfg.c b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/system/src/syscfg.c new file mode 100644 index 0000000..2efaf20 --- /dev/null +++ b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/system/src/syscfg.c @@ -0,0 +1,64 @@ + +/** + * SYSCFG Generated Driver File + * + * @file syscfg.c + * + * @ingroup syscfg + * + * @brief This is the generated driver implementation file for the SYSCFG driver. + * + * @version SYSCFG Driver Version 1.0.0 +*/ +/* +© [2024] Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip + software and any derivatives exclusively with Microchip products. + You are responsible for complying with 3rd party license terms + applicable to your use of 3rd party software (including open source + software) that may accompany Microchip software. SOFTWARE IS ?AS IS.? + NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS + SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, + MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT + WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY + KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF + MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE + FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S + TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT + EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR + THIS SOFTWARE. +*/ + +/** + Section: Included Files +*/ + +#include "../../system/utils/compiler.h" +#include "../syscfg.h" + +/** + Section: SYSCFG APIs +*/ + +void SYSCFG_Initialize(void) +{ + SYSCFG.VUSBCTRL = (0 << SYSCFG_USBVREG_bp); // USBVREG DISABLE; +} +uint8_t SYSCFG_GetRevId(void) +{ + return SYSCFG.REVID; +} +inline void SYSCFG_UsbVregEnable(void) +{ + SYSCFG.VUSBCTRL = SYSCFG_USBVREG_bm; +} +inline void SYSCFG_UsbVregDisable(void) +{ + SYSCFG.VUSBCTRL = ~SYSCFG_USBVREG_bm; +} + +/** + End of File +*/ \ No newline at end of file diff --git a/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/system/src/system.c b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/system/src/system.c new file mode 100644 index 0000000..aea8c6a --- /dev/null +++ b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/system/src/system.c @@ -0,0 +1,49 @@ +/** + * System Driver Source File + * + * @file system.c + * + * @ingroup systemdriver + * + * @brief This file contains the API implementation for the System driver. + * + * @version Driver Version 1.0.2 + * + * @version Package Version 4.2.14 +*/ +/* +© [2024] Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip + software and any derivatives exclusively with Microchip products. + You are responsible for complying with 3rd party license terms + applicable to your use of 3rd party software (including open source + software) that may accompany Microchip software. SOFTWARE IS ?AS IS.? + NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS + SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, + MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT + WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY + KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF + MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE + FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S + TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT + EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR + THIS SOFTWARE. +*/ + +#include "../system.h" + +void SYSTEM_Initialize(void) +{ + CLOCK_Initialize(); + SYSCFG_Initialize(); + PIN_MANAGER_Initialize(); + USB0_Initialize(); + AC0_Initialize(); + RTC_Initialize(); + VREF_Initialize(); + USBDevice_Initialize(); + CPUINT_Initialize(); +} + diff --git a/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/system/syscfg.h b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/system/syscfg.h new file mode 100644 index 0000000..617a7a7 --- /dev/null +++ b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/system/syscfg.h @@ -0,0 +1,83 @@ +/** + * SYSCFG Generated Driver API Header File + * + * @file syscfg.h + * + * @defgroup syscfg SYSCFG + * + * @brief This is the generated header file for the SYSCFG driver + * + * @version SYSCFG Driver Version 1.0.0 +*/ +/* +© [2024] Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip + software and any derivatives exclusively with Microchip products. + You are responsible for complying with 3rd party license terms + applicable to your use of 3rd party software (including open source + software) that may accompany Microchip software. SOFTWARE IS ?AS IS.? + NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS + SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, + MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT + WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY + KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF + MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE + FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S + TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT + EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR + THIS SOFTWARE. +*/ + +#ifndef SYSCFG_H +#define SYSCFG_H + +/** + Section: Included Files +*/ + +#include +#include + +/** + Section: SYSCFG APIs +*/ + +/** + * @ingroup syscfg + * @brief Initializes the SYSCFG driver. This routine is called only once during system initialization, before calling other APIs. + * @param None. + * @return None. + */ +void SYSCFG_Initialize(void); + +/** + * @ingroup syscfg + * @brief Returns the SYSCFG Revision ID. + * @param None. + * @return uint8_t + */ +uint8_t SYSCFG_GetRevId(void); + +/** + * @ingroup syscfg + * @brief Enables the SYSCFG USB voltage regulator. + * @param None. + * @return None. + */ + void SYSCFG_UsbVregEnable(void); + +/** + * @ingroup syscfg + * @brief Disables the SYSCFG USB voltage regulator. + * @param None. + * @return None. + */ +void SYSCFG_UsbVregDisable(void); + + +#endif // SYSCFG_H +/** + End of File +*/ diff --git a/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/system/system.h b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/system/system.h new file mode 100644 index 0000000..09583fb --- /dev/null +++ b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/system/system.h @@ -0,0 +1,68 @@ +/** + * System Driver Header File + * + * @file system.h + * + * @defgroup systemdriver System Driver + * + * @brief This file contains the API prototype for the System Driver. + * + * @version Driver Version 1.0.2 + * + * @version Package Version 4.2.14 +*/ +/* +© [2024] Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip + software and any derivatives exclusively with Microchip products. + You are responsible for complying with 3rd party license terms + applicable to your use of 3rd party software (including open source + software) that may accompany Microchip software. SOFTWARE IS ?AS IS.? + NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS + SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, + MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT + WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY + KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF + MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE + FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S + TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT + EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR + THIS SOFTWARE. +*/ + + +#ifndef MCC_H +#define MCC_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "../system/utils/compiler.h" +#include "config_bits.h" +#include "../system/pins.h" +#include "../usb/usb0.h" +#include "../ac/ac0.h" +#include "../timer/rtc.h" +#include "../vref/vref.h" +#include "../usb/usb_device.h" +#include "../system/interrupt.h" +#include "../system/clock.h" +#include "../system/syscfg.h" +/** + * @ingroup systemdriver + * @brief Initializes the System module. This routine is called only once during system initialization, before calling any other API. + * @param None. + * @return None. +*/ +void SYSTEM_Initialize(void); + +#ifdef __cplusplus +} +#endif +#endif /* MCC_H */ +/** + End of File +*/ \ No newline at end of file diff --git a/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/system/utils/assembler.h b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/system/utils/assembler.h new file mode 100644 index 0000000..0c6484a --- /dev/null +++ b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/system/utils/assembler.h @@ -0,0 +1,49 @@ +/** + * Assembler Header File + * + * @file assembler.h + * + * @ingroup config_bitsdriver + * + * @brief This file contains the assembler header file for the configuration bits driver. + * + * @version Driver Version 1.0.0 +*/ +/* +© [2024] Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip + software and any derivatives exclusively with Microchip products. + You are responsible for complying with 3rd party license terms + applicable to your use of 3rd party software (including open source + software) that may accompany Microchip software. SOFTWARE IS ?AS IS.? + NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS + SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, + MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT + WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY + KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF + MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE + FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S + TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT + EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR + THIS SOFTWARE. +*/ + + +#ifndef ASSEMBLER_H_INCLUDED +#define ASSEMBLER_H_INCLUDED + +#if !defined(__ASSEMBLER__) && !defined(__IAR_SYSTEMS_ASM__) && !defined(__DOXYGEN__) +#error This file may only be included from assembly files +#endif + +#if defined(__ASSEMBLER__) +#include "assembler/gas.h" +#include +#elif defined(__IAR_SYSTEMS_ASM__) +#include "assembler/iar.h" +#include +#endif + +#endif /* ASSEMBLER_H_INCLUDED */ diff --git a/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/system/utils/assembler/gas.h b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/system/utils/assembler/gas.h new file mode 100644 index 0000000..871a60a --- /dev/null +++ b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/system/utils/assembler/gas.h @@ -0,0 +1,120 @@ +/** + * GAS Header File + * + * @file gas.h + * + * @ingroup config_bitsdriver + * + * @brief This file contains the generated GAS header file for the Configuration bits driver. + * + * @version Driver Version 1.0.0 +*/ +/* +© [2024] Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip + software and any derivatives exclusively with Microchip products. + You are responsible for complying with 3rd party license terms + applicable to your use of 3rd party software (including open source + software) that may accompany Microchip software. SOFTWARE IS ?AS IS.? + NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS + SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, + MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT + WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY + KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF + MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE + FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S + TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT + EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR + THIS SOFTWARE. +*/ + + +#ifndef ASSEMBLER_GAS_H_INCLUDED +#define ASSEMBLER_GAS_H_INCLUDED + +#ifndef __DOXYGEN__ + +/* clang-format off */ + + /* IAR doesn't accept dots in macro names */ + .macro ld_addr, reg, sym + lda.w \reg, \sym + .endm + + /* Define a function \a name that is either globally visible or only + * file-local. + */ + .macro gas_begin_func name, is_public + .if \is_public + .global \name + .endif + #ifdef __XC8 + .section .text.\name, code + #else + .section .text.\name, "ax", @progbits + #endif + .type \name, @function + \name : + .endm + + /* Define a function \a name that is either globally visible or only + * file-local in a given segment. + */ + .macro gas_begin_func_segm name, is_public, segment + .if \is_public + .global \name + .endif + .section .\segment, "ax", @progbits + .type \name, @function + \name : + .endm + + /* Define \a name as a weak alias for the function \a strong_name */ + .macro gas_weak_function_alias name, strong_name + .global \name + .weak \name + .type \name, @function + .set \name, \strong_name + .endm + + /* Define a weak function called \a name */ + .macro gas_weak_function name + .weak \name + gas_begin_func \name 1 + .endm + +#define REPEAT(count) .rept count +#define END_REPEAT() .endr +#define FILL_BYTES(count) .fill count +#define SET_LOC(offset) .org offset +#define L(name) .L##name +#define EXTERN_SYMBOL(name) + +#define TEXT_SECTION(name) \ + .section name, "ax", @progbits +#define RODATA_SECTION(name) \ + .section name, "a", @progbits +#define DATA_SECTION(name) \ + .section name, "aw", @progbits +#define BSS_SECTION(name) \ + .section name, "aw", @nobits + +#define FUNCTION(name) gas_begin_func name 0 +#define PUBLIC_FUNCTION(name) gas_begin_func name 1 +#define PUBLIC_FUNCTION_SEGMENT(name, segment) \ + gas_begin_func_segm name 1 segment +#define WEAK_FUNCTION(name) gas_weak_function name +#define WEAK_FUNCTION_ALIAS(name, strong_name) \ + gas_weak_function_alias name strong_name +#define END_FUNC(name) \ + .size name, . - name + +#define END_FILE() + +/* clang-format on */ + +#endif /* __DOXYGEN__ */ + +#endif /* ASSEMBLER_GAS_H_INCLUDED */ diff --git a/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/system/utils/assembler/iar.h b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/system/utils/assembler/iar.h new file mode 100644 index 0000000..c52425f --- /dev/null +++ b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/system/utils/assembler/iar.h @@ -0,0 +1,104 @@ +/** + * IAR Header File + * + * @file iar.h + * + * @ingroup config_bitsdriver + * + * @brief This file contains the generated IAR header file for the Configuration bits driver. + * + * @version Driver Version 1.0.0 +*/ +/* +© [2024] Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip + software and any derivatives exclusively with Microchip products. + You are responsible for complying with 3rd party license terms + applicable to your use of 3rd party software (including open source + software) that may accompany Microchip software. SOFTWARE IS ?AS IS.? + NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS + SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, + MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT + WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY + KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF + MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE + FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S + TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT + EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR + THIS SOFTWARE. +*/ + + +#ifndef ASSEMBLER_IAR_H_INCLUDED +#define ASSEMBLER_IAR_H_INCLUDED + +/* clang-format off */ + +ld_addr MACRO reg, sym + mov reg, LWRD sym + orh reg, HWRD sym + ENDM + +call MACRO sym + rcall sym + ENDM + +iar_begin_func MACRO name, sect, is_public, is_weak + MODULE name + RSEG CODE:CODE:NOROOT(1) + IF is_weak == 1 + PUBWEAK name + ELSEIF is_public + PUBLIC name + ENDIF +name: + ENDM + +iar_begin_func_segm MACRO name, sect, is_public, is_weak, segment + MODULE name + RSEG segment:CODE:NOROOT(1) + IF is_weak == 1 + PUBWEAK name + ELSEIF is_public + PUBLIC name + ENDIF +name: + ENDM + +iar_weak_alias MACRO name, strong_name + PUBWEAK name +name: + rjmp strong_name + ENDM + +#define lo(x) LWRD x +#define hi(x) HWRD x + +#define REPEAT(count) REPT count +#define END_REPEAT() ENDR +#define SET_LOC(offset) ORG offset +#define END_FILE() END + +#define FILL_BYTES(count) DS8 count + +#define L(name) name +#define EXTERN_SYMBOL(name) EXTERN name +#define FUNCTION(name) iar_begin_func name, text_##name, 0, 0 +#define PUBLIC_FUNCTION(name) iar_begin_func name, text_##name, 1, 0 +#define PUBLIC_FUNCTION_SEGMENT(name, segment) \ + iar_begin_func_segm name, text_##name, 1, 0, segment +#define WEAK_FUNCTION(name) iar_begin_func name, text_##name, 1, 1 +#define WEAK_FUNCTION_ALIAS(name, strong_name) \ + iar_weak_alias name, strong_name +#define END_FUNC(name) ENDMOD + +#define TEXT_SECTION(name) RSEG name:CODE:NOROOT +#define RODATA_SECTION(name) RSEG name:CONST:NOROOT +#define DATA_SECTION(name) RSEG name:DATA:NOROOT +#define BSS_SECTION(name) RSEG name:DATA:NOROOT + +/* clang-format on */ + +#endif /* ASSEMBLER_IAR_H_INCLUDED */ diff --git a/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/system/utils/atomic.h b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/system/utils/atomic.h new file mode 100644 index 0000000..2f71dc3 --- /dev/null +++ b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/system/utils/atomic.h @@ -0,0 +1,87 @@ +/** + * CONFIGURATION BITS Generated Atomic Header File + * + * @file atomic.h + * + * @defgroup doc_driver_utils_atomic Atomic memory access and critical sections + * + * @brief This file contains the atomic memory access and critical sections header file for the configuration bits driver. + * + * @version Driver Version 1.0.0 +*/ +/* +© [2024] Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip + software and any derivatives exclusively with Microchip products. + You are responsible for complying with 3rd party license terms + applicable to your use of 3rd party software (including open source + software) that may accompany Microchip software. SOFTWARE IS ?AS IS.? + NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS + SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, + MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT + WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY + KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF + MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE + FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S + TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT + EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR + THIS SOFTWARE. +*/ + + +#ifndef ATOMIC_H +#define ATOMIC_H + +/* clang-format off */ + +#if defined(__GNUC__) || defined (__DOXYGEN__) + +/** + * @brief Enters critical region. Saves the contents of the status register, including the Global Interrupt Enable bit, so that it can be restored upon leaving the critical region. + * Thereafter, clears the Global Interrupt Enable Bit.This macro takes a parameter P that is unused for the GCC compiler,but necessary for code compatibility with the IAR compiler. + * The IAR compiler declares a variable with the name of the parameter forholding the SREG value. + * Compilation will fail when the variable declared in the macro is not unique within the scope that the critical region is declared within. + * @param[in] UNUSED(GCC)/P(IAR) Name of variable storing SREG. + */ + +#define ENTER_CRITICAL(UNUSED) __asm__ __volatile__ ( \ + "in __tmp_reg__, __SREG__" "\n\t" \ + "cli" "\n\t" \ + "push __tmp_reg__" "\n\t" \ + ::: "memory" \ + ) + +/** + * @brief Exits a critical region. Restores the contents of the status register, including the Global Interrupt Enable bit, as it was when entering the critical region. + * This macro takes a parameter P that is unused for the GCC compiler, but necessary for code compatibility with the IAR compiler. + * The IAR compiler uses this parameter as the name of a variable that holds the SREG value. + * The parameter must be identical to the parameter used in the corresponding ENTER_CRITICAL(). + * @param[in] UNUSED(GCC)/P(IAR) Name of variable storing SREG + */ + +#define EXIT_CRITICAL(UNUSED) __asm__ __volatile__ ( \ + "pop __tmp_reg__" "\n\t" \ + "out __SREG__, __tmp_reg__" "\n\t" \ + ::: "memory" \ + ) + +#define DISABLE_INTERRUPTS() __asm__ __volatile__ ( "cli" ::: "memory") +#define ENABLE_INTERRUPTS() __asm__ __volatile__ ( "sei" ::: "memory") + +#elif defined(__ICCAVR__) + +#define ENTER_CRITICAL(P) unsigned char P = __save_interrupt();__disable_interrupt(); +#define EXIT_CRITICAL(P) __restore_interrupt(P); + +#define DISABLE_INTERRUPTS() __disable_interrupt(); +#define ENABLE_INTERRUPTS() __enable_interrupt(); + +#else +# error Unsupported compiler. +#endif + +/* clang-format on */ + +#endif /* ATOMIC_H */ diff --git a/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/system/utils/compiler.h b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/system/utils/compiler.h new file mode 100644 index 0000000..682900b --- /dev/null +++ b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/system/utils/compiler.h @@ -0,0 +1,72 @@ +/** + * Compiler Header File + * + * @file compiler.h + * + * @defgroup doc_driver_utils_compiler Compiler abstraction + * + * @brief This file contains the compiler abstraction layer and code utilities for 8-bit AVR. This module provides various abstraction layers and utilities to make code compatible between different compilers. + * + * @version Driver Version 1.0.0 +*/ +/* +© [2024] Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip + software and any derivatives exclusively with Microchip products. + You are responsible for complying with 3rd party license terms + applicable to your use of 3rd party software (including open source + software) that may accompany Microchip software. SOFTWARE IS ?AS IS.? + NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS + SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, + MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT + WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY + KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF + MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE + FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S + TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT + EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR + THIS SOFTWARE. +*/ + + +#ifndef UTILS_COMPILER_H +#define UTILS_COMPILER_H + +#if defined(__GNUC__) +#include +#include +#if defined(__XC8__) +#include +#endif +#elif defined(__ICCAVR__) +#define ENABLE_BIT_DEFINITIONS 1 +#include +#include + +#ifndef CCP_IOREG_gc +#define CCP_IOREG_gc 0xD8 /* CPU_CCP_IOREG_gc */ +#endif +#ifndef CCP_SPM_gc +#define CCP_SPM_gc 0x9D /* CPU_CCP_SPM_gc */ +#endif + +#else +#error Unsupported compiler. +#endif + +#include +#include +#include +#include + +#include "interrupt_avr8.h" + +/** + * @def UNUSED + * @brief Marking \a v as a unused parameter or value. + */ +#define UNUSED(v) (void)(v) + +#endif /* UTILS_COMPILER_H */ diff --git a/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/system/utils/interrupt_avr8.h b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/system/utils/interrupt_avr8.h new file mode 100644 index 0000000..99068db --- /dev/null +++ b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/system/utils/interrupt_avr8.h @@ -0,0 +1,88 @@ +/** + * interrupt_avr8 Header File + * + * @file interrupt_avr8.h + * + * @defgroup doc_driver_utils_interrupts ISR abstraction + * + * @brief Interrupt-related functionality. + * + * @version Driver Version 1.0.0 +*/ +/* +© [2024] Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip + software and any derivatives exclusively with Microchip products. + You are responsible for complying with 3rd party license terms + applicable to your use of 3rd party software (including open source + software) that may accompany Microchip software. SOFTWARE IS ?AS IS.? + NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS + SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, + MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT + WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY + KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF + MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE + FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S + TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT + EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR + THIS SOFTWARE. +*/ + +#ifndef UTILS_INTERRUPT_AVR8_H +#define UTILS_INTERRUPT_AVR8_H + +/** + * \weakgroup interrupt_group + * + * @{ + */ + +#ifdef ISR_CUSTOM_H +#include ISR_CUSTOM_H +#else + +/** + * @def ISR + * @brief Define service routine for specified interrupt vector. + * @code + ISR(FOO_vect) + { + ... + } + * @endcode + * + * @param vect Interrupt vector name as found in the device header files. + */ +#if defined(__DOXYGEN__) +#define ISR(vect) +#elif defined(__GNUC__) +#include +#elif defined(__ICCAVR__) +#define __ISR(x) _Pragma(#x) +#define ISR(vect) __ISR(vector = vect) __interrupt void handler_##vect(void) +#endif +#endif // ISR_CUSTOM_H + +#ifdef __GNUC__ +#define cpu_irq_enable() sei() +#define cpu_irq_disable() cli() +#else +#define cpu_irq_enable() __enable_interrupt() +#define cpu_irq_disable() __disable_interrupt() +#endif + +//! @} + +/** + * \weakgroup interrupt_deprecated_group + * @{ + */ +// Deprecated definitions. +#define Enable_global_interrupt() cpu_irq_enable() +#define Disable_global_interrupt() cpu_irq_disable() +#define Is_global_interrupt_enabled() cpu_irq_is_enabled() +//! @} + +#endif /* UTILS_INTERRUPT_AVR8_H */ diff --git a/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/system/utils/utils.h b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/system/utils/utils.h new file mode 100644 index 0000000..a7b1b42 --- /dev/null +++ b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/system/utils/utils.h @@ -0,0 +1,52 @@ +/** + * utils Header File + * + * @file system.h + * + * @defgroup doc_driver_utils AVR Code utility functions + * + * @brief This file contains the compiler abstraction layer and code utilities for AVR.This module provides various abstraction layers and utilities to make code compatible between different compilers. + * + * @version Driver Version 1.0.1 + * \{ + * +*/ +/* +© [2024] Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip + software and any derivatives exclusively with Microchip products. + You are responsible for complying with 3rd party license terms + applicable to your use of 3rd party software (including open source + software) that may accompany Microchip software. SOFTWARE IS ?AS IS.? + NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS + SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, + MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT + WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY + KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF + MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE + FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S + TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT + EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR + THIS SOFTWARE. +*/ + +#ifndef UTILS_H_INCLUDED +#define UTILS_H_INCLUDED + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Retrieve array size + */ +#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) + +/** @} */ + +#ifdef __cplusplus +} +#endif +#endif /* UTILS_H_INCLUDED */ diff --git a/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/system/utils/utils_assert.h b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/system/utils/utils_assert.h new file mode 100644 index 0000000..b603f51 --- /dev/null +++ b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/system/utils/utils_assert.h @@ -0,0 +1,60 @@ +/** + * utils_assert Header File + * + * @file utils_assert.h + * + * @defgroup doc_driver_utils_assert Functionality for assert + * + * @brief This file contains the generated utils_assert header file for the configuration bits driver. + * + * @version Driver Version 1.0.1 +*/ +/* +© [2024] Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip + software and any derivatives exclusively with Microchip products. + You are responsible for complying with 3rd party license terms + applicable to your use of 3rd party software (including open source + software) that may accompany Microchip software. SOFTWARE IS ?AS IS.? + NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS + SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, + MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT + WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY + KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF + MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE + FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S + TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT + EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR + THIS SOFTWARE. +*/ + +#ifndef _ASSERT_H_INCLUDED +#define _ASSERT_H_INCLUDED + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +/** + * @brief Assert macro + * Macro used to throw asserts. It can be mapped to different function based on debug level. + * @param[in] condition A condition to be checked; assert is thrown if the given condition is false. + */ + +#ifdef DEBUG +#define ASSERT(condition) \ + if (!(condition)) \ + while (true) \ + ; +#else +#define ASSERT(condition) ((void)0) +#endif + +#ifdef __cplusplus +} +#endif +#endif /* _ASSERT_H_INCLUDED */ diff --git a/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/timer/rtc.h b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/timer/rtc.h new file mode 100644 index 0000000..10a822f --- /dev/null +++ b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/timer/rtc.h @@ -0,0 +1,193 @@ +/** + * RTC Generated Driver API Header File. + * + * @file rtc.h + * + * @defgroup rtc RTC + * + * @brief This file contains the API prototypes of the RTC driver. + * + * @version RTC Driver Version 2.1.0 +*/ +/* +© [2024] Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip + software and any derivatives exclusively with Microchip products. + You are responsible for complying with 3rd party license terms + applicable to your use of 3rd party software (including open source + software) that may accompany Microchip software. SOFTWARE IS ?AS IS.? + NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS + SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, + MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT + WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY + KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF + MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE + FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S + TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT + EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR + THIS SOFTWARE. +*/ + + +#ifndef RTCDRIVER_H +#define RTCDRIVER_H + +#include "../system/utils/compiler.h" +#include +#include + +/** + * @ingroup rtc + * @typedef void RTC_cb_t + * @brief Function pointer to callback function called by the RTC. The default value is set to NULL which means that no callback function will be used. + */ +typedef void (*RTC_cb_t)(void); +/** + * @ingroup rtc + * @brief Interrupt Service Routine (ISR) callback function to be called if Overflow (OVF) Interrupt flag is set. + * @param RTC_cb_t cb - Callback function to be called on Overflow event. + * @return None. + */ +void RTC_SetOVFIsrCallback(RTC_cb_t cb); +/** + * @ingroup rtc + * @brief ISR callback function to be called if Compare (CMP) match Interrupt flag is set. + * @param RTC_cb_t cb - Callback function to be called on compare match event. + * @return None. + */ +void RTC_SetCMPIsrCallback(RTC_cb_t cb); +/** + * @ingroup rtc + * @brief ISR callback function to be called if the Periodic Interrupt Timer (PIT) Interrupt flag is set. + * @param RTC_cb_t cb - Callback function to be called on periodic interrupt event. + * @return None. + */ +void RTC_SetPITIsrCallback(RTC_cb_t cb); +/** + * @ingroup rtc + * @brief Initializes the RTC module. + * @param None. + * @retval 0 - the RTC initialization is successful + * @retval 1 - the RTC initialization is not successful + */ +int8_t RTC_Initialize(void); +/** + * @ingroup rtc + * @brief Starts the counter register for the RTC module. + * @param None. + * @return None. + */ +void RTC_Start(void); +/** + * @ingroup rtc + * @brief Stops the counter register for the RTC module. + * @param None. + * @return None. + */ +void RTC_Stop(void); +/** + * @ingroup rtc + * @brief Writes a value to the Counter register of the RTC module. + * @param uint16_t timerVal - Value to be written to the Counter register of the RTC. + * @return None. + */ +void RTC_WriteCounter(uint16_t timerVal); +/** + * @ingroup rtc + * @brief Writes a value to the Period register of the RTC module. + * @param uint16_t timerVal - Value to be written to the Period register of the RTC. + * @return None. + */ +void RTC_WritePeriod(uint16_t timerVal); +/** + * @ingroup rtc + * @brief Returns the counter value from the Counter register. + * @param None. + * @return uint16_t - Value of the Counter register. + */ +uint16_t RTC_ReadCounter(void); +/** + * @ingroup rtc + * @brief Returns the value of the Period register. + * @param None. + * @return uint16_t - Value of the Period register. + */ +uint16_t RTC_ReadPeriod(void); +/** + * @ingroup rtc + * @brief Enables the Compare (CMP) Interrupt. + * @param None. + * @return None. + */ +void RTC_EnableCMPInterrupt(void); +/** + * @ingroup rtc + * @brief Disables the CMP Interrupt. + * @param None. + * @return None. + */ +void RTC_DisableCMPInterrupt(void); +/** + * @ingroup rtc + * @brief Enables the Overflow (OVF) Interrupt. + * @param None. + * @return None. + */ +void RTC_EnableOVFInterrupt(void); +/** + * @ingroup rtc + * @brief Disables the OVF Interrupt for the RTC module. + * @param None. + * @return None. + */ +void RTC_DisableOVFInterrupt(void); +/** + * @ingroup rtc + * @brief Enables the Periodic Interrupt Timer (PIT) interrupt for the RTC module. + * @param None. + * @return None. + */ +void RTC_EnablePITInterrupt(void); +/** + * @ingroup rtc + * @brief Disables the PIT Interrupt for the RTC module. + * @param None. + * @return None. + */ +void RTC_DisablePITInterrupt(void); +/** + * @ingroup rtc + * @brief Clears the OVF Interrupt flag. + * @param None. + * @return None. + */ +void RTC_ClearOVFInterruptFlag(void); +/** + * @ingroup rtc + * @brief Checks if Overflow interrupt has occurred. + * @param None. + * @retval True - Interrupt is enabled. + * @retval False - Interrupt is disabled. + */ +bool RTC_IsOVFInterruptEnabled(void); +/** + * @ingroup rtc + * @brief Writes a value to the CMP register of the RTC module. + * @param uint16_t value - Value to be written to the CMP register of the RTC. + * @return None. + */ +void RTC_WriteCMPRegister(uint16_t value); +/** + * @ingroup rtc + * @brief Returns the value from the CMP register. + * @param None. + * @return uint16_t - Value of the Compare register. + */ +uint16_t RTC_ReadCMPRegister(void); + + +#endif /* RTCDRIVER_H */ + +/** @}*/ \ No newline at end of file diff --git a/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/timer/src/rtc.c b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/timer/src/rtc.c new file mode 100644 index 0000000..104070b --- /dev/null +++ b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/timer/src/rtc.c @@ -0,0 +1,208 @@ +/** + * RTC Generated Driver API Source File. + * + * @file rtc.c + * + * @ingroup rtc + * + * @brief This file contains the API implementations for the RTC driver. + * + * version RTC Driver Version 2.1.0 +*/ +/* +© [2024] Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip + software and any derivatives exclusively with Microchip products. + You are responsible for complying with 3rd party license terms + applicable to your use of 3rd party software (including open source + software) that may accompany Microchip software. SOFTWARE IS ?AS IS.? + NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS + SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, + MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT + WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY + KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF + MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE + FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S + TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT + EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR + THIS SOFTWARE. +*/ + + +#include "../rtc.h" + +void (*RTC_OVF_isr_cb)(void) = NULL; +void (*RTC_CMP_isr_cb)(void) = NULL; +void (*RTC_PIT_isr_cb)(void) = NULL; + +int8_t RTC_Initialize(void) +{ + while (RTC.STATUS > 0) { /* Wait for all register to be synchronized */ + } + //Compare + RTC.CMP = 0x7FFF; + + //Count + RTC.CNT = 0x0; + + //Period + RTC.PER = 0xFFFF; + + //Clock selection + RTC.CLKSEL = 0x0; + + + //PIT Event Generation + RTC.PITEVGENCTRLA = 0x0; + + // CMP disabled; OVF disabled; + RTC.INTCTRL = 0x0; + + // DBGRUN disabled; + RTC.DBGCTRL = 0x0; + + // CORREN disabled; PRESCALER RTC Clock / 1; RTCEN enabled; RUNSTDBY disabled; + RTC.CTRLA = 0x1; + + + while (RTC.PITSTATUS > 0) { /* Wait for all register to be synchronized */ + } + // PI enabled; + RTC.PITINTCTRL = 0x1; + + // DBGRUN disabled; + RTC.PITDBGCTRL = 0x0; + + // PERIOD RTC Clock Cycles 1024; PITEN enabled; + RTC.PITCTRLA = 0x49; + + return 0; +} + +void RTC_Start(void) +{ + RTC.CTRLA |= RTC_RTCEN_bm; +} + +void RTC_Stop(void) +{ + RTC.CTRLA &= ~RTC_RTCEN_bm; +} + +void RTC_SetOVFIsrCallback(RTC_cb_t cb) +{ + RTC_OVF_isr_cb = cb; +} + +void RTC_SetCMPIsrCallback(RTC_cb_t cb) +{ + RTC_CMP_isr_cb = cb; +} + +void RTC_SetPITIsrCallback(RTC_cb_t cb) +{ + RTC_PIT_isr_cb = cb; +} + +ISR(RTC_CNT_vect) +{ + if ( (RTC.INTCTRL & RTC_OVF_bm) && (RTC.INTFLAGS & RTC_OVF_bm) ) + { + if (RTC_OVF_isr_cb != NULL) + { + (*RTC_OVF_isr_cb)(); + } + } + + if ( (RTC.INTCTRL & RTC_CMP_bm) && (RTC.INTFLAGS & RTC_CMP_bm) ) + { + if (RTC_CMP_isr_cb != NULL) + { + (*RTC_CMP_isr_cb)(); + } + } + RTC.INTFLAGS = (RTC_OVF_bm | RTC_CMP_bm); +} + +ISR(RTC_PIT_vect) +{ + if (RTC_PIT_isr_cb != NULL) + { + (*RTC_PIT_isr_cb)(); + } + RTC.PITINTFLAGS = RTC_PI_bm; +} + +inline void RTC_WriteCounter(uint16_t timerVal) +{ + while (RTC.STATUS & RTC_CNTBUSY_bm); + RTC.CNT = timerVal; +} + +inline uint16_t RTC_ReadCounter(void) +{ + return RTC.CNT; +} + +inline void RTC_WritePeriod(uint16_t timerVal) +{ + while (RTC.STATUS & RTC_PERBUSY_bm); + RTC.PER = timerVal; +} + +inline uint16_t RTC_ReadPeriod(void) +{ + return RTC.PER; +} + +inline void RTC_EnableCMPInterrupt(void) +{ + RTC.INTCTRL |= RTC_CMP_bm; +} + +inline void RTC_DisableCMPInterrupt(void) +{ + RTC.INTCTRL &= ~RTC_CMP_bm; +} + +inline void RTC_EnableOVFInterrupt(void) +{ + RTC.INTCTRL |= RTC_OVF_bm; +} + +inline void RTC_DisableOVFInterrupt(void) +{ + RTC.INTCTRL &= ~RTC_OVF_bm; +} + +inline void RTC_EnablePITInterrupt(void) +{ + RTC.PITINTCTRL |= RTC_PI_bm; +} + +inline void RTC_DisablePITInterrupt(void) +{ + RTC.PITINTCTRL &= ~RTC_PI_bm; +} + +inline void RTC_ClearOVFInterruptFlag(void) +{ + RTC.INTFLAGS = RTC_OVF_bm; +} + +inline bool RTC_IsOVFInterruptEnabled(void) +{ + return ((RTC.INTCTRL & RTC_OVF_bm) > 0); +} + +inline void RTC_WriteCMPRegister(uint16_t value) +{ + RTC.CMP = value; +} + +inline uint16_t RTC_ReadCMPRegister(void) +{ + return RTC.CMP; +} \ No newline at end of file diff --git a/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/src/usb0.c b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/src/usb0.c new file mode 100644 index 0000000..28210a2 --- /dev/null +++ b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/src/usb0.c @@ -0,0 +1,89 @@ +/** + * USB0 Generated Driver File + * + * @file usb0.c + * + * @ingroup usb0 + * + * @brief This file contains the API implementations for the USB0 driver. + * + * @version USB0 Driver Version 1.0.0 +*/ +/* +© [2024] Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip + software and any derivatives exclusively with Microchip products. + You are responsible for complying with 3rd party license terms + applicable to your use of 3rd party software (including open source + software) that may accompany Microchip software. SOFTWARE IS ?AS IS.? + NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS + SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, + MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT + WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY + KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF + MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE + FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S + TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT + EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR + THIS SOFTWARE. +*/ + +#include +#include "../usb0.h" +#include "../../system/syscfg.h" +#include "../../system/utils/compiler.h" + +static void USB0_DefaultTrnComplCallback(void); +static void USB0_DefaultBusEventCallback(void); +static void (*USB0_TrnCompl_isr_cb)(void) = &USB0_DefaultTrnComplCallback; +static void (*USB0_BusEvent_isr_cb)(void) = &USB0_DefaultBusEventCallback; + +void USB0_Initialize(void) +{ + // OVF disabled; RESET disabled; RESUME disabled; SOF disabled; STALLED disabled; SUSPEND disabled; UNF disabled; + USB0.INTCTRLA = 0x0; + // GNDONE disabled; SETUP disabled; TRNCOMPL disabled; + USB0.INTCTRLB = 0x0; + SYSCFG_UsbVregDisable(); +} + +void USB0_TrnComplCallbackRegister(USB_cb_t cb) +{ + USB0_TrnCompl_isr_cb = cb; +} + +void USB0_BusEventCallbackRegister(USB_cb_t cb) +{ + USB0_BusEvent_isr_cb = cb; +} + +static void USB0_DefaultTrnComplCallback(void) +{ + // Clear the interrupt Flags + USB0.INTFLAGSB = USB_TRNCOMPL_bm | USB_GNDONE_bm | USB_SETUP_bm; +} + +static void USB0_DefaultBusEventCallback(void) +{ + // Clear the interrupt Flags + USB0.INTFLAGSA = USB_SOF_bm | USB_SUSPEND_bm | USB_RESUME_bm | USB_RESET_bm | USB_STALLED_bm | USB_UNF_bm | USB_OVF_bm; +} + +ISR(USB0_TRNCOMPL_vect) { + if (USB0_TrnCompl_isr_cb != NULL) + { + (*USB0_TrnCompl_isr_cb)(); + } +} + +ISR(USB0_BUSEVENT_vect) { + if (USB0_BusEvent_isr_cb != NULL) { + (*USB0_BusEvent_isr_cb)(); + } +} + +/** + End of File +*/ diff --git a/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb0.h b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb0.h new file mode 100644 index 0000000..69deb67 --- /dev/null +++ b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb0.h @@ -0,0 +1,74 @@ +/** + * USB0 Generated Driver API Header File + * + * @file usb0.h + * + * @defgroup usb0 USB0 + * + * @brief This file contains the API prototypes for the USB0 driver. + * + * @version USB0 Driver Version 1.0.0 +*/ +/* +© [2024] Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip + software and any derivatives exclusively with Microchip products. + You are responsible for complying with 3rd party license terms + applicable to your use of 3rd party software (including open source + software) that may accompany Microchip software. SOFTWARE IS ?AS IS.? + NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS + SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, + MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT + WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY + KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF + MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE + FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S + TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT + EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR + THIS SOFTWARE. +*/ + +#ifndef USB0_H +#define USB0_H + +/** + * @ingroup usb0 + * @typedef void *USB_cb_t + * @brief Data type for the interrupt handlers called by USB. The default value is set to NULL which means that no callback function will be used. + */ +typedef void (*USB_cb_t)(void); + +/** + Section: USB0 APIs +*/ + +/** + * @ingroup usb0 + * @brief Initializes USB0. + * @param None. + * @return None. + */ +void USB0_Initialize(void); + +/** + * @ingroup usb0 + * @brief Registers a callback function handling the Interrupt Service Routine (ISR) if a Transaction Complete interrupt flag is set. + * @param USB_cb_t cb - Callback function for a transaction complete event + * @return None. + */ +void USB0_TrnComplCallbackRegister(USB_cb_t cb); + +/** + * @ingroup usb0 + * @brief Registers a callback function handling the ISR if a Bus Event interrupt flag is set. + * @param USB_cb_t cb - Callback function for a bus event + * @return None. + */ +void USB0_BusEventCallbackRegister(USB_cb_t cb); + +#endif // USB0_H +/** + End of File +*/ diff --git a/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_common/usb_common_elements.h b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_common/usb_common_elements.h new file mode 100644 index 0000000..95d07a4 --- /dev/null +++ b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_common/usb_common_elements.h @@ -0,0 +1,99 @@ +/** + * USBCOMMONELEMENTS Common Elements Header File + * @file usb_common_elements.h + * @defgroup usb_common USB Common Elements + * @ingroup usb_core + * @brief Common elements for the USB stack. + * @version USB Common Elements Version 1.0.0 + */ + +/* + (c) 2021 Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip software and any + derivatives exclusively with Microchip products. It is your responsibility to comply with third party + license terms applicable to your use of third party software (including open source software) that + may accompany Microchip software. + + THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER + EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY + IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS + FOR A PARTICULAR PURPOSE. + + IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND + WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP + HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO + THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL + CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT + OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS + SOFTWARE. + */ + +#ifndef USB_COMMON_ELEMENTS_H +// cppcheck-suppress misra-c2012-2.5 +#define USB_COMMON_ELEMENTS_H + +#ifndef TEST +#define STATIC static +#else +#define STATIC +#endif + +/** + * @ingroup usb_common + * @enum RETURN_CODE_enum + * @brief Describes the different function return reserved codes used by the USB stack. + */ + +typedef enum RETURN_CODE_enum +{ + UNSUPPORTED = 2, /** +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +RETURN_CODE_t USB_SetupProcess(USB_SETUP_REQUEST_t *setupRequestPtr) +{ + RETURN_CODE_t status = UNINITIALIZED; + + if (USB_REQUEST_TYPE_STANDARD == (USB_REQUEST_TYPE_t)setupRequestPtr->bmRequestType.type) + { + // Checks that an IN request actually requests data. + if ((USB_REQUEST_DIR_IN == (USB_REQUEST_DIR_t)setupRequestPtr->bmRequestType.dataPhaseTransferDirection) && (0u == setupRequestPtr->wLength)) + { + status = CONTROL_SETUP_DIRECTION_ERROR; + } + else + { + // Makes sure the data out transfer is reset before handling requests. + USB_ControlTransferDataSet(NULL, 0u); + + switch (setupRequestPtr->bmRequestType.recipient) + { + case USB_REQUEST_RECIPIENT_DEVICE: + { + status = USB_SetupProcessDeviceRequest(setupRequestPtr); + break; + } + case USB_REQUEST_RECIPIENT_ENDPOINT: + { + status = USB_SetupProcessEndpointRequest(setupRequestPtr); + break; + } + case USB_REQUEST_RECIPIENT_INTERFACE: + { + status = USB_SetupProcessInterfaceRequest(setupRequestPtr); + break; + } + case USB_REQUEST_RECIPIENT_OTHER: + { + if (NULL != event.OtherRequest) + { + status = event.OtherRequest(setupRequestPtr); + } + else + { + status = UNSUPPORTED; + } + break; + } + default: + status = UNSUPPORTED; + break; + } + } + } + else if (USB_REQUEST_TYPE_CLASS == (USB_REQUEST_TYPE_t)setupRequestPtr->bmRequestType.type) + { + if (NULL != event.ClassRequest) + { + status = event.ClassRequest(setupRequestPtr); + } + else + { + status = UNSUPPORTED; + } + } + else if (USB_REQUEST_TYPE_VENDOR == (USB_REQUEST_TYPE_t)setupRequestPtr->bmRequestType.type) + { + if (NULL != event.VendorRequest) + { + status = event.VendorRequest(setupRequestPtr); + } + else + { + status = UNSUPPORTED; + } + } + else + { + status = UNSUPPORTED; + } + + return status; +} + +RETURN_CODE_t USB_Start(void) +{ + RETURN_CODE_t status = SUCCESS; + + // Configures setup callback. + USB_ControlProcessSetupCallbackRegister(USB_SetupProcess); + + // Sets up the peripheral. + USB_PeripheralInitialize(); + + // Initializes and configures the endpoints. + USB_PIPE_t pipe = { .address = 0 }; + while (pipe.address < USB_EP_NUM) + { + if (status == SUCCESS) + { + pipe.direction = USB_EP_DIR_OUT; + status = USB_PipeReset(pipe); + } + if (status == SUCCESS) + { + pipe.direction = USB_EP_DIR_IN; + status = USB_PipeReset(pipe); + } + pipe.address++; + } + + // Initializes the control endpoints. + if (status == SUCCESS) + { + status = USB_ControlEndpointsInit(); + } + + // Attaches the device to the bus. + if (status == SUCCESS) + { + status = USB_ControlTransferReset(); + } + + if (status == SUCCESS) + { + USB_BusAttach(); + } + + return status; +} + +RETURN_CODE_t USB_Stop(void) +{ + RETURN_CODE_t status = SUCCESS; + + // Detaches from the bus and disables peripheral. + USB_BusDetach(); + USB_PeripheralDisable(); + + // Aborts any ongoing transfers. + USB_PIPE_t pipe = { .address = 0 }; + while (pipe.address < USB_EP_NUM) + { + if (status == SUCCESS) + { + pipe.direction = USB_EP_DIR_OUT; + status = USB_TransferAbort(pipe); + } + if (status == SUCCESS) + { + pipe.direction = USB_EP_DIR_IN; + status = USB_TransferAbort(pipe); + } + pipe.address++; + } + + return status; +} + +RETURN_CODE_t USB_Reset(void) +{ + RETURN_CODE_t status = UNINITIALIZED; + status = USB_Stop(); + if (status == SUCCESS) + { + status = USB_Start(); + } + return status; +} diff --git a/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_common/usb_core.h b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_common/usb_core.h new file mode 100644 index 0000000..819176d --- /dev/null +++ b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_common/usb_core.h @@ -0,0 +1,95 @@ +/** + * USBCORE CORE Header File + * @file usb_core.h + * @defgroup usb_core USB Core Layer + * @brief Core functionality for the USB stack. + * @version USB Device Core Version 1.0.0 + */ + +/* + (c) 2021 Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip software and any + derivatives exclusively with Microchip products. It is your responsibility to comply with third party + license terms applicable to your use of third party software (including open source software) that + may accompany Microchip software. + + THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER + EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY + IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS + FOR A PARTICULAR PURPOSE. + + IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND + WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP + HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO + THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL + CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT + OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS + SOFTWARE. + */ + +#ifndef USB_CORE_H +// cppcheck-suppress misra-c2012-2.5 +#define USB_CORE_H + +#include +#include + +#include +#include +#include +#include + +/** + * @ingroup usb_core + * @brief Setup function for the Standard Device Request USB 2.0 Specification Ch 9.4. + * | bRequest | wValue | wIndex | wLength | Data | + * |-------------------|---------------------------------------|-------------------------|-------------------|-------------------------------------| + * | CLEAR_FEATURE | Feature Selector | Zero | None | | + * | CLEAR_FEATURE | Feature Selector | Interface | None | | + * | CLEAR_FEATURE | Feature Selector | Endpoint | None | | + * | GET_CONFIGURATION | Zero | Zero | One | Configuration Value | + * | GET_DESCRIPTOR | Descriptor type and Descriptor index | Zero or Language ID | Descriptor Length | Descriptor | + * | GET_INTERFACE | Zero | Interface | One | Alternate Interface | + * | GET_STATUS | Zero | Zero Interface Endpoint | Two | Device status | + * | GET_STATUS | Zero | Interface | Two | Interface Status | + * | GET_STATUS | Zero | Endpoint | Two | Endpoint Status | + * | SET_ADDRESS | Device Address | Zero | Zero | None | + * | SET_CONFIGURATION | Configuration Value | Zero | Zero | None | + * | SET_DESCRIPTOR | Descriptor type and Descriptor index | Zero or Language ID | Descriptor Length | Descriptor | + * | SET_FEATURE | Feature Selector | Zero Interface Endpoint | Zero | None | + * | SET_FEATURE | Feature Selector | Interface | Zero | | + * | SET_FEATURE | Feature Selector | Endpoint | Zero | | + * | SET_INTERFACE | Alternate Setting | Interface | Zero | None | + * | SYNCH_FRAME | Zero | Endpoint | Two | Frame Number | + * @param *setupRequestPtr - Pointer to the setup request and its data + * @return SUCCESS or an Error code according to RETURN_CODE_t + */ +RETURN_CODE_t USB_SetupProcess(USB_SETUP_REQUEST_t *setupRequestPtr); + +/** + * @ingroup usb_core + * @brief Starts the USB peripheral, configures the callbacks and attaches it to the bus. + * @param None. + * @return SUCCESS or an Error code according to RETURN_CODE_t + */ +RETURN_CODE_t USB_Start(void); + +/** + * @ingroup usb_core + * @brief Stops the USB peripheral and detaches it from the bus. + * @param None. + * @return SUCCESS or an Error code according to RETURN_CODE_t + */ +RETURN_CODE_t USB_Stop(void); + +/** + * @ingroup usb_core + * @brief Resets the USB peripheral. + * @param None. + * @return SUCCESS or an Error code according to RETURN_CODE_t + */ +RETURN_CODE_t USB_Reset(void); + +#endif /* USB_CORE_H */ diff --git a/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_common/usb_core_descriptors.c b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_common/usb_core_descriptors.c new file mode 100644 index 0000000..60ea9bf --- /dev/null +++ b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_common/usb_core_descriptors.c @@ -0,0 +1,658 @@ +/** + * USBCOREDESCRIPTOR Core Descriptors Source File + * @file usb_core_descriptors.h + * @ingroup usb_core_descriptors + * @brief descriptors for the USB Core Stack. + * @version USB Device Core Version 1.0.0 + */ + +/* + (c) 2021 Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip software and any + derivatives exclusively with Microchip products. It is your responsibility to comply with third party + license terms applicable to your use of third party software (including open source software) that + may accompany Microchip software. + + THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER + EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY + IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS + FOR A PARTICULAR PURPOSE. + + IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND + WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP + HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO + THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL + CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT + OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS + SOFTWARE. + */ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +/** + * @ingroup usb_core_descriptors + * @def USB_DEFAULT_INTERFACE + * @brief Default interface number. + */ +#define USB_DEFAULT_INTERFACE 0u + +/** + * @ingroup usb_core_descriptors + * @def USB_DEFAULT_ALTERNATE_SETTING + * @brief Default alternate setting. + */ +#define USB_DEFAULT_ALTERNATE_SETTING 0u + +/** + * @ingroup usb_core_descriptors + * @def USB_DESCRIPTOR_SEARCH_LIMIT + * @brief The number of descriptors NextDescriptorPointerGet will search through before returning an error. + */ +#define USB_DESCRIPTOR_SEARCH_LIMIT 30u + +/** + * @typedef USB_DESCRIPTOR_PTR_t + * @brief Union of a uint8_t pointer and pointers to the different descriptor types. + * @misradeviation{@advisory,19.2} Needed for the stack to parse through the configuration descriptors + * without pointer casting between the different descriptor types and uint8_t. + */ +// cppcheck-suppress misra-c2012-19.2 +typedef union USB_DESCRIPTOR_PTR_union +{ + uint8_t *bytePtr; + USB_DESCRIPTOR_HEADER_t *headerPtr; + USB_ENDPOINT_DESCRIPTOR_t *endpointPtr; + USB_INTERFACE_DESCRIPTOR_t *interfacePtr; + USB_CONFIGURATION_DESCRIPTOR_t *configurationPtr; +} USB_DESCRIPTOR_PTR_t; + + +STATIC USB_CONFIGURATION_DESCRIPTOR_t *activeConfigurationPtr = NULL; +STATIC uint8_t activeInterfaces[USB_INTERFACE_NUM]; +STATIC USB_DESCRIPTOR_POINTERS_t *applicationPointers = NULL; + +RETURN_CODE_t USB_DescriptorPointersSet(USB_DESCRIPTOR_POINTERS_t *descriptorPointersPtr) +{ + RETURN_CODE_t status = UNINITIALIZED; + + if (NULL != descriptorPointersPtr) + { + // Checks that the device pointer is pointing to a struct with the device type. + if ((NULL == descriptorPointersPtr->devicePtr) || (USB_DESCRIPTOR_TYPE_DEVICE != (USB_DESCRIPTOR_TYPE_t)descriptorPointersPtr->devicePtr->header.bDescriptorType)) + { + status = DESCRIPTOR_POINTER_ERROR; + } + // Checks that the first configuration pointer is pointing to a struct with the configuration type. + else if ((NULL == descriptorPointersPtr->configurationsPtr) || (USB_DESCRIPTOR_TYPE_CONFIGURATION != (USB_DESCRIPTOR_TYPE_t)descriptorPointersPtr->configurationsPtr->header.bDescriptorType)) + { + status = DESCRIPTOR_POINTER_ERROR; + } + else + { + status = SUCCESS; + } + } + else + { + status = DESCRIPTOR_POINTER_ERROR; + } + + if (SUCCESS == status) + { + // Saves the pointer structure address. + applicationPointers = descriptorPointersPtr; + } + + return status; +} + +RETURN_CODE_t USB_DescriptorConfigurationEnable(uint8_t configurationValue) +{ + RETURN_CODE_t status = UNINITIALIZED; + + // Descriptor pointer to search through the different descriptors + // cppcheck-suppress misra-c2012-19.2 + USB_DESCRIPTOR_PTR_t currentDescriptor; + + if (NULL == applicationPointers) + { + status = DESCRIPTOR_POINTER_ERROR; + } + else + { + if (NULL != activeConfigurationPtr) + { + status = SUCCESS; + + // Find and disable all active interfaces in the current configuration + currentDescriptor.configurationPtr = activeConfigurationPtr; + uint8_t numInterfaces = activeConfigurationPtr->bNumInterfaces; + while ((SUCCESS == status) && (numInterfaces > 0u)) + { + status = NextDescriptorPointerGet(USB_DESCRIPTOR_TYPE_INTERFACE, ¤tDescriptor.headerPtr); + + if (SUCCESS == status) + { + if (activeInterfaces[currentDescriptor.interfacePtr->bInterfaceNumber] == currentDescriptor.interfacePtr->bAlternateSetting) + { + status = USB_DescriptorInterfaceConfigure(currentDescriptor.interfacePtr->bInterfaceNumber, USB_DEFAULT_ALTERNATE_SETTING, false); + numInterfaces--; + } + } + } + } + else + { + // No current configuration, nothing to disable + status = SUCCESS; + } + + if (SUCCESS == status) + { + if (USB_REQUEST_DEVICE_DISABLE_CONFIGURATION == configurationValue) + { + // Active configuration is disabled, so clear pointer + activeConfigurationPtr = NULL; + } + else + { + // Get new configuration pointer and enable its interfaces + status = ConfigurationPointerGet(configurationValue, &activeConfigurationPtr); + + if (SUCCESS == status) + { + // Find and enable all interfaces in the set configuration with bAlternateSetting == 0 + currentDescriptor.configurationPtr = activeConfigurationPtr; + uint8_t numInterfaces = activeConfigurationPtr->bNumInterfaces; + while ((SUCCESS == status) && (numInterfaces > 0u)) + { + status = NextDescriptorPointerGet(USB_DESCRIPTOR_TYPE_INTERFACE, ¤tDescriptor.headerPtr); + if (SUCCESS == status) + { + if (USB_DEFAULT_ALTERNATE_SETTING == currentDescriptor.interfacePtr->bAlternateSetting) + { + status = USB_DescriptorInterfaceConfigure(currentDescriptor.interfacePtr->bInterfaceNumber, USB_DEFAULT_ALTERNATE_SETTING, true); + numInterfaces--; + } + } + } + } + } + } + } + + return status; +} + +uint8_t USB_DescriptorActiveConfigurationValueGet(void) +{ + uint8_t configurationValue = USB_REQUEST_DEVICE_DISABLE_CONFIGURATION; + + if (NULL != activeConfigurationPtr) + { + configurationValue = activeConfigurationPtr->bConfigurationValue; + } + + return configurationValue; +} + +bool USB_DescriptorActiveConfigurationSelfPoweredGet(void) +{ + return (activeConfigurationPtr->bmAttributes & USB_CONFIG_ATTR_SELF_POWERED) == USB_CONFIG_ATTR_SELF_POWERED; +} + +bool USB_DescriptorActiveConfigurationRemoteWakeupGet(void) +{ + return (activeConfigurationPtr->bmAttributes & USB_CONFIG_ATTR_REMOTE_WAKEUP) == USB_CONFIG_ATTR_REMOTE_WAKEUP; +} + +RETURN_CODE_t ConfigurationPointerGet(uint8_t configurationValue, USB_CONFIGURATION_DESCRIPTOR_t **configurationPtr) +{ + RETURN_CODE_t status = UNINITIALIZED; + + // Checks if the requested configuration is an existing configuration. + if (configurationValue > applicationPointers->devicePtr->bNumConfigurations) + { + status = DESCRIPTOR_CONFIGURATIONS_ERROR; + } + else + { + // If there is only one configuration, return the pointer to the configuration. + if (1u == applicationPointers->devicePtr->bNumConfigurations) + { + *configurationPtr = applicationPointers->configurationsPtr; + status = SUCCESS; + } + else + { + // Pointer initialized to the address of the first configuration descriptor. + // cppcheck-suppress misra-c2012-19.2 + USB_DESCRIPTOR_PTR_t currentDescriptor = { .configurationPtr = applicationPointers->configurationsPtr }; + + uint8_t i = applicationPointers->devicePtr->bNumConfigurations; + while (i-- > 0u) + { + if (currentDescriptor.configurationPtr->bConfigurationValue != configurationValue) + { + status = NextDescriptorPointerGet(USB_DESCRIPTOR_TYPE_CONFIGURATION, ¤tDescriptor.headerPtr); + } + else + { + status = SUCCESS; + + // Ends loop on success + i = 0; + } + + if (SUCCESS != status) + { + // Ends loop on error. + i = 0; + } + } + + if (SUCCESS == status) + { + if (currentDescriptor.configurationPtr->bConfigurationValue == configurationValue) + { + *configurationPtr = currentDescriptor.configurationPtr; + } + else + { + // configurationValue not found + status = DESCRIPTOR_SEARCH_ERROR; + } + } + } + } + + return status; +} + +RETURN_CODE_t NextDescriptorPointerGet(USB_DESCRIPTOR_TYPE_t descriptorType, USB_DESCRIPTOR_HEADER_t **descriptorHeaderPtr) +{ + RETURN_CODE_t status = UNINITIALIZED; + + // cppcheck-suppress misra-c2012-19.2 + USB_DESCRIPTOR_PTR_t currentDescriptor = { .headerPtr = *descriptorHeaderPtr }; + + uint8_t incrementCount = 0u; + while (UNINITIALIZED == status) + { + // Increments to the start of the next pointer. + if ((USB_DESCRIPTOR_TYPE_CONFIGURATION == descriptorType) && (USB_DESCRIPTOR_TYPE_CONFIGURATION == (USB_DESCRIPTOR_TYPE_t)currentDescriptor.headerPtr->bDescriptorType)) + { + // If the device is looking for the next configuration, it increments the pointer with total length of the configuration. + currentDescriptor.bytePtr = ¤tDescriptor.bytePtr[currentDescriptor.configurationPtr->wTotalLength]; + } + else + { + // Else it only increments with the descriptor length. + currentDescriptor.bytePtr = ¤tDescriptor.bytePtr[currentDescriptor.headerPtr->bLength]; + } + + // Checks whether it has found the correct descriptor type or if it needs to continue looping. + if (descriptorType == (USB_DESCRIPTOR_TYPE_t)currentDescriptor.headerPtr->bDescriptorType) + { + status = SUCCESS; + *descriptorHeaderPtr = currentDescriptor.headerPtr; + } + else + { + // If it has looped through too many descriptors, it is assumed that the descriptor structure is set up incorrectly and the loop is exited. + if (incrementCount++ > USB_DESCRIPTOR_SEARCH_LIMIT) + { + status = DESCRIPTOR_SEARCH_ERROR; + } + } + } + + return status; +} + +RETURN_CODE_t USB_DescriptorInterfaceConfigure(uint8_t interfaceNumber, uint8_t alternateSetting, bool enable) +{ + RETURN_CODE_t status = UNINITIALIZED; + + if (NULL != activeConfigurationPtr) + { + // Pointer initialized to the address of the active configuration descriptor + // cppcheck-suppress misra-c2012-19.2 + USB_DESCRIPTOR_PTR_t currentDescriptor = { .configurationPtr = activeConfigurationPtr }; + + // Limit to end of configuration to make sure the loop does not overflow + uint8_t *endOfConfiguration = ¤tDescriptor.bytePtr[currentDescriptor.configurationPtr->wTotalLength]; + + // Find first interface descriptor before entering loop + status = NextDescriptorPointerGet(USB_DESCRIPTOR_TYPE_INTERFACE, ¤tDescriptor.headerPtr); + + // Loop through all the descriptors in the current configuration + USB_INTERFACE_DESCRIPTOR_t *enableInterfacePtr = NULL; + while ((SUCCESS == status) && (currentDescriptor.bytePtr < endOfConfiguration)) + { + // Check if interface number and alternate setting correspond to the active interface before disabling endpoints + if ((interfaceNumber == currentDescriptor.interfacePtr->bInterfaceNumber) && (activeInterfaces[interfaceNumber] == currentDescriptor.interfacePtr->bAlternateSetting)) + { + // Disable endpoints for the active alternate interface + status = DescriptorEndpointsConfigure(currentDescriptor.interfacePtr, false); + if (SUCCESS == status) + { + // Reset the active alternate interface to 0 + status = ActiveAlternateSettingSet(interfaceNumber, USB_DEFAULT_ALTERNATE_SETTING); + } + } + + if (enable) + { + if (interfaceNumber == currentDescriptor.interfacePtr->bInterfaceNumber) + { + if (alternateSetting == currentDescriptor.interfacePtr->bAlternateSetting) + { + // Requested interface found + enableInterfacePtr = currentDescriptor.interfacePtr; + } + } + } + + status = NextDescriptorPointerGet(USB_DESCRIPTOR_TYPE_INTERFACE, ¤tDescriptor.headerPtr); + if (DESCRIPTOR_SEARCH_ERROR == status) + { + // Search error from NextDescriptorPointerGet means search is complete + if ((false == enable) || (NULL != enableInterfacePtr)) + { + // Search was successful, correcting status + status = SUCCESS; + + // Set byte pointer to end of config to exit loop + currentDescriptor.bytePtr = endOfConfiguration; + } + } + } + + if (SUCCESS == status) + { + if (true == enable) + { + if (NULL != enableInterfacePtr) + { + // Enable the endpoints for the activated interface + status = DescriptorEndpointsConfigure(enableInterfacePtr, true); + if (SUCCESS == status) + { + status = ActiveAlternateSettingSet(interfaceNumber, alternateSetting); + } + } + else + { + status = DESCRIPTOR_SEARCH_ERROR; + } + } + } + } + else + { + status = DESCRIPTOR_POINTER_ERROR; + } + + return status; +} + +RETURN_CODE_t ActiveAlternateSettingSet(uint8_t interfaceNumber, uint8_t alternateSetting) +{ + RETURN_CODE_t status = UNINITIALIZED; + + if (interfaceNumber < USB_INTERFACE_NUM) + { + activeInterfaces[interfaceNumber] = alternateSetting; + status = SUCCESS; + } + else + { + status = INTERFACE_SET_ERROR; + } + + return status; +} + +RETURN_CODE_t ActiveAlternateSettingGet(uint8_t interfaceNumber, uint8_t *alternateSetting) +{ + RETURN_CODE_t status = UNINITIALIZED; + + if (interfaceNumber < USB_INTERFACE_NUM) + { + *alternateSetting = activeInterfaces[interfaceNumber]; + status = SUCCESS; + } + else + { + status = INTERFACE_GET_ERROR; + } + + return status; +} + +RETURN_CODE_t DescriptorEndpointsConfigure(USB_INTERFACE_DESCRIPTOR_t *interfacePtr, bool enable) +{ + RETURN_CODE_t status = UNINITIALIZED; + + if ((uint8_t)USB_DESCRIPTOR_TYPE_INTERFACE == interfacePtr->header.bDescriptorType) + { + // The number of endpoints to enable/disable is found from the interface. + uint8_t numEndpoints = interfacePtr->bNumEndpoints; + if (numEndpoints > 0u) + { + // cppcheck-suppress misra-c2012-19.2 + USB_DESCRIPTOR_PTR_t currentDescriptor = { .interfacePtr = interfacePtr }; + + while (numEndpoints > 0u) + { + // Pre-increments to the next descriptor, since the initial descriptor is the interface. + currentDescriptor.bytePtr = ¤tDescriptor.bytePtr[currentDescriptor.headerPtr->bLength]; + + if (USB_DESCRIPTOR_TYPE_ENDPOINT == (USB_DESCRIPTOR_TYPE_t)currentDescriptor.headerPtr->bDescriptorType) + { + if (true == enable) + { + // Configures endpoint according to descriptor. + status + = USB_EndpointConfigure(currentDescriptor.endpointPtr->bEndpointAddress, currentDescriptor.endpointPtr->wMaxPacketSize, currentDescriptor.endpointPtr->bmAttributes.type); + } + else + { + // Aborts any ongoing transfer and disable endpoint. + status = USB_TransferAbort(currentDescriptor.endpointPtr->bEndpointAddress); + if (SUCCESS == status) + { + status = USB_EndpointDisable(currentDescriptor.endpointPtr->bEndpointAddress); + } + } + + numEndpoints--; + + if (SUCCESS != status) + { + // Exits loop immediately. + numEndpoints = 0; + } + } + } + } + else + { + // Interface has no endpoints. + status = SUCCESS; + } + } + else + { + status = DESCRIPTOR_ENDPOINT_ERROR; + } + + return status; +} + +RETURN_CODE_t USB_DescriptorPointerGet(USB_DESCRIPTOR_TYPE_t descriptor, uint8_t attribute, uint8_t **descriptorPtr, uint16_t *descriptorLength) +{ + RETURN_CODE_t status = UNINITIALIZED; + + // cppcheck-suppress misra-c2012-19.2 + USB_DESCRIPTOR_PTR_t localDescriptorPtr; + + switch (descriptor) + { + case USB_DESCRIPTOR_TYPE_DEVICE: + // Returns pointer to device descriptor. + if (applicationPointers != NULL) + { + *descriptorPtr = (uint8_t *)applicationPointers->devicePtr; + *descriptorLength = (uint16_t)applicationPointers->devicePtr->header.bLength; + status = SUCCESS; + } + else + { + status = DESCRIPTOR_POINTER_ERROR; + } + break; + case USB_DESCRIPTOR_TYPE_CONFIGURATION:; + // Returns pointer to configuration, with the total length. + + status = ConfigurationPointerGet(attribute, &localDescriptorPtr.configurationPtr); + if (SUCCESS == status) + { + *descriptorPtr = localDescriptorPtr.bytePtr; + *descriptorLength = localDescriptorPtr.configurationPtr->wTotalLength; + } + break; + case USB_DESCRIPTOR_TYPE_DEVICE_QUALIFIER: + // Only for high-speed. + status = UNSUPPORTED; + break; + case USB_DESCRIPTOR_TYPE_OTHER_SPEED_CONFIGURATION: + // Only for high-speed. + status = UNSUPPORTED; + break; + case USB_DESCRIPTOR_TYPE_BOS: + if (NULL != applicationPointers->deviceBOSptr) + { + *descriptorPtr = (uint8_t *)applicationPointers->deviceBOSptr; + *descriptorLength = (uint16_t)applicationPointers->deviceBOSptr->wTotalLength; + status = SUCCESS; + } + else + { + status = UNSUPPORTED; + } + break; + default: + // Find class or vendor descriptor types in the active configuration + if (descriptor >= USB_DESCRIPTOR_TYPE_CLASS) + { + localDescriptorPtr.configurationPtr = activeConfigurationPtr; + + // Find the first descriptor available of the current type + status = NextDescriptorPointerGet(descriptor, &localDescriptorPtr.headerPtr); + if (SUCCESS == status) + { + *descriptorPtr = (uint8_t *)localDescriptorPtr.headerPtr; + *descriptorLength = localDescriptorPtr.headerPtr->bLength; + } + } + else + { + status = DESCRIPTOR_REQUEST_ERROR; + } + + break; + } + + if (SUCCESS != status) + { + *descriptorPtr = NULL; + *descriptorLength = 0u; + } + + return status; +} + +RETURN_CODE_t USB_DescriptorStringPointerGet(uint8_t stringIndex, uint16_t langID, uint8_t **descriptorAddressPtr, uint16_t *descriptorLength) +{ + RETURN_CODE_t status = UNINITIALIZED; + + if (NULL != applicationPointers->langIDptr) + { + if (stringIndex == 0u) + { + // Index 0 is the language id index, writes pointer and length. + *descriptorAddressPtr = (uint8_t *)applicationPointers->langIDptr; + *descriptorLength = (uint16_t)applicationPointers->langIDptr->header.bLength; + status = SUCCESS; + } + else + { + // Iterates through the supported language IDs to find the index. + uint8_t langIdx = 0; + for (langIdx = 0; langIdx < LANG_ID_NUM; langIdx++) + { + if (langID == applicationPointers->langIDptr->id_array[langIdx]) + { + // Language match, langIdx found. + break; + } + } + + if (LANG_ID_NUM == langIdx) + { + // Language ID not in langID struct, returns UNSUPPORTED. + status = UNSUPPORTED; + } + else if (NULL != applicationPointers->stringPtrs[langIdx]) + { + // Iterates through string descriptors to account for different string lengths. + USB_DESCRIPTOR_HEADER_t *stringHeader = applicationPointers->stringPtrs[langIdx]; + if (1u == stringIndex) + { + status = SUCCESS; + } + else + { + for (uint8_t i = 1u; i < stringIndex; i++) + { + status = NextDescriptorPointerGet(USB_DESCRIPTOR_TYPE_STRING, &stringHeader); + } + } + + // Writes pointer and length. + if (SUCCESS == status) + { + *descriptorAddressPtr = (uint8_t *)stringHeader; + *descriptorLength = (uint16_t)stringHeader->bLength; + } + } + else + { + // stringPtrs not set up correctly, returns error. + status = DESCRIPTOR_POINTER_ERROR; + } + } + } + else + { + // langIDptr not set up, returns unsupported and stalls request. + status = UNSUPPORTED; + } + + return status; +} diff --git a/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_common/usb_core_descriptors.h b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_common/usb_core_descriptors.h new file mode 100644 index 0000000..647ef38 --- /dev/null +++ b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_common/usb_core_descriptors.h @@ -0,0 +1,181 @@ +/** + * USBCOREDESCRIPTOR Core Descriptors Header File + * @file usb_core_descriptors.h + * @defgroup usb_core_descriptors USB Descriptor Definitions + * @ingroup usb_core + * @brief In this file the active configuration and interfaces can be changed. + * The active configuration and active interface is referenced by a pointer as two global variables. + * @version USB Device Core Version 1.0.0 + */ + +/* + (c) 2021 Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip software and any + derivatives exclusively with Microchip products. It is your responsibility to comply with third party + license terms applicable to your use of third party software (including open source software) that + may accompany Microchip software. + + THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER + EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY + IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS + FOR A PARTICULAR PURPOSE. + + IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND + WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP + HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO + THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL + CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT + OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS + SOFTWARE. + */ + +#ifndef USB_CORE_DESCRIPTORS_H +// cppcheck-suppress misra-c2012-2.5 +#define USB_CORE_DESCRIPTORS_H + +#include + +#include +#include + +/** + * @ingroup usb_core + * @brief Handles Descriptor pointer setup. + * Sets the address to the application descriptor pointers. + * Checks if the device pointer and a pointer to the start of the application configuration(s) are set before saving the address to the USB Core Stack. + * @param *descriptorPtr - The address of the application descriptor pointers + * @return SUCCESS or an Error code according to RETURN_CODE_t + */ +RETURN_CODE_t USB_DescriptorPointersSet(USB_DESCRIPTOR_POINTERS_t *descriptorPtr); + +/** + * @ingroup usb_core + * @brief Enables endpoint configuration descriptor. + * + * The USB Device Enable Endpoint function, from USB 2.0 Specification Ch. 9.6.6. + * | Offset | Field | Size | Value | Description | + * |--------|------------------|------|----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| + * | 0 | bLength | 1 | Number | Size of this descriptor in bytes | + * | 1 | bDescriptorType | 1 | Constant | CONFIGURATION Descriptor Type | + * | 2 | bEndpointAddress | 1 | Endpoint | Address of the endpoint on the USB device described by this descriptor. Address is encoded by the following: Bit 3-0: The endpoint number, Bit 6-4: Reserved, reset to zero, Bit 7: Direction, ignored for control endpoint. 0 = OUT endpoint, 1 = IN endpoint | + * | 3 | bmAttributes | 1 | Bitmap | Describes the endpoint attributes when it is configured using the bConfigurationValue. Bit 1-0: Transfer type, 00=Control, 01=Isochronous, 10=Bulk, 11=Interrupt. If not isochronous endpoint, bit 5-2 are reserved and must be set to zero. If isochronous: Bit 3-2: Synchronization type, 00 = No Sync, 01 = Async, 10 = Adaptive, 11 = Sync. Bit 5-4: Usage type, 00 = Data endpoint, 01 = Feedback endpoint, 10 = Implicit feedback Data endpoint, 11 = Reserved. All other bits are reserved and must be reset to zero. Reserved bits must be ignored by the host. | + * | 4 | wMaxPacketSize | 2 | Number | Maximum packet size this endpoint is capable of RX/TX when this configuration is selected. For isochronous endpoints, this value is used to reserve bus time in the schedule. For all endpoints, bit 10-0 specify maximum packet size. For high-speed isochronous and interrupt endpoints: Bit 12-11 number of additional transaction opportunities per microframe, 00 = None (1 transaction per microframe), 01 = 1 additional, 10 = 2 additional, 11 = Reserved. Bits 15-13 are reserved and must be set to zero. | + * + * @param configurationValue - The value of the configuration to be enabled + * @return SUCCESS or an Error code according to RETURN_CODE_t + */ +RETURN_CODE_t USB_DescriptorConfigurationEnable(uint8_t configurationValue); + +/** + * @ingroup usb_core + * @brief Gets the Self-Powered setting from the active configuration. + * @param None. + * @retval 0 - Self-Powered is not enabled + * @retval 1 - Self-Powered is enabled + */ +bool USB_DescriptorActiveConfigurationSelfPoweredGet(void); + +/** + * @ingroup usb_core + * @brief Gets the Remote Wake-up setting from the active configuration. + * @param None. + * @retval 0 - Remote Wake-up is not enabled + * @retval 1 - Remote Wake-up is enabled + */ +bool USB_DescriptorActiveConfigurationRemoteWakeupGet(void); + +/** + * @ingroup usb_core + * @brief Gets the active configuration value. + * @param None. + * @return The active configuration value + */ +uint8_t USB_DescriptorActiveConfigurationValueGet(void); + +/** + * @ingroup usb_core + * @brief Enables or Disables an Interface Descriptor. + * + * The USB Device Enable Interface Descriptor, from USB 2.0 Specification Ch. 9.6.5. + * | Offset | Field | Size | Value | Description | + * |--------|---------------------|------|----------|---------------------------------------------------------------------------------------------------------------------------------------| + * | 2 | bInterfaceNumber | 1 | Number | Number of this interface. Zero-based value identifying the index in the array of concurrent interfaces supported by this configuration| + * | 3 | bAlternateSetting | 1 | Number | Value used to select this alternate setting for the interface identified in the prior field | + * + * @param interfaceNumber - Interface number value + * @param alternateSetting - Alternative settings value, ignored if enable is false + . @param enable - Enable or disable the interface. + * @return SUCCESS or an Error code according to RETURN_CODE_t + */ +RETURN_CODE_t USB_DescriptorInterfaceConfigure(uint8_t interfaceNumber, uint8_t alternateSetting, bool enable); + +/** + * @ingroup usb_core + * @brief Gets the pointer to the descriptor. + * @param descriptor - Descriptor type + * @param attribute - Attribute type + * @param **descriptorPtr - Pointer to the descriptor + * @param *descriptorLength - Length of the descriptor + * @return SUCCESS or an Error code according to RETURN_CODE_t + */ +RETURN_CODE_t USB_DescriptorPointerGet(USB_DESCRIPTOR_TYPE_t descriptor, uint8_t attribute, uint8_t **descriptorPtr, uint16_t *descriptorLength); + +/** + * @ingroup usb_core + * @brief Gets the pointer to the string descriptor. + * @param stringIndex - Index of the string + * @param langID - Language ID + * @param **descriptorAddressPtr - Pointer to the descriptor + * @param *descriptorLength - Length of the descriptor + * @return SUCCESS or an Error code according to RETURN_CODE_t + */ +RETURN_CODE_t USB_DescriptorStringPointerGet(uint8_t stringIndex, uint16_t langID, uint8_t **descriptorAddressPtr, uint16_t *descriptorLength); + +/** + * @ingroup usb_core + * @brief Get the active alternate interface number for an interface. + * @param interfaceNumber - The interface number to get the alternate setting for + * @param *alternateSetting - The requested alternate setting + * @return SUCCESS or an Error code according to RETURN_CODE_t + */ +RETURN_CODE_t ActiveAlternateSettingGet(uint8_t interfaceNumber, uint8_t *alternateSetting); + +/** + * @ingroup usb_core + * @brief Set the active alternate interface number for an interface. + * @param interfaceNumber - The interface number to set the alternate setting for + * @param alternateSetting - The alternate setting to set + * @return SUCCESS or an Error code according to RETURN_CODE_t + */ +RETURN_CODE_t ActiveAlternateSettingSet(uint8_t interfaceNumber, uint8_t alternateSetting); + +/** + * @ingroup usb_core + * @brief Collects the configuration pointer. + * @param configurationValue - Value of the referenced configuration + * @param **configurationPtr - Pointer to the configuration + * @return SUCCESS or an Error code according to RETURN_CODE_t + */ +RETURN_CODE_t ConfigurationPointerGet(uint8_t configurationValue, USB_CONFIGURATION_DESCRIPTOR_t **configurationPtr); + +/** + * @ingroup usb_core + * @brief Configures the endpoints as given in the descriptor. + * @param *interfacePtr - Pointer to an interface + * @param enable - Boolean to enable or disable the endpoint + * @return SUCCESS or an Error code according to RETURN_CODE_t + */ +RETURN_CODE_t DescriptorEndpointsConfigure(USB_INTERFACE_DESCRIPTOR_t *interfacePtr, bool enable); + +/** + * @ingroup usb_core + * @brief Gets the next descriptor. + * @param descriptorType - Selected descriptor type + * @param **descriptorHeaderPtr - Pointer to the descriptor header + * @return SUCCESS or an Error code according to RETURN_CODE_t + */ +RETURN_CODE_t NextDescriptorPointerGet(USB_DESCRIPTOR_TYPE_t descriptorType, USB_DESCRIPTOR_HEADER_t **descriptorHeaderPtr); + +#endif /* USB_CORE_DESCRIPTORS_H */ \ No newline at end of file diff --git a/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_common/usb_core_events.c b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_common/usb_core_events.c new file mode 100644 index 0000000..cbaf70d --- /dev/null +++ b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_common/usb_core_events.c @@ -0,0 +1,170 @@ +/** + * USBCOREEVENTS USB Core Events Source File + * @file usb_core_events.h + * @ingroup usb_core_events + * @brief Event handling for the USB Core Stack. + * @version USB Device Core Version 1.0.0 + */ + +/* + (c) 2021 Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip software and any + derivatives exclusively with Microchip products. It is your responsibility to comply with third party + license terms applicable to your use of third party software (including open source software) that + may accompany Microchip software. + + THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER + EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY + IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS + FOR A PARTICULAR PURPOSE. + + IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND + WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP + HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO + THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL + CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT + OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS + SOFTWARE. + */ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +USB_EVENT_HANDLERS_t event; + +RETURN_CODE_t USB_EventHandler(void) +{ + RETURN_CODE_t status = SUCCESS; + + if (USB_EventSOFIsReceived() == true) + { + USB_EventSOFClear(); + if (NULL != event.SOFCallback) + { + event.SOFCallback(); + } + } + if (USB_EventResetIsReceived() == true) + { + USB_EventResetClear(); + if (NULL != event.ResetCallback) + { + event.ResetCallback(); + } + USB_PIPE_t pipe = { .address = 0 }; + while (pipe.address < USB_EP_NUM) + { + pipe.direction = USB_EP_DIR_IN; + if (SUCCESS == status) + { + status = USB_TransferAbort(pipe); + } + pipe.direction = USB_EP_DIR_OUT; + if (SUCCESS == status) + { + status = USB_TransferAbort(pipe); + } + pipe.address++; + } + status = USB_Reset(); + } + uint8_t eventOverUnderflow = USB_EventOverUnderflowIsReceived(); + if (0u < eventOverUnderflow) + { + USB_EventOverUnderflowClear(); + uint8_t controlOverUnderflow = USB_ControlOverUnderflowIsReceived(); + if (0u < controlOverUnderflow) + { + status = USB_ControlProcessOverUnderflow(controlOverUnderflow); + } + else + { + // Non-control overunderflows currently ignored by event handler + status = SUCCESS; + } + } + if (USB_EventSuspendIsReceived() == true) + { + USB_EventSuspendClear(); + if (NULL != event.SuspendCallback) + { + event.SuspendCallback(); + } + } + if (USB_EventResumeIsReceived() == true) + { + USB_EventResumeClear(); + if (NULL != event.ResumeCallback) + { + event.ResumeCallback(); + } + } + if (USB_EventStalledIsReceived() == true) + { + USB_EventStalledClear(); + USB_PIPE_t pipe = { .address = 0x00, .direction = USB_EP_DIR_OUT }; + status = USB_HandleEventStalled(pipe); + } + return status; +} + +void USB_SetConfigurationCallbackRegister(USB_SETUP_EVENT_CALLBACK_t callback) +{ + event.SetConfiguration = callback; +} + +void USB_SetInterfaceCallbackRegister(USB_SETUP_EVENT_CALLBACK_t callback) +{ + event.SetInterface = callback; +} + +void USB_InterfaceDisabledCallbackRegister(USB_EVENT_CALLBACK_t callback) +{ + event.InterfaceDisabled = callback; +} + +void USB_VendorRequestCallbackRegister(USB_SETUP_PROCESS_CALLBACK_t callback) +{ + event.VendorRequest = callback; +} + +void USB_ClassRequestCallbackRegister(USB_SETUP_PROCESS_CALLBACK_t callback) +{ + event.ClassRequest = callback; +} + +void USB_OtherRequestCallbackRegister(USB_SETUP_PROCESS_CALLBACK_t callback) +{ + event.OtherRequest = callback; +} + +void USB_SOFCallbackRegister(USB_EVENT_CALLBACK_t callback) +{ + event.SOFCallback = callback; +} + +void USB_ResetCallbackRegister(USB_EVENT_CALLBACK_t callback) +{ + event.ResetCallback = callback; +} + +void USB_SuspendCallbackRegister(USB_EVENT_CALLBACK_t callback) +{ + event.SuspendCallback = callback; +} + +void USB_ResumeCallbackRegister(USB_EVENT_CALLBACK_t callback) +{ + event.ResumeCallback = callback; +} diff --git a/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_common/usb_core_events.h b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_common/usb_core_events.h new file mode 100644 index 0000000..ab23174 --- /dev/null +++ b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_common/usb_core_events.h @@ -0,0 +1,158 @@ +/** + * USBCOREEVENTS USB Core Events Header File + * @file usb_core_events.h + * @defgroup usb_core_events USB Core Events + * @ingroup usb_core + * @brief Event handling for the USB Core Stack. + * @version USB Device Core Version 1.0.0 + */ + +/* + (c) 2021 Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip software and any + derivatives exclusively with Microchip products. It is your responsibility to comply with third party + license terms applicable to your use of third party software (including open source software) that + may accompany Microchip software. + + THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER + EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY + IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS + FOR A PARTICULAR PURPOSE. + + IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND + WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP + HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO + THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL + CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT + OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS + SOFTWARE. + */ + +#ifndef USB_CORE_EVENTS_H +// cppcheck-suppress misra-c2012-2.5 +#define USB_CORE_EVENTS_H + +#include +#include + +#include + +#include +#include +#include +#include +#include + +/** + * @ingroup usb_core + * @struct USB_EVENT_HANDLERS_struct + * @brief Represents the event callbacks, the configuration and the enumeration setups. + */ +typedef struct USB_EVENT_HANDLERS_struct +{ + USB_SETUP_EVENT_CALLBACK_t SetConfiguration; + USB_SETUP_EVENT_CALLBACK_t SetInterface; + USB_EVENT_CALLBACK_t InterfaceDisabled; + USB_SETUP_PROCESS_CALLBACK_t VendorRequest; + USB_SETUP_PROCESS_CALLBACK_t ClassRequest; + USB_SETUP_PROCESS_CALLBACK_t OtherRequest; + USB_EVENT_CALLBACK_t SOFCallback; + USB_EVENT_CALLBACK_t ResetCallback; + USB_EVENT_CALLBACK_t SuspendCallback; + USB_EVENT_CALLBACK_t ResumeCallback; +} USB_EVENT_HANDLERS_t; + +extern USB_EVENT_HANDLERS_t event; + +/** + * @ingroup usb_core + * @brief Handles the different types of events. + * @param None. + * @return SUCCESS or an Error code according to RETURN_CODE_t + */ + +RETURN_CODE_t USB_EventHandler(void); + +/** + * @ingroup usb_core + * @brief Registers a callback for Set Configuration requests. + * @param callback - Reference for the callback function + * @return None. + */ +void USB_SetConfigurationCallbackRegister(USB_SETUP_EVENT_CALLBACK_t callback); + +/** + * @ingroup usb_core + * @brief Registers a callback for Set Interface requests. + * @param callback - Reference for the callback function + * @return None. + */ +void USB_SetInterfaceCallbackRegister(USB_SETUP_EVENT_CALLBACK_t callback); + +/** + * @ingroup usb_core + * @brief Registers a callback for disabling interfaces. + * @param callback - Reference for the callback function + * @return None. + */ +void USB_InterfaceDisabledCallbackRegister(USB_EVENT_CALLBACK_t callback); + +/** + * @ingroup usb_core + * @brief Registers a callback for vendor requests. + * @param callback - Reference for the callback function + * @return None. + */ +void USB_VendorRequestCallbackRegister(USB_SETUP_PROCESS_CALLBACK_t callback); + +/** + * @ingroup usb_core + * @brief Registers a callback for class requests. + * @param callback - Reference for the callback function + * @return None. + */ +void USB_ClassRequestCallbackRegister(USB_SETUP_PROCESS_CALLBACK_t callback); + +/** + * @ingroup usb_core + * @brief Registers a callback for other requests. + * @param callback - Reference for the callback function + * @return None. + */ +void USB_OtherRequestCallbackRegister(USB_SETUP_PROCESS_CALLBACK_t callback); + +/** + * @ingroup usb_core + * @brief Registers a callback for Start-Of-Frame (SOF) events. + * @param callback - Reference for the callback function + * @return None. + */ +void USB_SOFCallbackRegister(USB_EVENT_CALLBACK_t callback); + +/** + * @ingroup usb_core + * @brief Registers a callback for Reset events. + * @param callback - Reference for the callback function + * @return None. + */ +void USB_ResetCallbackRegister(USB_EVENT_CALLBACK_t callback); + +/** + * @ingroup usb_core + * @brief Registers a callback for Suspend events. + * @param callback - Reference for the callback function + * @return None. + */ +void USB_SuspendCallbackRegister(USB_EVENT_CALLBACK_t callback); + +/** + * @ingroup usb_core + * @brief Registers a callback for Resume events. + * @param callback - Reference for the callback function + * @return None. + */ +void USB_ResumeCallbackRegister(USB_EVENT_CALLBACK_t callback); + +#endif /* USB_CORE_EVENTS_H */ diff --git a/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_common/usb_core_requests.c b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_common/usb_core_requests.c new file mode 100644 index 0000000..2128d14 --- /dev/null +++ b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_common/usb_core_requests.c @@ -0,0 +1,194 @@ +/** + * USBCOREREQUESTS USB Core Requests Source File + * @file usb_core_requests.c + * @ingroup usb_core_requests + * @brief USB Device Core Requests handling. + * @version USB Device Core Version 1.0.0 + */ + +/* + (c) 2021 Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip software and any + derivatives exclusively with Microchip products. It is your responsibility to comply with third party + license terms applicable to your use of third party software (including open source software) that + may accompany Microchip software. + + THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER + EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY + IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS + FOR A PARTICULAR PURPOSE. + + IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND + WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP + HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO + THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL + CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT + OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS + SOFTWARE. + */ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +RETURN_CODE_t USB_SetupProcessDeviceRequest(USB_SETUP_REQUEST_t *setupRequestPtr) +{ + RETURN_CODE_t status = UNINITIALIZED; + + switch (setupRequestPtr->bRequest) + { + case USB_REQUEST_GET_STATUS: + { + status = SetupDeviceRequestGetStatus(); + break; + } + case USB_REQUEST_CLEAR_FEATURE: + { + status = SetupDeviceRequestClearFeature(setupRequestPtr); + break; + } + case USB_REQUEST_SET_FEATURE: + { + status = SetupDeviceRequestSetFeature(setupRequestPtr); + break; + } + case USB_REQUEST_SET_ADDRESS: + { + status = SetupDeviceRequestSetAddress((uint8_t)setupRequestPtr->wValue & 0xffu); + break; + } + case USB_REQUEST_GET_DESCRIPTOR: + { + status = SetupDeviceRequestGetDescriptor(setupRequestPtr); + break; + } + case USB_REQUEST_SET_DESCRIPTOR: + { + // Set Descriptor not supported, please STALL + status = UNSUPPORTED; + break; + } + case USB_REQUEST_GET_CONFIGURATION: + { + status = SetupDeviceRequestGetConfiguration(); + break; + } + case USB_REQUEST_SET_CONFIGURATION: + { + status = SetupDeviceRequestSetConfiguration((uint8_t)(setupRequestPtr->wValue & 0xffu)); + break; + } + default: + // Invalid request, please STALL + status = UNSUPPORTED; + break; + } + + return status; +} + +RETURN_CODE_t USB_SetupProcessEndpointRequest(USB_SETUP_REQUEST_t *setupRequestPtr) +{ + RETURN_CODE_t status = UNINITIALIZED; + + // Gets the requested endpoint, endpoint address and its direction + USB_PIPE_t endpoint = EndpointFromRequestGet(setupRequestPtr->wIndex); + + // Checks if the request is for a valid endpoint + if (endpoint.address >= (uint8_t)USB_EP_NUM) + { + status = ENDPOINT_ADDRESS_ERROR; + } + else + { + // Handles the actual endpoint requests + switch (setupRequestPtr->bRequest) + { + case USB_REQUEST_GET_STATUS: + { + status = SetupEndpointRequestGetStatus(setupRequestPtr); + break; + } + case USB_REQUEST_CLEAR_FEATURE: + { + status = SetupEndpointRequestClearFeature(setupRequestPtr); + break; + } + case USB_REQUEST_SET_FEATURE: + { + status = SetupEndpointRequestSetFeature(setupRequestPtr); + break; + } + case USB_REQUEST_SYNCH_FRAME: + { + status = SetupEndpointRequestSynchFrame(); + break; + } + default: + // Invalid request, please STALL + status = UNSUPPORTED; + break; + } + } + + return status; +} + +RETURN_CODE_t USB_SetupProcessInterfaceRequest(USB_SETUP_REQUEST_t *setupRequestPtr) +{ + RETURN_CODE_t status = UNINITIALIZED; + + // Gets the requested interface number + // Handles the actual interface requests + switch (setupRequestPtr->bRequest) + { + case USB_REQUEST_GET_STATUS: + { + status = USB_SetupInterfaceRequestGetStatus(); + break; + } + case USB_REQUEST_CLEAR_FEATURE: + { + // Features are not specified for USB 2 interfaces, please STALL + status = UNSUPPORTED; + break; + } + case USB_REQUEST_SET_FEATURE: + { + // Features are not specified for USB 2 interfaces, please STALL + status = UNSUPPORTED; + break; + } + case USB_REQUEST_GET_INTERFACE: + { + status = USB_SetupInterfaceRequestGetInterface(setupRequestPtr); + break; + } + case USB_REQUEST_SET_INTERFACE: + { + status = USB_SetupInterfaceRequestSetInterface(setupRequestPtr); + break; + } + case USB_REQUEST_GET_DESCRIPTOR: + { + status = USB_SetupInterfaceRequestGetDescriptor(setupRequestPtr); + break; + } + default: + // Invalid request, please STALL + status = UNSUPPORTED; + break; + } + + return status; +} diff --git a/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_common/usb_core_requests.h b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_common/usb_core_requests.h new file mode 100644 index 0000000..27ba20f --- /dev/null +++ b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_common/usb_core_requests.h @@ -0,0 +1,105 @@ +/** + * USBCOREREQUESTS USB Core Requests Header File + * @file usb_core_requests.h + * @defgroup usb_core_requests USB Core Requests + * @ingroup usb_core + * @brief USB Device Core Requests handling. + * @version USB Device Core Version 1.0.0 + */ + +/* + (c) 2021 Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip software and any + derivatives exclusively with Microchip products. It is your responsibility to comply with third party + license terms applicable to your use of third party software (including open source software) that + may accompany Microchip software. + + THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER + EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY + IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS + FOR A PARTICULAR PURPOSE. + + IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND + WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP + HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO + THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL + CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT + OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS + SOFTWARE. + */ + + +#ifndef USB_CORE_REQUESTS_H +// cppcheck-suppress misra-c2012-2.5 +#define USB_CORE_REQUESTS_H + +#include +#include + +#include +#include +#include +#include +#include + +/** + * @ingroup usb_core_requests + * @brief Setup function for the device requests + * + * USB 2.0 Specification Ch 9.4. + * | bRequest | wValue | wIndex | wLength | Data | + * |-------------------|-------------------|------------|---------|---------------------| + * | CLEAR_FEATURE | Feature selector | Zero | Zero | None | + * | GET_CONFIGURATION | Zero | Zero | One | Config value | + * | GET_DESCRIPTOR | Type and index | Zero or ID | Length | Descriptor | + * | GET_STATUS | Zero | Endpoint | Two | Device status | + * | SET_ADDRESS | Device address | Zero | Zero | None | + * | SET_CONFIGURATION | Config value | Zero | Zero | None | + * | SET_DESCRIPTOR | Type and index | Zero or ID | Length | Descriptor | + * | SET_FEATURE | Feature selector | Zero | Zero | None | + * + * @param setupRequestPtr - Pointer to the setup request and its data + * @return SUCCESS or an Error code according to RETURN_CODE_t + */ +RETURN_CODE_t USB_SetupProcessDeviceRequest(USB_SETUP_REQUEST_t *setupRequestPtr); + +/** + * @ingroup usb_core_requests + * @brief Setup function for the endpoint requests + * + * USB 2.0 Specification Ch. 9.4. + * | bRequest | wValue | wIndex | wLength | Data | + * |---------------|------------------|----------|---------|-----------------| + * | CLEAR_FEATURE | Feature selector | Endpoint | Zero | None | + * | GET_STATUS | Zero | Endpoint | Two | Endpoint status | + * | SET_FEATURE | Feature selector | Endpoint | Zero | None | + * | SYNCH_FRAME | Zero | Endpoint | Two | Frame number | + * + * @param *setupRequestPtr - Pointer to the request and its data + * @return SUCCESS or an Error code according to RETURN_CODE_t + */ +RETURN_CODE_t USB_SetupProcessEndpointRequest(USB_SETUP_REQUEST_t *setupRequestPtr); + +/** + * @ingroup usb_core_requests + * @brief Setup function for the interface requests + * + * USB 2.0 Specification Ch 9.4. + * | bRequest | wValue | wIndex | wLength | Data | + * |-----------------|-------------------|-----------|---------|---------------------| + * | CLEAR_FEATURE | Feature selector | Interface | Zero | None | + * | GET_INTERFACE | Zero | Interface | One | Alternate interface | + * | GET_STATUS | Zero | Interface | Two | Interface | + * | SET_FEATURE | Feature selector | Interface | Zero | None | + * | SET_INTERFACE | Alternate setting | Interface | Zero | None | + * | GET_DESCRIPTOR | Type and index | Zero | Length | Descriptor | + * + * @param setupRequestPtr - Pointer to the setup request and its data + * @return SUCCESS or an Error code according to RETURN_CODE_t + */ +RETURN_CODE_t USB_SetupProcessInterfaceRequest(USB_SETUP_REQUEST_t *setupRequestPtr); + +#endif /* USB_CORE_REQUESTS_H */ + diff --git a/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_common/usb_core_requests_device.c b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_common/usb_core_requests_device.c new file mode 100644 index 0000000..38c1124 --- /dev/null +++ b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_common/usb_core_requests_device.c @@ -0,0 +1,181 @@ +/** + * USBCOREREQUESTSDEVICE USB Core Requests Device Core File + * @file usb_core_requests_device.c + * @ingroup usb_core_requests + * @brief USB Device Core Requests handling. + * @version USB Device Core Version 1.0.0 + */ + +/* + (c) 2021 Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip software and any + derivatives exclusively with Microchip products. It is your responsibility to comply with third party + license terms applicable to your use of third party software (including open source software) that + may accompany Microchip software. + + THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER + EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY + IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS + FOR A PARTICULAR PURPOSE. + + IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND + WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP + HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO + THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL + CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT + OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS + SOFTWARE. + */ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +STATIC uint8_t deviceAddress = 0; + +RETURN_CODE_t SetupDeviceRequestGetStatus(void) +{ + // Return IN transaction with Remote Wake-up and Self Powered. + uint8_t data[] = {0, 0}; + + if (USB_DescriptorActiveConfigurationSelfPoweredGet()) + { + data[0] |= USB_REQUEST_DEVICE_SELF_POWERED; + } + if (USB_DescriptorActiveConfigurationRemoteWakeupGet()) + { + data[0] |= USB_REQUEST_DEVICE_REMOTE_WAKEUP; + } + + return USB_ControlTransferDataWriteBuffer(data, sizeof(data)); +} + +RETURN_CODE_t SetupDeviceRequestClearFeature(USB_SETUP_REQUEST_t *setupRequestPtr) +{ + RETURN_CODE_t status = UNINITIALIZED; + + // Clear feature for DEVICE_REMOTE_WAKEUP and TEST_MODE not yet supported + (void)setupRequestPtr; + + return status; +} + +RETURN_CODE_t SetupDeviceRequestSetFeature(USB_SETUP_REQUEST_t *setupRequestPtr) +{ + RETURN_CODE_t status = UNINITIALIZED; + + // Set feature for DEVICE_REMOTE_WAKEUP and TEST_MODE not yet supported + (void)setupRequestPtr; + + return status; +} + +RETURN_CODE_t SetupDeviceRequestSetAddress(uint8_t address) +{ + // Must register the callback here since device address must be set after completion of status stage. + deviceAddress = address; + USB_ControlEndOfRequestCallbackRegister(&SetupDeviceAddressCallback); + + return SUCCESS; +} + +void SetupDeviceAddressCallback(void) +{ + USB_DeviceAddressConfigure(deviceAddress); + USB_ControlEndOfRequestCallbackRegister(NULL); +} + +RETURN_CODE_t SetupDeviceRequestGetDescriptor(USB_SETUP_REQUEST_t *setupRequestPtr) +{ + RETURN_CODE_t status = UNINITIALIZED; + + uint8_t descriptorType = (uint8_t)(setupRequestPtr->wValue >> 8u); + uint8_t descriptorIndex = (uint8_t)(setupRequestPtr->wValue & 0xffu); + + if (USB_DESCRIPTOR_TYPE_VENDOR <= (USB_DESCRIPTOR_TYPE_t)descriptorType) + { + // Vendor Get_Descriptor Requests handled by VendorRequest callback. + if (NULL != event.VendorRequest) + { + status = event.VendorRequest(setupRequestPtr); + } + else + { + status = UNSUPPORTED; + } + } + else if (USB_DESCRIPTOR_TYPE_CLASS <= (USB_DESCRIPTOR_TYPE_t)descriptorType) + { + // Class Get_Descriptor Requests handled by ClassRequest callback. + if (NULL != event.ClassRequest) + { + status = event.ClassRequest(setupRequestPtr); + } + else + { + status = UNSUPPORTED; + } + } + else + { + uint8_t *descriptorPtr = NULL; + uint16_t descriptorLength = 0; + + if (USB_DESCRIPTOR_TYPE_STRING == (USB_DESCRIPTOR_TYPE_t)descriptorType) + { + status = USB_DescriptorStringPointerGet(descriptorIndex, setupRequestPtr->wIndex, &descriptorPtr, &descriptorLength); + } + else + { + // USB_DescriptorPointerGet will handle remaining invalid descriptorTypes. + status = USB_DescriptorPointerGet(descriptorType, descriptorIndex, &descriptorPtr, &descriptorLength); + } + + if (SUCCESS == status) + { + if (descriptorLength > setupRequestPtr->wLength) + { + descriptorLength = setupRequestPtr->wLength; + } + + status = USB_ControlTransferDataSet(descriptorPtr, descriptorLength); + } + } + + return status; +} + +RETURN_CODE_t SetupDeviceRequestGetConfiguration(void) +{ + uint8_t configurationValue = USB_DescriptorActiveConfigurationValueGet(); + + return USB_ControlTransferDataWriteBuffer(&configurationValue, sizeof(configurationValue)); +} + +RETURN_CODE_t SetupDeviceRequestSetConfiguration(uint8_t configurationValue) +{ + RETURN_CODE_t status = UNINITIALIZED; + + if ((deviceAddress == 0u)) + { + status = USB_CONNECTION_ERROR; + } + else + { + // Enables configuration, clears it if configurationValue is zero. + status = USB_DescriptorConfigurationEnable(configurationValue); + } + + return status; +} diff --git a/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_common/usb_core_requests_device.h b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_common/usb_core_requests_device.h new file mode 100644 index 0000000..a2f62ac --- /dev/null +++ b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_common/usb_core_requests_device.h @@ -0,0 +1,107 @@ +/** + * USBCOREREQUESTSDEVICE USB Core Requests Device Header File + * @file usb_core_requests_device.h + * @ingroup usb_core_requests + * @brief USB Device Core Requests handling. + * @version USB Device Core Version 1.0.0 + */ + +/* + (c) 2021 Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip software and any + derivatives exclusively with Microchip products. It is your responsibility to comply with third party + license terms applicable to your use of third party software (including open source software) that + may accompany Microchip software. + + THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER + EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY + IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS + FOR A PARTICULAR PURPOSE. + + IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND + WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP + HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO + THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL + CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT + OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS + SOFTWARE. + */ + +#ifndef USB_CORE_REQUESTS_DEVICE_H +// cppcheck-suppress misra-c2012-2.5 +#define USB_CORE_REQUESTS_DEVICE_H + +#include +#include + +#include "usb_protocol_headers.h" +#include "usb_common_elements.h" + +/** + * @ingroup usb_core_requests + * @brief Returns the status of the device features. + * @param None. + * @return SUCCESS or an Error code according to RETURN_CODE_t + */ +RETURN_CODE_t SetupDeviceRequestGetStatus(void); + +/** + * @ingroup usb_core_requests + * @brief Clears the device feature. + * @param *setupRequestPtr - Pointer to the setup request + * @return SUCCESS or an Error code according to RETURN_CODE_t + */ +RETURN_CODE_t SetupDeviceRequestClearFeature(USB_SETUP_REQUEST_t *setupRequestPtr); + +/** + * @ingroup usb_core_requests + * @brief Sets the device feature. + * @param *setupRequestPtr - Pointer to the setup request + * @return SUCCESS or an Error code according to RETURN_CODE_t + */ +RETURN_CODE_t SetupDeviceRequestSetFeature(USB_SETUP_REQUEST_t *setupRequestPtr); + +/** + * @ingroup usb_core_requests + * @brief Sets the device address. + * @param address - Address to be set + * @return SUCCESS or an Error code according to RETURN_CODE_t + */ +RETURN_CODE_t SetupDeviceRequestSetAddress(uint8_t address); + +/** + * @ingroup usb_core_requests + * @brief Callback function for the address. + * @param None. + * @return None. + */ +void SetupDeviceAddressCallback(void); + +/** + * @ingroup usb_core_requests + * @brief Gets the device descriptor. + * @param *setupRequestPtr - Pointer to the setup request + * @return SUCCESS or an Error code according to RETURN_CODE_t + */ +RETURN_CODE_t SetupDeviceRequestGetDescriptor(USB_SETUP_REQUEST_t *setupRequestPtr); + +/** + * @ingroup usb_core_requests + * @brief Gets the device configuration. + * @param None. + * @return SUCCESS or an Error code according to RETURN_CODE_t + */ +RETURN_CODE_t SetupDeviceRequestGetConfiguration(void); + +/** + * @ingroup usb_core_requests + * @brief Sets the device configuration. + * @param configurationValue - Configuration value to be set + * @return SUCCESS or an Error code according to RETURN_CODE_t + */ +RETURN_CODE_t SetupDeviceRequestSetConfiguration(uint8_t configurationValue); + +#endif /* USB_CORE_REQUESTS_DEVICE_H */ + diff --git a/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_common/usb_core_requests_endpoint.c b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_common/usb_core_requests_endpoint.c new file mode 100644 index 0000000..f9c150b --- /dev/null +++ b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_common/usb_core_requests_endpoint.c @@ -0,0 +1,137 @@ +/** + * USBCOREREQUESTSENDPOINT USB Core Requests Endpoint Source File + * @file usb_core_requests_endpoint.c + * @ingroup usb_core_requests + * @brief USB Endpoint Core Requests handling. + * @version USB Device Core Version USB 1.0.0 + */ + +/* + (c) 2021 Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip software and any + derivatives exclusively with Microchip products. It is your responsibility to comply with third party + license terms applicable to your use of third party software (including open source software) that + may accompany Microchip software. + + THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER + EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY + IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS + FOR A PARTICULAR PURPOSE. + + IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND + WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP + HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO + THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL + CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT + OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS + SOFTWARE. + */ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +/** + * @ingroup usb_core_requests + * @def GET_STATUS_ENDPOINT_STALLED + * @brief Mask for the endpoint stall status in the first byte of the data stage of the setup request. + */ +#define GET_STATUS_ENDPOINT_STALLED (1u << 0u) + +/** + * @ingroup usb_core_requests + * @def ENDPOINT_ADDRESS_MASK + * @brief Mask for the endpoint address in the wIndex field of the setup request. + */ +#define ENDPOINT_ADDRESS_MASK (0x7fu) + +/** + * @ingroup usb_core_requests + * @def ENDPOINT_DIRECTION_BITPOSITION + * @brief Bit position for the endpoint direction in the wIndex field of the setup request. + */ +#define ENDPOINT_DIRECTION_BITPOSITION (7u) + +USB_PIPE_t EndpointFromRequestGet(uint16_t wIndex) +{ + USB_PIPE_t endpoint; + endpoint.address = (uint8_t)wIndex & ENDPOINT_ADDRESS_MASK; + endpoint.direction = (uint8_t)wIndex >> ENDPOINT_DIRECTION_BITPOSITION; + + return endpoint; +} + +RETURN_CODE_t SetupEndpointRequestGetStatus(USB_SETUP_REQUEST_t *setupRequestPtr) +{ + // Return IN transaction with ENDPOINT_HALT status (2 bytes) + USB_PIPE_t endpoint = EndpointFromRequestGet(setupRequestPtr->wIndex); + + uint8_t data[] = {0, 0}; + if (USB_EndpointIsStalled(endpoint) == true) + { + + data[0] |= GET_STATUS_ENDPOINT_STALLED; + } + + return USB_ControlTransferDataWriteBuffer(data, sizeof (data)); +} + +RETURN_CODE_t SetupEndpointRequestClearFeature(USB_SETUP_REQUEST_t *setupRequestPtr) +{ + RETURN_CODE_t status = UNINITIALIZED; + + // Only ENDPOINT_HALT available for endpoints + if (setupRequestPtr->wValue == USB_ENDPOINT_FEATURE_HALT) + { + USB_PIPE_t endpoint = EndpointFromRequestGet(setupRequestPtr->wIndex); + + status = USB_EndpointStallClear(endpoint); + } + else + { + status = UNSUPPORTED; + } + + return status; +} + +RETURN_CODE_t SetupEndpointRequestSetFeature(USB_SETUP_REQUEST_t *setupRequestPtr) +{ + RETURN_CODE_t status = UNINITIALIZED; + + // Only ENDPOINT_HALT available for endpoints + if (setupRequestPtr->wValue == USB_ENDPOINT_FEATURE_HALT) + { + USB_PIPE_t endpoint = EndpointFromRequestGet(setupRequestPtr->wIndex); + + status = USB_TransferAbort(endpoint); + if (SUCCESS == status) + { + status = USB_EndpointStall(endpoint); + } + } + else + { + status = UNSUPPORTED; + } + + return status; +} + +RETURN_CODE_t SetupEndpointRequestSynchFrame(void) +{ + uint16_t framenum = USB_FrameNumberGet(); + + return USB_ControlTransferDataWriteBuffer((uint8_t*) & framenum, sizeof (framenum)); +} diff --git a/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_common/usb_core_requests_endpoint.h b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_common/usb_core_requests_endpoint.h new file mode 100644 index 0000000..74c16da --- /dev/null +++ b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_common/usb_core_requests_endpoint.h @@ -0,0 +1,84 @@ +/** + * USBCOREREQUESTSENDPOINT USB Core Requests Endpoint Header File + * @file usb_core_requests_endpoint.h + * @ingroup usb_core_requests + * @brief USB Endpoint Core Requests handling. + * @version USB Device Core Version USB 1.0.0 + */ + +/* + (c) 2021 Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip software and any + derivatives exclusively with Microchip products. It is your responsibility to comply with third party + license terms applicable to your use of third party software (including open source software) that + may accompany Microchip software. + + THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER + EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY + IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS + FOR A PARTICULAR PURPOSE. + + IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND + WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP + HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO + THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL + CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT + OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS + SOFTWARE. + */ + + +#ifndef USB_CORE_REQUESTS_ENDPOINT_H +// cppcheck-suppress misra-c2012-2.5 +#define USB_CORE_REQUESTS_ENDPOINT_H + +#include +#include + +#include "usb_protocol_headers.h" +#include "usb_common_elements.h" + +/** + * @ingroup usb_core_requests + * @brief Gets the endpoint status. + * @param wIndex - Endpoint address and direction + * @return A structure with the endpoint status + */ +USB_PIPE_t EndpointFromRequestGet(uint16_t wIndex); + +/** + * @ingroup usb_core_requests + * @brief Gets the endpoint status. + * @param *setupRequestPtr - Pointer to the setup request + * @return SUCCESS or an Error code according to RETURN_CODE_t + */ +RETURN_CODE_t SetupEndpointRequestGetStatus(USB_SETUP_REQUEST_t *setupRequestPtr); + +/** + * @ingroup usb_core_requests + * @brief Clears the endpoint feature. + * @param *setupRequestPtr - Pointer to the setup request + * @return SUCCESS or an Error code according to RETURN_CODE_t + */ +RETURN_CODE_t SetupEndpointRequestClearFeature(USB_SETUP_REQUEST_t *setupRequestPtr); + +/** + * @ingroup usb_core_requests + * @brief Sets the endpoint feature. + * @param *setupRequestPtr - Pointer to the setup request + * @return SUCCESS or an Error code according to RETURN_CODE_t + */ +RETURN_CODE_t SetupEndpointRequestSetFeature(USB_SETUP_REQUEST_t *setupRequestPtr); + +/** + * @ingroup usb_core_requests + * @brief Gets the current frame number. + * @param None. + * @return SUCCESS or an Error code according to RETURN_CODE_t + */ +RETURN_CODE_t SetupEndpointRequestSynchFrame(void); + +#endif /* USB_CORE_REQUESTS_ENDPOINT_H */ + diff --git a/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_common/usb_core_requests_interface.c b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_common/usb_core_requests_interface.c new file mode 100644 index 0000000..bbd76eb --- /dev/null +++ b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_common/usb_core_requests_interface.c @@ -0,0 +1,145 @@ +/** + * USBCOREREQUESTSINTERFACE USB Core Requests Interface Source File + * @file usb_core_requests_interface.c + * @ingroup usb_core_requests + * @brief USB Interface Core Requests handling. + * @version USB Device Core Version 1.0.0 + */ + +/* + (c) 2021 Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip software and any + derivatives exclusively with Microchip products. It is your responsibility to comply with third party + license terms applicable to your use of third party software (including open source software) that + may accompany Microchip software. + + THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER + EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY + IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS + FOR A PARTICULAR PURPOSE. + + IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND + WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP + HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO + THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL + CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT + OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS + SOFTWARE. + */ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +/** + * @ingroup usb_core_requests + * @def GET_INTERFACE_REQUEST_NUMBER_MASK + * @brief Mask for the interface number in the wIndex field of the setup request. + */ +#define GET_INTERFACE_REQUEST_NUMBER_MASK (0xffu) + +/** + * @ingroup usb_core_requests + * @def GET_INTERFACE_REQUEST_WVALUE + * @brief Value for the wValue field of the setup request. + */ +#define GET_INTERFACE_REQUEST_WVALUE 0u + +/** + * @ingroup usb_core_requests + * @def GET_INTERFACE_RESPONSE_SIZE + * @brief Size of the response to the Get Interface request. + */ +#define GET_INTERFACE_RESPONSE_SIZE 1u + +RETURN_CODE_t USB_SetupInterfaceRequestGetStatus(void) +{ + uint8_t data[] = {0, 0}; + + return USB_ControlTransferDataWriteBuffer(data, sizeof (data)); +} + +RETURN_CODE_t USB_SetupInterfaceRequestGetInterface(USB_SETUP_REQUEST_t *setupRequestPtr) +{ + RETURN_CODE_t status = UNINITIALIZED; + + if ((GET_INTERFACE_REQUEST_WVALUE == setupRequestPtr->wValue) && (GET_INTERFACE_RESPONSE_SIZE == setupRequestPtr->wLength)) + { + uint8_t alternateSetting; + status = ActiveAlternateSettingGet((GET_INTERFACE_REQUEST_NUMBER_MASK & setupRequestPtr->wIndex), &alternateSetting); + if (SUCCESS == status) + { + status = USB_ControlTransferDataWriteBuffer(&alternateSetting, sizeof(alternateSetting)); + } + } + else + { + status = INTERFACE_GET_ERROR; + } + + return status; +} + +RETURN_CODE_t USB_SetupInterfaceRequestSetInterface(USB_SETUP_REQUEST_t *setupRequestPtr) +{ + RETURN_CODE_t status = USB_DescriptorInterfaceConfigure(setupRequestPtr->wIndex, setupRequestPtr->wValue, true); + if (SUCCESS == status) + { + if (NULL != event.SetInterface) + { + event.SetInterface(setupRequestPtr); + } + } + + return status; +} + +RETURN_CODE_t USB_SetupInterfaceRequestGetDescriptor(USB_SETUP_REQUEST_t *setupRequestPtr) +{ + RETURN_CODE_t status = UNINITIALIZED; + + uint8_t descriptorType = (uint8_t)(setupRequestPtr->wValue >> 8u); + + if (USB_DESCRIPTOR_TYPE_VENDOR <= (USB_DESCRIPTOR_TYPE_t)descriptorType) + { + // Vendor Get_Descriptor Requests handled by VendorRequest callback + if (NULL != event.VendorRequest) + { + status = event.VendorRequest(setupRequestPtr); + } + else + { + status = UNSUPPORTED; + } + } + else if (USB_DESCRIPTOR_TYPE_CLASS <= (USB_DESCRIPTOR_TYPE_t)descriptorType) + { + // Class Get_Descriptor Requests handled by ClassRequest callback + if (NULL != event.ClassRequest) + { + status = event.ClassRequest(setupRequestPtr); + } + else + { + status = UNSUPPORTED; + } + } + else + { + // Standard descriptor types not supported on interface requests + status = UNSUPPORTED; + } + + return status; +} \ No newline at end of file diff --git a/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_common/usb_core_requests_interface.h b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_common/usb_core_requests_interface.h new file mode 100644 index 0000000..514907d --- /dev/null +++ b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_common/usb_core_requests_interface.h @@ -0,0 +1,101 @@ +/** + * USBCOREREQUESTSINTERFACE USB Core Requests Interface Header File + * @file usb_core_requests_interface.h + * @ingroup usb_core_requests + * @brief USB Interface Core Requests handling. + * @version USB Device Core Version 1.0.0 + */ + +/* + (c) 2021 Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip software and any + derivatives exclusively with Microchip products. It is your responsibility to comply with third party + license terms applicable to your use of third party software (including open source software) that + may accompany Microchip software. + + THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER + EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY + IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS + FOR A PARTICULAR PURPOSE. + + IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND + WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP + HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO + THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL + CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT + OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS + SOFTWARE. + */ + + +#ifndef USB_CORE_REQUESTS_INTERFACE_H +// cppcheck-suppress misra-c2012-2.5 +#define USB_CORE_REQUESTS_INTERFACE_H + +#include +#include + +#include "usb_protocol_headers.h" +#include "usb_common_elements.h" + +/** + * @ingroup usb_core_requests + * @brief Returns status for the specified interface. + * + * Get status from interface request according to USB 2.0 specification Ch. 9.4.5. + * | bRequest | wValue | wIndex | wLength | Data | + * |------------|--------|-------------|---------|-----------| + * | GET_STATUS | Zero | Interface | Two | Interface | + * + * @param None. + * @return SUCCESS or an Error code according to RETURN_CODE_t + */ +RETURN_CODE_t USB_SetupInterfaceRequestGetStatus(void); + +/** + * @ingroup usb_core_requests + * @brief Returns the alternate setting for the specified interface. + * + * Format for GET_INTERFACE request according to USB 2.0 specification Ch 9.4.4. + * Document: Universal Serial Bus Specification for USB 2.0. + * | bRequest | wValue | wIndex | wLength | Data | + * |---------------|--------|-----------|---------|-------------------| + * | GET_INTERFACE | Zero | Interface | One | Alternate setting | + * + * @param *setupRequestPtr - Pointer to the request and its data + * @return SUCCESS or an Error code according to RETURN_CODE_t + */ +RETURN_CODE_t USB_SetupInterfaceRequestGetInterface(USB_SETUP_REQUEST_t *setupRequestPtr); + +/** + * @ingroup usb_core_requests + * @brief Setup function for the interface request to select the alternate setting. + * + * A request to set interface according to USB 2.0 specification Ch. 9.4.10. + * Document: Universal Serial Bus Specification for USB 2.0 + * | bRequest | wValue | wIndex | wLength | Data | + * |---------------|-------------------|-----------|---------|------| + * | SET_INTERFACE | Alternate setting | Interface | Zero | None | + * + * @param *setupRequestPtr - Pointer to the request and its data + * @return SUCCESS or an Error code according to RETURN_CODE_t + */ +RETURN_CODE_t USB_SetupInterfaceRequestSetInterface(USB_SETUP_REQUEST_t *setupRequestPtr); + +/** + * @ingroup usb_core_requests + * @brief Setup function for the interface request for class-specific descriptors. + * + * | bRequest | wValue | wIndex | wLength | Data | + * |----------------|-------------------|-----------|---------|------------| + * | GET_DESCRIPTOR | Type and index | Zero | Length | Descriptor | + * + * @param *setupRequestPtr - Pointer to the request and its data + * @return SUCCESS or an Error code according to RETURN_CODE_t + */ +RETURN_CODE_t USB_SetupInterfaceRequestGetDescriptor(USB_SETUP_REQUEST_t *setupRequestPtr); + +#endif /* USB_CORE_REQUESTS_INTERFACE_H */ + diff --git a/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_common/usb_core_transfer.c b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_common/usb_core_transfer.c new file mode 100644 index 0000000..6e466a9 --- /dev/null +++ b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_common/usb_core_transfer.c @@ -0,0 +1,175 @@ +/** + * USBCORETRANSFER USB Core Transfer Source File + * @file usb_core_transfer.c + * @ingroup usb_core_transfer + * @brief USB core layer implementation file. + * @version USB Core Version 1.0.0 + */ + +/* + (c) 2021 Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip software and any + derivatives exclusively with Microchip products. It is your responsibility to comply with third party + license terms applicable to your use of third party software (including open source software) that + may accompany Microchip software. + + THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER + EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY + IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS + FOR A PARTICULAR PURPOSE. + + IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND + WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP + HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO + THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL + CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT + OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS + SOFTWARE. + */ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +RETURN_CODE_t USB_TransferWriteStart(USB_PIPE_t pipe, uint8_t *dataPtr, uint16_t dataSize, bool useZLP, USB_TRANSFER_END_CALLBACK_t callback) +{ + RETURN_CODE_t status = UNINITIALIZED; + + if (USB_PipeStatusIsBusy(pipe) == true) + { + status = PIPE_BUSY_ERROR; + } + else + { + status = USB_PipeReset(pipe); + } + + if (status == SUCCESS) + { + USB_PipeDataPtrSet(pipe, dataPtr); + USB_PipeDataToTransferSizeSet(pipe, dataSize); + USB_PipeDataTransferredSizeReset(pipe); + if (true == useZLP) + { + USB_PipeTransferZLP_Enable(pipe); + } + USB_PipeTransferEndCallbackRegister(pipe, callback); + status = USB_InTransactionRun(pipe); + } + return status; +} + +RETURN_CODE_t USB_TransferReadStart(USB_PIPE_t pipe, uint8_t *dataPtr, uint16_t dataSize, bool useZLP, USB_TRANSFER_END_CALLBACK_t callback) +{ + RETURN_CODE_t status = UNINITIALIZED; + + if (USB_PipeStatusIsBusy(pipe) == true) + { + status = PIPE_BUSY_ERROR; + } + else + { + status = USB_PipeReset(pipe); + } + + if (status == SUCCESS) + { + USB_PipeDataPtrSet(pipe, dataPtr); + USB_PipeDataToTransferSizeSet(pipe, dataSize); + USB_PipeDataTransferredSizeReset(pipe); + if (true == useZLP) + { + USB_PipeTransferZLP_Enable(pipe); + } + USB_PipeTransferEndCallbackRegister(pipe, callback); + status = USB_OutTransactionRun(pipe); + } + + return status; +} + +RETURN_CODE_t USB_TransferControlDataSet(uint8_t *dataPtr, uint16_t dataSize, USB_SETUP_ENDOFREQUEST_CALLBACK_t callback) +{ + USB_ControlEndOfRequestCallbackRegister(callback); + return USB_ControlTransferDataSet(dataPtr, dataSize); +} + +RETURN_CODE_t USB_TransferAbort(USB_PIPE_t pipe) +{ + RETURN_CODE_t status = UNINITIALIZED; + + // Checks if abort is needed. + if (USB_PipeStatusIsBusy(pipe) == true) + { + //Stops transfer. + status = USB_TransactionAbort(pipe); + + if (status == SUCCESS) + { + // Calls callback. + USB_PipeTransferEndCallback(pipe); + } + } + else + { + // Pipe is not busy, so no need to abort. + status = SUCCESS; + } + + return status; +} + +RETURN_CODE_t USB_TransferHandler(void) +{ + RETURN_CODE_t status = UNINITIALIZED; + + // If it's the initial setup packet, handle that separately. + if (USB_SetupIsReceived() == true) + { + status = USB_ControlSetupReceived(); + } + // If a transaction is complete, handle that one. + else if (USB_TransactionIsCompleted() == true) + { + // Finds out which pipe has a completed transaction. + USB_PIPE_t pipe; + + status = USB_TransactionCompletedPipeGet(&pipe); + + if (status == SUCCESS) + { + // Acks the transaction. + status = USB_TransactionCompleteAck(pipe); + } + + if (status == SUCCESS) + { + // Handles control transactions separately. + if (pipe.address == 0U) + { + status = USB_ControlTransactionComplete(pipe); + } + else + { + // Regular handling of all regular endpoints. + status = USB_PipeTransactionComplete(pipe); + } + } + } + else + { + // No handling needed, return SUCCESS. + status = SUCCESS; + } + + return status; +} diff --git a/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_common/usb_core_transfer.h b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_common/usb_core_transfer.h new file mode 100644 index 0000000..54e149f --- /dev/null +++ b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_common/usb_core_transfer.h @@ -0,0 +1,116 @@ +/** + * USBCORETRANSFER USB Core Transfer Header File + * @file usb_core_transfer.h + * @defgroup usb_core_transfer USB Core Transfer + * @ingroup usb_core + * @brief USB core layer implementation file. + * @version USB Core Version 1.0.0 + */ + +/* + (c) 2021 Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip software and any + derivatives exclusively with Microchip products. It is your responsibility to comply with third party + license terms applicable to your use of third party software (including open source software) that + may accompany Microchip software. + + THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER + EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY + IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS + FOR A PARTICULAR PURPOSE. + + IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND + WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP + HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO + THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL + CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT + OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS + SOFTWARE. + */ + + +#ifndef USB_CORE_TRANSFER_H +// cppcheck-suppress misra-c2012-2.5 +#define USB_CORE_TRANSFER_H + +#include +#include + +#include +#include + +#include +#include +#include +#include + +/** + * @ingroup usb_core_transfer + * @brief Sets up the pipe for the write transfers. + * + * Sets up the pipe for the write transfers and checks to see if it is busy. If it is not busy, then the routine resets the pipe, setting it up for write transfer, then starts the transfer. + * + * @param pipe - A combination of endpoint address and direction + * @param *dataPtr - The pointer to the data to write + * @param dataSize - The size of the data to write + * @param useZLP - Enable zero-length package at the end of transfer + * @param callback - A combination of pipe, status and transferred bytes + * @return SUCCESS or an Error code according to RETURN_CODE_t + */ +RETURN_CODE_t USB_TransferWriteStart(USB_PIPE_t pipe, uint8_t *dataPtr, uint16_t dataSize, bool useZLP, USB_TRANSFER_END_CALLBACK_t callback); + +/** + * @ingroup usb_core_transfer + * @brief Sets up the pipe for the read transfers. + * + * Sets up the pipe for the write transfers and checks to see if it is busy. If it is not busy, then the routine resets the pipe, setting it up for read transfer, then starts the transfer. + * + * @param pipe - A combination of endpoint address and direction + * @param *dataPtr - The pointer to the data to read + * @param dataSize - The size of the data to read + * @param useZLP - Enable zero-length package at the end of transfer + * @param callback - A combination of pipe, status and transferred bytes + * @return SUCCESS or an Error code according to RETURN_CODE_t + */ +RETURN_CODE_t USB_TransferReadStart(USB_PIPE_t pipe, uint8_t *dataPtr, uint16_t dataSize, bool useZLP, USB_TRANSFER_END_CALLBACK_t callback); + +/** + * @ingroup usb_core_transfer + * @brief Sets up vendor or class control request data transfers. + * + * Sets up the pointer and size of the read or write trnasfer in the control data stage. + * + * @param *dataPtr - The pointer to the data to read or write + * @param dataSize - The size of the data to read or write + * @param callback - Pointer to a function to be called at the end of the control request + * @return SUCCESS or an Error code according to RETURN_CODE_t + */ +RETURN_CODE_t USB_TransferControlDataSet(uint8_t *dataPtr, uint16_t dataSize, USB_SETUP_ENDOFREQUEST_CALLBACK_t callback); + +/** + * @ingroup usb_core_transfer + * @brief Aborts an ongoing transfer. + * + * Will call the pipe transferEndCallback with the abort status, if configured. + * + * @param pipe - A combination of endpoint address and direction + * @return SUCCESS or an Error code according to RETURN_CODE_t + */ +RETURN_CODE_t USB_TransferAbort(USB_PIPE_t pipe); + +/** + * @ingroup usb_core_transfer + * @brief Handles the different types of packages received or transferred. + * + * Checks if a setup package is received or if a transaction is completed and which pipe has a completed transaction, then it handles them accordingly. + * Sends an ACK upon completed transaction confirmation. + * + * @param None. + * @return SUCCESS or an Error code according to RETURN_CODE_t + */ +RETURN_CODE_t USB_TransferHandler(void); + +#endif /* USB_CORE_TRANSFER_H */ + diff --git a/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_common/usb_protocol_headers.h b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_common/usb_protocol_headers.h new file mode 100644 index 0000000..f83b599 --- /dev/null +++ b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_common/usb_protocol_headers.h @@ -0,0 +1,660 @@ +/** + * USBPROTOCOLHEADERS USB Protocol Headers Header File + * @file usb_protocol_headers.h + * @defgroup usb_protocol USB Protocol + * @ingroup usb_core + * @brief Common data structures, enumerations and macro definitons based on the USB 2.0 base protocol. + * @version USB Protocol Version 1.0.0 + */ + +/* + (c) 2021 Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip software and any + derivatives exclusively with Microchip products. It is your responsibility to comply with third party + license terms applicable to your use of third party software (including open source software) that + may accompany Microchip software. + + THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER + EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY + IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS + FOR A PARTICULAR PURPOSE. + + IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND + WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP + HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO + THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL + CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT + OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS + SOFTWARE. + */ + +#ifndef USB_PROTOCOL_HEADERS_H +// cppcheck-suppress misra-c2012-2.5 +#define USB_PROTOCOL_HEADERS_H + +#include "usb_common_elements.h" +#include +#include +#include + +/* + * ENDPOINT LAYER + */ + +/** + * @ingroup usb_protocol + * @def USB_EP_DIR_IN + * @brief Endpoint direction IN. + */ +#define USB_EP_DIR_IN 0x01u + +/** + * @ingroup usb_protocol + * @def USB_EP_DIR_OUT + * @brief Endpoint direction OUT. + */ +#define USB_EP_DIR_OUT 0x00u + +/** + * @ingroup usb_protocol + * @def OVERFLOW_EVENT + * @brief Overflow event for the endpoint. + */ +#define OVERFLOW_EVENT 1u + +/** + * @ingroup usb_protocol + * @def UNDERFLOW_EVENT + * @brief Underflow event for the endpoint. + */ +#define UNDERFLOW_EVENT 2u + +/** + * @ingroup usb_protocol + * @enum USB_ENDPOINT_enum + * @brief Defines labels for the different endpoint types as per the USB 2.0 base specification. + */ +typedef enum USB_ENDPOINT_enum +{ + CONTROL = 0, /** +#include + +/** + * @ingroup usb_device_stack + * @def USB_EP_NUM + * @brief Limits the size of the endpoint table and transfer array in the RAM + * to 1 + the highest endpoint address used by the application. + */ +#define USB_EP_NUM 5U + +/** + * @ingroup usb_device_stack + * @def USB_EP0_SIZE + * @brief Controls the packet size of endpoint 0 and must correspond to bMaxPacketSize0 in the device descriptor. + */ +#define USB_EP0_SIZE 64U + +/** + * @ingroup usb_device_stack + * @def LANG_ID_NUM + * @brief Controls the number of language IDs supported by the application. + */ +#define LANG_ID_NUM 1U + +/** + * @ingroup usb_device_stack + * @name USB Endpoint Addresses + * Macros for the endpoint addresses. + */ +///@{ +#define INTERFACE0ALTERNATE1_INTERRUPT_EP1_IN 1U +#define INTERFACE0ALTERNATE1_INTERRUPT_EP1_OUT 1U +#define INTERFACE0ALTERNATE1_BULK_EP2_IN 2U +#define INTERFACE0ALTERNATE1_BULK_EP2_OUT 2U +#define INTERFACE0ALTERNATE2_ISOCHRONOUS_EP3_IN 3U +#define INTERFACE0ALTERNATE2_ISOCHRONOUS_EP3_OUT 3U +#define INTERFACE0ALTERNATE3_ISOCHRONOUS_EP4_OUT 4U +#define INTERFACE0ALTERNATE4_ISOCHRONOUS_EP4_IN 4U +///@} + +/** + * @ingroup usb_device_stack + * @name USB Endpoint Packet Sizes + * Macros for the endpoint packet sizes. + */ +///@{ +#define INTERFACE0ALTERNATE1_INTERRUPT_EP1_IN_SIZE 64U +#define INTERFACE0ALTERNATE1_INTERRUPT_EP1_OUT_SIZE 64U +#define INTERFACE0ALTERNATE1_BULK_EP2_IN_SIZE 64U +#define INTERFACE0ALTERNATE1_BULK_EP2_OUT_SIZE 64U +#define INTERFACE0ALTERNATE2_ISOCHRONOUS_EP3_IN_SIZE 512U +#define INTERFACE0ALTERNATE2_ISOCHRONOUS_EP3_OUT_SIZE 512U +#define INTERFACE0ALTERNATE3_ISOCHRONOUS_EP4_OUT_SIZE 1023U +#define INTERFACE0ALTERNATE4_ISOCHRONOUS_EP4_IN_SIZE 1023U +///@} + +/** + * @ingroup usb_device_stack + * @def USB_INTERFACE_NUM + * @brief The number of interfaces used by a configuration, excluding alternate interfaces. + */ +#define USB_INTERFACE_NUM 1U + +/** + * @ingroup usb_device_stack + * @struct USB_EP_STATIC_CONFIG_BITS_struct + * @brief Static endpoint settings. + */ +typedef struct USB_EP_STATIC_CONFIG_BITS_struct +{ + uint8_t InMultipktEnable : 1; + uint8_t InAzlpEnable : 1; + uint8_t InTrncInterruptEnable : 1; + uint8_t OutMultipktEnable : 1; + uint8_t OutAzlpEnable : 1; + uint8_t OutTrncInterruptEnable : 1; + uint8_t reserved : 2; +} USB_EP_STATIC_CONFIG_BITS_t; + +/** + * @ingroup usb_device_stack + * @struct endpointStaticConfig + * @brief Configuration of static endpoint settings. + */ +static const USB_EP_STATIC_CONFIG_BITS_t endpointStaticConfig [USB_EP_NUM] = { + [0] = {.InTrncInterruptEnable = 1, .OutTrncInterruptEnable = 1, .InMultipktEnable = 1, .InAzlpEnable = 0, .OutMultipktEnable = 1, .OutAzlpEnable = 0}, + [1] = {.InTrncInterruptEnable = 1, .OutTrncInterruptEnable = 1, .InMultipktEnable = 0, .InAzlpEnable = 0, .OutMultipktEnable = 0, .OutAzlpEnable = 0}, + [2] = {.InTrncInterruptEnable = 1, .OutTrncInterruptEnable = 1, .InMultipktEnable = 0, .InAzlpEnable = 0, .OutMultipktEnable = 0, .OutAzlpEnable = 0}, + [3] = {.InTrncInterruptEnable = 1, .OutTrncInterruptEnable = 1, .InMultipktEnable = 0, .InAzlpEnable = 0, .OutMultipktEnable = 0, .OutAzlpEnable = 0}, + [4] = {.InTrncInterruptEnable = 1, .OutTrncInterruptEnable = 1, .InMultipktEnable = 0, .InAzlpEnable = 0, .OutMultipktEnable = 0, .OutAzlpEnable = 0}, +}; + +#endif // USB_CONFIG_H +/** + End of File +*/ diff --git a/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_descriptors.c b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_descriptors.c new file mode 100644 index 0000000..598331d --- /dev/null +++ b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_descriptors.c @@ -0,0 +1,364 @@ +/** + * USB_DEVICE_STACK Generated Driver File + * + * @file usb_descriptors.c + * + * @ingroup usb_device_stack + * + * @brief Driver implementation file for example application descriptors. + * + * @version USB_DEVICE_STACK Driver Version 1.0.0 +*/ +/* +© [2024] Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip + software and any derivatives exclusively with Microchip products. + You are responsible for complying with 3rd party license terms + applicable to your use of 3rd party software (including open source + software) that may accompany Microchip software. SOFTWARE IS ?AS IS.? + NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS + SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, + MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT + WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY + KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF + MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE + FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S + TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT + EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR + THIS SOFTWARE. +*/ + +#include +#include "usb_descriptors.h" +#include + + +static USB_DEVICE_DESCRIPTOR_t deviceDescriptor = { + .header = { + .bLength = sizeof(USB_DEVICE_DESCRIPTOR_t), + .bDescriptorType = USB_DESCRIPTOR_TYPE_DEVICE, + }, + .bcdUSB = 0x200, // USB 2.0 + .bDeviceClass = USB_VENDOR_DEVICE_CLASS, // Not defined on device level + .bDeviceSubClass = 0x00, // Not defined in Device Descriptor level + .bDeviceProtocol = 0x00, // Not defined in Device Descriptor level + .bMaxPacketSize0 = USB_EP0_SIZE, // EP0 size + .idVendor = 0x04D8, // MCHP VID + .idProduct = 0x0B0A, // PID 0x0010-0x002F reserved for testing/non-public demos + .bcdDevice = 0x0110, // 01.1.0, + .iManufacturer = 0x01, // String index 1 + .iProduct = 0x02, // String index 2 + .iSerialNumber = 0x03, // String index 3 + .bNumConfigurations = 0x01 // Number of configurations +}; + +static USB_APPLICATION_CONFIGURATION_t configurationDescriptor = { + .Config1 = + { + .Configuration = + { + .header = + { + .bLength = sizeof (USB_CONFIGURATION_DESCRIPTOR_t), + .bDescriptorType = (uint8_t)USB_DESCRIPTOR_TYPE_CONFIGURATION, + }, + .wTotalLength = sizeof (USB_APPLICATION_CONFIGURATION1_t), + .bNumInterfaces = USB_INTERFACE_NUM, + .bConfigurationValue = 1u, + .iConfiguration = 0u, + .bmAttributes = USB_CONFIG_ATTR_MUST_SET | USB_CONFIG_ATTR_BUS_POWERED, + .bMaxPower = USB_CONFIG_MAX_POWER(2), + }, + .Interface0Alternate0 = + { + .header = + { + .bLength = sizeof (USB_INTERFACE_DESCRIPTOR_t), + .bDescriptorType = USB_DESCRIPTOR_TYPE_INTERFACE, + }, + .bInterfaceNumber = 0U, + .bAlternateSetting = 0U, + .bNumEndpoints = 0U, + .bInterfaceClass = 0xFF, // Vendor + .bInterfaceSubClass = 0xFF, + .bInterfaceProtocol = 0xFF, + .iInterface = 0U, + }, + .Interface0Alternate1 = + { + .header = + { + .bLength = sizeof (USB_INTERFACE_DESCRIPTOR_t), + .bDescriptorType = USB_DESCRIPTOR_TYPE_INTERFACE, + }, + .bInterfaceNumber = 0U, + .bAlternateSetting = 1U, + .bNumEndpoints = 4U, + .bInterfaceClass = 0xFF, // Vendor + .bInterfaceSubClass = 0xFF, + .bInterfaceProtocol = 0xFF, + .iInterface = 0U, + }, + .Interface0Alternate1_Endpoint1IN = + { + .header = + { + .bLength = sizeof (USB_ENDPOINT_DESCRIPTOR_t), + .bDescriptorType = USB_DESCRIPTOR_TYPE_ENDPOINT, + }, + .bEndpointAddress = + { + .direction = USB_EP_DIR_IN, + .address = INTERFACE0ALTERNATE1_INTERRUPT_EP1_IN, + }, + .bmAttributes = + { + .type = INTERRUPT, + .synchronisation = 0U, // None + .usage = 0U, // None + }, + .wMaxPacketSize = INTERFACE0ALTERNATE1_INTERRUPT_EP1_IN_SIZE, + .bInterval = 1U, + }, + .Interface0Alternate1_Endpoint1OUT = + { + .header = + { + .bLength = sizeof (USB_ENDPOINT_DESCRIPTOR_t), + .bDescriptorType = USB_DESCRIPTOR_TYPE_ENDPOINT, + }, + .bEndpointAddress = + { + .direction = USB_EP_DIR_OUT, + .address = INTERFACE0ALTERNATE1_INTERRUPT_EP1_OUT, + }, + .bmAttributes = + { + .type = INTERRUPT, + .synchronisation = 0U, // None + .usage = 0U, // None + }, + .wMaxPacketSize = INTERFACE0ALTERNATE1_INTERRUPT_EP1_OUT_SIZE, + .bInterval = 1U, + }, + .Interface0Alternate1_Endpoint2IN = + { + .header = + { + .bLength = sizeof (USB_ENDPOINT_DESCRIPTOR_t), + .bDescriptorType = USB_DESCRIPTOR_TYPE_ENDPOINT, + }, + .bEndpointAddress = + { + .direction = USB_EP_DIR_IN, + .address = INTERFACE0ALTERNATE1_BULK_EP2_IN, + }, + .bmAttributes = + { + .type = BULK, + .synchronisation = 0U, // None + .usage = 0U, // None + }, + .wMaxPacketSize = INTERFACE0ALTERNATE1_BULK_EP2_IN_SIZE, + .bInterval = 0U, + }, + .Interface0Alternate1_Endpoint2OUT = + { + .header = + { + .bLength = sizeof (USB_ENDPOINT_DESCRIPTOR_t), + .bDescriptorType = USB_DESCRIPTOR_TYPE_ENDPOINT, + }, + .bEndpointAddress = + { + .direction = USB_EP_DIR_OUT, + .address = INTERFACE0ALTERNATE1_BULK_EP2_OUT, + }, + .bmAttributes = + { + .type = BULK, + .synchronisation = 0U, // None + .usage = 0U, // None + }, + .wMaxPacketSize = INTERFACE0ALTERNATE1_BULK_EP2_OUT_SIZE, + .bInterval = 0U, + }, + .Interface0Alternate2 = + { + .header = + { + .bLength = sizeof (USB_INTERFACE_DESCRIPTOR_t), + .bDescriptorType = USB_DESCRIPTOR_TYPE_INTERFACE, + }, + .bInterfaceNumber = 0U, + .bAlternateSetting = 2U, + .bNumEndpoints = 2U, + .bInterfaceClass = 0xFF, // Vendor + .bInterfaceSubClass = 0xFF, + .bInterfaceProtocol = 0xFF, + .iInterface = 0U, + }, + .Interface0Alternate2_Endpoint3IN = + { + .header = + { + .bLength = sizeof (USB_ENDPOINT_DESCRIPTOR_t), + .bDescriptorType = USB_DESCRIPTOR_TYPE_ENDPOINT, + }, + .bEndpointAddress = + { + .direction = USB_EP_DIR_IN, + .address = INTERFACE0ALTERNATE2_ISOCHRONOUS_EP3_IN, + }, + .bmAttributes = + { + .type = ISOCHRONOUS, + .synchronisation = 1U, // Asynchronous + .usage = 0U, // Data + }, + .wMaxPacketSize = INTERFACE0ALTERNATE2_ISOCHRONOUS_EP3_IN_SIZE, + .bInterval = 1U, + }, + .Interface0Alternate2_Endpoint3OUT = + { + .header = + { + .bLength = sizeof (USB_ENDPOINT_DESCRIPTOR_t), + .bDescriptorType = USB_DESCRIPTOR_TYPE_ENDPOINT, + }, + .bEndpointAddress = + { + .direction = USB_EP_DIR_OUT, + .address = INTERFACE0ALTERNATE2_ISOCHRONOUS_EP3_OUT, + }, + .bmAttributes = + { + .type = ISOCHRONOUS, + .synchronisation = 1U, // Asynchronous + .usage = 0U, // Data + }, + .wMaxPacketSize = INTERFACE0ALTERNATE2_ISOCHRONOUS_EP3_OUT_SIZE, + .bInterval = 1U, + }, + .Interface0Alternate3 = + { + .header = + { + .bLength = sizeof (USB_INTERFACE_DESCRIPTOR_t), + .bDescriptorType = USB_DESCRIPTOR_TYPE_INTERFACE, + }, + .bInterfaceNumber = 0U, + .bAlternateSetting = 3U, + .bNumEndpoints = 1U, + .bInterfaceClass = 0xFF, // Vendor + .bInterfaceSubClass = 0xFF, + .bInterfaceProtocol = 0xFF, + .iInterface = 0U, + }, + .Interface0Alternate3_Endpoint4OUT = + { + .header = + { + .bLength = sizeof (USB_ENDPOINT_DESCRIPTOR_t), + .bDescriptorType = USB_DESCRIPTOR_TYPE_ENDPOINT, + }, + .bEndpointAddress = + { + .direction = USB_EP_DIR_OUT, + .address = INTERFACE0ALTERNATE3_ISOCHRONOUS_EP4_OUT, + }, + .bmAttributes = + { + .type = ISOCHRONOUS, + .synchronisation = 1U, // Asynchronous + .usage = 0U, // Data + }, + .wMaxPacketSize = INTERFACE0ALTERNATE3_ISOCHRONOUS_EP4_OUT_SIZE, + .bInterval = 1U, + }, + .Interface0Alternate4 = + { + .header = + { + .bLength = sizeof (USB_INTERFACE_DESCRIPTOR_t), + .bDescriptorType = USB_DESCRIPTOR_TYPE_INTERFACE, + }, + .bInterfaceNumber = 0U, + .bAlternateSetting = 4U, + .bNumEndpoints = 1U, + .bInterfaceClass = 0xFF, // Vendor + .bInterfaceSubClass = 0xFF, + .bInterfaceProtocol = 0xFF, + .iInterface = 0U, + }, + .Interface0Alternate4_Endpoint4IN = + { + .header = + { + .bLength = sizeof (USB_ENDPOINT_DESCRIPTOR_t), + .bDescriptorType = USB_DESCRIPTOR_TYPE_ENDPOINT, + }, + .bEndpointAddress = + { + .direction = USB_EP_DIR_IN, + .address = INTERFACE0ALTERNATE4_ISOCHRONOUS_EP4_IN, + }, + .bmAttributes = + { + .type = ISOCHRONOUS, + .synchronisation = 1U, // Asynchronous + .usage = 0U, // Data + }, + .wMaxPacketSize = INTERFACE0ALTERNATE4_ISOCHRONOUS_EP4_IN_SIZE, + .bInterval = 1U, + }, + }, +}; + +static USB_STRING_LANG_ID_DESCRIPTOR_t langIDDescriptor = { + .header = + { + .bLength = sizeof (USB_STRING_LANG_ID_DESCRIPTOR_t), + .bDescriptorType = USB_DESCRIPTOR_TYPE_STRING, + }, + .id_array = + {LANG_EN_US}, +}; + +static USB_APPLICATION_STRING_DESCRIPTORS_t stringDescriptors = { + .manufacturer_header = + { + .bLength = sizeof (stringDescriptors.manufacturer) + sizeof (USB_DESCRIPTOR_HEADER_t), + .bDescriptorType = USB_DESCRIPTOR_TYPE_STRING, + }, + .manufacturer = STRING_MANUFACTURER, + .product_header = + { + .bLength = sizeof (stringDescriptors.product) + sizeof (USB_DESCRIPTOR_HEADER_t), + .bDescriptorType = USB_DESCRIPTOR_TYPE_STRING, + }, + .product = STRING_PRODUCT, + .serial_header = + { + .bLength = sizeof (stringDescriptors.serial) + sizeof (USB_DESCRIPTOR_HEADER_t), + .bDescriptorType = USB_DESCRIPTOR_TYPE_STRING, + }, + .serial = STRING_SERIAL, +}; + +USB_DESCRIPTOR_POINTERS_t descriptorPointers = { + .devicePtr = (USB_DEVICE_DESCRIPTOR_t *) & deviceDescriptor, + .configurationsPtr = (USB_CONFIGURATION_DESCRIPTOR_t *) & configurationDescriptor, + .deviceBOSptr = NULL, + .langIDptr = &langIDDescriptor, + .stringPtrs = + { + &stringDescriptors.manufacturer_header, + }, +}; + +/** + End of File +*/ diff --git a/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_descriptors.h b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_descriptors.h new file mode 100644 index 0000000..31aa4cc --- /dev/null +++ b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_descriptors.h @@ -0,0 +1,128 @@ +/** + * USB_DEVICE_STACK Generated API Header File + * + * @file usb_descriptors.h + * + * @ingroup usb_device_stack + * + * @brief Header file for example application descriptors. + * + * @version USB_DEVICE_STACK Driver Version 1.0.0 +*/ +/* +© [2024] Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip + software and any derivatives exclusively with Microchip products. + You are responsible for complying with 3rd party license terms + applicable to your use of 3rd party software (including open source + software) that may accompany Microchip software. SOFTWARE IS ?AS IS.? + NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS + SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, + MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT + WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY + KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF + MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE + FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S + TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT + EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR + THIS SOFTWARE. +*/ + +#ifndef USB_DESCRIPTORS_H +#define USB_DESCRIPTORS_H + +#include +#include +#include "usb_config.h" + + +/** + * @ingroup usb_device_stack + * @def LANG_EN_US + * @brief Language ID String Descriptor, for English (US). + */ +#define LANG_EN_US 0x0409U + +/** + * @ingroup usb_device_stack + * @def STRING_MANUFACTURER + * @brief Manufacturer String descriptor. + */ +#define STRING_MANUFACTURER L"Microchip Technology Inc." + +/** + * @ingroup usb_device_stack + * @def STRING_PRODUCT + * @brief Product String descriptor. + */ +#define STRING_PRODUCT L"Vendor Class Demo" + +/** + * @ingroup usb_device_stack + * @def STRING_SERIAL + * @brief Serial Number String descriptor. + */ +#define STRING_SERIAL L"1" + +/** + * @ingroup usb_device_stack + * @struct USB_APPLICATION_CONFIGURATION1_struct + * @brief USB Configuration, Interface and Endpoint descriptors for Config1. + */ +typedef struct USB_APPLICATION_CONFIGURATION1_struct +{ + USB_CONFIGURATION_DESCRIPTOR_t Configuration; + USB_INTERFACE_DESCRIPTOR_t Interface0Alternate0; + USB_INTERFACE_DESCRIPTOR_t Interface0Alternate1; + USB_ENDPOINT_DESCRIPTOR_t Interface0Alternate1_Endpoint1IN; + USB_ENDPOINT_DESCRIPTOR_t Interface0Alternate1_Endpoint1OUT; + USB_ENDPOINT_DESCRIPTOR_t Interface0Alternate1_Endpoint2IN; + USB_ENDPOINT_DESCRIPTOR_t Interface0Alternate1_Endpoint2OUT; + USB_INTERFACE_DESCRIPTOR_t Interface0Alternate2; + USB_ENDPOINT_DESCRIPTOR_t Interface0Alternate2_Endpoint3IN; + USB_ENDPOINT_DESCRIPTOR_t Interface0Alternate2_Endpoint3OUT; + USB_INTERFACE_DESCRIPTOR_t Interface0Alternate3; + USB_ENDPOINT_DESCRIPTOR_t Interface0Alternate3_Endpoint4OUT; + USB_INTERFACE_DESCRIPTOR_t Interface0Alternate4; + USB_ENDPOINT_DESCRIPTOR_t Interface0Alternate4_Endpoint4IN; +} USB_APPLICATION_CONFIGURATION1_t; + +/** + * @ingroup usb_device_stack + * @struct USB_APPLICATION_CONFIGURATION_struct + * @brief USB Configuration, Interface and Endpoint descriptors. + */ +typedef struct USB_APPLICATION_CONFIGURATION_struct +{ + USB_APPLICATION_CONFIGURATION1_t Config1; +} USB_APPLICATION_CONFIGURATION_t; + +/** + * @ingroup usb_device_stack + * @struct USB_APPLICATION_STRING_DESCRIPTORS_struct + * @brief USB String descriptors. + */ +typedef struct USB_APPLICATION_STRING_DESCRIPTORS_struct +{ + USB_DESCRIPTOR_HEADER_t manufacturer_header; + wchar_t manufacturer[DESCRIPTOR_STRING_LENGTH(STRING_MANUFACTURER)]; + USB_DESCRIPTOR_HEADER_t product_header; + wchar_t product[DESCRIPTOR_STRING_LENGTH(STRING_PRODUCT)]; + USB_DESCRIPTOR_HEADER_t serial_header; + wchar_t serial[DESCRIPTOR_STRING_LENGTH(STRING_SERIAL)]; +} USB_APPLICATION_STRING_DESCRIPTORS_t; + +/** + * @ingroup usb_device_stack + * @struct descriptorPointers + * @brief Pointers to the standard USB descriptors. + */ +extern USB_DESCRIPTOR_POINTERS_t descriptorPointers; + + +#endif // USB_DESCRIPTORS_H +/** + End of File +*/ diff --git a/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_device.c b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_device.c new file mode 100644 index 0000000..978d358 --- /dev/null +++ b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_device.c @@ -0,0 +1,110 @@ +/** + * USB_DEVICE_STACK Generated Driver File + * + * @file usb_device.c + * + * @ingroup usb_device_stack + * + * @brief Driver implementation file for the USB device setup. + * + * @version USB_DEVICE_STACK Driver Version 1.0.0 +*/ +/* +© [2024] Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip + software and any derivatives exclusively with Microchip products. + You are responsible for complying with 3rd party license terms + applicable to your use of 3rd party software (including open source + software) that may accompany Microchip software. SOFTWARE IS ?AS IS.? + NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS + SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, + MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT + WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY + KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF + MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE + FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S + TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT + EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR + THIS SOFTWARE. +*/ + +#include +#include +#include "usb_device.h" +#include "usb0.h" + +static RETURN_CODE_t usbStatus; +static void USBDevice_TransferHandler(void); +static void USBDevice_EventHandler(void); + +static void Vendor_DefaultInterfaceEnCallback(USB_SETUP_REQUEST_t *setupRequestPtr); +static RETURN_CODE_t Vendor_DefaultControlReqCallback(USB_SETUP_REQUEST_t *setupRequestPtr); +static USB_SETUP_EVENT_CALLBACK_t Vendor_InterfaceEn_cb = &Vendor_DefaultInterfaceEnCallback; +static USB_SETUP_PROCESS_CALLBACK_t Vendor_ControlReq_cb = &Vendor_DefaultControlReqCallback; + +void USBDevice_Initialize(void) +{ + USB_DescriptorPointersSet(&descriptorPointers); + + USB_VendorClassInit(Vendor_InterfaceEn_cb, Vendor_ControlReq_cb, NULL); + + USB0_TrnComplCallbackRegister(USBDevice_TransferHandler); + USB0_BusEventCallbackRegister(USBDevice_EventHandler); + + usbStatus = USB_Start(); +} + +RETURN_CODE_t USBDevice_Handle(void) +{ + if (usbStatus == SUCCESS) + { + usbStatus = USB_TransferHandler(); + } + if (usbStatus == SUCCESS) + { + usbStatus = USB_EventHandler(); + } + return usbStatus; +} + +RETURN_CODE_t USBDevice_StatusGet(void) +{ + return usbStatus; +} + +static void USBDevice_TransferHandler(void) +{ + usbStatus = USB_TransferHandler(); +} + +static void USBDevice_EventHandler(void) +{ + usbStatus = USB_EventHandler(); +} + +void Vendor_InterfaceEnCallbackRegister(USB_SETUP_EVENT_CALLBACK_t cb) +{ + Vendor_InterfaceEn_cb = cb; +} + +void Vendor_ControlReqCallbackRegister(USB_SETUP_PROCESS_CALLBACK_t cb) +{ + Vendor_ControlReq_cb = cb; +} + +static void Vendor_DefaultInterfaceEnCallback(USB_SETUP_REQUEST_t *setupRequestPtr) +{ + // Add routine here +} + +static RETURN_CODE_t Vendor_DefaultControlReqCallback(USB_SETUP_REQUEST_t *setupRequestPtr) +{ + // Add routine here + return usbStatus; +} + +/** + End of File +*/ diff --git a/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_device.h b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_device.h new file mode 100644 index 0000000..836b268 --- /dev/null +++ b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_device.h @@ -0,0 +1,82 @@ +/** + * USB_DEVICE_STACK Generated API Header File + * + * @file usb_device.h + * + * @ingroup usb_device_stack + * + * @brief Header file for the USB device setup. + * + * @version USB_DEVICE_STACK Driver Version 1.0.0 +*/ +/* +© [2024] Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip + software and any derivatives exclusively with Microchip products. + You are responsible for complying with 3rd party license terms + applicable to your use of 3rd party software (including open source + software) that may accompany Microchip software. SOFTWARE IS ?AS IS.? + NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS + SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, + MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT + WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY + KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF + MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE + FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S + TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT + EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR + THIS SOFTWARE. +*/ + +#ifndef USB_DEVICE_H +#define USB_DEVICE_H + +#include +#include "usb_descriptors.h" + +/** + * @ingroup usb_device_stack + * @brief Initializes the USB device. + * @param None. + * @return None. + */ +void USBDevice_Initialize(void); + +/** + * @ingroup usb_device_stack + * @brief Handles the USB stack events and in progress transfers for the USB stack to function. + * @param None. + * @return SUCCESS or an Error code according to RETURN_CODE_t + */ +RETURN_CODE_t USBDevice_Handle(void); + +/** + * @ingroup usb_device_stack + * @brief Returns the status of the USB device. + * @param None. + * @return USB status code + */ +RETURN_CODE_t USBDevice_StatusGet(void); + +/** + * @ingroup usb_device_stack + * @brief Registers the callback for the interface enable setup request handler. + * @param USB_SETUP_EVENT_CALLBACK_t cb - Callback function for the interface enable setup request + * @return None. + */ +void Vendor_InterfaceEnCallbackRegister(USB_SETUP_EVENT_CALLBACK_t cb); + +/** + * @ingroup usb_device_stack + * @brief Registers the callback for the control request handler. + * @param USB_SETUP_PROCESS_CALLBACK_t cb - Callback function for the control request + * @return None. + */ +void Vendor_ControlReqCallbackRegister(USB_SETUP_PROCESS_CALLBACK_t cb); + +#endif // USB_DEVICE_H +/** + End of File +*/ diff --git a/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_peripheral/usb_peripheral.c b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_peripheral/usb_peripheral.c new file mode 100644 index 0000000..1acaeb8 --- /dev/null +++ b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_peripheral/usb_peripheral.c @@ -0,0 +1,646 @@ +/** + * USBPERIPHERAL Peripheral Source File + * @file usb_peripheral.c + * @ingroup usb_peripheral + * @brief Interface for a usb_peripheral module that needs to be implemented by a device specific USB module driver. + * @version USB Device Stack HAL Driver Version 1.0.0 + */ + +/* +(c) 2021 Microchip Technology Inc. and its subsidiaries. + +Subject to your compliance with these terms, you may use Microchip software and any +derivatives exclusively with Microchip products. It is your responsibility to comply with third party +license terms applicable to your use of third party software (including open source software) that +may accompany Microchip software. + +THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER +EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY +IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS +FOR A PARTICULAR PURPOSE. + +IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, +INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND +WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP +HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO +THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL +CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT +OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS +SOFTWARE. +*/ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +STATIC USB_CONTROL_TRANSFER_t controlTransfer __attribute__((aligned(2))) = { .transferDataPtr = controlTransfer.buffer }; + +bool USB_SetupIsReceived(void) +{ + return USB_SetupInterruptIs(); +} + +bool USB_EventSOFIsReceived(void) +{ + return USB_SOFInterruptIs(); +} + +void USB_EventSOFClear(void) +{ + USB_SOFInterruptClear(); +} + +bool USB_EventResetIsReceived(void) +{ + return USB_ResetInterruptIs(); +} + +void USB_EventResetClear(void) +{ + USB_ResetInterruptClear(); +} + +uint8_t USB_EventOverUnderflowIsReceived(void) +{ + uint8_t eventOverUnderflow = 0; + if (USB_OverflowInterruptIs() == true) + { + eventOverUnderflow |= (uint8_t)OVERFLOW_EVENT; + } + if (USB_UnderflowInterruptIs() == true) + { + eventOverUnderflow |= (uint8_t)UNDERFLOW_EVENT; + } + return eventOverUnderflow; +} + +uint8_t USB_ControlOverUnderflowIsReceived(void) +{ + uint8_t eventOverUnderflow = 0; + if (USB_EndpointOutOverUnderflowIsSet(0) == true) + { + eventOverUnderflow |= (uint8_t)OVERFLOW_EVENT; + USB_EndpointOutOverUnderflowAck(0); + } + if (USB_EndpointInOverUnderflowIsSet(0) == true) + { + eventOverUnderflow |= (uint8_t)UNDERFLOW_EVENT; + USB_EndpointInOverUnderflowAck(0); + } + return eventOverUnderflow; +} + +void USB_EventOverUnderflowClear(void) +{ + USB_OverflowInterruptClear(); + USB_UnderflowInterruptClear(); +} + +bool USB_EventSuspendIsReceived(void) +{ + return USB_SuspendInterruptIs(); +} + +void USB_EventSuspendClear(void) +{ + USB_SuspendInterruptClear(); +} + +bool USB_EventResumeIsReceived(void) +{ + return USB_ResumeInterruptIs(); +} + +void USB_EventResumeClear(void) +{ + USB_ResumeInterruptClear(); +} + +bool USB_EventStalledIsReceived(void) +{ + return USB_StalledInterruptIs(); +} + +void USB_EventStalledClear(void) +{ + USB_StalledInterruptClear(); +} + +void USB_BusAttach(void) +{ + USB_ConnectionAttach(); +} + +void USB_BusDetach(void) +{ + USB_ConnectionDetach(); +} + +bool USB_IsBusAttached(void) +{ + return USB_ConnectionIsAttach(); +} + +void USB_DeviceAddressConfigure(uint8_t deviceAddress) +{ + USB_DeviceAddressSet(deviceAddress); +} + +uint16_t USB_FrameNumberGet(void) +{ + return (USB_FrameNumGet()); +} + +RETURN_CODE_t USB_ControlEndpointsInit(void) +{ + RETURN_CODE_t status = UNINITIALIZED; + + USB_PIPE_t controlPipeOut = { .address = 0, .direction = USB_EP_DIR_OUT }; + USB_PIPE_t controlPipeIn = { .address = 0, .direction = USB_EP_DIR_IN }; + + status = USB_EndpointConfigure(controlPipeOut, USB_EP0_SIZE, CONTROL); + if (SUCCESS == status) + { + status = USB_EndpointConfigure(controlPipeIn, USB_EP0_SIZE, CONTROL); + } + + if (SUCCESS == status) + { + status = EndpointBufferSet(controlPipeOut, controlTransfer.buffer); + if (SUCCESS == status) + { + status = EndpointBufferSet(controlPipeIn, controlTransfer.buffer); + } + } + + if (SUCCESS == status) + { + status = USB_DataToggleClear(controlPipeOut); + if (SUCCESS == status) + { + status = USB_DataToggleSet(controlPipeIn); + } + } + + if (SUCCESS == status) + { + controlTransfer.status = USB_CONTROL_SETUP; + } + + return status; +} + +RETURN_CODE_t USB_ControlSetupReceived(void) +{ + RETURN_CODE_t status = UNINITIALIZED; + + USB_SetupInterruptClear(); + + if (USB_CONTROL_STALL_REQ == controlTransfer.status) + { + // Stall events are handled by the EventHandler. + status = SUCCESS; + } + else + { + // Acks Setup Received on the control endpoints. + USB_EndpointOutSetupReceivedAck(0u); + USB_EndpointInSetupCompleteAck(0u); + + // Clears bytes received and sent + USB_NumberBytesToSendReset(0u); + USB_NumberBytesSentReset(0u); + USB_NumberBytesToReceiveReset(0u); + USB_NumberBytesReceivedReset(0u); + + // Copies setup packet out of buffer to make it available for a data stage. + (void)memcpy((uint8_t *)(&controlTransfer.setupRequest), controlTransfer.buffer, sizeof(USB_SETUP_REQUEST_t)); + + // The processSetupCallback is in most cases the USB_SetupProcess function in usb_core.c. + if (controlTransfer.processSetupCallback != NULL) + { + RETURN_CODE_t setup_status = controlTransfer.processSetupCallback(&controlTransfer.setupRequest); + + if (UNSUPPORTED == setup_status) + { + // Setup Request unknown or rejected, stalls the next control transaction. + controlTransfer.status = USB_CONTROL_STALL_REQ; + USB_EndpointInStall(0u); + USB_EndpointOutStall(0u); + + status = SUCCESS; + } + else if (SUCCESS == setup_status) + { + if (0u == controlTransfer.transferDataSize) + { + // Request did not contain a data stage, sends ZLP directly. + status = USB_ControlTransferZLP(USB_EP_DIR_IN); + } + else + { + // Sends or Receives data in next stage of request. + controlTransfer.totalBytesTransferred = 0; + USB_PIPE_t controlPipe = { .address = 0u, .direction = USB_EP_DIR_IN }; + if ((controlTransfer.setupRequest.bmRequestType.dataPhaseTransferDirection) == USB_REQUEST_DIR_IN) + { + controlTransfer.status = USB_CONTROL_DATA_IN; + } + else + { + // Control OUT data transactions are controlled by the IN.DATAPTR so set specifically here. + status = EndpointBufferSet(controlPipe, controlTransfer.transferDataPtr); + + controlPipe.direction = USB_EP_DIR_OUT; + controlTransfer.status = USB_CONTROL_DATA_OUT; + } + + // Sets up the pipe variables. + USB_PipeDataTransferredSizeReset(controlPipe); + USB_PipeDataPtrSet(controlPipe, controlTransfer.transferDataPtr); + USB_PipeDataToTransferSizeSet(controlPipe, controlTransfer.transferDataSize); + + // Start data stage transaction. + status = USB_ControlTransactionComplete(controlPipe); + } + } + else + { + // Forward error from setup. + status = setup_status; + } + } + else + { + // processSetupCallback missing, return error. + status = CONTROL_SETUP_CALLBACK_ERROR; + } + } + + return status; +} + +RETURN_CODE_t USB_ControlTransactionComplete(USB_PIPE_t pipe) +{ + RETURN_CODE_t status = UNINITIALIZED; + + if (pipe.address != 0) + { + status = ENDPOINT_ADDRESS_ERROR; + } + else + { + // The data stage and the status stage must always have the data toggle bit set. + status = USB_DataToggleSet(pipe); + } + + if (SUCCESS == status) + { + switch (controlTransfer.status) + { + case USB_CONTROL_DATA_IN: + { + pipe.direction = USB_EP_DIR_IN; + + // Updates bytes sent and to be sent. + uint16_t bytesSent = USB_PipeDataTransferredSizeGet(pipe); + bytesSent += USB_NumberBytesSentGet(pipe.address); + USB_PipeDataTransferredSizeSet(pipe, bytesSent); + uint16_t transferDataSize = USB_PipeDataToTransferSizeGet(pipe); + + // Checks remaining data to send. + if (0U == (transferDataSize - bytesSent)) + { + controlTransfer.totalBytesTransferred += bytesSent; + if (controlTransfer.transferDataSize == controlTransfer.totalBytesTransferred) + { + + // Data stage is complete, sends an OUT ZLP for status stage. + status = USB_ControlTransferZLP(USB_REQUEST_DIR_OUT); + } + else + { + // Data stage is not complete, checks if we need a new buffer. + if ((controlTransfer.overUnderRunCallback != NULL) && (SUCCESS == controlTransfer.overUnderRunCallback())) + { + USB_PipeDataTransferredSizeReset(pipe); + USB_PipeDataToTransferSizeSet(pipe, controlTransfer.transferDataSize); + } + + // If no new buffer a normal in ZLP will get sent for the data stage. + status = USB_InTransactionRun(pipe); + } + } + else + { + // Starts next transaction in data stage. + status = USB_InTransactionRun(pipe); + } + + USB_EndpointInOverUnderflowAck(0); + + break; + } + case USB_CONTROL_DATA_OUT: + { + pipe.direction = USB_EP_DIR_OUT; + + // Updates bytes received and to be received. + uint16_t bytesReceived = USB_PipeDataTransferredSizeGet(pipe); + bytesReceived += USB_NumberBytesReceivedGet(pipe.address); + USB_PipeDataTransferredSizeSet(pipe, bytesReceived); + uint16_t transferDataSize = USB_PipeDataToTransferSizeGet(pipe); + + if (0U == (transferDataSize - bytesReceived)) + { + controlTransfer.totalBytesTransferred += bytesReceived; + if (controlTransfer.transferDataSize == controlTransfer.totalBytesTransferred) + { + + // Data stage is complete, sends an IN ZLP for status stage. + status = USB_ControlTransferZLP(USB_REQUEST_DIR_IN); + } + else + { + // Data stage is not complete, checks if we need a new buffer. + if ((controlTransfer.overUnderRunCallback != NULL) && (SUCCESS == controlTransfer.overUnderRunCallback())) + { + USB_PipeDataTransferredSizeReset(pipe); + USB_PipeDataToTransferSizeSet(pipe, controlTransfer.transferDataSize); + status = USB_InTransactionRun(pipe); + } + else + { + // If no new buffer the next transaction will be stalled. + controlTransfer.status = USB_CONTROL_STALL_REQ; + USB_EndpointInStall(0); + USB_EndpointOutStall(0); + + status = SUCCESS; + } + } + } + else + { + // Starts next transaction in data stage. + status = USB_OutTransactionRun(pipe); + } + + USB_EndpointOutOverUnderflowAck(0); + break; + } + case USB_CONTROL_ZLP: + { + // Valid end of setup request. + if (controlTransfer.endOfRequestCallback != NULL) + { + controlTransfer.endOfRequestCallback(); + } + + // Reinitializes control endpoint management. + status = USB_ControlTransferReset(); + break; + } + case USB_CONTROL_SETUP: + { + status = USB_ControlTransferReset(); + break; + } + default: + { + status = CONTROL_TRANSACTION_STATUS_ERROR; + break; + } + } + } + + return status; +} + +RETURN_CODE_t USB_ControlTransferZLP(uint8_t direction) +{ + RETURN_CODE_t status = UNINITIALIZED; + + USB_NumberBytesToSendReset(0); + USB_NumberBytesSentReset(0); + USB_NumberBytesToReceiveReset(0u); + USB_NumberBytesReceivedReset(0u); + + // Prepare to receive a new setup package in case the host decides to ignore the ZLP stage + USB_PipeDataPtrSet((USB_PIPE_t){ .address = 0, .direction = USB_REQUEST_DIR_OUT }, controlTransfer.buffer); + status = EndpointBufferSet((USB_PIPE_t){ .address = 0, .direction = USB_REQUEST_DIR_OUT }, controlTransfer.buffer); + + if (SUCCESS == status) + { + controlTransfer.status = USB_CONTROL_ZLP; + + // Starts the ZLP transaction + if (direction == USB_REQUEST_DIR_IN) + { + USB_EndpointInNAKClear(0); + USB_EndpointInOverUnderflowAck(0); + } + else + { + USB_EndpointOutNAKClear(0); + USB_EndpointOutOverUnderflowAck(0); + } + } + + return status; +} + +RETURN_CODE_t USB_ControlTransferReset(void) +{ + RETURN_CODE_t status = UNINITIALIZED; + USB_PIPE_t controlPipeOut = { .address = 0u, .direction = USB_EP_DIR_OUT }; + + // Aborts any ongoing transaction and resets the endpoint statuses + status = USB_TransactionAbort(controlPipeOut); + if (SUCCESS == status) + { + USB_PIPE_t controlPipeIn = { .address = 0u, .direction = USB_EP_DIR_IN }; + status = USB_TransactionAbort(controlPipeIn); + } + + if (SUCCESS == status) + { + USB_EndpointOutStatusClear(0u); + USB_EndpointInStatusClear(0u); + + // Prepare for receiving a new request packet + USB_PipeDataPtrSet(controlPipeOut, controlTransfer.buffer); + USB_PipeDataToTransferSizeSet(controlPipeOut, sizeof(USB_SETUP_REQUEST_t)); + USB_PipeDataTransferredSizeReset(controlPipeOut); + USB_PipeTransferEndCallbackRegister(controlPipeOut, NULL); + + // Clears the endpoint count registers + USB_NumberBytesToSendReset(0u); + USB_NumberBytesSentReset(0u); + USB_NumberBytesToReceiveReset(0u); + USB_NumberBytesReceivedReset(0u); + + // Resets the control transfer variables + controlTransfer.endOfRequestCallback = NULL; + controlTransfer.overUnderRunCallback = NULL; + controlTransfer.transferDataSize = 0u; + controlTransfer.status = USB_CONTROL_SETUP; + } + + return status; +} + +RETURN_CODE_t USB_ControlTransferDataSet(uint8_t *dataPtr, uint16_t dataSize) +{ + RETURN_CODE_t status = UNINITIALIZED; + + if (dataPtr == NULL) + { + controlTransfer.transferDataPtr = controlTransfer.buffer; + if (0u != dataSize) + { + status = CONTROL_SIZE_ERROR; + } + else + { + status = SUCCESS; + } + } + else + { + controlTransfer.transferDataPtr = dataPtr; + status = SUCCESS; + } + controlTransfer.transferDataSize = dataSize; + + return status; +} + +RETURN_CODE_t USB_ControlTransferDataWriteBuffer(uint8_t *dataPtr, uint8_t dataSize) +{ + RETURN_CODE_t status = UNINITIALIZED; + + if (USB_EP0_SIZE < dataSize) + { + status = CONTROL_SIZE_ERROR; + } + else + { + (void)memcpy(controlTransfer.buffer, dataPtr, dataSize); + controlTransfer.transferDataPtr = controlTransfer.buffer; + controlTransfer.transferDataSize = dataSize; + + status = SUCCESS; + } + return status; +} + +void USB_ControlEndOfRequestCallbackRegister(USB_SETUP_ENDOFREQUEST_CALLBACK_t callback) +{ + controlTransfer.endOfRequestCallback = callback; +} + +void USB_ControlProcessSetupCallbackRegister(USB_SETUP_PROCESS_CALLBACK_t callback) +{ + controlTransfer.processSetupCallback = callback; +} + +void USB_ControlOverUnderRunCallbackRegister(USB_SETUP_OVERUNDERRUN_CALLBACK_t callback) +{ + controlTransfer.overUnderRunCallback = callback; +} + +RETURN_CODE_t USB_ControlProcessOverUnderflow(uint8_t overunderflow) +{ + RETURN_CODE_t status = UNINITIALIZED; + + if (USB_CONTROL_DATA_IN == controlTransfer.status) + { + if (OVERFLOW_EVENT == overunderflow) + { + // Host is done with the data stage and expects an OUT ZLP + status = USB_ControlTransferZLP(USB_REQUEST_DIR_OUT); + } + else + { + // Host is too eager, let this be handled by the transfer handler + status = SUCCESS; + } + } + else if (USB_CONTROL_DATA_OUT == controlTransfer.status) + { + if (UNDERFLOW_EVENT == overunderflow) + { + // Host is done with the data stage and expects an IN ZLP + status = USB_ControlTransferZLP(USB_REQUEST_DIR_IN); + } + else + { + // Host is too eager, let this be handled by the transfer handler + status = SUCCESS; + } + } + else + { + // Remaining control statuses ignores overflow and underflow events + status = SUCCESS; + } + + return status; +} + +RETURN_CODE_t USB_HandleEventStalled(USB_PIPE_t pipe) +{ + RETURN_CODE_t status = UNINITIALIZED; + + USB_EndpointInStallAck(pipe.address); + USB_EndpointOutStallAck(pipe.address); + + USB_EndpointInStallClear(pipe.address); + USB_EndpointOutStallClear(pipe.address); + + if (0u == pipe.address) + { + // Reinitializes control endpoint management. + status = USB_ControlTransferReset(); + } + else + { + status = USB_TransactionAbort(pipe); + } + + return status; +} + +void USB_PeripheralInitialize(void) +{ + USB_Enable(); + USB_FrameNumEnable(); + USB_FifoEnable(); + USB_FifoReadPointerReset(); + USB_FifoWritePointerReset(); + USB_EndpointTableAddressSet(endpointTable.EP); + USB_MaxEndpointsSet(USB_EP_NUM - 1u); + USB_InterruptFlagsClear(); + // Reset endpoints table + for (uint8_t endpoint = 0; endpoint < (uint8_t)USB_EP_NUM; endpoint++) + { + endpointTable.EP[endpoint].OUT.CTRL = 0; + endpointTable.EP[endpoint].OUT.STATUS = 0; + endpointTable.EP[endpoint].IN.CTRL = 0; + endpointTable.EP[endpoint].IN.STATUS = 0; + } +} + +void USB_PeripheralDisable(void) +{ + USB_Disable(); + USB_DeviceAddressReset(); +} diff --git a/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_peripheral/usb_peripheral.h b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_peripheral/usb_peripheral.h new file mode 100644 index 0000000..b9031ee --- /dev/null +++ b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_peripheral/usb_peripheral.h @@ -0,0 +1,336 @@ +/** + * USBPERIPHERAL Peripheral Header File + * @file usb_peripheral.h + * @defgroup usb_peripheral USB Peripheral Hardware Abstraction Layer (HAL) + * @brief Interface for a USB peripheral module that needs to be implemented by a device-specific USB module driver. + * @version USB Device Stack HAL Driver Version 1.0.0 + */ + +/* + (c) 2021 Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip software and any + derivatives exclusively with Microchip products. It is your responsibility to comply with third party + license terms applicable to your use of third party software (including open source software) that + may accompany Microchip software. + + THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER + EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY + IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS + FOR A PARTICULAR PURPOSE. + + IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND + WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP + HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO + THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL + CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT + OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS + SOFTWARE. + */ + +#ifndef USB_PERIPHERAL_H +// cppcheck-suppress misra-c2012-2.5 +#define USB_PERIPHERAL_H + +#include +#include + +#include +#include +#include +#include + +/** + * @ingroup usb_peripheral + * @struct USB_CONTROL_TRANSFER_t + * @brief The data structure for internally handling control transfers, either IN or OUT. + */ +typedef struct USB_CONTROL_TRANSFER_struct +{ + uint8_t buffer[64]; /** +#else // avr-gcc + #include +#endif + +#include +#include + +/** + * @ingroup usb_peripheral_avr_du + * @def ALWAYS_INLINE + * @brief Alias that makes always inline function definitions more readable. + */ +#define ALWAYS_INLINE __attribute__((always_inline)) inline + +/** + * @ingroup usb_peripheral_avr_du + * @struct USB_ENDPOINT_TABLE_struct + * @brief Represents the endpoint configuration table based on the number of endpoints in use. + * The table data structure is defined by USB_EP_TABLE_struct in the device header file, + * modified to support configuration of size from USB_EP_NUM. + */ +typedef struct USB_ENDPOINT_TABLE_struct +{ + register8_t FIFO[USB_EP_NUM * 2u]; /**> USB_MAXEP_gp); +} + +/** + * @ingroup usb_peripheral_avr_du + * @brief Sets the address of the endpoint table. + * This is a device-specific function. + * @param endpointTableAddress - Address of the endpoint table + * @return None. + */ +static ALWAYS_INLINE void USB_EndpointTableAddressSet(USB_EP_PAIR_t *endpointTableAddress) +{ + USB0.EPPTR = (uint16_t)endpointTableAddress; +} + +/** + * @ingroup usb_peripheral_avr_du + * @brief Sets the address of the endpoint table to 0. + * This is a device-specific function. + * @param None. + * @return None. + */ +static ALWAYS_INLINE void USB_EndpointTableAddressReset(void) +{ + USB0.EPPTR = 0x0000; +} + +/** + * @ingroup usb_peripheral_avr_du + * @brief Gets the address of the endpoint table. + * This is a device-specific function. + * @param None. + * @return The address of the endpoint table + */ +static ALWAYS_INLINE uint16_t USB_EndpointTableAddressGet(void) +{ + return (USB0.EPPTR); +} + +/** + * @ingroup usb_peripheral_avr_du + * @brief Resets the read FIFO pointer. + * This is a device-specific function. + * @param None. + * @return None. + */ +static ALWAYS_INLINE void USB_FifoReadPointerReset(void) +{ + USB0.FIFORP |= (USB_FIFORP_gm); +} + +/** + * @ingroup usb_peripheral_avr_du + * @brief Gets the read FIFO pointer. + * This is a device-specific function. + * @param None. + * @return The FIFO read pointer + */ +static ALWAYS_INLINE int8_t USB_FifoReadPointerGet(void) +{ + return (int8_t)(USB0.FIFORP); +} + +/** + * @ingroup usb_peripheral_avr_du + * @brief Resets the write FIFO pointer. + * This is a device-specific function. + * @param None. + * @return None. + */ +static ALWAYS_INLINE void USB_FifoWritePointerReset(void) +{ + USB0.FIFOWP |= (USB_FIFOWP_gm); +} + +/** + * @ingroup usb_peripheral_avr_du + * @brief Gets the write FIFO pointer. + * This is a device-specific function. + * @param None. + * @return The FIFO write pointer + */ +static ALWAYS_INLINE int8_t USB_FifoWritePointerGet(void) +{ + return (int8_t)(USB0.FIFOWP); +} + +/** + * @ingroup usb_peripheral_avr_du + * @brief Sets the device address. + * @param usbAddress - The device address to set + * @return None. + */ +static ALWAYS_INLINE void USB_DeviceAddressSet(uint8_t usbAddress) +{ + USB0.ADDR = ((USB0.ADDR & ~USB_ADDR_gm) | (((usbAddress) << USB_ADDR_gp) & USB_ADDR_gm)); +} + +/** + * @ingroup usb_peripheral_avr_du + * @brief Resets the device address. + * @param None. + * @return None. + */ +static ALWAYS_INLINE void USB_DeviceAddressReset(void) +{ + USB0.ADDR &= ~(USB_ADDR_gm); +} + +/** + * @ingroup usb_peripheral_avr_du + * @brief Gets the device address. + * @param None. + * @return The device address + */ +static ALWAYS_INLINE uint8_t USB_DeviceAddressGet(void) +{ + return ((USB0.ADDR & USB_ADDR_gm) >> USB_ADDR_gp); +} + +/** + * @ingroup usb_peripheral_avr_du + * @brief Enables an upstream resume to be initated. + * @param None. + * @return None. + */ +static ALWAYS_INLINE void USB_UpstreamResumeEnable(void) +{ + USB0.CTRLB |= USB_URESUME_bm; +} + +/** + * @ingroup usb_peripheral_avr_du + * @brief Checks if upstream resume is enabled, but not yet initiated. + * @param None. + * @retval 0 - Upstream resume initiated or not enabled + * @retval 1 - Upstream resume enabled + */ +static ALWAYS_INLINE bool USB_UpstreamResumeIsEnable(void) +{ + return ((USB0.CTRLB & USB_URESUME_bm) != 0u); +} + +/** + * @ingroup usb_peripheral_avr_du + * @brief Gets the USB bus state. + * @param None. + * @return The state of the USB bus + */ +static ALWAYS_INLINE uint8_t USB_BusStateGet(void) +{ + return (USB0.BUSSTATE); +} + +/** + * @ingroup usb_peripheral_avr_du + * @brief Checks if the USB bus has any specific status flags set. + * @param bus_state_bm - The bitmap of the specific status flags to check + * @retval 0 - No status flags set + * @retval 1 - The bus has one or more specified status flags set + */ +static ALWAYS_INLINE bool USB_BusStateIs(uint8_t bus_state_bm) +{ + return ((USB0.BUSSTATE & (bus_state_bm)) != 0u); +} + +/** + * @ingroup usb_peripheral_avr_du + * @brief Enables the USB Start-Of-Frame interrupt. + * @param None. + * @return None. + */ +static ALWAYS_INLINE void USB_SOFInterruptEnable(void) +{ + USB0.INTCTRLA |= USB_SOF_bm; +} + +/** + * @ingroup usb_peripheral_avr_du + * @brief Disables the USB Start-Of-Frame interrupt. + * @param None. + * @return None. + */ +static ALWAYS_INLINE void USB_SOFInterruptDisable(void) +{ + USB0.INTCTRLA &= ~(USB_SOF_bm); +} + +/** + * @ingroup usb_peripheral_avr_du + * @brief Clears the USB Start-Of-Frame Interrupt flag. + * @param None. + * @return None. + */ +static ALWAYS_INLINE void USB_SOFInterruptClear(void) +{ + USB0.INTFLAGSA = USB_SOF_bm; +} + +/** + * @ingroup usb_peripheral_avr_du + * @brief Checks if the USB Start-Of-Frame interrupt has been triggered. + * @param None. + * @retval 0 - Interrupt not triggered + * @retval 1 - Interrupt triggered + */ +static ALWAYS_INLINE bool USB_SOFInterruptIs(void) +{ + return ((USB0.INTFLAGSA & USB_SOF_bm) != 0u); +} + +/** + * @ingroup usb_peripheral_avr_du + * @brief Enables the USB Suspend interrupt. + * @param None. + * @return None. + */ +static ALWAYS_INLINE void USB_SuspendInterruptEnable(void) +{ + USB0.INTCTRLA |= USB_SUSPEND_bm; +} + +/** + * @ingroup usb_peripheral_avr_du + * @brief Disables the USB Suspend interrupt. + * @param None. + * @return None. + */ +static ALWAYS_INLINE void USB_SuspendInterruptDisable(void) +{ + USB0.INTCTRLA &= ~(USB_SUSPEND_bm); +} + +/** + * @ingroup usb_peripheral_avr_du + * @brief Clears the USB Suspend Interrupt flag. + * @param None. + * @return None. + */ +static ALWAYS_INLINE void USB_SuspendInterruptClear(void) +{ + USB0.INTFLAGSA = USB_SUSPEND_bm; +} + +/** + * @ingroup usb_peripheral_avr_du + * @brief Checks if the USB Suspend interrupt has been triggered. + * @param None. + * @retval 0 - Interrupt not triggered + * @retval 1 - Interrupt triggered + */ +static ALWAYS_INLINE bool USB_SuspendInterruptIs(void) +{ + return ((USB0.INTFLAGSA & USB_SUSPEND_bm) != 0u); +} + +/** + * @ingroup usb_peripheral_avr_du + * @brief Enables the USB Resume interrupt. + * @param None. + * @return None. + */ +static ALWAYS_INLINE void USB_ResumeInterruptEnable(void) +{ + USB0.INTCTRLA |= USB_RESUME_bm; +} + +/** + * @ingroup usb_peripheral_avr_du + * @brief Disables the USB Resume interrupt. + * @param None. + * @return None. + */ +static ALWAYS_INLINE void USB_ResumeInterruptDisable(void) +{ + USB0.INTCTRLA &= ~(USB_RESUME_bm); +} + +/** + * @ingroup usb_peripheral_avr_du + * @brief Clears the USB Resume Interrupt flag. + * @param None. + * @return None. + */ +static ALWAYS_INLINE void USB_ResumeInterruptClear(void) +{ + USB0.INTFLAGSA = USB_RESUME_bm; +} + +/** + * @ingroup usb_peripheral_avr_du + * @brief Checks if the USB Resume interrupt has been triggered. + * @param None. + * @retval 0 - Interrupt not triggered + * @retval 1 - Interrupt triggered + */ +static ALWAYS_INLINE bool USB_ResumeInterruptIs(void) +{ + return ((USB0.INTFLAGSA & USB_RESUME_bm) != 0u); +} + +/** + * @ingroup usb_peripheral_avr_du + * @brief Enables the USB Reset interrupt. + * @param None. + * @return None. + */ +static ALWAYS_INLINE void USB_ResetInterruptEnable(void) +{ + USB0.INTCTRLA |= USB_RESET_bm; +} + +/** + * @ingroup usb_peripheral_avr_du + * @brief Disables the USB Reset interrupt. + * @param None. + * @return None. + */ +static ALWAYS_INLINE void USB_ResetInterruptDisable(void) +{ + USB0.INTCTRLA &= ~(USB_RESET_bm); +} + +/** + * @ingroup usb_peripheral_avr_du + * @brief Clears the USB Reset Interrupt flag. + * @param None. + * @return None. + */ +static ALWAYS_INLINE void USB_ResetInterruptClear(void) +{ + USB0.INTFLAGSA = USB_RESET_bm; +} + +/** + * @ingroup usb_peripheral_avr_du + * @brief Checks if the USB Reset interrupt has been triggered. + * @param None. + * @retval 0 - Interrupt not triggered + * @retval 1 - Interrupt triggered + */ +static ALWAYS_INLINE bool USB_ResetInterruptIs(void) +{ + return ((USB0.INTFLAGSA & USB_RESET_bm) != 0u); +} + +/** + * @ingroup usb_peripheral_avr_du + * @brief Enables the USB Stalled interrupt. + * @param None. + * @return None. + */ +static ALWAYS_INLINE void USB_StalledInterruptEnable(void) +{ + USB0.INTCTRLA |= USB_STALLED_bm; +} + +/** + * @ingroup usb_peripheral_avr_du + * @brief Disables the USB Stalled interrupt. + * @param None. + * @return None. + */ +static ALWAYS_INLINE void USB_StalledInterruptDisable(void) +{ + USB0.INTCTRLA &= ~(USB_STALLED_bm); +} + +/** + * @ingroup usb_peripheral_avr_du + * @brief Clears the USB Stalled Interrupt flag. + * @param None. + * @return None. + */ +static ALWAYS_INLINE void USB_StalledInterruptClear(void) +{ + USB0.INTFLAGSA = USB_STALLED_bm; +} + +/** + * @ingroup usb_peripheral_avr_du + * @brief Checks if the USB Stalled interrupt has been triggered. + * @param None. + * @retval 0 - Interrupt not triggered + * @retval 1 - Interrupt triggered + */ +static ALWAYS_INLINE bool USB_StalledInterruptIs(void) +{ + return ((USB0.INTFLAGSA & USB_STALLED_bm) != 0u); +} + +/** + * @ingroup usb_peripheral_avr_du + * @brief Enables the USB Underflow interrupt. + * @param None. + * @return None. + */ +static ALWAYS_INLINE void USB_UnderflowInterruptEnable(void) +{ + USB0.INTCTRLA |= USB_UNF_bm; +} + +/** + * @ingroup usb_peripheral_avr_du + * @brief Disables the USB Underflow interrupt. + * @param None. + * @return None. + */ +static ALWAYS_INLINE void USB_UnderflowInterruptDisable(void) +{ + USB0.INTCTRLA &= ~(USB_UNF_bm); +} + +/** + * @ingroup usb_peripheral_avr_du + * @brief Clears the USB Underflow Interrupt flag. + * @param None. + * @return None. + */ +static ALWAYS_INLINE void USB_UnderflowInterruptClear(void) +{ + USB0.INTFLAGSA = USB_UNF_bm; +} + +/** + * @ingroup usb_peripheral_avr_du + * @brief Checks if an Underflow interrupt has been triggered. + * @param None. + * @retval 0 - Interrupt not triggered + * @retval 1 - Interrupt triggered + */ +static ALWAYS_INLINE bool USB_UnderflowInterruptIs(void) +{ + return ((USB0.INTFLAGSA & USB_UNF_bm) != 0u); +} + +/** + * @ingroup usb_peripheral_avr_du + * @brief Enables the USB Overflow interrupt. + * @param None. + * @return None. + */ +static ALWAYS_INLINE void USB_OverflowInterruptEnable(void) +{ + USB0.INTCTRLA |= USB_OVF_bm; +} + +/** + * @ingroup usb_peripheral_avr_du + * @brief Disables the USB Overflow interrupt. + * @param None. + * @return None. + */ +static ALWAYS_INLINE void USB_OverflowInterruptDisable(void) +{ + USB0.INTCTRLA &= ~(USB_OVF_bm); +} + +/** + * @ingroup usb_peripheral_avr_du + * @brief Clears the USB Overflow Interrupt flag. + * @param None. + * @return None. + */ +static ALWAYS_INLINE void USB_OverflowInterruptClear(void) +{ + USB0.INTFLAGSA = USB_OVF_bm; +} + +/** + * @ingroup usb_peripheral_avr_du + * @brief Checks if an Overflow interrupt has been triggered. + * @param None. + * @retval 0 - Interrupt not triggered + * @retval 1 - Interrupt triggered + */ +static ALWAYS_INLINE bool USB_OverflowInterruptIs(void) +{ + return ((USB0.INTFLAGSA & USB_OVF_bm) != 0u); +} + +/** + * @ingroup usb_peripheral_avr_du + * @brief Enables the USB Transaction Complete interrupt. + * @param None. + * @return None. + */ +static ALWAYS_INLINE void USB_TransactionCompleteInterruptEnable(void) +{ + USB0.INTCTRLB |= USB_TRNCOMPL_bm; +} + +/** + * @ingroup usb_peripheral_avr_du + * @brief Disables the USB Transaction Complete interrupt. + * @param None. + * @return None. + */ +static ALWAYS_INLINE void USB_TransactionCompleteInterruptDisable(void) +{ + USB0.INTCTRLB &= ~(USB_TRNCOMPL_bm); +} + +/** + * @ingroup usb_peripheral_avr_du + * @brief Clears the USB Transaction Complete Interrupt flag. + * @param None. + * @return None. + */ +static ALWAYS_INLINE void USB_TransactionCompleteInterruptAck(void) +{ + USB0.INTFLAGSB = USB_TRNCOMPL_bm; +} + +/** + * @ingroup usb_peripheral_avr_du + * @brief Checks if a Transaction Complete interrupt has been triggered. + * @param None. + * @retval 0 - Interrupt not triggered + * @retval 1 - Interrupt triggered + */ +static ALWAYS_INLINE bool USB_TransactionCompleteInterruptIs(void) +{ + return ((USB0.INTFLAGSB & USB_TRNCOMPL_bm) != 0u); +} + +/** + * @ingroup usb_peripheral_avr_du + * @brief Checks if the USB Read-Modify-Write Interrupt is enabled. + * @param None. + * @retval 0 - Interrupt not enabled + * @retval 1 - Interrupt enabled + */ +static ALWAYS_INLINE bool USB_ReadModifyWriteInterruptIs(void) +{ + return ((USB0.INTFLAGSB & USB_RMWBUSY_bm) != 0u); +} + +/** + * @ingroup usb_peripheral_avr_du + * @brief Enables the USB Global NAK Done interrupt. + * @param None. + * @return None. + */ +static ALWAYS_INLINE void USB_GlobalNAKDoneInterruptEnable(void) +{ + USB0.INTCTRLB |= USB_GNDONE_bm; +} + +/** + * @ingroup usb_peripheral_avr_du + * @brief Disables the USB Global NAK Done interrupt. + * @param None. + * @return None. + */ +static ALWAYS_INLINE void USB_GlobalNAKDoneInterruptDisable(void) +{ + USB0.INTCTRLB &= ~(USB_GNDONE_bm); +} + +/** + * @ingroup usb_peripheral_avr_du + * @brief Clears the USB Global NAK Done Interrupt flag. + * @param None. + * @return None. + */ +static ALWAYS_INLINE void USB_GlobalNAKDoneInterruptAck(void) +{ + USB0.INTFLAGSB = USB_GNDONE_bm; +} + +/** + * @ingroup usb_peripheral_avr_du + * @brief Checks if the USB Global NAK Done interrupt has been triggered. + * @param None. + * @retval 0 - Interrupt not triggered + * @retval 1 - Interrupt triggered + */ +static ALWAYS_INLINE bool USB_GlobalNAKDoneInterruptIs(void) +{ + return ((USB0.INTFLAGSB & USB_GNDONE_bm) != 0u); +} + +/** + * @ingroup usb_peripheral_avr_du + * @brief Enables the USB Setup interrupt. + * @param None. + * @return None. + */ +static ALWAYS_INLINE void USB_SetupInterruptEnable(void) +{ + USB0.INTCTRLB |= USB_SETUP_bm; +} + +/** + * @ingroup usb_peripheral_avr_du + * @brief Disables the USB Setup interrupt. + * @param None. + * @return None. + */ +static ALWAYS_INLINE void USB_SetupInterruptDisable(void) +{ + USB0.INTCTRLB &= ~(USB_SETUP_bm); +} + +/** + * @ingroup usb_peripheral_avr_du + * @brief Clears the USB Setup Interrupt flag. + * @param None. + * @return None. + */ +static ALWAYS_INLINE void USB_SetupInterruptClear(void) +{ + USB0.INTFLAGSB = USB_SETUP_bm; +} + +/** + * @ingroup usb_peripheral_avr_du + * @brief Checks if a USB Setup interrupt has been triggered. + * @param None. + * @retval 0 - Interrupt not triggered + * @retval 1 - Interrupt triggered + */ +static ALWAYS_INLINE bool USB_SetupInterruptIs(void) +{ + return ((USB0.INTFLAGSB & USB_SETUP_bm) != 0u); +} + +/** + * @ingroup usb_peripheral_avr_du + * @brief Clears all the USB Interrupt flags. + * @param None. + * @return None. + */ +static ALWAYS_INLINE void USB_InterruptFlagsClear(void) +{ + USB0.INTFLAGSA = 0xff; + USB0.INTFLAGSB = 0xff; +} + +#endif /* USB_PERIPHERAL_AVR_DU_H */ diff --git a/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_peripheral/usb_peripheral_endpoint.c b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_peripheral/usb_peripheral_endpoint.c new file mode 100644 index 0000000..7622fbe --- /dev/null +++ b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_peripheral/usb_peripheral_endpoint.c @@ -0,0 +1,510 @@ +/** + * USBPERIPHERALENDPOINT Peripheral Endpoint Source File + * @file usb_peripheral_endpoint.c + * @ingroup usb_peripheral_endpoint + * @brief API module for usb_peripheral covering endpoint related functions. + * @version USB Device Stack HAL Driver Version 1.0.0 + */ + +/* + (c) 2021 Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip software and any + derivatives exclusively with Microchip products. It is your responsibility to comply with third party + license terms applicable to your use of third party software (including open source software) that + may accompany Microchip software. + + THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER + EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY + IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS + FOR A PARTICULAR PURPOSE. + + IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND + WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP + HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO + THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL + CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT + OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS + SOFTWARE. + */ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#if defined(USB_EP_NUM) && defined(USB_MAX_ENDPOINTS) + #if USB_EP_NUM > USB_MAX_ENDPOINTS + #error "USB_EP_NUM is too large, max is USB_MAX_ENDPOINTS" + #endif +#else + #error "USB_EP_NUM not configured" +#endif + +/** + * @ingroup usb_peripheral_endpoint + * @brief Algorithm to detect if a given number is a power of two. + * A number is a power of two if it has exactly one '1' in its binary representation. This is true if subtracting '1' from the number + * and doing an AND operation on the result with the number itself returns 0. + * @param number 8-bit unsigned integer + * @retval True - The given number is a power of two + * @retval False - The given number is not a power of two + */ +#define IsPowerOfTwo(number) ((0u != (number)) && (((number) & ((number)-1u)) == 0u)) + +/** + * @ingroup usb_peripheral_endpoint + * @brief SRAM tables for the FIFO and endpoint registers, as well as the FRAMENUM register. + * Represents the endpoint configuration table based on the number of endpoints in use. + * This line instantiates an object using the data structure type. + */ +USB_ENDPOINT_TABLE_t endpointTable __attribute__((aligned(2))); + +RETURN_CODE_t USB_EndpointConfigure(USB_PIPE_t pipe, uint16_t endpointSize, USB_ENDPOINT_t endpointType) +{ + RETURN_CODE_t status = UNINITIALIZED; + + uint8_t endpointConfiguration = 0; + if (SUCCESS != ConvertEndpointSizeToMask(endpointSize, endpointType, &endpointConfiguration)) + { + status = ENDPOINT_SIZE_ERROR; + } + else if ((uint8_t)USB_EP_NUM <= pipe.address) + { + status = ENDPOINT_ADDRESS_ERROR; + } + else if (INTERRUPT < endpointType) + { + status = ENDPOINT_TYPE_ERROR; + } + else + { + switch (endpointType) + { + case CONTROL: + endpointConfiguration |= USB_TYPE_CONTROL_gc; + break; + case ISOCHRONOUS: + endpointConfiguration |= USB_TYPE_ISO_gc; + break; + case BULK: + case INTERRUPT: + endpointConfiguration |= USB_TYPE_BULKINT_gc; + break; + default: + endpointConfiguration |= USB_TYPE_DISABLE_gc; + break; + } + + if (USB_EP_DIR_OUT == pipe.direction) + { + USB_EndpointOutNAKSet(pipe.address); + USB_EndpointOutStatusClear(pipe.address); + USB_NumberBytesReceivedReset(pipe.address); + USB_EndpointOutControlSet(pipe.address, endpointConfiguration); + + // Set up the static endpoint configurations + if ((uint8_t)0x01 == endpointStaticConfig[pipe.address].OutMultipktEnable) + { + USB_EndpointOutMultipktEnable(pipe.address); + + if ((uint8_t)0x01 == endpointStaticConfig[pipe.address].OutAzlpEnable) + { + USB_EndpointOutAzlpEnable(pipe.address); + } + + status = SUCCESS; + } + else if ((uint8_t)0x01 == endpointStaticConfig[pipe.address].OutAzlpEnable) + { + // AZLP only works together with multipacket + status = ENDPOINT_AZLP_ERROR; + } + else + { + status = SUCCESS; + } + + if ((uint8_t)0x01 != endpointStaticConfig[pipe.address].OutTrncInterruptEnable) + { + USB_EndpointOutTransactionCompleteInterruptDisable(pipe.address); + } + } + else + { + USB_EndpointInNAKSet(pipe.address); + USB_EndpointInStatusClear(pipe.address); + USB_NumberBytesToSendReset(pipe.address); + USB_EndpointInControlSet(pipe.address, endpointConfiguration); + + // Set up the static endpoint configurations + if ((uint8_t)0x01 == endpointStaticConfig[pipe.address].InMultipktEnable) + { + USB_EndpointInMultipktEnable(pipe.address); + + if ((uint8_t)0x01 == endpointStaticConfig[pipe.address].InAzlpEnable) + { + USB_EndpointInAlzpEnable(pipe.address); + } + + status = SUCCESS; + } + else if ((uint8_t)0x01 == endpointStaticConfig[pipe.address].InAzlpEnable) + { + // AZLP only works together with multipacket + status = ENDPOINT_AZLP_ERROR; + } + else + { + status = SUCCESS; + } + + if ((uint8_t)0x01 != endpointStaticConfig[pipe.address].InTrncInterruptEnable) + { + USB_EndpointInTransactionCompleteDisable(pipe.address); + } + } + } + + return status; +} + +RETURN_CODE_t USB_EndpointDisable(USB_PIPE_t pipe) +{ + RETURN_CODE_t status = UNINITIALIZED; + + if ((uint8_t)USB_EP_NUM <= pipe.address) + { + status = ENDPOINT_ADDRESS_ERROR; + } + else + { + if (USB_EP_DIR_OUT == pipe.direction) + { + USB_EndPointOutDisable(pipe.address); + } + else + { + USB_EndPointInDisable(pipe.address); + } + + status = SUCCESS; + } + + return status; +} + +uint16_t USB_EndpointSizeGet(USB_PIPE_t pipe) +{ + uint8_t endpointType = 0; + uint8_t endpointSizeConfig = 0; + int16_t endpointSize = 0; + if (USB_EP_DIR_OUT == pipe.direction) + { + endpointType = USB_EndPointOutTypeConfigGet(pipe.address); + endpointSizeConfig = (USB_TYPE_ISO_gc == endpointType) ? USB_EndpointOutIsoSizeGet(pipe.address) : USB_EndpointOutDefaultSizeGet(pipe.address); + } + else + { + endpointType = USB_EndPointInTypeConfigGet(pipe.address); + endpointSizeConfig = (USB_TYPE_ISO_gc == endpointType) ? USB_EndpointInIsoSizeGet(pipe.address) : USB_EndpointInDefaultSizeGet(pipe.address); + } + if (USB_BUFSIZE_ISO_BUF1023_gc == endpointSizeConfig) + { + endpointSize = MAX_ENDPOINT_SIZE_ISO; + } + else + { + endpointSize = 8U << (uint16_t)endpointSizeConfig; + } + return endpointSize; +} + +USB_ENDPOINT_t USB_EndpointTypeGet(USB_PIPE_t pipe) +{ + USB_TYPE_t endpointConfigType; + if (USB_EP_DIR_OUT == pipe.direction) + { + endpointConfigType = USB_EndPointOutTypeConfigGet(pipe.address); + } + else // USB_EP_DIR_IN + { + endpointConfigType = USB_EndPointInTypeConfigGet(pipe.address); + } + + USB_ENDPOINT_t endpointType = DISABLED; + switch (endpointConfigType) + { + case USB_TYPE_CONTROL_gc: + endpointType = CONTROL; + break; + case USB_TYPE_BULKINT_gc: + // Peripheral does not distinguish between BULK and INTERRUPT, returning BULK + endpointType = BULK; + break; + case USB_TYPE_ISO_gc: + endpointType = ISOCHRONOUS; + break; + default: + // endpointType = DISABLED; + break; + } + + return endpointType; +} + +RETURN_CODE_t USB_EndpointStall(USB_PIPE_t pipe) +{ + RETURN_CODE_t status = UNINITIALIZED; + + if ((uint8_t)USB_EP_NUM <= pipe.address) + { + status = ENDPOINT_ADDRESS_ERROR; + } + else + { + if (USB_EP_DIR_OUT == pipe.direction) + { + USB_EndpointOutStall(pipe.address); + } + else + { + USB_EndpointInStall(pipe.address); + } + + status = SUCCESS; + } + + return status; +} + +RETURN_CODE_t USB_EndpointStallClear(USB_PIPE_t pipe) +{ + RETURN_CODE_t status = UNINITIALIZED; + + if ((uint8_t)USB_EP_NUM <= pipe.address) + { + status = ENDPOINT_ADDRESS_ERROR; + } + else + { + if (USB_EP_DIR_OUT == pipe.direction) + { + USB_EndpointOutStallClear(pipe.address); + } + else + { + USB_EndpointInStallClear(pipe.address); + } + + status = SUCCESS; + } + + return status; +} + +bool USB_EndpointIsStalled(USB_PIPE_t pipe) +{ + + bool isStalled = false; + + if ((uint8_t)USB_EP_NUM > pipe.address) + { + if (USB_EP_DIR_OUT == pipe.direction) + { + isStalled = USB_EndpointOutIsStalled(pipe.address); + } + else + { + isStalled = USB_EndpointInIsStalled(pipe.address); + } + } + + return isStalled; +} + +RETURN_CODE_t USB_EndpointStalledConditionAck(USB_PIPE_t pipe) +{ + RETURN_CODE_t status = UNINITIALIZED; + + if ((uint8_t)USB_EP_NUM <= pipe.address) + { + status = ENDPOINT_ADDRESS_ERROR; + } + else + { + if (USB_EP_DIR_OUT == pipe.direction) + { + USB_EndpointOutStallAck(pipe.address); + } + else + { + USB_EndpointInStallAck(pipe.address); + } + + status = SUCCESS; + } + + return status; +} + +RETURN_CODE_t USB_DataToggleSet(USB_PIPE_t pipe) +{ + RETURN_CODE_t status = UNINITIALIZED; + + if ((uint8_t)USB_EP_NUM <= pipe.address) + { + status = ENDPOINT_ADDRESS_ERROR; + } + else + { + if (USB_EP_DIR_OUT == pipe.direction) + { + USB_EndpointOutDataToggleSet(pipe.address); + } + else + { + USB_EndpointInDataToggleSet(pipe.address); + } + + status = SUCCESS; + } + + return status; +} + +RETURN_CODE_t USB_DataToggleClear(USB_PIPE_t pipe) +{ + RETURN_CODE_t status = UNINITIALIZED; + + if ((uint8_t)USB_EP_NUM <= pipe.address) + { + status = ENDPOINT_ADDRESS_ERROR; + } + else + { + if (USB_EP_DIR_OUT == pipe.direction) + { + USB_EndpointOutDataToggleClear(pipe.address); + } + else + { + USB_EndpointInDataToggleClear(pipe.address); + } + + status = SUCCESS; + } + + return status; +} + +RETURN_CODE_t USB_DataToggle(USB_PIPE_t pipe) +{ + RETURN_CODE_t status = UNINITIALIZED; + + if ((uint8_t)USB_EP_NUM <= pipe.address) + { + status = ENDPOINT_ADDRESS_ERROR; + } + else + { + if (USB_EP_DIR_OUT == pipe.direction) + { + (USB_EndpointOutDataToggleIsSet(pipe.address)) ? USB_DataToggleClear(pipe) : USB_DataToggleSet(pipe); + } + else + { + (USB_EndpointInDataToggleIsSet(pipe.address)) ? USB_DataToggleClear(pipe) : USB_DataToggleSet(pipe); + } + + status = SUCCESS; + } + + return status; +} + +RETURN_CODE_t ConvertEndpointSizeToMask(uint16_t endpointSize, USB_ENDPOINT_t endpointType, uint8_t *endpointMaskPtr) +{ + RETURN_CODE_t status = UNINITIALIZED; + + if (ISOCHRONOUS == endpointType) + { + if (((uint16_t)MAX_ENDPOINT_SIZE_ISO < endpointSize) || ((endpointSize < (uint16_t)MAX_ENDPOINT_SIZE_ISO) && !(IsPowerOfTwo(endpointSize)))) + { + status = ENDPOINT_SIZE_ERROR; + } + } + else + { + if (((uint16_t)MAX_ENDPOINT_SIZE_DEFAULT < endpointSize) || !(IsPowerOfTwo(endpointSize))) + { + status = ENDPOINT_SIZE_ERROR; + } + } + + if (UNINITIALIZED == status) + { + if ((uint16_t)MAX_ENDPOINT_SIZE_ISO == endpointSize) + { + *endpointMaskPtr = USB_BUFSIZE_ISO_BUF1023_gc; + } + else + { + uint8_t mask = 0; + uint16_t baseSize = 8; + + while (baseSize < endpointSize) + { + + mask++; + baseSize <<= 1; + } + + *endpointMaskPtr = mask << USB_BUFSIZE_DEFAULT_gp; + } + + status = SUCCESS; + } + + return status; +} + +RETURN_CODE_t EndpointBufferSet(USB_PIPE_t pipe, uint8_t *bufAddress) +{ + RETURN_CODE_t status = UNINITIALIZED; + + if ((uint8_t)USB_EP_NUM <= pipe.address) + { + status = ENDPOINT_ADDRESS_ERROR; + } + else + { + if (USB_EP_DIR_OUT == pipe.direction) + { + // Errata: Out transactions must be word aligned when using multipacket + if ((1u == endpointStaticConfig[pipe.address].OutMultipktEnable) && (((uint16_t)bufAddress & 0x0001) != 0u)) + { + status = ENDPOINT_ALIGN_ERROR; + } + else + { + USB_EndpointOutBufferSet(pipe.address, bufAddress); + status = SUCCESS; + } + } + else + { + USB_EndpointInBufferSet(pipe.address, bufAddress); + status = SUCCESS; + } + } + + return status; +} diff --git a/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_peripheral/usb_peripheral_endpoint.h b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_peripheral/usb_peripheral_endpoint.h new file mode 100644 index 0000000..6de1e44 --- /dev/null +++ b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_peripheral/usb_peripheral_endpoint.h @@ -0,0 +1,171 @@ +/** + * USBPERIPHERALENDPOINT Peripheral Endpoint Header File + * @file usb_peripheral_endpoint.h + * @defgroup usb_peripheral_endpoint USB Peripheral Endpoint + * @ingroup usb_peripheral + * @brief API module for usb_peripheral_endpoint covering endpoint-related functions. + * @version USB Device Stack HAL Driver Version 1.0.0 + */ + +/* + (c) 2021 Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip software and any + derivatives exclusively with Microchip products. It is your responsibility to comply with third party + license terms applicable to your use of third party software (including open source software) that + may accompany Microchip software. + + THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER + EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY + IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS + FOR A PARTICULAR PURPOSE. + + IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND + WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP + HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO + THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL + CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT + OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS + SOFTWARE. + */ + +#ifndef USB_PERIPHERAL_ENDPOINT_H +// cppcheck-suppress misra-c2012-2.5 +#define USB_PERIPHERAL_ENDPOINT_H + +#include +#include + +#include "usb_common_elements.h" +#include "usb_protocol_headers.h" + +/** + * @ingroup usb_peripheral_endpoint + * @brief Configures the endpoint with the desired settings using the Control and Status Register. + * Used to set up an endpoint before using it in an application. + * Sets up all the control register settings by looking up the usb_config.h file and clears the count registers. + * @param pipe - A combination of endpoint address and direction + * @param endpointSize - Number of bytes of data supported by the endpoint in one USB transaction + * @param endpointType - Type of USB endpoint as defined by usb_endpoint_type + * @return SUCCESS or an Error code according to RETURN_CODE_t + */ +RETURN_CODE_t USB_EndpointConfigure(USB_PIPE_t pipe, uint16_t endpointSize, USB_ENDPOINT_t endpointType); + +/** + * @ingroup usb_peripheral_endpoint + * @brief Disables the endpoint by setting the endpoint type to 0x00. + * @param pipe - A combination of endpoint address and direction + * @return SUCCESS or an Error code according to RETURN_CODE_t + */ +RETURN_CODE_t USB_EndpointDisable(USB_PIPE_t pipe); + +/** + * @ingroup usb_peripheral_endpoint + * @brief Helper function to return the endpoint size. + * @param pipe - A combination of endpoint address and direction + * @return The size of the endpoint + */ +uint16_t USB_EndpointSizeGet(USB_PIPE_t pipe); + +/** + * @ingroup usb_peripheral_endpoint + * @brief Helper function to return the endpoint type. + * @param pipe - A combination of endpoint address and direction + * @return The endpoint type + */ +USB_ENDPOINT_t USB_EndpointTypeGet(USB_PIPE_t pipe); + +/** + * @ingroup usb_peripheral_endpoint + * @brief Helps stall an endpoint when a command received from the host is invalid or unrecognizable. + * Used if the host sends data that is not supported by the device. + * @param pipe - A combination of endpoint address and direction + * @return SUCCESS or an Error code according to RETURN_CODE_t + */ +RETURN_CODE_t USB_EndpointStall(USB_PIPE_t pipe); + +/** + * @ingroup usb_peripheral_endpoint + * @brief Helps clear the Stall condition after the device has recovered from an unsupported command from the host. + * Used to reset stall before the next USB transfer. + * Used when the host issues a clear HALT/Feature request to reset stall. + * @param pipe - A combination of endpoint address and direction + * @return SUCCESS or an Error code according to RETURN_CODE_t + */ +RETURN_CODE_t USB_EndpointStallClear(USB_PIPE_t pipe); + +/** + * @ingroup usb_peripheral_endpoint + * @brief Helper function to return the endpoint Stall condition. + * @param pipe - A combination of endpoint address and direction + * @return A boolean value representing the Stall condition. If the pipe address is out of bounds, the function will always return false + */ +bool USB_EndpointIsStalled(USB_PIPE_t pipe); + +/** + * @ingroup usb_peripheral_endpoint + * @brief Acknowledges the stall status condition by clearing the Stall Status bit. + * Used to clear the Stall Status bit after a stall has been detected. + * @param pipe - A combination of endpoint address and direction + * @return SUCCESS or an Error code according to RETURN_CODE_t + */ +RETURN_CODE_t USB_EndpointStalledConditionAck(USB_PIPE_t pipe); + +/** + * @ingroup usb_peripheral_endpoint + * @brief Sets the Data Toggle bit on an endpoint which is used to ensure correct data sequence. + * Only used if hardware data toggling is not available. + * After a successful transaction, toggle the Data Toggle bit. + * For SETUP transactions, ensure that the SETUP stage clears the Data Toggle bit, + * while the data stage and status stage set the Data Toggle bit. + * @param pipe - A combination of endpoint address and direction + * @return SUCCESS or an Error code according to RETURN_CODE_t + */ +RETURN_CODE_t USB_DataToggleSet(USB_PIPE_t pipe); + +/** + * @ingroup usb_peripheral_endpoint + * @brief Clears the Data Toggle bit on an endpoint which is used to ensure correct data sequence. + * Only used if hardware data toggling is not available. + * After a successful transaction, toggle the Data Toggle bit. + * For SETUP transactions, ensure that the SETUP stage clears the Data Toggle bit, + * while the data stage and status stage set the Data Toggle bit. + * @param pipe - A combination of endpoint address and direction + * @return SUCCESS or an Error code according to RETURN_CODE_t + */ +RETURN_CODE_t USB_DataToggleClear(USB_PIPE_t pipe); + +/** + * @ingroup usb_peripheral_endpoint + * @brief Toggles the Data Toggle bit on an endpoint which is used to ensure correct data sequence. + * Only used if hardware data toggling is not available. + * After a successful transaction, toggle the Data Toggle bit. + * For SETUP transactions, ensure that the SETUP stage clears the Data Toggle bit, + * while the data stage and status stage set the Data Toggle bit. + * @param pipe - A combination of endpoint address and direction + * @return SUCCESS or an Error code according to RETURN_CODE_t + */ +RETURN_CODE_t USB_DataToggle(USB_PIPE_t pipe); + +/** + * @ingroup usb_peripheral_endpoint + * @brief Converts an endpoint size in number of bytes into a register setting. + * Converts the endpoint size bit mask based on the EP_BUFSIZE setting of the endpoint control register. + * @param endpointSize - The size to convert + * @param endpointType - The endpoint type + * @param endpointMaskPtr - Pointer to the mask variable to write to + * @return SUCCESS or an Error code according to RETURN_CODE_t + */ +RETURN_CODE_t ConvertEndpointSizeToMask(uint16_t endpointSize, USB_ENDPOINT_t endpointType, uint8_t *endpointMaskPtr); + +/** + * @ingroup usb_peripheral_endpoint + * @brief Configures the endpoint data buffer to a location in RAM for the next transaction. + * @param pipe - A combination of endpoint address and direction + * @param bufAddress - The pointer to the data buffer the endpoint will use + * @return SUCCESS or an Error code according to RETURN_CODE_t + */ +RETURN_CODE_t EndpointBufferSet(USB_PIPE_t pipe, uint8_t *bufAddress); + +#endif /* USB_PERIPHERAL_ENDPOINT_H */ diff --git a/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_peripheral/usb_peripheral_read_write.c b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_peripheral/usb_peripheral_read_write.c new file mode 100644 index 0000000..23e02df --- /dev/null +++ b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_peripheral/usb_peripheral_read_write.c @@ -0,0 +1,484 @@ +/** + * USBPERIPHERALREADWRITE Peripheral Read/Write Source File + * @file usb_peripheral_read_write.c + * @ingroup usb_peripheral_read_write + * @brief API module for usb_peripheral covering low level USB transaction functions. + * @version USB Device Stack HAL Driver Version 1.0.0 + */ + +/* + (c) 2021 Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip software and any + derivatives exclusively with Microchip products. It is your responsibility to comply with third party + license terms applicable to your use of third party software (including open source software) that + may accompany Microchip software. + + THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER + EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY + IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS + FOR A PARTICULAR PURPOSE. + + IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND + WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP + HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO + THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL + CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT + OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS + SOFTWARE. + */ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +/** + * @ingroup usb_peripheral_read_write + * @def Calculates from pipe address and direction to location in a transfer array. + * @param pipe - A combination of endpoint address and direction + * @return The pipe transaction index for this pipe in pipe_transfer[] + */ +#define PipeTransferIndexGet(pipe) (((pipe).address * 2) + (pipe).direction) + +STATIC USB_PIPE_TRANSFER_t pipeTransfer[USB_EP_NUM * 2]; + +RETURN_CODE_t USB_TransactionStart(USB_PIPE_t pipe) +{ + RETURN_CODE_t status = UNINITIALIZED; + + if ((uint8_t)USB_EP_NUM <= pipe.address) + { + status = ENDPOINT_ADDRESS_ERROR; + } + else + { + if (USB_EP_DIR_OUT == pipe.direction) + { + USB_EndpointOutNAKClear(pipe.address); + } + else + { + USB_EndpointInNAKClear(pipe.address); + } + + status = SUCCESS; + } + + return status; +} + +RETURN_CODE_t USB_TransactionAbort(USB_PIPE_t pipe) +{ + RETURN_CODE_t status = UNINITIALIZED; + + if ((uint8_t)USB_EP_NUM <= pipe.address) + { + status = ENDPOINT_ADDRESS_ERROR; + } + else + { + if (USB_EP_DIR_OUT == pipe.direction) + { + USB_EndpointOutNAKSet(pipe.address); + } + else + { + USB_EndpointInNAKSet(pipe.address); + } + + pipeTransfer[PipeTransferIndexGet(pipe)].status = USB_PIPE_TRANSFER_ABORTED; + status = SUCCESS; + } + + return status; +} + +RETURN_CODE_t USB_TransactionCompleteAck(USB_PIPE_t pipe) +{ + RETURN_CODE_t status = UNINITIALIZED; + + if ((uint8_t)USB_EP_NUM <= pipe.address) + { + status = ENDPOINT_ADDRESS_ERROR; + } + else + { + if (USB_EP_DIR_OUT == pipe.direction) + { + USB_EndpointOutTransactionCompleteAck(pipe.address); + } + else + { + USB_EndpointInTransactionCompleteAck(pipe.address); + } + pipeTransfer[PipeTransferIndexGet(pipe)].status = USB_PIPE_TRANSFER_OK; + status = SUCCESS; + } + + return status; +} + +bool USB_TransactionIsCompleted(void) +{ + return USB_TransactionCompleteInterruptIs(); +} + +RETURN_CODE_t USB_TransactionCompletedPipeGet(USB_PIPE_t *pipe) +{ + RETURN_CODE_t status = UNINITIALIZED; + + if (USB_TransactionIsCompleted()) + { + // Finds FIFO entry by adding (subtracting) the signed read pointer to the size of the FIFO + // Reading the FIFO Read Pointer will handle the Transaction Complete Interrupt flag. + // The USB_FifoReadPointerGet is a device-specific function. + + uint8_t fifoEntry = endpointTable.FIFO[(USB_EP_NUM * 2u) + USB_FifoReadPointerGet()]; + + // The FIFO entry contains the endpoint address and direction of the endpoint to handle next. + USB_PIPE_t returnPipe = { .direction = (fifoEntry & USB_DIR_bm) >> USB_DIR_bp, .address = (fifoEntry & USB_EPNUM_gm) >> USB_EPNUM_gp }; + + if ((uint8_t)USB_EP_NUM <= returnPipe.address) + { + status = ENDPOINT_ADDRESS_ERROR; + } + else + { + pipe->address = returnPipe.address; + pipe->direction = returnPipe.direction; + status = SUCCESS; + } + } + else + { + // No transaction is completed. + status = PIPE_TRANSFER_ERROR; + } + + return status; +} + +RETURN_CODE_t USB_PipeReset(USB_PIPE_t pipe) +{ + RETURN_CODE_t status = UNINITIALIZED; + USB_PIPE_TRANSFER_t *pipeTransferPtr = &pipeTransfer[PipeTransferIndexGet(pipe)]; + + if ((uint8_t)USB_EP_NUM <= pipe.address) + { + status = ENDPOINT_ADDRESS_ERROR; + } + else + { + pipeTransferPtr->status = USB_PIPE_TRANSFER_OK; + pipeTransferPtr->transferDataPtr = NULL; + pipeTransferPtr->transferDataSize = 0; + pipeTransferPtr->bytesTransferred = 0; + pipeTransferPtr->transferEndCallback = NULL; + pipeTransferPtr->ZLPEnable = false; + + status = SUCCESS; + } + + return status; +} + +USB_TRANSFER_STATUS_t USB_PipeStatusGet(USB_PIPE_t pipe) +{ + + return pipeTransfer[PipeTransferIndexGet(pipe)].status; +} + +bool USB_PipeStatusIsBusy(USB_PIPE_t pipe) +{ + + return (pipeTransfer[PipeTransferIndexGet(pipe)].status == USB_PIPE_TRANSFER_BUSY); +} + +void USB_PipeDataPtrSet(USB_PIPE_t pipe, uint8_t *dataPtr) +{ + + pipeTransfer[PipeTransferIndexGet(pipe)].transferDataPtr = dataPtr; +} + +uint8_t *USB_PipeDataPtrGet(USB_PIPE_t pipe) +{ + + return pipeTransfer[PipeTransferIndexGet(pipe)].transferDataPtr; +} + +void USB_PipeDataToTransferSizeSet(USB_PIPE_t pipe, uint16_t dataSize) +{ + + pipeTransfer[PipeTransferIndexGet(pipe)].transferDataSize = dataSize; +} + +uint16_t USB_PipeDataToTransferSizeGet(USB_PIPE_t pipe) +{ + + return pipeTransfer[PipeTransferIndexGet(pipe)].transferDataSize; +} + +uint16_t USB_PipeDataTransferredSizeGet(USB_PIPE_t pipe) +{ + + return pipeTransfer[PipeTransferIndexGet(pipe)].bytesTransferred; +} + +void USB_PipeDataTransferredSizeSet(USB_PIPE_t pipe, uint16_t dataSize) +{ + + pipeTransfer[PipeTransferIndexGet(pipe)].bytesTransferred = dataSize; +} + +void USB_PipeDataTransferredSizeReset(USB_PIPE_t pipe) +{ + + pipeTransfer[PipeTransferIndexGet(pipe)].bytesTransferred = 0; +} + +void USB_PipeTransferZLP_Enable(USB_PIPE_t pipe) +{ + // Only enable manual ZLP if hardware AZLP is not enabled. + if (((USB_EP_DIR_IN == pipe.direction) && (0u == endpointStaticConfig[pipe.address].InAzlpEnable)) + || ((USB_EP_DIR_OUT == pipe.direction) && (0u == endpointStaticConfig[pipe.address].OutAzlpEnable))) + { + pipeTransfer[PipeTransferIndexGet(pipe)].ZLPEnable = true; + } +} + +void USB_PipeTransferEndCallbackRegister(USB_PIPE_t pipe, USB_TRANSFER_END_CALLBACK_t callback) +{ + pipeTransfer[PipeTransferIndexGet(pipe)].transferEndCallback = callback; +} + +void USB_PipeTransferEndCallback(USB_PIPE_t pipe) +{ + USB_PIPE_TRANSFER_t *pipeTransferPtr = &pipeTransfer[PipeTransferIndexGet(pipe)]; + + if (NULL != pipeTransferPtr->transferEndCallback) + { + pipeTransferPtr->transferEndCallback(pipe, pipeTransferPtr->status, pipeTransferPtr->bytesTransferred); + } +} + +RETURN_CODE_t USB_InTransactionRun(USB_PIPE_t pipe) +{ + USB_PIPE_TRANSFER_t *pipeTransferPtr = &pipeTransfer[PipeTransferIndexGet(pipe)]; + RETURN_CODE_t status = UNINITIALIZED; + uint16_t nextTransactionSize; + + if (USB_EP_DIR_IN != pipe.direction) + { + // Pipe is OUT, returns error code. + status = ENDPOINT_DIRECTION_ERROR; + } + else + { + // Makes sure the transfer status is busy. + pipeTransferPtr->status = USB_PIPE_TRANSFER_BUSY; + + // Calculates the size of next transaction. + nextTransactionSize = pipeTransferPtr->transferDataSize - pipeTransferPtr->bytesTransferred; + if (0U == nextTransactionSize) + { + // All data is sent, check if we need to send a manual ZLP as well. + if (true == pipeTransferPtr->ZLPEnable) + { + // Sends a zero-length package by setting bytes to send to 0. + USB_NumberBytesToSendSet(pipe.address, 0u); + USB_NumberBytesSentReset(pipe.address); + USB_EndpointInNAKClear(pipe.address); + + // Clears ZLPEnable to show it has been sent. + pipeTransferPtr->ZLPEnable = false; + } + else + { + // Everything has been sent, return transfer status to OK. + pipeTransferPtr->status = USB_PIPE_TRANSFER_OK; + } + + status = SUCCESS; + } + else + { + uint16_t endpointSize = USB_EndpointSizeGet(pipe); + if ((0u == endpointStaticConfig[pipe.address].InMultipktEnable) && (nextTransactionSize > endpointSize)) + { + // Only send endpoint size packet per transaction when MultiPacket is disabled. + nextTransactionSize = endpointSize; + } + else + { + // Check if a manual ZLP is needed after transaction, if transaction size is a multiple of endpoint size. + pipeTransferPtr->ZLPEnable = (pipeTransferPtr->ZLPEnable) && (0U == (nextTransactionSize % (uint16_t)endpointSize)); + } + + // Configure where to transfer from. + status = EndpointBufferSet(pipe, &pipeTransferPtr->transferDataPtr[pipeTransferPtr->bytesTransferred]); + + // Send transaction + if (SUCCESS == status) + { + USB_NumberBytesToSendSet(pipe.address, nextTransactionSize); + USB_NumberBytesSentReset(pipe.address); + USB_EndpointInNAKClear(pipe.address); + } + } + } + + return status; +} + +RETURN_CODE_t USB_OutTransactionRun(USB_PIPE_t pipe) +{ + USB_PIPE_TRANSFER_t *pipeTransferPtr = &pipeTransfer[PipeTransferIndexGet(pipe)]; + RETURN_CODE_t status = UNINITIALIZED; + + if (USB_EP_DIR_OUT != pipe.direction) + { + // Pipe is IN, return error code. + status = ENDPOINT_DIRECTION_ERROR; + } + else + { + // Make sure the transfer status is busy. + pipeTransferPtr->status = USB_PIPE_TRANSFER_BUSY; + + // Update the data pointer for the next transaction. + status = EndpointBufferSet(pipe, &pipeTransferPtr->transferDataPtr[pipeTransferPtr->bytesTransferred]); + + // Calculate the size of next transaction. + uint16_t endpointSize = USB_EndpointSizeGet(pipe); + uint16_t nextTransactionSize = pipeTransferPtr->transferDataSize - pipeTransferPtr->bytesTransferred; + if (0u == endpointStaticConfig[pipe.address].OutMultipktEnable) + { + if (nextTransactionSize < endpointSize) + { + // Temporarily enable MultiPacket to avoid receiving data that overflows endpoint buffer. + USB_EndpointOutMultipktEnable(pipe.address); + } + else + { + // Only expect one endpoint size packet per transaction when MultiPacket is disabled. + if (nextTransactionSize > endpointSize) + { + nextTransactionSize = endpointSize; + } + + // Disable MultiPacket in case it was enabled for previous transaction. + USB_EndpointOutMultipktDisable(pipe.address); + } + } + + if (0u == nextTransactionSize) + { + // Clear ZLPEnable to indicate that the transfer is completed and the ZLP transfer is initated. + pipeTransferPtr->ZLPEnable = false; + + // Everything has been sent, return transfer status to OK. + pipeTransferPtr->status = USB_PIPE_TRANSFER_OK; + } + else + { + // Check if a manual ZLP is needed after transaction, if transaction size is a multiple of endpoint size. + pipeTransferPtr->ZLPEnable = pipeTransferPtr->ZLPEnable && (0u == (nextTransactionSize % endpointSize)); + } + + // Start the transaction + USB_NumberBytesReceivedReset(pipe.address); + USB_NumberBytesToReceiveSet(pipe.address, nextTransactionSize); + USB_EndpointOutNAKClear(pipe.address); + } + + return status; +} + +RETURN_CODE_t USB_PipeTransactionComplete(USB_PIPE_t pipe) +{ + USB_PIPE_TRANSFER_t *pipeTransferPtr = &pipeTransfer[PipeTransferIndexGet(pipe)]; + RETURN_CODE_t status = UNINITIALIZED; + uint16_t transactionSize; + + if (USB_EP_DIR_IN == pipe.direction) + { + // Transaction complete on IN. + if (USB_EndpointInMultipktIsEnabled(pipe.address) == true) + { + // With multipacket enabled we know exactly what got transferred. + transactionSize = USB_NumberBytesSentGet(pipe.address); + } + else + { + // With multipacket disabled we know what we meant to transfer. + transactionSize = USB_NumberBytesToSendGet(pipe.address); + } + + // Check if we need to send more data, or ZLP. + pipeTransferPtr->bytesTransferred += transactionSize; + if ((pipeTransferPtr->bytesTransferred != pipeTransferPtr->transferDataSize) || (pipeTransferPtr->ZLPEnable)) + { + status = USB_InTransactionRun(pipe); + } + else + { + pipeTransferPtr->status = USB_PIPE_TRANSFER_OK; + status = SUCCESS; + } + } + else + { + // Transaction complete on OUT. + transactionSize = USB_NumberBytesReceivedGet(pipe.address); + + // Checks if we have transferred more than we wanted. + uint16_t expectedTransferRemainingSize = pipeTransferPtr->transferDataSize - pipeTransferPtr->bytesTransferred; + if (expectedTransferRemainingSize < transactionSize) + { + // We may have overflowed the receive location! + if (USB_NumberBytesToReceiveGet(pipe.address) == expectedTransferRemainingSize) + { + // Multipacket has limited what we received, even if transactionSize is larger. + transactionSize = expectedTransferRemainingSize; + } + else + { + pipeTransferPtr->status = USB_PIPE_TRANSFER_ERROR; + status = PIPE_TRANSFER_ERROR; + } + } + + if (PIPE_TRANSFER_ERROR != status) + { + // Updates bytes transfered and check if we need to run more transactions. + pipeTransferPtr->bytesTransferred += transactionSize; + + if (((pipeTransferPtr->bytesTransferred < pipeTransferPtr->transferDataSize) || pipeTransferPtr->ZLPEnable) && (0u == (transactionSize % USB_EndpointSizeGet(pipe)))) + { + status = USB_OutTransactionRun(pipe); + } + else + { + pipeTransferPtr->status = USB_PIPE_TRANSFER_OK; + status = SUCCESS; + } + } + } + + // Checks if transfer is completed and cleans up. + if (USB_PIPE_TRANSFER_BUSY != pipeTransferPtr->status) + { + USB_PipeTransferEndCallback(pipe); + } + + return status; +} diff --git a/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_peripheral/usb_peripheral_read_write.h b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_peripheral/usb_peripheral_read_write.h new file mode 100644 index 0000000..2a6f839 --- /dev/null +++ b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_peripheral/usb_peripheral_read_write.h @@ -0,0 +1,222 @@ +/** + * USBPERIPHERALREADWRITE Peripheral Read/Write Header File + * @file usb_peripheral_read_write.h + * @defgroup usb_peripheral_read_write USB Peripheral Read/Write + * @ingroup usb_peripheral + * @brief API module for usb_peripheral covering low-level USB transaction functions. + * @version USB Device Stack HAL Driver Version 1.0.0 + */ +/* + (c) 2021 Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip software and any + derivatives exclusively with Microchip products. It is your responsibility to comply with third party + license terms applicable to your use of third party software (including open source software) that + may accompany Microchip software. + + THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER + EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY + IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS + FOR A PARTICULAR PURPOSE. + + IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND + WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP + HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO + THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL + CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT + OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS + SOFTWARE. + */ + +#ifndef USB_PERIPHERAL_READ_WRITE_H +// cppcheck-suppress misra-c2012-2.5 +#define USB_PERIPHERAL_READ_WRITE_H + +#include +#include + +#include "usb_common_elements.h" +#include "usb_protocol_headers.h" + +/** + * @ingroup usb_peripheral_read_write + * @brief Starts sending or receiving data on an endpoint by clearing BUSNACK. + * Used as a final step while setting up a transaction on the bus. + * @param pipe - A combination of endpoint address and direction + * @return SUCCESS or an Error code according to RETURN_CODE_t + */ +RETURN_CODE_t USB_TransactionStart(USB_PIPE_t pipe); + +/** + * @ingroup usb_peripheral_read_write + * @brief Aborts the next transaction on an endpoint by setting BUSNACK. + * Used to stop exchanging data on an endpoint. The device will start NAKing requests from the host after calling this API. + * @param pipe - A combination of endpoint address and direction + * @return SUCCESS or an Error code according to RETURN_CODE_t + */ +RETURN_CODE_t USB_TransactionAbort(USB_PIPE_t pipe); + +/** + * @ingroup usb_peripheral_read_write + * @brief Acknowledges the Transaction Complete status condition by clearing the Transaction Complete status bit. + * Used to clear the Transaction Complete status bit after a transaction has successfully completed. + * @param pipe - A combination of endpoint address and direction + * @return SUCCESS or an Error code according to RETURN_CODE_t + */ +RETURN_CODE_t USB_TransactionCompleteAck(USB_PIPE_t pipe); + +/** + * @ingroup usb_peripheral_read_write + * @brief Helper function to return the endpoint transaction complete condition. + * @param None. + * @retval 0 - Transaction not complete or pipe address is out of bounds + * @retval 1 - Transaction is complete + */ +bool USB_TransactionIsCompleted(void); + +/** + * @ingroup usb_peripheral_read_write + * @brief Returns the pipe address and direction for the latest completed transaction. + * @param pipe - A combination of endpoint address and direction + * @return SUCCESS or an Error code according to RETURN_CODE_t + */ +RETURN_CODE_t USB_TransactionCompletedPipeGet(USB_PIPE_t *pipe); + +/** + * @ingroup usb_peripheral_read_write + * @brief Resets the pipe. + * @param pipe - A combination of endpoint address and direction + * @return SUCCESS or an Error code according to RETURN_CODE_t + */ +RETURN_CODE_t USB_PipeReset(USB_PIPE_t pipe); + +/** + * @ingroup usb_peripheral_read_write + * @brief Gets the current status of pipe. + * @param pipe - A combination of endpoint address and direction + * @return USB_PIPE_TRANSFER_OK or an Error code according to USB_TRANSFER_STATUS_t + */ +USB_TRANSFER_STATUS_t USB_PipeStatusGet(USB_PIPE_t pipe); + +/** + * @ingroup usb_peripheral_read_write + * @brief Checks if the pipe status is busy. + * @param pipe - A combination of endpoint address and direction + * @retval 0 - Pipe status not busy + * @retval 1 - Pipe status is busy + */ +bool USB_PipeStatusIsBusy(USB_PIPE_t pipe); + +/** + * @ingroup usb_peripheral_read_write + * @brief Configures the pointer for the data transfer in a given pipe. + * @param pipe - A combination of endpoint address and direction + * @param *dataPtr - The pointer to the data location + * @return None. + */ +void USB_PipeDataPtrSet(USB_PIPE_t pipe, uint8_t *dataPtr); + +/** + * @ingroup usb_peripheral_read_write + * @brief Gets the current data pointer for a given pipe. + * @param pipe - A combination of endpoint address and direction + * @return The pointer to the data location + */ +uint8_t *USB_PipeDataPtrGet(USB_PIPE_t pipe); + +/** + * @ingroup usb_peripheral_read_write + * @brief Sets the size of pipe data to transfer. + * @param pipe - A combination of endpoint address and direction + * @param dataSize - The size of pipe data to transfer + * @return None. + */ +void USB_PipeDataToTransferSizeSet(USB_PIPE_t pipe, uint16_t dataSize); + +/** + * @ingroup usb_peripheral_read_write + * @brief Gets the size of pipe data to transfer. + * @param pipe - A combination of endpoint address and direction + * @return The size of pipe data to transfer + */ +uint16_t USB_PipeDataToTransferSizeGet(USB_PIPE_t pipe); + +/** + * @ingroup usb_peripheral_read_write + * @brief Gets the size of the transferred pipe data. + * @param pipe - A combination of endpoint address and direction + * @return The size of transferred pipe data + */ +uint16_t USB_PipeDataTransferredSizeGet(USB_PIPE_t pipe); + +/** + * @ingroup usb_peripheral_read_write + * @brief Sets the size of the transferred pipe data. + * @param pipe - A combination of endpoint address and direction + * @param dataSize - The size of pipe data transferred + * @return None. + */ +void USB_PipeDataTransferredSizeSet(USB_PIPE_t pipe, uint16_t dataSize); + +/** + * @ingroup usb_peripheral_read_write + * @brief Resets the size of transferred pipe data. + * @param pipe - A combination of endpoint address and direction + * @return None. + */ +void USB_PipeDataTransferredSizeReset(USB_PIPE_t pipe); + +/** + * @ingroup usb_peripheral_read_write + * @brief Enables a ZLP on a transfer. + * It is enabled by default if the AZLP static config is enabled for the pipe. + * @param pipe - A combination of endpoint address and direction + * @return None. + */ +void USB_PipeTransferZLP_Enable(USB_PIPE_t pipe); + +/** + * @ingroup usb_peripheral_read_write + * @brief Sets the callback for transfer end. + * @param pipe - A combination of endpoint address and direction + * @param callback - A combination of pipe, status and transferred bytes + * @return None. + */ +void USB_PipeTransferEndCallbackRegister(USB_PIPE_t pipe, USB_TRANSFER_END_CALLBACK_t callback); + +/** + * @ingroup usb_peripheral_read_write + * @brief Calls the callback for transfer end. + * @param pipe - A combination of endpoint address and direction + * @return None. + */ +void USB_PipeTransferEndCallback(USB_PIPE_t pipe); + +/** + * @ingroup usb_peripheral_read_write + * @brief Checks the correctness of IN transactions and runs them. + * @param pipe - A combination of endpoint address and direction + * @return SUCCESS or an Error code according to RETURN_CODE_t + */ +RETURN_CODE_t USB_InTransactionRun(USB_PIPE_t pipe); + +/** + * @ingroup usb_peripheral_read_write + * @brief Checks the correctness OUT transactions and runs them. + * @param pipe - A combination of endpoint address and direction + * @return SUCCESS or an Error code according to RETURN_CODE_t + */ +RETURN_CODE_t USB_OutTransactionRun(USB_PIPE_t pipe); + +/** + * @ingroup usb_peripheral_read_write + * @brief Handles completed IN and OUT transactions. + * Processes the completed transaction and either completes the transfer or runs the next transaction. + * Will call the pipe transferEndCallback at the end of transfer, if configured. + * @param pipe - A combination of endpoint address and direction + * @return SUCCESS or an Error code according to RETURN_CODE_t + */ +RETURN_CODE_t USB_PipeTransactionComplete(USB_PIPE_t pipe); + +#endif /* USB_PERIPHERAL_READ_WRITE_H */ diff --git a/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_vendor/usb_vendor.c b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_vendor/usb_vendor.c new file mode 100644 index 0000000..539fbd0 --- /dev/null +++ b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_vendor/usb_vendor.c @@ -0,0 +1,41 @@ +/** + * USBVENDOR Vendor Source File + * @file usb_vendor.c + * @ingroup usb_vendor + * @brief Contains implementation for USB Vendor drivers. + * @version USB Device Stack Driver Version 1.0.0 + */ + +/* + (c) 2023 Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip software and any + derivatives exclusively with Microchip products. It is your responsibility to comply with third party + license terms applicable to your use of third party software (including open source software) that + may accompany Microchip software. + + THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER + EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY + IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS + FOR A PARTICULAR PURPOSE. + + IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND + WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP + HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO + THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL + CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT + OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS + SOFTWARE. + */ + +#include +#include +#include + +void USB_VendorClassInit(USB_SETUP_EVENT_CALLBACK_t interfaceEnabledCallback, USB_SETUP_PROCESS_CALLBACK_t vendorControlRequest, USB_EVENT_CALLBACK_t interfaceDisabledCallback) +{ + USB_SetInterfaceCallbackRegister(interfaceEnabledCallback); + USB_VendorRequestCallbackRegister(vendorControlRequest); + USB_InterfaceDisabledCallbackRegister(interfaceDisabledCallback); +}; diff --git a/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_vendor/usb_vendor.h b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_vendor/usb_vendor.h new file mode 100644 index 0000000..77b3d78 --- /dev/null +++ b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/usb/usb_vendor/usb_vendor.h @@ -0,0 +1,52 @@ +/** + * USBVENDOR Vendor Header File + * @file usb_vendor.h + * @defgroup usb_vendor USB Vendor Class + * @brief Contains the prototypes and data types for the vendor application drivers. + * @version USB Device Stack Driver Version 1.0.0 + * @{ + */ + +/* + (c) 2023 Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip software and any + derivatives exclusively with Microchip products. It is your responsibility to comply with third party + license terms applicable to your use of third party software (including open source software) that + may accompany Microchip software. + + THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER + EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY + IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS + FOR A PARTICULAR PURPOSE. + + IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND + WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP + HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO + THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL + CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT + OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS + SOFTWARE. + */ + +#ifndef USB_VENDOR_H +#define USB_VENDOR_H + +#include "usb_protocol_headers.h" + +/** + * @ingroup usb_vendor + * @brief Sets up interfaces for use with the Vendor class. + * @param interfaceEnabledCallback - Callback to the interface enable function + * @param vendorControlRequest - Callback to the control request function + * @param interfaceDisabledCallback - Callback to the interface disable function + * @return None. + */ +void USB_VendorClassInit(USB_SETUP_EVENT_CALLBACK_t interfaceEnabledCallback, USB_SETUP_PROCESS_CALLBACK_t vendorControlRequest, USB_EVENT_CALLBACK_t interfaceDisabledCallback); + +/** + * @} + */ + +#endif /* USB_VENDOR_H */ \ No newline at end of file diff --git a/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/vref/src/vref.c b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/vref/src/vref.c new file mode 100644 index 0000000..b41db39 --- /dev/null +++ b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/vref/src/vref.c @@ -0,0 +1,43 @@ +/** + * VREF Generated Driver File. + * + * @file vref.c + * + * @ingroup vref + * + * @brief This file contains the API implementation for the VREF module. + * + * @version VREF Driver Version 1.0.0 +*/ +/* +© [2024] Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip + software and any derivatives exclusively with Microchip products. + You are responsible for complying with 3rd party license terms + applicable to your use of 3rd party software (including open source + software) that may accompany Microchip software. SOFTWARE IS ?AS IS.? + NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS + SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, + MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT + WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY + KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF + MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE + FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S + TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT + EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR + THIS SOFTWARE. +*/ + +#include "../vref.h" + +int8_t VREF_Initialize(void) +{ + // ALWAYSON disabled; REFSEL Internal 2.048V reference; + VREF.ACREF = 0x1; + + + + return 0; +} \ No newline at end of file diff --git a/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/vref/vref.h b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/vref/vref.h new file mode 100644 index 0000000..8186128 --- /dev/null +++ b/avr64du32-cnano-usb-vendor-mplab-mcc.X/mcc_generated_files/vref/vref.h @@ -0,0 +1,55 @@ +/** + * VREF Generated Driver API Header File + * + * @file vref.h + * + * @defgroup vref VREF + * + * @brief This file contains the API prototypes for the VREF module. + * + * @version VREF Driver Version 1.0.0 +*/ +/* +© [2024] Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip + software and any derivatives exclusively with Microchip products. + You are responsible for complying with 3rd party license terms + applicable to your use of 3rd party software (including open source + software) that may accompany Microchip software. SOFTWARE IS ?AS IS.? + NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS + SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, + MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT + WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY + KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF + MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE + FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S + TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT + EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR + THIS SOFTWARE. +*/ + + +#ifndef VREF_H_INCLUDED +#define VREF_H_INCLUDED + +#include "../system/utils/compiler.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @ingroup vref + * @brief Initializes the VREF module. + * @param None. + * @retval 0 - VREF is initialized successfully. + */ +int8_t VREF_Initialize(void); + +#ifdef __cplusplus +} +#endif + +#endif /* VREF_H_INCLUDED */ \ No newline at end of file diff --git a/avr64du32-cnano-usb-vendor-mplab-mcc.X/nbproject/configurations.xml b/avr64du32-cnano-usb-vendor-mplab-mcc.X/nbproject/configurations.xml new file mode 100644 index 0000000..9d575be --- /dev/null +++ b/avr64du32-cnano-usb-vendor-mplab-mcc.X/nbproject/configurations.xml @@ -0,0 +1,296 @@ + + + + + + + mcc_generated_files/ac/ac0.h + + + + + mcc_generated_files/system/utils/assembler/gas.h + mcc_generated_files/system/utils/assembler/iar.h + + mcc_generated_files/system/utils/assembler.h + mcc_generated_files/system/utils/utils.h + mcc_generated_files/system/utils/compiler.h + mcc_generated_files/system/utils/utils_assert.h + mcc_generated_files/system/utils/interrupt_avr8.h + mcc_generated_files/system/utils/atomic.h + + mcc_generated_files/system/pins.h + mcc_generated_files/system/system.h + mcc_generated_files/system/config_bits.h + mcc_generated_files/system/port.h + mcc_generated_files/system/syscfg.h + mcc_generated_files/system/clock.h + mcc_generated_files/system/ccp.h + mcc_generated_files/system/interrupt.h + mcc_generated_files/system/protected_io.h + + + mcc_generated_files/timer/rtc.h + + + + mcc_generated_files/usb/usb_common/usb_core_requests.h + mcc_generated_files/usb/usb_common/usb_core_transfer.h + mcc_generated_files/usb/usb_common/usb_core_events.h + mcc_generated_files/usb/usb_common/usb_core_descriptors.h + mcc_generated_files/usb/usb_common/usb_protocol_headers.h + mcc_generated_files/usb/usb_common/usb_core_requests_endpoint.h + mcc_generated_files/usb/usb_common/usb_core.h + mcc_generated_files/usb/usb_common/usb_common_elements.h + mcc_generated_files/usb/usb_common/usb_core_requests_device.h + mcc_generated_files/usb/usb_common/usb_core_requests_interface.h + + + mcc_generated_files/usb/usb_peripheral/usb_peripheral.h + mcc_generated_files/usb/usb_peripheral/usb_peripheral_avr_du.h + mcc_generated_files/usb/usb_peripheral/usb_peripheral_endpoint.h + mcc_generated_files/usb/usb_peripheral/usb_peripheral_read_write.h + + + mcc_generated_files/usb/usb_vendor/usb_vendor.h + + mcc_generated_files/usb/usb_device.h + mcc_generated_files/usb/usb_descriptors.h + mcc_generated_files/usb/usb0.h + mcc_generated_files/usb/usb_config.h + + + mcc_generated_files/vref/vref.h + + + + + Makefile + avr64du32-cnano-usb-vendor-mplab-mcc.mc3 + + + + + + + + mcc_generated_files/ac/src/ac0.c + + + + + mcc_generated_files/system/src/protected_io.S + mcc_generated_files/system/src/interrupt.c + mcc_generated_files/system/src/system.c + mcc_generated_files/system/src/clock.c + mcc_generated_files/system/src/pins.c + mcc_generated_files/system/src/syscfg.c + mcc_generated_files/system/src/config_bits.c + + + + + mcc_generated_files/timer/src/rtc.c + + + + + mcc_generated_files/usb/src/usb0.c + + + mcc_generated_files/usb/usb_common/usb_core_requests.c + mcc_generated_files/usb/usb_common/usb_core_transfer.c + mcc_generated_files/usb/usb_common/usb_core_events.c + mcc_generated_files/usb/usb_common/usb_core_descriptors.c + mcc_generated_files/usb/usb_common/usb_core.c + mcc_generated_files/usb/usb_common/usb_core_requests_endpoint.c + mcc_generated_files/usb/usb_common/usb_core_requests_interface.c + mcc_generated_files/usb/usb_common/usb_core_requests_device.c + + + mcc_generated_files/usb/usb_peripheral/usb_peripheral_endpoint.c + mcc_generated_files/usb/usb_peripheral/usb_peripheral.c + mcc_generated_files/usb/usb_peripheral/usb_peripheral_read_write.c + + + mcc_generated_files/usb/usb_vendor/usb_vendor.c + + mcc_generated_files/usb/usb_device.c + mcc_generated_files/usb/usb_descriptors.c + + + + mcc_generated_files/vref/src/vref.c + + + + main.c + + + Makefile + + + + localhost + AVR64DU32 + + + nEdbgTool + XC8 + 2.46 + 3 + + + + + + + + + + + + + + + false + false + + + + + + + false + false + + false + + false + false + false + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/avr64du32-cnano-usb-vendor-mplab-mcc.X/nbproject/project.xml b/avr64du32-cnano-usb-vendor-mplab-mcc.X/nbproject/project.xml new file mode 100644 index 0000000..cb4e4b7 --- /dev/null +++ b/avr64du32-cnano-usb-vendor-mplab-mcc.X/nbproject/project.xml @@ -0,0 +1,23 @@ + + + com.microchip.mplab.nbide.embedded.makeproject + + + avr64du32-cnano-usb-vendor-mplab-mcc + c775033d-d9a6-4706-baf0-19271a45bfb5 + 0 + ISO-8859-1 + + + + + default + 2 + + + + false + + + + diff --git a/images/mcc_analog_comparator_dacref.png b/images/mcc_analog_comparator_dacref.png new file mode 100644 index 0000000..3f20209 Binary files /dev/null and b/images/mcc_analog_comparator_dacref.png differ diff --git a/images/mcc_clock_control.png b/images/mcc_clock_control.png new file mode 100644 index 0000000..2fcc132 Binary files /dev/null and b/images/mcc_clock_control.png differ diff --git a/images/mcc_global_interrupt.jpg b/images/mcc_global_interrupt.jpg new file mode 100644 index 0000000..b7cf423 Binary files /dev/null and b/images/mcc_global_interrupt.jpg differ diff --git a/images/mcc_pinout.png b/images/mcc_pinout.png new file mode 100644 index 0000000..9ff6dfc Binary files /dev/null and b/images/mcc_pinout.png differ diff --git a/images/mcc_pinout_locks.png b/images/mcc_pinout_locks.png new file mode 100644 index 0000000..ff3606a Binary files /dev/null and b/images/mcc_pinout_locks.png differ diff --git a/images/mcc_rtc_pit.png b/images/mcc_rtc_pit.png new file mode 100644 index 0000000..d0113a1 Binary files /dev/null and b/images/mcc_rtc_pit.png differ diff --git a/images/mcc_usb_device_descriptors.png b/images/mcc_usb_device_descriptors.png new file mode 100644 index 0000000..e6e26e6 Binary files /dev/null and b/images/mcc_usb_device_descriptors.png differ diff --git a/images/mcc_usb_general_settings.png b/images/mcc_usb_general_settings.png new file mode 100644 index 0000000..ff2f155 Binary files /dev/null and b/images/mcc_usb_general_settings.png differ diff --git a/images/mcc_usb_interfaces.png b/images/mcc_usb_interfaces.png new file mode 100644 index 0000000..7ebea2f Binary files /dev/null and b/images/mcc_usb_interfaces.png differ diff --git a/images/mcc_usb_interfaces_endpoints.png b/images/mcc_usb_interfaces_endpoints.png new file mode 100644 index 0000000..382e393 Binary files /dev/null and b/images/mcc_usb_interfaces_endpoints.png differ diff --git a/images/mcc_usb_power.jpg b/images/mcc_usb_power.jpg new file mode 100644 index 0000000..09785f0 Binary files /dev/null and b/images/mcc_usb_power.jpg differ diff --git a/images/mcc_voltage_reference.png b/images/mcc_voltage_reference.png new file mode 100644 index 0000000..9f684d6 Binary files /dev/null and b/images/mcc_voltage_reference.png differ diff --git a/images/zadig_installation.png b/images/zadig_installation.png new file mode 100644 index 0000000..f934377 Binary files /dev/null and b/images/zadig_installation.png differ diff --git a/python_test/vendor_endpoints.py b/python_test/vendor_endpoints.py new file mode 100644 index 0000000..1fbfb0c --- /dev/null +++ b/python_test/vendor_endpoints.py @@ -0,0 +1,400 @@ +#! /usr/bin/python3 + +try: + import sys + from time import sleep + import random + import argparse + import array + import usb1 # https://pypi.org/project/libusb1/ + from vendor_usb import vendor_usb +except ImportError: + sys.exit("""ImportError: You are probably missing some modules. +To add needed modules, run 'python -m pip install -U libusb1'""") + + +class usb_vendor_test_endpoints: + # Size of buffers used for the loopback + VENDOR_LOOPBACK_SIZE = 4096 + ISO_NB_TRANS = (VENDOR_LOOPBACK_SIZE*2) + VENDOR_LOOPBACK_REPEAT = 2 + + def __init__(self): + self.vendor_ep_interrupt_in = None + self.vendor_ep_interrupt_out = None + self.vendor_ep_interrupt_alt = None + + self.vendor_ep_bulk_in = None + self.vendor_ep_bulk_out = None + self.vendor_ep_bulk_alt = None + + self.vendor_ep_iso_in = None + self.vendor_ep_iso_out = None + self.vendor_ep_iso_alt = None + self.vendor_ep_iso_size = None + + self.vendor_ep_iso2_in = None + self.vendor_ep_iso2_out = None + self.vendor_ep_iso2_out_alt = None + self.vendor_ep_iso2_in_alt = None + self.vendor_ep_iso2_size = None + + self.vendor = vendor_usb() + self.vendor.connect_device() + + + def main(self): + # Get descriptors and endpoints + self.get_device_data() + self.run_tests() + + def get_device_data(self): + self.vendor.print_descriptors() + + interrupt_endpoints = self.vendor.get_endpoints( + type=usb1.libusb1.LIBUSB_TRANSFER_TYPE_INTERRUPT) + bulk_endpoints = self.vendor.get_endpoints( + type=usb1.libusb1.LIBUSB_TRANSFER_TYPE_BULK) + iso_endpoints = self.vendor.get_endpoints( + type=usb1.libusb1.LIBUSB_TRANSFER_TYPE_ISOCHRONOUS) + + if len(interrupt_endpoints): + for endpoint in interrupt_endpoints: + print( + " - Interface {0} alternate {1}:".format(endpoint['interface'], endpoint['alternate'])) + self.vendor_ep_interrupt_alt = endpoint['alternate'] + if (endpoint['address'] & usb1.libusb1.LIBUSB_ENDPOINT_IN): + self.vendor_ep_interrupt_in = endpoint['address'] + print(" - Endpoint interrupt IN: 0x%02X" % + endpoint['address']) + else: + self.vendor_ep_interrupt_out = endpoint['address'] + print(" - Endpoint interrupt OUT: 0x%02X" % + endpoint['address']) + + if len(bulk_endpoints): + for endpoint in bulk_endpoints: + print( + " - Interface {0} alternate {1}:".format(endpoint['interface'], endpoint['alternate'])) + self.vendor_ep_bulk_alt = endpoint['alternate'] + if (endpoint['address'] & usb1.libusb1.LIBUSB_ENDPOINT_IN): + self.vendor_ep_bulk_in = endpoint['address'] + print(" - Endpoint bulk IN: 0x%02X" % + endpoint['address']) + else: + self.vendor_ep_bulk_out = endpoint['address'] + print(" - Endpoint bulk OUT: 0x%02X" % + endpoint['address']) + + if len(iso_endpoints): + for endpoint in iso_endpoints: + print( + " - Interface {0} alternate {1}:".format(endpoint['interface'], endpoint['alternate'])) + if endpoint['alternate'] == 2: + self.vendor_ep_iso_alt = endpoint['alternate'] + self.vendor_ep_iso_size = endpoint['size'] + if (endpoint['address'] & usb1.libusb1.LIBUSB_ENDPOINT_IN): + self.vendor_ep_iso_in = endpoint['address'] + print(" - Endpoint iso 1 IN: 0x%02X" % + endpoint['address']) + else: + self.vendor_ep_iso_out = endpoint['address'] + print(" - Endpoint iso 1 OUT: 0x%02X" % + endpoint['address']) + print(" - Endpoint iso 1 size: %i" % endpoint['size']) + else: + self.vendor_ep_iso2_size = endpoint['size'] + if (endpoint['address'] & usb1.libusb1.LIBUSB_ENDPOINT_IN): + self.vendor_ep_iso2_in_alt = endpoint['alternate'] + self.vendor_ep_iso2_in = endpoint['address'] + print(" - Endpoint iso 2 IN: 0x%02X" % + endpoint['address']) + else: + self.vendor_ep_iso2_out_alt = endpoint['alternate'] + self.vendor_ep_iso2_out = endpoint['address'] + print(" - Endpoint iso 2 OUT: 0x%02X" % + endpoint['address']) + print(" - Endpoint iso 2 size:%i" % endpoint['size']) + + def run_tests(self): + print("\n------ Starting Vendor Data Transfers") + + try: + print("Run Control endpoint loop back...") + self.init_buffers() + self.loop_back_control(self.VENDOR_LOOPBACK_SIZE) + self.init_buffers() + self.loop_back_control(self.VENDOR_LOOPBACK_SIZE-123) + + # Send configure requests before changing to the alternate interface + + # Configure azlp using the control endpoint + self.vendor.device.controlWrite(usb1.libusb1.LIBUSB_REQUEST_TYPE_VENDOR | + usb1.libusb1.LIBUSB_RECIPIENT_INTERFACE, 0, args.azlp, self.vendor.REQUEST_VENDOR_CONFIGURE_BULKINT_ZLP, [], timeout=1000) + + # Configure the bulk and interrupt transfer size + self.vendor.device.controlWrite(usb1.libusb1.LIBUSB_REQUEST_TYPE_VENDOR | + usb1.libusb1.LIBUSB_RECIPIENT_INTERFACE, 0, self.VENDOR_LOOPBACK_SIZE, self.vendor.REQUEST_VENDOR_CONFIGURE_BULKINT_SIZE, [], timeout=1000) + + # reclaim the interface, not sure why + self.vendor.device.claimInterface(self.vendor.INTERFACE_ENDPOINTS) + + if (self.vendor_ep_interrupt_in and self.vendor_ep_interrupt_out): + self.vendor.set_interface( + self.vendor.INTERFACE_ENDPOINTS, self.vendor_ep_interrupt_alt) + for _ in range(self.VENDOR_LOOPBACK_REPEAT): + print("Run Interrupt endpoint loop back...") + self.init_buffers() + self.loop_back_interrupt() + + if (self.vendor_ep_bulk_in and self.vendor_ep_bulk_out): + self.vendor.set_interface( + self.vendor.INTERFACE_ENDPOINTS, self.vendor_ep_bulk_alt) + for _ in range(self.VENDOR_LOOPBACK_REPEAT): + print("Run Bulk endpoint loop back...") + self.init_buffers() + self.loop_back_bulk() + + if (self.vendor_ep_iso_in and self.vendor_ep_iso_out): + self.vendor.set_interface( + self.vendor.INTERFACE_ENDPOINTS, self.vendor_ep_iso_alt) + print("Run Isochronous endpoint loop back simple...") + self.init_buffers() + self.loop_back_isochronous_buffer() + # not sure why we need to sleep between switching back to sending more data? + sleep(1/3) + print("Run Isochronous endpoint loop back extended...") + self.init_buffers() + self.loop_back_isochronous_packets() + + if (self.vendor_ep_iso2_in and self.vendor_ep_iso2_out): + for _ in range(self.VENDOR_LOOPBACK_REPEAT): + print("Run Isochronous endpoint loop back in special iso 1023 way...") + self.init_buffers() + self.loop_back_isochronous_buffer_special_1023() + + print(f"\n------ Data Transfers Completed Successfully") + return + + except ValueError as e: + print(f"Error: {e}") + except usb1.USBError: + print(f"USB Error: Endpoints are not configured correctly.") + print(f"Solution: Upload correct c-code to the AVR decive.") + except Exception as e: + print(f"Unexpected error: {e}") + + print(f"\n------ Data Transfers Failed") + + + def init_buffers(self): + # Reset buffer OUT + self.vendor_buf_out = array.array('B', (0,)*self.VENDOR_LOOPBACK_SIZE) + for i in range(0, self.VENDOR_LOOPBACK_SIZE, 4): + self.vendor_buf_out[i+0] = (i >> 24) & 0xFF + self.vendor_buf_out[i+1] = (i >> 16) & 0xFF + self.vendor_buf_out[i+2] = (i >> 8) & 0xFF + self.vendor_buf_out[i+3] = (i >> 0) & 0xFF + if (i % 32) == 4: + self.vendor_buf_out[i] = random.randrange(0xFF) + + # Reset buffer IN + self.vendor_buf_in = array.array('B') + + def cmp_buffers(self): + if self.vendor_buf_in != self.vendor_buf_out: + raise ValueError("vendor_buf_in != vendor_buf_out") + else: + print("Successfully sent and received {} bytes!".format( + len(self.vendor_buf_in))) + + def loop_back_control(self, bytes): + try: + self.vendor_buf_out = self.vendor_buf_out[:bytes] + self.vendor.device.controlWrite(usb1.libusb1.LIBUSB_REQUEST_TYPE_VENDOR | + usb1.libusb1.LIBUSB_RECIPIENT_INTERFACE, 0, self.vendor.REQUEST_VENDOR_TEST_CONTROL, 0, self.vendor_buf_out, timeout=1000) + self.vendor_buf_in = self.vendor.device.controlRead( + usb1.libusb1.LIBUSB_REQUEST_TYPE_VENDOR | usb1.libusb1.LIBUSB_RECIPIENT_INTERFACE, 0, self.vendor.REQUEST_VENDOR_TEST_CONTROL, 0, bytes, timeout=1000) + self.cmp_buffers() + except ValueError: + raise ValueError("Error during control endpoint transfer") + + def loop_back_interrupt(self): + try: + self.vendor.device.interruptWrite( + self.vendor_ep_interrupt_out, self.vendor_buf_out) + if args.azlp: + # send zlp + self.vendor.device.interruptWrite( + self.vendor_ep_interrupt_out, []) + # read back one more byte to get zlp + self.vendor_buf_in = self.vendor.device.interruptRead( + self.vendor_ep_interrupt_in, self.VENDOR_LOOPBACK_SIZE+1) + else: + self.vendor_buf_in = self.vendor.device.interruptRead( + self.vendor_ep_interrupt_in, self.VENDOR_LOOPBACK_SIZE) + + self.cmp_buffers() + except ValueError: + raise ValueError("Error during interrupt endpoint transfer") + + def loop_back_bulk(self): + try: + self.vendor.device.bulkWrite( + self.vendor_ep_bulk_out, self.vendor_buf_out) + if args.azlp: + # send zlp + self.vendor.device.bulkWrite(self.vendor_ep_bulk_out, []) + # read back one more byte to get zlp + self.vendor_buf_in = self.vendor.device.bulkRead( + self.vendor_ep_bulk_in, self.VENDOR_LOOPBACK_SIZE+1) + else: + self.vendor_buf_in = self.vendor.device.bulkRead( + self.vendor_ep_bulk_in, self.VENDOR_LOOPBACK_SIZE) + + self.cmp_buffers() + except ValueError: + raise ValueError("Error during bulk endpoint transfer") + + def loop_back_isochronous_buffer(self): + try: + transfer = self.vendor.device.getTransfer( + int(self.VENDOR_LOOPBACK_SIZE/self.vendor_ep_iso_size)) + + transfer.setIsochronous( + self.vendor_ep_iso_out, self.vendor_buf_out, timeout=5000) + self.vendor.submit_wait_blocking(transfer) + + transfer.setIsochronous( + self.vendor_ep_iso_in, self.VENDOR_LOOPBACK_SIZE, timeout=5000) + self.vendor.submit_wait_blocking(transfer) + + self.vendor_buf_in = array.array('B') + self.vendor_buf_in.frombytes(transfer.getBuffer()) + + self.cmp_buffers() + except ValueError: + raise ValueError("Error during simple iso endpoint transfer") + + def loop_back_isochronous_packets(self): + # Reset extra large buffer OUT + self.vendor_buf_out = array.array('B', (0,)*self.ISO_NB_TRANS) + for i in range(0, self.ISO_NB_TRANS, 4): + self.vendor_buf_out[i+0] = ord('S') + self.vendor_buf_out[i+1] = (i >> 16) & 0xFF + self.vendor_buf_out[i+2] = (i >> 8) & 0xFF + self.vendor_buf_out[i+3] = (i >> 0) & 0xFF + + # Reset buffer IN + self.vendor_buf_in = array.array('B') + iso_packet_in = array.array('B') + + packets = min(64, int(self.ISO_NB_TRANS/self.vendor_ep_iso_size)) + print("...using {0} packets of endpoint size {1}".format(packets, + self.vendor_ep_iso_size)) + + try: + + transfer = self.vendor.device.getTransfer(1) + count = 0 + for i in range(packets): + count += 1 + + # Sending vendor_ep_iso_size bytes to device + iso_packet_out = self.vendor_buf_out[i*int( + self.vendor_ep_iso_size):(i+1)*int(self.vendor_ep_iso_size)] + transfer.setIsochronous( + self.vendor_ep_iso_out, iso_packet_out, timeout=5000) + self.vendor.submit_wait_blocking(transfer) + + transfer.setIsochronous( + self.vendor_ep_iso_in, self.vendor_ep_iso_size, timeout=5000) + self.vendor.submit_wait_blocking(transfer) + + iso_packet_in = array.array('B') + iso_packet_in.frombytes(transfer.getBuffer()) + + if iso_packet_in != iso_packet_out: + print("iso_packet %i/%i fail" % (count, packets)) + print("iso_packet_out[%i] = " % + (len(iso_packet_out)), iso_packet_out) + print("iso_packet_in[%i] = " % ( + len(iso_packet_in)), iso_packet_in, flush=True) + else: + print("iso_packet %i/%i ok" % (count, packets), flush=True) + self.vendor_buf_in += iso_packet_in + + # not sure why we need to sleep between switching back to sending more data? + sleep(1/3) + + self.cmp_buffers() + except ValueError: + raise ValueError("Error during simple iso endpoint transfer") + + def loop_back_isochronous_buffer_special_1023(self): + # This test is using iso with size 1023 as bulk/interrupt, with workarounds: + # In and OUT endpoints in separate interfaces to avoid OS driver crashing + # buffer size%1023==0 to avoid OS driver crashing + ISO2_TIMEOUT = 0.3 + + ISO_SIZE = int(self.VENDOR_LOOPBACK_SIZE / + self.vendor_ep_iso2_size)*self.vendor_ep_iso2_size + self.vendor_buf_out = self.vendor_buf_out[:ISO_SIZE] + + try: + self.vendor.set_interface( + setting=self.vendor.INTERFACE_ENDPOINTS, alternate=self.vendor_ep_iso2_out_alt) + sleep(ISO2_TIMEOUT) + + # Sending VENDOR_LOOPBACK_SIZE bytes to device + transfer = self.vendor.device.getTransfer( + int(ISO_SIZE/self.vendor_ep_iso2_size)) + + transfer.setIsochronous( + self.vendor_ep_iso2_out, self.vendor_buf_out, timeout=5000) + self.vendor.submit_wait_blocking(transfer) + + self.vendor.set_interface( + setting=self.vendor.INTERFACE_ENDPOINTS, alternate=self.vendor_ep_iso2_in_alt) + sleep(ISO2_TIMEOUT) + + # Receive VENDOR_LOOPBACK_SIZE from device + transfer.setIsochronous( + self.vendor_ep_iso2_in, ISO_SIZE, timeout=5000) + self.vendor.submit_wait_blocking(transfer) + self.vendor_buf_in = array.array('B') + self.vendor_buf_in.frombytes(transfer.getBuffer()) + + self.cmp_buffers() + + except ValueError: + raise ValueError("Error during iso {} endpoint transfer".format( + self.vendor_ep_iso2_size)) + + +if __name__ == '__main__': + # Generate help and use messages + parser = argparse.ArgumentParser( + description='Python test application for transferring data on all data types', + epilog='Example: python vendor_endpoints.py', + formatter_class=argparse.RawTextHelpFormatter) + parser.add_argument( + '-z', '--azlp', help='Auto Zero-Lenght Package', action='store_true') + args = parser.parse_args() + + print("\n------ Connecting to AVR device over USB...") + + test = usb_vendor_test_endpoints() + + if test.vendor.device is None: + print(f"\n------ Failed to Connect Device") + print(f"Device VID: {vendor_usb.VID:04x}, PID: {vendor_usb.PID:04x} was not found") + print("1. Check that the curiosity nano is connected to the PC from the USB-C TARGET port (not debugger)") + print("2. Check if the c-code is programmed correctly on the AVR device") + print(f"3. Check that the USB driver is installed for the correct device") + print(f"\t For Windows, download Zadig from: https://zadig.akeo.ie/") + print(f"\t Choose the libusbK installer after downloading") + print(f"\t Select the device with VID: {vendor_usb.VID:04x} and PID: {vendor_usb.PID:04x}\n") + else: + print("\n------ Device Connected") + test.main() diff --git a/python_test/vendor_usb.py b/python_test/vendor_usb.py new file mode 100644 index 0000000..f611045 --- /dev/null +++ b/python_test/vendor_usb.py @@ -0,0 +1,122 @@ +#! /usr/bin/python3 + +import platform +import usb1 # https://pypi.org/project/libusb1/ + +class vendor_usb: + VID = 0X04D8 # Microchip Vendor IO, must match the VID on the target device + PID = 0X0B0A # Prototying Product ID, must match the PID on the target device + + # Interface and Alternate Interface Indexes + INTERFACE_ENDPOINTS = 0 + INTERFACE_ALTERNATE_BULKINT = 1 + INTERFACE_ALTERNATE_ISO1 = 2 + INTERFACE_ALTERNATE_ISO1023_OUT = 3 + INTERFACE_ALTERNATE_ISO1023_IN = 4 + + # Indexes for the custom Vendor Requests + REQUEST_VENDOR_TEST_CONTROL = 0 + REQUEST_VENDOR_CONFIGURE_BULKINT_ZLP = 1 + REQUEST_VENDOR_CONFIGURE_BULKINT_SIZE = 2 + + def __init__(self): + self.device = None + self.configuration = None + self.interfacenumber = None + self.alternatesetting = None + + self.context = usb1.USBContext() + + def connect_device(self): + device_handle = self.context.openByVendorIDAndProductID( + self.VID, + self.PID, + skip_on_error=True, + ) + if device_handle: + self.device = device_handle + self.device.setConfiguration(1) + self.set_interface(0,0) + self.configuration = self.device.getConfiguration() + return True + return False + + def get_endpoints(self, type=None, direction=None, confignumber=None, interfacenumber=None, alternatesetting=None): + endpoints = [] + + device = self.device.getDevice() + for config in device.iterConfigurations(): + if confignumber == None or config.getConfigurationValue() == confignumber: + for interface in config.iterInterfaces(): + for alternateint in interface.iterSettings(): + if interfacenumber == None or alternateint.getNumber() == interfacenumber: + if alternatesetting == None or alternateint.getAlternateSetting() == alternatesetting: + for endpoint in alternateint.iterEndpoints(): + attributes = endpoint.getAttributes() + if type == None or attributes & usb1.libusb1.LIBUSB_TRANSFER_TYPE_MASK == type: + if direction == None or endpoint.getAddress() & usb1.libusb1.LIBUSB_ENDPOINT_DIR_MASK == direction: + endpoints.append(dict( + type = endpoint.getAttributes(), + address = endpoint.getAddress(), + size = endpoint.getMaxPacketSize(), + interface = alternateint.getNumber(), + alternate = alternateint.getAlternateSetting(), + configuration = config.getConfigurationValue(), + )) + return endpoints + + def print_descriptors(self): + deviceinfo = self.device.getDevice() + + print("VendorID: 0x{:04X}".format(deviceinfo.getVendorID())) + print("ProductID: 0x{:04X}".format(deviceinfo.getProductID())) + + langIDs = self.device.getSupportedLanguageList() + if len(langIDs) > 0: + try: + # Unknow failure when using these functions + print("Manufacturer:", self.device.getManufacturer()) + print("Product:", self.device.getProduct()) + print("Serial:", self.device.getSerialNumber()) + except usb1.USBErrorIO: + # Backup functions work + print("Manufacturer:", self.device.getStringDescriptor(1, langIDs[0], errors = 'ignore')) + print("Product:", self.device.getStringDescriptor(2, langIDs[0], errors = 'ignore')) + print("Serial:", self.device.getStringDescriptor(3, langIDs[0], errors = 'ignore')) + else: + print("No supported language ids, so not expecting any strings") + + def set_interface(self, setting, alternate=0): + if setting != self.interfacenumber: + print("Claiming interface {}".format(setting)) + if self.interfacenumber: + self.device.releaseInterface(self.interfacenumber) + self.device.claimInterface(setting) + if setting != self.interfacenumber or alternate != self.alternatesetting: + print("Switching to interface {}, alternate number {}".format(setting, alternate)) + self.device.setInterfaceAltSetting(interface = setting, alt_setting = alternate) + self.interfacenumber = setting + self.alternatesetting = alternate + + def submit_wait_blocking(self, transfer): + try: + transfer.submit() + except: + raise Exception("Check that the driver is libusbK, it is need for isochronous endpoints") + while transfer.isSubmitted(): + try: + self.context.handleEvents() + except usb1.USBErrorInterrupted: + pass + +if __name__ == '__main__': + test = vendor_usb() + if test.connect_device(): + print ("Valid vendor device connected, printing descriptors\n") + test.print_descriptors() + endpoints = test.get_endpoints() + for idx,endpoint in enumerate(endpoints): + print("Endpoint {}/{}: {}".format(idx, len(endpoints), endpoint)) + + else: + print ("No valid vendor device connected") \ No newline at end of file