gainamp3  2.0.0.0
gainamp3.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 GAINAMP3_H
29 #define GAINAMP3_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_spi_master.h"
48 #include "spi_specifics.h"
49 
70 #define GAINAMP3_REG_GAIN_MUX 0x00
71 #define GAINAMP3_REG_RESET 0x01
72 #define GAINAMP3_REG_SYNC_CFG 0x02
73 #define GAINAMP3_REG_DIGITAL_ERR 0x03
74 #define GAINAMP3_REG_ANALOG_ERR 0x04
75 #define GAINAMP3_REG_GPIO_DATA 0x05
76 #define GAINAMP3_REG_INPUT_MUX 0x06
77 #define GAINAMP3_REG_WB_DETECT 0x07
78 #define GAINAMP3_REG_GPIO_DIR 0x08
79 #define GAINAMP3_REG_SCS 0x09
80 #define GAINAMP3_REG_ANALOG_ERR_DIS 0x0A
81 #define GAINAMP3_REG_DIGITAL_ERR_DIS 0x0B
82 #define GAINAMP3_REG_SF_CFG 0x0C
83 #define GAINAMP3_REG_ERR_CFG 0x0D
84 #define GAINAMP3_REG_TEST_MUX 0x0E
85 #define GAINAMP3_REG_EX_CURRENT_CFG 0x0F
86 #define GAINAMP3_REG_GAIN_CAL1 0x10
87 #define GAINAMP3_REG_GAIN_CAL2 0x11
88 #define GAINAMP3_REG_GAIN_CAL3 0x12
89 #define GAINAMP3_REG_GAIN_CAL4 0x13
90 #define GAINAMP3_REG_GAIN_CAL5 0x14
91 #define GAINAMP3_REG_GAIN_CAL6 0x15
92 #define GAINAMP3_REG_GAIN_CAL7 0x16
93 #define GAINAMP3_REG_GAIN_CAL8 0x17
94 #define GAINAMP3_REG_GAIN_CAL9 0x18
95 #define GAINAMP3_REG_GAIN_CAL10 0x19
96 #define GAINAMP3_REG_GAIN_CAL11 0x1A
97 #define GAINAMP3_REG_GAIN_CAL12 0x1B
98 #define GAINAMP3_REG_GAIN_CAL13 0x1C
99 #define GAINAMP3_REG_GAIN_CAL14 0x1D
100 #define GAINAMP3_REG_GAIN_CAL15 0x1E
101 #define GAINAMP3_REG_GAIN_CAL16 0x1F
102 #define GAINAMP3_REG_GAIN_CAL17 0x20
103 #define GAINAMP3_REG_GAIN_CAL18 0x21
104 #define GAINAMP3_REG_GAIN_CAL19 0x22
105 #define GAINAMP3_REG_GAIN_CAL20 0x23
106 #define GAINAMP3_REG_GAIN_CAL21 0x24
107 #define GAINAMP3_REG_GAIN_CAL22 0x25
108 #define GAINAMP3_REG_GAIN_CAL23 0x26
109 #define GAINAMP3_REG_GAIN_CAL24 0x27
110 #define GAINAMP3_REG_TRIG_CAL 0x2A
111 #define GAINAMP3_REG_M_CLK_CNT 0x2E
112 #define GAINAMP3_REG_DIE_REV_ID 0x2F
113 #define GAINAMP3_REG_PART_ID 0x64
114  // gainamp3_reg
116 
131 #define GAINAMP3_SPI_CRC_ERR_DISABLE_BIT 0x20
132 #define GAINAMP3_SPI_CRC_ENABLE 0x01
133 #define GAINAMP3_SPI_CRC_DISABLE 0x00
134 
139 #define GAINAMP3_DIE_REV_ID 0x30
140 
145 #define GAINAMP3_GAIN_1_OVER_16 0x00
146 #define GAINAMP3_GAIN_1_OVER_8 0x01
147 #define GAINAMP3_GAIN_1_OVER_4 0x02
148 #define GAINAMP3_GAIN_1_OVER_2 0x03
149 #define GAINAMP3_GAIN_1 0x04
150 #define GAINAMP3_GAIN_2 0x05
151 #define GAINAMP3_GAIN_4 0x06
152 #define GAINAMP3_GAIN_8 0x07
153 #define GAINAMP3_GAIN_16 0x08
154 #define GAINAMP3_GAIN_32 0x09
155 #define GAINAMP3_GAIN_64 0x0A
156 #define GAINAMP3_GAIN_128 0x0B
157 #define GAINAMP3_GAIN_BITS_MASK 0x78
158 
163 #define GAINAMP3_CHANNEL_1 0x00
164 #define GAINAMP3_CHANNEL_2 0x01
165 #define GAINAMP3_CHANNEL_TEST 0x02
166 #define GAINAMP3_CHANNEL_SHORT_SWITCH 0x03
167 #define GAINAMP3_CHANNEL_BITS_MASK 0x60
168 
177 #define GAINAMP3_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
178 #define GAINAMP3_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
179  // gainamp3_set
181 
196 #define GAINAMP3_MAP_MIKROBUS( cfg, mikrobus ) \
197  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
198  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
199  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
200  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
201  // gainamp3_map // gainamp3
204 
209 typedef struct
210 {
211  // Modules
212  spi_master_t spi;
214  pin_name_t chip_select;
216  uint8_t spi_crc_enable;
218 } gainamp3_t;
219 
224 typedef struct
225 {
226  // Communication gpio pins
227  pin_name_t miso;
228  pin_name_t mosi;
229  pin_name_t sck;
230  pin_name_t cs;
232  // static variable
233  uint32_t spi_speed;
234  spi_master_mode_t spi_mode;
235  spi_master_chip_select_polarity_t cs_polarity;
238 
243 typedef enum
244 {
246  GAINAMP3_ERROR = -1
247 
249 
266 
282 
297 
313 err_t gainamp3_continuous_write ( gainamp3_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
314 
330 err_t gainamp3_continuous_read ( gainamp3_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
331 
345 err_t gainamp3_write_register ( gainamp3_t *ctx, uint8_t reg, uint8_t data_in );
346 
360 err_t gainamp3_read_register ( gainamp3_t *ctx, uint8_t reg, uint8_t *data_out );
361 
374 
387 err_t gainamp3_set_amplifier_gain ( gainamp3_t *ctx, uint8_t gain );
388 
401 err_t gainamp3_set_input_channel ( gainamp3_t *ctx, uint8_t channel );
402 
415 
416 #ifdef __cplusplus
417 }
418 #endif
419 #endif // GAINAMP3_H
420  // gainamp3
422 
423 // ------------------------------------------------------------------------ END
gainamp3_cfg_t::sck
pin_name_t sck
Definition: gainamp3.h:229
gainamp3_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: gainamp3.h:234
gainamp3_continuous_read
err_t gainamp3_continuous_read(gainamp3_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
GainAMP 3 continuous read function.
gainamp3_cfg_t::spi_speed
uint32_t spi_speed
Definition: gainamp3.h:233
gainamp3_read_register
err_t gainamp3_read_register(gainamp3_t *ctx, uint8_t reg, uint8_t *data_out)
GainAMP 3 read register function.
gainamp3_set_amplifier_gain
err_t gainamp3_set_amplifier_gain(gainamp3_t *ctx, uint8_t gain)
GainAMP 3 set amplifier gain function.
gainamp3_software_reset
err_t gainamp3_software_reset(gainamp3_t *ctx)
GainAMP 3 software reset function.
spi_specifics.h
This file contains SPI specific macros, functions, etc.
gainamp3_t
GainAMP 3 Click context object.
Definition: gainamp3.h:210
gainamp3_t::spi_crc_enable
uint8_t spi_crc_enable
Definition: gainamp3.h:216
GAINAMP3_ERROR
@ GAINAMP3_ERROR
Definition: gainamp3.h:246
gainamp3_cfg_t::cs
pin_name_t cs
Definition: gainamp3.h:230
gainamp3_cfg_t
GainAMP 3 Click configuration object.
Definition: gainamp3.h:225
gainamp3_return_value_t
gainamp3_return_value_t
GainAMP 3 Click return value data.
Definition: gainamp3.h:244
gainamp3_set_input_channel
err_t gainamp3_set_input_channel(gainamp3_t *ctx, uint8_t channel)
GainAMP 3 set input channel function.
gainamp3_verify_communication
err_t gainamp3_verify_communication(gainamp3_t *ctx)
GainAMP 3 verify communication function.
gainamp3_cfg_setup
void gainamp3_cfg_setup(gainamp3_cfg_t *cfg)
GainAMP 3 configuration object setup function.
gainamp3_default_cfg
err_t gainamp3_default_cfg(gainamp3_t *ctx)
GainAMP 3 default configuration function.
gainamp3_continuous_write
err_t gainamp3_continuous_write(gainamp3_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
GainAMP 3 continuous write function.
gainamp3_init
err_t gainamp3_init(gainamp3_t *ctx, gainamp3_cfg_t *cfg)
GainAMP 3 initialization function.
gainamp3_cfg_t::mosi
pin_name_t mosi
Definition: gainamp3.h:228
gainamp3_t::chip_select
pin_name_t chip_select
Definition: gainamp3.h:214
gainamp3_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: gainamp3.h:235
GAINAMP3_OK
@ GAINAMP3_OK
Definition: gainamp3.h:245
gainamp3_cfg_t::miso
pin_name_t miso
Definition: gainamp3.h:227
gainamp3_write_register
err_t gainamp3_write_register(gainamp3_t *ctx, uint8_t reg, uint8_t data_in)
GainAMP 3 write register function.
gainamp3_t::spi
spi_master_t spi
Definition: gainamp3.h:212