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 )
75 
81 #define STEPUP_RETVAL uint8_t
82 
83 #define STEPUP_OK 0x00
84 #define STEPUP_INIT_ERROR 0xFF
85 #define STEPUP_ERROR (-1)
86 
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
100  // End group macro
103 // --------------------------------------------------------------- PUBLIC TYPES
111 typedef struct
112 {
113  uint8_t buf;
114  uint8_t ga;
115  uint8_t shdn;
116 
118 
122 typedef 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 
142 typedef 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 
164 } stepup_cfg_t;
165  // End types group
167 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
168 
173 #ifdef __cplusplus
174 extern "C"{
175 #endif
176 
186 
195 
205 
206 
215 void stepup_mod_set ( stepup_t *ctx, uint8_t pin_state );
216 
225 void stepup_en_set ( stepup_t *ctx, uint8_t pin_state );
226 
236 
248 err_t stepup_dac_write ( stepup_t *ctx, uint16_t dac_val );
249 
260 err_t stepup_set_percentage ( stepup_t *ctx, float percentage );
261 
262 #ifdef __cplusplus
263 }
264 #endif
265 #endif // _STEPUP_H_
266  // End public_function group
269 
270 // ------------------------------------------------------------------------- END
stepup_t::dac_config
stepup_dac_cfg_t dac_config
Definition: stepup.h:135
stepup_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: stepup.h:160
STEPUP_RETVAL
#define STEPUP_RETVAL
Definition: stepup.h:81
stepup_dac_write
err_t stepup_dac_write(stepup_t *ctx, uint16_t dac_val)
DAC Write function.
stepup_dac_setup
void stepup_dac_setup(stepup_t *ctx, stepup_dac_cfg_t *cfg)
DAC Setup function.
stepup_mod_set
void stepup_mod_set(stepup_t *ctx, uint8_t pin_state)
Mod Pin set function.
stepup_t::en
digital_out_t en
Definition: stepup.h:127
stepup_cfg_t::mod
pin_name_t mod
Definition: stepup.h:153
stepup_cfg_t::mosi
pin_name_t mosi
Definition: stepup.h:147
stepup_dac_cfg_t
Click DAC configuration structure definition.
Definition: stepup.h:112
stepup_cfg_t::dac_config
stepup_dac_cfg_t dac_config
Definition: stepup.h:162
stepup_t::chip_select
pin_name_t chip_select
Definition: stepup.h:133
stepup_cfg_t::miso
pin_name_t miso
Definition: stepup.h:146
stepup_t
Click ctx object definition.
Definition: stepup.h:123
stepup_t::mod
digital_out_t mod
Definition: stepup.h:126
stepup_dac_cfg_t::shdn
uint8_t shdn
Definition: stepup.h:115
stepup_cfg_t::cs
pin_name_t cs
Definition: stepup.h:149
stepup_t::cs
digital_out_t cs
Definition: stepup.h:128
stepup_cfg_t::spi_speed
uint32_t spi_speed
Definition: stepup.h:158
stepup_cfg_t::spi_mode
uint8_t spi_mode
Definition: stepup.h:159
stepup_cfg_t::sck
pin_name_t sck
Definition: stepup.h:148
stepup_dac_cfg_t::ga
uint8_t ga
Definition: stepup.h:114
stepup_dac_cfg_t::buf
uint8_t buf
Definition: stepup.h:113
stepup_set_percentage
err_t stepup_set_percentage(stepup_t *ctx, float percentage)
Set DAC precetage up.
stepup_cfg_t::en
pin_name_t en
Definition: stepup.h:154
stepup_cfg_setup
void stepup_cfg_setup(stepup_cfg_t *cfg)
Config Object Initialization function.
stepup_en_set
void stepup_en_set(stepup_t *ctx, uint8_t pin_state)
En Pin set function.
stepup_init
STEPUP_RETVAL stepup_init(stepup_t *ctx, stepup_cfg_t *cfg)
Initialization function.
stepup_default_cfg
void stepup_default_cfg(stepup_t *ctx)
Click Default Configuration function.
stepup_cfg_t
Click configuration structure definition.
Definition: stepup.h:143
stepup_t::spi
spi_master_t spi
Definition: stepup.h:132