buck13  2.0.0.0
buck13.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 BUCK13_H
36 #define BUCK13_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 
53 // -------------------------------------------------------------- PUBLIC MACROS
64 #define BUCK13_MAP_MIKROBUS( cfg, mikrobus ) \
65  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
66  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
67  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
68  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
69  cfg.en = MIKROBUS( mikrobus, MIKROBUS_AN );
70 
76 #define BUCK13_RETVAL uint8_t
77 
78 #define BUCK13_OK 0x00
79 #define BUCK13_INIT_ERROR 0xFF
80 
86 #define BUCK13_ENABLE 1
87 #define BUCK13_DISABLE 0
88  // End group macro
90 // --------------------------------------------------------------- PUBLIC TYPES
99 typedef struct
100 {
101  // Output pins
102 
103  digital_out_t en;
104  digital_out_t cs;
105 
106  // Modules
107 
108  spi_master_t spi;
109  pin_name_t chip_select;
110 
111 } buck13_t;
112 
116 typedef struct
117 {
118  // Communication gpio pins
119 
120  pin_name_t miso;
121  pin_name_t mosi;
122  pin_name_t sck;
123  pin_name_t cs;
124 
125  // Additional gpio pins
126 
127  pin_name_t en;
128 
129  // static variable
130 
131  uint32_t spi_speed;
132  spi_master_mode_t spi_mode;
133  spi_master_chip_select_polarity_t cs_polarity;
134 
135 } buck13_cfg_t;
136  // End types group
138 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
139 
144 #ifdef __cplusplus
145 extern "C"{
146 #endif
147 
157 
167 
181 
194 (
195  buck13_t *ctx,
196  uint8_t *wr_buf,
197  uint16_t wr_len,
198  uint8_t *rd_buf,
199  uint16_t rd_len
200 );
201 
210 void buck13_enable ( buck13_t *ctx, uint8_t pwr_state );
211 
220 uint16_t buck13_get_adc( buck13_t *ctx );
221 
230 uint16_t buck13_get_voltage( buck13_t *ctx );
231 
232 #ifdef __cplusplus
233 }
234 #endif
235 #endif // _BUCK13_H_
236  // End public_function group
239 
240 // ------------------------------------------------------------------------- END
buck13_get_adc
uint16_t buck13_get_adc(buck13_t *ctx)
Get ADC function.
buck13_init
BUCK13_RETVAL buck13_init(buck13_t *ctx, buck13_cfg_t *cfg)
Initialization function.
buck13_t
Click ctx object definition.
Definition: buck13.h:100
buck13_t::cs
digital_out_t cs
Definition: buck13.h:104
buck13_t::chip_select
pin_name_t chip_select
Definition: buck13.h:109
buck13_cfg_t::sck
pin_name_t sck
Definition: buck13.h:122
buck13_cfg_t::cs
pin_name_t cs
Definition: buck13.h:123
buck13_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: buck13.h:133
buck13_cfg_t
Click configuration structure definition.
Definition: buck13.h:117
buck13_generic_transfer
void buck13_generic_transfer(buck13_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len)
Generic transfer function.
buck13_cfg_t::spi_speed
uint32_t spi_speed
Definition: buck13.h:131
buck13_cfg_t::en
pin_name_t en
Definition: buck13.h:127
BUCK13_RETVAL
#define BUCK13_RETVAL
Definition: buck13.h:76
buck13_t::spi
spi_master_t spi
Definition: buck13.h:108
buck13_t::en
digital_out_t en
Definition: buck13.h:103
buck13_enable
void buck13_enable(buck13_t *ctx, uint8_t pwr_state)
Enable Buck13 function.
buck13_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: buck13.h:132
buck13_default_cfg
void buck13_default_cfg(buck13_t *ctx)
Click Default Configuration function.
buck13_cfg_setup
void buck13_cfg_setup(buck13_cfg_t *cfg)
Config Object Initialization function.
buck13_get_voltage
uint16_t buck13_get_voltage(buck13_t *ctx)
Get voltage function.
buck13_cfg_t::mosi
pin_name_t mosi
Definition: buck13.h:121
buck13_cfg_t::miso
pin_name_t miso
Definition: buck13.h:120