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
32 extern "C"{
33 #endif
34 
35 #include "drv_digital_out.h"
36 #include "drv_spi_master.h"
37 
58 #define DIGIPOT2_MAP_MIKROBUS( cfg, mikrobus ) \
59  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
60  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
61  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
62  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
63  // digipot2_map
65 
80 #define DIGIPOT2_DATA_EEPROM_6 0x06
81 #define DIGIPOT2_DATA_EEPROM_7 0x07
82 #define DIGIPOT2_DATA_EEPROM_8 0x08
83 #define DIGIPOT2_DATA_EEPROM_9 0x09
84 #define DIGIPOT2_DATA_EEPROM_A 0x0A
85 #define DIGIPOT2_DATA_EEPROM_B 0x0B
86 #define DIGIPOT2_DATA_EEPROM_C 0x0C
87 #define DIGIPOT2_DATA_EEPROM_D 0x0D
88 #define DIGIPOT2_DATA_EEPROM_E 0x0E
89 #define DIGIPOT2_DATA_EEPROM_F 0x0F
90 #define DIGIPOT2_DATA_WRITE_CMD 0x20
91 
96 #define DIGIPOT2_VOLATILE_WIPER_0 0x00
97 #define DIGIPOT2_VOLATILE_WIPER_1 0x01
98 #define DIGIPOT2_NON_VOLATILE_WIPER_0 0x02
99 #define DIGIPOT2_NON_VOLATILE_WIPER_1 0x03
100 #define DIGIPOT2_VOLATILE_TCON_REGISTER 0x04
101 #define DIGIPOT2_STATUS_REGISTER 0x05
102  // digipot2_macros // digipot2
105 
110 typedef struct
111 {
112  // Output pins
113 
114  digital_out_t cs;
115 
116  // Modules
117  spi_master_t spi;
119  pin_name_t chip_select;
121 } digipot2_t;
122 
127 typedef struct
128 {
129  // Communication gpio pins
130  pin_name_t miso;
131  pin_name_t mosi;
132  pin_name_t sck;
133  pin_name_t cs;
135  // static variable
136 
137  uint32_t spi_speed;
138  spi_master_mode_t spi_mode;
139  spi_master_chip_select_polarity_t cs_polarity;
142 
147 typedef enum
148 {
150  DIGIPOT2_ERROR = -1
151 
153 
169 void digipot2_cfg_setup ( digipot2_cfg_t *cfg );
170 
185 err_t digipot2_init ( digipot2_t *ctx, digipot2_cfg_t *cfg );
186 
199 void digipot2_generic_transfer ( digipot2_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len );
200 
210 void digipot2_set_wiper_positions ( digipot2_t *ctx, uint8_t wiper_pos );
211 
221 float digipot2_convert_output ( uint16_t adc_val, float v_ref );
222 
223 #ifdef __cplusplus
224 }
225 #endif
226 #endif // DIGIPOT2_H
227  // digipot2
229 
230 // ------------------------------------------------------------------------ END
digipot2_cfg_setup
void digipot2_cfg_setup(digipot2_cfg_t *cfg)
DIGI POT 2 configuration object setup function.
DIGIPOT2_ERROR
Definition: digipot2.h:149
digipot2_convert_output
float digipot2_convert_output(uint16_t adc_val, float v_ref)
Convert ADC value to volatage.
digipot2_set_wiper_positions
void digipot2_set_wiper_positions(digipot2_t *ctx, uint8_t wiper_pos)
Set wiper position.
wiper_pos
uint8_t wiper_pos
Definition: main.c:29
digipot2_cfg_t
DIGI POT 2 Click configuration object.
Definition: digipot2.h:126
digipot2_return_value_t
digipot2_return_value_t
DIGI POT 2 Click return value data.
Definition: digipot2.h:146
digipot2_generic_transfer
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.
DIGIPOT2_OK
Definition: digipot2.h:148
digipot2_t
DIGI POT 2 Click context object.
Definition: digipot2.h:109
digipot2_init
err_t digipot2_init(digipot2_t *ctx, digipot2_cfg_t *cfg)
DIGI POT 2 initialization function.