Example #1
0
int main(int argc, char **argv)
{
	if (argc != 2) {
		printf("need i2c dev\n");
		return 1;
	}

	int fd = i2cdev_open(argv[1], O_RDWR);
	if (fd <= 0) {
		printf("open failed\n");
		return 2;
	}

#ifdef TEST_RX8010
	write_reg(fd, ADDR_RX8010, REG_RX8010, 0x00);
	read_reg(fd, ADDR_RX8010, REG_RX8010);
#endif

#ifdef TEST_TMDS181
	printf("====== TMDS181 TX ==========\n");
	for (uint8_t i = 0; i < 9; i++)
		read_reg(fd, ADDR_TMDS181_TX, i);

	printf("====== TMDS181 RX ==========\n");
	for (uint8_t i = 0; i < 9; i++)
		read_reg(fd, ADDR_TMDS181_RX, i);
#endif

	i2cdev_close(fd);

	return 0;
}
Example #2
0
int main(int argc, char **argv)
{
	int fd = -1;
	int idx = 0;
	int eq, fg, sw;
	uint8_t data;
	int mode = MODE_INVALID;

	printf("===== PI3EQX8908A i2c configuration =====\n");

	if (argc == 2 && !strcmp(argv[1], "read")) {
		mode = MODE_READ;
		goto START;
	}

	if (argc != 4) {
		print_usage();
		return -2;
	}
	mode = MODE_WRITE;

	eq = atoi(argv[1]);
	fg = atoi(argv[2]);
	sw = atoi(argv[3]);
	if (eq < 0 || eq > 15 || fg < 0 || fg > 3 || sw < 0 || sw > 1) {
		print_usage();
		return -3;
	}
	data = (uint8_t)((eq << 4) | (fg << 2) | sw);

	printf("EQ: %d\n", eq);
	printf("FG: %d\n", fg);
	printf("SW: %d\n", sw);
	printf("data = 0x%02x\n\n", data);

START:
	fd = i2cdev_open(I2CDEV_PATH, O_RDWR | O_SYNC);
	if (fd < 0) {
		printf("i2cdev_open failed: %s\n", strerror(errno));
		return -1;
	}

	print_register(fd);

	if (mode == MODE_WRITE) {
		for (idx = IDX_A0; idx <= IDX_B3; idx++)
			write_register(fd, idx, data);
		print_register(fd);
	}

	i2cdev_close(fd);

	return 0;
}
Example #3
0
int i2ccmd_get(FAR struct i2ctool_s *i2ctool, int argc, FAR char **argv)
{
  FAR char *ptr;
  uint16_t result;
  uint8_t regaddr;
  long repititions;
  int nargs;
  int argndx;
  int ret;
  int fd;
  int i;

  /* Parse any command line arguments */

  for (argndx = 1; argndx < argc; )
    {
      /* Break out of the look when the last option has been parsed */

      ptr = argv[argndx];
      if (*ptr != '-')
        {
          break;
        }

      /* Otherwise, check for common options */

      nargs = common_args(i2ctool, &argv[argndx]);
      if (nargs < 0)
        {
          return ERROR;
        }

      argndx += nargs;
    }

  /* There may be one more thing on the command line:  The repitition
   * count.
   */

  repititions = 1;
  if (argndx < argc)
    {
      repititions = strtol(argv[argndx], NULL, 16);
      if (repititions < 1)
        {
          i2ctool_printf(i2ctool, g_i2cargrange, argv[0]);
          return ERROR;
        }

      argndx++;
    }

  if (argndx != argc)
    {
      i2ctool_printf(i2ctool, g_i2ctoomanyargs, argv[0]);
      return ERROR;
    }

  /* Get a handle to the I2C bus */

  fd = i2cdev_open(i2ctool->bus);
  if (fd < 0)
    {
       i2ctool_printf(i2ctool, "Failed to get bus %d\n", i2ctool->bus);
       return ERROR;
    }

  /* Loop for the requested number of repititions */

  regaddr = i2ctool->regaddr;
  ret = OK;

  for (i = 0; i < repititions; i++)
    {
      /* Read from the I2C bus */

      ret = i2ctool_get(i2ctool, fd, regaddr, &result);

      /* Display the result */

      if (ret == OK)
        {
          i2ctool_printf(i2ctool, "READ Bus: %d Addr: %02x Subaddr: %02x Value: ",
                         i2ctool->bus, i2ctool->addr, regaddr);

          if (i2ctool->width == 8)
            {
              i2ctool_printf(i2ctool, "%02x\n", result);
            }
          else
            {
              i2ctool_printf(i2ctool, "%04x\n", result);
            }
        }
      else
        {
          i2ctool_printf(i2ctool, g_i2cxfrerror, argv[0], -ret);
          break;
        }

      /* Auto-increment the address if so configured */

      if (i2ctool->autoincr)
        {
          regaddr++;
        }
    }

  (void)close(fd);
  return ret;
}