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
32extern "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
106 // 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
130 // gainamp_map
131 // gainamp
132
137typedef 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
154typedef 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;
176
181typedef enum
182{
184 GAINAMP_ERROR = -1
185
187
204
220
236err_t gainamp_generic_write ( gainamp_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
237
253err_t gainamp_generic_read ( gainamp_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
254
266err_t gainamp_read_an_pin_value ( gainamp_t *ctx, uint16_t *data_out );
267
282err_t gainamp_read_an_pin_voltage ( gainamp_t *ctx, float *data_out );
283
292
301void gainamp_set_gain ( gainamp_t *ctx, uint8_t gain );
302
303#ifdef __cplusplus
304}
305#endif
306#endif // GAINAMP_H
307
308 // gainamp
309
310// ------------------------------------------------------------------------ END
gainamp_return_value_t
GainAMP Click return value data.
Definition gainamp.h:182
@ GAINAMP_OK
Definition gainamp.h:183
@ GAINAMP_ERROR
Definition gainamp.h:184
void gainamp_set_gain(gainamp_t *ctx, uint8_t gain)
Function for sets gain of the GainAMP Click.
err_t gainamp_init(gainamp_t *ctx, gainamp_cfg_t *cfg)
GainAMP initialization function.
err_t gainamp_generic_write(gainamp_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
GainAMP data writing function.
void gainamp_reset(gainamp_t *ctx)
Function for reset chip of the GainAMP Click.
void gainamp_cfg_setup(gainamp_cfg_t *cfg)
GainAMP configuration object setup function.
err_t gainamp_read_an_pin_voltage(gainamp_t *ctx, float *data_out)
GainAMP read AN pin voltage level function.
err_t gainamp_generic_read(gainamp_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
GainAMP data reading function.
err_t gainamp_read_an_pin_value(gainamp_t *ctx, uint16_t *data_out)
GainAMP read AN pin value function.
This file contains SPI specific macros, functions, etc.
GainAMP Click configuration object.
Definition gainamp.h:155
analog_in_resolution_t resolution
Definition gainamp.h:172
float vref
Definition gainamp.h:173
spi_master_chip_select_polarity_t cs_polarity
Definition gainamp.h:168
pin_name_t sck
Definition gainamp.h:159
spi_master_mode_t spi_mode
Definition gainamp.h:167
pin_name_t mosi
Definition gainamp.h:158
uint32_t spi_speed
Definition gainamp.h:166
pin_name_t miso
Definition gainamp.h:157
pin_name_t rst
Definition gainamp.h:163
pin_name_t an
Definition gainamp.h:170
pin_name_t cs
Definition gainamp.h:160
GainAMP Click context object.
Definition gainamp.h:138
spi_master_t spi
Definition gainamp.h:143
digital_out_t rst
Definition gainamp.h:140
pin_name_t chip_select
Definition gainamp.h:145
analog_in_t adc
Definition gainamp.h:146