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 
38 #include "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_spi_master.h"
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
63 #define DIGIPOT4_MAP_MIKROBUS( cfg, mikrobus ) \
64  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
65  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
66  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
67  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
68 
75 #define DIGIPOT4_RETVAL uint8_t
76 
77 #define DIGIPOT4_OK 0x00
78 #define DIGIPOT4_INIT_ERROR 0xFF
79 
85 #define DIGIPOT4_WIPER_REG_1 0x01
86 #define DIGIPOT4_WIPER_REG_2 0x02
87 
93 #define DIGIPOT4_NV_REG_1 0x11
94 #define DIGIPOT4_NV_REG_2 0x12
95 
101 #define DIGIPOT4_COPY_WIPER_TO_NV_1 0x21
102 #define DIGIPOT4_COPY_WIPER_TO_NV_2 0x22
103 #define DIGIPOT4_COPY_WIPER_TO_NV_1_2 0x23
104 
110 #define DIGIPOT4_COPY_NV_TO_WIPER_1 0x31
111 #define DIGIPOT4_COPY_NV_TO_WIPER_2 0x32
112 #define DIGIPOT4_COPY_NV_TO_WIPER_1_2 0x33
113  // End group macro
116 // --------------------------------------------------------------- PUBLIC TYPES
125 typedef struct
126 {
127  // Output pins
128 
129  digital_out_t cs;
130 
131  // Modules
132 
133  spi_master_t spi;
134  pin_name_t chip_select;
135 
136 } digipot4_t;
137 
141 typedef struct
142 {
143  // Communication gpio pins
144 
145  pin_name_t miso;
146  pin_name_t mosi;
147  pin_name_t sck;
148  pin_name_t cs;
149 
150  // static variable
151 
152  uint32_t spi_speed;
153  spi_master_mode_t spi_mode;
154  spi_master_chip_select_polarity_t cs_polarity;
155 
157  // End types group
159 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
160 
165 #ifdef __cplusplus
166 extern "C"{
167 #endif
168 
178 
188 
200 void digipot4_generic_transfer ( digipot4_t *ctx, uint8_t *wr_buf,
201  uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len );
202 
212 void digipot4_write_reg ( digipot4_t *ctx, uint8_t reg, uint16_t value );
213 
223 void digipot4_copy_reg ( digipot4_t *ctx, uint8_t reg );
224 
225 #ifdef __cplusplus
226 }
227 #endif
228 #endif // _DIGIPOT4_H_
229  // End public_function group
232 
233 // ------------------------------------------------------------------------- END
digipot4_cfg_t::spi_speed
uint32_t spi_speed
Definition: digipot4.h:152
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:134
digipot4_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: digipot4.h:153
DIGIPOT4_RETVAL
#define DIGIPOT4_RETVAL
Definition: digipot4.h:75
digipot4_cfg_t::miso
pin_name_t miso
Definition: digipot4.h:145
digipot4_cfg_t
Click configuration structure definition.
Definition: digipot4.h:142
digipot4_cfg_t::mosi
pin_name_t mosi
Definition: digipot4.h:146
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:126
digipot4_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: digipot4.h:154
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:147
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:148
digipot4_t::spi
spi_master_t spi
Definition: digipot4.h:133
digipot4_t::cs
digital_out_t cs
Definition: digipot4.h:129