digipot  2.0.0.0
digipot.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 DIGIPOT_H
36 #define DIGIPOT_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_spi_master.h"
40 
41 // -------------------------------------------------------------- PUBLIC MACROS
52 #define DIGIPOT_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
54  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
55  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
56  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS );
57 
63 #define DIGIPOT_RETVAL uint8_t
64 
65 #define DIGIPOT_OK 0x00
66 #define DIGIPOT_INIT_ERROR 0xFF
67 
73 #define DIGIPOT_VOLATILE_WIPER_0 0x00
74 #define DIGIPOT_VOLATILE_WIPER_1 0x01
75 #define DIGIPOT_NON_VOLATILE_WIPER_0 0x02
76 #define DIGIPOT_NON_VOLATILE_WIPER_1 0x03
77 #define DIGIPOT_VOLATILE_TCON_REGISTER 0x04
78 #define DIGIPOT_STATUS_REGISTER 0x05
79 
85 #define DIGIPOT_DATA_EEPROM_6 0x06
86 #define DIGIPOT_DATA_EEPROM_7 0x07
87 #define DIGIPOT_DATA_EEPROM_8 0x08
88 #define DIGIPOT_DATA_EEPROM_9 0x09
89 #define DIGIPOT_DATA_EEPROM_A 0x0A
90 #define DIGIPOT_DATA_EEPROM_B 0x0B
91 #define DIGIPOT_DATA_EEPROM_C 0x0C
92 #define DIGIPOT_DATA_EEPROM_D 0x0D
93 #define DIGIPOT_DATA_EEPROM_E 0x0E
94 #define DIGIPOT_DATA_EEPROM_F 0x0F
95 #define DIGIPOT_DATA_WRITE_CMD 0x20
96  // End group macro
99 // --------------------------------------------------------------- PUBLIC TYPES
108 typedef struct
109 {
110  // Modules
111 
112  spi_master_t spi;
113 
114 } digipot_t;
115 
119 typedef struct
120 {
121  // Communication gpio pins
122 
123  pin_name_t miso;
124  pin_name_t mosi;
125  pin_name_t sck;
126  pin_name_t cs;
127 
128  // static variable
129 
130  hal_spi_speed_t spi_speed;
131  hal_spi_mode_t spi_mode;
132 
133 } digipot_cfg_t;
134  // End types group
136 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
137 
142 #ifdef __cplusplus
143 extern "C"{
144 #endif
145 
154 void digipot_cfg_setup ( digipot_cfg_t *cfg );
155 
164 
173 void digipot_generic_transfer ( digipot_t *ctx, spi_master_transfer_data_t *block );
174 
183 void digipot_set_wiper_positions ( digipot_t *ctx, uint8_t wiper_pos );
184 
196 float digipot_convert_output ( uint16_t adc_val, float v_ref );
197 
198 #ifdef __cplusplus
199 }
200 #endif
201 #endif // _DIGIPOT_H_
202  // End public_function group
205 
206 // ------------------------------------------------------------------------- END
Click ctx object definition.
Definition: digipot.h:108
pin_name_t sck
Definition: digipot.h:125
hal_spi_speed_t spi_speed
Definition: digipot.h:130
spi_master_t spi
Definition: digipot.h:112
pin_name_t miso
Definition: digipot.h:123
DIGIPOT_RETVAL digipot_init(digipot_t *ctx, digipot_cfg_t *cfg)
Initialization function.
float digipot_convert_output(uint16_t adc_val, float v_ref)
Convert ADC value to volatage.
pin_name_t mosi
Definition: digipot.h:124
void digipot_generic_transfer(digipot_t *ctx, spi_master_transfer_data_t *block)
Generic transfer function.
Click configuration structure definition.
Definition: digipot.h:119
pin_name_t cs
Definition: digipot.h:126
void digipot_cfg_setup(digipot_cfg_t *cfg)
Config Object Initialization function.
uint8_t wiper_pos
Definition: main.c:31
#define DIGIPOT_RETVAL
Definition: digipot.h:63
hal_spi_mode_t spi_mode
Definition: digipot.h:131
void digipot_set_wiper_positions(digipot_t *ctx, uint8_t wiper_pos)
Set wiper position.