digipot5  2.0.0.0
digipot5.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright (c) 2019, MikroElektronika - www.mikroe.com
4  * All rights reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef _DIGIPOT5_H_
36 #define _DIGIPOT5_H_
37 
38 // #include "drv_digital_out.h"
39 #include "drv_spi_master.h"
40 
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
52 #define DIGIPOT5_RES_ZEROSCALE 0x00
53 #define DIGIPOT5_RES_1KOHM 0x1A
54 #define DIGIPOT5_RES_2KOHM 0x34
55 #define DIGIPOT5_RES_3KOHM 0x4E
56 #define DIGIPOT5_RES_5KOHM_HALFSCALE 0x80
57 #define DIGIPOT5_RES_7KOHM 0xB6
58 #define DIGIPOT5_RES_8KOHM 0xD0
59 #define DIGIPOT5_RES_10KOHM_FULLSCALE 0x100
60 
66 #define DIGIPOT5_MAP_MIKROBUS( cfg, mikrobus ) \
67  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
68  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
69  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
70  cfg.sdo = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
71  cfg.sdi = MIKROBUS( mikrobus, MIKROBUS_MOSI )
72  // End macros group
75 // --------------------------------------------------------------- PUBLIC TYPES
84 typedef enum
85 {
90 
92 
96 typedef enum
97 {
114 
116 
120 typedef struct
121 {
122  // Reset control pin.
123  digital_out_t rst;
124 
125  // Module.
126  spi_master_t spi;
127 
128 } digipot5_t;
129 
133 typedef struct
134 {
135  // Communication gpio pins.
136  pin_name_t cs;
137  pin_name_t sck;
138  pin_name_t sdo;
139  pin_name_t sdi;
140 
141  // Additional gpio pin.
142  pin_name_t rst;
143 
144  // SPI config variables.
145  hal_spi_speed_t spi_speed;
146  hal_spi_mode_t spi_mode;
147 
149  // End types group
151 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
157 #ifdef __cplusplus
158 extern "C"{
159 #endif
160 
170 void
172 
187 
196 void
197 digipot5_reset( digipot5_t *ctx );
198 
207 void
209 
225  uint16_t data_in );
226 
241  uint16_t *data_out );
242 
257 
272 
273 #ifdef __cplusplus
274 }
275 #endif
276 #endif // _DIGIPOT5_H_
277  // End public_function group
280 
281 // ------------------------------------------------------------------------ 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:138
digipot5_reset
void digipot5_reset(digipot5_t *ctx)
Reset function.
DIGIPOT5_ERROR_REG_ADDR
Definition: digipot5.h:89
DIGIPOT5_REG_EEPROM2_NONVOL
Definition: digipot5.h:111
DIGIPOT5_REG_WIPER0_NONVOL
Definition: digipot5.h:100
digipot5_cfg_t::sdi
pin_name_t sdi
Definition: digipot5.h:139
DIGIPOT5_ERROR_INIT_DRV
Definition: digipot5.h:88
DIGIPOT5_REG_WIPER1_NONVOL
Definition: digipot5.h:101
digipot5_cfg_t
Click configuration structure definition.
Definition: digipot5.h:133
DIGIPOT5_REG_EEPROM0_NONVOL
Definition: digipot5.h:109
DIGIPOT5_REG_WIPER0_VOL
Definition: digipot5.h:98
digipot5_cfg_t::rst
pin_name_t rst
Definition: digipot5.h:142
digipot5_t
Click context object definition.
Definition: digipot5.h:120
digipot5_err_t
digipot5_err_t
Click error code definition.
Definition: digipot5.h:84
DIGIPOT5_REG_EEPROM1_NONVOL
Definition: digipot5.h:110
DIGIPOT5_REG_WIPER1_VOL
Definition: digipot5.h:99
DIGIPOT5_REG_WIPER3_NONVOL
Definition: digipot5.h:107
digipot5_t::spi
spi_master_t spi
Definition: digipot5.h:126
digipot5_cfg_setup
void digipot5_cfg_setup(digipot5_cfg_t *cfg)
Configuration Object Setup function.
DIGIPOT5_REG_WIPER3_VOL
Definition: digipot5.h:105
DIGIPOT5_REG_EEPROM4_NONVOL
Definition: digipot5.h:113
digipot5_cfg_t::spi_mode
hal_spi_mode_t spi_mode
Definition: digipot5.h:146
DIGIPOT5_REG_TCON1_VOL
Definition: digipot5.h:108
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
Definition: digipot5.h:106
DIGIPOT5_REG_EEPROM3_NONVOL
Definition: digipot5.h:112
DIGIPOT5_REG_STATUS_VOL
Definition: digipot5.h:103
DIGIPOT5_REG_TCON0_VOL
Definition: digipot5.h:102
digipot5_t::rst
digital_out_t rst
Definition: digipot5.h:123
digipot5_default_cfg
void digipot5_default_cfg(digipot5_t *ctx)
Click Default Configuration function.
digipot5_cfg_t::spi_speed
hal_spi_speed_t spi_speed
Definition: digipot5.h:145
DIGIPOT5_STATUS_OK
Definition: digipot5.h:86
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:96
digipot5_cfg_t::sck
pin_name_t sck
Definition: digipot5.h:137
DIGIPOT5_ERROR_CMD
Definition: digipot5.h:87
DIGIPOT5_REG_WIPER2_VOL
Definition: digipot5.h:104
digipot5_cfg_t::cs
pin_name_t cs
Definition: digipot5.h:136