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
32extern "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 // digipot8_map // digipot8
111
116typedef 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
131typedef 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
158typedef enum
159{
161 DIGIPOT8_ERROR = -1
162
164
181
197
212err_t digipot8_write_data ( digipot8_t *ctx, uint8_t reg, uint8_t data_in );
213
226err_t digipot8_set_wiper_1 ( digipot8_t *ctx, uint8_t data_in );
227
240err_t digipot8_set_wiper_2 ( digipot8_t *ctx, uint8_t data_in );
241
254err_t digipot8_set_wiper_3 ( digipot8_t *ctx, uint8_t data_in );
255
268err_t digipot8_set_wiper_4 ( digipot8_t *ctx, uint8_t data_in );
269
282err_t digipot8_set_wiper_5 ( digipot8_t *ctx, uint8_t data_in );
283
296err_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_return_value_t
DIGI POT 8 Click return value data.
Definition: digipot8.h:159
@ DIGIPOT8_OK
Definition: digipot8.h:160
@ DIGIPOT8_ERROR
Definition: digipot8.h:161
err_t digipot8_write_data(digipot8_t *ctx, uint8_t reg, uint8_t data_in)
DIGI POT 8 write data function.
err_t digipot8_set_wiper_6(digipot8_t *ctx, uint8_t data_in)
DIGI POT 8 set wiper 6 function.
float digipot8_read_voltage(digipot8_t *ctx)
Generic read function.
err_t digipot8_set_wiper_1(digipot8_t *ctx, uint8_t data_in)
DIGI POT 8 set wiper 1 function.
uint16_t digipot8_generic_read(digipot8_t *ctx)
Generic read function.
err_t digipot8_set_wiper_5(digipot8_t *ctx, uint8_t data_in)
DIGI POT 8 set wiper 5 function.
err_t digipot8_set_wiper_2(digipot8_t *ctx, uint8_t data_in)
DIGI POT 8 set wiper 2 function.
void digipot8_cfg_setup(digipot8_cfg_t *cfg)
DIGI POT 8 configuration object setup function.
err_t digipot8_set_wiper_3(digipot8_t *ctx, uint8_t data_in)
DIGI POT 8 set wiper 3 function.
err_t digipot8_init(digipot8_t *ctx, digipot8_cfg_t *cfg)
DIGI POT 8 initialization function.
err_t digipot8_set_wiper_4(digipot8_t *ctx, uint8_t data_in)
DIGI POT 8 set wiper 4 function.
DIGI POT 8 Click configuration object.
Definition: digipot8.h:132
analog_in_resolution_t resolution
Definition: digipot8.h:146
float vref
Definition: digipot8.h:147
pin_name_t an_pin
Definition: digipot8.h:135
spi_master_chip_select_polarity_t cs_polarity
Definition: digipot8.h:150
pin_name_t sck
Definition: digipot8.h:141
spi_master_mode_t spi_mode
Definition: digipot8.h:149
pin_name_t mosi
Definition: digipot8.h:140
uint32_t spi_speed
Definition: digipot8.h:148
pin_name_t miso
Definition: digipot8.h:139
pin_name_t cs
Definition: digipot8.h:142
DIGI POT 8 Click context object.
Definition: digipot8.h:117
spi_master_t spi
Definition: digipot8.h:120
float vref
Definition: digipot8.h:122
pin_name_t chip_select
Definition: digipot8.h:123
analog_in_t adc
Definition: digipot8.h:119