To probe my i2c buses, I run a Debian docker command and add the libi2c-dev and i2c-tools tookits.
$ docker run -it --privileged torizon/debian:$CT_TAG_DEBIAN /bin/bash
“apt update && apt install --fix-missing libi2c-dev i2c-tools -y”
On the “standard i2c” device which maps to the /dev/i2c-17 in user space.
root@colibri-imx8x-06800883:/home/torizon# i2cdetect -l
i2c-17 unknown 5a810000.i2c N/A
i2c-18 unknown 56226000.i2c N/A
i2c-16 unknown 5a800000.i2c N/A
root@1622d8fba750:/# i2cdetect -y 17
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: – – – – – – – – – – 0d – –
10: – – – – – – – – – – – – – – – –
20: – – – – – – – – – – – – – – – –
30: – – – – – – – – – – – – – – – –
40: – – – – – – – – – – – – – – – –
50: – – – – – – – – – – – – – – – –
60: – – – – – – – – UU – – – – – – –
70: – – – – – – – –
The device is 0x0d ready to register to. So back to Microsoft Studio with the Torizon extensions.
The thing I need to know I think, is how to set things up so that Studio '19 on using the extensions runs docker with the --privileged flag so it can see the devices.
The tutorial “Install Debian Packages on Torizon Container” doesnt explain how this can be achieved. I.e. how the Torizon container is set up in Studio, so that it compiles and runs in the docker container. All day so far, I have looked around and can’t see how this is done.
I tried creating a custom container
https://developer.toradex.com/knowledge-base/modifying-our-based-container-images
colibri-imx8x-06800883:~$ cat Dockerfile
FROM torizon/debian:$CT_TAG_DEBIAN
RUN apt update -y && apt install -y i2c-tools -y && apt clean && apt autoremove && rm -rf /var/lib/apt/lists/*
colibri-imx8x-06800883:~$ docker build .
Sending build context to Docker daemon 19.46kB
Step 1/2 : FROM torizon/debian:$CT_TAG_DEBIAN
invalid reference format
colibri-imx8x-06800883:~$
That didn’t work either…
The technical note C/C++ Development and Debugging on Torizon Using Visual Studio doesn’t really help me.
I know I need to modify the containers somehow, as I think I need to add ‘libi2c-dev.h’ at least, but how!!!
If you know please can you signpost me to it !!
Regards
Richard
— Here is my C++ code to access my battery on i2c-17 -------------------------
I have a simple program (two snippets shown below)
a) main
int main(void)
{
printf("\nSmart Battery Interface Tests %i\n\n", VERSION);
Smart_battery_interface battery(17);
};
b) which sets up the battery
Smart_battery_interface::Smart_battery_interface(uint8_t bus_number) : bus_number(bus_number)
{
device_file = invalid_device_file;
}
Smart_battery_interface::~Smart_battery_interface(void)
{
terminate();
}
bool Smart_battery_interface::initialise(void)
{
bool result = false;
char device_filename[FILENAME_MAX];
snprintf(device_filename, sizeof(device_filename), “/dev/i2c-%d”, bus_number);
printf(“filename is %s\n”, device_filename);
device_file = open(device_filename, O_RDWR);
printf(“device file came back %i\n”, device_file);
if (0 > device_file)
{
printf("Failed to open I2C bus number /dev/i2c-%d\n", bus_number);
printf("Failed to open I2C device_file %s\n", device_filename);
}
else if (0 > ioctl(device_file, I2C_SLAVE, smart_battery_address))
{
printf("ioctl of smart battery I2C_SLAVE address 0x%02X failed...", smart_battery_address);
terminate();
}
else
{
result = true;
}
return result;
}
Which when it runs sends this out to the Linux window
Smart Battery Interface Tests 1
filename is /dev/i2c-17
device file came back -1
Failed to open I2C bus number /dev/i2c-17
Failed to open I2C device_file /dev/i2c-17
Error initialising smart battery interface