EFM32 Happy Gecko Software Documentation  efm32hg-doc-5.1.2
si7210.h
Go to the documentation of this file.
1 /***************************************************************************/
16 #ifndef __SI7210_H_
17 #define __SI7210_H_
18 
19 #include <stdint.h>
20 #include <stdbool.h>
21 
22 #include "si7210_config.h"
24 
25 /***************************************************************************/
31 /***************************************************************************/
38 #ifndef SI7210_CONFIG_I2C_DEVICE
39  #define SI7210_CONFIG_I2C_DEVICE (I2C0)
40 #endif
41 
42 #ifndef SI7210_CONFIG_I2C_BUS_ADDRESS
43  #define SI7210_CONFIG_I2C_BUS_ADDRESS (0x30)
44 #endif
45 
46 #ifndef SI7210_CONFIG_DEVICE_ID
47  #define SI7210_CONFIG_DEVICE_ID 0x11
48 #endif
49 
50 #ifndef SI7210_CONFIG_GPIO_PORT_OUT1
51  #define SI7210_CONFIG_GPIO_PORT_OUT1 gpioPortB
52 #endif
53 
54 #ifndef SI7210_CONFIG_GPIO_PIN_OUT1
55  #define SI7210_CONFIG_GPIO_PIN_OUT1 11
56 #endif
57 
58 
59 #define SI7210_I2C_DEVICE ( SI7210_CONFIG_I2C_DEVICE )
60 #define SI7210_I2C_DEVICE_BUS_ADDRESS ( SI7210_CONFIG_I2C_BUS_ADDRESS )
61 #define SI7210_I2C_DEVICE_BUS_TIMEOUT ( SI7210_CONFIG_I2C_BUS_TIMEOUT )
62 #define SI7210_GPIO_PORT_OUT1 ( SI7210_CONFIG_GPIO_PORT_OUT1 )
63 #define SI7210_GPIO_PIN_OUT1 ( SI7210_CONFIG_GPIO_PIN_OUT1 )
64 #define SI7210_DEVICE_ID ( SI7210_CONFIG_DEVICE_ID )
69 /***************************************************************************/
76 #define SI7210_OK 0
77 #define SI7210_ERROR_I2C_TRANSFER_FAILED 0x0001
78 #define SI7210_ERROR_INVALID_DEVICE_ID 0x0002
79 #define SI7210_ERROR_CONFIG_INVALID_MODE 0x0003
80 #define SI7210_ERROR_OTP_BUSY 0x0004
81 #define SI7210_ERROR_READ_TIMEOUT 0x0005
86 /***************************************************************************/
93 #define SI7210_CONFIG_MODE_THRESHOLD 0x01
94 #define SI7210_CONFIG_MODE_MEASURE 0x02
96 #define SI7210_CONFIG_SCALE_20mT 0x00
97 #define SI7210_CONFIG_SCALE_200mT 0x01
99 #define SI7210_CONFIG_POLARITY_OMNI 0x00
100 #define SI7210_CONFIG_POLARITY_NEG 0x01
101 #define SI7210_CONFIG_POLARITY_POS 0x02
103 #define SI7210_CONFIG_THRESHOLD_MIN 0.08f
104 #define SI7210_CONFIG_THRESHOLD_MAX 19.2f
109 /***************************************************************************/
116 typedef void * SI7210_Config;
117 typedef void (*SI7210_IntCallback)(uint8_t level);
119 /***************************************************************************/
124 typedef struct __SI7210_ConfigMeasure {
125 
126  uint8_t mode;
127  uint8_t scale;
128  uint32_t samplePeriod;
130 } SI7210_ConfigMeasure;
131 
132 /***************************************************************************/
137 typedef struct __SI7210_ConfigThreshold {
138 
139  uint8_t mode;
140  SI7210_IntCallback callback;
141  float threshold;
142  float hysteresis;
143  uint8_t polarity;
144  bool outputInvert;
146 } SI7210_ConfigThreshold;
147 
151 /***************************************************************************/
158 uint32_t SI7210_init ( void );
159 void SI7210_deInit ( void );
160 uint32_t SI7210_config ( SI7210_Config config );
161 uint32_t SI7210_measure ( float *result );
162 uint32_t SI7210_suspend ( void );
163 
164 uint32_t SI7210_regRead ( uint8_t addr, uint8_t *data );
165 uint32_t SI7210_regWrite ( uint8_t addr, uint8_t data );
166 uint32_t SI7210_regSetBits ( uint8_t addr, uint8_t mask );
167 uint32_t SI7210_regClearBits ( uint8_t addr, uint8_t mask );
168 uint32_t SI7210_regReadOTP ( uint8_t otpAddr, uint8_t *otpData );
169 
176 #endif /* __SI7210_H_ */
Driver for the Silicon Labs Si7210 Hall Effect Sensor.
uint32_t SI7210_regRead(uint8_t addr, uint8_t *data)
Reads register from the Si7021 device.
Definition: si7210.c:423
uint32_t SI7210_suspend(void)
Puts the Si7210 chip in sleep mode.
Definition: si7210.c:170
uint32_t SI7210_regSetBits(uint8_t addr, uint8_t mask)
Sets the given bit(s) in a register in the Si7021 device.
Definition: si7210.c:497
uint32_t SI7210_measure(float *result)
Performs a measurement.
Definition: si7210.c:374
void SI7210_deInit(void)
De-initializes the Si7210 chip. Disables the sensor power domain, this also disables other sensors...
Definition: si7210.c:150
uint32_t SI7210_regClearBits(uint8_t addr, uint8_t mask)
Clears the given bit(s) in a register in the Si7021 device.
Definition: si7210.c:531
uint32_t SI7210_init(void)
Initializes the Si7210 chip.
Definition: si7210.c:102
uint32_t SI7210_regWrite(uint8_t addr, uint8_t data)
Writes a register in the Si7021 device.
Definition: si7210.c:459
uint32_t SI7210_config(SI7210_Config config)
Configures the Si7210 chip.
Definition: si7210.c:202