├── .cproject ├── .gitignore ├── .project ├── .settings └── de.innot.avreclipse.core.prefs ├── CMakeLists.txt ├── LICENSE.txt ├── README.md ├── SIMMProgrammer-AVRStudio.atsln ├── SIMMProgrammer-AVRStudio.cproj ├── chip_id.h ├── drivers ├── mcp23s17.c ├── mcp23s17.h ├── parallel_flash.c └── parallel_flash.h ├── hal ├── at90usb646 │ ├── Descriptors.c │ ├── Descriptors.h │ ├── LUFA │ │ ├── CodeTemplates │ │ │ ├── DriverStubs │ │ │ │ ├── Buttons.h │ │ │ │ ├── Dataflash.h │ │ │ │ ├── Joystick.h │ │ │ │ └── LEDs.h │ │ │ ├── LUFAConfig.h │ │ │ ├── makefile_template.avr8 │ │ │ ├── makefile_template.uc3 │ │ │ └── makefile_template.xmega │ │ ├── Common │ │ │ ├── ArchitectureSpecific.h │ │ │ ├── Architectures.h │ │ │ ├── Attributes.h │ │ │ ├── BoardTypes.h │ │ │ ├── Common.h │ │ │ ├── CompilerSpecific.h │ │ │ └── Endianness.h │ │ ├── Doxygen.conf │ │ ├── DoxygenPages │ │ │ ├── AboutLUFA.txt │ │ │ ├── AlternativeStacks.txt │ │ │ ├── Author.jpg │ │ │ ├── BuildingLinkableLibraries.txt │ │ │ ├── ChangeLog.txt │ │ │ ├── CompileTimeTokens.txt │ │ │ ├── CompilingApps.txt │ │ │ ├── ConfiguringApps.txt │ │ │ ├── DevelopingWithLUFA.txt │ │ │ ├── DeviceSupport.txt │ │ │ ├── DirectorySummaries.txt │ │ │ ├── Donating.txt │ │ │ ├── FutureChanges.txt │ │ │ ├── GettingStarted.txt │ │ │ ├── Groups.txt │ │ │ ├── LUFA.png │ │ │ ├── LUFAPoweredProjects.txt │ │ │ ├── LUFA_thumb.png │ │ │ ├── LUFAvsAtmelStack.txt │ │ │ ├── LibraryApps.txt │ │ │ ├── LibraryResources.txt │ │ │ ├── LicenseInfo.txt │ │ │ ├── MainPage.txt │ │ │ ├── MigrationInformation.txt │ │ │ ├── ProgrammingApps.txt │ │ │ ├── SoftwareBootloaderJump.txt │ │ │ ├── VIDAndPIDValues.txt │ │ │ ├── WhyUseLUFA.txt │ │ │ ├── WritingBoardDrivers.txt │ │ │ └── footer.htm │ │ ├── Drivers │ │ │ └── USB │ │ │ │ ├── Class │ │ │ │ ├── CDCClass.h │ │ │ │ ├── Common │ │ │ │ │ └── CDCClassCommon.h │ │ │ │ └── Device │ │ │ │ │ ├── CDCClassDevice.c │ │ │ │ │ └── CDCClassDevice.h │ │ │ │ ├── Core │ │ │ │ ├── AVR8 │ │ │ │ │ ├── Device_AVR8.c │ │ │ │ │ ├── Device_AVR8.h │ │ │ │ │ ├── EndpointStream_AVR8.c │ │ │ │ │ ├── EndpointStream_AVR8.h │ │ │ │ │ ├── Endpoint_AVR8.c │ │ │ │ │ ├── Endpoint_AVR8.h │ │ │ │ │ ├── Host_AVR8.c │ │ │ │ │ ├── Host_AVR8.h │ │ │ │ │ ├── OTG_AVR8.h │ │ │ │ │ ├── PipeStream_AVR8.c │ │ │ │ │ ├── PipeStream_AVR8.h │ │ │ │ │ ├── Pipe_AVR8.c │ │ │ │ │ ├── Pipe_AVR8.h │ │ │ │ │ ├── Template │ │ │ │ │ │ ├── Template_Endpoint_Control_R.c │ │ │ │ │ │ ├── Template_Endpoint_Control_W.c │ │ │ │ │ │ ├── Template_Endpoint_RW.c │ │ │ │ │ │ └── Template_Pipe_RW.c │ │ │ │ │ ├── USBController_AVR8.c │ │ │ │ │ ├── USBController_AVR8.h │ │ │ │ │ ├── USBInterrupt_AVR8.c │ │ │ │ │ └── USBInterrupt_AVR8.h │ │ │ │ ├── ConfigDescriptor.c │ │ │ │ ├── ConfigDescriptor.h │ │ │ │ ├── Device.h │ │ │ │ ├── DeviceStandardReq.c │ │ │ │ ├── DeviceStandardReq.h │ │ │ │ ├── Endpoint.h │ │ │ │ ├── EndpointStream.h │ │ │ │ ├── Events.c │ │ │ │ ├── Events.h │ │ │ │ ├── Host.h │ │ │ │ ├── HostStandardReq.c │ │ │ │ ├── HostStandardReq.h │ │ │ │ ├── OTG.h │ │ │ │ ├── Pipe.h │ │ │ │ ├── PipeStream.h │ │ │ │ ├── StdDescriptors.h │ │ │ │ ├── StdRequestType.h │ │ │ │ ├── USBController.h │ │ │ │ ├── USBInterrupt.h │ │ │ │ ├── USBMode.h │ │ │ │ ├── USBTask.c │ │ │ │ └── USBTask.h │ │ │ │ └── USB.h │ │ ├── License.txt │ │ ├── Version.h │ │ └── makefile │ ├── LUFAConfig.h │ ├── at90usb646_options.cmake │ ├── at90usb646_sources.cmake │ ├── board.c │ ├── board_hw.h │ ├── cdc_device_definition.c │ ├── cdc_device_definition.h │ ├── gpio.c │ ├── gpio_hw.h │ ├── hardware.h │ ├── parallel_bus.c │ ├── spi.c │ ├── spi_private.h │ ├── usbcdc.c │ └── usbcdc_hw.h ├── board.h ├── gpio.h ├── m258ke │ ├── board.c │ ├── board_hw.h │ ├── descriptors.c │ ├── gpio.c │ ├── gpio_hw.h │ ├── hardware.h │ ├── m258ke_options.cmake │ ├── m258ke_sources.cmake │ ├── nuvoton │ │ ├── LDROM.ld │ │ ├── M251.h │ │ ├── NuMicro.h │ │ ├── README.md │ │ ├── acmp_reg.h │ │ ├── bpwm_reg.h │ │ ├── clk_reg.h │ │ ├── cmsis_armcc.h │ │ ├── cmsis_armclang.h │ │ ├── cmsis_compiler.h │ │ ├── cmsis_gcc.h │ │ ├── cmsis_version.h │ │ ├── core_cm23.h │ │ ├── crc_reg.h │ │ ├── crypto_reg.h │ │ ├── dac_reg.h │ │ ├── eadc_reg.h │ │ ├── ebi_reg.h │ │ ├── fmc_reg.h │ │ ├── gcc_arm.ld │ │ ├── gpio_reg.h │ │ ├── i2c_reg.h │ │ ├── lcd_reg.h │ │ ├── opa_reg.h │ │ ├── pdma_reg.h │ │ ├── psio_reg.h │ │ ├── pwm_reg.h │ │ ├── qspi_reg.h │ │ ├── rtc_reg.h │ │ ├── sc_reg.h │ │ ├── spi_reg.h │ │ ├── startup_M251.S │ │ ├── sys_reg.h │ │ ├── system_M251.c │ │ ├── system_M251.h │ │ ├── timer_reg.h │ │ ├── tk_reg.h │ │ ├── uart_reg.h │ │ ├── ui2c_reg.h │ │ ├── usbd.c │ │ ├── usbd.h │ │ ├── usbd_reg.h │ │ ├── uspi_reg.h │ │ ├── uuart_reg.h │ │ ├── wdt_reg.h │ │ └── wwdt_reg.h │ ├── parallel_bus.c │ ├── spi.c │ ├── spi_private.h │ ├── usbcdc.c │ └── usbcdc_hw.h ├── parallel_bus.h ├── spi.h └── usbcdc.h ├── led.h ├── main.c ├── programmer_protocol.h ├── simm_programmer.c ├── simm_programmer.h ├── tests ├── simm_electrical_test.c └── simm_electrical_test.h ├── toolchain-avr.cmake ├── toolchain-m258ke.cmake └── util.h /.gitignore: -------------------------------------------------------------------------------- 1 | /Debug 2 | /Release 3 | .settings/org.eclipse.cdt.core.prefs 4 | CMakeLists.txt.user 5 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | SIMMProgrammer 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | ?name? 14 | 15 | 16 | 17 | org.eclipse.cdt.make.core.append_environment 18 | true 19 | 20 | 21 | org.eclipse.cdt.make.core.autoBuildTarget 22 | all 23 | 24 | 25 | org.eclipse.cdt.make.core.buildArguments 26 | 27 | 28 | 29 | org.eclipse.cdt.make.core.buildCommand 30 | make 31 | 32 | 33 | org.eclipse.cdt.make.core.buildLocation 34 | ${workspace_loc:/SIMMProgrammer/Release} 35 | 36 | 37 | org.eclipse.cdt.make.core.cleanBuildTarget 38 | clean 39 | 40 | 41 | org.eclipse.cdt.make.core.contents 42 | org.eclipse.cdt.make.core.activeConfigSettings 43 | 44 | 45 | org.eclipse.cdt.make.core.enableAutoBuild 46 | false 47 | 48 | 49 | org.eclipse.cdt.make.core.enableCleanBuild 50 | true 51 | 52 | 53 | org.eclipse.cdt.make.core.enableFullBuild 54 | true 55 | 56 | 57 | org.eclipse.cdt.make.core.fullBuildTarget 58 | all 59 | 60 | 61 | org.eclipse.cdt.make.core.stopOnError 62 | true 63 | 64 | 65 | org.eclipse.cdt.make.core.useDefaultBuildCmd 66 | true 67 | 68 | 69 | 70 | 71 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 72 | full,incremental, 73 | 74 | 75 | 76 | 77 | 78 | org.eclipse.cdt.core.cnature 79 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 80 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 81 | de.innot.avreclipse.core.avrnature 82 | 83 | 84 | -------------------------------------------------------------------------------- /.settings/de.innot.avreclipse.core.prefs: -------------------------------------------------------------------------------- 1 | #Sat Mar 03 13:46:14 PST 2012 2 | avrtarget/ClockFrequency=16000000 3 | avrtarget/ExtRAMSize=0 4 | avrtarget/ExtendedRAM=false 5 | avrtarget/MCUType=at90usb646 6 | avrtarget/UseEEPROM=false 7 | avrtarget/UseExtendedRAMforHeap=true 8 | avrtarget/avrdude/BitBangDelay= 9 | avrtarget/avrdude/Bitclock= 10 | avrtarget/avrdude/EEPROMFile= 11 | avrtarget/avrdude/EEPROMFromConfig=true 12 | avrtarget/avrdude/FlashFile= 13 | avrtarget/avrdude/FlashFromConfig=true 14 | avrtarget/avrdude/Fuses/ByteValues=223\:208\:248 15 | avrtarget/avrdude/Fuses/FileName= 16 | avrtarget/avrdude/Fuses/MCUid=at90usb646 17 | avrtarget/avrdude/Fuses/UseFile=false 18 | avrtarget/avrdude/Fuses/Write=true 19 | avrtarget/avrdude/Locks/ByteValues=-1 20 | avrtarget/avrdude/Locks/FileName= 21 | avrtarget/avrdude/Locks/MCUid=at90usb646 22 | avrtarget/avrdude/Locks/UseFile=false 23 | avrtarget/avrdude/Locks/Write=false 24 | avrtarget/avrdude/NoChipErase=false 25 | avrtarget/avrdude/NoSigCheck=false 26 | avrtarget/avrdude/NoVerify=false 27 | avrtarget/avrdude/NoWrite=false 28 | avrtarget/avrdude/OtherOptions= 29 | avrtarget/avrdude/ProgrammerID=programmerconfig.1 30 | avrtarget/avrdude/UseCounter=false 31 | avrtarget/avrdude/WriteEEPROM=false 32 | avrtarget/avrdude/WriteFlash=true 33 | avrtarget/perConfig=false 34 | eclipse.preferences.version=1 35 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.13) 2 | enable_language(ASM) 3 | project(SIMMProgrammer) 4 | 5 | # Create a list of all source files common to all architectures 6 | set(SOURCES 7 | drivers/mcp23s17.c 8 | drivers/mcp23s17.h 9 | drivers/parallel_flash.c 10 | drivers/parallel_flash.h 11 | hal/board.h 12 | hal/gpio.h 13 | hal/parallel_bus.h 14 | hal/spi.h 15 | hal/usbcdc.h 16 | tests/simm_electrical_test.c 17 | tests/simm_electrical_test.h 18 | chip_id.h 19 | main.c 20 | led.h 21 | programmer_protocol.h 22 | simm_programmer.c 23 | simm_programmer.h 24 | util.h 25 | ) 26 | 27 | # Get hardware-specific source files 28 | if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "avr") 29 | include(hal/at90usb646/at90usb646_sources.cmake) 30 | elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "arm") 31 | include(hal/m258ke/m258ke_sources.cmake) 32 | else() 33 | message(FATAL_ERROR "unrecognized architecture for build") 34 | endif() 35 | 36 | # The actual executable, in ELF format 37 | add_executable(SIMMProgrammer.elf ${SOURCES} ${HWSOURCES}) 38 | 39 | # Common compiler options 40 | target_compile_options(SIMMProgrammer.elf PRIVATE 41 | -Wall -Os -ffunction-sections -fdata-sections 42 | ) 43 | set_property(TARGET SIMMProgrammer.elf PROPERTY C_STANDARD 99) 44 | 45 | # Common linker options 46 | target_link_options(SIMMProgrammer.elf PRIVATE 47 | -Wl,-Map,SIMMProgrammer.map -Wl,--gc-sections 48 | ) 49 | 50 | # Get hardware-specific options 51 | if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "avr") 52 | include(hal/at90usb646/at90usb646_options.cmake) 53 | elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "arm") 54 | include(hal/m258ke/m258ke_options.cmake) 55 | endif() 56 | -------------------------------------------------------------------------------- /SIMMProgrammer-AVRStudio.atsln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 11.00 3 | # AvrStudio Solution File, Format Version 11.00 4 | Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "SIMMProgrammer-AVRStudio", "SIMMProgrammer-AVRStudio.cproj", "{A831F317-AB11-4E59-8FCF-0E48824CE1BA}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|AVR = Debug|AVR 9 | Release|AVR = Release|AVR 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {A831F317-AB11-4E59-8FCF-0E48824CE1BA}.Debug|AVR.ActiveCfg = Debug|AVR 13 | {A831F317-AB11-4E59-8FCF-0E48824CE1BA}.Debug|AVR.Build.0 = Debug|AVR 14 | {A831F317-AB11-4E59-8FCF-0E48824CE1BA}.Release|AVR.ActiveCfg = Release|AVR 15 | {A831F317-AB11-4E59-8FCF-0E48824CE1BA}.Release|AVR.Build.0 = Release|AVR 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /chip_id.h: -------------------------------------------------------------------------------- 1 | /* 2 | * chip_id.h 3 | * 4 | * Created on: Dec 10, 2011 5 | * Author: Doug 6 | * 7 | * Copyright (C) 2011-2023 Doug Brown 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | * 22 | */ 23 | 24 | #ifndef CHIP_ID_H_ 25 | #define CHIP_ID_H_ 26 | 27 | #define SST_GREENLIANT 0xBF 28 | #define GLS29EE010 0x07 29 | #define GLS29SF020 0x24 30 | #define GLS29SF040 0x13 31 | #define SST39SF010A 0xB5 32 | #define SST39SF020A 0xB6 33 | #define SST39SF040 0xB7 34 | 35 | #define AMD 0x01 36 | #define AM29F040B 0xA4 37 | 38 | #endif /* CHIP_ID_H_ */ 39 | -------------------------------------------------------------------------------- /drivers/mcp23s17.h: -------------------------------------------------------------------------------- 1 | /* 2 | * mcp23s17.h 3 | * 4 | * Created on: Nov 25, 2011 5 | * Author: Doug 6 | * 7 | * Copyright (C) 2011-2023 Doug Brown 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | * 22 | */ 23 | 24 | #ifndef DRIVERS_MCP23S17_H_ 25 | #define DRIVERS_MCP23S17_H_ 26 | 27 | #include "../hal/spi.h" 28 | 29 | /// A few register defines. Ordinarily I wouldn't put these in the header file 30 | /// because users of this module shouldn't care...but I have had to do some 31 | /// optimizations with the AVR to bypass the hardware abstraction layer. 32 | #define MCP23S17_CONTROL_WRITE(address) (0x40 | (address << 1)) 33 | #define MCP23S17_CONTROL_READ(address) (0x40 | (address << 1) | 1) 34 | #define MCP23S17_IODIRA 0x00 35 | #define MCP23S17_IODIRB 0x01 36 | #define MCP23S17_IPOLA 0x02 37 | #define MCP23S17_IPOLB 0x03 38 | #define MCP23S17_GPINTENA 0x04 39 | #define MCP23S17_GPINTENB 0x05 40 | #define MCP23S17_DEFVALA 0x06 41 | #define MCP23S17_DEFVALB 0x07 42 | #define MCP23S17_INTCONA 0x08 43 | #define MCP23S17_INTCONB 0x09 44 | #define MCP23S17_IOCON 0x0A 45 | #define MCP23S17_IOCON_AGAIN 0x0B 46 | #define MCP23S17_GPPUA 0x0C 47 | #define MCP23S17_GPPUB 0x0D 48 | #define MCP23S17_INTFA 0x0E 49 | #define MCP23S17_INTFB 0x0F 50 | #define MCP23S17_INTCAPA 0x10 51 | #define MCP23S17_INTCAPB 0x11 52 | #define MCP23S17_GPIOA 0x12 53 | #define MCP23S17_GPIOB 0x13 54 | #define MCP23S17_OLATA 0x14 55 | #define MCP23S17_OLATB 0x15 56 | 57 | /// Struct representing a single MCP23S17 device 58 | typedef struct MCP23S17 59 | { 60 | /// The SPI device representing this MCP23S17 61 | SPIDevice spi; 62 | } MCP23S17; 63 | 64 | void MCP23S17_Init(MCP23S17 *mcp, GPIOPin resetPin); 65 | void MCP23S17_Begin(MCP23S17 *mcp); 66 | void MCP23S17_End(MCP23S17 *mcp); 67 | void MCP23S17_SetDDR(MCP23S17 *mcp, uint16_t ddr); 68 | uint16_t MCP23S17_DDR(MCP23S17 *mcp); 69 | void MCP23S17_SetOutputs(MCP23S17 *mcp, uint16_t data); 70 | uint16_t MCP23S17_Outputs(MCP23S17 *mcp); 71 | uint16_t MCP23S17_ReadInputs(MCP23S17 *mcp); 72 | void MCP23S17_SetPullups(MCP23S17 *mcp, uint16_t pullups); 73 | uint16_t MCP23S17_Pullups(MCP23S17 *mcp); 74 | 75 | #endif /* DRIVERS_MCP23S17_H_ */ 76 | -------------------------------------------------------------------------------- /drivers/parallel_flash.h: -------------------------------------------------------------------------------- 1 | /* 2 | * parallel_flash.h 3 | * 4 | * Created on: Nov 25, 2011 5 | * Author: Doug 6 | * 7 | * Copyright (C) 2011-2023 Doug Brown 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | * 22 | */ 23 | 24 | #ifndef DRIVERS_PARALLEL_FLASH_H_ 25 | #define DRIVERS_PARALLEL_FLASH_H_ 26 | 27 | #include "../hal/parallel_bus.h" 28 | 29 | /// The number of chips we are simultaneously addressing 30 | #define PARALLEL_FLASH_NUM_CHIPS 4 31 | 32 | /// Masks for functions that want a chip mask... 33 | #define IC1 (1 << 3) 34 | #define IC2 (1 << 2) 35 | #define IC3 (1 << 1) 36 | #define IC4 (1 << 0) 37 | #define ALL_CHIPS (IC1 | IC2 | IC3 | IC4) 38 | 39 | /// Holds info about the chip (retrieved with JEDEC standards) 40 | typedef struct ParallelFlashChipID 41 | { 42 | /// The manufacturer ID 43 | uint8_t manufacturer; 44 | /// The device ID 45 | uint8_t device; 46 | } ParallelFlashChipID; 47 | 48 | /// Type/layout of chips currently being addressed 49 | typedef enum ParallelFlashChipType 50 | { 51 | /// Four SST39SF040 chips, 512 KB each, for a total of 2 MB 52 | ParallelFlash_SST39SF040_x4, 53 | /// Four M29F160FB5AN6E2 chips, 2 MB each, in 8-bit mode, for a total of 8 MB 54 | ParallelFlash_M29F160FB5AN6E2_x4, 55 | } ParallelFlashChipType; 56 | 57 | /// Struct representing a group of identical erase sectors 58 | typedef struct ParallelFlashEraseSectorGroup 59 | { 60 | uint32_t count; 61 | uint32_t size; 62 | } ParallelFlashEraseSectorGroup; 63 | 64 | // Tells which type of flash chip we are communicating with 65 | void ParallelFlash_SetChipType(ParallelFlashChipType type); 66 | ParallelFlashChipType ParallelFlash_ChipType(void); 67 | 68 | // Reads a set of data from all 4 chips simultaneously 69 | void ParallelFlash_Read(uint32_t startAddress, uint32_t *buf, uint16_t len); 70 | 71 | // Does an unlock sequence on the chips requested 72 | void ParallelFlash_UnlockChips(uint8_t chipsMask); 73 | 74 | // Identifies all four chips 75 | void ParallelFlash_IdentifyChips(ParallelFlashChipID *chips); 76 | 77 | // Erases the chips/sectors requested 78 | void ParallelFlash_EraseChips(uint8_t chipsMask); 79 | bool ParallelFlash_EraseSectors(uint32_t address, uint32_t length, uint8_t chipsMask, uint8_t numEraseSectorGroups, ParallelFlashEraseSectorGroup const *eraseSectorGroups); 80 | 81 | // Writes a buffer to all 4 chips simultaneously (each uint32_t contains an 8-bit portion for each chip). 82 | // Optimized variant of this function if we know we're writing to all 4 chips simultaneously. 83 | // Allows us to bypass a lot of operations involving "chipsMask". 84 | void ParallelFlash_WriteAllChips(uint32_t startAddress, uint32_t const *buf, uint16_t len); 85 | 86 | // Writes a buffer to a mask of requested chips (each uint32_t contains an 8-bit portion for each chip). 87 | void ParallelFlash_WriteSomeChips(uint32_t startAddress, uint32_t const *buf, uint16_t len, uint8_t chipsMask); 88 | 89 | #endif /* DRIVERS_PARALLEL_FLASH_H_ */ 90 | -------------------------------------------------------------------------------- /hal/at90usb646/Descriptors.h: -------------------------------------------------------------------------------- 1 | /* 2 | LUFA Library 3 | Copyright (C) Dean Camera, 2011. 4 | 5 | dean [at] fourwalledcubicle [dot] com 6 | www.lufa-lib.org 7 | */ 8 | 9 | /* 10 | Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com) 11 | 12 | Permission to use, copy, modify, distribute, and sell this 13 | software and its documentation for any purpose is hereby granted 14 | without fee, provided that the above copyright notice appear in 15 | all copies and that both that the copyright notice and this 16 | permission notice and warranty disclaimer appear in supporting 17 | documentation, and that the name of the author not be used in 18 | advertising or publicity pertaining to distribution of the 19 | software without specific, written prior permission. 20 | 21 | The author disclaim all warranties with regard to this 22 | software, including all implied warranties of merchantability 23 | and fitness. In no event shall the author be liable for any 24 | special, indirect or consequential damages or any damages 25 | whatsoever resulting from loss of use, data or profits, whether 26 | in an action of contract, negligence or other tortious action, 27 | arising out of or in connection with the use or performance of 28 | this software. 29 | */ 30 | 31 | /** \file 32 | * 33 | * Header file for Descriptors.c. 34 | */ 35 | 36 | #ifndef _DESCRIPTORS_H_ 37 | #define _DESCRIPTORS_H_ 38 | 39 | /* Includes: */ 40 | #include 41 | 42 | #include "LUFA/Drivers/USB/USB.h" 43 | 44 | /* Macros: */ 45 | /** Endpoint number of the CDC device-to-host notification IN endpoint. */ 46 | #define CDC_NOTIFICATION_EPNUM 2 47 | 48 | /** Endpoint number of the CDC device-to-host data IN endpoint. */ 49 | #define CDC_TX_EPNUM 3 50 | 51 | /** Endpoint number of the CDC host-to-device data OUT endpoint. */ 52 | #define CDC_RX_EPNUM 4 53 | 54 | /** Size in bytes of the CDC device-to-host notification IN endpoint. */ 55 | #define CDC_NOTIFICATION_EPSIZE 8 56 | 57 | /** Size in bytes of the CDC data IN and OUT endpoints. */ 58 | #define CDC_TXRX_EPSIZE 64 59 | 60 | /* Type Defines: */ 61 | /** Type define for the device configuration descriptor structure. This must be defined in the 62 | * application code, as the configuration descriptor contains several sub-descriptors which 63 | * vary between devices, and which describe the device's usage to the host. 64 | */ 65 | typedef struct 66 | { 67 | USB_Descriptor_Configuration_Header_t Config; 68 | 69 | // CDC Command Interface 70 | USB_Descriptor_Interface_t CDC_CCI_Interface; 71 | USB_CDC_Descriptor_FunctionalHeader_t CDC_Functional_Header; 72 | USB_CDC_Descriptor_FunctionalACM_t CDC_Functional_ACM; 73 | USB_CDC_Descriptor_FunctionalUnion_t CDC_Functional_Union; 74 | USB_Descriptor_Endpoint_t CDC_NotificationEndpoint; 75 | 76 | // CDC Data Interface 77 | USB_Descriptor_Interface_t CDC_DCI_Interface; 78 | USB_Descriptor_Endpoint_t CDC_DataOutEndpoint; 79 | USB_Descriptor_Endpoint_t CDC_DataInEndpoint; 80 | } USB_Descriptor_Configuration_t; 81 | 82 | /* Function Prototypes: */ 83 | uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, 84 | const uint8_t wIndex, 85 | const void** const DescriptorAddress) 86 | ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(3); 87 | 88 | #endif 89 | 90 | -------------------------------------------------------------------------------- /hal/at90usb646/LUFA/CodeTemplates/DriverStubs/Buttons.h: -------------------------------------------------------------------------------- 1 | /* 2 | LUFA Library 3 | Copyright (C) Dean Camera, 2012. 4 | 5 | dean [at] fourwalledcubicle [dot] com 6 | www.lufa-lib.org 7 | */ 8 | 9 | /* 10 | Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) 11 | 12 | Permission to use, copy, modify, distribute, and sell this 13 | software and its documentation for any purpose is hereby granted 14 | without fee, provided that the above copyright notice appear in 15 | all copies and that both that the copyright notice and this 16 | permission notice and warranty disclaimer appear in supporting 17 | documentation, and that the name of the author not be used in 18 | advertising or publicity pertaining to distribution of the 19 | software without specific, written prior permission. 20 | 21 | The author disclaim all warranties with regard to this 22 | software, including all implied warranties of merchantability 23 | and fitness. In no event shall the author be liable for any 24 | special, indirect or consequential damages or any damages 25 | whatsoever resulting from loss of use, data or profits, whether 26 | in an action of contract, negligence or other tortious action, 27 | arising out of or in connection with the use or performance of 28 | this software. 29 | */ 30 | 31 | /* 32 | This is a stub driver header file, for implementing custom board 33 | layout hardware with compatible LUFA board specific drivers. If 34 | the library is configured to use the BOARD_USER board mode, this 35 | driver file should be completed and copied into the "/Board/" folder 36 | inside the application's folder. 37 | 38 | This stub is for the board-specific component of the LUFA Buttons driver, 39 | for the control of physical board-mounted GPIO pushbuttons. 40 | */ 41 | 42 | #ifndef __BUTTONS_USER_H__ 43 | #define __BUTTONS_USER_H__ 44 | 45 | /* Includes: */ 46 | // TODO: Add any required includes here 47 | 48 | /* Enable C linkage for C++ Compilers: */ 49 | #if defined(__cplusplus) 50 | extern "C" { 51 | #endif 52 | 53 | /* Preprocessor Checks: */ 54 | #if !defined(__INCLUDE_FROM_BUTTONS_H) 55 | #error Do not include this file directly. Include LUFA/Drivers/Board/Buttons.h instead. 56 | #endif 57 | 58 | /* Public Interface - May be used in end-application: */ 59 | /* Macros: */ 60 | /** Button mask for the first button on the board. */ 61 | #define BUTTONS_BUTTON1 // TODO: Add mask for first board button here 62 | 63 | /* Inline Functions: */ 64 | #if !defined(__DOXYGEN__) 65 | static inline void Buttons_Init(void) 66 | { 67 | // TODO: Initialize the appropriate port pins as an inputs here, with pull-ups 68 | } 69 | 70 | static inline void Buttons_Disable(void) 71 | { 72 | // TODO: Clear the appropriate port pins as high impedance inputs here 73 | } 74 | 75 | static inline uint8_t Buttons_GetStatus(void) ATTR_WARN_UNUSED_RESULT; 76 | static inline uint8_t Buttons_GetStatus(void) 77 | { 78 | // TODO: Return current button status here, debounced if required 79 | } 80 | #endif 81 | 82 | /* Disable C linkage for C++ Compilers: */ 83 | #if defined(__cplusplus) 84 | } 85 | #endif 86 | 87 | #endif 88 | 89 | -------------------------------------------------------------------------------- /hal/at90usb646/LUFA/CodeTemplates/DriverStubs/Joystick.h: -------------------------------------------------------------------------------- 1 | /* 2 | LUFA Library 3 | Copyright (C) Dean Camera, 2012. 4 | 5 | dean [at] fourwalledcubicle [dot] com 6 | www.lufa-lib.org 7 | */ 8 | 9 | /* 10 | Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) 11 | 12 | Permission to use, copy, modify, distribute, and sell this 13 | software and its documentation for any purpose is hereby granted 14 | without fee, provided that the above copyright notice appear in 15 | all copies and that both that the copyright notice and this 16 | permission notice and warranty disclaimer appear in supporting 17 | documentation, and that the name of the author not be used in 18 | advertising or publicity pertaining to distribution of the 19 | software without specific, written prior permission. 20 | 21 | The author disclaim all warranties with regard to this 22 | software, including all implied warranties of merchantability 23 | and fitness. In no event shall the author be liable for any 24 | special, indirect or consequential damages or any damages 25 | whatsoever resulting from loss of use, data or profits, whether 26 | in an action of contract, negligence or other tortious action, 27 | arising out of or in connection with the use or performance of 28 | this software. 29 | */ 30 | 31 | /* 32 | This is a stub driver header file, for implementing custom board 33 | layout hardware with compatible LUFA board specific drivers. If 34 | the library is configured to use the BOARD_USER board mode, this 35 | driver file should be completed and copied into the "/Board/" folder 36 | inside the application's folder. 37 | 38 | This stub is for the board-specific component of the LUFA Joystick 39 | driver, for a digital four-way (plus button) joystick. 40 | */ 41 | 42 | #ifndef __JOYSTICK_USER_H__ 43 | #define __JOYSTICK_USER_H__ 44 | 45 | /* Includes: */ 46 | // TODO: Add any required includes here 47 | 48 | /* Enable C linkage for C++ Compilers: */ 49 | #if defined(__cplusplus) 50 | extern "C" { 51 | #endif 52 | 53 | /* Preprocessor Checks: */ 54 | #if !defined(__INCLUDE_FROM_JOYSTICK_H) 55 | #error Do not include this file directly. Include LUFA/Drivers/Board/Joystick.h instead. 56 | #endif 57 | 58 | /* Public Interface - May be used in end-application: */ 59 | /* Macros: */ 60 | /** Mask for the joystick being pushed in the left direction. */ 61 | #define JOY_LEFT // TODO: Add mask to indicate joystick left position here 62 | 63 | /** Mask for the joystick being pushed in the right direction. */ 64 | #define JOY_RIGHT // TODO: Add mask to indicate joystick right position here 65 | 66 | /** Mask for the joystick being pushed in the upward direction. */ 67 | #define JOY_UP // TODO: Add mask to indicate joystick up position here 68 | 69 | /** Mask for the joystick being pushed in the downward direction. */ 70 | #define JOY_DOWN // TODO: Add mask to indicate joystick down position here 71 | 72 | /** Mask for the joystick being pushed inward. */ 73 | #define JOY_PRESS // TODO: Add mask to indicate joystick pressed position here 74 | 75 | /* Inline Functions: */ 76 | #if !defined(__DOXYGEN__) 77 | static inline void Joystick_Init(void) 78 | { 79 | // TODO: Initialize joystick port pins as inputs with pull-ups 80 | } 81 | 82 | static inline void Joystick_Disable(void) 83 | { 84 | // TODO: Clear the joystick pins as high impedance inputs here 85 | } 86 | 87 | static inline uint8_t Joystick_GetStatus(void) ATTR_WARN_UNUSED_RESULT; 88 | static inline uint8_t Joystick_GetStatus(void) 89 | { 90 | // TODO: Return current joystick position data which can be obtained by masking against the JOY_* macros 91 | } 92 | #endif 93 | 94 | /* Disable C linkage for C++ Compilers: */ 95 | #if defined(__cplusplus) 96 | } 97 | #endif 98 | 99 | #endif 100 | 101 | -------------------------------------------------------------------------------- /hal/at90usb646/LUFA/CodeTemplates/DriverStubs/LEDs.h: -------------------------------------------------------------------------------- 1 | /* 2 | LUFA Library 3 | Copyright (C) Dean Camera, 2012. 4 | 5 | dean [at] fourwalledcubicle [dot] com 6 | www.lufa-lib.org 7 | */ 8 | 9 | /* 10 | Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) 11 | 12 | Permission to use, copy, modify, distribute, and sell this 13 | software and its documentation for any purpose is hereby granted 14 | without fee, provided that the above copyright notice appear in 15 | all copies and that both that the copyright notice and this 16 | permission notice and warranty disclaimer appear in supporting 17 | documentation, and that the name of the author not be used in 18 | advertising or publicity pertaining to distribution of the 19 | software without specific, written prior permission. 20 | 21 | The author disclaim all warranties with regard to this 22 | software, including all implied warranties of merchantability 23 | and fitness. In no event shall the author be liable for any 24 | special, indirect or consequential damages or any damages 25 | whatsoever resulting from loss of use, data or profits, whether 26 | in an action of contract, negligence or other tortious action, 27 | arising out of or in connection with the use or performance of 28 | this software. 29 | */ 30 | 31 | /* 32 | This is a stub driver header file, for implementing custom board 33 | layout hardware with compatible LUFA board specific drivers. If 34 | the library is configured to use the BOARD_USER board mode, this 35 | driver file should be completed and copied into the "/Board/" folder 36 | inside the application's folder. 37 | 38 | This stub is for the board-specific component of the LUFA LEDs driver, 39 | for the LEDs (up to four) mounted on most development boards. 40 | */ 41 | 42 | #ifndef __LEDS_USER_H__ 43 | #define __LEDS_USER_H__ 44 | 45 | /* Includes: */ 46 | // TODO: Add any required includes here 47 | 48 | /* Enable C linkage for C++ Compilers: */ 49 | #if defined(__cplusplus) 50 | extern "C" { 51 | #endif 52 | 53 | /* Preprocessor Checks: */ 54 | #if !defined(__INCLUDE_FROM_LEDS_H) 55 | #error Do not include this file directly. Include LUFA/Drivers/Board/LEDS.h instead. 56 | #endif 57 | 58 | /* Public Interface - May be used in end-application: */ 59 | /* Macros: */ 60 | /** LED mask for the first LED on the board. */ 61 | #define LEDS_LED1 // TODO: Add mask for first board LED here 62 | 63 | /** LED mask for the second LED on the board. */ 64 | #define LEDS_LED2 // TODO: Add mask for second board LED here 65 | 66 | /** LED mask for the third LED on the board. */ 67 | #define LEDS_LED3 // TODO: Add mask for third board LED here 68 | 69 | /** LED mask for the fourth LED on the board. */ 70 | #define LEDS_LED4 // TODO: Add mask for fourth board LED here 71 | 72 | /** LED mask for all the LEDs on the board. */ 73 | #define LEDS_ALL_LEDS (LEDS_LED1 | LEDS_LED2 | LEDS_LED3 | LEDS_LED4) 74 | 75 | /** LED mask for none of the board LEDs. */ 76 | #define LEDS_NO_LEDS 0 77 | 78 | /* Inline Functions: */ 79 | #if !defined(__DOXYGEN__) 80 | static inline void LEDs_Init(void) 81 | { 82 | // TODO: Add code to initialize LED port pins as outputs here 83 | } 84 | 85 | static inline void LEDs_Disable(void) 86 | { 87 | // TODO: Clear the LED port pins as high impedance inputs here 88 | } 89 | 90 | static inline void LEDs_TurnOnLEDs(const uint8_t LEDMask) 91 | { 92 | // TODO: Add code to turn on LEDs given in the LEDMask mask here, leave others as-is 93 | } 94 | 95 | static inline void LEDs_TurnOffLEDs(const uint8_t LEDMask) 96 | { 97 | // TODO: Add code to turn off LEDs given in the LEDMask mask here, leave others as-is 98 | } 99 | 100 | static inline void LEDs_SetAllLEDs(const uint8_t LEDMask) 101 | { 102 | // TODO: Add code to turn on only LEDs given in the LEDMask mask here, all others off 103 | } 104 | 105 | static inline void LEDs_ChangeLEDs(const uint8_t LEDMask, const uint8_t ActiveMask) 106 | { 107 | // TODO: Add code to set the Leds in the given LEDMask to the status given in ActiveMask here 108 | } 109 | 110 | static inline void LEDs_ToggleLEDs(const uint8_t LEDMask) 111 | { 112 | // TODO: Add code to toggle the Leds in the given LEDMask, ignoring all others 113 | } 114 | 115 | static inline uint8_t LEDs_GetLEDs(void) ATTR_WARN_UNUSED_RESULT; 116 | static inline uint8_t LEDs_GetLEDs(void) 117 | { 118 | // TODO: Add code to return the current LEDs status' here which can be masked against LED_LED* macros 119 | } 120 | #endif 121 | 122 | /* Disable C linkage for C++ Compilers: */ 123 | #if defined(__cplusplus) 124 | } 125 | #endif 126 | 127 | #endif 128 | 129 | -------------------------------------------------------------------------------- /hal/at90usb646/LUFA/CodeTemplates/makefile_template.avr8: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dougg3/mac-rom-simm-programmer/87e074413c24a10ac9ac6eddd17e2dbc8793f40d/hal/at90usb646/LUFA/CodeTemplates/makefile_template.avr8 -------------------------------------------------------------------------------- /hal/at90usb646/LUFA/CodeTemplates/makefile_template.uc3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dougg3/mac-rom-simm-programmer/87e074413c24a10ac9ac6eddd17e2dbc8793f40d/hal/at90usb646/LUFA/CodeTemplates/makefile_template.uc3 -------------------------------------------------------------------------------- /hal/at90usb646/LUFA/CodeTemplates/makefile_template.xmega: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dougg3/mac-rom-simm-programmer/87e074413c24a10ac9ac6eddd17e2dbc8793f40d/hal/at90usb646/LUFA/CodeTemplates/makefile_template.xmega -------------------------------------------------------------------------------- /hal/at90usb646/LUFA/Common/Architectures.h: -------------------------------------------------------------------------------- 1 | /* 2 | LUFA Library 3 | Copyright (C) Dean Camera, 2012. 4 | 5 | dean [at] fourwalledcubicle [dot] com 6 | www.lufa-lib.org 7 | */ 8 | 9 | /* 10 | Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) 11 | 12 | Permission to use, copy, modify, distribute, and sell this 13 | software and its documentation for any purpose is hereby granted 14 | without fee, provided that the above copyright notice appear in 15 | all copies and that both that the copyright notice and this 16 | permission notice and warranty disclaimer appear in supporting 17 | documentation, and that the name of the author not be used in 18 | advertising or publicity pertaining to distribution of the 19 | software without specific, written prior permission. 20 | 21 | The author disclaim all warranties with regard to this 22 | software, including all implied warranties of merchantability 23 | and fitness. In no event shall the author be liable for any 24 | special, indirect or consequential damages or any damages 25 | whatsoever resulting from loss of use, data or profits, whether 26 | in an action of contract, negligence or other tortious action, 27 | arising out of or in connection with the use or performance of 28 | this software. 29 | */ 30 | 31 | /** \file 32 | * \brief Supported library architecture defines. 33 | * 34 | * \copydetails Group_Architectures 35 | * 36 | * \note Do not include this file directly, rather include the Common.h header file instead to gain this file's 37 | * functionality. 38 | */ 39 | 40 | /** \ingroup Group_Common 41 | * \defgroup Group_Architectures Hardware Architectures 42 | * \brief Supported library architecture defines. 43 | * 44 | * Architecture macros for selecting the desired target microcontroller architecture. One of these values should be 45 | * defined as the value of \c ARCH in the user project makefile via the \c -D compiler switch to GCC, to select the 46 | * target architecture. 47 | * 48 | * The selected architecture should remain consistent with the makefile \c ARCH value, which is used to select the 49 | * underlying driver source files for each architecture. 50 | * 51 | * @{ 52 | */ 53 | 54 | #ifndef __LUFA_ARCHITECTURES_H__ 55 | #define __LUFA_ARCHITECTURES_H__ 56 | 57 | /* Preprocessor Checks: */ 58 | #if !defined(__INCLUDE_FROM_COMMON_H) 59 | #error Do not include this file directly. Include LUFA/Common/Common.h instead to gain this functionality. 60 | #endif 61 | 62 | /* Public Interface - May be used in end-application: */ 63 | /* Macros: */ 64 | /** Selects the Atmel 8-bit AVR (AT90USB* and ATMEGA*U* chips) architecture. */ 65 | #define ARCH_AVR8 0 66 | 67 | /** Selects the Atmel 32-bit UC3 AVR (AT32UC3* chips) architecture. */ 68 | #define ARCH_UC3 1 69 | 70 | /** Selects the Atmel XMEGA AVR (ATXMEGA*U chips) architecture. */ 71 | #define ARCH_XMEGA 2 72 | 73 | #if !defined(__DOXYGEN__) 74 | #define ARCH_ ARCH_AVR8 75 | 76 | #if !defined(ARCH) 77 | #define ARCH ARCH_AVR8 78 | #endif 79 | #endif 80 | 81 | #endif 82 | 83 | /** @} */ 84 | 85 | -------------------------------------------------------------------------------- /hal/at90usb646/LUFA/Common/CompilerSpecific.h: -------------------------------------------------------------------------------- 1 | /* 2 | LUFA Library 3 | Copyright (C) Dean Camera, 2012. 4 | 5 | dean [at] fourwalledcubicle [dot] com 6 | www.lufa-lib.org 7 | */ 8 | 9 | /* 10 | Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) 11 | 12 | Permission to use, copy, modify, distribute, and sell this 13 | software and its documentation for any purpose is hereby granted 14 | without fee, provided that the above copyright notice appear in 15 | all copies and that both that the copyright notice and this 16 | permission notice and warranty disclaimer appear in supporting 17 | documentation, and that the name of the author not be used in 18 | advertising or publicity pertaining to distribution of the 19 | software without specific, written prior permission. 20 | 21 | The author disclaim all warranties with regard to this 22 | software, including all implied warranties of merchantability 23 | and fitness. In no event shall the author be liable for any 24 | special, indirect or consequential damages or any damages 25 | whatsoever resulting from loss of use, data or profits, whether 26 | in an action of contract, negligence or other tortious action, 27 | arising out of or in connection with the use or performance of 28 | this software. 29 | */ 30 | 31 | /** \file 32 | * \brief Compiler specific definitions for code optimization and correctness. 33 | * 34 | * \copydetails Group_CompilerSpecific 35 | * 36 | * \note Do not include this file directly, rather include the Common.h header file instead to gain this file's 37 | * functionality. 38 | */ 39 | 40 | /** \ingroup Group_Common 41 | * \defgroup Group_CompilerSpecific Compiler Specific Definitions 42 | * \brief Compiler specific definitions for code optimization and correctness. 43 | * 44 | * Compiler specific definitions to expose certain compiler features which may increase the level of code optimization 45 | * for a specific compiler, or correct certain issues that may be present such as memory barriers for use in conjunction 46 | * with atomic variable access. 47 | * 48 | * Where possible, on alternative compilers, these macros will either have no effect, or default to returning a sane value 49 | * so that they can be used in existing code without the need for extra compiler checks in the user application code. 50 | * 51 | * @{ 52 | */ 53 | 54 | #ifndef __LUFA_COMPILERSPEC_H__ 55 | #define __LUFA_COMPILERSPEC_H__ 56 | 57 | /* Preprocessor Checks: */ 58 | #if !defined(__INCLUDE_FROM_COMMON_H) 59 | #error Do not include this file directly. Include LUFA/Common/Common.h instead to gain this functionality. 60 | #endif 61 | 62 | /* Public Interface - May be used in end-application: */ 63 | /* Macros: */ 64 | #if defined(__GNUC__) || defined(__DOXYGEN__) 65 | /** Forces GCC to use pointer indirection (via the device's pointer register pairs) when accessing the given 66 | * struct pointer. In some cases GCC will emit non-optimal assembly code when accessing a structure through 67 | * a pointer, resulting in a larger binary. When this macro is used on a (non \c const) structure pointer before 68 | * use, it will force GCC to use pointer indirection on the elements rather than direct store and load 69 | * instructions. 70 | * 71 | * \param[in, out] StructPtr Pointer to a structure which is to be forced into indirect access mode. 72 | */ 73 | #define GCC_FORCE_POINTER_ACCESS(StructPtr) __asm__ __volatile__("" : "=b" (StructPtr) : "0" (StructPtr)) 74 | 75 | /** Forces GCC to create a memory barrier, ensuring that memory accesses are not reordered past the barrier point. 76 | * This can be used before ordering-critical operations, to ensure that the compiler does not re-order the resulting 77 | * assembly output in an unexpected manner on sections of code that are ordering-specific. 78 | */ 79 | #define GCC_MEMORY_BARRIER() __asm__ __volatile__("" ::: "memory"); 80 | 81 | /** Determines if the specified value can be determined at compile-time to be a constant value when compiling under GCC. 82 | * 83 | * \param[in] x Value to check compile-time constantness of. 84 | * 85 | * \return Boolean true if the given value is known to be a compile time constant, false otherwise. 86 | */ 87 | #define GCC_IS_COMPILE_CONST(x) __builtin_constant_p(x) 88 | #else 89 | #define GCC_FORCE_POINTER_ACCESS(StructPtr) 90 | #define GCC_MEMORY_BARRIER() 91 | #define GCC_IS_COMPILE_CONST(x) 0 92 | #endif 93 | 94 | #endif 95 | 96 | /** @} */ 97 | 98 | -------------------------------------------------------------------------------- /hal/at90usb646/LUFA/DoxygenPages/AboutLUFA.txt: -------------------------------------------------------------------------------- 1 | /** \file 2 | * 3 | * This file contains special DoxyGen information for the generation of the main page and other special 4 | * documentation pages. It is not a project source file. 5 | */ 6 | 7 | /** 8 | * \page Page_AboutLUFA About LUFA 9 | * 10 | * This section of the manual contains information about the library as a whole, including its supported targets, 11 | * past and planned changes, and links to other projects incorporating LUFA. 12 | * 13 | * Subsections: 14 | * \li \subpage Page_DeviceSupport - Current Device and Hardware Support 15 | * \li \subpage Page_Resources - LUFA and USB Related Resources 16 | * \li \subpage Page_ChangeLog - Project Changelog 17 | * \li \subpage Page_FutureChanges - Planned Changes to the Library 18 | * \li \subpage Page_LUFAPoweredProjects - Other Projects Using LUFA 19 | */ 20 | 21 | -------------------------------------------------------------------------------- /hal/at90usb646/LUFA/DoxygenPages/AlternativeStacks.txt: -------------------------------------------------------------------------------- 1 | /** \file 2 | * 3 | * This file contains special DoxyGen information for the generation of the main page and other special 4 | * documentation pages. It is not a project source file. 5 | */ 6 | 7 | /** 8 | * \page Page_AlternativeStacks Alternative USB AVR Stacks 9 | * 10 | * LUFA is not the only stack available for the USB AVRs, although it is perhaps the best (see \ref Page_WhyUseLUFA). 11 | * In the interests of completeness and user choice, other known USB AVR stacks are listed here. 12 | * 13 | * \section Sec_HardwareStacks Hardware USB AVR Stacks 14 | * These are the known alternative USB stacks which are designed for and run exclusively on the USB AVR series microcontrollers, 15 | * which contain on-chip USB controller hardware for maximum features and speed. 16 | * 17 | * - Name: Atmel USB AVR Stack (Atmel Inc.) \n 18 | * Cost: Free \n 19 | * License: Atmel Limited License (see Atmel download for details) \n 20 | * Website: http://atmel.com/dyn/products/app_notes.asp?family_id=607#USB \n 21 | * Description: This is the official Atmel USB AVR stack, for their 8-bit USB AVR lineup. Each series of 22 | * USB AVR is separated into a separate download stack, which is both AVR-GCC and IAR compatible. 23 | * 24 | * - Name: Dr. Stefan Salewski's AT90USB1287 Stack (Dr. Stefan Salewski) \n 25 | * Cost: Free \n 26 | * License: GPL \n 27 | * Website: http://www.ssalewski.de/AT90USB_firmware.html.en \n 28 | * Description: This is a GPL'd library specifically designed for the AT90USB1287, by Dr. Stefan Salewski, a 29 | * German Physicist. It compiles for AVR-GCC and can potentially be modified to work on other USB 30 | * AVR models. 31 | * 32 | * - Name: FreakUSB Stack (FreakLabs) \n 33 | * Cost: Free \n 34 | * License: Modified BSD \n 35 | * Website: http://freaklabs.org/index.php/FreakUSB-Open-Source-USB-Device-Stack.html \n 36 | * Description: An open source simple USB stack for a selection of the USB AVRs. Contains a sample class driver 37 | * for the CDC-ACM class, however other class driver implementations are also possible. 38 | * 39 | * - Name: PJRC Teensy Stack (Paul Stoffregen) \n 40 | * Cost: Free \n 41 | * License: BSD \n 42 | * Website: http://www.pjrc.com/teensy/usb_debug_only.html \n 43 | * Description: Not so much a complete stack as a collection of USB enabled demos, this library is specifically 44 | * designed for the PJRC Teensy line of USB AVRs, and thus may need to be modified for other USB AVR 45 | * chips. These minimal code samples shows the inner workings of the USB controller, without all the 46 | * abstraction present in most other USB AVR stacks. 47 | * 48 | * \section Sec_SoftwareStacks Software AVR Stacks 49 | * These are the known alternative USB stacks which can run on regular AVR models, lacking dedicated hardware USB controllers 50 | * via a bit-banged (emulated) version of the USB protocol. They are limited in their capabilities due to the cycles required 51 | * to be dedicated to managing the USB bus, but offer a cheap way to implement USB functionality into a design. 52 | * 53 | * - Name: AVR309: Software USB (Atmel) \n 54 | * Cost: Free \n 55 | * License: None Stated \n 56 | * Website: http://www.atmel.com/dyn/Products/app_notes.asp?family_id=607 \n 57 | * Description: Atmel's official software USB implementation, an Application Note containing work by Igor Cesko. This 58 | * is a minimal assembly-only implementation of software USB, providing HID functionality. Less compile 59 | * options than V-USB (see below). 60 | * 61 | * - Name: V-USB (Objective Development) \n 62 | * Cost: Free for some uses, see website for licensing \n 63 | * License: Dual GPL2/Custom \n 64 | * Website: http://www.obdev.at/products/vusb/index.html \n 65 | * Description: Well regarded and complete USB 1.1 software stack for several AVR models, implementing Low Speed HID. 66 | * Used in many commercial and non-commercial designs, with user-submitted projects available for viewing 67 | * on the company's website. Uses C language code mixed with assembly for time-critical sections. 68 | */ 69 | 70 | -------------------------------------------------------------------------------- /hal/at90usb646/LUFA/DoxygenPages/Author.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dougg3/mac-rom-simm-programmer/87e074413c24a10ac9ac6eddd17e2dbc8793f40d/hal/at90usb646/LUFA/DoxygenPages/Author.jpg -------------------------------------------------------------------------------- /hal/at90usb646/LUFA/DoxygenPages/BuildingLinkableLibraries.txt: -------------------------------------------------------------------------------- 1 | /** \file 2 | * 3 | * This file contains special DoxyGen information for the generation of the main page and other special 4 | * documentation pages. It is not a project source file. 5 | */ 6 | 7 | /** \page Page_BuildLibrary Building as a Linkable Library 8 | * 9 | * The LUFA library can be built as a proper linkable library (with the extention .a) under AVR-GCC, so that 10 | * the library does not need to be recompiled with each revision of a user project. Instructions for creating 11 | * a library from a given source tree can be found in the AVR-GCC user manual included in the WinAVR install 12 | * /Docs/ directory. 13 | * 14 | * However, building the library is not recommended, as the static (compile-time) options will be 15 | * unable to be changed without a recompilation of the LUFA code. Therefore, if the library is to be built 16 | * from the LUFA source, it should be made to be application-specific and compiled with the static options 17 | * that are required for each project (which should be recorded along with the library). 18 | * 19 | * Normal library use has the library components compiled in at the same point as the application code, as 20 | * demonstrated in the library demos and applications. This is the preferred method, as the library is recompiled 21 | * each time to ensure that all static options for a particular application are applied. 22 | */ 23 | 24 | -------------------------------------------------------------------------------- /hal/at90usb646/LUFA/DoxygenPages/CompilingApps.txt: -------------------------------------------------------------------------------- 1 | /** \file 2 | * 3 | * This file contains special DoxyGen information for the generation of the main page and other special 4 | * documentation pages. It is not a project source file. 5 | */ 6 | 7 | /** \page Page_CompilingApps Compiling the Demos, Bootloaders and Projects 8 | * 9 | * The following details how to compile the included LUFA demos, applications and bootloaders using AVR-GCC. 10 | * 11 | * \section Sec_Prerequisites Prerequisites 12 | * Before you can compile any of the LUFA library code or demos, you will need a recent distribution of avr-libc (1.6.2+) 13 | * and the AVR-GCC (4.2+) compiler. For Windows users, the best way to obtain these is the WinAVR project 14 | * (http://winavr.sourceforge.net) as this provides a single-file setup for everything required to compile your 15 | * own AVR projects. 16 | * 17 | * \section Sec_Compiling Compiling a LUFA Application 18 | * Compiling the LUFA demos, applications and/or bootloaders is very simple. LUFA comes with makefile scripts for 19 | * each individual demo, bootloader and project folder, as well as scripts in the /Demos/, /Bootloaders/, /Projects/ 20 | * and the LUFA root directory. This means that compilation can be started from any of the above directories, with 21 | * a build started from an upper directory in the directory structure executing build of all child directories under it. 22 | * This means that while a build inside a particular demo directory will build only that particular demo, a build stated 23 | * from the /Demos/ directory will build all LUFA demo projects sequentially. 24 | * 25 | * To build a project from the source via the command line, the command "make all" should be executed from the command line in the directory 26 | * of interest. To remove compiled files (including the binary output, all intermediately files and all diagnostic output 27 | * files), execute "make clean". Once a "make all" has been run and no errors were encountered, the resulting binary will 28 | * be located in the generated ".HEX" file. If your project makes use of pre-initialized EEPROM variables, the generated ".EEP" 29 | * file will contain the project's EEPROM data. 30 | */ 31 | -------------------------------------------------------------------------------- /hal/at90usb646/LUFA/DoxygenPages/DevelopingWithLUFA.txt: -------------------------------------------------------------------------------- 1 | /** \file 2 | * 3 | * This file contains special DoxyGen information for the generation of the main page and other special 4 | * documentation pages. It is not a project source file. 5 | */ 6 | 7 | /** 8 | * \page Page_DevelopingWithLUFA Developing With LUFA 9 | * 10 | * This section of the manual contains information on LUFA development, such as Getting Started information, 11 | * information on compile-time tuning of the library and other developer-related sections. 12 | * 13 | * Subsections: 14 | * \li \subpage Page_TokenSummary - Summary of Compile Time Tokens 15 | * \li \subpage Page_Migration - Migrating from an Older LUFA Version 16 | * \li \subpage Page_VIDPID - Allocated USB VID and PID Values 17 | * \li \subpage Page_BuildLibrary - Building as a Linkable Library 18 | * \li \subpage Page_WritingBoardDrivers - How to Write Custom Board Drivers 19 | * \li \subpage Page_SoftwareBootloaderStart - How to jump to the bootloader in software 20 | */ 21 | 22 | -------------------------------------------------------------------------------- /hal/at90usb646/LUFA/DoxygenPages/Donating.txt: -------------------------------------------------------------------------------- 1 | /** \file 2 | * 3 | * This file contains special DoxyGen information for the generation of the main page and other special 4 | * documentation pages. It is not a project source file. 5 | */ 6 | 7 | /** 8 | * \page Page_Donating Donating to Support This Project 9 | * 10 | * \image html Author.jpg "Dean Camera, LUFA Developer" 11 | * 12 | * I am a 22 year old University student studying for a double degree in Computer Science and Electronics Engineering. 13 | * The development and support of this library requires much effort from myself, as I am the sole developer, maintainer 14 | * and supporter. Please consider donating a small amount to support this and my future Open Source projects - All 15 | * donations are greatly appreciated. 16 | * 17 | * Note that commercial entities can remove the attribution portion of the LUFA license by a one-time fee - see 18 | * \ref Page_LicenseInfo for more details (Note: Please do NOT pay this in advance through the donation link below - 19 | * contact author for payment details.). 20 | * 21 | * \image html "http://www.pledgie.com/campaigns/6927.png?skin_name=chrome" 22 | * Donate to this project via PayPal - Thanks in Advance! 23 | */ 24 | 25 | -------------------------------------------------------------------------------- /hal/at90usb646/LUFA/DoxygenPages/FutureChanges.txt: -------------------------------------------------------------------------------- 1 | /** \file 2 | * 3 | * This file contains special DoxyGen information for the generation of the main page and other special 4 | * documentation pages. It is not a project source file. 5 | */ 6 | 7 | /** \page Page_FutureChanges Future Changes 8 | * 9 | * Below is a list of future changes which are proposed for the LUFA library, but not yet started/complete. 10 | * This gives an unordered list of future changes which may be available in future releases of the library. 11 | * If you have an item to add to this list, please contact the library author via email, the LUFA mailing list, 12 | * or post your suggestion as an enhancement request to the project bug tracker. 13 | * 14 | * Targeted for Future Releases: 15 | * - Code Features 16 | * -# Add hub support when in Host mode for multiple devices 17 | * -# Investigate virtual hubs when in device mode instead of composite devices 18 | * -# Change makefiles to allow for absolute LUFA location to be used 19 | * -# Re-add interrupt Pipe/Endpoint support 20 | * -# Add makefile includes to reduce boilerplate in user makefiles 21 | * -# Update stream APIs to use DMA transfers on supported architectures 22 | * -# Pull out third party libraries into a separate folder and reference them as required 23 | * -# Add a LUFA_YIELD macro for integration into a third-party RTOS 24 | * -# Abstract out Mass Storage byte send/receive to prevent low level API use in projects 25 | * -# Consider switch from endpoint numbers to full endpoint addresses to ease future architecture expansion 26 | * -# Fix HID report parser usage support for array types 27 | * -# Make HOST_DEVICE_SETTLE_DELAY_MS a global variable that can be changed 28 | * -# Add MANDATORY_EVENT_FUNCTIONS compile time option 29 | * -# Add watchdog support to the library and apps/bootloaders 30 | * -# Re-run USBIF test suite on all classes to formally verify operation 31 | * - Documentation/Support 32 | * -# Add detailed overviews of how each demo works 33 | * -# Add board overviews 34 | * -# Write LUFA tutorials 35 | * - Demos/Projects 36 | * -# Device/Host USB bridge 37 | * -# Finish incomplete demos and projects 38 | * -# Add class driver support for Test and Measurement class 39 | * -# Add class driver support for EEM class 40 | * -# Add class driver support for ECM class 41 | * -# Port all demos to multiple architectures 42 | * - Ports 43 | * -# Finish USB XMEGA port 44 | * -# Add AVR32 UC3C, UC3D and UC3L support 45 | * -# Atmel ARM7 series microcontrollers 46 | * -# Other (commercial) C compilers 47 | */ 48 | 49 | -------------------------------------------------------------------------------- /hal/at90usb646/LUFA/DoxygenPages/GettingStarted.txt: -------------------------------------------------------------------------------- 1 | /** \file 2 | * 3 | * This file contains special DoxyGen information for the generation of the main page and other special 4 | * documentation pages. It is not a project source file. 5 | */ 6 | 7 | /** \page Page_GettingStarted Getting Started 8 | * 9 | * Out of the box, LUFA contains a large number of pre-made class demos for you to test, experiment with and 10 | * ultimately build upon for your own projects. All the demos (where possible) come pre-configured to build and 11 | * run correctly on the AT90USB1287 AVR microcontroller, mounted on the Atmel USBKEY board and running at an 8MHz 12 | * master clock. This is due to two reasons; one, it is the hardware the author possesses, and two, it is the most 13 | * popular Atmel USB demonstration board to date. To learn how to reconfigure, recompile and program the included 14 | * LUFA applications using different settings, see the subsections below. 15 | * 16 | * Most of the included demos in the /Demos/ folder come in both ClassDriver and LowLevel varieties. If you are new 17 | * to LUFA, it is highly recommended that you look at the ClassDriver versions first, which use the pre-made USB 18 | * Class Drivers (\ref Group_USBClassDrivers) to simplify the use of the standard USB classes in user applications. 19 | * 20 | * For an overview of the included library applications, bootloaders and demos, see \ref Page_LibraryApps. 21 | * 22 | * Subsections: 23 | * \li \subpage Page_ConfiguringApps - How to Configure the Included Demos, Projects and Bootloaders 24 | * \li \subpage Page_CompilingApps - How to Compile the Included Demos, Projects and Bootloaders 25 | * \li \subpage Page_ProgrammingApps - How to Program an AVR with the Included Demos, Projects and Bootloaders 26 | */ 27 | 28 | -------------------------------------------------------------------------------- /hal/at90usb646/LUFA/DoxygenPages/Groups.txt: -------------------------------------------------------------------------------- 1 | /** \file 2 | * 3 | * This file contains special DoxyGen information for the generation of the main page and other special 4 | * documentation pages. It is not a project source file. 5 | */ 6 | 7 | /** \defgroup Group_BoardDrivers Board Drivers 8 | * 9 | * Functions, macros, variables, enums and types related to the control of physical board hardware. 10 | */ 11 | 12 | /** \defgroup Group_PeripheralDrivers On-chip Peripheral Drivers 13 | * 14 | * Functions, macros, variables, enums and types related to the control of AVR subsystems. 15 | */ 16 | 17 | /** \defgroup Group_MiscDrivers Miscellaneous Drivers 18 | * 19 | * Miscellaneous driver Functions, macros, variables, enums and types. 20 | */ 21 | 22 | /** \defgroup Group_PlatformDrivers System Platform Drivers 23 | * 24 | * Drivers relating to the general architecture platform, such as clock setup and interrupt management. 25 | */ 26 | 27 | /** \defgroup Group_PlatformDrivers_AVR8 AVR8 28 | * \ingroup Group_PlatformDrivers 29 | * 30 | * Drivers relating to the AVR8 architecture platform, such as clock setup and interrupt management. 31 | */ 32 | 33 | /** \defgroup Group_PlatformDrivers_XMEGA XMEGA 34 | * \ingroup Group_PlatformDrivers 35 | * 36 | * Drivers relating to the XMEGA architecture platform, such as clock setup and interrupt management. 37 | */ 38 | 39 | /** \defgroup Group_PlatformDrivers_UC3 UC3 40 | * \ingroup Group_PlatformDrivers 41 | * 42 | * Drivers relating to the UC3 architecture platform, such as clock setup and interrupt management. 43 | */ 44 | -------------------------------------------------------------------------------- /hal/at90usb646/LUFA/DoxygenPages/LUFA.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dougg3/mac-rom-simm-programmer/87e074413c24a10ac9ac6eddd17e2dbc8793f40d/hal/at90usb646/LUFA/DoxygenPages/LUFA.png -------------------------------------------------------------------------------- /hal/at90usb646/LUFA/DoxygenPages/LUFA_thumb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dougg3/mac-rom-simm-programmer/87e074413c24a10ac9ac6eddd17e2dbc8793f40d/hal/at90usb646/LUFA/DoxygenPages/LUFA_thumb.png -------------------------------------------------------------------------------- /hal/at90usb646/LUFA/DoxygenPages/LUFAvsAtmelStack.txt: -------------------------------------------------------------------------------- 1 | /** \file 2 | * 3 | * This file contains special DoxyGen information for the generation of the main page and other special 4 | * documentation pages. It is not a project source file. 5 | */ 6 | 7 | /** 8 | * \page Page_LUFAvsAtmelStack LUFA vs the Atmel 8-bit USB AVR Stack 9 | * 10 | * Atmel offers an official 8-bit USB AVR stack, which may be incorporated into user projects and products. As LUFA and the Atmel 11 | * stack aims to give roughly the same functionality to a design, it is often asked what advantages LUFA carries over the official 12 | * Atmel USB stack for the 8-bit USB AVRs. Below are just some of the advantages to choosing LUFA over the official Atmel stack. 13 | * 14 | * - Licensing: 15 | * LUFA is released under a very permissive MIT license (see \ref Page_LicenseInfo), while the Atmel stack carries several 16 | * restrictions as to how and where it can be used. LUFA's licensing should be suitable for both Commercial and Non-Commercial 17 | * entities alike. 18 | * 19 | * - Demos and Projects: 20 | * Unlike the Atmel stack, LUFA comes with many different Device and Host mode Demos and Projects ready to run out of the box. 21 | * Atmel favors separate downloads for each of their (small set) of USB AVR demos, which requires more time and offers less 22 | * to the end-user. LUFA also contains several open source Bootloaders, which can be modified as the user wishes to suit his or 23 | * her application, instead of being forced to use Atmel's single prebuilt (closed-source) DFU bootloader. 24 | * 25 | * - Central Library Code: 26 | * LUFA is designed to allow the central library core code to be shared amongst several projects, so long as the compiled object 27 | * files are cleaned between different projects. This is in direct contrast to the Atmel library, which is strongly coupled to the 28 | * project it is integrated with. Using LUFA allows for only one copy of the library core to be needed for all applications, and 29 | * makes updating the library used in all projects a trivial copy-and-paste process. 30 | * 31 | * - Clean API: 32 | * One of the main design goals of LUFA is to make the API easy to use. While LUFA is a fluid project which has undergone many 33 | * API improvements, the API is arguably much nicer to use and easier to understand than the equivalent Atmel stack code. LUFA's 34 | * API is also more complete than the Atmel stack, and contains many features to speed up application development. 35 | * 36 | * - Full Hardware Support: 37 | * LUFA supports the full range of Atmel's USB AVR microcontrollers (see \ref Page_DeviceSupport), with porting between chips being 38 | * as simple as a single compile switch in many cases. Atmel's stack requires different libraries to be used based on the USB AVR 39 | * microcontroller series, complicating the process of moving between USB AVR models. In addition, LUFA contains drivers for all the 40 | * hardware contained on Atmel's USB AVR based boards, so you can get started quickly and easily. 41 | * 42 | * - Better Library Support: 43 | * As many people are now using LUFA, there is a community being built around it. You can get answers to your LUFA related questions 44 | * quickly by either emailing the library author (subject to author's schedule) or by posting to the official LUFA support mailing list. 45 | * 46 | * - More Compact Code: 47 | * LUFA is written from the ground up to compile optimally, using clean code and good design. Two demos giving the same functionality - 48 | * the LUFA Low Level API Mouse Demo vs. the Atmel AVR270 HID Mouse application note shows LUFA to be the clear size winner *. 49 | * 50 | * * LUFA Low Level Mouse Demo: 3510 bytes, Atmel AVR270 Mouse Application Note: 4222 bytes, using an identical build environment. 51 | */ 52 | 53 | -------------------------------------------------------------------------------- /hal/at90usb646/LUFA/DoxygenPages/LibraryResources.txt: -------------------------------------------------------------------------------- 1 | /** \file 2 | * 3 | * This file contains special DoxyGen information for the generation of the main page and other special 4 | * documentation pages. It is not a project source file. 5 | */ 6 | 7 | /** 8 | * \page Page_Resources Library Resources 9 | * 10 | * \section Sec_UnofficialResources Unofficial Resources 11 | * Unofficial Russian LUFA documentation translation: http://microsin.ru/Download.cnt/doc/LUFA/ \n 12 | * 13 | * \section Sec_ProjectPages LUFA Related Webpages 14 | * Project Homepage: http://www.lufa-lib.org \n 15 | * Commercial Licenses: http://www.lufa-lib.org/license \n 16 | * Author's Website: http://www.fourwalledcubicle.com \n 17 | * Development Blog: http://www.fourwalledcubicle.com/blog \n 18 | * 19 | * \section Sec_ProjectHelp Assistance With LUFA 20 | * Discussion Group: http://www.lufa-lib.org/support \n 21 | * Author's Email: dean [at] fourwalledcubicle [dot] com \n 22 | * 23 | * \section Sec_InDevelopment Latest In-Development Source Code 24 | * Issue Tracker: http://www.lufa-lib.org/tracker \n 25 | * SVN Access: http://www.lufa-lib.org/svn \n 26 | * GIT Access: http://www.lufa-lib.org/git \n 27 | * Latest Repository Source Archive: http://www.lufa-lib.org/latest-archive \n 28 | * Commit RSS Feed: http://www.lufa-lib.org/rss \n 29 | * 30 | * \section Sec_USBResources USB Resources 31 | * USB-IF Website: http://www.usb.org \n 32 | */ 33 | 34 | -------------------------------------------------------------------------------- /hal/at90usb646/LUFA/DoxygenPages/LicenseInfo.txt: -------------------------------------------------------------------------------- 1 | /** \file 2 | * 3 | * This file contains special DoxyGen information for the generation of the main page and other special 4 | * documentation pages. It is not a project source file. 5 | */ 6 | 7 | /** 8 | * \page Page_LicenseInfo Source Code License 9 | * 10 | * The LUFA library is currently released under the MIT license, included below. 11 | * 12 | * Commercial entities can opt out of the public disclosure clause in this license 13 | * for a one-time US$1500 payment. This provides a non-exclusive modified MIT licensed which 14 | * allows for the free use of the LUFA library, bootloaders and (where the sole copyright 15 | * is attributed to Dean Camera) demos without public disclosure within an organization, in 16 | * addition to three free hours of consultation with the library author, and priority support. 17 | * Please visit the Commercial License link on \ref Page_Resources for more information on 18 | * ordering a commercial license for your company. 19 | * 20 | * \verbinclude License.txt 21 | */ 22 | 23 | -------------------------------------------------------------------------------- /hal/at90usb646/LUFA/DoxygenPages/MainPage.txt: -------------------------------------------------------------------------------- 1 | /** \file 2 | * 3 | * This file contains special DoxyGen information for the generation of the main page and other special 4 | * documentation pages. It is not a project source file. 5 | */ 6 | 7 | /** 8 | * \mainpage 9 | * 10 | * \image html LUFA.png 11 | *
Logo design by Studio Monsoon Photography
12 | * \n 13 | *
http://www.lufa-lib.org
14 | * \n 15 | * 16 | * LUFA is donationware. For author and donation information, see \ref Page_Donating. 17 | * 18 | * LUFA is an open-source USB library for the USB-enabled AVR microcontrollers, released under the MIT license (see \ref Page_LicenseInfo). 19 | * It supports a large number of USB AVR models and boards (see \ref Page_DeviceSupport). It is designed to provide an easy to use, 20 | * feature rich framework for the development of USB peripherals and hosts. 21 | * 22 | * LUFA focuses on the microcontroller side of USB development only; it includes no PC host USB driver development facilities - other projects 23 | * such as the Windows Driver Development Kit, Windows USB Device Mode Framework and libusb may be of interest for developing custom OS drivers. 24 | * While custom USB devices can be made with LUFA using such tools, the included demos all use the inbuilt OS drivers for each USB class for 25 | * simplicity. 26 | * 27 | * The library is currently in a stable release, suitable for download and incorporation into user projects for 28 | * both host and device modes. For information about the project progression, see the blog link at \ref Page_Resources. 29 | * 30 | * LUFA is written specifically for the free AVR-GCC compiler, and uses several GCC-only extensions to make the 31 | * library API more streamlined and robust. You can download AVR-GCC for free in a convenient windows package, 32 | * from the the WinAVR website (see \ref Page_Resources). 33 | * 34 | * The only required AVR peripherals for LUFA is the USB controller itself and interrupts - LUFA does not require the use of the 35 | * microcontroller's timers or other hardware, leaving more hardware to the application developer. 36 | * 37 | * Accompanying LUFA in the download package is a set of example demo applications, plus several Bootloaders of different classes 38 | * and open source LUFA powered projects. 39 | * 40 | * Subsections: 41 | * \li \subpage Page_WhyUseLUFA - What are the advantages of using LUFA? 42 | * \li \subpage Page_LUFAvsAtmelStack - How does LUFA compare to the Atmel USB AVR stack? 43 | * \li \subpage Page_AlternativeStacks - Alternative USB AVR Stacks 44 | * \li \subpage Page_LicenseInfo - Project source license and commercial use information 45 | * \li \subpage Page_Donating - Donating to support this project 46 | * \li \subpage Page_LibraryApps - Overview of included Demos, Bootloaders and Projects 47 | */ 48 | 49 | -------------------------------------------------------------------------------- /hal/at90usb646/LUFA/DoxygenPages/ProgrammingApps.txt: -------------------------------------------------------------------------------- 1 | /** \file 2 | * 3 | * This file contains special DoxyGen information for the generation of the main page and other special 4 | * documentation pages. It is not a project source file. 5 | */ 6 | 7 | /** \page Page_ProgrammingApps Programming an Application into a USB AVR 8 | * 9 | * Once you have built an application, you will need a way to program in the resulting ".HEX" file (and, if your 10 | * application uses EEPROM variables with initial values, also a ".EEP" file) into your USB AVR. Normally, the 11 | * reprogramming of an AVR device must be performed using a special piece of programming hardware, through one of the 12 | * supported AVR programming protocols - ISP, HVSP, HVPP, JTAG or dW. This can be done through a custom programmer, 13 | * a third party programmer, or an official Atmel AVR tool - for more information, see the Atmel.com website. 14 | * 15 | * Alternatively, you can use the bootloader. From the Atmel factory, each USB AVR comes preloaded with the Atmel 16 | * DFU (Device Firmware Update) class bootloader, a small piece of AVR firmware which allows the remainder of the 17 | * AVR to be programmed through a non-standard interface such as the serial USART port, SPI, or (in this case) USB. 18 | * Bootloaders have the advantage of not requiring any special hardware for programming, and cannot usually be erased 19 | * or broken without an external programming device. They have disadvantages however; they cannot change the fuses of 20 | * the AVR (special configuration settings that control the operation of the chip itself) and a small portion of the 21 | * AVR's FLASH program memory must be reserved to contain the bootloader firmware, and thus cannot be used by the 22 | * loaded application. Atmel's DFU bootloader is either 4KB (for the smaller USB AVRs) or 8KB (for the larger USB AVRs). 23 | * 24 | * If you wish to use the DFU bootloader to program in your application, refer to your DFU programmer's documentation. 25 | * Atmel provides a free utility called FLIP which is USB AVR compatible, and an open source (Linux compatible) 26 | * alternative exists called "dfu-programmer". 27 | */ 28 | -------------------------------------------------------------------------------- /hal/at90usb646/LUFA/DoxygenPages/SoftwareBootloaderJump.txt: -------------------------------------------------------------------------------- 1 | /** \file 2 | * 3 | * This file contains special DoxyGen information for the generation of the main page and other special 4 | * documentation pages. It is not a project source file. 5 | */ 6 | 7 | /** 8 | * \page Page_SoftwareBootloaderStart Entering the Bootloader via Software 9 | * 10 | * A common requirement of many applications is the ability to jump to the programmed bootloader of a chip 11 | * on demand, via the code's firmware (i.e. not as a result of any physical user interaction with the 12 | * hardware). This might be required because the device does not have any physical user input, or simply 13 | * just to streamline the device upgrade process on the host PC. 14 | * 15 | * The following C code snippets may be used to enter the bootloader upon request by the user application. 16 | * By using the watchdog to physically reset the controller, it is ensured that all system hardware is 17 | * completely reset to their defaults before the bootloader is run. This is important; since bootloaders 18 | * are written to occupy a very limited space, they usually make assumptions about the register states based 19 | * on the default values after a hard-reset of the chip. 20 | * 21 | * \section Sec_SoftareBootAVR8 AVR8 Architecture 22 | * The following software bootloader jump code is written for the AVR8 architecture. 23 | * 24 | * \code 25 | * #include 26 | * #include 27 | * #include 28 | * 29 | * #include 30 | * #include 31 | * 32 | * uint32_t Boot_Key ATTR_NO_INIT; 33 | * 34 | * #define MAGIC_BOOT_KEY 0xDC42ACCA 35 | * #define BOOTLOADER_START_ADDRESS (FLASH_SIZE_BYTES - BOOTLOADER_SEC_SIZE_BYTES) 36 | * 37 | * void Bootloader_Jump_Check(void) ATTR_INIT_SECTION(3); 38 | * void Bootloader_Jump_Check(void) 39 | * { 40 | * // If the reset source was the bootloader and the key is correct, clear it and jump to the bootloader 41 | * if ((MCUSR & (1 << WDRF)) && (Boot_Key == MAGIC_BOOT_KEY)) 42 | * { 43 | * Boot_Key = 0; 44 | * ((void (*)(void))BOOTLOADER_START_ADDRESS)(); 45 | * } 46 | * } 47 | * 48 | * void Jump_To_Bootloader(void) 49 | * { 50 | * // If USB is used, detach from the bus and reset it 51 | * USB_Disable(); 52 | * 53 | * // Disable all interrupts 54 | * cli(); 55 | * 56 | * // Wait two seconds for the USB detachment to register on the host 57 | * Delay_MS(2000); 58 | * 59 | * // Set the bootloader key to the magic value and force a reset 60 | * Boot_Key = MAGIC_BOOT_KEY; 61 | * wdt_enable(WDTO_250MS); 62 | * for (;;); 63 | * } 64 | * \endcode 65 | * 66 | * Note that the bootloader magic key can be any arbitrary value. The FLASH_SIZE_BYTES and 67 | * BOOTLOADER_SEC_SIZE_BYTES tokens should be replaced with the total flash size of the AVR 68 | * in bytes, and the allocated size of the bootloader section for the target AVR. 69 | * 70 | */ 71 | 72 | -------------------------------------------------------------------------------- /hal/at90usb646/LUFA/DoxygenPages/WhyUseLUFA.txt: -------------------------------------------------------------------------------- 1 | /** \file 2 | * 3 | * This file contains special DoxyGen information for the generation of the main page and other special 4 | * documentation pages. It is not a project source file. 5 | */ 6 | 7 | /** 8 | * \page Page_WhyUseLUFA Why Use LUFA? 9 | * 10 | * The LUFA Library has many advantages over implementing the code required to drive the USB AVRs directly. 11 | * It is much more preferable to incorporate LUFA into your existing projects - or even make a new project 12 | * using LUFA - than it is to start from scratch and use the USB AVR registers directly. Some of these reasons 13 | * are: 14 | * 15 | * - Portability: 16 | * The LUFA stack is designed to run (at some capacity) on the entire Atmel range of USB AVRs, regardless of the 17 | * exact USB controller revision used. If you decide to implement your own USB stack, you will either need to 18 | * code around the differences between each USB AVR controller's implementation between different chip models, or 19 | * require your code to run on only one specific USB AVR model series. 20 | * 21 | * - Speed of Development: 22 | * LUFA ships with a wide range of pre-made demos, bootloaders and projects for you to try, learn and extend. Each 23 | * of these demos are tested (where possible) across as many USB AVRs and Operating Systems as possible, to ensure 24 | * that they work under as many conditions as possible. In addition, there are inbuilt class drivers for several of 25 | * the USB classes which you can make use of in your projects with minimal effort. 26 | * 27 | * - Maintainability: 28 | * As LUFA takes care of much of the USB implementation, you can be left to focusing on your actual project's 29 | * functionality, rather than being held back developing and debugging the USB stack code. Since LUFA uses clear APIs 30 | * for USB development, your code will be more readable than if it had the low level USB stack code integrated into 31 | * it directly. Updating the LUFA library is a simple folder-replacement and gives new features and bug fixes in 32 | * seconds each time a new release is made. 33 | * 34 | * - Size: 35 | * Not just requiring less code to make complex USB devices, LUFA is written to compile down as much as possible into 36 | * optimal code, to occupy only a small space for its feature set. 37 | * 38 | * - Support: 39 | * Since many people are now using LUFA in their own projects, you can take advantage of other's knowledge when you run 40 | * into difficulties or need some advice. In addition, you can also email the library author to receive personalized 41 | * support when you need it (subject to author's schedule). 42 | */ 43 | 44 | -------------------------------------------------------------------------------- /hal/at90usb646/LUFA/DoxygenPages/WritingBoardDrivers.txt: -------------------------------------------------------------------------------- 1 | /** \file 2 | * 3 | * This file contains special DoxyGen information for the generation of the main page and other special 4 | * documentation pages. It is not a project source file. 5 | */ 6 | 7 | /** \page Page_WritingBoardDrivers Writing LUFA Board Drivers 8 | * 9 | * LUFA ships with several basic pre-made board drivers, to control hardware present on the supported board 10 | * hardware - such as Dataflash ICs, LEDs, Joysticks, or other hardware peripherals. When compiling an application 11 | * which makes use of one or more board drivers located in LUFA/Drivers/Board, you must also indicate what board 12 | * hardware you are using in your project makefile. This is done by defining the BOARD macro using the -D switch 13 | * passed to the compiler, with a constant of BOARD_{Name}. For example -DBOARD=BOARD_USBKEY instructs the 14 | * compiler to use the USBKEY board hardware drivers. 15 | * 16 | * If your application does not use *any* board level drivers, you can omit the definition of the BOARD macro. 17 | * However, some users may wish to write their own custom board hardware drivers which are to remain compatible 18 | * with the LUFA hardware API. To do this, the BOARD macro should be defined to the value BOARD_USER. This indicates 19 | * that the board level drivers should be located in a folder named "Board" located inside the application's folder. 20 | * 21 | * When used, the driver stub files located in the LUFA/CodeTemplates/DriverStubs folder should be copied to the user 22 | * Board/ directory, and fleshed out to include the values and code needed to control the custom board hardware. Once 23 | * done, the existing LUFA board level APIs (accessed in the regular LUFA/Drivers/Board/ folder) will redirect to the 24 | * user board drivers, maintaining code compatibility and allowing for a different board to be selected through the 25 | * project makefile with no code changes. 26 | */ 27 | 28 | -------------------------------------------------------------------------------- /hal/at90usb646/LUFA/DoxygenPages/footer.htm: -------------------------------------------------------------------------------- 1 | LUFA Project Page | Support Mailing List | Donate | Four Walled Cubicle - LUFA, the Lightweight USB Framework for AVRs -------------------------------------------------------------------------------- /hal/at90usb646/LUFA/Drivers/USB/Class/CDCClass.h: -------------------------------------------------------------------------------- 1 | /* 2 | LUFA Library 3 | Copyright (C) Dean Camera, 2012. 4 | 5 | dean [at] fourwalledcubicle [dot] com 6 | www.lufa-lib.org 7 | */ 8 | 9 | /* 10 | Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) 11 | 12 | Permission to use, copy, modify, distribute, and sell this 13 | software and its documentation for any purpose is hereby granted 14 | without fee, provided that the above copyright notice appear in 15 | all copies and that both that the copyright notice and this 16 | permission notice and warranty disclaimer appear in supporting 17 | documentation, and that the name of the author not be used in 18 | advertising or publicity pertaining to distribution of the 19 | software without specific, written prior permission. 20 | 21 | The author disclaim all warranties with regard to this 22 | software, including all implied warranties of merchantability 23 | and fitness. In no event shall the author be liable for any 24 | special, indirect or consequential damages or any damages 25 | whatsoever resulting from loss of use, data or profits, whether 26 | in an action of contract, negligence or other tortious action, 27 | arising out of or in connection with the use or performance of 28 | this software. 29 | */ 30 | 31 | /** \file 32 | * \brief Master include file for the library USB CDC-ACM Class driver. 33 | * 34 | * Master include file for the library USB CDC Class driver, for both host and device modes, where available. 35 | * 36 | * This file should be included in all user projects making use of this optional class driver, instead of 37 | * including any headers in the USB/ClassDriver/Device, USB/ClassDriver/Host or USB/ClassDriver/Common subdirectories. 38 | */ 39 | 40 | /** \ingroup Group_USBClassDrivers 41 | * \defgroup Group_USBClassCDC CDC-ACM (Virtual Serial) Class Driver 42 | * 43 | * \section Sec_Dependencies Module Source Dependencies 44 | * The following files must be built with any user project that uses this module: 45 | * - LUFA/Drivers/USB/Class/Device/CDCClassDevice.c (Makefile source module name: LUFA_SRC_USBCLASS) 46 | * - LUFA/Drivers/USB/Class/Host/CDCClassHost.c (Makefile source module name: LUFA_SRC_USBCLASS) 47 | * 48 | * \section Sec_ModDescription Module Description 49 | * CDC Class Driver module. This module contains an internal implementation of the USB CDC-ACM class Virtual Serial 50 | * Ports, for both Device and Host USB modes. User applications can use this class driver instead of implementing the 51 | * CDC class manually via the low-level LUFA APIs. 52 | * 53 | * This module is designed to simplify the user code by exposing only the required interface needed to interface with 54 | * Hosts or Devices using the USB CDC Class. 55 | * 56 | * @{ 57 | */ 58 | 59 | #ifndef _CDC_CLASS_H_ 60 | #define _CDC_CLASS_H_ 61 | 62 | /* Macros: */ 63 | #define __INCLUDE_FROM_USB_DRIVER 64 | #define __INCLUDE_FROM_CDC_DRIVER 65 | 66 | /* Includes: */ 67 | #include "../Core/USBMode.h" 68 | 69 | #if defined(USB_CAN_BE_DEVICE) 70 | #include "Device/CDCClassDevice.h" 71 | #endif 72 | 73 | #if defined(USB_CAN_BE_HOST) 74 | #include "Host/CDCClassHost.h" 75 | #endif 76 | 77 | #endif 78 | 79 | /** @} */ 80 | 81 | -------------------------------------------------------------------------------- /hal/at90usb646/LUFA/Drivers/USB/Core/AVR8/Device_AVR8.c: -------------------------------------------------------------------------------- 1 | /* 2 | LUFA Library 3 | Copyright (C) Dean Camera, 2012. 4 | 5 | dean [at] fourwalledcubicle [dot] com 6 | www.lufa-lib.org 7 | */ 8 | 9 | /* 10 | Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) 11 | 12 | Permission to use, copy, modify, distribute, and sell this 13 | software and its documentation for any purpose is hereby granted 14 | without fee, provided that the above copyright notice appear in 15 | all copies and that both that the copyright notice and this 16 | permission notice and warranty disclaimer appear in supporting 17 | documentation, and that the name of the author not be used in 18 | advertising or publicity pertaining to distribution of the 19 | software without specific, written prior permission. 20 | 21 | The author disclaim all warranties with regard to this 22 | software, including all implied warranties of merchantability 23 | and fitness. In no event shall the author be liable for any 24 | special, indirect or consequential damages or any damages 25 | whatsoever resulting from loss of use, data or profits, whether 26 | in an action of contract, negligence or other tortious action, 27 | arising out of or in connection with the use or performance of 28 | this software. 29 | */ 30 | 31 | #define __INCLUDE_FROM_USB_DRIVER 32 | #include "../USBMode.h" 33 | 34 | #if defined(USB_CAN_BE_DEVICE) 35 | 36 | #include "../Device.h" 37 | 38 | void USB_Device_SendRemoteWakeup(void) 39 | { 40 | if (!(USB_Options & USB_OPT_MANUAL_PLL)) 41 | { 42 | USB_PLL_On(); 43 | while (!(USB_PLL_IsReady())); 44 | } 45 | 46 | USB_CLK_Unfreeze(); 47 | 48 | UDCON |= (1 << RMWKUP); 49 | while (UDCON & (1 << RMWKUP)); 50 | } 51 | 52 | #endif 53 | 54 | -------------------------------------------------------------------------------- /hal/at90usb646/LUFA/Drivers/USB/Core/AVR8/Endpoint_AVR8.c: -------------------------------------------------------------------------------- 1 | /* 2 | LUFA Library 3 | Copyright (C) Dean Camera, 2012. 4 | 5 | dean [at] fourwalledcubicle [dot] com 6 | www.lufa-lib.org 7 | */ 8 | 9 | /* 10 | Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) 11 | 12 | Permission to use, copy, modify, distribute, and sell this 13 | software and its documentation for any purpose is hereby granted 14 | without fee, provided that the above copyright notice appear in 15 | all copies and that both that the copyright notice and this 16 | permission notice and warranty disclaimer appear in supporting 17 | documentation, and that the name of the author not be used in 18 | advertising or publicity pertaining to distribution of the 19 | software without specific, written prior permission. 20 | 21 | The author disclaim all warranties with regard to this 22 | software, including all implied warranties of merchantability 23 | and fitness. In no event shall the author be liable for any 24 | special, indirect or consequential damages or any damages 25 | whatsoever resulting from loss of use, data or profits, whether 26 | in an action of contract, negligence or other tortious action, 27 | arising out of or in connection with the use or performance of 28 | this software. 29 | */ 30 | 31 | #define __INCLUDE_FROM_USB_DRIVER 32 | #include "../USBMode.h" 33 | 34 | #if defined(USB_CAN_BE_DEVICE) 35 | 36 | #include "../Endpoint.h" 37 | 38 | #if !defined(FIXED_CONTROL_ENDPOINT_SIZE) 39 | uint8_t USB_Device_ControlEndpointSize = ENDPOINT_CONTROLEP_DEFAULT_SIZE; 40 | #endif 41 | 42 | bool Endpoint_ConfigureEndpoint_Prv(const uint8_t Number, 43 | const uint8_t UECFG0XData, 44 | const uint8_t UECFG1XData) 45 | { 46 | #if defined(CONTROL_ONLY_DEVICE) || defined(ORDERED_EP_CONFIG) 47 | Endpoint_SelectEndpoint(Number); 48 | Endpoint_EnableEndpoint(); 49 | 50 | UECFG1X = 0; 51 | UECFG0X = UECFG0XData; 52 | UECFG1X = UECFG1XData; 53 | 54 | return Endpoint_IsConfigured(); 55 | #else 56 | for (uint8_t EPNum = Number; EPNum < ENDPOINT_TOTAL_ENDPOINTS; EPNum++) 57 | { 58 | uint8_t UECFG0XTemp; 59 | uint8_t UECFG1XTemp; 60 | uint8_t UEIENXTemp; 61 | 62 | Endpoint_SelectEndpoint(EPNum); 63 | 64 | if (EPNum == Number) 65 | { 66 | UECFG0XTemp = UECFG0XData; 67 | UECFG1XTemp = UECFG1XData; 68 | UEIENXTemp = 0; 69 | } 70 | else 71 | { 72 | UECFG0XTemp = UECFG0X; 73 | UECFG1XTemp = UECFG1X; 74 | UEIENXTemp = UEIENX; 75 | } 76 | 77 | if (!(UECFG1XTemp & (1 << ALLOC))) 78 | continue; 79 | 80 | Endpoint_DisableEndpoint(); 81 | UECFG1X &= ~(1 << ALLOC); 82 | 83 | Endpoint_EnableEndpoint(); 84 | UECFG0X = UECFG0XTemp; 85 | UECFG1X = UECFG1XTemp; 86 | UEIENX = UEIENXTemp; 87 | 88 | if (!(Endpoint_IsConfigured())) 89 | return false; 90 | } 91 | 92 | Endpoint_SelectEndpoint(Number); 93 | return true; 94 | #endif 95 | } 96 | 97 | void Endpoint_ClearEndpoints(void) 98 | { 99 | UEINT = 0; 100 | 101 | for (uint8_t EPNum = 0; EPNum < ENDPOINT_TOTAL_ENDPOINTS; EPNum++) 102 | { 103 | Endpoint_SelectEndpoint(EPNum); 104 | UEIENX = 0; 105 | UEINTX = 0; 106 | UECFG1X = 0; 107 | Endpoint_DisableEndpoint(); 108 | } 109 | } 110 | 111 | void Endpoint_ClearStatusStage(void) 112 | { 113 | if (USB_ControlRequest.bmRequestType & REQDIR_DEVICETOHOST) 114 | { 115 | while (!(Endpoint_IsOUTReceived())) 116 | { 117 | if (USB_DeviceState == DEVICE_STATE_Unattached) 118 | return; 119 | } 120 | 121 | Endpoint_ClearOUT(); 122 | } 123 | else 124 | { 125 | while (!(Endpoint_IsINReady())) 126 | { 127 | if (USB_DeviceState == DEVICE_STATE_Unattached) 128 | return; 129 | } 130 | 131 | Endpoint_ClearIN(); 132 | } 133 | } 134 | 135 | #if !defined(CONTROL_ONLY_DEVICE) 136 | uint8_t Endpoint_WaitUntilReady(void) 137 | { 138 | #if (USB_STREAM_TIMEOUT_MS < 0xFF) 139 | uint8_t TimeoutMSRem = USB_STREAM_TIMEOUT_MS; 140 | #else 141 | uint16_t TimeoutMSRem = USB_STREAM_TIMEOUT_MS; 142 | #endif 143 | 144 | uint16_t PreviousFrameNumber = USB_Device_GetFrameNumber(); 145 | 146 | for (;;) 147 | { 148 | if (Endpoint_GetEndpointDirection() == ENDPOINT_DIR_IN) 149 | { 150 | if (Endpoint_IsINReady()) 151 | return ENDPOINT_READYWAIT_NoError; 152 | } 153 | else 154 | { 155 | if (Endpoint_IsOUTReceived()) 156 | return ENDPOINT_READYWAIT_NoError; 157 | } 158 | 159 | uint8_t USB_DeviceState_LCL = USB_DeviceState; 160 | 161 | if (USB_DeviceState_LCL == DEVICE_STATE_Unattached) 162 | return ENDPOINT_READYWAIT_DeviceDisconnected; 163 | else if (USB_DeviceState_LCL == DEVICE_STATE_Suspended) 164 | return ENDPOINT_READYWAIT_BusSuspended; 165 | else if (Endpoint_IsStalled()) 166 | return ENDPOINT_READYWAIT_EndpointStalled; 167 | 168 | uint16_t CurrentFrameNumber = USB_Device_GetFrameNumber(); 169 | 170 | if (CurrentFrameNumber != PreviousFrameNumber) 171 | { 172 | PreviousFrameNumber = CurrentFrameNumber; 173 | 174 | if (!(TimeoutMSRem--)) 175 | return ENDPOINT_READYWAIT_Timeout; 176 | } 177 | } 178 | } 179 | #endif 180 | 181 | #endif 182 | 183 | -------------------------------------------------------------------------------- /hal/at90usb646/LUFA/Drivers/USB/Core/AVR8/Pipe_AVR8.c: -------------------------------------------------------------------------------- 1 | /* 2 | LUFA Library 3 | Copyright (C) Dean Camera, 2012. 4 | 5 | dean [at] fourwalledcubicle [dot] com 6 | www.lufa-lib.org 7 | */ 8 | 9 | /* 10 | Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) 11 | 12 | Permission to use, copy, modify, distribute, and sell this 13 | software and its documentation for any purpose is hereby granted 14 | without fee, provided that the above copyright notice appear in 15 | all copies and that both that the copyright notice and this 16 | permission notice and warranty disclaimer appear in supporting 17 | documentation, and that the name of the author not be used in 18 | advertising or publicity pertaining to distribution of the 19 | software without specific, written prior permission. 20 | 21 | The author disclaim all warranties with regard to this 22 | software, including all implied warranties of merchantability 23 | and fitness. In no event shall the author be liable for any 24 | special, indirect or consequential damages or any damages 25 | whatsoever resulting from loss of use, data or profits, whether 26 | in an action of contract, negligence or other tortious action, 27 | arising out of or in connection with the use or performance of 28 | this software. 29 | */ 30 | 31 | #define __INCLUDE_FROM_USB_DRIVER 32 | #include "../USBMode.h" 33 | 34 | #if defined(USB_CAN_BE_HOST) 35 | 36 | #include "../Pipe.h" 37 | 38 | uint8_t USB_Host_ControlPipeSize = PIPE_CONTROLPIPE_DEFAULT_SIZE; 39 | 40 | bool Pipe_ConfigurePipe(const uint8_t Number, 41 | const uint8_t Type, 42 | const uint8_t Token, 43 | const uint8_t EndpointNumber, 44 | const uint16_t Size, 45 | const uint8_t Banks) 46 | { 47 | #if defined(ORDERED_EP_CONFIG) 48 | Pipe_SelectPipe(Number); 49 | Pipe_EnablePipe(); 50 | 51 | UPCFG1X = 0; 52 | 53 | UPCFG0X = ((Type << EPTYPE0) | Token | ((EndpointNumber & PIPE_EPNUM_MASK) << PEPNUM0)); 54 | UPCFG1X = ((1 << ALLOC) | Banks | Pipe_BytesToEPSizeMask(Size)); 55 | 56 | Pipe_SetInfiniteINRequests(); 57 | 58 | return Pipe_IsConfigured(); 59 | #else 60 | for (uint8_t PNum = Number; PNum < PIPE_TOTAL_PIPES; PNum++) 61 | { 62 | uint8_t UPCFG0XTemp; 63 | uint8_t UPCFG1XTemp; 64 | uint8_t UPCFG2XTemp; 65 | uint8_t UPIENXTemp; 66 | 67 | Pipe_SelectPipe(PNum); 68 | 69 | if (PNum == Number) 70 | { 71 | UPCFG0XTemp = ((Type << EPTYPE0) | Token | ((EndpointNumber & PIPE_EPNUM_MASK) << PEPNUM0)); 72 | UPCFG1XTemp = ((1 << ALLOC) | Banks | Pipe_BytesToEPSizeMask(Size)); 73 | UPCFG2XTemp = 0; 74 | UPIENXTemp = 0; 75 | } 76 | else 77 | { 78 | UPCFG0XTemp = UPCFG0X; 79 | UPCFG1XTemp = UPCFG1X; 80 | UPCFG2XTemp = UPCFG2X; 81 | UPIENXTemp = UPIENX; 82 | } 83 | 84 | if (!(UPCFG1XTemp & (1 << ALLOC))) 85 | continue; 86 | 87 | Pipe_DisablePipe(); 88 | UPCFG1X &= ~(1 << ALLOC); 89 | 90 | Pipe_EnablePipe(); 91 | UPCFG0X = UPCFG0XTemp; 92 | UPCFG1X = UPCFG1XTemp; 93 | UPCFG2X = UPCFG2XTemp; 94 | UPIENX = UPIENXTemp; 95 | 96 | Pipe_SetInfiniteINRequests(); 97 | 98 | if (!(Pipe_IsConfigured())) 99 | return false; 100 | } 101 | 102 | Pipe_SelectPipe(Number); 103 | return true; 104 | #endif 105 | } 106 | 107 | void Pipe_ClearPipes(void) 108 | { 109 | UPINT = 0; 110 | 111 | for (uint8_t PNum = 0; PNum < PIPE_TOTAL_PIPES; PNum++) 112 | { 113 | Pipe_SelectPipe(PNum); 114 | UPIENX = 0; 115 | UPINTX = 0; 116 | UPCFG1X = 0; 117 | Pipe_DisablePipe(); 118 | } 119 | } 120 | 121 | bool Pipe_IsEndpointBound(const uint8_t EndpointAddress) 122 | { 123 | uint8_t PrevPipeNumber = Pipe_GetCurrentPipe(); 124 | 125 | for (uint8_t PNum = 0; PNum < PIPE_TOTAL_PIPES; PNum++) 126 | { 127 | Pipe_SelectPipe(PNum); 128 | 129 | if (!(Pipe_IsConfigured())) 130 | continue; 131 | 132 | if (Pipe_GetBoundEndpointAddress() == EndpointAddress) 133 | return true; 134 | } 135 | 136 | Pipe_SelectPipe(PrevPipeNumber); 137 | return false; 138 | } 139 | 140 | uint8_t Pipe_WaitUntilReady(void) 141 | { 142 | #if (USB_STREAM_TIMEOUT_MS < 0xFF) 143 | uint8_t TimeoutMSRem = USB_STREAM_TIMEOUT_MS; 144 | #else 145 | uint16_t TimeoutMSRem = USB_STREAM_TIMEOUT_MS; 146 | #endif 147 | 148 | uint16_t PreviousFrameNumber = USB_Host_GetFrameNumber(); 149 | 150 | for (;;) 151 | { 152 | if (Pipe_GetPipeToken() == PIPE_TOKEN_IN) 153 | { 154 | if (Pipe_IsINReceived()) 155 | return PIPE_READYWAIT_NoError; 156 | } 157 | else 158 | { 159 | if (Pipe_IsOUTReady()) 160 | return PIPE_READYWAIT_NoError; 161 | } 162 | 163 | if (Pipe_IsStalled()) 164 | return PIPE_READYWAIT_PipeStalled; 165 | else if (USB_HostState == HOST_STATE_Unattached) 166 | return PIPE_READYWAIT_DeviceDisconnected; 167 | 168 | uint16_t CurrentFrameNumber = USB_Host_GetFrameNumber(); 169 | 170 | if (CurrentFrameNumber != PreviousFrameNumber) 171 | { 172 | PreviousFrameNumber = CurrentFrameNumber; 173 | 174 | if (!(TimeoutMSRem--)) 175 | return PIPE_READYWAIT_Timeout; 176 | } 177 | } 178 | } 179 | 180 | #endif 181 | 182 | -------------------------------------------------------------------------------- /hal/at90usb646/LUFA/Drivers/USB/Core/AVR8/Template/Template_Endpoint_Control_R.c: -------------------------------------------------------------------------------- 1 | /* 2 | LUFA Library 3 | Copyright (C) Dean Camera, 2012. 4 | 5 | dean [at] fourwalledcubicle [dot] com 6 | www.lufa-lib.org 7 | */ 8 | 9 | /* 10 | Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) 11 | 12 | Permission to use, copy, modify, distribute, and sell this 13 | software and its documentation for any purpose is hereby granted 14 | without fee, provided that the above copyright notice appear in 15 | all copies and that both that the copyright notice and this 16 | permission notice and warranty disclaimer appear in supporting 17 | documentation, and that the name of the author not be used in 18 | advertising or publicity pertaining to distribution of the 19 | software without specific, written prior permission. 20 | 21 | The author disclaim all warranties with regard to this 22 | software, including all implied warranties of merchantability 23 | and fitness. In no event shall the author be liable for any 24 | special, indirect or consequential damages or any damages 25 | whatsoever resulting from loss of use, data or profits, whether 26 | in an action of contract, negligence or other tortious action, 27 | arising out of or in connection with the use or performance of 28 | this software. 29 | */ 30 | 31 | #if defined(TEMPLATE_FUNC_NAME) 32 | 33 | uint8_t TEMPLATE_FUNC_NAME (void* const Buffer, 34 | uint16_t Length) 35 | { 36 | uint8_t* DataStream = ((uint8_t*)Buffer + TEMPLATE_BUFFER_OFFSET(Length)); 37 | 38 | if (!(Length)) 39 | Endpoint_ClearOUT(); 40 | 41 | while (Length) 42 | { 43 | uint8_t USB_DeviceState_LCL = USB_DeviceState; 44 | 45 | if (USB_DeviceState_LCL == DEVICE_STATE_Unattached) 46 | return ENDPOINT_RWCSTREAM_DeviceDisconnected; 47 | else if (USB_DeviceState_LCL == DEVICE_STATE_Suspended) 48 | return ENDPOINT_RWCSTREAM_BusSuspended; 49 | else if (Endpoint_IsSETUPReceived()) 50 | return ENDPOINT_RWCSTREAM_HostAborted; 51 | 52 | if (Endpoint_IsOUTReceived()) 53 | { 54 | while (Length && Endpoint_BytesInEndpoint()) 55 | { 56 | TEMPLATE_TRANSFER_BYTE(DataStream); 57 | TEMPLATE_BUFFER_MOVE(DataStream, 1); 58 | Length--; 59 | } 60 | 61 | Endpoint_ClearOUT(); 62 | } 63 | } 64 | 65 | while (!(Endpoint_IsINReady())) 66 | { 67 | uint8_t USB_DeviceState_LCL = USB_DeviceState; 68 | 69 | if (USB_DeviceState_LCL == DEVICE_STATE_Unattached) 70 | return ENDPOINT_RWCSTREAM_DeviceDisconnected; 71 | else if (USB_DeviceState_LCL == DEVICE_STATE_Suspended) 72 | return ENDPOINT_RWCSTREAM_BusSuspended; 73 | } 74 | 75 | return ENDPOINT_RWCSTREAM_NoError; 76 | } 77 | 78 | #undef TEMPLATE_BUFFER_OFFSET 79 | #undef TEMPLATE_BUFFER_MOVE 80 | #undef TEMPLATE_FUNC_NAME 81 | #undef TEMPLATE_TRANSFER_BYTE 82 | 83 | #endif 84 | 85 | -------------------------------------------------------------------------------- /hal/at90usb646/LUFA/Drivers/USB/Core/AVR8/Template/Template_Endpoint_Control_W.c: -------------------------------------------------------------------------------- 1 | /* 2 | LUFA Library 3 | Copyright (C) Dean Camera, 2012. 4 | 5 | dean [at] fourwalledcubicle [dot] com 6 | www.lufa-lib.org 7 | */ 8 | 9 | /* 10 | Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) 11 | 12 | Permission to use, copy, modify, distribute, and sell this 13 | software and its documentation for any purpose is hereby granted 14 | without fee, provided that the above copyright notice appear in 15 | all copies and that both that the copyright notice and this 16 | permission notice and warranty disclaimer appear in supporting 17 | documentation, and that the name of the author not be used in 18 | advertising or publicity pertaining to distribution of the 19 | software without specific, written prior permission. 20 | 21 | The author disclaim all warranties with regard to this 22 | software, including all implied warranties of merchantability 23 | and fitness. In no event shall the author be liable for any 24 | special, indirect or consequential damages or any damages 25 | whatsoever resulting from loss of use, data or profits, whether 26 | in an action of contract, negligence or other tortious action, 27 | arising out of or in connection with the use or performance of 28 | this software. 29 | */ 30 | 31 | #if defined(TEMPLATE_FUNC_NAME) 32 | 33 | uint8_t TEMPLATE_FUNC_NAME (const void* const Buffer, 34 | uint16_t Length) 35 | { 36 | uint8_t* DataStream = ((uint8_t*)Buffer + TEMPLATE_BUFFER_OFFSET(Length)); 37 | bool LastPacketFull = false; 38 | 39 | if (Length > USB_ControlRequest.wLength) 40 | Length = USB_ControlRequest.wLength; 41 | else if (!(Length)) 42 | Endpoint_ClearIN(); 43 | 44 | while (Length || LastPacketFull) 45 | { 46 | uint8_t USB_DeviceState_LCL = USB_DeviceState; 47 | 48 | if (USB_DeviceState_LCL == DEVICE_STATE_Unattached) 49 | return ENDPOINT_RWCSTREAM_DeviceDisconnected; 50 | else if (USB_DeviceState_LCL == DEVICE_STATE_Suspended) 51 | return ENDPOINT_RWCSTREAM_BusSuspended; 52 | else if (Endpoint_IsSETUPReceived()) 53 | return ENDPOINT_RWCSTREAM_HostAborted; 54 | else if (Endpoint_IsOUTReceived()) 55 | break; 56 | 57 | if (Endpoint_IsINReady()) 58 | { 59 | uint16_t BytesInEndpoint = Endpoint_BytesInEndpoint(); 60 | 61 | while (Length && (BytesInEndpoint < USB_Device_ControlEndpointSize)) 62 | { 63 | TEMPLATE_TRANSFER_BYTE(DataStream); 64 | TEMPLATE_BUFFER_MOVE(DataStream, 1); 65 | Length--; 66 | BytesInEndpoint++; 67 | } 68 | 69 | LastPacketFull = (BytesInEndpoint == USB_Device_ControlEndpointSize); 70 | Endpoint_ClearIN(); 71 | } 72 | } 73 | 74 | while (!(Endpoint_IsOUTReceived())) 75 | { 76 | uint8_t USB_DeviceState_LCL = USB_DeviceState; 77 | 78 | if (USB_DeviceState_LCL == DEVICE_STATE_Unattached) 79 | return ENDPOINT_RWCSTREAM_DeviceDisconnected; 80 | else if (USB_DeviceState_LCL == DEVICE_STATE_Suspended) 81 | return ENDPOINT_RWCSTREAM_BusSuspended; 82 | } 83 | 84 | return ENDPOINT_RWCSTREAM_NoError; 85 | } 86 | 87 | #undef TEMPLATE_BUFFER_OFFSET 88 | #undef TEMPLATE_BUFFER_MOVE 89 | #undef TEMPLATE_FUNC_NAME 90 | #undef TEMPLATE_TRANSFER_BYTE 91 | 92 | #endif 93 | 94 | -------------------------------------------------------------------------------- /hal/at90usb646/LUFA/Drivers/USB/Core/AVR8/Template/Template_Endpoint_RW.c: -------------------------------------------------------------------------------- 1 | /* 2 | LUFA Library 3 | Copyright (C) Dean Camera, 2012. 4 | 5 | dean [at] fourwalledcubicle [dot] com 6 | www.lufa-lib.org 7 | */ 8 | 9 | /* 10 | Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) 11 | 12 | Permission to use, copy, modify, distribute, and sell this 13 | software and its documentation for any purpose is hereby granted 14 | without fee, provided that the above copyright notice appear in 15 | all copies and that both that the copyright notice and this 16 | permission notice and warranty disclaimer appear in supporting 17 | documentation, and that the name of the author not be used in 18 | advertising or publicity pertaining to distribution of the 19 | software without specific, written prior permission. 20 | 21 | The author disclaim all warranties with regard to this 22 | software, including all implied warranties of merchantability 23 | and fitness. In no event shall the author be liable for any 24 | special, indirect or consequential damages or any damages 25 | whatsoever resulting from loss of use, data or profits, whether 26 | in an action of contract, negligence or other tortious action, 27 | arising out of or in connection with the use or performance of 28 | this software. 29 | */ 30 | 31 | #if defined(TEMPLATE_FUNC_NAME) 32 | 33 | uint8_t TEMPLATE_FUNC_NAME (TEMPLATE_BUFFER_TYPE const Buffer, 34 | uint16_t Length, 35 | uint16_t* const BytesProcessed) 36 | { 37 | uint8_t* DataStream = ((uint8_t*)Buffer + TEMPLATE_BUFFER_OFFSET(Length)); 38 | uint16_t BytesInTransfer = 0; 39 | uint8_t ErrorCode; 40 | 41 | if ((ErrorCode = Endpoint_WaitUntilReady())) 42 | return ErrorCode; 43 | 44 | if (BytesProcessed != NULL) 45 | { 46 | Length -= *BytesProcessed; 47 | TEMPLATE_BUFFER_MOVE(DataStream, *BytesProcessed); 48 | } 49 | 50 | while (Length) 51 | { 52 | if (!(Endpoint_IsReadWriteAllowed())) 53 | { 54 | TEMPLATE_CLEAR_ENDPOINT(); 55 | 56 | #if !defined(INTERRUPT_CONTROL_ENDPOINT) 57 | USB_USBTask(); 58 | #endif 59 | 60 | if (BytesProcessed != NULL) 61 | { 62 | *BytesProcessed += BytesInTransfer; 63 | return ENDPOINT_RWSTREAM_IncompleteTransfer; 64 | } 65 | 66 | if ((ErrorCode = Endpoint_WaitUntilReady())) 67 | return ErrorCode; 68 | } 69 | else 70 | { 71 | TEMPLATE_TRANSFER_BYTE(DataStream); 72 | TEMPLATE_BUFFER_MOVE(DataStream, 1); 73 | Length--; 74 | BytesInTransfer++; 75 | } 76 | } 77 | 78 | return ENDPOINT_RWSTREAM_NoError; 79 | } 80 | 81 | #undef TEMPLATE_FUNC_NAME 82 | #undef TEMPLATE_BUFFER_TYPE 83 | #undef TEMPLATE_TRANSFER_BYTE 84 | #undef TEMPLATE_CLEAR_ENDPOINT 85 | #undef TEMPLATE_BUFFER_OFFSET 86 | #undef TEMPLATE_BUFFER_MOVE 87 | 88 | #endif 89 | 90 | -------------------------------------------------------------------------------- /hal/at90usb646/LUFA/Drivers/USB/Core/AVR8/Template/Template_Pipe_RW.c: -------------------------------------------------------------------------------- 1 | /* 2 | LUFA Library 3 | Copyright (C) Dean Camera, 2012. 4 | 5 | dean [at] fourwalledcubicle [dot] com 6 | www.lufa-lib.org 7 | */ 8 | 9 | /* 10 | Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) 11 | 12 | Permission to use, copy, modify, distribute, and sell this 13 | software and its documentation for any purpose is hereby granted 14 | without fee, provided that the above copyright notice appear in 15 | all copies and that both that the copyright notice and this 16 | permission notice and warranty disclaimer appear in supporting 17 | documentation, and that the name of the author not be used in 18 | advertising or publicity pertaining to distribution of the 19 | software without specific, written prior permission. 20 | 21 | The author disclaim all warranties with regard to this 22 | software, including all implied warranties of merchantability 23 | and fitness. In no event shall the author be liable for any 24 | special, indirect or consequential damages or any damages 25 | whatsoever resulting from loss of use, data or profits, whether 26 | in an action of contract, negligence or other tortious action, 27 | arising out of or in connection with the use or performance of 28 | this software. 29 | */ 30 | 31 | #if defined(TEMPLATE_FUNC_NAME) 32 | 33 | uint8_t TEMPLATE_FUNC_NAME (TEMPLATE_BUFFER_TYPE const Buffer, 34 | uint16_t Length, 35 | uint16_t* const BytesProcessed) 36 | { 37 | uint8_t* DataStream = ((uint8_t*)Buffer + TEMPLATE_BUFFER_OFFSET(Length)); 38 | uint16_t BytesInTransfer = 0; 39 | uint8_t ErrorCode; 40 | 41 | Pipe_SetPipeToken(TEMPLATE_TOKEN); 42 | 43 | if ((ErrorCode = Pipe_WaitUntilReady())) 44 | return ErrorCode; 45 | 46 | if (BytesProcessed != NULL) 47 | { 48 | Length -= *BytesProcessed; 49 | TEMPLATE_BUFFER_MOVE(DataStream, *BytesProcessed); 50 | } 51 | 52 | while (Length) 53 | { 54 | if (!(Pipe_IsReadWriteAllowed())) 55 | { 56 | TEMPLATE_CLEAR_PIPE(); 57 | 58 | if (BytesProcessed != NULL) 59 | { 60 | *BytesProcessed += BytesInTransfer; 61 | return PIPE_RWSTREAM_IncompleteTransfer; 62 | } 63 | 64 | if ((ErrorCode = Pipe_WaitUntilReady())) 65 | return ErrorCode; 66 | } 67 | else 68 | { 69 | TEMPLATE_TRANSFER_BYTE(DataStream); 70 | TEMPLATE_BUFFER_MOVE(DataStream, 1); 71 | Length--; 72 | BytesInTransfer++; 73 | } 74 | } 75 | 76 | return PIPE_RWSTREAM_NoError; 77 | } 78 | 79 | #undef TEMPLATE_FUNC_NAME 80 | #undef TEMPLATE_BUFFER_TYPE 81 | #undef TEMPLATE_TOKEN 82 | #undef TEMPLATE_TRANSFER_BYTE 83 | #undef TEMPLATE_CLEAR_PIPE 84 | #undef TEMPLATE_BUFFER_OFFSET 85 | #undef TEMPLATE_BUFFER_MOVE 86 | 87 | #endif 88 | 89 | -------------------------------------------------------------------------------- /hal/at90usb646/LUFA/Drivers/USB/Core/Endpoint.h: -------------------------------------------------------------------------------- 1 | /* 2 | LUFA Library 3 | Copyright (C) Dean Camera, 2012. 4 | 5 | dean [at] fourwalledcubicle [dot] com 6 | www.lufa-lib.org 7 | */ 8 | 9 | /* 10 | Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) 11 | 12 | Permission to use, copy, modify, distribute, and sell this 13 | software and its documentation for any purpose is hereby granted 14 | without fee, provided that the above copyright notice appear in 15 | all copies and that both that the copyright notice and this 16 | permission notice and warranty disclaimer appear in supporting 17 | documentation, and that the name of the author not be used in 18 | advertising or publicity pertaining to distribution of the 19 | software without specific, written prior permission. 20 | 21 | The author disclaim all warranties with regard to this 22 | software, including all implied warranties of merchantability 23 | and fitness. In no event shall the author be liable for any 24 | special, indirect or consequential damages or any damages 25 | whatsoever resulting from loss of use, data or profits, whether 26 | in an action of contract, negligence or other tortious action, 27 | arising out of or in connection with the use or performance of 28 | this software. 29 | */ 30 | 31 | /** \file 32 | * \brief USB Endpoint definitions for all architectures. 33 | * \copydetails Group_EndpointManagement 34 | * 35 | * \note This file should not be included directly. It is automatically included as needed by the USB driver 36 | * dispatch header located in LUFA/Drivers/USB/USB.h. 37 | */ 38 | 39 | /** \ingroup Group_EndpointManagement 40 | * \defgroup Group_EndpointRW Endpoint Data Reading and Writing 41 | * \brief Endpoint data read/write definitions. 42 | * 43 | * Functions, macros, variables, enums and types related to data reading and writing from and to endpoints. 44 | */ 45 | 46 | /** \ingroup Group_EndpointRW 47 | * \defgroup Group_EndpointPrimitiveRW Read/Write of Primitive Data Types 48 | * \brief Endpoint data primitive read/write definitions. 49 | * 50 | * Functions, macros, variables, enums and types related to data reading and writing of primitive data types 51 | * from and to endpoints. 52 | */ 53 | 54 | /** \ingroup Group_EndpointManagement 55 | * \defgroup Group_EndpointPacketManagement Endpoint Packet Management 56 | * \brief USB Endpoint package management definitions. 57 | * 58 | * Functions, macros, variables, enums and types related to packet management of endpoints. 59 | */ 60 | 61 | /** \ingroup Group_USB 62 | * \defgroup Group_EndpointManagement Endpoint Management 63 | * \brief Endpoint management definitions. 64 | * 65 | * Functions, macros and enums related to endpoint management when in USB Device mode. This 66 | * module contains the endpoint management macros, as well as endpoint interrupt and data 67 | * send/receive functions for various data types. 68 | * 69 | * @{ 70 | */ 71 | 72 | #ifndef __ENDPOINT_H__ 73 | #define __ENDPOINT_H__ 74 | 75 | /* Includes: */ 76 | #include "../../../Common/Common.h" 77 | #include "USBMode.h" 78 | 79 | /* Enable C linkage for C++ Compilers: */ 80 | #if defined(__cplusplus) 81 | extern "C" { 82 | #endif 83 | 84 | /* Preprocessor Checks: */ 85 | #if !defined(__INCLUDE_FROM_USB_DRIVER) 86 | #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead. 87 | #endif 88 | 89 | /* Public Interface - May be used in end-application: */ 90 | /* Macros: */ 91 | /** Endpoint number mask, for masking against endpoint addresses to retrieve the endpoint's 92 | * numerical address in the device. 93 | */ 94 | #define ENDPOINT_EPNUM_MASK 0x0F 95 | 96 | /** Endpoint address for the default control endpoint, which always resides in address 0. This is 97 | * defined for convenience to give more readable code when used with the endpoint macros. 98 | */ 99 | #define ENDPOINT_CONTROLEP 0 100 | 101 | /* Architecture Includes: */ 102 | #if (ARCH == ARCH_AVR8) 103 | #include "AVR8/Endpoint_AVR8.h" 104 | #elif (ARCH == ARCH_UC3) 105 | #include "UC3/Endpoint_UC3.h" 106 | #elif (ARCH == ARCH_XMEGA) 107 | #include "XMEGA/Endpoint_XMEGA.h" 108 | #endif 109 | 110 | /* Disable C linkage for C++ Compilers: */ 111 | #if defined(__cplusplus) 112 | } 113 | #endif 114 | 115 | #endif 116 | 117 | /** @} */ 118 | 119 | -------------------------------------------------------------------------------- /hal/at90usb646/LUFA/Drivers/USB/Core/Events.c: -------------------------------------------------------------------------------- 1 | /* 2 | LUFA Library 3 | Copyright (C) Dean Camera, 2012. 4 | 5 | dean [at] fourwalledcubicle [dot] com 6 | www.lufa-lib.org 7 | */ 8 | 9 | /* 10 | Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) 11 | 12 | Permission to use, copy, modify, distribute, and sell this 13 | software and its documentation for any purpose is hereby granted 14 | without fee, provided that the above copyright notice appear in 15 | all copies and that both that the copyright notice and this 16 | permission notice and warranty disclaimer appear in supporting 17 | documentation, and that the name of the author not be used in 18 | advertising or publicity pertaining to distribution of the 19 | software without specific, written prior permission. 20 | 21 | The author disclaim all warranties with regard to this 22 | software, including all implied warranties of merchantability 23 | and fitness. In no event shall the author be liable for any 24 | special, indirect or consequential damages or any damages 25 | whatsoever resulting from loss of use, data or profits, whether 26 | in an action of contract, negligence or other tortious action, 27 | arising out of or in connection with the use or performance of 28 | this software. 29 | */ 30 | 31 | #define __INCLUDE_FROM_EVENTS_C 32 | #define __INCLUDE_FROM_USB_DRIVER 33 | #include "Events.h" 34 | 35 | void USB_Event_Stub(void) 36 | { 37 | 38 | } 39 | 40 | -------------------------------------------------------------------------------- /hal/at90usb646/LUFA/Drivers/USB/Core/OTG.h: -------------------------------------------------------------------------------- 1 | /* 2 | LUFA Library 3 | Copyright (C) Dean Camera, 2012. 4 | 5 | dean [at] fourwalledcubicle [dot] com 6 | www.lufa-lib.org 7 | */ 8 | 9 | /* 10 | Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) 11 | 12 | Permission to use, copy, modify, distribute, and sell this 13 | software and its documentation for any purpose is hereby granted 14 | without fee, provided that the above copyright notice appear in 15 | all copies and that both that the copyright notice and this 16 | permission notice and warranty disclaimer appear in supporting 17 | documentation, and that the name of the author not be used in 18 | advertising or publicity pertaining to distribution of the 19 | software without specific, written prior permission. 20 | 21 | The author disclaim all warranties with regard to this 22 | software, including all implied warranties of merchantability 23 | and fitness. In no event shall the author be liable for any 24 | special, indirect or consequential damages or any damages 25 | whatsoever resulting from loss of use, data or profits, whether 26 | in an action of contract, negligence or other tortious action, 27 | arising out of or in connection with the use or performance of 28 | this software. 29 | */ 30 | 31 | /** \file 32 | * \brief Common USB OTG definitions for all architectures. 33 | * \copydetails Group_OTG 34 | * 35 | * \note This file should not be included directly. It is automatically included as needed by the USB driver 36 | * dispatch header located in LUFA/Drivers/USB/USB.h. 37 | */ 38 | 39 | /** \ingroup Group_USB 40 | * \defgroup Group_OTG USB On The Go (OTG) Management 41 | * \brief USB OTG management definitions. 42 | * 43 | * This module contains macros for embedded USB hosts with dual role On The Go capabilities, for managing role 44 | * exchange. OTG is a way for two USB dual role devices to talk to one another directly without fixed device/host 45 | * roles. 46 | * 47 | * @{ 48 | */ 49 | 50 | #ifndef __USBOTG_H__ 51 | #define __USBOTG_H__ 52 | 53 | /* Includes: */ 54 | #include "../../../Common/Common.h" 55 | #include "USBMode.h" 56 | 57 | /* Enable C linkage for C++ Compilers: */ 58 | #if defined(__cplusplus) 59 | extern "C" { 60 | #endif 61 | 62 | /* Preprocessor Checks: */ 63 | #if !defined(__INCLUDE_FROM_USB_DRIVER) 64 | #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead. 65 | #endif 66 | 67 | /* Architecture Includes: */ 68 | #if (ARCH == ARCH_AVR8) 69 | #include "AVR8/OTG_AVR8.h" 70 | #endif 71 | 72 | /* Disable C linkage for C++ Compilers: */ 73 | #if defined(__cplusplus) 74 | } 75 | #endif 76 | 77 | #endif 78 | 79 | /** @} */ 80 | 81 | -------------------------------------------------------------------------------- /hal/at90usb646/LUFA/Drivers/USB/Core/Pipe.h: -------------------------------------------------------------------------------- 1 | /* 2 | LUFA Library 3 | Copyright (C) Dean Camera, 2012. 4 | 5 | dean [at] fourwalledcubicle [dot] com 6 | www.lufa-lib.org 7 | */ 8 | 9 | /* 10 | Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) 11 | 12 | Permission to use, copy, modify, distribute, and sell this 13 | software and its documentation for any purpose is hereby granted 14 | without fee, provided that the above copyright notice appear in 15 | all copies and that both that the copyright notice and this 16 | permission notice and warranty disclaimer appear in supporting 17 | documentation, and that the name of the author not be used in 18 | advertising or publicity pertaining to distribution of the 19 | software without specific, written prior permission. 20 | 21 | The author disclaim all warranties with regard to this 22 | software, including all implied warranties of merchantability 23 | and fitness. In no event shall the author be liable for any 24 | special, indirect or consequential damages or any damages 25 | whatsoever resulting from loss of use, data or profits, whether 26 | in an action of contract, negligence or other tortious action, 27 | arising out of or in connection with the use or performance of 28 | this software. 29 | */ 30 | 31 | /** \file 32 | * \brief Common USB Pipe definitions for all architectures. 33 | * \copydetails Group_PipeManagement 34 | * 35 | * \note This file should not be included directly. It is automatically included as needed by the USB driver 36 | * dispatch header located in LUFA/Drivers/USB/USB.h. 37 | */ 38 | 39 | /** \ingroup Group_PipeManagement 40 | * \defgroup Group_PipeRW Pipe Data Reading and Writing 41 | * \brief Pipe data read/write definitions. 42 | * 43 | * Functions, macros, variables, enums and types related to data reading and writing from and to pipes. 44 | */ 45 | 46 | /** \ingroup Group_PipeRW 47 | * \defgroup Group_PipePrimitiveRW Read/Write of Primitive Data Types 48 | * \brief Pipe data primitive read/write definitions. 49 | * 50 | * Functions, macros, variables, enums and types related to data reading and writing of primitive data types 51 | * from and to pipes. 52 | */ 53 | 54 | /** \ingroup Group_PipeManagement 55 | * \defgroup Group_PipePacketManagement Pipe Packet Management 56 | * \brief Pipe packet management definitions. 57 | * 58 | * Functions, macros, variables, enums and types related to packet management of pipes. 59 | */ 60 | 61 | /** \ingroup Group_PipeManagement 62 | * \defgroup Group_PipeControlReq Pipe Control Request Management 63 | * \brief Pipe control request definitions. 64 | * 65 | * Module for host mode request processing. This module allows for the transmission of standard, class and 66 | * vendor control requests to the default control endpoint of an attached device while in host mode. 67 | * 68 | * \see Chapter 9 of the USB 2.0 specification. 69 | */ 70 | 71 | /** \ingroup Group_USB 72 | * \defgroup Group_PipeManagement Pipe Management 73 | * \brief Pipe management definitions. 74 | * 75 | * This module contains functions, macros and enums related to pipe management when in USB Host mode. This 76 | * module contains the pipe management macros, as well as pipe interrupt and data send/receive functions 77 | * for various data types. 78 | * 79 | * @{ 80 | */ 81 | 82 | #ifndef __PIPE_H__ 83 | #define __PIPE_H__ 84 | 85 | /* Includes: */ 86 | #include "../../../Common/Common.h" 87 | #include "USBMode.h" 88 | 89 | /* Enable C linkage for C++ Compilers: */ 90 | #if defined(__cplusplus) 91 | extern "C" { 92 | #endif 93 | 94 | /* Preprocessor Checks: */ 95 | #if !defined(__INCLUDE_FROM_USB_DRIVER) 96 | #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead. 97 | #endif 98 | 99 | /* Public Interface - May be used in end-application: */ 100 | /* Macros: */ 101 | /** Pipe address for the default control pipe, which always resides in address 0. This is 102 | * defined for convenience to give more readable code when used with the pipe macros. 103 | */ 104 | #define PIPE_CONTROLPIPE 0 105 | 106 | /** Pipe number mask, for masking against pipe addresses to retrieve the pipe's numerical address 107 | * in the device. 108 | */ 109 | #define PIPE_PIPENUM_MASK 0x0F 110 | 111 | /** Endpoint number mask, for masking against endpoint addresses to retrieve the endpoint's 112 | * numerical address in the attached device. 113 | */ 114 | #define PIPE_EPNUM_MASK 0x0F 115 | 116 | /** Endpoint direction mask, for masking against endpoint addresses to retrieve the endpoint's 117 | * direction for comparing with the \c ENDPOINT_DIR_* masks. 118 | */ 119 | #define PIPE_EPDIR_MASK 0x80 120 | 121 | /* Architecture Includes: */ 122 | #if (ARCH == ARCH_AVR8) 123 | #include "AVR8/Pipe_AVR8.h" 124 | #elif (ARCH == ARCH_UC3) 125 | #include "UC3/Pipe_UC3.h" 126 | #endif 127 | 128 | /* Disable C linkage for C++ Compilers: */ 129 | #if defined(__cplusplus) 130 | } 131 | #endif 132 | 133 | #endif 134 | 135 | /** @} */ 136 | 137 | -------------------------------------------------------------------------------- /hal/at90usb646/LUFA/Drivers/USB/Core/PipeStream.h: -------------------------------------------------------------------------------- 1 | /* 2 | LUFA Library 3 | Copyright (C) Dean Camera, 2012. 4 | 5 | dean [at] fourwalledcubicle [dot] com 6 | www.lufa-lib.org 7 | */ 8 | 9 | /* 10 | Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) 11 | 12 | Permission to use, copy, modify, distribute, and sell this 13 | software and its documentation for any purpose is hereby granted 14 | without fee, provided that the above copyright notice appear in 15 | all copies and that both that the copyright notice and this 16 | permission notice and warranty disclaimer appear in supporting 17 | documentation, and that the name of the author not be used in 18 | advertising or publicity pertaining to distribution of the 19 | software without specific, written prior permission. 20 | 21 | The author disclaim all warranties with regard to this 22 | software, including all implied warranties of merchantability 23 | and fitness. In no event shall the author be liable for any 24 | special, indirect or consequential damages or any damages 25 | whatsoever resulting from loss of use, data or profits, whether 26 | in an action of contract, negligence or other tortious action, 27 | arising out of or in connection with the use or performance of 28 | this software. 29 | */ 30 | 31 | /** \file 32 | * \brief Pipe data stream transmission and reception management. 33 | * \copydetails Group_PipeStreamRW 34 | * 35 | * \note This file should not be included directly. It is automatically included as needed by the USB driver 36 | * dispatch header located in LUFA/Drivers/USB/USB.h. 37 | */ 38 | 39 | /** \ingroup Group_PipeRW 40 | * \defgroup Group_PipeStreamRW Read/Write of Multi-Byte Streams 41 | * \brief Pipe data stream transmission and reception management. 42 | * 43 | * Functions, macros, variables, enums and types related to data reading and writing of data streams from 44 | * and to pipes. 45 | * 46 | * @{ 47 | */ 48 | 49 | #ifndef __PIPE_STREAM_H__ 50 | #define __PIPE_STREAM_H__ 51 | 52 | /* Includes: */ 53 | #include "../../../Common/Common.h" 54 | #include "USBMode.h" 55 | 56 | /* Enable C linkage for C++ Compilers: */ 57 | #if defined(__cplusplus) 58 | extern "C" { 59 | #endif 60 | 61 | /* Preprocessor Checks: */ 62 | #if !defined(__INCLUDE_FROM_USB_DRIVER) 63 | #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead. 64 | #endif 65 | 66 | /* Public Interface - May be used in end-application: */ 67 | /* Enums: */ 68 | /** Enum for the possible error return codes of the Pipe_*_Stream_* functions. */ 69 | enum Pipe_Stream_RW_ErrorCodes_t 70 | { 71 | PIPE_RWSTREAM_NoError = 0, /**< Command completed successfully, no error. */ 72 | PIPE_RWSTREAM_PipeStalled = 1, /**< The device stalled the pipe during the transfer. */ 73 | PIPE_RWSTREAM_DeviceDisconnected = 2, /**< Device was disconnected from the host during 74 | * the transfer. 75 | */ 76 | PIPE_RWSTREAM_Timeout = 3, /**< The device failed to accept or send the next packet 77 | * within the software timeout period set by the 78 | * \ref USB_STREAM_TIMEOUT_MS macro. 79 | */ 80 | PIPE_RWSTREAM_IncompleteTransfer = 4, /**< Indicates that the pipe bank became full/empty before the 81 | * complete contents of the stream could be transferred. 82 | */ 83 | }; 84 | 85 | /* Architecture Includes: */ 86 | #if (ARCH == ARCH_AVR8) 87 | #include "AVR8/PipeStream_AVR8.h" 88 | #elif (ARCH == ARCH_UC3) 89 | #include "UC3/PipeStream_UC3.h" 90 | #endif 91 | 92 | /* Disable C linkage for C++ Compilers: */ 93 | #if defined(__cplusplus) 94 | } 95 | #endif 96 | 97 | #endif 98 | 99 | /** @} */ 100 | 101 | -------------------------------------------------------------------------------- /hal/at90usb646/LUFA/Drivers/USB/Core/USBController.h: -------------------------------------------------------------------------------- 1 | /* 2 | LUFA Library 3 | Copyright (C) Dean Camera, 2012. 4 | 5 | dean [at] fourwalledcubicle [dot] com 6 | www.lufa-lib.org 7 | */ 8 | 9 | /* 10 | Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) 11 | 12 | Permission to use, copy, modify, distribute, and sell this 13 | software and its documentation for any purpose is hereby granted 14 | without fee, provided that the above copyright notice appear in 15 | all copies and that both that the copyright notice and this 16 | permission notice and warranty disclaimer appear in supporting 17 | documentation, and that the name of the author not be used in 18 | advertising or publicity pertaining to distribution of the 19 | software without specific, written prior permission. 20 | 21 | The author disclaim all warranties with regard to this 22 | software, including all implied warranties of merchantability 23 | and fitness. In no event shall the author be liable for any 24 | special, indirect or consequential damages or any damages 25 | whatsoever resulting from loss of use, data or profits, whether 26 | in an action of contract, negligence or other tortious action, 27 | arising out of or in connection with the use or performance of 28 | this software. 29 | */ 30 | 31 | /** \file 32 | * \brief Common USB Controller definitions for all architectures. 33 | * \copydetails Group_USBManagement 34 | * 35 | * \note This file should not be included directly. It is automatically included as needed by the USB driver 36 | * dispatch header located in LUFA/Drivers/USB/USB.h. 37 | */ 38 | 39 | /** \ingroup Group_USB 40 | * \defgroup Group_USBManagement USB Interface Management 41 | * \brief USB Controller definitions for general USB controller management. 42 | * 43 | * Functions, macros, variables, enums and types related to the setup and management of the USB interface. 44 | * 45 | * @{ 46 | */ 47 | 48 | #ifndef __USBCONTROLLER_H__ 49 | #define __USBCONTROLLER_H__ 50 | 51 | /* Includes: */ 52 | #include "../../../Common/Common.h" 53 | #include "USBMode.h" 54 | 55 | /* Enable C linkage for C++ Compilers: */ 56 | #if defined(__cplusplus) 57 | extern "C" { 58 | #endif 59 | 60 | /* Preprocessor Checks and Defines: */ 61 | #if !defined(__INCLUDE_FROM_USB_DRIVER) 62 | #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead. 63 | #endif 64 | 65 | /* Defines: */ 66 | /** \name Endpoint Direction Masks */ 67 | //@{ 68 | /** Endpoint direction mask, for masking against endpoint addresses to retrieve the endpoint's 69 | * direction for comparing with the \c ENDPOINT_DIR_* masks. 70 | */ 71 | #define ENDPOINT_DIR_MASK 0x80 72 | 73 | /** Endpoint address direction mask for an OUT direction (Host to Device) endpoint. This may be ORed with 74 | * the index of the address within a device to obtain the full endpoint address. 75 | */ 76 | #define ENDPOINT_DIR_OUT 0x00 77 | 78 | /** Endpoint address direction mask for an IN direction (Device to Host) endpoint. This may be ORed with 79 | * the index of the address within a device to obtain the full endpoint address. 80 | */ 81 | #define ENDPOINT_DIR_IN 0x80 82 | //@} 83 | 84 | /** \name Endpoint/Pipe Type Masks */ 85 | //@{ 86 | /** Mask for determining the type of an endpoint from an endpoint descriptor. This should then be compared 87 | * with the \c EP_TYPE_* masks to determine the exact type of the endpoint. 88 | */ 89 | #define EP_TYPE_MASK 0x03 90 | 91 | /** Mask for a CONTROL type endpoint or pipe. 92 | * 93 | * \note See \ref Group_EndpointManagement and \ref Group_PipeManagement for endpoint/pipe functions. 94 | */ 95 | #define EP_TYPE_CONTROL 0x00 96 | 97 | /** Mask for an ISOCHRONOUS type endpoint or pipe. 98 | * 99 | * \note See \ref Group_EndpointManagement and \ref Group_PipeManagement for endpoint/pipe functions. 100 | */ 101 | #define EP_TYPE_ISOCHRONOUS 0x01 102 | 103 | /** Mask for a BULK type endpoint or pipe. 104 | * 105 | * \note See \ref Group_EndpointManagement and \ref Group_PipeManagement for endpoint/pipe functions. 106 | */ 107 | #define EP_TYPE_BULK 0x02 108 | 109 | /** Mask for an INTERRUPT type endpoint or pipe. 110 | * 111 | * \note See \ref Group_EndpointManagement and \ref Group_PipeManagement for endpoint/pipe functions. 112 | */ 113 | #define EP_TYPE_INTERRUPT 0x03 114 | //@} 115 | 116 | /* Architecture Includes: */ 117 | #if (ARCH == ARCH_AVR8) 118 | #include "AVR8/USBController_AVR8.h" 119 | #elif (ARCH == ARCH_UC3) 120 | #include "UC3/USBController_UC3.h" 121 | #elif (ARCH == ARCH_XMEGA) 122 | #include "XMEGA/USBController_XMEGA.h" 123 | #endif 124 | 125 | /* Disable C linkage for C++ Compilers: */ 126 | #if defined(__cplusplus) 127 | } 128 | #endif 129 | 130 | #endif 131 | 132 | /** @} */ 133 | 134 | -------------------------------------------------------------------------------- /hal/at90usb646/LUFA/Drivers/USB/Core/USBInterrupt.h: -------------------------------------------------------------------------------- 1 | /* 2 | LUFA Library 3 | Copyright (C) Dean Camera, 2012. 4 | 5 | dean [at] fourwalledcubicle [dot] com 6 | www.lufa-lib.org 7 | */ 8 | 9 | /* 10 | Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) 11 | 12 | Permission to use, copy, modify, distribute, and sell this 13 | software and its documentation for any purpose is hereby granted 14 | without fee, provided that the above copyright notice appear in 15 | all copies and that both that the copyright notice and this 16 | permission notice and warranty disclaimer appear in supporting 17 | documentation, and that the name of the author not be used in 18 | advertising or publicity pertaining to distribution of the 19 | software without specific, written prior permission. 20 | 21 | The author disclaim all warranties with regard to this 22 | software, including all implied warranties of merchantability 23 | and fitness. In no event shall the author be liable for any 24 | special, indirect or consequential damages or any damages 25 | whatsoever resulting from loss of use, data or profits, whether 26 | in an action of contract, negligence or other tortious action, 27 | arising out of or in connection with the use or performance of 28 | this software. 29 | */ 30 | 31 | /** \file 32 | * \brief USB controller interrupt service routine management. 33 | * 34 | * This file contains definitions required for the correct handling of low level USB service routine interrupts 35 | * from the USB controller. 36 | * 37 | * \note This file should not be included directly. It is automatically included as needed by the USB driver 38 | * dispatch header located in LUFA/Drivers/USB/USB.h. 39 | */ 40 | 41 | #ifndef __USBINTERRUPT_H__ 42 | #define __USBINTERRUPT_H__ 43 | 44 | /* Includes: */ 45 | #include "../../../Common/Common.h" 46 | #include "USBMode.h" 47 | 48 | /* Enable C linkage for C++ Compilers: */ 49 | #if defined(__cplusplus) 50 | extern "C" { 51 | #endif 52 | 53 | /* Preprocessor Checks: */ 54 | #if !defined(__INCLUDE_FROM_USB_DRIVER) 55 | #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead. 56 | #endif 57 | 58 | /* Architecture Includes: */ 59 | #if (ARCH == ARCH_AVR8) 60 | #include "AVR8/USBInterrupt_AVR8.h" 61 | #elif (ARCH == ARCH_UC3) 62 | #include "UC3/USBInterrupt_UC3.h" 63 | #elif (ARCH == ARCH_XMEGA) 64 | #include "XMEGA/USBInterrupt_XMEGA.h" 65 | #endif 66 | 67 | /* Disable C linkage for C++ Compilers: */ 68 | #if defined(__cplusplus) 69 | } 70 | #endif 71 | 72 | #endif 73 | 74 | -------------------------------------------------------------------------------- /hal/at90usb646/LUFA/Drivers/USB/Core/USBTask.c: -------------------------------------------------------------------------------- 1 | /* 2 | LUFA Library 3 | Copyright (C) Dean Camera, 2012. 4 | 5 | dean [at] fourwalledcubicle [dot] com 6 | www.lufa-lib.org 7 | */ 8 | 9 | /* 10 | Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) 11 | 12 | Permission to use, copy, modify, distribute, and sell this 13 | software and its documentation for any purpose is hereby granted 14 | without fee, provided that the above copyright notice appear in 15 | all copies and that both that the copyright notice and this 16 | permission notice and warranty disclaimer appear in supporting 17 | documentation, and that the name of the author not be used in 18 | advertising or publicity pertaining to distribution of the 19 | software without specific, written prior permission. 20 | 21 | The author disclaim all warranties with regard to this 22 | software, including all implied warranties of merchantability 23 | and fitness. In no event shall the author be liable for any 24 | special, indirect or consequential damages or any damages 25 | whatsoever resulting from loss of use, data or profits, whether 26 | in an action of contract, negligence or other tortious action, 27 | arising out of or in connection with the use or performance of 28 | this software. 29 | */ 30 | 31 | #define __INCLUDE_FROM_USBTASK_C 32 | #define __INCLUDE_FROM_USB_DRIVER 33 | #include "USBTask.h" 34 | 35 | volatile bool USB_IsInitialized; 36 | USB_Request_Header_t USB_ControlRequest; 37 | 38 | #if defined(USB_CAN_BE_HOST) && !defined(HOST_STATE_AS_GPIOR) 39 | volatile uint8_t USB_HostState; 40 | #endif 41 | 42 | #if defined(USB_CAN_BE_DEVICE) && !defined(DEVICE_STATE_AS_GPIOR) 43 | volatile uint8_t USB_DeviceState; 44 | #endif 45 | 46 | void USB_USBTask(void) 47 | { 48 | #if defined(USB_HOST_ONLY) 49 | USB_HostTask(); 50 | #elif defined(USB_DEVICE_ONLY) 51 | USB_DeviceTask(); 52 | #else 53 | if (USB_CurrentMode == USB_MODE_Device) 54 | USB_DeviceTask(); 55 | #if defined(USB_CAN_BE_HOST) 56 | else if (USB_CurrentMode == USB_MODE_Host) 57 | USB_HostTask(); 58 | #endif 59 | #endif 60 | } 61 | 62 | #if defined(USB_CAN_BE_DEVICE) 63 | static void USB_DeviceTask(void) 64 | { 65 | if (USB_DeviceState != DEVICE_STATE_Unattached) 66 | { 67 | uint8_t PrevEndpoint = Endpoint_GetCurrentEndpoint(); 68 | 69 | Endpoint_SelectEndpoint(ENDPOINT_CONTROLEP); 70 | 71 | if (Endpoint_IsSETUPReceived()) 72 | USB_Device_ProcessControlRequest(); 73 | 74 | Endpoint_SelectEndpoint(PrevEndpoint); 75 | } 76 | } 77 | #endif 78 | 79 | #if defined(USB_CAN_BE_HOST) 80 | static void USB_HostTask(void) 81 | { 82 | uint8_t PrevPipe = Pipe_GetCurrentPipe(); 83 | 84 | Pipe_SelectPipe(PIPE_CONTROLPIPE); 85 | 86 | USB_Host_ProcessNextHostState(); 87 | 88 | Pipe_SelectPipe(PrevPipe); 89 | } 90 | #endif 91 | 92 | -------------------------------------------------------------------------------- /hal/at90usb646/LUFA/License.txt: -------------------------------------------------------------------------------- 1 | Permission to use, copy, modify, and distribute this software 2 | and its documentation for any purpose is hereby granted without 3 | fee, provided that the above copyright notice appear in all 4 | copies and that both that the copyright notice and this 5 | permission notice and warranty disclaimer appear in supporting 6 | documentation, and that the name of the author not be used in 7 | advertising or publicity pertaining to distribution of the 8 | software without specific, written prior permission. 9 | 10 | The author disclaim all warranties with regard to this 11 | software, including all implied warranties of merchantability 12 | and fitness. In no event shall the author be liable for any 13 | special, indirect or consequential damages or any damages 14 | whatsoever resulting from loss of use, data or profits, whether 15 | in an action of contract, negligence or other tortious action, 16 | arising out of or in connection with the use or performance of 17 | this software. 18 | 19 | -------------------------------------------------------------------------------- /hal/at90usb646/LUFA/Version.h: -------------------------------------------------------------------------------- 1 | /* 2 | LUFA Library 3 | Copyright (C) Dean Camera, 2012. 4 | 5 | dean [at] fourwalledcubicle [dot] com 6 | www.lufa-lib.org 7 | */ 8 | 9 | /* 10 | Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) 11 | 12 | Permission to use, copy, modify, distribute, and sell this 13 | software and its documentation for any purpose is hereby granted 14 | without fee, provided that the above copyright notice appear in 15 | all copies and that both that the copyright notice and this 16 | permission notice and warranty disclaimer appear in supporting 17 | documentation, and that the name of the author not be used in 18 | advertising or publicity pertaining to distribution of the 19 | software without specific, written prior permission. 20 | 21 | The author disclaim all warranties with regard to this 22 | software, including all implied warranties of merchantability 23 | and fitness. In no event shall the author be liable for any 24 | special, indirect or consequential damages or any damages 25 | whatsoever resulting from loss of use, data or profits, whether 26 | in an action of contract, negligence or other tortious action, 27 | arising out of or in connection with the use or performance of 28 | this software. 29 | */ 30 | 31 | /** \file 32 | * 33 | * \brief LUFA library version constants. 34 | * 35 | * Version constants for informational purposes and version-specific macro creation. This header file contains the 36 | * current LUFA version number in several forms, for use in the user-application (for example, for printing out 37 | * whilst debugging, or for testing for version compatibility). 38 | */ 39 | 40 | #ifndef __LUFA_VERSION_H__ 41 | #define __LUFA_VERSION_H__ 42 | 43 | /* Public Interface - May be used in end-application: */ 44 | /* Macros: */ 45 | /** Indicates the version number of the library, as an integer. */ 46 | #define LUFA_VERSION_INTEGER 0x120219 47 | 48 | /** Indicates the version number of the library, as a string. */ 49 | #define LUFA_VERSION_STRING "120219" 50 | 51 | #endif 52 | 53 | -------------------------------------------------------------------------------- /hal/at90usb646/LUFA/makefile: -------------------------------------------------------------------------------- 1 | # 2 | # LUFA Library 3 | # Copyright (C) Dean Camera, 2011. 4 | # 5 | # dean [at] fourwalledcubicle [dot] com 6 | # www.lufa-lib.org 7 | # 8 | 9 | # Makefile for the LUFA library itself. This can be used to generate the library documentation. 10 | 11 | 12 | # Check to see if the LUFA_PATH variable has not been set (the makefile is not being included from a project makefile) 13 | ifeq ($(origin LUFA_PATH), undefined) 14 | LUFA_ROOT_PATH = . 15 | ARCH = {AVR8,UC3,XMEGA} 16 | else 17 | LUFA_ROOT_PATH = $(LUFA_PATH)/LUFA 18 | endif 19 | 20 | # Check to see if the chip architecture has not been defined in the user makefile, set a default architecture if not 21 | ifeq ($(origin ARCH), undefined) 22 | ARCH = AVR8 23 | endif 24 | 25 | # Define module source file lists 26 | LUFA_SRC_USB = $(LUFA_ROOT_PATH)/Drivers/USB/Core/$(ARCH)/Device_$(ARCH).c \ 27 | $(LUFA_ROOT_PATH)/Drivers/USB/Core/$(ARCH)/Endpoint_$(ARCH).c \ 28 | $(LUFA_ROOT_PATH)/Drivers/USB/Core/$(ARCH)/Host_$(ARCH).c \ 29 | $(LUFA_ROOT_PATH)/Drivers/USB/Core/$(ARCH)/Pipe_$(ARCH).c \ 30 | $(LUFA_ROOT_PATH)/Drivers/USB/Core/$(ARCH)/USBController_$(ARCH).c \ 31 | $(LUFA_ROOT_PATH)/Drivers/USB/Core/$(ARCH)/USBInterrupt_$(ARCH).c \ 32 | $(LUFA_ROOT_PATH)/Drivers/USB/Core/$(ARCH)/EndpointStream_$(ARCH).c \ 33 | $(LUFA_ROOT_PATH)/Drivers/USB/Core/$(ARCH)/PipeStream_$(ARCH).c \ 34 | $(LUFA_ROOT_PATH)/Drivers/USB/Core/ConfigDescriptor.c \ 35 | $(LUFA_ROOT_PATH)/Drivers/USB/Core/DeviceStandardReq.c \ 36 | $(LUFA_ROOT_PATH)/Drivers/USB/Core/Events.c \ 37 | $(LUFA_ROOT_PATH)/Drivers/USB/Core/HostStandardReq.c \ 38 | $(LUFA_ROOT_PATH)/Drivers/USB/Core/USBTask.c \ 39 | $(LUFA_ROOT_PATH)/Drivers/USB/Class/Common/HIDParser.c 40 | LUFA_SRC_USBCLASS = $(LUFA_ROOT_PATH)/Drivers/USB/Class/Device/AudioClassDevice.c \ 41 | $(LUFA_ROOT_PATH)/Drivers/USB/Class/Device/CDCClassDevice.c \ 42 | $(LUFA_ROOT_PATH)/Drivers/USB/Class/Device/HIDClassDevice.c \ 43 | $(LUFA_ROOT_PATH)/Drivers/USB/Class/Device/MassStorageClassDevice.c \ 44 | $(LUFA_ROOT_PATH)/Drivers/USB/Class/Device/MIDIClassDevice.c \ 45 | $(LUFA_ROOT_PATH)/Drivers/USB/Class/Device/RNDISClassDevice.c \ 46 | $(LUFA_ROOT_PATH)/Drivers/USB/Class/Host/AndroidAccessoryClassHost.c \ 47 | $(LUFA_ROOT_PATH)/Drivers/USB/Class/Host/AudioClassHost.c \ 48 | $(LUFA_ROOT_PATH)/Drivers/USB/Class/Host/CDCClassHost.c \ 49 | $(LUFA_ROOT_PATH)/Drivers/USB/Class/Host/HIDClassHost.c \ 50 | $(LUFA_ROOT_PATH)/Drivers/USB/Class/Host/MassStorageClassHost.c \ 51 | $(LUFA_ROOT_PATH)/Drivers/USB/Class/Host/MIDIClassHost.c \ 52 | $(LUFA_ROOT_PATH)/Drivers/USB/Class/Host/PrinterClassHost.c \ 53 | $(LUFA_ROOT_PATH)/Drivers/USB/Class/Host/RNDISClassHost.c \ 54 | $(LUFA_ROOT_PATH)/Drivers/USB/Class/Host/StillImageClassHost.c 55 | LUFA_SRC_TEMPERATURE = $(LUFA_ROOT_PATH)/Drivers/Board/Temperature.c 56 | LUFA_SRC_SERIAL = $(LUFA_ROOT_PATH)/Drivers/Peripheral/$(ARCH)/Serial_$(ARCH).c 57 | LUFA_SRC_TWI = $(LUFA_ROOT_PATH)/Drivers/Peripheral/$(ARCH)/TWI_$(ARCH).c 58 | LUFA_SRC_SCHEDULER = $(LUFA_ROOT_PATH)/Scheduler/Scheduler.c 59 | 60 | 61 | # Check to see if the LUFA_PATH variable has not been set (the makefile is not being included from a project makefile) 62 | ifeq ($(origin LUFA_PATH), undefined) 63 | LUFA_SRC_ALL_FILES = $(LUFA_SRC_USB) \ 64 | $(LUFA_SRC_USBCLASS) \ 65 | $(LUFA_SRC_TEMPERATURE) \ 66 | $(LUFA_SRC_SERIAL) \ 67 | $(LUFA_SRC_TWI) \ 68 | $(LUFA_SRC_SCHEDULER) 69 | 70 | all: 71 | 72 | clean: 73 | rm -f $(LUFA_SRC_ALL_FILES:%.c=%.o) 74 | rm -f $(LUFA_SRC_ALL_FILES:%.c=%.lst) 75 | 76 | clean_list: 77 | 78 | doxygen: 79 | @echo Generating LUFA Library Documentation... 80 | ( cat Doxygen.conf ; echo "PROJECT_NUMBER=`grep LUFA_VERSION_STRING Version.h | cut -d'"' -f2`" ) | doxygen - 81 | @echo Documentation Generation Complete. 82 | 83 | clean_doxygen: 84 | rm -rf Documentation 85 | 86 | checksource: 87 | 88 | version: 89 | @echo "LUFA `grep LUFA_VERSION_STRING Version.h | cut -d'"' -f2`" 90 | 91 | .PHONY: all clean clean_list doxygen clean_doxygen version 92 | endif 93 | -------------------------------------------------------------------------------- /hal/at90usb646/at90usb646_options.cmake: -------------------------------------------------------------------------------- 1 | # AVR-specific include paths 2 | target_include_directories(SIMMProgrammer.elf PRIVATE 3 | hal/at90usb646 4 | ) 5 | 6 | # AVR-specific compiler definitions 7 | target_compile_definitions(SIMMProgrammer.elf PRIVATE 8 | F_CPU=16000000UL 9 | F_USB=16000000UL 10 | USE_LUFA_CONFIG_HEADER 11 | ) 12 | 13 | # AVR-specific compiler options 14 | target_compile_options(SIMMProgrammer.elf PRIVATE 15 | -fpack-struct -fshort-enums -funsigned-char -funsigned-bitfields -mmcu=at90usb646 16 | ) 17 | 18 | # AVR-specific linker options 19 | target_link_options(SIMMProgrammer.elf PRIVATE 20 | -mmcu=at90usb646 21 | ) 22 | 23 | # AVR-specific command/target to generate .bin file from the ELF file. This program 24 | # is flashed using a bootloader, so there's no need to generate a HEX file. 25 | add_custom_command(OUTPUT SIMMProgrammer.bin 26 | COMMAND ${CMAKE_OBJCOPY} -R .eeprom -O binary SIMMProgrammer.elf SIMMProgrammer.bin 27 | DEPENDS SIMMProgrammer.elf 28 | ) 29 | add_custom_target(SIMMProgrammer_bin ALL DEPENDS SIMMProgrammer.bin) 30 | -------------------------------------------------------------------------------- /hal/at90usb646/at90usb646_sources.cmake: -------------------------------------------------------------------------------- 1 | set(HWSOURCES 2 | hal/at90usb646/LUFA/Common/Architectures.h 3 | hal/at90usb646/LUFA/Common/ArchitectureSpecific.h 4 | hal/at90usb646/LUFA/Common/Attributes.h 5 | hal/at90usb646/LUFA/Common/BoardTypes.h 6 | hal/at90usb646/LUFA/Common/Common.h 7 | hal/at90usb646/LUFA/Common/CompilerSpecific.h 8 | hal/at90usb646/LUFA/Common/Endianness.h 9 | hal/at90usb646/LUFA/Drivers/USB/Class/Device/CDCClassDevice.c 10 | hal/at90usb646/LUFA/Drivers/USB/Class/CDCClass.h 11 | hal/at90usb646/LUFA/Drivers/USB/Class/Common/CDCClassCommon.h 12 | hal/at90usb646/LUFA/Drivers/USB/Class/Device/CDCClassDevice.h 13 | hal/at90usb646/LUFA/Drivers/USB/Core/AVR8/Device_AVR8.c 14 | hal/at90usb646/LUFA/Drivers/USB/Core/AVR8/Device_AVR8.h 15 | hal/at90usb646/LUFA/Drivers/USB/Core/AVR8/Endpoint_AVR8.c 16 | hal/at90usb646/LUFA/Drivers/USB/Core/AVR8/Endpoint_AVR8.h 17 | hal/at90usb646/LUFA/Drivers/USB/Core/AVR8/EndpointStream_AVR8.c 18 | hal/at90usb646/LUFA/Drivers/USB/Core/AVR8/EndpointStream_AVR8.h 19 | hal/at90usb646/LUFA/Drivers/USB/Core/AVR8/Host_AVR8.c 20 | hal/at90usb646/LUFA/Drivers/USB/Core/AVR8/Host_AVR8.h 21 | hal/at90usb646/LUFA/Drivers/USB/Core/AVR8/OTG_AVR8.h 22 | hal/at90usb646/LUFA/Drivers/USB/Core/AVR8/Pipe_AVR8.c 23 | hal/at90usb646/LUFA/Drivers/USB/Core/AVR8/Pipe_AVR8.h 24 | hal/at90usb646/LUFA/Drivers/USB/Core/AVR8/PipeStream_AVR8.c 25 | hal/at90usb646/LUFA/Drivers/USB/Core/AVR8/PipeStream_AVR8.h 26 | hal/at90usb646/LUFA/Drivers/USB/Core/AVR8/USBController_AVR8.c 27 | hal/at90usb646/LUFA/Drivers/USB/Core/AVR8/USBController_AVR8.h 28 | hal/at90usb646/LUFA/Drivers/USB/Core/AVR8/USBInterrupt_AVR8.c 29 | hal/at90usb646/LUFA/Drivers/USB/Core/AVR8/USBInterrupt_AVR8.h 30 | hal/at90usb646/LUFA/Drivers/USB/Core/ConfigDescriptor.c 31 | hal/at90usb646/LUFA/Drivers/USB/Core/ConfigDescriptor.h 32 | hal/at90usb646/LUFA/Drivers/USB/Core/DeviceStandardReq.c 33 | hal/at90usb646/LUFA/Drivers/USB/Core/DeviceStandardReq.h 34 | hal/at90usb646/LUFA/Drivers/USB/Core/Device.h 35 | hal/at90usb646/LUFA/Drivers/USB/Core/Endpoint.h 36 | hal/at90usb646/LUFA/Drivers/USB/Core/EndpointStream.h 37 | hal/at90usb646/LUFA/Drivers/USB/Core/Events.c 38 | hal/at90usb646/LUFA/Drivers/USB/Core/Events.h 39 | hal/at90usb646/LUFA/Drivers/USB/Core/Host.h 40 | hal/at90usb646/LUFA/Drivers/USB/Core/HostStandardReq.h 41 | hal/at90usb646/LUFA/Drivers/USB/Core/OTG.h 42 | hal/at90usb646/LUFA/Drivers/USB/Core/Pipe.h 43 | hal/at90usb646/LUFA/Drivers/USB/Core/PipeStream.h 44 | hal/at90usb646/LUFA/Drivers/USB/Core/StdDescriptors.h 45 | hal/at90usb646/LUFA/Drivers/USB/Core/StdRequestType.h 46 | hal/at90usb646/LUFA/Drivers/USB/Core/USBController.h 47 | hal/at90usb646/LUFA/Drivers/USB/Core/USBInterrupt.h 48 | hal/at90usb646/LUFA/Drivers/USB/Core/USBMode.h 49 | hal/at90usb646/LUFA/Drivers/USB/Core/USBTask.c 50 | hal/at90usb646/LUFA/Drivers/USB/Core/USBTask.h 51 | hal/at90usb646/LUFA/Drivers/USB/USB.h 52 | hal/at90usb646/LUFA/Version.h 53 | hal/at90usb646/LUFAConfig.h 54 | 55 | hal/at90usb646/board.c 56 | hal/at90usb646/board_hw.h 57 | hal/at90usb646/cdc_device_definition.c 58 | hal/at90usb646/cdc_device_definition.h 59 | hal/at90usb646/Descriptors.c 60 | hal/at90usb646/Descriptors.h 61 | hal/at90usb646/gpio.c 62 | hal/at90usb646/gpio_hw.h 63 | hal/at90usb646/hardware.h 64 | hal/at90usb646/LUFAConfig.h 65 | hal/at90usb646/parallel_bus.c 66 | hal/at90usb646/spi.c 67 | hal/at90usb646/spi_private.h 68 | hal/at90usb646/usbcdc.c 69 | hal/at90usb646/usbcdc_hw.h 70 | ) 71 | -------------------------------------------------------------------------------- /hal/at90usb646/board.c: -------------------------------------------------------------------------------- 1 | /* 2 | * board.c 3 | * 4 | * Created on: Nov 15, 2020 5 | * Author: Doug 6 | * 7 | * Copyright (C) 2011-2023 Doug Brown 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | * 22 | */ 23 | 24 | #include "board_hw.h" 25 | #include 26 | 27 | /// Whether we detected that the board had a brownout event 28 | static bool brownout = false; 29 | 30 | /** Initializes any board hardware-specific stuff 31 | * 32 | */ 33 | void Board_Init(void) 34 | { 35 | // Figure out if a brownout occurred 36 | if (MCUSR & (1 << BORF)) 37 | { 38 | MCUSR = 0; 39 | brownout = true; 40 | } 41 | } 42 | 43 | /** Determines if a brownout was detected at startup 44 | * 45 | * @return True if a brownout was detected 46 | */ 47 | bool Board_BrownoutDetected(void) 48 | { 49 | return brownout; 50 | } 51 | -------------------------------------------------------------------------------- /hal/at90usb646/board_hw.h: -------------------------------------------------------------------------------- 1 | /* 2 | * board_hw.h 3 | * 4 | * Created on: Nov 14, 2020 5 | * Author: Doug 6 | * 7 | * Copyright (C) 2011-2023 Doug Brown 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | * 22 | */ 23 | 24 | #ifndef HAL_AT90USB646_BOARD_HW_H_ 25 | #define HAL_AT90USB646_BOARD_HW_H_ 26 | 27 | #include "gpio_hw.h" 28 | #include "../gpio.h" 29 | #include "hardware.h" 30 | #include "../usbcdc.h" 31 | 32 | /** Gets the GPIO pin on the board that controls the status LED 33 | * 34 | * @return The status LED pin 35 | */ 36 | static inline GPIOPin Board_LEDPin(void) 37 | { 38 | return GPIO_PIN(GPIOD, 7); 39 | } 40 | 41 | /** Jumps to the bootloader 42 | * 43 | */ 44 | static inline void Board_EnterBootloader(void) 45 | { 46 | // Insert a small delay to ensure that it arrives before rebooting. 47 | DelayMS(1000); 48 | 49 | // Done with the USB interface -- the bootloader will re-initialize it. 50 | USBCDC_Disable(); 51 | 52 | // Disable interrupts so nothing weird happens... 53 | DisableInterrupts(); 54 | 55 | // Wait a little bit to let everything settle and let the program 56 | // close the port after the USB disconnect 57 | DelayMS(2000); 58 | 59 | // Jump to the correct bootloader address based on whether this is an 60 | // AT90USB128x or AT90USB64x 61 | if (IsAT90USB128x()) 62 | { 63 | __asm__ __volatile__ ( "jmp 0x1E000" ); 64 | } 65 | else 66 | { 67 | __asm__ __volatile__ ( "jmp 0xE000" ); 68 | } 69 | } 70 | 71 | #endif /* HAL_AT90USB646_BOARD_HW_H_ */ 72 | -------------------------------------------------------------------------------- /hal/at90usb646/cdc_device_definition.c: -------------------------------------------------------------------------------- 1 | /* 2 | * cdc_device_definition.c 3 | * 4 | * Created on: Dec 26, 2011 5 | * Author: Doug 6 | * 7 | * Copyright (C) 2011-2023 Doug Brown 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | * 22 | */ 23 | 24 | #include "LUFA/Drivers/USB/USB.h" 25 | #include "Descriptors.h" 26 | 27 | /// Configuration info for the USB CDC serial interface 28 | USB_ClassInfo_CDC_Device_t VirtualSerial_CDC_Interface = 29 | { 30 | .Config = { 31 | .ControlInterfaceNumber = 0, 32 | 33 | .DataINEndpointNumber = CDC_TX_EPNUM, 34 | .DataINEndpointSize = CDC_TXRX_EPSIZE, 35 | .DataINEndpointDoubleBank = true, 36 | 37 | .DataOUTEndpointNumber = CDC_RX_EPNUM, 38 | .DataOUTEndpointSize = CDC_TXRX_EPSIZE, 39 | .DataOUTEndpointDoubleBank = true, 40 | 41 | .NotificationEndpointNumber = CDC_NOTIFICATION_EPNUM, 42 | .NotificationEndpointSize = CDC_NOTIFICATION_EPSIZE, 43 | .NotificationEndpointDoubleBank = false, 44 | }, 45 | }; 46 | -------------------------------------------------------------------------------- /hal/at90usb646/cdc_device_definition.h: -------------------------------------------------------------------------------- 1 | /* 2 | * cdc_device_definition.h 3 | * 4 | * Created on: Dec 26, 2011 5 | * Author: Doug 6 | * 7 | * Copyright (C) 2011-2023 Doug Brown 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | * 22 | */ 23 | 24 | #ifndef CDC_DEVICE_DEFINITION_H_ 25 | #define CDC_DEVICE_DEFINITION_H_ 26 | 27 | extern USB_ClassInfo_CDC_Device_t VirtualSerial_CDC_Interface; 28 | 29 | #endif /* CDC_DEVICE_DEFINITION_H_ */ 30 | -------------------------------------------------------------------------------- /hal/at90usb646/gpio.c: -------------------------------------------------------------------------------- 1 | /* 2 | * gpio.c 3 | * 4 | * Created on: Nov 14, 2020 5 | * Author: Doug 6 | * 7 | * Copyright (C) 2011-2023 Doug Brown 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | * 22 | */ 23 | 24 | #include "../gpio.h" 25 | #include 26 | 27 | /// Struct representing the registers belonging to an AVR's GPIO port 28 | typedef struct AVRGPIORegs 29 | { 30 | /// Address of the PORT register for setting output value or enabling pullups 31 | volatile uint8_t *port; 32 | /// Address of the PIN register for reading input value or toggling outputs 33 | volatile uint8_t *pin; 34 | /// Address of the DDR register for setting whether pins are input or output 35 | volatile uint8_t *ddr; 36 | } AVRGPIORegs; 37 | 38 | /// The GPIO ports available on the AVR 39 | static AVRGPIORegs const gpioRegs[] = { 40 | {&PORTA, &PINA, &DDRA}, 41 | {&PORTB, &PINB, &DDRB}, 42 | {&PORTC, &PINC, &DDRC}, 43 | {&PORTD, &PIND, &DDRD}, 44 | {&PORTE, &PINE, &DDRE}, 45 | {&PORTF, &PINF, &DDRF}, 46 | }; 47 | 48 | /** Sets the direction of a GPIO pin. 49 | * 50 | * @param pin The pin 51 | * @param output True if it should be an output, false if it should be an input 52 | */ 53 | void GPIO_SetDirection(GPIOPin pin, bool output) 54 | { 55 | if (output) 56 | { 57 | *(gpioRegs[pin.port].ddr) |= (1 << pin.pin); 58 | } 59 | else 60 | { 61 | *(gpioRegs[pin.port].ddr) &= ~(1 << pin.pin); 62 | } 63 | } 64 | 65 | /** Sets whether an input GPIO pin is pulled up 66 | * 67 | * @param pin The pin 68 | * @param pullup True if it should be pulled up, false if not 69 | */ 70 | void GPIO_SetPullup(GPIOPin pin, bool pullup) 71 | { 72 | // On the AVR, you set pullups using the PORT register that is ordinarily 73 | // used for setting the output value. You just have to make sure the pin 74 | // is configured as an input first. Otherwise you will modify the output. 75 | GPIO_Set(pin, pullup); 76 | } 77 | 78 | /** 79 | * @brief Sets whether an input GPIO pin is pulled down 80 | * @param pin The pin 81 | * @param pulldown True if it should be pulled down, false if not 82 | */ 83 | void GPIO_SetPulldown(GPIOPin pin, bool pulldown) 84 | { 85 | (void)pin; 86 | (void)pulldown; 87 | // The AVR doesn't support pulldowns 88 | } 89 | 90 | /** Turns a GPIO pin on (sets it high) 91 | * 92 | * @param pin The pin 93 | */ 94 | void GPIO_SetOn(GPIOPin pin) 95 | { 96 | *(gpioRegs[pin.port].port) |= (1 << pin.pin); 97 | } 98 | 99 | /** Turns a GPIO pin off (sets it low) 100 | * 101 | * @param pin The pin 102 | */ 103 | void GPIO_SetOff(GPIOPin pin) 104 | { 105 | *(gpioRegs[pin.port].port) &= ~(1 << pin.pin); 106 | } 107 | 108 | /** Toggles a GPIO pin 109 | * 110 | * @param pin The pin 111 | */ 112 | void GPIO_Toggle(GPIOPin pin) 113 | { 114 | // This is a tricky little hack the AVR provides that allows toggling 115 | // without a read/modify/write operation. 116 | *(gpioRegs[pin.port].pin) = (1 << pin.pin); 117 | } 118 | 119 | /** Reads the input status of a GPIO pin 120 | * 121 | * @param pin The pin 122 | * @return True if it's high, false if it's low 123 | */ 124 | bool GPIO_Read(GPIOPin pin) 125 | { 126 | return *(gpioRegs[pin.port].pin) & (1 << pin.pin); 127 | } 128 | -------------------------------------------------------------------------------- /hal/at90usb646/gpio_hw.h: -------------------------------------------------------------------------------- 1 | /* 2 | * gpio_hw.h 3 | * 4 | * Created on: Nov 14, 2020 5 | * Author: Doug 6 | * 7 | * Copyright (C) 2011-2023 Doug Brown 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | * 22 | */ 23 | 24 | #ifndef HAL_AT90USB646_GPIO_HW_H_ 25 | #define HAL_AT90USB646_GPIO_HW_H_ 26 | 27 | /// Enum representing the different GPIO ports available on the AVR. 28 | /// Used with the GPIOPin struct. 29 | enum { 30 | GPIOA, 31 | GPIOB, 32 | GPIOC, 33 | GPIOD, 34 | GPIOE, 35 | GPIOF 36 | }; 37 | 38 | #endif /* HAL_AT90USB646_GPIO_HW_H_ */ 39 | -------------------------------------------------------------------------------- /hal/at90usb646/hardware.h: -------------------------------------------------------------------------------- 1 | /* 2 | * hardware.h 3 | * 4 | * Created on: Dec 4, 2011 5 | * Author: Doug 6 | * 7 | * Copyright (C) 2011-2023 Doug Brown 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | * 22 | */ 23 | 24 | #ifndef HAL_AT90USB646_HARDWARE_H_ 25 | #define HAL_AT90USB646_HARDWARE_H_ 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | /** Disables interrupts 33 | * 34 | */ 35 | static inline void DisableInterrupts(void) 36 | { 37 | cli(); 38 | } 39 | 40 | /** Enables interrupts 41 | * 42 | */ 43 | static inline void EnableInterrupts(void) 44 | { 45 | sei(); 46 | } 47 | 48 | /** Blocks for the specified number of milliseconds 49 | * 50 | * @param ms The number of milliseconds to wait 51 | */ 52 | static inline void DelayMS(uint16_t ms) 53 | { 54 | _delay_ms(ms); 55 | } 56 | 57 | /** Blocks for the specified number of microseconds 58 | * 59 | * @param us The number of microseconds to wait 60 | */ 61 | static inline void DelayUS(uint16_t us) 62 | { 63 | _delay_us(us); 64 | } 65 | 66 | /** Determines if this code is running on an AT90USB128x or AT90USB64x 67 | * 68 | * @return True if it's an AT90USB128x, false if AT90USB64x 69 | */ 70 | static inline bool IsAT90USB128x(void) 71 | { 72 | // Read the device signature byte 2 to determine whether this is an 73 | // AT90USB128x or AT90USB64x. 74 | return boot_signature_byte_get(0x0002) == 0x97; 75 | } 76 | 77 | #endif /* HAL_AT90USB646_HARDWARE_H_ */ 78 | -------------------------------------------------------------------------------- /hal/at90usb646/spi_private.h: -------------------------------------------------------------------------------- 1 | /* 2 | * spi_private.h 3 | * 4 | * Created on: Nov 14, 2020 5 | * Author: Doug 6 | * 7 | * Copyright (C) 2011-2023 Doug Brown 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | * 22 | */ 23 | 24 | #ifndef HAL_AT90USB646_SPI_PRIVATE_H_ 25 | #define HAL_AT90USB646_SPI_PRIVATE_H_ 26 | 27 | /// Private data for an SPI device on the AT90USB646 28 | typedef struct SPIDevicePrivate 29 | { 30 | /// Value to write into the SPCR register (contains timing/mode info) 31 | uint8_t spcr; 32 | /// Value to write into the SPSR register (contains timing info) 33 | uint8_t spsr; 34 | } SPIDevicePrivate; 35 | 36 | #endif /* HAL_AT90USB646_SPI_PRIVATE_H_ */ 37 | -------------------------------------------------------------------------------- /hal/at90usb646/usbcdc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * usbcdc.c 3 | * 4 | * Created on: Nov 22, 2020 5 | * Author: Doug 6 | * 7 | * Copyright (C) 2011-2023 Doug Brown 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | * 22 | */ 23 | 24 | #include "../usbcdc.h" 25 | #include "LUFA/Drivers/USB/USB.h" 26 | #include "cdc_device_definition.h" 27 | #include "hardware.h" 28 | 29 | /** Initializes the USB CDC device 30 | * 31 | */ 32 | void USBCDC_Init(void) 33 | { 34 | // Initialize LUFA. 35 | // We have to manually start the USB PLL rather than allow LUFA to do it, 36 | // because we might be on an AT90USB128x instead of AT90USB64x, and LUFA's 37 | // automatic PLL control decides on the PLL init value at compile time. 38 | // It differs between the two chips when there's a 16 MHz crystal. 39 | if (IsAT90USB128x()) 40 | { 41 | PLLCSR = (1 << PLLP2) | (1 << PLLP0); 42 | PLLCSR = ((1 << PLLP2) | (1 << PLLP0) | (1 << PLLE)); 43 | } 44 | else 45 | { 46 | PLLCSR = (1 << PLLP2) | (1 << PLLP1); 47 | PLLCSR = ((1 << PLLP2) | (1 << PLLP1) | (1 << PLLE)); 48 | } 49 | while (!USB_PLL_IsReady()); 50 | USB_Init(); 51 | } 52 | 53 | /** Disables the USB CDC device 54 | * 55 | */ 56 | void USBCDC_Disable(void) 57 | { 58 | // Disable LUFA, this will cause us to no longer identify as a USB device 59 | USB_Disable(); 60 | USB_PLL_Off(); 61 | } 62 | 63 | /** Main loop handler for the USB CDC device. Call from the main loop. 64 | * 65 | */ 66 | void USBCDC_Check(void) 67 | { 68 | // Do the periodic CDC and USB tasks in LUFA 69 | CDC_Device_USBTask(&VirtualSerial_CDC_Interface); 70 | USB_USBTask(); 71 | } 72 | 73 | /** LUFA event handler for when the USB configuration changes. 74 | * 75 | */ 76 | void EVENT_USB_Device_ConfigurationChanged(void) 77 | { 78 | bool ConfigSuccess = true; 79 | 80 | ConfigSuccess &= CDC_Device_ConfigureEndpoints(&VirtualSerial_CDC_Interface); 81 | } 82 | 83 | /** LUFA event handler for when a USB control request is received 84 | * 85 | */ 86 | void EVENT_USB_Device_ControlRequest(void) 87 | { 88 | CDC_Device_ProcessControlRequest(&VirtualSerial_CDC_Interface); 89 | } 90 | -------------------------------------------------------------------------------- /hal/at90usb646/usbcdc_hw.h: -------------------------------------------------------------------------------- 1 | /* 2 | * usbcdc_hw.h 3 | * 4 | * Created on: Nov 22, 2020 5 | * Author: Doug 6 | * 7 | * Copyright (C) 2011-2023 Doug Brown 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | * 22 | */ 23 | 24 | #ifndef HAL_AT90USB646_USBCDC_HW_H_ 25 | #define HAL_AT90USB646_USBCDC_HW_H_ 26 | 27 | #include "LUFA/Drivers/USB/USB.h" 28 | #include "cdc_device_definition.h" 29 | #include "../../util.h" 30 | 31 | /** Sends a byte over the USB CDC serial port 32 | * 33 | * @param byte The byte to send 34 | */ 35 | static ALWAYS_INLINE void USBCDC_SendByte(uint8_t byte) 36 | { 37 | CDC_Device_SendByte(&VirtualSerial_CDC_Interface, byte); 38 | } 39 | 40 | /** Sends a block of data over the USB CDC serial port 41 | * 42 | * @param data The data to send 43 | * @param len The number of bytes 44 | * @return True on success, false on failure 45 | */ 46 | static ALWAYS_INLINE bool USBCDC_SendData(uint8_t const *data, uint16_t len) 47 | { 48 | return CDC_Device_SendData(&VirtualSerial_CDC_Interface, (char const *)data, len) == ENDPOINT_RWSTREAM_NoError; 49 | } 50 | 51 | /** Attempts to read a byte from the USB CDC serial port 52 | * 53 | * @return The byte read, or -1 if there are no bytes available 54 | */ 55 | static ALWAYS_INLINE int16_t USBCDC_ReadByte(void) 56 | { 57 | return CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface); 58 | } 59 | 60 | /** Reads a byte from the USB CDC serial port. Blocks until one is available. 61 | * 62 | * @return The byte read 63 | */ 64 | static ALWAYS_INLINE uint8_t USBCDC_ReadByteBlocking(void) 65 | { 66 | int16_t b; 67 | do 68 | { 69 | b = USBCDC_ReadByte(); 70 | } while (b < 0); 71 | return (uint8_t)b; 72 | } 73 | 74 | /** Forces any transmitted data to be sent over USB immediately 75 | * 76 | */ 77 | static ALWAYS_INLINE inline void USBCDC_Flush(void) 78 | { 79 | CDC_Device_Flush(&VirtualSerial_CDC_Interface); 80 | } 81 | 82 | #endif /* HAL_AT90USB646_USBCDC_HW_H_ */ 83 | -------------------------------------------------------------------------------- /hal/board.h: -------------------------------------------------------------------------------- 1 | /* 2 | * board.h 3 | * 4 | * Created on: Nov 14, 2020 5 | * Author: Doug 6 | * 7 | * Copyright (C) 2011-2023 Doug Brown 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | * 22 | */ 23 | 24 | #ifndef HAL_BOARD_H_ 25 | #define HAL_BOARD_H_ 26 | 27 | #include "gpio.h" 28 | #include "spi.h" 29 | 30 | // Commented-out functions should be static inline in each board-specific header file. 31 | //GPIOPin Board_LEDPin(void); 32 | //void Board_EnterBootloader(void); 33 | #include "board_hw.h" 34 | 35 | void Board_Init(void); 36 | bool Board_BrownoutDetected(void); 37 | 38 | #endif /* HAL_BOARD_H_ */ 39 | -------------------------------------------------------------------------------- /hal/gpio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * gpio.h 3 | * 4 | * Created on: Nov 14, 2020 5 | * Author: Doug 6 | * 7 | * Copyright (C) 2011-2023 Doug Brown 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | * 22 | */ 23 | 24 | #ifndef HAL_GPIO_H_ 25 | #define HAL_GPIO_H_ 26 | 27 | #include 28 | #include 29 | 30 | /// Creates a temporary GPIOPin struct. Used when assigning to a GPIOPin variable. 31 | #define GPIO_PIN(port, pin) ((GPIOPin){port, pin}) 32 | /// A NULL GPIO pin 33 | #define GPIO_PIN_NULL ((GPIOPin){0xFF, 0xFF}) 34 | 35 | /// The GPIO pin struct 36 | typedef struct GPIOPin 37 | { 38 | /// The port the pin belongs to 39 | uint8_t port; 40 | /// The index of the pin on the port 41 | uint8_t pin; 42 | } GPIOPin; 43 | 44 | void GPIO_SetDirection(GPIOPin pin, bool output); 45 | void GPIO_SetPullup(GPIOPin pin, bool pullup); 46 | void GPIO_SetPulldown(GPIOPin pin, bool pulldown); 47 | void GPIO_SetOn(GPIOPin pin); 48 | void GPIO_SetOff(GPIOPin pin); 49 | void GPIO_Toggle(GPIOPin pin); 50 | bool GPIO_Read(GPIOPin pin); 51 | 52 | /** Sets whether a GPIO pin is outputting high or low 53 | * 54 | * @param pin The pin 55 | * @param on True if it's high, false if it's low 56 | */ 57 | static inline void GPIO_Set(GPIOPin pin, bool on) 58 | { 59 | on ? GPIO_SetOn(pin) : GPIO_SetOff(pin); 60 | } 61 | 62 | /** Determines if a GPIO pin is null 63 | * 64 | * @param pin The pin 65 | * @return True if it's null, false if not 66 | */ 67 | static inline bool GPIO_IsNull(GPIOPin pin) 68 | { 69 | return pin.pin == 0xFF && pin.port == 0xFF; 70 | } 71 | 72 | #endif /* HAL_GPIO_H_ */ 73 | -------------------------------------------------------------------------------- /hal/m258ke/board.c: -------------------------------------------------------------------------------- 1 | /* 2 | * board.c 3 | * 4 | * Created on: Jun 19, 2023 5 | * Author: Doug 6 | * 7 | * Copyright (C) 2011-2023 Doug Brown 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | * 22 | */ 23 | 24 | #include "board_hw.h" 25 | 26 | /** Initializes any board hardware-specific stuff 27 | * 28 | */ 29 | void Board_Init(void) 30 | { 31 | // Unlock protected registers so we can configure clocks, flash, WDT, etc. 32 | do 33 | { 34 | SYS->REGLCTL = 0x59UL; 35 | SYS->REGLCTL = 0x16UL; 36 | SYS->REGLCTL = 0x88UL; 37 | } while (SYS->REGLCTL == 0UL); 38 | 39 | // Enable 48 MHz internal high-speed RC oscillator 40 | CLK->PWRCTL |= CLK_PWRCTL_HIRCEN_Msk; 41 | 42 | // Wait until it's ready 43 | while (!(CLK->STATUS & CLK_STATUS_HIRCSTB_Msk)); 44 | 45 | // Clock HCLK and USB from 48 MHz HIRC 46 | CLK->CLKSEL0 = (CLK->CLKSEL0 & (~(CLK_CLKSEL0_HCLKSEL_Msk | CLK_CLKSEL0_USBDSEL_Msk))) | 47 | (7 << CLK_CLKSEL0_HCLKSEL_Pos) | (0 << CLK_CLKSEL0_USBDSEL_Pos); 48 | 49 | // SystemCoreClock, CyclesPerUs, CyclesPerUs default to correct values already 50 | 51 | // Enable USB device controller 52 | CLK->APBCLK0 |= CLK_APBCLK0_USBDCKEN_Msk; 53 | 54 | // Enable timer 0 55 | CLK->APBCLK0 |= CLK_APBCLK0_TMR0CKEN_Msk; 56 | 57 | // Timer 0 clock source = 48 MHz HIRC 58 | CLK->CLKSEL1 = (CLK->CLKSEL1 & (~(CLK_CLKSEL1_TMR0SEL_Msk))) | (7UL << CLK_CLKSEL1_TMR0SEL_Pos); 59 | 60 | // Enable all GPIO 61 | CLK->AHBCLK |= 62 | CLK_AHBCLK_GPACKEN_Msk | 63 | CLK_AHBCLK_GPBCKEN_Msk | 64 | CLK_AHBCLK_GPCCKEN_Msk | 65 | CLK_AHBCLK_GPDCKEN_Msk | 66 | CLK_AHBCLK_GPECKEN_Msk | 67 | CLK_AHBCLK_GPFCKEN_Msk; 68 | 69 | // Start the timer, prescaler = 48, so 1 MHz 70 | TIMER0->CTL = TIMER_CTL_CNTEN_Msk | (3UL << TIMER_CTL_OPMODE_Pos) | 47; 71 | 72 | // Disable WDT now; the main firmware is booted. 73 | WDT->CTL = (6 << WDT_CTL_TOUTSEL_Pos); 74 | } 75 | 76 | /** Determines if a brownout was detected at startup 77 | * 78 | * @return True if a brownout was detected 79 | */ 80 | bool Board_BrownoutDetected(void) 81 | { 82 | return false; 83 | } 84 | -------------------------------------------------------------------------------- /hal/m258ke/board_hw.h: -------------------------------------------------------------------------------- 1 | /* 2 | * board_hw.h 3 | * 4 | * Created on: Jun 19, 2023 5 | * Author: Doug 6 | * 7 | * Copyright (C) 2011-2023 Doug Brown 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | * 22 | */ 23 | 24 | #ifndef HAL_M258KE_BOARD_HW_H_ 25 | #define HAL_M258KE_BOARD_HW_H_ 26 | 27 | #include "gpio_hw.h" 28 | #include "../gpio.h" 29 | #include "hardware.h" 30 | #include "../usbcdc.h" 31 | 32 | #define BOARD_LED_INVERTED true 33 | #define BOARD_SUPPORTS_PULLDOWNS true 34 | 35 | /** Gets the GPIO pin on the board that controls the status LED 36 | * 37 | * @return The status LED pin 38 | */ 39 | static inline GPIOPin Board_LEDPin(void) 40 | { 41 | return GPIO_PIN(GPIOC, 9); 42 | } 43 | 44 | /** Jumps to the bootloader 45 | * 46 | */ 47 | static inline void Board_EnterBootloader(void) 48 | { 49 | // Insert a small delay to ensure that it arrives before rebooting. 50 | DelayMS(1000); 51 | 52 | // Disable interrupts so nothing weird happens... 53 | DisableInterrupts(); 54 | 55 | // Done with the USB interface -- the bootloader will re-initialize it. 56 | USBCDC_Disable(); 57 | 58 | // Wait a little bit to let everything settle and let the program 59 | // close the port after the USB disconnect 60 | DelayMS(2000); 61 | 62 | // Clear reset status bits so that bootloader knows reset reason 63 | SYS->RSTSTS = (SYS_RSTSTS_PORF_Msk | SYS_RSTSTS_PINRF_Msk); 64 | 65 | // Boot to LDROM next time 66 | FMC->ISPCTL |= FMC_ISPCTL_BS_Msk; 67 | 68 | // Save a special flag in RAM to indicate we want to stay in the bootloader 69 | *(uint32_t *)(0x20003FFC) = 0xBADF00D5; 70 | 71 | // Reset! 72 | NVIC_SystemReset(); 73 | 74 | // Should never get here, but just in case... 75 | while (1); 76 | } 77 | 78 | #endif /* HAL_M258KE_BOARD_HW_H_ */ 79 | -------------------------------------------------------------------------------- /hal/m258ke/gpio.c: -------------------------------------------------------------------------------- 1 | /* 2 | * gpio.c 3 | * 4 | * Created on: Jun 19, 2023 5 | * Author: Doug 6 | * 7 | * Copyright (C) 2011-2023 Doug Brown 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | * 22 | */ 23 | 24 | #include "../gpio.h" 25 | #include "nuvoton/NuMicro.h" 26 | 27 | /// The GPIO ports available on the M258KE 28 | static GPIO_T * const gpioRegs[] = { 29 | PA, 30 | PB, 31 | PC, 32 | PD, 33 | PE, 34 | PF 35 | }; 36 | 37 | /** Sets the direction of a GPIO pin. 38 | * 39 | * @param pin The pin 40 | * @param output True if it should be an output, false if it should be an input 41 | */ 42 | void GPIO_SetDirection(GPIOPin pin, bool output) 43 | { 44 | if (output) 45 | { 46 | uint32_t tmp = gpioRegs[pin.port]->MODE; 47 | tmp &= ~(2UL << 2*pin.pin); 48 | tmp |= (1UL << 2*pin.pin); 49 | gpioRegs[pin.port]->MODE = tmp; 50 | } 51 | else 52 | { 53 | gpioRegs[pin.port]->MODE &= ~(3UL << 2*pin.pin); 54 | } 55 | } 56 | 57 | /** Sets whether an input GPIO pin is pulled up 58 | * 59 | * @param pin The pin 60 | * @param pullup True if it should be pulled up, false if not 61 | */ 62 | void GPIO_SetPullup(GPIOPin pin, bool pullup) 63 | { 64 | if (pullup) 65 | { 66 | uint32_t tmp = gpioRegs[pin.port]->PUSEL; 67 | tmp |= (1UL << 2*pin.pin); 68 | gpioRegs[pin.port]->PUSEL = tmp; 69 | } 70 | else 71 | { 72 | gpioRegs[pin.port]->PUSEL &= ~(1UL << 2*pin.pin); 73 | } 74 | } 75 | 76 | /** Sets whether an input GPIO pin is pulled down 77 | * 78 | * @param pin The pin 79 | * @param pulldown True if it should be pulled down, false if not 80 | */ 81 | void GPIO_SetPulldown(GPIOPin pin, bool pulldown) 82 | { 83 | if (pulldown) 84 | { 85 | uint32_t tmp = gpioRegs[pin.port]->PUSEL; 86 | tmp |= (2UL << 2*pin.pin); 87 | gpioRegs[pin.port]->PUSEL = tmp; 88 | } 89 | else 90 | { 91 | gpioRegs[pin.port]->PUSEL &= ~(2UL << 2*pin.pin); 92 | } 93 | } 94 | 95 | /** Turns a GPIO pin on (sets it high) 96 | * 97 | * @param pin The pin 98 | */ 99 | void GPIO_SetOn(GPIOPin pin) 100 | { 101 | gpioRegs[pin.port]->DOUT |= (1 << pin.pin); 102 | } 103 | 104 | /** Turns a GPIO pin off (sets it low) 105 | * 106 | * @param pin The pin 107 | */ 108 | void GPIO_SetOff(GPIOPin pin) 109 | { 110 | gpioRegs[pin.port]->DOUT &= ~(1 << pin.pin); 111 | } 112 | 113 | /** Toggles a GPIO pin 114 | * 115 | * @param pin The pin 116 | */ 117 | void GPIO_Toggle(GPIOPin pin) 118 | { 119 | gpioRegs[pin.port]->DOUT ^= (1 << pin.pin); 120 | } 121 | 122 | /** Reads the input status of a GPIO pin 123 | * 124 | * @param pin The pin 125 | * @return True if it's high, false if it's low 126 | */ 127 | bool GPIO_Read(GPIOPin pin) 128 | { 129 | return gpioRegs[pin.port]->PIN & (1 << pin.pin); 130 | } 131 | -------------------------------------------------------------------------------- /hal/m258ke/gpio_hw.h: -------------------------------------------------------------------------------- 1 | /* 2 | * gpio_hw.h 3 | * 4 | * Created on: Jun 19, 2023 5 | * Author: Doug 6 | * 7 | * Copyright (C) 2011-2023 Doug Brown 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | * 22 | */ 23 | 24 | #ifndef HAL_M258KE_GPIO_HW_H_ 25 | #define HAL_M258KE_GPIO_HW_H_ 26 | 27 | /// Enum representing the different GPIO ports available on the M258KE. 28 | /// Used with the GPIOPin struct. 29 | enum { 30 | GPIOA, 31 | GPIOB, 32 | GPIOC, 33 | GPIOD, 34 | GPIOE, 35 | GPIOF 36 | }; 37 | 38 | #endif /* HAL_M258KE_GPIO_HW_H_ */ 39 | -------------------------------------------------------------------------------- /hal/m258ke/hardware.h: -------------------------------------------------------------------------------- 1 | /* 2 | * hardware.h 3 | * 4 | * Created on: Jun 19, 2023 5 | * Author: Doug 6 | * 7 | * Copyright (C) 2011-2023 Doug Brown 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | * 22 | */ 23 | 24 | #ifndef HAL_M258KE_HARDWARE_H_ 25 | #define HAL_M258KE_HARDWARE_H_ 26 | 27 | #include 28 | #include 29 | #include "nuvoton/NuMicro.h" 30 | 31 | /** Disables interrupts 32 | * 33 | */ 34 | static inline void DisableInterrupts(void) 35 | { 36 | __disable_irq(); 37 | } 38 | 39 | /** Enables interrupts 40 | * 41 | */ 42 | static inline void EnableInterrupts(void) 43 | { 44 | __enable_irq(); 45 | } 46 | 47 | /** Blocks for the specified number of microseconds 48 | * 49 | * @param us The number of microseconds to wait 50 | */ 51 | static inline void DelayUS(uint32_t us) 52 | { 53 | const uint32_t startTime = TIMER0->CNT & 0xFFFFFFUL; 54 | uint32_t nowTime; 55 | do 56 | { 57 | nowTime = TIMER0->CNT & 0xFFFFFFUL; 58 | } while (((nowTime - startTime) & 0xFFFFFFUL) < us); 59 | } 60 | 61 | /** Blocks for the specified number of milliseconds 62 | * 63 | * @param ms The number of milliseconds to wait 64 | */ 65 | static inline void DelayMS(uint32_t ms) 66 | { 67 | DelayUS(ms * 1000UL); 68 | } 69 | 70 | #endif /* HAL_M258KE_HARDWARE_H_ */ 71 | -------------------------------------------------------------------------------- /hal/m258ke/m258ke_options.cmake: -------------------------------------------------------------------------------- 1 | # M258KE-specific include paths 2 | target_include_directories(SIMMProgrammer.elf PRIVATE 3 | hal/m258ke 4 | ) 5 | 6 | # M258KE-specific compiler definitions 7 | target_compile_definitions(SIMMProgrammer.elf PRIVATE 8 | ) 9 | 10 | # M258KE-specific compiler options 11 | target_compile_options(SIMMProgrammer.elf PRIVATE 12 | -mcpu=cortex-m23 -march=armv8-m.base -mthumb 13 | ) 14 | 15 | # M258KE-specific linker options 16 | target_link_options(SIMMProgrammer.elf PRIVATE 17 | -mcpu=cortex-m23 -march=armv8-m.base -mthumb 18 | -T ${CMAKE_SOURCE_DIR}/hal/m258ke/nuvoton/gcc_arm.ld 19 | --specs=nano.specs 20 | ) 21 | 22 | # M258KE-specific command/target to generate .bin file from the ELF file. This program 23 | # is flashed using a bootloader, so there's no need to generate a HEX file. 24 | add_custom_command(OUTPUT SIMMProgrammer.bin 25 | COMMAND ${CMAKE_OBJCOPY} -O binary SIMMProgrammer.elf SIMMProgrammer.bin 26 | DEPENDS SIMMProgrammer.elf 27 | ) 28 | add_custom_target(SIMMProgrammer_bin ALL DEPENDS SIMMProgrammer.bin) 29 | -------------------------------------------------------------------------------- /hal/m258ke/m258ke_sources.cmake: -------------------------------------------------------------------------------- 1 | set(HWSOURCES 2 | hal/m258ke/nuvoton/core_cm23.h 3 | hal/m258ke/nuvoton/cmsis_armcc.h 4 | hal/m258ke/nuvoton/cmsis_armclang.h 5 | hal/m258ke/nuvoton/cmsis_compiler.h 6 | hal/m258ke/nuvoton/cmsis_gcc.h 7 | hal/m258ke/nuvoton/cmsis_version.h 8 | 9 | hal/m258ke/nuvoton/NuMicro.h 10 | hal/m258ke/nuvoton/M251.h 11 | hal/m258ke/nuvoton/system_M251.c 12 | hal/m258ke/nuvoton/system_M251.h 13 | hal/m258ke/nuvoton/startup_M251.S 14 | 15 | hal/m258ke/nuvoton/acmp_reg.h 16 | hal/m258ke/nuvoton/bpwm_reg.h 17 | hal/m258ke/nuvoton/clk_reg.h 18 | hal/m258ke/nuvoton/crc_reg.h 19 | hal/m258ke/nuvoton/crypto_reg.h 20 | hal/m258ke/nuvoton/dac_reg.h 21 | hal/m258ke/nuvoton/eadc_reg.h 22 | hal/m258ke/nuvoton/ebi_reg.h 23 | hal/m258ke/nuvoton/fmc_reg.h 24 | hal/m258ke/nuvoton/gpio_reg.h 25 | hal/m258ke/nuvoton/i2c_reg.h 26 | hal/m258ke/nuvoton/lcd_reg.h 27 | hal/m258ke/nuvoton/opa_reg.h 28 | hal/m258ke/nuvoton/pdma_reg.h 29 | hal/m258ke/nuvoton/psio_reg.h 30 | hal/m258ke/nuvoton/pwm_reg.h 31 | hal/m258ke/nuvoton/qspi_reg.h 32 | hal/m258ke/nuvoton/rtc_reg.h 33 | hal/m258ke/nuvoton/sc_reg.h 34 | hal/m258ke/nuvoton/spi_reg.h 35 | hal/m258ke/nuvoton/sys_reg.h 36 | hal/m258ke/nuvoton/timer_reg.h 37 | hal/m258ke/nuvoton/tk_reg.h 38 | hal/m258ke/nuvoton/uart_reg.h 39 | hal/m258ke/nuvoton/ui2c_reg.h 40 | hal/m258ke/nuvoton/usbd_reg.h 41 | hal/m258ke/nuvoton/uspi_reg.h 42 | hal/m258ke/nuvoton/uuart_reg.h 43 | hal/m258ke/nuvoton/wdt_reg.h 44 | hal/m258ke/nuvoton/wwdt_reg.h 45 | 46 | hal/m258ke/nuvoton/usbd.c 47 | hal/m258ke/nuvoton/usbd.h 48 | 49 | hal/m258ke/board.c 50 | hal/m258ke/board_hw.h 51 | hal/m258ke/descriptors.c 52 | hal/m258ke/gpio.c 53 | hal/m258ke/gpio_hw.h 54 | hal/m258ke/hardware.h 55 | hal/m258ke/parallel_bus.c 56 | hal/m258ke/spi.c 57 | hal/m258ke/spi_private.h 58 | hal/m258ke/usbcdc.c 59 | hal/m258ke/usbcdc_hw.h 60 | ) 61 | -------------------------------------------------------------------------------- /hal/m258ke/nuvoton/LDROM.ld: -------------------------------------------------------------------------------- 1 | /* Linker script to configure memory regions. */ 2 | MEMORY 3 | { 4 | FLASH (rx) : ORIGIN = 0x00100000, LENGTH = 4*1024 5 | RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 16*1024 6 | } 7 | 8 | /* Library configurations */ 9 | GROUP(libgcc.a libc.a libm.a libnosys.a) 10 | 11 | /* Linker script to place sections and symbol values. Should be used together 12 | * with other linker script that defines memory regions FLASH and RAM. 13 | * It references following symbols, which must be defined in code: 14 | * Reset_Handler : Entry of reset handler 15 | * 16 | * It defines following symbols, which code can use without definition: 17 | * __exidx_start 18 | * __exidx_end 19 | * __copy_table_start__ 20 | * __copy_table_end__ 21 | * __zero_table_start__ 22 | * __zero_table_end__ 23 | * __etext 24 | * __data_start__ 25 | * __preinit_array_start 26 | * __preinit_array_end 27 | * __init_array_start 28 | * __init_array_end 29 | * __fini_array_start 30 | * __fini_array_end 31 | * __data_end__ 32 | * __bss_start__ 33 | * __bss_end__ 34 | * __end__ 35 | * end 36 | * __HeapLimit 37 | * __StackLimit 38 | * __StackTop 39 | * __stack 40 | * __Vectors_End 41 | * __Vectors_Size 42 | */ 43 | ENTRY(Reset_Handler) 44 | 45 | SECTIONS 46 | { 47 | .text : 48 | { 49 | KEEP(*(.vectors)) 50 | __Vectors_End = .; 51 | __Vectors_Size = __Vectors_End - __Vectors; 52 | __end__ = .; 53 | 54 | *(.text*) 55 | 56 | KEEP(*(.init)) 57 | KEEP(*(.fini)) 58 | 59 | /* .ctors */ 60 | *crtbegin.o(.ctors) 61 | *crtbegin?.o(.ctors) 62 | *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors) 63 | *(SORT(.ctors.*)) 64 | *(.ctors) 65 | 66 | /* .dtors */ 67 | *crtbegin.o(.dtors) 68 | *crtbegin?.o(.dtors) 69 | *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors) 70 | *(SORT(.dtors.*)) 71 | *(.dtors) 72 | 73 | *(.rodata*) 74 | 75 | KEEP(*(.eh_frame*)) 76 | } > FLASH 77 | 78 | .ARM.extab : 79 | { 80 | *(.ARM.extab* .gnu.linkonce.armextab.*) 81 | } > FLASH 82 | 83 | __exidx_start = .; 84 | .ARM.exidx : 85 | { 86 | *(.ARM.exidx* .gnu.linkonce.armexidx.*) 87 | } > FLASH 88 | __exidx_end = .; 89 | 90 | /* To copy multiple ROM to RAM sections, 91 | * uncomment .copy.table section and, 92 | * define __STARTUP_COPY_MULTIPLE in startup_ARMCMx.S */ 93 | /* 94 | .copy.table : 95 | { 96 | . = ALIGN(4); 97 | __copy_table_start__ = .; 98 | LONG (__etext) 99 | LONG (__data_start__) 100 | LONG (__data_end__ - __data_start__) 101 | LONG (__etext2) 102 | LONG (__data2_start__) 103 | LONG (__data2_end__ - __data2_start__) 104 | __copy_table_end__ = .; 105 | } > FLASH 106 | */ 107 | 108 | /* To clear multiple BSS sections, 109 | * uncomment .zero.table section and, 110 | * define __STARTUP_CLEAR_BSS_MULTIPLE in startup_ARMCMx.S */ 111 | /* 112 | .zero.table : 113 | { 114 | . = ALIGN(4); 115 | __zero_table_start__ = .; 116 | LONG (__bss_start__) 117 | LONG (__bss_end__ - __bss_start__) 118 | LONG (__bss2_start__) 119 | LONG (__bss2_end__ - __bss2_start__) 120 | __zero_table_end__ = .; 121 | } > FLASH 122 | */ 123 | 124 | __etext = .; 125 | 126 | .data : ALIGN(4) 127 | { 128 | __data_start__ = .; 129 | *(vtable) 130 | *(.data*) 131 | 132 | . = ALIGN(4); 133 | /* preinit data */ 134 | PROVIDE_HIDDEN (__preinit_array_start = .); 135 | KEEP(*(.preinit_array)) 136 | PROVIDE_HIDDEN (__preinit_array_end = .); 137 | 138 | . = ALIGN(4); 139 | /* init data */ 140 | PROVIDE_HIDDEN (__init_array_start = .); 141 | KEEP(*(SORT(.init_array.*))) 142 | KEEP(*(.init_array)) 143 | PROVIDE_HIDDEN (__init_array_end = .); 144 | 145 | 146 | . = ALIGN(4); 147 | /* finit data */ 148 | PROVIDE_HIDDEN (__fini_array_start = .); 149 | KEEP(*(SORT(.fini_array.*))) 150 | KEEP(*(.fini_array)) 151 | PROVIDE_HIDDEN (__fini_array_end = .); 152 | 153 | KEEP(*(.jcr*)) 154 | . = ALIGN(4); 155 | /* All data end */ 156 | __data_end__ = .; 157 | 158 | } > RAM AT > FLASH 159 | 160 | .bss : 161 | { 162 | . = ALIGN(4); 163 | __bss_start__ = .; 164 | *(.bss*) 165 | *(COMMON) 166 | . = ALIGN(4); 167 | __bss_end__ = .; 168 | } > RAM 169 | 170 | .heap (COPY): 171 | { 172 | __HeapBase = .; 173 | __end__ = .; 174 | end = __end__; 175 | KEEP(*(.heap*)) 176 | __HeapLimit = .; 177 | } > RAM 178 | 179 | /* .stack_dummy section doesn't contains any symbols. It is only 180 | * used for linker to calculate size of stack sections, and assign 181 | * values to stack symbols later */ 182 | .stack_dummy (COPY): 183 | { 184 | KEEP(*(.stack*)) 185 | } > RAM 186 | 187 | /* Set stack top to end of RAM, and stack limit move down by 188 | * size of stack_dummy section. Reserve 4 bytes at end of RAM for magic number. */ 189 | __StackTop = ORIGIN(RAM) + LENGTH(RAM) - 4; 190 | __StackLimit = __StackTop - SIZEOF(.stack_dummy); 191 | PROVIDE(__stack = __StackTop); 192 | 193 | /* Check if data + heap + stack exceeds RAM limit */ 194 | ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed with stack") 195 | } 196 | -------------------------------------------------------------------------------- /hal/m258ke/nuvoton/NuMicro.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file NuMicro.h 3 | * @version V1.00 4 | * @brief NuMicro peripheral access layer header file. 5 | * 6 | * SPDX-License-Identifier: Apache-2.0 7 | * @copyright (C) 2020 Nuvoton Technology Corp. All rights reserved. 8 | *****************************************************************************/ 9 | 10 | #ifndef __NUMICRO_H__ 11 | #define __NUMICRO_H__ 12 | 13 | #include "M251.h" 14 | 15 | #endif /* __NUMICRO_H__ */ 16 | -------------------------------------------------------------------------------- /hal/m258ke/nuvoton/README.md: -------------------------------------------------------------------------------- 1 | # Nuvoton/CMSIS files 2 | 3 | These files came from [Nuvoton's M251 BSP](https://github.com/OpenNuvoton/M251BSP/). They provide register defines, structs, startup code, the vector table, and linker scripts. 4 | 5 | I've tried to avoid using Nuvoton's BSP driver code for various peripherals as much as possible, but I did use their USBD driver because it would be too difficult to reimplement from scratch. 6 | -------------------------------------------------------------------------------- /hal/m258ke/nuvoton/cmsis_version.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file cmsis_version.h 3 | * @brief CMSIS Core(M) Version definitions 4 | * @version V5.0.2 5 | * @date 19. April 2017 6 | ******************************************************************************/ 7 | /* 8 | * Copyright (c) 2009-2017 ARM Limited. All rights reserved. 9 | * 10 | * SPDX-License-Identifier: Apache-2.0 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the License); you may 13 | * not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 20 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | 25 | #if defined ( __ICCARM__ ) 26 | #pragma system_include /* treat file as system include file for MISRA check */ 27 | #elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) 28 | #pragma clang system_header /* treat file as system include file */ 29 | #endif 30 | 31 | #ifndef __CMSIS_VERSION_H 32 | #define __CMSIS_VERSION_H 33 | 34 | /* CMSIS Version definitions */ 35 | #define __CM_CMSIS_VERSION_MAIN ( 5U) /*!< [31:16] CMSIS Core(M) main version */ 36 | #define __CM_CMSIS_VERSION_SUB ( 0U) /*!< [15:0] CMSIS Core(M) sub version */ 37 | #define __CM_CMSIS_VERSION ((__CM_CMSIS_VERSION_MAIN << 16U) | \ 38 | __CM_CMSIS_VERSION_SUB ) /*!< CMSIS Core(M) version number */ 39 | #endif 40 | -------------------------------------------------------------------------------- /hal/m258ke/nuvoton/gcc_arm.ld: -------------------------------------------------------------------------------- 1 | /* Linker script to configure memory regions. */ 2 | MEMORY 3 | { 4 | FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 128*1024 5 | RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 16*1024 6 | } 7 | 8 | /* Library configurations */ 9 | GROUP(libgcc.a libc.a libm.a libnosys.a) 10 | 11 | /* Linker script to place sections and symbol values. Should be used together 12 | * with other linker script that defines memory regions FLASH and RAM. 13 | * It references following symbols, which must be defined in code: 14 | * Reset_Handler : Entry of reset handler 15 | * 16 | * It defines following symbols, which code can use without definition: 17 | * __exidx_start 18 | * __exidx_end 19 | * __copy_table_start__ 20 | * __copy_table_end__ 21 | * __zero_table_start__ 22 | * __zero_table_end__ 23 | * __etext 24 | * __data_start__ 25 | * __preinit_array_start 26 | * __preinit_array_end 27 | * __init_array_start 28 | * __init_array_end 29 | * __fini_array_start 30 | * __fini_array_end 31 | * __data_end__ 32 | * __bss_start__ 33 | * __bss_end__ 34 | * __end__ 35 | * end 36 | * __HeapLimit 37 | * __StackLimit 38 | * __StackTop 39 | * __stack 40 | * __Vectors_End 41 | * __Vectors_Size 42 | */ 43 | ENTRY(Reset_Handler) 44 | 45 | SECTIONS 46 | { 47 | .text : 48 | { 49 | KEEP(*(.vectors)) 50 | __Vectors_End = .; 51 | __Vectors_Size = __Vectors_End - __Vectors; 52 | __end__ = .; 53 | 54 | *(.text*) 55 | 56 | KEEP(*(.init)) 57 | KEEP(*(.fini)) 58 | 59 | /* .ctors */ 60 | *crtbegin.o(.ctors) 61 | *crtbegin?.o(.ctors) 62 | *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors) 63 | *(SORT(.ctors.*)) 64 | *(.ctors) 65 | 66 | /* .dtors */ 67 | *crtbegin.o(.dtors) 68 | *crtbegin?.o(.dtors) 69 | *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors) 70 | *(SORT(.dtors.*)) 71 | *(.dtors) 72 | 73 | *(.rodata*) 74 | 75 | KEEP(*(.eh_frame*)) 76 | } > FLASH 77 | 78 | .ARM.extab : 79 | { 80 | *(.ARM.extab* .gnu.linkonce.armextab.*) 81 | } > FLASH 82 | 83 | __exidx_start = .; 84 | .ARM.exidx : 85 | { 86 | *(.ARM.exidx* .gnu.linkonce.armexidx.*) 87 | } > FLASH 88 | __exidx_end = .; 89 | 90 | /* To copy multiple ROM to RAM sections, 91 | * uncomment .copy.table section and, 92 | * define __STARTUP_COPY_MULTIPLE in startup_ARMCMx.S */ 93 | /* 94 | .copy.table : 95 | { 96 | . = ALIGN(4); 97 | __copy_table_start__ = .; 98 | LONG (__etext) 99 | LONG (__data_start__) 100 | LONG (__data_end__ - __data_start__) 101 | LONG (__etext2) 102 | LONG (__data2_start__) 103 | LONG (__data2_end__ - __data2_start__) 104 | __copy_table_end__ = .; 105 | } > FLASH 106 | */ 107 | 108 | /* To clear multiple BSS sections, 109 | * uncomment .zero.table section and, 110 | * define __STARTUP_CLEAR_BSS_MULTIPLE in startup_ARMCMx.S */ 111 | /* 112 | .zero.table : 113 | { 114 | . = ALIGN(4); 115 | __zero_table_start__ = .; 116 | LONG (__bss_start__) 117 | LONG (__bss_end__ - __bss_start__) 118 | LONG (__bss2_start__) 119 | LONG (__bss2_end__ - __bss2_start__) 120 | __zero_table_end__ = .; 121 | } > FLASH 122 | */ 123 | 124 | __etext = .; 125 | 126 | .data : ALIGN(4) 127 | { 128 | __data_start__ = .; 129 | *(vtable) 130 | *(.data*) 131 | 132 | . = ALIGN(4); 133 | /* preinit data */ 134 | PROVIDE_HIDDEN (__preinit_array_start = .); 135 | KEEP(*(.preinit_array)) 136 | PROVIDE_HIDDEN (__preinit_array_end = .); 137 | 138 | . = ALIGN(4); 139 | /* init data */ 140 | PROVIDE_HIDDEN (__init_array_start = .); 141 | KEEP(*(SORT(.init_array.*))) 142 | KEEP(*(.init_array)) 143 | PROVIDE_HIDDEN (__init_array_end = .); 144 | 145 | 146 | . = ALIGN(4); 147 | /* finit data */ 148 | PROVIDE_HIDDEN (__fini_array_start = .); 149 | KEEP(*(SORT(.fini_array.*))) 150 | KEEP(*(.fini_array)) 151 | PROVIDE_HIDDEN (__fini_array_end = .); 152 | 153 | KEEP(*(.jcr*)) 154 | . = ALIGN(4); 155 | /* All data end */ 156 | __data_end__ = .; 157 | 158 | } > RAM AT > FLASH 159 | 160 | .bss : 161 | { 162 | . = ALIGN(4); 163 | __bss_start__ = .; 164 | *(.bss*) 165 | *(COMMON) 166 | . = ALIGN(4); 167 | __bss_end__ = .; 168 | } > RAM 169 | 170 | .heap (COPY): 171 | { 172 | __HeapBase = .; 173 | __end__ = .; 174 | end = __end__; 175 | KEEP(*(.heap*)) 176 | __HeapLimit = .; 177 | } > RAM 178 | 179 | /* .stack_dummy section doesn't contains any symbols. It is only 180 | * used for linker to calculate size of stack sections, and assign 181 | * values to stack symbols later */ 182 | .stack_dummy (COPY): 183 | { 184 | KEEP(*(.stack*)) 185 | } > RAM 186 | 187 | /* Set stack top to end of RAM, and stack limit move down by 188 | * size of stack_dummy section. Reserve 4 bytes at end of RAM for magic number. */ 189 | __StackTop = ORIGIN(RAM) + LENGTH(RAM) - 4; 190 | __StackLimit = __StackTop - SIZEOF(.stack_dummy); 191 | PROVIDE(__stack = __StackTop); 192 | 193 | /* Check if data + heap + stack exceeds RAM limit */ 194 | ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed with stack") 195 | } 196 | -------------------------------------------------------------------------------- /hal/m258ke/nuvoton/system_M251.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file system_M251.c 3 | * @version V0.10 4 | * @brief System Setting Source File 5 | * 6 | * SPDX-License-Identifier: Apache-2.0 7 | * @copyright (C) 2020 Nuvoton Technology Corp. All rights reserved. 8 | ****************************************************************************/ 9 | 10 | #include 11 | #include 12 | #include 13 | #include "NuMicro.h" 14 | 15 | #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) 16 | #include "partition_M251.h" 17 | #endif 18 | 19 | 20 | extern void *__Vectors; /* see startup file */ 21 | 22 | /*---------------------------------------------------------------------------- 23 | Clock Variable definitions 24 | *----------------------------------------------------------------------------*/ 25 | uint32_t SystemCoreClock = __HSI; /*!< System Clock Frequency (Core Clock) */ 26 | uint32_t CyclesPerUs = (__HSI / 1000000); /*!< Cycles per micro second */ 27 | uint32_t PllClock = __HSI; /*!< PLL Output Clock Frequency */ 28 | const uint32_t gau32ClkSrcTbl[8] = {__HXT, __LXT, 0UL, __LIRC, 0UL, __MIRC, 0UL, __HIRC}; 29 | 30 | /** 31 | * @brief System Initialization 32 | * 33 | * @details The necessary initialization of system. Global variables are forbidden here. 34 | */ 35 | void SystemInit(void) 36 | { 37 | /* Set access cycle for CPU @ 48MHz */ 38 | FMC->CYCCTL = (FMC->CYCCTL & ~FMC_CYCCTL_CYCLE_Msk) | (3 << FMC_CYCCTL_CYCLE_Pos) | 0x100; 39 | 40 | #if defined (__VTOR_PRESENT) && (__VTOR_PRESENT == 1U) 41 | SCB->VTOR = (uint32_t) &__Vectors; 42 | #endif 43 | 44 | #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) 45 | TZ_SAU_Setup(); 46 | SCU_Setup(); 47 | FMC_NSBA_Setup(); 48 | #endif 49 | 50 | #ifdef INIT_SYSCLK_AT_BOOTING 51 | 52 | #endif 53 | 54 | } 55 | 56 | 57 | #if USE_ASSERT 58 | 59 | /** 60 | * @brief Assert Error Message 61 | * 62 | * @param[in] file the source file name 63 | * @param[in] line line number 64 | * 65 | * @details The function prints the source file name and line number where 66 | * the ASSERT_PARAM() error occurs, and then stops in an infinite loop. 67 | */ 68 | void AssertError(uint8_t *file, uint32_t line) 69 | { 70 | 71 | printf("[%s] line %u : wrong parameters.\r\n", file, line); 72 | 73 | /* Infinite loop */ 74 | while (1) ; 75 | } 76 | #endif 77 | -------------------------------------------------------------------------------- /hal/m258ke/nuvoton/system_M251.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file system_M251.h 3 | * @version V0.10 4 | * @brief System Setting Header File 5 | * 6 | * SPDX-License-Identifier: Apache-2.0 7 | * @copyright (C) 2020 Nuvoton Technology Corp. All rights reserved. 8 | ****************************************************************************/ 9 | 10 | #ifndef __SYSTEM_M251_H__ 11 | #define __SYSTEM_M251_H__ 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | #include 18 | 19 | /*---------------------------------------------------------------------------- 20 | Define clocks 21 | *----------------------------------------------------------------------------*/ 22 | #ifndef __HXT 23 | #define __HXT (12000000UL) /*!< External Crystal Clock Frequency */ 24 | #endif /* !defined(__HXT) */ 25 | 26 | #ifndef __LXT 27 | #define __LXT (32768UL) /*!< External Crystal Clock Frequency 32.768KHz */ 28 | #endif /* !defined(__LXT) */ 29 | 30 | #define __LIRC (38400UL) /*!< Internal 38.4KHz RC Oscillator Frequency */ 31 | #define __MIRC (4032000UL) /*!< Internal 4.032M RC Oscillator Frequency */ 32 | #define __HIRC (48000000UL) /*!< Internal 48M RC Oscillator Frequency */ 33 | #define __HSI (48000000UL) /*!< PLL default output is 48MHz */ 34 | #define __SYS_OSC_CLK ( ___HSI) /*!< Main oscillator frequency */ 35 | 36 | #define __SYSTEM_CLOCK (1UL*__HXT) 37 | 38 | extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */ 39 | extern uint32_t CyclesPerUs; /*!< Cycles per micro second */ 40 | extern uint32_t PllClock; /*!< PLL Output Clock Frequency */ 41 | 42 | 43 | /** 44 | * @brief System Initialization 45 | * 46 | * @details The necessary initialization of system. Global variables are forbidden here. 47 | */ 48 | extern void SystemInit(void); 49 | 50 | /** 51 | * @brief Check if debug message finished 52 | * 53 | * @return 1 Message is finished. 54 | * 0 Message is transmitting. 55 | * 56 | * @details Check if message finished (FIFO empty of debug port) 57 | */ 58 | extern int IsDebugFifoEmpty(void); 59 | 60 | 61 | #ifdef __cplusplus 62 | } 63 | #endif 64 | 65 | #endif /* __SYSTEM_M251_H__ */ 66 | -------------------------------------------------------------------------------- /hal/m258ke/spi.c: -------------------------------------------------------------------------------- 1 | /* 2 | * spi.c 3 | * 4 | * Created on: Jun 19, 2023 5 | * Author: Doug 6 | * 7 | * Copyright (C) 2011-2023 Doug Brown 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | * 22 | */ 23 | 24 | #include "../spi.h" 25 | #include "gpio_hw.h" 26 | #include 27 | 28 | /** Gets the SPI hardware controller at the specified index 29 | * 30 | * @param index The index of the controller. No SPI is available on the M258KE. 31 | * @return The SPI controller, or NULL if an invalid index is supplied 32 | */ 33 | SPIController *SPI_Controller(uint8_t index) 34 | { 35 | (void)index; 36 | return NULL; 37 | } 38 | 39 | /** Initializes the supplied SPI controller 40 | * 41 | * @param c The controller 42 | */ 43 | void SPI_InitController(SPIController *c) 44 | { 45 | (void)c; 46 | } 47 | 48 | /** Initializes the supplied SPI device 49 | * 50 | * @param spi The device 51 | * @param maxClock The maximum clock rate supported by the device in Hz 52 | * @param mode The SPI mode (see the SPI_MODE_*, SPI_CPHA, and SPI_CPOL defines) 53 | * @return True on success, false on failure 54 | */ 55 | bool SPI_InitDevice(SPIDevice *spi, uint32_t maxClock, uint8_t mode) 56 | { 57 | (void)spi; 58 | (void)maxClock; 59 | (void)mode; 60 | return false; 61 | } 62 | 63 | /** Allows an SPI device to request control of the bus. 64 | * 65 | * @param spi The SPI device 66 | */ 67 | void SPI_RequestBus(SPIDevice *spi) 68 | { 69 | (void)spi; 70 | } 71 | 72 | /** Allows an SPI device to relinquish control of the bus. 73 | * 74 | * @param spi The SPI device 75 | */ 76 | void SPI_ReleaseBus(SPIDevice *spi) 77 | { 78 | (void)spi; 79 | } 80 | 81 | /** Asserts an SPI device's chip select pin 82 | * 83 | * @param spi The SPI device 84 | */ 85 | void SPI_Assert(SPIDevice *spi) 86 | { 87 | (void)spi; 88 | } 89 | 90 | /** Deasserts an SPI device's chip select pin 91 | * 92 | * @param spi The SPI device 93 | */ 94 | void SPI_Deassert(SPIDevice *spi) 95 | { 96 | (void)spi; 97 | } 98 | 99 | /** Transfers a single byte to/from an SPI device 100 | * 101 | * @param spi The SPI device 102 | * @param b The byte to send 103 | * @return The byte that was simultaneously received 104 | */ 105 | uint8_t SPI_RWByte(SPIDevice *spi, uint8_t b) 106 | { 107 | (void)spi; 108 | (void)b; 109 | return 0; 110 | } 111 | -------------------------------------------------------------------------------- /hal/m258ke/spi_private.h: -------------------------------------------------------------------------------- 1 | /* 2 | * spi_private.h 3 | * 4 | * Created on: Jun 19, 2023 5 | * Author: Doug 6 | * 7 | * Copyright (C) 2011-2023 Doug Brown 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | * 22 | */ 23 | 24 | #ifndef HAL_M258KE_SPI_PRIVATE_H_ 25 | #define HAL_M258KE_SPI_PRIVATE_H_ 26 | 27 | /// Private data for an SPI device on the M258KE 28 | typedef struct SPIDevicePrivate 29 | { 30 | /// There's nothing needed. We don't need SPI on this device. 31 | } SPIDevicePrivate; 32 | 33 | #endif /* HAL_M258KE_SPI_PRIVATE_H_ */ 34 | -------------------------------------------------------------------------------- /hal/m258ke/usbcdc_hw.h: -------------------------------------------------------------------------------- 1 | /* 2 | * usbcdc_hw.h 3 | * 4 | * Created on: Jun 19, 2023 5 | * Author: Doug 6 | * 7 | * Copyright (C) 2011-2023 Doug Brown 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | * 22 | * Portions of this code also came from Nuvoton's BSP, originally 23 | * licensed as Apache-2.0: 24 | * @copyright (C) 2019 Nuvoton Technology Corp. All rights reserved. 25 | * 26 | */ 27 | 28 | #ifndef HAL_M258KE_USBCDC_HW_H_ 29 | #define HAL_M258KE_USBCDC_HW_H_ 30 | 31 | #include 32 | #include 33 | #include "nuvoton/NuMicro.h" 34 | #include "nuvoton/usbd.h" 35 | 36 | /// Maximum packet sizes of each endpoint 37 | #define EP0_MAX_PKT_SIZE 64 38 | #define EP1_MAX_PKT_SIZE 64 39 | #define EP2_MAX_PKT_SIZE 8 40 | #define EP3_MAX_PKT_SIZE 64 41 | #define EP4_MAX_PKT_SIZE 64 42 | 43 | /// Assigned endpoint numbers for CDC serial port 44 | #define INT_IN_EP_NUM 2 45 | #define BULK_IN_EP_NUM 3 46 | #define BULK_OUT_EP_NUM 4 47 | 48 | /** Initializes the USB CDC serial port 49 | * 50 | */ 51 | void USBCDC_Init(void); 52 | 53 | /** Disconnects the USB CDC device from the host 54 | * 55 | */ 56 | static inline void USBCDC_Disable(void) 57 | { 58 | USBD_SET_SE0(); 59 | } 60 | 61 | /** Performs any necessary periodic tasks for the USB CDC serial port 62 | * 63 | */ 64 | void USBCDC_Check(void); 65 | 66 | /** Sends a byte out the USB serial port 67 | * 68 | * @param b The byte 69 | */ 70 | void USBCDC_SendByte(uint8_t b); 71 | 72 | /** Sends a block of data over the USB CDC serial port 73 | * 74 | * @param data The data to send 75 | * @param len The number of bytes 76 | * @return True on success, false on failure 77 | */ 78 | static inline bool USBCDC_SendData(uint8_t const *data, uint16_t len) 79 | { 80 | while (len--) 81 | { 82 | USBCDC_SendByte(*data++); 83 | } 84 | 85 | return true; 86 | } 87 | 88 | /** Reads a byte from the USB serial port, if available 89 | * 90 | * @return The byte, or -1 if there is nothing available 91 | */ 92 | int16_t USBCDC_ReadByte(void); 93 | 94 | /** Reads a byte from the USB CDC serial port. Blocks until one is available. 95 | * 96 | * @return The byte read 97 | */ 98 | static inline uint8_t USBCDC_ReadByteBlocking(void) 99 | { 100 | int16_t b; 101 | do 102 | { 103 | b = USBCDC_ReadByte(); 104 | } while (b < 0); 105 | return (uint8_t)b; 106 | } 107 | 108 | /** Flushes remaining data out to the USB serial port 109 | * 110 | */ 111 | void USBCDC_Flush(void); 112 | 113 | #endif /* HAL_M258KE_USBCDC_HW_H_ */ 114 | -------------------------------------------------------------------------------- /hal/parallel_bus.h: -------------------------------------------------------------------------------- 1 | /* 2 | * parallel_bus.h 3 | * 4 | * Created on: Nov 26, 2011 5 | * Author: Doug 6 | * 7 | * Copyright (C) 2011-2023 Doug Brown 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | * 22 | */ 23 | 24 | #ifndef HAL_PARALLEL_BUS_H_ 25 | #define HAL_PARALLEL_BUS_H_ 26 | 27 | #include 28 | #include 29 | 30 | void ParallelBus_Init(void); 31 | 32 | void ParallelBus_SetAddress(uint32_t address); 33 | void ParallelBus_SetData(uint32_t data); 34 | void ParallelBus_SetCS(bool high); 35 | void ParallelBus_SetOE(bool high); 36 | void ParallelBus_SetWE(bool high); 37 | 38 | void ParallelBus_SetAddressDir(uint32_t outputs); 39 | void ParallelBus_SetDataDir(uint32_t outputs); 40 | void ParallelBus_SetCSDir(bool output); 41 | void ParallelBus_SetOEDir(bool output); 42 | void ParallelBus_SetWEDir(bool output); 43 | 44 | void ParallelBus_SetAddressPullups(uint32_t pullups); 45 | void ParallelBus_SetAddressPulldowns(uint32_t pulldowns); 46 | void ParallelBus_SetDataPullups(uint32_t pullups); 47 | void ParallelBus_SetDataPulldowns(uint32_t pulldowns); 48 | void ParallelBus_SetCSPullup(bool pullup); 49 | void ParallelBus_SetCSPulldown(bool pulldown); 50 | void ParallelBus_SetOEPullup(bool pullup); 51 | void ParallelBus_SetOEPulldown(bool pulldown); 52 | void ParallelBus_SetWEPullup(bool pullup); 53 | void ParallelBus_SetWEPulldown(bool pulldown); 54 | 55 | uint32_t ParallelBus_ReadAddress(void); 56 | uint32_t ParallelBus_ReadData(void); 57 | bool ParallelBus_ReadCS(void); 58 | bool ParallelBus_ReadOE(void); 59 | bool ParallelBus_ReadWE(void); 60 | 61 | void ParallelBus_WriteCycle(uint32_t address, uint32_t data); 62 | uint32_t ParallelBus_ReadCycle(uint32_t address); 63 | void ParallelBus_Read(uint32_t startAddress, uint32_t *buf, uint16_t len); 64 | 65 | #endif /* HAL_PARALLEL_BUS_H_ */ 66 | -------------------------------------------------------------------------------- /hal/spi.h: -------------------------------------------------------------------------------- 1 | /* 2 | * spi.h 3 | * 4 | * Created on: Nov 14, 2020 5 | * Author: Doug 6 | * 7 | * Copyright (C) 2011-2023 Doug Brown 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | * 22 | */ 23 | 24 | #ifndef HAL_SPI_H_ 25 | #define HAL_SPI_H_ 26 | 27 | #include "gpio.h" 28 | #include "spi_private.h" 29 | 30 | /// CPHA bit in the SPI mode parameter of SPI_InitDevice 31 | #define SPI_CPHA (1 << 0) 32 | /// CPOL bit in the SPI mode parameter of SPI_InitDevice 33 | #define SPI_CPOL (1 << 1) 34 | 35 | /// Friendly names for modes 0-3 when dealing with CPHA/CPOL in SPI_InitDevice 36 | #define SPI_MODE_0 (0 | 0) 37 | #define SPI_MODE_1 (0 | SPI_CPHA) 38 | #define SPI_MODE_2 (SPI_CPOL | 0) 39 | #define SPI_MODE_3 (SPI_CPOL | SPI_CPHA) 40 | 41 | /// SPI controller 42 | typedef struct SPIController 43 | { 44 | /// The serial clock pin 45 | GPIOPin sckPin; 46 | /// The master out/slave in pin 47 | GPIOPin mosiPin; 48 | /// The master in/slave out pin 49 | GPIOPin misoPin; 50 | } SPIController; 51 | 52 | /// SPI device 53 | typedef struct SPIDevice 54 | { 55 | // These two members should be filled in the struct by hand 56 | /// The GPIO pin used for chip select 57 | GPIOPin csPin; 58 | /// The SPI controller this device belongs to 59 | SPIController *controller; 60 | 61 | // Everything below here is private 62 | SPIDevicePrivate private; 63 | } SPIDevice; 64 | 65 | SPIController *SPI_Controller(uint8_t index); 66 | void SPI_InitController(SPIController *c); 67 | bool SPI_InitDevice(SPIDevice *spi, uint32_t maxClock, uint8_t mode); 68 | void SPI_RequestBus(SPIDevice *spi); 69 | void SPI_ReleaseBus(SPIDevice *spi); 70 | void SPI_Assert(SPIDevice *spi); 71 | void SPI_Deassert(SPIDevice *spi); 72 | uint8_t SPI_RWByte(SPIDevice *spi, uint8_t b); 73 | 74 | #endif /* HAL_SPI_H_ */ 75 | -------------------------------------------------------------------------------- /hal/usbcdc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * usbcdc.h 3 | * 4 | * Created on: Nov 22, 2020 5 | * Author: Doug 6 | * 7 | * Copyright (C) 2011-2023 Doug Brown 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | * 22 | */ 23 | 24 | #ifndef HAL_USBCDC_H_ 25 | #define HAL_USBCDC_H_ 26 | 27 | #include 28 | #include "usbcdc_hw.h" 29 | 30 | // Note: Functions commented out should be implemented as static inline 31 | // functions in the board-specific header file for efficiency. 32 | void USBCDC_Init(void); 33 | void USBCDC_Disable(void); 34 | void USBCDC_Check(void); 35 | //void USBCDC_SendByte(uint8_t byte); 36 | //bool USBCDC_SendData(uint8_t const *data, uint16_t len); 37 | //int16_t USBCDC_ReadByte(void); 38 | //uint8_t USBCDC_ReadByteBlocking(void); 39 | //void USBCDC_Flush(void) 40 | 41 | #endif /* HAL_USBCDC_H_ */ 42 | -------------------------------------------------------------------------------- /led.h: -------------------------------------------------------------------------------- 1 | /* 2 | * led.h 3 | * 4 | * Created on: May 27, 2012 5 | * Author: Doug 6 | * 7 | * Copyright (C) 2011-2023 Doug Brown 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | * 22 | */ 23 | 24 | #ifndef LED_H_ 25 | #define LED_H_ 26 | 27 | #include "hal/board.h" 28 | #include "hal/gpio.h" 29 | 30 | static inline void LED_Off(void); 31 | 32 | /** Initializes the LED and turns it off 33 | * 34 | */ 35 | static inline void LED_Init(void) 36 | { 37 | GPIOPin ledPin = Board_LEDPin(); 38 | GPIO_SetDirection(ledPin, true); 39 | LED_Off(); 40 | } 41 | 42 | /** Turns the LED on 43 | * 44 | */ 45 | static inline void LED_On(void) 46 | { 47 | #if BOARD_LED_INVERTED 48 | GPIO_SetOff(Board_LEDPin()); 49 | #else 50 | GPIO_SetOn(Board_LEDPin()); 51 | #endif 52 | } 53 | 54 | /** Turns the LED off 55 | * 56 | */ 57 | static inline void LED_Off(void) 58 | { 59 | #if BOARD_LED_INVERTED 60 | GPIO_SetOn(Board_LEDPin()); 61 | #else 62 | GPIO_SetOff(Board_LEDPin()); 63 | #endif 64 | } 65 | 66 | /** Toggles the LED 67 | * 68 | */ 69 | static inline void LED_Toggle(void) 70 | { 71 | GPIO_Toggle(Board_LEDPin()); 72 | } 73 | 74 | #endif /* LED_H_ */ 75 | -------------------------------------------------------------------------------- /main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * main.c 3 | * 4 | * Created on: Nov 25, 2011 5 | * Author: Doug 6 | * 7 | * Copyright (C) 2011-2023 Doug Brown 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | * 22 | * ----------------------------------------------------------------------------- 23 | * 24 | * TODO: Add smarter short detection? Automatically run an electrical test at 25 | * startup and leave everything in input mode if shorts are detected? 26 | * I'm especially thinking about the case of SIMM control pins shorted 27 | * together, like CS and OE, which will default to opposite output values. 28 | * Is this even worth implementing? It's probably only useful when testing 29 | * newly-built SIMMs. We would need to implement a protocol for this so 30 | * the programmer software can be alerted that a short was detected. 31 | */ 32 | 33 | #include "hal/board.h" 34 | #include "hardware.h" 35 | #include "hal/parallel_bus.h" 36 | #include "tests/simm_electrical_test.h" 37 | #include "simm_programmer.h" 38 | #include "led.h" 39 | 40 | /** Main function 41 | * 42 | * @return Never; the main loop is an infinite loop. 43 | */ 44 | int main(void) 45 | { 46 | DisableInterrupts(); 47 | Board_Init(); 48 | LED_Init(); 49 | 50 | // If there was a brownout detected, turn on the LED momentarily 51 | if (Board_BrownoutDetected()) 52 | { 53 | LED_On(); 54 | DelayMS(500); 55 | LED_Off(); 56 | } 57 | 58 | // Initialize everything and turn on interrupts 59 | ParallelBus_Init(); 60 | SIMMProgrammer_Init(); 61 | EnableInterrupts(); 62 | 63 | // Main loop 64 | while (1) 65 | { 66 | SIMMProgrammer_Check(); 67 | } 68 | 69 | return 0; 70 | } 71 | -------------------------------------------------------------------------------- /simm_programmer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * simm_programmer.h 3 | * 4 | * Created on: Dec 9, 2011 5 | * Author: Doug 6 | * 7 | * Copyright (C) 2011-2023 Doug Brown 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | * 22 | */ 23 | 24 | #ifndef SIMM_PROGRAMMER_H_ 25 | #define SIMM_PROGRAMMER_H_ 26 | 27 | void SIMMProgrammer_Init(void); 28 | void SIMMProgrammer_Check(void); 29 | 30 | #endif /* SIMM_PROGRAMMER_H_ */ 31 | -------------------------------------------------------------------------------- /tests/simm_electrical_test.h: -------------------------------------------------------------------------------- 1 | /* 2 | * simm_electrical_test.h 3 | * 4 | * Created on: Nov 26, 2011 5 | * Author: Doug 6 | * 7 | * Copyright (C) 2011-2023 Doug Brown 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | * 22 | */ 23 | 24 | #ifndef SIMM_ELECTRICAL_TEST_H_ 25 | #define SIMM_ELECTRICAL_TEST_H_ 26 | 27 | #include 28 | 29 | int SIMMElectricalTest_Run(void (*errorHandler)(uint8_t, uint8_t)); 30 | 31 | #endif /* SIMM_ELECTRICAL_TEST_H_ */ 32 | -------------------------------------------------------------------------------- /toolchain-avr.cmake: -------------------------------------------------------------------------------- 1 | # This will tell CMake that we are cross compiling 2 | set(CMAKE_SYSTEM_NAME Generic) 3 | set(CMAKE_SYSTEM_VERSION 1) 4 | set(CMAKE_SYSTEM_PROCESSOR avr) 5 | 6 | # Make sure it knows what binaries to use 7 | set(CMAKE_AR avr-ar) 8 | set(CMAKE_ASM_COMPILER avr-as) 9 | set(CMAKE_C_COMPILER avr-gcc) 10 | set(CMAKE_CXX_COMPILER avr-g++) 11 | set(CMAKE_LINKER avr-ld) 12 | set(CMAKE_OBJCOPY avr-objcopy) 13 | set(CMAKE_RANLIB avr-ranlib) 14 | set(CMAKE_SIZE avr-size) 15 | set(CMAKE_STRIP avr-strip) 16 | -------------------------------------------------------------------------------- /toolchain-m258ke.cmake: -------------------------------------------------------------------------------- 1 | # This will tell CMake that we are cross compiling 2 | set(CMAKE_SYSTEM_NAME Generic) 3 | set(CMAKE_SYSTEM_VERSION 1) 4 | set(CMAKE_SYSTEM_PROCESSOR arm) 5 | set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) 6 | 7 | # Make sure it knows what binaries to use 8 | set(CMAKE_AR arm-none-eabi-ar) 9 | set(CMAKE_ASM_COMPILER arm-none-eabi-gcc) 10 | set(CMAKE_C_COMPILER arm-none-eabi-gcc) 11 | set(CMAKE_CXX_COMPILER arm-none-eabi-g++) 12 | set(CMAKE_LINKER arm-none-eabi-ld) 13 | set(CMAKE_OBJCOPY arm-none-eabi-objcopy) 14 | set(CMAKE_RANLIB arm-none-eabi-ranlib) 15 | set(CMAKE_SIZE arm-none-eabi-size) 16 | set(CMAKE_STRIP arm-none-eabi-strip) 17 | -------------------------------------------------------------------------------- /util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * util.h 3 | * 4 | * Created on: Nov 25, 2020 5 | * Author: Doug 6 | * 7 | * Copyright (C) 2011-2023 Doug Brown 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | * 22 | */ 23 | 24 | #ifndef UTIL_H_ 25 | #define UTIL_H_ 26 | 27 | /// Macro so we don't have to repeat this monstrosity multiple times 28 | #define ALWAYS_INLINE __attribute__ ((__always_inline__)) inline 29 | 30 | #endif /* UTIL_H_ */ 31 | --------------------------------------------------------------------------------