digipot2 2.0.0.0
digipot2.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 DIGIPOT2_H
29#define DIGIPOT2_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_spi_master.h"
51
72#define DIGIPOT2_MAP_MIKROBUS( cfg, mikrobus ) \
73 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
74 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
75 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
76 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
77
78 // digipot2_map
79
94#define DIGIPOT2_DATA_EEPROM_6 0x06
95#define DIGIPOT2_DATA_EEPROM_7 0x07
96#define DIGIPOT2_DATA_EEPROM_8 0x08
97#define DIGIPOT2_DATA_EEPROM_9 0x09
98#define DIGIPOT2_DATA_EEPROM_A 0x0A
99#define DIGIPOT2_DATA_EEPROM_B 0x0B
100#define DIGIPOT2_DATA_EEPROM_C 0x0C
101#define DIGIPOT2_DATA_EEPROM_D 0x0D
102#define DIGIPOT2_DATA_EEPROM_E 0x0E
103#define DIGIPOT2_DATA_EEPROM_F 0x0F
104#define DIGIPOT2_DATA_WRITE_CMD 0x20
105
110#define DIGIPOT2_VOLATILE_WIPER_0 0x00
111#define DIGIPOT2_VOLATILE_WIPER_1 0x01
112#define DIGIPOT2_NON_VOLATILE_WIPER_0 0x02
113#define DIGIPOT2_NON_VOLATILE_WIPER_1 0x03
114#define DIGIPOT2_VOLATILE_TCON_REGISTER 0x04
115#define DIGIPOT2_STATUS_REGISTER 0x05
116
117 // digipot2_macros
118 // digipot2
119
124typedef struct
125{
126 // Output pins
127
128 digital_out_t cs;
129
130 // Modules
131 spi_master_t spi;
133 pin_name_t chip_select;
135} digipot2_t;
136
141typedef struct
142{
143 // Communication gpio pins
144 pin_name_t miso;
145 pin_name_t mosi;
146 pin_name_t sck;
147 pin_name_t cs;
149 // static variable
150
151 uint32_t spi_speed;
152 spi_master_mode_t spi_mode;
153 spi_master_chip_select_polarity_t cs_polarity;
156
161typedef enum
162{
164 DIGIPOT2_ERROR = -1
165
167
184
200
213void digipot2_generic_transfer ( digipot2_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len );
214
225
235float digipot2_convert_output ( uint16_t adc_val, float v_ref );
236
237#ifdef __cplusplus
238}
239#endif
240#endif // DIGIPOT2_H
241
242 // digipot2
243
244// ------------------------------------------------------------------------ END
digipot2_return_value_t
DIGI POT 2 Click return value data.
Definition digipot2.h:162
@ DIGIPOT2_OK
Definition digipot2.h:163
@ DIGIPOT2_ERROR
Definition digipot2.h:164
float digipot2_convert_output(uint16_t adc_val, float v_ref)
Convert ADC value to volatage.
err_t digipot2_init(digipot2_t *ctx, digipot2_cfg_t *cfg)
DIGI POT 2 initialization function.
void digipot2_set_wiper_positions(digipot2_t *ctx, uint8_t wiper_pos)
Set wiper position.
void digipot2_generic_transfer(digipot2_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len)
Generic transfer function.
void digipot2_cfg_setup(digipot2_cfg_t *cfg)
DIGI POT 2 configuration object setup function.
uint8_t wiper_pos
Definition main.c:29
DIGI POT 2 Click configuration object.
Definition digipot2.h:142
spi_master_chip_select_polarity_t cs_polarity
Definition digipot2.h:153
pin_name_t sck
Definition digipot2.h:146
spi_master_mode_t spi_mode
Definition digipot2.h:152
pin_name_t mosi
Definition digipot2.h:145
uint32_t spi_speed
Definition digipot2.h:151
pin_name_t miso
Definition digipot2.h:144
pin_name_t cs
Definition digipot2.h:147
DIGI POT 2 Click context object.
Definition digipot2.h:125
digital_out_t cs
Definition digipot2.h:128
spi_master_t spi
Definition digipot2.h:131
pin_name_t chip_select
Definition digipot2.h:133