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 
42 #ifdef PREINIT_SUPPORTED
43 #include "preinit.h"
44 #endif
45 
46 #ifdef MikroCCoreVersion
47  #if MikroCCoreVersion >= 1
48  #include "delays.h"
49  #endif
50 #endif
51 
52 #include "drv_digital_out.h"
53 #include "drv_digital_in.h"
54 #include "drv_spi_master.h"
55 
56 // -------------------------------------------------------------- PUBLIC MACROS
67 #define BUCK7_MAP_MIKROBUS( cfg, mikrobus ) \
68  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
69  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
70  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
71  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
72  cfg.en = MIKROBUS( mikrobus, MIKROBUS_AN ); \
73  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
74  cfg.mod = MIKROBUS( mikrobus, MIKROBUS_PWM );
75 
81 #define BUCK7_RETVAL uint8_t
82 
83 #define BUCK7_OK 0x00
84 #define BUCK7_INIT_ERROR 0xFF
85 
91 #define BUCK7_MODE_DCM 0x01
92 #define BUCK7_MODE_PWM 0x00
93 
99 #define BUCK7_OUT_VOLTAGE_3_3V 0x0FAF
100 #define BUCK7_OUT_VOLTAGE_5V 0x0EA6
101 #define BUCK7_OUT_VOLTAGE_6V 0x0E10
102 #define BUCK7_OUT_VOLTAGE_7V 0x0D7A
103 #define BUCK7_OUT_VOLTAGE_8V 0x0CE4
104 #define BUCK7_OUT_VOLTAGE_9V 0x0C4E
105 #define BUCK7_OUT_VOLTAGE_10V 0x0BB8
106 #define BUCK7_OUT_VOLTAGE_11V 0x0B22
107 #define BUCK7_OUT_VOLTAGE_12V 0x0A8C
108 #define BUCK7_OUT_VOLTAGE_13V 0x09F6
109 #define BUCK7_OUT_VOLTAGE_14V 0x0960
110 #define BUCK7_OUT_VOLTAGE_15V 0x08CA
111 #define BUCK7_OUT_VOLTAGE_16V 0x0834
112 #define BUCK7_OUT_VOLTAGE_17V 0x079E
113 #define BUCK7_OUT_VOLTAGE_18V 0x0708
114 #define BUCK7_OUT_VOLTAGE_19V 0x0672
115 #define BUCK7_OUT_VOLTAGE_20V 0x059C
116 #define BUCK7_OUT_VOLTAGE_21V 0x0546
117 #define BUCK7_OUT_VOLTAGE_22V 0x04B0
118 #define BUCK7_OUT_VOLTAGE_23V 0x041A
119 #define BUCK7_OUT_VOLTAGE_24V 0x0384
120 #define BUCK7_OUT_VOLTAGE_25V 0x02EE
121 #define BUCK7_OUT_VOLTAGE_26V 0x0244
122 #define BUCK7_OUT_VOLTAGE_27V 0x0190
123 #define BUCK7_OUT_VOLTAGE_28V 0x00FA
124 #define BUCK7_OUT_VOLTAGE_29V 0x0096
125 #define BUCK7_OUT_VOLTAGE_30V 0x0000
126  // End group macro
129 // --------------------------------------------------------------- PUBLIC TYPES
138 typedef struct
139 {
140  // Output pins
141 
142  digital_out_t en;
143  digital_out_t rst;
144  digital_out_t mod;
145  digital_out_t cs;
146 
147  // Modules
148 
149  spi_master_t spi;
150  pin_name_t chip_select;
151 
152 } buck7_t;
153 
157 typedef struct
158 {
159  // Communication gpio pins
160 
161  pin_name_t miso;
162  pin_name_t mosi;
163  pin_name_t sck;
164  pin_name_t cs;
165 
166  // Additional gpio pins
167 
168  pin_name_t en;
169  pin_name_t rst;
170  pin_name_t mod;
171 
172  // static variable
173 
174  uint32_t spi_speed;
175  uint8_t spi_mode;
176  spi_master_chip_select_polarity_t cs_polarity;
177 
178 } buck7_cfg_t;
179  // End types group
181 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
182 
187 #ifdef __cplusplus
188 extern "C"{
189 #endif
190 
200 
209 
218 
231 (
232  buck7_t *ctx,
233  uint8_t *wr_buf,
234  uint16_t wr_len,
235  uint8_t *rd_buf,
236  uint16_t rd_len
237 );
238 
247 void buck7_set_output_voltage ( buck7_t *ctx, uint16_t voltage );
248 
256 void buck7_enable ( buck7_t *ctx );
257 
266 void buck7_set_mode ( buck7_t *ctx, uint8_t mode );
267 
275 uint8_t buck7_get_res_state ( buck7_t *ctx );
276 
277 
278 #ifdef __cplusplus
279 }
280 #endif
281 #endif // _BUCK7_H_
282  // End public_function group
285 
286 // ------------------------------------------------------------------------- END
buck7_cfg_t::spi_mode
uint8_t spi_mode
Definition: buck7.h:175
buck7_t::spi
spi_master_t spi
Definition: buck7.h:149
buck7_t::rst
digital_out_t rst
Definition: buck7.h:143
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:164
buck7_enable
void buck7_enable(buck7_t *ctx)
Function for enable chip.
buck7_cfg_t::mod
pin_name_t mod
Definition: buck7.h:170
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:150
buck7_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: buck7.h:176
buck7_t::cs
digital_out_t cs
Definition: buck7.h:145
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:161
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:81
buck7_cfg_t::en
pin_name_t en
Definition: buck7.h:168
buck7_cfg_t::rst
pin_name_t rst
Definition: buck7.h:169
buck7_init
BUCK7_RETVAL buck7_init(buck7_t *ctx, buck7_cfg_t *cfg)
Initialization function.
buck7_t
Click ctx object definition.
Definition: buck7.h:139
buck7_t::en
digital_out_t en
Definition: buck7.h:142
buck7_cfg_t::mosi
pin_name_t mosi
Definition: buck7.h:162
buck7_cfg_t::spi_speed
uint32_t spi_speed
Definition: buck7.h:174
buck7_t::mod
digital_out_t mod
Definition: buck7.h:144
buck7_default_cfg
void buck7_default_cfg(buck7_t *ctx)
Click Default Configuration function.
buck7_cfg_t
Click configuration structure definition.
Definition: buck7.h:158
buck7_cfg_t::sck
pin_name_t sck
Definition: buck7.h:163