int rtc_read(unsigned char address)
{
    int value = -1;
    unsigned char buf[1];

    i2c_begin();

    buf[0] = address;

    /* send read command */
    if (i2c_write(RTC_DEV_READ,buf,1) >= 0)
    {
        i2c_start();
        i2c_outb(RTC_DEV_READ);
        if (i2c_getack())
        {
            value = i2c_inb(1);
        }
    }

    i2c_stop();

    i2c_end();
    return value;
}
int rtc_read_multiple(unsigned char address, unsigned char *buf, int numbytes)
{
    int ret = 0;
    unsigned char obuf[1];
    int i;

    i2c_begin();

    obuf[0] = address;

    /* send read command */
    if (i2c_write(RTC_DEV_READ, obuf, 1) >= 0)
    {
        i2c_start();
        i2c_outb(RTC_DEV_READ);
        if (i2c_getack())
        {
            for(i = 0; i < numbytes-1; i++)
                buf[i] = i2c_inb(0);

            buf[i] = i2c_inb(1);
        }
        else
        {
            ret = -1;
        }
    }

    i2c_stop();

    i2c_end();
    return ret;
}
void tcs34725::clearInterrupt(void) {
  int res;
  res = i2c_begin(i2c_dev_name);
  
  if (res < 0)
    return;

  if (i2c_smbus_write_byte(fd, 0x66) < 0){
    i2c_end();
    perror(__FUNCTION__);
	 return;
  }

  i2c_end();

}
Exemple #4
0
int dac_volume(unsigned int left, unsigned int right, bool deemph)
{
    int ret = 0;
    unsigned char buf[3];

    i2c_begin();

    if (left > 0x38)
        left = 0x38;
    if (right > 0x38)
        right = 0x38;

    buf[0] = DAC_REG_WRITE | DAC_AVOL;
    buf[1] = (left & 0x3f) | (deemph ? 0x40 : 0);
    buf[2] = right & 0x3f;

    /* send write command */
    if (i2c_write(DAC_DEV_WRITE,buf,3))
    {
        ret = -1;
    }

    i2c_end();
    return ret;
}
static void i2c_led_write(uint8_t addr, uint8_t data)
{
    i2c_start();
    i2c_send_raw(I2C_LED_ADDRESS << 1 | I2C_WRITE);
    i2c_send_raw(addr);
    i2c_send_raw(data);
    i2c_end();
}
void tcs34725::write8 (uint8_t reg, uint8_t value)
{
  int res;
  res = i2c_begin(i2c_dev_name);
  
  if (res < 0)
    return;

  if (i2c_smbus_write_byte_data(fd, TCS34725_COMMAND_BIT | reg, value) < 0) {
    i2c_end();
    perror(__FUNCTION__);
	 return;
  }

  i2c_end();

}
Exemple #7
0
void
real_init_i2c()
{
  i2c_start();
  i2c_write(0x4e);
  i2c_write(0x03);
  i2c_write(0x00);
  i2c_end();
}
Exemple #8
0
void
i2c_config(unsigned char value)
{
  i2c_start();
  i2c_write(0x4e);
  i2c_write(0x01);
  i2c_write(value);
  i2c_end();
}
Exemple #9
0
/**
 * Обработчик окончания приёма/передачи ведущим.
 */
static void i2c_m_end(void)
{
    // Обозначим конец передачи.
    i2c_end();
    
    // Если не была инициирована ещё одна передача.
    if(!_i2c_state.has_transfer){
        // Пошлём стоп.
        i2c_do_stop();
    }
}
Exemple #10
0
void dac_init(void)
{
    unsigned char buf[2];

    i2c_begin();

    buf[0] = DAC_REG_WRITE | DAC_SR_REG;
    buf[1] = 0x07;

    /* send write command */
    i2c_write(DAC_DEV_WRITE,buf,2);
    i2c_end();
}
uint8_t tcs34725::read8(uint8_t reg)
{
  int res;

  res = i2c_begin(i2c_dev_name);
  
  if (res < 0)
    return -1;

  /* return neg value if error or byte (0 - 0xff) */
  res = i2c_smbus_read_byte_data(fd, TCS34725_COMMAND_BIT | reg);

  if(res < 0) {
    i2c_end();
    perror(__FUNCTION__);
	 return (uint8_t) -1;
  }else{
    return (uint8_t) res;
  }
  
  i2c_end();

}
int nmi_i2c_write(unsigned char adr, unsigned char *b, unsigned long sz)
{
	int i;

	i2c_begin();

	i2c_write_byte((adr << 1));
	for(i = 0; i < sz; i++) {
		i2c_write_byte(b[i]);
	}

	i2c_end();
	return 1;
}
int nmi_i2c_read(unsigned char adr, unsigned char *b, unsigned long sz)
{
	int i;

	i2c_begin();
	i2c_write_byte((adr << 1)|0x1);

	for(i = 0; i < sz; i++) {
	    b[i] = i2c_read_byte();	    
		
	    if(i == sz-1) 
			i2c_write_ask(1);	
	    else  	           
			i2c_write_ask(0);
	}
 
	i2c_end();
	return 1;
}
int rtc_write(unsigned char address, unsigned char value)
{
    int ret = 0;
    unsigned char buf[2];

    i2c_begin();

    buf[0] = address;
    buf[1] = value;

    /* send run command */
    if (i2c_write(RTC_DEV_WRITE,buf,2))
    {
        ret = -1;
    }

    i2c_end();
    return ret;
}
Exemple #15
0
/**
 * Обработчик окончания приёма/передачи ведомым.
 */
static void i2c_s_end(void)
{
    // Обозначим конец передачи/приёма.
    i2c_end();
    
    // Если передача прервана.
    if(_i2c_state.interrupted){
        _i2c_state.interrupted = false;
        // Запустим новую.
        i2c_do_start();
    // Иначе.
    }else{
        // Если не была инициирована ещё одна передача.
        if(!_i2c_state.has_transfer){
            //Будем слушать дальше.
            i2c_do_listen();
        }
    }
}
Exemple #16
0
/* dac_config is called once to initialize it. we will apply
   our static settings because of the init flow.
   dac_init -> dac_line_in -> mpeg_init -> dac_config
*/
static int dac_config(void)
{
    int ret = 0;
    unsigned char buf[2];

    i2c_begin();

    buf[0] = DAC_REG_WRITE | DAC_GCFG;
    buf[1] = (dac_enabled ? 0x04 : 0) |
        (line_in_enabled ? 0x08 : 0);

    /* send write command */
    if (i2c_write(DAC_DEV_WRITE,buf,2))
    {
        ret = -1;
    }

    i2c_end();
    return ret;
}
Exemple #17
0
/**
 *  @ingroup I2C-RTC
 *
 */
void mcp7941x_end (void) {
	FUNC_PREFIX(i2c_end());
}
Exemple #18
0
void end() {
	logs_end();
	i2c_end();
	httpd_end();
	exit(0);
}