mcp16331inv  2.0.0.0
mcp16331inv.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 MCP16331INV_H
36 #define MCP16331INV_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 
56 
57 // -------------------------------------------------------------- PUBLIC MACROS
68 #define MCP16331INV_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.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
74  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST )
75 
81 #define MCP16331INV_RETVAL uint8_t
82 
83 #define MCP16331INV_OK 0x00
84 #define MCP16331INV_INIT_ERROR 0xFF
85 
92 #define MCP16331INV_ENABLE_VIN_PULL_UP 1
93 #define MCP16331INV_DISABLE_VIN_PULL_UP 0
94 
100 #define MCP16331INV_GAIN_1X_VREF 1
101 #define MCP16331INV_GAIN_2X_VREF 0
102 
108 #define MCP16331INV_ACTIVE_MODE 1
109 #define MCP16331INV_SHUTDOWN_MODE 0
110 
116 #define MCP16331INV_MIN_2715_MV_1X_GAIN 0x0000
117 #define MCP16331INV_2900_MV_1X_GAIN 0x00F5
118 #define MCP16331INV_3000_MV_1X_GAIN 0x017A
119 #define MCP16331INV_3100_MV_1X_GAIN 0x01FE
120 #define MCP16331INV_3300_MV_1X_GAIN 0x02FE
121 #define MCP16331INV_3500_MV_1X_GAIN 0x03FF
122 #define MCP16331INV_3700_MV_1X_GAIN 0x04FF
123 #define MCP16331INV_3900_MV_1X_GAIN 0x05FF
124 #define MCP16331INV_4000_MV_1X_GAIN 0x0690
125 #define MCP16331INV_4300_MV_1X_GAIN 0x0810
126 #define MCP16331INV_5000_MV_1X_GAIN 0x0BAE
127 #define MCP16331INV_5200_MV_1X_GAIN 0x0CAF
128 #define MCP16331INV_5300_MV_1X_GAIN 0x0D3F
129 #define MCP16331INV_MAX_5400_MV_1X_GAIN 0x0FFF
130 
136 #define MCP16331INV_MIN_2715_MV_2X_GAIN 0x0000
137 #define MCP16331INV_3000_MV_2X_GAIN 0x00B8
138 #define MCP16331INV_3500_MV_2X_GAIN 0x01FF
139 #define MCP16331INV_3900_MV_2X_GAIN 0x02FF
140 #define MCP16331INV_4400_MV_2X_GAIN 0x044F
141 #define MCP16331INV_4800_MV_2X_GAIN 0x0558
142 #define MCP16331INV_4900_MV_2X_GAIN 0x0590
143 #define MCP16331INV_5000_MV_2X_GAIN 0x05D0
144 #define MCP16331INV_5300_MV_2X_GAIN 0x0690
145 #define MCP16331INV_MAX_5400_MV_2X_GAIN 0x0FFF
146  // End group macro
148 // --------------------------------------------------------------- PUBLIC TYPES
157 typedef struct
158 {
159  // Output pins
160 
161  digital_out_t rst;
162  digital_out_t cs;
163 
164  // Input pins
165 
166  digital_in_t an;
167 
168  // Modules
169 
170  spi_master_t spi;
171  pin_name_t chip_select;
172 
173 } mcp16331inv_t;
174 
178 typedef struct
179 {
180  // Communication gpio pins
181 
182  pin_name_t miso;
183  pin_name_t mosi;
184  pin_name_t sck;
185  pin_name_t cs;
186 
187  // Additional gpio pins
188 
189  pin_name_t an;
190  pin_name_t rst;
191 
192  // static variable
193 
194  uint32_t spi_speed;
195  uint8_t spi_mode;
196  spi_master_chip_select_polarity_t cs_polarity;
197 
199  // End types group
201 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
202 
207 #ifdef __cplusplus
208 extern "C"{
209 #endif
210 
220 
229 
242 (
243  mcp16331inv_t *ctx,
244  uint8_t *wr_buf,
245  uint16_t wr_len,
246  uint8_t *rd_buf,
247  uint16_t rd_len
248 );
249 
261 void mcp16331inv_set_dac_vout ( mcp16331inv_t *ctx, uint16_t dac_value, uint8_t gain_value, uint8_t mode );
262 
271 void mcp16331inv_enable_vin ( mcp16331inv_t *ctx, uint8_t state );
272 
273 #ifdef __cplusplus
274 }
275 #endif
276 #endif // _MCP16331INV_H_
277  // End public_function group
280 
281 // ------------------------------------------------------------------------- END
mcp16331inv_cfg_t::miso
pin_name_t miso
Definition: mcp16331inv.h:182
mcp16331inv_init
MCP16331INV_RETVAL mcp16331inv_init(mcp16331inv_t *ctx, mcp16331inv_cfg_t *cfg)
Initialization function.
mcp16331inv_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: mcp16331inv.h:196
mcp16331inv_cfg_t::mosi
pin_name_t mosi
Definition: mcp16331inv.h:183
mcp16331inv_cfg_t
Click configuration structure definition.
Definition: mcp16331inv.h:179
mcp16331inv_enable_vin
void mcp16331inv_enable_vin(mcp16331inv_t *ctx, uint8_t state)
VIN Pull Up enable function.
mcp16331inv_t::cs
digital_out_t cs
Definition: mcp16331inv.h:162
mcp16331inv_t
Click ctx object definition.
Definition: mcp16331inv.h:158
mcp16331inv_set_dac_vout
void mcp16331inv_set_dac_vout(mcp16331inv_t *ctx, uint16_t dac_value, uint8_t gain_value, uint8_t mode)
DAC output voltage set function.
mcp16331inv_cfg_t::spi_mode
uint8_t spi_mode
Definition: mcp16331inv.h:195
mcp16331inv_t::an
digital_in_t an
Definition: mcp16331inv.h:166
mcp16331inv_t::rst
digital_out_t rst
Definition: mcp16331inv.h:161
mcp16331inv_cfg_t::rst
pin_name_t rst
Definition: mcp16331inv.h:190
mcp16331inv_t::chip_select
pin_name_t chip_select
Definition: mcp16331inv.h:171
mcp16331inv_t::spi
spi_master_t spi
Definition: mcp16331inv.h:170
mcp16331inv_cfg_setup
void mcp16331inv_cfg_setup(mcp16331inv_cfg_t *cfg)
Config Object Initialization function.
mcp16331inv_cfg_t::spi_speed
uint32_t spi_speed
Definition: mcp16331inv.h:194
mcp16331inv_generic_transfer
void mcp16331inv_generic_transfer(mcp16331inv_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len)
Generic transfer function.
mcp16331inv_cfg_t::sck
pin_name_t sck
Definition: mcp16331inv.h:184
mcp16331inv_cfg_t::cs
pin_name_t cs
Definition: mcp16331inv.h:185
MCP16331INV_RETVAL
#define MCP16331INV_RETVAL
Definition: mcp16331inv.h:81
mcp16331inv_cfg_t::an
pin_name_t an
Definition: mcp16331inv.h:189