int pmu_get_regs(int reg, uint8_t* out, int count) { uint8_t registers[1]; registers[0] = reg; return i2c_rx(PMU_I2C_BUS, PMU_GETADDR, registers, 1, out, count); }
int pmu_write_unk(uint8_t regidx, int flag1, int flag2) { uint8_t registers = PMU_UNKREG_START + regidx; uint8_t recv_buff = 0; uint8_t data = 0; int result; if (regidx > PMU_UNKREG_END - PMU_UNKREG_START) return -1; result = i2c_rx(PMU_I2C_BUS, PMU_GETADDR, (void*)®isters, 1, (void*)&recv_buff, 1); if (result != I2CNoError) return result; recv_buff &= 0x1D; if (!flag1) { data = recv_buff | 0x60; } else { data = recv_buff; if (flag2) data |= 2; } pmu_write_reg(registers, data, 1); return 0; }
void fst_nunchuk_read(){ int data[6] = {0x80, 0x80, 0, 0, 0, 0}; fst_nunchuk_xmit_cmd(0xF0, 0x55); fst_nunchuk_xmit_cmd(0xFB, 0x00); fst_nunchuk_xmit_cmd(0x00, 0x00); i2c_rx(FST_NUNCHUK_I2C_ADDR, 6, data, FST_NUNCHUK_DELAY_US); //checks to see if joystick is moving left or right if (data[0] < 75){ nunchuk_left(); } else if (data[0] > 175){ nunchuk_right(); } else if(data[0] > 100 && data[0] < 150 && data[1] > 100 && data[1] < 150) fst_nunchuk_reset(); //checks to see if joystick is moving up or down if (data[1] < 75){ nunchuk_down(); } else if (data[1] > 175){ nunchuk_up(); } }
int accel_get_reg(int reg) { uint8_t registers[1]; uint8_t out[1]; registers[0] = reg; i2c_rx(ACCEL_I2C_BUS, ACCEL_GETADDR, registers, 1, out, 1); return out[0]; }
int pmu_get_reg(int reg) { uint8_t registers[1]; uint8_t out[1]; registers[0] = reg; i2c_rx(PMU_I2C_BUS, PMU_GETADDR, registers, 1, out, 1); return out[0]; }
byte MP3Player::I2C_Read(byte Address) { byte data=0; i2c_start(); if(i2c_tx(0x86)) while(1); if(i2c_tx(Address)) while(1); i2c_start(); if(i2c_tx(0x87)) while(1); data=i2c_rx(0); i2c_stop(); return(data); }
void pmu_write_oocshdwn(int data) { uint8_t registers[1]; uint8_t discardData[5]; uint8_t poweroffData[] = {7, 0xD1, 0xFF, 0xF0}; registers[0] = 1; i2c_rx(PMU_I2C_BUS, PMU_GETADDR, registers, sizeof(registers), discardData, 3); i2c_tx(PMU_I2C_BUS, PMU_SETADDR, poweroffData, sizeof(poweroffData)); pmu_write_reg(PMU_OOCSHDWN, data, FALSE); // Wait for the hardware to shut down EnterCriticalSection(); while(TRUE) { udelay(100000); } }
void cmd_iic_read(int argc, char** argv) { if(argc < 4) { bufferPrintf("usage: %s <bus> <address> <register>\n", argv[0]); return; } int bus = parseNumber(argv[1]); int address = parseNumber(argv[2]); uint8_t registers[1]; uint8_t out[1]; registers[0] = parseNumber(argv[3]); int error = i2c_rx(bus, address, registers, 1, out, 1); bufferPrintf("result: %d, error: %d\r\n", (int) out[0], error); }
int accel_write_reg(int reg, int data, int verify) { uint8_t command[2]; command[0] = reg; command[1] = data; i2c_tx(ACCEL_I2C_BUS, ACCEL_SETADDR, command, sizeof(command)); if(!verify) return 0; uint8_t accelReg = reg; uint8_t buffer = 0; i2c_rx(ACCEL_I2C_BUS, ACCEL_GETADDR, &accelReg, 1, &buffer, 1); if(buffer == data) return 0; else return -1; }
int pmu_write_reg(int reg, int data, int verify) { uint8_t command[2]; command[0] = reg; command[1] = data; i2c_tx(PMU_I2C_BUS, PMU_SETADDR, command, sizeof(command)); if (!verify) return 0; uint8_t pmuReg = reg; uint8_t buffer = 0; i2c_rx(PMU_I2C_BUS, PMU_GETADDR, &pmuReg, 1, &buffer, 1); if (buffer == data) return 0; else return -1; }
int pmu_get_gpmem_reg(int reg, uint8_t* out) { if(reg > PMU_MAXREG) return -1; if((GPMemCachedPresent & (0x1 << reg)) == 0) { uint8_t registers[1]; registers[0] = reg + 0x67; if(i2c_rx(PMU_I2C_BUS, PMU_GETADDR, registers, 1, &GPMemCache[reg], 1) != 0) { return -1; } GPMemCachedPresent |= (0x1 << reg); } *out = GPMemCache[reg]; return 0; }
int pmu_get_gpmem_reg(int reg, uint8_t* out) { if (reg > PMU_MAXREG) return -1; // Check whether the register is already cached. if ((GPMemCachedPresent & (0x1 << reg)) == 0) { uint8_t registers[1]; registers[0] = reg ^ 0x80; if (i2c_rx(PMU_I2C_BUS, PMU_GETADDR, registers, 1, &GPMemCache[reg], 1) != 0) { return -1; } GPMemCachedPresent |= (0x1 << reg); } *out = GPMemCache[reg]; return 0; }
void Temp_I2C_sensor(int *array) { int i; short check_value_tx; short check_value_rx; unsigned char tmp[2]; const unsigned char temparray[1]= {REG_TEMP_VALUE}; // const due to not changing the value, char its a one byte element // this is so I can have my address in memory and create a pointer to point to it for the function const unsigned char all_temp_sensors[TEMP_SENSORS]= {TEMP_X_PLUS, TEMP_X_MINUS,TEMP_Y_PLUS, TEMP_Y_MINUS, TEMP_Z_PLUS, TEMP_Z_MINUS, TEMP_L_BOARD}; // Measure all temperature sensors at once. for (i=0; i<TEMP_SENSORS; i++) { check_value_tx = i2c_tx(all_temp_sensors[i],temparray,1);//place the address I want to talk to, //place the pointer to the array that stores my address, specify the number of bytes being sent //printf("\r\nSensor %i %s",i,I2C_error_str(check_value_tx)); if (check_value_tx==1) { check_value_rx = i2c_rx(all_temp_sensors[i],tmp,2);//place the address I want to talk to, //the array that stores my data, number of bytes being sent array[i]=tmp[0]; //printf("\r\nT%i = %i\r\n",i,tmp[0]); ctl_timeout_wait(ctl_get_current_time()+1000); } else if (check_value_tx==-1)//returns a -1 if there is no connection to the I2C device { array[i]=500;// printf("\r\nT%i = %i\r\n",i,tmp[0]); } else if (check_value_tx==0)//returns a zero if { array[i]=1111;// } } }
//read write cmd for CLYDE int clyde_take_data(int *array) { int res,i,found=0; unsigned char tx[2],rx[2]; unsigned short rez; //prevent other tasks from sending commands to the EPS if(!ctl_mutex_lock(&EPS_mutex,CTL_TIMEOUT_DELAY,200)) { return -1; } //Set //printf("sent cmd \r\n"); //send cmd\ //take first 21 adc measurements for beacon for(i=0; i<20; i++) { tx[0]=EPS_ADC_COMMAND; tx[1]= name_addrs_clyde[i]; res=i2c_tx(EPS_I2C_ADDRESS,tx,2); //error msg or success if(res<0) { //printf("tx returned = %s\r\n",I2C_error_str(res)); //set invalid value array[i]=0xF800; //skip to the next channel continue; } //wait 1.2 ms (300) ctl_timeout_wait(ctl_get_current_time()+5); //read cmd res=i2c_rx(EPS_I2C_ADDRESS,rx,2); //error msg or success if (res<0) { //printf("rx returned = %s\r\n",I2C_error_str(res)); //set invalid value array[i]=0xF800; //skip to the next channel continue; } rez=rx[1]; rez|=rx[0]<<8; rez&=0x3FF; //printf("rez = %i\r\n",rez); array[i]=(int)rez; //printf("EPS data = %i, array # = %i\r\n",array[i],i); } //take status packet for beacon tx[0]=EPS_STATUS_COMMAND; tx[1]=0;//THIS DOESNT MATTER WHAT IT IS res=i2c_tx(EPS_I2C_ADDRESS,tx,2); //error msg or success //printf("%s\r\n",I2C_error_str(res)); //wait 1.2 ms (300) ctl_timeout_wait(ctl_get_current_time()+5); //read cmd res=i2c_rx(EPS_I2C_ADDRESS,rx,2); //error msg or success if(res!=0) { //printf("%s\r\n",I2C_error_str(res)); //invalid value array[i]=0xFFFF; } else { rez=rx[1]; rez|=rx[0]<<8; printf("rez = 0x%04X\r\n",rez); array[i]=(int)rez; } //unlock the EPS ctl_mutex_unlock(&EPS_mutex); //return success return RET_SUCCESS; }