mcp73213 2.0.0.0
mcp73213.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 MCP73213_H
36#define MCP73213_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 MCP73213_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 )
79#define MCP73213_RETVAL uint8_t
80
81#define MCP73213_OK 0x00
82#define MCP73213_INIT_ERROR 0xFF
89#define MCP73213_SPI_CMD_READ 0x0C
90#define MCP73213_SPI_CMD_WRITE 0x00
97#define MCP73213_VOLATILE_WIPER_0 0x00
98#define MCP73213_VOLATILE_WIPER_1 0x01
99#define MCP73213_NON_VOLATILE_WIPER_0 0x02
100#define MCP73213_NON_VOLATILE_WIPER_1 0x03
101#define MCP73213_VOLATILE_TCON_REGISTER 0x04
102#define MCP73213_STATUS_REGISTER 0x05
103#define MCP73213_DATA_EEPROM_6 0x06
104#define MCP73213_DATA_EEPROM_7 0x07
105#define MCP73213_DATA_EEPROM_8 0x08
106#define MCP73213_DATA_EEPROM_9 0x09
107#define MCP73213_DATA_EEPROM_A 0x0A
108#define MCP73213_DATA_EEPROM_B 0x0B
109#define MCP73213_DATA_EEPROM_C 0x0C
110#define MCP73213_DATA_EEPROM_D 0x0D
111#define MCP73213_DATA_EEPROM_E 0x0E
112#define MCP73213_DATA_EEPROM_F 0x0F
113//#define MCP73213_DATA_WRITE_CMD 0x00
120#define P73213_VREF_3V3 3.30
121#define P73213_VREF_5V 5.00
128#define MCP73213_OUTPUT_130_mA 0x00
129#define MCP73213_OUTPUT_250_mA 0x82
130#define MCP73213_OUTPUT_550_mA 0xCC
131#define MCP73213_OUTPUT_1100_mA 0xE9
134 // End group macro
135// --------------------------------------------------------------- PUBLIC TYPES
144typedef struct
145{
146 digital_out_t cs;
147
148 // Modules
149
150 spi_master_t spi;
151 pin_name_t chip_select;
152
153} mcp73213_t;
154
158typedef struct
159{
160 // Communication gpio pins
161
162 pin_name_t miso;
163 pin_name_t mosi;
164 pin_name_t sck;
165 pin_name_t cs;
166
167 // static variable
168
169 uint32_t spi_speed;
170 spi_master_mode_t spi_mode;
171 spi_master_chip_select_polarity_t cs_polarity;
172
174
175 // End types group
176// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
177
182#ifdef __cplusplus
183extern "C"{
184#endif
185
195
204
217(
218 mcp73213_t *ctx,
219 uint8_t *wr_buf,
220 uint16_t wr_len,
221 uint8_t *rd_buf,
222 uint16_t rd_len
223);
224
235void mcp73213_write_data ( mcp73213_t *ctx, uint8_t command, uint8_t write_data );
236
249uint8_t mcp73213_read_data ( mcp73213_t *ctx, uint8_t command );
250
260void mcp73213_set_current_output ( mcp73213_t *ctx, uint8_t out_data );
261
274
288float mcp73213_convert_output ( uint8_t value_adc, float v_ref );
289
290#ifdef __cplusplus
291}
292#endif
293#endif // _MCP73213_H_
294
295 // End public_function group
297
298// ------------------------------------------------------------------------- END
#define MCP73213_RETVAL
Definition mcp73213.h:79
void mcp73213_cfg_setup(mcp73213_cfg_t *cfg)
Config Object Initialization function.
uint8_t mcp73213_get_status(mcp73213_t *ctx)
Get the status register data function.
void mcp73213_generic_transfer(mcp73213_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len)
Generic transfer function.
void mcp73213_write_data(mcp73213_t *ctx, uint8_t command, uint8_t write_data)
Generic write 8-bit data function.
void mcp73213_set_current_output(mcp73213_t *ctx, uint8_t out_data)
Set values for output current function.
uint8_t mcp73213_read_data(mcp73213_t *ctx, uint8_t command)
Generic read 8-bit data function.
MCP73213_RETVAL mcp73213_init(mcp73213_t *ctx, mcp73213_cfg_t *cfg)
Initialization function.
float mcp73213_convert_output(uint8_t value_adc, float v_ref)
Convert ADC value to volatage.
Click configuration structure definition.
Definition mcp73213.h:159
spi_master_chip_select_polarity_t cs_polarity
Definition mcp73213.h:171
pin_name_t sck
Definition mcp73213.h:164
spi_master_mode_t spi_mode
Definition mcp73213.h:170
pin_name_t mosi
Definition mcp73213.h:163
uint32_t spi_speed
Definition mcp73213.h:169
pin_name_t miso
Definition mcp73213.h:162
pin_name_t cs
Definition mcp73213.h:165
Click ctx object definition.
Definition mcp73213.h:145
digital_out_t cs
Definition mcp73213.h:146
spi_master_t spi
Definition mcp73213.h:150
pin_name_t chip_select
Definition mcp73213.h:151