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
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
123typedef 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
140typedef 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;
162
167typedef enum
168{
170 GAINAMP_ERROR = -1
171
173
190
206
222err_t gainamp_generic_write ( gainamp_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
223
239err_t gainamp_generic_read ( gainamp_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
240
252err_t gainamp_read_an_pin_value ( gainamp_t *ctx, uint16_t *data_out );
253
268err_t gainamp_read_an_pin_voltage ( gainamp_t *ctx, float *data_out );
269
278
287void 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_return_value_t
GainAMP Click return value data.
Definition: gainamp.h:168
@ GAINAMP_OK
Definition: gainamp.h:169
@ GAINAMP_ERROR
Definition: gainamp.h:170
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:141
analog_in_resolution_t resolution
Definition: gainamp.h:158
float vref
Definition: gainamp.h:159
spi_master_chip_select_polarity_t cs_polarity
Definition: gainamp.h:154
pin_name_t sck
Definition: gainamp.h:145
spi_master_mode_t spi_mode
Definition: gainamp.h:153
pin_name_t mosi
Definition: gainamp.h:144
uint32_t spi_speed
Definition: gainamp.h:152
pin_name_t miso
Definition: gainamp.h:143
pin_name_t rst
Definition: gainamp.h:149
pin_name_t an
Definition: gainamp.h:156
pin_name_t cs
Definition: gainamp.h:146
GainAMP Click context object.
Definition: gainamp.h:124
spi_master_t spi
Definition: gainamp.h:129
digital_out_t rst
Definition: gainamp.h:126
pin_name_t chip_select
Definition: gainamp.h:131
analog_in_t adc
Definition: gainamp.h:132