import rtconfig
Import('RTT_ROOT')
from building import *

# get current directory
cwd = GetCurrentDir()

# The set of source files associated with this SConscript file.
src = Split("""
CMSIS/Device/ST/STM32F0xx/Source/Templates/system_stm32f0xx.c
STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_dma.c
STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_cortex.c
STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_crc.c
STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_crc_ex.c
STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_pwr.c
STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_rcc.c
STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_rcc_ex.c
STM32F0xx_HAL_Driver/Src/stm32f0xx_hal.c
STM32F0xx_HAL_Driver/Src/stm32f0xx_ll_crc.c
STM32F0xx_HAL_Driver/Src/stm32f0xx_ll_dma.c
STM32F0xx_HAL_Driver/Src/stm32f0xx_ll_exti.c
STM32F0xx_HAL_Driver/Src/stm32f0xx_ll_gpio.c
STM32F0xx_HAL_Driver/Src/stm32f0xx_ll_pwr.c
STM32F0xx_HAL_Driver/Src/stm32f0xx_ll_rcc.c
STM32F0xx_HAL_Driver/Src/stm32f0xx_ll_utils.c
STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_gpio.c
""")

if GetDepend(['RT_USING_SERIAL']):
    src += ['STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_uart.c']
    src += ['STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_uart_ex.c']
    src += ['STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_usart.c']
    src += ['STM32F0xx_HAL_Driver/Src/stm32f0xx_ll_usart.c']

if GetDepend(['RT_USING_I2C']):
    src += ['STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_i2c.c']
    src += ['STM32F0xx_HAL_Driver/Src/stm32f0xx_ll_i2c.c']
    src += ['STM32F0xx_HAL_Driver/Src/stm32f0xx_ll_i2c.c']

if GetDepend(['RT_USING_SPI']):
    src += ['STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_spi.c']
    src += ['STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_spi_ex.c'] 
    src += ['STM32F0xx_HAL_Driver/Src/stm32f0xx_ll_spi.c']

if GetDepend(['RT_USING_USB']):
    src += ['STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_pcd.c']
    src += ['STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_pcd_ex.c']

if GetDepend(['RT_USING_CAN']):
    src += ['STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_can.c']

if GetDepend(['RT_USING_HWTIMER']) or GetDepend(['RT_USING_PWM']):
    src += ['STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_tim.c']
    src += ['STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_tim_ex.c']
    src += ['STM32F0xx_HAL_Driver/Src/stm32f0xx_ll_tim.c']
    

if GetDepend(['RT_USING_ADC']):
    src += ['STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_adc.c']
    src += ['STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_adc_ex.c']
    src += ['STM32F0xx_HAL_Driver/Src/stm32f0xx_ll_adc.c']
    
if GetDepend(['RT_USING_RTC']):
    src += ['STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_rtc.c']
    src += ['STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_rtc_ex.c']
    src += ['STM32F0xx_HAL_Driver/Src/stm32f0xx_ll_rtc.c']
    
if GetDepend(['RT_USING_WDT']):
    src += ['STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_iwdg.c']
    src += ['STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_wwdg.c']

if GetDepend(['RT_USING_AUDIO']):
    src += ['STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_i2s.c']

if GetDepend(['BSP_USING_ON_CHIP_FLASH']):
    src += ['STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_flash.c']
    src += ['STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_flash_ex.c']

path = [cwd + '/CMSIS/Device/ST/STM32F0xx/Include', 
    cwd + '/STM32F0xx_HAL_Driver/Inc']

CPPDEFINES = ['USE_HAL_DRIVER']
group = DefineGroup('Libraries', src, depend = [''], CPPPATH = path, CPPDEFINES = CPPDEFINES)

Return('group')
