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
35#include "drv_digital_out.h"
36#include "drv_digital_in.h"
37#include "drv_spi_master.h"
38#include "spi_specifics.h"
39
60#define GAINAMP3_REG_GAIN_MUX 0x00
61#define GAINAMP3_REG_RESET 0x01
62#define GAINAMP3_REG_SYNC_CFG 0x02
63#define GAINAMP3_REG_DIGITAL_ERR 0x03
64#define GAINAMP3_REG_ANALOG_ERR 0x04
65#define GAINAMP3_REG_GPIO_DATA 0x05
66#define GAINAMP3_REG_INPUT_MUX 0x06
67#define GAINAMP3_REG_WB_DETECT 0x07
68#define GAINAMP3_REG_GPIO_DIR 0x08
69#define GAINAMP3_REG_SCS 0x09
70#define GAINAMP3_REG_ANALOG_ERR_DIS 0x0A
71#define GAINAMP3_REG_DIGITAL_ERR_DIS 0x0B
72#define GAINAMP3_REG_SF_CFG 0x0C
73#define GAINAMP3_REG_ERR_CFG 0x0D
74#define GAINAMP3_REG_TEST_MUX 0x0E
75#define GAINAMP3_REG_EX_CURRENT_CFG 0x0F
76#define GAINAMP3_REG_GAIN_CAL1 0x10
77#define GAINAMP3_REG_GAIN_CAL2 0x11
78#define GAINAMP3_REG_GAIN_CAL3 0x12
79#define GAINAMP3_REG_GAIN_CAL4 0x13
80#define GAINAMP3_REG_GAIN_CAL5 0x14
81#define GAINAMP3_REG_GAIN_CAL6 0x15
82#define GAINAMP3_REG_GAIN_CAL7 0x16
83#define GAINAMP3_REG_GAIN_CAL8 0x17
84#define GAINAMP3_REG_GAIN_CAL9 0x18
85#define GAINAMP3_REG_GAIN_CAL10 0x19
86#define GAINAMP3_REG_GAIN_CAL11 0x1A
87#define GAINAMP3_REG_GAIN_CAL12 0x1B
88#define GAINAMP3_REG_GAIN_CAL13 0x1C
89#define GAINAMP3_REG_GAIN_CAL14 0x1D
90#define GAINAMP3_REG_GAIN_CAL15 0x1E
91#define GAINAMP3_REG_GAIN_CAL16 0x1F
92#define GAINAMP3_REG_GAIN_CAL17 0x20
93#define GAINAMP3_REG_GAIN_CAL18 0x21
94#define GAINAMP3_REG_GAIN_CAL19 0x22
95#define GAINAMP3_REG_GAIN_CAL20 0x23
96#define GAINAMP3_REG_GAIN_CAL21 0x24
97#define GAINAMP3_REG_GAIN_CAL22 0x25
98#define GAINAMP3_REG_GAIN_CAL23 0x26
99#define GAINAMP3_REG_GAIN_CAL24 0x27
100#define GAINAMP3_REG_TRIG_CAL 0x2A
101#define GAINAMP3_REG_M_CLK_CNT 0x2E
102#define GAINAMP3_REG_DIE_REV_ID 0x2F
103#define GAINAMP3_REG_PART_ID 0x64
104 // gainamp3_reg
106
121#define GAINAMP3_SPI_CRC_ERR_DISABLE_BIT 0x20
122#define GAINAMP3_SPI_CRC_ENABLE 0x01
123#define GAINAMP3_SPI_CRC_DISABLE 0x00
124
129#define GAINAMP3_DIE_REV_ID 0x30
130
135#define GAINAMP3_GAIN_1_OVER_16 0x00
136#define GAINAMP3_GAIN_1_OVER_8 0x01
137#define GAINAMP3_GAIN_1_OVER_4 0x02
138#define GAINAMP3_GAIN_1_OVER_2 0x03
139#define GAINAMP3_GAIN_1 0x04
140#define GAINAMP3_GAIN_2 0x05
141#define GAINAMP3_GAIN_4 0x06
142#define GAINAMP3_GAIN_8 0x07
143#define GAINAMP3_GAIN_16 0x08
144#define GAINAMP3_GAIN_32 0x09
145#define GAINAMP3_GAIN_64 0x0A
146#define GAINAMP3_GAIN_128 0x0B
147#define GAINAMP3_GAIN_BITS_MASK 0x78
148
153#define GAINAMP3_CHANNEL_1 0x00
154#define GAINAMP3_CHANNEL_2 0x01
155#define GAINAMP3_CHANNEL_TEST 0x02
156#define GAINAMP3_CHANNEL_SHORT_SWITCH 0x03
157#define GAINAMP3_CHANNEL_BITS_MASK 0x60
158
167#define GAINAMP3_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
168#define GAINAMP3_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
169 // gainamp3_set
171
186#define GAINAMP3_MAP_MIKROBUS( cfg, mikrobus ) \
187 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
188 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
189 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
190 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
191 // gainamp3_map // gainamp3
194
199typedef struct
200{
201 // Modules
202 spi_master_t spi;
204 pin_name_t chip_select;
208} gainamp3_t;
209
214typedef struct
215{
216 // Communication gpio pins
217 pin_name_t miso;
218 pin_name_t mosi;
219 pin_name_t sck;
220 pin_name_t cs;
222 // static variable
223 uint32_t spi_speed;
224 spi_master_mode_t spi_mode;
225 spi_master_chip_select_polarity_t cs_polarity;
228
233typedef enum
234{
236 GAINAMP3_ERROR = -1
237
239
256
272
287
303err_t gainamp3_continuous_write ( gainamp3_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
304
320err_t gainamp3_continuous_read ( gainamp3_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
321
335err_t gainamp3_write_register ( gainamp3_t *ctx, uint8_t reg, uint8_t data_in );
336
350err_t gainamp3_read_register ( gainamp3_t *ctx, uint8_t reg, uint8_t *data_out );
351
364
377err_t gainamp3_set_amplifier_gain ( gainamp3_t *ctx, uint8_t gain );
378
391err_t gainamp3_set_input_channel ( gainamp3_t *ctx, uint8_t channel );
392
405
406#ifdef __cplusplus
407}
408#endif
409#endif // GAINAMP3_H
410 // gainamp3
412
413// ------------------------------------------------------------------------ END
gainamp3_return_value_t
GainAMP 3 Click return value data.
Definition: gainamp3.h:234
@ GAINAMP3_ERROR
Definition: gainamp3.h:236
@ GAINAMP3_OK
Definition: gainamp3.h:235
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:215
spi_master_chip_select_polarity_t cs_polarity
Definition: gainamp3.h:225
pin_name_t sck
Definition: gainamp3.h:219
spi_master_mode_t spi_mode
Definition: gainamp3.h:224
pin_name_t mosi
Definition: gainamp3.h:218
uint32_t spi_speed
Definition: gainamp3.h:223
pin_name_t miso
Definition: gainamp3.h:217
pin_name_t cs
Definition: gainamp3.h:220
GainAMP 3 Click context object.
Definition: gainamp3.h:200
spi_master_t spi
Definition: gainamp3.h:202
uint8_t spi_crc_enable
Definition: gainamp3.h:206
pin_name_t chip_select
Definition: gainamp3.h:204