solarenergy2 2.1.0.0
solarenergy2.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 SOLARENERGY2_H
29#define SOLARENERGY2_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
73#define SOLARENERGY2_REG_T_HRV_PERIOD 0x00
74#define SOLARENERGY2_REG_T_HRV_MEAS 0x01
75#define SOLARENERGY2_REG_T_STS_PERIOD 0x02
76#define SOLARENERGY2_REG_T_LTS_PERIOD 0x03
77#define SOLARENERGY2_REG_V_HRV_CFG 0x04
78#define SOLARENERGY2_REG_HRV_CHECK_LVL 0x05
79#define SOLARENERGY2_REG_LTS_CFG 0x06
80#define SOLARENERGY2_REG_V_BAT_MAX_HI 0x07
81#define SOLARENERGY2_REG_V_BAT_MAX_LO 0x08
82#define SOLARENERGY2_REG_V_BAT_MIN_HI_DIS 0x09
83#define SOLARENERGY2_REG_V_BAT_MIN_HI_CON 0x0A
84#define SOLARENERGY2_REG_V_BAT_MIN_LO 0x0B
85#define SOLARENERGY2_REG_V_APL_MAX_HI 0x0C
86#define SOLARENERGY2_REG_V_APL_MAX_LO 0x0D
87#define SOLARENERGY2_REG_LDO_CFG 0x0E
88#define SOLARENERGY2_REG_PWR_CFG 0x0F
89#define SOLARENERGY2_REG_VAUX_CFG 0x10
90#define SOLARENERGY2_REG_VAUX_GND_CFG 0x11
91#define SOLARENERGY2_REG_MPPT_RATIO 0x12
92#define SOLARENERGY2_REG_EXT_CFG 0x13
93#define SOLARENERGY2_REG_T_SLEEP_VSUP_LO 0x14
94#define SOLARENERGY2_REG_T_SLEEP_VSUP_MID 0x15
95#define SOLARENERGY2_REG_T_SLEEP_VSUP_HI 0x16
96#define SOLARENERGY2_REG_T_HRV_LOW_CFG 0x17
97#define SOLARENERGY2_REG_SPI_I2C_CFG 0x18
98#define SOLARENERGY2_REG_PWR_MGT 0x19
99
100#define SOLARENERGY2_REG_SOFT_RES_WORD 0x1A
101#define SOLARENERGY2_REG_PROTECT_KEY 0x1B
102#define SOLARENERGY2_REG_LUX_METER_CFG 0x1C
103#define SOLARENERGY2_REG_LUX_METER_RESULT 0x1D
104#define SOLARENERGY2_REG_STATUS 0x22
105#define SOLARENERGY2_REG_VLD_STATUS 0x23
106
107#define SOLARENERGY2_REG_EEPROM_0 0x40
108
109 // solarenergy2_reg
110
125#define SOLARENERGY2_SET_T_HRV_PERIOD_256ms 0x00
126#define SOLARENERGY2_SET_T_HRV_PERIOD_512ms 0x01
127#define SOLARENERGY2_SET_T_HRV_PERIOD_1sec 0x02
128#define SOLARENERGY2_SET_T_HRV_PERIOD_2sec 0x03
129#define SOLARENERGY2_SET_T_HRV_PERIOD_4sec 0x04
130#define SOLARENERGY2_SET_T_HRV_PERIOD_8sec 0x05
131#define SOLARENERGY2_SET_T_HRV_PERIOD_16sec 0x06
132#define SOLARENERGY2_SET_T_HRV_PERIOD_32sec 0x07
133
134#define SOLARENERGY2_SET_T_HRV_MEAS_16ms 0x00
135#define SOLARENERGY2_SET_T_HRV_MEAS_32ms 0x01
136#define SOLARENERGY2_SET_T_HRV_MEAS_64ms 0x02
137#define SOLARENERGY2_SET_T_HRV_MEAS_128ms 0x03
138#define SOLARENERGY2_SET_T_HRV_MEAS_256ms 0x04
139#define SOLARENERGY2_SET_T_HRV_MEAS_512ms 0x05
140#define SOLARENERGY2_SET_T_HRV_MEAS_1sec 0x06
141#define SOLARENERGY2_SET_T_HRV_MEAS_2sec 0x07
142
143#define SOLARENERGY2_SET_T_STS_PERIOD_1ms 0x00
144#define SOLARENERGY2_SET_T_STS_PERIOD_2ms 0x01
145#define SOLARENERGY2_SET_T_STS_PERIOD_8ms 0x02
146#define SOLARENERGY2_SET_T_STS_PERIOD_16ms 0x03
147#define SOLARENERGY2_SET_T_STS_PERIOD_32ms 0x04
148#define SOLARENERGY2_SET_T_STS_PERIOD_64ms 0x05
149#define SOLARENERGY2_SET_T_STS_PERIOD_128ms 0x06
150#define SOLARENERGY2_SET_T_STS_PERIOD_256ms 0x07
151
152#define SOLARENERGY2_SET_T_LTS_PERIOD_1ms 0x00
153#define SOLARENERGY2_SET_T_LTS_PERIOD_4ms 0x01
154#define SOLARENERGY2_SET_T_LTS_PERIOD_16ms 0x02
155#define SOLARENERGY2_SET_T_LTS_PERIOD_64ms 0x03
156#define SOLARENERGY2_SET_T_LTS_PERIOD_256ms 0x04
157#define SOLARENERGY2_SET_T_LTS_PERIOD_1sec 0x05
158#define SOLARENERGY2_SET_T_LTS_PERIOD_4sec 0x06
159#define SOLARENERGY2_SET_T_LTS_PERIOD_16sec 0x07
160
161#define SOLARENERGY2_SET_T_HRV_LOW_PERIOD_256ms 0x00
162#define SOLARENERGY2_SET_T_HRV_LOW_PERIOD_512ms 0x01
163#define SOLARENERGY2_SET_T_HRV_LOW_PERIOD_1sec 0x02
164#define SOLARENERGY2_SET_T_HRV_LOW_PERIOD_2sec 0x03
165#define SOLARENERGY2_SET_T_HRV_LOW_PERIOD_4sec 0x04
166#define SOLARENERGY2_SET_T_HRV_LOW_PERIOD_8sec 0x05
167#define SOLARENERGY2_SET_T_HRV_LOW_PERIOD_16sec 0x06
168#define SOLARENERGY2_SET_T_HRV_LOW_PERIOD_32sec 0x07
169
170#define SOLARENERGY2_SET_T_LTS_LOW_PERIOD_2ms 0x00
171#define SOLARENERGY2_SET_T_LTS_LOW_PERIOD_8ms 0x01
172#define SOLARENERGY2_SET_T_LTS_LOW_PERIOD_32ms 0x02
173#define SOLARENERGY2_SET_T_LTS_LOW_PERIOD_128ms 0x03
174#define SOLARENERGY2_SET_T_LTS_LOW_PERIOD_512ms 0x04
175#define SOLARENERGY2_SET_T_LTS_LOW_PERIOD_2sec 0x05
176#define SOLARENERGY2_SET_T_LTS_LOW_PERIOD_8sec 0x06
177#define SOLARENERGY2_SET_T_LTS_LOW_PERIOD_32sec 0x07
178
179#define SOLARENERGY2_PROTECT_KEY_SOFT_RESET 0xE2
180#define SOLARENERGY2_PROTECT_KEY_PROTECTED_REG 0x4B
181#define SOLARENERGY2_PROTECT_KEY_EEPROM 0xA5
182
183#define SOLARENERGY2_SET_VAUX_LDO_CFG_1_2V 0x00
184#define SOLARENERGY2_SET_VAUX_LDO_CFG_1_55V 0x10
185#define SOLARENERGY2_SET_VAUX_LDO_CFG_1_65V 0x20
186#define SOLARENERGY2_SET_VAUX_LDO_CFG_1_8V 0x30
187#define SOLARENERGY2_SET_VAUX_LDO_CFG_2_0V 0x40
188#define SOLARENERGY2_SET_VAUX_LDO_CFG_2_2V 0x50
189#define SOLARENERGY2_SET_VAUX_LDO_CFG_2_4V 0x60
190#define SOLARENERGY2_SET_VAUX_LDO_CFG_2_6V 0x70
191#define SOLARENERGY2_SET_VAUX_LDO_CFG_BIT_MASK 0x70
192
193#define SOLARENERGY2_SET_ULP_LDO_CFG_1_2V 0x00
194#define SOLARENERGY2_SET_ULP_LDO_CFG_1_55V 0x01
195#define SOLARENERGY2_SET_ULP_LDO_CFG_1_65V 0x02
196#define SOLARENERGY2_SET_ULP_LDO_CFG_1_8V 0x03
197#define SOLARENERGY2_SET_ULP_LDO_CFG_2_0V 0x04
198#define SOLARENERGY2_SET_ULP_LDO_CFG_2_2V 0x05
199#define SOLARENERGY2_SET_ULP_LDO_CFG_2_4V 0x06
200#define SOLARENERGY2_SET_ULP_LDO_CFG_2_6V 0x07
201#define SOLARENERGY2_SET_ULP_LDO_CFG_BIT_MASK 0x07
202
203#define SOLARENERGY2_SET_MPPT_RATIO_50 0x00
204#define SOLARENERGY2_SET_MPPT_RATIO_60 0x01
205#define SOLARENERGY2_SET_MPPT_RATIO_67 0x02
206#define SOLARENERGY2_SET_MPPT_RATIO_71 0x03
207#define SOLARENERGY2_SET_MPPT_RATIO_75 0x04
208#define SOLARENERGY2_SET_MPPT_RATIO_78 0x05
209#define SOLARENERGY2_SET_MPPT_RATIO_80 0x06
210#define SOLARENERGY2_SET_MPPT_RATIO_82 0x07
211#define SOLARENERGY2_SET_MPPT_RATIO_83 0x08
212#define SOLARENERGY2_SET_MPPT_RATIO_85 0x09
213#define SOLARENERGY2_SET_MPPT_RATIO_86 0x0A
214#define SOLARENERGY2_SET_MPPT_RATIO_87 0x0B
215#define SOLARENERGY2_SET_MPPT_RATIO_88 0x0C
216#define SOLARENERGY2_SET_MPPT_BIT_MASK 0x0F
217
218#define SOLARENERGY2_SET_HRV_CHECK_VLD_VTG 0x00
219#define SOLARENERGY2_SET_HRV_CHECK_VLD_CUR 0x40
220#define SOLARENERGY2_SET_HRV_MIN_VTG_GEN 0x01
221
222#define SOLARENERGY2_SET_CRT_SRC_SEL_0mA 0x00
223#define SOLARENERGY2_SET_CRT_SRC_SEL_5mA 0x01
224#define SOLARENERGY2_SET_CRT_SRC_SEL_10mA 0x02
225#define SOLARENERGY2_SET_CRT_SRC_SEL_15mA 0x03
226#define SOLARENERGY2_CRT_SRC_SEL_BIT_MASK 0x03
227
228#define SOLARENERGY2_V_BATT_APP_VTG_BIT_MASK 0x3F
229
230#define SOLARENERGY2_SET_LTS_CFG_CONN_LTS_STS 0x04
231#define SOLARENERGY2_SET_LTS_CFG_NORMAL_MODE 0x00
232#define SOLARENERGY2_SET_LTS_CFG_NEVER_CHARGE 0x02
233#define SOLARENERGY2_SET_LTS_CFG_RECHARGEABLE 0x00
234#define SOLARENERGY2_SET_LTS_CFG_BATT_PROT_DIS 0x01
235#define SOLARENERGY2_SET_LTS_CFG_BATT_PROT_EN 0x00
236
237#define SOLARENERGY2_SET_VAUX0_CFG_STS 0x00
238#define SOLARENERGY2_SET_VAUX0_CFG_LDO 0x01
239#define SOLARENERGY2_SET_VAUX0_CFG_AUTO_FLT 0x02
240#define SOLARENERGY2_SET_VAUX0_CFG_AUTO_GND 0x03
241#define SOLARENERGY2_SET_VAUX1_CFG_STS 0x00
242#define SOLARENERGY2_SET_VAUX1_CFG_LDO 0x04
243#define SOLARENERGY2_SET_VAUX1_CFG_AUTO_FLT 0x08
244#define SOLARENERGY2_SET_VAUX1_CFG_AUTO_GND 0x0C
245#define SOLARENERGY2_SET_VAUX2_CFG_STS 0x00
246#define SOLARENERGY2_SET_VAUX2_CFG_LDO 0x10
247#define SOLARENERGY2_SET_VAUX2_CFG_AUTO_FLT 0x20
248#define SOLARENERGY2_SET_VAUX2_CFG_AUTO_GND 0x30
249#define SOLARENERGY2_SET_LDO_CFG_ULP_BIT_MASK 0x08
250#define SOLARENERGY2_SET_LDO_CFG_VSUP_BIT_MASK 0x80
251
252#define SOLARENERGY2_LUX_METER_BUSY_BIT_MASK 0x10
253#define SOLARENERGY2_LUX_METER_BIT_MASK 0x0F
254
255#define SOLARENERGY2_SET_HRV_CURRENT_LVL_15uA 0x0E
256
257
263#define SOLARENERGY2_DEVICE_ADDRESS 0x77
264
265 // solarenergy2_set
266
281#define SOLARENERGY2_MAP_MIKROBUS( cfg, mikrobus ) \
282 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
283 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
284 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
285 cfg.wup = MIKROBUS( mikrobus, MIKROBUS_AN ); \
286 cfg.blv = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
287 cfg.hlv = MIKROBUS( mikrobus, MIKROBUS_INT )
288
289 // solarenergy2_map
290 // solarenergy2
291
296typedef struct
297{
298 // Output pins
299 digital_out_t cs;
300 digital_out_t wup;
302 // Input pins
303 digital_in_t blv;
304 digital_in_t hlv;
306 // Modules
307 i2c_master_t i2c;
309 // I2C slave address
313
318typedef struct
319{
320 pin_name_t scl;
321 pin_name_t sda;
323 pin_name_t cs;
324 pin_name_t wup;
325 pin_name_t blv;
326 pin_name_t hlv;
328 uint32_t i2c_speed;
329 uint8_t i2c_address;
332
343
348typedef struct
349{
351 uint8_t hrv_lux_busy;
352 uint8_t hrv_low;
353 uint8_t bat_low;
355 uint8_t sw_lts_sts;
356 uint8_t usb_on;
357 uint8_t lts_protect;
360
377
393
410
425
439
454err_t solarenergy2_generic_write ( solarenergy2_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
455
470err_t solarenergy2_generic_read ( solarenergy2_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
471
486err_t solarenergy2_write_reg ( solarenergy2_t *ctx, uint8_t reg, uint8_t data_in );
487
503err_t solarenergy2_write_eeprom ( solarenergy2_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
504
518
533
548
562err_t solarenergy2_set_sleep_vsup ( solarenergy2_t *ctx, float sleep_vsup_sec );
563
590err_t solarenergy2_set_mppt_ratio ( solarenergy2_t *ctx, uint8_t mppt_ratio );
591
622err_t solarenergy2_set_ldo_cfg ( solarenergy2_t *ctx, uint8_t vaux_ldo, uint8_t ulp_ldo );
623
638
656err_t solarenergy2_set_pwr_current_source ( solarenergy2_t *ctx, uint8_t crt_src_sel );
657
671
684void solarenergy2_set_wup_pin ( solarenergy2_t *ctx, uint8_t state );
685
699
713
714#ifdef __cplusplus
715}
716#endif
717#endif // SOLARENERGY2_H
718
719 // solarenergy2
720
721// ------------------------------------------------------------------------ END
err_t solarenergy2_set_sleep_vsup(solarenergy2_t *ctx, float sleep_vsup_sec)
Solar Energy 2 set sleep VSUP function.
err_t solarenergy2_generic_write(solarenergy2_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Solar Energy 2 I2C writing function.
err_t solarenergy2_set_mppt_ratio(solarenergy2_t *ctx, uint8_t mppt_ratio)
Solar Energy 2 set MPPT ratio function.
err_t solarenergy2_config_abs_voltage(solarenergy2_t *ctx, solarenergy2_abs_vtg_v_t abs_vtg)
Solar Energy 2 config absolute voltage function.
err_t solarenergy2_default_cfg(solarenergy2_t *ctx)
Solar Energy 2 default configuration function.
err_t solarenergy2_set_ldo_cfg(solarenergy2_t *ctx, uint8_t vaux_ldo, uint8_t ulp_ldo)
Solar Energy 2 set LDO config function.
uint8_t solarenergy2_get_en_hv_cell_low_state(solarenergy2_t *ctx)
Solar Energy 2 get HLV state function.
err_t solarenergy2_init(solarenergy2_t *ctx, solarenergy2_cfg_t *cfg)
Solar Energy 2 initialization function.
err_t solarenergy2_store_config(solarenergy2_t *ctx)
Solar Energy 2 store config function.
err_t solarenergy2_get_status(solarenergy2_t *ctx, solarenergy2_status_t *status)
Solar Energy 2 get status function.
void solarenergy2_cfg_setup(solarenergy2_cfg_t *cfg)
Solar Energy 2 configuration object setup function.
err_t solarenergy2_get_bat_vtg_status(solarenergy2_t *ctx, solarenergy2_bat_vtg_status_t *bat_vtg_status)
Solar Energy 2 get storage element status function.
err_t solarenergy2_soft_reset(solarenergy2_t *ctx)
Solar Energy 2 soft reset function.
err_t solarenergy2_write_reg(solarenergy2_t *ctx, uint8_t reg, uint8_t data_in)
Solar Energy 2 write register function.
err_t solarenergy2_generic_read(solarenergy2_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Solar Energy 2 I2C reading function.
err_t solarenergy2_set_pwr_current_source(solarenergy2_t *ctx, uint8_t crt_src_sel)
Solar Energy 2 power source selection function.
uint8_t solarenergy2_get_battery_low_state(solarenergy2_t *ctx)
Solar Energy 2 get BLV state function.
void solarenergy2_set_wup_pin(solarenergy2_t *ctx, uint8_t state)
Solar Energy 2 set WUP pin function.
err_t solarenergy2_write_eeprom(solarenergy2_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Solar Energy 2 write EEPROM function.
solarenergy2_return_value_t
Solar Energy 2 Click return value data.
Definition solarenergy2.h:338
@ SOLARENERGY2_ERROR
Definition solarenergy2.h:340
@ SOLARENERGY2_OK
Definition solarenergy2.h:339
Solar Energy 2 Click operation battery voltage values object.
Definition solarenergy2.h:383
float v_apl_max_lo
Definition solarenergy2.h:390
float v_bat_min_hi_dis
Definition solarenergy2.h:386
float v_bat_min_hi_con
Definition solarenergy2.h:387
float v_apl_max_hi
Definition solarenergy2.h:389
float v_bat_max_hi
Definition solarenergy2.h:384
float v_bat_max_lo
Definition solarenergy2.h:385
float v_bat_min_lo
Definition solarenergy2.h:388
Solar Energy 2 Click storage element voltage and state object.
Definition solarenergy2.h:366
uint8_t lts_bat_min_hi
Definition solarenergy2.h:367
uint8_t sts_bat_max_lo
Definition solarenergy2.h:370
uint8_t sts_apl_max_lo
Definition solarenergy2.h:372
uint8_t lts_bat_min_lo
Definition solarenergy2.h:368
uint8_t sts_apl_max_hi
Definition solarenergy2.h:371
uint8_t sts_bat_max_hi
Definition solarenergy2.h:369
uint8_t sts_bat_min_hi
Definition solarenergy2.h:373
uint8_t sts_bat_min_lo
Definition solarenergy2.h:374
Solar Energy 2 Click configuration object.
Definition solarenergy2.h:319
pin_name_t wup
Definition solarenergy2.h:324
uint32_t i2c_speed
Definition solarenergy2.h:328
pin_name_t blv
Definition solarenergy2.h:325
pin_name_t scl
Definition solarenergy2.h:320
pin_name_t sda
Definition solarenergy2.h:321
pin_name_t hlv
Definition solarenergy2.h:326
pin_name_t cs
Definition solarenergy2.h:323
uint8_t i2c_address
Definition solarenergy2.h:329
Solar Energy 2 Click status information object.
Definition solarenergy2.h:349
uint8_t eeprom_data_busy
Definition solarenergy2.h:350
uint8_t hrv_lux_busy
Definition solarenergy2.h:351
uint8_t sw_vdcdc_lts_nsts
Definition solarenergy2.h:354
uint8_t sw_lts_sts
Definition solarenergy2.h:355
uint8_t hrv_low
Definition solarenergy2.h:352
uint8_t usb_on
Definition solarenergy2.h:356
uint8_t lts_protect
Definition solarenergy2.h:357
uint8_t bat_low
Definition solarenergy2.h:353
Solar Energy 2 Click context object.
Definition solarenergy2.h:297
digital_out_t cs
Definition solarenergy2.h:299
digital_in_t hlv
Definition solarenergy2.h:304
digital_in_t blv
Definition solarenergy2.h:303
i2c_master_t i2c
Definition solarenergy2.h:307
digital_out_t wup
Definition solarenergy2.h:300
uint8_t slave_address
Definition solarenergy2.h:310