This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

dynamically re-configure app_button library

Hi

In my application, I use some of the IO pins for a multi-purpose sensor interface, that I would like to be able to configure when the application is running. The interface sometimes counts pulses on an input pin, and sometimes uses the ADC to read from that same pin. The interface has 2 channels, and each of them can be switched between ADC and pulse counting, independent from each other.

To count pulses, I was using the app_button library, and I call APP_BUTTON_INIT at startup, with a default configuration, where both channels use the button library. Or in other words, I have 2 GPIO pins configured as input with internal pull-up, which I feed as argument into the function APP_BUTTON_INIT.

When configuring a channel to use the ADC, I would have to re-configure the button interface, as i now only contains 1 button. This would mean, doing another call to APP_BUTTON_INIT.

Now, from the code I see that this would do a call again to app_timer_create(). Is this going to cause problems when max number of timers is reached? Is there a way of doing some kind of a destruct on that timer before calling APP_BUTTON_INIT again? Or force it to re-use the timer which it previously created? The same remarks for the call to app_gpiote_user_register() in fact.

Or should I copy the app_button library code to my own library and fix it myself?

Related