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 
39 #ifdef PREINIT_SUPPORTED
40 #include "preinit.h"
41 #endif
42 
43 #ifdef MikroCCoreVersion
44  #if MikroCCoreVersion >= 1
45  #include "delays.h"
46  #endif
47 #endif
48 
49 #include "drv_digital_out.h"
50 #include "drv_digital_in.h"
51 #include "drv_spi_master.h"
52 
73 #define DIGIPOT9_CMD_NOP 0
74 #define DIGIPOT9_CMD_RESTORE_EEMEM 1
75 #define DIGIPOT9_CMD_STORE_RDAC 2
76 #define DIGIPOT9_CMD_STORE_USER_DATA 3
77 #define DIGIPOT9_CMD_DECREMENT_6DB 4
78 #define DIGIPOT9_CMD_DECREMENT_ALL_6DB 5
79 #define DIGIPOT9_CMD_DECREMENT_ONE_STEP 6
80 #define DIGIPOT9_CMD_DECREMENT_ALL_ONE_STEP 7
81 #define DIGIPOT9_CMD_RESET_EEMEM 8
82 #define DIGIPOT9_CMD_READ_EEMEM 9
83 #define DIGIPOT9_CMD_READ_RDAC 10
84 #define DIGIPOT9_CMD_WRITE_DATA 11
85 #define DIGIPOT9_CMD_INCREMENT_6DB 12
86 #define DIGIPOT9_CMD_INCREMENT_ALL_6DB 13
87 #define DIGIPOT9_CMD_INCREMENT_ONE_STEP 14
88 #define DIGIPOT9_CMD_INCREMENT_ALL_ONE_STEP 15
89 
94 #define DIGIPOT9_ADDRESS_RDAC1 0
95 #define DIGIPOT9_ADDRESS_RDAC2 1
96 #define DIGIPOT9_ADDRESS_USER_DATA_0 2
97 #define DIGIPOT9_ADDRESS_USER_DATA_1 3
98 #define DIGIPOT9_ADDRESS_USER_DATA_2 4
99 #define DIGIPOT9_ADDRESS_USER_DATA_3 5
100 #define DIGIPOT9_ADDRESS_USER_DATA_4 6
101 #define DIGIPOT9_ADDRESS_USER_DATA_5 7
102 #define DIGIPOT9_ADDRESS_USER_DATA_6 8
103 #define DIGIPOT9_ADDRESS_USER_DATA_7 9
104 #define DIGIPOT9_ADDRESS_USER_DATA_8 10
105 #define DIGIPOT9_ADDRESS_USER_DATA_9 11
106 #define DIGIPOT9_ADDRESS_USER_DATA_10 12
107 #define DIGIPOT9_ADDRESS_USER_DATA_11 13
108 #define DIGIPOT9_ADDRESS_USER_DATA_12 14
109 #define DIGIPOT9_ADDRESS_FACTORY_USAGE 15
110  // digipot9_cmd
112 
127 #define DIGIPOT9_WIPER_FULL_SCALE 1023
128 #define DIGIPOT9_WIPER_MID_SCALE 512
129 #define DIGIPOT9_WIPER_ZERO_SCALE 0
130  // digipot9_set
132 
147 #define DIGIPOT9_MAP_MIKROBUS( cfg, mikrobus ) \
148  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
149  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
150  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
151  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
152  cfg.pr = MIKROBUS( mikrobus, MIKROBUS_RST ); \
153  cfg.wp = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
154  cfg.rdy = MIKROBUS( mikrobus, MIKROBUS_INT )
155  // digipot9_map // digipot9
158 
163 typedef struct
164 {
165  // Output pins
166  digital_out_t pr;
167  digital_out_t wp;
169  // Input pins
170  digital_in_t rdy;
172  // Modules
173  spi_master_t spi;
175  pin_name_t chip_select;
177 } digipot9_t;
178 
183 typedef struct
184 {
185  // Communication gpio pins
186  pin_name_t miso;
187  pin_name_t mosi;
188  pin_name_t sck;
189  pin_name_t cs;
191  // Additional gpio pins
192  pin_name_t pr;
193  pin_name_t wp;
194  pin_name_t rdy;
196  // static variable
197  uint32_t spi_speed;
198  spi_master_mode_t spi_mode;
199  spi_master_chip_select_polarity_t cs_polarity;
202 
207 typedef enum
208 {
210  DIGIPOT9_ERROR = -1
211 
213 
230 
246 
259 
275 err_t digipot9_generic_write ( digipot9_t *ctx, uint8_t command, uint8_t address, uint16_t data_in );
276 
292 err_t digipot9_generic_read ( digipot9_t *ctx, uint8_t command, uint8_t address, uint16_t *data_out );
293 
306 err_t digipot9_set_wiper_1 ( digipot9_t *ctx, uint16_t data_in );
307 
320 err_t digipot9_set_wiper_2 ( digipot9_t *ctx, uint16_t data_in );
321 
331 void digipot9_set_pr_pin ( digipot9_t *ctx, uint8_t state );
332 
342 void digipot9_set_wp_pin ( digipot9_t *ctx, uint8_t state );
343 
353 
367 err_t digipot9_write_user_data ( digipot9_t *ctx, uint8_t address, uint16_t data_in );
368 
382 err_t digipot9_read_user_data ( digipot9_t *ctx, uint8_t address, uint16_t *data_out );
383 
384 #ifdef __cplusplus
385 }
386 #endif
387 #endif // DIGIPOT9_H
388  // digipot9
390 
391 // ------------------------------------------------------------------------ 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:170
digipot9_cfg_t::sck
pin_name_t sck
Definition: digipot9.h:188
digipot9_cfg_t::pr
pin_name_t pr
Definition: digipot9.h:192
digipot9_cfg_t::spi_speed
uint32_t spi_speed
Definition: digipot9.h:197
digipot9_cfg_t::cs
pin_name_t cs
Definition: digipot9.h:189
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:194
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:166
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:167
digipot9_t
DIGI POT 9 Click context object.
Definition: digipot9.h:164
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:184
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:208
DIGIPOT9_OK
@ DIGIPOT9_OK
Definition: digipot9.h:209
digipot9_t::chip_select
pin_name_t chip_select
Definition: digipot9.h:175
digipot9_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: digipot9.h:199
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:198
digipot9_cfg_t::wp
pin_name_t wp
Definition: digipot9.h:193
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:173
DIGIPOT9_ERROR
@ DIGIPOT9_ERROR
Definition: digipot9.h:210
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:187
digipot9_cfg_t::miso
pin_name_t miso
Definition: digipot9.h:186