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
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_spi_master.h"
52#include "spi_specifics.h"
53
74#define GAINAMP3_REG_GAIN_MUX 0x00
75#define GAINAMP3_REG_RESET 0x01
76#define GAINAMP3_REG_SYNC_CFG 0x02
77#define GAINAMP3_REG_DIGITAL_ERR 0x03
78#define GAINAMP3_REG_ANALOG_ERR 0x04
79#define GAINAMP3_REG_GPIO_DATA 0x05
80#define GAINAMP3_REG_INPUT_MUX 0x06
81#define GAINAMP3_REG_WB_DETECT 0x07
82#define GAINAMP3_REG_GPIO_DIR 0x08
83#define GAINAMP3_REG_SCS 0x09
84#define GAINAMP3_REG_ANALOG_ERR_DIS 0x0A
85#define GAINAMP3_REG_DIGITAL_ERR_DIS 0x0B
86#define GAINAMP3_REG_SF_CFG 0x0C
87#define GAINAMP3_REG_ERR_CFG 0x0D
88#define GAINAMP3_REG_TEST_MUX 0x0E
89#define GAINAMP3_REG_EX_CURRENT_CFG 0x0F
90#define GAINAMP3_REG_GAIN_CAL1 0x10
91#define GAINAMP3_REG_GAIN_CAL2 0x11
92#define GAINAMP3_REG_GAIN_CAL3 0x12
93#define GAINAMP3_REG_GAIN_CAL4 0x13
94#define GAINAMP3_REG_GAIN_CAL5 0x14
95#define GAINAMP3_REG_GAIN_CAL6 0x15
96#define GAINAMP3_REG_GAIN_CAL7 0x16
97#define GAINAMP3_REG_GAIN_CAL8 0x17
98#define GAINAMP3_REG_GAIN_CAL9 0x18
99#define GAINAMP3_REG_GAIN_CAL10 0x19
100#define GAINAMP3_REG_GAIN_CAL11 0x1A
101#define GAINAMP3_REG_GAIN_CAL12 0x1B
102#define GAINAMP3_REG_GAIN_CAL13 0x1C
103#define GAINAMP3_REG_GAIN_CAL14 0x1D
104#define GAINAMP3_REG_GAIN_CAL15 0x1E
105#define GAINAMP3_REG_GAIN_CAL16 0x1F
106#define GAINAMP3_REG_GAIN_CAL17 0x20
107#define GAINAMP3_REG_GAIN_CAL18 0x21
108#define GAINAMP3_REG_GAIN_CAL19 0x22
109#define GAINAMP3_REG_GAIN_CAL20 0x23
110#define GAINAMP3_REG_GAIN_CAL21 0x24
111#define GAINAMP3_REG_GAIN_CAL22 0x25
112#define GAINAMP3_REG_GAIN_CAL23 0x26
113#define GAINAMP3_REG_GAIN_CAL24 0x27
114#define GAINAMP3_REG_TRIG_CAL 0x2A
115#define GAINAMP3_REG_M_CLK_CNT 0x2E
116#define GAINAMP3_REG_DIE_REV_ID 0x2F
117#define GAINAMP3_REG_PART_ID 0x64
118
119 // gainamp3_reg
120
135#define GAINAMP3_SPI_CRC_ERR_DISABLE_BIT 0x20
136#define GAINAMP3_SPI_CRC_ENABLE 0x01
137#define GAINAMP3_SPI_CRC_DISABLE 0x00
138
143#define GAINAMP3_DIE_REV_ID 0x30
144
149#define GAINAMP3_GAIN_1_OVER_16 0x00
150#define GAINAMP3_GAIN_1_OVER_8 0x01
151#define GAINAMP3_GAIN_1_OVER_4 0x02
152#define GAINAMP3_GAIN_1_OVER_2 0x03
153#define GAINAMP3_GAIN_1 0x04
154#define GAINAMP3_GAIN_2 0x05
155#define GAINAMP3_GAIN_4 0x06
156#define GAINAMP3_GAIN_8 0x07
157#define GAINAMP3_GAIN_16 0x08
158#define GAINAMP3_GAIN_32 0x09
159#define GAINAMP3_GAIN_64 0x0A
160#define GAINAMP3_GAIN_128 0x0B
161#define GAINAMP3_GAIN_BITS_MASK 0x78
162
167#define GAINAMP3_CHANNEL_1 0x00
168#define GAINAMP3_CHANNEL_2 0x01
169#define GAINAMP3_CHANNEL_TEST 0x02
170#define GAINAMP3_CHANNEL_SHORT_SWITCH 0x03
171#define GAINAMP3_CHANNEL_BITS_MASK 0x60
172
181#define GAINAMP3_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
182#define GAINAMP3_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
183
184 // gainamp3_set
185
200#define GAINAMP3_MAP_MIKROBUS( cfg, mikrobus ) \
201 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
202 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
203 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
204 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
205
206 // gainamp3_map
207 // gainamp3
208
213typedef struct
214{
215 // Modules
216 spi_master_t spi;
218 pin_name_t chip_select;
222} gainamp3_t;
223
228typedef struct
229{
230 // Communication gpio pins
231 pin_name_t miso;
232 pin_name_t mosi;
233 pin_name_t sck;
234 pin_name_t cs;
236 // static variable
237 uint32_t spi_speed;
238 spi_master_mode_t spi_mode;
239 spi_master_chip_select_polarity_t cs_polarity;
242
247typedef enum
248{
250 GAINAMP3_ERROR = -1
251
253
270
286
301
317err_t gainamp3_continuous_write ( gainamp3_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
318
334err_t gainamp3_continuous_read ( gainamp3_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
335
349err_t gainamp3_write_register ( gainamp3_t *ctx, uint8_t reg, uint8_t data_in );
350
364err_t gainamp3_read_register ( gainamp3_t *ctx, uint8_t reg, uint8_t *data_out );
365
378
391err_t gainamp3_set_amplifier_gain ( gainamp3_t *ctx, uint8_t gain );
392
405err_t gainamp3_set_input_channel ( gainamp3_t *ctx, uint8_t channel );
406
419
420#ifdef __cplusplus
421}
422#endif
423#endif // GAINAMP3_H
424
425 // gainamp3
426
427// ------------------------------------------------------------------------ END
gainamp3_return_value_t
GainAMP 3 Click return value data.
Definition gainamp3.h:248
@ GAINAMP3_ERROR
Definition gainamp3.h:250
@ GAINAMP3_OK
Definition gainamp3.h:249
err_t gainamp3_set_input_channel(gainamp3_t *ctx, uint8_t channel)
GainAMP 3 set input channel function.
err_t gainamp3_read_register(gainamp3_t *ctx, uint8_t reg, uint8_t *data_out)
GainAMP 3 read register function.
err_t gainamp3_set_amplifier_gain(gainamp3_t *ctx, uint8_t gain)
GainAMP 3 set amplifier gain function.
err_t gainamp3_init(gainamp3_t *ctx, gainamp3_cfg_t *cfg)
GainAMP 3 initialization function.
err_t gainamp3_software_reset(gainamp3_t *ctx)
GainAMP 3 software reset function.
err_t gainamp3_continuous_read(gainamp3_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
GainAMP 3 continuous read function.
err_t gainamp3_verify_communication(gainamp3_t *ctx)
GainAMP 3 verify communication function.
void gainamp3_cfg_setup(gainamp3_cfg_t *cfg)
GainAMP 3 configuration object setup function.
err_t gainamp3_default_cfg(gainamp3_t *ctx)
GainAMP 3 default configuration function.
err_t gainamp3_write_register(gainamp3_t *ctx, uint8_t reg, uint8_t data_in)
GainAMP 3 write register function.
err_t gainamp3_continuous_write(gainamp3_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
GainAMP 3 continuous write function.
This file contains SPI specific macros, functions, etc.
GainAMP 3 Click configuration object.
Definition gainamp3.h:229
spi_master_chip_select_polarity_t cs_polarity
Definition gainamp3.h:239
pin_name_t sck
Definition gainamp3.h:233
spi_master_mode_t spi_mode
Definition gainamp3.h:238
pin_name_t mosi
Definition gainamp3.h:232
uint32_t spi_speed
Definition gainamp3.h:237
pin_name_t miso
Definition gainamp3.h:231
pin_name_t cs
Definition gainamp3.h:234
GainAMP 3 Click context object.
Definition gainamp3.h:214
spi_master_t spi
Definition gainamp3.h:216
uint8_t spi_crc_enable
Definition gainamp3.h:220
pin_name_t chip_select
Definition gainamp3.h:218