digipot4  2.0.0.0
digipot4.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 DIGIPOT4_H
36 #define DIGIPOT4_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_digital_out.h"
53 #include "drv_digital_in.h"
54 #include "drv_spi_master.h"
55 
56 // -------------------------------------------------------------- PUBLIC MACROS
67 #define DIGIPOT4_MAP_MIKROBUS( cfg, mikrobus ) \
68  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
69  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
70  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
71  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
72 
79 #define DIGIPOT4_RETVAL uint8_t
80 
81 #define DIGIPOT4_OK 0x00
82 #define DIGIPOT4_INIT_ERROR 0xFF
83 
89 #define DIGIPOT4_WIPER_REG_1 0x01
90 #define DIGIPOT4_WIPER_REG_2 0x02
91 
97 #define DIGIPOT4_NV_REG_1 0x11
98 #define DIGIPOT4_NV_REG_2 0x12
99 
105 #define DIGIPOT4_COPY_WIPER_TO_NV_1 0x21
106 #define DIGIPOT4_COPY_WIPER_TO_NV_2 0x22
107 #define DIGIPOT4_COPY_WIPER_TO_NV_1_2 0x23
108 
114 #define DIGIPOT4_COPY_NV_TO_WIPER_1 0x31
115 #define DIGIPOT4_COPY_NV_TO_WIPER_2 0x32
116 #define DIGIPOT4_COPY_NV_TO_WIPER_1_2 0x33
117  // End group macro
120 // --------------------------------------------------------------- PUBLIC TYPES
129 typedef struct
130 {
131  // Output pins
132 
133  digital_out_t cs;
134 
135  // Modules
136 
137  spi_master_t spi;
138  pin_name_t chip_select;
139 
140 } digipot4_t;
141 
145 typedef struct
146 {
147  // Communication gpio pins
148 
149  pin_name_t miso;
150  pin_name_t mosi;
151  pin_name_t sck;
152  pin_name_t cs;
153 
154  // static variable
155 
156  uint32_t spi_speed;
157  spi_master_mode_t spi_mode;
158  spi_master_chip_select_polarity_t cs_polarity;
159 
161  // End types group
163 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
164 
169 #ifdef __cplusplus
170 extern "C"{
171 #endif
172 
182 
192 
204 void digipot4_generic_transfer ( digipot4_t *ctx, uint8_t *wr_buf,
205  uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len );
206 
216 void digipot4_write_reg ( digipot4_t *ctx, uint8_t reg, uint16_t value );
217 
227 void digipot4_copy_reg ( digipot4_t *ctx, uint8_t reg );
228 
229 #ifdef __cplusplus
230 }
231 #endif
232 #endif // _DIGIPOT4_H_
233  // End public_function group
236 
237 // ------------------------------------------------------------------------- END
digipot4_cfg_t::spi_speed
uint32_t spi_speed
Definition: digipot4.h:156
digipot4_copy_reg
void digipot4_copy_reg(digipot4_t *ctx, uint8_t reg)
Copy data.
digipot4_t::chip_select
pin_name_t chip_select
Definition: digipot4.h:138
digipot4_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: digipot4.h:157
DIGIPOT4_RETVAL
#define DIGIPOT4_RETVAL
Definition: digipot4.h:79
digipot4_cfg_t::miso
pin_name_t miso
Definition: digipot4.h:149
digipot4_cfg_t
Click configuration structure definition.
Definition: digipot4.h:146
digipot4_cfg_t::mosi
pin_name_t mosi
Definition: digipot4.h:150
digipot4_generic_transfer
void digipot4_generic_transfer(digipot4_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len)
Generic transfer function.
digipot4_t
Click ctx object definition.
Definition: digipot4.h:130
digipot4_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: digipot4.h:158
digipot4_write_reg
void digipot4_write_reg(digipot4_t *ctx, uint8_t reg, uint16_t value)
Writes data in register.
digipot4_init
DIGIPOT4_RETVAL digipot4_init(digipot4_t *ctx, digipot4_cfg_t *cfg)
Initialization function.
digipot4_cfg_t::sck
pin_name_t sck
Definition: digipot4.h:151
digipot4_cfg_setup
void digipot4_cfg_setup(digipot4_cfg_t *cfg)
Config Object Initialization function.
digipot4_cfg_t::cs
pin_name_t cs
Definition: digipot4.h:152
digipot4_t::spi
spi_master_t spi
Definition: digipot4.h:137
digipot4_t::cs
digital_out_t cs
Definition: digipot4.h:133