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 "drv_digital_out.h"
39#include "drv_digital_in.h"
40#include "drv_spi_master.h"
41
42// -------------------------------------------------------------- PUBLIC MACROS
53#define DIGIPOT6_MAP_MIKROBUS( cfg, mikrobus ) \
54 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
55 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
56 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
57 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
64#define DIGIPOT6_RETVAL uint8_t
65
66#define DIGIPOT6_OK 0x00
67#define DIGIPOT6_INIT_ERROR 0xFF
74#define DIGIPOT6_CMD_WRITE 0x00
75#define DIGIPOT6_CMD_INCREMENT 0x01
76#define DIGIPOT6_CMD_DECREMENT 0x02
77#define DIGIPOT6_CMD_READ 0x03
84#define DIGIPOT6_VOLATILE_WIPER_0 0x00
85#define DIGIPOT6_TCON_REG 0x04
92#define DIGIPOT6_TCON_R0B 0xF1
93#define DIGIPOT6_TCON_R0W 0xF2
94#define DIGIPOT6_TCON_R0A 0xF4
95#define DIGIPOT6_TCON_R0HW 0xF8
96
97#define DIGIPOT6_TCON_MASK_R0B 0xFE
98#define DIGIPOT6_TCON_MASK_R0W 0xFD
99#define DIGIPOT6_TCON_MASK_R0A 0xFB
100#define DIGIPOT6_TCON_MASK_R0HW 0xF7
107#define DIGIPOT6_CONNECT 0x01
108#define DIGIPOT6_DISCONNECT 0x00 // End group macro
112// --------------------------------------------------------------- PUBLIC TYPES
121typedef struct
122{
123 // Output pins
124
125 digital_out_t cs;
126
127 // Modules
128
129 spi_master_t spi;
130 pin_name_t chip_select;
131
132} digipot6_t;
133
137typedef struct
138{
139 // Communication gpio pins
140
141 pin_name_t miso;
142 pin_name_t mosi;
143 pin_name_t sck;
144 pin_name_t cs;
145
146 // static variable
147
148 uint32_t spi_speed;
149 spi_master_mode_t spi_mode;
150 spi_master_chip_select_polarity_t cs_polarity;
151
153 // End types group
155// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
156
161#ifdef __cplusplus
162extern "C"{
163#endif
164
174
184
193
203void digipot6_write_data ( digipot6_t *ctx, uint8_t reg, uint8_t w_data );
204
213void digipot6_write_wiper_cmd ( digipot6_t *ctx, uint8_t cmd );
214
223uint8_t digipot6_read_data ( digipot6_t *ctx, uint8_t reg ) ;
224
235void digipot6_set_resistor ( digipot6_t *ctx, uint8_t state, uint8_t mask, uint8_t tcon );
236
237#ifdef __cplusplus
238}
239#endif
240#endif // _DIGIPOT6_H_
241 // End public_function group
244
245// ------------------------------------------------------------------------- END
#define DIGIPOT6_RETVAL
Definition: digipot6.h:64
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:138
spi_master_chip_select_polarity_t cs_polarity
Definition: digipot6.h:150
pin_name_t sck
Definition: digipot6.h:143
spi_master_mode_t spi_mode
Definition: digipot6.h:149
pin_name_t mosi
Definition: digipot6.h:142
uint32_t spi_speed
Definition: digipot6.h:148
pin_name_t miso
Definition: digipot6.h:141
pin_name_t cs
Definition: digipot6.h:144
Click ctx object definition.
Definition: digipot6.h:122
digital_out_t cs
Definition: digipot6.h:125
spi_master_t spi
Definition: digipot6.h:129
pin_name_t chip_select
Definition: digipot6.h:130