/* Computes a cycle count for a given time in nanoseconds.  */
static uint32_t LPI2C_GetCyclesForWidth(uint32_t sourceClock_Hz, uint32_t width_ns, uint32_t maxCycles, uint32_t prescaler)
/* Computes a cycle count for a given time in nanoseconds.  */
static uint32_t LPI2C_GetCyclesForWidth(uint32_t sourceClock_Hz, uint32_t width_ns, uint32_t maxCycles, uint32_t prescaler)
{
    assert(sourceClock_Hz > 0U);
    assert(prescaler > 0U);
    uint32_t busCycle_ns = 1000000U / (sourceClock_Hz / prescaler / 1000U);
    uint32_t cycles      = 0U;
    while ((((cycles + 1U) * busCycle_ns) < width_ns) && (cycles + 1U < maxCycles))
    {
        ++cycles;
    }
    if ((cycles == 0U) && (busCycle_ns <= (width_ns * 10U)))
    {
        cycles = 1U;
    }
    return cycles;
}