force5  2.0.0.0
force5.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 FORCE5_H
29 #define FORCE5_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_i2c_master.h"
48 
69 #define FORCE5_STATES_BIT_MASK 0x03
70 #define FORCE5_STATES_NORMAL_OPERATION 0x00
71 #define FORCE5_STATES_COMMAND_MODE 0x01
72 #define FORCE5_STATES_STALE_DATA 0x02
73 #define FORCE5_STATES_DIAGNOSTIC_CONDITION 0x03
74 
79 #define FORCE5_FORCE_SENSOR_10_N 10.0
80 #define FORCE5_FORCE_SENSOR_25_N 25.0
81 
82 #define FORCE5_FORCE_MAX_VALUE 14745.0
83 
89 #define FORCE5_SET_DEV_ADDR 0x28
90  // force5_set
92 
107 #define FORCE5_MAP_MIKROBUS( cfg, mikrobus ) \
108  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
109  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
110  // force5_map // force5
113 
118 typedef struct
119 {
120  // Modules
121  i2c_master_t i2c;
123  // I2C slave address
124  uint8_t slave_address;
126 } force5_t;
127 
132 typedef struct
133 {
134  pin_name_t scl;
135  pin_name_t sda;
137  uint32_t i2c_speed;
138  uint8_t i2c_address;
140 } force5_cfg_t;
141 
146 typedef struct
147 {
148  uint8_t status_data;
149  uint16_t force_data;
150  uint16_t temp_data;
152 
157 typedef struct
158 {
161 
166 typedef enum
167 {
169  FORCE5_ERROR = -1
170 
172 
189 
203 err_t force5_init ( force5_t *ctx, force5_cfg_t *cfg );
204 
219 err_t force5_generic_write ( force5_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
220 
235 err_t force5_generic_read ( force5_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
236 
250 err_t force5_read_byte ( force5_t *ctx, uint8_t *rx_data, uint8_t n_bytes );
251 
260 void force5_read_all_data ( force5_t *ctx, force5_data_t *force_data );
261 
271 uint8_t force5_get_force_value ( force5_t *ctx, uint16_t *force );
272 
282 uint8_t force5_get_temperature_value ( force5_t *ctx, uint16_t *temp );
283 
294 
304 
313 
314 #ifdef __cplusplus
315 }
316 #endif
317 #endif // FORCE5_H
318  // force5
320 
321 // ------------------------------------------------------------------------ END
force5_get_temperature
float force5_get_temperature(force5_t *ctx)
Get temperature function.
force5_cfg_t::sda
pin_name_t sda
Definition: force5.h:135
force5_t::i2c
i2c_master_t i2c
Definition: force5.h:121
force5_data_t::temp_data
uint16_t temp_data
Definition: force5.h:150
force5_data_t::force_data
uint16_t force_data
Definition: force5.h:149
force5_generic_write
err_t force5_generic_write(force5_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len)
Force 5 I2C writing function.
force5_get_force_value
uint8_t force5_get_force_value(force5_t *ctx, uint16_t *force)
Get force value function.
force5_read_byte
err_t force5_read_byte(force5_t *ctx, uint8_t *rx_data, uint8_t n_bytes)
Generic read data function.
force5_read_all_data
void force5_read_all_data(force5_t *ctx, force5_data_t *force_data)
Read all data function.
force5_cfg_t::i2c_address
uint8_t i2c_address
Definition: force5.h:138
force5_cfg_t::scl
pin_name_t scl
Definition: force5.h:134
force5_cfg_t
Force 5 Click configuration object.
Definition: force5.h:133
force5_init
err_t force5_init(force5_t *ctx, force5_cfg_t *cfg)
Force 5 initialization function.
force5_return_value_t
force5_return_value_t
Force 5 Click return value data.
Definition: force5.h:167
force5_t::slave_address
uint8_t slave_address
Definition: force5.h:124
FORCE5_OK
@ FORCE5_OK
Definition: force5.h:168
force5_data_t::status_data
uint8_t status_data
Definition: force5.h:148
force5_data_t
Force 5 Click data object.
Definition: force5.h:147
force5_t
Force 5 Click context object.
Definition: force5.h:119
force5_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: force5.h:137
force5_get_force
float force5_get_force(force5_t *ctx, force5_calibration_t calib_data)
Get force function.
force5_calibration
uint8_t force5_calibration(force5_t *ctx, force5_calibration_t *calib_data)
Calibration the sensor function.
FORCE5_ERROR
@ FORCE5_ERROR
Definition: force5.h:169
force5_generic_read
err_t force5_generic_read(force5_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
Force 5 I2C reading function.
force5_calibration_t::force_claib_data
uint16_t force_claib_data
Definition: force5.h:159
calib_data
force5_calibration_t calib_data
Definition: main.c:29
force5_calibration_t
Force 5 Click calibration object.
Definition: force5.h:158
force5_get_temperature_value
uint8_t force5_get_temperature_value(force5_t *ctx, uint16_t *temp)
Get temperature value function.
force5_cfg_setup
void force5_cfg_setup(force5_cfg_t *cfg)
Force 5 configuration object setup function.