digipot6  2.0.0.0
digipot6.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 DIGIPOT6_H
36 #define DIGIPOT6_H
37 
38 #include "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_spi_master.h"
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
63 #define DIGIPOT6_MAP_MIKROBUS( cfg, mikrobus ) \
64  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
65  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
66  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
67  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
68 
74 #define DIGIPOT6_RETVAL uint8_t
75 
76 #define DIGIPOT6_OK 0x00
77 #define DIGIPOT6_INIT_ERROR 0xFF
78 
84 #define DIGIPOT6_CMD_WRITE 0x00
85 #define DIGIPOT6_CMD_INCREMENT 0x01
86 #define DIGIPOT6_CMD_DECREMENT 0x02
87 #define DIGIPOT6_CMD_READ 0x03
88 
94 #define DIGIPOT6_VOLATILE_WIPER_0 0x00
95 #define DIGIPOT6_TCON_REG 0x04
96 
102 #define DIGIPOT6_TCON_R0B 0xF1
103 #define DIGIPOT6_TCON_R0W 0xF2
104 #define DIGIPOT6_TCON_R0A 0xF4
105 #define DIGIPOT6_TCON_R0HW 0xF8
106 
107 #define DIGIPOT6_TCON_MASK_R0B 0xFE
108 #define DIGIPOT6_TCON_MASK_R0W 0xFD
109 #define DIGIPOT6_TCON_MASK_R0A 0xFB
110 #define DIGIPOT6_TCON_MASK_R0HW 0xF7
111 
117 #define DIGIPOT6_CONNECT 0x01
118 #define DIGIPOT6_DISCONNECT 0x00
119  // End group macro
122 // --------------------------------------------------------------- PUBLIC TYPES
131 typedef struct
132 {
133  // Output pins
134 
135  digital_out_t cs;
136 
137  // Modules
138 
139  spi_master_t spi;
140  pin_name_t chip_select;
141 
142 } digipot6_t;
143 
147 typedef struct
148 {
149  // Communication gpio pins
150 
151  pin_name_t miso;
152  pin_name_t mosi;
153  pin_name_t sck;
154  pin_name_t cs;
155 
156  // static variable
157 
158  uint32_t spi_speed;
159  spi_master_mode_t spi_mode;
160  spi_master_chip_select_polarity_t cs_polarity;
161 
163  // End types group
165 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
166 
171 #ifdef __cplusplus
172 extern "C"{
173 #endif
174 
184 
194 
203 
213 void digipot6_write_data ( digipot6_t *ctx, uint8_t reg, uint8_t w_data );
214 
223 void digipot6_write_wiper_cmd ( digipot6_t *ctx, uint8_t cmd );
224 
233 uint8_t digipot6_read_data ( digipot6_t *ctx, uint8_t reg ) ;
234 
245 void digipot6_set_resistor ( digipot6_t *ctx, uint8_t state, uint8_t mask, uint8_t tcon );
246 
247 #ifdef __cplusplus
248 }
249 #endif
250 #endif // _DIGIPOT6_H_
251  // End public_function group
254 
255 // ------------------------------------------------------------------------- END
digipot6_default_cfg
void digipot6_default_cfg(digipot6_t *ctx)
Click Default Configuration function.
digipot6_write_data
void digipot6_write_data(digipot6_t *ctx, uint8_t reg, uint8_t w_data)
Write data function.
digipot6_cfg_t::sck
pin_name_t sck
Definition: digipot6.h:153
DIGIPOT6_RETVAL
#define DIGIPOT6_RETVAL
Definition: digipot6.h:74
digipot6_t
Click ctx object definition.
Definition: digipot6.h:132
digipot6_cfg_t::miso
pin_name_t miso
Definition: digipot6.h:151
digipot6_t::chip_select
pin_name_t chip_select
Definition: digipot6.h:140
digipot6_write_wiper_cmd
void digipot6_write_wiper_cmd(digipot6_t *ctx, uint8_t cmd)
Write wiper command function.
digipot6_cfg_t::mosi
pin_name_t mosi
Definition: digipot6.h:152
digipot6_cfg_t
Click configuration structure definition.
Definition: digipot6.h:148
digipot6_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: digipot6.h:159
digipot6_read_data
uint8_t digipot6_read_data(digipot6_t *ctx, uint8_t reg)
Read data function.
digipot6_cfg_t::spi_speed
uint32_t spi_speed
Definition: digipot6.h:158
digipot6_t::cs
digital_out_t cs
Definition: digipot6.h:135
digipot6_cfg_setup
void digipot6_cfg_setup(digipot6_cfg_t *cfg)
Config Object Initialization function.
digipot6_t::spi
spi_master_t spi
Definition: digipot6.h:139
digipot6_set_resistor
void digipot6_set_resistor(digipot6_t *ctx, uint8_t state, uint8_t mask, uint8_t tcon)
Set resistor function.
digipot6_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: digipot6.h:160
digipot6_cfg_t::cs
pin_name_t cs
Definition: digipot6.h:154
digipot6_init
DIGIPOT6_RETVAL digipot6_init(digipot6_t *ctx, digipot6_cfg_t *cfg)
Initialization function.