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 "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_spi_master.h"
38 
59 #define DIGIPOT9_CMD_NOP 0
60 #define DIGIPOT9_CMD_RESTORE_EEMEM 1
61 #define DIGIPOT9_CMD_STORE_RDAC 2
62 #define DIGIPOT9_CMD_STORE_USER_DATA 3
63 #define DIGIPOT9_CMD_DECREMENT_6DB 4
64 #define DIGIPOT9_CMD_DECREMENT_ALL_6DB 5
65 #define DIGIPOT9_CMD_DECREMENT_ONE_STEP 6
66 #define DIGIPOT9_CMD_DECREMENT_ALL_ONE_STEP 7
67 #define DIGIPOT9_CMD_RESET_EEMEM 8
68 #define DIGIPOT9_CMD_READ_EEMEM 9
69 #define DIGIPOT9_CMD_READ_RDAC 10
70 #define DIGIPOT9_CMD_WRITE_DATA 11
71 #define DIGIPOT9_CMD_INCREMENT_6DB 12
72 #define DIGIPOT9_CMD_INCREMENT_ALL_6DB 13
73 #define DIGIPOT9_CMD_INCREMENT_ONE_STEP 14
74 #define DIGIPOT9_CMD_INCREMENT_ALL_ONE_STEP 15
75 
80 #define DIGIPOT9_ADDRESS_RDAC1 0
81 #define DIGIPOT9_ADDRESS_RDAC2 1
82 #define DIGIPOT9_ADDRESS_USER_DATA_0 2
83 #define DIGIPOT9_ADDRESS_USER_DATA_1 3
84 #define DIGIPOT9_ADDRESS_USER_DATA_2 4
85 #define DIGIPOT9_ADDRESS_USER_DATA_3 5
86 #define DIGIPOT9_ADDRESS_USER_DATA_4 6
87 #define DIGIPOT9_ADDRESS_USER_DATA_5 7
88 #define DIGIPOT9_ADDRESS_USER_DATA_6 8
89 #define DIGIPOT9_ADDRESS_USER_DATA_7 9
90 #define DIGIPOT9_ADDRESS_USER_DATA_8 10
91 #define DIGIPOT9_ADDRESS_USER_DATA_9 11
92 #define DIGIPOT9_ADDRESS_USER_DATA_10 12
93 #define DIGIPOT9_ADDRESS_USER_DATA_11 13
94 #define DIGIPOT9_ADDRESS_USER_DATA_12 14
95 #define DIGIPOT9_ADDRESS_FACTORY_USAGE 15
96  // digipot9_cmd
98 
113 #define DIGIPOT9_WIPER_FULL_SCALE 1023
114 #define DIGIPOT9_WIPER_MID_SCALE 512
115 #define DIGIPOT9_WIPER_ZERO_SCALE 0
116  // digipot9_set
118 
133 #define DIGIPOT9_MAP_MIKROBUS( cfg, mikrobus ) \
134  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
135  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
136  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
137  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
138  cfg.pr = MIKROBUS( mikrobus, MIKROBUS_RST ); \
139  cfg.wp = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
140  cfg.rdy = MIKROBUS( mikrobus, MIKROBUS_INT )
141  // digipot9_map // digipot9
144 
149 typedef struct
150 {
151  // Output pins
152  digital_out_t pr;
153  digital_out_t wp;
155  // Input pins
156  digital_in_t rdy;
158  // Modules
159  spi_master_t spi;
161  pin_name_t chip_select;
163 } digipot9_t;
164 
169 typedef struct
170 {
171  // Communication gpio pins
172  pin_name_t miso;
173  pin_name_t mosi;
174  pin_name_t sck;
175  pin_name_t cs;
177  // Additional gpio pins
178  pin_name_t pr;
179  pin_name_t wp;
180  pin_name_t rdy;
182  // static variable
183  uint32_t spi_speed;
184  spi_master_mode_t spi_mode;
185  spi_master_chip_select_polarity_t cs_polarity;
188 
193 typedef enum
194 {
196  DIGIPOT9_ERROR = -1
197 
199 
216 
232 
245 
261 err_t digipot9_generic_write ( digipot9_t *ctx, uint8_t command, uint8_t address, uint16_t data_in );
262 
278 err_t digipot9_generic_read ( digipot9_t *ctx, uint8_t command, uint8_t address, uint16_t *data_out );
279 
292 err_t digipot9_set_wiper_1 ( digipot9_t *ctx, uint16_t data_in );
293 
306 err_t digipot9_set_wiper_2 ( digipot9_t *ctx, uint16_t data_in );
307 
317 void digipot9_set_pr_pin ( digipot9_t *ctx, uint8_t state );
318 
328 void digipot9_set_wp_pin ( digipot9_t *ctx, uint8_t state );
329 
339 
353 err_t digipot9_write_user_data ( digipot9_t *ctx, uint8_t address, uint16_t data_in );
354 
368 err_t digipot9_read_user_data ( digipot9_t *ctx, uint8_t address, uint16_t *data_out );
369 
370 #ifdef __cplusplus
371 }
372 #endif
373 #endif // DIGIPOT9_H
374  // digipot9
376 
377 // ------------------------------------------------------------------------ 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:156
digipot9_cfg_t::sck
pin_name_t sck
Definition: digipot9.h:174
digipot9_cfg_t::pr
pin_name_t pr
Definition: digipot9.h:178
digipot9_cfg_t::spi_speed
uint32_t spi_speed
Definition: digipot9.h:183
digipot9_cfg_t::cs
pin_name_t cs
Definition: digipot9.h:175
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:180
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:152
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:153
digipot9_t
DIGI POT 9 Click context object.
Definition: digipot9.h:150
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:170
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:194
DIGIPOT9_OK
@ DIGIPOT9_OK
Definition: digipot9.h:195
digipot9_t::chip_select
pin_name_t chip_select
Definition: digipot9.h:161
digipot9_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: digipot9.h:185
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:184
digipot9_cfg_t::wp
pin_name_t wp
Definition: digipot9.h:179
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:159
DIGIPOT9_ERROR
@ DIGIPOT9_ERROR
Definition: digipot9.h:196
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:173
digipot9_cfg_t::miso
pin_name_t miso
Definition: digipot9.h:172