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 
38 #include "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_spi_master.h"
51 #include "drv_analog_in.h"
52 
53 // -------------------------------------------------------------- PUBLIC MACROS
64 #define GAINAMP2_MAP_MIKROBUS( cfg, mikrobus ) \
65  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
66  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
67  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
68  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
69  cfg.vout = MIKROBUS( mikrobus, MIKROBUS_AN )
70 
76 #define GAINAMP2_RETVAL uint8_t
77 
82 #define GAINAMP2_OK 0x00
83 #define GAINAMP2_INIT_ERROR 0xFF
84 
90 #define GAINAMP2_NOP_INS 0x00
91 #define GAINAMP2_SHUTDOWN_INS 0x20
92 #define GAINAMP2_WRITE_INS 0x40
93 
99 #define GAINAMP2_CH 0x01
100 #define GAINAMP2_GAIN 0x00
101 
107 #define GAINAMP2_GAIN_1X 0x00
108 #define GAINAMP2_GAIN_2X 0x01
109 #define GAINAMP2_GAIN_4X 0x02
110 #define GAINAMP2_GAIN_5X 0x03
111 #define GAINAMP2_GAIN_8X 0x04
112 #define GAINAMP2_GAIN_10X 0x05
113 #define GAINAMP2_GAIN_16X 0x06
114 #define GAINAMP2_GAIN_32X 0x07
115 
121 #define GAINAMP2_CH0 0x00
122 #define GAINAMP2_CH1 0x01
123 #define GAINAMP2_CH2 0x02
124 #define GAINAMP2_CH3 0x03
125 #define GAINAMP2_CH4 0x04
126 #define GAINAMP2_CH5 0x05
127  // End group macro
130 // --------------------------------------------------------------- PUBLIC TYPES
139 typedef struct
140 {
141  // Output pins
142 
143  digital_out_t cs;
144 
145  // Modules
146 
147  spi_master_t spi;
148  pin_name_t chip_select;
149  analog_in_t adc;
150 
151  float vref;
152 
153 } gainamp2_t;
154 
158 typedef struct
159 {
160  // Communication gpio pins
161 
162  pin_name_t miso;
163  pin_name_t mosi;
164  pin_name_t sck;
165  pin_name_t cs;
166 
167  // Additional gpio pins
168 
169  pin_name_t vout;
170 
171  // static variable
172 
173  analog_in_resolution_t resolution;
174  float vref;
175  uint32_t spi_speed;
176  spi_master_mode_t spi_mode;
177  spi_master_chip_select_polarity_t cs_polarity;
178 
180  // End types group
182 
183 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
184 
189 #ifdef __cplusplus
190 extern "C"{
191 #endif
192 
202 
211 
223 void gainamp2_generic_transfer ( gainamp2_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len );
224 
234 void gainamp2_write_command( gainamp2_t *ctx, uint8_t instruction, uint8_t input );
235 
245 void gainamp2_set_channel_gain ( gainamp2_t *ctx, uint8_t channel, uint8_t gain );
246 
255 
256 #ifdef __cplusplus
257 }
258 #endif
259 #endif // _GAINAMP2_H_
260  // End public_function group
263 
264 // ------------------------------------------------------------------------- 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:174
gainamp2_cfg_t::vout
pin_name_t vout
Definition: gainamp2.h:169
gainamp2_cfg_t::spi_speed
uint32_t spi_speed
Definition: gainamp2.h:175
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:177
gainamp2_cfg_t::miso
pin_name_t miso
Definition: gainamp2.h:162
gainamp2_t::chip_select
pin_name_t chip_select
Definition: gainamp2.h:148
gainamp2_cfg_t
Click configuration structure definition.
Definition: gainamp2.h:159
gainamp2_t::spi
spi_master_t spi
Definition: gainamp2.h:147
gainamp2_t::adc
analog_in_t adc
Definition: gainamp2.h:149
gainamp2_cfg_t::resolution
analog_in_resolution_t resolution
Definition: gainamp2.h:173
gainamp2_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: gainamp2.h:176
gainamp2_t::cs
digital_out_t cs
Definition: gainamp2.h:143
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:165
gainamp2_cfg_t::mosi
pin_name_t mosi
Definition: gainamp2.h:163
GAINAMP2_RETVAL
#define GAINAMP2_RETVAL
Definition: gainamp2.h:76
gainamp2_t::vref
float vref
Definition: gainamp2.h:151
gainamp2_cfg_t::sck
pin_name_t sck
Definition: gainamp2.h:164
gainamp2_t
Click ctx object definition.
Definition: gainamp2.h:140
gainamp2_init
GAINAMP2_RETVAL gainamp2_init(gainamp2_t *ctx, gainamp2_cfg_t *cfg)
Initialization function.