Merge branch 'emulator' of github.com:t-moe/discoverpixy into emulator
This commit is contained in:
140
common/app/app.c
140
common/app/app.c
@@ -1,14 +1,47 @@
|
||||
#include "app.h"
|
||||
#include "tft.h"
|
||||
#include "system.h"
|
||||
#include "touch.h"
|
||||
#include "pixy.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
bool pixy_connected = false;
|
||||
|
||||
TOUCH_AREA_STRUCT a1;
|
||||
|
||||
|
||||
void touchCB(void* touchArea, TOUCH_ACTION triggeredAction) {
|
||||
|
||||
switch(triggeredAction) {
|
||||
case PEN_DOWN:
|
||||
printf("action PEN_DOWN\n");
|
||||
break;
|
||||
|
||||
case PEN_UP:
|
||||
printf("action PEN_UP\n");
|
||||
break;
|
||||
case PEN_MOVE:
|
||||
printf("action PEN_MOVE\n");
|
||||
break;
|
||||
case PEN_ENTER:
|
||||
printf("action PEN_ENTER\n");
|
||||
break;
|
||||
case PEN_LEAVE:
|
||||
printf("action PEN_LEAVE\n");
|
||||
break;
|
||||
default:
|
||||
printf("action %s\n",triggeredAction);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void app_init() {
|
||||
system_init();
|
||||
tft_init();
|
||||
touch_init();
|
||||
|
||||
pixy_init();
|
||||
pixy_connected = (pixy_init()==0); //try to connect to pixy
|
||||
|
||||
//only testwise
|
||||
tft_clear(WHITE);
|
||||
@@ -18,22 +51,53 @@ void app_init() {
|
||||
tft_fill_rectangle(100,215,200,225,GREEN);
|
||||
tft_draw_line(10,215,310,225,RGB(0xFF,0,0xFF));
|
||||
tft_draw_circle(10,10,100, RED);
|
||||
|
||||
a1.hookedActions = PEN_DOWN | PEN_UP | PEN_MOVE | PEN_ENTER | PEN_LEAVE;
|
||||
a1.x1 = 30;
|
||||
a1.y1 = 30;
|
||||
a1.x2 = 100;
|
||||
a1.y2 = 60;
|
||||
a1.callback = touchCB;
|
||||
touch_register_area(&a1);
|
||||
|
||||
tft_draw_rectangle(30,30,100,60,BLUE);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void pixy_led_test();
|
||||
void pixy_frame_test();
|
||||
|
||||
int pixy_led_test();
|
||||
int pixy_frame_test();
|
||||
|
||||
//app event loop
|
||||
void app_process() {
|
||||
pixy_service(); //send/receive event data
|
||||
|
||||
//Code for tests see below
|
||||
pixy_led_test();
|
||||
pixy_frame_test();
|
||||
system_process(); //Let the system handle it's pending events
|
||||
|
||||
//system_delay(500);
|
||||
|
||||
//Note: The only way to detect that pixy has been disconnected is if a command fails. There's no pixy_is_connected method yet :'(
|
||||
|
||||
if(!pixy_connected) { //Pixy not connected
|
||||
pixy_close(); //Ensure that all pixy resources are freed (failsafe)
|
||||
if(pixy_init()==0) { //try to connect to pixy
|
||||
pixy_connected=true;
|
||||
}
|
||||
}
|
||||
|
||||
if(pixy_connected) {
|
||||
pixy_service(); //Send/receive event data from/to pixy failed
|
||||
|
||||
//Code for tests see below
|
||||
if(pixy_led_test()!=0) {
|
||||
pixy_connected=false;
|
||||
}
|
||||
|
||||
/*if(pixy_frame_test()!=0) {
|
||||
pixy_connected=false;
|
||||
}*/
|
||||
system_delay(500);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +107,7 @@ int colorind;
|
||||
const uint32_t colors [] = {0xFF0000, 0x00FF00,0x0000FF,0xFFFF00,0x00FFFF,0xFF00FF,0xFFFFFF,0x000000};
|
||||
const int num_colors = sizeof(colors)/sizeof(uint32_t);
|
||||
|
||||
void pixy_led_test() {
|
||||
int pixy_led_test() {
|
||||
if(colorind==0) {
|
||||
pixy_led_set_max_current(5);
|
||||
}
|
||||
@@ -52,6 +116,12 @@ void pixy_led_test() {
|
||||
int return_value;
|
||||
return_value = pixy_command("led_set", INT32(colors[colorind++]), END_OUT_ARGS, &response, END_IN_ARGS);
|
||||
colorind%=num_colors;
|
||||
|
||||
if(return_value!=0) {
|
||||
colorind=0; //reset color ind, to start at zero when plugging pixy in again
|
||||
}
|
||||
|
||||
return return_value;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------------------------------
|
||||
@@ -59,7 +129,7 @@ void pixy_led_test() {
|
||||
int renderBA81(uint8_t renderFlags, uint16_t width, uint16_t height, uint32_t frameLen, uint8_t *frame);
|
||||
|
||||
|
||||
void pixy_frame_test() {
|
||||
int pixy_frame_test() {
|
||||
|
||||
uint8_t* videodata;
|
||||
int32_t response;
|
||||
@@ -86,15 +156,16 @@ void pixy_frame_test() {
|
||||
&videodata, // pointer to mem address for returned frame
|
||||
END_IN_ARGS);
|
||||
|
||||
|
||||
if(return_value==0) {
|
||||
return_value = renderBA81(renderflags,xwidth,ywidth,size,videodata);
|
||||
}
|
||||
|
||||
return return_value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
inline void interpolateBayer(uint16_t width, uint16_t x, uint16_t y, uint8_t *pixel, uint8_t* r, uint8_t* g, uint8_t* b)
|
||||
void interpolateBayer(uint16_t width, uint16_t x, uint16_t y, uint8_t *pixel, uint8_t* r, uint8_t* g, uint8_t* b)
|
||||
{
|
||||
if (y&1)
|
||||
{
|
||||
@@ -143,23 +214,40 @@ int renderBA81(uint8_t renderFlags, uint16_t width, uint16_t height, uint32_t fr
|
||||
// don't render top and bottom rows, and left and rightmost columns because of color
|
||||
// interpolation
|
||||
//uint32_t decodedimage[(width-2)*(height-2)];
|
||||
uint16_t decodedimage[(width-2)*(height-2)];
|
||||
uint16_t* decodedimage = malloc(sizeof(uint16_t)*(width-2)*(height-2));
|
||||
|
||||
uint16_t* line = decodedimage;
|
||||
for (y=1; y<height-1; y++)
|
||||
{
|
||||
//line = (unsigned int *)img.scanLine(y-1);
|
||||
frame++;
|
||||
for (x=1; x<width-1; x++, frame++)
|
||||
if(decodedimage==NULL) { //not enough free space to decode image in memory
|
||||
//decode & render image pixel by pixel
|
||||
uint16_t* line = decodedimage;
|
||||
for (y=1; y<height-1; y++)
|
||||
{
|
||||
interpolateBayer(width, x, y, frame, &r, &g, &b);
|
||||
//*line++ = (0xff<<24) | (r<<16) | (g<<8) | (b<<0);
|
||||
*line++ = RGB(r,g,b);
|
||||
}
|
||||
frame++;
|
||||
}
|
||||
frame++;
|
||||
for (x=1; x<width-1; x++, frame++)
|
||||
{
|
||||
interpolateBayer(width, x, y, frame, &r, &g, &b);
|
||||
tft_draw_pixel(x-1,y-1,RGB(r,g,b));
|
||||
}
|
||||
frame++;
|
||||
}
|
||||
} else { //enough space
|
||||
uint16_t* line = decodedimage;
|
||||
for (y=1; y<height-1; y++)
|
||||
{
|
||||
//line = (unsigned int *)img.scanLine(y-1);
|
||||
frame++;
|
||||
for (x=1; x<width-1; x++, frame++)
|
||||
{
|
||||
interpolateBayer(width, x, y, frame, &r, &g, &b);
|
||||
//*line++ = (0xff<<24) | (r<<16) | (g<<8) | (b<<0);
|
||||
*line++ = RGB(r,g,b);
|
||||
}
|
||||
frame++;
|
||||
}
|
||||
|
||||
tft_draw_bitmap_unscaled(0,0,width-2,height-2,decodedimage);
|
||||
tft_draw_bitmap_unscaled(0,0,width-2,height-2,decodedimage);
|
||||
|
||||
free(decodedimage);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -3,4 +3,5 @@
|
||||
|
||||
bool ll_system_init();
|
||||
void ll_system_delay(uint32_t msec);
|
||||
|
||||
void ll_system_process();
|
||||
void ll_system_toggle_led();
|
||||
|
||||
6
common/lowlevel/ll_touch.h
Normal file
6
common/lowlevel/ll_touch.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
bool ll_touch_init();
|
||||
|
||||
|
||||
@@ -6,10 +6,14 @@ bool system_init() {
|
||||
return ll_system_init();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void system_delay(uint32_t msec) {
|
||||
ll_system_delay(msec);
|
||||
}
|
||||
|
||||
void system_process() {
|
||||
ll_system_process();
|
||||
}
|
||||
|
||||
void system_toggle_led() {
|
||||
ll_system_toggle_led();
|
||||
}
|
||||
|
||||
@@ -3,3 +3,5 @@
|
||||
|
||||
bool system_init();
|
||||
void system_delay(uint32_t msec);
|
||||
void system_process();
|
||||
void system_toggle_led();
|
||||
|
||||
129
common/touch/touch.c
Normal file
129
common/touch/touch.c
Normal file
@@ -0,0 +1,129 @@
|
||||
#include "touch.h"
|
||||
#include "ll_touch.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#define NUM_AREAS 50 //Number of Structs Reserved in Memory for TouchAreas (e.g Buttons)
|
||||
TOUCH_AREA_STRUCT* areas[NUM_AREAS] = {NULL};
|
||||
|
||||
volatile int touchY=0; //Last Y Coordinate in pixels
|
||||
volatile int touchX=0; //Last X Coordinate in pixels
|
||||
volatile TOUCH_STATE oldState=TOUCH_UP;
|
||||
|
||||
bool touch_init() {
|
||||
return ll_touch_init();
|
||||
}
|
||||
|
||||
|
||||
bool touch_add_raw_event(uint16_t x, uint16_t y, TOUCH_STATE state) {
|
||||
bool penDown = (state==TOUCH_DOWN);
|
||||
bool oldPenDown = (oldState==TOUCH_DOWN);
|
||||
oldState=state;
|
||||
uint16_t touchX = x;
|
||||
uint16_t touchY = y;
|
||||
if(penDown)
|
||||
{
|
||||
// tftDrawPixel(touchX,touchY,WHITE);
|
||||
if(!oldPenDown) //First Touch
|
||||
{
|
||||
for(int z=0; z < NUM_AREAS; z++) // For every touch area
|
||||
{
|
||||
if(areas[z]!=NULL && touchX >= areas[z]->x1 && touchX <= areas[z]->x2 && touchY >= areas[z]->y1 && touchY <= areas[z]->y2 )
|
||||
{
|
||||
areas[z]->flags=1; //PenInside=1
|
||||
if(areas[z]->hookedActions & PEN_DOWN)
|
||||
areas[z]->callback(areas[z],PEN_DOWN);
|
||||
}
|
||||
}
|
||||
}
|
||||
else //Second, Third
|
||||
{
|
||||
for(int z=0; z < NUM_AREAS; z++) // For every touch area
|
||||
{
|
||||
if(areas[z]!=NULL )
|
||||
{
|
||||
if(touchX >= areas[z]->x1 && touchX <= areas[z]->x2 && touchY >= areas[z]->y1 && touchY <= areas[z]->y2)
|
||||
{
|
||||
if(areas[z]->flags==0) //PenInside ==0
|
||||
{
|
||||
areas[z]->flags=1; //PenInside=1
|
||||
if(areas[z]->hookedActions & PEN_ENTER)
|
||||
areas[z]->callback(areas[z],PEN_ENTER);
|
||||
}
|
||||
}
|
||||
else if(areas[z]->flags) //PenInside==1
|
||||
{
|
||||
areas[z]->flags=0; //PenInside=0
|
||||
if(areas[z]->hookedActions & PEN_LEAVE)
|
||||
areas[z]->callback(areas[z],PEN_LEAVE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for(int z=0; z < NUM_AREAS; z++) // For every touch area
|
||||
{
|
||||
if(areas[z]!=NULL && areas[z]->hookedActions&PEN_MOVE)
|
||||
{
|
||||
if(touchX >= areas[z]->x1 && touchX <= areas[z]->x2 && touchY >= areas[z]->y1 && touchY <= areas[z]->y2)
|
||||
{
|
||||
areas[z]->callback(areas[z],PEN_MOVE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(oldPenDown) //Was the pen ever down (or was it a too short touch)
|
||||
{
|
||||
for(int z=0; z < NUM_AREAS; z++) // For every touch area
|
||||
{
|
||||
if(areas[z]!=NULL && touchX >= areas[z]->x1 && touchX <= areas[z]->x2 && touchY >= areas[z]->y1 && touchY <= areas[z]->y2 )
|
||||
{
|
||||
areas[z]->flags=0; //PenInside = 0;
|
||||
if(areas[z]->hookedActions & PEN_UP)
|
||||
areas[z]->callback(areas[z],PEN_UP);
|
||||
}
|
||||
}
|
||||
}
|
||||
touchX=0xFFFF;
|
||||
touchY=0xFFFF;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool touch_have_empty(unsigned char num)
|
||||
{
|
||||
for(unsigned char i=0; i<NUM_AREAS; i++)
|
||||
{
|
||||
if(areas[i]==NULL) num--;
|
||||
if(num==0) return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
bool touch_register_area(TOUCH_AREA_STRUCT* area) //Registers an Area (fill Struct first). Return false if no more Space in the Pointertable (-->Change NUM_AREAS).
|
||||
{
|
||||
|
||||
for(unsigned char i=0; i<NUM_AREAS; i++)
|
||||
{
|
||||
if(areas[i]==NULL)
|
||||
{
|
||||
area->flags=0;
|
||||
areas[i]=area;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void touch_unregister_area(TOUCH_AREA_STRUCT* area)//Unregisters an Area
|
||||
{
|
||||
for(unsigned char i=0; i<NUM_AREAS; i++)
|
||||
{
|
||||
if(areas[i]==area)
|
||||
{
|
||||
areas[i]=NULL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
#include<stdbool.h>
|
||||
#include<stdint.h>
|
||||
|
||||
|
||||
typedef enum {TOUCH_UP,TOUCH_DOWN} TOUCH_STATE ;
|
||||
typedef enum {NONE=0x00,PEN_DOWN=0x01, PEN_UP=0x02, PEN_ENTER=0x04, PEN_LEAVE=0x08,PEN_MOVE=0x10} TOUCH_ACTION;
|
||||
|
||||
typedef void (*TOUCH_CALLBACK)(void* touchArea, TOUCH_ACTION triggeredAction);
|
||||
|
||||
typedef struct {
|
||||
TOUCH_ACTION hookedActions; //Actions to listen to
|
||||
unsigned int x1; //Top Left X Coordiate of Area
|
||||
unsigned int y1; //Top Left Y Coordiate of Area
|
||||
unsigned int x2; //Bottom Right X Coordiate of Area
|
||||
unsigned int y2; //Bottom Right Y Coordiate of Area
|
||||
TOUCH_CALLBACK callback; //Callback
|
||||
uint8_t flags; //Internal Used, don't change
|
||||
} TOUCH_AREA_STRUCT;
|
||||
|
||||
|
||||
bool touch_init();
|
||||
bool touch_add_raw_event(uint16_t x, uint16_t y,TOUCH_STATE state);
|
||||
bool touch_have_empty(unsigned char num);
|
||||
bool touch_register_area(TOUCH_AREA_STRUCT* area);
|
||||
void touch_unregister_area(TOUCH_AREA_STRUCT* area);
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
6
discovery/src/ll_touch.c
Normal file
@@ -0,0 +1,6 @@
|
||||
#include "ll_touch.h"
|
||||
|
||||
bool ll_touch_init() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ int main(void)
|
||||
while (1)
|
||||
{
|
||||
app_process();
|
||||
//USBH_Process(&USB_OTG_Core, &USB_Host);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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****/
|
||||
|
||||
1
doc/.gitignore
vendored
Normal file
1
doc/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
*.*~
|
||||
BIN
doc/docu.odt
BIN
doc/docu.odt
Binary file not shown.
BIN
doc/docu.pdf
Normal file
BIN
doc/docu.pdf
Normal file
Binary file not shown.
BIN
doc/planung.ods
BIN
doc/planung.ods
Binary file not shown.
BIN
doc/screens.jpg
Normal file
BIN
doc/screens.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 598 KiB |
BIN
doc/usecasediagramm.dia
Normal file
BIN
doc/usecasediagramm.dia
Normal file
Binary file not shown.
BIN
doc/usecasediagramm.png
Normal file
BIN
doc/usecasediagramm.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 138 KiB |
@@ -25,7 +25,7 @@ QT_LIB=$(QT_DIR)/libemulatorqt.a
|
||||
|
||||
|
||||
CPPFLAGS= -march=x86-64 -mtune=generic -fPIC $(INCLUDES)
|
||||
CFLAGS= -O0 -g
|
||||
CFLAGS= -O0 -g -std=c99
|
||||
|
||||
|
||||
LIBS= pixy usb-1.0 boost_system boost_timer boost_chrono
|
||||
|
||||
@@ -111,6 +111,7 @@ usblink_open__close_and_exit:
|
||||
|
||||
usblink_open__exit:
|
||||
log("pixydebug: USBLink::open() returned %d\n", return_value);
|
||||
usleep(100* 1000); //let pixy init pass
|
||||
|
||||
return return_value;
|
||||
}
|
||||
|
||||
@@ -14,12 +14,14 @@ SOURCES += \
|
||||
mainwindow.cpp \
|
||||
main.cpp \
|
||||
ll_tft.cpp \
|
||||
ll_system.cpp
|
||||
ll_system.cpp \
|
||||
ll_touch.cpp
|
||||
HEADERS += \
|
||||
mainwindow.h \
|
||||
|
||||
|
||||
INCLUDEPATH+= ../../common/lowlevel/
|
||||
INCLUDEPATH+= ../../common/lowlevel/ \
|
||||
../../common/touch/
|
||||
|
||||
|
||||
FORMS += \
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
#include <QThread>
|
||||
#include <QApplication>
|
||||
|
||||
extern "C" {
|
||||
#include "ll_system.h"
|
||||
}
|
||||
@@ -11,3 +13,10 @@ void ll_system_delay(uint32_t msec) {
|
||||
QThread::msleep(msec);
|
||||
}
|
||||
|
||||
void ll_system_process() {
|
||||
QApplication::processEvents();
|
||||
}
|
||||
|
||||
void ll_system_toggle_led() {
|
||||
|
||||
}
|
||||
|
||||
8
emulator/qt/ll_touch.cpp
Normal file
8
emulator/qt/ll_touch.cpp
Normal file
@@ -0,0 +1,8 @@
|
||||
|
||||
extern "C" {
|
||||
#include "ll_touch.h"
|
||||
}
|
||||
|
||||
bool ll_touch_init() {
|
||||
return true;
|
||||
}
|
||||
@@ -10,7 +10,6 @@ extern "C" {
|
||||
void app_loop() {
|
||||
while(!QApplication::closingDown()) {
|
||||
app_process();
|
||||
QApplication::processEvents();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,11 @@
|
||||
#include <QDebug>
|
||||
#include <QPainter>
|
||||
#include <math.h>
|
||||
#include <QMouseEvent>
|
||||
|
||||
extern "C" {
|
||||
#include "touch.h"
|
||||
}
|
||||
|
||||
#define DISPLAY_WIDTH 320
|
||||
#define DISPLAY_HEIGHT 240
|
||||
@@ -116,9 +121,38 @@ void MainWindow::paintEvent(QPaintEvent *)
|
||||
//render_mutex.unlock();
|
||||
}
|
||||
|
||||
void MainWindow::mousePressEvent(QMouseEvent *evt)
|
||||
{
|
||||
//qDebug() << "down" << evt->pos();
|
||||
checkAndSendEvent(evt->pos(),true);
|
||||
}
|
||||
|
||||
void MainWindow::mouseReleaseEvent(QMouseEvent *evt)
|
||||
{
|
||||
//qDebug() << "up" << evt->pos();
|
||||
checkAndSendEvent(evt->pos(),false);
|
||||
}
|
||||
|
||||
void MainWindow::mouseMoveEvent(QMouseEvent *evt)
|
||||
{
|
||||
//qDebug() << "move" << evt->pos();
|
||||
checkAndSendEvent(evt->pos(),true);
|
||||
|
||||
}
|
||||
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void MainWindow::checkAndSendEvent(QPoint pos, bool down)
|
||||
{
|
||||
QPoint p = pos - QPoint(DISPLAY_X,DISPLAY_Y);
|
||||
if(p.x()<0 || p.y()<0 || p.x() >= DISPLAY_WIDTH || p.y() >= DISPLAY_HEIGHT) return;
|
||||
|
||||
//qDebug() << down << p;
|
||||
|
||||
touch_add_raw_event(p.x(),p.y(),down?TOUCH_DOWN:TOUCH_UP);
|
||||
}
|
||||
|
||||
|
||||
@@ -26,11 +26,15 @@ public:
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent * evt);
|
||||
void mousePressEvent(QMouseEvent* evt);
|
||||
void mouseReleaseEvent(QMouseEvent* evt);
|
||||
void mouseMoveEvent(QMouseEvent* evt);
|
||||
~MainWindow();
|
||||
|
||||
private:
|
||||
//QMutex render_mutex;
|
||||
QImage image;
|
||||
void checkAndSendEvent(QPoint pos, bool down);
|
||||
|
||||
Ui::MainWindow *ui;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user