7 years, 8 months ago.

Optimized out, or something else ?

Here's one where I'd like to see the assembly code. There's a few alternate patterns shown below. I'm thinking that the online compiler may have optimized out my touch-wait loop, but can't readily prove it. Any thoughts?

The basic notion is that some screen updates are occurring, and the code 'pauses' if you touch/hold the screen.

while (1) {
    DoSomeWork();
    volatile TouchCode_t tc = lcd.TouchCode();    // with or without 'static' and 'volatile' makes no diff.
    
    while (tc == touch || tc == held) {

    #if 1       // This fails: on the first touch, it never exits the while
        tc = lcd.TouchCode();   // returns 0:no_touch, 1:touch, 2:held, 3:release
        //wait_us(0);   // Adding this makes it work, even if the wait is 0 or 1

    #elif 0     // This works: but includes the useless committment of a digital output
        tc = lcd.TouchCode();
        DigitalOut led(LED1);
        led = !led;

    #else       // This works: but includes the undesired printf
        tc = lcd.TouchCode();   // returns 0:no_touch, 1:touch, 2:held, 3:release
        pc.printf("tc: %d\r", tc);
    #endif

    }
}

1 Answer

7 years, 8 months ago.

Hello,

I don't know how lcd.TouchCode() function works, but I think it needs some wait/delay statements so that the data(gained from the lcd) can be ready when you want to call lcd.TouchCode() again.

Although I believe mbed compiler optimized some parts of your code, the touch-wait-loop may NOT have been optimized out.