LSM303DLHC Ultra Compact High Perfomance E-compass 3D Accelerometer and 3D Magnetometer module driver.
- Clone the code
git clone https://github.com/Sarlor/lsm303dlhc-driver.git
cd lsm303dlhc-driver/src/acc
- Edit the 'Makefile' file, set the correct kernel directory 'KERN_DIR'
vim Makefile
- Copy the driver files to the 'hwmon' directory
make cp
- Add board-level support code to the appropriate place
vim arch/arm/plat-s5p4418/realarm/device.c
#if defined(CONFIG_SENSORS_LSM303DLHC_ACC) || defined(CONFIG_SENSORS_LSM303DLHC_ACC_MODULE)
#include <linux/i2c.h>
/* CODEC */
static struct i2c_board_info __initdata lsm303dlhc_acc_i2c_bdi = {
.type = "lsm303dlhc_acc",
.addr = 0x19
};
#endif
#if defined(CONFIG_SENSORS_LSM303DLHC_ACC) || defined(CONFIG_SENSORS_LSM303DLHC_ACC_MODULE)
printk("plat: add accelerometer lsm303dlhc\n");
i2c_register_board_info(1, &lsm303dlhc_acc_i2c_bdi, 1);
#endif
- Modify the kernel configuration file for lsm303dlhc accelerometer
vim drivers/hwmon/Kconfig
config SENSORS_LSM303DLHC_ACC
tristate "3D accelerometer module"
depends on I2C
default n
help
Say Y here to enable the Accelerometer module.
If unsure, say N.
vim drivers/hwmon/Makefile
obj-$(CONFIG_SENSORS_LSM303DLHC_ACC) += lsm303dlhc_acc.o
- Enter the src directory, and edit Makefile file, set the correct kernel directory 'KERN_DIR'
cd src/mag
vim Makefile
- Copy the driver files to the 'hwmon' directory
make cp
- Add board-level support code to the appropriate place
vim arch/arm/plat-s5p4418/realarm/device.c
#if defined(CONFIG_SENSORS_LSM303DLHC_MAG) || defined(CONFIG_SENSORS_LSM303DLHC_MAG_MODULE)
#include <linux/i2c.h>
/* CODEC */
static struct i2c_board_info __initdata lsm303dlhc_mag_i2c_bdi = {
.type = "lsm303dlhc_mag",
.addr = 0x1E
};
#endif
#if defined(CONFIG_SENSORS_LSM303DLHC_MAG) || defined(CONFIG_SENSORS_LSM303DLHC_MAG_MODULE)
printk("plat: add magnetometer lsm303dlhc\n");
i2c_register_board_info(1, &lsm303dlhc_mag_i2c_bdi, 1);
#endif
- Modify the kernel configuration file for lsm303dlhc accelerometer
vim drivers/hwmon/Kconfig
config SENSORS_LSM303DLHC_MAG
tristate "3D magnetometer module"
depends on I2C
default n
help
Say Y here to enable the Magnetometer module.
If unsure, say N.
vim drivers/hwmon/Makefile
obj-$(CONFIG_SENSORS_LSM303DLHC_MAG) += lsm303dlhc_mag.o
make menuconfig
Device Drivers -> Hardware Monitoring support -> 3D accelerometer module && 3D magnetometer module