Ejemplo n.º 1
0
/**
 * This function will initialize the usb host stack, all the usb class driver and
 * host controller driver are also be initialized here.
 * 
 * @return none.
 */
rt_err_t rt_usb_host_init(void)
{
    ucd_t drv;
    rt_device_t uhc;    
#ifdef RT_USBH_HID
    uprotocal_t protocal;
#endif

    uhc = rt_device_find(USB_HOST_CONTROLLER_NAME);
    if(uhc == RT_NULL)
    {
        rt_kprintf("can't find usb host controller %s\n", USB_HOST_CONTROLLER_NAME);
        return -RT_ERROR;
    }

    /* initialize usb hub */
    rt_usbh_hub_init();

    /* initialize class driver */
    rt_usbh_class_driver_init();

#ifdef RT_USBH_MSTORAGE
    /* register mass storage class driver */
    drv = rt_usbh_class_driver_storage();
    rt_usbh_class_driver_register(drv);
#endif

#ifdef RT_USBH_HID
    /* register hid class driver */
    drv = rt_usbh_class_driver_hid();
    rt_usbh_class_driver_register(drv);

#ifdef RT_USBH_HID_KEYBOARD    
    /* register hid keyboard protocal */
    protocal = rt_usbh_hid_protocal_kbd();    
    rt_usbh_hid_protocal_register(protocal);
#endif

#ifdef RT_USBH_HID_MOUSE    
    /* register hid mouse protocal */
    protocal = rt_usbh_hid_protocal_mouse();    
    rt_usbh_hid_protocal_register(protocal);
#endif    
#endif

#ifdef RT_USBH_ADK
    /* register adk class driver */
    drv = rt_usbh_class_driver_adk();
    rt_usbh_class_driver_register(drv);
#endif

    /* register hub class driver */
    drv = rt_usbh_class_driver_hub();
    rt_usbh_class_driver_register(drv);

    /* initialize usb host controller */
    rt_device_init(uhc);

    return RT_EOK;
}
Ejemplo n.º 2
0
void rt_init_thread_entry(void *parameter)
{
#ifdef RT_USING_COMPONENTS_INIT
	/* initialization RT-Thread Components */
	rt_components_init();
#endif

	rt_platform_init();

	/* Filesystem Initialization */
#ifdef RT_USING_DFS
	/* mount sd card fat partition 1 as root directory */
	if (dfs_mount("sd0", "/", "elm", 0, 0) == 0)
	{
		rt_kprintf("File System initialized!\n");
	}
	else rt_kprintf("File System initialzation failed!\n");
#endif

#ifdef RT_USING_RTGUI
	gui_init();

	picture_show();

	/* initial touch. */
	{
        rt_device_t device;
	    device = rt_device_find("touch");
	    if (device != RT_NULL)
        {
            rt_device_init(device);
        }
	}
#endif /* RT_USING_RTGUI */
}
Ejemplo n.º 3
0
/**
 * @brief  USBH_USR_MSC_Application
 *         Demo application for mass storage
 * @param  None
 * @retval Staus
 */
int USBH_USR_MSC_Application( void )
{
//	FRESULT res;
	int		ret;

	if( diskinited )
	{
		return 0;
	}

	mscdev.type			= RT_Device_Class_Block;
	mscdev.init			= msc_init;
	mscdev.open			= msc_open;
	mscdev.close		= msc_close;
	mscdev.read			= msc_read;
	mscdev.write		= msc_write;
	mscdev.control		= msc_control;
	mscdev.user_data	= RT_NULL;
	diskinited			= 1;

	rt_device_register( &mscdev, "udisk", RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_REMOVABLE );
	rt_device_init( &mscdev );
	rt_thread_delay( RT_TICK_PER_SECOND / 10 );
	//ret = dfs_mount( "udisk", "/udisk", "elm", 0, 0 );
	if(0 == f_mount(USB, &fs))
		{
		rt_kprintf("\n f_mount USB OK!");
		}
	
	//rt_kprintf( "\ndfs_mount ret=%x  now udisk start", ret );

	return 0;
}
Ejemplo n.º 4
0
/**
 * @brief  USBH_USR_MSC_Application
 *         Demo application for mass storage
 * @param  None
 * @retval Staus
 */
int USBH_USR_MSC_Application( void )
{
    int		ret;

    if( diskinited )
    {
        return 0;
    }

    mscdev.type			= RT_Device_Class_Block;
    mscdev.init			= msc_init;
    mscdev.open			= msc_open;
    mscdev.close		= msc_close;
    mscdev.read			= msc_read;
    mscdev.write		= msc_write;
    mscdev.control		= msc_control;
    mscdev.user_data	= RT_NULL;
    diskinited			= 1;

    rt_device_register( &mscdev, "udisk", RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_REMOVABLE );
    rt_device_init( &mscdev );
    rt_thread_delay( RT_TICK_PER_SECOND / 10 );
    ret = dfs_mount( "udisk", "/udisk", "elm", 0, 0 );

    rt_kprintf( "dfs_mount ret=%x  now udisk start\r\n", ret );
    USB_find_status = USB_FIND;
    Show_Menu_5_2_ExportData();
    return 0;
}
Ejemplo n.º 5
0
/*RS485设备初始化*/
void RS485_init( void )
{
	//rt_sem_init( &sem_RS485, "sem_RS485", 0, 0 );
	rt_mq_init( &mq_RS485, "mq_RS485", &RS485_rawinfo[0], 128 - sizeof( void* ), RS485_RAWINFO_SIZE, RT_IPC_FLAG_FIFO );

	dev_RS485.type		= RT_Device_Class_Char;
	dev_RS485.init		= dev_RS485_init;
	dev_RS485.open		= dev_RS485_open;
	dev_RS485.close		= dev_RS485_close;
	dev_RS485.read		= dev_RS485_read;
	dev_RS485.write		= dev_RS485_write;
	dev_RS485.control	= dev_RS485_control;

	rt_device_register( &dev_RS485, "RS485", RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_STANDALONE );
	rt_device_init( &dev_RS485 );
	Cam_Device_init( );

	rt_thread_init( &thread_RS485,
	                "RS485",
	                rt_thread_entry_RS485,
	                RT_NULL,
	                &thread_RS485_stack[0],
	                sizeof( thread_RS485_stack ), 9, 5 );
	rt_thread_startup( &thread_RS485 );
}
Ejemplo n.º 6
0
/***********************************************************
* Function:
* Description:
* Input:
* Input:
* Output:
* Return:
* Others:
***********************************************************/
void mma8451_driver_init( void )
{
    dev_mma8451.type		= RT_Device_Class_Char;
    dev_mma8451.init		= mma8451_init;
    dev_mma8451.open		= mma8451_open;
    dev_mma8451.close		= mma8451_close;
    dev_mma8451.read		= mma8451_read;
    dev_mma8451.write		= mma8451_write;
    dev_mma8451.control		= mma8451_control;
    dev_mma8451.user_data	= RT_NULL;

    rt_device_register( &dev_mma8451, "sensor", RT_DEVICE_FLAG_RDWR );
    rt_device_init( &dev_mma8451 );
}
Ejemplo n.º 7
0
/* init 485 */
void _485_startup(void)
{

    Device_485.type	= RT_Device_Class_Char;
    Device_485.init	= Device_485_init;
    Device_485.open	=  Device_485_open;
    Device_485.close	=  Device_485_close;
    Device_485.read	=  Device_485_read;
    Device_485.write	=  Device_485_write;
    Device_485.control = Device_485_control;

    rt_device_register( &Device_485, "485", RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_STANDALONE );
    rt_device_init( &Device_485 );

}
Ejemplo n.º 8
0
static err_t eth_netif_device_init(struct netif *netif)
{
    struct eth_device *ethif;

    ethif = (struct eth_device*)netif->state;
    if (ethif != NULL)
    {
        rt_device_t device;

        /* get device object */
        device = (rt_device_t) ethif;
        if (rt_device_init(device) != RT_EOK)
        {
            return ERR_IF;
        }

        /* copy device flags to netif flags */
        netif->flags = ethif->flags;

        /* set default netif */
        if (netif_default == NULL)
            netif_set_default(ethif->netif);

#if LWIP_DHCP
        if (ethif->flags & NETIF_FLAG_DHCP)
        {
            /* if this interface uses DHCP, start the DHCP client */
            dhcp_start(ethif->netif);
        }
        else
#endif
        {
            /* set interface up */
            netif_set_up(ethif->netif);
        }

#ifdef LWIP_NETIF_LINK_CALLBACK
        netif_set_link_up(ethif->netif);
#endif

        return ERR_OK;
    }

    return ERR_IF;
}
Ejemplo n.º 9
0
/* init gsm */
void _gsm_startup(void)
{
    rt_err_t result;


    //    二. RT  相关初始化
    //-------------   sem  init  ---------------------------------
    //  创建DF 读写信号量
    rt_sem_init( &sem_DF, "sem_DF", 0, 0 );
    rt_sem_release( &sem_DF);


    rt_mq_init( &mq_GSM, "mq_GSM", &GSM_rawinfo[0], 1400 - sizeof( void * ), GSM_RAWINFO_SIZE, RT_IPC_FLAG_FIFO );

    //---------  timer_gsm ----------
    // 1. create  timer     100ms=Dur
    timer_gsm = rt_timer_create("tim_gsm", timeout_gsm, RT_NULL, 100, RT_TIMER_FLAG_PERIODIC); //| RT_TIMER_FLAG_SOFT_TIMER);
    //  2. start timer
    if(timer_gsm != RT_NULL)
        rt_timer_start(timer_gsm);


    result = rt_thread_init(&gsm_thread,
                            "GsmThrd",
                            gsm_thread_entry, RT_NULL,
                            &gsm_thread_stack[0], sizeof(gsm_thread_stack),
                            Prio_GSM, 10);

    if (result == RT_EOK)
    {
        rt_thread_startup(&gsm_thread);
    }

    Device_GSM.type	= RT_Device_Class_Char;
    Device_GSM.init	= Device_GSM_init;
    Device_GSM.open	=  Device_GSM_open;
    Device_GSM.close	=  Device_GSM_close;
    Device_GSM.read	=  Device_GSM_read;
    Device_GSM.write	=  Device_GSM_write;
    Device_GSM.control = Device_GSM_control;

    rt_device_register( &Device_GSM, "GsmDev", RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_STANDALONE );
    rt_device_init( &Device_GSM );

}
Ejemplo n.º 10
0
void rt_hw_usart_init()
{
/*初始化接收缓冲区*/
	rt_ringbuffer_init(&rb_vuart,vuart_rxbuf,VUART_RXBUF_SIZE);
	
	dev_vuart.type	= RT_Device_Class_Char;
	dev_vuart.init	= dev_vuart_init;
	dev_vuart.open	= dev_vuart_open;
	dev_vuart.close	= dev_vuart_close;
	dev_vuart.read	= dev_vuart_read;
	dev_vuart.write	= dev_vuart_write;
	dev_vuart.control = dev_vuart_control;
	dev_vuart.rx_indicate = RT_NULL;
	dev_vuart.tx_complete = RT_NULL;

	rt_device_register( &dev_vuart, "vuart", RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_STREAM );
	rt_device_init( &dev_vuart );
}
Ejemplo n.º 11
0
static err_t eth_netif_device_init(struct netif *netif)
{
    struct eth_device *ethif;

    ethif = (struct eth_device*)netif->state;
    if (ethif != RT_NULL)
    {
        rt_device_t device;

        /* get device object */
        device = (rt_device_t) ethif;
        if (rt_device_init(device) != RT_EOK)
        {
            return ERR_IF;
        }

        /* copy device flags to netif flags */
        netif->flags = (ethif->flags & 0xff);

        /* set default netif */
        if (netif_default == RT_NULL)
            netif_set_default(ethif->netif);

#if LWIP_DHCP
        /* set interface up */
        netif_set_up(ethif->netif);
        /* if this interface uses DHCP, start the DHCP client */
        dhcp_start(ethif->netif);
#else
        /* set interface up */
        netif_set_up(ethif->netif);
#endif

        if (!(ethif->flags & ETHIF_LINK_PHYUP))
        {
            /* set link_up for this netif */
            netif_set_link_up(ethif->netif);
        }

        return ERR_OK;
    }

    return ERR_IF;
}
Ejemplo n.º 12
0
static err_t netif_device_init(struct netif *netif)
{
	struct eth_device *ethif;

	ethif = (struct eth_device*)netif->state;
	if (ethif != NULL)
	{
		rt_device_t device;

		/* get device object */
		device = (rt_device_t) ethif;
		if (rt_device_init(device) != RT_EOK)
		{
			return ERR_IF;
		}
		return ERR_OK;
	}

	return ERR_IF;
}
Ejemplo n.º 13
0
int device_test(const char * device_name)
{
    rt_device_t device = RT_NULL;

    // step 1:find device
    device = rt_device_find(device_name);
    if( device == RT_NULL)
    {
        rt_kprintf("device %s: not found!\r\n");
        return RT_ERROR;
    }

    // step 2:init device
    if (!(device->flag & RT_DEVICE_FLAG_ACTIVATED))
    {
        rt_err_t result;
        result = rt_device_init(device);
        if (result != RT_EOK)
        {
            rt_kprintf("To initialize device:%s failed. The error code is %d\r\n",
                       device->parent.name, result);
            return result;
        }
        else
        {
            device->flag |= RT_DEVICE_FLAG_ACTIVATED;
        }
    }

    // step 3: device test
    switch( device->type )
    {
    case RT_Device_Class_Block :
        rt_kprintf("block device!\r\n");
        return _block_device_test(device);
    default:
        rt_kprintf("unkown device type : %02X",device->type);
        return RT_ERROR;
    }
}
Ejemplo n.º 14
0
void gui_init()
{
	extern void rtgui_touch_hw_init(void);
	extern rt_err_t load_setup(void);
    rtgui_rect_t rect;
	rt_device_t lcd;

	/* 初始化LCD驱动 */
    ra8875_init();
	lcd = rt_device_find("lcd");
	if (lcd != RT_NULL)
	{
		rt_device_init(lcd);
		rtgui_graphic_set_device(lcd);

		/* 初始化RT-Thread/GUI server */
	    rtgui_system_server_init();

    /* 注册面板 */
    rect.x1 = 0;
    rect.y1 = 0;
    rect.x2 = 800;
    rect.y2 = 480;
    rtgui_panel_register("main", &rect);
    rtgui_panel_set_default_focused("main");

		/* 初始化键盘驱动 */
//		rt_hw_key_init();

		/* 初始化触摸屏驱动 */
//		load_setup(); //touch装载默认值
//		rtgui_touch_hw_init();
	    rt_device_init_all();

		/* 初始化workbench */
		workbench_init();
	}
}
Ejemplo n.º 15
0
/*gps设备初始化*/
void gps_init( void )
{
	//rt_sem_init( &sem_gps, "sem_gps", 0, 0 );
	//rt_mq_init( &mq_gps, "mq_gps", &gps_rawinfo[0], 128 - sizeof( void* ), GPS_RAWINFO_SIZE, RT_IPC_FLAG_FIFO );
	rt_thread_init( &thread_gps,
	                "gps",
	                rt_thread_entry_gps,
	                RT_NULL,
	                &thread_gps_stack[0],
	                sizeof( thread_gps_stack ), Prio_GPS, 6 ); 
	rt_thread_startup( &thread_gps );

	dev_gps.type	= RT_Device_Class_Char;
	dev_gps.init	= dev_gps_init;
	dev_gps.open	= dev_gps_open;
	dev_gps.close	= dev_gps_close;
	dev_gps.read	= dev_gps_read;
	dev_gps.write	= dev_gps_write;
	dev_gps.control = dev_gps_control; 

	rt_device_register( &dev_gps, "gps", RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_STANDALONE );
	rt_device_init( &dev_gps );
}
Ejemplo n.º 16
0
void usb_thread_entry(void* parameter)
{
    int i;
    rt_thread_t tid;
    msd_msg_t msg;
    
    dev = rt_device_find(MOUNT_DEVICE);
    
    if(!dev)
    {
        rt_kprintf("no %s device found!\r\n", MOUNT_DEVICE);
        tid = rt_thread_self();
        rt_thread_delete(tid); 
    }
    
    rt_device_init(dev);
    rt_device_open(dev, RT_DEVICE_OFLAG_RDWR);
    
    usbd_init();                          /* USB Device Initialization          */
    usbd_connect(__TRUE);                 /* USB Device Connect                 */
    while (!usbd_configured ())
    {
        rt_thread_delay(10);
    }
    
    rt_kprintf("usb enum complete\r\n");
    
    while(1)
    {
        if(rt_mq_recv(msd_mq, &msg, sizeof(msd_msg_t), RT_WAITING_FOREVER) == RT_EOK)
        {
            if(msg.dir == 0) USBD_MSC_EP_BULKOUT_Event(0);
                else USBD_MSC_EP_BULKIN_Event (0);
        }
    }
}
Ejemplo n.º 17
0
rt_err_t rt_usb_device_init(const char* udc_name)
{
    rt_device_t udc;
    udevice_t udevice;
    uconfig_t cfg;
    uclass_t cls;    

    RT_ASSERT(udc_name != RT_NULL);

    udc = rt_device_find(udc_name);
    if(udc == RT_NULL)
    {
        rt_kprintf("can't find usb device controller %s\n", udc_name);
        return -RT_ERROR;
    }

    /* create and startup usb device thread */
    rt_usbd_core_init();

    /* create a device object */
    udevice = rt_usbd_device_create(ustring);
    
    /* set usb controller driver to the device */
    rt_usbd_device_set_controller(udevice, (udcd_t)udc);

    /* create a configuration object */
    cfg = rt_usbd_config_create();

#ifdef RT_USB_DEVICE_MSTORAGE
    /* create a mass storage class object */
    cls = rt_usbd_class_mstorage_create(udevice);    

    /* add the class to the configuration */
    rt_usbd_config_add_class(cfg, cls);
#endif
#ifdef RT_USB_DEVICE_CDC
    /* create a cdc class object */
    cls = rt_usbd_class_cdc_create(udevice);

    /* add the class to the configuration */
    rt_usbd_config_add_class(cfg, cls);
#endif

    /* set device descriptor to the device */
#ifdef RT_USB_DEVICE_COMPOSITE
    rt_usbd_device_set_descriptor(udevice, &compsit_desc);
#else
    rt_usbd_device_set_descriptor(udevice, cls->dev_desc);
#endif

    /* add the configuration to the device */
    rt_usbd_device_add_config(udevice, cfg);
    
    /* set default configuration to 1 */
    rt_usbd_set_config(udevice, 1);

    /* initialize usb device controller */
    rt_device_init(udc);

    return RT_EOK;
}
Ejemplo n.º 18
0
static void keypress(unsigned int key)
{

	switch(key)
		{
		case KEY_MENU:
			pMenuItem=&Menu_5_other;
			pMenuItem->show();

			concuss_screen=0;
			break;
			
		case KEY_OK:
			if(concuss_screen==0)
				{
				concuss_screen=1;
				
				if( jt808_param.id_0x005D != concuss_step )
					{
					jt808_param.id_0x005D = concuss_step;
					param_save(1);
					rt_device_init( &dev_mma8451 );
					}
					#if NEED_TODO
				JT808Conf_struct.concuss_step=concuss_step;
				Api_Config_Recwrite_Large(jt808,0,(u8*)&JT808Conf_struct,sizeof(JT808Conf_struct));
			#endif

                concuss_dis[9]=concuss_step/10+'0';
				concuss_dis[10]=concuss_step%10+'0';
				lcd_fill(0);
				lcd_text12(20,3,"震动级别设置成功",16,LCD_MODE_SET);
				lcd_text12(30,19,(char *)concuss_dis,sizeof(concuss_dis),LCD_MODE_SET);
				lcd_update_all();
				}
			break;
			
		case KEY_UP:
			if(concuss_screen==0)
			{
				 if(concuss_step==0)
					concuss_step=79;
				else if(concuss_step>=1)
					concuss_step--;
				
				concuss_dis[9]=concuss_step/10+'0';
				concuss_dis[10]=concuss_step%10+'0';
				lcd_fill(0);
				lcd_text12(30,10,(char *)concuss_dis,sizeof(concuss_dis),LCD_MODE_SET);
				lcd_update_all();
			}
						
			break;
			
		case KEY_DOWN:
			if(concuss_screen==0)
			{
				concuss_step++;
				if(concuss_step>79)
					concuss_step=0;
				
				concuss_dis[9]=concuss_step/10+'0';
				concuss_dis[10]=concuss_step%10+'0';
				lcd_fill(0);
				lcd_text12(30,10,(char *)concuss_dis,sizeof(concuss_dis),LCD_MODE_SET);
				lcd_update_all();
			}
			break;	
		}
}