/* Configure new channel. 
This is the alternative API, which requires the caller to store the mask of used channels. */
uint8_t ppi_add_channel(uint32_t *chan_map, uint32_t eep, uint32_t tep, bool enable)
/* Configure new channel. 
This is the alternative API, which requires the caller to store the mask of used channels. */
uint8_t ppi_add_channel(uint32_t *chan_map, uint32_t eep, uint32_t tep, bool enable)
{
    uint8_t i;
    uint32_t chan_bit;
    for (i = 0, chan_bit = 1; i <= PPI_MAX_PROG_CHANNEL; ++i, chan_bit <<= 1) {
        if (!(chan_bit & *chan_map)) {
            *chan_map |= chan_bit;
            break;
        }
    }
    if (i > PPI_MAX_PROG_CHANNEL) {
        return 0xff;
    }
    ppi_configure_channel(i, eep, tep);
    if (enable) {
        ppi_enable_channels(chan_bit);
    }
    return i;
}