<commit_before>/*
 * Copyright (C) 2014 Freie Universität Berlin
 *
 * This file is subject to the terms and conditions of the GNU Lesser
 * General Public License v2.1. See the file LICENSE in the top level
 * directory for more details.
 */

/**
 * @ingroup     drivers_lsm303dlhc
 * @{
 *
 * @file
 * @brief       Device driver implementation for the LSM303DLHC 3D accelerometer/magnetometer.
 *
 * @author      <NAME> <thomas.eichinger@fu-berlin.de>
 * @author      <NAME> <<EMAIL>>
 *
 * @}
 */

#include "lsm303dlhc.h"
#include "lsm303dlhc-internal.h"

#define ENABLE_DEBUG    (0)
#include "debug.h"

#define DEV_I2C         (dev->params.i2c)
#define DEV_ACC_ADDR    (dev->params.acc_addr)
#define DEV_ACC_PIN     (dev->params.acc_pin)
#define DEV_ACC_RATE    (dev->params.acc_rate)
#define DEV_ACC_SCALE   (dev->params.acc_scale)
#define DEV_MAG_ADDR    (dev->params.mag_addr)
#define DEV_MAG_PIN     (dev->params.mag_pin)
#define DEV_MAG_RATE    (dev->params.mag_rate)
#define DEV_MAG_GAIN    (dev->params.mag_gain)

int lsm303dlhc_init(lsm303dlhc_t *dev, const lsm303dlhc_params_t *params)
{
    dev->params = *params;

    int res;
    uint8_t tmp;

    /* Acquire exclusive access to the bus. */
    i2c_acquire(DEV_I2C);

    DEBUG("lsm303dlhc reboot...");
    res = i2c_write_reg(DEV_I2C, DEV_ACC_ADDR,
                        LSM303DLHC_REG_CTRL5_A, LSM303DLHC_REG_CTRL5_A_BOOT, 0);
    /* Release the bus for other threads. */
    i2c_release(DEV_I2C);
    DEBUG("[OK]\n");

    /* configure accelerometer */
    /* enable all three axis and set sample rate */
    tmp = (LSM303DLHC_CTRL1_A_XEN
          | LSM303DLHC_CTRL1_A_YEN
          | LSM303DLHC_CTRL1_A_ZEN
          | DEV_ACC_RATE);
    i2c_acquire(DEV_I2C);
    res += i2c_write_reg(DEV_I2C, DEV_ACC_ADDR,
                         LSM303DLHC_REG_CTRL1_A, tmp, 0);
    /* update on read, MSB @ low address, scale and high-resolution */
    tmp = (DEV_ACC_SCALE | LSM303DLHC_CTRL4_A_HR);
    res += i2c_write_reg(DEV_I2C, DEV_ACC_ADDR,
                         LSM303DLHC_REG_CTRL4_A, tmp, 0);
    /* no interrupt generation */
    res += i2c_write_reg(DEV_I2C, DEV_ACC_ADDR,
                         LSM303DLHC_REG_CTRL3_A, LSM303DLHC_CTRL3_A_I1_NONE, 0);
    /* configure acc data ready pin */
    gpio_init(DEV_ACC_PIN, GPIO_IN);

    /* configure magnetometer and temperature */
    /* enable temperature output and set sample rate */
    tmp = LSM303DLHC_TEMP_EN | DEV_MAG_RATE;
    res += i2c_write_reg(DEV_I2C, DEV_MAG_ADDR,
                         LSM303DLHC_REG_CRA_M, tmp, 0);
    /* configure z-axis gain */
    res += i2c_write_reg(DEV_I2C, DEV_MAG_ADDR,
                         LSM303DLHC_REG_CRB_M, DEV_MAG_GAIN, 0);
    /* set continuous mode */
    res += i2c_write_reg(DEV_I2C, DEV_MAG_ADDR,
                         LSM303DLHC_REG_MR_M, LSM303DLHC_MAG_MODE_CONTINUOUS, 0);
    i2c_release(DEV_I2C);
    /* configure mag data ready pin */
    gpio_init(DEV_MAG_PIN, GPIO_IN);
<commit_msg>drivers/lsm303dlhc: improve debug message during init<commit_after>/*
 * Copyright (C) 2014 Freie Universität Berlin
 *
 * This file is subject to the terms and conditions of the GNU Lesser
 * General Public License v2.1. See the file LICENSE in the top level
 * directory for more details.
 */

/**
 * @ingroup     drivers_lsm303dlhc
 * @{
 *
 * @file
 * @brief       Device driver implementation for the LSM303DLHC 3D accelerometer/magnetometer.
 *
 * @author      <NAME> <thomas.eichinger@fu-berlin.de>
 * @author      <NAME> <<EMAIL>>
 *
 * @}
 */

#include "lsm303dlhc.h"
#include "lsm303dlhc-internal.h"

#define ENABLE_DEBUG    (0)
#include "debug.h"

#define DEV_I2C         (dev->params.i2c)
#define DEV_ACC_ADDR    (dev->params.acc_addr)
#define DEV_ACC_PIN     (dev->params.acc_pin)
#define DEV_ACC_RATE    (dev->params.acc_rate)
#define DEV_ACC_SCALE   (dev->params.acc_scale)
#define DEV_MAG_ADDR    (dev->params.mag_addr)
#define DEV_MAG_PIN     (dev->params.mag_pin)
#define DEV_MAG_RATE    (dev->params.mag_rate)
#define DEV_MAG_GAIN    (dev->params.mag_gain)

int lsm303dlhc_init(lsm303dlhc_t *dev, const lsm303dlhc_params_t *params)
{
    dev->params = *params;

    int res;
    uint8_t tmp;

    DEBUG("lsm303dlhc init...");
    /* Acquire exclusive access to the bus. */
    i2c_acquire(DEV_I2C);

    /* reboot sensor */
    res = i2c_write_reg(DEV_I2C, DEV_ACC_ADDR,
                        LSM303DLHC_REG_CTRL5_A, LSM303DLHC_REG_CTRL5_A_BOOT, 0);
    /* Release the bus for other threads. */
    i2c_release(DEV_I2C);

    /* configure accelerometer */
    /* enable all three axis and set sample rate */
    tmp = (LSM303DLHC_CTRL1_A_XEN
          | LSM303DLHC_CTRL1_A_YEN
          | LSM303DLHC_CTRL1_A_ZEN
          | DEV_ACC_RATE);
    i2c_acquire(DEV_I2C);
    res += i2c_write_reg(DEV_I2C, DEV_ACC_ADDR,
                         LSM303DLHC_REG_CTRL1_A, tmp, 0);
    /* update on read, MSB @ low address, scale and high-resolution */
    tmp = (DEV_ACC_SCALE | LSM303DLHC_CTRL4_A_HR);
    res += i2c_write_reg(DEV_I2C, DEV_ACC_ADDR,
                         LSM303DLHC_REG_CTRL4_A, tmp, 0);
    /* no interrupt generation */
    res += i2c_write_reg(DEV_I2C, DEV_ACC_ADDR,
                         LSM303DLHC_REG_CTRL3_A, LSM303DLHC_CTRL3_A_I1_NONE, 0);
    /* configure acc data ready pin */
    gpio_init(DEV_ACC_PIN, GPIO_IN);

    /* configure magnetometer and temperature */
    /* enable temperature output and set sample rate */
    tmp = LSM303DLHC_TEMP_EN | DEV_MAG_RATE;
    res += i2c_write_reg(DEV_I2C, DEV_MAG_ADDR,
                         LSM303DLHC_REG_CRA_M, tmp, 0);
    /* configure z-axis gain */
    res += i2c_write_reg(DEV_I2C, DEV_MAG_ADDR,
                         LSM303DLHC_REG_CRB_M, DEV_MAG_GAIN, 0);
    /* set continuous mode */
    res += i2c_write_reg(DEV_I2C, DEV_MAG_ADDR,
                         LSM303DLHC_REG_MR_M, LSM303DLHC_MAG_MODE_CONTINUOUS, 0);
    i2c_release(DEV_I2C);
    /* configure mag data ready pin */
    gpio_init(DEV_MAG_PIN, GPIO_IN);
    if (ENABLE_DEBUG && res == 0) {
        DEBUG("[OK]\n");
    }
    else {
        DEBUG("[Failed]\n");
    }

{'fraction_non_alphanumeric': 0.1046777886817141, 'fraction_numerical': 0.0399084069349035, 'mean_word_length': 2.802860696517413, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3928112', 'n_tokens_mistral': 2467, 'n_tokens_neox': 2283, 'n_words': 467}