Sample calls

A typical sequence of hardware library calls is as follows:

    #include <hw/i2c.h>

    i2c_master_funcs_t  masterf;
    i2c_libversion_t    version;
    i2c_status_t        status;
    void *hdl;

    i2c_master_getfuncs(&masterf, sizeof(masterf));

    masterf.version_info(&version);
    if ((version.major != I2CLIB_VERSION_MAJOR) ||
        (version.minor > I2CLIB_VERSION_MINOR))
    {
        /* error */
        ...
    }

    hdl = masterf.init(...);

    masterf.set_bus_speed(hdl, ...);
    masterf.set_slave_addr(hdl, ...);

    status = masterf.send(hdl, ...);
    if (status != I2C_STATUS_DONE) {
        /* error */
        if (!(status & I2C_STATUS_DONE))
            masterf.abort(hdl);
    }

    status = masterf.recv(hdl, ...);
    if (status != I2C_STATUS_DONE) {
        /* error */
        ...
    }

    masterf.fini(hdl);