usb_video.c 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268
  1. /******************************************************************************
  2. *
  3. * Freescale Semiconductor Inc.
  4. * (c) Copyright 2004-2010 Freescale Semiconductor, Inc.
  5. * ALL RIGHTS RESERVED.
  6. *
  7. ******************************************************************************
  8. *
  9. * THIS SOFTWARE IS PROVIDED BY FREESCALE "AS IS" AND ANY EXPRESSED OR
  10. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  11. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  12. * IN NO EVENT SHALL FREESCALE OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  13. * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  14. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  15. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  16. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  17. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  18. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  19. * THE POSSIBILITY OF SUCH DAMAGE.
  20. *
  21. **************************************************************************//*!
  22. *
  23. * @file usb_video.c
  24. *
  25. * @author
  26. *
  27. * @version
  28. *
  29. * @date
  30. *
  31. * @brief The file contains USB stack Video layer implementation.
  32. *
  33. *****************************************************************************/
  34. /******************************************************************************
  35. * Includes
  36. *****************************************************************************/
  37. #include "usb_video.h" /* USB Video Class Header File */
  38. #include "usb_devapi.h" /* USB device Header File */
  39. #include "usb_framework.h" /* USB device Header File */
  40. /*****************************************************************************
  41. * Constant and Macro's
  42. *****************************************************************************/
  43. /****************************************************************************
  44. * Global Variables
  45. ****************************************************************************/
  46. /* Video endpoint info array */
  47. static USB_CLASS_VIDEO_ENDPOINT_DATA g_video_endpoint_data;
  48. /* Video Class Callback Function Pointer */
  49. static USB_CLASS_CALLBACK g_video_class_callback=NULL;
  50. /* Video Class Vendor Callback Function Pointer */
  51. static USB_REQ_FUNC g_vendor_req_callback=NULL;
  52. /* Video Class requests Callback Function Pointer */
  53. static USB_CLASS_CALLBACK g_param_callback = NULL;
  54. /*****************************************************************************
  55. * Local Types - None
  56. *****************************************************************************/
  57. /*****************************************************************************
  58. * Local Functions Prototypes
  59. *****************************************************************************/
  60. #ifndef COMPOSITE_DEV
  61. static uint_8 USB_Other_Requests(uint_8 controller_ID,
  62. USB_SETUP_STRUCT * setup_packet,
  63. uint_8_ptr *data,
  64. USB_PACKET_SIZE *size);
  65. #endif
  66. /*****************************************************************************
  67. * Local Variables - None
  68. *****************************************************************************/
  69. /*****************************************************************************
  70. * Local Functions
  71. *****************************************************************************/
  72. /**************************************************************************//*!
  73. *
  74. * @name USB_Service_Video_Isochronous
  75. *
  76. * @brief The funtion ic callback function of Video Isochronous IN endpoint
  77. *
  78. * @param event
  79. *
  80. * @return None
  81. *
  82. ****************************************************************************
  83. * The function is called in response to Isochronous IN Service
  84. ******************************************************************************/
  85. void USB_Service_Video_Isochronous(PTR_USB_DEV_EVENT_STRUCT event)
  86. {
  87. #if IMPLEMENT_QUEUING
  88. uint_8 index;
  89. uint_8 producer, consumer;
  90. /*Body*/
  91. USB_ENDPOINTS *usb_ep_data = (USB_ENDPOINTS *)
  92. USB_Desc_Get_Endpoints(event->controller_ID);
  93. /* map the endpoint num to the index of the endpoint structure */
  94. for(index = 0; index < usb_ep_data->count; index++)
  95. {
  96. if(usb_ep_data->ep[index].ep_num ==event->ep_num)
  97. break;
  98. }/*EndFor*/
  99. producer = g_video_endpoint_data.ep[index].bin_producer;
  100. /* if there are no errors de-queue the queue and decrement the no. of
  101. transfers left, else send the same data again */
  102. if(event->errors == 0)
  103. {
  104. /* de-queue if the send is complete without an error */
  105. if ((MAX_QUEUE_ELEMS-1) == g_video_endpoint_data.ep[index].bin_consumer)
  106. {
  107. g_video_endpoint_data.ep[index].bin_consumer = 0;
  108. } else {
  109. g_video_endpoint_data.ep[index].bin_consumer++;
  110. }/*EndIf*/
  111. g_video_endpoint_data.ep[index].queue_num--;
  112. }/*EndIf*/
  113. consumer = g_video_endpoint_data.ep[index].bin_consumer;
  114. if(0 != g_video_endpoint_data.ep[index].queue_num)
  115. {
  116. /*if bin is not empty */
  117. USB_CLASS_VIDEO_QUEUE queue;
  118. /* send the next packet in queue */
  119. queue = g_video_endpoint_data.ep[index].queue[consumer];
  120. (void)USB_Class_Send_Data(queue.controller_ID, queue.channel,
  121. queue.app_buff, queue.size);
  122. }/*EndIf*/
  123. #endif
  124. if(g_video_class_callback != NULL)
  125. {
  126. uint_8 event_type = USB_APP_SEND_COMPLETE;
  127. if(event->errors != 0)
  128. {
  129. event_type = USB_APP_ERROR;
  130. }/*EndIf*/
  131. g_video_class_callback(event->controller_ID, event_type,
  132. (uint_8*)(&(event->errors)));
  133. }/*EndIf*/
  134. }/*EndBody*/
  135. /**************************************************************************//*!
  136. *
  137. * @name USB_Class_Video_Event
  138. *
  139. * @brief The funtion initializes Video endpoint
  140. *
  141. * @param controller_ID : Controller ID
  142. * @param event : Event Type
  143. * @param val : Pointer to configuration Value
  144. *
  145. * @return None
  146. *
  147. ******************************************************************************
  148. * The funtion initializes the Video endpoints when event of comleted enumeration is
  149. * received
  150. *****************************************************************************/
  151. void USB_Class_Video_Event (
  152. uint_8 controller_ID, /* [IN] Controller ID */
  153. uint_8 event, /* [IN] Event Type */
  154. void* val /* [IN] Pointer to configuration Value */
  155. )
  156. {
  157. uint_8 index;
  158. if(event == USB_APP_ENUM_COMPLETE)
  159. {
  160. uint_8 index_num = 0;
  161. uint_8 count = 0,ep_count = 0;
  162. USB_ENDPOINTS *ep_desc_data;
  163. #ifdef COMPOSITE_DEV
  164. DEV_ARCHITECTURE_STRUCT_PTR dev_arc_ptr;
  165. CLASS_ARC_STRUCT_PTR dev_class_ptr;
  166. dev_arc_ptr = (DEV_ARCHITECTURE_STRUCT *)USB_Desc_Get_Class_Architecture(controller_ID);
  167. for(count = 0; count < dev_arc_ptr->cl_count; count++)
  168. {
  169. dev_class_ptr = (CLASS_ARC_STRUCT_PTR)dev_arc_ptr->value[count];
  170. /* Initializes sub_classes */
  171. ep_count = dev_class_ptr->value[0];
  172. if(dev_class_ptr->class_type == 0x0e/*VIDEO_CC*/)
  173. break;
  174. index_num +=dev_class_ptr->value[0];
  175. }
  176. /* get the endpoints from the descriptor module */
  177. ep_desc_data = (USB_ENDPOINTS *)USB_Desc_Get_Endpoints(controller_ID);
  178. #else
  179. /* get the endpoints from the descriptor module */
  180. ep_desc_data = (USB_ENDPOINTS *)USB_Desc_Get_Endpoints(controller_ID);
  181. ep_count = ep_desc_data->count;
  182. #endif
  183. /* deinitialize all endpoints in case they were initialized */
  184. for(count=index_num; count<ep_count+index_num; count++)
  185. {
  186. USB_EP_STRUCT_PTR ep_struct_ptr=
  187. (USB_EP_STRUCT_PTR) (&ep_desc_data->ep[count]);
  188. (void)_usb_device_deinit_endpoint(&controller_ID,
  189. ep_struct_ptr->ep_num, ep_struct_ptr->direction);
  190. }
  191. /* intialize all non control endpoints */
  192. for(count=index_num; count<ep_count+index_num; count++)
  193. {
  194. USB_EP_STRUCT_PTR ep_struct=
  195. (USB_EP_STRUCT_PTR)&ep_desc_data->ep[count];
  196. (void)_usb_device_init_endpoint(&controller_ID, ep_struct->ep_num,
  197. ep_struct->size, ep_struct->direction, ep_struct->type,
  198. TRUE);
  199. /* register callback service for the endpoint */
  200. switch(ep_struct->type)
  201. {
  202. case USB_INTERRUPT_PIPE:
  203. break;
  204. case USB_ISOCHRONOUS_PIPE:
  205. if(ep_struct->direction == USB_SEND)
  206. {
  207. (void)_usb_device_register_service(controller_ID,
  208. (uint_8)(USB_SERVICE_EP0+ep_struct->ep_num),
  209. USB_Service_Video_Isochronous);
  210. }
  211. break;
  212. default:
  213. break;
  214. }
  215. /* set the EndPoint Status as Idle in the device layer */
  216. (void)_usb_device_set_status(&controller_ID,
  217. (uint_8)(USB_STATUS_ENDPOINT | VIDEO_ENDPOINT |
  218. (ep_struct->direction << USB_COMPONENT_DIRECTION_SHIFT)),
  219. USB_STATUS_IDLE);
  220. }
  221. }
  222. else if(event == USB_APP_BUS_RESET)
  223. {
  224. /* clear producer and consumer on reset */
  225. for(index = 0; index < g_video_endpoint_data.count; index++)
  226. {
  227. g_video_endpoint_data.ep[index].bin_consumer = 0x00;
  228. g_video_endpoint_data.ep[index].bin_producer = 0x00;
  229. g_video_endpoint_data.ep[index].queue_num = 0x00;
  230. }
  231. }
  232. if(g_video_class_callback != NULL)
  233. {
  234. /* notify the event to the application */
  235. g_video_class_callback(controller_ID, event, val);
  236. }
  237. }
  238. static uint_8 USB_Video_Get_Cur_Control_Interface_Requests(
  239. uint_8 controller_ID, /* [IN] Controller ID */
  240. uint_8 control_selector, /* [IN] Controller ID */
  241. uint_8_ptr *data, /* [OUT] Pointer to Data */
  242. USB_PACKET_SIZE *size /* [OUT] Pointer to Size of Data */
  243. ){
  244. uint_8 status = USBERR_INVALID_REQ_TYPE;
  245. /*Body*/
  246. switch(control_selector){
  247. case VC_VIDEO_POWER_MODE_CONTROL:
  248. status=USB_Desc_Get_Cur_Power_Mode(controller_ID,data,size);
  249. break;
  250. case VC_REQUEST_ERROR_CODE_CONTROL:
  251. status=USB_Desc_Get_Cur_Error_Code(controller_ID,data,size);
  252. break;
  253. default:
  254. break;
  255. }/*EndSwitch*/
  256. return status;
  257. }/*EndBody*/
  258. static uint_8 USB_Video_Set_Cur_Control_Interface_Requests(
  259. uint_8 controller_ID, /* [IN] Controller ID */
  260. uint_8 control_selector, /* [IN] Controller ID */
  261. uint_8_ptr *data, /* [OUT] Pointer to Data */
  262. USB_PACKET_SIZE *size /* [OUT] Pointer to Size of Data */
  263. ){
  264. uint_8 status = USBERR_INVALID_REQ_TYPE;
  265. /*Body*/
  266. switch(control_selector){
  267. case VC_VIDEO_POWER_MODE_CONTROL:
  268. status=USB_Desc_Set_Cur_Power_Mode(controller_ID,data,size);
  269. break;
  270. default:
  271. break;
  272. }/*EndSwitch*/
  273. return status;
  274. }/*EndBody*/
  275. static uint_8 USB_Video_Get_Info_Control_Interface_Requests(
  276. uint_8 controller_ID, /* [IN] Controller ID */
  277. uint_8 control_selector, /* [IN] Controller ID */
  278. uint_8_ptr *data, /* [OUT] Pointer to Data */
  279. USB_PACKET_SIZE *size /* [OUT] Pointer to Size of Data */
  280. ){
  281. uint_8 status = USBERR_INVALID_REQ_TYPE;
  282. /*EndBody*/
  283. switch(control_selector){
  284. case VC_VIDEO_POWER_MODE_CONTROL:
  285. status=USB_Desc_Get_Info_Power_Mode(controller_ID,data,size);
  286. break;
  287. case VC_REQUEST_ERROR_CODE_CONTROL:
  288. status=USB_Desc_Get_Info_Error_Code(controller_ID,data,size);
  289. break;
  290. default:
  291. break;
  292. }/*EndSitch*/
  293. return status;
  294. }/*EndBody*/
  295. /**************************************************************************//*!
  296. *
  297. * @name: USB_Video_Get_Control_Interface_Requests
  298. *
  299. * @brief This function is called in response to Get Interface Requests
  300. *
  301. * @param controller_ID : Controller ID
  302. * @param setup_packet : Pointer to setup packet
  303. * @param data : Data to be send back
  304. * @param size : Size to be returned
  305. *
  306. * @return status:
  307. * USB_OK : When Successfull
  308. * USBERR_INVALID_REQ_TYPE : When request for invalid
  309. * Interface is presented
  310. *
  311. ******************************************************************************
  312. * The funtion Get Feature unit and Terminal requests. It is called in
  313. * USB_Other_Request function
  314. *****************************************************************************/
  315. static uint_8 USB_Video_Get_Control_Interface_Requests(
  316. uint_8 controller_ID, /* [IN] Controller ID */
  317. uint_8 bRequest,
  318. uint_8 control_selector,
  319. uint_8_ptr *data, /* [OUT] Pointer to Data */
  320. USB_PACKET_SIZE *size /* [OUT] Pointer to Size of Data */
  321. )
  322. {
  323. uint_8 status = USBERR_INVALID_REQ_TYPE;
  324. /*Body*/
  325. switch(bRequest)
  326. {
  327. case GET_CUR:
  328. status=USB_Video_Get_Cur_Control_Interface_Requests(controller_ID,
  329. control_selector,data,size);
  330. break;
  331. case GET_INFO:
  332. status=USB_Video_Get_Info_Control_Interface_Requests(controller_ID,control_selector,data,size);
  333. break;
  334. default:
  335. break;
  336. }/*EndSwitch*/
  337. return status;
  338. }/*EndBody*/
  339. /**************************************************************************//*!
  340. *
  341. * @name: USB_Video_Set_Control_Interface_Requests
  342. *
  343. * @brief This function is called in response to Get Interface Requests
  344. *
  345. * @param controller_ID : Controller ID
  346. * @param setup_packet : Pointer to setup packet
  347. * @param data : Data to be send back
  348. * @param size : Size to be returned
  349. *
  350. * @return status:
  351. * USB_OK : When Successfull
  352. * USBERR_INVALID_REQ_TYPE : When request for invalid
  353. * Interface is presented
  354. *
  355. ******************************************************************************
  356. * The funtion Get Feature unit and Terminal requests. It is called in
  357. * USB_Other_Request function
  358. *****************************************************************************/
  359. static uint_8 USB_Video_Set_Control_Interface_Requests(
  360. uint_8 controller_ID, /* [IN] Controller ID */
  361. uint_8 bRequest,
  362. uint_8 control_selector,
  363. uint_8_ptr *data, /* [OUT] Pointer to Data */
  364. USB_PACKET_SIZE *size /* [OUT] Pointer to Size of Data */
  365. ){
  366. uint_8 status = USBERR_INVALID_REQ_TYPE;
  367. /*Body*/
  368. switch(bRequest)
  369. {
  370. case SET_CUR:
  371. status=USB_Video_Set_Cur_Control_Interface_Requests(controller_ID,
  372. control_selector,data,size);
  373. break;
  374. default:
  375. break;
  376. }/*EndSwitch*/
  377. return status;
  378. }/*EndBody*/
  379. static uint_8 USB_Video_Set_Cur_Processing_Unit(
  380. uint_8 controller_ID, /* [IN] Controller ID */
  381. uint_8 control_selector, /* [IN] Controller ID */
  382. uint_8_ptr *data, /* [OUT] Pointer to Data */
  383. USB_PACKET_SIZE *size /* [OUT] Pointer to Size of Data */
  384. ){
  385. uint_8 status = USBERR_INVALID_REQ_TYPE;
  386. /*EndBody*/
  387. switch(control_selector){
  388. case PU_BRIGHTNESS_CONTROL:
  389. status=USB_Desc_Set_Cur_Brightness(controller_ID,data,size);
  390. break;
  391. default:
  392. break;
  393. }/*EndSwitch*/
  394. return status;
  395. }/*EndBody*/
  396. static uint_8 USB_Video_Get_Cur_Processing_Unit(
  397. uint_8 controller_ID, /* [IN] Controller ID */
  398. uint_8 control_selector, /* [IN] Controller ID */
  399. uint_8_ptr *data, /* [OUT] Pointer to Data */
  400. USB_PACKET_SIZE *size /* [OUT] Pointer to Size of Data */
  401. ){
  402. uint_8 status = USBERR_INVALID_REQ_TYPE;
  403. /*Body*/
  404. switch(control_selector){
  405. case PU_BRIGHTNESS_CONTROL:
  406. status=USB_Desc_Get_Cur_Brightness(controller_ID,data,size);
  407. break;
  408. default:
  409. break;
  410. }/*EndSwitch*/
  411. return status;
  412. }/*EndBody*/
  413. static uint_8 USB_Video_Get_Min_Processing_Unit(
  414. uint_8 controller_ID, /* [IN] Controller ID */
  415. uint_8 control_selector, /* [IN] Controller ID */
  416. uint_8_ptr *data, /* [OUT] Pointer to Data */
  417. USB_PACKET_SIZE *size /* [OUT] Pointer to Size of Data */
  418. ){
  419. uint_8 status = USBERR_INVALID_REQ_TYPE;
  420. /*Body*/
  421. switch(control_selector){
  422. case PU_BRIGHTNESS_CONTROL:
  423. status=USB_Desc_Get_Min_Brightness(controller_ID,data,size);
  424. break;
  425. default:
  426. break;
  427. }/*EndSwitch*/
  428. return status;
  429. }/*EndBody*/
  430. static uint_8 USB_Video_Get_Max_Processing_Unit(
  431. uint_8 controller_ID, /* [IN] Controller ID */
  432. uint_8 control_selector, /* [IN] Controller ID */
  433. uint_8_ptr *data, /* [OUT] Pointer to Data */
  434. USB_PACKET_SIZE *size /* [OUT] Pointer to Size of Data */
  435. ){
  436. uint_8 status = USBERR_INVALID_REQ_TYPE;
  437. /*Body*/
  438. switch(control_selector){
  439. case PU_BRIGHTNESS_CONTROL:
  440. status=USB_Desc_Get_Max_Brightness(controller_ID,data,size);
  441. break;
  442. default:
  443. break;
  444. }/*EndSwitch*/
  445. return status;
  446. }/*EndBody*/
  447. static uint_8 USB_Video_Get_Res_Processing_Unit(
  448. uint_8 controller_ID, /* [IN] Controller ID */
  449. uint_8 control_selector, /* [IN] Controller ID */
  450. uint_8_ptr *data, /* [OUT] Pointer to Data */
  451. USB_PACKET_SIZE *size /* [OUT] Pointer to Size of Data */
  452. ){
  453. uint_8 status = USBERR_INVALID_REQ_TYPE;
  454. /*Body*/
  455. switch(control_selector){
  456. case PU_BRIGHTNESS_CONTROL:
  457. status=USB_Desc_Get_Res_Brightness(controller_ID,data,size);
  458. break;
  459. default:
  460. break;
  461. }/*EndSwitch*/
  462. return status;
  463. }/*EndBody*/
  464. static uint_8 USB_Video_Get_Info_Processing_Unit(
  465. uint_8 controller_ID, /* [IN] Controller ID */
  466. uint_8 control_selector, /* [IN] Controller ID */
  467. uint_8_ptr *data, /* [OUT] Pointer to Data */
  468. USB_PACKET_SIZE *size /* [OUT] Pointer to Size of Data */
  469. ){
  470. uint_8 status = USBERR_INVALID_REQ_TYPE;
  471. /*Body*/
  472. switch(control_selector){
  473. case PU_BRIGHTNESS_CONTROL:
  474. status=USB_Desc_Get_Info_Brightness(controller_ID,data,size);
  475. break;
  476. default:
  477. break;
  478. }/*EndSwitch*/
  479. return status;
  480. }/*EndBody*/
  481. static uint_8 USB_Video_Get_Def_Processing_Unit(
  482. uint_8 controller_ID, /* [IN] Controller ID */
  483. uint_8 control_selector, /* [IN] Controller ID */
  484. uint_8_ptr *data, /* [OUT] Pointer to Data */
  485. USB_PACKET_SIZE *size /* [OUT] Pointer to Size of Data */
  486. ){
  487. uint_8 status = USBERR_INVALID_REQ_TYPE;
  488. /*Body*/
  489. switch(control_selector){
  490. case PU_BRIGHTNESS_CONTROL:
  491. status=USB_Desc_Get_Def_Brightness(controller_ID,data,size);
  492. break;
  493. default:
  494. break;
  495. }/*EndSwitch*/
  496. return status;
  497. }/*EndBody*/
  498. static uint_8 USB_Video_Set_Processing_Unit(
  499. uint_8 controller_ID, /* [IN] Controller ID */
  500. uint_8 bRequest,
  501. uint_8 control_selector,
  502. uint_8_ptr *data, /* [OUT] Pointer to Data */
  503. USB_PACKET_SIZE *size /* [OUT] Pointer to Size of Data */
  504. ){
  505. uint_8 status = USBERR_INVALID_REQ_TYPE;
  506. /*EndBody*/
  507. switch(bRequest)
  508. {
  509. case SET_CUR:
  510. status=USB_Video_Set_Cur_Processing_Unit(controller_ID,control_selector,data,size);
  511. break;
  512. default:
  513. break;
  514. }/*EndSwitch*/
  515. return status;
  516. }/*EndBody*/
  517. static uint_8 USB_Video_Get_Processing_Unit(
  518. uint_8 controller_ID, /* [IN] Controller ID */
  519. uint_8 bRequest,
  520. uint_8 control_selector,
  521. uint_8_ptr *data, /* [OUT] Pointer to Data */
  522. USB_PACKET_SIZE *size /* [OUT] Pointer to Size of Data */
  523. ){
  524. uint_8 status = USBERR_INVALID_REQ_TYPE;
  525. /*Body*/
  526. switch(bRequest)
  527. {
  528. case GET_CUR:
  529. status=USB_Video_Get_Cur_Processing_Unit(controller_ID,control_selector,data,size);
  530. break;
  531. case GET_MIN:
  532. status=USB_Video_Get_Min_Processing_Unit(controller_ID,control_selector,data,size);
  533. break;
  534. case GET_MAX:
  535. status=USB_Video_Get_Max_Processing_Unit(controller_ID,control_selector,data,size);
  536. break;
  537. case GET_RES:
  538. status=USB_Video_Get_Res_Processing_Unit(controller_ID,control_selector,data,size);
  539. break;
  540. case GET_LEN:
  541. break;
  542. case GET_INFO:
  543. status=USB_Video_Get_Info_Processing_Unit(controller_ID,control_selector,data,size);
  544. break;
  545. case GET_DEF:
  546. status=USB_Video_Get_Def_Processing_Unit(controller_ID,control_selector,data,size);
  547. break;
  548. default:
  549. break;
  550. }/*EndSwitch*/
  551. return status;
  552. }/*EndBody*/
  553. /**************************************************************************//*!
  554. *
  555. * @name: USB_Video_Get_Control_Interface_Requests
  556. *
  557. * @brief This function is called in response to Get Interface Requests
  558. *
  559. * @param controller_ID : Controller ID
  560. * @param setup_packet : Pointer to setup packet
  561. * @param data : Data to be send back
  562. * @param size : Size to be returned
  563. *
  564. * @return status:
  565. * USB_OK : When Successfull
  566. * USBERR_INVALID_REQ_TYPE : When request for invalid
  567. * Interface is presented
  568. *
  569. ******************************************************************************
  570. * The funtion Get Feature unit and Terminal requests. It is called in
  571. * USB_Other_Request function
  572. *****************************************************************************/
  573. static uint_8 USB_Video_Get_Unit_Terminal_Requests(
  574. uint_8 controller_ID, /* [IN] Controller ID */
  575. USB_SETUP_STRUCT * setup_packet, /* [IN] Pointer to setup packet */
  576. uint_8_ptr *data, /* [OUT] Pointer to Data */
  577. USB_PACKET_SIZE *size /* [OUT] Pointer to Size of Data */
  578. )
  579. {
  580. uint_8 i;
  581. volatile uint_8 j=0;
  582. uint_8 status = USBERR_INVALID_REQ_TYPE;
  583. USB_VIDEO_UNITS *entity_desc_data;
  584. USB_UT_STRUCT_PTR ut_struct;
  585. uint_8 control_selector;
  586. control_selector=(uint_8)(setup_packet->value>>8);
  587. /* get the I/O Interface and Feature from the descriptor module */
  588. entity_desc_data = (USB_VIDEO_UNITS *)USB_Desc_Get_Video_Entities(controller_ID);
  589. for(i=0;i<VIDEO_UNIT_COUNT; i++)
  590. {
  591. ut_struct=(USB_UT_STRUCT_PTR)&(entity_desc_data->et[i]);
  592. if((setup_packet->index >>8) == ut_struct->unit_id)
  593. {
  594. switch(ut_struct->type)
  595. {
  596. case VC_INPUT_TERMINAL:
  597. break;
  598. case VC_PROCESSING_UNIT:
  599. /* Select SET request Control Processing Unit Module */
  600. status = USB_Video_Get_Processing_Unit(controller_ID,
  601. setup_packet->request,control_selector,data,size);
  602. break;
  603. case VC_OUTPUT_TERMINAL:
  604. break;
  605. default:
  606. break;
  607. }
  608. }
  609. }
  610. return status;
  611. }
  612. /**************************************************************************//*!
  613. *
  614. * @name: USB_Video_Set_Control_Interface_Requests
  615. *
  616. * @brief This function is called in response to Get Interface Requests
  617. *
  618. * @param controller_ID : Controller ID
  619. * @param setup_packet : Pointer to setup packet
  620. * @param data : Data to be send back
  621. * @param size : Size to be returned
  622. *
  623. * @return status:
  624. * USB_OK : When Successfull
  625. * USBERR_INVALID_REQ_TYPE : When request for invalid
  626. * Interface is presented
  627. *
  628. ******************************************************************************
  629. * The funtion Get Feature unit and Terminal requests. It is called in
  630. * USB_Other_Request function
  631. *****************************************************************************/
  632. static uint_8 USB_Video_Set_Unit_Terminal_Requests(
  633. uint_8 controller_ID, /* [IN] Controller ID */
  634. USB_SETUP_STRUCT * setup_packet, /* [IN] Pointer to setup packet */
  635. uint_8_ptr *data, /* [OUT] Pointer to Data */
  636. USB_PACKET_SIZE *size /* [OUT] Pointer to Size of Data */
  637. )
  638. {
  639. uint_8 i;
  640. volatile uint_8 j=0;
  641. uint_8 status = USBERR_INVALID_REQ_TYPE;
  642. USB_VIDEO_UNITS *entity_desc_data;
  643. USB_UT_STRUCT_PTR ut_struct;
  644. uint_8 control_selector;
  645. control_selector=(uint_8)(setup_packet->value>>8);
  646. /* get the I/O Interface and Feature from the descriptor module */
  647. entity_desc_data = (USB_VIDEO_UNITS *)USB_Desc_Get_Video_Entities(controller_ID);
  648. for(i=0;i<VIDEO_UNIT_COUNT; i++)
  649. {
  650. ut_struct=(USB_UT_STRUCT_PTR)&(entity_desc_data->et[i]);
  651. if((setup_packet->index >>8) == ut_struct->unit_id)
  652. {
  653. switch(ut_struct->type)
  654. {
  655. case VC_INPUT_TERMINAL:
  656. break;
  657. case VC_PROCESSING_UNIT:
  658. /* Select SET request Control Feature Unit Module */
  659. status = USB_Video_Set_Processing_Unit(controller_ID,
  660. setup_packet->request,control_selector,data,size);
  661. break;
  662. case VC_OUTPUT_TERMINAL:
  663. break;
  664. default:
  665. break;
  666. }
  667. }
  668. }
  669. return status;
  670. }
  671. static uint_8 USB_Video_Set_Cur_Stream_Interface(
  672. uint_8 controller_ID, /* [IN] Controller ID */
  673. uint_8 control_selector, /* [IN] Controller ID */
  674. uint_8_ptr *data, /* [OUT] Pointer to Data */
  675. USB_PACKET_SIZE *size /* [OUT] Pointer to Size of Data */
  676. ){
  677. uint_8 status = USBERR_INVALID_REQ_TYPE;
  678. /*Body*/
  679. switch(control_selector){
  680. case VS_PROBE_CONTROL:
  681. status=USB_Desc_Set_Cur_Video_Probe(controller_ID,data,size);
  682. break;
  683. case VS_COMMIT_CONTROL:
  684. status=USB_Desc_Set_Cur_Video_Commit(controller_ID,data,size);
  685. break;
  686. default:
  687. break;
  688. }/*EndSwitch*/
  689. return status;
  690. }/*EndBody*/
  691. static uint_8 USB_Video_Get_Cur_Stream_Interface(
  692. uint_8 controller_ID, /* [IN] Controller ID */
  693. uint_8 control_selector, /* [IN] Controller ID */
  694. uint_8_ptr *data, /* [OUT] Pointer to Data */
  695. USB_PACKET_SIZE *size /* [OUT] Pointer to Size of Data */
  696. ){
  697. uint_8 status = USBERR_INVALID_REQ_TYPE;
  698. /*Body*/
  699. switch(control_selector){
  700. case VS_PROBE_CONTROL:
  701. status=USB_Desc_Get_Cur_Video_Probe(controller_ID,data,size);
  702. break;
  703. case VS_COMMIT_CONTROL:
  704. status=USB_Desc_Get_Cur_Video_Commit(controller_ID,data,size);
  705. break;
  706. default:
  707. break;
  708. }/*EndSwitch*/
  709. return status;
  710. }/*EndBody*/
  711. static uint_8 USB_Video_Get_Len_Stream_Interface(
  712. uint_8 controller_ID, /* [IN] Controller ID */
  713. uint_8 control_selector, /* [IN] Controller ID */
  714. uint_8_ptr *data, /* [OUT] Pointer to Data */
  715. USB_PACKET_SIZE *size /* [OUT] Pointer to Size of Data */
  716. ){
  717. uint_8 status = USBERR_INVALID_REQ_TYPE;
  718. /*Body*/
  719. switch(control_selector){
  720. case VS_PROBE_CONTROL:
  721. status=USB_Desc_Get_Len_Video_Probe(controller_ID,data,size);
  722. break;
  723. case VS_COMMIT_CONTROL:
  724. status=USB_Desc_Get_Len_Video_Commit(controller_ID,data,size);
  725. break;
  726. default:
  727. break;
  728. }/*EndSwitch*/
  729. return status;
  730. }/*EndBody*/
  731. static uint_8 USB_Video_Get_Info_Stream_Interface(
  732. uint_8 controller_ID, /* [IN] Controller ID */
  733. uint_8 control_selector, /* [IN] Controller ID */
  734. uint_8_ptr *data, /* [OUT] Pointer to Data */
  735. USB_PACKET_SIZE *size /* [OUT] Pointer to Size of Data */
  736. ){
  737. uint_8 status = USBERR_INVALID_REQ_TYPE;
  738. /*Body*/
  739. switch(control_selector){
  740. case VS_PROBE_CONTROL:
  741. status=USB_Desc_Get_Info_Video_Probe(controller_ID,data,size);
  742. break;
  743. case VS_COMMIT_CONTROL:
  744. status=USB_Desc_Get_Info_Video_Commit(controller_ID,data,size);
  745. break;
  746. default:
  747. break;
  748. }/*EndSwitch*/
  749. return status;
  750. }/*EndBody*/
  751. static uint_8 USB_Video_Set_Stream_Interface_Requests(
  752. uint_8 controller_ID, /* [IN] Controller ID */
  753. USB_SETUP_STRUCT * setup_packet, /* [IN] Pointer to setup packet */
  754. uint_8_ptr *data, /* [OUT] Pointer to Data */
  755. USB_PACKET_SIZE *size /* [OUT] Pointer to Size of Data */
  756. ){
  757. uint_8 status = USBERR_INVALID_REQ_TYPE;
  758. uint_8 control_selector;
  759. /*Body*/
  760. control_selector = (uint_8)(setup_packet->value>>8);
  761. switch(setup_packet->request)
  762. {
  763. case SET_CUR:
  764. status=USB_Video_Set_Cur_Stream_Interface(controller_ID,control_selector,data,size);
  765. break;
  766. default:
  767. break;
  768. }/*EndSwitch*/
  769. return status;
  770. }/*EndBody*/
  771. static uint_8 USB_Video_Get_Stream_Interface_Requests(
  772. uint_8 controller_ID, /* [IN] Controller ID */
  773. USB_SETUP_STRUCT * setup_packet, /* [IN] Pointer to setup packet */
  774. uint_8_ptr *data, /* [OUT] Pointer to Data */
  775. USB_PACKET_SIZE *size /* [OUT] Pointer to Size of Data */
  776. ){
  777. uint_8 status = USBERR_INVALID_REQ_TYPE;
  778. uint_8 control_selector;
  779. control_selector = (uint_8)(setup_packet->value>>8);
  780. /*Body*/
  781. switch(setup_packet->request)
  782. {
  783. case GET_CUR:
  784. status=USB_Video_Get_Cur_Stream_Interface(controller_ID,control_selector,data,size);
  785. break;
  786. case GET_LEN:
  787. status=USB_Video_Get_Len_Stream_Interface(controller_ID,control_selector,data,size);
  788. break;
  789. case GET_INFO:
  790. status=USB_Video_Get_Info_Stream_Interface(controller_ID,control_selector,data,size);
  791. break;
  792. default:
  793. break;
  794. }/*EndSwitch*/
  795. return status;
  796. }/*EndBody*/
  797. /**************************************************************************//*!
  798. *
  799. * @name USB_Other_Requests
  800. *
  801. * @brief The funtion provides flexibilty to add class and vendor specific
  802. * requests
  803. *
  804. * @param controller_ID : Controller ID
  805. * @param setup_packet : Setup packet received
  806. * @param data : Data to be send back
  807. * @param size : Size to be returned
  808. *
  809. * @return status:
  810. * USB_OK : When Successfull
  811. * Others : When Error
  812. *
  813. ******************************************************************************
  814. * Handles Video Class requests and forwards vendor specific request to the
  815. * application
  816. *****************************************************************************/
  817. #ifndef COMPOSITE_DEV
  818. static uint_8 USB_Other_Requests
  819. #else
  820. uint_8 USB_Video_Other_Requests
  821. #endif
  822. (
  823. uint_8 controller_ID, /* [IN] Controller ID */
  824. USB_SETUP_STRUCT * setup_packet, /*[IN] Setup packet received */
  825. uint_8_ptr *data, /* [OUT] Data to be send back */
  826. USB_PACKET_SIZE *size /* [OUT] Size to be returned*/
  827. )
  828. {
  829. uint_8 status = USBERR_INVALID_REQ_TYPE;
  830. uint_8 itf_num,unitID,control_selector;
  831. /*Body*/
  832. /* point to the data which comes after the setup packet */
  833. *data = ((uint_8*)setup_packet)+USB_SETUP_PKT_SIZE;
  834. if (size == NULL)
  835. {
  836. return USBERR_GET_MEMORY_FAILED;
  837. }/*EndIf*/
  838. itf_num=(uint_8)(setup_packet->index);
  839. unitID=(uint_8)(setup_packet->index>>8);
  840. control_selector=(uint_8)(setup_packet->value>>8);
  841. switch(setup_packet->request_type)
  842. {
  843. case GET_REQUEST_ITF:
  844. if(itf_num==0)
  845. {
  846. /* Video Control Interface is Interface 0 */
  847. if(0==unitID)
  848. {
  849. /* Interface Control Requests */
  850. status=USB_Video_Get_Control_Interface_Requests(controller_ID,
  851. setup_packet->request,control_selector,data,size);
  852. }
  853. else
  854. {
  855. /* Unit and Terminal Requests */
  856. status=USB_Video_Get_Unit_Terminal_Requests(controller_ID,
  857. setup_packet,data,size);
  858. } /*EndIf*/
  859. }
  860. else
  861. {
  862. /* Video Stream Inteface */
  863. status=USB_Video_Get_Stream_Interface_Requests(controller_ID,
  864. setup_packet,data,size);
  865. } /*EndIf*/
  866. break;
  867. case SET_REQUEST_ITF:
  868. if(itf_num==0){
  869. *size = 0;
  870. /* Video Control Interface is Interface 0 */
  871. if(0==unitID){
  872. /* Interface Control Requests */
  873. status=USB_Video_Set_Control_Interface_Requests(controller_ID,
  874. setup_packet->request,control_selector,data,size);
  875. }else{
  876. /* Unit and Terminal Requests */
  877. status=USB_Video_Set_Unit_Terminal_Requests(controller_ID,setup_packet,data,size);
  878. } /*EndIf*/
  879. }else{
  880. /* Video Stream Inteface */
  881. *size=0;
  882. status=USB_Video_Set_Stream_Interface_Requests(controller_ID,setup_packet,data,size);
  883. }/*EndIf*/
  884. break;
  885. default:
  886. break;
  887. } /*EndSwitch*/
  888. return status;
  889. }/*EndBody*/
  890. /*****************************************************************************
  891. * Global Functions
  892. *****************************************************************************/
  893. /**************************************************************************//*!
  894. *
  895. * @name USB_Class_Video_Init
  896. *
  897. * @brief The funtion initializes the Device and Controller layer
  898. *
  899. * @param controller_ID : Controller ID
  900. * @param video_class_callback : Video Class Callback
  901. * @param vendor_req_callback : Vendor Request Callback
  902. * @param param_callback : Class requests Callback
  903. *
  904. * @return status:
  905. * USB_OK : When Successfull
  906. * Others : When Error
  907. *
  908. ******************************************************************************
  909. *This function initializes the Video Class layer and layers it is dependent on
  910. *****************************************************************************/
  911. uint_8 USB_Class_Video_Init (
  912. uint_8 controller_ID, /* [IN] Controller ID */
  913. USB_CLASS_CALLBACK video_class_callback, /* [IN] Video Class Callback */
  914. USB_REQ_FUNC vendor_req_callback, /* [IN] Vendor Request Callback */
  915. USB_CLASS_CALLBACK param_callback /* [ IN] Video Class requests Callback */
  916. )
  917. {
  918. uint_8 index;
  919. uint_8 status = USB_OK;
  920. USB_ENDPOINTS *ep_desc_data = (USB_ENDPOINTS *)
  921. USB_Desc_Get_Endpoints(controller_ID);
  922. #ifndef COMPOSITE_DEV
  923. /* Initialize the device layer*/
  924. status = _usb_device_init(controller_ID,NULL,
  925. (uint_8)(ep_desc_data->count+1), TRUE);
  926. if(status == USB_OK)
  927. {
  928. /* Initialize the generic class functions */
  929. status = USB_Class_Init(controller_ID,USB_Class_Video_Event,
  930. USB_Other_Requests);
  931. if(status == USB_OK)
  932. {
  933. #endif
  934. g_video_endpoint_data.count = ep_desc_data->count;
  935. for(index = 0; index < ep_desc_data->count; index++)
  936. {
  937. g_video_endpoint_data.ep[index].endpoint =
  938. ep_desc_data->ep[index].ep_num;
  939. g_video_endpoint_data.ep[index].type =
  940. ep_desc_data->ep[index].type;
  941. g_video_endpoint_data.ep[index].bin_consumer = 0x00;
  942. g_video_endpoint_data.ep[index].bin_producer = 0x00;
  943. g_video_endpoint_data.ep[index].queue_num = 0x00;
  944. }
  945. /* save the video class callback pointer */
  946. g_video_class_callback = video_class_callback;
  947. /* save the vendor request callback pointer */
  948. g_vendor_req_callback = vendor_req_callback;
  949. /* Save the callback to ask application for class specific params*/
  950. g_param_callback = param_callback;
  951. #ifndef COMPOSITE_DEV
  952. }
  953. }
  954. #endif
  955. return status;
  956. }
  957. /**************************************************************************//*!
  958. *
  959. * @name USB_Class_Video_DeInit
  960. *
  961. * @brief The funtion de-initializes the Device and Controller layer
  962. *
  963. * @param controller_ID : Controller ID
  964. *
  965. * @return status:
  966. * USB_OK : When Successfull
  967. * Others : When Error
  968. *
  969. ******************************************************************************
  970. *This function de-initializes the Video Class layer
  971. *****************************************************************************/
  972. uint_8 USB_Class_Video_DeInit
  973. (
  974. uint_8 controller_ID /* [IN] Controller ID */
  975. )
  976. {
  977. uint_8 status = USB_OK;
  978. #ifdef COMPOSITE_DEV
  979. UNUSED(controller_ID)
  980. #endif
  981. /* free the Audio class callback pointer */
  982. g_video_class_callback = NULL;
  983. /* free the callback to ask application for class specific params*/
  984. g_param_callback = NULL;
  985. #ifndef COMPOSITE_DEV
  986. /* Call common class deinit function */
  987. status = USB_Class_DeInit(controller_ID);
  988. if(status == USB_OK)
  989. /* Call device deinit function */
  990. status = _usb_device_deinit();
  991. #endif
  992. return status;
  993. }
  994. /**************************************************************************//*!
  995. *
  996. * @name USB_Class_Video_Send_Data
  997. *
  998. * @brief This fucntion is used by Application to send data through Video class
  999. *
  1000. * @param controller_ID : Controller ID
  1001. * @param ep_num : Endpoint number
  1002. * @param app_buff : Buffer to send
  1003. * @param size : Length of the transfer
  1004. *
  1005. * @return status:
  1006. * USB_OK : When Successfull
  1007. * Others : When Error
  1008. *
  1009. ******************************************************************************
  1010. * This fucntion is used by Application to send data through Video class
  1011. *****************************************************************************/
  1012. uint_8 USB_Class_Video_Send_Data (
  1013. uint_8 controller_ID, /* [IN] Controller ID */
  1014. uint_8 ep_num, /* [IN] Endpoint Number */
  1015. uint_8_ptr app_buff, /* [IN] Buffer to Send */
  1016. USB_PACKET_SIZE size /* [IN] Length of the Transfer */
  1017. )
  1018. {
  1019. uint_8 status = USB_OK;
  1020. PTR_USB_CLASS_VIDEO_QUEUE queue_tmp;
  1021. #if IMPLEMENT_QUEUING
  1022. uint_8 index;
  1023. uint_8 producer, queue_num;
  1024. USB_ENDPOINTS *usb_ep_data = (USB_ENDPOINTS *)
  1025. USB_Desc_Get_Endpoints(controller_ID);
  1026. /*Body*/
  1027. /* map the endpoint num to the index of the endpoint structure */
  1028. for(index = 0; index < usb_ep_data->count; index++)
  1029. {
  1030. if(usb_ep_data->ep[index].ep_num == ep_num)
  1031. break;
  1032. }/*EndFor*/
  1033. producer = g_video_endpoint_data.ep[index].bin_producer;
  1034. queue_num = g_video_endpoint_data.ep[index].queue_num;
  1035. if(MAX_QUEUE_ELEMS != queue_num)
  1036. {
  1037. /* the bin is not full*/
  1038. /* put all send request parameters in the endpoint data structure */
  1039. queue_tmp = &(g_video_endpoint_data.ep[index].queue[producer]);
  1040. queue_tmp->controller_ID = controller_ID;
  1041. queue_tmp->channel = ep_num;
  1042. queue_tmp->app_buff = app_buff;
  1043. queue_tmp->size = size;
  1044. /* increment producer bin by 1*/
  1045. if (producer == (MAX_QUEUE_ELEMS - 1))
  1046. {
  1047. g_video_endpoint_data.ep[index].bin_producer = 0;
  1048. } /*Else*/
  1049. else
  1050. {
  1051. g_video_endpoint_data.ep[index].bin_producer++;
  1052. }/*EndElse*/
  1053. g_video_endpoint_data.ep[index].queue_num++;
  1054. if(g_video_endpoint_data.ep[index].queue_num == 1)
  1055. {
  1056. #endif
  1057. status = USB_Class_Send_Data(controller_ID, ep_num, app_buff,size);
  1058. #if IMPLEMENT_QUEUING
  1059. }/*EndIf*/
  1060. }/*Else*/
  1061. else /* bin is full */
  1062. {
  1063. status = USBERR_DEVICE_BUSY;
  1064. }/*EndIf*/
  1065. #endif
  1066. return status;
  1067. }/*EndBody*/