mcp16331  2.0.0.0
mcp16331.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 MCP16331_H
36 #define MCP16331_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 MCP16331_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.adc_out = MIKROBUS( mikrobus, MIKROBUS_AN ); \
70  cfg.en = MIKROBUS( mikrobus, MIKROBUS_RST ); \
71 
77 #define MCP16331_RETVAL uint8_t
78 
79 #define MCP16331_OK 0x00
80 #define MCP16331_INIT_ERROR 0xFF
81  // End group macro
84 // --------------------------------------------------------------- PUBLIC TYPES
93 typedef struct
94 {
95  // Output pins
96 
97  digital_out_t cs;
98  digital_out_t en;
99 
100  // Input pins
101 
102  digital_in_t adc_out;
103 
104  // Modules
105 
106  spi_master_t spi;
107  pin_name_t chip_select;
108 
109 } mcp16331_t;
110 
114 typedef struct
115 {
116  // Communication gpio pins
117 
118  pin_name_t miso;
119  pin_name_t mosi;
120  pin_name_t sck;
121  pin_name_t cs;
122 
123  // Additional gpio pins
124 
125  pin_name_t adc_out;
126  pin_name_t en;
127 
128  // static variable
129 
130  uint32_t spi_speed;
131  uint8_t spi_mode;
132  spi_master_chip_select_polarity_t cs_polarity;
133 
135  // End types group
137 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
138 
143 #ifdef __cplusplus
144 extern "C"{
145 #endif
146 
156 
165 
178 (
179  mcp16331_t *ctx,
180  uint8_t *wr_buf,
181  uint16_t wr_len,
182  uint8_t *rd_buf,
183  uint16_t rd_len
184 );
185 
194 void mcp16331_set_vout ( mcp16331_t *ctx, uint16_t millivolts_vout );
195 
196 #ifdef __cplusplus
197 }
198 #endif
199 #endif // _MCP16331_H_
200  // End public_function group
203 
204 // ------------------------------------------------------------------------- END
mcp16331_t::cs
digital_out_t cs
Definition: mcp16331.h:97
mcp16331_cfg_setup
void mcp16331_cfg_setup(mcp16331_cfg_t *cfg)
Config Object Initialization function.
mcp16331_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: mcp16331.h:132
mcp16331_cfg_t::mosi
pin_name_t mosi
Definition: mcp16331.h:119
mcp16331_cfg_t::sck
pin_name_t sck
Definition: mcp16331.h:120
mcp16331_t
Click ctx object definition.
Definition: mcp16331.h:94
mcp16331_t::en
digital_out_t en
Definition: mcp16331.h:98
mcp16331_cfg_t::adc_out
pin_name_t adc_out
Definition: mcp16331.h:125
MCP16331_RETVAL
#define MCP16331_RETVAL
Definition: mcp16331.h:77
mcp16331_cfg_t::miso
pin_name_t miso
Definition: mcp16331.h:118
mcp16331_set_vout
void mcp16331_set_vout(mcp16331_t *ctx, uint16_t millivolts_vout)
mcp16331 set vout
mcp16331_cfg_t::cs
pin_name_t cs
Definition: mcp16331.h:121
mcp16331_t::chip_select
pin_name_t chip_select
Definition: mcp16331.h:107
mcp16331_t::adc_out
digital_in_t adc_out
Definition: mcp16331.h:102
mcp16331_generic_transfer
void mcp16331_generic_transfer(mcp16331_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len)
Generic transfer function.
mcp16331_init
MCP16331_RETVAL mcp16331_init(mcp16331_t *ctx, mcp16331_cfg_t *cfg)
Initialization function.
mcp16331_cfg_t::spi_mode
uint8_t spi_mode
Definition: mcp16331.h:131
mcp16331_t::spi
spi_master_t spi
Definition: mcp16331.h:106
mcp16331_cfg_t
Click configuration structure definition.
Definition: mcp16331.h:115
mcp16331_cfg_t::en
pin_name_t en
Definition: mcp16331.h:126
mcp16331_cfg_t::spi_speed
uint32_t spi_speed
Definition: mcp16331.h:130