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
38#include "drv_digital_out.h"
39#include "drv_digital_in.h"
40#include "drv_spi_master.h"
41
42
43// -------------------------------------------------------------- PUBLIC MACROS
54#define MCP73213_MAP_MIKROBUS( cfg, mikrobus ) \
55 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
56 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
57 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
58 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
65#define MCP73213_RETVAL uint8_t
66
67#define MCP73213_OK 0x00
68#define MCP73213_INIT_ERROR 0xFF
75#define MCP73213_SPI_CMD_READ 0x0C
76#define MCP73213_SPI_CMD_WRITE 0x00
83#define MCP73213_VOLATILE_WIPER_0 0x00
84#define MCP73213_VOLATILE_WIPER_1 0x01
85#define MCP73213_NON_VOLATILE_WIPER_0 0x02
86#define MCP73213_NON_VOLATILE_WIPER_1 0x03
87#define MCP73213_VOLATILE_TCON_REGISTER 0x04
88#define MCP73213_STATUS_REGISTER 0x05
89#define MCP73213_DATA_EEPROM_6 0x06
90#define MCP73213_DATA_EEPROM_7 0x07
91#define MCP73213_DATA_EEPROM_8 0x08
92#define MCP73213_DATA_EEPROM_9 0x09
93#define MCP73213_DATA_EEPROM_A 0x0A
94#define MCP73213_DATA_EEPROM_B 0x0B
95#define MCP73213_DATA_EEPROM_C 0x0C
96#define MCP73213_DATA_EEPROM_D 0x0D
97#define MCP73213_DATA_EEPROM_E 0x0E
98#define MCP73213_DATA_EEPROM_F 0x0F
99//#define MCP73213_DATA_WRITE_CMD 0x00
106#define P73213_VREF_3V3 3.30
107#define P73213_VREF_5V 5.00
114#define MCP73213_OUTPUT_130_mA 0x00
115#define MCP73213_OUTPUT_250_mA 0x82
116#define MCP73213_OUTPUT_550_mA 0xCC
117#define MCP73213_OUTPUT_1100_mA 0xE9 // End group macro
121// --------------------------------------------------------------- PUBLIC TYPES
130typedef struct
131{
132 digital_out_t cs;
133
134 // Modules
135
136 spi_master_t spi;
137 pin_name_t chip_select;
138
139} mcp73213_t;
140
144typedef struct
145{
146 // Communication gpio pins
147
148 pin_name_t miso;
149 pin_name_t mosi;
150 pin_name_t sck;
151 pin_name_t cs;
152
153 // static variable
154
155 uint32_t spi_speed;
156 spi_master_mode_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
169extern "C"{
170#endif
171
181
190
203(
204 mcp73213_t *ctx,
205 uint8_t *wr_buf,
206 uint16_t wr_len,
207 uint8_t *rd_buf,
208 uint16_t rd_len
209);
210
221void mcp73213_write_data ( mcp73213_t *ctx, uint8_t command, uint8_t write_data );
222
235uint8_t mcp73213_read_data ( mcp73213_t *ctx, uint8_t command );
236
246void mcp73213_set_current_output ( mcp73213_t *ctx, uint8_t out_data );
247
260
274float mcp73213_convert_output ( uint8_t value_adc, float v_ref );
275
276#ifdef __cplusplus
277}
278#endif
279#endif // _MCP73213_H_
280 // End public_function group
283
284// ------------------------------------------------------------------------- END
#define MCP73213_RETVAL
Definition: mcp73213.h:65
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:145
spi_master_chip_select_polarity_t cs_polarity
Definition: mcp73213.h:157
pin_name_t sck
Definition: mcp73213.h:150
spi_master_mode_t spi_mode
Definition: mcp73213.h:156
pin_name_t mosi
Definition: mcp73213.h:149
uint32_t spi_speed
Definition: mcp73213.h:155
pin_name_t miso
Definition: mcp73213.h:148
pin_name_t cs
Definition: mcp73213.h:151
Click ctx object definition.
Definition: mcp73213.h:131
digital_out_t cs
Definition: mcp73213.h:132
spi_master_t spi
Definition: mcp73213.h:136
pin_name_t chip_select
Definition: mcp73213.h:137