diff --git a/bsp/stm32_radio/Libraries/Mass_Storage/inc/hw_config.h b/bsp/stm32_radio/Libraries/Mass_Storage/inc/hw_config.h index 20e73b376d991f195767db6f8474de5acd4fb3c6..fc63a69773bfdc4765e989816c0a24d047cb0d71 100644 --- a/bsp/stm32_radio/Libraries/Mass_Storage/inc/hw_config.h +++ b/bsp/stm32_radio/Libraries/Mass_Storage/inc/hw_config.h @@ -19,6 +19,7 @@ /* Includes ------------------------------------------------------------------*/ #include "stm32f10x.h" +#include "platform_config.h" /* Exported types ------------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/ diff --git a/bsp/stm32_radio/Libraries/Mass_Storage/inc/platform_config.h b/bsp/stm32_radio/Libraries/Mass_Storage/inc/platform_config.h index 1a8f7922e690a5e4fef0e99010ca708a887cba60..909289b91c34ffacf5a6a758394fd932728eb225 100644 --- a/bsp/stm32_radio/Libraries/Mass_Storage/inc/platform_config.h +++ b/bsp/stm32_radio/Libraries/Mass_Storage/inc/platform_config.h @@ -24,6 +24,9 @@ #define USB_DISCONNECT_PIN GPIO_Pin_7 #define RCC_APB2Periph_GPIO_DISCONNECT RCC_APB2Periph_GPIOG +/* use auto remove: 0-NO 1-YES */ +#define USB_USE_AUTO_REMOVE 1 + /* use led: 0-NO 1-YES */ #define USB_USE_LED 1 #define USB_LED_PORT GPIOE diff --git a/bsp/stm32_radio/Libraries/Mass_Storage/src/mass_mal.c b/bsp/stm32_radio/Libraries/Mass_Storage/src/mass_mal.c index bc5281564f076f78f7dfb5b8f7de34c46bce32bb..0399f4cc944d23fa51a4f4f5c259bb52cdc1f6db 100644 --- a/bsp/stm32_radio/Libraries/Mass_Storage/src/mass_mal.c +++ b/bsp/stm32_radio/Libraries/Mass_Storage/src/mass_mal.c @@ -91,8 +91,14 @@ uint16_t MAL_Read(uint8_t lun, uint32_t Memory_Offset, uint32_t *Readbuff, uint1 return MAL_OK; } +#if (USB_USE_AUTO_REMOVE == 1) +unsigned long test_unit_ready_last = 0; +#endif uint16_t MAL_GetStatus (uint8_t lun) { +#if (USB_USE_AUTO_REMOVE == 1) + test_unit_ready_last = rt_tick_get(); +#endif switch(lun) { case 0: diff --git a/bsp/stm32_radio/Libraries/Mass_Storage/src/usb_main.c b/bsp/stm32_radio/Libraries/Mass_Storage/src/usb_main.c index 1d05a08e8ead8e48b3f68d9bc4e183949aad3aa5..cf36d32f8c70bc5f8a5ebe305a7a1462d221d235 100644 --- a/bsp/stm32_radio/Libraries/Mass_Storage/src/usb_main.c +++ b/bsp/stm32_radio/Libraries/Mass_Storage/src/usb_main.c @@ -1,72 +1,102 @@ -#include "stm32f10x.h" -#include "usb_lib.h" -#include "usb_istr.h" -#include "hw_config.h" -#include "usb_pwr.h" - -#include "rtthread.h" - -extern uint32_t Mass_Memory_Size[3]; -extern uint32_t Mass_Block_Size[3]; -extern uint32_t Mass_Block_Count[3]; -extern rt_device_t dev_sdio; -extern rt_device_t dev_spi_flash; - -#include -#include "sdcard.h" -void USB_cable(void) -{ - rt_device_t dev = RT_NULL; - SD_CardInfo * sdio_info = RT_NULL; - dev = rt_device_find("sd0"); - - { - SPI_InitTypeDef SPI_InitStructure; - /*------------------------ SPI1 configuration ------------------------*/ - SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;//SPI_Direction_1Line_Tx; - 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_16;/* 72M/64=1.125M */ - SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; - SPI_InitStructure.SPI_CRCPolynomial = 7; - - SPI_I2S_DeInit(SPI1); - SPI_Init(SPI1, &SPI_InitStructure); - - /* Enable SPI_MASTER */ - SPI_Cmd(SPI1, ENABLE); - SPI_CalculateCRC(SPI1, DISABLE); - } - - - /* SPI_FLASH */ - dev_spi_flash = rt_device_find("spi0"); - Mass_Block_Size[1] = 512; - Mass_Block_Count[1] = 4096; - Mass_Memory_Size[1] = 4096*512; - - if(dev != RT_NULL) - { - dev_sdio = dev; - sdio_info = (SD_CardInfo *)dev->private; - Mass_Memory_Size[0] = sdio_info->CardCapacity; - Mass_Block_Size[0] = sdio_info->CardBlockSize; - Mass_Block_Count[0] = Mass_Memory_Size[0] / Mass_Block_Size[0]; - } - else - { - rt_kprintf("\r\nNo find the device sd0 !!!!"); - } - - /* 3:NAND */ - - /* usb msc up*/ - Set_System(); - Set_USBClock(); - USB_Interrupts_Config(); - USB_Init(); -} -FINSH_FUNCTION_EXPORT(USB_cable, cable_the_usb); +#include "stm32f10x.h" +#include "usb_lib.h" +#include "usb_istr.h" +#include "hw_config.h" +#include "usb_pwr.h" + +#include "rtthread.h" + +extern uint32_t Mass_Memory_Size[3]; +extern uint32_t Mass_Block_Size[3]; +extern uint32_t Mass_Block_Count[3]; +extern rt_device_t dev_sdio; +extern rt_device_t dev_spi_flash; + +#if (USB_USE_AUTO_REMOVE == 1) +extern unsigned long test_unit_ready_last; +void msc_thread_entry(void *parameter) +{ + test_unit_ready_last = rt_tick_get(); + while(1) + { + rt_thread_delay( RT_TICK_PER_SECOND/2 ); + if( rt_tick_get() - test_unit_ready_last > RT_TICK_PER_SECOND*2 ) + { + rt_kprintf("\r\nCable removed!\r\nSystemReset\r\n\r\n"); + NVIC_SystemReset(); + } + } +} +#endif + +#include +#include "sdcard.h" +void USB_cable(void) +{ + rt_device_t dev = RT_NULL; + SD_CardInfo * sdio_info = RT_NULL; + dev = rt_device_find("sd0"); + + { + SPI_InitTypeDef SPI_InitStructure; + /*------------------------ SPI1 configuration ------------------------*/ + SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;//SPI_Direction_1Line_Tx; + 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_16;/* 72M/64=1.125M */ + SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; + SPI_InitStructure.SPI_CRCPolynomial = 7; + + SPI_I2S_DeInit(SPI1); + SPI_Init(SPI1, &SPI_InitStructure); + + /* Enable SPI_MASTER */ + SPI_Cmd(SPI1, ENABLE); + SPI_CalculateCRC(SPI1, DISABLE); + } + + + /* SPI_FLASH */ + dev_spi_flash = rt_device_find("spi0"); + Mass_Block_Size[1] = 512; + Mass_Block_Count[1] = 4096; + Mass_Memory_Size[1] = 4096*512; + + if(dev != RT_NULL) + { + dev_sdio = dev; + sdio_info = (SD_CardInfo *)dev->private; + Mass_Memory_Size[0] = sdio_info->CardCapacity; + Mass_Block_Size[0] = sdio_info->CardBlockSize; + Mass_Block_Count[0] = Mass_Memory_Size[0] / Mass_Block_Size[0]; + } + else + { + rt_kprintf("\r\nNo find the device sd0 !!!!"); + } + + /* 3:NAND */ + + /* usb msc up*/ + Set_System(); + Set_USBClock(); + USB_Interrupts_Config(); + USB_Init(); + +#if (USB_USE_AUTO_REMOVE == 1) + /* delete the other thread */ + + /* create msc_thread */ + { + rt_thread_t msc_thread; + msc_thread = rt_thread_create("msc_thread", + msc_thread_entry, RT_NULL, + 1024, RT_THREAD_PRIORITY_MAX-1,1); + if (msc_thread != RT_NULL) rt_thread_startup(msc_thread); + } +#endif +} +FINSH_FUNCTION_EXPORT(USB_cable, cable_the_usb); diff --git a/bsp/stm32_radio/player_ui.c b/bsp/stm32_radio/player_ui.c index f6b12ec6e652ee624f5517dc8730c481cdc50e20..2869ccdb87e096a184cf426c9643cc5bde26ef06 100644 --- a/bsp/stm32_radio/player_ui.c +++ b/bsp/stm32_radio/player_ui.c @@ -73,7 +73,7 @@ void info_timer_timeout(rtgui_timer_t* timer, void* parameter) RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(home_view)) = RTGUI_RGB(82, 199, 16); rtgui_dc_draw_hline(dc, 14 + (tinfo.position * 212)/ tinfo.duration, 226, 75); } - + RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(home_view)) = saved; rtgui_dc_end_drawing(dc); } @@ -210,7 +210,7 @@ void player_play_file(const char* fn) { rtgui_rect_t play_rect; rtgui_image_t *button; - + /* update tag information */ player_update_tag_info(dc); @@ -254,7 +254,7 @@ void player_play_url(const char* url) { rtgui_rect_t play_rect; rtgui_image_t *button; - + /* update tag information */ player_update_tag_info(dc); @@ -387,6 +387,12 @@ void function_action(void* parameter) return; } +extern void USB_cable(void); +void function_cable(void) +{ + USB_cable(); +} + struct list_item function_list[] = { {"选择电台", RT_NULL, function_play_radio, RT_NULL}, @@ -394,6 +400,7 @@ struct list_item function_list[] = {"播放文件", RT_NULL, function_filelist, RT_NULL}, {"设备信息", RT_NULL, function_device, RT_NULL}, {"选项设置", RT_NULL, function_action, RT_NULL}, + {"USB 联机", RT_NULL, function_cable, RT_NULL}, {"返回播放器", RT_NULL, function_player, RT_NULL}, }; @@ -581,14 +588,14 @@ static rt_bool_t home_view_event_handler(struct rtgui_widget* widget, struct rtg dc = rtgui_dc_begin_drawing(widget); if (dc == RT_NULL) return RT_FALSE; - + player_update_tag_info(dc); saved = RTGUI_WIDGET_FOREGROUND(widget); RTGUI_WIDGET_FOREGROUND(widget) = RTGUI_RGB(82, 199, 16); rtgui_dc_draw_hline(dc, 14, 226, 75); - + /* update play button */ button = rtgui_image_create_from_mem("hdc", stop_hdh, sizeof(stop_hdh), RT_FALSE); @@ -596,7 +603,7 @@ static rt_bool_t home_view_event_handler(struct rtgui_widget* widget, struct rtg play_rect.x2 = 61; play_rect.y2 = 114; rtgui_image_blit(button, dc, &play_rect); rtgui_image_destroy(button); - + RTGUI_WIDGET_FOREGROUND(widget) = saved; rtgui_dc_end_drawing(dc); } @@ -608,7 +615,7 @@ static rt_bool_t home_view_event_handler(struct rtgui_widget* widget, struct rtg rtgui_color_t saved; rtgui_image_t *button; rtgui_rect_t play_rect; - + /* set stat */ next_step = PLAYER_STEP_STOP; player_mode = PLAYER_STOP;