Ejemplo n.º 1
0
/**
 * @brief Select the bandwidth the digital filter pass allows.
 * @return 0 if successful, -1 if not
 * @param rate[in] Bandwidth setting to be used
 *
 * EEPROM must be write-enabled before calling this function.
 */
static int32_t PIOS_BMA180_SelectBW(enum bma180_bandwidth bw)
{
    if(PIOS_BMA180_Validate(dev) != 0)
        return -1;

    dev->bandwidth = bw;

    uint8_t reg;
    reg = PIOS_BMA180_GetReg(BMA_BW_ADDR);
    reg = (reg & ~BMA_BW_MASK) | ((bw << BMA_BW_SHIFT) & BMA_BW_MASK);
    return PIOS_BMA180_SetReg(BMA_BW_ADDR, reg);
}
Ejemplo n.º 2
0
/**
 * @brief Claim the SPI bus for the accel communications and select this chip
 * \param[in] pointer which receives if a task has been woken
 * @return 0 if successful, -1 if unable to claim bus
 */
int32_t PIOS_BMA180_ClaimBusISR(bool *woken)
{
    if(PIOS_BMA180_Validate(dev) != 0)
        return -1;

    if(PIOS_SPI_ClaimBusISR(dev->spi_id, woken) != 0) {
        return -1;
    }

    PIOS_SPI_RC_PinSet(dev->spi_id,dev->slave_num,0);
    return 0;
}
Ejemplo n.º 3
0
/**
 * @brief Read a register from BMA180
 * @returns The register value or -1 if failure to get bus
 * @param reg[in] Register address to be read
 */
int32_t PIOS_BMA180_GetReg(uint8_t reg)
{
	if(PIOS_BMA180_Validate(dev) != 0)
		return -1;

	uint8_t data;
	
	if(PIOS_BMA180_ClaimBus() != 0)
		return -1;	

	PIOS_SPI_TransferByte(dev->spi_id,(0x80 | reg) ); // request byte
	data = PIOS_SPI_TransferByte(dev->spi_id,0 );     // receive response
	
	PIOS_BMA180_ReleaseBus();
	return data;
}
Ejemplo n.º 4
0
/**
 * @brief Returns the scale the BMA180 chip is using
 * @return Scale (m / s^2) / LSB
 */
float PIOS_BMA180_GetScale()
{
	if(PIOS_BMA180_Validate(dev) != 0)
		return -1;

	switch (dev->cfg->range) {
		case BMA_RANGE_1G:
			return GRAVITY / 8192.0f;
		case BMA_RANGE_1_5G:
			return GRAVITY / 5460.0f;
		case BMA_RANGE_2G:
			return GRAVITY / 4096.0f;
		case BMA_RANGE_3G:
			return GRAVITY / 2730.0f;
		case BMA_RANGE_4G:
			return GRAVITY / 2048.0f;
		case BMA_RANGE_8G:
			return GRAVITY / 1024.0f;
		case BMA_RANGE_16G:
			return GRAVITY / 512.0f;
	}
	return 0;
}