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 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_spi_master.h"
41 
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
54 #define STEPUP_MAP_MIKROBUS( cfg, mikrobus ) \
55  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
56  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
57  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
58  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
59  cfg.mod = MIKROBUS( mikrobus, MIKROBUS_RST ); \
60  cfg.en = MIKROBUS( mikrobus, MIKROBUS_PWM )
61 
67 #define STEPUP_RETVAL uint8_t
68 
69 #define STEPUP_OK 0x00
70 #define STEPUP_INIT_ERROR 0xFF
71 #define STEPUP_ERROR (-1)
72 
78 #define STEPUP_CFG_VREF_BUFFERED 1
79 #define STEPUP_CFG_VREF_UNBUFFERED 0
80 
81 #define STEPUP_CFG_GAIN_1X 1
82 #define STEPUP_CFG_GAIN_2X 0
83 
84 #define STEPUP_CFG_POWER_OUT_ON 1
85 #define STEPUP_CFG_POWER_OUT_OFF 0
86  // End group macro
89 // --------------------------------------------------------------- PUBLIC TYPES
97 typedef struct
98 {
99  uint8_t buf;
100  uint8_t ga;
101  uint8_t shdn;
102 
104 
108 typedef struct
109 {
110  // Output pins
111 
112  digital_out_t mod;
113  digital_out_t en;
114  digital_out_t cs;
115 
116  // Modules
117 
118  spi_master_t spi;
119  pin_name_t chip_select;
120 
122 
123 } stepup_t;
124 
128 typedef struct
129 {
130  // Communication gpio pins
131 
132  pin_name_t miso;
133  pin_name_t mosi;
134  pin_name_t sck;
135  pin_name_t cs;
136 
137  // Additional gpio pins
138 
139  pin_name_t mod;
140  pin_name_t en;
141 
142  // static variable
143 
144  uint32_t spi_speed;
145  uint8_t spi_mode;
146  spi_master_chip_select_polarity_t cs_polarity;
147 
149 
150 } stepup_cfg_t;
151  // End types group
153 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
154 
159 #ifdef __cplusplus
160 extern "C"{
161 #endif
162 
172 
181 
191 
192 
201 void stepup_mod_set ( stepup_t *ctx, uint8_t pin_state );
202 
211 void stepup_en_set ( stepup_t *ctx, uint8_t pin_state );
212 
222 
234 err_t stepup_dac_write ( stepup_t *ctx, uint16_t dac_val );
235 
246 err_t stepup_set_percentage ( stepup_t *ctx, float percentage );
247 
248 #ifdef __cplusplus
249 }
250 #endif
251 #endif // _STEPUP_H_
252  // End public_function group
255 
256 // ------------------------------------------------------------------------- END
stepup_t::dac_config
stepup_dac_cfg_t dac_config
Definition: stepup.h:121
stepup_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: stepup.h:146
STEPUP_RETVAL
#define STEPUP_RETVAL
Definition: stepup.h:67
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:113
stepup_cfg_t::mod
pin_name_t mod
Definition: stepup.h:139
stepup_cfg_t::mosi
pin_name_t mosi
Definition: stepup.h:133
stepup_dac_cfg_t
Click DAC configuration structure definition.
Definition: stepup.h:98
stepup_cfg_t::dac_config
stepup_dac_cfg_t dac_config
Definition: stepup.h:148
stepup_t::chip_select
pin_name_t chip_select
Definition: stepup.h:119
stepup_cfg_t::miso
pin_name_t miso
Definition: stepup.h:132
stepup_t
Click ctx object definition.
Definition: stepup.h:109
stepup_t::mod
digital_out_t mod
Definition: stepup.h:112
stepup_dac_cfg_t::shdn
uint8_t shdn
Definition: stepup.h:101
stepup_cfg_t::cs
pin_name_t cs
Definition: stepup.h:135
stepup_t::cs
digital_out_t cs
Definition: stepup.h:114
stepup_cfg_t::spi_speed
uint32_t spi_speed
Definition: stepup.h:144
stepup_cfg_t::spi_mode
uint8_t spi_mode
Definition: stepup.h:145
stepup_cfg_t::sck
pin_name_t sck
Definition: stepup.h:134
stepup_dac_cfg_t::ga
uint8_t ga
Definition: stepup.h:100
stepup_dac_cfg_t::buf
uint8_t buf
Definition: stepup.h:99
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:140
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:129
stepup_t::spi
spi_master_t spi
Definition: stepup.h:118