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
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_spi_master.h"
52#include "spi_specifics.h"
53
74#define BUCK20_CMD_NOP 0
75#define BUCK20_CMD_RESTORE_EEMEM 1
76#define BUCK20_CMD_STORE_RDAC 2
77#define BUCK20_CMD_STORE_USER_DATA 3
78#define BUCK20_CMD_DECREMENT_6DB 4
79#define BUCK20_CMD_DECREMENT_ALL_6DB 5
80#define BUCK20_CMD_DECREMENT_ONE_STEP 6
81#define BUCK20_CMD_DECREMENT_ALL_ONE_STEP 7
82#define BUCK20_CMD_RESET_EEMEM 8
83#define BUCK20_CMD_READ_EEMEM 9
84#define BUCK20_CMD_READ_RDAC 10
85#define BUCK20_CMD_WRITE_DATA 11
86#define BUCK20_CMD_INCREMENT_6DB 12
87#define BUCK20_CMD_INCREMENT_ALL_6DB 13
88#define BUCK20_CMD_INCREMENT_ONE_STEP 14
89#define BUCK20_CMD_INCREMENT_ALL_ONE_STEP 15
90
95#define BUCK20_ADDRESS_RDAC1 0
96#define BUCK20_ADDRESS_RDAC2 1
97#define BUCK20_ADDRESS_USER_DATA_0 2
98#define BUCK20_ADDRESS_USER_DATA_1 3
99#define BUCK20_ADDRESS_USER_DATA_2 4
100#define BUCK20_ADDRESS_USER_DATA_3 5
101#define BUCK20_ADDRESS_USER_DATA_4 6
102#define BUCK20_ADDRESS_USER_DATA_5 7
103#define BUCK20_ADDRESS_USER_DATA_6 8
104#define BUCK20_ADDRESS_USER_DATA_7 9
105#define BUCK20_ADDRESS_USER_DATA_8 10
106#define BUCK20_ADDRESS_USER_DATA_9 11
107#define BUCK20_ADDRESS_USER_DATA_10 12
108#define BUCK20_ADDRESS_USER_DATA_11 13
109#define BUCK20_ADDRESS_USER_DATA_12 14
110#define BUCK20_ADDRESS_FACTORY_USAGE 15
111
112 // buck20_cmd
113
128#define BUCK20_WIPER_FULL_SCALE 1023
129#define BUCK20_WIPER_MID_SCALE 512
130#define BUCK20_WIPER_ZERO_SCALE 0
131
136#define BUCK20_RESISTOR_R6_KOHM 47.0f
137#define BUCK20_DIGIPOT_MAX_KOHM 250.0f
138#define BUCK20_BUCK_R2_KOHM 40.2f
139#define BUCK20_BUCK_VREF 0.6f
140
149#define BUCK20_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
150#define BUCK20_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
151
152 // buck20_set
153
168#define BUCK20_MAP_MIKROBUS( cfg, mikrobus ) \
169 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
170 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
171 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
172 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
173 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
174 cfg.rdy = MIKROBUS( mikrobus, MIKROBUS_INT )
175
176 // buck20_map
177 // buck20
178
183typedef struct
184{
185 // Output pins
186 digital_out_t rst;
188 // Input pins
189 digital_in_t rdy;
191 // Modules
192 spi_master_t spi;
194 pin_name_t chip_select;
196} buck20_t;
197
202typedef struct
203{
204 // Communication gpio pins
205 pin_name_t miso;
206 pin_name_t mosi;
207 pin_name_t sck;
208 pin_name_t cs;
210 // Additional gpio pins
211 pin_name_t rst;
212 pin_name_t rdy;
214 // static variable
215 uint32_t spi_speed;
216 spi_master_mode_t spi_mode;
217 spi_master_chip_select_polarity_t cs_polarity;
220
225typedef enum
226{
228 BUCK20_ERROR = -1
229
231
248
262err_t buck20_init ( buck20_t *ctx, buck20_cfg_t *cfg );
263
278err_t buck20_generic_write ( buck20_t *ctx, uint8_t command, uint8_t address, uint16_t data_in );
279
294err_t buck20_generic_read ( buck20_t *ctx, uint8_t command, uint8_t address, uint16_t *data_out );
295
307err_t buck20_set_wiper_1 ( buck20_t *ctx, uint16_t data_in );
308
321err_t buck20_write_user_data ( buck20_t *ctx, uint8_t address, uint16_t data_in );
322
335err_t buck20_read_user_data ( buck20_t *ctx, uint8_t address, uint16_t *data_out );
336
346
356
366
367#ifdef __cplusplus
368}
369#endif
370#endif // BUCK20_H
371
372 // buck20
373
374// ------------------------------------------------------------------------ END
buck20_return_value_t
Buck 20 Click return value data.
Definition buck20.h:226
@ BUCK20_ERROR
Definition buck20.h:228
@ BUCK20_OK
Definition buck20.h:227
err_t buck20_set_wiper_1(buck20_t *ctx, uint16_t data_in)
Buck 20 Set wiper 1 function.
uint8_t buck20_get_rdy_pin(buck20_t *ctx)
Buck 20 get rdy pin function.
void buck20_enable_device(buck20_t *ctx)
Buck 20 enable device function.
err_t buck20_write_user_data(buck20_t *ctx, uint8_t address, uint16_t data_in)
Buck 20 write user data function.
void buck20_disable_device(buck20_t *ctx)
Buck 20 disable device function.
void buck20_cfg_setup(buck20_cfg_t *cfg)
Buck 20 configuration object setup function.
err_t buck20_generic_read(buck20_t *ctx, uint8_t command, uint8_t address, uint16_t *data_out)
Buck 20 data reading function.
err_t buck20_read_user_data(buck20_t *ctx, uint8_t address, uint16_t *data_out)
Buck 20 read user data function.
err_t buck20_generic_write(buck20_t *ctx, uint8_t command, uint8_t address, uint16_t data_in)
Buck 20 data writing function.
err_t buck20_init(buck20_t *ctx, buck20_cfg_t *cfg)
Buck 20 initialization function.
This file contains SPI specific macros, functions, etc.
Buck 20 Click configuration object.
Definition buck20.h:203
spi_master_chip_select_polarity_t cs_polarity
Definition buck20.h:217
pin_name_t sck
Definition buck20.h:207
spi_master_mode_t spi_mode
Definition buck20.h:216
pin_name_t mosi
Definition buck20.h:206
uint32_t spi_speed
Definition buck20.h:215
pin_name_t rdy
Definition buck20.h:212
pin_name_t miso
Definition buck20.h:205
pin_name_t rst
Definition buck20.h:211
pin_name_t cs
Definition buck20.h:208
Buck 20 Click context object.
Definition buck20.h:184
spi_master_t spi
Definition buck20.h:192
digital_out_t rst
Definition buck20.h:186
pin_name_t chip_select
Definition buck20.h:194
digital_in_t rdy
Definition buck20.h:189