uint8_t read_pixel_temp(uint8_t pixel, uint8_t data_tpa[]){ uint8_t byte = 1; uint8_t command; uint8_t bytes_read; //Festlegen des Rigsters ab dem gelesen werden soll, abhaenig vom Patam: pixel switch (pixel){ //Alle pixel case 0: byte = 8; command = 2; break; case 1: command = 2; break; case 2: command = 3; break; case 3: command = 4; break; case 4: command = 5; break; case 5: command = 6; break; case 6: command = 7; break; case 7: command = 8; break; case 8: command = 9; break; } //Registernr an modul schreiben if(write_i2c(I2C_1, ADDR_TPA81, &command, 1) != 1) return -2; //Lesen der Daten vom Modul bytes_read = read_i2c(I2C_1, ADDR_TPA81, data_tpa, byte); //Pruefen ob die geforderten Bytes gelesen wurden if(bytes_read == byte) return bytes_read; return -1; }
int pmx::GpioBoard::getValueP1(int pin) { if (!connected_) { logger().error() << "getValueP1() : return 0; GpioBoard NOT CONNECTED !" << utils::end; return 0; } uchar in = read_i2c(IN_P1); logger().debug() << "getValueP1 in = " << reinterpret_cast<void*>(in) << utils::end; int intmp = (in >> pin) & 0x01; logger().debug() << "getValueP1 in" << pin << "=" << reinterpret_cast<void*>(intmp) << utils::end; return intmp; }
/** * nmk_i2c_xfer() - I2C transfer function used by kernel framework * @i2c_adap: Adapter pointer to the controller * @msgs: Pointer to data to be written. * @num_msgs: Number of messages to be executed * * This is the function called by the generic kernel i2c_transfer() * or i2c_smbus...() API calls. Note that this code is protected by the * semaphore set in the kernel i2c_transfer() function. * * NOTE: * READ TRANSFER : We impose a restriction of the first message to be the * index message for any read transaction. * - a no index is coded as '0', * - 2byte big endian index is coded as '3' * !!! msg[0].buf holds the actual index. * This is compatible with generic messages of smbus emulator * that send a one byte index. * eg. a I2C transation to read 2 bytes from index 0 * idx = 0; * msg[0].addr = client->addr; * msg[0].flags = 0x0; * msg[0].len = 1; * msg[0].buf = &idx; * * msg[1].addr = client->addr; * msg[1].flags = I2C_M_RD; * msg[1].len = 2; * msg[1].buf = rd_buff * i2c_transfer(adap, msg, 2); * * WRITE TRANSFER : The I2C standard interface interprets all data as payload. * If you want to emulate an SMBUS write transaction put the * index as first byte(or first and second) in the payload. * eg. a I2C transation to write 2 bytes from index 1 * wr_buff[0] = 0x1; * wr_buff[1] = 0x23; * wr_buff[2] = 0x46; * msg[0].flags = 0x0; * msg[0].len = 3; * msg[0].buf = wr_buff; * i2c_transfer(adap, msg, 1); * * To read or write a block of data (multiple bytes) using SMBUS emulation * please use the i2c_smbus_read_i2c_block_data() * or i2c_smbus_write_i2c_block_data() API */ static int nmk_i2c_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg msgs[], int num_msgs) { int status; int i; u32 cause; struct nmk_i2c_dev *dev = i2c_get_adapdata(i2c_adap); status = init_hw(dev); if (status) return status; clk_enable(dev->clk); /* setup the i2c controller */ setup_i2c_controller(dev); for (i = 0; i < num_msgs; i++) { if (unlikely(msgs[i].flags & I2C_M_TEN)) { dev_err(&dev->pdev->dev, "10 bit addressing" "not supported\n"); return -EINVAL; } dev->cli.slave_adr = msgs[i].addr; dev->cli.buffer = msgs[i].buf; dev->cli.count = msgs[i].len; dev->stop = (i < (num_msgs - 1)) ? 0 : 1; dev->result = 0; if (msgs[i].flags & I2C_M_RD) { /* it is a read operation */ dev->cli.operation = I2C_READ; status = read_i2c(dev); } else { /* write operation */ dev->cli.operation = I2C_WRITE; status = write_i2c(dev); } if (status || (dev->result)) { /* get the abort cause */ cause = (readl(dev->virtbase + I2C_SR) >> 4) & 0x7; dev_err(&dev->pdev->dev, "error during I2C" "message xfer: %d\n", cause); dev_err(&dev->pdev->dev, "%s\n", cause >= ARRAY_SIZE(abort_causes) ? "unknown reason" : abort_causes[cause]); clk_disable(dev->clk); return status; } udelay(I2C_DELAY); }
int16 read_eeprom(ice1712 *ice, uint8 eeprom[32]) { int i; int16 tmp; for (i = 0; i < 6; i++) { tmp = read_i2c(ice, I2C_EEPROM_ADDRESS_READ, i); if (tmp >= 0) eeprom[i] = (uint8)tmp; else return -1; } if (eeprom[4] > 32) return -1; for (i = 6; i < eeprom[4]; i++) { tmp = read_i2c(ice, I2C_EEPROM_ADDRESS_READ, i); if (tmp >= 0) eeprom[i] = (uint8)tmp; else return -1; } return eeprom[4]; }
uint8_t read_umgebungs_temp(void){ uint8_t temperatur = 0; //Festlegen des zu lesenden Registers uint8_t cmd_reg_1 = {1}; //Registernr an modul schreiben if(write_i2c(I2C_1, ADDR_TPA81, &cmd_reg_1, 1) != 1) return -1; //Lesen der Umgebungstemperatur if(read_i2c(I2C_1, ADDR_TPA81, &temperatur, 1) != 1) return -1; //Rueckgabe der Umgebungstemperatur return temperatur; }
uint8_t read_version_tpa81(void){ uint8_t version = 0; //Festlegen des zu lesenden Registers uint8_t cmd_reg_0 = {0}; //Registernr an modul schreiben if(write_i2c(I2C_1, ADDR_TPA81, &cmd_reg_0, 1) != 1) return -1; //Lesen der Versionsnummer if(read_i2c(I2C_1, ADDR_TPA81, &version, 1) != 1) return -1; //Rueckgabe der Verison return version; }
static int imx214_match_id( hwsensor_intf_t* si, void * data) { sensor_t* sensor = I2S(si); struct sensor_cfg_data *cdata = (struct sensor_cfg_data *)data; #if 0 struct sensor_cfg_data cdata_h; struct sensor_cfg_data cdata_l; u16 id_h = 0; u16 id_l = 0; u16 sensor_id = 0; cam_info("%s TODO.", __func__); cdata_h.cfg.reg.subaddr = 0x0016; cdata_h.cfg.reg.value = 0; cdata_l.cfg.reg.subaddr = 0x0017; cdata_l.cfg.reg.value = 0; imx214_i2c_read(sensor, &cdata_h); imx214_i2c_read(sensor, &cdata_l); sensor_id = (cdata_h.cfg.reg.value) << 8 | (cdata_l.cfg.reg.value); cam_notice( "%s, line %d, sensor id: 0x%x", __func__, __LINE__, sensor_id); id = read_i2c(); if (id == chipid) { cam_info("%s succeed to match id.", __func__); } else { cam_info("%s failed to match id.", __func__); sensor->board_info->sensor_index = CAMERA_SENSOR_INVALID; } #endif cdata->data = sensor->board_info->sensor_index; hwsensor_writefile(sensor->board_info->sensor_index, sensor->board_info->name); return 0; }
void update_x_translation(void){ write_i2c (SENSORS_I2C, MPU6050_ADDR, 0x01, 0x01); read_i2c (SENSORS_I2C, MPU6050_ADDR, 0x01); }