stepdown9  2.1.0.0
stepdown9.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 STEPDOWN9_H
29 #define STEPDOWN9_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
39 #ifdef PREINIT_SUPPORTED
40 #include "preinit.h"
41 #endif
42 
43 #ifdef MikroCCoreVersion
44  #if MikroCCoreVersion >= 1
45  #include "delays.h"
46  #endif
47 #endif
48 
49 #include "drv_digital_out.h"
50 #include "drv_digital_in.h"
51 #include "drv_spi_master.h"
52 #include "spi_specifics.h"
53 
74 #define STEPDOWN9_VOUT_10V_RESISTANCE 8700
75 #define STEPDOWN9_VOUT_9V5_RESISTANCE 11500
76 #define STEPDOWN9_VOUT_9V_RESISTANCE 11700
77 #define STEPDOWN9_VOUT_8V5_RESISTANCE 12500
78 #define STEPDOWN9_VOUT_8V_RESISTANCE 13000
79 #define STEPDOWN9_VOUT_7V5_RESISTANCE 13700
80 #define STEPDOWN9_VOUT_7V_RESISTANCE 14700
81 #define STEPDOWN9_VOUT_6V5_RESISTANCE 15800
82 #define STEPDOWN9_VOUT_6V_RESISTANCE 17000
83 #define STEPDOWN9_VOUT_5V5_RESISTANCE 19000
84 #define STEPDOWN9_VOUT_5V_RESISTANCE 21000
85 #define STEPDOWN9_VOUT_4V5_RESISTANCE 23500
86 #define STEPDOWN9_VOUT_4V_RESISTANCE 27000
87 #define STEPDOWN9_VOUT_3V5_RESISTANCE 32000
88 #define STEPDOWN9_VOUT_3V3_RESISTANCE 34000
89 #define STEPDOWN9_VOUT_3V_RESISTANCE 38000
90 #define STEPDOWN9_VOUT_2V5_RESISTANCE 50000
91 #define STEPDOWN9_VOUT_2V_RESISTANCE 70000
92 #define STEPDOWN9_VOUT_1V6_RESISTANCE 100000
93 
98 #define STEPDOWN9_VOUT_10V 0x12
99 #define STEPDOWN9_VOUT_9V5 0x11
100 #define STEPDOWN9_VOUT_9V 0x10
101 #define STEPDOWN9_VOUT_8V5 0x0F
102 #define STEPDOWN9_VOUT_8V 0x0E
103 #define STEPDOWN9_VOUT_7V5 0x0D
104 #define STEPDOWN9_VOUT_7V 0x0C
105 #define STEPDOWN9_VOUT_6V5 0x0B
106 #define STEPDOWN9_VOUT_6V 0x0A
107 #define STEPDOWN9_VOUT_5V5 0x09
108 #define STEPDOWN9_VOUT_5V 0x08
109 #define STEPDOWN9_VOUT_4V5 0x07
110 #define STEPDOWN9_VOUT_4V 0x06
111 #define STEPDOWN9_VOUT_3V5 0x05
112 #define STEPDOWN9_VOUT_3V3 0x04
113 #define STEPDOWN9_VOUT_3V 0x03
114 #define STEPDOWN9_VOUT_2V5 0x02
115 #define STEPDOWN9_VOUT_2V 0x01
116 #define STEPDOWN9_VOUT_1V6 0x00
117 
122 #define STEPDOWN9_PIN_STATE_HIGH 0x01
123 #define STEPDOWN9_PIN_STATE_LOW 0x00
124 
130 #define STEPDOWN9_RESISTANCE_MIN 8700
131 #define STEPDOWN9_FULL_SCALE_RES_100_KOHM 100000
132 #define STEPDOWN9_WIPER_POS_MAX 0xFF
133 #define STEPDOWN9_ROUND_TO_NEAREST_INT 0.5
134 
143 #define STEPDOWN9_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
144 #define STEPDOWN9_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
145  // stepdown9_set
147 
162 #define STEPDOWN9_MAP_MIKROBUS( cfg, mikrobus ) \
163  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
164  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
165  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
166  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
167  cfg.en = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
168  cfg.pg = MIKROBUS( mikrobus, MIKROBUS_INT )
169  // stepdown9_map // stepdown9
172 
177 typedef struct
178 {
179  // Output pins
180  digital_out_t en;
182  // Input pins
183  digital_in_t pg;
185  // Modules
186  spi_master_t spi;
188  pin_name_t chip_select;
190 } stepdown9_t;
191 
196 typedef struct
197 {
198  // Communication gpio pins
199  pin_name_t miso;
200  pin_name_t mosi;
201  pin_name_t sck;
202  pin_name_t cs;
204  // Additional gpio pins
205  pin_name_t en;
206  pin_name_t pg;
208  // static variable
209  uint32_t spi_speed;
210  spi_master_mode_t spi_mode;
211  spi_master_chip_select_polarity_t cs_polarity;
214 
219 typedef enum
220 {
222  STEPDOWN9_ERROR = -1
223 
225 
242 
257 
271 
286 err_t stepdown9_generic_write ( stepdown9_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
287 
302 err_t stepdown9_generic_read ( stepdown9_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
303 
313 void stepdown9_set_en_pin ( stepdown9_t *ctx, uint8_t pin_state );
314 
324 
336 err_t stepdown9_set_wiper_pos ( stepdown9_t *ctx, uint8_t wiper_pos );
337 
349 err_t stepdown9_set_resistance ( stepdown9_t *ctx, uint32_t res_ohm );
350 
362 err_t stepdown9_set_output ( stepdown9_t *ctx, uint8_t voltage );
363 
364 #ifdef __cplusplus
365 }
366 #endif
367 #endif // STEPDOWN9_H
368  // stepdown9
370 
371 // ------------------------------------------------------------------------ END
stepdown9_set_resistance
err_t stepdown9_set_resistance(stepdown9_t *ctx, uint32_t res_ohm)
Step Down 9 set potentiometer resistance.
stepdown9_t::pg
digital_in_t pg
Definition: stepdown9.h:183
stepdown9_set_wiper_pos
err_t stepdown9_set_wiper_pos(stepdown9_t *ctx, uint8_t wiper_pos)
Step Down 9 set wiper position.
stepdown9_t
Step Down 9 Click context object.
Definition: stepdown9.h:178
stepdown9_t::chip_select
pin_name_t chip_select
Definition: stepdown9.h:188
stepdown9_cfg_t::en
pin_name_t en
Definition: stepdown9.h:205
spi_specifics.h
This file contains SPI specific macros, functions, etc.
STEPDOWN9_ERROR
@ STEPDOWN9_ERROR
Definition: stepdown9.h:222
stepdown9_cfg_t::spi_speed
uint32_t spi_speed
Definition: stepdown9.h:209
stepdown9_get_pg_pin
uint8_t stepdown9_get_pg_pin(stepdown9_t *ctx)
Step Down 9 get PG pin state function.
STEPDOWN9_OK
@ STEPDOWN9_OK
Definition: stepdown9.h:221
stepdown9_cfg_t
Step Down 9 Click configuration object.
Definition: stepdown9.h:197
stepdown9_set_en_pin
void stepdown9_set_en_pin(stepdown9_t *ctx, uint8_t pin_state)
Step Down 9 set EN pin state function.
stepdown9_return_value_t
stepdown9_return_value_t
Step Down 9 Click return value data.
Definition: stepdown9.h:220
stepdown9_cfg_t::mosi
pin_name_t mosi
Definition: stepdown9.h:200
stepdown9_cfg_setup
void stepdown9_cfg_setup(stepdown9_cfg_t *cfg)
Step Down 9 configuration object setup function.
stepdown9_generic_write
err_t stepdown9_generic_write(stepdown9_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Step Down 9 data writing function.
stepdown9_cfg_t::pg
pin_name_t pg
Definition: stepdown9.h:206
stepdown9_set_output
err_t stepdown9_set_output(stepdown9_t *ctx, uint8_t voltage)
Step Down 9 set output voltage.
stepdown9_cfg_t::cs
pin_name_t cs
Definition: stepdown9.h:202
stepdown9_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: stepdown9.h:210
stepdown9_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: stepdown9.h:211
stepdown9_default_cfg
err_t stepdown9_default_cfg(stepdown9_t *ctx)
Step Down 9 default configuration function.
stepdown9_t::spi
spi_master_t spi
Definition: stepdown9.h:186
stepdown9_init
err_t stepdown9_init(stepdown9_t *ctx, stepdown9_cfg_t *cfg)
Step Down 9 initialization function.
stepdown9_cfg_t::sck
pin_name_t sck
Definition: stepdown9.h:201
stepdown9_t::en
digital_out_t en
Definition: stepdown9.h:180
stepdown9_generic_read
err_t stepdown9_generic_read(stepdown9_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Step Down 9 data reading function.
stepdown9_cfg_t::miso
pin_name_t miso
Definition: stepdown9.h:199