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 )
74 
80 #define GAINAMP2_RETVAL uint8_t
81 
86 #define GAINAMP2_OK 0x00
87 #define GAINAMP2_INIT_ERROR 0xFF
88 
94 #define GAINAMP2_NOP_INS 0x00
95 #define GAINAMP2_SHUTDOWN_INS 0x20
96 #define GAINAMP2_WRITE_INS 0x40
97 
103 #define GAINAMP2_CH 0x01
104 #define GAINAMP2_GAIN 0x00
105 
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
119 
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
131  // End group macro
134 // --------------------------------------------------------------- PUBLIC TYPES
143 typedef 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 
162 typedef 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  // End types group
186 
187 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
188 
193 #ifdef __cplusplus
194 extern "C"{
195 #endif
196 
206 
215 
227 void gainamp2_generic_transfer ( gainamp2_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len );
228 
238 void gainamp2_write_command( gainamp2_t *ctx, uint8_t instruction, uint8_t input );
239 
249 void 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  // End public_function group
267 
268 // ------------------------------------------------------------------------- END
gainamp2_cfg_setup
void gainamp2_cfg_setup(gainamp2_cfg_t *cfg)
Config Object Initialization function.
gainamp2_get_voltage
float gainamp2_get_voltage(gainamp2_t *ctx)
Return voltage measured from OUT pin.
gainamp2_cfg_t::vref
float vref
Definition: gainamp2.h:178
gainamp2_cfg_t::vout
pin_name_t vout
Definition: gainamp2.h:173
gainamp2_cfg_t::spi_speed
uint32_t spi_speed
Definition: gainamp2.h:179
gainamp2_generic_transfer
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.
gainamp2_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: gainamp2.h:181
gainamp2_cfg_t::miso
pin_name_t miso
Definition: gainamp2.h:166
gainamp2_t::chip_select
pin_name_t chip_select
Definition: gainamp2.h:152
gainamp2_cfg_t
Click configuration structure definition.
Definition: gainamp2.h:163
gainamp2_t::spi
spi_master_t spi
Definition: gainamp2.h:151
gainamp2_t::adc
analog_in_t adc
Definition: gainamp2.h:153
gainamp2_cfg_t::resolution
analog_in_resolution_t resolution
Definition: gainamp2.h:177
gainamp2_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: gainamp2.h:180
gainamp2_t::cs
digital_out_t cs
Definition: gainamp2.h:147
gainamp2_write_command
void gainamp2_write_command(gainamp2_t *ctx, uint8_t instruction, uint8_t input)
Send Command.
gainamp2_set_channel_gain
void gainamp2_set_channel_gain(gainamp2_t *ctx, uint8_t channel, uint8_t gain)
Set the channel gain.
gainamp2_cfg_t::cs
pin_name_t cs
Definition: gainamp2.h:169
gainamp2_cfg_t::mosi
pin_name_t mosi
Definition: gainamp2.h:167
GAINAMP2_RETVAL
#define GAINAMP2_RETVAL
Definition: gainamp2.h:80
gainamp2_t::vref
float vref
Definition: gainamp2.h:155
gainamp2_cfg_t::sck
pin_name_t sck
Definition: gainamp2.h:168
gainamp2_t
Click ctx object definition.
Definition: gainamp2.h:144
gainamp2_init
GAINAMP2_RETVAL gainamp2_init(gainamp2_t *ctx, gainamp2_cfg_t *cfg)
Initialization function.