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 
38 // #include "drv_digital_out.h"
39 #include "drv_spi_master.h"
40 
41 // -------------------------------------------------------------- PUBLIC MACROS
51 #define DIGIPOT5_RETVAL uint8_t
52 
53 #define DIGIPOT5_OK 0x00
54 #define DIGIPOT5_INIT_ERROR 0xFF
55 
61 #define DIGIPOT5_RES_ZEROSCALE 0x00
62 #define DIGIPOT5_RES_1KOHM 0x1A
63 #define DIGIPOT5_RES_2KOHM 0x34
64 #define DIGIPOT5_RES_3KOHM 0x4E
65 #define DIGIPOT5_RES_5KOHM_HALFSCALE 0x80
66 #define DIGIPOT5_RES_7KOHM 0xB6
67 #define DIGIPOT5_RES_8KOHM 0xD0
68 #define DIGIPOT5_RES_10KOHM_FULLSCALE 0x100
69 
75 #define DIGIPOT5_MAP_MIKROBUS( cfg, mikrobus ) \
76  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
77  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
78  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
79  cfg.sdo = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
80  cfg.sdi = MIKROBUS( mikrobus, MIKROBUS_MOSI )
81  // End macros group
84 // --------------------------------------------------------------- PUBLIC TYPES
93 typedef enum
94 {
99 
101 
105 typedef enum
106 {
123 
125 
129 typedef struct
130 {
131  digital_out_t cs;
132 
133  // Reset control pin.
134  digital_out_t rst;
135 
136  // Modules.
137  spi_master_t spi;
138  pin_name_t chip_select;
139 
140 } digipot5_t;
141 
145 typedef struct
146 {
147  // Communication gpio pins.
148  pin_name_t cs;
149  pin_name_t sck;
150  pin_name_t sdo;
151  pin_name_t sdi;
152 
153  // Additional gpio pin.
154  pin_name_t rst;
155 
156  // SPI config variables.
157  uint32_t spi_speed;
158  spi_master_mode_t spi_mode;
159  spi_master_chip_select_polarity_t cs_polarity;
160 
162  // End types group
164 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
170 #ifdef __cplusplus
171 extern "C"{
172 #endif
173 
183 void
185 
200 
209 void
210 digipot5_reset( digipot5_t *ctx );
211 
220 void
222 
238  uint16_t data_in );
239 
254  uint16_t *data_out );
255 
270 
285 
286 #ifdef __cplusplus
287 }
288 #endif
289 #endif // _DIGIPOT5_H_
290  // End public_function group
293 
294 // ------------------------------------------------------------------------ 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:150
digipot5_reset
void digipot5_reset(digipot5_t *ctx)
Reset function.
DIGIPOT5_ERROR_REG_ADDR
Definition: digipot5.h:98
DIGIPOT5_REG_EEPROM2_NONVOL
Definition: digipot5.h:120
DIGIPOT5_REG_WIPER0_NONVOL
Definition: digipot5.h:109
digipot5_cfg_t::sdi
pin_name_t sdi
Definition: digipot5.h:151
DIGIPOT5_ERROR_INIT_DRV
Definition: digipot5.h:97
DIGIPOT5_REG_WIPER1_NONVOL
Definition: digipot5.h:110
digipot5_cfg_t
Click configuration structure definition.
Definition: digipot5.h:145
digipot5_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: digipot5.h:159
DIGIPOT5_REG_EEPROM0_NONVOL
Definition: digipot5.h:118
DIGIPOT5_REG_WIPER0_VOL
Definition: digipot5.h:107
digipot5_cfg_t::rst
pin_name_t rst
Definition: digipot5.h:154
digipot5_t::cs
digital_out_t cs
Definition: digipot5.h:131
digipot5_t
Click context object definition.
Definition: digipot5.h:129
digipot5_err_t
digipot5_err_t
Click error code definition.
Definition: digipot5.h:93
DIGIPOT5_REG_EEPROM1_NONVOL
Definition: digipot5.h:119
DIGIPOT5_REG_WIPER1_VOL
Definition: digipot5.h:108
DIGIPOT5_REG_WIPER3_NONVOL
Definition: digipot5.h:116
digipot5_t::spi
spi_master_t spi
Definition: digipot5.h:137
digipot5_cfg_setup
void digipot5_cfg_setup(digipot5_cfg_t *cfg)
Configuration Object Setup function.
DIGIPOT5_REG_WIPER3_VOL
Definition: digipot5.h:114
DIGIPOT5_REG_EEPROM4_NONVOL
Definition: digipot5.h:122
DIGIPOT5_REG_TCON1_VOL
Definition: digipot5.h:117
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:115
DIGIPOT5_REG_EEPROM3_NONVOL
Definition: digipot5.h:121
digipot5_t::chip_select
pin_name_t chip_select
Definition: digipot5.h:138
DIGIPOT5_REG_STATUS_VOL
Definition: digipot5.h:112
DIGIPOT5_REG_TCON0_VOL
Definition: digipot5.h:111
digipot5_t::rst
digital_out_t rst
Definition: digipot5.h:134
digipot5_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: digipot5.h:158
digipot5_default_cfg
void digipot5_default_cfg(digipot5_t *ctx)
Click Default Configuration function.
DIGIPOT5_STATUS_OK
Definition: digipot5.h:95
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:105
digipot5_cfg_t::sck
pin_name_t sck
Definition: digipot5.h:149
DIGIPOT5_ERROR_CMD
Definition: digipot5.h:96
DIGIPOT5_REG_WIPER2_VOL
Definition: digipot5.h:113
digipot5_cfg_t::spi_speed
uint32_t spi_speed
Definition: digipot5.h:157
digipot5_cfg_t::cs
pin_name_t cs
Definition: digipot5.h:148