buck12  2.0.0.0
buck12.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 BUCK12_H
36 #define BUCK12_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_spi_master.h"
54 
55 // -------------------------------------------------------------- PUBLIC MACROS
66 #define BUCK12_MAP_MIKROBUS( cfg, mikrobus ) \
67  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
68  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
69  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
70  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
71  cfg.en = MIKROBUS( mikrobus, MIKROBUS_RST );
72 
78 #define BUCK12_RETVAL uint8_t
79 
80 #define BUCK12_OK 0x00
81 #define BUCK12_INIT_ERROR 0xFF
82 
88 #define BUCK12_ENABLE 0x01
89 #define BUCK12_DISABLE 0x00
90 
96 #define BUCK12_INPUT_VOLTAGE 0x02
97 #define BUCK12_OUTPUT_VOLTAGE 0x03
98 
104 #define BUCK12_CHANNEL_0 0xA0
105 #define BUCK12_CHANNEL_1 0xE0
106  // End group macro
109 // --------------------------------------------------------------- PUBLIC TYPES
118 typedef struct
119 {
120  // Output pins
121 
122  digital_out_t en;
123  digital_out_t cs;
124 
125  spi_master_t spi;
126  pin_name_t chip_select;
127 
128 } buck12_t;
129 
133 typedef struct
134 {
135  // Communication gpio pins
136 
137  pin_name_t miso;
138  pin_name_t mosi;
139  pin_name_t sck;
140  pin_name_t cs;
141 
142  // Additional gpio pins
143 
144  pin_name_t en;
145 
146  // static variable
147 
148  uint32_t spi_speed;
149  spi_master_mode_t spi_mode;
150  spi_master_chip_select_polarity_t cs_polarity;
151 
152 } buck12_cfg_t;
153  // End types group
155 
156 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
157 
162 #ifdef __cplusplus
163 extern "C"{
164 #endif
165 
175 
184 
193 
206 (
207  buck12_t *ctx,
208  uint8_t *wr_buf,
209  uint16_t wr_len,
210  uint8_t *rd_buf,
211  uint16_t rd_len
212 );
213 
222 void buck12_control ( buck12_t *ctx, uint8_t ctrl );
223 
232 uint16_t buck12_get_channel_adc ( buck12_t *ctx, uint8_t channel );
233 
242 float buck12_get_voltage ( buck12_t *ctx, uint8_t select_volt );
243 
244 #ifdef __cplusplus
245 }
246 #endif
247 #endif // _BUCK12_H_
248  // End public_function group
251 
252 // ------------------------------------------------------------------------- END
buck12_t::cs
digital_out_t cs
Definition: buck12.h:123
buck12_cfg_t::en
pin_name_t en
Definition: buck12.h:144
buck12_t::chip_select
pin_name_t chip_select
Definition: buck12.h:126
buck12_cfg_t
Click configuration structure definition.
Definition: buck12.h:134
buck12_get_voltage
float buck12_get_voltage(buck12_t *ctx, uint8_t select_volt)
Function for get Voltage.
buck12_t
Click ctx object definition.
Definition: buck12.h:119
buck12_t::spi
spi_master_t spi
Definition: buck12.h:125
buck12_default_cfg
void buck12_default_cfg(buck12_t *ctx)
Click Default Configuration function.
buck12_init
BUCK12_RETVAL buck12_init(buck12_t *ctx, buck12_cfg_t *cfg)
Initialization function.
buck12_cfg_setup
void buck12_cfg_setup(buck12_cfg_t *cfg)
Config Object Initialization function.
buck12_cfg_t::spi_speed
uint32_t spi_speed
Definition: buck12.h:148
buck12_generic_transfer
void buck12_generic_transfer(buck12_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len)
Generic transfer function.
buck12_t::en
digital_out_t en
Definition: buck12.h:122
buck12_cfg_t::cs
pin_name_t cs
Definition: buck12.h:140
buck12_cfg_t::mosi
pin_name_t mosi
Definition: buck12.h:138
buck12_control
void buck12_control(buck12_t *ctx, uint8_t ctrl)
Function for enable or disable device.
buck12_cfg_t::miso
pin_name_t miso
Definition: buck12.h:137
buck12_get_channel_adc
uint16_t buck12_get_channel_adc(buck12_t *ctx, uint8_t channel)
Function for read ADC on the channel.
buck12_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: buck12.h:150
buck12_cfg_t::sck
pin_name_t sck
Definition: buck12.h:139
BUCK12_RETVAL
#define BUCK12_RETVAL
Definition: buck12.h:78
buck12_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: buck12.h:149