添加移除后自动重启 for stm32-netradio
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@416 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
parent
bb4f74cd12
commit
7225a9234e
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
#include "stm32f10x.h"
|
#include "stm32f10x.h"
|
||||||
|
#include "platform_config.h"
|
||||||
|
|
||||||
/* Exported types ------------------------------------------------------------*/
|
/* Exported types ------------------------------------------------------------*/
|
||||||
/* Exported constants --------------------------------------------------------*/
|
/* Exported constants --------------------------------------------------------*/
|
||||||
|
@ -24,6 +24,9 @@
|
|||||||
#define USB_DISCONNECT_PIN GPIO_Pin_7
|
#define USB_DISCONNECT_PIN GPIO_Pin_7
|
||||||
#define RCC_APB2Periph_GPIO_DISCONNECT RCC_APB2Periph_GPIOG
|
#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 */
|
/* use led: 0-NO 1-YES */
|
||||||
#define USB_USE_LED 1
|
#define USB_USE_LED 1
|
||||||
#define USB_LED_PORT GPIOE
|
#define USB_LED_PORT GPIOE
|
||||||
|
@ -91,8 +91,14 @@ uint16_t MAL_Read(uint8_t lun, uint32_t Memory_Offset, uint32_t *Readbuff, uint1
|
|||||||
return MAL_OK;
|
return MAL_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if (USB_USE_AUTO_REMOVE == 1)
|
||||||
|
unsigned long test_unit_ready_last = 0;
|
||||||
|
#endif
|
||||||
uint16_t MAL_GetStatus (uint8_t lun)
|
uint16_t MAL_GetStatus (uint8_t lun)
|
||||||
{
|
{
|
||||||
|
#if (USB_USE_AUTO_REMOVE == 1)
|
||||||
|
test_unit_ready_last = rt_tick_get();
|
||||||
|
#endif
|
||||||
switch(lun)
|
switch(lun)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
|
@ -1,72 +1,102 @@
|
|||||||
#include "stm32f10x.h"
|
#include "stm32f10x.h"
|
||||||
#include "usb_lib.h"
|
#include "usb_lib.h"
|
||||||
#include "usb_istr.h"
|
#include "usb_istr.h"
|
||||||
#include "hw_config.h"
|
#include "hw_config.h"
|
||||||
#include "usb_pwr.h"
|
#include "usb_pwr.h"
|
||||||
|
|
||||||
#include "rtthread.h"
|
#include "rtthread.h"
|
||||||
|
|
||||||
extern uint32_t Mass_Memory_Size[3];
|
extern uint32_t Mass_Memory_Size[3];
|
||||||
extern uint32_t Mass_Block_Size[3];
|
extern uint32_t Mass_Block_Size[3];
|
||||||
extern uint32_t Mass_Block_Count[3];
|
extern uint32_t Mass_Block_Count[3];
|
||||||
extern rt_device_t dev_sdio;
|
extern rt_device_t dev_sdio;
|
||||||
extern rt_device_t dev_spi_flash;
|
extern rt_device_t dev_spi_flash;
|
||||||
|
|
||||||
#include <finsh.h>
|
#if (USB_USE_AUTO_REMOVE == 1)
|
||||||
#include "sdcard.h"
|
extern unsigned long test_unit_ready_last;
|
||||||
void USB_cable(void)
|
void msc_thread_entry(void *parameter)
|
||||||
{
|
{
|
||||||
rt_device_t dev = RT_NULL;
|
test_unit_ready_last = rt_tick_get();
|
||||||
SD_CardInfo * sdio_info = RT_NULL;
|
while(1)
|
||||||
dev = rt_device_find("sd0");
|
{
|
||||||
|
rt_thread_delay( RT_TICK_PER_SECOND/2 );
|
||||||
{
|
if( rt_tick_get() - test_unit_ready_last > RT_TICK_PER_SECOND*2 )
|
||||||
SPI_InitTypeDef SPI_InitStructure;
|
{
|
||||||
/*------------------------ SPI1 configuration ------------------------*/
|
rt_kprintf("\r\nCable removed!\r\nSystemReset\r\n\r\n");
|
||||||
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;//SPI_Direction_1Line_Tx;
|
NVIC_SystemReset();
|
||||||
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;
|
#endif
|
||||||
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
|
|
||||||
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_16;/* 72M/64=1.125M */
|
#include <finsh.h>
|
||||||
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
|
#include "sdcard.h"
|
||||||
SPI_InitStructure.SPI_CRCPolynomial = 7;
|
void USB_cable(void)
|
||||||
|
{
|
||||||
SPI_I2S_DeInit(SPI1);
|
rt_device_t dev = RT_NULL;
|
||||||
SPI_Init(SPI1, &SPI_InitStructure);
|
SD_CardInfo * sdio_info = RT_NULL;
|
||||||
|
dev = rt_device_find("sd0");
|
||||||
/* Enable SPI_MASTER */
|
|
||||||
SPI_Cmd(SPI1, ENABLE);
|
{
|
||||||
SPI_CalculateCRC(SPI1, DISABLE);
|
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_FLASH */
|
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
|
||||||
dev_spi_flash = rt_device_find("spi0");
|
SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
|
||||||
Mass_Block_Size[1] = 512;
|
SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;
|
||||||
Mass_Block_Count[1] = 4096;
|
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
|
||||||
Mass_Memory_Size[1] = 4096*512;
|
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_16;/* 72M/64=1.125M */
|
||||||
|
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
|
||||||
if(dev != RT_NULL)
|
SPI_InitStructure.SPI_CRCPolynomial = 7;
|
||||||
{
|
|
||||||
dev_sdio = dev;
|
SPI_I2S_DeInit(SPI1);
|
||||||
sdio_info = (SD_CardInfo *)dev->private;
|
SPI_Init(SPI1, &SPI_InitStructure);
|
||||||
Mass_Memory_Size[0] = sdio_info->CardCapacity;
|
|
||||||
Mass_Block_Size[0] = sdio_info->CardBlockSize;
|
/* Enable SPI_MASTER */
|
||||||
Mass_Block_Count[0] = Mass_Memory_Size[0] / Mass_Block_Size[0];
|
SPI_Cmd(SPI1, ENABLE);
|
||||||
}
|
SPI_CalculateCRC(SPI1, DISABLE);
|
||||||
else
|
}
|
||||||
{
|
|
||||||
rt_kprintf("\r\nNo find the device sd0 !!!!");
|
|
||||||
}
|
/* SPI_FLASH */
|
||||||
|
dev_spi_flash = rt_device_find("spi0");
|
||||||
/* 3:NAND */
|
Mass_Block_Size[1] = 512;
|
||||||
|
Mass_Block_Count[1] = 4096;
|
||||||
/* usb msc up*/
|
Mass_Memory_Size[1] = 4096*512;
|
||||||
Set_System();
|
|
||||||
Set_USBClock();
|
if(dev != RT_NULL)
|
||||||
USB_Interrupts_Config();
|
{
|
||||||
USB_Init();
|
dev_sdio = dev;
|
||||||
}
|
sdio_info = (SD_CardInfo *)dev->private;
|
||||||
FINSH_FUNCTION_EXPORT(USB_cable, cable_the_usb);
|
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);
|
||||||
|
@ -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_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_dc_draw_hline(dc, 14 + (tinfo.position * 212)/ tinfo.duration, 226, 75);
|
||||||
}
|
}
|
||||||
|
|
||||||
RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(home_view)) = saved;
|
RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(home_view)) = saved;
|
||||||
rtgui_dc_end_drawing(dc);
|
rtgui_dc_end_drawing(dc);
|
||||||
}
|
}
|
||||||
@ -210,7 +210,7 @@ void player_play_file(const char* fn)
|
|||||||
{
|
{
|
||||||
rtgui_rect_t play_rect;
|
rtgui_rect_t play_rect;
|
||||||
rtgui_image_t *button;
|
rtgui_image_t *button;
|
||||||
|
|
||||||
/* update tag information */
|
/* update tag information */
|
||||||
player_update_tag_info(dc);
|
player_update_tag_info(dc);
|
||||||
|
|
||||||
@ -254,7 +254,7 @@ void player_play_url(const char* url)
|
|||||||
{
|
{
|
||||||
rtgui_rect_t play_rect;
|
rtgui_rect_t play_rect;
|
||||||
rtgui_image_t *button;
|
rtgui_image_t *button;
|
||||||
|
|
||||||
/* update tag information */
|
/* update tag information */
|
||||||
player_update_tag_info(dc);
|
player_update_tag_info(dc);
|
||||||
|
|
||||||
@ -387,6 +387,12 @@ void function_action(void* parameter)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern void USB_cable(void);
|
||||||
|
void function_cable(void)
|
||||||
|
{
|
||||||
|
USB_cable();
|
||||||
|
}
|
||||||
|
|
||||||
struct list_item function_list[] =
|
struct list_item function_list[] =
|
||||||
{
|
{
|
||||||
{"选择电台", RT_NULL, function_play_radio, RT_NULL},
|
{"选择电台", 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_filelist, RT_NULL},
|
||||||
{"设备信息", RT_NULL, function_device, RT_NULL},
|
{"设备信息", RT_NULL, function_device, RT_NULL},
|
||||||
{"选项设置", RT_NULL, function_action, RT_NULL},
|
{"选项设置", RT_NULL, function_action, RT_NULL},
|
||||||
|
{"USB 联机", RT_NULL, function_cable, RT_NULL},
|
||||||
{"返回播放器", RT_NULL, function_player, 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);
|
dc = rtgui_dc_begin_drawing(widget);
|
||||||
if (dc == RT_NULL) return RT_FALSE;
|
if (dc == RT_NULL) return RT_FALSE;
|
||||||
|
|
||||||
player_update_tag_info(dc);
|
player_update_tag_info(dc);
|
||||||
|
|
||||||
saved = RTGUI_WIDGET_FOREGROUND(widget);
|
saved = RTGUI_WIDGET_FOREGROUND(widget);
|
||||||
|
|
||||||
RTGUI_WIDGET_FOREGROUND(widget) = RTGUI_RGB(82, 199, 16);
|
RTGUI_WIDGET_FOREGROUND(widget) = RTGUI_RGB(82, 199, 16);
|
||||||
rtgui_dc_draw_hline(dc, 14, 226, 75);
|
rtgui_dc_draw_hline(dc, 14, 226, 75);
|
||||||
|
|
||||||
/* update play button */
|
/* update play button */
|
||||||
button = rtgui_image_create_from_mem("hdc",
|
button = rtgui_image_create_from_mem("hdc",
|
||||||
stop_hdh, sizeof(stop_hdh), RT_FALSE);
|
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;
|
play_rect.x2 = 61; play_rect.y2 = 114;
|
||||||
rtgui_image_blit(button, dc, &play_rect);
|
rtgui_image_blit(button, dc, &play_rect);
|
||||||
rtgui_image_destroy(button);
|
rtgui_image_destroy(button);
|
||||||
|
|
||||||
RTGUI_WIDGET_FOREGROUND(widget) = saved;
|
RTGUI_WIDGET_FOREGROUND(widget) = saved;
|
||||||
rtgui_dc_end_drawing(dc);
|
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_color_t saved;
|
||||||
rtgui_image_t *button;
|
rtgui_image_t *button;
|
||||||
rtgui_rect_t play_rect;
|
rtgui_rect_t play_rect;
|
||||||
|
|
||||||
/* set stat */
|
/* set stat */
|
||||||
next_step = PLAYER_STEP_STOP;
|
next_step = PLAYER_STEP_STOP;
|
||||||
player_mode = PLAYER_STOP;
|
player_mode = PLAYER_STOP;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user