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 
38 #include "drv_digital_out.h"
39 #include "drv_spi_master.h"
40 
41 // -------------------------------------------------------------- PUBLIC MACROS
52 #define BUCK12_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
54  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
55  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
56  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
57  cfg.en = MIKROBUS( mikrobus, MIKROBUS_RST );
58 
64 #define BUCK12_RETVAL uint8_t
65 
66 #define BUCK12_OK 0x00
67 #define BUCK12_INIT_ERROR 0xFF
68 
74 #define BUCK12_ENABLE 0x01
75 #define BUCK12_DISABLE 0x00
76 
82 #define BUCK12_INPUT_VOLTAGE 0x02
83 #define BUCK12_OUTPUT_VOLTAGE 0x03
84 
90 #define BUCK12_CHANNEL_0 0xA0
91 #define BUCK12_CHANNEL_1 0xE0
92  // End group macro
95 // --------------------------------------------------------------- PUBLIC TYPES
104 typedef struct
105 {
106  // Output pins
107 
108  digital_out_t en;
109  digital_out_t cs;
110 
111  spi_master_t spi;
112  pin_name_t chip_select;
113 
114 } buck12_t;
115 
119 typedef struct
120 {
121  // Communication gpio pins
122 
123  pin_name_t miso;
124  pin_name_t mosi;
125  pin_name_t sck;
126  pin_name_t cs;
127 
128  // Additional gpio pins
129 
130  pin_name_t en;
131 
132  // static variable
133 
134  uint32_t spi_speed;
135  spi_master_mode_t spi_mode;
136  spi_master_chip_select_polarity_t cs_polarity;
137 
138 } buck12_cfg_t;
139  // End types group
141 
142 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
143 
148 #ifdef __cplusplus
149 extern "C"{
150 #endif
151 
160 void buck12_cfg_setup ( buck12_cfg_t *cfg );
161 
170 
178 void buck12_default_cfg ( buck12_t *ctx );
179 
192 (
193  buck12_t *ctx,
194  uint8_t *wr_buf,
195  uint16_t wr_len,
196  uint8_t *rd_buf,
197  uint16_t rd_len
198 );
199 
208 void buck12_control ( buck12_t *ctx, uint8_t ctrl );
209 
218 uint16_t buck12_get_channel_adc ( buck12_t *ctx, uint8_t channel );
219 
228 float buck12_get_voltage ( buck12_t *ctx, uint8_t select_volt );
229 
230 #ifdef __cplusplus
231 }
232 #endif
233 #endif // _BUCK12_H_
234  // End public_function group
237 
238 // ------------------------------------------------------------------------- END
buck12_t::cs
digital_out_t cs
Definition: buck12.h:109
buck12_cfg_t::en
pin_name_t en
Definition: buck12.h:130
buck12_t::chip_select
pin_name_t chip_select
Definition: buck12.h:112
buck12_cfg_t
Click configuration structure definition.
Definition: buck12.h:119
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:104
buck12_t::spi
spi_master_t spi
Definition: buck12.h:111
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:134
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:108
buck12_cfg_t::cs
pin_name_t cs
Definition: buck12.h:126
buck12_cfg_t::mosi
pin_name_t mosi
Definition: buck12.h:124
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:123
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:136
buck12_cfg_t::sck
pin_name_t sck
Definition: buck12.h:125
BUCK12_RETVAL
#define BUCK12_RETVAL
Definition: buck12.h:64
buck12_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: buck12.h:135