buck20  2.1.0.0
buck20.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2020 MikroElektronika d.o.o.
3 ** Contact: https://www.mikroe.com/contact
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 ** of this software and associated documentation files (the "Software"), to deal
7 ** in the Software without restriction, including without limitation the rights
8 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 ** copies of the Software, and to permit persons to whom the Software is
10 ** furnished to do so, subject to the following conditions:
11 ** The above copyright notice and this permission notice shall be
12 ** included in all copies or substantial portions of the Software.
13 **
14 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 ** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 ** USE OR OTHER DEALINGS IN THE SOFTWARE.
21 ****************************************************************************/
22 
28 #ifndef BUCK20_H
29 #define BUCK20_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_spi_master.h"
48 #include "spi_specifics.h"
49 
70 #define BUCK20_CMD_NOP 0
71 #define BUCK20_CMD_RESTORE_EEMEM 1
72 #define BUCK20_CMD_STORE_RDAC 2
73 #define BUCK20_CMD_STORE_USER_DATA 3
74 #define BUCK20_CMD_DECREMENT_6DB 4
75 #define BUCK20_CMD_DECREMENT_ALL_6DB 5
76 #define BUCK20_CMD_DECREMENT_ONE_STEP 6
77 #define BUCK20_CMD_DECREMENT_ALL_ONE_STEP 7
78 #define BUCK20_CMD_RESET_EEMEM 8
79 #define BUCK20_CMD_READ_EEMEM 9
80 #define BUCK20_CMD_READ_RDAC 10
81 #define BUCK20_CMD_WRITE_DATA 11
82 #define BUCK20_CMD_INCREMENT_6DB 12
83 #define BUCK20_CMD_INCREMENT_ALL_6DB 13
84 #define BUCK20_CMD_INCREMENT_ONE_STEP 14
85 #define BUCK20_CMD_INCREMENT_ALL_ONE_STEP 15
86 
91 #define BUCK20_ADDRESS_RDAC1 0
92 #define BUCK20_ADDRESS_RDAC2 1
93 #define BUCK20_ADDRESS_USER_DATA_0 2
94 #define BUCK20_ADDRESS_USER_DATA_1 3
95 #define BUCK20_ADDRESS_USER_DATA_2 4
96 #define BUCK20_ADDRESS_USER_DATA_3 5
97 #define BUCK20_ADDRESS_USER_DATA_4 6
98 #define BUCK20_ADDRESS_USER_DATA_5 7
99 #define BUCK20_ADDRESS_USER_DATA_6 8
100 #define BUCK20_ADDRESS_USER_DATA_7 9
101 #define BUCK20_ADDRESS_USER_DATA_8 10
102 #define BUCK20_ADDRESS_USER_DATA_9 11
103 #define BUCK20_ADDRESS_USER_DATA_10 12
104 #define BUCK20_ADDRESS_USER_DATA_11 13
105 #define BUCK20_ADDRESS_USER_DATA_12 14
106 #define BUCK20_ADDRESS_FACTORY_USAGE 15
107  // buck20_cmd
109 
124 #define BUCK20_WIPER_FULL_SCALE 1023
125 #define BUCK20_WIPER_MID_SCALE 512
126 #define BUCK20_WIPER_ZERO_SCALE 0
127 
132 #define BUCK20_RESISTOR_R6_KOHM 47.0f
133 #define BUCK20_DIGIPOT_MAX_KOHM 250.0f
134 #define BUCK20_BUCK_R2_KOHM 40.2f
135 #define BUCK20_BUCK_VREF 0.6f
136 
145 #define BUCK20_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
146 #define BUCK20_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
147  // buck20_set
149 
164 #define BUCK20_MAP_MIKROBUS( cfg, mikrobus ) \
165  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
166  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
167  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
168  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
169  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
170  cfg.rdy = MIKROBUS( mikrobus, MIKROBUS_INT )
171  // buck20_map // buck20
174 
179 typedef struct
180 {
181  // Output pins
182  digital_out_t rst;
184  // Input pins
185  digital_in_t rdy;
187  // Modules
188  spi_master_t spi;
190  pin_name_t chip_select;
192 } buck20_t;
193 
198 typedef struct
199 {
200  // Communication gpio pins
201  pin_name_t miso;
202  pin_name_t mosi;
203  pin_name_t sck;
204  pin_name_t cs;
206  // Additional gpio pins
207  pin_name_t rst;
208  pin_name_t rdy;
210  // static variable
211  uint32_t spi_speed;
212  spi_master_mode_t spi_mode;
213  spi_master_chip_select_polarity_t cs_polarity;
215 } buck20_cfg_t;
216 
221 typedef enum
222 {
224  BUCK20_ERROR = -1
225 
227 
244 
258 err_t buck20_init ( buck20_t *ctx, buck20_cfg_t *cfg );
259 
274 err_t buck20_generic_write ( buck20_t *ctx, uint8_t command, uint8_t address, uint16_t data_in );
275 
290 err_t buck20_generic_read ( buck20_t *ctx, uint8_t command, uint8_t address, uint16_t *data_out );
291 
303 err_t buck20_set_wiper_1 ( buck20_t *ctx, uint16_t data_in );
304 
317 err_t buck20_write_user_data ( buck20_t *ctx, uint8_t address, uint16_t data_in );
318 
331 err_t buck20_read_user_data ( buck20_t *ctx, uint8_t address, uint16_t *data_out );
332 
341 uint8_t buck20_get_rdy_pin ( buck20_t *ctx );
342 
352 
362 
363 #ifdef __cplusplus
364 }
365 #endif
366 #endif // BUCK20_H
367  // buck20
369 
370 // ------------------------------------------------------------------------ END
buck20_t::spi
spi_master_t spi
Definition: buck20.h:188
buck20_generic_read
err_t buck20_generic_read(buck20_t *ctx, uint8_t command, uint8_t address, uint16_t *data_out)
Buck 20 data reading function.
buck20_cfg_t::sck
pin_name_t sck
Definition: buck20.h:203
BUCK20_ERROR
@ BUCK20_ERROR
Definition: buck20.h:224
spi_specifics.h
This file contains SPI specific macros, functions, etc.
buck20_set_wiper_1
err_t buck20_set_wiper_1(buck20_t *ctx, uint16_t data_in)
Buck 20 Set wiper 1 function.
buck20_init
err_t buck20_init(buck20_t *ctx, buck20_cfg_t *cfg)
Buck 20 initialization function.
buck20_disable_device
void buck20_disable_device(buck20_t *ctx)
Buck 20 disable device function.
buck20_generic_write
err_t buck20_generic_write(buck20_t *ctx, uint8_t command, uint8_t address, uint16_t data_in)
Buck 20 data writing function.
buck20_cfg_t
Buck 20 Click configuration object.
Definition: buck20.h:199
buck20_cfg_t::miso
pin_name_t miso
Definition: buck20.h:201
buck20_cfg_t::mosi
pin_name_t mosi
Definition: buck20.h:202
buck20_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: buck20.h:213
buck20_write_user_data
err_t buck20_write_user_data(buck20_t *ctx, uint8_t address, uint16_t data_in)
Buck 20 write user data function.
buck20_cfg_t::rst
pin_name_t rst
Definition: buck20.h:207
buck20_read_user_data
err_t buck20_read_user_data(buck20_t *ctx, uint8_t address, uint16_t *data_out)
Buck 20 read user data function.
buck20_t::rst
digital_out_t rst
Definition: buck20.h:182
buck20_get_rdy_pin
uint8_t buck20_get_rdy_pin(buck20_t *ctx)
Buck 20 get rdy pin function.
buck20_cfg_t::rdy
pin_name_t rdy
Definition: buck20.h:208
buck20_t::chip_select
pin_name_t chip_select
Definition: buck20.h:190
buck20_cfg_setup
void buck20_cfg_setup(buck20_cfg_t *cfg)
Buck 20 configuration object setup function.
BUCK20_OK
@ BUCK20_OK
Definition: buck20.h:223
buck20_t
Buck 20 Click context object.
Definition: buck20.h:180
buck20_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: buck20.h:212
buck20_cfg_t::spi_speed
uint32_t spi_speed
Definition: buck20.h:211
buck20_enable_device
void buck20_enable_device(buck20_t *ctx)
Buck 20 enable device function.
buck20_cfg_t::cs
pin_name_t cs
Definition: buck20.h:204
buck20_t::rdy
digital_in_t rdy
Definition: buck20.h:185
buck20_return_value_t
buck20_return_value_t
Buck 20 Click return value data.
Definition: buck20.h:222