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 );
78#define BUCK12_RETVAL uint8_t
79
80#define BUCK12_OK 0x00
81#define BUCK12_INIT_ERROR 0xFF
88#define BUCK12_ENABLE 0x01
89#define BUCK12_DISABLE 0x00
96#define BUCK12_INPUT_VOLTAGE 0x02
97#define BUCK12_OUTPUT_VOLTAGE 0x03
104#define BUCK12_CHANNEL_0 0xA0
105#define BUCK12_CHANNEL_1 0xE0
108 // End group macro
109// --------------------------------------------------------------- PUBLIC TYPES
118typedef 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
133typedef 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
153
154 // End types group
155
156// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
157
162#ifdef __cplusplus
163extern "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
222void buck12_control ( buck12_t *ctx, uint8_t ctrl );
223
232uint16_t buck12_get_channel_adc ( buck12_t *ctx, uint8_t channel );
233
242float buck12_get_voltage ( buck12_t *ctx, uint8_t select_volt );
243
244#ifdef __cplusplus
245}
246#endif
247#endif // _BUCK12_H_
248
249 // End public_function group
251
252// ------------------------------------------------------------------------- END
#define BUCK12_RETVAL
Definition buck12.h:78
BUCK12_RETVAL buck12_init(buck12_t *ctx, buck12_cfg_t *cfg)
Initialization function.
void buck12_default_cfg(buck12_t *ctx)
Click Default Configuration function.
float buck12_get_voltage(buck12_t *ctx, uint8_t select_volt)
Function for get Voltage.
void buck12_cfg_setup(buck12_cfg_t *cfg)
Config Object Initialization function.
uint16_t buck12_get_channel_adc(buck12_t *ctx, uint8_t channel)
Function for read ADC on the channel.
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.
void buck12_control(buck12_t *ctx, uint8_t ctrl)
Function for enable or disable device.
Click configuration structure definition.
Definition buck12.h:134
spi_master_chip_select_polarity_t cs_polarity
Definition buck12.h:150
pin_name_t sck
Definition buck12.h:139
spi_master_mode_t spi_mode
Definition buck12.h:149
pin_name_t mosi
Definition buck12.h:138
uint32_t spi_speed
Definition buck12.h:148
pin_name_t en
Definition buck12.h:144
pin_name_t miso
Definition buck12.h:137
pin_name_t cs
Definition buck12.h:140
Click ctx object definition.
Definition buck12.h:119
digital_out_t cs
Definition buck12.h:123
spi_master_t spi
Definition buck12.h:125
digital_out_t en
Definition buck12.h:122
pin_name_t chip_select
Definition buck12.h:126