The application in our case is that we would like to read specific camera registers (I2C). Is this possible via Libargus?
Hi,
You can read a value of camera sensor register using i2c-tools package :
- Check if the sensor is detected in the i2c bus
i2cdetect -r -y <I2C_BUS>
- If you see that the slave address of your sensor appear in the i2c bus, you can get a register value by using the command line below
i2cset -f -y <I2C_BUS> <I2C_SENSOR_SLAVE_ADDR> <I2C_REG_ADDR> ; i2cget -f -y <I2C_BUS> <I2C_SENSOR_SLAVE_ADDR>
This should output the register value
If you want to use it directly from a C/C++ app you have the following code as a reference
#include <fcntl.h>
#include <linux/i2c-dev.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <stdio.h>
#include <stdint.h>
int main() {
const char* i2cDevice = "/dev/i2c-0"; // Specify the correct I2C device file
int address = 0x50; // Replace with the sensor's actual I2C address
int registerAddress = 0x10; // Replace with the register address you want to read
// Open the I2C device
int file = open(i2cDevice, O_RDWR);
if (file < 0) {
perror("Failed to open the I2C device.");
return 1;
}
// Set the I2C slave address
if (ioctl(file, I2C_SLAVE, address) < 0) {
perror("Failed to set I2C slave address.");
close(file);
return 1;
}
// Send the register address to read from
if (write(file, ®isterAddress, sizeof(registerAddress)) != sizeof(registerAddress)) {
perror("Failed to write register address.");
close(file);
return 1;
}
// Read the register value
uint8_t registerValue;
if (read(file, ®isterValue, sizeof(registerValue)) != sizeof(registerValue)) {
perror("Failed to read register value.");
close(file);
return 1;
}
// Print the register value
printf("Register 0x%02X value: 0x%02X\n", registerAddress, registerValue);
// Close the I2C device
close(file);
return 0;
}
And btw LibArgus is an API to capture camera streaming from a camera module that output RAW data, this API use Jetson’s ISP for debayering and ISP’s stuff so the output will be in NV12 format.
I also recommand to implement read_i2c_reg function in your sensor driver, this latter can be as the one below
/*
* ds3231_read_reg() - read a register value from the DS3231 RTC
*
* @dev: pointer to the device structure
* @addr: the register address to read from
* @val: pointer to store the value read from the register
*
* Return: 0 on success, negative error code on failure
*/
static int ds3231_read_reg(struct device *dev, u16 addr, u32 *val)
{
struct ds3231 *priv = dev_get_drvdata(dev);
int err;
/* Read the value from the register at the specified address */
err = regmap_read(priv->regmap, addr, val);
dev_info(dev, "%s:i2c read data, 0x%x = 0x%x", __func__, addr, *val);
if (err)
dev_err(dev, "%s:i2c read failed, 0x%x\n", __func__, addr);
/* Delay before the next I2C command to avoid overloading the bus */
usleep_range(100, 110);
return err;
}
You can also have many references in nvidia image sensors drivers from public sources
See the path :
/sources/drivers/media/i2c/
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.