Pixy&Usb work with the new folder structure now.

This commit is contained in:
t-moe
2015-04-25 00:20:28 +02:00
parent 6c97e6fc24
commit 416883c15b
5 changed files with 86 additions and 54 deletions

View File

@@ -8,6 +8,7 @@ CROSS_COMPILE=arm-none-eabi-
CC=$(CROSS_COMPILE)gcc
OBJCOPY=$(CROSS_COMPILE)objcopy
GDB=$(CROSS_COMPILE)gdb
SIZE=$(CROSS_COMPILE)size
MKDIR=mkdir -p
RM=rm -f
@@ -90,6 +91,7 @@ stop:
#elf to binary
%.bin: %.elf
$(OBJCOPY) -O binary $< $@
$(SIZE) $<
#Asm files to objects
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.s

View File

@@ -1,13 +1,24 @@
#include "app.h"
#include "usb_hcd_int.h"
#include "usbh_usr.h"
#include "usbh_core.h"
#include "usbh_msc_core.h"
extern USB_OTG_CORE_HANDLE USB_OTG_Core;
extern USBH_HOST USB_Host;
int main(void)
{
app_init();
while (1)
{
USBH_Process(&USB_OTG_Core, &USB_Host);
app_process();
//USBH_Process(&USB_OTG_Core, &USB_Host);
}
}

View File

@@ -1,7 +1,6 @@
#include "usbh_msc_core.h"
#include "usbh_core.h"
#include "pixy.h"
static USBH_Status USBH_MSC_InterfaceInit (USB_OTG_CORE_HANDLE *pdev ,
@@ -18,6 +17,8 @@ static USBH_Status USBH_MSC_ClassRequest(USB_OTG_CORE_HANDLE *pdev ,
extern USB_OTG_CORE_HANDLE USB_OTG_Core;
extern USBH_HOST USB_Host;
USBH_Class_cb_TypeDef USBH_MSC_cb =
@@ -41,8 +42,6 @@ typedef struct
MSC_Machine_TypeDef;
MSC_Machine_TypeDef MSC_Machine;
enum {init,running,down}state;
static USBH_Status USBH_MSC_InterfaceInit ( USB_OTG_CORE_HANDLE *pdev,
void *phost)
@@ -108,11 +107,6 @@ static USBH_Status USBH_MSC_InterfaceInit ( USB_OTG_CORE_HANDLE *pdev,
void USBH_MSC_InterfaceDeInit ( USB_OTG_CORE_HANDLE *pdev,
void *phost)
{
if(state==running) {
pixy_close();
state=down;
}
if ( MSC_Machine.hc_num_out)
{
USB_OTG_HC_Halt(pdev, MSC_Machine.hc_num_out);
@@ -133,8 +127,6 @@ static USBH_Status USBH_MSC_ClassRequest(USB_OTG_CORE_HANDLE *pdev ,
{
USBH_Status status = USBH_OK ;
state=init;
return status;
}
@@ -147,32 +139,11 @@ static USBH_Status USBH_MSC_Handle(USB_OTG_CORE_HANDLE *pdev ,
if(HCD_IsDeviceConnected(pdev))
{
switch(state)
{
case init:
state = running;
USB_OTG_BSP_mDelay(3000); //let the pixy led flashing pass
pixy_init();
break;
case running:
pixy_service();
int appliStatus = pphost->usr_cb->USBH_USR_MSC_Application();
if(appliStatus == 0)
{
state=running; //stay here
}
else if (appliStatus == 1)
{
status = USBH_APPLY_DEINIT;
pixy_close();
state=down;
}
break;
case down:
break;
default:
break;
}
int appliStatus = pphost->usr_cb->USBH_USR_MSC_Application();
if(appliStatus != 0)
{
status = USBH_APPLY_DEINIT;
}
}
return status;
@@ -197,16 +168,37 @@ uint32_t USBH_LL_getTimer() {
int USBH_LL_open() {
int timeoutDetect=100;
int timeoutStartup=3000;
cnt_int=0; //reset timer
while(USB_Host.gState!=HOST_CLASS && cnt_int < timeoutDetect) {
USBH_Process(&USB_OTG_Core, &USB_Host);
}
if(USB_Host.gState!=HOST_CLASS) {
return -5; // = LIBUSB_ERROR_NOT_FOUND
}
//moved to common
cnt_int=0;
while(cnt_int<timeoutStartup) { //let pixy's led flashing pass
USBH_Process(&USB_OTG_Core, &USB_Host);
}
return 0; //ok
}
int USBH_LL_close() {
USBH_Process(&USB_OTG_Core, &USB_Host);
return 0;
}
int USBH_LL_send(const uint8_t *data, uint32_t len, uint16_t timeoutMs) {
USB_OTG_CORE_HANDLE *pdev = &USB_OTG_Core;
if(!HCD_IsDeviceConnected(pdev)) return -1;
USBH_BulkSendData (pdev,
(uint8_t*)data,
len ,
@@ -214,7 +206,7 @@ int USBH_LL_send(const uint8_t *data, uint32_t len, uint16_t timeoutMs) {
URB_STATE state;
cnt_int=0; //reset timer
if(timeoutMs==0) timeoutMs=10000; //Force 10s timeout (testwise)
if(timeoutMs==0) timeoutMs=1000; //Force 1s timeout (testwise)
while((state=HCD_GetURB_State(pdev , MSC_Machine.hc_num_out)) == URB_IDLE &&
(timeoutMs==0 || cnt_int < timeoutMs));
@@ -222,7 +214,7 @@ int USBH_LL_send(const uint8_t *data, uint32_t len, uint16_t timeoutMs) {
if(state!=URB_DONE) {
if(timeoutMs>0 && cnt_int>=timeoutMs) {
STM_EVAL_LEDOn(LED3);
return -7; //timeout (error code like with libusb
return -7; //timeout (error code like with libusb)
}
return -1;
@@ -234,6 +226,8 @@ int USBH_LL_receive(uint8_t *data, uint32_t len, uint16_t timeoutMs) {
USB_OTG_CORE_HANDLE *pdev = &USB_OTG_Core;
if(!HCD_IsDeviceConnected(pdev)) return -1;
USBH_BulkReceiveData (pdev,
data,
len ,
@@ -241,7 +235,7 @@ int USBH_LL_receive(uint8_t *data, uint32_t len, uint16_t timeoutMs) {
URB_STATE state;
cnt_int=0; //reset timer
if(timeoutMs==0) timeoutMs=10000; //Force 10s timeout (testwise)
if(timeoutMs==0) timeoutMs=1000; //Force 1s timeout (testwise)
while((state=HCD_GetURB_State(pdev , MSC_Machine.hc_num_in)) == URB_IDLE &&
(timeoutMs==0 || cnt_int < timeoutMs));
@@ -249,7 +243,7 @@ int USBH_LL_receive(uint8_t *data, uint32_t len, uint16_t timeoutMs) {
if(state!=URB_DONE) {
if(timeoutMs>0 && cnt_int>=timeoutMs) {
STM_EVAL_LEDOn(LED3);
return -7; //timeout (error code like with libusb
return -7; //timeout (error code like with libusb)
}
return -1;
}

View File

@@ -1,7 +1,7 @@
#include "usbh_usr.h"
#include <stdbool.h>
#include <string.h>
#include "pixy.h"
//#include "pixy.h"