1.USB debugged 2.Added modules
This commit is contained in:
parent
b837c2aef0
commit
f5441b6257
Binary file not shown.
|
|
@ -34,14 +34,16 @@
|
||||||
<option id="common.boards" value="Add" config="" content-id="Atmel.ASF" />
|
<option id="common.boards" value="Add" config="" content-id="Atmel.ASF" />
|
||||||
<option id="common.services.basic.sleepmgr" value="Add" config="" content-id="Atmel.ASF" />
|
<option id="common.services.basic.sleepmgr" value="Add" config="" content-id="Atmel.ASF" />
|
||||||
<option id="common.services.usb.class.device" value="Add" config="cdc_stdio" content-id="Atmel.ASF" />
|
<option id="common.services.usb.class.device" value="Add" config="cdc_stdio" content-id="Atmel.ASF" />
|
||||||
|
<option id="common.utils.interrupt" value="Add" config="" content-id="Atmel.ASF" />
|
||||||
|
<option id="common2.services.delay" value="Add" config="systick" content-id="Atmel.ASF" />
|
||||||
|
<option id="sam0.drivers.adc" value="Add" config="callback" content-id="Atmel.ASF" />
|
||||||
|
<option id="sam0.drivers.dac" value="Add" config="callback" content-id="Atmel.ASF" />
|
||||||
<option id="sam0.drivers.port" value="Add" config="" content-id="Atmel.ASF" />
|
<option id="sam0.drivers.port" value="Add" config="" content-id="Atmel.ASF" />
|
||||||
<option id="sam0.drivers.sercom.usart" value="Add" config="callback" content-id="Atmel.ASF" />
|
<option id="sam0.drivers.sercom.usart" value="Add" config="callback" content-id="Atmel.ASF" />
|
||||||
<option id="sam0.drivers.system" value="Add" config="" content-id="Atmel.ASF" />
|
<option id="sam0.drivers.system" value="Add" config="" content-id="Atmel.ASF" />
|
||||||
|
<option id="sam0.drivers.tcc" value="Add" config="polled" content-id="Atmel.ASF" />
|
||||||
<option id="thirdparty.os.freertos.version" value="Add" config="10.0.0" content-id="Atmel.ASF" />
|
<option id="thirdparty.os.freertos.version" value="Add" config="10.0.0" content-id="Atmel.ASF" />
|
||||||
<option id="sam0.drivers.dac" value="Add" config="callback" content-id="Atmel.ASF" />
|
<option id="sam0.drivers.tc" value="Add" config="callback" content-id="Atmel.ASF" />
|
||||||
<option id="sam0.drivers.adc" value="Add" config="callback" content-id="Atmel.ASF" />
|
|
||||||
<option id="common2.services.delay" value="Add" config="systick" content-id="Atmel.ASF" />
|
|
||||||
<option id="common.utils.interrupt" value="Add" config="" content-id="Atmel.ASF" />
|
|
||||||
<option id="common.services.usb.class.cdc.device.example" value="Add" config="" content-id="Atmel.ASF" />
|
<option id="common.services.usb.class.cdc.device.example" value="Add" config="" content-id="Atmel.ASF" />
|
||||||
<option id="common.utils" value="Add" config="" content-id="Atmel.ASF" />
|
<option id="common.utils" value="Add" config="" content-id="Atmel.ASF" />
|
||||||
<option id="sam0.utils.cmsis.samd21.source.template" value="Add" config="" content-id="Atmel.ASF" />
|
<option id="sam0.utils.cmsis.samd21.source.template" value="Add" config="" content-id="Atmel.ASF" />
|
||||||
|
|
@ -334,6 +336,15 @@
|
||||||
<file path="src/ASF/sam0/drivers/dac/dac_sam_d_c_h/dac.c" framework="" version="3.49.1" source="sam0\drivers\dac\dac_sam_d_c_h\dac.c" changed="False" content-id="Atmel.ASF" />
|
<file path="src/ASF/sam0/drivers/dac/dac_sam_d_c_h/dac.c" framework="" version="3.49.1" source="sam0\drivers\dac\dac_sam_d_c_h\dac.c" changed="False" content-id="Atmel.ASF" />
|
||||||
<file path="src/ASF/sam0/drivers/dac/dac_sam_d_c_h/dac_callback.c" framework="" version="3.49.1" source="sam0\drivers\dac\dac_sam_d_c_h\dac_callback.c" changed="False" content-id="Atmel.ASF" />
|
<file path="src/ASF/sam0/drivers/dac/dac_sam_d_c_h/dac_callback.c" framework="" version="3.49.1" source="sam0\drivers\dac\dac_sam_d_c_h\dac_callback.c" changed="False" content-id="Atmel.ASF" />
|
||||||
<file path="src/ASF/sam0/drivers/dac/dac_sam_d_c_h/dac_feature.h" framework="" version="3.49.1" source="sam0\drivers\dac\dac_sam_d_c_h\dac_feature.h" changed="False" content-id="Atmel.ASF" />
|
<file path="src/ASF/sam0/drivers/dac/dac_sam_d_c_h/dac_feature.h" framework="" version="3.49.1" source="sam0\drivers\dac\dac_sam_d_c_h\dac_feature.h" changed="False" content-id="Atmel.ASF" />
|
||||||
|
<file path="src/ASF/sam0/drivers/tcc/tcc.c" framework="" version="3.49.1" source="sam0\drivers\tcc\tcc.c" changed="False" content-id="Atmel.ASF" />
|
||||||
|
<file path="src/ASF/sam0/drivers/tcc/quick_start_buffering/qs_tcc_buffering.h" framework="" version="3.49.1" source="sam0\drivers\tcc\quick_start_buffering\qs_tcc_buffering.h" changed="False" content-id="Atmel.ASF" />
|
||||||
|
<file path="src/ASF/sam0/drivers/tcc/quick_start_dma/qs_tcc_dma.h" framework="" version="3.49.1" source="sam0\drivers\tcc\quick_start_dma\qs_tcc_dma.h" changed="False" content-id="Atmel.ASF" />
|
||||||
|
<file path="src/ASF/sam0/drivers/tcc/tcc.h" framework="" version="3.49.1" source="sam0\drivers\tcc\tcc.h" changed="False" content-id="Atmel.ASF" />
|
||||||
|
<file path="src/ASF/sam0/drivers/tcc/quick_start/qs_tcc_basic.h" framework="" version="3.49.1" source="sam0\drivers\tcc\quick_start\qs_tcc_basic.h" changed="False" content-id="Atmel.ASF" />
|
||||||
|
<file path="src/ASF/sam0/drivers/tc/tc_interrupt.c" framework="" version="3.49.1" source="sam0\drivers\tc\tc_interrupt.c" changed="False" content-id="Atmel.ASF" />
|
||||||
|
<file path="src/ASF/sam0/drivers/tc/tc_interrupt.h" framework="" version="3.49.1" source="sam0\drivers\tc\tc_interrupt.h" changed="False" content-id="Atmel.ASF" />
|
||||||
|
<file path="src/ASF/sam0/drivers/tc/tc.h" framework="" version="3.49.1" source="sam0\drivers\tc\tc.h" changed="False" content-id="Atmel.ASF" />
|
||||||
|
<file path="src/ASF/sam0/drivers/tc/tc_sam_d_r_h/tc.c" framework="" version="3.49.1" source="sam0\drivers\tc\tc_sam_d_r_h\tc.c" changed="False" content-id="Atmel.ASF" />
|
||||||
</files>
|
</files>
|
||||||
<documentation help="https://asf.microchip.com/docs/3.49.1/common.services.usb.class.cdc.device.example.samd21_xpro/html/index.html" />
|
<documentation help="https://asf.microchip.com/docs/3.49.1/common.services.usb.class.cdc.device.example.samd21_xpro/html/index.html" />
|
||||||
<offline-documentation help="" />
|
<offline-documentation help="" />
|
||||||
|
|
@ -383,6 +394,8 @@
|
||||||
<Value>SYSTICK_MODE</Value>
|
<Value>SYSTICK_MODE</Value>
|
||||||
<Value>ADC_CALLBACK_MODE=true</Value>
|
<Value>ADC_CALLBACK_MODE=true</Value>
|
||||||
<Value>DAC_CALLBACK_MODE=true</Value>
|
<Value>DAC_CALLBACK_MODE=true</Value>
|
||||||
|
<Value>TCC_ASYNC=false</Value>
|
||||||
|
<Value>TC_ASYNC=true</Value>
|
||||||
</ListValues>
|
</ListValues>
|
||||||
</armgcc.compiler.symbols.DefSymbols>
|
</armgcc.compiler.symbols.DefSymbols>
|
||||||
<armgcc.compiler.directories.IncludePaths>
|
<armgcc.compiler.directories.IncludePaths>
|
||||||
|
|
@ -431,6 +444,9 @@
|
||||||
<Value>../src/ASF/sam0/drivers/adc/adc_sam_d_r_h</Value>
|
<Value>../src/ASF/sam0/drivers/adc/adc_sam_d_r_h</Value>
|
||||||
<Value>../src/ASF/sam0/drivers/dac</Value>
|
<Value>../src/ASF/sam0/drivers/dac</Value>
|
||||||
<Value>../src/ASF/sam0/drivers/dac/dac_sam_d_c_h</Value>
|
<Value>../src/ASF/sam0/drivers/dac/dac_sam_d_c_h</Value>
|
||||||
|
<Value>../src/ASF/sam0/drivers/tcc</Value>
|
||||||
|
<Value>../src/ASF/sam0/drivers/tc</Value>
|
||||||
|
<Value>../src/ASF/sam0/drivers/tc/tc_sam_d_r_h</Value>
|
||||||
</ListValues>
|
</ListValues>
|
||||||
</armgcc.compiler.directories.IncludePaths>
|
</armgcc.compiler.directories.IncludePaths>
|
||||||
<armgcc.compiler.optimization.level>Optimize for size (-Os)</armgcc.compiler.optimization.level>
|
<armgcc.compiler.optimization.level>Optimize for size (-Os)</armgcc.compiler.optimization.level>
|
||||||
|
|
@ -498,9 +514,12 @@
|
||||||
<Value>../src/ASF/sam0/drivers/adc/adc_sam_d_r_h</Value>
|
<Value>../src/ASF/sam0/drivers/adc/adc_sam_d_r_h</Value>
|
||||||
<Value>../src/ASF/sam0/drivers/dac</Value>
|
<Value>../src/ASF/sam0/drivers/dac</Value>
|
||||||
<Value>../src/ASF/sam0/drivers/dac/dac_sam_d_c_h</Value>
|
<Value>../src/ASF/sam0/drivers/dac/dac_sam_d_c_h</Value>
|
||||||
|
<Value>../src/ASF/sam0/drivers/tcc</Value>
|
||||||
|
<Value>../src/ASF/sam0/drivers/tc</Value>
|
||||||
|
<Value>../src/ASF/sam0/drivers/tc/tc_sam_d_r_h</Value>
|
||||||
</ListValues>
|
</ListValues>
|
||||||
</armgcc.assembler.general.IncludePaths>
|
</armgcc.assembler.general.IncludePaths>
|
||||||
<armgcc.preprocessingassembler.general.AssemblerFlags>-DARM_MATH_CM0PLUS=true -DBOARD=SAMD21_XPLAINED_PRO -DEXTINT_CALLBACK_MODE=true -DUDD_ENABLE -DUSART_CALLBACK_MODE=true -DUSB_DEVICE_LPM_SUPPORT -D__SAMD21J18A__ -D__FREERTOS__ -DSYSTICK_MODE -DADC_CALLBACK_MODE=true -DDAC_CALLBACK_MODE=true</armgcc.preprocessingassembler.general.AssemblerFlags>
|
<armgcc.preprocessingassembler.general.AssemblerFlags>-DARM_MATH_CM0PLUS=true -DBOARD=SAMD21_XPLAINED_PRO -DEXTINT_CALLBACK_MODE=true -DUDD_ENABLE -DUSART_CALLBACK_MODE=true -DUSB_DEVICE_LPM_SUPPORT -D__SAMD21J18A__ -D__FREERTOS__ -DSYSTICK_MODE -DADC_CALLBACK_MODE=true -DDAC_CALLBACK_MODE=true -DTCC_ASYNC=false -DTC_ASYNC=true</armgcc.preprocessingassembler.general.AssemblerFlags>
|
||||||
<armgcc.preprocessingassembler.general.IncludePaths>
|
<armgcc.preprocessingassembler.general.IncludePaths>
|
||||||
<ListValues>
|
<ListValues>
|
||||||
<Value>../src</Value>
|
<Value>../src</Value>
|
||||||
|
|
@ -547,6 +566,9 @@
|
||||||
<Value>../src/ASF/sam0/drivers/adc/adc_sam_d_r_h</Value>
|
<Value>../src/ASF/sam0/drivers/adc/adc_sam_d_r_h</Value>
|
||||||
<Value>../src/ASF/sam0/drivers/dac</Value>
|
<Value>../src/ASF/sam0/drivers/dac</Value>
|
||||||
<Value>../src/ASF/sam0/drivers/dac/dac_sam_d_c_h</Value>
|
<Value>../src/ASF/sam0/drivers/dac/dac_sam_d_c_h</Value>
|
||||||
|
<Value>../src/ASF/sam0/drivers/tcc</Value>
|
||||||
|
<Value>../src/ASF/sam0/drivers/tc</Value>
|
||||||
|
<Value>../src/ASF/sam0/drivers/tc/tc_sam_d_r_h</Value>
|
||||||
</ListValues>
|
</ListValues>
|
||||||
</armgcc.preprocessingassembler.general.IncludePaths>
|
</armgcc.preprocessingassembler.general.IncludePaths>
|
||||||
</ArmGcc>
|
</ArmGcc>
|
||||||
|
|
@ -574,6 +596,8 @@
|
||||||
<Value>SYSTICK_MODE</Value>
|
<Value>SYSTICK_MODE</Value>
|
||||||
<Value>ADC_CALLBACK_MODE=true</Value>
|
<Value>ADC_CALLBACK_MODE=true</Value>
|
||||||
<Value>DAC_CALLBACK_MODE=true</Value>
|
<Value>DAC_CALLBACK_MODE=true</Value>
|
||||||
|
<Value>TCC_ASYNC=false</Value>
|
||||||
|
<Value>TC_ASYNC=true</Value>
|
||||||
</ListValues>
|
</ListValues>
|
||||||
</armgcc.compiler.symbols.DefSymbols>
|
</armgcc.compiler.symbols.DefSymbols>
|
||||||
<armgcc.compiler.directories.IncludePaths>
|
<armgcc.compiler.directories.IncludePaths>
|
||||||
|
|
@ -623,6 +647,9 @@
|
||||||
<Value>../src/ASF/sam0/drivers/adc/adc_sam_d_r_h</Value>
|
<Value>../src/ASF/sam0/drivers/adc/adc_sam_d_r_h</Value>
|
||||||
<Value>../src/ASF/sam0/drivers/dac</Value>
|
<Value>../src/ASF/sam0/drivers/dac</Value>
|
||||||
<Value>../src/ASF/sam0/drivers/dac/dac_sam_d_c_h</Value>
|
<Value>../src/ASF/sam0/drivers/dac/dac_sam_d_c_h</Value>
|
||||||
|
<Value>../src/ASF/sam0/drivers/tcc</Value>
|
||||||
|
<Value>../src/ASF/sam0/drivers/tc</Value>
|
||||||
|
<Value>../src/ASF/sam0/drivers/tc/tc_sam_d_r_h</Value>
|
||||||
</ListValues>
|
</ListValues>
|
||||||
</armgcc.compiler.directories.IncludePaths>
|
</armgcc.compiler.directories.IncludePaths>
|
||||||
<armgcc.compiler.optimization.OtherFlags>-fdata-sections</armgcc.compiler.optimization.OtherFlags>
|
<armgcc.compiler.optimization.OtherFlags>-fdata-sections</armgcc.compiler.optimization.OtherFlags>
|
||||||
|
|
@ -691,10 +718,13 @@
|
||||||
<Value>../src/ASF/sam0/drivers/adc/adc_sam_d_r_h</Value>
|
<Value>../src/ASF/sam0/drivers/adc/adc_sam_d_r_h</Value>
|
||||||
<Value>../src/ASF/sam0/drivers/dac</Value>
|
<Value>../src/ASF/sam0/drivers/dac</Value>
|
||||||
<Value>../src/ASF/sam0/drivers/dac/dac_sam_d_c_h</Value>
|
<Value>../src/ASF/sam0/drivers/dac/dac_sam_d_c_h</Value>
|
||||||
|
<Value>../src/ASF/sam0/drivers/tcc</Value>
|
||||||
|
<Value>../src/ASF/sam0/drivers/tc</Value>
|
||||||
|
<Value>../src/ASF/sam0/drivers/tc/tc_sam_d_r_h</Value>
|
||||||
</ListValues>
|
</ListValues>
|
||||||
</armgcc.assembler.general.IncludePaths>
|
</armgcc.assembler.general.IncludePaths>
|
||||||
<armgcc.assembler.debugging.DebugLevel>Default (-g)</armgcc.assembler.debugging.DebugLevel>
|
<armgcc.assembler.debugging.DebugLevel>Default (-g)</armgcc.assembler.debugging.DebugLevel>
|
||||||
<armgcc.preprocessingassembler.general.AssemblerFlags>-DARM_MATH_CM0PLUS=true -DBOARD=USER_BOARD -DEXTINT_CALLBACK_MODE=true -DUDD_ENABLE -DUSART_CALLBACK_MODE=true -DUSB_DEVICE_LPM_SUPPORT -D__SAMD21E16B__ -D__FREERTOS__ -DSYSTICK_MODE -DADC_CALLBACK_MODE=true -DDAC_CALLBACK_MODE=true</armgcc.preprocessingassembler.general.AssemblerFlags>
|
<armgcc.preprocessingassembler.general.AssemblerFlags>-DARM_MATH_CM0PLUS=true -DBOARD=USER_BOARD -DEXTINT_CALLBACK_MODE=true -DUDD_ENABLE -DUSART_CALLBACK_MODE=true -DUSB_DEVICE_LPM_SUPPORT -D__SAMD21E16B__ -D__FREERTOS__ -DSYSTICK_MODE -DADC_CALLBACK_MODE=true -DDAC_CALLBACK_MODE=true -DTCC_ASYNC=false -DTC_ASYNC=true</armgcc.preprocessingassembler.general.AssemblerFlags>
|
||||||
<armgcc.preprocessingassembler.general.IncludePaths>
|
<armgcc.preprocessingassembler.general.IncludePaths>
|
||||||
<ListValues>
|
<ListValues>
|
||||||
<Value>../src</Value>
|
<Value>../src</Value>
|
||||||
|
|
@ -741,6 +771,9 @@
|
||||||
<Value>../src/ASF/sam0/drivers/adc/adc_sam_d_r_h</Value>
|
<Value>../src/ASF/sam0/drivers/adc/adc_sam_d_r_h</Value>
|
||||||
<Value>../src/ASF/sam0/drivers/dac</Value>
|
<Value>../src/ASF/sam0/drivers/dac</Value>
|
||||||
<Value>../src/ASF/sam0/drivers/dac/dac_sam_d_c_h</Value>
|
<Value>../src/ASF/sam0/drivers/dac/dac_sam_d_c_h</Value>
|
||||||
|
<Value>../src/ASF/sam0/drivers/tcc</Value>
|
||||||
|
<Value>../src/ASF/sam0/drivers/tc</Value>
|
||||||
|
<Value>../src/ASF/sam0/drivers/tc/tc_sam_d_r_h</Value>
|
||||||
</ListValues>
|
</ListValues>
|
||||||
</armgcc.preprocessingassembler.general.IncludePaths>
|
</armgcc.preprocessingassembler.general.IncludePaths>
|
||||||
<armgcc.preprocessingassembler.debugging.DebugLevel>Default (-Wa,-g)</armgcc.preprocessingassembler.debugging.DebugLevel>
|
<armgcc.preprocessingassembler.debugging.DebugLevel>Default (-Wa,-g)</armgcc.preprocessingassembler.debugging.DebugLevel>
|
||||||
|
|
@ -799,6 +832,12 @@
|
||||||
<Folder Include="src\ASF\sam0\drivers\system\power\power_sam_d_r_h\" />
|
<Folder Include="src\ASF\sam0\drivers\system\power\power_sam_d_r_h\" />
|
||||||
<Folder Include="src\ASF\sam0\drivers\system\reset\" />
|
<Folder Include="src\ASF\sam0\drivers\system\reset\" />
|
||||||
<Folder Include="src\ASF\sam0\drivers\system\reset\reset_sam_d_r_h\" />
|
<Folder Include="src\ASF\sam0\drivers\system\reset\reset_sam_d_r_h\" />
|
||||||
|
<Folder Include="src\ASF\sam0\drivers\tcc\" />
|
||||||
|
<Folder Include="src\ASF\sam0\drivers\tcc\quick_start\" />
|
||||||
|
<Folder Include="src\ASF\sam0\drivers\tcc\quick_start_buffering\" />
|
||||||
|
<Folder Include="src\ASF\sam0\drivers\tcc\quick_start_dma\" />
|
||||||
|
<Folder Include="src\ASF\sam0\drivers\tc\" />
|
||||||
|
<Folder Include="src\ASF\sam0\drivers\tc\tc_sam_d_r_h\" />
|
||||||
<Folder Include="src\ASF\sam0\drivers\usb\" />
|
<Folder Include="src\ASF\sam0\drivers\usb\" />
|
||||||
<Folder Include="src\ASF\sam0\drivers\usb\stack_interface\" />
|
<Folder Include="src\ASF\sam0\drivers\usb\stack_interface\" />
|
||||||
<Folder Include="src\ASF\sam0\drivers\usb\usb_sam_d_r\" />
|
<Folder Include="src\ASF\sam0\drivers\usb\usb_sam_d_r\" />
|
||||||
|
|
@ -886,6 +925,33 @@
|
||||||
<None Include="src\ASF\sam0\drivers\dac\dac_sam_d_c_h\dac_feature.h">
|
<None Include="src\ASF\sam0\drivers\dac\dac_sam_d_c_h\dac_feature.h">
|
||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</None>
|
</None>
|
||||||
|
<None Include="src\ASF\sam0\drivers\tcc\quick_start_buffering\qs_tcc_buffering.h">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</None>
|
||||||
|
<None Include="src\ASF\sam0\drivers\tcc\quick_start_dma\qs_tcc_dma.h">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</None>
|
||||||
|
<None Include="src\ASF\sam0\drivers\tcc\quick_start\qs_tcc_basic.h">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</None>
|
||||||
|
<Compile Include="src\ASF\sam0\drivers\tcc\tcc.c">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
|
<None Include="src\ASF\sam0\drivers\tcc\tcc.h">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</None>
|
||||||
|
<None Include="src\ASF\sam0\drivers\tc\tc.h">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</None>
|
||||||
|
<Compile Include="src\ASF\sam0\drivers\tc\tc_interrupt.c">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
|
<None Include="src\ASF\sam0\drivers\tc\tc_interrupt.h">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</None>
|
||||||
|
<Compile Include="src\ASF\sam0\drivers\tc\tc_sam_d_r_h\tc.c">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
<Compile Include="src\ASF\sam0\utils\stdio\read.c">
|
<Compile Include="src\ASF\sam0\utils\stdio\read.c">
|
||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
|
@ -949,9 +1015,6 @@
|
||||||
<None Include="src\ASF\thirdparty\freertos\freertos-10.0.0\Source\include\timers.h">
|
<None Include="src\ASF\thirdparty\freertos\freertos-10.0.0\Source\include\timers.h">
|
||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</None>
|
</None>
|
||||||
<None Include="src\ASF\thirdparty\freertos\freertos-10.0.0\Source\include\StackMacros.h">
|
|
||||||
<SubType>compile</SubType>
|
|
||||||
</None>
|
|
||||||
<None Include="src\ASF\thirdparty\freertos\freertos-10.0.0\Source\include\queue.h">
|
<None Include="src\ASF\thirdparty\freertos\freertos-10.0.0\Source\include\queue.h">
|
||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</None>
|
</None>
|
||||||
|
|
@ -1681,15 +1744,39 @@
|
||||||
<Compile Include="src\include\adc_user.h">
|
<Compile Include="src\include\adc_user.h">
|
||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="src\include\adn8831.h">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="src\include\backlight.h">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
<Compile Include="src\include\dac_user.h">
|
<Compile Include="src\include\dac_user.h">
|
||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="src\include\dht.h">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="src\include\light_ws2812_cortex.h">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="src\include\ntc.h">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
<Compile Include="src\include\realsence.h">
|
<Compile Include="src\include\realsence.h">
|
||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="src\include\tec.h">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
<Compile Include="src\include\tmpgood.h">
|
<Compile Include="src\include\tmpgood.h">
|
||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="src\include\tm_ds18b20.h">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="src\include\tm_onewire.h">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
<Compile Include="src\include\ws2812.h">
|
<Compile Include="src\include\ws2812.h">
|
||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
|
@ -1699,15 +1786,39 @@
|
||||||
<Compile Include="src\source\adc_user.c">
|
<Compile Include="src\source\adc_user.c">
|
||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="src\source\adn8831.c">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="src\source\backlight.c">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
<Compile Include="src\source\dac_user.c">
|
<Compile Include="src\source\dac_user.c">
|
||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="src\source\dht.c">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="src\source\light_ws2812_cortex.c">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="src\source\ntc.c">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
<Compile Include="src\source\realsence.c">
|
<Compile Include="src\source\realsence.c">
|
||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="src\source\tec.c">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
<Compile Include="src\source\tmpgood.c">
|
<Compile Include="src\source\tmpgood.c">
|
||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="src\source\tm_ds18b20.c">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="src\source\tm_onewire.c">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
<Compile Include="src\source\ws2812.c">
|
<Compile Include="src\source\ws2812.c">
|
||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,189 @@
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
*
|
||||||
|
* \brief SAM TC - Timer Counter Callback Driver
|
||||||
|
*
|
||||||
|
* Copyright (c) 2013-2018 Microchip Technology Inc. and its subsidiaries.
|
||||||
|
*
|
||||||
|
* \asf_license_start
|
||||||
|
*
|
||||||
|
* \page License
|
||||||
|
*
|
||||||
|
* Subject to your compliance with these terms, you may use Microchip
|
||||||
|
* software and any derivatives exclusively with Microchip products.
|
||||||
|
* It is your responsibility to comply with third party license terms applicable
|
||||||
|
* to your use of third party software (including open source software) that
|
||||||
|
* may accompany Microchip software.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
|
||||||
|
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
|
||||||
|
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
|
||||||
|
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
|
||||||
|
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
|
||||||
|
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
|
||||||
|
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
|
||||||
|
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
|
||||||
|
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
|
||||||
|
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
|
||||||
|
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
|
||||||
|
*
|
||||||
|
* \asf_license_stop
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Support and FAQ: visit <a href="https://www.microchip.com/support/">Microchip Support</a>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "tc_interrupt.h"
|
||||||
|
|
||||||
|
void *_tc_instances[TC_INST_NUM];
|
||||||
|
|
||||||
|
void _tc_interrupt_handler(uint8_t instance);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Registers a callback.
|
||||||
|
*
|
||||||
|
* Registers a callback function which is implemented by the user.
|
||||||
|
*
|
||||||
|
* \note The callback must be enabled by \ref tc_enable_callback,
|
||||||
|
* in order for the interrupt handler to call it when the conditions for the
|
||||||
|
* callback type is met.
|
||||||
|
*
|
||||||
|
* \param[in] module Pointer to TC software instance struct
|
||||||
|
* \param[in] callback_func Pointer to callback function
|
||||||
|
* \param[in] callback_type Callback type given by an enum
|
||||||
|
*/
|
||||||
|
enum status_code tc_register_callback(
|
||||||
|
struct tc_module *const module,
|
||||||
|
tc_callback_t callback_func,
|
||||||
|
const enum tc_callback callback_type)
|
||||||
|
{
|
||||||
|
/* Sanity check arguments */
|
||||||
|
Assert(module);
|
||||||
|
Assert(callback_func);
|
||||||
|
|
||||||
|
/* Register callback function */
|
||||||
|
module->callback[callback_type] = callback_func;
|
||||||
|
|
||||||
|
/* Set the bit corresponding to the callback_type */
|
||||||
|
if (callback_type == TC_CALLBACK_CC_CHANNEL0) {
|
||||||
|
module->register_callback_mask |= TC_INTFLAG_MC(1);
|
||||||
|
}
|
||||||
|
else if (callback_type == TC_CALLBACK_CC_CHANNEL1) {
|
||||||
|
module->register_callback_mask |= TC_INTFLAG_MC(2);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
module->register_callback_mask |= (1 << callback_type);
|
||||||
|
}
|
||||||
|
return STATUS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Unregisters a callback.
|
||||||
|
*
|
||||||
|
* Unregisters a callback function implemented by the user. The callback should be
|
||||||
|
* disabled before it is unregistered.
|
||||||
|
*
|
||||||
|
* \param[in] module Pointer to TC software instance struct
|
||||||
|
* \param[in] callback_type Callback type given by an enum
|
||||||
|
*/
|
||||||
|
enum status_code tc_unregister_callback(
|
||||||
|
struct tc_module *const module,
|
||||||
|
const enum tc_callback callback_type)
|
||||||
|
{
|
||||||
|
/* Sanity check arguments */
|
||||||
|
Assert(module);
|
||||||
|
|
||||||
|
/* Unregister callback function */
|
||||||
|
module->callback[callback_type] = NULL;
|
||||||
|
|
||||||
|
/* Clear the bit corresponding to the callback_type */
|
||||||
|
if (callback_type == TC_CALLBACK_CC_CHANNEL0) {
|
||||||
|
module->register_callback_mask &= ~TC_INTFLAG_MC(1);
|
||||||
|
}
|
||||||
|
else if (callback_type == TC_CALLBACK_CC_CHANNEL1) {
|
||||||
|
module->register_callback_mask &= ~TC_INTFLAG_MC(2);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
module->register_callback_mask &= ~(1 << callback_type);
|
||||||
|
}
|
||||||
|
return STATUS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \internal ISR handler for TC
|
||||||
|
*
|
||||||
|
* Auto-generate a set of interrupt handlers for each TC in the device.
|
||||||
|
*/
|
||||||
|
#define _TC_INTERRUPT_HANDLER(n, m) \
|
||||||
|
void TC##n##_Handler(void) \
|
||||||
|
{ \
|
||||||
|
_tc_interrupt_handler(m); \
|
||||||
|
}
|
||||||
|
|
||||||
|
#if (SAML21E) || (SAML21G) || (SAMR30E) || (SAMR30G)
|
||||||
|
_TC_INTERRUPT_HANDLER(0,0)
|
||||||
|
_TC_INTERRUPT_HANDLER(1,1)
|
||||||
|
_TC_INTERRUPT_HANDLER(4,2)
|
||||||
|
#else
|
||||||
|
MRECURSION(TC_INST_NUM, _TC_INTERRUPT_HANDLER, TC_INST_MAX_ID)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \internal Interrupt Handler for TC module
|
||||||
|
*
|
||||||
|
* Handles interrupts as they occur, it will run the callback functions
|
||||||
|
* that are registered and enabled.
|
||||||
|
*
|
||||||
|
* \param[in] instance ID of the TC instance calling the interrupt
|
||||||
|
* handler
|
||||||
|
*/
|
||||||
|
void _tc_interrupt_handler(
|
||||||
|
uint8_t instance)
|
||||||
|
{
|
||||||
|
/* Temporary variable */
|
||||||
|
uint8_t interrupt_and_callback_status_mask;
|
||||||
|
|
||||||
|
/* Get device instance from the look-up table */
|
||||||
|
struct tc_module *module
|
||||||
|
= (struct tc_module *)_tc_instances[instance];
|
||||||
|
|
||||||
|
/* Read and mask interrupt flag register */
|
||||||
|
interrupt_and_callback_status_mask = module->hw->COUNT8.INTFLAG.reg &
|
||||||
|
module->register_callback_mask &
|
||||||
|
module->enable_callback_mask;
|
||||||
|
|
||||||
|
/* Check if an Overflow interrupt has occurred */
|
||||||
|
if (interrupt_and_callback_status_mask & TC_INTFLAG_OVF) {
|
||||||
|
/* Invoke registered and enabled callback function */
|
||||||
|
(module->callback[TC_CALLBACK_OVERFLOW])(module);
|
||||||
|
/* Clear interrupt flag */
|
||||||
|
module->hw->COUNT8.INTFLAG.reg = TC_INTFLAG_OVF;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check if an Error interrupt has occurred */
|
||||||
|
if (interrupt_and_callback_status_mask & TC_INTFLAG_ERR) {
|
||||||
|
/* Invoke registered and enabled callback function */
|
||||||
|
(module->callback[TC_CALLBACK_ERROR])(module);
|
||||||
|
/* Clear interrupt flag */
|
||||||
|
module->hw->COUNT8.INTFLAG.reg = TC_INTFLAG_ERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check if an Match/Capture Channel 0 interrupt has occurred */
|
||||||
|
if (interrupt_and_callback_status_mask & TC_INTFLAG_MC(1)) {
|
||||||
|
/* Invoke registered and enabled callback function */
|
||||||
|
(module->callback[TC_CALLBACK_CC_CHANNEL0])(module);
|
||||||
|
/* Clear interrupt flag */
|
||||||
|
module->hw->COUNT8.INTFLAG.reg = TC_INTFLAG_MC(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check if an Match/Capture Channel 1 interrupt has occurred */
|
||||||
|
if (interrupt_and_callback_status_mask & TC_INTFLAG_MC(2)) {
|
||||||
|
/* Invoke registered and enabled callback function */
|
||||||
|
(module->callback[TC_CALLBACK_CC_CHANNEL1])(module);
|
||||||
|
/* Clear interrupt flag */
|
||||||
|
module->hw->COUNT8.INTFLAG.reg = TC_INTFLAG_MC(2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,169 @@
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
*
|
||||||
|
* \brief SAM TC - Timer Counter Callback Driver
|
||||||
|
*
|
||||||
|
* Copyright (c) 2013-2018 Microchip Technology Inc. and its subsidiaries.
|
||||||
|
*
|
||||||
|
* \asf_license_start
|
||||||
|
*
|
||||||
|
* \page License
|
||||||
|
*
|
||||||
|
* Subject to your compliance with these terms, you may use Microchip
|
||||||
|
* software and any derivatives exclusively with Microchip products.
|
||||||
|
* It is your responsibility to comply with third party license terms applicable
|
||||||
|
* to your use of third party software (including open source software) that
|
||||||
|
* may accompany Microchip software.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
|
||||||
|
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
|
||||||
|
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
|
||||||
|
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
|
||||||
|
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
|
||||||
|
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
|
||||||
|
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
|
||||||
|
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
|
||||||
|
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
|
||||||
|
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
|
||||||
|
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
|
||||||
|
*
|
||||||
|
* \asf_license_stop
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Support and FAQ: visit <a href="https://www.microchip.com/support/">Microchip Support</a>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef TC_INTERRUPT_H_INCLUDED
|
||||||
|
#define TC_INTERRUPT_H_INCLUDED
|
||||||
|
|
||||||
|
#include "tc.h"
|
||||||
|
#include <system_interrupt.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !defined(__DOXYGEN__)
|
||||||
|
extern void *_tc_instances[TC_INST_NUM];
|
||||||
|
|
||||||
|
# define _TC_INTERRUPT_VECT_NUM(n, unused) \
|
||||||
|
SYSTEM_INTERRUPT_MODULE_TC##n,
|
||||||
|
/**
|
||||||
|
* \internal Get the interrupt vector for the given device instance
|
||||||
|
*
|
||||||
|
* \param[in] TC module instance number
|
||||||
|
*
|
||||||
|
* \return Interrupt vector for of the given TC module instance.
|
||||||
|
*/
|
||||||
|
static enum system_interrupt_vector _tc_interrupt_get_interrupt_vector(
|
||||||
|
uint32_t inst_num)
|
||||||
|
{
|
||||||
|
static uint8_t tc_interrupt_vectors[TC_INST_NUM] =
|
||||||
|
{
|
||||||
|
#if (SAML21E) || (SAML21G) || (SAMR30E) || (SAMR30G)
|
||||||
|
SYSTEM_INTERRUPT_MODULE_TC0,
|
||||||
|
SYSTEM_INTERRUPT_MODULE_TC1,
|
||||||
|
SYSTEM_INTERRUPT_MODULE_TC4
|
||||||
|
#else
|
||||||
|
MRECURSION(TC_INST_NUM, _TC_INTERRUPT_VECT_NUM, TC_INST_MAX_ID)
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
return (enum system_interrupt_vector)tc_interrupt_vectors[inst_num];
|
||||||
|
}
|
||||||
|
#endif /* !defined(__DOXYGEN__) */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \name Callback Management
|
||||||
|
* {@
|
||||||
|
*/
|
||||||
|
|
||||||
|
enum status_code tc_register_callback(
|
||||||
|
struct tc_module *const module,
|
||||||
|
tc_callback_t callback_func,
|
||||||
|
const enum tc_callback callback_type);
|
||||||
|
|
||||||
|
enum status_code tc_unregister_callback(
|
||||||
|
struct tc_module *const module,
|
||||||
|
const enum tc_callback callback_type);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Enables callback.
|
||||||
|
*
|
||||||
|
* Enables the callback function registered by the \ref
|
||||||
|
* tc_register_callback. The callback function will be called from the
|
||||||
|
* interrupt handler when the conditions for the callback type are
|
||||||
|
* met. This function will also enable the appropriate interrupts.
|
||||||
|
*
|
||||||
|
* \param[in] module Pointer to TC software instance struct
|
||||||
|
* \param[in] callback_type Callback type given by an enum
|
||||||
|
*/
|
||||||
|
static inline void tc_enable_callback(
|
||||||
|
struct tc_module *const module,
|
||||||
|
const enum tc_callback callback_type)
|
||||||
|
{
|
||||||
|
/* Sanity check arguments */
|
||||||
|
Assert(module);
|
||||||
|
|
||||||
|
|
||||||
|
/* Enable interrupts for this TC module */
|
||||||
|
system_interrupt_enable(_tc_interrupt_get_interrupt_vector(_tc_get_inst_index(module->hw)));
|
||||||
|
|
||||||
|
/* Enable callback */
|
||||||
|
if (callback_type == TC_CALLBACK_CC_CHANNEL0) {
|
||||||
|
module->enable_callback_mask |= TC_INTFLAG_MC(1);
|
||||||
|
module->hw->COUNT8.INTENSET.reg = TC_INTFLAG_MC(1);
|
||||||
|
}
|
||||||
|
else if (callback_type == TC_CALLBACK_CC_CHANNEL1) {
|
||||||
|
module->enable_callback_mask |= TC_INTFLAG_MC(2);
|
||||||
|
module->hw->COUNT8.INTENSET.reg = TC_INTFLAG_MC(2);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
module->enable_callback_mask |= (1 << callback_type);
|
||||||
|
module->hw->COUNT8.INTENSET.reg = (1 << callback_type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Disables callback.
|
||||||
|
*
|
||||||
|
* Disables the callback function registered by the \ref
|
||||||
|
* tc_register_callback, and the callback will not be called from the
|
||||||
|
* interrupt routine. The function will also disable the appropriate
|
||||||
|
* interrupts.
|
||||||
|
*
|
||||||
|
* \param[in] module Pointer to TC software instance struct
|
||||||
|
* \param[in] callback_type Callback type given by an enum
|
||||||
|
*/
|
||||||
|
static inline void tc_disable_callback(
|
||||||
|
struct tc_module *const module,
|
||||||
|
const enum tc_callback callback_type){
|
||||||
|
/* Sanity check arguments */
|
||||||
|
Assert(module);
|
||||||
|
|
||||||
|
/* Disable callback */
|
||||||
|
if (callback_type == TC_CALLBACK_CC_CHANNEL0) {
|
||||||
|
module->hw->COUNT8.INTENCLR.reg = TC_INTFLAG_MC(1);
|
||||||
|
module->enable_callback_mask &= ~TC_INTFLAG_MC(1);
|
||||||
|
}
|
||||||
|
else if (callback_type == TC_CALLBACK_CC_CHANNEL1) {
|
||||||
|
module->hw->COUNT8.INTENCLR.reg = TC_INTFLAG_MC(2);
|
||||||
|
module->enable_callback_mask &= ~TC_INTFLAG_MC(2);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
module->hw->COUNT8.INTENCLR.reg = (1 << callback_type);
|
||||||
|
module->enable_callback_mask &= ~(1 << callback_type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* TC_INTERRUPT_H_INCLUDED */
|
||||||
|
|
@ -0,0 +1,675 @@
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
*
|
||||||
|
* \brief SAM TC - Timer Counter Driver
|
||||||
|
*
|
||||||
|
* Copyright (c) 2013-2018 Microchip Technology Inc. and its subsidiaries.
|
||||||
|
*
|
||||||
|
* \asf_license_start
|
||||||
|
*
|
||||||
|
* \page License
|
||||||
|
*
|
||||||
|
* Subject to your compliance with these terms, you may use Microchip
|
||||||
|
* software and any derivatives exclusively with Microchip products.
|
||||||
|
* It is your responsibility to comply with third party license terms applicable
|
||||||
|
* to your use of third party software (including open source software) that
|
||||||
|
* may accompany Microchip software.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
|
||||||
|
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
|
||||||
|
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
|
||||||
|
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
|
||||||
|
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
|
||||||
|
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
|
||||||
|
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
|
||||||
|
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
|
||||||
|
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
|
||||||
|
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
|
||||||
|
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
|
||||||
|
*
|
||||||
|
* \asf_license_stop
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* Support and FAQ: visit <a href="https://www.microchip.com/support/">Microchip Support</a>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "tc.h"
|
||||||
|
|
||||||
|
#if TC_ASYNC == true
|
||||||
|
# include "tc_interrupt.h"
|
||||||
|
# include <system_interrupt.h>
|
||||||
|
|
||||||
|
/** \internal
|
||||||
|
* Converts a given TC index to its interrupt vector index.
|
||||||
|
*/
|
||||||
|
# define _TC_INTERRUPT_VECT_NUM(n, unused) \
|
||||||
|
SYSTEM_INTERRUPT_MODULE_TC##n,
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !defined(__DOXYGEN__)
|
||||||
|
# define _TC_GCLK_ID(n,unused) TPASTE3(TC,n,_GCLK_ID) ,
|
||||||
|
# define _TC_PM_APBCMASK(n,unused) TPASTE2(PM_APBCMASK_TC,n) ,
|
||||||
|
|
||||||
|
# define TC_INST_GCLK_ID { MRECURSION(TC_INST_NUM, _TC_GCLK_ID, TC_INST_MAX_ID) }
|
||||||
|
# define TC_INST_PM_APBCMASK { MRECURSION(TC_INST_NUM, _TC_PM_APBCMASK, TC_INST_MAX_ID) }
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \internal Find the index of given TC module instance.
|
||||||
|
*
|
||||||
|
* \param[in] TC module instance pointer
|
||||||
|
*
|
||||||
|
* \return Index of the given TC module instance.
|
||||||
|
*/
|
||||||
|
uint8_t _tc_get_inst_index(
|
||||||
|
Tc *const hw)
|
||||||
|
{
|
||||||
|
/* List of available TC modules. */
|
||||||
|
Tc *const tc_modules[TC_INST_NUM] = TC_INSTS;
|
||||||
|
|
||||||
|
/* Find index for TC instance. */
|
||||||
|
for (uint32_t i = 0; i < TC_INST_NUM; i++) {
|
||||||
|
if (hw == tc_modules[i]) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Invalid data given. */
|
||||||
|
Assert(false);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Initializes a hardware TC module instance.
|
||||||
|
*
|
||||||
|
* Enables the clock and initializes the TC module, based on the given
|
||||||
|
* configuration values.
|
||||||
|
*
|
||||||
|
* \param[in,out] module_inst Pointer to the software module instance struct
|
||||||
|
* \param[in] hw Pointer to the TC hardware module
|
||||||
|
* \param[in] config Pointer to the TC configuration options struct
|
||||||
|
*
|
||||||
|
* \return Status of the initialization procedure.
|
||||||
|
*
|
||||||
|
* \retval STATUS_OK The module was initialized successfully
|
||||||
|
* \retval STATUS_BUSY Hardware module was busy when the
|
||||||
|
* initialization procedure was attempted
|
||||||
|
* \retval STATUS_INVALID_ARG An invalid configuration option or argument
|
||||||
|
* was supplied
|
||||||
|
* \retval STATUS_ERR_DENIED Hardware module was already enabled, or the
|
||||||
|
* hardware module is configured in 32-bit
|
||||||
|
* slave mode
|
||||||
|
*/
|
||||||
|
enum status_code tc_init(
|
||||||
|
struct tc_module *const module_inst,
|
||||||
|
Tc *const hw,
|
||||||
|
const struct tc_config *const config)
|
||||||
|
{
|
||||||
|
/* Sanity check arguments */
|
||||||
|
Assert(hw);
|
||||||
|
Assert(module_inst);
|
||||||
|
Assert(config);
|
||||||
|
|
||||||
|
/* Temporary variable to hold all updates to the CTRLA
|
||||||
|
* register before they are written to it */
|
||||||
|
uint16_t ctrla_tmp = 0;
|
||||||
|
/* Temporary variable to hold all updates to the CTRLBSET
|
||||||
|
* register before they are written to it */
|
||||||
|
uint8_t ctrlbset_tmp = 0;
|
||||||
|
/* Temporary variable to hold all updates to the CTRLC
|
||||||
|
* register before they are written to it */
|
||||||
|
uint8_t ctrlc_tmp = 0;
|
||||||
|
/* Temporary variable to hold TC instance number */
|
||||||
|
uint8_t instance = _tc_get_inst_index(hw);
|
||||||
|
|
||||||
|
/* Array of GLCK ID for different TC instances */
|
||||||
|
uint8_t inst_gclk_id[] = TC_INST_GCLK_ID;
|
||||||
|
/* Array of PM APBC mask bit position for different TC instances */
|
||||||
|
uint16_t inst_pm_apbmask[] = TC_INST_PM_APBCMASK;
|
||||||
|
|
||||||
|
struct system_pinmux_config pin_config;
|
||||||
|
struct system_gclk_chan_config gclk_chan_config;
|
||||||
|
|
||||||
|
#if TC_ASYNC == true
|
||||||
|
/* Initialize parameters */
|
||||||
|
for (uint8_t i = 0; i < TC_CALLBACK_N; i++) {
|
||||||
|
module_inst->callback[i] = NULL;
|
||||||
|
}
|
||||||
|
module_inst->register_callback_mask = 0x00;
|
||||||
|
module_inst->enable_callback_mask = 0x00;
|
||||||
|
|
||||||
|
/* Register this instance for callbacks*/
|
||||||
|
_tc_instances[instance] = module_inst;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Associate the given device instance with the hardware module */
|
||||||
|
module_inst->hw = hw;
|
||||||
|
|
||||||
|
#if SAMD09 || SAMD10 || SAMD11 || SAMHA1 || SAMHA0
|
||||||
|
/* Check if even numbered TC modules are being configured in 32-bit
|
||||||
|
* counter size. Only odd numbered counters are allowed to be
|
||||||
|
* configured in 32-bit counter size.
|
||||||
|
*/
|
||||||
|
if ((config->counter_size == TC_COUNTER_SIZE_32BIT) &&
|
||||||
|
!((instance + TC_INSTANCE_OFFSET) & 0x01)) {
|
||||||
|
Assert(false);
|
||||||
|
return STATUS_ERR_INVALID_ARG;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
/* Check if odd numbered TC modules are being configured in 32-bit
|
||||||
|
* counter size. Only even numbered counters are allowed to be
|
||||||
|
* configured in 32-bit counter size.
|
||||||
|
*/
|
||||||
|
if ((config->counter_size == TC_COUNTER_SIZE_32BIT) &&
|
||||||
|
((instance + TC_INSTANCE_OFFSET) & 0x01)) {
|
||||||
|
Assert(false);
|
||||||
|
return STATUS_ERR_INVALID_ARG;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Make the counter size variable in the module_inst struct reflect
|
||||||
|
* the counter size in the module
|
||||||
|
*/
|
||||||
|
module_inst->counter_size = config->counter_size;
|
||||||
|
|
||||||
|
if (hw->COUNT8.CTRLA.reg & TC_CTRLA_SWRST) {
|
||||||
|
/* We are in the middle of a reset. Abort. */
|
||||||
|
return STATUS_BUSY;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hw->COUNT8.STATUS.reg & TC_STATUS_SLAVE) {
|
||||||
|
/* Module is used as a slave */
|
||||||
|
return STATUS_ERR_DENIED;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hw->COUNT8.CTRLA.reg & TC_CTRLA_ENABLE) {
|
||||||
|
/* Module must be disabled before initialization. Abort. */
|
||||||
|
return STATUS_ERR_DENIED;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set up the TC PWM out pin for channel 0 */
|
||||||
|
if (config->pwm_channel[0].enabled) {
|
||||||
|
system_pinmux_get_config_defaults(&pin_config);
|
||||||
|
pin_config.mux_position = config->pwm_channel[0].pin_mux;
|
||||||
|
pin_config.direction = SYSTEM_PINMUX_PIN_DIR_OUTPUT;
|
||||||
|
system_pinmux_pin_set_config(
|
||||||
|
config->pwm_channel[0].pin_out, &pin_config);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set up the TC PWM out pin for channel 1 */
|
||||||
|
if (config->pwm_channel[1].enabled) {
|
||||||
|
system_pinmux_get_config_defaults(&pin_config);
|
||||||
|
pin_config.mux_position = config->pwm_channel[1].pin_mux;
|
||||||
|
pin_config.direction = SYSTEM_PINMUX_PIN_DIR_OUTPUT;
|
||||||
|
system_pinmux_pin_set_config(
|
||||||
|
config->pwm_channel[1].pin_out, &pin_config);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Enable the user interface clock in the PM */
|
||||||
|
system_apb_clock_set_mask(SYSTEM_CLOCK_APB_APBC,
|
||||||
|
inst_pm_apbmask[instance]);
|
||||||
|
|
||||||
|
/* Enable the slave counter if counter_size is 32-bit */
|
||||||
|
if ((config->counter_size == TC_COUNTER_SIZE_32BIT))
|
||||||
|
{
|
||||||
|
/* Enable the user interface clock in the PM */
|
||||||
|
system_apb_clock_set_mask(SYSTEM_CLOCK_APB_APBC,
|
||||||
|
inst_pm_apbmask[instance + 1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Setup clock for module */
|
||||||
|
system_gclk_chan_get_config_defaults(&gclk_chan_config);
|
||||||
|
gclk_chan_config.source_generator = config->clock_source;
|
||||||
|
system_gclk_chan_set_config(inst_gclk_id[instance], &gclk_chan_config);
|
||||||
|
system_gclk_chan_enable(inst_gclk_id[instance]);
|
||||||
|
|
||||||
|
/* Set ctrla register */
|
||||||
|
ctrla_tmp =
|
||||||
|
(uint32_t)config->counter_size |
|
||||||
|
(uint32_t)config->wave_generation |
|
||||||
|
(uint32_t)config->reload_action |
|
||||||
|
(uint32_t)config->clock_prescaler;
|
||||||
|
|
||||||
|
if (config->run_in_standby) {
|
||||||
|
ctrla_tmp |= TC_CTRLA_RUNSTDBY;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Write configuration to register */
|
||||||
|
while (tc_is_syncing(module_inst)) {
|
||||||
|
/* Wait for sync */
|
||||||
|
}
|
||||||
|
hw->COUNT8.CTRLA.reg = ctrla_tmp;
|
||||||
|
|
||||||
|
/* Set ctrlb register */
|
||||||
|
if (config->oneshot) {
|
||||||
|
ctrlbset_tmp = TC_CTRLBSET_ONESHOT;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config->count_direction) {
|
||||||
|
ctrlbset_tmp |= TC_CTRLBSET_DIR;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Clear old ctrlb configuration */
|
||||||
|
while (tc_is_syncing(module_inst)) {
|
||||||
|
/* Wait for sync */
|
||||||
|
}
|
||||||
|
hw->COUNT8.CTRLBCLR.reg = 0xFF;
|
||||||
|
|
||||||
|
/* Check if we actually need to go into a wait state. */
|
||||||
|
if (ctrlbset_tmp) {
|
||||||
|
while (tc_is_syncing(module_inst)) {
|
||||||
|
/* Wait for sync */
|
||||||
|
}
|
||||||
|
/* Write configuration to register */
|
||||||
|
hw->COUNT8.CTRLBSET.reg = ctrlbset_tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set ctrlc register*/
|
||||||
|
ctrlc_tmp = config->waveform_invert_output;
|
||||||
|
for (uint8_t i = 0; i < NUMBER_OF_COMPARE_CAPTURE_CHANNELS; i++) {
|
||||||
|
if (config->enable_capture_on_channel[i] == true) {
|
||||||
|
ctrlc_tmp |= (TC_CTRLC_CPTEN(1) << i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Write configuration to register */
|
||||||
|
while (tc_is_syncing(module_inst)) {
|
||||||
|
/* Wait for sync */
|
||||||
|
}
|
||||||
|
hw->COUNT8.CTRLC.reg = ctrlc_tmp;
|
||||||
|
|
||||||
|
/* Write configuration to register */
|
||||||
|
while (tc_is_syncing(module_inst)) {
|
||||||
|
/* Wait for sync */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Switch for TC counter size */
|
||||||
|
switch (module_inst->counter_size) {
|
||||||
|
case TC_COUNTER_SIZE_8BIT:
|
||||||
|
while (tc_is_syncing(module_inst)) {
|
||||||
|
/* Wait for sync */
|
||||||
|
}
|
||||||
|
|
||||||
|
hw->COUNT8.COUNT.reg =
|
||||||
|
config->counter_8_bit.value;
|
||||||
|
|
||||||
|
|
||||||
|
while (tc_is_syncing(module_inst)) {
|
||||||
|
/* Wait for sync */
|
||||||
|
}
|
||||||
|
|
||||||
|
hw->COUNT8.PER.reg =
|
||||||
|
config->counter_8_bit.period;
|
||||||
|
|
||||||
|
while (tc_is_syncing(module_inst)) {
|
||||||
|
/* Wait for sync */
|
||||||
|
}
|
||||||
|
|
||||||
|
hw->COUNT8.CC[0].reg =
|
||||||
|
config->counter_8_bit.compare_capture_channel[0];
|
||||||
|
|
||||||
|
while (tc_is_syncing(module_inst)) {
|
||||||
|
/* Wait for sync */
|
||||||
|
}
|
||||||
|
|
||||||
|
hw->COUNT8.CC[1].reg =
|
||||||
|
config->counter_8_bit.compare_capture_channel[1];
|
||||||
|
|
||||||
|
return STATUS_OK;
|
||||||
|
|
||||||
|
case TC_COUNTER_SIZE_16BIT:
|
||||||
|
while (tc_is_syncing(module_inst)) {
|
||||||
|
/* Wait for sync */
|
||||||
|
}
|
||||||
|
|
||||||
|
hw->COUNT16.COUNT.reg
|
||||||
|
= config->counter_16_bit.value;
|
||||||
|
|
||||||
|
while (tc_is_syncing(module_inst)) {
|
||||||
|
/* Wait for sync */
|
||||||
|
}
|
||||||
|
|
||||||
|
hw->COUNT16.CC[0].reg =
|
||||||
|
config->counter_16_bit.compare_capture_channel[0];
|
||||||
|
|
||||||
|
while (tc_is_syncing(module_inst)) {
|
||||||
|
/* Wait for sync */
|
||||||
|
}
|
||||||
|
|
||||||
|
hw->COUNT16.CC[1].reg =
|
||||||
|
config->counter_16_bit.compare_capture_channel[1];
|
||||||
|
|
||||||
|
return STATUS_OK;
|
||||||
|
|
||||||
|
case TC_COUNTER_SIZE_32BIT:
|
||||||
|
while (tc_is_syncing(module_inst)) {
|
||||||
|
/* Wait for sync */
|
||||||
|
}
|
||||||
|
|
||||||
|
hw->COUNT32.COUNT.reg
|
||||||
|
= config->counter_32_bit.value;
|
||||||
|
|
||||||
|
while (tc_is_syncing(module_inst)) {
|
||||||
|
/* Wait for sync */
|
||||||
|
}
|
||||||
|
|
||||||
|
hw->COUNT32.CC[0].reg =
|
||||||
|
config->counter_32_bit.compare_capture_channel[0];
|
||||||
|
|
||||||
|
while (tc_is_syncing(module_inst)) {
|
||||||
|
/* Wait for sync */
|
||||||
|
}
|
||||||
|
|
||||||
|
hw->COUNT32.CC[1].reg =
|
||||||
|
config->counter_32_bit.compare_capture_channel[1];
|
||||||
|
|
||||||
|
return STATUS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
Assert(false);
|
||||||
|
return STATUS_ERR_INVALID_ARG;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Sets TC module count value.
|
||||||
|
*
|
||||||
|
* Sets the current timer count value of a initialized TC module. The
|
||||||
|
* specified TC module may be started or stopped.
|
||||||
|
*
|
||||||
|
* \param[in] module_inst Pointer to the software module instance struct
|
||||||
|
* \param[in] count New timer count value to set
|
||||||
|
*
|
||||||
|
* \return Status of the count update procedure.
|
||||||
|
*
|
||||||
|
* \retval STATUS_OK The timer count was updated successfully
|
||||||
|
* \retval STATUS_ERR_INVALID_ARG An invalid timer counter size was specified
|
||||||
|
*/
|
||||||
|
enum status_code tc_set_count_value(
|
||||||
|
const struct tc_module *const module_inst,
|
||||||
|
const uint32_t count)
|
||||||
|
{
|
||||||
|
/* Sanity check arguments */
|
||||||
|
Assert(module_inst);
|
||||||
|
Assert(module_inst->hw);
|
||||||
|
|
||||||
|
/* Get a pointer to the module's hardware instance*/
|
||||||
|
Tc *const tc_module = module_inst->hw;
|
||||||
|
|
||||||
|
while (tc_is_syncing(module_inst)) {
|
||||||
|
/* Wait for sync */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Write to based on the TC counter_size */
|
||||||
|
switch (module_inst->counter_size) {
|
||||||
|
case TC_COUNTER_SIZE_8BIT:
|
||||||
|
tc_module->COUNT8.COUNT.reg = (uint8_t)count;
|
||||||
|
return STATUS_OK;
|
||||||
|
|
||||||
|
case TC_COUNTER_SIZE_16BIT:
|
||||||
|
tc_module->COUNT16.COUNT.reg = (uint16_t)count;
|
||||||
|
return STATUS_OK;
|
||||||
|
|
||||||
|
case TC_COUNTER_SIZE_32BIT:
|
||||||
|
tc_module->COUNT32.COUNT.reg = (uint32_t)count;
|
||||||
|
return STATUS_OK;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return STATUS_ERR_INVALID_ARG;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Get TC module count value.
|
||||||
|
*
|
||||||
|
* Retrieves the current count value of a TC module. The specified TC module
|
||||||
|
* may be started or stopped.
|
||||||
|
*
|
||||||
|
* \param[in] module_inst Pointer to the software module instance struct
|
||||||
|
*
|
||||||
|
* \return Count value of the specified TC module.
|
||||||
|
*/
|
||||||
|
uint32_t tc_get_count_value(
|
||||||
|
const struct tc_module *const module_inst)
|
||||||
|
{
|
||||||
|
/* Sanity check arguments */
|
||||||
|
Assert(module_inst);
|
||||||
|
Assert(module_inst->hw);
|
||||||
|
|
||||||
|
/* Get a pointer to the module's hardware instance */
|
||||||
|
Tc *const tc_module = module_inst->hw;
|
||||||
|
|
||||||
|
while (tc_is_syncing(module_inst)) {
|
||||||
|
/* Wait for sync */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Read from based on the TC counter size */
|
||||||
|
switch (module_inst->counter_size) {
|
||||||
|
case TC_COUNTER_SIZE_8BIT:
|
||||||
|
return (uint32_t)tc_module->COUNT8.COUNT.reg;
|
||||||
|
|
||||||
|
case TC_COUNTER_SIZE_16BIT:
|
||||||
|
return (uint32_t)tc_module->COUNT16.COUNT.reg;
|
||||||
|
|
||||||
|
case TC_COUNTER_SIZE_32BIT:
|
||||||
|
return tc_module->COUNT32.COUNT.reg;
|
||||||
|
}
|
||||||
|
|
||||||
|
Assert(false);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Gets the TC module capture value.
|
||||||
|
*
|
||||||
|
* Retrieves the capture value in the indicated TC module capture channel.
|
||||||
|
*
|
||||||
|
* \param[in] module_inst Pointer to the software module instance struct
|
||||||
|
* \param[in] channel_index Index of the Compare Capture channel to read
|
||||||
|
*
|
||||||
|
* \return Capture value stored in the specified timer channel.
|
||||||
|
*/
|
||||||
|
uint32_t tc_get_capture_value(
|
||||||
|
const struct tc_module *const module_inst,
|
||||||
|
const enum tc_compare_capture_channel channel_index)
|
||||||
|
{
|
||||||
|
/* Sanity check arguments */
|
||||||
|
Assert(module_inst);
|
||||||
|
Assert(module_inst->hw);
|
||||||
|
|
||||||
|
/* Get a pointer to the module's hardware instance */
|
||||||
|
Tc *const tc_module = module_inst->hw;
|
||||||
|
|
||||||
|
while (tc_is_syncing(module_inst)) {
|
||||||
|
/* Wait for sync */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Read out based on the TC counter size */
|
||||||
|
switch (module_inst->counter_size) {
|
||||||
|
case TC_COUNTER_SIZE_8BIT:
|
||||||
|
if (channel_index <
|
||||||
|
NUMBER_OF_COMPARE_CAPTURE_CHANNELS) {
|
||||||
|
return tc_module->COUNT8.CC[channel_index].reg;
|
||||||
|
}
|
||||||
|
|
||||||
|
case TC_COUNTER_SIZE_16BIT:
|
||||||
|
if (channel_index <
|
||||||
|
NUMBER_OF_COMPARE_CAPTURE_CHANNELS) {
|
||||||
|
return tc_module->COUNT16.CC[channel_index].reg;
|
||||||
|
}
|
||||||
|
|
||||||
|
case TC_COUNTER_SIZE_32BIT:
|
||||||
|
if (channel_index <
|
||||||
|
NUMBER_OF_COMPARE_CAPTURE_CHANNELS) {
|
||||||
|
return tc_module->COUNT32.CC[channel_index].reg;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Assert(false);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Sets a TC module compare value.
|
||||||
|
*
|
||||||
|
* Writes a compare value to the given TC module compare/capture channel.
|
||||||
|
*
|
||||||
|
* \param[in] module_inst Pointer to the software module instance struct
|
||||||
|
* \param[in] channel_index Index of the compare channel to write to
|
||||||
|
* \param[in] compare New compare value to set
|
||||||
|
*
|
||||||
|
* \return Status of the compare update procedure.
|
||||||
|
*
|
||||||
|
* \retval STATUS_OK The compare value was updated successfully
|
||||||
|
* \retval STATUS_ERR_INVALID_ARG An invalid channel index was supplied
|
||||||
|
*/
|
||||||
|
enum status_code tc_set_compare_value(
|
||||||
|
const struct tc_module *const module_inst,
|
||||||
|
const enum tc_compare_capture_channel channel_index,
|
||||||
|
const uint32_t compare)
|
||||||
|
{
|
||||||
|
/* Sanity check arguments */
|
||||||
|
Assert(module_inst);
|
||||||
|
Assert(module_inst->hw);
|
||||||
|
|
||||||
|
/* Get a pointer to the module's hardware instance */
|
||||||
|
Tc *const tc_module = module_inst->hw;
|
||||||
|
|
||||||
|
while (tc_is_syncing(module_inst)) {
|
||||||
|
/* Wait for sync */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Read out based on the TC counter size */
|
||||||
|
switch (module_inst->counter_size) {
|
||||||
|
case TC_COUNTER_SIZE_8BIT:
|
||||||
|
if (channel_index <
|
||||||
|
NUMBER_OF_COMPARE_CAPTURE_CHANNELS) {
|
||||||
|
tc_module->COUNT8.CC[channel_index].reg =
|
||||||
|
(uint8_t)compare;
|
||||||
|
return STATUS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
case TC_COUNTER_SIZE_16BIT:
|
||||||
|
if (channel_index <
|
||||||
|
NUMBER_OF_COMPARE_CAPTURE_CHANNELS) {
|
||||||
|
tc_module->COUNT16.CC[channel_index].reg =
|
||||||
|
(uint16_t)compare;
|
||||||
|
return STATUS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
case TC_COUNTER_SIZE_32BIT:
|
||||||
|
if (channel_index <
|
||||||
|
NUMBER_OF_COMPARE_CAPTURE_CHANNELS) {
|
||||||
|
tc_module->COUNT32.CC[channel_index].reg =
|
||||||
|
(uint32_t)compare;
|
||||||
|
return STATUS_OK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return STATUS_ERR_INVALID_ARG;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Resets the TC module.
|
||||||
|
*
|
||||||
|
* Resets the TC module, restoring all hardware module registers to their
|
||||||
|
* default values and disabling the module. The TC module will not be
|
||||||
|
* accessible while the reset is being performed.
|
||||||
|
*
|
||||||
|
* \note When resetting a 32-bit counter only the master TC module's instance
|
||||||
|
* structure should be passed to the function.
|
||||||
|
*
|
||||||
|
* \param[in] module_inst Pointer to the software module instance struct
|
||||||
|
*
|
||||||
|
* \return Status of the procedure.
|
||||||
|
* \retval STATUS_OK The module was reset successfully
|
||||||
|
* \retval STATUS_ERR_UNSUPPORTED_DEV A 32-bit slave TC module was passed to
|
||||||
|
* the function. Only use reset on master
|
||||||
|
* TC
|
||||||
|
*/
|
||||||
|
enum status_code tc_reset(
|
||||||
|
const struct tc_module *const module_inst)
|
||||||
|
{
|
||||||
|
/* Sanity check arguments */
|
||||||
|
Assert(module_inst);
|
||||||
|
Assert(module_inst->hw);
|
||||||
|
|
||||||
|
/* Get a pointer to the module hardware instance */
|
||||||
|
TcCount8 *const tc_module = &(module_inst->hw->COUNT8);
|
||||||
|
|
||||||
|
if (tc_module->STATUS.reg & TC_STATUS_SLAVE) {
|
||||||
|
return STATUS_ERR_UNSUPPORTED_DEV;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Disable this module if it is running */
|
||||||
|
if (tc_module->CTRLA.reg & TC_CTRLA_ENABLE) {
|
||||||
|
tc_disable(module_inst);
|
||||||
|
while (tc_is_syncing(module_inst)) {
|
||||||
|
/* wait while module is disabling */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Reset this TC module */
|
||||||
|
tc_module->CTRLA.reg |= TC_CTRLA_SWRST;
|
||||||
|
|
||||||
|
return STATUS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Set the timer TOP/period value.
|
||||||
|
*
|
||||||
|
* For 8-bit counter size this function writes the top value to the period
|
||||||
|
* register.
|
||||||
|
*
|
||||||
|
* For 16- and 32-bit counter size this function writes the top value to
|
||||||
|
* Capture Compare register 0. The value in this register can not be used for
|
||||||
|
* any other purpose.
|
||||||
|
*
|
||||||
|
* \note This function is designed to be used in PWM or frequency
|
||||||
|
* match modes only, when the counter is set to 16- or 32-bit counter
|
||||||
|
* size. In 8-bit counter size it will always be possible to change the
|
||||||
|
* top value even in normal mode.
|
||||||
|
*
|
||||||
|
* \param[in] module_inst Pointer to the software module instance struct
|
||||||
|
* \param[in] top_value New timer TOP value to set
|
||||||
|
*
|
||||||
|
* \return Status of the TOP set procedure.
|
||||||
|
*
|
||||||
|
* \retval STATUS_OK The timer TOP value was updated successfully
|
||||||
|
* \retval STATUS_ERR_INVALID_ARG The configured TC module counter size in the
|
||||||
|
* module instance is invalid
|
||||||
|
*/
|
||||||
|
enum status_code tc_set_top_value (
|
||||||
|
const struct tc_module *const module_inst,
|
||||||
|
const uint32_t top_value)
|
||||||
|
{
|
||||||
|
Assert(module_inst);
|
||||||
|
Assert(module_inst->hw);
|
||||||
|
Assert(top_value);
|
||||||
|
|
||||||
|
Tc *const tc_module = module_inst->hw;
|
||||||
|
|
||||||
|
while (tc_is_syncing(module_inst)) {
|
||||||
|
/* Wait for sync */
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (module_inst->counter_size) {
|
||||||
|
case TC_COUNTER_SIZE_8BIT:
|
||||||
|
tc_module->COUNT8.PER.reg = (uint8_t)top_value;
|
||||||
|
return STATUS_OK;
|
||||||
|
|
||||||
|
case TC_COUNTER_SIZE_16BIT:
|
||||||
|
tc_module->COUNT16.CC[0].reg = (uint16_t)top_value;
|
||||||
|
return STATUS_OK;
|
||||||
|
|
||||||
|
case TC_COUNTER_SIZE_32BIT:
|
||||||
|
tc_module->COUNT32.CC[0].reg = (uint32_t)top_value;
|
||||||
|
return STATUS_OK;
|
||||||
|
|
||||||
|
default:
|
||||||
|
Assert(false);
|
||||||
|
return STATUS_ERR_INVALID_ARG;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,139 @@
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
*
|
||||||
|
* \brief SAM TCC Driver Quick Start
|
||||||
|
*
|
||||||
|
* Copyright (c) 2013-2018 Microchip Technology Inc. and its subsidiaries.
|
||||||
|
*
|
||||||
|
* \asf_license_start
|
||||||
|
*
|
||||||
|
* \page License
|
||||||
|
*
|
||||||
|
* Subject to your compliance with these terms, you may use Microchip
|
||||||
|
* software and any derivatives exclusively with Microchip products.
|
||||||
|
* It is your responsibility to comply with third party license terms applicable
|
||||||
|
* to your use of third party software (including open source software) that
|
||||||
|
* may accompany Microchip software.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
|
||||||
|
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
|
||||||
|
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
|
||||||
|
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
|
||||||
|
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
|
||||||
|
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
|
||||||
|
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
|
||||||
|
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
|
||||||
|
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
|
||||||
|
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
|
||||||
|
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
|
||||||
|
*
|
||||||
|
* \asf_license_stop
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* Support and FAQ: visit <a href="https://www.microchip.com/support/">Microchip Support</a>
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \page asfdoc_sam0_tcc_basic_use_case Quick Start Guide for TCC - Basic
|
||||||
|
*
|
||||||
|
* The supported board list:
|
||||||
|
* - SAM D21/R21/L21/L22/DA1/C21/HA1G16A Xplained Pro
|
||||||
|
*
|
||||||
|
* In this use case, the TCC will be used to generate a PWM signal. Here
|
||||||
|
* the pulse width is set to one quarter of the period.
|
||||||
|
* When the PWM signal connects to LED, LED will light. To see the waveform,
|
||||||
|
* you may need an oscilloscope.
|
||||||
|
* SAMHA1G16A Xpro LED is PA00 which isn't connected out, use PA04 instead,
|
||||||
|
* so we can't see LED blink but only see the waveform from oscilloscope.
|
||||||
|
*
|
||||||
|
* The PWM output is set up as follows:
|
||||||
|
* <table>
|
||||||
|
* <tr><th> Board </td><th> Pin </td><th> Connect to </td></tr>
|
||||||
|
* <tr><td> SAM D21 Xpro </td><td> PB30 </td><td> LED0 </td></tr>
|
||||||
|
* <tr><td> SAM R21 Xpro </td><td> PA19 </td><td> LED0 </td></tr>
|
||||||
|
* <tr><td> SAM L21 Xpro </td><td> PB10 </td><td> LED0 </td></tr>
|
||||||
|
* <tr><td> SAM L22 Xpro </td><td> PC27 </td><td> LED0 </td></tr>
|
||||||
|
* <tr><td> SAM DA1 Xpro </td><td> PB30 </td><td> LED0 </td></tr>
|
||||||
|
* <tr><td> SAM C21 Xpro </td><td> PA15 </td><td> LED0 </td></tr>
|
||||||
|
* <tr><td> SAM HA1G16A Xpro </td><td> PA04 </td><td> NULL </td></tr>
|
||||||
|
* </table>
|
||||||
|
*
|
||||||
|
* The TCC module will be set up as follows:
|
||||||
|
* - GCLK generator 0 (GCLK main) clock source
|
||||||
|
* - Use double buffering write when set top, compare, or pattern through API
|
||||||
|
* - No dithering on the counter or compare
|
||||||
|
* - Prescaler is set to 256
|
||||||
|
* - Single Slope PWM wave generation
|
||||||
|
* - GCLK reload action
|
||||||
|
* - Don't run in standby
|
||||||
|
* - No fault or waveform extensions
|
||||||
|
* - No inversion of waveform output
|
||||||
|
* - No capture enabled
|
||||||
|
* - Count upward
|
||||||
|
* - Don't perform one-shot operations
|
||||||
|
* - No event input enabled
|
||||||
|
* - No event action
|
||||||
|
* - No event generation enabled
|
||||||
|
* - Counter starts on 0
|
||||||
|
* - Counter top set to 0xFFFF
|
||||||
|
* - Capture compare channel 0 set to 0xFFFF/4
|
||||||
|
*
|
||||||
|
* \section asfdoc_sam0_tcc_basic_use_case_setup Quick Start
|
||||||
|
*
|
||||||
|
* \subsection asfdoc_sam0_tcc_basic_use_case_prereq Prerequisites
|
||||||
|
* There are no prerequisites for this use case.
|
||||||
|
*
|
||||||
|
* \subsection asfdoc_sam0_tcc_basic_use_case_setup_code Code
|
||||||
|
*
|
||||||
|
* Add to the main application source file, before any functions:
|
||||||
|
* \snippet conf_quick_start.h definition_pwm
|
||||||
|
*
|
||||||
|
* Add to the main application source file, outside of any functions:
|
||||||
|
* \snippet qs_tcc_basic.c module_inst
|
||||||
|
*
|
||||||
|
* Copy-paste the following setup code to your user application:
|
||||||
|
* \snippet qs_tcc_basic.c setup
|
||||||
|
*
|
||||||
|
* Add to user application initialization (typically the start of \c main()):
|
||||||
|
* \snippet qs_tcc_basic.c setup_init
|
||||||
|
*
|
||||||
|
* \subsection asfdoc_sam0_tcc_basic_use_case_setup_flow Workflow
|
||||||
|
* -# Create a module software instance structure for the TCC module to store
|
||||||
|
* the TCC driver state while it is in use.
|
||||||
|
* \snippet qs_tcc_basic.c module_inst
|
||||||
|
* \note This should never go out of scope as long as the module is in use.
|
||||||
|
* In most cases, this should be global.
|
||||||
|
*
|
||||||
|
* -# Configure the TCC module.
|
||||||
|
* -# Create a TCC module configuration struct, which can be filled out to
|
||||||
|
* adjust the configuration of a physical TCC peripheral.
|
||||||
|
* \snippet qs_tcc_basic.c setup_config
|
||||||
|
* -# Initialize the TCC configuration struct with the module's default values.
|
||||||
|
* \snippet qs_tcc_basic.c setup_config_defaults
|
||||||
|
* \note This should always be performed before using the configuration
|
||||||
|
* struct to ensure that all values are initialized to known default
|
||||||
|
* settings.
|
||||||
|
*
|
||||||
|
* -# Alter the TCC settings to configure the counter width, wave generation
|
||||||
|
* mode, and the compare channel 0 value.
|
||||||
|
* \snippet qs_tcc_basic.c setup_change_config
|
||||||
|
* -# Alter the TCC settings to configure the PWM output on a physical device
|
||||||
|
* pin.
|
||||||
|
* \snippet qs_tcc_basic.c setup_change_config_pwm
|
||||||
|
* -# Configure the TCC module with the desired settings.
|
||||||
|
* \snippet qs_tcc_basic.c setup_set_config
|
||||||
|
* -# Enable the TCC module to start the timer and begin PWM signal generation.
|
||||||
|
* \snippet qs_tcc_basic.c setup_enable
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* \section asfdoc_sam0_tcc_basic_use_case_main Use Case
|
||||||
|
*
|
||||||
|
* \subsection asfdoc_sam0_tcc_basic_use_case_main_code Code
|
||||||
|
* Copy-paste the following code to your user application:
|
||||||
|
* \snippet qs_tcc_basic.c main
|
||||||
|
*
|
||||||
|
* \subsection asfdoc_sam0_tcc_basic_use_case_main_flow Workflow
|
||||||
|
* -# Enter an infinite loop while the PWM wave is generated via the TCC module.
|
||||||
|
* \snippet qs_tcc_basic.c main_loop
|
||||||
|
*/
|
||||||
|
|
@ -0,0 +1,145 @@
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
*
|
||||||
|
* \brief SAM TCC Driver Double Buffering Quick Start
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014-2018 Microchip Technology Inc. and its subsidiaries.
|
||||||
|
*
|
||||||
|
* \asf_license_start
|
||||||
|
*
|
||||||
|
* \page License
|
||||||
|
*
|
||||||
|
* Subject to your compliance with these terms, you may use Microchip
|
||||||
|
* software and any derivatives exclusively with Microchip products.
|
||||||
|
* It is your responsibility to comply with third party license terms applicable
|
||||||
|
* to your use of third party software (including open source software) that
|
||||||
|
* may accompany Microchip software.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
|
||||||
|
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
|
||||||
|
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
|
||||||
|
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
|
||||||
|
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
|
||||||
|
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
|
||||||
|
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
|
||||||
|
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
|
||||||
|
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
|
||||||
|
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
|
||||||
|
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
|
||||||
|
*
|
||||||
|
* \asf_license_stop
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* Support and FAQ: visit <a href="https://www.microchip.com/support/">Microchip Support</a>
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \page asfdoc_sam0_tcc_buffering_use_case Quick Start Guide for TCC - Double Buffering and Circular
|
||||||
|
*
|
||||||
|
* The supported board list:
|
||||||
|
* - SAM D21/R21/L21/L22/DA1/C21/HA1G16A Xplained Pro
|
||||||
|
*
|
||||||
|
* In this use case, the TCC will be used to generate a PWM signal. Here
|
||||||
|
* the pulse width alters in one quarter and three quarter of the period.
|
||||||
|
* When the PWM signal connects to LED, LED will light. To see the waveform,
|
||||||
|
* you may need an oscilloscope.
|
||||||
|
* SAMHA1G16A Xpro LED is PA00 which isn't connected out, use PA04 instead,
|
||||||
|
* so we can't see LED blink but only see the waveform from oscilloscope.
|
||||||
|
*
|
||||||
|
* The PWM output is set up as follows:
|
||||||
|
* <table>
|
||||||
|
* <tr><th> Board </td><th> Pin </td><th> Connect to </td></tr>
|
||||||
|
* <tr><td> SAM D21 Xpro </td><td> PB30 </td><td> LED0 </td></tr>
|
||||||
|
* <tr><td> SAM R21 Xpro </td><td> PA19 </td><td> LED0 </td></tr>
|
||||||
|
* <tr><td> SAM L21 Xpro </td><td> PB10 </td><td> LED0 </td></tr>
|
||||||
|
* <tr><td> SAM L22 Xpro </td><td> PC27 </td><td> LED0 </td></tr>
|
||||||
|
* <tr><td> SAM DA1 Xpro </td><td> PB30 </td><td> LED0 </td></tr>
|
||||||
|
* <tr><td> SAM C21 Xpro </td><td> PA15 </td><td> LED0 </td></tr>
|
||||||
|
* <tr><td> SAM HA1G16A Xpro </td><td> PA04 </td><td> NULL </td></tr>
|
||||||
|
* </table>
|
||||||
|
*
|
||||||
|
* The TCC module will be set up as follows:
|
||||||
|
* - GCLK generator 0 (GCLK main) clock source
|
||||||
|
* - Use double buffering write when set top, compare, or pattern through API
|
||||||
|
* - No dithering on the counter or compare
|
||||||
|
* - Prescaler is set to 1024
|
||||||
|
* - Single Slope PWM wave generation
|
||||||
|
* - GCLK reload action
|
||||||
|
* - Don't run in standby
|
||||||
|
* - No fault or waveform extensions
|
||||||
|
* - No inversion of waveform output
|
||||||
|
* - No capture enabled
|
||||||
|
* - Count upward
|
||||||
|
* - Don't perform one-shot operations
|
||||||
|
* - No event input enabled
|
||||||
|
* - No event action
|
||||||
|
* - No event generation enabled
|
||||||
|
* - Counter starts on 0
|
||||||
|
* - Counter top set to 8000
|
||||||
|
* - Capture compare channel set to 8000/4
|
||||||
|
* - Capture compare channel buffer set to 8000*3/4
|
||||||
|
* - Circular option for compare channel is enabled so that the compare
|
||||||
|
* values keep switching on update condition
|
||||||
|
*
|
||||||
|
* \section asfdoc_sam0_tcc_buffering_use_case_setup Quick Start
|
||||||
|
*
|
||||||
|
* \subsection asfdoc_sam0_tcc_buffering_use_case_prereq Prerequisites
|
||||||
|
* There are no prerequisites for this use case.
|
||||||
|
*
|
||||||
|
* \subsection asfdoc_sam0_tcc_buffering_use_case_setup_code Code
|
||||||
|
*
|
||||||
|
* Add to the main application source file, before any functions:
|
||||||
|
* \snippet conf_quick_start_buffering.h definition_pwm
|
||||||
|
*
|
||||||
|
* Add to the main application source file, outside of any functions:
|
||||||
|
* \snippet qs_tcc_buffering.c module_inst
|
||||||
|
*
|
||||||
|
* Copy-paste the following setup code to your user application:
|
||||||
|
* \snippet qs_tcc_buffering.c setup
|
||||||
|
*
|
||||||
|
* Add to user application initialization (typically the start of \c main()):
|
||||||
|
* \snippet qs_tcc_buffering.c setup_init
|
||||||
|
*
|
||||||
|
* \subsection asfdoc_sam0_tcc_buffering_use_case_setup_flow Workflow
|
||||||
|
* -# Create a module software instance structure for the TCC module to store
|
||||||
|
* the TCC driver state while it is in use.
|
||||||
|
* \snippet qs_tcc_buffering.c module_inst
|
||||||
|
* \note This should never go out of scope as long as the module is in use.
|
||||||
|
* In most cases, this should be global.
|
||||||
|
*
|
||||||
|
* -# Configure the TCC module.
|
||||||
|
* -# Create a TCC module configuration struct, which can be filled out to
|
||||||
|
* adjust the configuration of a physical TCC peripheral.
|
||||||
|
* \snippet qs_tcc_buffering.c setup_config
|
||||||
|
* -# Initialize the TCC configuration struct with the module's default values.
|
||||||
|
* \snippet qs_tcc_buffering.c setup_config_defaults
|
||||||
|
* \note This should always be performed before using the configuration
|
||||||
|
* struct to ensure that all values are initialized to known default
|
||||||
|
* settings.
|
||||||
|
*
|
||||||
|
* -# Alter the TCC settings to configure the counter width, wave generation
|
||||||
|
* mode, and the compare channel 0 value.
|
||||||
|
* \snippet qs_tcc_buffering.c setup_change_config
|
||||||
|
* -# Alter the TCC settings to configure the PWM output on a physical device
|
||||||
|
* pin.
|
||||||
|
* \snippet qs_tcc_buffering.c setup_change_config_pwm
|
||||||
|
* -# Configure the TCC module with the desired settings.
|
||||||
|
* \snippet qs_tcc_buffering.c setup_set_config
|
||||||
|
* -# Set to compare buffer value and enable circular of double buffered
|
||||||
|
* compare values.
|
||||||
|
* \snippet qs_tcc_buffering.c setup_set_buffering
|
||||||
|
* -# Enable the TCC module to start the timer and begin PWM signal generation.
|
||||||
|
* \snippet qs_tcc_buffering.c setup_enable
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* \section asfdoc_sam0_tcc_buffering_use_case_main Use Case
|
||||||
|
*
|
||||||
|
* \subsection asfdoc_sam0_tcc_buffering_use_case_main_code Code
|
||||||
|
* Copy-paste the following code to your user application:
|
||||||
|
* \snippet qs_tcc_buffering.c main
|
||||||
|
*
|
||||||
|
* \subsection asfdoc_sam0_tcc_buffering_use_case_main_flow Workflow
|
||||||
|
* -# Enter an infinite loop while the PWM wave is generated via the TCC module.
|
||||||
|
* \snippet qs_tcc_buffering.c main_loop
|
||||||
|
*/
|
||||||
|
|
@ -0,0 +1,275 @@
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
*
|
||||||
|
* \brief SAM TCC Driver Quick Start with DMA
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014-2018 Microchip Technology Inc. and its subsidiaries.
|
||||||
|
*
|
||||||
|
* \asf_license_start
|
||||||
|
*
|
||||||
|
* \page License
|
||||||
|
*
|
||||||
|
* Subject to your compliance with these terms, you may use Microchip
|
||||||
|
* software and any derivatives exclusively with Microchip products.
|
||||||
|
* It is your responsibility to comply with third party license terms applicable
|
||||||
|
* to your use of third party software (including open source software) that
|
||||||
|
* may accompany Microchip software.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
|
||||||
|
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
|
||||||
|
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
|
||||||
|
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
|
||||||
|
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
|
||||||
|
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
|
||||||
|
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
|
||||||
|
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
|
||||||
|
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
|
||||||
|
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
|
||||||
|
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
|
||||||
|
*
|
||||||
|
* \asf_license_stop
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* Support and FAQ: visit <a href="https://www.microchip.com/support/">Microchip Support</a>
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \page asfdoc_sam0_tcc_dma_use_case Quick Start Guide for Using DMA with TCC
|
||||||
|
*
|
||||||
|
* The supported board list:
|
||||||
|
* - SAM D21/R21/L21/L22/DA1/C21/HA1G16A Xplained Pro
|
||||||
|
*
|
||||||
|
* In this use case, the TCC will be used to generate a PWM signal. Here
|
||||||
|
* the pulse width varies through the following values with the help of DMA
|
||||||
|
* transfer: one quarter of the period, half of the period, and three quarters
|
||||||
|
* of the period.
|
||||||
|
* The PWM output can be used to drive a LED. The waveform can also be
|
||||||
|
* viewed using an oscilloscope.
|
||||||
|
* The output signal is also fed back to another TCC channel by event system,
|
||||||
|
* the event stamps are captured and transferred to a buffer by DMA.
|
||||||
|
* SAMHA1G16A Xpro LED is PA00 which isn't connected out, use PA04 instead,
|
||||||
|
* so we can't see LED blink but only see the waveform from oscilloscope.
|
||||||
|
*
|
||||||
|
* The PWM output is set up as follows:
|
||||||
|
* <table>
|
||||||
|
* <tr><th> Board </td><th> Pin </td><th> Connect to </td></tr>
|
||||||
|
* <tr><td> SAM D21 Xpro </td><td> PB30 </td><td> LED0 </td></tr>
|
||||||
|
* <tr><td> SAM R21 Xpro </td><td> PA19 </td><td> LED0 </td></tr>
|
||||||
|
* <tr><td> SAM L21 Xpro </td><td> PB10 </td><td> LED0 </td></tr>
|
||||||
|
* <tr><td> SAM L22 Xpro </td><td> PC27 </td><td> LED0 </td></tr>
|
||||||
|
* <tr><td> SAM DA1 Xpro </td><td> PB30 </td><td> LED0 </td></tr>
|
||||||
|
* <tr><td> SAM C21 Xpro </td><td> PA15 </td><td> LED0 </td></tr>
|
||||||
|
* <tr><td> SAM HA1G16A Xpro </td><td> PA04 </td><td> NULL </td></tr>
|
||||||
|
* </table>
|
||||||
|
*
|
||||||
|
* The TCC module will be setup as follows:
|
||||||
|
* - GCLK generator 0 (GCLK main) clock source
|
||||||
|
* - Use double buffering write when set top, compare, or pattern through API
|
||||||
|
* - No dithering on the counter or compare
|
||||||
|
* - Prescaler is set to 1024
|
||||||
|
* - Single Slope PWM wave generation
|
||||||
|
* - GCLK reload action
|
||||||
|
* - Don't run in standby
|
||||||
|
* - No fault or waveform extensions
|
||||||
|
* - No inversion of waveform output
|
||||||
|
* - No capture enabled
|
||||||
|
* - Count upward
|
||||||
|
* - Don't perform one-shot operations
|
||||||
|
* - Counter starts on 0
|
||||||
|
* - Counter top set to 0x1000
|
||||||
|
* - Channel 0 (on SAM D21 Xpro) or 3 (on SAM R21 Xpro) is set to
|
||||||
|
* compare and match value 0x1000*3/4 and generate event
|
||||||
|
* - Channel 1 is set to capture on input event
|
||||||
|
*
|
||||||
|
* The event resource of EVSYS module will be setup as follows:
|
||||||
|
* - TCC match capture channel 0 (on SAM D21 Xpro) or 3 (on SAM R21 Xpro) is
|
||||||
|
* selected as event generator
|
||||||
|
* - Event generation is synchronous, with rising edge detected
|
||||||
|
* - TCC match capture channel 1 is the event user
|
||||||
|
*
|
||||||
|
* The DMA resource of DMAC module will be setup as follows:
|
||||||
|
* - Two DMA resources are used
|
||||||
|
* - Both DMA resources use peripheral trigger
|
||||||
|
* - Both DMA resources perform beat transfer on trigger
|
||||||
|
* - Both DMA resources use beat size of 16 bits
|
||||||
|
* - Both DMA resources are configured to transfer three beats and
|
||||||
|
* then repeat again in same buffer
|
||||||
|
* - On DMA resource which controls the compare value
|
||||||
|
* - TCC0 overflow triggers DMA transfer
|
||||||
|
* - The source address increment is enabled
|
||||||
|
* - The destination address is fixed to TCC channel 0 Compare/Capture
|
||||||
|
*register
|
||||||
|
* - On DMA resource which reads the captured value
|
||||||
|
* - TCC0 capture on channel 1 triggers DMA transfer
|
||||||
|
* - The source address is fixed to TCC channel 1 Compare/Capture register
|
||||||
|
* - The destination address increment is enabled
|
||||||
|
* - The captured value is transferred to an array in SRAM
|
||||||
|
*
|
||||||
|
* \section asfdoc_sam0_tcc_dma_use_case_setup Quick Start
|
||||||
|
*
|
||||||
|
* \subsection asfdoc_sam0_tcc_dma_use_case_prereq Prerequisites
|
||||||
|
* There are no prerequisites for this use case.
|
||||||
|
*
|
||||||
|
* \subsection asfdoc_sam0_tcc_dma_use_case_setup_code Code
|
||||||
|
*
|
||||||
|
* Add to the main application source file, before any functions, according to
|
||||||
|
* the kit used:
|
||||||
|
* - SAM D21 Xplained Pro
|
||||||
|
* \snippet samd21_xplained_pro/conf_quick_start_dma.h definition_pwm
|
||||||
|
* \snippet samd21_xplained_pro/conf_quick_start_dma.h definition_feedback
|
||||||
|
* \snippet samd21_xplained_pro/conf_quick_start_dma.h definition_dma_compare_trigger
|
||||||
|
* \snippet samd21_xplained_pro/conf_quick_start_dma.h definition_dma_capture_trigger
|
||||||
|
* - SAM R21 Xplained Pro
|
||||||
|
* \snippet samr21_xplained_pro/conf_quick_start_dma.h definition_pwm
|
||||||
|
* \snippet samr21_xplained_pro/conf_quick_start_dma.h definition_feedback
|
||||||
|
* \snippet samr21_xplained_pro/conf_quick_start_dma.h definition_dma_compare_trigger
|
||||||
|
* \snippet samr21_xplained_pro/conf_quick_start_dma.h definition_dma_capture_trigger
|
||||||
|
* - SAM L21 Xplained Pro
|
||||||
|
* \snippet saml21_xplained_pro/conf_quick_start_dma.h definition_pwm
|
||||||
|
* \snippet saml21_xplained_pro/conf_quick_start_dma.h definition_feedback
|
||||||
|
* \snippet saml21_xplained_pro/conf_quick_start_dma.h definition_dma_compare_trigger
|
||||||
|
* - SAM L22 Xplained Pro
|
||||||
|
* \snippet saml22_xplained_pro/conf_quick_start_dma.h definition_pwm
|
||||||
|
* \snippet saml22_xplained_pro/conf_quick_start_dma.h definition_feedback
|
||||||
|
* \snippet saml22_xplained_pro/conf_quick_start_dma.h definition_dma_compare_trigger
|
||||||
|
* - SAM DA1 Xplained Pro
|
||||||
|
* \snippet samda1_xplained_pro/conf_quick_start_dma.h definition_pwm
|
||||||
|
* \snippet samda1_xplained_pro/conf_quick_start_dma.h definition_feedback
|
||||||
|
* \snippet samda1_xplained_pro/conf_quick_start_dma.h definition_dma_compare_trigger
|
||||||
|
* \snippet samda1_xplained_pro/conf_quick_start_dma.h definition_dma_capture_trigger
|
||||||
|
* - SAM C21 Xplained Pro
|
||||||
|
* \snippet samc21_xplained_pro/conf_quick_start_dma.h definition_pwm
|
||||||
|
* \snippet samc21_xplained_pro/conf_quick_start_dma.h definition_feedback
|
||||||
|
* \snippet samc21_xplained_pro/conf_quick_start_dma.h definition_dma_compare_trigger
|
||||||
|
*
|
||||||
|
* Add to the main application source file, outside of any functions:
|
||||||
|
* \snippet qs_tcc_dma.c module_inst
|
||||||
|
* \snippet qs_tcc_dma.c capture_variables
|
||||||
|
* \snippet qs_tcc_dma.c compare_variables
|
||||||
|
*
|
||||||
|
* Copy-paste the following setup code to your user application:
|
||||||
|
* \snippet qs_tcc_dma.c config_event_for_capture
|
||||||
|
* \snippet qs_tcc_dma.c config_dma_for_capture
|
||||||
|
* \snippet qs_tcc_dma.c config_dma_for_wave
|
||||||
|
* \snippet qs_tcc_dma.c setup
|
||||||
|
*
|
||||||
|
* Add to user application initialization (typically the start of \c main()):
|
||||||
|
* \snippet qs_tcc_dma.c setup_init
|
||||||
|
*
|
||||||
|
* \subsection asfdoc_sam0_tcc_dma_use_case_setup_flow Workflow
|
||||||
|
* \subsubsection asfdoc_sam0_tcc_dma_use_case_setup_flow_tcc Configure the TCC
|
||||||
|
* -# Create a module software instance structure for the TCC module to store
|
||||||
|
* the TCC driver state while it is in use.
|
||||||
|
* \snippet qs_tcc_dma.c module_inst
|
||||||
|
* \note This should never go out of scope as long as the module is in use.
|
||||||
|
* In most cases, this should be global.
|
||||||
|
* -# Create a TCC module configuration struct, which can be filled out to
|
||||||
|
* adjust the configuration of a physical TCC peripheral.
|
||||||
|
* \snippet qs_tcc_dma.c setup_config
|
||||||
|
* -# Initialize the TCC configuration struct with the module's default values.
|
||||||
|
* \snippet qs_tcc_dma.c setup_config_defaults
|
||||||
|
* \note This should always be performed before using the configuration
|
||||||
|
* struct to ensure that all values are initialized to known default
|
||||||
|
* settings.
|
||||||
|
* -# Alter the TCC settings to configure the counter width, wave generation
|
||||||
|
* mode, and the compare channel 0 value.
|
||||||
|
* \snippet qs_tcc_dma.c setup_change_config
|
||||||
|
* -# Alter the TCC settings to configure the PWM output on a physical device
|
||||||
|
* pin.
|
||||||
|
* \snippet qs_tcc_dma.c setup_change_config_pwm
|
||||||
|
* -# Configure the TCC module with the desired settings.
|
||||||
|
* \snippet qs_tcc_dma.c setup_set_config
|
||||||
|
* -# Configure and enable the desired events for the TCC module.
|
||||||
|
* \snippet qs_tcc_dma.c setup_events
|
||||||
|
* \subsubsection asfdoc_sam0_tcc_dma_use_case_setup_flow_event Configure the Event System
|
||||||
|
* Configure the EVSYS module to wire channel 0 event to channel 1.
|
||||||
|
* -# Create an event resource instance.
|
||||||
|
* \snippet qs_tcc_dma.c capture_event_resource
|
||||||
|
* \note This should never go out of scope as long as the resource is in
|
||||||
|
* use. In most cases, this should be global.
|
||||||
|
*
|
||||||
|
* -# Create an event resource configuration struct.
|
||||||
|
* \snippet qs_tcc_dma.c event_setup_1
|
||||||
|
* -# Initialize the event resource configuration struct with default values.
|
||||||
|
* \snippet qs_tcc_dma.c event_setup_2
|
||||||
|
* \note This should always be performed before using the configuration
|
||||||
|
* struct to ensure that all values are initialized to known default
|
||||||
|
* settings.
|
||||||
|
* -# Adjust the event resource configuration to desired values.
|
||||||
|
* \snippet qs_tcc_dma.c event_setup_3
|
||||||
|
* -# Allocate and configure the resource using the configuration structure.
|
||||||
|
* \snippet qs_tcc_dma.c event_setup_4
|
||||||
|
* -# Attach a user to the resource.
|
||||||
|
* \snippet qs_tcc_dma.c event_setup_5
|
||||||
|
* \subsubsection asfdoc_sam0_tcc_dma_use_case_setup_flow_dma_capture Configure the DMA for Capture TCC Channel 1
|
||||||
|
* Configure the DMAC module to obtain captured value from TCC channel 1.
|
||||||
|
* -# Create a DMA resource instance.
|
||||||
|
* \snippet qs_tcc_dma.c capture_dma_resource
|
||||||
|
* \note This should never go out of scope as long as the resource is in
|
||||||
|
* use. In most cases, this should be global.
|
||||||
|
* -# Create a DMA resource configuration struct.
|
||||||
|
* \snippet qs_tcc_dma.c dma_setup_1
|
||||||
|
* -# Initialize the DMA resource configuration struct with default values.
|
||||||
|
* \snippet qs_tcc_dma.c dma_setup_2
|
||||||
|
* \note This should always be performed before using the configuration
|
||||||
|
* struct to ensure that all values are initialized to known default
|
||||||
|
* settings.
|
||||||
|
* -# Adjust the DMA resource configurations.
|
||||||
|
* \snippet qs_tcc_dma.c dma_setup_3
|
||||||
|
* -# Allocate a DMA resource with the configurations.
|
||||||
|
* \snippet qs_tcc_dma.c dma_setup_4
|
||||||
|
* -# Prepare DMA transfer descriptor.
|
||||||
|
* -# Create a DMA transfer descriptor.
|
||||||
|
* \snippet qs_tcc_dma.c capture_dma_descriptor
|
||||||
|
* \note When multiple descriptors are linked, the linked item should
|
||||||
|
* never go out of scope before it is loaded (to DMA Write-Back
|
||||||
|
* memory section). In most cases, if more than one descriptors are
|
||||||
|
* used, they should be global except the very first one.
|
||||||
|
* -# Create a DMA transfer descriptor struct.
|
||||||
|
* -# Create a DMA transfer descriptor configuration structure, which can be
|
||||||
|
* filled out to adjust the configuration of a single DMA transfer.
|
||||||
|
* \snippet qs_tcc_dma.c dma_setup_5
|
||||||
|
* -# Initialize the DMA transfer descriptor configuration struct with
|
||||||
|
* default values.
|
||||||
|
* \snippet qs_tcc_dma.c dma_setup_6
|
||||||
|
* \note This should always be performed before using the configuration
|
||||||
|
* struct to ensure that all values are initialized to known default
|
||||||
|
* settings.
|
||||||
|
* -# Adjust the DMA transfer descriptor configurations.
|
||||||
|
* \snippet qs_tcc_dma.c dma_setup_7
|
||||||
|
* -# Create the DMA transfer descriptor with the given configuration.
|
||||||
|
* \snippet qs_tcc_dma.c dma_setup_8
|
||||||
|
* -# Start DMA transfer job with prepared descriptor.
|
||||||
|
* -# Add the DMA transfer descriptor to the allocated DMA resource.
|
||||||
|
* \snippet qs_tcc_dma.c dma_setup_10
|
||||||
|
* \note When adding multiple descriptors, the last one added is linked
|
||||||
|
* at the end of the descriptor queue. If ringed list is needed,
|
||||||
|
* just add the first descriptor again to build the circle.
|
||||||
|
* -# Start the DMA transfer job with the allocated DMA resource and
|
||||||
|
* transfer descriptor.
|
||||||
|
* \snippet qs_tcc_dma.c dma_setup_11
|
||||||
|
* \subsubsection asfdoc_sam0_tcc_dma_use_case_setup_flow_dma_compare Configure the DMA for Compare TCC Channel 0
|
||||||
|
* Configure the DMAC module to update TCC channel 0 compare value.
|
||||||
|
* The flow is similar to last DMA configure step for capture.
|
||||||
|
* -# Allocate and configure the DMA resource.
|
||||||
|
* \snippet qs_tcc_dma.c compare_dma_resource
|
||||||
|
* \snippet qs_tcc_dma.c config_dma_resource_for_wave
|
||||||
|
* -# Prepare DMA transfer descriptor.
|
||||||
|
* \snippet qs_tcc_dma.c compare_dma_descriptor
|
||||||
|
* \snippet qs_tcc_dma.c config_dma_descriptor_for_wave
|
||||||
|
* -# Start DMA transfer job with prepared descriptor.
|
||||||
|
* \snippet qs_tcc_dma.c config_dma_job_for_wave
|
||||||
|
* -# Enable the TCC module to start the timer and begin PWM signal generation.
|
||||||
|
* \snippet qs_tcc_dma.c setup_enable
|
||||||
|
*
|
||||||
|
* \section asfdoc_sam0_tcc_dma_use_case_main Use Case
|
||||||
|
*
|
||||||
|
* \subsection asfdoc_sam0_tcc_dma_use_case_main_code Code
|
||||||
|
* Copy-paste the following code to your user application:
|
||||||
|
* \snippet qs_tcc_dma.c main
|
||||||
|
*
|
||||||
|
* \subsection asfdoc_sam0_tcc_dma_use_case_main_flow Workflow
|
||||||
|
* -# Enter an infinite loop while the PWM wave is generated via the TCC module.
|
||||||
|
* \snippet qs_tcc_dma.c main_loop
|
||||||
|
*/
|
||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
|
@ -73,7 +73,7 @@
|
||||||
|
|
||||||
// From module: FreeRTOS - kernel 10.0.0
|
// From module: FreeRTOS - kernel 10.0.0
|
||||||
#include <FreeRTOS.h>
|
#include <FreeRTOS.h>
|
||||||
#include <StackMacros.h>
|
//#include <StackMacros.h>
|
||||||
#include <croutine.h>
|
#include <croutine.h>
|
||||||
#include <deprecated_definitions.h>
|
#include <deprecated_definitions.h>
|
||||||
#include <event_groups.h>
|
#include <event_groups.h>
|
||||||
|
|
@ -135,6 +135,13 @@
|
||||||
#include <samd/sleepmgr.h>
|
#include <samd/sleepmgr.h>
|
||||||
#include <sleepmgr.h>
|
#include <sleepmgr.h>
|
||||||
|
|
||||||
|
// From module: TC - Timer Counter (Callback APIs)
|
||||||
|
#include <tc.h>
|
||||||
|
#include <tc_interrupt.h>
|
||||||
|
|
||||||
|
// From module: TCC - Timer Counter for Control Applications (Polled APIs)
|
||||||
|
#include <tcc.h>
|
||||||
|
|
||||||
// From module: USB - Universal Serial Bus
|
// From module: USB - Universal Serial Bus
|
||||||
#include <usb.h>
|
#include <usb.h>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
/*
|
||||||
|
* adn8831.h
|
||||||
|
*
|
||||||
|
* Created: 04.01.2021 19:13:57
|
||||||
|
* Author: Lexus
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef ADN8831_H_
|
||||||
|
#define ADN8831_H_
|
||||||
|
#include <asf.h>
|
||||||
|
#define MAX_STR_FLOAT 12
|
||||||
|
void make_float2str(char * str, uint16_t len, float value);
|
||||||
|
void ADN8831_control(void);
|
||||||
|
|
||||||
|
#endif /* ADN8831_H_ */
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
/*
|
||||||
|
* backlight.h
|
||||||
|
*
|
||||||
|
* Created: 10.04.2020 0:41:41
|
||||||
|
* Author: User
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef BACKLIGHT_H_
|
||||||
|
#define BACKLIGHT_H_
|
||||||
|
|
||||||
|
|
||||||
|
void backlight_event_100ms(void);
|
||||||
|
void backlight_event_1s(void);
|
||||||
|
void backlight_mode_demo(void);
|
||||||
|
void backlight_init(void);
|
||||||
|
void backlight_ws2812_sendarray(void);
|
||||||
|
void backlight_color_show(uint8_t R, uint8_t G, uint8_t B);
|
||||||
|
|
||||||
|
enum backlight_mode
|
||||||
|
{
|
||||||
|
mode_none=0,
|
||||||
|
mode_constant,
|
||||||
|
mode_demo
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* BACKLIGHT_H_ */
|
||||||
|
|
@ -0,0 +1,36 @@
|
||||||
|
/*
|
||||||
|
* dht.h
|
||||||
|
*
|
||||||
|
* Created: 04.01.2021 21:06:23
|
||||||
|
* Author: Lexus
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef DHT_H_
|
||||||
|
#define DHT_H_
|
||||||
|
|
||||||
|
#include <asf.h>
|
||||||
|
|
||||||
|
/* Ñòðóêòóðà âîçâðàùàåìûõ äàò÷èêîì äàííûõ */
|
||||||
|
typedef struct {
|
||||||
|
float hum;
|
||||||
|
float temp;
|
||||||
|
} DHT_data;
|
||||||
|
/* Òèï èñïîëüçóåìîãî äàò÷èêà */
|
||||||
|
typedef enum {
|
||||||
|
DHT11,
|
||||||
|
DHT22
|
||||||
|
} DHT_type;
|
||||||
|
|
||||||
|
/* Íàñòðîéêè */
|
||||||
|
#define DHT_Pin PIN_PA15 //Ïèí ëèíèè äàííûõ
|
||||||
|
#define DHT_timeout 1000000 //Êîëè÷åñòâî èòåðàöèé, ïîñëå êîòîðûõ ôóíêöèÿ âåðí¸ò ïóñòûå çíà÷åíèÿ
|
||||||
|
|
||||||
|
/* Ïðîòîòèïû ôóíêöèé */
|
||||||
|
uint8_t DHT_getData(DHT_type t, DHT_data* p_data); //Ïîëó÷èòü äàííûå ñ äàò÷èêà
|
||||||
|
uint8_t _DHT_getData(DHT_type t, DHT_data* p_data);
|
||||||
|
void measurement_DHT22(void);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* DHT_H_ */
|
||||||
|
|
@ -0,0 +1,128 @@
|
||||||
|
/*
|
||||||
|
* light weight WS2812 lib - ARM Cortex M0/M0+ version
|
||||||
|
*
|
||||||
|
* Created: 07.07.2013
|
||||||
|
* Author: Tim (cpldcpu@gmail.com)
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "light_ws2812_cortex.h"
|
||||||
|
/*
|
||||||
|
* The total length of each bit is 1.25µs (25 cycles @ 20Mhz)
|
||||||
|
* At 0µs the dataline is pulled high.
|
||||||
|
* To send a zero the dataline is pulled low after 0.375µs
|
||||||
|
* To send a one the dataline is pulled low after 0.625µs
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define ws2812_ctot (((F_CPU/1000)*1250)/1000000)
|
||||||
|
#define ws2812_t1 (((F_CPU/1000)*375 )/1000000) // floor
|
||||||
|
#define ws2812_t2 (((F_CPU/1000)*625+500000)/1000000) // ceil
|
||||||
|
|
||||||
|
#define w1 (ws2812_t1-2)
|
||||||
|
#define w2 (ws2812_t2-ws2812_t1-2)
|
||||||
|
#define w3 (ws2812_ctot-ws2812_t2-5)
|
||||||
|
|
||||||
|
#define ws2812_DEL1 " nop \n\t"
|
||||||
|
#define ws2812_DEL2 ws2812_DEL1 ws2812_DEL1
|
||||||
|
//#define ws2812_DEL2 " b .+2 \n\t"
|
||||||
|
#define ws2812_DEL4 ws2812_DEL2 ws2812_DEL2
|
||||||
|
#define ws2812_DEL8 ws2812_DEL4 ws2812_DEL4
|
||||||
|
#define ws2812_DEL16 ws2812_DEL8 ws2812_DEL8
|
||||||
|
|
||||||
|
#define ws2812_DEL ws2812_DEL8 ws2812_DEL2
|
||||||
|
|
||||||
|
|
||||||
|
void ws2812_sendarray(uint8_t *data,int datlen)
|
||||||
|
{
|
||||||
|
uint8_t gpio_pin = PIN_PA23;
|
||||||
|
PortGroup *const port_base = port_get_group_from_gpio_pin(gpio_pin);
|
||||||
|
uint32_t pin_mask = (1UL << (gpio_pin % 32));
|
||||||
|
|
||||||
|
uint32_t maskhi = pin_mask;
|
||||||
|
uint32_t masklo = pin_mask;
|
||||||
|
volatile uint32_t *set = &port_base->OUTSET.reg;
|
||||||
|
volatile uint32_t *clr = &port_base->OUTCLR.reg;
|
||||||
|
uint32_t i=0;
|
||||||
|
uint32_t curbyte;
|
||||||
|
|
||||||
|
while (datlen--) {
|
||||||
|
curbyte=*data++;
|
||||||
|
|
||||||
|
asm volatile(
|
||||||
|
" lsl %[dat],#24 \n\t"
|
||||||
|
" movs %[ctr],#8 \n\t"
|
||||||
|
"ilop%=: \n\t"
|
||||||
|
" lsl %[dat], #1 \n\t"
|
||||||
|
" str %[maskhi], [%[set]] \n\t"
|
||||||
|
ws2812_DEL
|
||||||
|
// ws2812_DEL19
|
||||||
|
/*
|
||||||
|
#if (w1&1)
|
||||||
|
ws2812_DEL1
|
||||||
|
#endif
|
||||||
|
#if (w1&2)
|
||||||
|
ws2812_DEL2
|
||||||
|
#endif
|
||||||
|
#if (w1&4)
|
||||||
|
ws2812_DEL4
|
||||||
|
#endif
|
||||||
|
#if (w1&8)
|
||||||
|
ws2812_DEL8
|
||||||
|
#endif
|
||||||
|
#if (w1&16)
|
||||||
|
ws2812_DEL16
|
||||||
|
#endif
|
||||||
|
*/
|
||||||
|
" bcs one%= \n\t"
|
||||||
|
" str %[masklo], [%[clr]] \n\t"
|
||||||
|
"one%=: \n\t"
|
||||||
|
|
||||||
|
ws2812_DEL
|
||||||
|
|
||||||
|
/*
|
||||||
|
#if (w2&1)
|
||||||
|
ws2812_DEL1
|
||||||
|
#endif
|
||||||
|
#if (w2&2)
|
||||||
|
ws2812_DEL2
|
||||||
|
#endif
|
||||||
|
#if (w2&4)
|
||||||
|
ws2812_DEL4
|
||||||
|
#endif
|
||||||
|
#if (w2&8)
|
||||||
|
ws2812_DEL8
|
||||||
|
#endif
|
||||||
|
#if (w2&16)
|
||||||
|
ws2812_DEL16
|
||||||
|
#endif
|
||||||
|
*/
|
||||||
|
" sub %[ctr], #1 \n\t"
|
||||||
|
" str %[masklo], [%[clr]] \n\t"
|
||||||
|
" beq end%= \n\t"
|
||||||
|
|
||||||
|
ws2812_DEL
|
||||||
|
|
||||||
|
/*
|
||||||
|
#if (w3&1)
|
||||||
|
ws2812_DEL1
|
||||||
|
#endif
|
||||||
|
#if (w3&2)
|
||||||
|
ws2812_DEL2
|
||||||
|
#endif
|
||||||
|
#if (w3&4)
|
||||||
|
ws2812_DEL4
|
||||||
|
#endif
|
||||||
|
#if (w3&8)
|
||||||
|
ws2812_DEL8
|
||||||
|
#endif
|
||||||
|
#if (w3&16)
|
||||||
|
ws2812_DEL16
|
||||||
|
#endif
|
||||||
|
*/
|
||||||
|
|
||||||
|
" b ilop%= \n\t"
|
||||||
|
"end%=: \n\t"
|
||||||
|
: [ctr] "+r" (i)
|
||||||
|
: [dat] "r" (curbyte), [set] "r" (set), [clr] "r" (clr), [masklo] "r" (masklo), [maskhi] "r" (maskhi)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,110 @@
|
||||||
|
/*
|
||||||
|
* light weight WS2812 lib - ARM Cortex M0/M0+ version
|
||||||
|
*
|
||||||
|
* Created: 07.07.2013
|
||||||
|
* Author: Tim (cpldcpu@gmail.com)
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef LIGHT_WS2812_H_
|
||||||
|
#define LIGHT_WS2812_H_
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define F_CPU 48000000LU
|
||||||
|
#define LIGHT_WS2812_SAM
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////
|
||||||
|
// User defined area: CPU specific CMSIS include
|
||||||
|
///////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#if defined(LIGHT_WS2812_UC_LPC8XX)
|
||||||
|
#include "LPC8XX.h"
|
||||||
|
#define LIGHT_WS2812_LPC
|
||||||
|
#elif defined(LIGHT_WS2812_UC_STM32L0XX)
|
||||||
|
#include "stm32l0xx_hal.h"
|
||||||
|
#define LIGHT_WS2812_STM32
|
||||||
|
#elif defined(LIGHT_WS2812_UC_FSL)
|
||||||
|
#include "fsl_port.h"
|
||||||
|
#include "fsl_gpio.h"
|
||||||
|
#define LIGHT_WS2812_FSL
|
||||||
|
#elif defined(LIGHT_WS2812_SAM)
|
||||||
|
#include <asf.h>
|
||||||
|
#else
|
||||||
|
#error "Error: Please define WS2812_UC_XXXXX"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////
|
||||||
|
// User defined area: Define I/O pin
|
||||||
|
///////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
// Data port and pin definition for your CPU. Depending on the way
|
||||||
|
// port access is implemented in your Cortex CPU, the set and clr
|
||||||
|
// mask and addresses may be the same.
|
||||||
|
#ifdef LIGHT_WS2812_LPC
|
||||||
|
// This example is for the NXP LPC81X
|
||||||
|
#define ws2812_port_set ((uint32_t*)&LIGHT_WS2812_GPIO_PORT->SET0) // Address of the data port register to set the pin
|
||||||
|
#define ws2812_port_clr ((uint32_t*)&LIGHT_WS2812_GPIO_PORT->CLR0) // Address of the data port register to clear the pin
|
||||||
|
|
||||||
|
#define ws2812_mask_set (1<<2) // Bitmask to set the data out pin
|
||||||
|
#define ws2812_mask_clr (1<<2) // Bitmask to clear the data out pin
|
||||||
|
#endif
|
||||||
|
#ifdef LIGHT_WS2812_STM32
|
||||||
|
// This example is for STM32 family
|
||||||
|
#define ws2812_port_set ((uint32_t*)&LIGHT_WS2812_GPIO_PORT->BSRR) // Address of the data port register to set the pin
|
||||||
|
#define ws2812_port_clr ((uint32_t*)&LIGHT_WS2812_GPIO_PORT->BRR) // Address of the data port register to clear the pin
|
||||||
|
|
||||||
|
#define ws2812_mask_set LIGHT_WS2812_GPIO_PIN // Bitmask to set the data out pin
|
||||||
|
#define ws2812_mask_clr LIGHT_WS2812_GPIO_PIN // Bitmask to clear the data out pin
|
||||||
|
#endif
|
||||||
|
#ifdef LIGHT_WS2812_FSL
|
||||||
|
// This example is for Freescale family
|
||||||
|
#define ws2812_port_set ((uint32_t*)&LIGHT_WS2812_GPIO_PORT->PSOR) // Address of the data port register to set the pin
|
||||||
|
#define ws2812_port_clr ((uint32_t*)&LIGHT_WS2812_GPIO_PORT->PCOR) // Address of the data port register to clear the pin
|
||||||
|
|
||||||
|
#define ws2812_mask_set 1u << 2u // Bitmask to set the data out pin
|
||||||
|
#define ws2812_mask_clr 1u << 2u // Bitmask to clear the data out pin
|
||||||
|
#endif
|
||||||
|
///////////////////////////////////////////////////////////////////////
|
||||||
|
// CPU clock speed
|
||||||
|
//
|
||||||
|
// The current implementation of the sendarray routine uses cycle accurate
|
||||||
|
// active waiting. The routine is automatically adjusted according to
|
||||||
|
// the clockspeed defined below. Only values between 8 Mhz and 60 Mhz
|
||||||
|
// are allowable.
|
||||||
|
//
|
||||||
|
// Important: The timing calculation assumes that there are no waitstates
|
||||||
|
// for code memory access. If there are waitstates you may have to reduce
|
||||||
|
// the value below until you get acceptable timing. It is highly recommended
|
||||||
|
// to use this library only on devices without flash waitstates and
|
||||||
|
// predictable code execution timing.
|
||||||
|
///////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#ifndef F_CPU
|
||||||
|
#error "Error: F_CPU (CPU clock speed) is not defined"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if (F_CPU<8000000)
|
||||||
|
#error "Minimum clockspeed for ARM ws2812 library is 8 Mhz!"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if (F_CPU>60000000)
|
||||||
|
#error "Maximum clockspeed for ARM ws2812 library is 60 Mhz!"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////
|
||||||
|
// Main function call
|
||||||
|
//
|
||||||
|
// Call with address to led color array (order is Green-Red-Blue)
|
||||||
|
// Numer of bytes to be transmitted is leds*3
|
||||||
|
///////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
void ws2812_sendarray(uint8_t *ledarray,int length);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* LIGHT_WS2812_H_ */
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
/*
|
||||||
|
* ntc.h
|
||||||
|
*
|
||||||
|
* Created: 04.01.2021 18:57:42
|
||||||
|
* Author: Lexus
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef NTC_H_
|
||||||
|
#define NTC_H_
|
||||||
|
#include <asf.h>
|
||||||
|
|
||||||
|
// ADC value to R
|
||||||
|
float NTC_MCU_value2R(uint16_t value);
|
||||||
|
|
||||||
|
float NTC_TEC_value2R(uint16_t value);
|
||||||
|
|
||||||
|
// Resistance to Temp
|
||||||
|
float NTC_R2T(float R);
|
||||||
|
|
||||||
|
// Read ADC and calculate temperature in Cenlsius.
|
||||||
|
float NTC_MCU_get_temp(void);
|
||||||
|
|
||||||
|
float NTC_TEC_get_temp(uint16_t *p_value, float *p_R);
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* NTC_H_ */
|
||||||
|
|
@ -8,8 +8,8 @@
|
||||||
|
|
||||||
#ifndef REALSENCE_H_
|
#ifndef REALSENCE_H_
|
||||||
#define REALSENCE_H_
|
#define REALSENCE_H_
|
||||||
|
#include <asf.h>
|
||||||
void rs_configure_port_pins(void);
|
void rs_configure_port_pins(void);
|
||||||
void rs_set(_Bool value);
|
void rs_set(bool value);
|
||||||
|
|
||||||
#endif /* REALSENCE_H_ */
|
#endif /* REALSENCE_H_ */
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
/*
|
||||||
|
* tec.h
|
||||||
|
*
|
||||||
|
* Created: 04.01.2021 17:08:46
|
||||||
|
* Author: Lexus
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef TEC_H_
|
||||||
|
#define TEC_H_
|
||||||
|
#include <asf.h>
|
||||||
|
|
||||||
|
bool VTEC_read(float *p_Vin, float *p_VTEC);
|
||||||
|
bool ITEC_read(float *p_Vin, float *p_ITEC);
|
||||||
|
void TEC_L_set(bool value);
|
||||||
|
void TEC_set_level(float value);
|
||||||
|
void TEC_set_TEMPSET_volt(float value);
|
||||||
|
void pin_set_output(uint8_t pin, bool output_flag, uint8_t value);
|
||||||
|
#endif /* TEC_H_ */
|
||||||
|
|
@ -0,0 +1,273 @@
|
||||||
|
/**
|
||||||
|
* @author Tilen Majerle
|
||||||
|
* @email tilen@majerle.eu
|
||||||
|
* @website http://stm32f4-discovery.net
|
||||||
|
* @link http://stm32f4-discovery.net/2015/07/hal-library-06-ds18b20-for-stm32fxxx/
|
||||||
|
* @version v1.0
|
||||||
|
* @ide Keil uVision
|
||||||
|
* @license MIT
|
||||||
|
* @brief Library for interfacing DS18B20 temperature sensor from Dallas semiconductors.
|
||||||
|
*
|
||||||
|
\verbatim
|
||||||
|
----------------------------------------------------------------------
|
||||||
|
Copyright (c) 2016 Tilen Majerle
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person
|
||||||
|
obtaining a copy of this software and associated documentation
|
||||||
|
files (the "Software"), to deal in the Software without restriction,
|
||||||
|
including without limitation the rights to use, copy, modify, merge,
|
||||||
|
publish, distribute, sublicense, and/or sell copies of the Software,
|
||||||
|
and to permit persons to whom the Software is furnished to do so,
|
||||||
|
subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be
|
||||||
|
included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||||
|
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||||
|
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||||
|
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||||
|
OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
----------------------------------------------------------------------
|
||||||
|
\endverbatim
|
||||||
|
*/
|
||||||
|
#ifndef TM_DS18B20_H
|
||||||
|
#define TM_DS18B20_H 100
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @addtogroup TM_STM32Fxxx_HAL_Libraries
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @defgroup TM_DS12820
|
||||||
|
* @brief Library for interfacing DS18B20 temperature sensor from Dallas semiconductors - http://stm32f4-discovery.net/2015/07/hal-library-06-ds18b20-for-stm32fxxx/
|
||||||
|
* @{
|
||||||
|
*
|
||||||
|
* With this you can read temperature, set and get temperature resolution from 9 to 12 bits and check if device is DS18B20.
|
||||||
|
*
|
||||||
|
* Pin for STM32Fxxx is the same as set with @ref TM_ONEWIRE library.
|
||||||
|
*
|
||||||
|
* \par Changelog
|
||||||
|
*
|
||||||
|
\verbatim
|
||||||
|
Version 1.0
|
||||||
|
- First release
|
||||||
|
\endverbatim
|
||||||
|
*
|
||||||
|
* \par Dependencies
|
||||||
|
*
|
||||||
|
\verbatim
|
||||||
|
- STM32Fxxx HAL
|
||||||
|
- TM ONEWIRE
|
||||||
|
- TM GPIO
|
||||||
|
- defines.h
|
||||||
|
\endverbatim
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "tm_onewire.h"
|
||||||
|
|
||||||
|
/* OneWire version check */
|
||||||
|
#if TM_ONEWIRE_H < 100
|
||||||
|
#error "Please update TM ONEWIRE LIB, minimum required version is 2.0.0. Download available on stm32f4-discovery.net website"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @defgroup TM_DS18B20_Macros
|
||||||
|
* @brief Library defines
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Every onewire chip has different ROM code, but all the same chips has same family code */
|
||||||
|
/* in case of DS18B20 this is 0x28 and this is first byte of ROM address */
|
||||||
|
#define DS18B20_FAMILY_CODE 0x28
|
||||||
|
#define DS18B20_CMD_ALARMSEARCH 0xEC
|
||||||
|
|
||||||
|
/* DS18B20 read temperature command */
|
||||||
|
#define DS18B20_CMD_CONVERTTEMP 0x44 /* Convert temperature */
|
||||||
|
#define DS18B20_DECIMAL_STEPS_12BIT 0.0625
|
||||||
|
#define DS18B20_DECIMAL_STEPS_11BIT 0.125
|
||||||
|
#define DS18B20_DECIMAL_STEPS_10BIT 0.25
|
||||||
|
#define DS18B20_DECIMAL_STEPS_9BIT 0.5
|
||||||
|
|
||||||
|
/* Bits locations for resolution */
|
||||||
|
#define DS18B20_RESOLUTION_R1 6
|
||||||
|
#define DS18B20_RESOLUTION_R0 5
|
||||||
|
|
||||||
|
/* CRC enabled */
|
||||||
|
#ifdef DS18B20_USE_CRC
|
||||||
|
#define DS18B20_DATA_LEN 9
|
||||||
|
#else
|
||||||
|
#define DS18B20_DATA_LEN 2
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @defgroup TM_DS18B20_Typedefs
|
||||||
|
* @brief Library Typedefs
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief DS18B0 Resolutions available
|
||||||
|
*/
|
||||||
|
typedef enum {
|
||||||
|
TM_DS18B20_Resolution_9bits = 9, /*!< DS18B20 9 bits resolution */
|
||||||
|
TM_DS18B20_Resolution_10bits = 10, /*!< DS18B20 10 bits resolution */
|
||||||
|
TM_DS18B20_Resolution_11bits = 11, /*!< DS18B20 11 bits resolution */
|
||||||
|
TM_DS18B20_Resolution_12bits = 12 /*!< DS18B20 12 bits resolution */
|
||||||
|
} TM_DS18B20_Resolution_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @defgroup TM_DS18B20_Functions
|
||||||
|
* @brief Library Functions
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Starts temperature conversion for specific DS18B20 on specific onewire channel
|
||||||
|
* @param *OneWireStruct: Pointer to @ref TM_OneWire_t working structure (OneWire channel)
|
||||||
|
* @param *ROM: Pointer to first byte of ROM address for desired DS12B80 device.
|
||||||
|
* Entire ROM address is 8-bytes long
|
||||||
|
* @retval 1 if device is DS18B20 or 0 if not
|
||||||
|
*/
|
||||||
|
uint8_t TM_DS18B20_Start(TM_OneWire_t* OneWireStruct, uint8_t* ROM);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Starts temperature conversion for all DS18B20 devices on specific onewire channel
|
||||||
|
* @note This mode will skip ROM addressing
|
||||||
|
* @param *OneWireStruct: Pointer to @ref TM_OneWire_t working structure (OneWire channel)
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void TM_DS18B20_StartAll(TM_OneWire_t* OneWireStruct);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Reads temperature from DS18B20
|
||||||
|
* @param *OneWireStruct: Pointer to @ref TM_OneWire_t working structure (OneWire channel)
|
||||||
|
* @param *ROM: Pointer to first byte of ROM address for desired DS12B80 device.
|
||||||
|
* Entire ROM address is 8-bytes long
|
||||||
|
* @param *destination: Pointer to float variable to store temperature
|
||||||
|
* @retval Temperature status:
|
||||||
|
* - 0: Device is not DS18B20 or conversion is not done yet or CRC failed
|
||||||
|
* - > 0: Temperature is read OK
|
||||||
|
*/
|
||||||
|
uint8_t TM_DS18B20_Read(TM_OneWire_t* OneWireStruct, uint8_t* ROM, float* destination);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Gets resolution for temperature conversion from DS18B20 device
|
||||||
|
* @param *OneWireStruct: Pointer to @ref TM_OneWire_t working structure (OneWire channel)
|
||||||
|
* @param *ROM: Pointer to first byte of ROM address for desired DS12B80 device.
|
||||||
|
* Entire ROM address is 8-bytes long
|
||||||
|
* @retval Resolution:
|
||||||
|
* - 0: Device is not DS18B20
|
||||||
|
* - 9 - 12: Resolution of DS18B20
|
||||||
|
*/
|
||||||
|
uint8_t TM_DS18B20_GetResolution(TM_OneWire_t* OneWireStruct, uint8_t* ROM);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Sets resolution for specific DS18B20 device
|
||||||
|
* @param *OneWireStruct: Pointer to @ref TM_OneWire_t working structure (OneWire channel)
|
||||||
|
* @param *ROM: Pointer to first byte of ROM address for desired DS12B80 device.
|
||||||
|
* Entire ROM address is 8-bytes long
|
||||||
|
* @param resolution: Resolution for DS18B20 device. This parameter can be a value of @ref TM_DS18B20_Resolution_t enumeration.
|
||||||
|
* @retval Success status:
|
||||||
|
* - 0: Device is not DS18B20
|
||||||
|
* - > 0: Resolution set OK
|
||||||
|
*/
|
||||||
|
uint8_t TM_DS18B20_SetResolution(TM_OneWire_t* OneWireStruct, uint8_t* ROM, TM_DS18B20_Resolution_t resolution);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Checks if device with specific ROM number is DS18B20
|
||||||
|
* @param *ROM: Pointer to first byte of ROM address for desired DS12B80 device.
|
||||||
|
* Entire ROM address is 8-bytes long
|
||||||
|
* @retval Device status
|
||||||
|
* - 0: Device is not DS18B20
|
||||||
|
* - > 0: Device is DS18B20
|
||||||
|
*/
|
||||||
|
uint8_t TM_DS18B20_Is(uint8_t* ROM);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Sets high alarm temperature to specific DS18B20 sensor
|
||||||
|
* @param *OneWireStruct: Pointer to @ref TM_OneWire_t working structure (OneWire channel)
|
||||||
|
* @param *ROM: Pointer to first byte of ROM address for desired DS12B80 device.
|
||||||
|
* Entire ROM address is 8-bytes long
|
||||||
|
* @param temp: integer value for temperature between -55 to 125 degrees
|
||||||
|
* @retval Success status:
|
||||||
|
* - 0: Device is not DS18B20
|
||||||
|
* - > 0: High alarm set OK
|
||||||
|
*/
|
||||||
|
uint8_t TM_DS18B20_SetAlarmHighTemperature(TM_OneWire_t* OneWireStruct, uint8_t* ROM, int8_t temp);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Sets low alarm temperature to specific DS18B20 sensor
|
||||||
|
* @param *OneWireStruct: Pointer to @ref TM_OneWire_t working structure (OneWire channel)
|
||||||
|
* @param *ROM: Pointer to first byte of ROM address for desired DS12B80 device.
|
||||||
|
* Entire ROM address is 8-bytes long
|
||||||
|
* @param temp: integer value for temperature between -55 to 125 degrees
|
||||||
|
* @retval Success status:
|
||||||
|
* - 0: Device is not DS18B20
|
||||||
|
* - > 0: Low alarm set OK
|
||||||
|
*/
|
||||||
|
uint8_t TM_DS18B20_SetAlarmLowTemperature(TM_OneWire_t* OneWireStruct, uint8_t* ROM, int8_t temp);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Disables alarm temperature for specific DS18B20 sensor
|
||||||
|
* @param *OneWireStruct: Pointer to @ref TM_OneWire_t working structure (OneWire channel)
|
||||||
|
* @param *ROM: Pointer to first byte of ROM address for desired DS12B80 device.
|
||||||
|
* Entire ROM address is 8-bytes long
|
||||||
|
* @retval Success status:
|
||||||
|
* - 0: Device is not DS18B20
|
||||||
|
* - > 0: Alarm disabled OK
|
||||||
|
*/
|
||||||
|
uint8_t TM_DS18B20_DisableAlarmTemperature(TM_OneWire_t* OneWireStruct, uint8_t* ROM);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Searches for devices with alarm flag set
|
||||||
|
* @param *OneWireStruct: Pointer to @ref TM_OneWire_t working structure (OneWire channel)
|
||||||
|
* @retval Alarm search status
|
||||||
|
* - 0: No device found with alarm flag set
|
||||||
|
* - > 0: Device is found with alarm flag
|
||||||
|
* @note To get all devices on one onewire channel with alarm flag set, you can do this:
|
||||||
|
\verbatim
|
||||||
|
while (TM_DS18B20_AlarmSearch(&OneWireStruct)) {
|
||||||
|
//Read device ID here
|
||||||
|
//Print to user device by device
|
||||||
|
}
|
||||||
|
\endverbatim
|
||||||
|
* @retval 1 if any device has flag, otherwise 0
|
||||||
|
*/
|
||||||
|
uint8_t TM_DS18B20_AlarmSearch(TM_OneWire_t* OneWireStruct);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Checks if all DS18B20 sensors are done with temperature conversion
|
||||||
|
* @param *OneWireStruct: Pointer to @ref TM_OneWire_t working structure (OneWire channel)
|
||||||
|
* @retval Conversion status
|
||||||
|
* - 0: Not all devices are done
|
||||||
|
* - > 0: All devices are done with conversion
|
||||||
|
*/
|
||||||
|
uint8_t TM_DS18B20_AllDone(TM_OneWire_t* OneWireStruct);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
void measurement_DS1820(void);
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
@ -0,0 +1,293 @@
|
||||||
|
/**
|
||||||
|
* @author Tilen Majerle
|
||||||
|
* @email tilen@majerle.eu
|
||||||
|
* @website http://stm32f4-discovery.net
|
||||||
|
* @link http://stm32f4-discovery.net/2015/07/hal-library-05-onewire-for-stm32fxxx/
|
||||||
|
* @version v1.0
|
||||||
|
* @ide Keil uVision
|
||||||
|
* @license MIT
|
||||||
|
* @brief Onewire library for STM32Fxxx devices
|
||||||
|
*
|
||||||
|
\verbatim
|
||||||
|
----------------------------------------------------------------------
|
||||||
|
Copyright (c) 2016 Tilen Majerle
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person
|
||||||
|
obtaining a copy of this software and associated documentation
|
||||||
|
files (the "Software"), to deal in the Software without restriction,
|
||||||
|
including without limitation the rights to use, copy, modify, merge,
|
||||||
|
publish, distribute, sublicense, and/or sell copies of the Software,
|
||||||
|
and to permit persons to whom the Software is furnished to do so,
|
||||||
|
subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be
|
||||||
|
included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||||
|
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||||
|
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||||
|
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||||
|
OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
----------------------------------------------------------------------
|
||||||
|
\endverbatim
|
||||||
|
*/
|
||||||
|
#ifndef TM_ONEWIRE_H
|
||||||
|
#define TM_ONEWIRE_H 100
|
||||||
|
|
||||||
|
/* C++ detection */
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @addtogroup TM_STM32Fxxx_HAL_Libraries
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @defgroup TM_ONEWIRE
|
||||||
|
* @brief Onewire library for STM32Fxxx devices - http://stm32f4-discovery.net/2015/07/hal-library-05-onewire-for-stm32fxxx/
|
||||||
|
* @{
|
||||||
|
*
|
||||||
|
* \par Changelog
|
||||||
|
*
|
||||||
|
\verbatim
|
||||||
|
Version 1.0
|
||||||
|
- First release
|
||||||
|
\endverbatim
|
||||||
|
*
|
||||||
|
* \par Dependencies
|
||||||
|
*
|
||||||
|
\verbatim
|
||||||
|
- STM32Fxxx HAL
|
||||||
|
- defines.h
|
||||||
|
- TM DELAY
|
||||||
|
- TM GPIO
|
||||||
|
\endverbatim
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <asf.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @defgroup TM_ONEWIRE_Macros
|
||||||
|
* @brief Library defines
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* OneWire delay */
|
||||||
|
#define ONEWIRE_DELAY(x) delay_us(x)
|
||||||
|
|
||||||
|
/* Pin settings */
|
||||||
|
#define ONEWIRE_LOW(structure) port_pin_set_output_level((structure)->GPIO_Pin, 0)
|
||||||
|
#define ONEWIRE_HIGH(structure) port_pin_set_output_level((structure)->GPIO_Pin, 1)
|
||||||
|
#define ONEWIRE_GET_VALUE(structure) port_pin_get_input_level((structure)->GPIO_Pin)
|
||||||
|
//#define ONEWIRE_INPUT(structure) TM_GPIO_SetPinAsInput(structure->GPIOx, (structure)->GPIO_Pin)
|
||||||
|
//#define ONEWIRE_OUTPUT(structure) TM_GPIO_SetPinAsOutput(structure->GPIOx, (structure)->GPIO_Pin)
|
||||||
|
|
||||||
|
/* OneWire commands */
|
||||||
|
#define ONEWIRE_CMD_RSCRATCHPAD 0xBE
|
||||||
|
#define ONEWIRE_CMD_WSCRATCHPAD 0x4E
|
||||||
|
#define ONEWIRE_CMD_CPYSCRATCHPAD 0x48
|
||||||
|
#define ONEWIRE_CMD_RECEEPROM 0xB8
|
||||||
|
#define ONEWIRE_CMD_RPWRSUPPLY 0xB4
|
||||||
|
#define ONEWIRE_CMD_SEARCHROM 0xF0
|
||||||
|
#define ONEWIRE_CMD_READROM 0x33
|
||||||
|
#define ONEWIRE_CMD_MATCHROM 0x55
|
||||||
|
#define ONEWIRE_CMD_SKIPROM 0xCC
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @defgroup TM_ONEWIRE_Typedefs
|
||||||
|
* @brief Library Typedefs
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief OneWire working struct
|
||||||
|
* @note Except ROM_NO member, everything is fully private and should not be touched by user
|
||||||
|
*/
|
||||||
|
typedef struct {
|
||||||
|
uint8_t GPIO_Pin; /*!< GPIO Pin to be used for I/O functions */
|
||||||
|
uint8_t LastDiscrepancy; /*!< Search private */
|
||||||
|
uint8_t LastFamilyDiscrepancy; /*!< Search private */
|
||||||
|
uint8_t LastDeviceFlag; /*!< Search private */
|
||||||
|
uint8_t ROM_NO[8]; /*!< 8-bytes address of last search device */
|
||||||
|
} TM_OneWire_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @defgroup TM_ONEWIRE_Functions
|
||||||
|
* @brief Library Functions
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Initializes OneWire bus
|
||||||
|
* @param *OneWireStruct: Pointer to @ref TM_OneWire_t empty working onewire structure
|
||||||
|
* @param *Pointer to GPIO port used for onewire channel
|
||||||
|
* @param GPIO_Pin: GPIO Pin on specific GPIOx to be used for onewire channel
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void TM_OneWire_Init(TM_OneWire_t* OneWireStruct, uint8_t GPIO_Pin);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Resets OneWire bus
|
||||||
|
*
|
||||||
|
* @note Sends reset command for OneWire
|
||||||
|
* @param *OneWireStruct: Pointer to @ref TM_OneWire_t working onewire structure
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
uint8_t TM_OneWire_Reset(TM_OneWire_t* OneWireStruct);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Reads byte from one wire bus
|
||||||
|
* @param *OneWireStruct: Pointer to @ref TM_OneWire_t working onewire structure
|
||||||
|
* @retval Byte from read operation
|
||||||
|
*/
|
||||||
|
uint8_t TM_OneWire_ReadByte(TM_OneWire_t* OneWireStruct);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Writes byte to bus
|
||||||
|
* @param *OneWireStruct: Pointer to @ref TM_OneWire_t working onewire structure
|
||||||
|
* @param byte: 8-bit value to write over OneWire protocol
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void TM_OneWire_WriteByte(TM_OneWire_t* OneWireStruct, uint8_t byte);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Writes single bit to onewire bus
|
||||||
|
* @param *OneWireStruct: Pointer to @ref TM_OneWire_t working onewire structure
|
||||||
|
* @param bit: Bit value to send, 1 or 0
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void TM_OneWire_WriteBit(TM_OneWire_t* OneWireStruct, uint8_t bit);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Reads single bit from one wire bus
|
||||||
|
* @param *OneWireStruct: Pointer to @ref TM_OneWire_t working onewire structure
|
||||||
|
* @retval Bit value:
|
||||||
|
* - 0: Bit is low (zero)
|
||||||
|
* - > 0: Bit is high (one)
|
||||||
|
*/
|
||||||
|
uint8_t TM_OneWire_ReadBit(TM_OneWire_t* OneWireStruct);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Searches for OneWire devices on specific Onewire port
|
||||||
|
* @note Not meant for public use. Use @ref TM_OneWire_First and @ref TM_OneWire_Next for this.
|
||||||
|
* @param *OneWireStruct: Pointer to @ref TM_OneWire_t working onewire structure where to search
|
||||||
|
* @param Device status:
|
||||||
|
* - 0: No devices detected
|
||||||
|
* - > 0: Device detected
|
||||||
|
*/
|
||||||
|
uint8_t TM_OneWire_Search(TM_OneWire_t* OneWireStruct, uint8_t command);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Resets search states
|
||||||
|
* @param *OneWireStruct: Pointer to @ref TM_OneWire_t working onewire where to reset search values
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void TM_OneWire_ResetSearch(TM_OneWire_t* OneWireStruct);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Starts search, reset states first
|
||||||
|
* @note When you want to search for ALL devices on one onewire port, you should first use this function.
|
||||||
|
\code
|
||||||
|
//...Initialization before
|
||||||
|
status = TM_OneWire_First(&OneWireStruct);
|
||||||
|
while (status) {
|
||||||
|
//Save ROM number from device
|
||||||
|
TM_OneWire_GetFullROM(ROM_Array_Pointer);
|
||||||
|
//Check for new device
|
||||||
|
status = TM_OneWire_Next(&OneWireStruct);
|
||||||
|
}
|
||||||
|
\endcode
|
||||||
|
* @param *OneWireStruct: Pointer to @ref TM_OneWire_t working onewire where to reset search values
|
||||||
|
* @param Device status:
|
||||||
|
* - 0: No devices detected
|
||||||
|
* - > 0: Device detected
|
||||||
|
*/
|
||||||
|
uint8_t TM_OneWire_First(TM_OneWire_t* OneWireStruct);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Reads next device
|
||||||
|
* @note Use @ref TM_OneWire_First to start searching
|
||||||
|
* @param *OneWireStruct: Pointer to @ref TM_OneWire_t working onewire
|
||||||
|
* @param Device status:
|
||||||
|
* - 0: No devices detected any more
|
||||||
|
* - > 0: New device detected
|
||||||
|
*/
|
||||||
|
uint8_t TM_OneWire_Next(TM_OneWire_t* OneWireStruct);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Gets ROM number from device from search
|
||||||
|
* @param *OneWireStruct: Pointer to @ref TM_OneWire_t working onewire
|
||||||
|
* @param index: Because each device has 8-bytes long ROm address, you have to call this 8 times, to get ROM bytes from 0 to 7
|
||||||
|
* @reetval ROM byte for index (0 to 7) at current found device
|
||||||
|
*/
|
||||||
|
uint8_t TM_OneWire_GetROM(TM_OneWire_t* OneWireStruct, uint8_t index);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Gets all 8 bytes ROM value from device from search
|
||||||
|
* @param *OneWireStruct: Pointer to @ref TM_OneWire_t working onewire
|
||||||
|
* @param *firstIndex: Pointer to first location for first byte, other bytes are automatically incremented
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void TM_OneWire_GetFullROM(TM_OneWire_t* OneWireStruct, uint8_t *firstIndex);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Selects specific slave on bus
|
||||||
|
* @param *OneWireStruct: Pointer to @ref TM_OneWire_t working onewire
|
||||||
|
* @param *addr: Pointer to first location of 8-bytes long ROM address
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void TM_OneWire_Select(TM_OneWire_t* OneWireStruct, uint8_t* addr);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Selects specific slave on bus with pointer address
|
||||||
|
* @param *OneWireStruct: Pointer to @ref TM_OneWire_t working onewire
|
||||||
|
* @param *ROM: Pointer to first byte of ROM address
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void TM_OneWire_SelectWithPointer(TM_OneWire_t* OneWireStruct, uint8_t* ROM);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Calculates 8-bit CRC for 1-wire devices
|
||||||
|
* @param *addr: Pointer to 8-bit array of data to calculate CRC
|
||||||
|
* @param len: Number of bytes to check
|
||||||
|
*
|
||||||
|
* @retval Calculated CRC from input data
|
||||||
|
*/
|
||||||
|
uint8_t TM_OneWire_CRC8(uint8_t* addr, uint8_t len);
|
||||||
|
|
||||||
|
|
||||||
|
void ONEWIRE_OUTPUT(TM_OneWire_t* OneWireStruct);
|
||||||
|
void ONEWIRE_INPUT(TM_OneWire_t* OneWireStruct);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
int TM_OneWire_Verify(TM_OneWire_t* OneWireStruct);
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
void TM_OneWire_TargetSetup(TM_OneWire_t* OneWireStruct, uint8_t family_code);
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
void TM_OneWire_FamilySkipSetup(TM_OneWire_t* OneWireStruct);
|
||||||
|
/* C++ detection */
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
@ -8,8 +8,8 @@
|
||||||
|
|
||||||
#ifndef TMPGOOD_H_
|
#ifndef TMPGOOD_H_
|
||||||
#define TMPGOOD_H_
|
#define TMPGOOD_H_
|
||||||
|
#include <asf.h>
|
||||||
void tmpgood_configure_port_pins(void);
|
void tmpgood_configure_port_pins(void);
|
||||||
_Bool tmpgood_get_state(void);
|
bool tmpgood_get_state(void);
|
||||||
|
|
||||||
#endif /* TMPGOOD_H_ */
|
#endif /* TMPGOOD_H_ */
|
||||||
|
|
@ -50,15 +50,9 @@ char str[128] = {0};
|
||||||
UBaseType_t uxHighWaterMark_cdc_rx_check;
|
UBaseType_t uxHighWaterMark_cdc_rx_check;
|
||||||
UBaseType_t uxHighWaterMark_led_blink;
|
UBaseType_t uxHighWaterMark_led_blink;
|
||||||
static volatile bool main_b_cdc_enable = false;
|
static volatile bool main_b_cdc_enable = false;
|
||||||
|
struct measured_params m_params;
|
||||||
|
|
||||||
|
|
||||||
void prvGetRegistersFromStack (uint32_t *pulFaultStackAddress);
|
|
||||||
void led_configure_port_pins(void);
|
|
||||||
void vApplicationMallocFailedHook (void);
|
|
||||||
void vApplicationStackOverflowHook (void);
|
|
||||||
void Task_cdc_rx_check(void *parameters);
|
|
||||||
void Task_led_blink(void *parameters);
|
|
||||||
void InitTask_cdc_rx_check(void);
|
|
||||||
void InitTask_led_blink(void);
|
|
||||||
/*! \brief Main function. Execution starts here.
|
/*! \brief Main function. Execution starts here.
|
||||||
*/
|
*/
|
||||||
int main(void)
|
int main(void)
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,25 @@
|
||||||
|
|
||||||
#include "usb_protocol_cdc.h"
|
#include "usb_protocol_cdc.h"
|
||||||
|
|
||||||
|
struct measured_params{
|
||||||
|
float TEC_Temp;
|
||||||
|
float MCU_Temp;
|
||||||
|
float Vin_LFB;
|
||||||
|
float Vin_SFB;
|
||||||
|
float Vin_CS;
|
||||||
|
float DHT22_Temp;
|
||||||
|
float DHT22_Hum;
|
||||||
|
float DS1820_Temp;
|
||||||
|
float TEC_Power;
|
||||||
|
};
|
||||||
|
void prvGetRegistersFromStack (uint32_t *pulFaultStackAddress);
|
||||||
|
void led_configure_port_pins(void);
|
||||||
|
void vApplicationMallocFailedHook (void);
|
||||||
|
void vApplicationStackOverflowHook (void);
|
||||||
|
void Task_cdc_rx_check(void *parameters);
|
||||||
|
void Task_led_blink(void *parameters);
|
||||||
|
void InitTask_cdc_rx_check(void);
|
||||||
|
void InitTask_led_blink(void);
|
||||||
/*! \brief Opens the communication port
|
/*! \brief Opens the communication port
|
||||||
* This is called by CDC interface when USB Host enable it.
|
* This is called by CDC interface when USB Host enable it.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
* Author: Lexus
|
* Author: Lexus
|
||||||
*/
|
*/
|
||||||
#include "adc_user.h"
|
#include "adc_user.h"
|
||||||
#include "adc.h"
|
#include <asf.h>
|
||||||
struct adc_module adc_instance;
|
struct adc_module adc_instance;
|
||||||
// init ADC
|
// init ADC
|
||||||
void configure_adc(void)
|
void configure_adc(void)
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
#ifndef ADC_H_
|
#ifndef ADC_H_
|
||||||
#define ADC_H_
|
#define ADC_H_
|
||||||
#include <stdint-gcc.h>
|
#include <asf.h>
|
||||||
#define chan_NTC_MCU ADC_POSITIVE_INPUT_PIN1
|
#define chan_NTC_MCU ADC_POSITIVE_INPUT_PIN1
|
||||||
#define chan_NTC_TEC ADC_POSITIVE_INPUT_PIN5
|
#define chan_NTC_TEC ADC_POSITIVE_INPUT_PIN5
|
||||||
#define chan_LFB ADC_POSITIVE_INPUT_PIN19
|
#define chan_LFB ADC_POSITIVE_INPUT_PIN19
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,60 @@
|
||||||
|
/*
|
||||||
|
* adn8831.c
|
||||||
|
*
|
||||||
|
* Created: 04.01.2021 19:13:33
|
||||||
|
* Author: Lexus
|
||||||
|
*/
|
||||||
|
#include "adn8831.h"
|
||||||
|
#include "ntc.h"
|
||||||
|
#include "tec.h"
|
||||||
|
#include "tmpgood.h"
|
||||||
|
|
||||||
|
void make_float2str(char * str, uint16_t len, float value){
|
||||||
|
bool neg_flag;
|
||||||
|
if(value >= 0)
|
||||||
|
neg_flag = false;
|
||||||
|
else{
|
||||||
|
neg_flag = true;
|
||||||
|
value = value * -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int a1 = value;
|
||||||
|
int a2 = (value - a1)*100.0;
|
||||||
|
snprintf(str, len, "%c%d.%2.2d",neg_flag?'-':'+', a1, a2);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ADN8831_control(void){
|
||||||
|
char t_TEC_str[MAX_STR_FLOAT];
|
||||||
|
char t_MCU_str[MAX_STR_FLOAT];
|
||||||
|
char v_VTEC_str[MAX_STR_FLOAT];
|
||||||
|
char v_ITEC_str[MAX_STR_FLOAT];
|
||||||
|
char VTEC_str[MAX_STR_FLOAT];
|
||||||
|
char ITEC_str[MAX_STR_FLOAT];
|
||||||
|
|
||||||
|
TEC_set_TEMPSET_volt(0.9);
|
||||||
|
|
||||||
|
// MCU temp
|
||||||
|
float t = NTC_MCU_get_temp();
|
||||||
|
make_float2str(t_MCU_str, MAX_STR_FLOAT, (float)t);
|
||||||
|
|
||||||
|
|
||||||
|
// TEC temp
|
||||||
|
uint16_t value_TEC;
|
||||||
|
float R_TEC;
|
||||||
|
float t_TEC = NTC_TEC_get_temp(&value_TEC, &R_TEC);
|
||||||
|
make_float2str(t_TEC_str, MAX_STR_FLOAT, (float)t_TEC);
|
||||||
|
|
||||||
|
bool TMPGD = tmpgood_get_state();
|
||||||
|
|
||||||
|
// VTEC & ITEC
|
||||||
|
float v_VTEC=0, v_ITEC=0, VTEC=0, ITEC=0;
|
||||||
|
VTEC_read(&v_VTEC, &VTEC);
|
||||||
|
ITEC_read(&v_ITEC, &ITEC);
|
||||||
|
|
||||||
|
make_float2str(v_VTEC_str, MAX_STR_FLOAT, v_VTEC);
|
||||||
|
make_float2str(v_ITEC_str, MAX_STR_FLOAT, v_ITEC);
|
||||||
|
make_float2str(VTEC_str, MAX_STR_FLOAT, VTEC);
|
||||||
|
make_float2str(ITEC_str, MAX_STR_FLOAT, ITEC);
|
||||||
|
|
||||||
|
printf("Info: t_MCU: %10s, t_TEC:%10s, TMPGD: %d, VTEC: %10s, v_VTEC: %10s, ITEC: %10s, v_ITEC: %10s\r\n",t_MCU_str, t_TEC_str, (int)TMPGD, VTEC_str, v_VTEC_str, ITEC_str, v_ITEC_str);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,127 @@
|
||||||
|
/*
|
||||||
|
* backlight.c
|
||||||
|
*
|
||||||
|
* Created: 10.04.2020 0:41:24
|
||||||
|
* Author: User
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <asf.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "light_ws2812_cortex.h"
|
||||||
|
#include "backlight.h"
|
||||||
|
|
||||||
|
enum backlight_mode mode=mode_none;
|
||||||
|
|
||||||
|
bool mode_run_light=false;
|
||||||
|
uint8_t mode_run_light_cnt=0;
|
||||||
|
|
||||||
|
uint8_t led_data[LEN_WS2812*3];
|
||||||
|
|
||||||
|
|
||||||
|
void backlight_event_100ms(void){
|
||||||
|
if(mode == mode_demo){
|
||||||
|
if(mode_run_light){
|
||||||
|
for(uint16_t i=0; i < LEN_WS2812/2;i++){
|
||||||
|
if(mode_run_light_cnt == i){
|
||||||
|
led_data[0 + i*3] = 0xff;
|
||||||
|
led_data[1 + i*3] = 0x00;
|
||||||
|
led_data[2 + i*3] = 0x00;
|
||||||
|
|
||||||
|
led_data[0 + (LEN_WS2812/2 - i - 1)*3 + (LEN_WS2812/2)*3] = 0x00;
|
||||||
|
led_data[1 + (LEN_WS2812/2 - i - 1)*3 + (LEN_WS2812/2)*3] = 0xff;
|
||||||
|
led_data[2 + (LEN_WS2812/2 - i - 1)*3 + (LEN_WS2812/2)*3] = 0x00;
|
||||||
|
}else{
|
||||||
|
led_data[0 + i*3] = 0x00;
|
||||||
|
led_data[1 + i*3] = 0x00;
|
||||||
|
led_data[2 + i*3] = 0x00;
|
||||||
|
|
||||||
|
led_data[0 + (LEN_WS2812/2 - i - 1)*3 + (LEN_WS2812/2)*3] = 0x00;
|
||||||
|
led_data[1 + (LEN_WS2812/2 - i - 1)*3 + (LEN_WS2812/2)*3] = 0x00;
|
||||||
|
led_data[2 + (LEN_WS2812/2 - i - 1)*3 + (LEN_WS2812/2)*3] = 0x00;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
backlight_ws2812_sendarray();
|
||||||
|
mode_run_light_cnt++;
|
||||||
|
if(mode_run_light_cnt >= LEN_WS2812/2){
|
||||||
|
mode_run_light=false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t s1_cnt=0;
|
||||||
|
void backlight_event_1s(void){
|
||||||
|
// LED WS2812
|
||||||
|
|
||||||
|
if(mode == mode_demo){
|
||||||
|
uint8_t modes = 6;
|
||||||
|
if(!mode_run_light){
|
||||||
|
if((s1_cnt % modes) == 0){
|
||||||
|
for(uint16_t i=0; i < LEN_WS2812;i++){
|
||||||
|
led_data[0 + i*3] = 0xff;
|
||||||
|
led_data[1 + i*3] = 0xff;
|
||||||
|
led_data[2 + i*3] = 0xff;
|
||||||
|
}
|
||||||
|
}else if((s1_cnt % modes) == 1){
|
||||||
|
for(uint16_t i=0; i < LEN_WS2812;i++){
|
||||||
|
led_data[0 + i*3] = 0xff;
|
||||||
|
led_data[1 + i*3] = 0x00;
|
||||||
|
led_data[2 + i*3] = 0x00;
|
||||||
|
}
|
||||||
|
}else if((s1_cnt % modes) == 2){
|
||||||
|
for(uint16_t i=0; i < LEN_WS2812;i++){
|
||||||
|
led_data[0 + i*3] = 0x00;
|
||||||
|
led_data[1 + i*3] = 0xff;
|
||||||
|
led_data[2 + i*3] = 0x00;
|
||||||
|
}
|
||||||
|
}else if((s1_cnt % modes) == 3){
|
||||||
|
for(uint16_t i=0; i < LEN_WS2812;i++){
|
||||||
|
led_data[0 + i*3] = 0x00;
|
||||||
|
led_data[1 + i*3] = 0x00;
|
||||||
|
led_data[2 + i*3] = 0xff;
|
||||||
|
}
|
||||||
|
}else if((s1_cnt % modes) == 4){
|
||||||
|
for(uint16_t i=0; i < LEN_WS2812;i++){
|
||||||
|
led_data[0 + i*3] = 0x00;
|
||||||
|
led_data[1 + i*3] = 0x00;
|
||||||
|
led_data[2 + i*3] = 0x00;
|
||||||
|
}
|
||||||
|
}else if((s1_cnt % modes) == 5){
|
||||||
|
mode_run_light=true;
|
||||||
|
mode_run_light_cnt=0;
|
||||||
|
}
|
||||||
|
backlight_ws2812_sendarray();
|
||||||
|
s1_cnt++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void backlight_mode_demo(void){
|
||||||
|
mode = mode_demo;
|
||||||
|
}
|
||||||
|
|
||||||
|
void backlight_init(void){
|
||||||
|
mode = mode_none;
|
||||||
|
// memset(led_data, 0, sizeof(led_data));
|
||||||
|
backlight_color_show(0,0,0);
|
||||||
|
// for(uint16_t i=0; i < LEN_WS2812*3; i++){
|
||||||
|
// printf("%d: %d\r\n", i, (int)led_data[i]);
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
void backlight_ws2812_sendarray(void){
|
||||||
|
cpu_irq_disable();
|
||||||
|
ws2812_sendarray(led_data,sizeof(led_data));
|
||||||
|
cpu_irq_enable();
|
||||||
|
}
|
||||||
|
|
||||||
|
void backlight_color_show(uint8_t R, uint8_t G, uint8_t B){
|
||||||
|
for(uint16_t i=0; i < LEN_WS2812; i++){
|
||||||
|
led_data[0 + i*3] = G;
|
||||||
|
led_data[1 + i*3] = R;
|
||||||
|
led_data[2 + i*3] = B;
|
||||||
|
// printf("%d: R: %d, G: %d, B: %d\r\n",(int)i, (int)led_data[1 + i*3], (int)led_data[0 + i*3], (int)led_data[2 + i*3]);
|
||||||
|
}
|
||||||
|
backlight_ws2812_sendarray();
|
||||||
|
}
|
||||||
|
|
@ -4,9 +4,11 @@
|
||||||
* Created: 04.01.2021 0:51:07
|
* Created: 04.01.2021 0:51:07
|
||||||
* Author: Lexus
|
* Author: Lexus
|
||||||
*/
|
*/
|
||||||
#include <dac.h>
|
|
||||||
#include "dac_user.h"
|
#include "dac_user.h"
|
||||||
|
#include <asf.h>
|
||||||
|
|
||||||
struct dac_module dac_instance;
|
struct dac_module dac_instance;
|
||||||
|
|
||||||
void configure_dac_channel(void)
|
void configure_dac_channel(void)
|
||||||
{
|
{
|
||||||
struct dac_chan_config config_dac_chan;
|
struct dac_chan_config config_dac_chan;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,128 @@
|
||||||
|
/*
|
||||||
|
* dht.c
|
||||||
|
*
|
||||||
|
* Created: 04.01.2021 21:06:09
|
||||||
|
* Author: Lexus
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "dht.h"
|
||||||
|
|
||||||
|
#define lineDown() port_pin_set_output_level(DHT_Pin, 0)
|
||||||
|
#define lineUp() port_pin_set_output_level(DHT_Pin, 1)
|
||||||
|
#define getLine() port_pin_get_input_level(DHT_Pin)
|
||||||
|
#define Delay(d) delay_ms(d)
|
||||||
|
|
||||||
|
#define CPU_IRQ_enable() cpu_irq_enable()
|
||||||
|
#define CPU_IRQ_disable() cpu_irq_disable()
|
||||||
|
extern struct measured_params m_params;
|
||||||
|
static void goToOutput(void) {
|
||||||
|
|
||||||
|
// ïî óìîë÷àíèþ íà ëèíèè âûñîêèé óðîâåíü
|
||||||
|
port_pin_set_output_level(DHT_Pin, 1);
|
||||||
|
|
||||||
|
struct port_config config_port_pin;
|
||||||
|
port_get_config_defaults(&config_port_pin);
|
||||||
|
config_port_pin.direction = PORT_PIN_DIR_OUTPUT;
|
||||||
|
config_port_pin.input_pull = PORT_PIN_PULL_NONE;
|
||||||
|
port_pin_set_config(DHT_Pin, &config_port_pin);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void goToInput(void) {
|
||||||
|
struct port_config config_port_pin;
|
||||||
|
port_get_config_defaults(&config_port_pin);
|
||||||
|
config_port_pin.direction = PORT_PIN_DIR_INPUT;
|
||||||
|
config_port_pin.input_pull = PORT_PIN_PULL_NONE;
|
||||||
|
port_pin_set_config(DHT_Pin, &config_port_pin);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t DHT_getData(DHT_type t, DHT_data* p_data){
|
||||||
|
uint8_t ret;
|
||||||
|
CPU_IRQ_disable();
|
||||||
|
ret = _DHT_getData(t, p_data);
|
||||||
|
CPU_IRQ_enable();
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t _DHT_getData(DHT_type t, DHT_data* p_data) {
|
||||||
|
p_data->hum=0.0f;
|
||||||
|
p_data->temp=0.0f;
|
||||||
|
|
||||||
|
|
||||||
|
/* Çàïðîñ äàííûõ ó äàò÷èêà */
|
||||||
|
//Ïåðåâîä ïèíà "íà âûõîä"
|
||||||
|
goToOutput();
|
||||||
|
//Îïóñêàíèå ëèíèè äàííûõ íà 15 ìñ
|
||||||
|
lineDown();
|
||||||
|
Delay(15);
|
||||||
|
//Ïîäú¸ì ëèíèè, ïåðåâîä ïîðòà "íà âõîä"
|
||||||
|
lineUp();
|
||||||
|
goToInput();
|
||||||
|
|
||||||
|
/* Îæèäàíèå îòâåòà îò äàò÷èêà */
|
||||||
|
uint32_t timeout = 0;
|
||||||
|
//Îæèäàíèå ñïàäà
|
||||||
|
while(getLine()) {
|
||||||
|
timeout++;
|
||||||
|
if (timeout > DHT_timeout) return 0x01;
|
||||||
|
}
|
||||||
|
timeout = 0;
|
||||||
|
//Îæèäàíèå ïîäú¸ìà
|
||||||
|
while(!getLine()) {
|
||||||
|
timeout++;
|
||||||
|
if (timeout > DHT_timeout) return 0x02;
|
||||||
|
}
|
||||||
|
timeout = 0;
|
||||||
|
//Îæèäàíèå ñïàäà
|
||||||
|
while(getLine()) {
|
||||||
|
timeout++;
|
||||||
|
if (timeout > DHT_timeout) return 0x03;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ×òåíèå îòâåòà îò äàò÷èêà */
|
||||||
|
uint8_t rawData[5] = {0,0,0,0,0};
|
||||||
|
for(uint8_t a = 0; a < 5; a++) {
|
||||||
|
for(uint8_t b = 7; b != 255; b--) {
|
||||||
|
uint32_t hT = 0, lT = 0;
|
||||||
|
//Ïîêà ëèíèÿ â íèçêîì óðîâíå, èíêðåìåíò ïåðåìåííîé lT
|
||||||
|
while(!getLine()) lT++;
|
||||||
|
//Ïîêà ëèíèÿ â âûñîêîì óðîâíå, èíêðåìåíò ïåðåìåííîé hT
|
||||||
|
while(getLine()) hT++;
|
||||||
|
//Åñëè hT áîëüøå lT, òî ïðèøëà åäèíèöà
|
||||||
|
if(hT > lT) rawData[a] |= (1<<b);
|
||||||
|
// printf("DEBUG: %d, %d]r]n",(int)hT, (int)lT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* Ïðîâåðêà öåëîñòíîñòè äàííûõ */
|
||||||
|
if((uint8_t)(rawData[0] + rawData[1] + rawData[2] + rawData[3]) == rawData[4]) {
|
||||||
|
//Åñëè êîíòðîëüíàÿ ñóììà ñîâïàäàåò, òî êîíâåðòàöèÿ è âîçâðàò ïîëó÷åííûõ çíà÷åíèé
|
||||||
|
if (t == DHT22) {
|
||||||
|
p_data->hum = (float)(((uint16_t)rawData[0]<<8) | rawData[1])*0.1f;
|
||||||
|
//Ïðîâåðêà íà îòðèöàòåëüíîñòü òåìïåðàòóðû
|
||||||
|
if(!(rawData[2] & (1<<7))) {
|
||||||
|
p_data->temp = (float)(((uint16_t)rawData[2]<<8) | rawData[3])*0.1f;
|
||||||
|
} else {
|
||||||
|
rawData[2] &= ~(1<<7);
|
||||||
|
p_data->temp = (float)(((uint16_t)rawData[2]<<8) | rawData[3])*-0.1f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (t == DHT11) {
|
||||||
|
p_data->hum = (float)rawData[0];
|
||||||
|
p_data->temp = (float)rawData[2];
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
return 0x04;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void measurement_DHT22(){
|
||||||
|
DHT_data d;
|
||||||
|
uint8_t ret = DHT_getData(DHT22, &d);
|
||||||
|
if(ret){
|
||||||
|
printf("DHT22 error: %d\r\n",(int)ret);
|
||||||
|
}else{
|
||||||
|
m_params.DHT22_Temp = d.temp;
|
||||||
|
m_params.DHT22_Hum = d.hum;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,128 @@
|
||||||
|
/*
|
||||||
|
* light weight WS2812 lib - ARM Cortex M0/M0+ version
|
||||||
|
*
|
||||||
|
* Created: 07.07.2013
|
||||||
|
* Author: Tim (cpldcpu@gmail.com)
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "light_ws2812_cortex.h"
|
||||||
|
/*
|
||||||
|
* The total length of each bit is 1.25µs (25 cycles @ 20Mhz)
|
||||||
|
* At 0µs the dataline is pulled high.
|
||||||
|
* To send a zero the dataline is pulled low after 0.375µs
|
||||||
|
* To send a one the dataline is pulled low after 0.625µs
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define ws2812_ctot (((F_CPU/1000)*1250)/1000000)
|
||||||
|
#define ws2812_t1 (((F_CPU/1000)*375 )/1000000) // floor
|
||||||
|
#define ws2812_t2 (((F_CPU/1000)*625+500000)/1000000) // ceil
|
||||||
|
|
||||||
|
#define w1 (ws2812_t1-2)
|
||||||
|
#define w2 (ws2812_t2-ws2812_t1-2)
|
||||||
|
#define w3 (ws2812_ctot-ws2812_t2-5)
|
||||||
|
|
||||||
|
#define ws2812_DEL1 " nop \n\t"
|
||||||
|
#define ws2812_DEL2 ws2812_DEL1 ws2812_DEL1
|
||||||
|
//#define ws2812_DEL2 " b .+2 \n\t"
|
||||||
|
#define ws2812_DEL4 ws2812_DEL2 ws2812_DEL2
|
||||||
|
#define ws2812_DEL8 ws2812_DEL4 ws2812_DEL4
|
||||||
|
#define ws2812_DEL16 ws2812_DEL8 ws2812_DEL8
|
||||||
|
|
||||||
|
#define ws2812_DEL ws2812_DEL8 ws2812_DEL2
|
||||||
|
|
||||||
|
|
||||||
|
void ws2812_sendarray(uint8_t *data,int datlen)
|
||||||
|
{
|
||||||
|
uint8_t gpio_pin = PIN_PA23;
|
||||||
|
PortGroup *const port_base = port_get_group_from_gpio_pin(gpio_pin);
|
||||||
|
uint32_t pin_mask = (1UL << (gpio_pin % 32));
|
||||||
|
|
||||||
|
uint32_t maskhi = pin_mask;
|
||||||
|
uint32_t masklo = pin_mask;
|
||||||
|
volatile uint32_t *set = &port_base->OUTSET.reg;
|
||||||
|
volatile uint32_t *clr = &port_base->OUTCLR.reg;
|
||||||
|
uint32_t i=0;
|
||||||
|
uint32_t curbyte;
|
||||||
|
|
||||||
|
while (datlen--) {
|
||||||
|
curbyte=*data++;
|
||||||
|
|
||||||
|
asm volatile(
|
||||||
|
" lsl %[dat],#24 \n\t"
|
||||||
|
" movs %[ctr],#8 \n\t"
|
||||||
|
"ilop%=: \n\t"
|
||||||
|
" lsl %[dat], #1 \n\t"
|
||||||
|
" str %[maskhi], [%[set]] \n\t"
|
||||||
|
ws2812_DEL
|
||||||
|
// ws2812_DEL19
|
||||||
|
/*
|
||||||
|
#if (w1&1)
|
||||||
|
ws2812_DEL1
|
||||||
|
#endif
|
||||||
|
#if (w1&2)
|
||||||
|
ws2812_DEL2
|
||||||
|
#endif
|
||||||
|
#if (w1&4)
|
||||||
|
ws2812_DEL4
|
||||||
|
#endif
|
||||||
|
#if (w1&8)
|
||||||
|
ws2812_DEL8
|
||||||
|
#endif
|
||||||
|
#if (w1&16)
|
||||||
|
ws2812_DEL16
|
||||||
|
#endif
|
||||||
|
*/
|
||||||
|
" bcs one%= \n\t"
|
||||||
|
" str %[masklo], [%[clr]] \n\t"
|
||||||
|
"one%=: \n\t"
|
||||||
|
|
||||||
|
ws2812_DEL
|
||||||
|
|
||||||
|
/*
|
||||||
|
#if (w2&1)
|
||||||
|
ws2812_DEL1
|
||||||
|
#endif
|
||||||
|
#if (w2&2)
|
||||||
|
ws2812_DEL2
|
||||||
|
#endif
|
||||||
|
#if (w2&4)
|
||||||
|
ws2812_DEL4
|
||||||
|
#endif
|
||||||
|
#if (w2&8)
|
||||||
|
ws2812_DEL8
|
||||||
|
#endif
|
||||||
|
#if (w2&16)
|
||||||
|
ws2812_DEL16
|
||||||
|
#endif
|
||||||
|
*/
|
||||||
|
" sub %[ctr], #1 \n\t"
|
||||||
|
" str %[masklo], [%[clr]] \n\t"
|
||||||
|
" beq end%= \n\t"
|
||||||
|
|
||||||
|
ws2812_DEL
|
||||||
|
|
||||||
|
/*
|
||||||
|
#if (w3&1)
|
||||||
|
ws2812_DEL1
|
||||||
|
#endif
|
||||||
|
#if (w3&2)
|
||||||
|
ws2812_DEL2
|
||||||
|
#endif
|
||||||
|
#if (w3&4)
|
||||||
|
ws2812_DEL4
|
||||||
|
#endif
|
||||||
|
#if (w3&8)
|
||||||
|
ws2812_DEL8
|
||||||
|
#endif
|
||||||
|
#if (w3&16)
|
||||||
|
ws2812_DEL16
|
||||||
|
#endif
|
||||||
|
*/
|
||||||
|
|
||||||
|
" b ilop%= \n\t"
|
||||||
|
"end%=: \n\t"
|
||||||
|
: [ctr] "+r" (i)
|
||||||
|
: [dat] "r" (curbyte), [set] "r" (set), [clr] "r" (clr), [masklo] "r" (masklo), [maskhi] "r" (maskhi)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,77 @@
|
||||||
|
/*
|
||||||
|
* ntc.c
|
||||||
|
*
|
||||||
|
* Created: 04.01.2021 18:57:53
|
||||||
|
* Author: Lexus
|
||||||
|
*/
|
||||||
|
#include "ntc.h"
|
||||||
|
#include <arm_math.h>
|
||||||
|
#include "adc_user.h"
|
||||||
|
|
||||||
|
#define MCU_CONTROL
|
||||||
|
// ADC value to R
|
||||||
|
float NTC_MCU_value2R(uint16_t value)
|
||||||
|
{
|
||||||
|
float R10 = 17800.0;
|
||||||
|
float R11 = 7680.0;
|
||||||
|
|
||||||
|
float Q = adc_get_Q(value);
|
||||||
|
|
||||||
|
return ((R10*Q)/(1 - Q) - R11);
|
||||||
|
}
|
||||||
|
|
||||||
|
float NTC_TEC_value2R(uint16_t value)
|
||||||
|
{
|
||||||
|
#ifdef MCU_CONTROL
|
||||||
|
float R32 = 17800.0;
|
||||||
|
float R36 = 7680.0;
|
||||||
|
float Q = adc_get_Q(value);
|
||||||
|
|
||||||
|
return ((R32*Q)/(1 - Q) - R36);
|
||||||
|
#else
|
||||||
|
float R36 = 7680.0;
|
||||||
|
float Uref = 2.5/2.;
|
||||||
|
float Uvcc = 3.3;
|
||||||
|
float Q = adc_get_Q(value);
|
||||||
|
|
||||||
|
return R36/(Uref/(Q*Uvcc) - 1);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
// Resistance to Temp
|
||||||
|
float NTC_R2T(float R)
|
||||||
|
{
|
||||||
|
float K0 = 273.15;
|
||||||
|
float T0 = 25.0 + K0;
|
||||||
|
float R0 = 10000.0;
|
||||||
|
|
||||||
|
float B = 3863.737706;
|
||||||
|
return (1.0/((log(R/R0)/B) + (1/T0)) - K0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read ADC and calculate temperature in Cenlsius.
|
||||||
|
float NTC_MCU_get_temp(void)
|
||||||
|
{
|
||||||
|
uint16_t adc_val = adc_read_value_spec(chan_NTC_MCU);
|
||||||
|
|
||||||
|
float R = NTC_MCU_value2R(adc_val);
|
||||||
|
float t = NTC_R2T(R);
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
float NTC_TEC_get_temp(uint16_t *p_value, float *p_R)
|
||||||
|
{
|
||||||
|
uint16_t adc_val = adc_read_value_spec(chan_NTC_TEC);
|
||||||
|
|
||||||
|
if(p_value){
|
||||||
|
*p_value = adc_val;
|
||||||
|
}
|
||||||
|
|
||||||
|
float R = NTC_TEC_value2R(adc_val);
|
||||||
|
|
||||||
|
if(p_R){
|
||||||
|
*p_R = R;
|
||||||
|
}
|
||||||
|
float t = NTC_R2T(R);
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
@ -5,8 +5,8 @@
|
||||||
* Author: Lexus
|
* Author: Lexus
|
||||||
*/
|
*/
|
||||||
#include "realsence.h"
|
#include "realsence.h"
|
||||||
#include "port.h"
|
|
||||||
#include "conf_board.h"
|
#include "conf_board.h"
|
||||||
|
|
||||||
bool rs_power;
|
bool rs_power;
|
||||||
|
|
||||||
void rs_configure_port_pins(void)
|
void rs_configure_port_pins(void)
|
||||||
|
|
@ -18,7 +18,7 @@ void rs_configure_port_pins(void)
|
||||||
port_pin_set_config(PIN_RS_POWER, &config_port_pin);
|
port_pin_set_config(PIN_RS_POWER, &config_port_pin);
|
||||||
}
|
}
|
||||||
|
|
||||||
void rs_set(_Bool value){
|
void rs_set(bool value){
|
||||||
port_pin_set_output_level(PIN_RS_POWER, value?0:1);
|
port_pin_set_output_level(PIN_RS_POWER, value?0:1);
|
||||||
rs_power = value;
|
rs_power = value;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,124 @@
|
||||||
|
/*
|
||||||
|
* tec.c
|
||||||
|
*
|
||||||
|
* Created: 04.01.2021 17:08:34
|
||||||
|
* Author: Lexus
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "tec.h"
|
||||||
|
#include <arm_math.h>
|
||||||
|
#include "adc_user.h"
|
||||||
|
#include "dac_user.h"
|
||||||
|
struct tcc_module tcc_instance;
|
||||||
|
extern struct dac_module dac_instance;
|
||||||
|
bool VTEC_read(float *p_Vin, float *p_VTEC){
|
||||||
|
float Vin= adc_get_V_spec(chan_VTEC);
|
||||||
|
if(p_Vin){
|
||||||
|
*p_Vin = Vin;
|
||||||
|
}
|
||||||
|
if(p_VTEC){
|
||||||
|
//float K __attribute__((used)) =3.67 ;
|
||||||
|
// *p_VTEC = ((Vin - 1.25)*K)/0.25;
|
||||||
|
*p_VTEC = ((Vin - 1.25))/0.25;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ITEC_read(float *p_Vin, float *p_ITEC){
|
||||||
|
float Vin= adc_get_V_spec(chan_ITEC);
|
||||||
|
if(p_Vin){
|
||||||
|
*p_Vin = Vin;
|
||||||
|
}
|
||||||
|
if(p_ITEC){
|
||||||
|
float Rsense = 0.005;
|
||||||
|
*p_ITEC = (Vin-1.25)/(25*Rsense);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TEC_L_set(bool value){
|
||||||
|
|
||||||
|
// switch off
|
||||||
|
pin_set_output(PIN_LPGATE, true, 1);
|
||||||
|
pin_set_output(PIN_LNGATE, true, 0);
|
||||||
|
|
||||||
|
if(value){
|
||||||
|
// L to +12
|
||||||
|
pin_set_output(PIN_LPGATE, true, 0);
|
||||||
|
}else{
|
||||||
|
// L to GND
|
||||||
|
pin_set_output(PIN_LNGATE, true, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void pin_set_output(uint8_t pin, bool output_flag, uint8_t value){
|
||||||
|
|
||||||
|
struct port_config config_port_pin;
|
||||||
|
port_get_config_defaults(&config_port_pin);
|
||||||
|
if(output_flag){
|
||||||
|
port_pin_set_output_level(pin, value);
|
||||||
|
config_port_pin.direction = PORT_PIN_DIR_OUTPUT;
|
||||||
|
}else{
|
||||||
|
config_port_pin.direction = PORT_PIN_DIR_INPUT;
|
||||||
|
}
|
||||||
|
config_port_pin.input_pull = PORT_PIN_PULL_NONE;
|
||||||
|
port_pin_set_config(pin, &config_port_pin);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Range from -1 to 0
|
||||||
|
void TEC_set_level(float value){
|
||||||
|
tcc_reset(&tcc_instance);
|
||||||
|
if(fpclassify(value) == FP_ZERO){//if(value == (float)0.0){//
|
||||||
|
// TEC OFF
|
||||||
|
pin_set_output(PIN_SPGATE, true, 1);
|
||||||
|
pin_set_output(PIN_SNGATE, true, 0);
|
||||||
|
pin_set_output(PIN_LPGATE, true, 1);
|
||||||
|
pin_set_output(PIN_LNGATE, true, 0);
|
||||||
|
}else{
|
||||||
|
struct port_config config_port_pin;
|
||||||
|
port_get_config_defaults(&config_port_pin);
|
||||||
|
config_port_pin.direction = PORT_PIN_DIR_INPUT;
|
||||||
|
config_port_pin.input_pull = PORT_PIN_PULL_NONE;
|
||||||
|
port_pin_set_config(PIN_SNGATE, &config_port_pin);
|
||||||
|
|
||||||
|
struct tcc_config config_tcc;
|
||||||
|
tcc_get_config_defaults(&config_tcc, CONF_PWM_MODULE);
|
||||||
|
config_tcc.counter.clock_prescaler = TCC_CLOCK_PRESCALER_DIV1;
|
||||||
|
config_tcc.counter.period = PWM_GCLK_PERIOD;
|
||||||
|
|
||||||
|
config_tcc.compare.wave_generation = TCC_WAVE_GENERATION_SINGLE_SLOPE_PWM;
|
||||||
|
|
||||||
|
uint8_t pin_output, chan;
|
||||||
|
if(value > 0.0){
|
||||||
|
TEC_L_set(true); // to +12
|
||||||
|
pin_set_output(PIN_SPGATE, true, 1);
|
||||||
|
pin_set_output(PIN_SNGATE, false, 0);
|
||||||
|
pin_output=7;
|
||||||
|
chan=3;
|
||||||
|
config_tcc.pins.wave_out_pin[pin_output] = PIN_PA17F_TCC0_WO7;
|
||||||
|
config_tcc.pins.wave_out_pin_mux[pin_output] = MUX_PA17F_TCC0_WO7;
|
||||||
|
|
||||||
|
config_tcc.compare.match[chan] = PWM_GCLK_PERIOD*value;
|
||||||
|
}else{
|
||||||
|
TEC_L_set(false); // to GND
|
||||||
|
pin_set_output(PIN_SPGATE, false, 0);
|
||||||
|
pin_set_output(PIN_SNGATE, true, 0);
|
||||||
|
pin_output=6;
|
||||||
|
chan=2;
|
||||||
|
config_tcc.pins.wave_out_pin[pin_output] = PIN_PA16F_TCC0_WO6;
|
||||||
|
config_tcc.pins.wave_out_pin_mux[pin_output] = MUX_PA16F_TCC0_WO6;
|
||||||
|
config_tcc.compare.match[chan] = PWM_GCLK_PERIOD*value*(-1.0);
|
||||||
|
config_tcc.wave_ext.invert[pin_output]=true;
|
||||||
|
}
|
||||||
|
config_tcc.pins.enable_wave_out_pin[pin_output] = true;
|
||||||
|
tcc_init(&tcc_instance, CONF_PWM_MODULE, &config_tcc);
|
||||||
|
tcc_enable(&tcc_instance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TEC_set_TEMPSET_volt(float value)
|
||||||
|
{
|
||||||
|
float Uref=3.3;
|
||||||
|
uint16_t dig_value = (value*1024)/Uref;
|
||||||
|
dac_chan_write(&dac_instance, DAC_CHANNEL_0, dig_value);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,420 @@
|
||||||
|
/**
|
||||||
|
* |----------------------------------------------------------------------
|
||||||
|
* | Copyright (c) 2016 Tilen Majerle
|
||||||
|
* |
|
||||||
|
* | Permission is hereby granted, free of charge, to any person
|
||||||
|
* | obtaining a copy of this software and associated documentation
|
||||||
|
* | files (the "Software"), to deal in the Software without restriction,
|
||||||
|
* | including without limitation the rights to use, copy, modify, merge,
|
||||||
|
* | publish, distribute, sublicense, and/or sell copies of the Software,
|
||||||
|
* | and to permit persons to whom the Software is furnished to do so,
|
||||||
|
* | subject to the following conditions:
|
||||||
|
* |
|
||||||
|
* | The above copyright notice and this permission notice shall be
|
||||||
|
* | included in all copies or substantial portions of the Software.
|
||||||
|
* |
|
||||||
|
* | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||||
|
* | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* | AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||||
|
* | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||||
|
* | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
* | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||||
|
* | OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
* |----------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
#include "tm_ds18b20.h"
|
||||||
|
TM_OneWire_t ow_instance;
|
||||||
|
extern struct measured_params m_params;
|
||||||
|
uint8_t TM_DS18B20_Start(TM_OneWire_t* OneWire, uint8_t *ROM) {
|
||||||
|
/* Check if device is DS18B20 */
|
||||||
|
if (!TM_DS18B20_Is(ROM)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Reset line */
|
||||||
|
TM_OneWire_Reset(OneWire);
|
||||||
|
/* Select ROM number */
|
||||||
|
TM_OneWire_SelectWithPointer(OneWire, ROM);
|
||||||
|
/* Start temperature conversion */
|
||||||
|
TM_OneWire_WriteByte(OneWire, DS18B20_CMD_CONVERTTEMP);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TM_DS18B20_StartAll(TM_OneWire_t* OneWire) {
|
||||||
|
/* Reset pulse */
|
||||||
|
TM_OneWire_Reset(OneWire);
|
||||||
|
/* Skip rom */
|
||||||
|
TM_OneWire_WriteByte(OneWire, ONEWIRE_CMD_SKIPROM);
|
||||||
|
/* Start conversion on all connected devices */
|
||||||
|
TM_OneWire_WriteByte(OneWire, DS18B20_CMD_CONVERTTEMP);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t TM_DS18B20_Read(TM_OneWire_t* OneWire, uint8_t *ROM, float *destination) {
|
||||||
|
uint16_t temperature;
|
||||||
|
uint8_t resolution;
|
||||||
|
int8_t digit, minus = 0;
|
||||||
|
float decimal;
|
||||||
|
uint8_t i = 0;
|
||||||
|
uint8_t data[9];
|
||||||
|
uint8_t crc;
|
||||||
|
|
||||||
|
/* Check if device is DS18B20 */
|
||||||
|
if (!TM_DS18B20_Is(ROM)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check if line is released, if it is, then conversion is complete */
|
||||||
|
if (!TM_OneWire_ReadBit(OneWire)) {
|
||||||
|
/* Conversion is not finished yet */
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Reset line */
|
||||||
|
TM_OneWire_Reset(OneWire);
|
||||||
|
/* Select ROM number */
|
||||||
|
TM_OneWire_SelectWithPointer(OneWire, ROM);
|
||||||
|
/* Read scratchpad command by onewire protocol */
|
||||||
|
TM_OneWire_WriteByte(OneWire, ONEWIRE_CMD_RSCRATCHPAD);
|
||||||
|
|
||||||
|
/* Get data */
|
||||||
|
for (i = 0; i < 9; i++) {
|
||||||
|
/* Read byte by byte */
|
||||||
|
data[i] = TM_OneWire_ReadByte(OneWire);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Calculate CRC */
|
||||||
|
crc = TM_OneWire_CRC8(data, 8);
|
||||||
|
|
||||||
|
/* Check if CRC is ok */
|
||||||
|
if (crc != data[8]) {
|
||||||
|
/* CRC invalid */
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* First two bytes of scratchpad are temperature values */
|
||||||
|
temperature = data[0] | (data[1] << 8);
|
||||||
|
|
||||||
|
/* Reset line */
|
||||||
|
TM_OneWire_Reset(OneWire);
|
||||||
|
|
||||||
|
/* Check if temperature is negative */
|
||||||
|
if (temperature & 0x8000) {
|
||||||
|
/* Two's complement, temperature is negative */
|
||||||
|
temperature = ~temperature + 1;
|
||||||
|
minus = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Get sensor resolution */
|
||||||
|
resolution = ((data[4] & 0x60) >> 5) + 9;
|
||||||
|
|
||||||
|
|
||||||
|
/* Store temperature integer digits and decimal digits */
|
||||||
|
digit = temperature >> 4;
|
||||||
|
digit |= ((temperature >> 8) & 0x7) << 4;
|
||||||
|
|
||||||
|
/* Store decimal digits */
|
||||||
|
switch (resolution) {
|
||||||
|
case 9: {
|
||||||
|
decimal = (temperature >> 3) & 0x01;
|
||||||
|
decimal *= (float)DS18B20_DECIMAL_STEPS_9BIT;
|
||||||
|
} break;
|
||||||
|
case 10: {
|
||||||
|
decimal = (temperature >> 2) & 0x03;
|
||||||
|
decimal *= (float)DS18B20_DECIMAL_STEPS_10BIT;
|
||||||
|
} break;
|
||||||
|
case 11: {
|
||||||
|
decimal = (temperature >> 1) & 0x07;
|
||||||
|
decimal *= (float)DS18B20_DECIMAL_STEPS_11BIT;
|
||||||
|
} break;
|
||||||
|
case 12: {
|
||||||
|
decimal = temperature & 0x0F;
|
||||||
|
decimal *= (float)DS18B20_DECIMAL_STEPS_12BIT;
|
||||||
|
} break;
|
||||||
|
default: {
|
||||||
|
decimal = 0xFF;
|
||||||
|
digit = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check for negative part */
|
||||||
|
decimal = digit + decimal;
|
||||||
|
if (minus) {
|
||||||
|
decimal = 0 - decimal;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set to pointer */
|
||||||
|
*destination = decimal;
|
||||||
|
|
||||||
|
/* Return 1, temperature valid */
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t TM_DS18B20_GetResolution(TM_OneWire_t* OneWire, uint8_t *ROM) {
|
||||||
|
uint8_t conf;
|
||||||
|
|
||||||
|
if (!TM_DS18B20_Is(ROM)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Reset line */
|
||||||
|
TM_OneWire_Reset(OneWire);
|
||||||
|
/* Select ROM number */
|
||||||
|
TM_OneWire_SelectWithPointer(OneWire, ROM);
|
||||||
|
/* Read scratchpad command by onewire protocol */
|
||||||
|
TM_OneWire_WriteByte(OneWire, ONEWIRE_CMD_RSCRATCHPAD);
|
||||||
|
|
||||||
|
/* Ignore first 4 bytes */
|
||||||
|
TM_OneWire_ReadByte(OneWire);
|
||||||
|
TM_OneWire_ReadByte(OneWire);
|
||||||
|
TM_OneWire_ReadByte(OneWire);
|
||||||
|
TM_OneWire_ReadByte(OneWire);
|
||||||
|
|
||||||
|
/* 5th byte of scratchpad is configuration register */
|
||||||
|
conf = TM_OneWire_ReadByte(OneWire);
|
||||||
|
|
||||||
|
/* Return 9 - 12 value according to number of bits */
|
||||||
|
return ((conf & 0x60) >> 5) + 9;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t TM_DS18B20_SetResolution(TM_OneWire_t* OneWire, uint8_t *ROM, TM_DS18B20_Resolution_t resolution) {
|
||||||
|
uint8_t th, tl, conf;
|
||||||
|
if (!TM_DS18B20_Is(ROM)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Reset line */
|
||||||
|
TM_OneWire_Reset(OneWire);
|
||||||
|
/* Select ROM number */
|
||||||
|
TM_OneWire_SelectWithPointer(OneWire, ROM);
|
||||||
|
/* Read scratchpad command by onewire protocol */
|
||||||
|
TM_OneWire_WriteByte(OneWire, ONEWIRE_CMD_RSCRATCHPAD);
|
||||||
|
|
||||||
|
/* Ignore first 2 bytes */
|
||||||
|
TM_OneWire_ReadByte(OneWire);
|
||||||
|
TM_OneWire_ReadByte(OneWire);
|
||||||
|
|
||||||
|
th = TM_OneWire_ReadByte(OneWire);
|
||||||
|
tl = TM_OneWire_ReadByte(OneWire);
|
||||||
|
conf = TM_OneWire_ReadByte(OneWire);
|
||||||
|
|
||||||
|
if (resolution == TM_DS18B20_Resolution_9bits) {
|
||||||
|
conf &= ~(1 << DS18B20_RESOLUTION_R1);
|
||||||
|
conf &= ~(1 << DS18B20_RESOLUTION_R0);
|
||||||
|
} else if (resolution == TM_DS18B20_Resolution_10bits) {
|
||||||
|
conf &= ~(1 << DS18B20_RESOLUTION_R1);
|
||||||
|
conf |= 1 << DS18B20_RESOLUTION_R0;
|
||||||
|
} else if (resolution == TM_DS18B20_Resolution_11bits) {
|
||||||
|
conf |= 1 << DS18B20_RESOLUTION_R1;
|
||||||
|
conf &= ~(1 << DS18B20_RESOLUTION_R0);
|
||||||
|
} else if (resolution == TM_DS18B20_Resolution_12bits) {
|
||||||
|
conf |= 1 << DS18B20_RESOLUTION_R1;
|
||||||
|
conf |= 1 << DS18B20_RESOLUTION_R0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Reset line */
|
||||||
|
TM_OneWire_Reset(OneWire);
|
||||||
|
/* Select ROM number */
|
||||||
|
TM_OneWire_SelectWithPointer(OneWire, ROM);
|
||||||
|
/* Write scratchpad command by onewire protocol, only th, tl and conf register can be written */
|
||||||
|
TM_OneWire_WriteByte(OneWire, ONEWIRE_CMD_WSCRATCHPAD);
|
||||||
|
|
||||||
|
/* Write bytes */
|
||||||
|
TM_OneWire_WriteByte(OneWire, th);
|
||||||
|
TM_OneWire_WriteByte(OneWire, tl);
|
||||||
|
TM_OneWire_WriteByte(OneWire, conf);
|
||||||
|
|
||||||
|
/* Reset line */
|
||||||
|
TM_OneWire_Reset(OneWire);
|
||||||
|
/* Select ROM number */
|
||||||
|
TM_OneWire_SelectWithPointer(OneWire, ROM);
|
||||||
|
/* Copy scratchpad to EEPROM of DS18B20 */
|
||||||
|
TM_OneWire_WriteByte(OneWire, ONEWIRE_CMD_CPYSCRATCHPAD);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t TM_DS18B20_Is(uint8_t *ROM) {
|
||||||
|
/* Checks if first byte is equal to DS18B20's family code */
|
||||||
|
if (*ROM == DS18B20_FAMILY_CODE) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t TM_DS18B20_SetAlarmLowTemperature(TM_OneWire_t* OneWire, uint8_t *ROM, int8_t temp) {
|
||||||
|
uint8_t tl, th, conf;
|
||||||
|
if (!TM_DS18B20_Is(ROM)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (temp > 125) {
|
||||||
|
temp = 125;
|
||||||
|
}
|
||||||
|
if (temp < -55) {
|
||||||
|
temp = -55;
|
||||||
|
}
|
||||||
|
/* Reset line */
|
||||||
|
TM_OneWire_Reset(OneWire);
|
||||||
|
/* Select ROM number */
|
||||||
|
TM_OneWire_SelectWithPointer(OneWire, ROM);
|
||||||
|
/* Read scratchpad command by onewire protocol */
|
||||||
|
TM_OneWire_WriteByte(OneWire, ONEWIRE_CMD_RSCRATCHPAD);
|
||||||
|
|
||||||
|
/* Ignore first 2 bytes */
|
||||||
|
TM_OneWire_ReadByte(OneWire);
|
||||||
|
TM_OneWire_ReadByte(OneWire);
|
||||||
|
|
||||||
|
th = TM_OneWire_ReadByte(OneWire);
|
||||||
|
tl = TM_OneWire_ReadByte(OneWire);
|
||||||
|
conf = TM_OneWire_ReadByte(OneWire);
|
||||||
|
|
||||||
|
tl = (uint8_t)temp;
|
||||||
|
|
||||||
|
/* Reset line */
|
||||||
|
TM_OneWire_Reset(OneWire);
|
||||||
|
/* Select ROM number */
|
||||||
|
TM_OneWire_SelectWithPointer(OneWire, ROM);
|
||||||
|
/* Write scratchpad command by onewire protocol, only th, tl and conf register can be written */
|
||||||
|
TM_OneWire_WriteByte(OneWire, ONEWIRE_CMD_WSCRATCHPAD);
|
||||||
|
|
||||||
|
/* Write bytes */
|
||||||
|
TM_OneWire_WriteByte(OneWire, th);
|
||||||
|
TM_OneWire_WriteByte(OneWire, tl);
|
||||||
|
TM_OneWire_WriteByte(OneWire, conf);
|
||||||
|
|
||||||
|
/* Reset line */
|
||||||
|
TM_OneWire_Reset(OneWire);
|
||||||
|
/* Select ROM number */
|
||||||
|
TM_OneWire_SelectWithPointer(OneWire, ROM);
|
||||||
|
/* Copy scratchpad to EEPROM of DS18B20 */
|
||||||
|
TM_OneWire_WriteByte(OneWire, ONEWIRE_CMD_CPYSCRATCHPAD);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t TM_DS18B20_SetAlarmHighTemperature(TM_OneWire_t* OneWire, uint8_t *ROM, int8_t temp) {
|
||||||
|
uint8_t tl, th, conf;
|
||||||
|
if (!TM_DS18B20_Is(ROM)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (temp > 125) {
|
||||||
|
temp = 125;
|
||||||
|
}
|
||||||
|
if (temp < -55) {
|
||||||
|
temp = -55;
|
||||||
|
}
|
||||||
|
/* Reset line */
|
||||||
|
TM_OneWire_Reset(OneWire);
|
||||||
|
/* Select ROM number */
|
||||||
|
TM_OneWire_SelectWithPointer(OneWire, ROM);
|
||||||
|
/* Read scratchpad command by onewire protocol */
|
||||||
|
TM_OneWire_WriteByte(OneWire, ONEWIRE_CMD_RSCRATCHPAD);
|
||||||
|
|
||||||
|
/* Ignore first 2 bytes */
|
||||||
|
TM_OneWire_ReadByte(OneWire);
|
||||||
|
TM_OneWire_ReadByte(OneWire);
|
||||||
|
|
||||||
|
th = TM_OneWire_ReadByte(OneWire);
|
||||||
|
tl = TM_OneWire_ReadByte(OneWire);
|
||||||
|
conf = TM_OneWire_ReadByte(OneWire);
|
||||||
|
|
||||||
|
th = (uint8_t)temp;
|
||||||
|
|
||||||
|
/* Reset line */
|
||||||
|
TM_OneWire_Reset(OneWire);
|
||||||
|
/* Select ROM number */
|
||||||
|
TM_OneWire_SelectWithPointer(OneWire, ROM);
|
||||||
|
/* Write scratchpad command by onewire protocol, only th, tl and conf register can be written */
|
||||||
|
TM_OneWire_WriteByte(OneWire, ONEWIRE_CMD_WSCRATCHPAD);
|
||||||
|
|
||||||
|
/* Write bytes */
|
||||||
|
TM_OneWire_WriteByte(OneWire, th);
|
||||||
|
TM_OneWire_WriteByte(OneWire, tl);
|
||||||
|
TM_OneWire_WriteByte(OneWire, conf);
|
||||||
|
|
||||||
|
/* Reset line */
|
||||||
|
TM_OneWire_Reset(OneWire);
|
||||||
|
/* Select ROM number */
|
||||||
|
TM_OneWire_SelectWithPointer(OneWire, ROM);
|
||||||
|
/* Copy scratchpad to EEPROM of DS18B20 */
|
||||||
|
TM_OneWire_WriteByte(OneWire, ONEWIRE_CMD_CPYSCRATCHPAD);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t TM_DS18B20_DisableAlarmTemperature(TM_OneWire_t* OneWire, uint8_t *ROM) {
|
||||||
|
uint8_t tl, th, conf;
|
||||||
|
if (!TM_DS18B20_Is(ROM)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/* Reset line */
|
||||||
|
TM_OneWire_Reset(OneWire);
|
||||||
|
/* Select ROM number */
|
||||||
|
TM_OneWire_SelectWithPointer(OneWire, ROM);
|
||||||
|
/* Read scratchpad command by onewire protocol */
|
||||||
|
TM_OneWire_WriteByte(OneWire, ONEWIRE_CMD_RSCRATCHPAD);
|
||||||
|
|
||||||
|
/* Ignore first 2 bytes */
|
||||||
|
TM_OneWire_ReadByte(OneWire);
|
||||||
|
TM_OneWire_ReadByte(OneWire);
|
||||||
|
|
||||||
|
th = TM_OneWire_ReadByte(OneWire);
|
||||||
|
tl = TM_OneWire_ReadByte(OneWire);
|
||||||
|
conf = TM_OneWire_ReadByte(OneWire);
|
||||||
|
|
||||||
|
th = 125;
|
||||||
|
tl = (uint8_t)-55;
|
||||||
|
|
||||||
|
/* Reset line */
|
||||||
|
TM_OneWire_Reset(OneWire);
|
||||||
|
/* Select ROM number */
|
||||||
|
TM_OneWire_SelectWithPointer(OneWire, ROM);
|
||||||
|
/* Write scratchpad command by onewire protocol, only th, tl and conf register can be written */
|
||||||
|
TM_OneWire_WriteByte(OneWire, ONEWIRE_CMD_WSCRATCHPAD);
|
||||||
|
|
||||||
|
/* Write bytes */
|
||||||
|
TM_OneWire_WriteByte(OneWire, th);
|
||||||
|
TM_OneWire_WriteByte(OneWire, tl);
|
||||||
|
TM_OneWire_WriteByte(OneWire, conf);
|
||||||
|
|
||||||
|
/* Reset line */
|
||||||
|
TM_OneWire_Reset(OneWire);
|
||||||
|
/* Select ROM number */
|
||||||
|
TM_OneWire_SelectWithPointer(OneWire, ROM);
|
||||||
|
/* Copy scratchpad to EEPROM of DS18B20 */
|
||||||
|
TM_OneWire_WriteByte(OneWire, ONEWIRE_CMD_CPYSCRATCHPAD);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t TM_DS18B20_AlarmSearch(TM_OneWire_t* OneWire) {
|
||||||
|
/* Start alarm search */
|
||||||
|
return TM_OneWire_Search(OneWire, DS18B20_CMD_ALARMSEARCH);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t TM_DS18B20_AllDone(TM_OneWire_t* OneWire) {
|
||||||
|
/* If read bit is low, then device is not finished yet with calculation temperature */
|
||||||
|
return TM_OneWire_ReadBit(OneWire);
|
||||||
|
}
|
||||||
|
|
||||||
|
void measurement_DS1820(void){
|
||||||
|
uint8_t ret;
|
||||||
|
cpu_irq_disable();
|
||||||
|
if (TM_OneWire_First(&ow_instance)) {
|
||||||
|
if(TM_DS18B20_Is(ow_instance.ROM_NO)){
|
||||||
|
if(TM_DS18B20_AllDone(&ow_instance)){
|
||||||
|
ret = TM_DS18B20_Read(&ow_instance, ow_instance.ROM_NO, &m_params.DS1820_Temp);
|
||||||
|
if(!ret){
|
||||||
|
printf("TM_DS18B20_Read() - error\r\n");
|
||||||
|
}
|
||||||
|
ret = TM_DS18B20_Start(&ow_instance, ow_instance.ROM_NO);
|
||||||
|
if(!ret){
|
||||||
|
printf("TM_DS18B20_Start() - ROM isn't correct\r\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cpu_irq_enable();
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,389 @@
|
||||||
|
/**
|
||||||
|
* https://stm32f4-discovery.net/2015/07/hal-library-05-onewire-for-stm32fxxx/
|
||||||
|
* https://github.com/MaJerle/stm32fxxx-hal-libraries/blob/master/06-STM32Fxxx_DS18B20/User/main.c
|
||||||
|
* |----------------------------------------------------------------------
|
||||||
|
* | Copyright (c) 2016 Tilen Majerle
|
||||||
|
* |
|
||||||
|
* | Permission is hereby granted, free of charge, to any person
|
||||||
|
* | obtaining a copy of this software and associated documentation
|
||||||
|
* | files (the "Software"), to deal in the Software without restriction,
|
||||||
|
* | including without limitation the rights to use, copy, modify, merge,
|
||||||
|
* | publish, distribute, sublicense, and/or sell copies of the Software,
|
||||||
|
* | and to permit persons to whom the Software is furnished to do so,
|
||||||
|
* | subject to the following conditions:
|
||||||
|
* |
|
||||||
|
* | The above copyright notice and this permission notice shall be
|
||||||
|
* | included in all copies or substantial portions of the Software.
|
||||||
|
* |
|
||||||
|
* | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||||
|
* | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* | AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||||
|
* | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||||
|
* | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
* | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||||
|
* | OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
* |----------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
#include "tm_onewire.h"
|
||||||
|
|
||||||
|
void ONEWIRE_OUTPUT(TM_OneWire_t* OneWireStruct){
|
||||||
|
// ïî óìîë÷àíèþ íà ëèíèè âûñîêèé óðîâåíü
|
||||||
|
struct port_config config_port_pin;
|
||||||
|
port_get_config_defaults(&config_port_pin);
|
||||||
|
config_port_pin.direction = PORT_PIN_DIR_OUTPUT;
|
||||||
|
config_port_pin.input_pull = PORT_PIN_PULL_NONE;
|
||||||
|
port_pin_set_config(OneWireStruct->GPIO_Pin, &config_port_pin);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ONEWIRE_INPUT(TM_OneWire_t* OneWireStruct){
|
||||||
|
struct port_config config_port_pin;
|
||||||
|
port_get_config_defaults(&config_port_pin);
|
||||||
|
config_port_pin.direction = PORT_PIN_DIR_INPUT;
|
||||||
|
config_port_pin.input_pull = PORT_PIN_PULL_NONE;
|
||||||
|
port_pin_set_config(OneWireStruct->GPIO_Pin, &config_port_pin);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TM_OneWire_Init(TM_OneWire_t* OneWireStruct, uint8_t GPIO_Pin) {
|
||||||
|
|
||||||
|
/* Save settings */
|
||||||
|
OneWireStruct->GPIO_Pin = GPIO_Pin;
|
||||||
|
ONEWIRE_INPUT(OneWireStruct);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t TM_OneWire_Reset(TM_OneWire_t* OneWireStruct) {
|
||||||
|
uint8_t i;
|
||||||
|
|
||||||
|
/* Line low, and wait 480us */
|
||||||
|
ONEWIRE_LOW(OneWireStruct);
|
||||||
|
ONEWIRE_OUTPUT(OneWireStruct);
|
||||||
|
ONEWIRE_DELAY(480);
|
||||||
|
|
||||||
|
/* Release line and wait for 70us */
|
||||||
|
ONEWIRE_INPUT(OneWireStruct);
|
||||||
|
ONEWIRE_DELAY(70);
|
||||||
|
|
||||||
|
/* Check bit value */
|
||||||
|
i = ONEWIRE_GET_VALUE(OneWireStruct);
|
||||||
|
|
||||||
|
/* Delay for 410 us */
|
||||||
|
ONEWIRE_DELAY(410);
|
||||||
|
|
||||||
|
/* Return value of presence pulse, 0 = OK, 1 = ERROR */
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TM_OneWire_WriteBit(TM_OneWire_t* OneWireStruct, uint8_t bit) {
|
||||||
|
if (bit) {
|
||||||
|
/* Set line low */
|
||||||
|
ONEWIRE_LOW(OneWireStruct);
|
||||||
|
ONEWIRE_OUTPUT(OneWireStruct);
|
||||||
|
ONEWIRE_DELAY(10);
|
||||||
|
|
||||||
|
/* Bit high */
|
||||||
|
ONEWIRE_INPUT(OneWireStruct);
|
||||||
|
|
||||||
|
/* Wait for 55 us and release the line */
|
||||||
|
ONEWIRE_DELAY(55);
|
||||||
|
ONEWIRE_INPUT(OneWireStruct);
|
||||||
|
} else {
|
||||||
|
/* Set line low */
|
||||||
|
ONEWIRE_LOW(OneWireStruct);
|
||||||
|
ONEWIRE_OUTPUT(OneWireStruct);
|
||||||
|
ONEWIRE_DELAY(65);
|
||||||
|
|
||||||
|
/* Bit high */
|
||||||
|
ONEWIRE_INPUT(OneWireStruct);
|
||||||
|
|
||||||
|
/* Wait for 5 us and release the line */
|
||||||
|
ONEWIRE_DELAY(5);
|
||||||
|
ONEWIRE_INPUT(OneWireStruct);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t TM_OneWire_ReadBit(TM_OneWire_t* OneWireStruct) {
|
||||||
|
uint8_t bit = 0;
|
||||||
|
|
||||||
|
/* Line low */
|
||||||
|
ONEWIRE_LOW(OneWireStruct);
|
||||||
|
ONEWIRE_OUTPUT(OneWireStruct);
|
||||||
|
ONEWIRE_DELAY(3);
|
||||||
|
|
||||||
|
/* Release line */
|
||||||
|
ONEWIRE_INPUT(OneWireStruct);
|
||||||
|
ONEWIRE_DELAY(10);
|
||||||
|
|
||||||
|
/* Read line value */
|
||||||
|
if (ONEWIRE_GET_VALUE(OneWireStruct)) {
|
||||||
|
/* Bit is HIGH */
|
||||||
|
bit = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Wait 50us to complete 60us period */
|
||||||
|
ONEWIRE_DELAY(50);
|
||||||
|
|
||||||
|
/* Return bit value */
|
||||||
|
return bit;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TM_OneWire_WriteByte(TM_OneWire_t* OneWireStruct, uint8_t byte) {
|
||||||
|
uint8_t i = 8;
|
||||||
|
/* Write 8 bits */
|
||||||
|
while (i--) {
|
||||||
|
/* LSB bit is first */
|
||||||
|
TM_OneWire_WriteBit(OneWireStruct, byte & 0x01);
|
||||||
|
byte >>= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t TM_OneWire_ReadByte(TM_OneWire_t* OneWireStruct) {
|
||||||
|
uint8_t i = 8, byte = 0;
|
||||||
|
while (i--) {
|
||||||
|
byte >>= 1;
|
||||||
|
byte |= (TM_OneWire_ReadBit(OneWireStruct) << 7);
|
||||||
|
}
|
||||||
|
|
||||||
|
return byte;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t TM_OneWire_First(TM_OneWire_t* OneWireStruct) {
|
||||||
|
/* Reset search values */
|
||||||
|
TM_OneWire_ResetSearch(OneWireStruct);
|
||||||
|
|
||||||
|
/* Start with searching */
|
||||||
|
return TM_OneWire_Search(OneWireStruct, ONEWIRE_CMD_SEARCHROM);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t TM_OneWire_Next(TM_OneWire_t* OneWireStruct) {
|
||||||
|
/* Leave the search state alone */
|
||||||
|
return TM_OneWire_Search(OneWireStruct, ONEWIRE_CMD_SEARCHROM);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TM_OneWire_ResetSearch(TM_OneWire_t* OneWireStruct) {
|
||||||
|
/* Reset the search state */
|
||||||
|
OneWireStruct->LastDiscrepancy = 0;
|
||||||
|
OneWireStruct->LastDeviceFlag = 0;
|
||||||
|
OneWireStruct->LastFamilyDiscrepancy = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t TM_OneWire_Search(TM_OneWire_t* OneWireStruct, uint8_t command) {
|
||||||
|
uint8_t id_bit_number;
|
||||||
|
uint8_t last_zero, rom_byte_number, search_result;
|
||||||
|
uint8_t id_bit, cmp_id_bit;
|
||||||
|
uint8_t rom_byte_mask, search_direction;
|
||||||
|
|
||||||
|
/* Initialize for search */
|
||||||
|
id_bit_number = 1;
|
||||||
|
last_zero = 0;
|
||||||
|
rom_byte_number = 0;
|
||||||
|
rom_byte_mask = 1;
|
||||||
|
search_result = 0;
|
||||||
|
|
||||||
|
/* Check if any devices */
|
||||||
|
if (!OneWireStruct->LastDeviceFlag) {
|
||||||
|
/* 1-Wire reset */
|
||||||
|
if (TM_OneWire_Reset(OneWireStruct)) {
|
||||||
|
/* Reset the search */
|
||||||
|
OneWireStruct->LastDiscrepancy = 0;
|
||||||
|
OneWireStruct->LastDeviceFlag = 0;
|
||||||
|
OneWireStruct->LastFamilyDiscrepancy = 0;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Issue the search command */
|
||||||
|
TM_OneWire_WriteByte(OneWireStruct, command);
|
||||||
|
|
||||||
|
/* Loop to do the search */
|
||||||
|
do {
|
||||||
|
/* Read a bit and its complement */
|
||||||
|
id_bit = TM_OneWire_ReadBit(OneWireStruct);
|
||||||
|
cmp_id_bit = TM_OneWire_ReadBit(OneWireStruct);
|
||||||
|
|
||||||
|
/* Check for no devices on 1-wire */
|
||||||
|
if ((id_bit == 1) && (cmp_id_bit == 1)) {
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
/* All devices coupled have 0 or 1 */
|
||||||
|
if (id_bit != cmp_id_bit) {
|
||||||
|
/* Bit write value for search */
|
||||||
|
search_direction = id_bit;
|
||||||
|
} else {
|
||||||
|
/* If this discrepancy is before the Last Discrepancy on a previous next then pick the same as last time */
|
||||||
|
if (id_bit_number < OneWireStruct->LastDiscrepancy) {
|
||||||
|
search_direction = ((OneWireStruct->ROM_NO[rom_byte_number] & rom_byte_mask) > 0);
|
||||||
|
} else {
|
||||||
|
/* If equal to last pick 1, if not then pick 0 */
|
||||||
|
search_direction = (id_bit_number == OneWireStruct->LastDiscrepancy);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If 0 was picked then record its position in LastZero */
|
||||||
|
if (search_direction == 0) {
|
||||||
|
last_zero = id_bit_number;
|
||||||
|
|
||||||
|
/* Check for Last discrepancy in family */
|
||||||
|
if (last_zero < 9) {
|
||||||
|
OneWireStruct->LastFamilyDiscrepancy = last_zero;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set or clear the bit in the ROM byte rom_byte_number with mask rom_byte_mask */
|
||||||
|
if (search_direction == 1) {
|
||||||
|
OneWireStruct->ROM_NO[rom_byte_number] |= rom_byte_mask;
|
||||||
|
} else {
|
||||||
|
OneWireStruct->ROM_NO[rom_byte_number] &= ~rom_byte_mask;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Serial number search direction write bit */
|
||||||
|
TM_OneWire_WriteBit(OneWireStruct, search_direction);
|
||||||
|
|
||||||
|
/* Increment the byte counter id_bit_number and shift the mask rom_byte_mask */
|
||||||
|
id_bit_number++;
|
||||||
|
rom_byte_mask <<= 1;
|
||||||
|
|
||||||
|
/* If the mask is 0 then go to new SerialNum byte rom_byte_number and reset mask */
|
||||||
|
if (rom_byte_mask == 0) {
|
||||||
|
rom_byte_number++;
|
||||||
|
rom_byte_mask = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* Loop until through all ROM bytes 0-7 */
|
||||||
|
} while (rom_byte_number < 8);
|
||||||
|
|
||||||
|
/* If the search was successful then */
|
||||||
|
if (!(id_bit_number < 65)) {
|
||||||
|
/* Search successful so set LastDiscrepancy, LastDeviceFlag, search_result */
|
||||||
|
OneWireStruct->LastDiscrepancy = last_zero;
|
||||||
|
|
||||||
|
/* Check for last device */
|
||||||
|
if (OneWireStruct->LastDiscrepancy == 0) {
|
||||||
|
OneWireStruct->LastDeviceFlag = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
search_result = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If no device found then reset counters so next 'search' will be like a first */
|
||||||
|
if (!search_result || !OneWireStruct->ROM_NO[0]) {
|
||||||
|
OneWireStruct->LastDiscrepancy = 0;
|
||||||
|
OneWireStruct->LastDeviceFlag = 0;
|
||||||
|
OneWireStruct->LastFamilyDiscrepancy = 0;
|
||||||
|
search_result = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return search_result;
|
||||||
|
}
|
||||||
|
|
||||||
|
int TM_OneWire_Verify(TM_OneWire_t* OneWireStruct) {
|
||||||
|
unsigned char rom_backup[8];
|
||||||
|
int i,rslt,ld_backup,ldf_backup,lfd_backup;
|
||||||
|
|
||||||
|
/* Keep a backup copy of the current state */
|
||||||
|
for (i = 0; i < 8; i++)
|
||||||
|
rom_backup[i] = OneWireStruct->ROM_NO[i];
|
||||||
|
ld_backup = OneWireStruct->LastDiscrepancy;
|
||||||
|
ldf_backup = OneWireStruct->LastDeviceFlag;
|
||||||
|
lfd_backup = OneWireStruct->LastFamilyDiscrepancy;
|
||||||
|
|
||||||
|
/* Set search to find the same device */
|
||||||
|
OneWireStruct->LastDiscrepancy = 64;
|
||||||
|
OneWireStruct->LastDeviceFlag = 0;
|
||||||
|
|
||||||
|
if (TM_OneWire_Search(OneWireStruct, ONEWIRE_CMD_SEARCHROM)) {
|
||||||
|
/* Check if same device found */
|
||||||
|
rslt = 1;
|
||||||
|
for (i = 0; i < 8; i++) {
|
||||||
|
if (rom_backup[i] != OneWireStruct->ROM_NO[i]) {
|
||||||
|
rslt = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
rslt = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Restore the search state */
|
||||||
|
for (i = 0; i < 8; i++) {
|
||||||
|
OneWireStruct->ROM_NO[i] = rom_backup[i];
|
||||||
|
}
|
||||||
|
OneWireStruct->LastDiscrepancy = ld_backup;
|
||||||
|
OneWireStruct->LastDeviceFlag = ldf_backup;
|
||||||
|
OneWireStruct->LastFamilyDiscrepancy = lfd_backup;
|
||||||
|
|
||||||
|
/* Return the result of the verify */
|
||||||
|
return rslt;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TM_OneWire_TargetSetup(TM_OneWire_t* OneWireStruct, uint8_t family_code) {
|
||||||
|
uint8_t i;
|
||||||
|
|
||||||
|
/* Set the search state to find SearchFamily type devices */
|
||||||
|
OneWireStruct->ROM_NO[0] = family_code;
|
||||||
|
for (i = 1; i < 8; i++) {
|
||||||
|
OneWireStruct->ROM_NO[i] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
OneWireStruct->LastDiscrepancy = 64;
|
||||||
|
OneWireStruct->LastFamilyDiscrepancy = 0;
|
||||||
|
OneWireStruct->LastDeviceFlag = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TM_OneWire_FamilySkipSetup(TM_OneWire_t* OneWireStruct) {
|
||||||
|
/* Set the Last discrepancy to last family discrepancy */
|
||||||
|
OneWireStruct->LastDiscrepancy = OneWireStruct->LastFamilyDiscrepancy;
|
||||||
|
OneWireStruct->LastFamilyDiscrepancy = 0;
|
||||||
|
|
||||||
|
/* Check for end of list */
|
||||||
|
if (OneWireStruct->LastDiscrepancy == 0) {
|
||||||
|
OneWireStruct->LastDeviceFlag = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t TM_OneWire_GetROM(TM_OneWire_t* OneWireStruct, uint8_t index) {
|
||||||
|
return OneWireStruct->ROM_NO[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
void TM_OneWire_Select(TM_OneWire_t* OneWireStruct, uint8_t* addr) {
|
||||||
|
uint8_t i;
|
||||||
|
TM_OneWire_WriteByte(OneWireStruct, ONEWIRE_CMD_MATCHROM);
|
||||||
|
|
||||||
|
for (i = 0; i < 8; i++) {
|
||||||
|
TM_OneWire_WriteByte(OneWireStruct, *(addr + i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TM_OneWire_SelectWithPointer(TM_OneWire_t* OneWireStruct, uint8_t *ROM) {
|
||||||
|
uint8_t i;
|
||||||
|
TM_OneWire_WriteByte(OneWireStruct, ONEWIRE_CMD_MATCHROM);
|
||||||
|
|
||||||
|
for (i = 0; i < 8; i++) {
|
||||||
|
TM_OneWire_WriteByte(OneWireStruct, *(ROM + i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TM_OneWire_GetFullROM(TM_OneWire_t* OneWireStruct, uint8_t *firstIndex) {
|
||||||
|
uint8_t i;
|
||||||
|
for (i = 0; i < 8; i++) {
|
||||||
|
*(firstIndex + i) = OneWireStruct->ROM_NO[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t TM_OneWire_CRC8(uint8_t *addr, uint8_t len) {
|
||||||
|
uint8_t crc = 0, inbyte, i, mix;
|
||||||
|
|
||||||
|
while (len--) {
|
||||||
|
inbyte = *addr++;
|
||||||
|
for (i = 8; i; i--) {
|
||||||
|
mix = (crc ^ inbyte) & 0x01;
|
||||||
|
crc >>= 1;
|
||||||
|
if (mix) {
|
||||||
|
crc ^= 0x8C;
|
||||||
|
}
|
||||||
|
inbyte >>= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Return calculated CRC */
|
||||||
|
return crc;
|
||||||
|
}
|
||||||
|
|
@ -4,8 +4,9 @@
|
||||||
* Created: 03.01.2021 23:22:04
|
* Created: 03.01.2021 23:22:04
|
||||||
* Author: Lexus
|
* Author: Lexus
|
||||||
*/
|
*/
|
||||||
|
#include "tmpgood.h"
|
||||||
#include "conf_board.h"
|
#include "conf_board.h"
|
||||||
#include "port.h"
|
|
||||||
void tmpgood_configure_port_pins(void)
|
void tmpgood_configure_port_pins(void)
|
||||||
{
|
{
|
||||||
struct port_config config_port_pin;
|
struct port_config config_port_pin;
|
||||||
|
|
@ -15,7 +16,7 @@ void tmpgood_configure_port_pins(void)
|
||||||
port_pin_set_config(TC_TMPGD, &config_port_pin);
|
port_pin_set_config(TC_TMPGD, &config_port_pin);
|
||||||
}
|
}
|
||||||
|
|
||||||
_Bool tmpgood_get_state(void)
|
bool tmpgood_get_state(void)
|
||||||
{
|
{
|
||||||
return port_pin_get_input_level(TC_TMPGD);
|
return port_pin_get_input_level(TC_TMPGD);
|
||||||
}
|
}
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
*/
|
*/
|
||||||
#include "ws2812.h"
|
#include "ws2812.h"
|
||||||
#include "conf_board.h"
|
#include "conf_board.h"
|
||||||
#include "port.h"
|
#include <asf.h>
|
||||||
|
|
||||||
void ws2812_configure_port_pins(void)
|
void ws2812_configure_port_pins(void)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue