Exemple #1
0
void close_drivers(void)
{
        /* FTDI:SDB Driver Close */
        vos_dev_close(hUSBSLAVE_1);
        vos_dev_close(hUSBSLAVE_2);
        vos_dev_close(hUART);
        /* FTDI:EDB */
}
void close_drivers(void)
{
        /* FTDI:SDB Driver Close */
        vos_dev_close(hUSBHOST_2);
        vos_dev_close(hUART);
        vos_dev_close(hGPIO_PORT_A);
        /* FTDI:EDB */
}
Exemple #3
0
VOS_HANDLE fat_attach(VOS_HANDLE hMSI, unsigned char devFAT)
{
	fat_ioctl_cb_t           fat_ioctl;
	fatdrv_ioctl_cb_attach_t fat_att;
	VOS_HANDLE hFAT;

	// currently the MSI (BOMS or other) must be open
        // open the FAT driver
	hFAT = vos_dev_open(devFAT);

        // attach the FAT driver to the MSI driver
	fat_ioctl.ioctl_code = FAT_IOCTL_FS_ATTACH;
	fat_ioctl.set = &fat_att;
	fat_att.msi_handle = hMSI;
	fat_att.partition = 0;

	if (vos_dev_ioctl(hFAT, &fat_ioctl) != FAT_OK)
	{
                // unable to open the FAT driver
		vos_dev_close(hFAT);
		hFAT = NULL;
	}

	return hFAT;
}
Exemple #4
0
void HID_detach(VOS_HANDLE hHID)
{
	usbHostHID_ioctl_t hid_iocb;

	if (hHID)
	{
		hid_iocb.ioctl_code = VOS_IOCTL_USBHOSTHID_DETACH;

		vos_dev_ioctl(hHID, &hid_iocb);
		vos_dev_close(hHID);
	}
}
Exemple #5
0
VOS_HANDLE boms_attach(VOS_HANDLE hUSB, unsigned char devBOMS)
{
	usbhost_device_handle_ex ifDisk = 0;
	usbhost_ioctl_cb_t hc_iocb;
	usbhost_ioctl_cb_class_t hc_iocb_class;
	msi_ioctl_cb_t boms_iocb;
	boms_ioctl_cb_attach_t boms_att;
	int error;
	VOS_HANDLE hBOMS;
	
	

	// find BOMS class device
	hc_iocb_class.dev_class = USB_CLASS_MASS_STORAGE;
	hc_iocb_class.dev_subclass = USB_SUBCLASS_MASS_STORAGE_SCSI;
	hc_iocb_class.dev_protocol = USB_PROTOCOL_MASS_STORAGE_BOMS;

	// user ioctl to find first hub device
	hc_iocb.ioctl_code = VOS_IOCTL_USBHOST_DEVICE_FIND_HANDLE_BY_CLASS;
	hc_iocb.handle.dif = NULL;
	hc_iocb.set = &hc_iocb_class;
	hc_iocb.get = &ifDisk;

	error = vos_dev_ioctl(hUSB, &hc_iocb);
	if (error != USBHOST_OK)
	{
		printf("ERROR: %d\n", error);
		printf("USB Bus 1 State: %d\n", getBusState(hUSBHOST_1));
		printf("USB Bus 2 State: %d\n", getBusState(hUSBHOST_2));
		return NULL;
	}

	// now we have a device, intialise a BOMS driver with it
	hBOMS = vos_dev_open(devBOMS);

	// perform attach
	boms_att.hc_handle = hUSB;
	boms_att.ifDev = ifDisk;

	boms_iocb.ioctl_code = MSI_IOCTL_BOMS_ATTACH;
	boms_iocb.set = &boms_att;
	boms_iocb.get = NULL;

	if (vos_dev_ioctl(hBOMS, &boms_iocb) != MSI_OK)
	{
		vos_dev_close(hBOMS);
		hBOMS = NULL;
	}

	return hBOMS;
}
Exemple #6
0
void boms_detach(VOS_HANDLE hBOMS)
{
	msi_ioctl_cb_t boms_iocb;

	if (hBOMS)
	{
		boms_iocb.ioctl_code = MSI_IOCTL_BOMS_DETACH;
		boms_iocb.set = NULL;
		boms_iocb.get = NULL;

		vos_dev_ioctl(hBOMS, &boms_iocb);
		vos_dev_close(hBOMS);
	}
}
Exemple #7
0
void fat_detach(VOS_HANDLE hFAT)
{
	fat_ioctl_cb_t           fat_ioctl;

	if (hFAT)
	{
		fat_ioctl.ioctl_code = FAT_IOCTL_FS_DETACH;
		fat_ioctl.set = NULL;
		fat_ioctl.get = NULL;

		vos_dev_ioctl(hFAT, &fat_ioctl);
		vos_dev_close(hFAT);
	}
}
Exemple #8
0
VOS_HANDLE hid_attach(VOS_HANDLE hUSB, unsigned char devHID)
{
	usbhost_device_handle_ex ifHID = 0;
	usbhost_ioctl_cb_t hc_iocb;
	usbhost_ioctl_cb_class_t hc_iocb_class;
	usbHostHID_ioctl_t hid_iocb;
	usbHostHID_ioctl_cb_attach_t hid_att;
	VOS_HANDLE hHID;

	// find HID class device
	hc_iocb_class.dev_class = USB_CLASS_HID;
	hc_iocb_class.dev_subclass = USB_SUBCLASS_ANY;
	hc_iocb_class.dev_protocol = USB_PROTOCOL_ANY;

	// user ioctl to find first hub device
	hc_iocb.ioctl_code = VOS_IOCTL_USBHOST_DEVICE_FIND_HANDLE_BY_CLASS;
	hc_iocb.handle.dif = NULL;
	hc_iocb.set = &hc_iocb_class;
	hc_iocb.get = &ifHID;

	if (vos_dev_ioctl(hUSB, &hc_iocb) != USBHOST_OK)
	{
		return NULL;
	}

	// now we have a device, intialise a HID driver with it
	hHID = vos_dev_open(devHID);

	// perform attach
	hid_att.hc_handle = hUSB;
	hid_att.ifDev = ifHID;

	hid_iocb.ioctl_code = VOS_IOCTL_USBHOSTHID_ATTACH;
	hid_iocb.set = &hid_att;
	hid_iocb.get = NULL;

	if (vos_dev_ioctl(hHID, &hid_iocb) != USBHOSTHID_OK)
	{
		vos_dev_close(hHID);
		hHID = NULL;
	}

	return hHID;
}
Exemple #9
0
//////////////////////////////////////////////////////////////////////
//
// RUN USB HOST PORT
//
//////////////////////////////////////////////////////////////////////
void RunHostPort(HOST_PORT_DATA *pHostData)
{
	int i;
	int midiParam;
	unsigned char status;
	unsigned char buf[64];	
	unsigned short num_bytes;
	unsigned int handle;
	usbhostGeneric_ioctl_t generic_iocb;
	usbhostGeneric_ioctl_cb_attach_t genericAtt;
	usbhost_device_handle_ex ifDev;
	usbhost_ioctl_cb_t hc_iocb;
	usbhost_ioctl_cb_vid_pid_t hc_iocb_vid_pid;
	gpio_ioctl_cb_t gpio_iocb;
	VOS_HANDLE hUSB;

	// wait for setup to complete
	vos_wait_semaphore(&setupSem);
	vos_signal_semaphore(&setupSem);
	
	// Open the base USB Host driver
	pHostData->hUSBHOST = vos_dev_open(pHostData->uchDeviceNumberBase);
	
	// loop forever
	while(1)
	{
		vos_delay_msecs(10);
		// is the device enumerated on this port?
		if (usbhost_connect_state(pHostData->hUSBHOST) == PORT_STATE_ENUMERATED)
		{
			// user ioctl to find first hub device
			hc_iocb.ioctl_code = VOS_IOCTL_USBHOST_DEVICE_GET_NEXT_HANDLE;
			hc_iocb.handle.dif = NULL;
			hc_iocb.set = NULL;
			hc_iocb.get = &ifDev;
			if (vos_dev_ioctl(pHostData->hUSBHOST, &hc_iocb) == USBHOST_OK)
			{
				// query the device VID/PID
				hc_iocb.ioctl_code = VOS_IOCTL_USBHOST_DEVICE_GET_VID_PID;
				hc_iocb.handle.dif = ifDev;
				hc_iocb.get = &hc_iocb_vid_pid;
				
				// Load the function driver
				hUSB = vos_dev_open(pHostData->uchDeviceNumber);
				
				// Attach the function driver to the base driver
				genericAtt.hc_handle = pHostData->hUSBHOST;
				genericAtt.ifDev = ifDev;
				generic_iocb.ioctl_code = VOS_IOCTL_USBHOSTGENERIC_ATTACH;
				generic_iocb.set.att = &genericAtt;
				if (vos_dev_ioctl(hUSB, &generic_iocb) == USBHOSTGENERIC_OK)
				{					
					// Turn on the LED for this port
					setGpioA(pHostData->uchActivityLed, pHostData->uchActivityLed);

					// flag that the port is attached
					VOS_ENTER_CRITICAL_SECTION;
					pHostData->hUSBHOSTGENERIC = hUSB;
					VOS_EXIT_CRITICAL_SECTION;
										
					// now we loop until the launchpad is detached
					while(1)
					{
						// listen for data from launchpad
						uint16 result = vos_dev_read(hUSB, buf, 64, &num_bytes);
						if(0 != result)
							break; // break when the launchpad is detached						
						fifo_write(&stSPIWriteFIFO, buf, (int)num_bytes); 
					}					
					
					// flag that the port is no longer attached
					VOS_ENTER_CRITICAL_SECTION;
					pHostData->hUSBHOSTGENERIC = NULL;
					VOS_EXIT_CRITICAL_SECTION;
					
					// turn off the activity LED
					setGpioA(pHostData->uchActivityLed, 0);
				}
				
				// close the function driver
				vos_dev_close(hUSB);
			}
		}
	}
}	
//////////////////////////////////////////////////////////////////////
//
// THREAD FUNCTION TO RUN USB HOST PORT
//
//////////////////////////////////////////////////////////////////////
void RunHostPort(HOST_PORT_DATA *pHostData)
{
	unsigned char status;
	unsigned char buf[64];
	unsigned short num_read;
	unsigned int handle;
	usbhostGeneric_ioctl_t generic_iocb;
	usbhostGeneric_ioctl_cb_attach_t genericAtt;
	usbhost_device_handle_ex ifDev;
	usbhost_ioctl_cb_t hc_iocb;
	usbhost_ioctl_cb_vid_pid_t hc_iocb_vid_pid;
	gpio_ioctl_cb_t gpio_iocb;

	SMQ_MSG msg;
	msg.status = 0x90;

	// wait for setup to complete
	vos_wait_semaphore(&setupSem);
	vos_signal_semaphore(&setupSem);

	// loop forever
	while(1)
	{
		// is the device enumerated on this port?
		if (usbhost_connect_state(pHostData->hUSBHOST) == PORT_STATE_ENUMERATED)
		{
			// user ioctl to find first hub device
			hc_iocb.ioctl_code = VOS_IOCTL_USBHOST_DEVICE_GET_NEXT_HANDLE;
			hc_iocb.handle.dif = NULL;
			hc_iocb.set = NULL;
			hc_iocb.get = &ifDev;
			if (vos_dev_ioctl(pHostData->hUSBHOST, &hc_iocb) == USBHOST_OK)
			{

				hc_iocb.ioctl_code = VOS_IOCTL_USBHOST_DEVICE_GET_VID_PID;
				hc_iocb.handle.dif = ifDev;
				hc_iocb.get = &hc_iocb_vid_pid;
				
				// attach the Launchpad device to the USB host device
				pHostData->hUSBHOSTGENERIC = vos_dev_open(pHostData->uchDeviceNumber);
				genericAtt.hc_handle = pHostData->hUSBHOST;
				genericAtt.ifDev = ifDev;
				generic_iocb.ioctl_code = VOS_IOCTL_USBHOSTGENERIC_ATTACH;
				generic_iocb.set.att = &genericAtt;
				if (vos_dev_ioctl(pHostData->hUSBHOSTGENERIC, &generic_iocb) == USBHOSTGENERIC_OK)
				{
					setLed(pHostData->uchActivityLed, 1);
					
					// now we loop until the launchpad is detached
					while(1)
					{
						int pos = 0;
						byte param = 1;
						
						// read data
						status = vos_dev_read(pHostData->hUSBHOSTGENERIC, buf, 64, &num_read);
						if(status != USBHOSTGENERIC_OK)
							break;
							
						setLed(pHostData->uchActivityLed, 0);

						// interpret MIDI data and pass to application thread
						
						while(pos < num_read)
						{
							if(buf[pos] & 0x80)
							{
								msg.status = buf[pos];
								param = 1;
							}
							else if(param == 1)
							{
								msg.param1 = buf[pos];
								param = 2;
							}
							else if(param == 2)
							{
								msg.param2 = buf[pos];
								SMQWrite(&msg);										
								param = 1;
							}
							++pos;
						}
						
						setLed(pHostData->uchActivityLed, 1);
					}					
				}
				vos_dev_close(pHostData->hUSBHOSTGENERIC);
			}
		}
		setLed(pHostData->uchActivityLed, 0);
	}
}	
void firmware()
{
	/* Thread code to be added here */

	// communications ioctl request blocks
	common_ioctl_cb_t uart_iocb;

	usbHostHID_ioctl_t	hid_iocb;
	usbhost_device_handle ifDev; 				// device handle
	usbhost_ioctl_cb_t hc_iocb;					// Host Controller ioctl request block
	unsigned char byteCount,status;
	unsigned short num_read;

	do
	{
		open_drivers();
		
		// UART set baud rate
		uart_iocb.ioctl_code = VOS_IOCTL_UART_SET_BAUD_RATE;
		uart_iocb.set.uart_baud_rate = DEF_UART_BAUD;
		vos_dev_ioctl(hUART, &uart_iocb);
		
		do
		{
			vos_delay_msecs(1000);
			// wait for enumeration to complete
//			message("Waiting for enumeration\r\n");
			status = usbhost_connect_state(hUSBHOST_2);
			
		} while (status != PORT_STATE_ENUMERATED);

		if (status == PORT_STATE_ENUMERATED)
		{
//			message("Enumeration complete\r\n");
			vos_gpio_set_port_mode(GPIO_PORT_A, 0b00000100); // A2 на выход
			vos_gpio_write_port(GPIO_PORT_A, 0b00000100); // зажечь светодиод
			
			attach_drivers();
			if (hUSBHOST_HID == NULL)
			{
//				message("No Wingman Found - code ");
//				number(status);
//				message(eol);
				break;
			}


			// get report descriptor
			hid_iocb.descriptorType = USB_DESCRIPTOR_TYPE_REPORT;
			hid_iocb.descriptorIndex = USB_HID_DESCRIPTOR_INDEX_ZERO;
			hid_iocb.Length = 0x40;
			hid_iocb.get.data=&buf[0];
			hid_iocb.ioctl_code = VOS_IOCTL_USBHOSTHID_GET_DESCRIPTOR;
			status = vos_dev_ioctl(hUSBHOST_HID, &hid_iocb);
			if (status != USBHOSTHID_OK)
			{
//				message("Get report descriptor failed - code ");
//				number(status);
//				message(eol);
				break;
			}

			// set idle
			hid_iocb.reportID = USB_HID_REPORT_ID_ZERO;
			hid_iocb.idleDuration = 0x20;
			hid_iocb.ioctl_code = VOS_IOCTL_USBHOSTHID_SET_IDLE;
			status = vos_dev_ioctl(hUSBHOST_HID, &hid_iocb);
			if (status != USBHOSTHID_OK)
			{
//				message("Set Idle failed - code ");
//				number(status);
//				message(eol);
				break;
			}


			// get idle
			hid_iocb.reportID = USB_HID_REPORT_ID_ZERO;
			hid_iocb.get.data=&buf[0];
			hid_iocb.ioctl_code = VOS_IOCTL_USBHOSTHID_GET_IDLE;
			status = vos_dev_ioctl(hUSBHOST_HID, &hid_iocb);
			if (status != USBHOSTHID_OK)
			{
//				message("Get Idle failed - code ");
//				number(status);
//				message(eol);
				break;
			}

			if (status == USBHOSTHID_OK)
			{
					while (1)
					{
						if (vos_dev_read(hUSBHOST_HID, buf, 8, &num_read) == USBHOSTHID_OK)
						{

							for (byteCount = 0; byteCount < num_read; byteCount++)
							{
								number(buf[byteCount]);
							}
//							message(eol);
						}
						else
						{
//							message("USB Read Failed - code ");
//							number(status);
//							message(eol);
							break;
						}
					}


			}

//		message("Disconnected!\r\n");
		vos_gpio_write_port(GPIO_PORT_A, 0b00000000); // погасить все

		} // end of if PORT_STATE_ENUMERATED


		vos_dev_close(hUSBHOST_HID);
		close_drivers();
	} while (1);


}