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 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_spi_master.h"
48 #include "drv_analog_in.h"
49 
70 #define DIGIPOT8_REG_RDAC1 0x00
71 #define DIGIPOT8_REG_RDAC2 0x01
72 #define DIGIPOT8_REG_RDAC3 0x02
73 #define DIGIPOT8_REG_RDAC4 0x03
74 #define DIGIPOT8_REG_RDAC5 0x04
75 #define DIGIPOT8_REG_RDAC6 0x05
76  // digipot8_reg
78 
93 #define DIGIPOT8_WIPER_POSITION_MIN 0x00
94 #define DIGIPOT8_WIPER_POSITION_MAX 0xFF
95  // digipot8_set
97 
112 #define DIGIPOT8_MAP_MIKROBUS( cfg, mikrobus ) \
113  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
114  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
115  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
116  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
117  cfg.an_pin = MIKROBUS( mikrobus, MIKROBUS_AN ); \
118 
119  // digipot8_map // digipot8
121 
126 typedef struct
127 {
128  // Modules
129  analog_in_t adc;
130  spi_master_t spi;
132  float vref;
133  pin_name_t chip_select;
135 } digipot8_t;
136 
141 typedef struct
142 {
143  // Additional gpio pins
144 
145  pin_name_t an_pin;
147  // Communication gpio pins
148 
149  pin_name_t miso;
150  pin_name_t mosi;
151  pin_name_t sck;
152  pin_name_t cs;
154  // static variable
155 
156  analog_in_resolution_t resolution;
157  float vref;
158  uint32_t spi_speed;
159  spi_master_mode_t spi_mode;
160  spi_master_chip_select_polarity_t cs_polarity;
163 
168 typedef enum
169 {
171  DIGIPOT8_ERROR = -1
172 
174 
191 
207 
222 err_t digipot8_write_data ( digipot8_t *ctx, uint8_t reg, uint8_t data_in );
223 
236 err_t digipot8_set_wiper_1 ( digipot8_t *ctx, uint8_t data_in );
237 
250 err_t digipot8_set_wiper_2 ( digipot8_t *ctx, uint8_t data_in );
251 
264 err_t digipot8_set_wiper_3 ( digipot8_t *ctx, uint8_t data_in );
265 
278 err_t digipot8_set_wiper_4 ( digipot8_t *ctx, uint8_t data_in );
279 
292 err_t digipot8_set_wiper_5 ( digipot8_t *ctx, uint8_t data_in );
293 
306 err_t digipot8_set_wiper_6 ( digipot8_t *ctx, uint8_t data_in );
307 
317 
327 
328 #ifdef __cplusplus
329 }
330 #endif
331 #endif // DIGIPOT8_H
332  // digipot8
334 
335 // ------------------------------------------------------------------------ END
DIGIPOT8_ERROR
@ DIGIPOT8_ERROR
Definition: digipot8.h:171
digipot8_cfg_t::vref
float vref
Definition: digipot8.h:157
digipot8_cfg_t::sck
pin_name_t sck
Definition: digipot8.h:151
digipot8_t::chip_select
pin_name_t chip_select
Definition: digipot8.h:133
digipot8_cfg_t::cs
pin_name_t cs
Definition: digipot8.h:152
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:159
digipot8_t::spi
spi_master_t spi
Definition: digipot8.h:130
digipot8_cfg_t::spi_speed
uint32_t spi_speed
Definition: digipot8.h:158
digipot8_cfg_t::miso
pin_name_t miso
Definition: digipot8.h:149
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:132
digipot8_t
DIGI POT 8 Click context object.
Definition: digipot8.h:127
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:129
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:142
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:150
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:156
digipot8_cfg_t::an_pin
pin_name_t an_pin
Definition: digipot8.h:145
digipot8_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: digipot8.h:160
digipot8_read_voltage
float digipot8_read_voltage(digipot8_t *ctx)
Generic read function.
DIGIPOT8_OK
@ DIGIPOT8_OK
Definition: digipot8.h:170
digipot8_return_value_t
digipot8_return_value_t
DIGI POT 8 Click return value data.
Definition: digipot8.h:169
digipot8_set_wiper_1
err_t digipot8_set_wiper_1(digipot8_t *ctx, uint8_t data_in)
DIGI POT 8 set wiper 1 function.