Axeda Ready Demo for Freescale FRDM-KL46Z as accident alert system

Dependencies:   FRDM_MMA8451Q KL46Z-USBHost MAG3110 SocketModem TSI mbed FATFileSystem

Fork of AxedaGo-Freescal_FRDM-KL46Z revert by Axeda Corp

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers BaseUvc.cpp Source File

BaseUvc.cpp

00001 // BaseUvc.cpp
00002 #include "USBHostConf.h"
00003 #include "USBHost.h"
00004 #include "BaseUvc.h"
00005 
00006 void BaseUvc::poll()
00007 {
00008     uint8_t buf[ep_iso_in->getSize()];
00009     int result = host->IsochronousRead(ep_iso_in, buf, sizeof(buf));
00010     if (result >= 0) {
00011         uint16_t frame = 0;
00012         onResult(frame, buf, ep_iso_in->getLengthTransferred());
00013     }
00014 }
00015 
00016 USB_TYPE BaseUvc::Control(int req, int cs, int index, uint8_t* buf, int size)
00017 {
00018     if (req == SET_CUR) {    
00019         return host->controlWrite(dev,
00020                     USB_HOST_TO_DEVICE | USB_REQUEST_TYPE_CLASS | USB_RECIPIENT_INTERFACE, 
00021                     req, cs<<8, index, buf, size);
00022     }
00023     return host->controlRead(dev,
00024                 USB_DEVICE_TO_HOST | USB_REQUEST_TYPE_CLASS | USB_RECIPIENT_INTERFACE, 
00025                 req, cs<<8, index, buf, size);
00026 }
00027 
00028 USB_TYPE BaseUvc::setInterfaceAlternate(uint8_t intf, uint8_t alt)
00029 {
00030     return host->controlWrite(dev, USB_HOST_TO_DEVICE | USB_RECIPIENT_INTERFACE,
00031                                    SET_INTERFACE, alt, intf, NULL, 0);
00032 }
00033 
00034 void BaseUvc::onResult(uint16_t frame, uint8_t* buf, int len)
00035 {
00036   if(m_pCbItem && m_pCbMeth)
00037     (m_pCbItem->*m_pCbMeth)(frame, buf, len);
00038   else if(m_pCb)
00039     m_pCb(frame, buf, len);
00040 }
00041 
00042 void BaseUvc::setOnResult( void (*pMethod)(uint16_t, uint8_t*, int) )
00043 {
00044     m_pCb = pMethod;
00045     m_pCbItem = NULL;
00046     m_pCbMeth = NULL;
00047 }
00048     
00049 void BaseUvc::clearOnResult()
00050 {
00051     m_pCb = NULL;
00052     m_pCbItem = NULL;
00053     m_pCbMeth = NULL;
00054 }
00055