gainamp2 2.0.0.0
gainamp2.h
Go to the documentation of this file.
1/*
2 * MikroSDK - MikroE Software Development Kit
3 * Copyright© 2020 MikroElektronika d.o.o.
4 *
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without restriction,
8 * including without limitation the rights to use, copy, modify, merge,
9 * publish, distribute, sublicense, and/or sell copies of the Software,
10 * and to permit persons to whom the Software is furnished to do so,
11 * subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22 * OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
33// ----------------------------------------------------------------------------
34
35#ifndef GAINAMP2_H
36#define GAINAMP2_H
37
42#ifdef PREINIT_SUPPORTED
43#include "preinit.h"
44#endif
45
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
48 #include "delays.h"
49 #endif
50#endif
51
52#include "drv_digital_out.h"
53#include "drv_digital_in.h"
54#include "drv_spi_master.h"
55#include "drv_analog_in.h"
56
57// -------------------------------------------------------------- PUBLIC MACROS
68#define GAINAMP2_MAP_MIKROBUS( cfg, mikrobus ) \
69 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
70 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
71 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
72 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
73 cfg.vout = MIKROBUS( mikrobus, MIKROBUS_AN )
80#define GAINAMP2_RETVAL uint8_t
81
86#define GAINAMP2_OK 0x00
87#define GAINAMP2_INIT_ERROR 0xFF
94#define GAINAMP2_NOP_INS 0x00
95#define GAINAMP2_SHUTDOWN_INS 0x20
96#define GAINAMP2_WRITE_INS 0x40
103#define GAINAMP2_CH 0x01
104#define GAINAMP2_GAIN 0x00
111#define GAINAMP2_GAIN_1X 0x00
112#define GAINAMP2_GAIN_2X 0x01
113#define GAINAMP2_GAIN_4X 0x02
114#define GAINAMP2_GAIN_5X 0x03
115#define GAINAMP2_GAIN_8X 0x04
116#define GAINAMP2_GAIN_10X 0x05
117#define GAINAMP2_GAIN_16X 0x06
118#define GAINAMP2_GAIN_32X 0x07
125#define GAINAMP2_CH0 0x00
126#define GAINAMP2_CH1 0x01
127#define GAINAMP2_CH2 0x02
128#define GAINAMP2_CH3 0x03
129#define GAINAMP2_CH4 0x04
130#define GAINAMP2_CH5 0x05
133 // End group macro
134// --------------------------------------------------------------- PUBLIC TYPES
143typedef struct
144{
145 // Output pins
146
147 digital_out_t cs;
148
149 // Modules
150
151 spi_master_t spi;
152 pin_name_t chip_select;
153 analog_in_t adc;
154
155 float vref;
156
157} gainamp2_t;
158
162typedef struct
163{
164 // Communication gpio pins
165
166 pin_name_t miso;
167 pin_name_t mosi;
168 pin_name_t sck;
169 pin_name_t cs;
170
171 // Additional gpio pins
172
173 pin_name_t vout;
174
175 // static variable
176
177 analog_in_resolution_t resolution;
178 float vref;
179 uint32_t spi_speed;
180 spi_master_mode_t spi_mode;
181 spi_master_chip_select_polarity_t cs_polarity;
182
184
185 // End types group
186
187// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
188
193#ifdef __cplusplus
194extern "C"{
195#endif
196
206
215
227void gainamp2_generic_transfer ( gainamp2_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len );
228
238void gainamp2_write_command( gainamp2_t *ctx, uint8_t instruction, uint8_t input );
239
249void gainamp2_set_channel_gain ( gainamp2_t *ctx, uint8_t channel, uint8_t gain );
250
259
260#ifdef __cplusplus
261}
262#endif
263#endif // _GAINAMP2_H_
264
265 // End public_function group
267
268// ------------------------------------------------------------------------- END
#define GAINAMP2_RETVAL
Definition gainamp2.h:80
GAINAMP2_RETVAL gainamp2_init(gainamp2_t *ctx, gainamp2_cfg_t *cfg)
Initialization function.
void gainamp2_set_channel_gain(gainamp2_t *ctx, uint8_t channel, uint8_t gain)
Set the channel gain.
float gainamp2_get_voltage(gainamp2_t *ctx)
Return voltage measured from OUT pin.
void gainamp2_cfg_setup(gainamp2_cfg_t *cfg)
Config Object Initialization function.
void gainamp2_write_command(gainamp2_t *ctx, uint8_t instruction, uint8_t input)
Send Command.
void gainamp2_generic_transfer(gainamp2_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len)
Generic transfer function.
Click configuration structure definition.
Definition gainamp2.h:163
analog_in_resolution_t resolution
Definition gainamp2.h:177
float vref
Definition gainamp2.h:178
spi_master_chip_select_polarity_t cs_polarity
Definition gainamp2.h:181
pin_name_t sck
Definition gainamp2.h:168
spi_master_mode_t spi_mode
Definition gainamp2.h:180
pin_name_t mosi
Definition gainamp2.h:167
uint32_t spi_speed
Definition gainamp2.h:179
pin_name_t vout
Definition gainamp2.h:173
pin_name_t miso
Definition gainamp2.h:166
pin_name_t cs
Definition gainamp2.h:169
Click ctx object definition.
Definition gainamp2.h:144
digital_out_t cs
Definition gainamp2.h:147
spi_master_t spi
Definition gainamp2.h:151
float vref
Definition gainamp2.h:155
pin_name_t chip_select
Definition gainamp2.h:152
analog_in_t adc
Definition gainamp2.h:153