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 "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_spi_master.h"
38 #include "spi_specifics.h"
39 
60 #define BUCK20_CMD_NOP 0
61 #define BUCK20_CMD_RESTORE_EEMEM 1
62 #define BUCK20_CMD_STORE_RDAC 2
63 #define BUCK20_CMD_STORE_USER_DATA 3
64 #define BUCK20_CMD_DECREMENT_6DB 4
65 #define BUCK20_CMD_DECREMENT_ALL_6DB 5
66 #define BUCK20_CMD_DECREMENT_ONE_STEP 6
67 #define BUCK20_CMD_DECREMENT_ALL_ONE_STEP 7
68 #define BUCK20_CMD_RESET_EEMEM 8
69 #define BUCK20_CMD_READ_EEMEM 9
70 #define BUCK20_CMD_READ_RDAC 10
71 #define BUCK20_CMD_WRITE_DATA 11
72 #define BUCK20_CMD_INCREMENT_6DB 12
73 #define BUCK20_CMD_INCREMENT_ALL_6DB 13
74 #define BUCK20_CMD_INCREMENT_ONE_STEP 14
75 #define BUCK20_CMD_INCREMENT_ALL_ONE_STEP 15
76 
81 #define BUCK20_ADDRESS_RDAC1 0
82 #define BUCK20_ADDRESS_RDAC2 1
83 #define BUCK20_ADDRESS_USER_DATA_0 2
84 #define BUCK20_ADDRESS_USER_DATA_1 3
85 #define BUCK20_ADDRESS_USER_DATA_2 4
86 #define BUCK20_ADDRESS_USER_DATA_3 5
87 #define BUCK20_ADDRESS_USER_DATA_4 6
88 #define BUCK20_ADDRESS_USER_DATA_5 7
89 #define BUCK20_ADDRESS_USER_DATA_6 8
90 #define BUCK20_ADDRESS_USER_DATA_7 9
91 #define BUCK20_ADDRESS_USER_DATA_8 10
92 #define BUCK20_ADDRESS_USER_DATA_9 11
93 #define BUCK20_ADDRESS_USER_DATA_10 12
94 #define BUCK20_ADDRESS_USER_DATA_11 13
95 #define BUCK20_ADDRESS_USER_DATA_12 14
96 #define BUCK20_ADDRESS_FACTORY_USAGE 15
97  // buck20_cmd
99 
114 #define BUCK20_WIPER_FULL_SCALE 1023
115 #define BUCK20_WIPER_MID_SCALE 512
116 #define BUCK20_WIPER_ZERO_SCALE 0
117 
122 #define BUCK20_RESISTOR_R6_KOHM 47.0f
123 #define BUCK20_DIGIPOT_MAX_KOHM 250.0f
124 #define BUCK20_BUCK_R2_KOHM 40.2f
125 #define BUCK20_BUCK_VREF 0.6f
126 
135 #define BUCK20_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
136 #define BUCK20_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
137  // buck20_set
139 
154 #define BUCK20_MAP_MIKROBUS( cfg, mikrobus ) \
155  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
156  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
157  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
158  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
159  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
160  cfg.rdy = MIKROBUS( mikrobus, MIKROBUS_INT )
161  // buck20_map // buck20
164 
169 typedef struct
170 {
171  // Output pins
172  digital_out_t rst;
174  // Input pins
175  digital_in_t rdy;
177  // Modules
178  spi_master_t spi;
180  pin_name_t chip_select;
182 } buck20_t;
183 
188 typedef struct
189 {
190  // Communication gpio pins
191  pin_name_t miso;
192  pin_name_t mosi;
193  pin_name_t sck;
194  pin_name_t cs;
196  // Additional gpio pins
197  pin_name_t rst;
198  pin_name_t rdy;
200  // static variable
201  uint32_t spi_speed;
202  spi_master_mode_t spi_mode;
203  spi_master_chip_select_polarity_t cs_polarity;
205 } buck20_cfg_t;
206 
211 typedef enum
212 {
214  BUCK20_ERROR = -1
215 
217 
234 
248 err_t buck20_init ( buck20_t *ctx, buck20_cfg_t *cfg );
249 
264 err_t buck20_generic_write ( buck20_t *ctx, uint8_t command, uint8_t address, uint16_t data_in );
265 
280 err_t buck20_generic_read ( buck20_t *ctx, uint8_t command, uint8_t address, uint16_t *data_out );
281 
293 err_t buck20_set_wiper_1 ( buck20_t *ctx, uint16_t data_in );
294 
307 err_t buck20_write_user_data ( buck20_t *ctx, uint8_t address, uint16_t data_in );
308 
321 err_t buck20_read_user_data ( buck20_t *ctx, uint8_t address, uint16_t *data_out );
322 
331 uint8_t buck20_get_rdy_pin ( buck20_t *ctx );
332 
342 
352 
353 #ifdef __cplusplus
354 }
355 #endif
356 #endif // BUCK20_H
357  // buck20
359 
360 // ------------------------------------------------------------------------ END
buck20_t::spi
spi_master_t spi
Definition: buck20.h:178
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:193
BUCK20_ERROR
@ BUCK20_ERROR
Definition: buck20.h:214
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:189
buck20_cfg_t::miso
pin_name_t miso
Definition: buck20.h:191
buck20_cfg_t::mosi
pin_name_t mosi
Definition: buck20.h:192
buck20_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: buck20.h:203
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:197
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:172
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:198
buck20_t::chip_select
pin_name_t chip_select
Definition: buck20.h:180
buck20_cfg_setup
void buck20_cfg_setup(buck20_cfg_t *cfg)
Buck 20 configuration object setup function.
BUCK20_OK
@ BUCK20_OK
Definition: buck20.h:213
buck20_t
Buck 20 Click context object.
Definition: buck20.h:170
buck20_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: buck20.h:202
buck20_cfg_t::spi_speed
uint32_t spi_speed
Definition: buck20.h:201
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:194
buck20_t::rdy
digital_in_t rdy
Definition: buck20.h:175
buck20_return_value_t
buck20_return_value_t
Buck 20 Click return value data.
Definition: buck20.h:212