mic33153  2.0.0.0
mic33153.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 MIC33153_H
36 #define MIC33153_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 MIC33153_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.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
74  cfg.en = MIKROBUS( mikrobus, MIKROBUS_RST ); \
75  cfg.pg = MIKROBUS( mikrobus, MIKROBUS_INT );
76 
82 #define MIC33153_RETVAL uint8_t
83 
84 #define MIC33153_OK 0x00
85 #define MIC33153_INIT_ERROR 0xFF
86 
92 #define MIC33153_OUT_ENABLE 1
93 #define MIC33153_OUT_DISABLE 0
94 
100 #define MIC33153_MIN_VOLTAGE_800MV 0x0FFF
101 #define MIC33153_VOLTAGE_1000MV 0x0EC0
102 #define MIC33153_VOLTAGE_1500MV 0x0BE0
103 #define MIC33153_VOLTAGE_2000MV 0x08F0
104 #define MIC33153_VOLTAGE_2500MV 0x060F
105 #define MIC33153_VOLTAGE_3000MV 0x0330
106 #define MIC33153_VOLTAGE_3200MV 0x0210
107 #define MIC33153_MAX_VOLTAGE_3550MV 0x0000
108  // End group macro
111 // --------------------------------------------------------------- PUBLIC TYPES
120 typedef struct
121 {
122  // Output pins
123 
124  digital_out_t en;
125  digital_out_t cs;
126 
127  // Input pins
128 
129  digital_in_t an;
130  digital_in_t pg;
131 
132  // Modules
133 
134  spi_master_t spi;
135  pin_name_t chip_select;
136 
137 } mic33153_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 an;
154  pin_name_t en;
155  pin_name_t pg;
156 
157  // static variable
158 
159  uint32_t spi_speed;
160  uint8_t spi_mode;
161  spi_master_chip_select_polarity_t cs_polarity;
162 
164  // End types group
166 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
167 
172 #ifdef __cplusplus
173 extern "C"{
174 #endif
175 
185 
194 
207 (
208  mic33153_t *ctx,
209  uint8_t *wr_buf,
210  uint16_t wr_len,
211  uint8_t *rd_buf,
212  uint16_t rd_len
213 );
214 
223 void mic33153_write_dac ( mic33153_t *ctx, const uint16_t value_dac );
224 
233 void mic33153_enable_out ( mic33153_t *ctx, uint8_t state );
234 
245 
246 #ifdef __cplusplus
247 }
248 #endif
249 #endif // _MIC33153_H_
250  // End public_function group
253 
254 // ------------------------------------------------------------------------- END
mic33153_cfg_t::sck
pin_name_t sck
Definition: mic33153.h:148
mic33153_cfg_setup
void mic33153_cfg_setup(mic33153_cfg_t *cfg)
Config Object Initialization function.
mic33153_cfg_t
Click configuration structure definition.
Definition: mic33153.h:143
mic33153_t::chip_select
pin_name_t chip_select
Definition: mic33153.h:135
mic33153_t::spi
spi_master_t spi
Definition: mic33153.h:134
mic33153_generic_transfer
void mic33153_generic_transfer(mic33153_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len)
Generic transfer function.
mic33153_t
Click ctx object definition.
Definition: mic33153.h:121
mic33153_enable_out
void mic33153_enable_out(mic33153_t *ctx, uint8_t state)
Out enable function.
mic33153_t::pg
digital_in_t pg
Definition: mic33153.h:130
MIC33153_RETVAL
#define MIC33153_RETVAL
Definition: mic33153.h:82
mic33153_cfg_t::spi_mode
uint8_t spi_mode
Definition: mic33153.h:160
mic33153_cfg_t::miso
pin_name_t miso
Definition: mic33153.h:146
mic33153_check_power_good
uint8_t mic33153_check_power_good(mic33153_t *ctx)
Power Good check function.
mic33153_t::en
digital_out_t en
Definition: mic33153.h:124
mic33153_cfg_t::pg
pin_name_t pg
Definition: mic33153.h:155
mic33153_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: mic33153.h:161
mic33153_cfg_t::mosi
pin_name_t mosi
Definition: mic33153.h:147
mic33153_t::an
digital_in_t an
Definition: mic33153.h:129
mic33153_cfg_t::cs
pin_name_t cs
Definition: mic33153.h:149
mic33153_cfg_t::en
pin_name_t en
Definition: mic33153.h:154
mic33153_write_dac
void mic33153_write_dac(mic33153_t *ctx, const uint16_t value_dac)
Write DAC function.
mic33153_init
MIC33153_RETVAL mic33153_init(mic33153_t *ctx, mic33153_cfg_t *cfg)
Initialization function.
mic33153_cfg_t::an
pin_name_t an
Definition: mic33153.h:153
mic33153_cfg_t::spi_speed
uint32_t spi_speed
Definition: mic33153.h:159
mic33153_t::cs
digital_out_t cs
Definition: mic33153.h:125