Skip to content

Improve efficiency of NRF52TouchSensor interrupt handler #60

@kevinjwalters

Description

@kevinjwalters

The interrupt handler can be made more efficient in the NRF52TouchSensor class.

Major improvement

The innocuous looking Evt with default construction gets initialised with a timestamp using system_timer_current_time_us() which is far more heavyweight than it sounds.

From https://github.com/lancaster-university/codal-nrf52/blob/master/source/NRF52TouchSensor.cpp#L33-L39

static void touch_sense_irq(uint16_t mask)
{
    if (instance) {
        Event evt;
        instance->onSampleEvent(evt);
    }
}

This event isn't used by onSampleEvent() so could be replaced with something more efficient like.

        Event unused_evt(0, 0,0, CREATE_ONLY);
        instance->onSampleEvent(unused_evt);

I've tested that and it improves lancaster-university/codal-microbit-v2#475 (comment)

Minor improvement

Is this disable/enable of interrupts required?

// Reset the timer, and enable the pin input event, unless we're leaving a timeslot for a single channel to charge.
target_disable_irq();
timer.timer->TASKS_CLEAR = 1;
if (channel >= 0)
NRF_GPIOTE->CONFIG[NRF52_TOUCH_SENSOR_GPIOTE_CHANNEL] = 0x00010001 | (buttons[channel]->_pin.name << 8);
target_enable_irq();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions