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 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_spi_master.h"
38 #include "spi_specifics.h"
39 #include "drv_analog_in.h"
40 
61 #define GAINAMP_CHANNEL_A_x0 0x00
62 #define GAINAMP_CHANNEL_A_x1 0x01
63 #define GAINAMP_CHANNEL_A_x2 0x02
64 #define GAINAMP_CHANNEL_A_x5 0x03
65 #define GAINAMP_CHANNEL_A_x10 0x04
66 #define GAINAMP_CHANNEL_A_x20 0x05
67 #define GAINAMP_CHANNEL_A_x50 0x06
68 #define GAINAMP_CHANNEL_A_x100 0x07
69 #define GAINAMP_CHANNEL_A_SHUTDOWN 0x08
70 
71 #define GAINAMP_CHANNEL_B_x0 0x00
72 #define GAINAMP_CHANNEL_B_x1 0x10
73 #define GAINAMP_CHANNEL_B_x2 0x20
74 #define GAINAMP_CHANNEL_B_x5 0x30
75 #define GAINAMP_CHANNEL_B_x10 0x40
76 #define GAINAMP_CHANNEL_B_x20 0x50
77 #define GAINAMP_CHANNEL_B_x50 0x60
78 #define GAINAMP_CHANNEL_B_x100 0x70
79 #define GAINAMP_CHANNEL_B_SHUTDOWN 0x80
80 
89 #define GAINAMP_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
90 #define GAINAMP_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
91  // gainamp_set
93 
108 #define GAINAMP_MAP_MIKROBUS( cfg, mikrobus ) \
109  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
110  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
111  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
112  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
113  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
114  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST )
115  // gainamp_map // gainamp
118 
123 typedef struct
124 {
125  // Output pins
126  digital_out_t rst;
128  // Modules
129  spi_master_t spi;
131  pin_name_t chip_select;
132  analog_in_t adc;
134 } gainamp_t;
135 
140 typedef struct
141 {
142  // Communication gpio pins
143  pin_name_t miso;
144  pin_name_t mosi;
145  pin_name_t sck;
146  pin_name_t cs;
148  // Additional gpio pins
149  pin_name_t rst;
151  // static variable
152  uint32_t spi_speed;
153  spi_master_mode_t spi_mode;
154  spi_master_chip_select_polarity_t cs_polarity;
156  pin_name_t an;
158  analog_in_resolution_t resolution;
159  float vref;
161 } gainamp_cfg_t;
162 
167 typedef enum
168 {
170  GAINAMP_ERROR = -1
171 
173 
190 
205 err_t gainamp_init ( gainamp_t *ctx, gainamp_cfg_t *cfg );
206 
222 err_t gainamp_generic_write ( gainamp_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
223 
239 err_t gainamp_generic_read ( gainamp_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
240 
252 err_t gainamp_read_an_pin_value ( gainamp_t *ctx, uint16_t *data_out );
253 
268 err_t gainamp_read_an_pin_voltage ( gainamp_t *ctx, float *data_out );
269 
277 void gainamp_reset ( gainamp_t *ctx );
278 
287 void gainamp_set_gain ( gainamp_t *ctx, uint8_t gain );
288 
289 #ifdef __cplusplus
290 }
291 #endif
292 #endif // GAINAMP_H
293  // gainamp
295 
296 // ------------------------------------------------------------------------ END
gainamp_cfg_t::cs
pin_name_t cs
Definition: gainamp.h:146
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:144
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:152
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:132
gainamp_return_value_t
gainamp_return_value_t
GainAMP Click return value data.
Definition: gainamp.h:168
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:149
gainamp_cfg_t::miso
pin_name_t miso
Definition: gainamp.h:143
gainamp_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: gainamp.h:153
gainamp_cfg_t
GainAMP Click configuration object.
Definition: gainamp.h:141
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:169
gainamp_t::rst
digital_out_t rst
Definition: gainamp.h:126
gainamp_t::chip_select
pin_name_t chip_select
Definition: gainamp.h:131
gainamp_init
err_t gainamp_init(gainamp_t *ctx, gainamp_cfg_t *cfg)
GainAMP initialization function.
GAINAMP_ERROR
@ GAINAMP_ERROR
Definition: gainamp.h:170
gainamp_cfg_t::an
pin_name_t an
Definition: gainamp.h:156
gainamp_cfg_t::resolution
analog_in_resolution_t resolution
Definition: gainamp.h:158
gainamp_t::spi
spi_master_t spi
Definition: gainamp.h:129
gainamp_cfg_t::vref
float vref
Definition: gainamp.h:159
gainamp_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: gainamp.h:154
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:145
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:124