digipot3 2.0.0.0
digipot3.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 DIGIPOT3_H
36#define DIGIPOT3_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 DIGIPOT3_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 cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
60 cfg.rdy = MIKROBUS( mikrobus, MIKROBUS_INT );
67#define DIGIPOT3_RETVAL uint8_t
68
69#define DIGIPOT3_OK 0x00
70#define DIGIPOT3_INIT_ERROR 0xFF
77#define DIGIPOT3_DO_NOTHING_COMM 0x00
78#define DIGIPOT3_RESTORE_EEMEM_TO_RDAC_COMM 0x01
79#define DIGIPOT3_STORE_RDAC_TO_EEMEM_COMM 0x02
80#define DIGIPOT3_DECREMENT_RDAC_6DB_COMM 0x04
81#define DIGIPOT3_DECREMENT_RDAC_ONESTEP_COMM 0x06
82#define DIGIPOT3_RESTORE_RDAC_WITH_EEMEM_COMM 0x08
83#define DIGIPOT3_INCREMENT_RDAC_6DB_COMM 0x0C
84#define DIGIPOT3_INCREMENT_RDAC_ONESTEP_COMM 0x0E
91#define DIGIPOT3_RDAC_EEMEM_LOC 0x00
92#define DIGIPOT3_O1_O2_EEMEM_LOC 0x01
93#define DIGIPOT3_USER1_EEMEM_LOC 0x02
94#define DIGIPOT3_USER2_EEMEM_LOC 0x03
95#define DIGIPOT3_USER3_EEMEM_LOC 0x04
96#define DIGIPOT3_USER4_EEMEM_LOC 0x05
97#define DIGIPOT3_USER5_EEMEM_LOC 0x06
98#define DIGIPOT3_USER6_EEMEM_LOC 0x07
99#define DIGIPOT3_USER7_EEMEM_LOC 0x08
100#define DIGIPOT3_USER8_EEMEM_LOC 0x09
101#define DIGIPOT3_USER9_EEMEM_LOC 0x0A
102#define DIGIPOT3_USER10_EEMEM_LOC 0x0B
103#define DIGIPOT3_USER11_EEMEM_LOC 0x0C
104#define DIGIPOT3_USER12_EEMEM_LOC 0x0D
105#define DIGIPOT3_USER13_EEMEM_LOC 0x0E
106#define DIGIPOT3_USER14_EEMEM_LOC 0x0F
113#define DIGIPOT3_ZERO_SCALE 0x0000
114#define DIGIPOT3_QUARTER_SCALE 0x0100
115#define DIGIPOT3_HALF_SCALE 0x0200
116#define DIGIPOT3_THREE_QUARTERS_SCALE 0x0300
117#define DIGIPOT3_FULL_SCALE 0x03FF // End group macro
121// --------------------------------------------------------------- PUBLIC TYPES
130typedef struct
131{
132 digital_out_t cs;
133
134 // Input pins
135
136 digital_in_t an;
137 digital_in_t rdy;
138
139 // Modules
140
141 spi_master_t spi;
142 pin_name_t chip_select;
143
144} digipot3_t;
145
149typedef struct
150{
151 // Communication gpio pins
152
153 pin_name_t miso;
154 pin_name_t mosi;
155 pin_name_t sck;
156 pin_name_t cs;
157
158 // Additional gpio pins
159
160 pin_name_t an;
161 pin_name_t rdy;
162
163 // static variable
164
165 uint32_t spi_speed;
166 spi_master_mode_t spi_mode;
167 spi_master_chip_select_polarity_t cs_polarity;
168
170 // End types group
172// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
173
178#ifdef __cplusplus
179extern "C"{
180#endif
181
191
201
213void digipot2_generic_transfer ( digipot3_t *ctx, uint8_t *wr_buf,
214 uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len );
215
224uint8_t digipot3_send_command ( digipot3_t *ctx, uint8_t command_byte );
225
235uint8_t digipot3_store_eemem ( digipot3_t *ctx, uint8_t location_address, uint16_t transfer_data );
236
246uint8_t digipot3_read_eemem ( digipot3_t *ctx, uint8_t location_address, uint16_t *data_out );
247
256uint8_t digipot3_write_dac ( digipot3_t *ctx, uint16_t value_dac );
257
266void digipot3_read_dac ( digipot3_t *ctx, uint16_t *data_out );
267
276
277#ifdef __cplusplus
278}
279#endif
280#endif // _DIGIPOT3_H_
281 // End public_function group
284
285// ------------------------------------------------------------------------- END
#define DIGIPOT3_RETVAL
Definition: digipot3.h:67
uint8_t digipot3_check_data_ready(digipot3_t *ctx)
Data Ready Check function.
uint8_t digipot3_send_command(digipot3_t *ctx, uint8_t command_byte)
Command Send function.
uint8_t digipot3_store_eemem(digipot3_t *ctx, uint8_t location_address, uint16_t transfer_data)
EEMEM Store function.
uint8_t digipot3_read_eemem(digipot3_t *ctx, uint8_t location_address, uint16_t *data_out)
EEMEM Read function.
void digipot3_read_dac(digipot3_t *ctx, uint16_t *data_out)
DAC Read function.
void digipot2_generic_transfer(digipot3_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len)
Generic transfer function.
void digipot3_cfg_setup(digipot3_cfg_t *cfg)
Config Object Initialization function.
DIGIPOT3_RETVAL digipot3_init(digipot3_t *ctx, digipot3_cfg_t *cfg)
Initialization function.
uint8_t digipot3_write_dac(digipot3_t *ctx, uint16_t value_dac)
DAC Write function.
Click configuration structure definition.
Definition: digipot3.h:150
spi_master_chip_select_polarity_t cs_polarity
Definition: digipot3.h:167
pin_name_t sck
Definition: digipot3.h:155
spi_master_mode_t spi_mode
Definition: digipot3.h:166
pin_name_t mosi
Definition: digipot3.h:154
uint32_t spi_speed
Definition: digipot3.h:165
pin_name_t rdy
Definition: digipot3.h:161
pin_name_t miso
Definition: digipot3.h:153
pin_name_t an
Definition: digipot3.h:160
pin_name_t cs
Definition: digipot3.h:156
Click ctx object definition.
Definition: digipot3.h:131
digital_out_t cs
Definition: digipot3.h:132
spi_master_t spi
Definition: digipot3.h:141
digital_in_t an
Definition: digipot3.h:136
pin_name_t chip_select
Definition: digipot3.h:142
digital_in_t rdy
Definition: digipot3.h:137