boost  2.0.0.0
boost.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 BOOST_H
36 #define BOOST_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_digital_in.h"
54 #include "drv_spi_master.h"
55 
56 // -------------------------------------------------------------- PUBLIC MACROS
66 #define BOOST_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.cs1 = MIKROBUS( mikrobus, MIKROBUS_CS ); \
71  cfg.cs2 = MIKROBUS( mikrobus, MIKROBUS_AN ); \
72  cfg.en = MIKROBUS( mikrobus, MIKROBUS_RST )
73 
79 #define BOOST_OK 0
80 #define BOOST_ERROR (-1)
81 
87 #define BOOST_CFG_VREF_BUFFERED 1
88 #define BOOST_CFG_VREF_UNBUFFERED 0
89 
90 #define BOOST_CFG_GAIN_1X 1
91 #define BOOST_CFG_GAIN_2X 0
92 
93 #define BOOST_CFG_POWER_OUT_ON 1
94 #define BOOST_CFG_POWER_OUT_OFF 0
95  // End group macro
98 // --------------------------------------------------------------- PUBLIC TYPES
107 typedef struct
108 {
109  uint8_t buf;
110  uint8_t ga;
111  uint8_t shdn;
112 
114 
118 typedef struct
119 {
120  // Output pins
121 
122  digital_out_t cs1;
123  digital_out_t cs2;
124  digital_out_t en;
125 
126  digital_in_t miso;
127 
128  // Modules
129 
130  spi_master_t spi;
131  pin_name_t chip_select1;
132  pin_name_t chip_select2;
133  spi_master_chip_select_polarity_t cs1_polarity;
134  spi_master_chip_select_polarity_t cs2_polarity;
135 
137 
138 } boost_t;
139 
143 typedef struct
144 {
145  // Communication gpio pins
146 
147  pin_name_t miso;
148  pin_name_t mosi;
149  pin_name_t sck;
150  pin_name_t cs1;
151  pin_name_t cs2;
152 
153  // Additional gpio pins
154 
155  pin_name_t en;
156 
157  // Static variable
158 
159  uint32_t spi_speed;
160  spi_master_mode_t spi_mode;
161  spi_master_chip_select_polarity_t cs1_polarity;
162  spi_master_chip_select_polarity_t cs2_polarity;
163 
165 
166 } boost_cfg_t;
167  // End types group
169 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
175 #ifdef __cplusplus
176 extern "C"{
177 #endif
178 
188 
199 err_t boost_init ( boost_t *ctx, boost_cfg_t *cfg );
200 
209 
218 
228 
240 err_t boost_dac_write ( boost_t *ctx, uint16_t dac_val );
241 
250 float boost_vout_read ( boost_t *ctx );
251 
252 #ifdef __cplusplus
253 }
254 #endif
255 #endif // BOOST_H
256  // End public_function group // End Click Driver group
259 
260 // ------------------------------------------------------------------------ END
boost_dac_cfg_t::buf
uint8_t buf
Definition: boost.h:109
boost_vout_read
float boost_vout_read(boost_t *ctx)
VOUT Read function.
boost_cfg_t::cs1_polarity
spi_master_chip_select_polarity_t cs1_polarity
Definition: boost.h:161
boost_cfg_t::dac
boost_dac_cfg_t dac
Definition: boost.h:164
boost_t::miso
digital_in_t miso
Definition: boost.h:126
boost_device_enable
void boost_device_enable(boost_t *ctx)
Device Enable function.
boost_t::cs1_polarity
spi_master_chip_select_polarity_t cs1_polarity
Definition: boost.h:133
boost_t::chip_select2
pin_name_t chip_select2
Definition: boost.h:132
boost_t::cs1
digital_out_t cs1
Definition: boost.h:122
boost_dac_cfg_t::ga
uint8_t ga
Definition: boost.h:110
boost_t::spi
spi_master_t spi
Definition: boost.h:130
boost_cfg_t::spi_speed
uint32_t spi_speed
Definition: boost.h:159
boost_t::en
digital_out_t en
Definition: boost.h:124
boost_t::chip_select1
pin_name_t chip_select1
Definition: boost.h:131
boost_cfg_t::miso
pin_name_t miso
Definition: boost.h:147
boost_t::dac
boost_dac_cfg_t dac
Definition: boost.h:136
boost_init
err_t boost_init(boost_t *ctx, boost_cfg_t *cfg)
Initialization function.
boost_dac_cfg_t
Click DAC configuration structure definition.
Definition: boost.h:108
boost_cfg_t::en
pin_name_t en
Definition: boost.h:155
boost_t::cs2
digital_out_t cs2
Definition: boost.h:123
boost_cfg_t::cs2_polarity
spi_master_chip_select_polarity_t cs2_polarity
Definition: boost.h:162
boost_device_disable
void boost_device_disable(boost_t *ctx)
Device Disable function.
boost_cfg_t::sck
pin_name_t sck
Definition: boost.h:149
boost_cfg_t::cs2
pin_name_t cs2
Definition: boost.h:151
boost_cfg_t
Click configuration structure definition.
Definition: boost.h:144
boost_t
Click ctx object definition.
Definition: boost.h:119
boost_cfg_setup
void boost_cfg_setup(boost_cfg_t *cfg)
Config Object Initialization function.
boost_dac_cfg_t::shdn
uint8_t shdn
Definition: boost.h:111
boost_cfg_t::cs1
pin_name_t cs1
Definition: boost.h:150
boost_dac_write
err_t boost_dac_write(boost_t *ctx, uint16_t dac_val)
DAC Write function.
boost_cfg_t::mosi
pin_name_t mosi
Definition: boost.h:148
boost_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: boost.h:160
boost_t::cs2_polarity
spi_master_chip_select_polarity_t cs2_polarity
Definition: boost.h:134
boost_dac_setup
void boost_dac_setup(boost_t *ctx, boost_dac_cfg_t *cfg)
DAC Setup function.