XC, structs, and ports

Technical questions regarding the XTC tools and programming with XMOS.
User avatar
ahenshaw
Experienced Member
Posts: 96
Joined: Mon Mar 22, 2010 8:55 pm

XC, structs, and ports

Post by ahenshaw »

I'm trying to abstract my communications to an I2C device, so I'd like to create a structure that combines the I2C comm ports and some state variables for the device. So, the standard way for me to use the I2C lib is to declare an r_i2c instance, like so:

Code: Select all

struct r_i2c mpu = {
    XS1_PORT_1P,
    XS1_PORT_1O,
};
That's fine, but how do I declare the equivalent where the r_i2c structure is a field of my super struct? Naively, I tried this:

Code: Select all

struct IMU {
    struct r_i2c i2c;
    int GYRO_XOUT_OFFSET ;
    int GYRO_YOUT_OFFSET ;
    int GYRO_ZOUT_OFFSET ;
};
That seems to legal in XC, but it won't do what I'm hoping. I can't see how I would assign the mpu instance to the i2c field of the IMU struct.

I understand that there are limits with resources and structs in XC. Am I going to be running into that problem?


User avatar
ahenshaw
Experienced Member
Posts: 96
Joined: Mon Mar 22, 2010 8:55 pm

Post by ahenshaw »

I believe that I fixed it -- just needed to make the initializer at the global level.