stepup 2.0.0.0
stepup.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 STEPUP_H
36#define STEPUP_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
57// -------------------------------------------------------------- PUBLIC MACROS
68#define STEPUP_MAP_MIKROBUS( cfg, mikrobus ) \
69 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
70 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
71 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
72 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
73 cfg.mod = MIKROBUS( mikrobus, MIKROBUS_RST ); \
74 cfg.en = MIKROBUS( mikrobus, MIKROBUS_PWM )
81#define STEPUP_RETVAL uint8_t
82
83#define STEPUP_OK 0x00
84#define STEPUP_INIT_ERROR 0xFF
85#define STEPUP_ERROR (-1)
92#define STEPUP_CFG_VREF_BUFFERED 1
93#define STEPUP_CFG_VREF_UNBUFFERED 0
94
95#define STEPUP_CFG_GAIN_1X 1
96#define STEPUP_CFG_GAIN_2X 0
97
98#define STEPUP_CFG_POWER_OUT_ON 1
99#define STEPUP_CFG_POWER_OUT_OFF 0
102 // End group macro
103// --------------------------------------------------------------- PUBLIC TYPES
111typedef struct
112{
113 uint8_t buf;
114 uint8_t ga;
115 uint8_t shdn;
116
118
122typedef struct
123{
124 // Output pins
125
126 digital_out_t mod;
127 digital_out_t en;
128 digital_out_t cs;
129
130 // Modules
131
132 spi_master_t spi;
133 pin_name_t chip_select;
134
136
137} stepup_t;
138
142typedef struct
143{
144 // Communication gpio pins
145
146 pin_name_t miso;
147 pin_name_t mosi;
148 pin_name_t sck;
149 pin_name_t cs;
150
151 // Additional gpio pins
152
153 pin_name_t mod;
154 pin_name_t en;
155
156 // static variable
157
158 uint32_t spi_speed;
159 uint8_t spi_mode;
160 spi_master_chip_select_polarity_t cs_polarity;
161
163
165
166 // End types group
167// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
168
173#ifdef __cplusplus
174extern "C"{
175#endif
176
186
195
205
206
215void stepup_mod_set ( stepup_t *ctx, uint8_t pin_state );
216
225void stepup_en_set ( stepup_t *ctx, uint8_t pin_state );
226
236
248err_t stepup_dac_write ( stepup_t *ctx, uint16_t dac_val );
249
260err_t stepup_set_percentage ( stepup_t *ctx, float percentage );
261
262#ifdef __cplusplus
263}
264#endif
265#endif // _STEPUP_H_
266
267 // End public_function group
269
270// ------------------------------------------------------------------------- END
#define STEPUP_RETVAL
Definition stepup.h:81
void stepup_en_set(stepup_t *ctx, uint8_t pin_state)
En Pin set function.
void stepup_default_cfg(stepup_t *ctx)
Click Default Configuration function.
STEPUP_RETVAL stepup_init(stepup_t *ctx, stepup_cfg_t *cfg)
Initialization function.
err_t stepup_set_percentage(stepup_t *ctx, float percentage)
Set DAC precetage up.
void stepup_mod_set(stepup_t *ctx, uint8_t pin_state)
Mod Pin set function.
void stepup_cfg_setup(stepup_cfg_t *cfg)
Config Object Initialization function.
err_t stepup_dac_write(stepup_t *ctx, uint16_t dac_val)
DAC Write function.
void stepup_dac_setup(stepup_t *ctx, stepup_dac_cfg_t *cfg)
DAC Setup function.
Click configuration structure definition.
Definition stepup.h:143
uint8_t spi_mode
Definition stepup.h:159
spi_master_chip_select_polarity_t cs_polarity
Definition stepup.h:160
pin_name_t sck
Definition stepup.h:148
stepup_dac_cfg_t dac_config
Definition stepup.h:162
pin_name_t mod
Definition stepup.h:153
pin_name_t mosi
Definition stepup.h:147
uint32_t spi_speed
Definition stepup.h:158
pin_name_t en
Definition stepup.h:154
pin_name_t miso
Definition stepup.h:146
pin_name_t cs
Definition stepup.h:149
Click DAC configuration structure definition.
Definition stepup.h:112
uint8_t buf
Definition stepup.h:113
uint8_t shdn
Definition stepup.h:115
uint8_t ga
Definition stepup.h:114
Click ctx object definition.
Definition stepup.h:123
digital_out_t cs
Definition stepup.h:128
digital_out_t mod
Definition stepup.h:126
spi_master_t spi
Definition stepup.h:132
stepup_dac_cfg_t dac_config
Definition stepup.h:135
digital_out_t en
Definition stepup.h:127
pin_name_t chip_select
Definition stepup.h:133