buck16  2.0.0.0
buck16.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2020 MikroElektronika d.o.o.
3 ** Contact: https://www.mikroe.com/contact
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 ** of this software and associated documentation files (the "Software"), to deal
7 ** in the Software without restriction, including without limitation the rights
8 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 ** copies of the Software, and to permit persons to whom the Software is
10 ** furnished to do so, subject to the following conditions:
11 ** The above copyright notice and this permission notice shall be
12 ** included in all copies or substantial portions of the Software.
13 **
14 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 ** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 ** USE OR OTHER DEALINGS IN THE SOFTWARE.
21 ****************************************************************************/
22 
28 #ifndef BUCK16_H
29 #define BUCK16_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
39 #ifdef PREINIT_SUPPORTED
40 #include "preinit.h"
41 #endif
42 
43 #ifdef MikroCCoreVersion
44  #if MikroCCoreVersion >= 1
45  #include "delays.h"
46  #endif
47 #endif
48 
49 #include "drv_digital_out.h"
50 #include "drv_digital_in.h"
51 #include "drv_spi_master.h"
52 #include "spi_specifics.h"
53 
74 #define BUCK16_CMD_VOLATILE_WIPER_0 0x00
75 #define BUCK16_CMD_NV_WIPER_0 0x20
76 #define BUCK16_CMD_VOLATILE_TCON 0x40
77 #define BUCK16_CMD_DATA_EEPROM_1 0x60
78 #define BUCK16_CMD_DATA_EEPROM_2 0x70
79 #define BUCK16_CMD_DATA_EEPROM_3 0x80
80 #define BUCK16_CMD_DATA_EEPROM_4 0x90
81 #define BUCK16_CMD_DATA_EEPROM_5 0xA0
82 #define BUCK16_CMD_DATA_EEPROM_6 0xB0
83 #define BUCK16_CMD_DATA_EEPROM_7 0xC0
84 #define BUCK16_CMD_DATA_EEPROM_8 0xD0
85 #define BUCK16_CMD_DATA_EEPROM_9 0xE0
86 #define BUCK16_CMD_DATA_EEPROM_10 0xF0
87 
92 #define BUCK16_WRITE 0x00
93 #define BUCK16_INCREMENT 0x04
94 #define BUCK16_DECREMENT 0x08
95  // buck16_reg
97 
116 #define BUCK16_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
117 #define BUCK16_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
118  // buck16_set
120 
135 #define BUCK16_MAP_MIKROBUS( cfg, mikrobus ) \
136  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
137  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
138  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
139  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
140  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST );
141  // buck16_map // buck16
144 
149 typedef struct
150 {
151  // Output pins
152  digital_out_t rst;
154  // Modules
155  spi_master_t spi;
156  pin_name_t chip_select;
158 } buck16_t;
159 
164 typedef struct
165 {
166  // Communication gpio pins
167  pin_name_t miso;
168  pin_name_t mosi;
169  pin_name_t sck;
170  pin_name_t cs;
172  // Additional gpio pins
173  pin_name_t rst;
175  // static variable
176  uint32_t spi_speed;
177  spi_master_mode_t spi_mode;
178  spi_master_chip_select_polarity_t cs_polarity;
180 } buck16_cfg_t;
181 
186 typedef enum
187 {
189  BUCK16_ERROR = -1
190 
192 
209 
223 err_t buck16_init ( buck16_t *ctx, buck16_cfg_t *cfg );
224 
238 err_t buck16_generic_write ( buck16_t *ctx, uint8_t cmd, uint8_t cmd_bits, uint16_t tx_data );
239 
248 void buck16_enable_output ( buck16_t *ctx, uint8_t enable );
249 
261 err_t buck16_set_potentiometer ( buck16_t *ctx, uint16_t rwb );
262 
276 err_t buck16_set_output ( buck16_t *ctx, uint16_t vout );
277 
278 
279 #ifdef __cplusplus
280 }
281 #endif
282 #endif // BUCK16_H
283  // buck16
285 
286 // ------------------------------------------------------------------------ END
buck16_t
Buck 16 Click context object.
Definition: buck16.h:150
buck16_enable_output
void buck16_enable_output(buck16_t *ctx, uint8_t enable)
Enable/Disable voltage output.
spi_specifics.h
This file contains SPI specific macros, functions, etc.
buck16_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: buck16.h:178
buck16_cfg_t
Buck 16 Click configuration object.
Definition: buck16.h:165
buck16_t::rst
digital_out_t rst
Definition: buck16.h:152
BUCK16_OK
@ BUCK16_OK
Definition: buck16.h:188
buck16_cfg_t::cs
pin_name_t cs
Definition: buck16.h:170
buck16_set_output
err_t buck16_set_output(buck16_t *ctx, uint16_t vout)
Set output voltage.
buck16_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: buck16.h:177
buck16_generic_write
err_t buck16_generic_write(buck16_t *ctx, uint8_t cmd, uint8_t cmd_bits, uint16_t tx_data)
Data writing function.
buck16_t::chip_select
pin_name_t chip_select
Definition: buck16.h:156
buck16_cfg_t::sck
pin_name_t sck
Definition: buck16.h:169
buck16_init
err_t buck16_init(buck16_t *ctx, buck16_cfg_t *cfg)
Buck 16 initialization function.
buck16_cfg_setup
void buck16_cfg_setup(buck16_cfg_t *cfg)
Buck 16 configuration object setup function.
buck16_cfg_t::miso
pin_name_t miso
Definition: buck16.h:167
buck16_return_value_t
buck16_return_value_t
Buck 16 Click return value data.
Definition: buck16.h:187
buck16_cfg_t::rst
pin_name_t rst
Definition: buck16.h:173
buck16_cfg_t::spi_speed
uint32_t spi_speed
Definition: buck16.h:176
BUCK16_ERROR
@ BUCK16_ERROR
Definition: buck16.h:189
buck16_set_potentiometer
err_t buck16_set_potentiometer(buck16_t *ctx, uint16_t rwb)
Set potentiometer resistivity.
buck16_t::spi
spi_master_t spi
Definition: buck16.h:155
buck16_cfg_t::mosi
pin_name_t mosi
Definition: buck16.h:168