components/esp-cryptoauthlib/cryptoauthlib/lib/hal/hal_uc3_i2c_asf.c
ATCA_STATUS hal_i2c_wake(ATCAIface iface)
{
    ATCAIfaceCfg *cfg = atgetifacecfg(iface);
    int retries = cfg->rx_retries;
    uint32_t bdrt = cfg->atcai2c.baud;
    int status = !TWI_SUCCESS;
    uint8_t data[4];
    twi_package_t packet;

    // TWI chip address to communicate with
    packet.chip = 0x00;
    // TWI address/commands to issue to the other chip (node)
    packet.addr[0] = 0;
    packet.addr[1] = 0;
    packet.addr[2] = 0;
    // Length of the TWI data address segment (1-3 bytes)
    packet.addr_length = 0;
    // Where to find the data to be written
    packet.buffer = (void*)&data[0];
    // How many bytes do we want to write
    packet.length = 1;

    // if not already at 100kHz, change it
    if (bdrt != 100000)
    {
        change_i2c_speed(iface, 100000);
    }

    // Send 0x00 as wake pulse
    twi_master_write(i2c_hal_data[cfg->atcai2c.bus].twi_master_instance, &packet);

    // rounded up to the nearest ms
    atca_delay_ms(((uint32_t)cfg->wake_delay + (1000 - 1)) / 1000);   // wait tWHI + tWLO which is configured based on device type and configuration structure



    // if necessary, revert baud rate to what came in.
    if (bdrt != 100000)
    {
        change_i2c_speed(iface, bdrt);
    }

    packet.chip = cfg->atcai2c.slave_address >> 1;
    packet.buffer         = (void*)data;
    packet.length         = (uint32_t)4;
    while (retries-- > 0 && status != TWI_SUCCESS)
    {
        status = twi_master_read(i2c_hal_data[cfg->atcai2c.bus].twi_master_instance, &packet);
    }
    if (status != TWI_SUCCESS)
    {
        return ATCA_COMM_FAIL;
    }

    return hal_check_wake(data, 4);
}
/** \brief wake up CryptoAuth device using I2C bus
 * \param[in] iface  interface to logical device to wakeup
 * \return ATCA_SUCCESS on success, otherwise an error code.

 */
\brief wake up CryptoAuth device using I2C bus
\param[in] iface  interface to logical device to wakeup
\return ATCA_SUCCESS on success, otherwise an error code.
\ brief wake up CryptoAuth device using I2C bus \ param [ in ] iface interface to logical device to wakeup \ return ATCA_SUCCESS on success otherwise an error code .
ATCA_STATUS hal_i2c_wake(ATCAIface iface)
{
    ATCAIfaceCfg *cfg = atgetifacecfg(iface);
    int retries = cfg->rx_retries;
    uint32_t bdrt = cfg->atcai2c.baud;
    int status = !TWI_SUCCESS;
    uint8_t data[4];
    twi_package_t packet;
    packet.chip = 0x00;
    packet.addr[0] = 0;
    packet.addr[1] = 0;
    packet.addr[2] = 0;
    packet.addr_length = 0;
    packet.buffer = (void*)&data[0];
    packet.length = 1;
    if (bdrt != 100000)
    {
        change_i2c_speed(iface, 100000);
    }
    twi_master_write(i2c_hal_data[cfg->atcai2c.bus].twi_master_instance, &packet);
    atca_delay_ms(((uint32_t)cfg->wake_delay + (1000 - 1)) / 1000);   
    if (bdrt != 100000)
    {
        change_i2c_speed(iface, bdrt);
    }
    packet.chip = cfg->atcai2c.slave_address >> 1;
    packet.buffer         = (void*)data;
    packet.length         = (uint32_t)4;
    while (retries-- > 0 && status != TWI_SUCCESS)
    {
        status = twi_master_read(i2c_hal_data[cfg->atcai2c.bus].twi_master_instance, &packet);
    }
    if (status != TWI_SUCCESS)
    {
        return ATCA_COMM_FAIL;
    }
    return hal_check_wake(data, 4);
}
ATCA_STATUS hal_i2c_wake ( ATCAIface iface ) { ATCAIfaceCfg * cfg = atgetifacecfg ( iface ) ; int retries = cfg -> rx_retries ; uint32_t bdrt = cfg -> atcai2c . baud ; int status = ! TWI_SUCCESS ; uint8_t data [ 4 ] ; twi_package_t packet ; packet . chip = 0x00 ; packet . addr [ 0 ] = 0 ; packet . addr [ 1 ] = 0 ; packet . addr [ 2 ] = 0 ; packet . addr_length = 0 ; packet . buffer = ( void * ) & data [ 0 ] ; packet . length = 1 ; if ( bdrt != 100000 ) { change_i2c_speed ( iface , 100000 ) ; } twi_master_write ( i2c_hal_data [ cfg -> atcai2c . bus ] . twi_master_instance , & packet ) ; atca_delay_ms ( ( ( uint32_t ) cfg -> wake_delay + ( 1000 - 1 ) ) / 1000 ) ; if ( bdrt != 100000 ) { change_i2c_speed ( iface , bdrt ) ; } packet . chip = cfg -> atcai2c . slave_address >> 1 ; packet . buffer = ( void * ) data ; packet . length = ( uint32_t ) 4 ; while ( retries -- > 0 && status != TWI_SUCCESS ) { status = twi_master_read ( i2c_hal_data [ cfg -> atcai2c . bus ] . twi_master_instance , & packet ) ; } if ( status != TWI_SUCCESS ) { return ATCA_COMM_FAIL ; } return hal_check_wake ( data , 4 ) ; }
\brief wake up CryptoAuth device using I2C bus
 \param[in] iface  interface to logical device to wakeup
 \return ATCA_SUCCESS on success, otherwise an error code.
\ brief wake up CryptoAuth device using I2C bus \ param [ in ] iface interface to logical device to wakeup \ return ATCA_SUCCESS on success otherwise an error code .
// TWI chip address to communicate with // TWI address/commands to issue to the other chip (node) // Length of the TWI data address segment (1-3 bytes) // Where to find the data to be written // How many bytes do we want to write // if not already at 100kHz, change it // Send 0x00 as wake pulse // rounded up to the nearest ms // wait tWHI + tWLO which is configured based on device type and configuration structure // if necessary, revert baud rate to what came in.