digipot9  2.0.0.0
digipot9.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2020 MikroElektronika d.o.o.
3 ** Contact: https://www.mikroe.com/contact
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 ** of this software and associated documentation files (the "Software"), to deal
7 ** in the Software without restriction, including without limitation the rights
8 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 ** copies of the Software, and to permit persons to whom the Software is
10 ** furnished to do so, subject to the following conditions:
11 ** The above copyright notice and this permission notice shall be
12 ** included in all copies or substantial portions of the Software.
13 **
14 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 ** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 ** USE OR OTHER DEALINGS IN THE SOFTWARE.
21 ****************************************************************************/
22 
28 #ifndef DIGIPOT9_H
29 #define DIGIPOT9_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_spi_master.h"
48 
69 #define DIGIPOT9_CMD_NOP 0
70 #define DIGIPOT9_CMD_RESTORE_EEMEM 1
71 #define DIGIPOT9_CMD_STORE_RDAC 2
72 #define DIGIPOT9_CMD_STORE_USER_DATA 3
73 #define DIGIPOT9_CMD_DECREMENT_6DB 4
74 #define DIGIPOT9_CMD_DECREMENT_ALL_6DB 5
75 #define DIGIPOT9_CMD_DECREMENT_ONE_STEP 6
76 #define DIGIPOT9_CMD_DECREMENT_ALL_ONE_STEP 7
77 #define DIGIPOT9_CMD_RESET_EEMEM 8
78 #define DIGIPOT9_CMD_READ_EEMEM 9
79 #define DIGIPOT9_CMD_READ_RDAC 10
80 #define DIGIPOT9_CMD_WRITE_DATA 11
81 #define DIGIPOT9_CMD_INCREMENT_6DB 12
82 #define DIGIPOT9_CMD_INCREMENT_ALL_6DB 13
83 #define DIGIPOT9_CMD_INCREMENT_ONE_STEP 14
84 #define DIGIPOT9_CMD_INCREMENT_ALL_ONE_STEP 15
85 
90 #define DIGIPOT9_ADDRESS_RDAC1 0
91 #define DIGIPOT9_ADDRESS_RDAC2 1
92 #define DIGIPOT9_ADDRESS_USER_DATA_0 2
93 #define DIGIPOT9_ADDRESS_USER_DATA_1 3
94 #define DIGIPOT9_ADDRESS_USER_DATA_2 4
95 #define DIGIPOT9_ADDRESS_USER_DATA_3 5
96 #define DIGIPOT9_ADDRESS_USER_DATA_4 6
97 #define DIGIPOT9_ADDRESS_USER_DATA_5 7
98 #define DIGIPOT9_ADDRESS_USER_DATA_6 8
99 #define DIGIPOT9_ADDRESS_USER_DATA_7 9
100 #define DIGIPOT9_ADDRESS_USER_DATA_8 10
101 #define DIGIPOT9_ADDRESS_USER_DATA_9 11
102 #define DIGIPOT9_ADDRESS_USER_DATA_10 12
103 #define DIGIPOT9_ADDRESS_USER_DATA_11 13
104 #define DIGIPOT9_ADDRESS_USER_DATA_12 14
105 #define DIGIPOT9_ADDRESS_FACTORY_USAGE 15
106  // digipot9_cmd
108 
123 #define DIGIPOT9_WIPER_FULL_SCALE 1023
124 #define DIGIPOT9_WIPER_MID_SCALE 512
125 #define DIGIPOT9_WIPER_ZERO_SCALE 0
126  // digipot9_set
128 
143 #define DIGIPOT9_MAP_MIKROBUS( cfg, mikrobus ) \
144  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
145  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
146  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
147  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
148  cfg.pr = MIKROBUS( mikrobus, MIKROBUS_RST ); \
149  cfg.wp = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
150  cfg.rdy = MIKROBUS( mikrobus, MIKROBUS_INT )
151  // digipot9_map // digipot9
154 
159 typedef struct
160 {
161  // Output pins
162  digital_out_t pr;
163  digital_out_t wp;
165  // Input pins
166  digital_in_t rdy;
168  // Modules
169  spi_master_t spi;
171  pin_name_t chip_select;
173 } digipot9_t;
174 
179 typedef struct
180 {
181  // Communication gpio pins
182  pin_name_t miso;
183  pin_name_t mosi;
184  pin_name_t sck;
185  pin_name_t cs;
187  // Additional gpio pins
188  pin_name_t pr;
189  pin_name_t wp;
190  pin_name_t rdy;
192  // static variable
193  uint32_t spi_speed;
194  spi_master_mode_t spi_mode;
195  spi_master_chip_select_polarity_t cs_polarity;
198 
203 typedef enum
204 {
206  DIGIPOT9_ERROR = -1
207 
209 
226 
242 
255 
271 err_t digipot9_generic_write ( digipot9_t *ctx, uint8_t command, uint8_t address, uint16_t data_in );
272 
288 err_t digipot9_generic_read ( digipot9_t *ctx, uint8_t command, uint8_t address, uint16_t *data_out );
289 
302 err_t digipot9_set_wiper_1 ( digipot9_t *ctx, uint16_t data_in );
303 
316 err_t digipot9_set_wiper_2 ( digipot9_t *ctx, uint16_t data_in );
317 
327 void digipot9_set_pr_pin ( digipot9_t *ctx, uint8_t state );
328 
338 void digipot9_set_wp_pin ( digipot9_t *ctx, uint8_t state );
339 
349 
363 err_t digipot9_write_user_data ( digipot9_t *ctx, uint8_t address, uint16_t data_in );
364 
378 err_t digipot9_read_user_data ( digipot9_t *ctx, uint8_t address, uint16_t *data_out );
379 
380 #ifdef __cplusplus
381 }
382 #endif
383 #endif // DIGIPOT9_H
384  // digipot9
386 
387 // ------------------------------------------------------------------------ END
digipot9_default_cfg
void digipot9_default_cfg(digipot9_t *ctx)
DIGI POT 9 default configuration function.
digipot9_t::rdy
digital_in_t rdy
Definition: digipot9.h:166
digipot9_cfg_t::sck
pin_name_t sck
Definition: digipot9.h:184
digipot9_cfg_t::pr
pin_name_t pr
Definition: digipot9.h:188
digipot9_cfg_t::spi_speed
uint32_t spi_speed
Definition: digipot9.h:193
digipot9_cfg_t::cs
pin_name_t cs
Definition: digipot9.h:185
digipot9_generic_write
err_t digipot9_generic_write(digipot9_t *ctx, uint8_t command, uint8_t address, uint16_t data_in)
DIGI POT 9 data writing function.
digipot9_set_wiper_1
err_t digipot9_set_wiper_1(digipot9_t *ctx, uint16_t data_in)
DIGI POT 9 Set wiper 1 function.
digipot9_init
err_t digipot9_init(digipot9_t *ctx, digipot9_cfg_t *cfg)
DIGI POT 9 initialization function.
digipot9_cfg_t::rdy
pin_name_t rdy
Definition: digipot9.h:190
digipot9_generic_read
err_t digipot9_generic_read(digipot9_t *ctx, uint8_t command, uint8_t address, uint16_t *data_out)
DIGI POT 9 data reading function.
digipot9_t::pr
digital_out_t pr
Definition: digipot9.h:162
digipot9_set_wiper_2
err_t digipot9_set_wiper_2(digipot9_t *ctx, uint16_t data_in)
DIGI POT 9 Set wiper 2 function.
digipot9_t::wp
digital_out_t wp
Definition: digipot9.h:163
digipot9_t
DIGI POT 9 Click context object.
Definition: digipot9.h:160
digipot9_set_pr_pin
void digipot9_set_pr_pin(digipot9_t *ctx, uint8_t state)
DIGI POT 9 Set PR pin function.
digipot9_cfg_t
DIGI POT 9 Click configuration object.
Definition: digipot9.h:180
digipot9_write_user_data
err_t digipot9_write_user_data(digipot9_t *ctx, uint8_t address, uint16_t data_in)
DIGI POT 9 write user data function.
digipot9_return_value_t
digipot9_return_value_t
DIGI POT 9 Click return value data.
Definition: digipot9.h:204
DIGIPOT9_OK
@ DIGIPOT9_OK
Definition: digipot9.h:205
digipot9_t::chip_select
pin_name_t chip_select
Definition: digipot9.h:171
digipot9_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: digipot9.h:195
digipot9_get_rdy_pin
uint8_t digipot9_get_rdy_pin(digipot9_t *ctx)
DIGI POT 9 get RDY pin function.
digipot9_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: digipot9.h:194
digipot9_cfg_t::wp
pin_name_t wp
Definition: digipot9.h:189
digipot9_read_user_data
err_t digipot9_read_user_data(digipot9_t *ctx, uint8_t address, uint16_t *data_out)
DIGI POT 9 read user data function.
digipot9_t::spi
spi_master_t spi
Definition: digipot9.h:169
DIGIPOT9_ERROR
@ DIGIPOT9_ERROR
Definition: digipot9.h:206
digipot9_set_wp_pin
void digipot9_set_wp_pin(digipot9_t *ctx, uint8_t state)
DIGI POT 9 Set WP pin function.
digipot9_cfg_setup
void digipot9_cfg_setup(digipot9_cfg_t *cfg)
DIGI POT 9 configuration object setup function.
digipot9_cfg_t::mosi
pin_name_t mosi
Definition: digipot9.h:183
digipot9_cfg_t::miso
pin_name_t miso
Definition: digipot9.h:182