digipot2  2.0.0.0
digipot2.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright© 2020 MikroElektronika d.o.o.
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without restriction,
8  * including without limitation the rights to use, copy, modify, merge,
9  * publish, distribute, sublicense, and/or sell copies of the Software,
10  * and to permit persons to whom the Software is furnished to do so,
11  * subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22  * OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef DIGIPOT2_H
36 #define DIGIPOT2_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_spi_master.h"
41 
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
54 #define DIGIPOT2_MAP_MIKROBUS( cfg, mikrobus ) \
55  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
56  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
57  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
58  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
59 
65 #define DIGIPOT2_RETVAL uint8_t
66 
67 #define DIGIPOT2_OK 0x00
68 #define DIGIPOT2_INIT_ERROR 0xFF
69 
75 #define DIGIPOT2_VREF_3V3 3.3
76 #define DIGIPOT2_VREF_5V 5.0
77  // End group macro
80 // --------------------------------------------------------------- PUBLIC TYPES
89 typedef struct
90 {
91  // Output pins
92 
93  digital_out_t cs;
94 
95  // Modules
96 
97  spi_master_t spi;
98  pin_name_t chip_select;
99 
100 } digipot2_t;
101 
105 typedef struct
106 {
107  // Communication gpio pins
108 
109  pin_name_t miso;
110  pin_name_t mosi;
111  pin_name_t sck;
112  pin_name_t cs;
113 
114  // Additional gpio pins
115 
116  uint32_t spi_speed;
117  spi_master_mode_t spi_mode;
118  spi_master_chip_select_polarity_t cs_polarity;
119 
121  // End types group
123 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
124 
129 #ifdef __cplusplus
130 extern "C"{
131 #endif
132 
141 void digipot2_cfg_setup ( digipot2_cfg_t *cfg );
142 
152 
164 void digipot2_generic_transfer ( digipot2_t *ctx, uint8_t *wr_buf,
165  uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len );
166 
177 void digipot2_write_byte ( digipot2_t *ctx, uint8_t command, uint8_t write_data );
178 
188 void digipot2_set_wiper_positions ( digipot2_t *ctx, uint8_t wiper_positions );
189 
203 float digipot2_convert_output ( digipot2_t *ctx, uint16_t value_adc, float v_ref );
204 
205 #ifdef __cplusplus
206 }
207 #endif
208 #endif // _DIGIPOT2_H_
209  // End public_function group
212 
213 // ------------------------------------------------------------------------- END
spi_master_mode_t spi_mode
Definition: digipot2.h:117
uint32_t spi_speed
Definition: digipot2.h:116
digital_out_t cs
Definition: digipot2.h:93
void digipot2_cfg_setup(digipot2_cfg_t *cfg)
Config Object Initialization function.
float digipot2_convert_output(digipot2_t *ctx, uint16_t value_adc, float v_ref)
Convert ADC value to volatage.
pin_name_t chip_select
Definition: digipot2.h:98
void digipot2_write_byte(digipot2_t *ctx, uint8_t command, uint8_t write_data)
Generic write 8-bit data function.
#define DIGIPOT2_RETVAL
Definition: digipot2.h:65
Click ctx object definition.
Definition: digipot2.h:89
Click configuration structure definition.
Definition: digipot2.h:105
spi_master_t spi
Definition: digipot2.h:97
pin_name_t cs
Definition: digipot2.h:112
void digipot2_set_wiper_positions(digipot2_t *ctx, uint8_t wiper_positions)
Set 8-bit wiper positions.
pin_name_t miso
Definition: digipot2.h:109
pin_name_t sck
Definition: digipot2.h:111
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.
pin_name_t mosi
Definition: digipot2.h:110
spi_master_chip_select_polarity_t cs_polarity
Definition: digipot2.h:118
DIGIPOT2_RETVAL digipot2_init(digipot2_t *ctx, digipot2_cfg_t *cfg)
Initialization function.