buck7  2.0.0.0
buck7.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 BUCK7_H
36 #define BUCK7_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 BUCK7_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  cfg.en = MIKROBUS( mikrobus, MIKROBUS_AN ); \
59  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
60  cfg.mod = MIKROBUS( mikrobus, MIKROBUS_PWM );
61 
67 #define BUCK7_RETVAL uint8_t
68 
69 #define BUCK7_OK 0x00
70 #define BUCK7_INIT_ERROR 0xFF
71 
77 #define BUCK7_MODE_DCM 0x01
78 #define BUCK7_MODE_PWM 0x00
79 
85 #define BUCK7_OUT_VOLTAGE_3_3V 0x0FAF
86 #define BUCK7_OUT_VOLTAGE_5V 0x0EA6
87 #define BUCK7_OUT_VOLTAGE_6V 0x0E10
88 #define BUCK7_OUT_VOLTAGE_7V 0x0D7A
89 #define BUCK7_OUT_VOLTAGE_8V 0x0CE4
90 #define BUCK7_OUT_VOLTAGE_9V 0x0C4E
91 #define BUCK7_OUT_VOLTAGE_10V 0x0BB8
92 #define BUCK7_OUT_VOLTAGE_11V 0x0B22
93 #define BUCK7_OUT_VOLTAGE_12V 0x0A8C
94 #define BUCK7_OUT_VOLTAGE_13V 0x09F6
95 #define BUCK7_OUT_VOLTAGE_14V 0x0960
96 #define BUCK7_OUT_VOLTAGE_15V 0x08CA
97 #define BUCK7_OUT_VOLTAGE_16V 0x0834
98 #define BUCK7_OUT_VOLTAGE_17V 0x079E
99 #define BUCK7_OUT_VOLTAGE_18V 0x0708
100 #define BUCK7_OUT_VOLTAGE_19V 0x0672
101 #define BUCK7_OUT_VOLTAGE_20V 0x059C
102 #define BUCK7_OUT_VOLTAGE_21V 0x0546
103 #define BUCK7_OUT_VOLTAGE_22V 0x04B0
104 #define BUCK7_OUT_VOLTAGE_23V 0x041A
105 #define BUCK7_OUT_VOLTAGE_24V 0x0384
106 #define BUCK7_OUT_VOLTAGE_25V 0x02EE
107 #define BUCK7_OUT_VOLTAGE_26V 0x0244
108 #define BUCK7_OUT_VOLTAGE_27V 0x0190
109 #define BUCK7_OUT_VOLTAGE_28V 0x00FA
110 #define BUCK7_OUT_VOLTAGE_29V 0x0096
111 #define BUCK7_OUT_VOLTAGE_30V 0x0000
112  // End group macro
115 // --------------------------------------------------------------- PUBLIC TYPES
124 typedef struct
125 {
126  // Output pins
127 
128  digital_out_t en;
129  digital_out_t rst;
130  digital_out_t mod;
131  digital_out_t cs;
132 
133  // Modules
134 
135  spi_master_t spi;
136  pin_name_t chip_select;
137 
138 } buck7_t;
139 
143 typedef struct
144 {
145  // Communication gpio pins
146 
147  pin_name_t miso;
148  pin_name_t mosi;
149  pin_name_t sck;
150  pin_name_t cs;
151 
152  // Additional gpio pins
153 
154  pin_name_t en;
155  pin_name_t rst;
156  pin_name_t mod;
157 
158  // static variable
159 
160  uint32_t spi_speed;
161  uint8_t spi_mode;
162  spi_master_chip_select_polarity_t cs_polarity;
163 
164 } buck7_cfg_t;
165  // End types group
167 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
168 
173 #ifdef __cplusplus
174 extern "C"{
175 #endif
176 
185 void buck7_cfg_setup ( buck7_cfg_t *cfg );
186 
195 
203 void buck7_default_cfg ( buck7_t *ctx );
204 
217 (
218  buck7_t *ctx,
219  uint8_t *wr_buf,
220  uint16_t wr_len,
221  uint8_t *rd_buf,
222  uint16_t rd_len
223 );
224 
233 void buck7_set_output_voltage ( buck7_t *ctx, uint16_t voltage );
234 
242 void buck7_enable ( buck7_t *ctx );
243 
252 void buck7_set_mode ( buck7_t *ctx, uint8_t mode );
253 
261 uint8_t buck7_get_res_state ( buck7_t *ctx );
262 
263 
264 #ifdef __cplusplus
265 }
266 #endif
267 #endif // _BUCK7_H_
268  // End public_function group
271 
272 // ------------------------------------------------------------------------- END
buck7_cfg_t::spi_mode
uint8_t spi_mode
Definition: buck7.h:161
buck7_t::spi
spi_master_t spi
Definition: buck7.h:135
buck7_t::rst
digital_out_t rst
Definition: buck7.h:129
buck7_generic_transfer
void buck7_generic_transfer(buck7_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len)
Generic transfer function.
buck7_cfg_t::cs
pin_name_t cs
Definition: buck7.h:150
buck7_enable
void buck7_enable(buck7_t *ctx)
Function for enable chip.
buck7_cfg_t::mod
pin_name_t mod
Definition: buck7.h:156
buck7_get_res_state
uint8_t buck7_get_res_state(buck7_t *ctx)
Function for read RES state.
buck7_t::chip_select
pin_name_t chip_select
Definition: buck7.h:136
buck7_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: buck7.h:162
buck7_t::cs
digital_out_t cs
Definition: buck7.h:131
buck7_cfg_setup
void buck7_cfg_setup(buck7_cfg_t *cfg)
Config Object Initialization function.
buck7_set_output_voltage
void buck7_set_output_voltage(buck7_t *ctx, uint16_t voltage)
Function for settings output voltage.
buck7_cfg_t::miso
pin_name_t miso
Definition: buck7.h:147
buck7_set_mode
void buck7_set_mode(buck7_t *ctx, uint8_t mode)
Function for settings chip mode.
BUCK7_RETVAL
#define BUCK7_RETVAL
Definition: buck7.h:67
buck7_cfg_t::en
pin_name_t en
Definition: buck7.h:154
buck7_cfg_t::rst
pin_name_t rst
Definition: buck7.h:155
buck7_init
BUCK7_RETVAL buck7_init(buck7_t *ctx, buck7_cfg_t *cfg)
Initialization function.
buck7_t
Click ctx object definition.
Definition: buck7.h:124
buck7_t::en
digital_out_t en
Definition: buck7.h:128
buck7_cfg_t::mosi
pin_name_t mosi
Definition: buck7.h:148
buck7_cfg_t::spi_speed
uint32_t spi_speed
Definition: buck7.h:160
buck7_t::mod
digital_out_t mod
Definition: buck7.h:130
buck7_default_cfg
void buck7_default_cfg(buck7_t *ctx)
Click Default Configuration function.
buck7_cfg_t
Click configuration structure definition.
Definition: buck7.h:143
buck7_cfg_t::sck
pin_name_t sck
Definition: buck7.h:149