digipot5  2.0.0.0
digipot5.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 _DIGIPOT5_H_
36 #define _DIGIPOT5_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_spi_master.h"
53 
54 // -------------------------------------------------------------- PUBLIC MACROS
64 #define DIGIPOT5_RETVAL uint8_t
65 
66 #define DIGIPOT5_OK 0x00
67 #define DIGIPOT5_INIT_ERROR 0xFF
68 
74 #define DIGIPOT5_RES_ZEROSCALE 0x00
75 #define DIGIPOT5_RES_1KOHM 0x1A
76 #define DIGIPOT5_RES_2KOHM 0x34
77 #define DIGIPOT5_RES_3KOHM 0x4E
78 #define DIGIPOT5_RES_5KOHM_HALFSCALE 0x80
79 #define DIGIPOT5_RES_7KOHM 0xB6
80 #define DIGIPOT5_RES_8KOHM 0xD0
81 #define DIGIPOT5_RES_10KOHM_FULLSCALE 0x100
82 
88 #define DIGIPOT5_MAP_MIKROBUS( cfg, mikrobus ) \
89  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
90  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
91  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
92  cfg.sdo = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
93  cfg.sdi = MIKROBUS( mikrobus, MIKROBUS_MOSI )
94  // End macros group
97 // --------------------------------------------------------------- PUBLIC TYPES
106 typedef enum
107 {
112 
114 
118 typedef enum
119 {
136 
138 
142 typedef struct
143 {
144  digital_out_t cs;
145 
146  // Reset control pin.
147  digital_out_t rst;
148 
149  // Modules.
150  spi_master_t spi;
151  pin_name_t chip_select;
152 
153 } digipot5_t;
154 
158 typedef struct
159 {
160  // Communication gpio pins.
161  pin_name_t cs;
162  pin_name_t sck;
163  pin_name_t sdo;
164  pin_name_t sdi;
165 
166  // Additional gpio pin.
167  pin_name_t rst;
168 
169  // SPI config variables.
170  uint32_t spi_speed;
171  spi_master_mode_t spi_mode;
172  spi_master_chip_select_polarity_t cs_polarity;
173 
175  // End types group
177 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
183 #ifdef __cplusplus
184 extern "C"{
185 #endif
186 
196 void
198 
213 
222 void
224 
233 void
235 
251  uint16_t data_in );
252 
267  uint16_t *data_out );
268 
283 
298 
299 #ifdef __cplusplus
300 }
301 #endif
302 #endif // _DIGIPOT5_H_
303  // End public_function group
306 
307 // ------------------------------------------------------------------------ END
digipot5_generic_read
digipot5_err_t digipot5_generic_read(digipot5_t *ctx, digipot5_reg_t reg_addr, uint16_t *data_out)
Generic Read function.
digipot5_init
digipot5_err_t digipot5_init(digipot5_t *ctx, digipot5_cfg_t *cfg)
Click Initialization function.
digipot5_increment_wiper
digipot5_reg_t digipot5_increment_wiper(digipot5_t *ctx, digipot5_reg_t reg_addr)
Increment Wiper function.
digipot5_cfg_t::sdo
pin_name_t sdo
Definition: digipot5.h:163
digipot5_reset
void digipot5_reset(digipot5_t *ctx)
Reset function.
DIGIPOT5_ERROR_REG_ADDR
@ DIGIPOT5_ERROR_REG_ADDR
Definition: digipot5.h:111
DIGIPOT5_REG_EEPROM2_NONVOL
@ DIGIPOT5_REG_EEPROM2_NONVOL
Definition: digipot5.h:133
DIGIPOT5_REG_WIPER0_NONVOL
@ DIGIPOT5_REG_WIPER0_NONVOL
Definition: digipot5.h:122
digipot5_cfg_t::sdi
pin_name_t sdi
Definition: digipot5.h:164
DIGIPOT5_ERROR_INIT_DRV
@ DIGIPOT5_ERROR_INIT_DRV
Definition: digipot5.h:110
DIGIPOT5_REG_WIPER1_NONVOL
@ DIGIPOT5_REG_WIPER1_NONVOL
Definition: digipot5.h:123
digipot5_cfg_t
Click configuration structure definition.
Definition: digipot5.h:159
digipot5_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: digipot5.h:172
DIGIPOT5_REG_EEPROM0_NONVOL
@ DIGIPOT5_REG_EEPROM0_NONVOL
Definition: digipot5.h:131
DIGIPOT5_REG_WIPER0_VOL
@ DIGIPOT5_REG_WIPER0_VOL
Definition: digipot5.h:120
digipot5_cfg_t::rst
pin_name_t rst
Definition: digipot5.h:167
digipot5_t::cs
digital_out_t cs
Definition: digipot5.h:144
digipot5_t
Click context object definition.
Definition: digipot5.h:143
digipot5_err_t
digipot5_err_t
Click error code definition.
Definition: digipot5.h:107
DIGIPOT5_REG_EEPROM1_NONVOL
@ DIGIPOT5_REG_EEPROM1_NONVOL
Definition: digipot5.h:132
DIGIPOT5_REG_WIPER1_VOL
@ DIGIPOT5_REG_WIPER1_VOL
Definition: digipot5.h:121
DIGIPOT5_REG_WIPER3_NONVOL
@ DIGIPOT5_REG_WIPER3_NONVOL
Definition: digipot5.h:129
digipot5_t::spi
spi_master_t spi
Definition: digipot5.h:150
digipot5_cfg_setup
void digipot5_cfg_setup(digipot5_cfg_t *cfg)
Configuration Object Setup function.
DIGIPOT5_REG_WIPER3_VOL
@ DIGIPOT5_REG_WIPER3_VOL
Definition: digipot5.h:127
DIGIPOT5_REG_EEPROM4_NONVOL
@ DIGIPOT5_REG_EEPROM4_NONVOL
Definition: digipot5.h:135
DIGIPOT5_REG_TCON1_VOL
@ DIGIPOT5_REG_TCON1_VOL
Definition: digipot5.h:130
digipot5_generic_write
digipot5_err_t digipot5_generic_write(digipot5_t *ctx, digipot5_reg_t reg_addr, uint16_t data_in)
Generic Write function.
DIGIPOT5_REG_WIPER2_NONVOL
@ DIGIPOT5_REG_WIPER2_NONVOL
Definition: digipot5.h:128
DIGIPOT5_REG_EEPROM3_NONVOL
@ DIGIPOT5_REG_EEPROM3_NONVOL
Definition: digipot5.h:134
digipot5_t::chip_select
pin_name_t chip_select
Definition: digipot5.h:151
DIGIPOT5_REG_STATUS_VOL
@ DIGIPOT5_REG_STATUS_VOL
Definition: digipot5.h:125
DIGIPOT5_REG_TCON0_VOL
@ DIGIPOT5_REG_TCON0_VOL
Definition: digipot5.h:124
digipot5_t::rst
digital_out_t rst
Definition: digipot5.h:147
digipot5_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: digipot5.h:171
digipot5_default_cfg
void digipot5_default_cfg(digipot5_t *ctx)
Click Default Configuration function.
DIGIPOT5_STATUS_OK
@ DIGIPOT5_STATUS_OK
Definition: digipot5.h:108
digipot5_decrement_wiper
digipot5_reg_t digipot5_decrement_wiper(digipot5_t *ctx, digipot5_reg_t reg_addr)
Decrement Wiper function.
digipot5_reg_t
digipot5_reg_t
Click register address definition.
Definition: digipot5.h:119
digipot5_cfg_t::sck
pin_name_t sck
Definition: digipot5.h:162
DIGIPOT5_ERROR_CMD
@ DIGIPOT5_ERROR_CMD
Definition: digipot5.h:109
DIGIPOT5_REG_WIPER2_VOL
@ DIGIPOT5_REG_WIPER2_VOL
Definition: digipot5.h:126
digipot5_cfg_t::spi_speed
uint32_t spi_speed
Definition: digipot5.h:170
digipot5_cfg_t::cs
pin_name_t cs
Definition: digipot5.h:161