boolean DRV2605::init(uint8_t adrs, boolean lra) { //uint8_t id = readRegister8(DRV2605_REG_STATUS); writeRegister8(adrs,DRV2605_REG_MODE, DRV2605_MODE_REALTIME); // out of standby writeRegister8(adrs,DRV2605_REG_RTPIN, 0x00); // disable input pin (I think) writeRegister8(adrs,DRV2605_REG_WAVESEQ1, 1); // strong click writeRegister8(adrs,DRV2605_REG_WAVESEQ2, 0); }
void Adafruit_MMA8451::setRange(mma8451_range_t range) { uint8_t reg1 = readRegister8(MMA8451_REG_CTRL_REG1); writeRegister8(MMA8451_REG_CTRL_REG1, 0x00); // deactivate writeRegister8(MMA8451_REG_XYZ_DATA_CFG, range & 0x3); writeRegister8(MMA8451_REG_CTRL_REG1, reg1 | 0x01); // activate }
void Adafruit_IS31FL3731::audioSync(boolean sync) { if (sync) { writeRegister8(ISSI_BANK_FUNCTIONREG, ISSI_REG_AUDIOSYNC, 0x1); } else { writeRegister8(ISSI_BANK_FUNCTIONREG, ISSI_REG_AUDIOSYNC, 0x0); } }
boolean Adafruit_IS31FL3731::begin(uint8_t addr) { Wire.begin(); _i2caddr = addr; _frame = 0; // shutdown writeRegister8(ISSI_BANK_FUNCTIONREG, ISSI_REG_SHUTDOWN, 0x00); delay(10); // out of shutdown writeRegister8(ISSI_BANK_FUNCTIONREG, ISSI_REG_SHUTDOWN, 0x01); // picture mode writeRegister8(ISSI_BANK_FUNCTIONREG, ISSI_REG_CONFIG, ISSI_REG_CONFIG_PICTUREMODE); displayFrame(_frame); // all LEDs on & 0 PWM clear(); // set each led to 0 PWM for (uint8_t f=0; f<8; f++) { for (uint8_t i=0; i<=0x11; i++) writeRegister8(f, i, 0xff); // each 8 LEDs on } audioSync(false); return true; }
void Adafruit_LIS3DH::setClick(uint8_t c, uint8_t clickthresh, uint8_t timelimit, uint8_t timelatency, uint8_t timewindow) { if (!c) { //disable int uint8_t r = readRegister8(LIS3DH_REG_CTRL3); r &= ~(0x80); // turn off I1_CLICK writeRegister8(LIS3DH_REG_CTRL3, r); writeRegister8(LIS3DH_REG_CLICKCFG, 0); return; } // else... writeRegister8(LIS3DH_REG_CTRL3, 0x80); // turn on int1 click writeRegister8(LIS3DH_REG_CTRL5, 0x08); // latch interrupt on int1 if (c == 1) writeRegister8(LIS3DH_REG_CLICKCFG, 0x15); // turn on all axes & singletap if (c == 2) writeRegister8(LIS3DH_REG_CLICKCFG, 0x2A); // turn on all axes & doubletap writeRegister8(LIS3DH_REG_CLICKTHS, clickthresh); // arbitrary writeRegister8(LIS3DH_REG_TIMELIMIT, timelimit); // arbitrary writeRegister8(LIS3DH_REG_TIMELATENCY, timelatency); // arbitrary writeRegister8(LIS3DH_REG_TIMEWINDOW, timewindow); // arbitrary }
void DW1000::resetAll() { writeRegister8(DW1000_PMSC, 0, 0x01); // set clock to XTAL writeRegister8(DW1000_PMSC, 3, 0x00); // set All reset usleep(10); // wait for PLL to lock writeRegister8(DW1000_PMSC, 3, 0xF0); // clear All reset }
void Adafruit_MMA8451::setDataRate(mma8451_dataRate_t dataRate) { uint8_t ctl1 = readRegister8(MMA8451_REG_CTRL_REG1); writeRegister8(MMA8451_REG_CTRL_REG1, 0x00); // deactivate ctl1 &= ~(MMA8451_DATARATE_MASK << 3); // mask off bits ctl1 |= (dataRate << 3); writeRegister8(MMA8451_REG_CTRL_REG1, ctl1 | 0x01); // activate }
bool Adafruit_LIS3DH::begin(uint8_t i2caddr) { _i2caddr = i2caddr; if (_cs == -1) { // i2c Wire.begin(); } else { digitalWrite(_cs, HIGH); pinMode(_cs, OUTPUT); if (_sck == -1) { // hardware SPI SPI.begin(); } else { // software SPI pinMode(_sck, OUTPUT); pinMode(_mosi, OUTPUT); pinMode(_miso, INPUT); } } /* Check connection */ uint8_t deviceid = readRegister8(LIS3DH_REG_WHOAMI); if (deviceid != 0x33) { /* No LIS3DH detected ... return false */ //Serial.println(deviceid, HEX); return false; } // enable all axes, normal mode writeRegister8(LIS3DH_REG_CTRL1, 0x07); // 400Hz rate setDataRate(LIS3DH_DATARATE_400_HZ); // High res enabled writeRegister8(LIS3DH_REG_CTRL4, 0x08); // DRDY on INT1 writeRegister8(LIS3DH_REG_CTRL3, 0x10); // Turn on orientation config //writeRegister8(LIS3DH_REG_PL_CFG, 0x40); // enable adc & temp sensor writeRegister8(LIS3DH_REG_TEMPCFG, 0xC0); for (uint8_t i=0; i<0x30; i++) { Serial.print("$"); Serial.print(i, HEX); Serial.print(" = 0x"); Serial.println(readRegister8(i), HEX); } return true; }
bool L3G4200D::begin(l3g4200d_dps_t scale, l3g4200d_odrbw_t odrbw) { // Reset calibrate values d.XAxis = 0; d.YAxis = 0; d.ZAxis = 0; useCalibrate = false; // Reset threshold values t.XAxis = 0; t.YAxis = 0; t.ZAxis = 0; actualThreshold = 0; Wire.begin(); // Check L3G4200D Who Am I Register if (fastRegister8(L3G4200D_REG_WHO_AM_I) != 0xD3) { return false; } // Enable all axis and setup normal mode + Output Data Range & Bandwidth uint8_t reg1 = 0x00; reg1 |= 0x0F; // Enable all axis and setup normal mode reg1 |= (odrbw << 4); // Set output data rate & bandwidh writeRegister8(L3G4200D_REG_CTRL_REG1, reg1); // Disable high pass filter writeRegister8(L3G4200D_REG_CTRL_REG2, 0x00); // Generata data ready interrupt on INT2 writeRegister8(L3G4200D_REG_CTRL_REG3, 0x08); // Set full scale selection in continous mode writeRegister8(L3G4200D_REG_CTRL_REG4, scale << 4); switch(scale) { case L3G4200D_SCALE_250DPS: dpsPerDigit = .00875f; break; case L3G4200D_SCALE_500DPS: dpsPerDigit = .0175f; break; case L3G4200D_SCALE_2000DPS: dpsPerDigit = .07f; break; default: break; } // Boot in normal mode, disable FIFO, HPF disabled writeRegister8(L3G4200D_REG_CTRL_REG5, 0x00); return true; }
void ADXL345::useInterrupt(adxl345_int_t interrupt) { if (interrupt == 0) { writeRegister8(ADXL345_REG_INT_MAP, 0x00); } else { writeRegister8(ADXL345_REG_INT_MAP, 0xFF); } writeRegister8(ADXL345_REG_INT_ENABLE, 0xFF); }
void Adafruit_LIS3DH::setDataRate(lis3dh_dataRate_t dataRate) { uint8_t ctl1 = readRegister8(LIS3DH_REG_CTRL1); ctl1 &= ~(0xF0); // mask off bits ctl1 |= (dataRate << 4); writeRegister8(LIS3DH_REG_CTRL1, ctl1); }
void Adafruit_LIS3DH::setRange(lis3dh_range_t range) { uint8_t r = readRegister8(LIS3DH_REG_CTRL4); r &= ~(0x30); r |= range << 4; writeRegister8(LIS3DH_REG_CTRL4, r); }
void Adafruit_TFTLCD::drawPixel(int16_t x, int16_t y, uint16_t color) { // Clip if((x < 0) || (y < 0) || (x >= _width) || (y >= _height)) return; CS_ACTIVE; if(driver == ID_932X) { int16_t t; switch(rotation) { case 1: t = x; x = TFTWIDTH - 1 - y; y = t; break; case 2: x = TFTWIDTH - 1 - x; y = TFTHEIGHT - 1 - y; break; case 3: t = x; x = y; y = TFTHEIGHT - 1 - t; break; } writeRegister16(0x0020, x); writeRegister16(0x0021, y); writeRegister16(0x0022, color); } else if(driver == ID_7575) { uint8_t hi, lo; switch(rotation) { default: lo = 0 ; break; case 1 : lo = 0x60; break; case 2 : lo = 0xc0; break; case 3 : lo = 0xa0; break; } writeRegister8( HX8347G_MEMACCESS , lo); // Only upper-left is set -- bottom-right is full screen default writeRegisterPair(HX8347G_COLADDRSTART_HI, HX8347G_COLADDRSTART_LO, x); writeRegisterPair(HX8347G_ROWADDRSTART_HI, HX8347G_ROWADDRSTART_LO, y); hi = color >> 8; lo = color; CD_COMMAND; write8(0x22); CD_DATA; write8(hi); write8(lo); }
void DS3231::clearAlarm2(void) { uint8_t value; value = readRegister8(DS3231_REG_STATUS); value &= 0b11111101; writeRegister8(DS3231_REG_STATUS, value); }
// Deprecated function -- here for compat w/old code void Adafruit_TFTLCD::goTo(int x, int y) { if (driver == 0x9325 || driver == 0x9328) { writeRegister16(0x0020, x); // GRAM Address Set (Horizontal Address) (R20h) writeRegister16(0x0021, y); // GRAM Address Set (Vertical Address) (R21h) writeCommand(0x0022); // Write Data to GRAM (R22h) } if (driver == 0x7575) { writeRegister8(HX8347G_COLADDRSTART2, x>>8); writeRegister8(HX8347G_COLADDRSTART1, x); writeRegister8(HX8347G_ROWADDRSTART2, y>>8); writeRegister8(HX8347G_ROWADDRSTART1, y); writeRegister8(HX8347G_COLADDREND2, 0); writeRegister8(HX8347G_COLADDREND1, TFTWIDTH-1); writeRegister8(HX8347G_ROWADDREND2, (TFTHEIGHT-1)>>8); writeRegister8(HX8347G_ROWADDREND1, (TFTHEIGHT-1)&0xFF); writeCommand(0x0022); // Write Data to GRAM (R22h) }
void HMC5883L::setSamples(hmc5883l_samples_t samples) { uint8_t value; value = readRegister8(HMC5883L_REG_CONFIG_A); value &= 0b10011111; value |= (samples << 5); writeRegister8(HMC5883L_REG_CONFIG_A, value); }
void HMC5883L::setDataRate(hmc5883l_dataRate_t dataRate) { uint8_t value; value = readRegister8(HMC5883L_REG_CONFIG_A); value &= 0b11100011; value |= (dataRate << 2); writeRegister8(HMC5883L_REG_CONFIG_A, value); }
void HMC5883L::setMeasurementMode(hmc5883l_mode_t mode) { uint8_t value; value = readRegister8(HMC5883L_REG_MODE); value &= 0b11111100; value |= mode; writeRegister8(HMC5883L_REG_MODE, value); }
void DS3231::enable32kHz(bool enabled) { uint8_t value; value = readRegister8(DS3231_REG_STATUS); value &= 0b11110111; value |= (enabled << 3); writeRegister8(DS3231_REG_STATUS, value); }
void DS3231::setOutput(DS3231_sqw_t mode) { uint8_t value; value = readRegister8(DS3231_REG_CONTROL); value &= 0b11100111; value |= (mode << 3); writeRegister8(DS3231_REG_CONTROL, value); }
void DS3231::enableOutput(bool enabled) { uint8_t value; value = readRegister8(DS3231_REG_CONTROL); value &= 0b11111011; value |= (!enabled << 2); writeRegister8(DS3231_REG_CONTROL, value); }
void DS3231::forceConversion(void) { uint8_t value; value = readRegister8(DS3231_REG_CONTROL); value |= 0b00100000; writeRegister8(DS3231_REG_CONTROL, value); do {} while ((readRegister8(DS3231_REG_CONTROL) & 0b00100000) != 0); }
void Adafruit_LIS3DH::setInertialInt(bool state, float thresh, uint8_t timelimit, uint8_t options) { if (!state) { //disable int uint8_t r = readRegister8(LIS3DH_REG_CTRL3); r &= ~(0x40); // turn off IA1 writeRegister8(LIS3DH_REG_CTRL3, r); return; } // else... writeRegister8(LIS3DH_REG_CTRL3, 0x40); // turn on int1 writeRegister8(LIS3DH_REG_CTRL5, 0x08); // latch interrupt on int1 uint8_t range = (2 << getRange()); if (thresh < 0) thresh = thresh * -1; if (thresh > range) thresh = range; thresh = (thresh * 127 / range); uint8_t th = (int) thresh; writeRegister8(LIS3DH_REG_INT1THS, (th & 0x7f)); // arbitrary writeRegister8(LIS3DH_REG_INT1DUR, (timelimit & 0x7f)); // arbitrary writeRegister8(LIS3DH_REG_INT1CFG, options); // arbitrary }
void DW1000::sendFrame(uint8_t* message, uint16_t length) { if (length >= 125) length = 125; // check for maximim length a frame can have with 127 Byte frames writeRegister(DW1000_TX_BUFFER, 0, message, length); // fill buffer uint8_t backup = readRegister8(DW1000_TX_FCTRL, 1); // put length of frame length += 2; // including 2 CRC Bytes length = ((backup & 0xFC) << 8) | (length & 0x03FF); writeRegister16(DW1000_TX_FCTRL, 0, length); stopTRX(); // stop receiving writeRegister8(DW1000_SYS_CTRL, 0, 0x02); // trigger sending process by setting the TXSTRT bit startRX(); // enable receiver again }
void DW1000::sendDelayedFrame(uint8_t* message, uint16_t length, uint64_t TxTimestamp) { if (length >= 125) length = 125; // check for maximim length a frame can have with 127 Byte frames writeRegister(DW1000_TX_BUFFER, 0, message, length); // fill buffer uint8_t backup = readRegister8(DW1000_TX_FCTRL, 1); // put length of frame length += 2; // including 2 CRC Bytes length = ((backup & 0xFC) << 8) | (length & 0x03FF); writeRegister16(DW1000_TX_FCTRL, 0, length); writeRegister40(DW1000_DX_TIME, 0, TxTimestamp); //write the timestamp on which to send the message stopTRX(); // stop receiving writeRegister8(DW1000_SYS_CTRL, 0, 0x02 | 0x04); // trigger sending process by setting the TXSTRT and TXDLYS bit startRX(); // enable receiver again }
void ADXL345::writeRegisterBit(uint8_t reg, uint8_t pos, bool state) { uint8_t value; value = readRegister8(reg); if (state) { value |= (1 << pos); } else { value &= ~(1 << pos); } writeRegister8(reg, value); }
// Set Range void ADXL345::setRange(adxl345_range_t range) { // Get actual value register uint8_t value = readRegister8(ADXL345_REG_DATA_FORMAT); // Update the data rate // (&) 0b11110000 (0xF0 - Leave HSB) // (|) 0b0000xx?? (range - Set range) // (|) 0b00001000 (0x08 - Set Full Res) value &= 0xF0; value |= range; value |= 0x08; writeRegister8(ADXL345_REG_DATA_FORMAT, value); }
void DS3231::armAlarm2(bool armed) { uint8_t value; value = readRegister8(DS3231_REG_CONTROL); if (armed) { value |= 0b00000010; } else { value &= 0b11111101; } writeRegister8(DS3231_REG_CONTROL, value); }
void ADXL345::setTapDetectionXYZ(bool state) { uint8_t value; value = readRegister8(ADXL345_REG_TAP_AXES); if (state) { value |= 0b00000111; } else { value &= 0b11111000; } writeRegister8(ADXL345_REG_TAP_AXES, value); }
void ADXL345::setInactivityXYZ(bool state) { uint8_t value; value = readRegister8(ADXL345_REG_ACT_INACT_CTL); if (state) { value |= 0b00000111; } else { value &= 0b11111000; } writeRegister8(ADXL345_REG_ACT_INACT_CTL, value); }