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 "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_spi_master.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
53 #define DIGIPOT4_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
55  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
56  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
57  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
58 
65 #define DIGIPOT4_RETVAL uint8_t
66 
67 #define DIGIPOT4_OK 0x00
68 #define DIGIPOT4_INIT_ERROR 0xFF
69 
75 #define DIGIPOT4_WIPER_REG_1 0x01
76 #define DIGIPOT4_WIPER_REG_2 0x02
77 
83 #define DIGIPOT4_NV_REG_1 0x11
84 #define DIGIPOT4_NV_REG_2 0x12
85 
91 #define DIGIPOT4_COPY_WIPER_TO_NV_1 0x21
92 #define DIGIPOT4_COPY_WIPER_TO_NV_2 0x22
93 #define DIGIPOT4_COPY_WIPER_TO_NV_1_2 0x23
94 
100 #define DIGIPOT4_COPY_NV_TO_WIPER_1 0x31
101 #define DIGIPOT4_COPY_NV_TO_WIPER_2 0x32
102 #define DIGIPOT4_COPY_NV_TO_WIPER_1_2 0x33
103  // End group macro
106 // --------------------------------------------------------------- PUBLIC TYPES
115 typedef struct
116 {
117  // Output pins
118 
119  digital_out_t cs;
120 
121  // Modules
122 
123  spi_master_t spi;
124  pin_name_t chip_select;
125 
126 } digipot4_t;
127 
131 typedef struct
132 {
133  // Communication gpio pins
134 
135  pin_name_t miso;
136  pin_name_t mosi;
137  pin_name_t sck;
138  pin_name_t cs;
139 
140  // static variable
141 
142  uint32_t spi_speed;
143  spi_master_mode_t spi_mode;
144  spi_master_chip_select_polarity_t cs_polarity;
145 
147  // End types group
149 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
150 
155 #ifdef __cplusplus
156 extern "C"{
157 #endif
158 
167 void digipot4_cfg_setup ( digipot4_cfg_t *cfg );
168 
178 
190 void digipot4_generic_transfer ( digipot4_t *ctx, uint8_t *wr_buf,
191  uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len );
192 
202 void digipot4_write_reg ( digipot4_t *ctx, uint8_t reg, uint16_t value );
203 
213 void digipot4_copy_reg ( digipot4_t *ctx, uint8_t reg );
214 
215 #ifdef __cplusplus
216 }
217 #endif
218 #endif // _DIGIPOT4_H_
219  // End public_function group
222 
223 // ------------------------------------------------------------------------- END
Click ctx object definition.
Definition: digipot4.h:115
spi_master_mode_t spi_mode
Definition: digipot4.h:143
void digipot4_copy_reg(digipot4_t *ctx, uint8_t reg)
Copy data.
void digipot4_cfg_setup(digipot4_cfg_t *cfg)
Config Object Initialization function.
Click configuration structure definition.
Definition: digipot4.h:131
pin_name_t miso
Definition: digipot4.h:135
pin_name_t mosi
Definition: digipot4.h:136
digital_out_t cs
Definition: digipot4.h:119
#define DIGIPOT4_RETVAL
Definition: digipot4.h:65
spi_master_chip_select_polarity_t cs_polarity
Definition: digipot4.h:144
void digipot4_write_reg(digipot4_t *ctx, uint8_t reg, uint16_t value)
Writes data in register.
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.
spi_master_t spi
Definition: digipot4.h:123
pin_name_t cs
Definition: digipot4.h:138
DIGIPOT4_RETVAL digipot4_init(digipot4_t *ctx, digipot4_cfg_t *cfg)
Initialization function.
uint32_t spi_speed
Definition: digipot4.h:142
pin_name_t sck
Definition: digipot4.h:137
pin_name_t chip_select
Definition: digipot4.h:124