xmos / lib_i2c

I²C library
Other
3 stars 25 forks source link

How to use lib_i2c when writing an application in C, as opposed to xC? #93

Closed mfreeborn closed 7 months ago

mfreeborn commented 7 months ago

I read that new applications should favour being written in C/C++, rather than xC, going forwards.

However, lib_i2c only seems to be available for xC projects (most of the code is hidden behind an XC define).

How can I convert the following example in the docs to compile from a C file (specifically the i2c bits; the ports are straightfowards to use)?

port p_scl = XS1_PORT_1E;
port p_sda = XS1_PORT_1F;
int main(void) {
    i2c_master_if i2c[1];
    static const uint8_t target_device_addr = 0x3c;
    par {
        i2c_master(i2c, 1, p_scl, p_sda, 100);
        my_application(i2c[0], target_device_addr);
    }
    return 0;
}
mfreeborn commented 7 months ago

Closing as no longer relevant to me having now updated all deps.

ed-xmos commented 7 months ago

Out of interest I did something like this a way back as an experiment. It did work for the master components.

https://github.com/ed-xmos/lib_i2c/blob/5c4dd35d142e89ce2bf090237351a2c8cda1e5ba/lib_i2c/src/i2c_master_ai_wrapper.xc

But as you say, you can also use these versions https://github.com/xmos/fwk_io/tree/develop/modules/i2c