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 "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_spi_master.h"
38 #include "drv_analog_in.h"
39 
60 #define DIGIPOT8_REG_RDAC1 0x00
61 #define DIGIPOT8_REG_RDAC2 0x01
62 #define DIGIPOT8_REG_RDAC3 0x02
63 #define DIGIPOT8_REG_RDAC4 0x03
64 #define DIGIPOT8_REG_RDAC5 0x04
65 #define DIGIPOT8_REG_RDAC6 0x05
66  // digipot8_reg
68 
83 #define DIGIPOT8_WIPER_POSITION_MIN 0x00
84 #define DIGIPOT8_WIPER_POSITION_MAX 0xFF
85  // digipot8_set
87 
102 #define DIGIPOT8_MAP_MIKROBUS( cfg, mikrobus ) \
103  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
104  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
105  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
106  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
107  cfg.an_pin = MIKROBUS( mikrobus, MIKROBUS_AN ); \
108 
109  // digipot8_map // digipot8
111 
116 typedef struct
117 {
118  // Modules
119  analog_in_t adc;
120  spi_master_t spi;
122  float vref;
123  pin_name_t chip_select;
125 } digipot8_t;
126 
131 typedef struct
132 {
133  // Additional gpio pins
134 
135  pin_name_t an_pin;
137  // Communication gpio pins
138 
139  pin_name_t miso;
140  pin_name_t mosi;
141  pin_name_t sck;
142  pin_name_t cs;
144  // static variable
145 
146  analog_in_resolution_t resolution;
147  float vref;
148  uint32_t spi_speed;
149  spi_master_mode_t spi_mode;
150  spi_master_chip_select_polarity_t cs_polarity;
153 
158 typedef enum
159 {
161  DIGIPOT8_ERROR = -1
162 
164 
181 
197 
212 err_t digipot8_write_data ( digipot8_t *ctx, uint8_t reg, uint8_t data_in );
213 
226 err_t digipot8_set_wiper_1 ( digipot8_t *ctx, uint8_t data_in );
227 
240 err_t digipot8_set_wiper_2 ( digipot8_t *ctx, uint8_t data_in );
241 
254 err_t digipot8_set_wiper_3 ( digipot8_t *ctx, uint8_t data_in );
255 
268 err_t digipot8_set_wiper_4 ( digipot8_t *ctx, uint8_t data_in );
269 
282 err_t digipot8_set_wiper_5 ( digipot8_t *ctx, uint8_t data_in );
283 
296 err_t digipot8_set_wiper_6 ( digipot8_t *ctx, uint8_t data_in );
297 
307 
317 
318 #ifdef __cplusplus
319 }
320 #endif
321 #endif // DIGIPOT8_H
322  // digipot8
324 
325 // ------------------------------------------------------------------------ END
DIGIPOT8_ERROR
@ DIGIPOT8_ERROR
Definition: digipot8.h:161
digipot8_cfg_t::vref
float vref
Definition: digipot8.h:147
digipot8_cfg_t::sck
pin_name_t sck
Definition: digipot8.h:141
digipot8_t::chip_select
pin_name_t chip_select
Definition: digipot8.h:123
digipot8_cfg_t::cs
pin_name_t cs
Definition: digipot8.h:142
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:149
digipot8_t::spi
spi_master_t spi
Definition: digipot8.h:120
digipot8_cfg_t::spi_speed
uint32_t spi_speed
Definition: digipot8.h:148
digipot8_cfg_t::miso
pin_name_t miso
Definition: digipot8.h:139
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:122
digipot8_t
DIGI POT 8 Click context object.
Definition: digipot8.h:117
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:119
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:132
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:140
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:146
digipot8_cfg_t::an_pin
pin_name_t an_pin
Definition: digipot8.h:135
digipot8_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: digipot8.h:150
digipot8_read_voltage
float digipot8_read_voltage(digipot8_t *ctx)
Generic read function.
DIGIPOT8_OK
@ DIGIPOT8_OK
Definition: digipot8.h:160
digipot8_return_value_t
digipot8_return_value_t
DIGI POT 8 Click return value data.
Definition: digipot8.h:159
digipot8_set_wiper_1
err_t digipot8_set_wiper_1(digipot8_t *ctx, uint8_t data_in)
DIGI POT 8 set wiper 1 function.