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 
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 
57 // -------------------------------------------------------------- PUBLIC MACROS
68 #define DIGIPOT3_MAP_MIKROBUS( cfg, mikrobus ) \
69  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
70  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
71  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
72  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
73  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
74  cfg.rdy = MIKROBUS( mikrobus, MIKROBUS_INT );
75 
81 #define DIGIPOT3_RETVAL uint8_t
82 
83 #define DIGIPOT3_OK 0x00
84 #define DIGIPOT3_INIT_ERROR 0xFF
85 
91 #define DIGIPOT3_DO_NOTHING_COMM 0x00
92 #define DIGIPOT3_RESTORE_EEMEM_TO_RDAC_COMM 0x01
93 #define DIGIPOT3_STORE_RDAC_TO_EEMEM_COMM 0x02
94 #define DIGIPOT3_DECREMENT_RDAC_6DB_COMM 0x04
95 #define DIGIPOT3_DECREMENT_RDAC_ONESTEP_COMM 0x06
96 #define DIGIPOT3_RESTORE_RDAC_WITH_EEMEM_COMM 0x08
97 #define DIGIPOT3_INCREMENT_RDAC_6DB_COMM 0x0C
98 #define DIGIPOT3_INCREMENT_RDAC_ONESTEP_COMM 0x0E
99 
105 #define DIGIPOT3_RDAC_EEMEM_LOC 0x00
106 #define DIGIPOT3_O1_O2_EEMEM_LOC 0x01
107 #define DIGIPOT3_USER1_EEMEM_LOC 0x02
108 #define DIGIPOT3_USER2_EEMEM_LOC 0x03
109 #define DIGIPOT3_USER3_EEMEM_LOC 0x04
110 #define DIGIPOT3_USER4_EEMEM_LOC 0x05
111 #define DIGIPOT3_USER5_EEMEM_LOC 0x06
112 #define DIGIPOT3_USER6_EEMEM_LOC 0x07
113 #define DIGIPOT3_USER7_EEMEM_LOC 0x08
114 #define DIGIPOT3_USER8_EEMEM_LOC 0x09
115 #define DIGIPOT3_USER9_EEMEM_LOC 0x0A
116 #define DIGIPOT3_USER10_EEMEM_LOC 0x0B
117 #define DIGIPOT3_USER11_EEMEM_LOC 0x0C
118 #define DIGIPOT3_USER12_EEMEM_LOC 0x0D
119 #define DIGIPOT3_USER13_EEMEM_LOC 0x0E
120 #define DIGIPOT3_USER14_EEMEM_LOC 0x0F
121 
127 #define DIGIPOT3_ZERO_SCALE 0x0000
128 #define DIGIPOT3_QUARTER_SCALE 0x0100
129 #define DIGIPOT3_HALF_SCALE 0x0200
130 #define DIGIPOT3_THREE_QUARTERS_SCALE 0x0300
131 #define DIGIPOT3_FULL_SCALE 0x03FF
132  // End group macro
135 // --------------------------------------------------------------- PUBLIC TYPES
144 typedef struct
145 {
146  digital_out_t cs;
147 
148  // Input pins
149 
150  digital_in_t an;
151  digital_in_t rdy;
152 
153  // Modules
154 
155  spi_master_t spi;
156  pin_name_t chip_select;
157 
158 } digipot3_t;
159 
163 typedef struct
164 {
165  // Communication gpio pins
166 
167  pin_name_t miso;
168  pin_name_t mosi;
169  pin_name_t sck;
170  pin_name_t cs;
171 
172  // Additional gpio pins
173 
174  pin_name_t an;
175  pin_name_t rdy;
176 
177  // static variable
178 
179  uint32_t spi_speed;
180  spi_master_mode_t spi_mode;
181  spi_master_chip_select_polarity_t cs_polarity;
182 
184  // End types group
186 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
187 
192 #ifdef __cplusplus
193 extern "C"{
194 #endif
195 
205 
215 
227 void digipot2_generic_transfer ( digipot3_t *ctx, uint8_t *wr_buf,
228  uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len );
229 
238 uint8_t digipot3_send_command ( digipot3_t *ctx, uint8_t command_byte );
239 
249 uint8_t digipot3_store_eemem ( digipot3_t *ctx, uint8_t location_address, uint16_t transfer_data );
250 
260 uint8_t digipot3_read_eemem ( digipot3_t *ctx, uint8_t location_address, uint16_t *data_out );
261 
270 uint8_t digipot3_write_dac ( digipot3_t *ctx, uint16_t value_dac );
271 
280 void digipot3_read_dac ( digipot3_t *ctx, uint16_t *data_out );
281 
290 
291 #ifdef __cplusplus
292 }
293 #endif
294 #endif // _DIGIPOT3_H_
295  // End public_function group
298 
299 // ------------------------------------------------------------------------- END
digipot3_t::chip_select
pin_name_t chip_select
Definition: digipot3.h:156
digipot3_cfg_t::an
pin_name_t an
Definition: digipot3.h:174
digipot3_cfg_setup
void digipot3_cfg_setup(digipot3_cfg_t *cfg)
Config Object Initialization function.
digipot3_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: digipot3.h:181
digipot3_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: digipot3.h:180
digipot3_cfg_t::sck
pin_name_t sck
Definition: digipot3.h:169
digipot3_cfg_t::rdy
pin_name_t rdy
Definition: digipot3.h:175
digipot3_t::an
digital_in_t an
Definition: digipot3.h:150
digipot3_cfg_t::mosi
pin_name_t mosi
Definition: digipot3.h:168
digipot3_t::spi
spi_master_t spi
Definition: digipot3.h:155
digipot2_generic_transfer
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.
digipot3_t::cs
digital_out_t cs
Definition: digipot3.h:146
digipot3_cfg_t
Click configuration structure definition.
Definition: digipot3.h:164
digipot3_check_data_ready
uint8_t digipot3_check_data_ready(digipot3_t *ctx)
Data Ready Check function.
digipot3_t
Click ctx object definition.
Definition: digipot3.h:145
digipot3_cfg_t::miso
pin_name_t miso
Definition: digipot3.h:167
digipot3_cfg_t::cs
pin_name_t cs
Definition: digipot3.h:170
digipot3_init
DIGIPOT3_RETVAL digipot3_init(digipot3_t *ctx, digipot3_cfg_t *cfg)
Initialization function.
digipot3_cfg_t::spi_speed
uint32_t spi_speed
Definition: digipot3.h:179
digipot3_t::rdy
digital_in_t rdy
Definition: digipot3.h:151
digipot3_read_dac
void digipot3_read_dac(digipot3_t *ctx, uint16_t *data_out)
DAC Read function.
digipot3_write_dac
uint8_t digipot3_write_dac(digipot3_t *ctx, uint16_t value_dac)
DAC Write function.
digipot3_send_command
uint8_t digipot3_send_command(digipot3_t *ctx, uint8_t command_byte)
Command Send function.
digipot3_read_eemem
uint8_t digipot3_read_eemem(digipot3_t *ctx, uint8_t location_address, uint16_t *data_out)
EEMEM Read function.
DIGIPOT3_RETVAL
#define DIGIPOT3_RETVAL
Definition: digipot3.h:81
digipot3_store_eemem
uint8_t digipot3_store_eemem(digipot3_t *ctx, uint8_t location_address, uint16_t transfer_data)
EEMEM Store function.