/** * @brief Set the ITG-3200 execution mode. * * This routine sets a specified ITG-3200 execution state to one of the * following: * * SENSOR_STATE_SLEEP or SENSOR_STATE_LOWEST_POWER * Setting the sleep mode puts the device into very low power sleep * mode. In this mode, only the serial interface and internal registers * remain active. * * SENSOR_STATE_NORMAL or SENSOR_STATE_HIGHEST_POWER * Sets the device to a normal operational state. * * SENSOR_STATE_RESET * Sets the device and internal registers to the power-up default * settings. * * @param sensor Address of an initialized sensor device descriptor. * @param state A specified sensor operational state. * @return bool true if the call succeeds, else false is returned. */ static bool itg3200_set_state(sensor_hal_t *hal, sensor_state_t state) { switch (state) { default: return false; case SENSOR_STATE_SLEEP: case SENSOR_STATE_LOWEST_POWER: sensor_reg_bitset(hal, ITG3200_PWR_MGM, PWR_MGM_SLEEP); break; case SENSOR_STATE_NORMAL: case SENSOR_STATE_HIGHEST_POWER: sensor_reg_bitclear(hal, ITG3200_PWR_MGM, PWR_MGM_SLEEP); delay_ms(5); break; case SENSOR_STATE_RESET: /* * \todo * * Update sensor device descriptor operational settings. */ return itg3200_default_init(hal); } return true; }
/** * @brief Analog Devices ADXL345Z accelerometer driver initialization. * * This is the main initialization function for the ADXL345Z device. * * @param sensor Address of a sensor device descriptor. * @param reserved Reserved value. * * @return bool true if the call succeeds, else false is returned. */ bool adxl345z_init(sensor_t *sensor, int reserved) { bool status = false; sensor_hal_t *const hal = sensor->hal; if (0xe5 == sensor_bus_get(hal, ADXL345Z_DEVID)) { /* Set the driver function table and capabilities pointer. */ static const sensor_device_t adxl345z_device = { .func.read = adxl345z_read, .func.ioctl = adxl345z_ioctl, .func.selftest = adxl345_selftest, .func.event = adxl345_event, .caps.feature = SENSOR_CAPS_3_AXIS | SENSOR_CAPS_SELFTEST | SENSOR_CAPS_TAP_EVENT | SENSOR_CAPS_DROP_EVENT, .caps.vendor = SENSOR_VENDOR_ADI, .caps.range_table = range_table, .caps.band_table = band_table, .caps.range_count = ARRAYSIZE(range_table), .caps.band_count = ARRAYSIZE(band_table), .caps.units = SENSOR_UNITS_g0, .caps.scale = SENSOR_SCALE_milli, .caps.name = "ADXL345Z Digital, triaxial acceleration sensor" }; sensor->drv = &adxl345z_device; /* Set the driver (device) default range, bandwidth, & * resolution. * Per the ADXL345Z Datasheet the default range and bandwidth * after device reset are +/- 2g and 100Hz respectively. */ hal->range = 2000; hal->bandwidth = 100; hal->resolution = 10; hal->burst_addr = ADXL345Z_DATAX0; /* After power is applied the device enters standby mode, where * power consumption is minimized and the device waits for the * command to enter measurement mode. While in standby mode, any * register can be read or written to configure the part. * Configure the part in standby mode prior to enabling * measurement mode. */ sensor_reg_bitset(hal, ADXL345Z_POWER_CTL, POWER_CTL_MEASURE); /* Install an interrupt handler. */ if ((STATUS_OK == hal->bus.status) && sensor_irq_connect(hal->mcu_sigint, adxl345z_isr, hal)) { status = true; } } return status; }
/** * @brief Enable or disable the BMA220 sleep mode. * * This routine enables or disables the BMA220 sleep mode depending upon * the value of the \sleep parameter; a \true value enables sleep mode and * a \false value disables sleep mode by setting or clearing the 'sleep_en' * bit, respectively. * * @param hal Address of an initialized sensor hardware descriptor. * @param sleep Set flag \true to enable sleep mode. * @return Nothing */ static inline void bma220_sleep_en(sensor_hal_t *hal, bool sleep) { if (sleep) { sensor_reg_bitset(hal, BMA220_SLEEP_CONFIG, SLEEP_ENABLE); } else { sensor_reg_bitclear(hal, BMA220_SLEEP_CONFIG, SLEEP_ENABLE); } }
/** * @brief Run BMA150 self-tests. * * @param sensor Address of an initialized sensor device descriptor. * @param test_code Address of a device-specific numeric test code. * @param arg Device-specific self-test argument options. * @return bool true if the call succeeds, else false is returned. */ static bool bma150_selftest(sensor_t *sensor, int *test_code, void *arg) { sensor_hal_t *const hal = sensor->hal; bool result = false; if (SENSOR_TEST_DEFLECTION == *test_code) { /* Execute BMA150 self-test 0; electrostatic deflection test. */ sensor_reg_bitset(hal, BMA150_CTRL1, CTRL1_SELF_TEST_0); result = (STATUS1_ST_RESULT & sensor_bus_get(hal, BMA150_STATUS1)) ? true : false; sensor_reg_bitclear(hal, BMA150_CTRL1, CTRL1_SELF_TEST_0); } else if (SENSOR_TEST_INTERRUPT == *test_code) { /* Execute BMA150 self-test 1; interrupt to MCU test. */ sensor_reg_bitset(hal, BMA150_CTRL1, CTRL1_SELF_TEST_1); } return result; }
/** * @brief Set the BMA150 execution mode. * * This routine sets a specified BMA150 execution state to one of the * following: * * SENSOR_STATE_SLEEP or SENSOR_STATE_LOWEST_POWER * Setting the sleep mode puts the BMA150 into a very low power state in * which no communication with the sensor IC is possible. The current * consumption in sleep mode is about 1 microamp. * * In case of a soft-reset, it is recommended to do the reset after * switching from sleep to operational mode. In case a soft-reset is * activated during sleep mode, it can take up to 30ms until normal * operation has resumed. * * SENSOR_STATE_LOW_POWER * This option sets the BMA150 to a low power "wake-up" mode that triggers * a system wake-up (interrupt output to master) when motion is detected. * In this mode, the device periodically evaluates acceleration data with * respect to interrupt criteria defined by the user. * * Typical current consumption in wake-up mode is estimated as follows: * @code * i_DD * t_active + i_DDsm * wake_up_pause * i_self_wake_up = ------------------------------------------ * t_active + wake_up_pause * @endcode * with approximation: * @code * t_active = 1ms + 0.333ms * [(4 * 750/bandwidth) + (1500/bandwidth) * n] * @endcode * with parameters: * @code * i_DD Normal mode current (200 microamp) * i_DDsm Sleep mode current (1 microamp) * wake_up_pause Wake-up pause setting * n Number of data points in any-motion logic (n=0 for * high-g and low-g threshold, n=3 for any-motion) * bandwidth bandwidth @ settings 1500 through 25 Hz. * @endcode * SENSOR_STATE_NORMAL or SENSOR_STATE_HIGHEST_POWER * In normal mode the sensor IC data and status registers can be accessed * without restriction. The device current consumption is 200 microamps * in this state. * * SENSOR_STATE_RESET * This function resets the device and internal registers to the power-up * default settings. * * In the wake-up mode, the BMA150 automatically switches from sleep mode to * normal mode after a delay defined by a programmable \c wake_up_pause value. * After transitioning from sleep to normal mode, acceleration data acquisition * and interrupt verification are performed. The sensor automatically returns * to sleep mode again if no interrupt criteria are satisfied. * * @param hal Address of an initialized sensor hardware descriptor. * @param state A specified sensor operational state. * @return bool true if the call succeeds, else false is returned. */ static bool bma150_set_state(sensor_hal_t *hal, sensor_state_t state) { switch (state) { case SENSOR_STATE_SLEEP: case SENSOR_STATE_LOWEST_POWER: sensor_reg_bitclear(hal, BMA150_CTRL5, CTRL5_WAKE_UP); sensor_reg_bitset(hal, BMA150_CTRL1, CTRL1_SLEEP); break; case SENSOR_STATE_LOW_POWER: sensor_reg_bitclear(hal, BMA150_CTRL1, CTRL1_SLEEP); sensor_reg_bitset(hal, BMA150_CTRL5, CTRL5_WAKE_UP); break; case SENSOR_STATE_NORMAL: case SENSOR_STATE_HIGHEST_POWER: sensor_reg_bitclear(hal, BMA150_CTRL1, CTRL1_SLEEP); sensor_reg_bitclear(hal, BMA150_CTRL5, CTRL5_WAKE_UP); break; case SENSOR_STATE_RESET: /* * \todo * * Update sensor device descriptor operational settings. */ sensor_reg_bitclear(hal, BMA150_CTRL1, CTRL1_SLEEP); sensor_bus_put(hal, BMA150_CTRL1, CTRL1_SOFT_RESET); break; default: return false; } return true; }