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

Committer:
AxedaCorp
Date:
Tue Jul 01 21:31:54 2014 +0000
Revision:
0:65004368569c
Made initial

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AxedaCorp 0:65004368569c 1 // BaseUvc.cpp
AxedaCorp 0:65004368569c 2 #include "USBHostConf.h"
AxedaCorp 0:65004368569c 3 #include "USBHost.h"
AxedaCorp 0:65004368569c 4 #include "BaseUvc.h"
AxedaCorp 0:65004368569c 5
AxedaCorp 0:65004368569c 6 void BaseUvc::poll()
AxedaCorp 0:65004368569c 7 {
AxedaCorp 0:65004368569c 8 uint8_t buf[ep_iso_in->getSize()];
AxedaCorp 0:65004368569c 9 int result = host->IsochronousRead(ep_iso_in, buf, sizeof(buf));
AxedaCorp 0:65004368569c 10 if (result >= 0) {
AxedaCorp 0:65004368569c 11 uint16_t frame = 0;
AxedaCorp 0:65004368569c 12 onResult(frame, buf, ep_iso_in->getLengthTransferred());
AxedaCorp 0:65004368569c 13 }
AxedaCorp 0:65004368569c 14 }
AxedaCorp 0:65004368569c 15
AxedaCorp 0:65004368569c 16 USB_TYPE BaseUvc::Control(int req, int cs, int index, uint8_t* buf, int size)
AxedaCorp 0:65004368569c 17 {
AxedaCorp 0:65004368569c 18 if (req == SET_CUR) {
AxedaCorp 0:65004368569c 19 return host->controlWrite(dev,
AxedaCorp 0:65004368569c 20 USB_HOST_TO_DEVICE | USB_REQUEST_TYPE_CLASS | USB_RECIPIENT_INTERFACE,
AxedaCorp 0:65004368569c 21 req, cs<<8, index, buf, size);
AxedaCorp 0:65004368569c 22 }
AxedaCorp 0:65004368569c 23 return host->controlRead(dev,
AxedaCorp 0:65004368569c 24 USB_DEVICE_TO_HOST | USB_REQUEST_TYPE_CLASS | USB_RECIPIENT_INTERFACE,
AxedaCorp 0:65004368569c 25 req, cs<<8, index, buf, size);
AxedaCorp 0:65004368569c 26 }
AxedaCorp 0:65004368569c 27
AxedaCorp 0:65004368569c 28 USB_TYPE BaseUvc::setInterfaceAlternate(uint8_t intf, uint8_t alt)
AxedaCorp 0:65004368569c 29 {
AxedaCorp 0:65004368569c 30 return host->controlWrite(dev, USB_HOST_TO_DEVICE | USB_RECIPIENT_INTERFACE,
AxedaCorp 0:65004368569c 31 SET_INTERFACE, alt, intf, NULL, 0);
AxedaCorp 0:65004368569c 32 }
AxedaCorp 0:65004368569c 33
AxedaCorp 0:65004368569c 34 void BaseUvc::onResult(uint16_t frame, uint8_t* buf, int len)
AxedaCorp 0:65004368569c 35 {
AxedaCorp 0:65004368569c 36 if(m_pCbItem && m_pCbMeth)
AxedaCorp 0:65004368569c 37 (m_pCbItem->*m_pCbMeth)(frame, buf, len);
AxedaCorp 0:65004368569c 38 else if(m_pCb)
AxedaCorp 0:65004368569c 39 m_pCb(frame, buf, len);
AxedaCorp 0:65004368569c 40 }
AxedaCorp 0:65004368569c 41
AxedaCorp 0:65004368569c 42 void BaseUvc::setOnResult( void (*pMethod)(uint16_t, uint8_t*, int) )
AxedaCorp 0:65004368569c 43 {
AxedaCorp 0:65004368569c 44 m_pCb = pMethod;
AxedaCorp 0:65004368569c 45 m_pCbItem = NULL;
AxedaCorp 0:65004368569c 46 m_pCbMeth = NULL;
AxedaCorp 0:65004368569c 47 }
AxedaCorp 0:65004368569c 48
AxedaCorp 0:65004368569c 49 void BaseUvc::clearOnResult()
AxedaCorp 0:65004368569c 50 {
AxedaCorp 0:65004368569c 51 m_pCb = NULL;
AxedaCorp 0:65004368569c 52 m_pCbItem = NULL;
AxedaCorp 0:65004368569c 53 m_pCbMeth = NULL;
AxedaCorp 0:65004368569c 54 }
AxedaCorp 0:65004368569c 55