annotate Small_CPU/Src/batteryCharger.c @ 755:92bf7bf9fb8a

Cleanup display of multiple warnings in T3 (Big font) view: In a very early version a list of possible warnings was shown and the active once highlithed in red. Because of the rising number of warnings and the big visualization of the first warning (double size) a erronous mixed warning list was displayed. This has now been cleaned up. The main warning is still be displayed in double size but the following warnings are shown on the right side in normal fornt size.
author Ideenmodellierer
date Tue, 07 Mar 2023 19:59:02 +0100
parents b1e24513b83e
children d32901746950
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3 * @file batteryCharger.c
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
4 * @author heinrichs weikamp gmbh
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
5 * @date 09-Dec-2014
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
6 * @version V0.0.1
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
7 * @since 09-Dec-2014
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
8 * @brief LTC4054 Battery Charger
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
9 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
10 @verbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
11 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
12 ##### How to use #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
13 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
14
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
15 The bq5105x provides one status output, CHG. This output is an open-drain NMOS device that is rated to 20 V.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
16 The open-drain FET connected to the CHG pin will be turned on whenever the output (BAT) of the charger is
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
17 enabled. As a note, the output of the charger supply will not be enabled if the VRECT-REG does not converge to the
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
18 no-load target voltage.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
19
644
ebe3fc302ab8 Compile with ENABLE_CHARGER_STATUS_V2
heinrichs weikamp
parents: 643
diff changeset
20 CHG F4 7 O Open-drain output � active when BAT is enabled. Float if not used.
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
21
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
22 @endverbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
23 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
24 * @attention
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
25 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
26 * <h2><center>&copy; COPYRIGHT(c) 2015 heinrichs weikamp</center></h2>
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
27 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
28 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
29 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
30 /* Includes ------------------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
31 #include "batteryCharger.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
32 #include "batteryGasGauge.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
33 #include "stm32f4xx_hal.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
34 #include "scheduler.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
35
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
36
643
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
37 /* Use This compile switch to select the new charger status control implementation */
644
ebe3fc302ab8 Compile with ENABLE_CHARGER_STATUS_V2
heinrichs weikamp
parents: 643
diff changeset
38 #define ENABLE_CHARGER_STATUS_V2
643
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
39
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
40 #define CHARGER_DEBOUNCE_SECONDS (6u) /* 6 seconds used to avoid problems with charger interrupts / disconnections */
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
41
668
079bb5b22c06 Rework charge cycle:
Ideenmodellierer
parents: 662
diff changeset
42 static uint8_t battery_i_charge_status = 0;
079bb5b22c06 Rework charge cycle:
Ideenmodellierer
parents: 662
diff changeset
43 static uint16_t battery_charger_counter = 0;
643
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
44
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
45 #ifdef ENABLE_CHARGER_STATUS_V2
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
46 static chargerState_t batteryChargerState = Charger_NotConnected;
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
47 #endif
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
48
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
49 /* can be 0, 1 or 255
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
50 * 0 is disconnected
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
51 * 1 is charging
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
52 * 255 is full
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
53 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
54 uint8_t get_charge_status(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
55 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
56 return battery_i_charge_status;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
57 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
58
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
59 void set_charge_state(uint8_t newState)
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
60 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
61 #ifdef ENABLE_CHARGER_STATUS_V2
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
62 if(newState < Charger_END)
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
63 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
64 batteryChargerState = newState;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
65 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
66 #endif
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
67 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
68
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
69 uint8_t get_charge_state(void)
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
70 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
71 return batteryChargerState;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
72 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
73
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
74 void init_battery_charger_status(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
75 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
76 #ifdef OSTC_ON_DISCOVERY_HARDWARE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
77 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
78 #endif
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
79
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
80 CHARGE_IN_GPIO_ENABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
81 CHARGE_OUT_GPIO_ENABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
82
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
83 ReInit_battery_charger_status_pins();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
84 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
85
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
86 void ReInit_battery_charger_status_pins(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
87 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
88 #ifdef OSTC_ON_DISCOVERY_HARDWARE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
89 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
90 #endif
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
91
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
92 GPIO_InitTypeDef GPIO_InitStructure;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
93
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
94 GPIO_InitStructure.Pin = CHARGE_IN_PIN;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
95 GPIO_InitStructure.Mode = GPIO_MODE_INPUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
96 GPIO_InitStructure.Pull = GPIO_NOPULL;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
97 GPIO_InitStructure.Speed = GPIO_SPEED_LOW;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
98 HAL_GPIO_Init(CHARGE_IN_GPIO_PORT, &GPIO_InitStructure);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
99
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
100 GPIO_InitStructure.Pin = CHARGE_OUT_PIN;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
101 GPIO_InitStructure.Mode = GPIO_MODE_ANALOG;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
102 GPIO_InitStructure.Pull = GPIO_NOPULL;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
103 GPIO_InitStructure.Speed = GPIO_SPEED_LOW;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
104 HAL_GPIO_Init(CHARGE_OUT_GPIO_PORT, &GPIO_InitStructure);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
105 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
106
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
107
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
108 void DeInit_battery_charger_status_pins(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
109 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
110 #ifdef OSTC_ON_DISCOVERY_HARDWARE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
111 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
112 #endif
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
113 GPIO_InitTypeDef GPIO_InitStructure;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
114
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
115
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
116 GPIO_InitStructure.Mode = GPIO_MODE_ANALOG;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
117 GPIO_InitStructure.Speed = GPIO_SPEED_LOW;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
118 GPIO_InitStructure.Pull = GPIO_NOPULL;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
119
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
120 GPIO_InitStructure.Pin = CHARGE_IN_PIN;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
121 HAL_GPIO_Init(CHARGE_IN_GPIO_PORT, &GPIO_InitStructure);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
122
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
123 GPIO_InitStructure.Pin = CHARGE_OUT_PIN;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
124 HAL_GPIO_Init(CHARGE_OUT_GPIO_PORT, &GPIO_InitStructure);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
125 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
126
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
127 /* static counter is used to avoid multiple counts of charge startings
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
128 and after that it is used, starting at 127 to count for the charge full signal
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
129
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
130 there a short disconnections with the QI charger
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
131 therefore the battery_charger_counter has a countdown instead of = 0.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
132
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
133 battery_gas_gauge_set_charge_full and scheduleUpdateDeviceDataChargerFull are
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
134 set after disconnection as the charging process continues as long as not disconnected
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
135 to prevent the short disconnections the battery_charger_counter is used too including
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
136 upcounting again while battery_i_charge_status == 255 and the connection is established
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
137
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
138 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
139
643
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
140 void battery_charger_get_status_and_contral_battery_gas_gauge(uint8_t cycleTimeBase)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
141 {
643
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
142 #ifdef ENABLE_CHARGER_STATUS_V2
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
143 static uint8_t notifyChargeComplete = 0;
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
144 #endif
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
145
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
146 #ifdef OSTC_ON_DISCOVERY_HARDWARE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
147 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
148 #endif
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
149
643
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
150 #ifdef ENABLE_CHARGER_STATUS_V2
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
151
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
152 if(batteryChargerState == Charger_ColdStart) /* wait for the first valid voltage meassurement */
643
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
153 {
686
b1e24513b83e Bugfix Battery charge complete event:
Ideenmodellierer
parents: 668
diff changeset
154 if((global.lifeData.battery_voltage != BATTERY_DEFAULT_VOLTAGE) && (global.lifeData.battery_voltage < BATTERY_CHARGER_CONNECTED_VOLTAGE))
643
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
155 {
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
156 if(global.lifeData.battery_voltage > BATTERY_ENDOF_CHARGE_VOLTAGE) /* Voltage close to full state => maybe new battery inserted */
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
157 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
158 battery_gas_gauge_set_charge_full();
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
159 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
160 batteryChargerState = Charger_NotConnected;
643
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
161 }
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
162 }
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
163 else
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
164 { /* on disconnection or while disconnected */
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
165 if(HAL_GPIO_ReadPin(CHARGE_IN_GPIO_PORT,CHARGE_IN_PIN))
643
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
166 {
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
167 switch(batteryChargerState)
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
168 {
686
b1e24513b83e Bugfix Battery charge complete event:
Ideenmodellierer
parents: 668
diff changeset
169 case Charger_WarmUp:
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
170 case Charger_Active: global.dataSendToMaster.chargeStatus = CHARGER_lostConnection;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
171 global.deviceDataSendToMaster.chargeStatus = CHARGER_lostConnection;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
172 batteryChargerState = Charger_LostConnection;
686
b1e24513b83e Bugfix Battery charge complete event:
Ideenmodellierer
parents: 668
diff changeset
173 if(cycleTimeBase > CHARGER_DEBOUNCE_SECONDS) /* adapt connection lost detection to sleep mode */
b1e24513b83e Bugfix Battery charge complete event:
Ideenmodellierer
parents: 668
diff changeset
174 {
b1e24513b83e Bugfix Battery charge complete event:
Ideenmodellierer
parents: 668
diff changeset
175 battery_charger_counter = cycleTimeBase + 1;
b1e24513b83e Bugfix Battery charge complete event:
Ideenmodellierer
parents: 668
diff changeset
176 }
b1e24513b83e Bugfix Battery charge complete event:
Ideenmodellierer
parents: 668
diff changeset
177 else
b1e24513b83e Bugfix Battery charge complete event:
Ideenmodellierer
parents: 668
diff changeset
178 {
b1e24513b83e Bugfix Battery charge complete event:
Ideenmodellierer
parents: 668
diff changeset
179 battery_charger_counter = CHARGER_DEBOUNCE_SECONDS;
b1e24513b83e Bugfix Battery charge complete event:
Ideenmodellierer
parents: 668
diff changeset
180 }
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
181 break;
686
b1e24513b83e Bugfix Battery charge complete event:
Ideenmodellierer
parents: 668
diff changeset
182 case Charger_Finished: battery_charger_counter = 0;
b1e24513b83e Bugfix Battery charge complete event:
Ideenmodellierer
parents: 668
diff changeset
183 batteryChargerState = Charger_LostConnection;
b1e24513b83e Bugfix Battery charge complete event:
Ideenmodellierer
parents: 668
diff changeset
184 /* no break */
668
079bb5b22c06 Rework charge cycle:
Ideenmodellierer
parents: 662
diff changeset
185 case Charger_LostConnection: /* the charger stops charging when charge current is 1/10 */
079bb5b22c06 Rework charge cycle:
Ideenmodellierer
parents: 662
diff changeset
186 /* Basically it is OK to rate a charging as complete if a defined voltage is reached */
686
b1e24513b83e Bugfix Battery charge complete event:
Ideenmodellierer
parents: 668
diff changeset
187 if(((battery_gas_gauge_isChargeValueValid() == 0) || (global.lifeData.battery_charge < 90)) && (get_voltage() >= BATTERY_ENDOF_CHARGE_VOLTAGE) && (get_voltage() < BATTERY_CHARGER_CONNECTED_VOLTAGE))
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
188 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
189 notifyChargeComplete = 1;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
190 }
686
b1e24513b83e Bugfix Battery charge complete event:
Ideenmodellierer
parents: 668
diff changeset
191 else
b1e24513b83e Bugfix Battery charge complete event:
Ideenmodellierer
parents: 668
diff changeset
192 {
b1e24513b83e Bugfix Battery charge complete event:
Ideenmodellierer
parents: 668
diff changeset
193 notifyChargeComplete = 0;
b1e24513b83e Bugfix Battery charge complete event:
Ideenmodellierer
parents: 668
diff changeset
194 }
b1e24513b83e Bugfix Battery charge complete event:
Ideenmodellierer
parents: 668
diff changeset
195 if(battery_charger_counter >= cycleTimeBase)
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
196 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
197 battery_charger_counter -= cycleTimeBase;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
198 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
199 else
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
200 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
201 battery_charger_counter = 0;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
202 battery_i_charge_status = 0;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
203 global.dataSendToMaster.chargeStatus = CHARGER_off;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
204 global.deviceDataSendToMaster.chargeStatus = CHARGER_off;
643
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
205
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
206 if(notifyChargeComplete)
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
207 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
208 battery_gas_gauge_set_charge_full();
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
209 scheduleUpdateDeviceDataChargerFull();
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
210 notifyChargeComplete = 0;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
211 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
212 batteryChargerState = Charger_NotConnected;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
213 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
214 break;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
215 default: break;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
216 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
217 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
218 else
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
219 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
220 /* connected */
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
221 /* wait for disconnection to write and reset */
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
222 switch(batteryChargerState)
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
223 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
224 case Charger_NotConnected: battery_i_charge_status = 1;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
225 battery_charger_counter = 0;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
226 batteryChargerState = Charger_WarmUp;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
227 break;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
228 case Charger_LostConnection: batteryChargerState = Charger_Active;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
229 break;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
230 case Charger_WarmUp: battery_charger_counter += cycleTimeBase;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
231 if(battery_charger_counter >= CHARGER_DEBOUNCE_SECONDS )
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
232 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
233 battery_i_charge_status = 2;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
234 scheduleUpdateDeviceDataChargerCharging();
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
235 batteryChargerState = Charger_Active;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
236 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
237 /* no break */
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
238 case Charger_Finished:
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
239 case Charger_Active: global.dataSendToMaster.chargeStatus = CHARGER_running;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
240 global.deviceDataSendToMaster.chargeStatus = CHARGER_running;
643
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
241
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
242 /* drive the output pin high to determine the state of the charger */
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
243 GPIO_InitTypeDef GPIO_InitStructure;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
244 GPIO_InitStructure.Pin = CHARGE_OUT_PIN;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
245 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
246 GPIO_InitStructure.Pull = GPIO_NOPULL;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
247 GPIO_InitStructure.Speed = GPIO_SPEED_LOW;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
248 HAL_GPIO_Init(CHARGE_OUT_GPIO_PORT, &GPIO_InitStructure);
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
249 HAL_GPIO_WritePin(CHARGE_OUT_GPIO_PORT, CHARGE_OUT_PIN,GPIO_PIN_SET);
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
250 HAL_Delay(1);
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
251
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
252 if(HAL_GPIO_ReadPin(CHARGE_IN_GPIO_PORT,CHARGE_IN_PIN)) /* high => charger stopped charging */
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
253 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
254 batteryChargerState = Charger_Finished;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
255 global.dataSendToMaster.chargeStatus = CHARGER_complete;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
256 global.deviceDataSendToMaster.chargeStatus = CHARGER_complete;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
257 battery_charger_counter = 30;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
258 notifyChargeComplete = 1;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
259 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
260 else
643
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
261 {
668
079bb5b22c06 Rework charge cycle:
Ideenmodellierer
parents: 662
diff changeset
262 if(global.lifeData.battery_charge > 100.0) /* still charging but indicator is set to full => decrease to 99% to keep count increasing */
079bb5b22c06 Rework charge cycle:
Ideenmodellierer
parents: 662
diff changeset
263 {
079bb5b22c06 Rework charge cycle:
Ideenmodellierer
parents: 662
diff changeset
264 battery_gas_gauge_set(99.0);
079bb5b22c06 Rework charge cycle:
Ideenmodellierer
parents: 662
diff changeset
265 }
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
266 if(batteryChargerState == Charger_Finished) /* voltage dropped below the hysteresis again => charging restarted */
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
267 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
268 batteryChargerState = Charger_Active;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
269 notifyChargeComplete = 0;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
270 }
643
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
271 }
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
272
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
273 /* restore high impedance to be able to detect disconnection */
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
274 GPIO_InitStructure.Pin = CHARGE_OUT_PIN;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
275 GPIO_InitStructure.Mode = GPIO_MODE_ANALOG;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
276 GPIO_InitStructure.Pull = GPIO_NOPULL;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
277 GPIO_InitStructure.Speed = GPIO_SPEED_LOW;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
278 HAL_GPIO_Init(CHARGE_OUT_GPIO_PORT, &GPIO_InitStructure);
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
279 HAL_Delay(1);
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
280 break;
643
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
281
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
282 default: /* wait for disconnection */
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
283 break;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 645
diff changeset
284 }
643
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
285 }
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
286 }
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
287 #else
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
288 /* on disconnection or while disconnected */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
289 if(HAL_GPIO_ReadPin(CHARGE_IN_GPIO_PORT,CHARGE_IN_PIN))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
290 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
291 if(battery_charger_counter)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
292 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
293 battery_charger_counter--;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
294 global.dataSendToMaster.chargeStatus = CHARGER_lostConnection;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
295 global.deviceDataSendToMaster.chargeStatus = CHARGER_lostConnection;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
296 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
297 /* max count down to 127+5 or 127+20 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
298 if((battery_i_charge_status == 255) && battery_charger_counter < 127)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
299 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
300 // battery_gas_gauge_set_charge_full();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
301 // scheduleUpdateDeviceDataChargerFull();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
302 battery_charger_counter = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
303 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
304
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
305 if(battery_charger_counter == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
306 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
307 battery_i_charge_status = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
308 global.dataSendToMaster.chargeStatus = CHARGER_off;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
309 global.deviceDataSendToMaster.chargeStatus = CHARGER_off;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
310
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
311 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
312 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
313 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
314
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
315 /* connected */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
316
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
317 /* wait for disconnection to write and reset */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
318 if(battery_i_charge_status == 255)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
319 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
320 global.dataSendToMaster.chargeStatus = CHARGER_complete;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
321 global.deviceDataSendToMaster.chargeStatus = CHARGER_complete;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
322
643
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
323 if(((cycleTimeBase > 1) && (battery_charger_counter < 127+5)) || (battery_charger_counter < 127+20))
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
324 battery_charger_counter++;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
325 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
326 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
327
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
328 if(battery_charger_counter == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
329 battery_i_charge_status = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
330
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
331 /* charger is connected and didn't signal full yet */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
332 global.dataSendToMaster.chargeStatus = CHARGER_running;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
333 global.deviceDataSendToMaster.chargeStatus = CHARGER_running;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
334
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
335 GPIO_InitTypeDef GPIO_InitStructure;
643
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
336 GPIO_InitStructure.Pin = CHARGE_OUT_PIN;
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
337 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
338 GPIO_InitStructure.Pull = GPIO_NOPULL;
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
339 GPIO_InitStructure.Speed = GPIO_SPEED_LOW;
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
340 HAL_GPIO_Init(CHARGE_OUT_GPIO_PORT, &GPIO_InitStructure);
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
341 HAL_GPIO_WritePin(CHARGE_OUT_GPIO_PORT, CHARGE_OUT_PIN,GPIO_PIN_SET);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
342 HAL_Delay(1);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
343
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
344
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
345 if(battery_charger_counter < 120)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
346 {
643
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
347 if(cycleTimeBase == 1)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
348 battery_charger_counter++;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
349 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
350 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
351 battery_charger_counter += 30;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
352 if(battery_charger_counter >= 127)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
353 battery_charger_counter = 126;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
354 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
355 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
356 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
357 if(battery_charger_counter < 127)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
358 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
359 battery_charger_counter = 127;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
360 if(battery_i_charge_status < 2)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
361 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
362 battery_i_charge_status = 2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
363 scheduleUpdateDeviceDataChargerCharging();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
364 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
365 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
366
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
367 if(battery_charger_counter >= 127)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
368 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
369 if(HAL_GPIO_ReadPin(CHARGE_IN_GPIO_PORT,CHARGE_IN_PIN) || (get_voltage() >= 4.1f))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
370 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
371 battery_charger_counter++;
643
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
372 if(((cycleTimeBase > 1) && (battery_charger_counter > 127+5)) || (battery_charger_counter > 127+20))
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
373 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
374 battery_charger_counter = 127;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
375 if(get_voltage() >= 4.1f)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
376 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
377 battery_i_charge_status = 255;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
378 battery_gas_gauge_set_charge_full();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
379 scheduleUpdateDeviceDataChargerFull();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
380 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
381 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
382 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
383 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
384 battery_charger_counter = 127;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
385 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
386
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
387 GPIO_InitStructure.Pin = CHARGE_OUT_PIN;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
388 GPIO_InitStructure.Mode = GPIO_MODE_ANALOG;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
389 GPIO_InitStructure.Pull = GPIO_NOPULL;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
390 GPIO_InitStructure.Speed = GPIO_SPEED_LOW;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
391 HAL_GPIO_Init(CHARGE_OUT_GPIO_PORT, &GPIO_InitStructure);
643
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
392 #endif
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
393 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
394
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
395 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/