Copy project
This commit is contained in:
parent
ce7a467af7
commit
26a0fd884f
63 changed files with 157458 additions and 1 deletions
19
space_game/SpaceGame.atsln
Normal file
19
space_game/SpaceGame.atsln
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Atmel Studio Solution File, Format Version 11.00
|
||||
VisualStudioVersion = 14.0.23107.0
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "SpaceGame", "SpaceGame\SpaceGame.cproj", "{DCE6C7E3-EE26-4D79-826B-08594B9AD897}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Release|AVR = Release|AVR
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Release|AVR.ActiveCfg = Release|AVR
|
||||
{DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Release|AVR.Build.0 = Release|AVR
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
86
space_game/SpaceGame/SpaceGame.componentinfo.xml
Normal file
86
space_game/SpaceGame/SpaceGame.componentinfo.xml
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Store xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="AtmelPackComponentManagement">
|
||||
<ProjectComponents>
|
||||
<ProjectComponent z:Id="i1" xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/">
|
||||
<CApiVersion></CApiVersion>
|
||||
<CBundle></CBundle>
|
||||
<CClass>Device</CClass>
|
||||
<CGroup>Startup</CGroup>
|
||||
<CSub></CSub>
|
||||
<CVariant></CVariant>
|
||||
<CVendor>Atmel</CVendor>
|
||||
<CVersion>1.3.0</CVersion>
|
||||
<DefaultRepoPath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs</DefaultRepoPath>
|
||||
<DependentComponents xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays" />
|
||||
<Description></Description>
|
||||
<Files xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
|
||||
<d4p1:anyType i:type="FileInfo">
|
||||
<AbsolutePath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATtiny_DFP\1.3.229\include</AbsolutePath>
|
||||
<Attribute></Attribute>
|
||||
<Category>include</Category>
|
||||
<Condition>C</Condition>
|
||||
<FileContentHash i:nil="true" />
|
||||
<FileVersion></FileVersion>
|
||||
<Name>include</Name>
|
||||
<SelectString></SelectString>
|
||||
<SourcePath></SourcePath>
|
||||
</d4p1:anyType>
|
||||
<d4p1:anyType i:type="FileInfo">
|
||||
<AbsolutePath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATtiny_DFP\1.3.229\include\avr\iotn85.h</AbsolutePath>
|
||||
<Attribute></Attribute>
|
||||
<Category>header</Category>
|
||||
<Condition>C</Condition>
|
||||
<FileContentHash>RcYmivGpgsCGGCzeWAIjcA==</FileContentHash>
|
||||
<FileVersion></FileVersion>
|
||||
<Name>include/avr/iotn85.h</Name>
|
||||
<SelectString></SelectString>
|
||||
<SourcePath></SourcePath>
|
||||
</d4p1:anyType>
|
||||
<d4p1:anyType i:type="FileInfo">
|
||||
<AbsolutePath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATtiny_DFP\1.3.229\templates\main.c</AbsolutePath>
|
||||
<Attribute>template</Attribute>
|
||||
<Category>source</Category>
|
||||
<Condition>C Exe</Condition>
|
||||
<FileContentHash>9ptzGqB00V1zM0TC00KMag==</FileContentHash>
|
||||
<FileVersion></FileVersion>
|
||||
<Name>templates/main.c</Name>
|
||||
<SelectString>Main file (.c)</SelectString>
|
||||
<SourcePath></SourcePath>
|
||||
</d4p1:anyType>
|
||||
<d4p1:anyType i:type="FileInfo">
|
||||
<AbsolutePath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATtiny_DFP\1.3.229\templates\main.cpp</AbsolutePath>
|
||||
<Attribute>template</Attribute>
|
||||
<Category>source</Category>
|
||||
<Condition>C Exe</Condition>
|
||||
<FileContentHash>YXFphlh0CtZJU+ebktABgQ==</FileContentHash>
|
||||
<FileVersion></FileVersion>
|
||||
<Name>templates/main.cpp</Name>
|
||||
<SelectString>Main file (.cpp)</SelectString>
|
||||
<SourcePath></SourcePath>
|
||||
</d4p1:anyType>
|
||||
<d4p1:anyType i:type="FileInfo">
|
||||
<AbsolutePath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATtiny_DFP\1.3.229\gcc\dev\attiny85</AbsolutePath>
|
||||
<Attribute></Attribute>
|
||||
<Category>libraryPrefix</Category>
|
||||
<Condition>GCC</Condition>
|
||||
<FileContentHash i:nil="true" />
|
||||
<FileVersion></FileVersion>
|
||||
<Name>gcc/dev/attiny85</Name>
|
||||
<SelectString></SelectString>
|
||||
<SourcePath></SourcePath>
|
||||
</d4p1:anyType>
|
||||
</Files>
|
||||
<PackName>ATtiny_DFP</PackName>
|
||||
<PackPath>C:/Program Files (x86)/Atmel/Studio/7.0/Packs/atmel/ATtiny_DFP/1.3.229/Atmel.ATtiny_DFP.pdsc</PackPath>
|
||||
<PackVersion>1.3.229</PackVersion>
|
||||
<PresentInProject>true</PresentInProject>
|
||||
<ReferenceConditionId>ATtiny85</ReferenceConditionId>
|
||||
<RteComponents xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
|
||||
<d4p1:string></d4p1:string>
|
||||
</RteComponents>
|
||||
<Status>Resolved</Status>
|
||||
<VersionMode>Fixed</VersionMode>
|
||||
<IsComponentInAtProject>true</IsComponentInAtProject>
|
||||
</ProjectComponent>
|
||||
</ProjectComponents>
|
||||
</Store>
|
||||
422
space_game/SpaceGame/SpaceGame.cproj
Normal file
422
space_game/SpaceGame/SpaceGame.cproj
Normal file
|
|
@ -0,0 +1,422 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="14.0">
|
||||
<PropertyGroup>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectVersion>7.0</ProjectVersion>
|
||||
<ToolchainName>com.Atmel.AVRGCC8.C</ToolchainName>
|
||||
<ProjectGuid>dce6c7e3-ee26-4d79-826b-08594b9ad897</ProjectGuid>
|
||||
<avrdevice>ATtiny85</avrdevice>
|
||||
<avrdeviceseries>none</avrdeviceseries>
|
||||
<OutputType>Executable</OutputType>
|
||||
<Language>C</Language>
|
||||
<OutputFileName>$(MSBuildProjectName)</OutputFileName>
|
||||
<OutputFileExtension>.elf</OutputFileExtension>
|
||||
<OutputDirectory>$(MSBuildProjectDirectory)\$(Configuration)</OutputDirectory>
|
||||
<AssemblyName>TestProject</AssemblyName>
|
||||
<Name>TestProject</Name>
|
||||
<RootNamespace>TestProject</RootNamespace>
|
||||
<ToolchainFlavour>Native</ToolchainFlavour>
|
||||
<KeepTimersRunning>false</KeepTimersRunning>
|
||||
<OverrideVtor>false</OverrideVtor>
|
||||
<CacheFlash>false</CacheFlash>
|
||||
<ProgFlashFromRam>true</ProgFlashFromRam>
|
||||
<RamSnippetAddress>0x20000000</RamSnippetAddress>
|
||||
<UncachedRange />
|
||||
<preserveEEPROM>false</preserveEEPROM>
|
||||
<OverrideVtorValue>exception_table</OverrideVtorValue>
|
||||
<BootSegment>2</BootSegment>
|
||||
<ResetRule>0</ResetRule>
|
||||
<eraseonlaunchrule>0</eraseonlaunchrule>
|
||||
<EraseKey />
|
||||
<AsfFrameworkConfig>
|
||||
<framework-data>
|
||||
<options />
|
||||
<configurations />
|
||||
<files />
|
||||
<documentation help="" />
|
||||
<offline-documentation help="" />
|
||||
<dependencies>
|
||||
<content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.47.0" />
|
||||
</dependencies>
|
||||
</framework-data>
|
||||
</AsfFrameworkConfig>
|
||||
<avrtool>com.atmel.avrdbg.tool.ispmk2</avrtool>
|
||||
<avrtoolserialnumber>000200212345</avrtoolserialnumber>
|
||||
<avrdeviceexpectedsignature>0x1E930B</avrdeviceexpectedsignature>
|
||||
<avrtoolinterface>ISP</avrtoolinterface>
|
||||
<avrtoolinterfaceclock>125000</avrtoolinterfaceclock>
|
||||
<com_atmel_avrdbg_tool_ispmk2>
|
||||
<ToolOptions>
|
||||
<InterfaceProperties>
|
||||
<IspClock>125000</IspClock>
|
||||
</InterfaceProperties>
|
||||
<InterfaceName>ISP</InterfaceName>
|
||||
</ToolOptions>
|
||||
<ToolType>com.atmel.avrdbg.tool.ispmk2</ToolType>
|
||||
<ToolNumber>000200212345</ToolNumber>
|
||||
<ToolName>AVRISP mkII</ToolName>
|
||||
</com_atmel_avrdbg_tool_ispmk2>
|
||||
<com_atmel_avrdbg_tool_simulator>
|
||||
<ToolOptions xmlns="">
|
||||
<InterfaceProperties>
|
||||
</InterfaceProperties>
|
||||
<InterfaceName>
|
||||
</InterfaceName>
|
||||
</ToolOptions>
|
||||
<ToolType xmlns="">com.atmel.avrdbg.tool.simulator</ToolType>
|
||||
<ToolNumber xmlns="">
|
||||
</ToolNumber>
|
||||
<ToolName xmlns="">Simulator</ToolName>
|
||||
</com_atmel_avrdbg_tool_simulator>
|
||||
<custom>
|
||||
<ToolOptions>
|
||||
<InterfaceProperties>
|
||||
<IspClock>125000</IspClock>
|
||||
</InterfaceProperties>
|
||||
<InterfaceName>
|
||||
</InterfaceName>
|
||||
</ToolOptions>
|
||||
<ToolType>custom</ToolType>
|
||||
<ToolNumber>
|
||||
</ToolNumber>
|
||||
<ToolName>Custom Programming Tool</ToolName>
|
||||
</custom>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||
<ToolchainSettings>
|
||||
<AvrGcc>
|
||||
<avrgcc.common.Device>-mmcu=attiny85 -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.3.229\gcc\dev\attiny85"</avrgcc.common.Device>
|
||||
<avrgcc.common.optimization.RelaxBranches>True</avrgcc.common.optimization.RelaxBranches>
|
||||
<avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
|
||||
<avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
|
||||
<avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
|
||||
<avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
|
||||
<avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
|
||||
<avrgcc.compiler.general.SubroutinesFunctionPrologues>True</avrgcc.compiler.general.SubroutinesFunctionPrologues>
|
||||
<avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
|
||||
<avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
|
||||
<avrgcc.compiler.symbols.DefSymbols>
|
||||
<ListValues>
|
||||
<Value>NDEBUG</Value>
|
||||
</ListValues>
|
||||
</avrgcc.compiler.symbols.DefSymbols>
|
||||
<avrgcc.compiler.directories.IncludePaths>
|
||||
<ListValues>
|
||||
<Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.3.229\include</Value>
|
||||
<Value>../src/macros</Value>
|
||||
</ListValues>
|
||||
</avrgcc.compiler.directories.IncludePaths>
|
||||
<avrgcc.compiler.optimization.level>Optimize for size (-Os)</avrgcc.compiler.optimization.level>
|
||||
<avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
|
||||
<avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
|
||||
<avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
|
||||
<avrgcc.compiler.warnings.ExtraWarnings>True</avrgcc.compiler.warnings.ExtraWarnings>
|
||||
<avrgcc.compiler.warnings.Undefined>True</avrgcc.compiler.warnings.Undefined>
|
||||
<avrgcc.linker.libraries.Libraries>
|
||||
<ListValues>
|
||||
<Value>libm</Value>
|
||||
</ListValues>
|
||||
</avrgcc.linker.libraries.Libraries>
|
||||
<avrgcc.assembler.general.IncludePaths>
|
||||
<ListValues>
|
||||
<Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.3.229\include</Value>
|
||||
</ListValues>
|
||||
</avrgcc.assembler.general.IncludePaths>
|
||||
</AvrGcc>
|
||||
</ToolchainSettings>
|
||||
<OutputFileName>space_game</OutputFileName>
|
||||
<OutputFileExtension>.elf</OutputFileExtension>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
||||
<ToolchainSettings>
|
||||
<AvrGcc>
|
||||
<avrgcc.common.Device>-mmcu=attiny85 -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.3.229\gcc\dev\attiny85"</avrgcc.common.Device>
|
||||
<avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
|
||||
<avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
|
||||
<avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
|
||||
<avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
|
||||
<avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
|
||||
<avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
|
||||
<avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
|
||||
<avrgcc.compiler.symbols.DefSymbols>
|
||||
<ListValues>
|
||||
<Value>DEBUG</Value>
|
||||
</ListValues>
|
||||
</avrgcc.compiler.symbols.DefSymbols>
|
||||
<avrgcc.compiler.directories.IncludePaths>
|
||||
<ListValues>
|
||||
<Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.3.229\include</Value>
|
||||
</ListValues>
|
||||
</avrgcc.compiler.directories.IncludePaths>
|
||||
<avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>
|
||||
<avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
|
||||
<avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
|
||||
<avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>
|
||||
<avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
|
||||
<avrgcc.linker.libraries.Libraries>
|
||||
<ListValues>
|
||||
<Value>libm</Value>
|
||||
</ListValues>
|
||||
</avrgcc.linker.libraries.Libraries>
|
||||
<avrgcc.assembler.general.IncludePaths>
|
||||
<ListValues>
|
||||
<Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.3.229\include</Value>
|
||||
</ListValues>
|
||||
</avrgcc.assembler.general.IncludePaths>
|
||||
<avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
|
||||
</AvrGcc>
|
||||
</ToolchainSettings>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'WithUART' ">
|
||||
<ToolchainSettings>
|
||||
<AvrGcc>
|
||||
<avrgcc.common.Device>-mmcu=attiny85 -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.3.229\gcc\dev\attiny85"</avrgcc.common.Device>
|
||||
<avrgcc.common.optimization.RelaxBranches>True</avrgcc.common.optimization.RelaxBranches>
|
||||
<avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
|
||||
<avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
|
||||
<avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
|
||||
<avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
|
||||
<avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
|
||||
<avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
|
||||
<avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
|
||||
<avrgcc.compiler.symbols.DefSymbols>
|
||||
<ListValues>
|
||||
<Value>NDEBUG</Value>
|
||||
<Value>UART_ENABLED</Value>
|
||||
</ListValues>
|
||||
</avrgcc.compiler.symbols.DefSymbols>
|
||||
<avrgcc.compiler.directories.IncludePaths>
|
||||
<ListValues>
|
||||
<Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.3.229\include</Value>
|
||||
</ListValues>
|
||||
</avrgcc.compiler.directories.IncludePaths>
|
||||
<avrgcc.compiler.optimization.level>Optimize for size (-Os)</avrgcc.compiler.optimization.level>
|
||||
<avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
|
||||
<avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
|
||||
<avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
|
||||
<avrgcc.compiler.warnings.ExtraWarnings>True</avrgcc.compiler.warnings.ExtraWarnings>
|
||||
<avrgcc.compiler.warnings.Undefined>True</avrgcc.compiler.warnings.Undefined>
|
||||
<avrgcc.linker.libraries.Libraries>
|
||||
<ListValues>
|
||||
<Value>libm</Value>
|
||||
</ListValues>
|
||||
</avrgcc.linker.libraries.Libraries>
|
||||
<avrgcc.assembler.general.IncludePaths>
|
||||
<ListValues>
|
||||
<Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.3.229\include</Value>
|
||||
</ListValues>
|
||||
</avrgcc.assembler.general.IncludePaths>
|
||||
</AvrGcc>
|
||||
</ToolchainSettings>
|
||||
<OutputFileName>space_game</OutputFileName>
|
||||
<OutputFileExtension>.elf</OutputFileExtension>
|
||||
<OutputPath>bin\WithUART\</OutputPath>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="src\driver\sleep\sleep.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="src\driver\uart\receive.c">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="src\driver\uart\receive.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="src\driver\uart\transmit.c">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="src\driver\uart\transmit.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="src\hardware_access\eeprom\eeprom.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="src\hardware_access\hardware_access.c">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="src\hardware_access\hardware_access.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="src\hardware_access\output_pins\output_pins.c">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="src\hardware_access\output_pins\output_pins.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="src\hardware_access\power_saving\power_saving.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="src\hardware_access\spi\spi.c">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="src\hardware_access\spi\spi.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="src\hardware_access\timing\timing.c">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="src\hardware_access\timing\timing.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="src\driver\display\display.c">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="src\driver\display\display.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="src\driver\infra\infra.c">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="src\driver\infra\infra.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="src\driver\sleep\sleep.c">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="src\macros\bitwise.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="src\macros\math.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="src\macros\null.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="src\main.c">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="src\mediator\mediator.c">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="src\mediator\mediator.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="src\objects\ai\ai.c">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="src\objects\ai\ai.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="src\objects\commands\commands.c">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="src\objects\commands\commands.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="src\objects\event_generator\event_generator.c">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="src\objects\event_generator\event_generator.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="src\objects\object.c">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="src\objects\object.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="src\objects\object_container\object_container.c">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="src\objects\object_container\object_container.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="src\objects\prototype.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="src\objects\types\asteroid\asteroid.c">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="src\objects\types\asteroid\asteroid.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="src\objects\types\astronaut\astronaut.c">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="src\objects\types\astronaut\astronaut.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="src\objects\types\background\background.c">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="src\objects\types\background\background.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="src\objects\types\bullet\bullet.c">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="src\objects\types\bullet\bullet.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="src\objects\types\heart\heart.c">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="src\objects\types\heart\heart.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="src\objects\types\spaceship\spaceship.c">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="src\objects\types\spaceship\spaceship.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="src\objects\types\sprites.c">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="src\objects\types\sprites.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="src\util\random\random.c">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="src\util\random\random.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="src\util\rectangle\rectangle.c">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="src\util\rectangle\rectangle.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="src\util\vec2\vec2.c">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="src\util\vec2\vec2.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="src" />
|
||||
<Folder Include="src\controller\" />
|
||||
<Folder Include="src\driver\" />
|
||||
<Folder Include="src\driver\display\" />
|
||||
<Folder Include="src\driver\infra\" />
|
||||
<Folder Include="src\driver\uart" />
|
||||
<Folder Include="src\driver\sleep\" />
|
||||
<Folder Include="src\hardware_access\" />
|
||||
<Folder Include="src\hardware_access\eeprom\" />
|
||||
<Folder Include="src\hardware_access\output_pins" />
|
||||
<Folder Include="src\hardware_access\power_saving\" />
|
||||
<Folder Include="src\hardware_access\spi\" />
|
||||
<Folder Include="src\hardware_access\timing\" />
|
||||
<Folder Include="src\macros\" />
|
||||
<Folder Include="src\mediator\" />
|
||||
<Folder Include="src\objects\" />
|
||||
<Folder Include="src\objects\ai\" />
|
||||
<Folder Include="src\objects\commands\" />
|
||||
<Folder Include="src\objects\event_generator\" />
|
||||
<Folder Include="src\objects\object_container\" />
|
||||
<Folder Include="src\objects\types\" />
|
||||
<Folder Include="src\objects\types\asteroid\" />
|
||||
<Folder Include="src\objects\types\astronaut\" />
|
||||
<Folder Include="src\objects\types\background\" />
|
||||
<Folder Include="src\objects\types\bullet\" />
|
||||
<Folder Include="src\objects\types\heart\" />
|
||||
<Folder Include="src\objects\types\spaceship\" />
|
||||
<Folder Include="src\util\" />
|
||||
<Folder Include="src\util\random\" />
|
||||
<Folder Include="src\util\rectangle\" />
|
||||
<Folder Include="src\util\vec2\" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />
|
||||
</Project>
|
||||
130
space_game/SpaceGame/src/driver/display/display.c
Normal file
130
space_game/SpaceGame/src/driver/display/display.c
Normal file
|
|
@ -0,0 +1,130 @@
|
|||
#include "display.h"
|
||||
|
||||
#include <avr/pgmspace.h>
|
||||
#include <avr/eeprom.h>
|
||||
|
||||
#include "bitwise.h"
|
||||
#include "math.h"
|
||||
#include "../../hardware_access/hardware_access.h"
|
||||
|
||||
|
||||
static uint8_t const configuration[] PROGMEM = {
|
||||
0xD5, 0xF0, // set clock frequency
|
||||
0x8D, 0x14, // enable charge pump
|
||||
0x20, 0x00, // horizontal addressing mode
|
||||
0xD6, 0x01, // 2 times vertical zoom
|
||||
0x22, 0x00, 0x03, // only draw to the top half of the screen
|
||||
0xAF // display on
|
||||
};
|
||||
|
||||
static struct {
|
||||
uint8_t compositingBuffer[DISPLAY_WIDTH_IN_PIXELS];
|
||||
Rectangle compositingWindow;
|
||||
DrawFunction drawEverything;
|
||||
bool wasIntersection;
|
||||
} display;
|
||||
|
||||
static inline void commandMode() {
|
||||
setOutputPin(DISPLAY_DC_OUTPUT_PIN, false);
|
||||
}
|
||||
|
||||
static inline void dataMode() {
|
||||
setOutputPin(DISPLAY_DC_OUTPUT_PIN, true);
|
||||
}
|
||||
|
||||
void setDisplayContrast(uint8_t value) {
|
||||
commandMode();
|
||||
sendByteOnSPI(0x81);
|
||||
sendByteOnSPI(value);
|
||||
dataMode();
|
||||
}
|
||||
|
||||
void initializeDisplay(DrawFunction drawEverything) {
|
||||
setOutputPin(DISPLAY_RESET_OUTPUT_PIN, false);
|
||||
for (volatile uint8_t i = 0; i != 255; i++)
|
||||
;
|
||||
// some time has to elapse before the next line gets called,
|
||||
// otherwise the display wont turn on
|
||||
setOutputPin(DISPLAY_RESET_OUTPUT_PIN, true);
|
||||
|
||||
for (uint8_t i = 0; i < sizeof(configuration); i++) {
|
||||
sendByteOnSPI(pgm_read_byte(configuration + i));
|
||||
}
|
||||
|
||||
display.drawEverything = drawEverything;
|
||||
setDisplayContrast(255);
|
||||
dataMode();
|
||||
}
|
||||
|
||||
void startIntersectionTest(Rectangle compositingWindow) {
|
||||
display.wasIntersection = false;
|
||||
display.compositingWindow = compositingWindow;
|
||||
}
|
||||
|
||||
bool endIntersectionTest() {
|
||||
for (uint8_t x = 0; x < DISPLAY_WIDTH_IN_PIXELS; x++) {
|
||||
display.compositingBuffer[x] = 0;
|
||||
}
|
||||
return display.wasIntersection;
|
||||
}
|
||||
|
||||
void drawFrame() {
|
||||
display.compositingWindow = DEFAULT_COMPOSITING_WINDOW;
|
||||
for (display.compositingWindow.position.y = 0; display.compositingWindow.position.y < DISPLAY_HEIGHT_IN_PIXELS; display.compositingWindow.position.y += 8) {
|
||||
display.drawEverything(display.compositingWindow);
|
||||
|
||||
for (uint8_t x = 0; x < DISPLAY_WIDTH_IN_PIXELS; x++) {
|
||||
sendByteOnSPI(display.compositingBuffer[x]);
|
||||
sendByteOnSPI(display.compositingBuffer[x]);
|
||||
display.compositingBuffer[x] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void compositePixelColumn(uint8_t x, uint8_t invertedMask, uint8_t fill) {
|
||||
if (display.compositingBuffer[x] & fill) {
|
||||
display.wasIntersection = true;
|
||||
}
|
||||
display.compositingBuffer[x] = (display.compositingBuffer[x] & (~invertedMask)) | fill;
|
||||
}
|
||||
|
||||
void drawBitmapFromProgMem(Rectangle boundingBox, uint16_t const bitmap[boundingBox.size.x][(boundingBox.size.y + 7) / 8], bool isMirrored) {
|
||||
boundingBox.position = substract(boundingBox.position, display.compositingWindow.position);
|
||||
|
||||
uint8_t spriteY = max(0, -boundingBox.position.y);
|
||||
uint8_t spriteYByte = spriteY >> 3;
|
||||
|
||||
for (uint8_t x = max(0, -boundingBox.position.x); x < boundingBox.size.x && boundingBox.position.x + x < DISPLAY_WIDTH_IN_PIXELS; x++) {
|
||||
uint8_t spriteX = isMirrored ? boundingBox.size.x - x - 1 : x;
|
||||
uint16_t currentPixelColumn = eeprom_read_word(&bitmap[spriteX][spriteYByte]);
|
||||
|
||||
uint8_t fill, invertedMask;
|
||||
if (boundingBox.position.y >= 0) {
|
||||
fill = (currentPixelColumn & 0x00FF) << boundingBox.position.y;
|
||||
invertedMask = currentPixelColumn >> 8 << boundingBox.position.y;
|
||||
} else {
|
||||
uint16_t lowerPixelColumn = spriteYByte + 1 < (boundingBox.size.y + 7) / 8 ? eeprom_read_word(&bitmap[spriteX][spriteYByte + 1]) : 0;
|
||||
uint8_t shift = spriteY % 8;
|
||||
uint8_t inverseShift = 8 - shift;
|
||||
|
||||
fill = ((currentPixelColumn & 0x00FF) >> shift) | ((lowerPixelColumn & 0x0FF) << inverseShift);
|
||||
invertedMask = (currentPixelColumn >> 8 >> shift) | (lowerPixelColumn >> 8 << inverseShift);
|
||||
}
|
||||
|
||||
compositePixelColumn(boundingBox.position.x + x, invertedMask, fill);
|
||||
}
|
||||
}
|
||||
|
||||
void drawFilledRectangle(Rectangle box, uint8_t invertedMask, uint8_t fill) {
|
||||
box.position = substract(box.position, display.compositingWindow.position);
|
||||
|
||||
uint8_t upperGapHeight = min(8, max(0, box.position.y));
|
||||
uint8_t lowerGapHeight = min(8, max(0, 8 - (box.position.y + box.size.y)));
|
||||
|
||||
uint8_t actualFill = (fill >> lowerGapHeight) & (fill << upperGapHeight);
|
||||
uint8_t actualInvertedMask = (invertedMask >> lowerGapHeight) & (invertedMask << upperGapHeight);
|
||||
|
||||
for (uint8_t x = max(0, box.position.x); x < box.position.x + box.size.x && x < DISPLAY_WIDTH_IN_PIXELS; x++) {
|
||||
compositePixelColumn(x, actualInvertedMask, actualFill);
|
||||
}
|
||||
}
|
||||
35
space_game/SpaceGame/src/driver/display/display.h
Normal file
35
space_game/SpaceGame/src/driver/display/display.h
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
#ifndef DISPLAY_H
|
||||
#define DISPLAY_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <avr/io.h>
|
||||
|
||||
#include "../../util/rectangle/rectangle.h"
|
||||
|
||||
|
||||
#define DISPLAY_RESET_OUTPUT_PIN PB0
|
||||
#define DISPLAY_DC_OUTPUT_PIN PB4
|
||||
|
||||
#define DISPLAY_WIDTH_IN_PIXELS 64
|
||||
#define DISPLAY_HEIGHT_IN_PIXELS 32
|
||||
|
||||
#define WINDOW ((Rectangle){(Vec2){0, 0}, (Vec2){DISPLAY_WIDTH_IN_PIXELS, DISPLAY_HEIGHT_IN_PIXELS}})
|
||||
#define DEFAULT_COMPOSITING_WINDOW ((Rectangle){(Vec2){0, 0}, (Vec2){DISPLAY_WIDTH_IN_PIXELS, 8}})
|
||||
|
||||
typedef void (*DrawFunction)(Rectangle);
|
||||
|
||||
void initializeDisplay(DrawFunction drawEverything);
|
||||
void setDisplayContrast(uint8_t value);
|
||||
|
||||
void startIntersectionTest();
|
||||
bool endIntersectionTest();
|
||||
|
||||
void drawFrame();
|
||||
|
||||
void drawBitmapFromProgMem(Rectangle boundingBox, uint16_t const bitmap[boundingBox.size.x][(boundingBox.size.y + 7) / 8], bool isMirrored);
|
||||
|
||||
// for white rectangle: invertedMask: don't care, fill: 0xFF
|
||||
// for black rectangle: invertedMask: 0xFF, fill: 0x00
|
||||
void drawFilledRectangle(Rectangle box, uint8_t invertedMask, uint8_t fill);
|
||||
|
||||
#endif
|
||||
146
space_game/SpaceGame/src/driver/infra/infra.c
Normal file
146
space_game/SpaceGame/src/driver/infra/infra.c
Normal file
|
|
@ -0,0 +1,146 @@
|
|||
#include "infra.h"
|
||||
|
||||
#include <avr/io.h>
|
||||
#include <avr/interrupt.h>
|
||||
|
||||
#include "bitwise.h"
|
||||
#include "../../hardware_access/hardware_access.h"
|
||||
#include "../uart/receive.h"
|
||||
|
||||
|
||||
// (0.5625 + (0.5625 + 1.6875) / 2) / 1000 / timer interval
|
||||
#define MEAN_OF_0_1_BIT_TIMES 53
|
||||
// 9 / 2 / 1000 / timer interval
|
||||
#define MAYBE_ONE_CHECK_TIME 141
|
||||
// some large value
|
||||
#define TIMEOUT 254
|
||||
|
||||
typedef enum {
|
||||
idle, maybeLeadingOne, leadingOneConfirmed, activeFirstBit, active, timingOut
|
||||
} ProtocolState;
|
||||
|
||||
typedef enum {
|
||||
noMatch, foundStartingByte, significantByte, waitingForEndOfCommand, waitingForRepeat
|
||||
} CommandState;
|
||||
|
||||
static struct {
|
||||
uint8_t current;
|
||||
uint8_t bitPosition;
|
||||
ProtocolState protocolState;
|
||||
CommandState commandState;
|
||||
OnCommandReceived onCommandReceived;
|
||||
} infra;
|
||||
|
||||
|
||||
static void saveCurrentByte() {
|
||||
uint8_t byte = infra.current;
|
||||
infra.current = 0;
|
||||
infra.bitPosition = 0;
|
||||
|
||||
if (byte == INFRA_ADDRESS) {
|
||||
infra.commandState = foundStartingByte;
|
||||
return;
|
||||
}
|
||||
|
||||
switch (infra.commandState) {
|
||||
case foundStartingByte:
|
||||
infra.commandState = significantByte;
|
||||
break;
|
||||
case significantByte:
|
||||
infra.onCommandReceived(byte);
|
||||
infra.commandState = waitingForEndOfCommand;
|
||||
break;
|
||||
case waitingForEndOfCommand:
|
||||
if (byte == 0) {
|
||||
infra.commandState = waitingForRepeat;
|
||||
}
|
||||
break;
|
||||
case waitingForRepeat:
|
||||
if (byte == 0) {
|
||||
infra.onCommandReceived(REPEAT_CODE);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void saveBit(uint8_t bit) {
|
||||
infra.current <<= 1;
|
||||
infra.current |= bit;
|
||||
if (++infra.bitPosition == 8) {
|
||||
saveCurrentByte();
|
||||
}
|
||||
}
|
||||
|
||||
static inline uint8_t isIrOff() {
|
||||
return getBit(PINB, IR_PIN);
|
||||
}
|
||||
|
||||
static inline uint8_t isIrOn() {
|
||||
return !isIrOff();
|
||||
}
|
||||
|
||||
ISR(PCINT0_vect) {
|
||||
handlePinChangeForUartReceive();
|
||||
switch (infra.protocolState) {
|
||||
case idle:
|
||||
if (isIrOn()) {
|
||||
enableTimerB(MAYBE_ONE_CHECK_TIME);
|
||||
infra.protocolState = maybeLeadingOne;
|
||||
}
|
||||
break;
|
||||
case maybeLeadingOne:
|
||||
infra.protocolState = idle;
|
||||
break;
|
||||
case leadingOneConfirmed:
|
||||
if (isIrOff()) {
|
||||
infra.protocolState = activeFirstBit;
|
||||
}
|
||||
break;
|
||||
case activeFirstBit:
|
||||
case timingOut:
|
||||
if (isIrOn()) {
|
||||
infra.protocolState = active;
|
||||
enableTimerB(MEAN_OF_0_1_BIT_TIMES);
|
||||
}
|
||||
break;
|
||||
case active:
|
||||
if (isIrOn()) {
|
||||
saveBit(1);
|
||||
enableTimerB(MEAN_OF_0_1_BIT_TIMES);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ISR(TIM0_COMPB_vect) {
|
||||
switch (infra.protocolState) {
|
||||
case maybeLeadingOne:
|
||||
if (isIrOn()) {
|
||||
infra.protocolState = leadingOneConfirmed;
|
||||
}
|
||||
disableTimerB();
|
||||
break;
|
||||
case active:
|
||||
saveBit(0);
|
||||
infra.protocolState = timingOut;
|
||||
enableTimerB(TIMEOUT);
|
||||
break;
|
||||
case timingOut:
|
||||
infra.protocolState = idle;
|
||||
saveCurrentByte();
|
||||
disableTimerB();
|
||||
break;
|
||||
default:
|
||||
disableTimerB();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void initializeInfra(OnCommandReceived onCommandReceived) {
|
||||
setBit(PORTB, IR_PIN); // enable pull-up
|
||||
setBit(PCMSK, IR_PIN); // specific pin change interrupt enable
|
||||
setBit(GIMSK, PCIE); // global on pin change interrupt enable;
|
||||
infra.onCommandReceived = onCommandReceived;
|
||||
}
|
||||
16
space_game/SpaceGame/src/driver/infra/infra.h
Normal file
16
space_game/SpaceGame/src/driver/infra/infra.h
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
#ifndef INFRA_H
|
||||
#define INFRA_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <avr/io.h>
|
||||
|
||||
|
||||
#define INFRA_ADDRESS 255
|
||||
#define IR_PIN PB4
|
||||
#define REPEAT_CODE 1
|
||||
|
||||
typedef void (*OnCommandReceived)(uint8_t);
|
||||
|
||||
void initializeInfra(OnCommandReceived onCommandReceived);
|
||||
|
||||
#endif
|
||||
34
space_game/SpaceGame/src/driver/sleep/sleep.c
Normal file
34
space_game/SpaceGame/src/driver/sleep/sleep.c
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
#include "sleep.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <avr/interrupt.h>
|
||||
#include <avr/sleep.h>
|
||||
|
||||
#include "bitwise.h"
|
||||
#include "../../hardware_access/hardware_access.h"
|
||||
|
||||
|
||||
#define TICKS_IN_MILISECOND 31
|
||||
|
||||
volatile int8_t milisecondsSinceFrameStart;
|
||||
|
||||
void startFrameLoop(FrameFunction function, uint8_t frameLengthInMilliseconds) {
|
||||
sleep_enable();
|
||||
|
||||
uint8_t previousFrameTime = 0;
|
||||
while (function(previousFrameTime)) {
|
||||
previousFrameTime = milisecondsSinceFrameStart;
|
||||
|
||||
while (milisecondsSinceFrameStart < frameLengthInMilliseconds) {
|
||||
sleep_cpu();
|
||||
}
|
||||
|
||||
milisecondsSinceFrameStart = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ISR(TIM0_COMPA_vect) {
|
||||
milisecondsSinceFrameStart++;
|
||||
enableTimerA(TICKS_IN_MILISECOND);
|
||||
}
|
||||
13
space_game/SpaceGame/src/driver/sleep/sleep.h
Normal file
13
space_game/SpaceGame/src/driver/sleep/sleep.h
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#ifndef SLEEP_H
|
||||
#define SLEEP_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <avr/io.h>
|
||||
|
||||
|
||||
typedef bool (*FrameFunction)(uint8_t);
|
||||
|
||||
// frameFunction gets previousFrameTime (in milliseconds) as argument
|
||||
void startFrameLoop(FrameFunction function, uint8_t frameLengthInMilliseconds);
|
||||
|
||||
#endif
|
||||
49
space_game/SpaceGame/src/driver/uart/receive.c
Normal file
49
space_game/SpaceGame/src/driver/uart/receive.c
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
#include <stdbool.h>
|
||||
#include <avr/interrupt.h>
|
||||
|
||||
#include "receive.h"
|
||||
#include "bitwise.h"
|
||||
#include "../../hardware_access/hardware_access.h"
|
||||
|
||||
|
||||
static struct {
|
||||
uint16_t message;
|
||||
uint8_t bitPosition; // goes from 0 to 9
|
||||
bool previousValue;
|
||||
uint8_t previousTimestamp;
|
||||
OnCommandReceived onCommandReceived;
|
||||
} uartReceive = {
|
||||
.previousValue = true
|
||||
};
|
||||
|
||||
void initializeUartReceive(OnCommandReceived onCommandReceived) {
|
||||
setBit(PORTB, RECEIVE_PIN); // setup pull-up
|
||||
setBit(PCMSK, RECEIVE_PIN); // enable interrupt on pin
|
||||
uartReceive.onCommandReceived = onCommandReceived;
|
||||
}
|
||||
|
||||
void handlePinChangeForUartReceive() {
|
||||
bool currentValue = getBit(PINB, RECEIVE_PIN);
|
||||
|
||||
if (uartReceive.previousValue != currentValue) {
|
||||
uint8_t elapsedBitCount = (getTimeSince(uartReceive.previousTimestamp) + BIT_TIME / 2) / BIT_TIME;
|
||||
uartReceive.message >>= elapsedBitCount;
|
||||
uartReceive.bitPosition += elapsedBitCount;
|
||||
|
||||
if (uartReceive.bitPosition == 9) {
|
||||
uartReceive.onCommandReceived((uint8_t)(uartReceive.message));
|
||||
uartReceive.bitPosition = 0;
|
||||
}
|
||||
|
||||
if (uartReceive.previousValue == true && currentValue == false) {
|
||||
if (uartReceive.bitPosition != elapsedBitCount) {
|
||||
uartReceive.message |= (uint8_t)(0xFF << (8 - elapsedBitCount));
|
||||
} else {
|
||||
uartReceive.bitPosition = 0;
|
||||
}
|
||||
}
|
||||
|
||||
uartReceive.previousTimestamp = getTimestampFromFastTimer();
|
||||
uartReceive.previousValue = currentValue;
|
||||
}
|
||||
}
|
||||
15
space_game/SpaceGame/src/driver/uart/receive.h
Normal file
15
space_game/SpaceGame/src/driver/uart/receive.h
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
#ifndef RECEIVE_H
|
||||
#define RECEIVE_H
|
||||
|
||||
// 8*10^6 / 256 / 1200
|
||||
#define BIT_TIME 26
|
||||
#define RECEIVE_PIN PB3
|
||||
|
||||
|
||||
typedef void (*OnCommandReceived)(uint8_t);
|
||||
|
||||
void initializeUartReceive(OnCommandReceived onCommandReceived);
|
||||
|
||||
void handlePinChangeForUartReceive();
|
||||
|
||||
#endif
|
||||
74
space_game/SpaceGame/src/driver/uart/transmit.c
Normal file
74
space_game/SpaceGame/src/driver/uart/transmit.c
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
#include "transmit.h"
|
||||
|
||||
#include <avr/io.h>
|
||||
#include <avr/interrupt.h>
|
||||
|
||||
#include "bitwise.h"
|
||||
#include "../../hardware_access/hardware_access.h"
|
||||
|
||||
static struct {
|
||||
char bytes[ASYNC_BUFFER_SIZE];
|
||||
uint8_t start;
|
||||
uint8_t end;
|
||||
// 0 - start bit, 1-8 word bits, 9 - end bit
|
||||
uint8_t currentMaskPosition;
|
||||
} uartTransmitter;
|
||||
|
||||
static inline void send0() {
|
||||
setOutputPin(UART_OUTPUT_PIN, false);
|
||||
}
|
||||
|
||||
static inline void send1() {
|
||||
setOutputPin(UART_OUTPUT_PIN, true);
|
||||
}
|
||||
|
||||
ISR(TIM1_COMPA_vect) {
|
||||
enableFastTimerA(BIT_TIME);
|
||||
switch(uartTransmitter.currentMaskPosition) {
|
||||
case 0:
|
||||
send0();
|
||||
uartTransmitter.currentMaskPosition++;
|
||||
break;
|
||||
case 9:
|
||||
send1();
|
||||
uartTransmitter.start = (uartTransmitter.start + 1) % ASYNC_BUFFER_SIZE;
|
||||
if (uartTransmitter.start == uartTransmitter.end) {
|
||||
disableFastTimerA();
|
||||
}
|
||||
uartTransmitter.currentMaskPosition = 0;
|
||||
break;
|
||||
default:
|
||||
uartTransmitter.bytes[uartTransmitter.start] & BV(uartTransmitter.currentMaskPosition - 1) ? send1() : send0();
|
||||
uartTransmitter.currentMaskPosition++;
|
||||
}
|
||||
}
|
||||
|
||||
void sendByteOnUartAsync(char byte) {
|
||||
cli();
|
||||
uartTransmitter.bytes[uartTransmitter.end] = byte;
|
||||
if (uartTransmitter.start == uartTransmitter.end) {
|
||||
enableFastTimerA(BIT_TIME);
|
||||
}
|
||||
uartTransmitter.end = (uartTransmitter.end + 1) % ASYNC_BUFFER_SIZE;
|
||||
|
||||
sei();
|
||||
}
|
||||
|
||||
void sendTextOnUartAsync(char text[]) {
|
||||
for (uint8_t i = 0; text[i]; i++) {
|
||||
sendByteOnUartAsync(text[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void sendUintOnUartAsync(uint8_t number) {
|
||||
sendByteOnUartAsync(number >= 100 ? '0' + number / 100 : ' ');
|
||||
number %= 100;
|
||||
sendByteOnUartAsync(number >= 10 ? '0' + number / 10 : ' ');
|
||||
number %= 10;
|
||||
sendByteOnUartAsync('0' + number);
|
||||
}
|
||||
|
||||
|
||||
void initializeUartTransmit() {
|
||||
send1();
|
||||
}
|
||||
18
space_game/SpaceGame/src/driver/uart/transmit.h
Normal file
18
space_game/SpaceGame/src/driver/uart/transmit.h
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
#ifndef TRANSMIT_H
|
||||
#define TRANSMIT_H
|
||||
|
||||
#include <avr/io.h>
|
||||
|
||||
|
||||
// 8*10^6 / 256 / 1200
|
||||
#define BIT_TIME 26
|
||||
#define ASYNC_BUFFER_SIZE 20
|
||||
#define UART_OUTPUT_PIN 2
|
||||
|
||||
|
||||
void initializeUartTransmit();
|
||||
void sendByteOnUartAsync(char byte);
|
||||
void sendTextOnUartAsync(char text[]);
|
||||
void sendUintOnUartAsync(uint8_t number);
|
||||
|
||||
#endif
|
||||
15
space_game/SpaceGame/src/hardware_access/eeprom/eeprom.h
Normal file
15
space_game/SpaceGame/src/hardware_access/eeprom/eeprom.h
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
#ifndef EEPROM_H
|
||||
#define EEPROM_H
|
||||
|
||||
#include <avr/io.h>
|
||||
|
||||
|
||||
#define STORAGE_SIZE 52
|
||||
|
||||
typedef void (*OnEEPROMFinished)(uint8_t*);
|
||||
|
||||
inline void initializeEEPROM() {
|
||||
EECR = 0; // atomic write
|
||||
}
|
||||
|
||||
#endif
|
||||
12
space_game/SpaceGame/src/hardware_access/hardware_access.c
Normal file
12
space_game/SpaceGame/src/hardware_access/hardware_access.c
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
#include "hardware_access.h"
|
||||
|
||||
#include <avr/interrupt.h>
|
||||
|
||||
|
||||
void initializeHardwareAccess() {
|
||||
sei();
|
||||
initializePowerSaving();
|
||||
initializeSPI();
|
||||
initializeTiming();
|
||||
initializeOutputPins();
|
||||
}
|
||||
30
space_game/SpaceGame/src/hardware_access/hardware_access.h
Normal file
30
space_game/SpaceGame/src/hardware_access/hardware_access.h
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
#ifndef HARDWARE_ACCESS_H
|
||||
#define HARDWARE_ACCESS_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <avr/io.h>
|
||||
#include "bitwise.h"
|
||||
|
||||
#include "power_saving/power_saving.h"
|
||||
#include "spi/spi.h"
|
||||
#include "eeprom/eeprom.h"
|
||||
#include "timing/timing.h"
|
||||
|
||||
#include "output_pins/output_pins.h"
|
||||
|
||||
|
||||
void initializeHardwareAccess();
|
||||
|
||||
void enableTimerA(uint8_t triggerInterruptInXTicks);
|
||||
void enableTimerB(uint8_t triggerInterruptInXTicks);
|
||||
void disableTimerB();
|
||||
void enableFastTimerA(uint8_t triggerInterruptInXTicks);
|
||||
void disableFastTimerA();
|
||||
uint8_t getTimestampFromFastTimer();
|
||||
uint8_t getTimeSince(uint8_t timestamp);
|
||||
|
||||
void sendByteOnSPI(uint8_t byte);
|
||||
|
||||
void setOutputPin(uint8_t id, bool value);
|
||||
|
||||
#endif
|
||||
19
space_game/SpaceGame/src/hardware_access/output_pins.c
Normal file
19
space_game/SpaceGame/src/hardware_access/output_pins.c
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
#include "shift_register_output_pins.h"
|
||||
#include "bitwise.h"
|
||||
#include "../../spi/spi.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
|
||||
static uint8_t currentValue = 0;
|
||||
|
||||
void sendCurrentValue() {
|
||||
clearBit(PORTB, CLK_ST_PIN);
|
||||
sendByteOnSPI(currentValue);
|
||||
setBit(PORTB, CLK_ST_PIN);
|
||||
}
|
||||
|
||||
void setOutputPin(uint8_t id, bool value) {
|
||||
currentValue = (currentValue & ~BV(id)) | (value & 1) << id;
|
||||
sendCurrentValue();
|
||||
}
|
||||
18
space_game/SpaceGame/src/hardware_access/output_pins.h
Normal file
18
space_game/SpaceGame/src/hardware_access/output_pins.h
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
#ifndef SHIFT_REGITER_OUTPUT_PINS_H
|
||||
#define SHIFT_REGITER_OUTPUT_PINS_H
|
||||
|
||||
#include <avr/io.h>
|
||||
|
||||
#include "bitwise.h"
|
||||
|
||||
#define CLK_ST_PIN PB0
|
||||
|
||||
void sendCurrentValue();
|
||||
|
||||
inline void initializeOutputPins() {
|
||||
setBit(DDRB, CLK_ST_PIN);
|
||||
setBit(PORTB, CLK_ST_PIN);
|
||||
sendCurrentValue();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
#include "output_pins.h"
|
||||
#include "bitwise.h"
|
||||
#include "../spi/spi.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
|
||||
static uint8_t currentValue = 0;
|
||||
|
||||
void sendCurrentValue() {
|
||||
clearBit(PORTB, CLK_ST_PIN);
|
||||
sendByteOnSPI(currentValue);
|
||||
setBit(PORTB, CLK_ST_PIN);
|
||||
}
|
||||
|
||||
void setOutputPin(uint8_t id, bool value) {
|
||||
currentValue = (currentValue & ~BV(id)) | (value & 1) << id;
|
||||
sendCurrentValue();
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
#ifndef SHIFT_REGITER_OUTPUT_PINS_H
|
||||
#define SHIFT_REGITER_OUTPUT_PINS_H
|
||||
|
||||
#include <avr/io.h>
|
||||
|
||||
#include "bitwise.h"
|
||||
|
||||
#define CLK_ST_PIN PB0
|
||||
|
||||
void sendCurrentValue();
|
||||
|
||||
inline void initializeOutputPins() {
|
||||
setBit(DDRB, CLK_ST_PIN);
|
||||
setBit(PORTB, CLK_ST_PIN);
|
||||
sendCurrentValue();
|
||||
}
|
||||
|
||||
#endif
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue