gainamp2  2.0.0.0
gainamp2.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 GAINAMP2_H
36 #define GAINAMP2_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_spi_master.h"
41 #include "drv_analog_in.h"
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
54 #define GAINAMP2_MAP_MIKROBUS( cfg, mikrobus ) \
55  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
56  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
57  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
58  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
59  cfg.vout = MIKROBUS( mikrobus, MIKROBUS_AN )
60 
66 #define GAINAMP2_RETVAL uint8_t
67 
72 #define GAINAMP2_OK 0x00
73 #define GAINAMP2_INIT_ERROR 0xFF
74 
80 #define GAINAMP2_NOP_INS 0x00
81 #define GAINAMP2_SHUTDOWN_INS 0x20
82 #define GAINAMP2_WRITE_INS 0x40
83 
89 #define GAINAMP2_CH 0x01
90 #define GAINAMP2_GAIN 0x00
91 
97 #define GAINAMP2_GAIN_1X 0x00
98 #define GAINAMP2_GAIN_2X 0x01
99 #define GAINAMP2_GAIN_4X 0x02
100 #define GAINAMP2_GAIN_5X 0x03
101 #define GAINAMP2_GAIN_8X 0x04
102 #define GAINAMP2_GAIN_10X 0x05
103 #define GAINAMP2_GAIN_16X 0x06
104 #define GAINAMP2_GAIN_32X 0x07
105 
111 #define GAINAMP2_CH0 0x00
112 #define GAINAMP2_CH1 0x01
113 #define GAINAMP2_CH2 0x02
114 #define GAINAMP2_CH3 0x03
115 #define GAINAMP2_CH4 0x04
116 #define GAINAMP2_CH5 0x05
117  // End group macro
120 // --------------------------------------------------------------- PUBLIC TYPES
129 typedef struct
130 {
131  // Output pins
132 
133  digital_out_t cs;
134 
135  // Modules
136 
137  spi_master_t spi;
138  pin_name_t chip_select;
139  analog_in_t adc;
140 
141  float vref;
142 
143 } gainamp2_t;
144 
148 typedef struct
149 {
150  // Communication gpio pins
151 
152  pin_name_t miso;
153  pin_name_t mosi;
154  pin_name_t sck;
155  pin_name_t cs;
156 
157  // Additional gpio pins
158 
159  pin_name_t vout;
160 
161  // static variable
162 
163  analog_in_resolution_t resolution;
164  float vref;
165  uint32_t spi_speed;
166  spi_master_mode_t spi_mode;
167  spi_master_chip_select_polarity_t cs_polarity;
168 
170  // End types group
172 
173 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
174 
179 #ifdef __cplusplus
180 extern "C"{
181 #endif
182 
191 void gainamp2_cfg_setup ( gainamp2_cfg_t *cfg );
192 
201 
213 void gainamp2_generic_transfer ( gainamp2_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len );
214 
224 void gainamp2_write_command( gainamp2_t *ctx, uint8_t instruction, uint8_t input );
225 
235 void gainamp2_set_channel_gain ( gainamp2_t *ctx, uint8_t channel, uint8_t gain );
236 
244 float gainamp2_get_voltage ( gainamp2_t *ctx );
245 
246 #ifdef __cplusplus
247 }
248 #endif
249 #endif // _GAINAMP2_H_
250  // End public_function group
253 
254 // ------------------------------------------------------------------------- END
gainamp2_cfg_setup
void gainamp2_cfg_setup(gainamp2_cfg_t *cfg)
Config Object Initialization function.
gainamp2_get_voltage
float gainamp2_get_voltage(gainamp2_t *ctx)
Return voltage measured from OUT pin.
gainamp2_cfg_t::vref
float vref
Definition: gainamp2.h:164
gainamp2_cfg_t::vout
pin_name_t vout
Definition: gainamp2.h:159
gainamp2_cfg_t::spi_speed
uint32_t spi_speed
Definition: gainamp2.h:165
gainamp2_generic_transfer
void gainamp2_generic_transfer(gainamp2_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len)
Generic transfer function.
gainamp2_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: gainamp2.h:167
gainamp2_cfg_t::miso
pin_name_t miso
Definition: gainamp2.h:152
gainamp2_t::chip_select
pin_name_t chip_select
Definition: gainamp2.h:138
gainamp2_cfg_t
Click configuration structure definition.
Definition: gainamp2.h:148
gainamp2_t::spi
spi_master_t spi
Definition: gainamp2.h:137
gainamp2_t::adc
analog_in_t adc
Definition: gainamp2.h:139
gainamp2_cfg_t::resolution
analog_in_resolution_t resolution
Definition: gainamp2.h:163
gainamp2_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: gainamp2.h:166
gainamp2_t::cs
digital_out_t cs
Definition: gainamp2.h:133
gainamp2_write_command
void gainamp2_write_command(gainamp2_t *ctx, uint8_t instruction, uint8_t input)
Send Command.
gainamp2_set_channel_gain
void gainamp2_set_channel_gain(gainamp2_t *ctx, uint8_t channel, uint8_t gain)
Set the channel gain.
gainamp2_cfg_t::cs
pin_name_t cs
Definition: gainamp2.h:155
gainamp2_cfg_t::mosi
pin_name_t mosi
Definition: gainamp2.h:153
GAINAMP2_RETVAL
#define GAINAMP2_RETVAL
Definition: gainamp2.h:66
gainamp2_t::vref
float vref
Definition: gainamp2.h:141
gainamp2_cfg_t::sck
pin_name_t sck
Definition: gainamp2.h:154
gainamp2_t
Click ctx object definition.
Definition: gainamp2.h:129
gainamp2_init
GAINAMP2_RETVAL gainamp2_init(gainamp2_t *ctx, gainamp2_cfg_t *cfg)
Initialization function.