aboutsummaryrefslogtreecommitdiff
path: root/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2017-01-25 22:24:18 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2017-01-25 22:29:25 +0100
commit40e04e3772726829d66c12e69f24b03920d79c67 (patch)
tree636811bad956798c9d5d22de9e7ba8c799b8d791 /thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities
parent2fff65aed2477a503c72629d27e2a330d30c02d1 (diff)
downloadstm32f103-playground-40e04e3772726829d66c12e69f24b03920d79c67.tar.gz
stm32f103-playground-40e04e3772726829d66c12e69f24b03920d79c67.tar.bz2
stm32f103-playground-40e04e3772726829d66c12e69f24b03920d79c67.tar.xz
stm32f103-playground-40e04e3772726829d66c12e69f24b03920d79c67.zip
o Moving tinyprintf and stm libraries under thirdparty.
Diffstat (limited to 'thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities')
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/Binary/TrueSTUDIO_elf2bin.bat10
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/Binary/arm-elf-objcopy.exebin0 -> 523776 bytes
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/Binary/axftobin.bat6
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/Binary/cygwin1.dllbin0 -> 1189587 bytes
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/Binary/hextobin.bat12
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM3210B-EVAL_AudioSpeaker.dfubin0 -> 7509 bytes
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM3210B-EVAL_JoystickMouse.dfubin0 -> 7509 bytes
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM3210B-EVAL_VirtualCOMPort.dfubin0 -> 7713 bytes
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM3210B-EVAL_VirtualComport_Loopback.dfubin0 -> 6849 bytes
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM3210E-EVAL_AudioSpeaker.dfubin0 -> 9025 bytes
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM3210E-EVAL_Composite_Example.dfubin0 -> 17945 bytes
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM3210E-EVAL_MassStorage.dfubin0 -> 16444 bytes
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM3210E-EVAL_XL_AudioSpeaker.dfubin0 -> 9025 bytes
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM3210E-EVAL_XL_Composite_Example.dfubin0 -> 17945 bytes
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM3210E-EVAL_XL_JoyStickMouse.dfubin0 -> 7673 bytes
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM3210E-EVAL_XL_MassStorage.dfubin0 -> 16444 bytes
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM3210E-EVAL_XL_VirtualCOMPort.dfubin0 -> 7741 bytes
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM3210E-EVAL_XL_VirtualComport_Loopback.dfubin0 -> 6985 bytes
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32303C-EVAL_CustomHID.dfubin0 -> 13317 bytes
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32303C-EVAL_MassStorage.dfubin0 -> 11189 bytes
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32303C-EVAL_VirtualCOMPort.dfubin0 -> 8937 bytes
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32303C-EVAL_VirtualComport_Loopback.dfubin0 -> 7301 bytes
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32373C-EVAL_CustomHID.dfubin0 -> 9085 bytes
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32373C-EVAL_JoyStickMouse.dfubin0 -> 7753 bytes
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32373C-EVAL_MassStorage.dfubin0 -> 10813 bytes
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32373C-EVAL_VirtualCOMPort.dfubin0 -> 8589 bytes
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32373C-EVAL_VirtualComport_Loopback.dfubin0 -> 7165 bytes
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32L152-EVAL_AudioSpeaker.dfubin0 -> 7033 bytes
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32L152-EVAL_Composite_Example.dfubin0 -> 12757 bytes
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32L152-EVAL_Custom_HID.dfubin0 -> 8353 bytes
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32L152-EVAL_MassStorage.dfubin0 -> 9685 bytes
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32L152-EVAL_VirtualCOMPort.dfubin0 -> 7277 bytes
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32L152-EVAL_VirtualComport_Loopback.dfubin0 -> 6653 bytes
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32L152D-EVAL_Composite_Example.dfubin0 -> 15497 bytes
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32L152D-EVAL_JoyStickMouse.dfubin0 -> 7453 bytes
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32L152D-EVAL_VirtualCOMPort.dfubin0 -> 7325 bytes
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32L152D-EVAL_VirtualComport_Loopback.dfubin0 -> 6749 bytes
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/Common/fonts.c1003
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/Common/lcd_log.c528
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/Common/lcd_log.h160
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/Common/lcd_log_conf_template.h113
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/Common/stm32_eval_legacy.h208
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210B_EVAL/Release_Notes.html347
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210B_EVAL/stm3210b_eval.c626
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210B_EVAL/stm3210b_eval.h403
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210B_EVAL/stm3210b_eval_i2c_tsensor.c982
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210B_EVAL/stm3210b_eval_i2c_tsensor.h179
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210B_EVAL/stm3210b_eval_lcd.c1884
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210B_EVAL/stm3210b_eval_lcd.h400
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210B_EVAL/stm3210b_eval_spi_flash.c546
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210B_EVAL/stm3210b_eval_spi_flash.h157
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210B_EVAL/stm3210b_eval_spi_sd.c911
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210B_EVAL/stm3210b_eval_spi_sd.h286
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210E_EVAL/stm3210e_eval.c677
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210E_EVAL/stm3210e_eval.h407
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210E_EVAL/stm3210e_eval_fsmc_nand.c552
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210E_EVAL/stm3210e_eval_fsmc_nand.h183
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210E_EVAL/stm3210e_eval_fsmc_nor.c484
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210E_EVAL/stm3210e_eval_fsmc_nor.h134
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210E_EVAL/stm3210e_eval_sdio_sd.c2816
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210E_EVAL/stm3210e_eval_sdio_sd.h406
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32303C_EVAL/stm32303c_eval.c762
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32303C_EVAL/stm32303c_eval.h442
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32303C_EVAL/stm32303c_eval_audio_codec.c1597
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32303C_EVAL/stm32303c_eval_audio_codec.h302
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32303C_EVAL/stm32303c_eval_i2c_ee.c717
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32303C_EVAL/stm32303c_eval_i2c_ee.h206
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32303C_EVAL/stm32303c_eval_i2c_tsensor.c754
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32303C_EVAL/stm32303c_eval_i2c_tsensor.h177
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32373C_EVAL/stm32373c_eval.c677
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32373C_EVAL/stm32373c_eval.h409
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32373C_EVAL/stm32373c_eval_audio_codec.c1405
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32373C_EVAL/stm32373c_eval_audio_codec.h284
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32373C_EVAL/stm32373c_eval_cec.c2033
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32373C_EVAL/stm32373c_eval_cec.h309
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32373C_EVAL/stm32373c_eval_i2c_ee_cpal.c580
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32373C_EVAL/stm32373c_eval_i2c_ee_cpal.h231
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32373C_EVAL/stm32373c_eval_i2c_tsensor_cpal.c458
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32373C_EVAL/stm32373c_eval_i2c_tsensor_cpal.h129
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32373C_EVAL/stm32373c_eval_spi_sd.c908
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32373C_EVAL/stm32373c_eval_spi_sd.h286
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval.c882
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval.h465
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval_audio_codec.c1489
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval_audio_codec.h283
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval_fsmc_nor.c535
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval_glass_lcd.c3479
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval_glass_lcd.h264
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval_lcd.c1684
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval_lcd.h385
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval_sdio_sd.c2818
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval_sdio_sd.h406
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval_spi_ee.c476
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval_spi_ee.h156
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152_EVAL/stm32l152_eval.c740
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152_EVAL/stm32l152_eval.h457
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152_EVAL/stm32l152_eval_glass_lcd.c861
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152_EVAL/stm32l152_eval_glass_lcd.h131
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152_EVAL/stm32l152_eval_i2c_ee.c816
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152_EVAL/stm32l152_eval_i2c_ee.h187
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152_EVAL/stm32l152_eval_i2c_tsensor.c982
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152_EVAL/stm32l152_eval_i2c_tsensor.h179
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152_EVAL/stm32l152_eval_lcd.c1624
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152_EVAL/stm32l152_eval_lcd.h398
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152_EVAL/stm32l152_eval_spi_sd.c912
-rw-r--r--thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152_EVAL/stm32l152_eval_spi_sd.h286
106 files changed, 47981 insertions, 0 deletions
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/Binary/TrueSTUDIO_elf2bin.bat b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/Binary/TrueSTUDIO_elf2bin.bat
new file mode 100644
index 0000000..b3e3fe8
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/Binary/TrueSTUDIO_elf2bin.bat
@@ -0,0 +1,10 @@
+@echo off
+
+if exist .\..\..\Project\Device_Firmware_Upgrade\binary_template\TrueSTUDIO\STM3210C-EVAL\Debug\STM3210C-EVAL.elf ("arm-elf-objcopy.exe" -O binary ".\..\..\Project\Device_Firmware_Upgrade\binary_template\TrueSTUDIO\STM3210C-EVAL\Debug\STM3210C-EVAL.elf" ".\..\..\Project\Device_Firmware_Upgrade\binary_template\TrueSTUDIO\STM3210C-EVAL\Debug\STM3210C-EVAL_SysTick.bin")
+if exist .\..\..\Project\Device_Firmware_Upgrade\binary_template\TrueSTUDIO\STM3210B-EVAL\Debug\STM3210B-EVAL.elf ("arm-elf-objcopy.exe" -O binary ".\..\..\Project\Device_Firmware_Upgrade\binary_template\TrueSTUDIO\STM3210B-EVAL\Debug\STM3210B-EVAL.elf" ".\..\..\Project\Device_Firmware_Upgrade\binary_template\TrueSTUDIO\STM3210B-EVAL\Debug\STM3210B-EVAL_SysTick.bin")
+if exist .\..\..\Project\Device_Firmware_Upgrade\binary_template\TrueSTUDIO\STM3210E-EVAL\Debug\STM3210E-EVAL.elf ("arm-elf-objcopy.exe" -O binary ".\..\..\Project\Device_Firmware_Upgrade\binary_template\TrueSTUDIO\STM3210E-EVAL\Debug\STM3210E-EVAL.elf" ".\..\..\Project\Device_Firmware_Upgrade\binary_template\TrueSTUDIO\STM3210E-EVAL\Debug\STM3210E-EVAL_SysTick.bin")
+if exist .\..\..\Project\Device_Firmware_Upgrade\binary_template\TrueSTUDIO\STM3210E-EVAL_XL\Debug\STM32F10X_XL.elf ("arm-elf-objcopy.exe" -O binary ".\..\..\Project\Device_Firmware_Upgrade\binary_template\TrueSTUDIO\STM3210E-EVAL_XL\Debug\STM32F10X_XL.elf" ".\..\..\Project\Device_Firmware_Upgrade\binary_template\TrueSTUDIO\STM3210E-EVAL_XL\Debug\STM32F10X_XL_SysTick.bin")
+if exist .\..\..\Project\Device_Firmware_Upgrade\binary_template\TrueSTUDIO\STM32L152-EVAL\Debug\STM32L152-EVAL.elf ("arm-elf-objcopy.exe" -O binary ".\..\..\Project\Device_Firmware_Upgrade\binary_template\TrueSTUDIO\STM32L152-EVAL\Debug\STM32L152-EVAL.elf" ".\..\..\Project\Device_Firmware_Upgrade\binary_template\TrueSTUDIO\STM32L152-EVAL\Debug\STM32L152-EVAL_SysTick.bin")
+
+pause
+
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/Binary/arm-elf-objcopy.exe b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/Binary/arm-elf-objcopy.exe
new file mode 100644
index 0000000..46553ff
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/Binary/arm-elf-objcopy.exe
Binary files differ
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/Binary/axftobin.bat b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/Binary/axftobin.bat
new file mode 100644
index 0000000..4a3becc
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/Binary/axftobin.bat
@@ -0,0 +1,6 @@
+if exist .\..\..\Project\Device_Firmware_Upgrade\binary_template\MDK-ARM\STM3210E-EVAL_XL\STM3210E-EVAL_XL.axf (C:\Keil\ARM\BIN40\fromelf.exe ".\..\..\Project\Device_Firmware_Upgrade\binary_template\MDK-ARM\STM3210E-EVAL_XL\STM3210E-EVAL_XL.axf" --bin --output ".\..\..\Project\Device_Firmware_Upgrade\binary_template\MDK-ARM\STM3210E-EVAL_XL\STM3210E-EVAL_XL_SysTick.bin")
+if exist .\..\..\Project\Device_Firmware_Upgrade\binary_template\MDK-ARM\STM3210B-EVAL\STM3210B-EVAL.axf (C:\Keil\ARM\BIN40\fromelf.exe ".\..\..\Project\Device_Firmware_Upgrade\binary_template\MDK-ARM\STM3210B-EVAL\STM3210B-EVAL.axf" --bin --output ".\..\..\Project\Device_Firmware_Upgrade\binary_template\MDK-ARM\STM3210B-EVAL\STM3210B-EVAL_SysTick.bin")
+if exist .\..\..\Project\Device_Firmware_Upgrade\binary_template\MDK-ARM\STM3210E-EVAL\STM3210E-EVAL.axf (C:\Keil\ARM\BIN40\fromelf.exe ".\..\..\Project\Device_Firmware_Upgrade\binary_template\MDK-ARM\STM3210E-EVAL\STM3210E-EVAL.axf" --bin --output ".\..\..\Project\Device_Firmware_Upgrade\binary_template\MDK-ARM\STM3210E-EVAL\STM3210E-EVAL_SysTick.bin")
+if exist .\..\..\Project\Device_Firmware_Upgrade\binary_template\MDK-ARM\STM3210C-EVAL\STM3210C-EVAL.axf (C:\Keil\ARM\BIN40\fromelf.exe ".\..\..\Project\Device_Firmware_Upgrade\binary_template\MDK-ARM\STM3210C-EVAL\STM3210C-EVAL.axf" --bin --output ".\..\..\Project\Device_Firmware_Upgrade\binary_template\MDK-ARM\STM3210C-EVAL\STM3210C-EVAL_SysTick.bin")
+if exist .\..\..\Project\Device_Firmware_Upgrade\binary_template\MDK-ARM\STM32L152-EVAL\STM32L152-EVAL.axf (C:\Keil\ARM\BIN40\fromelf.exe ".\..\..\Project\Device_Firmware_Upgrade\binary_template\MDK-ARM\STM32L152-EVAL\STM32L152-EVAL.axf" --bin --output ".\..\..\Project\Device_Firmware_Upgrade\binary_template\MDK-ARM\STM32L152-EVAL\STM32L152-EVAL_SysTick.bin")
+pause
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/Binary/cygwin1.dll b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/Binary/cygwin1.dll
new file mode 100644
index 0000000..984dd61
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/Binary/cygwin1.dll
Binary files differ
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/Binary/hextobin.bat b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/Binary/hextobin.bat
new file mode 100644
index 0000000..cee45c5
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/Binary/hextobin.bat
@@ -0,0 +1,12 @@
+if exist .\..\..\Project\Device_Firmware_Upgrade\binary_template\RIDE\STM3210E-EVAL\SysTick.hex (hex2bin.exe .\..\..\Project\Device_Firmware_Upgrade\binary_template\RIDE\STM3210E-EVAL\SysTick.hex)
+if exist .\..\..\Project\Device_Firmware_Upgrade\binary_template\RIDE\STM3210B-EVAL\SysTick.hex (hex2bin.exe .\..\..\Project\Device_Firmware_Upgrade\binary_template\RIDE\STM3210B-EVAL\SysTick.hex)
+if exist .\..\..\Project\Device_Firmware_Upgrade\binary_template\RIDE\STM3210C-EVAL\SysTick.hex (hex2bin.exe .\..\..\Project\Device_Firmware_Upgrade\binary_template\RIDE\STM3210C-EVAL\SysTick.hex)
+if exist .\..\..\Project\Device_Firmware_Upgrade\binary_template\RIDE\STM3210E-EVAL_XL\SysTick.hex (hex2bin.exe .\..\..\Project\Device_Firmware_Upgrade\binary_template\RIDE\STM3210E-EVAL_XL\SysTick.hex)
+if exist .\..\..\Project\Device_Firmware_Upgrade\binary_template\RIDE\STM32L152-EVAL\SysTick.hex (hex2bin.exe .\..\..\Project\Device_Firmware_Upgrade\binary_template\RIDE\STM32L152-EVAL\SysTick.hex)
+if exist .\..\..\Project\Device_Firmware_Upgrade\binary_template\HiTOP\STM3210B-EVAL\Project.hex (hex2bin.exe .\..\..\Project\Device_Firmware_Upgrade\binary_template\HiTOP\STM3210B-EVAL\Project.hex)
+if exist .\..\..\Project\Device_Firmware_Upgrade\binary_template\HiTOP\STM3210C-EVAL\Project.hex (hex2bin.exe .\..\..\Project\Device_Firmware_Upgrade\binary_template\HiTOP\STM3210C-EVAL\Project.hex)
+if exist .\..\..\Project\Device_Firmware_Upgrade\binary_template\HiTOP\STM3210E-EVAL\Project.hex (hex2bin.exe .\..\..\Project\Device_Firmware_Upgrade\binary_template\HiTOP\STM3210E-EVAL\Project.hex)
+if exist .\..\..\Project\Device_Firmware_Upgrade\binary_template\HiTOP\STM3210E-EVAL_XL\Project.hex (hex2bin.exe .\..\..\Project\Device_Firmware_Upgrade\binary_template\HiTOP\STM3210E-EVAL_XL\Project.hex)
+if exist .\..\..\Project\Device_Firmware_Upgrade\binary_template\HiTOP\STM32L152-EVAL\Project.hex (hex2bin.exe .\..\..\Project\Device_Firmware_Upgrade\binary_template\HiTOP\STM32L152-EVAL\Project.hex)
+
+pause
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM3210B-EVAL_AudioSpeaker.dfu b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM3210B-EVAL_AudioSpeaker.dfu
new file mode 100644
index 0000000..b6f599c
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM3210B-EVAL_AudioSpeaker.dfu
Binary files differ
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM3210B-EVAL_JoystickMouse.dfu b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM3210B-EVAL_JoystickMouse.dfu
new file mode 100644
index 0000000..0fd3c5f
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM3210B-EVAL_JoystickMouse.dfu
Binary files differ
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM3210B-EVAL_VirtualCOMPort.dfu b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM3210B-EVAL_VirtualCOMPort.dfu
new file mode 100644
index 0000000..580081e
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM3210B-EVAL_VirtualCOMPort.dfu
Binary files differ
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM3210B-EVAL_VirtualComport_Loopback.dfu b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM3210B-EVAL_VirtualComport_Loopback.dfu
new file mode 100644
index 0000000..c3fba6d
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM3210B-EVAL_VirtualComport_Loopback.dfu
Binary files differ
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM3210E-EVAL_AudioSpeaker.dfu b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM3210E-EVAL_AudioSpeaker.dfu
new file mode 100644
index 0000000..3081a9c
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM3210E-EVAL_AudioSpeaker.dfu
Binary files differ
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM3210E-EVAL_Composite_Example.dfu b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM3210E-EVAL_Composite_Example.dfu
new file mode 100644
index 0000000..9ccfa8c
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM3210E-EVAL_Composite_Example.dfu
Binary files differ
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM3210E-EVAL_MassStorage.dfu b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM3210E-EVAL_MassStorage.dfu
new file mode 100644
index 0000000..b649ba8
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM3210E-EVAL_MassStorage.dfu
Binary files differ
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM3210E-EVAL_XL_AudioSpeaker.dfu b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM3210E-EVAL_XL_AudioSpeaker.dfu
new file mode 100644
index 0000000..3081a9c
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM3210E-EVAL_XL_AudioSpeaker.dfu
Binary files differ
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM3210E-EVAL_XL_Composite_Example.dfu b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM3210E-EVAL_XL_Composite_Example.dfu
new file mode 100644
index 0000000..d0c4284
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM3210E-EVAL_XL_Composite_Example.dfu
Binary files differ
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM3210E-EVAL_XL_JoyStickMouse.dfu b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM3210E-EVAL_XL_JoyStickMouse.dfu
new file mode 100644
index 0000000..f161c91
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM3210E-EVAL_XL_JoyStickMouse.dfu
Binary files differ
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM3210E-EVAL_XL_MassStorage.dfu b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM3210E-EVAL_XL_MassStorage.dfu
new file mode 100644
index 0000000..b649ba8
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM3210E-EVAL_XL_MassStorage.dfu
Binary files differ
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM3210E-EVAL_XL_VirtualCOMPort.dfu b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM3210E-EVAL_XL_VirtualCOMPort.dfu
new file mode 100644
index 0000000..597cd0e
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM3210E-EVAL_XL_VirtualCOMPort.dfu
Binary files differ
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM3210E-EVAL_XL_VirtualComport_Loopback.dfu b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM3210E-EVAL_XL_VirtualComport_Loopback.dfu
new file mode 100644
index 0000000..1f85bfb
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM3210E-EVAL_XL_VirtualComport_Loopback.dfu
Binary files differ
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32303C-EVAL_CustomHID.dfu b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32303C-EVAL_CustomHID.dfu
new file mode 100644
index 0000000..4dcc9a2
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32303C-EVAL_CustomHID.dfu
Binary files differ
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32303C-EVAL_MassStorage.dfu b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32303C-EVAL_MassStorage.dfu
new file mode 100644
index 0000000..c927ebc
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32303C-EVAL_MassStorage.dfu
Binary files differ
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32303C-EVAL_VirtualCOMPort.dfu b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32303C-EVAL_VirtualCOMPort.dfu
new file mode 100644
index 0000000..e14ff75
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32303C-EVAL_VirtualCOMPort.dfu
Binary files differ
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32303C-EVAL_VirtualComport_Loopback.dfu b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32303C-EVAL_VirtualComport_Loopback.dfu
new file mode 100644
index 0000000..fec8ef3
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32303C-EVAL_VirtualComport_Loopback.dfu
Binary files differ
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32373C-EVAL_CustomHID.dfu b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32373C-EVAL_CustomHID.dfu
new file mode 100644
index 0000000..5658101
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32373C-EVAL_CustomHID.dfu
Binary files differ
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32373C-EVAL_JoyStickMouse.dfu b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32373C-EVAL_JoyStickMouse.dfu
new file mode 100644
index 0000000..103f4c3
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32373C-EVAL_JoyStickMouse.dfu
Binary files differ
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32373C-EVAL_MassStorage.dfu b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32373C-EVAL_MassStorage.dfu
new file mode 100644
index 0000000..29d81fa
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32373C-EVAL_MassStorage.dfu
Binary files differ
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32373C-EVAL_VirtualCOMPort.dfu b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32373C-EVAL_VirtualCOMPort.dfu
new file mode 100644
index 0000000..4c546b7
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32373C-EVAL_VirtualCOMPort.dfu
Binary files differ
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32373C-EVAL_VirtualComport_Loopback.dfu b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32373C-EVAL_VirtualComport_Loopback.dfu
new file mode 100644
index 0000000..5b13017
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32373C-EVAL_VirtualComport_Loopback.dfu
Binary files differ
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32L152-EVAL_AudioSpeaker.dfu b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32L152-EVAL_AudioSpeaker.dfu
new file mode 100644
index 0000000..6b19155
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32L152-EVAL_AudioSpeaker.dfu
Binary files differ
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32L152-EVAL_Composite_Example.dfu b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32L152-EVAL_Composite_Example.dfu
new file mode 100644
index 0000000..6ffb73a
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32L152-EVAL_Composite_Example.dfu
Binary files differ
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32L152-EVAL_Custom_HID.dfu b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32L152-EVAL_Custom_HID.dfu
new file mode 100644
index 0000000..eea820e
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32L152-EVAL_Custom_HID.dfu
Binary files differ
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32L152-EVAL_MassStorage.dfu b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32L152-EVAL_MassStorage.dfu
new file mode 100644
index 0000000..23ca6b6
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32L152-EVAL_MassStorage.dfu
Binary files differ
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32L152-EVAL_VirtualCOMPort.dfu b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32L152-EVAL_VirtualCOMPort.dfu
new file mode 100644
index 0000000..194e9e1
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32L152-EVAL_VirtualCOMPort.dfu
Binary files differ
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32L152-EVAL_VirtualComport_Loopback.dfu b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32L152-EVAL_VirtualComport_Loopback.dfu
new file mode 100644
index 0000000..6638545
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32L152-EVAL_VirtualComport_Loopback.dfu
Binary files differ
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32L152D-EVAL_Composite_Example.dfu b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32L152D-EVAL_Composite_Example.dfu
new file mode 100644
index 0000000..52a647e
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32L152D-EVAL_Composite_Example.dfu
Binary files differ
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32L152D-EVAL_JoyStickMouse.dfu b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32L152D-EVAL_JoyStickMouse.dfu
new file mode 100644
index 0000000..6c7ba98
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32L152D-EVAL_JoyStickMouse.dfu
Binary files differ
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32L152D-EVAL_VirtualCOMPort.dfu b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32L152D-EVAL_VirtualCOMPort.dfu
new file mode 100644
index 0000000..ba6f42c
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32L152D-EVAL_VirtualCOMPort.dfu
Binary files differ
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32L152D-EVAL_VirtualComport_Loopback.dfu b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32L152D-EVAL_VirtualComport_Loopback.dfu
new file mode 100644
index 0000000..16e64cd
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/DFU_images/STM32L152D-EVAL_VirtualComport_Loopback.dfu
Binary files differ
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/Common/fonts.c b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/Common/fonts.c
new file mode 100644
index 0000000..80cce42
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/Common/fonts.c
@@ -0,0 +1,1003 @@
+/**
+ ******************************************************************************
+ * @file fonts.c
+ * @author MCD Application Team
+ * @version V5.0.2
+ * @date 05-March-2012
+ * @brief This file provides text fonts for STM32xx-EVAL's LCD driver.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.st.com/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+
+/* Includes ------------------------------------------------------------------*/
+#include "fonts.h"
+
+/** @addtogroup Utilities
+ * @{
+ */
+
+/** @addtogroup STM32_EVAL
+ * @{
+ */
+
+/** @addtogroup Common
+ * @{
+ */
+
+/** @addtogroup FONTS
+ * @brief This file includes the Fonts driver of STM32xx-EVAL boards.
+ * @{
+ */
+
+/** @defgroup FONTS_Private_Types
+ * @{
+ */
+/**
+ * @}
+ */
+
+
+/** @defgroup FONTS_Private_Defines
+ * @{
+ */
+/**
+ * @}
+ */
+
+
+/** @defgroup FONTS_Private_Macros
+ * @{
+ */
+/**
+ * @}
+ */
+
+
+/** @defgroup FONTS_Private_Variables
+ * @{
+ */
+const uint16_t ASCII16x24_Table [] = {
+/**
+ * @brief Space ' '
+ */
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief '!'
+ */
+ 0x0000, 0x0180, 0x0180, 0x0180, 0x0180, 0x0180, 0x0180, 0x0180,
+ 0x0180, 0x0180, 0x0180, 0x0180, 0x0180, 0x0180, 0x0000, 0x0000,
+ 0x0180, 0x0180, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief '"'
+ */
+ 0x0000, 0x0000, 0x00CC, 0x00CC, 0x00CC, 0x00CC, 0x00CC, 0x00CC,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief '#'
+ */
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0C60, 0x0C60,
+ 0x0C60, 0x0630, 0x0630, 0x1FFE, 0x1FFE, 0x0630, 0x0738, 0x0318,
+ 0x1FFE, 0x1FFE, 0x0318, 0x0318, 0x018C, 0x018C, 0x018C, 0x0000,
+/**
+ * @brief '$'
+ */
+ 0x0000, 0x0080, 0x03E0, 0x0FF8, 0x0E9C, 0x1C8C, 0x188C, 0x008C,
+ 0x0098, 0x01F8, 0x07E0, 0x0E80, 0x1C80, 0x188C, 0x188C, 0x189C,
+ 0x0CB8, 0x0FF0, 0x03E0, 0x0080, 0x0080, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief '%'
+ */
+ 0x0000, 0x0000, 0x0000, 0x180E, 0x0C1B, 0x0C11, 0x0611, 0x0611,
+ 0x0311, 0x0311, 0x019B, 0x018E, 0x38C0, 0x6CC0, 0x4460, 0x4460,
+ 0x4430, 0x4430, 0x4418, 0x6C18, 0x380C, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief '&'
+ */
+ 0x0000, 0x01E0, 0x03F0, 0x0738, 0x0618, 0x0618, 0x0330, 0x01F0,
+ 0x00F0, 0x00F8, 0x319C, 0x330E, 0x1E06, 0x1C06, 0x1C06, 0x3F06,
+ 0x73FC, 0x21F0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief '''
+ */
+ 0x0000, 0x0000, 0x000C, 0x000C, 0x000C, 0x000C, 0x000C, 0x000C,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief '('
+ */
+ 0x0000, 0x0200, 0x0300, 0x0180, 0x00C0, 0x00C0, 0x0060, 0x0060,
+ 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030,
+ 0x0060, 0x0060, 0x00C0, 0x00C0, 0x0180, 0x0300, 0x0200, 0x0000,
+/**
+ * @brief ')'
+ */
+ 0x0000, 0x0020, 0x0060, 0x00C0, 0x0180, 0x0180, 0x0300, 0x0300,
+ 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600,
+ 0x0300, 0x0300, 0x0180, 0x0180, 0x00C0, 0x0060, 0x0020, 0x0000,
+/**
+ * @brief '*'
+ */
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x00C0, 0x00C0,
+ 0x06D8, 0x07F8, 0x01E0, 0x0330, 0x0738, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief '+'
+ */
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0180, 0x0180,
+ 0x0180, 0x0180, 0x0180, 0x3FFC, 0x3FFC, 0x0180, 0x0180, 0x0180,
+ 0x0180, 0x0180, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief ','
+ */
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0180, 0x0180, 0x0100, 0x0100, 0x0080, 0x0000, 0x0000,
+/**
+ * @brief '-'
+ */
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x07E0, 0x07E0, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief '.'
+ */
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x00C0, 0x00C0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief '/'
+ */
+ 0x0000, 0x0C00, 0x0C00, 0x0600, 0x0600, 0x0600, 0x0300, 0x0300,
+ 0x0300, 0x0380, 0x0180, 0x0180, 0x0180, 0x00C0, 0x00C0, 0x00C0,
+ 0x0060, 0x0060, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief '0'
+ */
+ 0x0000, 0x03E0, 0x07F0, 0x0E38, 0x0C18, 0x180C, 0x180C, 0x180C,
+ 0x180C, 0x180C, 0x180C, 0x180C, 0x180C, 0x180C, 0x0C18, 0x0E38,
+ 0x07F0, 0x03E0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief '1'
+ */
+ 0x0000, 0x0100, 0x0180, 0x01C0, 0x01F0, 0x0198, 0x0188, 0x0180,
+ 0x0180, 0x0180, 0x0180, 0x0180, 0x0180, 0x0180, 0x0180, 0x0180,
+ 0x0180, 0x0180, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief '2'
+ */
+ 0x0000, 0x03E0, 0x0FF8, 0x0C18, 0x180C, 0x180C, 0x1800, 0x1800,
+ 0x0C00, 0x0600, 0x0300, 0x0180, 0x00C0, 0x0060, 0x0030, 0x0018,
+ 0x1FFC, 0x1FFC, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief '3'
+ */
+ 0x0000, 0x01E0, 0x07F8, 0x0E18, 0x0C0C, 0x0C0C, 0x0C00, 0x0600,
+ 0x03C0, 0x07C0, 0x0C00, 0x1800, 0x1800, 0x180C, 0x180C, 0x0C18,
+ 0x07F8, 0x03E0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief '4'
+ */
+ 0x0000, 0x0C00, 0x0E00, 0x0F00, 0x0F00, 0x0D80, 0x0CC0, 0x0C60,
+ 0x0C60, 0x0C30, 0x0C18, 0x0C0C, 0x3FFC, 0x3FFC, 0x0C00, 0x0C00,
+ 0x0C00, 0x0C00, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief '5'
+ */
+ 0x0000, 0x0FF8, 0x0FF8, 0x0018, 0x0018, 0x000C, 0x03EC, 0x07FC,
+ 0x0E1C, 0x1C00, 0x1800, 0x1800, 0x1800, 0x180C, 0x0C1C, 0x0E18,
+ 0x07F8, 0x03E0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief '6'
+ */
+ 0x0000, 0x07C0, 0x0FF0, 0x1C38, 0x1818, 0x0018, 0x000C, 0x03CC,
+ 0x0FEC, 0x0E3C, 0x1C1C, 0x180C, 0x180C, 0x180C, 0x1C18, 0x0E38,
+ 0x07F0, 0x03E0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief '7'
+ */
+ 0x0000, 0x1FFC, 0x1FFC, 0x0C00, 0x0600, 0x0600, 0x0300, 0x0380,
+ 0x0180, 0x01C0, 0x00C0, 0x00E0, 0x0060, 0x0060, 0x0070, 0x0030,
+ 0x0030, 0x0030, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief '8'
+ */
+ 0x0000, 0x03E0, 0x07F0, 0x0E38, 0x0C18, 0x0C18, 0x0C18, 0x0638,
+ 0x07F0, 0x07F0, 0x0C18, 0x180C, 0x180C, 0x180C, 0x180C, 0x0C38,
+ 0x0FF8, 0x03E0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief '9'
+ */
+ 0x0000, 0x03E0, 0x07F0, 0x0E38, 0x0C1C, 0x180C, 0x180C, 0x180C,
+ 0x1C1C, 0x1E38, 0x1BF8, 0x19E0, 0x1800, 0x0C00, 0x0C00, 0x0E1C,
+ 0x07F8, 0x01F0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief ':'
+ */
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0180, 0x0180,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0180, 0x0180, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief ';'
+ */
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0180, 0x0180,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0180, 0x0180, 0x0100, 0x0100, 0x0080, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief '<'
+ */
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x1000, 0x1C00, 0x0F80, 0x03E0, 0x00F8, 0x0018, 0x00F8, 0x03E0,
+ 0x0F80, 0x1C00, 0x1000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief '='
+ */
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x1FF8, 0x0000, 0x0000, 0x0000, 0x1FF8, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief '>'
+ */
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0008, 0x0038, 0x01F0, 0x07C0, 0x1F00, 0x1800, 0x1F00, 0x07C0,
+ 0x01F0, 0x0038, 0x0008, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief '?'
+ */
+ 0x0000, 0x03E0, 0x0FF8, 0x0C18, 0x180C, 0x180C, 0x1800, 0x0C00,
+ 0x0600, 0x0300, 0x0180, 0x00C0, 0x00C0, 0x00C0, 0x0000, 0x0000,
+ 0x00C0, 0x00C0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief '@'
+ */
+ 0x0000, 0x0000, 0x07E0, 0x1818, 0x2004, 0x29C2, 0x4A22, 0x4411,
+ 0x4409, 0x4409, 0x4409, 0x2209, 0x1311, 0x0CE2, 0x4002, 0x2004,
+ 0x1818, 0x07E0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief 'A'
+ */
+ 0x0000, 0x0380, 0x0380, 0x06C0, 0x06C0, 0x06C0, 0x0C60, 0x0C60,
+ 0x1830, 0x1830, 0x1830, 0x3FF8, 0x3FF8, 0x701C, 0x600C, 0x600C,
+ 0xC006, 0xC006, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief 'B'
+ */
+ 0x0000, 0x03FC, 0x0FFC, 0x0C0C, 0x180C, 0x180C, 0x180C, 0x0C0C,
+ 0x07FC, 0x0FFC, 0x180C, 0x300C, 0x300C, 0x300C, 0x300C, 0x180C,
+ 0x1FFC, 0x07FC, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief 'C'
+ */
+ 0x0000, 0x07C0, 0x1FF0, 0x3838, 0x301C, 0x700C, 0x6006, 0x0006,
+ 0x0006, 0x0006, 0x0006, 0x0006, 0x0006, 0x6006, 0x700C, 0x301C,
+ 0x1FF0, 0x07E0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief 'D'
+ */
+ 0x0000, 0x03FE, 0x0FFE, 0x0E06, 0x1806, 0x1806, 0x3006, 0x3006,
+ 0x3006, 0x3006, 0x3006, 0x3006, 0x3006, 0x1806, 0x1806, 0x0E06,
+ 0x0FFE, 0x03FE, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief 'E'
+ */
+ 0x0000, 0x3FFC, 0x3FFC, 0x000C, 0x000C, 0x000C, 0x000C, 0x000C,
+ 0x1FFC, 0x1FFC, 0x000C, 0x000C, 0x000C, 0x000C, 0x000C, 0x000C,
+ 0x3FFC, 0x3FFC, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief 'F'
+ */
+ 0x0000, 0x3FF8, 0x3FF8, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018,
+ 0x1FF8, 0x1FF8, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018,
+ 0x0018, 0x0018, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief 'G'
+ */
+ 0x0000, 0x0FE0, 0x3FF8, 0x783C, 0x600E, 0xE006, 0xC007, 0x0003,
+ 0x0003, 0xFE03, 0xFE03, 0xC003, 0xC007, 0xC006, 0xC00E, 0xF03C,
+ 0x3FF8, 0x0FE0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief 'H'
+ */
+ 0x0000, 0x300C, 0x300C, 0x300C, 0x300C, 0x300C, 0x300C, 0x300C,
+ 0x3FFC, 0x3FFC, 0x300C, 0x300C, 0x300C, 0x300C, 0x300C, 0x300C,
+ 0x300C, 0x300C, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief 'I'
+ */
+ 0x0000, 0x0180, 0x0180, 0x0180, 0x0180, 0x0180, 0x0180, 0x0180,
+ 0x0180, 0x0180, 0x0180, 0x0180, 0x0180, 0x0180, 0x0180, 0x0180,
+ 0x0180, 0x0180, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief 'J'
+ */
+ 0x0000, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600,
+ 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0618, 0x0618, 0x0738,
+ 0x03F0, 0x01E0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief 'K'
+ */
+ 0x0000, 0x3006, 0x1806, 0x0C06, 0x0606, 0x0306, 0x0186, 0x00C6,
+ 0x0066, 0x0076, 0x00DE, 0x018E, 0x0306, 0x0606, 0x0C06, 0x1806,
+ 0x3006, 0x6006, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief 'L'
+ */
+ 0x0000, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018,
+ 0x0018, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018,
+ 0x1FF8, 0x1FF8, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief 'M'
+ */
+ 0x0000, 0xE00E, 0xF01E, 0xF01E, 0xF01E, 0xD836, 0xD836, 0xD836,
+ 0xD836, 0xCC66, 0xCC66, 0xCC66, 0xC6C6, 0xC6C6, 0xC6C6, 0xC6C6,
+ 0xC386, 0xC386, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief 'N'
+ */
+ 0x0000, 0x300C, 0x301C, 0x303C, 0x303C, 0x306C, 0x306C, 0x30CC,
+ 0x30CC, 0x318C, 0x330C, 0x330C, 0x360C, 0x360C, 0x3C0C, 0x3C0C,
+ 0x380C, 0x300C, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief 'O'
+ */
+ 0x0000, 0x07E0, 0x1FF8, 0x381C, 0x700E, 0x6006, 0xC003, 0xC003,
+ 0xC003, 0xC003, 0xC003, 0xC003, 0xC003, 0x6006, 0x700E, 0x381C,
+ 0x1FF8, 0x07E0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief 'P'
+ */
+ 0x0000, 0x0FFC, 0x1FFC, 0x380C, 0x300C, 0x300C, 0x300C, 0x300C,
+ 0x180C, 0x1FFC, 0x07FC, 0x000C, 0x000C, 0x000C, 0x000C, 0x000C,
+ 0x000C, 0x000C, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief 'Q'
+ */
+ 0x0000, 0x07E0, 0x1FF8, 0x381C, 0x700E, 0x6006, 0xE003, 0xC003,
+ 0xC003, 0xC003, 0xC003, 0xC003, 0xE007, 0x6306, 0x3F0E, 0x3C1C,
+ 0x3FF8, 0xF7E0, 0xC000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief 'R'
+ */
+ 0x0000, 0x0FFE, 0x1FFE, 0x3806, 0x3006, 0x3006, 0x3006, 0x3806,
+ 0x1FFE, 0x07FE, 0x0306, 0x0606, 0x0C06, 0x1806, 0x1806, 0x3006,
+ 0x3006, 0x6006, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief 'S'
+ */
+ 0x0000, 0x03E0, 0x0FF8, 0x0C1C, 0x180C, 0x180C, 0x000C, 0x001C,
+ 0x03F8, 0x0FE0, 0x1E00, 0x3800, 0x3006, 0x3006, 0x300E, 0x1C1C,
+ 0x0FF8, 0x07E0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief 'T'
+ */
+ 0x0000, 0x7FFE, 0x7FFE, 0x0180, 0x0180, 0x0180, 0x0180, 0x0180,
+ 0x0180, 0x0180, 0x0180, 0x0180, 0x0180, 0x0180, 0x0180, 0x0180,
+ 0x0180, 0x0180, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief 'U'
+ */
+ 0x0000, 0x300C, 0x300C, 0x300C, 0x300C, 0x300C, 0x300C, 0x300C,
+ 0x300C, 0x300C, 0x300C, 0x300C, 0x300C, 0x300C, 0x300C, 0x1818,
+ 0x1FF8, 0x07E0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief 'V'
+ */
+ 0x0000, 0x6003, 0x3006, 0x3006, 0x3006, 0x180C, 0x180C, 0x180C,
+ 0x0C18, 0x0C18, 0x0E38, 0x0630, 0x0630, 0x0770, 0x0360, 0x0360,
+ 0x01C0, 0x01C0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief 'W'
+ */
+ 0x0000, 0x6003, 0x61C3, 0x61C3, 0x61C3, 0x3366, 0x3366, 0x3366,
+ 0x3366, 0x3366, 0x3366, 0x1B6C, 0x1B6C, 0x1B6C, 0x1A2C, 0x1E3C,
+ 0x0E38, 0x0E38, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief 'X'
+ */
+ 0x0000, 0xE00F, 0x700C, 0x3018, 0x1830, 0x0C70, 0x0E60, 0x07C0,
+ 0x0380, 0x0380, 0x03C0, 0x06E0, 0x0C70, 0x1C30, 0x1818, 0x300C,
+ 0x600E, 0xE007, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief 'Y'
+ */
+ 0x0000, 0xC003, 0x6006, 0x300C, 0x381C, 0x1838, 0x0C30, 0x0660,
+ 0x07E0, 0x03C0, 0x0180, 0x0180, 0x0180, 0x0180, 0x0180, 0x0180,
+ 0x0180, 0x0180, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief 'Z'
+ */
+ 0x0000, 0x7FFC, 0x7FFC, 0x6000, 0x3000, 0x1800, 0x0C00, 0x0600,
+ 0x0300, 0x0180, 0x00C0, 0x0060, 0x0030, 0x0018, 0x000C, 0x0006,
+ 0x7FFE, 0x7FFE, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief '['
+ */
+ 0x0000, 0x03E0, 0x03E0, 0x0060, 0x0060, 0x0060, 0x0060, 0x0060,
+ 0x0060, 0x0060, 0x0060, 0x0060, 0x0060, 0x0060, 0x0060, 0x0060,
+ 0x0060, 0x0060, 0x0060, 0x0060, 0x0060, 0x03E0, 0x03E0, 0x0000,
+/**
+ * @brief '\'
+ */
+ 0x0000, 0x0030, 0x0030, 0x0060, 0x0060, 0x0060, 0x00C0, 0x00C0,
+ 0x00C0, 0x01C0, 0x0180, 0x0180, 0x0180, 0x0300, 0x0300, 0x0300,
+ 0x0600, 0x0600, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief ']'
+ */
+ 0x0000, 0x03E0, 0x03E0, 0x0300, 0x0300, 0x0300, 0x0300, 0x0300,
+ 0x0300, 0x0300, 0x0300, 0x0300, 0x0300, 0x0300, 0x0300, 0x0300,
+ 0x0300, 0x0300, 0x0300, 0x0300, 0x0300, 0x03E0, 0x03E0, 0x0000,
+/**
+ * @brief '^'
+ */
+ 0x0000, 0x0000, 0x01C0, 0x01C0, 0x0360, 0x0360, 0x0360, 0x0630,
+ 0x0630, 0x0C18, 0x0C18, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief '_'
+ */
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0xFFFF, 0xFFFF, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief '''
+ */
+ 0x0000, 0x000C, 0x000C, 0x000C, 0x000C, 0x000C, 0x000C, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief 'a'
+ */
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x03F0, 0x07F8,
+ 0x0C1C, 0x0C0C, 0x0F00, 0x0FF0, 0x0CF8, 0x0C0C, 0x0C0C, 0x0F1C,
+ 0x0FF8, 0x18F0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief 'b'
+ */
+ 0x0000, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018, 0x03D8, 0x0FF8,
+ 0x0C38, 0x1818, 0x1818, 0x1818, 0x1818, 0x1818, 0x1818, 0x0C38,
+ 0x0FF8, 0x03D8, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief 'c'
+ */
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x03C0, 0x07F0,
+ 0x0E30, 0x0C18, 0x0018, 0x0018, 0x0018, 0x0018, 0x0C18, 0x0E30,
+ 0x07F0, 0x03C0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief 'd'
+ */
+ 0x0000, 0x1800, 0x1800, 0x1800, 0x1800, 0x1800, 0x1BC0, 0x1FF0,
+ 0x1C30, 0x1818, 0x1818, 0x1818, 0x1818, 0x1818, 0x1818, 0x1C30,
+ 0x1FF0, 0x1BC0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief 'e'
+ */
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x03C0, 0x0FF0,
+ 0x0C30, 0x1818, 0x1FF8, 0x1FF8, 0x0018, 0x0018, 0x1838, 0x1C30,
+ 0x0FF0, 0x07C0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief 'f'
+ */
+ 0x0000, 0x0F80, 0x0FC0, 0x00C0, 0x00C0, 0x00C0, 0x07F0, 0x07F0,
+ 0x00C0, 0x00C0, 0x00C0, 0x00C0, 0x00C0, 0x00C0, 0x00C0, 0x00C0,
+ 0x00C0, 0x00C0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief 'g'
+ */
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0DE0, 0x0FF8,
+ 0x0E18, 0x0C0C, 0x0C0C, 0x0C0C, 0x0C0C, 0x0C0C, 0x0C0C, 0x0E18,
+ 0x0FF8, 0x0DE0, 0x0C00, 0x0C0C, 0x061C, 0x07F8, 0x01F0, 0x0000,
+/**
+ * @brief 'h'
+ */
+ 0x0000, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018, 0x07D8, 0x0FF8,
+ 0x1C38, 0x1818, 0x1818, 0x1818, 0x1818, 0x1818, 0x1818, 0x1818,
+ 0x1818, 0x1818, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief 'i'
+ */
+ 0x0000, 0x00C0, 0x00C0, 0x0000, 0x0000, 0x0000, 0x00C0, 0x00C0,
+ 0x00C0, 0x00C0, 0x00C0, 0x00C0, 0x00C0, 0x00C0, 0x00C0, 0x00C0,
+ 0x00C0, 0x00C0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief 'j'
+ */
+ 0x0000, 0x00C0, 0x00C0, 0x0000, 0x0000, 0x0000, 0x00C0, 0x00C0,
+ 0x00C0, 0x00C0, 0x00C0, 0x00C0, 0x00C0, 0x00C0, 0x00C0, 0x00C0,
+ 0x00C0, 0x00C0, 0x00C0, 0x00C0, 0x00C0, 0x00F8, 0x0078, 0x0000,
+/**
+ * @brief 'k'
+ */
+ 0x0000, 0x000C, 0x000C, 0x000C, 0x000C, 0x000C, 0x0C0C, 0x060C,
+ 0x030C, 0x018C, 0x00CC, 0x006C, 0x00FC, 0x019C, 0x038C, 0x030C,
+ 0x060C, 0x0C0C, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief 'l'
+ */
+ 0x0000, 0x00C0, 0x00C0, 0x00C0, 0x00C0, 0x00C0, 0x00C0, 0x00C0,
+ 0x00C0, 0x00C0, 0x00C0, 0x00C0, 0x00C0, 0x00C0, 0x00C0, 0x00C0,
+ 0x00C0, 0x00C0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief 'm'
+ */
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x3C7C, 0x7EFF,
+ 0xE3C7, 0xC183, 0xC183, 0xC183, 0xC183, 0xC183, 0xC183, 0xC183,
+ 0xC183, 0xC183, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief 'n'
+ */
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0798, 0x0FF8,
+ 0x1C38, 0x1818, 0x1818, 0x1818, 0x1818, 0x1818, 0x1818, 0x1818,
+ 0x1818, 0x1818, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief 'o'
+ */
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x03C0, 0x0FF0,
+ 0x0C30, 0x1818, 0x1818, 0x1818, 0x1818, 0x1818, 0x1818, 0x0C30,
+ 0x0FF0, 0x03C0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief 'p'
+ */
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x03D8, 0x0FF8,
+ 0x0C38, 0x1818, 0x1818, 0x1818, 0x1818, 0x1818, 0x1818, 0x0C38,
+ 0x0FF8, 0x03D8, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018, 0x0000,
+/**
+ * @brief 'q'
+ */
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x1BC0, 0x1FF0,
+ 0x1C30, 0x1818, 0x1818, 0x1818, 0x1818, 0x1818, 0x1818, 0x1C30,
+ 0x1FF0, 0x1BC0, 0x1800, 0x1800, 0x1800, 0x1800, 0x1800, 0x0000,
+/**
+ * @brief 'r'
+ */
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x07B0, 0x03F0,
+ 0x0070, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030,
+ 0x0030, 0x0030, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief 's'
+ */
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x03E0, 0x03F0,
+ 0x0E38, 0x0C18, 0x0038, 0x03F0, 0x07C0, 0x0C00, 0x0C18, 0x0E38,
+ 0x07F0, 0x03E0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief 't'
+ */
+ 0x0000, 0x0000, 0x0080, 0x00C0, 0x00C0, 0x00C0, 0x07F0, 0x07F0,
+ 0x00C0, 0x00C0, 0x00C0, 0x00C0, 0x00C0, 0x00C0, 0x00C0, 0x00C0,
+ 0x07C0, 0x0780, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief 'u'
+ */
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x1818, 0x1818,
+ 0x1818, 0x1818, 0x1818, 0x1818, 0x1818, 0x1818, 0x1818, 0x1C38,
+ 0x1FF0, 0x19E0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief 'v'
+ */
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x180C, 0x0C18,
+ 0x0C18, 0x0C18, 0x0630, 0x0630, 0x0630, 0x0360, 0x0360, 0x0360,
+ 0x01C0, 0x01C0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief 'w'
+ */
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x41C1, 0x41C1,
+ 0x61C3, 0x6363, 0x6363, 0x6363, 0x3636, 0x3636, 0x3636, 0x1C1C,
+ 0x1C1C, 0x1C1C, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief 'x'
+ */
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x381C, 0x1C38,
+ 0x0C30, 0x0660, 0x0360, 0x0360, 0x0360, 0x0360, 0x0660, 0x0C30,
+ 0x1C38, 0x381C, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief 'y'
+ */
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x3018, 0x1830,
+ 0x1830, 0x1870, 0x0C60, 0x0C60, 0x0CE0, 0x06C0, 0x06C0, 0x0380,
+ 0x0380, 0x0380, 0x0180, 0x0180, 0x01C0, 0x00F0, 0x0070, 0x0000,
+/**
+ * @brief 'z'
+ */
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x1FFC, 0x1FFC,
+ 0x0C00, 0x0600, 0x0300, 0x0180, 0x00C0, 0x0060, 0x0030, 0x0018,
+ 0x1FFC, 0x1FFC, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+/**
+ * @brief '{'
+ */
+ 0x0000, 0x0300, 0x0180, 0x00C0, 0x00C0, 0x00C0, 0x00C0, 0x00C0,
+ 0x00C0, 0x0060, 0x0060, 0x0030, 0x0060, 0x0040, 0x00C0, 0x00C0,
+ 0x00C0, 0x00C0, 0x00C0, 0x00C0, 0x0180, 0x0300, 0x0000, 0x0000,
+/**
+ * @brief '|'
+ */
+ 0x0000, 0x0180, 0x0180, 0x0180, 0x0180, 0x0180, 0x0180, 0x0180,
+ 0x0180, 0x0180, 0x0180, 0x0180, 0x0180, 0x0180, 0x0180, 0x0180,
+ 0x0180, 0x0180, 0x0180, 0x0180, 0x0180, 0x0180, 0x0180, 0x0000,
+/**
+ * @brief '}'
+ */
+ 0x0000, 0x0060, 0x00C0, 0x01C0, 0x0180, 0x0180, 0x0180, 0x0180,
+ 0x0180, 0x0300, 0x0300, 0x0600, 0x0300, 0x0100, 0x0180, 0x0180,
+ 0x0180, 0x0180, 0x0180, 0x0180, 0x00C0, 0x0060, 0x0000, 0x0000,
+/**
+ * @brief '~'
+ */
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x10F0, 0x1FF8, 0x0F08, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000};
+
+const uint16_t ASCII12x12_Table [] = {
+ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
+ 0x0000,0x2000,0x2000,0x2000,0x2000,0x2000,0x2000,0x2000,0x0000,0x2000,0x0000,0x0000,
+ 0x0000,0x5000,0x5000,0x5000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
+ 0x0000,0x0900,0x0900,0x1200,0x7f00,0x1200,0x7f00,0x1200,0x2400,0x2400,0x0000,0x0000,
+ 0x1000,0x3800,0x5400,0x5000,0x5000,0x3800,0x1400,0x5400,0x5400,0x3800,0x1000,0x0000,
+ 0x0000,0x3080,0x4900,0x4900,0x4a00,0x32c0,0x0520,0x0920,0x0920,0x10c0,0x0000,0x0000,
+ 0x0000,0x0c00,0x1200,0x1200,0x1400,0x1800,0x2500,0x2300,0x2300,0x1d80,0x0000,0x0000,
+ 0x0000,0x4000,0x4000,0x4000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
+ 0x0000,0x0800,0x1000,0x1000,0x2000,0x2000,0x2000,0x2000,0x2000,0x2000,0x1000,0x1000,
+ 0x0000,0x4000,0x2000,0x2000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x2000,0x2000,
+ 0x0000,0x2000,0x7000,0x2000,0x5000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
+ 0x0000,0x0000,0x0000,0x0800,0x0800,0x7f00,0x0800,0x0800,0x0000,0x0000,0x0000,0x0000,
+ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x2000,0x2000,0x4000,
+ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x7000,0x0000,0x0000,0x0000,0x0000,0x0000,
+ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x2000,0x0000,0x0000,
+ 0x0000,0x1000,0x1000,0x1000,0x2000,0x2000,0x2000,0x2000,0x4000,0x4000,0x0000,0x0000,
+ 0x0000,0x1000,0x2800,0x4400,0x4400,0x4400,0x4400,0x4400,0x2800,0x1000,0x0000,0x0000,
+ 0x0000,0x1000,0x3000,0x5000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x0000,0x0000,
+ 0x0000,0x3000,0x4800,0x4400,0x0400,0x0800,0x1000,0x2000,0x4000,0x7c00,0x0000,0x0000,
+ 0x0000,0x3000,0x4800,0x0400,0x0800,0x1000,0x0800,0x4400,0x4800,0x3000,0x0000,0x0000,
+ 0x0000,0x0800,0x1800,0x1800,0x2800,0x2800,0x4800,0x7c00,0x0800,0x0800,0x0000,0x0000,
+ 0x0000,0x3c00,0x2000,0x4000,0x7000,0x4800,0x0400,0x4400,0x4800,0x3000,0x0000,0x0000,
+ 0x0000,0x1800,0x2400,0x4000,0x5000,0x6800,0x4400,0x4400,0x2800,0x1000,0x0000,0x0000,
+ 0x0000,0x7c00,0x0400,0x0800,0x1000,0x1000,0x1000,0x2000,0x2000,0x2000,0x0000,0x0000,
+ 0x0000,0x1000,0x2800,0x4400,0x2800,0x1000,0x2800,0x4400,0x2800,0x1000,0x0000,0x0000,
+ 0x0000,0x1000,0x2800,0x4400,0x4400,0x2c00,0x1400,0x0400,0x4800,0x3000,0x0000,0x0000,
+ 0x0000,0x0000,0x0000,0x2000,0x0000,0x0000,0x0000,0x0000,0x0000,0x2000,0x0000,0x0000,
+ 0x0000,0x0000,0x0000,0x2000,0x0000,0x0000,0x0000,0x0000,0x0000,0x2000,0x2000,0x4000,
+ 0x0000,0x0000,0x0400,0x0800,0x3000,0x4000,0x3000,0x0800,0x0400,0x0000,0x0000,0x0000,
+ 0x0000,0x0000,0x0000,0x7c00,0x0000,0x0000,0x7c00,0x0000,0x0000,0x0000,0x0000,0x0000,
+ 0x0000,0x0000,0x4000,0x2000,0x1800,0x0400,0x1800,0x2000,0x4000,0x0000,0x0000,0x0000,
+ 0x0000,0x3800,0x6400,0x4400,0x0400,0x0800,0x1000,0x1000,0x0000,0x1000,0x0000,0x0000,
+ 0x0000,0x0f80,0x1040,0x2ea0,0x51a0,0x5120,0x5120,0x5120,0x5320,0x4dc0,0x2020,0x1040,
+ 0x0000,0x0800,0x1400,0x1400,0x1400,0x2200,0x3e00,0x2200,0x4100,0x4100,0x0000,0x0000,
+ 0x0000,0x3c00,0x2200,0x2200,0x2200,0x3c00,0x2200,0x2200,0x2200,0x3c00,0x0000,0x0000,
+ 0x0000,0x0e00,0x1100,0x2100,0x2000,0x2000,0x2000,0x2100,0x1100,0x0e00,0x0000,0x0000,
+ 0x0000,0x3c00,0x2200,0x2100,0x2100,0x2100,0x2100,0x2100,0x2200,0x3c00,0x0000,0x0000,
+ 0x0000,0x3e00,0x2000,0x2000,0x2000,0x3e00,0x2000,0x2000,0x2000,0x3e00,0x0000,0x0000,
+ 0x0000,0x3e00,0x2000,0x2000,0x2000,0x3c00,0x2000,0x2000,0x2000,0x2000,0x0000,0x0000,
+ 0x0000,0x0e00,0x1100,0x2100,0x2000,0x2700,0x2100,0x2100,0x1100,0x0e00,0x0000,0x0000,
+ 0x0000,0x2100,0x2100,0x2100,0x2100,0x3f00,0x2100,0x2100,0x2100,0x2100,0x0000,0x0000,
+ 0x0000,0x2000,0x2000,0x2000,0x2000,0x2000,0x2000,0x2000,0x2000,0x2000,0x0000,0x0000,
+ 0x0000,0x0800,0x0800,0x0800,0x0800,0x0800,0x0800,0x4800,0x4800,0x3000,0x0000,0x0000,
+ 0x0000,0x2200,0x2400,0x2800,0x2800,0x3800,0x2800,0x2400,0x2400,0x2200,0x0000,0x0000,
+ 0x0000,0x2000,0x2000,0x2000,0x2000,0x2000,0x2000,0x2000,0x2000,0x3e00,0x0000,0x0000,
+ 0x0000,0x2080,0x3180,0x3180,0x3180,0x2a80,0x2a80,0x2a80,0x2a80,0x2480,0x0000,0x0000,
+ 0x0000,0x2100,0x3100,0x3100,0x2900,0x2900,0x2500,0x2300,0x2300,0x2100,0x0000,0x0000,
+ 0x0000,0x0c00,0x1200,0x2100,0x2100,0x2100,0x2100,0x2100,0x1200,0x0c00,0x0000,0x0000,
+ 0x0000,0x3c00,0x2200,0x2200,0x2200,0x3c00,0x2000,0x2000,0x2000,0x2000,0x0000,0x0000,
+ 0x0000,0x0c00,0x1200,0x2100,0x2100,0x2100,0x2100,0x2100,0x1600,0x0d00,0x0100,0x0000,
+ 0x0000,0x3e00,0x2100,0x2100,0x2100,0x3e00,0x2400,0x2200,0x2100,0x2080,0x0000,0x0000,
+ 0x0000,0x1c00,0x2200,0x2200,0x2000,0x1c00,0x0200,0x2200,0x2200,0x1c00,0x0000,0x0000,
+ 0x0000,0x3e00,0x0800,0x0800,0x0800,0x0800,0x0800,0x0800,0x0800,0x0800,0x0000,0x0000,
+ 0x0000,0x2100,0x2100,0x2100,0x2100,0x2100,0x2100,0x2100,0x1200,0x0c00,0x0000,0x0000,
+ 0x0000,0x4100,0x4100,0x2200,0x2200,0x2200,0x1400,0x1400,0x1400,0x0800,0x0000,0x0000,
+ 0x0000,0x4440,0x4a40,0x2a40,0x2a80,0x2a80,0x2a80,0x2a80,0x2a80,0x1100,0x0000,0x0000,
+ 0x0000,0x4100,0x2200,0x1400,0x1400,0x0800,0x1400,0x1400,0x2200,0x4100,0x0000,0x0000,
+ 0x0000,0x4100,0x2200,0x2200,0x1400,0x0800,0x0800,0x0800,0x0800,0x0800,0x0000,0x0000,
+ 0x0000,0x7e00,0x0200,0x0400,0x0800,0x1000,0x1000,0x2000,0x4000,0x7e00,0x0000,0x0000,
+ 0x0000,0x3000,0x2000,0x2000,0x2000,0x2000,0x2000,0x2000,0x2000,0x2000,0x2000,0x2000,
+ 0x0000,0x4000,0x4000,0x2000,0x2000,0x2000,0x2000,0x2000,0x1000,0x1000,0x0000,0x0000,
+ 0x0000,0x6000,0x2000,0x2000,0x2000,0x2000,0x2000,0x2000,0x2000,0x2000,0x2000,0x2000,
+ 0x0000,0x1000,0x2800,0x2800,0x2800,0x4400,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
+ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x7e00,
+ 0x4000,0x2000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
+ 0x0000,0x0000,0x0000,0x3800,0x4400,0x0400,0x3c00,0x4400,0x4400,0x3c00,0x0000,0x0000,
+ 0x0000,0x4000,0x4000,0x5800,0x6400,0x4400,0x4400,0x4400,0x6400,0x5800,0x0000,0x0000,
+ 0x0000,0x0000,0x0000,0x3000,0x4800,0x4000,0x4000,0x4000,0x4800,0x3000,0x0000,0x0000,
+ 0x0000,0x0400,0x0400,0x3400,0x4c00,0x4400,0x4400,0x4400,0x4c00,0x3400,0x0000,0x0000,
+ 0x0000,0x0000,0x0000,0x3800,0x4400,0x4400,0x7c00,0x4000,0x4400,0x3800,0x0000,0x0000,
+ 0x0000,0x6000,0x4000,0xe000,0x4000,0x4000,0x4000,0x4000,0x4000,0x4000,0x0000,0x0000,
+ 0x0000,0x0000,0x0000,0x3400,0x4c00,0x4400,0x4400,0x4400,0x4c00,0x3400,0x0400,0x4400,
+ 0x0000,0x4000,0x4000,0x5800,0x6400,0x4400,0x4400,0x4400,0x4400,0x4400,0x0000,0x0000,
+ 0x0000,0x4000,0x0000,0x4000,0x4000,0x4000,0x4000,0x4000,0x4000,0x4000,0x0000,0x0000,
+ 0x0000,0x4000,0x0000,0x4000,0x4000,0x4000,0x4000,0x4000,0x4000,0x4000,0x4000,0x4000,
+ 0x0000,0x4000,0x4000,0x4800,0x5000,0x6000,0x5000,0x5000,0x4800,0x4800,0x0000,0x0000,
+ 0x0000,0x4000,0x4000,0x4000,0x4000,0x4000,0x4000,0x4000,0x4000,0x4000,0x0000,0x0000,
+ 0x0000,0x0000,0x0000,0x5200,0x6d00,0x4900,0x4900,0x4900,0x4900,0x4900,0x0000,0x0000,
+ 0x0000,0x0000,0x0000,0x5800,0x6400,0x4400,0x4400,0x4400,0x4400,0x4400,0x0000,0x0000,
+ 0x0000,0x0000,0x0000,0x3800,0x4400,0x4400,0x4400,0x4400,0x4400,0x3800,0x0000,0x0000,
+ 0x0000,0x0000,0x0000,0x5800,0x6400,0x4400,0x4400,0x4400,0x6400,0x5800,0x4000,0x4000,
+ 0x0000,0x0000,0x0000,0x3400,0x4c00,0x4400,0x4400,0x4400,0x4c00,0x3400,0x0400,0x0400,
+ 0x0000,0x0000,0x0000,0x5000,0x6000,0x4000,0x4000,0x4000,0x4000,0x4000,0x0000,0x0000,
+ 0x0000,0x0000,0x0000,0x3000,0x4800,0x4000,0x3000,0x0800,0x4800,0x3000,0x0000,0x0000,
+ 0x0000,0x4000,0x4000,0xe000,0x4000,0x4000,0x4000,0x4000,0x4000,0x6000,0x0000,0x0000,
+ 0x0000,0x0000,0x0000,0x4400,0x4400,0x4400,0x4400,0x4400,0x4c00,0x3400,0x0000,0x0000,
+ 0x0000,0x0000,0x0000,0x4400,0x4400,0x2800,0x2800,0x2800,0x2800,0x1000,0x0000,0x0000,
+ 0x0000,0x0000,0x0000,0x4900,0x4900,0x5500,0x5500,0x5500,0x5500,0x2200,0x0000,0x0000,
+ 0x0000,0x0000,0x0000,0x4400,0x2800,0x2800,0x1000,0x2800,0x2800,0x4400,0x0000,0x0000,
+ 0x0000,0x0000,0x0000,0x4400,0x4400,0x2800,0x2800,0x2800,0x1000,0x1000,0x1000,0x1000,
+ 0x0000,0x0000,0x0000,0x7800,0x0800,0x1000,0x2000,0x2000,0x4000,0x7800,0x0000,0x0000,
+ 0x0000,0x1000,0x2000,0x2000,0x2000,0x2000,0x4000,0x2000,0x2000,0x2000,0x2000,0x2000,
+ 0x0000,0x2000,0x2000,0x2000,0x2000,0x2000,0x2000,0x2000,0x2000,0x2000,0x2000,0x2000,
+ 0x0000,0x4000,0x2000,0x2000,0x2000,0x2000,0x1000,0x2000,0x2000,0x2000,0x2000,0x2000,
+ 0x0000,0x0000,0x0000,0x0000,0x7400,0x5800,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
+ 0x0000,0x0000,0x7000,0x5000,0x5000,0x5000,0x5000,0x5000,0x5000,0x7000,0x0000,0x0000};
+
+const uint16_t ASCII8x12_Table [] = {
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+ 0x00,0x00,0x00,0x10,0x10,0x10,0x10,0x10,0x10,0x00,0x10,0x00,
+ 0x00,0x00,0x00,0x28,0x28,0x28,0x00,0x00,0x00,0x00,0x00,0x00,
+ 0x00,0x00,0x00,0x14,0x14,0x3e,0x14,0x28,0x7c,0x28,0x28,0x00,
+ 0x00,0x00,0x10,0x38,0x54,0x50,0x38,0x14,0x14,0x54,0x38,0x10,
+ 0x00,0x00,0x00,0x44,0xa8,0xa8,0x50,0x14,0x1a,0x2a,0x24,0x00,
+ 0x00,0x00,0x00,0x20,0x50,0x50,0x20,0xe8,0x98,0x98,0x60,0x00,
+ 0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,
+ 0x00,0x00,0x00,0x40,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
+ 0x00,0x00,0x00,0x80,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,
+ 0x00,0x00,0x00,0x40,0xe0,0x40,0xa0,0x00,0x00,0x00,0x00,0x00,
+ 0x00,0x00,0x00,0x00,0x00,0x20,0x20,0xf8,0x20,0x20,0x00,0x00,
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x40,
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xc0,0x00,0x00,0x00,
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,
+ 0x00,0x00,0x00,0x20,0x20,0x20,0x40,0x40,0x80,0x80,0x80,0x00,
+ 0x00,0x00,0x00,0x60,0x90,0x90,0x90,0x90,0x90,0x90,0x60,0x00,
+ 0x00,0x00,0x00,0x20,0x60,0xa0,0x20,0x20,0x20,0x20,0x20,0x00,
+ 0x00,0x00,0x00,0x60,0x90,0x10,0x10,0x20,0x40,0x80,0xf0,0x00,
+ 0x00,0x00,0x00,0x60,0x90,0x10,0x60,0x10,0x10,0x90,0x60,0x00,
+ 0x00,0x00,0x00,0x10,0x30,0x50,0x50,0x90,0xf8,0x10,0x10,0x00,
+ 0x00,0x00,0x00,0x70,0x40,0x80,0xe0,0x10,0x10,0x90,0x60,0x00,
+ 0x00,0x00,0x00,0x60,0x90,0x80,0xa0,0xd0,0x90,0x90,0x60,0x00,
+ 0x00,0x00,0x00,0xf0,0x10,0x20,0x20,0x20,0x40,0x40,0x40,0x00,
+ 0x00,0x00,0x00,0x60,0x90,0x90,0x60,0x90,0x90,0x90,0x60,0x00,
+ 0x00,0x00,0x00,0x60,0x90,0x90,0xb0,0x50,0x10,0x90,0x60,0x00,
+ 0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x40,0x00,
+ 0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x40,0x40,
+ 0x00,0x00,0x00,0x00,0x00,0x10,0x60,0x80,0x60,0x10,0x00,0x00,
+ 0x00,0x00,0x00,0x00,0x00,0x00,0xf0,0x00,0xf0,0x00,0x00,0x00,
+ 0x00,0x00,0x00,0x00,0x00,0x80,0x60,0x10,0x60,0x80,0x00,0x00,
+ 0x00,0x00,0x00,0x60,0x90,0x10,0x20,0x40,0x40,0x00,0x40,0x00,
+ 0x00,0x00,0x00,0x1c,0x22,0x5b,0xa5,0xa5,0xa5,0xa5,0x9e,0x41,
+ 0x00,0x00,0x00,0x20,0x50,0x50,0x50,0x50,0x70,0x88,0x88,0x00,
+ 0x00,0x00,0x00,0xf0,0x88,0x88,0xf0,0x88,0x88,0x88,0xf0,0x00,
+ 0x00,0x00,0x00,0x38,0x44,0x84,0x80,0x80,0x84,0x44,0x38,0x00,
+ 0x00,0x00,0x00,0xe0,0x90,0x88,0x88,0x88,0x88,0x90,0xe0,0x00,
+ 0x00,0x00,0x00,0xf8,0x80,0x80,0xf8,0x80,0x80,0x80,0xf8,0x00,
+ 0x00,0x00,0x00,0x78,0x40,0x40,0x70,0x40,0x40,0x40,0x40,0x00,
+ 0x00,0x00,0x00,0x38,0x44,0x84,0x80,0x9c,0x84,0x44,0x38,0x00,
+ 0x00,0x00,0x00,0x88,0x88,0x88,0xf8,0x88,0x88,0x88,0x88,0x00,
+ 0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,
+ 0x00,0x00,0x00,0x10,0x10,0x10,0x10,0x10,0x90,0x90,0x60,0x00,
+ 0x00,0x00,0x00,0x88,0x90,0xa0,0xe0,0xa0,0x90,0x90,0x88,0x00,
+ 0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0xf0,0x00,
+ 0x00,0x00,0x00,0x82,0xc6,0xc6,0xaa,0xaa,0xaa,0xaa,0x92,0x00,
+ 0x00,0x00,0x00,0x84,0xc4,0xa4,0xa4,0x94,0x94,0x8c,0x84,0x00,
+ 0x00,0x00,0x00,0x30,0x48,0x84,0x84,0x84,0x84,0x48,0x30,0x00,
+ 0x00,0x00,0x00,0xf0,0x88,0x88,0x88,0xf0,0x80,0x80,0x80,0x00,
+ 0x00,0x00,0x00,0x30,0x48,0x84,0x84,0x84,0x84,0x58,0x34,0x04,
+ 0x00,0x00,0x00,0x78,0x44,0x44,0x78,0x50,0x48,0x44,0x42,0x00,
+ 0x00,0x00,0x00,0x70,0x88,0x80,0x70,0x08,0x88,0x88,0x70,0x00,
+ 0x00,0x00,0x00,0xf8,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x00,
+ 0x00,0x00,0x00,0x84,0x84,0x84,0x84,0x84,0x84,0x48,0x30,0x00,
+ 0x00,0x00,0x00,0x88,0x88,0x50,0x50,0x50,0x50,0x50,0x20,0x00,
+ 0x00,0x00,0x00,0x92,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0x44,0x00,
+ 0x00,0x00,0x00,0x84,0x48,0x48,0x30,0x30,0x48,0x48,0x84,0x00,
+ 0x00,0x00,0x00,0x88,0x50,0x50,0x20,0x20,0x20,0x20,0x20,0x00,
+ 0x00,0x00,0x00,0xf8,0x08,0x10,0x20,0x20,0x40,0x80,0xf8,0x00,
+ 0x00,0x00,0x00,0xc0,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
+ 0x00,0x00,0x00,0x80,0x80,0x40,0x40,0x40,0x40,0x20,0x20,0x00,
+ 0x00,0x00,0x00,0xc0,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,
+ 0x00,0x00,0x00,0x40,0xa0,0xa0,0xa0,0x00,0x00,0x00,0x00,0x00,
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xf8,
+ 0x00,0x00,0x00,0x80,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+ 0x00,0x00,0x00,0x00,0x00,0xe0,0x10,0x70,0x90,0x90,0x70,0x00,
+ 0x00,0x00,0x00,0x80,0x80,0xa0,0xd0,0x90,0x90,0xd0,0xa0,0x00,
+ 0x00,0x00,0x00,0x00,0x00,0x60,0x90,0x80,0x80,0x90,0x60,0x00,
+ 0x00,0x00,0x00,0x10,0x10,0x50,0xb0,0x90,0x90,0xb0,0x50,0x00,
+ 0x00,0x00,0x00,0x00,0x00,0x60,0x90,0xf0,0x80,0x90,0x60,0x00,
+ 0x00,0x00,0x00,0xc0,0x80,0xc0,0x80,0x80,0x80,0x80,0x80,0x00,
+ 0x00,0x00,0x00,0x00,0x00,0x50,0xb0,0x90,0x90,0xb0,0x50,0x10,
+ 0x00,0x00,0x00,0x80,0x80,0xa0,0xd0,0x90,0x90,0x90,0x90,0x00,
+ 0x00,0x00,0x00,0x80,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x00,
+ 0x00,0x00,0x00,0x80,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
+ 0x00,0x00,0x00,0x80,0x80,0x90,0xa0,0xc0,0xa0,0x90,0x90,0x00,
+ 0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,
+ 0x00,0x00,0x00,0x00,0x00,0xa6,0xda,0x92,0x92,0x92,0x92,0x00,
+ 0x00,0x00,0x00,0x00,0x00,0xa0,0xd0,0x90,0x90,0x90,0x90,0x00,
+ 0x00,0x00,0x00,0x00,0x00,0x60,0x90,0x90,0x90,0x90,0x60,0x00,
+ 0x00,0x00,0x00,0x00,0x00,0xa0,0xd0,0x90,0x90,0xd0,0xa0,0x80,
+ 0x00,0x00,0x00,0x00,0x00,0x50,0xb0,0x90,0x90,0xb0,0x50,0x10,
+ 0x00,0x00,0x00,0x00,0x00,0xa0,0xc0,0x80,0x80,0x80,0x80,0x00,
+ 0x00,0x00,0x00,0x00,0x00,0xe0,0x90,0x40,0x20,0x90,0x60,0x00,
+ 0x00,0x00,0x00,0x80,0x80,0xc0,0x80,0x80,0x80,0x80,0xc0,0x00,
+ 0x00,0x00,0x00,0x00,0x00,0x90,0x90,0x90,0x90,0xb0,0x50,0x00,
+ 0x00,0x00,0x00,0x00,0x00,0x88,0x88,0x50,0x50,0x50,0x20,0x00,
+ 0x00,0x00,0x00,0x00,0x00,0x92,0xaa,0xaa,0xaa,0xaa,0x44,0x00,
+ 0x00,0x00,0x00,0x00,0x00,0x88,0x50,0x20,0x20,0x50,0x88,0x00,
+ 0x00,0x00,0x00,0x00,0x00,0x88,0x50,0x50,0x50,0x20,0x20,0x20,
+ 0x00,0x00,0x00,0x00,0x00,0xf0,0x10,0x20,0x40,0x80,0xf0,0x00,
+ 0x00,0x00,0x00,0xc0,0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x80,
+ 0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
+ 0x00,0x00,0x00,0xc0,0x40,0x40,0x40,0x20,0x40,0x40,0x40,0x40,
+ 0x00,0x00,0x00,0x00,0x00,0x00,0xe8,0xb0,0x00,0x00,0x00,0x00,
+ 0x00,0x00,0x00,0x00,0xe0,0xa0,0xa0,0xa0,0xa0,0xa0,0xe0,0x00};
+
+const uint16_t ASCII8x8_Table [] = {
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x00, 0x40,
+ 0xa0, 0xa0, 0xa0, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x24, 0x24, 0xfe, 0x48, 0xfc, 0x48, 0x48,
+ 0x38, 0x54, 0x50, 0x38, 0x14, 0x14, 0x54, 0x38,
+ 0x44, 0xa8, 0xa8, 0x50, 0x14, 0x1a, 0x2a, 0x24,
+ 0x10, 0x28, 0x28, 0x10, 0x74, 0x4c, 0x4c, 0x30,
+ 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x08, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x08,
+ 0x10, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x10,
+ 0x00, 0x00, 0x24, 0x18, 0x3c, 0x18, 0x24, 0x00,
+ 0x00, 0x00, 0x10, 0x10, 0x7c, 0x10, 0x10, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x10,
+ 0x00, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18,
+ 0x08, 0x08, 0x08, 0x10, 0x10, 0x20, 0x20, 0x20,
+ 0x18, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x18,
+ 0x08, 0x18, 0x28, 0x08, 0x08, 0x08, 0x08, 0x08,
+ 0x38, 0x44, 0x00, 0x04, 0x08, 0x10, 0x20, 0x7c,
+ 0x18, 0x24, 0x04, 0x18, 0x04, 0x04, 0x24, 0x18,
+ 0x04, 0x0c, 0x14, 0x24, 0x44, 0x7e, 0x04, 0x04,
+ 0x3c, 0x20, 0x20, 0x38, 0x04, 0x04, 0x24, 0x18,
+ 0x18, 0x24, 0x20, 0x38, 0x24, 0x24, 0x24, 0x18,
+ 0x3c, 0x04, 0x08, 0x08, 0x08, 0x10, 0x10, 0x10,
+ 0x18, 0x24, 0x24, 0x18, 0x24, 0x24, 0x24, 0x18,
+ 0x18, 0x24, 0x24, 0x24, 0x1c, 0x04, 0x24, 0x18,
+ 0x00, 0x00, 0x10, 0x00, 0x00, 0x10, 0x00, 0x00,
+ 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x10, 0x00,
+ 0x00, 0x00, 0x04, 0x18, 0x20, 0x18, 0x04, 0x00,
+ 0x00, 0x00, 0x00, 0x3c, 0x00, 0x3c, 0x00, 0x00,
+ 0x00, 0x00, 0x20, 0x18, 0x04, 0x18, 0x20, 0x00,
+ 0x18, 0x24, 0x04, 0x08, 0x10, 0x10, 0x00, 0x10,
+ 0x3c, 0x42, 0x99, 0xa5, 0xa5, 0x9d, 0x42, 0x38,
+ 0x38, 0x44, 0x44, 0x44, 0x7c, 0x44, 0x44, 0x44,
+ 0x78, 0x44, 0x44, 0x78, 0x44, 0x44, 0x44, 0x78,
+ 0x1c, 0x22, 0x42, 0x40, 0x40, 0x42, 0x22, 0x1c,
+ 0x70, 0x48, 0x44, 0x44, 0x44, 0x44, 0x48, 0x70,
+ 0x7c, 0x40, 0x40, 0x7c, 0x40, 0x40, 0x40, 0x7c,
+ 0x3c, 0x20, 0x20, 0x38, 0x20, 0x20, 0x20, 0x20,
+ 0x1c, 0x22, 0x42, 0x40, 0x4e, 0x42, 0x22, 0x1c,
+ 0x44, 0x44, 0x44, 0x7c, 0x44, 0x44, 0x44, 0x44,
+ 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
+ 0x04, 0x04, 0x04, 0x04, 0x04, 0x24, 0x24, 0x18,
+ 0x44, 0x48, 0x50, 0x70, 0x50, 0x48, 0x48, 0x44,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x3c,
+ 0x82, 0xc6, 0xc6, 0xaa, 0xaa, 0xaa, 0xaa, 0x92,
+ 0x42, 0x62, 0x52, 0x52, 0x4a, 0x4a, 0x46, 0x42,
+ 0x18, 0x24, 0x42, 0x42, 0x42, 0x42, 0x24, 0x18,
+ 0x78, 0x44, 0x44, 0x44, 0x78, 0x40, 0x40, 0x40,
+ 0x18, 0x24, 0x42, 0x42, 0x42, 0x42, 0x2c, 0x1a,
+ 0x78, 0x44, 0x44, 0x78, 0x50, 0x48, 0x44, 0x42,
+ 0x38, 0x44, 0x40, 0x38, 0x04, 0x44, 0x44, 0x38,
+ 0x7c, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
+ 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x24, 0x18,
+ 0x44, 0x44, 0x28, 0x28, 0x28, 0x28, 0x28, 0x10,
+ 0x92, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0x44,
+ 0x42, 0x24, 0x24, 0x18, 0x18, 0x24, 0x24, 0x42,
+ 0x44, 0x28, 0x28, 0x10, 0x10, 0x10, 0x10, 0x10,
+ 0x7c, 0x04, 0x08, 0x10, 0x10, 0x20, 0x40, 0x7c,
+ 0x1c, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x1c,
+ 0x10, 0x10, 0x08, 0x08, 0x08, 0x08, 0x04, 0x04,
+ 0x1c, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x1c,
+ 0x10, 0x28, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x20, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x18, 0x04, 0x1c, 0x24, 0x24, 0x1c,
+ 0x20, 0x20, 0x28, 0x34, 0x24, 0x24, 0x34, 0x28,
+ 0x00, 0x00, 0x18, 0x24, 0x20, 0x20, 0x24, 0x18,
+ 0x04, 0x04, 0x14, 0x2c, 0x24, 0x24, 0x2c, 0x14,
+ 0x00, 0x00, 0x18, 0x24, 0x3c, 0x20, 0x24, 0x18,
+ 0x00, 0x18, 0x10, 0x10, 0x18, 0x10, 0x10, 0x10,
+ 0x00, 0x18, 0x24, 0x24, 0x18, 0x04, 0x24, 0x18,
+ 0x20, 0x20, 0x28, 0x34, 0x24, 0x24, 0x24, 0x24,
+ 0x10, 0x00, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
+ 0x08, 0x00, 0x08, 0x08, 0x08, 0x08, 0x28, 0x10,
+ 0x20, 0x20, 0x24, 0x28, 0x30, 0x28, 0x24, 0x24,
+ 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
+ 0x00, 0x00, 0xa6, 0xda, 0x92, 0x92, 0x92, 0x92,
+ 0x00, 0x00, 0x28, 0x34, 0x24, 0x24, 0x24, 0x24,
+ 0x00, 0x00, 0x18, 0x24, 0x24, 0x24, 0x24, 0x18,
+ 0x00, 0x28, 0x34, 0x24, 0x38, 0x20, 0x20, 0x20,
+ 0x00, 0x14, 0x2c, 0x24, 0x1c, 0x04, 0x04, 0x04,
+ 0x00, 0x00, 0x2c, 0x30, 0x20, 0x20, 0x20, 0x20,
+ 0x00, 0x00, 0x18, 0x24, 0x10, 0x08, 0x24, 0x18,
+ 0x00, 0x10, 0x38, 0x10, 0x10, 0x10, 0x10, 0x18,
+ 0x00, 0x00, 0x24, 0x24, 0x24, 0x24, 0x2c, 0x14,
+ 0x00, 0x00, 0x44, 0x44, 0x28, 0x28, 0x28, 0x10,
+ 0x00, 0x00, 0x92, 0xaa, 0xaa, 0xaa, 0xaa, 0x44,
+ 0x00, 0x00, 0x44, 0x28, 0x10, 0x10, 0x28, 0x44,
+ 0x00, 0x28, 0x28, 0x28, 0x10, 0x10, 0x10, 0x10,
+ 0x00, 0x00, 0x3c, 0x04, 0x08, 0x10, 0x20, 0x3c,
+ 0x00, 0x08, 0x10, 0x10, 0x20, 0x10, 0x10, 0x08,
+ 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
+ 0x00, 0x10, 0x08, 0x08, 0x04, 0x08, 0x08, 0x10,
+ 0x00, 0x00, 0x00, 0x60, 0x92, 0x0c, 0x00, 0x00,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
+
+
+sFONT Font16x24 = {
+ ASCII16x24_Table,
+ 16, /* Width */
+ 24, /* Height */
+};
+
+sFONT Font12x12 = {
+ ASCII12x12_Table,
+ 12, /* Width */
+ 12, /* Height */
+};
+
+sFONT Font8x12 = {
+ ASCII8x12_Table,
+ 8, /* Width */
+ 12, /* Height */
+};
+
+
+sFONT Font8x8 = {
+ ASCII8x8_Table,
+ 8, /* Width */
+ 8, /* Height */
+};
+
+/**
+ * @}
+ */
+
+
+/** @defgroup FONTS_Private_Function_Prototypes
+ * @{
+ */
+/**
+ * @}
+ */
+
+
+/** @defgroup FONTS_Private_Functions
+ * @{
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/Common/lcd_log.c b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/Common/lcd_log.c
new file mode 100644
index 0000000..203a17d
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/Common/lcd_log.c
@@ -0,0 +1,528 @@
+/**
+ ******************************************************************************
+ * @file lcd_log.c
+ * @author MCD Application Team
+ * @version V5.0.2
+ * @date 05-March-2012
+ * @brief This file provides all the LCD Log firmware functions.
+ *
+ * The LCD Log module allows to automatically set a header and footer
+ * on any application using the LCD display and allows to dump user,
+ * debug and error messages by using the following macros: LCD_ErrLog(),
+ * LCD_UsrLog() and LCD_DbgLog().
+ *
+ * It supports also the scroll feature by embedding an internal software
+ * cache for display. This feature allows to dump message sequentially
+ * on the display even if the number of displayed lines is bigger than
+ * the total number of line allowed by the display.
+ *
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.st.com/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+
+/* Includes ------------------------------------------------------------------*/
+#include "lcd_log.h"
+
+/** @addtogroup Utilities
+ * @{
+ */
+
+/** @addtogroup STM32_EVAL
+* @{
+*/
+
+/** @addtogroup Common
+ * @{
+ */
+
+/** @defgroup LCD_LOG
+* @brief LCD Log LCD_Application module
+* @{
+*/
+
+/** @defgroup LCD_LOG_Private_Types
+* @{
+*/
+/**
+* @}
+*/
+
+
+/** @defgroup LCD_LOG_Private_Defines
+* @{
+*/
+
+/**
+* @}
+*/
+
+
+/** @defgroup LCD_LOG_Private_Macros
+* @{
+*/
+/**
+* @}
+*/
+
+
+/** @defgroup LCD_LOG_Private_Variables
+* @{
+*/
+
+LCD_LOG_line LCD_CacheBuffer [LCD_CACHE_DEPTH];
+uint16_t LCD_LineColor;
+uint16_t LCD_CacheBuffer_xptr;
+uint16_t LCD_CacheBuffer_yptr_top;
+uint16_t LCD_CacheBuffer_yptr_bottom;
+
+uint16_t LCD_CacheBuffer_yptr_top_bak;
+uint16_t LCD_CacheBuffer_yptr_bottom_bak;
+
+FunctionalState LCD_CacheBuffer_yptr_invert;
+FunctionalState LCD_ScrollActive;
+FunctionalState LCD_Lock;
+FunctionalState LCD_Scrolled;
+uint16_t LCD_ScrollBackStep;
+
+/**
+* @}
+*/
+
+
+/** @defgroup LCD_LOG_Private_FunctionPrototypes
+* @{
+*/
+static void LCD_LOG_UpdateDisplay (void);
+/**
+* @}
+*/
+
+
+/** @defgroup LCD_LOG_Private_Functions
+* @{
+*/
+
+
+/**
+* @brief Init the LCD Log module
+* @param None
+* @retval None
+*/
+
+void LCD_LOG_Init ( void)
+{
+ /* Deinit LCD cache */
+ LCD_LOG_DeInit();
+ /* Clear the LCD */
+ LCD_Clear(Black);
+}
+
+/**
+* @brief DeInitializes the LCD Log module.
+* @param None
+* @retval None
+*/
+void LCD_LOG_DeInit(void)
+{
+ LCD_LineColor = LCD_LOG_DEFAULT_COLOR;
+ LCD_CacheBuffer_xptr = 0;
+ LCD_CacheBuffer_yptr_top = 0;
+ LCD_CacheBuffer_yptr_bottom = 0;
+
+ LCD_CacheBuffer_yptr_top_bak = 0;
+ LCD_CacheBuffer_yptr_bottom_bak = 0;
+
+ LCD_CacheBuffer_yptr_invert= ENABLE;
+ LCD_ScrollActive = DISABLE;
+ LCD_Lock = DISABLE;
+ LCD_Scrolled = DISABLE;
+ LCD_ScrollBackStep = 0;
+}
+
+/**
+* @brief Display the application header (title) on the LCD screen
+* @param Title : pointer to the string to be displayed
+* @retval None
+*/
+void LCD_LOG_SetHeader (uint8_t *Title)
+{
+ sFONT *cFont;
+ uint32_t size = 0 , idx;
+ uint8_t *ptr = Title;
+ uint8_t tmp[27];
+
+ /* center the header */
+ while (*ptr++) size ++ ;
+
+ /* truncate extra text */
+ if(size > 26)
+ {
+ size = 26;
+ }
+
+ for (idx = 0 ; idx < 27 ; idx ++)
+ {
+ tmp[idx] = ' ';
+ }
+
+ for (idx = 0 ; idx < size ; idx ++)
+ {
+ tmp[idx + (27 - size)/2] = Title[idx];
+ }
+
+ /* Clear the LCD */
+ LCD_Clear(Black);
+
+ /* Set the LCD Font */
+ LCD_SetFont (&Font12x12);
+
+ cFont = LCD_GetFont();
+ /* Set the LCD Text Color */
+ LCD_SetTextColor(White);
+ LCD_SetBackColor(Blue);
+ LCD_ClearLine(0);
+ LCD_DisplayStringLine(cFont->Height, tmp);
+ LCD_ClearLine(2 * cFont->Height);
+
+ LCD_SetBackColor(Black);
+ LCD_SetFont (&Font8x12);
+}
+
+/**
+* @brief Display the application footer (status) on the LCD screen
+* @param Status : pointer to the string to be displayed
+* @retval None
+*/
+void LCD_LOG_SetFooter(uint8_t *Status)
+{
+ sFONT *cFont;
+ uint8_t tmp[40], i;
+ LCD_SetBackColor(Blue);
+ cFont = LCD_GetFont();
+
+ for (i= 0; i< (320/cFont->Width)-1 ; i++)
+ {
+ tmp[i] = ' ';
+ }
+
+ tmp[(320/cFont->Width)-1] = 0;
+ LCD_DisplayStringLine(LCD_PIXEL_HEIGHT - cFont->Height, tmp);
+ LCD_DisplayStringLine(LCD_PIXEL_HEIGHT - cFont->Height, Status);
+ LCD_SetBackColor(Black);
+}
+
+/**
+* @brief Clear the Text Zone
+* @param None
+* @retval None
+*/
+void LCD_LOG_ClearTextZone(void)
+{
+ uint8_t i=0;
+ sFONT *cFont = LCD_GetFont();
+
+ for (i= 0 ; i < YWINDOW_SIZE; i++)
+ {
+ LCD_ClearLine((i + YWINDOW_MIN) * cFont->Height);
+ }
+
+ LCD_LOG_DeInit();
+}
+
+/**
+* @brief Redirect the printf to the lcd
+* @param c: character to be displayed
+* @param f: output file pointer
+* @retval None
+*/
+PUTCHAR_PROTOTYPE
+{
+
+ sFONT *cFont = LCD_GetFont();
+ uint32_t idx;
+
+ if(LCD_Lock == DISABLE)
+ {
+ if((LCD_ScrollActive == ENABLE)||(LCD_ScrollActive == ENABLE))
+ {
+ LCD_CacheBuffer_yptr_bottom = LCD_CacheBuffer_yptr_bottom_bak;
+ LCD_CacheBuffer_yptr_top = LCD_CacheBuffer_yptr_top_bak;
+ LCD_ScrollActive = DISABLE;
+ LCD_Scrolled = DISABLE;
+ LCD_ScrollBackStep = 0;
+
+ }
+
+ if(( LCD_CacheBuffer_xptr < LCD_PIXEL_WIDTH /cFont->Width ) && ( ch != '\n'))
+ {
+ LCD_CacheBuffer[LCD_CacheBuffer_yptr_bottom].line[LCD_CacheBuffer_xptr++] = (uint16_t)ch;
+ }
+ else
+ {
+ if(LCD_CacheBuffer_yptr_top >= LCD_CacheBuffer_yptr_bottom)
+ {
+
+ if(LCD_CacheBuffer_yptr_invert == DISABLE)
+ {
+ LCD_CacheBuffer_yptr_top++;
+
+ if(LCD_CacheBuffer_yptr_top == LCD_CACHE_DEPTH)
+ {
+ LCD_CacheBuffer_yptr_top = 0;
+ }
+ }
+ else
+ {
+ LCD_CacheBuffer_yptr_invert= DISABLE;
+ }
+ }
+
+ for(idx = LCD_CacheBuffer_xptr ; idx < LCD_PIXEL_WIDTH /cFont->Width; idx++)
+ {
+ LCD_CacheBuffer[LCD_CacheBuffer_yptr_bottom].line[LCD_CacheBuffer_xptr++] = ' ';
+ }
+ LCD_CacheBuffer[LCD_CacheBuffer_yptr_bottom].color = LCD_LineColor;
+
+ LCD_CacheBuffer_xptr = 0;
+
+ LCD_LOG_UpdateDisplay ();
+
+ LCD_CacheBuffer_yptr_bottom ++;
+
+ if (LCD_CacheBuffer_yptr_bottom == LCD_CACHE_DEPTH)
+ {
+ LCD_CacheBuffer_yptr_bottom = 0;
+ LCD_CacheBuffer_yptr_top = 1;
+ LCD_CacheBuffer_yptr_invert = ENABLE;
+ }
+
+ if( ch != '\n')
+ {
+ LCD_CacheBuffer[LCD_CacheBuffer_yptr_bottom].line[LCD_CacheBuffer_xptr++] = (uint16_t)ch;
+ }
+
+ }
+ }
+ return ch;
+}
+
+/**
+* @brief Update the text area display
+* @param None
+* @retval None
+*/
+static void LCD_LOG_UpdateDisplay (void)
+{
+ uint8_t cnt = 0 ;
+ uint16_t length = 0 ;
+ uint16_t ptr = 0, index = 0;
+
+ sFONT *cFont = LCD_GetFont();
+
+ if((LCD_CacheBuffer_yptr_bottom < (YWINDOW_SIZE -1)) &&
+ (LCD_CacheBuffer_yptr_bottom >= LCD_CacheBuffer_yptr_top))
+ {
+ LCD_SetTextColor(LCD_CacheBuffer[cnt + LCD_CacheBuffer_yptr_bottom].color);
+ LCD_DisplayStringLine ((YWINDOW_MIN + LCD_CacheBuffer_yptr_bottom) * cFont->Height,
+ (uint8_t *)(LCD_CacheBuffer[cnt + LCD_CacheBuffer_yptr_bottom].line));
+ }
+ else
+ {
+
+ if(LCD_CacheBuffer_yptr_bottom < LCD_CacheBuffer_yptr_top)
+ {
+ /* Virtual length for rolling */
+ length = LCD_CACHE_DEPTH + LCD_CacheBuffer_yptr_bottom ;
+ }
+ else
+ {
+ length = LCD_CacheBuffer_yptr_bottom;
+ }
+
+ ptr = length - YWINDOW_SIZE + 1;
+
+ for (cnt = 0 ; cnt < YWINDOW_SIZE ; cnt ++)
+ {
+
+ index = (cnt + ptr )% LCD_CACHE_DEPTH ;
+
+ LCD_SetTextColor(LCD_CacheBuffer[index].color);
+ LCD_DisplayStringLine ((cnt + YWINDOW_MIN) * cFont->Height,
+ (uint8_t *)(LCD_CacheBuffer[index].line));
+
+ }
+ }
+
+}
+
+#ifdef LCD_SCROLL_ENABLED
+/**
+* @brief Display previous text frame
+* @param None
+* @retval Status
+*/
+ErrorStatus LCD_LOG_ScrollBack (void)
+{
+
+ if(LCD_ScrollActive == DISABLE)
+ {
+
+ LCD_CacheBuffer_yptr_bottom_bak = LCD_CacheBuffer_yptr_bottom;
+ LCD_CacheBuffer_yptr_top_bak = LCD_CacheBuffer_yptr_top;
+
+
+ if(LCD_CacheBuffer_yptr_bottom > LCD_CacheBuffer_yptr_top)
+ {
+
+ if ((LCD_CacheBuffer_yptr_bottom - LCD_CacheBuffer_yptr_top) <= YWINDOW_SIZE)
+ {
+ LCD_Lock = DISABLE;
+ return ERROR;
+ }
+ }
+ LCD_ScrollActive = ENABLE;
+
+ if((LCD_CacheBuffer_yptr_bottom > LCD_CacheBuffer_yptr_top)&&
+ (LCD_Scrolled == DISABLE ))
+ {
+ LCD_CacheBuffer_yptr_bottom--;
+ LCD_Scrolled = ENABLE;
+ }
+
+ }
+
+ if(LCD_ScrollActive == ENABLE)
+ {
+ LCD_Lock = ENABLE;
+
+ if(LCD_CacheBuffer_yptr_bottom > LCD_CacheBuffer_yptr_top)
+ {
+
+ if((LCD_CacheBuffer_yptr_bottom - LCD_CacheBuffer_yptr_top) < YWINDOW_SIZE )
+ {
+ LCD_Lock = DISABLE;
+ return ERROR;
+ }
+
+ LCD_CacheBuffer_yptr_bottom --;
+ }
+ else if(LCD_CacheBuffer_yptr_bottom <= LCD_CacheBuffer_yptr_top)
+ {
+
+ if((LCD_CACHE_DEPTH - LCD_CacheBuffer_yptr_top + LCD_CacheBuffer_yptr_bottom) < YWINDOW_SIZE)
+ {
+ LCD_Lock = DISABLE;
+ return ERROR;
+ }
+ LCD_CacheBuffer_yptr_bottom --;
+
+ if(LCD_CacheBuffer_yptr_bottom == 0xFFFF)
+ {
+ LCD_CacheBuffer_yptr_bottom = LCD_CACHE_DEPTH - 2;
+ }
+ }
+ LCD_ScrollBackStep++;
+ LCD_LOG_UpdateDisplay();
+ LCD_Lock = DISABLE;
+ }
+ return SUCCESS;
+}
+
+/**
+* @brief Display next text frame
+* @param None
+* @retval Status
+*/
+ErrorStatus LCD_LOG_ScrollForward (void)
+{
+
+ if(LCD_ScrollBackStep != 0)
+ {
+ if(LCD_ScrollActive == DISABLE)
+ {
+
+ LCD_CacheBuffer_yptr_bottom_bak = LCD_CacheBuffer_yptr_bottom;
+ LCD_CacheBuffer_yptr_top_bak = LCD_CacheBuffer_yptr_top;
+
+ if(LCD_CacheBuffer_yptr_bottom > LCD_CacheBuffer_yptr_top)
+ {
+
+ if ((LCD_CacheBuffer_yptr_bottom - LCD_CacheBuffer_yptr_top) <= YWINDOW_SIZE)
+ {
+ LCD_Lock = DISABLE;
+ return ERROR;
+ }
+ }
+ LCD_ScrollActive = ENABLE;
+
+ if((LCD_CacheBuffer_yptr_bottom > LCD_CacheBuffer_yptr_top)&&
+ (LCD_Scrolled == DISABLE ))
+ {
+ LCD_CacheBuffer_yptr_bottom--;
+ LCD_Scrolled = ENABLE;
+ }
+
+ }
+
+ if(LCD_ScrollActive == ENABLE)
+ {
+ LCD_Lock = ENABLE;
+ LCD_ScrollBackStep--;
+
+ if(++LCD_CacheBuffer_yptr_bottom == LCD_CACHE_DEPTH)
+ {
+ LCD_CacheBuffer_yptr_bottom = 0;
+ }
+
+ LCD_LOG_UpdateDisplay();
+ LCD_Lock = DISABLE;
+
+ }
+ return SUCCESS;
+ }
+ else // LCD_ScrollBackStep == 0
+ {
+ LCD_Lock = DISABLE;
+ return ERROR;
+ }
+}
+#endif /* LCD_SCROLL_ENABLED */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/Common/lcd_log.h b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/Common/lcd_log.h
new file mode 100644
index 0000000..a7ec668
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/Common/lcd_log.h
@@ -0,0 +1,160 @@
+/**
+ ******************************************************************************
+ * @file lcd_log.h
+ * @author MCD Application Team
+ * @version V5.0.2
+ * @date 05-March-2012
+ * @brief header for the lcd_log.c file
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.st.com/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __LCD_LOG_H__
+#define __LCD_LOG_H__
+
+/* Includes ------------------------------------------------------------------*/
+
+#include "lcd_log_conf.h"
+
+/** @addtogroup Utilities
+ * @{
+ */
+
+/** @addtogroup STM32_EVAL
+ * @{
+ */
+
+/** @addtogroup Common
+ * @{
+ */
+
+/** @addtogroup LCD_LOG
+ * @{
+ */
+
+/** @defgroup LCD_LOG
+ * @brief
+ * @{
+ */
+
+
+/** @defgroup LCD_LOG_Exported_Defines
+ * @{
+ */
+#ifdef __GNUC__
+/* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf
+ set to 'Yes') calls __io_putchar() */
+#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
+#else
+#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
+#endif /* __GNUC__ */
+
+/** These value can be changed by user */
+
+#ifdef LCD_SCROLL_ENABLED
+ #define LCD_CACHE_DEPTH (YWINDOW_SIZE + CACHE_SIZE)
+#else
+ #define LCD_CACHE_DEPTH YWINDOW_SIZE
+#endif
+/**
+ * @}
+ */
+
+/** @defgroup LCD_LOG_Exported_Types
+ * @{
+ */
+typedef struct _LCD_LOG_line
+{
+ uint8_t line[XWINDOW_MAX];
+ uint16_t color;
+
+}LCD_LOG_line;
+
+/**
+ * @}
+ */
+
+/** @defgroup LCD_LOG_Exported_Macros
+ * @{
+ */
+#define LCD_ErrLog(...) LCD_LineColor = Red;\
+ printf("ERROR: ") ;\
+ printf(__VA_ARGS__);\
+ LCD_LineColor = LCD_LOG_DEFAULT_COLOR
+
+#define LCD_UsrLog(...) LCD_LineColor = LCD_LOG_DEFAULT_COLOR;\
+ printf(__VA_ARGS__);\
+
+
+#define LCD_DbgLog(...) LCD_LineColor = Cyan;\
+ printf(__VA_ARGS__);\
+ LCD_LineColor = LCD_LOG_DEFAULT_COLOR
+/**
+ * @}
+ */
+
+/** @defgroup LCD_LOG_Exported_Variables
+ * @{
+ */
+extern uint16_t LCD_LineColor;
+/**
+ * @}
+ */
+
+/** @defgroup LCD_LOG_Exported_FunctionsPrototype
+ * @{
+ */
+void LCD_LOG_Init(void);
+void LCD_LOG_DeInit(void);
+void LCD_LOG_SetHeader(uint8_t *Title);
+void LCD_LOG_SetFooter(uint8_t *Status);
+void LCD_LOG_ClearTextZone(void);
+#ifdef LCD_SCROLL_ENABLED
+ ErrorStatus LCD_LOG_ScrollBack(void);
+ ErrorStatus LCD_LOG_ScrollForward(void);
+#endif
+/**
+ * @}
+ */
+
+
+#endif /* __LCD_LOG_H__ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/Common/lcd_log_conf_template.h b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/Common/lcd_log_conf_template.h
new file mode 100644
index 0000000..c242be1
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/Common/lcd_log_conf_template.h
@@ -0,0 +1,113 @@
+/**
+ ******************************************************************************
+ * @file lcd_log_conf_template.h
+ * @author MCD Application Team
+ * @version V5.0.2
+ * @date 05-March-2012
+ * @brief lcd_log configuration template file.
+ * This file should be copied to the application folder and modified
+ * as follows:
+ * - Rename it to 'lcd_log_conf.h'.
+ * - Update the name of the LCD header file depending on the EVAL board
+ * you are using (see line32 below).
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.st.com/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __LCD_LOG_CONF_H__
+#define __LCD_LOG_CONF_H__
+
+/* Includes ------------------------------------------------------------------*/
+#include "stm32xxx_eval_lcd.h" /* replace 'stm32xxx' with your EVAL board name, ex: stm3210c_eval_lcd.h */
+#include <stdio.h>
+
+/** @addtogroup LCD_LOG
+ * @{
+ */
+
+/** @defgroup LCD_LOG
+ * @brief This file is the
+ * @{
+ */
+
+
+/** @defgroup LCD_LOG_CONF_Exported_Defines
+ * @{
+ */
+/* Comment the line below to disable the scroll back and forward features */
+#define LCD_SCROLL_ENABLED
+
+/* Define the LCD default text color */
+#define LCD_LOG_DEFAULT_COLOR LCD_COLOR_WHITE
+
+/* Define the display window settings */
+#define YWINDOW_MIN 3
+#define YWINDOW_SIZE 12
+#define XWINDOW_MAX 50
+
+/* Define the cache depth */
+#define CACHE_SIZE 50
+
+/** @defgroup LCD_LOG_CONF_Exported_TypesDefinitions
+ * @{
+ */
+
+/**
+ * @}
+ */
+
+
+/** @defgroup LCD_LOG_Exported_Macros
+ * @{
+ */
+
+
+/**
+ * @}
+ */
+
+/** @defgroup LCD_LOG_CONF_Exported_Variables
+ * @{
+ */
+
+/**
+ * @}
+ */
+
+/** @defgroup LCD_LOG_CONF_Exported_FunctionsPrototype
+ * @{
+ */
+
+/**
+ * @}
+ */
+
+
+#endif /* __LCD_LOG_H__ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/Common/stm32_eval_legacy.h b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/Common/stm32_eval_legacy.h
new file mode 100644
index 0000000..4910509
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/Common/stm32_eval_legacy.h
@@ -0,0 +1,208 @@
+/**
+ ******************************************************************************
+ * @file stm32_eval_legacy.h
+ * @author MCD Application Team
+ * @version V5.0.2
+ * @date 05-March-2012
+ * @brief This file contains defines legacy for STM32 EVAL drivers.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.st.com/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __STM32_EVAL_LEGACY_H
+#define __STM32_EVAL_LEGACY_H
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+/* Includes ------------------------------------------------------------------*/
+
+/* Exported types ------------------------------------------------------------*/
+/* Exported constants --------------------------------------------------------*/
+/* STM322xG_EVAL Defines Legacy */
+#ifdef USE_STM3220F_EVAL
+ #define USE_STM322xG_EVAL
+#endif
+#define STM3220F_LCD_Init STM322xG_LCD_Init
+
+/* Button Defines Legacy */
+#define Button_WAKEUP BUTTON_WAKEUP
+#define Button_TAMPER BUTTON_TAMPER
+#define Button_KEY BUTTON_KEY
+#define Button_RIGHT BUTTON_RIGHT
+#define Button_LEFT BUTTON_LEFT
+#define Button_UP BUTTON_UP
+#define Button_DOWN BUTTON_DOWN
+#define Button_SEL BUTTON_SEL
+#define Mode_GPIO BUTTON_MODE_GPIO
+#define Mode_EXTI BUTTON_MODE_EXTI
+#define Button_Mode_TypeDef ButtonMode_TypeDef
+#define JOY_CENTER JOY_SEL
+#define JOY_State_TypeDef JOYState_TypeDef
+
+/* LCD Defines Legacy */
+#define LCD_RSNWR_GPIO_CLK LCD_NWR_GPIO_CLK
+#define LCD_SPI_GPIO_PORT LCD_SPI_SCK_GPIO_PORT
+#define LCD_SPI_GPIO_CLK LCD_SPI_SCK_GPIO_CLK
+#define R0 LCD_REG_0
+#define R1 LCD_REG_1
+#define R2 LCD_REG_2
+#define R3 LCD_REG_3
+#define R4 LCD_REG_4
+#define R5 LCD_REG_5
+#define R6 LCD_REG_6
+#define R7 LCD_REG_7
+#define R8 LCD_REG_8
+#define R9 LCD_REG_9
+#define R10 LCD_REG_10
+#define R12 LCD_REG_12
+#define R13 LCD_REG_13
+#define R14 LCD_REG_14
+#define R15 LCD_REG_15
+#define R16 LCD_REG_16
+#define R17 LCD_REG_17
+#define R18 LCD_REG_18
+#define R19 LCD_REG_19
+#define R20 LCD_REG_20
+#define R21 LCD_REG_21
+#define R22 LCD_REG_22
+#define R23 LCD_REG_23
+#define R24 LCD_REG_24
+#define R25 LCD_REG_25
+#define R26 LCD_REG_26
+#define R27 LCD_REG_27
+#define R28 LCD_REG_28
+#define R29 LCD_REG_29
+#define R30 LCD_REG_30
+#define R31 LCD_REG_31
+#define R32 LCD_REG_32
+#define R33 LCD_REG_33
+#define R34 LCD_REG_34
+#define R36 LCD_REG_36
+#define R37 LCD_REG_37
+#define R40 LCD_REG_40
+#define R41 LCD_REG_41
+#define R43 LCD_REG_43
+#define R45 LCD_REG_45
+#define R48 LCD_REG_48
+#define R49 LCD_REG_49
+#define R50 LCD_REG_50
+#define R51 LCD_REG_51
+#define R52 LCD_REG_52
+#define R53 LCD_REG_53
+#define R54 LCD_REG_54
+#define R55 LCD_REG_55
+#define R56 LCD_REG_56
+#define R57 LCD_REG_57
+#define R59 LCD_REG_59
+#define R60 LCD_REG_60
+#define R61 LCD_REG_61
+#define R62 LCD_REG_62
+#define R63 LCD_REG_63
+#define R64 LCD_REG_64
+#define R65 LCD_REG_65
+#define R66 LCD_REG_66
+#define R67 LCD_REG_67
+#define R68 LCD_REG_68
+#define R69 LCD_REG_69
+#define R70 LCD_REG_70
+#define R71 LCD_REG_71
+#define R72 LCD_REG_72
+#define R73 LCD_REG_73
+#define R74 LCD_REG_74
+#define R75 LCD_REG_75
+#define R76 LCD_REG_76
+#define R77 LCD_REG_77
+#define R78 LCD_REG_78
+#define R79 LCD_REG_79
+#define R80 LCD_REG_80
+#define R81 LCD_REG_81
+#define R82 LCD_REG_82
+#define R83 LCD_REG_83
+#define R96 LCD_REG_96
+#define R97 LCD_REG_97
+#define R106 LCD_REG_106
+#define R118 LCD_REG_118
+#define R128 LCD_REG_128
+#define R129 LCD_REG_129
+#define R130 LCD_REG_130
+#define R131 LCD_REG_131
+#define R132 LCD_REG_132
+#define R133 LCD_REG_133
+#define R134 LCD_REG_134
+#define R135 LCD_REG_135
+#define R136 LCD_REG_136
+#define R137 LCD_REG_137
+#define R139 LCD_REG_139
+#define R140 LCD_REG_140
+#define R141 LCD_REG_141
+#define R143 LCD_REG_143
+#define R144 LCD_REG_144
+#define R145 LCD_REG_145
+#define R146 LCD_REG_146
+#define R147 LCD_REG_147
+#define R148 LCD_REG_148
+#define R149 LCD_REG_149
+#define R150 LCD_REG_150
+#define R151 LCD_REG_151
+#define R152 LCD_REG_152
+#define R153 LCD_REG_153
+#define R154 LCD_REG_154
+#define R157 LCD_REG_157
+#define R192 LCD_REG_192
+#define R193 LCD_REG_193
+#define R227 LCD_REG_227
+#define R229 LCD_REG_229
+#define R231 LCD_REG_231
+#define R239 LCD_REG_239
+#define White LCD_COLOR_WHITE
+#define Black LCD_COLOR_BLACK
+#define Grey LCD_COLOR_GREY
+#define Blue LCD_COLOR_BLUE
+#define Blue2 LCD_COLOR_BLUE2
+#define Red LCD_COLOR_RED
+#define Magenta LCD_COLOR_MAGENTA
+#define Green LCD_COLOR_GREEN
+#define Cyan LCD_COLOR_CYAN
+#define Yellow LCD_COLOR_YELLOW
+#define Line0 LCD_LINE_0
+#define Line1 LCD_LINE_1
+#define Line2 LCD_LINE_2
+#define Line3 LCD_LINE_3
+#define Line4 LCD_LINE_4
+#define Line5 LCD_LINE_5
+#define Line6 LCD_LINE_6
+#define Line7 LCD_LINE_7
+#define Line8 LCD_LINE_8
+#define Line9 LCD_LINE_9
+#define Horizontal LCD_DIR_HORIZONTAL
+#define Vertical LCD_DIR_VERTICAL
+
+/* Exported macro ------------------------------------------------------------*/
+/* Exported functions --------------------------------------------------------*/
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __STM32_EVAL_LEGACY_H */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210B_EVAL/Release_Notes.html b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210B_EVAL/Release_Notes.html
new file mode 100644
index 0000000..8d612a4
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210B_EVAL/Release_Notes.html
@@ -0,0 +1,347 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns="http://www.w3.org/TR/REC-html40"><head>
+
+
+
+
+
+
+
+ <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
+
+
+ <link rel="File-List" href="Library_files/filelist.xml">
+
+
+ <link rel="Edit-Time-Data" href="Library_files/editdata.mso"><!--[if !mso]> <style> v\:* {behavior:url(#default#VML);} o\:* {behavior:url(#default#VML);} w\:* {behavior:url(#default#VML);} .shape {behavior:url(#default#VML);} </style> <![endif]--><title>Release Notes for STM3210B_EVAL Evaluation Board Drivers</title><!--[if gte mso 9]><xml> <o:DocumentProperties> <o:Author>STMicroelectronics</o:Author> <o:LastAuthor>STMicroelectronics</o:LastAuthor> <o:Revision>37</o:Revision> <o:TotalTime>136</o:TotalTime> <o:Created>2009-02-27T19:26:00Z</o:Created> <o:LastSaved>2009-03-01T17:56:00Z</o:LastSaved> <o:Pages>1</o:Pages> <o:Words>522</o:Words> <o:Characters>2977</o:Characters> <o:Company>STMicroelectronics</o:Company> <o:Lines>24</o:Lines> <o:Paragraphs>6</o:Paragraphs> <o:CharactersWithSpaces>3493</o:CharactersWithSpaces> <o:Version>11.6568</o:Version> </o:DocumentProperties> </xml><![endif]--><!--[if gte mso 9]><xml> <w:WordDocument> <w:Zoom>110</w:Zoom> <w:ValidateAgainstSchemas/> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" LatentStyleCount="156"> </w:LatentStyles> </xml><![endif]-->
+
+
+
+
+
+
+
+ <style>
+<!--
+/* Style Definitions */
+p.MsoNormal, li.MsoNormal, div.MsoNormal
+{mso-style-parent:"";
+margin:0in;
+margin-bottom:.0001pt;
+mso-pagination:widow-orphan;
+font-size:12.0pt;
+font-family:"Times New Roman";
+mso-fareast-font-family:"Times New Roman";}
+h2
+{mso-style-next:Normal;
+margin-top:12.0pt;
+margin-right:0in;
+margin-bottom:3.0pt;
+margin-left:0in;
+mso-pagination:widow-orphan;
+page-break-after:avoid;
+mso-outline-level:2;
+font-size:14.0pt;
+font-family:Arial;
+font-weight:bold;
+font-style:italic;}
+a:link, span.MsoHyperlink
+{color:blue;
+text-decoration:underline;
+text-underline:single;}
+a:visited, span.MsoHyperlinkFollowed
+{color:blue;
+text-decoration:underline;
+text-underline:single;}
+p
+{mso-margin-top-alt:auto;
+margin-right:0in;
+mso-margin-bottom-alt:auto;
+margin-left:0in;
+mso-pagination:widow-orphan;
+font-size:12.0pt;
+font-family:"Times New Roman";
+mso-fareast-font-family:"Times New Roman";}
+@page Section1
+{size:8.5in 11.0in;
+margin:1.0in 1.25in 1.0in 1.25in;
+mso-header-margin:.5in;
+mso-footer-margin:.5in;
+mso-paper-source:0;}
+div.Section1
+{page:Section1;}
+-->
+ </style><!--[if gte mso 10]> <style> /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin:0in; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;} </style> <![endif]--><!--[if gte mso 9]><xml> <o:shapedefaults v:ext="edit" spidmax="5122"/> </xml><![endif]--><!--[if gte mso 9]><xml> <o:shapelayout v:ext="edit"> <o:idmap v:ext="edit" data="1"/> </o:shapelayout></xml><![endif]-->
+ <meta content="MCD Application Team" name="author"></head>
+<body link="blue" vlink="blue">
+<div class="Section1">
+<p class="MsoNormal"><span style="font-family: Arial;"><o:p><br>
+</o:p></span></p>
+<div align="center">
+<table class="MsoNormalTable" style="width: 675pt;" border="0" cellpadding="0" cellspacing="0" width="900">
+ <tbody>
+ <tr>
+ <td style="padding: 0cm;" valign="top">
+ <table class="MsoNormalTable" style="width: 675pt;" border="0" cellpadding="0" cellspacing="0" width="900">
+ <tbody>
+ <tr>
+ <td style="vertical-align: top;">
+ <p class="MsoNormal"><span style="font-size: 8pt; font-family: Arial; color: blue;"><a href="../../Release_Notes.html">Back to Release page</a><o:p></o:p></span></p>
+ </td>
+ </tr>
+ <tr style="">
+ <td style="padding: 1.5pt;">
+ <h1 style="margin-bottom: 18pt; text-align: center;" align="center"><span style="font-size: 20pt; font-family: Verdana; color: rgb(51, 102, 255);">Release
+Notes for STM3210B_EVAL Evaluation Board Drivers</span><span style="font-size: 20pt; font-family: Verdana;"><o:p></o:p></span></h1>
+ <p class="MsoNormal" style="text-align: center;" align="center"><span style="font-size: 10pt; font-family: Arial; color: black;">Copyright
+2012 STMicroelectronics</span><span style="color: black;"><u1:p></u1:p><o:p></o:p></span></p>
+ <p class="MsoNormal" style="text-align: center;" align="center"><span style="font-size: 10pt; font-family: Arial; color: black;"><img alt="" id="_x0000_i1025" src="../../../_htmresc/logo.bmp" style="border: 0px solid ; width: 86px; height: 65px;"></span><span style="font-size: 10pt;"><o:p></o:p></span></p>
+ </td>
+ </tr>
+ </tbody>
+ </table>
+ <p class="MsoNormal"><span style="font-family: Arial; display: none;"><o:p>&nbsp;</o:p></span></p>
+ <table class="MsoNormalTable" style="width: 675pt;" border="0" cellpadding="0" width="900">
+ <tbody>
+ <tr style="">
+ <td style="padding: 0cm;" valign="top">
+ <h2 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial;"><span style="font-size: 12pt; color: white;">Contents<o:p></o:p></span></h2>
+ <ol style="margin-top: 0cm;" start="1" type="1">
+ <li class="MsoNormal" style="color: black; margin-top: 4.5pt; margin-bottom: 4.5pt;"><span style="font-size: 10pt; font-family: Verdana;"><a href="#History">STM3210B_EVAL&nbsp;Evaluation Board Drivers
+update History</a><o:p></o:p></span></li>
+ <li class="MsoNormal" style="color: black; margin-top: 4.5pt; margin-bottom: 4.5pt;"><span style="font-size: 10pt; font-family: Verdana;"><a href="#License">License</a><o:p></o:p></span></li>
+ </ol>
+ <span style="font-family: &quot;Times New Roman&quot;;">
+ </span>
+ <h2 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial;"><a name="History"></a><span style="font-size: 12pt; color: white;">STM3210B_EVAL Evaluation Board Drivers update History</span></h2><h3 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial; margin-right: 500pt; width: 167px;"><span style="font-size: 10pt; font-family: Arial; color: white;">V5.0.1 / 05-March-2012<o:p></o:p></span></h3>
+ <p class="MsoNormal" style="margin: 4.5pt 0cm 4.5pt 18pt;"><b style=""><u><span style="font-size: 10pt; font-family: Verdana; color: black;">Main
+Changes<o:p></o:p></span></u></b></p>
+
+ <ul style="margin-top: 0cm;" type="square"><li class="MsoNormal" style="color: black; margin-top: 4.5pt; margin-bottom: 4.5pt;"><span style="font-size: 10pt; font-family: Verdana;">All source files:&nbsp;license disclaimer text update and add link to the License file on ST Internet.</span></li></ul><h3 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial; margin-right: 500pt; width: 176px;"><span style="font-size: 10pt; font-family: Arial; color: white;">V5.0.0 / 03-February-2012<o:p></o:p></span></h3><p class="MsoNormal" style="margin: 4.5pt 0cm 4.5pt 18pt;"><b style=""><u><span style="font-size: 10pt; font-family: Verdana; color: black;">Main
+Changes<o:p></o:p></span></u></b></p>
+<ul style="margin-top: 0cm;" type="square"><li class="MsoNormal" style="color: black; margin-top: 4.5pt; margin-bottom: 4.5pt;"><span style="font-size: 10pt; font-family: Verdana;">All source files: update disclaimer to add reference to the&nbsp;new license agreement</span></li><li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">Update STM32 Evaluation Board Drivers architecture and folder organization,&nbsp;<span style="font-weight: bold; font-style: italic;">full&nbsp;API compatibility maintained vs. V4.6.2</span></span></li><ul><li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">All the HW&nbsp;drivers required for each board are&nbsp;provided within this board folder</span><span style="font-size: 10pt; font-family: Verdana;">. The concerned drivers are:</span></li><ul><li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span style="font-style: italic;">stm32_eval_i2c_ee.c\.h:</span>&nbsp;I2C M24Cxx EEPROM memory driver</span></li><li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span style="font-style: italic;">stm32_eval_i2c_tsensor.c\.h:</span>&nbsp;</span><span style="font-size: 10pt; font-family: Verdana;">I2C </span><span style="font-size: 10pt; font-family: Verdana;">LM75 temperature sensor driver</span></li><li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span style="font-style: italic;">stm32_eval_spi_flash.c\.h:</span> SPI M25Pxxx FLASH memory driver</span></li><li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span style="font-style: italic;">stm32_eval_sdio_sd.c\.h:</span> SDIO SD Card memory driver</span></li><li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span style="font-style: italic;">stm32_eval_spi_sd.c\.h:</span>&nbsp;</span><span style="font-size: 10pt; font-family: Verdana;">SPI SD Card memory driver&nbsp;</span></li><li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">These drivers were&nbsp;moved from </span><span style="font-size: 10pt; font-family: Verdana;"><span style="font-style: italic;">\Common</span> to </span><span style="font-size: 10pt; font-family: Verdana;"><span style="font-style: italic;">\STM32XXX_EVAL</span> folder(s)</span></li></ul><li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span style="font-style: italic;">\Common&nbsp;</span></span><span style="font-size: 10pt; font-family: Verdana;">folder contains only drivers for the fonts and log module used by the LCD driver</span></li><li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span style="font-style: italic;">stm32_eval.c\.h</span> files removed, <span style="font-style: italic; text-decoration: underline;">as consequence you need to perform the following update on your project configuration&nbsp; (based on EVAL drivers V4.6.2):</span></span></li><ul><li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">In the&nbsp;project files, add your EVAL board driver source&nbsp;file&nbsp;</span><span style="font-size: 10pt; font-family: Verdana;"><span style="font-style: italic;">"stm3210b_eval.c"</span>&nbsp;instead of <span style="font-style: italic;">"stm32_eval.c"</span></span></li><li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">Include your EVAL board driver header file&nbsp;<span style="font-style: italic;">#include "stm3210b_eval.h"</span>&nbsp;instead of <span style="font-style: italic;">#include "stm32_eval.h"</span></span></li><li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">If
+you are&nbsp;using the EVAL board's LCD, you need to add the include of
+the LCD header file&nbsp;#include "stm3210b_eval_lcd.h"</span></li><ul><li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">If
+you are using the LCD log module, after copying it to the application
+folder you have to edit it and update the name of the LCD header file. For more details, refer to the <span style="font-style: italic;">lcd_log_conf_template.h</span> driver description.</span></li></ul></ul></ul><li class="MsoNormal" style="color: black; margin-top: 4.5pt; margin-bottom: 4.5pt;"><span style="font-size: 10pt; font-family: Verdana;">stm3210b_eval_lcd.c</span></li><ul><li class="MsoNormal" style="color: black; margin-top: 4.5pt; margin-bottom: 4.5pt;"><span style="font-size: 10pt; font-family: Verdana;"></span><span style="font-size: 10pt; font-family: Verdana;">Remove &#8220;static&#8221; from&nbsp;<span style="font-style: italic;">TextColor</span> and&nbsp;<span style="font-style: italic;">BackColor</span> variables declaration (need to be changed from other application modules)&nbsp;</span></li></ul></ul><h3 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial; margin-right: 500pt; width: 167px;"><span style="font-size: 10pt; font-family: Arial; color: white;">V4.6.2 /&nbsp;22-July-2011<o:p></o:p></span></h3>
+ <p class="MsoNormal" style="margin: 4.5pt 0cm 4.5pt 18pt;"><b style=""><u><span style="font-size: 10pt; font-family: Verdana; color: black;">Main
+Changes<o:p></o:p></span></u></b></p>
+
+ <ul style="margin-top: 0cm;" type="square"><li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">STM3210C_EVAL</span></li><ul><li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">stm3210c_eval_lcd.c: update to support new LCD AM240320D5TOQW01H (controller ILI9325)</span></li></ul><li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">STM322xG-EVAL</span></li><ul><li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">stm322xg_eval.h: fix value of the SDIO clock divider (<span style="font-style: italic;">SDIO_TRANSFER_CLK_DIV</span> constant) to 2 instead of 0</span></li></ul><ul><li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">stm322xg_eval_lcd.c: increase FSMC<span style="font-style: italic;"> AddressSetupTime</span> value from 1 to 3 to be compliant with some&nbsp;LCD access timing</span></li></ul><ul><li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">stm322xg_eval_audio_codec.c: update <span style="font-style: italic;">Codec_CtrlInterface_Init(</span>) and <span style="font-style: italic;">Codec_GPIO_Init(</span>) functions to not reconfigure the I2C peripheral if it's&nbsp;already </span><span style="font-size: 10pt; font-family: Verdana;">enabled and </span><span style="font-size: 10pt; font-family: Verdana;">configured&nbsp;(to
+avoid configuring the I2C twice when using both&nbsp;Audio codec and IO
+Expander drivers in the same application).<br></span></li></ul></ul><h3 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial; margin-right: 500pt; width: 167px;"><span style="font-size: 10pt; font-family: Arial; color: white;">V4.6.1 / 18-April-2011<o:p></o:p></span></h3>
+ <p class="MsoNormal" style="margin: 4.5pt 0cm 4.5pt 18pt;"><b style=""><u><span style="font-size: 10pt; font-family: Verdana; color: black;">Main
+Changes<o:p></o:p></span></u></b></p>
+
+ <ul style="margin-top: 0cm;" type="square"><li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">Update&nbsp;</span><span style="font-size: 10pt; font-family: Verdana;">some</span><span style="font-size: 10pt; font-family: Verdana;"> <span style="font-weight: bold; font-style: italic;">STM322xG_EVAL</span> drivers (no change on the API) to fix&nbsp;warnings wit<span style="font-weight: bold; font-style: italic;"></span>h TASKING C compiler.</span></li><li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">Change the Release Notes name to <span style="font-weight: bold; font-style: italic;">STM32 Evaluation Board Drivers </span><br></span></li><li style="font-style: italic;" class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">stm322xg_eval.c</span></li><ul><li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">SD_LowLevel_Init(): change&nbsp;SDIO pins speed configuration to&nbsp;"GPIO_Speed_25MHz"</span></li></ul></ul><span style="font-size: 10pt; font-family: Verdana;"><span style="font-style: italic; font-weight: bold;"></span></span><span style="font-size: 10pt; font-family: Verdana;"><span style="font-style: italic; font-weight: bold;"></span></span><span style="font-size: 10pt; font-family: Verdana;"><span style="font-style: italic; font-weight: bold;"></span></span><span style="font-size: 10pt; font-family: Verdana;"><span style="font-style: italic; font-weight: bold;"></span></span><span style="font-size: 10pt; font-family: Verdana;"><span style="font-style: italic; font-weight: bold;"></span></span><span style="font-size: 10pt; font-family: Verdana;"></span><h3 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial; margin-right: 500pt; width: 167px;"><span style="font-size: 10pt; font-family: Arial; color: white;">V4.6.0 / 11-March-2011<o:p></o:p></span></h3>
+ <p class="MsoNormal" style="margin: 4.5pt 0cm 4.5pt 18pt;"><b style=""><u><span style="font-size: 10pt; font-family: Verdana; color: black;">Main
+Changes<o:p></o:p></span></u></b></p>
+
+ <ul style="margin-top: 0cm;" type="square"><li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">Official version supporting <span style="font-weight: bold; font-style: italic;">STM322xG_EVAL</span> evaluation board RevB (for <span style="font-weight: bold; font-style: italic;">STM32F2xx</span> devices).</span></li><li style="font-style: italic;" class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">Common</span></li><ul><li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">Add
+new LCD log utility drivers: The LCD Log module allows to automatically
+set a header and footer on any application using the LCD display and
+allows to dump user, debug and error messages by using the following
+macros: LCD_ErrLog(),&nbsp;&nbsp;&nbsp; LCD_UsrLog() and LCD_DbgLog().</span></li></ul></ul><div style="margin-left: 40px;"><span style="font-size: 10pt; font-family: Verdana;"><span style="text-decoration: underline; font-style: italic;">Note</span><span style="font-style: italic;">:</span> the <span style="font-style: italic;">STM322xG_EVAL</span> board RevA was wrongly named <span style="font-style: italic;">STM3220F_EVAL</span></span><br></div><span style="font-size: 10pt; font-family: Verdana;"></span><h3 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial; margin-right: 500pt; width: 167px;"><span style="font-size: 10pt; font-family: Arial; color: white;">V4.5.0 / 07-March-2011<o:p></o:p></span></h3>
+ <p class="MsoNormal" style="margin: 4.5pt 0cm 4.5pt 18pt;"><b style=""><u><span style="font-size: 10pt; font-family: Verdana; color: black;">Main
+Changes<o:p></o:p></span></u></b></p>
+
+ <ul style="margin-top: 0cm;" type="square"><li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">stm32_eval_sdio_sd.c\.h: driver improvement</span></li><ul><li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">SD Clock increased to 24MHz to improve the data transfer performance.</span></li><li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">Add
+new functions to check the SDIO peripheral and SD Card status at any
+time:&nbsp;SD_WaitReadOperation(), SD_WaitWriteOperation(). The
+software sequence is little bit changed&nbsp;but without any impact on
+driver API. For more details, refer to the stm32_eval_sdio_sd.c
+driver&nbsp;description.</span></li><li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">Add
+new structure containing the SD Status register parameters. This
+structure is called by the
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+&nbsp;SD_SendSDStatus() function.</span></li><li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">Transfers mode updated</span></li><ul><li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">Read/Write Block using Polling and DMA modes</span></li><li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">Read/Write Multi Blocks using DMA mode only</span></li><li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">Interrupt mode removed</span></li></ul><li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">Data transfer functions are managing only fixed Block size (512-byte)&nbsp;</span></li></ul><li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">STM32100B-EVAL</span></li><ul><li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">stm32100b_eval_cec.c: fix some strict ANSI-C errors</span><span style="font-size: 10pt; font-family: Verdana;"></span></li></ul><li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">STM32100E-EVAL</span></li><ul><li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">stm32100e_eval_cec.c: fix some strict ANSI-C errors<br></span></li></ul></ul>
+ <h3 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial; margin-right: 500pt; width: 167px;"><span style="font-size: 10pt; font-family: Arial; color: white;">V4.4.0 / 31-December-2010<o:p></o:p></span></h3>
+ <p class="MsoNormal" style="margin: 4.5pt 0cm 4.5pt 18pt;"><b style=""><u><span style="font-size: 10pt; font-family: Verdana; color: black;">Main
+Changes<o:p></o:p></span></u></b></p>
+
+ <ul style="margin-top: 0cm;" type="square">
+ <li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">Add new directory for STM32L152-EVAL board containing the following files:</span></li>
+ <ul>
+<li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">stm32l152_eval.h/.c, </span><span style="font-size: 10pt; font-family: Verdana;">stm32l152</span><span style="font-size: 10pt; font-family: Verdana;">_eval_lcd.h/.c, stm32l152_eval_glass_lcd.h</span><span style="font-size: 10pt; font-family: Verdana;">/.c, </span><span style="font-size: 10pt; font-family: Verdana;">stm32l152_eval_i2c_ee</span><span style="font-size: 10pt; font-family: Verdana;">.h/.c</span></li>
+ </ul>
+ <li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">Add support for the STM32100E-EVAL Rev B: SPI FLASH CS pin "sFLASH_CS_PIN" changed from PB.02 to PE.06.</span></li>
+ <li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">stm32100e_eval_lcd.h/.c: Add support for "LCD_ILI9325" LCD controller.</span></li>
+ <li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">stm32100e_eval_fsmc_onenand.h/.c driver updated to correct asynchronous and synchronous read operations procedures.<br>
+ </span></li>
+ </ul>
+
+ <h3 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial; margin-right: 558.05pt;"><span style="font-size: 10pt; font-family: Arial; color: white;">4.3.0
+- 10/15/2010</span></h3>
+ <ol style="margin-top: 0in;" start="1" type="1">
+ <li class="MsoNormal" style=""><b><i><span style="font-size: 10pt; font-family: Verdana;">General</span></i></b><i><span style="font-size: 10pt; font-family: Verdana;"> </span></i><i><span style="font-size: 10pt;"><o:p></o:p></span></i></li>
+ </ol>
+
+ <ul style="margin-top: 0in;" type="disc">
+
+
+
+
+ <li class="MsoNormal" style=""><span style="font-size: 10pt; font-family: Verdana;">I2C EEPROM,&nbsp;</span><span style="font-size: 10pt; font-family: Verdana;">Temperature Sensor and&nbsp;</span><span style="font-size: 10pt; font-family: Verdana;">IOE Expander</span><span style="font-size: 10pt; font-family: Verdana;"> drivers&nbsp;updated to&nbsp;</span><span style="font-size: 10pt; font-family: Verdana;">use the DMA for read/write transfer and add more robustness</span></li>
+ <li class="MsoNormal" style=""><span style="font-size: 10pt; font-family: Verdana;">SD Card (SDIO) driver updated to&nbsp;</span><span style="font-size: 10pt; font-family: Verdana;">add more robustness</span></li><li class="MsoNormal" style=""><span style="font-size: 10pt; font-family: Verdana;">SPI Flash and </span><span style="font-size: 10pt; font-family: Verdana;">SD Card (SPI) drivers: SPI MISO pin configuration changed to Input Floating&nbsp;</span></li>
+ </ul>
+
+
+
+ <ol style="margin-top: 0in;" start="2" type="1">
+<li class="MsoNormal" style=""><b><i><span style="font-size: 10pt; font-family: Verdana;">Utilities</span></i></b><b><i><span style="font-size: 10pt;"><o:p></o:p></span></i></b></li>
+ </ol>
+
+
+
+
+
+ <ul style="margin-top: 0in;" type="circle">
+ <li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">Add new directory for STM32100E-EVAL board containing the following files:</span></li>
+ <ul>
+ <li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">stm32100e_eval.h/.c,
+stm32100e_eval_lcd.h/.c, stm32100e_eval_cec.h/.c,
+stm32100e_eval_fsmc_onenand.h/.c, stm32100e_eval_fsmc_sram.h/.c,
+stm32100e_eval_ioe.h/.c</span><br>
+<span style="font-size: 10pt; font-family: Verdana;"><span style="font-style: italic;"></span></span></li>
+ </ul>
+ <li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">Common</span></li><ul><li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">stm32_eval_sdio_sd.c:
+Update the DMA End of Transfer Check loop inside the SD_ReadBlock(),
+SD_WriteBlock(), SD_ReadMultiBlocks() and SD_Write MultiBlocks().</span></li></ul>
+ <ul><li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span style="font-style: italic;">stm32_eval_i2c_ee.c/.h</span> <br>
+ </span></li></ul>
+ <ul>
+ <ul><li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">Enhanced sEE_WaitEepromStandbyState() function for more robustness.</span></li><li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">Enhanced Read and Write operations to manage I2C limitations.</span></li><li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">Add Timeout management with user callback implementation which allows recovering from I2C bus errors.</span></li><li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">Add
+critical sections user callbacks allowing to disable then enable
+interrupts when I2C operation require to be not interrupted.</span></li></ul></ul>
+ <ul><li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span style="font-style: italic;">stm32_eval_i2c_tsensor.c/.h</span> <br>
+ </span></li></ul>
+ <ul>
+ <ul><li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">Enhanced I2C communication functions by using DMA for registers Read and Write operations.</span></li><li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">Add Timeout management with user callback implementation which allows recovering from I2C bus errors.</span></li></ul></ul>
+ <li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">STM32100B_EVAL</span></li><ul><li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">stm32100b_eval.h: Add LM75 DMA defines.</span></li></ul>
+ <ul><li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">stm32100b_eval_lcd.c: </span><span style="font-size: 10pt; font-family: Verdana;">Change "SPI_FLASH" by "sFLASH" in LCD_DrawBMP() function.</span></li></ul>
+ <li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">STM3210B_EVAL</span></li><ul><li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">stm3210b_eval.h: Add LM75 DMA defines.</span></li></ul>
+ <ul><li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">stm3210b_eval_lcd.c: </span><span style="font-size: 10pt; font-family: Verdana;">Change "SPI_FLASH" by "sFLASH" in LCD_DrawBMP() function.</span></li></ul>
+ <li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">STM3210C_EVAL</span></li><ul><li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">stm3210c_eval.h: Add EEPROM driver Timeout define.</span></li></ul>
+ <ul><li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">stm3210c_eval_lcd.c: </span><span style="font-size: 10pt; font-family: Verdana;">Change "SPI_FLASH" by "sFLASH" in LCD_DrawBMP() function.</span></li></ul><ul><li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">stm3210c_eval_i2c_ioe.c</span></li><ul><li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">Enhanced I2C communication functions by using DMA for registers Read and Write operations.</span></li></ul><ul><li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">Add Timeout management with user callback implementation which allows recovering from I2C bus errors.</span></li><li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">change IOE_I2C_SPEED from "400000" to "300000".</span></li></ul></ul>
+ <li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"></span><span style="font-size: 10pt; font-family: Verdana;">STM3210E_EVAL</span></li><ul><li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">stm3210e_eval.c: change "void SD_WaitForDMAEndOfTransfer(void)" to "uint32_t SD_DMAEndOfTransferStatus(void)".</span></li></ul>
+ <ul><li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">stm3210e_eval.h: Add LM75 DMA defines.</span></li></ul>
+ <ul><li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">stm3210e_eval_fsmc_nand.h: remove "NAND_CMD_AREA_TRUE1" define.</span></li></ul>
+ <ul><li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">stm3210e_eval_fsmc_nand.c: Update FSMC timing in NAND_Init() function to be aligned with AN2784 application note.</span></li></ul>
+ <ul><li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">stm3210e_eval_fsmc_nor.c</span></li><ul><li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">NOR</span><span style="font-size: 10pt; font-family: Verdana;">_Init()&nbsp;function: add FSMC_AsynchronousWait&nbsp;field&nbsp;to FSMC_NORSRAMInitStructure&nbsp;</span></li></ul></ul>
+ <ul><li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">stm3210e_eval_fsmc_sram.c<br>
+ </span></li></ul>
+ <ul>
+ <ul><li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">Update FSMC timing in SRAM_Init() function to be aligned with AN2784 application note.</span><br>
+ <span style="font-size: 10pt; font-family: Verdana;"></span></li></ul>
+ <ul><li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">SRAM_Init()&nbsp;function: add FSMC_AsynchronousWait&nbsp;field&nbsp;to FSMC_NORSRAMInitStructure&nbsp;</span></li></ul>
+ </ul>
+ <ul><li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">stm3210e_eval_lcd.c</span></li><ul><li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">LCD_FSMCConfig() function: add FSMC_AsynchronousWait&nbsp;field&nbsp;to FSMC_NORSRAMInitStructure&nbsp;</span></li></ul></ul></ul>
+ <ul style="margin-top: 0in;" type="disc">
+
+
+ </ul>
+
+ <h3 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial; margin-right: 558.05pt;"><span style="font-size: 10pt; font-family: Arial; color: white;">4.2.0
+- 04/16/2010</span></h3>
+ <ol style="margin-top: 0in;" start="1" type="1">
+ <li class="MsoNormal" style=""><b><i><span style="font-size: 10pt; font-family: Verdana;">General</span></i></b><i><span style="font-size: 10pt; font-family: Verdana;"> </span></i><i><span style="font-size: 10pt;"><o:p></o:p></span></i></li>
+ </ol>
+
+ <ul style="margin-top: 0in;" type="disc">
+
+
+ <li class="MsoNormal" style=""><span style="font-size: 10pt; font-family: Verdana;">I2C EEPROM driver
+update to&nbsp;</span><span style="font-size: 10pt; font-family: Verdana;">use the DMA to
+perform&nbsp;data transfer&nbsp;to/from EEPROM memory.</span><span style="font-size: 10pt; font-family: Verdana;"> </span><span style="font-size: 10pt;"><o:p></o:p></span></li>
+
+
+ </ul>
+
+ <ol style="margin-top: 0in;" start="2" type="1">
+ <li class="MsoNormal" style=""><b><i><span style="font-size: 10pt; font-family: Verdana;">Utilities</span></i></b><b><i><span style="font-size: 10pt;"><o:p></o:p></span></i></b></li>
+ </ol>
+ <ul style="margin-top: 0in;" type="disc">
+ <li class="MsoNormal" style=""><i><u><span style="font-size: 10pt; font-family: Verdana;">STM32_EVAL</span></u></i><u><span style="font-size: 10pt;"><o:p></o:p></span></u></li>
+ </ul>
+ <ul style="margin-top: 0in;" type="disc">
+ <ul style="margin-top: 0in;" type="circle">
+ <li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span style="font-style: italic;">stm32_eval_i2c_ee.c</span>:
+updated to use the DMA to perform&nbsp;data transfer&nbsp;to/from
+EEPROM memory. For more details, refer to the description provided
+within this file.</span></li>
+ <li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span style="font-style: italic;">stm3210c_eval.c</span>: add low level
+functions to configure the DMA (needed for I2C EEPROM driver)<br>
+ </span></li>
+ <li class="MsoNormal" style=""><span style="font-size: 10pt; font-family: Verdana;"><span style="font-style: italic;">stm3210c_eval_ioe.c</span>: add a delay
+in&nbsp;IOE_TS_GetState() function to wait till the end of ADC
+conversion</span></li>
+ <li class="MsoNormal" style=""><span style="font-size: 10pt; font-family: Verdana;"><span style="font-style: italic;">stm3210e_eval_fsmc_nor.c</span>: add </span><span style="font-size: 10pt; font-family: Verdana;">PD6 pin </span><span style="font-size: 10pt; font-family: Verdana;">configuration&nbsp;in
+NOR_Init() function</span></li>
+ <li class="MsoNormal" style=""><span style="font-size: 10pt; font-family: Verdana;"><span style="font-style: italic;">stm3210b_eval_lcd.c</span>: remove the
+second ";" from "static void PutPixel(int16_t x, int16_t y);;"&nbsp;</span><span style="font-size: 10pt; font-family: Verdana;"></span></li>
+ </ul>
+ </ul>
+ <h3 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial; margin-right: 558.05pt;"><span style="font-size: 10pt; font-family: Arial; color: white;">4.1.0
+- 03/01/2010</span></h3>
+ <ol style="margin-top: 0in;" start="1" type="1">
+ <li class="MsoNormal" style=""><b><i><span style="font-size: 10pt; font-family: Verdana;">General</span></i></b><i><span style="font-size: 10pt; font-family: Verdana;"> </span></i><i><span style="font-size: 10pt;"><o:p></o:p></span></i></li>
+ </ol>
+ <ul style="margin-top: 0in;" type="disc">
+ <li class="MsoNormal" style=""><span style="font-size: 10pt; font-family: Verdana;">Add support
+for&nbsp;<b>STM32 Low-density Value line (STM32F100x4/6) and
+Medium-density Value line (STM32F100x8/B) devices</b>.</span></li>
+ <li class="MsoNormal" style=""><span style="font-size: 10pt; font-family: Verdana;">Add support for the
+STMicroelectronics STM32100B-EVAL evaluation board. </span><span style="font-size: 10pt;"><o:p></o:p></span></li>
+ </ul>
+ <ol style="margin-top: 0in;" start="2" type="1">
+ <li class="MsoNormal" style=""><b><i><span style="font-size: 10pt; font-family: Verdana;">Utilities</span></i></b><b><i><span style="font-size: 10pt;"><o:p></o:p></span></i></b></li>
+ </ol>
+ <ul style="margin-top: 0in;" type="disc">
+ <li class="MsoNormal" style=""><i><u><span style="font-size: 10pt; font-family: Verdana;">STM32_EVAL</span></u></i><u><span style="font-size: 10pt;"><o:p></o:p></span></u></li>
+ </ul>
+ <ul style="margin-top: 0in;" type="disc">
+ <ul style="margin-top: 0in;" type="circle">
+ <li class="MsoNormal" style=""><span style="font-size: 10pt; font-family: Verdana;"></span><span style="font-size: 10pt; font-family: Verdana;"></span><span style="font-size: 10pt; font-family: Verdana;">Add new directory
+"Common" containing a common drivers for all STM32 evaluation boards:
+fonts.h/.c, stm32_eval_i2c_ee.h/.c, </span><span style="font-size: 10pt; font-family: Verdana;">stm32_eval_spi_flash.h/.c,
+ </span><span style="font-size: 10pt; font-family: Verdana;">stm32_eval_i2c_tsensor.h/.c,
+ </span><span style="font-size: 10pt; font-family: Verdana;">stm32_eval_spi_sd.h/.c
+and </span><span style="font-size: 10pt; font-family: Verdana;">stm32_eval_sdio_sd.h/.c</span></li>
+ <li class="MsoNormal" style=""><span style="font-size: 10pt; font-family: Verdana;">Add new driver for the
+STM32100B-EVAL managing Leds, push button and COM ports.</span></li>
+ <li class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">New HDMI CEC High level
+driver.</span><br>
+ </li>
+ <li class="MsoNormal" style=""><span style="font-size: 10pt; font-family: Verdana;"><span style="font-style: italic;"></span>For all LCD drivers new fonts has
+been added.</span></li>
+ <li class="MsoNormal" style=""><span style="font-size: 10pt; font-family: Verdana;">New FSMC memories
+drivers for STM3210E-EVAL board: stm3210e_eval_fsmc_sram.h/.c, </span><span style="font-size: 10pt; font-family: Verdana;">stm3210e_eval_fsmc_nor.h/.c
+and </span><span style="font-size: 10pt; font-family: Verdana;">stm3210e_eval_fsmc_nand.h/.c.</span></li>
+ </ul>
+ </ul>
+ <h2 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial;"><a name="License"></a><span style="font-size: 12pt; color: white;">License<o:p></o:p></span></h2><p class="MsoNormal"><span style="font-size: 10pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); You may not use this&nbsp;</span><span style="font-size: 10pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">package</span><span style="font-size: 10pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;"> except in compliance with the License. You may obtain a copy of the License at:<br><br></span></p><div style="text-align: center;"><span style="font-size: 10pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a target="_blank" href="http://www.st.com/software_license_agreement_liberty_v2">http://www.st.com/software_license_agreement_liberty_v2</a></span><br><span style="font-size: 10pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;"></span></div><span style="font-size: 10pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;"><br>Unless
+required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS, <br>WITHOUT
+WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
+the License for the specific language governing permissions and
+limitations under the License.</span><b><span style="font-size: 10pt; font-family: Verdana; color: black;"></span></b>
+
+ <div class="MsoNormal" style="text-align: center;" align="center"><span style="color: black;">
+ <hr align="center" size="2" width="100%"></span></div>
+ <p class="MsoNormal" style="margin: 4.5pt 0cm 4.5pt 18pt; text-align: center;" align="center"><span style="font-size: 10pt; font-family: Verdana; color: black;">For
+complete documentation on </span><span style="font-size: 10pt; font-family: Verdana;">STM32<span style="color: black;">&nbsp;Microcontrollers
+visit </span><u><span style="color: blue;"><a href="http://www.st.com/internet/mcu/class/1734.jsp" target="_blank">www.st.com/STM32</a></span></u></span><span style="font-size: 10pt; font-family: Verdana;"><a target="_blank" href="http://www.st.com/internet/mcu/family/141.jsp"><u><span style="color: blue;"></span></u></a></span><span style="font-size: 10pt; font-family: Verdana;"><u><span style="color: blue;"></span></u></span><span style="color: black;"><o:p></o:p></span></p>
+ </td>
+ </tr>
+ </tbody>
+ </table>
+ <p class="MsoNormal"><span style="font-size: 10pt;"><o:p></o:p></span></p>
+ </td>
+ </tr>
+ </tbody>
+</table>
+</div>
+<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
+</div>
+
+</body></html> \ No newline at end of file
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210B_EVAL/stm3210b_eval.c b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210B_EVAL/stm3210b_eval.c
new file mode 100644
index 0000000..338f921
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210B_EVAL/stm3210b_eval.c
@@ -0,0 +1,626 @@
+/**
+ ******************************************************************************
+ * @file stm3210b_eval.c
+ * @author MCD Application Team
+ * @version V5.0.1
+ * @date 05-March-2012
+ * @brief This file provides
+ * - set of firmware functions to manage Leds, push-button and COM ports
+ * - low level initialization functions for SD card (on SPI), SPI serial
+ * flash (sFLASH) and temperature sensor (LM75)
+ * available on STM3210B-EVAL evaluation board from STMicroelectronics.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.st.com/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+
+/* Includes ------------------------------------------------------------------*/
+#include "stm3210b_eval.h"
+
+/** @addtogroup Utilities
+ * @{
+ */
+
+/** @addtogroup STM32_EVAL
+ * @{
+ */
+
+/** @addtogroup STM3210B_EVAL
+ * @{
+ */
+
+/** @defgroup STM3210B_EVAL_LOW_LEVEL
+ * @brief This file provides firmware functions to manage Leds, push-buttons,
+ * COM ports, SD card on SPI, serial flash (sFLASH), serial EEPROM (sEE)
+ * and temperature sensor (LM75) available on STM3210B-EVAL evaluation
+ * board from STMicroelectronics.
+ * @{
+ */
+
+/** @defgroup STM3210B_EVAL_LOW_LEVEL_Private_TypesDefinitions
+ * @{
+ */
+/**
+ * @}
+ */
+
+
+/** @defgroup STM3210B_EVAL_LOW_LEVEL_Private_Defines
+ * @{
+ */
+/**
+ * @}
+ */
+
+
+/** @defgroup STM3210B_EVAL_LOW_LEVEL_Private_Macros
+ * @{
+ */
+/**
+ * @}
+ */
+
+
+/** @defgroup STM3210B_EVAL_LOW_LEVEL_Private_Variables
+ * @{
+ */
+GPIO_TypeDef* GPIO_PORT[LEDn] = {LED1_GPIO_PORT, LED2_GPIO_PORT, LED3_GPIO_PORT,
+ LED4_GPIO_PORT};
+const uint16_t GPIO_PIN[LEDn] = {LED1_PIN, LED2_PIN, LED3_PIN,
+ LED4_PIN};
+const uint32_t GPIO_CLK[LEDn] = {LED1_GPIO_CLK, LED2_GPIO_CLK, LED3_GPIO_CLK,
+ LED4_GPIO_CLK};
+
+GPIO_TypeDef* BUTTON_PORT[BUTTONn] = {WAKEUP_BUTTON_GPIO_PORT, TAMPER_BUTTON_GPIO_PORT,
+ KEY_BUTTON_GPIO_PORT, RIGHT_BUTTON_GPIO_PORT,
+ LEFT_BUTTON_GPIO_PORT, UP_BUTTON_GPIO_PORT,
+ DOWN_BUTTON_GPIO_PORT, SEL_BUTTON_GPIO_PORT};
+
+const uint16_t BUTTON_PIN[BUTTONn] = {WAKEUP_BUTTON_PIN, TAMPER_BUTTON_PIN,
+ KEY_BUTTON_PIN, RIGHT_BUTTON_PIN,
+ LEFT_BUTTON_PIN, UP_BUTTON_PIN,
+ DOWN_BUTTON_PIN, SEL_BUTTON_PIN};
+
+const uint32_t BUTTON_CLK[BUTTONn] = {WAKEUP_BUTTON_GPIO_CLK, TAMPER_BUTTON_GPIO_CLK,
+ KEY_BUTTON_GPIO_CLK, RIGHT_BUTTON_GPIO_CLK,
+ LEFT_BUTTON_GPIO_CLK, UP_BUTTON_GPIO_CLK,
+ DOWN_BUTTON_GPIO_CLK, SEL_BUTTON_GPIO_CLK};
+
+const uint16_t BUTTON_EXTI_LINE[BUTTONn] = {WAKEUP_BUTTON_EXTI_LINE,
+ TAMPER_BUTTON_EXTI_LINE,
+ KEY_BUTTON_EXTI_LINE,
+ RIGHT_BUTTON_EXTI_LINE,
+ LEFT_BUTTON_EXTI_LINE,
+ UP_BUTTON_EXTI_LINE,
+ DOWN_BUTTON_EXTI_LINE,
+ SEL_BUTTON_EXTI_LINE};
+
+const uint16_t BUTTON_PORT_SOURCE[BUTTONn] = {WAKEUP_BUTTON_EXTI_PORT_SOURCE,
+ TAMPER_BUTTON_EXTI_PORT_SOURCE,
+ KEY_BUTTON_EXTI_PORT_SOURCE,
+ RIGHT_BUTTON_EXTI_PORT_SOURCE,
+ LEFT_BUTTON_EXTI_PORT_SOURCE,
+ UP_BUTTON_EXTI_PORT_SOURCE,
+ DOWN_BUTTON_EXTI_PORT_SOURCE,
+ SEL_BUTTON_EXTI_PORT_SOURCE};
+
+const uint16_t BUTTON_PIN_SOURCE[BUTTONn] = {WAKEUP_BUTTON_EXTI_PIN_SOURCE,
+ TAMPER_BUTTON_EXTI_PIN_SOURCE,
+ KEY_BUTTON_EXTI_PIN_SOURCE,
+ RIGHT_BUTTON_EXTI_PIN_SOURCE,
+ LEFT_BUTTON_EXTI_PIN_SOURCE,
+ UP_BUTTON_EXTI_PIN_SOURCE,
+ DOWN_BUTTON_EXTI_PIN_SOURCE,
+ SEL_BUTTON_EXTI_PIN_SOURCE};
+
+const uint16_t BUTTON_IRQn[BUTTONn] = {WAKEUP_BUTTON_EXTI_IRQn, TAMPER_BUTTON_EXTI_IRQn,
+ KEY_BUTTON_EXTI_IRQn, RIGHT_BUTTON_EXTI_IRQn,
+ LEFT_BUTTON_EXTI_IRQn, UP_BUTTON_EXTI_IRQn,
+ DOWN_BUTTON_EXTI_IRQn, SEL_BUTTON_EXTI_IRQn};
+
+USART_TypeDef* COM_USART[COMn] = {EVAL_COM1, EVAL_COM2};
+
+GPIO_TypeDef* COM_TX_PORT[COMn] = {EVAL_COM1_TX_GPIO_PORT, EVAL_COM2_TX_GPIO_PORT};
+
+GPIO_TypeDef* COM_RX_PORT[COMn] = {EVAL_COM1_RX_GPIO_PORT, EVAL_COM2_RX_GPIO_PORT};
+
+const uint32_t COM_USART_CLK[COMn] = {EVAL_COM1_CLK, EVAL_COM2_CLK};
+
+const uint32_t COM_TX_PORT_CLK[COMn] = {EVAL_COM1_TX_GPIO_CLK, EVAL_COM2_TX_GPIO_CLK};
+
+const uint32_t COM_RX_PORT_CLK[COMn] = {EVAL_COM1_RX_GPIO_CLK, EVAL_COM2_RX_GPIO_CLK};
+
+const uint16_t COM_TX_PIN[COMn] = {EVAL_COM1_TX_PIN, EVAL_COM2_TX_PIN};
+
+const uint16_t COM_RX_PIN[COMn] = {EVAL_COM1_RX_PIN, EVAL_COM2_RX_PIN};
+
+
+/**
+ * @}
+ */
+
+
+/** @defgroup STM3210B_EVAL_LOW_LEVEL_Private_FunctionPrototypes
+ * @{
+ */
+
+/**
+ * @}
+ */
+
+
+/** @defgroup STM3210B_EVAL_LOW_LEVEL_Private_Functions
+ * @{
+ */
+
+/**
+ * @brief Configures LED GPIO.
+ * @param Led: Specifies the Led to be configured.
+ * This parameter can be one of following parameters:
+ * @arg LED1
+ * @arg LED2
+ * @arg LED3
+ * @arg LED4
+ * @retval None
+ */
+void STM_EVAL_LEDInit(Led_TypeDef Led)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+
+ /* Enable the GPIO_LED Clock */
+ RCC_APB2PeriphClockCmd(GPIO_CLK[Led], ENABLE);
+
+ /* Configure the GPIO_LED pin */
+ GPIO_InitStructure.GPIO_Pin = GPIO_PIN[Led];
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
+
+ GPIO_Init(GPIO_PORT[Led], &GPIO_InitStructure);
+}
+
+/**
+ * @brief Turns selected LED On.
+ * @param Led: Specifies the Led to be set on.
+ * This parameter can be one of following parameters:
+ * @arg LED1
+ * @arg LED2
+ * @arg LED3
+ * @arg LED4
+ * @retval None
+ */
+void STM_EVAL_LEDOn(Led_TypeDef Led)
+{
+ GPIO_PORT[Led]->BSRR = GPIO_PIN[Led];
+}
+
+/**
+ * @brief Turns selected LED Off.
+ * @param Led: Specifies the Led to be set off.
+ * This parameter can be one of following parameters:
+ * @arg LED1
+ * @arg LED2
+ * @arg LED3
+ * @arg LED4
+ * @retval None
+ */
+void STM_EVAL_LEDOff(Led_TypeDef Led)
+{
+ GPIO_PORT[Led]->BRR = GPIO_PIN[Led];
+}
+
+/**
+ * @brief Toggles the selected LED.
+ * @param Led: Specifies the Led to be toggled.
+ * This parameter can be one of following parameters:
+ * @arg LED1
+ * @arg LED2
+ * @arg LED3
+ * @arg LED4
+ * @retval None
+ */
+void STM_EVAL_LEDToggle(Led_TypeDef Led)
+{
+ GPIO_PORT[Led]->ODR ^= GPIO_PIN[Led];
+}
+
+/**
+ * @brief Configures Button GPIO and EXTI Line.
+ * @param Button: Specifies the Button to be configured.
+ * This parameter can be one of following parameters:
+ * @arg BUTTON_WAKEUP: Wakeup Push Button
+ * @arg BUTTON_TAMPER: Tamper Push Button
+ * @arg BUTTON_KEY: Key Push Button
+ * @arg BUTTON_RIGHT: Joystick Right Push Button
+ * @arg BUTTON_LEFT: Joystick Left Push Button
+ * @arg BUTTON_UP: Joystick Up Push Button
+ * @arg BUTTON_DOWN: Joystick Down Push Button
+ * @arg BUTTON_SEL: Joystick Sel Push Button
+ * @param Button_Mode: Specifies Button mode.
+ * This parameter can be one of following parameters:
+ * @arg BUTTON_MODE_GPIO: Button will be used as simple IO
+ * @arg BUTTON_MODE_EXTI: Button will be connected to EXTI line with interrupt
+ * generation capability
+ * @retval None
+ */
+void STM_EVAL_PBInit(Button_TypeDef Button, ButtonMode_TypeDef Button_Mode)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+ EXTI_InitTypeDef EXTI_InitStructure;
+ NVIC_InitTypeDef NVIC_InitStructure;
+
+ /* Enable the BUTTON Clock */
+ RCC_APB2PeriphClockCmd(BUTTON_CLK[Button] | RCC_APB2Periph_AFIO, ENABLE);
+
+ /* Configure Button pin as input floating */
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
+ GPIO_InitStructure.GPIO_Pin = BUTTON_PIN[Button];
+ GPIO_Init(BUTTON_PORT[Button], &GPIO_InitStructure);
+
+
+ if (Button_Mode == BUTTON_MODE_EXTI)
+ {
+ /* Connect Button EXTI Line to Button GPIO Pin */
+ GPIO_EXTILineConfig(BUTTON_PORT_SOURCE[Button], BUTTON_PIN_SOURCE[Button]);
+
+ /* Configure Button EXTI line */
+ EXTI_InitStructure.EXTI_Line = BUTTON_EXTI_LINE[Button];
+ EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
+
+ if(Button != BUTTON_WAKEUP)
+ {
+ EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
+ }
+ else
+ {
+ EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
+ }
+ EXTI_InitStructure.EXTI_LineCmd = ENABLE;
+ EXTI_Init(&EXTI_InitStructure);
+
+ /* Enable and set Button EXTI Interrupt to the lowest priority */
+ NVIC_InitStructure.NVIC_IRQChannel = BUTTON_IRQn[Button];
+ NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F;
+ NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;
+ NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
+
+ NVIC_Init(&NVIC_InitStructure);
+ }
+}
+
+/**
+ * @brief Returns the selected Button state.
+ * @param Button: Specifies the Button to be checked.
+ * This parameter can be one of following parameters:
+ * @arg BUTTON_WAKEUP: Wakeup Push Button
+ * @arg BUTTON_TAMPER: Tamper Push Button
+ * @arg BUTTON_KEY: Key Push Button
+ * @arg BUTTON_RIGHT: Joystick Right Push Button
+ * @arg BUTTON_LEFT: Joystick Left Push Button
+ * @arg BUTTON_UP: Joystick Up Push Button
+ * @arg BUTTON_DOWN: Joystick Down Push Button
+ * @arg BUTTON_SEL: Joystick Sel Push Button
+ * @retval The Button GPIO pin value.
+ */
+uint32_t STM_EVAL_PBGetState(Button_TypeDef Button)
+{
+ return GPIO_ReadInputDataBit(BUTTON_PORT[Button], BUTTON_PIN[Button]);
+}
+
+/**
+ * @brief Configures COM port.
+ * @param COM: Specifies the COM port to be configured.
+ * This parameter can be one of following parameters:
+ * @arg COM1
+ * @arg COM2
+ * @param USART_InitStruct: pointer to a USART_InitTypeDef structure that
+ * contains the configuration information for the specified USART peripheral.
+ * @retval None
+ */
+void STM_EVAL_COMInit(COM_TypeDef COM, USART_InitTypeDef* USART_InitStruct)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+
+ /* Enable GPIO clock */
+ RCC_APB2PeriphClockCmd(COM_TX_PORT_CLK[COM] | COM_RX_PORT_CLK[COM] | RCC_APB2Periph_AFIO, ENABLE);
+
+ if (COM == COM1)
+ {
+ RCC_APB2PeriphClockCmd(COM_USART_CLK[COM], ENABLE);
+ }
+ else
+ {
+ /* Enable the USART2 Pins Software Remapping */
+ GPIO_PinRemapConfig(GPIO_Remap_USART2, ENABLE);
+ RCC_APB1PeriphClockCmd(COM_USART_CLK[COM], ENABLE);
+ }
+
+ /* Configure USART Tx as alternate function push-pull */
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
+ GPIO_InitStructure.GPIO_Pin = COM_TX_PIN[COM];
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
+ GPIO_Init(COM_TX_PORT[COM], &GPIO_InitStructure);
+
+
+ /* Configure USART Rx as input floating */
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
+ GPIO_InitStructure.GPIO_Pin = COM_RX_PIN[COM];
+ GPIO_Init(COM_RX_PORT[COM], &GPIO_InitStructure);
+
+ /* USART configuration */
+ USART_Init(COM_USART[COM], USART_InitStruct);
+
+ /* Enable USART */
+ USART_Cmd(COM_USART[COM], ENABLE);
+}
+
+/**
+ * @brief DeInitializes the SD/SD communication.
+ * @param None
+ * @retval None
+ */
+void SD_LowLevel_DeInit(void)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+
+ SPI_Cmd(SD_SPI, DISABLE); /*!< SD_SPI disable */
+ SPI_I2S_DeInit(SD_SPI); /*!< DeInitializes the SD_SPI */
+
+ /*!< SD_SPI Periph clock disable */
+ RCC_APB2PeriphClockCmd(SD_SPI_CLK, DISABLE);
+
+ /*!< Configure SD_SPI pins: SCK */
+ GPIO_InitStructure.GPIO_Pin = SD_SPI_SCK_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
+ GPIO_Init(SD_SPI_SCK_GPIO_PORT, &GPIO_InitStructure);
+
+ /*!< Configure SD_SPI pins: MISO */
+ GPIO_InitStructure.GPIO_Pin = SD_SPI_MISO_PIN;
+ GPIO_Init(SD_SPI_MISO_GPIO_PORT, &GPIO_InitStructure);
+
+ /*!< Configure SD_SPI pins: MOSI */
+ GPIO_InitStructure.GPIO_Pin = SD_SPI_MOSI_PIN;
+ GPIO_Init(SD_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure);
+
+ /*!< Configure SD_SPI_CS_PIN pin: SD Card CS pin */
+ GPIO_InitStructure.GPIO_Pin = SD_CS_PIN;
+ GPIO_Init(SD_CS_GPIO_PORT, &GPIO_InitStructure);
+
+ /*!< Configure SD_SPI_DETECT_PIN pin: SD Card detect pin */
+ GPIO_InitStructure.GPIO_Pin = SD_DETECT_PIN;
+ GPIO_Init(SD_DETECT_GPIO_PORT, &GPIO_InitStructure);
+}
+
+/**
+ * @brief Initializes the SD_SPI and CS pins.
+ * @param None
+ * @retval None
+ */
+void SD_LowLevel_Init(void)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+ SPI_InitTypeDef SPI_InitStructure;
+
+ /*!< SD_SPI_CS_GPIO, SD_SPI_MOSI_GPIO, SD_SPI_MISO_GPIO, SD_SPI_DETECT_GPIO
+ and SD_SPI_SCK_GPIO Periph clock enable */
+ RCC_APB2PeriphClockCmd(SD_CS_GPIO_CLK | SD_SPI_MOSI_GPIO_CLK | SD_SPI_MISO_GPIO_CLK |
+ SD_SPI_SCK_GPIO_CLK | SD_DETECT_GPIO_CLK, ENABLE);
+
+ /*!< SD_SPI Periph clock enable */
+ RCC_APB2PeriphClockCmd(SD_SPI_CLK, ENABLE);
+
+
+ /*!< Configure SD_SPI pins: SCK */
+ GPIO_InitStructure.GPIO_Pin = SD_SPI_SCK_PIN;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
+ GPIO_Init(SD_SPI_SCK_GPIO_PORT, &GPIO_InitStructure);
+
+ /*!< Configure SD_SPI pins: MOSI */
+ GPIO_InitStructure.GPIO_Pin = SD_SPI_MOSI_PIN;
+ GPIO_Init(SD_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure);
+
+ /*!< Configure SD_SPI pins: MISO */
+ GPIO_InitStructure.GPIO_Pin = SD_SPI_MISO_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
+ GPIO_Init(SD_SPI_MISO_GPIO_PORT, &GPIO_InitStructure);
+
+ /*!< Configure SD_SPI_CS_PIN pin: SD Card CS pin */
+ GPIO_InitStructure.GPIO_Pin = SD_CS_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
+ GPIO_Init(SD_CS_GPIO_PORT, &GPIO_InitStructure);
+
+ /*!< Configure SD_SPI_DETECT_PIN pin: SD Card detect pin */
+ GPIO_InitStructure.GPIO_Pin = SD_DETECT_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
+ GPIO_Init(SD_DETECT_GPIO_PORT, &GPIO_InitStructure);
+
+ /*!< SD_SPI Config */
+ SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
+ SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
+ SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
+ SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;
+ SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
+ SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
+ SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4;
+ SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
+ SPI_InitStructure.SPI_CRCPolynomial = 7;
+ SPI_Init(SD_SPI, &SPI_InitStructure);
+
+ SPI_Cmd(SD_SPI, ENABLE); /*!< SD_SPI enable */
+}
+
+/**
+ * @brief DeInitializes the peripherals used by the SPI FLASH driver.
+ * @param None
+ * @retval None
+ */
+void sFLASH_LowLevel_DeInit(void)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+
+ /*!< Disable the sFLASH_SPI */
+ SPI_Cmd(sFLASH_SPI, DISABLE);
+
+ /*!< DeInitializes the sFLASH_SPI */
+ SPI_I2S_DeInit(sFLASH_SPI);
+
+ /*!< sFLASH_SPI Periph clock disable */
+ RCC_APB2PeriphClockCmd(sFLASH_SPI_CLK, DISABLE);
+
+ /*!< Configure sFLASH_SPI pins: SCK */
+ GPIO_InitStructure.GPIO_Pin = sFLASH_SPI_SCK_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
+ GPIO_Init(sFLASH_SPI_SCK_GPIO_PORT, &GPIO_InitStructure);
+
+ /*!< Configure sFLASH_SPI pins: MISO */
+ GPIO_InitStructure.GPIO_Pin = sFLASH_SPI_MISO_PIN;
+ GPIO_Init(sFLASH_SPI_MISO_GPIO_PORT, &GPIO_InitStructure);
+
+ /*!< Configure sFLASH_SPI pins: MOSI */
+ GPIO_InitStructure.GPIO_Pin = sFLASH_SPI_MOSI_PIN;
+ GPIO_Init(sFLASH_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure);
+
+ /*!< Configure sFLASH_CS_PIN pin: sFLASH Card CS pin */
+ GPIO_InitStructure.GPIO_Pin = sFLASH_CS_PIN;
+ GPIO_Init(sFLASH_CS_GPIO_PORT, &GPIO_InitStructure);
+}
+
+/**
+ * @brief Initializes the peripherals used by the SPI FLASH driver.
+ * @param None
+ * @retval None
+ */
+void sFLASH_LowLevel_Init(void)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+
+ /*!< sFLASH_SPI_CS_GPIO, sFLASH_SPI_MOSI_GPIO, sFLASH_SPI_MISO_GPIO
+ and sFLASH_SPI_SCK_GPIO Periph clock enable */
+ RCC_APB2PeriphClockCmd(sFLASH_CS_GPIO_CLK | sFLASH_SPI_MOSI_GPIO_CLK | sFLASH_SPI_MISO_GPIO_CLK |
+ sFLASH_SPI_SCK_GPIO_CLK, ENABLE);
+
+ /*!< sFLASH_SPI Periph clock enable */
+ RCC_APB2PeriphClockCmd(sFLASH_SPI_CLK, ENABLE);
+
+ /*!< Configure sFLASH_SPI pins: SCK */
+ GPIO_InitStructure.GPIO_Pin = sFLASH_SPI_SCK_PIN;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
+ GPIO_Init(sFLASH_SPI_SCK_GPIO_PORT, &GPIO_InitStructure);
+
+ /*!< Configure sFLASH_SPI pins: MOSI */
+ GPIO_InitStructure.GPIO_Pin = sFLASH_SPI_MOSI_PIN;
+ GPIO_Init(sFLASH_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure);
+
+ /*!< Configure sFLASH_SPI pins: MISO */
+ GPIO_InitStructure.GPIO_Pin = sFLASH_SPI_MISO_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
+ GPIO_Init(sFLASH_SPI_MISO_GPIO_PORT, &GPIO_InitStructure);
+
+ /*!< Configure sFLASH_CS_PIN pin: sFLASH Card CS pin */
+ GPIO_InitStructure.GPIO_Pin = sFLASH_CS_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
+ GPIO_Init(sFLASH_CS_GPIO_PORT, &GPIO_InitStructure);
+}
+
+/**
+ * @brief DeInitializes the LM75_I2C.
+ * @param None
+ * @retval None
+ */
+void LM75_LowLevel_DeInit(void)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+
+ /*!< Disable LM75_I2C */
+ I2C_Cmd(LM75_I2C, DISABLE);
+ /*!< DeInitializes the LM75_I2C */
+ I2C_DeInit(LM75_I2C);
+
+ /*!< LM75_I2C Periph clock disable */
+ RCC_APB1PeriphClockCmd(LM75_I2C_CLK, DISABLE);
+
+ /*!< Configure LM75_I2C pins: SCL */
+ GPIO_InitStructure.GPIO_Pin = LM75_I2C_SCL_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
+ GPIO_Init(LM75_I2C_SCL_GPIO_PORT, &GPIO_InitStructure);
+
+ /*!< Configure LM75_I2C pins: SDA */
+ GPIO_InitStructure.GPIO_Pin = LM75_I2C_SDA_PIN;
+ GPIO_Init(LM75_I2C_SDA_GPIO_PORT, &GPIO_InitStructure);
+
+ /*!< Configure LM75_I2C pin: SMBUS ALERT */
+ GPIO_InitStructure.GPIO_Pin = LM75_I2C_SMBUSALERT_PIN;
+ GPIO_Init(LM75_I2C_SMBUSALERT_GPIO_PORT, &GPIO_InitStructure);
+}
+
+/**
+ * @brief Initializes the LM75_I2C.
+ * @param None
+ * @retval None
+ */
+void LM75_LowLevel_Init(void)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+
+ /*!< LM75_I2C Periph clock enable */
+ RCC_APB1PeriphClockCmd(LM75_I2C_CLK, ENABLE);
+
+ /*!< LM75_I2C_SCL_GPIO_CLK, LM75_I2C_SDA_GPIO_CLK
+ and LM75_I2C_SMBUSALERT_GPIO_CLK Periph clock enable */
+ RCC_APB2PeriphClockCmd(LM75_I2C_SCL_GPIO_CLK | LM75_I2C_SDA_GPIO_CLK |
+ LM75_I2C_SMBUSALERT_GPIO_CLK, ENABLE);
+
+ /*!< Configure LM75_I2C pins: SCL */
+ GPIO_InitStructure.GPIO_Pin = LM75_I2C_SCL_PIN;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD;
+ GPIO_Init(LM75_I2C_SCL_GPIO_PORT, &GPIO_InitStructure);
+
+ /*!< Configure LM75_I2C pins: SDA */
+ GPIO_InitStructure.GPIO_Pin = LM75_I2C_SDA_PIN;
+ GPIO_Init(LM75_I2C_SDA_GPIO_PORT, &GPIO_InitStructure);
+
+ /*!< Configure LM75_I2C pin: SMBUS ALERT */
+ GPIO_InitStructure.GPIO_Pin = LM75_I2C_SMBUSALERT_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
+ GPIO_Init(LM75_I2C_SMBUSALERT_GPIO_PORT, &GPIO_InitStructure);
+}
+
+/**
+ * @}
+ */
+
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210B_EVAL/stm3210b_eval.h b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210B_EVAL/stm3210b_eval.h
new file mode 100644
index 0000000..0a43b80
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210B_EVAL/stm3210b_eval.h
@@ -0,0 +1,403 @@
+/**
+ ******************************************************************************
+ * @file stm3210b_eval.h
+ * @author MCD Application Team
+ * @version V5.0.1
+ * @date 05-March-2012
+ * @brief This file contains definitions for STM3210B_EVAL's Leds, push-buttons
+ * COM ports, SD Card (on SPI), sFLASH (on SPI) and Temperature sensor
+ * LM75 (on I2C) hardware resources.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.st.com/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __STM3210B_EVAL_H
+#define __STM3210B_EVAL_H
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+/* Includes ------------------------------------------------------------------*/
+#include "stm32f10x.h"
+#include "stm32_eval_legacy.h"
+
+/** @addtogroup Utilities
+ * @{
+ */
+
+/** @addtogroup STM32_EVAL
+ * @{
+ */
+
+/** @addtogroup STM3210B_EVAL
+ * @{
+ */
+
+/** @addtogroup STM3210B_EVAL_LOW_LEVEL
+ * @{
+ */
+
+/** @defgroup STM3210B_EVAL_LOW_LEVEL_Exported_Types
+ * @{
+ */
+typedef enum
+{
+ LED1 = 0,
+ LED2 = 1,
+ LED3 = 2,
+ LED4 = 3
+} Led_TypeDef;
+
+typedef enum
+{
+ BUTTON_WAKEUP = 0,
+ BUTTON_TAMPER = 1,
+ BUTTON_KEY = 2,
+ BUTTON_RIGHT = 3,
+ BUTTON_LEFT = 4,
+ BUTTON_UP = 5,
+ BUTTON_DOWN = 6,
+ BUTTON_SEL = 7
+} Button_TypeDef;
+
+typedef enum
+{
+ BUTTON_MODE_GPIO = 0,
+ BUTTON_MODE_EXTI = 1
+} ButtonMode_TypeDef;
+
+typedef enum
+{
+ JOY_NONE = 0,
+ JOY_SEL = 1,
+ JOY_DOWN = 2,
+ JOY_LEFT = 3,
+ JOY_RIGHT = 4,
+ JOY_UP = 5
+} JOYState_TypeDef
+;
+
+typedef enum
+{
+ COM1 = 0,
+ COM2 = 1
+} COM_TypeDef;
+
+/**
+ * @}
+ */
+
+
+/** @defgroup STM3210B_EVAL_LOW_LEVEL_Exported_Constants
+ * @{
+ */
+
+/**
+ * @brief Define for STM3210B_EVAL board
+ */
+#if !defined (USE_STM3210B_EVAL)
+ #define USE_STM3210B_EVAL
+#endif
+
+/** @addtogroup STM3210B_EVAL_LOW_LEVEL_LED
+ * @{
+ */
+#define LEDn 4
+#define LED1_PIN GPIO_Pin_6
+#define LED1_GPIO_PORT GPIOC
+#define LED1_GPIO_CLK RCC_APB2Periph_GPIOC
+
+#define LED2_PIN GPIO_Pin_7
+#define LED2_GPIO_PORT GPIOC
+#define LED2_GPIO_CLK RCC_APB2Periph_GPIOC
+
+#define LED3_PIN GPIO_Pin_8
+#define LED3_GPIO_PORT GPIOC
+#define LED3_GPIO_CLK RCC_APB2Periph_GPIOC
+
+#define LED4_PIN GPIO_Pin_9
+#define LED4_GPIO_PORT GPIOC
+#define LED4_GPIO_CLK RCC_APB2Periph_GPIOC
+
+/**
+ * @}
+ */
+
+/** @addtogroup STM3210B_EVAL_LOW_LEVEL_BUTTON
+ * @{
+ */
+#define BUTTONn 8
+
+/**
+ * @brief Wakeup push-button
+ */
+#define WAKEUP_BUTTON_PIN GPIO_Pin_0
+#define WAKEUP_BUTTON_GPIO_PORT GPIOA
+#define WAKEUP_BUTTON_GPIO_CLK RCC_APB2Periph_GPIOA
+#define WAKEUP_BUTTON_EXTI_LINE EXTI_Line0
+#define WAKEUP_BUTTON_EXTI_PORT_SOURCE GPIO_PortSourceGPIOA
+#define WAKEUP_BUTTON_EXTI_PIN_SOURCE GPIO_PinSource0
+#define WAKEUP_BUTTON_EXTI_IRQn EXTI0_IRQn
+/**
+ * @brief Tamper push-button
+ */
+#define TAMPER_BUTTON_PIN GPIO_Pin_13
+#define TAMPER_BUTTON_GPIO_PORT GPIOC
+#define TAMPER_BUTTON_GPIO_CLK RCC_APB2Periph_GPIOC
+#define TAMPER_BUTTON_EXTI_LINE EXTI_Line13
+#define TAMPER_BUTTON_EXTI_PORT_SOURCE GPIO_PortSourceGPIOC
+#define TAMPER_BUTTON_EXTI_PIN_SOURCE GPIO_PinSource13
+#define TAMPER_BUTTON_EXTI_IRQn EXTI15_10_IRQn
+/**
+ * @brief Key push-button
+ */
+#define KEY_BUTTON_PIN GPIO_Pin_9
+#define KEY_BUTTON_GPIO_PORT GPIOB
+#define KEY_BUTTON_GPIO_CLK RCC_APB2Periph_GPIOB
+#define KEY_BUTTON_EXTI_LINE EXTI_Line9
+#define KEY_BUTTON_EXTI_PORT_SOURCE GPIO_PortSourceGPIOB
+#define KEY_BUTTON_EXTI_PIN_SOURCE GPIO_PinSource9
+#define KEY_BUTTON_EXTI_IRQn EXTI9_5_IRQn
+/**
+ * @brief Joystick Right push-button
+ */
+#define RIGHT_BUTTON_PIN GPIO_Pin_0
+#define RIGHT_BUTTON_GPIO_PORT GPIOE
+#define RIGHT_BUTTON_GPIO_CLK RCC_APB2Periph_GPIOE
+#define RIGHT_BUTTON_EXTI_LINE EXTI_Line0
+#define RIGHT_BUTTON_EXTI_PORT_SOURCE GPIO_PortSourceGPIOE
+#define RIGHT_BUTTON_EXTI_PIN_SOURCE GPIO_PinSource0
+#define RIGHT_BUTTON_EXTI_IRQn EXTI0_IRQn
+/**
+ * @brief Joystick Left push-button
+ */
+#define LEFT_BUTTON_PIN GPIO_Pin_1
+#define LEFT_BUTTON_GPIO_PORT GPIOE
+#define LEFT_BUTTON_GPIO_CLK RCC_APB2Periph_GPIOE
+#define LEFT_BUTTON_EXTI_LINE EXTI_Line1
+#define LEFT_BUTTON_EXTI_PORT_SOURCE GPIO_PortSourceGPIOE
+#define LEFT_BUTTON_EXTI_PIN_SOURCE GPIO_PinSource1
+#define LEFT_BUTTON_EXTI_IRQn EXTI1_IRQn
+/**
+ * @brief Joystick Up push-button
+ */
+#define UP_BUTTON_PIN GPIO_Pin_8
+#define UP_BUTTON_GPIO_PORT GPIOD
+#define UP_BUTTON_GPIO_CLK RCC_APB2Periph_GPIOD
+#define UP_BUTTON_EXTI_LINE EXTI_Line8
+#define UP_BUTTON_EXTI_PORT_SOURCE GPIO_PortSourceGPIOD
+#define UP_BUTTON_EXTI_PIN_SOURCE GPIO_PinSource8
+#define UP_BUTTON_EXTI_IRQn EXTI9_5_IRQn
+/**
+ * @brief Joystick Down push-button
+ */
+#define DOWN_BUTTON_PIN GPIO_Pin_14
+#define DOWN_BUTTON_GPIO_PORT GPIOD
+#define DOWN_BUTTON_GPIO_CLK RCC_APB2Periph_GPIOD
+#define DOWN_BUTTON_EXTI_LINE EXTI_Line14
+#define DOWN_BUTTON_EXTI_PORT_SOURCE GPIO_PortSourceGPIOD
+#define DOWN_BUTTON_EXTI_PIN_SOURCE GPIO_PinSource14
+#define DOWN_BUTTON_EXTI_IRQn EXTI15_10_IRQn
+/**
+ * @brief Joystick Sel push-button
+ */
+#define SEL_BUTTON_PIN GPIO_Pin_12
+#define SEL_BUTTON_GPIO_PORT GPIOD
+#define SEL_BUTTON_GPIO_CLK RCC_APB2Periph_GPIOD
+#define SEL_BUTTON_EXTI_LINE EXTI_Line12
+#define SEL_BUTTON_EXTI_PORT_SOURCE GPIO_PortSourceGPIOD
+#define SEL_BUTTON_EXTI_PIN_SOURCE GPIO_PinSource12
+#define SEL_BUTTON_EXTI_IRQn EXTI15_10_IRQn
+/**
+ * @}
+ */
+
+/** @addtogroup STM3210B_EVAL_LOW_LEVEL_COM
+ * @{
+ */
+#define COMn 2
+
+/**
+ * @brief Definition for COM port1, connected to USART1
+ */
+#define EVAL_COM1 USART1
+#define EVAL_COM1_CLK RCC_APB2Periph_USART1
+#define EVAL_COM1_TX_PIN GPIO_Pin_9
+#define EVAL_COM1_TX_GPIO_PORT GPIOA
+#define EVAL_COM1_TX_GPIO_CLK RCC_APB2Periph_GPIOA
+#define EVAL_COM1_RX_PIN GPIO_Pin_10
+#define EVAL_COM1_RX_GPIO_PORT GPIOA
+#define EVAL_COM1_RX_GPIO_CLK RCC_APB2Periph_GPIOA
+#define EVAL_COM1_IRQn USART1_IRQn
+
+/**
+ * @brief Definition for COM port2, connected to USART2 (USART2 pins remapped on GPIOD)
+ */
+#define EVAL_COM2 USART2
+#define EVAL_COM2_CLK RCC_APB1Periph_USART2
+#define EVAL_COM2_TX_PIN GPIO_Pin_5
+#define EVAL_COM2_TX_GPIO_PORT GPIOD
+#define EVAL_COM2_TX_GPIO_CLK RCC_APB2Periph_GPIOD
+#define EVAL_COM2_RX_PIN GPIO_Pin_6
+#define EVAL_COM2_RX_GPIO_PORT GPIOD
+#define EVAL_COM2_RX_GPIO_CLK RCC_APB2Periph_GPIOD
+#define EVAL_COM2_IRQn USART2_IRQn
+
+/**
+ * @}
+ */
+
+/** @addtogroup STM3210B_EVAL_LOW_LEVEL_SD_SPI
+ * @{
+ */
+/**
+ * @brief SD SPI Interface pins
+ */
+#define SD_SPI SPI1
+#define SD_SPI_CLK RCC_APB2Periph_SPI1
+#define SD_SPI_SCK_PIN GPIO_Pin_5 /* PA.05 */
+#define SD_SPI_SCK_GPIO_PORT GPIOA /* GPIOA */
+#define SD_SPI_SCK_GPIO_CLK RCC_APB2Periph_GPIOA
+#define SD_SPI_MISO_PIN GPIO_Pin_6 /* PA.06 */
+#define SD_SPI_MISO_GPIO_PORT GPIOA /* GPIOA */
+#define SD_SPI_MISO_GPIO_CLK RCC_APB2Periph_GPIOA
+#define SD_SPI_MOSI_PIN GPIO_Pin_7 /* PA.07 */
+#define SD_SPI_MOSI_GPIO_PORT GPIOA /* GPIOA */
+#define SD_SPI_MOSI_GPIO_CLK RCC_APB2Periph_GPIOA
+#define SD_CS_PIN GPIO_Pin_12 /* PC.12 */
+#define SD_CS_GPIO_PORT GPIOC /* GPIOC */
+#define SD_CS_GPIO_CLK RCC_APB2Periph_GPIOC
+#define SD_DETECT_PIN GPIO_Pin_7 /* PE.07 */
+#define SD_DETECT_GPIO_PORT GPIOE /* GPIOE */
+#define SD_DETECT_GPIO_CLK RCC_APB2Periph_GPIOE
+
+/**
+ * @}
+ */
+
+/** @addtogroup STM3210B_EVAL_LOW_LEVEL_M25P_FLASH_SPI
+ * @{
+ */
+/**
+ * @brief M25P FLASH SPI Interface pins
+ */
+#define sFLASH_SPI SPI1
+#define sFLASH_SPI_CLK RCC_APB2Periph_SPI1
+#define sFLASH_SPI_SCK_PIN GPIO_Pin_5 /* PA.05 */
+#define sFLASH_SPI_SCK_GPIO_PORT GPIOA /* GPIOA */
+#define sFLASH_SPI_SCK_GPIO_CLK RCC_APB2Periph_GPIOA
+#define sFLASH_SPI_MISO_PIN GPIO_Pin_6 /* PA.06 */
+#define sFLASH_SPI_MISO_GPIO_PORT GPIOA /* GPIOA */
+#define sFLASH_SPI_MISO_GPIO_CLK RCC_APB2Periph_GPIOA
+#define sFLASH_SPI_MOSI_PIN GPIO_Pin_7 /* PA.07 */
+#define sFLASH_SPI_MOSI_GPIO_PORT GPIOA /* GPIOA */
+#define sFLASH_SPI_MOSI_GPIO_CLK RCC_APB2Periph_GPIOA
+#define sFLASH_CS_PIN GPIO_Pin_4 /* PA.04 */
+#define sFLASH_CS_GPIO_PORT GPIOA /* GPIOA */
+#define sFLASH_CS_GPIO_CLK RCC_APB2Periph_GPIOA
+
+/**
+ * @}
+ */
+
+/** @addtogroup STM3210B_EVAL_LOW_LEVEL_TSENSOR_I2C
+ * @{
+ */
+/**
+ * @brief LM75 Temperature Sensor I2C Interface pins
+ */
+#define LM75_I2C I2C1
+#define LM75_I2C_CLK RCC_APB1Periph_I2C1
+#define LM75_I2C_SCL_PIN GPIO_Pin_6 /* PB.06 */
+#define LM75_I2C_SCL_GPIO_PORT GPIOB /* GPIOB */
+#define LM75_I2C_SCL_GPIO_CLK RCC_APB2Periph_GPIOB
+#define LM75_I2C_SDA_PIN GPIO_Pin_7 /* PB.07 */
+#define LM75_I2C_SDA_GPIO_PORT GPIOB /* GPIOB */
+#define LM75_I2C_SDA_GPIO_CLK RCC_APB2Periph_GPIOB
+#define LM75_I2C_SMBUSALERT_PIN GPIO_Pin_5 /* PB.05 */
+#define LM75_I2C_SMBUSALERT_GPIO_PORT GPIOB /* GPIOB */
+#define LM75_I2C_SMBUSALERT_GPIO_CLK RCC_APB2Periph_GPIOB
+#define LM75_I2C_DR ((uint32_t)0x40005410)
+
+#define LM75_DMA_CLK RCC_AHBPeriph_DMA1
+#define LM75_DMA_TX_CHANNEL DMA1_Channel6
+#define LM75_DMA_RX_CHANNEL DMA1_Channel7
+#define LM75_DMA_TX_TCFLAG DMA1_FLAG_TC6
+#define LM75_DMA_RX_TCFLAG DMA1_FLAG_TC7
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/** @defgroup STM3210B_EVAL_LOW_LEVEL_Exported_Macros
+ * @{
+ */
+/**
+ * @}
+ */
+
+/** @defgroup STM3210B_EVAL_LOW_LEVEL_Exported_Functions
+ * @{
+ */
+void STM_EVAL_LEDInit(Led_TypeDef Led);
+void STM_EVAL_LEDOn(Led_TypeDef Led);
+void STM_EVAL_LEDOff(Led_TypeDef Led);
+void STM_EVAL_LEDToggle(Led_TypeDef Led);
+void STM_EVAL_PBInit(Button_TypeDef Button, ButtonMode_TypeDef Button_Mode);
+uint32_t STM_EVAL_PBGetState(Button_TypeDef Button);
+void STM_EVAL_COMInit(COM_TypeDef COM, USART_InitTypeDef* USART_InitStruct);
+void SD_LowLevel_DeInit(void);
+void SD_LowLevel_Init(void);
+void sFLASH_LowLevel_DeInit(void);
+void sFLASH_LowLevel_Init(void);
+void LM75_LowLevel_DeInit(void);
+void LM75_LowLevel_Init(void);
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __STM3210B_EVAL_H */
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210B_EVAL/stm3210b_eval_i2c_tsensor.c b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210B_EVAL/stm3210b_eval_i2c_tsensor.c
new file mode 100644
index 0000000..b10d513
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210B_EVAL/stm3210b_eval_i2c_tsensor.c
@@ -0,0 +1,982 @@
+/**
+ ******************************************************************************
+ * @file stm3210b_eval_i2c_tsensor.c
+ * @author MCD Application Team
+ * @version V5.0.1
+ * @date 05-March-2012
+ * @brief This file provides a set of functions needed to manage the I2C LM75
+ * temperature sensor mounted on STM3210B-EVAL board.
+ * It implements a high level communication layer for read and write
+ * from/to this sensor. The needed STM32 hardware resources (I2C and
+ * GPIO) are defined in stm3210b_eval.h file, and the initialization is
+ * performed in LM75_LowLevel_Init() function declared in stm3210b_eval.c
+ * file.
+ *
+ * Note:
+ * -----
+ * This driver uses the DMA method to send and receive data on I2C bus,
+ * which allows higher efficiency and reliability of the communication.
+ *
+ * You can easily tailor this driver to any other development board,
+ * by just adapting the defines for hardware resources and
+ * LM75_LowLevel_Init() function.
+ *
+ * +-----------------------------------------------------------------+
+ * | Pin assignment |
+ * +---------------------------------------+-----------+-------------+
+ * | STM32 I2C Pins | STLM75 | Pin |
+ * +---------------------------------------+-----------+-------------+
+ * | LM75_I2C_SDA_PIN/ SDA | SDA | 1 |
+ * | LM75_I2C_SCL_PIN/ SCL | SCL | 2 |
+ * | LM75_I2C_SMBUSALERT_PIN/ SMBUS ALERT | OS/INT | 3 |
+ * | . | GND | 4 (0V) |
+ * | . | GND | 5 (0V) |
+ * | . | GND | 6 (0V) |
+ * | . | GND | 7 (0V) |
+ * | . | VDD | 8 (3.3V)|
+ * +---------------------------------------+-----------+-------------+
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.st.com/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+
+/* Includes ------------------------------------------------------------------*/
+#include "stm3210b_eval_i2c_tsensor.h"
+
+/** @addtogroup Utilities
+ * @{
+ */
+
+/** @addtogroup STM32_EVAL
+ * @{
+ */
+
+/** @addtogroup STM3210B_EVAL
+ * @{
+ */
+
+/** @addtogroup STM3210B_EVAL_I2C_TSENSOR
+ * @brief This file includes the LM75 Temperature Sensor driver of
+ * STM3210B-EVAL board.
+ * @{
+ */
+
+/** @defgroup STM3210B_EVAL_I2C_TSENSOR_Private_Types
+ * @{
+ */
+/**
+ * @}
+ */
+
+/** @defgroup STM3210B_EVAL_I2C_TSENSOR_Private_Defines
+ * @{
+ */
+#define LM75_SD_SET 0x01 /*!< Set SD bit in the configuration register */
+#define LM75_SD_RESET 0xFE /*!< Reset SD bit in the configuration register */
+/**
+ * @}
+ */
+
+/** @defgroup STM3210B_EVAL_I2C_TSENSOR_Private_Macros
+ * @{
+ */
+/**
+ * @}
+ */
+
+/** @defgroup STM3210B_EVAL_I2C_TSENSOR_Private_Variables
+ * @{
+ */
+
+__IO uint32_t LM75_Timeout = LM75_LONG_TIMEOUT;
+/**
+ * @}
+ */
+
+/** @defgroup STM3210B_EVAL_I2C_TSENSOR_Private_Function_Prototypes
+ * @{
+ */
+static void LM75_DMA_Config(LM75_DMADirection_TypeDef Direction, uint8_t* buffer, uint8_t NumData);
+
+/**
+ * @}
+ */
+
+
+/** @defgroup STM3210B_EVAL_I2C_TSENSOR_Private_Functions
+ * @{
+ */
+
+/**
+ * @brief DeInitializes the LM75_I2C.
+ * @param None
+ * @retval None
+ */
+void LM75_DeInit(void)
+{
+ LM75_LowLevel_DeInit();
+}
+
+/**
+ * @brief Initializes the LM75_I2C.
+ * @param None
+ * @retval None
+ */
+void LM75_Init(void)
+{
+ I2C_InitTypeDef I2C_InitStructure;
+
+ LM75_LowLevel_Init();
+
+ I2C_DeInit(LM75_I2C);
+
+ /*!< LM75_I2C Init */
+ I2C_InitStructure.I2C_Mode = I2C_Mode_SMBusHost;
+ I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;
+ I2C_InitStructure.I2C_OwnAddress1 = 0x00;
+ I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
+ I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
+ I2C_InitStructure.I2C_ClockSpeed = LM75_I2C_SPEED;
+ I2C_Init(LM75_I2C, &I2C_InitStructure);
+
+ /*!< Enable SMBus Alert interrupt */
+ I2C_ITConfig(LM75_I2C, I2C_IT_ERR, ENABLE);
+
+ /*!< LM75_I2C Init */
+ I2C_Cmd(LM75_I2C, ENABLE);
+}
+
+
+/**
+ * @brief Configure the DMA Peripheral used to handle communication via I2C.
+ * @param None
+ * @retval None
+ */
+
+static void LM75_DMA_Config(LM75_DMADirection_TypeDef Direction, uint8_t* buffer, uint8_t NumData)
+{
+ DMA_InitTypeDef DMA_InitStructure;
+
+ RCC_AHBPeriphClockCmd(LM75_DMA_CLK, ENABLE);
+
+ /* Initialize the DMA_PeripheralBaseAddr member */
+ DMA_InitStructure.DMA_PeripheralBaseAddr = LM75_I2C_DR;
+ /* Initialize the DMA_MemoryBaseAddr member */
+ DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)buffer;
+ /* Initialize the DMA_PeripheralInc member */
+ DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
+ /* Initialize the DMA_MemoryInc member */
+ DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
+ /* Initialize the DMA_PeripheralDataSize member */
+ DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
+ /* Initialize the DMA_MemoryDataSize member */
+ DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
+ /* Initialize the DMA_Mode member */
+ DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
+ /* Initialize the DMA_Priority member */
+ DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh;
+ /* Initialize the DMA_M2M member */
+ DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
+
+ /* If using DMA for Reception */
+ if (Direction == LM75_DMA_RX)
+ {
+ /* Initialize the DMA_DIR member */
+ DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
+
+ /* Initialize the DMA_BufferSize member */
+ DMA_InitStructure.DMA_BufferSize = NumData;
+
+ DMA_DeInit(LM75_DMA_RX_CHANNEL);
+
+ DMA_Init(LM75_DMA_RX_CHANNEL, &DMA_InitStructure);
+ }
+ /* If using DMA for Transmission */
+ else if (Direction == LM75_DMA_TX)
+ {
+ /* Initialize the DMA_DIR member */
+ DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
+
+ /* Initialize the DMA_BufferSize member */
+ DMA_InitStructure.DMA_BufferSize = NumData;
+
+ DMA_DeInit(LM75_DMA_TX_CHANNEL);
+
+ DMA_Init(LM75_DMA_TX_CHANNEL, &DMA_InitStructure);
+ }
+}
+
+
+/**
+ * @brief Checks the LM75 status.
+ * @param None
+ * @retval ErrorStatus: LM75 Status (ERROR or SUCCESS).
+ */
+ErrorStatus LM75_GetStatus(void)
+{
+ uint32_t I2C_TimeOut = I2C_TIMEOUT;
+
+ /*!< Clear the LM75_I2C AF flag */
+ I2C_ClearFlag(LM75_I2C, I2C_FLAG_AF);
+
+ /*!< Enable LM75_I2C acknowledgement if it is already disabled by other function */
+ I2C_AcknowledgeConfig(LM75_I2C, ENABLE);
+
+ /*---------------------------- Transmission Phase ---------------------------*/
+
+ /*!< Send LM75_I2C START condition */
+ I2C_GenerateSTART(LM75_I2C, ENABLE);
+
+ /*!< Test on LM75_I2C EV5 and clear it */
+ while ((!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_SB)) && I2C_TimeOut) /*!< EV5 */
+ {
+ I2C_TimeOut--;
+ }
+ if (I2C_TimeOut == 0)
+ {
+ return ERROR;
+ }
+
+ I2C_TimeOut = I2C_TIMEOUT;
+
+ /*!< Send STLM75 slave address for write */
+ I2C_Send7bitAddress(LM75_I2C, LM75_ADDR, I2C_Direction_Transmitter);
+
+ while ((!I2C_CheckEvent(LM75_I2C, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)) && I2C_TimeOut)/* EV6 */
+ {
+ I2C_TimeOut--;
+ }
+
+ if ((I2C_GetFlagStatus(LM75_I2C, I2C_FLAG_AF) != 0x00) || (I2C_TimeOut == 0))
+ {
+ return ERROR;
+ }
+ else
+ {
+ return SUCCESS;
+ }
+}
+/**
+ * @brief Read the specified register from the LM75.
+ * @param RegName: specifies the LM75 register to be read.
+ * This member can be one of the following values:
+ * - LM75_REG_TEMP: temperature register
+ * - LM75_REG_TOS: Over-limit temperature register
+ * - LM75_REG_THYS: Hysteresis temperature register
+ * @retval LM75 register value.
+ */
+uint16_t LM75_ReadReg(uint8_t RegName)
+{
+ uint8_t LM75_BufferRX[2] ={0,0};
+ uint16_t tmp = 0;
+
+ /* Test on BUSY Flag */
+ LM75_Timeout = LM75_LONG_TIMEOUT;
+ while (I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BUSY))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Configure DMA Peripheral */
+ LM75_DMA_Config(LM75_DMA_RX, (uint8_t*)LM75_BufferRX, 2);
+
+ /* Enable DMA NACK automatic generation */
+ I2C_DMALastTransferCmd(LM75_I2C, ENABLE);
+
+ /* Enable the I2C peripheral */
+ I2C_GenerateSTART(LM75_I2C, ENABLE);
+
+ /* Test on SB Flag */
+ LM75_Timeout = LM75_FLAG_TIMEOUT;
+ while (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_SB))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Send device address for write */
+ I2C_Send7bitAddress(LM75_I2C, LM75_ADDR, I2C_Direction_Transmitter);
+
+ /* Test on ADDR Flag */
+ LM75_Timeout = LM75_FLAG_TIMEOUT;
+ while (!I2C_CheckEvent(LM75_I2C, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Send the device's internal address to write to */
+ I2C_SendData(LM75_I2C, RegName);
+
+ /* Test on TXE FLag (data sent) */
+ LM75_Timeout = LM75_FLAG_TIMEOUT;
+ while ((!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_TXE)) && (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BTF)))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Send START condition a second time */
+ I2C_GenerateSTART(LM75_I2C, ENABLE);
+
+ /* Test on SB Flag */
+ LM75_Timeout = LM75_FLAG_TIMEOUT;
+ while (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_SB))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Send LM75 address for read */
+ I2C_Send7bitAddress(LM75_I2C, LM75_ADDR, I2C_Direction_Receiver);
+
+ /* Test on ADDR Flag */
+ LM75_Timeout = LM75_FLAG_TIMEOUT;
+ while (!I2C_CheckEvent(LM75_I2C, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Enable I2C DMA request */
+ I2C_DMACmd(LM75_I2C,ENABLE);
+
+ /* Enable DMA RX Channel */
+ DMA_Cmd(LM75_DMA_RX_CHANNEL, ENABLE);
+
+ /* Wait until DMA Transfer Complete */
+ LM75_Timeout = LM75_LONG_TIMEOUT;
+ while (!DMA_GetFlagStatus(LM75_DMA_RX_TCFLAG))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Send STOP Condition */
+ I2C_GenerateSTOP(LM75_I2C, ENABLE);
+
+ /* Disable DMA RX Channel */
+ DMA_Cmd(LM75_DMA_RX_CHANNEL, DISABLE);
+
+ /* Disable I2C DMA request */
+ I2C_DMACmd(LM75_I2C,DISABLE);
+
+ /* Clear DMA RX Transfer Complete Flag */
+ DMA_ClearFlag(LM75_DMA_RX_TCFLAG);
+
+ /*!< Store LM75_I2C received data */
+ tmp = (uint16_t)(LM75_BufferRX[0] << 8);
+ tmp |= LM75_BufferRX[1];
+
+ /* return a Reg value */
+ return (uint16_t)tmp;
+}
+
+/**
+ * @brief Write to the specified register of the LM75.
+ * @param RegName: specifies the LM75 register to be written.
+ * This member can be one of the following values:
+ * - LM75_REG_TOS: Over-limit temperature register
+ * - LM75_REG_THYS: Hysteresis temperature register
+ * @param RegValue: value to be written to LM75 register.
+ * @retval None
+ */
+uint8_t LM75_WriteReg(uint8_t RegName, uint16_t RegValue)
+{
+ uint8_t LM75_BufferTX[2] ={0,0};
+ LM75_BufferTX[0] = (uint8_t)(RegValue >> 8);
+ LM75_BufferTX[1] = (uint8_t)(RegValue);
+
+ /* Test on BUSY Flag */
+ LM75_Timeout = LM75_LONG_TIMEOUT;
+ while (I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BUSY))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Configure DMA Peripheral */
+ LM75_DMA_Config(LM75_DMA_TX, (uint8_t*)LM75_BufferTX, 2);
+
+ /* Enable the I2C peripheral */
+ I2C_GenerateSTART(LM75_I2C, ENABLE);
+
+ /* Test on SB Flag */
+ LM75_Timeout = LM75_FLAG_TIMEOUT;
+ while (I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_SB) == RESET)
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Transmit the slave address and enable writing operation */
+ I2C_Send7bitAddress(LM75_I2C, LM75_ADDR, I2C_Direction_Transmitter);
+
+ /* Test on ADDR Flag */
+ LM75_Timeout = LM75_FLAG_TIMEOUT;
+ while (!I2C_CheckEvent(LM75_I2C, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Transmit the first address for r/w operations */
+ I2C_SendData(LM75_I2C, RegName);
+
+ /* Test on TXE FLag (data sent) */
+ LM75_Timeout = LM75_FLAG_TIMEOUT;
+ while ((!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_TXE)) && (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BTF)))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Enable I2C DMA request */
+ I2C_DMACmd(LM75_I2C,ENABLE);
+
+ /* Enable DMA TX Channel */
+ DMA_Cmd(LM75_DMA_TX_CHANNEL, ENABLE);
+
+ /* Wait until DMA Transfer Complete */
+ LM75_Timeout = LM75_LONG_TIMEOUT;
+ while (!DMA_GetFlagStatus(LM75_DMA_TX_TCFLAG))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Wait until BTF Flag is set before generating STOP */
+ LM75_Timeout = LM75_LONG_TIMEOUT;
+ while (I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BTF))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Send STOP Condition */
+ I2C_GenerateSTOP(LM75_I2C, ENABLE);
+
+ /* Disable DMA TX Channel */
+ DMA_Cmd(LM75_DMA_TX_CHANNEL, DISABLE);
+
+ /* Disable I2C DMA request */
+ I2C_DMACmd(LM75_I2C,DISABLE);
+
+ /* Clear DMA TX Transfer Complete Flag */
+ DMA_ClearFlag(LM75_DMA_TX_TCFLAG);
+
+ return LM75_OK;
+}
+
+/**
+ * @brief Read Temperature register of LM75: double temperature value.
+ * @param None
+ * @retval LM75 measured temperature value.
+ */
+uint16_t LM75_ReadTemp(void)
+{
+ uint8_t LM75_BufferRX[2] ={0,0};
+ uint16_t tmp = 0;
+
+ /* Test on BUSY Flag */
+ LM75_Timeout = LM75_LONG_TIMEOUT;
+ while (I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BUSY))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Configure DMA Peripheral */
+ LM75_DMA_Config(LM75_DMA_RX, (uint8_t*)LM75_BufferRX, 2);
+
+ /* Enable DMA NACK automatic generation */
+ I2C_DMALastTransferCmd(LM75_I2C, ENABLE);
+
+ /* Enable the I2C peripheral */
+ I2C_GenerateSTART(LM75_I2C, ENABLE);
+
+ /* Test on SB Flag */
+ LM75_Timeout = LM75_FLAG_TIMEOUT;
+ while (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_SB))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Send device address for write */
+ I2C_Send7bitAddress(LM75_I2C, LM75_ADDR, I2C_Direction_Transmitter);
+
+ /* Test on ADDR Flag */
+ LM75_Timeout = LM75_FLAG_TIMEOUT;
+ while (!I2C_CheckEvent(LM75_I2C, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Send the device's internal address to write to */
+ I2C_SendData(LM75_I2C, LM75_REG_TEMP);
+
+ /* Test on TXE FLag (data sent) */
+ LM75_Timeout = LM75_FLAG_TIMEOUT;
+ while ((!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_TXE)) && (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BTF)))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Send START condition a second time */
+ I2C_GenerateSTART(LM75_I2C, ENABLE);
+
+ /* Test on SB Flag */
+ LM75_Timeout = LM75_FLAG_TIMEOUT;
+ while (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_SB))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Send LM75 address for read */
+ I2C_Send7bitAddress(LM75_I2C, LM75_ADDR, I2C_Direction_Receiver);
+
+ /* Test on ADDR Flag */
+ LM75_Timeout = LM75_FLAG_TIMEOUT;
+ while (!I2C_CheckEvent(LM75_I2C, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Enable I2C DMA request */
+ I2C_DMACmd(LM75_I2C,ENABLE);
+
+ /* Enable DMA RX Channel */
+ DMA_Cmd(LM75_DMA_RX_CHANNEL, ENABLE);
+
+ /* Wait until DMA Transfer Complete */
+ LM75_Timeout = LM75_LONG_TIMEOUT;
+ while (!DMA_GetFlagStatus(LM75_DMA_RX_TCFLAG))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Send STOP Condition */
+ I2C_GenerateSTOP(LM75_I2C, ENABLE);
+
+ /* Disable DMA RX Channel */
+ DMA_Cmd(LM75_DMA_RX_CHANNEL, DISABLE);
+
+ /* Disable I2C DMA request */
+ I2C_DMACmd(LM75_I2C,DISABLE);
+
+ /* Clear DMA RX Transfer Complete Flag */
+ DMA_ClearFlag(LM75_DMA_RX_TCFLAG);
+
+ /*!< Store LM75_I2C received data */
+ tmp = (uint16_t)(LM75_BufferRX[0] << 8);
+ tmp |= LM75_BufferRX[1];
+
+ /*!< Return Temperature value */
+ return (uint16_t)(tmp >> 7);
+}
+
+/**
+ * @brief Read the configuration register from the LM75.
+ * @param None
+ * @retval LM75 configuration register value.
+ */
+uint8_t LM75_ReadConfReg(void)
+{
+ uint8_t LM75_BufferRX[2] ={0,0};
+
+ /* Test on BUSY Flag */
+ LM75_Timeout = LM75_LONG_TIMEOUT;
+ while (I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BUSY))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Configure DMA Peripheral */
+ LM75_DMA_Config(LM75_DMA_RX, (uint8_t*)LM75_BufferRX, 2);
+
+ /* Enable DMA NACK automatic generation */
+ I2C_DMALastTransferCmd(LM75_I2C, ENABLE);
+
+ /* Enable the I2C peripheral */
+ I2C_GenerateSTART(LM75_I2C, ENABLE);
+
+ /* Test on SB Flag */
+ LM75_Timeout = LM75_FLAG_TIMEOUT;
+ while (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_SB))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Send device address for write */
+ I2C_Send7bitAddress(LM75_I2C, LM75_ADDR, I2C_Direction_Transmitter);
+
+ /* Test on ADDR Flag */
+ LM75_Timeout = LM75_FLAG_TIMEOUT;
+ while (!I2C_CheckEvent(LM75_I2C, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Send the device's internal address to write to */
+ I2C_SendData(LM75_I2C, LM75_REG_CONF);
+
+ /* Test on TXE FLag (data sent) */
+ LM75_Timeout = LM75_FLAG_TIMEOUT;
+ while ((!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_TXE)) && (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BTF)))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Send START condition a second time */
+ I2C_GenerateSTART(LM75_I2C, ENABLE);
+
+ /* Test on SB Flag */
+ LM75_Timeout = LM75_FLAG_TIMEOUT;
+ while (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_SB))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Send LM75 address for read */
+ I2C_Send7bitAddress(LM75_I2C, LM75_ADDR, I2C_Direction_Receiver);
+
+ /* Test on ADDR Flag */
+ LM75_Timeout = LM75_FLAG_TIMEOUT;
+ while (!I2C_CheckEvent(LM75_I2C, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Enable I2C DMA request */
+ I2C_DMACmd(LM75_I2C,ENABLE);
+
+ /* Enable DMA RX Channel */
+ DMA_Cmd(LM75_DMA_RX_CHANNEL, ENABLE);
+
+ /* Wait until DMA Transfer Complete */
+ LM75_Timeout = LM75_LONG_TIMEOUT;
+ while (!DMA_GetFlagStatus(LM75_DMA_RX_TCFLAG))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Send STOP Condition */
+ I2C_GenerateSTOP(LM75_I2C, ENABLE);
+
+ /* Disable DMA RX Channel */
+ DMA_Cmd(LM75_DMA_RX_CHANNEL, DISABLE);
+
+ /* Disable I2C DMA request */
+ I2C_DMACmd(LM75_I2C,DISABLE);
+
+ /* Clear DMA RX Transfer Complete Flag */
+ DMA_ClearFlag(LM75_DMA_RX_TCFLAG);
+
+ /*!< Return Temperature value */
+ return (uint8_t)LM75_BufferRX[0];
+}
+
+/**
+ * @brief Write to the configuration register of the LM75.
+ * @param RegValue: sepecifies the value to be written to LM75 configuration
+ * register.
+ * @retval None
+ */
+uint8_t LM75_WriteConfReg(uint8_t RegValue)
+{
+ uint8_t LM75_BufferTX = 0;
+ LM75_BufferTX = (uint8_t)(RegValue);
+
+ /* Test on BUSY Flag */
+ LM75_Timeout = LM75_LONG_TIMEOUT;
+ while (I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BUSY))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Configure DMA Peripheral */
+ LM75_DMA_Config(LM75_DMA_TX, (uint8_t*)(&LM75_BufferTX), 1);
+
+ /* Enable the I2C peripheral */
+ I2C_GenerateSTART(LM75_I2C, ENABLE);
+
+ /* Test on SB Flag */
+ LM75_Timeout = LM75_FLAG_TIMEOUT;
+ while (I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_SB) == RESET)
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Transmit the slave address and enable writing operation */
+ I2C_Send7bitAddress(LM75_I2C, LM75_ADDR, I2C_Direction_Transmitter);
+
+ /* Test on ADDR Flag */
+ LM75_Timeout = LM75_FLAG_TIMEOUT;
+ while (!I2C_CheckEvent(LM75_I2C, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Transmit the first address for r/w operations */
+ I2C_SendData(LM75_I2C, LM75_REG_CONF);
+
+ /* Test on TXE FLag (data sent) */
+ LM75_Timeout = LM75_FLAG_TIMEOUT;
+ while ((!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_TXE)) && (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BTF)))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Enable I2C DMA request */
+ I2C_DMACmd(LM75_I2C,ENABLE);
+
+ /* Enable DMA TX Channel */
+ DMA_Cmd(LM75_DMA_TX_CHANNEL, ENABLE);
+
+ /* Wait until DMA Transfer Complete */
+ LM75_Timeout = LM75_LONG_TIMEOUT;
+ while (!DMA_GetFlagStatus(LM75_DMA_TX_TCFLAG))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Wait until BTF Flag is set before generating STOP */
+ LM75_Timeout = LM75_LONG_TIMEOUT;
+ while ((!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BTF)))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Send STOP Condition */
+ I2C_GenerateSTOP(LM75_I2C, ENABLE);
+
+ /* Disable DMA TX Channel */
+ DMA_Cmd(LM75_DMA_TX_CHANNEL, DISABLE);
+
+ /* Disable I2C DMA request */
+ I2C_DMACmd(LM75_I2C,DISABLE);
+
+ /* Clear DMA TX Transfer Complete Flag */
+ DMA_ClearFlag(LM75_DMA_TX_TCFLAG);
+
+ return LM75_OK;
+
+}
+
+/**
+ * @brief Enables or disables the LM75.
+ * @param NewState: specifies the LM75 new status. This parameter can be ENABLE
+ * or DISABLE.
+ * @retval None
+ */
+uint8_t LM75_ShutDown(FunctionalState NewState)
+{
+ uint8_t LM75_BufferRX[2] ={0,0};
+ uint8_t LM75_BufferTX = 0;
+ __IO uint8_t RegValue = 0;
+
+ /* Test on BUSY Flag */
+ LM75_Timeout = LM75_LONG_TIMEOUT;
+ while (I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BUSY))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Configure DMA Peripheral */
+ LM75_DMA_Config(LM75_DMA_RX, (uint8_t*)LM75_BufferRX, 2);
+
+ /* Enable DMA NACK automatic generation */
+ I2C_DMALastTransferCmd(LM75_I2C, ENABLE);
+
+ /* Enable the I2C peripheral */
+ I2C_GenerateSTART(LM75_I2C, ENABLE);
+
+ /* Test on SB Flag */
+ LM75_Timeout = LM75_FLAG_TIMEOUT;
+ while (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_SB))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Send device address for write */
+ I2C_Send7bitAddress(LM75_I2C, LM75_ADDR, I2C_Direction_Transmitter);
+
+ /* Test on ADDR Flag */
+ LM75_Timeout = LM75_FLAG_TIMEOUT;
+ while (!I2C_CheckEvent(LM75_I2C, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Send the device's internal address to write to */
+ I2C_SendData(LM75_I2C, LM75_REG_CONF);
+
+ /* Test on TXE FLag (data sent) */
+ LM75_Timeout = LM75_FLAG_TIMEOUT;
+ while ((!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_TXE)) && (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BTF)))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Send START condition a second time */
+ I2C_GenerateSTART(LM75_I2C, ENABLE);
+
+ /* Test on SB Flag */
+ LM75_Timeout = LM75_FLAG_TIMEOUT;
+ while (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_SB))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Send LM75 address for read */
+ I2C_Send7bitAddress(LM75_I2C, LM75_ADDR, I2C_Direction_Receiver);
+
+ /* Test on ADDR Flag */
+ LM75_Timeout = LM75_FLAG_TIMEOUT;
+ while (!I2C_CheckEvent(LM75_I2C, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Enable I2C DMA request */
+ I2C_DMACmd(LM75_I2C,ENABLE);
+
+ /* Enable DMA RX Channel */
+ DMA_Cmd(LM75_DMA_RX_CHANNEL, ENABLE);
+
+ /* Wait until DMA Transfer Complete */
+ LM75_Timeout = LM75_LONG_TIMEOUT;
+ while (!DMA_GetFlagStatus(LM75_DMA_RX_TCFLAG))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Send STOP Condition */
+ I2C_GenerateSTOP(LM75_I2C, ENABLE);
+
+ /* Disable DMA RX Channel */
+ DMA_Cmd(LM75_DMA_RX_CHANNEL, DISABLE);
+
+ /* Disable I2C DMA request */
+ I2C_DMACmd(LM75_I2C,DISABLE);
+
+ /* Clear DMA RX Transfer Complete Flag */
+ DMA_ClearFlag(LM75_DMA_RX_TCFLAG);
+
+ /*!< Get received data */
+ RegValue = (uint8_t)LM75_BufferRX[0];
+
+ /*---------------------------- Transmission Phase ---------------------------*/
+
+ /*!< Enable or disable SD bit */
+ if (NewState != DISABLE)
+ {
+ /*!< Enable LM75 */
+ LM75_BufferTX = RegValue & LM75_SD_RESET;
+ }
+ else
+ {
+ /*!< Disable LM75 */
+ LM75_BufferTX = RegValue | LM75_SD_SET;
+ }
+
+ /* Test on BUSY Flag */
+ LM75_Timeout = LM75_LONG_TIMEOUT;
+ while (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BUSY))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Configure DMA Peripheral */
+ LM75_DMA_Config(LM75_DMA_TX, (uint8_t*)(&LM75_BufferTX), 1);
+
+ /* Enable the I2C peripheral */
+ I2C_GenerateSTART(LM75_I2C, ENABLE);
+
+ /* Test on SB Flag */
+ LM75_Timeout = LM75_FLAG_TIMEOUT;
+ while (I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_SB) == RESET)
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Transmit the slave address and enable writing operation */
+ I2C_Send7bitAddress(LM75_I2C, LM75_ADDR, I2C_Direction_Transmitter);
+
+ /* Test on ADDR Flag */
+ LM75_Timeout = LM75_FLAG_TIMEOUT;
+ while (!I2C_CheckEvent(LM75_I2C, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Transmit the first address for r/w operations */
+ I2C_SendData(LM75_I2C, LM75_REG_CONF);
+
+ /* Test on TXE FLag (data sent) */
+ LM75_Timeout = LM75_FLAG_TIMEOUT;
+ while ((!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_TXE)) && (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BTF)))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Enable I2C DMA request */
+ I2C_DMACmd(LM75_I2C,ENABLE);
+
+ /* Enable DMA TX Channel */
+ DMA_Cmd(LM75_DMA_TX_CHANNEL, ENABLE);
+
+ /* Wait until DMA Transfer Complete */
+ LM75_Timeout = LM75_LONG_TIMEOUT;
+ while (!DMA_GetFlagStatus(LM75_DMA_TX_TCFLAG))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Wait until BTF Flag is set before generating STOP */
+ LM75_Timeout = LM75_LONG_TIMEOUT;
+ while ((!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BTF)))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Send STOP Condition */
+ I2C_GenerateSTOP(LM75_I2C, ENABLE);
+
+ /* Disable DMA TX Channel */
+ DMA_Cmd(LM75_DMA_TX_CHANNEL, DISABLE);
+
+ /* Disable I2C DMA request */
+ I2C_DMACmd(LM75_I2C,DISABLE);
+
+ /* Clear DMA TX Transfer Complete Flag */
+ DMA_ClearFlag(LM75_DMA_TX_TCFLAG);
+
+ return LM75_OK;
+}
+
+/**
+ * @}
+ */
+
+
+/**
+ * @}
+ */
+
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210B_EVAL/stm3210b_eval_i2c_tsensor.h b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210B_EVAL/stm3210b_eval_i2c_tsensor.h
new file mode 100644
index 0000000..5f76937
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210B_EVAL/stm3210b_eval_i2c_tsensor.h
@@ -0,0 +1,179 @@
+/**
+ ******************************************************************************
+ * @file stm3210b_eval_i2c_tsensor.h
+ * @author MCD Application Team
+ * @version V5.0.1
+ * @date 05-March-2012
+ * @brief This file contains all the functions prototypes for the
+ * stm3210b_eval_i2c_tsensor firmware driver.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.st.com/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __STM3210B_EVAL_I2C_TSENSOR_H
+#define __STM3210B_EVAL_I2C_TSENSOR_H
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+/* Includes ------------------------------------------------------------------*/
+#include "stm3210b_eval.h"
+
+/** @addtogroup Utilities
+ * @{
+ */
+
+/** @addtogroup STM32_EVAL
+ * @{
+ */
+
+/** @addtogroup STM3210B_EVAL
+ * @{
+ */
+
+/** @addtogroup STM3210B_EVAL_I2C_TSENSOR
+ * @{
+ */
+
+/** @defgroup STM3210B_EVAL_I2C_TSENSOR_Exported_Types
+ * @{
+ */
+
+ /**
+ * @brief IOE DMA Direction
+ */
+typedef enum
+{
+ LM75_DMA_TX = 0,
+ LM75_DMA_RX = 1
+}LM75_DMADirection_TypeDef;
+
+/**
+ * @brief TSENSOR Status
+ */
+typedef enum
+{
+ LM75_OK = 0,
+ LM75_FAIL
+}LM75_Status_TypDef;
+
+/**
+ * @}
+ */
+
+/** @defgroup STM3210B_EVAL_I2C_TSENSOR_Exported_Constants
+ * @{
+ */
+
+/* Uncomment the following line to use Timeout_User_Callback LM75_TimeoutUserCallback().
+ If This Callback is enabled, it should be implemented by user in main function .
+ LM75_TimeoutUserCallback() function is called whenever a timeout condition
+ occure during communication (waiting on an event that doesn't occur, bus
+ errors, busy devices ...). */
+/* #define USE_TIMEOUT_USER_CALLBACK */
+
+/* Maximum Timeout values for flags and events waiting loops. These timeouts are
+ not based on accurate values, they just guarantee that the application will
+ not remain stuck if the I2C communication is corrupted.
+ You may modify these timeout values depending on CPU frequency and application
+ conditions (interrupts routines ...). */
+#define LM75_FLAG_TIMEOUT ((uint32_t)0x1000)
+#define LM75_LONG_TIMEOUT ((uint32_t)(10 * LM75_FLAG_TIMEOUT))
+
+
+/**
+ * @brief Block Size
+ */
+#define LM75_REG_TEMP 0x00 /*!< Temperature Register of LM75 */
+#define LM75_REG_CONF 0x01 /*!< Configuration Register of LM75 */
+#define LM75_REG_THYS 0x02 /*!< Temperature Register of LM75 */
+#define LM75_REG_TOS 0x03 /*!< Over-temp Shutdown threshold Register of LM75 */
+#define I2C_TIMEOUT ((uint32_t)0x3FFFF) /*!< I2C Time out */
+#define LM75_ADDR 0x90 /*!< LM75 address */
+#define LM75_I2C_SPEED 100000 /*!< I2C Speed */
+
+
+
+/**
+ * @}
+ */
+
+/** @defgroup STM3210B_EVAL_I2C_TSENSOR_Exported_Macros
+ * @{
+ */
+/**
+ * @}
+ */
+
+/** @defgroup STM3210B_EVAL_I2C_TSENSOR_Exported_Functions
+ * @{
+ */
+void LM75_DeInit(void);
+void LM75_Init(void);
+ErrorStatus LM75_GetStatus(void);
+uint16_t LM75_ReadTemp(void);
+uint16_t LM75_ReadReg(uint8_t RegName);
+uint8_t LM75_WriteReg(uint8_t RegName, uint16_t RegValue);
+uint8_t LM75_ReadConfReg(void);
+uint8_t LM75_WriteConfReg(uint8_t RegValue);
+uint8_t LM75_ShutDown(FunctionalState NewState);
+
+/**
+ * @brief Timeout user callback function. This function is called when a timeout
+ * condition occurs during communication with IO Expander. Only protoype
+ * of this function is decalred in IO Expander driver. Its implementation
+ * may be done into user application. This function may typically stop
+ * current operations and reset the I2C peripheral and IO Expander.
+ * To enable this function use uncomment the define USE_TIMEOUT_USER_CALLBACK
+ * at the top of this file.
+ */
+#ifdef USE_TIMEOUT_USER_CALLBACK
+ uint8_t LM75_TIMEOUT_UserCallback(void);
+#else
+ #define LM75_TIMEOUT_UserCallback() LM75_FAIL
+#endif /* USE_TIMEOUT_USER_CALLBACK */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __STM3210B_EVAL_I2C_TSENSOR_H */
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210B_EVAL/stm3210b_eval_lcd.c b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210B_EVAL/stm3210b_eval_lcd.c
new file mode 100644
index 0000000..b30f9ef
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210B_EVAL/stm3210b_eval_lcd.c
@@ -0,0 +1,1884 @@
+/**
+ ******************************************************************************
+ * @file stm3210b_eval_lcd.c
+ * @author MCD Application Team
+ * @version V5.0.1
+ * @date 05-March-2012
+ * @brief This file includes the LCD driver for AM-240320LTNQW00H (LCD_HX8312),
+ * AM-240320L8TNQW00H (LCD_ILI9320), AM-240320LDTNQW00H (LCD_SPFD5408B)
+ * Liquid Crystal Display Module of STM3210B-EVAL board.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.st.com/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+
+/* Includes ------------------------------------------------------------------*/
+#include "stm3210b_eval_lcd.h"
+#include "../Common/fonts.c"
+
+/** @addtogroup Utilities
+ * @{
+ */
+
+/** @addtogroup STM32_EVAL
+ * @{
+ */
+
+/** @addtogroup STM3210B_EVAL
+ * @{
+ */
+
+/** @defgroup STM3210B_EVAL_LCD
+ * @briefThis file includes the LCD driver for AM-240320LTNQW00H (LCD_HX8312),
+ * AM-240320L8TNQW00H (LCD_ILI9320), AM-240320LDTNQW00H (LCD_SPFD5408B)
+ * Liquid Crystal Display Module of STM3210B-EVAL board.
+ * @{
+ */
+
+/** @defgroup STM3210B_EVAL_LCD_Private_Types
+ * @{
+ */
+/**
+ * @}
+ */
+
+
+/** @defgroup STM3210B_EVAL_LCD_Private_Defines
+ * @{
+ */
+#define LCD_ILI9320 0x9320
+#define LCD_HX8312 0x8312
+#define LCD_SPFD5408 0x5408
+#define START_BYTE 0x70
+#define SET_INDEX 0x00
+#define READ_STATUS 0x01
+#define LCD_WRITE_REG 0x02
+#define LCD_READ_REG 0x03
+#define MAX_POLY_CORNERS 200
+#define POLY_Y(Z) ((int32_t)((Points + Z)->X))
+#define POLY_X(Z) ((int32_t)((Points + Z)->Y))
+/**
+ * @}
+ */
+
+
+/** @defgroup STM3210B_EVAL_LCD_Private_Macros
+ * @{
+ */
+#define ABS(X) ((X) > 0 ? (X) : -(X))
+/**
+ * @}
+ */
+
+
+/** @defgroup STM3210B_EVAL_LCD_Private_Variables
+ * @{
+ */
+static sFONT *LCD_Currentfonts;
+/* Global variables to set the written text color */
+__IO uint16_t TextColor = 0x0000, BackColor = 0xFFFF;
+static __IO uint32_t LCDType = LCD_ILI9320;
+/**
+ * @}
+ */
+
+
+/** @defgroup STM3210B_EVAL_LCD_Private_Function_Prototypes
+ * @{
+ */
+#ifndef USE_Delay
+static void delay(vu32 nCount);
+#endif /* USE_Delay*/
+
+static void LCD_WriteRegHX8312(uint8_t LCD_Reg, uint8_t LCD_RegValue);
+static void LCD_WriteRegILI9320(uint8_t LCD_Reg, uint16_t LCD_RegValue);
+static void PutPixel(int16_t x, int16_t y);
+static void LCD_PolyLineRelativeClosed(pPoint Points, uint16_t PointCount, uint16_t Closed);
+/**
+ * @}
+ */
+
+
+/** @defgroup STM3210B_EVAL_LCD_Private_Functions
+ * @{
+ */
+
+/**
+ * @brief DeInitializes the LCD.
+ * @param None
+ * @retval None
+ */
+void LCD_DeInit(void)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+
+ /*!< LCD Display Off */
+ LCD_DisplayOff();
+
+ /*!< LCD_SPI disable */
+ SPI_Cmd(LCD_SPI, DISABLE);
+
+ /*!< LCD_SPI DeInit */
+ SPI_I2S_DeInit(LCD_SPI);
+
+ /*!< Disable SPI clock */
+ RCC_APB1PeriphClockCmd(LCD_SPI_CLK, DISABLE);
+
+ /* Configure NCS in Output Push-Pull mode */
+ GPIO_InitStructure.GPIO_Pin = LCD_NCS_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
+ GPIO_Init(LCD_NCS_GPIO_PORT, &GPIO_InitStructure);
+
+ /* Configure NWR(RNW), RS in Output Push-Pull mode */
+ GPIO_InitStructure.GPIO_Pin = LCD_RS_PIN;
+ GPIO_Init(LCD_RS_GPIO_PORT, &GPIO_InitStructure);
+
+ GPIO_InitStructure.GPIO_Pin = LCD_NWR_PIN;
+ GPIO_Init(LCD_NWR_GPIO_PORT, &GPIO_InitStructure);
+
+ /* Configure SPI pins: SCK, MISO and MOSI */
+ GPIO_InitStructure.GPIO_Pin = LCD_SPI_SCK_PIN;
+ GPIO_Init(LCD_SPI_SCK_GPIO_PORT, &GPIO_InitStructure);
+
+ GPIO_InitStructure.GPIO_Pin = LCD_SPI_MISO_PIN;
+ GPIO_Init(LCD_SPI_MISO_GPIO_PORT, &GPIO_InitStructure);
+
+ GPIO_InitStructure.GPIO_Pin = LCD_SPI_MOSI_PIN;
+ GPIO_Init(LCD_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure);
+}
+
+/**
+ * @brief Setups the LCD.
+ * @param None
+ * @retval None
+ */
+void LCD_Setup(void)
+{
+/* Configure the LCD Control pins --------------------------------------------*/
+ LCD_CtrlLinesConfig();
+
+/* Configure the LCD_SPI interface ----------------------------------------------*/
+ LCD_SPIConfig();
+ if(LCDType == LCD_ILI9320)
+ {
+ _delay_(5); /* Delay 50 ms */
+ /* Start Initial Sequence ------------------------------------------------*/
+ LCD_WriteReg(LCD_REG_229, 0x8000); /* Set the internal vcore voltage */
+ LCD_WriteReg(LCD_REG_0, 0x0001); /* Start internal OSC. */
+ LCD_WriteReg(LCD_REG_1, 0x0100); /* set SS and SM bit */
+ LCD_WriteReg(LCD_REG_2, 0x0700); /* set 1 line inversion */
+ LCD_WriteReg(LCD_REG_3, 0x1030); /* set GRAM write direction and BGR=1. */
+ LCD_WriteReg(LCD_REG_4, 0x0000); /* Resize register */
+ LCD_WriteReg(LCD_REG_8, 0x0202); /* set the back porch and front porch */
+ LCD_WriteReg(LCD_REG_9, 0x0000); /* set non-display area refresh cycle ISC[3:0] */
+ LCD_WriteReg(LCD_REG_10, 0x0000); /* FMARK function */
+ LCD_WriteReg(LCD_REG_12, 0x0000); /* RGB interface setting */
+ LCD_WriteReg(LCD_REG_13, 0x0000); /* Frame marker Position */
+ LCD_WriteReg(LCD_REG_15, 0x0000); /* RGB interface polarity */
+ /* Power On sequence -----------------------------------------------------*/
+ LCD_WriteReg(LCD_REG_16, 0x0000); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
+ LCD_WriteReg(LCD_REG_17, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */
+ LCD_WriteReg(LCD_REG_18, 0x0000); /* VREG1OUT voltage */
+ LCD_WriteReg(LCD_REG_19, 0x0000); /* VDV[4:0] for VCOM amplitude */
+ _delay_(20); /* Dis-charge capacitor power voltage (200ms) */
+ LCD_WriteReg(LCD_REG_16, 0x17B0); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
+ LCD_WriteReg(LCD_REG_17, 0x0137); /* DC1[2:0], DC0[2:0], VC[2:0] */
+ _delay_(5); /* Delay 50 ms */
+ LCD_WriteReg(LCD_REG_18, 0x0139); /* VREG1OUT voltage */
+ _delay_(5); /* Delay 50 ms */
+ LCD_WriteReg(LCD_REG_19, 0x1d00); /* VDV[4:0] for VCOM amplitude */
+ LCD_WriteReg(LCD_REG_41, 0x0013); /* VCM[4:0] for VCOMH */
+ _delay_(5); /* Delay 50 ms */
+ LCD_WriteReg(LCD_REG_32, 0x0000); /* GRAM horizontal Address */
+ LCD_WriteReg(LCD_REG_33, 0x0000); /* GRAM Vertical Address */
+ /* Adjust the Gamma Curve ------------------------------------------------*/
+ LCD_WriteReg(LCD_REG_48, 0x0006);
+ LCD_WriteReg(LCD_REG_49, 0x0101);
+ LCD_WriteReg(LCD_REG_50, 0x0003);
+ LCD_WriteReg(LCD_REG_53, 0x0106);
+ LCD_WriteReg(LCD_REG_54, 0x0b02);
+ LCD_WriteReg(LCD_REG_55, 0x0302);
+ LCD_WriteReg(LCD_REG_56, 0x0707);
+ LCD_WriteReg(LCD_REG_57, 0x0007);
+ LCD_WriteReg(LCD_REG_60, 0x0600);
+ LCD_WriteReg(LCD_REG_61, 0x020b);
+
+ /* Set GRAM area ---------------------------------------------------------*/
+ LCD_WriteReg(LCD_REG_80, 0x0000); /* Horizontal GRAM Start Address */
+ LCD_WriteReg(LCD_REG_81, 0x00EF); /* Horizontal GRAM End Address */
+ LCD_WriteReg(LCD_REG_82, 0x0000); /* Vertical GRAM Start Address */
+ LCD_WriteReg(LCD_REG_83, 0x013F); /* Vertical GRAM End Address */
+ LCD_WriteReg(LCD_REG_96, 0x2700); /* Gate Scan Line */
+ LCD_WriteReg(LCD_REG_97, 0x0001); /* NDL,VLE, REV */
+ LCD_WriteReg(LCD_REG_106, 0x0000); /* set scrolling line */
+ /* Partial Display Control -----------------------------------------------*/
+ LCD_WriteReg(LCD_REG_128, 0x0000);
+ LCD_WriteReg(LCD_REG_129, 0x0000);
+ LCD_WriteReg(LCD_REG_130, 0x0000);
+ LCD_WriteReg(LCD_REG_131, 0x0000);
+ LCD_WriteReg(LCD_REG_132, 0x0000);
+ LCD_WriteReg(LCD_REG_133, 0x0000);
+ /* Panel Control ---------------------------------------------------------*/
+ LCD_WriteReg(LCD_REG_144, 0x0010);
+ LCD_WriteReg(LCD_REG_146, 0x0000);
+ LCD_WriteReg(LCD_REG_147, 0x0003);
+ LCD_WriteReg(LCD_REG_149, 0x0110);
+ LCD_WriteReg(LCD_REG_151, 0x0000);
+ LCD_WriteReg(LCD_REG_152, 0x0000);
+ /* Set GRAM write direction and BGR = 1 */
+ /* I/D=01 (Horizontal : increment, Vertical : decrement) */
+ /* AM=1 (address is updated in vertical writing direction) */
+ LCD_WriteReg(LCD_REG_3, 0x1018);
+ LCD_WriteReg(LCD_REG_7, 0x0173); /* 262K color and display ON */
+ }
+ else if(LCDType == LCD_SPFD5408)
+ {
+ /* Start Initial Sequence --------------------------------------------------*/
+ LCD_WriteReg(LCD_REG_227, 0x3008); /* Set internal timing */
+ LCD_WriteReg(LCD_REG_231, 0x0012); /* Set internal timing */
+ LCD_WriteReg(LCD_REG_239, 0x1231); /* Set internal timing */
+ LCD_WriteReg(LCD_REG_1, 0x0100); /* Set SS and SM bit */
+ LCD_WriteReg(LCD_REG_2, 0x0700); /* Set 1 line inversion */
+ LCD_WriteReg(LCD_REG_3, 0x1030); /* Set GRAM write direction and BGR=1. */
+ LCD_WriteReg(LCD_REG_4, 0x0000); /* Resize register */
+ LCD_WriteReg(LCD_REG_8, 0x0202); /* Set the back porch and front porch */
+ LCD_WriteReg(LCD_REG_9, 0x0000); /* Set non-display area refresh cycle ISC[3:0] */
+ LCD_WriteReg(LCD_REG_10, 0x0000); /* FMARK function */
+ LCD_WriteReg(LCD_REG_12, 0x0000); /* RGB interface setting */
+ LCD_WriteReg(LCD_REG_13, 0x0000); /* Frame marker Position */
+ LCD_WriteReg(LCD_REG_15, 0x0000); /* RGB interface polarity */
+ /* Power On sequence -------------------------------------------------------*/
+ LCD_WriteReg(LCD_REG_16, 0x0000); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
+ LCD_WriteReg(LCD_REG_17, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */
+ LCD_WriteReg(LCD_REG_18, 0x0000); /* VREG1OUT voltage */
+ LCD_WriteReg(LCD_REG_19, 0x0000); /* VDV[4:0] for VCOM amplitude */
+ _delay_(20); /* Dis-charge capacitor power voltage (200ms) */
+ LCD_WriteReg(LCD_REG_17, 0x0007); /* DC1[2:0], DC0[2:0], VC[2:0] */
+ _delay_(5); /* Delay 50 ms */
+ LCD_WriteReg(LCD_REG_16, 0x12B0); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
+ _delay_(5); /* Delay 50 ms */
+ LCD_WriteReg(LCD_REG_18, 0x01BD); /* External reference voltage= Vci */
+ _delay_(5); /* Delay 50 ms */
+ LCD_WriteReg(LCD_REG_19, 0x1400); /* VDV[4:0] for VCOM amplitude */
+ LCD_WriteReg(LCD_REG_41, 0x000E); /* VCM[4:0] for VCOMH */
+ _delay_(5); /* Delay 50 ms */
+ LCD_WriteReg(LCD_REG_32, 0x0000); /* GRAM horizontal Address */
+ LCD_WriteReg(LCD_REG_33, 0x013F); /* GRAM Vertical Address */
+ /* Adjust the Gamma Curve --------------------------------------------------*/
+ LCD_WriteReg(LCD_REG_48, 0x0007);
+ LCD_WriteReg(LCD_REG_49, 0x0302);
+ LCD_WriteReg(LCD_REG_50, 0x0105);
+ LCD_WriteReg(LCD_REG_53, 0x0206);
+ LCD_WriteReg(LCD_REG_54, 0x0808);
+ LCD_WriteReg(LCD_REG_55, 0x0206);
+ LCD_WriteReg(LCD_REG_56, 0x0504);
+ LCD_WriteReg(LCD_REG_57, 0x0007);
+ LCD_WriteReg(LCD_REG_60, 0x0105);
+ LCD_WriteReg(LCD_REG_61, 0x0808);
+ /* Set GRAM area -----------------------------------------------------------*/
+ LCD_WriteReg(LCD_REG_80, 0x0000); /* Horizontal GRAM Start Address */
+ LCD_WriteReg(LCD_REG_81, 0x00EF); /* Horizontal GRAM End Address */
+ LCD_WriteReg(LCD_REG_82, 0x0000); /* Vertical GRAM Start Address */
+ LCD_WriteReg(LCD_REG_83, 0x013F); /* Vertical GRAM End Address */
+ LCD_WriteReg(LCD_REG_96, 0xA700); /* Gate Scan Line */
+ LCD_WriteReg(LCD_REG_97, 0x0001); /* NDL,VLE, REV */
+ LCD_WriteReg(LCD_REG_106, 0x0000); /* Set scrolling line */
+ /* Partial Display Control -------------------------------------------------*/
+ LCD_WriteReg(LCD_REG_128, 0x0000);
+ LCD_WriteReg(LCD_REG_129, 0x0000);
+ LCD_WriteReg(LCD_REG_130, 0x0000);
+ LCD_WriteReg(LCD_REG_131, 0x0000);
+ LCD_WriteReg(LCD_REG_132, 0x0000);
+ LCD_WriteReg(LCD_REG_133, 0x0000);
+ /* Panel Control -----------------------------------------------------------*/
+ LCD_WriteReg(LCD_REG_144, 0x0010);
+ LCD_WriteReg(LCD_REG_146, 0x0000);
+ LCD_WriteReg(LCD_REG_147, 0x0003);
+ LCD_WriteReg(LCD_REG_149, 0x0110);
+ LCD_WriteReg(LCD_REG_151, 0x0000);
+ LCD_WriteReg(LCD_REG_152, 0x0000);
+ /* Set GRAM write direction and BGR = 1
+ I/D=01 (Horizontal : increment, Vertical : decrement)
+ AM=1 (address is updated in vertical writing direction) */
+ LCD_WriteReg(LCD_REG_3, 0x1018);
+ LCD_WriteReg(LCD_REG_7, 0x0112); /* 262K color and display ON */
+ }
+ else if(LCDType == LCD_HX8312)
+ {
+ /* Enable the LCD Oscillator ---------------------------------------------*/
+ LCD_WriteReg(LCD_REG_1, 0x10);
+ LCD_WriteReg(LCD_REG_0, 0xA0);
+ LCD_WriteReg(LCD_REG_3, 0x01);
+ _delay_(1); /* Delay 10 ms */
+ LCD_WriteReg(LCD_REG_3, 0x00);
+ LCD_WriteReg(LCD_REG_43, 0x04);
+
+ LCD_WriteReg(LCD_REG_40, 0x18);
+ LCD_WriteReg(LCD_REG_26, 0x05);
+ LCD_WriteReg(LCD_REG_37, 0x05);
+ LCD_WriteReg(LCD_REG_25, 0x00);
+
+ /* LCD Power On ----------------------------------------------------------*/
+ LCD_WriteReg(LCD_REG_28, 0x73);
+ LCD_WriteReg(LCD_REG_36, 0x74);
+ LCD_WriteReg(LCD_REG_30, 0x01);
+ LCD_WriteReg(LCD_REG_24, 0xC1);
+ _delay_(1); /* Delay 10 ms */
+ LCD_WriteReg(LCD_REG_24, 0xE1);
+ LCD_WriteReg(LCD_REG_24, 0xF1);
+ _delay_(6); /* Delay 60 ms */
+ LCD_WriteReg(LCD_REG_24, 0xF5);
+ _delay_(6); /* Delay 60 ms */
+ LCD_WriteReg(LCD_REG_27, 0x09);
+ _delay_(1); /* Delay 10 ms */
+ LCD_WriteReg(LCD_REG_31, 0x11);
+ LCD_WriteReg(LCD_REG_32, 0x0E);
+ LCD_WriteReg(LCD_REG_30, 0x81);
+ _delay_(1); /* Delay 10 ms */
+
+ /* Chip Set --------------------------------------------------------------*/
+ LCD_WriteReg(LCD_REG_157, 0x00);
+ LCD_WriteReg(LCD_REG_192, 0x00);
+
+ LCD_WriteReg(LCD_REG_14, 0x00);
+ LCD_WriteReg(LCD_REG_15, 0x00);
+ LCD_WriteReg(LCD_REG_16, 0x00);
+ LCD_WriteReg(LCD_REG_17, 0x00);
+ LCD_WriteReg(LCD_REG_18, 0x00);
+ LCD_WriteReg(LCD_REG_19, 0x00);
+ LCD_WriteReg(LCD_REG_20, 0x00);
+ LCD_WriteReg(LCD_REG_21, 0x00);
+ LCD_WriteReg(LCD_REG_22, 0x00);
+ LCD_WriteReg(LCD_REG_23, 0x00);
+
+ LCD_WriteReg(LCD_REG_52, 0x01);
+ LCD_WriteReg(LCD_REG_53, 0x00);
+ LCD_WriteReg(LCD_REG_75, 0x00);
+ LCD_WriteReg(LCD_REG_76, 0x00);
+ LCD_WriteReg(LCD_REG_78, 0x00);
+ LCD_WriteReg(LCD_REG_79, 0x00);
+ LCD_WriteReg(LCD_REG_80, 0x00);
+
+ LCD_WriteReg(LCD_REG_60, 0x00);
+ LCD_WriteReg(LCD_REG_61, 0x00);
+ LCD_WriteReg(LCD_REG_62, 0x01);
+ LCD_WriteReg(LCD_REG_63, 0x3F);
+ LCD_WriteReg(LCD_REG_64, 0x02);
+ LCD_WriteReg(LCD_REG_65, 0x02);
+ LCD_WriteReg(LCD_REG_66, 0x00);
+ LCD_WriteReg(LCD_REG_67, 0x00);
+ LCD_WriteReg(LCD_REG_68, 0x00);
+ LCD_WriteReg(LCD_REG_69, 0x00);
+ LCD_WriteReg(LCD_REG_70, 0xEF);
+ LCD_WriteReg(LCD_REG_71, 0x00);
+ LCD_WriteReg(LCD_REG_72, 0x00);
+ LCD_WriteReg(LCD_REG_73, 0x01);
+ LCD_WriteReg(LCD_REG_74, 0x3F);
+
+ LCD_WriteReg(LCD_REG_29, 0x08); /* R29:Gate scan direction setting */
+
+ LCD_WriteReg(LCD_REG_134, 0x00);
+ LCD_WriteReg(LCD_REG_135, 0x30);
+ LCD_WriteReg(LCD_REG_136, 0x02);
+ LCD_WriteReg(LCD_REG_137, 0x05);
+
+ LCD_WriteReg(LCD_REG_141, 0x01); /* R141:Register set-up mode for one line clock */
+ LCD_WriteReg(LCD_REG_139, 0x20); /* R139:One line SYSCLK number in one-line */
+ LCD_WriteReg(LCD_REG_51, 0x01); /* R51:N line inversion setting */
+ LCD_WriteReg(LCD_REG_55, 0x01); /* R55:Scanning method setting */
+ LCD_WriteReg(LCD_REG_118, 0x00);
+
+ /* Gamma Set -------------------------------------------------------------*/
+ LCD_WriteReg(LCD_REG_143, 0x10);
+ LCD_WriteReg(LCD_REG_144, 0x67);
+ LCD_WriteReg(LCD_REG_145, 0x07);
+ LCD_WriteReg(LCD_REG_146, 0x65);
+ LCD_WriteReg(LCD_REG_147, 0x07);
+ LCD_WriteReg(LCD_REG_148, 0x01);
+ LCD_WriteReg(LCD_REG_149, 0x76);
+ LCD_WriteReg(LCD_REG_150, 0x56);
+ LCD_WriteReg(LCD_REG_151, 0x00);
+ LCD_WriteReg(LCD_REG_152, 0x06);
+ LCD_WriteReg(LCD_REG_153, 0x03);
+ LCD_WriteReg(LCD_REG_154, 0x00);
+
+ /* Display On ------------------------------------------------------------*/
+ LCD_WriteReg(LCD_REG_1, 0x50);
+ LCD_WriteReg(LCD_REG_5, 0x04);
+ LCD_WriteReg(LCD_REG_0, 0x80);
+ LCD_WriteReg(LCD_REG_59, 0x01);
+ _delay_(4); /* Delay 40 ms */
+ LCD_WriteReg(LCD_REG_0, 0x20);
+ }
+}
+
+
+/**
+ * @brief Initializes the LCD.
+ * @param None
+ * @retval None
+ */
+void STM3210B_LCD_Init(void)
+{
+ /* Setups the LCD */
+ LCD_Setup();
+ /* Try to read new LCD controller ID 0x9320 */
+ if (LCD_ReadReg(LCD_REG_0) == LCD_ILI9320)
+ {
+ LCDType = LCD_ILI9320;
+ }
+ else
+ {
+ LCDType = LCD_SPFD5408;
+ /* Setups the LCD */
+ LCD_Setup();
+ /* Try to read new LCD controller ID 0x5408 */
+ if (LCD_ReadReg(LCD_REG_0) != LCD_SPFD5408)
+ {
+ LCDType = LCD_HX8312;
+ /* Setups the LCD */
+ LCD_Setup();
+ }
+ }
+ LCD_SetFont(&LCD_DEFAULT_FONT);
+}
+
+/**
+ * @brief Sets the LCD Text and Background colors.
+ * @param _TextColor: specifies the Text Color.
+ * @param _BackColor: specifies the Background Color.
+ * @retval None
+ */
+void LCD_SetColors(__IO uint16_t _TextColor, __IO uint16_t _BackColor)
+{
+ TextColor = _TextColor;
+ BackColor = _BackColor;
+}
+
+/**
+ * @brief Gets the LCD Text and Background colors.
+ * @param _TextColor: pointer to the variable that will contain the Text
+ Color.
+ * @param _BackColor: pointer to the variable that will contain the Background
+ Color.
+ * @retval None
+ */
+void LCD_GetColors(__IO uint16_t *_TextColor, __IO uint16_t *_BackColor)
+{
+ *_TextColor = TextColor; *_BackColor = BackColor;
+}
+
+/**
+ * @brief Sets the Text color.
+ * @param Color: specifies the Text color code RGB(5-6-5).
+ * @retval None
+ */
+void LCD_SetTextColor(__IO uint16_t Color)
+{
+ TextColor = Color;
+}
+
+
+/**
+ * @brief Sets the Background color.
+ * @param Color: specifies the Background color code RGB(5-6-5).
+ * @retval None
+ */
+void LCD_SetBackColor(__IO uint16_t Color)
+{
+ BackColor = Color;
+}
+
+/**
+ * @brief Sets the Text Font.
+ * @param fonts: specifies the font to be used.
+ * @retval None
+ */
+void LCD_SetFont(sFONT *fonts)
+{
+ LCD_Currentfonts = fonts;
+}
+
+/**
+ * @brief Gets the Text Font.
+ * @param None.
+ * @retval the used font.
+ */
+sFONT *LCD_GetFont(void)
+{
+ return LCD_Currentfonts;
+}
+
+/**
+ * @brief Clears the selected line.
+ * @param Line: the Line to be cleared.
+ * This parameter can be one of the following values:
+ * @arg Linex: where x can be 0..n
+ * @retval None
+ */
+void LCD_ClearLine(uint8_t Line)
+{
+ uint16_t refcolumn = LCD_PIXEL_WIDTH - 1;
+ /* Send the string character by character on lCD */
+ while (((refcolumn + 1) & 0xFFFF) >= LCD_Currentfonts->Width)
+ {
+ /* Display one character on LCD */
+ LCD_DisplayChar(Line, refcolumn, ' ');
+ /* Decrement the column position by 16 */
+ refcolumn -= LCD_Currentfonts->Width;
+ }
+}
+
+
+/**
+ * @brief Clears the hole LCD.
+ * @param Color: the color of the background.
+ * @retval None
+ */
+void LCD_Clear(uint16_t Color)
+{
+ uint32_t index = 0;
+
+ LCD_SetCursor(0x00, 0x013F);
+ if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
+ {
+ LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
+ }
+ for(index = 0; index < 76800; index++)
+ {
+ LCD_WriteRAM(Color);
+ }
+ if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
+ {
+ LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_SET);
+ }
+}
+
+
+/**
+ * @brief Sets the cursor position.
+ * @param Xpos: specifies the X position.
+ * @param Ypos: specifies the Y position.
+ * @retval None
+ */
+void LCD_SetCursor(uint8_t Xpos, uint16_t Ypos)
+{
+ if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
+ {
+ LCD_WriteReg(LCD_REG_32, Xpos);
+ LCD_WriteReg(LCD_REG_33, Ypos);
+ }
+ else if(LCDType == LCD_HX8312)
+ {
+ LCD_WriteReg(LCD_REG_66, Xpos);
+ LCD_WriteReg(LCD_REG_67, ((Ypos & 0x100)>> 8));
+ LCD_WriteReg(LCD_REG_68, (Ypos & 0xFF));
+ }
+}
+
+
+/**
+ * @brief Draws a character on LCD.
+ * @param Xpos: the Line where to display the character shape.
+ * @param Ypos: start column address.
+ * @param c: pointer to the character data.
+ * @retval None
+ */
+void LCD_DrawChar(uint8_t Xpos, uint16_t Ypos, const uint16_t *c)
+{
+ uint32_t index = 0, i = 0;
+ uint8_t Xaddress = 0;
+
+ Xaddress = Xpos;
+
+ LCD_SetCursor(Xaddress, Ypos);
+
+ for(index = 0; index < LCD_Currentfonts->Height; index++)
+ {
+ if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
+ {
+ LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
+ }
+ for(i = 0; i < LCD_Currentfonts->Width; i++)
+ {
+ if((((c[index] & ((0x80 << ((LCD_Currentfonts->Width / 12 ) * 8 ) ) >> i)) == 0x00) &&(LCD_Currentfonts->Width <= 12))||
+ (((c[index] & (0x1 << i)) == 0x00)&&(LCD_Currentfonts->Width > 12 )))
+
+ {
+ LCD_WriteRAM(BackColor);
+ }
+ else
+ {
+ LCD_WriteRAM(TextColor);
+ }
+ }
+ if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
+ {
+ LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_SET);
+ }
+ Xaddress++;
+ LCD_SetCursor(Xaddress, Ypos);
+ }
+}
+
+
+/**
+ * @brief Displays one character (16dots width, 24dots height).
+ * @param Line: the Line where to display the character shape .
+ * This parameter can be one of the following values:
+ * @arg Linex: where x can be 0..9
+ * @param Column: start column address.
+ * @param Ascii: character ascii code, must be between 0x20 and 0x7E.
+ * @retval None
+ */
+void LCD_DisplayChar(uint8_t Line, uint16_t Column, uint8_t Ascii)
+{
+ Ascii -= 32;
+ LCD_DrawChar(Line, Column, &LCD_Currentfonts->table[Ascii * LCD_Currentfonts->Height]);
+}
+
+
+/**
+ * @brief Displays a maximum of 20 char on the LCD.
+ * @param Line: the Line where to display the character shape .
+ * This parameter can be one of the following values:
+ * @arg Linex: where x can be 0..9
+ * @param *ptr: pointer to string to display on LCD.
+ * @retval None
+ */
+void LCD_DisplayStringLine(uint8_t Line, uint8_t *ptr)
+{
+ uint16_t refcolumn = LCD_PIXEL_WIDTH - 1;
+
+ /* Send the string character by character on lCD */
+ while ((*ptr != 0) & (((refcolumn + 1) & 0xFFFF) >= LCD_Currentfonts->Width))
+ {
+ /* Display one character on LCD */
+ LCD_DisplayChar(Line, refcolumn, *ptr);
+ /* Decrement the column position by 16 */
+ refcolumn -= LCD_Currentfonts->Width;
+ /* Point on the next character */
+ ptr++;
+ }
+}
+
+
+/**
+ * @brief Sets a display window
+ * @param Xpos: specifies the X buttom left position.
+ * @param Ypos: specifies the Y buttom left position.
+ * @param Height: display window height.
+ * @param Width: display window width.
+ * @retval None
+ */
+void LCD_SetDisplayWindow(uint8_t Xpos, uint16_t Ypos, uint8_t Height, uint16_t Width)
+{
+ if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
+ {
+ /* Horizontal GRAM Start Address */
+ if(Xpos >= Height)
+ {
+ LCD_WriteReg(LCD_REG_80, (Xpos - Height + 1));
+ }
+ else
+ {
+ LCD_WriteReg(LCD_REG_80, 0);
+ }
+ /* Horizontal GRAM End Address */
+ LCD_WriteReg(LCD_REG_81, Xpos);
+ /* Vertical GRAM Start Address */
+ if(Ypos >= Width)
+ {
+ LCD_WriteReg(LCD_REG_82, (Ypos - Width + 1));
+ }
+ else
+ {
+ LCD_WriteReg(LCD_REG_82, 0);
+ }
+ /* Vertical GRAM End Address */
+ LCD_WriteReg(LCD_REG_83, Ypos);
+ }
+ else if(LCDType == LCD_HX8312)
+ {
+ LCD_WriteReg(LCD_REG_1, 0xD0);
+ LCD_WriteReg(LCD_REG_5, 0x14);
+
+ LCD_WriteReg(LCD_REG_69, (Xpos - Height + 1));
+ LCD_WriteReg(LCD_REG_70, Xpos);
+
+ LCD_WriteReg(LCD_REG_71, (((Ypos - Width + 1) & 0x100)>> 8));
+ LCD_WriteReg(LCD_REG_72, ((Ypos - Width + 1) & 0xFF));
+ LCD_WriteReg(LCD_REG_73, ((Ypos & 0x100)>> 8));
+ LCD_WriteReg(LCD_REG_74, (Ypos & 0xFF));
+ }
+ LCD_SetCursor(Xpos, Ypos);
+}
+
+
+/**
+ * @brief Disables LCD Window mode.
+ * @param None
+ * @retval None
+ */
+void LCD_WindowModeDisable(void)
+{
+ if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
+ {
+ LCD_SetDisplayWindow(239, 0x13F, 240, 320);
+ LCD_WriteReg(LCD_REG_3, 0x1018);
+ }
+ else if(LCDType == LCD_HX8312)
+ {
+ LCD_WriteReg(LCD_REG_1, 0x50);
+ LCD_WriteReg(LCD_REG_5, 0x04);
+ }
+
+}
+
+
+/**
+ * @brief Displays a line.
+ * @param Xpos: specifies the X position.
+ * @param Ypos: specifies the Y position.
+ * @param Length: line length.
+ * @param Direction: line direction.
+ * This parameter can be one of the following values: Vertical or Horizontal.
+ * @retval None
+ */
+void LCD_DrawLine(uint8_t Xpos, uint16_t Ypos, uint16_t Length, uint8_t Direction)
+{
+ uint32_t i = 0;
+
+ LCD_SetCursor(Xpos, Ypos);
+ if(Direction == LCD_DIR_HORIZONTAL)
+ {
+ if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
+ {
+ LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
+ }
+ for(i = 0; i < Length; i++)
+ {
+ LCD_WriteRAM(TextColor);
+ }
+ if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
+ {
+ LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_SET);
+ }
+ }
+ else
+ {
+ for(i = 0; i < Length; i++)
+ {
+ if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
+ {
+ LCD_WriteRAMWord(TextColor);
+ }
+ else if(LCDType == LCD_HX8312)
+ {
+ LCD_WriteRAM(TextColor);
+ }
+ Xpos++;
+ LCD_SetCursor(Xpos, Ypos);
+ }
+ }
+}
+
+
+/**
+ * @brief Displays a rectangle.
+ * @param Xpos: specifies the X position.
+ * @param Ypos: specifies the Y position.
+ * @param Height: display rectangle height.
+ * @param Width: display rectangle width.
+ * @retval None
+ */
+void LCD_DrawRect(uint8_t Xpos, uint16_t Ypos, uint8_t Height, uint16_t Width)
+{
+ LCD_DrawLine(Xpos, Ypos, Width, LCD_DIR_HORIZONTAL);
+ LCD_DrawLine((Xpos + Height), Ypos, Width, LCD_DIR_HORIZONTAL);
+
+ LCD_DrawLine(Xpos, Ypos, Height, LCD_DIR_VERTICAL);
+ LCD_DrawLine(Xpos, (Ypos - Width + 1), Height, LCD_DIR_VERTICAL);
+}
+
+
+/**
+ * @brief Displays a circle.
+ * @param Xpos: specifies the X position.
+ * @param Ypos: specifies the Y position.
+ * @param Radius
+ * @retval None
+ */
+void LCD_DrawCircle(uint8_t Xpos, uint16_t Ypos, uint16_t Radius)
+{
+ int32_t D;/* Decision Variable */
+ uint32_t CurX;/* Current X Value */
+ uint32_t CurY;/* Current Y Value */
+
+ D = 3 - (Radius << 1);
+ CurX = 0;
+ CurY = Radius;
+
+ while (CurX <= CurY)
+ {
+ LCD_SetCursor(Xpos + CurX, Ypos + CurY);
+ if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
+ {
+ LCD_WriteRAMWord(TextColor);
+ }
+ else if(LCDType == LCD_HX8312)
+ {
+ LCD_WriteRAM(TextColor);
+ }
+ LCD_SetCursor(Xpos + CurX, Ypos - CurY);
+
+ if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
+ {
+ LCD_WriteRAMWord(TextColor);
+ }
+ else if(LCDType == LCD_HX8312)
+ {
+ LCD_WriteRAM(TextColor);
+ }
+ LCD_SetCursor(Xpos - CurX, Ypos + CurY);
+
+ if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
+ {
+ LCD_WriteRAMWord(TextColor);
+ }
+ else if(LCDType == LCD_HX8312)
+ {
+ LCD_WriteRAM(TextColor);
+ }
+ LCD_SetCursor(Xpos - CurX, Ypos - CurY);
+
+ if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
+ {
+ LCD_WriteRAMWord(TextColor);
+ }
+ else if(LCDType == LCD_HX8312)
+ {
+ LCD_WriteRAM(TextColor);
+ }
+ LCD_SetCursor(Xpos + CurY, Ypos + CurX);
+ if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
+ {
+ LCD_WriteRAMWord(TextColor);
+ }
+ else if(LCDType == LCD_HX8312)
+ {
+ LCD_WriteRAM(TextColor);
+ }
+ LCD_SetCursor(Xpos + CurY, Ypos - CurX);
+
+ if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
+ {
+ LCD_WriteRAMWord(TextColor);
+ }
+ else if(LCDType == LCD_HX8312)
+ {
+ LCD_WriteRAM(TextColor);
+ }
+ LCD_SetCursor(Xpos - CurY, Ypos + CurX);
+
+ if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
+ {
+ LCD_WriteRAMWord(TextColor);
+ }
+ else if(LCDType == LCD_HX8312)
+ {
+ LCD_WriteRAM(TextColor);
+ }
+ LCD_SetCursor(Xpos - CurY, Ypos - CurX);
+
+ if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
+ {
+ LCD_WriteRAMWord(TextColor);
+ }
+ else if(LCDType == LCD_HX8312)
+ {
+ LCD_WriteRAM(TextColor);
+ }
+ if (D < 0)
+ {
+ D += (CurX << 2) + 6;
+ }
+ else
+ {
+ D += ((CurX - CurY) << 2) + 10;
+ CurY--;
+ }
+ CurX++;
+ }
+}
+
+
+/**
+ * @brief Displays a monocolor picture.
+ * @param Pict: pointer to the picture array.
+ * @retval None
+ */
+void LCD_DrawMonoPict(const uint32_t *Pict)
+{
+ uint32_t index = 0, i = 0;
+ LCD_SetCursor(0, (LCD_PIXEL_WIDTH - 1));
+
+ if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
+ {
+ LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
+ }
+
+ for(index = 0; index < 2400; index++)
+ {
+ for(i = 0; i < 32; i++)
+ {
+ if((Pict[index] & (1 << i)) == 0x00)
+ {
+ LCD_WriteRAM(BackColor);
+ }
+ else
+ {
+ LCD_WriteRAM(TextColor);
+ }
+ }
+ }
+
+ if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
+ {
+ LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_SET);
+ }
+}
+
+#ifdef USE_LCD_DrawBMP
+/**
+ * @brief Displays a bitmap picture loaded in the SPI Flash.
+ * @param BmpAddress: Bmp picture address in the SPI Flash.
+ * @retval None
+ */
+void LCD_DrawBMP(uint32_t BmpAddress)
+{
+ uint32_t i = 0, size = 0;
+ /* Read bitmap size */
+ sFLASH_ReadBuffer((uint8_t*)&size, BmpAddress + 2, 4);
+ /* get bitmap data address offset */
+ sFLASH_ReadBuffer((uint8_t*)&i, BmpAddress + 10, 4);
+
+ size = (size - i)/2;
+ sFLASH_StartReadSequence(BmpAddress + i);
+ /* Disable LCD_SPI */
+ SPI_Cmd(LCD_SPI, DISABLE);
+ /* SPI in 16-bit mode */
+ SPI_DataSizeConfig(LCD_SPI, SPI_DataSize_16b);
+ /* Enable LCD_SPI */
+ SPI_Cmd(LCD_SPI, ENABLE);
+
+ if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
+ {
+ /* Set GRAM write direction and BGR = 1 */
+ /* I/D=00 (Horizontal : decrement, Vertical : decrement) */
+ /* AM=1 (address is updated in vertical writing direction) */
+ LCD_WriteReg(LCD_REG_3, 0x1008);
+ LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
+ }
+
+ /* Read bitmap data from SPI Flash and send them to LCD */
+ for(i = 0; i < size; i++)
+ {
+ LCD_WriteRAM(__REV16(sFLASH_SendHalfWord(0xA5A5)));
+ }
+ if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
+ {
+ LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_SET);
+ }
+
+ /* Deselect the FLASH: Chip Select high */
+ sFLASH_CS_HIGH();
+ /* Disable LCD_SPI */
+ SPI_Cmd(LCD_SPI, DISABLE);
+ /* SPI in 8-bit mode */
+ SPI_DataSizeConfig(LCD_SPI, SPI_DataSize_8b);
+ /* Enable LCD_SPI */
+ SPI_Cmd(LCD_SPI, ENABLE);
+
+ if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
+ {
+ /* Set GRAM write direction and BGR = 1 */
+ /* I/D = 01 (Horizontal : increment, Vertical : decrement) */
+ /* AM = 1 (address is updated in vertical writing direction) */
+ LCD_WriteReg(LCD_REG_3, 0x1018);
+ }
+}
+#endif /* USE_LCD_DrawBMP */
+
+/**
+ * @brief Displays a full rectangle.
+ * @param Xpos: specifies the X position.
+ * @param Ypos: specifies the Y position.
+ * @param Height: rectangle height.
+ * @param Width: rectangle width.
+ * @retval None
+ */
+void LCD_DrawFullRect(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height)
+{
+ LCD_SetTextColor(TextColor);
+
+ LCD_DrawLine(Xpos, Ypos, Width, LCD_DIR_HORIZONTAL);
+ LCD_DrawLine((Xpos + Height), Ypos, Width, LCD_DIR_HORIZONTAL);
+
+ LCD_DrawLine(Xpos, Ypos, Height, LCD_DIR_VERTICAL);
+ LCD_DrawLine(Xpos, (Ypos - Width + 1), Height, LCD_DIR_VERTICAL);
+
+ Width -= 2;
+ Height--;
+ Ypos--;
+
+ LCD_SetTextColor(BackColor);
+
+ while(Height--)
+ {
+ LCD_DrawLine(++Xpos, Ypos, Width, LCD_DIR_HORIZONTAL);
+ }
+
+ LCD_SetTextColor(TextColor);
+}
+
+/**
+ * @brief Displays a full circle.
+ * @param Xpos: specifies the X position.
+ * @param Ypos: specifies the Y position.
+ * @param Radius
+ * @retval None
+ */
+void LCD_DrawFullCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius)
+{
+ int32_t D; /* Decision Variable */
+ uint32_t CurX;/* Current X Value */
+ uint32_t CurY;/* Current Y Value */
+
+ D = 3 - (Radius << 1);
+
+ CurX = 0;
+ CurY = Radius;
+
+ LCD_SetTextColor(BackColor);
+
+ while (CurX <= CurY)
+ {
+ if(CurY > 0)
+ {
+ LCD_DrawLine(Xpos - CurX, Ypos + CurY, 2*CurY, LCD_DIR_HORIZONTAL);
+ LCD_DrawLine(Xpos + CurX, Ypos + CurY, 2*CurY, LCD_DIR_HORIZONTAL);
+ }
+
+ if(CurX > 0)
+ {
+ LCD_DrawLine(Xpos - CurY, Ypos + CurX, 2*CurX, LCD_DIR_HORIZONTAL);
+ LCD_DrawLine(Xpos + CurY, Ypos + CurX, 2*CurX, LCD_DIR_HORIZONTAL);
+ }
+ if (D < 0)
+ {
+ D += (CurX << 2) + 6;
+ }
+ else
+ {
+ D += ((CurX - CurY) << 2) + 10;
+ CurY--;
+ }
+ CurX++;
+ }
+
+ LCD_SetTextColor(TextColor);
+ LCD_DrawCircle(Xpos, Ypos, Radius);
+}
+
+/**
+ * @brief Displays an uni line (between two points).
+ * @param x1: specifies the point 1 x position.
+ * @param y1: specifies the point 1 y position.
+ * @param x2: specifies the point 2 x position.
+ * @param y2: specifies the point 2 y position.
+ * @retval None
+ */
+void LCD_DrawUniLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2)
+{
+ int16_t deltax = 0, deltay = 0, x = 0, y = 0, xinc1 = 0, xinc2 = 0,
+ yinc1 = 0, yinc2 = 0, den = 0, num = 0, numadd = 0, numpixels = 0,
+ curpixel = 0;
+
+ deltax = ABS(x2 - x1); /* The difference between the x's */
+ deltay = ABS(y2 - y1); /* The difference between the y's */
+ x = x1; /* Start x off at the first pixel */
+ y = y1; /* Start y off at the first pixel */
+
+ if (x2 >= x1) /* The x-values are increasing */
+ {
+ xinc1 = 1;
+ xinc2 = 1;
+ }
+ else /* The x-values are decreasing */
+ {
+ xinc1 = -1;
+ xinc2 = -1;
+ }
+
+ if (y2 >= y1) /* The y-values are increasing */
+ {
+ yinc1 = 1;
+ yinc2 = 1;
+ }
+ else /* The y-values are decreasing */
+ {
+ yinc1 = -1;
+ yinc2 = -1;
+ }
+
+ if (deltax >= deltay) /* There is at least one x-value for every y-value */
+ {
+ xinc1 = 0; /* Don't change the x when numerator >= denominator */
+ yinc2 = 0; /* Don't change the y for every iteration */
+ den = deltax;
+ num = deltax / 2;
+ numadd = deltay;
+ numpixels = deltax; /* There are more x-values than y-values */
+ }
+ else /* There is at least one y-value for every x-value */
+ {
+ xinc2 = 0; /* Don't change the x for every iteration */
+ yinc1 = 0; /* Don't change the y when numerator >= denominator */
+ den = deltay;
+ num = deltay / 2;
+ numadd = deltax;
+ numpixels = deltay; /* There are more y-values than x-values */
+ }
+
+ for (curpixel = 0; curpixel <= numpixels; curpixel++)
+ {
+ PutPixel(x, y); /* Draw the current pixel */
+ num += numadd; /* Increase the numerator by the top of the fraction */
+ if (num >= den) /* Check if numerator >= denominator */
+ {
+ num -= den; /* Calculate the new numerator value */
+ x += xinc1; /* Change the x as appropriate */
+ y += yinc1; /* Change the y as appropriate */
+ }
+ x += xinc2; /* Change the x as appropriate */
+ y += yinc2; /* Change the y as appropriate */
+ }
+}
+
+/**
+ * @brief Displays an polyline (between many points).
+ * @param Points: pointer to the points array.
+ * @param PointCount: Number of points.
+ * @retval None
+ */
+void LCD_PolyLine(pPoint Points, uint16_t PointCount)
+{
+ int16_t X = 0, Y = 0;
+
+ if(PointCount < 2)
+ {
+ return;
+ }
+
+ while(--PointCount)
+ {
+ X = Points->X;
+ Y = Points->Y;
+ Points++;
+ LCD_DrawUniLine(X, Y, Points->X, Points->Y);
+ }
+}
+
+/**
+ * @brief Displays an relative polyline (between many points).
+ * @param Points: pointer to the points array.
+ * @param PointCount: Number of points.
+ * @param Closed: specifies if the draw is closed or not.
+ * 1: closed, 0 : not closed.
+ * @retval None
+ */
+static void LCD_PolyLineRelativeClosed(pPoint Points, uint16_t PointCount, uint16_t Closed)
+{
+ int16_t X = 0, Y = 0;
+ pPoint First = Points;
+
+ if(PointCount < 2)
+ {
+ return;
+ }
+ X = Points->X;
+ Y = Points->Y;
+ while(--PointCount)
+ {
+ Points++;
+ LCD_DrawUniLine(X, Y, X + Points->X, Y + Points->Y);
+ X = X + Points->X;
+ Y = Y + Points->Y;
+ }
+ if(Closed)
+ {
+ LCD_DrawUniLine(First->X, First->Y, X, Y);
+ }
+}
+
+/**
+ * @brief Displays a closed polyline (between many points).
+ * @param Points: pointer to the points array.
+ * @param PointCount: Number of points.
+ * @retval None
+ */
+void LCD_ClosedPolyLine(pPoint Points, uint16_t PointCount)
+{
+ LCD_PolyLine(Points, PointCount);
+ LCD_DrawUniLine(Points->X, Points->Y, (Points+PointCount-1)->X, (Points+PointCount-1)->Y);
+}
+
+/**
+ * @brief Displays a relative polyline (between many points).
+ * @param Points: pointer to the points array.
+ * @param PointCount: Number of points.
+ * @retval None
+ */
+void LCD_PolyLineRelative(pPoint Points, uint16_t PointCount)
+{
+ LCD_PolyLineRelativeClosed(Points, PointCount, 0);
+}
+
+/**
+ * @brief Displays a closed relative polyline (between many points).
+ * @param Points: pointer to the points array.
+ * @param PointCount: Number of points.
+ * @retval None
+ */
+void LCD_ClosedPolyLineRelative(pPoint Points, uint16_t PointCount)
+{
+ LCD_PolyLineRelativeClosed(Points, PointCount, 1);
+}
+
+
+/**
+ * @brief Displays a full polyline (between many points).
+ * @param Points: pointer to the points array.
+ * @param PointCount: Number of points.
+ * @retval None
+ */
+void LCD_FillPolyLine(pPoint Points, uint16_t PointCount)
+{
+ /* public-domain code by Darel Rex Finley, 2007 */
+ uint16_t nodes = 0, nodeX[MAX_POLY_CORNERS], pixelX = 0, pixelY = 0, i = 0,
+ j = 0, swap = 0;
+ uint16_t IMAGE_LEFT = 0, IMAGE_RIGHT = 0, IMAGE_TOP = 0, IMAGE_BOTTOM = 0;
+
+ IMAGE_LEFT = IMAGE_RIGHT = Points->X;
+ IMAGE_TOP= IMAGE_BOTTOM = Points->Y;
+
+ for(i = 1; i < PointCount; i++)
+ {
+ pixelX = POLY_X(i);
+ if(pixelX < IMAGE_LEFT)
+ {
+ IMAGE_LEFT = pixelX;
+ }
+ if(pixelX > IMAGE_RIGHT)
+ {
+ IMAGE_RIGHT = pixelX;
+ }
+
+ pixelY = POLY_Y(i);
+ if(pixelY < IMAGE_TOP)
+ {
+ IMAGE_TOP = pixelY;
+ }
+ if(pixelY > IMAGE_BOTTOM)
+ {
+ IMAGE_BOTTOM = pixelY;
+ }
+ }
+
+ LCD_SetTextColor(BackColor);
+
+ /* Loop through the rows of the image. */
+ for (pixelY = IMAGE_TOP; pixelY < IMAGE_BOTTOM; pixelY++)
+ {
+ /* Build a list of nodes. */
+ nodes = 0; j = PointCount-1;
+
+ for (i = 0; i < PointCount; i++)
+ {
+ if (POLY_Y(i)<(double) pixelY && POLY_Y(j)>=(double) pixelY || POLY_Y(j)<(double) pixelY && POLY_Y(i)>=(double) pixelY)
+ {
+ nodeX[nodes++]=(int) (POLY_X(i)+((pixelY-POLY_Y(i))*(POLY_X(j)-POLY_X(i)))/(POLY_Y(j)-POLY_Y(i)));
+ }
+ j = i;
+ }
+
+ /* Sort the nodes, via a simple "Bubble" sort. */
+ i = 0;
+ while (i < nodes-1)
+ {
+ if (nodeX[i]>nodeX[i+1])
+ {
+ swap = nodeX[i];
+ nodeX[i] = nodeX[i+1];
+ nodeX[i+1] = swap;
+ if(i)
+ {
+ i--;
+ }
+ }
+ else
+ {
+ i++;
+ }
+ }
+
+ /* Fill the pixels between node pairs. */
+ for (i = 0; i < nodes; i+=2)
+ {
+ if(nodeX[i] >= IMAGE_RIGHT)
+ {
+ break;
+ }
+ if(nodeX[i+1] > IMAGE_LEFT)
+ {
+ if (nodeX[i] < IMAGE_LEFT)
+ {
+ nodeX[i]=IMAGE_LEFT;
+ }
+ if(nodeX[i+1] > IMAGE_RIGHT)
+ {
+ nodeX[i+1] = IMAGE_RIGHT;
+ }
+ LCD_SetTextColor(BackColor);
+ LCD_DrawLine(pixelY, nodeX[i+1], nodeX[i+1] - nodeX[i], LCD_DIR_HORIZONTAL);
+ LCD_SetTextColor(TextColor);
+ PutPixel(pixelY, nodeX[i+1]);
+ PutPixel(pixelY, nodeX[i]);
+ /* for (j=nodeX[i]; j<nodeX[i+1]; j++) PutPixel(j,pixelY); */
+ }
+ }
+ }
+
+ /* draw the edges */
+ LCD_SetTextColor(TextColor);
+}
+
+/**
+ * @brief Reset LCD control line(/CS) and Send Start-Byte
+ * @param Start_Byte: the Start-Byte to be sent
+ * @retval None
+ */
+void LCD_nCS_StartByte(uint8_t Start_Byte)
+{
+ LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_RESET);
+
+ SPI_I2S_SendData(LCD_SPI, Start_Byte);
+
+ while(SPI_I2S_GetFlagStatus(LCD_SPI, SPI_I2S_FLAG_BSY) != RESET)
+ {
+ }
+}
+
+
+/**
+ * @brief Writes index to select the LCD register.
+ * @param LCD_Reg: address of the selected register.
+ * @retval None
+ */
+void LCD_WriteRegIndex(uint8_t LCD_Reg)
+{
+ /* Reset LCD control line(/CS) and Send Start-Byte */
+ LCD_nCS_StartByte(START_BYTE | SET_INDEX);
+
+ /* Write 16-bit Reg Index (High Byte is 0) */
+ SPI_I2S_SendData(LCD_SPI, 0x00);
+
+ while(SPI_I2S_GetFlagStatus(LCD_SPI, SPI_I2S_FLAG_BSY) != RESET)
+ {
+ }
+
+ SPI_I2S_SendData(LCD_SPI, LCD_Reg);
+
+ while(SPI_I2S_GetFlagStatus(LCD_SPI, SPI_I2S_FLAG_BSY) != RESET)
+ {
+ }
+
+ LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_SET);
+}
+
+
+/**
+ * @brief Writes to the selected LCD ILI9320 register.
+ * @param LCD_Reg: address of the selected register.
+ * @param LCD_RegValue: value to write to the selected register.
+ * @retval None
+ */
+static void LCD_WriteRegILI9320(uint8_t LCD_Reg, uint16_t LCD_RegValue)
+{
+ /* Write 16-bit Index (then Write Reg) */
+ LCD_WriteRegIndex(LCD_Reg);
+
+ /* Write 16-bit Reg */
+ /* Reset LCD control line(/CS) and Send Start-Byte */
+ LCD_nCS_StartByte(START_BYTE | LCD_WRITE_REG);
+
+ SPI_I2S_SendData(LCD_SPI, LCD_RegValue>>8);
+
+ while(SPI_I2S_GetFlagStatus(LCD_SPI, SPI_I2S_FLAG_BSY) != RESET)
+ {
+ }
+
+ SPI_I2S_SendData(LCD_SPI, (LCD_RegValue & 0xFF));
+
+ while(SPI_I2S_GetFlagStatus(LCD_SPI, SPI_I2S_FLAG_BSY) != RESET)
+ {
+ }
+
+ LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_SET);
+}
+
+
+/**
+ * @brief Reads the selected LCD Register.
+ * @param LCD_Reg: address of the selected register.
+ * @retval LCD Register Value.
+ */
+uint16_t LCD_ReadReg(uint8_t LCD_Reg)
+{
+ uint16_t tmp = 0;
+ uint8_t i = 0;
+
+ /* LCD_SPI prescaler: 4 */
+ LCD_SPI->CR1 &= 0xFFC7;
+ LCD_SPI->CR1 |= 0x0008;
+ /* Write 16-bit Index (then Read Reg) */
+ LCD_WriteRegIndex(LCD_Reg);
+ /* Read 16-bit Reg */
+ /* Reset LCD control line(/CS) and Send Start-Byte */
+ LCD_nCS_StartByte(START_BYTE | LCD_READ_REG);
+
+ for(i = 0; i < 5; i++)
+ {
+ SPI_I2S_SendData(LCD_SPI, 0xFF);
+ while(SPI_I2S_GetFlagStatus(LCD_SPI, SPI_I2S_FLAG_BSY) != RESET)
+ {
+ }
+ /* One byte of invalid dummy data read after the start byte */
+ while(SPI_I2S_GetFlagStatus(LCD_SPI, SPI_I2S_FLAG_RXNE) == RESET)
+ {
+ }
+ SPI_I2S_ReceiveData(LCD_SPI);
+ }
+
+ SPI_I2S_SendData(LCD_SPI, 0xFF);
+
+ /* Read upper byte */
+ while(SPI_I2S_GetFlagStatus(LCD_SPI, SPI_I2S_FLAG_BSY) != RESET)
+ {
+ }
+
+ /* Read lower byte */
+ while(SPI_I2S_GetFlagStatus(LCD_SPI, SPI_I2S_FLAG_RXNE) == RESET)
+ {
+ }
+ tmp = SPI_I2S_ReceiveData(LCD_SPI);
+
+
+ SPI_I2S_SendData(LCD_SPI, 0xFF);
+ while(SPI_I2S_GetFlagStatus(LCD_SPI, SPI_I2S_FLAG_BSY) != RESET)
+ {
+ }
+
+ /* Read lower byte */
+ while(SPI_I2S_GetFlagStatus(LCD_SPI, SPI_I2S_FLAG_RXNE) == RESET)
+ {
+ }
+
+ tmp = ((tmp & 0xFF) << 8) | SPI_I2S_ReceiveData(LCD_SPI);
+ LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_SET);
+
+ /* LCD_SPI prescaler: 2 */
+ LCD_SPI->CR1 &= 0xFFC7;
+
+ return tmp;
+}
+
+
+/**
+ * @brief Prepare to write to the LCD RAM.
+ * @param None
+ * @retval None
+ */
+void LCD_WriteRAM_Prepare(void)
+{
+ LCD_WriteRegIndex(LCD_REG_34); /* Select GRAM Reg */
+
+ /* Reset LCD control line(/CS) and Send Start-Byte */
+ LCD_nCS_StartByte(START_BYTE | LCD_WRITE_REG);
+}
+
+
+/**
+ * @brief Writes 1 word to the LCD RAM.
+ * @param RGB_Code: the pixel color in RGB mode (5-6-5).
+ * @retval None
+ */
+void LCD_WriteRAMWord(uint16_t RGB_Code)
+{
+
+ LCD_WriteRAM_Prepare();
+
+ LCD_WriteRAM(RGB_Code);
+
+ LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_SET);
+}
+
+
+/**
+ * @brief Writes to the selected LCD HX8312 register.
+ * @param LCD_Reg: address of the selected register.
+ * @param LCD_RegValue: value to write to the selected register.
+ * @retval None
+ */
+static void LCD_WriteRegHX8312(uint8_t LCD_Reg, uint8_t LCD_RegValue)
+{
+ uint16_t tmp = 0;
+
+ LCD_CtrlLinesWrite(LCD_NWR_GPIO_PORT, LCD_NWR_PIN, Bit_RESET);
+ LCD_CtrlLinesWrite(LCD_RS_GPIO_PORT, LCD_RS_PIN, Bit_RESET);
+ LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_RESET);
+
+ tmp = LCD_Reg << 8;
+ tmp |= LCD_RegValue;
+
+ SPI_I2S_SendData(LCD_SPI, tmp);
+
+ while(SPI_I2S_GetFlagStatus(LCD_SPI, SPI_I2S_FLAG_BSY) != RESET)
+ {
+ }
+
+ LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_SET);
+}
+
+
+/**
+ * @brief Writes to the selected LCD register.
+ * @param LCD_Reg: address of the selected register.
+ * @param LCD_RegValue: value to write to the selected register.
+ * @retval None
+ */
+void LCD_WriteReg(uint8_t LCD_Reg, uint16_t LCD_RegValue)
+{
+ if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
+ {
+ LCD_WriteRegILI9320(LCD_Reg, LCD_RegValue);
+ }
+ else if(LCDType == LCD_HX8312)
+ {
+ LCD_WriteRegHX8312(LCD_Reg, ((uint8_t)LCD_RegValue));
+ }
+}
+
+
+/**
+ * @brief Writes to the LCD RAM.
+ * @param RGB_Code: the pixel color in RGB mode (5-6-5).
+ * @retval None
+ */
+void LCD_WriteRAM(uint16_t RGB_Code)
+{
+ if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
+ {
+ SPI_I2S_SendData(LCD_SPI, RGB_Code >> 8);
+ while(SPI_I2S_GetFlagStatus(LCD_SPI, SPI_I2S_FLAG_BSY) != RESET)
+ {
+ }
+ SPI_I2S_SendData(LCD_SPI, RGB_Code & 0xFF);
+ while(SPI_I2S_GetFlagStatus(LCD_SPI, SPI_I2S_FLAG_BSY) != RESET)
+ {
+ }
+ }
+
+ if(LCDType == LCD_HX8312)
+ {
+ LCD_CtrlLinesWrite(LCD_NWR_GPIO_PORT, LCD_NWR_PIN, Bit_RESET);
+ LCD_CtrlLinesWrite(LCD_RS_GPIO_PORT, LCD_RS_PIN, Bit_SET);
+ LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_RESET);
+ SPI_I2S_SendData(LCD_SPI, RGB_Code);
+
+ while(SPI_I2S_GetFlagStatus(LCD_SPI, SPI_I2S_FLAG_BSY) != RESET)
+ {
+ }
+
+ LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_SET);
+ }
+}
+
+
+/**
+ * @brief Power on the LCD.
+ * @param None
+ * @retval None
+ */
+void LCD_PowerOn(void)
+{
+ if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
+ {
+ /* Power On sequence ---------------------------------------------------------*/
+ LCD_WriteReg(LCD_REG_16, 0x0000); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
+ LCD_WriteReg(LCD_REG_17, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */
+ LCD_WriteReg(LCD_REG_18, 0x0000); /* VREG1OUT voltage */
+ LCD_WriteReg(LCD_REG_19, 0x0000); /* VDV[4:0] for VCOM amplitude */
+ _delay_(20); /* Dis-charge capacitor power voltage (200ms) */
+ LCD_WriteReg(LCD_REG_16, 0x17B0); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
+ LCD_WriteReg(LCD_REG_17, 0x0137); /* DC1[2:0], DC0[2:0], VC[2:0] */
+ _delay_(5); /* Delay 50 ms */
+ LCD_WriteReg(LCD_REG_18, 0x0139); /* VREG1OUT voltage */
+ _delay_(5); /* delay 50 ms */
+ LCD_WriteReg(LCD_REG_19, 0x1d00); /* VDV[4:0] for VCOM amplitude */
+ LCD_WriteReg(LCD_REG_41, 0x0013); /* VCM[4:0] for VCOMH */
+ _delay_(5); /* delay 50 ms */
+ LCD_WriteReg(LCD_REG_7, 0x0173); /* 262K color and display ON */
+ }
+ else if(LCDType == LCD_HX8312)
+ {
+ /* Power On Set */
+ LCD_WriteReg(LCD_REG_28, 0x73);
+ LCD_WriteReg(LCD_REG_36, 0x74);
+ LCD_WriteReg(LCD_REG_30, 0x01);
+ LCD_WriteReg(LCD_REG_24, 0xC1);
+ _delay_(1); /* Delay 10 ms */
+ LCD_WriteReg(LCD_REG_24, 0xE1);
+ LCD_WriteReg(LCD_REG_24, 0xF1);
+ _delay_(6); /* Delay 60 ms */
+ LCD_WriteReg(LCD_REG_24, 0xF5);
+ _delay_(6); /* Delay 60 ms */
+ LCD_WriteReg(LCD_REG_27, 0x09);
+ _delay_(1); /* Delay 10 ms */
+ LCD_WriteReg(LCD_REG_31, 0x11);
+ LCD_WriteReg(LCD_REG_32, 0x0E);
+ LCD_WriteReg(LCD_REG_30, 0x81);
+ _delay_(1); /* Delay 10 ms */
+ }
+}
+
+
+/**
+ * @brief Enables the Display.
+ * @param None
+ * @retval None
+ */
+void LCD_DisplayOn(void)
+{
+ if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
+ {
+ /* Display On */
+ LCD_WriteReg(LCD_REG_7, 0x0173); /* 262K color and display ON */
+ }
+ else if(LCDType == LCD_HX8312)
+ {
+ LCD_WriteReg(LCD_REG_1, 0x50);
+ LCD_WriteReg(LCD_REG_5, 0x04);
+ /* Display On */
+ LCD_WriteReg(LCD_REG_0, 0x80);
+ LCD_WriteReg(LCD_REG_59, 0x01);
+ _delay_(4); /* Delay 40 ms */
+ LCD_WriteReg(LCD_REG_0, 0x20);
+ }
+}
+
+
+/**
+ * @brief Disables the Display.
+ * @param None
+ * @retval None
+ */
+void LCD_DisplayOff(void)
+{
+ if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
+ {
+ /* Display Off */
+ LCD_WriteReg(LCD_REG_7, 0x0);
+ }
+ else if(LCDType == LCD_HX8312)
+ {
+ /* Display Off */
+ LCD_WriteReg(LCD_REG_0, 0xA0);
+ _delay_(4); /* Delay 40 ms */
+ LCD_WriteReg(LCD_REG_59, 0x00);
+ }
+}
+
+
+/**
+ * @brief Configures LCD control lines in Output Push-Pull mode.
+ * @param None
+ * @retval None
+ */
+void LCD_CtrlLinesConfig(void)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+
+ /* Enable GPIO clock */
+ RCC_APB2PeriphClockCmd(LCD_NCS_GPIO_CLK | LCD_NWR_GPIO_CLK | LCD_RS_GPIO_CLK, ENABLE);
+
+ /* Configure NCS in Output Push-Pull mode */
+ GPIO_InitStructure.GPIO_Pin = LCD_NCS_PIN;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
+ GPIO_Init(LCD_NCS_GPIO_PORT, &GPIO_InitStructure);
+
+ /* Configure NWR(RNW), RS in Output Push-Pull mode */
+ GPIO_InitStructure.GPIO_Pin = LCD_RS_PIN;
+ GPIO_Init(LCD_RS_GPIO_PORT, &GPIO_InitStructure);
+
+ GPIO_InitStructure.GPIO_Pin = LCD_NWR_PIN;
+ GPIO_Init(LCD_NWR_GPIO_PORT, &GPIO_InitStructure);
+
+ LCD_CtrlLinesWrite(LCD_NWR_GPIO_PORT, LCD_NWR_PIN, Bit_SET);
+ LCD_CtrlLinesWrite(LCD_RS_GPIO_PORT, LCD_RS_PIN, Bit_SET);
+}
+
+
+/**
+ * @brief Sets or reset LCD control lines.
+ * @param GPIOx: where x can be B or D to select the GPIO peripheral.
+ * @param CtrlPins: the Control line.
+ * This parameter can be:
+ * @arg LCD_NCS_PIN: Chip Select pin
+ * @arg LCD_NWR_PIN: Read/Write Selection pin
+ * @arg LCD_RS_PIN: Register/RAM Selection pin
+ * @param BitVal: specifies the value to be written to the selected bit.
+ * This parameter can be:
+ * @arg Bit_RESET: to clear the port pin
+ * @arg Bit_SET: to set the port pin
+ * @retval None
+ */
+void LCD_CtrlLinesWrite(GPIO_TypeDef* GPIOx, uint16_t CtrlPins, BitAction BitVal)
+{
+ /* Set or Reset the control line */
+ GPIO_WriteBit(GPIOx, CtrlPins, BitVal);
+}
+
+/**
+ * @brief Configures the LCD_SPI interface.
+ * @param None
+ * @retval None
+ */
+void LCD_SPIConfig(void)
+{
+ SPI_InitTypeDef SPI_InitStructure;
+ GPIO_InitTypeDef GPIO_InitStructure;
+
+ /* Enable GPIO clock */
+ RCC_APB2PeriphClockCmd(LCD_SPI_SCK_GPIO_CLK | LCD_SPI_MISO_GPIO_CLK | LCD_SPI_MOSI_GPIO_CLK, ENABLE);
+
+ /* Enable SPI clock */
+ RCC_APB1PeriphClockCmd(LCD_SPI_CLK, ENABLE);
+
+ /* Configure SPI pins: SCK, MISO and MOSI */
+ GPIO_InitStructure.GPIO_Pin = LCD_SPI_SCK_PIN;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
+ GPIO_Init(LCD_SPI_SCK_GPIO_PORT, &GPIO_InitStructure);
+
+ GPIO_InitStructure.GPIO_Pin = LCD_SPI_MISO_PIN;
+ GPIO_Init(LCD_SPI_MISO_GPIO_PORT, &GPIO_InitStructure);
+
+ GPIO_InitStructure.GPIO_Pin = LCD_SPI_MOSI_PIN;
+ GPIO_Init(LCD_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure);
+
+ SPI_I2S_DeInit(LCD_SPI);
+
+ /* SPI Config */
+ SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
+ SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
+
+ if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
+ {
+ SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
+ SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;
+ SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
+ }
+ else if(LCDType == LCD_HX8312)
+ {
+ SPI_InitStructure.SPI_DataSize = SPI_DataSize_16b;
+ SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
+ SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;
+ }
+ SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
+ SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2;
+ SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
+
+ SPI_Init(LCD_SPI, &SPI_InitStructure);
+
+ /* SPI enable */
+ SPI_Cmd(LCD_SPI, ENABLE);
+}
+
+/**
+ * @brief Displays a pixel.
+ * @param x: pixel x.
+ * @param y: pixel y.
+ * @retval None
+ */
+static void PutPixel(int16_t x, int16_t y)
+{
+ if(x < 0 || x > 239 || y < 0 || y > 319)
+ {
+ return;
+ }
+ LCD_DrawLine(x, y, 1, LCD_DIR_HORIZONTAL);
+}
+
+#ifndef USE_Delay
+/**
+ * @brief Inserts a delay time.
+ * @param nCount: specifies the delay time length.
+ * @retval None
+ */
+static void delay(vu32 nCount)
+{
+ vu32 index = 0;
+ for(index = (100000 * nCount); index != 0; index--)
+ {
+ }
+}
+#endif /* USE_Delay*/
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210B_EVAL/stm3210b_eval_lcd.h b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210B_EVAL/stm3210b_eval_lcd.h
new file mode 100644
index 0000000..a733849
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210B_EVAL/stm3210b_eval_lcd.h
@@ -0,0 +1,400 @@
+/**
+ ******************************************************************************
+ * @file stm3210b_eval_lcd.h
+ * @author MCD Application Team
+ * @version V5.0.1
+ * @date 05-March-2012
+ * @brief This file contains all the functions prototypes for the
+ * stm3210b_eval_lcd firmware driver.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.st.com/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __STM3210B_EVAL_LCD_H
+#define __STM3210B_EVAL_LCD_H
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+/* Includes ------------------------------------------------------------------*/
+#include "stm3210b_eval.h"
+#include "../Common/fonts.h"
+
+/** @addtogroup Utilities
+ * @{
+ */
+
+/** @addtogroup STM32_EVAL
+ * @{
+ */
+
+/** @addtogroup STM3210B_EVAL
+ * @{
+ */
+
+/** @addtogroup STM3210B_EVAL_LCD
+ * @{
+ */
+
+
+/** @defgroup STM3210B_EVAL_LCD_Exported_Types
+ * @{
+ */
+typedef struct
+{
+ int16_t X;
+ int16_t Y;
+} Point, * pPoint;
+/**
+ * @}
+ */
+
+
+
+/** @defgroup STM3210B_EVAL_LCD_Exported_Constants
+ * @{
+ */
+
+/**
+ * @brief Uncomment the line below if you want to use LCD_DrawBMP function to
+ * display a bitmap picture on the LCD. This function assumes that the bitmap
+ * file is loaded in the SPI Flash (mounted on STM3210B-EVAL board), however
+ * user can tailor it according to his application hardware requirement.
+ */
+/*#define USE_LCD_DrawBMP*/
+
+/**
+ * @brief Uncomment the line below if you want to use user defined Delay function
+ * (for precise timing), otherwise default _delay_ function defined within
+ * this driver is used (less precise timing).
+ */
+/* #define USE_Delay */
+
+#ifdef USE_Delay
+#include "main.h"
+
+ #define _delay_ Delay /* !< User can provide more timing precise _delay_ function
+ (with 10ms time base), using SysTick for example */
+#else
+ #define _delay_ delay /* !< Default _delay_ function with less precise timing */
+#endif
+
+
+/**
+ * @brief LCD Control pins
+ */
+#define LCD_NCS_PIN GPIO_Pin_2
+#define LCD_NCS_GPIO_PORT GPIOB
+#define LCD_NCS_GPIO_CLK RCC_APB2Periph_GPIOB
+#define LCD_NWR_PIN GPIO_Pin_15
+#define LCD_NWR_GPIO_PORT GPIOD
+#define LCD_NWR_GPIO_CLK RCC_APB2Periph_GPIOD
+#define LCD_RS_PIN GPIO_Pin_7
+#define LCD_RS_GPIO_PORT GPIOD
+#define LCD_RS_GPIO_CLK RCC_APB2Periph_GPIOD
+
+/**
+ * @brief LCD SPI Interface pins
+ */
+#define LCD_SPI SPI2
+#define LCD_SPI_CLK RCC_APB1Periph_SPI2
+#define LCD_SPI_SCK_PIN GPIO_Pin_13
+#define LCD_SPI_SCK_GPIO_PORT GPIOB
+#define LCD_SPI_SCK_GPIO_CLK RCC_APB2Periph_GPIOB
+#define LCD_SPI_MISO_PIN GPIO_Pin_14
+#define LCD_SPI_MISO_GPIO_PORT GPIOB
+#define LCD_SPI_MISO_GPIO_CLK RCC_APB2Periph_GPIOB
+#define LCD_SPI_MOSI_PIN GPIO_Pin_15
+#define LCD_SPI_MOSI_GPIO_PORT GPIOB
+#define LCD_SPI_MOSI_GPIO_CLK RCC_APB2Periph_GPIOB
+
+/**
+ * @brief LCD Registers
+ */
+#define LCD_REG_0 0x00
+#define LCD_REG_1 0x01
+#define LCD_REG_2 0x02
+#define LCD_REG_3 0x03
+#define LCD_REG_4 0x04
+#define LCD_REG_5 0x05
+#define LCD_REG_6 0x06
+#define LCD_REG_7 0x07
+#define LCD_REG_8 0x08
+#define LCD_REG_9 0x09
+#define LCD_REG_10 0x0A
+#define LCD_REG_12 0x0C
+#define LCD_REG_13 0x0D
+#define LCD_REG_14 0x0E
+#define LCD_REG_15 0x0F
+#define LCD_REG_16 0x10
+#define LCD_REG_17 0x11
+#define LCD_REG_18 0x12
+#define LCD_REG_19 0x13
+#define LCD_REG_20 0x14
+#define LCD_REG_21 0x15
+#define LCD_REG_22 0x16
+#define LCD_REG_23 0x17
+#define LCD_REG_24 0x18
+#define LCD_REG_25 0x19
+#define LCD_REG_26 0x1A
+#define LCD_REG_27 0x1B
+#define LCD_REG_28 0x1C
+#define LCD_REG_29 0x1D
+#define LCD_REG_30 0x1E
+#define LCD_REG_31 0x1F
+#define LCD_REG_32 0x20
+#define LCD_REG_33 0x21
+#define LCD_REG_34 0x22
+#define LCD_REG_36 0x24
+#define LCD_REG_37 0x25
+#define LCD_REG_40 0x28
+#define LCD_REG_41 0x29
+#define LCD_REG_43 0x2B
+#define LCD_REG_45 0x2D
+#define LCD_REG_48 0x30
+#define LCD_REG_49 0x31
+#define LCD_REG_50 0x32
+#define LCD_REG_51 0x33
+#define LCD_REG_52 0x34
+#define LCD_REG_53 0x35
+#define LCD_REG_54 0x36
+#define LCD_REG_55 0x37
+#define LCD_REG_56 0x38
+#define LCD_REG_57 0x39
+#define LCD_REG_59 0x3B
+#define LCD_REG_60 0x3C
+#define LCD_REG_61 0x3D
+#define LCD_REG_62 0x3E
+#define LCD_REG_63 0x3F
+#define LCD_REG_64 0x40
+#define LCD_REG_65 0x41
+#define LCD_REG_66 0x42
+#define LCD_REG_67 0x43
+#define LCD_REG_68 0x44
+#define LCD_REG_69 0x45
+#define LCD_REG_70 0x46
+#define LCD_REG_71 0x47
+#define LCD_REG_72 0x48
+#define LCD_REG_73 0x49
+#define LCD_REG_74 0x4A
+#define LCD_REG_75 0x4B
+#define LCD_REG_76 0x4C
+#define LCD_REG_77 0x4D
+#define LCD_REG_78 0x4E
+#define LCD_REG_79 0x4F
+#define LCD_REG_80 0x50
+#define LCD_REG_81 0x51
+#define LCD_REG_82 0x52
+#define LCD_REG_83 0x53
+#define LCD_REG_96 0x60
+#define LCD_REG_97 0x61
+#define LCD_REG_106 0x6A
+#define LCD_REG_118 0x76
+#define LCD_REG_128 0x80
+#define LCD_REG_129 0x81
+#define LCD_REG_130 0x82
+#define LCD_REG_131 0x83
+#define LCD_REG_132 0x84
+#define LCD_REG_133 0x85
+#define LCD_REG_134 0x86
+#define LCD_REG_135 0x87
+#define LCD_REG_136 0x88
+#define LCD_REG_137 0x89
+#define LCD_REG_139 0x8B
+#define LCD_REG_140 0x8C
+#define LCD_REG_141 0x8D
+#define LCD_REG_143 0x8F
+#define LCD_REG_144 0x90
+#define LCD_REG_145 0x91
+#define LCD_REG_146 0x92
+#define LCD_REG_147 0x93
+#define LCD_REG_148 0x94
+#define LCD_REG_149 0x95
+#define LCD_REG_150 0x96
+#define LCD_REG_151 0x97
+#define LCD_REG_152 0x98
+#define LCD_REG_153 0x99
+#define LCD_REG_154 0x9A
+#define LCD_REG_157 0x9D
+#define LCD_REG_192 0xC0
+#define LCD_REG_193 0xC1
+#define LCD_REG_227 0xE3
+#define LCD_REG_229 0xE5
+#define LCD_REG_231 0xE7
+#define LCD_REG_239 0xEF
+
+
+/**
+ * @brief LCD color
+ */
+#define LCD_COLOR_WHITE 0xFFFF
+#define LCD_COLOR_BLACK 0x0000
+#define LCD_COLOR_GREY 0xF7DE
+#define LCD_COLOR_BLUE 0x001F
+#define LCD_COLOR_BLUE2 0x051F
+#define LCD_COLOR_RED 0xF800
+#define LCD_COLOR_MAGENTA 0xF81F
+#define LCD_COLOR_GREEN 0x07E0
+#define LCD_COLOR_CYAN 0x7FFF
+#define LCD_COLOR_YELLOW 0xFFE0
+
+/**
+ * @brief LCD Lines depending on the chosen fonts.
+ */
+#define LCD_LINE_0 LINE(0)
+#define LCD_LINE_1 LINE(1)
+#define LCD_LINE_2 LINE(2)
+#define LCD_LINE_3 LINE(3)
+#define LCD_LINE_4 LINE(4)
+#define LCD_LINE_5 LINE(5)
+#define LCD_LINE_6 LINE(6)
+#define LCD_LINE_7 LINE(7)
+#define LCD_LINE_8 LINE(8)
+#define LCD_LINE_9 LINE(9)
+#define LCD_LINE_10 LINE(10)
+#define LCD_LINE_11 LINE(11)
+#define LCD_LINE_12 LINE(12)
+#define LCD_LINE_13 LINE(13)
+#define LCD_LINE_14 LINE(14)
+#define LCD_LINE_15 LINE(15)
+#define LCD_LINE_16 LINE(16)
+#define LCD_LINE_17 LINE(17)
+#define LCD_LINE_18 LINE(18)
+#define LCD_LINE_19 LINE(19)
+#define LCD_LINE_20 LINE(20)
+#define LCD_LINE_21 LINE(21)
+#define LCD_LINE_22 LINE(22)
+#define LCD_LINE_23 LINE(23)
+#define LCD_LINE_24 LINE(24)
+#define LCD_LINE_25 LINE(25)
+#define LCD_LINE_26 LINE(26)
+#define LCD_LINE_27 LINE(27)
+#define LCD_LINE_28 LINE(28)
+#define LCD_LINE_29 LINE(29)
+
+/**
+ * @brief LCD default font
+ */
+#define LCD_DEFAULT_FONT Font16x24
+
+/**
+ * @brief LCD Direction
+ */
+#define LCD_DIR_HORIZONTAL 0x0000
+#define LCD_DIR_VERTICAL 0x0001
+
+/**
+ * @brief LCD Size (Width and Height)
+ */
+#define LCD_PIXEL_WIDTH 0x0140
+#define LCD_PIXEL_HEIGHT 0x00F0
+
+/**
+ * @}
+ */
+
+/** @defgroup STM3210B_EVAL_LCD_Exported_Macros
+ * @{
+ */
+#define ASSEMBLE_RGB(R, G, B) ((((R)& 0xF8) << 8) | (((G) & 0xFC) << 3) | (((B) & 0xF8) >> 3))
+/**
+ * @}
+ */
+
+
+
+/** @defgroup STM3210B_EVAL_LCD_Exported_Functions
+ * @{
+ */
+void LCD_DeInit(void);
+void LCD_Setup(void);
+void STM3210B_LCD_Init(void);
+void LCD_SetColors(__IO uint16_t _TextColor, __IO uint16_t _BackColor);
+void LCD_GetColors(__IO uint16_t *_TextColor, __IO uint16_t *_BackColor);
+void LCD_SetTextColor(__IO uint16_t Color);
+void LCD_SetBackColor(__IO uint16_t Color);
+void LCD_ClearLine(uint8_t Line);
+void LCD_Clear(uint16_t Color);
+void LCD_SetCursor(uint8_t Xpos, uint16_t Ypos);
+void LCD_DrawChar(uint8_t Xpos, uint16_t Ypos, const uint16_t *c);
+void LCD_DisplayChar(uint8_t Line, uint16_t Column, uint8_t Ascii);
+void LCD_SetFont(sFONT *fonts);
+sFONT *LCD_GetFont(void);
+void LCD_DisplayStringLine(uint8_t Line, uint8_t *ptr);
+void LCD_SetDisplayWindow(uint8_t Xpos, uint16_t Ypos, uint8_t Height, uint16_t Width);
+void LCD_WindowModeDisable(void);
+void LCD_DrawLine(uint8_t Xpos, uint16_t Ypos, uint16_t Length, uint8_t Direction);
+void LCD_DrawRect(uint8_t Xpos, uint16_t Ypos, uint8_t Height, uint16_t Width);
+void LCD_DrawCircle(uint8_t Xpos, uint16_t Ypos, uint16_t Radius);
+void LCD_DrawMonoPict(const uint32_t *Pict);
+void LCD_DrawBMP(uint32_t BmpAddress);
+void LCD_DrawUniLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2);
+void LCD_DrawFullRect(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height);
+void LCD_DrawFullCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius);
+void LCD_PolyLine(pPoint Points, uint16_t PointCount);
+void LCD_PolyLineRelative(pPoint Points, uint16_t PointCount);
+void LCD_ClosedPolyLine(pPoint Points, uint16_t PointCount);
+void LCD_ClosedPolyLineRelative(pPoint Points, uint16_t PointCount);
+void LCD_FillPolyLine(pPoint Points, uint16_t PointCount);
+
+void LCD_nCS_StartByte(uint8_t Start_Byte);
+void LCD_WriteRegIndex(uint8_t LCD_Reg);
+void LCD_WriteReg(uint8_t LCD_Reg, uint16_t LCD_RegValue);
+void LCD_WriteRAM_Prepare(void);
+void LCD_WriteRAMWord(uint16_t RGB_Code);
+uint16_t LCD_ReadReg(uint8_t LCD_Reg);
+void LCD_WriteRAM(uint16_t RGB_Code);
+void LCD_PowerOn(void);
+void LCD_DisplayOn(void);
+void LCD_DisplayOff(void);
+
+void LCD_CtrlLinesConfig(void);
+void LCD_CtrlLinesWrite(GPIO_TypeDef* GPIOx, uint16_t CtrlPins, BitAction BitVal);
+void LCD_SPIConfig(void);
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __STM3210B_EVAL_LCD_H */
+
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210B_EVAL/stm3210b_eval_spi_flash.c b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210B_EVAL/stm3210b_eval_spi_flash.c
new file mode 100644
index 0000000..bb827e2
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210B_EVAL/stm3210b_eval_spi_flash.c
@@ -0,0 +1,546 @@
+/**
+ ******************************************************************************
+ * @file stm3210b_eval_spi_flash.c
+ * @author MCD Application Team
+ * @version V5.0.1
+ * @date 05-March-2012
+ * @brief This file provides a set of functions needed to manage the SPI M25Pxxx
+ * FLASH memory mounted on STM3210B-EVAL board.
+ * It implements a high level communication layer for read and write
+ * from/to this memory. The needed STM32 hardware resources (SPI and
+ * GPIO) are defined in stm3210b_eval.h file, and the initialization is
+ * performed in sFLASH_LowLevel_Init() function declared in stm3210b_eval.c
+ * file.
+ * You can easily tailor this driver to any other development board,
+ * by just adapting the defines for hardware resources and
+ * sFLASH_LowLevel_Init() function.
+ *
+ * +-----------------------------------------------------------+
+ * | Pin assignment |
+ * +-----------------------------+---------------+-------------+
+ * | STM32 SPI Pins | sFLASH | Pin |
+ * +-----------------------------+---------------+-------------+
+ * | sFLASH_CS_PIN | ChipSelect(/S)| 1 |
+ * | sFLASH_SPI_MISO_PIN / MISO | DataOut(Q) | 2 |
+ * | | VCC | 3 (3.3 V)|
+ * | | GND | 4 (0 V) |
+ * | sFLASH_SPI_MOSI_PIN / MOSI | DataIn(D) | 5 |
+ * | sFLASH_SPI_SCK_PIN / SCLK | Clock(C) | 6 |
+ * | | VCC | 7 (3.3 V)|
+ * | | VCC | 8 (3.3 V)|
+ * +-----------------------------+---------------+-------------+
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.st.com/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+
+/* Includes ------------------------------------------------------------------*/
+#include "stm3210b_eval_spi_flash.h"
+
+/** @addtogroup Utilities
+ * @{
+ */
+
+/** @addtogroup STM32_EVAL
+ * @{
+ */
+
+/** @addtogroup STM3210B_EVAL
+ * @{
+ */
+
+/** @addtogroup STM3210B_EVAL_SPI_FLASH
+ * @brief This file includes the M25Pxxx SPI FLASH driver of STM3210B-EVAL board.
+ * @{
+ */
+
+/** @defgroup STM3210B_EVAL_SPI_FLASH_Private_Types
+ * @{
+ */
+/**
+ * @}
+ */
+
+
+/** @defgroup STM3210B_EVAL_SPI_FLASH_Private_Defines
+ * @{
+ */
+/**
+ * @}
+ */
+
+/** @defgroup STM3210B_EVAL_SPI_FLASH_Private_Macros
+ * @{
+ */
+/**
+ * @}
+ */
+
+
+/** @defgroup STM3210B_EVAL_SPI_FLASH_Private_Variables
+ * @{
+ */
+/**
+ * @}
+ */
+
+
+/** @defgroup STM3210B_EVAL_SPI_FLASH_Private_Function_Prototypes
+ * @{
+ */
+/**
+ * @}
+ */
+
+
+/** @defgroup STM3210B_EVAL_SPI_FLASH_Private_Functions
+ * @{
+ */
+
+/**
+ * @brief DeInitializes the peripherals used by the SPI FLASH driver.
+ * @param None
+ * @retval None
+ */
+void sFLASH_DeInit(void)
+{
+ sFLASH_LowLevel_DeInit();
+}
+
+/**
+ * @brief Initializes the peripherals used by the SPI FLASH driver.
+ * @param None
+ * @retval None
+ */
+void sFLASH_Init(void)
+{
+ SPI_InitTypeDef SPI_InitStructure;
+
+ sFLASH_LowLevel_Init();
+
+ /*!< Deselect the FLASH: Chip Select high */
+ sFLASH_CS_HIGH();
+
+ /*!< SPI configuration */
+ SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
+ SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
+ SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
+ SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;
+ SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
+ SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
+#if defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || defined (STM32F10X_HD_VL)
+ SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2;
+#else
+ SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4;
+#endif
+
+ SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
+ SPI_InitStructure.SPI_CRCPolynomial = 7;
+ SPI_Init(sFLASH_SPI, &SPI_InitStructure);
+
+ /*!< Enable the sFLASH_SPI */
+ SPI_Cmd(sFLASH_SPI, ENABLE);
+}
+
+/**
+ * @brief Erases the specified FLASH sector.
+ * @param SectorAddr: address of the sector to erase.
+ * @retval None
+ */
+void sFLASH_EraseSector(uint32_t SectorAddr)
+{
+ /*!< Send write enable instruction */
+ sFLASH_WriteEnable();
+
+ /*!< Sector Erase */
+ /*!< Select the FLASH: Chip Select low */
+ sFLASH_CS_LOW();
+ /*!< Send Sector Erase instruction */
+ sFLASH_SendByte(sFLASH_CMD_SE);
+ /*!< Send SectorAddr high nibble address byte */
+ sFLASH_SendByte((SectorAddr & 0xFF0000) >> 16);
+ /*!< Send SectorAddr medium nibble address byte */
+ sFLASH_SendByte((SectorAddr & 0xFF00) >> 8);
+ /*!< Send SectorAddr low nibble address byte */
+ sFLASH_SendByte(SectorAddr & 0xFF);
+ /*!< Deselect the FLASH: Chip Select high */
+ sFLASH_CS_HIGH();
+
+ /*!< Wait the end of Flash writing */
+ sFLASH_WaitForWriteEnd();
+}
+
+/**
+ * @brief Erases the entire FLASH.
+ * @param None
+ * @retval None
+ */
+void sFLASH_EraseBulk(void)
+{
+ /*!< Send write enable instruction */
+ sFLASH_WriteEnable();
+
+ /*!< Bulk Erase */
+ /*!< Select the FLASH: Chip Select low */
+ sFLASH_CS_LOW();
+ /*!< Send Bulk Erase instruction */
+ sFLASH_SendByte(sFLASH_CMD_BE);
+ /*!< Deselect the FLASH: Chip Select high */
+ sFLASH_CS_HIGH();
+
+ /*!< Wait the end of Flash writing */
+ sFLASH_WaitForWriteEnd();
+}
+
+/**
+ * @brief Writes more than one byte to the FLASH with a single WRITE cycle
+ * (Page WRITE sequence).
+ * @note The number of byte can't exceed the FLASH page size.
+ * @param pBuffer: pointer to the buffer containing the data to be written
+ * to the FLASH.
+ * @param WriteAddr: FLASH's internal address to write to.
+ * @param NumByteToWrite: number of bytes to write to the FLASH, must be equal
+ * or less than "sFLASH_PAGESIZE" value.
+ * @retval None
+ */
+void sFLASH_WritePage(uint8_t* pBuffer, uint32_t WriteAddr, uint16_t NumByteToWrite)
+{
+ /*!< Enable the write access to the FLASH */
+ sFLASH_WriteEnable();
+
+ /*!< Select the FLASH: Chip Select low */
+ sFLASH_CS_LOW();
+ /*!< Send "Write to Memory " instruction */
+ sFLASH_SendByte(sFLASH_CMD_WRITE);
+ /*!< Send WriteAddr high nibble address byte to write to */
+ sFLASH_SendByte((WriteAddr & 0xFF0000) >> 16);
+ /*!< Send WriteAddr medium nibble address byte to write to */
+ sFLASH_SendByte((WriteAddr & 0xFF00) >> 8);
+ /*!< Send WriteAddr low nibble address byte to write to */
+ sFLASH_SendByte(WriteAddr & 0xFF);
+
+ /*!< while there is data to be written on the FLASH */
+ while (NumByteToWrite--)
+ {
+ /*!< Send the current byte */
+ sFLASH_SendByte(*pBuffer);
+ /*!< Point on the next byte to be written */
+ pBuffer++;
+ }
+
+ /*!< Deselect the FLASH: Chip Select high */
+ sFLASH_CS_HIGH();
+
+ /*!< Wait the end of Flash writing */
+ sFLASH_WaitForWriteEnd();
+}
+
+/**
+ * @brief Writes block of data to the FLASH. In this function, the number of
+ * WRITE cycles are reduced, using Page WRITE sequence.
+ * @param pBuffer: pointer to the buffer containing the data to be written
+ * to the FLASH.
+ * @param WriteAddr: FLASH's internal address to write to.
+ * @param NumByteToWrite: number of bytes to write to the FLASH.
+ * @retval None
+ */
+void sFLASH_WriteBuffer(uint8_t* pBuffer, uint32_t WriteAddr, uint16_t NumByteToWrite)
+{
+ uint8_t NumOfPage = 0, NumOfSingle = 0, Addr = 0, count = 0, temp = 0;
+
+ Addr = WriteAddr % sFLASH_SPI_PAGESIZE;
+ count = sFLASH_SPI_PAGESIZE - Addr;
+ NumOfPage = NumByteToWrite / sFLASH_SPI_PAGESIZE;
+ NumOfSingle = NumByteToWrite % sFLASH_SPI_PAGESIZE;
+
+ if (Addr == 0) /*!< WriteAddr is sFLASH_PAGESIZE aligned */
+ {
+ if (NumOfPage == 0) /*!< NumByteToWrite < sFLASH_PAGESIZE */
+ {
+ sFLASH_WritePage(pBuffer, WriteAddr, NumByteToWrite);
+ }
+ else /*!< NumByteToWrite > sFLASH_PAGESIZE */
+ {
+ while (NumOfPage--)
+ {
+ sFLASH_WritePage(pBuffer, WriteAddr, sFLASH_SPI_PAGESIZE);
+ WriteAddr += sFLASH_SPI_PAGESIZE;
+ pBuffer += sFLASH_SPI_PAGESIZE;
+ }
+
+ sFLASH_WritePage(pBuffer, WriteAddr, NumOfSingle);
+ }
+ }
+ else /*!< WriteAddr is not sFLASH_PAGESIZE aligned */
+ {
+ if (NumOfPage == 0) /*!< NumByteToWrite < sFLASH_PAGESIZE */
+ {
+ if (NumOfSingle > count) /*!< (NumByteToWrite + WriteAddr) > sFLASH_PAGESIZE */
+ {
+ temp = NumOfSingle - count;
+
+ sFLASH_WritePage(pBuffer, WriteAddr, count);
+ WriteAddr += count;
+ pBuffer += count;
+
+ sFLASH_WritePage(pBuffer, WriteAddr, temp);
+ }
+ else
+ {
+ sFLASH_WritePage(pBuffer, WriteAddr, NumByteToWrite);
+ }
+ }
+ else /*!< NumByteToWrite > sFLASH_PAGESIZE */
+ {
+ NumByteToWrite -= count;
+ NumOfPage = NumByteToWrite / sFLASH_SPI_PAGESIZE;
+ NumOfSingle = NumByteToWrite % sFLASH_SPI_PAGESIZE;
+
+ sFLASH_WritePage(pBuffer, WriteAddr, count);
+ WriteAddr += count;
+ pBuffer += count;
+
+ while (NumOfPage--)
+ {
+ sFLASH_WritePage(pBuffer, WriteAddr, sFLASH_SPI_PAGESIZE);
+ WriteAddr += sFLASH_SPI_PAGESIZE;
+ pBuffer += sFLASH_SPI_PAGESIZE;
+ }
+
+ if (NumOfSingle != 0)
+ {
+ sFLASH_WritePage(pBuffer, WriteAddr, NumOfSingle);
+ }
+ }
+ }
+}
+
+/**
+ * @brief Reads a block of data from the FLASH.
+ * @param pBuffer: pointer to the buffer that receives the data read from the FLASH.
+ * @param ReadAddr: FLASH's internal address to read from.
+ * @param NumByteToRead: number of bytes to read from the FLASH.
+ * @retval None
+ */
+void sFLASH_ReadBuffer(uint8_t* pBuffer, uint32_t ReadAddr, uint16_t NumByteToRead)
+{
+ /*!< Select the FLASH: Chip Select low */
+ sFLASH_CS_LOW();
+
+ /*!< Send "Read from Memory " instruction */
+ sFLASH_SendByte(sFLASH_CMD_READ);
+
+ /*!< Send ReadAddr high nibble address byte to read from */
+ sFLASH_SendByte((ReadAddr & 0xFF0000) >> 16);
+ /*!< Send ReadAddr medium nibble address byte to read from */
+ sFLASH_SendByte((ReadAddr& 0xFF00) >> 8);
+ /*!< Send ReadAddr low nibble address byte to read from */
+ sFLASH_SendByte(ReadAddr & 0xFF);
+
+ while (NumByteToRead--) /*!< while there is data to be read */
+ {
+ /*!< Read a byte from the FLASH */
+ *pBuffer = sFLASH_SendByte(sFLASH_DUMMY_BYTE);
+ /*!< Point to the next location where the byte read will be saved */
+ pBuffer++;
+ }
+
+ /*!< Deselect the FLASH: Chip Select high */
+ sFLASH_CS_HIGH();
+}
+
+/**
+ * @brief Reads FLASH identification.
+ * @param None
+ * @retval FLASH identification
+ */
+uint32_t sFLASH_ReadID(void)
+{
+ uint32_t Temp = 0, Temp0 = 0, Temp1 = 0, Temp2 = 0;
+
+ /*!< Select the FLASH: Chip Select low */
+ sFLASH_CS_LOW();
+
+ /*!< Send "RDID " instruction */
+ sFLASH_SendByte(0x9F);
+
+ /*!< Read a byte from the FLASH */
+ Temp0 = sFLASH_SendByte(sFLASH_DUMMY_BYTE);
+
+ /*!< Read a byte from the FLASH */
+ Temp1 = sFLASH_SendByte(sFLASH_DUMMY_BYTE);
+
+ /*!< Read a byte from the FLASH */
+ Temp2 = sFLASH_SendByte(sFLASH_DUMMY_BYTE);
+
+ /*!< Deselect the FLASH: Chip Select high */
+ sFLASH_CS_HIGH();
+
+ Temp = (Temp0 << 16) | (Temp1 << 8) | Temp2;
+
+ return Temp;
+}
+
+/**
+ * @brief Initiates a read data byte (READ) sequence from the Flash.
+ * This is done by driving the /CS line low to select the device, then the READ
+ * instruction is transmitted followed by 3 bytes address. This function exit
+ * and keep the /CS line low, so the Flash still being selected. With this
+ * technique the whole content of the Flash is read with a single READ instruction.
+ * @param ReadAddr: FLASH's internal address to read from.
+ * @retval None
+ */
+void sFLASH_StartReadSequence(uint32_t ReadAddr)
+{
+ /*!< Select the FLASH: Chip Select low */
+ sFLASH_CS_LOW();
+
+ /*!< Send "Read from Memory " instruction */
+ sFLASH_SendByte(sFLASH_CMD_READ);
+
+ /*!< Send the 24-bit address of the address to read from -------------------*/
+ /*!< Send ReadAddr high nibble address byte */
+ sFLASH_SendByte((ReadAddr & 0xFF0000) >> 16);
+ /*!< Send ReadAddr medium nibble address byte */
+ sFLASH_SendByte((ReadAddr& 0xFF00) >> 8);
+ /*!< Send ReadAddr low nibble address byte */
+ sFLASH_SendByte(ReadAddr & 0xFF);
+}
+
+/**
+ * @brief Reads a byte from the SPI Flash.
+ * @note This function must be used only if the Start_Read_Sequence function
+ * has been previously called.
+ * @param None
+ * @retval Byte Read from the SPI Flash.
+ */
+uint8_t sFLASH_ReadByte(void)
+{
+ return (sFLASH_SendByte(sFLASH_DUMMY_BYTE));
+}
+
+/**
+ * @brief Sends a byte through the SPI interface and return the byte received
+ * from the SPI bus.
+ * @param byte: byte to send.
+ * @retval The value of the received byte.
+ */
+uint8_t sFLASH_SendByte(uint8_t byte)
+{
+ /*!< Loop while DR register in not emplty */
+ while (SPI_I2S_GetFlagStatus(sFLASH_SPI, SPI_I2S_FLAG_TXE) == RESET);
+
+ /*!< Send byte through the SPI1 peripheral */
+ SPI_I2S_SendData(sFLASH_SPI, byte);
+
+ /*!< Wait to receive a byte */
+ while (SPI_I2S_GetFlagStatus(sFLASH_SPI, SPI_I2S_FLAG_RXNE) == RESET);
+
+ /*!< Return the byte read from the SPI bus */
+ return SPI_I2S_ReceiveData(sFLASH_SPI);
+}
+
+/**
+ * @brief Sends a Half Word through the SPI interface and return the Half Word
+ * received from the SPI bus.
+ * @param HalfWord: Half Word to send.
+ * @retval The value of the received Half Word.
+ */
+uint16_t sFLASH_SendHalfWord(uint16_t HalfWord)
+{
+ /*!< Loop while DR register in not emplty */
+ while (SPI_I2S_GetFlagStatus(sFLASH_SPI, SPI_I2S_FLAG_TXE) == RESET);
+
+ /*!< Send Half Word through the sFLASH peripheral */
+ SPI_I2S_SendData(sFLASH_SPI, HalfWord);
+
+ /*!< Wait to receive a Half Word */
+ while (SPI_I2S_GetFlagStatus(sFLASH_SPI, SPI_I2S_FLAG_RXNE) == RESET);
+
+ /*!< Return the Half Word read from the SPI bus */
+ return SPI_I2S_ReceiveData(sFLASH_SPI);
+}
+
+/**
+ * @brief Enables the write access to the FLASH.
+ * @param None
+ * @retval None
+ */
+void sFLASH_WriteEnable(void)
+{
+ /*!< Select the FLASH: Chip Select low */
+ sFLASH_CS_LOW();
+
+ /*!< Send "Write Enable" instruction */
+ sFLASH_SendByte(sFLASH_CMD_WREN);
+
+ /*!< Deselect the FLASH: Chip Select high */
+ sFLASH_CS_HIGH();
+}
+
+/**
+ * @brief Polls the status of the Write In Progress (WIP) flag in the FLASH's
+ * status register and loop until write opertaion has completed.
+ * @param None
+ * @retval None
+ */
+void sFLASH_WaitForWriteEnd(void)
+{
+ uint8_t flashstatus = 0;
+
+ /*!< Select the FLASH: Chip Select low */
+ sFLASH_CS_LOW();
+
+ /*!< Send "Read Status Register" instruction */
+ sFLASH_SendByte(sFLASH_CMD_RDSR);
+
+ /*!< Loop as long as the memory is busy with a write cycle */
+ do
+ {
+ /*!< Send a dummy byte to generate the clock needed by the FLASH
+ and put the value of the status register in FLASH_Status variable */
+ flashstatus = sFLASH_SendByte(sFLASH_DUMMY_BYTE);
+
+ }
+ while ((flashstatus & sFLASH_WIP_FLAG) == SET); /* Write in progress */
+
+ /*!< Deselect the FLASH: Chip Select high */
+ sFLASH_CS_HIGH();
+}
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210B_EVAL/stm3210b_eval_spi_flash.h b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210B_EVAL/stm3210b_eval_spi_flash.h
new file mode 100644
index 0000000..ef3a4cb
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210B_EVAL/stm3210b_eval_spi_flash.h
@@ -0,0 +1,157 @@
+/**
+ ******************************************************************************
+ * @file stm3210b_eval_spi_flash.h
+ * @author MCD Application Team
+ * @version V5.0.1
+ * @date 05-March-2012
+ * @brief This file contains all the functions prototypes for the
+ * stm3210b_eval_spi_flash firmware driver.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.st.com/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __STM3210B_EVAL_SPI_FLASH_H
+#define __STM3210B_EVAL_SPI_FLASH_H
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+/* Includes ------------------------------------------------------------------*/
+#include "stm3210b_eval.h"
+
+/** @addtogroup Utilities
+ * @{
+ */
+
+/** @addtogroup STM32_EVAL
+ * @{
+ */
+
+/** @addtogroup STM3210B_EVAL
+ * @{
+ */
+
+/** @addtogroup STM3210B_EVAL_SPI_FLASH
+ * @{
+ */
+
+/** @defgroup STM3210B_EVAL_SPI_FLASH_Exported_Types
+ * @{
+ */
+/**
+ * @}
+ */
+
+/** @defgroup STM3210B_EVAL_SPI_FLASH_Exported_Constants
+ * @{
+ */
+/**
+ * @brief M25P SPI Flash supported commands
+ */
+#define sFLASH_CMD_WRITE 0x02 /*!< Write to Memory instruction */
+#define sFLASH_CMD_WRSR 0x01 /*!< Write Status Register instruction */
+#define sFLASH_CMD_WREN 0x06 /*!< Write enable instruction */
+#define sFLASH_CMD_READ 0x03 /*!< Read from Memory instruction */
+#define sFLASH_CMD_RDSR 0x05 /*!< Read Status Register instruction */
+#define sFLASH_CMD_RDID 0x9F /*!< Read identification */
+#define sFLASH_CMD_SE 0xD8 /*!< Sector Erase instruction */
+#define sFLASH_CMD_BE 0xC7 /*!< Bulk Erase instruction */
+
+#define sFLASH_WIP_FLAG 0x01 /*!< Write In Progress (WIP) flag */
+
+#define sFLASH_DUMMY_BYTE 0xA5
+#define sFLASH_SPI_PAGESIZE 0x100
+
+#define sFLASH_M25P128_ID 0x202018
+#define sFLASH_M25P64_ID 0x202017
+
+/**
+ * @}
+ */
+
+/** @defgroup STM3210B_EVAL_SPI_FLASH_Exported_Macros
+ * @{
+ */
+/**
+ * @brief Select sFLASH: Chip Select pin low
+ */
+#define sFLASH_CS_LOW() GPIO_ResetBits(sFLASH_CS_GPIO_PORT, sFLASH_CS_PIN)
+/**
+ * @brief Deselect sFLASH: Chip Select pin high
+ */
+#define sFLASH_CS_HIGH() GPIO_SetBits(sFLASH_CS_GPIO_PORT, sFLASH_CS_PIN)
+/**
+ * @}
+ */
+
+
+
+/** @defgroup STM3210B_EVAL_SPI_FLASH_Exported_Functions
+ * @{
+ */
+/**
+ * @brief High layer functions
+ */
+void sFLASH_DeInit(void);
+void sFLASH_Init(void);
+void sFLASH_EraseSector(uint32_t SectorAddr);
+void sFLASH_EraseBulk(void);
+void sFLASH_WritePage(uint8_t* pBuffer, uint32_t WriteAddr, uint16_t NumByteToWrite);
+void sFLASH_WriteBuffer(uint8_t* pBuffer, uint32_t WriteAddr, uint16_t NumByteToWrite);
+void sFLASH_ReadBuffer(uint8_t* pBuffer, uint32_t ReadAddr, uint16_t NumByteToRead);
+uint32_t sFLASH_ReadID(void);
+void sFLASH_StartReadSequence(uint32_t ReadAddr);
+
+/**
+ * @brief Low layer functions
+ */
+uint8_t sFLASH_ReadByte(void);
+uint8_t sFLASH_SendByte(uint8_t byte);
+uint16_t sFLASH_SendHalfWord(uint16_t HalfWord);
+void sFLASH_WriteEnable(void);
+void sFLASH_WaitForWriteEnd(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __STM3210B_EVAL_SPI_FLASH_H */
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210B_EVAL/stm3210b_eval_spi_sd.c b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210B_EVAL/stm3210b_eval_spi_sd.c
new file mode 100644
index 0000000..a672b69
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210B_EVAL/stm3210b_eval_spi_sd.c
@@ -0,0 +1,911 @@
+/**
+ ******************************************************************************
+ * @file stm3210b_eval_spi_sd.c
+ * @author MCD Application Team
+ * @version V5.0.1
+ * @date 05-March-2012
+ * @brief This file provides a set of functions needed to manage the SPI SD
+ * Card memory mounted on STM3210B-EVAL board.
+ * It implements a high level communication layer for read and write
+ * from/to this memory. The needed STM32 hardware resources (SPI and
+ * GPIO) are defined in stm3210b_eval.h file, and the initialization is
+ * performed in SD_LowLevel_Init() function declared in stm3210b_eval.c
+ * file.
+ * You can easily tailor this driver to any other development board,
+ * by just adapting the defines for hardware resources and
+ * SD_LowLevel_Init() function.
+ *
+ * ===================================================================
+ * Note:
+ * - This driver doesn't support SD High Capacity cards.
+ * ===================================================================
+ *
+ * +-------------------------------------------------------+
+ * | Pin assignment |
+ * +-------------------------+---------------+-------------+
+ * | STM32 SPI Pins | SD | Pin |
+ * +-------------------------+---------------+-------------+
+ * | SD_SPI_CS_PIN | ChipSelect | 1 |
+ * | SD_SPI_MOSI_PIN / MOSI | DataIn | 2 |
+ * | | GND | 3 (0 V) |
+ * | | VDD | 4 (3.3 V)|
+ * | SD_SPI_SCK_PIN / SCLK | Clock | 5 |
+ * | | GND | 6 (0 V) |
+ * | SD_SPI_MISO_PIN / MISO | DataOut | 7 |
+ * +-------------------------+---------------+-------------+
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.st.com/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+
+/* Includes ------------------------------------------------------------------*/
+#include "stm3210b_eval_spi_sd.h"
+
+/** @addtogroup Utilities
+ * @{
+ */
+
+/** @addtogroup STM32_EVAL
+ * @{
+ */
+
+/** @addtogroup STM3210B_EVAL
+ * @{
+ */
+
+/** @addtogroup STM3210B_EVAL_SPI_SD
+ * @brief This file includes the SD card driver of STM32-EVAL boards.
+ * @{
+ */
+
+/** @defgroup STM3210B_EVAL_SPI_SD_Private_Types
+ * @{
+ */
+/**
+ * @}
+ */
+
+
+/** @defgroup STM3210B_EVAL_SPI_SD_Private_Defines
+ * @{
+ */
+/**
+ * @}
+ */
+
+/** @defgroup STM3210B_EVAL_SPI_SD_Private_Macros
+ * @{
+ */
+/**
+ * @}
+ */
+
+
+/** @defgroup STM3210B_EVAL_SPI_SD_Private_Variables
+ * @{
+ */
+/**
+ * @}
+ */
+
+
+/** @defgroup STM3210B_EVAL_SPI_SD_Private_Function_Prototypes
+ * @{
+ */
+/**
+ * @}
+ */
+
+
+/** @defgroup STM3210B_EVAL_SPI_SD_Private_Functions
+ * @{
+ */
+
+/**
+ * @brief DeInitializes the SD/SD communication.
+ * @param None
+ * @retval None
+ */
+void SD_DeInit(void)
+{
+ SD_LowLevel_DeInit();
+}
+
+/**
+ * @brief Initializes the SD/SD communication.
+ * @param None
+ * @retval The SD Response:
+ * - SD_RESPONSE_FAILURE: Sequence failed
+ * - SD_RESPONSE_NO_ERROR: Sequence succeed
+ */
+SD_Error SD_Init(void)
+{
+ uint32_t i = 0;
+
+ /*!< Initialize SD_SPI */
+ SD_LowLevel_Init();
+
+ /*!< SD chip select high */
+ SD_CS_HIGH();
+
+ /*!< Send dummy byte 0xFF, 10 times with CS high */
+ /*!< Rise CS and MOSI for 80 clocks cycles */
+ for (i = 0; i <= 9; i++)
+ {
+ /*!< Send dummy byte 0xFF */
+ SD_WriteByte(SD_DUMMY_BYTE);
+ }
+ /*------------Put SD in SPI mode--------------*/
+ /*!< SD initialized and set to SPI mode properly */
+ return (SD_GoIdleState());
+}
+
+/**
+ * @brief Detect if SD card is correctly plugged in the memory slot.
+ * @param None
+ * @retval Return if SD is detected or not
+ */
+uint8_t SD_Detect(void)
+{
+ __IO uint8_t status = SD_PRESENT;
+
+ /*!< Check GPIO to detect SD */
+ if (GPIO_ReadInputData(SD_DETECT_GPIO_PORT) & SD_DETECT_PIN)
+ {
+ status = SD_NOT_PRESENT;
+ }
+ return status;
+}
+
+/**
+ * @brief Returns information about specific card.
+ * @param cardinfo: pointer to a SD_CardInfo structure that contains all SD
+ * card information.
+ * @retval The SD Response:
+ * - SD_RESPONSE_FAILURE: Sequence failed
+ * - SD_RESPONSE_NO_ERROR: Sequence succeed
+ */
+SD_Error SD_GetCardInfo(SD_CardInfo *cardinfo)
+{
+ SD_Error status = SD_RESPONSE_FAILURE;
+
+ status = SD_GetCSDRegister(&(cardinfo->SD_csd));
+ status = SD_GetCIDRegister(&(cardinfo->SD_cid));
+ cardinfo->CardCapacity = (cardinfo->SD_csd.DeviceSize + 1) ;
+ cardinfo->CardCapacity *= (1 << (cardinfo->SD_csd.DeviceSizeMul + 2));
+ cardinfo->CardBlockSize = 1 << (cardinfo->SD_csd.RdBlockLen);
+ cardinfo->CardCapacity *= cardinfo->CardBlockSize;
+
+ /*!< Returns the reponse */
+ return status;
+}
+
+/**
+ * @brief Reads a block of data from the SD.
+ * @param pBuffer: pointer to the buffer that receives the data read from the
+ * SD.
+ * @param ReadAddr: SD's internal address to read from.
+ * @param BlockSize: the SD card Data block size.
+ * @retval The SD Response:
+ * - SD_RESPONSE_FAILURE: Sequence failed
+ * - SD_RESPONSE_NO_ERROR: Sequence succeed
+ */
+SD_Error SD_ReadBlock(uint8_t* pBuffer, uint32_t ReadAddr, uint16_t BlockSize)
+{
+ uint32_t i = 0;
+ SD_Error rvalue = SD_RESPONSE_FAILURE;
+
+ /*!< SD chip select low */
+ SD_CS_LOW();
+
+ /*!< Send CMD17 (SD_CMD_READ_SINGLE_BLOCK) to read one block */
+ SD_SendCmd(SD_CMD_READ_SINGLE_BLOCK, ReadAddr, 0xFF);
+
+ /*!< Check if the SD acknowledged the read block command: R1 response (0x00: no errors) */
+ if (!SD_GetResponse(SD_RESPONSE_NO_ERROR))
+ {
+ /*!< Now look for the data token to signify the start of the data */
+ if (!SD_GetResponse(SD_START_DATA_SINGLE_BLOCK_READ))
+ {
+ /*!< Read the SD block data : read NumByteToRead data */
+ for (i = 0; i < BlockSize; i++)
+ {
+ /*!< Save the received data */
+ *pBuffer = SD_ReadByte();
+
+ /*!< Point to the next location where the byte read will be saved */
+ pBuffer++;
+ }
+ /*!< Get CRC bytes (not really needed by us, but required by SD) */
+ SD_ReadByte();
+ SD_ReadByte();
+ /*!< Set response value to success */
+ rvalue = SD_RESPONSE_NO_ERROR;
+ }
+ }
+ /*!< SD chip select high */
+ SD_CS_HIGH();
+
+ /*!< Send dummy byte: 8 Clock pulses of delay */
+ SD_WriteByte(SD_DUMMY_BYTE);
+
+ /*!< Returns the reponse */
+ return rvalue;
+}
+
+/**
+ * @brief Reads multiple block of data from the SD.
+ * @param pBuffer: pointer to the buffer that receives the data read from the
+ * SD.
+ * @param ReadAddr: SD's internal address to read from.
+ * @param BlockSize: the SD card Data block size.
+ * @param NumberOfBlocks: number of blocks to be read.
+ * @retval The SD Response:
+ * - SD_RESPONSE_FAILURE: Sequence failed
+ * - SD_RESPONSE_NO_ERROR: Sequence succeed
+ */
+SD_Error SD_ReadMultiBlocks(uint8_t* pBuffer, uint32_t ReadAddr, uint16_t BlockSize, uint32_t NumberOfBlocks)
+{
+ uint32_t i = 0, Offset = 0;
+ SD_Error rvalue = SD_RESPONSE_FAILURE;
+
+ /*!< SD chip select low */
+ SD_CS_LOW();
+ /*!< Data transfer */
+ while (NumberOfBlocks--)
+ {
+ /*!< Send CMD17 (SD_CMD_READ_SINGLE_BLOCK) to read one block */
+ SD_SendCmd (SD_CMD_READ_SINGLE_BLOCK, ReadAddr + Offset, 0xFF);
+ /*!< Check if the SD acknowledged the read block command: R1 response (0x00: no errors) */
+ if (SD_GetResponse(SD_RESPONSE_NO_ERROR))
+ {
+ return SD_RESPONSE_FAILURE;
+ }
+ /*!< Now look for the data token to signify the start of the data */
+ if (!SD_GetResponse(SD_START_DATA_SINGLE_BLOCK_READ))
+ {
+ /*!< Read the SD block data : read NumByteToRead data */
+ for (i = 0; i < BlockSize; i++)
+ {
+ /*!< Read the pointed data */
+ *pBuffer = SD_ReadByte();
+ /*!< Point to the next location where the byte read will be saved */
+ pBuffer++;
+ }
+ /*!< Set next read address*/
+ Offset += 512;
+ /*!< get CRC bytes (not really needed by us, but required by SD) */
+ SD_ReadByte();
+ SD_ReadByte();
+ /*!< Set response value to success */
+ rvalue = SD_RESPONSE_NO_ERROR;
+ }
+ else
+ {
+ /*!< Set response value to failure */
+ rvalue = SD_RESPONSE_FAILURE;
+ }
+ }
+ /*!< SD chip select high */
+ SD_CS_HIGH();
+ /*!< Send dummy byte: 8 Clock pulses of delay */
+ SD_WriteByte(SD_DUMMY_BYTE);
+ /*!< Returns the reponse */
+ return rvalue;
+}
+
+/**
+ * @brief Writes a block on the SD
+ * @param pBuffer: pointer to the buffer containing the data to be written on
+ * the SD.
+ * @param WriteAddr: address to write on.
+ * @param BlockSize: the SD card Data block size.
+ * @retval The SD Response:
+ * - SD_RESPONSE_FAILURE: Sequence failed
+ * - SD_RESPONSE_NO_ERROR: Sequence succeed
+ */
+SD_Error SD_WriteBlock(uint8_t* pBuffer, uint32_t WriteAddr, uint16_t BlockSize)
+{
+ uint32_t i = 0;
+ SD_Error rvalue = SD_RESPONSE_FAILURE;
+
+ /*!< SD chip select low */
+ SD_CS_LOW();
+
+ /*!< Send CMD24 (SD_CMD_WRITE_SINGLE_BLOCK) to write multiple block */
+ SD_SendCmd(SD_CMD_WRITE_SINGLE_BLOCK, WriteAddr, 0xFF);
+
+ /*!< Check if the SD acknowledged the write block command: R1 response (0x00: no errors) */
+ if (!SD_GetResponse(SD_RESPONSE_NO_ERROR))
+ {
+ /*!< Send a dummy byte */
+ SD_WriteByte(SD_DUMMY_BYTE);
+
+ /*!< Send the data token to signify the start of the data */
+ SD_WriteByte(0xFE);
+
+ /*!< Write the block data to SD : write count data by block */
+ for (i = 0; i < BlockSize; i++)
+ {
+ /*!< Send the pointed byte */
+ SD_WriteByte(*pBuffer);
+ /*!< Point to the next location where the byte read will be saved */
+ pBuffer++;
+ }
+ /*!< Put CRC bytes (not really needed by us, but required by SD) */
+ SD_ReadByte();
+ SD_ReadByte();
+
+ /*!< Read data response */
+ if (SD_GetDataResponse() == SD_DATA_OK)
+ {
+ rvalue = SD_RESPONSE_NO_ERROR;
+ }
+ }
+ /*!< SD chip select high */
+ SD_CS_HIGH();
+ /*!< Send dummy byte: 8 Clock pulses of delay */
+ SD_WriteByte(SD_DUMMY_BYTE);
+
+ /*!< Returns the reponse */
+ return rvalue;
+}
+
+/**
+ * @brief Writes many blocks on the SD
+ * @param pBuffer: pointer to the buffer containing the data to be written on
+ * the SD.
+ * @param WriteAddr: address to write on.
+ * @param BlockSize: the SD card Data block size.
+ * @param NumberOfBlocks: number of blocks to be written.
+ * @retval The SD Response:
+ * - SD_RESPONSE_FAILURE: Sequence failed
+ * - SD_RESPONSE_NO_ERROR: Sequence succeed
+ */
+SD_Error SD_WriteMultiBlocks(uint8_t* pBuffer, uint32_t WriteAddr, uint16_t BlockSize, uint32_t NumberOfBlocks)
+{
+ uint32_t i = 0, Offset = 0;
+ SD_Error rvalue = SD_RESPONSE_FAILURE;
+
+ /*!< SD chip select low */
+ SD_CS_LOW();
+ /*!< Data transfer */
+ while (NumberOfBlocks--)
+ {
+ /*!< Send CMD24 (SD_CMD_WRITE_SINGLE_BLOCK) to write blocks */
+ SD_SendCmd(SD_CMD_WRITE_SINGLE_BLOCK, WriteAddr + Offset, 0xFF);
+ /*!< Check if the SD acknowledged the write block command: R1 response (0x00: no errors) */
+ if (SD_GetResponse(SD_RESPONSE_NO_ERROR))
+ {
+ return SD_RESPONSE_FAILURE;
+ }
+ /*!< Send dummy byte */
+ SD_WriteByte(SD_DUMMY_BYTE);
+ /*!< Send the data token to signify the start of the data */
+ SD_WriteByte(SD_START_DATA_SINGLE_BLOCK_WRITE);
+ /*!< Write the block data to SD : write count data by block */
+ for (i = 0; i < BlockSize; i++)
+ {
+ /*!< Send the pointed byte */
+ SD_WriteByte(*pBuffer);
+ /*!< Point to the next location where the byte read will be saved */
+ pBuffer++;
+ }
+ /*!< Set next write address */
+ Offset += 512;
+ /*!< Put CRC bytes (not really needed by us, but required by SD) */
+ SD_ReadByte();
+ SD_ReadByte();
+ /*!< Read data response */
+ if (SD_GetDataResponse() == SD_DATA_OK)
+ {
+ /*!< Set response value to success */
+ rvalue = SD_RESPONSE_NO_ERROR;
+ }
+ else
+ {
+ /*!< Set response value to failure */
+ rvalue = SD_RESPONSE_FAILURE;
+ }
+ }
+ /*!< SD chip select high */
+ SD_CS_HIGH();
+ /*!< Send dummy byte: 8 Clock pulses of delay */
+ SD_WriteByte(SD_DUMMY_BYTE);
+ /*!< Returns the reponse */
+ return rvalue;
+}
+
+/**
+ * @brief Read the CSD card register.
+ * Reading the contents of the CSD register in SPI mode is a simple
+ * read-block transaction.
+ * @param SD_csd: pointer on an SCD register structure
+ * @retval The SD Response:
+ * - SD_RESPONSE_FAILURE: Sequence failed
+ * - SD_RESPONSE_NO_ERROR: Sequence succeed
+ */
+SD_Error SD_GetCSDRegister(SD_CSD* SD_csd)
+{
+ uint32_t i = 0;
+ SD_Error rvalue = SD_RESPONSE_FAILURE;
+ uint8_t CSD_Tab[16];
+
+ /*!< SD chip select low */
+ SD_CS_LOW();
+ /*!< Send CMD9 (CSD register) or CMD10(CSD register) */
+ SD_SendCmd(SD_CMD_SEND_CSD, 0, 0xFF);
+ /*!< Wait for response in the R1 format (0x00 is no errors) */
+ if (!SD_GetResponse(SD_RESPONSE_NO_ERROR))
+ {
+ if (!SD_GetResponse(SD_START_DATA_SINGLE_BLOCK_READ))
+ {
+ for (i = 0; i < 16; i++)
+ {
+ /*!< Store CSD register value on CSD_Tab */
+ CSD_Tab[i] = SD_ReadByte();
+ }
+ }
+ /*!< Get CRC bytes (not really needed by us, but required by SD) */
+ SD_WriteByte(SD_DUMMY_BYTE);
+ SD_WriteByte(SD_DUMMY_BYTE);
+ /*!< Set response value to success */
+ rvalue = SD_RESPONSE_NO_ERROR;
+ }
+ /*!< SD chip select high */
+ SD_CS_HIGH();
+ /*!< Send dummy byte: 8 Clock pulses of delay */
+ SD_WriteByte(SD_DUMMY_BYTE);
+
+ /*!< Byte 0 */
+ SD_csd->CSDStruct = (CSD_Tab[0] & 0xC0) >> 6;
+ SD_csd->SysSpecVersion = (CSD_Tab[0] & 0x3C) >> 2;
+ SD_csd->Reserved1 = CSD_Tab[0] & 0x03;
+
+ /*!< Byte 1 */
+ SD_csd->TAAC = CSD_Tab[1];
+
+ /*!< Byte 2 */
+ SD_csd->NSAC = CSD_Tab[2];
+
+ /*!< Byte 3 */
+ SD_csd->MaxBusClkFrec = CSD_Tab[3];
+
+ /*!< Byte 4 */
+ SD_csd->CardComdClasses = CSD_Tab[4] << 4;
+
+ /*!< Byte 5 */
+ SD_csd->CardComdClasses |= (CSD_Tab[5] & 0xF0) >> 4;
+ SD_csd->RdBlockLen = CSD_Tab[5] & 0x0F;
+
+ /*!< Byte 6 */
+ SD_csd->PartBlockRead = (CSD_Tab[6] & 0x80) >> 7;
+ SD_csd->WrBlockMisalign = (CSD_Tab[6] & 0x40) >> 6;
+ SD_csd->RdBlockMisalign = (CSD_Tab[6] & 0x20) >> 5;
+ SD_csd->DSRImpl = (CSD_Tab[6] & 0x10) >> 4;
+ SD_csd->Reserved2 = 0; /*!< Reserved */
+
+ SD_csd->DeviceSize = (CSD_Tab[6] & 0x03) << 10;
+
+ /*!< Byte 7 */
+ SD_csd->DeviceSize |= (CSD_Tab[7]) << 2;
+
+ /*!< Byte 8 */
+ SD_csd->DeviceSize |= (CSD_Tab[8] & 0xC0) >> 6;
+
+ SD_csd->MaxRdCurrentVDDMin = (CSD_Tab[8] & 0x38) >> 3;
+ SD_csd->MaxRdCurrentVDDMax = (CSD_Tab[8] & 0x07);
+
+ /*!< Byte 9 */
+ SD_csd->MaxWrCurrentVDDMin = (CSD_Tab[9] & 0xE0) >> 5;
+ SD_csd->MaxWrCurrentVDDMax = (CSD_Tab[9] & 0x1C) >> 2;
+ SD_csd->DeviceSizeMul = (CSD_Tab[9] & 0x03) << 1;
+ /*!< Byte 10 */
+ SD_csd->DeviceSizeMul |= (CSD_Tab[10] & 0x80) >> 7;
+
+ SD_csd->EraseGrSize = (CSD_Tab[10] & 0x40) >> 6;
+ SD_csd->EraseGrMul = (CSD_Tab[10] & 0x3F) << 1;
+
+ /*!< Byte 11 */
+ SD_csd->EraseGrMul |= (CSD_Tab[11] & 0x80) >> 7;
+ SD_csd->WrProtectGrSize = (CSD_Tab[11] & 0x7F);
+
+ /*!< Byte 12 */
+ SD_csd->WrProtectGrEnable = (CSD_Tab[12] & 0x80) >> 7;
+ SD_csd->ManDeflECC = (CSD_Tab[12] & 0x60) >> 5;
+ SD_csd->WrSpeedFact = (CSD_Tab[12] & 0x1C) >> 2;
+ SD_csd->MaxWrBlockLen = (CSD_Tab[12] & 0x03) << 2;
+
+ /*!< Byte 13 */
+ SD_csd->MaxWrBlockLen |= (CSD_Tab[13] & 0xC0) >> 6;
+ SD_csd->WriteBlockPaPartial = (CSD_Tab[13] & 0x20) >> 5;
+ SD_csd->Reserved3 = 0;
+ SD_csd->ContentProtectAppli = (CSD_Tab[13] & 0x01);
+
+ /*!< Byte 14 */
+ SD_csd->FileFormatGrouop = (CSD_Tab[14] & 0x80) >> 7;
+ SD_csd->CopyFlag = (CSD_Tab[14] & 0x40) >> 6;
+ SD_csd->PermWrProtect = (CSD_Tab[14] & 0x20) >> 5;
+ SD_csd->TempWrProtect = (CSD_Tab[14] & 0x10) >> 4;
+ SD_csd->FileFormat = (CSD_Tab[14] & 0x0C) >> 2;
+ SD_csd->ECC = (CSD_Tab[14] & 0x03);
+
+ /*!< Byte 15 */
+ SD_csd->CSD_CRC = (CSD_Tab[15] & 0xFE) >> 1;
+ SD_csd->Reserved4 = 1;
+
+ /*!< Return the reponse */
+ return rvalue;
+}
+
+/**
+ * @brief Read the CID card register.
+ * Reading the contents of the CID register in SPI mode is a simple
+ * read-block transaction.
+ * @param SD_cid: pointer on an CID register structure
+ * @retval The SD Response:
+ * - SD_RESPONSE_FAILURE: Sequence failed
+ * - SD_RESPONSE_NO_ERROR: Sequence succeed
+ */
+SD_Error SD_GetCIDRegister(SD_CID* SD_cid)
+{
+ uint32_t i = 0;
+ SD_Error rvalue = SD_RESPONSE_FAILURE;
+ uint8_t CID_Tab[16];
+
+ /*!< SD chip select low */
+ SD_CS_LOW();
+
+ /*!< Send CMD10 (CID register) */
+ SD_SendCmd(SD_CMD_SEND_CID, 0, 0xFF);
+
+ /*!< Wait for response in the R1 format (0x00 is no errors) */
+ if (!SD_GetResponse(SD_RESPONSE_NO_ERROR))
+ {
+ if (!SD_GetResponse(SD_START_DATA_SINGLE_BLOCK_READ))
+ {
+ /*!< Store CID register value on CID_Tab */
+ for (i = 0; i < 16; i++)
+ {
+ CID_Tab[i] = SD_ReadByte();
+ }
+ }
+ /*!< Get CRC bytes (not really needed by us, but required by SD) */
+ SD_WriteByte(SD_DUMMY_BYTE);
+ SD_WriteByte(SD_DUMMY_BYTE);
+ /*!< Set response value to success */
+ rvalue = SD_RESPONSE_NO_ERROR;
+ }
+ /*!< SD chip select high */
+ SD_CS_HIGH();
+ /*!< Send dummy byte: 8 Clock pulses of delay */
+ SD_WriteByte(SD_DUMMY_BYTE);
+
+ /*!< Byte 0 */
+ SD_cid->ManufacturerID = CID_Tab[0];
+
+ /*!< Byte 1 */
+ SD_cid->OEM_AppliID = CID_Tab[1] << 8;
+
+ /*!< Byte 2 */
+ SD_cid->OEM_AppliID |= CID_Tab[2];
+
+ /*!< Byte 3 */
+ SD_cid->ProdName1 = CID_Tab[3] << 24;
+
+ /*!< Byte 4 */
+ SD_cid->ProdName1 |= CID_Tab[4] << 16;
+
+ /*!< Byte 5 */
+ SD_cid->ProdName1 |= CID_Tab[5] << 8;
+
+ /*!< Byte 6 */
+ SD_cid->ProdName1 |= CID_Tab[6];
+
+ /*!< Byte 7 */
+ SD_cid->ProdName2 = CID_Tab[7];
+
+ /*!< Byte 8 */
+ SD_cid->ProdRev = CID_Tab[8];
+
+ /*!< Byte 9 */
+ SD_cid->ProdSN = CID_Tab[9] << 24;
+
+ /*!< Byte 10 */
+ SD_cid->ProdSN |= CID_Tab[10] << 16;
+
+ /*!< Byte 11 */
+ SD_cid->ProdSN |= CID_Tab[11] << 8;
+
+ /*!< Byte 12 */
+ SD_cid->ProdSN |= CID_Tab[12];
+
+ /*!< Byte 13 */
+ SD_cid->Reserved1 |= (CID_Tab[13] & 0xF0) >> 4;
+ SD_cid->ManufactDate = (CID_Tab[13] & 0x0F) << 8;
+
+ /*!< Byte 14 */
+ SD_cid->ManufactDate |= CID_Tab[14];
+
+ /*!< Byte 15 */
+ SD_cid->CID_CRC = (CID_Tab[15] & 0xFE) >> 1;
+ SD_cid->Reserved2 = 1;
+
+ /*!< Return the reponse */
+ return rvalue;
+}
+
+/**
+ * @brief Send 5 bytes command to the SD card.
+ * @param Cmd: The user expected command to send to SD card.
+ * @param Arg: The command argument.
+ * @param Crc: The CRC.
+ * @retval None
+ */
+void SD_SendCmd(uint8_t Cmd, uint32_t Arg, uint8_t Crc)
+{
+ uint32_t i = 0x00;
+
+ uint8_t Frame[6];
+
+ Frame[0] = (Cmd | 0x40); /*!< Construct byte 1 */
+
+ Frame[1] = (uint8_t)(Arg >> 24); /*!< Construct byte 2 */
+
+ Frame[2] = (uint8_t)(Arg >> 16); /*!< Construct byte 3 */
+
+ Frame[3] = (uint8_t)(Arg >> 8); /*!< Construct byte 4 */
+
+ Frame[4] = (uint8_t)(Arg); /*!< Construct byte 5 */
+
+ Frame[5] = (Crc); /*!< Construct CRC: byte 6 */
+
+ for (i = 0; i < 6; i++)
+ {
+ SD_WriteByte(Frame[i]); /*!< Send the Cmd bytes */
+ }
+}
+
+/**
+ * @brief Get SD card data response.
+ * @param None
+ * @retval The SD status: Read data response xxx0<status>1
+ * - status 010: Data accecpted
+ * - status 101: Data rejected due to a crc error
+ * - status 110: Data rejected due to a Write error.
+ * - status 111: Data rejected due to other error.
+ */
+uint8_t SD_GetDataResponse(void)
+{
+ uint32_t i = 0;
+ uint8_t response, rvalue;
+
+ while (i <= 64)
+ {
+ /*!< Read resonse */
+ response = SD_ReadByte();
+ /*!< Mask unused bits */
+ response &= 0x1F;
+ switch (response)
+ {
+ case SD_DATA_OK:
+ {
+ rvalue = SD_DATA_OK;
+ break;
+ }
+ case SD_DATA_CRC_ERROR:
+ return SD_DATA_CRC_ERROR;
+ case SD_DATA_WRITE_ERROR:
+ return SD_DATA_WRITE_ERROR;
+ default:
+ {
+ rvalue = SD_DATA_OTHER_ERROR;
+ break;
+ }
+ }
+ /*!< Exit loop in case of data ok */
+ if (rvalue == SD_DATA_OK)
+ break;
+ /*!< Increment loop counter */
+ i++;
+ }
+
+ /*!< Wait null data */
+ while (SD_ReadByte() == 0);
+
+ /*!< Return response */
+ return response;
+}
+
+/**
+ * @brief Returns the SD response.
+ * @param None
+ * @retval The SD Response:
+ * - SD_RESPONSE_FAILURE: Sequence failed
+ * - SD_RESPONSE_NO_ERROR: Sequence succeed
+ */
+SD_Error SD_GetResponse(uint8_t Response)
+{
+ uint32_t Count = 0xFFF;
+
+ /*!< Check if response is got or a timeout is happen */
+ while ((SD_ReadByte() != Response) && Count)
+ {
+ Count--;
+ }
+ if (Count == 0)
+ {
+ /*!< After time out */
+ return SD_RESPONSE_FAILURE;
+ }
+ else
+ {
+ /*!< Right response got */
+ return SD_RESPONSE_NO_ERROR;
+ }
+}
+
+/**
+ * @brief Returns the SD status.
+ * @param None
+ * @retval The SD status.
+ */
+uint16_t SD_GetStatus(void)
+{
+ uint16_t Status = 0;
+
+ /*!< SD chip select low */
+ SD_CS_LOW();
+
+ /*!< Send CMD13 (SD_SEND_STATUS) to get SD status */
+ SD_SendCmd(SD_CMD_SEND_STATUS, 0, 0xFF);
+
+ Status = SD_ReadByte();
+ Status |= (uint16_t)(SD_ReadByte() << 8);
+
+ /*!< SD chip select high */
+ SD_CS_HIGH();
+
+ /*!< Send dummy byte 0xFF */
+ SD_WriteByte(SD_DUMMY_BYTE);
+
+ return Status;
+}
+
+/**
+ * @brief Put SD in Idle state.
+ * @param None
+ * @retval The SD Response:
+ * - SD_RESPONSE_FAILURE: Sequence failed
+ * - SD_RESPONSE_NO_ERROR: Sequence succeed
+ */
+SD_Error SD_GoIdleState(void)
+{
+ /*!< SD chip select low */
+ SD_CS_LOW();
+
+ /*!< Send CMD0 (SD_CMD_GO_IDLE_STATE) to put SD in SPI mode */
+ SD_SendCmd(SD_CMD_GO_IDLE_STATE, 0, 0x95);
+
+ /*!< Wait for In Idle State Response (R1 Format) equal to 0x01 */
+ if (SD_GetResponse(SD_IN_IDLE_STATE))
+ {
+ /*!< No Idle State Response: return response failue */
+ return SD_RESPONSE_FAILURE;
+ }
+ /*----------Activates the card initialization process-----------*/
+ do
+ {
+ /*!< SD chip select high */
+ SD_CS_HIGH();
+
+ /*!< Send Dummy byte 0xFF */
+ SD_WriteByte(SD_DUMMY_BYTE);
+
+ /*!< SD chip select low */
+ SD_CS_LOW();
+
+ /*!< Send CMD1 (Activates the card process) until response equal to 0x0 */
+ SD_SendCmd(SD_CMD_SEND_OP_COND, 0, 0xFF);
+ /*!< Wait for no error Response (R1 Format) equal to 0x00 */
+ }
+ while (SD_GetResponse(SD_RESPONSE_NO_ERROR));
+
+ /*!< SD chip select high */
+ SD_CS_HIGH();
+
+ /*!< Send dummy byte 0xFF */
+ SD_WriteByte(SD_DUMMY_BYTE);
+
+ return SD_RESPONSE_NO_ERROR;
+}
+
+/**
+ * @brief Write a byte on the SD.
+ * @param Data: byte to send.
+ * @retval None
+ */
+uint8_t SD_WriteByte(uint8_t Data)
+{
+ /*!< Wait until the transmit buffer is empty */
+ while(SPI_I2S_GetFlagStatus(SD_SPI, SPI_I2S_FLAG_TXE) == RESET)
+ {
+ }
+
+ /*!< Send the byte */
+ SPI_I2S_SendData(SD_SPI, Data);
+
+ /*!< Wait to receive a byte*/
+ while(SPI_I2S_GetFlagStatus(SD_SPI, SPI_I2S_FLAG_RXNE) == RESET)
+ {
+ }
+
+ /*!< Return the byte read from the SPI bus */
+ return (uint8_t)SPI_I2S_ReceiveData(SD_SPI);
+}
+
+/**
+ * @brief Read a byte from the SD.
+ * @param None
+ * @retval The received byte.
+ */
+uint8_t SD_ReadByte(void)
+{
+ uint8_t Data = 0;
+
+ /*!< Wait until the transmit buffer is empty */
+ while (SPI_I2S_GetFlagStatus(SD_SPI, SPI_I2S_FLAG_TXE) == RESET)
+ {
+ }
+ /*!< Send the byte */
+ SPI_I2S_SendData(SD_SPI, SD_DUMMY_BYTE);
+
+ /*!< Wait until a data is received */
+ while (SPI_I2S_GetFlagStatus(SD_SPI, SPI_I2S_FLAG_RXNE) == RESET)
+ {
+ }
+ /*!< Get the received data */
+ Data = (uint8_t)SPI_I2S_ReceiveData(SD_SPI);
+
+ /*!< Return the shifted data */
+ return Data;
+}
+
+/**
+ * @}
+ */
+
+
+/**
+ * @}
+ */
+
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210B_EVAL/stm3210b_eval_spi_sd.h b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210B_EVAL/stm3210b_eval_spi_sd.h
new file mode 100644
index 0000000..3e9829b
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210B_EVAL/stm3210b_eval_spi_sd.h
@@ -0,0 +1,286 @@
+/**
+ ******************************************************************************
+ * @file stm3210b_eval_spi_sd.h
+ * @author MCD Application Team
+ * @version V5.0.1
+ * @date 05-March-2012
+ * @brief This file contains all the functions prototypes for the
+ * stm3210b_eval_spi_sd firmware driver.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.st.com/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __STM3210B_EVAL_SPI_SD_H
+#define __STM3210B_EVAL_SPI_SD_H
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+/* Includes ------------------------------------------------------------------*/
+#include "stm3210b_eval.h"
+
+/** @addtogroup Utilities
+ * @{
+ */
+
+/** @addtogroup STM32_EVAL
+ * @{
+ */
+
+/** @addtogroup STM3210B_EVAL
+ * @{
+ */
+
+/** @addtogroup STM3210B_EVAL_SPI_SD
+ * @{
+ */
+
+/** @defgroup STM3210B_EVAL_SPI_SD_Exported_Types
+ * @{
+ */
+
+typedef enum
+{
+/**
+ * @brief SD reponses and error flags
+ */
+ SD_RESPONSE_NO_ERROR = (0x00),
+ SD_IN_IDLE_STATE = (0x01),
+ SD_ERASE_RESET = (0x02),
+ SD_ILLEGAL_COMMAND = (0x04),
+ SD_COM_CRC_ERROR = (0x08),
+ SD_ERASE_SEQUENCE_ERROR = (0x10),
+ SD_ADDRESS_ERROR = (0x20),
+ SD_PARAMETER_ERROR = (0x40),
+ SD_RESPONSE_FAILURE = (0xFF),
+
+/**
+ * @brief Data response error
+ */
+ SD_DATA_OK = (0x05),
+ SD_DATA_CRC_ERROR = (0x0B),
+ SD_DATA_WRITE_ERROR = (0x0D),
+ SD_DATA_OTHER_ERROR = (0xFF)
+} SD_Error;
+
+/**
+ * @brief Card Specific Data: CSD Register
+ */
+typedef struct
+{
+ __IO uint8_t CSDStruct; /*!< CSD structure */
+ __IO uint8_t SysSpecVersion; /*!< System specification version */
+ __IO uint8_t Reserved1; /*!< Reserved */
+ __IO uint8_t TAAC; /*!< Data read access-time 1 */
+ __IO uint8_t NSAC; /*!< Data read access-time 2 in CLK cycles */
+ __IO uint8_t MaxBusClkFrec; /*!< Max. bus clock frequency */
+ __IO uint16_t CardComdClasses; /*!< Card command classes */
+ __IO uint8_t RdBlockLen; /*!< Max. read data block length */
+ __IO uint8_t PartBlockRead; /*!< Partial blocks for read allowed */
+ __IO uint8_t WrBlockMisalign; /*!< Write block misalignment */
+ __IO uint8_t RdBlockMisalign; /*!< Read block misalignment */
+ __IO uint8_t DSRImpl; /*!< DSR implemented */
+ __IO uint8_t Reserved2; /*!< Reserved */
+ __IO uint32_t DeviceSize; /*!< Device Size */
+ __IO uint8_t MaxRdCurrentVDDMin; /*!< Max. read current @ VDD min */
+ __IO uint8_t MaxRdCurrentVDDMax; /*!< Max. read current @ VDD max */
+ __IO uint8_t MaxWrCurrentVDDMin; /*!< Max. write current @ VDD min */
+ __IO uint8_t MaxWrCurrentVDDMax; /*!< Max. write current @ VDD max */
+ __IO uint8_t DeviceSizeMul; /*!< Device size multiplier */
+ __IO uint8_t EraseGrSize; /*!< Erase group size */
+ __IO uint8_t EraseGrMul; /*!< Erase group size multiplier */
+ __IO uint8_t WrProtectGrSize; /*!< Write protect group size */
+ __IO uint8_t WrProtectGrEnable; /*!< Write protect group enable */
+ __IO uint8_t ManDeflECC; /*!< Manufacturer default ECC */
+ __IO uint8_t WrSpeedFact; /*!< Write speed factor */
+ __IO uint8_t MaxWrBlockLen; /*!< Max. write data block length */
+ __IO uint8_t WriteBlockPaPartial; /*!< Partial blocks for write allowed */
+ __IO uint8_t Reserved3; /*!< Reserded */
+ __IO uint8_t ContentProtectAppli; /*!< Content protection application */
+ __IO uint8_t FileFormatGrouop; /*!< File format group */
+ __IO uint8_t CopyFlag; /*!< Copy flag (OTP) */
+ __IO uint8_t PermWrProtect; /*!< Permanent write protection */
+ __IO uint8_t TempWrProtect; /*!< Temporary write protection */
+ __IO uint8_t FileFormat; /*!< File Format */
+ __IO uint8_t ECC; /*!< ECC code */
+ __IO uint8_t CSD_CRC; /*!< CSD CRC */
+ __IO uint8_t Reserved4; /*!< always 1*/
+} SD_CSD;
+
+/**
+ * @brief Card Identification Data: CID Register
+ */
+typedef struct
+{
+ __IO uint8_t ManufacturerID; /*!< ManufacturerID */
+ __IO uint16_t OEM_AppliID; /*!< OEM/Application ID */
+ __IO uint32_t ProdName1; /*!< Product Name part1 */
+ __IO uint8_t ProdName2; /*!< Product Name part2*/
+ __IO uint8_t ProdRev; /*!< Product Revision */
+ __IO uint32_t ProdSN; /*!< Product Serial Number */
+ __IO uint8_t Reserved1; /*!< Reserved1 */
+ __IO uint16_t ManufactDate; /*!< Manufacturing Date */
+ __IO uint8_t CID_CRC; /*!< CID CRC */
+ __IO uint8_t Reserved2; /*!< always 1 */
+} SD_CID;
+
+/**
+ * @brief SD Card information
+ */
+typedef struct
+{
+ SD_CSD SD_csd;
+ SD_CID SD_cid;
+ uint32_t CardCapacity; /*!< Card Capacity */
+ uint32_t CardBlockSize; /*!< Card Block Size */
+} SD_CardInfo;
+
+/**
+ * @}
+ */
+
+/** @defgroup STM3210B_EVAL_SPI_SD_Exported_Constants
+ * @{
+ */
+
+/**
+ * @brief Block Size
+ */
+#define SD_BLOCK_SIZE 0x200
+
+/**
+ * @brief Dummy byte
+ */
+#define SD_DUMMY_BYTE 0xFF
+
+/**
+ * @brief Start Data tokens:
+ * Tokens (necessary because at nop/idle (and CS active) only 0xff is
+ * on the data/command line)
+ */
+#define SD_START_DATA_SINGLE_BLOCK_READ 0xFE /*!< Data token start byte, Start Single Block Read */
+#define SD_START_DATA_MULTIPLE_BLOCK_READ 0xFE /*!< Data token start byte, Start Multiple Block Read */
+#define SD_START_DATA_SINGLE_BLOCK_WRITE 0xFE /*!< Data token start byte, Start Single Block Write */
+#define SD_START_DATA_MULTIPLE_BLOCK_WRITE 0xFD /*!< Data token start byte, Start Multiple Block Write */
+#define SD_STOP_DATA_MULTIPLE_BLOCK_WRITE 0xFD /*!< Data toke stop byte, Stop Multiple Block Write */
+
+/**
+ * @brief SD detection on its memory slot
+ */
+#define SD_PRESENT ((uint8_t)0x01)
+#define SD_NOT_PRESENT ((uint8_t)0x00)
+
+
+/**
+ * @brief Commands: CMDxx = CMD-number | 0x40
+ */
+#define SD_CMD_GO_IDLE_STATE 0 /*!< CMD0 = 0x40 */
+#define SD_CMD_SEND_OP_COND 1 /*!< CMD1 = 0x41 */
+#define SD_CMD_SEND_CSD 9 /*!< CMD9 = 0x49 */
+#define SD_CMD_SEND_CID 10 /*!< CMD10 = 0x4A */
+#define SD_CMD_STOP_TRANSMISSION 12 /*!< CMD12 = 0x4C */
+#define SD_CMD_SEND_STATUS 13 /*!< CMD13 = 0x4D */
+#define SD_CMD_SET_BLOCKLEN 16 /*!< CMD16 = 0x50 */
+#define SD_CMD_READ_SINGLE_BLOCK 17 /*!< CMD17 = 0x51 */
+#define SD_CMD_READ_MULT_BLOCK 18 /*!< CMD18 = 0x52 */
+#define SD_CMD_SET_BLOCK_COUNT 23 /*!< CMD23 = 0x57 */
+#define SD_CMD_WRITE_SINGLE_BLOCK 24 /*!< CMD24 = 0x58 */
+#define SD_CMD_WRITE_MULT_BLOCK 25 /*!< CMD25 = 0x59 */
+#define SD_CMD_PROG_CSD 27 /*!< CMD27 = 0x5B */
+#define SD_CMD_SET_WRITE_PROT 28 /*!< CMD28 = 0x5C */
+#define SD_CMD_CLR_WRITE_PROT 29 /*!< CMD29 = 0x5D */
+#define SD_CMD_SEND_WRITE_PROT 30 /*!< CMD30 = 0x5E */
+#define SD_CMD_SD_ERASE_GRP_START 32 /*!< CMD32 = 0x60 */
+#define SD_CMD_SD_ERASE_GRP_END 33 /*!< CMD33 = 0x61 */
+#define SD_CMD_UNTAG_SECTOR 34 /*!< CMD34 = 0x62 */
+#define SD_CMD_ERASE_GRP_START 35 /*!< CMD35 = 0x63 */
+#define SD_CMD_ERASE_GRP_END 36 /*!< CMD36 = 0x64 */
+#define SD_CMD_UNTAG_ERASE_GROUP 37 /*!< CMD37 = 0x65 */
+#define SD_CMD_ERASE 38 /*!< CMD38 = 0x66 */
+
+/**
+ * @}
+ */
+
+/** @defgroup STM3210B_EVAL_SPI_SD_Exported_Macros
+ * @{
+ */
+/**
+ * @brief Select SD Card: ChipSelect pin low
+ */
+#define SD_CS_LOW() GPIO_ResetBits(SD_CS_GPIO_PORT, SD_CS_PIN)
+/**
+ * @brief Deselect SD Card: ChipSelect pin high
+ */
+#define SD_CS_HIGH() GPIO_SetBits(SD_CS_GPIO_PORT, SD_CS_PIN)
+/**
+ * @}
+ */
+
+/** @defgroup STM3210B_EVAL_SPI_SD_Exported_Functions
+ * @{
+ */
+void SD_DeInit(void);
+SD_Error SD_Init(void);
+uint8_t SD_Detect(void);
+SD_Error SD_GetCardInfo(SD_CardInfo *cardinfo);
+SD_Error SD_ReadBlock(uint8_t* pBuffer, uint32_t ReadAddr, uint16_t BlockSize);
+SD_Error SD_ReadMultiBlocks(uint8_t* pBuffer, uint32_t ReadAddr, uint16_t BlockSize, uint32_t NumberOfBlocks);
+SD_Error SD_WriteBlock(uint8_t* pBuffer, uint32_t WriteAddr, uint16_t BlockSize);
+SD_Error SD_WriteMultiBlocks(uint8_t* pBuffer, uint32_t WriteAddr, uint16_t BlockSize, uint32_t NumberOfBlocks);
+SD_Error SD_GetCSDRegister(SD_CSD* SD_csd);
+SD_Error SD_GetCIDRegister(SD_CID* SD_cid);
+
+void SD_SendCmd(uint8_t Cmd, uint32_t Arg, uint8_t Crc);
+SD_Error SD_GetResponse(uint8_t Response);
+uint8_t SD_GetDataResponse(void);
+SD_Error SD_GoIdleState(void);
+uint16_t SD_GetStatus(void);
+
+uint8_t SD_WriteByte(uint8_t byte);
+uint8_t SD_ReadByte(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __STM3210B_EVAL_SPI_SD_H */
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210E_EVAL/stm3210e_eval.c b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210E_EVAL/stm3210e_eval.c
new file mode 100644
index 0000000..e7495f7
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210E_EVAL/stm3210e_eval.c
@@ -0,0 +1,677 @@
+/**
+ ******************************************************************************
+ * @file stm3210e_eval.c
+ * @author MCD Application Team
+ * @version V5.1.0
+ * @date 18-January-2013
+ * @brief This file provides
+ * - set of firmware functions to manage Leds, push-button and COM ports
+ * - low level initialization functions for SD card (on SDIO), SPI serial
+ * flash (sFLASH) and temperature sensor (LM75)
+ * available on STM3210E-EVAL evaluation board from STMicroelectronics.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2013 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.st.com/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+
+/* Includes ------------------------------------------------------------------*/
+#include "stm3210e_eval.h"
+#include "stm32f10x_spi.h"
+#include "stm32f10x_i2c.h"
+#include "stm32f10x_sdio.h"
+#include "stm32f10x_dma.h"
+
+/** @addtogroup Utilities
+ * @{
+ */
+
+/** @addtogroup STM32_EVAL
+ * @{
+ */
+
+/** @addtogroup STM3210E_EVAL
+ * @{
+ */
+
+/** @defgroup STM3210E_EVAL_LOW_LEVEL
+ * @brief This file provides firmware functions to manage Leds, push-buttons,
+ * COM ports, SD card on SDIO, serial flash (sFLASH), serial EEPROM (sEE)
+ * and temperature sensor (LM75) available on STM3210E-EVAL evaluation
+ * board from STMicroelectronics.
+ * @{
+ */
+
+/** @defgroup STM3210E_EVAL_LOW_LEVEL_Private_TypesDefinitions
+ * @{
+ */
+/**
+ * @}
+ */
+
+
+/** @defgroup STM3210E_EVAL_LOW_LEVEL_Private_Defines
+ * @{
+ */
+/**
+ * @}
+ */
+
+
+/** @defgroup STM3210E_EVAL_LOW_LEVEL_Private_Macros
+ * @{
+ */
+/**
+ * @}
+ */
+
+
+/** @defgroup STM3210E_EVAL_LOW_LEVEL_Private_Variables
+ * @{
+ */
+GPIO_TypeDef* GPIO_PORT[LEDn] = {LED1_GPIO_PORT, LED2_GPIO_PORT, LED3_GPIO_PORT,
+ LED4_GPIO_PORT};
+const uint16_t GPIO_PIN[LEDn] = {LED1_PIN, LED2_PIN, LED3_PIN,
+ LED4_PIN};
+const uint32_t GPIO_CLK[LEDn] = {LED1_GPIO_CLK, LED2_GPIO_CLK, LED3_GPIO_CLK,
+ LED4_GPIO_CLK};
+
+GPIO_TypeDef* BUTTON_PORT[BUTTONn] = {WAKEUP_BUTTON_GPIO_PORT, TAMPER_BUTTON_GPIO_PORT,
+ KEY_BUTTON_GPIO_PORT, RIGHT_BUTTON_GPIO_PORT,
+ LEFT_BUTTON_GPIO_PORT, UP_BUTTON_GPIO_PORT,
+ DOWN_BUTTON_GPIO_PORT, SEL_BUTTON_GPIO_PORT};
+
+const uint16_t BUTTON_PIN[BUTTONn] = {WAKEUP_BUTTON_PIN, TAMPER_BUTTON_PIN,
+ KEY_BUTTON_PIN, RIGHT_BUTTON_PIN,
+ LEFT_BUTTON_PIN, UP_BUTTON_PIN,
+ DOWN_BUTTON_PIN, SEL_BUTTON_PIN};
+
+const uint32_t BUTTON_CLK[BUTTONn] = {WAKEUP_BUTTON_GPIO_CLK, TAMPER_BUTTON_GPIO_CLK,
+ KEY_BUTTON_GPIO_CLK, RIGHT_BUTTON_GPIO_CLK,
+ LEFT_BUTTON_GPIO_CLK, UP_BUTTON_GPIO_CLK,
+ DOWN_BUTTON_GPIO_CLK, SEL_BUTTON_GPIO_CLK};
+
+const uint16_t BUTTON_EXTI_LINE[BUTTONn] = {WAKEUP_BUTTON_EXTI_LINE,
+ TAMPER_BUTTON_EXTI_LINE,
+ KEY_BUTTON_EXTI_LINE,
+ RIGHT_BUTTON_EXTI_LINE,
+ LEFT_BUTTON_EXTI_LINE,
+ UP_BUTTON_EXTI_LINE,
+ DOWN_BUTTON_EXTI_LINE,
+ SEL_BUTTON_EXTI_LINE};
+
+const uint16_t BUTTON_PORT_SOURCE[BUTTONn] = {WAKEUP_BUTTON_EXTI_PORT_SOURCE,
+ TAMPER_BUTTON_EXTI_PORT_SOURCE,
+ KEY_BUTTON_EXTI_PORT_SOURCE,
+ RIGHT_BUTTON_EXTI_PORT_SOURCE,
+ LEFT_BUTTON_EXTI_PORT_SOURCE,
+ UP_BUTTON_EXTI_PORT_SOURCE,
+ DOWN_BUTTON_EXTI_PORT_SOURCE,
+ SEL_BUTTON_EXTI_PORT_SOURCE};
+
+const uint16_t BUTTON_PIN_SOURCE[BUTTONn] = {WAKEUP_BUTTON_EXTI_PIN_SOURCE,
+ TAMPER_BUTTON_EXTI_PIN_SOURCE,
+ KEY_BUTTON_EXTI_PIN_SOURCE,
+ RIGHT_BUTTON_EXTI_PIN_SOURCE,
+ LEFT_BUTTON_EXTI_PIN_SOURCE,
+ UP_BUTTON_EXTI_PIN_SOURCE,
+ DOWN_BUTTON_EXTI_PIN_SOURCE,
+ SEL_BUTTON_EXTI_PIN_SOURCE};
+
+const uint16_t BUTTON_IRQn[BUTTONn] = {WAKEUP_BUTTON_EXTI_IRQn, TAMPER_BUTTON_EXTI_IRQn,
+ KEY_BUTTON_EXTI_IRQn, RIGHT_BUTTON_EXTI_IRQn,
+ LEFT_BUTTON_EXTI_IRQn, UP_BUTTON_EXTI_IRQn,
+ DOWN_BUTTON_EXTI_IRQn, SEL_BUTTON_EXTI_IRQn};
+
+USART_TypeDef* COM_USART[COMn] = {EVAL_COM1, EVAL_COM2};
+
+GPIO_TypeDef* COM_TX_PORT[COMn] = {EVAL_COM1_TX_GPIO_PORT, EVAL_COM2_TX_GPIO_PORT};
+
+GPIO_TypeDef* COM_RX_PORT[COMn] = {EVAL_COM1_RX_GPIO_PORT, EVAL_COM2_RX_GPIO_PORT};
+
+const uint32_t COM_USART_CLK[COMn] = {EVAL_COM1_CLK, EVAL_COM2_CLK};
+
+const uint32_t COM_TX_PORT_CLK[COMn] = {EVAL_COM1_TX_GPIO_CLK, EVAL_COM2_TX_GPIO_CLK};
+
+const uint32_t COM_RX_PORT_CLK[COMn] = {EVAL_COM1_RX_GPIO_CLK, EVAL_COM2_RX_GPIO_CLK};
+
+const uint16_t COM_TX_PIN[COMn] = {EVAL_COM1_TX_PIN, EVAL_COM2_TX_PIN};
+
+const uint16_t COM_RX_PIN[COMn] = {EVAL_COM1_RX_PIN, EVAL_COM2_RX_PIN};
+
+/**
+ * @}
+ */
+
+
+/** @defgroup STM3210E_EVAL_LOW_LEVEL_Private_FunctionPrototypes
+ * @{
+ */
+
+/**
+ * @}
+ */
+
+
+/** @defgroup STM3210E_EVAL_LOW_LEVEL_Private_Functions
+ * @{
+ */
+
+/**
+ * @brief Configures LED GPIO.
+ * @param Led: Specifies the Led to be configured.
+ * This parameter can be one of following parameters:
+ * @arg LED1
+ * @arg LED2
+ * @arg LED3
+ * @arg LED4
+ * @retval None
+ */
+void STM_EVAL_LEDInit(Led_TypeDef Led)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+
+ /* Enable the GPIO_LED Clock */
+ RCC_APB2PeriphClockCmd(GPIO_CLK[Led], ENABLE);
+
+ /* Configure the GPIO_LED pin */
+ GPIO_InitStructure.GPIO_Pin = GPIO_PIN[Led];
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
+
+ GPIO_Init(GPIO_PORT[Led], &GPIO_InitStructure);
+}
+
+/**
+ * @brief Turns selected LED On.
+ * @param Led: Specifies the Led to be set on.
+ * This parameter can be one of following parameters:
+ * @arg LED1
+ * @arg LED2
+ * @arg LED3
+ * @arg LED4
+ * @retval None
+ */
+void STM_EVAL_LEDOn(Led_TypeDef Led)
+{
+ GPIO_PORT[Led]->BSRR = GPIO_PIN[Led];
+}
+
+/**
+ * @brief Turns selected LED Off.
+ * @param Led: Specifies the Led to be set off.
+ * This parameter can be one of following parameters:
+ * @arg LED1
+ * @arg LED2
+ * @arg LED3
+ * @arg LED4
+ * @retval None
+ */
+void STM_EVAL_LEDOff(Led_TypeDef Led)
+{
+ GPIO_PORT[Led]->BRR = GPIO_PIN[Led];
+}
+
+/**
+ * @brief Toggles the selected LED.
+ * @param Led: Specifies the Led to be toggled.
+ * This parameter can be one of following parameters:
+ * @arg LED1
+ * @arg LED2
+ * @arg LED3
+ * @arg LED4
+ * @retval None
+ */
+void STM_EVAL_LEDToggle(Led_TypeDef Led)
+{
+ GPIO_PORT[Led]->ODR ^= GPIO_PIN[Led];
+}
+
+/**
+ * @brief Configures Button GPIO and EXTI Line.
+ * @param Button: Specifies the Button to be configured.
+ * This parameter can be one of following parameters:
+ * @arg BUTTON_WAKEUP: Wakeup Push Button
+ * @arg BUTTON_TAMPER: Tamper Push Button
+ * @arg BUTTON_KEY: Key Push Button
+ * @arg BUTTON_RIGHT: Joystick Right Push Button
+ * @arg BUTTON_LEFT: Joystick Left Push Button
+ * @arg BUTTON_UP: Joystick Up Push Button
+ * @arg BUTTON_DOWN: Joystick Down Push Button
+ * @arg BUTTON_SEL: Joystick Sel Push Button
+ * @param Button_Mode: Specifies Button mode.
+ * This parameter can be one of following parameters:
+ * @arg BUTTON_MODE_GPIO: Button will be used as simple IO
+ * @arg BUTTON_MODE_EXTI: Button will be connected to EXTI line with interrupt
+ * generation capability
+ * @retval None
+ */
+void STM_EVAL_PBInit(Button_TypeDef Button, ButtonMode_TypeDef Button_Mode)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+ EXTI_InitTypeDef EXTI_InitStructure;
+ NVIC_InitTypeDef NVIC_InitStructure;
+
+ /* Enable the BUTTON Clock */
+ RCC_APB2PeriphClockCmd(BUTTON_CLK[Button] | RCC_APB2Periph_AFIO, ENABLE);
+
+ /* Configure Button pin as input floating */
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
+ GPIO_InitStructure.GPIO_Pin = BUTTON_PIN[Button];
+ GPIO_Init(BUTTON_PORT[Button], &GPIO_InitStructure);
+
+
+ if (Button_Mode == BUTTON_MODE_EXTI)
+ {
+ /* Connect Button EXTI Line to Button GPIO Pin */
+ GPIO_EXTILineConfig(BUTTON_PORT_SOURCE[Button], BUTTON_PIN_SOURCE[Button]);
+
+ /* Configure Button EXTI line */
+ EXTI_InitStructure.EXTI_Line = BUTTON_EXTI_LINE[Button];
+ EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
+
+ if(Button != BUTTON_WAKEUP)
+ {
+ EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
+ }
+ else
+ {
+ EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
+ }
+ EXTI_InitStructure.EXTI_LineCmd = ENABLE;
+ EXTI_Init(&EXTI_InitStructure);
+
+ /* Enable and set Button EXTI Interrupt to the lowest priority */
+ NVIC_InitStructure.NVIC_IRQChannel = BUTTON_IRQn[Button];
+ NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F;
+ NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;
+ NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
+
+ NVIC_Init(&NVIC_InitStructure);
+ }
+}
+
+/**
+ * @brief Returns the selected Button state.
+ * @param Button: Specifies the Button to be checked.
+ * This parameter can be one of following parameters:
+ * @arg BUTTON_WAKEUP: Wakeup Push Button
+ * @arg BUTTON_TAMPER: Tamper Push Button
+ * @arg BUTTON_KEY: Key Push Button
+ * @arg BUTTON_RIGHT: Joystick Right Push Button
+ * @arg BUTTON_LEFT: Joystick Left Push Button
+ * @arg BUTTON_UP: Joystick Up Push Button
+ * @arg BUTTON_DOWN: Joystick Down Push Button
+ * @arg BUTTON_SEL: Joystick Sel Push Button
+ * @retval The Button GPIO pin value.
+ */
+uint32_t STM_EVAL_PBGetState(Button_TypeDef Button)
+{
+ return GPIO_ReadInputDataBit(BUTTON_PORT[Button], BUTTON_PIN[Button]);
+}
+
+/**
+ * @brief Configures COM port.
+ * @param COM: Specifies the COM port to be configured.
+ * This parameter can be one of following parameters:
+ * @arg COM1
+ * @arg COM2
+ * @param USART_InitStruct: pointer to a USART_InitTypeDef structure that
+ * contains the configuration information for the specified USART peripheral.
+ * @retval None
+ */
+void STM_EVAL_COMInit(COM_TypeDef COM, USART_InitTypeDef* USART_InitStruct)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+
+ /* Enable GPIO clock */
+ RCC_APB2PeriphClockCmd(COM_TX_PORT_CLK[COM] | COM_RX_PORT_CLK[COM] | RCC_APB2Periph_AFIO, ENABLE);
+
+ /* Enable UART clock */
+ if (COM == COM1)
+ {
+ RCC_APB2PeriphClockCmd(COM_USART_CLK[COM], ENABLE);
+ }
+ else
+ {
+ RCC_APB1PeriphClockCmd(COM_USART_CLK[COM], ENABLE);
+ }
+
+ /* Configure USART Tx as alternate function push-pull */
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
+ GPIO_InitStructure.GPIO_Pin = COM_TX_PIN[COM];
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
+ GPIO_Init(COM_TX_PORT[COM], &GPIO_InitStructure);
+
+ /* Configure USART Rx as input floating */
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
+ GPIO_InitStructure.GPIO_Pin = COM_RX_PIN[COM];
+ GPIO_Init(COM_RX_PORT[COM], &GPIO_InitStructure);
+
+ /* USART configuration */
+ USART_Init(COM_USART[COM], USART_InitStruct);
+
+ /* Enable USART */
+ USART_Cmd(COM_USART[COM], ENABLE);
+}
+
+/**
+ * @brief DeInitializes the SDIO interface.
+ * @param None
+ * @retval None
+ */
+void SD_LowLevel_DeInit(void)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+
+ /*!< Disable SDIO Clock */
+ SDIO_ClockCmd(DISABLE);
+
+ /*!< Set Power State to OFF */
+ SDIO_SetPowerState(SDIO_PowerState_OFF);
+
+ /*!< DeInitializes the SDIO peripheral */
+ SDIO_DeInit();
+
+ /*!< Disable the SDIO AHB Clock */
+ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_SDIO, DISABLE);
+
+ /*!< Configure PC.08, PC.09, PC.10, PC.11, PC.12 pin: D0, D1, D2, D3, CLK pin */
+ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
+ GPIO_Init(GPIOC, &GPIO_InitStructure);
+
+ /*!< Configure PD.02 CMD line */
+ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
+ GPIO_Init(GPIOD, &GPIO_InitStructure);
+}
+
+/**
+ * @brief Initializes the SD Card and put it into StandBy State (Ready for
+ * data transfer).
+ * @param None
+ * @retval None
+ */
+void SD_LowLevel_Init(void)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+
+ /*!< GPIOC and GPIOD Periph clock enable */
+ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD | SD_DETECT_GPIO_CLK, ENABLE);
+
+ /*!< Configure PC.08, PC.09, PC.10, PC.11, PC.12 pin: D0, D1, D2, D3, CLK pin */
+ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
+ GPIO_Init(GPIOC, &GPIO_InitStructure);
+
+ /*!< Configure PD.02 CMD line */
+ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
+ GPIO_Init(GPIOD, &GPIO_InitStructure);
+
+ /*!< Configure SD_SPI_DETECT_PIN pin: SD Card detect pin */
+ GPIO_InitStructure.GPIO_Pin = SD_DETECT_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
+ GPIO_Init(SD_DETECT_GPIO_PORT, &GPIO_InitStructure);
+
+ /*!< Enable the SDIO AHB Clock */
+ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_SDIO, ENABLE);
+
+ /*!< Enable the DMA2 Clock */
+ RCC_AHBPeriphClockCmd(SD_SDIO_DMA_CLK, ENABLE);
+}
+
+/**
+ * @brief Configures the DMA2 Channel4 for SDIO Tx request.
+ * @param BufferSRC: pointer to the source buffer
+ * @param BufferSize: buffer size
+ * @retval None
+ */
+void SD_LowLevel_DMA_TxConfig(uint32_t *BufferSRC, uint32_t BufferSize)
+{
+
+ DMA_InitTypeDef DMA_InitStructure;
+
+ DMA_ClearFlag(SD_SDIO_DMA_FLAG_TC | SD_SDIO_DMA_FLAG_TE | SD_SDIO_DMA_FLAG_HT | SD_SDIO_DMA_FLAG_GL);
+
+ /*!< DMA2 Channel4 disable */
+ DMA_Cmd(SD_SDIO_DMA_CHANNEL, DISABLE);
+
+ /*!< SDIO DMA CHANNEL Config */
+ DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)SDIO_FIFO_ADDRESS;
+ DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)BufferSRC;
+ DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
+ DMA_InitStructure.DMA_BufferSize = BufferSize / 4;
+ DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
+ DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
+ DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word;
+ DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word;
+ DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
+ DMA_InitStructure.DMA_Priority = DMA_Priority_High;
+ DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
+ DMA_Init(SD_SDIO_DMA_CHANNEL, &DMA_InitStructure);
+
+ DMA_ITConfig(SD_SDIO_DMA_CHANNEL, DMA_IT_TC, ENABLE);
+
+ /*!< SDIO DMA CHANNEL enable */
+ DMA_Cmd(SD_SDIO_DMA_CHANNEL, ENABLE);
+}
+
+/**
+ * @brief Configures the DMA2 Channel4 for SDIO Rx request.
+ * @param BufferDST: pointer to the destination buffer
+ * @param BufferSize: buffer size
+ * @retval None
+ */
+void SD_LowLevel_DMA_RxConfig(uint32_t *BufferDST, uint32_t BufferSize)
+{
+ DMA_InitTypeDef DMA_InitStructure;
+
+ DMA_ClearFlag(SD_SDIO_DMA_FLAG_TC | SD_SDIO_DMA_FLAG_TE | SD_SDIO_DMA_FLAG_HT | SD_SDIO_DMA_FLAG_GL);
+
+ /*!< SDIO DMA CHANNEL disable */
+ DMA_Cmd(SD_SDIO_DMA_CHANNEL, DISABLE);
+
+ /*!< SDIO DMA CHANNEL Config */
+ DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)SDIO_FIFO_ADDRESS;
+ DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)BufferDST;
+ DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
+ DMA_InitStructure.DMA_BufferSize = BufferSize / 4;
+ DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
+ DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
+ DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word;
+ DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word;
+ DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
+ DMA_InitStructure.DMA_Priority = DMA_Priority_High;
+ DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
+ DMA_Init(SD_SDIO_DMA_CHANNEL, &DMA_InitStructure);
+
+ DMA_ITConfig(SD_SDIO_DMA_CHANNEL, DMA_IT_TC, ENABLE);
+
+ /*!< SDIO DMA CHANNEL enable */
+ DMA_Cmd(SD_SDIO_DMA_CHANNEL, ENABLE);
+}
+
+/**
+ * @brief Returns the DMA End Of Transfer Status.
+ * @param None
+ * @retval DMA SDIO Channel Status.
+ */
+uint32_t SD_DMAEndOfTransferStatus(void)
+{
+ return (uint32_t)DMA_GetFlagStatus(DMA2_FLAG_TC4);
+}
+
+/**
+ * @brief DeInitializes the peripherals used by the SPI FLASH driver.
+ * @param None
+ * @retval None
+ */
+void sFLASH_LowLevel_DeInit(void)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+
+ /*!< Disable the sFLASH_SPI */
+ SPI_Cmd(sFLASH_SPI, DISABLE);
+
+ /*!< DeInitializes the sFLASH_SPI */
+ SPI_I2S_DeInit(sFLASH_SPI);
+
+ /*!< sFLASH_SPI Periph clock disable */
+ RCC_APB2PeriphClockCmd(sFLASH_SPI_CLK, DISABLE);
+
+ /*!< Configure sFLASH_SPI pins: SCK */
+ GPIO_InitStructure.GPIO_Pin = sFLASH_SPI_SCK_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
+ GPIO_Init(sFLASH_SPI_SCK_GPIO_PORT, &GPIO_InitStructure);
+
+ /*!< Configure sFLASH_SPI pins: MISO */
+ GPIO_InitStructure.GPIO_Pin = sFLASH_SPI_MISO_PIN;
+ GPIO_Init(sFLASH_SPI_MISO_GPIO_PORT, &GPIO_InitStructure);
+
+ /*!< Configure sFLASH_SPI pins: MOSI */
+ GPIO_InitStructure.GPIO_Pin = sFLASH_SPI_MOSI_PIN;
+ GPIO_Init(sFLASH_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure);
+
+ /*!< Configure sFLASH_CS_PIN pin: sFLASH Card CS pin */
+ GPIO_InitStructure.GPIO_Pin = sFLASH_CS_PIN;
+ GPIO_Init(sFLASH_CS_GPIO_PORT, &GPIO_InitStructure);
+}
+
+/**
+ * @brief Initializes the peripherals used by the SPI FLASH driver.
+ * @param None
+ * @retval None
+ */
+void sFLASH_LowLevel_Init(void)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+
+ /*!< sFLASH_SPI_CS_GPIO, sFLASH_SPI_MOSI_GPIO, sFLASH_SPI_MISO_GPIO
+ and sFLASH_SPI_SCK_GPIO Periph clock enable */
+ RCC_APB2PeriphClockCmd(sFLASH_CS_GPIO_CLK | sFLASH_SPI_MOSI_GPIO_CLK | sFLASH_SPI_MISO_GPIO_CLK |
+ sFLASH_SPI_SCK_GPIO_CLK, ENABLE);
+
+ /*!< sFLASH_SPI Periph clock enable */
+ RCC_APB2PeriphClockCmd(sFLASH_SPI_CLK, ENABLE);
+
+ /*!< Configure sFLASH_SPI pins: SCK */
+ GPIO_InitStructure.GPIO_Pin = sFLASH_SPI_SCK_PIN;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
+ GPIO_Init(sFLASH_SPI_SCK_GPIO_PORT, &GPIO_InitStructure);
+
+ /*!< Configure sFLASH_SPI pins: MOSI */
+ GPIO_InitStructure.GPIO_Pin = sFLASH_SPI_MOSI_PIN;
+ GPIO_Init(sFLASH_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure);
+
+ /*!< Configure sFLASH_SPI pins: MISO */
+ GPIO_InitStructure.GPIO_Pin = sFLASH_SPI_MISO_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
+ GPIO_Init(sFLASH_SPI_MISO_GPIO_PORT, &GPIO_InitStructure);
+
+ /*!< Configure sFLASH_CS_PIN pin: sFLASH Card CS pin */
+ GPIO_InitStructure.GPIO_Pin = sFLASH_CS_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
+ GPIO_Init(sFLASH_CS_GPIO_PORT, &GPIO_InitStructure);
+}
+
+/**
+ * @brief DeInitializes the LM75_I2C.
+ * @param None
+ * @retval None
+ */
+void LM75_LowLevel_DeInit(void)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+
+ /*!< Disable LM75_I2C */
+ I2C_Cmd(LM75_I2C, DISABLE);
+ /*!< DeInitializes the LM75_I2C */
+ I2C_DeInit(LM75_I2C);
+
+ /*!< LM75_I2C Periph clock disable */
+ RCC_APB1PeriphClockCmd(LM75_I2C_CLK, DISABLE);
+
+ /*!< Configure LM75_I2C pins: SCL */
+ GPIO_InitStructure.GPIO_Pin = LM75_I2C_SCL_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
+ GPIO_Init(LM75_I2C_SCL_GPIO_PORT, &GPIO_InitStructure);
+
+ /*!< Configure LM75_I2C pins: SDA */
+ GPIO_InitStructure.GPIO_Pin = LM75_I2C_SDA_PIN;
+ GPIO_Init(LM75_I2C_SDA_GPIO_PORT, &GPIO_InitStructure);
+
+ /*!< Configure LM75_I2C pin: SMBUS ALERT */
+ GPIO_InitStructure.GPIO_Pin = LM75_I2C_SMBUSALERT_PIN;
+ GPIO_Init(LM75_I2C_SMBUSALERT_GPIO_PORT, &GPIO_InitStructure);
+}
+
+/**
+ * @brief Initializes the LM75_I2C..
+ * @param None
+ * @retval None
+ */
+void LM75_LowLevel_Init(void)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+
+ /*!< LM75_I2C Periph clock enable */
+ RCC_APB1PeriphClockCmd(LM75_I2C_CLK, ENABLE);
+
+ /*!< LM75_I2C_SCL_GPIO_CLK, LM75_I2C_SDA_GPIO_CLK
+ and LM75_I2C_SMBUSALERT_GPIO_CLK Periph clock enable */
+ RCC_APB2PeriphClockCmd(LM75_I2C_SCL_GPIO_CLK | LM75_I2C_SDA_GPIO_CLK |
+ LM75_I2C_SMBUSALERT_GPIO_CLK, ENABLE);
+
+ /*!< Configure LM75_I2C pins: SCL */
+ GPIO_InitStructure.GPIO_Pin = LM75_I2C_SCL_PIN;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD;
+ GPIO_Init(LM75_I2C_SCL_GPIO_PORT, &GPIO_InitStructure);
+
+ /*!< Configure LM75_I2C pins: SDA */
+ GPIO_InitStructure.GPIO_Pin = LM75_I2C_SDA_PIN;
+ GPIO_Init(LM75_I2C_SDA_GPIO_PORT, &GPIO_InitStructure);
+
+ /*!< Configure LM75_I2C pin: SMBUS ALERT */
+ GPIO_InitStructure.GPIO_Pin = LM75_I2C_SMBUSALERT_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
+ GPIO_Init(LM75_I2C_SMBUSALERT_GPIO_PORT, &GPIO_InitStructure);
+}
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210E_EVAL/stm3210e_eval.h b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210E_EVAL/stm3210e_eval.h
new file mode 100644
index 0000000..1f9fbe0
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210E_EVAL/stm3210e_eval.h
@@ -0,0 +1,407 @@
+/**
+ ******************************************************************************
+ * @file stm3210e_eval.h
+ * @author MCD Application Team
+ * @version V5.1.0
+ * @date 18-January-2013
+ * @brief This file contains definitions for STM3210E_EVAL's Leds, push-buttons
+ * COM ports, sFLASH (on SPI) and Temperature Sensor LM75 (on I2C)
+ * hardware resources.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2013 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.st.com/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __STM3210E_EVAL_H
+#define __STM3210E_EVAL_H
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+/* Includes ------------------------------------------------------------------*/
+#include "stm32f10x.h"
+#include "stm32_eval_legacy.h"
+
+/** @addtogroup Utilities
+ * @{
+ */
+
+/** @addtogroup STM32_EVAL
+ * @{
+ */
+
+/** @addtogroup STM3210E_EVAL
+ * @{
+ */
+
+/** @addtogroup STM3210E_EVAL_LOW_LEVEL
+ * @{
+ */
+
+/** @defgroup STM3210E_EVAL_LOW_LEVEL_Exported_Types
+ * @{
+ */
+typedef enum
+{
+ LED1 = 0,
+ LED2 = 1,
+ LED3 = 2,
+ LED4 = 3
+} Led_TypeDef;
+
+typedef enum
+{
+ BUTTON_WAKEUP = 0,
+ BUTTON_TAMPER = 1,
+ BUTTON_KEY = 2,
+ BUTTON_RIGHT = 3,
+ BUTTON_LEFT = 4,
+ BUTTON_UP = 5,
+ BUTTON_DOWN = 6,
+ BUTTON_SEL = 7
+} Button_TypeDef;
+
+typedef enum
+{
+ BUTTON_MODE_GPIO = 0,
+ BUTTON_MODE_EXTI = 1
+} ButtonMode_TypeDef;
+
+typedef enum
+{
+ JOY_NONE = 0,
+ JOY_SEL = 1,
+ JOY_DOWN = 2,
+ JOY_LEFT = 3,
+ JOY_RIGHT = 4,
+ JOY_UP = 5
+} JOYState_TypeDef
+;
+
+typedef enum
+{
+ COM1 = 0,
+ COM2 = 1
+} COM_TypeDef;
+/**
+ * @}
+ */
+
+/** @defgroup STM3210E_EVAL_LOW_LEVEL_Exported_Constants
+ * @{
+ */
+/**
+ * @brief Define for STM3210E_EVAL board
+ */
+#if !defined (USE_STM3210E_EVAL)
+ #define USE_STM3210E_EVAL
+#endif
+
+/** @addtogroup STM3210E_EVAL_LOW_LEVEL_LED
+ * @{
+ */
+#define LEDn 4
+
+#define LED1_PIN GPIO_Pin_6
+#define LED1_GPIO_PORT GPIOF
+#define LED1_GPIO_CLK RCC_APB2Periph_GPIOF
+
+#define LED2_PIN GPIO_Pin_7
+#define LED2_GPIO_PORT GPIOF
+#define LED2_GPIO_CLK RCC_APB2Periph_GPIOF
+
+#define LED3_PIN GPIO_Pin_8
+#define LED3_GPIO_PORT GPIOF
+#define LED3_GPIO_CLK RCC_APB2Periph_GPIOF
+
+#define LED4_PIN GPIO_Pin_9
+#define LED4_GPIO_PORT GPIOF
+#define LED4_GPIO_CLK RCC_APB2Periph_GPIOF
+
+/**
+ * @}
+ */
+
+/** @addtogroup STM3210E_EVAL_LOW_LEVEL_BUTTON
+ * @{
+ */
+#define BUTTONn 8
+
+/**
+ * @brief Wakeup push-button
+ */
+#define WAKEUP_BUTTON_PIN GPIO_Pin_0
+#define WAKEUP_BUTTON_GPIO_PORT GPIOA
+#define WAKEUP_BUTTON_GPIO_CLK RCC_APB2Periph_GPIOA
+#define WAKEUP_BUTTON_EXTI_LINE EXTI_Line0
+#define WAKEUP_BUTTON_EXTI_PORT_SOURCE GPIO_PortSourceGPIOA
+#define WAKEUP_BUTTON_EXTI_PIN_SOURCE GPIO_PinSource0
+#define WAKEUP_BUTTON_EXTI_IRQn EXTI0_IRQn
+/**
+ * @brief Tamper push-button
+ */
+#define TAMPER_BUTTON_PIN GPIO_Pin_13
+#define TAMPER_BUTTON_GPIO_PORT GPIOC
+#define TAMPER_BUTTON_GPIO_CLK RCC_APB2Periph_GPIOC
+#define TAMPER_BUTTON_EXTI_LINE EXTI_Line13
+#define TAMPER_BUTTON_EXTI_PORT_SOURCE GPIO_PortSourceGPIOC
+#define TAMPER_BUTTON_EXTI_PIN_SOURCE GPIO_PinSource13
+#define TAMPER_BUTTON_EXTI_IRQn EXTI15_10_IRQn
+/**
+ * @brief Key push-button
+ */
+#define KEY_BUTTON_PIN GPIO_Pin_8
+#define KEY_BUTTON_GPIO_PORT GPIOG
+#define KEY_BUTTON_GPIO_CLK RCC_APB2Periph_GPIOG
+#define KEY_BUTTON_EXTI_LINE EXTI_Line8
+#define KEY_BUTTON_EXTI_PORT_SOURCE GPIO_PortSourceGPIOG
+#define KEY_BUTTON_EXTI_PIN_SOURCE GPIO_PinSource8
+#define KEY_BUTTON_EXTI_IRQn EXTI9_5_IRQn
+/**
+ * @brief Joystick Right push-button
+ */
+#define RIGHT_BUTTON_PIN GPIO_Pin_13
+#define RIGHT_BUTTON_GPIO_PORT GPIOG
+#define RIGHT_BUTTON_GPIO_CLK RCC_APB2Periph_GPIOG
+#define RIGHT_BUTTON_EXTI_LINE EXTI_Line13
+#define RIGHT_BUTTON_EXTI_PORT_SOURCE GPIO_PortSourceGPIOG
+#define RIGHT_BUTTON_EXTI_PIN_SOURCE GPIO_PinSource13
+#define RIGHT_BUTTON_EXTI_IRQn EXTI15_10_IRQn
+/**
+ * @brief Joystick Left push-button
+ */
+#define LEFT_BUTTON_PIN GPIO_Pin_14
+#define LEFT_BUTTON_GPIO_PORT GPIOG
+#define LEFT_BUTTON_GPIO_CLK RCC_APB2Periph_GPIOG
+#define LEFT_BUTTON_EXTI_LINE EXTI_Line14
+#define LEFT_BUTTON_EXTI_PORT_SOURCE GPIO_PortSourceGPIOG
+#define LEFT_BUTTON_EXTI_PIN_SOURCE GPIO_PinSource14
+#define LEFT_BUTTON_EXTI_IRQn EXTI15_10_IRQn
+/**
+ * @brief Joystick Up push-button
+ */
+#define UP_BUTTON_PIN GPIO_Pin_15
+#define UP_BUTTON_GPIO_PORT GPIOG
+#define UP_BUTTON_GPIO_CLK RCC_APB2Periph_GPIOG
+#define UP_BUTTON_EXTI_LINE EXTI_Line15
+#define UP_BUTTON_EXTI_PORT_SOURCE GPIO_PortSourceGPIOG
+#define UP_BUTTON_EXTI_PIN_SOURCE GPIO_PinSource15
+#define UP_BUTTON_EXTI_IRQn EXTI15_10_IRQn
+/**
+ * @brief Joystick Down push-button
+ */
+#define DOWN_BUTTON_PIN GPIO_Pin_3
+#define DOWN_BUTTON_GPIO_PORT GPIOD
+#define DOWN_BUTTON_GPIO_CLK RCC_APB2Periph_GPIOD
+#define DOWN_BUTTON_EXTI_LINE EXTI_Line3
+#define DOWN_BUTTON_EXTI_PORT_SOURCE GPIO_PortSourceGPIOD
+#define DOWN_BUTTON_EXTI_PIN_SOURCE GPIO_PinSource3
+#define DOWN_BUTTON_EXTI_IRQn EXTI3_IRQn
+/**
+ * @brief Joystick Sel push-button
+ */
+#define SEL_BUTTON_PIN GPIO_Pin_7
+#define SEL_BUTTON_GPIO_PORT GPIOG
+#define SEL_BUTTON_GPIO_CLK RCC_APB2Periph_GPIOG
+#define SEL_BUTTON_EXTI_LINE EXTI_Line7
+#define SEL_BUTTON_EXTI_PORT_SOURCE GPIO_PortSourceGPIOG
+#define SEL_BUTTON_EXTI_PIN_SOURCE GPIO_PinSource7
+#define SEL_BUTTON_EXTI_IRQn EXTI9_5_IRQn
+/**
+ * @}
+ */
+
+/** @addtogroup STM3210E_EVAL_LOW_LEVEL_COM
+ * @{
+ */
+#define COMn 2
+
+/**
+ * @brief Definition for COM port1, connected to USART1
+ */
+#define EVAL_COM1 USART1
+#define EVAL_COM1_CLK RCC_APB2Periph_USART1
+#define EVAL_COM1_TX_PIN GPIO_Pin_9
+#define EVAL_COM1_TX_GPIO_PORT GPIOA
+#define EVAL_COM1_TX_GPIO_CLK RCC_APB2Periph_GPIOA
+#define EVAL_COM1_RX_PIN GPIO_Pin_10
+#define EVAL_COM1_RX_GPIO_PORT GPIOA
+#define EVAL_COM1_RX_GPIO_CLK RCC_APB2Periph_GPIOA
+#define EVAL_COM1_IRQn USART1_IRQn
+
+/**
+ * @brief Definition for COM port2, connected to USART2
+ */
+#define EVAL_COM2 USART2
+#define EVAL_COM2_CLK RCC_APB1Periph_USART2
+#define EVAL_COM2_TX_PIN GPIO_Pin_2
+#define EVAL_COM2_TX_GPIO_PORT GPIOA
+#define EVAL_COM2_TX_GPIO_CLK RCC_APB2Periph_GPIOA
+#define EVAL_COM2_RX_PIN GPIO_Pin_3
+#define EVAL_COM2_RX_GPIO_PORT GPIOA
+#define EVAL_COM2_RX_GPIO_CLK RCC_APB2Periph_GPIOA
+#define EVAL_COM2_IRQn USART2_IRQn
+
+/**
+ * @}
+ */
+
+/** @addtogroup STM3210E_EVAL_LOW_LEVEL_SD_FLASH
+ * @{
+ */
+/**
+ * @brief SD FLASH SDIO Interface
+ */
+
+#define SD_DETECT_PIN GPIO_Pin_11 /* PF.11 */
+#define SD_DETECT_GPIO_PORT GPIOF /* GPIOF */
+#define SD_DETECT_GPIO_CLK RCC_APB2Periph_GPIOF
+
+#define SDIO_FIFO_ADDRESS ((uint32_t)0x40018080)
+/**
+ * @brief SDIO Intialization Frequency (400KHz max)
+ */
+#define SDIO_INIT_CLK_DIV ((uint8_t)0xB2)
+/**
+ * @brief SDIO Data Transfer Frequency (25MHz max)
+ */
+#define SDIO_TRANSFER_CLK_DIV ((uint8_t)0x01)
+
+#define SD_SDIO_DMA DMA2
+#define SD_SDIO_DMA_CLK RCC_AHBPeriph_DMA2
+#define SD_SDIO_DMA_CHANNEL DMA2_Channel4
+#define SD_SDIO_DMA_FLAG_TC DMA2_FLAG_TC4
+#define SD_SDIO_DMA_FLAG_TE DMA2_FLAG_TE4
+#define SD_SDIO_DMA_FLAG_HT DMA2_FLAG_HT4
+#define SD_SDIO_DMA_FLAG_GL DMA2_FLAG_GL4
+#define SD_SDIO_DMA_IRQn DMA2_Channel4_5_IRQn
+#define SD_SDIO_DMA_IRQHANDLER DMA2_Channel4_5_IRQHandler
+
+/**
+ * @}
+ */
+
+/** @addtogroup STM3210E_EVAL_LOW_LEVEL_M25P_FLASH_SPI
+ * @{
+ */
+/**
+ * @brief M25P FLASH SPI Interface pins
+ */
+#define sFLASH_SPI SPI1
+#define sFLASH_SPI_CLK RCC_APB2Periph_SPI1
+#define sFLASH_SPI_SCK_PIN GPIO_Pin_5 /* PA.05 */
+#define sFLASH_SPI_SCK_GPIO_PORT GPIOA /* GPIOA */
+#define sFLASH_SPI_SCK_GPIO_CLK RCC_APB2Periph_GPIOA
+#define sFLASH_SPI_MISO_PIN GPIO_Pin_6 /* PA.06 */
+#define sFLASH_SPI_MISO_GPIO_PORT GPIOA /* GPIOA */
+#define sFLASH_SPI_MISO_GPIO_CLK RCC_APB2Periph_GPIOA
+#define sFLASH_SPI_MOSI_PIN GPIO_Pin_7 /* PA.07 */
+#define sFLASH_SPI_MOSI_GPIO_PORT GPIOA /* GPIOA */
+#define sFLASH_SPI_MOSI_GPIO_CLK RCC_APB2Periph_GPIOA
+#define sFLASH_CS_PIN GPIO_Pin_2 /* PB.02 */
+#define sFLASH_CS_GPIO_PORT GPIOB /* GPIOB */
+#define sFLASH_CS_GPIO_CLK RCC_APB2Periph_GPIOB
+
+/**
+ * @}
+ */
+
+/** @addtogroup STM3210E_EVAL_LOW_LEVEL_TSENSOR_I2C
+ * @{
+ */
+/**
+ * @brief LM75 Temperature Sensor I2C Interface pins
+ */
+#define LM75_I2C I2C1
+#define LM75_I2C_CLK RCC_APB1Periph_I2C1
+#define LM75_I2C_SCL_PIN GPIO_Pin_6 /* PB.06 */
+#define LM75_I2C_SCL_GPIO_PORT GPIOB /* GPIOB */
+#define LM75_I2C_SCL_GPIO_CLK RCC_APB2Periph_GPIOB
+#define LM75_I2C_SDA_PIN GPIO_Pin_7 /* PB.07 */
+#define LM75_I2C_SDA_GPIO_PORT GPIOB /* GPIOB */
+#define LM75_I2C_SDA_GPIO_CLK RCC_APB2Periph_GPIOB
+#define LM75_I2C_SMBUSALERT_PIN GPIO_Pin_5 /* PB.05 */
+#define LM75_I2C_SMBUSALERT_GPIO_PORT GPIOB /* GPIOB */
+#define LM75_I2C_SMBUSALERT_GPIO_CLK RCC_APB2Periph_GPIOB
+#define LM75_I2C_DR ((uint32_t)0x40005410)
+
+#define LM75_DMA_CLK RCC_AHBPeriph_DMA1
+#define LM75_DMA_TX_CHANNEL DMA1_Channel6
+#define LM75_DMA_RX_CHANNEL DMA1_Channel7
+#define LM75_DMA_TX_TCFLAG DMA1_FLAG_TC6
+#define LM75_DMA_RX_TCFLAG DMA1_FLAG_TC7
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/** @defgroup STM3210E_EVAL_LOW_LEVEL_Exported_Macros
+ * @{
+ */
+/**
+ * @}
+ */
+
+/** @defgroup STM3210E_EVAL_LOW_LEVEL_Exported_Functions
+ * @{
+ */
+void STM_EVAL_LEDInit(Led_TypeDef Led);
+void STM_EVAL_LEDOn(Led_TypeDef Led);
+void STM_EVAL_LEDOff(Led_TypeDef Led);
+void STM_EVAL_LEDToggle(Led_TypeDef Led);
+void STM_EVAL_PBInit(Button_TypeDef Button, ButtonMode_TypeDef Button_Mode);
+uint32_t STM_EVAL_PBGetState(Button_TypeDef Button);
+void STM_EVAL_COMInit(COM_TypeDef COM, USART_InitTypeDef* USART_InitStruct);
+void SD_LowLevel_DeInit(void);
+void SD_LowLevel_Init(void);
+void SD_LowLevel_DMA_TxConfig(uint32_t *BufferSRC, uint32_t BufferSize);
+void SD_LowLevel_DMA_RxConfig(uint32_t *BufferDST, uint32_t BufferSize);
+void sFLASH_LowLevel_DeInit(void);
+void sFLASH_LowLevel_Init(void);
+void LM75_LowLevel_DeInit(void);
+void LM75_LowLevel_Init(void);
+/**
+ * @}
+ */
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __STM3210E_EVAL_H */
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210E_EVAL/stm3210e_eval_fsmc_nand.c b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210E_EVAL/stm3210e_eval_fsmc_nand.c
new file mode 100644
index 0000000..8d19219
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210E_EVAL/stm3210e_eval_fsmc_nand.c
@@ -0,0 +1,552 @@
+/**
+ ******************************************************************************
+ * @file stm3210e_eval_fsmc_nand.c
+ * @author MCD Application Team
+ * @version V5.1.0
+ * @date 18-January-2013
+ * @brief This file provides a set of functions needed to drive the
+ * NAND512W3A2 memory mounted on STM3210E-EVAL board.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2013 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.st.com/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+
+/* Includes ------------------------------------------------------------------*/
+#include "stm3210e_eval_fsmc_nand.h"
+
+/** @addtogroup Utilities
+ * @{
+ */
+
+/** @addtogroup STM32_EVAL
+ * @{
+ */
+
+/** @addtogroup STM3210E_EVAL
+ * @{
+ */
+
+/** @addtogroup STM3210E_EVAL_FSMC_NAND
+ * @brief This file provides a set of functions needed to drive the
+ * NAND512W3A2 memory mounted on STM3210E-EVAL board.
+ * @{
+ */
+
+/** @defgroup STM3210E_EVAL_FSMC_NAND_Private_Types
+ * @{
+ */
+/**
+ * @}
+ */
+
+
+/** @defgroup STM3210E_EVAL_FSMC_NAND_Private_Defines
+ * @{
+ */
+/**
+ * @brief FSMC Bank 2
+ */
+#define FSMC_Bank_NAND FSMC_Bank2_NAND
+#define Bank_NAND_ADDR Bank2_NAND_ADDR
+#define Bank2_NAND_ADDR ((uint32_t)0x70000000)
+/**
+ * @}
+ */
+
+/** @defgroup STM3210E_EVAL_FSMC_NAND_Private_Macros
+ * @{
+ */
+#define ROW_ADDRESS (Address.Page + (Address.Block + (Address.Zone * NAND_ZONE_SIZE)) * NAND_BLOCK_SIZE)
+/**
+ * @}
+ */
+
+
+/** @defgroup STM3210E_EVAL_FSMC_NAND_Private_Variables
+ * @{
+ */
+/**
+ * @}
+ */
+
+
+/** @defgroup STM3210E_EVAL_FSMC_NAND_Private_Function_Prototypes
+ * @{
+ */
+/**
+ * @}
+ */
+
+
+/** @defgroup STM3210E_EVAL_FSMC_NAND_Private_Functions
+ * @{
+ */
+
+/**
+ * @brief Configures the FSMC and GPIOs to interface with the NAND memory.
+ * This function must be called before any write/read operation on the
+ * NAND.
+ * @param None
+ * @retval None
+ */
+void NAND_Init(void)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+ FSMC_NANDInitTypeDef FSMC_NANDInitStructure;
+ FSMC_NAND_PCCARDTimingInitTypeDef p;
+
+ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE |
+ RCC_APB2Periph_GPIOF | RCC_APB2Periph_GPIOG, ENABLE);
+
+/*-- GPIO Configuration ------------------------------------------------------*/
+/*!< CLE, ALE, D0->D3, NOE, NWE and NCE2 NAND pin configuration */
+ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_14 | GPIO_Pin_15 |
+ GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_4 | GPIO_Pin_5 |
+ GPIO_Pin_7;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
+
+ GPIO_Init(GPIOD, &GPIO_InitStructure);
+
+/*!< D4->D7 NAND pin configuration */
+ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10;
+
+ GPIO_Init(GPIOE, &GPIO_InitStructure);
+
+
+/*!< NWAIT NAND pin configuration */
+ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
+
+ GPIO_Init(GPIOD, &GPIO_InitStructure);
+
+/*!< INT2 NAND pin configuration */
+ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
+ GPIO_Init(GPIOG, &GPIO_InitStructure);
+
+ /*-- FSMC Configuration ------------------------------------------------------*/
+ p.FSMC_SetupTime = 0x0;
+ p.FSMC_WaitSetupTime = 0x2;
+ p.FSMC_HoldSetupTime = 0x1;
+ p.FSMC_HiZSetupTime = 0x0;
+
+ FSMC_NANDInitStructure.FSMC_Bank = FSMC_Bank2_NAND;
+ FSMC_NANDInitStructure.FSMC_Waitfeature = FSMC_Waitfeature_Enable;
+ FSMC_NANDInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_8b;
+ FSMC_NANDInitStructure.FSMC_ECC = FSMC_ECC_Enable;
+ FSMC_NANDInitStructure.FSMC_ECCPageSize = FSMC_ECCPageSize_512Bytes;
+ FSMC_NANDInitStructure.FSMC_TCLRSetupTime = 0x00;
+ FSMC_NANDInitStructure.FSMC_TARSetupTime = 0x00;
+ FSMC_NANDInitStructure.FSMC_CommonSpaceTimingStruct = &p;
+ FSMC_NANDInitStructure.FSMC_AttributeSpaceTimingStruct = &p;
+
+ FSMC_NANDInit(&FSMC_NANDInitStructure);
+
+ /*!< FSMC NAND Bank Cmd Test */
+ FSMC_NANDCmd(FSMC_Bank2_NAND, ENABLE);
+}
+
+/**
+ * @brief Reads NAND memory's ID.
+ * @param NAND_ID: pointer to a NAND_IDTypeDef structure which will hold
+ * the Manufacturer and Device ID.
+ * @retval None
+ */
+void NAND_ReadID(NAND_IDTypeDef* NAND_ID)
+{
+ uint32_t data = 0;
+
+ /*!< Send Command to the command area */
+ *(__IO uint8_t *)(Bank_NAND_ADDR | CMD_AREA) = 0x90;
+ *(__IO uint8_t *)(Bank_NAND_ADDR | ADDR_AREA) = 0x00;
+
+ /*!< Sequence to read ID from NAND flash */
+ data = *(__IO uint32_t *)(Bank_NAND_ADDR | DATA_AREA);
+
+ NAND_ID->Maker_ID = ADDR_1st_CYCLE (data);
+ NAND_ID->Device_ID = ADDR_2nd_CYCLE (data);
+ NAND_ID->Third_ID = ADDR_3rd_CYCLE (data);
+ NAND_ID->Fourth_ID = ADDR_4th_CYCLE (data);
+}
+
+/**
+ * @brief This routine is for writing one or several 512 Bytes Page size.
+ * @param pBuffer: pointer on the Buffer containing data to be written
+ * @param Address: First page address
+ * @param NumPageToWrite: Number of page to write
+ * @retval New status of the NAND operation. This parameter can be:
+ * - NAND_TIMEOUT_ERROR: when the previous operation generate
+ * a Timeout error
+ * - NAND_READY: when memory is ready for the next operation
+ * And the new status of the increment address operation. It can be:
+ * - NAND_VALID_ADDRESS: When the new address is valid address
+ * - NAND_INVALID_ADDRESS: When the new address is invalid address
+ */
+uint32_t NAND_WriteSmallPage(uint8_t *pBuffer, NAND_ADDRESS Address, uint32_t NumPageToWrite)
+{
+ uint32_t index = 0x00, numpagewritten = 0x00, addressstatus = NAND_VALID_ADDRESS;
+ uint32_t status = NAND_READY, size = 0x00;
+
+ while((NumPageToWrite != 0x00) && (addressstatus == NAND_VALID_ADDRESS) && (status == NAND_READY))
+ {
+ /*!< Page write command and address */
+ *(__IO uint8_t *)(Bank_NAND_ADDR | CMD_AREA) = NAND_CMD_AREA_A;
+ *(__IO uint8_t *)(Bank_NAND_ADDR | CMD_AREA) = NAND_CMD_WRITE0;
+
+ *(__IO uint8_t *)(Bank_NAND_ADDR | ADDR_AREA) = 0x00;
+ *(__IO uint8_t *)(Bank_NAND_ADDR | ADDR_AREA) = ADDR_1st_CYCLE(ROW_ADDRESS);
+ *(__IO uint8_t *)(Bank_NAND_ADDR | ADDR_AREA) = ADDR_2nd_CYCLE(ROW_ADDRESS);
+ *(__IO uint8_t *)(Bank_NAND_ADDR | ADDR_AREA) = ADDR_3rd_CYCLE(ROW_ADDRESS);
+
+ /*!< Calculate the size */
+ size = NAND_PAGE_SIZE + (NAND_PAGE_SIZE * numpagewritten);
+
+ /*!< Write data */
+ for(; index < size; index++)
+ {
+ *(__IO uint8_t *)(Bank_NAND_ADDR | DATA_AREA) = pBuffer[index];
+ }
+
+ *(__IO uint8_t *)(Bank_NAND_ADDR | CMD_AREA) = NAND_CMD_WRITE_TRUE1;
+
+ /*!< Check status for successful operation */
+ status = NAND_GetStatus();
+
+ if(status == NAND_READY)
+ {
+ numpagewritten++;
+
+ NumPageToWrite--;
+
+ /*!< Calculate Next small page Address */
+ addressstatus = NAND_AddressIncrement(&Address);
+ }
+ }
+
+ return (status | addressstatus);
+}
+
+/**
+ * @brief This routine is for sequential read from one or several 512 Bytes Page size.
+ * @param pBuffer: pointer on the Buffer to fill
+ * @param Address: First page address
+ * @param NumPageToRead: Number of page to read
+ * @retval New status of the NAND operation. This parameter can be:
+ * - NAND_TIMEOUT_ERROR: when the previous operation generate
+ * a Timeout error
+ * - NAND_READY: when memory is ready for the next operation
+ * And the new status of the increment address operation. It can be:
+ * - NAND_VALID_ADDRESS: When the new address is valid address
+ * - NAND_INVALID_ADDRESS: When the new address is invalid address
+ */
+uint32_t NAND_ReadSmallPage(uint8_t *pBuffer, NAND_ADDRESS Address, uint32_t NumPageToRead)
+{
+ uint32_t index = 0x00, numpageread = 0x00, addressstatus = NAND_VALID_ADDRESS;
+ uint32_t status = NAND_READY, size = 0x00;
+
+ while((NumPageToRead != 0x0) && (addressstatus == NAND_VALID_ADDRESS))
+ {
+ /*!< Page Read command and page address */
+ *(__IO uint8_t *)(Bank_NAND_ADDR | CMD_AREA) = NAND_CMD_AREA_A;
+
+ *(__IO uint8_t *)(Bank_NAND_ADDR | ADDR_AREA) = 0x00;
+ *(__IO uint8_t *)(Bank_NAND_ADDR | ADDR_AREA) = ADDR_1st_CYCLE(ROW_ADDRESS);
+ *(__IO uint8_t *)(Bank_NAND_ADDR | ADDR_AREA) = ADDR_2nd_CYCLE(ROW_ADDRESS);
+ *(__IO uint8_t *)(Bank_NAND_ADDR | ADDR_AREA) = ADDR_3rd_CYCLE(ROW_ADDRESS);
+
+ /*!< Calculate the size */
+ size = NAND_PAGE_SIZE + (NAND_PAGE_SIZE * numpageread);
+
+ /*!< Get Data into Buffer */
+ for(; index < size; index++)
+ {
+ pBuffer[index]= *(__IO uint8_t *)(Bank_NAND_ADDR | DATA_AREA);
+ }
+
+ numpageread++;
+
+ NumPageToRead--;
+
+ /*!< Calculate page address */
+ addressstatus = NAND_AddressIncrement(&Address);
+ }
+
+ status = NAND_GetStatus();
+
+ return (status | addressstatus);
+}
+
+/**
+ * @brief This routine write the spare area information for the specified
+ * pages addresses.
+ * @param pBuffer: pointer on the Buffer containing data to be written
+ * @param Address: First page address
+ * @param NumSpareAreaTowrite: Number of Spare Area to write
+ * @retval New status of the NAND operation. This parameter can be:
+ * - NAND_TIMEOUT_ERROR: when the previous operation generate
+ * a Timeout error
+ * - NAND_READY: when memory is ready for the next operation
+ * And the new status of the increment address operation. It can be:
+ * - NAND_VALID_ADDRESS: When the new address is valid address
+ * - NAND_INVALID_ADDRESS: When the new address is invalid address
+ */
+uint32_t NAND_WriteSpareArea(uint8_t *pBuffer, NAND_ADDRESS Address, uint32_t NumSpareAreaTowrite)
+{
+ uint32_t index = 0x00, numsparesreawritten = 0x00, addressstatus = NAND_VALID_ADDRESS;
+ uint32_t status = NAND_READY, size = 0x00;
+
+ while((NumSpareAreaTowrite != 0x00) && (addressstatus == NAND_VALID_ADDRESS) && (status == NAND_READY))
+ {
+ /*!< Page write Spare area command and address */
+ *(__IO uint8_t *)(Bank_NAND_ADDR | CMD_AREA) = NAND_CMD_AREA_C;
+ *(__IO uint8_t *)(Bank_NAND_ADDR | CMD_AREA) = NAND_CMD_WRITE0;
+
+ *(__IO uint8_t *)(Bank_NAND_ADDR | ADDR_AREA) = 0x00;
+ *(__IO uint8_t *)(Bank_NAND_ADDR | ADDR_AREA) = ADDR_1st_CYCLE(ROW_ADDRESS);
+ *(__IO uint8_t *)(Bank_NAND_ADDR | ADDR_AREA) = ADDR_2nd_CYCLE(ROW_ADDRESS);
+ *(__IO uint8_t *)(Bank_NAND_ADDR | ADDR_AREA) = ADDR_3rd_CYCLE(ROW_ADDRESS);
+
+ /*!< Calculate the size */
+ size = NAND_SPARE_AREA_SIZE + (NAND_SPARE_AREA_SIZE * numsparesreawritten);
+
+ /*!< Write the data */
+ for(; index < size; index++)
+ {
+ *(__IO uint8_t *)(Bank_NAND_ADDR | DATA_AREA) = pBuffer[index];
+ }
+
+ *(__IO uint8_t *)(Bank_NAND_ADDR | CMD_AREA) = NAND_CMD_WRITE_TRUE1;
+
+ /*!< Check status for successful operation */
+ status = NAND_GetStatus();
+
+ if(status == NAND_READY)
+ {
+ numsparesreawritten++;
+
+ NumSpareAreaTowrite--;
+
+ /*!< Calculate Next page Address */
+ addressstatus = NAND_AddressIncrement(&Address);
+ }
+ }
+
+ return (status | addressstatus);
+}
+
+/**
+ * @brief This routine read the spare area information from the specified
+ * pages addresses.
+ * @param pBuffer: pointer on the Buffer to fill
+ * @param Address: First page address
+ * @param NumSpareAreaToRead: Number of Spare Area to read
+ * @retval New status of the NAND operation. This parameter can be:
+ * - NAND_TIMEOUT_ERROR: when the previous operation generate
+ * a Timeout error
+ * - NAND_READY: when memory is ready for the next operation
+ * And the new status of the increment address operation. It can be:
+ * - NAND_VALID_ADDRESS: When the new address is valid address
+ * - NAND_INVALID_ADDRESS: When the new address is invalid address
+ */
+uint32_t NAND_ReadSpareArea(uint8_t *pBuffer, NAND_ADDRESS Address, uint32_t NumSpareAreaToRead)
+{
+ uint32_t numsparearearead = 0x00, index = 0x00, addressstatus = NAND_VALID_ADDRESS;
+ uint32_t status = NAND_READY, size = 0x00;
+
+ while((NumSpareAreaToRead != 0x0) && (addressstatus == NAND_VALID_ADDRESS))
+ {
+ /*!< Page Read command and page address */
+ *(__IO uint8_t *)(Bank_NAND_ADDR | CMD_AREA) = NAND_CMD_AREA_C;
+
+ *(__IO uint8_t *)(Bank_NAND_ADDR | ADDR_AREA) = 0x00;
+ *(__IO uint8_t *)(Bank_NAND_ADDR | ADDR_AREA) = ADDR_1st_CYCLE(ROW_ADDRESS);
+ *(__IO uint8_t *)(Bank_NAND_ADDR | ADDR_AREA) = ADDR_2nd_CYCLE(ROW_ADDRESS);
+ *(__IO uint8_t *)(Bank_NAND_ADDR | ADDR_AREA) = ADDR_3rd_CYCLE(ROW_ADDRESS);
+
+ /*!< Data Read */
+ size = NAND_SPARE_AREA_SIZE + (NAND_SPARE_AREA_SIZE * numsparearearead);
+
+ /*!< Get Data into Buffer */
+ for ( ;index < size; index++)
+ {
+ pBuffer[index] = *(__IO uint8_t *)(Bank_NAND_ADDR | DATA_AREA);
+ }
+
+ numsparearearead++;
+
+ NumSpareAreaToRead--;
+
+ /*!< Calculate page address */
+ addressstatus = NAND_AddressIncrement(&Address);
+ }
+
+ status = NAND_GetStatus();
+
+ return (status | addressstatus);
+}
+
+/**
+ * @brief This routine erase complete block from NAND FLASH
+ * @param Address: Any address into block to be erased
+ * @retval New status of the NAND operation. This parameter can be:
+ * - NAND_TIMEOUT_ERROR: when the previous operation generate
+ * a Timeout error
+ * - NAND_READY: when memory is ready for the next operation
+ */
+uint32_t NAND_EraseBlock(NAND_ADDRESS Address)
+{
+ *(__IO uint8_t *)(Bank_NAND_ADDR | CMD_AREA) = NAND_CMD_ERASE0;
+
+ *(__IO uint8_t *)(Bank_NAND_ADDR | ADDR_AREA) = ADDR_1st_CYCLE(ROW_ADDRESS);
+ *(__IO uint8_t *)(Bank_NAND_ADDR | ADDR_AREA) = ADDR_2nd_CYCLE(ROW_ADDRESS);
+ *(__IO uint8_t *)(Bank_NAND_ADDR | ADDR_AREA) = ADDR_3rd_CYCLE(ROW_ADDRESS);
+
+ *(__IO uint8_t *)(Bank_NAND_ADDR | CMD_AREA) = NAND_CMD_ERASE1;
+
+ return (NAND_GetStatus());
+}
+
+/**
+ * @brief This routine reset the NAND FLASH.
+ * @param None
+ * @retval NAND_READY
+ */
+uint32_t NAND_Reset(void)
+{
+ *(__IO uint8_t *)(Bank_NAND_ADDR | CMD_AREA) = NAND_CMD_RESET;
+
+ return (NAND_READY);
+}
+
+/**
+ * @brief Get the NAND operation status.
+ * @param None
+ * @retval New status of the NAND operation. This parameter can be:
+ * - NAND_TIMEOUT_ERROR: when the previous operation generate
+ * a Timeout error
+ * - NAND_READY: when memory is ready for the next operation
+ */
+uint32_t NAND_GetStatus(void)
+{
+ uint32_t timeout = 0x1000000, status = NAND_READY;
+
+ status = NAND_ReadStatus();
+
+ /*!< Wait for a NAND operation to complete or a TIMEOUT to occur */
+ while ((status != NAND_READY) &&( timeout != 0x00))
+ {
+ status = NAND_ReadStatus();
+ timeout --;
+ }
+
+ if(timeout == 0x00)
+ {
+ status = NAND_TIMEOUT_ERROR;
+ }
+
+ /*!< Return the operation status */
+ return (status);
+}
+
+/**
+ * @brief Reads the NAND memory status using the Read status command.
+ * @param None
+ * @retval The status of the NAND memory. This parameter can be:
+ * - NAND_BUSY: when memory is busy
+ * - NAND_READY: when memory is ready for the next operation
+ * - NAND_ERROR: when the previous operation gererates error
+ */
+uint32_t NAND_ReadStatus(void)
+{
+ uint32_t data = 0x00, status = NAND_BUSY;
+
+ /*!< Read status operation ------------------------------------ */
+ *(__IO uint8_t *)(Bank_NAND_ADDR | CMD_AREA) = NAND_CMD_STATUS;
+ data = *(__IO uint8_t *)(Bank_NAND_ADDR);
+
+ if((data & NAND_ERROR) == NAND_ERROR)
+ {
+ status = NAND_ERROR;
+ }
+ else if((data & NAND_READY) == NAND_READY)
+ {
+ status = NAND_READY;
+ }
+ else
+ {
+ status = NAND_BUSY;
+ }
+
+ return (status);
+}
+
+/**
+ * @brief Increment the NAND memory address.
+ * @param Address: address to be incremented.
+ * @retval The new status of the increment address operation. It can be:
+ * - NAND_VALID_ADDRESS: When the new address is valid address
+ * - NAND_INVALID_ADDRESS: When the new address is invalid address
+ */
+uint32_t NAND_AddressIncrement(NAND_ADDRESS* Address)
+{
+ uint32_t status = NAND_VALID_ADDRESS;
+
+ Address->Page++;
+
+ if(Address->Page == NAND_BLOCK_SIZE)
+ {
+ Address->Page = 0;
+ Address->Block++;
+
+ if(Address->Block == NAND_ZONE_SIZE)
+ {
+ Address->Block = 0;
+ Address->Zone++;
+
+ if(Address->Zone == NAND_MAX_ZONE)
+ {
+ status = NAND_INVALID_ADDRESS;
+ }
+ }
+ }
+
+ return (status);
+}
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210E_EVAL/stm3210e_eval_fsmc_nand.h b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210E_EVAL/stm3210e_eval_fsmc_nand.h
new file mode 100644
index 0000000..4c6cdf9
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210E_EVAL/stm3210e_eval_fsmc_nand.h
@@ -0,0 +1,183 @@
+/**
+ ******************************************************************************
+ * @file stm3210e_eval_fsmc_nand.h
+ * @author MCD Application Team
+ * @version V5.1.0
+ * @date 18-January-2013
+ * @brief This file contains all the functions prototypes for the
+ * stm3210e_eval_fsmc_nand firmware driver.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2013 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.st.com/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __STM3210E_EVAL_FSMC_NAND_H
+#define __STM3210E_EVAL_FSMC_NAND_H
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+/* Includes ------------------------------------------------------------------*/
+#include "stm3210e_eval.h"
+
+/** @addtogroup Utilities
+ * @{
+ */
+
+/** @addtogroup STM32_EVAL
+ * @{
+ */
+
+/** @addtogroup STM3210E_EVAL
+ * @{
+ */
+
+/** @addtogroup STM3210E_EVAL_FSMC_NAND
+ * @{
+ */
+
+/** @defgroup STM3210E_EVAL_FSMC_NAND_Exported_Types
+ * @{
+ */
+typedef struct
+{
+ uint8_t Maker_ID;
+ uint8_t Device_ID;
+ uint8_t Third_ID;
+ uint8_t Fourth_ID;
+}NAND_IDTypeDef;
+
+typedef struct
+{
+ uint16_t Zone;
+ uint16_t Block;
+ uint16_t Page;
+} NAND_ADDRESS;
+/**
+ * @}
+ */
+
+/** @defgroup STM3210E_EVAL_FSMC_NAND_Exported_Constants
+ * @{
+ */
+/**
+ * @brief NAND Area definition for STM3210E-EVAL Board RevD
+ */
+#define CMD_AREA (uint32_t)(1<<16) /* A16 = CLE high */
+#define ADDR_AREA (uint32_t)(1<<17) /* A17 = ALE high */
+
+#define DATA_AREA ((uint32_t)0x00000000)
+
+/**
+ * @brief FSMC NAND memory command
+ */
+#define NAND_CMD_AREA_A ((uint8_t)0x00)
+#define NAND_CMD_AREA_B ((uint8_t)0x01)
+#define NAND_CMD_AREA_C ((uint8_t)0x50)
+
+#define NAND_CMD_WRITE0 ((uint8_t)0x80)
+#define NAND_CMD_WRITE_TRUE1 ((uint8_t)0x10)
+
+#define NAND_CMD_ERASE0 ((uint8_t)0x60)
+#define NAND_CMD_ERASE1 ((uint8_t)0xD0)
+
+#define NAND_CMD_READID ((uint8_t)0x90)
+#define NAND_CMD_STATUS ((uint8_t)0x70)
+#define NAND_CMD_LOCK_STATUS ((uint8_t)0x7A)
+#define NAND_CMD_RESET ((uint8_t)0xFF)
+
+/**
+ * @brief NAND memory status
+ */
+#define NAND_VALID_ADDRESS ((uint32_t)0x00000100)
+#define NAND_INVALID_ADDRESS ((uint32_t)0x00000200)
+#define NAND_TIMEOUT_ERROR ((uint32_t)0x00000400)
+#define NAND_BUSY ((uint32_t)0x00000000)
+#define NAND_ERROR ((uint32_t)0x00000001)
+#define NAND_READY ((uint32_t)0x00000040)
+
+/**
+ * @brief FSMC NAND memory parameters
+ */
+#define NAND_PAGE_SIZE ((uint16_t)0x0200) /* 512 bytes per page w/o Spare Area */
+#define NAND_BLOCK_SIZE ((uint16_t)0x0020) /* 32x512 bytes pages per block */
+#define NAND_ZONE_SIZE ((uint16_t)0x0400) /* 1024 Block per zone */
+#define NAND_SPARE_AREA_SIZE ((uint16_t)0x0010) /* last 16 bytes as spare area */
+#define NAND_MAX_ZONE ((uint16_t)0x0004) /* 4 zones of 1024 block */
+
+/**
+ * @brief FSMC NAND memory address computation
+ */
+#define ADDR_1st_CYCLE(ADDR) (uint8_t)((ADDR)& 0xFF) /* 1st addressing cycle */
+#define ADDR_2nd_CYCLE(ADDR) (uint8_t)(((ADDR)& 0xFF00) >> 8) /* 2nd addressing cycle */
+#define ADDR_3rd_CYCLE(ADDR) (uint8_t)(((ADDR)& 0xFF0000) >> 16) /* 3rd addressing cycle */
+#define ADDR_4th_CYCLE(ADDR) (uint8_t)(((ADDR)& 0xFF000000) >> 24) /* 4th addressing cycle */
+/**
+ * @}
+ */
+
+/** @defgroup STM3210E_EVAL_FSMC_NAND_Exported_Macros
+ * @{
+ */
+/**
+ * @}
+ */
+
+/** @defgroup STM3210E_EVAL_FSMC_NAND_Exported_Functions
+ * @{
+ */
+void NAND_Init(void);
+void NAND_ReadID(NAND_IDTypeDef* NAND_ID);
+uint32_t NAND_WriteSmallPage(uint8_t *pBuffer, NAND_ADDRESS Address, uint32_t NumPageToWrite);
+uint32_t NAND_ReadSmallPage (uint8_t *pBuffer, NAND_ADDRESS Address, uint32_t NumPageToRead);
+uint32_t NAND_WriteSpareArea(uint8_t *pBuffer, NAND_ADDRESS Address, uint32_t NumSpareAreaTowrite);
+uint32_t NAND_ReadSpareArea(uint8_t *pBuffer, NAND_ADDRESS Address, uint32_t NumSpareAreaToRead);
+uint32_t NAND_EraseBlock(NAND_ADDRESS Address);
+uint32_t NAND_Reset(void);
+uint32_t NAND_GetStatus(void);
+uint32_t NAND_ReadStatus(void);
+uint32_t NAND_AddressIncrement(NAND_ADDRESS* Address);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __STM3210E_EVAL_FSMC_NAND_H */
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210E_EVAL/stm3210e_eval_fsmc_nor.c b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210E_EVAL/stm3210e_eval_fsmc_nor.c
new file mode 100644
index 0000000..45a788a
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210E_EVAL/stm3210e_eval_fsmc_nor.c
@@ -0,0 +1,484 @@
+/**
+ ******************************************************************************
+ * @file stm3210e_eval_fsmc_nor.c
+ * @author MCD Application Team
+ * @version V5.1.0
+ * @date 18-January-2013
+ * @brief This file provides a set of functions needed to drive the M29W128FL,
+ * M29W128GL and S29GL128P NOR memories mounted on STM3210E-EVAL board.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2013 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.st.com/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+
+/* Includes ------------------------------------------------------------------*/
+#include "stm3210e_eval_fsmc_nor.h"
+
+/** @addtogroup Utilities
+ * @{
+ */
+
+/** @addtogroup STM32_EVAL
+ * @{
+ */
+
+/** @addtogroup STM3210E_EVAL
+ * @{
+ */
+
+/** @addtogroup STM3210E_EVAL_FSMC_NOR
+ * @brief This file provides a set of functions needed to drive the M29W128FL,
+ * M29W128GL and S29GL128P NOR memories mounted on STM3210E-EVAL board.
+ * @{
+ */
+
+/** @defgroup STM3210E_EVAL_FSMC_NOR_Private_Types
+ * @{
+ */
+/**
+ * @}
+ */
+
+/** @defgroup STM3210E_EVAL_FSMC_NOR_Private_Defines
+ * @{
+ */
+/**
+ * @brief FSMC Bank 1 NOR/SRAM2
+ */
+#define Bank1_NOR2_ADDR ((uint32_t)0x64000000)
+
+/* Delay definition */
+#define BlockErase_Timeout ((uint32_t)0x00A00000)
+#define ChipErase_Timeout ((uint32_t)0x30000000)
+#define Program_Timeout ((uint32_t)0x00001400)
+/**
+ * @}
+ */
+
+
+/** @defgroup STM3210E_EVAL_FSMC_NOR_Private_Macros
+ * @{
+ */
+#define ADDR_SHIFT(A) (Bank1_NOR2_ADDR + (2 * (A)))
+#define NOR_WRITE(Address, Data) (*(__IO uint16_t *)(Address) = (Data))
+/**
+ * @}
+ */
+
+
+/** @defgroup STM3210E_EVAL_FSMC_NOR_Private_Variables
+ * @{
+ */
+/**
+ * @}
+ */
+
+
+/** @defgroupSTM3210E_EVAL_FSMC_NOR_Private_Function_Prototypes
+ * @{
+ */
+/**
+ * @}
+ */
+
+
+/** @defgroup STM3210E_EVAL_FSMC_NOR_Private_Functions
+ * @{
+ */
+
+/**
+ * @brief Configures the FSMC and GPIOs to interface with the NOR memory.
+ * This function must be called before any write/read operation
+ * on the NOR.
+ * @param None
+ * @retval None
+ */
+void NOR_Init(void)
+{
+ FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure;
+ FSMC_NORSRAMTimingInitTypeDef p;
+ GPIO_InitTypeDef GPIO_InitStructure;
+
+ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE |
+ RCC_APB2Periph_GPIOF | RCC_APB2Periph_GPIOG, ENABLE);
+
+ /*-- GPIO Configuration ------------------------------------------------------*/
+ /*!< NOR Data lines configuration */
+ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_8 | GPIO_Pin_9 |
+ GPIO_Pin_10 | GPIO_Pin_14 | GPIO_Pin_15;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
+ GPIO_Init(GPIOD, &GPIO_InitStructure);
+
+ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 |
+ GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 |
+ GPIO_Pin_14 | GPIO_Pin_15;
+ GPIO_Init(GPIOE, &GPIO_InitStructure);
+
+ /*!< NOR Address lines configuration */
+ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 |
+ GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_12 | GPIO_Pin_13 |
+ GPIO_Pin_14 | GPIO_Pin_15;
+ GPIO_Init(GPIOF, &GPIO_InitStructure);
+
+ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 |
+ GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5;
+ GPIO_Init(GPIOG, &GPIO_InitStructure);
+
+ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13;
+ GPIO_Init(GPIOD, &GPIO_InitStructure);
+
+ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6;
+ GPIO_Init(GPIOE, &GPIO_InitStructure);
+
+ /*!< NOE and NWE configuration */
+ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5;
+ GPIO_Init(GPIOD, &GPIO_InitStructure);
+
+ /*!< NE2 configuration */
+ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
+ GPIO_Init(GPIOG, &GPIO_InitStructure);
+
+ /*!< Configure PD6 for NOR memory Ready/Busy signal */
+ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
+ GPIO_Init(GPIOD, &GPIO_InitStructure);
+
+ /*-- FSMC Configuration ----------------------------------------------------*/
+ p.FSMC_AddressSetupTime = 0x02;
+ p.FSMC_AddressHoldTime = 0x00;
+ p.FSMC_DataSetupTime = 0x05;
+ p.FSMC_BusTurnAroundDuration = 0x00;
+ p.FSMC_CLKDivision = 0x00;
+ p.FSMC_DataLatency = 0x00;
+ p.FSMC_AccessMode = FSMC_AccessMode_B;
+
+ FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM2;
+ FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable;
+ FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_NOR;
+ FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b;
+ FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable;
+ FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable;
+ FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low;
+ FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable;
+ FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState;
+ FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable;
+ FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable;
+ FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable;
+ FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable;
+ FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p;
+ FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p;
+
+ FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure);
+
+ /*!< Enable FSMC Bank1_NOR Bank */
+ FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM2, ENABLE);
+}
+
+/**
+ * @brief Reads NOR memory's Manufacturer and Device Code.
+ * @param NOR_ID: pointer to a NOR_IDTypeDef structure which will hold the
+ * Manufacturer and Device Code.
+ * @retval None
+ */
+void NOR_ReadID(NOR_IDTypeDef* NOR_ID)
+{
+ NOR_WRITE(ADDR_SHIFT(0x0555), 0x00AA);
+ NOR_WRITE(ADDR_SHIFT(0x02AA), 0x0055);
+ NOR_WRITE(ADDR_SHIFT(0x0555), 0x0090);
+
+ NOR_ID->Manufacturer_Code = *(__IO uint16_t *) ADDR_SHIFT(0x0000);
+ NOR_ID->Device_Code1 = *(__IO uint16_t *) ADDR_SHIFT(0x0001);
+ NOR_ID->Device_Code2 = *(__IO uint16_t *) ADDR_SHIFT(0x000E);
+ NOR_ID->Device_Code3 = *(__IO uint16_t *) ADDR_SHIFT(0x000F);
+}
+
+/**
+ * @brief Erases the specified Nor memory block.
+ * @param BlockAddr: address of the block to erase.
+ * @retval NOR_Status: The returned value can be: NOR_SUCCESS, NOR_ERROR
+ * or NOR_TIMEOUT
+ */
+NOR_Status NOR_EraseBlock(uint32_t BlockAddr)
+{
+ NOR_WRITE(ADDR_SHIFT(0x0555), 0x00AA);
+ NOR_WRITE(ADDR_SHIFT(0x02AA), 0x0055);
+ NOR_WRITE(ADDR_SHIFT(0x0555), 0x0080);
+ NOR_WRITE(ADDR_SHIFT(0x0555), 0x00AA);
+ NOR_WRITE(ADDR_SHIFT(0x02AA), 0x0055);
+ NOR_WRITE((Bank1_NOR2_ADDR + BlockAddr), 0x30);
+
+ return (NOR_GetStatus(BlockErase_Timeout));
+}
+
+/**
+ * @brief Erases the entire chip.
+ * @param None
+ * @retval NOR_Status: The returned value can be: NOR_SUCCESS, NOR_ERROR
+ * or NOR_TIMEOUT
+ */
+NOR_Status NOR_EraseChip(void)
+{
+ NOR_WRITE(ADDR_SHIFT(0x0555), 0x00AA);
+ NOR_WRITE(ADDR_SHIFT(0x02AA), 0x0055);
+ NOR_WRITE(ADDR_SHIFT(0x0555), 0x0080);
+ NOR_WRITE(ADDR_SHIFT(0x0555), 0x00AA);
+ NOR_WRITE(ADDR_SHIFT(0x02AA), 0x0055);
+ NOR_WRITE(ADDR_SHIFT(0x0555), 0x0010);
+
+ return (NOR_GetStatus(ChipErase_Timeout));
+}
+
+/**
+ * @brief Writes a half-word to the NOR memory.
+ * @param WriteAddr: NOR memory internal address to write to.
+ * @param Data: Data to write.
+ * @retval NOR_Status: The returned value can be: NOR_SUCCESS, NOR_ERROR
+ * or NOR_TIMEOUT
+ */
+NOR_Status NOR_WriteHalfWord(uint32_t WriteAddr, uint16_t Data)
+{
+ NOR_WRITE(ADDR_SHIFT(0x0555), 0x00AA);
+ NOR_WRITE(ADDR_SHIFT(0x02AA), 0x0055);
+ NOR_WRITE(ADDR_SHIFT(0x0555), 0x00A0);
+ NOR_WRITE((Bank1_NOR2_ADDR + WriteAddr), Data);
+
+ return (NOR_GetStatus(Program_Timeout));
+}
+
+/**
+ * @brief Writes a half-word buffer to the FSMC NOR memory.
+ * @param pBuffer: pointer to buffer.
+ * @param WriteAddr: NOR memory internal address from which the data will be
+ * written.
+ * @param NumHalfwordToWrite: number of Half words to write.
+ * @retval NOR_Status: The returned value can be: NOR_SUCCESS, NOR_ERROR
+ * or NOR_TIMEOUT
+ */
+NOR_Status NOR_WriteBuffer(uint16_t* pBuffer, uint32_t WriteAddr, uint32_t NumHalfwordToWrite)
+{
+ NOR_Status status = NOR_ONGOING;
+
+ do
+ {
+ /*!< Transfer data to the memory */
+ status = NOR_WriteHalfWord(WriteAddr, *pBuffer++);
+ WriteAddr = WriteAddr + 2;
+ NumHalfwordToWrite--;
+ }
+ while((status == NOR_SUCCESS) && (NumHalfwordToWrite != 0));
+
+ return (status);
+}
+
+/**
+ * @brief Writes a half-word buffer to the FSMC NOR memory.
+ * @param pBuffer: pointer to buffer.
+ * @param WriteAddr: NOR memory internal address from which the data will be
+ * written.
+ * @param NumHalfwordToWrite: number of Half words to write.
+ * The maximum allowed value is 32 Half words (64 bytes).
+ * @retval NOR_Status: The returned value can be: NOR_SUCCESS, NOR_ERROR
+ * or NOR_TIMEOUT
+ */
+NOR_Status NOR_ProgramBuffer(uint16_t* pBuffer, uint32_t WriteAddr, uint32_t NumHalfwordToWrite)
+{
+ uint32_t lastloadedaddress = 0x00;
+ uint32_t currentaddress = 0x00;
+ uint32_t endaddress = 0x00;
+
+ /*!< Initialize variables */
+ currentaddress = WriteAddr;
+ endaddress = WriteAddr + NumHalfwordToWrite - 1;
+ lastloadedaddress = WriteAddr;
+
+ /*!< Issue unlock command sequence */
+ NOR_WRITE(ADDR_SHIFT(0x00555), 0x00AA);
+
+ NOR_WRITE(ADDR_SHIFT(0x02AA), 0x0055);
+
+ /*!< Write Write Buffer Load Command */
+ NOR_WRITE(ADDR_SHIFT(WriteAddr), 0x0025);
+ NOR_WRITE(ADDR_SHIFT(WriteAddr), (NumHalfwordToWrite - 1));
+
+ /*!< Load Data into NOR Buffer */
+ while(currentaddress <= endaddress)
+ {
+ /*!< Store last loaded address & data value (for polling) */
+ lastloadedaddress = currentaddress;
+
+ NOR_WRITE(ADDR_SHIFT(currentaddress), *pBuffer++);
+ currentaddress += 1;
+ }
+
+ NOR_WRITE(ADDR_SHIFT(lastloadedaddress), 0x29);
+
+ return(NOR_GetStatus(Program_Timeout));
+}
+
+/**
+ * @brief Reads a half-word from the NOR memory.
+ * @param ReadAddr: NOR memory internal address to read from.
+ * @retval Half-word read from the NOR memory
+ */
+uint16_t NOR_ReadHalfWord(uint32_t ReadAddr)
+{
+ NOR_WRITE(ADDR_SHIFT(0x00555), 0x00AA);
+ NOR_WRITE(ADDR_SHIFT(0x002AA), 0x0055);
+ NOR_WRITE((Bank1_NOR2_ADDR + ReadAddr), 0x00F0 );
+
+ return (*(__IO uint16_t *)((Bank1_NOR2_ADDR + ReadAddr)));
+}
+
+/**
+ * @brief Reads a block of data from the FSMC NOR memory.
+ * @param pBuffer: pointer to the buffer that receives the data read from the
+ * NOR memory.
+ * @param ReadAddr: NOR memory internal address to read from.
+ * @param NumHalfwordToRead : number of Half word to read.
+ * @retval None
+ */
+void NOR_ReadBuffer(uint16_t* pBuffer, uint32_t ReadAddr, uint32_t NumHalfwordToRead)
+{
+ NOR_WRITE(ADDR_SHIFT(0x0555), 0x00AA);
+ NOR_WRITE(ADDR_SHIFT(0x02AA), 0x0055);
+ NOR_WRITE((Bank1_NOR2_ADDR + ReadAddr), 0x00F0);
+
+ for(; NumHalfwordToRead != 0x00; NumHalfwordToRead--) /*!< while there is data to read */
+ {
+ /*!< Read a Halfword from the NOR */
+ *pBuffer++ = *(__IO uint16_t *)((Bank1_NOR2_ADDR + ReadAddr));
+ ReadAddr = ReadAddr + 2;
+ }
+}
+
+/**
+ * @brief Returns the NOR memory to Read mode.
+ * @param None
+ * @retval NOR_SUCCESS
+ */
+NOR_Status NOR_ReturnToReadMode(void)
+{
+ NOR_WRITE(Bank1_NOR2_ADDR, 0x00F0);
+
+ return (NOR_SUCCESS);
+}
+
+/**
+ * @brief Returns the NOR memory to Read mode and resets the errors in the NOR
+ * memory Status Register.
+ * @param None
+ * @retval NOR_SUCCESS
+ */
+NOR_Status NOR_Reset(void)
+{
+ NOR_WRITE(ADDR_SHIFT(0x00555), 0x00AA);
+ NOR_WRITE(ADDR_SHIFT(0x002AA), 0x0055);
+ NOR_WRITE(Bank1_NOR2_ADDR, 0x00F0);
+
+ return (NOR_SUCCESS);
+}
+
+/**
+ * @brief Returns the NOR operation status.
+ * @param Timeout: NOR progamming Timeout
+ * @retval NOR_Status: The returned value can be: NOR_SUCCESS, NOR_ERROR
+ * or NOR_TIMEOUT
+ */
+NOR_Status NOR_GetStatus(uint32_t Timeout)
+{
+ uint16_t val1 = 0x00, val2 = 0x00;
+ NOR_Status status = NOR_ONGOING;
+ uint32_t timeout = Timeout;
+
+ /*!< Poll on NOR memory Ready/Busy signal ----------------------------------*/
+ while((GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_6) != RESET) && (timeout > 0))
+ {
+ timeout--;
+ }
+
+ timeout = Timeout;
+
+ while((GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_6) == RESET) && (timeout > 0))
+ {
+ timeout--;
+ }
+
+ /*!< Get the NOR memory operation status -----------------------------------*/
+ while((Timeout != 0x00) && (status != NOR_SUCCESS))
+ {
+ Timeout--;
+
+ /*!< Read DQ6 and DQ5 */
+ val1 = *(__IO uint16_t *)(Bank1_NOR2_ADDR);
+ val2 = *(__IO uint16_t *)(Bank1_NOR2_ADDR);
+
+ /*!< If DQ6 did not toggle between the two reads then return NOR_Success */
+ if((val1 & 0x0040) == (val2 & 0x0040))
+ {
+ return NOR_SUCCESS;
+ }
+
+ if((val1 & 0x0020) != 0x0020)
+ {
+ status = NOR_ONGOING;
+ }
+
+ val1 = *(__IO uint16_t *)(Bank1_NOR2_ADDR);
+ val2 = *(__IO uint16_t *)(Bank1_NOR2_ADDR);
+
+ if((val1 & 0x0040) == (val2 & 0x0040))
+ {
+ return NOR_SUCCESS;
+ }
+ else if((val1 & 0x0020) == 0x0020)
+ {
+ return NOR_ERROR;
+ }
+ }
+
+ if(Timeout == 0x00)
+ {
+ status = NOR_TIMEOUT;
+ }
+
+ /*!< Return the operation status */
+ return (status);
+}
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210E_EVAL/stm3210e_eval_fsmc_nor.h b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210E_EVAL/stm3210e_eval_fsmc_nor.h
new file mode 100644
index 0000000..707e5e3
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210E_EVAL/stm3210e_eval_fsmc_nor.h
@@ -0,0 +1,134 @@
+/**
+ ******************************************************************************
+ * @file stm3210e_eval_fsmc_nor.h
+ * @author MCD Application Team
+ * @version V5.1.0
+ * @date 18-January-2013
+ * @brief This file contains all the functions prototypes for the
+ * stm3210e_eval_fsmc_nor firmware driver.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2013 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.st.com/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __STM3210E_EVAL_FSMC_NOR_H
+#define __STM3210E_EVAL_FSMC_NOR_H
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+/* Includes ------------------------------------------------------------------*/
+#include "stm3210e_eval.h"
+
+/** @addtogroup Utilities
+ * @{
+ */
+
+/** @addtogroup STM32_EVAL
+ * @{
+ */
+
+/** @addtogroup STM3210E_EVAL
+ * @{
+ */
+
+/** @addtogroup STM3210E_EVAL_FSMC_NOR
+ * @{
+ */
+
+/** @defgroup STM3210E_EVAL_FSMC_NOR_Exported_Types
+ * @{
+ */
+typedef struct
+{
+ uint16_t Manufacturer_Code;
+ uint16_t Device_Code1;
+ uint16_t Device_Code2;
+ uint16_t Device_Code3;
+}NOR_IDTypeDef;
+
+/* NOR Status */
+typedef enum
+{
+ NOR_SUCCESS = 0,
+ NOR_ONGOING,
+ NOR_ERROR,
+ NOR_TIMEOUT
+}NOR_Status;
+/**
+ * @}
+ */
+
+/** @defgroup STM3210E_EVAL_FSMC_NOR_Exported_Constants
+ * @{
+ */
+/**
+ * @}
+ */
+
+/** @defgroup STM3210E_EVAL_FSMC_NOR_Exported_Macros
+ * @{
+ */
+/**
+ * @}
+ */
+
+/** @defgroup STM3210E_EVAL_FSMC_NOR_Exported_Functions
+ * @{
+ */
+void NOR_Init(void);
+void NOR_ReadID(NOR_IDTypeDef* NOR_ID);
+NOR_Status NOR_EraseBlock(uint32_t BlockAddr);
+NOR_Status NOR_EraseChip(void);
+NOR_Status NOR_WriteHalfWord(uint32_t WriteAddr, uint16_t Data);
+NOR_Status NOR_WriteBuffer(uint16_t* pBuffer, uint32_t WriteAddr, uint32_t NumHalfwordToWrite);
+NOR_Status NOR_ProgramBuffer(uint16_t* pBuffer, uint32_t WriteAddr, uint32_t NumHalfwordToWrite);
+uint16_t NOR_ReadHalfWord(uint32_t ReadAddr);
+void NOR_ReadBuffer(uint16_t* pBuffer, uint32_t ReadAddr, uint32_t NumHalfwordToRead);
+NOR_Status NOR_ReturnToReadMode(void);
+NOR_Status NOR_Reset(void);
+NOR_Status NOR_GetStatus(uint32_t Timeout);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __STM3210E_EVAL_FSMC_NOR_H */
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210E_EVAL/stm3210e_eval_sdio_sd.c b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210E_EVAL/stm3210e_eval_sdio_sd.c
new file mode 100644
index 0000000..1e1de17
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210E_EVAL/stm3210e_eval_sdio_sd.c
@@ -0,0 +1,2816 @@
+/**
+ ******************************************************************************
+ * @file stm3210e_eval_sdio_sd.c
+ * @author MCD Application Team
+ * @version V5.1.0
+ * @date 18-January-2013
+ * @brief This file provides a set of functions needed to manage the SDIO SD
+ * Card memory mounted on STM3210E-EVAL evaluation board.
+ *
+ *
+ * @verbatim
+ *
+ * ===================================================================
+ * How to use this driver
+ * ===================================================================
+ * It implements a high level communication layer for read and write
+ * from/to this memory. The needed STM32 hardware resources (SDIO and
+ * GPIO) are defined in stm3210e_eval.h file, and the initialization is
+ * performed in SD_LowLevel_Init() function declared in stm3210e_eval.c
+ * file.
+ * You can easily tailor this driver to any other development board,
+ * by just adapting the defines for hardware resources and
+ * SD_LowLevel_Init() function.
+ *
+ * A - SD Card Initialization and configuration
+ * ============================================
+ * - To initialize the SD Card, use the SD_Init() function. It
+ * Initializes the SD Card and put it into StandBy State (Ready
+ * for data transfer). This function provide the following operations:
+ *
+ * 1 - Apply the SD Card initialization process at 400KHz and check
+ * the SD Card type (Standard Capacity or High Capacity). You
+ * can change or adapt this frequency by adjusting the
+ * "SDIO_INIT_CLK_DIV" define inside the stm3210e_eval.h file.
+ * The SD Card frequency (SDIO_CK) is computed as follows:
+ *
+ * +---------------------------------------------+
+ * | SDIO_CK = SDIOCLK / (SDIO_INIT_CLK_DIV + 2) |
+ * +---------------------------------------------+
+ *
+ * In initialization mode and according to the SD Card standard,
+ * make sure that the SDIO_CK frequency don't exceed 400KHz.
+ *
+ * 2 - Get the SD CID and CSD data. All these information are
+ * managed by the SDCardInfo structure. This structure provide
+ * also ready computed SD Card capacity and Block size.
+ *
+ * 3 - Configure the SD Card Data transfer frequency. By Default,
+ * the card transfer frequency is set to 24MHz. You can change
+ * or adapt this frequency by adjusting the "SDIO_TRANSFER_CLK_DIV"
+ * define inside the stm3210e_eval.h file.
+ * The SD Card frequency (SDIO_CK) is computed as follows:
+ *
+ * +---------------------------------------------+
+ * | SDIO_CK = SDIOCLK / (SDIO_INIT_CLK_DIV + 2) |
+ * +---------------------------------------------+
+ *
+ * In transfer mode and according to the SD Card standard,
+ * make sure that the SDIO_CK frequency don't exceed 25MHz
+ * and 50MHz in High-speed mode switch.
+ * To be able to use a frequency higher than 24MHz, you should
+ * use the SDIO peripheral in bypass mode. Refer to the
+ * corresponding reference manual for more details.
+ *
+ * 4 - Select the corresponding SD Card according to the address
+ * read with the step 2.
+ *
+ * 5 - Configure the SD Card in wide bus mode: 4-bits data.
+ *
+ * B - SD Card Read operation
+ * ==========================
+ * - You can read SD card by using two function: SD_ReadBlock() and
+ * SD_ReadMultiBlocks() functions. These functions support only
+ * 512-byte block length.
+ * - The SD_ReadBlock() function read only one block (512-byte). This
+ * function can transfer the data using DMA controller or using
+ * polling mode. To select between DMA or polling mode refer to
+ * "SD_DMA_MODE" or "SD_POLLING_MODE" inside the stm3210e_eval_sdio_sd.h
+ * file and uncomment the corresponding line. By default the SD DMA
+ * mode is selected
+ * - The SD_ReadMultiBlocks() function read only mutli blocks (multiple
+ * of 512-byte).
+ * - Any read operation should be followed by two functions to check
+ * if the DMA Controller and SD Card status.
+ * - SD_ReadWaitOperation(): this function insure that the DMA
+ * controller has finished all data transfer.
+ * - SD_GetStatus(): to check that the SD Card has finished the
+ * data transfer and it is ready for data.
+ *
+ * - The DMA transfer is finished by the SDIO Data End interrupt.
+ * User has to call the SD_ProcessIRQ() function inside the SDIO_IRQHandler()
+ * and SD_ProcessDMAIRQ() function inside the DMA2_Channel4_5_IRQHandler().
+ * Don't forget to enable the SDIO_IRQn and DMA2_Channel4_5_IRQn
+ * interrupts using the NVIC controller.
+ *
+ * C - SD Card Write operation
+ * ===========================
+ * - You can write SD card by using two function: SD_WriteBlock() and
+ * SD_WriteMultiBlocks() functions. These functions support only
+ * 512-byte block length.
+ * - The SD_WriteBlock() function write only one block (512-byte). This
+ * function can transfer the data using DMA controller or using
+ * polling mode. To select between DMA or polling mode refer to
+ * "SD_DMA_MODE" or "SD_POLLING_MODE" inside the stm3210e_eval_sdio_sd.h
+ * file and uncomment the corresponding line. By default the SD DMA
+ * mode is selected
+ * - The SD_WriteMultiBlocks() function write only mutli blocks (multiple
+ * of 512-byte).
+ * - Any write operation should be followed by two functions to check
+ * if the DMA Controller and SD Card status.
+ * - SD_ReadWaitOperation(): this function insure that the DMA
+ * controller has finished all data transfer.
+ * - SD_GetStatus(): to check that the SD Card has finished the
+ * data transfer and it is ready for data.
+ *
+ * - The DMA transfer is finished by the SDIO Data End interrupt.
+ * User has to call the SD_ProcessIRQ() function inside the SDIO_IRQHandler()
+ * and SD_ProcessDMAIRQ() function inside the DMA2_Channel4_5_IRQHandler().
+ * Don't forget to enable the SDIO_IRQn and DMA2_Channel4_5_IRQn
+ * interrupts using the NVIC controller.
+ *
+ *
+ * D - SD card status
+ * ==================
+ * - At any time, you can check the SD Card status and get the SD card
+ * state by using the SD_GetStatus() function. This function checks
+ * first if the SD card is still connected and then get the internal
+ * SD Card transfer state.
+ * - You can also get the SD card SD Status register by using the
+ * SD_SendSDStatus() function.
+ *
+ * E - Programming Model (Selecting DMA for SDIO data Transfer)
+ * ============================================================
+ * Status = SD_Init(); // Initialization Step as described in section A
+ *
+ * // SDIO Interrupt ENABLE
+ * NVIC_InitStructure.NVIC_IRQChannel = SDIO_IRQn;
+ * NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
+ * NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
+ * NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
+ * NVIC_Init(&NVIC_InitStructure);
+ * // DMA2 Channel4 Interrupt ENABLE
+ * NVIC_InitStructure.NVIC_IRQChannel = SD_SDIO_DMA_IRQn;
+ * NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
+ * NVIC_Init(&NVIC_InitStructure);
+ *
+ * // Write operation as described in Section C
+ * Status = SD_WriteBlock(buffer, address, 512);
+ * Status = SD_WaitWriteOperation();
+ * while(SD_GetStatus() != SD_TRANSFER_OK);
+ *
+ * Status = SD_WriteMultiBlocks(buffer, address, 512, NUMBEROFBLOCKS);
+ * Status = SD_WaitWriteOperation();
+ * while(SD_GetStatus() != SD_TRANSFER_OK);
+ *
+ * // Read operation as described in Section B
+ * Status = SD_ReadBlock(buffer, address, 512);
+ * Status = SD_WaitReadOperation();
+ * while(SD_GetStatus() != SD_TRANSFER_OK);
+ *
+ * Status = SD_ReadMultiBlocks(buffer, address, 512, NUMBEROFBLOCKS);
+ * Status = SD_WaitReadOperation();
+ * while(SD_GetStatus() != SD_TRANSFER_OK);
+ *
+ * - Add the SDIO and DMA2 Channel4 IRQ Handlers:
+ * void SDIO_IRQHandler(void)
+ * {
+ * SD_ProcessIRQ();
+ * }
+ * void SD_SDIO_DMA_IRQHANDLER(void)
+ * {
+ * SD_ProcessDMAIRQ();
+ * }
+ *
+ * F - Programming Model (Selecting Polling for SDIO data Transfer)
+ * ================================================================
+ * //Only SD Card Single Block operation are managed.
+ * Status = SD_Init(); // Initialization Step as described in section
+ *
+ * // Write operation as described in Section C
+ * Status = SD_WriteBlock(buffer, address, 512);
+ *
+ * // Read operation as described in Section B
+ * Status = SD_ReadBlock(buffer, address, 512);
+ *
+ * STM32 SDIO Pin assignment
+ * =========================
+ * +-----------------------------------------------------------+
+ * | Pin assignment |
+ * +-----------------------------+---------------+-------------+
+ * | STM32 SDIO Pins | SD | Pin |
+ * +-----------------------------+---------------+-------------+
+ * | SDIO D2 | D2 | 1 |
+ * | SDIO D3 | D3 | 2 |
+ * | SDIO CMD | CMD | 3 |
+ * | | VCC | 4 (3.3 V)|
+ * | SDIO CLK | CLK | 5 |
+ * | | GND | 6 (0 V) |
+ * | SDIO D0 | D0 | 7 |
+ * | SDIO D1 | D1 | 8 |
+ * +-----------------------------+---------------+-------------+
+ *
+ * @endverbatim
+ *
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2013 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.st.com/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+
+/* Includes ------------------------------------------------------------------*/
+#include "stm3210e_eval_sdio_sd.h"
+
+
+/** @addtogroup Utilities
+ * @{
+ */
+
+/** @addtogroup STM32_EVAL
+ * @{
+ */
+
+/** @addtogroup STM3210E_EVAL
+ * @{
+ */
+
+/** @addtogroup STM3210E_EVAL_SDIO_SD
+ * @brief This file provides all the SD Card driver firmware functions.
+ * @{
+ */
+
+/** @defgroup STM3210E_EVAL_SDIO_SD_Private_Types
+ * @{
+ */
+/**
+ * @}
+ */
+
+
+/** @defgroup STM3210E_EVAL_SDIO_SD_Private_Defines
+ * @{
+ */
+
+/**
+ * @brief SDIO Static flags, TimeOut, FIFO Address
+ */
+#define NULL 0
+#define SDIO_STATIC_FLAGS ((uint32_t)0x000005FF)
+#define SDIO_CMD0TIMEOUT ((uint32_t)0x00010000)
+
+/**
+ * @brief Mask for errors Card Status R1 (OCR Register)
+ */
+#define SD_OCR_ADDR_OUT_OF_RANGE ((uint32_t)0x80000000)
+#define SD_OCR_ADDR_MISALIGNED ((uint32_t)0x40000000)
+#define SD_OCR_BLOCK_LEN_ERR ((uint32_t)0x20000000)
+#define SD_OCR_ERASE_SEQ_ERR ((uint32_t)0x10000000)
+#define SD_OCR_BAD_ERASE_PARAM ((uint32_t)0x08000000)
+#define SD_OCR_WRITE_PROT_VIOLATION ((uint32_t)0x04000000)
+#define SD_OCR_LOCK_UNLOCK_FAILED ((uint32_t)0x01000000)
+#define SD_OCR_COM_CRC_FAILED ((uint32_t)0x00800000)
+#define SD_OCR_ILLEGAL_CMD ((uint32_t)0x00400000)
+#define SD_OCR_CARD_ECC_FAILED ((uint32_t)0x00200000)
+#define SD_OCR_CC_ERROR ((uint32_t)0x00100000)
+#define SD_OCR_GENERAL_UNKNOWN_ERROR ((uint32_t)0x00080000)
+#define SD_OCR_STREAM_READ_UNDERRUN ((uint32_t)0x00040000)
+#define SD_OCR_STREAM_WRITE_OVERRUN ((uint32_t)0x00020000)
+#define SD_OCR_CID_CSD_OVERWRIETE ((uint32_t)0x00010000)
+#define SD_OCR_WP_ERASE_SKIP ((uint32_t)0x00008000)
+#define SD_OCR_CARD_ECC_DISABLED ((uint32_t)0x00004000)
+#define SD_OCR_ERASE_RESET ((uint32_t)0x00002000)
+#define SD_OCR_AKE_SEQ_ERROR ((uint32_t)0x00000008)
+#define SD_OCR_ERRORBITS ((uint32_t)0xFDFFE008)
+
+/**
+ * @brief Masks for R6 Response
+ */
+#define SD_R6_GENERAL_UNKNOWN_ERROR ((uint32_t)0x00002000)
+#define SD_R6_ILLEGAL_CMD ((uint32_t)0x00004000)
+#define SD_R6_COM_CRC_FAILED ((uint32_t)0x00008000)
+
+#define SD_VOLTAGE_WINDOW_SD ((uint32_t)0x80100000)
+#define SD_HIGH_CAPACITY ((uint32_t)0x40000000)
+#define SD_STD_CAPACITY ((uint32_t)0x00000000)
+#define SD_CHECK_PATTERN ((uint32_t)0x000001AA)
+
+#define SD_MAX_VOLT_TRIAL ((uint32_t)0x0000FFFF)
+#define SD_ALLZERO ((uint32_t)0x00000000)
+
+#define SD_WIDE_BUS_SUPPORT ((uint32_t)0x00040000)
+#define SD_SINGLE_BUS_SUPPORT ((uint32_t)0x00010000)
+#define SD_CARD_LOCKED ((uint32_t)0x02000000)
+
+#define SD_DATATIMEOUT ((uint32_t)0xFFFFFFFF)
+#define SD_0TO7BITS ((uint32_t)0x000000FF)
+#define SD_8TO15BITS ((uint32_t)0x0000FF00)
+#define SD_16TO23BITS ((uint32_t)0x00FF0000)
+#define SD_24TO31BITS ((uint32_t)0xFF000000)
+#define SD_MAX_DATA_LENGTH ((uint32_t)0x01FFFFFF)
+
+#define SD_HALFFIFO ((uint32_t)0x00000008)
+#define SD_HALFFIFOBYTES ((uint32_t)0x00000020)
+
+/**
+ * @brief Command Class Supported
+ */
+#define SD_CCCC_LOCK_UNLOCK ((uint32_t)0x00000080)
+#define SD_CCCC_WRITE_PROT ((uint32_t)0x00000040)
+#define SD_CCCC_ERASE ((uint32_t)0x00000020)
+
+/**
+ * @brief Following commands are SD Card Specific commands.
+ * SDIO_APP_CMD should be sent before sending these commands.
+ */
+#define SDIO_SEND_IF_COND ((uint32_t)0x00000008)
+
+/**
+ * @}
+ */
+
+/** @defgroup STM3210E_EVAL_SDIO_SD_Private_Macros
+ * @{
+ */
+/**
+ * @}
+ */
+
+/** @defgroup STM3210E_EVAL_SDIO_SD_Private_Variables
+ * @{
+ */
+
+static uint32_t CardType = SDIO_STD_CAPACITY_SD_CARD_V1_1;
+static uint32_t CSD_Tab[4], CID_Tab[4], RCA = 0;
+static uint8_t SDSTATUS_Tab[16];
+__IO uint32_t StopCondition = 0;
+__IO SD_Error TransferError = SD_OK;
+__IO uint32_t TransferEnd = 0, DMAEndOfTransfer = 0;
+SD_CardInfo SDCardInfo;
+
+SDIO_InitTypeDef SDIO_InitStructure;
+SDIO_CmdInitTypeDef SDIO_CmdInitStructure;
+SDIO_DataInitTypeDef SDIO_DataInitStructure;
+/**
+ * @}
+ */
+
+
+/** @defgroup STM3210E_EVAL_SDIO_SD_Private_Function_Prototypes
+ * @{
+ */
+static SD_Error CmdError(void);
+static SD_Error CmdResp1Error(uint8_t cmd);
+static SD_Error CmdResp7Error(void);
+static SD_Error CmdResp3Error(void);
+static SD_Error CmdResp2Error(void);
+static SD_Error CmdResp6Error(uint8_t cmd, uint16_t *prca);
+static SD_Error SDEnWideBus(FunctionalState NewState);
+static SD_Error IsCardProgramming(uint8_t *pstatus);
+static SD_Error FindSCR(uint16_t rca, uint32_t *pscr);
+uint8_t convert_from_bytes_to_power_of_two(uint16_t NumberOfBytes);
+
+/**
+ * @}
+ */
+
+
+/** @defgroup STM3210E_EVAL_SDIO_SD_Private_Functions
+ * @{
+ */
+
+/**
+ * @brief DeInitializes the SDIO interface.
+ * @param None
+ * @retval None
+ */
+void SD_DeInit(void)
+{
+ SD_LowLevel_DeInit();
+}
+
+/**
+ * @brief Initializes the SD Card and put it into StandBy State (Ready for data
+ * transfer).
+ * @param None
+ * @retval SD_Error: SD Card Error code.
+ */
+SD_Error SD_Init(void)
+{
+ __IO SD_Error errorstatus = SD_OK;
+
+ /* SDIO Peripheral Low Level Init */
+ SD_LowLevel_Init();
+
+ SDIO_DeInit();
+
+ errorstatus = SD_PowerON();
+
+ if (errorstatus != SD_OK)
+ {
+ /*!< CMD Response TimeOut (wait for CMDSENT flag) */
+ return(errorstatus);
+ }
+
+ errorstatus = SD_InitializeCards();
+
+ if (errorstatus != SD_OK)
+ {
+ /*!< CMD Response TimeOut (wait for CMDSENT flag) */
+ return(errorstatus);
+ }
+
+ /*!< Configure the SDIO peripheral */
+ /*!< SDIO_CK = SDIOCLK / (SDIO_TRANSFER_CLK_DIV + 2) */
+ SDIO_InitStructure.SDIO_ClockDiv = SDIO_TRANSFER_CLK_DIV;
+ SDIO_InitStructure.SDIO_ClockEdge = SDIO_ClockEdge_Rising;
+ SDIO_InitStructure.SDIO_ClockBypass = SDIO_ClockBypass_Disable;
+ SDIO_InitStructure.SDIO_ClockPowerSave = SDIO_ClockPowerSave_Disable;
+ SDIO_InitStructure.SDIO_BusWide = SDIO_BusWide_1b;
+ SDIO_InitStructure.SDIO_HardwareFlowControl = SDIO_HardwareFlowControl_Disable;
+ SDIO_Init(&SDIO_InitStructure);
+
+ /*----------------- Read CSD/CID MSD registers ------------------*/
+ errorstatus = SD_GetCardInfo(&SDCardInfo);
+
+ if (errorstatus == SD_OK)
+ {
+ /*----------------- Select Card --------------------------------*/
+ errorstatus = SD_SelectDeselect((uint32_t) (SDCardInfo.RCA << 16));
+ }
+
+ if (errorstatus == SD_OK)
+ {
+ errorstatus = SD_EnableWideBusOperation(SDIO_BusWide_4b);
+ }
+
+ return(errorstatus);
+}
+
+/**
+ * @brief Gets the cuurent sd card data transfer status.
+ * @param None
+ * @retval SDTransferState: Data Transfer state.
+ * This value can be:
+ * - SD_TRANSFER_OK: No data transfer is acting
+ * - SD_TRANSFER_BUSY: Data transfer is acting
+ */
+SDTransferState SD_GetStatus(void)
+{
+ SDCardState cardstate = SD_CARD_TRANSFER;
+
+ cardstate = SD_GetState();
+
+ if (cardstate == SD_CARD_TRANSFER)
+ {
+ return(SD_TRANSFER_OK);
+ }
+ else if(cardstate == SD_CARD_ERROR)
+ {
+ return (SD_TRANSFER_ERROR);
+ }
+ else
+ {
+ return(SD_TRANSFER_BUSY);
+ }
+}
+
+/**
+ * @brief Returns the current card's state.
+ * @param None
+ * @retval SDCardState: SD Card Error or SD Card Current State.
+ */
+SDCardState SD_GetState(void)
+{
+ uint32_t resp1 = 0;
+
+ if(SD_Detect()== SD_PRESENT)
+ {
+ if (SD_SendStatus(&resp1) != SD_OK)
+ {
+ return SD_CARD_ERROR;
+ }
+ else
+ {
+ return (SDCardState)((resp1 >> 9) & 0x0F);
+ }
+ }
+ else
+ {
+ return SD_CARD_ERROR;
+ }
+}
+
+/**
+ * @brief Detect if SD card is correctly plugged in the memory slot.
+ * @param None
+ * @retval Return if SD is detected or not
+ */
+uint8_t SD_Detect(void)
+{
+ __IO uint8_t status = SD_PRESENT;
+
+ /*!< Check GPIO to detect SD */
+ if (GPIO_ReadInputDataBit(SD_DETECT_GPIO_PORT, SD_DETECT_PIN) != Bit_RESET)
+ {
+ status = SD_NOT_PRESENT;
+ }
+ return status;
+}
+
+/**
+ * @brief Enquires cards about their operating voltage and configures
+ * clock controls.
+ * @param None
+ * @retval SD_Error: SD Card Error code.
+ */
+SD_Error SD_PowerON(void)
+{
+ __IO SD_Error errorstatus = SD_OK;
+ uint32_t response = 0, count = 0, validvoltage = 0;
+ uint32_t SDType = SD_STD_CAPACITY;
+
+ /*!< Power ON Sequence -----------------------------------------------------*/
+ /*!< Configure the SDIO peripheral */
+ /*!< SDIO_CK = SDIOCLK / (SDIO_INIT_CLK_DIV + 2) */
+ /*!< SDIO_CK for initialization should not exceed 400 KHz */
+ SDIO_InitStructure.SDIO_ClockDiv = SDIO_INIT_CLK_DIV;
+ SDIO_InitStructure.SDIO_ClockEdge = SDIO_ClockEdge_Rising;
+ SDIO_InitStructure.SDIO_ClockBypass = SDIO_ClockBypass_Disable;
+ SDIO_InitStructure.SDIO_ClockPowerSave = SDIO_ClockPowerSave_Disable;
+ SDIO_InitStructure.SDIO_BusWide = SDIO_BusWide_1b;
+ SDIO_InitStructure.SDIO_HardwareFlowControl = SDIO_HardwareFlowControl_Disable;
+ SDIO_Init(&SDIO_InitStructure);
+
+ /*!< Set Power State to ON */
+ SDIO_SetPowerState(SDIO_PowerState_ON);
+
+ /*!< Enable SDIO Clock */
+ SDIO_ClockCmd(ENABLE);
+
+ /*!< CMD0: GO_IDLE_STATE ---------------------------------------------------*/
+ /*!< No CMD response required */
+ SDIO_CmdInitStructure.SDIO_Argument = 0x0;
+ SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_GO_IDLE_STATE;
+ SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_No;
+ SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
+ SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
+ SDIO_SendCommand(&SDIO_CmdInitStructure);
+
+ errorstatus = CmdError();
+
+ if (errorstatus != SD_OK)
+ {
+ /*!< CMD Response TimeOut (wait for CMDSENT flag) */
+ return(errorstatus);
+ }
+
+ /*!< CMD8: SEND_IF_COND ----------------------------------------------------*/
+ /*!< Send CMD8 to verify SD card interface operating condition */
+ /*!< Argument: - [31:12]: Reserved (shall be set to '0')
+ - [11:8]: Supply Voltage (VHS) 0x1 (Range: 2.7-3.6 V)
+ - [7:0]: Check Pattern (recommended 0xAA) */
+ /*!< CMD Response: R7 */
+ SDIO_CmdInitStructure.SDIO_Argument = SD_CHECK_PATTERN;
+ SDIO_CmdInitStructure.SDIO_CmdIndex = SDIO_SEND_IF_COND;
+ SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
+ SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
+ SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
+ SDIO_SendCommand(&SDIO_CmdInitStructure);
+
+ errorstatus = CmdResp7Error();
+
+ if (errorstatus == SD_OK)
+ {
+ CardType = SDIO_STD_CAPACITY_SD_CARD_V2_0; /*!< SD Card 2.0 */
+ SDType = SD_HIGH_CAPACITY;
+ }
+ else
+ {
+ /*!< CMD55 */
+ SDIO_CmdInitStructure.SDIO_Argument = 0x00;
+ SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_APP_CMD;
+ SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
+ SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
+ SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
+ SDIO_SendCommand(&SDIO_CmdInitStructure);
+ errorstatus = CmdResp1Error(SD_CMD_APP_CMD);
+ }
+ /*!< CMD55 */
+ SDIO_CmdInitStructure.SDIO_Argument = 0x00;
+ SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_APP_CMD;
+ SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
+ SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
+ SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
+ SDIO_SendCommand(&SDIO_CmdInitStructure);
+ errorstatus = CmdResp1Error(SD_CMD_APP_CMD);
+
+ /*!< If errorstatus is Command TimeOut, it is a MMC card */
+ /*!< If errorstatus is SD_OK it is a SD card: SD card 2.0 (voltage range mismatch)
+ or SD card 1.x */
+ if (errorstatus == SD_OK)
+ {
+ /*!< SD CARD */
+ /*!< Send ACMD41 SD_APP_OP_COND with Argument 0x80100000 */
+ while ((!validvoltage) && (count < SD_MAX_VOLT_TRIAL))
+ {
+
+ /*!< SEND CMD55 APP_CMD with RCA as 0 */
+ SDIO_CmdInitStructure.SDIO_Argument = 0x00;
+ SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_APP_CMD;
+ SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
+ SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
+ SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
+ SDIO_SendCommand(&SDIO_CmdInitStructure);
+
+ errorstatus = CmdResp1Error(SD_CMD_APP_CMD);
+
+ if (errorstatus != SD_OK)
+ {
+ return(errorstatus);
+ }
+ SDIO_CmdInitStructure.SDIO_Argument = SD_VOLTAGE_WINDOW_SD | SDType;
+ SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_SD_APP_OP_COND;
+ SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
+ SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
+ SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
+ SDIO_SendCommand(&SDIO_CmdInitStructure);
+
+ errorstatus = CmdResp3Error();
+ if (errorstatus != SD_OK)
+ {
+ return(errorstatus);
+ }
+
+ response = SDIO_GetResponse(SDIO_RESP1);
+ validvoltage = (((response >> 31) == 1) ? 1 : 0);
+ count++;
+ }
+ if (count >= SD_MAX_VOLT_TRIAL)
+ {
+ errorstatus = SD_INVALID_VOLTRANGE;
+ return(errorstatus);
+ }
+
+ if (response &= SD_HIGH_CAPACITY)
+ {
+ CardType = SDIO_HIGH_CAPACITY_SD_CARD;
+ }
+
+ }/*!< else MMC Card */
+
+ return(errorstatus);
+}
+
+/**
+ * @brief Turns the SDIO output signals off.
+ * @param None
+ * @retval SD_Error: SD Card Error code.
+ */
+SD_Error SD_PowerOFF(void)
+{
+ SD_Error errorstatus = SD_OK;
+
+ /*!< Set Power State to OFF */
+ SDIO_SetPowerState(SDIO_PowerState_OFF);
+
+ return(errorstatus);
+}
+
+/**
+ * @brief Intialises all cards or single card as the case may be Card(s) come
+ * into standby state.
+ * @param None
+ * @retval SD_Error: SD Card Error code.
+ */
+SD_Error SD_InitializeCards(void)
+{
+ SD_Error errorstatus = SD_OK;
+ uint16_t rca = 0x01;
+
+ if (SDIO_GetPowerState() == SDIO_PowerState_OFF)
+ {
+ errorstatus = SD_REQUEST_NOT_APPLICABLE;
+ return(errorstatus);
+ }
+
+ if (SDIO_SECURE_DIGITAL_IO_CARD != CardType)
+ {
+ /*!< Send CMD2 ALL_SEND_CID */
+ SDIO_CmdInitStructure.SDIO_Argument = 0x0;
+ SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_ALL_SEND_CID;
+ SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Long;
+ SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
+ SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
+ SDIO_SendCommand(&SDIO_CmdInitStructure);
+
+ errorstatus = CmdResp2Error();
+
+ if (SD_OK != errorstatus)
+ {
+ return(errorstatus);
+ }
+
+ CID_Tab[0] = SDIO_GetResponse(SDIO_RESP1);
+ CID_Tab[1] = SDIO_GetResponse(SDIO_RESP2);
+ CID_Tab[2] = SDIO_GetResponse(SDIO_RESP3);
+ CID_Tab[3] = SDIO_GetResponse(SDIO_RESP4);
+ }
+ if ((SDIO_STD_CAPACITY_SD_CARD_V1_1 == CardType) || (SDIO_STD_CAPACITY_SD_CARD_V2_0 == CardType) || (SDIO_SECURE_DIGITAL_IO_COMBO_CARD == CardType)
+ || (SDIO_HIGH_CAPACITY_SD_CARD == CardType))
+ {
+ /*!< Send CMD3 SET_REL_ADDR with argument 0 */
+ /*!< SD Card publishes its RCA. */
+ SDIO_CmdInitStructure.SDIO_Argument = 0x00;
+ SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_SET_REL_ADDR;
+ SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
+ SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
+ SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
+ SDIO_SendCommand(&SDIO_CmdInitStructure);
+
+ errorstatus = CmdResp6Error(SD_CMD_SET_REL_ADDR, &rca);
+
+ if (SD_OK != errorstatus)
+ {
+ return(errorstatus);
+ }
+ }
+
+ if (SDIO_SECURE_DIGITAL_IO_CARD != CardType)
+ {
+ RCA = rca;
+
+ /*!< Send CMD9 SEND_CSD with argument as card's RCA */
+ SDIO_CmdInitStructure.SDIO_Argument = (uint32_t)(rca << 16);
+ SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_SEND_CSD;
+ SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Long;
+ SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
+ SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
+ SDIO_SendCommand(&SDIO_CmdInitStructure);
+
+ errorstatus = CmdResp2Error();
+
+ if (SD_OK != errorstatus)
+ {
+ return(errorstatus);
+ }
+
+ CSD_Tab[0] = SDIO_GetResponse(SDIO_RESP1);
+ CSD_Tab[1] = SDIO_GetResponse(SDIO_RESP2);
+ CSD_Tab[2] = SDIO_GetResponse(SDIO_RESP3);
+ CSD_Tab[3] = SDIO_GetResponse(SDIO_RESP4);
+ }
+
+ errorstatus = SD_OK; /*!< All cards get intialized */
+
+ return(errorstatus);
+}
+
+/**
+ * @brief Returns information about specific card.
+ * @param cardinfo: pointer to a SD_CardInfo structure that contains all SD card
+ * information.
+ * @retval SD_Error: SD Card Error code.
+ */
+SD_Error SD_GetCardInfo(SD_CardInfo *cardinfo)
+{
+ SD_Error errorstatus = SD_OK;
+ uint8_t tmp = 0;
+
+ cardinfo->CardType = (uint8_t)CardType;
+ cardinfo->RCA = (uint16_t)RCA;
+
+ /*!< Byte 0 */
+ tmp = (uint8_t)((CSD_Tab[0] & 0xFF000000) >> 24);
+ cardinfo->SD_csd.CSDStruct = (tmp & 0xC0) >> 6;
+ cardinfo->SD_csd.SysSpecVersion = (tmp & 0x3C) >> 2;
+ cardinfo->SD_csd.Reserved1 = tmp & 0x03;
+
+ /*!< Byte 1 */
+ tmp = (uint8_t)((CSD_Tab[0] & 0x00FF0000) >> 16);
+ cardinfo->SD_csd.TAAC = tmp;
+
+ /*!< Byte 2 */
+ tmp = (uint8_t)((CSD_Tab[0] & 0x0000FF00) >> 8);
+ cardinfo->SD_csd.NSAC = tmp;
+
+ /*!< Byte 3 */
+ tmp = (uint8_t)(CSD_Tab[0] & 0x000000FF);
+ cardinfo->SD_csd.MaxBusClkFrec = tmp;
+
+ /*!< Byte 4 */
+ tmp = (uint8_t)((CSD_Tab[1] & 0xFF000000) >> 24);
+ cardinfo->SD_csd.CardComdClasses = tmp << 4;
+
+ /*!< Byte 5 */
+ tmp = (uint8_t)((CSD_Tab[1] & 0x00FF0000) >> 16);
+ cardinfo->SD_csd.CardComdClasses |= (tmp & 0xF0) >> 4;
+ cardinfo->SD_csd.RdBlockLen = tmp & 0x0F;
+
+ /*!< Byte 6 */
+ tmp = (uint8_t)((CSD_Tab[1] & 0x0000FF00) >> 8);
+ cardinfo->SD_csd.PartBlockRead = (tmp & 0x80) >> 7;
+ cardinfo->SD_csd.WrBlockMisalign = (tmp & 0x40) >> 6;
+ cardinfo->SD_csd.RdBlockMisalign = (tmp & 0x20) >> 5;
+ cardinfo->SD_csd.DSRImpl = (tmp & 0x10) >> 4;
+ cardinfo->SD_csd.Reserved2 = 0; /*!< Reserved */
+
+ if ((CardType == SDIO_STD_CAPACITY_SD_CARD_V1_1) || (CardType == SDIO_STD_CAPACITY_SD_CARD_V2_0))
+ {
+ cardinfo->SD_csd.DeviceSize = (tmp & 0x03) << 10;
+
+ /*!< Byte 7 */
+ tmp = (uint8_t)(CSD_Tab[1] & 0x000000FF);
+ cardinfo->SD_csd.DeviceSize |= (tmp) << 2;
+
+ /*!< Byte 8 */
+ tmp = (uint8_t)((CSD_Tab[2] & 0xFF000000) >> 24);
+ cardinfo->SD_csd.DeviceSize |= (tmp & 0xC0) >> 6;
+
+ cardinfo->SD_csd.MaxRdCurrentVDDMin = (tmp & 0x38) >> 3;
+ cardinfo->SD_csd.MaxRdCurrentVDDMax = (tmp & 0x07);
+
+ /*!< Byte 9 */
+ tmp = (uint8_t)((CSD_Tab[2] & 0x00FF0000) >> 16);
+ cardinfo->SD_csd.MaxWrCurrentVDDMin = (tmp & 0xE0) >> 5;
+ cardinfo->SD_csd.MaxWrCurrentVDDMax = (tmp & 0x1C) >> 2;
+ cardinfo->SD_csd.DeviceSizeMul = (tmp & 0x03) << 1;
+ /*!< Byte 10 */
+ tmp = (uint8_t)((CSD_Tab[2] & 0x0000FF00) >> 8);
+ cardinfo->SD_csd.DeviceSizeMul |= (tmp & 0x80) >> 7;
+
+ cardinfo->CardCapacity = (cardinfo->SD_csd.DeviceSize + 1) ;
+ cardinfo->CardCapacity *= (1 << (cardinfo->SD_csd.DeviceSizeMul + 2));
+ cardinfo->CardBlockSize = 1 << (cardinfo->SD_csd.RdBlockLen);
+ cardinfo->CardCapacity *= cardinfo->CardBlockSize;
+ }
+ else if (CardType == SDIO_HIGH_CAPACITY_SD_CARD)
+ {
+ /*!< Byte 7 */
+ tmp = (uint8_t)(CSD_Tab[1] & 0x000000FF);
+ cardinfo->SD_csd.DeviceSize = (tmp & 0x3F) << 16;
+
+ /*!< Byte 8 */
+ tmp = (uint8_t)((CSD_Tab[2] & 0xFF000000) >> 24);
+
+ cardinfo->SD_csd.DeviceSize |= (tmp << 8);
+
+ /*!< Byte 9 */
+ tmp = (uint8_t)((CSD_Tab[2] & 0x00FF0000) >> 16);
+
+ cardinfo->SD_csd.DeviceSize |= (tmp);
+
+ /*!< Byte 10 */
+ tmp = (uint8_t)((CSD_Tab[2] & 0x0000FF00) >> 8);
+
+ cardinfo->CardCapacity = (cardinfo->SD_csd.DeviceSize + 1) * 512 * 1024;
+ cardinfo->CardBlockSize = 512;
+ }
+
+
+ cardinfo->SD_csd.EraseGrSize = (tmp & 0x40) >> 6;
+ cardinfo->SD_csd.EraseGrMul = (tmp & 0x3F) << 1;
+
+ /*!< Byte 11 */
+ tmp = (uint8_t)(CSD_Tab[2] & 0x000000FF);
+ cardinfo->SD_csd.EraseGrMul |= (tmp & 0x80) >> 7;
+ cardinfo->SD_csd.WrProtectGrSize = (tmp & 0x7F);
+
+ /*!< Byte 12 */
+ tmp = (uint8_t)((CSD_Tab[3] & 0xFF000000) >> 24);
+ cardinfo->SD_csd.WrProtectGrEnable = (tmp & 0x80) >> 7;
+ cardinfo->SD_csd.ManDeflECC = (tmp & 0x60) >> 5;
+ cardinfo->SD_csd.WrSpeedFact = (tmp & 0x1C) >> 2;
+ cardinfo->SD_csd.MaxWrBlockLen = (tmp & 0x03) << 2;
+
+ /*!< Byte 13 */
+ tmp = (uint8_t)((CSD_Tab[3] & 0x00FF0000) >> 16);
+ cardinfo->SD_csd.MaxWrBlockLen |= (tmp & 0xC0) >> 6;
+ cardinfo->SD_csd.WriteBlockPaPartial = (tmp & 0x20) >> 5;
+ cardinfo->SD_csd.Reserved3 = 0;
+ cardinfo->SD_csd.ContentProtectAppli = (tmp & 0x01);
+
+ /*!< Byte 14 */
+ tmp = (uint8_t)((CSD_Tab[3] & 0x0000FF00) >> 8);
+ cardinfo->SD_csd.FileFormatGrouop = (tmp & 0x80) >> 7;
+ cardinfo->SD_csd.CopyFlag = (tmp & 0x40) >> 6;
+ cardinfo->SD_csd.PermWrProtect = (tmp & 0x20) >> 5;
+ cardinfo->SD_csd.TempWrProtect = (tmp & 0x10) >> 4;
+ cardinfo->SD_csd.FileFormat = (tmp & 0x0C) >> 2;
+ cardinfo->SD_csd.ECC = (tmp & 0x03);
+
+ /*!< Byte 15 */
+ tmp = (uint8_t)(CSD_Tab[3] & 0x000000FF);
+ cardinfo->SD_csd.CSD_CRC = (tmp & 0xFE) >> 1;
+ cardinfo->SD_csd.Reserved4 = 1;
+
+
+ /*!< Byte 0 */
+ tmp = (uint8_t)((CID_Tab[0] & 0xFF000000) >> 24);
+ cardinfo->SD_cid.ManufacturerID = tmp;
+
+ /*!< Byte 1 */
+ tmp = (uint8_t)((CID_Tab[0] & 0x00FF0000) >> 16);
+ cardinfo->SD_cid.OEM_AppliID = tmp << 8;
+
+ /*!< Byte 2 */
+ tmp = (uint8_t)((CID_Tab[0] & 0x000000FF00) >> 8);
+ cardinfo->SD_cid.OEM_AppliID |= tmp;
+
+ /*!< Byte 3 */
+ tmp = (uint8_t)(CID_Tab[0] & 0x000000FF);
+ cardinfo->SD_cid.ProdName1 = tmp << 24;
+
+ /*!< Byte 4 */
+ tmp = (uint8_t)((CID_Tab[1] & 0xFF000000) >> 24);
+ cardinfo->SD_cid.ProdName1 |= tmp << 16;
+
+ /*!< Byte 5 */
+ tmp = (uint8_t)((CID_Tab[1] & 0x00FF0000) >> 16);
+ cardinfo->SD_cid.ProdName1 |= tmp << 8;
+
+ /*!< Byte 6 */
+ tmp = (uint8_t)((CID_Tab[1] & 0x0000FF00) >> 8);
+ cardinfo->SD_cid.ProdName1 |= tmp;
+
+ /*!< Byte 7 */
+ tmp = (uint8_t)(CID_Tab[1] & 0x000000FF);
+ cardinfo->SD_cid.ProdName2 = tmp;
+
+ /*!< Byte 8 */
+ tmp = (uint8_t)((CID_Tab[2] & 0xFF000000) >> 24);
+ cardinfo->SD_cid.ProdRev = tmp;
+
+ /*!< Byte 9 */
+ tmp = (uint8_t)((CID_Tab[2] & 0x00FF0000) >> 16);
+ cardinfo->SD_cid.ProdSN = tmp << 24;
+
+ /*!< Byte 10 */
+ tmp = (uint8_t)((CID_Tab[2] & 0x0000FF00) >> 8);
+ cardinfo->SD_cid.ProdSN |= tmp << 16;
+
+ /*!< Byte 11 */
+ tmp = (uint8_t)(CID_Tab[2] & 0x000000FF);
+ cardinfo->SD_cid.ProdSN |= tmp << 8;
+
+ /*!< Byte 12 */
+ tmp = (uint8_t)((CID_Tab[3] & 0xFF000000) >> 24);
+ cardinfo->SD_cid.ProdSN |= tmp;
+
+ /*!< Byte 13 */
+ tmp = (uint8_t)((CID_Tab[3] & 0x00FF0000) >> 16);
+ cardinfo->SD_cid.Reserved1 |= (tmp & 0xF0) >> 4;
+ cardinfo->SD_cid.ManufactDate = (tmp & 0x0F) << 8;
+
+ /*!< Byte 14 */
+ tmp = (uint8_t)((CID_Tab[3] & 0x0000FF00) >> 8);
+ cardinfo->SD_cid.ManufactDate |= tmp;
+
+ /*!< Byte 15 */
+ tmp = (uint8_t)(CID_Tab[3] & 0x000000FF);
+ cardinfo->SD_cid.CID_CRC = (tmp & 0xFE) >> 1;
+ cardinfo->SD_cid.Reserved2 = 1;
+
+ return(errorstatus);
+}
+
+/**
+ * @brief Enables wide bus opeartion for the requeseted card if supported by
+ * card.
+ * @param WideMode: Specifies the SD card wide bus mode.
+ * This parameter can be one of the following values:
+ * @arg SDIO_BusWide_8b: 8-bit data transfer (Only for MMC)
+ * @arg SDIO_BusWide_4b: 4-bit data transfer
+ * @arg SDIO_BusWide_1b: 1-bit data transfer
+ * @retval SD_Error: SD Card Error code.
+ */
+SD_Error SD_GetCardStatus(SD_CardStatus *cardstatus)
+{
+ SD_Error errorstatus = SD_OK;
+ uint8_t tmp = 0;
+
+ errorstatus = SD_SendSDStatus((uint32_t *)SDSTATUS_Tab);
+
+ if (errorstatus != SD_OK)
+ {
+ return(errorstatus);
+ }
+
+ /*!< Byte 0 */
+ tmp = (uint8_t)((SDSTATUS_Tab[0] & 0xC0) >> 6);
+ cardstatus->DAT_BUS_WIDTH = tmp;
+
+ /*!< Byte 0 */
+ tmp = (uint8_t)((SDSTATUS_Tab[0] & 0x20) >> 5);
+ cardstatus->SECURED_MODE = tmp;
+
+ /*!< Byte 2 */
+ tmp = (uint8_t)((SDSTATUS_Tab[2] & 0xFF));
+ cardstatus->SD_CARD_TYPE = tmp << 8;
+
+ /*!< Byte 3 */
+ tmp = (uint8_t)((SDSTATUS_Tab[3] & 0xFF));
+ cardstatus->SD_CARD_TYPE |= tmp;
+
+ /*!< Byte 4 */
+ tmp = (uint8_t)(SDSTATUS_Tab[4] & 0xFF);
+ cardstatus->SIZE_OF_PROTECTED_AREA = tmp << 24;
+
+ /*!< Byte 5 */
+ tmp = (uint8_t)(SDSTATUS_Tab[5] & 0xFF);
+ cardstatus->SIZE_OF_PROTECTED_AREA |= tmp << 16;
+
+ /*!< Byte 6 */
+ tmp = (uint8_t)(SDSTATUS_Tab[6] & 0xFF);
+ cardstatus->SIZE_OF_PROTECTED_AREA |= tmp << 8;
+
+ /*!< Byte 7 */
+ tmp = (uint8_t)(SDSTATUS_Tab[7] & 0xFF);
+ cardstatus->SIZE_OF_PROTECTED_AREA |= tmp;
+
+ /*!< Byte 8 */
+ tmp = (uint8_t)((SDSTATUS_Tab[8] & 0xFF));
+ cardstatus->SPEED_CLASS = tmp;
+
+ /*!< Byte 9 */
+ tmp = (uint8_t)((SDSTATUS_Tab[9] & 0xFF));
+ cardstatus->PERFORMANCE_MOVE = tmp;
+
+ /*!< Byte 10 */
+ tmp = (uint8_t)((SDSTATUS_Tab[10] & 0xF0) >> 4);
+ cardstatus->AU_SIZE = tmp;
+
+ /*!< Byte 11 */
+ tmp = (uint8_t)(SDSTATUS_Tab[11] & 0xFF);
+ cardstatus->ERASE_SIZE = tmp << 8;
+
+ /*!< Byte 12 */
+ tmp = (uint8_t)(SDSTATUS_Tab[12] & 0xFF);
+ cardstatus->ERASE_SIZE |= tmp;
+
+ /*!< Byte 13 */
+ tmp = (uint8_t)((SDSTATUS_Tab[13] & 0xFC) >> 2);
+ cardstatus->ERASE_TIMEOUT = tmp;
+
+ /*!< Byte 13 */
+ tmp = (uint8_t)((SDSTATUS_Tab[13] & 0x3));
+ cardstatus->ERASE_OFFSET = tmp;
+
+ return(errorstatus);
+}
+
+/**
+ * @brief Enables wide bus opeartion for the requeseted card if supported by
+ * card.
+ * @param WideMode: Specifies the SD card wide bus mode.
+ * This parameter can be one of the following values:
+ * @arg SDIO_BusWide_8b: 8-bit data transfer (Only for MMC)
+ * @arg SDIO_BusWide_4b: 4-bit data transfer
+ * @arg SDIO_BusWide_1b: 1-bit data transfer
+ * @retval SD_Error: SD Card Error code.
+ */
+SD_Error SD_EnableWideBusOperation(uint32_t WideMode)
+{
+ SD_Error errorstatus = SD_OK;
+
+ /*!< MMC Card doesn't support this feature */
+ if (SDIO_MULTIMEDIA_CARD == CardType)
+ {
+ errorstatus = SD_UNSUPPORTED_FEATURE;
+ return(errorstatus);
+ }
+ else if ((SDIO_STD_CAPACITY_SD_CARD_V1_1 == CardType) || (SDIO_STD_CAPACITY_SD_CARD_V2_0 == CardType) || (SDIO_HIGH_CAPACITY_SD_CARD == CardType))
+ {
+ if (SDIO_BusWide_8b == WideMode)
+ {
+ errorstatus = SD_UNSUPPORTED_FEATURE;
+ return(errorstatus);
+ }
+ else if (SDIO_BusWide_4b == WideMode)
+ {
+ errorstatus = SDEnWideBus(ENABLE);
+
+ if (SD_OK == errorstatus)
+ {
+ /*!< Configure the SDIO peripheral */
+ SDIO_InitStructure.SDIO_ClockDiv = SDIO_TRANSFER_CLK_DIV;
+ SDIO_InitStructure.SDIO_ClockEdge = SDIO_ClockEdge_Rising;
+ SDIO_InitStructure.SDIO_ClockBypass = SDIO_ClockBypass_Disable;
+ SDIO_InitStructure.SDIO_ClockPowerSave = SDIO_ClockPowerSave_Disable;
+ SDIO_InitStructure.SDIO_BusWide = SDIO_BusWide_4b;
+ SDIO_InitStructure.SDIO_HardwareFlowControl = SDIO_HardwareFlowControl_Disable;
+ SDIO_Init(&SDIO_InitStructure);
+ }
+ }
+ else
+ {
+ errorstatus = SDEnWideBus(DISABLE);
+
+ if (SD_OK == errorstatus)
+ {
+ /*!< Configure the SDIO peripheral */
+ SDIO_InitStructure.SDIO_ClockDiv = SDIO_TRANSFER_CLK_DIV;
+ SDIO_InitStructure.SDIO_ClockEdge = SDIO_ClockEdge_Rising;
+ SDIO_InitStructure.SDIO_ClockBypass = SDIO_ClockBypass_Disable;
+ SDIO_InitStructure.SDIO_ClockPowerSave = SDIO_ClockPowerSave_Disable;
+ SDIO_InitStructure.SDIO_BusWide = SDIO_BusWide_1b;
+ SDIO_InitStructure.SDIO_HardwareFlowControl = SDIO_HardwareFlowControl_Disable;
+ SDIO_Init(&SDIO_InitStructure);
+ }
+ }
+ }
+
+ return(errorstatus);
+}
+
+/**
+ * @brief Selects od Deselects the corresponding card.
+ * @param addr: Address of the Card to be selected.
+ * @retval SD_Error: SD Card Error code.
+ */
+SD_Error SD_SelectDeselect(uint32_t addr)
+{
+ SD_Error errorstatus = SD_OK;
+
+ /*!< Send CMD7 SDIO_SEL_DESEL_CARD */
+ SDIO_CmdInitStructure.SDIO_Argument = addr;
+ SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_SEL_DESEL_CARD;
+ SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
+ SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
+ SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
+ SDIO_SendCommand(&SDIO_CmdInitStructure);
+
+ errorstatus = CmdResp1Error(SD_CMD_SEL_DESEL_CARD);
+
+ return(errorstatus);
+}
+
+/**
+ * @brief Allows to read one block from a specified address in a card. The Data
+ * transfer can be managed by DMA mode or Polling mode.
+ * @note This operation should be followed by two functions to check if the
+ * DMA Controller and SD Card status.
+ * - SD_ReadWaitOperation(): this function insure that the DMA
+ * controller has finished all data transfer.
+ * - SD_GetStatus(): to check that the SD Card has finished the
+ * data transfer and it is ready for data.
+ * @param readbuff: pointer to the buffer that will contain the received data
+ * @param ReadAddr: Address from where data are to be read.
+ * @param BlockSize: the SD card Data block size. The Block size should be 512.
+ * @retval SD_Error: SD Card Error code.
+ */
+SD_Error SD_ReadBlock(uint8_t *readbuff, uint64_t ReadAddr, uint16_t BlockSize)
+{
+ SD_Error errorstatus = SD_OK;
+#if defined (SD_POLLING_MODE)
+ uint32_t count = 0, *tempbuff = (uint32_t *)readbuff;
+#endif
+
+ TransferError = SD_OK;
+ TransferEnd = 0;
+ StopCondition = 0;
+
+ SDIO->DCTRL = 0x0;
+
+
+ if (CardType == SDIO_HIGH_CAPACITY_SD_CARD)
+ {
+ BlockSize = 512;
+ ReadAddr /= 512;
+ }
+
+ /* Set Block Size for Card */
+ SDIO_CmdInitStructure.SDIO_Argument = (uint32_t) BlockSize;
+ SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_SET_BLOCKLEN;
+ SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
+ SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
+ SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
+ SDIO_SendCommand(&SDIO_CmdInitStructure);
+
+ errorstatus = CmdResp1Error(SD_CMD_SET_BLOCKLEN);
+
+ if (SD_OK != errorstatus)
+ {
+ return(errorstatus);
+ }
+
+ SDIO_DataInitStructure.SDIO_DataTimeOut = SD_DATATIMEOUT;
+ SDIO_DataInitStructure.SDIO_DataLength = BlockSize;
+ SDIO_DataInitStructure.SDIO_DataBlockSize = (uint32_t) 9 << 4;
+ SDIO_DataInitStructure.SDIO_TransferDir = SDIO_TransferDir_ToSDIO;
+ SDIO_DataInitStructure.SDIO_TransferMode = SDIO_TransferMode_Block;
+ SDIO_DataInitStructure.SDIO_DPSM = SDIO_DPSM_Enable;
+ SDIO_DataConfig(&SDIO_DataInitStructure);
+
+ /*!< Send CMD17 READ_SINGLE_BLOCK */
+ SDIO_CmdInitStructure.SDIO_Argument = (uint32_t)ReadAddr;
+ SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_READ_SINGLE_BLOCK;
+ SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
+ SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
+ SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
+ SDIO_SendCommand(&SDIO_CmdInitStructure);
+
+ errorstatus = CmdResp1Error(SD_CMD_READ_SINGLE_BLOCK);
+
+ if (errorstatus != SD_OK)
+ {
+ return(errorstatus);
+ }
+
+#if defined (SD_POLLING_MODE)
+ /*!< In case of single block transfer, no need of stop transfer at all.*/
+ /*!< Polling mode */
+ while (!(SDIO->STA &(SDIO_FLAG_RXOVERR | SDIO_FLAG_DCRCFAIL | SDIO_FLAG_DTIMEOUT | SDIO_FLAG_DBCKEND | SDIO_FLAG_STBITERR)))
+ {
+ if (SDIO_GetFlagStatus(SDIO_FLAG_RXFIFOHF) != RESET)
+ {
+ for (count = 0; count < 8; count++)
+ {
+ *(tempbuff + count) = SDIO_ReadData();
+ }
+ tempbuff += 8;
+ }
+ }
+
+ if (SDIO_GetFlagStatus(SDIO_FLAG_DTIMEOUT) != RESET)
+ {
+ SDIO_ClearFlag(SDIO_FLAG_DTIMEOUT);
+ errorstatus = SD_DATA_TIMEOUT;
+ return(errorstatus);
+ }
+ else if (SDIO_GetFlagStatus(SDIO_FLAG_DCRCFAIL) != RESET)
+ {
+ SDIO_ClearFlag(SDIO_FLAG_DCRCFAIL);
+ errorstatus = SD_DATA_CRC_FAIL;
+ return(errorstatus);
+ }
+ else if (SDIO_GetFlagStatus(SDIO_FLAG_RXOVERR) != RESET)
+ {
+ SDIO_ClearFlag(SDIO_FLAG_RXOVERR);
+ errorstatus = SD_RX_OVERRUN;
+ return(errorstatus);
+ }
+ else if (SDIO_GetFlagStatus(SDIO_FLAG_STBITERR) != RESET)
+ {
+ SDIO_ClearFlag(SDIO_FLAG_STBITERR);
+ errorstatus = SD_START_BIT_ERR;
+ return(errorstatus);
+ }
+ count = SD_DATATIMEOUT;
+ while ((SDIO_GetFlagStatus(SDIO_FLAG_RXDAVL) != RESET) && (count > 0))
+ {
+ *tempbuff = SDIO_ReadData();
+ tempbuff++;
+ count--;
+ }
+
+ /*!< Clear all the static flags */
+ SDIO_ClearFlag(SDIO_STATIC_FLAGS);
+
+#elif defined (SD_DMA_MODE)
+ SDIO_ITConfig(SDIO_IT_DCRCFAIL | SDIO_IT_DTIMEOUT | SDIO_IT_DATAEND | SDIO_IT_RXOVERR | SDIO_IT_STBITERR, ENABLE);
+ SDIO_DMACmd(ENABLE);
+ SD_LowLevel_DMA_RxConfig((uint32_t *)readbuff, BlockSize);
+#endif
+
+ return(errorstatus);
+}
+
+/**
+ * @brief Allows to read blocks from a specified address in a card. The Data
+ * transfer can be managed by DMA mode or Polling mode.
+ * @note This operation should be followed by two functions to check if the
+ * DMA Controller and SD Card status.
+ * - SD_ReadWaitOperation(): this function insure that the DMA
+ * controller has finished all data transfer.
+ * - SD_GetStatus(): to check that the SD Card has finished the
+ * data transfer and it is ready for data.
+ * @param readbuff: pointer to the buffer that will contain the received data.
+ * @param ReadAddr: Address from where data are to be read.
+ * @param BlockSize: the SD card Data block size. The Block size should be 512.
+ * @param NumberOfBlocks: number of blocks to be read.
+ * @retval SD_Error: SD Card Error code.
+ */
+SD_Error SD_ReadMultiBlocks(uint8_t *readbuff, uint64_t ReadAddr, uint16_t BlockSize, uint32_t NumberOfBlocks)
+{
+ SD_Error errorstatus = SD_OK;
+ TransferError = SD_OK;
+ TransferEnd = 0;
+ StopCondition = 1;
+
+ SDIO->DCTRL = 0x0;
+
+ if (CardType == SDIO_HIGH_CAPACITY_SD_CARD)
+ {
+ BlockSize = 512;
+ ReadAddr /= 512;
+ }
+
+ /*!< Set Block Size for Card */
+ SDIO_CmdInitStructure.SDIO_Argument = (uint32_t) BlockSize;
+ SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_SET_BLOCKLEN;
+ SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
+ SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
+ SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
+ SDIO_SendCommand(&SDIO_CmdInitStructure);
+
+ errorstatus = CmdResp1Error(SD_CMD_SET_BLOCKLEN);
+
+ if (SD_OK != errorstatus)
+ {
+ return(errorstatus);
+ }
+
+ SDIO_DataInitStructure.SDIO_DataTimeOut = SD_DATATIMEOUT;
+ SDIO_DataInitStructure.SDIO_DataLength = NumberOfBlocks * BlockSize;
+ SDIO_DataInitStructure.SDIO_DataBlockSize = (uint32_t) 9 << 4;
+ SDIO_DataInitStructure.SDIO_TransferDir = SDIO_TransferDir_ToSDIO;
+ SDIO_DataInitStructure.SDIO_TransferMode = SDIO_TransferMode_Block;
+ SDIO_DataInitStructure.SDIO_DPSM = SDIO_DPSM_Enable;
+ SDIO_DataConfig(&SDIO_DataInitStructure);
+
+ /*!< Send CMD18 READ_MULT_BLOCK with argument data address */
+ SDIO_CmdInitStructure.SDIO_Argument = (uint32_t)ReadAddr;
+ SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_READ_MULT_BLOCK;
+ SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
+ SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
+ SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
+ SDIO_SendCommand(&SDIO_CmdInitStructure);
+
+ errorstatus = CmdResp1Error(SD_CMD_READ_MULT_BLOCK);
+
+ if (errorstatus != SD_OK)
+ {
+ return(errorstatus);
+ }
+
+ SDIO_ITConfig(SDIO_IT_DCRCFAIL | SDIO_IT_DTIMEOUT | SDIO_IT_DATAEND | SDIO_IT_RXOVERR | SDIO_IT_STBITERR, ENABLE);
+ SDIO_DMACmd(ENABLE);
+ SD_LowLevel_DMA_RxConfig((uint32_t *)readbuff, (NumberOfBlocks * BlockSize));
+
+ return(errorstatus);
+}
+
+/**
+ * @brief This function waits until the SDIO DMA data transfer is finished.
+ * This function should be called after SDIO_ReadMultiBlocks() function
+ * to insure that all data sent by the card are already transferred by
+ * the DMA controller.
+ * @param None.
+ * @retval SD_Error: SD Card Error code.
+ */
+SD_Error SD_WaitReadOperation(void)
+{
+ SD_Error errorstatus = SD_OK;
+ uint32_t timeout;
+
+ timeout = SD_DATATIMEOUT;
+
+ while ((DMAEndOfTransfer == 0x00) && (TransferEnd == 0) && (TransferError == SD_OK) && (timeout > 0))
+ {
+ timeout--;
+ }
+
+ DMAEndOfTransfer = 0x00;
+
+ timeout = SD_DATATIMEOUT;
+
+ while(((SDIO->STA & SDIO_FLAG_RXACT)) && (timeout > 0))
+ {
+ timeout--;
+ }
+
+ if (StopCondition == 1)
+ {
+ errorstatus = SD_StopTransfer();
+ }
+
+ if ((timeout == 0) && (errorstatus == SD_OK))
+ {
+ errorstatus = SD_DATA_TIMEOUT;
+ }
+
+ /*!< Clear all the static flags */
+ SDIO_ClearFlag(SDIO_STATIC_FLAGS);
+
+ if (TransferError != SD_OK)
+ {
+ return(TransferError);
+ }
+ else
+ {
+ return(errorstatus);
+ }
+}
+
+/**
+ * @brief Allows to write one block starting from a specified address in a card.
+ * The Data transfer can be managed by DMA mode or Polling mode.
+ * @note This operation should be followed by two functions to check if the
+ * DMA Controller and SD Card status.
+ * - SD_ReadWaitOperation(): this function insure that the DMA
+ * controller has finished all data transfer.
+ * - SD_GetStatus(): to check that the SD Card has finished the
+ * data transfer and it is ready for data.
+ * @param writebuff: pointer to the buffer that contain the data to be transferred.
+ * @param WriteAddr: Address from where data are to be read.
+ * @param BlockSize: the SD card Data block size. The Block size should be 512.
+ * @retval SD_Error: SD Card Error code.
+ */
+SD_Error SD_WriteBlock(uint8_t *writebuff, uint64_t WriteAddr, uint16_t BlockSize)
+{
+ SD_Error errorstatus = SD_OK;
+
+#if defined (SD_POLLING_MODE)
+ uint32_t bytestransferred = 0, count = 0, restwords = 0;
+ uint32_t *tempbuff = (uint32_t *)writebuff;
+#endif
+
+ TransferError = SD_OK;
+ TransferEnd = 0;
+ StopCondition = 0;
+
+ SDIO->DCTRL = 0x0;
+
+
+ if (CardType == SDIO_HIGH_CAPACITY_SD_CARD)
+ {
+ BlockSize = 512;
+ WriteAddr /= 512;
+ }
+
+ /* Set Block Size for Card */
+ SDIO_CmdInitStructure.SDIO_Argument = (uint32_t) BlockSize;
+ SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_SET_BLOCKLEN;
+ SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
+ SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
+ SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
+ SDIO_SendCommand(&SDIO_CmdInitStructure);
+
+ errorstatus = CmdResp1Error(SD_CMD_SET_BLOCKLEN);
+
+ if (SD_OK != errorstatus)
+ {
+ return(errorstatus);
+ }
+
+ /*!< Send CMD24 WRITE_SINGLE_BLOCK */
+ SDIO_CmdInitStructure.SDIO_Argument = WriteAddr;
+ SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_WRITE_SINGLE_BLOCK;
+ SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
+ SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
+ SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
+ SDIO_SendCommand(&SDIO_CmdInitStructure);
+
+ errorstatus = CmdResp1Error(SD_CMD_WRITE_SINGLE_BLOCK);
+
+ if (errorstatus != SD_OK)
+ {
+ return(errorstatus);
+ }
+
+ SDIO_DataInitStructure.SDIO_DataTimeOut = SD_DATATIMEOUT;
+ SDIO_DataInitStructure.SDIO_DataLength = BlockSize;
+ SDIO_DataInitStructure.SDIO_DataBlockSize = (uint32_t) 9 << 4;
+ SDIO_DataInitStructure.SDIO_TransferDir = SDIO_TransferDir_ToCard;
+ SDIO_DataInitStructure.SDIO_TransferMode = SDIO_TransferMode_Block;
+ SDIO_DataInitStructure.SDIO_DPSM = SDIO_DPSM_Enable;
+ SDIO_DataConfig(&SDIO_DataInitStructure);
+
+ /*!< In case of single data block transfer no need of stop command at all */
+#if defined (SD_POLLING_MODE)
+ while (!(SDIO->STA & (SDIO_FLAG_DBCKEND | SDIO_FLAG_TXUNDERR | SDIO_FLAG_DCRCFAIL | SDIO_FLAG_DTIMEOUT | SDIO_FLAG_STBITERR)))
+ {
+ if (SDIO_GetFlagStatus(SDIO_FLAG_TXFIFOHE) != RESET)
+ {
+ if ((512 - bytestransferred) < 32)
+ {
+ restwords = ((512 - bytestransferred) % 4 == 0) ? ((512 - bytestransferred) / 4) : (( 512 - bytestransferred) / 4 + 1);
+ for (count = 0; count < restwords; count++, tempbuff++, bytestransferred += 4)
+ {
+ SDIO_WriteData(*tempbuff);
+ }
+ }
+ else
+ {
+ for (count = 0; count < 8; count++)
+ {
+ SDIO_WriteData(*(tempbuff + count));
+ }
+ tempbuff += 8;
+ bytestransferred += 32;
+ }
+ }
+ }
+ if (SDIO_GetFlagStatus(SDIO_FLAG_DTIMEOUT) != RESET)
+ {
+ SDIO_ClearFlag(SDIO_FLAG_DTIMEOUT);
+ errorstatus = SD_DATA_TIMEOUT;
+ return(errorstatus);
+ }
+ else if (SDIO_GetFlagStatus(SDIO_FLAG_DCRCFAIL) != RESET)
+ {
+ SDIO_ClearFlag(SDIO_FLAG_DCRCFAIL);
+ errorstatus = SD_DATA_CRC_FAIL;
+ return(errorstatus);
+ }
+ else if (SDIO_GetFlagStatus(SDIO_FLAG_TXUNDERR) != RESET)
+ {
+ SDIO_ClearFlag(SDIO_FLAG_TXUNDERR);
+ errorstatus = SD_TX_UNDERRUN;
+ return(errorstatus);
+ }
+ else if (SDIO_GetFlagStatus(SDIO_FLAG_STBITERR) != RESET)
+ {
+ SDIO_ClearFlag(SDIO_FLAG_STBITERR);
+ errorstatus = SD_START_BIT_ERR;
+ return(errorstatus);
+ }
+#elif defined (SD_DMA_MODE)
+ SDIO_ITConfig(SDIO_IT_DCRCFAIL | SDIO_IT_DTIMEOUT | SDIO_IT_DATAEND | SDIO_IT_RXOVERR | SDIO_IT_STBITERR, ENABLE);
+ SD_LowLevel_DMA_TxConfig((uint32_t *)writebuff, BlockSize);
+ SDIO_DMACmd(ENABLE);
+#endif
+
+ return(errorstatus);
+}
+
+/**
+ * @brief Allows to write blocks starting from a specified address in a card.
+ * The Data transfer can be managed by DMA mode only.
+ * @note This operation should be followed by two functions to check if the
+ * DMA Controller and SD Card status.
+ * - SD_ReadWaitOperation(): this function insure that the DMA
+ * controller has finished all data transfer.
+ * - SD_GetStatus(): to check that the SD Card has finished the
+ * data transfer and it is ready for data.
+ * @param WriteAddr: Address from where data are to be read.
+ * @param writebuff: pointer to the buffer that contain the data to be transferred.
+ * @param BlockSize: the SD card Data block size. The Block size should be 512.
+ * @param NumberOfBlocks: number of blocks to be written.
+ * @retval SD_Error: SD Card Error code.
+ */
+SD_Error SD_WriteMultiBlocks(uint8_t *writebuff, uint64_t WriteAddr, uint16_t BlockSize, uint32_t NumberOfBlocks)
+{
+ SD_Error errorstatus = SD_OK;
+
+ TransferError = SD_OK;
+ TransferEnd = 0;
+ StopCondition = 1;
+
+ SDIO->DCTRL = 0x0;
+
+ if (CardType == SDIO_HIGH_CAPACITY_SD_CARD)
+ {
+ BlockSize = 512;
+ WriteAddr /= 512;
+ }
+
+ /* Set Block Size for Card */
+ SDIO_CmdInitStructure.SDIO_Argument = (uint32_t) BlockSize;
+ SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_SET_BLOCKLEN;
+ SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
+ SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
+ SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
+ SDIO_SendCommand(&SDIO_CmdInitStructure);
+
+ errorstatus = CmdResp1Error(SD_CMD_SET_BLOCKLEN);
+
+ if (SD_OK != errorstatus)
+ {
+ return(errorstatus);
+ }
+
+ /*!< To improve performance */
+ SDIO_CmdInitStructure.SDIO_Argument = (uint32_t) (RCA << 16);
+ SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_APP_CMD;
+ SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
+ SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
+ SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
+ SDIO_SendCommand(&SDIO_CmdInitStructure);
+
+
+ errorstatus = CmdResp1Error(SD_CMD_APP_CMD);
+
+ if (errorstatus != SD_OK)
+ {
+ return(errorstatus);
+ }
+ /*!< To improve performance */
+ SDIO_CmdInitStructure.SDIO_Argument = (uint32_t)NumberOfBlocks;
+ SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_SET_BLOCK_COUNT;
+ SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
+ SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
+ SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
+ SDIO_SendCommand(&SDIO_CmdInitStructure);
+
+ errorstatus = CmdResp1Error(SD_CMD_SET_BLOCK_COUNT);
+
+ if (errorstatus != SD_OK)
+ {
+ return(errorstatus);
+ }
+
+
+ /*!< Send CMD25 WRITE_MULT_BLOCK with argument data address */
+ SDIO_CmdInitStructure.SDIO_Argument = (uint32_t)WriteAddr;
+ SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_WRITE_MULT_BLOCK;
+ SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
+ SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
+ SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
+ SDIO_SendCommand(&SDIO_CmdInitStructure);
+
+ errorstatus = CmdResp1Error(SD_CMD_WRITE_MULT_BLOCK);
+
+ if (SD_OK != errorstatus)
+ {
+ return(errorstatus);
+ }
+
+ SDIO_DataInitStructure.SDIO_DataTimeOut = SD_DATATIMEOUT;
+ SDIO_DataInitStructure.SDIO_DataLength = NumberOfBlocks * BlockSize;
+ SDIO_DataInitStructure.SDIO_DataBlockSize = (uint32_t) 9 << 4;
+ SDIO_DataInitStructure.SDIO_TransferDir = SDIO_TransferDir_ToCard;
+ SDIO_DataInitStructure.SDIO_TransferMode = SDIO_TransferMode_Block;
+ SDIO_DataInitStructure.SDIO_DPSM = SDIO_DPSM_Enable;
+ SDIO_DataConfig(&SDIO_DataInitStructure);
+
+ SDIO_ITConfig(SDIO_IT_DCRCFAIL | SDIO_IT_DTIMEOUT | SDIO_IT_DATAEND | SDIO_IT_RXOVERR | SDIO_IT_STBITERR, ENABLE);
+ SDIO_DMACmd(ENABLE);
+ SD_LowLevel_DMA_TxConfig((uint32_t *)writebuff, (NumberOfBlocks * BlockSize));
+
+ return(errorstatus);
+}
+
+/**
+ * @brief This function waits until the SDIO DMA data transfer is finished.
+ * This function should be called after SDIO_WriteBlock() and
+ * SDIO_WriteMultiBlocks() function to insure that all data sent by the
+ * card are already transferred by the DMA controller.
+ * @param None.
+ * @retval SD_Error: SD Card Error code.
+ */
+SD_Error SD_WaitWriteOperation(void)
+{
+ SD_Error errorstatus = SD_OK;
+ uint32_t timeout;
+
+ timeout = SD_DATATIMEOUT;
+
+ while ((DMAEndOfTransfer == 0x00) && (TransferEnd == 0) && (TransferError == SD_OK) && (timeout > 0))
+ {
+ timeout--;
+ }
+
+ DMAEndOfTransfer = 0x00;
+
+ timeout = SD_DATATIMEOUT;
+
+ while(((SDIO->STA & SDIO_FLAG_TXACT)) && (timeout > 0))
+ {
+ timeout--;
+ }
+
+ if (StopCondition == 1)
+ {
+ errorstatus = SD_StopTransfer();
+ }
+
+ if ((timeout == 0) && (errorstatus == SD_OK))
+ {
+ errorstatus = SD_DATA_TIMEOUT;
+ }
+
+ /*!< Clear all the static flags */
+ SDIO_ClearFlag(SDIO_STATIC_FLAGS);
+
+ if (TransferError != SD_OK)
+ {
+ return(TransferError);
+ }
+ else
+ {
+ return(errorstatus);
+ }
+}
+
+/**
+ * @brief Gets the cuurent data transfer state.
+ * @param None
+ * @retval SDTransferState: Data Transfer state.
+ * This value can be:
+ * - SD_TRANSFER_OK: No data transfer is acting
+ * - SD_TRANSFER_BUSY: Data transfer is acting
+ */
+SDTransferState SD_GetTransferState(void)
+{
+ if (SDIO->STA & (SDIO_FLAG_TXACT | SDIO_FLAG_RXACT))
+ {
+ return(SD_TRANSFER_BUSY);
+ }
+ else
+ {
+ return(SD_TRANSFER_OK);
+ }
+}
+
+/**
+ * @brief Aborts an ongoing data transfer.
+ * @param None
+ * @retval SD_Error: SD Card Error code.
+ */
+SD_Error SD_StopTransfer(void)
+{
+ SD_Error errorstatus = SD_OK;
+
+ /*!< Send CMD12 STOP_TRANSMISSION */
+ SDIO_CmdInitStructure.SDIO_Argument = 0x0;
+ SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_STOP_TRANSMISSION;
+ SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
+ SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
+ SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
+ SDIO_SendCommand(&SDIO_CmdInitStructure);
+
+ errorstatus = CmdResp1Error(SD_CMD_STOP_TRANSMISSION);
+
+ return(errorstatus);
+}
+
+/**
+ * @brief Allows to erase memory area specified for the given card.
+ * @param startaddr: the start address.
+ * @param endaddr: the end address.
+ * @retval SD_Error: SD Card Error code.
+ */
+SD_Error SD_Erase(uint32_t startaddr, uint32_t endaddr)
+{
+ SD_Error errorstatus = SD_OK;
+ uint32_t delay = 0;
+ __IO uint32_t maxdelay = 0;
+ uint8_t cardstate = 0;
+
+ /*!< Check if the card coomnd class supports erase command */
+ if (((CSD_Tab[1] >> 20) & SD_CCCC_ERASE) == 0)
+ {
+ errorstatus = SD_REQUEST_NOT_APPLICABLE;
+ return(errorstatus);
+ }
+
+ maxdelay = 120000 / ((SDIO->CLKCR & 0xFF) + 2);
+
+ if (SDIO_GetResponse(SDIO_RESP1) & SD_CARD_LOCKED)
+ {
+ errorstatus = SD_LOCK_UNLOCK_FAILED;
+ return(errorstatus);
+ }
+
+ if (CardType == SDIO_HIGH_CAPACITY_SD_CARD)
+ {
+ startaddr /= 512;
+ endaddr /= 512;
+ }
+
+ /*!< According to sd-card spec 1.0 ERASE_GROUP_START (CMD32) and erase_group_end(CMD33) */
+ if ((SDIO_STD_CAPACITY_SD_CARD_V1_1 == CardType) || (SDIO_STD_CAPACITY_SD_CARD_V2_0 == CardType) || (SDIO_HIGH_CAPACITY_SD_CARD == CardType))
+ {
+ /*!< Send CMD32 SD_ERASE_GRP_START with argument as addr */
+ SDIO_CmdInitStructure.SDIO_Argument = startaddr;
+ SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_SD_ERASE_GRP_START;
+ SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
+ SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
+ SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
+ SDIO_SendCommand(&SDIO_CmdInitStructure);
+
+ errorstatus = CmdResp1Error(SD_CMD_SD_ERASE_GRP_START);
+ if (errorstatus != SD_OK)
+ {
+ return(errorstatus);
+ }
+
+ /*!< Send CMD33 SD_ERASE_GRP_END with argument as addr */
+ SDIO_CmdInitStructure.SDIO_Argument = endaddr;
+ SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_SD_ERASE_GRP_END;
+ SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
+ SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
+ SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
+ SDIO_SendCommand(&SDIO_CmdInitStructure);
+
+ errorstatus = CmdResp1Error(SD_CMD_SD_ERASE_GRP_END);
+ if (errorstatus != SD_OK)
+ {
+ return(errorstatus);
+ }
+ }
+
+ /*!< Send CMD38 ERASE */
+ SDIO_CmdInitStructure.SDIO_Argument = 0;
+ SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_ERASE;
+ SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
+ SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
+ SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
+ SDIO_SendCommand(&SDIO_CmdInitStructure);
+
+ errorstatus = CmdResp1Error(SD_CMD_ERASE);
+
+ if (errorstatus != SD_OK)
+ {
+ return(errorstatus);
+ }
+
+ for (delay = 0; delay < maxdelay; delay++)
+ {}
+
+ /*!< Wait till the card is in programming state */
+ errorstatus = IsCardProgramming(&cardstate);
+ delay = SD_DATATIMEOUT;
+ while ((delay > 0) && (errorstatus == SD_OK) && ((SD_CARD_PROGRAMMING == cardstate) || (SD_CARD_RECEIVING == cardstate)))
+ {
+ errorstatus = IsCardProgramming(&cardstate);
+ delay--;
+ }
+
+ return(errorstatus);
+}
+
+/**
+ * @brief Returns the current card's status.
+ * @param pcardstatus: pointer to the buffer that will contain the SD card
+ * status (Card Status register).
+ * @retval SD_Error: SD Card Error code.
+ */
+SD_Error SD_SendStatus(uint32_t *pcardstatus)
+{
+ SD_Error errorstatus = SD_OK;
+
+ if (pcardstatus == NULL)
+ {
+ errorstatus = SD_INVALID_PARAMETER;
+ return(errorstatus);
+ }
+
+ SDIO_CmdInitStructure.SDIO_Argument = (uint32_t) RCA << 16;
+ SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_SEND_STATUS;
+ SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
+ SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
+ SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
+ SDIO_SendCommand(&SDIO_CmdInitStructure);
+
+ errorstatus = CmdResp1Error(SD_CMD_SEND_STATUS);
+
+ if (errorstatus != SD_OK)
+ {
+ return(errorstatus);
+ }
+
+ *pcardstatus = SDIO_GetResponse(SDIO_RESP1);
+
+ return(errorstatus);
+}
+
+/**
+ * @brief Returns the current SD card's status.
+ * @param psdstatus: pointer to the buffer that will contain the SD card status
+ * (SD Status register).
+ * @retval SD_Error: SD Card Error code.
+ */
+SD_Error SD_SendSDStatus(uint32_t *psdstatus)
+{
+ SD_Error errorstatus = SD_OK;
+ uint32_t count = 0;
+
+ if (SDIO_GetResponse(SDIO_RESP1) & SD_CARD_LOCKED)
+ {
+ errorstatus = SD_LOCK_UNLOCK_FAILED;
+ return(errorstatus);
+ }
+
+ /*!< Set block size for card if it is not equal to current block size for card. */
+ SDIO_CmdInitStructure.SDIO_Argument = 64;
+ SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_SET_BLOCKLEN;
+ SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
+ SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
+ SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
+ SDIO_SendCommand(&SDIO_CmdInitStructure);
+
+ errorstatus = CmdResp1Error(SD_CMD_SET_BLOCKLEN);
+
+ if (errorstatus != SD_OK)
+ {
+ return(errorstatus);
+ }
+
+ /*!< CMD55 */
+ SDIO_CmdInitStructure.SDIO_Argument = (uint32_t) RCA << 16;
+ SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_APP_CMD;
+ SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
+ SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
+ SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
+ SDIO_SendCommand(&SDIO_CmdInitStructure);
+ errorstatus = CmdResp1Error(SD_CMD_APP_CMD);
+
+ if (errorstatus != SD_OK)
+ {
+ return(errorstatus);
+ }
+
+ SDIO_DataInitStructure.SDIO_DataTimeOut = SD_DATATIMEOUT;
+ SDIO_DataInitStructure.SDIO_DataLength = 64;
+ SDIO_DataInitStructure.SDIO_DataBlockSize = SDIO_DataBlockSize_64b;
+ SDIO_DataInitStructure.SDIO_TransferDir = SDIO_TransferDir_ToSDIO;
+ SDIO_DataInitStructure.SDIO_TransferMode = SDIO_TransferMode_Block;
+ SDIO_DataInitStructure.SDIO_DPSM = SDIO_DPSM_Enable;
+ SDIO_DataConfig(&SDIO_DataInitStructure);
+
+ /*!< Send ACMD13 SD_APP_STAUS with argument as card's RCA.*/
+ SDIO_CmdInitStructure.SDIO_Argument = 0;
+ SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_SD_APP_STAUS;
+ SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
+ SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
+ SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
+ SDIO_SendCommand(&SDIO_CmdInitStructure);
+ errorstatus = CmdResp1Error(SD_CMD_SD_APP_STAUS);
+
+ if (errorstatus != SD_OK)
+ {
+ return(errorstatus);
+ }
+
+ while (!(SDIO->STA &(SDIO_FLAG_RXOVERR | SDIO_FLAG_DCRCFAIL | SDIO_FLAG_DTIMEOUT | SDIO_FLAG_DBCKEND | SDIO_FLAG_STBITERR)))
+ {
+ if (SDIO_GetFlagStatus(SDIO_FLAG_RXFIFOHF) != RESET)
+ {
+ for (count = 0; count < 8; count++)
+ {
+ *(psdstatus + count) = SDIO_ReadData();
+ }
+ psdstatus += 8;
+ }
+ }
+
+ if (SDIO_GetFlagStatus(SDIO_FLAG_DTIMEOUT) != RESET)
+ {
+ SDIO_ClearFlag(SDIO_FLAG_DTIMEOUT);
+ errorstatus = SD_DATA_TIMEOUT;
+ return(errorstatus);
+ }
+ else if (SDIO_GetFlagStatus(SDIO_FLAG_DCRCFAIL) != RESET)
+ {
+ SDIO_ClearFlag(SDIO_FLAG_DCRCFAIL);
+ errorstatus = SD_DATA_CRC_FAIL;
+ return(errorstatus);
+ }
+ else if (SDIO_GetFlagStatus(SDIO_FLAG_RXOVERR) != RESET)
+ {
+ SDIO_ClearFlag(SDIO_FLAG_RXOVERR);
+ errorstatus = SD_RX_OVERRUN;
+ return(errorstatus);
+ }
+ else if (SDIO_GetFlagStatus(SDIO_FLAG_STBITERR) != RESET)
+ {
+ SDIO_ClearFlag(SDIO_FLAG_STBITERR);
+ errorstatus = SD_START_BIT_ERR;
+ return(errorstatus);
+ }
+
+ count = SD_DATATIMEOUT;
+ while ((SDIO_GetFlagStatus(SDIO_FLAG_RXDAVL) != RESET) && (count > 0))
+ {
+ *psdstatus = SDIO_ReadData();
+ psdstatus++;
+ count--;
+ }
+ /*!< Clear all the static status flags*/
+ SDIO_ClearFlag(SDIO_STATIC_FLAGS);
+
+ return(errorstatus);
+}
+
+/**
+ * @brief Allows to process all the interrupts that are high.
+ * @param None
+ * @retval SD_Error: SD Card Error code.
+ */
+SD_Error SD_ProcessIRQSrc(void)
+{
+ if (SDIO_GetITStatus(SDIO_IT_DATAEND) != RESET)
+ {
+ TransferError = SD_OK;
+ SDIO_ClearITPendingBit(SDIO_IT_DATAEND);
+ TransferEnd = 1;
+ }
+ else if (SDIO_GetITStatus(SDIO_IT_DCRCFAIL) != RESET)
+ {
+ SDIO_ClearITPendingBit(SDIO_IT_DCRCFAIL);
+ TransferError = SD_DATA_CRC_FAIL;
+ }
+ else if (SDIO_GetITStatus(SDIO_IT_DTIMEOUT) != RESET)
+ {
+ SDIO_ClearITPendingBit(SDIO_IT_DTIMEOUT);
+ TransferError = SD_DATA_TIMEOUT;
+ }
+ else if (SDIO_GetITStatus(SDIO_IT_RXOVERR) != RESET)
+ {
+ SDIO_ClearITPendingBit(SDIO_IT_RXOVERR);
+ TransferError = SD_RX_OVERRUN;
+ }
+ else if (SDIO_GetITStatus(SDIO_IT_TXUNDERR) != RESET)
+ {
+ SDIO_ClearITPendingBit(SDIO_IT_TXUNDERR);
+ TransferError = SD_TX_UNDERRUN;
+ }
+ else if (SDIO_GetITStatus(SDIO_IT_STBITERR) != RESET)
+ {
+ SDIO_ClearITPendingBit(SDIO_IT_STBITERR);
+ TransferError = SD_START_BIT_ERR;
+ }
+
+ SDIO_ITConfig(SDIO_IT_DCRCFAIL | SDIO_IT_DTIMEOUT | SDIO_IT_DATAEND |
+ SDIO_IT_TXFIFOHE | SDIO_IT_RXFIFOHF | SDIO_IT_TXUNDERR |
+ SDIO_IT_RXOVERR | SDIO_IT_STBITERR, DISABLE);
+ return(TransferError);
+}
+
+/**
+ * @brief This function waits until the SDIO DMA data transfer is finished.
+ * @param None.
+ * @retval None.
+ */
+void SD_ProcessDMAIRQ(void)
+{
+ if(DMA2->ISR & DMA2_FLAG_TC4)
+ {
+ DMAEndOfTransfer = 0x01;
+ DMA_ClearFlag(DMA2_FLAG_TC4 | DMA2_FLAG_TE4 | DMA2_FLAG_HT4 | DMA2_FLAG_GL4);
+ }
+}
+
+/**
+ * @brief Checks for error conditions for CMD0.
+ * @param None
+ * @retval SD_Error: SD Card Error code.
+ */
+static SD_Error CmdError(void)
+{
+ SD_Error errorstatus = SD_OK;
+ uint32_t timeout;
+
+ timeout = SDIO_CMD0TIMEOUT; /*!< 10000 */
+
+ while ((timeout > 0) && (SDIO_GetFlagStatus(SDIO_FLAG_CMDSENT) == RESET))
+ {
+ timeout--;
+ }
+
+ if (timeout == 0)
+ {
+ errorstatus = SD_CMD_RSP_TIMEOUT;
+ return(errorstatus);
+ }
+
+ /*!< Clear all the static flags */
+ SDIO_ClearFlag(SDIO_STATIC_FLAGS);
+
+ return(errorstatus);
+}
+
+/**
+ * @brief Checks for error conditions for R7 response.
+ * @param None
+ * @retval SD_Error: SD Card Error code.
+ */
+static SD_Error CmdResp7Error(void)
+{
+ SD_Error errorstatus = SD_OK;
+ uint32_t status;
+ uint32_t timeout = SDIO_CMD0TIMEOUT;
+
+ status = SDIO->STA;
+
+ while (!(status & (SDIO_FLAG_CCRCFAIL | SDIO_FLAG_CMDREND | SDIO_FLAG_CTIMEOUT)) && (timeout > 0))
+ {
+ timeout--;
+ status = SDIO->STA;
+ }
+
+ if ((timeout == 0) || (status & SDIO_FLAG_CTIMEOUT))
+ {
+ /*!< Card is not V2.0 complient or card does not support the set voltage range */
+ errorstatus = SD_CMD_RSP_TIMEOUT;
+ SDIO_ClearFlag(SDIO_FLAG_CTIMEOUT);
+ return(errorstatus);
+ }
+
+ if (status & SDIO_FLAG_CMDREND)
+ {
+ /*!< Card is SD V2.0 compliant */
+ errorstatus = SD_OK;
+ SDIO_ClearFlag(SDIO_FLAG_CMDREND);
+ return(errorstatus);
+ }
+ return(errorstatus);
+}
+
+/**
+ * @brief Checks for error conditions for R1 response.
+ * @param cmd: The sent command index.
+ * @retval SD_Error: SD Card Error code.
+ */
+static SD_Error CmdResp1Error(uint8_t cmd)
+{
+ SD_Error errorstatus = SD_OK;
+ uint32_t status;
+ uint32_t response_r1;
+
+ status = SDIO->STA;
+
+ while (!(status & (SDIO_FLAG_CCRCFAIL | SDIO_FLAG_CMDREND | SDIO_FLAG_CTIMEOUT)))
+ {
+ status = SDIO->STA;
+ }
+
+ if (status & SDIO_FLAG_CTIMEOUT)
+ {
+ errorstatus = SD_CMD_RSP_TIMEOUT;
+ SDIO_ClearFlag(SDIO_FLAG_CTIMEOUT);
+ return(errorstatus);
+ }
+ else if (status & SDIO_FLAG_CCRCFAIL)
+ {
+ errorstatus = SD_CMD_CRC_FAIL;
+ SDIO_ClearFlag(SDIO_FLAG_CCRCFAIL);
+ return(errorstatus);
+ }
+
+ /*!< Check response received is of desired command */
+ if (SDIO_GetCommandResponse() != cmd)
+ {
+ errorstatus = SD_ILLEGAL_CMD;
+ return(errorstatus);
+ }
+
+ /*!< Clear all the static flags */
+ SDIO_ClearFlag(SDIO_STATIC_FLAGS);
+
+ /*!< We have received response, retrieve it for analysis */
+ response_r1 = SDIO_GetResponse(SDIO_RESP1);
+
+ if ((response_r1 & SD_OCR_ERRORBITS) == SD_ALLZERO)
+ {
+ return(errorstatus);
+ }
+
+ if (response_r1 & SD_OCR_ADDR_OUT_OF_RANGE)
+ {
+ return(SD_ADDR_OUT_OF_RANGE);
+ }
+
+ if (response_r1 & SD_OCR_ADDR_MISALIGNED)
+ {
+ return(SD_ADDR_MISALIGNED);
+ }
+
+ if (response_r1 & SD_OCR_BLOCK_LEN_ERR)
+ {
+ return(SD_BLOCK_LEN_ERR);
+ }
+
+ if (response_r1 & SD_OCR_ERASE_SEQ_ERR)
+ {
+ return(SD_ERASE_SEQ_ERR);
+ }
+
+ if (response_r1 & SD_OCR_BAD_ERASE_PARAM)
+ {
+ return(SD_BAD_ERASE_PARAM);
+ }
+
+ if (response_r1 & SD_OCR_WRITE_PROT_VIOLATION)
+ {
+ return(SD_WRITE_PROT_VIOLATION);
+ }
+
+ if (response_r1 & SD_OCR_LOCK_UNLOCK_FAILED)
+ {
+ return(SD_LOCK_UNLOCK_FAILED);
+ }
+
+ if (response_r1 & SD_OCR_COM_CRC_FAILED)
+ {
+ return(SD_COM_CRC_FAILED);
+ }
+
+ if (response_r1 & SD_OCR_ILLEGAL_CMD)
+ {
+ return(SD_ILLEGAL_CMD);
+ }
+
+ if (response_r1 & SD_OCR_CARD_ECC_FAILED)
+ {
+ return(SD_CARD_ECC_FAILED);
+ }
+
+ if (response_r1 & SD_OCR_CC_ERROR)
+ {
+ return(SD_CC_ERROR);
+ }
+
+ if (response_r1 & SD_OCR_GENERAL_UNKNOWN_ERROR)
+ {
+ return(SD_GENERAL_UNKNOWN_ERROR);
+ }
+
+ if (response_r1 & SD_OCR_STREAM_READ_UNDERRUN)
+ {
+ return(SD_STREAM_READ_UNDERRUN);
+ }
+
+ if (response_r1 & SD_OCR_STREAM_WRITE_OVERRUN)
+ {
+ return(SD_STREAM_WRITE_OVERRUN);
+ }
+
+ if (response_r1 & SD_OCR_CID_CSD_OVERWRIETE)
+ {
+ return(SD_CID_CSD_OVERWRITE);
+ }
+
+ if (response_r1 & SD_OCR_WP_ERASE_SKIP)
+ {
+ return(SD_WP_ERASE_SKIP);
+ }
+
+ if (response_r1 & SD_OCR_CARD_ECC_DISABLED)
+ {
+ return(SD_CARD_ECC_DISABLED);
+ }
+
+ if (response_r1 & SD_OCR_ERASE_RESET)
+ {
+ return(SD_ERASE_RESET);
+ }
+
+ if (response_r1 & SD_OCR_AKE_SEQ_ERROR)
+ {
+ return(SD_AKE_SEQ_ERROR);
+ }
+ return(errorstatus);
+}
+
+/**
+ * @brief Checks for error conditions for R3 (OCR) response.
+ * @param None
+ * @retval SD_Error: SD Card Error code.
+ */
+static SD_Error CmdResp3Error(void)
+{
+ SD_Error errorstatus = SD_OK;
+ uint32_t status;
+
+ status = SDIO->STA;
+
+ while (!(status & (SDIO_FLAG_CCRCFAIL | SDIO_FLAG_CMDREND | SDIO_FLAG_CTIMEOUT)))
+ {
+ status = SDIO->STA;
+ }
+
+ if (status & SDIO_FLAG_CTIMEOUT)
+ {
+ errorstatus = SD_CMD_RSP_TIMEOUT;
+ SDIO_ClearFlag(SDIO_FLAG_CTIMEOUT);
+ return(errorstatus);
+ }
+ /*!< Clear all the static flags */
+ SDIO_ClearFlag(SDIO_STATIC_FLAGS);
+ return(errorstatus);
+}
+
+/**
+ * @brief Checks for error conditions for R2 (CID or CSD) response.
+ * @param None
+ * @retval SD_Error: SD Card Error code.
+ */
+static SD_Error CmdResp2Error(void)
+{
+ SD_Error errorstatus = SD_OK;
+ uint32_t status;
+
+ status = SDIO->STA;
+
+ while (!(status & (SDIO_FLAG_CCRCFAIL | SDIO_FLAG_CTIMEOUT | SDIO_FLAG_CMDREND)))
+ {
+ status = SDIO->STA;
+ }
+
+ if (status & SDIO_FLAG_CTIMEOUT)
+ {
+ errorstatus = SD_CMD_RSP_TIMEOUT;
+ SDIO_ClearFlag(SDIO_FLAG_CTIMEOUT);
+ return(errorstatus);
+ }
+ else if (status & SDIO_FLAG_CCRCFAIL)
+ {
+ errorstatus = SD_CMD_CRC_FAIL;
+ SDIO_ClearFlag(SDIO_FLAG_CCRCFAIL);
+ return(errorstatus);
+ }
+
+ /*!< Clear all the static flags */
+ SDIO_ClearFlag(SDIO_STATIC_FLAGS);
+
+ return(errorstatus);
+}
+
+/**
+ * @brief Checks for error conditions for R6 (RCA) response.
+ * @param cmd: The sent command index.
+ * @param prca: pointer to the variable that will contain the SD card relative
+ * address RCA.
+ * @retval SD_Error: SD Card Error code.
+ */
+static SD_Error CmdResp6Error(uint8_t cmd, uint16_t *prca)
+{
+ SD_Error errorstatus = SD_OK;
+ uint32_t status;
+ uint32_t response_r1;
+
+ status = SDIO->STA;
+
+ while (!(status & (SDIO_FLAG_CCRCFAIL | SDIO_FLAG_CTIMEOUT | SDIO_FLAG_CMDREND)))
+ {
+ status = SDIO->STA;
+ }
+
+ if (status & SDIO_FLAG_CTIMEOUT)
+ {
+ errorstatus = SD_CMD_RSP_TIMEOUT;
+ SDIO_ClearFlag(SDIO_FLAG_CTIMEOUT);
+ return(errorstatus);
+ }
+ else if (status & SDIO_FLAG_CCRCFAIL)
+ {
+ errorstatus = SD_CMD_CRC_FAIL;
+ SDIO_ClearFlag(SDIO_FLAG_CCRCFAIL);
+ return(errorstatus);
+ }
+
+ /*!< Check response received is of desired command */
+ if (SDIO_GetCommandResponse() != cmd)
+ {
+ errorstatus = SD_ILLEGAL_CMD;
+ return(errorstatus);
+ }
+
+ /*!< Clear all the static flags */
+ SDIO_ClearFlag(SDIO_STATIC_FLAGS);
+
+ /*!< We have received response, retrieve it. */
+ response_r1 = SDIO_GetResponse(SDIO_RESP1);
+
+ if (SD_ALLZERO == (response_r1 & (SD_R6_GENERAL_UNKNOWN_ERROR | SD_R6_ILLEGAL_CMD | SD_R6_COM_CRC_FAILED)))
+ {
+ *prca = (uint16_t) (response_r1 >> 16);
+ return(errorstatus);
+ }
+
+ if (response_r1 & SD_R6_GENERAL_UNKNOWN_ERROR)
+ {
+ return(SD_GENERAL_UNKNOWN_ERROR);
+ }
+
+ if (response_r1 & SD_R6_ILLEGAL_CMD)
+ {
+ return(SD_ILLEGAL_CMD);
+ }
+
+ if (response_r1 & SD_R6_COM_CRC_FAILED)
+ {
+ return(SD_COM_CRC_FAILED);
+ }
+
+ return(errorstatus);
+}
+
+/**
+ * @brief Enables or disables the SDIO wide bus mode.
+ * @param NewState: new state of the SDIO wide bus mode.
+ * This parameter can be: ENABLE or DISABLE.
+ * @retval SD_Error: SD Card Error code.
+ */
+static SD_Error SDEnWideBus(FunctionalState NewState)
+{
+ SD_Error errorstatus = SD_OK;
+
+ uint32_t scr[2] = {0, 0};
+
+ if (SDIO_GetResponse(SDIO_RESP1) & SD_CARD_LOCKED)
+ {
+ errorstatus = SD_LOCK_UNLOCK_FAILED;
+ return(errorstatus);
+ }
+
+ /*!< Get SCR Register */
+ errorstatus = FindSCR((uint16_t)RCA, scr);
+
+ if (errorstatus != SD_OK)
+ {
+ return(errorstatus);
+ }
+
+ /*!< If wide bus operation to be enabled */
+ if (NewState == ENABLE)
+ {
+ /*!< If requested card supports wide bus operation */
+ if ((scr[1] & SD_WIDE_BUS_SUPPORT) != SD_ALLZERO)
+ {
+ /*!< Send CMD55 APP_CMD with argument as card's RCA.*/
+ SDIO_CmdInitStructure.SDIO_Argument = (uint32_t) RCA << 16;
+ SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_APP_CMD;
+ SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
+ SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
+ SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
+ SDIO_SendCommand(&SDIO_CmdInitStructure);
+
+ errorstatus = CmdResp1Error(SD_CMD_APP_CMD);
+
+ if (errorstatus != SD_OK)
+ {
+ return(errorstatus);
+ }
+
+ /*!< Send ACMD6 APP_CMD with argument as 2 for wide bus mode */
+ SDIO_CmdInitStructure.SDIO_Argument = 0x2;
+ SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_APP_SD_SET_BUSWIDTH;
+ SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
+ SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
+ SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
+ SDIO_SendCommand(&SDIO_CmdInitStructure);
+
+ errorstatus = CmdResp1Error(SD_CMD_APP_SD_SET_BUSWIDTH);
+
+ if (errorstatus != SD_OK)
+ {
+ return(errorstatus);
+ }
+ return(errorstatus);
+ }
+ else
+ {
+ errorstatus = SD_REQUEST_NOT_APPLICABLE;
+ return(errorstatus);
+ }
+ } /*!< If wide bus operation to be disabled */
+ else
+ {
+ /*!< If requested card supports 1 bit mode operation */
+ if ((scr[1] & SD_SINGLE_BUS_SUPPORT) != SD_ALLZERO)
+ {
+ /*!< Send CMD55 APP_CMD with argument as card's RCA.*/
+ SDIO_CmdInitStructure.SDIO_Argument = (uint32_t) RCA << 16;
+ SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_APP_CMD;
+ SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
+ SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
+ SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
+ SDIO_SendCommand(&SDIO_CmdInitStructure);
+
+
+ errorstatus = CmdResp1Error(SD_CMD_APP_CMD);
+
+ if (errorstatus != SD_OK)
+ {
+ return(errorstatus);
+ }
+
+ /*!< Send ACMD6 APP_CMD with argument as 2 for wide bus mode */
+ SDIO_CmdInitStructure.SDIO_Argument = 0x00;
+ SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_APP_SD_SET_BUSWIDTH;
+ SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
+ SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
+ SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
+ SDIO_SendCommand(&SDIO_CmdInitStructure);
+
+ errorstatus = CmdResp1Error(SD_CMD_APP_SD_SET_BUSWIDTH);
+
+ if (errorstatus != SD_OK)
+ {
+ return(errorstatus);
+ }
+
+ return(errorstatus);
+ }
+ else
+ {
+ errorstatus = SD_REQUEST_NOT_APPLICABLE;
+ return(errorstatus);
+ }
+ }
+}
+
+/**
+ * @brief Checks if the SD card is in programming state.
+ * @param pstatus: pointer to the variable that will contain the SD card state.
+ * @retval SD_Error: SD Card Error code.
+ */
+static SD_Error IsCardProgramming(uint8_t *pstatus)
+{
+ SD_Error errorstatus = SD_OK;
+ __IO uint32_t respR1 = 0, status = 0;
+
+ SDIO_CmdInitStructure.SDIO_Argument = (uint32_t) RCA << 16;
+ SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_SEND_STATUS;
+ SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
+ SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
+ SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
+ SDIO_SendCommand(&SDIO_CmdInitStructure);
+
+ status = SDIO->STA;
+ while (!(status & (SDIO_FLAG_CCRCFAIL | SDIO_FLAG_CMDREND | SDIO_FLAG_CTIMEOUT)))
+ {
+ status = SDIO->STA;
+ }
+
+ if (status & SDIO_FLAG_CTIMEOUT)
+ {
+ errorstatus = SD_CMD_RSP_TIMEOUT;
+ SDIO_ClearFlag(SDIO_FLAG_CTIMEOUT);
+ return(errorstatus);
+ }
+ else if (status & SDIO_FLAG_CCRCFAIL)
+ {
+ errorstatus = SD_CMD_CRC_FAIL;
+ SDIO_ClearFlag(SDIO_FLAG_CCRCFAIL);
+ return(errorstatus);
+ }
+
+ status = (uint32_t)SDIO_GetCommandResponse();
+
+ /*!< Check response received is of desired command */
+ if (status != SD_CMD_SEND_STATUS)
+ {
+ errorstatus = SD_ILLEGAL_CMD;
+ return(errorstatus);
+ }
+
+ /*!< Clear all the static flags */
+ SDIO_ClearFlag(SDIO_STATIC_FLAGS);
+
+
+ /*!< We have received response, retrieve it for analysis */
+ respR1 = SDIO_GetResponse(SDIO_RESP1);
+
+ /*!< Find out card status */
+ *pstatus = (uint8_t) ((respR1 >> 9) & 0x0000000F);
+
+ if ((respR1 & SD_OCR_ERRORBITS) == SD_ALLZERO)
+ {
+ return(errorstatus);
+ }
+
+ if (respR1 & SD_OCR_ADDR_OUT_OF_RANGE)
+ {
+ return(SD_ADDR_OUT_OF_RANGE);
+ }
+
+ if (respR1 & SD_OCR_ADDR_MISALIGNED)
+ {
+ return(SD_ADDR_MISALIGNED);
+ }
+
+ if (respR1 & SD_OCR_BLOCK_LEN_ERR)
+ {
+ return(SD_BLOCK_LEN_ERR);
+ }
+
+ if (respR1 & SD_OCR_ERASE_SEQ_ERR)
+ {
+ return(SD_ERASE_SEQ_ERR);
+ }
+
+ if (respR1 & SD_OCR_BAD_ERASE_PARAM)
+ {
+ return(SD_BAD_ERASE_PARAM);
+ }
+
+ if (respR1 & SD_OCR_WRITE_PROT_VIOLATION)
+ {
+ return(SD_WRITE_PROT_VIOLATION);
+ }
+
+ if (respR1 & SD_OCR_LOCK_UNLOCK_FAILED)
+ {
+ return(SD_LOCK_UNLOCK_FAILED);
+ }
+
+ if (respR1 & SD_OCR_COM_CRC_FAILED)
+ {
+ return(SD_COM_CRC_FAILED);
+ }
+
+ if (respR1 & SD_OCR_ILLEGAL_CMD)
+ {
+ return(SD_ILLEGAL_CMD);
+ }
+
+ if (respR1 & SD_OCR_CARD_ECC_FAILED)
+ {
+ return(SD_CARD_ECC_FAILED);
+ }
+
+ if (respR1 & SD_OCR_CC_ERROR)
+ {
+ return(SD_CC_ERROR);
+ }
+
+ if (respR1 & SD_OCR_GENERAL_UNKNOWN_ERROR)
+ {
+ return(SD_GENERAL_UNKNOWN_ERROR);
+ }
+
+ if (respR1 & SD_OCR_STREAM_READ_UNDERRUN)
+ {
+ return(SD_STREAM_READ_UNDERRUN);
+ }
+
+ if (respR1 & SD_OCR_STREAM_WRITE_OVERRUN)
+ {
+ return(SD_STREAM_WRITE_OVERRUN);
+ }
+
+ if (respR1 & SD_OCR_CID_CSD_OVERWRIETE)
+ {
+ return(SD_CID_CSD_OVERWRITE);
+ }
+
+ if (respR1 & SD_OCR_WP_ERASE_SKIP)
+ {
+ return(SD_WP_ERASE_SKIP);
+ }
+
+ if (respR1 & SD_OCR_CARD_ECC_DISABLED)
+ {
+ return(SD_CARD_ECC_DISABLED);
+ }
+
+ if (respR1 & SD_OCR_ERASE_RESET)
+ {
+ return(SD_ERASE_RESET);
+ }
+
+ if (respR1 & SD_OCR_AKE_SEQ_ERROR)
+ {
+ return(SD_AKE_SEQ_ERROR);
+ }
+
+ return(errorstatus);
+}
+
+/**
+ * @brief Find the SD card SCR register value.
+ * @param rca: selected card address.
+ * @param pscr: pointer to the buffer that will contain the SCR value.
+ * @retval SD_Error: SD Card Error code.
+ */
+static SD_Error FindSCR(uint16_t rca, uint32_t *pscr)
+{
+ uint32_t index = 0;
+ SD_Error errorstatus = SD_OK;
+ uint32_t tempscr[2] = {0, 0};
+
+ /*!< Set Block Size To 8 Bytes */
+ /*!< Send CMD55 APP_CMD with argument as card's RCA */
+ SDIO_CmdInitStructure.SDIO_Argument = (uint32_t)8;
+ SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_SET_BLOCKLEN;
+ SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
+ SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
+ SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
+ SDIO_SendCommand(&SDIO_CmdInitStructure);
+
+ errorstatus = CmdResp1Error(SD_CMD_SET_BLOCKLEN);
+
+ if (errorstatus != SD_OK)
+ {
+ return(errorstatus);
+ }
+
+ /*!< Send CMD55 APP_CMD with argument as card's RCA */
+ SDIO_CmdInitStructure.SDIO_Argument = (uint32_t) RCA << 16;
+ SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_APP_CMD;
+ SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
+ SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
+ SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
+ SDIO_SendCommand(&SDIO_CmdInitStructure);
+
+ errorstatus = CmdResp1Error(SD_CMD_APP_CMD);
+
+ if (errorstatus != SD_OK)
+ {
+ return(errorstatus);
+ }
+ SDIO_DataInitStructure.SDIO_DataTimeOut = SD_DATATIMEOUT;
+ SDIO_DataInitStructure.SDIO_DataLength = 8;
+ SDIO_DataInitStructure.SDIO_DataBlockSize = SDIO_DataBlockSize_8b;
+ SDIO_DataInitStructure.SDIO_TransferDir = SDIO_TransferDir_ToSDIO;
+ SDIO_DataInitStructure.SDIO_TransferMode = SDIO_TransferMode_Block;
+ SDIO_DataInitStructure.SDIO_DPSM = SDIO_DPSM_Enable;
+ SDIO_DataConfig(&SDIO_DataInitStructure);
+
+
+ /*!< Send ACMD51 SD_APP_SEND_SCR with argument as 0 */
+ SDIO_CmdInitStructure.SDIO_Argument = 0x0;
+ SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_SD_APP_SEND_SCR;
+ SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
+ SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
+ SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
+ SDIO_SendCommand(&SDIO_CmdInitStructure);
+
+ errorstatus = CmdResp1Error(SD_CMD_SD_APP_SEND_SCR);
+
+ if (errorstatus != SD_OK)
+ {
+ return(errorstatus);
+ }
+
+ while (!(SDIO->STA & (SDIO_FLAG_RXOVERR | SDIO_FLAG_DCRCFAIL | SDIO_FLAG_DTIMEOUT | SDIO_FLAG_DBCKEND | SDIO_FLAG_STBITERR)))
+ {
+ if (SDIO_GetFlagStatus(SDIO_FLAG_RXDAVL) != RESET)
+ {
+ *(tempscr + index) = SDIO_ReadData();
+ index++;
+ }
+ }
+
+ if (SDIO_GetFlagStatus(SDIO_FLAG_DTIMEOUT) != RESET)
+ {
+ SDIO_ClearFlag(SDIO_FLAG_DTIMEOUT);
+ errorstatus = SD_DATA_TIMEOUT;
+ return(errorstatus);
+ }
+ else if (SDIO_GetFlagStatus(SDIO_FLAG_DCRCFAIL) != RESET)
+ {
+ SDIO_ClearFlag(SDIO_FLAG_DCRCFAIL);
+ errorstatus = SD_DATA_CRC_FAIL;
+ return(errorstatus);
+ }
+ else if (SDIO_GetFlagStatus(SDIO_FLAG_RXOVERR) != RESET)
+ {
+ SDIO_ClearFlag(SDIO_FLAG_RXOVERR);
+ errorstatus = SD_RX_OVERRUN;
+ return(errorstatus);
+ }
+ else if (SDIO_GetFlagStatus(SDIO_FLAG_STBITERR) != RESET)
+ {
+ SDIO_ClearFlag(SDIO_FLAG_STBITERR);
+ errorstatus = SD_START_BIT_ERR;
+ return(errorstatus);
+ }
+
+ /*!< Clear all the static flags */
+ SDIO_ClearFlag(SDIO_STATIC_FLAGS);
+
+ *(pscr + 1) = ((tempscr[0] & SD_0TO7BITS) << 24) | ((tempscr[0] & SD_8TO15BITS) << 8) | ((tempscr[0] & SD_16TO23BITS) >> 8) | ((tempscr[0] & SD_24TO31BITS) >> 24);
+
+ *(pscr) = ((tempscr[1] & SD_0TO7BITS) << 24) | ((tempscr[1] & SD_8TO15BITS) << 8) | ((tempscr[1] & SD_16TO23BITS) >> 8) | ((tempscr[1] & SD_24TO31BITS) >> 24);
+
+ return(errorstatus);
+}
+
+/**
+ * @brief Converts the number of bytes in power of two and returns the power.
+ * @param NumberOfBytes: number of bytes.
+ * @retval None
+ */
+uint8_t convert_from_bytes_to_power_of_two(uint16_t NumberOfBytes)
+{
+ uint8_t count = 0;
+
+ while (NumberOfBytes != 1)
+ {
+ NumberOfBytes >>= 1;
+ count++;
+ }
+ return(count);
+}
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210E_EVAL/stm3210e_eval_sdio_sd.h b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210E_EVAL/stm3210e_eval_sdio_sd.h
new file mode 100644
index 0000000..e3e2252
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM3210E_EVAL/stm3210e_eval_sdio_sd.h
@@ -0,0 +1,406 @@
+/**
+ ******************************************************************************
+ * @file stm3210e_eval_sdio_sd.h
+ * @author MCD Application Team
+ * @version V5.1.0
+ * @date 18-January-2013
+ * @brief This file contains all the functions prototypes for the SD Card
+ * stm3210e_eval_sdio_sd driver firmware library.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2013 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.st.com/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __STM3210E_EVAL_SDIO_SD_H
+#define __STM3210E_EVAL_SDIO_SD_H
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+/* Includes ------------------------------------------------------------------*/
+#include "stm3210e_eval.h"
+
+/** @addtogroup Utilities
+ * @{
+ */
+
+/** @addtogroup STM32_EVAL
+ * @{
+ */
+
+/** @addtogroup STM3210E_EVAL
+ * @{
+ */
+
+/** @addtogroup STM3210E_EVAL_SDIO_SD
+ * @{
+ */
+
+/** @defgroup STM3210E_EVAL_SDIO_SD_Exported_Types
+ * @{
+ */
+typedef enum
+{
+/**
+ * @brief SDIO specific error defines
+ */
+ SD_CMD_CRC_FAIL = (1), /*!< Command response received (but CRC check failed) */
+ SD_DATA_CRC_FAIL = (2), /*!< Data bock sent/received (CRC check Failed) */
+ SD_CMD_RSP_TIMEOUT = (3), /*!< Command response timeout */
+ SD_DATA_TIMEOUT = (4), /*!< Data time out */
+ SD_TX_UNDERRUN = (5), /*!< Transmit FIFO under-run */
+ SD_RX_OVERRUN = (6), /*!< Receive FIFO over-run */
+ SD_START_BIT_ERR = (7), /*!< Start bit not detected on all data signals in widE bus mode */
+ SD_CMD_OUT_OF_RANGE = (8), /*!< CMD's argument was out of range.*/
+ SD_ADDR_MISALIGNED = (9), /*!< Misaligned address */
+ SD_BLOCK_LEN_ERR = (10), /*!< Transferred block length is not allowed for the card or the number of transferred bytes does not match the block length */
+ SD_ERASE_SEQ_ERR = (11), /*!< An error in the sequence of erase command occurs.*/
+ SD_BAD_ERASE_PARAM = (12), /*!< An Invalid selection for erase groups */
+ SD_WRITE_PROT_VIOLATION = (13), /*!< Attempt to program a write protect block */
+ SD_LOCK_UNLOCK_FAILED = (14), /*!< Sequence or password error has been detected in unlock command or if there was an attempt to access a locked card */
+ SD_COM_CRC_FAILED = (15), /*!< CRC check of the previous command failed */
+ SD_ILLEGAL_CMD = (16), /*!< Command is not legal for the card state */
+ SD_CARD_ECC_FAILED = (17), /*!< Card internal ECC was applied but failed to correct the data */
+ SD_CC_ERROR = (18), /*!< Internal card controller error */
+ SD_GENERAL_UNKNOWN_ERROR = (19), /*!< General or Unknown error */
+ SD_STREAM_READ_UNDERRUN = (20), /*!< The card could not sustain data transfer in stream read operation. */
+ SD_STREAM_WRITE_OVERRUN = (21), /*!< The card could not sustain data programming in stream mode */
+ SD_CID_CSD_OVERWRITE = (22), /*!< CID/CSD overwrite error */
+ SD_WP_ERASE_SKIP = (23), /*!< only partial address space was erased */
+ SD_CARD_ECC_DISABLED = (24), /*!< Command has been executed without using internal ECC */
+ SD_ERASE_RESET = (25), /*!< Erase sequence was cleared before executing because an out of erase sequence command was received */
+ SD_AKE_SEQ_ERROR = (26), /*!< Error in sequence of authentication. */
+ SD_INVALID_VOLTRANGE = (27),
+ SD_ADDR_OUT_OF_RANGE = (28),
+ SD_SWITCH_ERROR = (29),
+ SD_SDIO_DISABLED = (30),
+ SD_SDIO_FUNCTION_BUSY = (31),
+ SD_SDIO_FUNCTION_FAILED = (32),
+ SD_SDIO_UNKNOWN_FUNCTION = (33),
+
+/**
+ * @brief Standard error defines
+ */
+ SD_INTERNAL_ERROR,
+ SD_NOT_CONFIGURED,
+ SD_REQUEST_PENDING,
+ SD_REQUEST_NOT_APPLICABLE,
+ SD_INVALID_PARAMETER,
+ SD_UNSUPPORTED_FEATURE,
+ SD_UNSUPPORTED_HW,
+ SD_ERROR,
+ SD_OK = 0
+} SD_Error;
+
+/**
+ * @brief SDIO Transfer state
+ */
+typedef enum
+{
+ SD_TRANSFER_OK = 0,
+ SD_TRANSFER_BUSY = 1,
+ SD_TRANSFER_ERROR
+} SDTransferState;
+
+/**
+ * @brief SD Card States
+ */
+typedef enum
+{
+ SD_CARD_READY = ((uint32_t)0x00000001),
+ SD_CARD_IDENTIFICATION = ((uint32_t)0x00000002),
+ SD_CARD_STANDBY = ((uint32_t)0x00000003),
+ SD_CARD_TRANSFER = ((uint32_t)0x00000004),
+ SD_CARD_SENDING = ((uint32_t)0x00000005),
+ SD_CARD_RECEIVING = ((uint32_t)0x00000006),
+ SD_CARD_PROGRAMMING = ((uint32_t)0x00000007),
+ SD_CARD_DISCONNECTED = ((uint32_t)0x00000008),
+ SD_CARD_ERROR = ((uint32_t)0x000000FF)
+}SDCardState;
+
+
+/**
+ * @brief Card Specific Data: CSD Register
+ */
+typedef struct
+{
+ __IO uint8_t CSDStruct; /*!< CSD structure */
+ __IO uint8_t SysSpecVersion; /*!< System specification version */
+ __IO uint8_t Reserved1; /*!< Reserved */
+ __IO uint8_t TAAC; /*!< Data read access-time 1 */
+ __IO uint8_t NSAC; /*!< Data read access-time 2 in CLK cycles */
+ __IO uint8_t MaxBusClkFrec; /*!< Max. bus clock frequency */
+ __IO uint16_t CardComdClasses; /*!< Card command classes */
+ __IO uint8_t RdBlockLen; /*!< Max. read data block length */
+ __IO uint8_t PartBlockRead; /*!< Partial blocks for read allowed */
+ __IO uint8_t WrBlockMisalign; /*!< Write block misalignment */
+ __IO uint8_t RdBlockMisalign; /*!< Read block misalignment */
+ __IO uint8_t DSRImpl; /*!< DSR implemented */
+ __IO uint8_t Reserved2; /*!< Reserved */
+ __IO uint32_t DeviceSize; /*!< Device Size */
+ __IO uint8_t MaxRdCurrentVDDMin; /*!< Max. read current @ VDD min */
+ __IO uint8_t MaxRdCurrentVDDMax; /*!< Max. read current @ VDD max */
+ __IO uint8_t MaxWrCurrentVDDMin; /*!< Max. write current @ VDD min */
+ __IO uint8_t MaxWrCurrentVDDMax; /*!< Max. write current @ VDD max */
+ __IO uint8_t DeviceSizeMul; /*!< Device size multiplier */
+ __IO uint8_t EraseGrSize; /*!< Erase group size */
+ __IO uint8_t EraseGrMul; /*!< Erase group size multiplier */
+ __IO uint8_t WrProtectGrSize; /*!< Write protect group size */
+ __IO uint8_t WrProtectGrEnable; /*!< Write protect group enable */
+ __IO uint8_t ManDeflECC; /*!< Manufacturer default ECC */
+ __IO uint8_t WrSpeedFact; /*!< Write speed factor */
+ __IO uint8_t MaxWrBlockLen; /*!< Max. write data block length */
+ __IO uint8_t WriteBlockPaPartial; /*!< Partial blocks for write allowed */
+ __IO uint8_t Reserved3; /*!< Reserded */
+ __IO uint8_t ContentProtectAppli; /*!< Content protection application */
+ __IO uint8_t FileFormatGrouop; /*!< File format group */
+ __IO uint8_t CopyFlag; /*!< Copy flag (OTP) */
+ __IO uint8_t PermWrProtect; /*!< Permanent write protection */
+ __IO uint8_t TempWrProtect; /*!< Temporary write protection */
+ __IO uint8_t FileFormat; /*!< File Format */
+ __IO uint8_t ECC; /*!< ECC code */
+ __IO uint8_t CSD_CRC; /*!< CSD CRC */
+ __IO uint8_t Reserved4; /*!< always 1*/
+} SD_CSD;
+
+/**
+ * @brief Card Identification Data: CID Register
+ */
+typedef struct
+{
+ __IO uint8_t ManufacturerID; /*!< ManufacturerID */
+ __IO uint16_t OEM_AppliID; /*!< OEM/Application ID */
+ __IO uint32_t ProdName1; /*!< Product Name part1 */
+ __IO uint8_t ProdName2; /*!< Product Name part2*/
+ __IO uint8_t ProdRev; /*!< Product Revision */
+ __IO uint32_t ProdSN; /*!< Product Serial Number */
+ __IO uint8_t Reserved1; /*!< Reserved1 */
+ __IO uint16_t ManufactDate; /*!< Manufacturing Date */
+ __IO uint8_t CID_CRC; /*!< CID CRC */
+ __IO uint8_t Reserved2; /*!< always 1 */
+} SD_CID;
+
+/**
+ * @brief SD Card Status
+ */
+typedef struct
+{
+ __IO uint8_t DAT_BUS_WIDTH;
+ __IO uint8_t SECURED_MODE;
+ __IO uint16_t SD_CARD_TYPE;
+ __IO uint32_t SIZE_OF_PROTECTED_AREA;
+ __IO uint8_t SPEED_CLASS;
+ __IO uint8_t PERFORMANCE_MOVE;
+ __IO uint8_t AU_SIZE;
+ __IO uint16_t ERASE_SIZE;
+ __IO uint8_t ERASE_TIMEOUT;
+ __IO uint8_t ERASE_OFFSET;
+} SD_CardStatus;
+
+
+/**
+ * @brief SD Card information
+ */
+typedef struct
+{
+ SD_CSD SD_csd;
+ SD_CID SD_cid;
+ uint64_t CardCapacity; /*!< Card Capacity */
+ uint32_t CardBlockSize; /*!< Card Block Size */
+ uint16_t RCA;
+ uint8_t CardType;
+} SD_CardInfo;
+
+/**
+ * @}
+ */
+
+/** @defgroup STM3210E_EVAL_SDIO_SD_Exported_Constants
+ * @{
+ */
+
+/**
+ * @brief SDIO Commands Index
+ */
+#define SD_CMD_GO_IDLE_STATE ((uint8_t)0)
+#define SD_CMD_SEND_OP_COND ((uint8_t)1)
+#define SD_CMD_ALL_SEND_CID ((uint8_t)2)
+#define SD_CMD_SET_REL_ADDR ((uint8_t)3) /*!< SDIO_SEND_REL_ADDR for SD Card */
+#define SD_CMD_SET_DSR ((uint8_t)4)
+#define SD_CMD_SDIO_SEN_OP_COND ((uint8_t)5)
+#define SD_CMD_HS_SWITCH ((uint8_t)6)
+#define SD_CMD_SEL_DESEL_CARD ((uint8_t)7)
+#define SD_CMD_HS_SEND_EXT_CSD ((uint8_t)8)
+#define SD_CMD_SEND_CSD ((uint8_t)9)
+#define SD_CMD_SEND_CID ((uint8_t)10)
+#define SD_CMD_READ_DAT_UNTIL_STOP ((uint8_t)11) /*!< SD Card doesn't support it */
+#define SD_CMD_STOP_TRANSMISSION ((uint8_t)12)
+#define SD_CMD_SEND_STATUS ((uint8_t)13)
+#define SD_CMD_HS_BUSTEST_READ ((uint8_t)14)
+#define SD_CMD_GO_INACTIVE_STATE ((uint8_t)15)
+#define SD_CMD_SET_BLOCKLEN ((uint8_t)16)
+#define SD_CMD_READ_SINGLE_BLOCK ((uint8_t)17)
+#define SD_CMD_READ_MULT_BLOCK ((uint8_t)18)
+#define SD_CMD_HS_BUSTEST_WRITE ((uint8_t)19)
+#define SD_CMD_WRITE_DAT_UNTIL_STOP ((uint8_t)20) /*!< SD Card doesn't support it */
+#define SD_CMD_SET_BLOCK_COUNT ((uint8_t)23) /*!< SD Card doesn't support it */
+#define SD_CMD_WRITE_SINGLE_BLOCK ((uint8_t)24)
+#define SD_CMD_WRITE_MULT_BLOCK ((uint8_t)25)
+#define SD_CMD_PROG_CID ((uint8_t)26) /*!< reserved for manufacturers */
+#define SD_CMD_PROG_CSD ((uint8_t)27)
+#define SD_CMD_SET_WRITE_PROT ((uint8_t)28)
+#define SD_CMD_CLR_WRITE_PROT ((uint8_t)29)
+#define SD_CMD_SEND_WRITE_PROT ((uint8_t)30)
+#define SD_CMD_SD_ERASE_GRP_START ((uint8_t)32) /*!< To set the address of the first write
+ block to be erased. (For SD card only) */
+#define SD_CMD_SD_ERASE_GRP_END ((uint8_t)33) /*!< To set the address of the last write block of the
+ continuous range to be erased. (For SD card only) */
+#define SD_CMD_ERASE_GRP_START ((uint8_t)35) /*!< To set the address of the first write block to be erased.
+ (For MMC card only spec 3.31) */
+
+#define SD_CMD_ERASE_GRP_END ((uint8_t)36) /*!< To set the address of the last write block of the
+ continuous range to be erased. (For MMC card only spec 3.31) */
+
+#define SD_CMD_ERASE ((uint8_t)38)
+#define SD_CMD_FAST_IO ((uint8_t)39) /*!< SD Card doesn't support it */
+#define SD_CMD_GO_IRQ_STATE ((uint8_t)40) /*!< SD Card doesn't support it */
+#define SD_CMD_LOCK_UNLOCK ((uint8_t)42)
+#define SD_CMD_APP_CMD ((uint8_t)55)
+#define SD_CMD_GEN_CMD ((uint8_t)56)
+#define SD_CMD_NO_CMD ((uint8_t)64)
+
+/**
+ * @brief Following commands are SD Card Specific commands.
+ * SDIO_APP_CMD should be sent before sending these commands.
+ */
+#define SD_CMD_APP_SD_SET_BUSWIDTH ((uint8_t)6) /*!< For SD Card only */
+#define SD_CMD_SD_APP_STAUS ((uint8_t)13) /*!< For SD Card only */
+#define SD_CMD_SD_APP_SEND_NUM_WRITE_BLOCKS ((uint8_t)22) /*!< For SD Card only */
+#define SD_CMD_SD_APP_OP_COND ((uint8_t)41) /*!< For SD Card only */
+#define SD_CMD_SD_APP_SET_CLR_CARD_DETECT ((uint8_t)42) /*!< For SD Card only */
+#define SD_CMD_SD_APP_SEND_SCR ((uint8_t)51) /*!< For SD Card only */
+#define SD_CMD_SDIO_RW_DIRECT ((uint8_t)52) /*!< For SD I/O Card only */
+#define SD_CMD_SDIO_RW_EXTENDED ((uint8_t)53) /*!< For SD I/O Card only */
+
+/**
+ * @brief Following commands are SD Card Specific security commands.
+ * SDIO_APP_CMD should be sent before sending these commands.
+ */
+#define SD_CMD_SD_APP_GET_MKB ((uint8_t)43) /*!< For SD Card only */
+#define SD_CMD_SD_APP_GET_MID ((uint8_t)44) /*!< For SD Card only */
+#define SD_CMD_SD_APP_SET_CER_RN1 ((uint8_t)45) /*!< For SD Card only */
+#define SD_CMD_SD_APP_GET_CER_RN2 ((uint8_t)46) /*!< For SD Card only */
+#define SD_CMD_SD_APP_SET_CER_RES2 ((uint8_t)47) /*!< For SD Card only */
+#define SD_CMD_SD_APP_GET_CER_RES1 ((uint8_t)48) /*!< For SD Card only */
+#define SD_CMD_SD_APP_SECURE_READ_MULTIPLE_BLOCK ((uint8_t)18) /*!< For SD Card only */
+#define SD_CMD_SD_APP_SECURE_WRITE_MULTIPLE_BLOCK ((uint8_t)25) /*!< For SD Card only */
+#define SD_CMD_SD_APP_SECURE_ERASE ((uint8_t)38) /*!< For SD Card only */
+#define SD_CMD_SD_APP_CHANGE_SECURE_AREA ((uint8_t)49) /*!< For SD Card only */
+#define SD_CMD_SD_APP_SECURE_WRITE_MKB ((uint8_t)48) /*!< For SD Card only */
+
+/* Uncomment the following line to select the SDIO Data transfer mode */
+#if !defined (SD_DMA_MODE) && !defined (SD_POLLING_MODE)
+#define SD_DMA_MODE ((uint32_t)0x00000000)
+/*#define SD_POLLING_MODE ((uint32_t)0x00000002)*/
+#endif
+
+/**
+ * @brief SD detection on its memory slot
+ */
+#define SD_PRESENT ((uint8_t)0x01)
+#define SD_NOT_PRESENT ((uint8_t)0x00)
+
+/**
+ * @brief Supported SD Memory Cards
+ */
+#define SDIO_STD_CAPACITY_SD_CARD_V1_1 ((uint32_t)0x00000000)
+#define SDIO_STD_CAPACITY_SD_CARD_V2_0 ((uint32_t)0x00000001)
+#define SDIO_HIGH_CAPACITY_SD_CARD ((uint32_t)0x00000002)
+#define SDIO_MULTIMEDIA_CARD ((uint32_t)0x00000003)
+#define SDIO_SECURE_DIGITAL_IO_CARD ((uint32_t)0x00000004)
+#define SDIO_HIGH_SPEED_MULTIMEDIA_CARD ((uint32_t)0x00000005)
+#define SDIO_SECURE_DIGITAL_IO_COMBO_CARD ((uint32_t)0x00000006)
+#define SDIO_HIGH_CAPACITY_MMC_CARD ((uint32_t)0x00000007)
+
+/**
+ * @}
+ */
+
+/** @defgroup STM3210E_EVAL_SDIO_SD_Exported_Macros
+ * @{
+ */
+/**
+ * @}
+ */
+
+/** @defgroup STM3210E_EVAL_SDIO_SD_Exported_Functions
+ * @{
+ */
+void SD_DeInit(void);
+SD_Error SD_Init(void);
+SDTransferState SD_GetStatus(void);
+SDCardState SD_GetState(void);
+uint8_t SD_Detect(void);
+SD_Error SD_PowerON(void);
+SD_Error SD_PowerOFF(void);
+SD_Error SD_InitializeCards(void);
+SD_Error SD_GetCardInfo(SD_CardInfo *cardinfo);
+SD_Error SD_GetCardStatus(SD_CardStatus *cardstatus);
+SD_Error SD_EnableWideBusOperation(uint32_t WideMode);
+SD_Error SD_SelectDeselect(uint32_t addr);
+SD_Error SD_ReadBlock(uint8_t *readbuff, uint64_t ReadAddr, uint16_t BlockSize);
+SD_Error SD_ReadMultiBlocks(uint8_t *readbuff, uint64_t ReadAddr, uint16_t BlockSize, uint32_t NumberOfBlocks);
+SD_Error SD_WriteBlock(uint8_t *writebuff, uint64_t WriteAddr, uint16_t BlockSize);
+SD_Error SD_WriteMultiBlocks(uint8_t *writebuff, uint64_t WriteAddr, uint16_t BlockSize, uint32_t NumberOfBlocks);
+SDTransferState SD_GetTransferState(void);
+SD_Error SD_StopTransfer(void);
+SD_Error SD_Erase(uint32_t startaddr, uint32_t endaddr);
+SD_Error SD_SendStatus(uint32_t *pcardstatus);
+SD_Error SD_SendSDStatus(uint32_t *psdstatus);
+SD_Error SD_ProcessIRQSrc(void);
+void SD_ProcessDMAIRQ(void);
+SD_Error SD_WaitReadOperation(void);
+SD_Error SD_WaitWriteOperation(void);
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __STM3210E_EVAL_SDIO_SD_H */
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32303C_EVAL/stm32303c_eval.c b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32303C_EVAL/stm32303c_eval.c
new file mode 100644
index 0000000..37cba19
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32303C_EVAL/stm32303c_eval.c
@@ -0,0 +1,762 @@
+/**
+ ******************************************************************************
+ * @file stm32303c_eval.c
+ * @author MCD Application Team
+ * @version V1.0.1
+ * @date 23-October-2012
+ * @brief This file provides: a set of firmware functions to manage Leds,
+ * push-button and COM ports
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.st.com/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+
+/* Includes ------------------------------------------------------------------*/
+#include "stm32303c_eval.h"
+
+/** @addtogroup Utilities
+ * @{
+ */
+
+/** @addtogroup STM32_EVAL
+ * @{
+ */
+
+/** @addtogroup STM32303C_EVAL
+ * @{
+ */
+
+/** @defgroup STM32303C_EVAL_LOW_LEVEL
+ * @brief This file provides firmware functions to manage Leds, push-buttons,
+ * COM ports, SD card on SPI and temperature sensor (TS751) available on
+ * STM32303C-EVAL evaluation board from STMicroelectronics.
+ * @{
+ */
+
+/** @defgroup STM32303C_EVAL_LOW_LEVEL_Private_TypesDefinitions
+ * @{
+ */
+/**
+ * @}
+ */
+
+
+/** @defgroup STM32303C_EVAL_LOW_LEVEL_Private_Defines
+ * @{
+ */
+/**
+ * @}
+ */
+
+
+/** @defgroup STM32303C_EVAL_LOW_LEVEL_Private_Macros
+ * @{
+ */
+/**
+ * @}
+ */
+
+
+/** @defgroup STM32303C_EVAL_LOW_LEVEL_Private_Variables
+ * @{
+ */
+GPIO_TypeDef* GPIO_PORT[LEDn] = {LED1_GPIO_PORT, LED2_GPIO_PORT, LED3_GPIO_PORT,
+ LED4_GPIO_PORT};
+const uint16_t GPIO_PIN[LEDn] = {LED1_PIN, LED2_PIN, LED3_PIN,
+ LED4_PIN};
+const uint32_t GPIO_CLK[LEDn] = {LED1_GPIO_CLK, LED2_GPIO_CLK, LED3_GPIO_CLK,
+ LED4_GPIO_CLK};
+
+GPIO_TypeDef* BUTTON_PORT[BUTTONn] = {KEY_BUTTON_GPIO_PORT, RIGHT_BUTTON_GPIO_PORT,
+ LEFT_BUTTON_GPIO_PORT, UP_BUTTON_GPIO_PORT,
+ DOWN_BUTTON_GPIO_PORT, SEL_BUTTON_GPIO_PORT};
+
+const uint16_t BUTTON_PIN[BUTTONn] = {KEY_BUTTON_PIN, RIGHT_BUTTON_PIN, LEFT_BUTTON_PIN,
+ UP_BUTTON_PIN, DOWN_BUTTON_PIN, SEL_BUTTON_PIN};
+
+const uint32_t BUTTON_CLK[BUTTONn] = {KEY_BUTTON_GPIO_CLK, RIGHT_BUTTON_GPIO_CLK,
+ LEFT_BUTTON_GPIO_CLK, UP_BUTTON_GPIO_CLK,
+ DOWN_BUTTON_GPIO_CLK, SEL_BUTTON_GPIO_CLK};
+
+const uint16_t BUTTON_EXTI_LINE[BUTTONn] = {KEY_BUTTON_EXTI_LINE,
+ RIGHT_BUTTON_EXTI_LINE,
+ LEFT_BUTTON_EXTI_LINE,
+ UP_BUTTON_EXTI_LINE,
+ DOWN_BUTTON_EXTI_LINE,
+ SEL_BUTTON_EXTI_LINE};
+
+const uint8_t BUTTON_PORT_SOURCE[BUTTONn] = {KEY_BUTTON_EXTI_PORT_SOURCE,
+ RIGHT_BUTTON_EXTI_PORT_SOURCE,
+ LEFT_BUTTON_EXTI_PORT_SOURCE,
+ UP_BUTTON_EXTI_PORT_SOURCE,
+ DOWN_BUTTON_EXTI_PORT_SOURCE,
+ SEL_BUTTON_EXTI_PORT_SOURCE};
+
+const uint8_t BUTTON_PIN_SOURCE[BUTTONn] = {KEY_BUTTON_EXTI_PIN_SOURCE,
+ RIGHT_BUTTON_EXTI_PIN_SOURCE,
+ LEFT_BUTTON_EXTI_PIN_SOURCE,
+ UP_BUTTON_EXTI_PIN_SOURCE,
+ DOWN_BUTTON_EXTI_PIN_SOURCE,
+ SEL_BUTTON_EXTI_PIN_SOURCE};
+
+const uint8_t BUTTON_IRQn[BUTTONn] = {KEY_BUTTON_EXTI_IRQn,
+ RIGHT_BUTTON_EXTI_IRQn, LEFT_BUTTON_EXTI_IRQn,
+ UP_BUTTON_EXTI_IRQn, DOWN_BUTTON_EXTI_IRQn,
+ SEL_BUTTON_EXTI_IRQn};
+
+USART_TypeDef* COM_USART[COMn] = {EVAL_COM1};
+
+GPIO_TypeDef* COM_TX_PORT[COMn] = {EVAL_COM1_TX_GPIO_PORT};
+
+GPIO_TypeDef* COM_RX_PORT[COMn] = {EVAL_COM1_RX_GPIO_PORT};
+
+const uint32_t COM_USART_CLK[COMn] = {EVAL_COM1_CLK};
+
+const uint32_t COM_TX_PORT_CLK[COMn] = {EVAL_COM1_TX_GPIO_CLK};
+
+const uint32_t COM_RX_PORT_CLK[COMn] = {EVAL_COM1_RX_GPIO_CLK};
+
+const uint16_t COM_TX_PIN[COMn] = {EVAL_COM1_TX_PIN};
+
+const uint16_t COM_RX_PIN[COMn] = {EVAL_COM1_RX_PIN};
+
+const uint16_t COM_TX_PIN_SOURCE[COMn] = {EVAL_COM1_TX_SOURCE};
+
+const uint16_t COM_RX_PIN_SOURCE[COMn] = {EVAL_COM1_RX_SOURCE};
+
+const uint8_t COM_TX_AF[COMn] = {EVAL_COM1_TX_AF};
+
+const uint8_t COM_RX_AF[COMn] = {EVAL_COM1_RX_AF};
+
+
+/**
+ * @}
+ */
+
+
+/** @defgroup STM32303C_EVAL_LOW_LEVEL_Private_FunctionPrototypes
+ * @{
+ */
+
+/**
+ * @}
+ */
+
+/** @defgroup STM32303C_EVAL_LOW_LEVEL_Private_Functions
+ * @{
+ */
+
+/**
+ * @brief Configures LED GPIO.
+ * @param Led: Specifies the Led to be configured.
+ * This parameter can be one of following parameters:
+ * @arg LED1
+ * @arg LED2
+ * @arg LED3
+ * @arg LED4
+ * @retval None
+ */
+void STM_EVAL_LEDInit(Led_TypeDef Led)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+
+ /* Enable the GPIO_LED Clock */
+ RCC_AHBPeriphClockCmd(GPIO_CLK[Led], ENABLE);
+
+ /* Configure the GPIO_LED pin */
+ GPIO_InitStructure.GPIO_Pin = GPIO_PIN[Led];
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
+ GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
+ GPIO_Init(GPIO_PORT[Led], &GPIO_InitStructure);
+ GPIO_PORT[Led]->BSRR = GPIO_PIN[Led];
+}
+
+/**
+ * @brief Turns selected LED On.
+ * @param Led: Specifies the Led to be set on.
+ * This parameter can be one of following parameters:
+ * @arg LED1
+ * @arg LED2
+ * @arg LED3
+ * @arg LED4
+ * @retval None
+ */
+void STM_EVAL_LEDOn(Led_TypeDef Led)
+{
+ GPIO_PORT[Led]->BRR = GPIO_PIN[Led];
+}
+
+/**
+ * @brief Turns selected LED Off.
+ * @param Led: Specifies the Led to be set off.
+ * This parameter can be one of following parameters:
+ * @arg LED1
+ * @arg LED2
+ * @arg LED3
+ * @arg LED4
+ * @retval None
+ */
+void STM_EVAL_LEDOff(Led_TypeDef Led)
+{
+ GPIO_PORT[Led]->BSRR = GPIO_PIN[Led];
+}
+
+/**
+ * @brief Toggles the selected LED.
+ * @param Led: Specifies the Led to be toggled.
+ * This parameter can be one of following parameters:
+ * @arg LED1
+ * @arg LED2
+ * @arg LED3
+ * @arg LED4
+ * @retval None
+ */
+void STM_EVAL_LEDToggle(Led_TypeDef Led)
+{
+ GPIO_PORT[Led]->ODR ^= GPIO_PIN[Led];
+}
+
+/**
+ * @brief Configures Button GPIO and EXTI Line.
+ * @param Button: Specifies the Button to be configured.
+ * This parameter can be one of following parameters:
+ * @arg BUTTON_KEY: Key Push Button
+ * @arg BUTTON_RIGHT: Joystick Right Push Button
+ * @arg BUTTON_LEFT: Joystick Left Push Button
+ * @arg BUTTON_UP: Joystick Up Push Button
+ * @arg BUTTON_DOWN: Joystick Down Push Button
+ * @arg BUTTON_SEL: Joystick Sel Push Button
+ * @param Button_Mode: Specifies Button mode.
+ * This parameter can be one of following parameters:
+ * @arg BUTTON_MODE_GPIO: Button will be used as simple IO
+ * @arg BUTTON_MODE_EXTI: Button will be connected to EXTI line with interrupt
+ * generation capability
+ * @retval None
+ */
+void STM_EVAL_PBInit(Button_TypeDef Button, ButtonMode_TypeDef Button_Mode)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+ EXTI_InitTypeDef EXTI_InitStructure;
+ NVIC_InitTypeDef NVIC_InitStructure;
+
+ /* There is no Wakeup button on STM32303C_EVAL-EVAL, the Button value should
+ be greater than 0. */
+ if(Button > 0)
+ {
+ Button = (Button_TypeDef) (Button - 1);
+
+ /* Enable the BUTTON Clock */
+ RCC_AHBPeriphClockCmd(BUTTON_CLK[Button], ENABLE);
+ RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
+
+ /* Configure Button pin as input */
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
+ GPIO_InitStructure.GPIO_Pin = BUTTON_PIN[Button];
+ GPIO_Init(BUTTON_PORT[Button], &GPIO_InitStructure);
+
+
+ if (Button_Mode == BUTTON_MODE_EXTI)
+ {
+ /* Connect Button EXTI Line to Button GPIO Pin */
+ SYSCFG_EXTILineConfig(BUTTON_PORT_SOURCE[Button], BUTTON_PIN_SOURCE[Button]);
+
+ /* Configure Button EXTI line */
+ EXTI_InitStructure.EXTI_Line = BUTTON_EXTI_LINE[Button];
+ EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
+
+ if(Button != BUTTON_KEY)
+ {
+ EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
+ }
+ else
+ {
+ EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
+ }
+ EXTI_InitStructure.EXTI_LineCmd = ENABLE;
+ EXTI_Init(&EXTI_InitStructure);
+
+ /* Enable and set Button EXTI Interrupt to the lowest priority */
+ NVIC_InitStructure.NVIC_IRQChannel = BUTTON_IRQn[Button];
+ NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F;
+ NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;
+ NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
+
+ NVIC_Init(&NVIC_InitStructure);
+ }
+ }
+}
+
+/**
+ * @brief Returns the selected Button state.
+ * @param Button: Specifies the Button to be checked.
+ * This parameter can be one of following parameters:
+ * @arg BUTTON_KEY: Key Push Button
+ * @arg BUTTON_RIGHT: Joystick Right Push Button
+ * @arg BUTTON_LEFT: Joystick Left Push Button
+ * @arg BUTTON_UP: Joystick Up Push Button
+ * @arg BUTTON_DOWN: Joystick Down Push Button
+ * @arg BUTTON_SEL: Joystick Sel Push Button
+ * @retval - When Button > 0, the Button GPIO pin value is returned.
+ * - When Button = 0 , error code (0xFF) is returned.
+ */
+uint32_t STM_EVAL_PBGetState(Button_TypeDef Button)
+{
+ /* There is no Wakeup button on STM32303C_EVAL-EVAL, the Button value should
+ be greater than 0. */
+ if(Button > 0)
+ {
+ Button = (Button_TypeDef) (Button - 1);
+ return GPIO_ReadInputDataBit(BUTTON_PORT[Button], BUTTON_PIN[Button]);
+ }
+ else
+ {
+ return 0xFF; /* Error Code */
+ }
+}
+
+/**
+ * @brief Configures COM port.
+ * @param COM: Specifies the COM port to be configured.
+ * This parameter can be one of following parameters:
+ * @arg COM1
+ * @param USART_InitStruct: pointer to a USART_InitTypeDef structure that
+ * contains the configuration information for the specified USART peripheral.
+ * @retval None
+ */
+void STM_EVAL_COMInit(COM_TypeDef COM, USART_InitTypeDef* USART_InitStruct)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+
+ /* Enable GPIO clock */
+ RCC_AHBPeriphClockCmd(COM_TX_PORT_CLK[COM] | COM_RX_PORT_CLK[COM], ENABLE);
+
+ /* Enable USART clock */
+ RCC_APB2PeriphClockCmd(COM_USART_CLK[COM], ENABLE);
+
+ /* Connect PXx to USARTx_Tx */
+ GPIO_PinAFConfig(COM_TX_PORT[COM], COM_TX_PIN_SOURCE[COM], COM_TX_AF[COM]);
+
+ /* Connect PXx to USARTx_Rx */
+ GPIO_PinAFConfig(COM_RX_PORT[COM], COM_RX_PIN_SOURCE[COM], COM_RX_AF[COM]);
+
+ /* Configure USART Tx as alternate function push-pull */
+ GPIO_InitStructure.GPIO_Pin = COM_TX_PIN[COM];
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
+ GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
+ GPIO_Init(COM_TX_PORT[COM], &GPIO_InitStructure);
+
+ /* Configure USART Rx as alternate function push-pull */
+ GPIO_InitStructure.GPIO_Pin = COM_RX_PIN[COM];
+ GPIO_Init(COM_RX_PORT[COM], &GPIO_InitStructure);
+
+ /* USART configuration */
+ USART_Init(COM_USART[COM], USART_InitStruct);
+
+ /* Enable USART */
+ USART_Cmd(COM_USART[COM], ENABLE);
+}
+
+/**
+ * @brief DeInitializes the SPI interface.
+ * @param None
+ * @retval None
+ */
+void SD_LowLevel_DeInit(void)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+
+ SPI_Cmd(SD_SPI, DISABLE); /* SD_SPI disable */
+ SPI_I2S_DeInit(SD_SPI); /* DeInitializes the SD_SPI */
+
+ /* SD_SPI Periph clock disable */
+ RCC_APB1PeriphClockCmd(SD_SPI_CLK, DISABLE);
+
+ /*Configure SD_SPI pins: SCK */
+ GPIO_InitStructure.GPIO_Pin = SD_SPI_SCK_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
+ GPIO_Init(SD_SPI_SCK_GPIO_PORT, &GPIO_InitStructure);
+
+ /* Configure SD_SPI pins: MISO */
+ GPIO_InitStructure.GPIO_Pin = SD_SPI_MISO_PIN;
+ GPIO_Init(SD_SPI_MISO_GPIO_PORT, &GPIO_InitStructure);
+
+ /* Configure SD_SPI pins: MOSI */
+ GPIO_InitStructure.GPIO_Pin = SD_SPI_MOSI_PIN;
+ GPIO_Init(SD_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure);
+
+ /* Configure SD_SPI_CS_PIN pin: SD Card CS pin */
+ GPIO_InitStructure.GPIO_Pin = SD_CS_PIN;
+ GPIO_Init(SD_CS_GPIO_PORT, &GPIO_InitStructure);
+
+ /* Configure SD_SPI_DETECT_PIN pin: SD Card detect pin */
+ GPIO_InitStructure.GPIO_Pin = SD_DETECT_PIN;
+ GPIO_Init(SD_DETECT_GPIO_PORT, &GPIO_InitStructure);
+}
+
+/**
+ * @brief Initializes the SD Card and put it into StandBy State (Ready for
+ * data transfer).
+ * @param None
+ * @retval None
+ */
+void SD_LowLevel_Init(void)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+ SPI_InitTypeDef SPI_InitStructure;
+
+ /* SD_SPI_CS_GPIO, SD_SPI_MOSI_GPIO, SD_SPI_MISO_GPIO, SD_SPI_DETECT_GPIO
+ and SD_SPI_SCK_GPIO Periph clock enable */
+ RCC_AHBPeriphClockCmd(SD_CS_GPIO_CLK | SD_SPI_MOSI_GPIO_CLK | SD_SPI_MISO_GPIO_CLK |
+ SD_SPI_SCK_GPIO_CLK | SD_DETECT_GPIO_CLK, ENABLE);
+
+ /* SD_SPI Periph clock enable */
+ RCC_APB1PeriphClockCmd(SD_SPI_CLK, ENABLE);
+
+ /* Configure SD_SPI pins: SCK */
+ GPIO_InitStructure.GPIO_Pin = SD_SPI_SCK_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
+ GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
+ GPIO_Init(SD_SPI_SCK_GPIO_PORT, &GPIO_InitStructure);
+
+ /* Configure SD_SPI pins: MISO */
+ GPIO_InitStructure.GPIO_Pin = SD_SPI_MISO_PIN;
+ GPIO_Init(SD_SPI_MISO_GPIO_PORT, &GPIO_InitStructure);
+
+ /* Configure SD_SPI pins: MOSI */
+ GPIO_InitStructure.GPIO_Pin = SD_SPI_MOSI_PIN;
+ GPIO_Init(SD_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure);
+
+ /* Configure SD_SPI_CS_PIN pin: SD Card CS pin */
+ GPIO_InitStructure.GPIO_Pin = SD_CS_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
+ GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
+ GPIO_Init(SD_CS_GPIO_PORT, &GPIO_InitStructure);
+
+ /* Configure SD_SPI_DETECT_PIN pin: SD Card detect pin */
+ GPIO_InitStructure.GPIO_Pin = SD_DETECT_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
+ GPIO_Init(SD_DETECT_GPIO_PORT, &GPIO_InitStructure);
+
+ /* Connect PXx to SD_SPI_SCK */
+ GPIO_PinAFConfig(SD_SPI_SCK_GPIO_PORT, SD_SPI_SCK_SOURCE, SD_SPI_SCK_AF);
+
+ /* Connect PXx to SD_SPI_MISO */
+ GPIO_PinAFConfig(SD_SPI_MISO_GPIO_PORT, SD_SPI_MISO_SOURCE, SD_SPI_MISO_AF);
+
+ /* Connect PXx to SD_SPI_MOSI */
+ GPIO_PinAFConfig(SD_SPI_MOSI_GPIO_PORT, SD_SPI_MOSI_SOURCE, SD_SPI_MOSI_AF);
+
+ /* SD_SPI Config */
+ SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
+ SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
+ SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
+ SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;
+ SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
+ SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
+ SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2;
+
+ SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
+ SPI_InitStructure.SPI_CRCPolynomial = 7;
+ SPI_Init(SD_SPI, &SPI_InitStructure);
+
+ SPI_RxFIFOThresholdConfig(SD_SPI, SPI_RxFIFOThreshold_QF);
+
+ SPI_Cmd(SD_SPI, ENABLE); /* SD_SPI enable */
+}
+
+/**
+ * @brief DeInitializes the TS751_I2C.
+ * @param None
+ * @retval None
+ */
+void TS751_LowLevel_DeInit(void)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+
+ /* Disable TS751_I2C */
+ I2C_Cmd(TS751_I2C, DISABLE);
+
+ /* DeInitializes the TS751_I2C */
+ I2C_DeInit(TS751_I2C);
+
+ /* TS751_I2C Periph clock disable */
+ RCC_APB1PeriphClockCmd(TS751_I2C_CLK, DISABLE);
+
+ /* Configure TS751_I2C pins: SCL */
+ GPIO_InitStructure.GPIO_Pin = TS751_I2C_SCL_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
+ GPIO_Init(TS751_I2C_SCL_GPIO_PORT, &GPIO_InitStructure);
+
+ /* Configure TS751_I2C pins: SDA */
+ GPIO_InitStructure.GPIO_Pin = TS751_I2C_SDA_PIN;
+ GPIO_Init(TS751_I2C_SDA_GPIO_PORT, &GPIO_InitStructure);
+
+ /* Configure TS751_I2C pin: SMBUS ALERT */
+ GPIO_InitStructure.GPIO_Pin = TS751_I2C_SMBUSALERT_PIN;
+ GPIO_Init(TS751_I2C_SMBUSALERT_GPIO_PORT, &GPIO_InitStructure);
+}
+
+/**
+ * @brief Initializes the TS751_I2C..
+ * @param None
+ * @retval None
+ */
+void TS751_LowLevel_Init(void)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+
+ /* TS751_I2C Periph clock enable */
+ RCC_APB1PeriphClockCmd(TS751_I2C_CLK, ENABLE);
+
+ /* Configure the I2C clock source. The clock is derived from the SYSCLK */
+ RCC_I2CCLKConfig(RCC_I2C2CLK_SYSCLK);
+
+ /* TS751_I2C_SCL_GPIO_CLK, TS751_I2C_SDA_GPIO_CLK
+ and TS751_I2C_SMBUSALERT_GPIO_CLK Periph clock enable */
+ RCC_AHBPeriphClockCmd(TS751_I2C_SCL_GPIO_CLK | TS751_I2C_SDA_GPIO_CLK |
+ TS751_I2C_SMBUSALERT_GPIO_CLK, ENABLE);
+
+ /* Connect PXx to I2C_SCL */
+ GPIO_PinAFConfig(TS751_I2C_SCL_GPIO_PORT, TS751_I2C_SCL_SOURCE, TS751_I2C_SCL_AF);
+
+ /* Connect PXx to I2C_SDA */
+ GPIO_PinAFConfig(TS751_I2C_SDA_GPIO_PORT, TS751_I2C_SDA_SOURCE, TS751_I2C_SDA_AF);
+
+ /* Connect PXx to I2C_SMBUSALER */
+ GPIO_PinAFConfig(TS751_I2C_SMBUSALERT_GPIO_PORT, TS751_I2C_SMBUSALERT_SOURCE, TS751_I2C_SMBUSALERT_AF);
+
+ /* Configure TS751_I2C pins: SCL */
+ GPIO_InitStructure.GPIO_Pin = TS751_I2C_SCL_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
+ GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
+ GPIO_Init(TS751_I2C_SCL_GPIO_PORT, &GPIO_InitStructure);
+
+ /* Configure TS751_I2C pins: SDA */
+ GPIO_InitStructure.GPIO_Pin = TS751_I2C_SDA_PIN;
+ GPIO_Init(TS751_I2C_SDA_GPIO_PORT, &GPIO_InitStructure);
+
+ /* Configure TS751_I2C pin: SMBUS ALERT */
+ GPIO_InitStructure.GPIO_Pin = TS751_I2C_SMBUSALERT_PIN;
+ GPIO_Init(TS751_I2C_SMBUSALERT_GPIO_PORT, &GPIO_InitStructure);
+}
+
+/**
+ * @brief DeInitializes peripherals used by the I2C EEPROM driver.
+ * @param None
+ * @retval None
+ */
+void sEE_I2C_LowLevel_DeInit(void)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+
+ /* sEE_I2C Peripheral Disable */
+ I2C_Cmd(sEE_I2C, DISABLE);
+
+ /* sEE_I2C DeInit */
+ I2C_DeInit(sEE_I2C);
+
+ /* sEE_I2C Periph clock disable */
+ RCC_APB1PeriphClockCmd(sEE_I2C_CLK, DISABLE);
+
+ /* GPIO configuration */
+ /* Configure sEE_I2C pins: SCL */
+ GPIO_InitStructure.GPIO_Pin = sEE_I2C_SCL_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
+ GPIO_Init(sEE_I2C_SCL_GPIO_PORT, &GPIO_InitStructure);
+
+ /* Configure sEE_I2C pins: SDA */
+ GPIO_InitStructure.GPIO_Pin = sEE_I2C_SDA_PIN;
+ GPIO_Init(sEE_I2C_SDA_GPIO_PORT, &GPIO_InitStructure);
+}
+
+/**
+ * @brief Initializes peripherals used by the I2C EEPROM driver.
+ * @param None
+ * @retval None
+ */
+void sEE_I2C_LowLevel_Init(void)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+
+ /* Configure the I2C clock source. The clock is derived from the SYSCLK */
+ RCC_I2CCLKConfig(RCC_I2C2CLK_SYSCLK);
+
+ /* sEE_I2C_SCL_GPIO_CLK and sEE_I2C_SDA_GPIO_CLK Periph clock enable */
+ RCC_AHBPeriphClockCmd(sEE_I2C_SCL_GPIO_CLK | sEE_I2C_SDA_GPIO_CLK, ENABLE);
+
+ /* sEE_I2C Periph clock enable */
+ RCC_APB1PeriphClockCmd(sEE_I2C_CLK, ENABLE);
+
+ /* Connect PXx to I2C_SCL*/
+ GPIO_PinAFConfig(sEE_I2C_SCL_GPIO_PORT, sEE_I2C_SCL_SOURCE, sEE_I2C_SCL_AF);
+
+ /* Connect PXx to I2C_SDA*/
+ GPIO_PinAFConfig(sEE_I2C_SDA_GPIO_PORT, sEE_I2C_SDA_SOURCE, sEE_I2C_SDA_AF);
+
+ /* GPIO configuration */
+ /* Configure sEE_I2C pins: SCL */
+ GPIO_InitStructure.GPIO_Pin = sEE_I2C_SCL_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
+ GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
+ GPIO_Init(sEE_I2C_SCL_GPIO_PORT, &GPIO_InitStructure);
+
+ /* Configure sEE_I2C pins: SDA */
+ GPIO_InitStructure.GPIO_Pin = sEE_I2C_SDA_PIN;
+ GPIO_Init(sEE_I2C_SDA_GPIO_PORT, &GPIO_InitStructure);
+}
+
+/**
+ * @brief DeInitializes the SPI interface.
+ * @param None
+ * @retval None
+ */
+void sEE_SPI_LowLevel_DeInit(void)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+
+ SPI_Cmd(sEE_SPI, DISABLE); /* sEE_SPI disable */
+ SPI_I2S_DeInit(sEE_SPI); /* DeInitializes the sEE_SPI */
+
+ /* sEE_SPI Periph clock disable */
+ RCC_APB1PeriphClockCmd(sEE_SPI_CLK, DISABLE);
+
+ /* Configure sEE_SPI pins: SCK */
+ GPIO_InitStructure.GPIO_Pin = sEE_SPI_SCK_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
+ GPIO_Init(sEE_SPI_SCK_GPIO_PORT, &GPIO_InitStructure);
+
+ /* Configure sEE pins: MISO */
+ GPIO_InitStructure.GPIO_Pin = sEE_SPI_MISO_PIN;
+ GPIO_Init(sEE_SPI_MISO_GPIO_PORT, &GPIO_InitStructure);
+
+ /* Configure sEE pins: MOSI */
+ GPIO_InitStructure.GPIO_Pin = sEE_SPI_MOSI_PIN;
+ GPIO_Init(sEE_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure);
+
+ /* Configure sEE_CS_PIN pin: sEE Card CS pin */
+ GPIO_InitStructure.GPIO_Pin = sEE_SPI_CS_PIN;
+ GPIO_Init(sEE_SPI_CS_GPIO_PORT, &GPIO_InitStructure);
+}
+
+/**
+ * @brief Initializes the SPI interface for EEPROM
+ * @param None
+ * @retval None
+ */
+void sEE_SPI_LowLevel_Init(void)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+ SPI_InitTypeDef SPI_InitStructure;
+
+ /* sEE_CS_GPIO, sEE_MOSI_GPIO, sEE_MISO_GPIO and sEE_SCK_GPIO
+ Periph clock enable */
+ RCC_AHBPeriphClockCmd(sEE_SPI_CS_GPIO_CLK | sEE_SPI_MOSI_GPIO_CLK | sEE_SPI_MISO_GPIO_CLK |
+ sEE_SPI_SCK_GPIO_CLK , ENABLE);
+
+ /* sEE Periph clock enable */
+ RCC_APB1PeriphClockCmd(sEE_SPI_CLK, ENABLE);
+
+ /* Configure sEE pins: SCK */
+ GPIO_InitStructure.GPIO_Pin = sEE_SPI_SCK_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
+ GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
+ GPIO_Init(sEE_SPI_SCK_GPIO_PORT, &GPIO_InitStructure);
+
+ /* Configure sEE pins: MISO */
+ GPIO_InitStructure.GPIO_Pin = sEE_SPI_MISO_PIN;
+ GPIO_Init(sEE_SPI_MISO_GPIO_PORT, &GPIO_InitStructure);
+
+ /* Configure sEE pins: MOSI */
+ GPIO_InitStructure.GPIO_Pin = sEE_SPI_MOSI_PIN;
+ GPIO_Init(sEE_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure);
+
+ /* Configure sEE_CS_PIN pin: sEE Card CS pin */
+ GPIO_InitStructure.GPIO_Pin = sEE_SPI_CS_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
+ GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
+ GPIO_Init(sEE_SPI_CS_GPIO_PORT, &GPIO_InitStructure);
+
+ /* Connect PXx to sEE_SCK */
+ GPIO_PinAFConfig(sEE_SPI_SCK_GPIO_PORT, sEE_SPI_SCK_SOURCE, sEE_SPI_SCK_AF);
+
+ /* Connect PXx to sEE_MISO */
+ GPIO_PinAFConfig(sEE_SPI_MISO_GPIO_PORT, sEE_SPI_MISO_SOURCE, sEE_SPI_MISO_AF);
+
+ /* Connect PXx to sEE_MOSI */
+ GPIO_PinAFConfig(sEE_SPI_MOSI_GPIO_PORT, sEE_SPI_MOSI_SOURCE, sEE_SPI_MOSI_AF);
+
+ /* sEE SPI Config */
+ SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
+ SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
+ SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
+ SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;
+ SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
+ SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
+ SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_64;
+
+ SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
+ SPI_InitStructure.SPI_CRCPolynomial = 7;
+ SPI_Init(sEE_SPI, &SPI_InitStructure);
+
+ SPI_RxFIFOThresholdConfig(sEE_SPI, SPI_RxFIFOThreshold_QF);
+
+ SPI_Cmd(sEE_SPI, ENABLE); /* sEE_SPI enable */
+}
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32303C_EVAL/stm32303c_eval.h b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32303C_EVAL/stm32303c_eval.h
new file mode 100644
index 0000000..82a2749
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32303C_EVAL/stm32303c_eval.h
@@ -0,0 +1,442 @@
+/**
+ ******************************************************************************
+ * @file stm32303c_eval.h
+ * @author MCD Application Team
+ * @version V1.0.1
+ * @date 23-October-2012
+ * @brief This file contains definitions for STM32303C_EVAL's Leds, push-buttons
+ * and COM ports hardware resources.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.st.com/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __STM32303C_EVAL_H
+#define __STM32303C_EVAL_H
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+/* Includes ------------------------------------------------------------------*/
+#include "stm32f30x.h"
+#include "stm32_eval_legacy.h"
+
+/** @addtogroup Utilities
+ * @{
+ */
+
+/** @addtogroup STM32_EVAL
+ * @{
+ */
+
+/** @addtogroup STM32303C_EVAL
+ * @{
+ */
+
+/** @addtogroup STM32303C_EVAL_LOW_LEVEL
+ * @{
+ */
+
+/** @defgroup STM32303C_EVAL_LOW_LEVEL_Exported_Types
+ * @{
+ */
+typedef enum
+{
+ LED1 = 0,
+ LED2 = 1,
+ LED3 = 2,
+ LED4 = 3
+} Led_TypeDef;
+
+typedef enum
+{
+ BUTTON_NONE = 0,
+ BUTTON_KEY = 1,
+ BUTTON_RIGHT = 2,
+ BUTTON_LEFT = 3,
+ BUTTON_UP = 4,
+ BUTTON_DOWN = 5,
+ BUTTON_SEL = 6
+} Button_TypeDef;
+
+typedef enum
+{
+ BUTTON_MODE_GPIO = 0,
+ BUTTON_MODE_EXTI = 1
+} ButtonMode_TypeDef;
+
+typedef enum
+{
+ JOY_NONE = 0,
+ JOY_SEL = 1,
+ JOY_DOWN = 2,
+ JOY_LEFT = 3,
+ JOY_RIGHT = 4,
+ JOY_UP = 5
+} JOYState_TypeDef
+;
+
+typedef enum
+{
+ COM1 = 0,
+ COM2 = 1
+} COM_TypeDef;
+/**
+ * @}
+ */
+
+/** @defgroup STM32303C_EVAL_LOW_LEVEL_Exported_Constants
+ * @{
+ */
+
+/**
+ * @brief Define for STM32303C_EVAL board
+ */
+#if !defined (USE_STM32303C_EVAL)
+ #define USE_STM32303C_EVAL
+#endif
+
+/** @addtogroup STM32303C_EVAL_LOW_LEVEL_LED
+ * @{
+ */
+#define LEDn 4
+
+#define LED1_PIN GPIO_Pin_8
+#define LED1_GPIO_PORT GPIOE
+#define LED1_GPIO_CLK RCC_AHBPeriph_GPIOE
+
+#define LED2_PIN GPIO_Pin_9
+#define LED2_GPIO_PORT GPIOE
+#define LED2_GPIO_CLK RCC_AHBPeriph_GPIOE
+
+#define LED3_PIN GPIO_Pin_10
+#define LED3_GPIO_PORT GPIOE
+#define LED3_GPIO_CLK RCC_AHBPeriph_GPIOE
+
+#define LED4_PIN GPIO_Pin_11
+#define LED4_GPIO_PORT GPIOE
+#define LED4_GPIO_CLK RCC_AHBPeriph_GPIOE
+
+/**
+ * @}
+ */
+
+/** @addtogroup STM32303C_EVAL_LOW_LEVEL_BUTTON
+ * @{
+ */
+#define BUTTONn 6
+
+/**
+ * @brief Key push-button
+ */
+#define KEY_BUTTON_PIN GPIO_Pin_6
+#define KEY_BUTTON_GPIO_PORT GPIOE
+#define KEY_BUTTON_GPIO_CLK RCC_AHBPeriph_GPIOE
+#define KEY_BUTTON_EXTI_LINE EXTI_Line6
+#define KEY_BUTTON_EXTI_PORT_SOURCE EXTI_PortSourceGPIOE
+#define KEY_BUTTON_EXTI_PIN_SOURCE EXTI_PinSource6
+#define KEY_BUTTON_EXTI_IRQn EXTI9_5_IRQn
+
+/**
+ * @brief Joystick Right push-button
+ */
+#define RIGHT_BUTTON_PIN GPIO_Pin_6
+#define RIGHT_BUTTON_GPIO_PORT GPIOD
+#define RIGHT_BUTTON_GPIO_CLK RCC_AHBPeriph_GPIOD
+#define RIGHT_BUTTON_EXTI_LINE EXTI_Line6
+#define RIGHT_BUTTON_EXTI_PORT_SOURCE EXTI_PortSourceGPIOD
+#define RIGHT_BUTTON_EXTI_PIN_SOURCE EXTI_PinSource6
+#define RIGHT_BUTTON_EXTI_IRQn EXTI9_5_IRQn
+
+/**
+ * @brief Joystick Left push-button
+ */
+#define LEFT_BUTTON_PIN GPIO_Pin_5
+#define LEFT_BUTTON_GPIO_PORT GPIOB
+#define LEFT_BUTTON_GPIO_CLK RCC_AHBPeriph_GPIOB
+#define LEFT_BUTTON_EXTI_LINE EXTI_Line5
+#define LEFT_BUTTON_EXTI_PORT_SOURCE EXTI_PortSourceGPIOB
+#define LEFT_BUTTON_EXTI_PIN_SOURCE EXTI_PinSource5
+#define LEFT_BUTTON_EXTI_IRQn EXTI9_5_IRQn
+
+/**
+ * @brief Joystick Up push-button
+ */
+#define UP_BUTTON_PIN GPIO_Pin_7
+#define UP_BUTTON_GPIO_PORT GPIOE
+#define UP_BUTTON_GPIO_CLK RCC_AHBPeriph_GPIOE
+#define UP_BUTTON_EXTI_LINE EXTI_Line7
+#define UP_BUTTON_EXTI_PORT_SOURCE EXTI_PortSourceGPIOE
+#define UP_BUTTON_EXTI_PIN_SOURCE EXTI_PinSource7
+#define UP_BUTTON_EXTI_IRQn EXTI9_5_IRQn
+
+/**
+ * @brief Joystick Down push-button
+ */
+#define DOWN_BUTTON_PIN GPIO_Pin_5
+#define DOWN_BUTTON_GPIO_PORT GPIOD
+#define DOWN_BUTTON_GPIO_CLK RCC_AHBPeriph_GPIOD
+#define DOWN_BUTTON_EXTI_LINE EXTI_Line5
+#define DOWN_BUTTON_EXTI_PORT_SOURCE EXTI_PortSourceGPIOD
+#define DOWN_BUTTON_EXTI_PIN_SOURCE EXTI_PinSource5
+#define DOWN_BUTTON_EXTI_IRQn EXTI9_5_IRQn
+
+/**
+ * @brief Joystick Sel push-button
+ */
+#define SEL_BUTTON_PIN GPIO_Pin_13
+#define SEL_BUTTON_GPIO_PORT GPIOC
+#define SEL_BUTTON_GPIO_CLK RCC_AHBPeriph_GPIOC
+#define SEL_BUTTON_EXTI_LINE EXTI_Line13
+#define SEL_BUTTON_EXTI_PORT_SOURCE EXTI_PortSourceGPIOC
+#define SEL_BUTTON_EXTI_PIN_SOURCE EXTI_PinSource13
+#define SEL_BUTTON_EXTI_IRQn EXTI15_10_IRQn
+
+/**
+ * @}
+ */
+
+
+/** @addtogroup STM32303C_EVAL_LOW_LEVEL_COM
+ * @{
+ */
+#define COMn 1
+
+/**
+ * @brief Definition for COM port1, connected to USART1
+ */
+#define EVAL_COM1 USART1
+#define EVAL_COM1_CLK RCC_APB2Periph_USART1
+
+#define EVAL_COM1_TX_PIN GPIO_Pin_4
+#define EVAL_COM1_TX_GPIO_PORT GPIOC
+#define EVAL_COM1_TX_GPIO_CLK RCC_AHBPeriph_GPIOC
+#define EVAL_COM1_TX_SOURCE GPIO_PinSource4
+#define EVAL_COM1_TX_AF GPIO_AF_7
+
+#define EVAL_COM1_RX_PIN GPIO_Pin_1
+#define EVAL_COM1_RX_GPIO_PORT GPIOE
+#define EVAL_COM1_RX_GPIO_CLK RCC_AHBPeriph_GPIOE
+#define EVAL_COM1_RX_SOURCE GPIO_PinSource1
+#define EVAL_COM1_RX_AF GPIO_AF_7
+
+#define EVAL_COM1_CTS_PIN GPIO_Pin_11
+#define EVAL_COM1_CTS_GPIO_PORT GPIOA
+#define EVAL_COM1_CTS_GPIO_CLK RCC_AHBPeriph_GPIOA
+#define EVAL_COM1_CTS_SOURCE GPIO_PinSource11
+#define EVAL_COM1_CTS_AF GPIO_AF_7
+
+#define EVAL_COM1_RTS_PIN GPIO_Pin_12
+#define EVAL_COM1_RTS_GPIO_PORT GPIOA
+#define EVAL_COM1_RTS_GPIO_CLK RCC_AHBPeriph_GPIOA
+#define EVAL_COM1_RTS_SOURCE GPIO_PinSource12
+#define EVAL_COM1_RTS_AF GPIO_AF_7
+
+#define EVAL_COM1_IRQn USART1_IRQn
+
+/**
+ * @}
+ */
+
+/** @addtogroup STM32303C_EVAL_LOW_LEVEL_SD_SPI
+ * @{
+ */
+/**
+ * @brief SD SPI Interface pins
+ */
+#define SD_SPI SPI2
+#define SD_SPI_CLK RCC_APB1Periph_SPI2
+
+#define SD_SPI_SCK_PIN GPIO_Pin_9 /* PF.09 */
+#define SD_SPI_SCK_GPIO_PORT GPIOF /* GPIOF */
+#define SD_SPI_SCK_GPIO_CLK RCC_AHBPeriph_GPIOF
+#define SD_SPI_SCK_SOURCE GPIO_PinSource9
+#define SD_SPI_SCK_AF GPIO_AF_5
+
+#define SD_SPI_MISO_PIN GPIO_Pin_14 /* PB.14 */
+#define SD_SPI_MISO_GPIO_PORT GPIOB /* GPIOB */
+#define SD_SPI_MISO_GPIO_CLK RCC_AHBPeriph_GPIOB
+#define SD_SPI_MISO_SOURCE GPIO_PinSource14
+#define SD_SPI_MISO_AF GPIO_AF_5
+
+#define SD_SPI_MOSI_PIN GPIO_Pin_15 /* PB.15 */
+#define SD_SPI_MOSI_GPIO_PORT GPIOB /* GPIOB */
+#define SD_SPI_MOSI_GPIO_CLK RCC_AHBPeriph_GPIOB
+#define SD_SPI_MOSI_SOURCE GPIO_PinSource15
+#define SD_SPI_MOSI_AF GPIO_AF_5
+
+#define SD_CS_PIN GPIO_Pin_15 /* PE.15 */
+#define SD_CS_GPIO_PORT GPIOE /* GPIOE */
+#define SD_CS_GPIO_CLK RCC_AHBPeriph_GPIOF
+
+
+#define SD_DETECT_PIN GPIO_Pin_6 /* PC.06 */
+#define SD_DETECT_EXTI_LINE EXTI_Line6
+#define SD_DETECT_EXTI_PIN_SOURCE EXTI_PinSource6
+#define SD_DETECT_GPIO_PORT GPIOC /* GPIOC */
+#define SD_DETECT_GPIO_CLK RCC_AHBPeriph_GPIOC
+#define SD_DETECT_EXTI_PORT_SOURCE EXTI_PortSourceGPIOC
+#define SD_DETECT_EXTI_IRQn EXTI9_5_IRQn
+
+/**
+ * @}
+ */
+
+/** @addtogroup STM32303C_EVAL_LOW_LEVEL_sEE_SPI
+ * @{
+ */
+/**
+ * @brief sEE SPI Interface pins
+ */
+#define sEE_SPI SPI2
+#define sEE_SPI_CLK RCC_APB1Periph_SPI2
+
+#define sEE_SPI_SCK_PIN GPIO_Pin_9 /* PF.09 */
+#define sEE_SPI_SCK_GPIO_PORT GPIOF /* GPIOF */
+#define sEE_SPI_SCK_GPIO_CLK RCC_AHBPeriph_GPIOF
+#define sEE_SPI_SCK_SOURCE GPIO_PinSource9
+#define sEE_SPI_SCK_AF GPIO_AF_5
+
+#define sEE_SPI_MISO_PIN GPIO_Pin_14 /* PB.14 */
+#define sEE_SPI_MISO_GPIO_PORT GPIOB /* GPIOB */
+#define sEE_SPI_MISO_GPIO_CLK RCC_AHBPeriph_GPIOB
+#define sEE_SPI_MISO_SOURCE GPIO_PinSource14
+#define sEE_SPI_MISO_AF GPIO_AF_5
+
+#define sEE_SPI_MOSI_PIN GPIO_Pin_15 /* PB.15 */
+#define sEE_SPI_MOSI_GPIO_PORT GPIOB /* GPIOB */
+#define sEE_SPI_MOSI_GPIO_CLK RCC_AHBPeriph_GPIOB
+#define sEE_SPI_MOSI_SOURCE GPIO_PinSource15
+#define sEE_SPI_MOSI_AF GPIO_AF_5
+
+#define sEE_SPI_CS_PIN GPIO_Pin_7 /* PD.07 */
+#define sEE_SPI_CS_GPIO_PORT GPIOD /* GPIOD */
+#define sEE_SPI_CS_GPIO_CLK RCC_AHBPeriph_GPIOD
+
+/**
+ * @brief sEE SPI Interface Type
+ */
+#define sEE_M95M01
+
+/**
+ * @}
+ */
+
+/** @addtogroup STM32303C_EVAL_LOW_LEVEL_TSENSOR_I2C
+ * @{
+ */
+/**
+ * @brief TS751 Temperature Sensor I2C Interface pins
+ */
+#define TS751_I2C I2C2
+#define TS751_I2C_CLK RCC_APB1Periph_I2C2
+
+#define TS751_I2C_SCL_PIN GPIO_Pin_6 /* PF.06 */
+#define TS751_I2C_SCL_GPIO_PORT GPIOF /* GPIOF */
+#define TS751_I2C_SCL_GPIO_CLK RCC_AHBPeriph_GPIOF
+#define TS751_I2C_SCL_SOURCE GPIO_PinSource6
+#define TS751_I2C_SCL_AF GPIO_AF_4
+
+#define TS751_I2C_SDA_PIN GPIO_Pin_10 /* PA.10 */
+#define TS751_I2C_SDA_GPIO_PORT GPIOA /* GPIOA */
+#define TS751_I2C_SDA_GPIO_CLK RCC_AHBPeriph_GPIOA
+#define TS751_I2C_SDA_SOURCE GPIO_PinSource10
+#define TS751_I2C_SDA_AF GPIO_AF_4
+
+#define TS751_I2C_SMBUSALERT_PIN GPIO_Pin_8 /* PA.08 */
+#define TS751_I2C_SMBUSALERT_GPIO_PORT GPIOA /* GPIOA */
+#define TS751_I2C_SMBUSALERT_GPIO_CLK RCC_AHBPeriph_GPIOA
+#define TS751_I2C_SMBUSALERT_SOURCE GPIO_PinSource8
+#define TS751_I2C_SMBUSALERT_AF GPIO_AF_4
+
+/**
+ * @}
+ */
+
+/** @addtogroup STM32303C_EVAL_LOW_LEVEL_I2C_EE
+ * @{
+ */
+/**
+ * @brief I2C EEPROM Interface pins
+ */
+#define sEE_I2C I2C2
+#define sEE_I2C_CLK RCC_APB1Periph_I2C2
+
+#define sEE_I2C_SCL_PIN GPIO_Pin_6 /* PF.06 */
+#define sEE_I2C_SCL_GPIO_PORT GPIOF /* GPIOF */
+#define sEE_I2C_SCL_GPIO_CLK RCC_AHBPeriph_GPIOF
+#define sEE_I2C_SCL_SOURCE GPIO_PinSource6
+#define sEE_I2C_SCL_AF GPIO_AF_4
+
+#define sEE_I2C_SDA_PIN GPIO_Pin_10 /* PA.10 */
+#define sEE_I2C_SDA_GPIO_PORT GPIOA /* GPIOA */
+#define sEE_I2C_SDA_GPIO_CLK RCC_AHBPeriph_GPIOA
+#define sEE_I2C_SDA_SOURCE GPIO_PinSource10
+#define sEE_I2C_SDA_AF GPIO_AF_4
+
+/**
+ * @}
+ */
+
+/** @defgroup STM32303C_EVAL_LOW_LEVEL_Exported_Functions
+ * @{
+ */
+void STM_EVAL_LEDInit(Led_TypeDef Led);
+void STM_EVAL_LEDOn(Led_TypeDef Led);
+void STM_EVAL_LEDOff(Led_TypeDef Led);
+void STM_EVAL_LEDToggle(Led_TypeDef Led);
+void STM_EVAL_PBInit(Button_TypeDef Button, ButtonMode_TypeDef Button_Mode);
+uint32_t STM_EVAL_PBGetState(Button_TypeDef Button);
+void STM_EVAL_COMInit(COM_TypeDef COM, USART_InitTypeDef* USART_InitStruct);
+void SD_LowLevel_DeInit(void);
+void SD_LowLevel_Init(void);
+void TS751_LowLevel_DeInit(void);
+void TS751_LowLevel_Init(void);
+void sEE_SPI_LowLevel_DeInit(void);
+void sEE_SPI_LowLevel_Init(void);
+void sEE_I2C_LowLevel_DeInit(void);
+void sEE_I2C_LowLevel_Init(void);
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __STM32303C_EVAL_H */
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32303C_EVAL/stm32303c_eval_audio_codec.c b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32303C_EVAL/stm32303c_eval_audio_codec.c
new file mode 100644
index 0000000..9d0991d
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32303C_EVAL/stm32303c_eval_audio_codec.c
@@ -0,0 +1,1597 @@
+/**
+ ******************************************************************************
+ * @file stm32303c_eval_audio_codec.c
+ * @author MCD Application Team
+ * @version V1.0.1
+ * @date 23-October-2012
+ * @brief This file includes the low layer driver for CS42L52 Audio Codec
+ * available on STM32303C_EVAL evaluation board(MB1019).
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.st.com/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+
+/*==============================================================================================================================
+ User NOTES
+1. How To use this driver:
+--------------------------
+ - This driver supports STM32F30x devices on STM32303C_EVAL (MB1019) Evaluation boards.
+
+ - Configure the options in file stm32303c_eval_audio_codec.h in the section CONFIGURATION.
+ Refer to the sections 2 and 3 to have more details on the possible configurations.
+
+ - Call the function EVAL_AUDIO_Init(
+ OutputDevice: physical output mode (OUTPUT_DEVICE_SPEAKER,
+ OUTPUT_DEVICE_HEADPHONE, OUTPUT_DEVICE_AUTO or
+ OUTPUT_DEVICE_BOTH)
+ Volume: initial volume to be set (0 is min (mute), 100 is max (100%)
+ AudioFreq: Audio frequency in Hz (8000, 16000, 22500, 32000 ...)
+ this parameter is relative to the audio file/stream type.
+ )
+ This function configures all the hardware required for the audio application (codec, I2C, I2S,
+ GPIOs, DMA and interrupt if needed). This function returns 0 if configuration is OK.
+ if the returned value is different from 0 or the function is stuck then the communication with
+ the codec has failed (try to un-plug the power or reset device in this case).
+ + OUTPUT_DEVICE_SPEAKER: only speaker will be set as output for the audio stream.
+ + OUTPUT_DEVICE_HEADPHONE: only headphones will be set as output for the audio stream.
+ + OUTPUT_DEVICE_AUTO: Selection of output device is made through external switch (implemented
+ into the audio jack on the evaluation board). When the Headphone is connected it is used
+ as output. When the headphone is disconnected from the audio jack, the output is
+ automatically switched to Speaker.
+ + OUTPUT_DEVICE_BOTH: both Speaker and Headphone are used as outputs for the audio stream
+ at the same time.
+
+ - Call the function EVAL_AUDIO_Play(
+ pBuffer: pointer to the audio data file address
+ Size: size of the buffer to be sent in Bytes
+ )
+ to start playing (for the first time) from the audio file/stream.
+
+ - Call the function EVAL_AUDIO_PauseResume(
+ Cmd: AUDIO_PAUSE (or 0) to pause playing or AUDIO_RESUME (or
+ any value different from 0) to resume playing.
+ )
+ Note. After calling EVAL_AUDIO_PauseResume() function for pause, only EVAL_AUDIO_PauseResume() should be called
+ for resume (it is not allowed to call EVAL_AUDIO_Play() in this case).
+ Note. This function should be called only when the audio file is played or paused (not stopped).
+
+ - For each mode, you may need to implement the relative callback functions into your code.
+ The Callback functions are named EVAL_AUDIO_XXX_CallBack() and only their prototypes are declared in
+ the stm32303c_eval_audio_codec.h file. (refer to the example for more details on the callbacks implementations)
+
+ - To Stop playing, to modify the volume level or to mute, use the functions
+ EVAL_AUDIO_Stop(), EVAL_AUDIO_VolumeCtl() and EVAL_AUDIO_Mute().
+
+ - The driver API and the callback functions are at the end of the stm32303c_eval_audio_codec.h file.
+
+
+ Driver architecture:
+ --------------------
+ This driver is composed of three main layers:
+ o High Audio Layer: consists of the function API exported in the stm32303c_eval_audio_codec.h file
+ (EVAL_AUDIO_Init(), EVAL_AUDIO_Play() ...)
+ o Codec Control layer: consists of the functions API controlling the audio codec (CS42L52) and
+ included as local functions in file stm32303c_eval_audio_codec.c (Codec_Init(), Codec_Play() ...)
+ o Media Access Layer (MAL): which consists of functions allowing to access the media containing/
+ providing the audio file/stream. These functions are also included as local functions into
+ the stm32303c_eval_audio_codec.c file (Audio_MAL_Init(), Audio_MAL_Play() ...)
+ Each set of functions (layer) may be implemented independently of the others and customized when
+ needed.
+
+2. Modes description:
+---------------------
+ + AUDIO_MAL_MODE_NORMAL : is suitable when the audio file is in a memory location.
+ + AUDIO_MAL_MODE_CIRCULAR: is suitable when the audio data are read either from a
+ memory location or from a device at real time (double buffer could be used).
+
+3. DMA interrupts description:
+------------------------------
+ + EVAL_AUDIO_IT_TC_ENABLE: Enable this define to use the DMA end of transfer interrupt.
+ then, a callback should be implemented by user to perform specific actions
+ when the DMA has finished the transfer.
+ + EVAL_AUDIO_IT_HT_ENABLE: Enable this define to use the DMA end of half transfer interrupt.
+ then, a callback should be implemented by user to perform specific actions
+ when the DMA has reached the half of the buffer transfer (generally, it is useful
+ to load the first half of buffer while DMA is loading from the second half).
+ + EVAL_AUDIO_IT_ER_ENABLE: Enable this define to manage the cases of error on DMA transfer.
+
+4. Known Limitations:
+---------------------
+ 1- When using the Speaker, if the audio file quality is not high enough, the speaker output
+ may produce high and uncomfortable noise level. To avoid this issue, to use speaker
+ output properly, try to increase audio file sampling rate (typically higher than 48KHz).
+ This operation will lead to larger file size.
+ 2- Communication with the audio codec (through I2C) may be corrupted if it is interrupted by some
+ user interrupt routines (in this case, interrupts could be disabled just before the start of
+ communication then re-enabled when it is over). Note that this communication is only done at
+ the configuration phase (EVAL_AUDIO_Init() or EVAL_AUDIO_Stop()) and when Volume control modification is
+ performed (EVAL_AUDIO_VolumeCtl() or EVAL_AUDIO_Mute()). When the audio data is played, no communication is
+ required with the audio codec.
+ 3- Parsing of audio file is not implemented (in order to determine audio file properties: Mono/Stereo, Data size,
+ File size, Audio Frequency, Audio Data header size ...). The configuration is fixed for the given audio file.
+ 4- Mono audio streaming is not supported (in order to play mono audio streams, each data should be sent twice
+ on the I2S or should be duplicated on the source buffer. Or convert the stream in stereo before playing).
+ 5- Supports only 16-bit audio data size.
+===============================================================================================================================*/
+
+
+/* Includes ------------------------------------------------------------------*/
+#include "stm32303c_eval_audio_codec.h"
+
+/** @addtogroup Utilities
+ * @{
+ */
+
+/** @addtogroup STM32_EVAL
+ * @{
+ */
+
+/** @addtogroup STM32303C_EVAL
+ * @{
+ */
+
+/** @addtogroup STM32303C_EVAL_AUDIO_CODEC
+ * @brief This file includes the low layer driver for CS42L52 Audio Codec
+ * available on STM32303C_EVAL evaluation board(MB1019).
+ * @{
+ */
+
+/** @defgroup STM32303C_EVAL_AUDIO_CODEC_Private_Types
+ * @{
+ */
+/**
+ * @}
+ */
+
+/** @defgroup STM32303C_EVAL_AUDIO_CODEC_Private_Defines
+ * @{
+ */
+
+/* Mask for the bit EN of the I2S CFGR register */
+#define I2S_ENABLE_MASK 0x0400
+
+/* Delay for the Codec to be correctly reset */
+#define CODEC_RESET_DELAY 0x4FFF
+
+/* Codec audio Standards */
+#ifdef I2S_STANDARD_PHILLIPS
+ #define CODEC_STANDARD 0x04
+ #define I2S_STANDARD I2S_Standard_Phillips
+#elif defined(I2S_STANDARD_MSB)
+ #define CODEC_STANDARD 0x00
+ #define I2S_STANDARD I2S_Standard_MSB
+#elif defined(I2S_STANDARD_LSB)
+ #define CODEC_STANDARD 0x08
+ #define I2S_STANDARD I2S_Standard_LSB
+#else
+ #error "Error: No audio communication standard selected !"
+#endif /* I2S_STANDARD */
+
+/* The 7 bits Codec address (sent through I2C interface) */
+#define CODEC_ADDRESS 0x94 /* b1001010. */
+/**
+ * @}
+ */
+
+/** @defgroup STM32303C_EVAL_AUDIO_CODEC_Private_Macros
+ * @{
+ */
+/**
+ * @}
+ */
+
+/** @defgroup STM32303C_EVAL_AUDIO_CODEC_Private_Variables
+ * @{
+ */
+/* This structure is declared global because it is handled by two different functions */
+DMA_InitTypeDef DMA_InitStructure;
+DMA_InitTypeDef AUDIO_MAL_DMA_InitStructure;
+
+uint32_t AudioTotalSize = 0xFFFF; /* This variable holds the total size of the audio file */
+uint32_t AudioRemSize = 0xFFFF; /* This variable holds the remaining data in audio file */
+uint16_t *CurrentPos; /* This variable holds the current position of audio pointer */
+
+__IO uint32_t CODECTimeout = CODEC_LONG_TIMEOUT;
+__IO uint8_t OutputDev = 0;
+
+/**
+ * @}
+ */
+
+/** @defgroup STM32303C_EVAL_AUDIO_CODEC_Private_Function_Prototypes
+ * @{
+ */
+/**
+ * @}
+ */
+
+/** @defgroup STM32303C_EVAL_AUDIO_CODEC_Private_Functions
+ * @{
+ */
+
+/*----------------------------------------------------------------------------
+ Audio Codec functions
+ ----------------------------------------------------------------------------*/
+/* High Layer codec functions */
+static uint32_t Codec_Init(uint16_t OutputDevice, uint8_t Volume, uint32_t AudioFreq);
+static uint32_t Codec_DeInit(void);
+static uint32_t Codec_Play(void);
+static uint32_t Codec_PauseResume(uint32_t Cmd);
+static uint32_t Codec_Stop(uint32_t Cmd);
+static uint32_t Codec_VolumeCtrl(uint8_t Volume);
+static uint32_t Codec_Mute(uint32_t Cmd);
+/* Low layer codec functions */
+static void Codec_CtrlInterface_Init(void);
+static void Codec_CtrlInterface_DeInit(void);
+static void Codec_AudioInterface_Init(uint32_t AudioFreq);
+static void Codec_AudioInterface_DeInit(void);
+uint32_t Codec_ReadRegister(uint8_t RegisterAddr);
+static void Codec_GPIO_Init(void);
+static void Codec_GPIO_Recorder_Init(void);
+static void Codec_GPIO_DeInit(void);
+static void Delay(__IO uint32_t nCount);
+/*----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+ MAL (Media Access Layer) functions
+ ----------------------------------------------------------------------------*/
+/* Peripherals configuration functions */
+static void Audio_MAL_Init(void);
+static void Audio_MAL_DeInit(void);
+static void Audio_MAL_PauseResume(uint32_t Cmd, uint32_t Addr);
+static void Audio_MAL_Stop(void);
+/*----------------------------------------------------------------------------*/
+
+/**
+ * @brief Configure the audio peripherals.
+ * @param OutputDevice: OUTPUT_DEVICE_SPEAKER, OUTPUT_DEVICE_HEADPHONE,
+ * OUTPUT_DEVICE_BOTH or OUTPUT_DEVICE_AUTO .
+ * @param Volume: Initial volume level (from 0 (Mute) to 100 (Max))
+ * @param AudioFreq: Audio frequency used to play the audio stream.
+ * @retval 0 if correct communication, else wrong communication
+ */
+uint32_t EVAL_AUDIO_Init(uint16_t OutputDevice, uint8_t Volume, uint32_t AudioFreq)
+{
+ /* Perform low layer Codec initialization */
+ if (Codec_Init(OutputDevice, VOLUME_CONVERT(Volume), AudioFreq) != 0)
+ {
+ return 1;
+ }
+ else
+ {
+ /* I2S data transfer preparation:
+ Prepare the Media to be used for the audio transfer from memory to I2S peripheral */
+ Audio_MAL_Init();
+
+ /* Return 0 when all operations are OK */
+ return 0;
+ }
+}
+
+/**
+ * @brief Deinitializes all the resources used by the codec (those initialized
+ * by EVAL_AUDIO_Init() function).
+ * @param None
+ * @retval 0 if correct communication, else wrong communication
+ */
+uint32_t EVAL_AUDIO_DeInit(void)
+{
+ /* DeInitialize Codec */
+ Codec_DeInit();
+
+ /* DeInitialize the Media layer */
+ Audio_MAL_DeInit();
+
+ return 0;
+}
+
+/**
+ * @brief Starts playing audio stream from a data buffer for a determined size.
+ * @param pBuffer: Pointer to the buffer
+ * @param Size: Number of audio data BYTES.
+ * @retval 0 if correct communication, else wrong communication
+ */
+uint32_t EVAL_AUDIO_Play(uint16_t* pBuffer, uint32_t Size)
+{
+ /* Set the total number of data to be played (count in half-word) */
+ AudioTotalSize = Size/2;
+
+ /* Call the audio Codec Play function */
+ Codec_Play();
+
+ /* Update the Media layer and enable it for play */
+ Audio_MAL_Play((uint32_t)pBuffer, (uint32_t)(DMA_MAX(AudioTotalSize / 2)));
+
+ /* Update the remaining number of data to be played */
+ AudioRemSize = (Size/2) - DMA_MAX(AudioTotalSize);
+
+ /* Update the current audio pointer position */
+ CurrentPos = pBuffer + DMA_MAX(AudioTotalSize);
+
+ return 0;
+}
+
+/**
+ * @brief This function Pauses or Resumes the audio file stream. In case
+ * of using DMA, the DMA Pause feature is used. In all cases the I2S
+ * peripheral is disabled.
+ *
+ * @WARNING When calling EVAL_AUDIO_PauseResume() function for pause, only
+ * this function should be called for resume (use of EVAL_AUDIO_Play()
+ * function for resume could lead to unexpected behavior).
+ *
+ * @param Cmd: AUDIO_PAUSE (or 0) to pause, AUDIO_RESUME (or any value different
+ * from 0) to resume.
+ * @retval 0 if correct communication, else wrong communication
+ */
+uint32_t EVAL_AUDIO_PauseResume(uint32_t Cmd)
+{
+ /* Call the Audio Codec Pause/Resume function */
+ if (Codec_PauseResume(Cmd) != 0)
+ {
+ return 1;
+ }
+ else
+ {
+ /* Call the Media layer pause/resume function */
+ Audio_MAL_PauseResume(Cmd, 0);
+
+ /* Return 0 if all operations are OK */
+ return 0;
+ }
+}
+
+/**
+ * @brief Stops audio playing and Power down the Audio Codec.
+ * @param Option: could be one of the following parameters
+ * - CODEC_PDWN_SW: for software power off (by writing registers).
+ * Then no need to reconfigure the Codec after power on.
+ * - CODEC_PDWN_HW: completely shut down the codec (physically).
+ * Then need to reconfigure the Codec after power on.
+ * @retval 0 if correct communication, else wrong communication
+ */
+uint32_t EVAL_AUDIO_Stop(uint32_t Option)
+{
+ /* Call Audio Codec Stop function */
+ if (Codec_Stop(Option) != 0)
+ {
+ return 1;
+ }
+ else
+ {
+ /* Call Media layer Stop function */
+ Audio_MAL_Stop();
+
+ /* Update the remaining data number */
+ AudioRemSize = AudioTotalSize;
+
+ /* Return 0 when all operations are correctly done */
+ return 0;
+ }
+}
+
+/**
+ * @brief Controls the current audio volume level.
+ * @param Volume: Volume level to be set in percentage from 0% to 100% (0 for
+ * Mute and 100 for Max volume level).
+ * @retval 0 if correct communication, else wrong communication
+ */
+uint32_t EVAL_AUDIO_VolumeCtl(uint8_t Volume)
+{
+ /* Call the codec volume control function with converted volume value */
+ return (Codec_VolumeCtrl(VOLUME_CONVERT(Volume)));
+}
+
+/**
+ * @brief Enables or disables the MUTE mode by software
+ * @param Command: could be AUDIO_MUTE_ON to mute sound or AUDIO_MUTE_OFF to
+ * unmute the codec and restore previous volume level.
+ * @retval 0 if correct communication, else wrong communication
+ */
+uint32_t EVAL_AUDIO_Mute(uint32_t Cmd)
+{
+ /* Call the Codec Mute function */
+ return (Codec_Mute(Cmd));
+}
+
+/**
+ * @brief This function handles main Media layer interrupt.
+ * @param None
+ * @retval 0 if correct communication, else wrong communication
+ */
+void Audio_MAL_IRQHandler(void)
+{
+#ifndef AUDIO_MAL_MODE_NORMAL
+ uint16_t *pAddr = (uint16_t *)CurrentPos;
+ uint32_t Size = AudioRemSize;
+#endif /* AUDIO_MAL_MODE_NORMAL */
+
+#ifdef AUDIO_MAL_DMA_IT_TC_EN
+ /* Transfer complete interrupt */
+ if (DMA_GetFlagStatus(AUDIO_MAL_DMA_FLAG_TC) != RESET)
+ {
+ #ifdef AUDIO_MAL_MODE_NORMAL
+ /* Check if the end of file has been reached */
+ if (AudioRemSize > 0)
+ {
+ /* Wait the DMA Channel to be effectively disabled */
+ while (DMA_GetFlagStatus(AUDIO_MAL_DMA_FLAG_TC) != SET)
+ {}
+
+ /* Clear the Interrupt flag */
+ DMA_ClearFlag(AUDIO_MAL_DMA_FLAG_TC);
+
+ /* Re-Configure the buffer address and size */
+ DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t) CurrentPos;
+ DMA_InitStructure.DMA_BufferSize = (uint32_t) (DMA_MAX(AudioRemSize));
+
+ /* Configure the DMA Channel with the new parameters */
+ DMA_Init(AUDIO_MAL_DMA_CHANNEL , &DMA_InitStructure);
+
+ /* Enable the I2S DMA Channel */
+ DMA_Cmd(AUDIO_MAL_DMA_CHANNEL , ENABLE);
+
+ /* Update the current pointer position */
+ CurrentPos += DMA_MAX(AudioRemSize);
+
+ /* Update the remaining number of data to be played */
+ AudioRemSize -= DMA_MAX(AudioRemSize);
+ }
+ else
+ {
+ /* Disable the I2S DMA Channel */
+ DMA_Cmd(AUDIO_MAL_DMA_CHANNEL , DISABLE);
+
+ /* Clear the Interrupt flag */
+ DMA_ClearFlag(AUDIO_MAL_DMA_FLAG_TC);
+
+ /* Manage the remaining file size and new address offset: This function
+ should be coded by user (its prototype is already declared in stm32_eval_audio_codec.h) */
+ EVAL_AUDIO_TransferComplete_CallBack((uint32_t)CurrentPos, 0);
+ }
+
+ #elif defined(AUDIO_MAL_MODE_CIRCULAR)
+ /* Manage the remaining file size and new address offset: This function
+ should be coded by user (its prototype is already declared in stm32_eval_audio_codec.h) */
+ EVAL_AUDIO_TransferComplete_CallBack(pAddr, Size);
+
+ /* Clear the Interrupt flag */
+ DMA_ClearFlag(AUDIO_MAL_DMA_STREAM, AUDIO_MAL_DMA_FLAG_TC);
+ #endif /* AUDIO_MAL_MODE_NORMAL */
+ }
+#endif /* AUDIO_MAL_DMA_IT_TC_EN */
+
+#ifdef AUDIO_MAL_DMA_IT_HT_EN
+ /* Half Transfer complete interrupt */
+ if (DMA_GetFlagStatus(AUDIO_MAL_DMA_CHANNEL, AUDIO_MAL_DMA_FLAG_HT) != RESET)
+ {
+ /* Manage the remaining file size and new address offset: This function
+ should be coded by user (its prototype is already declared in stm32_eval_audio_codec.h) */
+ EVAL_AUDIO_HalfTransfer_CallBack((uint32_t)pAddr, Size);
+
+ /* Clear the Interrupt flag */
+ DMA_ClearFlag(AUDIO_MAL_DMA_CHANNEL, AUDIO_MAL_DMA_FLAG_HT);
+ }
+#endif /* AUDIO_MAL_DMA_IT_HT_EN */
+
+#ifdef AUDIO_MAL_DMA_IT_TE_EN
+ /* FIFO Error interrupt */
+ if ((DMA_GetFlagStatus(AUDIO_MAL_DMA_CHANNEL, AUDIO_MAL_DMA_FLAG_TE) != RESET) || \
+ (DMA_GetFlagStatus(AUDIO_MAL_DMA_CHANNEL, AUDIO_MAL_DMA_FLAG_FE) != RESET) || \
+ (DMA_GetFlagStatus(AUDIO_MAL_DMA_CHANNEL, AUDIO_MAL_DMA_FLAG_DME) != RESET))
+
+ {
+ /* Manage the error generated on DMA FIFO: This function
+ should be coded by user (its prototype is already declared in stm32_eval_audio_codec.h) */
+ EVAL_AUDIO_Error_CallBack((uint32_t*)&pAddr);
+
+ /* Clear the Interrupt flag */
+ DMA_ClearFlag(AUDIO_MAL_DMA_CHANNEL, AUDIO_MAL_DMA_FLAG_TE | AUDIO_MAL_DMA_FLAG_FE | \
+ AUDIO_MAL_DMA_FLAG_DME);
+ }
+#endif /* AUDIO_MAL_DMA_IT_TE_EN */
+}
+
+/*============================================================================
+ CS42L52 Audio Codec Control Functions
+ ============================================================================*/
+/**
+ * @brief Initializes the audio codec and all related interfaces (control
+ * interface: I2C and audio interface: I2S)
+ * @param OutputDevice: can be OUTPUT_DEVICE_SPEAKER, OUTPUT_DEVICE_HEADPHONE,
+ * OUTPUT_DEVICE_BOTH or OUTPUT_DEVICE_AUTO .
+ * @param Volume: Initial volume level (from 0 (Mute) to 100 (Max))
+ * @param AudioFreq: Audio frequency used to play the audio stream.
+ * @retval 0 if correct communication, else wrong communication
+ */
+static uint32_t Codec_Init(uint16_t OutputDevice, uint8_t Volume, uint32_t AudioFreq)
+{
+ uint32_t counter = 0;
+
+ /* Configure the Codec related IOs */
+ Codec_GPIO_Init();
+
+ /* Initialize the Control interface of the Audio Codec */
+ Codec_CtrlInterface_Init();
+
+ /* Keep Codec powered OFF */
+ counter += Codec_WriteRegister(0x02, 0x9E/*0x01*/);
+
+ switch (OutputDevice)
+ {
+ case OUTPUT_DEVICE_SPEAKER:
+ counter += Codec_WriteRegister(0x04, 0xFA); /* SPK always ON & HP always OFF */
+ OutputDev = 0xFA;
+ break;
+
+ case OUTPUT_DEVICE_HEADPHONE:
+ counter += Codec_WriteRegister(0x04, 0xAF); /* SPK always OFF & HP always ON */
+ OutputDev = 0xAF;
+ break;
+
+ case OUTPUT_DEVICE_BOTH:
+ counter += Codec_WriteRegister(0x04, 0xAA); /* SPK always ON & HP always ON */
+ OutputDev = 0xAA;
+ break;
+
+ case OUTPUT_DEVICE_AUTO:
+ counter += Codec_WriteRegister(0x04, 0x05); /* Detect the HP or the SPK automatically */
+ OutputDev = 0x05;
+ break;
+
+ default:
+ counter += Codec_WriteRegister(0x04, 0x05); /* Detect the HP or the SPK automatically */
+ OutputDev = 0x05;
+ break;
+ }
+
+ /* Clock configuration: Auto detection */
+ counter += Codec_WriteRegister(0x05, 0x80);
+ /* Set the Slave Mode and the audio Standard */
+ counter += Codec_WriteRegister(0x06, 0x03/*CODEC_STANDARD*/);
+ /* Interface Control 2: SCLK is Re-timed signal from MCLK*/
+ counter +=Codec_WriteRegister(0x07, 0x00);
+ /* ADCA and PGAA Select: no input selected*/
+ counter +=Codec_WriteRegister(0x08, 0x00);
+ /* ADCB and PGAB Select: no input selected*/
+ counter +=Codec_WriteRegister(0x09, 0x00);
+ /*Play Back Control 1: headphone gain is 0.4, PCM not inverted, Master not mute*/
+ counter +=Codec_WriteRegister(0x0D, 0x10);/* CS42L52 has different config than CS42L52*/
+ /* Miscellaneous Controls: Passthrough Analog & Passthrough Mute off, Soft Ramp on @0x0E*/
+ counter +=Codec_WriteRegister(0x0E, 0x02);
+ /* Play Back Control 2: Headphone Mute off, speaker mute off, mono enabled */
+ counter +=Codec_WriteRegister(0x0F, 0x32);
+ /* PCM A Volume: PCM Mute disabled, Volume is 0db(default) */
+ counter +=Codec_WriteRegister(0x1A, 0x00);
+ /* PCM B Volume: PCM Mute disabled, Volume is 0db(default) */
+ counter +=Codec_WriteRegister(0x1B, 0x00);
+ /* Headphone A Volume: Headphone Volume is -6db */
+ counter +=Codec_WriteRegister(0x22, (u8)(0-12));
+ /* Headphone B Volume: Headphone Volume is -6db */
+ counter +=Codec_WriteRegister(0x23, (u8)(0-12));
+ /* Speaker A Volume: Speaker Volume is 0db (default) */
+ counter +=Codec_WriteRegister(0x24, 0x00);
+ /* Speaker B Volume: Speaker Volume is 0db (default) */
+ counter +=Codec_WriteRegister(0x25, 0x00);
+ /* Charge Pump Frequency: 5 (default) */
+ counter +=Codec_WriteRegister(0x34, 5<<4);
+ /* Power Control 1: power up */
+ counter += Codec_WriteRegister(0x02, 0x00);
+ counter += Codec_WriteRegister(0x20, 0xff);
+ counter += Codec_WriteRegister(0x21, 0xff);
+
+ /* Configure the I2S peripheral */
+ Codec_AudioInterface_Init(AudioFreq);
+
+ /* Return communication control value */
+ return counter;
+}
+
+/**
+ * @brief Initializes the audio codec and all related interfaces (control
+ * interface: I2C and audio interface: I2S)
+ * @param OutputDevice: can be OUTPUT_DEVICE_SPEAKER, OUTPUT_DEVICE_HEADPHONE,
+ * OUTPUT_DEVICE_BOTH or OUTPUT_DEVICE_AUTO .
+ * @param Volume: Initial volume level (from 0 (Mute) to 100 (Max))
+ * @param AudioFreq: Audio frequency used to play the audio stream.
+ * @retval 0 if correct communication, else wrong communication
+ */
+uint32_t Codec_Record_Init(void)
+{
+ uint32_t counter = 0;
+
+ /* Configure the Codec related IOs */
+ Codec_GPIO_Recorder_Init();
+
+ /* Initialize the Control interface of the Audio Codec */
+ Codec_CtrlInterface_Init();
+
+ /* Mono Record @ MIC1+ with Bias */
+ /* Power Control 2[@03h]: MICB Off, MIC A & Bias On */
+ counter += Codec_WriteRegister(0x03, 0x04);
+ /* Power Control 3[@04h]: headphone A/B Off, speaker A & B Off */
+ counter += Codec_WriteRegister(0x04, 0xFF);
+ /* Clocking Control: auto sample rate(Fs) */
+ counter += Codec_WriteRegister(0x05, 0x80);
+ /* Interface Control 1: slave, LeftJustified, 16-bit data */
+ counter += Codec_WriteRegister(0x06, 0x03);
+ /* Interface Control 2: SCLK is Re-timed signal from MCLK, BIAS: 0.5*VA */
+ counter += Codec_WriteRegister(0x07, 0x00);
+ /* ADCA and PGAA Select: MICx selected */
+ counter += Codec_WriteRegister(0x08, 0x90);
+ /* ADCB and PGAB Select: MICx selected */
+ counter += Codec_WriteRegister(0x09, 0x90);
+ /* Misc ADC Control: SDOUT Signal Source is ADC_or_DSP */
+ counter += Codec_WriteRegister(0x0C, 0x00);
+ /* Play Back Control 1: headphone gain is 0.4, PCM not inverted, Master not mute */
+ counter += Codec_WriteRegister(0x0D, 0x00);
+ /* Miscellaneous Controls: Passthrough Analog & Passthrough Mute off, Soft Ramp on @0x0E */
+ counter += Codec_WriteRegister(0x0E, 0x02);
+ /* Play Back Control 2: Headphone Mute on, speaker mute off, mono enabled */
+ counter += Codec_WriteRegister(0x0F, 0xC2);
+ /* MICA Amp Control: select MIC 2x, Single-Ended, Gain=16db */
+ counter += Codec_WriteRegister(0x10, 0x2E);
+ /* MICB Amp Control: select MIC 2x, Single-Ended, Gain=16db */
+ counter += Codec_WriteRegister(0x11, 0x40);
+ /* MICB Amp Control: try with Differential, Gain=16db */
+ counter += Codec_WriteRegister(0x11, 0x20);
+ /* PGA Volume ALC Control: Gain=0db */
+ counter += Codec_WriteRegister(0x12, 0x00);
+ /* PGA Volume ALC Control: Gain=0db */
+ counter += Codec_WriteRegister(0x13, 0x00);
+ counter += Codec_WriteRegister(0x34, 5<<4);
+
+ counter += Codec_WriteRegister(0x02, 0x14);
+
+ /* Return communication control value */
+ return counter;
+
+}
+
+/**
+ * @brief Restore the audio codec state to default state and free all used
+ * resources.
+ * @param None
+ * @retval 0 if correct communication, else wrong communication
+ */
+static uint32_t Codec_DeInit(void)
+{
+ uint32_t counter = 0;
+ uint16_t i = 0;
+ uint8_t tmp = 0;
+
+ /* Enable Master Playback Mute @0x0D */
+ counter += Codec_WriteRegister(0x02, 0x03);
+ /* Power down CS42L52 @0x03 */
+ counter += Codec_WriteRegister(0x03, 0x07);
+ /* Power down CS42L52 @0x04 */
+ counter += Codec_WriteRegister(0x04, 0xFF);
+ /* config interface @0x06 */
+ counter += Codec_WriteRegister(0x06, 0x03);
+ /* Disable Analog (Soft Ramp & Zero Cross) and HighPassFilter @0x0A */
+ counter += Codec_WriteRegister(0x0A, 0x00);
+ /* Digital Soft Ramp on & Zero Cross off @0x0E */
+ counter += Codec_WriteRegister(0x0E, 0x02);
+ /* Headphone Mute, Speaker Mute @0x0F */
+ counter += Codec_WriteRegister(0x0F, 0xF2);
+ /* PCM A Volume: Mute @0x1A */
+ counter += Codec_WriteRegister(0x1A, 0x80);
+ /* PCM B Volume: Mute @0x1B */
+ counter += Codec_WriteRegister(0x1B, 0x80);
+ /* Limiter Attack Rate: 0x00 @0x29 */
+ counter += Codec_WriteRegister(0x29, 0x00);
+
+ i = 0;
+ do{
+ // Power down CS42L52 @0x02
+ counter += Codec_WriteRegister(0x02, 0x9F);
+ tmp = Codec_ReadRegister(0x02);
+ i++;
+ }
+ while (((tmp & 0x01) == 0) && (i < 10));
+
+ Delay(CODEC_RESET_DELAY);
+
+ /* Deinitialize all use GPIOs */
+ Codec_GPIO_DeInit();
+
+ /* Deinitialize the Codec audio interface (I2S) */
+ Codec_AudioInterface_DeInit();
+ /* Disable the Codec control interface */
+ Codec_CtrlInterface_DeInit();
+
+ /* Return communication control value */
+ return counter;
+}
+
+/**
+ * @brief Start the audio Codec play feature.
+ * @note For this codec no Play options are required.
+ * @param None
+ * @retval 0 if correct communication, else wrong communication
+ */
+static uint32_t Codec_Play(void)
+{
+ /*
+ No actions required on Codec level for play command
+ */
+
+ /* Return communication control value */
+ return 0;
+}
+
+/**
+ * @brief Pauses and resumes playing on the audio codec.
+ * @param Cmd: AUDIO_PAUSE (or 0) to pause, AUDIO_RESUME (or any value different
+ * from 0) to resume.
+ * @retval 0 if correct communication, else wrong communication
+ */
+static uint32_t Codec_PauseResume(uint32_t Cmd)
+{
+ uint32_t counter = 0;
+
+ /* Pause the audio file playing */
+ if (Cmd == AUDIO_PAUSE)
+ {
+ /* Mute the output first */
+ counter += Codec_Mute(AUDIO_MUTE_ON);
+
+ /* Put the Codec in Power save mode */
+ counter += Codec_WriteRegister(0x02, 0x01);
+ }
+ else /* AUDIO_RESUME */
+ {
+ /* Unmute the output first */
+ counter += Codec_Mute(AUDIO_MUTE_OFF);
+
+ counter += Codec_WriteRegister(0x04, OutputDev);
+
+ /* Exit the Power save mode */
+ counter += Codec_WriteRegister(0x02, 0x9E);
+
+ }
+
+ return counter;
+}
+
+/**
+ * @brief Stops audio Codec playing. It powers down the codec.
+ * @param CodecPdwnMode: selects the power down mode.
+ * - CODEC_PDWN_SW: only mutes the audio codec. When resuming from this
+ * mode the codec keeps the previous initialization
+ * (no need to re-Initialize the codec registers).
+ * - CODEC_PDWN_HW: Physically power down the codec. When resuming from this
+ * mode, the codec is set to default configuration
+ * (user should re-Initialize the codec in order to
+ * play again the audio stream).
+ * @retval 0 if correct communication, else wrong communication
+ */
+static uint32_t Codec_Stop(uint32_t CodecPdwnMode)
+{
+ uint32_t counter = 0;
+
+ /* Mute the output first */
+ Codec_Mute(AUDIO_MUTE_ON);
+
+ if (CodecPdwnMode == CODEC_PDWN_SW)
+ {
+ /* Power down the DAC and the speaker (PMDAC and PMSPK bits)*/
+ counter += Codec_WriteRegister(0x02, 0x9F);
+ }
+ else /* CODEC_PDWN_HW */
+ {
+ /* Power down the components */
+ counter += Codec_WriteRegister(0x02, 0x9F);
+
+ /* Wait at least 100us */
+ Delay(0xFFF);
+ }
+ return counter;
+}
+
+/**
+ * @brief Sets higher or lower the codec volume level.
+ * @param Volume: a byte value from 0 to 255 (refer to codec registers
+ * description for more details).
+ * @retval 0 if correct communication, else wrong communication
+ */
+static uint32_t Codec_VolumeCtrl(uint8_t Volume)
+{
+ uint32_t counter = 0;
+
+ if (Volume > 0xE6)
+ {
+ /* Set the Master volume */
+ counter += Codec_WriteRegister(0x20, Volume - 0xE7);
+ counter += Codec_WriteRegister(0x21, Volume - 0xE7);
+ }
+ else
+ {
+ /* Set the Master volume */
+ counter += Codec_WriteRegister(0x20, Volume + 0x19);
+ counter += Codec_WriteRegister(0x21, Volume + 0x19);
+ }
+
+ return counter;
+}
+
+/**
+ * @brief Enables or disables the mute feature on the audio codec.
+ * @param Cmd: AUDIO_MUTE_ON to enable the mute or AUDIO_MUTE_OFF to disable the
+ * mute mode.
+ * @retval 0 if correct communication, else wrong communication
+ */
+static uint32_t Codec_Mute(uint32_t Cmd)
+{
+ uint32_t counter = 0;
+
+ /* Set the Mute mode */
+ if (Cmd == AUDIO_MUTE_ON)
+ {
+ counter += Codec_WriteRegister(0x04, 0xFF);
+ counter += Codec_WriteRegister(0x0F, 0xF0);
+ }
+ else /* AUDIO_MUTE_OFF Disable the Mute */
+ {
+ counter += Codec_WriteRegister(0x04, 0x05);
+ counter += Codec_WriteRegister(0x0F, 0x02);
+ }
+
+ return counter;
+}
+
+/**
+ * @brief Switch dynamically (while audio file is played) the output target
+ * (speaker or headphone).
+ * @note This function modifies a global variable of the audio codec driver: OutputDev.
+ * @param Output: specifies the audio output target: OUTPUT_DEVICE_SPEAKER,
+ * OUTPUT_DEVICE_HEADPHONE, OUTPUT_DEVICE_BOTH or OUTPUT_DEVICE_AUTO
+ * @retval 0 if correct communication, else wrong communication
+ */
+uint32_t Codec_SwitchOutput(uint8_t Output)
+{
+ uint8_t counter = 0;
+
+ switch (Output)
+ {
+ case OUTPUT_DEVICE_SPEAKER:
+ counter += Codec_WriteRegister(0x04, 0xFA); /* SPK always ON & HP always OFF */
+ OutputDev = 0xFA;
+ break;
+
+ case OUTPUT_DEVICE_HEADPHONE:
+ counter += Codec_WriteRegister(0x04, 0xAF); /* SPK always OFF & HP always ON */
+ OutputDev = 0xAF;
+ break;
+
+ case OUTPUT_DEVICE_BOTH:
+ counter += Codec_WriteRegister(0x04, 0xAA); /* SPK always ON & HP always ON */
+ OutputDev = 0xAA;
+ break;
+
+ case OUTPUT_DEVICE_AUTO:
+ counter += Codec_WriteRegister(0x04, 0x05); /* Detect the HP or the SPK automatically */
+ OutputDev = 0x05;
+ break;
+
+ default:
+ counter += Codec_WriteRegister(0x04, 0x05); /* Detect the HP or the SPK automatically */
+ OutputDev = 0x05;
+ break;
+ }
+
+ return counter;
+}
+
+/**
+ * @brief Writes a Byte to a given register into the audio codec through the
+ control interface (I2C)
+ * @param RegisterAddr: The address (location) of the register to be written.
+ * @param RegisterValue: the Byte value to be written into destination register.
+ * @retval 0 if correct communication, else wrong communication
+ */
+uint32_t Codec_WriteRegister(uint8_t RegisterAddr, uint8_t RegisterValue)
+{
+ uint32_t result = 0;
+
+ /* Test on BUSY Flag */
+ CODECTimeout = CODEC_FLAG_TIMEOUT;
+ while(I2C_GetFlagStatus(CODEC_I2C, I2C_ISR_BUSY) != RESET)
+ {
+ if((CODECTimeout--) == 0) return Codec_TIMEOUT_UserCallback();
+ }
+
+ /* Configure slave address, nbytes, reload, end mode and start or stop generation */
+ I2C_TransferHandling(CODEC_I2C, CODEC_ADDRESS, 2, I2C_AutoEnd_Mode, I2C_Generate_Start_Write);
+
+ /* Wait until TXIS flag is set */
+ CODECTimeout = CODEC_FLAG_TIMEOUT;
+ while(I2C_GetFlagStatus(CODEC_I2C, I2C_ISR_TXIS) == RESET)
+ {
+ if((CODECTimeout--) == 0) return Codec_TIMEOUT_UserCallback();
+ }
+
+ /* Send Register address */
+ I2C_SendData(CODEC_I2C, (uint8_t)RegisterAddr );
+
+ /* Wait until TXIS flag is set */
+ CODECTimeout = CODEC_FLAG_TIMEOUT;
+ while(I2C_GetFlagStatus(CODEC_I2C, I2C_ISR_TXIS) == RESET)
+ {
+ if((CODECTimeout--) == 0) return Codec_TIMEOUT_UserCallback();
+ }
+
+ /* Write data to TXDR */
+ I2C_SendData(CODEC_I2C, (uint8_t)RegisterValue);
+
+ /* Wait until STOPF flag is set */
+ CODECTimeout = CODEC_FLAG_TIMEOUT;
+ while(I2C_GetFlagStatus(CODEC_I2C, I2C_ISR_STOPF) == RESET)
+ {
+ if((CODECTimeout--) == 0) return Codec_TIMEOUT_UserCallback();
+ }
+
+ /* Clear STOPF flag */
+ I2C_ClearFlag(CODEC_I2C, I2C_ICR_STOPCF);
+
+#ifdef VERIFY_WRITTENDATA
+ /* Verify that the data has been correctly written */
+ result = (Codec_ReadRegister(RegisterAddr) == RegisterValue)? 0:1;
+#endif /* VERIFY_WRITTENDATA */
+
+ /* Return the verifying value: 0 (Passed) or 1 (Failed) */
+ return result;
+}
+
+/**
+ * @brief Reads and returns the value of an audio codec register through the
+ * control interface (I2C).
+ * @param RegisterAddr: Address of the register to be read.
+ * @retval Value of the register to be read or dummy value if the communication
+ * fails.
+ */
+uint32_t Codec_ReadRegister(uint8_t RegisterAddr)
+{
+ uint32_t result = 0;
+
+ /* Test on BUSY Flag */
+ CODECTimeout = CODEC_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(CODEC_I2C, I2C_ISR_BUSY) != RESET)
+ {
+ if((CODECTimeout--) == 0) return Codec_TIMEOUT_UserCallback();
+ }
+
+ /* Configure slave address, nbytes, reload, end mode and start or stop generation */
+ I2C_TransferHandling(CODEC_I2C, CODEC_ADDRESS, 1, I2C_SoftEnd_Mode, I2C_Generate_Start_Write);
+
+ /* Wait until TXIS flag is set */
+ CODECTimeout = CODEC_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(CODEC_I2C, I2C_ISR_TXIS) == RESET)
+ {
+ if((CODECTimeout--) == 0) return Codec_TIMEOUT_UserCallback();
+ }
+
+ /* Send Register address */
+ I2C_SendData(CODEC_I2C, (uint8_t)RegisterAddr);
+
+ /* Wait until TC flag is set */
+ CODECTimeout = CODEC_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(CODEC_I2C, I2C_ISR_TC) == RESET)
+ {
+ if((CODECTimeout--) == 0) return Codec_TIMEOUT_UserCallback();
+ }
+
+ /* Configure slave address, nbytes, reload, end mode and start or stop generation */
+ I2C_TransferHandling(CODEC_I2C, CODEC_ADDRESS, 1, I2C_AutoEnd_Mode, I2C_Generate_Start_Read);
+
+ /* Wait until RXNE flag is set */
+ CODECTimeout = CODEC_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(CODEC_I2C, I2C_ISR_RXNE) == RESET)
+ {
+ if((CODECTimeout--) == 0) return Codec_TIMEOUT_UserCallback();
+ }
+
+ /* Read data from RXDR */
+ result = I2C_ReceiveData(CODEC_I2C);
+
+ /* Wait until STOPF flag is set */
+ CODECTimeout = CODEC_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(CODEC_I2C, I2C_ISR_STOPF) == RESET)
+ {
+ if((CODECTimeout--) == 0) return Codec_TIMEOUT_UserCallback();
+ }
+
+ /* Clear STOPF flag */
+ I2C_ClearFlag(CODEC_I2C, I2C_ICR_STOPCF);
+
+ /* Return the byte read from Codec */
+ return result;
+}
+
+/**
+ * @brief Initializes the Audio Codec control interface (I2C).
+ * @param None
+ * @retval None
+ */
+static void Codec_CtrlInterface_Init(void)
+{
+ I2C_InitTypeDef I2C_InitStructure;
+
+ /* Configure the I2C clock source. The clock is derived from the SYSCLK */
+ RCC_I2CCLKConfig(RCC_I2C2CLK_SYSCLK);
+
+ /* Enable the CODEC_I2C peripheral clock */
+ RCC_APB1PeriphClockCmd(CODEC_I2C_CLK, ENABLE);
+
+ /* CODEC_I2C configuration */
+ I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
+ I2C_InitStructure.I2C_AnalogFilter = I2C_AnalogFilter_Enable;
+ I2C_InitStructure.I2C_DigitalFilter = 0x00;
+ I2C_InitStructure.I2C_OwnAddress1 = 0x00;
+ I2C_InitStructure.I2C_Ack = I2C_Ack_Disable;
+ I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
+ I2C_InitStructure.I2C_Timing = CODEC_I2C_TIMING;
+
+ /* Enable the I2C peripheral */
+ I2C_Init(CODEC_I2C, &I2C_InitStructure);
+ I2C_Cmd(CODEC_I2C, ENABLE);
+
+}
+
+/**
+ * @brief Restore the Audio Codec control interface to its default state.
+ * This function doesn't de-initialize the I2C because the I2C peripheral
+ * may be used by other modules.
+ * @param None
+ * @retval None
+ */
+static void Codec_CtrlInterface_DeInit(void)
+{
+ /* Disable the I2C peripheral */ /* This step is not done here because
+ the I2C interface can be used by other modules */
+ /*I2C_DeInit(CODEC_I2C); */
+}
+
+/**
+ * @brief Initializes the Audio Codec audio interface (I2S)
+ * @note This function assumes that the I2S input clock (through PLL_R in
+ * Devices RevA/Z and through dedicated PLLI2S_R in Devices RevB/Y)
+ * is already configured and ready to be used.
+ * @param AudioFreq: Audio frequency to be configured for the I2S peripheral.
+ * @retval None
+ */
+static void Codec_AudioInterface_Init(uint32_t AudioFreq)
+{
+ I2S_InitTypeDef I2S_InitStructure;
+
+ /* Enable the CODEC_I2S peripheral clock */
+ RCC_APB1PeriphClockCmd(CODEC_I2S_CLK, ENABLE);
+
+ /* Deinitialize SPI3_I2S3 peripheral */
+ SPI_I2S_DeInit(CODEC_I2S);
+
+ /* CODEC_I2S peripheral configuration */
+ SPI_I2S_DeInit(CODEC_I2S);
+ I2S_InitStructure.I2S_AudioFreq = AudioFreq;
+ I2S_InitStructure.I2S_Standard = I2S_Standard_MSB;
+ I2S_InitStructure.I2S_DataFormat = I2S_DataFormat_16b;
+ I2S_InitStructure.I2S_CPOL = I2S_CPOL_Low;
+ I2S_InitStructure.I2S_Mode = I2S_Mode_MasterTx;
+#ifdef CODEC_MCLK_ENABLED
+ I2S_InitStructure.I2S_MCLKOutput = I2S_MCLKOutput_Enable;
+#elif defined(CODEC_MCLK_DISABLED)
+ I2S_InitStructure.I2S_MCLKOutput = I2S_MCLKOutput_Disable;
+#else
+ #error "No selection for the MCLK output has been defined !"
+#endif /* CODEC_MCLK_ENABLED */
+
+ /* Initialize the I2S peripheral with the structure above */
+ I2S_Init(CODEC_I2S, &I2S_InitStructure);
+
+ /* The I2S peripheral will be enabled only in the EVAL_AUDIO_Play() function
+ or by user functions if DMA mode not enabled */
+}
+
+/**
+ * @brief Restores the Audio Codec audio interface to its default state.
+ * @param None
+ * @retval None
+ */
+static void Codec_AudioInterface_DeInit(void)
+{
+ /* Disable the CODEC_I2S peripheral (in case it hasn't already been disabled) */
+ I2S_Cmd(CODEC_I2S, DISABLE);
+
+ /* Deinitialize the CODEC_I2S peripheral */
+ SPI_I2S_DeInit(CODEC_I2S);
+
+ /* Disable the CODEC_I2S peripheral clock */
+ RCC_APB1PeriphClockCmd(CODEC_I2S_CLK, DISABLE);
+}
+
+/**
+ * @brief Initializes IOs used by the Audio Codec (on the control and audio
+ * interfaces).
+ * @param None
+ * @retval None
+ */
+static void Codec_GPIO_Init(void)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+ NVIC_InitTypeDef NVIC_InitStructure;
+ I2S_InitTypeDef I2S_InitStructure;
+
+ /* Enable I2S and I2C GPIO clocks */
+ RCC_AHBPeriphClockCmd(CODEC_I2C_GPIO_CLOCK | CODEC_I2S_GPIO_CLOCK, ENABLE);
+
+ /* Connect pins to I2C peripheral */
+ GPIO_PinAFConfig(CODEC_I2C_SCL_GPIO, CODEC_I2S_SCL_PINSRC, CODEC_I2C_GPIO_AF);
+ GPIO_PinAFConfig(CODEC_I2C_SDA_GPIO, CODEC_I2S_SDA_PINSRC, CODEC_I2C_GPIO_AF);
+
+ /* CODEC_I2C SCL and SDA pins configuration ----------------------------------*/
+ GPIO_InitStructure.GPIO_Pin = CODEC_I2C_SDA_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
+ GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
+ GPIO_Init(CODEC_I2C_SDA_GPIO, &GPIO_InitStructure);
+
+ GPIO_InitStructure.GPIO_Pin = CODEC_I2C_SCL_PIN ;
+ GPIO_Init(CODEC_I2C_SCL_GPIO, &GPIO_InitStructure);
+
+ /* Connect pins to I2S peripheral */
+ GPIO_PinAFConfig(CODEC_I2S_MCK_WS_GPIO, CODEC_I2S_WS_PINSRC, CODEC_I2S_GPIO_AF);
+ GPIO_PinAFConfig(CODEC_I2S_GPIO, CODEC_I2S_SCK_PINSRC, CODEC_I2S_GPIO_AF);
+ GPIO_PinAFConfig(CODEC_I2S_GPIO, CODEC_I2S_DIN_PINSRC, CODEC_I2S_GPIO_AF);
+ GPIO_PinAFConfig(CODEC_I2S_GPIO, CODEC_I2S_DOUT_PINSRC, CODEC_I2S_GPIO_AF);
+
+ /* CODEC_I2S pins configuration: WS, SCK, DIN and DOUT pins -------------------------*/
+ GPIO_InitStructure.GPIO_Pin = CODEC_I2S_SCK_PIN | CODEC_I2S_DIN_PIN | CODEC_I2S_DOUT_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
+ GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
+ GPIO_Init(CODEC_I2S_GPIO, &GPIO_InitStructure);
+
+ GPIO_InitStructure.GPIO_Pin = CODEC_I2S_WS_PIN;
+ GPIO_Init(CODEC_I2S_MCK_WS_GPIO, &GPIO_InitStructure);
+
+ #ifdef CODEC_MCLK_ENABLED
+ /* CODEC_I2S pins configuration: MCK pin */
+ GPIO_InitStructure.GPIO_Pin = CODEC_I2S_MCK_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
+ GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
+ GPIO_Init(CODEC_I2S_MCK_WS_GPIO, &GPIO_InitStructure);
+ /* Connect pins to I2S peripheral */
+ GPIO_PinAFConfig(CODEC_I2S_MCK_WS_GPIO, CODEC_I2S_MCK_PINSRC, CODEC_I2S_MCK_GPIO_AF);
+ #endif /* CODEC_MCLK_ENABLED */
+
+ /* SPI3/I2S3 IRQ Channel configuration */
+ NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
+
+ NVIC_InitStructure.NVIC_IRQChannel = SPI3_IRQn;
+ NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
+ NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;
+ NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
+ NVIC_Init(&NVIC_InitStructure);
+
+ RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI3, ENABLE);
+
+ /* Deinitialize SPI3_I2S3 peripheral */
+ SPI_I2S_DeInit(CODEC_I2S);
+ /* I2S3 configuration ---------------------------------------//
+ SPI3_I2S3 - configured as follow:
+ - Work as Master & (transmiter) Rx
+ - 16bit data
+ - (Disable) Output MCLK
+ - Audio sample rate: 11kHz(have to use 8k/24k for CS42L52 ?)
+ - Default clock polarity: low level */
+ I2S_InitStructure.I2S_Mode = I2S_Mode_MasterTx;
+ I2S_InitStructure.I2S_Standard = I2S_Standard_MSB;
+ I2S_InitStructure.I2S_DataFormat = I2S_DataFormat_16b;
+ I2S_InitStructure.I2S_MCLKOutput = I2S_MCLKOutput_Enable;
+ I2S_InitStructure.I2S_AudioFreq = I2S_AudioFreq_32k;
+ I2S_InitStructure.I2S_CPOL = I2S_CPOL_Low;
+ I2S_Init(CODEC_I2S, &I2S_InitStructure);
+ /* Disable the I2S3 TXE Interrupt */
+ SPI_I2S_ITConfig(CODEC_I2S, SPI_I2S_IT_TXE, DISABLE);
+ /* Enable the SPI3/I2S3 peripheral */
+ I2S_Cmd(CODEC_I2S, ENABLE);
+
+}
+
+/**
+ * @brief Initializes IOs used by the Audio Codec (on the control and audio
+ * interfaces).
+ * @param None
+ * @retval None
+ */
+static void Codec_GPIO_Recorder_Init(void)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+ NVIC_InitTypeDef NVIC_InitStructure;
+ I2S_InitTypeDef I2S_InitStructure;
+
+ /* Enable I2S and I2C GPIO clocks */
+ RCC_AHBPeriphClockCmd(CODEC_I2C_GPIO_CLOCK | CODEC_I2S_GPIO_CLOCK, ENABLE);
+
+ /* Connect pins to I2C peripheral */
+ GPIO_PinAFConfig(CODEC_I2C_SCL_GPIO, CODEC_I2S_SCL_PINSRC, CODEC_I2C_GPIO_AF);
+ GPIO_PinAFConfig(CODEC_I2C_SDA_GPIO, CODEC_I2S_SDA_PINSRC, CODEC_I2C_GPIO_AF);
+
+ /* CODEC_I2C SCL and SDA pins configuration ----------------------------------*/
+ GPIO_InitStructure.GPIO_Pin = CODEC_I2C_SDA_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
+ GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
+ GPIO_Init(CODEC_I2C_SDA_GPIO, &GPIO_InitStructure);
+
+ GPIO_InitStructure.GPIO_Pin = CODEC_I2C_SCL_PIN ;
+ GPIO_Init(CODEC_I2C_SCL_GPIO, &GPIO_InitStructure);
+
+ /* Connect pins to I2S peripheral */
+ GPIO_PinAFConfig(CODEC_I2S_MCK_WS_GPIO, CODEC_I2S_WS_PINSRC, CODEC_I2S_GPIO_AF);
+ GPIO_PinAFConfig(CODEC_I2S_GPIO, CODEC_I2S_SCK_PINSRC, CODEC_I2S_GPIO_AF);
+ GPIO_PinAFConfig(CODEC_I2S_GPIO, CODEC_I2S_DIN_PINSRC, CODEC_I2S_GPIO_AF);
+ GPIO_PinAFConfig(CODEC_I2S_GPIO, CODEC_I2S_DOUT_PINSRC, CODEC_I2S_GPIO_AF);
+
+ /* CODEC_I2S pins configuration: WS, SCK, DIN and DOUT pins -------------------------*/
+ GPIO_InitStructure.GPIO_Pin = CODEC_I2S_SCK_PIN | CODEC_I2S_DIN_PIN | CODEC_I2S_DOUT_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
+ GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
+ GPIO_Init(CODEC_I2S_GPIO, &GPIO_InitStructure);
+
+ GPIO_InitStructure.GPIO_Pin = CODEC_I2S_WS_PIN;
+ GPIO_Init(CODEC_I2S_MCK_WS_GPIO, &GPIO_InitStructure);
+
+ #ifdef CODEC_MCLK_ENABLED
+ /* CODEC_I2S pins configuration: MCK pin */
+ GPIO_InitStructure.GPIO_Pin = CODEC_I2S_MCK_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
+ GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
+ GPIO_Init(CODEC_I2S_MCK_WS_GPIO, &GPIO_InitStructure);
+ /* Connect pins to I2S peripheral */
+ GPIO_PinAFConfig(CODEC_I2S_MCK_WS_GPIO, CODEC_I2S_MCK_PINSRC, CODEC_I2S_MCK_GPIO_AF);
+ #endif /* CODEC_MCLK_ENABLED */
+
+
+ /* SPI3/I2S3 IRQ Channel configuration */
+ NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
+
+ NVIC_InitStructure.NVIC_IRQChannel = SPI3_IRQn;
+ NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
+ NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;
+ NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
+ NVIC_Init(&NVIC_InitStructure);
+
+ RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI3, ENABLE);
+
+ /* Deinitialize SPI3_I2S3 peripheral */
+ SPI_I2S_DeInit(CODEC_I2S);
+ /* I2S3 configuration ---------------------------------------//
+ SPI3_I2S3 - configured as follow:
+ - Work as Master & (transmiter) Rx
+ - 16bit data
+ - (Disable) Output MCLK
+ - Audio sample rate: 11kHz(have to use 8k/24k for CS42L52)
+ - Default clock polarity: low level */
+ I2S_InitStructure.I2S_Mode = I2S_Mode_MasterTx;
+ I2S_InitStructure.I2S_Standard = I2S_Standard_MSB;
+ I2S_InitStructure.I2S_DataFormat = I2S_DataFormat_16b;
+ I2S_InitStructure.I2S_MCLKOutput = I2S_MCLKOutput_Enable;
+ I2S_InitStructure.I2S_AudioFreq = I2S_AudioFreq_8k;
+ I2S_InitStructure.I2S_CPOL = I2S_CPOL_Low;
+ I2S_Init(CODEC_I2S, &I2S_InitStructure);
+ /* configure Full Duplex */
+ I2S_FullDuplexConfig(I2S3ext, &I2S_InitStructure);
+ /* Disable the I2S3 TXE Interrupt */
+ SPI_I2S_ITConfig(CODEC_I2S, SPI_I2S_IT_TXE, DISABLE);
+ /* Enable the SPI3/I2S3 peripheral */
+ I2S_Cmd(CODEC_I2S, ENABLE);
+ I2S_Cmd(I2S3ext, ENABLE);
+}
+
+/**
+ * @brief Restores the IOs used by the Audio Codec interface to their default state.
+ * @param None
+ * @retval None
+ */
+static void Codec_GPIO_DeInit(void)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+
+ /* Deinitialize all the GPIOs used by the driver (EXCEPT the I2C IOs since
+ they are used by the IOExpander as well) */
+ GPIO_InitStructure.GPIO_Pin = CODEC_I2S_SCK_PIN | CODEC_I2S_DIN_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
+ GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
+ GPIO_Init(CODEC_I2S_GPIO, &GPIO_InitStructure);
+
+ GPIO_InitStructure.GPIO_Pin = CODEC_I2S_WS_PIN;
+ GPIO_Init(CODEC_I2S_MCK_WS_GPIO, &GPIO_InitStructure);
+
+#ifdef CODEC_MCLK_ENABLED
+ /* CODEC_I2S pins deinitialization: MCK pin */
+ GPIO_InitStructure.GPIO_Pin = CODEC_I2S_MCK_PIN;
+ GPIO_Init(CODEC_I2S_MCK_WS_GPIO, &GPIO_InitStructure);
+ /* Disconnect pins from I2S peripheral */
+ GPIO_PinAFConfig(CODEC_I2S_MCK_WS_GPIO, CODEC_I2S_MCK_PINSRC, 0x00);
+#endif /* CODEC_MCLK_ENABLED */
+
+ GPIO_InitStructure.GPIO_Pin = CODEC_I2S_DOUT_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
+ GPIO_Init(CODEC_I2S_GPIO, &GPIO_InitStructure);
+
+ /* Disconnect pins from I2S peripheral */
+ GPIO_PinAFConfig(CODEC_I2S_MCK_WS_GPIO, CODEC_I2S_WS_PINSRC, 0x00);
+ GPIO_PinAFConfig(CODEC_I2S_GPIO, CODEC_I2S_SCK_PINSRC, 0x00);
+ GPIO_PinAFConfig(CODEC_I2S_GPIO, CODEC_I2S_DIN_PINSRC, 0x00);
+ GPIO_PinAFConfig(CODEC_I2S_GPIO, CODEC_I2S_DOUT_PINSRC, 0x00);
+}
+
+/**
+ * @brief Inserts a delay time (not accurate timing).
+ * @param nCount: specifies the delay time length.
+ * @retval None
+ */
+void Delay( __IO uint32_t nCount)
+{
+ for (; nCount != 0; nCount--);
+}
+
+#ifdef USE_DEFAULT_TIMEOUT_CALLBACK
+/**
+ * @brief Basic management of the timeout situation.
+ * @param None
+ * @retval None
+ */
+uint32_t Codec_TIMEOUT_UserCallback(void)
+{
+ /* The following code allows I2C error recovery and return to normal communication
+ if the error source doesn’t still exist (ie. hardware issue..) */
+ I2C_InitTypeDef I2C_InitStructure;
+
+
+ /* LCD_ErrLog("> I2C Timeout error occurred\n"); */
+ I2C_GenerateSTOP(CODEC_I2C, ENABLE);
+ /* Generated a Software reset */
+ I2C_SoftwareResetCmd(CODEC_I2C);
+
+ /* CODEC_I2C configuration */
+ I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
+ I2C_InitStructure.I2C_AnalogFilter = I2C_AnalogFilter_Enable;
+ I2C_InitStructure.I2C_DigitalFilter = 0x00;
+ I2C_InitStructure.I2C_OwnAddress1 = 0x00;
+ I2C_InitStructure.I2C_Ack = I2C_Ack_Disable;
+ I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
+ I2C_InitStructure.I2C_Timing = CODEC_I2C_TIMING;
+
+ /* Enable the I2C peripheral */
+ I2C_Init(CODEC_I2C, &I2C_InitStructure);
+ I2C_Cmd(CODEC_I2C, ENABLE);
+
+ /* At this stage the I2C error should be recovered and device can communicate
+ again (except if the error source still exist).
+ User can implement mechanism (ex. test on max trial number) to manage situation
+ when the I2C can't recover from current error. */
+
+ /* LCD_UsrLog("> I2C error recovered.\n"); */
+
+ return 0;
+}
+#endif /* USE_DEFAULT_TIMEOUT_CALLBACK */
+
+/*============================================================================
+ Audio MAL Interface Control Functions
+ ============================================================================*/
+
+/**
+ * @brief Initializes and prepares the Media to perform audio data transfer
+ * from Media to the I2S peripheral.
+ * @param None
+ * @retval None
+ */
+static void Audio_MAL_Init(void)
+{
+#if defined(AUDIO_MAL_DMA_IT_TC_EN) || defined(AUDIO_MAL_DMA_IT_HT_EN) || defined(AUDIO_MAL_DMA_IT_TE_EN)
+ NVIC_InitTypeDef NVIC_InitStructure;
+#endif
+
+ /* Enable the DMA clock */
+ RCC_AHBPeriphClockCmd(AUDIO_MAL_DMA_CLOCK, ENABLE);
+
+ /* Configure the DMA Channel */
+ DMA_Cmd(AUDIO_MAL_DMA_CHANNEL, DISABLE);
+ DMA_DeInit(AUDIO_MAL_DMA_CHANNEL);
+ /* Set the parameters to be configured */
+
+ DMA_InitStructure.DMA_PeripheralBaseAddr = CODEC_I2S_ADDRESS;
+ DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)0; /* This field will be configured in play function */
+ DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
+ DMA_InitStructure.DMA_BufferSize = (uint32_t)0xFFFE; /* This field will be configured in play function */
+ DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
+ DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
+ DMA_InitStructure.DMA_PeripheralDataSize = AUDIO_MAL_DMA_PERIPH_DATA_SIZE;
+ DMA_InitStructure.DMA_MemoryDataSize = AUDIO_MAL_DMA_MEM_DATA_SIZE;
+#ifdef AUDIO_MAL_MODE_NORMAL
+ DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
+#elif defined(AUDIO_MAL_MODE_CIRCULAR)
+ DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
+#else
+ #error "AUDIO_MAL_MODE_NORMAL or AUDIO_MAL_MODE_CIRCULAR should be selected !!"
+#endif /* AUDIO_MAL_MODE_NORMAL */
+ DMA_Init(AUDIO_MAL_DMA_CHANNEL, &DMA_InitStructure);
+
+ /* Enable the selected DMA interrupts (selected in "stm32_eval_audio_codec.h" defines) */
+#ifdef AUDIO_MAL_DMA_IT_TC_EN
+ DMA_ITConfig(AUDIO_MAL_DMA_CHANNEL, DMA_IT_TC, ENABLE);
+#endif /* AUDIO_MAL_DMA_IT_TC_EN */
+#ifdef AUDIO_MAL_DMA_IT_HT_EN
+ DMA_ITConfig(AUDIO_MAL_DMA_CHANNEL, DMA_IT_HT, ENABLE);
+#endif /* AUDIO_MAL_DMA_IT_HT_EN */
+#ifdef AUDIO_MAL_DMA_IT_TE_EN
+ DMA_ITConfig(AUDIO_MAL_DMA_CHANNEL, DMA_IT_TE | DMA_IT_FE | DMA_IT_DME, ENABLE);
+#endif /* AUDIO_MAL_DMA_IT_TE_EN */
+
+ /* Enable the I2S DMA request */
+ SPI_I2S_DMACmd(CODEC_I2S, SPI_I2S_DMAReq_Tx, ENABLE);
+
+#if defined(AUDIO_MAL_DMA_IT_TC_EN) || defined(AUDIO_MAL_DMA_IT_HT_EN) || defined(AUDIO_MAL_DMA_IT_TE_EN)
+ /* I2S DMA IRQ Channel configuration */
+ NVIC_InitStructure.NVIC_IRQChannel = AUDIO_MAL_DMA_IRQ;
+ NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = EVAL_AUDIO_IRQ_PREPRIO;
+ NVIC_InitStructure.NVIC_IRQChannelSubPriority = EVAL_AUDIO_IRQ_SUBRIO;
+ NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
+ NVIC_Init(&NVIC_InitStructure);
+#endif
+}
+
+/**
+ * @brief Restore default state of the used Media.
+ * @param None
+ * @retval None
+ */
+static void Audio_MAL_DeInit(void)
+{
+#if defined(AUDIO_MAL_DMA_IT_TC_EN) || defined(AUDIO_MAL_DMA_IT_HT_EN) || defined(AUDIO_MAL_DMA_IT_TE_EN)
+ NVIC_InitTypeDef NVIC_InitStructure;
+
+ /* Deinitialize the NVIC interrupt for the I2S DMA Channel */
+ NVIC_InitStructure.NVIC_IRQChannel = AUDIO_MAL_DMA_IRQ;
+ NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = EVAL_AUDIO_IRQ_PREPRIO;
+ NVIC_InitStructure.NVIC_IRQChannelSubPriority = EVAL_AUDIO_IRQ_SUBRIO;
+ NVIC_InitStructure.NVIC_IRQChannelCmd = DISABLE;
+ NVIC_Init(&NVIC_InitStructure);
+#endif
+
+ /* Disable the DMA before the deinit */
+ DMA_Cmd(AUDIO_MAL_DMA_CHANNEL, DISABLE);
+
+ /* Dinitialize the DMA Channel */
+ DMA_DeInit(AUDIO_MAL_DMA_CHANNEL);
+
+ /* The DMA clock is not disabled */
+}
+
+/**
+ * @brief Starts playing audio stream from the audio Media.
+ * @param None
+ * @retval None
+ */
+void Audio_MAL_Play(uint32_t Addr, uint32_t Size)
+{
+ /* Configure the buffer address and size */
+ DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)Addr;
+ DMA_InitStructure.DMA_BufferSize = (uint32_t)Size/2;
+
+ /* Configure the DMA Channel with the new parameters */
+ DMA_Init(AUDIO_MAL_DMA_CHANNEL, &DMA_InitStructure);
+
+ /* Enable the I2S DMA Channel */
+ DMA_Cmd(AUDIO_MAL_DMA_CHANNEL, ENABLE);
+}
+
+/**
+ * @brief Pauses or Resumes the audio stream playing from the Media.
+ * @param Cmd: AUDIO_PAUSE (or 0) to pause, AUDIO_RESUME (or any value different
+ * from 0) to resume.
+ * @param Addr: Address from/at which the audio stream should resume/pause.
+ * @retval None
+ */
+static void Audio_MAL_PauseResume(uint32_t Cmd, uint32_t Addr)
+{
+ /* Pause the audio file playing */
+ if (Cmd == AUDIO_PAUSE)
+ {
+ /* Disable the I2S DMA request */
+ SPI_I2S_DMACmd(CODEC_I2S, SPI_I2S_DMAReq_Tx, DISABLE);
+
+ /* Pause the I2S DMA Channel
+ Note. For the STM32F30x devices, the DMA implements a pause feature,
+ by disabling the channel, all configuration is preserved and data
+ transfer is paused till the next enable of the channel.*/
+ DMA_Cmd(AUDIO_MAL_DMA_CHANNEL, DISABLE);
+ }
+ else /* AUDIO_RESUME */
+ {
+ /* Enable the I2S DMA request */
+ SPI_I2S_DMACmd(CODEC_I2S, SPI_I2S_DMAReq_Tx, ENABLE);
+
+ /* Resume the I2S DMA Channel
+ Note. For the STM32F30x devices, the DMA implements a pause feature,
+ by disabling the channel, all configuration is preserved and data
+ transfer is paused till the next enable of the channel.*/
+ DMA_Cmd(AUDIO_MAL_DMA_CHANNEL, ENABLE);
+
+ /* If the I2S peripheral is still not enabled, enable it */
+ if ((CODEC_I2S->I2SCFGR & I2S_ENABLE_MASK) == 0)
+ {
+ I2S_Cmd(CODEC_I2S, ENABLE);
+ }
+ }
+}
+
+/**
+ * @brief Stops audio stream playing on the used Media.
+ * @param None
+ * @retval None
+ */
+static void Audio_MAL_Stop(void)
+{
+ /* Stop the Transfer on the I2S side: Stop and disable the DMA channel */
+ DMA_Cmd(AUDIO_MAL_DMA_CHANNEL, DISABLE);
+
+ /* Clear all the DMA flags for the next transfer */
+ DMA_ClearFlag(AUDIO_MAL_DMA_FLAG_TC|AUDIO_MAL_DMA_FLAG_HT|AUDIO_MAL_DMA_FLAG_TE);
+
+ /* The I2S DMA requests are not disabled here. */
+
+ /* In all modes, disable the I2S peripheral */
+ I2S_Cmd(CODEC_I2S, DISABLE);
+}
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32303C_EVAL/stm32303c_eval_audio_codec.h b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32303C_EVAL/stm32303c_eval_audio_codec.h
new file mode 100644
index 0000000..0e0f44c
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32303C_EVAL/stm32303c_eval_audio_codec.h
@@ -0,0 +1,302 @@
+/**
+ ******************************************************************************
+ * @file stm32303c_eval_audio_codec.h
+ * @author MCD Application Team
+ * @version V1.0.1
+ * @date 23-October-2012
+ * @brief This file contains all the functions prototypes for the
+ * stm32303c_eval_audio_codec.c driver.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.st.com/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __STM32303C_EVAL_AUDIOCODEC_H
+#define __STM32303C_EVAL_AUDIOCODEC_H
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+/* Includes ------------------------------------------------------------------*/
+#include "stm32f30x.h"
+
+/** @addtogroup Utilities
+ * @{
+ */
+
+/** @addtogroup STM32_EVAL
+ * @{
+ */
+
+/** @addtogroup STM32303C_EVAL
+ * @{
+ */
+
+/** @addtogroup STM32303C_EVAL_AUDIO_CODEC
+ * @{
+ */
+
+
+/** @defgroup STM32303C_EVAL_AUDIO_CODEC_Exported_Types
+ * @{
+ */
+
+/**
+ * @}
+ */
+
+/** @defgroup STM32303C_EVAL_AUDIO_CODEC_Exported_Constants
+ * @{
+ */
+
+/*----------------------------------------------------------------------------
+ CONFIGURATION: Audio Codec Driver Configuration parameters
+ ----------------------------------------------------------------------------*/
+/* Audio Transfer mode (DMA, Interrupt or Polling) */
+#define AUDIO_MAL_MODE_NORMAL /* Uncomment this line to enable the audio
+ Transfer using DMA */
+/* #define AUDIO_MAL_MODE_CIRCULAR */ /* Uncomment this line to enable the audio
+ Transfer using DMA */
+
+/* For the DMA modes select the interrupt that will be used */
+#define AUDIO_MAL_DMA_IT_TC_EN /* Uncomment this line to enable DMA Transfer Complete interrupt */
+/* #define AUDIO_MAL_DMA_IT_HT_EN */ /* Uncomment this line to enable DMA Half Transfer Complete interrupt */
+/* #define AUDIO_MAL_DMA_IT_TE_EN */ /* Uncomment this line to enable DMA Transfer Error interrupt */
+
+/* Select the interrupt preemption priority and subpriority for the DMA interrupt */
+#define EVAL_AUDIO_IRQ_PREPRIO 0 /* Select the preemption priority level(0 is the highest) */
+#define EVAL_AUDIO_IRQ_SUBRIO 0 /* Select the sub-priority level (0 is the highest) */
+
+/* Uncomment the following line to use the default Codec_TIMEOUT_UserCallback()
+ function implemented in stm32303c_eval_audio_codec.c file.
+ Codec_TIMEOUT_UserCallback() function is called whenever a timeout condition
+ occurs during communication (waiting on an event that doesn't occur, bus
+ errors, busy devices ...). */
+/* #define USE_DEFAULT_TIMEOUT_CALLBACK */
+/*----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+ OPTIONAL Configuration defines parameters
+ ----------------------------------------------------------------------------*/
+/* I2C clock speed configuration (in Hz)
+ WARNING:
+ Make sure that this define is not already declared in other files (ie.
+ stm32303c_eval.h file). It can be used in parallel by other modules. */
+
+/* I2C TIMING Register define when I2C clock source is SYSCLK */
+/* set TIMING to 0xC062121F to reach 100 KHz speed (Rise time = 640ns, Fall time = 20ns) */
+
+#define CODEC_I2C_TIMING 0xC062121F
+
+/* Uncomment defines below to select standard for audio communication between
+ Codec and I2S peripheral */
+#define I2S_STANDARD_PHILLIPS
+/* #define I2S_STANDARD_MSB */
+/* #define I2S_STANDARD_LSB */
+
+/* Uncomment the defines below to select if the Master clock mode should be
+ enabled or not */
+#define CODEC_MCLK_ENABLED
+/* #define CODEC_MCLK_DISABLED */
+
+/* Uncomment this line to enable verifying data sent to codec after each write
+ operation */
+#define VERIFY_WRITTENDATA
+/*----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+ Hardware Configuration defines parameters
+ ----------------------------------------------------------------------------*/
+/* Audio Reset Pin definition */
+#define AUDIO_RESET_GPIO_CLK RCC_AHBPeriph_GPIOD
+#define AUDIO_RESET_PIN GPIO_Pin_11
+#define AUDIO_RESET_GPIO GPIOD
+
+/* I2S peripheral configuration defines */
+#define CODEC_I2S SPI3
+#define CODEC_I2S_CLK RCC_APB1Periph_SPI3
+#define CODEC_I2S_ADDRESS 0x40003C0C
+#define CODEC_I2S_GPIO_AF GPIO_AF_6
+#define CODEC_I2S_MCK_GPIO_AF GPIO_AF_5
+#define CODEC_I2S_IRQ SPI3_IRQn
+#define CODEC_I2S_GPIO_CLOCK (RCC_AHBPeriph_GPIOA)|(RCC_AHBPeriph_GPIOC)
+#define CODEC_I2S_WS_PIN GPIO_Pin_4
+#define CODEC_I2S_SCK_PIN GPIO_Pin_10
+#define CODEC_I2S_DOUT_PIN GPIO_Pin_11
+#define CODEC_I2S_DIN_PIN GPIO_Pin_12
+#define CODEC_I2S_MCK_PIN GPIO_Pin_9
+#define CODEC_I2S_WS_PINSRC GPIO_PinSource4
+#define CODEC_I2S_SCK_PINSRC GPIO_PinSource10
+#define CODEC_I2S_DOUT_PINSRC GPIO_PinSource11
+#define CODEC_I2S_DIN_PINSRC GPIO_PinSource12
+#define CODEC_I2S_MCK_PINSRC GPIO_PinSource9
+#define CODEC_I2S_GPIO GPIOC
+#define CODEC_I2S_MCK_WS_GPIO GPIOA
+#define Audio_I2S_IRQHandler SPI3_IRQHandler
+
+ /* I2S DMA Channel definitions */
+#define AUDIO_MAL_DMA_CLOCK RCC_AHBPeriph_DMA2
+#define AUDIO_MAL_DMA_CHANNEL DMA2_Channel2
+#define AUDIO_MAL_DMA_IRQ DMA2_Channel2_IRQn
+#define AUDIO_MAL_DMA_FLAG_TC DMA2_FLAG_TC2
+#define AUDIO_MAL_DMA_FLAG_HT DMA2_FLAG_HT2
+#define AUDIO_MAL_DMA_FLAG_TE DMA2_FLAG_TE2
+
+#define Audio_MAL_IRQHandler DMA2_Channel2_IRQHandler
+#define AUDIO_MAL_DMA_PERIPH_DATA_SIZE DMA_PeripheralDataSize_HalfWord
+#define AUDIO_MAL_DMA_MEM_DATA_SIZE DMA_MemoryDataSize_HalfWord
+#define DMA_MAX_SZE 0xFFFF
+
+/* I2C peripheral configuration defines (control interface of the audio codec) */
+#define CODEC_I2C I2C2
+#define CODEC_I2C_CLK RCC_APB1Periph_I2C2
+#define CODEC_I2C_GPIO_CLOCK (RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOF)
+#define CODEC_I2C_GPIO_AF GPIO_AF_4
+#define CODEC_I2C_SCL_GPIO GPIOF
+#define CODEC_I2C_SDA_GPIO GPIOA
+#define CODEC_I2C_SCL_PIN GPIO_Pin_6
+#define CODEC_I2C_SDA_PIN GPIO_Pin_10
+#define CODEC_I2S_SCL_PINSRC GPIO_PinSource6
+#define CODEC_I2S_SDA_PINSRC GPIO_PinSource10
+
+/* Maximum Timeout values for flags and events waiting loops. These timeouts are
+ not based on accurate values, they just guarantee that the application will
+ not remain stuck if the I2C communication is corrupted.
+ You may modify these timeout values depending on CPU frequency and application
+ conditions (interrupts routines ...). */
+#define CODEC_FLAG_TIMEOUT ((uint32_t)0x1000)
+#define CODEC_LONG_TIMEOUT ((uint32_t)(300 * CODEC_FLAG_TIMEOUT))
+/*----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+ Audio Codec User defines
+ ----------------------------------------------------------------------------*/
+/* Codec output DEVICE */
+#define OUTPUT_DEVICE_SPEAKER 1
+#define OUTPUT_DEVICE_HEADPHONE 2
+#define OUTPUT_DEVICE_BOTH 3
+#define OUTPUT_DEVICE_AUTO 4
+
+/* Volume Levels values */
+#define DEFAULT_VOLMIN 0x00
+#define DEFAULT_VOLMAX 0xFF
+#define DEFAULT_VOLSTEP 0x04
+
+#define AUDIO_PAUSE 0
+#define AUDIO_RESUME 1
+
+/* Codec POWER DOWN modes */
+#define CODEC_PDWN_HW 1
+#define CODEC_PDWN_SW 2
+
+/* MUTE commands */
+#define AUDIO_MUTE_ON 1
+#define AUDIO_MUTE_OFF 0
+/*----------------------------------------------------------------------------*/
+/**
+ * @}
+ */
+
+/** @defgroup STM32303C_EVAL_AUDIO_CODEC_Exported_Macros
+ * @{
+ */
+#define VOLUME_CONVERT(x) ((Volume > 100)? 100:((uint8_t)((Volume * 255) / 100)))
+#define DMA_MAX(x) (((x) <= DMA_MAX_SZE)? (x):DMA_MAX_SZE)
+
+/**
+ * @}
+ */
+
+/** @defgroup STM32303C_EVAL_AUDIO_CODEC_Exported_Functions
+ * @{
+ */
+uint32_t EVAL_AUDIO_Init(uint16_t OutputDevice, uint8_t Volume, uint32_t AudioFreq);
+uint32_t EVAL_AUDIO_DeInit(void);
+uint32_t EVAL_AUDIO_Play(uint16_t* pBuffer, uint32_t Size);
+uint32_t EVAL_AUDIO_PauseResume(uint32_t Cmd);
+uint32_t EVAL_AUDIO_Stop(uint32_t CodecPowerDown_Mode);
+uint32_t EVAL_AUDIO_VolumeCtl(uint8_t Volume);
+uint32_t EVAL_AUDIO_Mute(uint32_t Command);
+
+uint32_t Codec_SwitchOutput(uint8_t Output);
+uint32_t Codec_Record_Init(void);
+uint32_t Codec_ReadRegister(uint8_t RegisterAddr);
+
+uint32_t Codec_WriteRegister(uint8_t RegisterAddr, uint8_t RegisterValue);
+
+
+
+/* User Callbacks: user has to implement these functions in his code if
+ they are needed. -----------------------------------------------------------*/
+
+/* This function is called when the requested data has been completely transferred.
+ In Normal mode (when the define AUDIO_MAL_MODE_NORMAL is enabled) this function
+ is called at the end of the whole audio file.
+ In circular mode (when the define AUDIO_MAL_MODE_CIRCULAR is enabled) this
+ function is called at the end of the current buffer transmission. */
+void EVAL_AUDIO_TransferComplete_CallBack(uint32_t pBuffer, uint32_t Size);
+
+/* This function is called when half of the requested buffer has been transferred
+ This callback is useful in Circular mode only (when AUDIO_MAL_MODE_CIRCULAR
+ define is enabled)*/
+void EVAL_AUDIO_HalfTransfer_CallBack(uint32_t pBuffer, uint32_t Size);
+
+/* This function is called when an Interrupt due to transfer error on or peripheral
+ error occurs. */
+void EVAL_AUDIO_Error_CallBack(void* pData);
+
+/* Codec_TIMEOUT_UserCallback() function is called whenever a timeout condition
+ occurs during communication (waiting on an event that doesn't occur, bus
+ errors, busy devices ...) on the Codec control interface (I2C).
+ You can use the default timeout callback implementation by uncommenting the
+ define USE_DEFAULT_TIMEOUT_CALLBACK in stm32303c_eval_audio_codec.h file.
+ Typically the user implementation of this callback should reset I2C peripheral
+ and re-initialize communication or in worst case reset all the application. */
+uint32_t Codec_TIMEOUT_UserCallback(void);
+void Audio_MAL_IRQHandler(void);
+void Audio_MAL_Play(uint32_t Addr, uint32_t Size);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __STM32303C_EVAL_AUDIOCODEC_H */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/******************* (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32303C_EVAL/stm32303c_eval_i2c_ee.c b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32303C_EVAL/stm32303c_eval_i2c_ee.c
new file mode 100644
index 0000000..fe89465
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32303C_EVAL/stm32303c_eval_i2c_ee.c
@@ -0,0 +1,717 @@
+/**
+ ******************************************************************************
+ * @file stm32303c_eval_i2c_ee.c
+ * @author MCD Application Team
+ * @version V1.0.1
+ * @date 23-October-2012
+ * @brief This file provides a set of functions needed to manage an I2C M24LR64
+ * and M24M01 EEPROM memory.
+ *
+ * It implements a high level communication layer for read and write
+ * from/to this memory. The needed STM32F30x hardware resources (I2C and
+ * GPIO) are defined in stm32303c_eval.h file, and the initialization is
+ * performed in sEE_LowLevel_Init() function declared in stm32303c_eval.c
+ * file.
+ * You can easily tailor this driver to any other development board,
+ * by just adapting the defines for hardware resources and
+ * sEE_LowLevel_Init() function.
+ *
+ * @note In this driver, basic read and write functions (sEE_ReadBuffer()
+ * and sEE_WritePage()) use Polling mode to perform the data transfer
+ * to/from EEPROM memory.
+ *
+ * +-----------------------------------------------------------------+
+ * | Pin assignment for M24M01 EEPROM |
+ * +---------------------------------------+-----------+-------------+
+ * | STM32F30x I2C Pins | sEE | Pin |
+ * +---------------------------------------+-----------+-------------+
+ * | . | NC | 1 |
+ * | . | E1(VDD) | 2 (3.3V) |
+ * | . | E2(GND) | 3 (0V) |
+ * | . | VSS | 4 (0V) |
+ * | sEE_I2C_SDA_PIN/ SDA | SDA | 5 |
+ * | sEE_I2C_SCL_PIN/ SCL | SCL | 6 |
+ * | . | /WC(VSS)| 7 (0V) |
+ * | . | VDD | 8 (3.3V) |
+ * +---------------------------------------+-----------+-------------+
+ * +-----------------------------------------------------------------+
+ * | Pin assignment for M24LR64 EEPROM |
+ * +---------------------------------------+-----------+-------------+
+ * | STM32F30x I2C Pins | sEE | Pin |
+ * +---------------------------------------+-----------+-------------+
+ * | . | E0(GND) | 1 (0V) |
+ * | . | AC0 | 2 |
+ * | . | AC1 | 3 |
+ * | . | VSS | 4 (0V) |
+ * | sEE_I2C_SDA_PIN/ SDA | SDA | 5 |
+ * | sEE_I2C_SCL_PIN/ SCL | SCL | 6 |
+ * | . | E1(GND) | 7 (0V) |
+ * | . | VDD | 8 (3.3V) |
+ * +---------------------------------------+-----------+-------------+ *
+ *
+ * * *
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.st.com/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+
+/* Includes ------------------------------------------------------------------*/
+#include "stm32303c_eval_i2c_ee.h"
+
+/** @addtogroup Utilities
+ * @{
+ */
+
+/** @addtogroup STM32_EVAL
+ * @{
+ */
+
+/** @addtogroup STM32303C_EVAL
+ * @{
+ */
+
+/** @addtogroup STM32303C_EVAL_I2C_EE
+ * @brief This file includes the I2C EEPROM driver of STM32303C-EVAL board.
+ * @{
+ */
+
+/** @defgroup STM32303C_EVAL_I2C_EE_Private_Types
+ * @{
+ */
+/**
+ * @}
+ */
+
+
+/** @defgroup STM32303C_EVAL_I2C_EE_Private_Defines
+ * @{
+ */
+/**
+ * @}
+ */
+
+
+/** @defgroup STM32303C_EVAL_I2C_EE_Private_Macros
+ * @{
+ */
+/**
+ * @}
+ */
+
+
+/** @defgroup STM32303C_EVAL_I2C_EE_Private_Variables
+ * @{
+ */
+__IO uint16_t sEEAddress = 0;
+__IO uint32_t sEETimeout = sEE_LONG_TIMEOUT;
+__IO uint16_t sEEDataNum;
+/**
+ * @}
+ */
+
+
+/** @defgroup STM32303C_EVAL_I2C_EE_Private_Function_Prototypes
+ * @{
+ */
+/**
+ * @}
+ */
+
+
+/** @defgroup STM32303C_EVAL_I2C_EE_Private_Functions
+ * @{
+ */
+
+/**
+ * @brief DeInitializes peripherals used by the I2C EEPROM driver.
+ * @param None
+ * @retval None
+ */
+void sEE_DeInit(void)
+{
+ sEE_I2C_LowLevel_DeInit();
+}
+
+/**
+ * @brief Initializes peripherals used by the I2C EEPROM driver.
+ * @param None
+ * @retval None
+ */
+void sEE_Init(void)
+{
+ I2C_InitTypeDef I2C_InitStructure;
+
+ sEE_I2C_LowLevel_Init();
+
+ /*!< I2C configuration */
+ /* sEE_I2C configuration */
+ I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
+ I2C_InitStructure.I2C_AnalogFilter = I2C_AnalogFilter_Enable;
+ I2C_InitStructure.I2C_DigitalFilter = 0x00;
+ I2C_InitStructure.I2C_OwnAddress1 = 0x00;
+ I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
+ I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
+ I2C_InitStructure.I2C_Timing = sEE_I2C_TIMING;
+
+ /* Apply sEE_I2C configuration after enabling it */
+ I2C_Init(sEE_I2C, &I2C_InitStructure);
+
+ /* sEE_I2C Peripheral Enable */
+ I2C_Cmd(sEE_I2C, ENABLE);
+
+ /*!< Select the EEPROM address */
+ sEEAddress = sEE_HW_ADDRESS;
+}
+
+/**
+ * @brief Reads a block of data from the EEPROM.
+ * @param pBuffer : pointer to the buffer that receives the data read from
+ * the EEPROM.
+ * @param ReadAddr : EEPROM's internal address to start reading from.
+ * @param NumByteToRead : pointer to the variable holding number of bytes to
+ * be read from the EEPROM.
+ *
+ * @retval sEE_OK (0) if operation is correctly performed, else return value
+ * different from sEE_OK (0) or the timeout user callback.
+ */
+uint32_t sEE_ReadBuffer(uint8_t* pBuffer, uint16_t ReadAddr, uint16_t* NumByteToRead)
+{
+ uint32_t NumbOfSingle = 0, Count = 0, DataNum = 0, StartCom = 0;
+
+ /* Get number of reload cycles */
+ Count = (*NumByteToRead) / 255;
+ NumbOfSingle = (*NumByteToRead) % 255;
+
+#ifdef sEE_M24C08
+
+ /* Configure slave address, nbytes, reload and generate start */
+ I2C_TransferHandling(sEE_I2C, sEEAddress, 1, I2C_SoftEnd_Mode, I2C_Generate_Start_Write);
+
+ /* Wait until TXIS flag is set */
+ sEETimeout = sEE_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(sEE_I2C, I2C_ISR_TXIS) == RESET)
+ {
+ if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback();
+ }
+
+ /* Send memory address */
+ I2C_SendData(sEE_I2C, (uint8_t)ReadAddr);
+
+#elif defined(sEE_M24M01) || defined(sEE_M24C64_32) || defined (sEE_M24LR64)
+
+ /* Configure slave address, nbytes, reload and generate start */
+ I2C_TransferHandling(sEE_I2C, sEEAddress, 2, I2C_SoftEnd_Mode, I2C_Generate_Start_Write);
+
+ /* Wait until TXIS flag is set */
+ sEETimeout = sEE_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(sEE_I2C, I2C_ISR_TXIS) == RESET)
+ {
+ if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback();
+ }
+
+ /* Send MSB of memory address */
+ I2C_SendData(sEE_I2C, (uint8_t)((ReadAddr & 0xFF00) >> 8));
+
+ /* Wait until TXIS flag is set */
+ sEETimeout = sEE_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(sEE_I2C, I2C_ISR_TXIS) == RESET)
+ {
+ if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback();
+ }
+
+ /* Send LSB of memory address */
+ I2C_SendData(sEE_I2C, (uint8_t)(ReadAddr & 0x00FF));
+
+#endif /*!< sEE_M24C08 */
+
+ /* Wait until TC flag is set */
+ sEETimeout = sEE_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(sEE_I2C, I2C_ISR_TC) == RESET)
+ {
+ if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback();
+ }
+
+ /* If number of Reload cycles is not equal to 0 */
+ if (Count != 0)
+ {
+ /* Starting communication */
+ StartCom = 1;
+
+ /* Wait until all reload cycles are performed */
+ while( Count != 0)
+ {
+ /* If a read transfer is performed */
+ if (StartCom == 0)
+ {
+ /* Wait until TCR flag is set */
+ sEETimeout = sEE_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(sEE_I2C, I2C_ISR_TCR) == RESET)
+ {
+ if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback();
+ }
+ }
+
+ /* if remains one read cycle */
+ if ((Count == 1) && (NumbOfSingle == 0))
+ {
+ /* if starting communication */
+ if (StartCom != 0)
+ {
+ /* Configure slave address, end mode and start condition */
+ I2C_TransferHandling(sEE_I2C, sEEAddress, 255, I2C_AutoEnd_Mode, I2C_Generate_Start_Read);
+ }
+ else
+ {
+ /* Configure slave address, end mode */
+ I2C_TransferHandling(sEE_I2C, sEEAddress, 255, I2C_AutoEnd_Mode, I2C_No_StartStop);
+ }
+ }
+ else
+ {
+ /* if starting communication */
+ if (StartCom != 0)
+ {
+ /* Configure slave address, end mode and start condition */
+ I2C_TransferHandling(sEE_I2C, sEEAddress, 255, I2C_Reload_Mode, I2C_Generate_Start_Read);
+ }
+ else
+ {
+ /* Configure slave address, end mode */
+ I2C_TransferHandling(sEE_I2C, sEEAddress, 255, I2C_Reload_Mode, I2C_No_StartStop);
+ }
+ }
+
+ /* Update local variable */
+ StartCom = 0;
+ DataNum = 0;
+
+ /* Wait until all data are received */
+ while (DataNum != 255)
+ {
+ /* Wait until RXNE flag is set */
+ sEETimeout = sEE_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(sEE_I2C, I2C_ISR_RXNE) == RESET)
+ {
+ if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback();
+ }
+
+ /* Read data from RXDR */
+ pBuffer[DataNum]= I2C_ReceiveData(sEE_I2C);
+
+ /* Update number of received data */
+ DataNum++;
+ (*NumByteToRead)--;
+ }
+ /* Update Pointer of received buffer */
+ pBuffer += DataNum;
+
+ /* update number of reload cycle */
+ Count--;
+ }
+
+ /* If number of single data is not equal to 0 */
+ if (NumbOfSingle != 0)
+ {
+ /* Wait until TCR flag is set */
+ sEETimeout = sEE_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(sEE_I2C, I2C_ISR_TCR) == RESET)
+ {
+ if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback();
+ }
+
+ /* Update CR2 : set Nbytes and end mode */
+ I2C_TransferHandling(sEE_I2C, sEEAddress, (uint8_t)(NumbOfSingle), I2C_AutoEnd_Mode, I2C_No_StartStop);
+
+ /* Reset local variable */
+ DataNum = 0;
+
+ /* Wait until all data are received */
+ while (DataNum != NumbOfSingle)
+ {
+ /* Wait until RXNE flag is set */
+ sEETimeout = sEE_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(sEE_I2C, I2C_ISR_RXNE) == RESET)
+ {
+ if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback();
+ }
+
+ /* Read data from RXDR */
+ pBuffer[DataNum]= I2C_ReceiveData(sEE_I2C);
+
+ /* Update number of received data */
+ DataNum++;
+ (*NumByteToRead)--;
+ }
+ }
+ }
+ else
+ {
+ /* Update CR2 : set Slave Address , set read request, generate Start and set end mode */
+ I2C_TransferHandling(sEE_I2C, sEEAddress, (uint32_t)(NumbOfSingle), I2C_AutoEnd_Mode, I2C_Generate_Start_Read);
+
+ /* Reset local variable */
+ DataNum = 0;
+
+ /* Wait until all data are received */
+ while (DataNum != NumbOfSingle)
+ {
+ /* Wait until RXNE flag is set */
+ sEETimeout = sEE_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(sEE_I2C, I2C_ISR_RXNE) == RESET)
+ {
+ if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback();
+ }
+
+ /* Read data from RXDR */
+ pBuffer[DataNum]= I2C_ReceiveData(sEE_I2C);
+
+ /* Update number of received data */
+ DataNum++;
+ (*NumByteToRead)--;
+ }
+ }
+
+ /* Wait until STOPF flag is set */
+ sEETimeout = sEE_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(sEE_I2C, I2C_ISR_STOPF) == RESET)
+ {
+ if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback();
+ }
+
+ /* Clear STOPF flag */
+ I2C_ClearFlag(sEE_I2C, I2C_ICR_STOPCF);
+
+ /* If all operations OK, return sEE_OK (0) */
+ return sEE_OK;
+}
+
+/**
+ * @brief Writes more than one byte to the EEPROM with a single WRITE cycle.
+ *
+ * @note The number of bytes (combined to write start address) must not
+ * cross the EEPROM page boundary. This function can only write into
+ * the boundaries of an EEPROM page.
+ * This function doesn't check on boundaries condition (in this driver
+ * the function sEE_WriteBuffer() which calls sEE_WritePage() is
+ * responsible of checking on Page boundaries).
+ *
+ * @param pBuffer : pointer to the buffer containing the data to be written to
+ * the EEPROM.
+ * @param WriteAddr : EEPROM's internal address to write to.
+ * @param NumByteToWrite : pointer to the variable holding number of bytes to
+ * be written into the EEPROM.
+ *
+ * @retval sEE_OK (0) if operation is correctly performed, else return value
+ * different from sEE_OK (0) or the timeout user callback.
+ */
+uint32_t sEE_WritePage(uint8_t* pBuffer, uint16_t WriteAddr, uint8_t* NumByteToWrite)
+{
+ uint32_t DataNum = 0;
+
+#ifdef sEE_M24C08
+
+ /* Configure slave address, nbytes, reload and generate start */
+ I2C_TransferHandling(sEE_I2C, sEEAddress, 1, I2C_Reload_Mode, I2C_Generate_Start_Write);
+
+ /* Wait until TXIS flag is set */
+ sEETimeout = sEE_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(sEE_I2C, I2C_ISR_TXIS) == RESET)
+ {
+ if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback();
+ }
+
+ /* Send memory address */
+ I2C_SendData(sEE_I2C, (uint8_t)WriteAddr);
+
+#elif defined(sEE_M24M01) || defined(sEE_M24C64_32) || defined (sEE_M24LR64)
+
+ /* Configure slave address, nbytes, reload and generate start */
+ I2C_TransferHandling(sEE_I2C, sEEAddress, 2, I2C_Reload_Mode, I2C_Generate_Start_Write);
+
+ /* Wait until TXIS flag is set */
+ sEETimeout = sEE_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(sEE_I2C, I2C_ISR_TXIS) == RESET)
+ {
+ if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback();
+ }
+
+ /* Send MSB of memory address */
+ I2C_SendData(sEE_I2C, (uint8_t)((WriteAddr & 0xFF00) >> 8));
+
+ /* Wait until TXIS flag is set */
+ sEETimeout = sEE_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(sEE_I2C, I2C_ISR_TXIS) == RESET)
+ {
+ if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback();
+ }
+
+ /* Send LSB of memory address */
+ I2C_SendData(sEE_I2C, (uint8_t)(WriteAddr & 0x00FF));
+
+#endif /*!< sEE_M24C08 */
+
+ /* Wait until TCR flag is set */
+ sEETimeout = sEE_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(sEE_I2C, I2C_ISR_TCR) == RESET)
+ {
+ if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback();
+ }
+
+ /* Update CR2 : set Slave Address , set write request, generate Start and set end mode */
+ I2C_TransferHandling(sEE_I2C, sEEAddress, (uint8_t)(*NumByteToWrite), I2C_AutoEnd_Mode, I2C_No_StartStop);
+
+ while (DataNum != (*NumByteToWrite))
+ {
+ /* Wait until TXIS flag is set */
+ sEETimeout = sEE_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(sEE_I2C, I2C_ISR_TXIS) == RESET)
+ {
+ if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback();
+ }
+
+ /* Write data to TXDR */
+ I2C_SendData(sEE_I2C, (uint8_t)(pBuffer[DataNum]));
+
+ /* Update number of transmitted data */
+ DataNum++;
+ }
+
+ /* Wait until STOPF flag is set */
+ sEETimeout = sEE_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(sEE_I2C, I2C_ISR_STOPF) == RESET)
+ {
+ if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback();
+ }
+
+ /* Clear STOPF flag */
+ I2C_ClearFlag(sEE_I2C, I2C_ICR_STOPCF);
+
+ /* If all operations OK, return sEE_OK (0) */
+ return sEE_OK;
+}
+
+/**
+ * @brief Writes buffer of data to the I2C EEPROM.
+ * @param pBuffer : pointer to the buffer containing the data to be written
+ * to the EEPROM.
+ * @param WriteAddr : EEPROM's internal address to write to.
+ * @param NumByteToWrite : number of bytes to write to the EEPROM.
+ * @retval None
+ */
+void sEE_WriteBuffer(uint8_t* pBuffer, uint16_t WriteAddr, uint16_t NumByteToWrite)
+{
+ uint16_t NumOfPage = 0, NumOfSingle = 0, count = 0;
+ uint16_t Addr = 0;
+
+ Addr = WriteAddr % sEE_PAGESIZE;
+ count = sEE_PAGESIZE - Addr;
+ NumOfPage = NumByteToWrite / sEE_PAGESIZE;
+ NumOfSingle = NumByteToWrite % sEE_PAGESIZE;
+
+ /*!< If WriteAddr is sEE_PAGESIZE aligned */
+ if(Addr == 0)
+ {
+ /*!< If NumByteToWrite < sEE_PAGESIZE */
+ if(NumOfPage == 0)
+ {
+ /* Store the number of data to be written */
+ sEEDataNum = NumOfSingle;
+ /* Start writing data */
+ sEE_WritePage(pBuffer, WriteAddr, (uint8_t*)(&sEEDataNum));
+ sEE_WaitEepromStandbyState();
+ }
+ /*!< If NumByteToWrite > sEE_PAGESIZE */
+ else
+ {
+ while(NumOfPage--)
+ {
+ /* Store the number of data to be written */
+ sEEDataNum = sEE_PAGESIZE;
+ sEE_WritePage(pBuffer, WriteAddr, (uint8_t*)(&sEEDataNum));
+ sEE_WaitEepromStandbyState();
+ WriteAddr += sEE_PAGESIZE;
+ pBuffer += sEE_PAGESIZE;
+ }
+
+ if(NumOfSingle!=0)
+ {
+ /* Store the number of data to be written */
+ sEEDataNum = NumOfSingle;
+ sEE_WritePage(pBuffer, WriteAddr, (uint8_t*)(&sEEDataNum));
+ sEE_WaitEepromStandbyState();
+ }
+ }
+ }
+ /*!< If WriteAddr is not sEE_PAGESIZE aligned */
+ else
+ {
+ /*!< If NumByteToWrite < sEE_PAGESIZE */
+ if(NumOfPage== 0)
+ {
+ /*!< If the number of data to be written is more than the remaining space
+ in the current page: */
+ if (NumByteToWrite > count)
+ {
+ /* Store the number of data to be written */
+ sEEDataNum = count;
+ /*!< Write the data contained in same page */
+ sEE_WritePage(pBuffer, WriteAddr, (uint8_t*)(&sEEDataNum));
+ sEE_WaitEepromStandbyState();
+
+ /* Store the number of data to be written */
+ sEEDataNum = (NumByteToWrite - count);
+ /*!< Write the remaining data in the following page */
+ sEE_WritePage((uint8_t*)(pBuffer + count), (WriteAddr + count), (uint8_t*)(&sEEDataNum));
+ sEE_WaitEepromStandbyState();
+ }
+ else
+ {
+ /* Store the number of data to be written */
+ sEEDataNum = NumOfSingle;
+ sEE_WritePage(pBuffer, WriteAddr, (uint8_t*)(&sEEDataNum));
+ sEE_WaitEepromStandbyState();
+ }
+ }
+ /*!< If NumByteToWrite > sEE_PAGESIZE */
+ else
+ {
+ NumByteToWrite -= count;
+ NumOfPage = NumByteToWrite / sEE_PAGESIZE;
+ NumOfSingle = NumByteToWrite % sEE_PAGESIZE;
+
+ if(count != 0)
+ {
+ /* Store the number of data to be written */
+ sEEDataNum = count;
+ sEE_WritePage(pBuffer, WriteAddr, (uint8_t*)(&sEEDataNum));
+ sEE_WaitEepromStandbyState();
+ WriteAddr += count;
+ pBuffer += count;
+ }
+
+ while(NumOfPage--)
+ {
+ /* Store the number of data to be written */
+ sEEDataNum = sEE_PAGESIZE;
+ sEE_WritePage(pBuffer, WriteAddr, (uint8_t*)(&sEEDataNum));
+ sEETimeout = sEE_LONG_TIMEOUT;
+ sEE_WaitEepromStandbyState();
+ WriteAddr += sEE_PAGESIZE;
+ pBuffer += sEE_PAGESIZE;
+ }
+ if(NumOfSingle != 0)
+ {
+ /* Store the number of data to be written */
+ sEEDataNum = NumOfSingle;
+ sEE_WritePage(pBuffer, WriteAddr, (uint8_t*)(&sEEDataNum));
+ sEE_WaitEepromStandbyState();
+ }
+ }
+ }
+}
+
+/**
+ * @brief Wait for EEPROM Standby state.
+ *
+ * @note This function allows to wait and check that EEPROM has finished the
+ * last operation. It is mostly used after Write operation: after receiving
+ * the buffer to be written, the EEPROM may need additional time to actually
+ * perform the write operation. During this time, it doesn't answer to
+ * I2C packets addressed to it. Once the write operation is complete
+ * the EEPROM responds to its address.
+ *
+ * @param None
+ *
+ * @retval sEE_OK (0) if operation is correctly performed, else return value
+ * different from sEE_OK (0) or the timeout user callback.
+ */
+uint32_t sEE_WaitEepromStandbyState(void)
+{
+ __IO uint32_t sEETrials = 0;
+
+ /* Keep looping till the slave acknowledge his address or maximum number
+ of trials is reached (this number is defined by sEE_MAX_TRIALS_NUMBER define
+ in stm32303c_eval_i2c_ee.h file) */
+
+ /* Configure CR2 register : set Slave Address and end mode */
+ I2C_TransferHandling(sEE_I2C, sEEAddress, 0, I2C_AutoEnd_Mode, I2C_No_StartStop);
+
+ do
+ {
+ /* Initialize sEETimeout */
+ sEETimeout = sEE_FLAG_TIMEOUT;
+
+ /* Clear NACKF */
+ I2C_ClearFlag(sEE_I2C, I2C_ICR_NACKCF | I2C_ICR_STOPCF);
+
+ /* Generate start */
+ I2C_GenerateSTART(sEE_I2C, ENABLE);
+
+ /* Wait until timeout elapsed */
+ while (sEETimeout-- != 0);
+
+ /* Check if the maximum allowed numbe of trials has bee reached */
+ if (sEETrials++ == sEE_MAX_TRIALS_NUMBER)
+ {
+ /* If the maximum number of trials has been reached, exit the function */
+ return sEE_TIMEOUT_UserCallback();
+ }
+ }
+ while(I2C_GetFlagStatus(sEE_I2C, I2C_ISR_NACKF) != RESET);
+
+ /* Clear STOPF */
+ I2C_ClearFlag(sEE_I2C, I2C_ICR_STOPCF);
+
+ /* Return sEE_OK if device is ready */
+ return sEE_OK;
+}
+
+#ifdef USE_DEFAULT_TIMEOUT_CALLBACK
+/**
+ * @brief Basic management of the timeout situation.
+ * @param None.
+ * @retval None.
+ */
+uint32_t sEE_TIMEOUT_UserCallback(void)
+{
+ return 0;
+}
+#endif /* USE_DEFAULT_TIMEOUT_CALLBACK */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
+
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32303C_EVAL/stm32303c_eval_i2c_ee.h b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32303C_EVAL/stm32303c_eval_i2c_ee.h
new file mode 100644
index 0000000..00a799a
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32303C_EVAL/stm32303c_eval_i2c_ee.h
@@ -0,0 +1,206 @@
+/**
+ ******************************************************************************
+ * @file stm32303c_eval_i2c_ee.h
+ * @author MCD Application Team
+ * @version V1.0.1
+ * @date 23-October-2012
+ * @brief This file contains all the functions prototypes for
+ * the stm32303c_eval_i2c_ee.c firmware driver.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.st.com/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __STM32303C_EVAL_I2C_EE_H
+#define __STM32303C_EVAL_I2C_EE_H
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+/* Includes ------------------------------------------------------------------*/
+#include "stm32303c_eval.h"
+
+/** @addtogroup Utilities
+ * @{
+ */
+
+/** @addtogroup STM32_EVAL
+ * @{
+ */
+
+/** @addtogroup STM32303C_EVAL
+ * @{
+ */
+
+/** @addtogroup STM32303C_EVAL_I2C_EE
+ * @{
+ */
+
+/** @defgroup STM32303C_EVAL_I2C_EE_Exported_Types
+ * @{
+ */
+
+/**
+ * @}
+ */
+
+/** @defgroup STM32303C_EVAL_I2C_EE_Exported_Constants
+ * @{
+ */
+
+/* Select which EEPROM will be used with this driver */
+#define sEE_M24LR64
+/* #define sEE_M24M01 */
+
+/* Uncomment the following line to use the default sEE_TIMEOUT_UserCallback()
+ function implemented in stm32303c_eval_i2c_ee.c file.
+ sEE_TIMEOUT_UserCallback() function is called whenever a timeout condition
+ occure during communication (waiting on an event that doesn't occur, bus
+ errors, busy devices ...). */
+/* #define USE_DEFAULT_TIMEOUT_CALLBACK */
+
+#if !defined (sEE_M24C08) && !defined (sEE_M24C64_32) && !defined (sEE_M24LR64) && !defined (sEE_M24M01)
+/* Use the defines below the choose the EEPROM type */
+#define sEE_M24M01 /* Support the device: M24M01. */
+/* #define sEE_M24C08*/ /* Support the device: M24C08. */
+/* note: Could support: M24C01, M24C02, M24C04 and M24C16 if the blocks and
+ HW address are correctly defined*/
+/*#define sEE_M24C64_32*/ /* Support the devices: M24C32 and M24C64 */
+/*#define sEE_M24LR64*/ /*Support the devices: M24LR64 */
+#endif
+
+#ifdef sEE_M24C64_32
+/* For M24C32 and M24C64 devices, E0,E1 and E2 pins are all used for device
+ address selection (ne need for additional address lines). According to the
+ Harware connection on the board. */
+
+ #define sEE_HW_ADDRESS 0xA0 /* E0 = E1 = E2 = 0 */
+
+#elif defined (sEE_M24C08)
+/* The M24C08W contains 4 blocks (128byte each) with the adresses below: E2 = 0
+ EEPROM Addresses defines */
+ #define sEE_HW_ADDRESS 0xA0 /* E2 = 0 */
+ /*#define sEE_HW_ADDRESS 0xA2*/ /* E2 = 0 */
+ /*#define sEE_HW_ADDRESS 0xA4*/ /* E2 = 0 */
+ /*#define sEE_HW_ADDRESS 0xA6*/ /* E2 = 0 */
+
+#elif defined (sEE_M24LR64)
+ #define sEE_HW_ADDRESS 0xA0
+
+#elif defined (sEE_M24M01)
+/* The sEE_M24M01 contains 2 blocks (64Kbytes each) with the adresses below
+ EEPROM Addresses defines */
+ #define sEE_HW_ADDRESS 0xA4 /* Block 1 : E1= 1; E2 = 0; A16 = 0 */
+ /*#define sEE_HW_ADDRESS 0xA6*/ /* Block 2 : E1= 1; E2 = 0; A16 = 1 */
+
+#endif /* sEE_M24C64_32 */
+
+/* I2C TIMING Register define when I2C clock source is SYSCLK */
+/* I2C TIMING is calculated in case of the I2C Clock source is the SYSCLK = 72 MHz */
+/* When using sEE_M24M01 set TIMING to 0x00C4092A to reach 1 MHz speed (Rise time = 26ns, Fall time = 2ns) */
+/* When using sEE_M24LR64 set TIMING to 0xC062121F to reach 100 KHz speed (Rise time = 640ns, Fall time = 20ns) */
+
+#define sEE_I2C_TIMING 0xC062121F
+
+
+#if defined (sEE_M24C08)
+ #define sEE_PAGESIZE 16
+#elif defined (sEE_M24C64_32)
+ #define sEE_PAGESIZE 32
+#elif defined (sEE_M24LR64)
+ #define sEE_PAGESIZE 4
+#elif defined (sEE_M24M01)
+ #define sEE_PAGESIZE 128
+#endif
+
+/* Maximum Timeout values for flags and events waiting loops. These timeouts are
+ not based on accurate values, they just guarantee that the application will
+ not remain stuck if the I2C communication is corrupted.
+ You may modify these timeout values depending on CPU frequency and application
+ conditions (interrupts routines ...). */
+#define sEE_FLAG_TIMEOUT ((uint32_t)0x1000)
+#define sEE_LONG_TIMEOUT ((uint32_t)(10 * sEE_FLAG_TIMEOUT))
+
+/* Maximum number of trials for sEE_WaitEepromStandbyState() function */
+#define sEE_MAX_TRIALS_NUMBER 300
+
+#define sEE_OK 0
+#define sEE_FAIL 1
+
+/**
+ * @}
+ */
+
+/** @defgroup STM32303C_EVAL_I2C_EE_Exported_Macros
+ * @{
+ */
+/**
+ * @}
+ */
+
+/** @defgroup STM32303C_EVAL_I2C_EE_Exported_Functions
+ * @{
+ */
+void sEE_DeInit(void);
+void sEE_Init(void);
+uint32_t sEE_ReadBuffer(uint8_t* pBuffer, uint16_t ReadAddr, uint16_t* NumByteToRead);
+uint32_t sEE_WritePage(uint8_t* pBuffer, uint16_t WriteAddr, uint8_t* NumByteToWrite);
+void sEE_WriteBuffer(uint8_t* pBuffer, uint16_t WriteAddr, uint16_t NumByteToWrite);
+uint32_t sEE_WaitEepromStandbyState(void);
+
+/* USER Callbacks: These are functions for which prototypes only are declared in
+ EEPROM driver and that should be implemented into user applicaiton. */
+/* sEE_TIMEOUT_UserCallback() function is called whenever a timeout condition
+ occure during communication (waiting on an event that doesn't occur, bus
+ errors, busy devices ...).
+ You can use the default timeout callback implementation by uncommenting the
+ define USE_DEFAULT_TIMEOUT_CALLBACK in stm32303c_eval_i2c_ee.h file.
+ Typically the user implementation of this callback should reset I2C peripheral
+ and re-initialize communication or in worst case reset all the application. */
+uint32_t sEE_TIMEOUT_UserCallback(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __STM32303C_EVAL_I2C_EE_H */
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
+
+
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32303C_EVAL/stm32303c_eval_i2c_tsensor.c b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32303C_EVAL/stm32303c_eval_i2c_tsensor.c
new file mode 100644
index 0000000..54476df
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32303C_EVAL/stm32303c_eval_i2c_tsensor.c
@@ -0,0 +1,754 @@
+/**
+ ******************************************************************************
+ * @file stm32303c_eval_i2c_tsensor.c
+ * @author MCD Application Team
+ * @version V1.0.1
+ * @date 23-October-2012
+ * @brief This file provides a set of functions needed to manage the I2C TS751
+ * temperature sensor mounted on STM32303C-EVAL board .
+ * It implements a high level communication layer for read and write
+ * from/to this sensor. The needed STM323F30x hardware resources (I2C and
+ * GPIO) are defined in stm32303c_eval.h file, and the initialization is
+ * performed in TS751_LowLevel_Init() function declared in stm32303c_eval.c
+ * file.
+ * You can easily tailor this driver to any other development board,
+ * by just adapting the defines for hardware resources and
+ * TS751_LowLevel_Init() function.
+ *
+ * +--------------------------------------------------------------------+
+ * | Pin assignment |
+ * +---------------------------------------+-----------+----------------+
+ * | STM32F30x I2C Pins | STTS751 | Pin |
+ * +---------------------------------------+-----------+----------------+
+ * | TS751_I2C_SDA_PIN/ SDA | Addr/Therm | 1 |
+ * | TS751_I2C_SCL_PIN/ SCL | GND | 2 (0V) |
+ * | TS751_I2C_SMBUSALERT_PIN/ SMBUS ALERT | VDD | 3 (3.3V)|
+ * | Addr/Therm pin | SCL | 4 |
+ * | . | SMBUS ALERT| 5 |
+ * | . | SDA | 6 |
+ * +---------------------------------------+-----------+----------------+
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.st.com/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+
+/* Includes ------------------------------------------------------------------*/
+#include "stm32303c_eval_i2c_tsensor.h"
+
+/** @addtogroup Utilities
+ * @{
+ */
+
+/** @addtogroup STM32303C_EVAL
+ * @{
+ */
+
+/** @addtogroup Common
+ * @{
+ */
+
+/** @addtogroup STM32303C_EVAL_I2C_TSENSOR
+ * @brief This file includes the TS751 Temperature Sensor driver of
+ * STM32303C-EVAL boards.
+ * @{
+ */
+
+/** @defgroup STM32303C_EVAL_I2C_TSENSOR_Private_Types
+ * @{
+ */
+/**
+ * @}
+ */
+
+/** @defgroup STM32303C_EVAL_I2C_TSENSOR_Private_Defines
+ * @{
+ */
+#define TS751_SD_SET 0x01 /*!< Set SD bit in the configuration register */
+#define TS751_SD_RESET 0xFE /*!< Reset SD bit in the configuration register */
+/**
+ * @}
+ */
+
+/** @defgroup STM32303C_EVAL_I2C_TSENSOR_Private_Macros
+ * @{
+ */
+/**
+ * @}
+ */
+
+/** @defgroup STM32303C_EVAL_I2C_TSENSOR_Private_Variables
+ * @{
+ */
+
+__IO uint32_t TS751_Timeout = TS751_LONG_TIMEOUT;
+/**
+ * @}
+ */
+
+/** @defgroup STM32303C_EVAL_I2C_TSENSOR_Private_Function_Prototypes
+ * @{
+ */
+
+/**
+ * @}
+ */
+
+
+/** @defgroup STM32303C_EVAL_I2C_TSENSOR_Private_Functions
+ * @{
+ */
+
+/**
+ * @brief DeInitializes the TS751_I2C.
+ * @param None
+ * @retval None
+ */
+void TS751_DeInit(void)
+{
+ TS751_LowLevel_DeInit();
+}
+
+/**
+ * @brief Initializes the TS751_I2C.
+ * @param None
+ * @retval None
+ */
+void TS751_Init(void)
+{
+ I2C_InitTypeDef I2C_InitStructure;
+
+ TS751_LowLevel_Init();
+
+ /* TS751_I2C configuration */
+ I2C_InitStructure.I2C_Mode = I2C_Mode_SMBusHost;
+ I2C_InitStructure.I2C_AnalogFilter = I2C_AnalogFilter_Enable;
+ I2C_InitStructure.I2C_DigitalFilter = 0x00;
+ I2C_InitStructure.I2C_OwnAddress1 = 0x00;
+ I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
+ I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
+ I2C_InitStructure.I2C_Timing = TS751_I2C_TIMING;
+
+ /* Apply TS751_I2C configuration after enabling it */
+ I2C_Init(TS751_I2C, &I2C_InitStructure);
+
+ /* TS751_I2C Peripheral Enable */
+ I2C_Cmd(TS751_I2C, ENABLE);
+}
+
+/**
+ * @brief Checks the TS751 status.
+ * @param None
+ * @retval ErrorStatus: TS751 Status (ERROR or SUCCESS).
+ */
+ErrorStatus TS751_GetStatus(void)
+{
+ uint32_t I2C_TimeOut = I2C_TIMEOUT;
+
+ /* Configure slave address, nbytes, reload, end mode and start or stop generation */
+ I2C_TransferHandling(TS751_I2C, TS751_ADDR, 0, I2C_AutoEnd_Mode, I2C_No_StartStop);
+
+ /* Clear NACKF and STOPF */
+ I2C_ClearFlag(TS751_I2C, I2C_ICR_NACKCF | I2C_ICR_STOPCF);
+
+ /* Generate start */
+ I2C_GenerateSTART(TS751_I2C, ENABLE);
+
+ /* Wait until timeout elapsed */
+ while ((I2C_GetFlagStatus(TS751_I2C, I2C_ISR_STOPF) == RESET) && (I2C_TimeOut-- != 0));
+
+ /* Check if Temp sensor is ready for use */
+ if ((I2C_GetFlagStatus(TS751_I2C, I2C_ISR_NACKF) != RESET) || (I2C_TimeOut == 0))
+ {
+ /* Clear NACKF and STOPF */
+ I2C_ClearFlag(TS751_I2C, I2C_ICR_NACKCF | I2C_ICR_STOPCF);
+
+ return ERROR;
+ }
+ else
+ {
+ /* Clear STOPF */
+ I2C_ClearFlag(TS751_I2C, I2C_ICR_STOPCF);
+
+ return SUCCESS;
+ }
+}
+
+/**
+ * @brief Read the specified register from the TS751.
+ * @param RegName: specifies the TS751 register to be read.
+ * This member can be one of the following values:
+ * - TS751_REG_TEMP: temperature register
+ * - TS751_REG_TOS: Over-limit temperature register
+ * - TS751_REG_THYS: Hysteresis temperature register
+ * @retval TS751 register value.
+ */
+uint8_t TS751_ReadReg(uint8_t RegName)
+{
+ uint8_t TS751_BufferRX[1] ={0};
+
+ /* Test on BUSY Flag */
+ TS751_Timeout = TS751_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(TS751_I2C, I2C_ISR_BUSY) != RESET)
+ {
+ if((TS751_Timeout--) == 0) return TS751_TIMEOUT_UserCallback();
+ }
+
+ /* Configure slave address, nbytes, reload, end mode and start or stop generation */
+ I2C_TransferHandling(TS751_I2C, TS751_ADDR, 1, I2C_SoftEnd_Mode, I2C_Generate_Start_Write);
+
+ /* Wait until TXIS flag is set */
+ TS751_Timeout = TS751_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(TS751_I2C, I2C_ISR_TXIS) == RESET)
+ {
+ if((TS751_Timeout--) == 0) return TS751_TIMEOUT_UserCallback();
+ }
+
+ /* Send Register address */
+ I2C_SendData(TS751_I2C, (uint8_t)RegName);
+
+ /* Wait until TC flag is set */
+ TS751_Timeout = TS751_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(TS751_I2C, I2C_ISR_TC) == RESET)
+ {
+ if((TS751_Timeout--) == 0) return TS751_TIMEOUT_UserCallback();
+ }
+
+ /* Configure slave address, nbytes, reload, end mode and start or stop generation */
+ I2C_TransferHandling(TS751_I2C, TS751_ADDR, 1, I2C_AutoEnd_Mode, I2C_Generate_Start_Read);
+
+ /* Wait until RXNE flag is set */
+ TS751_Timeout = TS751_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(TS751_I2C, I2C_ISR_RXNE) == RESET)
+ {
+ if((TS751_Timeout--) == 0) return TS751_TIMEOUT_UserCallback();
+ }
+
+ /* Read data from RXDR */
+ TS751_BufferRX[0]= I2C_ReceiveData(TS751_I2C);
+
+ /* Wait until STOPF flag is set */
+ TS751_Timeout = TS751_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(TS751_I2C, I2C_ISR_STOPF) == RESET)
+ {
+ if((TS751_Timeout--) == 0) return TS751_TIMEOUT_UserCallback();
+ }
+
+ /* Clear STOPF flag */
+ I2C_ClearFlag(TS751_I2C, I2C_ICR_STOPCF);
+
+ /* return a Reg value */
+ return TS751_BufferRX[0];
+}
+
+/**
+ * @brief Write to the specified register of the TS751.
+ * @param RegName: specifies the TS751 register to be written.
+ * This member can be one of the following values:
+ * - TS751_REG_TOS: Over-limit temperature register
+ * - TS751_REG_THYS: Hysteresis temperature register
+ * @param RegValue: value to be written to TS751 register.
+ * @retval None
+ */
+uint8_t TS751_WriteReg(uint8_t RegName, uint16_t RegValue)
+{
+ uint8_t TS751_BufferTX[1] ={0};
+
+ TS751_BufferTX[0] = (uint8_t)(RegValue);
+
+ /* Test on BUSY Flag */
+ TS751_Timeout = TS751_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(TS751_I2C, I2C_ISR_BUSY) != RESET)
+ {
+ if((TS751_Timeout--) == 0) return TS751_TIMEOUT_UserCallback();
+ }
+
+ /* Configure slave address, nbytes, reload, end mode and start or stop generation */
+ I2C_TransferHandling(TS751_I2C, TS751_ADDR, 1, I2C_Reload_Mode, I2C_Generate_Start_Write);
+
+ /* Wait until TXIS flag is set */
+ TS751_Timeout = TS751_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(TS751_I2C, I2C_ISR_TXIS) == RESET)
+ {
+ if((TS751_Timeout--) == 0) return TS751_TIMEOUT_UserCallback();
+ }
+
+ /* Send Register address */
+ I2C_SendData(TS751_I2C, (uint8_t)RegName);
+
+ /* Wait until TCR flag is set */
+ TS751_Timeout = TS751_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(TS751_I2C, I2C_ISR_TCR) == RESET)
+ {
+ if((TS751_Timeout--) == 0) return TS751_TIMEOUT_UserCallback();
+ }
+
+ /* Configure slave address, nbytes, reload, end mode and start or stop generation */
+ I2C_TransferHandling(TS751_I2C, TS751_ADDR, 1, I2C_AutoEnd_Mode, I2C_No_StartStop);
+
+ /* Wait until TXIS flag is set */
+ TS751_Timeout = TS751_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(TS751_I2C, I2C_ISR_TXIS) == RESET)
+ {
+ if((TS751_Timeout--) == 0) return TS751_TIMEOUT_UserCallback();
+ }
+
+ /* Write data to TXDR */
+ I2C_SendData(TS751_I2C, (TS751_BufferTX[0]));
+
+
+ /* Wait until STOPF flag is set */
+ TS751_Timeout = TS751_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(TS751_I2C, I2C_ISR_STOPF) == RESET)
+ {
+ if((TS751_Timeout--) == 0) return TS751_TIMEOUT_UserCallback();
+ }
+
+ /* Clear STOPF flag */
+ I2C_ClearFlag(TS751_I2C, I2C_ICR_STOPCF);
+
+ return TS751_OK;
+}
+/**
+ * @brief Read Temperature register of TS751: double temperature value.
+ * @param None
+ * @retval TS751 measured temperature value.
+ */
+uint8_t TS751_AlerteResponseAddressRead(void)
+{
+ uint8_t TS751_BufferRX[1] ={0};
+
+ /**************** Read Alerte Response Address ***********************/
+ /* Test on BUSY Flag */
+ TS751_Timeout = TS751_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(TS751_I2C, I2C_ISR_BUSY) != RESET)
+ {
+ if((TS751_Timeout--) == 0) return TS751_TIMEOUT_UserCallback();
+ }
+ /* Configure slave address, nbytes, reload, end mode and start generation */
+ I2C_TransferHandling(TS751_I2C, 0x18, 1, I2C_AutoEnd_Mode, I2C_Generate_Start_Read);
+ /* Wait until RXNE flag is set */
+ TS751_Timeout = TS751_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(TS751_I2C, I2C_ISR_RXNE) == RESET)
+ {
+ if((TS751_Timeout--) == 0) return TS751_TIMEOUT_UserCallback();
+ }
+ /* Read data from RXDR */
+ TS751_BufferRX[0]= I2C_ReceiveData(TS751_I2C);
+
+ /* Wait until STOPF flag is set */
+ TS751_Timeout = TS751_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(TS751_I2C, I2C_ISR_STOPF) == RESET)
+ {
+ if((TS751_Timeout--) == 0) return TS751_TIMEOUT_UserCallback();
+ }
+ /* Clear STOPF flag */
+ I2C_ClearFlag(TS751_I2C, I2C_ICR_STOPCF | I2C_ICR_NACKCF);
+
+ /* return ARA value */
+ return TS751_BufferRX[0];
+}
+
+
+/**
+ * @brief Read Temperature register of TS751: double temperature value.
+ * @param None
+ * @retval TS751 measured temperature value.
+ */
+uint16_t TS751_ReadTemp(void)
+{
+ uint8_t TS751_BufferRX[2] ={0,0};
+ uint16_t tmp = 0;
+
+ /**************** Read Temperature value high Register ***********************/
+ /* Test on BUSY Flag */
+ TS751_Timeout = TS751_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(TS751_I2C, I2C_ISR_BUSY) != RESET)
+ {
+ if((TS751_Timeout--) == 0) return TS751_TIMEOUT_UserCallback();
+ }
+ /* Configure slave address, nbytes, reload, end mode and start or stop generation */
+ I2C_TransferHandling(TS751_I2C, TS751_ADDR, 1, I2C_SoftEnd_Mode, I2C_Generate_Start_Write);
+ /* Wait until TXIS flag is set */
+ TS751_Timeout = TS751_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(TS751_I2C, I2C_ISR_TXIS) == RESET)
+ {
+ if((TS751_Timeout--) == 0) return TS751_TIMEOUT_UserCallback();
+ }
+ /* Send Register address */
+ I2C_SendData(TS751_I2C, (uint8_t)TS751_REG_TEMPH);
+ /* Wait until TC flag is set */
+ TS751_Timeout = TS751_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(TS751_I2C, I2C_ISR_TC) == RESET)
+ {
+ if((TS751_Timeout--) == 0) return TS751_TIMEOUT_UserCallback();
+ }
+ /* Configure slave address, nbytes, reload, end mode and start or stop generation */
+ I2C_TransferHandling(TS751_I2C, TS751_ADDR, 1, I2C_AutoEnd_Mode, I2C_Generate_Start_Read);
+ /* Wait until RXNE flag is set */
+ TS751_Timeout = TS751_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(TS751_I2C, I2C_ISR_RXNE) == RESET)
+ {
+ if((TS751_Timeout--) == 0) return TS751_TIMEOUT_UserCallback();
+ }
+ /* Read data from RXDR */
+ TS751_BufferRX[0]= I2C_ReceiveData(TS751_I2C);
+ /* Wait until STOPF flag is set */
+ TS751_Timeout = TS751_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(TS751_I2C, I2C_ISR_STOPF) == RESET)
+ {
+ if((TS751_Timeout--) == 0) return TS751_TIMEOUT_UserCallback();
+ }
+ /* Clear STOPF flag */
+ I2C_ClearFlag(TS751_I2C, I2C_ICR_STOPCF);
+
+
+ /****************** Read Temperature value low Register ************************/
+ /* Test on BUSY Flag */
+ TS751_Timeout = TS751_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(TS751_I2C, I2C_ISR_BUSY) != RESET)
+ {
+ if((TS751_Timeout--) == 0) return TS751_TIMEOUT_UserCallback();
+ }
+ /* Configure slave address, nbytes, reload, end mode and start or stop generation */
+ I2C_TransferHandling(TS751_I2C, TS751_ADDR, 1, I2C_SoftEnd_Mode, I2C_Generate_Start_Write);
+ /* Wait until TXIS flag is set */
+ TS751_Timeout = TS751_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(TS751_I2C, I2C_ISR_TXIS) == RESET)
+ {
+ if((TS751_Timeout--) == 0) return TS751_TIMEOUT_UserCallback();
+ }
+ /* Send Register address */
+ I2C_SendData(TS751_I2C, (uint8_t)TS751_REG_TEMPL);
+
+ /* Wait until TC flag is set */
+ TS751_Timeout = TS751_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(TS751_I2C, I2C_ISR_TC) == RESET)
+ {
+ if((TS751_Timeout--) == 0) return TS751_TIMEOUT_UserCallback();
+ }
+ /* Configure slave address, nbytes, reload, end mode and start or stop generation */
+ I2C_TransferHandling(TS751_I2C, TS751_ADDR, 1, I2C_AutoEnd_Mode, I2C_Generate_Start_Read);
+
+ /* Wait until RXNE flag is set */
+ TS751_Timeout = TS751_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(TS751_I2C, I2C_ISR_RXNE) == RESET)
+ {
+ if((TS751_Timeout--) == 0) return TS751_TIMEOUT_UserCallback();
+ }
+ /* Read data from RXDR */
+ TS751_BufferRX[1]= I2C_ReceiveData(TS751_I2C);
+ /* Wait until STOPF flag is set */
+ TS751_Timeout = TS751_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(TS751_I2C, I2C_ISR_STOPF) == RESET)
+ {
+ if((TS751_Timeout--) == 0) return TS751_TIMEOUT_UserCallback();
+ }
+ /* Clear STOPF flag */
+ I2C_ClearFlag(TS751_I2C, I2C_ICR_STOPCF);
+
+ /*************************** Store Data ******************************/
+ /*!< Store TS751_I2C received data */
+ tmp = (uint16_t)(TS751_BufferRX[0] << 8);
+ tmp |= TS751_BufferRX[1];
+ /*!< Return Temperature value */
+ return (uint16_t)(tmp >> 4);
+}
+
+/**
+ * @brief Read the configuration register from the TS751.
+ * @param None
+ * @retval TS751 configuration register value.
+ */
+uint8_t TS751_ReadConfReg(void)
+{
+ uint8_t TS751_BufferRX[1] ={0};
+
+ /* Test on BUSY Flag */
+ TS751_Timeout = TS751_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(TS751_I2C, I2C_ISR_BUSY) != RESET)
+ {
+ if((TS751_Timeout--) == 0) return TS751_TIMEOUT_UserCallback();
+ }
+
+ /* Configure slave address, nbytes, reload, end mode and start or stop generation */
+ I2C_TransferHandling(TS751_I2C, TS751_ADDR, 1, I2C_SoftEnd_Mode, I2C_Generate_Start_Write);
+
+ /* Wait until TXIS flag is set */
+ TS751_Timeout = TS751_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(TS751_I2C, I2C_ISR_TXIS) == RESET)
+ {
+ if((TS751_Timeout--) == 0) return TS751_TIMEOUT_UserCallback();
+ }
+
+ /* Send Register address */
+ I2C_SendData(TS751_I2C, (uint8_t)TS751_REG_CONF);
+
+ /* Wait until TC flag is set */
+ TS751_Timeout = TS751_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(TS751_I2C, I2C_ISR_TC) == RESET)
+ {
+ if((TS751_Timeout--) == 0) return TS751_TIMEOUT_UserCallback();
+ }
+
+ /* Configure slave address, nbytes, reload, end mode and start or stop generation */
+ I2C_TransferHandling(TS751_I2C, TS751_ADDR, 1, I2C_AutoEnd_Mode, I2C_Generate_Start_Read);
+
+ /* Wait until RXNE flag is set */
+ TS751_Timeout = TS751_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(TS751_I2C, I2C_ISR_RXNE) == RESET)
+ {
+ if((TS751_Timeout--) == 0) return TS751_TIMEOUT_UserCallback();
+ }
+
+ /* Read data from RXDR */
+ TS751_BufferRX[0]= I2C_ReceiveData(TS751_I2C);
+
+ /* Wait until STOPF flag is set */
+ TS751_Timeout = TS751_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(TS751_I2C, I2C_ISR_STOPF) == RESET)
+ {
+ if((TS751_Timeout--) == 0) return TS751_TIMEOUT_UserCallback();
+ }
+
+ /* Clear STOPF flag */
+ I2C_ClearFlag(TS751_I2C, I2C_ICR_STOPCF);
+
+ /*!< Return Register value */
+ return (uint8_t)TS751_BufferRX[0];
+}
+
+/**
+ * @brief Write to the configuration register of the TS751.
+ * @param RegValue: specifies the value to be written to TS751 configuration
+ * register.
+ * @retval None
+ */
+uint8_t TS751_WriteConfReg(uint8_t RegValue)
+{
+ uint8_t TS751_BufferTX = 0;
+
+ TS751_BufferTX = (uint8_t)(RegValue);
+
+ /* Test on BUSY Flag */
+ TS751_Timeout = TS751_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(TS751_I2C, I2C_ISR_BUSY) != RESET)
+ {
+ if((TS751_Timeout--) == 0) return TS751_TIMEOUT_UserCallback();
+ }
+
+ /* Configure slave address, nbytes, reload, end mode and start or stop generation */
+ I2C_TransferHandling(TS751_I2C, TS751_ADDR, 1, I2C_Reload_Mode, I2C_Generate_Start_Write);
+
+ /* Wait until TXIS flag is set */
+ TS751_Timeout = TS751_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(TS751_I2C, I2C_ISR_TXIS) == RESET)
+ {
+ if((TS751_Timeout--) == 0) return TS751_TIMEOUT_UserCallback();
+ }
+
+ /* Send Register address */
+ I2C_SendData(TS751_I2C, (uint8_t)TS751_REG_CONF);
+
+ /* Wait until TCR flag is set */
+ TS751_Timeout = TS751_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(TS751_I2C, I2C_ISR_TCR) == RESET)
+ {
+ if((TS751_Timeout--) == 0) return TS751_TIMEOUT_UserCallback();
+ }
+
+ /* Configure slave address, nbytes, reload, end mode and start or stop generation */
+ I2C_TransferHandling(TS751_I2C, TS751_ADDR, 1, I2C_AutoEnd_Mode, I2C_No_StartStop);
+
+ /* Wait until TXIS flag is set */
+ TS751_Timeout = TS751_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(TS751_I2C, I2C_ISR_TXIS) == RESET)
+ {
+ if((TS751_Timeout--) == 0) return TS751_TIMEOUT_UserCallback();
+ }
+
+ /* Write data to TXDR */
+ I2C_SendData(TS751_I2C, (uint8_t)TS751_BufferTX);
+
+ /* Wait until STOPF flag is set */
+ TS751_Timeout = TS751_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(TS751_I2C, I2C_ISR_STOPF) == RESET)
+ {
+ if((TS751_Timeout--) == 0) return TS751_TIMEOUT_UserCallback();
+ }
+
+ /* Clear STOPF flag */
+ I2C_ClearFlag(TS751_I2C, I2C_ICR_STOPCF);
+
+ return TS751_OK;
+}
+
+/**
+ * @brief Enables or disables the TS751.
+ * @param NewState: specifies the TS751 new status. This parameter can be ENABLE
+ * or DISABLE.
+ * @retval None
+ */
+uint8_t TS751_ShutDown(FunctionalState NewState)
+{
+ uint8_t TS751_BufferRX[2] ={0,0};
+ uint8_t TS751_BufferTX = 0;
+ __IO uint8_t RegValue = 0;
+
+ /* Test on BUSY Flag */
+ TS751_Timeout = TS751_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(TS751_I2C, I2C_ISR_BUSY) != RESET)
+ {
+ if((TS751_Timeout--) == 0) return TS751_TIMEOUT_UserCallback();
+ }
+
+ /* Configure slave address, nbytes, reload, end mode and start or stop generation */
+ I2C_TransferHandling(TS751_I2C, TS751_ADDR, 1, I2C_SoftEnd_Mode, I2C_Generate_Start_Write);
+
+ /* Wait until TXIS flag is set */
+ TS751_Timeout = TS751_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(TS751_I2C, I2C_ISR_TXIS) == RESET)
+ {
+ if((TS751_Timeout--) == 0) return TS751_TIMEOUT_UserCallback();
+ }
+
+ /* Send Register address */
+ I2C_SendData(TS751_I2C, (uint8_t)TS751_REG_CONF);
+
+ /* Wait until TC flag is set */
+ TS751_Timeout = TS751_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(TS751_I2C, I2C_ISR_TC) == RESET)
+ {
+ if((TS751_Timeout--) == 0) return TS751_TIMEOUT_UserCallback();
+ }
+
+ /* Configure slave address, nbytes, reload, end mode and start or stop generation */
+ I2C_TransferHandling(TS751_I2C, TS751_ADDR, 1, I2C_AutoEnd_Mode, I2C_Generate_Start_Read);
+
+ /* Wait until RXNE flag is set */
+ TS751_Timeout = TS751_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(TS751_I2C, I2C_ISR_RXNE) == RESET)
+ {
+ if((TS751_Timeout--) == 0) return TS751_TIMEOUT_UserCallback();
+ }
+
+ /* Read data from RXDR */
+ TS751_BufferRX[0]= I2C_ReceiveData(TS751_I2C);
+
+ /* Wait until STOPF flag is set */
+ TS751_Timeout = TS751_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(TS751_I2C, I2C_ISR_STOPF) == RESET)
+ {
+ if((TS751_Timeout--) == 0) return TS751_TIMEOUT_UserCallback();
+ }
+
+ /* Clear STOPF flag */
+ I2C_ClearFlag(TS751_I2C, I2C_ICR_STOPCF);
+
+ /*!< Get received data */
+ RegValue = (uint8_t)TS751_BufferRX[0];
+
+ /*---------------------------- Transmission Phase ---------------------------*/
+
+ /*!< Enable or disable SD bit */
+ if (NewState != DISABLE)
+ {
+ /*!< Enable TS751 */
+ TS751_BufferTX = RegValue & TS751_SD_RESET;
+ }
+ else
+ {
+ /*!< Disable TS751 */
+ TS751_BufferTX = RegValue | TS751_SD_SET;
+ }
+
+ /* Test on BUSY Flag */
+ TS751_Timeout = TS751_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(TS751_I2C, I2C_ISR_BUSY) != RESET)
+ {
+ if((TS751_Timeout--) == 0) return TS751_TIMEOUT_UserCallback();
+ }
+
+ /* Configure slave address, nbytes, reload, end mode and start or stop generation */
+ I2C_TransferHandling(TS751_I2C, TS751_ADDR, 1, I2C_Reload_Mode, I2C_Generate_Start_Write);
+
+ /* Wait until TXIS flag is set */
+ TS751_Timeout = TS751_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(TS751_I2C, I2C_ISR_TXIS) == RESET)
+ {
+ if((TS751_Timeout--) == 0) return TS751_TIMEOUT_UserCallback();
+ }
+
+ /* Send Register address */
+ I2C_SendData(TS751_I2C, (uint8_t)TS751_REG_CONF);
+
+ /* Wait until TCR flag is set */
+ TS751_Timeout = TS751_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(TS751_I2C, I2C_ISR_TCR) == RESET)
+ {
+ if((TS751_Timeout--) == 0) return TS751_TIMEOUT_UserCallback();
+ }
+
+ /* Configure slave address, nbytes, reload, end mode and start or stop generation */
+ I2C_TransferHandling(TS751_I2C, TS751_ADDR, 1, I2C_AutoEnd_Mode, I2C_No_StartStop);
+
+ /* Wait until TXIS flag is set */
+ TS751_Timeout = TS751_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(TS751_I2C, I2C_ISR_TXIS) == RESET)
+ {
+ if((TS751_Timeout--) == 0) return TS751_TIMEOUT_UserCallback();
+ }
+
+ /* Write data to TXDR */
+ I2C_SendData(TS751_I2C, (uint8_t)TS751_BufferTX);
+
+ /* Wait until STOPF flag is set */
+ TS751_Timeout = TS751_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(TS751_I2C, I2C_ISR_STOPF) == RESET)
+ {
+ if((TS751_Timeout--) == 0) return TS751_TIMEOUT_UserCallback();
+ }
+
+ /* Clear STOPF flag */
+ I2C_ClearFlag(TS751_I2C, I2C_ICR_STOPCF);
+
+ return TS751_OK;
+}
+
+/**
+ * @}
+ */
+
+
+/**
+ * @}
+ */
+
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32303C_EVAL/stm32303c_eval_i2c_tsensor.h b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32303C_EVAL/stm32303c_eval_i2c_tsensor.h
new file mode 100644
index 0000000..af5ff97
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32303C_EVAL/stm32303c_eval_i2c_tsensor.h
@@ -0,0 +1,177 @@
+/**
+ ******************************************************************************
+ * @file stm32303c_eval_i2c_tsensor.h
+ * @author MCD Application Team
+ * @version V1.0.1
+ * @date 23-October-2012
+ * @brief This file contains all the functions prototypes for the
+ * stm32303c_eval_i2c_tsensor.c firmware driver.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.st.com/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __STM32303C_EVAL_I2C_TSENSOR_H
+#define __STM32303C_EVAL_I2C_TSENSOR_H
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+/* Includes ------------------------------------------------------------------*/
+#include "stm32303c_eval.h"
+
+/** @addtogroup Utilities
+ * @{
+ */
+
+/** @addtogroup STM32303C_EVAL
+ * @{
+ */
+
+/** @addtogroup Common
+ * @{
+ */
+
+/** @addtogroup STM32303C_EVAL_I2C_TSENSOR
+ * @{
+ */
+
+/** @defgroup STM32303C_EVAL_I2C_TSENSOR_Exported_Types
+ * @{
+ */
+
+/**
+ * @brief TSENSOR Status
+ */
+typedef enum
+{
+ TS751_OK = 0,
+ TS751_FAIL
+}TS751_Status_TypDef;
+
+/**
+ * @}
+ */
+
+/** @defgroup STM32303C_EVAL_I2C_TSENSOR_Exported_Constants
+ * @{
+ */
+
+/* Uncomment the following line to use Timeout_User_Callback TS751_TimeoutUserCallback().
+ If This Callback is enabled, it should be implemented by user in main function .
+ TS751_TimeoutUserCallback() function is called whenever a timeout condition
+ occure during communication (waiting on an event that doesn't occur, bus
+ errors, busy devices ...). */
+/*#define USE_TIMEOUT_USER_CALLBACK*/
+
+/* Maximum Timeout values for flags and events waiting loops. These timeouts are
+ not based on accurate values, they just guarantee that the application will
+ not remain stuck if the I2C communication is corrupted.
+ You may modify these timeout values depending on CPU frequency and application
+ conditions (interrupts routines ...). */
+#define TS751_FLAG_TIMEOUT ((uint32_t)0x1000)
+#define TS751_LONG_TIMEOUT ((uint32_t)(10 * TS751_FLAG_TIMEOUT))
+
+
+/**
+ * @brief Block Size
+ */
+#define TS751_REG_TEMPH 0x00 /*!< Temperature Register of TS751 */
+#define TS751_REG_TEMPL 0x02 /*!< Temperature Register of TS751 */
+#define TS751_REG_CONF 0x03 /*!< Configuration Register of TS751 */
+#define TS751_REG_THYS 0x21 /*!< Temperature Register of TS751 */
+#define TS751_REG_TOS 0x20 /*!< Over-temp Shutdown threshold Register of TS751 */
+#define I2C_TIMEOUT ((uint32_t)0x3FFFF) /*!< I2C Time out */
+#define TS751_ADDR 0x90 /*!< TS751 address */
+
+
+/* I2C TIMING Register define when I2C clock source is SYSCLK */
+/* I2C TIMING is calculated in case of the I2C Clock source is the SYSCLK = 72 MHz */
+/* set TIMING to 0xC062121F to reach 100 KHz speed (Rise time = 640ns, Fall time = 20ns) */
+
+#define TS751_I2C_TIMING 0xC062121F
+
+
+/**
+ * @}
+ */
+
+/** @defgroup STM32303C_EVAL_I2C_TSENSOR_Exported_Macros
+ * @{
+ */
+/**
+ * @}
+ */
+
+/** @defgroup STM32303C_EVAL_I2C_TSENSOR_Exported_Functions
+ * @{
+ */
+void TS751_DeInit(void);
+void TS751_Init(void);
+ErrorStatus TS751_GetStatus(void);
+uint8_t TS751_AlerteResponseAddressRead(void);
+uint16_t TS751_ReadTemp(void);
+uint8_t TS751_ReadReg(uint8_t RegName);
+uint8_t TS751_WriteReg(uint8_t RegName, uint16_t RegValue);
+uint8_t TS751_ReadConfReg(void);
+uint8_t TS751_WriteConfReg(uint8_t RegValue);
+uint8_t TS751_ShutDown(FunctionalState NewState);
+
+/**
+ * @brief Timeout user callback function. This function is called when a timeout
+ * condition occurs during communication with TS751. Only protoype
+ * of this function is decalred in TS751 driver. Its implementation
+ * may be done into user application. This function may typically stop
+ * current operations and reset the I2C peripheral and TS751.
+ * To enable this function use uncomment the define USE_TIMEOUT_USER_CALLBACK
+ * at the top of this file.
+ */
+#ifdef USE_TIMEOUT_USER_CALLBACK
+ uint8_t TS751_TIMEOUT_UserCallback(void);
+#else
+ #define TS751_TIMEOUT_UserCallback() TS751_FAIL
+#endif /* USE_TIMEOUT_USER_CALLBACK */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __STM32303C_EVAL_I2C_TSENSOR_H */
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32373C_EVAL/stm32373c_eval.c b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32373C_EVAL/stm32373c_eval.c
new file mode 100644
index 0000000..62b6a04
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32373C_EVAL/stm32373c_eval.c
@@ -0,0 +1,677 @@
+/**
+ ******************************************************************************
+ * @file stm32373c_eval.c
+ * @author MCD Application Team
+ * @version V1.0.0
+ * @date 20-September-2012
+ * @brief This file provides a set of firmware functions to manage Leds,
+ * push-button and COM ports
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.st.com/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+
+/* Includes ------------------------------------------------------------------*/
+#include "stm32373c_eval.h"
+
+/** @addtogroup Utilities
+ * @{
+ */
+
+/** @addtogroup STM32_EVAL
+ * @{
+ */
+
+/** @addtogroup STM32373C_EVAL
+ * @{
+ */
+
+/** @defgroup STM32373C_EVAL_LOW_LEVEL
+ * @brief This file provides firmware functions to manage Leds, push-buttons,
+ * COM ports, SD card on SPI and temperature sensor (LM75) available on
+ * STM32373C-EVAL evaluation board from STMicroelectronics.
+ * @{
+ */
+
+/** @defgroup STM32373C_EVAL_LOW_LEVEL_Private_TypesDefinitions
+ * @{
+ */
+/**
+ * @}
+ */
+
+
+/** @defgroup STM32373C_EVAL_LOW_LEVEL_Private_Defines
+ * @{
+ */
+/**
+ * @}
+ */
+
+
+/** @defgroup STM32373C_EVAL_LOW_LEVEL_Private_Macros
+ * @{
+ */
+/**
+ * @}
+ */
+
+
+/** @defgroup STM32373C_EVAL_LOW_LEVEL_Private_Variables
+ * @{
+ */
+GPIO_TypeDef* GPIO_PORT[LEDn] = {LED1_GPIO_PORT, LED2_GPIO_PORT, LED3_GPIO_PORT,
+ LED4_GPIO_PORT};
+const uint16_t GPIO_PIN[LEDn] = {LED1_PIN, LED2_PIN, LED3_PIN,
+ LED4_PIN};
+const uint32_t GPIO_CLK[LEDn] = {LED1_GPIO_CLK, LED2_GPIO_CLK, LED3_GPIO_CLK,
+ LED4_GPIO_CLK};
+
+GPIO_TypeDef* BUTTON_PORT[BUTTONn] = {TAMPER_BUTTON_GPIO_PORT, KEY_BUTTON_GPIO_PORT,
+ RIGHT_BUTTON_GPIO_PORT, LEFT_BUTTON_GPIO_PORT,
+ UP_BUTTON_GPIO_PORT, DOWN_BUTTON_GPIO_PORT,
+ SEL_BUTTON_GPIO_PORT};
+
+const uint16_t BUTTON_PIN[BUTTONn] = {TAMPER_BUTTON_PIN, KEY_BUTTON_PIN,
+ RIGHT_BUTTON_PIN, LEFT_BUTTON_PIN,
+ UP_BUTTON_PIN, DOWN_BUTTON_PIN,
+ SEL_BUTTON_PIN};
+
+const uint32_t BUTTON_CLK[BUTTONn] = {TAMPER_BUTTON_GPIO_CLK, KEY_BUTTON_GPIO_CLK,
+ RIGHT_BUTTON_GPIO_CLK, LEFT_BUTTON_GPIO_CLK,
+ UP_BUTTON_GPIO_CLK, DOWN_BUTTON_GPIO_CLK,
+ SEL_BUTTON_GPIO_CLK};
+
+const uint16_t BUTTON_EXTI_LINE[BUTTONn] = {TAMPER_BUTTON_EXTI_LINE,
+ KEY_BUTTON_EXTI_LINE,
+ RIGHT_BUTTON_EXTI_LINE,
+ LEFT_BUTTON_EXTI_LINE,
+ UP_BUTTON_EXTI_LINE,
+ DOWN_BUTTON_EXTI_LINE,
+ SEL_BUTTON_EXTI_LINE};
+
+const uint8_t BUTTON_PORT_SOURCE[BUTTONn] = {TAMPER_BUTTON_EXTI_PORT_SOURCE,
+ KEY_BUTTON_EXTI_PORT_SOURCE,
+ RIGHT_BUTTON_EXTI_PORT_SOURCE,
+ LEFT_BUTTON_EXTI_PORT_SOURCE,
+ UP_BUTTON_EXTI_PORT_SOURCE,
+ DOWN_BUTTON_EXTI_PORT_SOURCE,
+ SEL_BUTTON_EXTI_PORT_SOURCE};
+
+const uint8_t BUTTON_PIN_SOURCE[BUTTONn] = {TAMPER_BUTTON_EXTI_PIN_SOURCE,
+ KEY_BUTTON_EXTI_PIN_SOURCE,
+ RIGHT_BUTTON_EXTI_PIN_SOURCE,
+ LEFT_BUTTON_EXTI_PIN_SOURCE,
+ UP_BUTTON_EXTI_PIN_SOURCE,
+ DOWN_BUTTON_EXTI_PIN_SOURCE,
+ SEL_BUTTON_EXTI_PIN_SOURCE};
+
+const uint8_t BUTTON_IRQn[BUTTONn] = {TAMPER_BUTTON_EXTI_IRQn, KEY_BUTTON_EXTI_IRQn,
+ RIGHT_BUTTON_EXTI_IRQn, LEFT_BUTTON_EXTI_IRQn,
+ UP_BUTTON_EXTI_IRQn, DOWN_BUTTON_EXTI_IRQn,
+ SEL_BUTTON_EXTI_IRQn};
+
+
+USART_TypeDef* COM_USART[COMn] = {EVAL_COM1};
+
+GPIO_TypeDef* COM_TX_PORT[COMn] = {EVAL_COM1_TX_GPIO_PORT};
+
+GPIO_TypeDef* COM_RX_PORT[COMn] = {EVAL_COM1_RX_GPIO_PORT};
+
+const uint32_t COM_USART_CLK[COMn] = {EVAL_COM1_CLK};
+
+const uint32_t COM_TX_PORT_CLK[COMn] = {EVAL_COM1_TX_GPIO_CLK};
+
+const uint32_t COM_RX_PORT_CLK[COMn] = {EVAL_COM1_RX_GPIO_CLK};
+
+const uint16_t COM_TX_PIN[COMn] = {EVAL_COM1_TX_PIN};
+
+const uint16_t COM_RX_PIN[COMn] = {EVAL_COM1_RX_PIN};
+
+const uint16_t COM_TX_PIN_SOURCE[COMn] = {EVAL_COM1_TX_SOURCE};
+
+const uint16_t COM_RX_PIN_SOURCE[COMn] = {EVAL_COM1_RX_SOURCE};
+
+const uint8_t COM_TX_AF[COMn] = {EVAL_COM1_TX_AF};
+
+const uint8_t COM_RX_AF[COMn] = {EVAL_COM1_RX_AF};
+
+
+/**
+ * @}
+ */
+
+
+/** @defgroup STM32373C_EVAL_LOW_LEVEL_Private_FunctionPrototypes
+ * @{
+ */
+
+/**
+ * @}
+ */
+
+/** @defgroup STM32373C_EVAL_LOW_LEVEL_Private_Functions
+ * @{
+ */
+
+/**
+ * @brief Configures LED GPIO.
+ * @param Led: Specifies the Led to be configured.
+ * This parameter can be one of following parameters:
+ * @arg LED1
+ * @arg LED2
+ * @arg LED3
+ * @arg LED4
+ * @retval None
+ */
+void STM_EVAL_LEDInit(Led_TypeDef Led)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+
+ /* Enable the GPIO_LED Clock */
+ RCC_AHBPeriphClockCmd(GPIO_CLK[Led], ENABLE);
+
+ /* Configure the GPIO_LED pin */
+ GPIO_InitStructure.GPIO_Pin = GPIO_PIN[Led];
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
+ GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
+ GPIO_Init(GPIO_PORT[Led], &GPIO_InitStructure);
+ GPIO_PORT[Led]->BSRR = GPIO_PIN[Led];
+}
+
+/**
+ * @brief Turns selected LED On.
+ * @param Led: Specifies the Led to be set on.
+ * This parameter can be one of following parameters:
+ * @arg LED1
+ * @arg LED2
+ * @arg LED3
+ * @arg LED4
+ * @retval None
+ */
+void STM_EVAL_LEDOn(Led_TypeDef Led)
+{
+ GPIO_PORT[Led]->BRR = GPIO_PIN[Led];
+}
+
+/**
+ * @brief Turns selected LED Off.
+ * @param Led: Specifies the Led to be set off.
+ * This parameter can be one of following parameters:
+ * @arg LED1
+ * @arg LED2
+ * @arg LED3
+ * @arg LED4
+ * @retval None
+ */
+void STM_EVAL_LEDOff(Led_TypeDef Led)
+{
+ GPIO_PORT[Led]->BSRR = GPIO_PIN[Led];
+}
+
+/**
+ * @brief Toggles the selected LED.
+ * @param Led: Specifies the Led to be toggled.
+ * This parameter can be one of following parameters:
+ * @arg LED1
+ * @arg LED2
+ * @arg LED3
+ * @arg LED4
+ * @retval None
+ */
+void STM_EVAL_LEDToggle(Led_TypeDef Led)
+{
+ GPIO_PORT[Led]->ODR ^= GPIO_PIN[Led];
+}
+
+/**
+ * @brief Configures Button GPIO and EXTI Line.
+ * @param Button: Specifies the Button to be configured.
+ * This parameter can be one of following parameters:
+ * @arg BUTTON_TAMPER: Tamper Push Button
+ * @arg BUTTON_KEY: Key Push Button
+ * @arg BUTTON_RIGHT: Joystick Right Push Button
+ * @arg BUTTON_LEFT: Joystick Left Push Button
+ * @arg BUTTON_UP: Joystick Up Push Button
+ * @arg BUTTON_DOWN: Joystick Down Push Button
+ * @arg BUTTON_SEL: Joystick Sel Push Button
+ * @param Button_Mode: Specifies Button mode.
+ * This parameter can be one of following parameters:
+ * @arg BUTTON_MODE_GPIO: Button will be used as simple IO
+ * @arg BUTTON_MODE_EXTI: Button will be connected to EXTI line with interrupt
+ * generation capability
+ * @retval None
+ */
+void STM_EVAL_PBInit(Button_TypeDef Button, ButtonMode_TypeDef Button_Mode)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+ EXTI_InitTypeDef EXTI_InitStructure;
+ NVIC_InitTypeDef NVIC_InitStructure;
+
+ /* There is no Wakeup button on STM32373C_EVAL, the Button value should
+ be greater than 0. */
+ if(Button > 0)
+ {
+ Button = (Button_TypeDef) (Button - 1);
+
+ /* Enable the BUTTON Clock */
+ RCC_AHBPeriphClockCmd(BUTTON_CLK[Button], ENABLE);
+ RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
+
+ /* Configure Button pin as input */
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
+ GPIO_InitStructure.GPIO_Pin = BUTTON_PIN[Button];
+ GPIO_Init(BUTTON_PORT[Button], &GPIO_InitStructure);
+
+
+ if (Button_Mode == BUTTON_MODE_EXTI)
+ {
+ /* Connect Button EXTI Line to Button GPIO Pin */
+ SYSCFG_EXTILineConfig(BUTTON_PORT_SOURCE[Button], BUTTON_PIN_SOURCE[Button]);
+
+ /* Configure Button EXTI line */
+ EXTI_InitStructure.EXTI_Line = BUTTON_EXTI_LINE[Button];
+ EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
+
+ if(Button != BUTTON_KEY)
+ {
+ EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
+ }
+ else
+ {
+ EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
+ }
+ EXTI_InitStructure.EXTI_LineCmd = ENABLE;
+ EXTI_Init(&EXTI_InitStructure);
+
+ /* Enable and set Button EXTI Interrupt to the lowest priority */
+ NVIC_InitStructure.NVIC_IRQChannel = BUTTON_IRQn[Button];
+ NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F;
+ NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;
+ NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
+
+ NVIC_Init(&NVIC_InitStructure);
+ }
+ }
+}
+
+/**
+ * @brief Returns the selected Button state.
+ * @param Button: Specifies the Button to be checked.
+ * This parameter can be one of following parameters:
+ * @arg BUTTON_TAMPER: Tamper Push Button
+ * @arg BUTTON_KEY: Key Push Button
+ * @arg BUTTON_RIGHT: Joystick Right Push Button
+ * @arg BUTTON_LEFT: Joystick Left Push Button
+ * @arg BUTTON_UP: Joystick Up Push Button
+ * @arg BUTTON_DOWN: Joystick Down Push Button
+ * @arg BUTTON_SEL: Joystick Sel Push Button
+ * @retval - When Button > 0, the Button GPIO pin value is returned.
+ * - When Button = 0 , error code (0xFF) is returned.
+ */
+uint32_t STM_EVAL_PBGetState(Button_TypeDef Button)
+{
+ /* There is no Wakeup button on STM32373C_EVAL-EVAL, the Button value should
+ be greater than 0. */
+ if(Button > 0)
+ {
+ Button = (Button_TypeDef) (Button - 1);
+ return GPIO_ReadInputDataBit(BUTTON_PORT[Button], BUTTON_PIN[Button]);
+ }
+ else
+ {
+ return 0xFF; /* Error Code */
+ }
+}
+
+/**
+ * @brief Configures COM port.
+ * @param COM: Specifies the COM port to be configured.
+ * This parameter can be one of following parameters:
+ * @arg COM1
+ * @arg COM2
+ * @param USART_InitStruct: pointer to a USART_InitTypeDef structure that
+ * contains the configuration information for the specified USART peripheral.
+ * @retval None
+ */
+void STM_EVAL_COMInit(COM_TypeDef COM, USART_InitTypeDef* USART_InitStruct)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+
+ /* Enable GPIO clock */
+ RCC_AHBPeriphClockCmd(COM_TX_PORT_CLK[COM] | COM_RX_PORT_CLK[COM], ENABLE);
+
+ /* Enable USART clock */
+ RCC_APB1PeriphClockCmd(COM_USART_CLK[COM], ENABLE);
+
+ /* Connect PXx to USARTx_Tx */
+ GPIO_PinAFConfig(COM_TX_PORT[COM], COM_TX_PIN_SOURCE[COM], COM_TX_AF[COM]);
+
+ /* Connect PXx to USARTx_Rx */
+ GPIO_PinAFConfig(COM_RX_PORT[COM], COM_RX_PIN_SOURCE[COM], COM_RX_AF[COM]);
+
+ /* Configure USART Tx as alternate function push-pull */
+ GPIO_InitStructure.GPIO_Pin = COM_TX_PIN[COM];
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
+ GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
+ GPIO_Init(COM_TX_PORT[COM], &GPIO_InitStructure);
+
+ /* Configure USART Rx as alternate function push-pull */
+ GPIO_InitStructure.GPIO_Pin = COM_RX_PIN[COM];
+ GPIO_Init(COM_RX_PORT[COM], &GPIO_InitStructure);
+
+ /* USART configuration */
+ USART_Init(COM_USART[COM], USART_InitStruct);
+
+ /* Enable USART */
+ USART_Cmd(COM_USART[COM], ENABLE);
+}
+
+/**
+ * @brief DeInitializes the SPI interface.
+ * @param None
+ * @retval None
+ */
+void SD_LowLevel_DeInit(void)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+
+ SPI_Cmd(SD_SPI, DISABLE); /*!< SD_SPI disable */
+ SPI_I2S_DeInit(SD_SPI); /*!< DeInitializes the SD_SPI */
+
+ /*!< SD_SPI Periph clock disable */
+ RCC_APB1PeriphClockCmd(SD_SPI_CLK, DISABLE);
+
+ /*!< Configure SD_SPI pins: SCK */
+ GPIO_InitStructure.GPIO_Pin = SD_SPI_SCK_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
+ GPIO_Init(SD_SPI_SCK_GPIO_PORT, &GPIO_InitStructure);
+
+ /*!< Configure SD_SPI pins: MISO */
+ GPIO_InitStructure.GPIO_Pin = SD_SPI_MISO_PIN;
+ GPIO_Init(SD_SPI_MISO_GPIO_PORT, &GPIO_InitStructure);
+
+ /*!< Configure SD_SPI pins: MOSI */
+ GPIO_InitStructure.GPIO_Pin = SD_SPI_MOSI_PIN;
+ GPIO_Init(SD_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure);
+
+ /*!< Configure SD_SPI_CS_PIN pin: SD Card CS pin */
+ GPIO_InitStructure.GPIO_Pin = SD_CS_PIN;
+ GPIO_Init(SD_CS_GPIO_PORT, &GPIO_InitStructure);
+
+ /*!< Configure SD_SPI_DETECT_PIN pin: SD Card detect pin */
+ GPIO_InitStructure.GPIO_Pin = SD_DETECT_PIN;
+ GPIO_Init(SD_DETECT_GPIO_PORT, &GPIO_InitStructure);
+}
+
+/**
+ * @brief Initializes the SD Card and put it into StandBy State (Ready for
+ * data transfer).
+ * @param None
+ * @retval None
+ */
+void SD_LowLevel_Init(void)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+ SPI_InitTypeDef SPI_InitStructure;
+
+ /*!< SD_SPI_CS_GPIO, SD_SPI_MOSI_GPIO, SD_SPI_MISO_GPIO, SD_SPI_DETECT_GPIO
+ and SD_SPI_SCK_GPIO Periph clock enable */
+ RCC_AHBPeriphClockCmd(SD_CS_GPIO_CLK | SD_SPI_MOSI_GPIO_CLK | SD_SPI_MISO_GPIO_CLK |
+ SD_SPI_SCK_GPIO_CLK | SD_DETECT_GPIO_CLK, ENABLE);
+
+ /*!< SD_SPI Periph clock enable */
+ RCC_APB1PeriphClockCmd(SD_SPI_CLK, ENABLE);
+
+ /*!< Configure SD_SPI pins: SCK */
+ GPIO_InitStructure.GPIO_Pin = SD_SPI_SCK_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
+ GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
+ GPIO_Init(SD_SPI_SCK_GPIO_PORT, &GPIO_InitStructure);
+
+ /*!< Configure SD_SPI pins: MISO */
+ GPIO_InitStructure.GPIO_Pin = SD_SPI_MISO_PIN;
+ GPIO_Init(SD_SPI_MISO_GPIO_PORT, &GPIO_InitStructure);
+
+ /*!< Configure SD_SPI pins: MOSI */
+ GPIO_InitStructure.GPIO_Pin = SD_SPI_MOSI_PIN;
+ GPIO_Init(SD_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure);
+
+ /*!< Configure SD_SPI_CS_PIN pin: SD Card CS pin */
+ GPIO_InitStructure.GPIO_Pin = SD_CS_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
+ GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
+ GPIO_Init(SD_CS_GPIO_PORT, &GPIO_InitStructure);
+
+ /*!< Configure SD_SPI_DETECT_PIN pin: SD Card detect pin */
+ GPIO_InitStructure.GPIO_Pin = SD_DETECT_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
+ GPIO_Init(SD_DETECT_GPIO_PORT, &GPIO_InitStructure);
+
+ /* Connect PXx to SD_SPI_SCK */
+ GPIO_PinAFConfig(SD_SPI_SCK_GPIO_PORT, SD_SPI_SCK_SOURCE, SD_SPI_SCK_AF);
+
+ /* Connect PXx to SD_SPI_MISO */
+ GPIO_PinAFConfig(SD_SPI_MISO_GPIO_PORT, SD_SPI_MISO_SOURCE, SD_SPI_MISO_AF);
+
+ /* Connect PXx to SD_SPI_MOSI */
+ GPIO_PinAFConfig(SD_SPI_MOSI_GPIO_PORT, SD_SPI_MOSI_SOURCE, SD_SPI_MOSI_AF);
+
+ /*!< SD_SPI Config */
+ SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
+ SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
+ SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
+ SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;
+ SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
+ SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
+ SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2;
+
+ SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
+ SPI_InitStructure.SPI_CRCPolynomial = 7;
+ SPI_Init(SD_SPI, &SPI_InitStructure);
+
+ SPI_RxFIFOThresholdConfig(SD_SPI, SPI_RxFIFOThreshold_QF);
+
+ SPI_Cmd(SD_SPI, ENABLE); /*!< SD_SPI enable */
+}
+
+/**
+ * @brief DeInitializes the LM75_I2C.
+ * @param None
+ * @retval None
+ */
+void LM75_LowLevel_DeInit(void)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+
+ /*!< Disable LM75_I2C */
+ I2C_Cmd(LM75_I2C, DISABLE);
+
+ /*!< DeInitializes the LM75_I2C */
+ I2C_DeInit(LM75_I2C);
+
+ /*!< LM75_I2C Periph clock disable */
+ RCC_APB1PeriphClockCmd(LM75_I2C_CLK, DISABLE);
+
+ /*!< Configure LM75_I2C pins: SCL */
+ GPIO_InitStructure.GPIO_Pin = LM75_I2C_SCL_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
+ GPIO_Init(LM75_I2C_SCL_GPIO_PORT, &GPIO_InitStructure);
+
+ /*!< Configure LM75_I2C pins: SDA */
+ GPIO_InitStructure.GPIO_Pin = LM75_I2C_SDA_PIN;
+ GPIO_Init(LM75_I2C_SDA_GPIO_PORT, &GPIO_InitStructure);
+
+ /*!< Configure LM75_I2C pin: SMBUS ALERT */
+ GPIO_InitStructure.GPIO_Pin = LM75_I2C_SMBUSALERT_PIN;
+ GPIO_Init(LM75_I2C_SMBUSALERT_GPIO_PORT, &GPIO_InitStructure);
+}
+
+
+/**
+ * @brief Initializes the LM75_I2C..
+ * @param None
+ * @retval None
+ */
+void LM75_LowLevel_Init(void)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+
+ /*!< LM75_I2C Periph clock enable */
+ RCC_APB1PeriphClockCmd(LM75_I2C_CLK, ENABLE);
+
+ /* Configure the I2C clock source. The clock is derived from the SYSCLK */
+ RCC_I2CCLKConfig(RCC_I2C2CLK_SYSCLK);
+
+ /*!< LM75_I2C_SCL_GPIO_CLK, LM75_I2C_SDA_GPIO_CLK
+ and LM75_I2C_SMBUSALERT_GPIO_CLK Periph clock enable */
+ RCC_AHBPeriphClockCmd(LM75_I2C_SCL_GPIO_CLK | LM75_I2C_SDA_GPIO_CLK |
+ LM75_I2C_SMBUSALERT_GPIO_CLK, ENABLE);
+
+ /* Connect PXx to I2C_SCL */
+ GPIO_PinAFConfig(LM75_I2C_SCL_GPIO_PORT, LM75_I2C_SCL_SOURCE, LM75_I2C_SCL_AF);
+
+ /* Connect PXx to I2C_SDA */
+ GPIO_PinAFConfig(LM75_I2C_SDA_GPIO_PORT, LM75_I2C_SDA_SOURCE, LM75_I2C_SDA_AF);
+
+ /* Connect PXx to I2C_SMBUSALER */
+ GPIO_PinAFConfig(LM75_I2C_SMBUSALERT_GPIO_PORT, LM75_I2C_SMBUSALERT_SOURCE, LM75_I2C_SMBUSALERT_AF);
+
+ /*!< Configure LM75_I2C pins: SCL */
+ GPIO_InitStructure.GPIO_Pin = LM75_I2C_SCL_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
+ GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
+ GPIO_Init(LM75_I2C_SCL_GPIO_PORT, &GPIO_InitStructure);
+
+ /*!< Configure LM75_I2C pins: SDA */
+ GPIO_InitStructure.GPIO_Pin = LM75_I2C_SDA_PIN;
+ GPIO_Init(LM75_I2C_SDA_GPIO_PORT, &GPIO_InitStructure);
+
+ /*!< Configure LM75_I2C pin: SMBUS ALERT */
+ GPIO_InitStructure.GPIO_Pin = LM75_I2C_SMBUSALERT_PIN;
+ GPIO_Init(LM75_I2C_SMBUSALERT_GPIO_PORT, &GPIO_InitStructure);
+}
+
+/**
+ * @brief DeInitializes peripherals used by the I2C EEPROM driver.
+ * @param None
+ * @retval None
+ */
+void sEE_I2C_LowLevel_DeInit(void)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+
+ /* sEE_I2C Peripheral Disable */
+ I2C_Cmd(sEE_I2C, DISABLE);
+
+ /* sEE_I2C DeInit */
+ I2C_DeInit(sEE_I2C);
+
+ /*!< sEE_I2C Periph clock disable */
+ RCC_APB1PeriphClockCmd(sEE_I2C_CLK, DISABLE);
+
+ /* Disable the I2C fast mode plus driving capability */
+ SYSCFG_I2CFastModePlusConfig(SYSCFG_I2CFastModePlus_I2C2, DISABLE);
+
+ /*!< GPIO configuration */
+ /*!< Configure sEE_I2C pins: SCL */
+ GPIO_InitStructure.GPIO_Pin = sEE_I2C_SCL_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
+ GPIO_Init(sEE_I2C_SCL_GPIO_PORT, &GPIO_InitStructure);
+
+ /*!< Configure sEE_I2C pins: SDA */
+ GPIO_InitStructure.GPIO_Pin = sEE_I2C_SDA_PIN;
+ GPIO_Init(sEE_I2C_SDA_GPIO_PORT, &GPIO_InitStructure);
+}
+
+/**
+ * @brief Initializes peripherals used by the I2C EEPROM driver.
+ * @param None
+ * @retval None
+ */
+void sEE_I2C_LowLevel_Init(void)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+
+ /* Configure the I2C clock source. The clock is derived from the SYSCLK */
+ RCC_I2CCLKConfig(RCC_I2C2CLK_SYSCLK);
+
+ /* Enable the I2C fast mode plus driving capability */
+ SYSCFG_I2CFastModePlusConfig(SYSCFG_I2CFastModePlus_I2C2, ENABLE);
+
+ /*!< sEE_I2C_SCL_GPIO_CLK and sEE_I2C_SDA_GPIO_CLK Periph clock enable */
+ RCC_AHBPeriphClockCmd(sEE_I2C_SCL_GPIO_CLK | sEE_I2C_SDA_GPIO_CLK, ENABLE);
+
+ /*!< sEE_I2C Periph clock enable */
+ RCC_APB1PeriphClockCmd(sEE_I2C_CLK, ENABLE);
+
+ /* Connect PXx to I2C_SCL*/
+ GPIO_PinAFConfig(sEE_I2C_SCL_GPIO_PORT, sEE_I2C_SCL_SOURCE, sEE_I2C_SCL_AF);
+
+ /* Connect PXx to I2C_SDA*/
+ GPIO_PinAFConfig(sEE_I2C_SDA_GPIO_PORT, sEE_I2C_SDA_SOURCE, sEE_I2C_SDA_AF);
+
+ /*!< GPIO configuration */
+ /*!< Configure sEE_I2C pins: SCL */
+ GPIO_InitStructure.GPIO_Pin = sEE_I2C_SCL_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
+ GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
+ GPIO_Init(sEE_I2C_SCL_GPIO_PORT, &GPIO_InitStructure);
+
+ /*!< Configure sEE_I2C pins: SDA */
+ GPIO_InitStructure.GPIO_Pin = sEE_I2C_SDA_PIN;
+ GPIO_Init(sEE_I2C_SDA_GPIO_PORT, &GPIO_InitStructure);
+}
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32373C_EVAL/stm32373c_eval.h b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32373C_EVAL/stm32373c_eval.h
new file mode 100644
index 0000000..335482b
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32373C_EVAL/stm32373c_eval.h
@@ -0,0 +1,409 @@
+/**
+ ******************************************************************************
+ * @file stm32373c_eval.h
+ * @author MCD Application Team
+ * @version V1.0.0
+ * @date 20-September-2012
+ * @brief This file contains definitions for STM32373C_EVAL's Leds, push-buttons
+ * and COM ports hardware resources.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.st.com/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __STM32373C_EVAL_H
+#define __STM32373C_EVAL_H
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+/* Includes ------------------------------------------------------------------*/
+#include "stm32f37x.h"
+#include "stm32_eval_legacy.h"
+
+/** @addtogroup Utilities
+ * @{
+ */
+
+/** @addtogroup STM32_EVAL
+ * @{
+ */
+
+/** @addtogroup STM32373C_EVAL
+ * @{
+ */
+
+/** @addtogroup STM32373C_EVAL_LOW_LEVEL
+ * @{
+ */
+
+/** @defgroup STM32373C_EVAL_LOW_LEVEL_Exported_Types
+ * @{
+ */
+typedef enum
+{
+ LED1 = 0,
+ LED2 = 1,
+ LED3 = 2,
+ LED4 = 3
+} Led_TypeDef;
+
+typedef enum
+{
+ BUTTON_WAKEUP = 0,
+ BUTTON_TAMPER = 1,
+ BUTTON_KEY = 2,
+ BUTTON_RIGHT = 3,
+ BUTTON_LEFT = 4,
+ BUTTON_UP = 5,
+ BUTTON_DOWN = 6,
+ BUTTON_SEL = 7
+} Button_TypeDef;
+
+typedef enum
+{
+ BUTTON_MODE_GPIO = 0,
+ BUTTON_MODE_EXTI = 1
+} ButtonMode_TypeDef;
+
+typedef enum
+{
+ JOY_NONE = 0,
+ JOY_SEL = 1,
+ JOY_DOWN = 2,
+ JOY_LEFT = 3,
+ JOY_RIGHT = 4,
+ JOY_UP = 5
+} JOYState_TypeDef
+;
+
+typedef enum
+{
+ COM1 = 0,
+ COM2 = 1
+} COM_TypeDef;
+/**
+ * @}
+ */
+
+/** @defgroup STM32373C_EVAL_LOW_LEVEL_Exported_Constants
+ * @{
+ */
+
+/**
+ * @brief Define for STM32373C_EVAL board
+ */
+#if !defined (USE_STM32373C_EVAL)
+ #define USE_STM32373C_EVAL
+#endif
+
+/** @addtogroup STM32373C_EVAL_LOW_LEVEL_LED
+ * @{
+ */
+#define LEDn 4
+
+#define LED1_PIN GPIO_Pin_0
+#define LED1_GPIO_PORT GPIOC
+#define LED1_GPIO_CLK RCC_AHBPeriph_GPIOC
+
+#define LED2_PIN GPIO_Pin_1
+#define LED2_GPIO_PORT GPIOC
+#define LED2_GPIO_CLK RCC_AHBPeriph_GPIOC
+
+#define LED3_PIN GPIO_Pin_2
+#define LED3_GPIO_PORT GPIOC
+#define LED3_GPIO_CLK RCC_AHBPeriph_GPIOC
+
+#define LED4_PIN GPIO_Pin_3
+#define LED4_GPIO_PORT GPIOC
+#define LED4_GPIO_CLK RCC_AHBPeriph_GPIOC
+
+/**
+ * @}
+ */
+
+/** @addtogroup STM32373C_EVAL_LOW_LEVEL_BUTTON
+ * @{
+ */
+#define BUTTONn 7
+
+/**
+ * @brief Tamper push-button
+ */
+#define TAMPER_BUTTON_PIN GPIO_Pin_0
+#define TAMPER_BUTTON_GPIO_PORT GPIOA
+#define TAMPER_BUTTON_GPIO_CLK RCC_AHBPeriph_GPIOA
+#define TAMPER_BUTTON_EXTI_LINE EXTI_Line0
+#define TAMPER_BUTTON_EXTI_PORT_SOURCE EXTI_PortSourceGPIOA
+#define TAMPER_BUTTON_EXTI_PIN_SOURCE EXTI_PinSource0
+#define TAMPER_BUTTON_EXTI_IRQn EXTI0_IRQn
+/**
+ * @brief Key push-button
+ */
+#define KEY_BUTTON_PIN GPIO_Pin_2
+#define KEY_BUTTON_GPIO_PORT GPIOA
+#define KEY_BUTTON_GPIO_CLK RCC_AHBPeriph_GPIOA
+#define KEY_BUTTON_EXTI_LINE EXTI_Line2
+#define KEY_BUTTON_EXTI_PORT_SOURCE EXTI_PortSourceGPIOA
+#define KEY_BUTTON_EXTI_PIN_SOURCE EXTI_PinSource2
+#define KEY_BUTTON_EXTI_IRQn EXTI2_TS_IRQn
+
+/**
+ * @brief Joystick Right push-button
+ */
+#define RIGHT_BUTTON_PIN GPIO_Pin_9
+#define RIGHT_BUTTON_GPIO_PORT GPIOF
+#define RIGHT_BUTTON_GPIO_CLK RCC_AHBPeriph_GPIOF
+#define RIGHT_BUTTON_EXTI_LINE EXTI_Line9
+#define RIGHT_BUTTON_EXTI_PORT_SOURCE EXTI_PortSourceGPIOF
+#define RIGHT_BUTTON_EXTI_PIN_SOURCE EXTI_PinSource9
+#define RIGHT_BUTTON_EXTI_IRQn EXTI9_5_IRQn
+
+/**
+ * @brief Joystick Left push-button
+ */
+#define LEFT_BUTTON_PIN GPIO_Pin_4
+#define LEFT_BUTTON_GPIO_PORT GPIOF
+#define LEFT_BUTTON_GPIO_CLK RCC_AHBPeriph_GPIOF
+#define LEFT_BUTTON_EXTI_LINE EXTI_Line4
+#define LEFT_BUTTON_EXTI_PORT_SOURCE EXTI_PortSourceGPIOF
+#define LEFT_BUTTON_EXTI_PIN_SOURCE EXTI_PinSource4
+#define LEFT_BUTTON_EXTI_IRQn EXTI4_IRQn
+
+/**
+ * @brief Joystick Up push-button
+ */
+#define UP_BUTTON_PIN GPIO_Pin_10
+#define UP_BUTTON_GPIO_PORT GPIOF
+#define UP_BUTTON_GPIO_CLK RCC_AHBPeriph_GPIOF
+#define UP_BUTTON_EXTI_LINE EXTI_Line10
+#define UP_BUTTON_EXTI_PORT_SOURCE EXTI_PortSourceGPIOF
+#define UP_BUTTON_EXTI_PIN_SOURCE EXTI_PinSource10
+#define UP_BUTTON_EXTI_IRQn EXTI15_10_IRQn
+
+/**
+ * @brief Joystick Down push-button
+ */
+#define DOWN_BUTTON_PIN GPIO_Pin_2
+#define DOWN_BUTTON_GPIO_PORT GPIOF
+#define DOWN_BUTTON_GPIO_CLK RCC_AHBPeriph_GPIOF
+#define DOWN_BUTTON_EXTI_LINE EXTI_Line2
+#define DOWN_BUTTON_EXTI_PORT_SOURCE EXTI_PortSourceGPIOF
+#define DOWN_BUTTON_EXTI_PIN_SOURCE EXTI_PinSource2
+#define DOWN_BUTTON_EXTI_IRQn EXTI2_TS_IRQn
+
+/**
+ * @brief Joystick Sel push-button
+ */
+#define SEL_BUTTON_PIN GPIO_Pin_6
+#define SEL_BUTTON_GPIO_PORT GPIOE
+#define SEL_BUTTON_GPIO_CLK RCC_AHBPeriph_GPIOE
+#define SEL_BUTTON_EXTI_LINE EXTI_Line6
+#define SEL_BUTTON_EXTI_PORT_SOURCE EXTI_PortSourceGPIOE
+#define SEL_BUTTON_EXTI_PIN_SOURCE EXTI_PinSource6
+#define SEL_BUTTON_EXTI_IRQn EXTI9_5_IRQn
+
+/**
+ * @}
+ */
+
+
+/** @addtogroup STM32373C_EVAL_LOW_LEVEL_COM
+ * @{
+ */
+#define COMn 1
+
+/**
+ * @brief Definition for COM port1, connected to USART2
+ */
+#define EVAL_COM1 USART2
+#define EVAL_COM1_CLK RCC_APB1Periph_USART2
+
+#define EVAL_COM1_TX_PIN GPIO_Pin_5
+#define EVAL_COM1_TX_GPIO_PORT GPIOD
+#define EVAL_COM1_TX_GPIO_CLK RCC_AHBPeriph_GPIOD
+#define EVAL_COM1_TX_SOURCE GPIO_PinSource5
+#define EVAL_COM1_TX_AF GPIO_AF_7
+
+#define EVAL_COM1_RX_PIN GPIO_Pin_6
+#define EVAL_COM1_RX_GPIO_PORT GPIOD
+#define EVAL_COM1_RX_GPIO_CLK RCC_AHBPeriph_GPIOD
+#define EVAL_COM1_RX_SOURCE GPIO_PinSource6
+#define EVAL_COM1_RX_AF GPIO_AF_7
+
+#define EVAL_COM1_CTS_PIN GPIO_Pin_3
+#define EVAL_COM1_CTS_GPIO_PORT GPIOD
+#define EVAL_COM1_CTS_GPIO_CLK RCC_AHBPeriph_GPIOD
+#define EVAL_COM1_CTS_SOURCE GPIO_PinSource3
+#define EVAL_COM1_CTS_AF GPIO_AF_7
+
+#define EVAL_COM1_RTS_PIN GPIO_Pin_4
+#define EVAL_COM1_RTS_GPIO_PORT GPIOD
+#define EVAL_COM1_RTS_GPIO_CLK RCC_AHBPeriph_GPIOD
+#define EVAL_COM1_RTS_SOURCE GPIO_PinSource4
+#define EVAL_COM1_RTS_AF GPIO_AF_7
+
+#define EVAL_COM1_IRQn USART2_IRQn
+
+
+/**
+ * @}
+ */
+
+/** @addtogroup STM32373C_EVAL_LOW_LEVEL_SD_SPI
+ * @{
+ */
+/**
+ * @brief SD SPI Interface pins
+ */
+#define SD_SPI SPI3
+#define SD_SPI_CLK RCC_APB1Periph_SPI3
+#define SD_SPI_SCK_PIN GPIO_Pin_10 /* PC.10 */
+#define SD_SPI_SCK_GPIO_PORT GPIOC /* GPIOC */
+#define SD_SPI_SCK_GPIO_CLK RCC_AHBPeriph_GPIOC
+#define SD_SPI_SCK_SOURCE GPIO_PinSource10
+#define SD_SPI_SCK_AF GPIO_AF_6
+
+#define SD_SPI_MISO_PIN GPIO_Pin_11 /* PC.11 */
+#define SD_SPI_MISO_GPIO_PORT GPIOC /* GPIOC */
+#define SD_SPI_MISO_GPIO_CLK RCC_AHBPeriph_GPIOC
+#define SD_SPI_MISO_SOURCE GPIO_PinSource11
+#define SD_SPI_MISO_AF GPIO_AF_6
+
+#define SD_SPI_MOSI_PIN GPIO_Pin_12 /* PC.12 */
+#define SD_SPI_MOSI_GPIO_PORT GPIOC /* GPIOC */
+#define SD_SPI_MOSI_GPIO_CLK RCC_AHBPeriph_GPIOC
+#define SD_SPI_MOSI_SOURCE GPIO_PinSource12
+#define SD_SPI_MOSI_AF GPIO_AF_6
+
+#define SD_CS_PIN GPIO_Pin_2 /* PE.02 */
+#define SD_CS_GPIO_PORT GPIOE /* GPIOE */
+#define SD_CS_GPIO_CLK RCC_AHBPeriph_GPIOE
+
+
+#define SD_DETECT_PIN GPIO_Pin_3 /* PE.03 */
+#define SD_DETECT_EXTI_LINE EXTI_Line3
+#define SD_DETECT_EXTI_PIN_SOURCE EXTI_PinSource3
+#define SD_DETECT_GPIO_PORT GPIOE /* GPIOE */
+#define SD_DETECT_GPIO_CLK RCC_AHBPeriph_GPIOE
+#define SD_DETECT_EXTI_PORT_SOURCE EXTI_PortSourceGPIOE
+#define SD_DETECT_EXTI_IRQn EXTI3_IRQn
+
+/**
+ * @}
+ */
+
+/** @addtogroup STM32373C_EVAL_LOW_LEVEL_TSENSOR_I2C
+ * @{
+ */
+/**
+ * @brief LM75 Temperature Sensor I2C Interface pins
+ */
+#define LM75_I2C I2C2
+#define LM75_I2C_CLK RCC_APB1Periph_I2C2
+
+#define LM75_I2C_SCL_PIN GPIO_Pin_9 /* PA.09 */
+#define LM75_I2C_SCL_GPIO_PORT GPIOA /* GPIOA */
+#define LM75_I2C_SCL_GPIO_CLK RCC_AHBPeriph_GPIOA
+#define LM75_I2C_SCL_SOURCE GPIO_PinSource9
+#define LM75_I2C_SCL_AF GPIO_AF_4
+
+#define LM75_I2C_SDA_PIN GPIO_Pin_10 /* PA.10 */
+#define LM75_I2C_SDA_GPIO_PORT GPIOA /* GPIOA */
+#define LM75_I2C_SDA_GPIO_CLK RCC_AHBPeriph_GPIOA
+#define LM75_I2C_SDA_SOURCE GPIO_PinSource10
+#define LM75_I2C_SDA_AF GPIO_AF_4
+
+#define LM75_I2C_SMBUSALERT_PIN GPIO_Pin_8 /* PA.08 */
+#define LM75_I2C_SMBUSALERT_GPIO_PORT GPIOA /* GPIOA */
+#define LM75_I2C_SMBUSALERT_GPIO_CLK RCC_AHBPeriph_GPIOA
+#define LM75_I2C_SMBUSALERT_SOURCE GPIO_PinSource8
+#define LM75_I2C_SMBUSALERT_AF GPIO_AF_4
+/**
+ * @}
+ */
+
+/** @addtogroup STM32373C_EVAL_LOW_LEVEL_I2C_EE
+ * @{
+ */
+/**
+ * @brief I2C EEPROM Interface pins
+ */
+#define sEE_I2C I2C2
+#define sEE_I2C_CLK RCC_APB1Periph_I2C2
+
+#define sEE_I2C_SCL_PIN GPIO_Pin_9 /* PA.09 */
+#define sEE_I2C_SCL_GPIO_PORT GPIOA /* GPIOA */
+#define sEE_I2C_SCL_GPIO_CLK RCC_AHBPeriph_GPIOA
+#define sEE_I2C_SCL_SOURCE GPIO_PinSource9
+#define sEE_I2C_SCL_AF GPIO_AF_4
+
+#define sEE_I2C_SDA_PIN GPIO_Pin_10 /* PA.10 */
+#define sEE_I2C_SDA_GPIO_PORT GPIOA /* GPIOA */
+#define sEE_I2C_SDA_GPIO_CLK RCC_AHBPeriph_GPIOA
+#define sEE_I2C_SDA_SOURCE GPIO_PinSource10
+#define sEE_I2C_SDA_AF GPIO_AF_4
+
+/**
+ * @}
+ */
+
+/** @defgroup STM32373C_EVAL_LOW_LEVEL_Exported_Functions
+ * @{
+ */
+void STM_EVAL_LEDInit(Led_TypeDef Led);
+void STM_EVAL_LEDOn(Led_TypeDef Led);
+void STM_EVAL_LEDOff(Led_TypeDef Led);
+void STM_EVAL_LEDToggle(Led_TypeDef Led);
+void STM_EVAL_PBInit(Button_TypeDef Button, ButtonMode_TypeDef Button_Mode);
+uint32_t STM_EVAL_PBGetState(Button_TypeDef Button);
+void STM_EVAL_COMInit(COM_TypeDef COM, USART_InitTypeDef* USART_InitStruct);
+void SD_LowLevel_DeInit(void);
+void SD_LowLevel_Init(void);
+void LM75_LowLevel_DeInit(void);
+void LM75_LowLevel_Init(void);
+void sEE_I2C_LowLevel_DeInit(void);
+void sEE_I2C_LowLevel_Init(void);
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __STM32373C_EVAL_H */
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32373C_EVAL/stm32373c_eval_audio_codec.c b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32373C_EVAL/stm32373c_eval_audio_codec.c
new file mode 100644
index 0000000..351a4b5
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32373C_EVAL/stm32373c_eval_audio_codec.c
@@ -0,0 +1,1405 @@
+/**
+ ******************************************************************************
+ * @file stm32373c_eval_audio_codec.c
+ * @author MCD Application Team
+ * @version V1.0.0
+ * @date 20-September-2012
+ * @brief This file includes the low layer driver for CS43L22 Audio Codec
+ * available on STM32373C_EVAL evaluation board(MB988).
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.st.com/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+
+/*==============================================================================================================================
+ User NOTES
+1. How To use this driver:
+--------------------------
+ - This driver supports STM32F37x devices on STM32373C_EVAL (MB988) Evaluation boards.
+
+ - Configure the options in file stm32373c_eval_audio_codec.h in the section CONFIGURATION.
+ Refer to the sections 2 and 3 to have more details on the possible configurations.
+
+ - Call the function EVAL_AUDIO_Init(
+ OutputDevice: physical output mode (OUTPUT_DEVICE_SPEAKER,
+ OUTPUT_DEVICE_HEADPHONE, OUTPUT_DEVICE_AUTO or
+ OUTPUT_DEVICE_BOTH)
+ Volume: initial volume to be set (0 is min (mute), 100 is max (100%)
+ AudioFreq: Audio frequency in Hz (8000, 16000, 22500, 32000 ...)
+ this parameter is relative to the audio file/stream type.
+ )
+ This function configures all the hardware required for the audio application (codec, I2C, I2S,
+ GPIOs, DMA and interrupt if needed). This function returns 0 if configuration is OK.
+ if the returned value is different from 0 or the function is stuck then the communication with
+ the codec has failed (try to un-plug the power or reset device in this case).
+ + OUTPUT_DEVICE_SPEAKER: only speaker will be set as output for the audio stream.
+ + OUTPUT_DEVICE_HEADPHONE: only headphones will be set as output for the audio stream.
+ + OUTPUT_DEVICE_AUTO: Selection of output device is made through external switch (implemented
+ into the audio jack on the evaluation board). When the Headphone is connected it is used
+ as output. When the headphone is disconnected from the audio jack, the output is
+ automatically switched to Speaker.
+ + OUTPUT_DEVICE_BOTH: both Speaker and Headphone are used as outputs for the audio stream
+ at the same time.
+
+ - Call the function EVAL_AUDIO_Play(
+ pBuffer: pointer to the audio data file address
+ Size: size of the buffer to be sent in Bytes
+ )
+ to start playing (for the first time) from the audio file/stream.
+
+ - Call the function EVAL_AUDIO_PauseResume(
+ Cmd: AUDIO_PAUSE (or 0) to pause playing or AUDIO_RESUME (or
+ any value different from 0) to resume playing.
+ )
+ Note. After calling EVAL_AUDIO_PauseResume() function for pause, only EVAL_AUDIO_PauseResume() should be called
+ for resume (it is not allowed to call EVAL_AUDIO_Play() in this case).
+ Note. This function should be called only when the audio file is played or paused (not stopped).
+
+ - For each mode, you may need to implement the relative callback functions into your code.
+ The Callback functions are named EVAL_AUDIO_XXX_CallBack() and only their prototypes are declared in
+ the stm32373c_eval_audio_codec.h file. (refer to the example for more details on the callbacks implementations)
+
+ - To Stop playing, to modify the volume level or to mute, use the functions
+ EVAL_AUDIO_Stop(), EVAL_AUDIO_VolumeCtl() and EVAL_AUDIO_Mute().
+
+ - The driver API and the callback functions are at the end of the stm32373c_eval_audio_codec.h file.
+
+
+ Driver architecture:
+ --------------------
+ This driver is composed of three main layers:
+ o High Audio Layer: consists of the function API exported in the stm32373c_eval_audio_codec.h file
+ (EVAL_AUDIO_Init(), EVAL_AUDIO_Play() ...)
+ o Codec Control layer: consists of the functions API controlling the audio codec (CS43L22) and
+ included as local functions in file stm32373c_eval_audio_codec.c (Codec_Init(), Codec_Play() ...)
+ o Media Access Layer (MAL): which consists of functions allowing to access the media containing/
+ providing the audio file/stream. These functions are also included as local functions into
+ the stm32373c_eval_audio_codec.c file (Audio_MAL_Init(), Audio_MAL_Play() ...)
+ Each set of functions (layer) may be implemented independently of the others and customized when
+ needed.
+
+2. Modes description:
+---------------------
+ + AUDIO_MAL_MODE_NORMAL : is suitable when the audio file is in a memory location.
+ + AUDIO_MAL_MODE_CIRCULAR: is suitable when the audio data are read either from a
+ memory location or from a device at real time (double buffer could be used).
+
+3. DMA interrupts description:
+------------------------------
+ + EVAL_AUDIO_IT_TC_ENABLE: Enable this define to use the DMA end of transfer interrupt.
+ then, a callback should be implemented by user to perform specific actions
+ when the DMA has finished the transfer.
+ + EVAL_AUDIO_IT_HT_ENABLE: Enable this define to use the DMA end of half transfer interrupt.
+ then, a callback should be implemented by user to perform specific actions
+ when the DMA has reached the half of the buffer transfer (generally, it is useful
+ to load the first half of buffer while DMA is loading from the second half).
+ + EVAL_AUDIO_IT_ER_ENABLE: Enable this define to manage the cases of error on DMA transfer.
+
+4. Known Limitations:
+---------------------
+ 1- When using the Speaker, if the audio file quality is not high enough, the speaker output
+ may produce high and uncomfortable noise level. To avoid this issue, to use speaker
+ output properly, try to increase audio file sampling rate (typically higher than 48KHz).
+ This operation will lead to larger file size.
+ 2- Communication with the audio codec (through I2C) may be corrupted if it is interrupted by some
+ user interrupt routines (in this case, interrupts could be disabled just before the start of
+ communication then re-enabled when it is over). Note that this communication is only done at
+ the configuration phase (EVAL_AUDIO_Init() or EVAL_AUDIO_Stop()) and when Volume control modification is
+ performed (EVAL_AUDIO_VolumeCtl() or EVAL_AUDIO_Mute()). When the audio data is played, no communication is
+ required with the audio codec.
+ 3- Parsing of audio file is not implemented (in order to determine audio file properties: Mono/Stereo, Data size,
+ File size, Audio Frequency, Audio Data header size ...). The configuration is fixed for the given audio file.
+ 4- Mono audio streaming is not supported (in order to play mono audio streams, each data should be sent twice
+ on the I2S or should be duplicated on the source buffer. Or convert the stream in stereo before playing).
+ 5- Supports only 16-bit audio data size.
+===============================================================================================================================*/
+
+
+/* Includes ------------------------------------------------------------------*/
+#include "stm32373c_eval_audio_codec.h"
+
+/** @addtogroup Utilities
+ * @{
+ */
+
+/** @addtogroup STM32_EVAL
+ * @{
+ */
+
+/** @addtogroup STM32373C_EVAL
+ * @{
+ */
+
+/** @addtogroup STM32373C_EVAL_AUDIO_CODEC
+ * @brief This file includes the low layer driver for CS43L22 Audio Codec
+ * available on STM32373C_EVAL evaluation board(MB988).
+ * @{
+ */
+
+/** @defgroup STM32373C_EVAL_AUDIO_CODEC_Private_Types
+ * @{
+ */
+/**
+ * @}
+ */
+
+/** @defgroup STM32373C_EVAL_AUDIO_CODEC_Private_Defines
+ * @{
+ */
+
+/* Mask for the bit EN of the I2S CFGR register */
+#define I2S_ENABLE_MASK 0x0400
+
+/* Delay for the Codec to be correctly reset */
+#define CODEC_RESET_DELAY 0x4FFF
+
+/* Codec audio Standards */
+#ifdef I2S_STANDARD_PHILLIPS
+ #define CODEC_STANDARD 0x04
+ #define I2S_STANDARD I2S_Standard_Phillips
+#elif defined(I2S_STANDARD_MSB)
+ #define CODEC_STANDARD 0x00
+ #define I2S_STANDARD I2S_Standard_MSB
+#elif defined(I2S_STANDARD_LSB)
+ #define CODEC_STANDARD 0x08
+ #define I2S_STANDARD I2S_Standard_LSB
+#else
+ #error "Error: No audio communication standard selected !"
+#endif /* I2S_STANDARD */
+
+/* The 7 bits Codec address (sent through I2C interface) */
+#define CODEC_ADDRESS 0x94 /* b00100111 */
+/**
+ * @}
+ */
+
+/** @defgroup STM32373C_EVAL_AUDIO_CODEC_Private_Macros
+ * @{
+ */
+/**
+ * @}
+ */
+
+/** @defgroup STM32373C_EVAL_AUDIO_CODEC_Private_Variables
+ * @{
+ */
+/* This structure is declared global because it is handled by two different functions */
+DMA_InitTypeDef DMA_InitStructure;
+DMA_InitTypeDef AUDIO_MAL_DMA_InitStructure;
+
+uint32_t AudioTotalSize = 0xFFFF; /* This variable holds the total size of the audio file */
+uint32_t AudioRemSize = 0xFFFF; /* This variable holds the remaining data in audio file */
+uint16_t *CurrentPos; /* This variable holds the current position of audio pointer */
+
+__IO uint32_t CODECTimeout = CODEC_LONG_TIMEOUT;
+__IO uint8_t OutputDev = 0;
+
+/**
+ * @}
+ */
+
+/** @defgroup STM32373C_EVAL_AUDIO_CODEC_Private_Function_Prototypes
+ * @{
+ */
+/**
+ * @}
+ */
+
+/** @defgroup STM32373C_EVAL_AUDIO_CODEC_Private_Functions
+ * @{
+ */
+
+/*----------------------------------------------------------------------------
+ Audio Codec functions
+ ----------------------------------------------------------------------------*/
+/* High Layer codec functions */
+static uint32_t Codec_Init(uint16_t OutputDevice, uint8_t Volume, uint32_t AudioFreq);
+static uint32_t Codec_DeInit(void);
+static uint32_t Codec_Play(void);
+static uint32_t Codec_PauseResume(uint32_t Cmd);
+static uint32_t Codec_Stop(uint32_t Cmd);
+static uint32_t Codec_VolumeCtrl(uint8_t Volume);
+static uint32_t Codec_Mute(uint32_t Cmd);
+/* Low layer codec functions */
+static void Codec_CtrlInterface_Init(void);
+static void Codec_CtrlInterface_DeInit(void);
+static void Codec_AudioInterface_Init(uint32_t AudioFreq);
+static void Codec_AudioInterface_DeInit(void);
+static void Codec_Reset(void);
+static uint32_t Codec_WriteRegister(uint8_t RegisterAddr, uint8_t RegisterValue);
+static uint32_t Codec_ReadRegister(uint8_t RegisterAddr);
+static void Codec_GPIO_Init(void);
+static void Codec_GPIO_DeInit(void);
+static void Delay(__IO uint32_t nCount);
+/*----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+ MAL (Media Access Layer) functions
+ ----------------------------------------------------------------------------*/
+/* Peripherals configuration functions */
+static void Audio_MAL_Init(void);
+static void Audio_MAL_DeInit(void);
+static void Audio_MAL_PauseResume(uint32_t Cmd, uint32_t Addr);
+static void Audio_MAL_Stop(void);
+/*----------------------------------------------------------------------------*/
+
+/**
+ * @brief Configure the audio peripherals.
+ * @param OutputDevice: OUTPUT_DEVICE_SPEAKER, OUTPUT_DEVICE_HEADPHONE,
+ * OUTPUT_DEVICE_BOTH or OUTPUT_DEVICE_AUTO .
+ * @param Volume: Initial volume level (from 0 (Mute) to 100 (Max))
+ * @param AudioFreq: Audio frequency used to play the audio stream.
+ * @retval 0 if correct communication, else wrong communication
+ */
+uint32_t EVAL_AUDIO_Init(uint16_t OutputDevice, uint8_t Volume, uint32_t AudioFreq)
+{
+ /* Perform low layer Codec initialization */
+ if (Codec_Init(OutputDevice, VOLUME_CONVERT(Volume), AudioFreq) != 0)
+ {
+ return 1;
+ }
+ else
+ {
+ /* I2S data transfer preparation:
+ Prepare the Media to be used for the audio transfer from memory to I2S peripheral */
+ Audio_MAL_Init();
+
+ /* Return 0 when all operations are OK */
+ return 0;
+ }
+}
+
+/**
+ * @brief Deinitializes all the resources used by the codec (those initialized
+ * by EVAL_AUDIO_Init() function) EXCEPT the I2C resources since they are
+ * used by the IOExpander as well (and eventually other modules).
+ * @param None
+ * @retval 0 if correct communication, else wrong communication
+ */
+uint32_t EVAL_AUDIO_DeInit(void)
+{
+ /* DeInitialize the Media layer */
+ Audio_MAL_DeInit();
+
+ /* DeInitialize Codec */
+ Codec_DeInit();
+
+ return 0;
+}
+
+/**
+ * @brief Starts playing audio stream from a data buffer for a determined size.
+ * @param pBuffer: Pointer to the buffer
+ * @param Size: Number of audio data BYTES.
+ * @retval 0 if correct communication, else wrong communication
+ */
+uint32_t EVAL_AUDIO_Play(uint16_t* pBuffer, uint32_t Size)
+{
+ /* Set the total number of data to be played (count in half-word) */
+ AudioTotalSize = Size/2;
+
+ /* Call the audio Codec Play function */
+ Codec_Play();
+
+ /* Update the Media layer and enable it for play */
+ Audio_MAL_Play((uint32_t)pBuffer, (uint32_t)(DMA_MAX(AudioTotalSize / 2)));
+
+ /* Update the remaining number of data to be played */
+ AudioRemSize = (Size/2) - DMA_MAX(AudioTotalSize);
+
+ /* Update the current audio pointer position */
+ CurrentPos = pBuffer + DMA_MAX(AudioTotalSize);
+
+ return 0;
+}
+
+/**
+ * @brief This function Pauses or Resumes the audio file stream. In case
+ * of using DMA, the DMA Pause feature is used. In all cases the I2S
+ * peripheral is disabled.
+ *
+ * @WARNING When calling EVAL_AUDIO_PauseResume() function for pause, only
+ * this function should be called for resume (use of EVAL_AUDIO_Play()
+ * function for resume could lead to unexpected behavior).
+ *
+ * @param Cmd: AUDIO_PAUSE (or 0) to pause, AUDIO_RESUME (or any value different
+ * from 0) to resume.
+ * @retval 0 if correct communication, else wrong communication
+ */
+uint32_t EVAL_AUDIO_PauseResume(uint32_t Cmd)
+{
+ /* Call the Audio Codec Pause/Resume function */
+ if (Codec_PauseResume(Cmd) != 0)
+ {
+ return 1;
+ }
+ else
+ {
+ /* Call the Media layer pause/resume function */
+ Audio_MAL_PauseResume(Cmd, 0);
+
+ /* Return 0 if all operations are OK */
+ return 0;
+ }
+}
+
+/**
+ * @brief Stops audio playing and Power down the Audio Codec.
+ * @param Option: could be one of the following parameters
+ * - CODEC_PDWN_SW: for software power off (by writing registers).
+ * Then no need to reconfigure the Codec after power on.
+ * - CODEC_PDWN_HW: completely shut down the codec (physically).
+ * Then need to reconfigure the Codec after power on.
+ * @retval 0 if correct communication, else wrong communication
+ */
+uint32_t EVAL_AUDIO_Stop(uint32_t Option)
+{
+ /* Call Audio Codec Stop function */
+ if (Codec_Stop(Option) != 0)
+ {
+ return 1;
+ }
+ else
+ {
+ /* Call Media layer Stop function */
+ Audio_MAL_Stop();
+
+ /* Update the remaining data number */
+ AudioRemSize = AudioTotalSize;
+
+ /* Return 0 when all operations are correctly done */
+ return 0;
+ }
+}
+
+/**
+ * @brief Controls the current audio volume level.
+ * @param Volume: Volume level to be set in percentage from 0% to 100% (0 for
+ * Mute and 100 for Max volume level).
+ * @retval 0 if correct communication, else wrong communication
+ */
+uint32_t EVAL_AUDIO_VolumeCtl(uint8_t Volume)
+{
+ /* Call the codec volume control function with converted volume value */
+ return (Codec_VolumeCtrl(VOLUME_CONVERT(Volume)));
+}
+
+/**
+ * @brief Enables or disables the MUTE mode by software
+ * @param Command: could be AUDIO_MUTE_ON to mute sound or AUDIO_MUTE_OFF to
+ * unmute the codec and restore previous volume level.
+ * @retval 0 if correct communication, else wrong communication
+ */
+uint32_t EVAL_AUDIO_Mute(uint32_t Cmd)
+{
+ /* Call the Codec Mute function */
+ return (Codec_Mute(Cmd));
+}
+
+/**
+ * @brief This function handles main Media layer interrupt.
+ * @param None
+ * @retval 0 if correct communication, else wrong communication
+ */
+void Audio_MAL_IRQHandler(void)
+{
+#ifndef AUDIO_MAL_MODE_NORMAL
+ uint16_t *pAddr = (uint16_t *)CurrentPos;
+ uint32_t Size = AudioRemSize;
+#endif /* AUDIO_MAL_MODE_NORMAL */
+
+#ifdef AUDIO_MAL_DMA_IT_TC_EN
+ /* Transfer complete interrupt */
+ if (DMA_GetFlagStatus(AUDIO_MAL_DMA_FLAG_TC) != RESET)
+ {
+ #ifdef AUDIO_MAL_MODE_NORMAL
+ /* Check if the end of file has been reached */
+ if (AudioRemSize > 0)
+ {
+ /* Wait the DMA Channel to be effectively disabled */
+ while (DMA_GetFlagStatus(AUDIO_MAL_DMA_FLAG_TC) != SET)
+ {}
+
+ /* Clear the Interrupt flag */
+ DMA_ClearFlag(AUDIO_MAL_DMA_FLAG_TC);
+
+ /* Re-Configure the buffer address and size */
+ DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t) CurrentPos;
+ DMA_InitStructure.DMA_BufferSize = (uint32_t) (DMA_MAX(AudioRemSize));
+
+ /* Configure the DMA Channel with the new parameters */
+ DMA_Init(AUDIO_MAL_DMA_CHANNEL , &DMA_InitStructure);
+
+ /* Enable the I2S DMA Channel */
+ DMA_Cmd(AUDIO_MAL_DMA_CHANNEL , ENABLE);
+
+ /* Update the current pointer position */
+ CurrentPos += DMA_MAX(AudioRemSize);
+
+ /* Update the remaining number of data to be played */
+ AudioRemSize -= DMA_MAX(AudioRemSize);
+ }
+ else
+ {
+ /* Disable the I2S DMA Channel */
+ DMA_Cmd(AUDIO_MAL_DMA_CHANNEL , DISABLE);
+
+ /* Clear the Interrupt flag */
+ DMA_ClearFlag(AUDIO_MAL_DMA_FLAG_TC);
+
+ /* Manage the remaining file size and new address offset: This function
+ should be coded by user (its prototype is already declared in stm32_eval_audio_codec.h) */
+ EVAL_AUDIO_TransferComplete_CallBack((uint32_t)CurrentPos, 0);
+ }
+
+ #elif defined(AUDIO_MAL_MODE_CIRCULAR)
+ /* Manage the remaining file size and new address offset: This function
+ should be coded by user (its prototype is already declared in stm32_eval_audio_codec.h) */
+ EVAL_AUDIO_TransferComplete_CallBack(pAddr, Size);
+
+ /* Clear the Interrupt flag */
+ DMA_ClearFlag(AUDIO_MAL_DMA_STREAM, AUDIO_MAL_DMA_FLAG_TC);
+ #endif /* AUDIO_MAL_MODE_NORMAL */
+ }
+#endif /* AUDIO_MAL_DMA_IT_TC_EN */
+
+#ifdef AUDIO_MAL_DMA_IT_HT_EN
+ /* Half Transfer complete interrupt */
+ if (DMA_GetFlagStatus(AUDIO_MAL_DMA_CHANNEL, AUDIO_MAL_DMA_FLAG_HT) != RESET)
+ {
+ /* Manage the remaining file size and new address offset: This function
+ should be coded by user (its prototype is already declared in stm32_eval_audio_codec.h) */
+ EVAL_AUDIO_HalfTransfer_CallBack((uint32_t)pAddr, Size);
+
+ /* Clear the Interrupt flag */
+ DMA_ClearFlag(AUDIO_MAL_DMA_CHANNEL, AUDIO_MAL_DMA_FLAG_HT);
+ }
+#endif /* AUDIO_MAL_DMA_IT_HT_EN */
+
+#ifdef AUDIO_MAL_DMA_IT_TE_EN
+ /* FIFO Error interrupt */
+ if ((DMA_GetFlagStatus(AUDIO_MAL_DMA_CHANNEL, AUDIO_MAL_DMA_FLAG_TE) != RESET) || \
+ (DMA_GetFlagStatus(AUDIO_MAL_DMA_CHANNEL, AUDIO_MAL_DMA_FLAG_FE) != RESET) || \
+ (DMA_GetFlagStatus(AUDIO_MAL_DMA_CHANNEL, AUDIO_MAL_DMA_FLAG_DME) != RESET))
+
+ {
+ /* Manage the error generated on DMA FIFO: This function
+ should be coded by user (its prototype is already declared in stm32_eval_audio_codec.h) */
+ EVAL_AUDIO_Error_CallBack((uint32_t*)&pAddr);
+
+ /* Clear the Interrupt flag */
+ DMA_ClearFlag(AUDIO_MAL_DMA_CHANNEL, AUDIO_MAL_DMA_FLAG_TE | AUDIO_MAL_DMA_FLAG_FE | \
+ AUDIO_MAL_DMA_FLAG_DME);
+ }
+#endif /* AUDIO_MAL_DMA_IT_TE_EN */
+}
+
+/*============================================================================
+ CS43L22 Audio Codec Control Functions
+ ============================================================================*/
+/**
+ * @brief Initializes the audio codec and all related interfaces (control
+ * interface: I2C and audio interface: I2S)
+ * @param OutputDevice: can be OUTPUT_DEVICE_SPEAKER, OUTPUT_DEVICE_HEADPHONE,
+ * OUTPUT_DEVICE_BOTH or OUTPUT_DEVICE_AUTO .
+ * @param Volume: Initial volume level (from 0 (Mute) to 100 (Max))
+ * @param AudioFreq: Audio frequency used to play the audio stream.
+ * @retval 0 if correct communication, else wrong communication
+ */
+static uint32_t Codec_Init(uint16_t OutputDevice, uint8_t Volume, uint32_t AudioFreq)
+{
+ uint32_t counter = 0;
+
+ /* Configure the Codec related IOs */
+ Codec_GPIO_Init();
+
+ /* Reset the Codec Registers */
+ Codec_Reset();
+
+ /* Initialize the Control interface of the Audio Codec */
+ Codec_CtrlInterface_Init();
+
+ /* Keep Codec powered OFF */
+ counter += Codec_WriteRegister(0x02, 0x01);
+
+ switch (OutputDevice)
+ {
+ case OUTPUT_DEVICE_SPEAKER:
+ counter += Codec_WriteRegister(0x04, 0xFA); /* SPK always ON & HP always OFF */
+ OutputDev = 0xFA;
+ break;
+
+ case OUTPUT_DEVICE_HEADPHONE:
+ counter += Codec_WriteRegister(0x04, 0xAF); /* SPK always OFF & HP always ON */
+ OutputDev = 0xAF;
+ break;
+
+ case OUTPUT_DEVICE_BOTH:
+ counter += Codec_WriteRegister(0x04, 0xAA); /* SPK always ON & HP always ON */
+ OutputDev = 0xAA;
+ break;
+
+ case OUTPUT_DEVICE_AUTO:
+ counter += Codec_WriteRegister(0x04, 0x05); /* Detect the HP or the SPK automatically */
+ OutputDev = 0x05;
+ break;
+
+ default:
+ counter += Codec_WriteRegister(0x04, 0x05); /* Detect the HP or the SPK automatically */
+ OutputDev = 0x05;
+ break;
+ }
+
+ /* Clock configuration: Auto detection */
+ counter += Codec_WriteRegister(0x05, 0x81);
+
+ /* Set the Slave Mode and the audio Standard */
+ counter += Codec_WriteRegister(0x06, CODEC_STANDARD);
+
+ /* Set the Master volume */
+ Codec_VolumeCtrl(Volume);
+
+ /* If the Speaker is enabled, set the Mono mode and volume attenuation level */
+ if (OutputDevice != OUTPUT_DEVICE_HEADPHONE)
+ {
+ /* Set the Speaker Mono mode */
+ counter += Codec_WriteRegister(0x0F , 0x06);
+
+ /* Set the Speaker attenuation level */
+ counter += Codec_WriteRegister(0x24, 0x00);
+ counter += Codec_WriteRegister(0x25, 0x00);
+ }
+
+ /* Power on the Codec */
+ counter += Codec_WriteRegister(0x02, 0x9E);
+
+ /* Additional configuration for the CODEC. These configurations are done to reduce
+ the time needed for the Codec to power off. If these configurations are removed,
+ then a long delay should be added between powering off the Codec and switching
+ off the I2S peripheral MCLK clock (which is the operating clock for Codec).
+ If this delay is not inserted, then the codec will not shut down properly and
+ it results in high noise after shut down. */
+
+ /* Disable the analog soft ramp */
+ counter += Codec_WriteRegister(0x0A, 0x00);
+ /* Disable the digital soft ramp */
+ counter += Codec_WriteRegister(0x0E, 0x04);
+ /* Disable the limiter attack level */
+ counter += Codec_WriteRegister(0x27, 0x00);
+ /* Adjust Bass and Treble levels */
+ counter += Codec_WriteRegister(0x1F, 0x0F);
+ /* Adjust PCM volume level */
+ counter += Codec_WriteRegister(0x1A, 0x0A);
+ counter += Codec_WriteRegister(0x1B, 0x0A);
+
+ /* Configure the I2S peripheral */
+ Codec_AudioInterface_Init(AudioFreq);
+
+ /* Return communication control value */
+ return counter;
+}
+
+/**
+ * @brief Restore the audio codec state to default state and free all used
+ * resources.
+ * @param None
+ * @retval 0 if correct communication, else wrong communication
+ */
+static uint32_t Codec_DeInit(void)
+{
+ uint32_t counter = 0;
+
+ /* Reset the Codec Registers */
+ Codec_Reset();
+
+ /* Keep Codec powered OFF */
+ counter += Codec_WriteRegister(0x02, 0x01);
+
+ /* Deinitialize all use GPIOs */
+ Codec_GPIO_DeInit();
+
+ /* Disable the Codec control interface */
+ Codec_CtrlInterface_DeInit();
+
+ /* Deinitialize the Codec audio interface (I2S) */
+ Codec_AudioInterface_DeInit();
+
+ /* Return communication control value */
+ return counter;
+}
+
+/**
+ * @brief Start the audio Codec play feature.
+ * @note For this codec no Play options are required.
+ * @param None
+ * @retval 0 if correct communication, else wrong communication
+ */
+static uint32_t Codec_Play(void)
+{
+ /*
+ No actions required on Codec level for play command
+ */
+
+ /* Return communication control value */
+ return 0;
+}
+
+/**
+ * @brief Pauses and resumes playing on the audio codec.
+ * @param Cmd: AUDIO_PAUSE (or 0) to pause, AUDIO_RESUME (or any value different
+ * from 0) to resume.
+ * @retval 0 if correct communication, else wrong communication
+ */
+static uint32_t Codec_PauseResume(uint32_t Cmd)
+{
+ uint32_t counter = 0;
+
+ /* Pause the audio file playing */
+ if (Cmd == AUDIO_PAUSE)
+ {
+ /* Mute the output first */
+ counter += Codec_Mute(AUDIO_MUTE_ON);
+
+ /* Put the Codec in Power save mode */
+ counter += Codec_WriteRegister(0x02, 0x01);
+ }
+ else /* AUDIO_RESUME */
+ {
+ /* Unmute the output first */
+ counter += Codec_Mute(AUDIO_MUTE_OFF);
+
+ counter += Codec_WriteRegister(0x04, OutputDev);
+
+ /* Exit the Power save mode */
+ counter += Codec_WriteRegister(0x02, 0x9E);
+ }
+
+ return counter;
+}
+
+/**
+ * @brief Stops audio Codec playing. It powers down the codec.
+ * @param CodecPdwnMode: selects the power down mode.
+ * - CODEC_PDWN_SW: only mutes the audio codec. When resuming from this
+ * mode the codec keeps the previous initialization
+ * (no need to re-Initialize the codec registers).
+ * - CODEC_PDWN_HW: Physically power down the codec. When resuming from this
+ * mode, the codec is set to default configuration
+ * (user should re-Initialize the codec in order to
+ * play again the audio stream).
+ * @retval 0 if correct communication, else wrong communication
+ */
+static uint32_t Codec_Stop(uint32_t CodecPdwnMode)
+{
+ uint32_t counter = 0;
+
+ /* Mute the output first */
+ Codec_Mute(AUDIO_MUTE_ON);
+
+ if (CodecPdwnMode == CODEC_PDWN_SW)
+ {
+ /* Power down the DAC and the speaker (PMDAC and PMSPK bits)*/
+ counter += Codec_WriteRegister(0x02, 0x9F);
+ }
+ else /* CODEC_PDWN_HW */
+ {
+ /* Power down the components */
+ counter += Codec_WriteRegister(0x02, 0x9F);
+
+ /* Wait at least 100us */
+ Delay(0xFFF);
+
+ /* Reset The pin */
+ GPIO_WriteBit(AUDIO_RESET_GPIO, AUDIO_RESET_PIN, Bit_RESET);
+ }
+
+ return counter;
+}
+
+/**
+ * @brief Sets higher or lower the codec volume level.
+ * @param Volume: a byte value from 0 to 255 (refer to codec registers
+ * description for more details).
+ * @retval 0 if correct communication, else wrong communication
+ */
+static uint32_t Codec_VolumeCtrl(uint8_t Volume)
+{
+ uint32_t counter = 0;
+
+ if (Volume > 0xE6)
+ {
+ /* Set the Master volume */
+ counter += Codec_WriteRegister(0x20, Volume - 0xE7);
+ counter += Codec_WriteRegister(0x21, Volume - 0xE7);
+ }
+ else
+ {
+ /* Set the Master volume */
+ counter += Codec_WriteRegister(0x20, Volume + 0x19);
+ counter += Codec_WriteRegister(0x21, Volume + 0x19);
+ }
+
+ return counter;
+}
+
+/**
+ * @brief Enables or disables the mute feature on the audio codec.
+ * @param Cmd: AUDIO_MUTE_ON to enable the mute or AUDIO_MUTE_OFF to disable the
+ * mute mode.
+ * @retval 0 if correct communication, else wrong communication
+ */
+static uint32_t Codec_Mute(uint32_t Cmd)
+{
+ uint32_t counter = 0;
+
+ /* Set the Mute mode */
+ if (Cmd == AUDIO_MUTE_ON)
+ {
+ counter += Codec_WriteRegister(0x04, 0xFF);
+ }
+ else /* AUDIO_MUTE_OFF Disable the Mute */
+ {
+ counter += Codec_WriteRegister(0x04, OutputDev);
+ }
+
+ return counter;
+}
+
+/**
+ * @brief Resets the audio codec. It restores the default configuration of the
+ * codec (this function shall be called before initializing the codec).
+ * @note This function calls an external driver function: The IO Expander driver.
+ * @param None
+ * @retval None
+ */
+static void Codec_Reset(void)
+{
+ /* Power Down the codec */
+ GPIO_WriteBit(AUDIO_RESET_GPIO, AUDIO_RESET_PIN, Bit_RESET);
+
+ /* wait for a delay to insure registers erasing */
+ Delay(CODEC_RESET_DELAY);
+
+ /* Power on the codec */
+ GPIO_WriteBit(AUDIO_RESET_GPIO, AUDIO_RESET_PIN, Bit_SET);
+}
+
+/**
+ * @brief Switch dynamically (while audio file is played) the output target
+ * (speaker or headphone).
+ * @note This function modifies a global variable of the audio codec driver: OutputDev.
+ * @param Output: specifies the audio output target: OUTPUT_DEVICE_SPEAKER,
+ * OUTPUT_DEVICE_HEADPHONE, OUTPUT_DEVICE_BOTH or OUTPUT_DEVICE_AUTO
+ * @retval 0 if correct communication, else wrong communication
+ */
+uint32_t Codec_SwitchOutput(uint8_t Output)
+{
+ uint8_t counter = 0;
+
+ switch (Output)
+ {
+ case OUTPUT_DEVICE_SPEAKER:
+ counter += Codec_WriteRegister(0x04, 0xFA); /* SPK always ON & HP always OFF */
+ OutputDev = 0xFA;
+ break;
+
+ case OUTPUT_DEVICE_HEADPHONE:
+ counter += Codec_WriteRegister(0x04, 0xAF); /* SPK always OFF & HP always ON */
+ OutputDev = 0xAF;
+ break;
+
+ case OUTPUT_DEVICE_BOTH:
+ counter += Codec_WriteRegister(0x04, 0xAA); /* SPK always ON & HP always ON */
+ OutputDev = 0xAA;
+ break;
+
+ case OUTPUT_DEVICE_AUTO:
+ counter += Codec_WriteRegister(0x04, 0x05); /* Detect the HP or the SPK automatically */
+ OutputDev = 0x05;
+ break;
+
+ default:
+ counter += Codec_WriteRegister(0x04, 0x05); /* Detect the HP or the SPK automatically */
+ OutputDev = 0x05;
+ break;
+ }
+
+ return counter;
+}
+
+/**
+ * @brief Writes a Byte to a given register into the audio codec through the
+ control interface (I2C)
+ * @param RegisterAddr: The address (location) of the register to be written.
+ * @param RegisterValue: the Byte value to be written into destination register.
+ * @retval 0 if correct communication, else wrong communication
+ */
+static uint32_t Codec_WriteRegister(uint8_t RegisterAddr, uint8_t RegisterValue)
+{
+ uint32_t result = 0;
+
+ /* Test on BUSY Flag */
+ CODECTimeout = CODEC_FLAG_TIMEOUT;
+ while(I2C_GetFlagStatus(CODEC_I2C, I2C_ISR_BUSY) != RESET)
+ {
+ if((CODECTimeout--) == 0) return Codec_TIMEOUT_UserCallback();
+ }
+
+ /* Configure slave address, nbytes, reload, end mode and start or stop generation */
+ I2C_TransferHandling(CODEC_I2C, CODEC_ADDRESS, 2, I2C_AutoEnd_Mode, I2C_Generate_Start_Write);
+
+ /* Wait until TXIS flag is set */
+ CODECTimeout = CODEC_FLAG_TIMEOUT;
+ while(I2C_GetFlagStatus(CODEC_I2C, I2C_ISR_TXIS) == RESET)
+ {
+ if((CODECTimeout--) == 0) return Codec_TIMEOUT_UserCallback();
+ }
+
+ /* Send Register address */
+ I2C_SendData(CODEC_I2C, (uint8_t)RegisterAddr );
+
+ /* Wait until TXIS flag is set */
+ CODECTimeout = CODEC_FLAG_TIMEOUT;
+ while(I2C_GetFlagStatus(CODEC_I2C, I2C_ISR_TXIS) == RESET)
+ {
+ if((CODECTimeout--) == 0) return Codec_TIMEOUT_UserCallback();
+ }
+
+ /* Write data to TXDR */
+ I2C_SendData(CODEC_I2C, (uint8_t)RegisterValue);
+
+ /* Wait until STOPF flag is set */
+ CODECTimeout = CODEC_FLAG_TIMEOUT;
+ while(I2C_GetFlagStatus(CODEC_I2C, I2C_ISR_STOPF) == RESET)
+ {
+ if((CODECTimeout--) == 0) return Codec_TIMEOUT_UserCallback();
+ }
+
+ /* Clear STOPF flag */
+ I2C_ClearFlag(CODEC_I2C, I2C_ICR_STOPCF);
+
+#ifdef VERIFY_WRITTENDATA
+ /* Verify that the data has been correctly written */
+ result = (Codec_ReadRegister(RegisterAddr) == RegisterValue)? 0:1;
+#endif /* VERIFY_WRITTENDATA */
+
+ /* Return the verifying value: 0 (Passed) or 1 (Failed) */
+ return result;
+}
+
+/**
+ * @brief Reads and returns the value of an audio codec register through the
+ * control interface (I2C).
+ * @param RegisterAddr: Address of the register to be read.
+ * @retval Value of the register to be read or dummy value if the communication
+ * fails.
+ */
+static uint32_t Codec_ReadRegister(uint8_t RegisterAddr)
+{
+ uint32_t result = 0;
+
+ /* Test on BUSY Flag */
+ CODECTimeout = CODEC_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(CODEC_I2C, I2C_ISR_BUSY) != RESET)
+ {
+ if((CODECTimeout--) == 0) return Codec_TIMEOUT_UserCallback();
+ }
+
+ /* Configure slave address, nbytes, reload, end mode and start or stop generation */
+ I2C_TransferHandling(CODEC_I2C, CODEC_ADDRESS, 1, I2C_SoftEnd_Mode, I2C_Generate_Start_Write);
+
+ /* Wait until TXIS flag is set */
+ CODECTimeout = CODEC_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(CODEC_I2C, I2C_ISR_TXIS) == RESET)
+ {
+ if((CODECTimeout--) == 0) return Codec_TIMEOUT_UserCallback();
+ }
+
+ /* Send Register address */
+ I2C_SendData(CODEC_I2C, (uint8_t)RegisterAddr);
+
+ /* Wait until TC flag is set */
+ CODECTimeout = CODEC_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(CODEC_I2C, I2C_ISR_TC) == RESET)
+ {
+ if((CODECTimeout--) == 0) return Codec_TIMEOUT_UserCallback();
+ }
+
+ /* Configure slave address, nbytes, reload, end mode and start or stop generation */
+ I2C_TransferHandling(CODEC_I2C, CODEC_ADDRESS, 1, I2C_AutoEnd_Mode, I2C_Generate_Start_Read);
+
+ /* Wait until RXNE flag is set */
+ CODECTimeout = CODEC_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(CODEC_I2C, I2C_ISR_RXNE) == RESET)
+ {
+ if((CODECTimeout--) == 0) return Codec_TIMEOUT_UserCallback();
+ }
+
+ /* Read data from RXDR */
+ result = I2C_ReceiveData(CODEC_I2C);
+
+ /* Wait until STOPF flag is set */
+ CODECTimeout = CODEC_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(CODEC_I2C, I2C_ISR_STOPF) == RESET)
+ {
+ if((CODECTimeout--) == 0) return Codec_TIMEOUT_UserCallback();
+ }
+
+ /* Clear STOPF flag */
+ I2C_ClearFlag(CODEC_I2C, I2C_ICR_STOPCF);
+
+ /* Return the byte read from Codec */
+ return result;
+}
+
+/**
+ * @brief Initializes the Audio Codec control interface (I2C).
+ * @param None
+ * @retval None
+ */
+static void Codec_CtrlInterface_Init(void)
+{
+ I2C_InitTypeDef I2C_InitStructure;
+
+ /* Configure the I2C clock source. The clock is derived from the SYSCLK */
+ RCC_I2CCLKConfig(RCC_I2C2CLK_SYSCLK);
+
+ /* Enable the CODEC_I2C peripheral clock */
+ RCC_APB1PeriphClockCmd(CODEC_I2C_CLK, ENABLE);
+
+ /* CODEC_I2C configuration */
+ I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
+ I2C_InitStructure.I2C_AnalogFilter = I2C_AnalogFilter_Enable;
+ I2C_InitStructure.I2C_DigitalFilter = 0x00;
+ I2C_InitStructure.I2C_OwnAddress1 = 0x33;
+ I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
+ I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
+ I2C_InitStructure.I2C_Timing = CODEC_I2C_TIMING;
+
+ /* Enable the I2C peripheral */
+ I2C_Init(CODEC_I2C, &I2C_InitStructure);
+ I2C_Cmd(CODEC_I2C, ENABLE);
+}
+
+/**
+ * @brief Restore the Audio Codec control interface to its default state.
+ * This function doesn't de-initialize the I2C because the I2C peripheral
+ * may be used by other modules.
+ * @param None
+ * @retval None
+ */
+static void Codec_CtrlInterface_DeInit(void)
+{
+ /* Disable the I2C peripheral */ /* This step is not done here because
+ the I2C interface can be used by other modules */
+ /* I2C_DeInit(CODEC_I2C); */
+}
+
+/**
+ * @brief Initializes the Audio Codec audio interface (I2S)
+ * @note This function assumes that the I2S input clock (through PLL_R in
+ * Devices RevA/Z and through dedicated PLLI2S_R in Devices RevB/Y)
+ * is already configured and ready to be used.
+ * @param AudioFreq: Audio frequency to be configured for the I2S peripheral.
+ * @retval None
+ */
+static void Codec_AudioInterface_Init(uint32_t AudioFreq)
+{
+ I2S_InitTypeDef I2S_InitStructure;
+
+ /* Enable the CODEC_I2S peripheral clock */
+ RCC_APB2PeriphClockCmd(CODEC_I2S_CLK, ENABLE);
+
+ /* CODEC_I2S peripheral configuration */
+ SPI_I2S_DeInit(CODEC_I2S);
+ I2S_InitStructure.I2S_AudioFreq = AudioFreq;
+ I2S_InitStructure.I2S_Standard = I2S_STANDARD;
+ I2S_InitStructure.I2S_DataFormat = I2S_DataFormat_16b;
+ I2S_InitStructure.I2S_CPOL = I2S_CPOL_Low;
+ I2S_InitStructure.I2S_Mode = I2S_Mode_MasterTx;
+#ifdef CODEC_MCLK_ENABLED
+ I2S_InitStructure.I2S_MCLKOutput = I2S_MCLKOutput_Enable;
+#elif defined(CODEC_MCLK_DISABLED)
+ I2S_InitStructure.I2S_MCLKOutput = I2S_MCLKOutput_Disable;
+#else
+ #error "No selection for the MCLK output has been defined !"
+#endif /* CODEC_MCLK_ENABLED */
+
+ /* Initialize the I2S peripheral with the structure above */
+ I2S_Init(CODEC_I2S, &I2S_InitStructure);
+
+ /* The I2S peripheral will be enabled only in the EVAL_AUDIO_Play() function
+ or by user functions if DMA mode not enabled */
+}
+
+/**
+ * @brief Restores the Audio Codec audio interface to its default state.
+ * @param None
+ * @retval None
+ */
+static void Codec_AudioInterface_DeInit(void)
+{
+ /* Disable the CODEC_I2S peripheral (in case it hasn't already been disabled) */
+ I2S_Cmd(CODEC_I2S, DISABLE);
+
+ /* Deinitialize the CODEC_I2S peripheral */
+ SPI_I2S_DeInit(CODEC_I2S);
+
+ /* Disable the CODEC_I2S peripheral clock */
+ RCC_APB2PeriphClockCmd(CODEC_I2S_CLK, DISABLE);
+}
+
+/**
+ * @brief Initializes IOs used by the Audio Codec (on the control and audio
+ * interfaces).
+ * @param None
+ * @retval None
+ */
+static void Codec_GPIO_Init(void)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+
+ /* Enable Reset GPIO Clock */
+ RCC_AHBPeriphClockCmd(AUDIO_RESET_GPIO_CLK,ENABLE);
+
+ /* Audio reset pin configuration ---------------------------------------------*/
+ GPIO_InitStructure.GPIO_Pin = AUDIO_RESET_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
+ GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
+ GPIO_Init(AUDIO_RESET_GPIO, &GPIO_InitStructure);
+
+ /* Enable I2S and I2C GPIO clocks */
+ RCC_AHBPeriphClockCmd(CODEC_I2C_GPIO_CLOCK | CODEC_I2S_GPIO_CLOCK, ENABLE);
+
+ /* Connect pins to I2C peripheral */
+ GPIO_PinAFConfig(CODEC_I2C_GPIO, CODEC_I2S_SCL_PINSRC, CODEC_I2C_GPIO_AF);
+ GPIO_PinAFConfig(CODEC_I2C_GPIO, CODEC_I2S_SDA_PINSRC, CODEC_I2C_GPIO_AF);
+
+ /* CODEC_I2C SCL and SDA pins configuration ----------------------------------*/
+ GPIO_InitStructure.GPIO_Pin = CODEC_I2C_SCL_PIN | CODEC_I2C_SDA_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
+ GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
+ GPIO_Init(CODEC_I2C_GPIO, &GPIO_InitStructure);
+
+
+ /* CODEC_I2S pins configuration: WS, SCK and SD pins -------------------------*/
+ GPIO_InitStructure.GPIO_Pin = CODEC_I2S_SCK_PIN | CODEC_I2S_SD_PIN | CODEC_I2S_WS_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
+ GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
+ GPIO_Init(CODEC_I2S_GPIO, &GPIO_InitStructure);
+
+ /* Connect pins to I2S peripheral */
+ GPIO_PinAFConfig(CODEC_I2S_GPIO, CODEC_I2S_WS_PINSRC, CODEC_I2S_GPIO_AF);
+ GPIO_PinAFConfig(CODEC_I2S_GPIO, CODEC_I2S_SCK_PINSRC, CODEC_I2S_GPIO_AF);
+ GPIO_PinAFConfig(CODEC_I2S_GPIO, CODEC_I2S_SD_PINSRC, CODEC_I2S_GPIO_AF);
+
+ #ifdef CODEC_MCLK_ENABLED
+ /* CODEC_I2S pins configuration: MCK pin */
+ GPIO_InitStructure.GPIO_Pin = CODEC_I2S_MCK_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
+ GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
+ GPIO_Init(CODEC_I2S_MCK_GPIO, &GPIO_InitStructure);
+ /* Connect pins to I2S peripheral */
+ GPIO_PinAFConfig(CODEC_I2S_MCK_GPIO, CODEC_I2S_MCK_PINSRC, CODEC_I2S_GPIO_AF);
+ #endif /* CODEC_MCLK_ENABLED */
+}
+
+/**
+ * @brief Restores the IOs used by the Audio Codec interface to their default state.
+ * @param None
+ * @retval None
+ */
+static void Codec_GPIO_DeInit(void)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+
+ /* Deinitialize all the GPIOs used by the driver (EXCEPT the I2C IOs since
+ they are used by the IOExpander as well) */
+ GPIO_InitStructure.GPIO_Pin = CODEC_I2S_WS_PIN | CODEC_I2S_SCK_PIN | CODEC_I2S_SD_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
+ GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
+ GPIO_Init(CODEC_I2S_GPIO, &GPIO_InitStructure);
+
+#ifdef CODEC_MCLK_ENABLED
+ /* CODEC_I2S pins deinitialization: MCK pin */
+ GPIO_InitStructure.GPIO_Pin = CODEC_I2S_MCK_PIN;
+ GPIO_Init(CODEC_I2S_MCK_GPIO, &GPIO_InitStructure);
+ /* Disconnect pins from I2S peripheral */
+ GPIO_PinAFConfig(CODEC_I2S_MCK_GPIO, CODEC_I2S_MCK_PINSRC, CODEC_I2S_GPIO_AF);
+#endif /* CODEC_MCLK_ENABLED */
+}
+
+/**
+ * @brief Inserts a delay time (not accurate timing).
+ * @param nCount: specifies the delay time length.
+ * @retval None
+ */
+static void Delay( __IO uint32_t nCount)
+{
+ for (; nCount != 0; nCount--);
+}
+
+#ifdef USE_DEFAULT_TIMEOUT_CALLBACK
+/**
+ * @brief Basic management of the timeout situation.
+ * @param None
+ * @retval None
+ */
+uint32_t Codec_TIMEOUT_UserCallback(void)
+{
+ /* The following code allows I2C error recovery and return to normal communication
+ if the error source doesn’t still exist (ie. hardware issue..) */
+ I2C_InitTypeDef I2C_InitStructure;
+
+ /* LCD_ErrLog("> I2C Timeout error occurred\n"); */
+
+ I2C_GenerateSTOP(CODEC_I2C, ENABLE);
+ I2C_SoftwareResetCmd(CODEC_I2C, ENABLE);
+ I2C_SoftwareResetCmd(CODEC_I2C, DISABLE);
+
+ /* CODEC_I2C peripheral configuration */
+ I2C_DeInit(CODEC_I2C);
+ I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
+ I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;
+ I2C_InitStructure.I2C_OwnAddress1 = 0x33;
+ I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
+ I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
+ I2C_InitStructure.I2C_ClockSpeed = I2C_SPEED;
+ /* Enable the I2C peripheral */
+ I2C_Cmd(CODEC_I2C, ENABLE);
+ I2C_Init(CODEC_I2C, &I2C_InitStructure);
+
+ /* At this stage the I2C error should be recovered and device can communicate
+ again (except if the error source still exist).
+ User can implement mechanism (ex. test on max trial number) to manage situation
+ when the I2C can't recover from current error. */
+
+ /* LCD_UsrLog("> I2C error recovered.\n"); */
+
+ return 0;
+}
+#endif /* USE_DEFAULT_TIMEOUT_CALLBACK */
+
+/*============================================================================
+ Audio MAL Interface Control Functions
+ ============================================================================*/
+
+/**
+ * @brief Initializes and prepares the Media to perform audio data transfer
+ * from Media to the I2S peripheral.
+ * @param None
+ * @retval None
+ */
+static void Audio_MAL_Init(void)
+{
+#if defined(AUDIO_MAL_DMA_IT_TC_EN) || defined(AUDIO_MAL_DMA_IT_HT_EN) || defined(AUDIO_MAL_DMA_IT_TE_EN)
+ NVIC_InitTypeDef NVIC_InitStructure;
+#endif
+
+ /* Enable the DMA clock */
+ RCC_AHBPeriphClockCmd(AUDIO_MAL_DMA_CLOCK, ENABLE);
+
+ /* Configure the DMA Channel */
+ DMA_Cmd(AUDIO_MAL_DMA_CHANNEL, DISABLE);
+ DMA_DeInit(AUDIO_MAL_DMA_CHANNEL);
+ /* Set the parameters to be configured */
+
+ DMA_InitStructure.DMA_PeripheralBaseAddr = CODEC_I2S_ADDRESS;
+ DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)0; /* This field will be configured in play function */
+ DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
+ DMA_InitStructure.DMA_BufferSize = (uint32_t)0xFFFE; /* This field will be configured in play function */
+ DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
+ DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
+ DMA_InitStructure.DMA_PeripheralDataSize = AUDIO_MAL_DMA_PERIPH_DATA_SIZE;
+ DMA_InitStructure.DMA_MemoryDataSize = AUDIO_MAL_DMA_MEM_DATA_SIZE;
+#ifdef AUDIO_MAL_MODE_NORMAL
+ DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
+#elif defined(AUDIO_MAL_MODE_CIRCULAR)
+ DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
+#else
+ #error "AUDIO_MAL_MODE_NORMAL or AUDIO_MAL_MODE_CIRCULAR should be selected !!"
+#endif /* AUDIO_MAL_MODE_NORMAL */
+ DMA_Init(AUDIO_MAL_DMA_CHANNEL, &DMA_InitStructure);
+
+ /* Enable the selected DMA interrupts (selected in "stm32_eval_audio_codec.h" defines) */
+#ifdef AUDIO_MAL_DMA_IT_TC_EN
+ DMA_ITConfig(AUDIO_MAL_DMA_CHANNEL, DMA_IT_TC, ENABLE);
+#endif /* AUDIO_MAL_DMA_IT_TC_EN */
+#ifdef AUDIO_MAL_DMA_IT_HT_EN
+ DMA_ITConfig(AUDIO_MAL_DMA_CHANNEL, DMA_IT_HT, ENABLE);
+#endif /* AUDIO_MAL_DMA_IT_HT_EN */
+#ifdef AUDIO_MAL_DMA_IT_TE_EN
+ DMA_ITConfig(AUDIO_MAL_DMA_CHANNEL, DMA_IT_TE | DMA_IT_FE | DMA_IT_DME, ENABLE);
+#endif /* AUDIO_MAL_DMA_IT_TE_EN */
+
+ /* Enable the I2S DMA request */
+ SPI_I2S_DMACmd(CODEC_I2S, SPI_I2S_DMAReq_Tx, ENABLE);
+
+#if defined(AUDIO_MAL_DMA_IT_TC_EN) || defined(AUDIO_MAL_DMA_IT_HT_EN) || defined(AUDIO_MAL_DMA_IT_TE_EN)
+ /* I2S DMA IRQ Channel configuration */
+ NVIC_InitStructure.NVIC_IRQChannel = AUDIO_MAL_DMA_IRQ;
+ NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = EVAL_AUDIO_IRQ_PREPRIO;
+ NVIC_InitStructure.NVIC_IRQChannelSubPriority = EVAL_AUDIO_IRQ_SUBRIO;
+ NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
+ NVIC_Init(&NVIC_InitStructure);
+#endif
+}
+
+/**
+ * @brief Restore default state of the used Media.
+ * @param None
+ * @retval None
+ */
+static void Audio_MAL_DeInit(void)
+{
+#if defined(AUDIO_MAL_DMA_IT_TC_EN) || defined(AUDIO_MAL_DMA_IT_HT_EN) || defined(AUDIO_MAL_DMA_IT_TE_EN)
+ NVIC_InitTypeDef NVIC_InitStructure;
+
+ /* Deinitialize the NVIC interrupt for the I2S DMA Channel */
+ NVIC_InitStructure.NVIC_IRQChannel = AUDIO_MAL_DMA_IRQ;
+ NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = EVAL_AUDIO_IRQ_PREPRIO;
+ NVIC_InitStructure.NVIC_IRQChannelSubPriority = EVAL_AUDIO_IRQ_SUBRIO;
+ NVIC_InitStructure.NVIC_IRQChannelCmd = DISABLE;
+ NVIC_Init(&NVIC_InitStructure);
+#endif
+
+ /* Disable the DMA before the deinit */
+ DMA_Cmd(AUDIO_MAL_DMA_CHANNEL, DISABLE);
+
+ /* Dinitialize the DMA Channel */
+ DMA_DeInit(AUDIO_MAL_DMA_CHANNEL);
+
+ /* The DMA clock is not disabled */
+}
+
+/**
+ * @brief Starts playing audio stream from the audio Media.
+ * @param None
+ * @retval None
+ */
+void Audio_MAL_Play(uint32_t Addr, uint32_t Size)
+{
+ /* Configure the buffer address and size */
+ DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)Addr;
+ DMA_InitStructure.DMA_BufferSize = (uint32_t)Size/2;
+
+ /* Configure the DMA Channel with the new parameters */
+ DMA_Init(AUDIO_MAL_DMA_CHANNEL, &DMA_InitStructure);
+
+ /* Enable the I2S DMA Channel */
+ DMA_Cmd(AUDIO_MAL_DMA_CHANNEL, ENABLE);
+
+ /* If the I2S peripheral is still not enabled, enable it */
+ if ((CODEC_I2S->I2SCFGR & I2S_ENABLE_MASK) == 0)
+ {
+ I2S_Cmd(CODEC_I2S, ENABLE);
+ }
+}
+
+/**
+ * @brief Pauses or Resumes the audio stream playing from the Media.
+ * @param Cmd: AUDIO_PAUSE (or 0) to pause, AUDIO_RESUME (or any value different
+ * from 0) to resume.
+ * @param Addr: Address from/at which the audio stream should resume/pause.
+ * @retval None
+ */
+static void Audio_MAL_PauseResume(uint32_t Cmd, uint32_t Addr)
+{
+ /* Pause the audio file playing */
+ if (Cmd == AUDIO_PAUSE)
+ {
+ /* Disable the I2S DMA request */
+ SPI_I2S_DMACmd(CODEC_I2S, SPI_I2S_DMAReq_Tx, DISABLE);
+
+ /* Pause the I2S DMA Channel
+ Note. For the STM32F37x devices, the DMA implements a pause feature,
+ by disabling the channel, all configuration is preserved and data
+ transfer is paused till the next enable of the channel.*/
+ DMA_Cmd(AUDIO_MAL_DMA_CHANNEL, DISABLE);
+ }
+ else /* AUDIO_RESUME */
+ {
+ /* Enable the I2S DMA request */
+ SPI_I2S_DMACmd(CODEC_I2S, SPI_I2S_DMAReq_Tx, ENABLE);
+
+ /* Resume the I2S DMA Channel
+ Note. For the STM32F37x devices, the DMA implements a pause feature,
+ by disabling the channel, all configuration is preserved and data
+ transfer is paused till the next enable of the channel.*/
+ DMA_Cmd(AUDIO_MAL_DMA_CHANNEL, ENABLE);
+
+ /* If the I2S peripheral is still not enabled, enable it */
+ if ((CODEC_I2S->I2SCFGR & I2S_ENABLE_MASK) == 0)
+ {
+ I2S_Cmd(CODEC_I2S, ENABLE);
+ }
+ }
+}
+
+/**
+ * @brief Stops audio stream playing on the used Media.
+ * @param None
+ * @retval None
+ */
+static void Audio_MAL_Stop(void)
+{
+ /* Stop the Transfer on the I2S side: Stop and disable the DMA channel */
+ DMA_Cmd(AUDIO_MAL_DMA_CHANNEL, DISABLE);
+
+ /* Clear all the DMA flags for the next transfer */
+ DMA_ClearFlag(AUDIO_MAL_DMA_FLAG_TC|AUDIO_MAL_DMA_FLAG_HT|AUDIO_MAL_DMA_FLAG_TE);
+
+ /*
+ The I2S DMA requests are not disabled here.
+ */
+
+ /* In all modes, disable the I2S peripheral */
+ I2S_Cmd(CODEC_I2S, DISABLE);
+}
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32373C_EVAL/stm32373c_eval_audio_codec.h b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32373C_EVAL/stm32373c_eval_audio_codec.h
new file mode 100644
index 0000000..6204868
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32373C_EVAL/stm32373c_eval_audio_codec.h
@@ -0,0 +1,284 @@
+/**
+ ******************************************************************************
+ * @file stm32373c_eval_audio_codec.h
+ * @author MCD Application Team
+ * @version V1.0.0
+ * @date 20-September-2012
+ * @brief This file contains all the functions prototypes for the
+ * stm32373c_eval_audio_codec.c driver.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.st.com/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __STM32373C_EVAL_AUDIOCODEC_H
+#define __STM32373C_EVAL_AUDIOCODEC_H
+
+/* Includes ------------------------------------------------------------------*/
+#include "stm32373c_eval.h"
+
+/** @addtogroup Utilities
+ * @{
+ */
+
+/** @addtogroup STM32_EVAL
+ * @{
+ */
+
+/** @addtogroup STM32373C_EVAL
+ * @{
+ */
+
+/** @defgroup STM32373C_EVAL_AUDIO_CODEC
+ * @{
+ */
+
+
+/** @defgroup STM32373C_EVAL_AUDIO_CODEC_Exported_Types
+ * @{
+ */
+
+/**
+ * @}
+ */
+
+/** @defgroup STM32373C_EVAL_AUDIO_CODEC_Exported_Constants
+ * @{
+ */
+
+/*----------------------------------------------------------------------------
+ CONFIGURATION: Audio Codec Driver Configuration parameters
+ ----------------------------------------------------------------------------*/
+/* Audio Transfer mode (DMA, Interrupt or Polling) */
+#define AUDIO_MAL_MODE_NORMAL /* Uncomment this line to enable the audio
+ Transfer using DMA */
+/* #define AUDIO_MAL_MODE_CIRCULAR */ /* Uncomment this line to enable the audio
+ Transfer using DMA */
+
+/* For the DMA modes select the interrupt that will be used */
+#define AUDIO_MAL_DMA_IT_TC_EN /* Uncomment this line to enable DMA Transfer Complete interrupt */
+/* #define AUDIO_MAL_DMA_IT_HT_EN */ /* Uncomment this line to enable DMA Half Transfer Complete interrupt */
+/* #define AUDIO_MAL_DMA_IT_TE_EN */ /* Uncomment this line to enable DMA Transfer Error interrupt */
+
+/* Select the interrupt preemption priority and subpriority for the DMA interrupt */
+#define EVAL_AUDIO_IRQ_PREPRIO 0 /* Select the preemption priority level(0 is the highest) */
+#define EVAL_AUDIO_IRQ_SUBRIO 0 /* Select the sub-priority level (0 is the highest) */
+
+/* Uncomment the following line to use the default Codec_TIMEOUT_UserCallback()
+ function implemented in stm32373c_eval_audio_codec.c file.
+ Codec_TIMEOUT_UserCallback() function is called whenever a timeout condition
+ occurs during communication (waiting on an event that doesn't occur, bus
+ errors, busy devices ...). */
+/* #define USE_DEFAULT_TIMEOUT_CALLBACK */
+/*----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+ OPTIONAL Configuration defines parameters
+ ----------------------------------------------------------------------------*/
+/* I2C clock speed configuration (in Hz)
+ WARNING:
+ Make sure that this define is not already declared in other files (ie.
+ stm32373c_eval.h file). It can be used in parallel by other modules. */
+
+/* I2C TIMING Register define when I2C clock source is SYSCLK */
+/* set TIMING to 0xC062121F to reach 100 KHz speed (Rise time = 640ns, Fall time = 20ns) */
+
+#define CODEC_I2C_TIMING 0xC062121F
+
+/* Uncomment defines below to select standard for audio communication between
+ Codec and I2S peripheral */
+#define I2S_STANDARD_PHILLIPS
+/* #define I2S_STANDARD_MSB */
+/* #define I2S_STANDARD_LSB */
+
+/* Uncomment the defines below to select if the Master clock mode should be
+ enabled or not */
+#define CODEC_MCLK_ENABLED
+/* #deine CODEC_MCLK_DISABLED */
+
+/* Uncomment this line to enable verifying data sent to codec after each write
+ operation */
+#define VERIFY_WRITTENDATA
+/*----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+ Hardware Configuration defines parameters
+ ----------------------------------------------------------------------------*/
+/* Audio Reset Pin definition */
+#define AUDIO_RESET_GPIO_CLK RCC_AHBPeriph_GPIOD
+#define AUDIO_RESET_PIN GPIO_Pin_11
+#define AUDIO_RESET_GPIO GPIOD
+
+/* I2S peripheral configuration defines */
+#define CODEC_I2S SPI1
+#define CODEC_I2S_CLK RCC_APB2Periph_SPI1
+#define CODEC_I2S_ADDRESS 0x4001300C
+#define CODEC_I2S_GPIO_AF GPIO_AF_5
+#define CODEC_I2S_IRQ SPI1_IRQn
+#define CODEC_I2S_GPIO_CLOCK (RCC_AHBPeriph_GPIOC)
+#define CODEC_I2S_WS_PIN GPIO_Pin_6
+#define CODEC_I2S_SCK_PIN GPIO_Pin_7
+#define CODEC_I2S_SD_PIN GPIO_Pin_9
+#define CODEC_I2S_MCK_PIN GPIO_Pin_8
+#define CODEC_I2S_WS_PINSRC GPIO_PinSource6
+#define CODEC_I2S_SCK_PINSRC GPIO_PinSource7
+#define CODEC_I2S_SD_PINSRC GPIO_PinSource9
+#define CODEC_I2S_MCK_PINSRC GPIO_PinSource8
+#define CODEC_I2S_GPIO GPIOC
+#define CODEC_I2S_MCK_GPIO GPIOC
+
+ /* I2S DMA channel definitions */
+#define AUDIO_MAL_DMA_CLOCK RCC_AHBPeriph_DMA1
+#define AUDIO_MAL_DMA_CHANNEL DMA1_Channel3
+#define AUDIO_MAL_DMA_IRQ DMA1_Channel3_IRQn
+#define AUDIO_MAL_DMA_FLAG_TC DMA1_FLAG_TC3
+#define AUDIO_MAL_DMA_FLAG_HT DMA1_FLAG_HT3
+#define AUDIO_MAL_DMA_FLAG_TE DMA1_FLAG_TE3
+
+#define Audio_MAL_IRQHandler DMA1_Channel3_IRQHandler
+#define AUDIO_MAL_DMA_PERIPH_DATA_SIZE DMA_PeripheralDataSize_HalfWord
+#define AUDIO_MAL_DMA_MEM_DATA_SIZE DMA_MemoryDataSize_HalfWord
+#define DMA_MAX_SZE 0xFFFF
+
+/* I2C peripheral configuration defines (control interface of the audio codec) */
+#define CODEC_I2C I2C2
+#define CODEC_I2C_CLK RCC_APB1Periph_I2C2
+#define CODEC_I2C_GPIO_CLOCK RCC_AHBPeriph_GPIOB
+#define CODEC_I2C_GPIO_AF GPIO_AF_4
+#define CODEC_I2C_GPIO GPIOA
+#define CODEC_I2C_SCL_PIN GPIO_Pin_9
+#define CODEC_I2C_SDA_PIN GPIO_Pin_10
+#define CODEC_I2S_SCL_PINSRC GPIO_PinSource9
+#define CODEC_I2S_SDA_PINSRC GPIO_PinSource10
+
+/* Maximum Timeout values for flags and events waiting loops. These timeouts are
+ not based on accurate values, they just guarantee that the application will
+ not remain stuck if the I2C communication is corrupted.
+ You may modify these timeout values depending on CPU frequency and application
+ conditions (interrupts routines ...). */
+#define CODEC_FLAG_TIMEOUT ((uint32_t)0x1000)
+#define CODEC_LONG_TIMEOUT ((uint32_t)(300 * CODEC_FLAG_TIMEOUT))
+/*----------------------------------------------------------------------------*/
+
+/*----------------------------------------------------------------------------
+ Audio Codec User defines
+ ----------------------------------------------------------------------------*/
+/* Codec output DEVICE */
+#define OUTPUT_DEVICE_SPEAKER 1
+#define OUTPUT_DEVICE_HEADPHONE 2
+#define OUTPUT_DEVICE_BOTH 3
+#define OUTPUT_DEVICE_AUTO 4
+
+/* Volume Levels values */
+#define DEFAULT_VOLMIN 0x00
+#define DEFAULT_VOLMAX 0xFF
+#define DEFAULT_VOLSTEP 0x04
+
+#define AUDIO_PAUSE 0
+#define AUDIO_RESUME 1
+
+/* Codec POWER DOWN modes */
+#define CODEC_PDWN_HW 1
+#define CODEC_PDWN_SW 2
+
+/* MUTE commands */
+#define AUDIO_MUTE_ON 1
+#define AUDIO_MUTE_OFF 0
+/*----------------------------------------------------------------------------*/
+/**
+ * @}
+ */
+
+/** @defgroup STM32373C_EVAL_AUDIO_CODEC_Exported_Macros
+ * @{
+ */
+#define VOLUME_CONVERT(x) ((Volume > 100)? 100:((uint8_t)((Volume * 255) / 100)))
+#define DMA_MAX(x) (((x) <= DMA_MAX_SZE)? (x):DMA_MAX_SZE)
+
+/**
+ * @}
+ */
+
+/** @defgroup STM32373C_EVAL_AUDIO_CODEC_Exported_Functions
+ * @{
+ */
+
+uint32_t EVAL_AUDIO_Init(uint16_t OutputDevice, uint8_t Volume, uint32_t AudioFreq);
+uint32_t EVAL_AUDIO_DeInit(void);
+uint32_t EVAL_AUDIO_Play(uint16_t* pBuffer, uint32_t Size);
+uint32_t EVAL_AUDIO_PauseResume(uint32_t Cmd);
+uint32_t EVAL_AUDIO_Stop(uint32_t CodecPowerDown_Mode);
+uint32_t EVAL_AUDIO_VolumeCtl(uint8_t Volume);
+uint32_t EVAL_AUDIO_Mute(uint32_t Command);
+
+uint32_t Codec_SwitchOutput(uint8_t Output);
+
+/* User Callbacks: user has to implement these functions in his code if
+ they are needed. -----------------------------------------------------------*/
+
+/* This function is called when the requested data has been completely transferred.
+ In Normal mode (when the define AUDIO_MAL_MODE_NORMAL is enabled) this function
+ is called at the end of the whole audio file.
+ In circular mode (when the define AUDIO_MAL_MODE_CIRCULAR is enabled) this
+ function is called at the end of the current buffer transmission. */
+void EVAL_AUDIO_TransferComplete_CallBack(uint32_t pBuffer, uint32_t Size);
+
+/* This function is called when half of the requested buffer has been transferred
+ This callback is useful in Circular mode only (when AUDIO_MAL_MODE_CIRCULAR
+ define is enabled)*/
+void EVAL_AUDIO_HalfTransfer_CallBack(uint32_t pBuffer, uint32_t Size);
+
+/* This function is called when an Interrupt due to transfer error on or peripheral
+ error occurs. */
+void EVAL_AUDIO_Error_CallBack(void* pData);
+
+/* Codec_TIMEOUT_UserCallback() function is called whenever a timeout condition
+ occurs during communication (waiting on an event that doesn't occur, bus
+ errors, busy devices ...) on the Codec control interface (I2C).
+ You can use the default timeout callback implementation by uncommenting the
+ define USE_DEFAULT_TIMEOUT_CALLBACK in stm32373c_eval_audio_codec.h file.
+ Typically the user implementation of this callback should reset I2C peripheral
+ and re-initialize communication or in worst case reset all the application. */
+uint32_t Codec_TIMEOUT_UserCallback(void);
+void Audio_MAL_IRQHandler(void);
+void Audio_MAL_Play(uint32_t Addr, uint32_t Size);
+
+#endif /* __STM32373C_EVAL_AUDIOCODEC_H */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32373C_EVAL/stm32373c_eval_cec.c b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32373C_EVAL/stm32373c_eval_cec.c
new file mode 100644
index 0000000..1641cea
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32373C_EVAL/stm32373c_eval_cec.c
@@ -0,0 +1,2033 @@
+/**
+ ******************************************************************************
+ * @file stm32373c_eval_cec.c
+ * @author MCD Application Team
+ * @version V1.0.0
+ * @date 20-September-2012
+ * @brief This file provides all the STM32373C-EVAL HDMI-CEC firmware functions.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.st.com/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+
+/* Includes ------------------------------------------------------------------*/
+#include "stm32373c_eval_cec.h"
+
+/** @addtogroup Utilities
+ * @{
+ */
+
+/** @addtogroup STM32_EVAL
+ * @{
+ */
+
+/** @addtogroup STM32373C_EVAL
+ * @{
+ */
+
+/** @defgroup STM32373C_EVAL_CEC
+ * @brief This file includes the CEC Stack driver for HDMI-CEC Module
+ * of STM32373C-EVAL board
+ * @{
+ */
+
+/** @defgroup STM32373C_EVAL_CEC_Private_Types
+ * @{
+ */
+
+/**
+ * @}
+ */
+
+/** @defgroup STM32373C_EVAL_CEC_Private_Defines
+ * @{
+ */
+
+/* Uncomment the define to use the LSE as a source clock */
+/* #define LSE_SOURCE_CLK */
+
+/**
+ * @}
+ */
+
+/** @defgroup STM32373C_EVAL_CEC_Private_Macros
+ * @{
+ */
+/**
+ * @}
+ */
+
+/** @defgroup STM32373C_EVAL_CEC_Private_Variables
+ * @{
+ */
+
+__IO uint32_t ReceivedFrame = 0;
+__IO uint32_t SendFrame = 0;
+uint32_t BufferCount = 0, TxCounter = 0, RxCounter = 0;
+__IO uint8_t BufferPointer[15];
+__IO uint32_t ReceiveStatus = 0;
+__IO uint32_t SendStatus = 0;
+__IO uint8_t TransErrorCode = 0;
+uint8_t MyLogicalAddress = 0;
+uint16_t MyPhysicalAddress = 0;
+__IO uint8_t DeviceType = 0;
+#ifdef HDMI_CEC_USE_DDC
+uint8_t pBuffer[256];
+__IO uint16_t NumByteToRead = 255;
+#endif
+
+__IO uint8_t CECDevicesNumber = 0;
+HDMI_CEC_Message HDMI_CEC_TX_MessageStructPrivate;
+HDMI_CEC_Message HDMI_CEC_RX_MessageStructPrivate;
+HDMI_CEC_Message HDMI_CEC_TX_MessageStructure;
+
+__IO uint8_t FeatureOpcode = 0;
+__IO uint8_t AbortReason = 0;
+__IO uint8_t DeviceCount = 0;
+
+HDMI_CEC_Map HDMI_CEC_MapStruct;
+HDMI_CEC_Map HDMI_CEC_DeviceMap[14];
+
+/* CEC follower addresses */
+uint8_t* HDMI_CEC_Follower_String[13][2] =
+ {
+ {(uint8_t *)" TV ", (uint8_t *)"0"},
+ {(uint8_t *)" Recording Device 1 ", (uint8_t *)"0"},
+ {(uint8_t *)" Recording Device 2 ", (uint8_t *)"0"},
+ {(uint8_t *)" Tuner 1 ", (uint8_t *)"0"},
+ {(uint8_t *)" Playback Device 1 ", (uint8_t *)"0"},
+ {(uint8_t *)" Audio System ", (uint8_t *)"0"},
+ {(uint8_t *)" Tuner 2 ", (uint8_t *)"0"},
+ {(uint8_t *)" Tuner 3 ", (uint8_t *)"0"},
+ {(uint8_t *)" Playback Device 2 ", (uint8_t *)"0"},
+ {(uint8_t *)" Recording Device 3 ", (uint8_t *)"0"},
+ {(uint8_t *)" Tuner 4 ", (uint8_t *)"0"},
+ {(uint8_t *)" Playback Device 3 ", (uint8_t *)"0"},
+ {(uint8_t *)" Broadcast ", (uint8_t *)"1"}
+ };
+
+/* EDID & CEA861 Extension */
+const uint8_t EDID_Structure[256] =
+{
+ /*-------------------------- Block0: 128Bytes ------------------------------*/
+ /* Header */
+ 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00,
+ /* Vendor & Product Identification */
+ 0x4C, 0x2D, 0x57, 0x03, 0x00, 0x00, 0x00, 0x00, 0x22, 0x11,
+ /* EDID Structure Version & Revision */
+ 0x01, 0x03,
+ /* Basic Display Parameters & Features */
+ 0x80, 0x10, 0x09, 0x78, 0x0A,
+ /* Color Characteristics */
+ 0x1D, 0xED, 0xA7, 0x53, 0x34, 0xAC, 0x25, 0x12, 0x47, 0x4A,
+ /* Established Timings */
+ 0x20, 0x00, 0x00,
+ /* Standard Timings */
+ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+ 0x01, 0x01, 0x01,
+ /* Byte Data Blocks*/
+ 0x02, 0x3A, 0x80, 0x18, 0x71, 0x38, 0x2D, 0x40, 0x58, 0x2C, 0x45, 0x00, 0xA0,
+ 0x5A, 0x00, 0x00, 0x00, 0x1E, 0x01, 0x1D, 0x00, 0x72, 0x51, 0xD0, 0x1E, 0x20,
+ 0x6E, 0x28, 0x55, 0x00, 0xA0, 0x5A, 0x00, 0x00, 0x00, 0x1E, 0x00, 0x00, 0x00,
+ 0xFD, 0x00, 0x17, 0x3D, 0x1A, 0x44, 0x17, 0x00, 0x0A, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x00, 0x00, 0x00, 0xFC, 0x00, 0x53, 0x41, 0x4D, 0x53, 0x55, 0x4E,
+ 0x47, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20,
+ /* Extension Block Count */
+ 0x01,
+ /* Checksum C */
+ 0xF3,
+ /* ------------------------ Block1: 128Bytes------------------------------- */
+ /* Refer to CEA 861 Standard for definitions */
+ /* CEA 861 EXTENSION Block – Version 3 */
+ 0x02, 0x03,
+ /* Byte number within this block where the 18-byte DTDs begin */
+ 0x21,
+ /* Number of DTDs present */
+ 0x00,
+ /* Start of Data Block Collection */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ /* IEEE Registration Identifier */
+ 0x03, 0x0C, 0x00,
+ /* Vendor Specific Data: Physical Address */
+ 0x10, 0x00,
+ /* Byte Data Blocks */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00
+};
+
+/**
+ * @}
+ */
+
+/** @defgroup STM32373C_EVAL_CEC_Private_Function_Prototypes
+ * @{
+ */
+static HDMI_CEC_Error SinkPhysicalAddressDiscovery(void);
+static HDMI_CEC_Error SourcePhysicalAddressDiscovery(void);
+static HDMI_CEC_Error LogicalAddressAllocation(void);
+
+/**
+ * @}
+ */
+
+/** @defgroup STM32373C_EVAL_CEC_Private_Functions
+ * @{
+ */
+
+/**
+ * @brief Initializes the HDMI CEC.
+ * @param None
+ * @retval HDMI_CEC_Error: CEC Error code
+ */
+HDMI_CEC_Error HDMI_CEC_Init(void)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+ CEC_InitTypeDef CEC_InitStructure;
+ HDMI_CEC_Error errorstatus = HDMI_CEC_OK;
+ uint8_t sendcount = 0;
+ uint32_t idx = 0;
+
+#ifdef LSE_SOURCE_CLK
+ /* LSE */
+ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
+ PWR_BackupAccessCmd(ENABLE);
+
+ RCC_LSEConfig(RCC_LSE_ON);
+ while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
+ {}
+
+ RCC_CECCLKConfig(RCC_CECCLK_LSE);
+#endif
+
+ for(idx=0; idx<12; idx++)
+ {
+ HDMI_CEC_Follower_String[idx][1] = (uint8_t *)"0";
+ }
+
+ /* Enable CEC and PWR clocks */
+ RCC_APB1PeriphClockCmd(RCC_APB1Periph_CEC | RCC_APB1Periph_PWR, ENABLE);
+
+ /* Enable CEC_LINE_GPIO clocks */
+ RCC_AHBPeriphClockCmd(HDMI_CEC_LINE_GPIO_CLK, ENABLE);
+
+ /* Configure CEC_LINE_GPIO as Output open drain */
+ GPIO_InitStructure.GPIO_Pin = HDMI_CEC_LINE_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
+ GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
+ GPIO_Init(HDMI_CEC_LINE_GPIO_PORT, &GPIO_InitStructure);
+
+ GPIO_PinAFConfig(HDMI_CEC_LINE_GPIO_PORT,HDMI_CEC_LINE_PIN_SOURCE,HDMI_CEC_GPIO_AF);
+
+ /* CEC DeInit */
+ CEC_DeInit();
+
+ /* Configure CEC */
+ CEC_InitStructure.CEC_SignalFreeTime = CEC_SignalFreeTime_Standard/*CEC_SignalFreeTime_1T*/;
+ CEC_InitStructure.CEC_RxTolerance = CEC_RxTolerance_Standard;
+ CEC_InitStructure.CEC_StopReception = CEC_StopReception_Off;
+ CEC_InitStructure.CEC_BitRisingError = CEC_BitRisingError_Off;
+ CEC_InitStructure.CEC_LongBitPeriodError = CEC_LongBitPeriodError_Off;
+ CEC_InitStructure.CEC_BRDNoGen = CEC_BRDNoGen_Off;
+ CEC_InitStructure.CEC_SFTOption = CEC_SFTOption_Off;
+ CEC_Init(&CEC_InitStructure);
+
+ /* Disable Listen Mode */
+ CEC_ListenModeCmd(DISABLE);
+
+ /* Enable CEC */
+ CEC_Cmd(ENABLE);
+
+ if (HDMI_CEC_ROOT == 0x1)
+ {
+ /* Logical Address Allocation */
+ sendcount = 0;
+ errorstatus = LogicalAddressAllocation();
+
+ while ((errorstatus != HDMI_CEC_OK) && sendcount < 0x5)
+ {
+ sendcount++;
+ errorstatus = LogicalAddressAllocation();
+ }
+
+ if (errorstatus != HDMI_CEC_OK)
+ {
+ /* Device Unregistered */
+ return(errorstatus);
+ }
+
+ HDMI_CEC_CheckConnectedDevices();
+
+ /* Set the CEC initiator address */
+ CEC_OwnAddressConfig(MyLogicalAddress);
+
+ /* Sink Physical Address discovery */
+ errorstatus = SinkPhysicalAddressDiscovery();
+
+ if (errorstatus != HDMI_CEC_OK)
+ {
+ /* Device not connected (Physical Address lost) */
+ return(errorstatus);
+ }
+ }
+ else
+ {
+ /* Source Physical Address discovery */
+ errorstatus = SourcePhysicalAddressDiscovery();
+
+ if (errorstatus != HDMI_CEC_OK)
+ {
+ /* Device not connected (Physical Address lost) */
+ return(errorstatus);
+ }
+
+ /* Logical Address Allocation */
+ sendcount = 0;
+ errorstatus = LogicalAddressAllocation();
+
+ while ((errorstatus != HDMI_CEC_OK) && sendcount < 0x5)
+ {
+ sendcount++;
+ errorstatus = LogicalAddressAllocation();
+ }
+
+ if (errorstatus != HDMI_CEC_OK)
+ {
+ /* Device Unregistered */
+ return(errorstatus);
+ }
+
+ HDMI_CEC_CheckConnectedDevices();
+
+ /* Set the CEC initiator address */
+ CEC_OwnAddressConfig(MyLogicalAddress);
+ }
+
+ /* Activate CEC interrupts associated to the set of TX flags */
+ CEC_ITConfig(CEC_IT_TXEND|CEC_IT_TXBR,ENABLE);
+
+ /* Activate CEC interrupts associated to the set of RX flags */
+ CEC_ITConfig(CEC_IT_RXEND|CEC_IT_RXBR,ENABLE);
+
+ /* Activate CEC interrupts associated to the set of TX error */
+ CEC_ITConfig(CEC_IT_TXACKE|CEC_IT_TXERR|CEC_IT_TXUDR|CEC_IT_ARBLST,ENABLE);
+
+ /* Activate CEC interrupts associated to the set of RX error */
+ CEC_ITConfig(CEC_IT_RXACKE|CEC_IT_LBPE|CEC_IT_SBPE|CEC_IT_BRE|CEC_IT_RXOVR,ENABLE);
+
+ /* Report physical address */
+ errorstatus = HDMI_CEC_ReportPhysicalAddress();
+ sendcount = 0;
+ RxCounter = 0;
+
+ while ((errorstatus != HDMI_CEC_OK) && sendcount < 0x5)
+ {
+ sendcount++;
+ errorstatus = HDMI_CEC_ReportPhysicalAddress();
+ }
+
+ if (errorstatus != HDMI_CEC_OK)
+ {
+ /* Device Unregistred */
+ return(errorstatus);
+ }
+ return errorstatus;
+}
+
+/**
+ * @brief Transmit message by taking data from typedef struct CEC_Meassage
+ * @param CEC_TX_MessageStructure: pointer to an CEC_Message structure that contains
+ * the message to be sent.
+ * @retval HDMI_CEC_Error: CEC Error code
+ */
+HDMI_CEC_Error HDMI_CEC_TransmitMessage(HDMI_CEC_Message *HDMI_CEC_TX_MessageStructure)
+{
+ HDMI_CEC_Error errorstatus = HDMI_CEC_OK;
+ __IO uint32_t count = 0, j = 0;
+
+ SendFrame = 0;
+ SendStatus = 0;
+ TxCounter = 0;
+ BufferCount = 0;
+
+ HDMI_CEC_TX_MessageStructPrivate = *HDMI_CEC_TX_MessageStructure;
+
+ /* Initialize BufferPointer */
+ for (j = 0; j < 15; j++)
+ {
+ BufferPointer[j] = 0;
+ }
+
+ BufferPointer[0] = HDMI_CEC_TX_MessageStructPrivate.Opcode;
+
+ for (BufferCount = 1; BufferCount < HDMI_CEC_TX_MessageStructPrivate.TxMessageLength + 1; BufferCount++)
+ {
+ BufferPointer[BufferCount] = HDMI_CEC_TX_MessageStructPrivate.Operande[BufferCount - 1];
+ }
+
+ CEC_ClearFlag(CEC_FLAG_TXBR|CEC_FLAG_TXEND);
+
+ /* Write single Data in the TX Buffer to Transmit through the CEC peripheral */
+ CEC_SendData(HDMI_CEC_TX_MessageStructPrivate.Header);
+
+ /* Initiate Message Transmission */
+ CEC_StartOfMessage();
+
+ while ((SendFrame == 0) && (count < HDMI_CEC_TIMEOUT_VALUE))
+ {
+ count++;
+ }
+ if (count >= HDMI_CEC_TIMEOUT_VALUE)
+ {
+ errorstatus = HDMI_CEC_TIMEOUT;
+ return(errorstatus);
+ }
+
+ if (SendStatus == 0)
+ {
+ errorstatus = (HDMI_CEC_Error) TransErrorCode;
+ }
+ return errorstatus;
+}
+
+/**
+ * @brief Get the ISR register status.
+ * @param None
+ * @retval HDMI_CEC_Error: CEC Error code
+ */
+HDMI_CEC_Error HDMI_CEC_GetErrorStatus (void)
+{
+ HDMI_CEC_Error errorstatus = HDMI_CEC_OK;
+
+ /* RX Overrun error case*/
+ if (CEC_GetFlagStatus(CEC_FLAG_RXOVR) != RESET)
+ {
+ errorstatus = HDMI_CEC_RX_OVERRUN;
+ CEC_ClearFlag(CEC_FLAG_RXOVR);
+ }
+ /* Bit Rising error case */
+ if (CEC_GetFlagStatus(CEC_FLAG_BRE) != RESET)
+ {
+ errorstatus = HDMI_CEC_RX_BIT_RISING;
+ CEC_ClearFlag(CEC_FLAG_BRE);
+ }
+ /* Short Bit Period error case */
+ if (CEC_GetFlagStatus(CEC_FLAG_SBPE) != RESET)
+ {
+ errorstatus = HDMI_CEC_RX_SHORT_BIT_PERIOD;
+ CEC_ClearFlag(CEC_FLAG_SBPE);
+ }
+ /* Long Bit Period error case */
+ if (CEC_GetFlagStatus(CEC_FLAG_LBPE) != RESET)
+ {
+ errorstatus = HDMI_CEC_RX_LONG_BIT_PERIOD;
+ CEC_ClearFlag(CEC_FLAG_LBPE);
+ }
+ /* RX Acknowledge error case */
+ if (CEC_GetFlagStatus(CEC_FLAG_RXACKE) != RESET)
+ {
+ errorstatus = HDMI_CEC_RX_ACKNOWLEDGE;
+ CEC_ClearFlag(CEC_FLAG_RXACKE);
+ }
+ /* Arbitration Lost error case */
+ if (CEC_GetFlagStatus(CEC_FLAG_ARBLST) != RESET)
+ {
+ errorstatus = HDMI_CEC_ARBITRATION_LOST;
+ CEC_ClearFlag(CEC_FLAG_ARBLST);
+ }
+ /* TX underrun error case */
+ if (CEC_GetFlagStatus(CEC_FLAG_TXUDR) != RESET)
+ {
+ errorstatus = HDMI_CEC_TX_UNDERRUN;
+ CEC_ClearFlag(CEC_FLAG_TXUDR);
+ }
+ /* TX error case */
+ if (CEC_GetFlagStatus(CEC_FLAG_TXERR) != RESET)
+ {
+ errorstatus = HDMI_CEC_TX_ERROR;
+ CEC_ClearFlag(CEC_FLAG_TXERR);
+ }
+ /* TX Acknowledge error case */
+ if (CEC_GetFlagStatus(CEC_FLAG_TXACKE) != RESET)
+ {
+ errorstatus = HDMI_CEC_TX_ACKNOWLEDGE;
+ CEC_ClearFlag(CEC_FLAG_TXACKE);
+ }
+ return errorstatus;
+}
+
+/**
+ * @brief Allows to process all the interrupts that are high.
+ * @param None
+ * @retval None
+ */
+void HDMI_CEC_ProcessIRQSrc(void)
+{
+ /********************** Reception *******************************************/
+ /* Check if a reception error occured */
+ if (CEC->ISR & (CEC_IT_RXACKE | CEC_IT_LBPE | CEC_IT_SBPE | CEC_IT_BRE | CEC_IT_RXOVR))
+ {
+ /* Set receive status bit (Error) */
+ ReceiveStatus = 0;
+ ReceivedFrame = 1;
+ CEC->ISR = (CEC_IT_RXACKE | CEC_IT_LBPE | CEC_IT_SBPE | CEC_IT_BRE | CEC_IT_RXOVR);
+ }
+
+ if (CEC_GetITStatus(CEC_IT_RXBR))
+ {
+ /* Check if the byte received is a Header */
+ if (RxCounter == 0)
+ {
+ HDMI_CEC_RX_MessageStructPrivate.Header = CEC_ReceiveData();
+ RxCounter ++;
+ }
+ else if(RxCounter == 1) /* Receive opcode in the reception buffer */
+ {
+ HDMI_CEC_RX_MessageStructPrivate.Opcode = CEC_ReceiveData();
+ RxCounter++;
+ }
+ else /* Receive each byte except header and opcode in the reception buffer */
+ {
+ HDMI_CEC_RX_MessageStructPrivate.Operande[RxCounter-2] = CEC_ReceiveData();
+ RxCounter++;
+ }
+ CEC_ClearITPendingBit(CEC_IT_RXBR);
+ }
+
+ /* Check if the byte received is the last one of the message */
+ if (CEC_GetITStatus(CEC_IT_RXEND))
+ {
+ if (RxCounter == 1)
+ {
+
+ HDMI_CEC_RX_MessageStructPrivate.RxMessageLength = RxCounter-1;
+ }
+ else
+ {
+ HDMI_CEC_RX_MessageStructPrivate.RxMessageLength = RxCounter-2;
+ ReceivedFrame = 1;
+ }
+
+ /* Set the receive status */
+ ReceiveStatus = SUCCESS;
+ RxCounter = 0;
+
+ /* Clear all reception flags */
+ CEC_ClearITPendingBit(CEC_IT_RXEND);
+ }
+
+ /********************** Transmission ****************************************/
+ /* Check if a transmission error occurred */
+ if (CEC->ISR & (CEC_IT_TXACKE | CEC_IT_TXERR | CEC_IT_TXUDR | CEC_IT_ARBLST))
+ {
+ TransErrorCode = HDMI_CEC_GetErrorStatus();
+ CEC->ISR = (CEC_IT_TXACKE | CEC_IT_TXERR | CEC_IT_TXUDR | CEC_IT_ARBLST);
+ SendFrame = 1;
+ SendStatus = 0;
+ }
+
+ /* Check if end of message bit is set in the data to be transmitted */
+ if (CEC_GetITStatus(CEC_IT_TXEND))
+ {
+ CEC_ClearITPendingBit(CEC_IT_TXEND | CEC_IT_TXBR);
+ SendFrame = 1;
+ SendStatus = SUCCESS;
+ }
+ /* Check if data byte has been sent */
+ else if (CEC_GetITStatus(CEC_IT_TXBR))
+ {
+ /* Set EOM bit if the byte to be transmitted is the last one of the Transmit Buffer */
+ if (TxCounter == (HDMI_CEC_TX_MessageStructPrivate.TxMessageLength))
+ {
+ CEC_EndOfMessage();
+ CEC_SendData(BufferPointer[TxCounter++]);
+ }
+ else
+ {
+ /* Put the byte in the TX Buffer */
+ CEC_SendData(BufferPointer[TxCounter++]);
+ }
+ CEC_ClearITPendingBit(CEC_IT_TXBR);
+ }
+}
+
+/**
+ * @brief Report physical address to all other devices thus allowing any
+ device to create a map of the network.
+ * @param None
+ * @retval HDMI_CEC_Error: CEC Error code.
+ */
+HDMI_CEC_Error HDMI_CEC_ReportPhysicalAddress(void)
+{
+ HDMI_CEC_Error errorstatus = HDMI_CEC_OK;
+ HDMI_CEC_Message HDMI_CEC_TX_Message;
+
+ HDMI_CEC_TX_Message.Header = ((MyLogicalAddress << 4) | 0xF);
+ HDMI_CEC_TX_Message.Opcode = HDMI_CEC_OPCODE_REPORT_PHYSICAL_ADDRESS;
+ HDMI_CEC_TX_Message.Operande[0] = MyPhysicalAddress >> 8;
+ HDMI_CEC_TX_Message.Operande[1] = MyPhysicalAddress & 0xFF;
+ HDMI_CEC_TX_Message.Operande[2] = DeviceType;
+ HDMI_CEC_TX_Message.TxMessageLength = 0x03;
+
+ errorstatus = HDMI_CEC_TransmitMessage(&HDMI_CEC_TX_Message);
+
+ return errorstatus;
+}
+
+/**
+ * @brief Handle CEC command receive callback.
+ * When receiving the STANDBY Opcode command, the system is entered in
+ * Stop mode and when wakeup, the PLL is configured as system clock and
+ * the HSI is selected as PLL source.
+ * @param None
+ * @retval None
+ */
+void HDMI_CEC_CommandCallBack(void)
+{
+ uint8_t i = 0, sendcount = 0;
+ HDMI_CEC_Error errorstatus = HDMI_CEC_OK;
+ ErrorStatus HSEStartUpStatus;
+
+ switch (HDMI_CEC_RX_MessageStructPrivate.Opcode)
+ {
+ case HDMI_CEC_OPCODE_REPORT_PHYSICAL_ADDRESS:
+ HDMI_CEC_MapStruct.PhysicalAddress_A = HDMI_CEC_RX_MessageStructPrivate.Operande[1] >> 4;
+ HDMI_CEC_MapStruct.PhysicalAddress_B = HDMI_CEC_RX_MessageStructPrivate.Operande[1] & 0x0F;
+ HDMI_CEC_MapStruct.PhysicalAddress_C = HDMI_CEC_RX_MessageStructPrivate.Operande[0] >> 4;
+ HDMI_CEC_MapStruct.PhysicalAddress_D = HDMI_CEC_RX_MessageStructPrivate.Operande[0] & 0x0F;
+ HDMI_CEC_MapStruct.LogicalAddress = (HDMI_CEC_RX_MessageStructPrivate.Header >> 0x4) & 0x0F;
+ HDMI_CEC_MapStruct.DeviceType = HDMI_CEC_RX_MessageStructPrivate.Operande[2];
+ HDMI_CEC_DeviceMap[DeviceCount] = HDMI_CEC_MapStruct;
+ HDMI_CEC_Follower_String[(HDMI_CEC_DeviceMap[DeviceCount].LogicalAddress)][1] = (uint8_t *)"1";
+ DeviceCount++;
+ break;
+
+ case HDMI_CEC_OPCODE_STANDBY:
+
+ /* Request to enter Stop mode */
+ PWR_EnterSTOPMode(PWR_Regulator_ON, PWR_STOPEntry_WFI);
+
+ /* Enable HSE */
+ RCC_HSEConfig(RCC_HSE_ON);
+
+ /* Wait till HSE is ready */
+ HSEStartUpStatus = RCC_WaitForHSEStartUp();
+ if (HSEStartUpStatus == SUCCESS)
+ {
+ /* Enable PLL */
+ RCC_PLLCmd(ENABLE);
+ /* Wait till PLL is ready */
+ while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
+ {}
+ /* Select PLL as system clock source */
+ RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
+ /* Wait till PLL is used as system clock source */
+ while (RCC_GetSYSCLKSource() != 0x08)
+ {}
+ }
+ break;
+
+ case HDMI_CEC_OPCODE_GET_CEC_VERSION:
+ /* Send the Used CEC version */
+ HDMI_CEC_TX_MessageStructPrivate.Header = ((MyLogicalAddress << 4) | HDMI_CEC_RX_MessageStructPrivate.Header >> 4);
+ HDMI_CEC_TX_MessageStructPrivate.Opcode = HDMI_CEC_OPCODE_CEC_VERSION;
+ HDMI_CEC_TX_MessageStructPrivate.Operande[0] = HDMI_CEC_VERSION; /* CEC Version */
+ HDMI_CEC_TX_MessageStructPrivate.TxMessageLength = 0x01;
+ errorstatus = HDMI_CEC_TransmitMessage(&HDMI_CEC_TX_MessageStructPrivate);
+
+ /* Retransmit message until 5 time */
+ while ((errorstatus != HDMI_CEC_OK) && sendcount < 0x5)
+ {
+ sendcount++;
+ errorstatus = HDMI_CEC_TransmitMessage(&HDMI_CEC_TX_MessageStructPrivate);
+ }
+ break;
+
+ case HDMI_CEC_OPCODE_GIVE_PHYSICAL_ADDRESS:
+ /* Send the Physical address */
+ errorstatus = HDMI_CEC_ReportPhysicalAddress();
+ sendcount = 0;
+ /* Retransmit message until 5 time */
+ while ((errorstatus != HDMI_CEC_OK) && sendcount < 0x5)
+ {
+ sendcount++;
+ errorstatus = HDMI_CEC_ReportPhysicalAddress();
+ }
+ break;
+
+ case HDMI_CEC_OPCODE_FEATURE_ABORT:
+ /* The device doesn't support the requested message type, or that it cannot
+ execute it at the present time. */
+ FeatureOpcode = HDMI_CEC_RX_MessageStructPrivate.Operande[0];
+ AbortReason = HDMI_CEC_RX_MessageStructPrivate.Operande[1];
+ break;
+
+ case HDMI_CEC_OPCODE_GIVE_OSD_NAME:
+ /* Send the OSD name = STM32373C CEC */
+ HDMI_CEC_TX_MessageStructPrivate.Header = ((MyLogicalAddress << 4) | HDMI_CEC_RX_MessageStructPrivate.Header >> 4);
+ HDMI_CEC_TX_MessageStructPrivate.Opcode = HDMI_CEC_OPCODE_SET_OSD_NAME;
+ /* STM32373C */
+ HDMI_CEC_TX_MessageStructPrivate.Operande[0] = 0x53;
+ HDMI_CEC_TX_MessageStructPrivate.Operande[1] = 0x54;
+ HDMI_CEC_TX_MessageStructPrivate.Operande[2] = 0x4D;
+ HDMI_CEC_TX_MessageStructPrivate.Operande[3] = 0x33;
+ HDMI_CEC_TX_MessageStructPrivate.Operande[4] = 0x32;
+ HDMI_CEC_TX_MessageStructPrivate.Operande[5] = 0x33;
+ HDMI_CEC_TX_MessageStructPrivate.Operande[6] = 0x37;
+ HDMI_CEC_TX_MessageStructPrivate.Operande[7] = 0x33;
+ HDMI_CEC_TX_MessageStructPrivate.Operande[8] = 0x43;
+ HDMI_CEC_TX_MessageStructPrivate.Operande[9] = 0x20;
+ /* CEC */
+ HDMI_CEC_TX_MessageStructPrivate.Operande[10] = 0x43;
+ HDMI_CEC_TX_MessageStructPrivate.Operande[11] = 0x45;
+ HDMI_CEC_TX_MessageStructPrivate.Operande[12] = 0x43;
+ HDMI_CEC_TX_MessageStructPrivate.TxMessageLength = 13;
+ errorstatus = HDMI_CEC_TransmitMessage(&HDMI_CEC_TX_MessageStructPrivate);
+ sendcount = 0;
+ /* Retransmit message until 5 time */
+ while ((errorstatus != HDMI_CEC_OK) && sendcount < 0x5)
+ {
+ sendcount++;
+ errorstatus = HDMI_CEC_TransmitMessage(&HDMI_CEC_TX_MessageStructPrivate);
+ }
+ break;
+
+ case HDMI_CEC_OPCODE_ROUTING_CHANGE:
+ for (i = 0;i < 0x14;i++)
+ {
+ if ((HDMI_CEC_DeviceMap[i].PhysicalAddress_A == (HDMI_CEC_RX_MessageStructPrivate.Operande[1] >> 4)) &&
+ (HDMI_CEC_DeviceMap[i].PhysicalAddress_B == (HDMI_CEC_RX_MessageStructPrivate.Operande[1]&0x0F)) &&
+ (HDMI_CEC_DeviceMap[i].PhysicalAddress_C == (HDMI_CEC_RX_MessageStructPrivate.Operande[0] >> 4)) &&
+ (HDMI_CEC_DeviceMap[i].PhysicalAddress_D == (HDMI_CEC_RX_MessageStructPrivate.Operande[0]&0x0F)))
+ {
+ HDMI_CEC_MapStruct.LogicalAddress = (HDMI_CEC_RX_MessageStructPrivate.Header >> 0x4) & 0x0F;
+ HDMI_CEC_MapStruct.DeviceType = HDMI_CEC_RX_MessageStructPrivate.Operande[2];
+ HDMI_CEC_DeviceMap[i] = HDMI_CEC_MapStruct;
+ }
+ }
+ break;
+
+ default:
+ /* Send Abort feature */
+ HDMI_CEC_TX_MessageStructPrivate.Header = ((MyLogicalAddress << 4) | HDMI_CEC_RX_MessageStructPrivate.Header >> 4);
+ HDMI_CEC_TX_MessageStructPrivate.Opcode = HDMI_CEC_OPCODE_FEATURE_ABORT;
+ HDMI_CEC_TX_MessageStructPrivate.Operande[0] = 0x02; /* Defines command to be performed */
+ HDMI_CEC_TX_MessageStructPrivate.Operande[1] = HDMI_CEC_REFUSED; /* Reason for abort feature */
+ HDMI_CEC_TX_MessageStructPrivate.TxMessageLength = 0x02;
+ errorstatus = HDMI_CEC_TransmitMessage(&HDMI_CEC_TX_MessageStructPrivate);
+ sendcount = 0;
+ /* Retransmit message until 5 time */
+ while ((errorstatus != HDMI_CEC_OK) && sendcount < 0x5)
+ {
+ sendcount++;
+ errorstatus = HDMI_CEC_TransmitMessage(&HDMI_CEC_TX_MessageStructPrivate);
+ }
+ break;
+ }
+}
+
+/**
+ * @brief Check the connected CEC devices.
+ * @param None
+ * @retval HDMI_CEC_Error
+ */
+HDMI_CEC_Error HDMI_CEC_CheckConnectedDevices(void)
+{
+ HDMI_CEC_Error errorstatus = HDMI_CEC_OK;
+ uint32_t count = 0, i = 1;
+
+ /*------------------------------- TV device --------------------------------*/
+ CEC_EndOfMessage();
+
+ CEC_SendData((MyLogicalAddress << 4) | 0x0);
+
+ /* Start of message */
+ CEC_StartOfMessage();
+
+ /* Wait till the header message is sent */
+ while (count < HDMI_CEC_TIMEOUT_VALUE)
+ {
+ if (CEC_GetFlagStatus(CEC_FLAG_TXACKE) != RESET)
+ {
+ errorstatus = HDMI_CEC_GetErrorStatus();
+ CEC_ClearFlag( CEC_FLAG_TXACKE);
+ break;
+ }
+ else if(CEC_GetFlagStatus(CEC_FLAG_TXEND) != RESET)
+ {
+ errorstatus = HDMI_CEC_OK;
+ break;
+ }
+ count++;
+ }
+
+ if (count >= HDMI_CEC_TIMEOUT_VALUE)
+ {
+ errorstatus = HDMI_CEC_TIMEOUT;
+ return(errorstatus);
+ }
+
+ if (errorstatus == HDMI_CEC_OK)
+ {
+ HDMI_CEC_Follower_String[0][1] = (uint8_t *)"1";
+ i++;
+ errorstatus = HDMI_CEC_OK;
+ }
+
+ /* Clear CEC ISR register */
+ CEC_ClearFlag(CEC_FLAG_TXBR|CEC_FLAG_TXEND);
+
+ /*---------------------------- Recording device 1 --------------------------*/
+ CEC_EndOfMessage();
+
+ CEC_SendData((MyLogicalAddress << 4)|0x1);
+
+ /* Start of message */
+ CEC_StartOfMessage();
+
+ /* Wait till the header message is sent */
+ while (count < HDMI_CEC_TIMEOUT_VALUE)
+ {
+ if (CEC_GetFlagStatus(CEC_FLAG_TXACKE) != RESET)
+ {
+ errorstatus = HDMI_CEC_GetErrorStatus();
+ CEC_ClearFlag( CEC_FLAG_TXACKE);
+ break;
+ }
+ else if(CEC_GetFlagStatus(CEC_FLAG_TXEND) != RESET)
+ {
+ errorstatus = HDMI_CEC_OK;
+ break;
+ }
+ count++;
+ }
+ if (count >= HDMI_CEC_TIMEOUT_VALUE)
+ {
+ errorstatus = HDMI_CEC_TIMEOUT;
+ return(errorstatus);
+ }
+
+ if (errorstatus == HDMI_CEC_OK)
+ {
+ HDMI_CEC_Follower_String[1][1] = (uint8_t *)"1";
+ i++;
+ errorstatus = HDMI_CEC_OK;
+ }
+
+ /* Clear CEC ISR register */
+ CEC_ClearFlag(CEC_FLAG_TXBR|CEC_FLAG_TXEND);
+
+ /*---------------------------- Recording device 2 --------------------------*/
+ CEC_EndOfMessage();
+
+ CEC_SendData((MyLogicalAddress << 4) | 0x2);
+
+ /* Start of message */
+ CEC_StartOfMessage();
+
+ /* Wait till the header message is sent */
+ while (count < HDMI_CEC_TIMEOUT_VALUE)
+ {
+ if (CEC_GetFlagStatus(CEC_FLAG_TXACKE) != RESET)
+ {
+ errorstatus = HDMI_CEC_GetErrorStatus();
+ CEC_ClearFlag( CEC_FLAG_TXACKE);
+ break;
+ }
+ else if(CEC_GetFlagStatus(CEC_FLAG_TXEND) != RESET)
+ {
+ errorstatus = HDMI_CEC_OK;
+ break;
+ }
+ count++;
+ }
+
+ if (count >= HDMI_CEC_TIMEOUT_VALUE)
+ {
+ errorstatus = HDMI_CEC_TIMEOUT;
+ return(errorstatus);
+ }
+
+ if (errorstatus == HDMI_CEC_OK)
+ {
+ HDMI_CEC_Follower_String[2][1] = (uint8_t *)"1";
+ i++;
+ errorstatus = HDMI_CEC_OK;
+ }
+
+ /* Clear CEC ISR register */
+ CEC_ClearFlag(CEC_FLAG_TXBR|CEC_FLAG_TXEND);
+
+ /*------------------------------ Tuner 1 -----------------------------------*/
+ CEC_EndOfMessage();
+
+ CEC_SendData((MyLogicalAddress << 4) | 0x3);
+
+ /* Start of message */
+ CEC_StartOfMessage();
+
+ /* Wait till the header message is sent */
+ while (count < HDMI_CEC_TIMEOUT_VALUE)
+ {
+ if (CEC_GetFlagStatus(CEC_FLAG_TXACKE) != RESET)
+ {
+ errorstatus = HDMI_CEC_GetErrorStatus();
+ CEC_ClearFlag( CEC_FLAG_TXACKE);
+ break;
+ }
+ else if(CEC_GetFlagStatus(CEC_FLAG_TXEND) != RESET)
+ {
+ errorstatus = HDMI_CEC_OK;
+ break;
+ }
+ count++;
+ }
+ if (count >= HDMI_CEC_TIMEOUT_VALUE)
+ {
+ errorstatus = HDMI_CEC_TIMEOUT;
+ return(errorstatus);
+ }
+
+ if (errorstatus == HDMI_CEC_OK)
+ {
+ HDMI_CEC_Follower_String[3][1] = (uint8_t *)"1";
+ i++;
+ errorstatus = HDMI_CEC_OK;
+ }
+ /* Clear CEC ISR register */
+ CEC_ClearFlag(CEC_FLAG_TXBR|CEC_FLAG_TXEND);
+
+ /*---------------------------- Playback device 1 ---------------------------*/
+ CEC_EndOfMessage();
+
+ CEC_SendData((MyLogicalAddress << 4) | 0x4);
+
+ /* Start of message */
+ CEC_StartOfMessage();
+
+ /* Wait till the header message is sent */
+ while (count < HDMI_CEC_TIMEOUT_VALUE)
+ {
+ if (CEC_GetFlagStatus(CEC_FLAG_TXACKE) != RESET)
+ {
+ errorstatus = HDMI_CEC_GetErrorStatus();
+ CEC_ClearFlag(CEC_FLAG_TXACKE);
+ break;
+ }
+ else if(CEC_GetFlagStatus(CEC_FLAG_TXEND) != RESET)
+ {
+ errorstatus = HDMI_CEC_OK;
+ break;
+ }
+ count++;
+ }
+
+ if (count >= HDMI_CEC_TIMEOUT_VALUE)
+ {
+ errorstatus = HDMI_CEC_TIMEOUT;
+ return(errorstatus);
+ }
+
+ if (errorstatus == HDMI_CEC_OK)
+ {
+ HDMI_CEC_Follower_String[4][1] = (uint8_t *)"1";
+ i++;
+ errorstatus = HDMI_CEC_OK;
+ }
+ /* Clear CEC ISR register */
+ CEC_ClearFlag(CEC_FLAG_TXBR|CEC_FLAG_TXEND);
+
+ /*-------------------------------- Audio system ----------------------------*/
+ CEC_EndOfMessage();
+
+ CEC_SendData((MyLogicalAddress << 4) | 0x5);
+
+ /* Start of message */
+ CEC_StartOfMessage();
+
+ /* Wait till the header message is sent */
+ while (count < HDMI_CEC_TIMEOUT_VALUE)
+ {
+ if (CEC_GetFlagStatus(CEC_FLAG_TXACKE) != RESET)
+ {
+ errorstatus = HDMI_CEC_GetErrorStatus();
+ CEC_ClearFlag(CEC_FLAG_TXACKE);
+ break;
+ }
+ else if(CEC_GetFlagStatus(CEC_FLAG_TXEND) != RESET)
+ {
+ errorstatus = HDMI_CEC_OK;
+ break;
+ }
+ count++;
+ }
+
+ if (count >= HDMI_CEC_TIMEOUT_VALUE)
+ {
+ errorstatus = HDMI_CEC_TIMEOUT;
+ return(errorstatus);
+ }
+
+ if (errorstatus == HDMI_CEC_OK)
+ {
+ HDMI_CEC_Follower_String[5][1] = (uint8_t *)"1";
+ i++;
+ errorstatus = HDMI_CEC_OK;
+ }
+
+ /* Clear CEC ISR register */
+ CEC_ClearFlag(CEC_FLAG_TXBR|CEC_FLAG_TXEND);
+
+ /*--------------------------------- Tuner 2 --------------------------------*/
+ CEC_EndOfMessage();
+
+ CEC_SendData((MyLogicalAddress << 4) | 0x6);
+
+ /* Start of message */
+ CEC_StartOfMessage();
+
+ /* Wait till the header message is sent */
+ while (count < HDMI_CEC_TIMEOUT_VALUE)
+ {
+ if (CEC_GetFlagStatus(CEC_FLAG_TXACKE) != RESET)
+ {
+ errorstatus = HDMI_CEC_GetErrorStatus();
+ CEC_ClearFlag(CEC_FLAG_TXACKE);
+ break;
+ }
+ else if(CEC_GetFlagStatus(CEC_FLAG_TXEND) != RESET)
+ {
+ errorstatus = HDMI_CEC_OK;
+ break;
+ }
+ count++;
+ }
+
+ if (count >= HDMI_CEC_TIMEOUT_VALUE)
+ {
+ errorstatus = HDMI_CEC_TIMEOUT;
+ return(errorstatus);
+ }
+
+ if (errorstatus == HDMI_CEC_OK)
+ {
+ HDMI_CEC_Follower_String[6][1] = (uint8_t *)"1";
+ i++;
+ errorstatus = HDMI_CEC_OK;
+ }
+ /* Clear CEC ISR register */
+ CEC_ClearFlag(CEC_FLAG_TXBR|CEC_FLAG_TXEND);
+
+ /*--------------------------------- Tuner 3 --------------------------------*/
+ CEC_EndOfMessage();
+
+ CEC_SendData((MyLogicalAddress << 4) | 0x7);
+
+ /* Start of message */
+ CEC_StartOfMessage();
+
+ /* Wait till the header message is sent */
+ while (count < HDMI_CEC_TIMEOUT_VALUE)
+ {
+ if (CEC_GetFlagStatus(CEC_FLAG_TXACKE) != RESET)
+ {
+ errorstatus = HDMI_CEC_GetErrorStatus();
+ CEC_ClearFlag(CEC_FLAG_TXACKE);
+ break;
+ }
+ else if(CEC_GetFlagStatus(CEC_FLAG_TXEND) != RESET)
+ {
+ errorstatus = HDMI_CEC_OK;
+ break;
+ }
+ count++;
+ }
+ if (count >= HDMI_CEC_TIMEOUT_VALUE)
+ {
+ errorstatus = HDMI_CEC_TIMEOUT;
+ return(errorstatus);
+ }
+
+ if (errorstatus == HDMI_CEC_OK)
+ {
+ HDMI_CEC_Follower_String[7][1] = (uint8_t *)"1";
+ i++;
+ errorstatus = HDMI_CEC_OK;
+ }
+
+ /* Clear CEC ISR register */
+ CEC_ClearFlag(CEC_FLAG_TXBR|CEC_FLAG_TXEND);
+
+ /*---------------------------- Playback device 2 ---------------------------*/
+ CEC_EndOfMessage();
+
+ CEC_SendData((MyLogicalAddress << 4) | 0x8);
+
+ /* Start of message */
+ CEC_StartOfMessage();
+
+ /* Wait till the header message is sent */
+ while(count < HDMI_CEC_TIMEOUT_VALUE)
+ {
+ if (CEC_GetFlagStatus(CEC_FLAG_TXACKE) != RESET)
+ {
+ errorstatus = HDMI_CEC_GetErrorStatus();
+ CEC_ClearFlag(CEC_FLAG_TXACKE);
+ break;
+ }
+ else if(CEC_GetFlagStatus(CEC_FLAG_TXEND) != RESET)
+ {
+ errorstatus = HDMI_CEC_OK;
+ break;
+ }
+ count++;
+ }
+
+ if (count >= HDMI_CEC_TIMEOUT_VALUE)
+ {
+ errorstatus = HDMI_CEC_TIMEOUT;
+ return(errorstatus);
+ }
+
+ if (errorstatus == HDMI_CEC_OK)
+ {
+ HDMI_CEC_Follower_String[8][1] = (uint8_t *)"1";
+ i++;
+ errorstatus = HDMI_CEC_OK;
+ }
+ /* Clear CEC ISR register */
+ CEC_ClearFlag(CEC_FLAG_TXBR|CEC_FLAG_TXEND);
+
+ /*---------------------------- Recording device 3 --------------------------*/
+ CEC_EndOfMessage();
+
+ CEC_SendData((MyLogicalAddress << 4) | 0x9);
+
+ /* Start of message */
+ CEC_StartOfMessage();
+
+ /* Wait till the header message is sent */
+ while(count < HDMI_CEC_TIMEOUT_VALUE)
+ {
+ if (CEC_GetFlagStatus(CEC_FLAG_TXACKE) != RESET)
+ {
+ errorstatus = HDMI_CEC_GetErrorStatus();
+ CEC_ClearFlag(CEC_FLAG_TXACKE);
+ break;
+ }
+ else if(CEC_GetFlagStatus(CEC_FLAG_TXEND) != RESET)
+ {
+ errorstatus = HDMI_CEC_OK;
+ break;
+ }
+ count++;
+ }
+
+ if (count >= HDMI_CEC_TIMEOUT_VALUE)
+ {
+ errorstatus = HDMI_CEC_TIMEOUT;
+ return(errorstatus);
+ }
+
+ if (errorstatus == HDMI_CEC_OK)
+ {
+ HDMI_CEC_Follower_String[9][1] = (uint8_t *)"1";
+ i++;
+ errorstatus = HDMI_CEC_OK;
+ }
+ /* Clear CEC ISR register */
+ CEC_ClearFlag(CEC_FLAG_TXBR|CEC_FLAG_TXEND);
+
+ /*-------------------------------- Tuner 4 ---------------------------------*/
+ CEC_EndOfMessage();
+
+ CEC_SendData((MyLogicalAddress << 4) | 0xA);
+
+ /* Start of message */
+ CEC_StartOfMessage();
+
+ /* Wait till the header message is sent */
+ while (count < HDMI_CEC_TIMEOUT_VALUE)
+ {
+ if (CEC_GetFlagStatus(CEC_FLAG_TXACKE) != RESET)
+ {
+ errorstatus = HDMI_CEC_GetErrorStatus();
+ CEC_ClearFlag(CEC_FLAG_TXACKE);
+ break;
+ }
+ else if(CEC_GetFlagStatus(CEC_FLAG_TXEND) != RESET)
+ {
+ errorstatus = HDMI_CEC_OK;
+ break;
+ }
+ count++;
+ }
+
+ if (count >= HDMI_CEC_TIMEOUT_VALUE)
+ {
+ errorstatus = HDMI_CEC_TIMEOUT;
+ return(errorstatus);
+ }
+
+ if (errorstatus == HDMI_CEC_OK)
+ {
+ HDMI_CEC_Follower_String[10][1] = (uint8_t *)"1";
+ i++;
+ errorstatus = HDMI_CEC_OK;
+ }
+ /* Clear CEC ISR register */
+ CEC_ClearFlag(CEC_FLAG_TXBR|CEC_FLAG_TXEND);
+
+ /*---------------------------- Playback device 3 ---------------------------*/
+ CEC_EndOfMessage();
+
+ CEC_SendData((MyLogicalAddress << 4)|0xB);
+
+ /* Start of message */
+ CEC_StartOfMessage();
+
+ /* Wait till the header message is sent */
+ while(count < HDMI_CEC_TIMEOUT_VALUE)
+ {
+ if (CEC_GetFlagStatus(CEC_FLAG_TXACKE) != RESET)
+ {
+ errorstatus = HDMI_CEC_GetErrorStatus();
+ CEC_ClearFlag(CEC_FLAG_TXACKE);
+ break;
+ }
+ else if(CEC_GetFlagStatus(CEC_FLAG_TXEND) != RESET)
+ {
+ errorstatus = HDMI_CEC_OK;
+ break;
+ }
+ count++;
+ }
+
+ if (count >= HDMI_CEC_TIMEOUT_VALUE)
+ {
+ errorstatus = HDMI_CEC_TIMEOUT;
+ return(errorstatus);
+ }
+
+ if (errorstatus == HDMI_CEC_OK)
+ {
+ HDMI_CEC_Follower_String[11][1] = (uint8_t *)"1";
+ i++;
+ errorstatus = HDMI_CEC_OK;
+ }
+ /* Clear CEC ISR register */
+ CEC_ClearFlag(CEC_FLAG_TXBR|CEC_FLAG_TXEND);
+
+ CECDevicesNumber = i - 1;
+
+ return errorstatus;
+}
+
+/**
+ * @brief Sink Physical address discovery.
+ * @param None
+ * @retval HDMI_CEC_Error: CEC Error code.
+ */
+static HDMI_CEC_Error SinkPhysicalAddressDiscovery(void)
+{
+ uint32_t DataNum=0;
+ HDMI_CEC_Error errorstatus = HDMI_CEC_OK;
+
+ I2C_InitTypeDef I2C_InitStructure;
+ GPIO_InitTypeDef GPIO_InitStructure;
+
+ /*------------------------------ Physical address discovery ----------------*/
+ /* if HDMI_CEC_ROOT == 0x1*/
+ MyPhysicalAddress = 0x0000;
+ /* The HDMI-CEC here is configured as sink or as a repeater. The configuration
+ of the +5V power signal and the HPD should be well configured.
+ Implement here the EDID Structure to be sent to the HDMI source.
+ For more details please refer to the HDMI specification.
+ The EDID structure should be sent to the device source using the DDC Channel
+ and using the HPD signal. */
+
+ /* Enable CEC_I2C clocks */
+ RCC_APB1PeriphClockCmd(HDMI_CEC_SINK_I2C_CLK, ENABLE);
+
+ /* Enable CEC_I2C_GPIO and CEC_HPD_GPIO clocks */
+ RCC_AHBPeriphClockCmd(HDMI_CEC_SINK_I2C_GPIO_CLK | HDMI_CEC_HPD_SINK_GPIO_CLK, ENABLE);
+
+ I2C_DeInit(HDMI_CEC_SINK_I2C);
+
+ GPIO_PinAFConfig(HDMI_CEC_SINK_I2C_GPIO_PORT, HDMI_CEC_SINK_I2C_SCL_PIN_SOURCE, GPIO_AF_1);
+ GPIO_PinAFConfig(HDMI_CEC_SINK_I2C_GPIO_PORT, HDMI_CEC_SINK_I2C_SDA_PIN_SOURCE, GPIO_AF_1);
+
+ /* Set PF6/PF7 as OD AF - I2C2_SCL/I2C2_SDA of Source*/
+ GPIO_InitStructure.GPIO_Pin = HDMI_CEC_SINK_I2C_SDA_PIN | HDMI_CEC_SINK_I2C_SCL_PIN;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
+ GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
+ GPIO_Init(HDMI_CEC_SINK_I2C_GPIO_PORT, &GPIO_InitStructure);
+
+ /* Set PA11 as PP - HPD */
+ GPIO_InitStructure.GPIO_Pin = HDMI_CEC_HPD_SINK_PIN;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
+ GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
+ GPIO_Init(HDMI_CEC_HPD_SINK_GPIO_PORT, &GPIO_InitStructure);
+
+ RCC_I2CCLKConfig(RCC_I2C1CLK_HSI);
+
+ HDMI_CEC_SINK_I2C->CR1 &= (uint16_t)(~I2C_CR1_NOSTRETCH);
+
+ I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
+ I2C_InitStructure.I2C_Timing = HDMI_CEC_I2C_TIMING;
+ I2C_InitStructure.I2C_AnalogFilter = I2C_AnalogFilter_Enable;
+ /* Initialize the I2C_DigitalFilter member */
+ I2C_InitStructure.I2C_DigitalFilter = 0x00;
+ I2C_InitStructure.I2C_OwnAddress1 = HDMI_CEC_I2C_SLAVE_ADDRESS7;
+ I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
+ I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
+ I2C_Init(HDMI_CEC_SINK_I2C, &I2C_InitStructure);
+
+ /* Enable HDMI_CEC_SINK_I2C */
+ I2C_Cmd(HDMI_CEC_SINK_I2C, ENABLE);
+
+ /* Wait until ADDR is set */
+ while (!(HDMI_CEC_SINK_I2C->ISR & I2C_ISR_ADDR));
+
+ /* Clear ADDR flag */
+ HDMI_CEC_SINK_I2C->ICR = I2C_ICR_ADDRCF;
+
+ while (!(HDMI_CEC_SINK_I2C->ISR & I2C_ISR_RXNE));
+
+ HDMI_CEC_SINK_I2C->RXDR;
+
+ /* Wait until ADDR is set */
+ while (!(HDMI_CEC_SINK_I2C->ISR & I2C_ISR_ADDR));
+
+ /* Clear ADDR flag */
+ HDMI_CEC_SINK_I2C->ICR = I2C_ICR_ADDRCF;
+
+ while (!(HDMI_CEC_SINK_I2C->ISR & I2C_ISR_TXIS));
+
+ while (DataNum != 256)
+ {
+ if (HDMI_CEC_SINK_I2C->ISR & I2C_ISR_TXIS)
+ {
+ /* Write data to TXDR */
+ HDMI_CEC_SINK_I2C->TXDR = (uint8_t)(EDID_Structure[DataNum++]);
+ }
+ }
+
+ while (!(HDMI_CEC_SINK_I2C->ISR & I2C_ISR_STOPF));
+ while (!(HDMI_CEC_SINK_I2C->ISR & I2C_ISR_NACKF));
+
+ /* Clear STOPF and NACKF flag */
+ HDMI_CEC_SINK_I2C->ICR = ( I2C_ICR_STOPCF | I2C_ICR_NACKCF);
+
+ return errorstatus;
+}
+
+/**
+ * @brief Source Physical address discovery.
+ * @param None
+ * @retval HDMI_CEC_Error: CEC Error code.
+ */
+static HDMI_CEC_Error SourcePhysicalAddressDiscovery(void)
+{
+ HDMI_CEC_Error errorstatus = HDMI_CEC_OK;
+
+#ifdef HDMI_CEC_USE_DDC
+ uint32_t i = 0;
+ uint32_t DataNum=0;
+ GPIO_InitTypeDef GPIO_InitStructure;
+ I2C_InitTypeDef I2C_InitStructure;
+
+ /* Enable CEC_I2C clocks */
+ RCC_APB1PeriphClockCmd(HDMI_CEC_I2C_CLK, ENABLE);
+
+ /* Enable CEC_I2C_GPIO and CEC_HPD_GPIO clocks */
+ RCC_AHBPeriphClockCmd(HDMI_CEC_I2C_GPIO_CLK|HDMI_CEC_HPD_SOURCE_GPIO_CLK, ENABLE);
+
+ GPIO_PinAFConfig(HDMI_CEC_I2C_GPIO_PORT,HDMI_CEC_I2C_SCL_PIN_SOURCE,GPIO_AF_1);
+ GPIO_PinAFConfig(HDMI_CEC_I2C_GPIO_PORT,HDMI_CEC_I2C_SDA_PIN_SOURCE,GPIO_AF_1);
+
+ /* Configure CEC_I2C_SCL_PIN and CEC_I2C_SDA_PIN as Output open drain */
+ GPIO_InitStructure.GPIO_Pin = HDMI_CEC_I2C_SCL_PIN|HDMI_CEC_I2C_SDA_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
+ GPIO_Init(HDMI_CEC_I2C_GPIO_PORT, &GPIO_InitStructure);
+
+/* This configuration is only when the HDMI CEC is configured as source.
+ The HDMI source has to provide the +5V Power signal to the sink.
+ Then, the source will wait for HPD signal to be asserted from the sink.
+ Once the HPD signal is detected the source shall read the EDID structure
+ through the DDC channel. */
+ /* Configure CEC_HPD_GPIO as Input pull down */
+ GPIO_InitStructure.GPIO_Pin = HDMI_CEC_HPD_SOURCE_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
+ GPIO_Init(HDMI_CEC_HPD_SOURCE_GPIO_PORT, &GPIO_InitStructure);
+
+ /* I2C configuration */
+ I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
+ I2C_InitStructure.I2C_AnalogFilter = I2C_AnalogFilter_Enable;
+ I2C_InitStructure.I2C_DigitalFilter = 0x00;
+ I2C_InitStructure.I2C_OwnAddress1 = 0x00;
+ I2C_InitStructure.I2C_Ack =I2C_Ack_Enable;
+ I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
+ I2C_InitStructure.I2C_Timing = HDMI_CEC_I2C_TIMING;
+
+ /* I2C configuration */
+ I2C_Init(HDMI_CEC_I2C, &I2C_InitStructure);
+
+ /* I2C Peripheral Enable */
+ I2C_Cmd(HDMI_CEC_I2C, ENABLE);
+
+ /* The HDMI-CEC here is configured as source or as a repeater. The configuration
+ of the +5V power signal and the HPD should be well configured.
+ The source should wait for HPD and then read the EDID structure. */
+ while(GPIO_ReadInputDataBit(HDMI_CEC_HPD_SOURCE_GPIO_PORT, HDMI_CEC_HPD_SOURCE_PIN) == RESET)
+ {
+ }
+
+ /* Wait for 100 ms after HPD was received */
+ for(i = 0; i <0x5FFFFF; i++)
+ {
+ }
+
+ /* Configure slave address, nbytes, reload and generate start */
+ HDMI_CEC_I2C->CR2 = (uint32_t)(0xA0)|(uint32_t)(1 << 16)|I2C_CR2_START;
+
+ /* Wait until TXIS is set */
+ while (!(HDMI_CEC_I2C->ISR & I2C_ISR_TXIS));
+
+ /* Send memory address */
+ HDMI_CEC_I2C->TXDR = (uint8_t)(0x00);
+
+ /* Wait until TC is set */
+ while (!(HDMI_CEC_I2C->ISR & I2C_ISR_TC));
+
+ /* Update CR2 : set Nbytes and reload */
+ HDMI_CEC_I2C->CR2 = (uint32_t)(0xA0)|I2C_CR2_RD_WRN|I2C_CR2_START |(uint32_t)(255 << 16)|I2C_CR2_RELOAD;
+
+ /* Wait until all data are received */
+ while (DataNum != 255)
+ {
+ /* Wait until RXNE flag is set */
+ while (!(HDMI_CEC_I2C->ISR & I2C_ISR_RXNE));
+
+ /* Read data from RXDR */
+ pBuffer[DataNum]= (uint8_t)HDMI_CEC_I2C->RXDR;
+
+ /* Update number of received data */
+ DataNum++;
+ }
+
+ /* Wait until TCR flag is set */
+ while (!(HDMI_CEC_I2C->ISR & I2C_ISR_TCR));
+
+ /* Update CR2 : set Nbytes and end mode */
+ HDMI_CEC_I2C->CR2 = (uint32_t)(1 << 16)|I2C_CR2_AUTOEND;
+
+ while (!(HDMI_CEC_I2C->ISR & I2C_ISR_RXNE));
+
+ /* Read data from RXDR */
+ pBuffer[DataNum]= (uint8_t)HDMI_CEC_I2C->RXDR;
+
+ /* Wait until STOPF flag is set */
+ while (!(HDMI_CEC_I2C->ISR & I2C_ISR_STOPF));
+
+ /* Clear STOPF flag */
+ HDMI_CEC_I2C->ICR = I2C_ICR_STOPCF;
+
+ MyPhysicalAddress = ((pBuffer[158] << 8)|pBuffer[159]);
+#else
+ MyPhysicalAddress = 0x1000;
+#endif
+
+ return errorstatus;
+}
+
+/**
+ * @brief Allocate the logical address.
+ * @param None
+ * @retval HDMI_CEC_Error: CEC Error code.
+ */
+static HDMI_CEC_Error LogicalAddressAllocation(void)
+{
+ HDMI_CEC_Error errorstatus = HDMI_CEC_OK;
+ uint32_t count = 0;
+
+ /*------------------ Logical address allocation ----------------------------*/
+ /* Get the device type */
+ /* Device type = CEC_TV */
+ if (DeviceType == HDMI_CEC_TV)
+ {
+ if (HDMI_CEC_ROOT)
+ {
+ MyLogicalAddress = 0x00;
+ }
+ else
+ {
+ CEC_OwnAddressConfig(0xE); /* Own address = 0xE */
+
+ CEC_EndOfMessage();
+
+ CEC_SendData(0xEE);
+
+ /* Start of message */
+ CEC_StartOfMessage();
+
+ /* Wait till the header message is sent */
+ while ((CEC_GetFlagStatus(CEC_FLAG_TXACKE) == RESET) && (count < HDMI_CEC_TIMEOUT_VALUE))
+ {
+ if(CEC_GetFlagStatus(CEC_FLAG_TXEND) != RESET)
+ {
+ break;
+ }
+ count++;
+ }
+
+ if (count >= HDMI_CEC_TIMEOUT_VALUE)
+ {
+ errorstatus = HDMI_CEC_TIMEOUT;
+ return(errorstatus);
+ }
+
+ errorstatus = HDMI_CEC_GetErrorStatus();
+
+ if (errorstatus == HDMI_CEC_TX_ACKNOWLEDGE)
+ {
+ MyLogicalAddress = 0x0E;
+ errorstatus = HDMI_CEC_OK;
+ }
+ else if (errorstatus == HDMI_CEC_OK)
+ {
+ MyLogicalAddress = 0x0F;
+ errorstatus = HDMI_CEC_DEVICE_UNREGISTRED;
+ }
+ }
+ /* Clear CEC ISR register */
+ CEC_ClearFlag(CEC_FLAG_TXEND);
+ }
+
+ /* Device type = CEC_RECORDING */
+ if (DeviceType == HDMI_CEC_RECORDING)
+ {
+ CEC_OwnAddressConfig(0x1); /* Own address = 0x1 */
+
+ CEC_EndOfMessage();
+
+ CEC_SendData(0x11);
+
+ /* Start of message */
+ CEC_StartOfMessage();
+
+ /* Wait till the header message is sent */
+ while ((CEC_GetFlagStatus(CEC_FLAG_TXACKE) == RESET) && (count < HDMI_CEC_TIMEOUT_VALUE))
+ {
+ if(CEC_GetFlagStatus(CEC_FLAG_TXEND) != RESET)
+ {
+ break;
+ }
+ count++;
+ }
+
+ if (count >= HDMI_CEC_TIMEOUT_VALUE)
+ {
+ errorstatus = HDMI_CEC_TIMEOUT;
+ return(errorstatus);
+ }
+
+ errorstatus = HDMI_CEC_GetErrorStatus();
+
+ if (errorstatus == HDMI_CEC_TX_ACKNOWLEDGE)
+ {
+ MyLogicalAddress = 0x01;
+ errorstatus = HDMI_CEC_OK;
+ }
+ else if (errorstatus == HDMI_CEC_OK)
+ {
+ /* Clear CEC ISR register */
+ CEC_ClearFlag(CEC_FLAG_TXEND|CEC_FLAG_TXACKE|CEC_FLAG_TXBR);
+
+ /* Clear the OAR */
+ CEC_OwnAddressClear();
+
+ CEC_OwnAddressConfig(0x2); /* Own address = 0x2 */
+
+ CEC_EndOfMessage();
+
+ CEC_SendData(0x22);
+
+ /* Start of message */
+ CEC_StartOfMessage();
+
+ count = 0;
+
+ /* Wait till the header message is sent */
+ while ((CEC_GetFlagStatus(CEC_FLAG_TXACKE) == RESET) && (count < HDMI_CEC_TIMEOUT_VALUE))
+ {
+ if(CEC_GetFlagStatus(CEC_FLAG_TXEND) != RESET)
+ {
+ break;
+ }
+ count++;
+ }
+
+ if (count >= HDMI_CEC_TIMEOUT_VALUE)
+ {
+ errorstatus = HDMI_CEC_TIMEOUT;
+ return(errorstatus);
+ }
+ errorstatus = HDMI_CEC_GetErrorStatus();
+
+ if (errorstatus == HDMI_CEC_TX_ACKNOWLEDGE)
+ {
+ MyLogicalAddress = 0x02;
+ errorstatus = HDMI_CEC_OK;
+ }
+ else if (errorstatus == HDMI_CEC_OK)
+ {
+ /* Clear CEC ISR register */
+ CEC_ClearFlag( CEC_FLAG_TXEND);
+
+ CEC_OwnAddressClear();
+
+ CEC_OwnAddressConfig(0x9); /* Own address = 0x9 */
+
+ CEC_EndOfMessage();
+
+ CEC_SendData(0x99);
+
+ /* Start of message */
+ CEC_StartOfMessage();
+
+ count = 0;
+
+ /* Wait till the header message is sent */
+ while ((CEC_GetFlagStatus(CEC_FLAG_TXACKE) == RESET) && (count < HDMI_CEC_TIMEOUT_VALUE))
+ {
+ if(CEC_GetFlagStatus(CEC_FLAG_TXEND) != RESET)
+ {
+ break;
+ }
+ count++;
+ }
+
+ if (count >= HDMI_CEC_TIMEOUT_VALUE)
+ {
+ errorstatus = HDMI_CEC_TIMEOUT;
+ return(errorstatus);
+ }
+ errorstatus = HDMI_CEC_GetErrorStatus();
+
+ if (errorstatus == HDMI_CEC_TX_ACKNOWLEDGE)
+ {
+ MyLogicalAddress = 0x09;
+ errorstatus = HDMI_CEC_OK;
+ }
+ else if (errorstatus == HDMI_CEC_OK)
+ {
+ MyLogicalAddress = 0x0F;
+ errorstatus = HDMI_CEC_DEVICE_UNREGISTRED;
+ }
+ }
+ }
+ /* Clear CEC ISR register */
+ CEC_ClearFlag(CEC_FLAG_TXEND|CEC_FLAG_TXACKE|CEC_FLAG_TXBR);
+ }
+
+ /* Device type = CEC_TUNER */
+ if (DeviceType == HDMI_CEC_TUNER)
+ {
+ CEC_OwnAddressConfig(0x3); /* Own address = 0x3 */
+
+ CEC_EndOfMessage();
+
+ CEC_SendData(0x33);
+
+ /* Start of message */
+ CEC_StartOfMessage();
+
+ count = 0;
+
+ /* Wait till the header message is sent */
+ while ((CEC_GetFlagStatus(CEC_FLAG_TXACKE) == RESET) && (count < HDMI_CEC_TIMEOUT_VALUE))
+ {
+ if(CEC_GetFlagStatus(CEC_FLAG_TXEND) != RESET)
+ {
+ break;
+ }
+ count++;
+ }
+
+ if (count >= HDMI_CEC_TIMEOUT_VALUE)
+ {
+ errorstatus = HDMI_CEC_TIMEOUT;
+ return(errorstatus);
+ }
+ errorstatus = HDMI_CEC_GetErrorStatus();
+
+ if (errorstatus == HDMI_CEC_TX_ACKNOWLEDGE)
+ {
+ MyLogicalAddress = 0x03;
+ errorstatus = HDMI_CEC_OK;
+ }
+ else if (errorstatus == HDMI_CEC_OK)
+ {
+ /* Clear CEC ISR register */
+ CEC_ClearFlag(CEC_FLAG_TXEND);
+
+ /* Clear the OAR */
+ CEC_OwnAddressClear();
+
+ CEC_OwnAddressConfig(0x6); /* Own address = 0x6 */
+
+ CEC_EndOfMessage();
+
+ CEC_SendData(0x66);
+
+ /* Start of message */
+ CEC_StartOfMessage();
+
+ count = 0;
+
+ /* Wait till the header message is sent */
+ while ((CEC_GetFlagStatus(CEC_FLAG_TXACKE) == RESET) && (count < HDMI_CEC_TIMEOUT_VALUE))
+ {
+ if(CEC_GetFlagStatus(CEC_FLAG_TXEND) != RESET)
+ {
+ break;
+ }
+ count++;
+ }
+
+ if (count >= HDMI_CEC_TIMEOUT_VALUE)
+ {
+ errorstatus = HDMI_CEC_TIMEOUT;
+ return(errorstatus);
+ }
+ errorstatus = HDMI_CEC_GetErrorStatus();
+
+ if (errorstatus == HDMI_CEC_TX_ACKNOWLEDGE)
+ {
+ MyLogicalAddress = 0x06;
+ errorstatus = HDMI_CEC_OK;
+ }
+ else if (errorstatus == HDMI_CEC_OK)
+ {
+ /* Clear CEC ISR register */
+ CEC_ClearFlag(CEC_FLAG_TXEND);
+
+ /* Clear the OAR */
+ CEC_OwnAddressClear();
+
+ CEC_OwnAddressConfig(0x7); /* Own address = 0x7 */
+
+ CEC_EndOfMessage();
+
+ CEC_SendData(0x77);
+
+ /* Start of message */
+ CEC_StartOfMessage();
+
+ count = 0;
+
+ /* Wait till the header message is sent */
+ while ((CEC_GetFlagStatus(CEC_FLAG_TXACKE) == RESET) && (count < HDMI_CEC_TIMEOUT_VALUE))
+ {
+ if(CEC_GetFlagStatus(CEC_FLAG_TXEND) != RESET)
+ {
+ break;
+ }
+ count++;
+ }
+
+ if (count >= HDMI_CEC_TIMEOUT_VALUE)
+ {
+ errorstatus = HDMI_CEC_TIMEOUT;
+ return(errorstatus);
+ }
+ errorstatus = HDMI_CEC_GetErrorStatus();
+
+ if (errorstatus == HDMI_CEC_TX_ACKNOWLEDGE)
+ {
+ MyLogicalAddress = 0x07;
+ errorstatus = HDMI_CEC_OK;
+ }
+ else if (errorstatus == HDMI_CEC_OK)
+ {
+ /* Clear CEC ISR register */
+ CEC_ClearFlag(CEC_FLAG_TXEND);
+
+ /* Clear the OAR */
+ CEC_OwnAddressClear();
+
+ CEC_OwnAddressConfig(0xA); /* Own address = 0xA */
+
+ CEC_EndOfMessage();
+
+ CEC_SendData(0xAA);
+
+ /* Start of message */
+ CEC_StartOfMessage();
+
+ count = 0;
+
+ /* Wait till the header message is sent */
+ while ((CEC_GetFlagStatus(CEC_FLAG_TXACKE) == RESET) && (count < HDMI_CEC_TIMEOUT_VALUE))
+ {
+ if(CEC_GetFlagStatus(CEC_FLAG_TXEND) != RESET)
+ {
+ break;
+ }
+ count++;
+ }
+ if (count >= HDMI_CEC_TIMEOUT_VALUE)
+ {
+ errorstatus = HDMI_CEC_TIMEOUT;
+ return(errorstatus);
+ }
+ errorstatus = HDMI_CEC_GetErrorStatus();
+
+ if (errorstatus == HDMI_CEC_TX_ACKNOWLEDGE)
+ {
+ MyLogicalAddress = 0x0A;
+ errorstatus = HDMI_CEC_OK;
+ }
+ else if (errorstatus == HDMI_CEC_OK)
+ {
+ MyLogicalAddress = 0x0F;
+ errorstatus = HDMI_CEC_DEVICE_UNREGISTRED;
+ }
+ }
+ }
+ }
+ /* Clear CEC ISR register */
+ CEC_ClearFlag(CEC_FLAG_TXEND);
+ }
+
+ /* Device type = CEC_PLAYBACK */
+ if (DeviceType == HDMI_CEC_PLAYBACK)
+ {
+ CEC_OwnAddressConfig(0x4); /* Own address = 0x4 */
+
+ CEC_EndOfMessage();
+
+ CEC_SendData(0x44);
+
+ /* Start of message */
+ CEC_StartOfMessage();
+
+ count = 0;
+
+ /* Wait till the header message is sent */
+ while ((CEC_GetFlagStatus(CEC_FLAG_TXACKE) == RESET) && (count < HDMI_CEC_TIMEOUT_VALUE))
+ {
+ if(CEC_GetFlagStatus(CEC_FLAG_TXEND) != RESET)
+ {
+ break;
+ }
+ count++;
+ }
+ if (count >= HDMI_CEC_TIMEOUT_VALUE)
+ {
+ errorstatus = HDMI_CEC_TIMEOUT;
+ return(errorstatus);
+ }
+
+ errorstatus = HDMI_CEC_GetErrorStatus();
+
+ if (errorstatus == HDMI_CEC_TX_ACKNOWLEDGE)
+ {
+ MyLogicalAddress = 0x04;
+ errorstatus = HDMI_CEC_OK;
+ }
+ else if (errorstatus == HDMI_CEC_OK)
+ {
+ /* Clear CEC ISR register */
+ CEC_ClearFlag(CEC_FLAG_TXEND);
+
+ /* Clear the OAR */
+ CEC_OwnAddressClear();
+
+ CEC_OwnAddressConfig(0x8); /* Own address = 0x8 */
+
+ CEC_EndOfMessage();
+
+ CEC_SendData(0x88);
+
+ /* Start of message */
+ CEC_StartOfMessage();
+
+ count = 0;
+
+ /* Wait till the header message is sent */
+ while ((CEC_GetFlagStatus(CEC_FLAG_TXACKE) == RESET) && (count < HDMI_CEC_TIMEOUT_VALUE))
+ {
+ if(CEC_GetFlagStatus(CEC_FLAG_TXEND) != RESET)
+ {
+ break;
+ }
+ count++;
+ }
+
+ if (count >= HDMI_CEC_TIMEOUT_VALUE)
+ {
+ errorstatus = HDMI_CEC_TIMEOUT;
+ return(errorstatus);
+ }
+ errorstatus = HDMI_CEC_GetErrorStatus();
+
+ if (errorstatus == HDMI_CEC_TX_ACKNOWLEDGE)
+ {
+ MyLogicalAddress = 0x08;
+ errorstatus = HDMI_CEC_OK;
+ }
+ else if (errorstatus == HDMI_CEC_OK)
+ {
+ /* Clear CEC ISR register */
+ CEC_ClearFlag(CEC_FLAG_TXEND);
+
+ /* Clear the OAR */
+ CEC_OwnAddressClear();
+
+ CEC_OwnAddressConfig(0xB); /* Own address = 0xBB */
+
+ CEC_EndOfMessage();
+
+ CEC_SendData(0xBB);
+
+ /* Start of message */
+ CEC_StartOfMessage();
+
+ count = 0;
+
+ /* Wait till the header message is sent */
+ while ((CEC_GetFlagStatus(CEC_FLAG_TXACKE) == RESET) && (count < HDMI_CEC_TIMEOUT_VALUE))
+ {
+ if(CEC_GetFlagStatus(CEC_FLAG_TXEND) != RESET)
+ {
+ break;
+ }
+ count++;
+ }
+ /* Clear the OAR */
+ CEC_OwnAddressClear();
+
+ if (count >= HDMI_CEC_TIMEOUT_VALUE)
+ {
+ errorstatus = HDMI_CEC_TIMEOUT;
+ return(errorstatus);
+ }
+
+ errorstatus = HDMI_CEC_GetErrorStatus();
+
+ if (errorstatus == HDMI_CEC_TX_ACKNOWLEDGE)
+ {
+ MyLogicalAddress = 0x0B;
+ errorstatus = HDMI_CEC_OK;
+ }
+ else if (errorstatus == HDMI_CEC_OK)
+ {
+ MyLogicalAddress = 0x0F;
+ errorstatus = HDMI_CEC_DEVICE_UNREGISTRED;
+ }
+ }
+ }
+ /* Clear CEC ISR register */
+ CEC_ClearFlag(CEC_FLAG_TXEND);
+ }
+
+ /* Device type = CEC Audio System */
+ if (DeviceType == HDMI_CEC_AUDIOSYSTEM)
+ {
+ CEC_OwnAddressConfig(0x5); /* Own address = 0x5 */
+
+ CEC_EndOfMessage();
+
+ CEC_SendData(0x55);
+
+ /* Start of message */
+ CEC_StartOfMessage();
+
+ count = 0;
+
+ /* Wait till the header message is sent */
+ while ((CEC_GetFlagStatus(CEC_FLAG_TXACKE) == RESET) && (count < HDMI_CEC_TIMEOUT_VALUE))
+ {
+ if(CEC_GetFlagStatus(CEC_FLAG_TXEND) != RESET)
+ {
+ break;
+ }
+ count++;
+ }
+
+ if (count >= HDMI_CEC_TIMEOUT_VALUE)
+ {
+ errorstatus = HDMI_CEC_TIMEOUT;
+ return(errorstatus);
+ }
+
+ errorstatus = HDMI_CEC_GetErrorStatus();
+
+ if (errorstatus == HDMI_CEC_TX_ACKNOWLEDGE)
+ {
+ MyLogicalAddress = 0x05;
+ errorstatus = HDMI_CEC_OK;
+ }
+ else if (errorstatus == HDMI_CEC_OK)
+ {
+ MyLogicalAddress = 0x0F;
+ errorstatus = HDMI_CEC_DEVICE_UNREGISTRED;
+ }
+
+ /* Clear CEC ISR register */
+ CEC_ClearFlag(CEC_FLAG_TXEND);
+ }
+
+ return errorstatus;
+}
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32373C_EVAL/stm32373c_eval_cec.h b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32373C_EVAL/stm32373c_eval_cec.h
new file mode 100644
index 0000000..c5cd7e6
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32373C_EVAL/stm32373c_eval_cec.h
@@ -0,0 +1,309 @@
+/**
+ ******************************************************************************
+ * @file stm32373c_eval_cec.h
+ * @author MCD Application Team
+ * @version V1.0.0
+ * @date 20-September-2012
+ * @brief This file contains all the functions prototypes for the stm32373c_eval_cec
+ * firmware driver.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.st.com/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __STM32373C_EVAL_CEC_H
+#define __STM32373C_EVAL_CEC_H
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /* Includes ------------------------------------------------------------------*/
+#include "stm32f37x.h"
+
+/** @addtogroup Utilities
+ * @{
+ */
+
+/** @addtogroup STM32_EVAL
+ * @{
+ */
+
+/** @addtogroup STM32373C_EVAL
+ * @{
+ */
+
+/** @defgroup STM32373C_EVAL_CEC
+ * @{
+ */
+
+/** @defgroup STM32373C_EVAL_CEC_Exported_Types
+ * @{
+ */
+typedef enum
+{
+ HDMI_CEC_RX_OVERRUN = (1), /*!< CEC Receive overrun Error */
+ HDMI_CEC_RX_BIT_RISING = (2), /*!< CEC Rx Bit Rising Error */
+ HDMI_CEC_RX_SHORT_BIT_PERIOD = (3), /*!< CEC Rx Short Bit Period Error */
+ HDMI_CEC_RX_LONG_BIT_PERIOD = (4), /*!< CEC Rx Long Bit Period Error */
+ HDMI_CEC_RX_ACKNOWLEDGE = (5), /*!< CEC RX Acknowledge Error */
+ HDMI_CEC_ARBITRATION_LOST = (6), /*!< Arbitration Lost Error */
+ HDMI_CEC_TX_UNDERRUN = (7), /*!< CEC Transmit Underrun Error */
+ HDMI_CEC_TX_ERROR = (8), /*!< CEC Transmit Error */
+ HDMI_CEC_TX_ACKNOWLEDGE = (9), /*!< CEC TX Acknowledge Error */
+ HDMI_CEC_DEVICE_UNREGISTRED = (10), /*!< CEC Device Unregistered */
+ HDMI_CEC_TIMEOUT = (11), /*!< CEC TimeOut */
+ HDMI_CEC_OK = (12) /*!< CEC OK */
+}HDMI_CEC_Error;
+
+typedef struct
+{
+ uint8_t PhysicalAddress_A;
+ uint8_t PhysicalAddress_B;
+ uint8_t PhysicalAddress_C;
+ uint8_t PhysicalAddress_D;
+ uint8_t LogicalAddress;
+ uint8_t DeviceType;
+}HDMI_CEC_Map;
+
+#define HDMI_CEC_TX_MESSAGE_LENGTH_MAX ((uint32_t)0x0000000E)
+#define HDMI_CEC_TIMEOUT_VALUE ((uint32_t)0x001FFFFF)
+
+/**
+* @brief CEC Init Structure definition
+*/
+typedef struct
+{
+ __IO uint8_t Header;
+ __IO uint8_t Opcode;
+ __IO uint8_t Operande[HDMI_CEC_TX_MESSAGE_LENGTH_MAX];
+ __IO uint8_t TxMessageLength;
+ __IO uint8_t RxMessageLength;
+}HDMI_CEC_Message;
+
+/**
+* @}
+*/
+
+/** @defgroup STM32373C_EVAL_CEC_Exported_Constants
+ * @{
+ */
+
+/**
+ * @brief CEC device types
+ */
+#define HDMI_CEC_TV 0x00
+#define HDMI_CEC_RECORDING 0x01
+#define HDMI_CEC_TUNER 0x03
+#define HDMI_CEC_PLAYBACK 0x04
+#define HDMI_CEC_AUDIOSYSTEM 0x05
+
+/**
+ * @brief HDMI CEC I2C Interface pins
+ */
+#define HDMI_CEC_I2C_SCL_PIN GPIO_Pin_9
+#define HDMI_CEC_I2C_SDA_PIN GPIO_Pin_10
+#define HDMI_CEC_I2C_SCL_PIN_SOURCE GPIO_PinSource9
+#define HDMI_CEC_I2C_SDA_PIN_SOURCE GPIO_PinSource10
+#define HDMI_CEC_I2C_GPIO_PORT GPIOA
+#define HDMI_CEC_I2C_GPIO_CLK RCC_AHBPeriph_GPIOA
+#define HDMI_CEC_I2C I2C2
+#define HDMI_CEC_I2C_CLK RCC_APB1Periph_I2C2
+
+#define HDMI_CEC_SINK_I2C_SCL_PIN GPIO_Pin_6
+#define HDMI_CEC_SINK_I2C_SDA_PIN GPIO_Pin_7
+#define HDMI_CEC_SINK_I2C_SCL_PIN_SOURCE GPIO_PinSource6
+#define HDMI_CEC_SINK_I2C_SDA_PIN_SOURCE GPIO_PinSource7
+#define HDMI_CEC_SINK_I2C_GPIO_PORT GPIOB
+#define HDMI_CEC_SINK_I2C_GPIO_CLK RCC_AHBPeriph_GPIOB
+#define HDMI_CEC_SINK_I2C I2C1
+#define HDMI_CEC_SINK_I2C_CLK RCC_APB1Periph_I2C1
+/**
+ * @brief HDMI CEC HPD (Hot Plug Detect) Interface pin
+ */
+#define HDMI_CEC_HPD_SINK_PIN GPIO_Pin_9
+#define HDMI_CEC_HPD_SINK_GPIO_PORT GPIOD
+#define HDMI_CEC_HPD_SINK_GPIO_CLK RCC_AHBPeriph_GPIOD
+
+/**
+ * @brief HDMI CEC HPD (Hot Plug Detect) Interface pin
+ */
+#define HDMI_CEC_HPD_SOURCE_PIN GPIO_Pin_7
+#define HDMI_CEC_HPD_SOURCE_GPIO_PORT GPIOD
+#define HDMI_CEC_HPD_SOURCE_GPIO_CLK RCC_AHBPeriph_GPIOD
+
+/**
+ * @brief HDMI CEC Interface pin
+ */
+#define HDMI_CEC_LINE_PIN GPIO_Pin_8
+#define HDMI_CEC_LINE_GPIO_PORT GPIOB
+#define HDMI_CEC_LINE_GPIO_CLK RCC_AHBPeriph_GPIOB
+#define HDMI_CEC_LINE_PIN_SOURCE GPIO_PinSource8
+#define HDMI_CEC_GPIO_AF GPIO_AF_6
+
+#define HDMI_CEC_I2C_TIMING 0x00330E10
+#define HDMI_CEC_I2C_SLAVE_ADDRESS7 0xA0
+
+/**
+ * @brief HDMI CEC Root (Mainly for TV with a fixed physical address (0.0.0.0))
+ * If you want to configure the STM32373C-EVAL board as CEC Root (Sink)
+ * change the following define to 0x1
+ */
+#define HDMI_CEC_ROOT 0x00
+
+/**
+ * @brief To select if the DDC Channel will be used for physical address discovery
+ * or not. To use the DDC Channel to read the EDID structure uncomment
+ * the following line.
+ * If the device is configured as HMDI source it should read his own physical
+ * address from the sink that is connected to.
+ */
+/* #define HDMI_CEC_USE_DDC */
+
+/**
+ * @brief CEC version: V1.4
+ */
+#define HDMI_CEC_VERSION 0x05 /*0x04 For CEC version: V1.3.a*/
+
+/**
+ * @brief Reason for Abort feature
+ */
+#define HDMI_CEC_UNRECOGNIZED_OPCODE 0x00
+#define HDMI_CEC_NOT_CORRECT_MODETORESPOND 0x01
+#define HDMI_CEC_CANNOTPROVIDE_SOURCE 0x02
+#define HDMI_CEC_INVALID_OPERAND 0x03
+#define HDMI_CEC_REFUSED 0x04
+
+/**
+ * @brief HDMI CEC specific commands
+ */
+#define HDMI_CEC_OPCODE_ACTIVE_SOURCE ((uint8_t) 0x82)
+#define HDMI_CEC_OPCODE_IMAGE_VIEW_ON ((uint8_t) 0x04)
+#define HDMI_CEC_OPCODE_TEXT_VIEW_ON ((uint8_t) 0x0D)
+#define HDMI_CEC_OPCODE_INACTIVE_SOURCE ((uint8_t) 0x9D)
+#define HDMI_CEC_OPCODE_REQUEST_ACTIVE_SOURCE ((uint8_t) 0x85)
+#define HDMI_CEC_OPCODE_ROUTING_CHANGE ((uint8_t) 0x80)
+#define HDMI_CEC_OPCODE_ROUTING_INFORMATION ((uint8_t) 0x81)
+#define HDMI_CEC_OPCODE_SET_STREAM_PATH ((uint8_t) 0x86)
+#define HDMI_CEC_OPCODE_STANDBY ((uint8_t) 0x36)
+#define HDMI_CEC_OPCODE_RECORD_OFF ((uint8_t) 0x0B)
+#define HDMI_CEC_OPCODE_RECORD_ON ((uint8_t) 0x09)
+#define HDMI_CEC_OPCODE_RECORD_STATUS ((uint8_t) 0x0A)
+#define HDMI_CEC_OPCODE_RECORD_TV_SCREEN ((uint8_t) 0x0F)
+#define HDMI_CEC_OPCODE_CLEAR_ANALOGUE_TIMER ((uint8_t) 0x33)
+#define HDMI_CEC_OPCODE_CLEAR_DIGITAL_TIMER ((uint8_t) 0x99)
+#define HDMI_CEC_OPCODE_CLEAR_EXTERNAL_TIMER ((uint8_t) 0xA1)
+#define HDMI_CEC_OPCODE_SET_ANALOGUE_TIMER ((uint8_t) 0x34)
+#define HDMI_CEC_OPCODE_SET_DIGITAL_TIMER ((uint8_t) 0x97)
+#define HDMI_CEC_OPCODE_SET_EXTERNAL_TIMER ((uint8_t) 0xA2)
+#define HDMI_CEC_OPCODE_SET_TIMER_PROGRAM_TITLE ((uint8_t) 0x67)
+#define HDMI_CEC_OPCODE_TIMER_CLEARED_STATUS ((uint8_t) 0x43)
+#define HDMI_CEC_OPCODE_TIMER_STATUS ((uint8_t) 0x35)
+#define HDMI_CEC_OPCODE_CEC_VERSION ((uint8_t) 0x9E)
+#define HDMI_CEC_OPCODE_GET_CEC_VERSION ((uint8_t) 0x9F)
+#define HDMI_CEC_OPCODE_GIVE_PHYSICAL_ADDRESS ((uint8_t) 0x83)
+#define HDMI_CEC_OPCODE_GET_MENU_LANGUAGE ((uint8_t) 0x91)
+#define HDMI_CEC_OPCODE_REPORT_PHYSICAL_ADDRESS ((uint8_t) 0x84)
+#define HDMI_CEC_OPCODE_SET_MENU_LANGUAGE ((uint8_t) 0x32)
+#define HDMI_CEC_OPCODE_DECK_CONTROL ((uint8_t) 0x42)
+#define HDMI_CEC_OPCODE_DECK_STATUS ((uint8_t) 0x1B)
+#define HDMI_CEC_OPCODE_GIVE_DECK_STATUS ((uint8_t) 0x1A)
+#define HDMI_CEC_OPCODE_PLAY ((uint8_t) 0x41)
+#define HDMI_CEC_OPCODE_GIVE_TUNER_DEVICE_STATUS ((uint8_t) 0x08)
+#define HDMI_CEC_OPCODE_SELECT_ANALOGUE_SERVICE ((uint8_t) 0x92)
+#define HDMI_CEC_OPCODE_SELECT_DIGITAL_SERVICE ((uint8_t) 0x93)
+#define HDMI_CEC_OPCODE_TUNER_DEVICE_STATUS ((uint8_t) 0x07)
+#define HDMI_CEC_OPCODE_TUNER_STEP_DECREMENT ((uint8_t) 0x06)
+#define HDMI_CEC_OPCODE_TUNER_STEP_INCREMENT ((uint8_t) 0x05)
+#define HDMI_CEC_OPCODE_DEVICE_VENDOR_ID ((uint8_t) 0x87)
+#define HDMI_CEC_OPCODE_GIVE_DEVICE_VENDOR_ID ((uint8_t) 0x8C)
+#define HDMI_CEC_OPCODE_VENDOR_COMMAND ((uint8_t) 0x89)
+#define HDMI_CEC_OPCODE_VENDOR_COMMAND_WITH_ID ((uint8_t) 0xA0)
+#define HDMI_CEC_OPCODE_VENDOR_REMOTE_BUTTON_DOWN ((uint8_t) 0x8A)
+#define HDMI_CEC_OPCODE_VENDOR_REMOTE_BUTTON_UP ((uint8_t) 0x8B)
+#define HDMI_CEC_OPCODE_SET_OSD_STRING ((uint8_t) 0x64)
+#define HDMI_CEC_OPCODE_GIVE_OSD_NAME ((uint8_t) 0x46)
+#define HDMI_CEC_OPCODE_SET_OSD_NAME ((uint8_t) 0x47)
+#define HDMI_CEC_OPCODE_MENU_REQUEST ((uint8_t) 0x8D)
+#define HDMI_CEC_OPCODE_MENU_STATUS ((uint8_t) 0x8E)
+#define HDMI_CEC_OPCODE_USER_CONTROL_PRESSED ((uint8_t) 0x44)
+#define HDMI_CEC_OPCODE_USER_CONTROL_RELEASED ((uint8_t) 0x45)
+#define HDMI_CEC_OPCODE_GIVE_DEVICE_POWER_STATUS ((uint8_t) 0x8F)
+#define HDMI_CEC_OPCODE_REPORT_POWER_STATUS ((uint8_t) 0x90)
+#define HDMI_CEC_OPCODE_FEATURE_ABORT ((uint8_t) 0x00)
+#define HDMI_CEC_OPCODE_ABORT ((uint8_t) 0xFF)
+#define HDMI_CEC_OPCODE_GIVE_AUDIO_STATUS ((uint8_t) 0x71)
+#define HDMI_CEC_OPCODE_GIVE_SYSTEM_AUDIO_MODE_STATUS ((uint8_t) 0x7D)
+#define HDMI_CEC_OPCODE_REPORT_AUDIO_STATUS ((uint8_t) 0x7A)
+#define HDMI_CEC_OPCODE_SET_SYSTEM_AUDIO_MODE ((uint8_t) 0x72)
+#define HDMI_CEC_OPCODE_SYSTEM_AUDIO_MODE_REQUEST ((uint8_t) 0x70)
+#define HDMI_CEC_OPCODE_SYSTEM_AUDIO_MODE_STATUS ((uint8_t) 0x7E)
+#define HDMI_CEC_OPCODE_SET_AUDIO_RATE ((uint8_t) 0x9A)
+
+/**
+ * @}
+ */
+
+/** @defgroup STM32373C_EVAL_CEC_Exported_Macros
+ * @{
+ */
+
+/**
+ * @}
+ */
+
+/** @defgroup STM32373C_EVAL_CEC_Exported_Functions
+ * @{
+ */
+HDMI_CEC_Error HDMI_CEC_Init(void);
+HDMI_CEC_Error HDMI_CEC_TransmitMessage(HDMI_CEC_Message *HDMI_CEC_TX_MessageStructure);
+HDMI_CEC_Error HDMI_CEC_GetErrorStatus (void);
+void HDMI_CEC_ProcessIRQSrc(void);
+HDMI_CEC_Error HDMI_CEC_ReportPhysicalAddress(void);
+void HDMI_CEC_CommandCallBack(void);
+HDMI_CEC_Error HDMI_CEC_CheckConnectedDevices(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __STM32373C_EVAL_CEC_H */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32373C_EVAL/stm32373c_eval_i2c_ee_cpal.c b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32373C_EVAL/stm32373c_eval_i2c_ee_cpal.c
new file mode 100644
index 0000000..8cc95d1
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32373C_EVAL/stm32373c_eval_i2c_ee_cpal.c
@@ -0,0 +1,580 @@
+/**
+ ******************************************************************************
+ * @file stm32373c_eval_i2c_ee_cpal.c
+ * @author MCD Application Team
+ * @version V1.0.0
+ * @date 20-September-2012
+ * @brief This file provides a set of functions needed to manage I2C
+ * EEPROM memory.
+ *
+ * ===================================================================
+ * Notes:
+ * - This driver is intended for STM32F37x families devices only.
+ * - The I2C EEPROM memory (M24LR64) is available in RF EEPROM daughter
+ * board (ANT7-M24LR-A) provided with the EVAL board, to use this
+ * driver you have to connect the ANT7-M24LR-A to CN12 connector.
+ * ===================================================================
+ *
+ * It implements a high level communication layer for read and write
+ * from/to this memory.
+ *
+ * @note This file has been updated to use the CPAL library drivers
+ * instead of the Standard peripheral drivers.
+ *
+ * @note In this driver, basic read and write functions (sEE_ReadBuffer()
+ * and sEE_WritePage()) use the DMA or Interrupt to perform the
+ * data transfer to/from EEPROM memory.
+ * Thus, after calling these two functions, user application may
+ * perform other tasks while data transfer is ongoing.
+ * The application should then monitor the variable holding
+ * the state of EEPROM in order to determine when the transfer is
+ * completed . Stopping transfer tasks are performed into DMA or I2C
+ * interrupt handlers (which are integrated into this driver).
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.st.com/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+
+/* Includes ------------------------------------------------------------------*/
+#include "stm32373c_eval_i2c_ee_cpal.h"
+
+
+/* Private typedef -----------------------------------------------------------*/
+
+/*========= sEE_Write_TypeDef =========*/
+/* sEE Write parameter structure definition */
+
+typedef struct
+{
+ __IO uint32_t sEEDataNum; /*!< The number of data that will be written in next transfer */
+
+ uint32_t sEEWriteAddr; /*!< Physical memory address of EEPROM where data will be written */
+
+ __IO uint8_t *sEEpBuffer; /*!< The address of the buffer from which data transfer should start */
+
+ __IO uint16_t sEENumOfPage; /*!< The number of page that will be written */
+
+ __IO uint8_t sEENumOfSingle; /*!< The number of single data that will be written */
+
+ __IO uint8_t sEENextWrite; /*!< This member indicates there is remaining transfers */
+
+} sEE_WriteTypeDef;
+
+/* Private defines -----------------------------------------------------------*/
+/* Private macro -------------------------------------------------------------*/
+/* Private variables ---------------------------------------------------------*/
+
+/*========= Local Structures declaration =========*/
+
+#ifdef CPAL_USE_I2C1
+ sEE_InitTypeDef sEE1_DevStructure = {&I2C1_DevStructure, 0, 0, 0, sEE_STATE_IDLE}; /* Initialize All structure parameters to 0 */
+#endif /* CPAL_USE_I2C1 */
+
+#ifdef CPAL_USE_I2C2
+ sEE_InitTypeDef sEE2_DevStructure = {&I2C2_DevStructure, 0, 0, 0, sEE_STATE_IDLE}; /* Initialize All structure parameters to 0 */
+#endif /* CPAL_USE_I2C2 */
+
+sEE_InitTypeDef* sEE_DevStructures[CPAL_I2C_DEV_NUM] =
+{
+#ifdef CPAL_USE_I2C1
+ &sEE1_DevStructure,
+#else
+ pNULL,
+#endif
+
+#ifdef CPAL_USE_I2C2
+ &sEE2_DevStructure,
+#else
+ pNULL,
+#endif
+};
+
+#ifdef CPAL_USE_I2C1
+ sEE_WriteTypeDef sEE1_WriteStructure = {0, 0, pNULL, 0, 0, 0}; /* Initialize All structure parameters to 0 */
+#endif /* CPAL_USE_I2C1 */
+
+#ifdef CPAL_USE_I2C2
+ sEE_WriteTypeDef sEE2_WriteStructure = {0, 0, pNULL, 0, 0, 0}; /* Initialize All structure parameters to 0 */
+#endif /* CPAL_USE_I2C2 */
+
+sEE_WriteTypeDef* sEE_WriteStructures[CPAL_I2C_DEV_NUM] =
+{
+#ifdef CPAL_USE_I2C1
+ &sEE1_WriteStructure,
+#else
+ pNULL,
+#endif
+
+#ifdef CPAL_USE_I2C2
+ &sEE2_WriteStructure,
+#else
+ pNULL,
+#endif
+};
+
+#ifdef CPAL_USE_I2C1
+CPAL_TransferTypeDef sEE1_TXTransfer = {
+ /* Initialize TX Transfer structure */
+ pNULL,
+ 0,
+ 0,
+ 0};
+
+CPAL_TransferTypeDef sEE1_RXTransfer = {
+ /* Initialize RX Transfer structure */
+ pNULL,
+ 0,
+ 0,
+ 0};
+#endif /* CPAL_USE_I2C1 */
+
+#ifdef CPAL_USE_I2C2
+CPAL_TransferTypeDef sEE2_TXTransfer = {
+ /* Initialize TX Transfer structure */
+ pNULL,
+ 0,
+ 0,
+ 0};
+
+CPAL_TransferTypeDef sEE2_RXTransfer = {
+ /* Initialize RX Transfer structure */
+ pNULL,
+ 0,
+ 0,
+ 0};
+#endif /* CPAL_USE_I2C2 */
+
+CPAL_TransferTypeDef* sEE_TXTransfer[CPAL_I2C_DEV_NUM] =
+{
+#ifdef CPAL_USE_I2C1
+ &sEE1_TXTransfer,
+#else
+ pNULL,
+#endif
+
+#ifdef CPAL_USE_I2C2
+ &sEE2_TXTransfer,
+#else
+ pNULL,
+#endif
+};
+
+
+CPAL_TransferTypeDef* sEE_RXTransfer[CPAL_I2C_DEV_NUM] =
+{
+#ifdef CPAL_USE_I2C1
+ &sEE1_RXTransfer,
+#else
+ pNULL,
+#endif
+
+#ifdef CPAL_USE_I2C2
+ &sEE2_RXTransfer,
+#else
+ pNULL,
+#endif
+};
+
+/**
+ * @}
+ */
+
+/* Private function prototypes -----------------------------------------------*/
+
+
+static uint32_t sEE_WritePage(sEE_InitTypeDef* sEEInitStruct, uint8_t* pBuffer, \
+ uint16_t WriteAddr, uint32_t NumByteToWrite);
+
+/* Private functions ---------------------------------------------------------*/
+
+/**
+ * @brief DeInitialize peripherals used by the I2C EEPROM driver.
+ * @param sEEInitStruct : Pointer to sEE Device structure
+ * @retval None
+ */
+void sEE_DeInit(sEE_InitTypeDef* sEEInitStruct)
+{
+ /* Deinitialize CPAL peripheral */
+ CPAL_I2C_DeInit(sEEInitStruct->sEE_CPALStructure);
+}
+
+/**
+ * @brief Initialize peripherals used by the I2C EEPROM driver.
+ * @param sEEInitStruct : Pointer to sEE Device structure
+ * @retval None
+ */
+void sEE_Init(sEE_InitTypeDef* sEEInitStruct)
+{
+ /* Initialize CPAL peripheral */
+ CPAL_I2C_Init(sEEInitStruct->sEE_CPALStructure);
+}
+
+/**
+ * @brief Initialize sEE CPAL Structure used by the I2C EEPROM driver.
+ * @param sEEInitStruct : Pointer to sEE Device structure
+ * @retval None
+ */
+void sEE_StructInit(sEE_InitTypeDef* sEEInitStruct)
+{
+ /* Set CPAL structure parameters to their default values */
+ CPAL_I2C_StructInit(sEEInitStruct->sEE_CPALStructure);
+
+ /* Set I2C clock speed */
+ sEEInitStruct->sEE_CPALStructure->pCPAL_I2C_Struct->I2C_Timing = sEE_I2C_TIMING;
+
+#ifdef sEE_IT
+ /* Select Interrupt programming model */
+ sEEInitStruct->sEE_CPALStructure->CPAL_ProgModel = CPAL_PROGMODEL_INTERRUPT;
+#else
+ /* Select DMA programming model */
+ sEEInitStruct->sEE_CPALStructure->CPAL_ProgModel = CPAL_PROGMODEL_DMA;
+#endif /* sEE_IT */
+
+ /* Disable all options */
+ sEEInitStruct->sEE_CPALStructure->wCPAL_Options = 0;
+}
+
+/**
+ * @brief Reads a block of data from the EEPROM.
+ * @param sEEInitStruct : Pointer to sEE Device structure
+ * @param pBuffer : pointer to the buffer that receives the data read from
+ * the EEPROM.
+ * @param ReadAddr : EEPROM's internal address to read from.
+ * @param NumByteToRead : pointer to the variable holding number of bytes to
+ * read from the EEPROM.
+ *
+ * @note The variable pointed by NumByteToRead is reset to 0 when all the
+ * data are read from the EEPROM. Application should monitor this
+ * variable in order know when the transfer is complete.
+ *
+ * @note When number of data to be read is higher than 1, this function just
+ * configure the communication and enable the DMA channel to transfer data.
+ * Meanwhile, the user application may perform other tasks.
+ * When number of data to be read is 1, then the DMA is not used.
+ *
+ * @retval None
+ */
+uint32_t sEE_ReadBuffer(sEE_InitTypeDef* sEEInitStruct, uint8_t* pBuffer, \
+ uint16_t ReadAddr, uint32_t NumByteToRead)
+{
+ if (sEEInitStruct->sEEState == sEE_STATE_IDLE)
+ {
+ sEEInitStruct->sEEState = sEE_STATE_READING;
+
+ sEEInitStruct->sEE_CPALStructure->wCPAL_Options = 0;
+
+ /* Enable 16Bit memory register option on CPAL */
+ if (sEEInitStruct->sEEMemoryAddrMode & sEE_OPT_16BIT_REG)
+ {
+ sEEInitStruct->sEE_CPALStructure->wCPAL_Options = CPAL_OPT_16BIT_REG;
+ }
+
+ /* Enable no memory addressing mode option on CPAL */
+ if (sEEInitStruct->sEEMemoryAddrMode & sEE_OPT_NO_MEM_ADDR)
+ {
+ sEEInitStruct->sEE_CPALStructure->wCPAL_Options |= CPAL_OPT_NO_MEM_ADDR;
+ }
+
+ sEEInitStruct->sEE_CPALStructure->pCPAL_TransferRx = sEE_RXTransfer[sEEInitStruct->sEE_CPALStructure->CPAL_Dev];
+
+ sEEInitStruct->sEE_CPALStructure->pCPAL_TransferRx->wNumData = (uint32_t)(NumByteToRead);
+ sEEInitStruct->sEE_CPALStructure->pCPAL_TransferRx->pbBuffer = pBuffer;
+ sEEInitStruct->sEE_CPALStructure->pCPAL_TransferRx->wAddr1 = (uint32_t)((uint8_t)sEEInitStruct->sEEAddress);
+ sEEInitStruct->sEE_CPALStructure->pCPAL_TransferRx->wAddr2 = (uint32_t)((uint16_t)ReadAddr);
+
+ return CPAL_I2C_Read(sEEInitStruct->sEE_CPALStructure);
+ }
+ else
+ {
+ return CPAL_FAIL;
+ }
+}
+
+/**
+ * @brief Writes buffer of data to the I2C EEPROM.
+ * @param sEEInitStruct : Pointer to sEE Device structure
+ * @param pBuffer : pointer to the buffer containing the data to be written
+ * to the EEPROM.
+ * @param WriteAddr : EEPROM's internal address to write to.
+ * @param NumByteToWrite : number of bytes to write to the EEPROM.
+ * @retval None
+ */
+uint32_t sEE_WriteBuffer(sEE_InitTypeDef* sEEInitStruct, uint8_t* pBuffer, \
+ uint16_t WriteAddr, uint32_t NumByteToWrite)
+{
+ uint32_t DataNum = 0;
+ uint16_t count = 0;
+ uint16_t Addr = 0;
+
+ if (sEEInitStruct->sEEState == sEE_STATE_IDLE)
+ {
+ sEEInitStruct->sEEState = sEE_STATE_WRITING;
+
+ sEE_WriteStructures[sEEInitStruct->sEE_CPALStructure->CPAL_Dev]->sEEDataNum = 0;
+ sEE_WriteStructures[sEEInitStruct->sEE_CPALStructure->CPAL_Dev]->sEEWriteAddr = 0;
+ sEE_WriteStructures[sEEInitStruct->sEE_CPALStructure->CPAL_Dev]->sEEpBuffer = pNULL;
+ sEE_WriteStructures[sEEInitStruct->sEE_CPALStructure->CPAL_Dev]->sEENumOfPage = 0;
+ sEE_WriteStructures[sEEInitStruct->sEE_CPALStructure->CPAL_Dev]->sEENextWrite = 0;
+ sEE_WriteStructures[sEEInitStruct->sEE_CPALStructure->CPAL_Dev]->sEENumOfSingle = 0;
+
+ /* if one data will be written */
+ if (NumByteToWrite == 1)
+ {
+ /* Transfer complete */
+ sEE_WriteStructures[sEEInitStruct->sEE_CPALStructure->CPAL_Dev]->sEENextWrite = 0;
+
+ /* update number od data for write */
+ DataNum = NumByteToWrite;
+
+ if(sEE_WritePage(sEEInitStruct, pBuffer, WriteAddr, DataNum) != CPAL_PASS)
+ {
+ return CPAL_FAIL;
+ }
+ }
+ /* Use Write page */
+ else
+ {
+ /* if Address aligned reset count value to 0 */
+ Addr = WriteAddr % sEEInitStruct->sEEPageSize;
+
+ if (Addr == 0)
+ {
+ count = 0;
+ }
+ else
+ {
+ count = sEEInitStruct->sEEPageSize - Addr;
+
+ if (NumByteToWrite <= count)
+ {
+ count = NumByteToWrite;
+ }
+ }
+
+ /* Get Number of page for write and number of single byte */
+ sEE_WriteStructures[sEEInitStruct->sEE_CPALStructure->CPAL_Dev]->sEENumOfPage = \
+ (uint16_t)((NumByteToWrite - count) / sEEInitStruct->sEEPageSize);
+ sEE_WriteStructures[sEEInitStruct->sEE_CPALStructure->CPAL_Dev]->sEENumOfSingle = \
+ (uint8_t)((NumByteToWrite - count) % sEEInitStruct->sEEPageSize);
+
+ /* If WriteAddr is sEE_PAGESIZE is not aligned */
+ if (Addr != 0)
+ {
+ /* Update Number of data to write */
+ sEE_WriteStructures[sEEInitStruct->sEE_CPALStructure->CPAL_Dev]->sEEDataNum = count;
+ }
+ /* If WriteAddr is sEE_PAGESIZE is aligned */
+ else
+ {
+ /* if only single byte must be written */
+ if (sEE_WriteStructures[sEEInitStruct->sEE_CPALStructure->CPAL_Dev]->sEENumOfPage == 0)
+ {
+ /* update number of data to write */
+ sEE_WriteStructures[sEEInitStruct->sEE_CPALStructure->CPAL_Dev]->sEEDataNum = \
+ sEE_WriteStructures[sEEInitStruct->sEE_CPALStructure->CPAL_Dev]->sEENumOfSingle;
+
+ /* reset number of single */
+ sEE_WriteStructures[sEEInitStruct->sEE_CPALStructure->CPAL_Dev]->sEENumOfSingle = 0;
+ }
+ else
+ {
+ /* update number of data to write */
+ sEE_WriteStructures[sEEInitStruct->sEE_CPALStructure->CPAL_Dev]->sEEDataNum = (uint32_t)((uint16_t)sEEInitStruct->sEEPageSize);
+
+ /* update number of page */
+ sEE_WriteStructures[sEEInitStruct->sEE_CPALStructure->CPAL_Dev]->sEENumOfPage--;
+ }
+ }
+
+ /* update global variable */
+ DataNum = sEE_WriteStructures[sEEInitStruct->sEE_CPALStructure->CPAL_Dev]->sEEDataNum;
+ sEE_WriteStructures[sEEInitStruct->sEE_CPALStructure->CPAL_Dev]->sEEWriteAddr = (uint32_t)((uint16_t)WriteAddr);
+ sEE_WriteStructures[sEEInitStruct->sEE_CPALStructure->CPAL_Dev]->sEEpBuffer = pBuffer;
+
+ /* If there are remaining data to transfer */
+ if ((sEE_WriteStructures[sEEInitStruct->sEE_CPALStructure->CPAL_Dev]->sEENumOfPage != 0)
+ || (sEE_WriteStructures[sEEInitStruct->sEE_CPALStructure->CPAL_Dev]->sEENumOfSingle != 0))
+ {
+ /* update global variable */
+ sEE_WriteStructures[sEEInitStruct->sEE_CPALStructure->CPAL_Dev]->sEENextWrite = 1;
+ }
+
+ /* Write data on EEPROM */
+ if (sEE_WritePage(sEEInitStruct, pBuffer, WriteAddr, DataNum) != CPAL_PASS)
+ {
+ return CPAL_FAIL;
+ }
+
+ }
+ return CPAL_PASS;
+ }
+ else
+ {
+ return CPAL_FAIL;
+ }
+}
+
+/**
+ * @brief Handle EEPROM Write operation
+ * @param Device : sEE CPAL device instance
+ * @retval None
+ */
+uint32_t sEE_WriteHandler(CPAL_DevTypeDef Device)
+{
+ uint32_t DataNum = 0;
+
+ /* wait until EEPROM ready for transfer */
+ while (sEE_WaitEepromStandbyState(Device) == CPAL_FAIL);
+
+ /* if there are remaining data for write */
+ if (sEE_WriteStructures[Device]->sEENextWrite != 0)
+ {
+ sEE_WriteStructures[Device]->sEEWriteAddr += sEE_WriteStructures[Device]->sEEDataNum;
+ sEE_WriteStructures[Device]->sEEpBuffer += sEE_WriteStructures[Device]->sEEDataNum;
+ sEE_WriteStructures[Device]->sEENextWrite = 0;
+
+ /* if page must be written in EEPROM */
+ if(sEE_WriteStructures[Device]->sEENumOfPage != 0)
+ {
+ sEE_WriteStructures[Device]->sEEDataNum = (uint32_t)((uint16_t)sEE_DevStructures[Device]->sEEPageSize);
+ sEE_WriteStructures[Device]->sEENumOfPage--;
+ }
+ /* if single byte must be written in EEPROM */
+ else if (sEE_WriteStructures[Device]->sEENumOfSingle != 0)
+ {
+ sEE_WriteStructures[Device]->sEEDataNum = (uint32_t)((uint8_t)sEE_WriteStructures[Device]->sEENumOfSingle);
+ sEE_WriteStructures[Device]->sEENumOfSingle = 0;
+ sEE_WriteStructures[Device]->sEENextWrite = 0;
+ }
+
+ /* update number of date for write */
+ DataNum = sEE_WriteStructures[Device]->sEEDataNum;
+
+ /* if another data must be written */
+ if ((sEE_WriteStructures[Device]->sEENumOfPage != 0)
+ || (sEE_WriteStructures[Device]->sEENumOfSingle != 0))
+ {
+ sEE_WriteStructures[Device]->sEENextWrite = 1;
+ }
+
+ /* write data in EEPROM */
+ sEE_WritePage(sEE_DevStructures[Device],(uint8_t*)sEE_WriteStructures[Device]->sEEpBuffer, \
+ sEE_WriteStructures[Device]->sEEWriteAddr, DataNum);
+ }
+ else
+ {
+ if (sEE_DevStructures[Device]->sEEState != sEE_STATE_ERROR)
+ {
+ /* Reset EEPROM State */
+ sEE_DevStructures[Device]->sEEState = sEE_STATE_IDLE;
+ }
+ }
+
+ return CPAL_PASS;
+}
+
+
+/**
+ * @brief Handle EEPROM Read operation
+ * @param Device : sEE CPAL device instance
+ * @retval None
+ */
+uint32_t sEE_ReadHandler(CPAL_DevTypeDef Device)
+{
+ if (sEE_DevStructures[Device]->sEEState != sEE_STATE_ERROR)
+ {
+ /* Reset EEPROM State */
+ sEE_DevStructures[Device]->sEEState = sEE_STATE_IDLE;
+ }
+
+ return CPAL_PASS;
+}
+
+
+/**
+ * @brief Writes more than one byte to the EEPROM with a single WRITE cycle.
+ * @note The number of byte can't exceed the EEPROM page size.
+ * @param sEEInitStruct : Pointer to sEE Device structure
+ * @param pBuffer : pointer to the buffer containing the data to be written to
+ * the EEPROM.
+ * @param WriteAddr : EEPROM's internal address to write to.
+ * @param NumByteToWrite : pointer to the variable holding number of bytes to
+ * written to the EEPROM.
+ *
+ * @note The variable pointed by NumByteToWrite is reset to 0 when all the
+ * data are read from the EEPROM. Application should monitor this
+ * variable in order know when the transfer is complete.
+ *
+ * @note When number of data to be written is higher than 1, this function just
+ * configure the communication and enable the DMA channel to transfer data.
+ * Meanwhile, the user application may perform other tasks.
+ * When number of data to be written is 1, then the DMA is not used.
+ *
+ * @retval None
+ */
+static uint32_t sEE_WritePage(sEE_InitTypeDef* sEEInitStruct, uint8_t* pBuffer, \
+ uint16_t WriteAddr, uint32_t NumByteToWrite)
+{
+ sEEInitStruct->sEE_CPALStructure->wCPAL_Options = 0;
+
+ /* Enable 16Bit memory register option on CPAL */
+ if (sEEInitStruct->sEEMemoryAddrMode & sEE_OPT_16BIT_REG)
+ {
+ sEEInitStruct->sEE_CPALStructure->wCPAL_Options = CPAL_OPT_16BIT_REG;
+ }
+
+ sEEInitStruct->sEE_CPALStructure->pCPAL_TransferTx = sEE_TXTransfer[sEEInitStruct->sEE_CPALStructure->CPAL_Dev];
+
+ /* Configure transfer parameters */
+ sEEInitStruct->sEE_CPALStructure->pCPAL_TransferTx->wNumData = (uint32_t)(NumByteToWrite);
+ sEEInitStruct->sEE_CPALStructure->pCPAL_TransferTx->pbBuffer = pBuffer;
+ sEEInitStruct->sEE_CPALStructure->pCPAL_TransferTx->wAddr1 = (uint32_t)((uint8_t)sEEInitStruct->sEEAddress);
+ sEEInitStruct->sEE_CPALStructure->pCPAL_TransferTx->wAddr2 = (uint32_t)((uint16_t)WriteAddr);
+
+ /* Write Operation */
+ return CPAL_I2C_Write(sEEInitStruct->sEE_CPALStructure);
+
+}
+
+/**
+ * @brief Wait for EEPROM Standby state
+ * @param Device : sEE CPAL device instance
+ * @retval None
+ */
+uint32_t sEE_WaitEepromStandbyState(CPAL_DevTypeDef Device)
+{
+ sEE_DevStructures[Device]->sEE_CPALStructure->pCPAL_TransferTx = sEE_TXTransfer[Device];
+ sEE_DevStructures[Device]->sEE_CPALStructure->pCPAL_TransferTx->wAddr1 = \
+ (uint32_t)((uint8_t)sEE_DevStructures[Device]->sEEAddress);
+
+ return CPAL_I2C_IsDeviceReady(sEE_DevStructures[Device]->sEE_CPALStructure);
+}
+
+
+/**
+ * @brief Wait for EEPROM Standby state
+ * @param sEEInitStruct : Pointer to sEE Device structure
+ * @retval None
+ */
+uint32_t sEE_GetEepromState(sEE_InitTypeDef* sEEInitStruct)
+{
+ return sEEInitStruct->sEEState;
+}
+
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32373C_EVAL/stm32373c_eval_i2c_ee_cpal.h b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32373C_EVAL/stm32373c_eval_i2c_ee_cpal.h
new file mode 100644
index 0000000..9779bb9
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32373C_EVAL/stm32373c_eval_i2c_ee_cpal.h
@@ -0,0 +1,231 @@
+/**
+ ******************************************************************************
+ * @file stm32373c_eval_i2c_ee_cpal.h
+ * @author MCD Application Team
+ * @version V1.0.0
+ * @date 20-September-2012
+ * @brief This file contains all the functions prototypes for
+ * the stm32373c_eval_i2c_ee_cpal.c firmware driver.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.st.com/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __STM32373C_EVAL_I2C_EE_CPAL_H
+#define __STM32373C_EVAL_I2C_EE_CPAL_H
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+
+/*===================================================================================
+ User NOTES
+=====================================================================================
+
+---------------------------------
+ How To use the EEPROM Driver:
+---------------------------------
+----- All EEPROM operations are controlled and monitored through a single
+ structure. This structure holds all necessary parameters to manage EEPROM
+ communication (pointer to CPAL I2C device structure, EEPROM address,
+ EEPROM page size, EEPROM memory addressing mode, EEPROM state).
+
+----- User should follow these steps to use this driver correctly :
+
+ -1- STRUCTURE INITIALIZATION
+ Start by initializing the structure holding EEPROM Information. To perform
+ this action, the global variable sEEx_DevStructure declared in EEPROM driver
+ as sEE_InitTypeDef (sEE1_DevStructure for EEPROM connected with I2C1,
+ sEE2_DevStructure for EEPROM connected with I2C1 ...) must be used.
+
+ sEE_InitTypeDef structure contains five parameters:
+
+ *- CPAL_InitTypeDef* sEE_CPALStructure : Pointer on a CPAL Device structure
+ relative to the device instantiated
+ to communicate with EEPROM.
+
+ *- uint32_t sEEAddress : Contains the EEPROM device Address.
+
+ *- uint32_t sEEPageSize : Contains the page size of EEPROM Memory.
+
+ *- uint8_t sEEMemoryAddrMode : Bit-field value specifying Memory Addressing Mode.
+
+ *- __IO sEE_StateTypeDef sEEState : Holds the current State of the EEPROM device.
+
+ To configure this structure, user must initialize only three parameters
+ (sEEAddress, sEEPageSize, sEEMemoryAddrMode).
+
+ Example:
+ sEE1_DevStructure.sEEAddress = 0xA0; // set EEPROM address to 0xA0
+ sEE1_DevStructure.sEEPageSize = 32; // set page size to 32
+ sEE1_DevStructure.sEEMemoryAddrMode = sEE_OPT_16BIT_REG; // enable 16Bit memory addressing mode
+
+ -2- DEVICE CONFIGURATION
+ Call the function sEE_StructInit() to initialize I2Cx CPAL device structure
+ relative to EEPROM than call sEE_Init() to configure the selected device
+ with the selected configuration.
+
+ -3- READ / WRITE OPERATIONS
+ Call the function sEE_WriteBuffer() or sEE_ReadBuffer() to perform transfer operations.
+ These functions start data transfer and exit. sEE_WriteHandler() and sEE_ReadHandler()
+ handle the remainder of the communication. sEE_WriteHandler() must be called in
+ CPAL_I2C_TXTC_UserCallback() and sEE_ReadHandler() must be called in CPAL_I2C_RXTC_UserCallback().
+ These two callbacks are implemented in "cpal_usercallback.c" file.
+
+ Example of how to implement sEE_WriteHandler() in CPAL_I2C_TXTC_UserCallback():
+
+ 1** Comment "#define CPAL_I2C_TXTC_UserCallback (void)" in cpal_conf.h.
+ 2** Implement CPAL_I2C_TXTC_UserCallback in "cpal_usercallback.c" file.
+
+ void CPAL_I2C_TXTC_UserCallback(CPAL_InitTypeDef* pDevInitStruct)
+ {
+ sEE_WriteHandler(pDevInitStruct->CPAL_Dev);
+ }
+
+ User should monitor transfer by testing the value of sEEState parameter of
+ sEEx_DevStructure. When transfer is ongoing sEEState is equal to sEE_STATE_WRITING
+ or sEE_STATE_READING. After transfer complete this parameter is set to sEE_STATE_IDLE.
+
+ Example of how to wait until EEPROM communication finishes:
+
+ while(sEE_GetEepromState(&sEE_DevStructure) != sEE_STATE_IDLE)
+ {
+ //Application may perform other tasks while transfer operation is ongoing
+ }
+
+ -4- DEVICE DEINITIALIZATION
+ When transfer operations are finished, you may call sEE_DeInit() to disable I2Cx device
+ and related resources (GPIO, DMA , IT and NVIC) relative to used EEPROM.
+
+*****************************END OF User Notes**********************************************/
+
+/* Includes ------------------------------------------------------------------*/
+#include "stm32f37x_i2c_cpal.h"
+
+/* Exported types ------------------------------------------------------------*/
+
+/*========= sEE_State_Enum =========*/
+/* sEE global State enumeration contains the current state of EEPROM.
+ Before starting each operation this state is tested. After each operation
+ sEE_State is updated with the new value resulting from the relative operation.*/
+
+ typedef enum
+{
+ sEE_STATE_IDLE = 0x01, /*!<This state indicates that the EEPROM device is in idle state */
+
+ sEE_STATE_WRITING = 0x02, /*!<This state indicates that write operation is ongoing */
+
+ sEE_STATE_READING = 0x03, /*!<This state indicates that read operation is ongoing */
+
+ sEE_STATE_ERROR = 0x04, /*!<This state indicates that an error is occurred during
+ last operation */
+
+}sEE_StateTypeDef;
+
+
+/*========= CPAL_sEE_TypeDef =========*/
+/* sEE Device structure definition */
+typedef struct
+{
+ CPAL_InitTypeDef* sEE_CPALStructure; /*!< Pointer on a CPAL Device structure relative to the device
+ instantiated to communicate with EEPROM */
+
+ uint16_t sEEPageSize; /*!< Contains the page size of EEPROM Memory*/
+
+ uint8_t sEEAddress; /*!< Contains the EEPROM device Address */
+
+
+ uint8_t sEEMemoryAddrMode; /*!< Bit-field value specifying Memory Addressing Mode. Can be
+ any combination of following values:
+ sEE_Memory_Addressing_Mode_Defines */
+
+ __IO sEE_StateTypeDef sEEState; /*!< Holds the current State of the EEPROM device. The state
+ parameter can be one of the following values: sEE_State_Enum */
+
+} sEE_InitTypeDef;
+
+
+/*========= sEE_Global_Device_Structures =========*/
+/* sEE Global Device Structures are the Global default structures which
+ are used to handle sEE configuration and status.*/
+
+extern sEE_InitTypeDef* sEE_DevStructures[];
+
+#ifdef CPAL_USE_I2C1
+extern sEE_InitTypeDef sEE1_DevStructure;
+#endif /* CPAL_USE_I2C1 */
+
+#ifdef CPAL_USE_I2C2
+extern sEE_InitTypeDef sEE2_DevStructure;
+#endif /* CPAL_USE_I2C2 */
+
+/* Exported constants --------------------------------------------------------*/
+
+/*============== TIMING Configuration ==========================*/
+/* I2C TIMING Register define */
+/* I2C TIMING is calculated in case of the I2C Clock source is the SYSCLK = 72 MHz */
+/* When using sEE_M24M01 set TIMING to 0x00C4092A to reach 1 MHz speed (Rise time = 26ns, Fall time = 2ns) */
+/* When using sEE_M24LR64 set TIMING to 0xC062121F to reach 100 KHz speed (Rise time = 640ns, Fall time = 20ns) */
+
+#define sEE_I2C_TIMING 0xC062121F
+
+
+/*============== Programming model Configuration ==========================*/
+/* Select interrupt programming model : By default DMA programming model is selected.
+ To select interrupt programming model uncomment this define */
+//#define sEE_IT
+
+/*========= sEE_Memory_Addressing_Mode_Defines =========*/
+/* sEE Memory_Addressing_Mode defines can be affected to sEEMemoryAddrMode which is
+ a bit-field argument so any combination of these parameters can be selected.
+ If one option is not selected then the relative feature is disabled.*/
+
+
+#define sEE_OPT_NO_MEM_ADDR ((uint8_t)0x01) /*!<Enable No Memory addressing mode for read operation : only EEPROM
+ device address sent. No Register/Physical address to be sent after
+ addressing phase */
+
+#define sEE_OPT_16BIT_REG ((uint8_t)0x02) /*!<Enable 16-Bit Register/Physical addressing mode (two bytes,
+ MSB first). This option is supported only when sEE_OPT_NO_MEM_ADDR
+ option is not set */
+
+
+
+/* Exported macro ------------------------------------------------------------*/
+/* Exported functions ------------------------------------------------------- */
+
+void sEE_DeInit(sEE_InitTypeDef* sEEInitStruct);
+void sEE_Init(sEE_InitTypeDef* sEEInitStruct);
+void sEE_StructInit(sEE_InitTypeDef* sEEInitStruct);
+uint32_t sEE_WriteBuffer(sEE_InitTypeDef* sEEInitStruct, uint8_t* pBuffer, uint16_t WriteAddr, uint32_t NumByteToWrite);
+uint32_t sEE_WriteHandler(CPAL_DevTypeDef Device);
+uint32_t sEE_ReadBuffer(sEE_InitTypeDef* sEEInitStruct, uint8_t* pBuffer, uint16_t ReadAddr, uint32_t NumByteToRead);
+uint32_t sEE_ReadHandler(CPAL_DevTypeDef Device);
+uint32_t sEE_WaitEepromStandbyState(CPAL_DevTypeDef Device);
+uint32_t sEE_GetEepromState(sEE_InitTypeDef* sEEInitStruct);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __STM32373C_EVAL_I2C_EE_CPAL_H */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32373C_EVAL/stm32373c_eval_i2c_tsensor_cpal.c b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32373C_EVAL/stm32373c_eval_i2c_tsensor_cpal.c
new file mode 100644
index 0000000..db14977
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32373C_EVAL/stm32373c_eval_i2c_tsensor_cpal.c
@@ -0,0 +1,458 @@
+/**
+ ******************************************************************************
+ * @file stm32373c_eval_i2c_tsensor_cpal.c
+ * @author MCD Application Team
+ * @version V1.0.0
+ * @date 20-September-2012
+ * @brief This file provides a set of functions needed to manage the I2C LM75
+ * temperature sensor mounted on STM32373C-EVAL board .
+ * It implements a high level communication layer for read and write
+ * from/to this sensor.
+ *
+ * @note This file is a modified version of stm32373c_eval_i2c_tsensor.c driver;
+ * I2C CPAL library drivers are used instead of the Standard Peripherals
+ * I2C driver.
+ *
+ *
+ * +-----------------------------------------------------------------+
+ * | Pin assignment |
+ * +---------------------------------------+-----------+-------------+
+ * | STM32 I2C Pins | STLM75 | Pin |
+ * +---------------------------------------+-----------+-------------+
+ * | LM75_I2C_SDA_PIN/ SDA | SDA | 1 |
+ * | LM75_I2C_SCL_PIN/ SCL | SCL | 2 |
+ * | | OS/INT | 3 |
+ * | . | GND | 4 (0V) |
+ * | . | GND | 5 (0V) |
+ * | . | GND | 6 (0V) |
+ * | . | GND | 7 (0V) |
+ * | . | VDD | 8 (3.3V)|
+ * +---------------------------------------+-----------+-------------+
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.st.com/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+
+/* Includes ------------------------------------------------------------------*/
+#include "stm32373c_eval_i2c_tsensor_cpal.h"
+
+/* Private typedef -----------------------------------------------------------*/
+/* Private defines -----------------------------------------------------------*/
+#define LM75_SD_SET 0x01 /*!< Set SD bit in the configuration register */
+#define LM75_SD_RESET 0xFE /*!< Reset SD bit in the configuration register */
+
+/* Private macro -------------------------------------------------------------*/
+/* Private variables ---------------------------------------------------------*/
+
+CPAL_TransferTypeDef LM75_RXTransfer = {
+ /* Initialize TX Transfer structure */
+ pNULL,
+ 0,
+ 0,
+ 0};
+
+CPAL_TransferTypeDef LM75_TXTransfer = {
+ /* Initialize RX Transfer structure */
+ pNULL,
+ 0,
+ 0,
+ 0};
+
+uint8_t LM75_Buffer[2] = {0x00,0x00};
+
+extern CPAL_InitTypeDef LM75_DevStructure;
+
+
+__IO uint32_t LM75_Timeout = LM75_TIMEOUT;
+
+/* Private function prototypes -----------------------------------------------*/
+static void LM75_StructInit(void);
+static void LM75_Init(void);
+
+/* Private functions ---------------------------------------------------------*/
+
+/**
+ * @brief Configure the LM75_I2C.
+ * @param None
+ * @retval None
+ */
+void LM75_Config(void)
+{
+ LM75_StructInit ();
+ LM75_Init();
+}
+
+/**
+ * @brief Deinitialize the LM75_I2C.
+ * @param None
+ * @retval None
+ */
+void LM75_DeInit(void)
+{
+ /* Initialize CPAL peripheral */
+ CPAL_I2C_DeInit(&LM75_DevStructure);
+}
+
+/**
+ * @brief Initializes the LM75_I2C.
+ * @param None
+ * @retval None
+ */
+static void LM75_Init(void)
+{
+ /* Initialize CPAL peripheral */
+ CPAL_I2C_Init(&LM75_DevStructure);
+}
+
+/**
+ * @brief Initializes the LM75_I2C.
+ * @param None
+ * @retval None
+ */
+static void LM75_StructInit(void)
+{
+ /* Set CPAL structure parameters to their default values */
+ CPAL_I2C_StructInit(&LM75_DevStructure);
+
+ /* Set I2C clock speed */
+ LM75_DevStructure.pCPAL_I2C_Struct->I2C_Timing = LM75_I2C_TIMING;
+
+#ifdef LM75_IT
+ /* Select Interrupt programming model */
+ LM75_DevStructure.CPAL_ProgModel = CPAL_PROGMODEL_INTERRUPT;
+#else
+ /* Select DMA programming model */
+ LM75_DevStructure.CPAL_ProgModel = CPAL_PROGMODEL_DMA;
+#endif /* LM75_IT */
+
+ /* Disable all options */
+ LM75_DevStructure.wCPAL_Options = 0;
+
+ /* point to CPAL_TransferTypeDef structure */
+ LM75_DevStructure.pCPAL_TransferTx = &LM75_TXTransfer;
+ LM75_DevStructure.pCPAL_TransferRx = &LM75_RXTransfer;
+}
+
+static uint32_t LM75_Status (void)
+{
+ LM75_DevStructure.pCPAL_TransferTx = &LM75_TXTransfer;
+ LM75_DevStructure.pCPAL_TransferTx->wAddr1 = (uint32_t)LM75_ADDR;
+
+ return CPAL_I2C_IsDeviceReady(&LM75_DevStructure);
+}
+
+/**
+ * @brief Checks the LM75 status.
+ * @param None
+ * @retval ErrorStatus: LM75 Status (ERROR or SUCCESS).
+ */
+ErrorStatus LM75_GetStatus(void)
+{
+ /* Test if LM75 is ready */
+ while ((LM75_Status() == CPAL_FAIL) && LM75_Timeout)
+ {
+ LM75_Timeout--;
+ }
+
+ /* If LM75 is not responding return ERROR */
+ if (LM75_Timeout == 0)
+ {
+ return ERROR;
+ }
+
+ /* In other case return SUCCESS */
+ return SUCCESS;
+}
+/**
+ * @brief Read the specified register from the LM75.
+ * @param RegName: specifies the LM75 register to be read.
+ * This member can be one of the following values:
+ * - LM75_REG_TEMP: temperature register
+ * - LM75_REG_TOS: Over-limit temperature register
+ * - LM75_REG_THYS: Hysteresis temperature register
+ * @retval LM75 register value.
+ */
+uint16_t LM75_ReadReg(uint8_t RegName)
+{
+ uint16_t tmp = 0;
+
+ LM75_Buffer[0] = 0;
+ LM75_Buffer[1] = 0;
+
+ /* Disable all options */
+ LM75_DevStructure.wCPAL_Options = 0;
+
+ /* point to CPAL_TransferTypeDef structure */
+ LM75_DevStructure.pCPAL_TransferRx = &LM75_RXTransfer;
+
+ /* Configure transfer parameters */
+ LM75_DevStructure.pCPAL_TransferRx->wNumData = 2;
+ LM75_DevStructure.pCPAL_TransferRx->pbBuffer = LM75_Buffer ;
+ LM75_DevStructure.pCPAL_TransferRx->wAddr1 = (uint32_t)LM75_ADDR;
+ LM75_DevStructure.pCPAL_TransferRx->wAddr2 = (uint32_t)RegName;
+
+ /* Read Operation */
+ if(CPAL_I2C_Read(&LM75_DevStructure) == CPAL_PASS)
+ {
+ while ((LM75_DevStructure.CPAL_State != CPAL_STATE_READY) && (LM75_DevStructure.CPAL_State != CPAL_STATE_ERROR) )
+ { }
+ }
+
+ /* Store LM75_I2C received data */
+ tmp = (uint16_t)(LM75_Buffer[0] << 8);
+ tmp |= LM75_Buffer[1];
+
+ /* return a Reg value */
+ return (uint16_t)tmp;
+}
+
+/**
+ * @brief Write to the specified register of the LM75.
+ * @param RegName: specifies the LM75 register to be written.
+ * This member can be one of the following values:
+ * - LM75_REG_TOS: Over-limit temperature register
+ * - LM75_REG_THYS: Hysteresis temperature register
+ * @param RegValue: value to be written to LM75 register.
+ * @retval None
+ */
+uint8_t LM75_WriteReg(uint8_t RegName, uint16_t RegValue)
+{
+ LM75_Buffer[0] = (uint8_t)(RegValue >> 8);
+ LM75_Buffer[1] = (uint8_t)(RegValue);
+
+ /* Disable all options */
+ LM75_DevStructure.wCPAL_Options = 0;
+
+ /* point to CPAL_TransferTypeDef structure */
+ LM75_DevStructure.pCPAL_TransferTx = &LM75_TXTransfer;
+
+ /* Configure transfer parameters */
+ LM75_DevStructure.pCPAL_TransferTx->wNumData = 2;
+ LM75_DevStructure.pCPAL_TransferTx->pbBuffer = LM75_Buffer ;
+ LM75_DevStructure.pCPAL_TransferTx->wAddr1 = (uint32_t)LM75_ADDR;
+ LM75_DevStructure.pCPAL_TransferTx->wAddr2 = (uint32_t)RegName;
+
+ /* Write Operation */
+ if(CPAL_I2C_Write(&LM75_DevStructure) == CPAL_PASS)
+ {
+ while ((LM75_DevStructure.CPAL_State != CPAL_STATE_READY) && (LM75_DevStructure.CPAL_State != CPAL_STATE_ERROR) )
+ { }
+
+ if (LM75_DevStructure.CPAL_State == CPAL_STATE_ERROR)
+ {
+ return LM75_FAIL;
+ }
+ }
+ else
+ {
+ return LM75_FAIL;
+ }
+
+ return LM75_OK;
+}
+
+/**
+ * @brief Read Temperature register of LM75: double temperature value.
+ * @param None
+ * @retval LM75 measured temperature value.
+ */
+uint16_t LM75_ReadTemp(void)
+{
+ uint16_t tmp = 0;
+
+ LM75_Buffer[0] = 0;
+ LM75_Buffer[1] = 0;
+
+ /* Disable all options */
+ LM75_DevStructure.wCPAL_Options = 0;
+
+ /* point to CPAL_TransferTypeDef structure */
+ LM75_DevStructure.pCPAL_TransferRx = &LM75_RXTransfer;
+
+ /* Configure transfer parameters */
+ LM75_DevStructure.pCPAL_TransferRx->wNumData = 2;
+ LM75_DevStructure.pCPAL_TransferRx->pbBuffer = LM75_Buffer ;
+ LM75_DevStructure.pCPAL_TransferRx->wAddr1 = (uint32_t)LM75_ADDR;
+ LM75_DevStructure.pCPAL_TransferRx->wAddr2 = (uint32_t)LM75_REG_TEMP;
+
+ /* Read Operation */
+ if(CPAL_I2C_Read(&LM75_DevStructure) == CPAL_PASS)
+ {
+ while ((LM75_DevStructure.CPAL_State != CPAL_STATE_READY) && (LM75_DevStructure.CPAL_State != CPAL_STATE_ERROR) )
+ { }
+ }
+
+ /* Store LM75_I2C received data */
+ tmp = (uint16_t)(LM75_Buffer[0] << 8);
+ tmp |= LM75_Buffer[1];
+
+ /* Return Temperature value */
+ return (uint16_t)(tmp >> 7);
+}
+
+/**
+ * @brief Read the configuration register from the LM75.
+ * @param None
+ * @retval LM75 configuration register value.
+ */
+uint8_t LM75_ReadConfReg(void)
+{
+ LM75_Buffer[0] = 0;
+
+ /* Disable all options */
+ LM75_DevStructure.wCPAL_Options = 0;
+
+ /* point to CPAL_TransferTypeDef structure */
+ LM75_DevStructure.pCPAL_TransferRx = &LM75_RXTransfer;
+
+ /* Configure transfer parameters */
+ LM75_DevStructure.pCPAL_TransferRx->wNumData = 1;
+ LM75_DevStructure.pCPAL_TransferRx->pbBuffer = LM75_Buffer ;
+ LM75_DevStructure.pCPAL_TransferRx->wAddr1 = (uint32_t)LM75_ADDR;
+ LM75_DevStructure.pCPAL_TransferRx->wAddr2 = (uint32_t)LM75_REG_CONF;
+
+ /* Read Operation */
+ if(CPAL_I2C_Read(&LM75_DevStructure) == CPAL_PASS)
+ {
+ while ((LM75_DevStructure.CPAL_State != CPAL_STATE_READY) && (LM75_DevStructure.CPAL_State != CPAL_STATE_ERROR) )
+ { }
+ }
+
+ /* Return Temperature value */
+ return (uint8_t)LM75_Buffer[0];
+}
+
+/**
+ * @brief Write to the configuration register of the LM75.
+ * @param RegValue: specifies the value to be written to LM75 configuration
+ * register.
+ * @retval None
+ */
+uint8_t LM75_WriteConfReg(uint8_t RegValue)
+{
+ LM75_Buffer[0] = (uint8_t)(RegValue);
+
+ /* Disable all options */
+ LM75_DevStructure.wCPAL_Options = 0;
+
+ /* point to CPAL_TransferTypeDef structure */
+ LM75_DevStructure.pCPAL_TransferTx = &LM75_TXTransfer;
+
+ /* Configure transfer parameters */
+ LM75_DevStructure.pCPAL_TransferTx->wNumData = 1;
+ LM75_DevStructure.pCPAL_TransferTx->pbBuffer = LM75_Buffer ;
+ LM75_DevStructure.pCPAL_TransferTx->wAddr1 = (uint32_t)LM75_ADDR;
+ LM75_DevStructure.pCPAL_TransferTx->wAddr2 = (uint32_t)LM75_REG_CONF;
+
+ /* Write Operation */
+ if(CPAL_I2C_Write(&LM75_DevStructure) == CPAL_PASS)
+ {
+ while ((LM75_DevStructure.CPAL_State != CPAL_STATE_READY) && (LM75_DevStructure.CPAL_State != CPAL_STATE_ERROR) )
+ { }
+
+ if (LM75_DevStructure.CPAL_State == CPAL_STATE_ERROR)
+ {
+ return LM75_FAIL;
+ }
+ }
+ else
+ {
+ return LM75_FAIL;
+ }
+
+ return LM75_OK;
+
+}
+
+/**
+ * @brief Enables or disables the LM75.
+ * @param NewState: specifies the LM75 new status. This parameter can be ENABLE
+ * or DISABLE.
+ * @retval None
+ */
+uint8_t LM75_ShutDown(FunctionalState NewState)
+{
+ __IO uint8_t RegValue = 0;
+
+ LM75_Buffer[0] = 0;
+
+ /* Disable all options */
+ LM75_DevStructure.wCPAL_Options = 0;
+
+ /* point to CPAL_TransferTypeDef structure */
+ LM75_DevStructure.pCPAL_TransferRx = &LM75_RXTransfer;
+
+ /* Configure transfer parameters */
+ LM75_DevStructure.pCPAL_TransferRx->wNumData = 1;
+ LM75_DevStructure.pCPAL_TransferRx->pbBuffer = LM75_Buffer ;
+ LM75_DevStructure.pCPAL_TransferRx->wAddr1 = (uint32_t)LM75_ADDR;
+ LM75_DevStructure.pCPAL_TransferRx->wAddr2 = (uint32_t)LM75_REG_CONF;
+
+ /* Read Operation */
+ if(CPAL_I2C_Read(&LM75_DevStructure) == CPAL_PASS)
+ {
+ while ((LM75_DevStructure.CPAL_State != CPAL_STATE_READY) && (LM75_DevStructure.CPAL_State != CPAL_STATE_ERROR) )
+ { }
+ }
+
+ /* Get received data */
+ RegValue = (uint8_t)LM75_Buffer[0];
+
+ /*---------------------------- Transmission Phase ---------------------------*/
+
+ /* Enable or disable SD bit */
+ if (NewState != DISABLE)
+ {
+ /* Enable LM75 */
+ LM75_Buffer[0] = RegValue & LM75_SD_RESET;
+ }
+ else
+ {
+ /* Disable LM75 */
+ LM75_Buffer[0] = RegValue | LM75_SD_SET;
+ }
+
+ /* point to CPAL_TransferTypeDef structure */
+ LM75_DevStructure.pCPAL_TransferTx = &LM75_TXTransfer;
+
+ /* Configure transfer parameters */
+ LM75_DevStructure.pCPAL_TransferTx->wNumData = 1;
+ LM75_DevStructure.pCPAL_TransferTx->pbBuffer = LM75_Buffer ;
+ LM75_DevStructure.pCPAL_TransferTx->wAddr1 = (uint32_t)LM75_ADDR;
+ LM75_DevStructure.pCPAL_TransferTx->wAddr2 = (uint32_t)LM75_REG_CONF;
+
+ /* Write Operation */
+ if(CPAL_I2C_Write(&LM75_DevStructure) == CPAL_PASS)
+ {
+ while ((LM75_DevStructure.CPAL_State != CPAL_STATE_READY) && (LM75_DevStructure.CPAL_State != CPAL_STATE_ERROR) )
+ { }
+
+ if (LM75_DevStructure.CPAL_State == CPAL_STATE_ERROR)
+ {
+ return LM75_FAIL;
+ }
+ }
+ else
+ {
+ return LM75_FAIL;
+ }
+
+ return LM75_OK;
+}
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32373C_EVAL/stm32373c_eval_i2c_tsensor_cpal.h b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32373C_EVAL/stm32373c_eval_i2c_tsensor_cpal.h
new file mode 100644
index 0000000..dd868b4
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32373C_EVAL/stm32373c_eval_i2c_tsensor_cpal.h
@@ -0,0 +1,129 @@
+/**
+ ******************************************************************************
+ * @file stm32373c_eval_i2c_tsensor_cpal.h
+ * @author MCD Application Team
+ * @version V1.0.0
+ * @date 20-September-2012
+ * @brief This file contains all the functions prototypes for the
+ * stm32373c_eval_i2c_tsensor_cpal.c firmware driver.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.st.com/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __STM32373C_EVAL_I2C_TSENSOR_CPAL_H
+#define __STM32373C_EVAL_I2C_TSENSOR_CPAL_H
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+
+/* Includes ------------------------------------------------------------------*/
+#include "stm32f37x_i2c_cpal.h"
+
+/* Exported types ------------------------------------------------------------*/
+
+/**
+ * @brief TSENSOR Status
+ */
+typedef enum
+{
+ LM75_OK = 0,
+ LM75_FAIL
+}LM75_Status_TypDef;
+
+/* Exported constants --------------------------------------------------------*/
+
+/*====================== CPAL Structure configuration ========================*/
+/* Select I2C device (uncomment relative define) */
+
+//#define LM75_DevStructure I2C1_DevStructure
+#define LM75_DevStructure I2C2_DevStructure
+
+
+/*============== TIMING Configuration ==========================*/
+/* I2C TIMING Register define when I2C clock source is SYSCLK */
+/* I2C TIMING is calculated in case of the I2C Clock source is the SYSCLK = 72 MHz */
+/* set TIMING to 0xC062121F to reach 100 KHz speed (Rise time = 640ns, Fall time = 20ns) */
+
+#define LM75_I2C_TIMING 0xC062121F
+
+
+/*=================== Programming model Configuration ========================*/
+/* Select interrupt programming model : By default DMA programming model is selected.
+ To select interrupt programming model uncomment this define */
+//#define LM75_IT
+
+
+/* Maximum Timeout values for waiting until device is ready for communication.*/
+
+#define LM75_TIMEOUT ((uint32_t)0x3FFFF)
+
+/**
+ * @brief Internal register Memory
+ */
+#define LM75_REG_TEMP 0x00 /*!< Temperature Register of LM75 */
+#define LM75_REG_CONF 0x01 /*!< Configuration Register of LM75 */
+#define LM75_REG_THYS 0x02 /*!< Temperature Register of LM75 */
+#define LM75_REG_TOS 0x03 /*!< Over-temp Shutdown threshold Register of LM75 */
+#define LM75_ADDR 0x90 /*!< LM75 address */
+
+
+/* Exported macro ------------------------------------------------------------*/
+/* Exported functions ------------------------------------------------------- */
+
+void LM75_DeInit(void);
+void LM75_Config(void);
+ErrorStatus LM75_GetStatus(void);
+uint16_t LM75_ReadTemp(void);
+uint16_t LM75_ReadReg(uint8_t RegName);
+uint8_t LM75_WriteReg(uint8_t RegName, uint16_t RegValue);
+uint8_t LM75_ReadConfReg(void);
+uint8_t LM75_WriteConfReg(uint8_t RegValue);
+uint8_t LM75_ShutDown(FunctionalState NewState);
+
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __STM32373C_EVAL_I2C_TSENSOR_CPAL_H */
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32373C_EVAL/stm32373c_eval_spi_sd.c b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32373C_EVAL/stm32373c_eval_spi_sd.c
new file mode 100644
index 0000000..33e9f74
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32373C_EVAL/stm32373c_eval_spi_sd.c
@@ -0,0 +1,908 @@
+/**
+ ******************************************************************************
+ * @file stm32373c_eval_spi_sd.c
+ * @author MCD Application Team
+ * @version V1.0.0
+ * @date 20-September-2012
+ * @brief This file provides a set of functions needed to manage the SPI SD
+ * Card memory mounted on STM32373C-EVAL board.
+ * It implements a high level communication layer for read and write
+ * from/to this memory. The needed STM32F37x hardware resources (SPI and
+ * GPIO) are defined in stm32373c_eval.h file, and the initialization is
+ * performed in SD_LowLevel_Init() function declared in stm32373c_eval.c
+ * file.
+ * You can easily tailor this driver to any other development board,
+ * by just adapting the defines for hardware resources and
+ * SD_LowLevel_Init() function.
+ *
+ * +-------------------------------------------------------+
+ * | Pin assignment |
+ * +-------------------------+---------------+-------------+
+ * | STM32F0xx SPI Pins | SD | Pin |
+ * +-------------------------+---------------+-------------+
+ * | SD_SPI_CS_PIN | ChipSelect | 1 |
+ * | SD_SPI_MOSI_PIN / MOSI | DataIn | 2 |
+ * | | GND | 3 (0 V) |
+ * | | VDD | 4 (3.3 V)|
+ * | SD_SPI_SCK_PIN / SCLK | Clock | 5 |
+ * | | GND | 6 (0 V) |
+ * | SD_SPI_MISO_PIN / MISO | DataOut | 7 |
+ * +-------------------------+---------------+-------------+
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.st.com/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+
+/* Includes ------------------------------------------------------------------*/
+#include "stm32373c_eval_spi_sd.h"
+
+/** @addtogroup Utilities
+ * @{
+ */
+
+/** @addtogroup STM32_EVAL
+ * @{
+ */
+
+/** @addtogroup STM32373C_EVAL
+ * @{
+ */
+
+/** @addtogroup STM32373C_EVAL_SPI_SD
+ * @brief This file includes the SD card driver of STM32373C-EVAL boards.
+ * @{
+ */
+
+/** @defgroup STM32373C_EVAL_SPI_SD_Private_Types
+ * @{
+ */
+/**
+ * @}
+ */
+
+
+/** @defgroup STM32373C_EVAL_SPI_SD_Private_Defines
+ * @{
+ */
+/**
+ * @}
+ */
+
+/** @defgroup STM32373C_EVAL_SPI_SD_Private_Macros
+ * @{
+ */
+/**
+ * @}
+ */
+
+
+/** @defgroup STM32373C_EVAL_SPI_SD_Private_Variables
+ * @{
+ */
+
+/**
+ * @}
+ */
+
+
+/** @defgroup STM32373C_EVAL_SPI_SD_Private_Function_Prototypes
+ * @{
+ */
+/**
+ * @}
+ */
+
+
+/** @defgroup STM32373C_EVAL_SPI_SD_Private_Functions
+ * @{
+ */
+
+/**
+ * @brief DeInitializes the SD/SD communication.
+ * @param None
+ * @retval None
+ */
+void SD_DeInit(void)
+{
+ SD_LowLevel_DeInit();
+}
+
+/**
+ * @brief Initializes the SD/SD communication.
+ * @param None
+ * @retval The SD Response:
+ * - SD_RESPONSE_FAILURE: Sequence failed
+ * - SD_RESPONSE_NO_ERROR: Sequence succeed
+ */
+SD_Error SD_Init(void)
+{
+ uint32_t i = 0;
+
+ /*!< Initialize SD_SPI */
+ SD_LowLevel_Init();
+
+ /*!< SD chip select high */
+ SD_CS_HIGH();
+
+ /*!< Send dummy byte 0xFF, 10 times with CS high */
+ /*!< Rise CS and MOSI for 80 clocks cycles */
+ for (i = 0; i <= 9; i++)
+ {
+ /*!< Send dummy byte 0xFF */
+ SD_WriteByte(SD_DUMMY_BYTE);
+ }
+
+ /*------------Put SD in SPI mode--------------*/
+ /*!< SD initialized and set to SPI mode properly */
+ return (SD_GoIdleState());
+}
+
+/**
+ * @brief Detect if SD card is correctly plugged in the memory slot.
+ * @param None
+ * @retval Return if SD is detected or not
+ */
+uint8_t SD_Detect(void)
+{
+ __IO uint8_t status = SD_PRESENT;
+
+ /*!< Check GPIO to detect SD */
+ if (GPIO_ReadInputData(SD_DETECT_GPIO_PORT) & SD_DETECT_PIN)
+ {
+ status = SD_NOT_PRESENT;
+ }
+ return status;
+}
+
+/**
+ * @brief Returns information about specific card.
+ * @param cardinfo: pointer to a SD_CardInfo structure that contains all SD
+ * card information.
+ * @retval The SD Response:
+ * - SD_RESPONSE_FAILURE: Sequence failed
+ * - SD_RESPONSE_NO_ERROR: Sequence succeed
+ */
+SD_Error SD_GetCardInfo(SD_CardInfo *cardinfo)
+{
+ SD_Error status = SD_RESPONSE_FAILURE;
+
+ SD_GetCSDRegister(&(cardinfo->SD_csd));
+ status = SD_GetCIDRegister(&(cardinfo->SD_cid));
+ cardinfo->CardCapacity = (cardinfo->SD_csd.DeviceSize + 1) ;
+ cardinfo->CardCapacity *= (1 << (cardinfo->SD_csd.DeviceSizeMul + 2));
+ cardinfo->CardBlockSize = 1 << (cardinfo->SD_csd.RdBlockLen);
+ cardinfo->CardCapacity *= cardinfo->CardBlockSize;
+
+ /*!< Returns the reponse */
+ return status;
+}
+
+/**
+ * @brief Reads a block of data from the SD.
+ * @param pBuffer: pointer to the buffer that receives the data read from the
+ * SD.
+ * @param ReadAddr: SD's internal address to read from.
+ * @param BlockSize: the SD card Data block size.
+ * @retval The SD Response:
+ * - SD_RESPONSE_FAILURE: Sequence failed
+ * - SD_RESPONSE_NO_ERROR: Sequence succeed
+ */
+SD_Error SD_ReadBlock(uint8_t* pBuffer, uint32_t ReadAddr, uint16_t BlockSize)
+{
+ uint32_t i = 0;
+ SD_Error rvalue = SD_RESPONSE_FAILURE;
+
+ /*!< SD chip select low */
+ SD_CS_LOW();
+
+ /*!< Send CMD17 (SD_CMD_READ_SINGLE_BLOCK) to read one block */
+ SD_SendCmd(SD_CMD_READ_SINGLE_BLOCK, ReadAddr, 0xFF);
+
+ /*!< Check if the SD acknowledged the read block command: R1 response (0x00: no errors) */
+ if (!SD_GetResponse(SD_RESPONSE_NO_ERROR))
+ {
+ /*!< Now look for the data token to signify the start of the data */
+ if (!SD_GetResponse(SD_START_DATA_SINGLE_BLOCK_READ))
+ {
+ /*!< Read the SD block data : read NumByteToRead data */
+ for (i = 0; i < BlockSize; i++)
+ {
+ /*!< Save the received data */
+ *pBuffer = SD_ReadByte();
+
+ /*!< Point to the next location where the byte read will be saved */
+ pBuffer++;
+ }
+ /*!< Get CRC bytes (not really needed by us, but required by SD) */
+ SD_ReadByte();
+ SD_ReadByte();
+ /*!< Set response value to success */
+ rvalue = SD_RESPONSE_NO_ERROR;
+ }
+ }
+ /*!< SD chip select high */
+ SD_CS_HIGH();
+
+ /*!< Send dummy byte: 8 Clock pulses of delay */
+ SD_WriteByte(SD_DUMMY_BYTE);
+
+ /*!< Returns the reponse */
+ return rvalue;
+}
+
+/**
+ * @brief Reads multiple block of data from the SD.
+ * @param pBuffer: pointer to the buffer that receives the data read from the
+ * SD.
+ * @param ReadAddr: SD's internal address to read from.
+ * @param BlockSize: the SD card Data block size.
+ * @param NumberOfBlocks: number of blocks to be read.
+ * @retval The SD Response:
+ * - SD_RESPONSE_FAILURE: Sequence failed
+ * - SD_RESPONSE_NO_ERROR: Sequence succeed
+ */
+SD_Error SD_ReadMultiBlocks(uint8_t* pBuffer, uint32_t ReadAddr, uint16_t BlockSize, uint32_t NumberOfBlocks)
+{
+ uint32_t i = 0, Offset = 0;
+ SD_Error rvalue = SD_RESPONSE_FAILURE;
+
+ /*!< SD chip select low */
+ SD_CS_LOW();
+ /*!< Data transfer */
+ while (NumberOfBlocks--)
+ {
+ /*!< Send CMD17 (SD_CMD_READ_SINGLE_BLOCK) to read one block */
+ SD_SendCmd (SD_CMD_READ_SINGLE_BLOCK, ReadAddr + Offset, 0xFF);
+ /*!< Check if the SD acknowledged the read block command: R1 response (0x00: no errors) */
+ if (SD_GetResponse(SD_RESPONSE_NO_ERROR))
+ {
+ return SD_RESPONSE_FAILURE;
+ }
+ /*!< Now look for the data token to signify the start of the data */
+ if (!SD_GetResponse(SD_START_DATA_SINGLE_BLOCK_READ))
+ {
+ /*!< Read the SD block data : read NumByteToRead data */
+ for (i = 0; i < BlockSize; i++)
+ {
+ /*!< Read the pointed data */
+ *pBuffer = SD_ReadByte();
+ /*!< Point to the next location where the byte read will be saved */
+ pBuffer++;
+ }
+ /*!< Set next read address*/
+ Offset += 512;
+ /*!< get CRC bytes (not really needed by us, but required by SD) */
+ SD_ReadByte();
+ SD_ReadByte();
+ /*!< Set response value to success */
+ rvalue = SD_RESPONSE_NO_ERROR;
+ }
+ else
+ {
+ /*!< Set response value to failure */
+ rvalue = SD_RESPONSE_FAILURE;
+ }
+ }
+ /*!< SD chip select high */
+ SD_CS_HIGH();
+ /*!< Send dummy byte: 8 Clock pulses of delay */
+ SD_WriteByte(SD_DUMMY_BYTE);
+ /*!< Returns the reponse */
+ return rvalue;
+}
+
+/**
+ * @brief Writes a block on the SD
+ * @param pBuffer: pointer to the buffer containing the data to be written on
+ * the SD.
+ * @param WriteAddr: address to write on.
+ * @param BlockSize: the SD card Data block size.
+ * @retval The SD Response:
+ * - SD_RESPONSE_FAILURE: Sequence failed
+ * - SD_RESPONSE_NO_ERROR: Sequence succeed
+ */
+SD_Error SD_WriteBlock(uint8_t* pBuffer, uint32_t WriteAddr, uint16_t BlockSize)
+{
+ uint32_t i = 0;
+ SD_Error rvalue = SD_RESPONSE_FAILURE;
+
+ /*!< SD chip select low */
+ SD_CS_LOW();
+
+ /*!< Send CMD24 (SD_CMD_WRITE_SINGLE_BLOCK) to write multiple block */
+ SD_SendCmd(SD_CMD_WRITE_SINGLE_BLOCK, WriteAddr, 0xFF);
+
+ /*!< Check if the SD acknowledged the write block command: R1 response (0x00: no errors) */
+ if (!SD_GetResponse(SD_RESPONSE_NO_ERROR))
+ {
+ /*!< Send a dummy byte */
+ SD_WriteByte(SD_DUMMY_BYTE);
+
+ /*!< Send the data token to signify the start of the data */
+ SD_WriteByte(0xFE);
+
+ /*!< Write the block data to SD : write count data by block */
+ for (i = 0; i < BlockSize; i++)
+ {
+ /*!< Send the pointed byte */
+ SD_WriteByte(*pBuffer);
+ /*!< Point to the next location where the byte read will be saved */
+ pBuffer++;
+ }
+ /*!< Put CRC bytes (not really needed by us, but required by SD) */
+ SD_ReadByte();
+ SD_ReadByte();
+ /*!< Read data response */
+ if (SD_GetDataResponse() == SD_DATA_OK)
+ {
+ rvalue = SD_RESPONSE_NO_ERROR;
+ }
+ }
+ /*!< SD chip select high */
+ SD_CS_HIGH();
+ /*!< Send dummy byte: 8 Clock pulses of delay */
+ SD_WriteByte(SD_DUMMY_BYTE);
+
+ /*!< Returns the reponse */
+ return rvalue;
+}
+
+/**
+ * @brief Writes many blocks on the SD
+ * @param pBuffer: pointer to the buffer containing the data to be written on
+ * the SD.
+ * @param WriteAddr: address to write on.
+ * @param BlockSize: the SD card Data block size.
+ * @param NumberOfBlocks: number of blocks to be written.
+ * @retval The SD Response:
+ * - SD_RESPONSE_FAILURE: Sequence failed
+ * - SD_RESPONSE_NO_ERROR: Sequence succeed
+ */
+SD_Error SD_WriteMultiBlocks(uint8_t* pBuffer, uint32_t WriteAddr, uint16_t BlockSize, uint32_t NumberOfBlocks)
+{
+ uint32_t i = 0, Offset = 0;
+ SD_Error rvalue = SD_RESPONSE_FAILURE;
+
+ /*!< SD chip select low */
+ SD_CS_LOW();
+ /*!< Data transfer */
+ while (NumberOfBlocks--)
+ {
+ /*!< Send CMD24 (SD_CMD_WRITE_SINGLE_BLOCK) to write blocks */
+ SD_SendCmd(SD_CMD_WRITE_SINGLE_BLOCK, WriteAddr + Offset, 0xFF);
+ /*!< Check if the SD acknowledged the write block command: R1 response (0x00: no errors) */
+ if (SD_GetResponse(SD_RESPONSE_NO_ERROR))
+ {
+ return SD_RESPONSE_FAILURE;
+ }
+ /*!< Send dummy byte */
+ SD_WriteByte(SD_DUMMY_BYTE);
+ /*!< Send the data token to signify the start of the data */
+ SD_WriteByte(SD_START_DATA_SINGLE_BLOCK_WRITE);
+ /*!< Write the block data to SD : write count data by block */
+ for (i = 0; i < BlockSize; i++)
+ {
+ /*!< Send the pointed byte */
+ SD_WriteByte(*pBuffer);
+ /*!< Point to the next location where the byte read will be saved */
+ pBuffer++;
+ }
+ /*!< Set next write address */
+ Offset += 512;
+ /*!< Put CRC bytes (not really needed by us, but required by SD) */
+ SD_ReadByte();
+ SD_ReadByte();
+ /*!< Read data response */
+ if (SD_GetDataResponse() == SD_DATA_OK)
+ {
+ /*!< Set response value to success */
+ rvalue = SD_RESPONSE_NO_ERROR;
+ }
+ else
+ {
+ /*!< Set response value to failure */
+ rvalue = SD_RESPONSE_FAILURE;
+ }
+ }
+ /*!< SD chip select high */
+ SD_CS_HIGH();
+ /*!< Send dummy byte: 8 Clock pulses of delay */
+ SD_WriteByte(SD_DUMMY_BYTE);
+ /*!< Returns the reponse */
+ return rvalue;
+}
+
+/**
+ * @brief Read the CSD card register.
+ * Reading the contents of the CSD register in SPI mode is a simple
+ * read-block transaction.
+ * @param SD_csd: pointer on an SCD register structure
+ * @retval The SD Response:
+ * - SD_RESPONSE_FAILURE: Sequence failed
+ * - SD_RESPONSE_NO_ERROR: Sequence succeed
+ */
+SD_Error SD_GetCSDRegister(SD_CSD* SD_csd)
+{
+ uint32_t i = 0;
+ SD_Error rvalue = SD_RESPONSE_FAILURE;
+ uint8_t CSD_Tab[16];
+
+ /*!< SD chip select low */
+ SD_CS_LOW();
+ /*!< Send CMD9 (CSD register) or CMD10(CSD register) */
+ SD_SendCmd(SD_CMD_SEND_CSD, 0, 0xFF);
+ /*!< Wait for response in the R1 format (0x00 is no errors) */
+ if (!SD_GetResponse(SD_RESPONSE_NO_ERROR))
+ {
+ if (!SD_GetResponse(SD_START_DATA_SINGLE_BLOCK_READ))
+ {
+ for (i = 0; i < 16; i++)
+ {
+ /*!< Store CSD register value on CSD_Tab */
+ CSD_Tab[i] = SD_ReadByte();
+ }
+ }
+ /*!< Get CRC bytes (not really needed by us, but required by SD) */
+ SD_WriteByte(SD_DUMMY_BYTE);
+ SD_WriteByte(SD_DUMMY_BYTE);
+ /*!< Set response value to success */
+ rvalue = SD_RESPONSE_NO_ERROR;
+ }
+ /*!< SD chip select high */
+ SD_CS_HIGH();
+ /*!< Send dummy byte: 8 Clock pulses of delay */
+ SD_WriteByte(SD_DUMMY_BYTE);
+
+ /*!< Byte 0 */
+ SD_csd->CSDStruct = (CSD_Tab[0] & 0xC0) >> 6;
+ SD_csd->SysSpecVersion = (CSD_Tab[0] & 0x3C) >> 2;
+ SD_csd->Reserved1 = CSD_Tab[0] & 0x03;
+
+ /*!< Byte 1 */
+ SD_csd->TAAC = CSD_Tab[1];
+
+ /*!< Byte 2 */
+ SD_csd->NSAC = CSD_Tab[2];
+
+ /*!< Byte 3 */
+ SD_csd->MaxBusClkFrec = CSD_Tab[3];
+
+ /*!< Byte 4 */
+ SD_csd->CardComdClasses = CSD_Tab[4] << 4;
+
+ /*!< Byte 5 */
+ SD_csd->CardComdClasses |= (CSD_Tab[5] & 0xF0) >> 4;
+ SD_csd->RdBlockLen = CSD_Tab[5] & 0x0F;
+
+ /*!< Byte 6 */
+ SD_csd->PartBlockRead = (CSD_Tab[6] & 0x80) >> 7;
+ SD_csd->WrBlockMisalign = (CSD_Tab[6] & 0x40) >> 6;
+ SD_csd->RdBlockMisalign = (CSD_Tab[6] & 0x20) >> 5;
+ SD_csd->DSRImpl = (CSD_Tab[6] & 0x10) >> 4;
+ SD_csd->Reserved2 = 0; /*!< Reserved */
+
+ SD_csd->DeviceSize = (CSD_Tab[6] & 0x03) << 10;
+
+ /*!< Byte 7 */
+ SD_csd->DeviceSize |= (CSD_Tab[7]) << 2;
+
+ /*!< Byte 8 */
+ SD_csd->DeviceSize |= (CSD_Tab[8] & 0xC0) >> 6;
+
+ SD_csd->MaxRdCurrentVDDMin = (CSD_Tab[8] & 0x38) >> 3;
+ SD_csd->MaxRdCurrentVDDMax = (CSD_Tab[8] & 0x07);
+
+ /*!< Byte 9 */
+ SD_csd->MaxWrCurrentVDDMin = (CSD_Tab[9] & 0xE0) >> 5;
+ SD_csd->MaxWrCurrentVDDMax = (CSD_Tab[9] & 0x1C) >> 2;
+ SD_csd->DeviceSizeMul = (CSD_Tab[9] & 0x03) << 1;
+ /*!< Byte 10 */
+ SD_csd->DeviceSizeMul |= (CSD_Tab[10] & 0x80) >> 7;
+
+ SD_csd->EraseGrSize = (CSD_Tab[10] & 0x40) >> 6;
+ SD_csd->EraseGrMul = (CSD_Tab[10] & 0x3F) << 1;
+
+ /*!< Byte 11 */
+ SD_csd->EraseGrMul |= (CSD_Tab[11] & 0x80) >> 7;
+ SD_csd->WrProtectGrSize = (CSD_Tab[11] & 0x7F);
+
+ /*!< Byte 12 */
+ SD_csd->WrProtectGrEnable = (CSD_Tab[12] & 0x80) >> 7;
+ SD_csd->ManDeflECC = (CSD_Tab[12] & 0x60) >> 5;
+ SD_csd->WrSpeedFact = (CSD_Tab[12] & 0x1C) >> 2;
+ SD_csd->MaxWrBlockLen = (CSD_Tab[12] & 0x03) << 2;
+
+ /*!< Byte 13 */
+ SD_csd->MaxWrBlockLen |= (CSD_Tab[13] & 0xC0) >> 6;
+ SD_csd->WriteBlockPaPartial = (CSD_Tab[13] & 0x20) >> 5;
+ SD_csd->Reserved3 = 0;
+ SD_csd->ContentProtectAppli = (CSD_Tab[13] & 0x01);
+
+ /*!< Byte 14 */
+ SD_csd->FileFormatGrouop = (CSD_Tab[14] & 0x80) >> 7;
+ SD_csd->CopyFlag = (CSD_Tab[14] & 0x40) >> 6;
+ SD_csd->PermWrProtect = (CSD_Tab[14] & 0x20) >> 5;
+ SD_csd->TempWrProtect = (CSD_Tab[14] & 0x10) >> 4;
+ SD_csd->FileFormat = (CSD_Tab[14] & 0x0C) >> 2;
+ SD_csd->ECC = (CSD_Tab[14] & 0x03);
+
+ /*!< Byte 15 */
+ SD_csd->CSD_CRC = (CSD_Tab[15] & 0xFE) >> 1;
+ SD_csd->Reserved4 = 1;
+
+ /*!< Return the reponse */
+ return rvalue;
+}
+
+/**
+ * @brief Read the CID card register.
+ * Reading the contents of the CID register in SPI mode is a simple
+ * read-block transaction.
+ * @param SD_cid: pointer on an CID register structure
+ * @retval The SD Response:
+ * - SD_RESPONSE_FAILURE: Sequence failed
+ * - SD_RESPONSE_NO_ERROR: Sequence succeed
+ */
+SD_Error SD_GetCIDRegister(SD_CID* SD_cid)
+{
+ uint32_t i = 0;
+ SD_Error rvalue = SD_RESPONSE_FAILURE;
+ uint8_t CID_Tab[16];
+
+ /*!< SD chip select low */
+ SD_CS_LOW();
+
+ /*!< Send CMD10 (CID register) */
+ SD_SendCmd(SD_CMD_SEND_CID, 0, 0xFF);
+
+ /*!< Wait for response in the R1 format (0x00 is no errors) */
+ if (!SD_GetResponse(SD_RESPONSE_NO_ERROR))
+ {
+ if (!SD_GetResponse(SD_START_DATA_SINGLE_BLOCK_READ))
+ {
+ /*!< Store CID register value on CID_Tab */
+ for (i = 0; i < 16; i++)
+ {
+ CID_Tab[i] = SD_ReadByte();
+ }
+ }
+ /*!< Get CRC bytes (not really needed by us, but required by SD) */
+ SD_WriteByte(SD_DUMMY_BYTE);
+ SD_WriteByte(SD_DUMMY_BYTE);
+ /*!< Set response value to success */
+ rvalue = SD_RESPONSE_NO_ERROR;
+ }
+ /*!< SD chip select high */
+ SD_CS_HIGH();
+ /*!< Send dummy byte: 8 Clock pulses of delay */
+ SD_WriteByte(SD_DUMMY_BYTE);
+
+ /*!< Byte 0 */
+ SD_cid->ManufacturerID = CID_Tab[0];
+
+ /*!< Byte 1 */
+ SD_cid->OEM_AppliID = CID_Tab[1] << 8;
+
+ /*!< Byte 2 */
+ SD_cid->OEM_AppliID |= CID_Tab[2];
+
+ /*!< Byte 3 */
+ SD_cid->ProdName1 = CID_Tab[3] << 24;
+
+ /*!< Byte 4 */
+ SD_cid->ProdName1 |= CID_Tab[4] << 16;
+
+ /*!< Byte 5 */
+ SD_cid->ProdName1 |= CID_Tab[5] << 8;
+
+ /*!< Byte 6 */
+ SD_cid->ProdName1 |= CID_Tab[6];
+
+ /*!< Byte 7 */
+ SD_cid->ProdName2 = CID_Tab[7];
+
+ /*!< Byte 8 */
+ SD_cid->ProdRev = CID_Tab[8];
+
+ /*!< Byte 9 */
+ SD_cid->ProdSN = CID_Tab[9] << 24;
+
+ /*!< Byte 10 */
+ SD_cid->ProdSN |= CID_Tab[10] << 16;
+
+ /*!< Byte 11 */
+ SD_cid->ProdSN |= CID_Tab[11] << 8;
+
+ /*!< Byte 12 */
+ SD_cid->ProdSN |= CID_Tab[12];
+
+ /*!< Byte 13 */
+ SD_cid->Reserved1 |= (CID_Tab[13] & 0xF0) >> 4;
+ SD_cid->ManufactDate = (CID_Tab[13] & 0x0F) << 8;
+
+ /*!< Byte 14 */
+ SD_cid->ManufactDate |= CID_Tab[14];
+
+ /*!< Byte 15 */
+ SD_cid->CID_CRC = (CID_Tab[15] & 0xFE) >> 1;
+ SD_cid->Reserved2 = 1;
+
+ /*!< Return the reponse */
+ return rvalue;
+}
+
+/**
+ * @brief Send 5 bytes command to the SD card.
+ * @param Cmd: The user expected command to send to SD card.
+ * @param Arg: The command argument.
+ * @param Crc: The CRC.
+ * @retval None
+ */
+void SD_SendCmd(uint8_t Cmd, uint32_t Arg, uint8_t Crc)
+{
+ uint32_t i = 0x00;
+
+ uint8_t Frame[6];
+
+ Frame[0] = (Cmd | 0x40); /*!< Construct byte 1 */
+
+ Frame[1] = (uint8_t)(Arg >> 24); /*!< Construct byte 2 */
+
+ Frame[2] = (uint8_t)(Arg >> 16); /*!< Construct byte 3 */
+
+ Frame[3] = (uint8_t)(Arg >> 8); /*!< Construct byte 4 */
+
+ Frame[4] = (uint8_t)(Arg); /*!< Construct byte 5 */
+
+ Frame[5] = (Crc); /*!< Construct CRC: byte 6 */
+
+ for (i = 0; i < 6; i++)
+ {
+ SD_WriteByte(Frame[i]); /*!< Send the Cmd bytes */
+ }
+}
+
+/**
+ * @brief Get SD card data response.
+ * @param None
+ * @retval The SD status: Read data response xxx0<status>1
+ * - status 010: Data accecpted
+ * - status 101: Data rejected due to a crc error
+ * - status 110: Data rejected due to a Write error.
+ * - status 111: Data rejected due to other error.
+ */
+uint8_t SD_GetDataResponse(void)
+{
+ uint32_t i = 0;
+ uint8_t response, rvalue;
+
+ while (i <= 64)
+ {
+ /*!< Read resonse */
+ response = SD_ReadByte();
+ /*!< Mask unused bits */
+ response &= 0x1F;
+ switch (response)
+ {
+ case SD_DATA_OK:
+ {
+ rvalue = SD_DATA_OK;
+ break;
+ }
+ case SD_DATA_CRC_ERROR:
+ return SD_DATA_CRC_ERROR;
+ case SD_DATA_WRITE_ERROR:
+ return SD_DATA_WRITE_ERROR;
+ default:
+ {
+ rvalue = SD_DATA_OTHER_ERROR;
+ break;
+ }
+ }
+ /*!< Exit loop in case of data ok */
+ if (rvalue == SD_DATA_OK)
+ break;
+ /*!< Increment loop counter */
+ i++;
+ }
+
+ /*!< Wait null data */
+ while (SD_ReadByte() == 0);
+
+ /*!< Return response */
+ return response;
+}
+
+/**
+ * @brief Returns the SD response.
+ * @param None
+ * @retval The SD Response:
+ * - SD_RESPONSE_FAILURE: Sequence failed
+ * - SD_RESPONSE_NO_ERROR: Sequence succeed
+ */
+SD_Error SD_GetResponse(uint8_t Response)
+{
+ uint32_t Count = 0xFFF;
+
+ /* Check if response is got or a timeout is happen */
+ while ((SD_ReadByte() != Response) && Count)
+ {
+ Count--;
+ }
+
+ if (Count == 0)
+ {
+ /* After time out */
+ return SD_RESPONSE_FAILURE;
+ }
+ else
+ {
+ /* Right response got */
+ return SD_RESPONSE_NO_ERROR;
+ }
+}
+
+/**
+ * @brief Returns the SD status.
+ * @param None
+ * @retval The SD status.
+ */
+uint16_t SD_GetStatus(void)
+{
+ uint16_t Status = 0;
+
+ /*!< SD chip select low */
+ SD_CS_LOW();
+
+ /*!< Send CMD13 (SD_SEND_STATUS) to get SD status */
+ SD_SendCmd(SD_CMD_SEND_STATUS, 0, 0xFF);
+
+ Status = SD_ReadByte();
+ Status |= (uint16_t)(SD_ReadByte() << 8);
+
+ /*!< SD chip select high */
+ SD_CS_HIGH();
+
+ /*!< Send dummy byte 0xFF */
+ SD_WriteByte(SD_DUMMY_BYTE);
+
+ return Status;
+}
+
+/**
+ * @brief Put SD in Idle state.
+ * @param None
+ * @retval The SD Response:
+ * - SD_RESPONSE_FAILURE: Sequence failed
+ * - SD_RESPONSE_NO_ERROR: Sequence succeed
+ */
+SD_Error SD_GoIdleState(void)
+{
+ /*!< SD chip select low */
+ SD_CS_LOW();
+
+ /*!< Send CMD0 (SD_CMD_GO_IDLE_STATE) to put SD in SPI mode */
+ SD_SendCmd(SD_CMD_GO_IDLE_STATE, 0, 0x95);
+
+ /*!< Wait for In Idle State Response (R1 Format) equal to 0x01 */
+ if (SD_GetResponse(SD_IN_IDLE_STATE))
+ {
+ /*!< No Idle State Response: return response failue */
+ return SD_RESPONSE_FAILURE;
+ }
+ /*----------Activates the card initialization process-----------*/
+ do
+ {
+ /*!< SD chip select high */
+ SD_CS_HIGH();
+
+ /*!< Send Dummy byte 0xFF */
+ SD_WriteByte(SD_DUMMY_BYTE);
+
+ /*!< SD chip select low */
+ SD_CS_LOW();
+
+ /*!< Send CMD1 (Activates the card process) until response equal to 0x0 */
+ SD_SendCmd(SD_CMD_SEND_OP_COND, 0, 0xFF);
+ /*!< Wait for no error Response (R1 Format) equal to 0x00 */
+ }
+ while (SD_GetResponse(SD_RESPONSE_NO_ERROR));
+
+ /*!< SD chip select high */
+ SD_CS_HIGH();
+
+ /*!< Send dummy byte 0xFF */
+ SD_WriteByte(SD_DUMMY_BYTE);
+
+ return SD_RESPONSE_NO_ERROR;
+}
+
+/**
+ * @brief Write a byte on the SD.
+ * @param Data: byte to send.
+ * @retval None
+ */
+uint8_t SD_WriteByte(uint8_t Data)
+{
+ /*!< Wait until the transmit buffer is empty */
+ while(SPI_I2S_GetFlagStatus(SD_SPI, SPI_I2S_FLAG_TXE) == RESET)
+ {
+ }
+
+ /*!< Send the byte */
+ SPI_SendData8(SD_SPI, Data);
+
+ /*!< Wait to receive a byte*/
+ while(SPI_I2S_GetFlagStatus(SD_SPI, SPI_I2S_FLAG_RXNE) == RESET)
+ {
+ }
+
+ /*!< Return the byte read from the SPI bus */
+ return SPI_ReceiveData8(SD_SPI);
+}
+
+/**
+ * @brief Read a byte from the SD.
+ * @param None
+ * @retval The received byte.
+ */
+uint8_t SD_ReadByte(void)
+{
+ uint8_t Data = 0;
+
+ /*!< Wait until the transmit buffer is empty */
+ while (SPI_I2S_GetFlagStatus(SD_SPI, SPI_I2S_FLAG_TXE) == RESET)
+ {
+ }
+ /*!< Send the byte */
+ SPI_SendData8(SD_SPI, SD_DUMMY_BYTE);
+
+ /*!< Wait until a data is received */
+ while (SPI_I2S_GetFlagStatus(SD_SPI, SPI_I2S_FLAG_RXNE) == RESET)
+ {
+ }
+ /*!< Get the received data */
+ Data = SPI_ReceiveData8(SD_SPI);
+
+ /*!< Return the shifted data */
+ return Data;
+}
+
+/**
+ * @}
+ */
+
+
+/**
+ * @}
+ */
+
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32373C_EVAL/stm32373c_eval_spi_sd.h b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32373C_EVAL/stm32373c_eval_spi_sd.h
new file mode 100644
index 0000000..7282545
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32373C_EVAL/stm32373c_eval_spi_sd.h
@@ -0,0 +1,286 @@
+/**
+ ******************************************************************************
+ * @file stm32373c_eval_spi_sd.h
+ * @author MCD Application Team
+ * @version V1.0.0
+ * @date 20-September-2012
+ * @brief This file contains all the functions prototypes for the stm32373c_eval_spi_sd
+ * firmware driver.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.st.com/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __STM32373C_EVAL_SPI_SD_H
+#define __STM32373C_EVAL_SPI_SD_H
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+/* Includes ------------------------------------------------------------------*/
+#include "stm32373c_eval.h"
+
+/** @addtogroup Utilities
+ * @{
+ */
+
+/** @addtogroup STM32_EVAL
+ * @{
+ */
+
+/** @addtogroup STM32373C_EVAL
+ * @{
+ */
+
+/** @addtogroup STM32373C_EVAL_SPI_SD
+ * @{
+ */
+
+/** @defgroup STM32373C_EVAL_SPI_SD_Exported_Types
+ * @{
+ */
+
+typedef enum
+{
+/**
+ * @brief SD reponses and error flags
+ */
+ SD_RESPONSE_NO_ERROR = (0x00),
+ SD_IN_IDLE_STATE = (0x01),
+ SD_ERASE_RESET = (0x02),
+ SD_ILLEGAL_COMMAND = (0x04),
+ SD_COM_CRC_ERROR = (0x08),
+ SD_ERASE_SEQUENCE_ERROR = (0x10),
+ SD_ADDRESS_ERROR = (0x20),
+ SD_PARAMETER_ERROR = (0x40),
+ SD_RESPONSE_FAILURE = (0xFF),
+
+/**
+ * @brief Data response error
+ */
+ SD_DATA_OK = (0x05),
+ SD_DATA_CRC_ERROR = (0x0B),
+ SD_DATA_WRITE_ERROR = (0x0D),
+ SD_DATA_OTHER_ERROR = (0xFF)
+} SD_Error;
+
+/**
+ * @brief Card Specific Data: CSD Register
+ */
+typedef struct
+{
+ __IO uint8_t CSDStruct; /*!< CSD structure */
+ __IO uint8_t SysSpecVersion; /*!< System specification version */
+ __IO uint8_t Reserved1; /*!< Reserved */
+ __IO uint8_t TAAC; /*!< Data read access-time 1 */
+ __IO uint8_t NSAC; /*!< Data read access-time 2 in CLK cycles */
+ __IO uint8_t MaxBusClkFrec; /*!< Max. bus clock frequency */
+ __IO uint16_t CardComdClasses; /*!< Card command classes */
+ __IO uint8_t RdBlockLen; /*!< Max. read data block length */
+ __IO uint8_t PartBlockRead; /*!< Partial blocks for read allowed */
+ __IO uint8_t WrBlockMisalign; /*!< Write block misalignment */
+ __IO uint8_t RdBlockMisalign; /*!< Read block misalignment */
+ __IO uint8_t DSRImpl; /*!< DSR implemented */
+ __IO uint8_t Reserved2; /*!< Reserved */
+ __IO uint32_t DeviceSize; /*!< Device Size */
+ __IO uint8_t MaxRdCurrentVDDMin; /*!< Max. read current @ VDD min */
+ __IO uint8_t MaxRdCurrentVDDMax; /*!< Max. read current @ VDD max */
+ __IO uint8_t MaxWrCurrentVDDMin; /*!< Max. write current @ VDD min */
+ __IO uint8_t MaxWrCurrentVDDMax; /*!< Max. write current @ VDD max */
+ __IO uint8_t DeviceSizeMul; /*!< Device size multiplier */
+ __IO uint8_t EraseGrSize; /*!< Erase group size */
+ __IO uint8_t EraseGrMul; /*!< Erase group size multiplier */
+ __IO uint8_t WrProtectGrSize; /*!< Write protect group size */
+ __IO uint8_t WrProtectGrEnable; /*!< Write protect group enable */
+ __IO uint8_t ManDeflECC; /*!< Manufacturer default ECC */
+ __IO uint8_t WrSpeedFact; /*!< Write speed factor */
+ __IO uint8_t MaxWrBlockLen; /*!< Max. write data block length */
+ __IO uint8_t WriteBlockPaPartial; /*!< Partial blocks for write allowed */
+ __IO uint8_t Reserved3; /*!< Reserded */
+ __IO uint8_t ContentProtectAppli; /*!< Content protection application */
+ __IO uint8_t FileFormatGrouop; /*!< File format group */
+ __IO uint8_t CopyFlag; /*!< Copy flag (OTP) */
+ __IO uint8_t PermWrProtect; /*!< Permanent write protection */
+ __IO uint8_t TempWrProtect; /*!< Temporary write protection */
+ __IO uint8_t FileFormat; /*!< File Format */
+ __IO uint8_t ECC; /*!< ECC code */
+ __IO uint8_t CSD_CRC; /*!< CSD CRC */
+ __IO uint8_t Reserved4; /*!< always 1*/
+} SD_CSD;
+
+/**
+ * @brief Card Identification Data: CID Register
+ */
+typedef struct
+{
+ __IO uint8_t ManufacturerID; /*!< ManufacturerID */
+ __IO uint16_t OEM_AppliID; /*!< OEM/Application ID */
+ __IO uint32_t ProdName1; /*!< Product Name part1 */
+ __IO uint8_t ProdName2; /*!< Product Name part2*/
+ __IO uint8_t ProdRev; /*!< Product Revision */
+ __IO uint32_t ProdSN; /*!< Product Serial Number */
+ __IO uint8_t Reserved1; /*!< Reserved1 */
+ __IO uint16_t ManufactDate; /*!< Manufacturing Date */
+ __IO uint8_t CID_CRC; /*!< CID CRC */
+ __IO uint8_t Reserved2; /*!< always 1 */
+} SD_CID;
+
+/**
+ * @brief SD Card information
+ */
+typedef struct
+{
+ SD_CSD SD_csd;
+ SD_CID SD_cid;
+ uint32_t CardCapacity; /*!< Card Capacity */
+ uint32_t CardBlockSize; /*!< Card Block Size */
+} SD_CardInfo;
+
+/**
+ * @}
+ */
+
+/** @defgroup STM32373C_EVAL_SPI_SD_Exported_Constants
+ * @{
+ */
+
+/**
+ * @brief Block Size
+ */
+#define SD_BLOCK_SIZE 0x200
+
+/**
+ * @brief Dummy byte
+ */
+#define SD_DUMMY_BYTE 0xFF
+
+/**
+ * @brief Start Data tokens:
+ * Tokens (necessary because at nop/idle (and CS active) only 0xff is
+ * on the data/command line)
+ */
+#define SD_START_DATA_SINGLE_BLOCK_READ 0xFE /*!< Data token start byte, Start Single Block Read */
+#define SD_START_DATA_MULTIPLE_BLOCK_READ 0xFE /*!< Data token start byte, Start Multiple Block Read */
+#define SD_START_DATA_SINGLE_BLOCK_WRITE 0xFE /*!< Data token start byte, Start Single Block Write */
+#define SD_START_DATA_MULTIPLE_BLOCK_WRITE 0xFD /*!< Data token start byte, Start Multiple Block Write */
+#define SD_STOP_DATA_MULTIPLE_BLOCK_WRITE 0xFD /*!< Data toke stop byte, Stop Multiple Block Write */
+
+/**
+ * @brief SD detection on its memory slot
+ */
+#define SD_PRESENT ((uint8_t)0x01)
+#define SD_NOT_PRESENT ((uint8_t)0x00)
+
+
+/**
+ * @brief Commands: CMDxx = CMD-number | 0x40
+ */
+#define SD_CMD_GO_IDLE_STATE 0 /*!< CMD0 = 0x40 */
+#define SD_CMD_SEND_OP_COND 1 /*!< CMD1 = 0x41 */
+#define SD_CMD_SEND_CSD 9 /*!< CMD9 = 0x49 */
+#define SD_CMD_SEND_CID 10 /*!< CMD10 = 0x4A */
+#define SD_CMD_STOP_TRANSMISSION 12 /*!< CMD12 = 0x4C */
+#define SD_CMD_SEND_STATUS 13 /*!< CMD13 = 0x4D */
+#define SD_CMD_SET_BLOCKLEN 16 /*!< CMD16 = 0x50 */
+#define SD_CMD_READ_SINGLE_BLOCK 17 /*!< CMD17 = 0x51 */
+#define SD_CMD_READ_MULT_BLOCK 18 /*!< CMD18 = 0x52 */
+#define SD_CMD_SET_BLOCK_COUNT 23 /*!< CMD23 = 0x57 */
+#define SD_CMD_WRITE_SINGLE_BLOCK 24 /*!< CMD24 = 0x58 */
+#define SD_CMD_WRITE_MULT_BLOCK 25 /*!< CMD25 = 0x59 */
+#define SD_CMD_PROG_CSD 27 /*!< CMD27 = 0x5B */
+#define SD_CMD_SET_WRITE_PROT 28 /*!< CMD28 = 0x5C */
+#define SD_CMD_CLR_WRITE_PROT 29 /*!< CMD29 = 0x5D */
+#define SD_CMD_SEND_WRITE_PROT 30 /*!< CMD30 = 0x5E */
+#define SD_CMD_SD_ERASE_GRP_START 32 /*!< CMD32 = 0x60 */
+#define SD_CMD_SD_ERASE_GRP_END 33 /*!< CMD33 = 0x61 */
+#define SD_CMD_UNTAG_SECTOR 34 /*!< CMD34 = 0x62 */
+#define SD_CMD_ERASE_GRP_START 35 /*!< CMD35 = 0x63 */
+#define SD_CMD_ERASE_GRP_END 36 /*!< CMD36 = 0x64 */
+#define SD_CMD_UNTAG_ERASE_GROUP 37 /*!< CMD37 = 0x65 */
+#define SD_CMD_ERASE 38 /*!< CMD38 = 0x66 */
+
+/**
+ * @}
+ */
+
+/** @defgroup STM32373C_EVAL_SPI_SD_Exported_Macros
+ * @{
+ */
+/**
+ * @brief Select SD Card: ChipSelect pin low
+ */
+#define SD_CS_LOW() GPIO_ResetBits(SD_CS_GPIO_PORT, SD_CS_PIN)
+/**
+ * @brief Deselect SD Card: ChipSelect pin high
+ */
+#define SD_CS_HIGH() GPIO_SetBits(SD_CS_GPIO_PORT, SD_CS_PIN)
+/**
+ * @}
+ */
+
+/** @defgroup STM32373C_EVAL_SPI_SD_Exported_Functions
+ * @{
+ */
+void SD_DeInit(void);
+SD_Error SD_Init(void);
+uint8_t SD_Detect(void);
+SD_Error SD_GetCardInfo(SD_CardInfo *cardinfo);
+SD_Error SD_ReadBlock(uint8_t* pBuffer, uint32_t ReadAddr, uint16_t BlockSize);
+SD_Error SD_ReadMultiBlocks(uint8_t* pBuffer, uint32_t ReadAddr, uint16_t BlockSize, uint32_t NumberOfBlocks);
+SD_Error SD_WriteBlock(uint8_t* pBuffer, uint32_t WriteAddr, uint16_t BlockSize);
+SD_Error SD_WriteMultiBlocks(uint8_t* pBuffer, uint32_t WriteAddr, uint16_t BlockSize, uint32_t NumberOfBlocks);
+SD_Error SD_GetCSDRegister(SD_CSD* SD_csd);
+SD_Error SD_GetCIDRegister(SD_CID* SD_cid);
+
+void SD_SendCmd(uint8_t Cmd, uint32_t Arg, uint8_t Crc);
+SD_Error SD_GetResponse(uint8_t Response);
+uint8_t SD_GetDataResponse(void);
+SD_Error SD_GoIdleState(void);
+uint16_t SD_GetStatus(void);
+
+uint8_t SD_WriteByte(uint8_t byte);
+uint8_t SD_ReadByte(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __STM32373C_EVAL_SPI_SD_H */
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval.c b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval.c
new file mode 100644
index 0000000..540c87e
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval.c
@@ -0,0 +1,882 @@
+/**
+ ******************************************************************************
+ * @file stm32l152d_eval.c
+ * @author MCD Application Team
+ * @version V1.0.1
+ * @date 09-March-2012
+ * @brief This file provides
+ * - set of firmware functions to manage Leds, push-button and COM ports
+ * - low level initialization functions for SD card (on SDIO), SPI serial
+ * flash (sFLASH) and temperature sensor (LM75)
+ * available on STM32L152D-EVAL evaluation board from STMicroelectronics.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.st.com/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+
+/* Includes ------------------------------------------------------------------*/
+#include "stm32l152d_eval.h"
+#include "stm32l1xx_spi.h"
+#include "stm32l1xx_i2c.h"
+#include "stm32l1xx_sdio.h"
+#include "stm32l1xx_dma.h"
+
+/** @addtogroup Utilities
+ * @{
+ */
+
+/** @addtogroup STM32_EVAL
+ * @{
+ */
+
+/** @addtogroup STM32L152D_EVAL
+ * @{
+ */
+
+/** @defgroup STM32L152D_EVAL_LOW_LEVEL
+ * @brief This file provides firmware functions to manage Leds, push-buttons,
+ * COM ports, SD card on SDIO, serial flash (sFLASH), serial EEPROM (sEE)
+ * and temperature sensor (LM75) available on STM32L152D-EVAL evaluation
+ * board from STMicroelectronics.
+ * @{
+ */
+
+/** @defgroup STM32L152D_EVAL_LOW_LEVEL_Private_TypesDefinitions
+ * @{
+ */
+/**
+ * @}
+ */
+
+
+/** @defgroup STM32L152D_EVAL_LOW_LEVEL_Private_Defines
+ * @{
+ */
+/**
+ * @}
+ */
+
+
+/** @defgroup STM32L152D_EVAL_LOW_LEVEL_Private_Macros
+ * @{
+ */
+/**
+ * @}
+ */
+
+
+/** @defgroup STM32L152D_EVAL_LOW_LEVEL_Private_Variables
+ * @{
+ */
+GPIO_TypeDef* GPIO_PORT[LEDn] = {LED1_GPIO_PORT, LED2_GPIO_PORT, LED3_GPIO_PORT,
+ LED4_GPIO_PORT};
+const uint16_t GPIO_PIN[LEDn] = {LED1_PIN, LED2_PIN, LED3_PIN,
+ LED4_PIN};
+const uint32_t GPIO_CLK[LEDn] = {LED1_GPIO_CLK, LED2_GPIO_CLK, LED3_GPIO_CLK,
+ LED4_GPIO_CLK};
+
+GPIO_TypeDef* BUTTON_PORT[BUTTONn] = {KEY_BUTTON_GPIO_PORT, RIGHT_BUTTON_GPIO_PORT,
+ LEFT_BUTTON_GPIO_PORT, UP_BUTTON_GPIO_PORT,
+ DOWN_BUTTON_GPIO_PORT, SEL_BUTTON_GPIO_PORT};
+
+const uint16_t BUTTON_PIN[BUTTONn] = {KEY_BUTTON_PIN, RIGHT_BUTTON_PIN,
+ LEFT_BUTTON_PIN, UP_BUTTON_PIN,
+ DOWN_BUTTON_PIN, SEL_BUTTON_PIN};
+
+const uint32_t BUTTON_CLK[BUTTONn] = {KEY_BUTTON_GPIO_CLK, RIGHT_BUTTON_GPIO_CLK,
+ LEFT_BUTTON_GPIO_CLK, UP_BUTTON_GPIO_CLK,
+ DOWN_BUTTON_GPIO_CLK, SEL_BUTTON_GPIO_CLK};
+
+const uint16_t BUTTON_EXTI_LINE[BUTTONn] = {KEY_BUTTON_EXTI_LINE,
+ RIGHT_BUTTON_EXTI_LINE,
+ LEFT_BUTTON_EXTI_LINE,
+ UP_BUTTON_EXTI_LINE,
+ DOWN_BUTTON_EXTI_LINE,
+ SEL_BUTTON_EXTI_LINE};
+
+const uint8_t BUTTON_PORT_SOURCE[BUTTONn] = {KEY_BUTTON_EXTI_PORT_SOURCE,
+ RIGHT_BUTTON_EXTI_PORT_SOURCE,
+ LEFT_BUTTON_EXTI_PORT_SOURCE,
+ UP_BUTTON_EXTI_PORT_SOURCE,
+ DOWN_BUTTON_EXTI_PORT_SOURCE,
+ SEL_BUTTON_EXTI_PORT_SOURCE};
+
+const uint8_t BUTTON_PIN_SOURCE[BUTTONn] = {KEY_BUTTON_EXTI_PIN_SOURCE,
+ RIGHT_BUTTON_EXTI_PIN_SOURCE,
+ LEFT_BUTTON_EXTI_PIN_SOURCE,
+ UP_BUTTON_EXTI_PIN_SOURCE,
+ DOWN_BUTTON_EXTI_PIN_SOURCE,
+ SEL_BUTTON_EXTI_PIN_SOURCE};
+
+const uint8_t BUTTON_IRQn[BUTTONn] = {KEY_BUTTON_EXTI_IRQn, RIGHT_BUTTON_EXTI_IRQn,
+ LEFT_BUTTON_EXTI_IRQn, UP_BUTTON_EXTI_IRQn,
+ DOWN_BUTTON_EXTI_IRQn, SEL_BUTTON_EXTI_IRQn};
+
+USART_TypeDef* COM_USART[COMn] = {EVAL_COM1};
+
+GPIO_TypeDef* COM_TX_PORT[COMn] = {EVAL_COM1_TX_GPIO_PORT};
+
+GPIO_TypeDef* COM_RX_PORT[COMn] = {EVAL_COM1_RX_GPIO_PORT};
+
+const uint32_t COM_USART_CLK[COMn] = {EVAL_COM1_CLK};
+
+const uint32_t COM_TX_PORT_CLK[COMn] = {EVAL_COM1_TX_GPIO_CLK};
+
+const uint32_t COM_RX_PORT_CLK[COMn] = {EVAL_COM1_RX_GPIO_CLK};
+
+const uint16_t COM_TX_PIN[COMn] = {EVAL_COM1_TX_PIN};
+
+const uint16_t COM_RX_PIN[COMn] = {EVAL_COM1_RX_PIN};
+
+const uint8_t COM_TX_PIN_SOURCE[COMn] = {EVAL_COM1_TX_SOURCE};
+
+const uint8_t COM_RX_PIN_SOURCE[COMn] = {EVAL_COM1_RX_SOURCE};
+
+const uint8_t COM_TX_AF[COMn] = {EVAL_COM1_TX_AF};
+
+const uint8_t COM_RX_AF[COMn] = {EVAL_COM1_RX_AF};
+
+DMA_InitTypeDef sEEDMA_InitStructure;
+
+/**
+ * @}
+ */
+
+
+/** @defgroup STM32L152D_EVAL_LOW_LEVEL_Private_FunctionPrototypes
+ * @{
+ */
+
+/**
+ * @}
+ */
+
+
+/** @defgroup STM32L152D_EVAL_LOW_LEVEL_Private_Functions
+ * @{
+ */
+
+/**
+ * @brief Configures LED GPIO.
+ * @param Led: Specifies the Led to be configured.
+ * This parameter can be one of following parameters:
+ * @arg LED1
+ * @arg LED2
+ * @arg LED3
+ * @arg LED4
+ * @retval None
+ */
+void STM_EVAL_LEDInit(Led_TypeDef Led)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+
+ /* Enable the GPIO_LED Clock */
+ RCC_AHBPeriphClockCmd(GPIO_CLK[Led], ENABLE);
+
+ /* Configure the GPIO_LED pin */
+ GPIO_InitStructure.GPIO_Pin = GPIO_PIN[Led];
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
+ GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
+ GPIO_Init(GPIO_PORT[Led], &GPIO_InitStructure);
+ GPIO_PORT[Led]->BSRRL = GPIO_PIN[Led];
+}
+
+/**
+ * @brief Turns selected LED On.
+ * @param Led: Specifies the Led to be set on.
+ * This parameter can be one of following parameters:
+ * @arg LED1
+ * @arg LED2
+ * @arg LED3
+ * @arg LED4
+ * @retval None
+ */
+void STM_EVAL_LEDOn(Led_TypeDef Led)
+{
+ GPIO_PORT[Led]->BSRRH = GPIO_PIN[Led];
+}
+
+/**
+ * @brief Turns selected LED Off.
+ * @param Led: Specifies the Led to be set off.
+ * This parameter can be one of following parameters:
+ * @arg LED1
+ * @arg LED2
+ * @arg LED3
+ * @arg LED4
+ * @retval None
+ */
+void STM_EVAL_LEDOff(Led_TypeDef Led)
+{
+ GPIO_PORT[Led]->BSRRL = GPIO_PIN[Led];
+}
+
+/**
+ * @brief Toggles the selected LED.
+ * @param Led: Specifies the Led to be toggled.
+ * This parameter can be one of following parameters:
+ * @arg LED1
+ * @arg LED2
+ * @arg LED3
+ * @arg LED4
+ * @retval None
+ */
+void STM_EVAL_LEDToggle(Led_TypeDef Led)
+{
+ GPIO_PORT[Led]->ODR ^= GPIO_PIN[Led];
+}
+
+/**
+ * @brief Configures Button GPIO and EXTI Line.
+ * @param Button: Specifies the Button to be configured.
+ * This parameter can be one of following parameters:
+ * @arg BUTTON_KEY: Key Push Button
+ * @arg BUTTON_RIGHT: Joystick Right Push Button
+ * @arg BUTTON_LEFT: Joystick Left Push Button
+ * @arg BUTTON_UP: Joystick Up Push Button
+ * @arg BUTTON_DOWN: Joystick Down Push Button
+ * @arg BUTTON_SEL: Joystick Sel Push Button
+ * @param Button_Mode: Specifies Button mode.
+ * This parameter can be one of following parameters:
+ * @arg BUTTON_MODE_GPIO: Button will be used as simple IO
+ * @arg BUTTON_MODE_EXTI: Button will be connected to EXTI line with interrupt
+ * generation capability
+ * @retval None
+ */
+void STM_EVAL_PBInit(Button_TypeDef Button, ButtonMode_TypeDef Button_Mode)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+ EXTI_InitTypeDef EXTI_InitStructure;
+ NVIC_InitTypeDef NVIC_InitStructure;
+
+ /* There is no Wakeup and Tamper buttons on STM32L152D-EVAL. */
+
+ /* Enable the BUTTON Clock */
+ RCC_AHBPeriphClockCmd(BUTTON_CLK[Button], ENABLE);
+ RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
+
+ /* Configure Button pin as input */
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
+ GPIO_InitStructure.GPIO_Pin = BUTTON_PIN[Button];
+ GPIO_Init(BUTTON_PORT[Button], &GPIO_InitStructure);
+
+
+ if (Button_Mode == BUTTON_MODE_EXTI)
+ {
+ /* Connect Button EXTI Line to Button GPIO Pin */
+ SYSCFG_EXTILineConfig(BUTTON_PORT_SOURCE[Button], BUTTON_PIN_SOURCE[Button]);
+
+ /* Configure Button EXTI line */
+ EXTI_InitStructure.EXTI_Line = BUTTON_EXTI_LINE[Button];
+ EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
+
+ if(Button != BUTTON_KEY)
+ {
+ EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
+ }
+ else
+ {
+ EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
+ }
+ EXTI_InitStructure.EXTI_LineCmd = ENABLE;
+ EXTI_Init(&EXTI_InitStructure);
+
+ /* Enable and set Button EXTI Interrupt to the lowest priority */
+ NVIC_InitStructure.NVIC_IRQChannel = BUTTON_IRQn[Button];
+ NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F;
+ NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;
+ NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
+
+ NVIC_Init(&NVIC_InitStructure);
+ }
+}
+
+/**
+ * @brief Returns the selected Button state.
+ * @param Button: Specifies the Button to be checked.
+ * This parameter can be one of following parameters:
+ * @arg BUTTON_KEY: Key Push Button
+ * @arg BUTTON_RIGHT: Joystick Right Push Button
+ * @arg BUTTON_LEFT: Joystick Left Push Button
+ * @arg BUTTON_UP: Joystick Up Push Button
+ * @arg BUTTON_DOWN: Joystick Down Push Button
+ * @arg BUTTON_SEL: Joystick Sel Push Button
+ * @retval The Button GPIO pin value.
+ */
+uint32_t STM_EVAL_PBGetState(Button_TypeDef Button)
+{
+ /* There is no Wakeup and Tamper pins on STM32L152D-EVAL. */
+
+ return GPIO_ReadInputDataBit(BUTTON_PORT[Button], BUTTON_PIN[Button]);
+}
+
+/**
+ * @brief Configures COM port.
+ * @param COM: Specifies the COM port to be configured.
+ * This parameter can be one of following parameters:
+ * @arg COM1
+ * @param USART_InitStruct: pointer to a USART_InitTypeDef structure that
+ * contains the configuration information for the specified USART peripheral.
+ * @retval None
+ */
+void STM_EVAL_COMInit(COM_TypeDef COM, USART_InitTypeDef* USART_InitStruct)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+
+ /* Enable GPIO clock */
+ RCC_AHBPeriphClockCmd(COM_TX_PORT_CLK[COM] | COM_RX_PORT_CLK[COM], ENABLE);
+
+ /* Enable USART1 clock */
+ RCC_APB2PeriphClockCmd(COM_USART_CLK[COM], ENABLE);
+
+ /* Connect PXx to USARTx_Tx */
+ GPIO_PinAFConfig(COM_TX_PORT[COM], COM_TX_PIN_SOURCE[COM], COM_TX_AF[COM]);
+
+ /* Connect PXx to USARTx_Rx */
+ GPIO_PinAFConfig(COM_RX_PORT[COM], COM_RX_PIN_SOURCE[COM], COM_RX_AF[COM]);
+
+ /* Configure USART Tx as alternate function push-pull */
+ GPIO_InitStructure.GPIO_Pin = COM_TX_PIN[COM];
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
+ GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
+ GPIO_Init(COM_TX_PORT[COM], &GPIO_InitStructure);
+
+ /* Configure USART Rx as alternate function push-pull */
+ GPIO_InitStructure.GPIO_Pin = COM_RX_PIN[COM];
+ GPIO_Init(COM_RX_PORT[COM], &GPIO_InitStructure);
+
+ /* USART configuration */
+ USART_Init(COM_USART[COM], USART_InitStruct);
+
+ /* Enable USART */
+ USART_Cmd(COM_USART[COM], ENABLE);
+}
+
+/**
+ * @brief DeInitializes the SDIO interface.
+ * @param None
+ * @retval None
+ */
+void SD_LowLevel_DeInit(void)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+
+ /*!< Disable SDIO Clock */
+ SDIO_ClockCmd(DISABLE);
+
+ /*!< Set Power State to OFF */
+ SDIO_SetPowerState(SDIO_PowerState_OFF);
+
+ /*!< DeInitializes the SDIO peripheral */
+ SDIO_DeInit();
+
+ /* Disable the SDIO APB2 Clock */
+ RCC_APB2PeriphClockCmd(RCC_APB2Periph_SDIO, DISABLE);
+
+ GPIO_PinAFConfig(GPIOC, GPIO_PinSource8, GPIO_AF_MCO);
+ GPIO_PinAFConfig(GPIOC, GPIO_PinSource9, GPIO_AF_MCO);
+ GPIO_PinAFConfig(GPIOC, GPIO_PinSource10, GPIO_AF_MCO);
+ GPIO_PinAFConfig(GPIOC, GPIO_PinSource11, GPIO_AF_MCO);
+ GPIO_PinAFConfig(GPIOC, GPIO_PinSource12, GPIO_AF_MCO);
+ GPIO_PinAFConfig(GPIOD, GPIO_PinSource2, GPIO_AF_MCO);
+
+ /* Configure PC.08, PC.09, PC.10, PC.11 pins: D0, D1, D2, D3 pins */
+ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
+ GPIO_Init(GPIOC, &GPIO_InitStructure);
+
+ /* Configure PD.02 CMD line */
+ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
+ GPIO_Init(GPIOD, &GPIO_InitStructure);
+
+ /* Configure PC.12 pin: CLK pin */
+ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
+ GPIO_Init(GPIOC, &GPIO_InitStructure);
+}
+
+/**
+ * @brief Initializes the SD Card and put it into StandBy State (Ready for
+ * data transfer).
+ * @param None
+ * @retval None
+ */
+void SD_LowLevel_Init(void)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+
+ /* GPIOC and GPIOD Periph clock enable */
+ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC | RCC_AHBPeriph_GPIOD | SD_DETECT_GPIO_CLK, ENABLE);
+
+ GPIO_PinAFConfig(GPIOC, GPIO_PinSource8, GPIO_AF_SDIO);
+ GPIO_PinAFConfig(GPIOC, GPIO_PinSource9, GPIO_AF_SDIO);
+ GPIO_PinAFConfig(GPIOC, GPIO_PinSource10, GPIO_AF_SDIO);
+ GPIO_PinAFConfig(GPIOC, GPIO_PinSource11, GPIO_AF_SDIO);
+ GPIO_PinAFConfig(GPIOC, GPIO_PinSource12, GPIO_AF_SDIO);
+ GPIO_PinAFConfig(GPIOD, GPIO_PinSource2, GPIO_AF_SDIO);
+
+ /* Configure PC.08, PC.09, PC.10, PC.11 pins: D0, D1, D2, D3 pins */
+ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
+ GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
+ GPIO_Init(GPIOC, &GPIO_InitStructure);
+
+ /* Configure PD.02 CMD line */
+ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
+ GPIO_Init(GPIOD, &GPIO_InitStructure);
+
+ /* Configure PC.12 pin: CLK pin */
+ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
+ GPIO_Init(GPIOC, &GPIO_InitStructure);
+
+ /*!< Configure SD_SPI_DETECT_PIN pin: SD Card detect pin */
+ GPIO_InitStructure.GPIO_Pin = SD_DETECT_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
+ GPIO_Init(SD_DETECT_GPIO_PORT, &GPIO_InitStructure);
+
+ /* Enable the SDIO APB2 Clock */
+ RCC_APB2PeriphClockCmd(RCC_APB2Periph_SDIO, ENABLE);
+
+ /* Enable the DMA2 Clock */
+ RCC_AHBPeriphClockCmd(SD_SDIO_DMA_CLK, ENABLE);
+}
+
+/**
+ * @brief Configures the DMA2 Channel4 for SDIO Tx request.
+ * @param BufferSRC: pointer to the source buffer
+ * @param BufferSize: buffer size
+ * @retval None
+ */
+void SD_LowLevel_DMA_TxConfig(uint32_t *BufferSRC, uint32_t BufferSize)
+{
+ DMA_InitTypeDef DMA_InitStructure;
+
+ DMA_ClearFlag(SD_SDIO_DMA_FLAG_TC | SD_SDIO_DMA_FLAG_TE | SD_SDIO_DMA_FLAG_HT | SD_SDIO_DMA_FLAG_GL);
+
+ /*!< SDIO DMA CHANNEL disable */
+ DMA_Cmd(SD_SDIO_DMA_CHANNEL, DISABLE);
+
+ /*!< SDIO DMA CHANNEL Config */
+ DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)SDIO_FIFO_ADDRESS;
+ DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)BufferSRC;
+ DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
+ DMA_InitStructure.DMA_BufferSize = BufferSize / 4;
+ DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
+ DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
+ DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word;
+ DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word;
+ DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
+ DMA_InitStructure.DMA_Priority = DMA_Priority_High;
+ DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
+ DMA_Init(SD_SDIO_DMA_CHANNEL, &DMA_InitStructure);
+ DMA_ITConfig(SD_SDIO_DMA_CHANNEL, DMA_IT_TC, ENABLE);
+ /*!< SDIO DMA CHANNEL enable */
+ DMA_Cmd(SD_SDIO_DMA_CHANNEL, ENABLE);
+}
+
+/**
+ * @brief Configures the DMA2 Channel4 for SDIO Rx request.
+ * @param BufferDST: pointer to the destination buffer
+ * @param BufferSize: buffer size
+ * @retval None
+ */
+void SD_LowLevel_DMA_RxConfig(uint32_t *BufferDST, uint32_t BufferSize)
+{
+ DMA_InitTypeDef DMA_InitStructure;
+
+ DMA_ClearFlag(SD_SDIO_DMA_FLAG_TC | SD_SDIO_DMA_FLAG_TE | SD_SDIO_DMA_FLAG_HT | SD_SDIO_DMA_FLAG_GL);
+
+ /*!< SDIO DMA CHANNEL disable */
+ DMA_Cmd(SD_SDIO_DMA_CHANNEL, DISABLE);
+
+ /*!< SDIO DMA CHANNEL Config */
+ DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)SDIO_FIFO_ADDRESS;
+ DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)BufferDST;
+ DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
+ DMA_InitStructure.DMA_BufferSize = BufferSize / 4;
+ DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
+ DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
+ DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word;
+ DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word;
+ DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
+ DMA_InitStructure.DMA_Priority = DMA_Priority_High;
+ DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
+ DMA_Init(SD_SDIO_DMA_CHANNEL, &DMA_InitStructure);
+ DMA_ITConfig(SD_SDIO_DMA_CHANNEL, DMA_IT_TC, ENABLE);
+ /*!< SDIO DMA CHANNEL enable */
+ DMA_Cmd(SD_SDIO_DMA_CHANNEL, ENABLE);
+}
+
+/**
+ * @brief DeInitializes the LM75_I2C.
+ * @param None
+ * @retval None
+ */
+void LM75_LowLevel_DeInit(void)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+
+ /*!< Disable LM75_I2C */
+ I2C_Cmd(LM75_I2C, DISABLE);
+
+ /*!< DeInitializes the LM75_I2C */
+ I2C_DeInit(LM75_I2C);
+
+ /*!< LM75_I2C Periph clock disable */
+ RCC_APB1PeriphClockCmd(LM75_I2C_CLK, DISABLE);
+
+ /*!< Configure LM75_I2C pins: SCL */
+ GPIO_InitStructure.GPIO_Pin = LM75_I2C_SCL_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
+ GPIO_Init(LM75_I2C_SCL_GPIO_PORT, &GPIO_InitStructure);
+
+ /*!< Configure LM75_I2C pins: SDA */
+ GPIO_InitStructure.GPIO_Pin = LM75_I2C_SDA_PIN;
+ GPIO_Init(LM75_I2C_SDA_GPIO_PORT, &GPIO_InitStructure);
+
+ /*!< Configure LM75_I2C pin: SMBUS ALERT */
+ GPIO_InitStructure.GPIO_Pin = LM75_I2C_SMBUSALERT_PIN;
+ GPIO_Init(LM75_I2C_SMBUSALERT_GPIO_PORT, &GPIO_InitStructure);
+}
+
+/**
+ * @brief Initializes the LM75_I2C..
+ * @param None
+ * @retval None
+ */
+void LM75_LowLevel_Init(void)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+
+ /*!< LM75_I2C Periph clock enable */
+ RCC_APB1PeriphClockCmd(LM75_I2C_CLK, ENABLE);
+
+ /*!< LM75_I2C_SCL_GPIO_CLK, LM75_I2C_SDA_GPIO_CLK
+ and LM75_I2C_SMBUSALERT_GPIO_CLK Periph clock enable */
+ RCC_AHBPeriphClockCmd(LM75_I2C_SCL_GPIO_CLK | LM75_I2C_SDA_GPIO_CLK |
+ LM75_I2C_SMBUSALERT_GPIO_CLK, ENABLE);
+
+ /* Connect PXx to I2C_SCL */
+ GPIO_PinAFConfig(LM75_I2C_SCL_GPIO_PORT, LM75_I2C_SCL_SOURCE, LM75_I2C_SCL_AF);
+
+ /* Connect PXx to I2C_SDA */
+ GPIO_PinAFConfig(LM75_I2C_SDA_GPIO_PORT, LM75_I2C_SDA_SOURCE, LM75_I2C_SDA_AF);
+
+ /* Connect PXx to I2C_SMBUSALER */
+ GPIO_PinAFConfig(LM75_I2C_SMBUSALERT_GPIO_PORT, LM75_I2C_SMBUSALERT_SOURCE, LM75_I2C_SMBUSALERT_AF);
+
+ /*!< Configure LM75_I2C pins: SCL */
+ GPIO_InitStructure.GPIO_Pin = LM75_I2C_SCL_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
+ GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
+ GPIO_Init(LM75_I2C_SCL_GPIO_PORT, &GPIO_InitStructure);
+
+ /*!< Configure LM75_I2C pins: SDA */
+ GPIO_InitStructure.GPIO_Pin = LM75_I2C_SDA_PIN;
+ GPIO_Init(LM75_I2C_SDA_GPIO_PORT, &GPIO_InitStructure);
+
+ /*!< Configure LM75_I2C pin: SMBUS ALERT */
+ GPIO_InitStructure.GPIO_Pin = LM75_I2C_SMBUSALERT_PIN;
+ GPIO_Init(LM75_I2C_SMBUSALERT_GPIO_PORT, &GPIO_InitStructure);
+}
+
+/**
+ * @brief DeInitializes the SPI interface.
+ * @param None
+ * @retval None
+ */
+void sEE_SPI_LowLevel_DeInit(void)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+
+ SPI_Cmd(sEE_SPI, DISABLE); /*!< sEE_SPI disable */
+ SPI_I2S_DeInit(sEE_SPI); /*!< DeInitializes the sEE_SPI */
+
+ /*!< sEE_SPI Periph clock disable */
+ RCC_APB1PeriphClockCmd(sEE_SPI_CLK, DISABLE);
+
+ /*!< Configure sEE_SPI pins: SCK */
+ GPIO_InitStructure.GPIO_Pin = sEE_SPI_SCK_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
+ GPIO_Init(sEE_SPI_SCK_GPIO_PORT, &GPIO_InitStructure);
+
+ /*!< Configure sEE pins: MISO */
+ GPIO_InitStructure.GPIO_Pin = sEE_SPI_MISO_PIN;
+ GPIO_Init(sEE_SPI_MISO_GPIO_PORT, &GPIO_InitStructure);
+
+ /*!< Configure sEE pins: MOSI */
+ GPIO_InitStructure.GPIO_Pin = sEE_SPI_MOSI_PIN;
+ GPIO_Init(sEE_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure);
+
+ /*!< Configure sEE_CS_PIN pin: sEE Card CS pin */
+ GPIO_InitStructure.GPIO_Pin = sEE_SPI_CS_PIN;
+ GPIO_Init(sEE_SPI_CS_GPIO_PORT, &GPIO_InitStructure);
+}
+
+/**
+ * @brief Initializes the SPI interface for EEPROM
+ * @param None
+ * @retval None
+ */
+void sEE_SPI_LowLevel_Init(void)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+ SPI_InitTypeDef SPI_InitStructure;
+
+ /*!< sEE_CS_GPIO, sEE_MOSI_GPIO, sEE_MISO_GPIO and sEE_SCK_GPIO
+ Periph clock enable */
+ RCC_AHBPeriphClockCmd(sEE_SPI_CS_GPIO_CLK | sEE_SPI_MOSI_GPIO_CLK | sEE_SPI_MISO_GPIO_CLK |
+ sEE_SPI_SCK_GPIO_CLK , ENABLE);
+
+ /*!< sEE Periph clock enable */
+ RCC_APB2PeriphClockCmd(sEE_SPI_CLK, ENABLE);
+
+ /*!< Configure sEE pins: SCK */
+ GPIO_InitStructure.GPIO_Pin = sEE_SPI_SCK_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
+ GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
+ GPIO_Init(sEE_SPI_SCK_GPIO_PORT, &GPIO_InitStructure);
+
+ /*!< Configure sEE_SPI pins: MISO */
+ GPIO_InitStructure.GPIO_Pin = sEE_SPI_MISO_PIN;
+ GPIO_Init(sEE_SPI_MISO_GPIO_PORT, &GPIO_InitStructure);
+
+ /*!< Configure sEE_SPI pins: MOSI */
+ GPIO_InitStructure.GPIO_Pin = sEE_SPI_MOSI_PIN;
+ GPIO_Init(sEE_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure);
+
+ /*!< Configure sEE_SPI_CS_PIN pin: sEE_SPI Card CS pin */
+ GPIO_InitStructure.GPIO_Pin = sEE_SPI_CS_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
+ GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
+ GPIO_Init(sEE_SPI_CS_GPIO_PORT, &GPIO_InitStructure);
+
+ /* Connect PXx to sEE_SPI_SCK */
+ GPIO_PinAFConfig(sEE_SPI_SCK_GPIO_PORT, sEE_SPI_SCK_SOURCE, sEE_SPI_SCK_AF);
+
+ /* Connect PXx to sEE_SPI_MISO */
+ GPIO_PinAFConfig(sEE_SPI_MISO_GPIO_PORT, sEE_SPI_MISO_SOURCE, sEE_SPI_MISO_AF);
+
+ /* Connect PXx to sEE_SPI_MOSI */
+ GPIO_PinAFConfig(sEE_SPI_MOSI_GPIO_PORT, sEE_SPI_MOSI_SOURCE, sEE_SPI_MOSI_AF);
+
+ /*!< sEE SPI Config */
+ SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
+ SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
+ SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
+ SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
+ SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;
+ SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
+ SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2;
+ SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
+ SPI_InitStructure.SPI_CRCPolynomial = 7;
+ SPI_Init(sEE_SPI, &SPI_InitStructure);
+
+ SPI_Cmd(sEE_SPI, ENABLE); /*!< sEE_SPI enable */
+}
+
+/**
+ * @brief DeInitializes peripherals used by the I2C EEPROM driver.
+ * @param None
+ * @retval None
+ */
+void sEE_LowLevel_DeInit(void)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+ NVIC_InitTypeDef NVIC_InitStructure;
+
+ /* sEE_I2C Peripheral Disable */
+ I2C_Cmd(sEE_I2C, DISABLE);
+
+ /* sEE_I2C DeInit */
+ I2C_DeInit(sEE_I2C);
+
+ /*!< sEE_I2C Periph clock disable */
+ RCC_APB1PeriphClockCmd(sEE_I2C_CLK, DISABLE);
+
+ /*!< GPIO configuration */
+ /*!< Configure sEE_I2C pins: SCL */
+ GPIO_InitStructure.GPIO_Pin = sEE_I2C_SCL_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
+ GPIO_Init(sEE_I2C_SCL_GPIO_PORT, &GPIO_InitStructure);
+
+ /*!< Configure sEE_I2C pins: SDA */
+ GPIO_InitStructure.GPIO_Pin = sEE_I2C_SDA_PIN;
+ GPIO_Init(sEE_I2C_SDA_GPIO_PORT, &GPIO_InitStructure);
+
+ /* Configure and enable I2C DMA TX Channel interrupt */
+ NVIC_InitStructure.NVIC_IRQChannel = sEE_I2C_DMA_TX_IRQn;
+ NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = sEE_I2C_DMA_PREPRIO;
+ NVIC_InitStructure.NVIC_IRQChannelSubPriority = sEE_I2C_DMA_SUBPRIO;
+ NVIC_InitStructure.NVIC_IRQChannelCmd = DISABLE;
+ NVIC_Init(&NVIC_InitStructure);
+
+ /* Configure and enable I2C DMA RX Channel interrupt */
+ NVIC_InitStructure.NVIC_IRQChannel = sEE_I2C_DMA_RX_IRQn;
+ NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = sEE_I2C_DMA_PREPRIO;
+ NVIC_InitStructure.NVIC_IRQChannelSubPriority = sEE_I2C_DMA_SUBPRIO;
+ NVIC_Init(&NVIC_InitStructure);
+
+ /* Disable and Deinitialize the DMA channels */
+ DMA_Cmd(sEE_I2C_DMA_CHANNEL_TX, DISABLE);
+ DMA_Cmd(sEE_I2C_DMA_CHANNEL_RX, DISABLE);
+ DMA_DeInit(sEE_I2C_DMA_CHANNEL_TX);
+ DMA_DeInit(sEE_I2C_DMA_CHANNEL_RX);
+}
+
+/**
+ * @brief Initializes peripherals used by the I2C EEPROM driver.
+ * @param None
+ * @retval None
+ */
+void sEE_LowLevel_Init(void)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+ NVIC_InitTypeDef NVIC_InitStructure;
+
+ /*!< sEE_I2C_SCL_GPIO_CLK and sEE_I2C_SDA_GPIO_CLK Periph clock enable */
+ RCC_AHBPeriphClockCmd(sEE_I2C_SCL_GPIO_CLK | sEE_I2C_SDA_GPIO_CLK, ENABLE);
+
+ /*!< sEE_I2C Periph clock enable */
+ RCC_APB1PeriphClockCmd(sEE_I2C_CLK, ENABLE);
+
+ /* Connect PXx to I2C_SCL*/
+ GPIO_PinAFConfig(sEE_I2C_SCL_GPIO_PORT, sEE_I2C_SCL_SOURCE, sEE_I2C_SCL_AF);
+
+ /* Connect PXx to I2C_SDA*/
+ GPIO_PinAFConfig(sEE_I2C_SDA_GPIO_PORT, sEE_I2C_SDA_SOURCE, sEE_I2C_SDA_AF);
+
+ /*!< GPIO configuration */
+ /*!< Configure sEE_I2C pins: SCL */
+ GPIO_InitStructure.GPIO_Pin = sEE_I2C_SCL_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
+ GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
+ GPIO_Init(sEE_I2C_SCL_GPIO_PORT, &GPIO_InitStructure);
+
+ /*!< Configure sEE_I2C pins: SDA */
+ GPIO_InitStructure.GPIO_Pin = sEE_I2C_SDA_PIN;
+ GPIO_Init(sEE_I2C_SDA_GPIO_PORT, &GPIO_InitStructure);
+
+ /* Configure and enable I2C DMA TX Channel interrupt */
+ NVIC_InitStructure.NVIC_IRQChannel = sEE_I2C_DMA_TX_IRQn;
+ NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = sEE_I2C_DMA_PREPRIO;
+ NVIC_InitStructure.NVIC_IRQChannelSubPriority = sEE_I2C_DMA_SUBPRIO;
+ NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
+ NVIC_Init(&NVIC_InitStructure);
+
+ /* Configure and enable I2C DMA RX Channel interrupt */
+ NVIC_InitStructure.NVIC_IRQChannel = sEE_I2C_DMA_RX_IRQn;
+ NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = sEE_I2C_DMA_PREPRIO;
+ NVIC_InitStructure.NVIC_IRQChannelSubPriority = sEE_I2C_DMA_SUBPRIO;
+ NVIC_Init(&NVIC_InitStructure);
+
+ /*!< I2C DMA TX and RX channels configuration */
+ /* Enable the DMA clock */
+ RCC_AHBPeriphClockCmd(sEE_I2C_DMA_CLK, ENABLE);
+
+ /* I2C TX DMA Channel configuration */
+ DMA_DeInit(sEE_I2C_DMA_CHANNEL_TX);
+ sEEDMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)sEE_I2C_DR_Address;
+ sEEDMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)0; /* This parameter will be configured durig communication */
+ sEEDMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST; /* This parameter will be configured durig communication */
+ sEEDMA_InitStructure.DMA_BufferSize = 0xFFFF; /* This parameter will be configured durig communication */
+ sEEDMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
+ sEEDMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
+ sEEDMA_InitStructure.DMA_PeripheralDataSize = DMA_MemoryDataSize_Byte;
+ sEEDMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
+ sEEDMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
+ sEEDMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh;
+ sEEDMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
+ DMA_Init(sEE_I2C_DMA_CHANNEL_TX, &sEEDMA_InitStructure);
+
+ /* I2C RX DMA Channel configuration */
+ DMA_DeInit(sEE_I2C_DMA_CHANNEL_RX);
+ DMA_Init(sEE_I2C_DMA_CHANNEL_RX, &sEEDMA_InitStructure);
+
+ /* Enable the DMA Channels Interrupts */
+ DMA_ITConfig(sEE_I2C_DMA_CHANNEL_TX, DMA_IT_TC, ENABLE);
+ DMA_ITConfig(sEE_I2C_DMA_CHANNEL_RX, DMA_IT_TC, ENABLE);
+}
+
+
+/**
+ * @brief Initializes DMA channel used by the I2C EEPROM driver.
+ * @param None
+ * @retval None
+ */
+void sEE_LowLevel_DMAConfig(uint32_t pBuffer, uint32_t BufferSize, uint32_t Direction)
+{
+ /* Initialize the DMA with the new parameters */
+ if (Direction == sEE_DIRECTION_TX)
+ {
+ /* Configure the DMA Tx Channel with the buffer address and the buffer size */
+ sEEDMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)pBuffer;
+ sEEDMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
+ sEEDMA_InitStructure.DMA_BufferSize = (uint32_t)BufferSize;
+ DMA_Init(sEE_I2C_DMA_CHANNEL_TX, &sEEDMA_InitStructure);
+ }
+ else
+ {
+ /* Configure the DMA Rx Channel with the buffer address and the buffer size */
+ sEEDMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)pBuffer;
+ sEEDMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
+ sEEDMA_InitStructure.DMA_BufferSize = (uint32_t)BufferSize;
+ DMA_Init(sEE_I2C_DMA_CHANNEL_RX, &sEEDMA_InitStructure);
+ }
+}
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval.h b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval.h
new file mode 100644
index 0000000..f7e40bd
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval.h
@@ -0,0 +1,465 @@
+/**
+ ******************************************************************************
+ * @file stm32l152d_eval.h
+ * @author MCD Application Team
+ * @version V1.0.1
+ * @date 09-March-2012
+ * @brief This file contains definitions for STM32L152D_EVAL's Leds, push-buttons
+ * COM ports and Temperature Sensor LM75 (on I2C) hardware resources.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.st.com/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __STM32L152D_EVAL_H
+#define __STM32L152D_EVAL_H
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+/* Includes ------------------------------------------------------------------*/
+#include "stm32l1xx.h"
+#include "stm32_eval_legacy.h"
+
+/** @addtogroup Utilities
+ * @{
+ */
+
+/** @addtogroup STM32_EVAL
+ * @{
+ */
+
+/** @addtogroup STM32L152D_EVAL
+ * @{
+ */
+
+/** @addtogroup STM32L152D_EVAL_LOW_LEVEL
+ * @{
+ */
+
+/** @defgroup STM32L152D_EVAL_LOW_LEVEL_Exported_Types
+ * @{
+ */
+typedef enum
+{
+ LED1 = 0,
+ LED2 = 1,
+ LED3 = 2,
+ LED4 = 3
+} Led_TypeDef;
+
+typedef enum
+{
+ BUTTON_KEY = 0,
+ BUTTON_RIGHT = 1,
+ BUTTON_LEFT = 2,
+ BUTTON_UP = 3,
+ BUTTON_DOWN = 4,
+ BUTTON_SEL = 5
+} Button_TypeDef;
+
+typedef enum
+{
+ BUTTON_MODE_GPIO = 0,
+ BUTTON_MODE_EXTI = 1
+} ButtonMode_TypeDef;
+
+typedef enum
+{
+ JOY_NONE = 0,
+ JOY_SEL = 1,
+ JOY_DOWN = 2,
+ JOY_LEFT = 3,
+ JOY_RIGHT = 4,
+ JOY_UP = 5
+} JOYState_TypeDef
+;
+
+typedef enum
+{
+ COM1 = 0,
+ COM2 = 1
+} COM_TypeDef;
+/**
+ * @}
+ */
+
+/** @defgroup STM32L152D_EVAL_LOW_LEVEL_Exported_Constants
+ * @{
+ */
+
+/**
+ * @brief Define for STM32L152D_EVAL board
+ */
+#if !defined (USE_STM32L152D_EVAL)
+ #define USE_STM32L152D_EVAL
+#endif
+
+/** @addtogroup STM32L152D_EVAL_LOW_LEVEL_LED
+ * @{
+ */
+#define LEDn 4
+
+#define LED1_PIN GPIO_Pin_3
+#define LED1_GPIO_PORT GPIOD
+#define LED1_GPIO_CLK RCC_AHBPeriph_GPIOD
+
+#define LED2_PIN GPIO_Pin_7
+#define LED2_GPIO_PORT GPIOD
+#define LED2_GPIO_CLK RCC_AHBPeriph_GPIOD
+
+#define LED3_PIN GPIO_Pin_14
+#define LED3_GPIO_PORT GPIOG
+#define LED3_GPIO_CLK RCC_AHBPeriph_GPIOG
+
+#define LED4_PIN GPIO_Pin_15
+#define LED4_GPIO_PORT GPIOG
+#define LED4_GPIO_CLK RCC_AHBPeriph_GPIOG
+
+/**
+ * @}
+ */
+
+/** @addtogroup STM32L152D_EVAL_LOW_LEVEL_BUTTON
+ * @{
+ */
+#define BUTTONn 6
+/* On STM32L152D-EVAL board, the KEY button is connected to PA.00 and it can
+ be use as Wakeup pin button. */
+
+/**
+ * @brief Key push-button
+ */
+#define KEY_BUTTON_PIN GPIO_Pin_0
+#define KEY_BUTTON_GPIO_PORT GPIOA
+#define KEY_BUTTON_GPIO_CLK RCC_AHBPeriph_GPIOA
+#define KEY_BUTTON_EXTI_LINE EXTI_Line0
+#define KEY_BUTTON_EXTI_PORT_SOURCE EXTI_PortSourceGPIOA
+#define KEY_BUTTON_EXTI_PIN_SOURCE EXTI_PinSource0
+#define KEY_BUTTON_EXTI_IRQn EXTI0_IRQn
+
+/**
+ * @brief Joystick Right push-button
+ */
+#define RIGHT_BUTTON_PIN GPIO_Pin_7
+#define RIGHT_BUTTON_GPIO_PORT GPIOG
+#define RIGHT_BUTTON_GPIO_CLK RCC_AHBPeriph_GPIOG
+#define RIGHT_BUTTON_EXTI_LINE EXTI_Line7
+#define RIGHT_BUTTON_EXTI_PORT_SOURCE EXTI_PortSourceGPIOG
+#define RIGHT_BUTTON_EXTI_PIN_SOURCE EXTI_PinSource7
+#define RIGHT_BUTTON_EXTI_IRQn EXTI9_5_IRQn
+
+/**
+ * @brief Joystick Left push-button
+ */
+#define LEFT_BUTTON_PIN GPIO_Pin_6
+#define LEFT_BUTTON_GPIO_PORT GPIOG
+#define LEFT_BUTTON_GPIO_CLK RCC_AHBPeriph_GPIOG
+#define LEFT_BUTTON_EXTI_LINE EXTI_Line6
+#define LEFT_BUTTON_EXTI_PORT_SOURCE EXTI_PortSourceGPIOG
+#define LEFT_BUTTON_EXTI_PIN_SOURCE EXTI_PinSource6
+#define LEFT_BUTTON_EXTI_IRQn EXTI9_5_IRQn
+
+/**
+ * @brief Joystick Up push-button
+ */
+#define UP_BUTTON_PIN GPIO_Pin_11
+#define UP_BUTTON_GPIO_PORT GPIOG
+#define UP_BUTTON_GPIO_CLK RCC_AHBPeriph_GPIOG
+#define UP_BUTTON_EXTI_LINE EXTI_Line11
+#define UP_BUTTON_EXTI_PORT_SOURCE EXTI_PortSourceGPIOG
+#define UP_BUTTON_EXTI_PIN_SOURCE EXTI_PinSource11
+#define UP_BUTTON_EXTI_IRQn EXTI15_10_IRQn
+
+/**
+ * @brief Joystick Down push-button
+ */
+#define DOWN_BUTTON_PIN GPIO_Pin_8
+#define DOWN_BUTTON_GPIO_PORT GPIOG
+#define DOWN_BUTTON_GPIO_CLK RCC_AHBPeriph_GPIOG
+#define DOWN_BUTTON_EXTI_LINE EXTI_Line8
+#define DOWN_BUTTON_EXTI_PORT_SOURCE EXTI_PortSourceGPIOG
+#define DOWN_BUTTON_EXTI_PIN_SOURCE EXTI_PinSource8
+#define DOWN_BUTTON_EXTI_IRQn EXTI9_5_IRQn
+
+/**
+ * @brief Joystick Sel push-button
+ */
+#define SEL_BUTTON_PIN GPIO_Pin_13
+#define SEL_BUTTON_GPIO_PORT GPIOG
+#define SEL_BUTTON_GPIO_CLK RCC_AHBPeriph_GPIOG
+#define SEL_BUTTON_EXTI_LINE EXTI_Line13
+#define SEL_BUTTON_EXTI_PORT_SOURCE EXTI_PortSourceGPIOG
+#define SEL_BUTTON_EXTI_PIN_SOURCE EXTI_PinSource13
+#define SEL_BUTTON_EXTI_IRQn EXTI15_10_IRQn
+
+/**
+ * @}
+ */
+
+/** @addtogroup STM32L152D_EVAL_LOW_LEVEL_COM
+ * @{
+ */
+#define COMn 1
+
+/**
+ * @brief Definition for COM port1, connected to USART1
+ */
+#define EVAL_COM1 USART1
+#define EVAL_COM1_CLK RCC_APB2Periph_USART1
+
+#define EVAL_COM1_TX_PIN GPIO_Pin_9
+#define EVAL_COM1_TX_GPIO_PORT GPIOA
+#define EVAL_COM1_TX_GPIO_CLK RCC_AHBPeriph_GPIOA
+#define EVAL_COM1_TX_SOURCE GPIO_PinSource9
+#define EVAL_COM1_TX_AF GPIO_AF_USART1
+
+#define EVAL_COM1_RX_PIN GPIO_Pin_10
+#define EVAL_COM1_RX_GPIO_PORT GPIOA
+#define EVAL_COM1_RX_GPIO_CLK RCC_AHBPeriph_GPIOA
+#define EVAL_COM1_RX_SOURCE GPIO_PinSource10
+#define EVAL_COM1_RX_AF GPIO_AF_USART1
+
+#define EVAL_COM1_IRQn USART1_IRQn
+
+/**
+ * @}
+ */
+
+/** @addtogroup STM32L152D_EVAL_LOW_LEVEL_SD_FLASH
+ * @{
+ */
+/**
+ * @brief SD FLASH SDIO Interface
+ */
+#define SD_DETECT_PIN GPIO_Pin_7 /* PC.07 */
+#define SD_DETECT_EXTI_LINE EXTI_Line7
+#define SD_DETECT_EXTI_PIN_SOURCE EXTI_PinSource7
+
+#define SD_DETECT_GPIO_PORT GPIOC /* GPIOC */
+#define SD_DETECT_GPIO_CLK RCC_AHBPeriph_GPIOC
+#define SD_DETECT_EXTI_PORT_SOURCE EXTI_PortSourceGPIOC
+#define SD_DETECT_EXTI_IRQn EXTI9_5_IRQn
+
+
+#define SDIO_FIFO_ADDRESS ((uint32_t)0x40012C80)
+/**
+ * @brief SDIO Intialization Frequency (400KHz max)
+ */
+#define SDIO_INIT_CLK_DIV ((uint8_t)0x76)
+/**
+ * @brief SDIO Data Transfer Frequency (24MHz max)
+ */
+#define SDIO_TRANSFER_CLK_DIV ((uint8_t)0x1)
+
+
+#define SD_SDIO_DMA DMA2
+#define SD_SDIO_DMA_CLK RCC_AHBPeriph_DMA2
+#define SD_SDIO_DMA_CHANNEL DMA2_Channel4
+#define SD_SDIO_DMA_FLAG_TC DMA2_FLAG_TC4
+#define SD_SDIO_DMA_FLAG_TE DMA2_FLAG_TE4
+#define SD_SDIO_DMA_FLAG_HT DMA2_FLAG_HT4
+#define SD_SDIO_DMA_FLAG_GL DMA2_FLAG_GL4
+#define SD_SDIO_DMA_IRQn DMA2_Channel4_IRQn
+#define SD_SDIO_DMA_IRQHANDLER DMA2_Channel4_IRQHandler
+/**
+ * @}
+ */
+
+/** @addtogroup STM32L152D_EVAL_LOW_LEVEL_TSENSOR_I2C
+ * @{
+ */
+/**
+ * @brief LM75 Temperature Sensor I2C Interface pins
+ */
+#define LM75_I2C I2C1
+#define LM75_I2C_CLK RCC_APB1Periph_I2C1
+#define LM75_I2C_SCL_PIN GPIO_Pin_8 /* PB.08 */
+#define LM75_I2C_SCL_GPIO_PORT GPIOB /* GPIOB */
+#define LM75_I2C_SCL_GPIO_CLK RCC_AHBPeriph_GPIOB
+#define LM75_I2C_SCL_SOURCE GPIO_PinSource8
+#define LM75_I2C_SCL_AF GPIO_AF_I2C1
+#define LM75_I2C_SDA_PIN GPIO_Pin_9 /* PB.09 */
+#define LM75_I2C_SDA_GPIO_PORT GPIOB /* GPIOB */
+#define LM75_I2C_SDA_GPIO_CLK RCC_AHBPeriph_GPIOB
+#define LM75_I2C_SDA_SOURCE GPIO_PinSource9
+#define LM75_I2C_SDA_AF GPIO_AF_I2C1
+#define LM75_I2C_SMBUSALERT_PIN GPIO_Pin_5 /* PB.05 */
+#define LM75_I2C_SMBUSALERT_GPIO_PORT GPIOB /* GPIOB */
+#define LM75_I2C_SMBUSALERT_GPIO_CLK RCC_AHBPeriph_GPIOB
+#define LM75_I2C_SMBUSALERT_SOURCE GPIO_PinSource5
+#define LM75_I2C_SMBUSALERT_AF GPIO_AF_I2C1
+#define LM75_I2C_DR ((uint32_t)0x40005410)
+
+#define LM75_DMA_CLK RCC_AHBPeriph_DMA1
+#define LM75_DMA_TX_CHANNEL DMA1_Channel6
+#define LM75_DMA_RX_CHANNEL DMA1_Channel7
+#define LM75_DMA_TX_TCFLAG DMA1_FLAG_TC6
+#define LM75_DMA_RX_TCFLAG DMA1_FLAG_TC7
+/**
+ * @}
+ */
+
+/** @addtogroup STM32L152D_EVAL_LOW_LEVEL_SPI_EE
+ * @{
+ */
+/**
+ * @brief sEE SPI Interface pins
+ */
+#define sEE_SPI SPI1
+#define sEE_SPI_CLK RCC_APB2Periph_SPI1
+
+#define sEE_SPI_SCK_PIN GPIO_Pin_5 /* PA.05 */
+#define sEE_SPI_SCK_GPIO_PORT GPIOA /* GPIOA */
+#define sEE_SPI_SCK_GPIO_CLK RCC_AHBPeriph_GPIOA
+#define sEE_SPI_SCK_SOURCE GPIO_PinSource5
+#define sEE_SPI_SCK_AF GPIO_AF_SPI1
+
+#define sEE_SPI_MISO_PIN GPIO_Pin_14 /* PE.14 */
+#define sEE_SPI_MISO_GPIO_PORT GPIOE /* GPIOE */
+#define sEE_SPI_MISO_GPIO_CLK RCC_AHBPeriph_GPIOE
+#define sEE_SPI_MISO_SOURCE GPIO_PinSource14
+#define sEE_SPI_MISO_AF GPIO_AF_SPI1
+
+#define sEE_SPI_MOSI_PIN GPIO_Pin_15 /* PE.15 */
+#define sEE_SPI_MOSI_GPIO_PORT GPIOE /* GPIOE */
+#define sEE_SPI_MOSI_GPIO_CLK RCC_AHBPeriph_GPIOE
+#define sEE_SPI_MOSI_SOURCE GPIO_PinSource15
+#define sEE_SPI_MOSI_AF GPIO_AF_SPI1
+
+#define sEE_SPI_CS_PIN GPIO_Pin_5 /* PC.05 */
+#define sEE_SPI_CS_GPIO_PORT GPIOC /* GPIOC */
+#define sEE_SPI_CS_GPIO_CLK RCC_AHBPeriph_GPIOC
+
+/**
+ * @brief sEE SPI Interface Type
+ */
+#define sEE_M95040
+
+/**
+ * @}
+ */
+
+/** @addtogroup STM32L152D_EVAL_LOW_LEVEL_I2C_EE
+ * @{
+ */
+/**
+ * @brief I2C EEPROM Interface pins
+ */
+#define sEE_I2C I2C1
+#define sEE_I2C_CLK RCC_APB1Periph_I2C1
+
+#define sEE_I2C_SCL_PIN GPIO_Pin_8 /* PB.08 */
+#define sEE_I2C_SCL_GPIO_PORT GPIOB /* GPIOB */
+#define sEE_I2C_SCL_GPIO_CLK RCC_AHBPeriph_GPIOB
+#define sEE_I2C_SCL_SOURCE GPIO_PinSource8
+#define sEE_I2C_SCL_AF GPIO_AF_I2C1
+
+#define sEE_I2C_SDA_PIN GPIO_Pin_9 /* PB.09 */
+#define sEE_I2C_SDA_GPIO_PORT GPIOB /* GPIOB */
+#define sEE_I2C_SDA_GPIO_CLK RCC_AHBPeriph_GPIOB
+#define sEE_I2C_SDA_SOURCE GPIO_PinSource9
+#define sEE_I2C_SDA_AF GPIO_AF_I2C1
+
+#define sEE_M24LR64
+
+#define sEE_I2C_DMA DMA1
+#define sEE_I2C_DMA_CHANNEL_TX DMA1_Channel6
+#define sEE_I2C_DMA_CHANNEL_RX DMA1_Channel7
+#define sEE_I2C_DMA_FLAG_TX_TC DMA1_IT_TC6
+#define sEE_I2C_DMA_FLAG_TX_GL DMA1_IT_GL6
+#define sEE_I2C_DMA_FLAG_RX_TC DMA1_IT_TC7
+#define sEE_I2C_DMA_FLAG_RX_GL DMA1_IT_GL7
+#define sEE_I2C_DMA_CLK RCC_AHBPeriph_DMA1
+#define sEE_I2C_DR_Address ((uint32_t)0x40005410)
+#define sEE_USE_DMA
+
+#define sEE_I2C_DMA_TX_IRQn DMA1_Channel6_IRQn
+#define sEE_I2C_DMA_RX_IRQn DMA1_Channel7_IRQn
+#define sEE_I2C_DMA_TX_IRQHandler DMA1_Channel6_IRQHandler
+#define sEE_I2C_DMA_RX_IRQHandler DMA1_Channel7_IRQHandler
+#define sEE_I2C_DMA_PREPRIO 0
+#define sEE_I2C_DMA_SUBPRIO 0
+
+#define sEE_DIRECTION_TX 0
+#define sEE_DIRECTION_RX 1
+
+/* Time constant for the delay caclulation allowing to have a millisecond
+ incrementing counter. This value should be equal to (System Clock / 1000).
+ ie. if system clock = 32MHz then sEE_TIME_CONST should be 32. */
+#define sEE_TIME_CONST 32
+
+/**
+ * @}
+ */
+
+/** @defgroup STM32L152D_EVAL_LOW_LEVEL_Exported_Macros
+ * @{
+ */
+/**
+ * @}
+ */
+
+/** @defgroup STM32L152D_EVAL_LOW_LEVEL_Exported_Functions
+ * @{
+ */
+void STM_EVAL_LEDInit(Led_TypeDef Led);
+void STM_EVAL_LEDOn(Led_TypeDef Led);
+void STM_EVAL_LEDOff(Led_TypeDef Led);
+void STM_EVAL_LEDToggle(Led_TypeDef Led);
+void STM_EVAL_PBInit(Button_TypeDef Button, ButtonMode_TypeDef Button_Mode);
+uint32_t STM_EVAL_PBGetState(Button_TypeDef Button);
+void STM_EVAL_COMInit(COM_TypeDef COM, USART_InitTypeDef* USART_InitStruct);
+void SD_LowLevel_DeInit(void);
+void SD_LowLevel_Init(void);
+void SD_LowLevel_DMA_TxConfig(uint32_t *BufferSRC, uint32_t BufferSize);
+void SD_LowLevel_DMA_RxConfig(uint32_t *BufferDST, uint32_t BufferSize);
+void LM75_LowLevel_DeInit(void);
+void LM75_LowLevel_Init(void);
+void sEE_SPI_LowLevel_DeInit(void);
+void sEE_SPI_LowLevel_Init(void);
+void sEE_LowLevel_DeInit(void);
+void sEE_LowLevel_Init(void);
+void sEE_LowLevel_DMAConfig(uint32_t pBuffer, uint32_t BufferSize, uint32_t Direction);
+/**
+ * @}
+ */
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __STM32L152D_EVAL_H */
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval_audio_codec.c b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval_audio_codec.c
new file mode 100644
index 0000000..4fad206
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval_audio_codec.c
@@ -0,0 +1,1489 @@
+/**
+ ******************************************************************************
+ * @file stm32l152d_eval_audio_codec.c
+ * @author MCD Application Team
+ * @version V1.0.1
+ * @date 09-March-2012
+ * @brief This file includes the low layer driver for CS43L22 Audio Codec
+ * mounted on STM32L152D-EVAL board.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.st.com/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+
+/*==============================================================================================================================
+ User NOTES
+1. How To use this driver:
+--------------------------
+ - This driver supports STM32L1xx devices on STM32L152D-EVAL Evaluation boards.
+
+ - Configure the options in file stm32l152d_eval_audio_codec.h in the section CONFIGURATION.
+ Refer to the sections 2 and 3 to have more details on the possible configurations.
+
+ - Call the function EVAL_AUDIO_Init(
+ OutputDevice: physical output mode (OUTPUT_DEVICE_SPEAKER,
+ OUTPUT_DEVICE_HEADPHONE, OUTPUT_DEVICE_AUTO or
+ OUTPUT_DEVICE_BOTH)
+ Volume: intial volume to be set (0 is min (mute), 100 is max (100%)
+ AudioFreq: Audio frequency in Hz (8000, 16000, 22500, 32000 ...)
+ this parameter is relative to the audio file/stream type.
+ )
+ This function configures all the hardware required for the audio application (codec, I2C, I2S,
+ GPIOs, DMA and interrupt if needed). This function returns 0 if configuration is OK.
+ if the returned value is different from 0 or the function is stuck then the communication with
+ the codec or the IOExpander has failed (try to unplug the power or reset device in this case).
+ + OUTPUT_DEVICE_SPEAKER: only speaker will be set as output for the audio stream.
+ + OUTPUT_DEVICE_HEADPHONE: only headphones will be set as output for the audio stream.
+ + OUTPUT_DEVICE_AUTO: Selection of output device is made through external switch (implemented
+ into the audio jack on the evaluation board). When the Headphone is connected it is used
+ as output. When the headphone is disconnected from tha audio jack, the output is
+ automatically switched to Speaker.
+ + OUTPUT_DEVICE_BOTH: both Speaker and Headphone are used as outputs for the audio stream
+ at the same time.
+
+ - Call the function EVAL_AUDIO_Play(
+ pBuffer: pointer to the audio data file address
+ Size: size of the buffer to be sent in Bytes
+ )
+ to start playing (for the first time) from the audio file/stream.
+
+ - Call the function EVAL_AUDIO_PauseResume(
+ Cmd: AUDIO_PAUSE (or 0) to pause playing or AUDIO_RESUME (or
+ any value different from 0) to resume palying.
+ )
+ Note. After calling EVAL_AUDIO_PauseResume() function for pause, only EVAL_AUDIO_PauseResume() should be called
+ for resume (it is not allowed to call EVAL_AUDIO_Play() in this case).
+ Note. This function should be called only when the audio file is played or paused (not stopped).
+
+ - For each mode, you may need to implement the relative callback functions into your code.
+ The Callback functions are named EVAL_AUDIO_XXX_CallBack() and only their prototypes are declared in
+ the stm324xg_eval_audio_codec.h file. (refer to the example for more details on the callbacks implementations)
+
+ - To Stop playing, to modify the volume level or to mute, use the functions
+ EVAL_AUDIO_Stop(), EVAL_AUDIO_VolumeCtl() and EVAL_AUDIO_Mute().
+
+ - The driver API and the callback functions are at the end of the stm324xg_eval_audio_codec.h file.
+
+
+ Driver architecture:
+ --------------------
+ This driver is composed of three main layers:
+ o High Audio Layer: consists of the function API exported in the stm324xg_eval_audio_codec.h file
+ (EVAL_AUDIO_Init(), EVAL_AUDIO_Play() ...)
+ o Codec Control layer: consists of the functions API controlling the audio codec (CS43L22) and
+ included as local functions in file stm324xg_eval_audio_codec.c (Codec_Init(), Codec_Play() ...)
+ o Media Access Layer (MAL): which consists of functions allowing to access the media containing/
+ providing the audio file/stream. These functions are also included as local functions into
+ the stm324xg_eval_audio_codec.c file (Audio_MAL_Init(), Audio_MAL_Play() ...)
+ Each set of functions (layer) may be implemented independently of the others and customized when
+ needed.
+
+2. Modes description:
+---------------------
+ + AUDIO_MAL_MODE_NORMAL : is suitable when the audio file is in a memory location.
+ + AUDIO_MAL_MODE_CIRCULAR: is suitable when the audio data are read either from a
+ memory location or from a device at real time (double buffer could be used).
+
+3. DMA interrupts description:
+------------------------------
+ + EVAL_AUDIO_IT_TC_ENABLE: Enable this define to use the DMA end of transfer interrupt.
+ then, a callback should be implemented by user to perform specific actions
+ when the DMA has finished the transfer.
+ + EVAL_AUDIO_IT_HT_ENABLE: Enable this define to use the DMA end of half transfer interrupt.
+ then, a callback should be implemented by user to perform specific actions
+ when the DMA has reached the half of the buffer transfer (generally, it is useful
+ to load the first half of buffer while DMA is loading from the second half).
+ + EVAL_AUDIO_IT_ER_ENABLE: Enable this define to manage the cases of error on DMA transfer.
+
+4. Known Limitations:
+---------------------
+ 1- When using the Speaker, if the audio file quality is not high enough, the speaker output
+ may produce high and uncomfortable noise level. To avoid this issue, to use speaker
+ output properly, try to increase audio file sampling rate (typically higher than 48KHz).
+ This operation will lead to larger file size.
+ 2- Communication with the audio codec (through I2C) may be corrupted if it is interrupted by some
+ user interrupt routines (in this case, interrupts could be disabled just before the start of
+ communication then re-enabled when it is over). Note that this communication is only done at
+ the configuration phase (EVAL_AUDIO_Init() or EVAL_AUDIO_Stop()) and when Volume control modification is
+ performed (EVAL_AUDIO_VolumeCtl() or EVAL_AUDIO_Mute()). When the audio data is played, no communication is
+ required with the audio codec.
+ 3- Parsing of audio file is not implemented (in order to determine audio file properties: Mono/Stereo, Data size,
+ File size, Audio Frequency, Audio Data header size ...). The configuration is fixed for the given audio file.
+ 4- Mono audio streaming is not supported (in order to play mono audio streams, each data should be sent twice
+ on the I2S or should be duplicated on the source buffer. Or convert the stream in stereo before playing).
+ 5- Supports only 16-bit audio data size.
+===============================================================================================================================*/
+
+
+/* Includes ------------------------------------------------------------------*/
+#include "stm32l152d_eval_audio_codec.h"
+
+/** @addtogroup Utilities
+ * @{
+ */
+
+/** @addtogroup STM32_EVAL
+ * @{
+ */
+
+/** @addtogroup STM32L152D_EVAL
+ * @{
+ */
+
+/** @addtogroup STM32L152D_EVAL_AUDIO_CODEC
+ * @brief This file includes the low layer driver for CS43L22 Audio Codec
+ * available on STM32L152D-EVAL Eval.
+ * @{
+ */
+
+/** @defgroup STM32L152D_EVAL_AUDIO_CODEC_Private_Types
+ * @{
+ */
+/**
+ * @}
+ */
+
+/** @defgroup STM32L152D_EVAL_AUDIO_CODEC_Private_Defines
+ * @{
+ */
+
+/* Mask for the bit EN of the I2S CFGR register */
+#define I2S_ENABLE_MASK 0x0400
+
+/* Delay for the Codec to be correctly reset */
+#define CODEC_RESET_DELAY 0x4FFF
+
+/* Codec audio Standards */
+#ifdef I2S_STANDARD_PHILLIPS
+#define CODEC_STANDARD 0x04
+#define I2S_STANDARD I2S_Standard_Phillips
+#elif defined(I2S_STANDARD_MSB)
+#define CODEC_STANDARD 0x00
+#define I2S_STANDARD I2S_Standard_MSB
+#elif defined(I2S_STANDARD_LSB)
+#define CODEC_STANDARD 0x08
+#define I2S_STANDARD I2S_Standard_LSB
+#else
+#error "Error: No audio communication standard selected !"
+#endif /* I2S_STANDARD */
+
+/* The 7 bits Codec address (sent through I2C interface) */
+#define CODEC_ADDRESS 0x94 /* b00100111 */
+/**
+ * @}
+ */
+
+/** @defgroup STM32L152D_EVAL_AUDIO_CODEC_Private_Macros
+ * @{
+ */
+/**
+ * @}
+ */
+
+/** @defgroup STM32L152D_EVAL_AUDIO_CODEC_Private_Variables
+ * @{
+ */
+/* This structure is declared global because it is handled by two different functions */
+static DMA_InitTypeDef DMA_InitStructure;
+
+DMA_InitTypeDef AUDIO_MAL_DMA_InitStructure;
+
+uint32_t AudioTotalSize = 0xFFFF; /* This variable holds the total size of the audio file */
+uint32_t AudioRemSize = 0xFFFF; /* This variable holds the remaining data in audio file */
+uint16_t *CurrentPos; /* This variable holds the current position of audio pointer */
+
+__IO uint32_t CODECTimeout = CODEC_LONG_TIMEOUT;
+__IO uint8_t OutputDev = 0;
+
+__IO uint32_t CurrAudioInterface = AUDIO_INTERFACE_I2S;
+/**
+ * @}
+ */
+
+/** @defgroup STM32L152D_EVAL_AUDIO_CODEC_Private_Function_Prototypes
+ * @{
+ */
+/**
+ * @}
+ */
+
+/** @defgroup STM32L152D_EVAL_AUDIO_CODEC_Private_Functions
+ * @{
+ */
+static void Audio_MAL_IRQHandler(void);
+/*-----------------------------------
+Audio Codec functions
+------------------------------------------*/
+/* High Layer codec functions */
+static uint32_t Codec_Init(uint16_t OutputDevice, uint8_t Volume, uint32_t AudioFreq);
+static uint32_t Codec_DeInit(void);
+static uint32_t Codec_Play(void);
+static uint32_t Codec_PauseResume(uint32_t Cmd);
+static uint32_t Codec_Stop(uint32_t Cmd);
+static uint32_t Codec_VolumeCtrl(uint8_t Volume);
+static uint32_t Codec_Mute(uint32_t Cmd);
+/* Low layer codec functions */
+static void Codec_CtrlInterface_Init(void);
+static void Codec_CtrlInterface_DeInit(void);
+static void Codec_AudioInterface_Init(uint32_t AudioFreq);
+static void Codec_AudioInterface_DeInit(void);
+static void Codec_Reset(void);
+static uint32_t Codec_WriteRegister(uint8_t RegisterAddr, uint8_t RegisterValue);
+static uint32_t Codec_ReadRegister(uint8_t RegisterAddr);
+static void Codec_GPIO_Init(void);
+static void Codec_GPIO_DeInit(void);
+static void Delay(__IO uint32_t nCount);
+/*----------------------------------------------------------------------------*/
+
+/*-----------------------------------
+MAL (Media Access Layer) functions
+------------------------------------------*/
+/* Peripherals configuration functions */
+static void Audio_MAL_Init(void);
+static void Audio_MAL_DeInit(void);
+static void Audio_MAL_Play(uint32_t Addr, uint32_t Size);
+static void Audio_MAL_PauseResume(uint32_t Cmd, uint32_t Addr);
+static void Audio_MAL_Stop(void);
+
+/*----------------------------------------------------------------------------*/
+
+/* DMA Channel definitions */
+DMA_Channel_TypeDef* AUDIO_MAL_DMA_CHANNEL = AUDIO_I2S_DMA_CHANNEL;
+uint32_t AUDIO_MAL_DMA_CLOCK = AUDIO_I2S_DMA_CLOCK;
+uint32_t AUDIO_MAL_DMA_DREG = AUDIO_I2S_DMA_DREG;
+uint32_t AUDIO_MAL_DMA_IRQ = AUDIO_I2S_DMA_IRQ;
+uint32_t AUDIO_MAL_DMA_FLAG_TC = AUDIO_I2S_DMA_FLAG_TC;
+uint32_t AUDIO_MAL_DMA_FLAG_HT = AUDIO_I2S_DMA_FLAG_HT;
+uint32_t AUDIO_MAL_DMA_FLAG_TE = AUDIO_I2S_DMA_FLAG_TE;
+
+
+/**
+ * @brief Set the current audio interface (I2S).
+ * @param Interface: AUDIO_INTERFACE_I2S
+ * @retval None
+ */
+void EVAL_AUDIO_SetAudioInterface(uint32_t Interface)
+{
+ CurrAudioInterface = Interface;
+
+ if (CurrAudioInterface == AUDIO_INTERFACE_I2S)
+ {
+ /* DMA Channel definitions */
+ AUDIO_MAL_DMA_CLOCK = AUDIO_I2S_DMA_CLOCK;
+ AUDIO_MAL_DMA_DREG = AUDIO_I2S_DMA_DREG;
+ AUDIO_MAL_DMA_CHANNEL = AUDIO_I2S_DMA_CHANNEL;
+ AUDIO_MAL_DMA_IRQ = AUDIO_I2S_DMA_IRQ ;
+ AUDIO_MAL_DMA_FLAG_TC = AUDIO_I2S_DMA_FLAG_TC;
+ AUDIO_MAL_DMA_FLAG_HT = AUDIO_I2S_DMA_FLAG_HT;
+ AUDIO_MAL_DMA_FLAG_TE = AUDIO_I2S_DMA_FLAG_TE;
+ }
+}
+
+/**
+ * @brief Configure the audio peripherals.
+ * @param OutputDevice: OUTPUT_DEVICE_SPEAKER, OUTPUT_DEVICE_HEADPHONE,
+ * OUTPUT_DEVICE_BOTH or OUTPUT_DEVICE_AUTO .
+ * @param Volume: Initial volume level (from 0 (Mute) to 100 (Max))
+ * @param AudioFreq: Audio frequency used to play the audio stream.
+ * @retval 0 if correct communication, else wrong communication
+ */
+uint32_t EVAL_AUDIO_Init(uint16_t OutputDevice, uint8_t Volume, uint32_t AudioFreq)
+{
+ /* Perform low layer Codec initialization */
+ if (Codec_Init(OutputDevice, VOLUME_CONVERT(Volume), AudioFreq) != 0)
+ {
+ return 1;
+ }
+ else
+ {
+ /* I2S data transfer preparation:
+ Prepare the Media to be used for the audio transfer from memory to I2S peripheral */
+ Audio_MAL_Init();
+
+ /* Return 0 when all operations are OK */
+ return 0;
+ }
+}
+
+/**
+ * @brief Deinitializes all the resources used by the codec (those initialized
+ * by EVAL_AUDIO_Init() function).
+ * @param None
+ * @retval 0 if correct communication, else wrong communication
+ */
+uint32_t EVAL_AUDIO_DeInit(void)
+{
+ /* DeInitialize the Media layer */
+ Audio_MAL_DeInit();
+
+ /* DeInitialize Codec */
+ Codec_DeInit();
+
+ return 0;
+}
+
+/**
+ * @brief Starts playing audio stream from a data buffer for a determined size.
+ * @param pBuffer: Pointer to the buffer
+ * @param Size: Number of audio data BYTES.
+ * @retval 0 if correct communication, else wrong communication
+ */
+uint32_t EVAL_AUDIO_Play(uint16_t* pBuffer, uint32_t Size)
+{
+ /* Set the total number of data to be played (count in half-word) */
+ AudioTotalSize = Size/2;
+
+ /* Call the audio Codec Play function */
+ Codec_Play();
+
+ /* Update the Media layer and enable it for play */
+ Audio_MAL_Play((uint32_t)pBuffer, (uint32_t)(DMA_MAX(AudioTotalSize / 2)));
+
+ /* Update the remaining number of data to be played */
+ AudioRemSize = (Size/2) - DMA_MAX(AudioTotalSize);
+
+ /* Update the current audio pointer position */
+ CurrentPos = pBuffer + DMA_MAX(AudioTotalSize);
+
+ return 0;
+}
+
+/**
+ * @brief This function Pauses or Resumes the audio file stream. In case
+ * of using DMA, the DMA Pause feature is used. In all cases the I2S
+ * peripheral is disabled.
+ *
+ * @WARNING When calling EVAL_AUDIO_PauseResume() function for pause, only
+ * this function should be called for resume (use of EVAL_AUDIO_Play()
+ * function for resume could lead to unexpected behavior).
+ *
+ * @param Cmd: AUDIO_PAUSE (or 0) to pause, AUDIO_RESUME (or any value different
+ * from 0) to resume.
+ * @retval 0 if correct communication, else wrong communication
+ */
+uint32_t EVAL_AUDIO_PauseResume(uint32_t Cmd)
+{
+ /* Call the Audio Codec Pause/Resume function */
+ if (Codec_PauseResume(Cmd) != 0)
+ {
+ return 1;
+ }
+ else
+ {
+ /* Call the Media layer pause/resume function */
+ Audio_MAL_PauseResume(Cmd, 0);
+
+ /* Return 0 if all operations are OK */
+ return 0;
+ }
+}
+
+/**
+ * @brief Stops audio playing and Power down the Audio Codec.
+ * @param Option: could be one of the following parameters
+ * - CODEC_PDWN_SW: for software power off (by writing registers).
+ * Then no need to reconfigure the Codec after power on.
+ * - CODEC_PDWN_HW: completely shut down the codec (physically).
+ * Then need to reconfigure the Codec after power on.
+ * @retval 0 if correct communication, else wrong communication
+ */
+uint32_t EVAL_AUDIO_Stop(uint32_t Option)
+{
+ /* Call Audio Codec Stop function */
+ if (Codec_Stop(Option) != 0)
+ {
+ return 1;
+ }
+ else
+ {
+ /* Call Media layer Stop function */
+ Audio_MAL_Stop();
+
+ /* Update the remaining data number */
+ AudioRemSize = AudioTotalSize;
+
+ /* Return 0 when all operations are correctly done */
+ return 0;
+ }
+}
+
+/**
+ * @brief Controls the current audio volume level.
+ * @param Volume: Volume level to be set in percentage from 0% to 100% (0 for
+ * Mute and 100 for Max volume level).
+ * @retval 0 if correct communication, else wrong communication
+ */
+uint32_t EVAL_AUDIO_VolumeCtl(uint8_t Volume)
+{
+ /* Call the codec volume control function with converted volume value */
+ return (Codec_VolumeCtrl(VOLUME_CONVERT(Volume)));
+}
+
+/**
+ * @brief Enables or disables the MUTE mode by software
+ * @param Command: could be AUDIO_MUTE_ON to mute sound or AUDIO_MUTE_OFF to
+ * unmute the codec and restore previous volume level.
+ * @retval 0 if correct communication, else wrong communication
+ */
+uint32_t EVAL_AUDIO_Mute(uint32_t Cmd)
+{
+ /* Call the Codec Mute function */
+ return (Codec_Mute(Cmd));
+}
+
+/**
+ * @brief This function handles main Media layer interrupt.
+ * @param None
+ * @retval 0 if correct communication, else wrong communication
+ */
+static void Audio_MAL_IRQHandler(void)
+{
+#ifndef AUDIO_MAL_MODE_NORMAL
+ uint16_t *pAddr = (uint16_t *)CurrentPos;
+ uint32_t Size = AudioRemSize;
+#endif /* AUDIO_MAL_MODE_NORMAL */
+
+#ifdef AUDIO_MAL_DMA_IT_TC_EN
+ /* Transfer complete interrupt */
+ if (DMA_GetFlagStatus(AUDIO_MAL_DMA_FLAG_TC) != RESET)
+ {
+#ifdef AUDIO_MAL_MODE_NORMAL
+ /* Check if the end of file has been reached */
+ if (AudioRemSize > 0)
+ {
+ /* Clear the Interrupt flag */
+ DMA_ClearFlag( AUDIO_MAL_DMA_FLAG_TC);
+
+ /* Re-Configure the buffer address and size */
+ DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t) CurrentPos;
+ DMA_InitStructure.DMA_BufferSize = (uint32_t) (DMA_MAX(AudioRemSize));
+
+ /* Configure the DMA Channel with the new parameters */
+ DMA_Init(AUDIO_MAL_DMA_CHANNEL, &DMA_InitStructure);
+
+ /* Enable the I2S DMA Channel*/
+ DMA_Cmd(AUDIO_MAL_DMA_CHANNEL, ENABLE);
+
+ /* Update the current pointer position */
+ CurrentPos += DMA_MAX(AudioRemSize);
+
+ /* Update the remaining number of data to be played */
+ AudioRemSize -= DMA_MAX(AudioRemSize);
+ }
+ else
+ {
+ /* Disable the I2S DMA Channel*/
+ DMA_Cmd(AUDIO_MAL_DMA_CHANNEL, DISABLE);
+
+ /* Clear the Interrupt flag */
+ DMA_ClearFlag(AUDIO_MAL_DMA_FLAG_TC);
+
+ /* Manage the remaining file size and new address offset: This function
+ should be coded by user (its prototype is already declared in stm32l152d_eval_audio_codec.h) */
+ EVAL_AUDIO_TransferComplete_CallBack((uint32_t)CurrentPos, 0);
+ }
+
+#elif defined(AUDIO_MAL_MODE_CIRCULAR)
+ /* Manage the remaining file size and new address offset: This function
+ should be coded by user (its prototype is already declared in stm32l152d_eval_audio_codec.h) */
+ EVAL_AUDIO_TransferComplete_CallBack(*pAddr, Size);
+
+ /* Clear the Interrupt flag */
+ DMA_ClearFlag(AUDIO_MAL_DMA_FLAG_TC);
+#endif /* AUDIO_MAL_MODE_NORMAL */
+ }
+#endif /* AUDIO_MAL_DMA_IT_TC_EN */
+
+#ifdef AUDIO_MAL_DMA_IT_HT_EN
+ /* Half Transfer complete interrupt */
+ if (DMA_GetFlagStatus(AUDIO_MAL_DMA_FLAG_HT) != RESET)
+ {
+ /* Manage the remaining file size and new address offset: This function
+ should be coded by user (its prototype is already declared in stm32l152d_eval_audio_codec.h) */
+ EVAL_AUDIO_HalfTransfer_CallBack((uint32_t)pAddr, Size);
+
+ /* Clear the Interrupt flag */
+ DMA_ClearFlag(AUDIO_MAL_DMA_FLAG_HT);
+ }
+#endif /* AUDIO_MAL_DMA_IT_HT_EN */
+
+#ifdef AUDIO_MAL_DMA_IT_TE_EN
+ /* FIFO Error interrupt */
+ if ((DMA_GetFlagStatus(AUDIO_MAL_DMA_FLAG_TE) != RESET))
+
+ {
+ /* Manage the error generated on DMA FIFO: This function
+ should be coded by user (its prototype is already declared in stm32l152d_eval_audio_codec.h) */
+ EVAL_AUDIO_Error_CallBack((uint32_t*)&pAddr);
+
+ /* Clear the Interrupt flag */
+ DMA_ClearFlag(AUDIO_MAL_DMA_FLAG_TE);
+ }
+#endif /* AUDIO_MAL_DMA_IT_TE_EN */
+}
+
+/**
+ * @brief This function handles main I2S interrupt.
+ * @param None
+ * @retval 0 if correct communication, else wrong communication
+ */
+void Audio_MAL_I2S_IRQHandler(void)
+{
+ Audio_MAL_IRQHandler();
+}
+
+/**
+ * @brief I2S interrupt management
+ * @param None
+ * @retval None
+ */
+void Audio_I2S_IRQHandler(void)
+{
+ EVAL_Audio_I2S_IRQHandler();
+}
+
+/*==============================================================================
+ CS43L22 Audio Codec Control Functions
+==============================================================================*/
+/**
+ * @brief Initializes the audio codec and all related interfaces (control
+ * interface: I2C and audio interface: I2S)
+ * @param OutputDevice: can be OUTPUT_DEVICE_SPEAKER, OUTPUT_DEVICE_HEADPHONE,
+ * OUTPUT_DEVICE_BOTH or OUTPUT_DEVICE_AUTO .
+ * @param Volume: Initial volume level (from 0 (Mute) to 100 (Max))
+ * @param AudioFreq: Audio frequency used to play the audio stream.
+ * @retval 0 if correct communication, else wrong communication
+ */
+static uint32_t Codec_Init(uint16_t OutputDevice, uint8_t Volume, uint32_t AudioFreq)
+{
+ uint32_t counter = 0;
+
+ /* Configure the Codec related IOs */
+ Codec_GPIO_Init();
+
+ /* Reset the Codec Registers */
+ Codec_Reset();
+
+ /* Initialize the Control interface of the Audio Codec */
+ Codec_CtrlInterface_Init();
+
+ /* Keep Codec powered OFF */
+ counter += Codec_WriteRegister(0x02, 0x01);
+
+ switch (OutputDevice)
+ {
+ case OUTPUT_DEVICE_SPEAKER:
+ counter += Codec_WriteRegister(0x04, 0xFA); /* SPK always ON & HP always OFF */
+ OutputDev = 0xFA;
+ break;
+
+ case OUTPUT_DEVICE_HEADPHONE:
+ counter += Codec_WriteRegister(0x04, 0xAF); /* SPK always OFF & HP always ON */
+ OutputDev = 0xAF;
+ break;
+
+ case OUTPUT_DEVICE_BOTH:
+ counter += Codec_WriteRegister(0x04, 0xAA); /* SPK always ON & HP always ON */
+ OutputDev = 0xAA;
+ break;
+
+ case OUTPUT_DEVICE_AUTO:
+ counter += Codec_WriteRegister(0x04, 0x05); /* Detect the HP or the SPK automatically */
+ OutputDev = 0x05;
+ break;
+
+ default:
+ counter += Codec_WriteRegister(0x04, 0x05); /* Detect the HP or the SPK automatically */
+ OutputDev = 0x05;
+ break;
+ }
+
+ /* Clock configuration: Auto detection */
+ counter += Codec_WriteRegister(0x05, 0x81);
+
+ /* Set the Slave Mode and the audio Standard */
+ counter += Codec_WriteRegister(0x06, CODEC_STANDARD);
+
+ /* Set the Master volume */
+ Codec_VolumeCtrl(Volume);
+
+ /* If the Speaker is enabled, set the Mono mode and volume attenuation level */
+ if (OutputDevice != OUTPUT_DEVICE_HEADPHONE)
+ {
+ /* Set the Speaker Mono mode */
+ counter += Codec_WriteRegister(0x0F , 0x06);
+
+ /* Set the Speaker attenuation level */
+ counter += Codec_WriteRegister(0x24, 0xF0);
+ counter += Codec_WriteRegister(0x25, 0xF0);
+ }
+
+ /* Power on the Codec */
+ counter += Codec_WriteRegister(0x02, 0x9E);
+
+ /* Configure the I2S peripheral */
+ Codec_AudioInterface_Init(AudioFreq);
+
+ /* Return communication control value */
+ return counter;
+}
+
+/**
+ * @brief Restore the audio codec state to default state and free all used
+ * resources.
+ * @param None
+ * @retval 0 if correct communication, else wrong communication
+ */
+static uint32_t Codec_DeInit(void)
+{
+ uint32_t counter = 0;
+
+ /* Reset the Codec Registers */
+ Codec_Reset();
+
+ /* Keep Codec powered OFF */
+ counter += Codec_WriteRegister(0x02, 0x01);
+
+ /* Deinitialize all use GPIOs */
+ Codec_GPIO_DeInit();
+
+ /* Disable the Codec control interface */
+ Codec_CtrlInterface_DeInit();
+
+ /* Deinitialize the Codec audio interface (I2S) */
+ Codec_AudioInterface_DeInit();
+
+ /* Return communication control value */
+ return counter;
+}
+
+/**
+ * @brief Start the audio Codec play feature.
+ * @note For this codec no Play options are required.
+ * @param None
+ * @retval 0 if correct communication, else wrong communication
+ */
+static uint32_t Codec_Play(void)
+{
+ /*
+ No actions required on Codec level for play command
+ */
+
+ /* Return communication control value */
+ return 0;
+}
+
+/**
+ * @brief Pauses and resumes playing on the audio codec.
+ * @param Cmd: AUDIO_PAUSE (or 0) to pause, AUDIO_RESUME (or any value different
+ * from 0) to resume.
+ * @retval 0 if correct communication, else wrong communication
+ */
+static uint32_t Codec_PauseResume(uint32_t Cmd)
+{
+ uint32_t counter = 0;
+
+ /* Pause the audio file playing */
+ if (Cmd == AUDIO_PAUSE)
+ {
+ /* Mute the output first */
+ counter += Codec_Mute(AUDIO_MUTE_ON);
+
+ /* Put the Codec in Power save mode */
+ counter += Codec_WriteRegister(0x02, 0x01);
+ }
+ else /* AUDIO_RESUME */
+ {
+ /* Unmute the output first */
+ counter += Codec_Mute(AUDIO_MUTE_OFF);
+
+ counter += Codec_WriteRegister(0x04, OutputDev);
+
+ /* Exit the Power save mode */
+ counter += Codec_WriteRegister(0x02, 0x9E);
+ }
+
+ return counter;
+}
+
+/**
+ * @brief Stops audio Codec playing. It powers down the codec.
+ * @param CodecPdwnMode: selects the power down mode.
+ * - CODEC_PDWN_SW: only mutes the audio codec. When resuming from this
+ * mode the codec keeps the previous initialization
+ * (no need to re-Initialize the codec registers).
+ * - CODEC_PDWN_HW: Physically power down the codec. When resuming from this
+ * mode, the codec is set to default configuration
+ * (user should re-Initialize the codec in order to
+ * play again the audio stream).
+ * @retval 0 if correct communication, else wrong communication
+ */
+static uint32_t Codec_Stop(uint32_t CodecPdwnMode)
+{
+ uint32_t counter = 0;
+
+ /* Mute the output first */
+ Codec_Mute(AUDIO_MUTE_ON);
+
+ if (CodecPdwnMode == CODEC_PDWN_SW)
+ {
+ /* Power down the speaker (PMSPK bits)*/
+ counter += Codec_WriteRegister(0x02, 0x9F);
+ }
+ else /* CODEC_PDWN_HW */
+ {
+ /* Power down the components */
+ counter += Codec_WriteRegister(0x02, 0x9F);
+
+ /* Wait at least 100us */
+ Delay(0xFFF);
+
+ /* Reset The pin */
+ GPIO_WriteBit(AUDIO_RESET_GPIO, AUDIO_RESET_PIN, Bit_RESET);
+ }
+
+ return counter;
+}
+
+/**
+ * @brief Sets higher or lower the codec volume level.
+ * @param Volume: a byte value from 0 to 255 (refer to codec registers
+ * description for more details).
+ * @retval 0 if correct communication, else wrong communication
+ */
+static uint32_t Codec_VolumeCtrl(uint8_t Volume)
+{
+ uint32_t counter = 0;
+
+ if (Volume > 0xE6)
+ {
+ /* Set the Master volume */
+ counter += Codec_WriteRegister(0x20, Volume - 0xE7);
+ counter += Codec_WriteRegister(0x21, Volume - 0xE7);
+ }
+ else
+ {
+ /* Set the Master volume */
+ counter += Codec_WriteRegister(0x20, Volume + 0x19);
+ counter += Codec_WriteRegister(0x21, Volume + 0x19);
+ }
+
+ return counter;
+}
+
+/**
+ * @brief Enables or disables the mute feature on the audio codec.
+ * @param Cmd: AUDIO_MUTE_ON to enable the mute or AUDIO_MUTE_OFF to disable the
+ * mute mode.
+ * @retval 0 if correct communication, else wrong communication
+ */
+static uint32_t Codec_Mute(uint32_t Cmd)
+{
+ uint32_t counter = 0;
+
+ /* Set the Mute mode */
+ if (Cmd == AUDIO_MUTE_ON)
+ {
+ counter += Codec_WriteRegister(0x04, 0xFF);
+ }
+ else /* AUDIO_MUTE_OFF Disable the Mute */
+ {
+ counter += Codec_WriteRegister(0x04, OutputDev);
+ }
+
+ return counter;
+}
+
+/**
+ * @brief Resets the audio codec. It restores the default configuration of the
+ * codec (this function shall be called before initializing the codec).
+ * @note This function calls an external driver function: The IO Expander driver.
+ * @param None
+ * @retval None
+ */
+static void Codec_Reset(void)
+{
+ /* Power Down the codec */
+ GPIO_WriteBit(AUDIO_RESET_GPIO, AUDIO_RESET_PIN, Bit_RESET);
+
+ /* wait for a delay to insure registers erasing */
+ Delay(CODEC_RESET_DELAY);
+
+ /* Power on the codec */
+ GPIO_WriteBit(AUDIO_RESET_GPIO, AUDIO_RESET_PIN, Bit_SET);
+}
+
+/**
+ * @brief Writes a Byte to a given register into the audio codec through the
+ * control interface (I2C)
+ * @param RegisterAddr: The address (location) of the register to be written.
+ * @param RegisterValue: the Byte value to be written into destination register.
+ * @retval 0 if correct communication, else wrong communication
+ */
+static uint32_t Codec_WriteRegister(uint8_t RegisterAddr, uint8_t RegisterValue)
+{
+ uint32_t result = 0;
+
+ /*!< While the bus is busy */
+ CODECTimeout = CODEC_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(CODEC_I2C, I2C_FLAG_BUSY))
+ {
+ if((CODECTimeout--) == 0) return Codec_TIMEOUT_UserCallback();
+ }
+
+ /* Start the config sequence */
+ I2C_GenerateSTART(CODEC_I2C, ENABLE);
+
+ /* Test on EV5 and clear it */
+ CODECTimeout = CODEC_FLAG_TIMEOUT;
+ while (!I2C_CheckEvent(CODEC_I2C, I2C_EVENT_MASTER_MODE_SELECT))
+ {
+ if((CODECTimeout--) == 0) return Codec_TIMEOUT_UserCallback();
+ }
+
+ /* Transmit the slave address and enable writing operation */
+ I2C_Send7bitAddress(CODEC_I2C, CODEC_ADDRESS, I2C_Direction_Transmitter);
+
+ /* Test on EV6 and clear it */
+ CODECTimeout = CODEC_FLAG_TIMEOUT;
+ while (!I2C_CheckEvent(CODEC_I2C, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED))
+ {
+ if((CODECTimeout--) == 0) return Codec_TIMEOUT_UserCallback();
+ }
+
+ /* Transmit the first address for write operation */
+ I2C_SendData(CODEC_I2C, RegisterAddr);
+
+ /* Test on EV8 and clear it */
+ CODECTimeout = CODEC_FLAG_TIMEOUT;
+ while (!I2C_CheckEvent(CODEC_I2C, I2C_EVENT_MASTER_BYTE_TRANSMITTING))
+ {
+ if((CODECTimeout--) == 0) return Codec_TIMEOUT_UserCallback();
+ }
+
+ /* Prepare the register value to be sent */
+ I2C_SendData(CODEC_I2C, RegisterValue);
+
+ /*!< Wait till all data have been physically transferred on the bus */
+ CODECTimeout = CODEC_LONG_TIMEOUT;
+ while(!I2C_GetFlagStatus(CODEC_I2C, I2C_FLAG_BTF))
+ {
+ if((CODECTimeout--) == 0) Codec_TIMEOUT_UserCallback();
+ }
+
+ /* End the configuration sequence */
+ I2C_GenerateSTOP(CODEC_I2C, ENABLE);
+
+#ifdef VERIFY_WRITTENDATA
+ /* Verify that the data has been correctly written */
+ result = (Codec_ReadRegister(RegisterAddr) == RegisterValue)? 0:1;
+#endif /* VERIFY_WRITTENDATA */
+
+ /* Return the verifying value: 0 (Passed) or 1 (Failed) */
+ return result;
+}
+
+/**
+ * @brief Reads and returns the value of an audio codec register through the
+ * control interface (I2C).
+ * @param RegisterAddr: Address of the register to be read.
+ * @retval Value of the register to be read or dummy value if the communication
+ * fails.
+ */
+static uint32_t Codec_ReadRegister(uint8_t RegisterAddr)
+{
+ uint32_t result = 0;
+
+ /*!< While the bus is busy */
+ CODECTimeout = CODEC_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(CODEC_I2C, I2C_FLAG_BUSY))
+ {
+ if((CODECTimeout--) == 0) return Codec_TIMEOUT_UserCallback();
+ }
+
+ /* Start the config sequence */
+ I2C_GenerateSTART(CODEC_I2C, ENABLE);
+
+ /* Test on EV5 and clear it */
+ CODECTimeout = CODEC_FLAG_TIMEOUT;
+ while (!I2C_CheckEvent(CODEC_I2C, I2C_EVENT_MASTER_MODE_SELECT))
+ {
+ if((CODECTimeout--) == 0) return Codec_TIMEOUT_UserCallback();
+ }
+
+ /* Transmit the slave address and enable writing operation */
+ I2C_Send7bitAddress(CODEC_I2C, CODEC_ADDRESS, I2C_Direction_Transmitter);
+
+ /* Test on EV6 and clear it */
+ CODECTimeout = CODEC_FLAG_TIMEOUT;
+ while (!I2C_CheckEvent(CODEC_I2C, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED))
+ {
+ if((CODECTimeout--) == 0) return Codec_TIMEOUT_UserCallback();
+ }
+
+ /* Transmit the register address to be read */
+ I2C_SendData(CODEC_I2C, RegisterAddr);
+
+ /* Test on EV8 and clear it */
+ CODECTimeout = CODEC_FLAG_TIMEOUT;
+ while (I2C_GetFlagStatus(CODEC_I2C, I2C_FLAG_BTF) == RESET)
+ {
+ if((CODECTimeout--) == 0) return Codec_TIMEOUT_UserCallback();
+ }
+
+ /*!< Send START condition a second time */
+ I2C_GenerateSTART(CODEC_I2C, ENABLE);
+
+ /*!< Test on EV5 and clear it (cleared by reading SR1 then writing to DR) */
+ CODECTimeout = CODEC_FLAG_TIMEOUT;
+ while(!I2C_CheckEvent(CODEC_I2C, I2C_EVENT_MASTER_MODE_SELECT))
+ {
+ if((CODECTimeout--) == 0) return Codec_TIMEOUT_UserCallback();
+ }
+
+ /*!< Send Codec address for read */
+ I2C_Send7bitAddress(CODEC_I2C, CODEC_ADDRESS, I2C_Direction_Receiver);
+
+ /* Wait on ADDR flag to be set (ADDR is still not cleared at this level */
+ CODECTimeout = CODEC_FLAG_TIMEOUT;
+ while(I2C_GetFlagStatus(CODEC_I2C, I2C_FLAG_ADDR) == RESET)
+ {
+ if((CODECTimeout--) == 0) return Codec_TIMEOUT_UserCallback();
+ }
+
+ /*!< Disable Acknowledgment */
+ I2C_AcknowledgeConfig(CODEC_I2C, DISABLE);
+
+ /* Clear ADDR register by reading SR1 then SR2 register (SR1 has already been read) */
+ (void)CODEC_I2C->SR2;
+
+ /*!< Send STOP Condition */
+ I2C_GenerateSTOP(CODEC_I2C, ENABLE);
+
+ /* Wait for the byte to be received */
+ CODECTimeout = CODEC_FLAG_TIMEOUT;
+ while(I2C_GetFlagStatus(CODEC_I2C, I2C_FLAG_RXNE) == RESET)
+ {
+ if((CODECTimeout--) == 0) return Codec_TIMEOUT_UserCallback();
+ }
+
+ /*!< Read the byte received from the Codec */
+ result = I2C_ReceiveData(CODEC_I2C);
+
+ /* Wait to make sure that STOP flag has been cleared */
+ CODECTimeout = CODEC_FLAG_TIMEOUT;
+ while(CODEC_I2C->CR1 & I2C_CR1_STOP)
+ {
+ if((CODECTimeout--) == 0) return Codec_TIMEOUT_UserCallback();
+ }
+
+ /*!< Re-Enable Acknowledgment to be ready for another reception */
+ I2C_AcknowledgeConfig(CODEC_I2C, ENABLE);
+
+ /* Clear AF flag for next communication */
+ I2C_ClearFlag(CODEC_I2C, I2C_FLAG_AF);
+
+ /* Return the byte read from Codec */
+ return result;
+}
+
+/**
+ * @brief Initializes the Audio Codec control interface (I2C).
+ * @param None
+ * @retval None
+ */
+static void Codec_CtrlInterface_Init(void)
+{
+ I2C_InitTypeDef I2C_InitStructure;
+
+ /* Enable the CODEC_I2C peripheral clock */
+ RCC_APB1PeriphClockCmd(CODEC_I2C_CLK, ENABLE);
+
+ /* CODEC_I2C peripheral configuration */
+ I2C_DeInit(CODEC_I2C);
+ I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
+ I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;
+ I2C_InitStructure.I2C_OwnAddress1 = 0x33;
+ I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
+ I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
+ I2C_InitStructure.I2C_ClockSpeed = I2C_SPEED;
+ /* Enable the I2C peripheral */
+ I2C_Cmd(CODEC_I2C, ENABLE);
+ I2C_Init(CODEC_I2C, &I2C_InitStructure);
+}
+
+/**
+ * @brief Restore the Audio Codec control interface to its default state.
+ * This function doesn't de-initialize the I2C because the I2C peripheral
+ * may be used by other modules.
+ * @param None
+ * @retval None
+ */
+static void Codec_CtrlInterface_DeInit(void)
+{
+ /* Disable the I2C peripheral */ /* This step is not done here because
+ the I2C interface can be used by other modules */
+ I2C_DeInit(CODEC_I2C);
+}
+
+/**
+ * @brief Initializes the Audio Codec audio interface (I2S)
+ * @note This function assumes that the I2S input clock (through PLL_R in
+ * Devices RevA/Z and through dedicated PLLI2S_R in Devices RevB/Y)
+ * is already configured and ready to be used.
+ * @param AudioFreq: Audio frequency to be configured for the I2S peripheral.
+ * @retval None
+ */
+static void Codec_AudioInterface_Init(uint32_t AudioFreq)
+{
+ I2S_InitTypeDef I2S_InitStructure;
+
+ /* Enable the CODEC_I2S peripheral clock */
+ RCC_APB1PeriphClockCmd(CODEC_I2S_CLK, ENABLE);
+
+ /* CODEC_I2S peripheral configuration */
+ SPI_I2S_DeInit(CODEC_I2S);
+ I2S_InitStructure.I2S_AudioFreq = AudioFreq;
+ I2S_InitStructure.I2S_Standard = I2S_STANDARD;
+ I2S_InitStructure.I2S_DataFormat = I2S_DataFormat_16b;
+ I2S_InitStructure.I2S_CPOL = I2S_CPOL_Low;
+
+ I2S_InitStructure.I2S_Mode = I2S_Mode_MasterTx;
+
+#ifdef CODEC_MCLK_ENABLED
+ I2S_InitStructure.I2S_MCLKOutput = I2S_MCLKOutput_Enable;
+#elif defined(CODEC_MCLK_DISABLED)
+ I2S_InitStructure.I2S_MCLKOutput = I2S_MCLKOutput_Disable;
+#else
+#error "No selection for the MCLK output has been defined !"
+#endif /* CODEC_MCLK_ENABLED */
+
+ /* Initialize the I2S peripheral with the structure above */
+ I2S_Init(CODEC_I2S, &I2S_InitStructure);
+ /* The I2S peripheral will be enabled only in the EVAL_AUDIO_Play() function
+ or by user functions if DMA mode not enabled */
+}
+
+/**
+ * @brief Restores the Audio Codec audio interface to its default state.
+ * @param None
+ * @retval None
+ */
+static void Codec_AudioInterface_DeInit(void)
+{
+ /* Disable the CODEC_I2S peripheral (in case it hasn't already been disabled) */
+ I2S_Cmd(CODEC_I2S, DISABLE);
+
+ /* Deinitialize the CODEC_I2S peripheral */
+ SPI_I2S_DeInit(CODEC_I2S);
+
+ /* Disable the CODEC_I2S peripheral clock */
+ RCC_APB1PeriphClockCmd(CODEC_I2S_CLK, DISABLE);
+}
+
+/**
+ * @brief Initializes IOs used by the Audio Codec (on the control and audio
+ * interfaces).
+ * @param None
+ * @retval None
+ */
+static void Codec_GPIO_Init(void)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+
+ /* Enable Reset GPIO Clock */
+ RCC_AHBPeriphClockCmd(AUDIO_RESET_GPIO_CLK,ENABLE);
+
+/* Audio reset pin configuration ---------------------------------------------*/
+ GPIO_InitStructure.GPIO_Pin = AUDIO_RESET_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
+ GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
+ GPIO_Init(AUDIO_RESET_GPIO, &GPIO_InitStructure);
+
+ /* Enable I2S and I2C GPIO clocks */
+ RCC_AHBPeriphClockCmd(CODEC_I2C_GPIO_CLOCK | CODEC_I2S_GPIO_CLOCK, ENABLE);
+
+/* CODEC_I2C SCL and SDA pins configuration ----------------------------------*/
+ GPIO_InitStructure.GPIO_Pin = CODEC_I2C_SCL_PIN | CODEC_I2C_SDA_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
+ GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
+ GPIO_Init(CODEC_I2C_GPIO, &GPIO_InitStructure);
+ /* Connect pins to I2C peripheral */
+ GPIO_PinAFConfig(CODEC_I2C_GPIO, CODEC_I2S_SCL_PINSRC, CODEC_I2C_GPIO_AF);
+ GPIO_PinAFConfig(CODEC_I2C_GPIO, CODEC_I2S_SDA_PINSRC, CODEC_I2C_GPIO_AF);
+
+/* CODEC_I2S pins configuration: WS, SCK and SD pins -------------------------*/
+ GPIO_InitStructure.GPIO_Pin = CODEC_I2S_SCK_PIN |
+ CODEC_I2S_SD_PIN |
+ CODEC_I2S_WS_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
+ GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
+ GPIO_Init(CODEC_I2S_GPIO, &GPIO_InitStructure);
+
+ /* Connect pins to I2S peripheral */
+ GPIO_PinAFConfig(CODEC_I2S_GPIO, CODEC_I2S_WS_PINSRC, CODEC_I2S_GPIO_AF);
+ GPIO_PinAFConfig(CODEC_I2S_GPIO, CODEC_I2S_SCK_PINSRC, CODEC_I2S_GPIO_AF);
+ GPIO_PinAFConfig(CODEC_I2S_GPIO, CODEC_I2S_SD_PINSRC, CODEC_I2S_GPIO_AF);
+
+#ifdef CODEC_MCLK_ENABLED
+ /* CODEC_I2S pins configuration: MCK pin */
+ GPIO_InitStructure.GPIO_Pin = CODEC_I2S_MCK_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
+ GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
+ GPIO_Init(CODEC_I2S_MCK_GPIO, &GPIO_InitStructure);
+ /* Connect pins to I2S peripheral */
+ GPIO_PinAFConfig(CODEC_I2S_MCK_GPIO, CODEC_I2S_MCK_PINSRC, CODEC_I2S_GPIO_AF);
+#endif /* CODEC_MCLK_ENABLED */
+}
+
+/**
+ * @brief Restores the IOs used by the Audio Codec interface to their default state.
+ * @param None
+ * @retval None
+ */
+static void Codec_GPIO_DeInit(void)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+
+ /* Deinitialize all the GPIOs used by the driver */
+ GPIO_InitStructure.GPIO_Pin = CODEC_I2S_SCK_PIN | CODEC_I2S_SD_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
+ GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
+ GPIO_Init(CODEC_I2S_GPIO, &GPIO_InitStructure);
+
+ GPIO_InitStructure.GPIO_Pin = CODEC_I2S_WS_PIN;
+ GPIO_Init(CODEC_I2S_GPIO, &GPIO_InitStructure);
+
+ /* Disconnect pins from I2S peripheral */
+ GPIO_PinAFConfig(CODEC_I2S_GPIO, CODEC_I2S_WS_PINSRC, 0x00);
+ GPIO_PinAFConfig(CODEC_I2S_GPIO, CODEC_I2S_SCK_PINSRC, 0x00);
+ GPIO_PinAFConfig(CODEC_I2S_GPIO, CODEC_I2S_SD_PINSRC, 0x00);
+
+#ifdef CODEC_MCLK_ENABLED
+ /* CODEC_I2S pins deinitialization: MCK pin */
+ GPIO_InitStructure.GPIO_Pin = CODEC_I2S_MCK_PIN;
+ GPIO_Init(CODEC_I2S_MCK_GPIO, &GPIO_InitStructure);
+ /* Disconnect pins from I2S peripheral */
+ GPIO_PinAFConfig(CODEC_I2S_MCK_GPIO, CODEC_I2S_MCK_PINSRC, CODEC_I2S_GPIO_AF);
+#endif /* CODEC_MCLK_ENABLED */
+}
+
+/**
+ * @brief Inserts a delay time (not accurate timing).
+ * @param nCount: specifies the delay time length.
+ * @retval None
+ */
+static void Delay( __IO uint32_t nCount)
+{
+ for (; nCount != 0; nCount--);
+}
+
+#ifdef USE_DEFAULT_TIMEOUT_CALLBACK
+/**
+ * @brief Basic management of the timeout situation.
+ * @param None
+ * @retval None
+ */
+uint32_t Codec_TIMEOUT_UserCallback(void)
+{
+ /* Block communication and all processes */
+ while (1)
+ {
+ }
+}
+#endif /* USE_DEFAULT_TIMEOUT_CALLBACK */
+
+/*==============================================================================
+ Audio MAL Interface Control Functions
+==============================================================================*/
+
+/**
+ * @brief Initializes and prepares the Media to perform audio data transfer
+ * from Media to the I2S peripheral.
+ * @param None
+ * @retval None
+ */
+static void Audio_MAL_Init(void)
+{
+
+#ifdef I2S_INTERRUPT
+ NVIC_InitTypeDef NVIC_InitStructure;
+
+ NVIC_InitStructure.NVIC_IRQChannel = CODEC_I2S_IRQ;
+ NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
+ NVIC_InitStructure.NVIC_IRQChannelSubPriority =0;
+ NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
+ NVIC_Init(&NVIC_InitStructure);
+
+ SPI_I2S_ITConfig(CODEC_I2S, SPI_I2S_IT_TXE, ENABLE);
+
+#else
+#if defined(AUDIO_MAL_DMA_IT_TC_EN) || defined(AUDIO_MAL_DMA_IT_HT_EN) || defined(AUDIO_MAL_DMA_IT_TE_EN)
+ NVIC_InitTypeDef NVIC_InitStructure;
+#endif
+
+ if (CurrAudioInterface == AUDIO_INTERFACE_I2S)
+ {
+ /* Enable the DMA clock */
+ RCC_AHBPeriphClockCmd(AUDIO_I2S_DMA_CLOCK, ENABLE);
+
+ /* Configure the DMA Channel */
+ DMA_Cmd(AUDIO_MAL_DMA_CHANNEL, DISABLE);
+ DMA_DeInit(AUDIO_MAL_DMA_CHANNEL);
+ /* Set the parameters to be configured */
+ DMA_InitStructure.DMA_PeripheralBaseAddr = AUDIO_MAL_DMA_DREG;
+ DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)0; /* This field will be configured in play function */
+ DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
+ DMA_InitStructure.DMA_BufferSize = (uint32_t)0xFFFE; /* This field will be configured in play function */
+ DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
+ DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
+ DMA_InitStructure.DMA_PeripheralDataSize = AUDIO_MAL_DMA_PERIPH_DATA_SIZE;
+ DMA_InitStructure.DMA_MemoryDataSize = AUDIO_MAL_DMA_MEM_DATA_SIZE;
+#ifdef AUDIO_MAL_MODE_NORMAL
+ DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
+#elif defined(AUDIO_MAL_MODE_CIRCULAR)
+ DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
+#else
+#error "AUDIO_MAL_MODE_NORMAL or AUDIO_MAL_MODE_CIRCULAR should be selected !!"
+#endif /* AUDIO_MAL_MODE_NORMAL */
+ DMA_InitStructure.DMA_Priority = DMA_Priority_High;
+ DMA_Init(AUDIO_MAL_DMA_CHANNEL, &DMA_InitStructure);
+
+ /* Enable the selected DMA interrupts (selected in "stm32l152d_eval_eval_audio_codec.h" defines) */
+#ifdef AUDIO_MAL_DMA_IT_TC_EN
+ DMA_ITConfig(AUDIO_MAL_DMA_CHANNEL, DMA_IT_TC, ENABLE);
+#endif /* AUDIO_MAL_DMA_IT_TC_EN */
+#ifdef AUDIO_MAL_DMA_IT_HT_EN
+ DMA_ITConfig(AUDIO_MAL_DMA_CHANNEL, DMA_IT_HT, ENABLE);
+#endif /* AUDIO_MAL_DMA_IT_HT_EN */
+#ifdef AUDIO_MAL_DMA_IT_TE_EN
+ DMA_ITConfig(AUDIO_MAL_DMA_CHANNEl, DMA_IT_TE | DMA_IT_FE | DMA_IT_DME, ENABLE);
+#endif /* AUDIO_MAL_DMA_IT_TE_EN */
+
+#if defined(AUDIO_MAL_DMA_IT_TC_EN) || defined(AUDIO_MAL_DMA_IT_HT_EN) || defined(AUDIO_MAL_DMA_IT_TE_EN)
+ /* I2S DMA IRQ Channel configuration */
+ NVIC_InitStructure.NVIC_IRQChannel = AUDIO_MAL_DMA_IRQ;
+ NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = EVAL_AUDIO_IRQ_PREPRIO;
+ NVIC_InitStructure.NVIC_IRQChannelSubPriority = EVAL_AUDIO_IRQ_SUBRIO;
+ NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
+ NVIC_Init(&NVIC_InitStructure);
+#endif
+ }
+
+ if (CurrAudioInterface == AUDIO_INTERFACE_I2S)
+ {
+ /* Enable the I2S DMA request */
+ SPI_I2S_DMACmd(CODEC_I2S, SPI_I2S_DMAReq_Tx, ENABLE);
+ }
+#endif
+}
+
+/**
+ * @brief Restore default state of the used Media.
+ * @param None
+ * @retval None
+ */
+static void Audio_MAL_DeInit(void)
+{
+#if defined(AUDIO_MAL_DMA_IT_TC_EN) || defined(AUDIO_MAL_DMA_IT_HT_EN) || defined(AUDIO_MAL_DMA_IT_TE_EN)
+ NVIC_InitTypeDef NVIC_InitStructure;
+
+ /* Deinitialize the NVIC interrupt for the I2S DMA Channel */
+ NVIC_InitStructure.NVIC_IRQChannel = AUDIO_MAL_DMA_IRQ;
+ NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = EVAL_AUDIO_IRQ_PREPRIO;
+ NVIC_InitStructure.NVIC_IRQChannelSubPriority = EVAL_AUDIO_IRQ_SUBRIO;
+ NVIC_InitStructure.NVIC_IRQChannelCmd = DISABLE;
+ NVIC_Init(&NVIC_InitStructure);
+#endif
+
+ /* Disable the DMA channel before the deinit */
+ DMA_Cmd(AUDIO_MAL_DMA_CHANNEL, DISABLE);
+
+ /* Dinitialize the DMA Channel */
+ DMA_DeInit(AUDIO_MAL_DMA_CHANNEL);
+
+ /*
+ The DMA clock is not disabled, since it can be used by other channels
+ */
+}
+
+/**
+ * @brief Starts playing audio stream from the audio Media.
+ * @param None
+ * @retval None
+ */
+static void Audio_MAL_Play(uint32_t Addr, uint32_t Size)
+{
+#ifndef I2S_INTERRUPT
+ if (CurrAudioInterface == AUDIO_INTERFACE_I2S)
+ {
+ /* Configure the buffer address and size */
+ DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)Addr;
+ DMA_InitStructure.DMA_BufferSize = (uint32_t)Size;
+
+ /* Configure the DMA Channel with the new parameters */
+ DMA_Init(AUDIO_MAL_DMA_CHANNEL, &DMA_InitStructure);
+
+ /* Enable the I2S DMA Channel*/
+ DMA_Cmd(AUDIO_MAL_DMA_CHANNEL, ENABLE);
+ }
+#else
+ /* If the I2S peripheral is still not enabled, enable it */
+ if ((CODEC_I2S->I2SCFGR & I2S_ENABLE_MASK) == 0)
+ {
+ I2S_Cmd(CODEC_I2S, ENABLE);
+ }
+#endif /* I2S_INTERRUPT */
+}
+
+/**
+ * @brief Switch dynamically (while audio file is played) the output target
+ * (speaker or headphone).
+ * @note This function modifies a global variable of the audio codec driver: OutputDev.
+ * @param Output: specifies the audio output target: OUTPUT_DEVICE_SPEAKER,
+ * OUTPUT_DEVICE_HEADPHONE, OUTPUT_DEVICE_BOTH or OUTPUT_DEVICE_AUTO
+ * @retval 0 if correct communication, else wrong communication
+ */
+uint32_t Codec_SwitchOutput(uint8_t Output)
+{
+ uint8_t counter = 0;
+
+ switch (Output)
+ {
+ case OUTPUT_DEVICE_SPEAKER:
+ counter += Codec_WriteRegister(0x04, 0xFA); /* SPK always ON & HP always OFF */
+ OutputDev = 0xFA;
+ break;
+
+ case OUTPUT_DEVICE_HEADPHONE:
+ counter += Codec_WriteRegister(0x04, 0xAF); /* SPK always OFF & HP always ON */
+ OutputDev = 0xAF;
+ break;
+
+ case OUTPUT_DEVICE_BOTH:
+ counter += Codec_WriteRegister(0x04, 0xAA); /* SPK always ON & HP always ON */
+ OutputDev = 0xAA;
+ break;
+
+ case OUTPUT_DEVICE_AUTO:
+ counter += Codec_WriteRegister(0x04, 0x05); /* Detect the HP or the SPK automatically */
+ OutputDev = 0x05;
+ break;
+
+ default:
+ counter += Codec_WriteRegister(0x04, 0x05); /* Detect the HP or the SPK automatically */
+ OutputDev = 0x05;
+ break;
+ }
+
+ return counter;
+}
+
+/**
+ * @brief Pauses or Resumes the audio stream playing from the Media.
+ * @param Cmd: AUDIO_PAUSE (or 0) to pause, AUDIO_RESUME (or any value different
+ * from 0) to resume.
+ * @param Addr: Address from/at which the audio stream should resume/pause.
+ * @retval None
+ */
+static void Audio_MAL_PauseResume(uint32_t Cmd, uint32_t Addr)
+{
+ /* Pause the audio file playing */
+ if (Cmd == AUDIO_PAUSE)
+ {
+ /* Disable the I2S DMA request */
+ SPI_I2S_DMACmd(CODEC_I2S, SPI_I2S_DMAReq_Tx, DISABLE);
+
+ /* Pause the I2S DMA Channel
+ Note. For the STM32L1xx devices, the DMA implements a pause feature,
+ by disabling the Channel, all configuration is preserved and data
+ transfer is paused till the next enable of the Channel.
+ This feature is not available on STM32L1xx devices. */
+ DMA_Cmd(AUDIO_MAL_DMA_CHANNEL, DISABLE);
+ }
+ else /* AUDIO_RESUME */
+ {
+ /* Enable the I2S DMA request */
+ SPI_I2S_DMACmd(CODEC_I2S, SPI_I2S_DMAReq_Tx, ENABLE);
+
+ /* Resume the I2S DMA Channel
+ Note. For the STM32L1xx devices, the DMA implements a pause feature,
+ by disabling the channel, all configuration is preserved and data
+ transfer is paused till the next enable of the channel.
+ This feature is not available on STM32L1xx devices. */
+ DMA_Cmd(AUDIO_MAL_DMA_CHANNEL, ENABLE);
+
+ /* If the I2S peripheral is still not enabled, enable it */
+ if ((CODEC_I2S->I2SCFGR & I2S_ENABLE_MASK) == 0)
+ {
+ I2S_Cmd(CODEC_I2S, ENABLE);
+ }
+ }
+}
+
+/**
+ * @brief Stops audio stream playing on the used Media.
+ * @param None
+ * @retval None
+ */
+static void Audio_MAL_Stop(void)
+{
+ /* Stop the Transfer on the I2S side: Stop and disable the DMA channel */
+ DMA_Cmd(AUDIO_MAL_DMA_CHANNEL, DISABLE);
+
+ /* Clear all the DMA flags for the next transfer */
+ DMA_ClearFlag(AUDIO_MAL_DMA_FLAG_TC |AUDIO_MAL_DMA_FLAG_HT | AUDIO_MAL_DMA_FLAG_TE);
+
+ /*
+ The I2S DMA requests are not disabled here.
+ */
+ /* In all modes, disable the I2S peripheral */
+ I2S_Cmd(CODEC_I2S, DISABLE);
+}
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval_audio_codec.h b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval_audio_codec.h
new file mode 100644
index 0000000..cb808e9
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval_audio_codec.h
@@ -0,0 +1,283 @@
+/**
+ ******************************************************************************
+ * @file stm32l152d_eval_audio_codec.h
+ * @author MCD Application Team
+ * @version V1.0.1
+ * @date 09-March-2012
+ * @brief This file contains all the functions prototypes for the
+ * stm32l152d_eval_audio_codec.c driver.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.st.com/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __STM32L152D_EVAL_AUDIOCODEC_H
+#define __STM32L152D_EVAL_AUDIOCODEC_H
+
+/* Includes ------------------------------------------------------------------*/
+#include "stm32l1xx.h"
+
+/** @addtogroup Utilities
+ * @{
+ */
+
+/** @addtogroup STM32_EVAL
+ * @{
+ */
+
+/** @addtogroup STM32L152D_EVAL
+ * @{
+ */
+
+/** @addtogroup STM32L152D_EVAL_AUDIO_CODEC
+ * @{
+ */
+
+/** @defgroup STM32L152D_EVAL_AUDIO_CODEC_Exported_Constants
+ * @{
+ */
+
+/*------------------------------------
+ CONFIGURATION: Audio Codec Driver Configuration parameters
+ ----------------------------------------*/
+#define I2S_INTERRUPT /* Comment this line to enable the DMA Handler */
+/* Audio Transfer mode (DMA, Interrupt or Polling) */
+#define AUDIO_MAL_MODE_NORMAL /* Uncomment this line to enable the audio
+ Transfer using DMA with normal mode */
+/* #define AUDIO_MAL_MODE_CIRCULAR */ /* Uncomment this line to enable the audio
+ Transfer using DMA with circular mode */
+
+/* For the DMA modes select the interrupt that will be used */
+#define AUDIO_MAL_DMA_IT_TC_EN /* Uncomment this line to enable DMA Transfer Complete interrupt */
+/* #define AUDIO_MAL_DMA_IT_HT_EN */ /* Uncomment this line to enable DMA Half Transfer Complete interrupt */
+/* #define AUDIO_MAL_DMA_IT_TE_EN */ /* Uncomment this line to enable DMA Transfer Error interrupt */
+
+/* Select the interrupt preemption priority and subpriority for the DMA interrupt */
+#define EVAL_AUDIO_IRQ_PREPRIO 0 /* Select the preemption priority level(0 is the highest) */
+#define EVAL_AUDIO_IRQ_SUBRIO 0 /* Select the sub-priority level (0 is the highest) */
+
+/* Uncomment the following line to use the default Codec_TIMEOUT_UserCallback()
+ function implemented in stm32l152d_eval_audio_codec.c file.
+ Codec_TIMEOUT_UserCallback() function is called whenever a timeout condition
+ occurs during communication (waiting on an event that doesn't occur, bus
+ errors, busy devices ...). */
+/* #define USE_DEFAULT_TIMEOUT_CALLBACK */
+
+/*----------------------------------------------------------------------------*/
+
+/*------------------------------------
+ OPTIONAL Configuration defines parameters
+ ----------------------------------------*/
+/* I2C clock speed configuration (in Hz)
+ WARNING:
+ Make sure that this define is not already declared in other files (ie.
+ stm32l152d_eval.h file). It can be used in parallel by other modules. */
+#ifndef I2C_SPEED
+ #define I2C_SPEED 100000
+#endif /* I2C_SPEED */
+
+/* Uncomment defines below to select standard for audio communication between
+ Codec and I2S peripheral */
+#define I2S_STANDARD_PHILLIPS
+/* #define I2S_STANDARD_MSB */
+/* #define I2S_STANDARD_LSB */
+
+/* Uncomment the defines below to select if the Master clock mode should be
+ enabled or not */
+#define CODEC_MCLK_ENABLED
+/* #define CODEC_MCLK_DISABLED */
+
+/* Uncomment this line to enable verifying data sent to codec after each write
+ operation */
+#define VERIFY_WRITTENDATA
+/*----------------------------------------------------------------------------*/
+
+/*-----------------------------------
+ Hardware Configuration defines parameters
+ -----------------------------------------*/
+/* Audio Reset Pin definition */
+#define AUDIO_RESET_GPIO_CLK RCC_AHBPeriph_GPIOB
+#define AUDIO_RESET_PIN GPIO_Pin_1
+#define AUDIO_RESET_GPIO GPIOB
+
+/* I2S peripheral configuration defines */
+#define CODEC_I2S SPI2
+#define CODEC_I2S_CLK RCC_APB1Periph_SPI2
+#define CODEC_I2S_ADDRESS 0x4000380C
+#define CODEC_I2S_GPIO_AF GPIO_AF_SPI2
+#define CODEC_I2S_IRQ SPI2_IRQn
+#define CODEC_I2S_GPIO_CLOCK (RCC_AHBPeriph_GPIOC | RCC_AHBPeriph_GPIOB)
+#define CODEC_I2S_WS_PIN GPIO_Pin_12
+#define CODEC_I2S_SCK_PIN GPIO_Pin_13
+#define CODEC_I2S_SD_PIN GPIO_Pin_15
+#define CODEC_I2S_MCK_PIN GPIO_Pin_6
+#define CODEC_I2S_WS_PINSRC GPIO_PinSource12
+#define CODEC_I2S_SCK_PINSRC GPIO_PinSource13
+#define CODEC_I2S_SD_PINSRC GPIO_PinSource15
+#define CODEC_I2S_MCK_PINSRC GPIO_PinSource6
+#define CODEC_I2S_GPIO GPIOB
+#define CODEC_I2S_MCK_GPIO GPIOC
+#define Audio_I2S_IRQHandler SPI2_IRQHandler
+
+
+#define AUDIO_MAL_DMA_PERIPH_DATA_SIZE DMA_PeripheralDataSize_HalfWord
+#define AUDIO_MAL_DMA_MEM_DATA_SIZE DMA_MemoryDataSize_HalfWord
+#define DMA_MAX_SZE 0xFFFF
+
+ /* I2S DMA Channel definitions */
+#define AUDIO_I2S_DMA_CLOCK RCC_AHBPeriph_DMA1
+#define AUDIO_I2S_DMA_DREG CODEC_I2S_ADDRESS
+#define AUDIO_I2S_DMA_CHANNEL DMA1_Channel5
+#define AUDIO_I2S_DMA_IRQ DMA1_Channel5_IRQn
+#define AUDIO_I2S_DMA_FLAG_TC DMA1_FLAG_TC5
+#define AUDIO_I2S_DMA_FLAG_HT DMA1_FLAG_HT5
+#define AUDIO_I2S_DMA_FLAG_TE DMA1_FLAG_TE5
+
+#define Audio_MAL_I2S_IRQHandler DMA1_Channel5_IRQHandler
+
+/* I2C peripheral configuration defines (control interface of the audio codec) */
+#define CODEC_I2C I2C1
+#define CODEC_I2C_CLK RCC_APB1Periph_I2C1
+#define CODEC_I2C_GPIO_CLOCK RCC_AHBPeriph_GPIOB
+#define CODEC_I2C_GPIO_AF GPIO_AF_I2C1
+#define CODEC_I2C_GPIO GPIOB
+#define CODEC_I2C_SCL_PIN GPIO_Pin_8
+#define CODEC_I2C_SDA_PIN GPIO_Pin_9
+#define CODEC_I2S_SCL_PINSRC GPIO_PinSource8
+#define CODEC_I2S_SDA_PINSRC GPIO_PinSource9
+
+/* Maximum Timeout values for flags and events waiting loops. These timeouts are
+ not based on accurate values, they just guarantee that the application will
+ not remain stuck if the I2C communication is corrupted.
+ You may modify these timeout values depending on CPU frequency and application
+ conditions (interrupts routines ...). */
+#define CODEC_FLAG_TIMEOUT ((uint32_t)0x1000)
+#define CODEC_LONG_TIMEOUT ((uint32_t)(300 * CODEC_FLAG_TIMEOUT))
+/*----------------------------------------------------------------------------*/
+
+/*-----------------------------------
+ Audio Codec User defines
+ -----------------------------------------*/
+/* Audio interface : I2S */
+#define AUDIO_INTERFACE_I2S 1
+
+/* Codec output DEVICE */
+#define OUTPUT_DEVICE_SPEAKER 1
+#define OUTPUT_DEVICE_HEADPHONE 2
+#define OUTPUT_DEVICE_BOTH 3
+#define OUTPUT_DEVICE_AUTO 4
+
+/* Volume Levels values */
+#define DEFAULT_VOLMIN 0x00
+#define DEFAULT_VOLMAX 0xFF
+#define DEFAULT_VOLSTEP 0x04
+
+#define AUDIO_PAUSE 0
+#define AUDIO_RESUME 1
+
+/* Codec POWER DOWN modes */
+#define CODEC_PDWN_HW 1
+#define CODEC_PDWN_SW 2
+
+/* MUTE commands */
+#define AUDIO_MUTE_ON 1
+#define AUDIO_MUTE_OFF 0
+/*----------------------------------------------------------------------------*/
+
+/**
+ * @}
+ */
+
+/** @defgroup STM32L152D_EVAL_AUDIO_CODEC_Exported_Macros
+ * @{
+ */
+#define VOLUME_CONVERT(x) ((Volume > 100)? 100:((uint8_t)((Volume * 255) / 100)))
+#define DMA_MAX(x) (((x) <= DMA_MAX_SZE)? (x):DMA_MAX_SZE)
+
+/**
+ * @}
+ */
+
+/** @defgroup STM32L152D_EVAL_AUDIO_CODEC_Exported_Functions
+ * @{
+ */
+void EVAL_AUDIO_SetAudioInterface(uint32_t Interface);
+uint32_t EVAL_AUDIO_Init(uint16_t OutputDevice, uint8_t Volume, uint32_t AudioFreq);
+uint32_t EVAL_AUDIO_DeInit(void);
+uint32_t EVAL_AUDIO_Play(uint16_t* pBuffer, uint32_t Size);
+uint32_t EVAL_AUDIO_PauseResume(uint32_t Cmd);
+uint32_t EVAL_AUDIO_Stop(uint32_t CodecPowerDown_Mode);
+uint32_t EVAL_AUDIO_VolumeCtl(uint8_t Volume);
+uint32_t EVAL_AUDIO_Mute(uint32_t Command);
+uint32_t Codec_SwitchOutput(uint8_t Output) ;
+
+/* User Callbacks: user has to implement these functions in his code if
+ they are needed. -----------------------------------------------------------*/
+
+extern uint16_t EVAL_AUDIO_GetSampleCallBack(void);
+
+/* User I2S IrqnHandler : user has to implement these functions in his code if
+ they are needed. -----------------------------------------------------------*/
+extern void EVAL_Audio_I2S_IRQHandler(void);
+
+
+/* This function is called when the requested data has been completely transferred.
+ In Normal mode (when the define AUDIO_MAL_MODE_NORMAL is enabled) this function
+ is called at the end of the whole audio file.
+ In circular mode (when the define AUDIO_MAL_MODE_CIRCULAR is enabled) this
+ function is called at the end of the current buffer transmission. */
+void EVAL_AUDIO_TransferComplete_CallBack(uint32_t pBuffer, uint32_t Size);
+
+/* This function is called when half of the requested buffer has been transferred
+ This callback is useful in Circular mode only (when AUDIO_MAL_MODE_CIRCULAR
+ define is enabled)*/
+void EVAL_AUDIO_HalfTransfer_CallBack(uint32_t pBuffer, uint32_t Size);
+
+/* This function is called when an Interrupt due to transfer error on or peripheral
+ error occurs. */
+void EVAL_AUDIO_Error_CallBack(void* pData);
+
+/* Codec_TIMEOUT_UserCallback() function is called whenever a timeout condition
+ occurs during communication (waiting on an event that doesn't occur, bus
+ errors, busy devices ...) on the Codec control interface (I2C).
+ You can use the default timeout callback implementation by uncommenting the
+ define USE_DEFAULT_TIMEOUT_CALLBACK in stm32l152d_eval_audio_codec.h file.
+ Typically the user implementation of this callback should reset I2C peripheral
+ and re-initialize communication or in worst case reset all the application. */
+uint32_t Codec_TIMEOUT_UserCallback(void);
+
+#endif /* __STM32L152D_EVAL_AUDIOCODEC_H */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval_fsmc_nor.c b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval_fsmc_nor.c
new file mode 100644
index 0000000..9d6484f
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval_fsmc_nor.c
@@ -0,0 +1,535 @@
+/**
+ ******************************************************************************
+ * @file stm32l152d_eval_fsmc_nor.c
+ * @author MCD Application Team
+ * @version V1.0.1
+ * @date 09-March-2012
+ * @brief This file provides a set of functions needed to drive the M29W128FL,
+ * M29W128GL and S29GL128P NOR memories mounted on STM32L152D-EVAL board.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.st.com/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+
+/* Includes ------------------------------------------------------------------*/
+#include "stm32l152d_eval_fsmc_nor.h"
+
+/** @addtogroup Utilities
+ * @{
+ */
+
+/** @addtogroup STM32_EVAL
+ * @{
+ */
+
+/** @addtogroup STM32L152D_EVAL
+ * @{
+ */
+
+/** @addtogroup STM32L152D_EVAL_FSMC_NOR
+ * @brief This file provides a set of functions needed to drive the M29W128FL,
+ * M29W128GL and S29GL128P NOR memories mounted on STM32L152D-EVAL board.
+ * @{
+ */
+
+/** @defgroup STM32L152D_EVAL_FSMC_NOR_Private_Types
+ * @{
+ */
+/**
+ * @}
+ */
+
+/** @defgroup STM32L152D_EVAL_FSMC_NOR_Private_Defines
+ * @{
+ */
+/**
+ * @brief FSMC Bank 1 NOR/SRAM2
+ */
+#define Bank1_NOR2_ADDR ((uint32_t)0x64000000)
+
+/* Delay definition */
+#define BlockErase_Timeout ((uint32_t)0x00A00000)
+#define ChipErase_Timeout ((uint32_t)0x30000000)
+#define Program_Timeout ((uint32_t)0x00001400)
+/**
+ * @}
+ */
+
+
+/** @defgroup STM32L152D_EVAL_FSMC_NOR_Private_Macros
+ * @{
+ */
+#define ADDR_SHIFT(A) (Bank1_NOR2_ADDR + (2 * (A)))
+#define NOR_WRITE(Address, Data) (*(__IO uint16_t *)(Address) = (Data))
+/**
+ * @}
+ */
+
+
+/** @defgroup STM32L152D_EVAL_FSMC_NOR_Private_Variables
+ * @{
+ */
+/**
+ * @}
+ */
+
+
+/** @defgroupSTM32L152D_EVAL_FSMC_NOR_Private_Function_Prototypes
+ * @{
+ */
+/**
+ * @}
+ */
+
+
+/** @defgroup STM32L152D_EVAL_FSMC_NOR_Private_Functions
+ * @{
+ */
+
+/**
+ * @brief Configures the FSMC and GPIOs to interface with the NOR memory.
+ * This function must be called before any write/read operation
+ * on the NOR.
+ * @param None
+ * @retval None
+ */
+void NOR_Init(void)
+{
+ FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure;
+ FSMC_NORSRAMTimingInitTypeDef p;
+
+ GPIO_InitTypeDef GPIO_InitStructure;
+
+ /* Enable GPIOD, GPIOE, GPIOF and GPIOG clocks */
+ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOD | RCC_AHBPeriph_GPIOE | RCC_AHBPeriph_GPIOF |
+ RCC_AHBPeriph_GPIOG, ENABLE);
+
+/*-- GPIO Configuration ------------------------------------------------------*/
+ /*!< NOR Data lines configuration */
+ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_8 | GPIO_Pin_9 |
+ GPIO_Pin_10 | GPIO_Pin_14 | GPIO_Pin_15;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
+ GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
+ GPIO_Init(GPIOD, &GPIO_InitStructure);
+
+ GPIO_PinAFConfig(GPIOD, GPIO_PinSource0, GPIO_AF_FSMC);
+ GPIO_PinAFConfig(GPIOD, GPIO_PinSource1, GPIO_AF_FSMC);
+ GPIO_PinAFConfig(GPIOD, GPIO_PinSource8, GPIO_AF_FSMC);
+ GPIO_PinAFConfig(GPIOD, GPIO_PinSource9, GPIO_AF_FSMC);
+ GPIO_PinAFConfig(GPIOD, GPIO_PinSource10, GPIO_AF_FSMC);
+ GPIO_PinAFConfig(GPIOD, GPIO_PinSource14, GPIO_AF_FSMC);
+ GPIO_PinAFConfig(GPIOD, GPIO_PinSource15, GPIO_AF_FSMC);
+
+ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 |
+ GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 |
+ GPIO_Pin_15;
+ GPIO_Init(GPIOE, &GPIO_InitStructure);
+
+ GPIO_PinAFConfig(GPIOE, GPIO_PinSource7 , GPIO_AF_FSMC);
+ GPIO_PinAFConfig(GPIOE, GPIO_PinSource8 , GPIO_AF_FSMC);
+ GPIO_PinAFConfig(GPIOE, GPIO_PinSource9 , GPIO_AF_FSMC);
+ GPIO_PinAFConfig(GPIOE, GPIO_PinSource10 , GPIO_AF_FSMC);
+ GPIO_PinAFConfig(GPIOE, GPIO_PinSource11 , GPIO_AF_FSMC);
+ GPIO_PinAFConfig(GPIOE, GPIO_PinSource12 , GPIO_AF_FSMC);
+ GPIO_PinAFConfig(GPIOE, GPIO_PinSource13 , GPIO_AF_FSMC);
+ GPIO_PinAFConfig(GPIOE, GPIO_PinSource14 , GPIO_AF_FSMC);
+ GPIO_PinAFConfig(GPIOE, GPIO_PinSource15 , GPIO_AF_FSMC);
+
+ /*!< NOR Address lines configuration */
+ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 |
+ GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_12 | GPIO_Pin_13 |
+ GPIO_Pin_14 | GPIO_Pin_15;
+ GPIO_Init(GPIOF, &GPIO_InitStructure);
+ GPIO_PinAFConfig(GPIOF, GPIO_PinSource0, GPIO_AF_FSMC);
+ GPIO_PinAFConfig(GPIOF, GPIO_PinSource1, GPIO_AF_FSMC);
+ GPIO_PinAFConfig(GPIOF, GPIO_PinSource2, GPIO_AF_FSMC);
+ GPIO_PinAFConfig(GPIOF, GPIO_PinSource3, GPIO_AF_FSMC);
+ GPIO_PinAFConfig(GPIOF, GPIO_PinSource4, GPIO_AF_FSMC);
+ GPIO_PinAFConfig(GPIOF, GPIO_PinSource5, GPIO_AF_FSMC);
+ GPIO_PinAFConfig(GPIOF, GPIO_PinSource12, GPIO_AF_FSMC);
+ GPIO_PinAFConfig(GPIOF, GPIO_PinSource13, GPIO_AF_FSMC);
+ GPIO_PinAFConfig(GPIOF, GPIO_PinSource14, GPIO_AF_FSMC);
+ GPIO_PinAFConfig(GPIOF, GPIO_PinSource15, GPIO_AF_FSMC);
+
+ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 |
+ GPIO_Pin_4 | GPIO_Pin_5;
+ GPIO_Init(GPIOG, &GPIO_InitStructure);
+ GPIO_PinAFConfig(GPIOG, GPIO_PinSource0, GPIO_AF_FSMC);
+ GPIO_PinAFConfig(GPIOG, GPIO_PinSource1, GPIO_AF_FSMC);
+ GPIO_PinAFConfig(GPIOG, GPIO_PinSource2, GPIO_AF_FSMC);
+ GPIO_PinAFConfig(GPIOG, GPIO_PinSource3, GPIO_AF_FSMC);
+ GPIO_PinAFConfig(GPIOG, GPIO_PinSource4, GPIO_AF_FSMC);
+ GPIO_PinAFConfig(GPIOG, GPIO_PinSource5, GPIO_AF_FSMC);
+
+ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13;
+ GPIO_Init(GPIOD, &GPIO_InitStructure);
+ GPIO_PinAFConfig(GPIOD, GPIO_PinSource11, GPIO_AF_FSMC);
+ GPIO_PinAFConfig(GPIOD, GPIO_PinSource12, GPIO_AF_FSMC);
+ GPIO_PinAFConfig(GPIOD, GPIO_PinSource13, GPIO_AF_FSMC);
+
+ /*!< NOE and NWE configuration */
+ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 |GPIO_Pin_5;
+ GPIO_Init(GPIOD, &GPIO_InitStructure);
+ GPIO_PinAFConfig(GPIOD, GPIO_PinSource4, GPIO_AF_FSMC);
+ GPIO_PinAFConfig(GPIOD, GPIO_PinSource5, GPIO_AF_FSMC);
+
+ /*!< NE2 configuration */
+ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
+ GPIO_Init(GPIOG, &GPIO_InitStructure);
+ GPIO_PinAFConfig(GPIOG, GPIO_PinSource9, GPIO_AF_FSMC);
+
+ /*!< NBL0, NBL1 configuration */
+ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6;
+ GPIO_Init(GPIOE, &GPIO_InitStructure);
+ GPIO_PinAFConfig(GPIOE, GPIO_PinSource3, GPIO_AF_FSMC);
+ GPIO_PinAFConfig(GPIOE, GPIO_PinSource4, GPIO_AF_FSMC);
+ GPIO_PinAFConfig(GPIOE, GPIO_PinSource5, GPIO_AF_FSMC);
+ GPIO_PinAFConfig(GPIOE, GPIO_PinSource6, GPIO_AF_FSMC);
+
+ /*!< Configure PD6 for NOR memory Ready/Busy signal */
+ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
+ GPIO_Init(GPIOD, &GPIO_InitStructure);
+ GPIO_PinAFConfig(GPIOD, GPIO_PinSource6, GPIO_AF_FSMC);
+
+ /*-- FSMC Configuration ----------------------------------------------------*/
+ p.FSMC_AddressSetupTime = 0x02;
+ p.FSMC_AddressHoldTime = 0x00;
+ p.FSMC_DataSetupTime = 0x05;
+ p.FSMC_BusTurnAroundDuration = 0x00;
+ p.FSMC_CLKDivision = 0x00;
+ p.FSMC_DataLatency = 0x00;
+ p.FSMC_AccessMode = FSMC_AccessMode_B;
+
+ FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM2;
+ FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable;
+ FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_NOR;
+ FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b;
+ FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable;
+ FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable;
+ FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low;
+ FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable;
+ FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState;
+ FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable;
+ FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable;
+ FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable;
+ FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable;
+ FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p;
+ FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p;
+
+ FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure);
+
+ /*!< Enable FSMC Bank1_NOR Bank */
+ FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM2, ENABLE);
+}
+
+/**
+ * @brief Reads NOR memory's Manufacturer and Device Code.
+ * @param NOR_ID: pointer to a NOR_IDTypeDef structure which will hold the
+ * Manufacturer and Device Code.
+ * @retval None
+ */
+void NOR_ReadID(NOR_IDTypeDef* NOR_ID)
+{
+ NOR_WRITE(ADDR_SHIFT(0x0555), 0x00AA);
+ NOR_WRITE(ADDR_SHIFT(0x02AA), 0x0055);
+ NOR_WRITE(ADDR_SHIFT(0x0555), 0x0090);
+
+ NOR_ID->Manufacturer_Code = *(__IO uint16_t *) ADDR_SHIFT(0x0000);
+ NOR_ID->Device_Code1 = *(__IO uint16_t *) ADDR_SHIFT(0x0001);
+ NOR_ID->Device_Code2 = *(__IO uint16_t *) ADDR_SHIFT(0x000E);
+ NOR_ID->Device_Code3 = *(__IO uint16_t *) ADDR_SHIFT(0x000F);
+}
+
+/**
+ * @brief Erases the specified Nor memory block.
+ * @param BlockAddr: address of the block to erase.
+ * @retval NOR_Status: The returned value can be: NOR_SUCCESS, NOR_ERROR
+ * or NOR_TIMEOUT
+ */
+NOR_Status NOR_EraseBlock(uint32_t BlockAddr)
+{
+ NOR_WRITE(ADDR_SHIFT(0x0555), 0x00AA);
+ NOR_WRITE(ADDR_SHIFT(0x02AA), 0x0055);
+ NOR_WRITE(ADDR_SHIFT(0x0555), 0x0080);
+ NOR_WRITE(ADDR_SHIFT(0x0555), 0x00AA);
+ NOR_WRITE(ADDR_SHIFT(0x02AA), 0x0055);
+ NOR_WRITE((Bank1_NOR2_ADDR + BlockAddr), 0x30);
+
+ return (NOR_GetStatus(BlockErase_Timeout));
+}
+
+/**
+ * @brief Erases the entire chip.
+ * @param None
+ * @retval NOR_Status: The returned value can be: NOR_SUCCESS, NOR_ERROR
+ * or NOR_TIMEOUT
+ */
+NOR_Status NOR_EraseChip(void)
+{
+ NOR_WRITE(ADDR_SHIFT(0x0555), 0x00AA);
+ NOR_WRITE(ADDR_SHIFT(0x02AA), 0x0055);
+ NOR_WRITE(ADDR_SHIFT(0x0555), 0x0080);
+ NOR_WRITE(ADDR_SHIFT(0x0555), 0x00AA);
+ NOR_WRITE(ADDR_SHIFT(0x02AA), 0x0055);
+ NOR_WRITE(ADDR_SHIFT(0x0555), 0x0010);
+
+ return (NOR_GetStatus(ChipErase_Timeout));
+}
+
+/**
+ * @brief Writes a half-word to the NOR memory.
+ * @param WriteAddr: NOR memory internal address to write to.
+ * @param Data: Data to write.
+ * @retval NOR_Status: The returned value can be: NOR_SUCCESS, NOR_ERROR
+ * or NOR_TIMEOUT
+ */
+NOR_Status NOR_WriteHalfWord(uint32_t WriteAddr, uint16_t Data)
+{
+ NOR_WRITE(ADDR_SHIFT(0x0555), 0x00AA);
+ NOR_WRITE(ADDR_SHIFT(0x02AA), 0x0055);
+ NOR_WRITE(ADDR_SHIFT(0x0555), 0x00A0);
+ NOR_WRITE((Bank1_NOR2_ADDR + WriteAddr), Data);
+
+ return (NOR_GetStatus(Program_Timeout));
+}
+
+/**
+ * @brief Writes a half-word buffer to the FSMC NOR memory.
+ * @param pBuffer: pointer to buffer.
+ * @param WriteAddr: NOR memory internal address from which the data will be
+ * written.
+ * @param NumHalfwordToWrite: number of Half words to write.
+ * @retval NOR_Status: The returned value can be: NOR_SUCCESS, NOR_ERROR
+ * or NOR_TIMEOUT
+ */
+NOR_Status NOR_WriteBuffer(uint16_t* pBuffer, uint32_t WriteAddr, uint32_t NumHalfwordToWrite)
+{
+ NOR_Status status = NOR_ONGOING;
+
+ do
+ {
+ /*!< Transfer data to the memory */
+ status = NOR_WriteHalfWord(WriteAddr, *pBuffer++);
+ WriteAddr = WriteAddr + 2;
+ NumHalfwordToWrite--;
+ }
+ while((status == NOR_SUCCESS) && (NumHalfwordToWrite != 0));
+
+ return (status);
+}
+
+/**
+ * @brief Writes a half-word buffer to the FSMC NOR memory. This function
+ * must be used only with S29GL128P NOR memory.
+ * @param pBuffer: pointer to buffer.
+ * @param WriteAddr: NOR memory internal address from which the data will be
+ * written.
+ * @param NumHalfwordToWrite: number of Half words to write.
+ * The maximum allowed value is 32 Half words (64 bytes).
+ * @retval NOR_Status: The returned value can be: NOR_SUCCESS, NOR_ERROR
+ * or NOR_TIMEOUT
+ */
+NOR_Status NOR_ProgramBuffer(uint16_t* pBuffer, uint32_t WriteAddr, uint32_t NumHalfwordToWrite)
+{
+ uint32_t lastloadedaddress = 0x00;
+ uint32_t currentaddress = 0x00;
+ uint32_t endaddress = 0x00;
+
+ /*!< Initialize variables */
+ currentaddress = WriteAddr;
+ endaddress = WriteAddr + NumHalfwordToWrite - 1;
+ lastloadedaddress = WriteAddr;
+
+ /*!< Issue unlock command sequence */
+ NOR_WRITE(ADDR_SHIFT(0x00555), 0x00AA);
+
+ NOR_WRITE(ADDR_SHIFT(0x02AA), 0x0055);
+
+ /*!< Write Write Buffer Load Command */
+ NOR_WRITE(ADDR_SHIFT(WriteAddr), 0x0025);
+ NOR_WRITE(ADDR_SHIFT(WriteAddr), (NumHalfwordToWrite - 1));
+
+ /*!< Load Data into NOR Buffer */
+ while(currentaddress <= endaddress)
+ {
+ /*!< Store last loaded address & data value (for polling) */
+ lastloadedaddress = currentaddress;
+
+ NOR_WRITE(ADDR_SHIFT(currentaddress), *pBuffer++);
+ currentaddress += 1;
+ }
+
+ NOR_WRITE(ADDR_SHIFT(lastloadedaddress), 0x29);
+
+ return(NOR_GetStatus(Program_Timeout));
+}
+
+/**
+ * @brief Reads a half-word from the NOR memory.
+ * @param ReadAddr: NOR memory internal address to read from.
+ * @retval Half-word read from the NOR memory
+ */
+uint16_t NOR_ReadHalfWord(uint32_t ReadAddr)
+{
+ NOR_WRITE(ADDR_SHIFT(0x00555), 0x00AA);
+ NOR_WRITE(ADDR_SHIFT(0x002AA), 0x0055);
+ NOR_WRITE((Bank1_NOR2_ADDR + ReadAddr), 0x00F0 );
+
+ return (*(__IO uint16_t *)((Bank1_NOR2_ADDR + ReadAddr)));
+}
+
+/**
+ * @brief Reads a block of data from the FSMC NOR memory.
+ * @param pBuffer: pointer to the buffer that receives the data read from the
+ * NOR memory.
+ * @param ReadAddr: NOR memory internal address to read from.
+ * @param NumHalfwordToRead : number of Half word to read.
+ * @retval None
+ */
+void NOR_ReadBuffer(uint16_t* pBuffer, uint32_t ReadAddr, uint32_t NumHalfwordToRead)
+{
+ NOR_WRITE(ADDR_SHIFT(0x0555), 0x00AA);
+ NOR_WRITE(ADDR_SHIFT(0x02AA), 0x0055);
+ NOR_WRITE((Bank1_NOR2_ADDR + ReadAddr), 0x00F0);
+
+ for(; NumHalfwordToRead != 0x00; NumHalfwordToRead--) /*!< while there is data to read */
+ {
+ /*!< Read a Halfword from the NOR */
+ *pBuffer++ = *(__IO uint16_t *)((Bank1_NOR2_ADDR + ReadAddr));
+ ReadAddr = ReadAddr + 2;
+ }
+}
+
+/**
+ * @brief Returns the NOR memory to Read mode.
+ * @param None
+ * @retval NOR_SUCCESS
+ */
+NOR_Status NOR_ReturnToReadMode(void)
+{
+ NOR_WRITE(Bank1_NOR2_ADDR, 0x00F0);
+
+ return (NOR_SUCCESS);
+}
+
+/**
+ * @brief Returns the NOR memory to Read mode and resets the errors in the NOR
+ * memory Status Register.
+ * @param None
+ * @retval NOR_SUCCESS
+ */
+NOR_Status NOR_Reset(void)
+{
+ NOR_WRITE(ADDR_SHIFT(0x00555), 0x00AA);
+ NOR_WRITE(ADDR_SHIFT(0x002AA), 0x0055);
+ NOR_WRITE(Bank1_NOR2_ADDR, 0x00F0);
+
+ return (NOR_SUCCESS);
+}
+
+/**
+ * @brief Returns the NOR operation status.
+ * @param Timeout: NOR progamming Timeout
+ * @retval NOR_Status: The returned value can be: NOR_SUCCESS, NOR_ERROR
+ * or NOR_TIMEOUT
+ */
+NOR_Status NOR_GetStatus(uint32_t Timeout)
+{
+ uint16_t val1 = 0x00, val2 = 0x00;
+ NOR_Status status = NOR_ONGOING;
+ uint32_t timeout = Timeout;
+
+ /*!< Poll on NOR memory Ready/Busy signal ----------------------------------*/
+ while((GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_6) != RESET) && (timeout > 0))
+ {
+ timeout--;
+ }
+
+ timeout = Timeout;
+
+ while((GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_6) == RESET) && (timeout > 0))
+ {
+ timeout--;
+ }
+
+ /*!< Get the NOR memory operation status -----------------------------------*/
+ while((Timeout != 0x00) && (status != NOR_SUCCESS))
+ {
+ Timeout--;
+
+ /*!< Read DQ6 and DQ5 */
+ val1 = *(__IO uint16_t *)(Bank1_NOR2_ADDR);
+ val2 = *(__IO uint16_t *)(Bank1_NOR2_ADDR);
+
+ /*!< If DQ6 did not toggle between the two reads then return NOR_Success */
+ if((val1 & 0x0040) == (val2 & 0x0040))
+ {
+ return NOR_SUCCESS;
+ }
+
+ if((val1 & 0x0020) != 0x0020)
+ {
+ status = NOR_ONGOING;
+ }
+
+ val1 = *(__IO uint16_t *)(Bank1_NOR2_ADDR);
+ val2 = *(__IO uint16_t *)(Bank1_NOR2_ADDR);
+
+ if((val1 & 0x0040) == (val2 & 0x0040))
+ {
+ return NOR_SUCCESS;
+ }
+ else if((val1 & 0x0020) == 0x0020)
+ {
+ return NOR_ERROR;
+ }
+ }
+
+ if(Timeout == 0x00)
+ {
+ status = NOR_TIMEOUT;
+ }
+
+ /*!< Return the operation status */
+ return (status);
+}
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval_glass_lcd.c b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval_glass_lcd.c
new file mode 100644
index 0000000..08dae7e
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval_glass_lcd.c
@@ -0,0 +1,3479 @@
+/**
+ ******************************************************************************
+ * @file stm32l152d_eval_glass_lcd.c
+ * @author MCD Application Team
+ * @version V1.0.1
+ * @date 09-March-2012
+ * @brief This file includes the LCD Glass driver for LCD XHO5002B Module of
+ * STM32L152D-EVAL board.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.st.com/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+
+/* Includes ------------------------------------------------------------------*/
+#include "stm32l152d_eval_glass_lcd.h"
+
+/** @addtogroup Utilities
+ * @{
+ */
+
+/** @addtogroup STM32_EVAL
+ * @{
+ */
+
+/** @addtogroup STM32L152D_EVAL
+ * @{
+ */
+
+/** @defgroup STM32L152D_EVAL_GLASS_LCD
+ * @brief This file includes the LCD Glass driver for LCD_XHO5002B Module of
+ * STM32L152D-EVAL board.
+ * @{
+ */
+
+/** @defgroup STM32L152D_EVAL_GLASS_LCD_Private_Types
+ * @{
+ */
+/**
+ * @}
+ */
+
+/** @defgroup STM32L152D_EVAL_GLASS_LCD_Private_Defines
+ * @{
+ */
+/**
+ * @}
+ */
+
+/** @defgroup STM32L152D_EVAL_GLASS_LCD_Private_Macros
+ * @{
+ */
+/**
+ * @}
+ */
+
+/** @defgroup STM32L152D_EVAL_GLASS_LCD_Private_Variables
+ * @{
+ */
+
+/**
+ @verbatim
+================================================================================
+ GLASS LCD MAPPING
+================================================================================
+ A
+ _ ----------
+ P|_| |\ |H /|
+ F| G | I |B
+ | \ | / |
+ --M-- --N--
+ | /| \ |
+ E| L | J |C
+ _ | / |K \|
+ Q|_| -----------
+ D
+
+A LCD character coding is based on the following matrix:
+ COM0 COM1 COM4 COM5 COM6 COM7
+ SEG(n) { 0 , 0 , I , B , C , J }
+ SEG(n+1) { D , K , A , H , M , N }
+ SEG(n+2) { Q , L , G , F , P , E }
+
+The character A for example is:
+-----------------------------------------------------------
+ COM0 COM1 COM4 COM5 COM6 COM7
+ SEG(n) { 0 , 0 , 0 , 1 , 1 , 0 }
+ SEG(n+1) { 0 , 0 , 1 , 0 , 1 , 1 }
+ SEG(n+2) { 0 , 0 , 0 , 1 , 0 , 1 }
+ --------------------------------------------------------
+ = 0 0 2 5 3 6 hex
+
+ => 'A' = 0x002536
+
+ @endverbatim
+ */
+
+/**
+ * @brief LETTERS AND NUMBERS MAPPING DEFINITION
+ */
+uint16_t i;
+__I uint32_t Mask[] =
+ {
+ 0x00F00000, 0x000F0000, 0x0000F000, 0x00000F00, 0x000000F0, 0x0000000F
+ };
+const uint8_t Shift[6] =
+ {
+ 20, 16, 12, 8, 4, 0
+ };
+
+uint32_t Digit[6]; /* Digit frame buffer */
+
+/* Letters and number map of the custom LCD 8x40(STM8L152D-EVAL evaluation board) */
+__I uint32_t LetterMap[26] =
+ {
+ /* A B C D E F */
+ 0x00002536, 0x00202536, 0x00202404, 0x00222310, 0x00202426, 0x00002426,
+ /* G H I J K L */
+ 0x00202416, 0x00000536, 0x00222200, 0x00200114, 0x00001425, 0x00200404,
+ /* M N O P Q R */
+ 0x00005514, 0x00004515, 0x00202514, 0x00002526, 0x00002532, 0x00002527,
+ /* S T U V W X */
+ 0x00202432, 0x00022200, 0x00200514, 0x00041404, 0x00050515, 0x00045001,
+ /* Y Z */
+ 0x00025000, 0x00243000
+ };
+
+__I uint32_t NumberMap[10] =
+ {
+ /* 0 1 2 3 4 */
+ 0x00202514, 0x00000110, 0x00202126, 0x00202132, 0x00000532,
+ /* 5 6 7 8 9 */
+ 0x00202432, 0x00202436, 0x00002110, 0x00202536, 0x00202532
+ };
+
+/**
+ * @}
+ */
+
+/** @defgroup STM32L152D_EVAL_LCD_Private_Function_Prototypes
+ * @{
+ */
+static void Convert(uint8_t* c, Point_Typedef Point, DoublePoint_Typedef DoublePoint);
+static void delay(__IO uint32_t nCount);
+static void LCD_GPIOConfig(void);
+
+/**
+ * @}
+ */
+
+/** @defgroup STM32L152D_EVAL_LCD_Private_Functions
+ * @{
+ */
+
+/**
+ * @brief Configures the LCD GLASS relative GPIO port IOs and LCD peripheral.
+ * @param None
+ * @retval None
+ */
+void LCD_GLASS_Init(void)
+{
+ LCD_InitTypeDef LCD_InitStructure;
+
+ LCD_GPIOConfig(); /*!< Configure the LCD Glass GPIO pins */
+
+ /*!< Configure the LCD interface -------------------------------------------*/
+ RCC_APB1PeriphClockCmd(RCC_APB1Periph_LCD, ENABLE); /*!< Enable LCD APB1 Clock */
+
+ LCD_InitStructure.LCD_Prescaler = LCD_Prescaler_4;
+ LCD_InitStructure.LCD_Divider = LCD_Divider_16;
+ LCD_InitStructure.LCD_Duty = LCD_Duty_1_8;
+ LCD_InitStructure.LCD_Bias = LCD_Bias_1_4;
+ LCD_InitStructure.LCD_VoltageSource = LCD_VoltageSource_Internal;
+ LCD_Init(&LCD_InitStructure);
+
+ /*!< Configure the Pulse On Duration */
+ LCD_PulseOnDurationConfig(LCD_PulseOnDuration_2);
+
+ /*!< Configure the LCD Contrast (3.51V) */
+ LCD_ContrastConfig(LCD_Contrast_Level_7);
+
+ /*!< Wait Until the LCD FCR register is synchronized */
+ LCD_WaitForSynchro();
+
+ /*!< Enable LCD peripheral */
+ LCD_Cmd(ENABLE);
+
+ /*!< Wait Until the LCD is enabled */
+ while(LCD_GetFlagStatus(LCD_FLAG_ENS) == RESET)
+ {
+ }
+ /*!< Wait Until the LCD Booster is ready */
+ while(LCD_GetFlagStatus(LCD_FLAG_RDY) == RESET)
+ {
+ }
+}
+
+/**
+ * @brief This function writes a char in the LCD RAM.
+ * @param ch: The character to display.
+ * @param point: A point to add in front of char.
+ * This parameter can be one of the following values:
+ * @arg POINT_OFF : No point to add in front of char.
+ * @arg POINT_ON : Add a point in front of char.
+ * @param apostrophe: Flag indicating if a apostrophe has to be add in front
+ * of displayed character.
+ * This parameter can be one of the following values:
+ * @arg APOSTROPHE_OFF : No apostrophe to add in back of char.
+ * @arg APOSTROPHE_ON : Add an apostrophe in back of char.
+ * @param position: Position in the LCD of the caracter to write.
+ * This parameter can be any value in range [0:7].
+ * @retval None
+ */
+void LCD_GLASS_WriteChar(uint8_t* ch, Point_Typedef point, DoublePoint_Typedef DoublePoint, uint8_t position)
+{
+ Convert(ch, point, DoublePoint);
+
+ switch (position)
+ {
+ /* Position 0 on LCD */
+ case 0:
+ /* Write Digit 0 on COM0 */
+ LCD->RAM[LCD_RAMRegister_0] &= (uint32_t)0xFFFFFBFF;
+ LCD->RAM[LCD_RAMRegister_0] |= (uint32_t)(Digit[0] << (uint32_t)0x09);
+ /* Write Digit 1 on COM1 */
+ LCD->RAM[LCD_RAMRegister_2] &= (uint32_t)0xFFFFF3FF;
+ LCD->RAM[LCD_RAMRegister_2] |= (uint32_t)(Digit[1] << (uint32_t)0x09);
+ /* Write Digit 2 on COM4 */
+ LCD->RAM[LCD_RAMRegister_8] &= (uint32_t)0xFFFFF1FF;
+ LCD->RAM[LCD_RAMRegister_8] |= (uint32_t)(Digit[2] << (uint32_t)0x09);
+ /* Write Digit 3 on COM5 */
+ LCD->RAM[LCD_RAMRegister_10] &= (uint32_t)0xFFFFF1FF;
+ LCD->RAM[LCD_RAMRegister_10] |= (uint32_t)(Digit[3] << (uint32_t)0x09);
+ /* Write Digit 4 on COM6 */
+ LCD->RAM[LCD_RAMRegister_12] &= (uint32_t)0xFFFFF9FF;
+ LCD->RAM[LCD_RAMRegister_12] |= (uint32_t)(Digit[4] << (uint32_t)0x09);
+ /* Write Digit 5 on COM7 */
+ LCD->RAM[LCD_RAMRegister_14] &= (uint32_t)0xFFFFF1FF;
+ LCD->RAM[LCD_RAMRegister_14] |= (uint32_t)(Digit[5] << (uint32_t)0x09);
+ break;
+
+ /* Position 1 on LCD */
+ case 1:
+ /* Write Digit 0 on COM0 */
+ LCD->RAM[LCD_RAMRegister_0] &= (uint32_t)0xFFFF9FFF;
+ LCD->RAM[LCD_RAMRegister_0] |= (uint32_t)(Digit[0] << (uint32_t)0x0C);
+ /* Write Digit 1 on COM1 */
+ LCD->RAM[LCD_RAMRegister_2] &= (uint32_t)0xFFFF9FFF;
+ LCD->RAM[LCD_RAMRegister_2] |= (uint32_t)(Digit[1] << (uint32_t)0x0C);
+ /* Write Digit 2 on COM4 */
+ LCD->RAM[LCD_RAMRegister_8] &= (uint32_t)0xFFFF8FFF;
+ LCD->RAM[LCD_RAMRegister_8] |= (uint32_t)(Digit[2] << (uint32_t)0x0C);
+ /* Write Digit 3 on COM5 */
+ LCD->RAM[LCD_RAMRegister_10] &= (uint32_t)0xFFFF8FFF;
+ LCD->RAM[LCD_RAMRegister_10] |= (uint32_t)(Digit[3] << (uint32_t)0x0C);
+ /* Write Digit 4 on COM6 */
+ LCD->RAM[LCD_RAMRegister_12] &= (uint32_t)0xFFFF8FFF;
+ LCD->RAM[LCD_RAMRegister_12] |= (uint32_t)(Digit[4] << (uint32_t)0x0C);
+ /* Write Digit 5 on COM7 */
+ LCD->RAM[LCD_RAMRegister_14] &= (uint32_t)0xFFFF8FFF;
+ LCD->RAM[LCD_RAMRegister_14] |= (uint32_t)(Digit[5] << (uint32_t)0x0C);
+ break;
+
+ /* Position 2 on LCD */
+ case 2:
+ /* Write Digit 0 on COM0 */
+ LCD->RAM[LCD_RAMRegister_0] &= (uint32_t)0xFFFCFFFF;
+ LCD->RAM[LCD_RAMRegister_0] |= (uint32_t)(Digit[0] << (uint32_t)0x0F);
+ /* Write Digit 1 on COM1 */
+ LCD->RAM[LCD_RAMRegister_2] &= (uint32_t)0xFFFCFFFF;
+ LCD->RAM[LCD_RAMRegister_2] |= (uint32_t)(Digit[1] << (uint32_t)0x0F);
+ /* Write Digit 2 on COM4 */
+ LCD->RAM[LCD_RAMRegister_8] &= (uint32_t)0xFFFC7FFF;
+ LCD->RAM[LCD_RAMRegister_8] |= (uint32_t)(Digit[2] << (uint32_t)0x0F);
+ /* Write Digit 3 on COM5 */
+ LCD->RAM[LCD_RAMRegister_10] &= (uint32_t)0xFFFC7FFF;
+ LCD->RAM[LCD_RAMRegister_10] |= (uint32_t)(Digit[3] << (uint32_t)0x0F);
+ /* Write Digit 4 on COM6 */
+ LCD->RAM[LCD_RAMRegister_12] &= (uint32_t)0xFFFC7FFF;
+ LCD->RAM[LCD_RAMRegister_12] |= (uint32_t)(Digit[4] << (uint32_t)0x0F);
+ /* Write Digit 5 on COM7 */
+ LCD->RAM[LCD_RAMRegister_14] &= (uint32_t)0xFFFC7FFF;
+ LCD->RAM[LCD_RAMRegister_14] |= (uint32_t)(Digit[5] << (uint32_t)0x0F);
+ break;
+
+ /* Position 3 on LCD */
+ case 3:
+ /* Write Digit 0 on COM0 */
+ LCD->RAM[LCD_RAMRegister_0] &= (uint32_t)0xFFE7FFFF;
+ LCD->RAM[LCD_RAMRegister_0] |= (uint32_t)(Digit[0] << (uint32_t)0x12);
+ /* Write Digit 1 on COM1 */
+ LCD->RAM[LCD_RAMRegister_2] &= (uint32_t)0xFFE7FFFF;
+ LCD->RAM[LCD_RAMRegister_2] |= (uint32_t)(Digit[1] << (uint32_t)0x12);
+ /* Write Digit 2 on COM4 */
+ LCD->RAM[LCD_RAMRegister_8] &= (uint32_t)0xFFE3FFFF;
+ LCD->RAM[LCD_RAMRegister_8] |= (uint32_t)(Digit[2] << (uint32_t)0x12);
+ /* Write Digit 3 on COM5 */
+ LCD->RAM[LCD_RAMRegister_10] &= (uint32_t)0xFFE3FFFF;
+ LCD->RAM[LCD_RAMRegister_10] |= (uint32_t)(Digit[3] << (uint32_t)0x12);
+ /* Write Digit 4 on COM6 */
+ LCD->RAM[LCD_RAMRegister_12] &= (uint32_t)0xFFE3FFFF;
+ LCD->RAM[LCD_RAMRegister_12] |= (uint32_t)(Digit[4] << (uint32_t)0x12);
+ /* Write Digit 5 on COM7 */
+ LCD->RAM[LCD_RAMRegister_14] &= (uint32_t)0xFFE3FFFF;
+ LCD->RAM[LCD_RAMRegister_14] |= (uint32_t)(Digit[5] << (uint32_t)0x12);
+ break;
+
+ /* Position 4 on LCD */
+ case 4:
+ /* Write Digit 0 on COM0 */
+ LCD->RAM[LCD_RAMRegister_0] &= (uint32_t)0xFFFFFFF9;
+ LCD->RAM[LCD_RAMRegister_0] |= (uint32_t)(Digit[0] );
+ /* Write Digit 1 on COM1 */
+ LCD->RAM[LCD_RAMRegister_2] &= (uint32_t)0xFFFFFFF9;
+ LCD->RAM[LCD_RAMRegister_2] |= (uint32_t)(Digit[1]);
+ /* Write Digit 2 on COM4 */
+ LCD->RAM[LCD_RAMRegister_8] &= (uint32_t)0xFFFFFFF8;
+ LCD->RAM[LCD_RAMRegister_8] |= (uint32_t)(Digit[2]);
+ /* Write Digit 3 on COM5 */
+ LCD->RAM[LCD_RAMRegister_10] &= (uint32_t)0xFFFFFFF8;
+ LCD->RAM[LCD_RAMRegister_10] |= (uint32_t)(Digit[3]);
+ /* Write Digit 4 on COM6 */
+ LCD->RAM[LCD_RAMRegister_12] &= (uint32_t)0xFFFFFFF8;
+ LCD->RAM[LCD_RAMRegister_12] |= (uint32_t)(Digit[4]);
+ /* Write Digit 5 on COM7 */
+ LCD->RAM[LCD_RAMRegister_14] &= (uint32_t)0xFFFFFFF8;
+ LCD->RAM[LCD_RAMRegister_14] |= (uint32_t)(Digit[5]);
+ break;
+
+ /* Position 5 on LCD */
+ case 5:
+ /* Write Digit 0 on COM0 */
+ LCD->RAM[LCD_RAMRegister_0] &= (uint32_t)0xFFFFFFCF;
+ LCD->RAM[LCD_RAMRegister_0] |= (uint32_t)(Digit[0] << (uint32_t)0x03);
+ /* Write Digit 1 on COM1 */
+ LCD->RAM[LCD_RAMRegister_2] &= (uint32_t)0xFFFFFFCF;
+ LCD->RAM[LCD_RAMRegister_2] |= (uint32_t)(Digit[1] << (uint32_t)0x03);
+ /* Write Digit 2 on COM4 */
+ LCD->RAM[LCD_RAMRegister_8] &= (uint32_t)0xFFFFFFC7;
+ LCD->RAM[LCD_RAMRegister_8] |= (uint32_t)(Digit[2] << (uint32_t)0x03);
+ /* Write Digit 3 on COM5 */
+ LCD->RAM[LCD_RAMRegister_10] &= (uint32_t)0xFFFFFFC7;
+ LCD->RAM[LCD_RAMRegister_10] |= (uint32_t)(Digit[3] << (uint32_t)0x03);
+ /* Write Digit 4 on COM6 */
+ LCD->RAM[LCD_RAMRegister_12] &= (uint32_t)0xFFFFFFC7;
+ LCD->RAM[LCD_RAMRegister_12] |= (uint32_t)(Digit[4] << (uint32_t)0x03);
+ /* Write Digit 5 on COM7 */
+ LCD->RAM[LCD_RAMRegister_14] &= (uint32_t)0xFFFFFFC7;
+ LCD->RAM[LCD_RAMRegister_14] |= (uint32_t)(Digit[5] << (uint32_t)0x03);
+ break;
+
+ /* Position 6 on LCD */
+ case 6:
+ /* Write Digit 0 on COM0 */
+ LCD->RAM[LCD_RAMRegister_0] &= (uint32_t)0xFFFFFE7F;
+ LCD->RAM[LCD_RAMRegister_0] |= (uint32_t)(Digit[0] << (uint32_t)0x06);
+ /* Write Digit 1 on COM1 */
+ LCD->RAM[LCD_RAMRegister_2] &= (uint32_t)0xFFFFFE7F;
+ LCD->RAM[LCD_RAMRegister_2] |= (uint32_t)(Digit[1] << (uint32_t)0x06);
+ /* Write Digit 2 on COM4 */
+ LCD->RAM[LCD_RAMRegister_8] &= (uint32_t)0xFFFFFE3F;
+ LCD->RAM[LCD_RAMRegister_8] |= (uint32_t)(Digit[2] << (uint32_t)0x06);
+ /* Write Digit 3 on COM5 */
+ LCD->RAM[LCD_RAMRegister_10] &= (uint32_t)0xFFFFFE3F;
+ LCD->RAM[LCD_RAMRegister_10] |= (uint32_t)(Digit[3] << (uint32_t)0x06);
+ /* Write Digit 4 on COM6 */
+ LCD->RAM[LCD_RAMRegister_12] &= (uint32_t)0xFFFFFE3F;
+ LCD->RAM[LCD_RAMRegister_12] |= (uint32_t)(Digit[4] << (uint32_t)0x06);
+ /* Write Digit 5 on COM7 */
+ LCD->RAM[LCD_RAMRegister_14] &= (uint32_t)0xFFFFFE3F;
+ LCD->RAM[LCD_RAMRegister_14] |= (uint32_t)(Digit[5] << (uint32_t)0x06);
+ break;
+
+ default:
+ break;
+ }
+}
+
+/**
+ * @brief This function Clear a char in the LCD RAM.
+ * @param position: Position in the LCD of the caracter to write.
+ * This parameter can be any value in range [0:7].
+ * @retval None
+ */
+void LCD_GLASS_ClearChar(uint8_t position)
+{
+ /*!< Wait Until the last LCD RAM update finish */
+ while(LCD_GetFlagStatus(LCD_FLAG_UDR) != RESET)
+ {
+ }
+ switch (position)
+ {
+ /* Clear position 0 on LCD */
+ case 0:
+ LCD->RAM[LCD_RAMRegister_0] &= (uint32_t)0xFFFFFBFF;
+ LCD->RAM[LCD_RAMRegister_2] &= (uint32_t)0xFFFFF3FF;
+ LCD->RAM[LCD_RAMRegister_8] &= (uint32_t)0xFFFFF1FF;
+ LCD->RAM[LCD_RAMRegister_10] &= (uint32_t)0xFFFFF1FF;
+ LCD->RAM[LCD_RAMRegister_12] &= (uint32_t)0xFFFFF9FF;
+ LCD->RAM[LCD_RAMRegister_14] &= (uint32_t)0xFFFFF1FF;
+ break;
+
+ /* Clear position 1 on LCD */
+ case 1:
+ LCD->RAM[LCD_RAMRegister_0] &= (uint32_t)0xFFFF9FFF;
+ LCD->RAM[LCD_RAMRegister_2] &= (uint32_t)0xFFFF9FFF;
+ LCD->RAM[LCD_RAMRegister_8] &= (uint32_t)0xFFFF8FFF;
+ LCD->RAM[LCD_RAMRegister_10] &= (uint32_t)0xFFFF8FFF;
+ LCD->RAM[LCD_RAMRegister_12] &= (uint32_t)0xFFFF8FFF;
+ LCD->RAM[LCD_RAMRegister_14] &= (uint32_t)0xFFFF8FFF;
+ break;
+
+ /* Clear position 2 on LCD */
+ case 2:
+ LCD->RAM[LCD_RAMRegister_0] &= (uint32_t)0xFFFCFFFF;
+ LCD->RAM[LCD_RAMRegister_2] &= (uint32_t)0xFFFCFFFF;
+ LCD->RAM[LCD_RAMRegister_8] &= (uint32_t)0xFFFC7FFF;
+ LCD->RAM[LCD_RAMRegister_10] &= (uint32_t)0xFFFC7FFF;
+ LCD->RAM[LCD_RAMRegister_12] &= (uint32_t)0xFFFC7FFF;
+ LCD->RAM[LCD_RAMRegister_14] &= (uint32_t)0xFFFC7FFF;
+ break;
+
+ /* Clear position 3 on LCD */
+ case 3:
+ LCD->RAM[LCD_RAMRegister_0] &= (uint32_t)0xFFE7FFFF;
+ LCD->RAM[LCD_RAMRegister_2] &= (uint32_t)0xFFE7FFFF;
+ LCD->RAM[LCD_RAMRegister_8] &= (uint32_t)0xFFE3FFFF;
+ LCD->RAM[LCD_RAMRegister_10] &= (uint32_t)0xFFE3FFFF;
+ LCD->RAM[LCD_RAMRegister_12] &= (uint32_t)0xFFE3FFFF;
+ LCD->RAM[LCD_RAMRegister_14] &= (uint32_t)0xFFE3FFFF;
+ break;
+
+ /* Clear position 4 on LCD */
+ case 4:
+ LCD->RAM[LCD_RAMRegister_0] &= (uint32_t)0xFFFFFFF9;
+ LCD->RAM[LCD_RAMRegister_2] &= (uint32_t)0xFFFFFFF9;
+ LCD->RAM[LCD_RAMRegister_8] &= (uint32_t)0xFFFFFFF8;
+ LCD->RAM[LCD_RAMRegister_10] &= (uint32_t)0xFFFFFFF8;
+ LCD->RAM[LCD_RAMRegister_12] &= (uint32_t)0xFFFFFFF8;
+ LCD->RAM[LCD_RAMRegister_14] &= (uint32_t)0xFFFFFFF8;
+ break;
+
+ /* Clear position 5 on LCD */
+ case 5:
+ LCD->RAM[LCD_RAMRegister_0] &= (uint32_t)0xFFFFFFCF;
+ LCD->RAM[LCD_RAMRegister_2] &= (uint32_t)0xFFFFFFCF;
+ LCD->RAM[LCD_RAMRegister_8] &= (uint32_t)0xFFFFFFC7;
+ LCD->RAM[LCD_RAMRegister_10] &= (uint32_t)0xFFFFFFC7;
+ LCD->RAM[LCD_RAMRegister_12] &= (uint32_t)0xFFFFFFC7;
+ LCD->RAM[LCD_RAMRegister_14] &= (uint32_t)0xFFFFFFC7;
+ break;
+
+ /* Clear position 6 on LCD */
+ case 6:
+ LCD->RAM[LCD_RAMRegister_0] &= (uint32_t)0xFFFFFE7F;
+ LCD->RAM[LCD_RAMRegister_2] &= (uint32_t)0xFFFFFE7F;
+ LCD->RAM[LCD_RAMRegister_8] &= (uint32_t)0xFFFFFE3F;
+ LCD->RAM[LCD_RAMRegister_10] &= (uint32_t)0xFFFFFE3F;
+ LCD->RAM[LCD_RAMRegister_12] &= (uint32_t)0xFFFFFE3F;
+ LCD->RAM[LCD_RAMRegister_14] &= (uint32_t)0xFFFFFE3F;
+ break;
+
+ default:
+ break;
+ }
+ /*!< Request LCD RAM update */
+ LCD_UpdateDisplayRequest();
+}
+
+/**
+ * @brief This function writes a char in the LCD RAM.
+ * @param ch: The character to display.
+ * @param point: A point to add in front of char.
+ * This parameter can be one of the following values:
+ * @arg POINT_OFF: No point to add in front of char.
+ * @arg POINT_ON: Add a point in front of char.
+ * @param apostrophe: Flag indicating if a apostrophe has to be add in front
+ * of displayed character.
+ * This parameter can be one of the following values:
+ * @arg APOSTROPHE_OFF: No apostrophe to add in back of char.
+ * @arg APOSTROPHE_ON: Add an apostrophe in back of char.
+ * @param position: Position in the LCD of the caracter to write.
+ * This parameter can be any value in range [0:7].
+ * @retval None
+ */
+void LCD_GLASS_DisplayChar(uint8_t* ch, Point_Typedef point, DoublePoint_Typedef DoublePoint, uint8_t position)
+{
+ /*!< Wait Until the last LCD RAM update finish */
+ while(LCD_GetFlagStatus(LCD_FLAG_UDR) != RESET)
+ {
+ }
+ /*!< LCD Write Char */
+ LCD_GLASS_WriteChar(ch, point, DoublePoint, position);
+
+ /*!< Request LCD RAM update */
+ LCD_UpdateDisplayRequest();
+}
+
+/**
+ * @brief This function writes a char in the LCD RAM.
+ * @param ptr: Pointer to string to display on the LCD Glass.
+ * @retval None
+ */
+void LCD_GLASS_DisplayString(uint8_t* ptr)
+{
+ uint8_t i = 0x00;
+
+ /*!< Wait Until the last LCD RAM update finish */
+ while(LCD_GetFlagStatus(LCD_FLAG_UDR) != RESET)
+ {
+ }
+
+ /*!< Send the string character by character on lCD */
+ while ((*ptr != 0) & (i < 8))
+ {
+ /*!< Display one character on LCD */
+ LCD_GLASS_WriteChar(ptr, POINT_OFF, DOUBLEPOINT_OFF, i);
+ /*!< Point on the next character */
+ ptr++;
+ /*!< Increment the character counter */
+ i++;
+ }
+ /*!< Request LCD RAM update */
+ LCD_UpdateDisplayRequest();
+}
+
+/**
+ * @brief Display a string in scrolling mode
+ * @note The LCD should be cleared before to start the write operation.
+ * @param ptr: Pointer to string to display on the LCD Glass.
+ * @param nScroll: Specifies how many time the message will be scrolled
+ * @param ScrollSpeed: Specifies the speed of the scroll.
+ * Low value gives higher speed.
+ * @retval None
+ */
+void LCD_GLASS_ScrollString(uint8_t* ptr, uint16_t nScroll, uint16_t ScrollSpeed)
+{
+ uint8_t Repetition = 0;
+ uint8_t* ptr1;
+ uint8_t str[8] = "";
+ ptr1 = ptr;
+
+ LCD_GLASS_DisplayString(ptr1);
+
+ delay(ScrollSpeed);
+
+ for (Repetition = 0; Repetition < nScroll; Repetition++)
+ {
+ *(str + 1) = *ptr1;
+ *(str + 2) = *(ptr1 + 1);
+ *(str + 3) = *(ptr1 + 2);
+ *(str + 4) = *(ptr1 + 3);
+ *(str + 5) = *(ptr1 + 4);
+ *(str + 6) = *(ptr1 + 5);
+ *(str + 7) =*(ptr1 + 6);
+ *(str) = *(ptr1 + 7);
+ LCD_GLASS_ClearTextZone();
+ LCD_GLASS_DisplayString(str);
+ delay(ScrollSpeed);
+
+ *(str + 1) = *(ptr1 + 7);
+ *(str + 2) = *ptr1;
+ *(str + 3) = *(ptr1 + 1);
+ *(str + 4) = *(ptr1 + 2);
+ *(str + 5) = *(ptr1 + 3);
+ *(str + 6) = *(ptr1 + 4);
+ *(str + 7) = *(ptr1 + 5);
+ *(str) = *(ptr1 + 6);
+ LCD_GLASS_ClearTextZone();
+ LCD_GLASS_DisplayString(str);
+ delay(ScrollSpeed);
+
+ *(str + 1) = *(ptr1 + 6);
+ *(str + 2) = *(ptr1 + 7);
+ *(str + 3) = *ptr1;
+ *(str + 4) = *(ptr1 + 1);
+ *(str + 5) = *(ptr1 + 2);
+ *(str + 6) = *(ptr1 + 3);
+ *(str + 7) = *(ptr1 + 4);
+ *(str) = *(ptr1 + 5);
+ LCD_GLASS_ClearTextZone();
+ LCD_GLASS_DisplayString(str);
+ delay(ScrollSpeed);
+
+ *(str + 1) = *(ptr1 + 5);
+ *(str + 2) = *(ptr1 + 6);
+ *(str + 3) = *(ptr1 + 7);
+ *(str + 4) = *ptr1;
+ *(str + 5) = *(ptr1 + 1);
+ *(str + 6) = *(ptr1 + 2);
+ *(str + 7) = *(ptr1 + 3);
+ *(str) = *(ptr1 + 4);
+ LCD_GLASS_ClearTextZone();
+ LCD_GLASS_DisplayString(str);
+ delay(ScrollSpeed);
+
+ *(str + 1) = *(ptr1 + 4);
+ *(str + 2) = *(ptr1 + 5);
+ *(str + 3) = *(ptr1 + 6);
+ *(str + 4) = *(ptr1 + 7);
+ *(str + 5) = *ptr1;
+ *(str + 6) = *(ptr1 + 1);
+ *(str + 7) = *(ptr1 + 2);
+ *(str) = *(ptr1 + 3);
+ LCD_GLASS_ClearTextZone();
+ LCD_GLASS_DisplayString(str);
+ delay(ScrollSpeed);
+
+ *(str + 1) = *(ptr1 + 3);
+ *(str + 2) = *(ptr1 + 4);
+ *(str + 3) = *(ptr1 + 5);
+ *(str + 4) = *(ptr1 + 6);
+ *(str + 5) = *(ptr1 + 7);
+ *(str + 6) = *ptr1;
+ *(str + 7) = *(ptr1 + 1);
+ *(str) = *(ptr1 + 2);
+ LCD_GLASS_ClearTextZone();
+ LCD_GLASS_DisplayString(str);
+ delay(ScrollSpeed);
+
+ *(str + 1) = *(ptr1 + 2);
+ *(str + 2) = *(ptr1 + 3);
+ *(str + 3) = *(ptr1 + 4);
+ *(str + 4) = *(ptr1 + 5);
+ *(str + 5) = *(ptr1 + 6);
+ *(str + 6) = *(ptr1 + 7);
+ *(str + 7) = *ptr1;
+ *(str) = *(ptr1 + 1);
+ LCD_GLASS_ClearTextZone();
+ LCD_GLASS_DisplayString(str);
+ delay(ScrollSpeed);
+
+ *(str + 1) = *(ptr1 + 1);
+ *(str + 2) = *(ptr1 + 2);
+ *(str + 3) = *(ptr1 + 3);
+ *(str + 4) = *(ptr1 + 4);
+ *(str + 5) = *(ptr1 + 5);
+ *(str + 6) = *(ptr1 + 6);
+ *(str + 7) = *(ptr1 + 7);
+ *(str) = *(ptr1);
+ LCD_GLASS_ClearTextZone();
+ LCD_GLASS_DisplayString(str);
+ delay(ScrollSpeed);
+ }
+}
+
+/**
+ * @brief This function Clears the LCD Glass Text Zone.
+ * @param None
+ * @retval None
+ */
+void LCD_GLASS_ClearTextZone(void)
+{
+ /*!< Wait Until the last LCD RAM update finish */
+ while(LCD_GetFlagStatus(LCD_FLAG_UDR) != RESET)
+ {
+ }
+
+ LCD->RAM[LCD_RAMRegister_0] &= (uint32_t)0xFFE49A49;
+ LCD->RAM[LCD_RAMRegister_2] &= (uint32_t)0xFFE49249;
+ LCD->RAM[LCD_RAMRegister_8] &= (uint32_t)0xFFE00000;
+ LCD->RAM[LCD_RAMRegister_10] &= (uint32_t)0xFFE00000;
+ LCD->RAM[LCD_RAMRegister_12] &= (uint32_t)0xFFE00800;
+ LCD->RAM[LCD_RAMRegister_14] &= (uint32_t)0xFFE00000;
+
+ /*!< Request LCD RAM update */
+ LCD_UpdateDisplayRequest();
+}
+
+/**
+ * @brief This function Clear the whole LCD RAM.
+ * @param None
+ * @retval None
+ */
+void LCD_GLASS_Clear(void)
+{
+ uint32_t counter = 0;
+
+ /*!< Wait Until the last LCD RAM update finish */
+ while(LCD_GetFlagStatus(LCD_FLAG_UDR) != RESET)
+ {
+ }
+
+ for (counter = 0; counter <= 0x0F; counter++)
+ {
+ LCD->RAM[counter] = (uint32_t)0x00;
+ }
+
+ /*!< Request LCD RAM update */
+ LCD_UpdateDisplayRequest();
+}
+
+/**
+ * @brief Configure ST Logo display.
+ * @param NewState: enable or disable the logo display .
+ * @retval None
+ */
+void LCD_GLASS_DisplayLogo(FunctionalState NewState)
+{
+ /*!< Wait Until the last LCD RAM update finish */
+ while(LCD_GetFlagStatus(LCD_FLAG_UDR) != RESET)
+ {
+ }
+
+ if (NewState != DISABLE)
+ {
+ /* Set logo on */
+ LCD->RAM[LCD_RAMRegister_0] |= (uint32_t)0x00000040;
+ }
+ else
+ {
+ /* Set logo of */
+ LCD->RAM[LCD_RAMRegister_0] &= (uint32_t)0xFFFFFFBF;
+ }
+
+ /*!< Request LCD RAM update */
+ LCD_UpdateDisplayRequest();
+}
+
+/**
+ * @brief Configure the LCD Battery Level.
+ * @param BatteryLevel: Specify the Battery Level to set.
+ * @retval None
+ */
+void LCD_GLASS_BatteryLevelConfig(BatteryLevel_TypeDef BatteryLevel)
+{
+ /*!< Wait Until the last LCD RAM update finish */
+ while(LCD_GetFlagStatus(LCD_FLAG_UDR) != RESET)
+ {
+ }
+
+ switch (BatteryLevel)
+ {
+ /* BATTERYLEVEL 1/4 */
+ case BATTERYLEVEL_1_4:
+ LCD->RAM[LCD_RAMRegister_0] &= (uint32_t)0xFFFFFFF6;
+ LCD->RAM[LCD_RAMRegister_2] &= (uint32_t)0xFFFFFFF6;
+ /* Set BATTERYLEVEL_1_4 on */
+ LCD->RAM[LCD_RAMRegister_0] |= (uint32_t)0x00000001;
+ break;
+
+ /* BATTERYLEVEL 1/2 */
+ case BATTERYLEVEL_1_2:
+ LCD->RAM[LCD_RAMRegister_0] &= (uint32_t)0xFFFFFFF6;
+ LCD->RAM[LCD_RAMRegister_2] &= (uint32_t)0xFFFFFFF6;
+ /* Set BatteryLevel_1_4 on */
+ LCD->RAM[LCD_RAMRegister_0] |= (uint32_t)0x00000001;
+ /* Set BatteryLevel_1_2 on */
+ LCD->RAM[LCD_RAMRegister_2] |= (uint32_t)0x00000001;
+ break;
+
+ /* Battery Level 3/4 */
+ case BATTERYLEVEL_3_4:
+ LCD->RAM[LCD_RAMRegister_0] &= (uint32_t)0xFFFFFFF6;
+ LCD->RAM[LCD_RAMRegister_2] &= (uint32_t)0xFFFFFFF6;
+ /* Set BATTERYLEVEL_3_4 on */
+ /* Set BatteryLevel_1_4 on */
+ LCD->RAM[LCD_RAMRegister_0] |= (uint32_t)0x00000001;
+ /* Set BatteryLevel_1_2 on */
+ LCD->RAM[LCD_RAMRegister_2] |= (uint32_t)0x00000009;
+ break;
+
+ /* BATTERYLEVEL_FULL */
+ case BATTERYLEVEL_FULL:
+ /* Set BATTERYLEVEL_3_4 on */
+ /* Set BatteryLevel_1_4 on */
+ LCD->RAM[LCD_RAMRegister_0] |= (uint32_t)0x00000009;
+ /* Set BATTERYLEVEL_FULL on */
+ /* Set BatteryLevel_1_2 on */
+ LCD->RAM[LCD_RAMRegister_2] |= (uint32_t)0x00000009;
+ break;
+
+ case BATTERYLEVEL_OFF:
+ /* Set BATTERYLEVEL_3_4 off */
+ /* Set BATTERYLEVEL_1_4 off */
+ LCD->RAM[LCD_RAMRegister_0] &= (uint32_t)0xFFFFFFF6;
+ /* Set BATTERYLEVEL_1_2 off */
+ /* Set BATTERYLEVEL_FULL off */
+ LCD->RAM[LCD_RAMRegister_2] &= (uint32_t)0xFFFFFFF6;
+ break;
+
+ default:
+ break;
+ }
+ /*!< Request LCD RAM update */
+ LCD_UpdateDisplayRequest();
+}
+
+/**
+ * @brief Configure the LCD ArrowDirection.
+ * @param Arrow: Specify the ArrowDirection to set.
+ * @retval None
+ */
+void LCD_GLASS_ArrowConfig(ArrowDirection_TypeDef ArrowDirection)
+{
+ /*!< Wait Until the last LCD RAM update finish */
+ while(LCD_GetFlagStatus(LCD_FLAG_UDR) != RESET)
+ {
+ }
+
+ switch (ArrowDirection)
+ {
+ /* ARROWDIRECTION_UP */
+ case ARROWDIRECTION_UP:
+ /* Set ARROWDIRECTION_UP on */
+ LCD->RAM[LCD_RAMRegister_0] |= (uint32_t)0x00001000;
+ break;
+
+ /* ARROWDIRECTION_LEFT */
+ case ARROWDIRECTION_LEFT :
+ /* Set ARROWDIRECTION_LEFT on */
+ LCD->RAM[LCD_RAMRegister_2] |= (uint32_t)0x00001000;
+ break;
+
+ /* ARROWDIRECTION_DOWN */
+ case ARROWDIRECTION_DOWN:
+ /* Set ARROWDIRECTION_DOWN on */
+ LCD->RAM[LCD_RAMRegister_2] |= (uint32_t)0x00008000;
+ break;
+
+ /* ARROWDIRECTION_RIGHT */
+ case ARROWDIRECTION_RIGHT:
+ /* Set ARROWDIRECTION_RIGHT on */
+ LCD->RAM[LCD_RAMRegister_0] |= (uint32_t)0x00008000;
+ break;
+
+ case ARROWDIRECTION_OFF:
+ /* Set ARROWDIRECTION_UP off */
+ /* Set ARROWDIRECTION_RIGHT off */
+ LCD->RAM[LCD_RAMRegister_0] &= (uint32_t)0xFFFF6FFF;
+ /* Set ARROWDIRECTION_LEFT off */
+ /* Set ARROWDIRECTION_DOWN off */
+ LCD->RAM[LCD_RAMRegister_2] &= (uint32_t)0xFFFF6FFF;
+ break;
+
+ default:
+ break;
+ }
+ /*!< Request LCD RAM update */
+ LCD_UpdateDisplayRequest();
+}
+
+/**
+ * @brief Configure the LCD Temperature level display .
+ * @param Temperature: indicate the Temperature level to set.
+ * @retval None
+ */
+void LCD_GLASS_TemperatureConfig(TemperatureLevel_TypeDef Temperature)
+{
+ /*!< Wait Until the last LCD RAM update finish */
+ while(LCD_GetFlagStatus(LCD_FLAG_UDR) != RESET)
+ {
+ }
+
+ switch (Temperature)
+ {
+ /* Temperature level 1*/
+ case TEMPERATURELEVEL_1 :
+ /* Clear Temperature level 5 */
+ LCD->RAM[LCD_RAMRegister_0] &= (uint32_t)0xFFFFFDFF;
+ /* Clear Temperature level 6 */
+ LCD->RAM[LCD_RAMRegister_2] &= (uint32_t)0xFFFFFDFF;
+ /* Clear Temperature level 4 and level 2 */
+ LCD->RAM[LCD_RAMRegister_4] &= (uint32_t)0xFFFFF3FF;
+ /* Clear Temperature level 1 and level 3 */
+ LCD->RAM[LCD_RAMRegister_6] &= (uint32_t)0xFFFFF3FF;
+ /* Set Temperature level 1*/
+ LCD->RAM[LCD_RAMRegister_2] |= (uint32_t)0x00000200;
+ break;
+
+ /* Temperature level 2 */
+ case TEMPERATURELEVEL_2:
+ /* Clear Temperature level 5 */
+ LCD->RAM[LCD_RAMRegister_0] &= (uint32_t)0xFFFFFDFF;
+ /* Clear Temperature level 6 */
+ LCD->RAM[LCD_RAMRegister_2] &= (uint32_t)0xFFFFFDFF;
+ /* Clear Temperature level 4 and level 2 */
+ LCD->RAM[LCD_RAMRegister_4] &= (uint32_t)0xFFFFF3FF;
+ /* Clear Temperature level 1 and level 3 */
+ LCD->RAM[LCD_RAMRegister_6] &= (uint32_t)0xFFFFF3FF;
+ /* Set Temperature level 1 */
+ LCD->RAM[LCD_RAMRegister_2] |= (uint32_t)0x00000200;
+ /* Set Temperature level 2 */
+ LCD->RAM[LCD_RAMRegister_0] |= (uint32_t)0x00000200;
+ break;
+
+ /* Temperature level 3 */
+ case TEMPERATURELEVEL_3:
+ /* Clear Temperature level 5 */
+ LCD->RAM[LCD_RAMRegister_0] &= (uint32_t)0xFFFFFDFF;
+ /* Clear Temperature level 6 */
+ LCD->RAM[LCD_RAMRegister_2] &= (uint32_t)0xFFFFFDFF;
+ /* Clear Temperature level 4 and level 2 */
+ LCD->RAM[LCD_RAMRegister_4] &= (uint32_t)0xFFFFF3FF;
+ /* Clear Temperature level 1 and level 3 */
+ LCD->RAM[LCD_RAMRegister_6] &= (uint32_t)0xFFFFF3FF;
+ /* Set Temperature level 1 */
+ LCD->RAM[LCD_RAMRegister_2] |= (uint32_t)0x00000200;
+ /* Set Temperature level 2 */
+ LCD->RAM[LCD_RAMRegister_0] |= (uint32_t)0x00000200;
+ /* Set Temperature level 3 */
+ LCD->RAM[LCD_RAMRegister_4] |= (uint32_t)0x00000400;
+ break;
+
+ /* Temperature level 4*/
+ case TEMPERATURELEVEL_4:
+ /* Clear Temperature level 5 */
+ LCD->RAM[LCD_RAMRegister_0] &= (uint32_t)0xFFFFFDFF;
+ /* Clear Temperature level 6 */
+ LCD->RAM[LCD_RAMRegister_2] &= (uint32_t)0xFFFFFDFF;
+ /* Clear Temperature level 4 and level 2 */
+ LCD->RAM[LCD_RAMRegister_4] &= (uint32_t)0xFFFFF3FF;
+ /* Clear Temperature level 1 and level 3 */
+ LCD->RAM[LCD_RAMRegister_6] &= (uint32_t)0xFFFFF3FF;
+ /* Set Temperature level 1 */
+ LCD->RAM[LCD_RAMRegister_2] |= (uint32_t)0x00000200;
+ /* Set Temperature level 2 */
+ LCD->RAM[LCD_RAMRegister_0] |= (uint32_t)0x00000200;
+ /* Set Temperature level 3 */
+ LCD->RAM[LCD_RAMRegister_4] |= (uint32_t)0x00000400;
+ /* Set Temperature level 4 */
+ LCD->RAM[LCD_RAMRegister_6] |= (uint32_t)0x00000400;
+ break;
+
+ /* Temperature_2*/
+ case TEMPERATURELEVEL_5:
+ /* Clear Temperature level 5 */
+ LCD->RAM[LCD_RAMRegister_0] &= (uint32_t)0xFFFFFDFF;
+ /* Clear Temperature level 6 */
+ LCD->RAM[LCD_RAMRegister_2] &= (uint32_t)0xFFFFFDFF;
+ /* Clear Temperature level 4 and level 2 */
+ LCD->RAM[LCD_RAMRegister_4] &= (uint32_t)0xFFFFF3FF;
+ /* Clear Temperature level 1 and level 3 */
+ LCD->RAM[LCD_RAMRegister_6] &= (uint32_t)0xFFFFF3FF;
+ /* Set Temperature level 1 */
+ LCD->RAM[LCD_RAMRegister_2] |= (uint32_t)0x00000200;
+ /* Set Temperature level 2 */
+ LCD->RAM[LCD_RAMRegister_0] |= (uint32_t)0x00000200;
+ /* Set Temperature level 3 and level 5 */
+ LCD->RAM[LCD_RAMRegister_4] |= (uint32_t)0x00000C00;
+ /* Set Temperature level 4 */
+ LCD->RAM[LCD_RAMRegister_6] |= (uint32_t)0x00000400;
+ break;
+
+ /* Temperature_6*/
+ case TEMPERATURELEVEL_6:
+ /* Clear Temperature level 5 */
+ LCD->RAM[LCD_RAMRegister_0] &= (uint32_t)0xFFFFFDFF;
+ /* Clear Temperature level 6 */
+ LCD->RAM[LCD_RAMRegister_2] &= (uint32_t)0xFFFFFDFF;
+ /* Clear Temperature level 4 and level 2 */
+ LCD->RAM[LCD_RAMRegister_4] &= (uint32_t)0xFFFFF3FF;
+ /* Clear Temperature level 1 and level 3 */
+ LCD->RAM[LCD_RAMRegister_6] &= (uint32_t)0xFFFFF3FF;
+ /* Set Temperature level 1 */
+ LCD->RAM[LCD_RAMRegister_2] |= (uint32_t)0x00000200;
+ /* Set Temperature level 2 */
+ LCD->RAM[LCD_RAMRegister_0] |= (uint32_t)0x00000200;
+ /* Set Temperature level 3 and level 5 */
+ LCD->RAM[LCD_RAMRegister_4] |= (uint32_t)0x00000C00;
+ /* Set Temperature level 4 and level 6 */
+ LCD->RAM[LCD_RAMRegister_6] |= (uint32_t)0x00000C00;
+ break;
+
+ case TEMPERATURELEVEL_OFF:
+ /* Clear Temperature level 5 */
+ LCD->RAM[LCD_RAMRegister_0] &= (uint32_t)0xFFFFFDFF;
+ /* Clear Temperature level 6 */
+ LCD->RAM[LCD_RAMRegister_2] &= (uint32_t)0xFFFFFDFF;
+ /* Clear Temperature level 4 and level 2 */
+ LCD->RAM[LCD_RAMRegister_4] &= (uint32_t)0xFFFFF3FF;
+ /* Clear Temperature level 1 and level 3 */
+ LCD->RAM[LCD_RAMRegister_6] &= (uint32_t)0xFFFFF3FF;
+ break;
+
+ default:
+ break;
+ }
+
+ /*!< Request LCD RAM update */
+ LCD_UpdateDisplayRequest();
+}
+
+/**
+ * @brief Configure the LCD Value Unit.
+ * @param ValueUnit: indicate the Value Unit to set.
+ * @param NewState: enable or disable the Digit.
+ * @retval None
+ */
+void LCD_GLASS_ValueUnitConfig(ValueUnit_TypeDef ValueUnit)
+{
+ /*!< Wait Until the last LCD RAM update finish */
+ while(LCD_GetFlagStatus(LCD_FLAG_UDR) != RESET)
+ {
+ }
+
+ switch (ValueUnit)
+ {
+ /* VALUEUNIT MILLIAMPERE*/
+ case VALUEUNIT_MILLIAMPERE:
+ /* Set VALUEUNIT_MILLIAMPERE on */
+ LCD->RAM[LCD_RAMRegister_2] |= (uint32_t)0x00040000;
+ break;
+
+ /* VALUEUNIT MICROAMPERE)*/
+ case VALUEUNIT_MICROAMPERE:
+ /* Set VALUEUNIT_MICROAMPERE */
+ LCD->RAM[LCD_RAMRegister_0] |= (uint32_t)0x00040000;
+ break;
+
+ /* VALUEUNIT NANOAMPERE*/
+ case VALUEUNIT_NANOAMPERE:
+ /* Set VALUEUNIT_NANOAMPERE on */
+ LCD->RAM[LCD_RAMRegister_2] |= (uint32_t)0x00000040;
+ break;
+
+ case VALUEUNIT_OFF:
+ /* Set VALUEUNIT_MILLIAMPERE and VALUEUNIT_NANOAMPERE OFF */
+ LCD->RAM[LCD_RAMRegister_2] &= (uint32_t)0xFFFBFFBF;
+ /* Set VALUEUNIT_MICROAMPERE off */
+ LCD->RAM[LCD_RAMRegister_0] &= (uint32_t)0xFFFBFFFF;
+ break;
+
+ default:
+ break;
+ }
+ /*!< Request LCD RAM update */
+ LCD_UpdateDisplayRequest();
+}
+
+/**
+ * @brief Configure the LCD sign.
+ * @param Sign: indicate the sign to set.
+ * @param NewState: enable or disable the Digit.
+ * @retval None
+ */
+void LCD_GLASS_SignCmd(Sign_TypeDef Sign, FunctionalState NewState)
+{
+ /*!< Wait Until the last LCD RAM update finish */
+ while(LCD_GetFlagStatus(LCD_FLAG_UDR) != RESET)
+ {
+ }
+
+ if (NewState != DISABLE)
+ {
+ switch (Sign)
+ {
+ /* Sign positive */
+ case SIGN_POSITIVE:
+ /* Set SIGN_POSITIVE on */
+ LCD->RAM[LCD_RAMRegister_12] |= (uint32_t)0x00000800;
+ break;
+
+ /* Sign negative*/
+ case SIGN_NEGATIVE:
+ /* Set SIGN_NEGATIVE on */
+ LCD->RAM[LCD_RAMRegister_0] |= (uint32_t)0x00000800;
+ break;
+
+ default:
+ break;
+ }
+ }
+ else
+ {
+ switch (Sign)
+ {
+ /* Sign positive */
+ case SIGN_POSITIVE:
+ /* Set SIGN_POSITIVE off */
+ LCD->RAM[LCD_RAMRegister_12] &= (uint32_t)0xFFFFF7FF;
+ break;
+
+ /* Sign negative */
+ case SIGN_NEGATIVE:
+ /* Set SIGN_NEGATIVE off */
+ LCD->RAM[LCD_RAMRegister_0] &= (uint32_t)0xFFFFF7FF;
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ /*!< Request LCD RAM update */
+ LCD_UpdateDisplayRequest();
+}
+/**
+ * @brief Set Matrix Pixel on.
+ * @param PixelRow: Specify Matrix Row.
+ * @param PixelColumn: Specify Matrix Column.
+ * @retval None
+ */
+void LCD_GLASS_WriteMatrixPixel(PixelRow_TypeDef PixelRow, PixelColumn_TypeDef PixelColumn)
+{
+ /*!< Wait Until the last LCD RAM update finish */
+ while(LCD_GetFlagStatus(LCD_FLAG_UDR) != RESET)
+ {
+ }
+
+ switch (PixelRow)
+ {
+ case PIXELROW_1:
+ switch (PixelColumn)
+ {
+ case PIXELCOLUMN_1:
+ /* Position : Row = 1 , Column = 1 */
+ LCD->RAM[LCD_RAMRegister_6] |= (uint32_t)0x00000200;
+ break;
+
+ case PIXELCOLUMN_2:
+ /* Position : Row = 1 , Column = 2 */
+ LCD->RAM[LCD_RAMRegister_6] |= (uint32_t)0x00004000;
+ break;
+
+ case PIXELCOLUMN_3:
+ /* Position : Row = 1 , Column = 3 */
+ LCD->RAM[LCD_RAMRegister_6] |= (uint32_t)0x00002000;
+ break;
+
+ case PIXELCOLUMN_4:
+ /* Position : Row = 1 , Column = 4 */
+ LCD->RAM[LCD_RAMRegister_6] |= (uint32_t)0x00001000;
+ break;
+
+ case PIXELCOLUMN_5:
+ /* Position : Row = 1 , Column = 5 */
+ LCD->RAM[LCD_RAMRegister_6] |= (uint32_t)0x00020000;
+ break;
+
+ case PIXELCOLUMN_6:
+ /* Position : Row = 1 , Column = 6 */
+ LCD->RAM[LCD_RAMRegister_6] |= (uint32_t)0x00010000;
+ break;
+
+ case PIXELCOLUMN_7:
+ /* Position : Row = 1 , Column = 7 */
+ LCD->RAM[LCD_RAMRegister_6] |= (uint32_t)0x00008000;
+ break;
+
+ case PIXELCOLUMN_8:
+ /* Position : Row = 1 , Column = 8 */
+ LCD->RAM[LCD_RAMRegister_6] |= (uint32_t)0x00100000;
+ break;
+
+ case PIXELCOLUMN_9:
+ /* Position : Row = 1 , Column = 9 */
+ LCD->RAM[LCD_RAMRegister_6] |= (uint32_t)0x00080000;
+ break;
+
+ case PIXELCOLUMN_10:
+ /* Position : Row = 1 , Column = 10 */
+ LCD->RAM[LCD_RAMRegister_6] |= (uint32_t)0x00040000;
+ break;
+
+ case PIXELCOLUMN_11:
+ /* Position : Row = 1 , Column = 11 */
+ LCD->RAM[LCD_RAMRegister_6] |= (uint32_t)0x00000004;
+ break;
+
+ case PIXELCOLUMN_12:
+ /* Position : Row = 1 , Column = 12 */
+ LCD->RAM[LCD_RAMRegister_6] |= (uint32_t)0x00000002;
+ break;
+
+ case PIXELCOLUMN_13:
+ /* Position : Row = 1 , Column = 13 */
+ LCD->RAM[LCD_RAMRegister_6] |= (uint32_t)0x00000001;
+ break;
+
+ case PIXELCOLUMN_14:
+ /* Position : Row = 1 , Column = 14 */
+ LCD->RAM[LCD_RAMRegister_6] |= (uint32_t)0x00000020;
+ break;
+
+ case PIXELCOLUMN_15:
+ /* Position : Row = 1 , Column = 15 */
+ LCD->RAM[LCD_RAMRegister_6] |= (uint32_t)0x00000010;
+ break;
+
+ case PIXELCOLUMN_16:
+ /* Position : Row = 1 , Column = 16 */
+ LCD->RAM[LCD_RAMRegister_6] |= (uint32_t)0x00000008;
+ break;
+
+ case PIXELCOLUMN_17:
+ /* Position : Row = 1 , Column = 17 */
+ LCD->RAM[LCD_RAMRegister_6] |= (uint32_t)0x00000100;
+ break;
+
+ case PIXELCOLUMN_18:
+ /* Position : Row = 1 , Column = 18 */
+ LCD->RAM[LCD_RAMRegister_6] |= (uint32_t)0x00000080;
+ break;
+
+ case PIXELCOLUMN_19:
+ /* Position : Row = 1 , Column = 19 */
+ LCD->RAM[LCD_RAMRegister_6] |= (uint32_t)0x00000040;
+ break;
+
+ default:
+ break;
+
+ }
+ break;
+
+ case PIXELROW_2:
+ switch (PixelColumn)
+ {
+ case PIXELCOLUMN_1:
+ /* Position : Row = 2 , Column = 1 */
+ LCD->RAM[LCD_RAMRegister_4] |= (uint32_t)0x00000200;
+ break;
+
+ case PIXELCOLUMN_2:
+ /* Position : Row = 2 , Column = 2 */
+ LCD->RAM[LCD_RAMRegister_4] |= (uint32_t)0x00004000;
+ break;
+
+ case PIXELCOLUMN_3:
+ /* Position : Row = 2 , Column = 3 */
+ LCD->RAM[LCD_RAMRegister_4] |= (uint32_t)0x00002000;
+ break;
+
+ case PIXELCOLUMN_4:
+ /* Position : Row = 2 , Column = 4 */
+ LCD->RAM[LCD_RAMRegister_4] |= (uint32_t)0x00001000;
+ break;
+
+ case PIXELCOLUMN_5:
+ /* Position : Row = 2 , Column = 5 */
+ LCD->RAM[LCD_RAMRegister_4] |= (uint32_t)0x00020000;
+ break;
+
+ case PIXELCOLUMN_6:
+ /* Position : Row = 2 , Column = 6 */
+ LCD->RAM[LCD_RAMRegister_4] |= (uint32_t)0x00010000;
+ break;
+
+ case PIXELCOLUMN_7:
+ /* Position : Row = 2 , Column = 7 */
+ LCD->RAM[LCD_RAMRegister_4] |= (uint32_t)0x00008000;
+ break;
+
+ case PIXELCOLUMN_8:
+ /* Position : Row = 2 , Column = 8 */
+ LCD->RAM[LCD_RAMRegister_4] |= (uint32_t)0x00100000;
+ break;
+
+ case PIXELCOLUMN_9:
+ /* Position : Row = 2 , Column = 9 */
+ LCD->RAM[LCD_RAMRegister_4] |= (uint32_t)0x00080000;
+ break;
+
+ case PIXELCOLUMN_10:
+ /* Position : Row = 2 , Column = 10 */
+ LCD->RAM[LCD_RAMRegister_4] |= (uint32_t)0x00040000;
+ break;
+
+ case PIXELCOLUMN_11:
+ /* Position : Row = 2 , Column = 11 */
+ LCD->RAM[LCD_RAMRegister_4] |= (uint32_t)0x00000004;
+ break;
+
+ case PIXELCOLUMN_12:
+ /* Position : Row = 2 , Column = 12 */
+ LCD->RAM[LCD_RAMRegister_4] |= (uint32_t)0x00000002;
+ break;
+
+ case PIXELCOLUMN_13:
+ /* Position : Row = 2 , Column = 13 */
+ LCD->RAM[LCD_RAMRegister_4] |= (uint32_t)0x00000001;
+ break;
+
+ case PIXELCOLUMN_14:
+ /* Position : Row = 2 , Column = 14 */
+ LCD->RAM[LCD_RAMRegister_4] |= (uint32_t)0x00000020;
+ break;
+
+ case PIXELCOLUMN_15:
+ /* Position : Row = 2 , Column = 15 */
+ LCD->RAM[LCD_RAMRegister_4] |= (uint32_t)0x00000010;
+ break;
+
+ case PIXELCOLUMN_16:
+ /* Position : Row = 2 , Column = 16 */
+ LCD->RAM[LCD_RAMRegister_4] |= (uint32_t)0x00000008;
+ break;
+
+ case PIXELCOLUMN_17:
+ /* Position : Row = 2 , Column = 17 */
+ LCD->RAM[LCD_RAMRegister_4] |= (uint32_t)0x00000100;
+ break;
+
+ case PIXELCOLUMN_18:
+ /* Position : Row = 2 , Column = 18 */
+ LCD->RAM[LCD_RAMRegister_4] |= (uint32_t)0x00000080;
+ break;
+
+ case PIXELCOLUMN_19:
+ /* Position : Row = 2 , Column = 19 */
+ LCD->RAM[LCD_RAMRegister_4] |= (uint32_t)0x00000040;
+ break;
+
+ default:
+ break;
+ }
+ break;
+
+ case PIXELROW_3:
+ switch (PixelColumn)
+ {
+ case PIXELCOLUMN_1:
+ /* Position : Row = 3 , Column = 1 */
+ LCD->RAM[LCD_RAMRegister_4] |= (uint32_t)0x00200000;
+ break;
+
+ case PIXELCOLUMN_2:
+ /* Position : Row = 3 , Column = 2 */
+ LCD->RAM[LCD_RAMRegister_4] |= (uint32_t)0x00400000;
+ break;
+
+ case PIXELCOLUMN_3:
+ /* Position : Row = 3 , Column = 3 */
+ LCD->RAM[LCD_RAMRegister_4] |= (uint32_t)0x00800000;
+ break;
+
+ case PIXELCOLUMN_4:
+ /* Position : Row = 3 , Column = 4 */
+ LCD->RAM[LCD_RAMRegister_4] |= (uint32_t)0x01000000;
+ break;
+
+ case PIXELCOLUMN_5:
+ /* Position : Row = 3 , Column = 5 */
+ LCD->RAM[LCD_RAMRegister_4] |= (uint32_t)0x02000000;
+ break;
+
+ case PIXELCOLUMN_6:
+ /* Position : Row = 3 , Column = 6 */
+ LCD->RAM[LCD_RAMRegister_4] |= (uint32_t)0x04000000;
+ break;
+
+ case PIXELCOLUMN_7:
+ /* Position : Row = 3 , Column = 7 */
+ LCD->RAM[LCD_RAMRegister_4] |= (uint32_t)0x08000000;
+ break;
+
+ case PIXELCOLUMN_8:
+ /* Position : Row = 3 , Column = 8 */
+ LCD->RAM[LCD_RAMRegister_4] |= (uint32_t)0x10000000;
+ break;
+
+ case PIXELCOLUMN_9:
+ /* Position : Row = 3 , Column = 9*/
+ LCD->RAM[LCD_RAMRegister_4] |= (uint32_t)0x20000000;
+ break;
+
+ case PIXELCOLUMN_10:
+ /* Position : Row = 3 , Column = 10*/
+ LCD->RAM[LCD_RAMRegister_4] |= (uint32_t)0x40000000;
+ break;
+
+ case PIXELCOLUMN_11:
+ /* Position : Row = 3 , Column = 11*/
+ LCD->RAM[LCD_RAMRegister_4] |= (uint32_t)0x80000000;
+ break;
+
+ case PIXELCOLUMN_12:
+ /* Position : Row = 3 , Column = 12*/
+ LCD->RAM[LCD_RAMRegister_5] |= (uint32_t)0x00000001;
+ break;
+
+ case PIXELCOLUMN_13:
+ /* Position : Row = 3 , Column = 13*/
+ LCD->RAM[LCD_RAMRegister_5] |= (uint32_t)0x00000002;
+ break;
+
+ case PIXELCOLUMN_14:
+ /* Position : Row = 3 , Column = 14*/
+ LCD->RAM[LCD_RAMRegister_5] |= (uint32_t)0x00000004;
+ break;
+
+ case PIXELCOLUMN_15:
+ /* Position : Row = 3 , Column = 15*/
+ LCD->RAM[LCD_RAMRegister_5] |= (uint32_t)0x00000008;
+ break;
+
+ case PIXELCOLUMN_16:
+ /* Position : Row = 3 , Column = 16*/
+ LCD->RAM[LCD_RAMRegister_5] |= (uint32_t)0x00000010;
+ break;
+
+ case PIXELCOLUMN_17:
+ /* Position : Row = 3 , Column = 17*/
+ LCD->RAM[LCD_RAMRegister_5] |= (uint32_t)0x00000020;
+ break;
+
+ case PIXELCOLUMN_18:
+ /* Position : Row = 3 , Column = 18*/
+ LCD->RAM[LCD_RAMRegister_5] |= (uint32_t)0x00000040;
+ break;
+
+ case PIXELCOLUMN_19:
+ /* Position : Row = 3 , Column = 19 */
+ LCD->RAM[LCD_RAMRegister_5] |= (uint32_t)0x00000080;
+ break;
+
+ default:
+ break;
+ }
+ break;
+
+ case PIXELROW_4:
+ switch (PixelColumn)
+ {
+ case PIXELCOLUMN_1:
+ /* Position : Row = 4 , Column = 1 */
+ LCD->RAM[LCD_RAMRegister_6] |= (uint32_t)0x00200000;
+ break;
+
+ case PIXELCOLUMN_2:
+ /* Position : Row = 4 , Column = 2 */
+ LCD->RAM[LCD_RAMRegister_6] |= (uint32_t)0x00400000;
+ break;
+
+ case PIXELCOLUMN_3:
+ /* Position : Row = 4 , Column = 3 */
+ LCD->RAM[LCD_RAMRegister_6] |= (uint32_t)0x00800000;
+ break;
+
+ case PIXELCOLUMN_4:
+ /* Position : Row = 4 , Column = 4 */
+ LCD->RAM[LCD_RAMRegister_6] |= (uint32_t)0x01000000;
+ break;
+
+ case PIXELCOLUMN_5:
+ /* Position : Row = 4 , Column = 5 */
+ LCD->RAM[LCD_RAMRegister_6] |= (uint32_t)0x02000000;
+ break;
+
+ case PIXELCOLUMN_6:
+ /* Position : Row = 4 , Column = 6 */
+ LCD->RAM[LCD_RAMRegister_6] |= (uint32_t)0x04000000;
+ break;
+
+ case PIXELCOLUMN_7:
+ /* Position : Row = 4 , Column = 7 */
+ LCD->RAM[LCD_RAMRegister_6] |= (uint32_t)0x08000000;
+ break;
+
+ case PIXELCOLUMN_8:
+ /* Position : Row = 4 , Column = 8 */
+ LCD->RAM[LCD_RAMRegister_6] |= (uint32_t)0x10000000;
+ break;
+
+ case PIXELCOLUMN_9:
+ /* Position : Row = 4 , Column = 9*/
+ LCD->RAM[LCD_RAMRegister_6] |= (uint32_t)0x20000000;
+ break;
+
+ case PIXELCOLUMN_10:
+ /* Position : Row = 4 , Column = 10*/
+ LCD->RAM[LCD_RAMRegister_6] |= (uint32_t)0x40000000;
+ break;
+
+ case PIXELCOLUMN_11:
+ /* Position : Row = 4 , Column = 11*/
+ LCD->RAM[LCD_RAMRegister_6] |= (uint32_t)0x80000000;
+ break;
+
+ case PIXELCOLUMN_12:
+ /* Position : Row = 4 , Column = 12*/
+ LCD->RAM[LCD_RAMRegister_7] |= (uint32_t)0x00000001;
+ break;
+
+ case PIXELCOLUMN_13:
+ /* Position : Row = 4 , Column = 13*/
+ LCD->RAM[LCD_RAMRegister_7] |= (uint32_t)0x00000002;
+ break;
+
+ case PIXELCOLUMN_14:
+ /* Position : Row = 4 , Column = 14*/
+ LCD->RAM[LCD_RAMRegister_7] |= (uint32_t)0x00000004;
+ break;
+
+ case PIXELCOLUMN_15:
+ /* Position : Row = 4 , Column = 15*/
+ LCD->RAM[LCD_RAMRegister_7] |= (uint32_t)0x00000008;
+ break;
+
+ case PIXELCOLUMN_16:
+ /* Position : Row = 4 , Column = 16*/
+ LCD->RAM[LCD_RAMRegister_7] |= (uint32_t)0x00000010;
+ break;
+
+ case PIXELCOLUMN_17:
+ /* Position : Row = 4 , Column = 17*/
+ LCD->RAM[LCD_RAMRegister_7] |= (uint32_t)0x00000020;
+ break;
+
+ case PIXELCOLUMN_18:
+ /* Position : Row = 4 , Column = 18*/
+ LCD->RAM[LCD_RAMRegister_7] |= (uint32_t)0x00000040;
+ break;
+
+ case PIXELCOLUMN_19:
+ /* Position : Row = 4 , Column = 19 */
+ LCD->RAM[LCD_RAMRegister_7] |= (uint32_t)0x00000080;
+ break;
+
+ default:
+ break;
+
+ }
+ break;
+
+ case PIXELROW_5:
+ switch (PixelColumn)
+ {
+ case PIXELCOLUMN_1:
+ /* Position : Row = 5 , Column = 1 */
+ LCD->RAM[LCD_RAMRegister_0] |= (uint32_t)0x00200000;
+ break;
+
+ case PIXELCOLUMN_2:
+ /* Position : Row = 5 , Column = 2 */
+ LCD->RAM[LCD_RAMRegister_0] |= (uint32_t)0x00400000;
+ break;
+
+ case PIXELCOLUMN_3:
+ /* Position : Row = 5 , Column = 3 */
+ LCD->RAM[LCD_RAMRegister_0] |= (uint32_t)0x00800000;
+ break;
+
+ case PIXELCOLUMN_4:
+ /* Position : Row = 5 , Column = 4 */
+ LCD->RAM[LCD_RAMRegister_0] |= (uint32_t)0x01000000;
+ break;
+
+ case PIXELCOLUMN_5:
+ /* Position : Row = 5 , Column = 5 */
+ LCD->RAM[LCD_RAMRegister_0] |= (uint32_t)0x02000000;
+ break;
+
+ case PIXELCOLUMN_6:
+ /* Position : Row = 5 , Column = 6 */
+ LCD->RAM[LCD_RAMRegister_0] |= (uint32_t)0x04000000;
+ break;
+
+ case PIXELCOLUMN_7:
+ /* Position : Row = 5 , Column = 7 */
+ LCD->RAM[LCD_RAMRegister_0] |= (uint32_t)0x08000000;
+ break;
+
+ case PIXELCOLUMN_8:
+ /* Position : Row = 5 , Column = 8 */
+ LCD->RAM[LCD_RAMRegister_0] |= (uint32_t)0x10000000;
+ break;
+
+ case PIXELCOLUMN_9:
+ /* Position : Row = 5 , Column = 9*/
+ LCD->RAM[LCD_RAMRegister_0] |= (uint32_t)0x20000000;
+ break;
+
+ case PIXELCOLUMN_10:
+ /* Position : Row = 5 , Column = 10*/
+ LCD->RAM[LCD_RAMRegister_0] |= (uint32_t)0x40000000;
+ break;
+
+ case PIXELCOLUMN_11:
+ /* Position : Row = 5 , Column = 11*/
+ LCD->RAM[LCD_RAMRegister_0] |= (uint32_t)0x80000000;
+ break;
+
+ case PIXELCOLUMN_12:
+ /* Position : Row = 5 , Column = 12*/
+ LCD->RAM[LCD_RAMRegister_1] |= (uint32_t)0x00000001;
+ break;
+
+ case PIXELCOLUMN_13:
+ /* Position : Row = 5 , Column = 13*/
+ LCD->RAM[LCD_RAMRegister_1] |= (uint32_t)0x00000002;
+ break;
+
+ case PIXELCOLUMN_14:
+ /* Position : Row = 5 , Column = 14*/
+ LCD->RAM[LCD_RAMRegister_1] |= (uint32_t)0x00000004;
+ break;
+
+ case PIXELCOLUMN_15:
+ /* Position : Row = 5 , Column = 15*/
+ LCD->RAM[LCD_RAMRegister_1] |= (uint32_t)0x00000008;
+ break;
+
+ case PIXELCOLUMN_16:
+ /* Position : Row = 5 , Column = 16*/
+ LCD->RAM[LCD_RAMRegister_1] |= (uint32_t)0x00000010;
+ break;
+
+ case PIXELCOLUMN_17:
+ /* Position : Row = 5 , Column = 17*/
+ LCD->RAM[LCD_RAMRegister_1] |= (uint32_t)0x00000020;
+ break;
+
+ case PIXELCOLUMN_18:
+ /* Position : Row = 5 , Column = 18*/
+ LCD->RAM[LCD_RAMRegister_1] |= (uint32_t)0x00000040;
+ break;
+
+ case PIXELCOLUMN_19:
+ /* Position : Row = 5 , Column = 19 */
+ LCD->RAM[LCD_RAMRegister_1] |= (uint32_t)0x00000080;
+ break;
+
+ default:
+ break;
+ }
+ break;
+
+ case PIXELROW_6:
+ switch (PixelColumn)
+ {
+ case PIXELCOLUMN_1:
+ /* Position : Row = 6 , Column = 1 */
+ LCD->RAM[LCD_RAMRegister_2] |= (uint32_t)0x00200000;
+ break;
+
+ case PIXELCOLUMN_2:
+ /* Position : Row = 6 , Column = 2 */
+ LCD->RAM[LCD_RAMRegister_2] |= (uint32_t)0x00400000;
+ break;
+
+ case PIXELCOLUMN_3:
+ /* Position : Row = 6 , Column = 3 */
+ LCD->RAM[LCD_RAMRegister_2] |= (uint32_t)0x00800000;
+ break;
+
+ case PIXELCOLUMN_4:
+ /* Position : Row = 6 , Column = 4 */
+ LCD->RAM[LCD_RAMRegister_2] |= (uint32_t)0x01000000;
+ break;
+
+ case PIXELCOLUMN_5:
+ /* Position : Row = 6 , Column = 5 */
+ LCD->RAM[LCD_RAMRegister_2] |= (uint32_t)0x02000000;
+ break;
+
+ case PIXELCOLUMN_6:
+ /* Position : Row = 6 , Column = 6 */
+ LCD->RAM[LCD_RAMRegister_2] |= (uint32_t)0x04000000;
+ break;
+
+ case PIXELCOLUMN_7:
+ /* Position : Row = 6 , Column = 7 */
+ LCD->RAM[LCD_RAMRegister_2] |= (uint32_t)0x08000000;
+ break;
+
+ case PIXELCOLUMN_8:
+ /* Position : Row = 6 , Column = 8 */
+ LCD->RAM[LCD_RAMRegister_2] |= (uint32_t)0x10000000;
+ break;
+
+ case PIXELCOLUMN_9:
+ /* Position : Row = 6 , Column = 9*/
+ LCD->RAM[LCD_RAMRegister_2] |= (uint32_t)0x20000000;
+ break;
+
+ case PIXELCOLUMN_10:
+ /* Position : Row = 6 , Column = 10*/
+ LCD->RAM[LCD_RAMRegister_2] |= (uint32_t)0x40000000;
+ break;
+
+ case PIXELCOLUMN_11:
+ /* Position : Row = 6 , Column = 11*/
+ LCD->RAM[LCD_RAMRegister_2] |= (uint32_t)0x80000000;
+ break;
+
+ case PIXELCOLUMN_12:
+ /* Position : Row = 6 , Column = 12*/
+ LCD->RAM[LCD_RAMRegister_3] |= (uint32_t)0x00000001;
+ break;
+
+ case PIXELCOLUMN_13:
+ /* Position : Row = 6 , Column = 13*/
+ LCD->RAM[LCD_RAMRegister_3] |= (uint32_t)0x00000002;
+ break;
+
+ case PIXELCOLUMN_14:
+ /* Position : Row = 6 , Column = 14*/
+ LCD->RAM[LCD_RAMRegister_3] |= (uint32_t)0x00000004;
+ break;
+
+ case PIXELCOLUMN_15:
+ /* Position : Row = 6 , Column = 15*/
+ LCD->RAM[LCD_RAMRegister_3] |= (uint32_t)0x00000008;
+ break;
+
+ case PIXELCOLUMN_16:
+ /* Position : Row = 6 , Column = 16*/
+ LCD->RAM[LCD_RAMRegister_3] |= (uint32_t)0x00000010;
+ break;
+
+ case PIXELCOLUMN_17:
+ /* Position : Row = 6 , Column = 17*/
+ LCD->RAM[LCD_RAMRegister_3] |= (uint32_t)0x00000020;
+ break;
+
+ case PIXELCOLUMN_18:
+ /* Position : Row = 6 , Column = 18*/
+ LCD->RAM[LCD_RAMRegister_3] |= (uint32_t)0x00000040;
+ break;
+
+ case PIXELCOLUMN_19:
+ /* Position : Row = 6 , Column = 19 */
+ LCD->RAM[LCD_RAMRegister_3] |= (uint32_t)0x00000080;
+ break;
+
+ default:
+ break;
+ }
+ break;
+
+ case PIXELROW_7:
+ switch (PixelColumn)
+ {
+ case PIXELCOLUMN_1:
+ /* Position : Row = 7 , Column = 1 */
+ LCD->RAM[LCD_RAMRegister_14] |= (uint32_t)0x00200000;
+ break;
+
+ case PIXELCOLUMN_2:
+ /* Position : Row = 7 , Column = 2 */
+ LCD->RAM[LCD_RAMRegister_14] |= (uint32_t)0x00400000;
+ break;
+
+ case PIXELCOLUMN_3:
+ /* Position : Row = 7 , Column = 3 */
+ LCD->RAM[LCD_RAMRegister_14] |= (uint32_t)0x00800000;
+ break;
+
+ case PIXELCOLUMN_4:
+ /* Position : Row = 7 , Column = 4 */
+ LCD->RAM[LCD_RAMRegister_14] |= (uint32_t)0x01000000;
+ break;
+
+ case PIXELCOLUMN_5:
+ /* Position : Row = 7 , Column = 5 */
+ LCD->RAM[LCD_RAMRegister_14] |= (uint32_t)0x02000000;
+ break;
+
+ case PIXELCOLUMN_6:
+ /* Position : Row = 7 , Column = 6 */
+ LCD->RAM[LCD_RAMRegister_14] |= (uint32_t)0x04000000;
+ break;
+
+ case PIXELCOLUMN_7:
+ /* Position : Row = 7 , Column = 7 */
+ LCD->RAM[LCD_RAMRegister_14] |= (uint32_t)0x08000000;
+ break;
+
+ case PIXELCOLUMN_8:
+ /* Position : Row = 7 , Column = 8 */
+ LCD->RAM[LCD_RAMRegister_14] |= (uint32_t)0x10000000;
+ break;
+
+ case PIXELCOLUMN_9:
+ /* Position : Row = 7 , Column = 9*/
+ LCD->RAM[LCD_RAMRegister_14] |= (uint32_t)0x20000000;
+ break;
+
+ case PIXELCOLUMN_10:
+ /* Position : Row = 7 , Column = 10*/
+ LCD->RAM[LCD_RAMRegister_14] |= (uint32_t)0x40000000;
+ break;
+
+ case PIXELCOLUMN_11:
+ /* Position : Row = 7 , Column = 11*/
+ LCD->RAM[LCD_RAMRegister_14] |= (uint32_t)0x80000000;
+ break;
+
+ case PIXELCOLUMN_12:
+ /* Position : Row = 7 , Column = 12*/
+ LCD->RAM[LCD_RAMRegister_15] |= (uint32_t)0x00000001;
+ break;
+
+ case PIXELCOLUMN_13:
+ /* Position : Row = 7 , Column = 13*/
+ LCD->RAM[LCD_RAMRegister_15] |= (uint32_t)0x00000002;
+ break;
+
+ case PIXELCOLUMN_14:
+ /* Position : Row = 7 , Column = 14*/
+ LCD->RAM[LCD_RAMRegister_15] |= (uint32_t)0x00000004;
+ break;
+
+ case PIXELCOLUMN_15:
+ /* Position : Row = 7 , Column = 15*/
+ LCD->RAM[LCD_RAMRegister_15] |= (uint32_t)0x00000008;
+ break;
+
+ case PIXELCOLUMN_16:
+ /* Position : Row = 7 , Column = 16*/
+ LCD->RAM[LCD_RAMRegister_15] |= (uint32_t)0x00000010;
+ break;
+
+ case PIXELCOLUMN_17:
+ /* Position : Row = 7 , Column = 17*/
+ LCD->RAM[LCD_RAMRegister_15] |= (uint32_t)0x00000020;
+ break;
+
+ case PIXELCOLUMN_18:
+ /* Position : Row = 7 , Column = 18*/
+ LCD->RAM[LCD_RAMRegister_15] |= (uint32_t)0x00000040;
+ break;
+
+ case PIXELCOLUMN_19:
+ /* Position : Row = 7 , Column = 19 */
+ LCD->RAM[LCD_RAMRegister_15] |= (uint32_t)0x00000080;
+ break;
+
+ default:
+ break;
+ }
+ break;
+
+ case PIXELROW_8:
+ switch (PixelColumn)
+ {
+ case PIXELCOLUMN_1:
+ /* Position : Row = 8 , Column = 1 */
+ LCD->RAM[LCD_RAMRegister_12] |= (uint32_t)0x00200000;
+ break;
+
+ case PIXELCOLUMN_2:
+ /* Position : Row = 8 , Column = 2 */
+ LCD->RAM[LCD_RAMRegister_12] |= (uint32_t)0x00400000;
+ break;
+
+ case PIXELCOLUMN_3:
+ /* Position : Row = 8 , Column = 3 */
+ LCD->RAM[LCD_RAMRegister_12] |= (uint32_t)0x00800000;
+ break;
+
+ case PIXELCOLUMN_4:
+ /* Position : Row = 8 , Column = 4 */
+ LCD->RAM[LCD_RAMRegister_12] |= (uint32_t)0x01000000;
+ break;
+
+ case PIXELCOLUMN_5:
+ /* Position : Row = 8 , Column = 5 */
+ LCD->RAM[LCD_RAMRegister_12] |= (uint32_t)0x02000000;
+ break;
+
+ case PIXELCOLUMN_6:
+ /* Position : Row = 8 , Column = 6 */
+ LCD->RAM[LCD_RAMRegister_12] |= (uint32_t)0x04000000;
+ break;
+
+ case PIXELCOLUMN_7:
+ /* Position : Row = 8 , Column = 7 */
+ LCD->RAM[LCD_RAMRegister_12] |= (uint32_t)0x08000000;
+ break;
+
+ case PIXELCOLUMN_8:
+ /* Position : Row = 8 , Column = 8 */
+ LCD->RAM[LCD_RAMRegister_12] |= (uint32_t)0x10000000;
+ break;
+
+ case PIXELCOLUMN_9:
+ /* Position : Row = 8 , Column = 9*/
+ LCD->RAM[LCD_RAMRegister_12] |= (uint32_t)0x20000000;
+ break;
+
+ case PIXELCOLUMN_10:
+ /* Position : Row = 8 , Column = 10*/
+ LCD->RAM[LCD_RAMRegister_12] |= (uint32_t)0x40000000;
+ break;
+
+ case PIXELCOLUMN_11:
+ /* Position : Row = 8 , Column = 11*/
+ LCD->RAM[LCD_RAMRegister_12] |= (uint32_t)0x80000000;
+ break;
+
+ case PIXELCOLUMN_12:
+ /* Position : Row = 8 , Column = 12*/
+ LCD->RAM[LCD_RAMRegister_13] |= (uint32_t)0x00000001;
+ break;
+
+ case PIXELCOLUMN_13:
+ /* Position : Row = 8 , Column = 13*/
+ LCD->RAM[LCD_RAMRegister_13] |= (uint32_t)0x00000002;
+ break;
+
+ case PIXELCOLUMN_14:
+ /* Position : Row = 8 , Column = 14*/
+ LCD->RAM[LCD_RAMRegister_13] |= (uint32_t)0x00000004;
+ break;
+
+ case PIXELCOLUMN_15:
+ /* Position : Row = 8 , Column = 15*/
+ LCD->RAM[LCD_RAMRegister_13] |= (uint32_t)0x00000008;
+ break;
+
+ case PIXELCOLUMN_16:
+ /* Position : Row = 8 , Column = 16*/
+ LCD->RAM[LCD_RAMRegister_13] |= (uint32_t)0x00000010;
+ break;
+
+ case PIXELCOLUMN_17:
+ /* Position : Row = 8 , Column = 17*/
+ LCD->RAM[LCD_RAMRegister_13] |= (uint32_t)0x00000020;
+ break;
+
+ case PIXELCOLUMN_18:
+ /* Position : Row = 8 , Column = 18*/
+ LCD->RAM[LCD_RAMRegister_13] |= (uint32_t)0x00000040;
+ break;
+
+ case PIXELCOLUMN_19:
+ /* Position : Row = 8 , Column = 19 */
+ LCD->RAM[LCD_RAMRegister_13] |= (uint32_t)0x00000080;
+ break;
+
+ default:
+ break;
+ }
+ break;
+
+ case PIXELROW_9:
+ switch (PixelColumn)
+ {
+ case PIXELCOLUMN_1:
+ /* Position : Row = 9 , Column = 1 */
+ LCD->RAM[LCD_RAMRegister_10] |= (uint32_t)0x00200000;
+ break;
+
+ case PIXELCOLUMN_2:
+ /* Position : Row = 9 , Column = 2 */
+ LCD->RAM[LCD_RAMRegister_10] |= (uint32_t)0x00400000;
+ break;
+
+ case PIXELCOLUMN_3:
+ /* Position : Row = 9 , Column = 3 */
+ LCD->RAM[LCD_RAMRegister_10] |= (uint32_t)0x00800000;
+ break;
+
+ case PIXELCOLUMN_4:
+ /* Position : Row = 9 , Column = 4 */
+ LCD->RAM[LCD_RAMRegister_10] |= (uint32_t)0x01000000;
+ break;
+
+ case PIXELCOLUMN_5:
+ /* Position : Row = 9 , Column = 5 */
+ LCD->RAM[LCD_RAMRegister_10] |= (uint32_t)0x02000000;
+ break;
+
+ case PIXELCOLUMN_6:
+ /* Position : Row = 9 , Column = 6 */
+ LCD->RAM[LCD_RAMRegister_10] |= (uint32_t)0x04000000;
+ break;
+
+ case PIXELCOLUMN_7:
+ /* Position : Row = 9 , Column = 7 */
+ LCD->RAM[LCD_RAMRegister_10] |= (uint32_t)0x08000000;
+ break;
+
+ case PIXELCOLUMN_8:
+ /* Position : Row = 9 , Column = 8 */
+ LCD->RAM[LCD_RAMRegister_10] |= (uint32_t)0x10000000;
+ break;
+
+ case PIXELCOLUMN_9:
+ /* Position : Row = 9 , Column = 9*/
+ LCD->RAM[LCD_RAMRegister_10] |= (uint32_t)0x20000000;
+ break;
+
+ case PIXELCOLUMN_10:
+ /* Position : Row = 9 , Column = 10*/
+ LCD->RAM[LCD_RAMRegister_10] |= (uint32_t)0x40000000;
+ break;
+
+ case PIXELCOLUMN_11:
+ /* Position : Row = 9 , Column = 11*/
+ LCD->RAM[LCD_RAMRegister_10] |= (uint32_t)0x80000000;
+ break;
+
+ case PIXELCOLUMN_12:
+ /* Position : Row = 9 , Column = 12*/
+ LCD->RAM[LCD_RAMRegister_11] |= (uint32_t)0x00000001;
+ break;
+
+ case PIXELCOLUMN_13:
+ /* Position : Row = 9 , Column = 13*/
+ LCD->RAM[LCD_RAMRegister_11] |= (uint32_t)0x00000002;
+ break;
+
+ case PIXELCOLUMN_14:
+ /* Position : Row = 9 , Column = 14*/
+ LCD->RAM[LCD_RAMRegister_11] |= (uint32_t)0x00000004;
+ break;
+
+ case PIXELCOLUMN_15:
+ /* Position : Row = 9 , Column = 15*/
+ LCD->RAM[LCD_RAMRegister_11] |= (uint32_t)0x00000008;
+ break;
+
+ case PIXELCOLUMN_16:
+ /* Position : Row = 9 , Column = 16*/
+ LCD->RAM[LCD_RAMRegister_11] |= (uint32_t)0x00000010;
+ break;
+
+ case PIXELCOLUMN_17:
+ /* Position : Row = 9 , Column = 17*/
+ LCD->RAM[LCD_RAMRegister_11] |= (uint32_t)0x00000020;
+ break;
+
+ case PIXELCOLUMN_18:
+ /* Position : Row = 9 , Column = 18*/
+ LCD->RAM[LCD_RAMRegister_11] |= (uint32_t)0x00000040;
+ break;
+
+ case PIXELCOLUMN_19:
+ /* Position : Row = 9 , Column = 19 */
+ LCD->RAM[LCD_RAMRegister_11] |= (uint32_t)0x00000080;
+ break;
+
+ default:
+ break;
+ }
+ break;
+
+ case PIXELROW_10:
+ switch (PixelColumn)
+ {
+ case PIXELCOLUMN_1:
+ /* Position : Row = 10 , Column = 1 */
+ LCD->RAM[LCD_RAMRegister_8] |= (uint32_t)0x00200000;
+ break;
+
+ case PIXELCOLUMN_2:
+ /* Position : Row = 10 , Column = 2 */
+ LCD->RAM[LCD_RAMRegister_8] |= (uint32_t)0x00400000;
+ break;
+
+ case PIXELCOLUMN_3:
+ /* Position : Row = 10 , Column = 3 */
+ LCD->RAM[LCD_RAMRegister_8] |= (uint32_t)0x00800000;
+ break;
+
+ case PIXELCOLUMN_4:
+ /* Position : Row = 10 , Column = 4 */
+ LCD->RAM[LCD_RAMRegister_8] |= (uint32_t)0x01000000;
+ break;
+
+ case PIXELCOLUMN_5:
+ /* Position : Row = 10 , Column = 5 */
+ LCD->RAM[LCD_RAMRegister_8] |= (uint32_t)0x02000000;
+ break;
+
+ case PIXELCOLUMN_6:
+ /* Position : Row = 10 , Column = 6 */
+ LCD->RAM[LCD_RAMRegister_8] |= (uint32_t)0x04000000;
+ break;
+
+ case PIXELCOLUMN_7:
+ /* Position : Row = 10 , Column = 7 */
+ LCD->RAM[LCD_RAMRegister_8] |= (uint32_t)0x08000000;
+ break;
+
+ case PIXELCOLUMN_8:
+ /* Position : Row = 10 , Column = 8 */
+ LCD->RAM[LCD_RAMRegister_8] |= (uint32_t)0x10000000;
+ break;
+
+ case PIXELCOLUMN_9:
+ /* Position : Row = 10 , Column = 9*/
+ LCD->RAM[LCD_RAMRegister_8] |= (uint32_t)0x20000000;
+ break;
+
+ case PIXELCOLUMN_10:
+ /* Position : Row = 10 , Column = 10*/
+ LCD->RAM[LCD_RAMRegister_8] |= (uint32_t)0x40000000;
+ break;
+
+ case PIXELCOLUMN_11:
+ /* Position : Row = 10 , Column = 11*/
+ LCD->RAM[LCD_RAMRegister_8] |= (uint32_t)0x80000000;
+ break;
+
+ case PIXELCOLUMN_12:
+ /* Position : Row = 10 , Column = 12*/
+ LCD->RAM[LCD_RAMRegister_9] |= (uint32_t)0x00000001;
+ break;
+
+ case PIXELCOLUMN_13:
+ /* Position : Row = 10 , Column = 13*/
+ LCD->RAM[LCD_RAMRegister_9] |= (uint32_t)0x00000002;
+ break;
+
+ case PIXELCOLUMN_14:
+ /* Position : Row = 10 , Column = 14*/
+ LCD->RAM[LCD_RAMRegister_9] |= (uint32_t)0x00000004;
+ break;
+
+ case PIXELCOLUMN_15:
+ /* Position : Row = 10 , Column = 15*/
+ LCD->RAM[LCD_RAMRegister_9] |= (uint32_t)0x00000008;
+ break;
+
+ case PIXELCOLUMN_16:
+ /* Position : Row = 10 , Column = 16*/
+ LCD->RAM[LCD_RAMRegister_9] |= (uint32_t)0x00000010;
+ break;
+
+ case PIXELCOLUMN_17:
+ /* Position : Row = 10 , Column = 17*/
+ LCD->RAM[LCD_RAMRegister_9] |= (uint32_t)0x00000020;
+ break;
+
+ case PIXELCOLUMN_18:
+ /* Position : Row = 10 , Column = 18*/
+ LCD->RAM[LCD_RAMRegister_9] |= (uint32_t)0x00000040;
+ break;
+
+ case PIXELCOLUMN_19:
+ /* Position : Row = 10 , Column = 19 */
+ LCD->RAM[LCD_RAMRegister_9] |= (uint32_t)0x00000080;
+ break;
+
+ default:
+ break;
+ }
+ break;
+ }
+
+ /*!< Request LCD RAM update */
+ LCD_UpdateDisplayRequest();
+}
+
+/**
+ * @brief Set Matrix Pixel off.
+ * @param PixelRow: Specify Matrix Row.
+ * @param PixelColumn: Specify Matrix Column.
+ * @retval None
+ */
+void LCD_GLASS_ClearMatrixPixel(PixelRow_TypeDef PixelRow, PixelColumn_TypeDef PixelColumn)
+{
+ /*!< Wait Until the last LCD RAM update finish */
+ while(LCD_GetFlagStatus(LCD_FLAG_UDR) != RESET)
+ {
+ }
+
+ switch (PixelRow)
+ {
+ case PIXELROW_1:
+ switch (PixelColumn)
+ {
+ case PIXELCOLUMN_1:
+ /* Position : Row = 1 , Column = 1 */
+ LCD->RAM[LCD_RAMRegister_6] &= (uint32_t)0xFFFFFDFF;
+ break;
+
+ case PIXELCOLUMN_2:
+ /* Position : Row = 1 , Column = 2 */
+ LCD->RAM[LCD_RAMRegister_6] &= (uint32_t)0xFFFFBFFF;
+ break;
+
+ case PIXELCOLUMN_3:
+ /* Position : Row = 1 , Column = 3 */
+ LCD->RAM[LCD_RAMRegister_6] &= (uint32_t)0xFFFFDFFF;
+ break;
+
+ case PIXELCOLUMN_4:
+ /* Position : Row = 1 , Column = 4 */
+ LCD->RAM[LCD_RAMRegister_6] &= (uint32_t)0xFFFFEFFF;
+ break;
+
+ case PIXELCOLUMN_5:
+ /* Position : Row = 1 , Column = 5 */
+ LCD->RAM[LCD_RAMRegister_6] &= (uint32_t)0xFFFDFFFF;
+ break;
+
+ case PIXELCOLUMN_6:
+ /* Position : Row = 1 , Column = 6 */
+ LCD->RAM[LCD_RAMRegister_6] &= (uint32_t)0xFFFEFFFF;
+ break;
+
+ case PIXELCOLUMN_7:
+ /* Position : Row = 1 , Column = 7 */
+ LCD->RAM[LCD_RAMRegister_6] &= (uint32_t)0xFFFF7FFF;
+ break;
+
+ case PIXELCOLUMN_8:
+ /* Position : Row = 1 , Column = 8 */
+ LCD->RAM[LCD_RAMRegister_6] &= (uint32_t)0xFFEFFFFF;
+ break;
+
+ case PIXELCOLUMN_9:
+ /* Position : Row = 1 , Column = 9 */
+ LCD->RAM[LCD_RAMRegister_6] &= (uint32_t)0xFFF7FFFF;
+ break;
+
+ case PIXELCOLUMN_10:
+ /* Position : Row = 1 , Column = 10 */
+ LCD->RAM[LCD_RAMRegister_6] &= (uint32_t)0xFFFBFFFF;
+ break;
+
+ case PIXELCOLUMN_11:
+ /* Position : Row = 1 , Column = 11 */
+ LCD->RAM[LCD_RAMRegister_6] &= (uint32_t)0xFFFFFFFB;
+ break;
+
+ case PIXELCOLUMN_12:
+ /* Position : Row = 1 , Column = 12 */
+ LCD->RAM[LCD_RAMRegister_6] &= (uint32_t)0xFFFFFFFD;
+ break;
+
+ case PIXELCOLUMN_13:
+ /* Position : Row = 1 , Column = 13 */
+ LCD->RAM[LCD_RAMRegister_6] &= (uint32_t)0xFFFFFFFE;
+ break;
+
+ case PIXELCOLUMN_14:
+ /* Position : Row = 1 , Column = 14 */
+ LCD->RAM[LCD_RAMRegister_6] &= (uint32_t)0xFFFFFFDF;
+ break;
+
+ case PIXELCOLUMN_15:
+ /* Position : Row = 1 , Column = 15 */
+ LCD->RAM[LCD_RAMRegister_6] &= (uint32_t)0xFFFFFFEF;
+ break;
+
+ case PIXELCOLUMN_16:
+ /* Position : Row = 1 , Column = 16 */
+ LCD->RAM[LCD_RAMRegister_6] &= (uint32_t)0xFFFFFFF7;
+ break;
+
+ case PIXELCOLUMN_17:
+ /* Position : Row = 1 , Column = 17 */
+ LCD->RAM[LCD_RAMRegister_6] &= (uint32_t)0xFFFFFEFF;
+ break;
+
+ case PIXELCOLUMN_18:
+ /* Position : Row = 1 , Column = 18 */
+ LCD->RAM[LCD_RAMRegister_6] &= (uint32_t)0xFFFFFF7F;
+ break;
+
+ case PIXELCOLUMN_19:
+ /* Position : Row = 1 , Column = 19 */
+ LCD->RAM[LCD_RAMRegister_6] &= (uint32_t)0xFFFFFFBF;
+ break;
+
+ default:
+ break;
+ }
+ break;
+
+ case PIXELROW_2:
+
+ switch (PixelColumn)
+ {
+ case PIXELCOLUMN_1:
+ /* Position : Row = 2 , Column = 1 */
+ LCD->RAM[LCD_RAMRegister_4] &= (uint32_t)0xFFFFFDFF;
+ break;
+
+ case PIXELCOLUMN_2:
+ /* Position : Row = 2 , Column = 2 */
+ LCD->RAM[LCD_RAMRegister_4] &= (uint32_t)0xFFFFBFFF;
+ break;
+
+ case PIXELCOLUMN_3:
+ /* Position : Row = 2 , Column = 3 */
+ LCD->RAM[LCD_RAMRegister_4] &= (uint32_t)0xFFFFDFFF;
+ break;
+
+ case PIXELCOLUMN_4:
+ /* Position : Row = 2 , Column = 4 */
+ LCD->RAM[LCD_RAMRegister_4] &= (uint32_t)0xFFFFEFFF;
+ break;
+
+ case PIXELCOLUMN_5:
+ /* Position : Row = 2 , Column = 5 */
+ LCD->RAM[LCD_RAMRegister_4] &= (uint32_t)0xFFFDFFFF;
+ break;
+
+ case PIXELCOLUMN_6:
+ /* Position : Row = 2 , Column = 6 */
+ LCD->RAM[LCD_RAMRegister_4] &= (uint32_t)0xFFFEFFFF;
+ break;
+
+ case PIXELCOLUMN_7:
+ /* Position : Row = 2 , Column = 7 */
+ LCD->RAM[LCD_RAMRegister_4] &= (uint32_t)0xFFFF7FFF;
+ break;
+
+ case PIXELCOLUMN_8:
+ /* Position : Row = 2 , Column = 8 */
+ LCD->RAM[LCD_RAMRegister_4] &= (uint32_t)0xFFEFFFFF;
+ break;
+
+ case PIXELCOLUMN_9:
+ /* Position : Row = 2 , Column = 9 */
+ LCD->RAM[LCD_RAMRegister_4] &= (uint32_t)0xFFF7FFFF;
+ break;
+
+ case PIXELCOLUMN_10:
+ /* Position : Row = 2 , Column = 10 */
+ LCD->RAM[LCD_RAMRegister_4] &= (uint32_t)0xFFFBFFFF;
+ break;
+
+ case PIXELCOLUMN_11:
+ /* Position : Row = 2 , Column = 11 */
+ LCD->RAM[LCD_RAMRegister_4] &= (uint32_t)0xFFFFFFFB;
+ break;
+
+ case PIXELCOLUMN_12:
+ /* Position : Row = 2 , Column = 12 */
+ LCD->RAM[LCD_RAMRegister_4] &= (uint32_t)0xFFFFFFFD;
+ break;
+
+ case PIXELCOLUMN_13:
+ /* Position : Row = 2 , Column = 13 */
+ LCD->RAM[LCD_RAMRegister_4] &= (uint32_t)0xFFFFFFFE;
+ break;
+
+ case PIXELCOLUMN_14:
+ /* Position : Row = 2 , Column = 14 */
+ LCD->RAM[LCD_RAMRegister_4] &= (uint32_t)0xFFFFFFDF;
+ break;
+
+ case PIXELCOLUMN_15:
+ /* Position : Row = 2 , Column = 15 */
+ LCD->RAM[LCD_RAMRegister_4] &= (uint32_t)0xFFFFFFEF;
+ break;
+
+ case PIXELCOLUMN_16:
+ /* Position : Row = 2 , Column = 16 */
+ LCD->RAM[LCD_RAMRegister_4] &= (uint32_t)0xFFFFFFF7;
+ break;
+
+ case PIXELCOLUMN_17:
+ /* Position : Row = 2 , Column = 17 */
+ LCD->RAM[LCD_RAMRegister_4] &= (uint32_t)0xFFFFFEFF;
+ break;
+
+ case PIXELCOLUMN_18:
+ /* Position : Row = 2 , Column = 18 */
+ LCD->RAM[LCD_RAMRegister_4] &= (uint32_t)0xFFFFFF7F;
+ break;
+
+ case PIXELCOLUMN_19:
+ /* Position : Row = 2 , Column = 19 */
+ LCD->RAM[LCD_RAMRegister_4] &= (uint32_t)0xFFFFFFBF;
+ break;
+
+ default:
+ break;
+ }
+ break;
+
+ case PIXELROW_3:
+ switch (PixelColumn)
+ {
+ case PIXELCOLUMN_1:
+ /* Position : Row = 3 , Column = 1 */
+ LCD->RAM[LCD_RAMRegister_4] &= (uint32_t)0xFFDFFFFF;
+ break;
+
+ case PIXELCOLUMN_2:
+ /* Position : Row = 3 , Column = 2 */
+ LCD->RAM[LCD_RAMRegister_4] &= (uint32_t)0xFFBFFFFF;
+ break;
+
+ case PIXELCOLUMN_3:
+ /* Position : Row = 3 , Column = 3 */
+ LCD->RAM[LCD_RAMRegister_4] &= (uint32_t)0xFF7FFFFF;
+ break;
+
+ case PIXELCOLUMN_4:
+ /* Position : Row = 3 , Column = 4 */
+ LCD->RAM[LCD_RAMRegister_4] &= (uint32_t)0xFEFFFFFF;
+ break;
+
+ case PIXELCOLUMN_5:
+ /* Position : Row = 3 , Column = 5 */
+ LCD->RAM[LCD_RAMRegister_4] &= (uint32_t)0xFDFFFFFF;
+ break;
+
+ case PIXELCOLUMN_6:
+ /* Position : Row = 3 , Column = 6 */
+ LCD->RAM[LCD_RAMRegister_4] &= (uint32_t)0xFBFFFFFF;
+ break;
+
+ case PIXELCOLUMN_7:
+ /* Position : Row = 3 , Column = 7 */
+ LCD->RAM[LCD_RAMRegister_4] &= (uint32_t)0xF7FFFFFF;
+ break;
+
+ case PIXELCOLUMN_8:
+ /* Position : Row = 3 , Column = 8 */
+ LCD->RAM[LCD_RAMRegister_4] &= (uint32_t)0xEFFFFFFF;
+ break;
+
+ case PIXELCOLUMN_9:
+ /* Position : Row = 3 , Column = 9*/
+ LCD->RAM[LCD_RAMRegister_4] &= (uint32_t)0xDFFFFFFF;
+ break;
+
+ case PIXELCOLUMN_10:
+ /* Position : Row = 3 , Column = 10*/
+ LCD->RAM[LCD_RAMRegister_4] &= (uint32_t)0xBFFFFFFF;
+ break;
+
+ case PIXELCOLUMN_11:
+ /* Position : Row = 3 , Column = 11*/
+ LCD->RAM[LCD_RAMRegister_4] &= (uint32_t)0x7FFFFFFF;
+ break;
+
+ case PIXELCOLUMN_12:
+ /* Position : Row = 3 , Column = 12*/
+ LCD->RAM[LCD_RAMRegister_5] &= (uint32_t)0xFFFFFFFE;
+ break;
+
+ case PIXELCOLUMN_13:
+ /* Position : Row = 3 , Column = 13*/
+ LCD->RAM[LCD_RAMRegister_5] &= (uint32_t)0xFFFFFFFD;
+ break;
+
+ case PIXELCOLUMN_14:
+ /* Position : Row = 3 , Column = 14*/
+ LCD->RAM[LCD_RAMRegister_5] &= (uint32_t)0xFFFFFFFB;
+ break;
+
+ case PIXELCOLUMN_15:
+ /* Position : Row = 3 , Column = 15*/
+ LCD->RAM[LCD_RAMRegister_5] &= (uint32_t)0xFFFFFFF7;
+ break;
+
+ case PIXELCOLUMN_16:
+ /* Position : Row = 3 , Column = 16*/
+ LCD->RAM[LCD_RAMRegister_5] &= (uint32_t)0xFFFFFFEF;
+ break;
+
+ case PIXELCOLUMN_17:
+ /* Position : Row = 3 , Column = 17*/
+ LCD->RAM[LCD_RAMRegister_5] &= (uint32_t)0xFFFFFFDF;
+ break;
+
+ case PIXELCOLUMN_18:
+ /* Position : Row = 3 , Column = 18*/
+ LCD->RAM[LCD_RAMRegister_5] &= (uint32_t)0xFFFFFFBF;
+ break;
+
+ case PIXELCOLUMN_19:
+ /* Position : Row = 3 , Column = 19 */
+ LCD->RAM[LCD_RAMRegister_5] &= (uint32_t)0xFFFFFF7F;
+ break;
+
+ default:
+ break;
+ }
+ break;
+
+ case PIXELROW_4:
+ switch (PixelColumn)
+ {
+ case PIXELCOLUMN_1:
+ /* Position : Row = 4 , Column = 1 */
+ LCD->RAM[LCD_RAMRegister_6] &= (uint32_t)0xFFDFFFFF;
+ break;
+
+ case PIXELCOLUMN_2:
+ /* Position : Row = 4 , Column = 2 */
+ LCD->RAM[LCD_RAMRegister_6] &= (uint32_t)0xFFBFFFFF;
+ break;
+
+ case PIXELCOLUMN_3:
+ /* Position : Row = 4 , Column = 3 */
+ LCD->RAM[LCD_RAMRegister_6] &= (uint32_t)0xFF7FFFFF;
+ break;
+
+ case PIXELCOLUMN_4:
+ /* Position : Row = 4 , Column = 4 */
+ LCD->RAM[LCD_RAMRegister_6] &= (uint32_t)0xFEFFFFFF;
+ break;
+
+ case PIXELCOLUMN_5:
+ /* Position : Row = 4 , Column = 5 */
+ LCD->RAM[LCD_RAMRegister_6] &= (uint32_t)0xFDFFFFFF;
+ break;
+
+ case PIXELCOLUMN_6:
+ /* Position : Row = 4 , Column = 6 */
+ LCD->RAM[LCD_RAMRegister_6] &= (uint32_t)0xFBFFFFFF;
+ break;
+
+ case PIXELCOLUMN_7:
+ /* Position : Row = 4 , Column = 7 */
+ LCD->RAM[LCD_RAMRegister_6] &= (uint32_t)0xF7FFFFFF;
+ break;
+
+ case PIXELCOLUMN_8:
+ /* Position : Row = 4 , Column = 8 */
+ LCD->RAM[LCD_RAMRegister_6] &= (uint32_t)0xEFFFFFFF;
+ break;
+
+ case PIXELCOLUMN_9:
+ /* Position : Row = 4 , Column = 9*/
+ LCD->RAM[LCD_RAMRegister_6] &= (uint32_t)0xDFFFFFFF;
+ break;
+
+ case PIXELCOLUMN_10:
+ /* Position : Row = 4 , Column = 10*/
+ LCD->RAM[LCD_RAMRegister_6] &= (uint32_t)0xBFFFFFFF;
+ break;
+
+ case PIXELCOLUMN_11:
+ /* Position : Row = 4 , Column = 11*/
+ LCD->RAM[LCD_RAMRegister_6] &= (uint32_t)0x7FFFFFFF;
+ break;
+
+ case PIXELCOLUMN_12:
+ /* Position : Row = 4 , Column = 12*/
+ LCD->RAM[LCD_RAMRegister_7] &= (uint32_t)0xFFFFFFFE;
+ break;
+
+ case PIXELCOLUMN_13:
+ /* Position : Row = 4 , Column = 13*/
+ LCD->RAM[LCD_RAMRegister_7] &= (uint32_t)0xFFFFFFFD;
+ break;
+
+ case PIXELCOLUMN_14:
+ /* Position : Row = 4 , Column = 14*/
+ LCD->RAM[LCD_RAMRegister_7] &= (uint32_t)0xFFFFFFFB;
+ break;
+
+ case PIXELCOLUMN_15:
+ /* Position : Row = 4 , Column = 15*/
+ LCD->RAM[LCD_RAMRegister_7] &= (uint32_t)0xFFFFFFF7;
+ break;
+
+ case PIXELCOLUMN_16:
+ /* Position : Row = 4 , Column = 16*/
+ LCD->RAM[LCD_RAMRegister_7] &= (uint32_t)0xFFFFFFEF;
+ break;
+
+ case PIXELCOLUMN_17:
+ /* Position : Row = 4 , Column = 17*/
+ LCD->RAM[LCD_RAMRegister_7] &= (uint32_t)0xFFFFFFDF;
+ break;
+
+ case PIXELCOLUMN_18:
+ /* Position : Row = 4 , Column = 18*/
+ LCD->RAM[LCD_RAMRegister_7] &= (uint32_t)0xFFFFFFBF;
+ break;
+
+ case PIXELCOLUMN_19:
+ /* Position : Row = 4 , Column = 19 */
+ LCD->RAM[LCD_RAMRegister_7] &= (uint32_t)0xFFFFFF7F;
+ break;
+
+ default:
+ break;
+ }
+ break;
+
+ case PIXELROW_5:
+ switch (PixelColumn)
+ {
+ case PIXELCOLUMN_1:
+ /* Position : Row = 5 , Column = 1 */
+ LCD->RAM[LCD_RAMRegister_0] &= (uint32_t)0xFFDFFFFF;
+ break;
+
+ case PIXELCOLUMN_2:
+ /* Position : Row = 5 , Column = 2 */
+ LCD->RAM[LCD_RAMRegister_0] &= (uint32_t)0xFFBFFFFF;
+ break;
+
+ case PIXELCOLUMN_3:
+ /* Position : Row = 5 , Column = 3 */
+ LCD->RAM[LCD_RAMRegister_0] &= (uint32_t)0xFF7FFFFF;
+ break;
+
+ case PIXELCOLUMN_4:
+ /* Position : Row = 5 , Column = 4 */
+ LCD->RAM[LCD_RAMRegister_0] &= (uint32_t)0xFEFFFFFF;
+ break;
+
+ case PIXELCOLUMN_5:
+ /* Position : Row = 5 , Column = 5 */
+ LCD->RAM[LCD_RAMRegister_0] &= (uint32_t)0xFDFFFFFF;
+ break;
+
+ case PIXELCOLUMN_6:
+ /* Position : Row = 5 , Column = 6 */
+ LCD->RAM[LCD_RAMRegister_0] &= (uint32_t)0xFBFFFFFF;
+ break;
+
+ case PIXELCOLUMN_7:
+ /* Position : Row = 5 , Column = 7 */
+ LCD->RAM[LCD_RAMRegister_0] &= (uint32_t)0xF7FFFFFF;
+ break;
+
+ case PIXELCOLUMN_8:
+ /* Position : Row = 5 , Column = 8 */
+ LCD->RAM[LCD_RAMRegister_0] &= (uint32_t)0xEFFFFFFF;
+ break;
+
+ case PIXELCOLUMN_9:
+ /* Position : Row = 5 , Column = 9*/
+ LCD->RAM[LCD_RAMRegister_0] &= (uint32_t)0xDFFFFFFF;
+ break;
+
+ case PIXELCOLUMN_10:
+ /* Position : Row = 5 , Column = 10*/
+ LCD->RAM[LCD_RAMRegister_0] &= (uint32_t)0xBFFFFFFF;
+ break;
+
+ case PIXELCOLUMN_11:
+ /* Position : Row = 5 , Column = 11*/
+ LCD->RAM[LCD_RAMRegister_0] &= (uint32_t)0x7FFFFFFF;
+ break;
+
+ case PIXELCOLUMN_12:
+ /* Position : Row = 5 , Column = 12*/
+ LCD->RAM[LCD_RAMRegister_1] &= (uint32_t)0xFFFFFFFE;
+ break;
+
+ case PIXELCOLUMN_13:
+ /* Position : Row = 5 , Column = 13*/
+ LCD->RAM[LCD_RAMRegister_1] &= (uint32_t)0xFFFFFFFD;
+ break;
+
+ case PIXELCOLUMN_14:
+ /* Position : Row = 5 , Column = 14*/
+ LCD->RAM[LCD_RAMRegister_1] &= (uint32_t)0xFFFFFFFB;
+ break;
+
+ case PIXELCOLUMN_15:
+ /* Position : Row = 5 , Column = 15*/
+ LCD->RAM[LCD_RAMRegister_1] &= (uint32_t)0xFFFFFFF7;
+ break;
+
+ case PIXELCOLUMN_16:
+ /* Position : Row = 5 , Column = 16*/
+ LCD->RAM[LCD_RAMRegister_1] &= (uint32_t)0xFFFFFFEF;
+ break;
+
+ case PIXELCOLUMN_17:
+ /* Position : Row = 5 , Column = 17*/
+ LCD->RAM[LCD_RAMRegister_1] &= (uint32_t)0xFFFFFFDF;
+ break;
+
+ case PIXELCOLUMN_18:
+ /* Position : Row = 5 , Column = 18*/
+ LCD->RAM[LCD_RAMRegister_1] &= (uint32_t)0xFFFFFFBF;
+ break;
+
+ case PIXELCOLUMN_19:
+ /* Position : Row = 5 , Column = 19 */
+ LCD->RAM[LCD_RAMRegister_1] &= (uint32_t)0xFFFFFF7F;
+ break;
+
+ default:
+ break;
+ }
+ break;
+
+ case PIXELROW_6:
+ switch (PixelColumn)
+ {
+ case PIXELCOLUMN_1:
+ /* Position : Row = 6 , Column = 1 */
+ LCD->RAM[LCD_RAMRegister_2] &= (uint32_t)0xFFDFFFFF;
+ break;
+
+ case PIXELCOLUMN_2:
+ /* Position : Row = 6 , Column = 2 */
+ LCD->RAM[LCD_RAMRegister_2] &= (uint32_t)0xFFBFFFFF;
+ break;
+
+ case PIXELCOLUMN_3:
+ /* Position : Row = 6 , Column = 3 */
+ LCD->RAM[LCD_RAMRegister_2] &= (uint32_t)0xFF7FFFFF;
+ break;
+
+ case PIXELCOLUMN_4:
+ /* Position : Row = 6 , Column = 4 */
+ LCD->RAM[LCD_RAMRegister_2] &= (uint32_t)0xFEFFFFFF;
+ break;
+
+ case PIXELCOLUMN_5:
+ /* Position : Row = 6 , Column = 5 */
+ LCD->RAM[LCD_RAMRegister_2] &= (uint32_t)0xFDFFFFFF;
+ break;
+
+ case PIXELCOLUMN_6:
+ /* Position : Row = 6 , Column = 6 */
+ LCD->RAM[LCD_RAMRegister_2] &= (uint32_t)0xFBFFFFFF;
+ break;
+
+ case PIXELCOLUMN_7:
+ /* Position : Row = 6 , Column = 7 */
+ LCD->RAM[LCD_RAMRegister_2] &= (uint32_t)0xF7FFFFFF;
+ break;
+
+ case PIXELCOLUMN_8:
+ /* Position : Row = 6 , Column = 8 */
+ LCD->RAM[LCD_RAMRegister_2] &= (uint32_t)0xEFFFFFFF;
+ break;
+
+ case PIXELCOLUMN_9:
+ /* Position : Row = 6 , Column = 9*/
+ LCD->RAM[LCD_RAMRegister_2] &= (uint32_t)0xDFFFFFFF;
+ break;
+
+ case PIXELCOLUMN_10:
+ /* Position : Row = 6 , Column = 10*/
+ LCD->RAM[LCD_RAMRegister_2] &= (uint32_t)0xBFFFFFFF;
+ break;
+
+ case PIXELCOLUMN_11:
+ /* Position : Row = 6 , Column = 11*/
+ LCD->RAM[LCD_RAMRegister_2] &= (uint32_t)0x7FFFFFFF;
+ break;
+
+ case PIXELCOLUMN_12:
+ /* Position : Row = 6 , Column = 12*/
+ LCD->RAM[LCD_RAMRegister_3] &= (uint32_t)0xFFFFFFFE;
+ break;
+
+ case PIXELCOLUMN_13:
+ /* Position : Row = 6 , Column = 13*/
+ LCD->RAM[LCD_RAMRegister_3] &= (uint32_t)0xFFFFFFFD;
+ break;
+
+ case PIXELCOLUMN_14:
+ /* Position : Row = 6 , Column = 14*/
+ LCD->RAM[LCD_RAMRegister_3] &= (uint32_t)0xFFFFFFFB;
+ break;
+
+ case PIXELCOLUMN_15:
+ /* Position : Row = 6 , Column = 15*/
+ LCD->RAM[LCD_RAMRegister_3] &= (uint32_t)0xFFFFFFF7;
+ break;
+
+ case PIXELCOLUMN_16:
+ /* Position : Row = 6 , Column = 16*/
+ LCD->RAM[LCD_RAMRegister_3] &= (uint32_t)0xFFFFFFEF;
+ break;
+
+ case PIXELCOLUMN_17:
+ /* Position : Row = 6 , Column = 17*/
+ LCD->RAM[LCD_RAMRegister_3] &= (uint32_t)0xFFFFFFDF;
+ break;
+
+ case PIXELCOLUMN_18:
+ /* Position : Row = 6 , Column = 18*/
+ LCD->RAM[LCD_RAMRegister_3] &= (uint32_t)0xFFFFFFBF;
+ break;
+
+ case PIXELCOLUMN_19:
+ /* Position : Row = 6 , Column = 19 */
+ LCD->RAM[LCD_RAMRegister_3] &= (uint32_t)0xFFFFFF7F;
+ break;
+
+ default:
+ break;
+ }
+ break;
+
+ case PIXELROW_7:
+ switch (PixelColumn)
+ {
+ case PIXELCOLUMN_1:
+ /* Position : Row = 7 , Column = 1 */
+ LCD->RAM[LCD_RAMRegister_14] &= (uint32_t)0xFFDFFFFF;
+ break;
+
+ case PIXELCOLUMN_2:
+ /* Position : Row = 7 , Column = 2 */
+ LCD->RAM[LCD_RAMRegister_14] &= (uint32_t)0xFFBFFFFF;
+ break;
+
+ case PIXELCOLUMN_3:
+ /* Position : Row = 7 , Column = 3 */
+ LCD->RAM[LCD_RAMRegister_14] &= (uint32_t)0xFF7FFFFF;
+ break;
+
+ case PIXELCOLUMN_4:
+ /* Position : Row = 7 , Column = 4 */
+ LCD->RAM[LCD_RAMRegister_14] &= (uint32_t)0xFEFFFFFF;
+ break;
+
+ case PIXELCOLUMN_5:
+ /* Position : Row = 7 , Column = 5 */
+ LCD->RAM[LCD_RAMRegister_14] &= (uint32_t)0xFDFFFFFF;
+ break;
+
+ case PIXELCOLUMN_6:
+ /* Position : Row = 7 , Column = 6 */
+ LCD->RAM[LCD_RAMRegister_14] &= (uint32_t)0xFBFFFFFF;
+ break;
+
+ case PIXELCOLUMN_7:
+ /* Position : Row = 7 , Column = 7 */
+ LCD->RAM[LCD_RAMRegister_14] &= (uint32_t)0xF7FFFFFF;
+ break;
+
+ case PIXELCOLUMN_8:
+ /* Position : Row = 7 , Column = 8 */
+ LCD->RAM[LCD_RAMRegister_14] &= (uint32_t)0xEFFFFFFF;
+ break;
+
+ case PIXELCOLUMN_9:
+ /* Position : Row = 7 , Column = 9*/
+ LCD->RAM[LCD_RAMRegister_14] &= (uint32_t)0xDFFFFFFF;
+ break;
+
+ case PIXELCOLUMN_10:
+ /* Position : Row = 7 , Column = 10*/
+ LCD->RAM[LCD_RAMRegister_14] &= (uint32_t)0xBFFFFFFF;
+ break;
+
+ case PIXELCOLUMN_11:
+ /* Position : Row = 7 , Column = 11*/
+ LCD->RAM[LCD_RAMRegister_14] &= (uint32_t)0x7FFFFFFF;
+ break;
+
+ case PIXELCOLUMN_12:
+ /* Position : Row = 7 , Column = 12*/
+ LCD->RAM[LCD_RAMRegister_15] &= (uint32_t)0xFFFFFFFE;
+ break;
+
+ case PIXELCOLUMN_13:
+ /* Position : Row = 7 , Column = 13*/
+ LCD->RAM[LCD_RAMRegister_15] &= (uint32_t)0xFFFFFFFD;
+ break;
+
+ case PIXELCOLUMN_14:
+ /* Position : Row = 7 , Column = 14*/
+ LCD->RAM[LCD_RAMRegister_15] &= (uint32_t)0xFFFFFFFB;
+ break;
+
+ case PIXELCOLUMN_15:
+ /* Position : Row = 7 , Column = 15*/
+ LCD->RAM[LCD_RAMRegister_15] &= (uint32_t)0xFFFFFFF7;
+ break;
+
+ case PIXELCOLUMN_16:
+ /* Position : Row = 7 , Column = 16*/
+ LCD->RAM[LCD_RAMRegister_15] &= (uint32_t)0xFFFFFFEF;
+ break;
+
+ case PIXELCOLUMN_17:
+ /* Position : Row = 7 , Column = 17*/
+ LCD->RAM[LCD_RAMRegister_15] &= (uint32_t)0xFFFFFFDF;
+ break;
+
+ case PIXELCOLUMN_18:
+ /* Position : Row = 7 , Column = 18*/
+ LCD->RAM[LCD_RAMRegister_15] &= (uint32_t)0xFFFFFFBF;
+ break;
+
+ case PIXELCOLUMN_19:
+ /* Position : Row = 7 , Column = 19 */
+ LCD->RAM[LCD_RAMRegister_15] &= (uint32_t)0xFFFFFF7F;
+ break;
+
+ default:
+ break;
+ }
+ break;
+
+ case PIXELROW_8:
+ switch (PixelColumn)
+ {
+ case PIXELCOLUMN_1:
+ /* Position : Row = 8 , Column = 1 */
+ LCD->RAM[LCD_RAMRegister_12] &= (uint32_t)0xFFDFFFFF;
+ break;
+
+ case PIXELCOLUMN_2:
+ /* Position : Row = 8 , Column = 2 */
+ LCD->RAM[LCD_RAMRegister_12] &= (uint32_t)0xFFBFFFFF;
+ break;
+
+ case PIXELCOLUMN_3:
+ /* Position : Row = 8 , Column = 3 */
+ LCD->RAM[LCD_RAMRegister_12] &= (uint32_t)0xFF7FFFFF;
+ break;
+
+ case PIXELCOLUMN_4:
+ /* Position : Row = 8 , Column = 4 */
+ LCD->RAM[LCD_RAMRegister_12] &= (uint32_t)0xFEFFFFF0;
+ break;
+
+ case PIXELCOLUMN_5:
+ /* Position : Row = 8 , Column = 5 */
+ LCD->RAM[LCD_RAMRegister_12] &= (uint32_t)0xFDFFFFFF;
+ break;
+
+ case PIXELCOLUMN_6:
+ /* Position : Row = 8 , Column = 6 */
+ LCD->RAM[LCD_RAMRegister_12] &= (uint32_t)0xFBFFFFF0;
+ break;
+
+ case PIXELCOLUMN_7:
+ /* Position : Row = 8 , Column = 7 */
+ LCD->RAM[LCD_RAMRegister_12] &= (uint32_t)0xF7FFFFFF;
+ break;
+
+ case PIXELCOLUMN_8:
+ /* Position : Row = 8 , Column = 8 */
+ LCD->RAM[LCD_RAMRegister_12] &= (uint32_t)0xEFFFFFFF;
+ break;
+
+ case PIXELCOLUMN_9:
+ /* Position : Row = 8 , Column = 9*/
+ LCD->RAM[LCD_RAMRegister_12] &= (uint32_t)0xDFFFFFFF;
+ break;
+
+ case PIXELCOLUMN_10:
+ /* Position : Row = 8 , Column = 10*/
+ LCD->RAM[LCD_RAMRegister_12] &= (uint32_t)0xBFFFFFFF;
+ break;
+
+ case PIXELCOLUMN_11:
+ /* Position : Row = 8 , Column = 11*/
+ LCD->RAM[LCD_RAMRegister_12] &= (uint32_t)0x7FFFFFFF;
+ break;
+
+ case PIXELCOLUMN_12:
+ /* Position : Row = 8 , Column = 12*/
+ LCD->RAM[LCD_RAMRegister_13] &= (uint32_t)0xFFFFFFFE;
+ break;
+
+ case PIXELCOLUMN_13:
+ /* Position : Row = 8 , Column = 13*/
+ LCD->RAM[LCD_RAMRegister_13] &= (uint32_t)0xFFFFFFFD;
+ break;
+
+ case PIXELCOLUMN_14:
+ /* Position : Row = 8 , Column = 14*/
+ LCD->RAM[LCD_RAMRegister_13] &= (uint32_t)0xFFFFFFFB;
+ break;
+
+ case PIXELCOLUMN_15:
+ /* Position : Row = 8 , Column = 15*/
+ LCD->RAM[LCD_RAMRegister_13] &= (uint32_t)0xFFFFFFF7;
+ break;
+
+ case PIXELCOLUMN_16:
+ /* Position : Row = 8 , Column = 16*/
+ LCD->RAM[LCD_RAMRegister_13] &= (uint32_t)0xFFFFFFEF;
+ break;
+
+ case PIXELCOLUMN_17:
+ /* Position : Row = 8 , Column = 17*/
+ LCD->RAM[LCD_RAMRegister_13] &= (uint32_t)0xFFFFFFDF;
+ break;
+
+ case PIXELCOLUMN_18:
+ /* Position : Row = 8 , Column = 18*/
+ LCD->RAM[LCD_RAMRegister_13] &= (uint32_t)0xFFFFFFBF;
+ break;
+
+ case PIXELCOLUMN_19:
+ /* Position : Row = 8 , Column = 19 */
+ LCD->RAM[LCD_RAMRegister_13] &= (uint32_t)0xFFFFFF7F;
+ break;
+
+ default:
+ break;
+ }
+ break;
+
+ case PIXELROW_9:
+ switch (PixelColumn)
+ {
+ case PIXELCOLUMN_1:
+ /* Position : Row = 9 , Column = 1 */
+ LCD->RAM[LCD_RAMRegister_10] &= (uint32_t)0xFFDFFFFF;
+ break;
+
+ case PIXELCOLUMN_2:
+ /* Position : Row = 9 , Column = 2 */
+ LCD->RAM[LCD_RAMRegister_10] &= (uint32_t)0xFFBFFFFF;
+ break;
+
+ case PIXELCOLUMN_3:
+ /* Position : Row = 9 , Column = 3 */
+ LCD->RAM[LCD_RAMRegister_10] &= (uint32_t)0xFF7FFFFF;
+ break;
+
+ case PIXELCOLUMN_4:
+ /* Position : Row = 9 , Column = 4 */
+ LCD->RAM[LCD_RAMRegister_10] &= (uint32_t)0xFEFFFFFF;
+ break;
+
+ case PIXELCOLUMN_5:
+ /* Position : Row = 9 , Column = 5 */
+ LCD->RAM[LCD_RAMRegister_10] &= (uint32_t)0xFDFFFFFF;
+ break;
+
+ case PIXELCOLUMN_6:
+ /* Position : Row = 9 , Column = 6 */
+ LCD->RAM[LCD_RAMRegister_10] &= (uint32_t)0xFBFFFFFF;
+ break;
+
+ case PIXELCOLUMN_7:
+ /* Position : Row = 9 , Column = 7 */
+ LCD->RAM[LCD_RAMRegister_10] &= (uint32_t)0xF7FFFFFF;
+ break;
+
+ case PIXELCOLUMN_8:
+ /* Position : Row = 9 , Column = 8 */
+ LCD->RAM[LCD_RAMRegister_10] &= (uint32_t)0xEFFFFFFF;
+ break;
+
+ case PIXELCOLUMN_9:
+ /* Position : Row = 9 , Column = 9*/
+ LCD->RAM[LCD_RAMRegister_10] &= (uint32_t)0xDFFFFFFF;
+ break;
+
+ case PIXELCOLUMN_10:
+ /* Position : Row = 9 , Column = 10*/
+ LCD->RAM[LCD_RAMRegister_10] &= (uint32_t)0xBFFFFFF;
+ break;
+
+ case PIXELCOLUMN_11:
+ /* Position : Row = 9 , Column = 11*/
+ LCD->RAM[LCD_RAMRegister_10] &= (uint32_t)0x7FFFFFFF;
+ break;
+
+ case PIXELCOLUMN_12:
+ /* Position : Row = 9 , Column = 12*/
+ LCD->RAM[LCD_RAMRegister_11] &= (uint32_t)0xFFFFFFFE;
+ break;
+
+ case PIXELCOLUMN_13:
+ /* Position : Row = 9 , Column = 13*/
+ LCD->RAM[LCD_RAMRegister_11] &= (uint32_t)0xFFFFFFFD;
+ break;
+
+ case PIXELCOLUMN_14:
+ /* Position : Row = 9 , Column = 14*/
+ LCD->RAM[LCD_RAMRegister_11] &= (uint32_t)0xFFFFFFFB;
+ break;
+
+ case PIXELCOLUMN_15:
+ /* Position : Row = 9 , Column = 15*/
+ LCD->RAM[LCD_RAMRegister_11] &= (uint32_t)0xFFFFFFF7;
+ break;
+
+ case PIXELCOLUMN_16:
+ /* Position : Row = 9 , Column = 16*/
+ LCD->RAM[LCD_RAMRegister_11] &= (uint32_t)0xFFFFFFEF;
+ break;
+
+ case PIXELCOLUMN_17:
+ /* Position : Row = 9 , Column = 17*/
+ LCD->RAM[LCD_RAMRegister_11] &= (uint32_t)0xFFFFFFDF;
+ break;
+
+ case PIXELCOLUMN_18:
+ /* Position : Row = 9 , Column = 18*/
+ LCD->RAM[LCD_RAMRegister_11] &= (uint32_t)0xFFFFFFBF;
+ break;
+
+ case PIXELCOLUMN_19:
+ /* Position : Row = 9 , Column = 19 */
+ LCD->RAM[LCD_RAMRegister_11] &= (uint32_t)0xFFFFFF7F;
+ break;
+
+ default:
+ break;
+ }
+ break;
+
+ case PIXELROW_10:
+ switch (PixelColumn)
+ {
+ case PIXELCOLUMN_1:
+ /* Position : Row = 10 , Column = 1 */
+ LCD->RAM[LCD_RAMRegister_8] &= (uint32_t)0xFFDFFFFF;
+ break;
+
+ case PIXELCOLUMN_2:
+ /* Position : Row = 10 , Column = 2 */
+ LCD->RAM[LCD_RAMRegister_8] &= (uint32_t)0xFFBFFFFF;
+ break;
+
+ case PIXELCOLUMN_3:
+ /* Position : Row = 10 , Column = 3 */
+ LCD->RAM[LCD_RAMRegister_8] &= (uint32_t)0xFF7FFFFF;
+ break;
+
+ case PIXELCOLUMN_4:
+ /* Position : Row = 10 , Column = 4 */
+ LCD->RAM[LCD_RAMRegister_8] &= (uint32_t)0xFEFFFFFF;
+ break;
+
+ case PIXELCOLUMN_5:
+ /* Position : Row = 10 , Column = 5 */
+ LCD->RAM[LCD_RAMRegister_8] &= (uint32_t)0xFDFFFFFF;
+ break;
+
+ case PIXELCOLUMN_6:
+ /* Position : Row = 10 , Column = 6 */
+ LCD->RAM[LCD_RAMRegister_8] &= (uint32_t)0xFBFFFFFF;
+ break;
+
+ case PIXELCOLUMN_7:
+ /* Position : Row = 10 , Column = 7 */
+ LCD->RAM[LCD_RAMRegister_8] &= (uint32_t)0xF7FFFFFF;
+ break;
+
+ case PIXELCOLUMN_8:
+ /* Position : Row = 10 , Column = 8 */
+ LCD->RAM[LCD_RAMRegister_8] &= (uint32_t)0xEFFFFFFF;
+ break;
+
+ case PIXELCOLUMN_9:
+ /* Position : Row = 10 , Column = 9*/
+ LCD->RAM[LCD_RAMRegister_8] &= (uint32_t)0xDFFFFFFF;
+ break;
+
+ case PIXELCOLUMN_10:
+ /* Position : Row = 10 , Column = 10*/
+ LCD->RAM[LCD_RAMRegister_8] &= (uint32_t)0xBFFFFFFF;
+ break;
+
+ case PIXELCOLUMN_11:
+ /* Position : Row = 10 , Column = 11*/
+ LCD->RAM[LCD_RAMRegister_8] &= (uint32_t)0x7FFFFFFF;
+ break;
+
+ case PIXELCOLUMN_12:
+ /* Position : Row = 10 , Column = 12*/
+ LCD->RAM[LCD_RAMRegister_9] &= (uint32_t)0xFFFFFFFE;
+ break;
+
+ case PIXELCOLUMN_13:
+ /* Position : Row = 10 , Column = 13*/
+ LCD->RAM[LCD_RAMRegister_9] &= (uint32_t)0xFFFFFFFD;
+ break;
+
+ case PIXELCOLUMN_14:
+ /* Position : Row = 10 , Column = 14*/
+ LCD->RAM[LCD_RAMRegister_9] &= (uint32_t)0xFFFFFFFB;
+ break;
+
+ case PIXELCOLUMN_15:
+ /* Position : Row = 10 , Column = 15*/
+ LCD->RAM[LCD_RAMRegister_9] &= (uint32_t)0xFFFFFFF7;
+ break;
+
+ case PIXELCOLUMN_16:
+ /* Position : Row = 10 , Column = 16*/
+ LCD->RAM[LCD_RAMRegister_9] &= (uint32_t)0xFFFFFFEF;
+ break;
+
+ case PIXELCOLUMN_17:
+ /* Position : Row = 10 , Column = 17*/
+ LCD->RAM[LCD_RAMRegister_9] &= (uint32_t)0xFFFFFFDF;
+ break;
+
+ case PIXELCOLUMN_18:
+ /* Position : Row = 10 , Column = 18*/
+ LCD->RAM[LCD_RAMRegister_9] &= (uint32_t)0xFFFFFFBF;
+ break;
+
+ case PIXELCOLUMN_19:
+ /* Position : Row = 10 , Column = 19 */
+ LCD->RAM[LCD_RAMRegister_9] &= (uint32_t)0xFFFFFF7F;
+ break;
+
+ default:
+ break;
+ }
+ break;
+ }
+
+ /*!< Request LCD RAM update */
+ LCD_UpdateDisplayRequest();
+}
+
+/**
+ * @brief Converts an ascii char to the a LCD Digit (previous coding).
+ * @param c: a char to display.
+ * @param Point: a point to add in front of a char
+ * This parameter can be: POINT_OFF or POINT_ON
+ * @param DoublePoint: flag indicating if Double Point has to be added in front
+ * of the displayed character.
+ * This parameter can be: DOUBLEPOINT_ON or DOUBLEPOINT_OFF.
+ * @retval None
+ */
+static void Convert(uint8_t* c, Point_Typedef Point, DoublePoint_Typedef DoublePoint)
+{
+ uint32_t ch = 0 , tmp = 0;
+ uint8_t i = 0;
+
+ /* The character c is a letter in upper case*/
+ if ((*c < (uint8_t)0x5B)&(*c > (uint8_t)0x40))
+ {
+ ch = LetterMap[*c-(uint8_t)0x41];
+ }
+ /* The character c is a number*/
+ if ((*c < (uint8_t)0x3A)&(*c > (uint8_t)0x2F))
+ {
+ ch = NumberMap[*c-(uint8_t)0x30];
+ }
+ /* The character c is a space character */
+ if (*c == (uint8_t)0x20)
+ {
+ ch = (uint32_t)0x00;
+ }
+ /* Set the Q pixel in the character that can be displayed if the point is on */
+ if (Point == POINT_ON)
+ {
+ ch |= (uint32_t)0x00400000;
+ }
+
+ /* Set the P pixel in the character that can be displayed if the double point is on */
+ if (DoublePoint == DOUBLEPOINT_ON)
+ {
+ ch |= (uint32_t)0x00000040;
+ }
+
+ for (i = 0;i < 6; i++)
+ {
+ tmp = ch & Mask[i];
+ Digit[i] = (uint8_t)(tmp >> (uint8_t)Shift[i]);
+ }
+}
+
+/**
+ * @brief Configures the LCD Segments and Coms GPIOs.
+ * @param None
+ * @retval None
+ */
+static void LCD_GPIOConfig(void)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+
+ /*!< Enable GPIOA, GPIOB, GPIOC, GPIOD and GPIOE AHB Clocks */
+ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOB | RCC_AHBPeriph_GPIOC
+ | RCC_AHBPeriph_GPIOD | RCC_AHBPeriph_GPIOE, ENABLE);
+
+ /*!< Connect PA.08 to LCD COM0 */
+ GPIO_PinAFConfig(GPIOA, GPIO_PinSource8, GPIO_AF_LCD);
+
+ /*!< Connect PA.09 to LCD COM1 */
+ GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_LCD);
+
+ /*!< Connect PA.10 to LCD COM2 */
+ GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_LCD);
+
+ /*!< Connect PB.09 to LCD COM3 */
+ GPIO_PinAFConfig(GPIOB, GPIO_PinSource9, GPIO_AF_LCD);
+
+ /*!< Connect PA.01 to LCD SEG0 */
+ GPIO_PinAFConfig(GPIOA, GPIO_PinSource1, GPIO_AF_LCD);
+
+ /*!< Connect PA.02 to LCD SEG1 */
+ GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_LCD);
+
+ /*!< Connect PA.03 to LCD SEG2 */
+ GPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_LCD);
+
+ /*!< Connect PA.06 to LCD SEG3 */
+ GPIO_PinAFConfig(GPIOA, GPIO_PinSource6, GPIO_AF_LCD);
+
+ /*!< Connect PA.07 to LCD SEG4 */
+ GPIO_PinAFConfig(GPIOA, GPIO_PinSource7, GPIO_AF_LCD);
+
+ /*!< Connect PB.00 to LCD SEG5 */
+ GPIO_PinAFConfig(GPIOB, GPIO_PinSource0, GPIO_AF_LCD);
+
+ /*!< Connect PB.01 to LCD SEG6 */
+ GPIO_PinAFConfig(GPIOB, GPIO_PinSource1, GPIO_AF_LCD);
+
+ /*!< Connect PB.03 to LCD SEG7 */
+ GPIO_PinAFConfig(GPIOB, GPIO_PinSource3, GPIO_AF_LCD);
+
+ /*!< Connect PB.04 to LCD SEG8 */
+ GPIO_PinAFConfig(GPIOB, GPIO_PinSource4, GPIO_AF_LCD);
+
+ /*!< Connect PB.05 to LCD SEG9 */
+ GPIO_PinAFConfig(GPIOB, GPIO_PinSource5, GPIO_AF_LCD);
+
+ /*!< Connect PB.10 to LCD SEG10 */
+ GPIO_PinAFConfig(GPIOB, GPIO_PinSource10, GPIO_AF_LCD);
+
+ /*!< Connect PB.11 to LCD SEG11 */
+ GPIO_PinAFConfig(GPIOB, GPIO_PinSource11, GPIO_AF_LCD);
+
+ /*!< Connect PB.12 to LCD SEG12 */
+ GPIO_PinAFConfig(GPIOB, GPIO_PinSource12, GPIO_AF_LCD);
+
+ /*!< Connect PB.13 to LCD SEG13 */
+ GPIO_PinAFConfig(GPIOB, GPIO_PinSource13, GPIO_AF_LCD);
+
+ /*!< Connect PB.14 to LCD SEG14 */
+ GPIO_PinAFConfig(GPIOB, GPIO_PinSource14, GPIO_AF_LCD);
+
+ /*!< Connect PB.15 to LCD SEG15 */
+ GPIO_PinAFConfig(GPIOB, GPIO_PinSource15, GPIO_AF_LCD);
+
+ /*!< Connect PB.8 to LCD SEG16 */
+ GPIO_PinAFConfig(GPIOB, GPIO_PinSource8, GPIO_AF_LCD);
+
+ /*!< Connect PA15 to LCD SEG17 */
+ GPIO_PinAFConfig(GPIOA, GPIO_PinSource15, GPIO_AF_LCD);
+
+ /*!< Connect PC.00 to LCD SEG18 */
+ GPIO_PinAFConfig(GPIOC, GPIO_PinSource0, GPIO_AF_LCD);
+
+ /*!< Connect PC.01 to LCD SEG19 */
+ GPIO_PinAFConfig(GPIOC, GPIO_PinSource1, GPIO_AF_LCD);
+
+ /*!< Connect PC.02 to LCD SEG20 */
+ GPIO_PinAFConfig(GPIOC, GPIO_PinSource2, GPIO_AF_LCD);
+
+ /*!< Connect PC.03 to LCD SEG21 */
+ GPIO_PinAFConfig(GPIOC, GPIO_PinSource3, GPIO_AF_LCD);
+
+ /*!< Connect PC.04 to LCD SEG22 */
+ GPIO_PinAFConfig(GPIOC, GPIO_PinSource4, GPIO_AF_LCD);
+
+ /*!< Connect PC.05 to LCD SEG23 */
+ GPIO_PinAFConfig(GPIOC, GPIO_PinSource5, GPIO_AF_LCD);
+
+ /*!< Connect PC.06 to LCD SEG24 */
+ GPIO_PinAFConfig(GPIOC, GPIO_PinSource6, GPIO_AF_LCD);
+
+ /*!< Connect PC.07 to LCD SEG25 */
+ GPIO_PinAFConfig(GPIOC, GPIO_PinSource7, GPIO_AF_LCD);
+
+ /*!< Connect PC.08 to LCD SEG26 */
+ GPIO_PinAFConfig(GPIOC, GPIO_PinSource8, GPIO_AF_LCD);
+
+ /*!< Connect PC.09 to LCD SEG27 */
+ GPIO_PinAFConfig(GPIOC, GPIO_PinSource9, GPIO_AF_LCD);
+
+ /*!< Connect PD.08 to LCD SEG28 */
+ GPIO_PinAFConfig(GPIOD, GPIO_PinSource8, GPIO_AF_LCD);
+
+ /*!< Connect PD.09 to LCD SEG29 */
+ GPIO_PinAFConfig(GPIOD, GPIO_PinSource9, GPIO_AF_LCD);
+
+ /*!< Connect PD.10 to LCD SEG30 */
+ GPIO_PinAFConfig(GPIOD, GPIO_PinSource10, GPIO_AF_LCD);
+
+ /*!< Connect PD.11 to LCD SEG31 */
+ GPIO_PinAFConfig(GPIOD, GPIO_PinSource11, GPIO_AF_LCD);
+
+ /*!< Connect PD.12 to LCD SEG32 */
+ GPIO_PinAFConfig(GPIOD, GPIO_PinSource12, GPIO_AF_LCD);
+
+ /*!< Connect PD.13 to LCD SEG33 */
+ GPIO_PinAFConfig(GPIOD, GPIO_PinSource13, GPIO_AF_LCD);
+
+ /*!< Connect PD.14 to LCD SEG34 */
+ GPIO_PinAFConfig(GPIOD, GPIO_PinSource14, GPIO_AF_LCD);
+
+ /*!< Connect PD.15 to LCD SEG35 */
+ GPIO_PinAFConfig(GPIOD, GPIO_PinSource15, GPIO_AF_LCD);
+
+ /*!< Connect PE.00 to LCD SEG36 */
+ GPIO_PinAFConfig(GPIOE, GPIO_PinSource0, GPIO_AF_LCD);
+
+ /*!< Connect PE.01 to LCD SEG37 */
+ GPIO_PinAFConfig(GPIOE, GPIO_PinSource1, GPIO_AF_LCD);
+
+ /*!< Connect PE.02 to LCD SEG38 */
+ GPIO_PinAFConfig(GPIOE, GPIO_PinSource2, GPIO_AF_LCD);
+
+ /*!< Connect PE.03 to LCD SEG39 */
+ GPIO_PinAFConfig(GPIOE, GPIO_PinSource3, GPIO_AF_LCD);
+
+ /*!< Connect PC.10 to LCD SEG40 or LCD COM4 */
+ GPIO_PinAFConfig(GPIOC, GPIO_PinSource10, GPIO_AF_LCD);
+
+ /*!< Connect PC.11 to LCD SEG41 or LCD COM5 */
+ GPIO_PinAFConfig(GPIOC, GPIO_PinSource11, GPIO_AF_LCD);
+
+ /*!< Connect PC.12 to LCD SEG42 or LCD COM6 */
+ GPIO_PinAFConfig(GPIOC, GPIO_PinSource12, GPIO_AF_LCD);
+
+ /*!< Connect PD.02 to LCD SEG43 or LCD COM7 */
+ GPIO_PinAFConfig(GPIOD, GPIO_PinSource2, GPIO_AF_LCD);
+
+ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_6 | \
+ GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | \
+ GPIO_Pin_15;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
+ GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
+ GPIO_Init(GPIOA, &GPIO_InitStructure);
+
+ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_3 | GPIO_Pin_4 | \
+ GPIO_Pin_5 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | \
+ GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | \
+ GPIO_Pin_15;
+ GPIO_Init(GPIOB, &GPIO_InitStructure);
+
+ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | \
+ GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7 | \
+ GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | \
+ GPIO_Pin_12;
+ GPIO_Init(GPIOC, &GPIO_InitStructure);
+
+ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | \
+ GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | \
+ GPIO_Pin_15;
+ GPIO_Init(GPIOD, &GPIO_InitStructure);
+
+ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3;
+ GPIO_Init(GPIOE, &GPIO_InitStructure);
+}
+
+/**
+ * @brief Inserts a delay time.
+ * @param nCount: specifies the delay time length.
+ * @retval None
+ */
+static void delay(__IO uint32_t nCount)
+{
+ __IO uint32_t index = 0;
+ for(index = (0xFF * nCount); index != 0; index--)
+ {
+ }
+}
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
+
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval_glass_lcd.h b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval_glass_lcd.h
new file mode 100644
index 0000000..10c9e68
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval_glass_lcd.h
@@ -0,0 +1,264 @@
+/**
+ ******************************************************************************
+ * @file stm32l152d_eval_glass_lcd.h
+ * @author MCD Application Team
+ * @version V1.0.1
+ * @date 09-March-2012
+ * @brief Header file for stm32l152d_eval_glass_lcd.c module.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.st.com/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __STM32L152D_EVAL_GLASS_LCD_H
+#define __STM32L152D_EVAL_GLASS_LCD_H
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+/* Includes ------------------------------------------------------------------*/
+#include "stm32l152d_eval.h"
+
+/** @addtogroup Utilities
+ * @{
+ */
+
+/** @addtogroup STM32_EVAL
+ * @{
+ */
+
+/** @addtogroup STM32L152D_EVAL
+ * @{
+ */
+
+/** @addtogroup STM32L152D_EVAL_GLASS_LCD
+ * @{
+ */
+
+/** @defgroup STM32L152D_EVAL_GLASS_LCD_Exported_Types
+ * @{
+ */
+
+/**
+ * @brief LCD Glass point
+ * Warning: element values correspond to LCD Glass point.
+ */
+
+typedef enum
+{
+ POINT_OFF = 0,
+ POINT_ON = 1
+}Point_Typedef;
+
+/**
+ * @brief LCD Glass Double point
+ * Warning: element values correspond to LCD Glass Double point.
+ */
+typedef enum
+{
+ DOUBLEPOINT_OFF = 0,
+ DOUBLEPOINT_ON = 1
+}DoublePoint_Typedef;
+
+/**
+ * @brief LCD Glass Battery Level
+ * Warning: element values correspond to LCD Glass Battery Level.
+ */
+
+typedef enum
+{
+ BATTERYLEVEL_OFF = 0,
+ BATTERYLEVEL_1_4 = 1,
+ BATTERYLEVEL_1_2 = 2,
+ BATTERYLEVEL_3_4 = 3,
+ BATTERYLEVEL_FULL = 4
+}BatteryLevel_TypeDef;
+
+/**
+ * @brief LCD Glass Temperature Level
+ * Warning: element values correspond to LCD Glass Temperature Level.
+ */
+
+typedef enum
+{
+ TEMPERATURELEVEL_OFF = 0,
+ TEMPERATURELEVEL_1 = 1,
+ TEMPERATURELEVEL_2 = 2,
+ TEMPERATURELEVEL_3 = 3,
+ TEMPERATURELEVEL_4 = 4,
+ TEMPERATURELEVEL_5 = 5,
+ TEMPERATURELEVEL_6 = 6
+}TemperatureLevel_TypeDef;
+
+/**
+ * @brief LCD Glass Arrow Direction
+ * Warning: element values correspond to LCD Glass Arrow Direction.
+ */
+
+typedef enum
+{
+ ARROWDIRECTION_OFF = 0,
+ ARROWDIRECTION_UP = 1,
+ ARROWDIRECTION_DOWN = 2,
+ ARROWDIRECTION_LEFT = 3,
+ ARROWDIRECTION_RIGHT = 4
+}ArrowDirection_TypeDef;
+
+/**
+ * @brief LCD Glass Value Unit
+ * Warning: element values correspond to LCD Glass Value Unit.
+ */
+typedef enum
+{
+ VALUEUNIT_OFF = 0,
+ VALUEUNIT_MILLIAMPERE = 1,
+ VALUEUNIT_MICROAMPERE = 2,
+ VALUEUNIT_NANOAMPERE = 3
+}ValueUnit_TypeDef;
+
+/**
+ * @brief LCD Glass Sign
+ * Warning: element values correspond to LCD Glass Sign.
+ */
+typedef enum
+{
+ SIGN_POSITIVE = 0,
+ SIGN_NEGATIVE = 1
+}Sign_TypeDef;
+
+/**
+ * @brief LCD Glass Pixel Row
+ * Warning: element values correspond to LCD Glass Pixel Row.
+ */
+typedef enum
+{
+ PIXELROW_1 = 1,
+ PIXELROW_2 = 2,
+ PIXELROW_3 = 3,
+ PIXELROW_4 = 4,
+ PIXELROW_5 = 5,
+ PIXELROW_6 = 6,
+ PIXELROW_7 = 7,
+ PIXELROW_8 = 8,
+ PIXELROW_9 = 9,
+ PIXELROW_10 = 10
+}PixelRow_TypeDef;
+
+/**
+ * @brief LCD Glass Pixel Column
+ * Warning: element values correspond to LCD Glass Pixel Column.
+ */
+typedef enum
+{
+ PIXELCOLUMN_1 = 1,
+ PIXELCOLUMN_2 = 2,
+ PIXELCOLUMN_3 = 3,
+ PIXELCOLUMN_4 = 4,
+ PIXELCOLUMN_5 = 5,
+ PIXELCOLUMN_6 = 6,
+ PIXELCOLUMN_7 = 7,
+ PIXELCOLUMN_8 = 8,
+ PIXELCOLUMN_9 = 9,
+ PIXELCOLUMN_10 = 10,
+ PIXELCOLUMN_11 = 11,
+ PIXELCOLUMN_12 = 12,
+ PIXELCOLUMN_13 = 13,
+ PIXELCOLUMN_14 = 14,
+ PIXELCOLUMN_15 = 15,
+ PIXELCOLUMN_16 = 16,
+ PIXELCOLUMN_17 = 17,
+ PIXELCOLUMN_18 = 18,
+ PIXELCOLUMN_19 = 19
+}PixelColumn_TypeDef;
+
+/**
+ * @}
+ */
+
+/** @defgroup STM32L152D_EVAL_GLASS_LCD_Exported_Constants
+ * @{
+ */
+
+/**
+ * @}
+ */
+
+/** @defgroup STM32L152D_EVAL_GLASS_LCD_Exported_Macros
+ * @{
+ */
+
+/**
+ * @}
+ */
+
+/** @defgroup STM32L152D_EVAL_GLASS_LCD_Exported_Functions
+ * @{
+ */
+void LCD_GLASS_Init(void);
+void LCD_GLASS_DisplayChar(uint8_t* ch, Point_Typedef point, DoublePoint_Typedef DoublePoint,uint8_t position);
+void LCD_GLASS_DisplayString(uint8_t* ptr);
+void LCD_GLASS_WriteChar(uint8_t* ch, Point_Typedef point, DoublePoint_Typedef DoublePoint,uint8_t position);
+void LCD_GLASS_ClearChar(uint8_t position);
+void LCD_GLASS_Clear(void);
+void LCD_GLASS_ScrollString(uint8_t* ptr, uint16_t nScroll, uint16_t ScrollSpeed);
+
+void LCD_GLASS_ClearTextZone(void);
+void LCD_GLASS_DisplayLogo(FunctionalState NewState);
+void LCD_GLASS_BatteryLevelConfig(BatteryLevel_TypeDef BatteryLevel);
+void LCD_GLASS_ArrowConfig(ArrowDirection_TypeDef ArrowDirection);
+void LCD_GLASS_TemperatureConfig(TemperatureLevel_TypeDef TemperatureLevel);
+void LCD_GLASS_ValueUnitConfig(ValueUnit_TypeDef ValueUnit);
+void LCD_GLASS_SignCmd(Sign_TypeDef Sign, FunctionalState NewState);
+
+void LCD_GLASS_WriteMatrixPixel(PixelRow_TypeDef PixelRow, PixelColumn_TypeDef PixelColumn);
+void LCD_GLASS_ClearMatrixPixel(PixelRow_TypeDef PixelRow, PixelColumn_TypeDef PixelColumn);
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __STM32L152D_EVAL_GLASS_LCD_H */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
+
+
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval_lcd.c b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval_lcd.c
new file mode 100644
index 0000000..eaf7823
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval_lcd.c
@@ -0,0 +1,1684 @@
+/**
+ ******************************************************************************
+ * @file stm32l152d_eval_lcd.c
+ * @author MCD Application Team
+ * @version V1.0.1
+ * @date 09-March-2012
+ * @brief This file includes the LCD driver for AM-240320D4TOQW-T00H(R),
+ * AM240320L8TNQW-00H(ILI9320), AM-240320LDTNQW-00H(SPFD5408B),
+ * AM240320LDTNQW04H00(ILI9325 or RM68050) and AM240320LGTNQW00H (HX8347-D)
+ * Liquid Crystal Display Module of STM32L152D-EVAL board.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.st.com/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+
+/* Includes ------------------------------------------------------------------*/
+#include "stm32l152d_eval_lcd.h"
+#include "../Common/fonts.c"
+
+/** @addtogroup Utilities
+ * @{
+ */
+
+/** @addtogroup STM32_EVAL
+ * @{
+ */
+
+/** @addtogroup STM32L152D_EVAL
+ * @{
+ */
+
+/** @defgroup STM32L152D_EVAL_LCD
+ * @brief This file includes the LCD driver for AM-240320D4TOQW-T00H(R),
+ * AM240320L8TNQW-00H(ILI9320), AM-240320LDTNQW-00H(SPFD5408B),
+ * AM240320LDTNQW04H00(ILI9325 or RM68050) and AM240320LGTNQW00H (HX8347-D)
+ * Liquid Crystal Display Module of STM32L152D-EVAL board.
+ * @{
+ */
+
+/** @defgroup STM32L152D_EVAL_LCD_Private_TypesDefinitions
+ * @{
+ */
+typedef struct
+{
+ __IO uint16_t LCD_REG_R; /* Read Register */
+ __IO uint16_t LCD_RAM_R; /* Read RAM */
+ __IO uint16_t LCD_REG_W; /* Write Register */
+ __IO uint16_t LCD_RAM_W; /* Write RAM */
+} TFT_LCD_TypeDef;
+/**
+ * @}
+ */
+
+
+/** @defgroup STM32L152D_EVAL_LCD_Private_Defines
+ * @{
+ */
+/* Note: LCD /CS is CE4 - Bank 4 of NOR/SRAM Bank 1~4 */
+#define TFT_LCD_BASE ((uint32_t)(0x60000000 | 0x0C000000))
+#define TFT_LCD ((TFT_LCD_TypeDef *) TFT_LCD_BASE)
+#define MAX_POLY_CORNERS 200
+#define POLY_Y(Z) ((int32_t)((Points + Z)->X))
+#define POLY_X(Z) ((int32_t)((Points + Z)->Y))
+#define LCD_ILI9325 0x9325
+#define LCD_ILI9320 0x9320
+#define LCD_SPFD5408 0x5408
+#define LCD_HX8347D 0x0047
+/**
+ * @}
+ */
+
+/** @defgroup STM32L152D_EVAL_LCD_Private_Macros
+ * @{
+ */
+#define ABS(X) ((X) > 0 ? (X) : -(X))
+/**
+ * @}
+ */
+
+/** @defgroup STM32L152D_EVAL_LCD_Private_Variables
+ * @{
+ */
+static sFONT *LCD_Currentfonts;
+/* Global variables to set the written text color */
+static __IO uint16_t TextColor = 0x0000, BackColor = 0xFFFF;
+static __IO uint16_t LCD_ID = 0;
+
+/**
+ * @}
+ */
+
+
+/** @defgroup STM32L152D_EVAL_LCD_Private_FunctionPrototypes
+ * @{
+ */
+#ifndef USE_Delay
+static void delay(__IO uint32_t nCount);
+#endif /* USE_Delay*/
+static void PutPixel(int16_t x, int16_t y);
+static void LCD_PolyLineRelativeClosed(pPoint Points, uint16_t PointCount, uint16_t Closed);
+/**
+ * @}
+ */
+
+
+/** @defgroup STM32L152D_EVAL_LCD_Private_Functions
+ * @{
+ */
+
+/**
+ * @brief DeInitializes the LCD.
+ * @param None
+ * @retval None
+ */
+void STM32L152D_LCD_DeInit(void)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+
+ /*!< LCD Display Off */
+ LCD_DisplayOff();
+
+ /* BANK 4 (of NOR/SRAM Bank 1~4) is disabled */
+ FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM4, ENABLE);
+
+ /*!< LCD_SPI DeInit */
+ FSMC_NORSRAMDeInit(FSMC_Bank1_NORSRAM4);
+
+/*-- GPIO Configuration ------------------------------------------------------*/
+ /* Set PD.00(D2), PD.01(D3), PD.04(NOE), PD.05(NWE), PD.08(D13), PD.09(D14),
+ PD.10(D15), PD.14(D0), PD.15(D1) as input floating */
+ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_4 | GPIO_Pin_5 |
+ GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_14 |
+ GPIO_Pin_15;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
+ GPIO_Init(GPIOD, &GPIO_InitStructure);
+
+ GPIO_PinAFConfig(GPIOD, GPIO_PinSource0, GPIO_AF_EVENTOUT);
+ GPIO_PinAFConfig(GPIOD, GPIO_PinSource1, GPIO_AF_EVENTOUT);
+ GPIO_PinAFConfig(GPIOD, GPIO_PinSource4, GPIO_AF_EVENTOUT);
+ GPIO_PinAFConfig(GPIOD, GPIO_PinSource5, GPIO_AF_EVENTOUT);
+ GPIO_PinAFConfig(GPIOD, GPIO_PinSource8, GPIO_AF_EVENTOUT);
+ GPIO_PinAFConfig(GPIOD, GPIO_PinSource9, GPIO_AF_EVENTOUT);
+ GPIO_PinAFConfig(GPIOD, GPIO_PinSource10, GPIO_AF_EVENTOUT);
+ GPIO_PinAFConfig(GPIOD, GPIO_PinSource14, GPIO_AF_EVENTOUT);
+ GPIO_PinAFConfig(GPIOD, GPIO_PinSource15, GPIO_AF_EVENTOUT);
+
+ /* Set PE.07(D4), PE.08(D5), PE.09(D6), PE.10(D7), PE.11(D8), PE.12(D9), PE.13(D10),
+ PE.14(D11), PE.15(D12) as input floating */
+ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 |
+ GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 |
+ GPIO_Pin_15;
+ GPIO_Init(GPIOE, &GPIO_InitStructure);
+
+ GPIO_PinAFConfig(GPIOE, GPIO_PinSource7 , GPIO_AF_EVENTOUT);
+ GPIO_PinAFConfig(GPIOE, GPIO_PinSource8 , GPIO_AF_EVENTOUT);
+ GPIO_PinAFConfig(GPIOE, GPIO_PinSource9 , GPIO_AF_EVENTOUT);
+ GPIO_PinAFConfig(GPIOE, GPIO_PinSource10 , GPIO_AF_EVENTOUT);
+ GPIO_PinAFConfig(GPIOE, GPIO_PinSource11 , GPIO_AF_EVENTOUT);
+ GPIO_PinAFConfig(GPIOE, GPIO_PinSource12 , GPIO_AF_EVENTOUT);
+ GPIO_PinAFConfig(GPIOE, GPIO_PinSource13 , GPIO_AF_EVENTOUT);
+ GPIO_PinAFConfig(GPIOE, GPIO_PinSource14 , GPIO_AF_EVENTOUT);
+ GPIO_PinAFConfig(GPIOE, GPIO_PinSource15 , GPIO_AF_EVENTOUT);
+
+ /* Set PF.00(A0 (RS)) as input floating */
+ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
+ GPIO_Init(GPIOF, &GPIO_InitStructure);
+ GPIO_PinAFConfig(GPIOF, GPIO_PinSource0, GPIO_AF_EVENTOUT);
+
+ /* Set PG.12(NE4 (LCD/CS)) as input floating - NE4(LCD /CS) */
+ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
+ GPIO_Init(GPIOG, &GPIO_InitStructure);
+ GPIO_PinAFConfig(GPIOG, GPIO_PinSource12, GPIO_AF_EVENTOUT);
+}
+
+/**
+ * @brief Initializes the LCD.
+ * @param None
+ * @retval None
+ */
+void STM32L152D_LCD_Init(void)
+{
+/* Configure the LCD Control pins --------------------------------------------*/
+ LCD_CtrlLinesConfig();
+/* Configure the FSMC Parallel interface -------------------------------------*/
+ LCD_FSMCConfig();
+
+ _delay_(5); /* Delay 50 ms */
+
+ /* Read the LCD ID */
+ LCD_ID = LCD_ReadReg(0x00);
+
+ /* Check if the LCD is HX8347D Controller */
+ if(LCD_ID == LCD_HX8347D)
+ {
+ /* Driving ability setting */
+ LCD_WriteReg(LCD_REG_234, 0x00);
+ LCD_WriteReg(LCD_REG_235, 0x20);
+ LCD_WriteReg(LCD_REG_236, 0x0C);
+ LCD_WriteReg(LCD_REG_237, 0xC4);
+ LCD_WriteReg(LCD_REG_232, 0x40);
+ LCD_WriteReg(LCD_REG_233, 0x38);
+ LCD_WriteReg(LCD_REG_241, 0x01); /* RGB 18-bit interface ;0x0110 */
+ LCD_WriteReg(LCD_REG_242, 0x10);
+ LCD_WriteReg(LCD_REG_39, 0xA3);
+
+ /* Adjust the Gamma Curve */
+ LCD_WriteReg(LCD_REG_64, 0x01);
+ LCD_WriteReg(LCD_REG_65, 0x00);
+ LCD_WriteReg(LCD_REG_66, 0x00);
+ LCD_WriteReg(LCD_REG_67, 0x10);
+ LCD_WriteReg(LCD_REG_68, 0x0E);
+ LCD_WriteReg(LCD_REG_69, 0x24);
+ LCD_WriteReg(LCD_REG_70, 0x04);
+ LCD_WriteReg(LCD_REG_71, 0x50);
+ LCD_WriteReg(LCD_REG_72, 0x02);
+ LCD_WriteReg(LCD_REG_73, 0x13);
+ LCD_WriteReg(LCD_REG_74, 0x19);
+ LCD_WriteReg(LCD_REG_75, 0x19);
+ LCD_WriteReg(LCD_REG_76, 0x16);
+
+ LCD_WriteReg(LCD_REG_80, 0x1B);
+ LCD_WriteReg(LCD_REG_81, 0x31);
+ LCD_WriteReg(LCD_REG_82, 0x2F);
+ LCD_WriteReg(LCD_REG_83, 0x3F);
+ LCD_WriteReg(LCD_REG_84, 0x3F);
+ LCD_WriteReg(LCD_REG_85, 0x3E);
+ LCD_WriteReg(LCD_REG_86, 0x2F);
+ LCD_WriteReg(LCD_REG_87, 0x7B);
+ LCD_WriteReg(LCD_REG_88, 0x09);
+ LCD_WriteReg(LCD_REG_89, 0x06);
+ LCD_WriteReg(LCD_REG_90, 0x06);
+ LCD_WriteReg(LCD_REG_91, 0x0C);
+ LCD_WriteReg(LCD_REG_92, 0x1D);
+ LCD_WriteReg(LCD_REG_93, 0xCC);
+
+ /* Power voltage setting */
+ LCD_WriteReg(LCD_REG_27, 0x1B);
+ LCD_WriteReg(LCD_REG_26, 0x01);
+ LCD_WriteReg(LCD_REG_36, 0x2F);
+ LCD_WriteReg(LCD_REG_37, 0x57);
+ /*****VCOM offset ****/
+ LCD_WriteReg(LCD_REG_35, 0x86);
+
+ /* Power on setting */
+ LCD_WriteReg(LCD_REG_24, 0x36); /* Display frame rate:75Hz(2.85MHz X 117%) */
+ LCD_WriteReg(LCD_REG_25, 0x01); /* Internal oscillator start to oscillate */
+ LCD_WriteReg(LCD_REG_1,0x00);
+ LCD_WriteReg(LCD_REG_31, 0x88); /* Step-up Circuit 1 on,open abnormal power-off monitor */
+ _delay_(2);
+ LCD_WriteReg(LCD_REG_31, 0x80); /* Step-up Circuit 1 off */
+ _delay_(2);
+ LCD_WriteReg(LCD_REG_31, 0x90); /* VCOML voltage can output to negative voltage,
+ (1.0V ~ VCL+0.5V) */
+ _delay_(2);
+ LCD_WriteReg(LCD_REG_31, 0xD0); /* Step-up Circuit 2 on */
+ _delay_(2);
+
+ LCD_WriteReg(LCD_REG_23, 0x05); /* COLMOD control */
+
+ /* Set GRAM Area - Partial Display Control */
+ LCD_WriteReg(LCD_REG_1, 0x00); /* Scroll off */
+
+ LCD_WriteReg(LCD_REG_2, 0x00);
+ LCD_WriteReg(LCD_REG_3, 0x00);
+ LCD_WriteReg(LCD_REG_4, 0x01); /* X,Y swap */
+ LCD_WriteReg(LCD_REG_5, 0x3F); /* X,Y swap */
+
+ LCD_WriteReg(LCD_REG_6, 0x00);
+ LCD_WriteReg(LCD_REG_7, 0x00);
+ LCD_WriteReg(LCD_REG_8, 0x00); /* X,Y swap */
+ LCD_WriteReg(LCD_REG_9, 0xEF); /* X,Y swap */
+
+ /* Memory access control */
+ /* bit7 controls left,right swap(X) */
+ /* bit6 controls up,down swap(Y) */
+ /* bit5 controls X,Y swap */
+ LCD_WriteReg(LCD_REG_22, 0x28);
+
+ /* SET PANEL */
+ LCD_WriteReg(LCD_REG_54, 0x00); /* Panel characteristic control */
+ LCD_WriteReg(LCD_REG_54, 0x04); /* Panel characteristic control: gate driver shift reverse[work] */
+ LCD_WriteReg(LCD_REG_40, 0x38); /* Display control3: source output->PT(0,0) */
+ _delay_(6);
+ LCD_WriteReg(LCD_REG_40, 0x3C); /* Display control3: source output->Display */
+ }
+ /* Check if the LCD is SPFD5408B Controller */
+ else if(LCD_ID == LCD_SPFD5408)
+ {
+ /* Start Initial Sequence ------------------------------------------------*/
+ LCD_WriteReg(LCD_REG_1, 0x0100); /* Set SS bit */
+ LCD_WriteReg(LCD_REG_2, 0x0700); /* Set 1 line inversion */
+ LCD_WriteReg(LCD_REG_3, 0x1030); /* Set GRAM write direction and BGR=1. */
+ LCD_WriteReg(LCD_REG_4, 0x0000); /* Resize register */
+ LCD_WriteReg(LCD_REG_8, 0x0202); /* Set the back porch and front porch */
+ LCD_WriteReg(LCD_REG_9, 0x0000); /* Set non-display area refresh cycle ISC[3:0] */
+ LCD_WriteReg(LCD_REG_10, 0x0000); /* FMARK function */
+ LCD_WriteReg(LCD_REG_12, 0x0000); /* RGB 18-bit System interface setting */
+ LCD_WriteReg(LCD_REG_13, 0x0000); /* Frame marker Position */
+ LCD_WriteReg(LCD_REG_15, 0x0000); /* RGB interface polarity, no impact */
+ /* Power On sequence -----------------------------------------------------*/
+ LCD_WriteReg(LCD_REG_16, 0x0000); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
+ LCD_WriteReg(LCD_REG_17, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */
+ LCD_WriteReg(LCD_REG_18, 0x0000); /* VREG1OUT voltage */
+ LCD_WriteReg(LCD_REG_19, 0x0000); /* VDV[4:0] for VCOM amplitude */
+ _delay_(20); /* Dis-charge capacitor power voltage (200ms) */
+ LCD_WriteReg(LCD_REG_17, 0x0007); /* DC1[2:0], DC0[2:0], VC[2:0] */
+ _delay_(5); /* Delay 50 ms */
+ LCD_WriteReg(LCD_REG_16, 0x12B0); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
+ _delay_(5); /* Delay 50 ms */
+ LCD_WriteReg(LCD_REG_18, 0x01BD); /* External reference voltage= Vci */
+ _delay_(5);
+ LCD_WriteReg(LCD_REG_19, 0x1400); /* VDV[4:0] for VCOM amplitude */
+ LCD_WriteReg(LCD_REG_41, 0x000E); /* VCM[4:0] for VCOMH */
+ _delay_(5); /* Delay 50 ms */
+ LCD_WriteReg(LCD_REG_32, 0x0000); /* GRAM horizontal Address */
+ LCD_WriteReg(LCD_REG_33, 0x013F); /* GRAM Vertical Address */
+ /* Adjust the Gamma Curve (SPFD5408B)-------------------------------------*/
+ LCD_WriteReg(LCD_REG_48, 0x0b0d);
+ LCD_WriteReg(LCD_REG_49, 0x1923);
+ LCD_WriteReg(LCD_REG_50, 0x1c26);
+ LCD_WriteReg(LCD_REG_51, 0x261c);
+ LCD_WriteReg(LCD_REG_52, 0x2419);
+ LCD_WriteReg(LCD_REG_53, 0x0d0b);
+ LCD_WriteReg(LCD_REG_54, 0x1006);
+ LCD_WriteReg(LCD_REG_55, 0x0610);
+ LCD_WriteReg(LCD_REG_56, 0x0706);
+ LCD_WriteReg(LCD_REG_57, 0x0304);
+ LCD_WriteReg(LCD_REG_58, 0x0e05);
+ LCD_WriteReg(LCD_REG_59, 0x0e01);
+ LCD_WriteReg(LCD_REG_60, 0x010e);
+ LCD_WriteReg(LCD_REG_61, 0x050e);
+ LCD_WriteReg(LCD_REG_62, 0x0403);
+ LCD_WriteReg(LCD_REG_63, 0x0607);
+ /* Set GRAM area ---------------------------------------------------------*/
+ LCD_WriteReg(LCD_REG_80, 0x0000); /* Horizontal GRAM Start Address */
+ LCD_WriteReg(LCD_REG_81, 0x00EF); /* Horizontal GRAM End Address */
+ LCD_WriteReg(LCD_REG_82, 0x0000); /* Vertical GRAM Start Address */
+ LCD_WriteReg(LCD_REG_83, 0x013F); /* Vertical GRAM End Address */
+ LCD_WriteReg(LCD_REG_96, 0xA700); /* Gate Scan Line */
+ LCD_WriteReg(LCD_REG_97, 0x0001); /* NDL, VLE, REV */
+ LCD_WriteReg(LCD_REG_106, 0x0000); /* set scrolling line */
+ /* Partial Display Control -----------------------------------------------*/
+ LCD_WriteReg(LCD_REG_128, 0x0000);
+ LCD_WriteReg(LCD_REG_129, 0x0000);
+ LCD_WriteReg(LCD_REG_130, 0x0000);
+ LCD_WriteReg(LCD_REG_131, 0x0000);
+ LCD_WriteReg(LCD_REG_132, 0x0000);
+ LCD_WriteReg(LCD_REG_133, 0x0000);
+ /* Panel Control ---------------------------------------------------------*/
+ LCD_WriteReg(LCD_REG_144, 0x0010);
+ LCD_WriteReg(LCD_REG_146, 0x0000);
+ LCD_WriteReg(LCD_REG_147, 0x0003);
+ LCD_WriteReg(LCD_REG_149, 0x0110);
+ LCD_WriteReg(LCD_REG_151, 0x0000);
+ LCD_WriteReg(LCD_REG_152, 0x0000);
+ /* Set GRAM write direction and BGR=1
+ I/D=01 (Horizontal : increment, Vertical : decrement)
+ AM=1 (address is updated in vertical writing direction) */
+ LCD_WriteReg(LCD_REG_3, 0x1018);
+ LCD_WriteReg(LCD_REG_7, 0x0112); /* 262K color and display ON */
+ }
+ /* Check if the LCD is ILI9320 Controller */
+ else if(LCD_ID == LCD_ILI9320)
+ {
+ /* Start Initial Sequence ------------------------------------------------*/
+ LCD_WriteReg(LCD_REG_229,0x8000); /* Set the internal vcore voltage */
+ LCD_WriteReg(LCD_REG_0, 0x0001); /* Start internal OSC. */
+ LCD_WriteReg(LCD_REG_1, 0x0100); /* set SS and SM bit */
+ LCD_WriteReg(LCD_REG_2, 0x0700); /* set 1 line inversion */
+ LCD_WriteReg(LCD_REG_3, 0x1030); /* set GRAM write direction and BGR=1. */
+ LCD_WriteReg(LCD_REG_4, 0x0000); /* Resize register */
+ LCD_WriteReg(LCD_REG_8, 0x0202); /* set the back porch and front porch */
+ LCD_WriteReg(LCD_REG_9, 0x0000); /* set non-display area refresh cycle ISC[3:0] */
+ LCD_WriteReg(LCD_REG_10, 0x0000); /* FMARK function */
+ LCD_WriteReg(LCD_REG_12, 0x0000); /* RGB interface setting */
+ LCD_WriteReg(LCD_REG_13, 0x0000); /* Frame marker Position */
+ LCD_WriteReg(LCD_REG_15, 0x0000); /* RGB interface polarity */
+
+ /* Power On sequence -----------------------------------------------------*/
+ LCD_WriteReg(LCD_REG_16, 0x0000); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
+ LCD_WriteReg(LCD_REG_17, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */
+ LCD_WriteReg(LCD_REG_18, 0x0000); /* VREG1OUT voltage */
+ LCD_WriteReg(LCD_REG_19, 0x0000); /* VDV[4:0] for VCOM amplitude */
+ _delay_(20); /* Dis-charge capacitor power voltage (200ms) */
+ LCD_WriteReg(LCD_REG_16, 0x17B0); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
+ LCD_WriteReg(LCD_REG_17, 0x0137); /* DC1[2:0], DC0[2:0], VC[2:0] */
+ _delay_(5); /* Delay 50 ms */
+ LCD_WriteReg(LCD_REG_18, 0x0139); /* VREG1OUT voltage */
+ _delay_(5); /* Delay 50 ms */
+ LCD_WriteReg(LCD_REG_19, 0x1d00); /* VDV[4:0] for VCOM amplitude */
+ LCD_WriteReg(LCD_REG_41, 0x0013); /* VCM[4:0] for VCOMH */
+ _delay_(5); /* Delay 50 ms */
+ LCD_WriteReg(LCD_REG_32, 0x0000); /* GRAM horizontal Address */
+ LCD_WriteReg(LCD_REG_33, 0x0000); /* GRAM Vertical Address */
+
+ /* Adjust the Gamma Curve ------------------------------------------------*/
+ LCD_WriteReg(LCD_REG_48, 0x0006);
+ LCD_WriteReg(LCD_REG_49, 0x0101);
+ LCD_WriteReg(LCD_REG_50, 0x0003);
+ LCD_WriteReg(LCD_REG_53, 0x0106);
+ LCD_WriteReg(LCD_REG_54, 0x0b02);
+ LCD_WriteReg(LCD_REG_55, 0x0302);
+ LCD_WriteReg(LCD_REG_56, 0x0707);
+ LCD_WriteReg(LCD_REG_57, 0x0007);
+ LCD_WriteReg(LCD_REG_60, 0x0600);
+ LCD_WriteReg(LCD_REG_61, 0x020b);
+
+ /* Set GRAM area ---------------------------------------------------------*/
+ LCD_WriteReg(LCD_REG_80, 0x0000); /* Horizontal GRAM Start Address */
+ LCD_WriteReg(LCD_REG_81, 0x00EF); /* Horizontal GRAM End Address */
+ LCD_WriteReg(LCD_REG_82, 0x0000); /* Vertical GRAM Start Address */
+ LCD_WriteReg(LCD_REG_83, 0x013F); /* Vertical GRAM End Address */
+ LCD_WriteReg(LCD_REG_96, 0x2700); /* Gate Scan Line */
+ LCD_WriteReg(LCD_REG_97, 0x0001); /* NDL,VLE, REV */
+ LCD_WriteReg(LCD_REG_106, 0x0000); /* set scrolling line */
+
+ /* Partial Display Control -----------------------------------------------*/
+ LCD_WriteReg(LCD_REG_128, 0x0000);
+ LCD_WriteReg(LCD_REG_129, 0x0000);
+ LCD_WriteReg(LCD_REG_130, 0x0000);
+ LCD_WriteReg(LCD_REG_131, 0x0000);
+ LCD_WriteReg(LCD_REG_132, 0x0000);
+ LCD_WriteReg(LCD_REG_133, 0x0000);
+
+ /* Panel Control ---------------------------------------------------------*/
+ LCD_WriteReg(LCD_REG_144, 0x0010);
+ LCD_WriteReg(LCD_REG_146, 0x0000);
+ LCD_WriteReg(LCD_REG_147, 0x0003);
+ LCD_WriteReg(LCD_REG_149, 0x0110);
+ LCD_WriteReg(LCD_REG_151, 0x0000);
+ LCD_WriteReg(LCD_REG_152, 0x0000);
+
+ /* Set GRAM write direction and BGR = 1 */
+ /* I/D=01 (Horizontal : increment, Vertical : decrement) */
+ /* AM=1 (address is updated in vertical writing direction) */
+ LCD_WriteReg(LCD_REG_3, 0x1018);
+
+ LCD_WriteReg(LCD_REG_7, 0x0173); /* 262K color and display ON */
+ }
+ else if(LCD_ID == LCD_ILI9325) /* Check if the LCD is ILI9325 Controller */
+ {
+ /* Start Initial Sequence ------------------------------------------------*/
+ LCD_WriteReg(LCD_REG_0, 0x0001); /* Start internal OSC. */
+ LCD_WriteReg(LCD_REG_1, 0x0100); /* Set SS and SM bit */
+ LCD_WriteReg(LCD_REG_2, 0x0700); /* Set 1 line inversion */
+ LCD_WriteReg(LCD_REG_3, 0x1018); /* Set GRAM write direction and BGR=1. */
+ LCD_WriteReg(LCD_REG_4, 0x0000); /* Resize register */
+ LCD_WriteReg(LCD_REG_8, 0x0202); /* Set the back porch and front porch */
+ LCD_WriteReg(LCD_REG_9, 0x0000); /* Set non-display area refresh cycle ISC[3:0] */
+ LCD_WriteReg(LCD_REG_10, 0x0000); /* FMARK function */
+ LCD_WriteReg(LCD_REG_12, 0x0000); /* RGB interface setting */
+ LCD_WriteReg(LCD_REG_13, 0x0000); /* Frame marker Position */
+ LCD_WriteReg(LCD_REG_15, 0x0000); /* RGB interface polarity */
+
+ /* Power On sequence -----------------------------------------------------*/
+ LCD_WriteReg(LCD_REG_16, 0x0000); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
+ LCD_WriteReg(LCD_REG_17, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */
+ LCD_WriteReg(LCD_REG_18, 0x0000); /* VREG1OUT voltage */
+ LCD_WriteReg(LCD_REG_19, 0x0000); /* VDV[4:0] for VCOM amplitude */
+ _delay_(20); /* Dis-charge capacitor power voltage (200ms) */
+ LCD_WriteReg(LCD_REG_16, 0x17B0); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
+ LCD_WriteReg(LCD_REG_17, 0x0137); /* DC1[2:0], DC0[2:0], VC[2:0] */
+ _delay_(5); /* Delay 50 ms */
+ LCD_WriteReg(LCD_REG_18, 0x0139); /* VREG1OUT voltage */
+ _delay_(5); /* Delay 50 ms */
+ LCD_WriteReg(LCD_REG_19, 0x1d00); /* VDV[4:0] for VCOM amplitude */
+ LCD_WriteReg(LCD_REG_41, 0x0013); /* VCM[4:0] for VCOMH */
+ _delay_(5); /* Delay 50 ms */
+ LCD_WriteReg(LCD_REG_32, 0x0000); /* GRAM horizontal Address */
+ LCD_WriteReg(LCD_REG_33, 0x0000); /* GRAM Vertical Address */
+
+ /* Adjust the Gamma Curve (ILI9325)---------------------------------------*/
+ LCD_WriteReg(LCD_REG_48, 0x0007);
+ LCD_WriteReg(LCD_REG_49, 0x0302);
+ LCD_WriteReg(LCD_REG_50, 0x0105);
+ LCD_WriteReg(LCD_REG_53, 0x0206);
+ LCD_WriteReg(LCD_REG_54, 0x0808);
+ LCD_WriteReg(LCD_REG_55, 0x0206);
+ LCD_WriteReg(LCD_REG_56, 0x0504);
+ LCD_WriteReg(LCD_REG_57, 0x0007);
+ LCD_WriteReg(LCD_REG_60, 0x0105);
+ LCD_WriteReg(LCD_REG_61, 0x0808);
+
+ /* Set GRAM area ---------------------------------------------------------*/
+ LCD_WriteReg(LCD_REG_80, 0x0000); /* Horizontal GRAM Start Address */
+ LCD_WriteReg(LCD_REG_81, 0x00EF); /* Horizontal GRAM End Address */
+ LCD_WriteReg(LCD_REG_82, 0x0000); /* Vertical GRAM Start Address */
+ LCD_WriteReg(LCD_REG_83, 0x013F); /* Vertical GRAM End Address */
+
+ LCD_WriteReg(LCD_REG_96, 0xA700); /* Gate Scan Line(GS=1, scan direction is G320~G1) */
+ LCD_WriteReg(LCD_REG_97, 0x0001); /* NDL,VLE, REV */
+ LCD_WriteReg(LCD_REG_106, 0x0000); /* set scrolling line */
+
+ /* Partial Display Control -----------------------------------------------*/
+ LCD_WriteReg(LCD_REG_128, 0x0000);
+ LCD_WriteReg(LCD_REG_129, 0x0000);
+ LCD_WriteReg(LCD_REG_130, 0x0000);
+ LCD_WriteReg(LCD_REG_131, 0x0000);
+ LCD_WriteReg(LCD_REG_132, 0x0000);
+ LCD_WriteReg(LCD_REG_133, 0x0000);
+
+ /* Panel Control ---------------------------------------------------------*/
+ LCD_WriteReg(LCD_REG_144, 0x0010);
+ LCD_WriteReg(LCD_REG_146, 0x0000);
+ LCD_WriteReg(LCD_REG_147, 0x0003);
+ LCD_WriteReg(LCD_REG_149, 0x0110);
+ LCD_WriteReg(LCD_REG_151, 0x0000);
+ LCD_WriteReg(LCD_REG_152, 0x0000);
+
+ /* Set GRAM write direction and BGR = 1 */
+ /* I/D=00 (Horizontal : increment, Vertical : decrement) */
+ /* AM=1 (address is updated in vertical writing direction) */
+ LCD_WriteReg(LCD_REG_3, 0x1018);
+
+ LCD_WriteReg(LCD_REG_7, 0x0133); /* 262K color and display ON */
+ }
+ LCD_SetFont(&LCD_DEFAULT_FONT);
+}
+
+/**
+ * @brief Sets the LCD Text and Background colors.
+ * @param _TextColor: specifies the Text Color.
+ * @param _BackColor: specifies the Background Color.
+ * @retval None
+ */
+void LCD_SetColors(__IO uint16_t _TextColor, __IO uint16_t _BackColor)
+{
+ TextColor = _TextColor;
+ BackColor = _BackColor;
+}
+
+/**
+ * @brief Gets the LCD Text and Background colors.
+ * @param _TextColor: pointer to the variable that will contain the Text
+ Color.
+ * @param _BackColor: pointer to the variable that will contain the Background
+ Color.
+ * @retval None
+ */
+void LCD_GetColors(__IO uint16_t *_TextColor, __IO uint16_t *_BackColor)
+{
+ *_TextColor = TextColor; *_BackColor = BackColor;
+}
+
+/**
+ * @brief Sets the Text color.
+ * @param Color: specifies the Text color code RGB(5-6-5).
+ * @retval None
+ */
+void LCD_SetTextColor(__IO uint16_t Color)
+{
+ TextColor = Color;
+}
+
+
+/**
+ * @brief Sets the Background color.
+ * @param Color: specifies the Background color code RGB(5-6-5).
+ * @retval None
+ */
+void LCD_SetBackColor(__IO uint16_t Color)
+{
+ BackColor = Color;
+}
+
+/**
+ * @brief Sets the Text Font.
+ * @param fonts: specifies the font to be used.
+ * @retval None
+ */
+void LCD_SetFont(sFONT *fonts)
+{
+ LCD_Currentfonts = fonts;
+}
+
+/**
+ * @brief Gets the Text Font.
+ * @param None.
+ * @retval the used font.
+ */
+sFONT *LCD_GetFont(void)
+{
+ return LCD_Currentfonts;
+}
+
+/**
+ * @brief Clears the selected line.
+ * @param Line: the Line to be cleared.
+ * This parameter can be one of the following values:
+ * @arg Linex: where x can be 0..n
+ * @retval None
+ */
+void LCD_ClearLine(uint16_t Line)
+{
+ uint16_t refcolumn = LCD_PIXEL_WIDTH - 1;
+
+ if(LCD_ID == LCD_HX8347D)
+ {
+ refcolumn = 0;
+ /* Send the string character by character on LCD */
+ while ((LCD_PIXEL_WIDTH - (refcolumn & 0xFFFF)) >= LCD_Currentfonts->Width)
+ {
+ /* Display one character on LCD */
+ LCD_DisplayChar(Line, refcolumn, ' ');
+ /* Increment the column position by 16 */
+ refcolumn += LCD_Currentfonts->Width;
+ }
+ }
+ else
+ {
+ /* Send the string character by character on lCD */
+ while (((refcolumn + 1)&0xFFFF) >= LCD_Currentfonts->Width)
+ {
+ /* Display one character on LCD */
+ LCD_DisplayChar(Line, refcolumn, ' ');
+ /* Decrement the column position by 16 */
+ refcolumn -= LCD_Currentfonts->Width;
+ }
+ }
+}
+
+/**
+ * @brief Clears the hole LCD.
+ * @param Color: the color of the background.
+ * @retval None
+ */
+void LCD_Clear(uint16_t Color)
+{
+ uint32_t index = 0;
+
+ if(LCD_ID == LCD_HX8347D)
+ {
+ LCD_SetCursor(0x00, 0x0000);
+ }
+ else
+ {
+ LCD_SetCursor(0x00, 0x013F);
+ }
+ LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
+ for(index = 0; index < 76800; index++)
+ {
+ TFT_LCD->LCD_RAM_W = Color;
+ }
+}
+
+/**
+ * @brief Sets the cursor position.
+ * @param Xpos: specifies the X position.
+ * @param Ypos: specifies the Y position.
+ * @retval None
+ */
+void LCD_SetCursor(uint16_t Xpos, uint16_t Ypos)
+{
+ if(LCD_ID == LCD_HX8347D)
+ {
+ LCD_WriteReg(LCD_REG_2, Ypos >> 8);
+ LCD_WriteReg(LCD_REG_3, Ypos & 0xFF);
+ LCD_WriteReg(LCD_REG_6, 0x00);
+ LCD_WriteReg(LCD_REG_7, Xpos);
+ }
+ else
+ {
+ LCD_WriteReg(LCD_REG_32, Xpos);
+ LCD_WriteReg(LCD_REG_33, Ypos);
+ }
+}
+
+/**
+ * @brief Draws a character on LCD.
+ * @param Xpos: the Line where to display the character shape.
+ * @param Ypos: start column address.
+ * @param c: pointer to the character data.
+ * @retval None
+ */
+void LCD_DrawChar(uint16_t Xpos, uint16_t Ypos, const uint16_t *c)
+{
+ uint32_t index = 0, i = 0;
+ uint16_t Xaddress = 0;
+
+ Xaddress = Xpos;
+
+ LCD_SetCursor(Xaddress, Ypos);
+
+ for(index = 0; index < LCD_Currentfonts->Height; index++)
+ {
+ LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
+ for(i = 0; i < LCD_Currentfonts->Width; i++)
+ {
+ if((((c[index] & ((0x80 << ((LCD_Currentfonts->Width / 12 ) * 8 ) ) >> i)) == 0x00) &&(LCD_Currentfonts->Width <= 12))||
+ (((c[index] & (0x1 << i)) == 0x00)&&(LCD_Currentfonts->Width > 12 )))
+
+ {
+ LCD_WriteRAM(BackColor);
+ }
+ else
+ {
+ LCD_WriteRAM(TextColor);
+ }
+ }
+ Xaddress++;
+ LCD_SetCursor(Xaddress, Ypos);
+ }
+}
+
+/**
+ * @brief Displays one character (16dots width, 24dots height).
+ * @param Line: the Line where to display the character shape .
+ * This parameter can be one of the following values:
+ * @arg Linex: where x can be 0..9
+ * @param Column: start column address.
+ * @param Ascii: character ascii code, must be between 0x20 and 0x7E.
+ * @retval None
+ */
+void LCD_DisplayChar(uint16_t Line, uint16_t Column, uint8_t Ascii)
+{
+ Ascii -= 32;
+ LCD_DrawChar(Line, Column, &LCD_Currentfonts->table[Ascii * LCD_Currentfonts->Height]);
+}
+
+/**
+ * @brief Displays a maximum of 20 char on the LCD.
+ * @param Line: the Line where to display the character shape .
+ * This parameter can be one of the following values:
+ * @arg Linex: where x can be 0..9
+ * @param *ptr: pointer to string to display on LCD.
+ * @retval None
+ */
+void LCD_DisplayStringLine(uint16_t Line, uint8_t *ptr)
+{
+ uint16_t refcolumn = LCD_PIXEL_WIDTH - 1;
+
+ if(LCD_ID == LCD_HX8347D)
+ {
+ refcolumn = 0;
+ /* Send the string character by character on LCD */
+ while ((*ptr != 0) & ((LCD_PIXEL_WIDTH - (refcolumn & 0xFFFF)) >= LCD_Currentfonts->Width))
+ {
+ /* Display one character on LCD */
+ LCD_DisplayChar(Line, refcolumn, *ptr);
+ /* Increment the column position by 16 */
+ refcolumn += LCD_Currentfonts->Width;
+ /* Point on the next character */
+ ptr++;
+ }
+ }
+ else
+ {
+ /* Send the string character by character on LCD */
+ while ((*ptr != 0) & (((refcolumn + 1) & 0xFFFF) >= LCD_Currentfonts->Width))
+ {
+ /* Display one character on LCD */
+ LCD_DisplayChar(Line, refcolumn, *ptr);
+ /* Decrement the column position by 16 */
+ refcolumn -= LCD_Currentfonts->Width;
+ /* Point on the next character */
+ ptr++;
+ }
+ }
+}
+
+/**
+ * @brief Sets a display window
+ * @param Xpos: specifies the X buttom left position.
+ * @param Ypos: specifies the Y buttom left position.
+ * @param Height: display window height.
+ * @param Width: display window width.
+ * @retval None
+ */
+void LCD_SetDisplayWindow(uint16_t Xpos, uint16_t Ypos, uint8_t Height, uint16_t Width)
+{
+ if(LCD_ID == LCD_HX8347D)
+ {
+ LCD_WriteReg(LCD_REG_2, (319 - Ypos) >> 8); /* SC */
+ LCD_WriteReg(LCD_REG_3, (319 - Ypos) & 0xFF); /* SC */
+
+ LCD_WriteReg(LCD_REG_4, (319 - (Ypos - Width + 1)) >> 8); /* EC */
+ LCD_WriteReg(LCD_REG_5, (319 - (Ypos - Width + 1)) & 0xFF); /* EC */
+
+ LCD_WriteReg(LCD_REG_6, 0x0); /* SP */
+ LCD_WriteReg(LCD_REG_7, (239 - Xpos) & 0xFF); /* SP */
+
+ LCD_WriteReg(LCD_REG_8, 0x0); /* EP */
+ LCD_WriteReg(LCD_REG_9, (239 - (Xpos - Height + 1)) & 0xFF); /* EP */
+ }
+ else
+ {
+ /* Horizontal GRAM Start Address */
+ if(Xpos >= Height)
+ {
+ LCD_WriteReg(LCD_REG_80, (Xpos - Height + 1));
+ }
+ else
+ {
+ LCD_WriteReg(LCD_REG_80, 0);
+ }
+ /* Horizontal GRAM End Address */
+ LCD_WriteReg(LCD_REG_81, Xpos);
+ /* Vertical GRAM Start Address */
+ if(Ypos >= Width)
+ {
+ LCD_WriteReg(LCD_REG_82, (Ypos - Width + 1));
+ }
+ else
+ {
+ LCD_WriteReg(LCD_REG_82, 0);
+ }
+ /* Vertical GRAM End Address */
+ LCD_WriteReg(LCD_REG_83, Ypos);
+ LCD_SetCursor(Xpos, Ypos);
+ }
+}
+
+/**
+ * @brief Disables LCD Window mode.
+ * @param None
+ * @retval None
+ */
+void LCD_WindowModeDisable(void)
+{
+ LCD_SetDisplayWindow(239, 0x13F, 240, 320);
+
+ if(LCD_ID != LCD_HX8347D)
+ {
+ LCD_WriteReg(LCD_REG_3, 0x1018);
+ }
+}
+
+/**
+ * @brief Displays a line.
+ * @param Xpos: specifies the X position.
+ * @param Ypos: specifies the Y position.
+ * @param Length: line length.
+ * @param Direction: line direction.
+ * This parameter can be one of the following values: Vertical or Horizontal.
+ * @retval None
+ */
+void LCD_DrawLine(uint16_t Xpos, uint16_t Ypos, uint16_t Length, uint8_t Direction)
+{
+ uint32_t i = 0;
+
+ if(LCD_ID == LCD_HX8347D)
+ {
+ LCD_SetCursor(Xpos, (LCD_PIXEL_WIDTH - 1) - Ypos);
+ }
+ else
+ {
+ LCD_SetCursor(Xpos, Ypos);
+ }
+
+ if(Direction == LCD_DIR_HORIZONTAL)
+ {
+ LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
+ for(i = 0; i < Length; i++)
+ {
+ LCD_WriteRAM(TextColor);
+ }
+ }
+ else
+ {
+ for(i = 0; i < Length; i++)
+ {
+ LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
+ LCD_WriteRAM(TextColor);
+ Xpos++;
+ if(LCD_ID == LCD_HX8347D)
+ {
+ LCD_SetCursor(Xpos, (LCD_PIXEL_WIDTH - 1) - Ypos);
+ }
+ else
+ {
+ LCD_SetCursor(Xpos, Ypos);
+ }
+ }
+ }
+}
+
+/**
+ * @brief Displays a rectangle.
+ * @param Xpos: specifies the X position.
+ * @param Ypos: specifies the Y position.
+ * @param Height: display rectangle height.
+ * @param Width: display rectangle width.
+ * @retval None
+ */
+void LCD_DrawRect(uint16_t Xpos, uint16_t Ypos, uint8_t Height, uint16_t Width)
+{
+ LCD_DrawLine(Xpos, Ypos, Width, LCD_DIR_HORIZONTAL);
+ LCD_DrawLine((Xpos + Height), Ypos, Width, LCD_DIR_HORIZONTAL);
+
+ LCD_DrawLine(Xpos, Ypos, Height, LCD_DIR_VERTICAL);
+ LCD_DrawLine(Xpos, (Ypos - Width + 1), Height, LCD_DIR_VERTICAL);
+}
+
+/**
+ * @brief Displays a circle.
+ * @param Xpos: specifies the X position.
+ * @param Ypos: specifies the Y position.
+ * @param Radius
+ * @retval None
+ */
+void LCD_DrawCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius)
+{
+ int32_t D;/* Decision Variable */
+ uint32_t CurX;/* Current X Value */
+ uint32_t CurY;/* Current Y Value */
+
+ if(LCD_ID == LCD_HX8347D)
+ {
+ Ypos = (LCD_PIXEL_WIDTH - 1) - Ypos;
+ }
+ D = 3 - (Radius << 1);
+ CurX = 0;
+ CurY = Radius;
+
+ while (CurX <= CurY)
+ {
+ LCD_SetCursor(Xpos + CurX, Ypos + CurY);
+ LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
+ LCD_WriteRAM(TextColor);
+ LCD_SetCursor(Xpos + CurX, Ypos - CurY);
+ LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
+ LCD_WriteRAM(TextColor);
+ LCD_SetCursor(Xpos - CurX, Ypos + CurY);
+ LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
+ LCD_WriteRAM(TextColor);
+ LCD_SetCursor(Xpos - CurX, Ypos - CurY);
+ LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
+ LCD_WriteRAM(TextColor);
+ LCD_SetCursor(Xpos + CurY, Ypos + CurX);
+ LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
+ LCD_WriteRAM(TextColor);
+ LCD_SetCursor(Xpos + CurY, Ypos - CurX);
+ LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
+ LCD_WriteRAM(TextColor);
+ LCD_SetCursor(Xpos - CurY, Ypos + CurX);
+ LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
+ LCD_WriteRAM(TextColor);
+ LCD_SetCursor(Xpos - CurY, Ypos - CurX);
+ LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
+ LCD_WriteRAM(TextColor);
+ if (D < 0)
+ {
+ D += (CurX << 2) + 6;
+ }
+ else
+ {
+ D += ((CurX - CurY) << 2) + 10;
+ CurY--;
+ }
+ CurX++;
+ }
+}
+
+/**
+ * @brief Displays a monocolor picture.
+ * @param Pict: pointer to the picture array.
+ * @retval None
+ */
+void LCD_DrawMonoPict(const uint32_t *Pict)
+{
+ uint32_t index = 0, i = 0;
+
+ if(LCD_ID == LCD_HX8347D)
+ {
+ LCD_SetCursor(0, 0);
+ }
+ else
+ {
+ LCD_SetCursor(0, (LCD_PIXEL_WIDTH - 1));
+ }
+
+ LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
+ for(index = 0; index < 2400; index++)
+ {
+ for(i = 0; i < 32; i++)
+ {
+ if((Pict[index] & (1 << i)) == 0x00)
+ {
+ LCD_WriteRAM(BackColor);
+ }
+ else
+ {
+ LCD_WriteRAM(TextColor);
+ }
+ }
+ }
+}
+
+/**
+ * @brief Displays a bitmap picture loaded in the internal Flash.
+ * @param BmpAddress: Bmp picture address in the internal Flash.
+ * @retval None
+ */
+void LCD_WriteBMP(uint32_t BmpAddress)
+{
+ uint32_t index = 0, size = 0;
+ /* Read bitmap size */
+ size = *(__IO uint16_t *) (BmpAddress + 2);
+ size |= (*(__IO uint16_t *) (BmpAddress + 4)) << 16;
+ /* Get bitmap data address offset */
+ index = *(__IO uint16_t *) (BmpAddress + 10);
+ index |= (*(__IO uint16_t *) (BmpAddress + 12)) << 16;
+ size = (size - index)/2;
+ BmpAddress += index;
+ /* Set GRAM write direction and BGR = 1 */
+ /* I/D=00 (Horizontal : decrement, Vertical : decrement) */
+ /* AM=1 (address is updated in vertical writing direction) */
+ LCD_WriteReg(LCD_REG_3, 0x1008);
+
+ LCD_WriteRAM_Prepare();
+
+ for(index = 0; index < size; index++)
+ {
+ LCD_WriteRAM(*(__IO uint16_t *)BmpAddress);
+ BmpAddress += 2;
+ }
+
+ /* Set GRAM write direction and BGR = 1 */
+ /* I/D = 01 (Horizontal : increment, Vertical : decrement) */
+ /* AM = 1 (address is updated in vertical writing direction) */
+ LCD_WriteReg(LCD_REG_3, 0x1018);
+}
+
+/**
+ * @brief Displays a full rectangle.
+ * @param Xpos: specifies the X position.
+ * @param Ypos: specifies the Y position.
+ * @param Height: rectangle height.
+ * @param Width: rectangle width.
+ * @retval None
+ */
+void LCD_DrawFullRect(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height)
+{
+ LCD_SetTextColor(TextColor);
+
+ LCD_DrawLine(Xpos, Ypos, Width, LCD_DIR_HORIZONTAL);
+ LCD_DrawLine((Xpos + Height), Ypos, Width, LCD_DIR_HORIZONTAL);
+
+ LCD_DrawLine(Xpos, Ypos, Height, LCD_DIR_VERTICAL);
+ LCD_DrawLine(Xpos, (Ypos - Width + 1), Height, LCD_DIR_VERTICAL);
+
+ Width -= 2;
+ Height--;
+ Ypos--;
+
+ LCD_SetTextColor(BackColor);
+
+ while(Height--)
+ {
+ LCD_DrawLine(++Xpos, Ypos, Width, LCD_DIR_HORIZONTAL);
+ }
+
+ LCD_SetTextColor(TextColor);
+}
+
+/**
+ * @brief Displays a full circle.
+ * @param Xpos: specifies the X position.
+ * @param Ypos: specifies the Y position.
+ * @param Radius
+ * @retval None
+ */
+void LCD_DrawFullCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius)
+{
+ int32_t D; /* Decision Variable */
+ uint32_t CurX;/* Current X Value */
+ uint32_t CurY;/* Current Y Value */
+
+ D = 3 - (Radius << 1);
+
+ CurX = 0;
+ CurY = Radius;
+
+ LCD_SetTextColor(BackColor);
+
+ while (CurX <= CurY)
+ {
+ if(CurY > 0)
+ {
+ LCD_DrawLine(Xpos - CurX, Ypos + CurY, 2*CurY, LCD_DIR_HORIZONTAL);
+ LCD_DrawLine(Xpos + CurX, Ypos + CurY, 2*CurY, LCD_DIR_HORIZONTAL);
+ }
+
+ if(CurX > 0)
+ {
+ LCD_DrawLine(Xpos - CurY, Ypos + CurX, 2*CurX, LCD_DIR_HORIZONTAL);
+ LCD_DrawLine(Xpos + CurY, Ypos + CurX, 2*CurX, LCD_DIR_HORIZONTAL);
+ }
+ if (D < 0)
+ {
+ D += (CurX << 2) + 6;
+ }
+ else
+ {
+ D += ((CurX - CurY) << 2) + 10;
+ CurY--;
+ }
+ CurX++;
+ }
+
+ LCD_SetTextColor(TextColor);
+ LCD_DrawCircle(Xpos, Ypos, Radius);
+}
+
+/**
+ * @brief Displays an uni line (between two points).
+ * @param x1: specifies the point 1 x position.
+ * @param y1: specifies the point 1 y position.
+ * @param x2: specifies the point 2 x position.
+ * @param y2: specifies the point 2 y position.
+ * @retval None
+ */
+void LCD_DrawUniLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2)
+{
+ int16_t deltax = 0, deltay = 0, x = 0, y = 0, xinc1 = 0, xinc2 = 0,
+ yinc1 = 0, yinc2 = 0, den = 0, num = 0, numadd = 0, numpixels = 0,
+ curpixel = 0;
+
+ deltax = ABS(x2 - x1); /* The difference between the x's */
+ deltay = ABS(y2 - y1); /* The difference between the y's */
+ x = x1; /* Start x off at the first pixel */
+ y = y1; /* Start y off at the first pixel */
+
+ if (x2 >= x1) /* The x-values are increasing */
+ {
+ xinc1 = 1;
+ xinc2 = 1;
+ }
+ else /* The x-values are decreasing */
+ {
+ xinc1 = -1;
+ xinc2 = -1;
+ }
+
+ if (y2 >= y1) /* The y-values are increasing */
+ {
+ yinc1 = 1;
+ yinc2 = 1;
+ }
+ else /* The y-values are decreasing */
+ {
+ yinc1 = -1;
+ yinc2 = -1;
+ }
+
+ if (deltax >= deltay) /* There is at least one x-value for every y-value */
+ {
+ xinc1 = 0; /* Don't change the x when numerator >= denominator */
+ yinc2 = 0; /* Don't change the y for every iteration */
+ den = deltax;
+ num = deltax / 2;
+ numadd = deltay;
+ numpixels = deltax; /* There are more x-values than y-values */
+ }
+ else /* There is at least one y-value for every x-value */
+ {
+ xinc2 = 0; /* Don't change the x for every iteration */
+ yinc1 = 0; /* Don't change the y when numerator >= denominator */
+ den = deltay;
+ num = deltay / 2;
+ numadd = deltax;
+ numpixels = deltay; /* There are more y-values than x-values */
+ }
+
+ for (curpixel = 0; curpixel <= numpixels; curpixel++)
+ {
+ PutPixel(x, y); /* Draw the current pixel */
+ num += numadd; /* Increase the numerator by the top of the fraction */
+ if (num >= den) /* Check if numerator >= denominator */
+ {
+ num -= den; /* Calculate the new numerator value */
+ x += xinc1; /* Change the x as appropriate */
+ y += yinc1; /* Change the y as appropriate */
+ }
+ x += xinc2; /* Change the x as appropriate */
+ y += yinc2; /* Change the y as appropriate */
+ }
+}
+
+/**
+ * @brief Displays an polyline (between many points).
+ * @param Points: pointer to the points array.
+ * @param PointCount: Number of points.
+ * @retval None
+ */
+void LCD_PolyLine(pPoint Points, uint16_t PointCount)
+{
+ int16_t X = 0, Y = 0;
+
+ if(PointCount < 2)
+ {
+ return;
+ }
+
+ while(--PointCount)
+ {
+ X = Points->X;
+ Y = Points->Y;
+ Points++;
+ LCD_DrawUniLine(X, Y, Points->X, Points->Y);
+ }
+}
+
+/**
+ * @brief Displays an relative polyline (between many points).
+ * @param Points: pointer to the points array.
+ * @param PointCount: Number of points.
+ * @param Closed: specifies if the draw is closed or not.
+ * 1: closed, 0 : not closed.
+ * @retval None
+ */
+static void LCD_PolyLineRelativeClosed(pPoint Points, uint16_t PointCount, uint16_t Closed)
+{
+ int16_t X = 0, Y = 0;
+ pPoint First = Points;
+
+ if(PointCount < 2)
+ {
+ return;
+ }
+ X = Points->X;
+ Y = Points->Y;
+ while(--PointCount)
+ {
+ Points++;
+ LCD_DrawUniLine(X, Y, X + Points->X, Y + Points->Y);
+ X = X + Points->X;
+ Y = Y + Points->Y;
+ }
+ if(Closed)
+ {
+ LCD_DrawUniLine(First->X, First->Y, X, Y);
+ }
+}
+
+/**
+ * @brief Displays a closed polyline (between many points).
+ * @param Points: pointer to the points array.
+ * @param PointCount: Number of points.
+ * @retval None
+ */
+void LCD_ClosedPolyLine(pPoint Points, uint16_t PointCount)
+{
+ LCD_PolyLine(Points, PointCount);
+ LCD_DrawUniLine(Points->X, Points->Y, (Points+PointCount-1)->X, (Points+PointCount-1)->Y);
+}
+
+/**
+ * @brief Displays a relative polyline (between many points).
+ * @param Points: pointer to the points array.
+ * @param PointCount: Number of points.
+ * @retval None
+ */
+void LCD_PolyLineRelative(pPoint Points, uint16_t PointCount)
+{
+ LCD_PolyLineRelativeClosed(Points, PointCount, 0);
+}
+
+/**
+ * @brief Displays a closed relative polyline (between many points).
+ * @param Points: pointer to the points array.
+ * @param PointCount: Number of points.
+ * @retval None
+ */
+void LCD_ClosedPolyLineRelative(pPoint Points, uint16_t PointCount)
+{
+ LCD_PolyLineRelativeClosed(Points, PointCount, 1);
+}
+
+/**
+ * @brief Displays a full polyline (between many points).
+ * @param Points: pointer to the points array.
+ * @param PointCount: Number of points.
+ * @retval None
+ */
+void LCD_FillPolyLine(pPoint Points, uint16_t PointCount)
+{
+ /* public-domain code by Darel Rex Finley, 2007 */
+ uint16_t nodes = 0, nodeX[MAX_POLY_CORNERS], pixelX = 0, pixelY = 0, i = 0,
+ j = 0, swap = 0;
+ uint16_t IMAGE_LEFT = 0, IMAGE_RIGHT = 0, IMAGE_TOP = 0, IMAGE_BOTTOM = 0;
+
+ IMAGE_LEFT = IMAGE_RIGHT = Points->X;
+ IMAGE_TOP= IMAGE_BOTTOM = Points->Y;
+
+ for(i = 1; i < PointCount; i++)
+ {
+ pixelX = POLY_X(i);
+ if(pixelX < IMAGE_LEFT)
+ {
+ IMAGE_LEFT = pixelX;
+ }
+ if(pixelX > IMAGE_RIGHT)
+ {
+ IMAGE_RIGHT = pixelX;
+ }
+
+ pixelY = POLY_Y(i);
+ if(pixelY < IMAGE_TOP)
+ {
+ IMAGE_TOP = pixelY;
+ }
+ if(pixelY > IMAGE_BOTTOM)
+ {
+ IMAGE_BOTTOM = pixelY;
+ }
+ }
+
+ LCD_SetTextColor(BackColor);
+
+ /* Loop through the rows of the image. */
+ for (pixelY = IMAGE_TOP; pixelY < IMAGE_BOTTOM; pixelY++)
+ {
+ /* Build a list of nodes. */
+ nodes = 0; j = PointCount-1;
+
+ for (i = 0; i < PointCount; i++)
+ {
+ if (((POLY_Y(i)<(double) pixelY) && (POLY_Y(j)>=(double) pixelY)) || \
+ ((POLY_Y(j)<(double) pixelY) && (POLY_Y(i)>=(double) pixelY)))
+ {
+ nodeX[nodes++]=(int) (POLY_X(i)+((pixelY-POLY_Y(i))*(POLY_X(j)-POLY_X(i)))/(POLY_Y(j)-POLY_Y(i)));
+ }
+ j = i;
+ }
+
+ /* Sort the nodes, via a simple "Bubble" sort. */
+ i = 0;
+ while (i < nodes-1)
+ {
+ if (nodeX[i]>nodeX[i+1])
+ {
+ swap = nodeX[i];
+ nodeX[i] = nodeX[i+1];
+ nodeX[i+1] = swap;
+ if(i)
+ {
+ i--;
+ }
+ }
+ else
+ {
+ i++;
+ }
+ }
+
+ /* Fill the pixels between node pairs. */
+ for (i = 0; i < nodes; i+=2)
+ {
+ if(nodeX[i] >= IMAGE_RIGHT)
+ {
+ break;
+ }
+ if(nodeX[i+1] > IMAGE_LEFT)
+ {
+ if (nodeX[i] < IMAGE_LEFT)
+ {
+ nodeX[i]=IMAGE_LEFT;
+ }
+ if(nodeX[i+1] > IMAGE_RIGHT)
+ {
+ nodeX[i+1] = IMAGE_RIGHT;
+ }
+ LCD_SetTextColor(BackColor);
+ LCD_DrawLine(pixelY, nodeX[i+1], nodeX[i+1] - nodeX[i], LCD_DIR_HORIZONTAL);
+ LCD_SetTextColor(TextColor);
+ PutPixel(pixelY, nodeX[i+1]);
+ PutPixel(pixelY, nodeX[i]);
+ /* for (j=nodeX[i]; j<nodeX[i+1]; j++) PutPixel(j,pixelY); */
+ }
+ }
+ }
+
+ /* draw the edges */
+ LCD_SetTextColor(TextColor);
+}
+
+/**
+ * @brief Writes to the selected LCD register.
+ * @param LCD_Reg: address of the selected register.
+ * @param LCD_RegValue: value to write to the selected register.
+ * @retval None
+ */
+void LCD_WriteReg(uint8_t LCD_Reg, uint16_t LCD_RegValue)
+{
+ /* Write 16-bit Index, then Write Reg */
+ TFT_LCD->LCD_REG_W = LCD_Reg;
+ /* Write 16-bit Reg */
+ TFT_LCD->LCD_RAM_W = LCD_RegValue;
+}
+
+/**
+ * @brief Reads the selected LCD Register.
+ * @param LCD_Reg: address of the selected register.
+ * @retval LCD Register Value.
+ */
+uint16_t LCD_ReadReg(uint8_t LCD_Reg)
+{
+ /* Write 16-bit Index (then Read Reg) */
+ TFT_LCD->LCD_REG_W = LCD_Reg;
+ /* Read 16-bit Reg */
+ return (TFT_LCD->LCD_RAM_R);
+}
+
+/**
+ * @brief Prepare to write to the LCD RAM.
+ * @param None
+ * @retval None
+ */
+void LCD_WriteRAM_Prepare(void)
+{
+ TFT_LCD->LCD_REG_W = LCD_REG_34;
+}
+
+/**
+ * @brief Writes to the LCD RAM.
+ * @param RGB_Code: the pixel color in RGB mode (5-6-5).
+ * @retval None
+ */
+void LCD_WriteRAM(uint16_t RGB_Code)
+{
+ /* Write 16-bit GRAM Reg */
+ TFT_LCD->LCD_RAM_W = RGB_Code;
+}
+
+/**
+ * @brief Reads the LCD RAM.
+ * @param None
+ * @retval LCD RAM Value.
+ */
+uint16_t LCD_ReadRAM(void)
+{
+ /* Write 16-bit Index (then Read Reg) */
+ TFT_LCD->LCD_REG_W = LCD_REG_34; /* Select GRAM Reg */
+ /* Read 16-bit Reg */
+ return TFT_LCD->LCD_RAM_R;
+}
+
+/**
+ * @brief Power on the LCD.
+ * @param None
+ * @retval None
+ */
+void LCD_PowerOn(void)
+{
+/* Power On sequence ---------------------------------------------------------*/
+ LCD_WriteReg(LCD_REG_16, 0x0000); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
+ LCD_WriteReg(LCD_REG_17, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */
+ LCD_WriteReg(LCD_REG_18, 0x0000); /* VREG1OUT voltage */
+ LCD_WriteReg(LCD_REG_19, 0x0000); /* VDV[4:0] for VCOM amplitude*/
+ _delay_(20); /* Dis-charge capacitor power voltage (200ms) */
+ LCD_WriteReg(LCD_REG_16, 0x17B0); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
+ LCD_WriteReg(LCD_REG_17, 0x0137); /* DC1[2:0], DC0[2:0], VC[2:0] */
+ _delay_(5); /* Delay 50 ms */
+ LCD_WriteReg(LCD_REG_18, 0x0139); /* VREG1OUT voltage */
+ _delay_(5); /* Delay 50 ms */
+ LCD_WriteReg(LCD_REG_19, 0x1d00); /* VDV[4:0] for VCOM amplitude */
+ LCD_WriteReg(LCD_REG_41, 0x0013); /* VCM[4:0] for VCOMH */
+ _delay_(5); /* Delay 50 ms */
+ LCD_WriteReg(LCD_REG_7, 0x0173); /* 262K color and display ON */
+}
+
+/**
+ * @brief Enables the Display.
+ * @param None
+ * @retval None
+ */
+void LCD_DisplayOn(void)
+{
+ if(LCD_ID == LCD_HX8347D)
+ {
+ LCD_WriteReg(LCD_REG_40, 0x38);
+ _delay_(6);
+ LCD_WriteReg(LCD_REG_40, 0x3C);
+ }
+ else
+ {
+ /* Display On */
+ LCD_WriteReg(LCD_REG_7, 0x0173); /* 262K color and display ON */
+ }
+}
+
+/**
+ * @brief Disables the Display.
+ * @param None
+ * @retval None
+ */
+void LCD_DisplayOff(void)
+{
+ if(LCD_ID == LCD_HX8347D)
+ {
+ LCD_WriteReg(LCD_REG_40, 0x38);
+ _delay_(6);
+ LCD_WriteReg(LCD_REG_40, 0x04);
+ }
+ else
+ {
+ /* Display Off */
+ LCD_WriteReg(LCD_REG_7, 0x0);
+ }
+}
+
+/**
+ * @brief Configures LCD Control lines (FSMC Pins) in alternate function mode.
+ * @param None
+ * @retval None
+ */
+void LCD_CtrlLinesConfig(void)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+
+ /* Enable GPIOD, GPIOE, GPIOF and GPIOG clocks */
+ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOD | RCC_AHBPeriph_GPIOE | RCC_AHBPeriph_GPIOF |
+ RCC_AHBPeriph_GPIOG, ENABLE);
+
+/*-- GPIO Configuration ------------------------------------------------------*/
+ /* Set PD.00(D2), PD.01(D3), PD.04(NOE), PD.05(NWE), PD.08(D13), PD.09(D14),
+ PD.10(D15), PD.14(D0), PD.15(D1) as alternate function push pull */
+ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_4 | GPIO_Pin_5 |
+ GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_14 |
+ GPIO_Pin_15;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
+ GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
+ GPIO_Init(GPIOD, &GPIO_InitStructure);
+
+ GPIO_PinAFConfig(GPIOD, GPIO_PinSource0, GPIO_AF_FSMC);
+ GPIO_PinAFConfig(GPIOD, GPIO_PinSource1, GPIO_AF_FSMC);
+ GPIO_PinAFConfig(GPIOD, GPIO_PinSource4, GPIO_AF_FSMC);
+ GPIO_PinAFConfig(GPIOD, GPIO_PinSource5, GPIO_AF_FSMC);
+ GPIO_PinAFConfig(GPIOD, GPIO_PinSource8, GPIO_AF_FSMC);
+ GPIO_PinAFConfig(GPIOD, GPIO_PinSource9, GPIO_AF_FSMC);
+ GPIO_PinAFConfig(GPIOD, GPIO_PinSource10, GPIO_AF_FSMC);
+ GPIO_PinAFConfig(GPIOD, GPIO_PinSource14, GPIO_AF_FSMC);
+ GPIO_PinAFConfig(GPIOD, GPIO_PinSource15, GPIO_AF_FSMC);
+
+ /* Set PE.07(D4), PE.08(D5), PE.09(D6), PE.10(D7), PE.11(D8), PE.12(D9), PE.13(D10),
+ PE.14(D11), PE.15(D12) as alternate function push pull */
+ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 |
+ GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 |
+ GPIO_Pin_15;
+ GPIO_Init(GPIOE, &GPIO_InitStructure);
+
+ GPIO_PinAFConfig(GPIOE, GPIO_PinSource7 , GPIO_AF_FSMC);
+ GPIO_PinAFConfig(GPIOE, GPIO_PinSource8 , GPIO_AF_FSMC);
+ GPIO_PinAFConfig(GPIOE, GPIO_PinSource9 , GPIO_AF_FSMC);
+ GPIO_PinAFConfig(GPIOE, GPIO_PinSource10 , GPIO_AF_FSMC);
+ GPIO_PinAFConfig(GPIOE, GPIO_PinSource11 , GPIO_AF_FSMC);
+ GPIO_PinAFConfig(GPIOE, GPIO_PinSource12 , GPIO_AF_FSMC);
+ GPIO_PinAFConfig(GPIOE, GPIO_PinSource13 , GPIO_AF_FSMC);
+ GPIO_PinAFConfig(GPIOE, GPIO_PinSource14 , GPIO_AF_FSMC);
+ GPIO_PinAFConfig(GPIOE, GPIO_PinSource15 , GPIO_AF_FSMC);
+
+ /* Set PF.00(A0 (RS)) and PF.01 (A1 (Level Shifter Direction) as alternate
+ function push pull */
+ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;
+ GPIO_Init(GPIOF, &GPIO_InitStructure);
+ GPIO_PinAFConfig(GPIOF, GPIO_PinSource0, GPIO_AF_FSMC);
+ GPIO_PinAFConfig(GPIOF, GPIO_PinSource1, GPIO_AF_FSMC);
+
+ /* Set PG.12(NE4 (LCD/CS)) as alternate function push pull - NE4(LCD /CS) */
+ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
+ GPIO_Init(GPIOG, &GPIO_InitStructure);
+ GPIO_PinAFConfig(GPIOG, GPIO_PinSource12, GPIO_AF_FSMC);
+}
+
+/**
+ * @brief Configures the Parallel interface (FSMC) for LCD(Parallel mode)
+ * @param None
+ * @retval None
+ */
+void LCD_FSMCConfig(void)
+{
+ FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure;
+ FSMC_NORSRAMTimingInitTypeDef p;
+
+ /* Enable FSMC clock */
+ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);
+
+/*-- FSMC Configuration ------------------------------------------------------*/
+/*----------------------- SRAM Bank 4 ----------------------------------------*/
+ /* FSMC_Bank1_NORSRAM4 configuration */
+ p.FSMC_AddressSetupTime = 1;
+ p.FSMC_AddressHoldTime = 0;
+ p.FSMC_DataSetupTime = 2;
+ p.FSMC_BusTurnAroundDuration = 0;
+ p.FSMC_CLKDivision = 0;
+ p.FSMC_DataLatency = 0;
+ p.FSMC_AccessMode = FSMC_AccessMode_A;
+ /* Color LCD configuration ------------------------------------
+ LCD configured as follow:
+ - Data/Address MUX = Disable
+ - Memory Type = SRAM
+ - Data Width = 16bit
+ - Write Operation = Enable
+ - Extended Mode = Enable
+ - Asynchronous Wait = Disable */
+ FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM4;
+ FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable;
+ FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM;
+ FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b;
+ FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable;
+ FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable;
+ FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low;
+ FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable;
+ FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState;
+ FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable;
+ FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable;
+ FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable;
+ FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable;
+ FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p;
+ FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p;
+ FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure);
+ /* BANK 4 (of NOR/SRAM Bank) is enabled */
+ FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM4, ENABLE);
+}
+
+/**
+ * @brief Displays a pixel.
+ * @param x: pixel x.
+ * @param y: pixel y.
+ * @retval None
+ */
+static void PutPixel(int16_t x, int16_t y)
+{
+ if(x < 0 || x > 239 || y < 0 || y > 319)
+ {
+ return;
+ }
+ LCD_DrawLine(x, y, 1, LCD_DIR_HORIZONTAL);
+}
+
+#ifndef USE_Delay
+/**
+ * @brief Inserts a delay time.
+ * @param nCount: specifies the delay time length.
+ * @retval None
+ */
+static void delay(__IO uint32_t nCount)
+{
+ __IO uint32_t index = 0;
+ for(index = (10000 * nCount); index != 0; index--)
+ {
+ }
+}
+#endif /* USE_Delay*/
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval_lcd.h b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval_lcd.h
new file mode 100644
index 0000000..46016c8
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval_lcd.h
@@ -0,0 +1,385 @@
+/**
+ ******************************************************************************
+ * @file stm32l152d_eval_lcd.h
+ * @author MCD Application Team
+ * @version V1.0.1
+ * @date 09-March-2012
+ * @brief This file contains all the functions prototypes for the stm32l152d_eval_lcd
+ * firmware driver.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.st.com/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __STM32L152D_EVAL_LCD_H
+#define __STM32L152D_EVAL_LCD_H
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+/* Includes ------------------------------------------------------------------*/
+#include "stm32l152d_eval.h"
+#include "../Common/fonts.h"
+
+/** @addtogroup Utilities
+ * @{
+ */
+
+/** @addtogroup STM32_EVAL
+ * @{
+ */
+
+/** @addtogroup STM32L152D_EVAL
+ * @{
+ */
+
+/** @addtogroup STM32L152D_EVAL_LCD
+ * @{
+ */
+
+/** @defgroup STM32L152D_EVAL_LCD_Exported_Types
+ * @{
+ */
+typedef struct
+{
+ int16_t X;
+ int16_t Y;
+} Point, * pPoint;
+/**
+ * @}
+ */
+
+/** @defgroup STM32L152D_EVAL_LCD_Exported_Constants
+ * @{
+ */
+
+/**
+ * @brief Uncomment the line below if you want to use user defined Delay function
+ * (for precise timing), otherwise default _delay_ function defined within
+ * this driver is used (less precise timing).
+ */
+/* #define USE_Delay */
+
+#ifdef USE_Delay
+#include "main.h"
+ #define _delay_ Delay /* !< User can provide more timing precise _delay_ function
+ (with 10ms time base), using SysTick for example */
+#else
+ #define _delay_ delay /* !< Default _delay_ function with less precise timing */
+#endif
+
+/**
+ * @brief LCD Registers
+ */
+#define LCD_REG_0 0x00
+#define LCD_REG_1 0x01
+#define LCD_REG_2 0x02
+#define LCD_REG_3 0x03
+#define LCD_REG_4 0x04
+#define LCD_REG_5 0x05
+#define LCD_REG_6 0x06
+#define LCD_REG_7 0x07
+#define LCD_REG_8 0x08
+#define LCD_REG_9 0x09
+#define LCD_REG_10 0x0A
+#define LCD_REG_12 0x0C
+#define LCD_REG_13 0x0D
+#define LCD_REG_14 0x0E
+#define LCD_REG_15 0x0F
+#define LCD_REG_16 0x10
+#define LCD_REG_17 0x11
+#define LCD_REG_18 0x12
+#define LCD_REG_19 0x13
+#define LCD_REG_20 0x14
+#define LCD_REG_21 0x15
+#define LCD_REG_22 0x16
+#define LCD_REG_23 0x17
+#define LCD_REG_24 0x18
+#define LCD_REG_25 0x19
+#define LCD_REG_26 0x1A
+#define LCD_REG_27 0x1B
+#define LCD_REG_28 0x1C
+#define LCD_REG_29 0x1D
+#define LCD_REG_30 0x1E
+#define LCD_REG_31 0x1F
+#define LCD_REG_32 0x20
+#define LCD_REG_33 0x21
+#define LCD_REG_34 0x22
+#define LCD_REG_35 0x23
+#define LCD_REG_36 0x24
+#define LCD_REG_37 0x25
+#define LCD_REG_39 0x27
+#define LCD_REG_40 0x28
+#define LCD_REG_41 0x29
+#define LCD_REG_43 0x2B
+#define LCD_REG_45 0x2D
+#define LCD_REG_48 0x30
+#define LCD_REG_49 0x31
+#define LCD_REG_50 0x32
+#define LCD_REG_51 0x33
+#define LCD_REG_52 0x34
+#define LCD_REG_53 0x35
+#define LCD_REG_54 0x36
+#define LCD_REG_55 0x37
+#define LCD_REG_56 0x38
+#define LCD_REG_57 0x39
+#define LCD_REG_58 0x3A
+#define LCD_REG_59 0x3B
+#define LCD_REG_60 0x3C
+#define LCD_REG_61 0x3D
+#define LCD_REG_62 0x3E
+#define LCD_REG_63 0x3F
+#define LCD_REG_64 0x40
+#define LCD_REG_65 0x41
+#define LCD_REG_66 0x42
+#define LCD_REG_67 0x43
+#define LCD_REG_68 0x44
+#define LCD_REG_69 0x45
+#define LCD_REG_70 0x46
+#define LCD_REG_71 0x47
+#define LCD_REG_72 0x48
+#define LCD_REG_73 0x49
+#define LCD_REG_74 0x4A
+#define LCD_REG_75 0x4B
+#define LCD_REG_76 0x4C
+#define LCD_REG_77 0x4D
+#define LCD_REG_78 0x4E
+#define LCD_REG_79 0x4F
+#define LCD_REG_80 0x50
+#define LCD_REG_81 0x51
+#define LCD_REG_82 0x52
+#define LCD_REG_83 0x53
+#define LCD_REG_84 0x54
+#define LCD_REG_85 0x55
+#define LCD_REG_86 0x56
+#define LCD_REG_87 0x57
+#define LCD_REG_88 0x58
+#define LCD_REG_89 0x59
+#define LCD_REG_90 0x5A
+#define LCD_REG_91 0x5B
+#define LCD_REG_92 0x5C
+#define LCD_REG_93 0x5D
+#define LCD_REG_96 0x60
+#define LCD_REG_97 0x61
+#define LCD_REG_106 0x6A
+#define LCD_REG_118 0x76
+#define LCD_REG_128 0x80
+#define LCD_REG_129 0x81
+#define LCD_REG_130 0x82
+#define LCD_REG_131 0x83
+#define LCD_REG_132 0x84
+#define LCD_REG_133 0x85
+#define LCD_REG_134 0x86
+#define LCD_REG_135 0x87
+#define LCD_REG_136 0x88
+#define LCD_REG_137 0x89
+#define LCD_REG_139 0x8B
+#define LCD_REG_140 0x8C
+#define LCD_REG_141 0x8D
+#define LCD_REG_143 0x8F
+#define LCD_REG_144 0x90
+#define LCD_REG_145 0x91
+#define LCD_REG_146 0x92
+#define LCD_REG_147 0x93
+#define LCD_REG_148 0x94
+#define LCD_REG_149 0x95
+#define LCD_REG_150 0x96
+#define LCD_REG_151 0x97
+#define LCD_REG_152 0x98
+#define LCD_REG_153 0x99
+#define LCD_REG_154 0x9A
+#define LCD_REG_157 0x9D
+#define LCD_REG_192 0xC0
+#define LCD_REG_193 0xC1
+#define LCD_REG_229 0xE5
+#define LCD_REG_232 0xE8
+#define LCD_REG_233 0xE9
+#define LCD_REG_234 0xEA
+#define LCD_REG_235 0xEB
+#define LCD_REG_236 0xEC
+#define LCD_REG_237 0xED
+#define LCD_REG_241 0xF1
+#define LCD_REG_242 0xF2
+
+/**
+ * @brief LCD color
+ */
+#define LCD_COLOR_WHITE 0xFFFF
+#define LCD_COLOR_BLACK 0x0000
+#define LCD_COLOR_GREY 0xF7DE
+#define LCD_COLOR_BLUE 0x001F
+#define LCD_COLOR_BLUE2 0x051F
+#define LCD_COLOR_RED 0xF800
+#define LCD_COLOR_MAGENTA 0xF81F
+#define LCD_COLOR_GREEN 0x07E0
+#define LCD_COLOR_CYAN 0x7FFF
+#define LCD_COLOR_YELLOW 0xFFE0
+
+/**
+ * @brief LCD Lines depending on the chosen fonts.
+ */
+#define LCD_LINE_0 LINE(0)
+#define LCD_LINE_1 LINE(1)
+#define LCD_LINE_2 LINE(2)
+#define LCD_LINE_3 LINE(3)
+#define LCD_LINE_4 LINE(4)
+#define LCD_LINE_5 LINE(5)
+#define LCD_LINE_6 LINE(6)
+#define LCD_LINE_7 LINE(7)
+#define LCD_LINE_8 LINE(8)
+#define LCD_LINE_9 LINE(9)
+#define LCD_LINE_10 LINE(10)
+#define LCD_LINE_11 LINE(11)
+#define LCD_LINE_12 LINE(12)
+#define LCD_LINE_13 LINE(13)
+#define LCD_LINE_14 LINE(14)
+#define LCD_LINE_15 LINE(15)
+#define LCD_LINE_16 LINE(16)
+#define LCD_LINE_17 LINE(17)
+#define LCD_LINE_18 LINE(18)
+#define LCD_LINE_19 LINE(19)
+#define LCD_LINE_20 LINE(20)
+#define LCD_LINE_21 LINE(21)
+#define LCD_LINE_22 LINE(22)
+#define LCD_LINE_23 LINE(23)
+#define LCD_LINE_24 LINE(24)
+#define LCD_LINE_25 LINE(25)
+#define LCD_LINE_26 LINE(26)
+#define LCD_LINE_27 LINE(27)
+#define LCD_LINE_28 LINE(28)
+#define LCD_LINE_29 LINE(29)
+
+/**
+ * @brief LCD default font
+ */
+#define LCD_DEFAULT_FONT Font16x24
+
+/**
+ * @brief LCD Direction
+ */
+#define LCD_DIR_HORIZONTAL 0x0000
+#define LCD_DIR_VERTICAL 0x0001
+
+/**
+ * @brief LCD Size (Width and Height)
+ */
+#define LCD_PIXEL_WIDTH 0x0140
+#define LCD_PIXEL_HEIGHT 0x00F0
+
+/**
+ * @}
+ */
+
+/** @defgroup STM32L152D_EVAL_LCD_Exported_Macros
+ * @{
+ */
+#define ASSEMBLE_RGB(R, G, B) ((((R)& 0xF8) << 8) | (((G) & 0xFC) << 3) | (((B) & 0xF8) >> 3))
+/**
+ * @}
+ */
+
+/** @defgroup STM32L152D_EVAL_LCD_Exported_Functions
+ * @{
+ */
+/** @defgroup
+ * @{
+ */
+void STM32L152D_LCD_DeInit(void);
+void STM32L152D_LCD_Init(void);
+void LCD_SetColors(__IO uint16_t _TextColor, __IO uint16_t _BackColor);
+void LCD_GetColors(__IO uint16_t *_TextColor, __IO uint16_t *_BackColor);
+void LCD_SetTextColor(__IO uint16_t Color);
+void LCD_SetBackColor(__IO uint16_t Color);
+void LCD_ClearLine(uint16_t Line);
+void LCD_Clear(uint16_t Color);
+void LCD_SetCursor(uint16_t Xpos, uint16_t Ypos);
+void LCD_DrawChar(uint16_t Xpos, uint16_t Ypos, const uint16_t *c);
+void LCD_DisplayChar(uint16_t Line, uint16_t Column, uint8_t Ascii);
+void LCD_SetFont(sFONT *fonts);
+sFONT *LCD_GetFont(void);
+void LCD_DisplayStringLine(uint16_t Line, uint8_t *ptr);
+void LCD_SetDisplayWindow(uint16_t Xpos, uint16_t Ypos, uint8_t Height, uint16_t Width);
+void LCD_WindowModeDisable(void);
+void LCD_DrawLine(uint16_t Xpos, uint16_t Ypos, uint16_t Length, uint8_t Direction);
+void LCD_DrawRect(uint16_t Xpos, uint16_t Ypos, uint8_t Height, uint16_t Width);
+void LCD_DrawCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius);
+void LCD_DrawMonoPict(const uint32_t *Pict);
+void LCD_WriteBMP(uint32_t BmpAddress);
+void LCD_DrawUniLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2);
+void LCD_DrawFullRect(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height);
+void LCD_DrawFullCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius);
+void LCD_PolyLine(pPoint Points, uint16_t PointCount);
+void LCD_PolyLineRelative(pPoint Points, uint16_t PointCount);
+void LCD_ClosedPolyLine(pPoint Points, uint16_t PointCount);
+void LCD_ClosedPolyLineRelative(pPoint Points, uint16_t PointCount);
+void LCD_FillPolyLine(pPoint Points, uint16_t PointCount);
+/**
+ * @}
+ */
+
+/** @defgroup
+ * @{
+ */
+void LCD_WriteReg(uint8_t LCD_Reg, uint16_t LCD_RegValue);
+uint16_t LCD_ReadReg(uint8_t LCD_Reg);
+void LCD_WriteRAM_Prepare(void);
+void LCD_WriteRAM(uint16_t RGB_Code);
+uint16_t LCD_ReadRAM(void);
+void LCD_PowerOn(void);
+void LCD_DisplayOn(void);
+void LCD_DisplayOff(void);
+/**
+ * @}
+ */
+
+/** @defgroup
+ * @{
+ */
+void LCD_CtrlLinesConfig(void);
+void LCD_FSMCConfig(void);
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __STM32L152D_EVAL_LCD_H */
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval_sdio_sd.c b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval_sdio_sd.c
new file mode 100644
index 0000000..f95f418
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval_sdio_sd.c
@@ -0,0 +1,2818 @@
+/**
+ ******************************************************************************
+ * @file stm32l152d_eval_sdio_sd.c
+ * @author MCD Application Team
+ * @version V1.0.1
+ * @date 09-March-2012
+ * @brief This file provides a set of functions needed to manage the SDIO SD
+ * Card memory mounted on STM32L152D-EVAL evaluation board.
+ *
+ *
+ * @verbatim
+ *
+ * ===================================================================
+ * How to use this driver
+ * ===================================================================
+ * It implements a high level communication layer for read and write
+ * from/to this memory. The needed STM32 hardware resources (SDIO and
+ * GPIO) are defined in stm32l152d_eval.h file, and the initialization is
+ * performed in SD_LowLevel_Init() function declared in stm32l152d_eval.c
+ * file.
+ * You can easily tailor this driver to any other development board,
+ * by just adapting the defines for hardware resources and
+ * SD_LowLevel_Init() function.
+ *
+ * A - SD Card Initialization and configuration
+ * ============================================
+ * - To initialize the SD Card, use the SD_Init() function. It
+ * Initializes the SD Card and put it into StandBy State (Ready
+ * for data transfer). This function provide the following operations:
+ *
+ * 1 - Apply the SD Card initialization process at 400KHz and check
+ * the SD Card type (Standard Capacity or High Capacity). You
+ * can change or adapt this frequency by adjusting the
+ * "SDIO_INIT_CLK_DIV" define inside the stm32l152d_eval.h file.
+ * The SD Card frequency (SDIO_CK) is computed as follows:
+ *
+ * +---------------------------------------------+
+ * | SDIO_CK = SDIOCLK / (SDIO_INIT_CLK_DIV + 2) |
+ * +---------------------------------------------+
+ *
+ * In initialization mode and according to the SD Card standard,
+ * make sure that the SDIO_CK frequency don't exceed 400KHz.
+ *
+ * 2 - Get the SD CID and CSD data. All these information are
+ * managed by the SDCardInfo structure. This structure provide
+ * also ready computed SD Card capacity and Block size.
+ *
+ * 3 - Configure the SD Card Data transfer frequency. By Default,
+ * the card transfer frequency is set to 24MHz. You can change
+ * or adapt this frequency by adjusting the "SDIO_TRANSFER_CLK_DIV"
+ * define inside the stm32l152d_eval.h file.
+ * The SD Card frequency (SDIO_CK) is computed as follows:
+ *
+ * +---------------------------------------------+
+ * | SDIO_CK = SDIOCLK / (SDIO_INIT_CLK_DIV + 2) |
+ * +---------------------------------------------+
+ *
+ * In transfer mode and according to the SD Card standard,
+ * make sure that the SDIO_CK frequency don't exceed 25MHz
+ * and 50MHz in High-speed mode switch.
+ * To be able to use a frequency higher than 24MHz, you should
+ * use the SDIO peripheral in bypass mode. Refer to the
+ * corresponding reference manual for more details.
+ *
+ * 4 - Select the corresponding SD Card according to the address
+ * read with the step 2.
+ *
+ * 5 - Configure the SD Card in wide bus mode: 4-bits data.
+ *
+ * B - SD Card Read operation
+ * ==========================
+ * - You can read SD card by using two function: SD_ReadBlock() and
+ * SD_ReadMultiBlocks() functions. These functions support only
+ * 512-byte block length.
+ * - The SD_ReadBlock() function read only one block (512-byte). This
+ * function can transfer the data using DMA controller or using
+ * polling mode. To select between DMA or polling mode refer to
+ * "SD_DMA_MODE" or "SD_POLLING_MODE" inside the stm32l152d_eval_sdio_sd.h
+ * file and uncomment the corresponding line. By default the SD DMA
+ * mode is selected
+ * - The SD_ReadMultiBlocks() function read only mutli blocks (multiple
+ * of 512-byte).
+ * - Any read operation should be followed by two functions to check
+ * if the DMA Controller and SD Card status.
+ * - SD_ReadWaitOperation(): this function insure that the DMA
+ * controller has finished all data transfer.
+ * - SD_GetStatus(): to check that the SD Card has finished the
+ * data transfer and it is ready for data.
+ *
+ * - The DMA transfer is finished by the SDIO Data End interrupt.
+ * User has to call the SD_ProcessIRQ() function inside the SDIO_IRQHandler()
+ * and SD_ProcessDMAIRQ() function inside the DMA2_Channel4_IRQHandler().
+ * Don't forget to enable the SDIO_IRQn and DMA2_Channel4_IRQn
+ * interrupts using the NVIC controller.
+ *
+ * C - SD Card Write operation
+ * ===========================
+ * - You can write SD card by using two function: SD_WriteBlock() and
+ * SD_WriteMultiBlocks() functions. These functions support only
+ * 512-byte block length.
+ * - The SD_WriteBlock() function write only one block (512-byte). This
+ * function can transfer the data using DMA controller or using
+ * polling mode. To select between DMA or polling mode refer to
+ * "SD_DMA_MODE" or "SD_POLLING_MODE" inside the stm32l152d_eval_sdio_sd.h
+ * file and uncomment the corresponding line. By default the SD DMA
+ * mode is selected
+ * - The SD_WriteMultiBlocks() function write only mutli blocks (multiple
+ * of 512-byte).
+ * - Any write operation should be followed by two functions to check
+ * if the DMA Controller and SD Card status.
+ * - SD_ReadWaitOperation(): this function insure that the DMA
+ * controller has finished all data transfer.
+ * - SD_GetStatus(): to check that the SD Card has finished the
+ * data transfer and it is ready for data.
+ *
+ * - The DMA transfer is finished by the SDIO Data End interrupt.
+ * User has to call the SD_ProcessIRQ() function inside the SDIO_IRQHandler()
+ * and SD_ProcessDMAIRQ() function inside the DMA2_Channel4_IRQHandler().
+ * Don't forget to enable the SDIO_IRQn and DMA2_Channel4_IRQn
+ * interrupts using the NVIC controller.
+ *
+ *
+ * D - SD card status
+ * ==================
+ * - At any time, you can check the SD Card status and get the SD card
+ * state by using the SD_GetStatus() function. This function checks
+ * first if the SD card is still connected and then get the internal
+ * SD Card transfer state.
+ * - You can also get the SD card SD Status register by using the
+ * SD_SendSDStatus() function.
+ *
+ * E - Programming Model (Selecting DMA for SDIO data Transfer)
+ * ============================================================
+ * Status = SD_Init(); // Initialization Step as described in section A
+ *
+ * // SDIO Interrupt ENABLE
+ * NVIC_InitStructure.NVIC_IRQChannel = SDIO_IRQn;
+ * NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
+ * NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
+ * NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
+ * NVIC_Init(&NVIC_InitStructure);
+ * // DMA2 Channel4 Interrupt ENABLE
+ * NVIC_InitStructure.NVIC_IRQChannel = SD_SDIO_DMA_IRQn;
+ * NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
+ * NVIC_Init(&NVIC_InitStructure);
+ *
+ * // Write operation as described in Section C
+ * Status = SD_WriteBlock(buffer, address, 512);
+ * Status = SD_WaitWriteOperation();
+ * while(SD_GetStatus() != SD_TRANSFER_OK);
+ *
+ * Status = SD_WriteMultiBlocks(buffer, address, 512, NUMBEROFBLOCKS);
+ * Status = SD_WaitWriteOperation();
+ * while(SD_GetStatus() != SD_TRANSFER_OK);
+ *
+ * // Read operation as described in Section B
+ * Status = SD_ReadBlock(buffer, address, 512);
+ * Status = SD_WaitReadOperation();
+ * while(SD_GetStatus() != SD_TRANSFER_OK);
+ *
+ * Status = SD_ReadMultiBlocks(buffer, address, 512, NUMBEROFBLOCKS);
+ * Status = SD_WaitReadOperation();
+ * while(SD_GetStatus() != SD_TRANSFER_OK);
+ *
+ * - Add the SDIO and DMA2 Channel4 IRQ Handlers:
+ * void SDIO_IRQHandler(void)
+ * {
+ * SD_ProcessIRQ();
+ * }
+ * void SD_SDIO_DMA_IRQHANDLER(void)
+ * {
+ * SD_ProcessDMAIRQ();
+ * }
+ *
+ * F - Programming Model (Selecting Polling for SDIO data Transfer)
+ * ================================================================
+ * //Only SD Card Single Block operation are managed.
+ * Status = SD_Init(); // Initialization Step as described in section
+ *
+ * // Write operation as described in Section C
+ * Status = SD_WriteBlock(buffer, address, 512);
+ *
+ * // Read operation as described in Section B
+ * Status = SD_ReadBlock(buffer, address, 512);
+ *
+ * STM32 SDIO Pin assignment
+ * =========================
+ * +-----------------------------------------------------------+
+ * | Pin assignment |
+ * +-----------------------------+---------------+-------------+
+ * | STM32 SDIO Pins | SD | Pin |
+ * +-----------------------------+---------------+-------------+
+ * | SDIO D2 | D2 | 1 |
+ * | SDIO D3 | D3 | 2 |
+ * | SDIO CMD | CMD | 3 |
+ * | | VCC | 4 (3.3 V)|
+ * | SDIO CLK | CLK | 5 |
+ * | | GND | 6 (0 V) |
+ * | SDIO D0 | D0 | 7 |
+ * | SDIO D1 | D1 | 8 |
+ * +-----------------------------+---------------+-------------+
+ *
+ * @endverbatim
+ *
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.st.com/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+
+/* Includes ------------------------------------------------------------------*/
+#include "stm32l152d_eval_sdio_sd.h"
+
+
+/** @addtogroup Utilities
+ * @{
+ */
+
+/** @addtogroup STM32_EVAL
+ * @{
+ */
+
+/** @addtogroup STM32L152D_EVAL
+ * @{
+ */
+
+/** @addtogroup STM32L152D_EVAL_SDIO_SD
+ * @brief This file provides all the SD Card driver firmware functions.
+ * @{
+ */
+
+/** @defgroup STM32L152D_EVAL_SDIO_SD_Private_Types
+ * @{
+ */
+/**
+ * @}
+ */
+
+
+/** @defgroup STM32L152D_EVAL_SDIO_SD_Private_Defines
+ * @{
+ */
+
+/**
+ * @brief SDIO Static flags, TimeOut, FIFO Address
+ */
+#define NULL 0
+#define SDIO_STATIC_FLAGS ((uint32_t)0x000005FF)
+#define SDIO_CMD0TIMEOUT ((uint32_t)0x00010000)
+
+/**
+ * @brief Mask for errors Card Status R1 (OCR Register)
+ */
+#define SD_OCR_ADDR_OUT_OF_RANGE ((uint32_t)0x80000000)
+#define SD_OCR_ADDR_MISALIGNED ((uint32_t)0x40000000)
+#define SD_OCR_BLOCK_LEN_ERR ((uint32_t)0x20000000)
+#define SD_OCR_ERASE_SEQ_ERR ((uint32_t)0x10000000)
+#define SD_OCR_BAD_ERASE_PARAM ((uint32_t)0x08000000)
+#define SD_OCR_WRITE_PROT_VIOLATION ((uint32_t)0x04000000)
+#define SD_OCR_LOCK_UNLOCK_FAILED ((uint32_t)0x01000000)
+#define SD_OCR_COM_CRC_FAILED ((uint32_t)0x00800000)
+#define SD_OCR_ILLEGAL_CMD ((uint32_t)0x00400000)
+#define SD_OCR_CARD_ECC_FAILED ((uint32_t)0x00200000)
+#define SD_OCR_CC_ERROR ((uint32_t)0x00100000)
+#define SD_OCR_GENERAL_UNKNOWN_ERROR ((uint32_t)0x00080000)
+#define SD_OCR_STREAM_READ_UNDERRUN ((uint32_t)0x00040000)
+#define SD_OCR_STREAM_WRITE_OVERRUN ((uint32_t)0x00020000)
+#define SD_OCR_CID_CSD_OVERWRIETE ((uint32_t)0x00010000)
+#define SD_OCR_WP_ERASE_SKIP ((uint32_t)0x00008000)
+#define SD_OCR_CARD_ECC_DISABLED ((uint32_t)0x00004000)
+#define SD_OCR_ERASE_RESET ((uint32_t)0x00002000)
+#define SD_OCR_AKE_SEQ_ERROR ((uint32_t)0x00000008)
+#define SD_OCR_ERRORBITS ((uint32_t)0xFDFFE008)
+
+/**
+ * @brief Masks for R6 Response
+ */
+#define SD_R6_GENERAL_UNKNOWN_ERROR ((uint32_t)0x00002000)
+#define SD_R6_ILLEGAL_CMD ((uint32_t)0x00004000)
+#define SD_R6_COM_CRC_FAILED ((uint32_t)0x00008000)
+
+#define SD_VOLTAGE_WINDOW_SD ((uint32_t)0x80100000)
+#define SD_HIGH_CAPACITY ((uint32_t)0x40000000)
+#define SD_STD_CAPACITY ((uint32_t)0x00000000)
+#define SD_CHECK_PATTERN ((uint32_t)0x000001AA)
+
+#define SD_MAX_VOLT_TRIAL ((uint32_t)0x0000FFFF)
+#define SD_ALLZERO ((uint32_t)0x00000000)
+
+#define SD_WIDE_BUS_SUPPORT ((uint32_t)0x00040000)
+#define SD_SINGLE_BUS_SUPPORT ((uint32_t)0x00010000)
+#define SD_CARD_LOCKED ((uint32_t)0x02000000)
+
+#define SD_DATATIMEOUT ((uint32_t)0xFFFFFFFF)
+#define SD_0TO7BITS ((uint32_t)0x000000FF)
+#define SD_8TO15BITS ((uint32_t)0x0000FF00)
+#define SD_16TO23BITS ((uint32_t)0x00FF0000)
+#define SD_24TO31BITS ((uint32_t)0xFF000000)
+#define SD_MAX_DATA_LENGTH ((uint32_t)0x01FFFFFF)
+
+#define SD_HALFFIFO ((uint32_t)0x00000008)
+#define SD_HALFFIFOBYTES ((uint32_t)0x00000020)
+
+/**
+ * @brief Command Class Supported
+ */
+#define SD_CCCC_LOCK_UNLOCK ((uint32_t)0x00000080)
+#define SD_CCCC_WRITE_PROT ((uint32_t)0x00000040)
+#define SD_CCCC_ERASE ((uint32_t)0x00000020)
+
+/**
+ * @brief Following commands are SD Card Specific commands.
+ * SDIO_APP_CMD should be sent before sending these commands.
+ */
+#define SDIO_SEND_IF_COND ((uint32_t)0x00000008)
+
+/**
+ * @}
+ */
+
+/** @defgroup STM32L152D_EVAL_SDIO_SD_Private_Macros
+ * @{
+ */
+/**
+ * @}
+ */
+
+/** @defgroup STM32L152D_EVAL_SDIO_SD_Private_Variables
+ * @{
+ */
+
+static uint32_t CardType = SDIO_STD_CAPACITY_SD_CARD_V1_1;
+static uint32_t CSD_Tab[4], CID_Tab[4], RCA = 0;
+static uint8_t SDSTATUS_Tab[16];
+__IO uint32_t StopCondition = 0;
+__IO SD_Error TransferError = SD_OK;
+__IO uint32_t TransferEnd = 0, DMAEndOfTransfer = 0;
+SD_CardInfo SDCardInfo;
+
+SDIO_InitTypeDef SDIO_InitStructure;
+SDIO_CmdInitTypeDef SDIO_CmdInitStructure;
+SDIO_DataInitTypeDef SDIO_DataInitStructure;
+/**
+ * @}
+ */
+
+
+/** @defgroup STM32L152D_EVAL_SDIO_SD_Private_Function_Prototypes
+ * @{
+ */
+static SD_Error CmdError(void);
+static SD_Error CmdResp1Error(uint8_t cmd);
+static SD_Error CmdResp7Error(void);
+static SD_Error CmdResp3Error(void);
+static SD_Error CmdResp2Error(void);
+static SD_Error CmdResp6Error(uint8_t cmd, uint16_t *prca);
+static SD_Error SDEnWideBus(FunctionalState NewState);
+static SD_Error IsCardProgramming(uint8_t *pstatus);
+static SD_Error FindSCR(uint16_t rca, uint32_t *pscr);
+uint8_t convert_from_bytes_to_power_of_two(uint16_t NumberOfBytes);
+
+/**
+ * @}
+ */
+
+
+/** @defgroup STM32L152D_EVAL_SDIO_SD_Private_Functions
+ * @{
+ */
+
+/**
+ * @brief DeInitializes the SDIO interface.
+ * @param None
+ * @retval None
+ */
+void SD_DeInit(void)
+{
+ SD_LowLevel_DeInit();
+}
+
+/**
+ * @brief Initializes the SD Card and put it into StandBy State (Ready for data
+ * transfer).
+ * @param None
+ * @retval SD_Error: SD Card Error code.
+ */
+SD_Error SD_Init(void)
+{
+ __IO SD_Error errorstatus = SD_OK;
+
+ /* SDIO Peripheral Low Level Init */
+ SD_LowLevel_Init();
+
+ SDIO_DeInit();
+
+ errorstatus = SD_PowerON();
+
+ if (errorstatus != SD_OK)
+ {
+ /*!< CMD Response TimeOut (wait for CMDSENT flag) */
+ return(errorstatus);
+ }
+
+ errorstatus = SD_InitializeCards();
+
+ if (errorstatus != SD_OK)
+ {
+ /*!< CMD Response TimeOut (wait for CMDSENT flag) */
+ return(errorstatus);
+ }
+
+ /*!< Configure the SDIO peripheral */
+ /*!< SDIO_CK = SDIOCLK / (SDIO_TRANSFER_CLK_DIV + 2) */
+ /*!< on STM32L1xx devices, SDIOCLK is fixed to 48MHz */
+ SDIO_InitStructure.SDIO_ClockDiv = SDIO_TRANSFER_CLK_DIV;
+ SDIO_InitStructure.SDIO_ClockEdge = SDIO_ClockEdge_Rising;
+ SDIO_InitStructure.SDIO_ClockBypass = SDIO_ClockBypass_Disable;
+ SDIO_InitStructure.SDIO_ClockPowerSave = SDIO_ClockPowerSave_Disable;
+ SDIO_InitStructure.SDIO_BusWide = SDIO_BusWide_1b;
+ SDIO_InitStructure.SDIO_HardwareFlowControl = SDIO_HardwareFlowControl_Disable;
+ SDIO_Init(&SDIO_InitStructure);
+
+ /*----------------- Read CSD/CID MSD registers ------------------*/
+ errorstatus = SD_GetCardInfo(&SDCardInfo);
+
+ if (errorstatus == SD_OK)
+ {
+ /*----------------- Select Card --------------------------------*/
+ errorstatus = SD_SelectDeselect((uint32_t) (SDCardInfo.RCA << 16));
+ }
+
+ if (errorstatus == SD_OK)
+ {
+ errorstatus = SD_EnableWideBusOperation(SDIO_BusWide_4b);
+ }
+
+ return(errorstatus);
+}
+
+/**
+ * @brief Gets the cuurent sd card data transfer status.
+ * @param None
+ * @retval SDTransferState: Data Transfer state.
+ * This value can be:
+ * - SD_TRANSFER_OK: No data transfer is acting
+ * - SD_TRANSFER_BUSY: Data transfer is acting
+ */
+SDTransferState SD_GetStatus(void)
+{
+ SDCardState cardstate = SD_CARD_TRANSFER;
+
+ cardstate = SD_GetState();
+
+ if (cardstate == SD_CARD_TRANSFER)
+ {
+ return(SD_TRANSFER_OK);
+ }
+ else if(cardstate == SD_CARD_ERROR)
+ {
+ return (SD_TRANSFER_ERROR);
+ }
+ else
+ {
+ return(SD_TRANSFER_BUSY);
+ }
+}
+
+/**
+ * @brief Returns the current card's state.
+ * @param None
+ * @retval SDCardState: SD Card Error or SD Card Current State.
+ */
+SDCardState SD_GetState(void)
+{
+ uint32_t resp1 = 0;
+
+ if(SD_Detect()== SD_PRESENT)
+ {
+ if (SD_SendStatus(&resp1) != SD_OK)
+ {
+ return SD_CARD_ERROR;
+ }
+ else
+ {
+ return (SDCardState)((resp1 >> 9) & 0x0F);
+ }
+ }
+ else
+ {
+ return SD_CARD_ERROR;
+ }
+}
+
+/**
+ * @brief Detect if SD card is correctly plugged in the memory slot.
+ * @param None
+ * @retval Return if SD is detected or not
+ */
+uint8_t SD_Detect(void)
+{
+ __IO uint8_t status = SD_PRESENT;
+
+ /*!< Check GPIO to detect SD */
+ if (GPIO_ReadInputDataBit(SD_DETECT_GPIO_PORT, SD_DETECT_PIN) != Bit_RESET)
+ {
+ status = SD_NOT_PRESENT;
+ }
+ return status;
+}
+
+/**
+ * @brief Enquires cards about their operating voltage and configures
+ * clock controls.
+ * @param None
+ * @retval SD_Error: SD Card Error code.
+ */
+SD_Error SD_PowerON(void)
+{
+ __IO SD_Error errorstatus = SD_OK;
+ uint32_t response = 0, count = 0, validvoltage = 0;
+ uint32_t SDType = SD_STD_CAPACITY;
+
+ /*!< Power ON Sequence -----------------------------------------------------*/
+ /*!< Configure the SDIO peripheral */
+ /*!< SDIO_CK = SDIOCLK / (SDIO_INIT_CLK_DIV + 2) */
+ /*!< on STM32L1xx devices, SDIOCLK is fixed to 48MHz */
+ /*!< SDIO_CK for initialization should not exceed 400 KHz */
+ SDIO_InitStructure.SDIO_ClockDiv = SDIO_INIT_CLK_DIV;
+ SDIO_InitStructure.SDIO_ClockEdge = SDIO_ClockEdge_Rising;
+ SDIO_InitStructure.SDIO_ClockBypass = SDIO_ClockBypass_Disable;
+ SDIO_InitStructure.SDIO_ClockPowerSave = SDIO_ClockPowerSave_Disable;
+ SDIO_InitStructure.SDIO_BusWide = SDIO_BusWide_1b;
+ SDIO_InitStructure.SDIO_HardwareFlowControl = SDIO_HardwareFlowControl_Disable;
+ SDIO_Init(&SDIO_InitStructure);
+
+ /*!< Set Power State to ON */
+ SDIO_SetPowerState(SDIO_PowerState_ON);
+
+ /*!< Enable SDIO Clock */
+ SDIO_ClockCmd(ENABLE);
+
+ /*!< CMD0: GO_IDLE_STATE ---------------------------------------------------*/
+ /*!< No CMD response required */
+ SDIO_CmdInitStructure.SDIO_Argument = 0x0;
+ SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_GO_IDLE_STATE;
+ SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_No;
+ SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
+ SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
+ SDIO_SendCommand(&SDIO_CmdInitStructure);
+
+ errorstatus = CmdError();
+
+ if (errorstatus != SD_OK)
+ {
+ /*!< CMD Response TimeOut (wait for CMDSENT flag) */
+ return(errorstatus);
+ }
+
+ /*!< CMD8: SEND_IF_COND ----------------------------------------------------*/
+ /*!< Send CMD8 to verify SD card interface operating condition */
+ /*!< Argument: - [31:12]: Reserved (shall be set to '0')
+ - [11:8]: Supply Voltage (VHS) 0x1 (Range: 2.7-3.6 V)
+ - [7:0]: Check Pattern (recommended 0xAA) */
+ /*!< CMD Response: R7 */
+ SDIO_CmdInitStructure.SDIO_Argument = SD_CHECK_PATTERN;
+ SDIO_CmdInitStructure.SDIO_CmdIndex = SDIO_SEND_IF_COND;
+ SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
+ SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
+ SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
+ SDIO_SendCommand(&SDIO_CmdInitStructure);
+
+ errorstatus = CmdResp7Error();
+
+ if (errorstatus == SD_OK)
+ {
+ CardType = SDIO_STD_CAPACITY_SD_CARD_V2_0; /*!< SD Card 2.0 */
+ SDType = SD_HIGH_CAPACITY;
+ }
+ else
+ {
+ /*!< CMD55 */
+ SDIO_CmdInitStructure.SDIO_Argument = 0x00;
+ SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_APP_CMD;
+ SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
+ SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
+ SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
+ SDIO_SendCommand(&SDIO_CmdInitStructure);
+ errorstatus = CmdResp1Error(SD_CMD_APP_CMD);
+ }
+ /*!< CMD55 */
+ SDIO_CmdInitStructure.SDIO_Argument = 0x00;
+ SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_APP_CMD;
+ SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
+ SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
+ SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
+ SDIO_SendCommand(&SDIO_CmdInitStructure);
+ errorstatus = CmdResp1Error(SD_CMD_APP_CMD);
+
+ /*!< If errorstatus is Command TimeOut, it is a MMC card */
+ /*!< If errorstatus is SD_OK it is a SD card: SD card 2.0 (voltage range mismatch)
+ or SD card 1.x */
+ if (errorstatus == SD_OK)
+ {
+ /*!< SD CARD */
+ /*!< Send ACMD41 SD_APP_OP_COND with Argument 0x80100000 */
+ while ((!validvoltage) && (count < SD_MAX_VOLT_TRIAL))
+ {
+
+ /*!< SEND CMD55 APP_CMD with RCA as 0 */
+ SDIO_CmdInitStructure.SDIO_Argument = 0x00;
+ SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_APP_CMD;
+ SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
+ SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
+ SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
+ SDIO_SendCommand(&SDIO_CmdInitStructure);
+
+ errorstatus = CmdResp1Error(SD_CMD_APP_CMD);
+
+ if (errorstatus != SD_OK)
+ {
+ return(errorstatus);
+ }
+ SDIO_CmdInitStructure.SDIO_Argument = SD_VOLTAGE_WINDOW_SD | SDType;
+ SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_SD_APP_OP_COND;
+ SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
+ SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
+ SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
+ SDIO_SendCommand(&SDIO_CmdInitStructure);
+
+ errorstatus = CmdResp3Error();
+ if (errorstatus != SD_OK)
+ {
+ return(errorstatus);
+ }
+
+ response = SDIO_GetResponse(SDIO_RESP1);
+ validvoltage = (((response >> 31) == 1) ? 1 : 0);
+ count++;
+ }
+ if (count >= SD_MAX_VOLT_TRIAL)
+ {
+ errorstatus = SD_INVALID_VOLTRANGE;
+ return(errorstatus);
+ }
+
+ if (response &= SD_HIGH_CAPACITY)
+ {
+ CardType = SDIO_HIGH_CAPACITY_SD_CARD;
+ }
+
+ }/*!< else MMC Card */
+
+ return(errorstatus);
+}
+
+/**
+ * @brief Turns the SDIO output signals off.
+ * @param None
+ * @retval SD_Error: SD Card Error code.
+ */
+SD_Error SD_PowerOFF(void)
+{
+ SD_Error errorstatus = SD_OK;
+
+ /*!< Set Power State to OFF */
+ SDIO_SetPowerState(SDIO_PowerState_OFF);
+
+ return(errorstatus);
+}
+
+/**
+ * @brief Intialises all cards or single card as the case may be Card(s) come
+ * into standby state.
+ * @param None
+ * @retval SD_Error: SD Card Error code.
+ */
+SD_Error SD_InitializeCards(void)
+{
+ SD_Error errorstatus = SD_OK;
+ uint16_t rca = 0x01;
+
+ if (SDIO_GetPowerState() == SDIO_PowerState_OFF)
+ {
+ errorstatus = SD_REQUEST_NOT_APPLICABLE;
+ return(errorstatus);
+ }
+
+ if (SDIO_SECURE_DIGITAL_IO_CARD != CardType)
+ {
+ /*!< Send CMD2 ALL_SEND_CID */
+ SDIO_CmdInitStructure.SDIO_Argument = 0x0;
+ SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_ALL_SEND_CID;
+ SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Long;
+ SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
+ SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
+ SDIO_SendCommand(&SDIO_CmdInitStructure);
+
+ errorstatus = CmdResp2Error();
+
+ if (SD_OK != errorstatus)
+ {
+ return(errorstatus);
+ }
+
+ CID_Tab[0] = SDIO_GetResponse(SDIO_RESP1);
+ CID_Tab[1] = SDIO_GetResponse(SDIO_RESP2);
+ CID_Tab[2] = SDIO_GetResponse(SDIO_RESP3);
+ CID_Tab[3] = SDIO_GetResponse(SDIO_RESP4);
+ }
+ if ((SDIO_STD_CAPACITY_SD_CARD_V1_1 == CardType) || (SDIO_STD_CAPACITY_SD_CARD_V2_0 == CardType) || (SDIO_SECURE_DIGITAL_IO_COMBO_CARD == CardType)
+ || (SDIO_HIGH_CAPACITY_SD_CARD == CardType))
+ {
+ /*!< Send CMD3 SET_REL_ADDR with argument 0 */
+ /*!< SD Card publishes its RCA. */
+ SDIO_CmdInitStructure.SDIO_Argument = 0x00;
+ SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_SET_REL_ADDR;
+ SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
+ SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
+ SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
+ SDIO_SendCommand(&SDIO_CmdInitStructure);
+
+ errorstatus = CmdResp6Error(SD_CMD_SET_REL_ADDR, &rca);
+
+ if (SD_OK != errorstatus)
+ {
+ return(errorstatus);
+ }
+ }
+
+ if (SDIO_SECURE_DIGITAL_IO_CARD != CardType)
+ {
+ RCA = rca;
+
+ /*!< Send CMD9 SEND_CSD with argument as card's RCA */
+ SDIO_CmdInitStructure.SDIO_Argument = (uint32_t)(rca << 16);
+ SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_SEND_CSD;
+ SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Long;
+ SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
+ SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
+ SDIO_SendCommand(&SDIO_CmdInitStructure);
+
+ errorstatus = CmdResp2Error();
+
+ if (SD_OK != errorstatus)
+ {
+ return(errorstatus);
+ }
+
+ CSD_Tab[0] = SDIO_GetResponse(SDIO_RESP1);
+ CSD_Tab[1] = SDIO_GetResponse(SDIO_RESP2);
+ CSD_Tab[2] = SDIO_GetResponse(SDIO_RESP3);
+ CSD_Tab[3] = SDIO_GetResponse(SDIO_RESP4);
+ }
+
+ errorstatus = SD_OK; /*!< All cards get intialized */
+
+ return(errorstatus);
+}
+
+/**
+ * @brief Returns information about specific card.
+ * @param cardinfo: pointer to a SD_CardInfo structure that contains all SD card
+ * information.
+ * @retval SD_Error: SD Card Error code.
+ */
+SD_Error SD_GetCardInfo(SD_CardInfo *cardinfo)
+{
+ SD_Error errorstatus = SD_OK;
+ uint8_t tmp = 0;
+
+ cardinfo->CardType = (uint8_t)CardType;
+ cardinfo->RCA = (uint16_t)RCA;
+
+ /*!< Byte 0 */
+ tmp = (uint8_t)((CSD_Tab[0] & 0xFF000000) >> 24);
+ cardinfo->SD_csd.CSDStruct = (tmp & 0xC0) >> 6;
+ cardinfo->SD_csd.SysSpecVersion = (tmp & 0x3C) >> 2;
+ cardinfo->SD_csd.Reserved1 = tmp & 0x03;
+
+ /*!< Byte 1 */
+ tmp = (uint8_t)((CSD_Tab[0] & 0x00FF0000) >> 16);
+ cardinfo->SD_csd.TAAC = tmp;
+
+ /*!< Byte 2 */
+ tmp = (uint8_t)((CSD_Tab[0] & 0x0000FF00) >> 8);
+ cardinfo->SD_csd.NSAC = tmp;
+
+ /*!< Byte 3 */
+ tmp = (uint8_t)(CSD_Tab[0] & 0x000000FF);
+ cardinfo->SD_csd.MaxBusClkFrec = tmp;
+
+ /*!< Byte 4 */
+ tmp = (uint8_t)((CSD_Tab[1] & 0xFF000000) >> 24);
+ cardinfo->SD_csd.CardComdClasses = tmp << 4;
+
+ /*!< Byte 5 */
+ tmp = (uint8_t)((CSD_Tab[1] & 0x00FF0000) >> 16);
+ cardinfo->SD_csd.CardComdClasses |= (tmp & 0xF0) >> 4;
+ cardinfo->SD_csd.RdBlockLen = tmp & 0x0F;
+
+ /*!< Byte 6 */
+ tmp = (uint8_t)((CSD_Tab[1] & 0x0000FF00) >> 8);
+ cardinfo->SD_csd.PartBlockRead = (tmp & 0x80) >> 7;
+ cardinfo->SD_csd.WrBlockMisalign = (tmp & 0x40) >> 6;
+ cardinfo->SD_csd.RdBlockMisalign = (tmp & 0x20) >> 5;
+ cardinfo->SD_csd.DSRImpl = (tmp & 0x10) >> 4;
+ cardinfo->SD_csd.Reserved2 = 0; /*!< Reserved */
+
+ if ((CardType == SDIO_STD_CAPACITY_SD_CARD_V1_1) || (CardType == SDIO_STD_CAPACITY_SD_CARD_V2_0))
+ {
+ cardinfo->SD_csd.DeviceSize = (tmp & 0x03) << 10;
+
+ /*!< Byte 7 */
+ tmp = (uint8_t)(CSD_Tab[1] & 0x000000FF);
+ cardinfo->SD_csd.DeviceSize |= (tmp) << 2;
+
+ /*!< Byte 8 */
+ tmp = (uint8_t)((CSD_Tab[2] & 0xFF000000) >> 24);
+ cardinfo->SD_csd.DeviceSize |= (tmp & 0xC0) >> 6;
+
+ cardinfo->SD_csd.MaxRdCurrentVDDMin = (tmp & 0x38) >> 3;
+ cardinfo->SD_csd.MaxRdCurrentVDDMax = (tmp & 0x07);
+
+ /*!< Byte 9 */
+ tmp = (uint8_t)((CSD_Tab[2] & 0x00FF0000) >> 16);
+ cardinfo->SD_csd.MaxWrCurrentVDDMin = (tmp & 0xE0) >> 5;
+ cardinfo->SD_csd.MaxWrCurrentVDDMax = (tmp & 0x1C) >> 2;
+ cardinfo->SD_csd.DeviceSizeMul = (tmp & 0x03) << 1;
+ /*!< Byte 10 */
+ tmp = (uint8_t)((CSD_Tab[2] & 0x0000FF00) >> 8);
+ cardinfo->SD_csd.DeviceSizeMul |= (tmp & 0x80) >> 7;
+
+ cardinfo->CardCapacity = (cardinfo->SD_csd.DeviceSize + 1) ;
+ cardinfo->CardCapacity *= (1 << (cardinfo->SD_csd.DeviceSizeMul + 2));
+ cardinfo->CardBlockSize = 1 << (cardinfo->SD_csd.RdBlockLen);
+ cardinfo->CardCapacity *= cardinfo->CardBlockSize;
+ }
+ else if (CardType == SDIO_HIGH_CAPACITY_SD_CARD)
+ {
+ /*!< Byte 7 */
+ tmp = (uint8_t)(CSD_Tab[1] & 0x000000FF);
+ cardinfo->SD_csd.DeviceSize = (tmp & 0x3F) << 16;
+
+ /*!< Byte 8 */
+ tmp = (uint8_t)((CSD_Tab[2] & 0xFF000000) >> 24);
+
+ cardinfo->SD_csd.DeviceSize |= (tmp << 8);
+
+ /*!< Byte 9 */
+ tmp = (uint8_t)((CSD_Tab[2] & 0x00FF0000) >> 16);
+
+ cardinfo->SD_csd.DeviceSize |= (tmp);
+
+ /*!< Byte 10 */
+ tmp = (uint8_t)((CSD_Tab[2] & 0x0000FF00) >> 8);
+
+ cardinfo->CardCapacity = (cardinfo->SD_csd.DeviceSize + 1) * 512 * 1024;
+ cardinfo->CardBlockSize = 512;
+ }
+
+
+ cardinfo->SD_csd.EraseGrSize = (tmp & 0x40) >> 6;
+ cardinfo->SD_csd.EraseGrMul = (tmp & 0x3F) << 1;
+
+ /*!< Byte 11 */
+ tmp = (uint8_t)(CSD_Tab[2] & 0x000000FF);
+ cardinfo->SD_csd.EraseGrMul |= (tmp & 0x80) >> 7;
+ cardinfo->SD_csd.WrProtectGrSize = (tmp & 0x7F);
+
+ /*!< Byte 12 */
+ tmp = (uint8_t)((CSD_Tab[3] & 0xFF000000) >> 24);
+ cardinfo->SD_csd.WrProtectGrEnable = (tmp & 0x80) >> 7;
+ cardinfo->SD_csd.ManDeflECC = (tmp & 0x60) >> 5;
+ cardinfo->SD_csd.WrSpeedFact = (tmp & 0x1C) >> 2;
+ cardinfo->SD_csd.MaxWrBlockLen = (tmp & 0x03) << 2;
+
+ /*!< Byte 13 */
+ tmp = (uint8_t)((CSD_Tab[3] & 0x00FF0000) >> 16);
+ cardinfo->SD_csd.MaxWrBlockLen |= (tmp & 0xC0) >> 6;
+ cardinfo->SD_csd.WriteBlockPaPartial = (tmp & 0x20) >> 5;
+ cardinfo->SD_csd.Reserved3 = 0;
+ cardinfo->SD_csd.ContentProtectAppli = (tmp & 0x01);
+
+ /*!< Byte 14 */
+ tmp = (uint8_t)((CSD_Tab[3] & 0x0000FF00) >> 8);
+ cardinfo->SD_csd.FileFormatGrouop = (tmp & 0x80) >> 7;
+ cardinfo->SD_csd.CopyFlag = (tmp & 0x40) >> 6;
+ cardinfo->SD_csd.PermWrProtect = (tmp & 0x20) >> 5;
+ cardinfo->SD_csd.TempWrProtect = (tmp & 0x10) >> 4;
+ cardinfo->SD_csd.FileFormat = (tmp & 0x0C) >> 2;
+ cardinfo->SD_csd.ECC = (tmp & 0x03);
+
+ /*!< Byte 15 */
+ tmp = (uint8_t)(CSD_Tab[3] & 0x000000FF);
+ cardinfo->SD_csd.CSD_CRC = (tmp & 0xFE) >> 1;
+ cardinfo->SD_csd.Reserved4 = 1;
+
+
+ /*!< Byte 0 */
+ tmp = (uint8_t)((CID_Tab[0] & 0xFF000000) >> 24);
+ cardinfo->SD_cid.ManufacturerID = tmp;
+
+ /*!< Byte 1 */
+ tmp = (uint8_t)((CID_Tab[0] & 0x00FF0000) >> 16);
+ cardinfo->SD_cid.OEM_AppliID = tmp << 8;
+
+ /*!< Byte 2 */
+ tmp = (uint8_t)((CID_Tab[0] & 0x000000FF00) >> 8);
+ cardinfo->SD_cid.OEM_AppliID |= tmp;
+
+ /*!< Byte 3 */
+ tmp = (uint8_t)(CID_Tab[0] & 0x000000FF);
+ cardinfo->SD_cid.ProdName1 = tmp << 24;
+
+ /*!< Byte 4 */
+ tmp = (uint8_t)((CID_Tab[1] & 0xFF000000) >> 24);
+ cardinfo->SD_cid.ProdName1 |= tmp << 16;
+
+ /*!< Byte 5 */
+ tmp = (uint8_t)((CID_Tab[1] & 0x00FF0000) >> 16);
+ cardinfo->SD_cid.ProdName1 |= tmp << 8;
+
+ /*!< Byte 6 */
+ tmp = (uint8_t)((CID_Tab[1] & 0x0000FF00) >> 8);
+ cardinfo->SD_cid.ProdName1 |= tmp;
+
+ /*!< Byte 7 */
+ tmp = (uint8_t)(CID_Tab[1] & 0x000000FF);
+ cardinfo->SD_cid.ProdName2 = tmp;
+
+ /*!< Byte 8 */
+ tmp = (uint8_t)((CID_Tab[2] & 0xFF000000) >> 24);
+ cardinfo->SD_cid.ProdRev = tmp;
+
+ /*!< Byte 9 */
+ tmp = (uint8_t)((CID_Tab[2] & 0x00FF0000) >> 16);
+ cardinfo->SD_cid.ProdSN = tmp << 24;
+
+ /*!< Byte 10 */
+ tmp = (uint8_t)((CID_Tab[2] & 0x0000FF00) >> 8);
+ cardinfo->SD_cid.ProdSN |= tmp << 16;
+
+ /*!< Byte 11 */
+ tmp = (uint8_t)(CID_Tab[2] & 0x000000FF);
+ cardinfo->SD_cid.ProdSN |= tmp << 8;
+
+ /*!< Byte 12 */
+ tmp = (uint8_t)((CID_Tab[3] & 0xFF000000) >> 24);
+ cardinfo->SD_cid.ProdSN |= tmp;
+
+ /*!< Byte 13 */
+ tmp = (uint8_t)((CID_Tab[3] & 0x00FF0000) >> 16);
+ cardinfo->SD_cid.Reserved1 |= (tmp & 0xF0) >> 4;
+ cardinfo->SD_cid.ManufactDate = (tmp & 0x0F) << 8;
+
+ /*!< Byte 14 */
+ tmp = (uint8_t)((CID_Tab[3] & 0x0000FF00) >> 8);
+ cardinfo->SD_cid.ManufactDate |= tmp;
+
+ /*!< Byte 15 */
+ tmp = (uint8_t)(CID_Tab[3] & 0x000000FF);
+ cardinfo->SD_cid.CID_CRC = (tmp & 0xFE) >> 1;
+ cardinfo->SD_cid.Reserved2 = 1;
+
+ return(errorstatus);
+}
+
+/**
+ * @brief Enables wide bus opeartion for the requeseted card if supported by
+ * card.
+ * @param WideMode: Specifies the SD card wide bus mode.
+ * This parameter can be one of the following values:
+ * @arg SDIO_BusWide_8b: 8-bit data transfer (Only for MMC)
+ * @arg SDIO_BusWide_4b: 4-bit data transfer
+ * @arg SDIO_BusWide_1b: 1-bit data transfer
+ * @retval SD_Error: SD Card Error code.
+ */
+SD_Error SD_GetCardStatus(SD_CardStatus *cardstatus)
+{
+ SD_Error errorstatus = SD_OK;
+ uint8_t tmp = 0;
+
+ errorstatus = SD_SendSDStatus((uint32_t *)SDSTATUS_Tab);
+
+ if (errorstatus != SD_OK)
+ {
+ return(errorstatus);
+ }
+
+ /*!< Byte 0 */
+ tmp = (uint8_t)((SDSTATUS_Tab[0] & 0xC0) >> 6);
+ cardstatus->DAT_BUS_WIDTH = tmp;
+
+ /*!< Byte 0 */
+ tmp = (uint8_t)((SDSTATUS_Tab[0] & 0x20) >> 5);
+ cardstatus->SECURED_MODE = tmp;
+
+ /*!< Byte 2 */
+ tmp = (uint8_t)((SDSTATUS_Tab[2] & 0xFF));
+ cardstatus->SD_CARD_TYPE = tmp << 8;
+
+ /*!< Byte 3 */
+ tmp = (uint8_t)((SDSTATUS_Tab[3] & 0xFF));
+ cardstatus->SD_CARD_TYPE |= tmp;
+
+ /*!< Byte 4 */
+ tmp = (uint8_t)(SDSTATUS_Tab[4] & 0xFF);
+ cardstatus->SIZE_OF_PROTECTED_AREA = tmp << 24;
+
+ /*!< Byte 5 */
+ tmp = (uint8_t)(SDSTATUS_Tab[5] & 0xFF);
+ cardstatus->SIZE_OF_PROTECTED_AREA |= tmp << 16;
+
+ /*!< Byte 6 */
+ tmp = (uint8_t)(SDSTATUS_Tab[6] & 0xFF);
+ cardstatus->SIZE_OF_PROTECTED_AREA |= tmp << 8;
+
+ /*!< Byte 7 */
+ tmp = (uint8_t)(SDSTATUS_Tab[7] & 0xFF);
+ cardstatus->SIZE_OF_PROTECTED_AREA |= tmp;
+
+ /*!< Byte 8 */
+ tmp = (uint8_t)((SDSTATUS_Tab[8] & 0xFF));
+ cardstatus->SPEED_CLASS = tmp;
+
+ /*!< Byte 9 */
+ tmp = (uint8_t)((SDSTATUS_Tab[9] & 0xFF));
+ cardstatus->PERFORMANCE_MOVE = tmp;
+
+ /*!< Byte 10 */
+ tmp = (uint8_t)((SDSTATUS_Tab[10] & 0xF0) >> 4);
+ cardstatus->AU_SIZE = tmp;
+
+ /*!< Byte 11 */
+ tmp = (uint8_t)(SDSTATUS_Tab[11] & 0xFF);
+ cardstatus->ERASE_SIZE = tmp << 8;
+
+ /*!< Byte 12 */
+ tmp = (uint8_t)(SDSTATUS_Tab[12] & 0xFF);
+ cardstatus->ERASE_SIZE |= tmp;
+
+ /*!< Byte 13 */
+ tmp = (uint8_t)((SDSTATUS_Tab[13] & 0xFC) >> 2);
+ cardstatus->ERASE_TIMEOUT = tmp;
+
+ /*!< Byte 13 */
+ tmp = (uint8_t)((SDSTATUS_Tab[13] & 0x3));
+ cardstatus->ERASE_OFFSET = tmp;
+
+ return(errorstatus);
+}
+
+/**
+ * @brief Enables wide bus opeartion for the requeseted card if supported by
+ * card.
+ * @param WideMode: Specifies the SD card wide bus mode.
+ * This parameter can be one of the following values:
+ * @arg SDIO_BusWide_8b: 8-bit data transfer (Only for MMC)
+ * @arg SDIO_BusWide_4b: 4-bit data transfer
+ * @arg SDIO_BusWide_1b: 1-bit data transfer
+ * @retval SD_Error: SD Card Error code.
+ */
+SD_Error SD_EnableWideBusOperation(uint32_t WideMode)
+{
+ SD_Error errorstatus = SD_OK;
+
+ /*!< MMC Card doesn't support this feature */
+ if (SDIO_MULTIMEDIA_CARD == CardType)
+ {
+ errorstatus = SD_UNSUPPORTED_FEATURE;
+ return(errorstatus);
+ }
+ else if ((SDIO_STD_CAPACITY_SD_CARD_V1_1 == CardType) || (SDIO_STD_CAPACITY_SD_CARD_V2_0 == CardType) || (SDIO_HIGH_CAPACITY_SD_CARD == CardType))
+ {
+ if (SDIO_BusWide_8b == WideMode)
+ {
+ errorstatus = SD_UNSUPPORTED_FEATURE;
+ return(errorstatus);
+ }
+ else if (SDIO_BusWide_4b == WideMode)
+ {
+ errorstatus = SDEnWideBus(ENABLE);
+
+ if (SD_OK == errorstatus)
+ {
+ /*!< Configure the SDIO peripheral */
+ SDIO_InitStructure.SDIO_ClockDiv = SDIO_TRANSFER_CLK_DIV;
+ SDIO_InitStructure.SDIO_ClockEdge = SDIO_ClockEdge_Rising;
+ SDIO_InitStructure.SDIO_ClockBypass = SDIO_ClockBypass_Disable;
+ SDIO_InitStructure.SDIO_ClockPowerSave = SDIO_ClockPowerSave_Disable;
+ SDIO_InitStructure.SDIO_BusWide = SDIO_BusWide_4b;
+ SDIO_InitStructure.SDIO_HardwareFlowControl = SDIO_HardwareFlowControl_Disable;
+ SDIO_Init(&SDIO_InitStructure);
+ }
+ }
+ else
+ {
+ errorstatus = SDEnWideBus(DISABLE);
+
+ if (SD_OK == errorstatus)
+ {
+ /*!< Configure the SDIO peripheral */
+ SDIO_InitStructure.SDIO_ClockDiv = SDIO_TRANSFER_CLK_DIV;
+ SDIO_InitStructure.SDIO_ClockEdge = SDIO_ClockEdge_Rising;
+ SDIO_InitStructure.SDIO_ClockBypass = SDIO_ClockBypass_Disable;
+ SDIO_InitStructure.SDIO_ClockPowerSave = SDIO_ClockPowerSave_Disable;
+ SDIO_InitStructure.SDIO_BusWide = SDIO_BusWide_1b;
+ SDIO_InitStructure.SDIO_HardwareFlowControl = SDIO_HardwareFlowControl_Disable;
+ SDIO_Init(&SDIO_InitStructure);
+ }
+ }
+ }
+
+ return(errorstatus);
+}
+
+/**
+ * @brief Selects od Deselects the corresponding card.
+ * @param addr: Address of the Card to be selected.
+ * @retval SD_Error: SD Card Error code.
+ */
+SD_Error SD_SelectDeselect(uint32_t addr)
+{
+ SD_Error errorstatus = SD_OK;
+
+ /*!< Send CMD7 SDIO_SEL_DESEL_CARD */
+ SDIO_CmdInitStructure.SDIO_Argument = addr;
+ SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_SEL_DESEL_CARD;
+ SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
+ SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
+ SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
+ SDIO_SendCommand(&SDIO_CmdInitStructure);
+
+ errorstatus = CmdResp1Error(SD_CMD_SEL_DESEL_CARD);
+
+ return(errorstatus);
+}
+
+/**
+ * @brief Allows to read one block from a specified address in a card. The Data
+ * transfer can be managed by DMA mode or Polling mode.
+ * @note This operation should be followed by two functions to check if the
+ * DMA Controller and SD Card status.
+ * - SD_ReadWaitOperation(): this function insure that the DMA
+ * controller has finished all data transfer.
+ * - SD_GetStatus(): to check that the SD Card has finished the
+ * data transfer and it is ready for data.
+ * @param readbuff: pointer to the buffer that will contain the received data
+ * @param ReadAddr: Address from where data are to be read.
+ * @param BlockSize: the SD card Data block size. The Block size should be 512.
+ * @retval SD_Error: SD Card Error code.
+ */
+SD_Error SD_ReadBlock(uint8_t *readbuff, uint64_t ReadAddr, uint16_t BlockSize)
+{
+ SD_Error errorstatus = SD_OK;
+#if defined (SD_POLLING_MODE)
+ uint32_t count = 0, *tempbuff = (uint32_t *)readbuff;
+#endif
+
+ TransferError = SD_OK;
+ TransferEnd = 0;
+ StopCondition = 0;
+
+ SDIO->DCTRL = 0x0;
+
+
+ if (CardType == SDIO_HIGH_CAPACITY_SD_CARD)
+ {
+ BlockSize = 512;
+ ReadAddr /= 512;
+ }
+
+ /* Set Block Size for Card */
+ SDIO_CmdInitStructure.SDIO_Argument = (uint32_t) BlockSize;
+ SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_SET_BLOCKLEN;
+ SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
+ SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
+ SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
+ SDIO_SendCommand(&SDIO_CmdInitStructure);
+
+ errorstatus = CmdResp1Error(SD_CMD_SET_BLOCKLEN);
+
+ if (SD_OK != errorstatus)
+ {
+ return(errorstatus);
+ }
+
+ SDIO_DataInitStructure.SDIO_DataTimeOut = SD_DATATIMEOUT;
+ SDIO_DataInitStructure.SDIO_DataLength = BlockSize;
+ SDIO_DataInitStructure.SDIO_DataBlockSize = (uint32_t) 9 << 4;
+ SDIO_DataInitStructure.SDIO_TransferDir = SDIO_TransferDir_ToSDIO;
+ SDIO_DataInitStructure.SDIO_TransferMode = SDIO_TransferMode_Block;
+ SDIO_DataInitStructure.SDIO_DPSM = SDIO_DPSM_Enable;
+ SDIO_DataConfig(&SDIO_DataInitStructure);
+
+ /*!< Send CMD17 READ_SINGLE_BLOCK */
+ SDIO_CmdInitStructure.SDIO_Argument = (uint32_t)ReadAddr;
+ SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_READ_SINGLE_BLOCK;
+ SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
+ SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
+ SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
+ SDIO_SendCommand(&SDIO_CmdInitStructure);
+
+ errorstatus = CmdResp1Error(SD_CMD_READ_SINGLE_BLOCK);
+
+ if (errorstatus != SD_OK)
+ {
+ return(errorstatus);
+ }
+
+#if defined (SD_POLLING_MODE)
+ /*!< In case of single block transfer, no need of stop transfer at all.*/
+ /*!< Polling mode */
+ while (!(SDIO->STA &(SDIO_FLAG_RXOVERR | SDIO_FLAG_DCRCFAIL | SDIO_FLAG_DTIMEOUT | SDIO_FLAG_DBCKEND | SDIO_FLAG_STBITERR)))
+ {
+ if (SDIO_GetFlagStatus(SDIO_FLAG_RXFIFOHF) != RESET)
+ {
+ for (count = 0; count < 8; count++)
+ {
+ *(tempbuff + count) = SDIO_ReadData();
+ }
+ tempbuff += 8;
+ }
+ }
+
+ if (SDIO_GetFlagStatus(SDIO_FLAG_DTIMEOUT) != RESET)
+ {
+ SDIO_ClearFlag(SDIO_FLAG_DTIMEOUT);
+ errorstatus = SD_DATA_TIMEOUT;
+ return(errorstatus);
+ }
+ else if (SDIO_GetFlagStatus(SDIO_FLAG_DCRCFAIL) != RESET)
+ {
+ SDIO_ClearFlag(SDIO_FLAG_DCRCFAIL);
+ errorstatus = SD_DATA_CRC_FAIL;
+ return(errorstatus);
+ }
+ else if (SDIO_GetFlagStatus(SDIO_FLAG_RXOVERR) != RESET)
+ {
+ SDIO_ClearFlag(SDIO_FLAG_RXOVERR);
+ errorstatus = SD_RX_OVERRUN;
+ return(errorstatus);
+ }
+ else if (SDIO_GetFlagStatus(SDIO_FLAG_STBITERR) != RESET)
+ {
+ SDIO_ClearFlag(SDIO_FLAG_STBITERR);
+ errorstatus = SD_START_BIT_ERR;
+ return(errorstatus);
+ }
+ count = SD_DATATIMEOUT;
+ while ((SDIO_GetFlagStatus(SDIO_FLAG_RXDAVL) != RESET) && (count > 0))
+ {
+ *tempbuff = SDIO_ReadData();
+ tempbuff++;
+ count--;
+ }
+
+ /*!< Clear all the static flags */
+ SDIO_ClearFlag(SDIO_STATIC_FLAGS);
+
+#elif defined (SD_DMA_MODE)
+ SDIO_ITConfig(SDIO_IT_DCRCFAIL | SDIO_IT_DTIMEOUT | SDIO_IT_DATAEND | SDIO_IT_RXOVERR | SDIO_IT_STBITERR, ENABLE);
+ SDIO_DMACmd(ENABLE);
+ SD_LowLevel_DMA_RxConfig((uint32_t *)readbuff, BlockSize);
+#endif
+
+ return(errorstatus);
+}
+
+/**
+ * @brief Allows to read blocks from a specified address in a card. The Data
+ * transfer can be managed by DMA mode or Polling mode.
+ * @note This operation should be followed by two functions to check if the
+ * DMA Controller and SD Card status.
+ * - SD_ReadWaitOperation(): this function insure that the DMA
+ * controller has finished all data transfer.
+ * - SD_GetStatus(): to check that the SD Card has finished the
+ * data transfer and it is ready for data.
+ * @param readbuff: pointer to the buffer that will contain the received data.
+ * @param ReadAddr: Address from where data are to be read.
+ * @param BlockSize: the SD card Data block size. The Block size should be 512.
+ * @param NumberOfBlocks: number of blocks to be read.
+ * @retval SD_Error: SD Card Error code.
+ */
+SD_Error SD_ReadMultiBlocks(uint8_t *readbuff, uint64_t ReadAddr, uint16_t BlockSize, uint32_t NumberOfBlocks)
+{
+ SD_Error errorstatus = SD_OK;
+ TransferError = SD_OK;
+ TransferEnd = 0;
+ StopCondition = 1;
+
+ SDIO->DCTRL = 0x0;
+
+ if (CardType == SDIO_HIGH_CAPACITY_SD_CARD)
+ {
+ BlockSize = 512;
+ ReadAddr /= 512;
+ }
+
+ /*!< Set Block Size for Card */
+ SDIO_CmdInitStructure.SDIO_Argument = (uint32_t) BlockSize;
+ SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_SET_BLOCKLEN;
+ SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
+ SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
+ SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
+ SDIO_SendCommand(&SDIO_CmdInitStructure);
+
+ errorstatus = CmdResp1Error(SD_CMD_SET_BLOCKLEN);
+
+ if (SD_OK != errorstatus)
+ {
+ return(errorstatus);
+ }
+
+ SDIO_DataInitStructure.SDIO_DataTimeOut = SD_DATATIMEOUT;
+ SDIO_DataInitStructure.SDIO_DataLength = NumberOfBlocks * BlockSize;
+ SDIO_DataInitStructure.SDIO_DataBlockSize = (uint32_t) 9 << 4;
+ SDIO_DataInitStructure.SDIO_TransferDir = SDIO_TransferDir_ToSDIO;
+ SDIO_DataInitStructure.SDIO_TransferMode = SDIO_TransferMode_Block;
+ SDIO_DataInitStructure.SDIO_DPSM = SDIO_DPSM_Enable;
+ SDIO_DataConfig(&SDIO_DataInitStructure);
+
+ /*!< Send CMD18 READ_MULT_BLOCK with argument data address */
+ SDIO_CmdInitStructure.SDIO_Argument = (uint32_t)ReadAddr;
+ SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_READ_MULT_BLOCK;
+ SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
+ SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
+ SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
+ SDIO_SendCommand(&SDIO_CmdInitStructure);
+
+ errorstatus = CmdResp1Error(SD_CMD_READ_MULT_BLOCK);
+
+ if (errorstatus != SD_OK)
+ {
+ return(errorstatus);
+ }
+
+ SDIO_ITConfig(SDIO_IT_DCRCFAIL | SDIO_IT_DTIMEOUT | SDIO_IT_DATAEND | SDIO_IT_RXOVERR | SDIO_IT_STBITERR, ENABLE);
+ SDIO_DMACmd(ENABLE);
+ SD_LowLevel_DMA_RxConfig((uint32_t *)readbuff, (NumberOfBlocks * BlockSize));
+
+ return(errorstatus);
+}
+
+/**
+ * @brief This function waits until the SDIO DMA data transfer is finished.
+ * This function should be called after SDIO_ReadMultiBlocks() function
+ * to insure that all data sent by the card are already transferred by
+ * the DMA controller.
+ * @param None.
+ * @retval SD_Error: SD Card Error code.
+ */
+SD_Error SD_WaitReadOperation(void)
+{
+ SD_Error errorstatus = SD_OK;
+ uint32_t timeout;
+
+ timeout = SD_DATATIMEOUT;
+
+ while ((DMAEndOfTransfer == 0x00) && (TransferEnd == 0) && (TransferError == SD_OK) && (timeout > 0))
+ {
+ timeout--;
+ }
+
+ DMAEndOfTransfer = 0x00;
+
+ timeout = SD_DATATIMEOUT;
+
+ while(((SDIO->STA & SDIO_FLAG_RXACT)) && (timeout > 0))
+ {
+ timeout--;
+ }
+
+ if (StopCondition == 1)
+ {
+ errorstatus = SD_StopTransfer();
+ }
+
+ if ((timeout == 0) && (errorstatus == SD_OK))
+ {
+ errorstatus = SD_DATA_TIMEOUT;
+ }
+
+ /*!< Clear all the static flags */
+ SDIO_ClearFlag(SDIO_STATIC_FLAGS);
+
+ if (TransferError != SD_OK)
+ {
+ return(TransferError);
+ }
+ else
+ {
+ return(errorstatus);
+ }
+}
+
+/**
+ * @brief Allows to write one block starting from a specified address in a card.
+ * The Data transfer can be managed by DMA mode or Polling mode.
+ * @note This operation should be followed by two functions to check if the
+ * DMA Controller and SD Card status.
+ * - SD_ReadWaitOperation(): this function insure that the DMA
+ * controller has finished all data transfer.
+ * - SD_GetStatus(): to check that the SD Card has finished the
+ * data transfer and it is ready for data.
+ * @param writebuff: pointer to the buffer that contain the data to be transferred.
+ * @param WriteAddr: Address from where data are to be read.
+ * @param BlockSize: the SD card Data block size. The Block size should be 512.
+ * @retval SD_Error: SD Card Error code.
+ */
+SD_Error SD_WriteBlock(uint8_t *writebuff, uint64_t WriteAddr, uint16_t BlockSize)
+{
+ SD_Error errorstatus = SD_OK;
+
+#if defined (SD_POLLING_MODE)
+ uint32_t bytestransferred = 0, count = 0, restwords = 0;
+ uint32_t *tempbuff = (uint32_t *)writebuff;
+#endif
+
+ TransferError = SD_OK;
+ TransferEnd = 0;
+ StopCondition = 0;
+
+ SDIO->DCTRL = 0x0;
+
+
+ if (CardType == SDIO_HIGH_CAPACITY_SD_CARD)
+ {
+ BlockSize = 512;
+ WriteAddr /= 512;
+ }
+
+ /* Set Block Size for Card */
+ SDIO_CmdInitStructure.SDIO_Argument = (uint32_t) BlockSize;
+ SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_SET_BLOCKLEN;
+ SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
+ SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
+ SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
+ SDIO_SendCommand(&SDIO_CmdInitStructure);
+
+ errorstatus = CmdResp1Error(SD_CMD_SET_BLOCKLEN);
+
+ if (SD_OK != errorstatus)
+ {
+ return(errorstatus);
+ }
+
+ /*!< Send CMD24 WRITE_SINGLE_BLOCK */
+ SDIO_CmdInitStructure.SDIO_Argument = WriteAddr;
+ SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_WRITE_SINGLE_BLOCK;
+ SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
+ SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
+ SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
+ SDIO_SendCommand(&SDIO_CmdInitStructure);
+
+ errorstatus = CmdResp1Error(SD_CMD_WRITE_SINGLE_BLOCK);
+
+ if (errorstatus != SD_OK)
+ {
+ return(errorstatus);
+ }
+
+ SDIO_DataInitStructure.SDIO_DataTimeOut = SD_DATATIMEOUT;
+ SDIO_DataInitStructure.SDIO_DataLength = BlockSize;
+ SDIO_DataInitStructure.SDIO_DataBlockSize = (uint32_t) 9 << 4;
+ SDIO_DataInitStructure.SDIO_TransferDir = SDIO_TransferDir_ToCard;
+ SDIO_DataInitStructure.SDIO_TransferMode = SDIO_TransferMode_Block;
+ SDIO_DataInitStructure.SDIO_DPSM = SDIO_DPSM_Enable;
+ SDIO_DataConfig(&SDIO_DataInitStructure);
+
+ /*!< In case of single data block transfer no need of stop command at all */
+#if defined (SD_POLLING_MODE)
+ while (!(SDIO->STA & (SDIO_FLAG_DBCKEND | SDIO_FLAG_TXUNDERR | SDIO_FLAG_DCRCFAIL | SDIO_FLAG_DTIMEOUT | SDIO_FLAG_STBITERR)))
+ {
+ if (SDIO_GetFlagStatus(SDIO_FLAG_TXFIFOHE) != RESET)
+ {
+ if ((512 - bytestransferred) < 32)
+ {
+ restwords = ((512 - bytestransferred) % 4 == 0) ? ((512 - bytestransferred) / 4) : (( 512 - bytestransferred) / 4 + 1);
+ for (count = 0; count < restwords; count++, tempbuff++, bytestransferred += 4)
+ {
+ SDIO_WriteData(*tempbuff);
+ }
+ }
+ else
+ {
+ for (count = 0; count < 8; count++)
+ {
+ SDIO_WriteData(*(tempbuff + count));
+ }
+ tempbuff += 8;
+ bytestransferred += 32;
+ }
+ }
+ }
+ if (SDIO_GetFlagStatus(SDIO_FLAG_DTIMEOUT) != RESET)
+ {
+ SDIO_ClearFlag(SDIO_FLAG_DTIMEOUT);
+ errorstatus = SD_DATA_TIMEOUT;
+ return(errorstatus);
+ }
+ else if (SDIO_GetFlagStatus(SDIO_FLAG_DCRCFAIL) != RESET)
+ {
+ SDIO_ClearFlag(SDIO_FLAG_DCRCFAIL);
+ errorstatus = SD_DATA_CRC_FAIL;
+ return(errorstatus);
+ }
+ else if (SDIO_GetFlagStatus(SDIO_FLAG_TXUNDERR) != RESET)
+ {
+ SDIO_ClearFlag(SDIO_FLAG_TXUNDERR);
+ errorstatus = SD_TX_UNDERRUN;
+ return(errorstatus);
+ }
+ else if (SDIO_GetFlagStatus(SDIO_FLAG_STBITERR) != RESET)
+ {
+ SDIO_ClearFlag(SDIO_FLAG_STBITERR);
+ errorstatus = SD_START_BIT_ERR;
+ return(errorstatus);
+ }
+#elif defined (SD_DMA_MODE)
+ SDIO_ITConfig(SDIO_IT_DCRCFAIL | SDIO_IT_DTIMEOUT | SDIO_IT_DATAEND | SDIO_IT_RXOVERR | SDIO_IT_STBITERR, ENABLE);
+ SD_LowLevel_DMA_TxConfig((uint32_t *)writebuff, BlockSize);
+ SDIO_DMACmd(ENABLE);
+#endif
+
+ return(errorstatus);
+}
+
+/**
+ * @brief Allows to write blocks starting from a specified address in a card.
+ * The Data transfer can be managed by DMA mode only.
+ * @note This operation should be followed by two functions to check if the
+ * DMA Controller and SD Card status.
+ * - SD_ReadWaitOperation(): this function insure that the DMA
+ * controller has finished all data transfer.
+ * - SD_GetStatus(): to check that the SD Card has finished the
+ * data transfer and it is ready for data.
+ * @param WriteAddr: Address from where data are to be read.
+ * @param writebuff: pointer to the buffer that contain the data to be transferred.
+ * @param BlockSize: the SD card Data block size. The Block size should be 512.
+ * @param NumberOfBlocks: number of blocks to be written.
+ * @retval SD_Error: SD Card Error code.
+ */
+SD_Error SD_WriteMultiBlocks(uint8_t *writebuff, uint64_t WriteAddr, uint16_t BlockSize, uint32_t NumberOfBlocks)
+{
+ SD_Error errorstatus = SD_OK;
+
+ TransferError = SD_OK;
+ TransferEnd = 0;
+ StopCondition = 1;
+
+ SDIO->DCTRL = 0x0;
+
+ if (CardType == SDIO_HIGH_CAPACITY_SD_CARD)
+ {
+ BlockSize = 512;
+ WriteAddr /= 512;
+ }
+
+ /* Set Block Size for Card */
+ SDIO_CmdInitStructure.SDIO_Argument = (uint32_t) BlockSize;
+ SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_SET_BLOCKLEN;
+ SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
+ SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
+ SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
+ SDIO_SendCommand(&SDIO_CmdInitStructure);
+
+ errorstatus = CmdResp1Error(SD_CMD_SET_BLOCKLEN);
+
+ if (SD_OK != errorstatus)
+ {
+ return(errorstatus);
+ }
+
+ /*!< To improve performance */
+ SDIO_CmdInitStructure.SDIO_Argument = (uint32_t) (RCA << 16);
+ SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_APP_CMD;
+ SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
+ SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
+ SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
+ SDIO_SendCommand(&SDIO_CmdInitStructure);
+
+
+ errorstatus = CmdResp1Error(SD_CMD_APP_CMD);
+
+ if (errorstatus != SD_OK)
+ {
+ return(errorstatus);
+ }
+ /*!< To improve performance */
+ SDIO_CmdInitStructure.SDIO_Argument = (uint32_t)NumberOfBlocks;
+ SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_SET_BLOCK_COUNT;
+ SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
+ SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
+ SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
+ SDIO_SendCommand(&SDIO_CmdInitStructure);
+
+ errorstatus = CmdResp1Error(SD_CMD_SET_BLOCK_COUNT);
+
+ if (errorstatus != SD_OK)
+ {
+ return(errorstatus);
+ }
+
+
+ /*!< Send CMD25 WRITE_MULT_BLOCK with argument data address */
+ SDIO_CmdInitStructure.SDIO_Argument = (uint32_t)WriteAddr;
+ SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_WRITE_MULT_BLOCK;
+ SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
+ SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
+ SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
+ SDIO_SendCommand(&SDIO_CmdInitStructure);
+
+ errorstatus = CmdResp1Error(SD_CMD_WRITE_MULT_BLOCK);
+
+ if (SD_OK != errorstatus)
+ {
+ return(errorstatus);
+ }
+
+ SDIO_DataInitStructure.SDIO_DataTimeOut = SD_DATATIMEOUT;
+ SDIO_DataInitStructure.SDIO_DataLength = NumberOfBlocks * BlockSize;
+ SDIO_DataInitStructure.SDIO_DataBlockSize = (uint32_t) 9 << 4;
+ SDIO_DataInitStructure.SDIO_TransferDir = SDIO_TransferDir_ToCard;
+ SDIO_DataInitStructure.SDIO_TransferMode = SDIO_TransferMode_Block;
+ SDIO_DataInitStructure.SDIO_DPSM = SDIO_DPSM_Enable;
+ SDIO_DataConfig(&SDIO_DataInitStructure);
+
+ SDIO_ITConfig(SDIO_IT_DCRCFAIL | SDIO_IT_DTIMEOUT | SDIO_IT_DATAEND | SDIO_IT_RXOVERR | SDIO_IT_STBITERR, ENABLE);
+ SDIO_DMACmd(ENABLE);
+ SD_LowLevel_DMA_TxConfig((uint32_t *)writebuff, (NumberOfBlocks * BlockSize));
+
+ return(errorstatus);
+}
+
+/**
+ * @brief This function waits until the SDIO DMA data transfer is finished.
+ * This function should be called after SDIO_WriteBlock() and
+ * SDIO_WriteMultiBlocks() function to insure that all data sent by the
+ * card are already transferred by the DMA controller.
+ * @param None.
+ * @retval SD_Error: SD Card Error code.
+ */
+SD_Error SD_WaitWriteOperation(void)
+{
+ SD_Error errorstatus = SD_OK;
+ uint32_t timeout;
+
+ timeout = SD_DATATIMEOUT;
+
+ while ((DMAEndOfTransfer == 0x00) && (TransferEnd == 0) && (TransferError == SD_OK) && (timeout > 0))
+ {
+ timeout--;
+ }
+
+ DMAEndOfTransfer = 0x00;
+
+ timeout = SD_DATATIMEOUT;
+
+ while(((SDIO->STA & SDIO_FLAG_TXACT)) && (timeout > 0))
+ {
+ timeout--;
+ }
+
+ if (StopCondition == 1)
+ {
+ errorstatus = SD_StopTransfer();
+ }
+
+ if ((timeout == 0) && (errorstatus == SD_OK))
+ {
+ errorstatus = SD_DATA_TIMEOUT;
+ }
+
+ /*!< Clear all the static flags */
+ SDIO_ClearFlag(SDIO_STATIC_FLAGS);
+
+ if (TransferError != SD_OK)
+ {
+ return(TransferError);
+ }
+ else
+ {
+ return(errorstatus);
+ }
+}
+
+/**
+ * @brief Gets the cuurent data transfer state.
+ * @param None
+ * @retval SDTransferState: Data Transfer state.
+ * This value can be:
+ * - SD_TRANSFER_OK: No data transfer is acting
+ * - SD_TRANSFER_BUSY: Data transfer is acting
+ */
+SDTransferState SD_GetTransferState(void)
+{
+ if (SDIO->STA & (SDIO_FLAG_TXACT | SDIO_FLAG_RXACT))
+ {
+ return(SD_TRANSFER_BUSY);
+ }
+ else
+ {
+ return(SD_TRANSFER_OK);
+ }
+}
+
+/**
+ * @brief Aborts an ongoing data transfer.
+ * @param None
+ * @retval SD_Error: SD Card Error code.
+ */
+SD_Error SD_StopTransfer(void)
+{
+ SD_Error errorstatus = SD_OK;
+
+ /*!< Send CMD12 STOP_TRANSMISSION */
+ SDIO_CmdInitStructure.SDIO_Argument = 0x0;
+ SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_STOP_TRANSMISSION;
+ SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
+ SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
+ SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
+ SDIO_SendCommand(&SDIO_CmdInitStructure);
+
+ errorstatus = CmdResp1Error(SD_CMD_STOP_TRANSMISSION);
+
+ return(errorstatus);
+}
+
+/**
+ * @brief Allows to erase memory area specified for the given card.
+ * @param startaddr: the start address.
+ * @param endaddr: the end address.
+ * @retval SD_Error: SD Card Error code.
+ */
+SD_Error SD_Erase(uint32_t startaddr, uint32_t endaddr)
+{
+ SD_Error errorstatus = SD_OK;
+ uint32_t delay = 0;
+ __IO uint32_t maxdelay = 0;
+ uint8_t cardstate = 0;
+
+ /*!< Check if the card coomnd class supports erase command */
+ if (((CSD_Tab[1] >> 20) & SD_CCCC_ERASE) == 0)
+ {
+ errorstatus = SD_REQUEST_NOT_APPLICABLE;
+ return(errorstatus);
+ }
+
+ maxdelay = 120000 / ((SDIO->CLKCR & 0xFF) + 2);
+
+ if (SDIO_GetResponse(SDIO_RESP1) & SD_CARD_LOCKED)
+ {
+ errorstatus = SD_LOCK_UNLOCK_FAILED;
+ return(errorstatus);
+ }
+
+ if (CardType == SDIO_HIGH_CAPACITY_SD_CARD)
+ {
+ startaddr /= 512;
+ endaddr /= 512;
+ }
+
+ /*!< According to sd-card spec 1.0 ERASE_GROUP_START (CMD32) and erase_group_end(CMD33) */
+ if ((SDIO_STD_CAPACITY_SD_CARD_V1_1 == CardType) || (SDIO_STD_CAPACITY_SD_CARD_V2_0 == CardType) || (SDIO_HIGH_CAPACITY_SD_CARD == CardType))
+ {
+ /*!< Send CMD32 SD_ERASE_GRP_START with argument as addr */
+ SDIO_CmdInitStructure.SDIO_Argument = startaddr;
+ SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_SD_ERASE_GRP_START;
+ SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
+ SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
+ SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
+ SDIO_SendCommand(&SDIO_CmdInitStructure);
+
+ errorstatus = CmdResp1Error(SD_CMD_SD_ERASE_GRP_START);
+ if (errorstatus != SD_OK)
+ {
+ return(errorstatus);
+ }
+
+ /*!< Send CMD33 SD_ERASE_GRP_END with argument as addr */
+ SDIO_CmdInitStructure.SDIO_Argument = endaddr;
+ SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_SD_ERASE_GRP_END;
+ SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
+ SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
+ SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
+ SDIO_SendCommand(&SDIO_CmdInitStructure);
+
+ errorstatus = CmdResp1Error(SD_CMD_SD_ERASE_GRP_END);
+ if (errorstatus != SD_OK)
+ {
+ return(errorstatus);
+ }
+ }
+
+ /*!< Send CMD38 ERASE */
+ SDIO_CmdInitStructure.SDIO_Argument = 0;
+ SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_ERASE;
+ SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
+ SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
+ SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
+ SDIO_SendCommand(&SDIO_CmdInitStructure);
+
+ errorstatus = CmdResp1Error(SD_CMD_ERASE);
+
+ if (errorstatus != SD_OK)
+ {
+ return(errorstatus);
+ }
+
+ for (delay = 0; delay < maxdelay; delay++)
+ {}
+
+ /*!< Wait till the card is in programming state */
+ errorstatus = IsCardProgramming(&cardstate);
+ delay = SD_DATATIMEOUT;
+ while ((delay > 0) && (errorstatus == SD_OK) && ((SD_CARD_PROGRAMMING == cardstate) || (SD_CARD_RECEIVING == cardstate)))
+ {
+ errorstatus = IsCardProgramming(&cardstate);
+ delay--;
+ }
+
+ return(errorstatus);
+}
+
+/**
+ * @brief Returns the current card's status.
+ * @param pcardstatus: pointer to the buffer that will contain the SD card
+ * status (Card Status register).
+ * @retval SD_Error: SD Card Error code.
+ */
+SD_Error SD_SendStatus(uint32_t *pcardstatus)
+{
+ SD_Error errorstatus = SD_OK;
+
+ if (pcardstatus == NULL)
+ {
+ errorstatus = SD_INVALID_PARAMETER;
+ return(errorstatus);
+ }
+
+ SDIO_CmdInitStructure.SDIO_Argument = (uint32_t) RCA << 16;
+ SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_SEND_STATUS;
+ SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
+ SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
+ SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
+ SDIO_SendCommand(&SDIO_CmdInitStructure);
+
+ errorstatus = CmdResp1Error(SD_CMD_SEND_STATUS);
+
+ if (errorstatus != SD_OK)
+ {
+ return(errorstatus);
+ }
+
+ *pcardstatus = SDIO_GetResponse(SDIO_RESP1);
+
+ return(errorstatus);
+}
+
+/**
+ * @brief Returns the current SD card's status.
+ * @param psdstatus: pointer to the buffer that will contain the SD card status
+ * (SD Status register).
+ * @retval SD_Error: SD Card Error code.
+ */
+SD_Error SD_SendSDStatus(uint32_t *psdstatus)
+{
+ SD_Error errorstatus = SD_OK;
+ uint32_t count = 0;
+
+ if (SDIO_GetResponse(SDIO_RESP1) & SD_CARD_LOCKED)
+ {
+ errorstatus = SD_LOCK_UNLOCK_FAILED;
+ return(errorstatus);
+ }
+
+ /*!< Set block size for card if it is not equal to current block size for card. */
+ SDIO_CmdInitStructure.SDIO_Argument = 64;
+ SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_SET_BLOCKLEN;
+ SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
+ SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
+ SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
+ SDIO_SendCommand(&SDIO_CmdInitStructure);
+
+ errorstatus = CmdResp1Error(SD_CMD_SET_BLOCKLEN);
+
+ if (errorstatus != SD_OK)
+ {
+ return(errorstatus);
+ }
+
+ /*!< CMD55 */
+ SDIO_CmdInitStructure.SDIO_Argument = (uint32_t) RCA << 16;
+ SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_APP_CMD;
+ SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
+ SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
+ SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
+ SDIO_SendCommand(&SDIO_CmdInitStructure);
+ errorstatus = CmdResp1Error(SD_CMD_APP_CMD);
+
+ if (errorstatus != SD_OK)
+ {
+ return(errorstatus);
+ }
+
+ SDIO_DataInitStructure.SDIO_DataTimeOut = SD_DATATIMEOUT;
+ SDIO_DataInitStructure.SDIO_DataLength = 64;
+ SDIO_DataInitStructure.SDIO_DataBlockSize = SDIO_DataBlockSize_64b;
+ SDIO_DataInitStructure.SDIO_TransferDir = SDIO_TransferDir_ToSDIO;
+ SDIO_DataInitStructure.SDIO_TransferMode = SDIO_TransferMode_Block;
+ SDIO_DataInitStructure.SDIO_DPSM = SDIO_DPSM_Enable;
+ SDIO_DataConfig(&SDIO_DataInitStructure);
+
+ /*!< Send ACMD13 SD_APP_STAUS with argument as card's RCA.*/
+ SDIO_CmdInitStructure.SDIO_Argument = 0;
+ SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_SD_APP_STAUS;
+ SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
+ SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
+ SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
+ SDIO_SendCommand(&SDIO_CmdInitStructure);
+ errorstatus = CmdResp1Error(SD_CMD_SD_APP_STAUS);
+
+ if (errorstatus != SD_OK)
+ {
+ return(errorstatus);
+ }
+
+ while (!(SDIO->STA &(SDIO_FLAG_RXOVERR | SDIO_FLAG_DCRCFAIL | SDIO_FLAG_DTIMEOUT | SDIO_FLAG_DBCKEND | SDIO_FLAG_STBITERR)))
+ {
+ if (SDIO_GetFlagStatus(SDIO_FLAG_RXFIFOHF) != RESET)
+ {
+ for (count = 0; count < 8; count++)
+ {
+ *(psdstatus + count) = SDIO_ReadData();
+ }
+ psdstatus += 8;
+ }
+ }
+
+ if (SDIO_GetFlagStatus(SDIO_FLAG_DTIMEOUT) != RESET)
+ {
+ SDIO_ClearFlag(SDIO_FLAG_DTIMEOUT);
+ errorstatus = SD_DATA_TIMEOUT;
+ return(errorstatus);
+ }
+ else if (SDIO_GetFlagStatus(SDIO_FLAG_DCRCFAIL) != RESET)
+ {
+ SDIO_ClearFlag(SDIO_FLAG_DCRCFAIL);
+ errorstatus = SD_DATA_CRC_FAIL;
+ return(errorstatus);
+ }
+ else if (SDIO_GetFlagStatus(SDIO_FLAG_RXOVERR) != RESET)
+ {
+ SDIO_ClearFlag(SDIO_FLAG_RXOVERR);
+ errorstatus = SD_RX_OVERRUN;
+ return(errorstatus);
+ }
+ else if (SDIO_GetFlagStatus(SDIO_FLAG_STBITERR) != RESET)
+ {
+ SDIO_ClearFlag(SDIO_FLAG_STBITERR);
+ errorstatus = SD_START_BIT_ERR;
+ return(errorstatus);
+ }
+
+ count = SD_DATATIMEOUT;
+ while ((SDIO_GetFlagStatus(SDIO_FLAG_RXDAVL) != RESET) && (count > 0))
+ {
+ *psdstatus = SDIO_ReadData();
+ psdstatus++;
+ count--;
+ }
+ /*!< Clear all the static status flags*/
+ SDIO_ClearFlag(SDIO_STATIC_FLAGS);
+
+ return(errorstatus);
+}
+
+/**
+ * @brief Allows to process all the interrupts that are high.
+ * @param None
+ * @retval SD_Error: SD Card Error code.
+ */
+SD_Error SD_ProcessIRQSrc(void)
+{
+ if (SDIO_GetITStatus(SDIO_IT_DATAEND) != RESET)
+ {
+ TransferError = SD_OK;
+ SDIO_ClearITPendingBit(SDIO_IT_DATAEND);
+ TransferEnd = 1;
+ }
+ else if (SDIO_GetITStatus(SDIO_IT_DCRCFAIL) != RESET)
+ {
+ SDIO_ClearITPendingBit(SDIO_IT_DCRCFAIL);
+ TransferError = SD_DATA_CRC_FAIL;
+ }
+ else if (SDIO_GetITStatus(SDIO_IT_DTIMEOUT) != RESET)
+ {
+ SDIO_ClearITPendingBit(SDIO_IT_DTIMEOUT);
+ TransferError = SD_DATA_TIMEOUT;
+ }
+ else if (SDIO_GetITStatus(SDIO_IT_RXOVERR) != RESET)
+ {
+ SDIO_ClearITPendingBit(SDIO_IT_RXOVERR);
+ TransferError = SD_RX_OVERRUN;
+ }
+ else if (SDIO_GetITStatus(SDIO_IT_TXUNDERR) != RESET)
+ {
+ SDIO_ClearITPendingBit(SDIO_IT_TXUNDERR);
+ TransferError = SD_TX_UNDERRUN;
+ }
+ else if (SDIO_GetITStatus(SDIO_IT_STBITERR) != RESET)
+ {
+ SDIO_ClearITPendingBit(SDIO_IT_STBITERR);
+ TransferError = SD_START_BIT_ERR;
+ }
+
+ SDIO_ITConfig(SDIO_IT_DCRCFAIL | SDIO_IT_DTIMEOUT | SDIO_IT_DATAEND |
+ SDIO_IT_TXFIFOHE | SDIO_IT_RXFIFOHF | SDIO_IT_TXUNDERR |
+ SDIO_IT_RXOVERR | SDIO_IT_STBITERR, DISABLE);
+ return(TransferError);
+}
+
+/**
+ * @brief This function waits until the SDIO DMA data transfer is finished.
+ * @param None.
+ * @retval None.
+ */
+void SD_ProcessDMAIRQ(void)
+{
+ if(DMA2->ISR & SD_SDIO_DMA_FLAG_TC)
+ {
+ DMAEndOfTransfer = 0x01;
+ DMA_ClearFlag(SD_SDIO_DMA_FLAG_TC | SD_SDIO_DMA_FLAG_TE | SD_SDIO_DMA_FLAG_HT | SD_SDIO_DMA_FLAG_GL);
+ }
+}
+
+/**
+ * @brief Checks for error conditions for CMD0.
+ * @param None
+ * @retval SD_Error: SD Card Error code.
+ */
+static SD_Error CmdError(void)
+{
+ SD_Error errorstatus = SD_OK;
+ uint32_t timeout;
+
+ timeout = SDIO_CMD0TIMEOUT; /*!< 10000 */
+
+ while ((timeout > 0) && (SDIO_GetFlagStatus(SDIO_FLAG_CMDSENT) == RESET))
+ {
+ timeout--;
+ }
+
+ if (timeout == 0)
+ {
+ errorstatus = SD_CMD_RSP_TIMEOUT;
+ return(errorstatus);
+ }
+
+ /*!< Clear all the static flags */
+ SDIO_ClearFlag(SDIO_STATIC_FLAGS);
+
+ return(errorstatus);
+}
+
+/**
+ * @brief Checks for error conditions for R7 response.
+ * @param None
+ * @retval SD_Error: SD Card Error code.
+ */
+static SD_Error CmdResp7Error(void)
+{
+ SD_Error errorstatus = SD_OK;
+ uint32_t status;
+ uint32_t timeout = SDIO_CMD0TIMEOUT;
+
+ status = SDIO->STA;
+
+ while (!(status & (SDIO_FLAG_CCRCFAIL | SDIO_FLAG_CMDREND | SDIO_FLAG_CTIMEOUT)) && (timeout > 0))
+ {
+ timeout--;
+ status = SDIO->STA;
+ }
+
+ if ((timeout == 0) || (status & SDIO_FLAG_CTIMEOUT))
+ {
+ /*!< Card is not V2.0 complient or card does not support the set voltage range */
+ errorstatus = SD_CMD_RSP_TIMEOUT;
+ SDIO_ClearFlag(SDIO_FLAG_CTIMEOUT);
+ return(errorstatus);
+ }
+
+ if (status & SDIO_FLAG_CMDREND)
+ {
+ /*!< Card is SD V2.0 compliant */
+ errorstatus = SD_OK;
+ SDIO_ClearFlag(SDIO_FLAG_CMDREND);
+ return(errorstatus);
+ }
+ return(errorstatus);
+}
+
+/**
+ * @brief Checks for error conditions for R1 response.
+ * @param cmd: The sent command index.
+ * @retval SD_Error: SD Card Error code.
+ */
+static SD_Error CmdResp1Error(uint8_t cmd)
+{
+ SD_Error errorstatus = SD_OK;
+ uint32_t status;
+ uint32_t response_r1;
+
+ status = SDIO->STA;
+
+ while (!(status & (SDIO_FLAG_CCRCFAIL | SDIO_FLAG_CMDREND | SDIO_FLAG_CTIMEOUT)))
+ {
+ status = SDIO->STA;
+ }
+
+ if (status & SDIO_FLAG_CTIMEOUT)
+ {
+ errorstatus = SD_CMD_RSP_TIMEOUT;
+ SDIO_ClearFlag(SDIO_FLAG_CTIMEOUT);
+ return(errorstatus);
+ }
+ else if (status & SDIO_FLAG_CCRCFAIL)
+ {
+ errorstatus = SD_CMD_CRC_FAIL;
+ SDIO_ClearFlag(SDIO_FLAG_CCRCFAIL);
+ return(errorstatus);
+ }
+
+ /*!< Check response received is of desired command */
+ if (SDIO_GetCommandResponse() != cmd)
+ {
+ errorstatus = SD_ILLEGAL_CMD;
+ return(errorstatus);
+ }
+
+ /*!< Clear all the static flags */
+ SDIO_ClearFlag(SDIO_STATIC_FLAGS);
+
+ /*!< We have received response, retrieve it for analysis */
+ response_r1 = SDIO_GetResponse(SDIO_RESP1);
+
+ if ((response_r1 & SD_OCR_ERRORBITS) == SD_ALLZERO)
+ {
+ return(errorstatus);
+ }
+
+ if (response_r1 & SD_OCR_ADDR_OUT_OF_RANGE)
+ {
+ return(SD_ADDR_OUT_OF_RANGE);
+ }
+
+ if (response_r1 & SD_OCR_ADDR_MISALIGNED)
+ {
+ return(SD_ADDR_MISALIGNED);
+ }
+
+ if (response_r1 & SD_OCR_BLOCK_LEN_ERR)
+ {
+ return(SD_BLOCK_LEN_ERR);
+ }
+
+ if (response_r1 & SD_OCR_ERASE_SEQ_ERR)
+ {
+ return(SD_ERASE_SEQ_ERR);
+ }
+
+ if (response_r1 & SD_OCR_BAD_ERASE_PARAM)
+ {
+ return(SD_BAD_ERASE_PARAM);
+ }
+
+ if (response_r1 & SD_OCR_WRITE_PROT_VIOLATION)
+ {
+ return(SD_WRITE_PROT_VIOLATION);
+ }
+
+ if (response_r1 & SD_OCR_LOCK_UNLOCK_FAILED)
+ {
+ return(SD_LOCK_UNLOCK_FAILED);
+ }
+
+ if (response_r1 & SD_OCR_COM_CRC_FAILED)
+ {
+ return(SD_COM_CRC_FAILED);
+ }
+
+ if (response_r1 & SD_OCR_ILLEGAL_CMD)
+ {
+ return(SD_ILLEGAL_CMD);
+ }
+
+ if (response_r1 & SD_OCR_CARD_ECC_FAILED)
+ {
+ return(SD_CARD_ECC_FAILED);
+ }
+
+ if (response_r1 & SD_OCR_CC_ERROR)
+ {
+ return(SD_CC_ERROR);
+ }
+
+ if (response_r1 & SD_OCR_GENERAL_UNKNOWN_ERROR)
+ {
+ return(SD_GENERAL_UNKNOWN_ERROR);
+ }
+
+ if (response_r1 & SD_OCR_STREAM_READ_UNDERRUN)
+ {
+ return(SD_STREAM_READ_UNDERRUN);
+ }
+
+ if (response_r1 & SD_OCR_STREAM_WRITE_OVERRUN)
+ {
+ return(SD_STREAM_WRITE_OVERRUN);
+ }
+
+ if (response_r1 & SD_OCR_CID_CSD_OVERWRIETE)
+ {
+ return(SD_CID_CSD_OVERWRITE);
+ }
+
+ if (response_r1 & SD_OCR_WP_ERASE_SKIP)
+ {
+ return(SD_WP_ERASE_SKIP);
+ }
+
+ if (response_r1 & SD_OCR_CARD_ECC_DISABLED)
+ {
+ return(SD_CARD_ECC_DISABLED);
+ }
+
+ if (response_r1 & SD_OCR_ERASE_RESET)
+ {
+ return(SD_ERASE_RESET);
+ }
+
+ if (response_r1 & SD_OCR_AKE_SEQ_ERROR)
+ {
+ return(SD_AKE_SEQ_ERROR);
+ }
+ return(errorstatus);
+}
+
+/**
+ * @brief Checks for error conditions for R3 (OCR) response.
+ * @param None
+ * @retval SD_Error: SD Card Error code.
+ */
+static SD_Error CmdResp3Error(void)
+{
+ SD_Error errorstatus = SD_OK;
+ uint32_t status;
+
+ status = SDIO->STA;
+
+ while (!(status & (SDIO_FLAG_CCRCFAIL | SDIO_FLAG_CMDREND | SDIO_FLAG_CTIMEOUT)))
+ {
+ status = SDIO->STA;
+ }
+
+ if (status & SDIO_FLAG_CTIMEOUT)
+ {
+ errorstatus = SD_CMD_RSP_TIMEOUT;
+ SDIO_ClearFlag(SDIO_FLAG_CTIMEOUT);
+ return(errorstatus);
+ }
+ /*!< Clear all the static flags */
+ SDIO_ClearFlag(SDIO_STATIC_FLAGS);
+ return(errorstatus);
+}
+
+/**
+ * @brief Checks for error conditions for R2 (CID or CSD) response.
+ * @param None
+ * @retval SD_Error: SD Card Error code.
+ */
+static SD_Error CmdResp2Error(void)
+{
+ SD_Error errorstatus = SD_OK;
+ uint32_t status;
+
+ status = SDIO->STA;
+
+ while (!(status & (SDIO_FLAG_CCRCFAIL | SDIO_FLAG_CTIMEOUT | SDIO_FLAG_CMDREND)))
+ {
+ status = SDIO->STA;
+ }
+
+ if (status & SDIO_FLAG_CTIMEOUT)
+ {
+ errorstatus = SD_CMD_RSP_TIMEOUT;
+ SDIO_ClearFlag(SDIO_FLAG_CTIMEOUT);
+ return(errorstatus);
+ }
+ else if (status & SDIO_FLAG_CCRCFAIL)
+ {
+ errorstatus = SD_CMD_CRC_FAIL;
+ SDIO_ClearFlag(SDIO_FLAG_CCRCFAIL);
+ return(errorstatus);
+ }
+
+ /*!< Clear all the static flags */
+ SDIO_ClearFlag(SDIO_STATIC_FLAGS);
+
+ return(errorstatus);
+}
+
+/**
+ * @brief Checks for error conditions for R6 (RCA) response.
+ * @param cmd: The sent command index.
+ * @param prca: pointer to the variable that will contain the SD card relative
+ * address RCA.
+ * @retval SD_Error: SD Card Error code.
+ */
+static SD_Error CmdResp6Error(uint8_t cmd, uint16_t *prca)
+{
+ SD_Error errorstatus = SD_OK;
+ uint32_t status;
+ uint32_t response_r1;
+
+ status = SDIO->STA;
+
+ while (!(status & (SDIO_FLAG_CCRCFAIL | SDIO_FLAG_CTIMEOUT | SDIO_FLAG_CMDREND)))
+ {
+ status = SDIO->STA;
+ }
+
+ if (status & SDIO_FLAG_CTIMEOUT)
+ {
+ errorstatus = SD_CMD_RSP_TIMEOUT;
+ SDIO_ClearFlag(SDIO_FLAG_CTIMEOUT);
+ return(errorstatus);
+ }
+ else if (status & SDIO_FLAG_CCRCFAIL)
+ {
+ errorstatus = SD_CMD_CRC_FAIL;
+ SDIO_ClearFlag(SDIO_FLAG_CCRCFAIL);
+ return(errorstatus);
+ }
+
+ /*!< Check response received is of desired command */
+ if (SDIO_GetCommandResponse() != cmd)
+ {
+ errorstatus = SD_ILLEGAL_CMD;
+ return(errorstatus);
+ }
+
+ /*!< Clear all the static flags */
+ SDIO_ClearFlag(SDIO_STATIC_FLAGS);
+
+ /*!< We have received response, retrieve it. */
+ response_r1 = SDIO_GetResponse(SDIO_RESP1);
+
+ if (SD_ALLZERO == (response_r1 & (SD_R6_GENERAL_UNKNOWN_ERROR | SD_R6_ILLEGAL_CMD | SD_R6_COM_CRC_FAILED)))
+ {
+ *prca = (uint16_t) (response_r1 >> 16);
+ return(errorstatus);
+ }
+
+ if (response_r1 & SD_R6_GENERAL_UNKNOWN_ERROR)
+ {
+ return(SD_GENERAL_UNKNOWN_ERROR);
+ }
+
+ if (response_r1 & SD_R6_ILLEGAL_CMD)
+ {
+ return(SD_ILLEGAL_CMD);
+ }
+
+ if (response_r1 & SD_R6_COM_CRC_FAILED)
+ {
+ return(SD_COM_CRC_FAILED);
+ }
+
+ return(errorstatus);
+}
+
+/**
+ * @brief Enables or disables the SDIO wide bus mode.
+ * @param NewState: new state of the SDIO wide bus mode.
+ * This parameter can be: ENABLE or DISABLE.
+ * @retval SD_Error: SD Card Error code.
+ */
+static SD_Error SDEnWideBus(FunctionalState NewState)
+{
+ SD_Error errorstatus = SD_OK;
+
+ uint32_t scr[2] = {0, 0};
+
+ if (SDIO_GetResponse(SDIO_RESP1) & SD_CARD_LOCKED)
+ {
+ errorstatus = SD_LOCK_UNLOCK_FAILED;
+ return(errorstatus);
+ }
+
+ /*!< Get SCR Register */
+ errorstatus = FindSCR((uint16_t)RCA, scr);
+
+ if (errorstatus != SD_OK)
+ {
+ return(errorstatus);
+ }
+
+ /*!< If wide bus operation to be enabled */
+ if (NewState == ENABLE)
+ {
+ /*!< If requested card supports wide bus operation */
+ if ((scr[1] & SD_WIDE_BUS_SUPPORT) != SD_ALLZERO)
+ {
+ /*!< Send CMD55 APP_CMD with argument as card's RCA.*/
+ SDIO_CmdInitStructure.SDIO_Argument = (uint32_t) RCA << 16;
+ SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_APP_CMD;
+ SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
+ SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
+ SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
+ SDIO_SendCommand(&SDIO_CmdInitStructure);
+
+ errorstatus = CmdResp1Error(SD_CMD_APP_CMD);
+
+ if (errorstatus != SD_OK)
+ {
+ return(errorstatus);
+ }
+
+ /*!< Send ACMD6 APP_CMD with argument as 2 for wide bus mode */
+ SDIO_CmdInitStructure.SDIO_Argument = 0x2;
+ SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_APP_SD_SET_BUSWIDTH;
+ SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
+ SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
+ SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
+ SDIO_SendCommand(&SDIO_CmdInitStructure);
+
+ errorstatus = CmdResp1Error(SD_CMD_APP_SD_SET_BUSWIDTH);
+
+ if (errorstatus != SD_OK)
+ {
+ return(errorstatus);
+ }
+ return(errorstatus);
+ }
+ else
+ {
+ errorstatus = SD_REQUEST_NOT_APPLICABLE;
+ return(errorstatus);
+ }
+ } /*!< If wide bus operation to be disabled */
+ else
+ {
+ /*!< If requested card supports 1 bit mode operation */
+ if ((scr[1] & SD_SINGLE_BUS_SUPPORT) != SD_ALLZERO)
+ {
+ /*!< Send CMD55 APP_CMD with argument as card's RCA.*/
+ SDIO_CmdInitStructure.SDIO_Argument = (uint32_t) RCA << 16;
+ SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_APP_CMD;
+ SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
+ SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
+ SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
+ SDIO_SendCommand(&SDIO_CmdInitStructure);
+
+
+ errorstatus = CmdResp1Error(SD_CMD_APP_CMD);
+
+ if (errorstatus != SD_OK)
+ {
+ return(errorstatus);
+ }
+
+ /*!< Send ACMD6 APP_CMD with argument as 2 for wide bus mode */
+ SDIO_CmdInitStructure.SDIO_Argument = 0x00;
+ SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_APP_SD_SET_BUSWIDTH;
+ SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
+ SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
+ SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
+ SDIO_SendCommand(&SDIO_CmdInitStructure);
+
+ errorstatus = CmdResp1Error(SD_CMD_APP_SD_SET_BUSWIDTH);
+
+ if (errorstatus != SD_OK)
+ {
+ return(errorstatus);
+ }
+
+ return(errorstatus);
+ }
+ else
+ {
+ errorstatus = SD_REQUEST_NOT_APPLICABLE;
+ return(errorstatus);
+ }
+ }
+}
+
+/**
+ * @brief Checks if the SD card is in programming state.
+ * @param pstatus: pointer to the variable that will contain the SD card state.
+ * @retval SD_Error: SD Card Error code.
+ */
+static SD_Error IsCardProgramming(uint8_t *pstatus)
+{
+ SD_Error errorstatus = SD_OK;
+ __IO uint32_t respR1 = 0, status = 0;
+
+ SDIO_CmdInitStructure.SDIO_Argument = (uint32_t) RCA << 16;
+ SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_SEND_STATUS;
+ SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
+ SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
+ SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
+ SDIO_SendCommand(&SDIO_CmdInitStructure);
+
+ status = SDIO->STA;
+ while (!(status & (SDIO_FLAG_CCRCFAIL | SDIO_FLAG_CMDREND | SDIO_FLAG_CTIMEOUT)))
+ {
+ status = SDIO->STA;
+ }
+
+ if (status & SDIO_FLAG_CTIMEOUT)
+ {
+ errorstatus = SD_CMD_RSP_TIMEOUT;
+ SDIO_ClearFlag(SDIO_FLAG_CTIMEOUT);
+ return(errorstatus);
+ }
+ else if (status & SDIO_FLAG_CCRCFAIL)
+ {
+ errorstatus = SD_CMD_CRC_FAIL;
+ SDIO_ClearFlag(SDIO_FLAG_CCRCFAIL);
+ return(errorstatus);
+ }
+
+ status = (uint32_t)SDIO_GetCommandResponse();
+
+ /*!< Check response received is of desired command */
+ if (status != SD_CMD_SEND_STATUS)
+ {
+ errorstatus = SD_ILLEGAL_CMD;
+ return(errorstatus);
+ }
+
+ /*!< Clear all the static flags */
+ SDIO_ClearFlag(SDIO_STATIC_FLAGS);
+
+
+ /*!< We have received response, retrieve it for analysis */
+ respR1 = SDIO_GetResponse(SDIO_RESP1);
+
+ /*!< Find out card status */
+ *pstatus = (uint8_t) ((respR1 >> 9) & 0x0000000F);
+
+ if ((respR1 & SD_OCR_ERRORBITS) == SD_ALLZERO)
+ {
+ return(errorstatus);
+ }
+
+ if (respR1 & SD_OCR_ADDR_OUT_OF_RANGE)
+ {
+ return(SD_ADDR_OUT_OF_RANGE);
+ }
+
+ if (respR1 & SD_OCR_ADDR_MISALIGNED)
+ {
+ return(SD_ADDR_MISALIGNED);
+ }
+
+ if (respR1 & SD_OCR_BLOCK_LEN_ERR)
+ {
+ return(SD_BLOCK_LEN_ERR);
+ }
+
+ if (respR1 & SD_OCR_ERASE_SEQ_ERR)
+ {
+ return(SD_ERASE_SEQ_ERR);
+ }
+
+ if (respR1 & SD_OCR_BAD_ERASE_PARAM)
+ {
+ return(SD_BAD_ERASE_PARAM);
+ }
+
+ if (respR1 & SD_OCR_WRITE_PROT_VIOLATION)
+ {
+ return(SD_WRITE_PROT_VIOLATION);
+ }
+
+ if (respR1 & SD_OCR_LOCK_UNLOCK_FAILED)
+ {
+ return(SD_LOCK_UNLOCK_FAILED);
+ }
+
+ if (respR1 & SD_OCR_COM_CRC_FAILED)
+ {
+ return(SD_COM_CRC_FAILED);
+ }
+
+ if (respR1 & SD_OCR_ILLEGAL_CMD)
+ {
+ return(SD_ILLEGAL_CMD);
+ }
+
+ if (respR1 & SD_OCR_CARD_ECC_FAILED)
+ {
+ return(SD_CARD_ECC_FAILED);
+ }
+
+ if (respR1 & SD_OCR_CC_ERROR)
+ {
+ return(SD_CC_ERROR);
+ }
+
+ if (respR1 & SD_OCR_GENERAL_UNKNOWN_ERROR)
+ {
+ return(SD_GENERAL_UNKNOWN_ERROR);
+ }
+
+ if (respR1 & SD_OCR_STREAM_READ_UNDERRUN)
+ {
+ return(SD_STREAM_READ_UNDERRUN);
+ }
+
+ if (respR1 & SD_OCR_STREAM_WRITE_OVERRUN)
+ {
+ return(SD_STREAM_WRITE_OVERRUN);
+ }
+
+ if (respR1 & SD_OCR_CID_CSD_OVERWRIETE)
+ {
+ return(SD_CID_CSD_OVERWRITE);
+ }
+
+ if (respR1 & SD_OCR_WP_ERASE_SKIP)
+ {
+ return(SD_WP_ERASE_SKIP);
+ }
+
+ if (respR1 & SD_OCR_CARD_ECC_DISABLED)
+ {
+ return(SD_CARD_ECC_DISABLED);
+ }
+
+ if (respR1 & SD_OCR_ERASE_RESET)
+ {
+ return(SD_ERASE_RESET);
+ }
+
+ if (respR1 & SD_OCR_AKE_SEQ_ERROR)
+ {
+ return(SD_AKE_SEQ_ERROR);
+ }
+
+ return(errorstatus);
+}
+
+/**
+ * @brief Find the SD card SCR register value.
+ * @param rca: selected card address.
+ * @param pscr: pointer to the buffer that will contain the SCR value.
+ * @retval SD_Error: SD Card Error code.
+ */
+static SD_Error FindSCR(uint16_t rca, uint32_t *pscr)
+{
+ uint32_t index = 0;
+ SD_Error errorstatus = SD_OK;
+ uint32_t tempscr[2] = {0, 0};
+
+ /*!< Set Block Size To 8 Bytes */
+ /*!< Send CMD55 APP_CMD with argument as card's RCA */
+ SDIO_CmdInitStructure.SDIO_Argument = (uint32_t)8;
+ SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_SET_BLOCKLEN;
+ SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
+ SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
+ SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
+ SDIO_SendCommand(&SDIO_CmdInitStructure);
+
+ errorstatus = CmdResp1Error(SD_CMD_SET_BLOCKLEN);
+
+ if (errorstatus != SD_OK)
+ {
+ return(errorstatus);
+ }
+
+ /*!< Send CMD55 APP_CMD with argument as card's RCA */
+ SDIO_CmdInitStructure.SDIO_Argument = (uint32_t) RCA << 16;
+ SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_APP_CMD;
+ SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
+ SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
+ SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
+ SDIO_SendCommand(&SDIO_CmdInitStructure);
+
+ errorstatus = CmdResp1Error(SD_CMD_APP_CMD);
+
+ if (errorstatus != SD_OK)
+ {
+ return(errorstatus);
+ }
+ SDIO_DataInitStructure.SDIO_DataTimeOut = SD_DATATIMEOUT;
+ SDIO_DataInitStructure.SDIO_DataLength = 8;
+ SDIO_DataInitStructure.SDIO_DataBlockSize = SDIO_DataBlockSize_8b;
+ SDIO_DataInitStructure.SDIO_TransferDir = SDIO_TransferDir_ToSDIO;
+ SDIO_DataInitStructure.SDIO_TransferMode = SDIO_TransferMode_Block;
+ SDIO_DataInitStructure.SDIO_DPSM = SDIO_DPSM_Enable;
+ SDIO_DataConfig(&SDIO_DataInitStructure);
+
+
+ /*!< Send ACMD51 SD_APP_SEND_SCR with argument as 0 */
+ SDIO_CmdInitStructure.SDIO_Argument = 0x0;
+ SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_SD_APP_SEND_SCR;
+ SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
+ SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
+ SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
+ SDIO_SendCommand(&SDIO_CmdInitStructure);
+
+ errorstatus = CmdResp1Error(SD_CMD_SD_APP_SEND_SCR);
+
+ if (errorstatus != SD_OK)
+ {
+ return(errorstatus);
+ }
+
+ while (!(SDIO->STA & (SDIO_FLAG_RXOVERR | SDIO_FLAG_DCRCFAIL | SDIO_FLAG_DTIMEOUT | SDIO_FLAG_DBCKEND | SDIO_FLAG_STBITERR)))
+ {
+ if (SDIO_GetFlagStatus(SDIO_FLAG_RXDAVL) != RESET)
+ {
+ *(tempscr + index) = SDIO_ReadData();
+ index++;
+ }
+ }
+
+ if (SDIO_GetFlagStatus(SDIO_FLAG_DTIMEOUT) != RESET)
+ {
+ SDIO_ClearFlag(SDIO_FLAG_DTIMEOUT);
+ errorstatus = SD_DATA_TIMEOUT;
+ return(errorstatus);
+ }
+ else if (SDIO_GetFlagStatus(SDIO_FLAG_DCRCFAIL) != RESET)
+ {
+ SDIO_ClearFlag(SDIO_FLAG_DCRCFAIL);
+ errorstatus = SD_DATA_CRC_FAIL;
+ return(errorstatus);
+ }
+ else if (SDIO_GetFlagStatus(SDIO_FLAG_RXOVERR) != RESET)
+ {
+ SDIO_ClearFlag(SDIO_FLAG_RXOVERR);
+ errorstatus = SD_RX_OVERRUN;
+ return(errorstatus);
+ }
+ else if (SDIO_GetFlagStatus(SDIO_FLAG_STBITERR) != RESET)
+ {
+ SDIO_ClearFlag(SDIO_FLAG_STBITERR);
+ errorstatus = SD_START_BIT_ERR;
+ return(errorstatus);
+ }
+
+ /*!< Clear all the static flags */
+ SDIO_ClearFlag(SDIO_STATIC_FLAGS);
+
+ *(pscr + 1) = ((tempscr[0] & SD_0TO7BITS) << 24) | ((tempscr[0] & SD_8TO15BITS) << 8) | ((tempscr[0] & SD_16TO23BITS) >> 8) | ((tempscr[0] & SD_24TO31BITS) >> 24);
+
+ *(pscr) = ((tempscr[1] & SD_0TO7BITS) << 24) | ((tempscr[1] & SD_8TO15BITS) << 8) | ((tempscr[1] & SD_16TO23BITS) >> 8) | ((tempscr[1] & SD_24TO31BITS) >> 24);
+
+ return(errorstatus);
+}
+
+/**
+ * @brief Converts the number of bytes in power of two and returns the power.
+ * @param NumberOfBytes: number of bytes.
+ * @retval None
+ */
+uint8_t convert_from_bytes_to_power_of_two(uint16_t NumberOfBytes)
+{
+ uint8_t count = 0;
+
+ while (NumberOfBytes != 1)
+ {
+ NumberOfBytes >>= 1;
+ count++;
+ }
+ return(count);
+}
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval_sdio_sd.h b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval_sdio_sd.h
new file mode 100644
index 0000000..942c72c
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval_sdio_sd.h
@@ -0,0 +1,406 @@
+/**
+ ******************************************************************************
+ * @file stm32l152d_eval_sdio_sd.h
+ * @author MCD Application Team
+ * @version V1.0.1
+ * @date 09-March-2012
+ * @brief This file contains all the functions prototypes for the SD Card
+ * stm32l152d_eval_sdio_sd driver firmware library.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.st.com/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __STM32L152D_EVAL_SDIO_SD_H
+#define __STM32L152D_EVAL_SDIO_SD_H
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+/* Includes ------------------------------------------------------------------*/
+#include "stm32l152d_eval.h"
+
+/** @addtogroup Utilities
+ * @{
+ */
+
+/** @addtogroup STM32_EVAL
+ * @{
+ */
+
+/** @addtogroup STM32L152D_EVAL
+ * @{
+ */
+
+/** @addtogroup STM32L152D_EVAL_SDIO_SD
+ * @{
+ */
+
+/** @defgroup STM32L152D_EVAL_SDIO_SD_Exported_Types
+ * @{
+ */
+typedef enum
+{
+/**
+ * @brief SDIO specific error defines
+ */
+ SD_CMD_CRC_FAIL = (1), /*!< Command response received (but CRC check failed) */
+ SD_DATA_CRC_FAIL = (2), /*!< Data bock sent/received (CRC check Failed) */
+ SD_CMD_RSP_TIMEOUT = (3), /*!< Command response timeout */
+ SD_DATA_TIMEOUT = (4), /*!< Data time out */
+ SD_TX_UNDERRUN = (5), /*!< Transmit FIFO under-run */
+ SD_RX_OVERRUN = (6), /*!< Receive FIFO over-run */
+ SD_START_BIT_ERR = (7), /*!< Start bit not detected on all data signals in widE bus mode */
+ SD_CMD_OUT_OF_RANGE = (8), /*!< CMD's argument was out of range.*/
+ SD_ADDR_MISALIGNED = (9), /*!< Misaligned address */
+ SD_BLOCK_LEN_ERR = (10), /*!< Transferred block length is not allowed for the card or the number of transferred bytes does not match the block length */
+ SD_ERASE_SEQ_ERR = (11), /*!< An error in the sequence of erase command occurs.*/
+ SD_BAD_ERASE_PARAM = (12), /*!< An Invalid selection for erase groups */
+ SD_WRITE_PROT_VIOLATION = (13), /*!< Attempt to program a write protect block */
+ SD_LOCK_UNLOCK_FAILED = (14), /*!< Sequence or password error has been detected in unlock command or if there was an attempt to access a locked card */
+ SD_COM_CRC_FAILED = (15), /*!< CRC check of the previous command failed */
+ SD_ILLEGAL_CMD = (16), /*!< Command is not legal for the card state */
+ SD_CARD_ECC_FAILED = (17), /*!< Card internal ECC was applied but failed to correct the data */
+ SD_CC_ERROR = (18), /*!< Internal card controller error */
+ SD_GENERAL_UNKNOWN_ERROR = (19), /*!< General or Unknown error */
+ SD_STREAM_READ_UNDERRUN = (20), /*!< The card could not sustain data transfer in stream read operation. */
+ SD_STREAM_WRITE_OVERRUN = (21), /*!< The card could not sustain data programming in stream mode */
+ SD_CID_CSD_OVERWRITE = (22), /*!< CID/CSD overwrite error */
+ SD_WP_ERASE_SKIP = (23), /*!< only partial address space was erased */
+ SD_CARD_ECC_DISABLED = (24), /*!< Command has been executed without using internal ECC */
+ SD_ERASE_RESET = (25), /*!< Erase sequence was cleared before executing because an out of erase sequence command was received */
+ SD_AKE_SEQ_ERROR = (26), /*!< Error in sequence of authentication. */
+ SD_INVALID_VOLTRANGE = (27),
+ SD_ADDR_OUT_OF_RANGE = (28),
+ SD_SWITCH_ERROR = (29),
+ SD_SDIO_DISABLED = (30),
+ SD_SDIO_FUNCTION_BUSY = (31),
+ SD_SDIO_FUNCTION_FAILED = (32),
+ SD_SDIO_UNKNOWN_FUNCTION = (33),
+
+/**
+ * @brief Standard error defines
+ */
+ SD_INTERNAL_ERROR,
+ SD_NOT_CONFIGURED,
+ SD_REQUEST_PENDING,
+ SD_REQUEST_NOT_APPLICABLE,
+ SD_INVALID_PARAMETER,
+ SD_UNSUPPORTED_FEATURE,
+ SD_UNSUPPORTED_HW,
+ SD_ERROR,
+ SD_OK = 0
+} SD_Error;
+
+/**
+ * @brief SDIO Transfer state
+ */
+typedef enum
+{
+ SD_TRANSFER_OK = 0,
+ SD_TRANSFER_BUSY = 1,
+ SD_TRANSFER_ERROR
+} SDTransferState;
+
+/**
+ * @brief SD Card States
+ */
+typedef enum
+{
+ SD_CARD_READY = ((uint32_t)0x00000001),
+ SD_CARD_IDENTIFICATION = ((uint32_t)0x00000002),
+ SD_CARD_STANDBY = ((uint32_t)0x00000003),
+ SD_CARD_TRANSFER = ((uint32_t)0x00000004),
+ SD_CARD_SENDING = ((uint32_t)0x00000005),
+ SD_CARD_RECEIVING = ((uint32_t)0x00000006),
+ SD_CARD_PROGRAMMING = ((uint32_t)0x00000007),
+ SD_CARD_DISCONNECTED = ((uint32_t)0x00000008),
+ SD_CARD_ERROR = ((uint32_t)0x000000FF)
+}SDCardState;
+
+
+/**
+ * @brief Card Specific Data: CSD Register
+ */
+typedef struct
+{
+ __IO uint8_t CSDStruct; /*!< CSD structure */
+ __IO uint8_t SysSpecVersion; /*!< System specification version */
+ __IO uint8_t Reserved1; /*!< Reserved */
+ __IO uint8_t TAAC; /*!< Data read access-time 1 */
+ __IO uint8_t NSAC; /*!< Data read access-time 2 in CLK cycles */
+ __IO uint8_t MaxBusClkFrec; /*!< Max. bus clock frequency */
+ __IO uint16_t CardComdClasses; /*!< Card command classes */
+ __IO uint8_t RdBlockLen; /*!< Max. read data block length */
+ __IO uint8_t PartBlockRead; /*!< Partial blocks for read allowed */
+ __IO uint8_t WrBlockMisalign; /*!< Write block misalignment */
+ __IO uint8_t RdBlockMisalign; /*!< Read block misalignment */
+ __IO uint8_t DSRImpl; /*!< DSR implemented */
+ __IO uint8_t Reserved2; /*!< Reserved */
+ __IO uint32_t DeviceSize; /*!< Device Size */
+ __IO uint8_t MaxRdCurrentVDDMin; /*!< Max. read current @ VDD min */
+ __IO uint8_t MaxRdCurrentVDDMax; /*!< Max. read current @ VDD max */
+ __IO uint8_t MaxWrCurrentVDDMin; /*!< Max. write current @ VDD min */
+ __IO uint8_t MaxWrCurrentVDDMax; /*!< Max. write current @ VDD max */
+ __IO uint8_t DeviceSizeMul; /*!< Device size multiplier */
+ __IO uint8_t EraseGrSize; /*!< Erase group size */
+ __IO uint8_t EraseGrMul; /*!< Erase group size multiplier */
+ __IO uint8_t WrProtectGrSize; /*!< Write protect group size */
+ __IO uint8_t WrProtectGrEnable; /*!< Write protect group enable */
+ __IO uint8_t ManDeflECC; /*!< Manufacturer default ECC */
+ __IO uint8_t WrSpeedFact; /*!< Write speed factor */
+ __IO uint8_t MaxWrBlockLen; /*!< Max. write data block length */
+ __IO uint8_t WriteBlockPaPartial; /*!< Partial blocks for write allowed */
+ __IO uint8_t Reserved3; /*!< Reserded */
+ __IO uint8_t ContentProtectAppli; /*!< Content protection application */
+ __IO uint8_t FileFormatGrouop; /*!< File format group */
+ __IO uint8_t CopyFlag; /*!< Copy flag (OTP) */
+ __IO uint8_t PermWrProtect; /*!< Permanent write protection */
+ __IO uint8_t TempWrProtect; /*!< Temporary write protection */
+ __IO uint8_t FileFormat; /*!< File Format */
+ __IO uint8_t ECC; /*!< ECC code */
+ __IO uint8_t CSD_CRC; /*!< CSD CRC */
+ __IO uint8_t Reserved4; /*!< always 1*/
+} SD_CSD;
+
+/**
+ * @brief Card Identification Data: CID Register
+ */
+typedef struct
+{
+ __IO uint8_t ManufacturerID; /*!< ManufacturerID */
+ __IO uint16_t OEM_AppliID; /*!< OEM/Application ID */
+ __IO uint32_t ProdName1; /*!< Product Name part1 */
+ __IO uint8_t ProdName2; /*!< Product Name part2*/
+ __IO uint8_t ProdRev; /*!< Product Revision */
+ __IO uint32_t ProdSN; /*!< Product Serial Number */
+ __IO uint8_t Reserved1; /*!< Reserved1 */
+ __IO uint16_t ManufactDate; /*!< Manufacturing Date */
+ __IO uint8_t CID_CRC; /*!< CID CRC */
+ __IO uint8_t Reserved2; /*!< always 1 */
+} SD_CID;
+
+/**
+ * @brief SD Card Status
+ */
+typedef struct
+{
+ __IO uint8_t DAT_BUS_WIDTH;
+ __IO uint8_t SECURED_MODE;
+ __IO uint16_t SD_CARD_TYPE;
+ __IO uint32_t SIZE_OF_PROTECTED_AREA;
+ __IO uint8_t SPEED_CLASS;
+ __IO uint8_t PERFORMANCE_MOVE;
+ __IO uint8_t AU_SIZE;
+ __IO uint16_t ERASE_SIZE;
+ __IO uint8_t ERASE_TIMEOUT;
+ __IO uint8_t ERASE_OFFSET;
+} SD_CardStatus;
+
+
+/**
+ * @brief SD Card information
+ */
+typedef struct
+{
+ SD_CSD SD_csd;
+ SD_CID SD_cid;
+ uint64_t CardCapacity; /*!< Card Capacity */
+ uint32_t CardBlockSize; /*!< Card Block Size */
+ uint16_t RCA;
+ uint8_t CardType;
+} SD_CardInfo;
+
+/**
+ * @}
+ */
+
+/** @defgroup STM32L152D_EVAL_SDIO_SD_Exported_Constants
+ * @{
+ */
+
+/**
+ * @brief SDIO Commands Index
+ */
+#define SD_CMD_GO_IDLE_STATE ((uint8_t)0)
+#define SD_CMD_SEND_OP_COND ((uint8_t)1)
+#define SD_CMD_ALL_SEND_CID ((uint8_t)2)
+#define SD_CMD_SET_REL_ADDR ((uint8_t)3) /*!< SDIO_SEND_REL_ADDR for SD Card */
+#define SD_CMD_SET_DSR ((uint8_t)4)
+#define SD_CMD_SDIO_SEN_OP_COND ((uint8_t)5)
+#define SD_CMD_HS_SWITCH ((uint8_t)6)
+#define SD_CMD_SEL_DESEL_CARD ((uint8_t)7)
+#define SD_CMD_HS_SEND_EXT_CSD ((uint8_t)8)
+#define SD_CMD_SEND_CSD ((uint8_t)9)
+#define SD_CMD_SEND_CID ((uint8_t)10)
+#define SD_CMD_READ_DAT_UNTIL_STOP ((uint8_t)11) /*!< SD Card doesn't support it */
+#define SD_CMD_STOP_TRANSMISSION ((uint8_t)12)
+#define SD_CMD_SEND_STATUS ((uint8_t)13)
+#define SD_CMD_HS_BUSTEST_READ ((uint8_t)14)
+#define SD_CMD_GO_INACTIVE_STATE ((uint8_t)15)
+#define SD_CMD_SET_BLOCKLEN ((uint8_t)16)
+#define SD_CMD_READ_SINGLE_BLOCK ((uint8_t)17)
+#define SD_CMD_READ_MULT_BLOCK ((uint8_t)18)
+#define SD_CMD_HS_BUSTEST_WRITE ((uint8_t)19)
+#define SD_CMD_WRITE_DAT_UNTIL_STOP ((uint8_t)20) /*!< SD Card doesn't support it */
+#define SD_CMD_SET_BLOCK_COUNT ((uint8_t)23) /*!< SD Card doesn't support it */
+#define SD_CMD_WRITE_SINGLE_BLOCK ((uint8_t)24)
+#define SD_CMD_WRITE_MULT_BLOCK ((uint8_t)25)
+#define SD_CMD_PROG_CID ((uint8_t)26) /*!< reserved for manufacturers */
+#define SD_CMD_PROG_CSD ((uint8_t)27)
+#define SD_CMD_SET_WRITE_PROT ((uint8_t)28)
+#define SD_CMD_CLR_WRITE_PROT ((uint8_t)29)
+#define SD_CMD_SEND_WRITE_PROT ((uint8_t)30)
+#define SD_CMD_SD_ERASE_GRP_START ((uint8_t)32) /*!< To set the address of the first write
+ block to be erased. (For SD card only) */
+#define SD_CMD_SD_ERASE_GRP_END ((uint8_t)33) /*!< To set the address of the last write block of the
+ continuous range to be erased. (For SD card only) */
+#define SD_CMD_ERASE_GRP_START ((uint8_t)35) /*!< To set the address of the first write block to be erased.
+ (For MMC card only spec 3.31) */
+
+#define SD_CMD_ERASE_GRP_END ((uint8_t)36) /*!< To set the address of the last write block of the
+ continuous range to be erased. (For MMC card only spec 3.31) */
+
+#define SD_CMD_ERASE ((uint8_t)38)
+#define SD_CMD_FAST_IO ((uint8_t)39) /*!< SD Card doesn't support it */
+#define SD_CMD_GO_IRQ_STATE ((uint8_t)40) /*!< SD Card doesn't support it */
+#define SD_CMD_LOCK_UNLOCK ((uint8_t)42)
+#define SD_CMD_APP_CMD ((uint8_t)55)
+#define SD_CMD_GEN_CMD ((uint8_t)56)
+#define SD_CMD_NO_CMD ((uint8_t)64)
+
+/**
+ * @brief Following commands are SD Card Specific commands.
+ * SDIO_APP_CMD should be sent before sending these commands.
+ */
+#define SD_CMD_APP_SD_SET_BUSWIDTH ((uint8_t)6) /*!< For SD Card only */
+#define SD_CMD_SD_APP_STAUS ((uint8_t)13) /*!< For SD Card only */
+#define SD_CMD_SD_APP_SEND_NUM_WRITE_BLOCKS ((uint8_t)22) /*!< For SD Card only */
+#define SD_CMD_SD_APP_OP_COND ((uint8_t)41) /*!< For SD Card only */
+#define SD_CMD_SD_APP_SET_CLR_CARD_DETECT ((uint8_t)42) /*!< For SD Card only */
+#define SD_CMD_SD_APP_SEND_SCR ((uint8_t)51) /*!< For SD Card only */
+#define SD_CMD_SDIO_RW_DIRECT ((uint8_t)52) /*!< For SD I/O Card only */
+#define SD_CMD_SDIO_RW_EXTENDED ((uint8_t)53) /*!< For SD I/O Card only */
+
+/**
+ * @brief Following commands are SD Card Specific security commands.
+ * SDIO_APP_CMD should be sent before sending these commands.
+ */
+#define SD_CMD_SD_APP_GET_MKB ((uint8_t)43) /*!< For SD Card only */
+#define SD_CMD_SD_APP_GET_MID ((uint8_t)44) /*!< For SD Card only */
+#define SD_CMD_SD_APP_SET_CER_RN1 ((uint8_t)45) /*!< For SD Card only */
+#define SD_CMD_SD_APP_GET_CER_RN2 ((uint8_t)46) /*!< For SD Card only */
+#define SD_CMD_SD_APP_SET_CER_RES2 ((uint8_t)47) /*!< For SD Card only */
+#define SD_CMD_SD_APP_GET_CER_RES1 ((uint8_t)48) /*!< For SD Card only */
+#define SD_CMD_SD_APP_SECURE_READ_MULTIPLE_BLOCK ((uint8_t)18) /*!< For SD Card only */
+#define SD_CMD_SD_APP_SECURE_WRITE_MULTIPLE_BLOCK ((uint8_t)25) /*!< For SD Card only */
+#define SD_CMD_SD_APP_SECURE_ERASE ((uint8_t)38) /*!< For SD Card only */
+#define SD_CMD_SD_APP_CHANGE_SECURE_AREA ((uint8_t)49) /*!< For SD Card only */
+#define SD_CMD_SD_APP_SECURE_WRITE_MKB ((uint8_t)48) /*!< For SD Card only */
+
+/* Uncomment the following line to select the SDIO Data transfer mode */
+#if !defined (SD_DMA_MODE) && !defined (SD_POLLING_MODE)
+#define SD_DMA_MODE ((uint32_t)0x00000000)
+/*#define SD_POLLING_MODE ((uint32_t)0x00000002)*/
+#endif
+
+/**
+ * @brief SD detection on its memory slot
+ */
+#define SD_PRESENT ((uint8_t)0x01)
+#define SD_NOT_PRESENT ((uint8_t)0x00)
+
+/**
+ * @brief Supported SD Memory Cards
+ */
+#define SDIO_STD_CAPACITY_SD_CARD_V1_1 ((uint32_t)0x00000000)
+#define SDIO_STD_CAPACITY_SD_CARD_V2_0 ((uint32_t)0x00000001)
+#define SDIO_HIGH_CAPACITY_SD_CARD ((uint32_t)0x00000002)
+#define SDIO_MULTIMEDIA_CARD ((uint32_t)0x00000003)
+#define SDIO_SECURE_DIGITAL_IO_CARD ((uint32_t)0x00000004)
+#define SDIO_HIGH_SPEED_MULTIMEDIA_CARD ((uint32_t)0x00000005)
+#define SDIO_SECURE_DIGITAL_IO_COMBO_CARD ((uint32_t)0x00000006)
+#define SDIO_HIGH_CAPACITY_MMC_CARD ((uint32_t)0x00000007)
+
+/**
+ * @}
+ */
+
+/** @defgroup STM32L152D_EVAL_SDIO_SD_Exported_Macros
+ * @{
+ */
+/**
+ * @}
+ */
+
+/** @defgroup STM32L152D_EVAL_SDIO_SD_Exported_Functions
+ * @{
+ */
+void SD_DeInit(void);
+SD_Error SD_Init(void);
+SDTransferState SD_GetStatus(void);
+SDCardState SD_GetState(void);
+uint8_t SD_Detect(void);
+SD_Error SD_PowerON(void);
+SD_Error SD_PowerOFF(void);
+SD_Error SD_InitializeCards(void);
+SD_Error SD_GetCardInfo(SD_CardInfo *cardinfo);
+SD_Error SD_GetCardStatus(SD_CardStatus *cardstatus);
+SD_Error SD_EnableWideBusOperation(uint32_t WideMode);
+SD_Error SD_SelectDeselect(uint32_t addr);
+SD_Error SD_ReadBlock(uint8_t *readbuff, uint64_t ReadAddr, uint16_t BlockSize);
+SD_Error SD_ReadMultiBlocks(uint8_t *readbuff, uint64_t ReadAddr, uint16_t BlockSize, uint32_t NumberOfBlocks);
+SD_Error SD_WriteBlock(uint8_t *writebuff, uint64_t WriteAddr, uint16_t BlockSize);
+SD_Error SD_WriteMultiBlocks(uint8_t *writebuff, uint64_t WriteAddr, uint16_t BlockSize, uint32_t NumberOfBlocks);
+SDTransferState SD_GetTransferState(void);
+SD_Error SD_StopTransfer(void);
+SD_Error SD_Erase(uint32_t startaddr, uint32_t endaddr);
+SD_Error SD_SendStatus(uint32_t *pcardstatus);
+SD_Error SD_SendSDStatus(uint32_t *psdstatus);
+SD_Error SD_ProcessIRQSrc(void);
+void SD_ProcessDMAIRQ(void);
+SD_Error SD_WaitReadOperation(void);
+SD_Error SD_WaitWriteOperation(void);
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __STM32L152D_EVAL_SDIO_SD_H */
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval_spi_ee.c b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval_spi_ee.c
new file mode 100644
index 0000000..9c23813
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval_spi_ee.c
@@ -0,0 +1,476 @@
+/**
+ ******************************************************************************
+ * @file stm32l152d_eval_spi_ee.c
+ * @author MCD Application Team
+ * @version V1.0.1
+ * @date 09-March-2012
+ * @brief This file provides a set of functions needed to manage the SPI M95xxx
+ * EEPROM memory mounted on STM32L152D-EVAL board (refer to stm32l152d_eval.h
+ * to know about the boards supporting this memory).
+ * It implements a high level communication layer for read and write
+ * from/to this memory. The needed STM32 hardware resources (SPI and
+ * GPIO) are defined in stm32l152d_eval.h file, and the initialization is
+ * performed in SPI_sEE_LowLevel_Init() function declared in stm32l152d_eval.c
+ * file.
+ * You can easily tailor this driver to any other development board,
+ * by just adapting the defines for hardware resources and
+ * SPI_sEE_LowLevel_Init() function.
+ *
+ * +-----------------------------------------------------------+
+ * | Pin assignment |
+ * +-----------------------------+---------------+-------------+
+ * | STM32 SPI Pins | sEE | Pin |
+ * +-----------------------------+---------------+-------------+
+ * | sEE_CS_PIN | ChipSelect | 1 (/S) |
+ * | sEE_MISO_PIN / MISO | DataOut | 2 (Q) |
+ * | sEE_WP_PIN | WriteProtect | 3 (/W) |
+ * | | GND | 4 (0 V) |
+ * | sEE_MOSI_PIN / MOSI | DataIn | 5 (D) |
+ * | sEE_SCK_PIN / SCLK | Clock | 6 (C) |
+ * | | Hold | 7 (/HOLD)|
+ * | | VCC | 8 (3.3 V)|
+ * +-----------------------------+---------------+-------------+
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.st.com/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+
+/* Includes ------------------------------------------------------------------*/
+#include "stm32l152d_eval_spi_ee.h"
+
+/** @addtogroup Utilities
+ * @{
+ */
+
+/** @addtogroup STM32_EVAL
+ * @{
+ */
+
+/** @addtogroup STM32L152D_EVAL
+ * @{
+ */
+
+/** @addtogroup STM32L152D_EVAL_SPI_EEPROM
+ * @brief This file includes the M95xxx SPI EEPROM driver of STM32-EVAL boards.
+ * @{
+ */
+
+/** @defgroup STM32L152D_EVAL_SPI_EEPROM_Private_Types
+ * @{
+ */
+/**
+ * @}
+ */
+
+
+/** @defgroup STM32L152D_EVAL_SPI_EEPROM_Private_Defines
+ * @{
+ */
+/**
+ * @}
+ */
+
+/** @defgroup STM32L152D_EVAL_SPI_EEPROM_Private_Macros
+ * @{
+ */
+/**
+ * @}
+ */
+
+
+/** @defgroup STM32L152D_EVAL_SPI_EEPROM_Private_Variables
+ * @{
+ */
+/**
+ * @}
+ */
+
+
+/** @defgroup STM32L152D_EVAL_SPI_EEPROM_Private_Function_Prototypes
+ * @{
+ */
+/**
+ * @}
+ */
+
+
+/** @defgroup STM32L152D_EVAL_SPI_EEPROM_Private_Functions
+ * @{
+ */
+
+/**
+ * @brief DeInitializes the peripherals used by the SPI EEPROM driver.
+ * @param None
+ * @retval None
+ */
+void sEE_DeInit(void)
+{
+ sEE_SPI_LowLevel_DeInit();
+}
+
+/**
+ * @brief Initializes the peripherals used by the SPI EEPROM driver.
+ * @param None
+ * @retval None
+ */
+void sEE_Init(void)
+{
+ sEE_SPI_LowLevel_Init();
+
+ /*!< Deselect the EEPROM: Chip Select high */
+ sEE_CS_HIGH();
+}
+
+/**
+ * @brief Writes more than one byte to the EEPROM with a single WRITE cycle
+ * (Page WRITE sequence).
+ * @note The number of byte can't exceed the EEPROM page size.
+ * @param pBuffer: pointer to the buffer containing the data to be written
+ * to the EEPROM.
+ * @param WriteAddr: EEPROM's internal address to write to.
+ * @param NumByteToWrite: number of bytes to write to the EEPROM, must be equal
+ * or less than "sEE_PAGESIZE" value.
+ * @retval None
+ */
+uint32_t sEE_WritePage(uint8_t* pBuffer, uint16_t WriteAddr, uint16_t* NumByteToWrite)
+{
+ /*!< Enable the write access to the EEPROM */
+ sEE_WriteEnable();
+
+ /*!< Select the EEPROM: Chip Select low */
+ sEE_CS_LOW();
+
+ /*!< Send "Write to Memory" instruction and MSB of WriteAddr */
+ sEE_SendByte(sEE_CMD_WRITE | (uint8_t)((WriteAddr & 0x0100)>>5));
+
+ /*!< Send WriteAddr address byte to write to */
+ sEE_SendByte(WriteAddr & 0xFF);
+
+ /*!< while there is data to be written on the EEPROM */
+ while ((*NumByteToWrite)--)
+ {
+ /*!< Send the current byte */
+ sEE_SendByte(*pBuffer);
+ /*!< Point on the next byte to be written */
+ pBuffer++;
+ }
+
+ /*!< Deselect the EEPROM: Chip Select high */
+ sEE_CS_HIGH();
+
+ /*!< Wait the end of EEPROM writing */
+ sEE_WaitEepromStandbyState();
+
+ /*!< Disable the write access to the EEROM */
+ sEE_WriteDisable();
+
+ return 0;
+}
+
+/**
+ * @brief Writes block of data to the EEPROM. In this function, the number of
+ * WRITE cycles are reduced, using Page WRITE sequence.
+ * @param pBuffer: pointer to the buffer containing the data to be written
+ * to the EEPROM.
+ * @param WriteAddr: EEPROM's internal address to write to.
+ * @param NumByteToWrite: number of bytes to write to the EEPROM.
+ * @retval None
+ */
+void sEE_WriteBuffer(uint8_t* pBuffer, uint16_t WriteAddr, uint16_t NumByteToWrite)
+{
+ uint16_t NumOfPage = 0, NumOfSingle = 0, Addr = 0, count = 0, temp = 0;
+ uint16_t sEE_DataNum = 0;
+
+ Addr = WriteAddr % sEE_PAGESIZE;
+ count = sEE_PAGESIZE - Addr;
+ NumOfPage = NumByteToWrite / sEE_PAGESIZE;
+ NumOfSingle = NumByteToWrite % sEE_PAGESIZE;
+
+ if (Addr == 0) /*!< WriteAddr is sEE_PAGESIZE aligned */
+ {
+ if (NumOfPage == 0) /*!< NumByteToWrite < sEE_PAGESIZE */
+ {
+ sEE_DataNum = NumByteToWrite;
+ sEE_WritePage(pBuffer, WriteAddr, &sEE_DataNum);
+ }
+ else /*!< NumByteToWrite > sEE_PAGESIZE */
+ {
+ while (NumOfPage--)
+ {
+ sEE_DataNum = sEE_PAGESIZE;
+ sEE_WritePage(pBuffer, WriteAddr, &sEE_DataNum);
+ WriteAddr += sEE_PAGESIZE;
+ pBuffer += sEE_PAGESIZE;
+ }
+
+ sEE_DataNum = NumOfSingle;
+ sEE_WritePage(pBuffer, WriteAddr, &sEE_DataNum);
+ }
+ }
+ else /*!< WriteAddr is not sEE_PAGESIZE aligned */
+ {
+ if (NumOfPage == 0) /*!< NumByteToWrite < sEE_PAGESIZE */
+ {
+ if (NumOfSingle > count) /*!< (NumByteToWrite + WriteAddr) > sEE_PAGESIZE */
+ {
+ temp = NumOfSingle - count;
+ sEE_DataNum = count;
+ sEE_WritePage(pBuffer, WriteAddr, &sEE_DataNum);
+ WriteAddr += count;
+ pBuffer += count;
+
+ sEE_DataNum = temp;
+ sEE_WritePage(pBuffer, WriteAddr, &sEE_DataNum);
+ }
+ else
+ {
+ sEE_DataNum = NumByteToWrite;
+ sEE_WritePage(pBuffer, WriteAddr, &sEE_DataNum);
+ }
+ }
+ else /*!< NumByteToWrite > sEE_PAGESIZE */
+ {
+ NumByteToWrite -= count;
+ NumOfPage = NumByteToWrite / sEE_PAGESIZE;
+ NumOfSingle = NumByteToWrite % sEE_PAGESIZE;
+
+ sEE_DataNum = count;
+
+ sEE_WritePage(pBuffer, WriteAddr, &sEE_DataNum);
+ WriteAddr += count;
+ pBuffer += count;
+
+ while (NumOfPage--)
+ {
+ sEE_DataNum = sEE_PAGESIZE;
+
+ sEE_WritePage(pBuffer, WriteAddr, &sEE_DataNum);
+ WriteAddr += sEE_PAGESIZE;
+ pBuffer += sEE_PAGESIZE;
+ }
+
+ if (NumOfSingle != 0)
+ {
+ sEE_DataNum = NumOfSingle;
+
+ sEE_WritePage(pBuffer, WriteAddr, &sEE_DataNum);
+ }
+ }
+ }
+}
+
+/**
+ * @brief Reads a block of data from the EEPROM.
+ * @param pBuffer: pointer to the buffer that receives the data read from the EEPROM.
+ * @param ReadAddr: EEPROM's internal address to read from.
+ * @param NumByteToRead: number of bytes to read from the EEPROM.
+ * @retval None
+ */
+uint32_t sEE_ReadBuffer(uint8_t* pBuffer, uint16_t ReadAddr, uint16_t* NumByteToRead)
+{
+ /*!< Select the EEPROM: Chip Select low */
+ sEE_CS_LOW();
+
+ /*!< Send "Read from Memory" instruction and MSB of WriteAddr */
+ sEE_SendByte(sEE_CMD_READ | (uint8_t)((ReadAddr & 0x100)>>5));
+
+ /*!< Send WriteAddr address byte to write to */
+ sEE_SendByte(ReadAddr & 0xFF);
+
+ while ((*NumByteToRead)--) /*!< while there is data to be read */
+ {
+ /*!< Read a byte from the EEPROM */
+ *pBuffer = sEE_SendByte(sEE_DUMMY_BYTE);
+ /*!< Point to the next location where the byte read will be saved */
+ pBuffer++;
+ }
+
+ /*!< Deselect the EEPROM: Chip Select high */
+ sEE_CS_HIGH();
+
+ return 0;
+}
+
+
+/**
+ * @brief Reads a byte from the SPI EEPROM.
+ * @note This function must be used only if the Start_Read_Sequence function
+ * has been previously called.
+ * @param None
+ * @retval Byte Read from the SPI EEPROM.
+ */
+uint8_t sEE_ReadByte(void)
+{
+ return (sEE_SendByte(sEE_DUMMY_BYTE));
+}
+
+/**
+ * @brief Sends a byte through the SPI interface and return the byte received
+ * from the SPI bus.
+ * @param byte: byte to send.
+ * @retval The value of the received byte.
+ */
+uint8_t sEE_SendByte(uint8_t byte)
+{
+ /*!< Loop while DR register in not empty */
+ while (SPI_I2S_GetFlagStatus(sEE_SPI, SPI_I2S_FLAG_TXE) == RESET);
+
+ /*!< Send byte through the SPI peripheral */
+ SPI_SendData(sEE_SPI, byte);
+
+ /*!< Wait to receive a byte */
+ while (SPI_I2S_GetFlagStatus(sEE_SPI, SPI_I2S_FLAG_RXNE) == RESET);
+
+ /*!< Return the byte read from the SPI bus */
+ return (uint8_t)SPI_ReceiveData(sEE_SPI);
+}
+/**
+ * @brief Enables the write access to the EEPROM.
+ * @param None
+ * @retval None
+ */
+void sEE_WriteEnable(void)
+{
+ /*!< Select the EEPROM: Chip Select low */
+ sEE_CS_LOW();
+
+ /*!< Send "Write Enable" instruction */
+ sEE_SendByte(sEE_CMD_WREN);
+
+ /*!< Deselect the EEPROM: Chip Select high */
+ sEE_CS_HIGH();
+}
+
+/**
+ * @brief Disables the write access to the EEPROM.
+ * @param None
+ * @retval None
+ */
+void sEE_WriteDisable(void)
+{
+ /*!< Select the EEPROM: Chip Select low */
+ sEE_CS_LOW();
+
+ /*!< Send "Write Disable" instruction */
+ sEE_SendByte(sEE_CMD_WRDI);
+
+ /*!< Deselect the EEPROM: Chip Select high */
+ sEE_CS_HIGH();
+}
+
+/**
+ * @brief Write new value in EEPROM Status Register.
+ * @param regval : new value of register
+ * @retval None
+ */
+void sEE_WriteStatusRegister(uint8_t regval)
+{
+ /*!< Select the EEPROM: Chip Select low */
+ sEE_CS_LOW();
+
+ /*!< Enable the write access to the EEPROM */
+ sEE_WriteEnable();
+
+ /*!< Send "Write Status Register" instruction */
+ sEE_SendByte(sEE_CMD_WRSR);
+
+ /*!< Write regval in status register */
+ sEE_SendByte(regval);
+
+ /*!< Deselect the EEPROM: Chip Select high */
+ sEE_CS_HIGH();
+}
+
+/**
+ * @brief Read EEPROM Status Register.
+ * @param None
+ * @retval The value of the Status register.
+ */
+uint8_t sEE_ReadStatusRegister(void)
+{
+ uint8_t sEEstatus = 0;
+
+ /*!< Select the EEPROM: Chip Select low */
+ sEE_CS_LOW();
+
+ /*!< Send "Read Status Register" instruction */
+ sEE_SendByte(sEE_CMD_RDSR);
+
+ /*!< Send a dummy byte to generate the clock needed by the EEPROM
+ and put the value of the status register in EEPROM Status variable */
+ sEEstatus = sEE_SendByte(sEE_DUMMY_BYTE);
+
+ /*!< Deselect the EEPROM: Chip Select high */
+ sEE_CS_HIGH();
+
+ return sEEstatus;
+}
+
+/**
+ * @brief Polls the status of the Write In Progress (WIP) flag in the EEPROM's
+ * status register and loop until write operation has completed.
+ * @param None
+ * @retval None
+ */
+uint32_t sEE_WaitEepromStandbyState(void)
+{
+ uint8_t sEEstatus = 0;
+
+ /*!< Select the EEPROM: Chip Select low */
+ sEE_CS_LOW();
+
+ /*!< Send "Read Status Register" instruction */
+ sEE_SendByte(sEE_CMD_RDSR);
+
+ /*!< Loop as long as the memory is busy with a write cycle */
+ do
+ {
+ /*!< Send a dummy byte to generate the clock needed by the EEPROM
+ and put the value of the status register in EEPROM Status variable */
+ sEEstatus = sEE_SendByte(sEE_DUMMY_BYTE);
+
+ }
+ while ((sEEstatus & sEE_WIP_FLAG) == SET); /* Write in progress */
+
+ /*!< Deselect the EEPROM: Chip Select high */
+ sEE_CS_HIGH();
+
+ return 0;
+}
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval_spi_ee.h b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval_spi_ee.h
new file mode 100644
index 0000000..f1abfac
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152D_EVAL/stm32l152d_eval_spi_ee.h
@@ -0,0 +1,156 @@
+/**
+ ******************************************************************************
+ * @file stm32l152d_eval_spi_ee.h
+ * @author MCD Application Team
+ * @version V1.0.1
+ * @date 09-March-2012
+ * @brief This file contains all the functions prototypes for the stm32l152d_eval_spi_ee
+ * firmware driver.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.st.com/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __STM32L152D_EVAL_SPI_EE_H
+#define __STM32L152D_EVAL_SPI_EE_H
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+/* Includes ------------------------------------------------------------------*/
+#include "stm32l152d_eval.h"
+
+/** @addtogroup Utilities
+ * @{
+ */
+
+/** @addtogroup STM32_EVAL
+ * @{
+ */
+
+/** @addtogroup STM32L152D_EVAL
+ * @{
+ */
+
+/** @addtogroup STM32L152D_EVAL_SPI_EEPROM
+ * @{
+ */
+
+/** @defgroup STM32L152D_EVAL_SPI_EEPROM_Exported_Types
+ * @{
+ */
+/**
+ * @}
+ */
+
+/** @defgroup STM32L152D_EVAL_SPI_EEPROM_Exported_Constants
+ * @{
+ */
+/**
+ * @brief M95 SPI EEPROM supported commands
+ */
+#define sEE_CMD_WREN 0x06 /*!< Write enable instruction */
+#define sEE_CMD_WRDI 0x04 /*!< Write disable instruction */
+#define sEE_CMD_RDSR 0x05 /*!< Read Status Register instruction */
+#define sEE_CMD_WRSR 0x01 /*!< Write Status Register instruction */
+#define sEE_CMD_WRITE 0x02 /*!< Write to Memory instruction */
+#define sEE_CMD_READ 0x03 /*!< Read from Memory instruction */
+
+/**
+ * @brief M95040 SPI EEPROM defines
+ */
+#define sEE_WIP_FLAG 0x01 /*!< Write In Progress (WIP) flag */
+
+#define sEE_DUMMY_BYTE 0xA5
+
+#define sEE_PAGESIZE 16
+
+
+
+/**
+ * @}
+ */
+
+/** @defgroup STM32L152D_EVAL_SPI_EEPROM_Exported_Macros
+ * @{
+ */
+/**
+ * @brief Select EEPROM: Chip Select pin low
+ */
+#define sEE_CS_LOW() GPIO_ResetBits(sEE_SPI_CS_GPIO_PORT, sEE_SPI_CS_PIN)
+/**
+ * @brief Deselect EEPROM: Chip Select pin high
+ */
+#define sEE_CS_HIGH() GPIO_SetBits(sEE_SPI_CS_GPIO_PORT, sEE_SPI_CS_PIN)
+/**
+ * @}
+ */
+
+
+
+/** @defgroup STM32L152D_EVAL_SPI_EEPROM_Exported_Functions
+ * @{
+ */
+/**
+ * @brief High layer functions
+ */
+void sEE_DeInit(void);
+void sEE_Init(void);
+uint32_t sEE_ReadBuffer(uint8_t* pBuffer, uint16_t ReadAddr, uint16_t* NumByteToRead);
+void sEE_WriteBuffer(uint8_t* pBuffer, uint16_t WriteAddr, uint16_t NumByteToWrite);
+uint32_t sEE_WritePage(uint8_t* pBuffer, uint16_t WriteAddr, uint16_t* NumByteToWrite);
+uint32_t sEE_WaitEepromStandbyState(void);
+
+/**
+ * @brief Low layer functions
+ */
+uint8_t sEE_ReadByte(void);
+uint8_t sEE_SendByte(uint8_t byte);
+void sEE_WriteEnable(void);
+void sEE_WriteDisable(void);
+void sEE_WriteStatusRegister(uint8_t regval);
+uint8_t sEE_ReadStatusRegister(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __STM32L152D_EVAL_SPI_EE_H */
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152_EVAL/stm32l152_eval.c b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152_EVAL/stm32l152_eval.c
new file mode 100644
index 0000000..0ef5928
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152_EVAL/stm32l152_eval.c
@@ -0,0 +1,740 @@
+/**
+ ******************************************************************************
+ * @file stm32l152_eval.c
+ * @author MCD Application Team
+ * @version V5.0.2
+ * @date 09-March-2012
+ * @brief This file provides:
+ * - set of firmware functions to manage Leds, push-button and COM ports
+ * - low level initialization functions for SD card (on SPI) and
+ * temperature sensor (LM75) available on STM32L152-EVAL
+ * evaluation board RevB from STMicroelectronics.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.st.com/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+
+/* Includes ------------------------------------------------------------------*/
+#include "stm32l152_eval.h"
+#include "stm32l1xx_spi.h"
+#include "stm32l1xx_i2c.h"
+
+/** @addtogroup Utilities
+ * @{
+ */
+
+/** @addtogroup STM32_EVAL
+ * @{
+ */
+
+/** @addtogroup STM32L152_EVAL
+ * @{
+ */
+
+/** @defgroup STM32L152_EVAL_LOW_LEVEL
+ * @brief This file provides firmware functions to manage Leds, push-buttons,
+ * COM ports, SD card on SPI and temperature sensor (LM75) available on
+ * STM32L152-EVAL evaluation board from STMicroelectronics.
+ * @{
+ */
+
+/** @defgroup STM32L152_EVAL_LOW_LEVEL_Private_TypesDefinitions
+ * @{
+ */
+/**
+ * @}
+ */
+
+
+/** @defgroup STM32L152_EVAL_LOW_LEVEL_Private_Defines
+ * @{
+ */
+/**
+ * @}
+ */
+
+
+/** @defgroup STM32L152_EVAL_LOW_LEVEL_Private_Macros
+ * @{
+ */
+/**
+ * @}
+ */
+
+
+/** @defgroup STM32L152_EVAL_LOW_LEVEL_Private_Variables
+ * @{
+ */
+GPIO_TypeDef* GPIO_PORT[LEDn] = {LED1_GPIO_PORT, LED2_GPIO_PORT, LED3_GPIO_PORT,
+ LED4_GPIO_PORT};
+const uint16_t GPIO_PIN[LEDn] = {LED1_PIN, LED2_PIN, LED3_PIN,
+ LED4_PIN};
+const uint32_t GPIO_CLK[LEDn] = {LED1_GPIO_CLK, LED2_GPIO_CLK, LED3_GPIO_CLK,
+ LED4_GPIO_CLK};
+
+GPIO_TypeDef* BUTTON_PORT[BUTTONn] = {KEY_BUTTON_GPIO_PORT, RIGHT_BUTTON_GPIO_PORT,
+ LEFT_BUTTON_GPIO_PORT, UP_BUTTON_GPIO_PORT,
+ DOWN_BUTTON_GPIO_PORT, SEL_BUTTON_GPIO_PORT};
+
+const uint16_t BUTTON_PIN[BUTTONn] = {KEY_BUTTON_PIN, RIGHT_BUTTON_PIN,
+ LEFT_BUTTON_PIN, UP_BUTTON_PIN,
+ DOWN_BUTTON_PIN, SEL_BUTTON_PIN};
+
+const uint32_t BUTTON_CLK[BUTTONn] = {KEY_BUTTON_GPIO_CLK, RIGHT_BUTTON_GPIO_CLK,
+ LEFT_BUTTON_GPIO_CLK, UP_BUTTON_GPIO_CLK,
+ DOWN_BUTTON_GPIO_CLK, SEL_BUTTON_GPIO_CLK};
+
+const uint16_t BUTTON_EXTI_LINE[BUTTONn] = {KEY_BUTTON_EXTI_LINE,
+ RIGHT_BUTTON_EXTI_LINE,
+ LEFT_BUTTON_EXTI_LINE,
+ UP_BUTTON_EXTI_LINE,
+ DOWN_BUTTON_EXTI_LINE,
+ SEL_BUTTON_EXTI_LINE};
+
+const uint8_t BUTTON_PORT_SOURCE[BUTTONn] = {KEY_BUTTON_EXTI_PORT_SOURCE,
+ RIGHT_BUTTON_EXTI_PORT_SOURCE,
+ LEFT_BUTTON_EXTI_PORT_SOURCE,
+ UP_BUTTON_EXTI_PORT_SOURCE,
+ DOWN_BUTTON_EXTI_PORT_SOURCE,
+ SEL_BUTTON_EXTI_PORT_SOURCE};
+
+const uint8_t BUTTON_PIN_SOURCE[BUTTONn] = {KEY_BUTTON_EXTI_PIN_SOURCE,
+ RIGHT_BUTTON_EXTI_PIN_SOURCE,
+ LEFT_BUTTON_EXTI_PIN_SOURCE,
+ UP_BUTTON_EXTI_PIN_SOURCE,
+ DOWN_BUTTON_EXTI_PIN_SOURCE,
+ SEL_BUTTON_EXTI_PIN_SOURCE};
+
+const uint8_t BUTTON_IRQn[BUTTONn] = {KEY_BUTTON_EXTI_IRQn, RIGHT_BUTTON_EXTI_IRQn,
+ LEFT_BUTTON_EXTI_IRQn, UP_BUTTON_EXTI_IRQn,
+ DOWN_BUTTON_EXTI_IRQn, SEL_BUTTON_EXTI_IRQn};
+
+USART_TypeDef* COM_USART[COMn] = {EVAL_COM1, EVAL_COM2};
+
+GPIO_TypeDef* COM_TX_PORT[COMn] = {EVAL_COM1_TX_GPIO_PORT, EVAL_COM2_TX_GPIO_PORT};
+
+GPIO_TypeDef* COM_RX_PORT[COMn] = {EVAL_COM1_RX_GPIO_PORT, EVAL_COM2_RX_GPIO_PORT};
+
+const uint32_t COM_USART_CLK[COMn] = {EVAL_COM1_CLK, EVAL_COM2_CLK};
+
+const uint32_t COM_TX_PORT_CLK[COMn] = {EVAL_COM1_TX_GPIO_CLK, EVAL_COM2_TX_GPIO_CLK};
+
+const uint32_t COM_RX_PORT_CLK[COMn] = {EVAL_COM1_RX_GPIO_CLK, EVAL_COM2_RX_GPIO_CLK};
+
+const uint16_t COM_TX_PIN[COMn] = {EVAL_COM1_TX_PIN, EVAL_COM2_TX_PIN};
+
+const uint16_t COM_RX_PIN[COMn] = {EVAL_COM1_RX_PIN, EVAL_COM2_RX_PIN};
+
+const uint8_t COM_TX_PIN_SOURCE[COMn] = {EVAL_COM1_TX_SOURCE, EVAL_COM2_TX_SOURCE};
+
+const uint8_t COM_RX_PIN_SOURCE[COMn] = {EVAL_COM1_RX_SOURCE, EVAL_COM2_RX_SOURCE};
+
+const uint8_t COM_TX_AF[COMn] = {EVAL_COM1_TX_AF, EVAL_COM2_TX_AF};
+
+const uint8_t COM_RX_AF[COMn] = {EVAL_COM1_RX_AF, EVAL_COM2_RX_AF};
+
+DMA_InitTypeDef sEEDMA_InitStructure;
+
+/**
+ * @}
+ */
+
+
+/** @defgroup STM32L152_EVAL_LOW_LEVEL_Private_FunctionPrototypes
+ * @{
+ */
+
+/**
+ * @}
+ */
+
+/** @defgroup STM32L152_EVAL_LOW_LEVEL_Private_Functions
+ * @{
+ */
+
+/**
+ * @brief Configures LED GPIO.
+ * @param Led: Specifies the Led to be configured.
+ * This parameter can be one of following parameters:
+ * @arg LED1
+ * @arg LED2
+ * @arg LED3
+ * @arg LED4
+ * @retval None
+ */
+void STM_EVAL_LEDInit(Led_TypeDef Led)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+
+ /* Enable the GPIO_LED Clock */
+ RCC_AHBPeriphClockCmd(GPIO_CLK[Led], ENABLE);
+
+ /* Configure the GPIO_LED pin */
+ GPIO_InitStructure.GPIO_Pin = GPIO_PIN[Led];
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
+ GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
+ GPIO_Init(GPIO_PORT[Led], &GPIO_InitStructure);
+ GPIO_PORT[Led]->BSRRL = GPIO_PIN[Led];
+}
+
+/**
+ * @brief Turns selected LED On.
+ * @param Led: Specifies the Led to be set on.
+ * This parameter can be one of following parameters:
+ * @arg LED1
+ * @arg LED2
+ * @arg LED3
+ * @arg LED4
+ * @retval None
+ */
+void STM_EVAL_LEDOn(Led_TypeDef Led)
+{
+ GPIO_PORT[Led]->BSRRH = GPIO_PIN[Led];
+}
+
+/**
+ * @brief Turns selected LED Off.
+ * @param Led: Specifies the Led to be set off.
+ * This parameter can be one of following parameters:
+ * @arg LED1
+ * @arg LED2
+ * @arg LED3
+ * @arg LED4
+ * @retval None
+ */
+void STM_EVAL_LEDOff(Led_TypeDef Led)
+{
+ GPIO_PORT[Led]->BSRRL = GPIO_PIN[Led];
+}
+
+/**
+ * @brief Toggles the selected LED.
+ * @param Led: Specifies the Led to be toggled.
+ * This parameter can be one of following parameters:
+ * @arg LED1
+ * @arg LED2
+ * @arg LED3
+ * @arg LED4
+ * @retval None
+ */
+void STM_EVAL_LEDToggle(Led_TypeDef Led)
+{
+ GPIO_PORT[Led]->ODR ^= GPIO_PIN[Led];
+}
+
+/**
+ * @brief Configures Button GPIO and EXTI Line.
+ * @param Button: Specifies the Button to be configured.
+ * This parameter can be one of following parameters:
+ * @arg BUTTON_KEY: Key Push Button
+ * @arg BUTTON_RIGHT: Joystick Right Push Button
+ * @arg BUTTON_LEFT: Joystick Left Push Button
+ * @arg BUTTON_UP: Joystick Up Push Button
+ * @arg BUTTON_DOWN: Joystick Down Push Button
+ * @arg BUTTON_SEL: Joystick Sel Push Button
+ * @param Button_Mode: Specifies Button mode.
+ * This parameter can be one of following parameters:
+ * @arg BUTTON_MODE_GPIO: Button will be used as simple IO
+ * @arg BUTTON_MODE_EXTI: Button will be connected to EXTI line with interrupt
+ * generation capability
+ * @retval None
+ */
+void STM_EVAL_PBInit(Button_TypeDef Button, ButtonMode_TypeDef Button_Mode)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+ EXTI_InitTypeDef EXTI_InitStructure;
+ NVIC_InitTypeDef NVIC_InitStructure;
+
+ /* There is no Wakeup and Tamper buttons on STM32L152-EVAL. */
+
+ /* Enable the BUTTON Clock */
+ RCC_AHBPeriphClockCmd(BUTTON_CLK[Button], ENABLE);
+ RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
+
+ /* Configure Button pin as input */
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
+ GPIO_InitStructure.GPIO_Pin = BUTTON_PIN[Button];
+ GPIO_Init(BUTTON_PORT[Button], &GPIO_InitStructure);
+
+ if (Button_Mode == BUTTON_MODE_EXTI)
+ {
+ /* Connect Button EXTI Line to Button GPIO Pin */
+ SYSCFG_EXTILineConfig(BUTTON_PORT_SOURCE[Button], BUTTON_PIN_SOURCE[Button]);
+ /* Configure Button EXTI line */
+ EXTI_InitStructure.EXTI_Line = BUTTON_EXTI_LINE[Button];
+ EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
+
+ if(Button != BUTTON_KEY)
+ {
+ EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
+ }
+ else
+ {
+ EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
+ }
+ EXTI_InitStructure.EXTI_LineCmd = ENABLE;
+ EXTI_Init(&EXTI_InitStructure);
+
+ /* Enable and set Button EXTI Interrupt to the lowest priority */
+ NVIC_InitStructure.NVIC_IRQChannel = BUTTON_IRQn[Button];
+ NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F;
+ NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;
+ NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
+
+ NVIC_Init(&NVIC_InitStructure);
+ }
+}
+
+/**
+ * @brief Returns the selected Button state.
+ * @param Button: Specifies the Button to be checked.
+ * This parameter can be one of following parameters:
+ * @arg BUTTON_KEY: Key Push Button
+ * @arg BUTTON_RIGHT: Joystick Right Push Button
+ * @arg BUTTON_LEFT: Joystick Left Push Button
+ * @arg BUTTON_UP: Joystick Up Push Button
+ * @arg BUTTON_DOWN: Joystick Down Push Button
+ * @arg BUTTON_SEL: Joystick Sel Push Button
+ * @retval Button GPIO pin value is returned.
+ */
+uint32_t STM_EVAL_PBGetState(Button_TypeDef Button)
+{
+ /* There is no Wakeup and Tamper pins on STM32L152-EVAL. */
+
+ return GPIO_ReadInputDataBit(BUTTON_PORT[Button], BUTTON_PIN[Button]);
+}
+
+/**
+ * @brief Configures COM port.
+ * @param COM: Specifies the COM port to be configured.
+ * This parameter can be one of following parameters:
+ * @arg COM1
+ * @arg COM2
+ * @param USART_InitStruct: pointer to a USART_InitTypeDef structure that
+ * contains the configuration information for the specified USART peripheral.
+ * @retval None
+ */
+void STM_EVAL_COMInit(COM_TypeDef COM, USART_InitTypeDef* USART_InitStruct)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+
+ /* Enable GPIO clock */
+ RCC_AHBPeriphClockCmd(COM_TX_PORT_CLK[COM] | COM_RX_PORT_CLK[COM], ENABLE);
+
+ /* Enable UART clock */
+ RCC_APB1PeriphClockCmd(COM_USART_CLK[COM], ENABLE);
+
+ /* Connect PXx to USARTx_Tx */
+ GPIO_PinAFConfig(COM_TX_PORT[COM], COM_TX_PIN_SOURCE[COM], COM_TX_AF[COM]);
+
+ /* Connect PXx to USARTx_Rx */
+ GPIO_PinAFConfig(COM_RX_PORT[COM], COM_RX_PIN_SOURCE[COM], COM_RX_AF[COM]);
+
+ /* Configure USART Tx as alternate function push-pull */
+ GPIO_InitStructure.GPIO_Pin = COM_TX_PIN[COM];
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
+ GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
+ GPIO_Init(COM_TX_PORT[COM], &GPIO_InitStructure);
+
+ /* Configure USART Rx as alternate function push-pull */
+ GPIO_InitStructure.GPIO_Pin = COM_RX_PIN[COM];
+ GPIO_Init(COM_RX_PORT[COM], &GPIO_InitStructure);
+
+ /* USART configuration */
+ USART_Init(COM_USART[COM], USART_InitStruct);
+
+ /* Enable USART */
+ USART_Cmd(COM_USART[COM], ENABLE);
+}
+
+/**
+ * @brief DeInitializes the SPI interface.
+ * @param None
+ * @retval None
+ */
+void SD_LowLevel_DeInit(void)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+
+ SPI_Cmd(SD_SPI, DISABLE); /*!< SD_SPI disable */
+ SPI_DeInit(SD_SPI); /*!< DeInitializes the SD_SPI */
+
+ /*!< SD_SPI Periph clock disable */
+ RCC_APB1PeriphClockCmd(SD_SPI_CLK, DISABLE);
+
+ /*!< Configure SD_SPI pins: SCK */
+ GPIO_InitStructure.GPIO_Pin = SD_SPI_SCK_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
+ GPIO_Init(SD_SPI_SCK_GPIO_PORT, &GPIO_InitStructure);
+
+ /*!< Configure SD_SPI pins: MISO */
+ GPIO_InitStructure.GPIO_Pin = SD_SPI_MISO_PIN;
+ GPIO_Init(SD_SPI_MISO_GPIO_PORT, &GPIO_InitStructure);
+
+ /*!< Configure SD_SPI pins: MOSI */
+ GPIO_InitStructure.GPIO_Pin = SD_SPI_MOSI_PIN;
+ GPIO_Init(SD_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure);
+
+ /*!< Configure SD_SPI_CS_PIN pin: SD Card CS pin */
+ GPIO_InitStructure.GPIO_Pin = SD_CS_PIN;
+ GPIO_Init(SD_CS_GPIO_PORT, &GPIO_InitStructure);
+
+ /*!< Configure SD_SPI_DETECT_PIN pin: SD Card detect pin */
+ GPIO_InitStructure.GPIO_Pin = SD_DETECT_PIN;
+ GPIO_Init(SD_DETECT_GPIO_PORT, &GPIO_InitStructure);
+}
+
+/**
+ * @brief Initializes the SD Card and put it into StandBy State (Ready for
+ * data transfer).
+ * @param None
+ * @retval None
+ */
+void SD_LowLevel_Init(void)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+ SPI_InitTypeDef SPI_InitStructure;
+
+ /*!< SD_SPI_CS_GPIO, SD_SPI_MOSI_GPIO, SD_SPI_MISO_GPIO, SD_SPI_DETECT_GPIO
+ and SD_SPI_SCK_GPIO Periph clock enable */
+ RCC_AHBPeriphClockCmd(SD_CS_GPIO_CLK | SD_SPI_MOSI_GPIO_CLK | SD_SPI_MISO_GPIO_CLK |
+ SD_SPI_SCK_GPIO_CLK | SD_DETECT_GPIO_CLK, ENABLE);
+
+ /*!< SD_SPI Periph clock enable */
+ RCC_APB1PeriphClockCmd(SD_SPI_CLK, ENABLE);
+
+ /*!< Configure SD_SPI pins: SCK */
+ GPIO_InitStructure.GPIO_Pin = SD_SPI_SCK_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
+ GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
+ GPIO_Init(SD_SPI_SCK_GPIO_PORT, &GPIO_InitStructure);
+
+ /*!< Configure SD_SPI pins: MISO */
+ GPIO_InitStructure.GPIO_Pin = SD_SPI_MISO_PIN;
+ GPIO_Init(SD_SPI_MISO_GPIO_PORT, &GPIO_InitStructure);
+
+ /*!< Configure SD_SPI pins: MOSI */
+ GPIO_InitStructure.GPIO_Pin = SD_SPI_MOSI_PIN;
+ GPIO_Init(SD_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure);
+
+ /*!< Configure SD_SPI_CS_PIN pin: SD Card CS pin */
+ GPIO_InitStructure.GPIO_Pin = SD_CS_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
+ GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
+ GPIO_Init(SD_CS_GPIO_PORT, &GPIO_InitStructure);
+
+ /*!< Configure SD_SPI_DETECT_PIN pin: SD Card detect pin */
+ GPIO_InitStructure.GPIO_Pin = SD_DETECT_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
+ GPIO_Init(SD_DETECT_GPIO_PORT, &GPIO_InitStructure);
+
+ /* Connect PXx to SD_SPI_SCK */
+ GPIO_PinAFConfig(SD_SPI_SCK_GPIO_PORT, SD_SPI_SCK_SOURCE, SD_SPI_SCK_AF);
+
+ /* Connect PXx to SD_SPI_MISO */
+ GPIO_PinAFConfig(SD_SPI_MISO_GPIO_PORT, SD_SPI_MISO_SOURCE, SD_SPI_MISO_AF);
+
+ /* Connect PXx to SD_SPI_MOSI */
+ GPIO_PinAFConfig(SD_SPI_MOSI_GPIO_PORT, SD_SPI_MOSI_SOURCE, SD_SPI_MOSI_AF);
+
+ /*!< SD_SPI Config */
+ SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
+ SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
+ SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
+ SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;
+ SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
+ SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
+ SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2;
+
+ SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
+ SPI_InitStructure.SPI_CRCPolynomial = 7;
+ SPI_Init(SD_SPI, &SPI_InitStructure);
+
+ SPI_Cmd(SD_SPI, ENABLE); /*!< SD_SPI enable */
+}
+
+/**
+ * @brief DeInitializes the LM75_I2C.
+ * @param None
+ * @retval None
+ */
+void LM75_LowLevel_DeInit(void)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+
+ /*!< Disable LM75_I2C */
+ I2C_Cmd(LM75_I2C, DISABLE);
+
+ /*!< DeInitializes the LM75_I2C */
+ I2C_DeInit(LM75_I2C);
+
+ /*!< LM75_I2C Periph clock disable */
+ RCC_APB1PeriphClockCmd(LM75_I2C_CLK, DISABLE);
+
+ /*!< Configure LM75_I2C pins: SCL */
+ GPIO_InitStructure.GPIO_Pin = LM75_I2C_SCL_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
+ GPIO_Init(LM75_I2C_SCL_GPIO_PORT, &GPIO_InitStructure);
+
+ /*!< Configure LM75_I2C pins: SDA */
+ GPIO_InitStructure.GPIO_Pin = LM75_I2C_SDA_PIN;
+ GPIO_Init(LM75_I2C_SDA_GPIO_PORT, &GPIO_InitStructure);
+
+ /*!< Configure LM75_I2C pin: SMBUS ALERT */
+ GPIO_InitStructure.GPIO_Pin = LM75_I2C_SMBUSALERT_PIN;
+ GPIO_Init(LM75_I2C_SMBUSALERT_GPIO_PORT, &GPIO_InitStructure);
+}
+
+/**
+ * @brief Initializes the LM75_I2C.
+ * @param None
+ * @retval None
+ */
+void LM75_LowLevel_Init(void)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+
+ /*!< LM75_I2C Periph clock enable */
+ RCC_APB1PeriphClockCmd(LM75_I2C_CLK, ENABLE);
+
+ /*!< LM75_I2C_SCL_GPIO_CLK, LM75_I2C_SDA_GPIO_CLK
+ and LM75_I2C_SMBUSALERT_GPIO_CLK Periph clock enable */
+ RCC_AHBPeriphClockCmd(LM75_I2C_SCL_GPIO_CLK | LM75_I2C_SDA_GPIO_CLK |
+ LM75_I2C_SMBUSALERT_GPIO_CLK, ENABLE);
+
+ /* Connect PXx to I2C_SCL */
+ GPIO_PinAFConfig(LM75_I2C_SCL_GPIO_PORT, LM75_I2C_SCL_SOURCE, LM75_I2C_SCL_AF);
+
+ /* Connect PXx to I2C_SDA */
+ GPIO_PinAFConfig(LM75_I2C_SDA_GPIO_PORT, LM75_I2C_SDA_SOURCE, LM75_I2C_SDA_AF);
+
+ /* Connect PXx to I2C_SMBUSALER */
+ GPIO_PinAFConfig(LM75_I2C_SMBUSALERT_GPIO_PORT, LM75_I2C_SMBUSALERT_SOURCE, LM75_I2C_SMBUSALERT_AF);
+
+ /*!< Configure LM75_I2C pins: SCL */
+ GPIO_InitStructure.GPIO_Pin = LM75_I2C_SCL_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
+ GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
+ GPIO_Init(LM75_I2C_SCL_GPIO_PORT, &GPIO_InitStructure);
+
+ /*!< Configure LM75_I2C pins: SDA */
+ GPIO_InitStructure.GPIO_Pin = LM75_I2C_SDA_PIN;
+ GPIO_Init(LM75_I2C_SDA_GPIO_PORT, &GPIO_InitStructure);
+
+ /*!< Configure LM75_I2C pin: SMBUS ALERT */
+ GPIO_InitStructure.GPIO_Pin = LM75_I2C_SMBUSALERT_PIN;
+ GPIO_Init(LM75_I2C_SMBUSALERT_GPIO_PORT, &GPIO_InitStructure);
+}
+
+/**
+ * @brief DeInitializes peripherals used by the I2C EEPROM driver.
+ * @param None
+ * @retval None
+ */
+void sEE_LowLevel_DeInit(void)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+ NVIC_InitTypeDef NVIC_InitStructure;
+
+ /* sEE_I2C Peripheral Disable */
+ I2C_Cmd(sEE_I2C, DISABLE);
+
+ /* sEE_I2C DeInit */
+ I2C_DeInit(sEE_I2C);
+
+ /*!< sEE_I2C Periph clock disable */
+ RCC_APB1PeriphClockCmd(sEE_I2C_CLK, DISABLE);
+
+ /*!< GPIO configuration */
+ /*!< Configure sEE_I2C pins: SCL */
+ GPIO_InitStructure.GPIO_Pin = sEE_I2C_SCL_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
+ GPIO_Init(sEE_I2C_SCL_GPIO_PORT, &GPIO_InitStructure);
+
+ /*!< Configure sEE_I2C pins: SDA */
+ GPIO_InitStructure.GPIO_Pin = sEE_I2C_SDA_PIN;
+ GPIO_Init(sEE_I2C_SDA_GPIO_PORT, &GPIO_InitStructure);
+
+ /* Configure and enable I2C DMA TX Channel interrupt */
+ NVIC_InitStructure.NVIC_IRQChannel = sEE_I2C_DMA_TX_IRQn;
+ NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = sEE_I2C_DMA_PREPRIO;
+ NVIC_InitStructure.NVIC_IRQChannelSubPriority = sEE_I2C_DMA_SUBPRIO;
+ NVIC_InitStructure.NVIC_IRQChannelCmd = DISABLE;
+ NVIC_Init(&NVIC_InitStructure);
+
+ /* Configure and enable I2C DMA RX Channel interrupt */
+ NVIC_InitStructure.NVIC_IRQChannel = sEE_I2C_DMA_RX_IRQn;
+ NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = sEE_I2C_DMA_PREPRIO;
+ NVIC_InitStructure.NVIC_IRQChannelSubPriority = sEE_I2C_DMA_SUBPRIO;
+ NVIC_Init(&NVIC_InitStructure);
+
+ /* Disable and Deinitialize the DMA channels */
+ DMA_Cmd(sEE_I2C_DMA_CHANNEL_TX, DISABLE);
+ DMA_Cmd(sEE_I2C_DMA_CHANNEL_RX, DISABLE);
+ DMA_DeInit(sEE_I2C_DMA_CHANNEL_TX);
+ DMA_DeInit(sEE_I2C_DMA_CHANNEL_RX);
+}
+
+/**
+ * @brief Initializes peripherals used by the I2C EEPROM driver.
+ * @param None
+ * @retval None
+ */
+void sEE_LowLevel_Init(void)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+ NVIC_InitTypeDef NVIC_InitStructure;
+
+ /*!< sEE_I2C Periph clock enable */
+ RCC_APB1PeriphClockCmd(sEE_I2C_CLK, ENABLE);
+
+ /*!< sEE_I2C_SCL_GPIO_CLK and sEE_I2C_SDA_GPIO_CLK Periph clock enable */
+ RCC_AHBPeriphClockCmd(sEE_I2C_SCL_GPIO_CLK | sEE_I2C_SDA_GPIO_CLK, ENABLE);
+
+ RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
+
+ /* Reset sEE_I2C peripheral */
+ RCC_APB1PeriphResetCmd(sEE_I2C_CLK, ENABLE);
+
+ /* Release reset signal of sEE_I2C IP */
+ RCC_APB1PeriphResetCmd(sEE_I2C_CLK, DISABLE);
+
+ /*!< GPIO configuration */
+ /* Connect PXx to I2C_SCL*/
+ GPIO_PinAFConfig(sEE_I2C_SCL_GPIO_PORT, sEE_I2C_SCL_SOURCE, sEE_I2C_SCL_AF);
+
+ /* Connect PXx to I2C_SDA*/
+ GPIO_PinAFConfig(sEE_I2C_SDA_GPIO_PORT, sEE_I2C_SDA_SOURCE, sEE_I2C_SDA_AF);
+
+ /*!< Configure sEE_I2C pins: SCL */
+ GPIO_InitStructure.GPIO_Pin = sEE_I2C_SCL_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
+ GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
+ GPIO_Init(sEE_I2C_SCL_GPIO_PORT, &GPIO_InitStructure);
+
+ /*!< Configure sEE_I2C pins: SDA */
+ GPIO_InitStructure.GPIO_Pin = sEE_I2C_SDA_PIN;
+ GPIO_Init(sEE_I2C_SDA_GPIO_PORT, &GPIO_InitStructure);
+
+
+ /* Configure and enable I2C DMA TX Channel interrupt */
+ NVIC_InitStructure.NVIC_IRQChannel = sEE_I2C_DMA_TX_IRQn;
+ NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = sEE_I2C_DMA_PREPRIO;
+ NVIC_InitStructure.NVIC_IRQChannelSubPriority = sEE_I2C_DMA_SUBPRIO;
+ NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
+ NVIC_Init(&NVIC_InitStructure);
+
+ /* Configure and enable I2C DMA RX Channel interrupt */
+ NVIC_InitStructure.NVIC_IRQChannel = sEE_I2C_DMA_RX_IRQn;
+ NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = sEE_I2C_DMA_PREPRIO;
+ NVIC_InitStructure.NVIC_IRQChannelSubPriority = sEE_I2C_DMA_SUBPRIO;
+ NVIC_Init(&NVIC_InitStructure);
+
+ /*!< I2C DMA TX and RX channels configuration */
+ /* Enable the DMA clock */
+ RCC_AHBPeriphClockCmd(sEE_I2C_DMA_CLK, ENABLE);
+
+ /* I2C TX DMA Channel configuration */
+ DMA_DeInit(sEE_I2C_DMA_CHANNEL_TX);
+ sEEDMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)sEE_I2C_DR_Address;
+ sEEDMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)0; /* This parameter will be configured durig communication */
+ sEEDMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST; /* This parameter will be configured durig communication */
+ sEEDMA_InitStructure.DMA_BufferSize = 0xFFFF; /* This parameter will be configured durig communication */
+ sEEDMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
+ sEEDMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
+ sEEDMA_InitStructure.DMA_PeripheralDataSize = DMA_MemoryDataSize_Byte;
+ sEEDMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
+ sEEDMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
+ sEEDMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh;
+ sEEDMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
+ DMA_Init(sEE_I2C_DMA_CHANNEL_TX, &sEEDMA_InitStructure);
+
+ /* I2C RX DMA Channel configuration */
+ DMA_DeInit(sEE_I2C_DMA_CHANNEL_RX);
+ DMA_Init(sEE_I2C_DMA_CHANNEL_RX, &sEEDMA_InitStructure);
+
+ /* Enable the DMA Channels Interrupts */
+ DMA_ITConfig(sEE_I2C_DMA_CHANNEL_TX, DMA_IT_TC, ENABLE);
+ DMA_ITConfig(sEE_I2C_DMA_CHANNEL_RX, DMA_IT_TC, ENABLE);
+}
+
+/**
+ * @brief Initializes DMA channel used by the I2C EEPROM driver.
+ * @param None
+ * @retval None
+ */
+void sEE_LowLevel_DMAConfig(uint32_t pBuffer, uint32_t BufferSize, uint32_t Direction)
+{
+ /* Initialize the DMA with the new parameters */
+ if (Direction == sEE_DIRECTION_TX)
+ {
+ /* Configure the DMA Tx Channel with the buffer address and the buffer size */
+ sEEDMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)pBuffer;
+ sEEDMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
+ sEEDMA_InitStructure.DMA_BufferSize = (uint32_t)BufferSize;
+ DMA_Init(sEE_I2C_DMA_CHANNEL_TX, &sEEDMA_InitStructure);
+ }
+ else
+ {
+ /* Configure the DMA Rx Channel with the buffer address and the buffer size */
+ sEEDMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)pBuffer;
+ sEEDMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
+ sEEDMA_InitStructure.DMA_BufferSize = (uint32_t)BufferSize;
+ DMA_Init(sEE_I2C_DMA_CHANNEL_RX, &sEEDMA_InitStructure);
+ }
+}
+
+/**
+ * @}
+ */
+
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152_EVAL/stm32l152_eval.h b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152_EVAL/stm32l152_eval.h
new file mode 100644
index 0000000..9bdef11
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152_EVAL/stm32l152_eval.h
@@ -0,0 +1,457 @@
+/**
+ ******************************************************************************
+ * @file stm32l152_eval.h
+ * @author MCD Application Team
+ * @version V5.0.2
+ * @date 09-March-2012
+ * @brief This file contains definitions for STM32L152_EVAL's Leds, push-buttons
+ * and COM ports hardware resources.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.st.com/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __STM32L152_EVAL_H
+#define __STM32L152_EVAL_H
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+/* Includes ------------------------------------------------------------------*/
+#include "stm32l1xx.h"
+#include "stm32_eval_legacy.h"
+
+/** @addtogroup Utilities
+ * @{
+ */
+
+/** @addtogroup STM32_EVAL
+ * @{
+ */
+
+/** @addtogroup STM32L152_EVAL
+ * @{
+ */
+
+/** @addtogroup STM32L152_EVAL_LOW_LEVEL
+ * @{
+ */
+
+/** @defgroup STM32L152_EVAL_LOW_LEVEL_Exported_Types
+ * @{
+ */
+typedef enum
+{
+ LED1 = 0,
+ LED2 = 1,
+ LED3 = 2,
+ LED4 = 3
+} Led_TypeDef;
+
+typedef enum
+{
+ BUTTON_KEY = 0,
+ BUTTON_RIGHT = 1,
+ BUTTON_LEFT = 2,
+ BUTTON_UP = 3,
+ BUTTON_DOWN = 4,
+ BUTTON_SEL = 5
+} Button_TypeDef;
+
+typedef enum
+{
+ BUTTON_MODE_GPIO = 0,
+ BUTTON_MODE_EXTI = 1
+} ButtonMode_TypeDef;
+
+typedef enum
+{
+ JOY_NONE = 0,
+ JOY_SEL = 1,
+ JOY_DOWN = 2,
+ JOY_LEFT = 3,
+ JOY_RIGHT = 4,
+ JOY_UP = 5
+} JOYState_TypeDef
+;
+
+typedef enum
+{
+ COM1 = 0,
+ COM2 = 1
+} COM_TypeDef;
+/**
+ * @}
+ */
+
+/** @defgroup STM32L152_EVAL_LOW_LEVEL_Exported_Constants
+ * @{
+ */
+
+/**
+ * @brief Define for STM32L152_EVAL board
+ */
+#if !defined (USE_STM32L152_EVAL)
+ #define USE_STM32L152_EVAL
+#endif
+
+/** @addtogroup STM32L152_EVAL_LOW_LEVEL_LED
+ * @{
+ */
+#define LEDn 4
+
+#define LED1_PIN GPIO_Pin_0
+#define LED1_GPIO_PORT GPIOD
+#define LED1_GPIO_CLK RCC_AHBPeriph_GPIOD
+
+#define LED2_PIN GPIO_Pin_1
+#define LED2_GPIO_PORT GPIOD
+#define LED2_GPIO_CLK RCC_AHBPeriph_GPIOD
+
+#define LED3_PIN GPIO_Pin_4
+#define LED3_GPIO_PORT GPIOD
+#define LED3_GPIO_CLK RCC_AHBPeriph_GPIOD
+
+#define LED4_PIN GPIO_Pin_5
+#define LED4_GPIO_PORT GPIOD
+#define LED4_GPIO_CLK RCC_AHBPeriph_GPIOD
+
+/**
+ * @}
+ */
+
+/** @addtogroup STM32L152_EVAL_LOW_LEVEL_BUTTON
+ * @{
+ */
+#define BUTTONn 6
+/* On STM32L152-EVAL board, the KEY button is connected to PA.00 and it can
+ be use as Wakeup pin button. */
+
+/**
+ * @brief Key push-button
+ */
+#define KEY_BUTTON_PIN GPIO_Pin_0
+#define KEY_BUTTON_GPIO_PORT GPIOA
+#define KEY_BUTTON_GPIO_CLK RCC_AHBPeriph_GPIOA
+#define KEY_BUTTON_EXTI_LINE EXTI_Line0
+#define KEY_BUTTON_EXTI_PORT_SOURCE EXTI_PortSourceGPIOA
+#define KEY_BUTTON_EXTI_PIN_SOURCE EXTI_PinSource0
+#define KEY_BUTTON_EXTI_IRQn EXTI0_IRQn
+
+/**
+ * @brief Joystick Right push-button
+ */
+#define RIGHT_BUTTON_PIN GPIO_Pin_11
+#define RIGHT_BUTTON_GPIO_PORT GPIOE
+#define RIGHT_BUTTON_GPIO_CLK RCC_AHBPeriph_GPIOE
+#define RIGHT_BUTTON_EXTI_LINE EXTI_Line11
+#define RIGHT_BUTTON_EXTI_PORT_SOURCE EXTI_PortSourceGPIOE
+#define RIGHT_BUTTON_EXTI_PIN_SOURCE EXTI_PinSource11
+#define RIGHT_BUTTON_EXTI_IRQn EXTI15_10_IRQn
+
+/**
+ * @brief Joystick Left push-button
+ */
+#define LEFT_BUTTON_PIN GPIO_Pin_12
+#define LEFT_BUTTON_GPIO_PORT GPIOE
+#define LEFT_BUTTON_GPIO_CLK RCC_AHBPeriph_GPIOE
+#define LEFT_BUTTON_EXTI_LINE EXTI_Line12
+#define LEFT_BUTTON_EXTI_PORT_SOURCE EXTI_PortSourceGPIOE
+#define LEFT_BUTTON_EXTI_PIN_SOURCE EXTI_PinSource12
+#define LEFT_BUTTON_EXTI_IRQn EXTI15_10_IRQn
+
+/**
+ * @brief Joystick Up push-button
+ */
+#define UP_BUTTON_PIN GPIO_Pin_9
+#define UP_BUTTON_GPIO_PORT GPIOE
+#define UP_BUTTON_GPIO_CLK RCC_AHBPeriph_GPIOE
+#define UP_BUTTON_EXTI_LINE EXTI_Line9
+#define UP_BUTTON_EXTI_PORT_SOURCE EXTI_PortSourceGPIOE
+#define UP_BUTTON_EXTI_PIN_SOURCE EXTI_PinSource9
+#define UP_BUTTON_EXTI_IRQn EXTI9_5_IRQn
+
+/**
+ * @brief Joystick Down push-button
+ */
+#define DOWN_BUTTON_PIN GPIO_Pin_10
+#define DOWN_BUTTON_GPIO_PORT GPIOE
+#define DOWN_BUTTON_GPIO_CLK RCC_AHBPeriph_GPIOE
+#define DOWN_BUTTON_EXTI_LINE EXTI_Line10
+#define DOWN_BUTTON_EXTI_PORT_SOURCE EXTI_PortSourceGPIOE
+#define DOWN_BUTTON_EXTI_PIN_SOURCE EXTI_PinSource10
+#define DOWN_BUTTON_EXTI_IRQn EXTI15_10_IRQn
+
+/**
+ * @brief Joystick Sel push-button
+ */
+#define SEL_BUTTON_PIN GPIO_Pin_8
+#define SEL_BUTTON_GPIO_PORT GPIOE
+#define SEL_BUTTON_GPIO_CLK RCC_AHBPeriph_GPIOE
+#define SEL_BUTTON_EXTI_LINE EXTI_Line8
+#define SEL_BUTTON_EXTI_PORT_SOURCE EXTI_PortSourceGPIOE
+#define SEL_BUTTON_EXTI_PIN_SOURCE EXTI_PinSource8
+#define SEL_BUTTON_EXTI_IRQn EXTI9_5_IRQn
+
+/**
+ * @}
+ */
+
+/** @addtogroup STM32L152_EVAL_LOW_LEVEL_COM
+ * @{
+ */
+#define COMn 2
+
+/**
+ * @brief Definition for COM port1, connected to USART2
+ */
+#define EVAL_COM1 USART2
+#define EVAL_COM1_CLK RCC_APB1Periph_USART2
+
+#define EVAL_COM1_TX_PIN GPIO_Pin_5
+#define EVAL_COM1_TX_GPIO_PORT GPIOD
+#define EVAL_COM1_TX_GPIO_CLK RCC_AHBPeriph_GPIOD
+#define EVAL_COM1_TX_SOURCE GPIO_PinSource5
+#define EVAL_COM1_TX_AF GPIO_AF_USART2
+
+#define EVAL_COM1_RX_PIN GPIO_Pin_6
+#define EVAL_COM1_RX_GPIO_PORT GPIOD
+#define EVAL_COM1_RX_GPIO_CLK RCC_AHBPeriph_GPIOD
+#define EVAL_COM1_RX_SOURCE GPIO_PinSource6
+#define EVAL_COM1_RX_AF GPIO_AF_USART2
+
+#define EVAL_COM1_RTS_PIN GPIO_Pin_4
+#define EVAL_COM1_RTS_GPIO_PORT GPIOD
+#define EVAL_COM1_RTS_GPIO_CLK RCC_AHBPeriph_GPIOD
+#define EVAL_COM1_RTS_SOURCE GPIO_PinSource4
+#define EVAL_COM1_RTS_AF GPIO_AF_USART2
+
+#define EVAL_COM1_CTS_PIN GPIO_Pin_3
+#define EVAL_COM1_CTS_GPIO_PORT GPIOD
+#define EVAL_COM1_CTS_GPIO_CLK RCC_AHBPeriph_GPIOD
+#define EVAL_COM1_CTS_SOURCE GPIO_PinSource3
+#define EVAL_COM1_CTS_AF GPIO_AF_USART2
+
+#define EVAL_COM1_IRQn USART2_IRQn
+
+/**
+ * @brief Definition for COM port2, connected to USART3
+ */
+#define EVAL_COM2 USART3
+#define EVAL_COM2_CLK RCC_APB1Periph_USART3
+
+#define EVAL_COM2_TX_PIN GPIO_Pin_10
+#define EVAL_COM2_TX_GPIO_PORT GPIOC
+#define EVAL_COM2_TX_GPIO_CLK RCC_AHBPeriph_GPIOC
+#define EVAL_COM2_TX_SOURCE GPIO_PinSource10
+#define EVAL_COM2_TX_AF GPIO_AF_USART3
+
+#define EVAL_COM2_RX_PIN GPIO_Pin_11
+#define EVAL_COM2_RX_GPIO_PORT GPIOC
+#define EVAL_COM2_RX_GPIO_CLK RCC_AHBPeriph_GPIOC
+#define EVAL_COM2_RX_SOURCE GPIO_PinSource11
+#define EVAL_COM2_RX_AF GPIO_AF_USART3
+
+#define EVAL_COM2_IRQn USART3_IRQn
+
+/**
+ * @}
+ */
+
+/** @addtogroup STM32L152_EVAL_LOW_LEVEL_SD_FLASH
+ * @{
+ */
+/**
+ * @brief SD Card SPI Interface
+ */
+#define SD_SPI SPI2
+#define SD_SPI_CLK RCC_APB1Periph_SPI2
+#define SD_SPI_SCK_PIN GPIO_Pin_13 /* PB.13 */
+#define SD_SPI_SCK_GPIO_PORT GPIOB /* GPIOB */
+#define SD_SPI_SCK_GPIO_CLK RCC_AHBPeriph_GPIOB
+#define SD_SPI_SCK_SOURCE GPIO_PinSource13
+#define SD_SPI_SCK_AF GPIO_AF_SPI2
+#define SD_SPI_MISO_PIN GPIO_Pin_14 /* PB.14 */
+#define SD_SPI_MISO_GPIO_PORT GPIOB /* GPIOB */
+#define SD_SPI_MISO_GPIO_CLK RCC_AHBPeriph_GPIOB
+#define SD_SPI_MISO_SOURCE GPIO_PinSource14
+#define SD_SPI_MISO_AF GPIO_AF_SPI2
+#define SD_SPI_MOSI_PIN GPIO_Pin_15 /* PB.15 */
+#define SD_SPI_MOSI_GPIO_PORT GPIOB /* GPIOB */
+#define SD_SPI_MOSI_GPIO_CLK RCC_AHBPeriph_GPIOB
+#define SD_SPI_MOSI_SOURCE GPIO_PinSource15
+#define SD_SPI_MOSI_AF GPIO_AF_SPI2
+#define SD_CS_PIN GPIO_Pin_7 /* PD.07 */
+#define SD_CS_GPIO_PORT GPIOD /* GPIOD */
+#define SD_CS_GPIO_CLK RCC_AHBPeriph_GPIOD
+#define SD_DETECT_PIN GPIO_Pin_6 /* PE.06 */
+#define SD_DETECT_EXTI_LINE EXTI_Line6
+#define SD_DETECT_EXTI_PIN_SOURCE EXTI_PinSource6
+
+#define SD_DETECT_GPIO_PORT GPIOE /* GPIOE */
+#define SD_DETECT_GPIO_CLK RCC_AHBPeriph_GPIOE
+#define SD_DETECT_EXTI_PORT_SOURCE EXTI_PortSourceGPIOE
+#define SD_DETECT_EXTI_IRQn EXTI9_5_IRQn
+/**
+ * @}
+ */
+
+/** @addtogroup STM32L152_EVAL_LOW_LEVEL_TSENSOR_I2C
+ * @{
+ */
+/**
+ * @brief LM75 Temperature Sensor I2C Interface pins
+ */
+#define LM75_I2C I2C1
+#define LM75_I2C_CLK RCC_APB1Periph_I2C1
+#define LM75_I2C_SCL_PIN GPIO_Pin_6 /* PB.06 */
+#define LM75_I2C_SCL_GPIO_PORT GPIOB /* GPIOB */
+#define LM75_I2C_SCL_GPIO_CLK RCC_AHBPeriph_GPIOB
+#define LM75_I2C_SCL_SOURCE GPIO_PinSource6
+#define LM75_I2C_SCL_AF GPIO_AF_I2C1
+#define LM75_I2C_SDA_PIN GPIO_Pin_7 /* PB.07 */
+#define LM75_I2C_SDA_GPIO_PORT GPIOB /* GPIOB */
+#define LM75_I2C_SDA_GPIO_CLK RCC_AHBPeriph_GPIOB
+#define LM75_I2C_SDA_SOURCE GPIO_PinSource7
+#define LM75_I2C_SDA_AF GPIO_AF_I2C1
+#define LM75_I2C_SMBUSALERT_PIN GPIO_Pin_5 /* PB.05 */
+#define LM75_I2C_SMBUSALERT_GPIO_PORT GPIOB /* GPIOB */
+#define LM75_I2C_SMBUSALERT_GPIO_CLK RCC_AHBPeriph_GPIOB
+#define LM75_I2C_SMBUSALERT_SOURCE GPIO_PinSource5
+#define LM75_I2C_SMBUSALERT_AF GPIO_AF_I2C1
+#define LM75_I2C_DR ((uint32_t)0x40005410)
+
+#define LM75_DMA_CLK RCC_AHBPeriph_DMA1
+#define LM75_DMA_TX_CHANNEL DMA1_Channel6
+#define LM75_DMA_RX_CHANNEL DMA1_Channel7
+#define LM75_DMA_TX_TCFLAG DMA1_FLAG_TC6
+#define LM75_DMA_RX_TCFLAG DMA1_FLAG_TC7
+
+/**
+ * @}
+ */
+
+/** @addtogroup STM32L152_EVAL_LOW_LEVEL_I2C_EE
+ * @{
+ */
+/**
+ * @brief I2C EEPROM Interface pins
+ */
+
+#define sEE_I2C I2C1
+#define sEE_I2C_CLK RCC_APB1Periph_I2C1
+#define sEE_I2C_SCL_PIN GPIO_Pin_6 /* PB.06 */
+#define sEE_I2C_SCL_GPIO_PORT GPIOB /* GPIOB */
+#define sEE_I2C_SCL_GPIO_CLK RCC_AHBPeriph_GPIOB
+#define sEE_I2C_SCL_SOURCE GPIO_PinSource6
+#define sEE_I2C_SCL_AF GPIO_AF_I2C1
+#define sEE_I2C_SDA_PIN GPIO_Pin_7 /* PB.07 */
+#define sEE_I2C_SDA_GPIO_PORT GPIOB /* GPIOB */
+#define sEE_I2C_SDA_GPIO_CLK RCC_AHBPeriph_GPIOB
+#define sEE_I2C_SDA_SOURCE GPIO_PinSource7
+#define sEE_I2C_SDA_AF GPIO_AF_I2C1
+#define sEE_M24C64_32
+
+#define sEE_I2C_DMA DMA1
+#define sEE_I2C_DMA_CHANNEL_TX DMA1_Channel6
+#define sEE_I2C_DMA_CHANNEL_RX DMA1_Channel7
+#define sEE_I2C_DMA_FLAG_TX_TC DMA1_IT_TC6
+#define sEE_I2C_DMA_FLAG_TX_GL DMA1_IT_GL6
+#define sEE_I2C_DMA_FLAG_RX_TC DMA1_IT_TC7
+#define sEE_I2C_DMA_FLAG_RX_GL DMA1_IT_GL7
+#define sEE_I2C_DMA_CLK RCC_AHBPeriph_DMA1
+#define sEE_I2C_DR_Address ((uint32_t)0x40005410)
+#define sEE_USE_DMA
+
+#define sEE_I2C_DMA_TX_IRQn DMA1_Channel6_IRQn
+#define sEE_I2C_DMA_RX_IRQn DMA1_Channel7_IRQn
+#define sEE_I2C_DMA_TX_IRQHandler DMA1_Channel6_IRQHandler
+#define sEE_I2C_DMA_RX_IRQHandler DMA1_Channel7_IRQHandler
+#define sEE_I2C_DMA_PREPRIO 0
+#define sEE_I2C_DMA_SUBPRIO 0
+
+#define sEE_DIRECTION_TX 0
+#define sEE_DIRECTION_RX 1
+
+/* Time constant for the delay caclulation allowing to have a millisecond
+ incrementing counter. This value should be equal to (System Clock / 1000).
+ ie. if system clock = 32MHz then sEE_TIME_CONST should be 32. */
+#define sEE_TIME_CONST 32
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/** @defgroup STM32L152_EVAL_LOW_LEVEL_Exported_Macros
+ * @{
+ */
+/**
+ * @}
+ */
+
+
+/** @defgroup STM32L152_EVAL_LOW_LEVEL_Exported_Functions
+ * @{
+ */
+void STM_EVAL_LEDInit(Led_TypeDef Led);
+void STM_EVAL_LEDOn(Led_TypeDef Led);
+void STM_EVAL_LEDOff(Led_TypeDef Led);
+void STM_EVAL_LEDToggle(Led_TypeDef Led);
+void STM_EVAL_PBInit(Button_TypeDef Button, ButtonMode_TypeDef Button_Mode);
+uint32_t STM_EVAL_PBGetState(Button_TypeDef Button);
+void STM_EVAL_COMInit(COM_TypeDef COM, USART_InitTypeDef* USART_InitStruct);
+void SD_LowLevel_DeInit(void);
+void SD_LowLevel_Init(void);
+void LM75_LowLevel_DeInit(void);
+void LM75_LowLevel_Init(void);
+void sEE_LowLevel_DeInit(void);
+void sEE_LowLevel_Init(void);
+void sEE_LowLevel_DMAConfig(uint32_t pBuffer, uint32_t BufferSize, uint32_t Direction);
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __STM32L152_EVAL_H */
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152_EVAL/stm32l152_eval_glass_lcd.c b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152_EVAL/stm32l152_eval_glass_lcd.c
new file mode 100644
index 0000000..5a80c56
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152_EVAL/stm32l152_eval_glass_lcd.c
@@ -0,0 +1,861 @@
+/**
+ ******************************************************************************
+ * @file stm32l152_eval_glass_lcd.c
+ * @author MCD Application Team
+ * @version V5.0.2
+ * @date 09-March-2012
+ * @brief This file includes the LCD Glass driver for Pacific Display
+ * (LCD_PD878, PD878-DP-FH-W-LV-6-RH) Module of STM32L152-EVAL board RevB.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.st.com/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+
+/* Includes ------------------------------------------------------------------*/
+#include "stm32l152_eval_glass_lcd.h"
+
+/** @addtogroup Utilities
+ * @{
+ */
+
+/** @addtogroup STM32_EVAL
+ * @{
+ */
+
+/** @addtogroup STM32L152_EVAL
+ * @{
+ */
+
+/** @defgroup STM32L152_EVAL_GLASS_LCD
+ * @brief This file includes the LCD Glass driver for Pacific Display
+ * (LCD_PD878, PD878-DP-FH-W-LV-6-RH) Module of STM32L152-EVAL board.
+ * @{
+ */
+
+/** @defgroup STM32L152_EVAL_GLASS_LCD_Private_Types
+ * @{
+ */
+/**
+ * @}
+ */
+
+
+/** @defgroup STM32L152_EVAL_GLASS_LCD_Private_Defines
+ * @{
+ */
+/**
+ * @}
+ */
+
+
+/** @defgroup STM32L152_EVAL_GLASS_LCD_Private_Macros
+ * @{
+ */
+/**
+ * @}
+ */
+
+
+/** @defgroup STM32L152_EVAL_GLASS_LCD_Private_Variables
+ * @{
+ */
+
+/**
+ @verbatim
+================================================================================
+ GLASS LCD MAPPING
+================================================================================
+ A
+ -- ----------
+ X \/ |\ |I /|
+ F| H | J |B
+ | \ | / |
+ --G-- --K--
+ | /| \ |
+ E | L | N |C
+ | / |M \| _
+ ----------- | |DP
+ D -
+
+A LCD character coding is based on the following matrix:
+
+
+{ X , F , E , D }
+{ I , J , K , N }
+{ A , B , C , DP }
+{ H , G , L , M }
+
+The character A for example is:
+-------------------------------
+ { 0 , 1 , 1 , 0 }
+ { 0 , 0 , 1 , 0 }
+ { 1 , 1 , 1 , 0 }
+ { 0 , 1 , 0 , 0 }
+-------------------
+= 4 D 7 0 hex
+
+=> 'A' = 0x4D70
+
+ @endverbatim
+ */
+
+/**
+ * @brief LETTERS AND NUMBERS MAPPING DEFINITION
+ */
+uint8_t digit[4]; /* Digit LCD RAM buffer */
+__I uint16_t mask[4] = {0xF000, 0x0F00, 0x00F0, 0x000F};
+__I uint8_t shift[4] = {0x0C, 0x08, 0x04, 0x00};
+
+/* Letters and number map of PD_878 LCD */
+__I uint16_t LetterMap[26]=
+{
+/* A B C D E F G H I */
+0x4D70, 0x6469, 0x4111, 0x6449, 0x4911, 0x4910, 0x4171, 0x0D70, 0x6009,
+/* J K L M N O P Q R */
+0x0451, 0x0B12, 0x0111, 0x8750, 0x8552, 0x4551, 0x4D30, 0x4553, 0x4D32,
+/* S T U V W X Y Z */
+0x4961, 0x6008, 0x0551, 0x0390, 0x05D2, 0x8282, 0x8208, 0x4281
+};
+
+__I uint16_t NumberMap[10]=
+{
+/* 0 1 2 3 4 5 6 7 8 9 */
+0x47D1, 0x0640, 0x4C31, 0x4C61, 0x0D60, 0x4961, 0x4971, 0x4440, 0x4D71, 0x4D61
+};
+
+/**
+ * @}
+ */
+
+
+/** @defgroup STM32L152_EVAL_LCD_Private_Function_Prototypes
+ * @{
+ */
+static void Convert(uint8_t* c, Point_Typedef point, Apostrophe_Typedef apostrophe);
+static void delay(__IO uint32_t nCount);
+static void LCD_GPIOConfig(void);
+
+/**
+ * @}
+ */
+
+/** @defgroup STM32L152_EVAL_LCD_Private_Functions
+ * @{
+ */
+
+/**
+ * @brief Configures the LCD GLASS relative GPIO port IOs and LCD peripheral.
+ * @param None
+ * @retval None
+ */
+void LCD_GLASS_Init(void)
+{
+ LCD_InitTypeDef LCD_InitStructure;
+
+ LCD_GPIOConfig(); /*!< Configure the LCD Glass GPIO pins */
+
+ /*!< Configure the LCD interface -------------------------------------------*/
+ RCC_APB1PeriphClockCmd(RCC_APB1Periph_LCD, ENABLE); /*!< Enable LCD APB1 Clock */
+
+ LCD_InitStructure.LCD_Prescaler = LCD_Prescaler_8;
+ LCD_InitStructure.LCD_Divider = LCD_Divider_16;
+ LCD_InitStructure.LCD_Duty = LCD_Duty_1_4;
+ LCD_InitStructure.LCD_Bias = LCD_Bias_1_3;
+ LCD_InitStructure.LCD_VoltageSource = LCD_VoltageSource_Internal;
+ LCD_Init(&LCD_InitStructure);
+
+ /*!< Configure the Pulse On Duration */
+ LCD_PulseOnDurationConfig(LCD_PulseOnDuration_2);
+
+ /*!< Configure the LCD Contrast (3.51V) */
+ LCD_ContrastConfig(LCD_Contrast_Level_7);
+
+ /*!< Wait Until the LCD FCR register is synchronized */
+ LCD_WaitForSynchro();
+
+ /*!< Enable LCD peripheral */
+ LCD_Cmd(ENABLE);
+
+ /*!< Wait Until the LCD is enabled */
+ while(LCD_GetFlagStatus(LCD_FLAG_ENS) == RESET)
+ {
+ }
+ /*!< Wait Until the LCD Booster is ready */
+ while(LCD_GetFlagStatus(LCD_FLAG_RDY) == RESET)
+ {
+ }
+}
+
+/**
+ * @brief This function writes a char in the LCD RAM.
+ * @param ch: The character to dispaly.
+ * @param point: A point to add in front of char.
+ * This parameter can be one of the following values:
+ * @arg POINT_OFF: No point to add in front of char.
+ * @arg POINT_ON: Add a point in front of char.
+ * @param apostrophe: Flag indicating if a apostrophe has to be add in front
+ * of displayed character.
+ * This parameter can be one of the following values:
+ * @arg APOSTROPHE_OFF: No apostrophe to add in back of char.
+ * @arg APOSTROPHE_ON: Add an apostrophe in back of char.
+ * @param position: Position in the LCD of the caracter to write.
+ * This parameter can be any value in range [0:7].
+ * @retval None
+ */
+void LCD_GLASS_DisplayChar(uint8_t* ch, Point_Typedef point, Apostrophe_Typedef apostrophe, uint8_t position)
+{
+ /*!< Wait Until the last LCD RAM update finish */
+ while(LCD_GetFlagStatus(LCD_FLAG_UDR) != RESET)
+ {
+ }
+ /*!< LCD Write Char */
+ LCD_GLASS_WriteChar(ch, point, apostrophe, position);
+
+ /*!< Requesy LCD RAM update */
+ LCD_UpdateDisplayRequest();
+}
+
+/**
+ * @brief This function writes a char in the LCD RAM.
+ * @param ptr: Pointer to string to display on the LCD Glass.
+ * @retval None
+ */
+void LCD_GLASS_DisplayString(uint8_t* ptr)
+{
+ uint8_t i = 0x00;
+
+ /*!< Wait Until the last LCD RAM update finish */
+ while(LCD_GetFlagStatus(LCD_FLAG_UDR) != RESET)
+ {
+ }
+
+ /*!< Send the string character by character on lCD */
+ while ((*ptr != 0) & (i < 8))
+ {
+ /*!< Display one character on LCD */
+ LCD_GLASS_WriteChar(ptr, POINT_OFF, APOSTROPHE_OFF, i);
+ /*!< Point on the next character */
+ ptr++;
+ /*!< Increment the character counter */
+ i++;
+ }
+ /*!< Requesy LCD RAM update */
+ LCD_UpdateDisplayRequest();
+}
+
+/**
+ * @brief This function writes a char in the LCD RAM.
+ * @param ch: The character to dispaly.
+ * @param point: A point to add in front of char.
+ * This parameter can be one of the following values:
+ * @arg POINT_OFF : No point to add in front of char.
+ * @arg POINT_ON : Add a point in front of char.
+ * @param apostrophe: Flag indicating if a apostrophe has to be add in front
+ * of displayed character.
+ * This parameter can be one of the following values:
+ * @arg APOSTROPHE_OFF : No apostrophe to add in back of char.
+ * @arg APOSTROPHE_ON : Add an apostrophe in back of char.
+ * @param position: Position in the LCD of the caracter to write.
+ * This parameter can be any value in range [0:7].
+ * @retval None
+ */
+void LCD_GLASS_WriteChar(uint8_t* ch, Point_Typedef point, Apostrophe_Typedef apostrophe, uint8_t position)
+{
+ uint32_t tmp = 0x00;
+
+ Convert(ch, point, apostrophe); /*!< Convert the corresponding character */
+
+ switch (position)
+ {
+ case 7:
+ /*!< Clear the corresponding segments (SEG0, SEG1, SEG2, SEG3) */
+ LCD->RAM[LCD_RAMRegister_0] &= (uint32_t)(0xFFFFFFF0);
+ LCD->RAM[LCD_RAMRegister_2] &= (uint32_t)(0xFFFFFFF0);
+ LCD->RAM[LCD_RAMRegister_4] &= (uint32_t)(0xFFFFFFF0);
+ LCD->RAM[LCD_RAMRegister_6] &= (uint32_t)(0xFFFFFFF0);
+
+ /*!< Write the corresponding segments (SEG0, SEG1, SEG2, SEG3) */
+ LCD->RAM[LCD_RAMRegister_0] |= (uint32_t)(digit[0]);
+ LCD->RAM[LCD_RAMRegister_2] |= (uint32_t)(digit[1]);
+ LCD->RAM[LCD_RAMRegister_4] |= (uint32_t)(digit[2]);
+ LCD->RAM[LCD_RAMRegister_6] |= (uint32_t)(digit[3]);
+ break;
+
+ case 6:
+ /*!< Clear the corresponding segments (SEG4, SEG5, SEG6, SEG10) */
+ LCD->RAM[LCD_RAMRegister_0] &= (uint32_t)(0xFFFFFB8F);
+ LCD->RAM[LCD_RAMRegister_2] &= (uint32_t)(0xFFFFFB8F);
+ LCD->RAM[LCD_RAMRegister_4] &= (uint32_t)(0xFFFFFB8F);
+ LCD->RAM[LCD_RAMRegister_6] &= (uint32_t)(0xFFFFFB8F);
+
+ /*!< Write the corresponding segments (SEG4, SEG5, SEG6, SEG10) */
+ tmp = (((digit[0] & 0x8) << 7) | ((digit[0]& 0x7) << 4));
+ LCD->RAM[LCD_RAMRegister_0] |= (uint32_t) tmp;
+ tmp = (((digit[1] & 0x8) << 7) | ((digit[1]& 0x7) << 4));
+ LCD->RAM[LCD_RAMRegister_2] |= (uint32_t) tmp;
+ tmp = (((digit[2] & 0x8) << 7) | ((digit[2]& 0x7) << 4));
+ LCD->RAM[LCD_RAMRegister_4] |= (uint32_t) tmp;
+ tmp = (((digit[3] & 0x8) << 7) | ((digit[3]& 0x7) << 4));
+ LCD->RAM[LCD_RAMRegister_6] |= (uint32_t) tmp;
+ break;
+
+ case 5:
+ /*!< Clear the corresponding segments (SEG11, SEG16, SEG18, SEG19) */
+ LCD->RAM[LCD_RAMRegister_0] &= (uint32_t)(0xFFF2F7FF);
+ LCD->RAM[LCD_RAMRegister_2] &= (uint32_t)(0xFFF2F7FF);
+ LCD->RAM[LCD_RAMRegister_4] &= (uint32_t)(0xFFF2F7FF);
+ LCD->RAM[LCD_RAMRegister_6] &= (uint32_t)(0xFFF2F7FF);
+
+ /*!< Write the corresponding segments (SEG11, SEG16, SEG18, SEG19) */
+ tmp = (((digit[0] & 0x1) << 11) | ((digit[0]& 0x2) << 15) | ((digit[0]& 0xC) << 16));
+ LCD->RAM[LCD_RAMRegister_0] |= (uint32_t)(tmp);
+ tmp = (((digit[1] & 0x1) << 11) | ((digit[1]& 0x2) << 15) | ((digit[1]& 0xC) << 16));
+ LCD->RAM[LCD_RAMRegister_2] |= (uint32_t)(tmp);
+ tmp = (((digit[2] & 0x1) << 11) | ((digit[2]& 0x2) << 15) | ((digit[2]& 0xC) << 16));
+ LCD->RAM[LCD_RAMRegister_4] |= (uint32_t)(tmp);
+ tmp = (((digit[3] & 0x1) << 11) | ((digit[3]& 0x2) << 15) | ((digit[3]& 0xC) << 16));
+ LCD->RAM[LCD_RAMRegister_6] |= (uint32_t)(tmp);
+ break;
+
+ case 4:
+ /*!< Clear the corresponding segments (SEG20, SEG21, SEG22, SEG23) */
+ LCD->RAM[LCD_RAMRegister_0] &= (uint32_t)(0xFF0FFFFF);
+ LCD->RAM[LCD_RAMRegister_2] &= (uint32_t)(0xFF0FFFFF);
+ LCD->RAM[LCD_RAMRegister_4] &= (uint32_t)(0xFF0FFFFF);
+ LCD->RAM[LCD_RAMRegister_6] &= (uint32_t)(0xFF0FFFFF);
+
+ /*!< Write the corresponding segments (SEG20, SEG21, SEG22, SEG23) */
+ LCD->RAM[LCD_RAMRegister_0] |= (uint32_t)(digit[0] << 20);
+ LCD->RAM[LCD_RAMRegister_2] |= (uint32_t)(digit[1] << 20);
+ LCD->RAM[LCD_RAMRegister_4] |= (uint32_t)(digit[2] << 20);
+ LCD->RAM[LCD_RAMRegister_6] |= (uint32_t)(digit[3] << 20);
+ break;
+
+ case 3:
+ /*!< Clear the corresponding segments (SEG28, SEG29, SEG30, SEG31) */
+ LCD->RAM[LCD_RAMRegister_0] &= (uint32_t)(0x0FFFFFFF);
+ LCD->RAM[LCD_RAMRegister_2] &= (uint32_t)(0x0FFFFFFF);
+ LCD->RAM[LCD_RAMRegister_4] &= (uint32_t)(0x0FFFFFFF);
+ LCD->RAM[LCD_RAMRegister_6] &= (uint32_t)(0x0FFFFFFF);
+
+ /*!< Write the corresponding segments (SEG28, SEG29, SEG30, SEG31) */
+ LCD->RAM[LCD_RAMRegister_0] |= (uint32_t)(digit[0] << 28);
+ LCD->RAM[LCD_RAMRegister_2] |= (uint32_t)(digit[1] << 28);
+ LCD->RAM[LCD_RAMRegister_4] |= (uint32_t)(digit[2] << 28);
+ LCD->RAM[LCD_RAMRegister_6] |= (uint32_t)(digit[3] << 28);
+ break;
+
+ case 2:
+ /*!< Clear the corresponding segments (SEG32, SEG33, SEG34, SEG35) */
+ LCD->RAM[LCD_RAMRegister_1] &= (uint32_t)(0xFFFFFFF0);
+ LCD->RAM[LCD_RAMRegister_3] &= (uint32_t)(0xFFFFFFF0);
+ LCD->RAM[LCD_RAMRegister_5] &= (uint32_t)(0xFFFFFFF0);
+ LCD->RAM[LCD_RAMRegister_7] &= (uint32_t)(0xFFFFFFF0);
+
+ /*!< Write the corresponding segments (SEG32, SEG33, SEG34, SEG35) */
+ LCD->RAM[LCD_RAMRegister_1] |= (uint32_t)(digit[0] << 0);
+ LCD->RAM[LCD_RAMRegister_3] |= (uint32_t)(digit[1] << 0);
+ LCD->RAM[LCD_RAMRegister_5] |= (uint32_t)(digit[2] << 0);
+ LCD->RAM[LCD_RAMRegister_7] |= (uint32_t)(digit[3] << 0);
+ break;
+
+ case 1:
+ /*!< Clear the corresponding segments (SEG36, SEG37, SEG38, SEG39) */
+ LCD->RAM[LCD_RAMRegister_1] &= (uint32_t)(0xFFFFFF0F);
+ LCD->RAM[LCD_RAMRegister_3] &= (uint32_t)(0xFFFFFF0F);
+ LCD->RAM[LCD_RAMRegister_5] &= (uint32_t)(0xFFFFFF0F);
+ LCD->RAM[LCD_RAMRegister_7] &= (uint32_t)(0xFFFFFF0F);
+
+ /*!< Write the corresponding segments (SEG36, SEG37, SEG38, SEG39) */
+ LCD->RAM[LCD_RAMRegister_1] |= (uint32_t)(digit[0] << 4);
+ LCD->RAM[LCD_RAMRegister_3] |= (uint32_t)(digit[1] << 4);
+ LCD->RAM[LCD_RAMRegister_5] |= (uint32_t)(digit[2] << 4);
+ LCD->RAM[LCD_RAMRegister_7] |= (uint32_t)(digit[3] << 4);
+
+ break;
+
+ case 0:
+ /*!< Clear the corresponding segments (SEG40, SEG41, SEG42, SEG43) */
+ LCD->RAM[LCD_RAMRegister_1] &= (uint32_t)(0xFFFFF0FF);
+ LCD->RAM[LCD_RAMRegister_3] &= (uint32_t)(0xFFFFF0FF);
+ LCD->RAM[LCD_RAMRegister_5] &= (uint32_t)(0xFFFFF0FF);
+ LCD->RAM[LCD_RAMRegister_7] &= (uint32_t)(0xFFFFF0FF);
+
+ /*!< Write the corresponding segments (SEG40, SEG41, SEG42, SEG43) */
+ LCD->RAM[LCD_RAMRegister_1] |= (uint32_t)(digit[0] << 8);
+ LCD->RAM[LCD_RAMRegister_3] |= (uint32_t)(digit[1] << 8);
+ LCD->RAM[LCD_RAMRegister_5] |= (uint32_t)(digit[2] << 8);
+ LCD->RAM[LCD_RAMRegister_7] |= (uint32_t)(digit[3] << 8);
+ break;
+ }
+}
+
+/**
+ * @brief Display a string in scrolling mode
+ * @note The LCD should be cleared before to start the write operation.
+ * @param ptr: Pointer to string to display on the LCD Glass.
+ * @param nScroll: Specifies how many time the message will be scrolled
+ * @param ScrollSpeed: Speciifes the speed of the scroll.
+ * Low value gives higher speed.
+ * @retval None
+ */
+void LCD_GLASS_ScrollString(uint8_t* ptr, uint16_t nScroll, uint16_t ScrollSpeed)
+{
+ uint8_t Repetition = 0;
+ uint8_t* ptr1;
+ uint8_t str[8] = "";
+ ptr1 = ptr;
+
+ LCD_GLASS_DisplayString(ptr1);
+
+ delay(ScrollSpeed);
+
+ for (Repetition = 0; Repetition < nScroll; Repetition++)
+ {
+ *(str + 1) = *ptr1;
+ *(str + 2) = *(ptr1 + 1);
+ *(str + 3) = *(ptr1 + 2);
+ *(str + 4) = *(ptr1 + 3);
+ *(str + 5) = *(ptr1 + 4);
+ *(str + 6) = *(ptr1 + 5);
+ *(str + 7) =*(ptr1 + 6);
+ *(str) = *(ptr1 + 7);
+ LCD_GLASS_Clear();
+ LCD_GLASS_DisplayString(str);
+ delay(ScrollSpeed);
+
+ *(str + 1) = *(ptr1 + 7);
+ *(str + 2) = *ptr1;
+ *(str + 3) = *(ptr1 + 1);
+ *(str + 4) = *(ptr1 + 2);
+ *(str + 5) = *(ptr1 + 3);
+ *(str + 6) = *(ptr1 + 4);
+ *(str + 7) = *(ptr1 + 5);
+ *(str) = *(ptr1 + 6);
+ LCD_GLASS_Clear();
+ LCD_GLASS_DisplayString(str);
+ delay(ScrollSpeed);
+
+ *(str + 1) = *(ptr1 + 6);
+ *(str + 2) = *(ptr1 + 7);
+ *(str + 3) = *ptr1;
+ *(str + 4) = *(ptr1 + 1);
+ *(str + 5) = *(ptr1 + 2);
+ *(str + 6) = *(ptr1 + 3);
+ *(str + 7) = *(ptr1 + 4);
+ *(str) = *(ptr1 + 5);
+ LCD_GLASS_Clear();
+ LCD_GLASS_DisplayString(str);
+ delay(ScrollSpeed);
+
+ *(str + 1) = *(ptr1 + 5);
+ *(str + 2) = *(ptr1 + 6);
+ *(str + 3) = *(ptr1 + 7);
+ *(str + 4) = *ptr1;
+ *(str + 5) = *(ptr1 + 1);
+ *(str + 6) = *(ptr1 + 2);
+ *(str + 7) = *(ptr1 + 3);
+ *(str) = *(ptr1 + 4);
+ LCD_GLASS_Clear();
+ LCD_GLASS_DisplayString(str);
+ delay(ScrollSpeed);
+
+ *(str + 1) = *(ptr1 + 4);
+ *(str + 2) = *(ptr1 + 5);
+ *(str + 3) = *(ptr1 + 6);
+ *(str + 4) = *(ptr1 + 7);
+ *(str + 5) = *ptr1;
+ *(str + 6) = *(ptr1 + 1);
+ *(str + 7) = *(ptr1 + 2);
+ *(str) = *(ptr1 + 3);
+ LCD_GLASS_Clear();
+ LCD_GLASS_DisplayString(str);
+ delay(ScrollSpeed);
+
+ *(str + 1) = *(ptr1 + 3);
+ *(str + 2) = *(ptr1 + 4);
+ *(str + 3) = *(ptr1 + 5);
+ *(str + 4) = *(ptr1 + 6);
+ *(str + 5) = *(ptr1 + 7);
+ *(str + 6) = *ptr1;
+ *(str + 7) = *(ptr1 + 1);
+ *(str) = *(ptr1 + 2);
+ LCD_GLASS_Clear();
+ LCD_GLASS_DisplayString(str);
+ delay(ScrollSpeed);
+
+ *(str + 1) = *(ptr1 + 2);
+ *(str + 2) = *(ptr1 + 3);
+ *(str + 3) = *(ptr1 + 4);
+ *(str + 4) = *(ptr1 + 5);
+ *(str + 5) = *(ptr1 + 6);
+ *(str + 6) = *(ptr1 + 7);
+ *(str + 7) = *ptr1;
+ *(str) = *(ptr1 + 1);
+ LCD_GLASS_Clear();
+ LCD_GLASS_DisplayString(str);
+ delay(ScrollSpeed);
+
+ *(str + 1) = *(ptr1 + 1);
+ *(str + 2) = *(ptr1 + 2);
+ *(str + 3) = *(ptr1 + 3);
+ *(str + 4) = *(ptr1 + 4);
+ *(str + 5) = *(ptr1 + 5);
+ *(str + 6) = *(ptr1 + 6);
+ *(str + 7) = *(ptr1 + 7);
+ *(str) = *(ptr1);
+ LCD_GLASS_Clear();
+ LCD_GLASS_DisplayString(str);
+ delay(ScrollSpeed);
+ }
+}
+
+/**
+ * @brief This function Clear a char in the LCD RAM.
+ * @param position: Position in the LCD of the caracter to write.
+ * This parameter can be any value in range [0:7].
+ * @retval None
+ */
+void LCD_GLASS_ClearChar(uint8_t position)
+{
+ switch (position)
+ {
+ case 7:
+ /*!< Clear the corresponding segments (SEG0, SEG1, SEG2, SEG3) */
+ LCD->RAM[LCD_RAMRegister_0] &= (uint32_t)(0xFFFFFFF0);
+ LCD->RAM[LCD_RAMRegister_2] &= (uint32_t)(0xFFFFFFF0);
+ LCD->RAM[LCD_RAMRegister_4] &= (uint32_t)(0xFFFFFFF0);
+ LCD->RAM[LCD_RAMRegister_6] &= (uint32_t)(0xFFFFFFF0);
+ break;
+
+ case 6:
+ /*!< Clear the corresponding segments (SEG4, SEG5, SEG6, SEG10) */
+ LCD->RAM[LCD_RAMRegister_0] &= (uint32_t)(0xFFFFFB8F);
+ LCD->RAM[LCD_RAMRegister_2] &= (uint32_t)(0xFFFFFB8F);
+ LCD->RAM[LCD_RAMRegister_4] &= (uint32_t)(0xFFFFFB8F);
+ LCD->RAM[LCD_RAMRegister_6] &= (uint32_t)(0xFFFFFB8F);
+ break;
+
+ case 5:
+ /*!< Clear the corresponding segments (SEG11, SEG16, SEG18, SEG19) */
+ LCD->RAM[LCD_RAMRegister_0] &= (uint32_t)(0xFFF2F7FF);
+ LCD->RAM[LCD_RAMRegister_2] &= (uint32_t)(0xFFF2F7FF);
+ LCD->RAM[LCD_RAMRegister_4] &= (uint32_t)(0xFFF2F7FF);
+ LCD->RAM[LCD_RAMRegister_6] &= (uint32_t)(0xFFF2F7FF);
+ break;
+
+ case 4:
+ /*!< Clear the corresponding segments (SEG20, SEG21, SEG22, SEG23) */
+ LCD->RAM[LCD_RAMRegister_0] &= (uint32_t)(0xFF0FFFFF);
+ LCD->RAM[LCD_RAMRegister_2] &= (uint32_t)(0xFF0FFFFF);
+ LCD->RAM[LCD_RAMRegister_4] &= (uint32_t)(0xFF0FFFFF);
+ LCD->RAM[LCD_RAMRegister_6] &= (uint32_t)(0xFF0FFFFF);
+ break;
+
+ case 3:
+ /*!< Clear the corresponding segments (SEG28, SEG29, SEG30, SEG31) */
+ LCD->RAM[LCD_RAMRegister_0] &= (uint32_t)(0x0FFFFFFF);
+ LCD->RAM[LCD_RAMRegister_2] &= (uint32_t)(0x0FFFFFFF);
+ LCD->RAM[LCD_RAMRegister_4] &= (uint32_t)(0x0FFFFFFF);
+ LCD->RAM[LCD_RAMRegister_6] &= (uint32_t)(0x0FFFFFFF);
+ break;
+
+ case 2:
+ /*!< Clear the corresponding segments (SEG32, SEG33, SEG34, SEG35) */
+ LCD->RAM[LCD_RAMRegister_1] &= (uint32_t)(0xFFFFFFF0);
+ LCD->RAM[LCD_RAMRegister_3] &= (uint32_t)(0xFFFFFFF0);
+ LCD->RAM[LCD_RAMRegister_5] &= (uint32_t)(0xFFFFFFF0);
+ LCD->RAM[LCD_RAMRegister_7] &= (uint32_t)(0xFFFFFFF0);
+ break;
+
+ case 1:
+ /*!< Clear the corresponding segments (SEG36, SEG37, SEG38, SEG39) */
+ LCD->RAM[LCD_RAMRegister_1] &= (uint32_t)(0xFFFFFF0F);
+ LCD->RAM[LCD_RAMRegister_3] &= (uint32_t)(0xFFFFFF0F);
+ LCD->RAM[LCD_RAMRegister_5] &= (uint32_t)(0xFFFFFF0F);
+ LCD->RAM[LCD_RAMRegister_7] &= (uint32_t)(0xFFFFFF0F);
+ break;
+
+ case 0:
+ /*!< Clear the corresponding segments (SEG40, SEG41, SEG42, SEG43) */
+ LCD->RAM[LCD_RAMRegister_1] &= (uint32_t)(0xFFFFF0FF);
+ LCD->RAM[LCD_RAMRegister_3] &= (uint32_t)(0xFFFFF0FF);
+ LCD->RAM[LCD_RAMRegister_5] &= (uint32_t)(0xFFFFF0FF);
+ LCD->RAM[LCD_RAMRegister_7] &= (uint32_t)(0xFFFFF0FF);
+ break;
+ }
+}
+
+/**
+ * @brief This function Clear the whole LCD RAM.
+ * @param None
+ * @retval None
+ */
+void LCD_GLASS_Clear(void)
+{
+ uint32_t counter = 0;
+
+ for (counter = 0; counter < 0x0F; counter++)
+ {
+ LCD->RAM[counter] = (uint32_t)0x00;
+ }
+}
+
+/**
+ * @brief Converts an ascii char to an LCD digit.
+ * @param c: Char to display.
+ * @param point: A point to add in front of char.
+ * This parameter can be one of the following values:
+ * @arg POINT_OFF : No point to add in front of char.
+ * @arg POINT_ON : Add a point in front of char.
+ * @param apostrophe: Flag indicating if a apostrophe has to be add in front
+ * of displayed character.
+ * This parameter can be one of the following values:
+ * @arg APOSTROPHE_OFF : No apostrophe to add in back of char.
+ * @arg APOSTROPHE_ON : Add an apostrophe in back of char.
+ * @retval None
+ */
+static void Convert(uint8_t* c, Point_Typedef point, Apostrophe_Typedef apostrophe)
+{
+ uint16_t ch = 0, tmp = 0;
+ uint8_t i = 0;
+
+ /*!< The character c is a letter in upper case*/
+ if ((*c < 0x5B) & (*c > 0x40))
+ {
+ ch = LetterMap[*c - 0x41];
+ }
+
+ /*!< The character c is a number*/
+ if ((*c < 0x3A) & (*c > 0x2F))
+ {
+ ch = NumberMap[*c - 0x30];
+ }
+
+ /*!< The character c is a space character */
+ if (*c == 0x20)
+ {
+ ch =0x00;
+ }
+
+ /*!< Set the DP seg in the character that can be displayed if the point is on */
+ if (point == POINT_ON)
+ {
+ ch |= 0x0004;
+ }
+
+ /*!< Set the X seg in the character that can be displayed if the apostrophe is on */
+ if (apostrophe == APOSTROPHE_ON)
+ {
+ ch |= 0x1000;
+ }
+
+ for (i = 0; i < 4; i++)
+ {
+ tmp = ch & mask[i];
+ digit[i] =(uint8_t)(tmp >> shift[i]);
+ }
+}
+
+/**
+ * @brief Configures the LCD Segments and Coms GPIOs.
+ * @param None
+ * @retval None
+ */
+static void LCD_GPIOConfig(void)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+
+ /*!< Enable GPIOA, GPIOB, GPIOC, GPIOD and GPIOE AHB Clocks */
+ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOB | RCC_AHBPeriph_GPIOC
+ | RCC_AHBPeriph_GPIOD | RCC_AHBPeriph_GPIOE, ENABLE);
+
+ /*!< Connect PA.08 to LCD COM0 */
+ GPIO_PinAFConfig(GPIOA, GPIO_PinSource8, GPIO_AF_LCD);
+
+ /*!< Connect PA.09 to LCD COM1 */
+ GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_LCD);
+
+ /*!< Connect PA.10 to LCD COM2 */
+ GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_LCD);
+
+ /*!< Connect PB.09 to LCD COM3 */
+ GPIO_PinAFConfig(GPIOB, GPIO_PinSource9, GPIO_AF_LCD);
+
+ /*!< Connect PA.01 to LCD SEG0 */
+ GPIO_PinAFConfig(GPIOA, GPIO_PinSource1, GPIO_AF_LCD);
+
+ /*!< Connect PA.02 to LCD SEG1 */
+ GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_LCD);
+
+ /*!< Connect PA.03 to LCD SEG2 */
+ GPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_LCD);
+
+ /*!< Connect PA.06 to LCD SEG3 */
+ GPIO_PinAFConfig(GPIOA, GPIO_PinSource6, GPIO_AF_LCD);
+
+ /*!< Connect PA.07 to LCD SEG4 */
+ GPIO_PinAFConfig(GPIOA, GPIO_PinSource7, GPIO_AF_LCD);
+
+ /*!< Connect PB.00 to LCD SEG5 */
+ GPIO_PinAFConfig(GPIOB, GPIO_PinSource0, GPIO_AF_LCD);
+
+ /*!< Connect PB.01 to LCD SEG6 */
+ GPIO_PinAFConfig(GPIOB, GPIO_PinSource1, GPIO_AF_LCD);
+
+ /*!< Connect PB.10 to LCD SEG10 */
+ GPIO_PinAFConfig(GPIOB, GPIO_PinSource10, GPIO_AF_LCD);
+
+ /*!< Connect PB.11 to LCD SEG11 */
+ GPIO_PinAFConfig(GPIOB, GPIO_PinSource11, GPIO_AF_LCD);
+
+ /*!< Connect PB.08 to LCD SEG16 */
+ GPIO_PinAFConfig(GPIOB, GPIO_PinSource8, GPIO_AF_LCD);
+
+ /*!< Connect PC.00 to LCD SEG18 */
+ GPIO_PinAFConfig(GPIOC, GPIO_PinSource0, GPIO_AF_LCD);
+
+ /*!< Connect PC.01 to LCD SEG19 */
+ GPIO_PinAFConfig(GPIOC, GPIO_PinSource1, GPIO_AF_LCD);
+
+ /*!< Connect PC.02 to LCD SEG20 */
+ GPIO_PinAFConfig(GPIOC, GPIO_PinSource2, GPIO_AF_LCD);
+
+ /*!< Connect PC.03 to LCD SEG21 */
+ GPIO_PinAFConfig(GPIOC, GPIO_PinSource3, GPIO_AF_LCD);
+
+ /*!< Connect PC.04 to LCD SEG22 */
+ GPIO_PinAFConfig(GPIOC, GPIO_PinSource4, GPIO_AF_LCD);
+
+ /*!< Connect PC.05 to LCD SEG23 */
+ GPIO_PinAFConfig(GPIOC, GPIO_PinSource5, GPIO_AF_LCD);
+
+ /*!< Connect PD.08 to LCD SEG28 */
+ GPIO_PinAFConfig(GPIOD, GPIO_PinSource8, GPIO_AF_LCD);
+
+ /*!< Connect PD.09 to LCD SEG29 */
+ GPIO_PinAFConfig(GPIOD, GPIO_PinSource9, GPIO_AF_LCD);
+
+ /*!< Connect PD.10 to LCD SEG30 */
+ GPIO_PinAFConfig(GPIOD, GPIO_PinSource10, GPIO_AF_LCD);
+
+ /*!< Connect PD.11 to LCD SEG31 */
+ GPIO_PinAFConfig(GPIOD, GPIO_PinSource11, GPIO_AF_LCD);
+
+ /*!< Connect PD.12 to LCD SEG32 */
+ GPIO_PinAFConfig(GPIOD, GPIO_PinSource12, GPIO_AF_LCD);
+
+ /*!< Connect PD.13 to LCD SEG33 */
+ GPIO_PinAFConfig(GPIOD, GPIO_PinSource13, GPIO_AF_LCD);
+
+ /*!< Connect PD.14 to LCD SEG34 */
+ GPIO_PinAFConfig(GPIOD, GPIO_PinSource14, GPIO_AF_LCD);
+
+ /*!< Connect PD.15 to LCD SEG35 */
+ GPIO_PinAFConfig(GPIOD, GPIO_PinSource15, GPIO_AF_LCD);
+
+ /*!< Connect PE.00 to LCD SEG36 */
+ GPIO_PinAFConfig(GPIOE, GPIO_PinSource0, GPIO_AF_LCD);
+
+ /*!< Connect PE.01 to LCD SEG37 */
+ GPIO_PinAFConfig(GPIOE, GPIO_PinSource1, GPIO_AF_LCD);
+
+ /*!< Connect PE.02 to LCD SEG38 */
+ GPIO_PinAFConfig(GPIOE, GPIO_PinSource2, GPIO_AF_LCD);
+
+ /*!< Connect PE.03 to LCD SEG39 */
+ GPIO_PinAFConfig(GPIOE, GPIO_PinSource3, GPIO_AF_LCD);
+
+ /*!< Connect PC.10 to LCD SEG40 */
+ GPIO_PinAFConfig(GPIOC, GPIO_PinSource10, GPIO_AF_LCD);
+
+ /*!< Connect PC.11 to LCD SEG41 */
+ GPIO_PinAFConfig(GPIOC, GPIO_PinSource11, GPIO_AF_LCD);
+
+ /*!< Connect PC.12 to LCD SEG42 */
+ GPIO_PinAFConfig(GPIOC, GPIO_PinSource12, GPIO_AF_LCD);
+
+ /*!< Connect PD.02 to LCD SEG43 */
+ GPIO_PinAFConfig(GPIOD, GPIO_PinSource2, GPIO_AF_LCD);
+
+ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_6 | \
+ GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
+ GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
+ GPIO_Init(GPIOA, &GPIO_InitStructure);
+
+ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_8 | GPIO_Pin_9 | \
+ GPIO_Pin_10 | GPIO_Pin_11;
+ GPIO_Init(GPIOB, &GPIO_InitStructure);
+
+ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | \
+ GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_10 | GPIO_Pin_11 | \
+ GPIO_Pin_12;
+ GPIO_Init(GPIOC, &GPIO_InitStructure);
+
+ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | \
+ GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | \
+ GPIO_Pin_15;
+ GPIO_Init(GPIOD, &GPIO_InitStructure);
+
+ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3;
+ GPIO_Init(GPIOE, &GPIO_InitStructure);
+}
+
+/**
+ * @brief Inserts a delay time.
+ * @param nCount: specifies the delay time length.
+ * @retval None
+ */
+static void delay(__IO uint32_t nCount)
+{
+ __IO uint32_t index = 0;
+ for(index = (0xFF * nCount); index != 0; index--)
+ {
+ }
+}
+
+/**
+ * @}
+ */
+
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152_EVAL/stm32l152_eval_glass_lcd.h b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152_EVAL/stm32l152_eval_glass_lcd.h
new file mode 100644
index 0000000..5dde106
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152_EVAL/stm32l152_eval_glass_lcd.h
@@ -0,0 +1,131 @@
+/**
+ ******************************************************************************
+ * @file stm32l152_eval_glass_lcd.h
+ * @author MCD Application Team
+ * @version V5.0.2
+ * @date 09-March-2012
+ * @brief Header file for stm32l152_eval_glass_lcd.c module.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.st.com/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __STM32L152_EVAL_GLASS_LCD_H
+#define __STM32L152_EVAL_GLASS_LCD_H
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+/* Includes ------------------------------------------------------------------*/
+#include "stm32l152_eval.h"
+
+/** @addtogroup Utilities
+ * @{
+ */
+
+/** @addtogroup STM32_EVAL
+ * @{
+ */
+
+/** @addtogroup STM32L152_EVAL
+ * @{
+ */
+
+/** @addtogroup STM32L152_EVAL_GLASS_LCD
+ * @{
+ */
+
+
+/** @defgroup STM32L152_EVAL_GLASS_LCD_Exported_Types
+ * @{
+ */
+typedef enum
+{
+ POINT_OFF = 0,
+ POINT_ON = 1
+}Point_Typedef;
+
+typedef enum
+{
+ APOSTROPHE_OFF = 0,
+ APOSTROPHE_ON = 1
+}Apostrophe_Typedef;
+/**
+ * @}
+ */
+
+/** @defgroup STM32L152_EVAL_GLASS_LCD_Exported_Constants
+ * @{
+ */
+
+/**
+ * @}
+ */
+
+/** @defgroup STM32L152_EVAL_GLASS_LCD_Exported_Macros
+ * @{
+ */
+/**
+ * @}
+ */
+
+
+/** @defgroup STM32L152_EVAL_GLASS_LCD_Exported_Functions
+ * @{
+ */
+void LCD_GLASS_Init(void);
+void LCD_GLASS_DisplayChar(uint8_t* ch, Point_Typedef point, Apostrophe_Typedef apostrophe,uint8_t position);
+void LCD_GLASS_DisplayString(uint8_t* ptr);
+void LCD_GLASS_WriteChar(uint8_t* ch, Point_Typedef point, Apostrophe_Typedef apostrophe,uint8_t position);
+void LCD_GLASS_ClearChar(uint8_t position);
+void LCD_GLASS_Clear(void);
+void LCD_GLASS_ScrollString(uint8_t* ptr, uint16_t nScroll, uint16_t ScrollSpeed);
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __STM32L152_EVAL_GLASS_LCD_H */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152_EVAL/stm32l152_eval_i2c_ee.c b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152_EVAL/stm32l152_eval_i2c_ee.c
new file mode 100644
index 0000000..e67441f
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152_EVAL/stm32l152_eval_i2c_ee.c
@@ -0,0 +1,816 @@
+/**
+ ******************************************************************************
+ * @file stm32l152_eval_i2c_ee.c
+ * @author MCD Application Team
+ * @version V5.0.2
+ * @date 09-March-2012
+ * @brief This file provides a set of functions needed to manage an I2C M24CXX
+ * EEPROM memory.
+ *
+ * ===================================================================
+ * Notes:
+ * - This driver is intended for STM32L1xx families devices only.
+ * - There is no I2C EEPROM memory available in STM32L152-EVAL board,
+ * to use this driver you have to build your own hardware.
+ * ===================================================================
+ *
+ * It implements a high level communication layer for read and write
+ * from/to this memory. The needed STM32 hardware resources (I2C and
+ * GPIO) are defined in stm32l152_eval.h file, and the initialization is
+ * performed in sEE_LowLevel_Init() function declared in stm32l152_eval.c
+ * file.
+ * You can easily tailor this driver to any other development board,
+ * by just adapting the defines for hardware resources and
+ * sEE_LowLevel_Init() function.
+ *
+ * @note In this driver, basic read and write functions (sEE_ReadBuffer()
+ * and sEE_WritePage()) use the DMA to perform the data transfer
+ * to/from EEPROM memory (except when number of requested data is
+ * equal to 1). Thus, after calling these two functions, user
+ * application may perform other tasks while DMA is transferring
+ * data. The application should then monitor the variable holding
+ * the number of data in order to determine when the transfer is
+ * completed (variable decremented to 0). Stopping transfer tasks
+ * are performed into DMA interrupt handlers (which are integrated
+ * into this driver).
+ *
+ * +-----------------------------------------------------------------+
+ * | Pin assignment |
+ * +---------------------------------------+-----------+-------------+
+ * | STM32 I2C Pins | sEE | Pin |
+ * +---------------------------------------+-----------+-------------+
+ * | . | E0(GND) | 1 (0V) |
+ * | . | E1(GND) | 2 (0V) |
+ * | . | E2(GND) | 3 (0V) |
+ * | . | E0(VSS) | 4 (0V) |
+ * | sEE_I2C_SDA_PIN/ SDA | SDA | 5 |
+ * | sEE_I2C_SCL_PIN/ SCL | SCL | 6 |
+ * | . | /WC(VDD)| 7 (3.3V) |
+ * | . | VDD | 8 (3.3V) |
+ * +---------------------------------------+-----------+-------------+
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.st.com/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+
+/* Includes ------------------------------------------------------------------*/
+#include "stm32l152_eval_i2c_ee.h"
+
+/** @addtogroup Utilities
+ * @{
+ */
+
+/** @addtogroup STM32_EVAL
+ * @{
+ */
+
+/** @addtogroup STM32L152_EVAL
+ * @{
+ */
+
+/** @addtogroup STM32L152_EVAL_I2C_EE
+ * @brief This file includes the I2C EEPROM driver of STM32L152-EVAL board.
+ * @{
+ */
+
+/** @defgroup STM32L152_EVAL_I2C_EE_Private_Types
+ * @{
+ */
+/**
+ * @}
+ */
+
+
+/** @defgroup STM32L152_EVAL_I2C_EE_Private_Defines
+ * @{
+ */
+/**
+ * @}
+ */
+
+
+/** @defgroup STM32L152_EVAL_I2C_EE_Private_Macros
+ * @{
+ */
+/**
+ * @}
+ */
+
+
+/** @defgroup STM32L152_EVAL_I2C_EE_Private_Variables
+ * @{
+ */
+__IO uint16_t sEEAddress = 0;
+__IO uint32_t sEETimeout = sEE_LONG_TIMEOUT;
+__IO uint16_t* sEEDataReadPointer;
+__IO uint8_t* sEEDataWritePointer;
+__IO uint8_t sEEDataNum;
+/**
+ * @}
+ */
+
+
+/** @defgroup STM32L152_EVAL_I2C_EE_Private_Function_Prototypes
+ * @{
+ */
+/**
+ * @}
+ */
+
+
+/** @defgroup STM32L152_EVAL_I2C_EE_Private_Functions
+ * @{
+ */
+
+/**
+ * @brief DeInitializes peripherals used by the I2C EEPROM driver.
+ * @param None
+ * @retval None
+ */
+void sEE_DeInit(void)
+{
+ sEE_LowLevel_DeInit();
+}
+
+/**
+ * @brief Initializes peripherals used by the I2C EEPROM driver.
+ * @param None
+ * @retval None
+ */
+void sEE_Init(void)
+{
+ I2C_InitTypeDef I2C_InitStructure;
+
+ sEE_LowLevel_Init();
+
+ /*!< I2C configuration */
+ /* sEE_I2C configuration */
+ I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
+ I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;
+ I2C_InitStructure.I2C_OwnAddress1 = I2C_SLAVE_ADDRESS7;
+ I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
+ I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
+ I2C_InitStructure.I2C_ClockSpeed = I2C_SPEED;
+
+ /* sEE_I2C Peripheral Enable */
+ I2C_Cmd(sEE_I2C, ENABLE);
+ /* Apply sEE_I2C configuration after enabling it */
+ I2C_Init(sEE_I2C, &I2C_InitStructure);
+
+ /* Enable the sEE_I2C peripheral DMA requests */
+ I2C_DMACmd(sEE_I2C, ENABLE);
+
+#if defined (sEE_M24C64_32)
+ /*!< Select the EEPROM address according to the state of E0, E1, E2 pins */
+ sEEAddress = sEE_HW_ADDRESS;
+#elif defined (sEE_M24C08)
+ /*!< depending on the sEE Address selected in the i2c_ee.h file */
+ #ifdef sEE_Block0_ADDRESS
+ /*!< Select the sEE Block0 to write on */
+ sEEAddress = sEE_Block0_ADDRESS;
+ #endif
+
+ #ifdef sEE_Block1_ADDRESS
+ /*!< Select the sEE Block1 to write on */
+ sEEAddress = sEE_Block1_ADDRESS;
+ #endif
+
+ #ifdef sEE_Block2_ADDRESS
+ /*!< Select the sEE Block2 to write on */
+ sEEAddress = sEE_Block2_ADDRESS;
+ #endif
+
+ #ifdef sEE_Block3_ADDRESS
+ /*!< Select the sEE Block3 to write on */
+ sEEAddress = sEE_Block3_ADDRESS;
+ #endif
+#endif /*!< sEE_M24C64_32 */
+}
+
+/**
+ * @brief Reads a block of data from the EEPROM.
+ * @param pBuffer : pointer to the buffer that receives the data read from
+ * the EEPROM.
+ * @param ReadAddr : EEPROM's internal address to start reading from.
+ * @param NumByteToRead : pointer to the variable holding number of bytes to
+ * be read from the EEPROM.
+ *
+ * @note The variable pointed by NumByteToRead is reset to 0 when all the
+ * data are read from the EEPROM. Application should monitor this
+ * variable in order know when the transfer is complete.
+ *
+ * @note When number of data to be read is higher than 1, this function just
+ * configures the communication and enable the DMA channel to transfer data.
+ * Meanwhile, the user application may perform other tasks.
+ * When number of data to be read is 1, then the DMA is not used. The byte
+ * is read in polling mode.
+ *
+ * @retval sEE_OK (0) if operation is correctly performed, else return value
+ * different from sEE_OK (0) or the timeout user callback.
+ */
+uint32_t sEE_ReadBuffer(uint8_t* pBuffer, uint16_t ReadAddr, uint16_t* NumByteToRead)
+{
+ /* Set the pointer to the Number of data to be read. This pointer will be used
+ by the DMA Transfer Completer interrupt Handler in order to reset the
+ variable to 0. User should check on this variable in order to know if the
+ DMA transfer has been complete or not. */
+ sEEDataReadPointer = NumByteToRead;
+
+ /*!< While the bus is busy */
+ sEETimeout = sEE_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(sEE_I2C, I2C_FLAG_BUSY))
+ {
+ if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback();
+ }
+
+ /*!< Send START condition */
+ I2C_GenerateSTART(sEE_I2C, ENABLE);
+
+ /*!< Test on EV5 and clear it (cleared by reading SR1 then writing to DR) */
+ sEETimeout = sEE_FLAG_TIMEOUT;
+ while(!I2C_CheckEvent(sEE_I2C, I2C_EVENT_MASTER_MODE_SELECT))
+ {
+ if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback();
+ }
+
+ /*!< Send EEPROM address for write */
+ I2C_Send7bitAddress(sEE_I2C, sEEAddress, I2C_Direction_Transmitter);
+
+ /*!< Test on EV6 and clear it */
+ sEETimeout = sEE_FLAG_TIMEOUT;
+ while(!I2C_CheckEvent(sEE_I2C, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED))
+ {
+ if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback();
+ }
+
+#ifdef sEE_M24C08
+
+ /*!< Send the EEPROM's internal address to read from: Only one byte address */
+ I2C_SendData(sEE_I2C, ReadAddr);
+
+#elif defined (sEE_M24C64_32)
+
+ /*!< Send the EEPROM's internal address to read from: MSB of the address first */
+ I2C_SendData(sEE_I2C, (uint8_t)((ReadAddr & 0xFF00) >> 8));
+
+ /*!< Test on EV8 and clear it */
+ sEETimeout = sEE_FLAG_TIMEOUT;
+ while(!I2C_CheckEvent(sEE_I2C, I2C_EVENT_MASTER_BYTE_TRANSMITTING))
+ {
+ if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback();
+ }
+
+ /*!< Send the EEPROM's internal address to read from: LSB of the address */
+ I2C_SendData(sEE_I2C, (uint8_t)(ReadAddr & 0x00FF));
+
+#endif /*!< sEE_M24C08 */
+
+ /*!< Test on EV8 and clear it */
+ sEETimeout = sEE_FLAG_TIMEOUT;
+ while(I2C_GetFlagStatus(sEE_I2C, I2C_FLAG_BTF) == RESET)
+ {
+ if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback();
+ }
+
+ /*!< Send STRAT condition a second time */
+ I2C_GenerateSTART(sEE_I2C, ENABLE);
+
+ /*!< Test on EV5 and clear it (cleared by reading SR1 then writing to DR) */
+ sEETimeout = sEE_FLAG_TIMEOUT;
+ while(!I2C_CheckEvent(sEE_I2C, I2C_EVENT_MASTER_MODE_SELECT))
+ {
+ if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback();
+ }
+
+ /*!< Send EEPROM address for read */
+ I2C_Send7bitAddress(sEE_I2C, sEEAddress, I2C_Direction_Receiver);
+
+ /* If number of data to be read is 1, then DMA couldn't be used */
+ /* One Byte Master Reception procedure (POLLING) ---------------------------*/
+ if ((uint16_t)(*NumByteToRead) < 2)
+ {
+ /* Wait on ADDR flag to be set (ADDR is still not cleared at this level */
+ sEETimeout = sEE_FLAG_TIMEOUT;
+ while(I2C_GetFlagStatus(sEE_I2C, I2C_FLAG_ADDR) == RESET)
+ {
+ if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback();
+ }
+
+ /*!< Disable Acknowledgement */
+ I2C_AcknowledgeConfig(sEE_I2C, DISABLE);
+
+ /* Clear ADDR register by reading SR1 then SR2 register (SR1 has already been read) */
+ (void)sEE_I2C->SR2;
+
+ /*!< Send STOP Condition */
+ I2C_GenerateSTOP(sEE_I2C, ENABLE);
+
+ /* Wait for the byte to be received */
+ sEETimeout = sEE_FLAG_TIMEOUT;
+ while(I2C_GetFlagStatus(sEE_I2C, I2C_FLAG_RXNE) == RESET)
+ {
+ if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback();
+ }
+
+ /*!< Read the byte received from the EEPROM */
+ *pBuffer = I2C_ReceiveData(sEE_I2C);
+
+ /*!< Decrement the read bytes counter */
+ (uint16_t)(*NumByteToRead)--;
+
+ /* Wait to make sure that STOP control bit has been cleared */
+ sEETimeout = sEE_FLAG_TIMEOUT;
+ while(sEE_I2C->CR1 & I2C_CR1_STOP)
+ {
+ if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback();
+ }
+
+ /*!< Re-Enable Acknowledgement to be ready for another reception */
+ I2C_AcknowledgeConfig(sEE_I2C, ENABLE);
+ }
+ else/* More than one Byte Master Reception procedure (DMA) -----------------*/
+ {
+ /*!< Test on EV6 and clear it */
+ sEETimeout = sEE_FLAG_TIMEOUT;
+ while(!I2C_CheckEvent(sEE_I2C, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED))
+ {
+ if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback();
+ }
+
+ /* Configure the DMA Rx Channel with the buffer address and the buffer size */
+ sEE_LowLevel_DMAConfig((uint32_t)pBuffer, (uint16_t)(*NumByteToRead), sEE_DIRECTION_RX);
+
+ /* Inform the DMA that the next End Of Transfer Signal will be the last one */
+ I2C_DMALastTransferCmd(sEE_I2C, ENABLE);
+
+ /* Enable the DMA Rx Channel */
+ DMA_Cmd(sEE_I2C_DMA_CHANNEL_RX, ENABLE);
+ }
+
+ /* If all operations OK, return sEE_OK (0) */
+ return sEE_OK;
+}
+
+/**
+ * @brief Writes more than one byte to the EEPROM with a single WRITE cycle.
+ *
+ * @note The number of bytes (combined to write start address) must not
+ * cross the EEPROM page boundary. This function can only write into
+ * the boundaries of an EEPROM page.
+ * This function doesn't check on boundaries condition (in this driver
+ * the function sEE_WriteBuffer() which calls sEE_WritePage() is
+ * responsible of checking on Page boundaries).
+ *
+ * @param pBuffer : pointer to the buffer containing the data to be written to
+ * the EEPROM.
+ * @param WriteAddr : EEPROM's internal address to write to.
+ * @param NumByteToWrite : pointer to the variable holding number of bytes to
+ * be written into the EEPROM.
+ *
+ * @note The variable pointed by NumByteToWrite is reset to 0 when all the
+ * data are written to the EEPROM. Application should monitor this
+ * variable in order know when the transfer is complete.
+ *
+ * @note This function just configure the communication and enable the DMA
+ * channel to transfer data. Meanwhile, the user application may perform
+ * other tasks in parallel.
+ *
+ * @retval sEE_OK (0) if operation is correctly performed, else return value
+ * different from sEE_OK (0) or the timeout user callback.
+ */
+uint32_t sEE_WritePage(uint8_t* pBuffer, uint16_t WriteAddr, uint8_t* NumByteToWrite)
+{
+ /* Set the pointer to the Number of data to be written. This pointer will be used
+ by the DMA Transfer Completer interrupt Handler in order to reset the
+ variable to 0. User should check on this variable in order to know if the
+ DMA transfer has been complete or not. */
+ sEEDataWritePointer = NumByteToWrite;
+
+ /*!< While the bus is busy */
+ sEETimeout = sEE_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(sEE_I2C, I2C_FLAG_BUSY))
+ {
+ if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback();
+ }
+
+ /*!< Send START condition */
+ I2C_GenerateSTART(sEE_I2C, ENABLE);
+
+ /*!< Test on EV5 and clear it */
+ sEETimeout = sEE_FLAG_TIMEOUT;
+ while(!I2C_CheckEvent(sEE_I2C, I2C_EVENT_MASTER_MODE_SELECT))
+ {
+ if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback();
+ }
+
+ /*!< Send EEPROM address for write */
+ sEETimeout = sEE_FLAG_TIMEOUT;
+ I2C_Send7bitAddress(sEE_I2C, sEEAddress, I2C_Direction_Transmitter);
+
+ /*!< Test on EV6 and clear it */
+ sEETimeout = sEE_FLAG_TIMEOUT;
+ while(!I2C_CheckEvent(sEE_I2C, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED))
+ {
+ if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback();
+ }
+
+#ifdef sEE_M24C08
+
+ /*!< Send the EEPROM's internal address to write to : only one byte Address */
+ I2C_SendData(sEE_I2C, WriteAddr);
+
+#elif defined(sEE_M24C64_32)
+
+ /*!< Send the EEPROM's internal address to write to : MSB of the address first */
+ I2C_SendData(sEE_I2C, (uint8_t)((WriteAddr & 0xFF00) >> 8));
+
+ /*!< Test on EV8 and clear it */
+ sEETimeout = sEE_FLAG_TIMEOUT;
+ while(!I2C_CheckEvent(sEE_I2C, I2C_EVENT_MASTER_BYTE_TRANSMITTING))
+ {
+ if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback();
+ }
+
+ /*!< Send the EEPROM's internal address to write to : LSB of the address */
+ I2C_SendData(sEE_I2C, (uint8_t)(WriteAddr & 0x00FF));
+
+#endif /*!< sEE_M24C08 */
+
+ /*!< Test on EV8 and clear it */
+ sEETimeout = sEE_FLAG_TIMEOUT;
+ while(!I2C_CheckEvent(sEE_I2C, I2C_EVENT_MASTER_BYTE_TRANSMITTING))
+ {
+ if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback();
+ }
+
+ /* Configure the DMA Tx Channel with the buffer address and the buffer size */
+ sEE_LowLevel_DMAConfig((uint32_t)pBuffer, (uint8_t)(*NumByteToWrite), sEE_DIRECTION_TX);
+
+ /* Enable the DMA Tx Channel */
+ DMA_Cmd(sEE_I2C_DMA_CHANNEL_TX, ENABLE);
+
+ /* If all operations OK, return sEE_OK (0) */
+ return sEE_OK;
+}
+
+/**
+ * @brief Writes buffer of data to the I2C EEPROM.
+ * @param pBuffer : pointer to the buffer containing the data to be written
+ * to the EEPROM.
+ * @param WriteAddr : EEPROM's internal address to write to.
+ * @param NumByteToWrite : number of bytes to write to the EEPROM.
+ * @retval None
+ */
+void sEE_WriteBuffer(uint8_t* pBuffer, uint16_t WriteAddr, uint16_t NumByteToWrite)
+{
+ uint16_t NumOfPage = 0, NumOfSingle = 0, count = 0;
+ uint16_t Addr = 0;
+
+ Addr = WriteAddr % sEE_PAGESIZE;
+ count = sEE_PAGESIZE - Addr;
+ NumOfPage = NumByteToWrite / sEE_PAGESIZE;
+ NumOfSingle = NumByteToWrite % sEE_PAGESIZE;
+
+ /*!< If WriteAddr is sEE_PAGESIZE aligned */
+ if(Addr == 0)
+ {
+ /*!< If NumByteToWrite < sEE_PAGESIZE */
+ if(NumOfPage == 0)
+ {
+ /* Store the number of data to be written */
+ sEEDataNum = NumOfSingle;
+ /* Start writing data */
+ sEE_WritePage(pBuffer, WriteAddr, (uint8_t*)(&sEEDataNum));
+ /* Wait transfer through DMA to be complete */
+ sEETimeout = sEE_LONG_TIMEOUT;
+ while (sEEDataNum > 0)
+ {
+ if((sEETimeout--) == 0) {sEE_TIMEOUT_UserCallback(); return;};
+ }
+ sEE_WaitEepromStandbyState();
+ }
+ /*!< If NumByteToWrite > sEE_PAGESIZE */
+ else
+ {
+ while(NumOfPage--)
+ {
+ /* Store the number of data to be written */
+ sEEDataNum = sEE_PAGESIZE;
+ sEE_WritePage(pBuffer, WriteAddr, (uint8_t*)(&sEEDataNum));
+ /* Wait transfer through DMA to be complete */
+ sEETimeout = sEE_LONG_TIMEOUT;
+ while (sEEDataNum > 0)
+ {
+ if((sEETimeout--) == 0) {sEE_TIMEOUT_UserCallback(); return;};
+ }
+ sEE_WaitEepromStandbyState();
+ WriteAddr += sEE_PAGESIZE;
+ pBuffer += sEE_PAGESIZE;
+ }
+
+ if(NumOfSingle!=0)
+ {
+ /* Store the number of data to be written */
+ sEEDataNum = NumOfSingle;
+ sEE_WritePage(pBuffer, WriteAddr, (uint8_t*)(&sEEDataNum));
+ /* Wait transfer through DMA to be complete */
+ sEETimeout = sEE_LONG_TIMEOUT;
+ while (sEEDataNum > 0)
+ {
+ if((sEETimeout--) == 0) {sEE_TIMEOUT_UserCallback(); return;};
+ }
+ sEE_WaitEepromStandbyState();
+ }
+ }
+ }
+ /*!< If WriteAddr is not sEE_PAGESIZE aligned */
+ else
+ {
+ /*!< If NumByteToWrite < sEE_PAGESIZE */
+ if(NumOfPage== 0)
+ {
+ /*!< If the number of data to be written is more than the remaining space
+ in the current page: */
+ if (NumByteToWrite > count)
+ {
+ /* Store the number of data to be written */
+ sEEDataNum = count;
+ /*!< Write the data conained in same page */
+ sEE_WritePage(pBuffer, WriteAddr, (uint8_t*)(&sEEDataNum));
+ /* Wait transfer through DMA to be complete */
+ sEETimeout = sEE_LONG_TIMEOUT;
+ while (sEEDataNum > 0)
+ {
+ if((sEETimeout--) == 0) {sEE_TIMEOUT_UserCallback(); return;};
+ }
+ sEE_WaitEepromStandbyState();
+
+ /* Store the number of data to be written */
+ sEEDataNum = (NumByteToWrite - count);
+ /*!< Write the remaining data in the following page */
+ sEE_WritePage((uint8_t*)(pBuffer + count), (WriteAddr + count), (uint8_t*)(&sEEDataNum));
+ /* Wait transfer through DMA to be complete */
+ sEETimeout = sEE_LONG_TIMEOUT;
+ while (sEEDataNum > 0)
+ {
+ if((sEETimeout--) == 0) {sEE_TIMEOUT_UserCallback(); return;};
+ }
+ sEE_WaitEepromStandbyState();
+ }
+ else
+ {
+ /* Store the number of data to be written */
+ sEEDataNum = NumOfSingle;
+ sEE_WritePage(pBuffer, WriteAddr, (uint8_t*)(&sEEDataNum));
+ /* Wait transfer through DMA to be complete */
+ sEETimeout = sEE_LONG_TIMEOUT;
+ while (sEEDataNum > 0)
+ {
+ if((sEETimeout--) == 0) {sEE_TIMEOUT_UserCallback(); return;};
+ }
+ sEE_WaitEepromStandbyState();
+ }
+ }
+ /*!< If NumByteToWrite > sEE_PAGESIZE */
+ else
+ {
+ NumByteToWrite -= count;
+ NumOfPage = NumByteToWrite / sEE_PAGESIZE;
+ NumOfSingle = NumByteToWrite % sEE_PAGESIZE;
+
+ if(count != 0)
+ {
+ /* Store the number of data to be written */
+ sEEDataNum = count;
+ sEE_WritePage(pBuffer, WriteAddr, (uint8_t*)(&sEEDataNum));
+ /* Wait transfer through DMA to be complete */
+ sEETimeout = sEE_LONG_TIMEOUT;
+ while (sEEDataNum > 0)
+ {
+ if((sEETimeout--) == 0) {sEE_TIMEOUT_UserCallback(); return;};
+ }
+ sEE_WaitEepromStandbyState();
+ WriteAddr += count;
+ pBuffer += count;
+ }
+
+ while(NumOfPage--)
+ {
+ /* Store the number of data to be written */
+ sEEDataNum = sEE_PAGESIZE;
+ sEE_WritePage(pBuffer, WriteAddr, (uint8_t*)(&sEEDataNum));
+ /* Wait transfer through DMA to be complete */
+ sEETimeout = sEE_LONG_TIMEOUT;
+ while (sEEDataNum > 0)
+ {
+ if((sEETimeout--) == 0) {sEE_TIMEOUT_UserCallback(); return;};
+ }
+ sEE_WaitEepromStandbyState();
+ WriteAddr += sEE_PAGESIZE;
+ pBuffer += sEE_PAGESIZE;
+ }
+ if(NumOfSingle != 0)
+ {
+ /* Store the number of data to be written */
+ sEEDataNum = NumOfSingle;
+ sEE_WritePage(pBuffer, WriteAddr, (uint8_t*)(&sEEDataNum));
+ /* Wait transfer through DMA to be complete */
+ sEETimeout = sEE_LONG_TIMEOUT;
+ while (sEEDataNum > 0)
+ {
+ if((sEETimeout--) == 0) {sEE_TIMEOUT_UserCallback(); return;};
+ }
+ sEE_WaitEepromStandbyState();
+ }
+ }
+ }
+}
+
+/**
+ * @brief Wait for EEPROM Standby state.
+ *
+ * @note This function allows to wait and check that EEPROM has finished the
+ * last operation. It is mostly used after Write operation: after receiving
+ * the buffer to be written, the EEPROM may need additional time to actually
+ * perform the write operation. During this time, it doesn't answer to
+ * I2C packets addressed to it. Once the write operation is complete
+ * the EEPROM responds to its address.
+ *
+ * @param None
+ * @retval sEE_OK (0) if operation is correctly performed, else return value
+ * different from sEE_OK (0) or the timeout user callback.
+ */
+uint32_t sEE_WaitEepromStandbyState(void)
+{
+ __IO uint16_t tmpSR1 = 0;
+ __IO uint32_t sEETrials = 0;
+
+ /*!< While the bus is busy */
+ sEETimeout = sEE_LONG_TIMEOUT;
+ while(I2C_GetFlagStatus(sEE_I2C, I2C_FLAG_BUSY))
+ {
+ if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback();
+ }
+
+ /* Keep looping till the slave acknowledge his address or maximum number
+ of trials is reached (this number is defined by sEE_MAX_TRIALS_NUMBER define
+ in stm32l152_eval_i2c_ee.h file) */
+ while (1)
+ {
+ /*!< Send START condition */
+ I2C_GenerateSTART(sEE_I2C, ENABLE);
+
+ /*!< Test on EV5 and clear it */
+ sEETimeout = sEE_FLAG_TIMEOUT;
+ while(!I2C_CheckEvent(sEE_I2C, I2C_EVENT_MASTER_MODE_SELECT))
+ {
+ if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback();
+ }
+
+ /*!< Send EEPROM address for write */
+ I2C_Send7bitAddress(sEE_I2C, sEEAddress, I2C_Direction_Transmitter);
+
+ /* Wait for ADDR flag to be set (Slave acknowledged his address) */
+ sEETimeout = sEE_LONG_TIMEOUT;
+ do
+ {
+ /* Get the current value of the SR1 register */
+ tmpSR1 = sEE_I2C->SR1;
+
+ /* Update the timeout value and exit if it reach 0 */
+ if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback();
+ }
+ /* Keep looping till the Address is acknowledged or the AF flag is
+ set (address not acknowledged at time) */
+ while((tmpSR1 & (I2C_SR1_ADDR | I2C_SR1_AF)) == 0);
+
+ /* Check if the ADDR flag has been set */
+ if (tmpSR1 & I2C_SR1_ADDR)
+ {
+ /* Clear ADDR Flag by reading SR1 then SR2 registers (SR1 have already
+ been read) */
+ (void)sEE_I2C->SR2;
+
+ /*!< STOP condition */
+ I2C_GenerateSTOP(sEE_I2C, ENABLE);
+
+ /* Exit the function */
+ return sEE_OK;
+ }
+ else
+ {
+ /*!< Clear AF flag */
+ I2C_ClearFlag(sEE_I2C, I2C_FLAG_AF);
+ }
+
+ /* Check if the maximum allowed numbe of trials has bee reached */
+ if (sEETrials++ == sEE_MAX_TRIALS_NUMBER)
+ {
+ /* If the maximum number of trials has been reached, exit the function */
+ return sEE_TIMEOUT_UserCallback();
+ }
+ }
+}
+
+/**
+ * @brief This function handles the DMA Tx Channel interrupt Handler.
+ * @param None
+ * @retval None
+ */
+void sEE_I2C_DMA_TX_IRQHandler(void)
+{
+ /* Check if the DMA transfer is complete */
+ if(DMA_GetFlagStatus(sEE_I2C_DMA_FLAG_TX_TC) != RESET)
+ {
+ /* Disable the DMA Tx Channel and Clear all its Flags */
+ DMA_Cmd(sEE_I2C_DMA_CHANNEL_TX, DISABLE);
+ DMA_ClearFlag(sEE_I2C_DMA_FLAG_TX_GL);
+
+ /*!< Wait till all data have been physically transferred on the bus */
+ sEETimeout = sEE_LONG_TIMEOUT;
+ while(!I2C_GetFlagStatus(sEE_I2C, I2C_FLAG_BTF))
+ {
+ if((sEETimeout--) == 0) sEE_TIMEOUT_UserCallback();
+ }
+
+ /*!< Send STOP condition */
+ I2C_GenerateSTOP(sEE_I2C, ENABLE);
+
+ /* Reset the variable holding the number of data to be written */
+ *sEEDataWritePointer = 0;
+ }
+}
+
+/**
+ * @brief This function handles the DMA Rx Channel interrupt Handler.
+ * @param None
+ * @retval None
+ */
+void sEE_I2C_DMA_RX_IRQHandler(void)
+{
+ /* Check if the DMA transfer is complete */
+ if(DMA_GetFlagStatus(sEE_I2C_DMA_FLAG_RX_TC) != RESET)
+ {
+ /*!< Send STOP Condition */
+ I2C_GenerateSTOP(sEE_I2C, ENABLE);
+
+ /* Disable the DMA Rx Channel and Clear all its Flags */
+ DMA_Cmd(sEE_I2C_DMA_CHANNEL_RX, DISABLE);
+ DMA_ClearFlag(sEE_I2C_DMA_FLAG_RX_GL);
+
+ /* Reset the variable holding the number of data to be read */
+ *sEEDataReadPointer = 0;
+ }
+}
+
+#ifdef USE_DEFAULT_TIMEOUT_CALLBACK
+/**
+ * @brief Basic management of the timeout situation.
+ * @param None.
+ * @retval None.
+ */
+uint32_t sEE_TIMEOUT_UserCallback(void)
+{
+ /* Block communication and all processes */
+ while (1)
+ {
+ }
+}
+#endif /* USE_DEFAULT_TIMEOUT_CALLBACK */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152_EVAL/stm32l152_eval_i2c_ee.h b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152_EVAL/stm32l152_eval_i2c_ee.h
new file mode 100644
index 0000000..fc41d9b
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152_EVAL/stm32l152_eval_i2c_ee.h
@@ -0,0 +1,187 @@
+/**
+ ******************************************************************************
+ * @file stm32l152_eval_i2c_ee.h
+ * @author MCD Application Team
+ * @version V5.0.2
+ * @date 09-March-2012
+ * @brief This file contains all the functions prototypes for the stm32l152_eval_i2c_ee
+ * firmware driver.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.st.com/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __STM32L152_EVAL_I2C_EE_H
+#define __STM32L152_EVAL_I2C_EE_H
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+/* Includes ------------------------------------------------------------------*/
+#include "stm32l152_eval.h"
+
+/** @addtogroup Utilities
+ * @{
+ */
+
+/** @addtogroup STM32_EVAL
+ * @{
+ */
+
+/** @addtogroup STM32L152_EVAL
+ * @{
+ */
+
+/** @addtogroup STM32L152_EVAL_I2C_EE
+ * @{
+ */
+
+/** @defgroup STM32L152_EVAL_I2C_EE_Exported_Types
+ * @{
+ */
+
+/**
+ * @}
+ */
+
+/** @defgroup STM32L152_EVAL_I2C_EE_Exported_Constants
+ * @{
+ */
+
+/* Uncomment the following line to use the default sEE_TIMEOUT_UserCallback()
+ function implemented in stm32_evel_i2c_ee.c file.
+ sEE_TIMEOUT_UserCallback() function is called whenever a timeout condition
+ occure during communication (waiting on an event that doesn't occur, bus
+ errors, busy devices ...). */
+/* #define USE_DEFAULT_TIMEOUT_CALLBACK */
+
+#if !defined (sEE_M24C08) && !defined (sEE_M24C64_32)
+/* Use the defines below the choose the EEPROM type */
+/* #define sEE_M24C08*/ /* Support the device: M24C08. */
+/* note: Could support: M24C01, M24C02, M24C04 and M24C16 if the blocks and
+ HW address are correctly defined*/
+#define sEE_M24C64_32 /* Support the devices: M24C32 and M24C64 */
+#endif
+
+#ifdef sEE_M24C64_32
+/* For M24C32 and M24C64 devices, E0,E1 and E2 pins are all used for device
+ address selection (ne need for additional address lines). According to the
+ Harware connection on the board (on STM3210C-EVAL board E0 = E1 = E2 = 0) */
+
+ #define sEE_HW_ADDRESS 0xA0 /* E0 = E1 = E2 = 0 */
+
+#elif defined (sEE_M24C08)
+/* The M24C08W contains 4 blocks (128byte each) with the adresses below: E2 = 0
+ EEPROM Addresses defines */
+ #define sEE_Block0_ADDRESS 0xA0 /* E2 = 0 */
+ /*#define sEE_Block1_ADDRESS 0xA2*/ /* E2 = 0 */
+ /*#define sEE_Block2_ADDRESS 0xA4*/ /* E2 = 0 */
+ /*#define sEE_Block3_ADDRESS 0xA6*/ /* E2 = 0 */
+
+#endif /* sEE_M24C64_32 */
+
+#define I2C_SPEED 200000
+#define I2C_SLAVE_ADDRESS7 0xA0
+
+#if defined (sEE_M24C08)
+ #define sEE_PAGESIZE 16
+#elif defined (sEE_M24C64_32)
+ #define sEE_PAGESIZE 32
+#endif
+
+/* Maximum Timeout values for flags and events waiting loops. These timeouts are
+ not based on accurate values, they just guarantee that the application will
+ not remain stuck if the I2C communication is corrupted.
+ You may modify these timeout values depending on CPU frequency and application
+ conditions (interrupts routines ...). */
+#define sEE_FLAG_TIMEOUT ((uint32_t)0x1000)
+#define sEE_LONG_TIMEOUT ((uint32_t)(10 * sEE_FLAG_TIMEOUT))
+
+/* Maximum number of trials for sEE_WaitEepromStandbyState() function */
+#define sEE_MAX_TRIALS_NUMBER 300
+
+/* Defintions for the state of the DMA transfer */
+#define sEE_STATE_READY 0
+#define sEE_STATE_BUSY 1
+#define sEE_STATE_ERROR 2
+
+#define sEE_OK 0
+#define sEE_FAIL 1
+
+/**
+ * @}
+ */
+
+/** @defgroup STM32L152_EVAL_I2C_EE_Exported_Macros
+ * @{
+ */
+/**
+ * @}
+ */
+
+/** @defgroup STM32L152_EVAL_I2C_EE_Exported_Functions
+ * @{
+ */
+void sEE_DeInit(void);
+void sEE_Init(void);
+uint32_t sEE_ReadBuffer(uint8_t* pBuffer, uint16_t ReadAddr, uint16_t* NumByteToRead);
+uint32_t sEE_WritePage(uint8_t* pBuffer, uint16_t WriteAddr, uint8_t* NumByteToWrite);
+void sEE_WriteBuffer(uint8_t* pBuffer, uint16_t WriteAddr, uint16_t NumByteToWrite);
+uint32_t sEE_WaitEepromStandbyState(void);
+
+/* USER Callbacks: These are functions for which prototypes only are declared in
+ EEPROM driver and that should be implemented into user applicaiton. */
+/* sEE_TIMEOUT_UserCallback() function is called whenever a timeout condition
+ occure during communication (waiting on an event that doesn't occur, bus
+ errors, busy devices ...).
+ You can use the default timeout callback implementation by uncommenting the
+ define USE_DEFAULT_TIMEOUT_CALLBACK in stm32_evel_i2c_ee.h file.
+ Typically the user implementation of this callback should reset I2C peripheral
+ and re-initialize communication or in worst case reset all the application. */
+uint32_t sEE_TIMEOUT_UserCallback(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __STM32L152_EVAL_I2C_EE_H */
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
+
+
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152_EVAL/stm32l152_eval_i2c_tsensor.c b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152_EVAL/stm32l152_eval_i2c_tsensor.c
new file mode 100644
index 0000000..3c15376
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152_EVAL/stm32l152_eval_i2c_tsensor.c
@@ -0,0 +1,982 @@
+/**
+ ******************************************************************************
+ * @file stm32l152_eval_i2c_tsensor.c
+ * @author MCD Application Team
+ * @version V5.0.2
+ * @date 09-March-2012
+ * @brief This file provides a set of functions needed to manage the I2C LM75
+ * temperature sensor mounted on STM32L152-EVAL board.
+ * It implements a high level communication layer for read and write
+ * from/to this sensor. The needed STM32L hardware resources (I2C and
+ * GPIO) are defined in stm32l152_eval.h file, and the initialization is
+ * performed in LM75_LowLevel_Init() function declared in stm32l152_eval.c
+ * file.
+ *
+ * Note:
+ * -----
+ * This driver uses the DMA method to send and receive data on I2C bus,
+ * which allows higher efficiency and reliability of the communication.
+ *
+ * You can easily tailor this driver to any other development board,
+ * by just adapting the defines for hardware resources and
+ * LM75_LowLevel_Init() function.
+ *
+ * +-----------------------------------------------------------------+
+ * | Pin assignment |
+ * +---------------------------------------+-----------+-------------+
+ * | STM32 I2C Pins | STLM75 | Pin |
+ * +---------------------------------------+-----------+-------------+
+ * | LM75_I2C_SDA_PIN/ SDA | SDA | 1 |
+ * | LM75_I2C_SCL_PIN/ SCL | SCL | 2 |
+ * | LM75_I2C_SMBUSALERT_PIN/ SMBUS ALERT | OS/INT | 3 |
+ * | . | GND | 4 (0V) |
+ * | . | GND | 5 (0V) |
+ * | . | GND | 6 (0V) |
+ * | . | GND | 7 (0V) |
+ * | . | VDD | 8 (3.3V)|
+ * +---------------------------------------+-----------+-------------+
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.st.com/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+
+/* Includes ------------------------------------------------------------------*/
+#include "stm32l152_eval_i2c_tsensor.h"
+
+/** @addtogroup Utilities
+ * @{
+ */
+
+/** @addtogroup STM32_EVAL
+ * @{
+ */
+
+/** @addtogroup STM32L152_EVAL
+ * @{
+ */
+
+/** @addtogroup STM32L152_EVAL_I2C_TSENSOR
+ * @brief This file includes the LM75 Temperature Sensor driver of
+ * STM32-EVAL boards.
+ * @{
+ */
+
+/** @defgroup STM32L152_EVAL_I2C_TSENSOR_Private_Types
+ * @{
+ */
+/**
+ * @}
+ */
+
+/** @defgroup STM32L152_EVAL_I2C_TSENSOR_Private_Defines
+ * @{
+ */
+#define LM75_SD_SET 0x01 /*!< Set SD bit in the configuration register */
+#define LM75_SD_RESET 0xFE /*!< Reset SD bit in the configuration register */
+/**
+ * @}
+ */
+
+/** @defgroup STM32L152_EVAL_I2C_TSENSOR_Private_Macros
+ * @{
+ */
+/**
+ * @}
+ */
+
+/** @defgroup STM32L152_EVAL_I2C_TSENSOR_Private_Variables
+ * @{
+ */
+
+__IO uint32_t LM75_Timeout = LM75_LONG_TIMEOUT;
+/**
+ * @}
+ */
+
+/** @defgroup STM32L152_EVAL_I2C_TSENSOR_Private_Function_Prototypes
+ * @{
+ */
+static void LM75_DMA_Config(LM75_DMADirection_TypeDef Direction, uint8_t* buffer, uint8_t NumData);
+
+/**
+ * @}
+ */
+
+
+/** @defgroup STM32L152_EVAL_I2C_TSENSOR_Private_Functions
+ * @{
+ */
+
+/**
+ * @brief DeInitializes the LM75_I2C.
+ * @param None
+ * @retval None
+ */
+void LM75_DeInit(void)
+{
+ LM75_LowLevel_DeInit();
+}
+
+/**
+ * @brief Initializes the LM75_I2C.
+ * @param None
+ * @retval None
+ */
+void LM75_Init(void)
+{
+ I2C_InitTypeDef I2C_InitStructure;
+
+ LM75_LowLevel_Init();
+
+ I2C_DeInit(LM75_I2C);
+
+ /*!< LM75_I2C Init */
+ I2C_InitStructure.I2C_Mode = I2C_Mode_SMBusHost;
+ I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;
+ I2C_InitStructure.I2C_OwnAddress1 = 0x00;
+ I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
+ I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
+ I2C_InitStructure.I2C_ClockSpeed = LM75_I2C_SPEED;
+ I2C_Init(LM75_I2C, &I2C_InitStructure);
+
+ /*!< Enable SMBus Alert interrupt */
+ I2C_ITConfig(LM75_I2C, I2C_IT_ERR, ENABLE);
+
+ /*!< LM75_I2C Init */
+ I2C_Cmd(LM75_I2C, ENABLE);
+}
+
+
+/**
+ * @brief Configure the DMA Peripheral used to handle communication via I2C.
+ * @param None
+ * @retval None
+ */
+
+static void LM75_DMA_Config(LM75_DMADirection_TypeDef Direction, uint8_t* buffer, uint8_t NumData)
+{
+ DMA_InitTypeDef DMA_InitStructure;
+
+ RCC_AHBPeriphClockCmd(LM75_DMA_CLK, ENABLE);
+
+ /* Initialize the DMA_PeripheralBaseAddr member */
+ DMA_InitStructure.DMA_PeripheralBaseAddr = LM75_I2C_DR;
+ /* Initialize the DMA_MemoryBaseAddr member */
+ DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)buffer;
+ /* Initialize the DMA_PeripheralInc member */
+ DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
+ /* Initialize the DMA_MemoryInc member */
+ DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
+ /* Initialize the DMA_PeripheralDataSize member */
+ DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
+ /* Initialize the DMA_MemoryDataSize member */
+ DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
+ /* Initialize the DMA_Mode member */
+ DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
+ /* Initialize the DMA_Priority member */
+ DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh;
+ /* Initialize the DMA_M2M member */
+ DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
+
+ /* If using DMA for Reception */
+ if (Direction == LM75_DMA_RX)
+ {
+ /* Initialize the DMA_DIR member */
+ DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
+
+ /* Initialize the DMA_BufferSize member */
+ DMA_InitStructure.DMA_BufferSize = NumData;
+
+ DMA_DeInit(LM75_DMA_RX_CHANNEL);
+
+ DMA_Init(LM75_DMA_RX_CHANNEL, &DMA_InitStructure);
+ }
+ /* If using DMA for Transmission */
+ else if (Direction == LM75_DMA_TX)
+ {
+ /* Initialize the DMA_DIR member */
+ DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
+
+ /* Initialize the DMA_BufferSize member */
+ DMA_InitStructure.DMA_BufferSize = NumData;
+
+ DMA_DeInit(LM75_DMA_TX_CHANNEL);
+
+ DMA_Init(LM75_DMA_TX_CHANNEL, &DMA_InitStructure);
+ }
+}
+
+
+/**
+ * @brief Checks the LM75 status.
+ * @param None
+ * @retval ErrorStatus: LM75 Status (ERROR or SUCCESS).
+ */
+ErrorStatus LM75_GetStatus(void)
+{
+ uint32_t I2C_TimeOut = I2C_TIMEOUT;
+
+ /*!< Clear the LM75_I2C AF flag */
+ I2C_ClearFlag(LM75_I2C, I2C_FLAG_AF);
+
+ /*!< Enable LM75_I2C acknowledgement if it is already disabled by other function */
+ I2C_AcknowledgeConfig(LM75_I2C, ENABLE);
+
+ /*---------------------------- Transmission Phase ---------------------------*/
+
+ /*!< Send LM75_I2C START condition */
+ I2C_GenerateSTART(LM75_I2C, ENABLE);
+
+ /*!< Test on LM75_I2C EV5 and clear it */
+ while ((!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_SB)) && I2C_TimeOut) /*!< EV5 */
+ {
+ I2C_TimeOut--;
+ }
+ if (I2C_TimeOut == 0)
+ {
+ return ERROR;
+ }
+
+ I2C_TimeOut = I2C_TIMEOUT;
+
+ /*!< Send STLM75 slave address for write */
+ I2C_Send7bitAddress(LM75_I2C, LM75_ADDR, I2C_Direction_Transmitter);
+
+ while ((!I2C_CheckEvent(LM75_I2C, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)) && I2C_TimeOut)/* EV6 */
+ {
+ I2C_TimeOut--;
+ }
+
+ if ((I2C_GetFlagStatus(LM75_I2C, I2C_FLAG_AF) != 0x00) || (I2C_TimeOut == 0))
+ {
+ return ERROR;
+ }
+ else
+ {
+ return SUCCESS;
+ }
+}
+/**
+ * @brief Read the specified register from the LM75.
+ * @param RegName: specifies the LM75 register to be read.
+ * This member can be one of the following values:
+ * - LM75_REG_TEMP: temperature register
+ * - LM75_REG_TOS: Over-limit temperature register
+ * - LM75_REG_THYS: Hysteresis temperature register
+ * @retval LM75 register value.
+ */
+uint16_t LM75_ReadReg(uint8_t RegName)
+{
+ uint8_t LM75_BufferRX[2] ={0,0};
+ uint16_t tmp = 0;
+
+ /* Test on BUSY Flag */
+ LM75_Timeout = LM75_LONG_TIMEOUT;
+ while (I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BUSY))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Configure DMA Peripheral */
+ LM75_DMA_Config(LM75_DMA_RX, (uint8_t*)LM75_BufferRX, 2);
+
+ /* Enable DMA NACK automatic generation */
+ I2C_DMALastTransferCmd(LM75_I2C, ENABLE);
+
+ /* Enable the I2C peripheral */
+ I2C_GenerateSTART(LM75_I2C, ENABLE);
+
+ /* Test on SB Flag */
+ LM75_Timeout = LM75_FLAG_TIMEOUT;
+ while (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_SB))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Send device address for write */
+ I2C_Send7bitAddress(LM75_I2C, LM75_ADDR, I2C_Direction_Transmitter);
+
+ /* Test on ADDR Flag */
+ LM75_Timeout = LM75_FLAG_TIMEOUT;
+ while (!I2C_CheckEvent(LM75_I2C, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Send the device's internal address to write to */
+ I2C_SendData(LM75_I2C, RegName);
+
+ /* Test on TXE FLag (data sent) */
+ LM75_Timeout = LM75_FLAG_TIMEOUT;
+ while ((!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_TXE)) && (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BTF)))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Send START condition a second time */
+ I2C_GenerateSTART(LM75_I2C, ENABLE);
+
+ /* Test on SB Flag */
+ LM75_Timeout = LM75_FLAG_TIMEOUT;
+ while (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_SB))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Send LM75 address for read */
+ I2C_Send7bitAddress(LM75_I2C, LM75_ADDR, I2C_Direction_Receiver);
+
+ /* Test on ADDR Flag */
+ LM75_Timeout = LM75_FLAG_TIMEOUT;
+ while (!I2C_CheckEvent(LM75_I2C, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Enable I2C DMA request */
+ I2C_DMACmd(LM75_I2C,ENABLE);
+
+ /* Enable DMA RX Channel */
+ DMA_Cmd(LM75_DMA_RX_CHANNEL, ENABLE);
+
+ /* Wait until DMA Transfer Complete */
+ LM75_Timeout = LM75_LONG_TIMEOUT;
+ while (!DMA_GetFlagStatus(LM75_DMA_RX_TCFLAG))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Send STOP Condition */
+ I2C_GenerateSTOP(LM75_I2C, ENABLE);
+
+ /* Disable DMA RX Channel */
+ DMA_Cmd(LM75_DMA_RX_CHANNEL, DISABLE);
+
+ /* Disable I2C DMA request */
+ I2C_DMACmd(LM75_I2C,DISABLE);
+
+ /* Clear DMA RX Transfer Complete Flag */
+ DMA_ClearFlag(LM75_DMA_RX_TCFLAG);
+
+ /*!< Store LM75_I2C received data */
+ tmp = (uint16_t)(LM75_BufferRX[0] << 8);
+ tmp |= LM75_BufferRX[1];
+
+ /* return a Reg value */
+ return (uint16_t)tmp;
+}
+
+/**
+ * @brief Write to the specified register of the LM75.
+ * @param RegName: specifies the LM75 register to be written.
+ * This member can be one of the following values:
+ * - LM75_REG_TOS: Over-limit temperature register
+ * - LM75_REG_THYS: Hysteresis temperature register
+ * @param RegValue: value to be written to LM75 register.
+ * @retval None
+ */
+uint8_t LM75_WriteReg(uint8_t RegName, uint16_t RegValue)
+{
+ uint8_t LM75_BufferTX[2] ={0,0};
+ LM75_BufferTX[0] = (uint8_t)(RegValue >> 8);
+ LM75_BufferTX[1] = (uint8_t)(RegValue);
+
+ /* Test on BUSY Flag */
+ LM75_Timeout = LM75_LONG_TIMEOUT;
+ while (I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BUSY))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Configure DMA Peripheral */
+ LM75_DMA_Config(LM75_DMA_TX, (uint8_t*)LM75_BufferTX, 2);
+
+ /* Enable the I2C peripheral */
+ I2C_GenerateSTART(LM75_I2C, ENABLE);
+
+ /* Test on SB Flag */
+ LM75_Timeout = LM75_FLAG_TIMEOUT;
+ while (I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_SB) == RESET)
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Transmit the slave address and enable writing operation */
+ I2C_Send7bitAddress(LM75_I2C, LM75_ADDR, I2C_Direction_Transmitter);
+
+ /* Test on ADDR Flag */
+ LM75_Timeout = LM75_FLAG_TIMEOUT;
+ while (!I2C_CheckEvent(LM75_I2C, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Transmit the first address for r/w operations */
+ I2C_SendData(LM75_I2C, RegName);
+
+ /* Test on TXE FLag (data sent) */
+ LM75_Timeout = LM75_FLAG_TIMEOUT;
+ while ((!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_TXE)) && (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BTF)))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Enable I2C DMA request */
+ I2C_DMACmd(LM75_I2C,ENABLE);
+
+ /* Enable DMA TX Channel */
+ DMA_Cmd(LM75_DMA_TX_CHANNEL, ENABLE);
+
+ /* Wait until DMA Transfer Complete */
+ LM75_Timeout = LM75_LONG_TIMEOUT;
+ while (!DMA_GetFlagStatus(LM75_DMA_TX_TCFLAG))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Wait until BTF Flag is set before generating STOP */
+ LM75_Timeout = LM75_LONG_TIMEOUT;
+ while (I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BTF))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Send STOP Condition */
+ I2C_GenerateSTOP(LM75_I2C, ENABLE);
+
+ /* Disable DMA TX Channel */
+ DMA_Cmd(LM75_DMA_TX_CHANNEL, DISABLE);
+
+ /* Disable I2C DMA request */
+ I2C_DMACmd(LM75_I2C,DISABLE);
+
+ /* Clear DMA TX Transfer Complete Flag */
+ DMA_ClearFlag(LM75_DMA_TX_TCFLAG);
+
+ return LM75_OK;
+}
+
+/**
+ * @brief Read Temperature register of LM75: double temperature value.
+ * @param None
+ * @retval LM75 measured temperature value.
+ */
+uint16_t LM75_ReadTemp(void)
+{
+ uint8_t LM75_BufferRX[2] ={0,0};
+ uint16_t tmp = 0;
+
+ /* Test on BUSY Flag */
+ LM75_Timeout = LM75_LONG_TIMEOUT;
+ while (I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BUSY))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Configure DMA Peripheral */
+ LM75_DMA_Config(LM75_DMA_RX, (uint8_t*)LM75_BufferRX, 2);
+
+ /* Enable DMA NACK automatic generation */
+ I2C_DMALastTransferCmd(LM75_I2C, ENABLE);
+
+ /* Enable the I2C peripheral */
+ I2C_GenerateSTART(LM75_I2C, ENABLE);
+
+ /* Test on SB Flag */
+ LM75_Timeout = LM75_FLAG_TIMEOUT;
+ while (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_SB))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Send device address for write */
+ I2C_Send7bitAddress(LM75_I2C, LM75_ADDR, I2C_Direction_Transmitter);
+
+ /* Test on ADDR Flag */
+ LM75_Timeout = LM75_FLAG_TIMEOUT;
+ while (!I2C_CheckEvent(LM75_I2C, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Send the device's internal address to write to */
+ I2C_SendData(LM75_I2C, LM75_REG_TEMP);
+
+ /* Test on TXE FLag (data sent) */
+ LM75_Timeout = LM75_FLAG_TIMEOUT;
+ while ((!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_TXE)) && (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BTF)))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Send START condition a second time */
+ I2C_GenerateSTART(LM75_I2C, ENABLE);
+
+ /* Test on SB Flag */
+ LM75_Timeout = LM75_FLAG_TIMEOUT;
+ while (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_SB))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Send LM75 address for read */
+ I2C_Send7bitAddress(LM75_I2C, LM75_ADDR, I2C_Direction_Receiver);
+
+ /* Test on ADDR Flag */
+ LM75_Timeout = LM75_FLAG_TIMEOUT;
+ while (!I2C_CheckEvent(LM75_I2C, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Enable I2C DMA request */
+ I2C_DMACmd(LM75_I2C,ENABLE);
+
+ /* Enable DMA RX Channel */
+ DMA_Cmd(LM75_DMA_RX_CHANNEL, ENABLE);
+
+ /* Wait until DMA Transfer Complete */
+ LM75_Timeout = LM75_LONG_TIMEOUT;
+ while (!DMA_GetFlagStatus(LM75_DMA_RX_TCFLAG))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Send STOP Condition */
+ I2C_GenerateSTOP(LM75_I2C, ENABLE);
+
+ /* Disable DMA RX Channel */
+ DMA_Cmd(LM75_DMA_RX_CHANNEL, DISABLE);
+
+ /* Disable I2C DMA request */
+ I2C_DMACmd(LM75_I2C,DISABLE);
+
+ /* Clear DMA RX Transfer Complete Flag */
+ DMA_ClearFlag(LM75_DMA_RX_TCFLAG);
+
+ /*!< Store LM75_I2C received data */
+ tmp = (uint16_t)(LM75_BufferRX[0] << 8);
+ tmp |= LM75_BufferRX[1];
+
+ /*!< Return Temperature value */
+ return (uint16_t)(tmp >> 7);
+}
+
+/**
+ * @brief Read the configuration register from the LM75.
+ * @param None
+ * @retval LM75 configuration register value.
+ */
+uint8_t LM75_ReadConfReg(void)
+{
+ uint8_t LM75_BufferRX[2] ={0,0};
+
+ /* Test on BUSY Flag */
+ LM75_Timeout = LM75_LONG_TIMEOUT;
+ while (I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BUSY))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Configure DMA Peripheral */
+ LM75_DMA_Config(LM75_DMA_RX, (uint8_t*)LM75_BufferRX, 2);
+
+ /* Enable DMA NACK automatic generation */
+ I2C_DMALastTransferCmd(LM75_I2C, ENABLE);
+
+ /* Enable the I2C peripheral */
+ I2C_GenerateSTART(LM75_I2C, ENABLE);
+
+ /* Test on SB Flag */
+ LM75_Timeout = LM75_FLAG_TIMEOUT;
+ while (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_SB))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Send device address for write */
+ I2C_Send7bitAddress(LM75_I2C, LM75_ADDR, I2C_Direction_Transmitter);
+
+ /* Test on ADDR Flag */
+ LM75_Timeout = LM75_FLAG_TIMEOUT;
+ while (!I2C_CheckEvent(LM75_I2C, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Send the device's internal address to write to */
+ I2C_SendData(LM75_I2C, LM75_REG_CONF);
+
+ /* Test on TXE FLag (data sent) */
+ LM75_Timeout = LM75_FLAG_TIMEOUT;
+ while ((!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_TXE)) && (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BTF)))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Send START condition a second time */
+ I2C_GenerateSTART(LM75_I2C, ENABLE);
+
+ /* Test on SB Flag */
+ LM75_Timeout = LM75_FLAG_TIMEOUT;
+ while (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_SB))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Send LM75 address for read */
+ I2C_Send7bitAddress(LM75_I2C, LM75_ADDR, I2C_Direction_Receiver);
+
+ /* Test on ADDR Flag */
+ LM75_Timeout = LM75_FLAG_TIMEOUT;
+ while (!I2C_CheckEvent(LM75_I2C, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Enable I2C DMA request */
+ I2C_DMACmd(LM75_I2C,ENABLE);
+
+ /* Enable DMA RX Channel */
+ DMA_Cmd(LM75_DMA_RX_CHANNEL, ENABLE);
+
+ /* Wait until DMA Transfer Complete */
+ LM75_Timeout = LM75_LONG_TIMEOUT;
+ while (!DMA_GetFlagStatus(LM75_DMA_RX_TCFLAG))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Send STOP Condition */
+ I2C_GenerateSTOP(LM75_I2C, ENABLE);
+
+ /* Disable DMA RX Channel */
+ DMA_Cmd(LM75_DMA_RX_CHANNEL, DISABLE);
+
+ /* Disable I2C DMA request */
+ I2C_DMACmd(LM75_I2C,DISABLE);
+
+ /* Clear DMA RX Transfer Complete Flag */
+ DMA_ClearFlag(LM75_DMA_RX_TCFLAG);
+
+ /*!< Return Temperature value */
+ return (uint8_t)LM75_BufferRX[0];
+}
+
+/**
+ * @brief Write to the configuration register of the LM75.
+ * @param RegValue: sepecifies the value to be written to LM75 configuration
+ * register.
+ * @retval None
+ */
+uint8_t LM75_WriteConfReg(uint8_t RegValue)
+{
+ uint8_t LM75_BufferTX = 0;
+ LM75_BufferTX = (uint8_t)(RegValue);
+
+ /* Test on BUSY Flag */
+ LM75_Timeout = LM75_LONG_TIMEOUT;
+ while (I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BUSY))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Configure DMA Peripheral */
+ LM75_DMA_Config(LM75_DMA_TX, (uint8_t*)(&LM75_BufferTX), 1);
+
+ /* Enable the I2C peripheral */
+ I2C_GenerateSTART(LM75_I2C, ENABLE);
+
+ /* Test on SB Flag */
+ LM75_Timeout = LM75_FLAG_TIMEOUT;
+ while (I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_SB) == RESET)
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Transmit the slave address and enable writing operation */
+ I2C_Send7bitAddress(LM75_I2C, LM75_ADDR, I2C_Direction_Transmitter);
+
+ /* Test on ADDR Flag */
+ LM75_Timeout = LM75_FLAG_TIMEOUT;
+ while (!I2C_CheckEvent(LM75_I2C, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Transmit the first address for r/w operations */
+ I2C_SendData(LM75_I2C, LM75_REG_CONF);
+
+ /* Test on TXE FLag (data sent) */
+ LM75_Timeout = LM75_FLAG_TIMEOUT;
+ while ((!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_TXE)) && (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BTF)))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Enable I2C DMA request */
+ I2C_DMACmd(LM75_I2C,ENABLE);
+
+ /* Enable DMA TX Channel */
+ DMA_Cmd(LM75_DMA_TX_CHANNEL, ENABLE);
+
+ /* Wait until DMA Transfer Complete */
+ LM75_Timeout = LM75_LONG_TIMEOUT;
+ while (!DMA_GetFlagStatus(LM75_DMA_TX_TCFLAG))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Wait until BTF Flag is set before generating STOP */
+ LM75_Timeout = LM75_LONG_TIMEOUT;
+ while ((!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BTF)))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Send STOP Condition */
+ I2C_GenerateSTOP(LM75_I2C, ENABLE);
+
+ /* Disable DMA TX Channel */
+ DMA_Cmd(LM75_DMA_TX_CHANNEL, DISABLE);
+
+ /* Disable I2C DMA request */
+ I2C_DMACmd(LM75_I2C,DISABLE);
+
+ /* Clear DMA TX Transfer Complete Flag */
+ DMA_ClearFlag(LM75_DMA_TX_TCFLAG);
+
+ return LM75_OK;
+
+}
+
+/**
+ * @brief Enables or disables the LM75.
+ * @param NewState: specifies the LM75 new status. This parameter can be ENABLE
+ * or DISABLE.
+ * @retval None
+ */
+uint8_t LM75_ShutDown(FunctionalState NewState)
+{
+ uint8_t LM75_BufferRX[2] ={0,0};
+ uint8_t LM75_BufferTX = 0;
+ __IO uint8_t RegValue = 0;
+
+ /* Test on BUSY Flag */
+ LM75_Timeout = LM75_LONG_TIMEOUT;
+ while (I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BUSY))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Configure DMA Peripheral */
+ LM75_DMA_Config(LM75_DMA_RX, (uint8_t*)LM75_BufferRX, 2);
+
+ /* Enable DMA NACK automatic generation */
+ I2C_DMALastTransferCmd(LM75_I2C, ENABLE);
+
+ /* Enable the I2C peripheral */
+ I2C_GenerateSTART(LM75_I2C, ENABLE);
+
+ /* Test on SB Flag */
+ LM75_Timeout = LM75_FLAG_TIMEOUT;
+ while (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_SB))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Send device address for write */
+ I2C_Send7bitAddress(LM75_I2C, LM75_ADDR, I2C_Direction_Transmitter);
+
+ /* Test on ADDR Flag */
+ LM75_Timeout = LM75_FLAG_TIMEOUT;
+ while (!I2C_CheckEvent(LM75_I2C, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Send the device's internal address to write to */
+ I2C_SendData(LM75_I2C, LM75_REG_CONF);
+
+ /* Test on TXE FLag (data sent) */
+ LM75_Timeout = LM75_FLAG_TIMEOUT;
+ while ((!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_TXE)) && (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BTF)))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Send START condition a second time */
+ I2C_GenerateSTART(LM75_I2C, ENABLE);
+
+ /* Test on SB Flag */
+ LM75_Timeout = LM75_FLAG_TIMEOUT;
+ while (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_SB))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Send LM75 address for read */
+ I2C_Send7bitAddress(LM75_I2C, LM75_ADDR, I2C_Direction_Receiver);
+
+ /* Test on ADDR Flag */
+ LM75_Timeout = LM75_FLAG_TIMEOUT;
+ while (!I2C_CheckEvent(LM75_I2C, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Enable I2C DMA request */
+ I2C_DMACmd(LM75_I2C,ENABLE);
+
+ /* Enable DMA RX Channel */
+ DMA_Cmd(LM75_DMA_RX_CHANNEL, ENABLE);
+
+ /* Wait until DMA Transfer Complete */
+ LM75_Timeout = LM75_LONG_TIMEOUT;
+ while (!DMA_GetFlagStatus(LM75_DMA_RX_TCFLAG))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Send STOP Condition */
+ I2C_GenerateSTOP(LM75_I2C, ENABLE);
+
+ /* Disable DMA RX Channel */
+ DMA_Cmd(LM75_DMA_RX_CHANNEL, DISABLE);
+
+ /* Disable I2C DMA request */
+ I2C_DMACmd(LM75_I2C,DISABLE);
+
+ /* Clear DMA RX Transfer Complete Flag */
+ DMA_ClearFlag(LM75_DMA_RX_TCFLAG);
+
+ /*!< Get received data */
+ RegValue = (uint8_t)LM75_BufferRX[0];
+
+ /*---------------------------- Transmission Phase ---------------------------*/
+
+ /*!< Enable or disable SD bit */
+ if (NewState != DISABLE)
+ {
+ /*!< Enable LM75 */
+ LM75_BufferTX = RegValue & LM75_SD_RESET;
+ }
+ else
+ {
+ /*!< Disable LM75 */
+ LM75_BufferTX = RegValue | LM75_SD_SET;
+ }
+
+ /* Test on BUSY Flag */
+ LM75_Timeout = LM75_LONG_TIMEOUT;
+ while (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BUSY))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Configure DMA Peripheral */
+ LM75_DMA_Config(LM75_DMA_TX, (uint8_t*)(&LM75_BufferTX), 1);
+
+ /* Enable the I2C peripheral */
+ I2C_GenerateSTART(LM75_I2C, ENABLE);
+
+ /* Test on SB Flag */
+ LM75_Timeout = LM75_FLAG_TIMEOUT;
+ while (I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_SB) == RESET)
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Transmit the slave address and enable writing operation */
+ I2C_Send7bitAddress(LM75_I2C, LM75_ADDR, I2C_Direction_Transmitter);
+
+ /* Test on ADDR Flag */
+ LM75_Timeout = LM75_FLAG_TIMEOUT;
+ while (!I2C_CheckEvent(LM75_I2C, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Transmit the first address for r/w operations */
+ I2C_SendData(LM75_I2C, LM75_REG_CONF);
+
+ /* Test on TXE FLag (data sent) */
+ LM75_Timeout = LM75_FLAG_TIMEOUT;
+ while ((!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_TXE)) && (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BTF)))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Enable I2C DMA request */
+ I2C_DMACmd(LM75_I2C,ENABLE);
+
+ /* Enable DMA TX Channel */
+ DMA_Cmd(LM75_DMA_TX_CHANNEL, ENABLE);
+
+ /* Wait until DMA Transfer Complete */
+ LM75_Timeout = LM75_LONG_TIMEOUT;
+ while (!DMA_GetFlagStatus(LM75_DMA_TX_TCFLAG))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Wait until BTF Flag is set before generating STOP */
+ LM75_Timeout = LM75_LONG_TIMEOUT;
+ while ((!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BTF)))
+ {
+ if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
+ }
+
+ /* Send STOP Condition */
+ I2C_GenerateSTOP(LM75_I2C, ENABLE);
+
+ /* Disable DMA TX Channel */
+ DMA_Cmd(LM75_DMA_TX_CHANNEL, DISABLE);
+
+ /* Disable I2C DMA request */
+ I2C_DMACmd(LM75_I2C,DISABLE);
+
+ /* Clear DMA TX Transfer Complete Flag */
+ DMA_ClearFlag(LM75_DMA_TX_TCFLAG);
+
+ return LM75_OK;
+}
+
+/**
+ * @}
+ */
+
+
+/**
+ * @}
+ */
+
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152_EVAL/stm32l152_eval_i2c_tsensor.h b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152_EVAL/stm32l152_eval_i2c_tsensor.h
new file mode 100644
index 0000000..668ac91
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152_EVAL/stm32l152_eval_i2c_tsensor.h
@@ -0,0 +1,179 @@
+/**
+ ******************************************************************************
+ * @file stm32l152_eval_i2c_tsensor.h
+ * @author MCD Application Team
+ * @version V5.0.2
+ * @date 09-March-2012
+ * @brief This file contains all the functions prototypes for the
+ * stm32l152_eval_i2c_tsensor firmware driver.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.st.com/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __STM32L152_EVAL_I2C_TSENSOR_H
+#define __STM32L152_EVAL_I2C_TSENSOR_H
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+/* Includes ------------------------------------------------------------------*/
+#include "stm32l152_eval.h"
+
+/** @addtogroup Utilities
+ * @{
+ */
+
+/** @addtogroup STM32_EVAL
+ * @{
+ */
+
+/** @addtogroup STM32L152_EVAL
+ * @{
+ */
+
+/** @addtogroup STM32L152_EVAL_I2C_TSENSOR
+ * @{
+ */
+
+/** @defgroup STM32L152_EVAL_I2C_TSENSOR_Exported_Types
+ * @{
+ */
+
+ /**
+ * @brief IOE DMA Direction
+ */
+typedef enum
+{
+ LM75_DMA_TX = 0,
+ LM75_DMA_RX = 1
+}LM75_DMADirection_TypeDef;
+
+/**
+ * @brief TSENSOR Status
+ */
+typedef enum
+{
+ LM75_OK = 0,
+ LM75_FAIL
+}LM75_Status_TypDef;
+
+/**
+ * @}
+ */
+
+/** @defgroup STM32L152_EVAL_I2C_TSENSOR_Exported_Constants
+ * @{
+ */
+
+/* Uncomment the following line to use Timeout_User_Callback LM75_TimeoutUserCallback().
+ If This Callback is enabled, it should be implemented by user in main function .
+ LM75_TimeoutUserCallback() function is called whenever a timeout condition
+ occure during communication (waiting on an event that doesn't occur, bus
+ errors, busy devices ...). */
+/* #define USE_TIMEOUT_USER_CALLBACK */
+
+/* Maximum Timeout values for flags and events waiting loops. These timeouts are
+ not based on accurate values, they just guarantee that the application will
+ not remain stuck if the I2C communication is corrupted.
+ You may modify these timeout values depending on CPU frequency and application
+ conditions (interrupts routines ...). */
+#define LM75_FLAG_TIMEOUT ((uint32_t)0x1000)
+#define LM75_LONG_TIMEOUT ((uint32_t)(10 * LM75_FLAG_TIMEOUT))
+
+
+/**
+ * @brief Block Size
+ */
+#define LM75_REG_TEMP 0x00 /*!< Temperature Register of LM75 */
+#define LM75_REG_CONF 0x01 /*!< Configuration Register of LM75 */
+#define LM75_REG_THYS 0x02 /*!< Temperature Register of LM75 */
+#define LM75_REG_TOS 0x03 /*!< Over-temp Shutdown threshold Register of LM75 */
+#define I2C_TIMEOUT ((uint32_t)0x3FFFF) /*!< I2C Time out */
+#define LM75_ADDR 0x90 /*!< LM75 address */
+#define LM75_I2C_SPEED 100000 /*!< I2C Speed */
+
+
+
+/**
+ * @}
+ */
+
+/** @defgroup STM32L152_EVAL_I2C_TSENSOR_Exported_Macros
+ * @{
+ */
+/**
+ * @}
+ */
+
+/** @defgroup STM32L152_EVAL_I2C_TSENSOR_Exported_Functions
+ * @{
+ */
+void LM75_DeInit(void);
+void LM75_Init(void);
+ErrorStatus LM75_GetStatus(void);
+uint16_t LM75_ReadTemp(void);
+uint16_t LM75_ReadReg(uint8_t RegName);
+uint8_t LM75_WriteReg(uint8_t RegName, uint16_t RegValue);
+uint8_t LM75_ReadConfReg(void);
+uint8_t LM75_WriteConfReg(uint8_t RegValue);
+uint8_t LM75_ShutDown(FunctionalState NewState);
+
+/**
+ * @brief Timeout user callback function. This function is called when a timeout
+ * condition occurs during communication with IO Expander. Only protoype
+ * of this function is decalred in IO Expander driver. Its implementation
+ * may be done into user application. This function may typically stop
+ * current operations and reset the I2C peripheral and IO Expander.
+ * To enable this function use uncomment the define USE_TIMEOUT_USER_CALLBACK
+ * at the top of this file.
+ */
+#ifdef USE_TIMEOUT_USER_CALLBACK
+ uint8_t LM75_TIMEOUT_UserCallback(void);
+#else
+ #define LM75_TIMEOUT_UserCallback() LM75_FAIL
+#endif /* USE_TIMEOUT_USER_CALLBACK */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __STM32L152_EVAL_I2C_TSENSOR_H */
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152_EVAL/stm32l152_eval_lcd.c b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152_EVAL/stm32l152_eval_lcd.c
new file mode 100644
index 0000000..1572a8e
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152_EVAL/stm32l152_eval_lcd.c
@@ -0,0 +1,1624 @@
+/**
+ ******************************************************************************
+ * @file stm32l152_eval_lcd.c
+ * @author MCD Application Team
+ * @version V5.0.2
+ * @date 09-March-2012
+ * @brief This file includes the LCD driver for AM-240320L8TNQW00H (LCD_ILI9320),
+ * AM-240320LDTNQW00H (LCD_SPFD5408B) and AM240320D5TOQW01H (LCD_ILI9325)
+ * Liquid Crystal Display Module of STM32L152-EVAL board RevB.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.st.com/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+
+/* Includes ------------------------------------------------------------------*/
+#include "stm32l152_eval_lcd.h"
+#include "../Common/fonts.c"
+
+/** @addtogroup Utilities
+ * @{
+ */
+
+/** @addtogroup STM32_EVAL
+ * @{
+ */
+
+/** @addtogroup STM32L152_EVAL
+ * @{
+ */
+
+/** @defgroup STM32L152_EVAL_LCD
+ * @brief This file includes the LCD driver for AM-240320L8TNQW00H (LCD_ILI9320),
+ * AM-240320LDTNQW00H (LCD_SPFD5408B) and AM240320D5TOQW01H (LCD_ILI9325)
+ * Liquid Crystal Display Module of STM32L152-EVAL board.
+ * @{
+ */
+
+/** @defgroup STM32L152_EVAL_LCD_Private_Types
+ * @{
+ */
+/**
+ * @}
+ */
+
+/** @defgroup STM32L152_EVAL_LCD_Private_Defines
+ * @{
+ */
+#define LCD_ILI9325 0x9325
+#define LCD_ILI9320 0x9320
+#define LCD_SPFD5408 0x5408
+#define START_BYTE 0x70
+#define SET_INDEX 0x00
+#define READ_STATUS 0x01
+#define LCD_WRITE_REG 0x02
+#define LCD_READ_REG 0x03
+#define MAX_POLY_CORNERS 200
+#define POLY_Y(Z) ((int32_t)((Points + Z)->X))
+#define POLY_X(Z) ((int32_t)((Points + Z)->Y))
+/**
+ * @}
+ */
+
+/** @defgroup STM32L152_EVAL_LCD_Private_Macros
+ * @{
+ */
+#define ABS(X) ((X) > 0 ? (X) : -(X))
+/**
+ * @}
+ */
+
+/** @defgroup STM32L152_EVAL_LCD_Private_Variables
+ * @{
+ */
+static sFONT *LCD_Currentfonts;
+/* Global variables to set the written text color */
+static __IO uint16_t TextColor = 0x0000, BackColor = 0xFFFF;
+static __IO uint32_t LCDType = LCD_SPFD5408;
+/**
+ * @}
+ */
+
+/** @defgroup STM32L152_EVAL_LCD_Private_Function_Prototypes
+ * @{
+ */
+#ifndef USE_Delay
+static void delay(__IO uint32_t nCount);
+#endif /* USE_Delay*/
+
+static void PutPixel(int16_t x, int16_t y);
+static void LCD_PolyLineRelativeClosed(pPoint Points, uint16_t PointCount, uint16_t Closed);
+
+/**
+ * @}
+ */
+
+/** @defgroup STM32L152_EVAL_LCD_Private_Functions
+ * @{
+ */
+
+/**
+ * @brief DeInitializes the LCD.
+ * @param None
+ * @retval None
+ */
+void STM32L152_LCD_DeInit(void)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+
+ /*!< LCD Display Off */
+ LCD_DisplayOff();
+
+ /*!< LCD_SPI disable */
+ SPI_Cmd(LCD_SPI, DISABLE);
+
+ /*!< LCD_SPI DeInit */
+ SPI_DeInit(LCD_SPI);
+
+ /*!< Disable SPI clock */
+ RCC_APB1PeriphClockCmd(LCD_SPI_CLK, DISABLE);
+
+ /* Configure NCS in Output Push-Pull mode */
+ GPIO_InitStructure.GPIO_Pin = LCD_NCS_PIN;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
+ GPIO_Init(LCD_NCS_GPIO_PORT, &GPIO_InitStructure);
+
+ /* Configure SPI pins: SCK, MISO and MOSI */
+ GPIO_InitStructure.GPIO_Pin = LCD_SPI_SCK_PIN;
+ GPIO_Init(LCD_SPI_SCK_GPIO_PORT, &GPIO_InitStructure);
+
+ GPIO_InitStructure.GPIO_Pin = LCD_SPI_MISO_PIN;
+ GPIO_Init(LCD_SPI_MISO_GPIO_PORT, &GPIO_InitStructure);
+
+ GPIO_InitStructure.GPIO_Pin = LCD_SPI_MOSI_PIN;
+ GPIO_Init(LCD_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure);
+}
+
+/**
+ * @brief Setups the LCD.
+ * @param None
+ * @retval None
+ */
+void LCD_Setup(void)
+{
+/* Configure the LCD Control pins --------------------------------------------*/
+ LCD_CtrlLinesConfig();
+
+/* Configure the LCD_SPI interface ----------------------------------------------*/
+ LCD_SPIConfig();
+
+ if(LCDType == LCD_SPFD5408)
+ {
+ /* Start Initial Sequence --------------------------------------------------*/
+ LCD_WriteReg(LCD_REG_227, 0x3008); /* Set internal timing */
+ LCD_WriteReg(LCD_REG_231, 0x0012); /* Set internal timing */
+ LCD_WriteReg(LCD_REG_239, 0x1231); /* Set internal timing */
+ LCD_WriteReg(LCD_REG_1, 0x0100); /* Set SS and SM bit */
+ LCD_WriteReg(LCD_REG_2, 0x0700); /* Set 1 line inversion */
+ LCD_WriteReg(LCD_REG_3, 0x1030); /* Set GRAM write direction and BGR=1. */
+ LCD_WriteReg(LCD_REG_4, 0x0000); /* Resize register */
+ LCD_WriteReg(LCD_REG_8, 0x0202); /* Set the back porch and front porch */
+ LCD_WriteReg(LCD_REG_9, 0x0000); /* Set non-display area refresh cycle ISC[3:0] */
+ LCD_WriteReg(LCD_REG_10, 0x0000); /* FMARK function */
+ LCD_WriteReg(LCD_REG_12, 0x0000); /* RGB interface setting */
+ LCD_WriteReg(LCD_REG_13, 0x0000); /* Frame marker Position */
+ LCD_WriteReg(LCD_REG_15, 0x0000); /* RGB interface polarity */
+ /* Power On sequence -------------------------------------------------------*/
+ LCD_WriteReg(LCD_REG_16, 0x0000); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
+ LCD_WriteReg(LCD_REG_17, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */
+ LCD_WriteReg(LCD_REG_18, 0x0000); /* VREG1OUT voltage */
+ LCD_WriteReg(LCD_REG_19, 0x0000); /* VDV[4:0] for VCOM amplitude */
+ _delay_(20); /* Dis-charge capacitor power voltage (200ms) */
+ LCD_WriteReg(LCD_REG_17, 0x0007); /* DC1[2:0], DC0[2:0], VC[2:0] */
+ _delay_(5); /* Delay 50 ms */
+ LCD_WriteReg(LCD_REG_16, 0x12B0); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
+ _delay_(5); /* Delay 50 ms */
+ LCD_WriteReg(LCD_REG_18, 0x01BD); /* External reference voltage= Vci */
+ _delay_(5); /* Delay 50 ms */
+ LCD_WriteReg(LCD_REG_19, 0x1400); /* VDV[4:0] for VCOM amplitude */
+ LCD_WriteReg(LCD_REG_41, 0x000E); /* VCM[4:0] for VCOMH */
+ _delay_(5); /* Delay 50 ms */
+ LCD_WriteReg(LCD_REG_32, 0x0000); /* GRAM horizontal Address */
+ LCD_WriteReg(LCD_REG_33, 0x013F); /* GRAM Vertical Address */
+ /* Adjust the Gamma Curve --------------------------------------------------*/
+ LCD_WriteReg(LCD_REG_48, 0x0007);
+ LCD_WriteReg(LCD_REG_49, 0x0302);
+ LCD_WriteReg(LCD_REG_50, 0x0105);
+ LCD_WriteReg(LCD_REG_53, 0x0206);
+ LCD_WriteReg(LCD_REG_54, 0x0808);
+ LCD_WriteReg(LCD_REG_55, 0x0206);
+ LCD_WriteReg(LCD_REG_56, 0x0504);
+ LCD_WriteReg(LCD_REG_57, 0x0007);
+ LCD_WriteReg(LCD_REG_60, 0x0105);
+ LCD_WriteReg(LCD_REG_61, 0x0808);
+ /* Set GRAM area -----------------------------------------------------------*/
+ LCD_WriteReg(LCD_REG_80, 0x0000); /* Horizontal GRAM Start Address */
+ LCD_WriteReg(LCD_REG_81, 0x00EF); /* Horizontal GRAM End Address */
+ LCD_WriteReg(LCD_REG_82, 0x0000); /* Vertical GRAM Start Address */
+ LCD_WriteReg(LCD_REG_83, 0x013F); /* Vertical GRAM End Address */
+ LCD_WriteReg(LCD_REG_96, 0xA700); /* Gate Scan Line */
+ LCD_WriteReg(LCD_REG_97, 0x0001); /* NDL,VLE, REV */
+ LCD_WriteReg(LCD_REG_106, 0x0000); /* Set scrolling line */
+ /* Partial Display Control -------------------------------------------------*/
+ LCD_WriteReg(LCD_REG_128, 0x0000);
+ LCD_WriteReg(LCD_REG_129, 0x0000);
+ LCD_WriteReg(LCD_REG_130, 0x0000);
+ LCD_WriteReg(LCD_REG_131, 0x0000);
+ LCD_WriteReg(LCD_REG_132, 0x0000);
+ LCD_WriteReg(LCD_REG_133, 0x0000);
+ /* Panel Control -----------------------------------------------------------*/
+ LCD_WriteReg(LCD_REG_144, 0x0010);
+ LCD_WriteReg(LCD_REG_146, 0x0000);
+ LCD_WriteReg(LCD_REG_147, 0x0003);
+ LCD_WriteReg(LCD_REG_149, 0x0110);
+ LCD_WriteReg(LCD_REG_151, 0x0000);
+ LCD_WriteReg(LCD_REG_152, 0x0000);
+ /* Set GRAM write direction and BGR = 1
+ I/D=01 (Horizontal : increment, Vertical : decrement)
+ AM=1 (address is updated in vertical writing direction) */
+ LCD_WriteReg(LCD_REG_3, 0x1018);
+ LCD_WriteReg(LCD_REG_7, 0x0112); /* 262K color and display ON */
+ }
+ else if(LCDType == LCD_ILI9320)
+ {
+ _delay_(5); /* Delay 50 ms */
+ /* Start Initial Sequence ------------------------------------------------*/
+ LCD_WriteReg(LCD_REG_229, 0x8000); /* Set the internal vcore voltage */
+ LCD_WriteReg(LCD_REG_0, 0x0001); /* Start internal OSC. */
+ LCD_WriteReg(LCD_REG_1, 0x0100); /* set SS and SM bit */
+ LCD_WriteReg(LCD_REG_2, 0x0700); /* set 1 line inversion */
+ LCD_WriteReg(LCD_REG_3, 0x1030); /* set GRAM write direction and BGR=1. */
+ LCD_WriteReg(LCD_REG_4, 0x0000); /* Resize register */
+ LCD_WriteReg(LCD_REG_8, 0x0202); /* set the back porch and front porch */
+ LCD_WriteReg(LCD_REG_9, 0x0000); /* set non-display area refresh cycle ISC[3:0] */
+ LCD_WriteReg(LCD_REG_10, 0x0000); /* FMARK function */
+ LCD_WriteReg(LCD_REG_12, 0x0000); /* RGB interface setting */
+ LCD_WriteReg(LCD_REG_13, 0x0000); /* Frame marker Position */
+ LCD_WriteReg(LCD_REG_15, 0x0000); /* RGB interface polarity */
+ /* Power On sequence -----------------------------------------------------*/
+ LCD_WriteReg(LCD_REG_16, 0x0000); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
+ LCD_WriteReg(LCD_REG_17, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */
+ LCD_WriteReg(LCD_REG_18, 0x0000); /* VREG1OUT voltage */
+ LCD_WriteReg(LCD_REG_19, 0x0000); /* VDV[4:0] for VCOM amplitude */
+ _delay_(20); /* Dis-charge capacitor power voltage (200ms) */
+ LCD_WriteReg(LCD_REG_16, 0x17B0); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
+ LCD_WriteReg(LCD_REG_17, 0x0137); /* DC1[2:0], DC0[2:0], VC[2:0] */
+ _delay_(5); /* Delay 50 ms */
+ LCD_WriteReg(LCD_REG_18, 0x0139); /* VREG1OUT voltage */
+ _delay_(5); /* Delay 50 ms */
+ LCD_WriteReg(LCD_REG_19, 0x1d00); /* VDV[4:0] for VCOM amplitude */
+ LCD_WriteReg(LCD_REG_41, 0x0013); /* VCM[4:0] for VCOMH */
+ _delay_(5); /* Delay 50 ms */
+ LCD_WriteReg(LCD_REG_32, 0x0000); /* GRAM horizontal Address */
+ LCD_WriteReg(LCD_REG_33, 0x0000); /* GRAM Vertical Address */
+ /* Adjust the Gamma Curve ------------------------------------------------*/
+ LCD_WriteReg(LCD_REG_48, 0x0006);
+ LCD_WriteReg(LCD_REG_49, 0x0101);
+ LCD_WriteReg(LCD_REG_50, 0x0003);
+ LCD_WriteReg(LCD_REG_53, 0x0106);
+ LCD_WriteReg(LCD_REG_54, 0x0b02);
+ LCD_WriteReg(LCD_REG_55, 0x0302);
+ LCD_WriteReg(LCD_REG_56, 0x0707);
+ LCD_WriteReg(LCD_REG_57, 0x0007);
+ LCD_WriteReg(LCD_REG_60, 0x0600);
+ LCD_WriteReg(LCD_REG_61, 0x020b);
+
+ /* Set GRAM area ---------------------------------------------------------*/
+ LCD_WriteReg(LCD_REG_80, 0x0000); /* Horizontal GRAM Start Address */
+ LCD_WriteReg(LCD_REG_81, 0x00EF); /* Horizontal GRAM End Address */
+ LCD_WriteReg(LCD_REG_82, 0x0000); /* Vertical GRAM Start Address */
+ LCD_WriteReg(LCD_REG_83, 0x013F); /* Vertical GRAM End Address */
+ LCD_WriteReg(LCD_REG_96, 0x2700); /* Gate Scan Line */
+ LCD_WriteReg(LCD_REG_97, 0x0001); /* NDL,VLE, REV */
+ LCD_WriteReg(LCD_REG_106, 0x0000); /* set scrolling line */
+ /* Partial Display Control -----------------------------------------------*/
+ LCD_WriteReg(LCD_REG_128, 0x0000);
+ LCD_WriteReg(LCD_REG_129, 0x0000);
+ LCD_WriteReg(LCD_REG_130, 0x0000);
+ LCD_WriteReg(LCD_REG_131, 0x0000);
+ LCD_WriteReg(LCD_REG_132, 0x0000);
+ LCD_WriteReg(LCD_REG_133, 0x0000);
+ /* Panel Control ---------------------------------------------------------*/
+ LCD_WriteReg(LCD_REG_144, 0x0010);
+ LCD_WriteReg(LCD_REG_146, 0x0000);
+ LCD_WriteReg(LCD_REG_147, 0x0003);
+ LCD_WriteReg(LCD_REG_149, 0x0110);
+ LCD_WriteReg(LCD_REG_151, 0x0000);
+ LCD_WriteReg(LCD_REG_152, 0x0000);
+ /* Set GRAM write direction and BGR = 1 */
+ /* I/D=01 (Horizontal : increment, Vertical : decrement) */
+ /* AM=1 (address is updated in vertical writing direction) */
+ LCD_WriteReg(LCD_REG_3, 0x1018);
+ LCD_WriteReg(LCD_REG_7, 0x0173); /* 262K color and display ON */
+ }
+ else if(LCDType == LCD_ILI9325)
+ {
+ /* Start Initial Sequence ------------------------------------------------*/
+ LCD_WriteReg(LCD_REG_0, 0x0001); /* Start internal OSC. */
+ LCD_WriteReg(LCD_REG_1, 0x0100); /* Set SS and SM bit */
+ LCD_WriteReg(LCD_REG_2, 0x0700); /* Set 1 line inversion */
+ LCD_WriteReg(LCD_REG_3, 0x1018); /* Set GRAM write direction and BGR=1. */
+ LCD_WriteReg(LCD_REG_4, 0x0000); /* Resize register */
+ LCD_WriteReg(LCD_REG_8, 0x0202); /* Set the back porch and front porch */
+ LCD_WriteReg(LCD_REG_9, 0x0000); /* Set non-display area refresh cycle ISC[3:0] */
+ LCD_WriteReg(LCD_REG_10, 0x0000); /* FMARK function */
+ LCD_WriteReg(LCD_REG_12, 0x0000); /* RGB interface setting */
+ LCD_WriteReg(LCD_REG_13, 0x0000); /* Frame marker Position */
+ LCD_WriteReg(LCD_REG_15, 0x0000); /* RGB interface polarity */
+
+ /* Power On sequence -----------------------------------------------------*/
+ LCD_WriteReg(LCD_REG_16, 0x0000); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
+ LCD_WriteReg(LCD_REG_17, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */
+ LCD_WriteReg(LCD_REG_18, 0x0000); /* VREG1OUT voltage */
+ LCD_WriteReg(LCD_REG_19, 0x0000); /* VDV[4:0] for VCOM amplitude */
+ _delay_(20); /* Dis-charge capacitor power voltage (200ms) */
+ LCD_WriteReg(LCD_REG_16, 0x17B0); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
+ LCD_WriteReg(LCD_REG_17, 0x0137); /* DC1[2:0], DC0[2:0], VC[2:0] */
+ _delay_(5); /* Delay 50 ms */
+ LCD_WriteReg(LCD_REG_18, 0x0139); /* VREG1OUT voltage */
+ _delay_(5); /* Delay 50 ms */
+ LCD_WriteReg(LCD_REG_19, 0x1d00); /* VDV[4:0] for VCOM amplitude */
+ LCD_WriteReg(LCD_REG_41, 0x0013); /* VCM[4:0] for VCOMH */
+ _delay_(5); /* Delay 50 ms */
+ LCD_WriteReg(LCD_REG_32, 0x0000); /* GRAM horizontal Address */
+ LCD_WriteReg(LCD_REG_33, 0x0000); /* GRAM Vertical Address */
+
+ /* Adjust the Gamma Curve (ILI9325)---------------------------------------*/
+ LCD_WriteReg(LCD_REG_48, 0x0007);
+ LCD_WriteReg(LCD_REG_49, 0x0302);
+ LCD_WriteReg(LCD_REG_50, 0x0105);
+ LCD_WriteReg(LCD_REG_53, 0x0206);
+ LCD_WriteReg(LCD_REG_54, 0x0808);
+ LCD_WriteReg(LCD_REG_55, 0x0206);
+ LCD_WriteReg(LCD_REG_56, 0x0504);
+ LCD_WriteReg(LCD_REG_57, 0x0007);
+ LCD_WriteReg(LCD_REG_60, 0x0105);
+ LCD_WriteReg(LCD_REG_61, 0x0808);
+
+ /* Set GRAM area ---------------------------------------------------------*/
+ LCD_WriteReg(LCD_REG_80, 0x0000); /* Horizontal GRAM Start Address */
+ LCD_WriteReg(LCD_REG_81, 0x00EF); /* Horizontal GRAM End Address */
+ LCD_WriteReg(LCD_REG_82, 0x0000); /* Vertical GRAM Start Address */
+ LCD_WriteReg(LCD_REG_83, 0x013F); /* Vertical GRAM End Address */
+
+ LCD_WriteReg(LCD_REG_96, 0xA700); /* Gate Scan Line(GS=1, scan direction is G320~G1) */
+ LCD_WriteReg(LCD_REG_97, 0x0001); /* NDL,VLE, REV */
+ LCD_WriteReg(LCD_REG_106, 0x0000); /* set scrolling line */
+
+ /* Partial Display Control -----------------------------------------------*/
+ LCD_WriteReg(LCD_REG_128, 0x0000);
+ LCD_WriteReg(LCD_REG_129, 0x0000);
+ LCD_WriteReg(LCD_REG_130, 0x0000);
+ LCD_WriteReg(LCD_REG_131, 0x0000);
+ LCD_WriteReg(LCD_REG_132, 0x0000);
+ LCD_WriteReg(LCD_REG_133, 0x0000);
+
+ /* Panel Control ---------------------------------------------------------*/
+ LCD_WriteReg(LCD_REG_144, 0x0010);
+ LCD_WriteReg(LCD_REG_146, 0x0000);
+ LCD_WriteReg(LCD_REG_147, 0x0003);
+ LCD_WriteReg(LCD_REG_149, 0x0110);
+ LCD_WriteReg(LCD_REG_151, 0x0000);
+ LCD_WriteReg(LCD_REG_152, 0x0000);
+
+ /* set GRAM write direction and BGR = 1 */
+ /* I/D=00 (Horizontal : increment, Vertical : decrement) */
+ /* AM=1 (address is updated in vertical writing direction) */
+ LCD_WriteReg(LCD_REG_3, 0x1018);
+
+ LCD_WriteReg(LCD_REG_7, 0x0133); /* 262K color and display ON */
+ }
+}
+
+
+/**
+ * @brief Initializes the LCD.
+ * @param None
+ * @retval None
+ */
+void STM32L152_LCD_Init(void)
+{
+ __IO uint32_t lcdid = 0;
+
+ /* Setups the LCD */
+ LCD_Setup();
+
+ /* Read the LCD ID */
+ lcdid = LCD_ReadReg(0x00);
+
+ if (lcdid == LCD_SPFD5408)
+ {
+ LCDType = LCD_SPFD5408;
+ }
+ else if (lcdid == LCD_ILI9320)
+ {
+ LCDType = LCD_ILI9320;
+ /* Setups the LCD */
+ LCD_Setup();
+ }
+ else
+ {
+ LCDType = LCD_ILI9325;
+ /* Setups the LCD */
+ LCD_Setup();
+ }
+
+ LCD_SetFont(&LCD_DEFAULT_FONT);
+}
+
+/**
+ * @brief Sets the LCD Text and Background colors.
+ * @param _TextColor: specifies the Text Color.
+ * @param _BackColor: specifies the Background Color.
+ * @retval None
+ */
+void LCD_SetColors(__IO uint16_t _TextColor, __IO uint16_t _BackColor)
+{
+ TextColor = _TextColor;
+ BackColor = _BackColor;
+}
+
+/**
+ * @brief Gets the LCD Text and Background colors.
+ * @param _TextColor: pointer to the variable that will contain the Text
+ Color.
+ * @param _BackColor: pointer to the variable that will contain the Background
+ Color.
+ * @retval None
+ */
+void LCD_GetColors(__IO uint16_t *_TextColor, __IO uint16_t *_BackColor)
+{
+ *_TextColor = TextColor; *_BackColor = BackColor;
+}
+
+/**
+ * @brief Sets the Text color.
+ * @param Color: specifies the Text color code RGB(5-6-5).
+ * @retval None
+ */
+void LCD_SetTextColor(__IO uint16_t Color)
+{
+ TextColor = Color;
+}
+
+
+/**
+ * @brief Sets the Background color.
+ * @param Color: specifies the Background color code RGB(5-6-5).
+ * @retval None
+ */
+void LCD_SetBackColor(__IO uint16_t Color)
+{
+ BackColor = Color;
+}
+
+/**
+ * @brief Sets the Text Font.
+ * @param fonts: specifies the font to be used.
+ * @retval None
+ */
+void LCD_SetFont(sFONT *fonts)
+{
+ LCD_Currentfonts = fonts;
+}
+
+/**
+ * @brief Gets the Text Font.
+ * @param None.
+ * @retval the used font.
+ */
+sFONT *LCD_GetFont(void)
+{
+ return LCD_Currentfonts;
+}
+
+/**
+ * @brief Clears the selected line.
+ * @param Line: the Line to be cleared.
+ * This parameter can be one of the following values:
+ * @arg Linex: where x can be 0..n
+ * @retval None
+ */
+void LCD_ClearLine(uint16_t Line)
+{
+ uint16_t refcolumn = LCD_PIXEL_WIDTH - 1;
+
+ /* Send the string character by character on lCD */
+ while (((refcolumn + 1) & 0xFFFF) >= LCD_Currentfonts->Width)
+ {
+ /* Display one character on LCD */
+ LCD_DisplayChar(Line, refcolumn, ' ');
+ /* Decrement the column position by 16 */
+ refcolumn -= LCD_Currentfonts->Width;
+ }
+}
+
+
+/**
+ * @brief Clears the hole LCD.
+ * @param Color: the color of the background.
+ * @retval None
+ */
+void LCD_Clear(uint16_t Color)
+{
+ uint32_t index = 0;
+
+ LCD_SetCursor(0x00, 0x013F);
+
+ LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
+
+ for(index = 0; index < 76800; index++)
+ {
+ LCD_WriteRAM(Color);
+ }
+
+ LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_SET);
+
+}
+
+
+/**
+ * @brief Sets the cursor position.
+ * @param Xpos: specifies the X position.
+ * @param Ypos: specifies the Y position.
+ * @retval None
+ */
+void LCD_SetCursor(uint16_t Xpos, uint16_t Ypos)
+{
+ LCD_WriteReg(LCD_REG_32, Xpos);
+ LCD_WriteReg(LCD_REG_33, Ypos);
+}
+
+
+/**
+ * @brief Draws a character on LCD.
+ * @param Xpos: the Line where to display the character shape.
+ * @param Ypos: start column address.
+ * @param c: pointer to the character data.
+ * @retval None
+ */
+void LCD_DrawChar(uint16_t Xpos, uint16_t Ypos, const uint16_t *c)
+{
+ uint32_t index = 0, i = 0;
+ uint16_t Xaddress = 0;
+
+ Xaddress = Xpos;
+
+ LCD_SetCursor(Xaddress, Ypos);
+
+ for(index = 0; index < LCD_Currentfonts->Height; index++)
+ {
+ LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
+
+ for(i = 0; i < LCD_Currentfonts->Width; i++)
+ {
+ if((((c[index] & ((0x80 << ((LCD_Currentfonts->Width / 12 ) * 8 ) ) >> i)) == 0x00) &&(LCD_Currentfonts->Width <= 12))||
+ (((c[index] & (0x1 << i)) == 0x00)&&(LCD_Currentfonts->Width > 12 )))
+
+ {
+ LCD_WriteRAM(BackColor);
+ }
+ else
+ {
+ LCD_WriteRAM(TextColor);
+ }
+ }
+
+ LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_SET);
+ Xaddress++;
+ LCD_SetCursor(Xaddress, Ypos);
+ }
+}
+
+
+/**
+ * @brief Displays one character (16dots width, 24dots height).
+ * @param Line: the Line where to display the character shape .
+ * This parameter can be one of the following values:
+ * @arg Linex: where x can be 0..9
+ * @param Column: start column address.
+ * @param Ascii: character ascii code, must be between 0x20 and 0x7E.
+ * @retval None
+ */
+void LCD_DisplayChar(uint16_t Line, uint16_t Column, uint8_t Ascii)
+{
+ Ascii -= 32;
+ LCD_DrawChar(Line, Column, &LCD_Currentfonts->table[Ascii * LCD_Currentfonts->Height]);
+}
+
+
+/**
+ * @brief Displays a maximum of 20 char on the LCD.
+ * @param Line: the Line where to display the character shape .
+ * This parameter can be one of the following values:
+ * @arg Linex: where x can be 0..9
+ * @param *ptr: pointer to string to display on LCD.
+ * @retval None
+ */
+void LCD_DisplayStringLine(uint16_t Line, uint8_t *ptr)
+{
+ uint16_t refcolumn = LCD_PIXEL_WIDTH - 1;
+
+ /* Send the string character by character on lCD */
+ while ((*ptr != 0) & (((refcolumn + 1) & 0xFFFF) >= LCD_Currentfonts->Width))
+ {
+ /* Display one character on LCD */
+ LCD_DisplayChar(Line, refcolumn, *ptr);
+ /* Decrement the column position by 16 */
+ refcolumn -= LCD_Currentfonts->Width;
+ /* Point on the next character */
+ ptr++;
+ }
+}
+
+
+/**
+ * @brief Sets a display window
+ * @param Xpos: specifies the X buttom left position.
+ * @param Ypos: specifies the Y buttom left position.
+ * @param Height: display window height.
+ * @param Width: display window width.
+ * @retval None
+ */
+void LCD_SetDisplayWindow(uint16_t Xpos, uint16_t Ypos, uint8_t Height, uint16_t Width)
+{
+ /* Horizontal GRAM Start Address */
+ if(Xpos >= Height)
+ {
+ LCD_WriteReg(LCD_REG_80, (Xpos - Height + 1));
+ }
+ else
+ {
+ LCD_WriteReg(LCD_REG_80, 0);
+ }
+ /* Horizontal GRAM End Address */
+ LCD_WriteReg(LCD_REG_81, Xpos);
+ /* Vertical GRAM Start Address */
+ if(Ypos >= Width)
+ {
+ LCD_WriteReg(LCD_REG_82, (Ypos - Width + 1));
+ }
+ else
+ {
+ LCD_WriteReg(LCD_REG_82, 0);
+ }
+ /* Vertical GRAM End Address */
+ LCD_WriteReg(LCD_REG_83, Ypos);
+
+ LCD_SetCursor(Xpos, Ypos);
+}
+
+
+/**
+ * @brief Disables LCD Window mode.
+ * @param None
+ * @retval None
+ */
+void LCD_WindowModeDisable(void)
+{
+ LCD_SetDisplayWindow(239, 0x13F, 240, 320);
+ LCD_WriteReg(LCD_REG_3, 0x1018);
+}
+
+/**
+ * @brief Displays a line.
+ * @param Xpos: specifies the X position.
+ * @param Ypos: specifies the Y position.
+ * @param Length: line length.
+ * @param Direction: line direction.
+ * This parameter can be one of the following values: Vertical or Horizontal.
+ * @retval None
+ */
+void LCD_DrawLine(uint16_t Xpos, uint16_t Ypos, uint16_t Length, uint8_t Direction)
+{
+ uint32_t i = 0;
+
+ LCD_SetCursor(Xpos, Ypos);
+
+ if(Direction == LCD_DIR_HORIZONTAL)
+ {
+ LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
+
+ for(i = 0; i < Length; i++)
+ {
+ LCD_WriteRAM(TextColor);
+ }
+ LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_SET);
+ }
+ else
+ {
+ for(i = 0; i < Length; i++)
+ {
+ LCD_WriteRAMWord(TextColor);
+ Xpos++;
+ LCD_SetCursor(Xpos, Ypos);
+ }
+ }
+}
+
+
+/**
+ * @brief Displays a rectangle.
+ * @param Xpos: specifies the X position.
+ * @param Ypos: specifies the Y position.
+ * @param Height: display rectangle height.
+ * @param Width: display rectangle width.
+ * @retval None
+ */
+void LCD_DrawRect(uint16_t Xpos, uint16_t Ypos, uint8_t Height, uint16_t Width)
+{
+ LCD_DrawLine(Xpos, Ypos, Width, LCD_DIR_HORIZONTAL);
+ LCD_DrawLine((Xpos + Height), Ypos, Width, LCD_DIR_HORIZONTAL);
+
+ LCD_DrawLine(Xpos, Ypos, Height, LCD_DIR_VERTICAL);
+ LCD_DrawLine(Xpos, (Ypos - Width + 1), Height, LCD_DIR_VERTICAL);
+}
+
+
+/**
+ * @brief Displays a circle.
+ * @param Xpos: specifies the X position.
+ * @param Ypos: specifies the Y position.
+ * @param Radius
+ * @retval None
+ */
+void LCD_DrawCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius)
+{
+ int32_t D;/* Decision Variable */
+ uint32_t CurX;/* Current X Value */
+ uint32_t CurY;/* Current Y Value */
+
+ D = 3 - (Radius << 1);
+ CurX = 0;
+ CurY = Radius;
+
+ while (CurX <= CurY)
+ {
+ LCD_SetCursor(Xpos + CurX, Ypos + CurY);
+ LCD_WriteRAMWord(TextColor);
+ LCD_SetCursor(Xpos + CurX, Ypos - CurY);
+ LCD_WriteRAMWord(TextColor);
+
+ LCD_SetCursor(Xpos - CurX, Ypos + CurY);
+ LCD_WriteRAMWord(TextColor);
+
+ LCD_SetCursor(Xpos - CurX, Ypos - CurY);
+ LCD_WriteRAMWord(TextColor);
+
+ LCD_SetCursor(Xpos + CurY, Ypos + CurX);
+ LCD_WriteRAMWord(TextColor);
+
+ LCD_SetCursor(Xpos + CurY, Ypos - CurX);
+ LCD_WriteRAMWord(TextColor);
+
+ LCD_SetCursor(Xpos - CurY, Ypos + CurX);
+ LCD_WriteRAMWord(TextColor);
+
+ LCD_SetCursor(Xpos - CurY, Ypos - CurX);
+ LCD_WriteRAMWord(TextColor);
+
+ if (D < 0)
+ {
+ D += (CurX << 2) + 6;
+ }
+ else
+ {
+ D += ((CurX - CurY) << 2) + 10;
+ CurY--;
+ }
+ CurX++;
+ }
+}
+
+
+/**
+ * @brief Displays a monocolor picture.
+ * @param Pict: pointer to the picture array.
+ * @retval None
+ */
+void LCD_DrawMonoPict(const uint32_t *Pict)
+{
+ uint32_t index = 0, i = 0;
+ LCD_SetCursor(0, (LCD_PIXEL_WIDTH - 1));
+
+ LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
+
+ for(index = 0; index < 2400; index++)
+ {
+ for(i = 0; i < 32; i++)
+ {
+ if((Pict[index] & (1 << i)) == 0x00)
+ {
+ LCD_WriteRAM(BackColor);
+ }
+ else
+ {
+ LCD_WriteRAM(TextColor);
+ }
+ }
+ }
+
+ LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_SET);
+}
+
+#ifdef USE_LCD_DrawBMP
+/**
+ * @brief Displays a bitmap picture loaded in the SPI Flash.
+ * @param BmpAddress: Bmp picture address in the SPI Flash.
+ * @retval None
+ */
+void LCD_DrawBMP(uint32_t BmpAddress)
+{
+ uint32_t i = 0, size = 0;
+ /* Read bitmap size */
+ sFLASH_ReadBuffer((uint8_t*)&size, BmpAddress + 2, 4);
+ /* get bitmap data address offset */
+ sFLASH_ReadBuffer((uint8_t*)&i, BmpAddress + 10, 4);
+
+ size = (size - i)/2;
+ sFLASH_StartReadSequence(BmpAddress + i);
+ /* Disable LCD_SPI */
+ SPI_Cmd(LCD_SPI, DISABLE);
+ /* SPI in 16-bit mode */
+ SPI_DataSizeConfig(LCD_SPI, SPI_DataSize_16b);
+ /* Enable LCD_SPI */
+ SPI_Cmd(LCD_SPI, ENABLE);
+
+ if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
+ {
+ /* Set GRAM write direction and BGR = 1 */
+ /* I/D=00 (Horizontal : decrement, Vertical : decrement) */
+ /* AM=1 (address is updated in vertical writing direction) */
+ LCD_WriteReg(LCD_REG_3, 0x1008);
+ LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
+ }
+
+ /* Read bitmap data from SPI Flash and send them to LCD */
+ for(i = 0; i < size; i++)
+ {
+ LCD_WriteRAM(__REV16(sFLASH_SendHalfWord(0xA5A5)));
+ }
+ if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
+ {
+ LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_SET);
+ }
+
+ /* Deselect the FLASH: Chip Select high */
+ sFLASH_CS_HIGH();
+ /* Disable LCD_SPI */
+ SPI_Cmd(LCD_SPI, DISABLE);
+ /* SPI in 8-bit mode */
+ SPI_DataSizeConfig(LCD_SPI, SPI_DataSize_8b);
+ /* Enable LCD_SPI */
+ SPI_Cmd(LCD_SPI, ENABLE);
+
+ if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
+ {
+ /* Set GRAM write direction and BGR = 1 */
+ /* I/D = 01 (Horizontal : increment, Vertical : decrement) */
+ /* AM = 1 (address is updated in vertical writing direction) */
+ LCD_WriteReg(LCD_REG_3, 0x1018);
+ }
+}
+#endif /* USE_LCD_DrawBMP */
+
+/**
+ * @brief Displays a full rectangle.
+ * @param Xpos: specifies the X position.
+ * @param Ypos: specifies the Y position.
+ * @param Height: rectangle height.
+ * @param Width: rectangle width.
+ * @retval None
+ */
+void LCD_DrawFullRect(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height)
+{
+ LCD_SetTextColor(TextColor);
+
+ LCD_DrawLine(Xpos, Ypos, Width, LCD_DIR_HORIZONTAL);
+ LCD_DrawLine((Xpos + Height), Ypos, Width, LCD_DIR_HORIZONTAL);
+
+ LCD_DrawLine(Xpos, Ypos, Height, LCD_DIR_VERTICAL);
+ LCD_DrawLine(Xpos, (Ypos - Width + 1), Height, LCD_DIR_VERTICAL);
+
+ Width -= 2;
+ Height--;
+ Ypos--;
+
+ LCD_SetTextColor(BackColor);
+
+ while(Height--)
+ {
+ LCD_DrawLine(++Xpos, Ypos, Width, LCD_DIR_HORIZONTAL);
+ }
+
+ LCD_SetTextColor(TextColor);
+}
+
+/**
+ * @brief Displays a full circle.
+ * @param Xpos: specifies the X position.
+ * @param Ypos: specifies the Y position.
+ * @param Radius
+ * @retval None
+ */
+void LCD_DrawFullCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius)
+{
+ int32_t D; /* Decision Variable */
+ uint32_t CurX;/* Current X Value */
+ uint32_t CurY;/* Current Y Value */
+
+ D = 3 - (Radius << 1);
+
+ CurX = 0;
+ CurY = Radius;
+
+ LCD_SetTextColor(BackColor);
+
+ while (CurX <= CurY)
+ {
+ if(CurY > 0)
+ {
+ LCD_DrawLine(Xpos - CurX, Ypos + CurY, 2*CurY, LCD_DIR_HORIZONTAL);
+ LCD_DrawLine(Xpos + CurX, Ypos + CurY, 2*CurY, LCD_DIR_HORIZONTAL);
+ }
+
+ if(CurX > 0)
+ {
+ LCD_DrawLine(Xpos - CurY, Ypos + CurX, 2*CurX, LCD_DIR_HORIZONTAL);
+ LCD_DrawLine(Xpos + CurY, Ypos + CurX, 2*CurX, LCD_DIR_HORIZONTAL);
+ }
+ if (D < 0)
+ {
+ D += (CurX << 2) + 6;
+ }
+ else
+ {
+ D += ((CurX - CurY) << 2) + 10;
+ CurY--;
+ }
+ CurX++;
+ }
+
+ LCD_SetTextColor(TextColor);
+ LCD_DrawCircle(Xpos, Ypos, Radius);
+}
+
+/**
+ * @brief Displays an uni line (between two points).
+ * @param x1: specifies the point 1 x position.
+ * @param y1: specifies the point 1 y position.
+ * @param x2: specifies the point 2 x position.
+ * @param y2: specifies the point 2 y position.
+ * @retval None
+ */
+void LCD_DrawUniLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2)
+{
+ int16_t deltax = 0, deltay = 0, x = 0, y = 0, xinc1 = 0, xinc2 = 0,
+ yinc1 = 0, yinc2 = 0, den = 0, num = 0, numadd = 0, numpixels = 0,
+ curpixel = 0;
+
+ deltax = ABS(x2 - x1); /* The difference between the x's */
+ deltay = ABS(y2 - y1); /* The difference between the y's */
+ x = x1; /* Start x off at the first pixel */
+ y = y1; /* Start y off at the first pixel */
+
+ if (x2 >= x1) /* The x-values are increasing */
+ {
+ xinc1 = 1;
+ xinc2 = 1;
+ }
+ else /* The x-values are decreasing */
+ {
+ xinc1 = -1;
+ xinc2 = -1;
+ }
+
+ if (y2 >= y1) /* The y-values are increasing */
+ {
+ yinc1 = 1;
+ yinc2 = 1;
+ }
+ else /* The y-values are decreasing */
+ {
+ yinc1 = -1;
+ yinc2 = -1;
+ }
+
+ if (deltax >= deltay) /* There is at least one x-value for every y-value */
+ {
+ xinc1 = 0; /* Don't change the x when numerator >= denominator */
+ yinc2 = 0; /* Don't change the y for every iteration */
+ den = deltax;
+ num = deltax / 2;
+ numadd = deltay;
+ numpixels = deltax; /* There are more x-values than y-values */
+ }
+ else /* There is at least one y-value for every x-value */
+ {
+ xinc2 = 0; /* Don't change the x for every iteration */
+ yinc1 = 0; /* Don't change the y when numerator >= denominator */
+ den = deltay;
+ num = deltay / 2;
+ numadd = deltax;
+ numpixels = deltay; /* There are more y-values than x-values */
+ }
+
+ for (curpixel = 0; curpixel <= numpixels; curpixel++)
+ {
+ PutPixel(x, y); /* Draw the current pixel */
+ num += numadd; /* Increase the numerator by the top of the fraction */
+ if (num >= den) /* Check if numerator >= denominator */
+ {
+ num -= den; /* Calculate the new numerator value */
+ x += xinc1; /* Change the x as appropriate */
+ y += yinc1; /* Change the y as appropriate */
+ }
+ x += xinc2; /* Change the x as appropriate */
+ y += yinc2; /* Change the y as appropriate */
+ }
+}
+
+/**
+ * @brief Displays an polyline (between many points).
+ * @param Points: pointer to the points array.
+ * @param PointCount: Number of points.
+ * @retval None
+ */
+void LCD_PolyLine(pPoint Points, uint16_t PointCount)
+{
+ int16_t X = 0, Y = 0;
+
+ if(PointCount < 2)
+ {
+ return;
+ }
+
+ while(--PointCount)
+ {
+ X = Points->X;
+ Y = Points->Y;
+ Points++;
+ LCD_DrawUniLine(X, Y, Points->X, Points->Y);
+ }
+}
+
+/**
+ * @brief Displays an relative polyline (between many points).
+ * @param Points: pointer to the points array.
+ * @param PointCount: Number of points.
+ * @param Closed: specifies if the draw is closed or not.
+ * 1: closed, 0 : not closed.
+ * @retval None
+ */
+static void LCD_PolyLineRelativeClosed(pPoint Points, uint16_t PointCount, uint16_t Closed)
+{
+ int16_t X = 0, Y = 0;
+ pPoint First = Points;
+
+ if(PointCount < 2)
+ {
+ return;
+ }
+ X = Points->X;
+ Y = Points->Y;
+ while(--PointCount)
+ {
+ Points++;
+ LCD_DrawUniLine(X, Y, X + Points->X, Y + Points->Y);
+ X = X + Points->X;
+ Y = Y + Points->Y;
+ }
+ if(Closed)
+ {
+ LCD_DrawUniLine(First->X, First->Y, X, Y);
+ }
+}
+
+/**
+ * @brief Displays a closed polyline (between many points).
+ * @param Points: pointer to the points array.
+ * @param PointCount: Number of points.
+ * @retval None
+ */
+void LCD_ClosedPolyLine(pPoint Points, uint16_t PointCount)
+{
+ LCD_PolyLine(Points, PointCount);
+ LCD_DrawUniLine(Points->X, Points->Y, (Points+PointCount-1)->X, (Points+PointCount-1)->Y);
+}
+
+/**
+ * @brief Displays a relative polyline (between many points).
+ * @param Points: pointer to the points array.
+ * @param PointCount: Number of points.
+ * @retval None
+ */
+void LCD_PolyLineRelative(pPoint Points, uint16_t PointCount)
+{
+ LCD_PolyLineRelativeClosed(Points, PointCount, 0);
+}
+
+/**
+ * @brief Displays a closed relative polyline (between many points).
+ * @param Points: pointer to the points array.
+ * @param PointCount: Number of points.
+ * @retval None
+ */
+void LCD_ClosedPolyLineRelative(pPoint Points, uint16_t PointCount)
+{
+ LCD_PolyLineRelativeClosed(Points, PointCount, 1);
+}
+
+
+/**
+ * @brief Displays a full polyline (between many points).
+ * @param Points: pointer to the points array.
+ * @param PointCount: Number of points.
+ * @retval None
+ */
+void LCD_FillPolyLine(pPoint Points, uint16_t PointCount)
+{
+ /* public-domain code by Darel Rex Finley, 2007 */
+ uint16_t nodes = 0, nodeX[MAX_POLY_CORNERS], pixelX = 0, pixelY = 0, i = 0,
+ j = 0, swap = 0;
+ uint16_t IMAGE_LEFT = 0, IMAGE_RIGHT = 0, IMAGE_TOP = 0, IMAGE_BOTTOM = 0;
+
+ IMAGE_LEFT = IMAGE_RIGHT = Points->X;
+ IMAGE_TOP= IMAGE_BOTTOM = Points->Y;
+
+ for(i = 1; i < PointCount; i++)
+ {
+ pixelX = POLY_X(i);
+ if(pixelX < IMAGE_LEFT)
+ {
+ IMAGE_LEFT = pixelX;
+ }
+ if(pixelX > IMAGE_RIGHT)
+ {
+ IMAGE_RIGHT = pixelX;
+ }
+
+ pixelY = POLY_Y(i);
+ if(pixelY < IMAGE_TOP)
+ {
+ IMAGE_TOP = pixelY;
+ }
+ if(pixelY > IMAGE_BOTTOM)
+ {
+ IMAGE_BOTTOM = pixelY;
+ }
+ }
+
+ LCD_SetTextColor(BackColor);
+
+ /* Loop through the rows of the image. */
+ for (pixelY = IMAGE_TOP; pixelY < IMAGE_BOTTOM; pixelY++)
+ {
+ /* Build a list of nodes. */
+ nodes = 0; j = PointCount-1;
+
+ for (i = 0; i < PointCount; i++)
+ {
+ if (((POLY_Y(i)<(double) pixelY) && (POLY_Y(j)>=(double) pixelY)) || \
+ ((POLY_Y(j)<(double) pixelY) && (POLY_Y(i)>=(double) pixelY)))
+ {
+ nodeX[nodes++]=(int) (POLY_X(i)+((pixelY-POLY_Y(i))*(POLY_X(j)-POLY_X(i)))/(POLY_Y(j)-POLY_Y(i)));
+ }
+ j = i;
+ }
+
+ /* Sort the nodes, via a simple "Bubble" sort. */
+ i = 0;
+ while (i < nodes-1)
+ {
+ if (nodeX[i]>nodeX[i+1])
+ {
+ swap = nodeX[i];
+ nodeX[i] = nodeX[i+1];
+ nodeX[i+1] = swap;
+ if(i)
+ {
+ i--;
+ }
+ }
+ else
+ {
+ i++;
+ }
+ }
+
+ /* Fill the pixels between node pairs. */
+ for (i = 0; i < nodes; i+=2)
+ {
+ if(nodeX[i] >= IMAGE_RIGHT)
+ {
+ break;
+ }
+ if(nodeX[i+1] > IMAGE_LEFT)
+ {
+ if (nodeX[i] < IMAGE_LEFT)
+ {
+ nodeX[i]=IMAGE_LEFT;
+ }
+ if(nodeX[i+1] > IMAGE_RIGHT)
+ {
+ nodeX[i+1] = IMAGE_RIGHT;
+ }
+ LCD_SetTextColor(BackColor);
+ LCD_DrawLine(pixelY, nodeX[i+1], nodeX[i+1] - nodeX[i], LCD_DIR_HORIZONTAL);
+ LCD_SetTextColor(TextColor);
+ PutPixel(pixelY, nodeX[i+1]);
+ PutPixel(pixelY, nodeX[i]);
+ /* for (j=nodeX[i]; j<nodeX[i+1]; j++) PutPixel(j,pixelY); */
+ }
+ }
+ }
+
+ /* draw the edges */
+ LCD_SetTextColor(TextColor);
+}
+
+/**
+ * @brief Reset LCD control line(/CS) and Send Start-Byte
+ * @param Start_Byte: the Start-Byte to be sent
+ * @retval None
+ */
+void LCD_nCS_StartByte(uint8_t Start_Byte)
+{
+ LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_RESET);
+
+ SPI_SendData(LCD_SPI, Start_Byte);
+
+ while(SPI_GetFlagStatus(LCD_SPI, SPI_FLAG_BSY) != RESET)
+ {
+ }
+}
+
+
+/**
+ * @brief Writes index to select the LCD register.
+ * @param LCD_Reg: address of the selected register.
+ * @retval None
+ */
+void LCD_WriteRegIndex(uint8_t LCD_Reg)
+{
+ /* Reset LCD control line(/CS) and Send Start-Byte */
+ LCD_nCS_StartByte(START_BYTE | SET_INDEX);
+
+ /* Write 16-bit Reg Index (High Byte is 0) */
+ SPI_SendData(LCD_SPI, 0x00);
+
+ while(SPI_GetFlagStatus(LCD_SPI, SPI_FLAG_BSY) != RESET)
+ {
+ }
+
+ SPI_SendData(LCD_SPI, LCD_Reg);
+
+ while(SPI_GetFlagStatus(LCD_SPI, SPI_FLAG_BSY) != RESET)
+ {
+ }
+
+ LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_SET);
+}
+
+
+/**
+ * @brief Writes to the selected LCD ILI9320 register.
+ * @param LCD_Reg: address of the selected register.
+ * @param LCD_RegValue: value to write to the selected register.
+ * @retval None
+ */
+void LCD_WriteReg(uint8_t LCD_Reg, uint16_t LCD_RegValue)
+{
+ /* Write 16-bit Index (then Write Reg) */
+ LCD_WriteRegIndex(LCD_Reg);
+
+ /* Write 16-bit Reg */
+ /* Reset LCD control line(/CS) and Send Start-Byte */
+ LCD_nCS_StartByte(START_BYTE | LCD_WRITE_REG);
+
+ SPI_SendData(LCD_SPI, LCD_RegValue >> 8);
+
+ while(SPI_GetFlagStatus(LCD_SPI, SPI_FLAG_BSY) != RESET)
+ {
+ }
+
+ SPI_SendData(LCD_SPI, (LCD_RegValue & 0xFF));
+
+ while(SPI_GetFlagStatus(LCD_SPI, SPI_FLAG_BSY) != RESET)
+ {
+ }
+
+ LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_SET);
+}
+
+
+/**
+ * @brief Reads the selected LCD Register.
+ * @param LCD_Reg: address of the selected register.
+ * @retval LCD Register Value.
+ */
+uint16_t LCD_ReadReg(uint8_t LCD_Reg)
+{
+ uint16_t tmp = 0;
+ uint8_t i = 0;
+
+ /* LCD_SPI prescaler: 4 */
+ LCD_SPI->CR1 &= 0xFFC7;
+ LCD_SPI->CR1 |= 0x0008;
+ /* Write 16-bit Index (then Read Reg) */
+ LCD_WriteRegIndex(LCD_Reg);
+ /* Read 16-bit Reg */
+ /* Reset LCD control line(/CS) and Send Start-Byte */
+ LCD_nCS_StartByte(START_BYTE | LCD_READ_REG);
+
+ for(i = 0; i < 5; i++)
+ {
+ SPI_SendData(LCD_SPI, 0xFF);
+ while(SPI_GetFlagStatus(LCD_SPI, SPI_FLAG_BSY) != RESET)
+ {
+ }
+ /* One byte of invalid dummy data read after the start byte */
+ while(SPI_GetFlagStatus(LCD_SPI, SPI_FLAG_RXNE) == RESET)
+ {
+ }
+ SPI_ReceiveData(LCD_SPI);
+ }
+
+ SPI_SendData(LCD_SPI, 0xFF);
+
+ /* Read upper byte */
+ while(SPI_GetFlagStatus(LCD_SPI, SPI_FLAG_BSY) != RESET)
+ {
+ }
+
+ /* Read lower byte */
+ while(SPI_GetFlagStatus(LCD_SPI, SPI_FLAG_RXNE) == RESET)
+ {
+ }
+ tmp = SPI_ReceiveData(LCD_SPI);
+
+
+ SPI_SendData(LCD_SPI, 0xFF);
+ while(SPI_GetFlagStatus(LCD_SPI, SPI_FLAG_BSY) != RESET)
+ {
+ }
+
+ /* Read lower byte */
+ while(SPI_GetFlagStatus(LCD_SPI, SPI_FLAG_RXNE) == RESET)
+ {
+ }
+
+ tmp = ((tmp & 0xFF) << 8) | SPI_ReceiveData(LCD_SPI);
+ LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_SET);
+
+ /* LCD_SPI prescaler: 2 */
+ LCD_SPI->CR1 &= 0xFFC7;
+
+ return tmp;
+}
+
+
+/**
+ * @brief Prepare to write to the LCD RAM.
+ * @param None
+ * @retval None
+ */
+void LCD_WriteRAM_Prepare(void)
+{
+ LCD_WriteRegIndex(LCD_REG_34); /* Select GRAM Reg */
+
+ /* Reset LCD control line(/CS) and Send Start-Byte */
+ LCD_nCS_StartByte(START_BYTE | LCD_WRITE_REG);
+}
+
+
+/**
+ * @brief Writes 1 word to the LCD RAM.
+ * @param RGB_Code: the pixel color in RGB mode (5-6-5).
+ * @retval None
+ */
+void LCD_WriteRAMWord(uint16_t RGB_Code)
+{
+ LCD_WriteRAM_Prepare();
+
+ LCD_WriteRAM(RGB_Code);
+
+ LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_SET);
+}
+
+/**
+ * @brief Writes to the LCD RAM.
+ * @param RGB_Code: the pixel color in RGB mode (5-6-5).
+ * @retval None
+ */
+void LCD_WriteRAM(uint16_t RGB_Code)
+{
+ SPI_SendData(LCD_SPI, RGB_Code >> 8);
+ while(SPI_GetFlagStatus(LCD_SPI, SPI_FLAG_BSY) != RESET)
+ {
+ }
+ SPI_SendData(LCD_SPI, RGB_Code & 0xFF);
+ while(SPI_GetFlagStatus(LCD_SPI, SPI_FLAG_BSY) != RESET)
+ {
+ }
+}
+
+
+/**
+ * @brief Power on the LCD.
+ * @param None
+ * @retval None
+ */
+void LCD_PowerOn(void)
+{
+ /* Power On sequence ---------------------------------------------------------*/
+ LCD_WriteReg(LCD_REG_16, 0x0000); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
+ LCD_WriteReg(LCD_REG_17, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */
+ LCD_WriteReg(LCD_REG_18, 0x0000); /* VREG1OUT voltage */
+ LCD_WriteReg(LCD_REG_19, 0x0000); /* VDV[4:0] for VCOM amplitude */
+ _delay_(20); /* Dis-charge capacitor power voltage (200ms) */
+ LCD_WriteReg(LCD_REG_16, 0x17B0); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
+ LCD_WriteReg(LCD_REG_17, 0x0137); /* DC1[2:0], DC0[2:0], VC[2:0] */
+ _delay_(5); /* Delay 50 ms */
+ LCD_WriteReg(LCD_REG_18, 0x0139); /* VREG1OUT voltage */
+ _delay_(5); /* delay 50 ms */
+ LCD_WriteReg(LCD_REG_19, 0x1d00); /* VDV[4:0] for VCOM amplitude */
+ LCD_WriteReg(LCD_REG_41, 0x0013); /* VCM[4:0] for VCOMH */
+ _delay_(5); /* delay 50 ms */
+ LCD_WriteReg(LCD_REG_7, 0x0173); /* 262K color and display ON */
+}
+
+
+/**
+ * @brief Enables the Display.
+ * @param None
+ * @retval None
+ */
+void LCD_DisplayOn(void)
+{
+ /* Display On */
+ LCD_WriteReg(LCD_REG_7, 0x0173); /* 262K color and display ON */
+}
+
+
+/**
+ * @brief Disables the Display.
+ * @param None
+ * @retval None
+ */
+void LCD_DisplayOff(void)
+{
+ /* Display Off */
+ LCD_WriteReg(LCD_REG_7, 0x0);
+}
+
+
+/**
+ * @brief Configures LCD control lines in Output Push-Pull mode.
+ * @param None
+ * @retval None
+ */
+void LCD_CtrlLinesConfig(void)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+
+ RCC_AHBPeriphClockCmd(LCD_NCS_GPIO_CLK, ENABLE);
+
+ /* Configure NCS (PF.02) in Output Push-Pull mode */
+ GPIO_InitStructure.GPIO_Pin = LCD_NCS_PIN;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
+ GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
+ GPIO_Init(LCD_NCS_GPIO_PORT, &GPIO_InitStructure);
+
+ LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_SET);
+}
+
+
+/**
+ * @brief Sets or reset LCD control lines.
+ * @param GPIOx: where x can be B or D to select the GPIO peripheral.
+ * @param CtrlPins: the Control line.
+ * This parameter can be:
+ * @arg LCD_NCS_PIN: Chip Select pin
+ * @arg LCD_NWR_PIN: Read/Write Selection pin
+ * @arg LCD_RS_PIN: Register/RAM Selection pin
+ * @param BitVal: specifies the value to be written to the selected bit.
+ * This parameter can be:
+ * @arg Bit_RESET: to clear the port pin
+ * @arg Bit_SET: to set the port pin
+ * @retval None
+ */
+void LCD_CtrlLinesWrite(GPIO_TypeDef* GPIOx, uint16_t CtrlPins, BitAction BitVal)
+{
+ /* Set or Reset the control line */
+ GPIO_WriteBit(GPIOx, CtrlPins, BitVal);
+}
+
+
+/**
+ * @brief Configures the LCD_SPI interface.
+ * @param None
+ * @retval None
+ */
+void LCD_SPIConfig(void)
+{
+ SPI_InitTypeDef SPI_InitStructure;
+ GPIO_InitTypeDef GPIO_InitStructure;
+
+ /* Enable LCD_SPI_SCK_GPIO_CLK, LCD_SPI_MISO_GPIO_CLK and LCD_SPI_MOSI_GPIO_CLK clock */
+ RCC_AHBPeriphClockCmd(LCD_SPI_SCK_GPIO_CLK | LCD_SPI_MISO_GPIO_CLK | LCD_SPI_MOSI_GPIO_CLK, ENABLE);
+
+ /* Enable LCD_SPI and SYSCFG clock */
+ RCC_APB2PeriphClockCmd(LCD_SPI_CLK | RCC_APB2Periph_SYSCFG, ENABLE);
+
+ /* Configure LCD_SPI SCK pin */
+ GPIO_InitStructure.GPIO_Pin = LCD_SPI_SCK_PIN;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
+ GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
+ GPIO_Init(LCD_SPI_SCK_GPIO_PORT, &GPIO_InitStructure);
+
+ /* Configure LCD_SPI MISO pin */
+ GPIO_InitStructure.GPIO_Pin = LCD_SPI_MISO_PIN;
+ GPIO_Init(LCD_SPI_MISO_GPIO_PORT, &GPIO_InitStructure);
+
+ /* Configure LCD_SPI MOSI pin */
+ GPIO_InitStructure.GPIO_Pin = LCD_SPI_MOSI_PIN;
+ GPIO_Init(LCD_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure);
+
+ /* Connect PE.13 to SPI SCK */
+ GPIO_PinAFConfig(LCD_SPI_SCK_GPIO_PORT, LCD_SPI_SCK_SOURCE, LCD_SPI_SCK_AF);
+
+ /* Connect PE.14 to SPI MISO */
+ GPIO_PinAFConfig(LCD_SPI_MISO_GPIO_PORT, LCD_SPI_MISO_SOURCE, LCD_SPI_MISO_AF);
+
+ /* Connect PE.15 to SPI MOSI */
+ GPIO_PinAFConfig(LCD_SPI_MOSI_GPIO_PORT, LCD_SPI_MOSI_SOURCE, LCD_SPI_MOSI_AF);
+
+ SPI_DeInit(LCD_SPI);
+
+ /* SPI Config */
+ SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
+ SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
+ SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
+ SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;
+ SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
+ SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
+ SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2;
+ SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
+ SPI_InitStructure.SPI_CRCPolynomial = 7;
+ SPI_Init(LCD_SPI, &SPI_InitStructure);
+
+ /* SPI enable */
+ SPI_Cmd(LCD_SPI, ENABLE);
+}
+
+/**
+ * @brief Displays a pixel.
+ * @param x: pixel x.
+ * @param y: pixel y.
+ * @retval None
+ */
+static void PutPixel(int16_t x, int16_t y)
+{
+ if(x < 0 || x > 239 || y < 0 || y > 319)
+ {
+ return;
+ }
+ LCD_DrawLine(x, y, 1, LCD_DIR_HORIZONTAL);
+}
+
+#ifndef USE_Delay
+/**
+ * @brief Inserts a delay time.
+ * @param nCount: specifies the delay time length.
+ * @retval None
+ */
+static void delay(__IO uint32_t nCount)
+{
+ __IO uint32_t index = 0;
+ for(index = (34000 * nCount); index != 0; index--)
+ {
+ }
+}
+#endif /* USE_Delay*/
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152_EVAL/stm32l152_eval_lcd.h b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152_EVAL/stm32l152_eval_lcd.h
new file mode 100644
index 0000000..9f1383a
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152_EVAL/stm32l152_eval_lcd.h
@@ -0,0 +1,398 @@
+/**
+ ******************************************************************************
+ * @file stm32l152_eval_lcd.h
+ * @author MCD Application Team
+ * @version V5.0.2
+ * @date 09-March-2012
+ * @brief This file contains all the functions prototypes for the stm32l152_eval_lcd
+ * firmware driver.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.st.com/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __STM32L152_EVAL_LCD_H
+#define __STM32L152_EVAL_LCD_H
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+/* Includes ------------------------------------------------------------------*/
+#include "stm32l152_eval.h"
+#include "../Common/fonts.h"
+
+/** @addtogroup Utilities
+ * @{
+ */
+
+/** @addtogroup STM32_EVAL
+ * @{
+ */
+
+/** @addtogroup STM32L152_EVAL
+ * @{
+ */
+
+/** @addtogroup STM32L152_EVAL_LCD
+ * @{
+ */
+
+
+/** @defgroup STM32L152_EVAL_LCD_Exported_Types
+ * @{
+ */
+typedef struct
+{
+ int16_t X;
+ int16_t Y;
+} Point, * pPoint;
+/**
+ * @}
+ */
+
+/** @defgroup STM32L152_EVAL_LCD_Exported_Constants
+ * @{
+ */
+
+/**
+ * @brief Uncomment the line below if you want to use LCD_DrawBMP function to
+ * display a bitmap picture on the LCD. This function assumes that the bitmap
+ * file is loaded in the SPI Flash (mounted on STM32L152-EVAL board), however
+ * user can tailor it according to his application hardware requirement.
+ */
+/*#define USE_LCD_DrawBMP*/
+
+/**
+ * @brief Uncomment the line below if you want to use user defined Delay function
+ * (for precise timing), otherwise default _delay_ function defined within
+ * this driver is used (less precise timing).
+ */
+/* #define USE_Delay */
+
+#ifdef USE_Delay
+#include "main.h"
+
+ #define _delay_ Delay /* !< User can provide more timing precise _delay_ function
+ (with 10ms time base), using SysTick for example */
+#else
+ #define _delay_ delay /* !< Default _delay_ function with less precise timing */
+#endif
+
+
+/**
+ * @brief LCD Control pins
+ */
+#define LCD_NCS_PIN GPIO_Pin_2
+#define LCD_NCS_GPIO_PORT GPIOH
+#define LCD_NCS_GPIO_CLK RCC_AHBPeriph_GPIOH
+
+/**
+ * @brief LCD SPI Interface pins
+ */
+#define LCD_SPI_SCK_PIN GPIO_Pin_13 /* PE.13 */
+#define LCD_SPI_SCK_GPIO_PORT GPIOE /* GPIOE */
+#define LCD_SPI_SCK_GPIO_CLK RCC_AHBPeriph_GPIOE
+#define LCD_SPI_SCK_SOURCE GPIO_PinSource13
+#define LCD_SPI_SCK_AF GPIO_AF_SPI1
+#define LCD_SPI_MISO_PIN GPIO_Pin_14 /* PE.14 */
+#define LCD_SPI_MISO_GPIO_PORT GPIOE /* GPIOE */
+#define LCD_SPI_MISO_GPIO_CLK RCC_AHBPeriph_GPIOE
+#define LCD_SPI_MISO_SOURCE GPIO_PinSource14
+#define LCD_SPI_MISO_AF GPIO_AF_SPI1
+#define LCD_SPI_MOSI_PIN GPIO_Pin_15 /* PE.15 */
+#define LCD_SPI_MOSI_GPIO_PORT GPIOE /* GPIOE */
+#define LCD_SPI_MOSI_GPIO_CLK RCC_AHBPeriph_GPIOE
+#define LCD_SPI_MOSI_SOURCE GPIO_PinSource15
+#define LCD_SPI_MOSI_AF GPIO_AF_SPI1
+#define LCD_SPI SPI1
+#define LCD_SPI_CLK RCC_APB2Periph_SPI1
+
+
+/**
+ * @brief LCD Registers
+ */
+#define LCD_REG_0 0x00
+#define LCD_REG_1 0x01
+#define LCD_REG_2 0x02
+#define LCD_REG_3 0x03
+#define LCD_REG_4 0x04
+#define LCD_REG_5 0x05
+#define LCD_REG_6 0x06
+#define LCD_REG_7 0x07
+#define LCD_REG_8 0x08
+#define LCD_REG_9 0x09
+#define LCD_REG_10 0x0A
+#define LCD_REG_12 0x0C
+#define LCD_REG_13 0x0D
+#define LCD_REG_14 0x0E
+#define LCD_REG_15 0x0F
+#define LCD_REG_16 0x10
+#define LCD_REG_17 0x11
+#define LCD_REG_18 0x12
+#define LCD_REG_19 0x13
+#define LCD_REG_20 0x14
+#define LCD_REG_21 0x15
+#define LCD_REG_22 0x16
+#define LCD_REG_23 0x17
+#define LCD_REG_24 0x18
+#define LCD_REG_25 0x19
+#define LCD_REG_26 0x1A
+#define LCD_REG_27 0x1B
+#define LCD_REG_28 0x1C
+#define LCD_REG_29 0x1D
+#define LCD_REG_30 0x1E
+#define LCD_REG_31 0x1F
+#define LCD_REG_32 0x20
+#define LCD_REG_33 0x21
+#define LCD_REG_34 0x22
+#define LCD_REG_36 0x24
+#define LCD_REG_37 0x25
+#define LCD_REG_40 0x28
+#define LCD_REG_41 0x29
+#define LCD_REG_43 0x2B
+#define LCD_REG_45 0x2D
+#define LCD_REG_48 0x30
+#define LCD_REG_49 0x31
+#define LCD_REG_50 0x32
+#define LCD_REG_51 0x33
+#define LCD_REG_52 0x34
+#define LCD_REG_53 0x35
+#define LCD_REG_54 0x36
+#define LCD_REG_55 0x37
+#define LCD_REG_56 0x38
+#define LCD_REG_57 0x39
+#define LCD_REG_59 0x3B
+#define LCD_REG_60 0x3C
+#define LCD_REG_61 0x3D
+#define LCD_REG_62 0x3E
+#define LCD_REG_63 0x3F
+#define LCD_REG_64 0x40
+#define LCD_REG_65 0x41
+#define LCD_REG_66 0x42
+#define LCD_REG_67 0x43
+#define LCD_REG_68 0x44
+#define LCD_REG_69 0x45
+#define LCD_REG_70 0x46
+#define LCD_REG_71 0x47
+#define LCD_REG_72 0x48
+#define LCD_REG_73 0x49
+#define LCD_REG_74 0x4A
+#define LCD_REG_75 0x4B
+#define LCD_REG_76 0x4C
+#define LCD_REG_77 0x4D
+#define LCD_REG_78 0x4E
+#define LCD_REG_79 0x4F
+#define LCD_REG_80 0x50
+#define LCD_REG_81 0x51
+#define LCD_REG_82 0x52
+#define LCD_REG_83 0x53
+#define LCD_REG_96 0x60
+#define LCD_REG_97 0x61
+#define LCD_REG_106 0x6A
+#define LCD_REG_118 0x76
+#define LCD_REG_128 0x80
+#define LCD_REG_129 0x81
+#define LCD_REG_130 0x82
+#define LCD_REG_131 0x83
+#define LCD_REG_132 0x84
+#define LCD_REG_133 0x85
+#define LCD_REG_134 0x86
+#define LCD_REG_135 0x87
+#define LCD_REG_136 0x88
+#define LCD_REG_137 0x89
+#define LCD_REG_139 0x8B
+#define LCD_REG_140 0x8C
+#define LCD_REG_141 0x8D
+#define LCD_REG_143 0x8F
+#define LCD_REG_144 0x90
+#define LCD_REG_145 0x91
+#define LCD_REG_146 0x92
+#define LCD_REG_147 0x93
+#define LCD_REG_148 0x94
+#define LCD_REG_149 0x95
+#define LCD_REG_150 0x96
+#define LCD_REG_151 0x97
+#define LCD_REG_152 0x98
+#define LCD_REG_153 0x99
+#define LCD_REG_154 0x9A
+#define LCD_REG_157 0x9D
+#define LCD_REG_192 0xC0
+#define LCD_REG_193 0xC1
+#define LCD_REG_227 0xE3
+#define LCD_REG_229 0xE5
+#define LCD_REG_231 0xE7
+#define LCD_REG_239 0xEF
+
+
+/**
+ * @brief LCD color
+ */
+#define LCD_COLOR_WHITE 0xFFFF
+#define LCD_COLOR_BLACK 0x0000
+#define LCD_COLOR_GREY 0xF7DE
+#define LCD_COLOR_BLUE 0x001F
+#define LCD_COLOR_BLUE2 0x051F
+#define LCD_COLOR_RED 0xF800
+#define LCD_COLOR_MAGENTA 0xF81F
+#define LCD_COLOR_GREEN 0x07E0
+#define LCD_COLOR_CYAN 0x7FFF
+#define LCD_COLOR_YELLOW 0xFFE0
+
+/**
+ * @brief LCD Lines depending on the chosen fonts.
+ */
+#define LCD_LINE_0 LINE(0)
+#define LCD_LINE_1 LINE(1)
+#define LCD_LINE_2 LINE(2)
+#define LCD_LINE_3 LINE(3)
+#define LCD_LINE_4 LINE(4)
+#define LCD_LINE_5 LINE(5)
+#define LCD_LINE_6 LINE(6)
+#define LCD_LINE_7 LINE(7)
+#define LCD_LINE_8 LINE(8)
+#define LCD_LINE_9 LINE(9)
+#define LCD_LINE_10 LINE(10)
+#define LCD_LINE_11 LINE(11)
+#define LCD_LINE_12 LINE(12)
+#define LCD_LINE_13 LINE(13)
+#define LCD_LINE_14 LINE(14)
+#define LCD_LINE_15 LINE(15)
+#define LCD_LINE_16 LINE(16)
+#define LCD_LINE_17 LINE(17)
+#define LCD_LINE_18 LINE(18)
+#define LCD_LINE_19 LINE(19)
+#define LCD_LINE_20 LINE(20)
+#define LCD_LINE_21 LINE(21)
+#define LCD_LINE_22 LINE(22)
+#define LCD_LINE_23 LINE(23)
+#define LCD_LINE_24 LINE(24)
+#define LCD_LINE_25 LINE(25)
+#define LCD_LINE_26 LINE(26)
+#define LCD_LINE_27 LINE(27)
+#define LCD_LINE_28 LINE(28)
+#define LCD_LINE_29 LINE(29)
+
+
+/**
+ * @brief LCD default font
+ */
+#define LCD_DEFAULT_FONT Font16x24
+
+/**
+ * @brief LCD Direction
+ */
+#define LCD_DIR_HORIZONTAL 0x0000
+#define LCD_DIR_VERTICAL 0x0001
+
+/**
+ * @brief LCD Size (Width and Height)
+ */
+#define LCD_PIXEL_WIDTH 0x0140
+#define LCD_PIXEL_HEIGHT 0x00F0
+
+/**
+ * @}
+ */
+
+/** @defgroup STM32L152_EVAL_LCD_Exported_Macros
+ * @{
+ */
+#define ASSEMBLE_RGB(R, G, B) ((((R)& 0xF8) << 8) | (((G) & 0xFC) << 3) | (((B) & 0xF8) >> 3))
+
+/**
+ * @}
+ */
+
+/** @defgroup STM32L152_EVAL_LCD_Exported_Functions
+ * @{
+ */
+void STM32L152_LCD_DeInit(void);
+void LCD_Setup(void);
+void STM32L152_LCD_Init(void);
+void LCD_SetColors(__IO uint16_t _TextColor, __IO uint16_t _BackColor);
+void LCD_GetColors(__IO uint16_t *_TextColor, __IO uint16_t *_BackColor);
+void LCD_SetTextColor(__IO uint16_t Color);
+void LCD_SetBackColor(__IO uint16_t Color);
+void LCD_ClearLine(uint16_t Line);
+void LCD_Clear(uint16_t Color);
+void LCD_SetCursor(uint16_t Xpos, uint16_t Ypos);
+void LCD_DrawChar(uint16_t Xpos, uint16_t Ypos, const uint16_t *c);
+void LCD_DisplayChar(uint16_t Line, uint16_t Column, uint8_t Ascii);
+void LCD_SetFont(sFONT *fonts);
+sFONT *LCD_GetFont(void);
+void LCD_DisplayStringLine(uint16_t Line, uint8_t *ptr);
+void LCD_SetDisplayWindow(uint16_t Xpos, uint16_t Ypos, uint8_t Height, uint16_t Width);
+void LCD_WindowModeDisable(void);
+void LCD_DrawLine(uint16_t Xpos, uint16_t Ypos, uint16_t Length, uint8_t Direction);
+void LCD_DrawRect(uint16_t Xpos, uint16_t Ypos, uint8_t Height, uint16_t Width);
+void LCD_DrawCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius);
+void LCD_DrawMonoPict(const uint32_t *Pict);
+void LCD_DrawBMP(uint32_t BmpAddress);
+void LCD_DrawUniLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2);
+void LCD_DrawFullRect(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height);
+void LCD_DrawFullCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius);
+void LCD_PolyLine(pPoint Points, uint16_t PointCount);
+void LCD_PolyLineRelative(pPoint Points, uint16_t PointCount);
+void LCD_ClosedPolyLine(pPoint Points, uint16_t PointCount);
+void LCD_ClosedPolyLineRelative(pPoint Points, uint16_t PointCount);
+void LCD_FillPolyLine(pPoint Points, uint16_t PointCount);
+void LCD_nCS_StartByte(uint8_t Start_Byte);
+void LCD_WriteRegIndex(uint8_t LCD_Reg);
+void LCD_WriteReg(uint8_t LCD_Reg, uint16_t LCD_RegValue);
+void LCD_WriteRAM_Prepare(void);
+void LCD_WriteRAMWord(uint16_t RGB_Code);
+uint16_t LCD_ReadReg(uint8_t LCD_Reg);
+void LCD_WriteRAM(uint16_t RGB_Code);
+void LCD_PowerOn(void);
+void LCD_DisplayOn(void);
+void LCD_DisplayOff(void);
+
+void LCD_CtrlLinesConfig(void);
+void LCD_CtrlLinesWrite(GPIO_TypeDef* GPIOx, uint16_t CtrlPins, BitAction BitVal);
+void LCD_SPIConfig(void);
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __STM32L152_EVAL_LCD_H */
+
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152_EVAL/stm32l152_eval_spi_sd.c b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152_EVAL/stm32l152_eval_spi_sd.c
new file mode 100644
index 0000000..b8104f6
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152_EVAL/stm32l152_eval_spi_sd.c
@@ -0,0 +1,912 @@
+/**
+ ******************************************************************************
+ * @file stm32l152_eval_spi_sd.c
+ * @author MCD Application Team
+ * @version V5.0.2
+ * @date 09-March-2012
+ * @brief This file provides a set of functions needed to manage the SPI SD
+ * Card memory mounted on STM32L152-EVAL board.
+ * It implements a high level communication layer for read and write
+ * from/to this memory. The needed STM32L hardware resources (SPI and
+ * GPIO) are defined in stm32l152_eval.h file, and the initialization is
+ * performed in SD_LowLevel_Init() function declared in stm32l152_eval.c
+ * file.
+ * You can easily tailor this driver to any other development board,
+ * by just adapting the defines for hardware resources and
+ * SD_LowLevel_Init() function.
+ *
+ * ===================================================================
+ * Notes:
+ * - This driver is intended for STM32L1xx families devices only.
+ * - This driver doesn't support SD High Capacity cards.
+ * ===================================================================
+ *
+ * +-------------------------------------------------------+
+ * | Pin assignment |
+ * +-------------------------+---------------+-------------+
+ * | STM32 SPI Pins | SD | Pin |
+ * +-------------------------+---------------+-------------+
+ * | SD_SPI_CS_PIN | ChipSelect | 1 |
+ * | SD_SPI_MOSI_PIN / MOSI | DataIn | 2 |
+ * | | GND | 3 (0 V) |
+ * | | VDD | 4 (3.3 V)|
+ * | SD_SPI_SCK_PIN / SCLK | Clock | 5 |
+ * | | GND | 6 (0 V) |
+ * | SD_SPI_MISO_PIN / MISO | DataOut | 7 |
+ * +-------------------------+---------------+-------------+
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.st.com/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+
+/* Includes ------------------------------------------------------------------*/
+#include "stm32l152_eval_spi_sd.h"
+
+/** @addtogroup Utilities
+ * @{
+ */
+
+/** @addtogroup STM32_EVAL
+ * @{
+ */
+
+/** @addtogroup STM32L152_EVAL
+ * @{
+ */
+
+/** @addtogroup STM32L152_EVAL_SPI_SD
+ * @brief This file includes the SD card driver of STM32L152-EVAL boards.
+ * @{
+ */
+
+/** @defgroup STM32L152_EVAL_SPI_SD_Private_Types
+ * @{
+ */
+/**
+ * @}
+ */
+
+
+/** @defgroup STM32L152_EVAL_SPI_SD_Private_Defines
+ * @{
+ */
+/**
+ * @}
+ */
+
+/** @defgroup STM32L152_EVAL_SPI_SD_Private_Macros
+ * @{
+ */
+/**
+ * @}
+ */
+
+
+/** @defgroup STM32L152_EVAL_SPI_SD_Private_Variables
+ * @{
+ */
+/**
+ * @}
+ */
+
+
+/** @defgroup STM32L152_EVAL_SPI_SD_Private_Function_Prototypes
+ * @{
+ */
+/**
+ * @}
+ */
+
+
+/** @defgroup STM32L152_EVAL_SPI_SD_Private_Functions
+ * @{
+ */
+
+/**
+ * @brief DeInitializes the SD/SD communication.
+ * @param None
+ * @retval None
+ */
+void SD_DeInit(void)
+{
+ SD_LowLevel_DeInit();
+}
+
+/**
+ * @brief Initializes the SD/SD communication.
+ * @param None
+ * @retval The SD Response:
+ * - SD_RESPONSE_FAILURE: Sequence failed
+ * - SD_RESPONSE_NO_ERROR: Sequence succeed
+ */
+SD_Error SD_Init(void)
+{
+ uint32_t i = 0;
+
+ /*!< Initialize SD_SPI */
+ SD_LowLevel_Init();
+
+ /*!< SD chip select high */
+ SD_CS_HIGH();
+
+ /*!< Send dummy byte 0xFF, 10 times with CS high */
+ /*!< Rise CS and MOSI for 80 clocks cycles */
+ for (i = 0; i <= 9; i++)
+ {
+ /*!< Send dummy byte 0xFF */
+ SD_WriteByte(SD_DUMMY_BYTE);
+ }
+ /*------------Put SD in SPI mode--------------*/
+ /*!< SD initialized and set to SPI mode properly */
+ return (SD_GoIdleState());
+}
+
+/**
+ * @brief Detect if SD card is correctly plugged in the memory slot.
+ * @param None
+ * @retval Return if SD is detected or not
+ */
+uint8_t SD_Detect(void)
+{
+ __IO uint8_t status = SD_PRESENT;
+
+ /*!< Check GPIO to detect SD */
+ if (GPIO_ReadInputData(SD_DETECT_GPIO_PORT) & SD_DETECT_PIN)
+ {
+ status = SD_NOT_PRESENT;
+ }
+ return status;
+}
+
+/**
+ * @brief Returns information about specific card.
+ * @param cardinfo: pointer to a SD_CardInfo structure that contains all SD
+ * card information.
+ * @retval The SD Response:
+ * - SD_RESPONSE_FAILURE: Sequence failed
+ * - SD_RESPONSE_NO_ERROR: Sequence succeed
+ */
+SD_Error SD_GetCardInfo(SD_CardInfo *cardinfo)
+{
+ SD_Error status = SD_RESPONSE_FAILURE;
+
+ status = SD_GetCSDRegister(&(cardinfo->SD_csd));
+ status = SD_GetCIDRegister(&(cardinfo->SD_cid));
+ cardinfo->CardCapacity = (cardinfo->SD_csd.DeviceSize + 1) ;
+ cardinfo->CardCapacity *= (1 << (cardinfo->SD_csd.DeviceSizeMul + 2));
+ cardinfo->CardBlockSize = 1 << (cardinfo->SD_csd.RdBlockLen);
+ cardinfo->CardCapacity *= cardinfo->CardBlockSize;
+
+ /*!< Returns the reponse */
+ return status;
+}
+
+/**
+ * @brief Reads a block of data from the SD.
+ * @param pBuffer: pointer to the buffer that receives the data read from the
+ * SD.
+ * @param ReadAddr: SD's internal address to read from.
+ * @param BlockSize: the SD card Data block size.
+ * @retval The SD Response:
+ * - SD_RESPONSE_FAILURE: Sequence failed
+ * - SD_RESPONSE_NO_ERROR: Sequence succeed
+ */
+SD_Error SD_ReadBlock(uint8_t* pBuffer, uint32_t ReadAddr, uint16_t BlockSize)
+{
+ uint32_t i = 0;
+ SD_Error rvalue = SD_RESPONSE_FAILURE;
+
+ /*!< SD chip select low */
+ SD_CS_LOW();
+
+ /*!< Send CMD17 (SD_CMD_READ_SINGLE_BLOCK) to read one block */
+ SD_SendCmd(SD_CMD_READ_SINGLE_BLOCK, ReadAddr, 0xFF);
+
+ /*!< Check if the SD acknowledged the read block command: R1 response (0x00: no errors) */
+ if (!SD_GetResponse(SD_RESPONSE_NO_ERROR))
+ {
+ /*!< Now look for the data token to signify the start of the data */
+ if (!SD_GetResponse(SD_START_DATA_SINGLE_BLOCK_READ))
+ {
+ /*!< Read the SD block data : read NumByteToRead data */
+ for (i = 0; i < BlockSize; i++)
+ {
+ /*!< Save the received data */
+ *pBuffer = SD_ReadByte();
+
+ /*!< Point to the next location where the byte read will be saved */
+ pBuffer++;
+ }
+ /*!< Get CRC bytes (not really needed by us, but required by SD) */
+ SD_ReadByte();
+ SD_ReadByte();
+ /*!< Set response value to success */
+ rvalue = SD_RESPONSE_NO_ERROR;
+ }
+ }
+ /*!< SD chip select high */
+ SD_CS_HIGH();
+
+ /*!< Send dummy byte: 8 Clock pulses of delay */
+ SD_WriteByte(SD_DUMMY_BYTE);
+
+ /*!< Returns the reponse */
+ return rvalue;
+}
+
+/**
+ * @brief Reads multiple block of data from the SD.
+ * @param pBuffer: pointer to the buffer that receives the data read from the
+ * SD.
+ * @param ReadAddr: SD's internal address to read from.
+ * @param BlockSize: the SD card Data block size.
+ * @param NumberOfBlocks: number of blocks to be read.
+ * @retval The SD Response:
+ * - SD_RESPONSE_FAILURE: Sequence failed
+ * - SD_RESPONSE_NO_ERROR: Sequence succeed
+ */
+SD_Error SD_ReadMultiBlocks(uint8_t* pBuffer, uint32_t ReadAddr, uint16_t BlockSize, uint32_t NumberOfBlocks)
+{
+ uint32_t i = 0, Offset = 0;
+ SD_Error rvalue = SD_RESPONSE_FAILURE;
+
+ /*!< SD chip select low */
+ SD_CS_LOW();
+ /*!< Data transfer */
+ while (NumberOfBlocks--)
+ {
+ /*!< Send CMD17 (SD_CMD_READ_SINGLE_BLOCK) to read one block */
+ SD_SendCmd (SD_CMD_READ_SINGLE_BLOCK, ReadAddr + Offset, 0xFF);
+ /*!< Check if the SD acknowledged the read block command: R1 response (0x00: no errors) */
+ if (SD_GetResponse(SD_RESPONSE_NO_ERROR))
+ {
+ return SD_RESPONSE_FAILURE;
+ }
+ /*!< Now look for the data token to signify the start of the data */
+ if (!SD_GetResponse(SD_START_DATA_SINGLE_BLOCK_READ))
+ {
+ /*!< Read the SD block data : read NumByteToRead data */
+ for (i = 0; i < BlockSize; i++)
+ {
+ /*!< Read the pointed data */
+ *pBuffer = SD_ReadByte();
+ /*!< Point to the next location where the byte read will be saved */
+ pBuffer++;
+ }
+ /*!< Set next read address*/
+ Offset += 512;
+ /*!< get CRC bytes (not really needed by us, but required by SD) */
+ SD_ReadByte();
+ SD_ReadByte();
+ /*!< Set response value to success */
+ rvalue = SD_RESPONSE_NO_ERROR;
+ }
+ else
+ {
+ /*!< Set response value to failure */
+ rvalue = SD_RESPONSE_FAILURE;
+ }
+ }
+ /*!< SD chip select high */
+ SD_CS_HIGH();
+ /*!< Send dummy byte: 8 Clock pulses of delay */
+ SD_WriteByte(SD_DUMMY_BYTE);
+ /*!< Returns the reponse */
+ return rvalue;
+}
+
+/**
+ * @brief Writes a block on the SD
+ * @param pBuffer: pointer to the buffer containing the data to be written on
+ * the SD.
+ * @param WriteAddr: address to write on.
+ * @param BlockSize: the SD card Data block size.
+ * @retval The SD Response:
+ * - SD_RESPONSE_FAILURE: Sequence failed
+ * - SD_RESPONSE_NO_ERROR: Sequence succeed
+ */
+SD_Error SD_WriteBlock(uint8_t* pBuffer, uint32_t WriteAddr, uint16_t BlockSize)
+{
+ uint32_t i = 0;
+ SD_Error rvalue = SD_RESPONSE_FAILURE;
+
+ /*!< SD chip select low */
+ SD_CS_LOW();
+
+ /*!< Send CMD24 (SD_CMD_WRITE_SINGLE_BLOCK) to write multiple block */
+ SD_SendCmd(SD_CMD_WRITE_SINGLE_BLOCK, WriteAddr, 0xFF);
+
+ /*!< Check if the SD acknowledged the write block command: R1 response (0x00: no errors) */
+ if (!SD_GetResponse(SD_RESPONSE_NO_ERROR))
+ {
+ /*!< Send a dummy byte */
+ SD_WriteByte(SD_DUMMY_BYTE);
+
+ /*!< Send the data token to signify the start of the data */
+ SD_WriteByte(0xFE);
+
+ /*!< Write the block data to SD : write count data by block */
+ for (i = 0; i < BlockSize; i++)
+ {
+ /*!< Send the pointed byte */
+ SD_WriteByte(*pBuffer);
+ /*!< Point to the next location where the byte read will be saved */
+ pBuffer++;
+ }
+ /*!< Put CRC bytes (not really needed by us, but required by SD) */
+ SD_ReadByte();
+ SD_ReadByte();
+
+ /*!< Read data response */
+ if (SD_GetDataResponse() == SD_DATA_OK)
+ {
+ rvalue = SD_RESPONSE_NO_ERROR;
+ }
+ }
+ /*!< SD chip select high */
+ SD_CS_HIGH();
+ /*!< Send dummy byte: 8 Clock pulses of delay */
+ SD_WriteByte(SD_DUMMY_BYTE);
+
+ /*!< Returns the reponse */
+ return rvalue;
+}
+
+/**
+ * @brief Writes many blocks on the SD
+ * @param pBuffer: pointer to the buffer containing the data to be written on
+ * the SD.
+ * @param WriteAddr: address to write on.
+ * @param BlockSize: the SD card Data block size.
+ * @param NumberOfBlocks: number of blocks to be written.
+ * @retval The SD Response:
+ * - SD_RESPONSE_FAILURE: Sequence failed
+ * - SD_RESPONSE_NO_ERROR: Sequence succeed
+ */
+SD_Error SD_WriteMultiBlocks(uint8_t* pBuffer, uint32_t WriteAddr, uint16_t BlockSize, uint32_t NumberOfBlocks)
+{
+ uint32_t i = 0, Offset = 0;
+ SD_Error rvalue = SD_RESPONSE_FAILURE;
+
+ /*!< SD chip select low */
+ SD_CS_LOW();
+ /*!< Data transfer */
+ while (NumberOfBlocks--)
+ {
+ /*!< Send CMD24 (SD_CMD_WRITE_SINGLE_BLOCK) to write blocks */
+ SD_SendCmd(SD_CMD_WRITE_SINGLE_BLOCK, WriteAddr + Offset, 0xFF);
+ /*!< Check if the SD acknowledged the write block command: R1 response (0x00: no errors) */
+ if (SD_GetResponse(SD_RESPONSE_NO_ERROR))
+ {
+ return SD_RESPONSE_FAILURE;
+ }
+ /*!< Send dummy byte */
+ SD_WriteByte(SD_DUMMY_BYTE);
+ /*!< Send the data token to signify the start of the data */
+ SD_WriteByte(SD_START_DATA_SINGLE_BLOCK_WRITE);
+ /*!< Write the block data to SD : write count data by block */
+ for (i = 0; i < BlockSize; i++)
+ {
+ /*!< Send the pointed byte */
+ SD_WriteByte(*pBuffer);
+ /*!< Point to the next location where the byte read will be saved */
+ pBuffer++;
+ }
+ /*!< Set next write address */
+ Offset += 512;
+ /*!< Put CRC bytes (not really needed by us, but required by SD) */
+ SD_ReadByte();
+ SD_ReadByte();
+ /*!< Read data response */
+ if (SD_GetDataResponse() == SD_DATA_OK)
+ {
+ /*!< Set response value to success */
+ rvalue = SD_RESPONSE_NO_ERROR;
+ }
+ else
+ {
+ /*!< Set response value to failure */
+ rvalue = SD_RESPONSE_FAILURE;
+ }
+ }
+ /*!< SD chip select high */
+ SD_CS_HIGH();
+ /*!< Send dummy byte: 8 Clock pulses of delay */
+ SD_WriteByte(SD_DUMMY_BYTE);
+ /*!< Returns the reponse */
+ return rvalue;
+}
+
+/**
+ * @brief Read the CSD card register.
+ * Reading the contents of the CSD register in SPI mode is a simple
+ * read-block transaction.
+ * @param SD_csd: pointer on an SCD register structure
+ * @retval The SD Response:
+ * - SD_RESPONSE_FAILURE: Sequence failed
+ * - SD_RESPONSE_NO_ERROR: Sequence succeed
+ */
+SD_Error SD_GetCSDRegister(SD_CSD* SD_csd)
+{
+ uint32_t i = 0;
+ SD_Error rvalue = SD_RESPONSE_FAILURE;
+ uint8_t CSD_Tab[16];
+
+ /*!< SD chip select low */
+ SD_CS_LOW();
+ /*!< Send CMD9 (CSD register) or CMD10(CSD register) */
+ SD_SendCmd(SD_CMD_SEND_CSD, 0, 0xFF);
+ /*!< Wait for response in the R1 format (0x00 is no errors) */
+ if (!SD_GetResponse(SD_RESPONSE_NO_ERROR))
+ {
+ if (!SD_GetResponse(SD_START_DATA_SINGLE_BLOCK_READ))
+ {
+ for (i = 0; i < 16; i++)
+ {
+ /*!< Store CSD register value on CSD_Tab */
+ CSD_Tab[i] = SD_ReadByte();
+ }
+ }
+ /*!< Get CRC bytes (not really needed by us, but required by SD) */
+ SD_WriteByte(SD_DUMMY_BYTE);
+ SD_WriteByte(SD_DUMMY_BYTE);
+ /*!< Set response value to success */
+ rvalue = SD_RESPONSE_NO_ERROR;
+ }
+ /*!< SD chip select high */
+ SD_CS_HIGH();
+ /*!< Send dummy byte: 8 Clock pulses of delay */
+ SD_WriteByte(SD_DUMMY_BYTE);
+
+ /*!< Byte 0 */
+ SD_csd->CSDStruct = (CSD_Tab[0] & 0xC0) >> 6;
+ SD_csd->SysSpecVersion = (CSD_Tab[0] & 0x3C) >> 2;
+ SD_csd->Reserved1 = CSD_Tab[0] & 0x03;
+
+ /*!< Byte 1 */
+ SD_csd->TAAC = CSD_Tab[1];
+
+ /*!< Byte 2 */
+ SD_csd->NSAC = CSD_Tab[2];
+
+ /*!< Byte 3 */
+ SD_csd->MaxBusClkFrec = CSD_Tab[3];
+
+ /*!< Byte 4 */
+ SD_csd->CardComdClasses = CSD_Tab[4] << 4;
+
+ /*!< Byte 5 */
+ SD_csd->CardComdClasses |= (CSD_Tab[5] & 0xF0) >> 4;
+ SD_csd->RdBlockLen = CSD_Tab[5] & 0x0F;
+
+ /*!< Byte 6 */
+ SD_csd->PartBlockRead = (CSD_Tab[6] & 0x80) >> 7;
+ SD_csd->WrBlockMisalign = (CSD_Tab[6] & 0x40) >> 6;
+ SD_csd->RdBlockMisalign = (CSD_Tab[6] & 0x20) >> 5;
+ SD_csd->DSRImpl = (CSD_Tab[6] & 0x10) >> 4;
+ SD_csd->Reserved2 = 0; /*!< Reserved */
+
+ SD_csd->DeviceSize = (CSD_Tab[6] & 0x03) << 10;
+
+ /*!< Byte 7 */
+ SD_csd->DeviceSize |= (CSD_Tab[7]) << 2;
+
+ /*!< Byte 8 */
+ SD_csd->DeviceSize |= (CSD_Tab[8] & 0xC0) >> 6;
+
+ SD_csd->MaxRdCurrentVDDMin = (CSD_Tab[8] & 0x38) >> 3;
+ SD_csd->MaxRdCurrentVDDMax = (CSD_Tab[8] & 0x07);
+
+ /*!< Byte 9 */
+ SD_csd->MaxWrCurrentVDDMin = (CSD_Tab[9] & 0xE0) >> 5;
+ SD_csd->MaxWrCurrentVDDMax = (CSD_Tab[9] & 0x1C) >> 2;
+ SD_csd->DeviceSizeMul = (CSD_Tab[9] & 0x03) << 1;
+ /*!< Byte 10 */
+ SD_csd->DeviceSizeMul |= (CSD_Tab[10] & 0x80) >> 7;
+
+ SD_csd->EraseGrSize = (CSD_Tab[10] & 0x40) >> 6;
+ SD_csd->EraseGrMul = (CSD_Tab[10] & 0x3F) << 1;
+
+ /*!< Byte 11 */
+ SD_csd->EraseGrMul |= (CSD_Tab[11] & 0x80) >> 7;
+ SD_csd->WrProtectGrSize = (CSD_Tab[11] & 0x7F);
+
+ /*!< Byte 12 */
+ SD_csd->WrProtectGrEnable = (CSD_Tab[12] & 0x80) >> 7;
+ SD_csd->ManDeflECC = (CSD_Tab[12] & 0x60) >> 5;
+ SD_csd->WrSpeedFact = (CSD_Tab[12] & 0x1C) >> 2;
+ SD_csd->MaxWrBlockLen = (CSD_Tab[12] & 0x03) << 2;
+
+ /*!< Byte 13 */
+ SD_csd->MaxWrBlockLen |= (CSD_Tab[13] & 0xC0) >> 6;
+ SD_csd->WriteBlockPaPartial = (CSD_Tab[13] & 0x20) >> 5;
+ SD_csd->Reserved3 = 0;
+ SD_csd->ContentProtectAppli = (CSD_Tab[13] & 0x01);
+
+ /*!< Byte 14 */
+ SD_csd->FileFormatGrouop = (CSD_Tab[14] & 0x80) >> 7;
+ SD_csd->CopyFlag = (CSD_Tab[14] & 0x40) >> 6;
+ SD_csd->PermWrProtect = (CSD_Tab[14] & 0x20) >> 5;
+ SD_csd->TempWrProtect = (CSD_Tab[14] & 0x10) >> 4;
+ SD_csd->FileFormat = (CSD_Tab[14] & 0x0C) >> 2;
+ SD_csd->ECC = (CSD_Tab[14] & 0x03);
+
+ /*!< Byte 15 */
+ SD_csd->CSD_CRC = (CSD_Tab[15] & 0xFE) >> 1;
+ SD_csd->Reserved4 = 1;
+
+ /*!< Return the reponse */
+ return rvalue;
+}
+
+/**
+ * @brief Read the CID card register.
+ * Reading the contents of the CID register in SPI mode is a simple
+ * read-block transaction.
+ * @param SD_cid: pointer on an CID register structure
+ * @retval The SD Response:
+ * - SD_RESPONSE_FAILURE: Sequence failed
+ * - SD_RESPONSE_NO_ERROR: Sequence succeed
+ */
+SD_Error SD_GetCIDRegister(SD_CID* SD_cid)
+{
+ uint32_t i = 0;
+ SD_Error rvalue = SD_RESPONSE_FAILURE;
+ uint8_t CID_Tab[16];
+
+ /*!< SD chip select low */
+ SD_CS_LOW();
+
+ /*!< Send CMD10 (CID register) */
+ SD_SendCmd(SD_CMD_SEND_CID, 0, 0xFF);
+
+ /*!< Wait for response in the R1 format (0x00 is no errors) */
+ if (!SD_GetResponse(SD_RESPONSE_NO_ERROR))
+ {
+ if (!SD_GetResponse(SD_START_DATA_SINGLE_BLOCK_READ))
+ {
+ /*!< Store CID register value on CID_Tab */
+ for (i = 0; i < 16; i++)
+ {
+ CID_Tab[i] = SD_ReadByte();
+ }
+ }
+ /*!< Get CRC bytes (not really needed by us, but required by SD) */
+ SD_WriteByte(SD_DUMMY_BYTE);
+ SD_WriteByte(SD_DUMMY_BYTE);
+ /*!< Set response value to success */
+ rvalue = SD_RESPONSE_NO_ERROR;
+ }
+ /*!< SD chip select high */
+ SD_CS_HIGH();
+ /*!< Send dummy byte: 8 Clock pulses of delay */
+ SD_WriteByte(SD_DUMMY_BYTE);
+
+ /*!< Byte 0 */
+ SD_cid->ManufacturerID = CID_Tab[0];
+
+ /*!< Byte 1 */
+ SD_cid->OEM_AppliID = CID_Tab[1] << 8;
+
+ /*!< Byte 2 */
+ SD_cid->OEM_AppliID |= CID_Tab[2];
+
+ /*!< Byte 3 */
+ SD_cid->ProdName1 = CID_Tab[3] << 24;
+
+ /*!< Byte 4 */
+ SD_cid->ProdName1 |= CID_Tab[4] << 16;
+
+ /*!< Byte 5 */
+ SD_cid->ProdName1 |= CID_Tab[5] << 8;
+
+ /*!< Byte 6 */
+ SD_cid->ProdName1 |= CID_Tab[6];
+
+ /*!< Byte 7 */
+ SD_cid->ProdName2 = CID_Tab[7];
+
+ /*!< Byte 8 */
+ SD_cid->ProdRev = CID_Tab[8];
+
+ /*!< Byte 9 */
+ SD_cid->ProdSN = CID_Tab[9] << 24;
+
+ /*!< Byte 10 */
+ SD_cid->ProdSN |= CID_Tab[10] << 16;
+
+ /*!< Byte 11 */
+ SD_cid->ProdSN |= CID_Tab[11] << 8;
+
+ /*!< Byte 12 */
+ SD_cid->ProdSN |= CID_Tab[12];
+
+ /*!< Byte 13 */
+ SD_cid->Reserved1 |= (CID_Tab[13] & 0xF0) >> 4;
+ SD_cid->ManufactDate = (CID_Tab[13] & 0x0F) << 8;
+
+ /*!< Byte 14 */
+ SD_cid->ManufactDate |= CID_Tab[14];
+
+ /*!< Byte 15 */
+ SD_cid->CID_CRC = (CID_Tab[15] & 0xFE) >> 1;
+ SD_cid->Reserved2 = 1;
+
+ /*!< Return the reponse */
+ return rvalue;
+}
+
+/**
+ * @brief Send 5 bytes command to the SD card.
+ * @param Cmd: The user expected command to send to SD card.
+ * @param Arg: The command argument.
+ * @param Crc: The CRC.
+ * @retval None
+ */
+void SD_SendCmd(uint8_t Cmd, uint32_t Arg, uint8_t Crc)
+{
+ uint32_t i = 0x00;
+
+ uint8_t Frame[6];
+
+ Frame[0] = (Cmd | 0x40); /*!< Construct byte 1 */
+
+ Frame[1] = (uint8_t)(Arg >> 24); /*!< Construct byte 2 */
+
+ Frame[2] = (uint8_t)(Arg >> 16); /*!< Construct byte 3 */
+
+ Frame[3] = (uint8_t)(Arg >> 8); /*!< Construct byte 4 */
+
+ Frame[4] = (uint8_t)(Arg); /*!< Construct byte 5 */
+
+ Frame[5] = (Crc); /*!< Construct CRC: byte 6 */
+
+ for (i = 0; i < 6; i++)
+ {
+ SD_WriteByte(Frame[i]); /*!< Send the Cmd bytes */
+ }
+}
+
+/**
+ * @brief Get SD card data response.
+ * @param None
+ * @retval The SD status: Read data response xxx0<status>1
+ * - status 010: Data accecpted
+ * - status 101: Data rejected due to a crc error
+ * - status 110: Data rejected due to a Write error.
+ * - status 111: Data rejected due to other error.
+ */
+uint8_t SD_GetDataResponse(void)
+{
+ uint32_t i = 0;
+ uint8_t response, rvalue;
+
+ while (i <= 64)
+ {
+ /*!< Read resonse */
+ response = SD_ReadByte();
+ /*!< Mask unused bits */
+ response &= 0x1F;
+ switch (response)
+ {
+ case SD_DATA_OK:
+ {
+ rvalue = SD_DATA_OK;
+ break;
+ }
+ case SD_DATA_CRC_ERROR:
+ return SD_DATA_CRC_ERROR;
+ case SD_DATA_WRITE_ERROR:
+ return SD_DATA_WRITE_ERROR;
+ default:
+ {
+ rvalue = SD_DATA_OTHER_ERROR;
+ break;
+ }
+ }
+ /*!< Exit loop in case of data ok */
+ if (rvalue == SD_DATA_OK)
+ break;
+ /*!< Increment loop counter */
+ i++;
+ }
+
+ /*!< Wait null data */
+ while (SD_ReadByte() == 0);
+
+ /*!< Return response */
+ return response;
+}
+
+/**
+ * @brief Returns the SD response.
+ * @param None
+ * @retval The SD Response:
+ * - SD_RESPONSE_FAILURE: Sequence failed
+ * - SD_RESPONSE_NO_ERROR: Sequence succeed
+ */
+SD_Error SD_GetResponse(uint8_t Response)
+{
+ uint32_t Count = 0xFFF;
+
+ /*!< Check if response is got or a timeout is happen */
+ while ((SD_ReadByte() != Response) && Count)
+ {
+ Count--;
+ }
+ if (Count == 0)
+ {
+ /*!< After time out */
+ return SD_RESPONSE_FAILURE;
+ }
+ else
+ {
+ /*!< Right response got */
+ return SD_RESPONSE_NO_ERROR;
+ }
+}
+
+/**
+ * @brief Returns the SD status.
+ * @param None
+ * @retval The SD status.
+ */
+uint16_t SD_GetStatus(void)
+{
+ uint16_t Status = 0;
+
+ /*!< SD chip select low */
+ SD_CS_LOW();
+
+ /*!< Send CMD13 (SD_SEND_STATUS) to get SD status */
+ SD_SendCmd(SD_CMD_SEND_STATUS, 0, 0xFF);
+
+ Status = SD_ReadByte();
+ Status |= (uint16_t)(SD_ReadByte() << 8);
+
+ /*!< SD chip select high */
+ SD_CS_HIGH();
+
+ /*!< Send dummy byte 0xFF */
+ SD_WriteByte(SD_DUMMY_BYTE);
+
+ return Status;
+}
+
+/**
+ * @brief Put SD in Idle state.
+ * @param None
+ * @retval The SD Response:
+ * - SD_RESPONSE_FAILURE: Sequence failed
+ * - SD_RESPONSE_NO_ERROR: Sequence succeed
+ */
+SD_Error SD_GoIdleState(void)
+{
+ /*!< SD chip select low */
+ SD_CS_LOW();
+
+ /*!< Send CMD0 (SD_CMD_GO_IDLE_STATE) to put SD in SPI mode */
+ SD_SendCmd(SD_CMD_GO_IDLE_STATE, 0, 0x95);
+
+ /*!< Wait for In Idle State Response (R1 Format) equal to 0x01 */
+ if (SD_GetResponse(SD_IN_IDLE_STATE))
+ {
+ /*!< No Idle State Response: return response failue */
+ return SD_RESPONSE_FAILURE;
+ }
+ /*----------Activates the card initialization process-----------*/
+ do
+ {
+ /*!< SD chip select high */
+ SD_CS_HIGH();
+
+ /*!< Send Dummy byte 0xFF */
+ SD_WriteByte(SD_DUMMY_BYTE);
+
+ /*!< SD chip select low */
+ SD_CS_LOW();
+
+ /*!< Send CMD1 (Activates the card process) until response equal to 0x0 */
+ SD_SendCmd(SD_CMD_SEND_OP_COND, 0, 0xFF);
+ /*!< Wait for no error Response (R1 Format) equal to 0x00 */
+ }
+ while (SD_GetResponse(SD_RESPONSE_NO_ERROR));
+
+ /*!< SD chip select high */
+ SD_CS_HIGH();
+
+ /*!< Send dummy byte 0xFF */
+ SD_WriteByte(SD_DUMMY_BYTE);
+
+ return SD_RESPONSE_NO_ERROR;
+}
+
+/**
+ * @brief Write a byte on the SD.
+ * @param Data: byte to send.
+ * @retval None
+ */
+uint8_t SD_WriteByte(uint8_t Data)
+{
+ /*!< Wait until the transmit buffer is empty */
+ while(SPI_I2S_GetFlagStatus(SD_SPI, SPI_I2S_FLAG_TXE) == RESET)
+ {
+ }
+
+ /*!< Send the byte */
+ SPI_I2S_SendData(SD_SPI, Data);
+
+ /*!< Wait to receive a byte*/
+ while(SPI_I2S_GetFlagStatus(SD_SPI, SPI_I2S_FLAG_RXNE) == RESET)
+ {
+ }
+
+ /*!< Return the byte read from the SPI bus */
+ return (uint8_t)SPI_I2S_ReceiveData(SD_SPI);
+}
+
+/**
+ * @brief Read a byte from the SD.
+ * @param None
+ * @retval The received byte.
+ */
+uint8_t SD_ReadByte(void)
+{
+ uint8_t Data = 0;
+
+ /*!< Wait until the transmit buffer is empty */
+ while (SPI_I2S_GetFlagStatus(SD_SPI, SPI_I2S_FLAG_TXE) == RESET)
+ {
+ }
+ /*!< Send the byte */
+ SPI_I2S_SendData(SD_SPI, SD_DUMMY_BYTE);
+
+ /*!< Wait until a data is received */
+ while (SPI_I2S_GetFlagStatus(SD_SPI, SPI_I2S_FLAG_RXNE) == RESET)
+ {
+ }
+ /*!< Get the received data */
+ Data = (uint8_t)SPI_I2S_ReceiveData(SD_SPI);
+
+ /*!< Return the shifted data */
+ return Data;
+}
+
+/**
+ * @}
+ */
+
+
+/**
+ * @}
+ */
+
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152_EVAL/stm32l152_eval_spi_sd.h b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152_EVAL/stm32l152_eval_spi_sd.h
new file mode 100644
index 0000000..3c47702
--- /dev/null
+++ b/thirdparty/STM32_USB-FS-Device_Lib_V4.0.0/Utilities/STM32_EVAL/STM32L152_EVAL/stm32l152_eval_spi_sd.h
@@ -0,0 +1,286 @@
+/**
+ ******************************************************************************
+ * @file stm32l152_eval_spi_sd.h
+ * @author MCD Application Team
+ * @version V5.0.2
+ * @date 09-March-2012
+ * @brief This file contains all the functions prototypes for the stm32l152_eval_spi_sd
+ * firmware driver.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.st.com/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __STM32L152_EVAL_SPI_SD_H
+#define __STM32L152_EVAL_SPI_SD_H
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+/* Includes ------------------------------------------------------------------*/
+#include "stm32l152_eval.h"
+
+/** @addtogroup Utilities
+ * @{
+ */
+
+/** @addtogroup STM32_EVAL
+ * @{
+ */
+
+/** @addtogroup STM32L152_EVAL
+ * @{
+ */
+
+/** @addtogroup STM32L152_EVAL_SPI_SD
+ * @{
+ */
+
+/** @defgroup STM32L152_EVAL_SPI_SD_Exported_Types
+ * @{
+ */
+
+typedef enum
+{
+/**
+ * @brief SD reponses and error flags
+ */
+ SD_RESPONSE_NO_ERROR = (0x00),
+ SD_IN_IDLE_STATE = (0x01),
+ SD_ERASE_RESET = (0x02),
+ SD_ILLEGAL_COMMAND = (0x04),
+ SD_COM_CRC_ERROR = (0x08),
+ SD_ERASE_SEQUENCE_ERROR = (0x10),
+ SD_ADDRESS_ERROR = (0x20),
+ SD_PARAMETER_ERROR = (0x40),
+ SD_RESPONSE_FAILURE = (0xFF),
+
+/**
+ * @brief Data response error
+ */
+ SD_DATA_OK = (0x05),
+ SD_DATA_CRC_ERROR = (0x0B),
+ SD_DATA_WRITE_ERROR = (0x0D),
+ SD_DATA_OTHER_ERROR = (0xFF)
+} SD_Error;
+
+/**
+ * @brief Card Specific Data: CSD Register
+ */
+typedef struct
+{
+ __IO uint8_t CSDStruct; /*!< CSD structure */
+ __IO uint8_t SysSpecVersion; /*!< System specification version */
+ __IO uint8_t Reserved1; /*!< Reserved */
+ __IO uint8_t TAAC; /*!< Data read access-time 1 */
+ __IO uint8_t NSAC; /*!< Data read access-time 2 in CLK cycles */
+ __IO uint8_t MaxBusClkFrec; /*!< Max. bus clock frequency */
+ __IO uint16_t CardComdClasses; /*!< Card command classes */
+ __IO uint8_t RdBlockLen; /*!< Max. read data block length */
+ __IO uint8_t PartBlockRead; /*!< Partial blocks for read allowed */
+ __IO uint8_t WrBlockMisalign; /*!< Write block misalignment */
+ __IO uint8_t RdBlockMisalign; /*!< Read block misalignment */
+ __IO uint8_t DSRImpl; /*!< DSR implemented */
+ __IO uint8_t Reserved2; /*!< Reserved */
+ __IO uint32_t DeviceSize; /*!< Device Size */
+ __IO uint8_t MaxRdCurrentVDDMin; /*!< Max. read current @ VDD min */
+ __IO uint8_t MaxRdCurrentVDDMax; /*!< Max. read current @ VDD max */
+ __IO uint8_t MaxWrCurrentVDDMin; /*!< Max. write current @ VDD min */
+ __IO uint8_t MaxWrCurrentVDDMax; /*!< Max. write current @ VDD max */
+ __IO uint8_t DeviceSizeMul; /*!< Device size multiplier */
+ __IO uint8_t EraseGrSize; /*!< Erase group size */
+ __IO uint8_t EraseGrMul; /*!< Erase group size multiplier */
+ __IO uint8_t WrProtectGrSize; /*!< Write protect group size */
+ __IO uint8_t WrProtectGrEnable; /*!< Write protect group enable */
+ __IO uint8_t ManDeflECC; /*!< Manufacturer default ECC */
+ __IO uint8_t WrSpeedFact; /*!< Write speed factor */
+ __IO uint8_t MaxWrBlockLen; /*!< Max. write data block length */
+ __IO uint8_t WriteBlockPaPartial; /*!< Partial blocks for write allowed */
+ __IO uint8_t Reserved3; /*!< Reserded */
+ __IO uint8_t ContentProtectAppli; /*!< Content protection application */
+ __IO uint8_t FileFormatGrouop; /*!< File format group */
+ __IO uint8_t CopyFlag; /*!< Copy flag (OTP) */
+ __IO uint8_t PermWrProtect; /*!< Permanent write protection */
+ __IO uint8_t TempWrProtect; /*!< Temporary write protection */
+ __IO uint8_t FileFormat; /*!< File Format */
+ __IO uint8_t ECC; /*!< ECC code */
+ __IO uint8_t CSD_CRC; /*!< CSD CRC */
+ __IO uint8_t Reserved4; /*!< always 1*/
+} SD_CSD;
+
+/**
+ * @brief Card Identification Data: CID Register
+ */
+typedef struct
+{
+ __IO uint8_t ManufacturerID; /*!< ManufacturerID */
+ __IO uint16_t OEM_AppliID; /*!< OEM/Application ID */
+ __IO uint32_t ProdName1; /*!< Product Name part1 */
+ __IO uint8_t ProdName2; /*!< Product Name part2*/
+ __IO uint8_t ProdRev; /*!< Product Revision */
+ __IO uint32_t ProdSN; /*!< Product Serial Number */
+ __IO uint8_t Reserved1; /*!< Reserved1 */
+ __IO uint16_t ManufactDate; /*!< Manufacturing Date */
+ __IO uint8_t CID_CRC; /*!< CID CRC */
+ __IO uint8_t Reserved2; /*!< always 1 */
+} SD_CID;
+
+/**
+ * @brief SD Card information
+ */
+typedef struct
+{
+ SD_CSD SD_csd;
+ SD_CID SD_cid;
+ uint32_t CardCapacity; /*!< Card Capacity */
+ uint32_t CardBlockSize; /*!< Card Block Size */
+} SD_CardInfo;
+
+/**
+ * @}
+ */
+
+/** @defgroup STM32L152_EVAL_SPI_SD_Exported_Constants
+ * @{
+ */
+
+/**
+ * @brief Block Size
+ */
+#define SD_BLOCK_SIZE 0x200
+
+/**
+ * @brief Dummy byte
+ */
+#define SD_DUMMY_BYTE 0xFF
+
+/**
+ * @brief Start Data tokens:
+ * Tokens (necessary because at nop/idle (and CS active) only 0xff is
+ * on the data/command line)
+ */
+#define SD_START_DATA_SINGLE_BLOCK_READ 0xFE /*!< Data token start byte, Start Single Block Read */
+#define SD_START_DATA_MULTIPLE_BLOCK_READ 0xFE /*!< Data token start byte, Start Multiple Block Read */
+#define SD_START_DATA_SINGLE_BLOCK_WRITE 0xFE /*!< Data token start byte, Start Single Block Write */
+#define SD_START_DATA_MULTIPLE_BLOCK_WRITE 0xFD /*!< Data token start byte, Start Multiple Block Write */
+#define SD_STOP_DATA_MULTIPLE_BLOCK_WRITE 0xFD /*!< Data toke stop byte, Stop Multiple Block Write */
+
+/**
+ * @brief SD detection on its memory slot
+ */
+#define SD_PRESENT ((uint8_t)0x01)
+#define SD_NOT_PRESENT ((uint8_t)0x00)
+
+
+/**
+ * @brief Commands: CMDxx = CMD-number | 0x40
+ */
+#define SD_CMD_GO_IDLE_STATE 0 /*!< CMD0 = 0x40 */
+#define SD_CMD_SEND_OP_COND 1 /*!< CMD1 = 0x41 */
+#define SD_CMD_SEND_CSD 9 /*!< CMD9 = 0x49 */
+#define SD_CMD_SEND_CID 10 /*!< CMD10 = 0x4A */
+#define SD_CMD_STOP_TRANSMISSION 12 /*!< CMD12 = 0x4C */
+#define SD_CMD_SEND_STATUS 13 /*!< CMD13 = 0x4D */
+#define SD_CMD_SET_BLOCKLEN 16 /*!< CMD16 = 0x50 */
+#define SD_CMD_READ_SINGLE_BLOCK 17 /*!< CMD17 = 0x51 */
+#define SD_CMD_READ_MULT_BLOCK 18 /*!< CMD18 = 0x52 */
+#define SD_CMD_SET_BLOCK_COUNT 23 /*!< CMD23 = 0x57 */
+#define SD_CMD_WRITE_SINGLE_BLOCK 24 /*!< CMD24 = 0x58 */
+#define SD_CMD_WRITE_MULT_BLOCK 25 /*!< CMD25 = 0x59 */
+#define SD_CMD_PROG_CSD 27 /*!< CMD27 = 0x5B */
+#define SD_CMD_SET_WRITE_PROT 28 /*!< CMD28 = 0x5C */
+#define SD_CMD_CLR_WRITE_PROT 29 /*!< CMD29 = 0x5D */
+#define SD_CMD_SEND_WRITE_PROT 30 /*!< CMD30 = 0x5E */
+#define SD_CMD_SD_ERASE_GRP_START 32 /*!< CMD32 = 0x60 */
+#define SD_CMD_SD_ERASE_GRP_END 33 /*!< CMD33 = 0x61 */
+#define SD_CMD_UNTAG_SECTOR 34 /*!< CMD34 = 0x62 */
+#define SD_CMD_ERASE_GRP_START 35 /*!< CMD35 = 0x63 */
+#define SD_CMD_ERASE_GRP_END 36 /*!< CMD36 = 0x64 */
+#define SD_CMD_UNTAG_ERASE_GROUP 37 /*!< CMD37 = 0x65 */
+#define SD_CMD_ERASE 38 /*!< CMD38 = 0x66 */
+
+/**
+ * @}
+ */
+
+/** @defgroup STM32L152_EVAL_SPI_SD_Exported_Macros
+ * @{
+ */
+/**
+ * @brief Select SD Card: ChipSelect pin low
+ */
+#define SD_CS_LOW() GPIO_ResetBits(SD_CS_GPIO_PORT, SD_CS_PIN)
+/**
+ * @brief Deselect SD Card: ChipSelect pin high
+ */
+#define SD_CS_HIGH() GPIO_SetBits(SD_CS_GPIO_PORT, SD_CS_PIN)
+/**
+ * @}
+ */
+
+/** @defgroup STM32L152_EVAL_SPI_SD_Exported_Functions
+ * @{
+ */
+void SD_DeInit(void);
+SD_Error SD_Init(void);
+uint8_t SD_Detect(void);
+SD_Error SD_GetCardInfo(SD_CardInfo *cardinfo);
+SD_Error SD_ReadBlock(uint8_t* pBuffer, uint32_t ReadAddr, uint16_t BlockSize);
+SD_Error SD_ReadMultiBlocks(uint8_t* pBuffer, uint32_t ReadAddr, uint16_t BlockSize, uint32_t NumberOfBlocks);
+SD_Error SD_WriteBlock(uint8_t* pBuffer, uint32_t WriteAddr, uint16_t BlockSize);
+SD_Error SD_WriteMultiBlocks(uint8_t* pBuffer, uint32_t WriteAddr, uint16_t BlockSize, uint32_t NumberOfBlocks);
+SD_Error SD_GetCSDRegister(SD_CSD* SD_csd);
+SD_Error SD_GetCIDRegister(SD_CID* SD_cid);
+
+void SD_SendCmd(uint8_t Cmd, uint32_t Arg, uint8_t Crc);
+SD_Error SD_GetResponse(uint8_t Response);
+uint8_t SD_GetDataResponse(void);
+SD_Error SD_GoIdleState(void);
+uint16_t SD_GetStatus(void);
+
+uint8_t SD_WriteByte(uint8_t byte);
+uint8_t SD_ReadByte(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __STM32L152_EVAL_SPI_SD_H */
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/