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 "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_spi_master.h"
48 #include "spi_specifics.h"
49 #include "drv_analog_in.h"
50 
71 #define GAINAMP_CHANNEL_A_x0 0x00
72 #define GAINAMP_CHANNEL_A_x1 0x01
73 #define GAINAMP_CHANNEL_A_x2 0x02
74 #define GAINAMP_CHANNEL_A_x5 0x03
75 #define GAINAMP_CHANNEL_A_x10 0x04
76 #define GAINAMP_CHANNEL_A_x20 0x05
77 #define GAINAMP_CHANNEL_A_x50 0x06
78 #define GAINAMP_CHANNEL_A_x100 0x07
79 #define GAINAMP_CHANNEL_A_SHUTDOWN 0x08
80 
81 #define GAINAMP_CHANNEL_B_x0 0x00
82 #define GAINAMP_CHANNEL_B_x1 0x10
83 #define GAINAMP_CHANNEL_B_x2 0x20
84 #define GAINAMP_CHANNEL_B_x5 0x30
85 #define GAINAMP_CHANNEL_B_x10 0x40
86 #define GAINAMP_CHANNEL_B_x20 0x50
87 #define GAINAMP_CHANNEL_B_x50 0x60
88 #define GAINAMP_CHANNEL_B_x100 0x70
89 #define GAINAMP_CHANNEL_B_SHUTDOWN 0x80
90 
99 #define GAINAMP_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
100 #define GAINAMP_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
101  // gainamp_set
103 
118 #define GAINAMP_MAP_MIKROBUS( cfg, mikrobus ) \
119  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
120  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
121  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
122  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
123  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
124  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST )
125  // gainamp_map // gainamp
128 
133 typedef struct
134 {
135  // Output pins
136  digital_out_t rst;
138  // Modules
139  spi_master_t spi;
141  pin_name_t chip_select;
142  analog_in_t adc;
144 } gainamp_t;
145 
150 typedef struct
151 {
152  // Communication gpio pins
153  pin_name_t miso;
154  pin_name_t mosi;
155  pin_name_t sck;
156  pin_name_t cs;
158  // Additional gpio pins
159  pin_name_t rst;
161  // static variable
162  uint32_t spi_speed;
163  spi_master_mode_t spi_mode;
164  spi_master_chip_select_polarity_t cs_polarity;
166  pin_name_t an;
168  analog_in_resolution_t resolution;
169  float vref;
171 } gainamp_cfg_t;
172 
177 typedef enum
178 {
180  GAINAMP_ERROR = -1
181 
183 
200 
215 err_t gainamp_init ( gainamp_t *ctx, gainamp_cfg_t *cfg );
216 
232 err_t gainamp_generic_write ( gainamp_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
233 
249 err_t gainamp_generic_read ( gainamp_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
250 
262 err_t gainamp_read_an_pin_value ( gainamp_t *ctx, uint16_t *data_out );
263 
278 err_t gainamp_read_an_pin_voltage ( gainamp_t *ctx, float *data_out );
279 
287 void gainamp_reset ( gainamp_t *ctx );
288 
297 void gainamp_set_gain ( gainamp_t *ctx, uint8_t gain );
298 
299 #ifdef __cplusplus
300 }
301 #endif
302 #endif // GAINAMP_H
303  // gainamp
305 
306 // ------------------------------------------------------------------------ END
gainamp_cfg_t::cs
pin_name_t cs
Definition: gainamp.h:156
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:154
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:162
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:142
gainamp_return_value_t
gainamp_return_value_t
GainAMP Click return value data.
Definition: gainamp.h:178
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:159
gainamp_cfg_t::miso
pin_name_t miso
Definition: gainamp.h:153
gainamp_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: gainamp.h:163
gainamp_cfg_t
GainAMP Click configuration object.
Definition: gainamp.h:151
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:179
gainamp_t::rst
digital_out_t rst
Definition: gainamp.h:136
gainamp_t::chip_select
pin_name_t chip_select
Definition: gainamp.h:141
gainamp_init
err_t gainamp_init(gainamp_t *ctx, gainamp_cfg_t *cfg)
GainAMP initialization function.
GAINAMP_ERROR
@ GAINAMP_ERROR
Definition: gainamp.h:180
gainamp_cfg_t::an
pin_name_t an
Definition: gainamp.h:166
gainamp_cfg_t::resolution
analog_in_resolution_t resolution
Definition: gainamp.h:168
gainamp_t::spi
spi_master_t spi
Definition: gainamp.h:139
gainamp_cfg_t::vref
float vref
Definition: gainamp.h:169
gainamp_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: gainamp.h:164
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:155
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:134