hallswitch3  2.1.0.0
hallswitch3.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2020 MikroElektronika d.o.o.
3 ** Contact: https://www.mikroe.com/contact
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 ** of this software and associated documentation files (the "Software"), to deal
7 ** in the Software without restriction, including without limitation the rights
8 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 ** copies of the Software, and to permit persons to whom the Software is
10 ** furnished to do so, subject to the following conditions:
11 ** The above copyright notice and this permission notice shall be
12 ** included in all copies or substantial portions of the Software.
13 **
14 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 ** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 ** USE OR OTHER DEALINGS IN THE SOFTWARE.
21 ****************************************************************************/
22 
28 #ifndef HALLSWITCH3_H
29 #define HALLSWITCH3_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_i2c_master.h"
38 
59 #define HALLSWITCH3_REG_STATUS 0x00
60 #define HALLSWITCH3_REG_CONTROL_REG1 0x01
61 #define HALLSWITCH3_REG_OUT_M_REG 0x03
62 #define HALLSWITCH3_REG_USER_ASSERT_THRESH 0x04
63 #define HALLSWITCH3_REG_USER_CLEAR_THRESH 0x05
64 #define HALLSWITCH3_REG_USER_ODR 0x06
65 #define HALLSWITCH3_REG_WHO_AM_I 0x08
66 #define HALLSWITCH3_REG_I2C_ADDR 0x09
67  // hallswitch3_reg
69 
84 #define HALLSWITCH3_STATUS_OUT_B_CLEAR 0x00
85 #define HALLSWITCH3_STATUS_OUT_B_ASSERT 0x01
86 #define HALLSWITCH3_STATUS_RST_COMPLETE 0x00
87 #define HALLSWITCH3_STATUS_RST_NOT_COMPLETE 0x02
88 #define HALLSWITCH3_STATUS_OPMODE_SA 0x00
89 #define HALLSWITCH3_STATUS_OPMODE_I2C 0x08
90 #define HALLSWITCH3_STATUS_MDR_DATA_RDY 0x00
91 #define HALLSWITCH3_STATUS_MDR_DATA_NO_RDY 0x20
92 #define HALLSWITCH3_STATUS_MDO_DATA_OK 0x00
93 #define HALLSWITCH3_STATUS_MDO_DATA_FAULT 0x40
94 #define HALLSWITCH3_STATUS_VOUT_LOW 0x00
95 #define HALLSWITCH3_STATUS_VOUT_HIGH 0x80
96 
101 #define HALLSWITCH3_CONTROL_SW_RESET 0x01
102 #define HALLSWITCH3_CONTROL_ONE_SHOT 0x04
103 #define HALLSWITCH3_CONTROL_AUTO_STOP 0x00
104 #define HALLSWITCH3_CONTROL_AUTO_START 0x08
105 #define HALLSWITCH3_CONTROL_V_POL_ASSERT_H 0x00
106 #define HALLSWITCH3_CONTROL_V_POL_ASSERT_L 0x20
107 
112 #define HALLSWITCH3_ASSERT_THOLD_DEFAULT 0x10
113 #define HALLSWITCH3_CLEAR_THOLD_DEFAULT 0x15
114 #define HALLSWITCH3_THOLD_BITMASK 0x1F
115 
120 #define HALLSWITCH3_OUT_M_RES_RST 0x00
121 #define HALLSWITCH3_OUT_M_RES_LOWEST 0x01
122 #define HALLSWITCH3_OUT_M_RES_HIGHEST 0x1F
123 
128 #define HALLSWITCH3_USER_ODR_LSP 0x1F
129 #define HALLSWITCH3_USER_ODR_LSP 0x00
130 #define HALLSWITCH3_USER_ODR_LSP_X5 0x01
131 #define HALLSWITCH3_USER_ODR_MSP 0x02
132 #define HALLSWITCH3_USER_ODR_MSP_X5 0x03
133 #define HALLSWITCH3_USER_ODR_HSP 0x04
134 #define HALLSWITCH3_USER_ODR_HSP_X5 0x05
135 #define HALLSWITCH3_USER_ODR_HSP_X10 0x06
136 #define HALLSWITCH3_USER_ODR_CFG_ERR 0x07
137 
142 #define HALLSWITCH3_OUT_STATE_LOW 0x00
143 #define HALLSWITCH3_OUT_STATE_HIGH 0x01
144 
149 #define HALLSWITCH3_WHO_AM_I 0x01
150 
156 #define HALLSWITCH3_DEVICE_ADDRESS 0x60
157  // hallswitch3_set
159 
174 #define HALLSWITCH3_MAP_MIKROBUS( cfg, mikrobus ) \
175  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
176  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
177  cfg.out = MIKROBUS( mikrobus, MIKROBUS_INT )
178  // hallswitch3_map // hallswitch3
181 
186 typedef struct
187 {
188  // Input pins
189  digital_in_t out;
191  // Modules
192  i2c_master_t i2c;
194  // I2C slave address
195  uint8_t slave_address;
197 } hallswitch3_t;
198 
203 typedef struct
204 {
205  pin_name_t scl;
206  pin_name_t sda;
208  pin_name_t out;
210  uint32_t i2c_speed;
211  uint8_t i2c_address;
214 
219 typedef enum
220 {
222  HALLSWITCH3_ERROR = -1
223 
225 
242 
257 
271 
285 err_t hallswitch3_reg_write ( hallswitch3_t *ctx, uint8_t reg, uint8_t data_in );
286 
300 err_t hallswitch3_reg_read ( hallswitch3_t *ctx, uint8_t reg, uint8_t *data_out );
301 
314 err_t hallswitch3_get_status ( hallswitch3_t *ctx, uint8_t *status );
315 
328 
342 
356 
370 err_t hallswitch3_set_vpol ( hallswitch3_t *ctx, uint8_t v_pol );
371 
384 err_t hallswitch3_get_mag_data ( hallswitch3_t *ctx, int8_t *mag_data );
385 
399 err_t hallswitch3_set_threshold ( hallswitch3_t *ctx, uint8_t assert_thold, uint8_t clear_thold );
400 
414 err_t hallswitch3_set_out_data_rate ( hallswitch3_t *ctx, uint8_t odr );
415 
428 err_t hallswitch3_get_device_id ( hallswitch3_t *ctx, uint8_t *device_id );
429 
441 
442 #ifdef __cplusplus
443 }
444 #endif
445 #endif // HALLSWITCH3_H
446  // hallswitch3
448 
449 // ------------------------------------------------------------------------ END
hallswitch3_t::i2c
i2c_master_t i2c
Definition: hallswitch3.h:192
hallswitch3_t::out
digital_in_t out
Definition: hallswitch3.h:189
hallswitch3_get_status
err_t hallswitch3_get_status(hallswitch3_t *ctx, uint8_t *status)
Hall Switch 3 get status function.
HALLSWITCH3_OK
@ HALLSWITCH3_OK
Definition: hallswitch3.h:221
hallswitch3_init
err_t hallswitch3_init(hallswitch3_t *ctx, hallswitch3_cfg_t *cfg)
Hall Switch 3 initialization function.
hallswitch3_cfg_t::i2c_address
uint8_t i2c_address
Definition: hallswitch3.h:211
HALLSWITCH3_ERROR
@ HALLSWITCH3_ERROR
Definition: hallswitch3.h:222
hallswitch3_autonomous_mode
err_t hallswitch3_autonomous_mode(hallswitch3_t *ctx)
Hall Switch 3 autonomous mode function.
hallswitch3_cfg_t
Hall Switch 3 Click configuration object.
Definition: hallswitch3.h:204
hallswitch3_set_threshold
err_t hallswitch3_set_threshold(hallswitch3_t *ctx, uint8_t assert_thold, uint8_t clear_thold)
Hall Switch 3 sets assert and clear threshold function.
hallswitch3_t::slave_address
uint8_t slave_address
Definition: hallswitch3.h:195
hallswitch3_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: hallswitch3.h:210
hallswitch3_reset
err_t hallswitch3_reset(hallswitch3_t *ctx)
Hall Switch 3 software reset function.
hallswitch3_get_device_id
err_t hallswitch3_get_device_id(hallswitch3_t *ctx, uint8_t *device_id)
Hall Switch 3 get device ID function.
hallswitch3_reg_read
err_t hallswitch3_reg_read(hallswitch3_t *ctx, uint8_t reg, uint8_t *data_out)
Hall Switch 3 I2C reading function.
hallswitch3_cfg_t::sda
pin_name_t sda
Definition: hallswitch3.h:206
hallswitch3_check_mag_field
uint8_t hallswitch3_check_mag_field(hallswitch3_t *ctx)
Hall Switch 3 check magnetic field function.
hallswitch3_set_one_shot
err_t hallswitch3_set_one_shot(hallswitch3_t *ctx)
Hall Switch 3 sets one-shot function.
hallswitch3_t
Hall Switch 3 Click context object.
Definition: hallswitch3.h:187
hallswitch3_get_mag_data
err_t hallswitch3_get_mag_data(hallswitch3_t *ctx, int8_t *mag_data)
Hall Switch 3 get mag data function.
hallswitch3_return_value_t
hallswitch3_return_value_t
Hall Switch 3 Click return value data.
Definition: hallswitch3.h:220
hallswitch3_reg_write
err_t hallswitch3_reg_write(hallswitch3_t *ctx, uint8_t reg, uint8_t data_in)
Hall Switch 3 I2C writing function.
hallswitch3_cfg_t::out
pin_name_t out
Definition: hallswitch3.h:208
hallswitch3_cfg_setup
void hallswitch3_cfg_setup(hallswitch3_cfg_t *cfg)
Hall Switch 3 configuration object setup function.
hallswitch3_default_cfg
err_t hallswitch3_default_cfg(hallswitch3_t *ctx)
Hall Switch 3 default configuration function.
hallswitch3_set_vpol
err_t hallswitch3_set_vpol(hallswitch3_t *ctx, uint8_t v_pol)
Hall Switch 3 set VPOL function.
hallswitch3_cfg_t::scl
pin_name_t scl
Definition: hallswitch3.h:205
hallswitch3_set_out_data_rate
err_t hallswitch3_set_out_data_rate(hallswitch3_t *ctx, uint8_t odr)
Hall Switch 3 sets output data rates function.