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 "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_spi_master.h"
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
63 #define BUCK7_MAP_MIKROBUS( cfg, mikrobus ) \
64  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
65  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
66  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
67  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
68  cfg.en = MIKROBUS( mikrobus, MIKROBUS_AN ); \
69  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
70  cfg.mod = MIKROBUS( mikrobus, MIKROBUS_PWM );
71 
77 #define BUCK7_RETVAL uint8_t
78 
79 #define BUCK7_OK 0x00
80 #define BUCK7_INIT_ERROR 0xFF
81 
87 #define BUCK7_MODE_DCM 0x01
88 #define BUCK7_MODE_PWM 0x00
89 
95 #define BUCK7_OUT_VOLTAGE_3_3V 0x0FAF
96 #define BUCK7_OUT_VOLTAGE_5V 0x0EA6
97 #define BUCK7_OUT_VOLTAGE_6V 0x0E10
98 #define BUCK7_OUT_VOLTAGE_7V 0x0D7A
99 #define BUCK7_OUT_VOLTAGE_8V 0x0CE4
100 #define BUCK7_OUT_VOLTAGE_9V 0x0C4E
101 #define BUCK7_OUT_VOLTAGE_10V 0x0BB8
102 #define BUCK7_OUT_VOLTAGE_11V 0x0B22
103 #define BUCK7_OUT_VOLTAGE_12V 0x0A8C
104 #define BUCK7_OUT_VOLTAGE_13V 0x09F6
105 #define BUCK7_OUT_VOLTAGE_14V 0x0960
106 #define BUCK7_OUT_VOLTAGE_15V 0x08CA
107 #define BUCK7_OUT_VOLTAGE_16V 0x0834
108 #define BUCK7_OUT_VOLTAGE_17V 0x079E
109 #define BUCK7_OUT_VOLTAGE_18V 0x0708
110 #define BUCK7_OUT_VOLTAGE_19V 0x0672
111 #define BUCK7_OUT_VOLTAGE_20V 0x059C
112 #define BUCK7_OUT_VOLTAGE_21V 0x0546
113 #define BUCK7_OUT_VOLTAGE_22V 0x04B0
114 #define BUCK7_OUT_VOLTAGE_23V 0x041A
115 #define BUCK7_OUT_VOLTAGE_24V 0x0384
116 #define BUCK7_OUT_VOLTAGE_25V 0x02EE
117 #define BUCK7_OUT_VOLTAGE_26V 0x0244
118 #define BUCK7_OUT_VOLTAGE_27V 0x0190
119 #define BUCK7_OUT_VOLTAGE_28V 0x00FA
120 #define BUCK7_OUT_VOLTAGE_29V 0x0096
121 #define BUCK7_OUT_VOLTAGE_30V 0x0000
122  // End group macro
125 // --------------------------------------------------------------- PUBLIC TYPES
134 typedef struct
135 {
136  // Output pins
137 
138  digital_out_t en;
139  digital_out_t rst;
140  digital_out_t mod;
141  digital_out_t cs;
142 
143  // Modules
144 
145  spi_master_t spi;
146  pin_name_t chip_select;
147 
148 } buck7_t;
149 
153 typedef struct
154 {
155  // Communication gpio pins
156 
157  pin_name_t miso;
158  pin_name_t mosi;
159  pin_name_t sck;
160  pin_name_t cs;
161 
162  // Additional gpio pins
163 
164  pin_name_t en;
165  pin_name_t rst;
166  pin_name_t mod;
167 
168  // static variable
169 
170  uint32_t spi_speed;
171  uint8_t spi_mode;
172  spi_master_chip_select_polarity_t cs_polarity;
173 
174 } buck7_cfg_t;
175  // End types group
177 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
178 
183 #ifdef __cplusplus
184 extern "C"{
185 #endif
186 
196 
205 
214 
227 (
228  buck7_t *ctx,
229  uint8_t *wr_buf,
230  uint16_t wr_len,
231  uint8_t *rd_buf,
232  uint16_t rd_len
233 );
234 
243 void buck7_set_output_voltage ( buck7_t *ctx, uint16_t voltage );
244 
252 void buck7_enable ( buck7_t *ctx );
253 
262 void buck7_set_mode ( buck7_t *ctx, uint8_t mode );
263 
271 uint8_t buck7_get_res_state ( buck7_t *ctx );
272 
273 
274 #ifdef __cplusplus
275 }
276 #endif
277 #endif // _BUCK7_H_
278  // End public_function group
281 
282 // ------------------------------------------------------------------------- END
buck7_cfg_t::spi_mode
uint8_t spi_mode
Definition: buck7.h:171
buck7_t::spi
spi_master_t spi
Definition: buck7.h:145
buck7_t::rst
digital_out_t rst
Definition: buck7.h:139
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:160
buck7_enable
void buck7_enable(buck7_t *ctx)
Function for enable chip.
buck7_cfg_t::mod
pin_name_t mod
Definition: buck7.h:166
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:146
buck7_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: buck7.h:172
buck7_t::cs
digital_out_t cs
Definition: buck7.h:141
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:157
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:77
buck7_cfg_t::en
pin_name_t en
Definition: buck7.h:164
buck7_cfg_t::rst
pin_name_t rst
Definition: buck7.h:165
buck7_init
BUCK7_RETVAL buck7_init(buck7_t *ctx, buck7_cfg_t *cfg)
Initialization function.
buck7_t
Click ctx object definition.
Definition: buck7.h:135
buck7_t::en
digital_out_t en
Definition: buck7.h:138
buck7_cfg_t::mosi
pin_name_t mosi
Definition: buck7.h:158
buck7_cfg_t::spi_speed
uint32_t spi_speed
Definition: buck7.h:170
buck7_t::mod
digital_out_t mod
Definition: buck7.h:140
buck7_default_cfg
void buck7_default_cfg(buck7_t *ctx)
Click Default Configuration function.
buck7_cfg_t
Click configuration structure definition.
Definition: buck7.h:154
buck7_cfg_t::sck
pin_name_t sck
Definition: buck7.h:159