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
42#ifdef PREINIT_SUPPORTED
43#include "preinit.h"
44#endif
45
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
48 #include "delays.h"
49 #endif
50#endif
51
52#include "drv_digital_out.h"
53#include "drv_digital_in.h"
54#include "drv_spi_master.h"
55
56// -------------------------------------------------------------- PUBLIC MACROS
67#define DIGIPOT6_MAP_MIKROBUS( cfg, mikrobus ) \
68 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
69 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
70 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
71 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
78#define DIGIPOT6_RETVAL uint8_t
79
80#define DIGIPOT6_OK 0x00
81#define DIGIPOT6_INIT_ERROR 0xFF
88#define DIGIPOT6_CMD_WRITE 0x00
89#define DIGIPOT6_CMD_INCREMENT 0x01
90#define DIGIPOT6_CMD_DECREMENT 0x02
91#define DIGIPOT6_CMD_READ 0x03
98#define DIGIPOT6_VOLATILE_WIPER_0 0x00
99#define DIGIPOT6_TCON_REG 0x04
106#define DIGIPOT6_TCON_R0B 0xF1
107#define DIGIPOT6_TCON_R0W 0xF2
108#define DIGIPOT6_TCON_R0A 0xF4
109#define DIGIPOT6_TCON_R0HW 0xF8
110
111#define DIGIPOT6_TCON_MASK_R0B 0xFE
112#define DIGIPOT6_TCON_MASK_R0W 0xFD
113#define DIGIPOT6_TCON_MASK_R0A 0xFB
114#define DIGIPOT6_TCON_MASK_R0HW 0xF7
121#define DIGIPOT6_CONNECT 0x01
122#define DIGIPOT6_DISCONNECT 0x00
125 // End group macro
126// --------------------------------------------------------------- PUBLIC TYPES
135typedef struct
136{
137 // Output pins
138
139 digital_out_t cs;
140
141 // Modules
142
143 spi_master_t spi;
144 pin_name_t chip_select;
145
146} digipot6_t;
147
151typedef struct
152{
153 // Communication gpio pins
154
155 pin_name_t miso;
156 pin_name_t mosi;
157 pin_name_t sck;
158 pin_name_t cs;
159
160 // static variable
161
162 uint32_t spi_speed;
163 spi_master_mode_t spi_mode;
164 spi_master_chip_select_polarity_t cs_polarity;
165
167
168 // End types group
169// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
170
175#ifdef __cplusplus
176extern "C"{
177#endif
178
188
198
207
217void digipot6_write_data ( digipot6_t *ctx, uint8_t reg, uint8_t w_data );
218
227void digipot6_write_wiper_cmd ( digipot6_t *ctx, uint8_t cmd );
228
237uint8_t digipot6_read_data ( digipot6_t *ctx, uint8_t reg ) ;
238
249void digipot6_set_resistor ( digipot6_t *ctx, uint8_t state, uint8_t mask, uint8_t tcon );
250
251#ifdef __cplusplus
252}
253#endif
254#endif // _DIGIPOT6_H_
255
256 // End public_function group
258
259// ------------------------------------------------------------------------- END
#define DIGIPOT6_RETVAL
Definition digipot6.h:78
void digipot6_set_resistor(digipot6_t *ctx, uint8_t state, uint8_t mask, uint8_t tcon)
Set resistor function.
void digipot6_cfg_setup(digipot6_cfg_t *cfg)
Config Object Initialization function.
uint8_t digipot6_read_data(digipot6_t *ctx, uint8_t reg)
Read data function.
void digipot6_default_cfg(digipot6_t *ctx)
Click Default Configuration function.
void digipot6_write_wiper_cmd(digipot6_t *ctx, uint8_t cmd)
Write wiper command function.
DIGIPOT6_RETVAL digipot6_init(digipot6_t *ctx, digipot6_cfg_t *cfg)
Initialization function.
void digipot6_write_data(digipot6_t *ctx, uint8_t reg, uint8_t w_data)
Write data function.
Click configuration structure definition.
Definition digipot6.h:152
spi_master_chip_select_polarity_t cs_polarity
Definition digipot6.h:164
pin_name_t sck
Definition digipot6.h:157
spi_master_mode_t spi_mode
Definition digipot6.h:163
pin_name_t mosi
Definition digipot6.h:156
uint32_t spi_speed
Definition digipot6.h:162
pin_name_t miso
Definition digipot6.h:155
pin_name_t cs
Definition digipot6.h:158
Click ctx object definition.
Definition digipot6.h:136
digital_out_t cs
Definition digipot6.h:139
spi_master_t spi
Definition digipot6.h:143
pin_name_t chip_select
Definition digipot6.h:144