Merge branch 'emulator' of github.com:t-moe/discoverpixy into emulator

This commit is contained in:
id101010
2015-04-27 18:43:08 +02:00
29 changed files with 413 additions and 113 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
@@ -40,7 +41,7 @@ INCLUDES:=$(addprefix -I,$(INCLUDES))
CPPFLAGS=-DUSE_USB_OTG_FS -DUSE_HOST_MODE $(INCLUDES)
CFLAGS=$(ARCH_FLAGS) -O0 -g
CFLAGS=$(ARCH_FLAGS) -O0 -g -std=c99
LIBS=pixy usbhost coreperiph stdc++
@@ -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

@@ -856,6 +856,10 @@ int Chirp::realloc(uint32_t min)
min = m_bufSize+CRP_BUFSIZE;
else
min += CRP_BUFSIZE;
if(min==m_bufSize)
return CRP_RES_OK;
uint8_t *newbuf = new (std::nothrow) uint8_t[min];
if (newbuf==NULL)
return CRP_RES_ERROR_MEMORY;

View File

@@ -55,6 +55,17 @@ bool ll_system_init(void)
return true;
}
void ll_system_process() {
USBH_Process(&USB_OTG_Core, &USB_Host);
}
void ll_system_delay(uint32_t msec) {
USB_OTG_BSP_mDelay(msec);
}
void ll_system_toggle_led() {
STM_EVAL_LEDToggle(LED6);
}

6
discovery/src/ll_touch.c Normal file
View File

@@ -0,0 +1,6 @@
#include "ll_touch.h"
bool ll_touch_init() {
return false;
}

View File

@@ -7,7 +7,6 @@ int main(void)
while (1)
{
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,36 @@ 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
}
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 +205,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 +213,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 +225,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 +234,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 +242,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,8 +1,6 @@
#include "usbh_usr.h"
#include <stdbool.h>
#include <string.h>
#include "pixy.h"
USBH_Usr_cb_TypeDef USR_Callbacks =
@@ -55,9 +53,9 @@ void USBH_USR_DeviceAttached(void)
serial_ok=false;
STM_EVAL_LEDOff(LED5);
STM_EVAL_LEDOff(LED3);
STM_EVAL_LEDOn(LED4);
STM_EVAL_LEDOff(LED5);
STM_EVAL_LEDOff(LED3);
STM_EVAL_LEDOn(LED4);
}
/**
@@ -144,7 +142,6 @@ void USBH_USR_Configuration_DescAvailable(USBH_CfgDesc_TypeDef * cfgDesc,
void USBH_USR_Manufacturer_String(void *ManufacturerString)
{
manufacturer_ok = strcmp((char*)ManufacturerString,"Charmed Labs") == 0;
/* callback for Manufacturer String */
}
/**
@@ -155,7 +152,6 @@ void USBH_USR_Manufacturer_String(void *ManufacturerString)
void USBH_USR_Product_String(void *ProductString)
{
product_ok = strcmp((char*)ProductString,"Pixy") == 0;
/* callback for Product String */
}
/**
@@ -166,7 +162,6 @@ void USBH_USR_Product_String(void *ProductString)
void USBH_USR_SerialNum_String(void *SerialNumString)
{
serial_ok = strcmp((char*)SerialNumString,"DEMO 0.0") == 0;
/* callback for SerialNum_String */
}
/**
@@ -220,26 +215,8 @@ void USBH_USR_OverCurrentDetected (void)
* @param None
* @retval Staus
*/
/*int colorind;
const uint32_t colors [] = {0xFF0000, 0x00FF00,0x0000FF,0xFFFF00,0x00FFFF,0xFF00FF,0xFFFFFF,0x000000};
const int num_colors = sizeof(colors)/sizeof(uint32_t);
*/
int USBH_USR_MSC_Application(void)
{
/* if(colorind==0) {
pixy_led_set_max_current(5);
}
int32_t response;
int return_value;
return_value = pixy_command("led_set", INT32(colors[colorind++]), END_OUT_ARGS, &response, END_IN_ARGS);
colorind%=num_colors;
USB_OTG_BSP_mDelay(500);
*/
return 0;
}
@@ -254,10 +231,3 @@ void USBH_USR_DeInit(void)
}
/**
* @}
*/
/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/