targets/TARGET_Cypress/TARGET_PSOC6/i2c_api.c
static cy_en_sysclk_status_t i2c_init_clock(i2c_obj_t *obj, uint32_t speed)
{
    I2cDividerInfo *p_div = NULL;
    cy_en_sysclk_status_t status = CY_SYSCLK_INVALID_STATE;
    I2cDividerType divider = select_divider(speed);

    if (divider == I2C_INVALID_DIVIDER) {
        error("I2C: required speed/frequency is out of valid range.");
    }

    if (allocate_divider(divider) < 0) {
        error("I2C: cannot allocate clock divider.");
    }

    obj->divider = divider;
    p_div = &i2c_dividers[divider];

    status = Cy_SysClk_PeriphAssignDivider(obj->clock, p_div->div_type, p_div->div_num);
    if (status != CY_SYSCLK_SUCCESS) {
        error("I2C: cannot assign clock divider.");
    }

    /* Set desired speed/frequency */
    obj->actual_speed = Cy_SCB_I2C_SetDataRate(obj->base, speed, p_div->clk_frequency);
    return (obj->actual_speed != 0) ? CY_SYSCLK_SUCCESS : CY_SYSCLK_BAD_PARAM;
}
/*
 * Initializes i2c clock for the required speed
 */
Initializes i2c clock for the required speed
Initializes i2c clock for the required speed
static cy_en_sysclk_status_t i2c_init_clock(i2c_obj_t *obj, uint32_t speed)
{
    I2cDividerInfo *p_div = NULL;
    cy_en_sysclk_status_t status = CY_SYSCLK_INVALID_STATE;
    I2cDividerType divider = select_divider(speed);
    if (divider == I2C_INVALID_DIVIDER) {
        error("I2C: required speed/frequency is out of valid range.");
    }
    if (allocate_divider(divider) < 0) {
        error("I2C: cannot allocate clock divider.");
    }
    obj->divider = divider;
    p_div = &i2c_dividers[divider];
    status = Cy_SysClk_PeriphAssignDivider(obj->clock, p_div->div_type, p_div->div_num);
    if (status != CY_SYSCLK_SUCCESS) {
        error("I2C: cannot assign clock divider.");
    }
    obj->actual_speed = Cy_SCB_I2C_SetDataRate(obj->base, speed, p_div->clk_frequency);
    return (obj->actual_speed != 0) ? CY_SYSCLK_SUCCESS : CY_SYSCLK_BAD_PARAM;
}
static cy_en_sysclk_status_t i2c_init_clock ( i2c_obj_t * obj , uint32_t speed ) { I2cDividerInfo * p_div = NULL ; cy_en_sysclk_status_t status = CY_SYSCLK_INVALID_STATE ; I2cDividerType divider = select_divider ( speed ) ; if ( divider == I2C_INVALID_DIVIDER ) { error ( " " ) ; } if ( allocate_divider ( divider ) < 0 ) { error ( " " ) ; } obj -> divider = divider ; p_div = & i2c_dividers [ divider ] ; status = Cy_SysClk_PeriphAssignDivider ( obj -> clock , p_div -> div_type , p_div -> div_num ) ; if ( status != CY_SYSCLK_SUCCESS ) { error ( " " ) ; } obj -> actual_speed = Cy_SCB_I2C_SetDataRate ( obj -> base , speed , p_div -> clk_frequency ) ; return ( obj -> actual_speed != 0 ) ? CY_SYSCLK_SUCCESS : CY_SYSCLK_BAD_PARAM ; }
Initializes i2c clock for the required speed
Initializes i2c clock for the required speed
/* Set desired speed/frequency */