int16_t gyro_read_axis(uint8_t axis){ /*i2c_send_start(); i2c_send_addr(GYRO_ADDR,TW_WRITE); i2c_send_data( axis | (1<<7)); i2c_send_start(); i2c_send_addr(GYRO_ADDR,TW_READ); int datal,datah; datal=i2c_receive_data(1); datah=i2c_receive_data(0); i2c_send_stop(); return ((datah<<8) + datal);//&0x7ff;*/ int16_t x = i2c_read_word(GYRO_ADDR, (axis | (1<<7))); //SIGN EXTEND! struct {signed int x:10;} b; b.x=x; return b.x; }
static uint16_t mpu6050_read_word(uint16_t addr) { i2c_send_byte(MPU6050_I2C_ADDRESS, addr); return i2c_read_word(MPU6050_I2C_ADDRESS); }
static int psu_ne2572_info_get(int id, onlp_psu_info_t* info) { DIAG_PRINT("%s, id:%d", __FUNCTION__, id); //int val = 0; //int index = ONLP_OID_ID_GET(info->hdr.id); /* Set capability */ info->caps = ONLP_PSU_CAPS_AC; if (info->status & ONLP_PSU_STATUS_FAILED) { return ONLP_STATUS_OK; } /* Set the associated oid_table */ //info->hdr.coids[0] = ONLP_FAN_ID_CREATE(index + CHASSIS_FAN_COUNT); //info->hdr.coids[1] = ONLP_THERMAL_ID_CREATE(index + CHASSIS_THERMAL_COUNT); #if 1 int i = 0; int status; int exponent, mantissa; for (i = 0; i < 6; i++) { //printf("I2C register 0x%X \n", regs_word[i].reg); status = i2c_read_word(id, RPS_PSU_MICRO_P_ADDR, regs_word[i].reg); if (status < 0) printf("I2C command 0x%X Read Fail\n", regs_word[i].reg); else { //printf("I2C command 0x%X Read Success: 0x%02x\n", regs_word[i].reg, status); regs_word[i].value = status; } } info->caps |= ONLP_PSU_CAPS_VOUT; info->caps |= ONLP_PSU_CAPS_VIN; info->caps |= ONLP_PSU_CAPS_IOUT; info->caps |= ONLP_PSU_CAPS_IIN; info->caps |= ONLP_PSU_CAPS_POUT; info->caps |= ONLP_PSU_CAPS_PIN; /* Linear_5s_11s */ exponent = psu_two_complement_to_int(regs_word[0].value >> 11, 5, 0x1f); mantissa = psu_two_complement_to_int(regs_word[0].value & 0x7ff, 11, 0x7ff); info->mvin = psu_ne2572_linear_format(exponent, mantissa); /* Linear_16u */ exponent = -12; mantissa = regs_word[1].value; info->mvout = psu_ne2572_linear_format(exponent, mantissa); exponent = psu_two_complement_to_int(regs_word[2].value >> 11, 5, 0x1f); mantissa = psu_two_complement_to_int(regs_word[2].value & 0x7ff, 11, 0x7ff); info->miin = psu_ne2572_linear_format(exponent, mantissa); exponent = psu_two_complement_to_int(regs_word[3].value >> 11, 5, 0x1f); mantissa = psu_two_complement_to_int(regs_word[3].value & 0x7ff, 11, 0x7ff); info->miout = psu_ne2572_linear_format(exponent, mantissa); exponent = psu_two_complement_to_int(regs_word[4].value >> 11, 5, 0x1f); mantissa = psu_two_complement_to_int(regs_word[4].value & 0x7ff, 11, 0x7ff); info->mpout = psu_ne2572_linear_format(exponent, mantissa); exponent = psu_two_complement_to_int(regs_word[5].value >> 11, 5, 0x1f); mantissa = psu_two_complement_to_int(regs_word[5].value & 0x7ff, 11, 0x7ff); info->mpin = psu_ne2572_linear_format(exponent, mantissa); #endif return ONLP_STATUS_OK; }