static int16_t
eeprom_do(const uint8_t *txbuf, size_t txbytes,
        uint8_t *rxbuf, size_t rxbytes) {
    int16_t status;
    uint8_t retries = 5;
    while (retries) {
        status = i2c_transact(EEPROM_I2C, (EEPROM_ADDR << 1),
                (uint8_t*)txbuf, txbytes);
        if (status == EERR_AGAIN) {
            /* Retry forever. */
            continue;
        } else if (status != EERR_OK) {
            retries--;
            continue;
        }
        if (rxbytes == 0) {
            break;
        }

        status = i2c_transact(EEPROM_I2C, (EEPROM_ADDR << 1) | 1,
                rxbuf, rxbytes);
        if (status != EERR_OK) {
            retries--;
            continue;
        } else {
            break;
        }
    }
    return status;
}
Beispiel #2
0
void L3GD20_setupSensor(void)
{
	/* setup the gyro by letting it enter the normal mode (PD bit set) */
	static uint8_t txBuf[5];
	static uint8_t rxBuf[5];
	txBuf[0] = 0xcf; /* CTRL_REG1 with 760Hz sample rate PD and Xen, Yen, Zen */
	txBuf[1] = 0x09; /* CTRL_REG2 */
	txBuf[2] = 0x00; /* CTRL_REG3 */
	txBuf[3] = 0x00; /* CTRL_REG4 without BLE for little endian transmission and 250dps scale */
	txBuf[4] = 0x00; /* CTRL_REG5 */

	i2c_transact(L3GD20_DEVICE_ADRESS, L3GD20_REGISTER_CTRL_REG1, txBuf, sizeof(txBuf), NULL, 0, NULL);
	i2c_transact(L3GD20_DEVICE_ADRESS, L3GD20_REGISTER_CTRL_REG1, NULL, 0, rxBuf, sizeof(rxBuf), &gyroConfigDataCallback);
}
Beispiel #3
0
static void pollData(void)
{
	bool succ = i2c_transact(L3GD20_DEVICE_ADRESS, L3GD20_REGISTER_OUT_X_L, NULL, 0, (uint8_t*)g_gyroData, sizeof(g_gyroData), &gyroDataCallback);
	static uint8_t ct = 0;
	if(FALSE == succ) {
		++ct;
		if(ct > 10) {
			i2cSensorStickForceReset();
			L3GD20_setupSensor();
			ct = 0;
		}

	} else ct = 0;
}