void MMA8452Q::axes(int axes[]) { uint8_t *data; uint8_t read_count = 0; uint8_t val = registerRead(CTRL_REG1); if (bitRead(val, F_READ) == 0) read_count = 6; else read_count = 3; data = new uint8_t[read_count]; registersRead(OUT_X_MSB, data, read_count); for (int i = 0; i < 3; i++) { axes[i] = data[i * (read_count / 3)] << 8; if (bitRead(val, F_READ) == 0) axes[i] |= data[(i * 2) + 1]; axes[i] >>= 4; } delete[] data; }
void MMA8452Q::scale(uint8_t scale) { uint8_t value = registerRead(XYZ_DATA_CFG); switch (scale) { case 2: bitWrite(value, 0, 0); bitWrite(value, 1, 0); break; case 4: bitWrite(value, 0, 1); bitWrite(value, 1, 0); break; case 8: bitWrite(value, 0, 0); bitWrite(value, 1, 1); break; } }
void _ISR _SI2CInterrupt(void) //I2C slave interrupt { IEC0bits.SI2CIE = 0; //Disable interrupts if((I2CSTATbits.R_W == 0)&&(I2CSTATbits.D_A == 0)) //Address matched, writing register address to slave { temp = I2CRCV; //dummy read to remove stored address value Flag.AddrFlag = 1; //next byte will be address Flag.DataFlag = 0; } else if((I2CSTATbits.R_W == 0)&&(I2CSTATbits.D_A == 1)) //Check for data { if(Flag.AddrFlag) { Flag.AddrFlag = 0; Flag.DataFlag = 1; //next byte is data address = I2CRCV; I2CCONbits.SCLREL = 1; //Release SCL line } else if(Flag.DataFlag) { registerWrite(address, I2CRCV);// store data into register I2CCONbits.SCLREL = 1; //Release SCL line address++; //Increment address pointer incase stop bit isn't recieved / another byte comes through } } else if((I2CSTATbits.R_W == 1)&&(I2CSTATbits.D_A == 0)) //Been told to put data on bus, must already have desired register address { temp = I2CRCV; //ditch stored address I2CTRN = registerRead(address); //Read data from register & send data to I2C transmit buffer, setting D/A in the process I2CCONbits.SCLREL = 1; //Release SCL line address++; //Increment address for next read } else if((I2CSTATbits.R_W == 1)&&(I2CSTATbits.D_A == 1)) //D/A hasn't been reset, master must want more data { I2CTRN = registerRead(address); //Read data from RAM & send data to I2C master device I2CCONbits.SCLREL = 1; //Release SCL line address++; } _SI2CIF = 0; //clear I2C1 Slave interrupt flag IEC0bits.SI2CIE = 1; //Enable interrupts }
int MMA8452Q::begin(void) { uint8_t whoami; Wire.begin(); whoami = registerRead(WHO_AM_I); if (whoami != 0x2A) return -1; this -> active(true); return 0; }
static int pixi_spi_get (int channel, int address, int data) { LIBPIXI_UNUSED(channel); LIBPIXI_UNUSED(data); return registerRead (address); }
bool MMA8452Q::orientation(uint8_t *value) { *value = registerRead(PL_STATUS); return bitRead(*value, NEWLP); }
uint8_t MMA8452Q::intSource(void) { return registerRead(INT_SOURCE); }
uint8_t MMA8452Q::sysmod(void) { return registerRead(SYSMOD); }
uint8_t MMA8452Q::status(void) { return registerRead(STATUS); }
static inline void registerSetBit(uint8_t addr, uint8_t bit, bool value) { uint8_t val = registerRead(addr); bitWrite(val, bit, value); registerWrite(addr, val); }