mic24055  2.0.0.0
mic24055.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 MIC24055_H
36 #define MIC24055_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 MIC24055_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.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
72 
78 #define MIC24055_RETVAL uint8_t
79 
80 #define MIC24055_OK 0x00
81 #define MIC24055_INIT_ERROR 0xFF
82  // End group macro
85 // --------------------------------------------------------------- PUBLIC TYPES
94 typedef struct
95 {
96  // Output pins
97 
98  digital_out_t en;
99  digital_out_t int_pin;
100  digital_out_t cs;
101 
102  // Input pins
103 
104  digital_in_t an;
105 
106  // Modules
107 
108  spi_master_t spi;
109  pin_name_t chip_select;
110 
111 
112 } mic24055_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 an;
129  pin_name_t en;
130  //pin_name_t pwm;
131  pin_name_t int_pin;
132 
133  // static variable
134 
135  uint32_t spi_speed;
136  spi_master_mode_t spi_mode;
137  spi_master_chip_select_polarity_t cs_polarity;
138 
140  // End types group
142 
143 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
144 
149 #ifdef __cplusplus
150 extern "C"{
151 #endif
152 
162 
171 
184 (
185  mic24055_t *ctx,
186  uint8_t *wr_buf,
187  uint16_t wr_len,
188  uint8_t *rd_buf,
189  uint16_t rd_len
190 );
191 
200 void mic24055_dac_output ( mic24055_t *ctx, uint16_t value_dac );
201 
210 void mic24055_set_vout ( mic24055_t *ctx, uint16_t voltage );
211 
212 #ifdef __cplusplus
213 }
214 #endif
215 #endif // _MIC24055_H_
216  // End public_function group
219 
220 // ------------------------------------------------------------------------- END
mic24055_t::an
digital_in_t an
Definition: mic24055.h:104
mic24055_generic_transfer
void mic24055_generic_transfer(mic24055_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len)
Generic transfer function.
mic24055_cfg_t
Click configuration structure definition.
Definition: mic24055.h:118
mic24055_t::cs
digital_out_t cs
Definition: mic24055.h:100
mic24055_cfg_t::spi_speed
uint32_t spi_speed
Definition: mic24055.h:135
mic24055_dac_output
void mic24055_dac_output(mic24055_t *ctx, uint16_t value_dac)
Generic transfer function.
mic24055_cfg_setup
void mic24055_cfg_setup(mic24055_cfg_t *cfg)
Config Object Initialization function.
mic24055_t::spi
spi_master_t spi
Definition: mic24055.h:108
mic24055_set_vout
void mic24055_set_vout(mic24055_t *ctx, uint16_t voltage)
Set output voltage.
MIC24055_RETVAL
#define MIC24055_RETVAL
Definition: mic24055.h:78
mic24055_t::int_pin
digital_out_t int_pin
Definition: mic24055.h:99
mic24055_init
MIC24055_RETVAL mic24055_init(mic24055_t *ctx, mic24055_cfg_t *cfg)
Initialization function.
mic24055_t
Click ctx object definition.
Definition: mic24055.h:95
mic24055_t::chip_select
pin_name_t chip_select
Definition: mic24055.h:109
mic24055_cfg_t::cs
pin_name_t cs
Definition: mic24055.h:124
mic24055_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: mic24055.h:137
mic24055_cfg_t::miso
pin_name_t miso
Definition: mic24055.h:121
mic24055_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: mic24055.h:136
mic24055_cfg_t::int_pin
pin_name_t int_pin
Definition: mic24055.h:131
mic24055_cfg_t::mosi
pin_name_t mosi
Definition: mic24055.h:122
mic24055_cfg_t::sck
pin_name_t sck
Definition: mic24055.h:123
mic24055_cfg_t::en
pin_name_t en
Definition: mic24055.h:129
mic24055_t::en
digital_out_t en
Definition: mic24055.h:98
mic24055_cfg_t::an
pin_name_t an
Definition: mic24055.h:128