Rationale for enable/disable function v.s. change_state?

Viewed 665

I am implementing a driver for an accelerometer where I have to implement functions such as enable/disable low-power mode.

I can either write:

lis2dh12_low_power_enable();
lis2dh12_low_power_disable();

or:

lis2dh12_low_power_change_state(boolean_t enable);

The former solution is generally more readable, but it may creates extra code such as in this specific case:

void foo(boolean_t status) {
    if (status)
        lis2dh12_low_power_enable();
    else
        lis2dh12_low_power_disable();
}

Is there any rationale (MISRA like rules) for implementing such typical enable / disable functions?

3 Answers
Related