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 
38 #include "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_spi_master.h"
51 
52 
53 // -------------------------------------------------------------- PUBLIC MACROS
64 #define MIC33153_MAP_MIKROBUS( cfg, mikrobus ) \
65  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
66  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
67  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
68  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
69  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
70  cfg.en = MIKROBUS( mikrobus, MIKROBUS_RST ); \
71  cfg.pg = MIKROBUS( mikrobus, MIKROBUS_INT );
72 
78 #define MIC33153_RETVAL uint8_t
79 
80 #define MIC33153_OK 0x00
81 #define MIC33153_INIT_ERROR 0xFF
82 
88 #define MIC33153_OUT_ENABLE 1
89 #define MIC33153_OUT_DISABLE 0
90 
96 #define MIC33153_MIN_VOLTAGE_800MV 0x0FFF
97 #define MIC33153_VOLTAGE_1000MV 0x0EC0
98 #define MIC33153_VOLTAGE_1500MV 0x0BE0
99 #define MIC33153_VOLTAGE_2000MV 0x08F0
100 #define MIC33153_VOLTAGE_2500MV 0x060F
101 #define MIC33153_VOLTAGE_3000MV 0x0330
102 #define MIC33153_VOLTAGE_3200MV 0x0210
103 #define MIC33153_MAX_VOLTAGE_3550MV 0x0000
104  // End group macro
107 // --------------------------------------------------------------- PUBLIC TYPES
116 typedef struct
117 {
118  // Output pins
119 
120  digital_out_t en;
121  digital_out_t cs;
122 
123  // Input pins
124 
125  digital_in_t an;
126  digital_in_t pg;
127 
128  // Modules
129 
130  spi_master_t spi;
131  pin_name_t chip_select;
132 
133 } mic33153_t;
134 
138 typedef struct
139 {
140  // Communication gpio pins
141 
142  pin_name_t miso;
143  pin_name_t mosi;
144  pin_name_t sck;
145  pin_name_t cs;
146 
147  // Additional gpio pins
148 
149  pin_name_t an;
150  pin_name_t en;
151  pin_name_t pg;
152 
153  // static variable
154 
155  uint32_t spi_speed;
156  uint8_t spi_mode;
157  spi_master_chip_select_polarity_t cs_polarity;
158 
160  // End types group
162 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
163 
168 #ifdef __cplusplus
169 extern "C"{
170 #endif
171 
181 
190 
203 (
204  mic33153_t *ctx,
205  uint8_t *wr_buf,
206  uint16_t wr_len,
207  uint8_t *rd_buf,
208  uint16_t rd_len
209 );
210 
219 void mic33153_write_dac ( mic33153_t *ctx, const uint16_t value_dac );
220 
229 void mic33153_enable_out ( mic33153_t *ctx, uint8_t state );
230 
241 
242 #ifdef __cplusplus
243 }
244 #endif
245 #endif // _MIC33153_H_
246  // End public_function group
249 
250 // ------------------------------------------------------------------------- END
mic33153_cfg_t::sck
pin_name_t sck
Definition: mic33153.h:144
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:139
mic33153_t::chip_select
pin_name_t chip_select
Definition: mic33153.h:131
mic33153_t::spi
spi_master_t spi
Definition: mic33153.h:130
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:117
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:126
MIC33153_RETVAL
#define MIC33153_RETVAL
Definition: mic33153.h:78
mic33153_cfg_t::spi_mode
uint8_t spi_mode
Definition: mic33153.h:156
mic33153_cfg_t::miso
pin_name_t miso
Definition: mic33153.h:142
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:120
mic33153_cfg_t::pg
pin_name_t pg
Definition: mic33153.h:151
mic33153_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: mic33153.h:157
mic33153_cfg_t::mosi
pin_name_t mosi
Definition: mic33153.h:143
mic33153_t::an
digital_in_t an
Definition: mic33153.h:125
mic33153_cfg_t::cs
pin_name_t cs
Definition: mic33153.h:145
mic33153_cfg_t::en
pin_name_t en
Definition: mic33153.h:150
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:149
mic33153_cfg_t::spi_speed
uint32_t spi_speed
Definition: mic33153.h:155
mic33153_t::cs
digital_out_t cs
Definition: mic33153.h:121