42#ifdef PREINIT_SUPPORTED
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
52#include "drv_digital_out.h"
53#include "drv_digital_in.h"
54#include "drv_spi_master.h"
67#define BALANCER2_MAP_MIKROBUS( cfg, mikrobus ) \
68 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
69 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
70 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
71 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
72 cfg.cell2 = MIKROBUS( mikrobus, MIKROBUS_AN ); \
73 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_RST ); \
74 cfg.cell1 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
75 cfg.stat = MIKROBUS( mikrobus, MIKROBUS_INT )
82#define BALANCER2_RETVAL uint8_t
84#define BALANCER2_OK 0x00
85#define BALANCER2_INIT_ERROR 0xFF
92#define BALANCER2_VREF_5V 5000
93#define BALANCER2_VREF_3V3 3300
100#define BALANCER2_CMD_START 0x01
101#define BALANCER2_CMD_MSBF_LSB 0x20
102#define BALANCER2_CMD_MSBF_MSB 0x00
103#define BALANCER2_CMD_SINGLE_MODE_CH0 0x80
104#define BALANCER2_CMD_SINGLE_MODE_CH1 0xC0
105#define BALANCER2_CMD_DIFF_MODE_CH0M_CH1P 0x40
106#define BALANCER2_CMD_DIFF_MODE_CH0P_CH1M 0x00
107#define BALANCER2_CMD_DUMMY 0x00
114#define BALANCER2_MASK 0x0F
121#define BALANCER2_BATT1 0xAA
122#define BALANCER2_BATT2 0xBB
123#define BALANCER2_BATT_BOTH 0xCC
130#define BALANCER2_PIN_STATE_HIGH 1
131#define BALANCER2_PIN_STATE_LOW 0
138#define BALANCER2_MODE_CHARGING 0x10
139#define BALANCER2_MODE_BALANCING_P 0x20
140#define BALANCER2_MODE_BALANCING_NP 0x30
141#define BALANCER2_MODE_BALANCING_PP 0x40
142#define BALANCER2_MODE_BALANCING_NPP 0x50
143#define BALANCER2_MODE_BALANCING_P1 0x60
144#define BALANCER2_MODE_BALANCING_NP1 0x70
145#define BALANCER2_MODE_BALANCING_P2 0x80
146#define BALANCER2_MODE_BALANCING_NP2 0x90
153#define CHN_0_MV_MULT 3.0
154#define CHN_1_MV_MULT 1.5
155#define ADC_RESOLUTION 4096.0
#define BALANCER2_RETVAL
Definition balancer2.h:82
void balancer2_cfg_setup(balancer2_cfg_t *cfg)
Config Object Initialization function.
void balancer2_cell_2_state(balancer2_t *ctx, uint8_t state)
Generic function for setting cell 2 pin status.
void balancer2_status_led_state(balancer2_t *ctx, uint8_t state)
Generic function for setting status led pin status.
void balancer2_default_cfg(balancer2_t *ctx)
Click Default Configuration function.
float balancer2_get_batttery_lvl(balancer2_t *ctx, uint8_t bat_num)
Function for getting real battery lvl.
float balancer2_adc_to_mv(balancer2_t *ctx, uint16_t adc_val)
Function for converting adc value to mV.
void balancer2_supply_state(balancer2_t *ctx, uint8_t state)
Generic function for setting supply pin status.
void balancer2_cell_1_state(balancer2_t *ctx, uint8_t state)
Generic function for setting cell 1 pin status.
uint16_t balancer2_read_adc(balancer2_t *ctx, uint8_t cmd_byte)
Function for reading adc value.
BALANCER2_RETVAL balancer2_init(balancer2_t *ctx, balancer2_cfg_t *cfg)
Initialization function.
void balancer2_set_vref(balancer2_t *ctx, uint16_t vref)
Function for setting reference value.
Click configuration structure definition.
Definition balancer2.h:189
spi_master_chip_select_polarity_t cs_polarity
Definition balancer2.h:208
pin_name_t sck
Definition balancer2.h:194
pin_name_t cell1
Definition balancer2.h:201
spi_master_mode_t spi_mode
Definition balancer2.h:207
pin_name_t mosi
Definition balancer2.h:193
uint32_t spi_speed
Definition balancer2.h:206
pin_name_t int_pin
Definition balancer2.h:200
pin_name_t miso
Definition balancer2.h:192
pin_name_t stat
Definition balancer2.h:202
pin_name_t cell2
Definition balancer2.h:199
pin_name_t cs
Definition balancer2.h:195
Click ctx object definition.
Definition balancer2.h:169
digital_out_t cs
Definition balancer2.h:172
spi_master_t spi
Definition balancer2.h:180
digital_out_t stat
Definition balancer2.h:176
digital_out_t cell2
Definition balancer2.h:173
digital_out_t int_pin
Definition balancer2.h:174
pin_name_t chip_select
Definition balancer2.h:181
digital_out_t cell1
Definition balancer2.h:175