wheatstone  2.0.0.0
wheatstone.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright© 2020 MikroElektronika d.o.o.
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without restriction,
8  * including without limitation the rights to use, copy, modify, merge,
9  * publish, distribute, sublicense, and/or sell copies of the Software,
10  * and to permit persons to whom the Software is furnished to do so,
11  * subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22  * OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef WHEATSTONE_H
36 #define WHEATSTONE_H
37 
42 #ifdef PREINIT_SUPPORTED
43 #include "preinit.h"
44 #endif
45 
46 #ifdef MikroCCoreVersion
47  #if MikroCCoreVersion >= 1
48  #include "delays.h"
49  #endif
50 #endif
51 
52 #include "drv_digital_out.h"
53 #include "drv_digital_in.h"
54 #include "drv_spi_master.h"
55 #include "drv_analog_in.h"
56 
57 
58 // -------------------------------------------------------------- PUBLIC MACROS
69 #define WHEATSTONE_MAP_MIKROBUS( cfg, mikrobus ) \
70  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
71  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
72  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
73  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
74  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN )
75 
76 
81 #define WHEATSTONE_OK 0
82 #define WHEATSTONE_ERROR -1
83 
89 #define WHEATSTONE_POT_RESOLUTION 256
90 #define WHEATSTONE_POT_MAX 255
91 #define WHEATSTONE_POT_MIN 0
92 
98 #define WHEATSTONE_MAX_POT_KOHM 100
99 #define WHEATSTONE_R8_KOHM 1
100 #define WHEATSTONE_GAIN_R1_KOHM 1
101 #define WHEATSTONE_VCC_5V 5.0f
102 #define WHEATSTONE_VCC_3V3 3.3f
103  // End group macro
106 // --------------------------------------------------------------- PUBLIC TYPES
115 typedef struct
116 {
117  // Modules
118  spi_master_t spi;
119  analog_in_t adc;
120  pin_name_t chip_select;
121 
122  // Approximate gain output level related to the potentiometer settings
123  float gain;
124 
125 } wheatstone_t;
126 
130 typedef struct
131 {
132  // Communication gpio pins
133  pin_name_t miso;
134  pin_name_t mosi;
135  pin_name_t sck;
136  pin_name_t cs;
137  pin_name_t an;
138 
139  // static variable
140  uint32_t spi_speed;
141  spi_master_mode_t spi_mode;
142  spi_master_chip_select_polarity_t cs_polarity;
143 
144  analog_in_resolution_t resolution; // Resolution
145  float vref; // VRef
146 
148  // End types group
150 
151 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
152 
157 #ifdef __cplusplus
158 extern "C"{
159 #endif
160 
170 
179 
188 void wheatstone_set_potentiometer ( wheatstone_t *ctx, uint8_t pot_value );
189 
201 err_t wheatstone_read_an_pin_value ( wheatstone_t *ctx, uint16_t *data_out );
202 
216 err_t wheatstone_read_an_pin_voltage ( wheatstone_t *ctx, float *data_out );
217 
218 #ifdef __cplusplus
219 }
220 #endif
221 #endif // _WHEATSTONE_H_
222  // End public_function group
225 
226 // ------------------------------------------------------------------------- END
wheatstone_cfg_t::miso
pin_name_t miso
Definition: wheatstone.h:133
wheatstone_t::spi
spi_master_t spi
Definition: wheatstone.h:118
wheatstone_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: wheatstone.h:142
wheatstone_cfg_t::vref
float vref
Definition: wheatstone.h:145
wheatstone_read_an_pin_voltage
err_t wheatstone_read_an_pin_voltage(wheatstone_t *ctx, float *data_out)
Wheatstone read AN pin voltage level function.
wheatstone_cfg_t::sck
pin_name_t sck
Definition: wheatstone.h:135
wheatstone_t
Click ctx object definition.
Definition: wheatstone.h:116
wheatstone_cfg_t::spi_speed
uint32_t spi_speed
Definition: wheatstone.h:140
wheatstone_read_an_pin_value
err_t wheatstone_read_an_pin_value(wheatstone_t *ctx, uint16_t *data_out)
Wheatstone read AN pin value function.
wheatstone_t::adc
analog_in_t adc
Definition: wheatstone.h:119
wheatstone_set_potentiometer
void wheatstone_set_potentiometer(wheatstone_t *ctx, uint8_t pot_value)
Set potentiometer ( 0 - 100k )
wheatstone_t::chip_select
pin_name_t chip_select
Definition: wheatstone.h:120
wheatstone_cfg_setup
void wheatstone_cfg_setup(wheatstone_cfg_t *cfg)
Config Object Initialization function.
wheatstone_cfg_t::resolution
analog_in_resolution_t resolution
Definition: wheatstone.h:144
wheatstone_cfg_t::an
pin_name_t an
Definition: wheatstone.h:137
wheatstone_cfg_t::mosi
pin_name_t mosi
Definition: wheatstone.h:134
wheatstone_cfg_t::cs
pin_name_t cs
Definition: wheatstone.h:136
wheatstone_cfg_t
Click configuration structure definition.
Definition: wheatstone.h:131
wheatstone_t::gain
float gain
Definition: wheatstone.h:123
wheatstone_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: wheatstone.h:141
wheatstone_init
err_t wheatstone_init(wheatstone_t *ctx, wheatstone_cfg_t *cfg)
Initialization function.