I would not call your code stupid at all, quite the opposite! Thank you for all your time and effort!
I updated my code based on your help and all is working well now. I added a third button that just increments the number by one instead of counting up continuously. Thank you!
uint8_t tag;
static uint8_t toggle_lock = 0;
uint16_t toggle_state = 0;
uint16_t toggle_state2 = 0;
uint16_t toggle_state3 = 0;
uint16_t display_list_size = 0;
void TFT_touch(void)
{
if(EVE_busy()) /* is EVE still processing the last display list? */
{
return;
}
display_list_size = EVE_memRead16(REG_CMD_DL); /* debug-information, get the size of the last generated display-list */
tag = EVE_memRead8(REG_TOUCH_TAG); /* read the value for the first touch point */
uint32_t touchtest = EVE_memRead32(REG_TOUCH_RAW_XY);
switch(tag)
{
case 0:
if(touchtest == 0xffffffff) /* display is no longer touched */
{
toggle_lock = 0;
}
break;
case 10: /* use button on top as on/off radio-switch */
if(toggle_lock == 0)
{
toggle_lock = 42;
if(toggle_state == 0)
{
toggle_state = EVE_OPT_FLAT;
}
else
{
toggle_state = 0;
}
}
break;
case 11: /* use button on top as on/off radio-switch */
if(toggle_lock == 0)
{
toggle_lock = 42;
if(toggle_state2 == 0)
{
toggle_state2 = EVE_OPT_FLAT ;
}
else
{
toggle_state2 = 0;
}
}
break;
case 12: /* use button on top as on/off radio-switch */
if(toggle_lock == 0)
{
toggle_lock = 42;
if(toggle_state3 == 0)
{
toggle_state3 = EVE_OPT_FLAT ;
}
else
{
toggle_state3 = 0;
}
}
break;
}
}
/*
dynamic portion of display-handling, meant to be called every 20ms or more
*/
int basicnumber = 0;
int basicnumber2 = 0;
int basicnumber3 = 0;
void TFT_display(void)
{
if(tft_active != 0)
{
#if defined (EVE_DMA)
uint16_t cmd_fifo_size;
cmd_fifo_size = EVE_dma_buffer_index*4; /* without DMA there is no way to tell how many bytes are written to the cmd-fifo */
#endif
EVE_start_cmd_burst(); /* start writing to the cmd-fifo as one stream of bytes, only sending the address once */
EVE_cmd_dl_burst(CMD_DLSTART); /* start the display list */
EVE_cmd_dl_burst(DL_CLEAR_RGB | BLACK); /* set the default clear color to white */
EVE_cmd_dl_burst(DL_CLEAR | CLR_COL | CLR_STN | CLR_TAG); /* clear the screen - this and the previous prevent artifacts between lists, Attributes are the color, stencil and tag buffers */
EVE_cmd_dl_burst(TAG(0));
EVE_cmd_append_burst(MEM_DL_STATIC, num_dl_static); /* insert static part of display-list from copy in gfx-mem */
/* display a button */
EVE_cmd_dl_burst(DL_COLOR_RGB | GREEN);
EVE_cmd_fgcolor_burst(0x00c0c0c0); /* some grey */
EVE_cmd_dl_burst(TAG(10)); /* assign tag-value '10' to the button that follows */
EVE_cmd_button_burst(50,120,120,70, 28, toggle_state,"Touch!");
EVE_cmd_dl_burst(TAG(0)); /* no touch */
if(toggle_state != 0)
{
basicnumber++;
}
EVE_cmd_dl_burst(DL_COLOR_RGB | RED);
EVE_cmd_fgcolor_burst(0x00c0c0c0); /* some grey */
EVE_cmd_dl_burst(TAG(11)); /* assign tag-value '10' to the button that follows */
EVE_cmd_button_burst(250,120,120,70, 28, toggle_state2,"Touch2!");
EVE_cmd_dl_burst(TAG(0)); /* no touch */
if(toggle_state2 != 0)
{
basicnumber2++;
}
EVE_cmd_dl_burst(DL_COLOR_RGB | PURPLE);
EVE_cmd_fgcolor_burst(0x00c0c0c0); /* some grey */
EVE_cmd_dl_burst(TAG(12)); /* assign tag-value '10' to the button that follows */
EVE_cmd_button_burst(450,120,120,70, 28, toggle_state3,"Touch3!");
EVE_cmd_dl_burst(TAG(0)); /* no touch */
if(toggle_state3 != 0)
{
basicnumber3++;
toggle_state3 = 0;
}
EVE_cmd_dl_burst(DL_COLOR_RGB | GREEN);
EVE_cmd_number_burst(155, 200, 25, EVE_OPT_RIGHTX|5, basicnumber);
EVE_cmd_dl_burst(DL_COLOR_RGB | RED);
EVE_cmd_number_burst(355, 200, 25, EVE_OPT_RIGHTX|5, basicnumber2);
EVE_cmd_dl_burst(DL_COLOR_RGB | PURPLE);
EVE_cmd_number_burst(555, 200, 25, EVE_OPT_RIGHTX|5, basicnumber3);
EVE_cmd_dl_burst(DL_DISPLAY); /* instruct the graphics processor to show the list */
EVE_cmd_dl_burst(CMD_SWAP); /* make this list active */
EVE_end_cmd_burst(); /* stop writing to the cmd-fifo, the cmd-FIFO will be executed automatically after this or when DMA is done */
}
}