charger11 2.0.0.0
charger11.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2020 MikroElektronika d.o.o.
3** Contact: https://www.mikroe.com/contact
4**
5** Permission is hereby granted, free of charge, to any person obtaining a copy
6** of this software and associated documentation files (the "Software"), to deal
7** in the Software without restriction, including without limitation the rights
8** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9** copies of the Software, and to permit persons to whom the Software is
10** furnished to do so, subject to the following conditions:
11** The above copyright notice and this permission notice shall be
12** included in all copies or substantial portions of the Software.
13**
14** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20** USE OR OTHER DEALINGS IN THE SOFTWARE.
21****************************************************************************/
22
28#ifndef CHARGER11_H
29#define CHARGER11_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_i2c_master.h"
52#include "drv_spi_master.h"
53#include "spi_specifics.h"
54
75#define CHARGER11_SPI_VOLATILE_WIPER_0 0x00
76#define CHARGER11_SPI_VOLATILE_WIPER_1 0x01
77#define CHARGER11_SPI_NON_VOLATILE_WIPER_0 0x02
78#define CHARGER11_SPI_NON_VOLATILE_WIPER_1 0x03
79#define CHARGER11_SPI_VOLATILE_TCON 0x04
80#define CHARGER11_SPI_STATUS_REGISTER 0x05
81#define CHARGER11_SPI_DATA_EEPROM_0 0x06
82#define CHARGER11_SPI_DATA_EEPROM_1 0x07
83#define CHARGER11_SPI_DATA_EEPROM_2 0x08
84#define CHARGER11_SPI_DATA_EEPROM_3 0x09
85#define CHARGER11_SPI_DATA_EEPROM_4 0x0A
86#define CHARGER11_SPI_DATA_EEPROM_5 0x0B
87#define CHARGER11_SPI_DATA_EEPROM_6 0x0C
88#define CHARGER11_SPI_DATA_EEPROM_7 0x0D
89#define CHARGER11_SPI_DATA_EEPROM_8 0x0E
90#define CHARGER11_SPI_DATA_EEPROM_9 0x0F
91
92 // charger11_reg
93
108#define CHARGER11_PIN_ENABE 0x01
109#define CHARGER11_PIN_DISABLE 0x00
110
116#define CHARGER11_SET_DEV_ADDR 0x4D
117
126#define CHARGER11_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
127#define CHARGER11_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
128
129 // charger11_set
130
145#define CHARGER11_MAP_MIKROBUS( cfg, mikrobus ) \
146 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
147 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
148 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
149 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
150 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
151 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
152 cfg.lr = MIKROBUS( mikrobus, MIKROBUS_AN ); \
153 cfg.lg = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
154 cfg.st = MIKROBUS( mikrobus, MIKROBUS_INT )
155
156 // charger11_map
157 // charger11
158
163typedef struct charger11_s
164{
165 digital_out_t lr;
166 digital_out_t lg;
168 digital_in_t st;
170 i2c_master_t i2c;
171 spi_master_t spi;
174 pin_name_t chip_select;
177
182typedef struct
183{
184 pin_name_t scl;
185 pin_name_t sda;
186 pin_name_t miso;
187 pin_name_t mosi;
188 pin_name_t sck;
189 pin_name_t cs;
190 pin_name_t lr;
191 pin_name_t lg;
192 pin_name_t st;
194 uint32_t i2c_speed;
195 uint8_t i2c_address;
197 uint32_t spi_speed;
198 spi_master_mode_t spi_mode;
199 spi_master_chip_select_polarity_t cs_polarity;
202
213
230
245
260err_t charger11_i2c_write ( charger11_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
261
276err_t charger11_i2c_read ( charger11_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
277
292err_t charger11_spi_write ( charger11_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
293
308err_t charger11_spi_read ( charger11_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
309
318
327void charger11_lr_set( charger11_t *ctx, uint8_t pin_state );
328
337void charger11_lg_set( charger11_t *ctx, uint8_t pin_state );
338
349void charger11_spi_transfer( charger11_t *ctx, uint8_t *data_in, uint8_t *data_out,
350 uint8_t len );
351
361void charger11_spi_set_register( charger11_t *ctx, uint8_t register_address,
362 uint16_t register_value );
363
373void charger11_spi_get_register( charger11_t *ctx, uint8_t register_address,
374 uint16_t * register_value );
375
384
393
402
411
422float charger11_i2c_get_volt( charger11_t *ctx, float reference_voltage );
423
424#ifdef __cplusplus
425}
426#endif
427#endif // CHARGER11_H
428
429 // charger11
430
431// ------------------------------------------------------------------------ END
struct charger11_s charger11_t
Charger 11 Click context object.
charger11_return_value_t
Charger 11 Click return value data.
Definition charger11.h:208
@ CHARGER11_ERROR
Definition charger11.h:210
@ CHARGER11_OK
Definition charger11.h:209
uint8_t charger11_spi_get_wiper_position(charger11_t *ctx)
Charger 11 getting wiper position.
void charger11_lr_set(charger11_t *ctx, uint8_t pin_state)
Charger 11 setting AN pin state.
err_t charger11_i2c_read(charger11_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Charger 11 I2C reading function.
void charger11_cfg_setup(charger11_cfg_t *cfg)
Charger 11 configuration object setup function.
void charger11_lg_set(charger11_t *ctx, uint8_t pin_state)
Charger 11 Setting PWM pin state.
void charger11_spi_decrement_wiper(charger11_t *ctx)
Charger 11 decrementing wiper position.
uint16_t charger11_i2c_get_raw_data(charger11_t *ctx)
Charger 11 getting raw ADC data.
void charger11_spi_increment_wiper(charger11_t *ctx)
Charger 11 incrementing wiper position.
err_t charger11_spi_write(charger11_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Charger 11 SPI writing function.
float charger11_i2c_get_volt(charger11_t *ctx, float reference_voltage)
Charger 11 getting output voltage.
err_t charger11_init(charger11_t *ctx, charger11_cfg_t *cfg)
Charger 11 initialization function.
uint8_t charger11_get_int(charger11_t *ctx)
Charger 11 getting INT pin state.
void charger11_spi_set_register(charger11_t *ctx, uint8_t register_address, uint16_t register_value)
Charger 11 setting register.
err_t charger11_spi_read(charger11_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Charger 11 SPI reading function.
void charger11_spi_transfer(charger11_t *ctx, uint8_t *data_in, uint8_t *data_out, uint8_t len)
Charger 11 transfering bytes via SPI.
err_t charger11_i2c_write(charger11_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Charger 11 I2C writing function.
void charger11_spi_get_register(charger11_t *ctx, uint8_t register_address, uint16_t *register_value)
Charger 11 getting register value.
This file contains SPI specific macros, functions, etc.
Charger 11 Click configuration object.
Definition charger11.h:183
pin_name_t st
Definition charger11.h:192
uint32_t i2c_speed
Definition charger11.h:194
pin_name_t lg
Definition charger11.h:191
spi_master_chip_select_polarity_t cs_polarity
Definition charger11.h:199
pin_name_t sck
Definition charger11.h:188
spi_master_mode_t spi_mode
Definition charger11.h:198
pin_name_t lr
Definition charger11.h:190
pin_name_t mosi
Definition charger11.h:187
uint32_t spi_speed
Definition charger11.h:197
pin_name_t scl
Definition charger11.h:184
pin_name_t miso
Definition charger11.h:186
pin_name_t sda
Definition charger11.h:185
pin_name_t cs
Definition charger11.h:189
uint8_t i2c_address
Definition charger11.h:195
Charger 11 Click context object.
Definition charger11.h:164
spi_master_t spi
Definition charger11.h:171
digital_in_t st
Definition charger11.h:168
digital_out_t lg
Definition charger11.h:166
i2c_master_t i2c
Definition charger11.h:170
digital_out_t lr
Definition charger11.h:165
uint8_t slave_address
Definition charger11.h:173
pin_name_t chip_select
Definition charger11.h:174