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 "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 
53 // -------------------------------------------------------------- PUBLIC MACROS
64 #define DIGIPOT3_MAP_MIKROBUS( cfg, mikrobus ) \
65  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
66  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
67  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
68  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
69  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
70  cfg.rdy = MIKROBUS( mikrobus, MIKROBUS_INT );
71 
77 #define DIGIPOT3_RETVAL uint8_t
78 
79 #define DIGIPOT3_OK 0x00
80 #define DIGIPOT3_INIT_ERROR 0xFF
81 
87 #define DIGIPOT3_DO_NOTHING_COMM 0x00
88 #define DIGIPOT3_RESTORE_EEMEM_TO_RDAC_COMM 0x01
89 #define DIGIPOT3_STORE_RDAC_TO_EEMEM_COMM 0x02
90 #define DIGIPOT3_DECREMENT_RDAC_6DB_COMM 0x04
91 #define DIGIPOT3_DECREMENT_RDAC_ONESTEP_COMM 0x06
92 #define DIGIPOT3_RESTORE_RDAC_WITH_EEMEM_COMM 0x08
93 #define DIGIPOT3_INCREMENT_RDAC_6DB_COMM 0x0C
94 #define DIGIPOT3_INCREMENT_RDAC_ONESTEP_COMM 0x0E
95 
101 #define DIGIPOT3_RDAC_EEMEM_LOC 0x00
102 #define DIGIPOT3_O1_O2_EEMEM_LOC 0x01
103 #define DIGIPOT3_USER1_EEMEM_LOC 0x02
104 #define DIGIPOT3_USER2_EEMEM_LOC 0x03
105 #define DIGIPOT3_USER3_EEMEM_LOC 0x04
106 #define DIGIPOT3_USER4_EEMEM_LOC 0x05
107 #define DIGIPOT3_USER5_EEMEM_LOC 0x06
108 #define DIGIPOT3_USER6_EEMEM_LOC 0x07
109 #define DIGIPOT3_USER7_EEMEM_LOC 0x08
110 #define DIGIPOT3_USER8_EEMEM_LOC 0x09
111 #define DIGIPOT3_USER9_EEMEM_LOC 0x0A
112 #define DIGIPOT3_USER10_EEMEM_LOC 0x0B
113 #define DIGIPOT3_USER11_EEMEM_LOC 0x0C
114 #define DIGIPOT3_USER12_EEMEM_LOC 0x0D
115 #define DIGIPOT3_USER13_EEMEM_LOC 0x0E
116 #define DIGIPOT3_USER14_EEMEM_LOC 0x0F
117 
123 #define DIGIPOT3_ZERO_SCALE 0x0000
124 #define DIGIPOT3_QUARTER_SCALE 0x0100
125 #define DIGIPOT3_HALF_SCALE 0x0200
126 #define DIGIPOT3_THREE_QUARTERS_SCALE 0x0300
127 #define DIGIPOT3_FULL_SCALE 0x03FF
128  // End group macro
131 // --------------------------------------------------------------- PUBLIC TYPES
140 typedef struct
141 {
142  digital_out_t cs;
143 
144  // Input pins
145 
146  digital_in_t an;
147  digital_in_t rdy;
148 
149  // Modules
150 
151  spi_master_t spi;
152  pin_name_t chip_select;
153 
154 } digipot3_t;
155 
159 typedef struct
160 {
161  // Communication gpio pins
162 
163  pin_name_t miso;
164  pin_name_t mosi;
165  pin_name_t sck;
166  pin_name_t cs;
167 
168  // Additional gpio pins
169 
170  pin_name_t an;
171  pin_name_t rdy;
172 
173  // static variable
174 
175  uint32_t spi_speed;
176  spi_master_mode_t spi_mode;
177  spi_master_chip_select_polarity_t cs_polarity;
178 
180  // End types group
182 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
183 
188 #ifdef __cplusplus
189 extern "C"{
190 #endif
191 
201 
211 
223 void digipot2_generic_transfer ( digipot3_t *ctx, uint8_t *wr_buf,
224  uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len );
225 
234 uint8_t digipot3_send_command ( digipot3_t *ctx, uint8_t command_byte );
235 
245 uint8_t digipot3_store_eemem ( digipot3_t *ctx, uint8_t location_address, uint16_t transfer_data );
246 
256 uint8_t digipot3_read_eemem ( digipot3_t *ctx, uint8_t location_address, uint16_t *data_out );
257 
266 uint8_t digipot3_write_dac ( digipot3_t *ctx, uint16_t value_dac );
267 
276 void digipot3_read_dac ( digipot3_t *ctx, uint16_t *data_out );
277 
286 
287 #ifdef __cplusplus
288 }
289 #endif
290 #endif // _DIGIPOT3_H_
291  // End public_function group
294 
295 // ------------------------------------------------------------------------- END
digipot3_t::chip_select
pin_name_t chip_select
Definition: digipot3.h:152
digipot3_cfg_t::an
pin_name_t an
Definition: digipot3.h:170
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:177
digipot3_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: digipot3.h:176
digipot3_cfg_t::sck
pin_name_t sck
Definition: digipot3.h:165
digipot3_cfg_t::rdy
pin_name_t rdy
Definition: digipot3.h:171
digipot3_t::an
digital_in_t an
Definition: digipot3.h:146
digipot3_cfg_t::mosi
pin_name_t mosi
Definition: digipot3.h:164
digipot3_t::spi
spi_master_t spi
Definition: digipot3.h:151
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:142
digipot3_cfg_t
Click configuration structure definition.
Definition: digipot3.h:160
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:141
digipot3_cfg_t::miso
pin_name_t miso
Definition: digipot3.h:163
digipot3_cfg_t::cs
pin_name_t cs
Definition: digipot3.h:166
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:175
digipot3_t::rdy
digital_in_t rdy
Definition: digipot3.h:147
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:77
digipot3_store_eemem
uint8_t digipot3_store_eemem(digipot3_t *ctx, uint8_t location_address, uint16_t transfer_data)
EEMEM Store function.