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 
77 #define STEPUP_DACB 0x8000
78 #define STEPUP_DACA 0x0000
79 #define STEPUP_BUFFERED 0x4000
80 #define STEPUP_UNBUFFERED 0x0000
81 #define STEPUP_GAIN_1X 0x2000
82 #define STEPUP_GAIN_2X 0x0000
83 #define STEPUP_POWER_UP 0x1000
84 #define STEPUP_POWER_DOWN 0x0000
85  // End group macro
88 // --------------------------------------------------------------- PUBLIC TYPES
97 typedef struct
98 {
99  // Output pins
100 
101  digital_out_t mod;
102  digital_out_t en;
103  digital_out_t cs;
104 
105  // Modules
106 
107  spi_master_t spi;
108  pin_name_t chip_select;
109 
110  uint16_t config_word;
111 
112 } stepup_t;
113 
117 typedef struct
118 {
119  // Communication gpio pins
120 
121  pin_name_t miso;
122  pin_name_t mosi;
123  pin_name_t sck;
124  pin_name_t cs;
125 
126  // Additional gpio pins
127 
128  pin_name_t mod;
129  pin_name_t en;
130 
131  // static variable
132 
133  uint32_t spi_speed;
134  uint8_t spi_mode;
135  spi_master_chip_select_polarity_t cs_polarity;
136 
137  uint16_t config_word_cfg;
138 
139 } stepup_cfg_t;
140  // End types group
142 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
143 
148 #ifdef __cplusplus
149 extern "C"{
150 #endif
151 
160 void stepup_cfg_setup ( stepup_cfg_t *cfg );
161 
170 
179 void stepup_default_cfg ( stepup_t *ctx, uint16_t out_value );
180 
193 (
194  stepup_t *ctx,
195  uint8_t *wr_buf,
196  uint16_t wr_len,
197  uint8_t *rd_buf,
198  uint16_t rd_len
199 );
200 
209 void stepup_mod_set ( stepup_t *ctx, uint8_t pin_state );
210 
219 void stepup_en_set ( stepup_t *ctx, uint8_t pin_state );
220 
232 uint8_t stepup_set_config ( stepup_t *ctx, uint16_t config );
233 
247 uint8_t stepup_set_out ( stepup_t *ctx, uint16_t out_value );
248 
259 float stepup_get_percent ( uint16_t out_value );
260 
261 #ifdef __cplusplus
262 }
263 #endif
264 #endif // _STEPUP_H_
265  // End public_function group
268 
269 // ------------------------------------------------------------------------- END
digital_out_t en
Definition: stepup.h:102
float stepup_get_percent(uint16_t out_value)
Calculate ouput value in percent.
pin_name_t miso
Definition: stepup.h:121
uint8_t stepup_set_config(stepup_t *ctx, uint16_t config)
En Pin set function.
void stepup_generic_transfer(stepup_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len)
Generic transfer function.
pin_name_t cs
Definition: stepup.h:124
uint8_t stepup_set_out(stepup_t *ctx, uint16_t out_value)
Setting output value.
pin_name_t sck
Definition: stepup.h:123
void stepup_mod_set(stepup_t *ctx, uint8_t pin_state)
Mod Pin set function.
uint16_t config_word
Definition: stepup.h:110
void stepup_default_cfg(stepup_t *ctx, uint16_t out_value)
Click Default Configuration function.
pin_name_t en
Definition: stepup.h:129
pin_name_t chip_select
Definition: stepup.h:108
pin_name_t mod
Definition: stepup.h:128
uint16_t config_word_cfg
Definition: stepup.h:137
#define STEPUP_RETVAL
Definition: stepup.h:67
void stepup_en_set(stepup_t *ctx, uint8_t pin_state)
En Pin set function.
pin_name_t mosi
Definition: stepup.h:122
digital_out_t cs
Definition: stepup.h:103
Click ctx object definition.
Definition: stepup.h:97
uint8_t spi_mode
Definition: stepup.h:134
Click configuration structure definition.
Definition: stepup.h:117
uint32_t spi_speed
Definition: stepup.h:133
digital_out_t mod
Definition: stepup.h:101
uint16_t out_value
Definition: main.c:35
spi_master_chip_select_polarity_t cs_polarity
Definition: stepup.h:135
STEPUP_RETVAL stepup_init(stepup_t *ctx, stepup_cfg_t *cfg)
Initialization function.
spi_master_t spi
Definition: stepup.h:107
void stepup_cfg_setup(stepup_cfg_t *cfg)
Config Object Initialization function.