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 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_spi_master.h"
38 #include "spi_specifics.h"
39 
60 #define BUCK16_CMD_VOLATILE_WIPER_0 0x00
61 #define BUCK16_CMD_NV_WIPER_0 0x20
62 #define BUCK16_CMD_VOLATILE_TCON 0x40
63 #define BUCK16_CMD_DATA_EEPROM_1 0x60
64 #define BUCK16_CMD_DATA_EEPROM_2 0x70
65 #define BUCK16_CMD_DATA_EEPROM_3 0x80
66 #define BUCK16_CMD_DATA_EEPROM_4 0x90
67 #define BUCK16_CMD_DATA_EEPROM_5 0xA0
68 #define BUCK16_CMD_DATA_EEPROM_6 0xB0
69 #define BUCK16_CMD_DATA_EEPROM_7 0xC0
70 #define BUCK16_CMD_DATA_EEPROM_8 0xD0
71 #define BUCK16_CMD_DATA_EEPROM_9 0xE0
72 #define BUCK16_CMD_DATA_EEPROM_10 0xF0
73 
78 #define BUCK16_WRITE 0x00
79 #define BUCK16_INCREMENT 0x04
80 #define BUCK16_DECREMENT 0x08
81  // buck16_reg
83 
102 #define BUCK16_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
103 #define BUCK16_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
104  // buck16_set
106 
121 #define BUCK16_MAP_MIKROBUS( cfg, mikrobus ) \
122  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
123  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
124  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
125  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
126  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST );
127  // buck16_map // buck16
130 
135 typedef struct
136 {
137  // Output pins
138  digital_out_t rst;
140  // Modules
141  spi_master_t spi;
142  pin_name_t chip_select;
144 } buck16_t;
145 
150 typedef struct
151 {
152  // Communication gpio pins
153  pin_name_t miso;
154  pin_name_t mosi;
155  pin_name_t sck;
156  pin_name_t cs;
158  // Additional gpio pins
159  pin_name_t rst;
161  // static variable
162  uint32_t spi_speed;
163  spi_master_mode_t spi_mode;
164  spi_master_chip_select_polarity_t cs_polarity;
166 } buck16_cfg_t;
167 
172 typedef enum
173 {
176 
178 
194 void buck16_cfg_setup ( buck16_cfg_t *cfg );
195 
209 err_t buck16_init ( buck16_t *ctx, buck16_cfg_t *cfg );
210 
224 err_t buck16_generic_write ( buck16_t *ctx, uint8_t cmd, uint8_t cmd_bits, uint16_t tx_data );
225 
234 void buck16_enable_output ( buck16_t *ctx, uint8_t enable );
235 
247 err_t buck16_set_potentiometer ( buck16_t *ctx, uint16_t rwb );
248 
262 err_t buck16_set_output ( buck16_t *ctx, uint16_t vout );
263 
264 
265 #ifdef __cplusplus
266 }
267 #endif
268 #endif // BUCK16_H
269  // buck16
271 
272 // ------------------------------------------------------------------------ END
buck16_t
Buck 16 Click context object.
Definition: buck16.h:135
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:164
buck16_cfg_t
Buck 16 Click configuration object.
Definition: buck16.h:150
buck16_t::rst
digital_out_t rst
Definition: buck16.h:138
BUCK16_OK
Definition: buck16.h:174
buck16_cfg_t::cs
pin_name_t cs
Definition: buck16.h:156
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:163
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:142
buck16_cfg_t::sck
pin_name_t sck
Definition: buck16.h:155
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:153
buck16_return_value_t
buck16_return_value_t
Buck 16 Click return value data.
Definition: buck16.h:172
buck16_cfg_t::rst
pin_name_t rst
Definition: buck16.h:159
buck16_cfg_t::spi_speed
uint32_t spi_speed
Definition: buck16.h:162
BUCK16_ERROR
Definition: buck16.h:175
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:141
buck16_cfg_t::mosi
pin_name_t mosi
Definition: buck16.h:154