components/esp-cryptoauthlib/cryptoauthlib/lib/hal/hal_linux_i2c_userspace.c
ATCA_STATUS hal_i2c_wake(ATCAIface iface)
{
    ATCAIfaceCfg *cfg = atgetifacecfg(iface);
    ATCAI2CMaster_t * hal_data = (ATCAI2CMaster_t*)atgetifacehaldat(iface);
    int f_i2c;  // I2C file descriptor
    uint8_t data[4];
    uint8_t dummy_byte = 0x00;

    // Initiate I2C communication
    if ( (f_i2c = open(hal_data->i2c_file, O_RDWR)) < 0)
    {
        return ATCA_COMM_FAIL;
    }

    // Send the wake by writing to an address of 0x00
    // Create wake up pulse by sending a slave address 0f 0x00.
    // This slave address is sent to device by using a dummy write command.
    if (ioctl(f_i2c, I2C_SLAVE, 0x00) < 0)
    {
        close(f_i2c);
        return ATCA_COMM_FAIL;
    }

    // Dummy Write
    if (write(f_i2c, &dummy_byte, 1) < 0)
    {
        // This command will always return NACK.
        // So, the return code is being ignored.
    }

    atca_delay_us(cfg->wake_delay); // wait tWHI + tWLO which is configured based on device type and configuration structure

    // Set Slave Address
    if (ioctl(f_i2c, I2C_SLAVE, cfg->atcai2c.slave_address >> 1) < 0)
    {
        close(f_i2c);
        return ATCA_COMM_FAIL;
    }

    // Receive data
    if (read(f_i2c, data, 4) != 4)
    {
        close(f_i2c);
        return ATCA_RX_NO_RESPONSE;
    }

    close(f_i2c);
    // if necessary, revert baud rate to what came in.

    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);
    ATCAI2CMaster_t * hal_data = (ATCAI2CMaster_t*)atgetifacehaldat(iface);
    int f_i2c;  
    uint8_t data[4];
    uint8_t dummy_byte = 0x00;
    if ( (f_i2c = open(hal_data->i2c_file, O_RDWR)) < 0)
    {
        return ATCA_COMM_FAIL;
    }
    if (ioctl(f_i2c, I2C_SLAVE, 0x00) < 0)
    {
        close(f_i2c);
        return ATCA_COMM_FAIL;
    }
    if (write(f_i2c, &dummy_byte, 1) < 0)
    {
    }
    atca_delay_us(cfg->wake_delay); 
    if (ioctl(f_i2c, I2C_SLAVE, cfg->atcai2c.slave_address >> 1) < 0)
    {
        close(f_i2c);
        return ATCA_COMM_FAIL;
    }
    if (read(f_i2c, data, 4) != 4)
    {
        close(f_i2c);
        return ATCA_RX_NO_RESPONSE;
    }
    close(f_i2c);
    return hal_check_wake(data, 4);
}
ATCA_STATUS hal_i2c_wake ( ATCAIface iface ) { ATCAIfaceCfg * cfg = atgetifacecfg ( iface ) ; ATCAI2CMaster_t * hal_data = ( ATCAI2CMaster_t * ) atgetifacehaldat ( iface ) ; int f_i2c ; uint8_t data [ 4 ] ; uint8_t dummy_byte = 0x00 ; if ( ( f_i2c = open ( hal_data -> i2c_file , O_RDWR ) ) < 0 ) { return ATCA_COMM_FAIL ; } if ( ioctl ( f_i2c , I2C_SLAVE , 0x00 ) < 0 ) { close ( f_i2c ) ; return ATCA_COMM_FAIL ; } if ( write ( f_i2c , & dummy_byte , 1 ) < 0 ) { } atca_delay_us ( cfg -> wake_delay ) ; if ( ioctl ( f_i2c , I2C_SLAVE , cfg -> atcai2c . slave_address >> 1 ) < 0 ) { close ( f_i2c ) ; return ATCA_COMM_FAIL ; } if ( read ( f_i2c , data , 4 ) != 4 ) { close ( f_i2c ) ; return ATCA_RX_NO_RESPONSE ; } close ( f_i2c ) ; 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 .
// I2C file descriptor // Initiate I2C communication // Send the wake by writing to an address of 0x00 // Create wake up pulse by sending a slave address 0f 0x00. // This slave address is sent to device by using a dummy write command. // Dummy Write // This command will always return NACK. // So, the return code is being ignored. // wait tWHI + tWLO which is configured based on device type and configuration structure // Set Slave Address // Receive data // if necessary, revert baud rate to what came in.