gainamp  2.0.0.0
gainamp.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 GAINAMP_H
29 #define GAINAMP_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
39 #ifdef PREINIT_SUPPORTED
40 #include "preinit.h"
41 #endif
42 
43 #ifdef MikroCCoreVersion
44  #if MikroCCoreVersion >= 1
45  #include "delays.h"
46  #endif
47 #endif
48 
49 #include "drv_digital_out.h"
50 #include "drv_digital_in.h"
51 #include "drv_spi_master.h"
52 #include "spi_specifics.h"
53 #include "drv_analog_in.h"
54 
75 #define GAINAMP_CHANNEL_A_x0 0x00
76 #define GAINAMP_CHANNEL_A_x1 0x01
77 #define GAINAMP_CHANNEL_A_x2 0x02
78 #define GAINAMP_CHANNEL_A_x5 0x03
79 #define GAINAMP_CHANNEL_A_x10 0x04
80 #define GAINAMP_CHANNEL_A_x20 0x05
81 #define GAINAMP_CHANNEL_A_x50 0x06
82 #define GAINAMP_CHANNEL_A_x100 0x07
83 #define GAINAMP_CHANNEL_A_SHUTDOWN 0x08
84 
85 #define GAINAMP_CHANNEL_B_x0 0x00
86 #define GAINAMP_CHANNEL_B_x1 0x10
87 #define GAINAMP_CHANNEL_B_x2 0x20
88 #define GAINAMP_CHANNEL_B_x5 0x30
89 #define GAINAMP_CHANNEL_B_x10 0x40
90 #define GAINAMP_CHANNEL_B_x20 0x50
91 #define GAINAMP_CHANNEL_B_x50 0x60
92 #define GAINAMP_CHANNEL_B_x100 0x70
93 #define GAINAMP_CHANNEL_B_SHUTDOWN 0x80
94 
103 #define GAINAMP_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
104 #define GAINAMP_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
105  // gainamp_set
107 
122 #define GAINAMP_MAP_MIKROBUS( cfg, mikrobus ) \
123  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
124  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
125  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
126  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
127  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
128  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST )
129  // gainamp_map // gainamp
132 
137 typedef struct
138 {
139  // Output pins
140  digital_out_t rst;
142  // Modules
143  spi_master_t spi;
145  pin_name_t chip_select;
146  analog_in_t adc;
148 } gainamp_t;
149 
154 typedef struct
155 {
156  // Communication gpio pins
157  pin_name_t miso;
158  pin_name_t mosi;
159  pin_name_t sck;
160  pin_name_t cs;
162  // Additional gpio pins
163  pin_name_t rst;
165  // static variable
166  uint32_t spi_speed;
167  spi_master_mode_t spi_mode;
168  spi_master_chip_select_polarity_t cs_polarity;
170  pin_name_t an;
172  analog_in_resolution_t resolution;
173  float vref;
175 } gainamp_cfg_t;
176 
181 typedef enum
182 {
184  GAINAMP_ERROR = -1
185 
187 
204 
219 err_t gainamp_init ( gainamp_t *ctx, gainamp_cfg_t *cfg );
220 
236 err_t gainamp_generic_write ( gainamp_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
237 
253 err_t gainamp_generic_read ( gainamp_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
254 
266 err_t gainamp_read_an_pin_value ( gainamp_t *ctx, uint16_t *data_out );
267 
282 err_t gainamp_read_an_pin_voltage ( gainamp_t *ctx, float *data_out );
283 
291 void gainamp_reset ( gainamp_t *ctx );
292 
301 void gainamp_set_gain ( gainamp_t *ctx, uint8_t gain );
302 
303 #ifdef __cplusplus
304 }
305 #endif
306 #endif // GAINAMP_H
307  // gainamp
309 
310 // ------------------------------------------------------------------------ END
gainamp_cfg_t::cs
pin_name_t cs
Definition: gainamp.h:160
gainamp_reset
void gainamp_reset(gainamp_t *ctx)
Function for reset chip of the GainAMP Click.
gainamp_cfg_t::mosi
pin_name_t mosi
Definition: gainamp.h:158
spi_specifics.h
This file contains SPI specific macros, functions, etc.
gainamp_generic_read
err_t gainamp_generic_read(gainamp_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
GainAMP data reading function.
gainamp_cfg_t::spi_speed
uint32_t spi_speed
Definition: gainamp.h:166
gainamp_cfg_setup
void gainamp_cfg_setup(gainamp_cfg_t *cfg)
GainAMP configuration object setup function.
gainamp_t::adc
analog_in_t adc
Definition: gainamp.h:146
gainamp_return_value_t
gainamp_return_value_t
GainAMP Click return value data.
Definition: gainamp.h:182
gainamp_read_an_pin_voltage
err_t gainamp_read_an_pin_voltage(gainamp_t *ctx, float *data_out)
GainAMP read AN pin voltage level function.
gainamp_cfg_t::rst
pin_name_t rst
Definition: gainamp.h:163
gainamp_cfg_t::miso
pin_name_t miso
Definition: gainamp.h:157
gainamp_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: gainamp.h:167
gainamp_cfg_t
GainAMP Click configuration object.
Definition: gainamp.h:155
gainamp_generic_write
err_t gainamp_generic_write(gainamp_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
GainAMP data writing function.
GAINAMP_OK
@ GAINAMP_OK
Definition: gainamp.h:183
gainamp_t::rst
digital_out_t rst
Definition: gainamp.h:140
gainamp_t::chip_select
pin_name_t chip_select
Definition: gainamp.h:145
gainamp_init
err_t gainamp_init(gainamp_t *ctx, gainamp_cfg_t *cfg)
GainAMP initialization function.
GAINAMP_ERROR
@ GAINAMP_ERROR
Definition: gainamp.h:184
gainamp_cfg_t::an
pin_name_t an
Definition: gainamp.h:170
gainamp_cfg_t::resolution
analog_in_resolution_t resolution
Definition: gainamp.h:172
gainamp_t::spi
spi_master_t spi
Definition: gainamp.h:143
gainamp_cfg_t::vref
float vref
Definition: gainamp.h:173
gainamp_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: gainamp.h:168
gainamp_set_gain
void gainamp_set_gain(gainamp_t *ctx, uint8_t gain)
Function for sets gain of the GainAMP Click.
gainamp_cfg_t::sck
pin_name_t sck
Definition: gainamp.h:159
gainamp_read_an_pin_value
err_t gainamp_read_an_pin_value(gainamp_t *ctx, uint16_t *data_out)
GainAMP read AN pin value function.
gainamp_t
GainAMP Click context object.
Definition: gainamp.h:138