digipot8  2.0.0.0
digipot8.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 DIGIPOT8_H
29 #define DIGIPOT8_H
30 
31 #ifdef __cplusplus
32 extern "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 "drv_analog_in.h"
53 
74 #define DIGIPOT8_REG_RDAC1 0x00
75 #define DIGIPOT8_REG_RDAC2 0x01
76 #define DIGIPOT8_REG_RDAC3 0x02
77 #define DIGIPOT8_REG_RDAC4 0x03
78 #define DIGIPOT8_REG_RDAC5 0x04
79 #define DIGIPOT8_REG_RDAC6 0x05
80  // digipot8_reg
82 
97 #define DIGIPOT8_WIPER_POSITION_MIN 0x00
98 #define DIGIPOT8_WIPER_POSITION_MAX 0xFF
99  // digipot8_set
101 
116 #define DIGIPOT8_MAP_MIKROBUS( cfg, mikrobus ) \
117  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
118  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
119  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
120  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
121  cfg.an_pin = MIKROBUS( mikrobus, MIKROBUS_AN ); \
122 
123  // digipot8_map // digipot8
125 
130 typedef struct
131 {
132  // Modules
133  analog_in_t adc;
134  spi_master_t spi;
136  float vref;
137  pin_name_t chip_select;
139 } digipot8_t;
140 
145 typedef struct
146 {
147  // Additional gpio pins
148 
149  pin_name_t an_pin;
151  // Communication gpio pins
152 
153  pin_name_t miso;
154  pin_name_t mosi;
155  pin_name_t sck;
156  pin_name_t cs;
158  // static variable
159 
160  analog_in_resolution_t resolution;
161  float vref;
162  uint32_t spi_speed;
163  spi_master_mode_t spi_mode;
164  spi_master_chip_select_polarity_t cs_polarity;
167 
172 typedef enum
173 {
175  DIGIPOT8_ERROR = -1
176 
178 
195 
211 
226 err_t digipot8_write_data ( digipot8_t *ctx, uint8_t reg, uint8_t data_in );
227 
240 err_t digipot8_set_wiper_1 ( digipot8_t *ctx, uint8_t data_in );
241 
254 err_t digipot8_set_wiper_2 ( digipot8_t *ctx, uint8_t data_in );
255 
268 err_t digipot8_set_wiper_3 ( digipot8_t *ctx, uint8_t data_in );
269 
282 err_t digipot8_set_wiper_4 ( digipot8_t *ctx, uint8_t data_in );
283 
296 err_t digipot8_set_wiper_5 ( digipot8_t *ctx, uint8_t data_in );
297 
310 err_t digipot8_set_wiper_6 ( digipot8_t *ctx, uint8_t data_in );
311 
321 
331 
332 #ifdef __cplusplus
333 }
334 #endif
335 #endif // DIGIPOT8_H
336  // digipot8
338 
339 // ------------------------------------------------------------------------ END
DIGIPOT8_ERROR
@ DIGIPOT8_ERROR
Definition: digipot8.h:175
digipot8_cfg_t::vref
float vref
Definition: digipot8.h:161
digipot8_cfg_t::sck
pin_name_t sck
Definition: digipot8.h:155
digipot8_t::chip_select
pin_name_t chip_select
Definition: digipot8.h:137
digipot8_cfg_t::cs
pin_name_t cs
Definition: digipot8.h:156
digipot8_set_wiper_3
err_t digipot8_set_wiper_3(digipot8_t *ctx, uint8_t data_in)
DIGI POT 8 set wiper 3 function.
digipot8_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: digipot8.h:163
digipot8_t::spi
spi_master_t spi
Definition: digipot8.h:134
digipot8_cfg_t::spi_speed
uint32_t spi_speed
Definition: digipot8.h:162
digipot8_cfg_t::miso
pin_name_t miso
Definition: digipot8.h:153
digipot8_set_wiper_6
err_t digipot8_set_wiper_6(digipot8_t *ctx, uint8_t data_in)
DIGI POT 8 set wiper 6 function.
digipot8_t::vref
float vref
Definition: digipot8.h:136
digipot8_t
DIGI POT 8 Click context object.
Definition: digipot8.h:131
digipot8_set_wiper_5
err_t digipot8_set_wiper_5(digipot8_t *ctx, uint8_t data_in)
DIGI POT 8 set wiper 5 function.
digipot8_t::adc
analog_in_t adc
Definition: digipot8.h:133
digipot8_set_wiper_2
err_t digipot8_set_wiper_2(digipot8_t *ctx, uint8_t data_in)
DIGI POT 8 set wiper 2 function.
digipot8_init
err_t digipot8_init(digipot8_t *ctx, digipot8_cfg_t *cfg)
DIGI POT 8 initialization function.
digipot8_cfg_t
DIGI POT 8 Click configuration object.
Definition: digipot8.h:146
digipot8_set_wiper_4
err_t digipot8_set_wiper_4(digipot8_t *ctx, uint8_t data_in)
DIGI POT 8 set wiper 4 function.
digipot8_write_data
err_t digipot8_write_data(digipot8_t *ctx, uint8_t reg, uint8_t data_in)
DIGI POT 8 write data function.
digipot8_cfg_t::mosi
pin_name_t mosi
Definition: digipot8.h:154
digipot8_generic_read
uint16_t digipot8_generic_read(digipot8_t *ctx)
Generic read function.
digipot8_cfg_setup
void digipot8_cfg_setup(digipot8_cfg_t *cfg)
DIGI POT 8 configuration object setup function.
digipot8_cfg_t::resolution
analog_in_resolution_t resolution
Definition: digipot8.h:160
digipot8_cfg_t::an_pin
pin_name_t an_pin
Definition: digipot8.h:149
digipot8_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: digipot8.h:164
digipot8_read_voltage
float digipot8_read_voltage(digipot8_t *ctx)
Generic read function.
DIGIPOT8_OK
@ DIGIPOT8_OK
Definition: digipot8.h:174
digipot8_return_value_t
digipot8_return_value_t
DIGI POT 8 Click return value data.
Definition: digipot8.h:173
digipot8_set_wiper_1
err_t digipot8_set_wiper_1(digipot8_t *ctx, uint8_t data_in)
DIGI POT 8 set wiper 1 function.