Contiki 3.x
|
Interface of LIS3DH SPI driver used in the Mulle platform.More...
#include <stdint.h>
Go to the source code of this file.
Macros | |
#define | LIS3DH_WHO_AM_I_RESPONSE (0b00110011) |
The WHO_AM_I register should contain this value in order to correctly identify the chip. | |
#define | LIS3DH_TEMP_CFG_REG_ADC_PD_MASK (1 << 7) |
ADC enable. More... | |
#define | LIS3DH_TEMP_CFG_REG_TEMP_EN_MASK (1 << 6) |
Temperature sensor (T) enable. More... | |
#define | LIS3DH_CTRL_REG1_ODR_SHIFT (4) |
Data rate selection. More... | |
#define | LIS3DH_CTRL_REG1_LPEN_MASK (1 << 3) |
Low power mode enable. More... | |
#define | LIS3DH_CTRL_REG1_ZEN_MASK (1 << LIS3DH_CTRL_REG1_ZEN_SHIFT) |
Z axis enable. More... | |
#define | LIS3DH_CTRL_REG1_YEN_MASK (1 << LIS3DH_CTRL_REG1_YEN_SHIFT) |
Y axis enable. More... | |
#define | LIS3DH_CTRL_REG1_XEN_MASK (1 << LIS3DH_CTRL_REG1_XEN_SHIFT) |
X axis enable. More... | |
#define | LIS3DH_AXES_XYZ (LIS3DH_CTRL_REG1_XYZEN_MASK) |
Convenience macro for enabling all axes. | |
#define | LIS3DH_CTRL_REG2_HPM1_MASK (1 << 7) |
High pass filter mode selection. More... | |
#define | LIS3DH_CTRL_REG2_HPCF2_MASK (1 << 5) |
High pass filter cut off frequency selection. | |
#define | LIS3DH_CTRL_REG2_FDS_MASK (1 << 3) |
Filtered data selection. More... | |
#define | LIS3DH_CTRL_REG2_HPCLICK_MASK (1 << 2) |
High pass filter enabled for CLICK function. More... | |
#define | LIS3DH_CTRL_REG2_HPIS2_MASK (1 << 1) |
High pass filter enabled for AOI function on interrupt 2, (0: filter bypassed; 1: filter enabled) | |
#define | LIS3DH_CTRL_REG3_I1_CLICK_MASK (1 << 7) |
CLICK interrupt on INT1. More... | |
#define | LIS3DH_CTRL_REG3_I1_AOI1_MASK (1 << 6) |
AOI1 interrupt on INT1. More... | |
#define | LIS3DH_CTRL_REG3_I1_AOI2_MASK (1 << 5) |
AOI2 interrupt on INT1. More... | |
#define | LIS3DH_CTRL_REG3_I1_DRDY1_MASK (1 << 4) |
DRDY1 interrupt on INT1. More... | |
#define | LIS3DH_CTRL_REG3_I1_DRDY2_MASK (1 << 3) |
DRDY2 interrupt on INT1. More... | |
#define | LIS3DH_CTRL_REG3_I1_WTM_MASK (1 << 2) |
FIFO Watermark interrupt on INT1. More... | |
#define | LIS3DH_CTRL_REG3_I1_OVERRUN_MASK (1 << 1) |
FIFO Overrun interrupt on INT1. More... | |
#define | LIS3DH_CTRL_REG4_BDU_MASK (1 << 7) |
Block data update. More... | |
#define | LIS3DH_CTRL_REG4_BLE_MASK (1 << 6) |
Big/little endian data selection. More... | |
#define | LIS3DH_CTRL_REG4_FS1_MASK (1 << 5) |
Full scale selection. More... | |
#define | LIS3DH_CTRL_REG4_HR_MASK (1 << 3) |
High resolution output mode: Default value: 0 (0: High resolution disable; 1: High resolution Enable) | |
#define | LIS3DH_CTRL_REG4_ST1_MASK (1 << 2) |
Self test enable. More... | |
#define | LIS3DH_CTRL_REG4_SIM_MASK (1 << 0) |
SPI serial interface mode selection. More... | |
#define | LIS3DH_CTRL_REG5_REBOOT_MASK (1 << 7) |
Reboot memory content. More... | |
#define | LIS3DH_CTRL_REG5_FIFO_EN_MASK (1 << 6) |
FIFO enable. More... | |
#define | LIS3DH_CTRL_REG5_LIR_I1_MASK (1 << 3) |
Latch interrupt request on INT1_SRC register, with INT1_SRC register cleared by reading INT1_SRC itself. More... | |
#define | LIS3DH_CTRL_REG5_D4D_I1_MASK (1 << 2) |
4D enable: 4D detection is enabled on INT1 when 6D bit on INT1_CFG is set to 1. | |
#define | LIS3DH_STATUS_REG_ZYXOR_MASK (1 << 7) |
X, Y and Z axis data overrun. More... | |
#define | LIS3DH_STATUS_REG_ZOR_MASK (1 << 6) |
Z axis data overrun. More... | |
#define | LIS3DH_STATUS_REG_YOR_MASK (1 << 5) |
Y axis data overrun. More... | |
#define | LIS3DH_STATUS_REG_XOR_MASK (1 << 4) |
X axis data overrun. More... | |
#define | LIS3DH_STATUS_REG_ZYXDA_MASK (1 << 3) |
X, Y and Z axis new data available. More... | |
#define | LIS3DH_STATUS_REG_ZDA_MASK (1 << 2) |
Z axis new data available. More... | |
#define | LIS3DH_STATUS_REG_YDA_MASK (1 << 1) |
Y axis new data available. More... | |
#define | LIS3DH_STATUS_REG_XDA_MASK (1 << 0) |
X axis new data available. More... | |
#define | LIS3DH_SPI_READ_MASK (1 << 7) |
The READ bit must be set when reading. | |
#define | LIS3DH_SPI_MULTI_MASK (1 << 6) |
Multi byte transfers must assert this bit when writing the address. | |
#define | LIS3DH_SPI_SINGLE_MASK (0 << 6) |
Opposite of LIS3DH_SPI_MULTI_MASK. | |
#define | LIS3DH_SPI_ADDRESS_MASK (0x3F) |
Mask of the address bits in the address byte during transfers. | |
#define | LIS3DH_ACC_DATA_SIZE (2) |
Length of X, Y, Z data in bytes. | |
Enumerations | |
enum | lis3dh_reg_addr_t |
All LIS3DH hardware registers are enumerated here. | |
enum | lis3dh_odr_t |
Allowed values for the Output Data Rate of the sensor. More... | |
enum | lis3dh_scale_t |
Scale parameters, use these names when calling lis3dh_set_scale(scale). | |
enum | lis3dh_fifo_mode_t |
Allowed FIFO modes. More... | |
Functions | |
void | lis3dh_set_bits (const lis3dh_reg_addr_t addr, const uint8_t bitmask) |
Set bits of an 8-bit register on the LIS3DH. | |
void | lis3dh_clear_bits (const lis3dh_reg_addr_t addr, const uint8_t bitmask) |
Clear bits of an 8-bit register on the LIS3DH. | |
int16_t | lis3dh_read_xaxis () |
Get one X-axis reading from the accelerometer. More... | |
int16_t | lis3dh_read_yaxis () |
Get one Y-axis reading from the accelerometer. More... | |
int16_t | lis3dh_read_zaxis () |
Get one Z-axis reading from the accelerometer. More... | |
void | lis3dh_read_xyz (int16_t *buffer) |
Read all three axes in a single transaction. More... | |
int16_t | lis3dh_read_aux_adc1 () |
Get one reading from the first channel of the auxiliary ADC. More... | |
int16_t | lis3dh_read_aux_adc2 () |
Get one reading from the second channel of the auxiliary ADC. More... | |
int16_t | lis3dh_read_aux_adc3 () |
Get one reading from the third channel of the auxiliary ADC. More... | |
void | lis3dh_set_aux_adc (const uint8_t enable, const uint8_t temperature) |
Turn on/off power to the auxiliary ADC in LIS3DH. More... | |
void | lis3dh_set_axes (const uint8_t axes) |
Enable/disable accelerometer axes. More... | |
void | lis3dh_set_fifo_mode (const lis3dh_fifo_mode_t mode) |
Set the FIFO mode. More... | |
void | lis3dh_set_fifo (const uint8_t enable) |
Enable/disable the FIFO. More... | |
void | lis3dh_set_odr (const lis3dh_odr_t odr) |
Set the output data rate of the sensor. More... | |
void | lis3dh_set_scale (const lis3dh_scale_t scale) |
Set the full scale range of the sensor. More... | |
void | lis3dh_init () |
Initialize a LIS3DH accelerometer. More... | |
void | lis3dh_write_byte (const lis3dh_reg_addr_t addr, const uint8_t value) |
Write a single byte to the LIS3DH. More... | |
uint8_t | lis3dh_read_byte (const lis3dh_reg_addr_t addr) |
Read a single byte from the LIS3DH. More... | |
int16_t | lis3dh_read_int16 (const lis3dh_reg_addr_t lsb_addr) |
Read a 16-bit integer from the LIS3DH. More... | |
void | lis3dh_memcpy_from_device (const lis3dh_reg_addr_t start_address, uint8_t *buffer, uint8_t count) |
Read multiple bytes from the LIS3DH. More... | |
void | lis3dh_memcpy_to_device (const lis3dh_reg_addr_t start_address, const uint8_t *buffer, uint8_t count) |
Write multiple bytes to the LIS3DH. More... | |
void | lis3dh_arch_init () |
Perform the platform specific part of the initialization process of the LIS3DH. More... | |
Interface of LIS3DH SPI driver used in the Mulle platform.
Definition in file lis3dh.h.
#define LIS3DH_CTRL_REG1_LPEN_MASK (1 << 3) |
#define LIS3DH_CTRL_REG1_ODR_SHIFT (4) |
Data rate selection.
Default value: 00 (0000: Power down; Others: Refer to Table 25, “Data rate configuration”)
Definition at line 118 of file lis3dh.h.
Referenced by lis3dh_set_odr().
#define LIS3DH_CTRL_REG1_XEN_MASK (1 << LIS3DH_CTRL_REG1_XEN_SHIFT) |
#define LIS3DH_CTRL_REG1_YEN_MASK (1 << LIS3DH_CTRL_REG1_YEN_SHIFT) |
#define LIS3DH_CTRL_REG1_ZEN_MASK (1 << LIS3DH_CTRL_REG1_ZEN_SHIFT) |
#define LIS3DH_CTRL_REG2_FDS_MASK (1 << 3) |
#define LIS3DH_CTRL_REG2_HPCLICK_MASK (1 << 2) |
#define LIS3DH_CTRL_REG2_HPM1_MASK (1 << 7) |
#define LIS3DH_CTRL_REG3_I1_AOI1_MASK (1 << 6) |
#define LIS3DH_CTRL_REG3_I1_AOI2_MASK (1 << 5) |
#define LIS3DH_CTRL_REG3_I1_CLICK_MASK (1 << 7) |
#define LIS3DH_CTRL_REG3_I1_DRDY1_MASK (1 << 4) |
#define LIS3DH_CTRL_REG3_I1_DRDY2_MASK (1 << 3) |
#define LIS3DH_CTRL_REG3_I1_OVERRUN_MASK (1 << 1) |
#define LIS3DH_CTRL_REG3_I1_WTM_MASK (1 << 2) |
#define LIS3DH_CTRL_REG4_BDU_MASK (1 << 7) |
#define LIS3DH_CTRL_REG4_BLE_MASK (1 << 6) |
#define LIS3DH_CTRL_REG4_FS1_MASK (1 << 5) |
#define LIS3DH_CTRL_REG4_SIM_MASK (1 << 0) |
#define LIS3DH_CTRL_REG4_ST1_MASK (1 << 2) |
#define LIS3DH_CTRL_REG5_FIFO_EN_MASK (1 << 6) |
FIFO enable.
Default value: 0 (0: FIFO disable; 1: FIFO Enable)
Definition at line 340 of file lis3dh.h.
Referenced by lis3dh_set_fifo().
#define LIS3DH_CTRL_REG5_LIR_I1_MASK (1 << 3) |
#define LIS3DH_CTRL_REG5_REBOOT_MASK (1 << 7) |
#define LIS3DH_STATUS_REG_XDA_MASK (1 << 0) |
#define LIS3DH_STATUS_REG_XOR_MASK (1 << 4) |
#define LIS3DH_STATUS_REG_YDA_MASK (1 << 1) |
#define LIS3DH_STATUS_REG_YOR_MASK (1 << 5) |
#define LIS3DH_STATUS_REG_ZDA_MASK (1 << 2) |
#define LIS3DH_STATUS_REG_ZOR_MASK (1 << 6) |
#define LIS3DH_STATUS_REG_ZYXDA_MASK (1 << 3) |
#define LIS3DH_STATUS_REG_ZYXOR_MASK (1 << 7) |
#define LIS3DH_TEMP_CFG_REG_ADC_PD_MASK (1 << 7) |
ADC enable.
Default value: 0 (0: ADC disabled; 1: ADC enabled)
Definition at line 107 of file lis3dh.h.
Referenced by lis3dh_set_aux_adc().
#define LIS3DH_TEMP_CFG_REG_TEMP_EN_MASK (1 << 6) |
Temperature sensor (T) enable.
Default value: 0 (0: T disabled; 1: T enabled)
Definition at line 112 of file lis3dh.h.
Referenced by lis3dh_set_aux_adc().
enum lis3dh_fifo_mode_t |
enum lis3dh_odr_t |
void lis3dh_arch_init | ( | ) |
Perform the platform specific part of the initialization process of the LIS3DH.
This function is expected to set up the SPI module for the LIS3DH.
Definition at line 231 of file lis3dh-arch.c.
References PORTD, SIM, and SPI0.
Referenced by lis3dh_init().
void lis3dh_init | ( | ) |
Initialize a LIS3DH accelerometer.
Definition at line 261 of file lis3dh.c.
References lis3dh_arch_init(), lis3dh_read_byte(), LIS3DH_WHO_AM_I_RESPONSE, and lis3dh_write_byte().
void lis3dh_memcpy_from_device | ( | const lis3dh_reg_addr_t | start_address, |
uint8_t * | buffer, | ||
uint8_t | count | ||
) |
Read multiple bytes from the LIS3DH.
start_address | The lower address of the source registers. |
buffer | A buffer to write the read values into. |
count | Number of bytes to read. |
Definition at line 160 of file lis3dh-arch.c.
References LIS3DH_SPI_ADDRESS_MASK, LIS3DH_SPI_MULTI_MASK, and LIS3DH_SPI_READ_MASK.
Referenced by lis3dh_read_xyz().
void lis3dh_memcpy_to_device | ( | const lis3dh_reg_addr_t | start_address, |
const uint8_t * | buffer, | ||
uint8_t | count | ||
) |
Write multiple bytes to the LIS3DH.
start_address | The lower address of the target registers. |
buffer | A buffer to read the values from. |
count | Number of bytes to write. |
Definition at line 197 of file lis3dh-arch.c.
References LIS3DH_SPI_ADDRESS_MASK, and LIS3DH_SPI_MULTI_MASK.
int16_t lis3dh_read_aux_adc1 | ( | ) |
Get one reading from the first channel of the auxiliary ADC.
Definition at line 134 of file lis3dh.c.
References lis3dh_read_int16().
int16_t lis3dh_read_aux_adc2 | ( | ) |
Get one reading from the second channel of the auxiliary ADC.
Definition at line 144 of file lis3dh.c.
References lis3dh_read_int16().
int16_t lis3dh_read_aux_adc3 | ( | ) |
Get one reading from the third channel of the auxiliary ADC.
Definition at line 157 of file lis3dh.c.
References lis3dh_read_int16().
uint8_t lis3dh_read_byte | ( | const lis3dh_reg_addr_t | addr | ) |
Read a single byte from the LIS3DH.
addr | The source register. |
Definition at line 109 of file lis3dh-arch.c.
References LIS3DH_SPI_ADDRESS_MASK, LIS3DH_SPI_READ_MASK, and LIS3DH_SPI_SINGLE_MASK.
Referenced by lis3dh_clear_bits(), lis3dh_init(), lis3dh_set_bits(), and lis3dh_write_bits().
int16_t lis3dh_read_int16 | ( | const lis3dh_reg_addr_t | lsb_addr | ) |
Read a 16-bit integer from the LIS3DH.
lsb_addr | The lower address of the two source registers. |
Definition at line 127 of file lis3dh-arch.c.
References LIS3DH_SPI_ADDRESS_MASK, LIS3DH_SPI_MULTI_MASK, and LIS3DH_SPI_READ_MASK.
Referenced by lis3dh_read_aux_adc1(), lis3dh_read_aux_adc2(), lis3dh_read_aux_adc3(), lis3dh_read_xaxis(), lis3dh_read_yaxis(), and lis3dh_read_zaxis().
int16_t lis3dh_read_xaxis | ( | ) |
Get one X-axis reading from the accelerometer.
Definition at line 93 of file lis3dh.c.
References lis3dh_read_int16().
void lis3dh_read_xyz | ( | int16_t * | buffer | ) |
Read all three axes in a single transaction.
buffer | Pointer to an int16_t[3] buffer. |
Definition at line 123 of file lis3dh.c.
References LIS3DH_ACC_DATA_SIZE, and lis3dh_memcpy_from_device().
int16_t lis3dh_read_yaxis | ( | ) |
Get one Y-axis reading from the accelerometer.
Definition at line 103 of file lis3dh.c.
References lis3dh_read_int16().
int16_t lis3dh_read_zaxis | ( | ) |
Get one Z-axis reading from the accelerometer.
Definition at line 113 of file lis3dh.c.
References lis3dh_read_int16().
void lis3dh_set_aux_adc | ( | const uint8_t | enable, |
const uint8_t | temperature | ||
) |
Turn on/off power to the auxiliary ADC in LIS3DH.
enable | Power state of the auxiliary ADC |
temperature | If not zero, switch the ADC mux so that a temperature reading is available on OUT_3_L, OUT_3_H. |
Definition at line 172 of file lis3dh.c.
References LIS3DH_TEMP_CFG_REG_ADC_PD_MASK, LIS3DH_TEMP_CFG_REG_TEMP_EN_MASK, and lis3dh_write_bits().
void lis3dh_set_axes | ( | const uint8_t | axes | ) |
Enable/disable accelerometer axes.
axes | An OR-ed combination of LIS3DH_AXES_X, LIS3DH_AXES_Y, LIS3DH_AXES_Z. |
Definition at line 186 of file lis3dh.c.
References lis3dh_write_bits().
void lis3dh_set_fifo | ( | const uint8_t | enable | ) |
Enable/disable the FIFO.
enable | If zero, disable the FIFO, otherwise enables the FIFO. |
Definition at line 207 of file lis3dh.c.
References LIS3DH_CTRL_REG5_FIFO_EN_MASK, and lis3dh_write_bits().
void lis3dh_set_fifo_mode | ( | const lis3dh_fifo_mode_t | mode | ) |
Set the FIFO mode.
mode | The chosen FIFO mode. |
Definition at line 196 of file lis3dh.c.
References lis3dh_write_bits().
void lis3dh_set_odr | ( | const lis3dh_odr_t | odr | ) |
Set the output data rate of the sensor.
odr | Chosen output data rate. |
Definition at line 218 of file lis3dh.c.
References LIS3DH_CTRL_REG1_ODR_SHIFT, and lis3dh_write_bits().
void lis3dh_set_scale | ( | const lis3dh_scale_t | scale | ) |
Set the full scale range of the sensor.
Valid values for scale is 2, 4, 8, 16 and represents the full range of the sensor.
scale | The chosen sensitivity scale. |
Definition at line 231 of file lis3dh.c.
References lis3dh_write_bits().
void lis3dh_write_byte | ( | const lis3dh_reg_addr_t | addr, |
const uint8_t | value | ||
) |
Write a single byte to the LIS3DH.
addr | The target register. |
value | The value to write. |
Definition at line 95 of file lis3dh-arch.c.
References LIS3DH_SPI_ADDRESS_MASK, and LIS3DH_SPI_SINGLE_MASK.
Referenced by lis3dh_clear_bits(), lis3dh_init(), lis3dh_set_bits(), and lis3dh_write_bits().