annotate Small_CPU/Src/batteryCharger.c @ 646:0fc1b47d2482

Remove battery charge counter from information menu: Due to long timeouts during charging (e.g. temperature break) multiple charge cycles could be counted without removment of the charger. To avoid confusions the visualization of this parameter has been removed.
author Ideenmodellierer
date Tue, 13 Apr 2021 19:21:14 +0200
parents e58f81cb25a7
children 1b995079c045
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
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
40 #define CHARGE_IN_PIN GPIO_PIN_2
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
41 #define CHARGE_IN_GPIO_PORT GPIOC
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
42 #define CHARGE_IN_GPIO_ENABLE() __GPIOC_CLK_ENABLE()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
43
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
44 #define CHARGE_OUT_PIN GPIO_PIN_1
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
45 #define CHARGE_OUT_GPIO_PORT GPIOC
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
46 #define CHARGE_OUT_GPIO_ENABLE() __GPIOC_CLK_ENABLE()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
47
645
e58f81cb25a7 Small changes in charger state handling:
Ideenmodellierer
parents: 644
diff changeset
48 #define CHARGER_DEBOUNCE_SECONDS (5u) /* 5 seconds used to avoid problems with charger interrupts / disconnections */
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
49
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
50 uint8_t battery_i_charge_status = 0;
643
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
51 uint16_t battery_charger_counter = 0;
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
52
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
53 #ifdef ENABLE_CHARGER_STATUS_V2
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
54 typedef enum
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
55 {
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
56 Charger_NotConnected = 0, /* This is identified reading CHARGE_IN_PIN == HIGH */
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
57 Charger_WarmUp, /* Charging started but counter did not yet reach a certain limit (used to debounce connect / disconnect events to avoid multiple increases of statistic charging cycle counter) */
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
58 Charger_Active, /* Charging identified by CHARGE_IN_PIN == LOW for a certain time */
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
59 Charger_Finished,
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
60 Charger_LostConnection /* Intermediate state to debounce disconnecting events (including charging error state like over temperature) */
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
61 } chargerState_t;
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
62
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
63 static chargerState_t batteryChargerState = Charger_NotConnected;
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
64 #endif
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
65
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
66 /* can be 0, 1 or 255
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
67 * 0 is disconnected
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
68 * 1 is charging
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
69 * 255 is full
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
70 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
71 uint8_t get_charge_status(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
72 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
73 return battery_i_charge_status;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
74 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
75
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
76 void init_battery_charger_status(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
77 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
78 #ifdef OSTC_ON_DISCOVERY_HARDWARE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
79 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
80 #endif
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
81
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
82 CHARGE_IN_GPIO_ENABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
83 CHARGE_OUT_GPIO_ENABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
84
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
85 ReInit_battery_charger_status_pins();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
86 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
87
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
88 void ReInit_battery_charger_status_pins(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
89 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
90 #ifdef OSTC_ON_DISCOVERY_HARDWARE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
91 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
92 #endif
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
93
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
94 GPIO_InitTypeDef GPIO_InitStructure;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
95
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
96 GPIO_InitStructure.Pin = CHARGE_IN_PIN;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
97 GPIO_InitStructure.Mode = GPIO_MODE_INPUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
98 GPIO_InitStructure.Pull = GPIO_NOPULL;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
99 GPIO_InitStructure.Speed = GPIO_SPEED_LOW;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
100 HAL_GPIO_Init(CHARGE_IN_GPIO_PORT, &GPIO_InitStructure);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
101
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
102 GPIO_InitStructure.Pin = CHARGE_OUT_PIN;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
103 GPIO_InitStructure.Mode = GPIO_MODE_ANALOG;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
104 GPIO_InitStructure.Pull = GPIO_NOPULL;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
105 GPIO_InitStructure.Speed = GPIO_SPEED_LOW;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
106 HAL_GPIO_Init(CHARGE_OUT_GPIO_PORT, &GPIO_InitStructure);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
107 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
108
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
109
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
110 void DeInit_battery_charger_status_pins(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
111 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
112 #ifdef OSTC_ON_DISCOVERY_HARDWARE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
113 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
114 #endif
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
115 GPIO_InitTypeDef GPIO_InitStructure;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
116
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
117
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
118 GPIO_InitStructure.Mode = GPIO_MODE_ANALOG;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
119 GPIO_InitStructure.Speed = GPIO_SPEED_LOW;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
120 GPIO_InitStructure.Pull = GPIO_NOPULL;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
121
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
122 GPIO_InitStructure.Pin = CHARGE_IN_PIN;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
123 HAL_GPIO_Init(CHARGE_IN_GPIO_PORT, &GPIO_InitStructure);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
124
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
125 GPIO_InitStructure.Pin = CHARGE_OUT_PIN;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
126 HAL_GPIO_Init(CHARGE_OUT_GPIO_PORT, &GPIO_InitStructure);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
127 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
128
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
129 /* static counter is used to avoid multiple counts of charge startings
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
130 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
131
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
132 there a short disconnections with the QI charger
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
133 therefore the battery_charger_counter has a countdown instead of = 0.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
134
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
135 battery_gas_gauge_set_charge_full and scheduleUpdateDeviceDataChargerFull are
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
136 set after disconnection as the charging process continues as long as not disconnected
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
137 to prevent the short disconnections the battery_charger_counter is used too including
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
138 upcounting again while battery_i_charge_status == 255 and the connection is established
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
139
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
140 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
141
643
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
142 void battery_charger_get_status_and_contral_battery_gas_gauge(uint8_t cycleTimeBase)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
143 {
643
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
144 #ifdef ENABLE_CHARGER_STATUS_V2
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
145 static uint8_t notifyChargeComplete = 0;
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
146 #endif
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
147
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
148 #ifdef OSTC_ON_DISCOVERY_HARDWARE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
149 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
150 #endif
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
151
643
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
152 #ifdef ENABLE_CHARGER_STATUS_V2
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
153 /* on disconnection or while disconnected */
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
154 if(HAL_GPIO_ReadPin(CHARGE_IN_GPIO_PORT,CHARGE_IN_PIN))
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
155 {
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
156 switch(batteryChargerState)
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
157 {
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
158 case Charger_Active: global.dataSendToMaster.chargeStatus = CHARGER_lostConnection;
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
159 global.deviceDataSendToMaster.chargeStatus = CHARGER_lostConnection;
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
160 batteryChargerState = Charger_LostConnection;
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
161 battery_charger_counter = CHARGER_DEBOUNCE_SECONDS;
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
162
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
163 if(get_voltage() >= 4.1f) /* the charger stops charging when charge current is 1/10. */
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
164 { /* Basically it is OK to rate a charging as complete if a defined voltage is reached */
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
165 batteryChargerState = Charger_Finished;
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
166 global.dataSendToMaster.chargeStatus = CHARGER_complete;
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
167 global.deviceDataSendToMaster.chargeStatus = CHARGER_complete;
645
e58f81cb25a7 Small changes in charger state handling:
Ideenmodellierer
parents: 644
diff changeset
168 battery_charger_counter = 15;
643
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
169 notifyChargeComplete = 1;
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
170 }
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
171 break;
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
172 case Charger_WarmUp:
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
173 case Charger_Finished:
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
174 case Charger_LostConnection: if(battery_charger_counter >= cycleTimeBase)
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
175 {
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
176 battery_charger_counter -= cycleTimeBase;
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
177 global.dataSendToMaster.chargeStatus = CHARGER_lostConnection;
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
178 global.deviceDataSendToMaster.chargeStatus = CHARGER_lostConnection;
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
179 batteryChargerState = Charger_LostConnection;
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
180 }
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
181 else
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
182 {
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
183 battery_charger_counter = 0;
645
e58f81cb25a7 Small changes in charger state handling:
Ideenmodellierer
parents: 644
diff changeset
184 battery_i_charge_status = 0;
643
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
185 global.dataSendToMaster.chargeStatus = CHARGER_off;
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
186 global.deviceDataSendToMaster.chargeStatus = CHARGER_off;
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
187
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
188 if(notifyChargeComplete)
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
189 {
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
190 battery_gas_gauge_set_charge_full();
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
191 scheduleUpdateDeviceDataChargerFull();
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
192 notifyChargeComplete = 0;
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
193 }
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
194 batteryChargerState = Charger_NotConnected;
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
195 }
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
196 break;
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
197 default: break;
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
198 }
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
199 }
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
200 else
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
201 {
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
202 /* connected */
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
203 /* wait for disconnection to write and reset */
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
204 switch(batteryChargerState)
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
205 {
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
206 case Charger_NotConnected: battery_i_charge_status = 1;
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
207 battery_charger_counter = 0;
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
208 batteryChargerState = Charger_WarmUp;
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
209 break;
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
210 case Charger_LostConnection: batteryChargerState = Charger_Active;
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
211 break;
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
212 case Charger_WarmUp: battery_charger_counter += cycleTimeBase;
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
213 if(battery_charger_counter >= CHARGER_DEBOUNCE_SECONDS )
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
214 {
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
215 battery_i_charge_status = 2;
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
216 scheduleUpdateDeviceDataChargerCharging();
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
217 batteryChargerState = Charger_Active;
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
218 }
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
219 /* no break */
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
220 case Charger_Finished:
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
221 case Charger_Active: global.dataSendToMaster.chargeStatus = CHARGER_running;
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
222 global.deviceDataSendToMaster.chargeStatus = CHARGER_running;
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
223
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
224 /* drive the output pin high to determine the state of the charger */
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
225 GPIO_InitTypeDef GPIO_InitStructure;
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
226 GPIO_InitStructure.Pin = CHARGE_OUT_PIN;
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
227 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
228 GPIO_InitStructure.Pull = GPIO_NOPULL;
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
229 GPIO_InitStructure.Speed = GPIO_SPEED_LOW;
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
230 HAL_GPIO_Init(CHARGE_OUT_GPIO_PORT, &GPIO_InitStructure);
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
231 HAL_GPIO_WritePin(CHARGE_OUT_GPIO_PORT, CHARGE_OUT_PIN,GPIO_PIN_SET);
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
232 HAL_Delay(1);
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
233
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
234 if(HAL_GPIO_ReadPin(CHARGE_IN_GPIO_PORT,CHARGE_IN_PIN)) /* high => charger stopped charging */
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
235 {
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
236 batteryChargerState = Charger_Finished;
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
237 global.dataSendToMaster.chargeStatus = CHARGER_complete;
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
238 global.deviceDataSendToMaster.chargeStatus = CHARGER_complete;
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
239 battery_charger_counter = 30;
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
240 notifyChargeComplete = 1;
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
241 }
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
242 else
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
243 {
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
244 if(batteryChargerState == Charger_Finished) /* voltage dropped below the hysteresis again => charging restarted */
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
245 {
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
246 batteryChargerState = Charger_Active;
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
247 notifyChargeComplete = 0;
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
248 }
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
249 }
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
250
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
251 /* restore high impedance to be able to detect disconnection */
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
252 GPIO_InitStructure.Pin = CHARGE_OUT_PIN;
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
253 GPIO_InitStructure.Mode = GPIO_MODE_ANALOG;
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
254 GPIO_InitStructure.Pull = GPIO_NOPULL;
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
255 GPIO_InitStructure.Speed = GPIO_SPEED_LOW;
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
256 HAL_GPIO_Init(CHARGE_OUT_GPIO_PORT, &GPIO_InitStructure);
645
e58f81cb25a7 Small changes in charger state handling:
Ideenmodellierer
parents: 644
diff changeset
257 HAL_Delay(1);
643
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
258 break;
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
259
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
260 default: /* wait for disconnection */
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
261 break;
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
262 }
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
263 }
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
264 #else
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
265 /* on disconnection or while disconnected */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
266 if(HAL_GPIO_ReadPin(CHARGE_IN_GPIO_PORT,CHARGE_IN_PIN))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
267 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
268 if(battery_charger_counter)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
269 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
270 battery_charger_counter--;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
271 global.dataSendToMaster.chargeStatus = CHARGER_lostConnection;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
272 global.deviceDataSendToMaster.chargeStatus = CHARGER_lostConnection;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
273 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
274 /* max count down to 127+5 or 127+20 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
275 if((battery_i_charge_status == 255) && battery_charger_counter < 127)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
276 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
277 // battery_gas_gauge_set_charge_full();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
278 // scheduleUpdateDeviceDataChargerFull();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
279 battery_charger_counter = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
280 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
281
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
282 if(battery_charger_counter == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
283 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
284 battery_i_charge_status = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
285 global.dataSendToMaster.chargeStatus = CHARGER_off;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
286 global.deviceDataSendToMaster.chargeStatus = CHARGER_off;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
287
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
288 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
289 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
290 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
291
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
292 /* connected */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
293
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
294 /* wait for disconnection to write and reset */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
295 if(battery_i_charge_status == 255)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
296 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
297 global.dataSendToMaster.chargeStatus = CHARGER_complete;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
298 global.deviceDataSendToMaster.chargeStatus = CHARGER_complete;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
299
643
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
300 if(((cycleTimeBase > 1) && (battery_charger_counter < 127+5)) || (battery_charger_counter < 127+20))
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
301 battery_charger_counter++;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
302 return;
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 battery_i_charge_status = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
307
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
308 /* charger is connected and didn't signal full yet */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
309 global.dataSendToMaster.chargeStatus = CHARGER_running;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
310 global.deviceDataSendToMaster.chargeStatus = CHARGER_running;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
311
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
312 GPIO_InitTypeDef GPIO_InitStructure;
643
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
313 GPIO_InitStructure.Pin = CHARGE_OUT_PIN;
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
314 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
315 GPIO_InitStructure.Pull = GPIO_NOPULL;
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
316 GPIO_InitStructure.Speed = GPIO_SPEED_LOW;
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
317 HAL_GPIO_Init(CHARGE_OUT_GPIO_PORT, &GPIO_InitStructure);
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
318 HAL_GPIO_WritePin(CHARGE_OUT_GPIO_PORT, CHARGE_OUT_PIN,GPIO_PIN_SET);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
319 HAL_Delay(1);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
320
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
321
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
322 if(battery_charger_counter < 120)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
323 {
643
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
324 if(cycleTimeBase == 1)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
325 battery_charger_counter++;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
326 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
327 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
328 battery_charger_counter += 30;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
329 if(battery_charger_counter >= 127)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
330 battery_charger_counter = 126;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
331 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
332 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
333 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
334 if(battery_charger_counter < 127)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
335 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
336 battery_charger_counter = 127;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
337 if(battery_i_charge_status < 2)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
338 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
339 battery_i_charge_status = 2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
340 scheduleUpdateDeviceDataChargerCharging();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
341 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
342 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
343
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
344 if(battery_charger_counter >= 127)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
345 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
346 if(HAL_GPIO_ReadPin(CHARGE_IN_GPIO_PORT,CHARGE_IN_PIN) || (get_voltage() >= 4.1f))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
347 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
348 battery_charger_counter++;
643
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
349 if(((cycleTimeBase > 1) && (battery_charger_counter > 127+5)) || (battery_charger_counter > 127+20))
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
350 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
351 battery_charger_counter = 127;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
352 if(get_voltage() >= 4.1f)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
353 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
354 battery_i_charge_status = 255;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
355 battery_gas_gauge_set_charge_full();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
356 scheduleUpdateDeviceDataChargerFull();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
357 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
358 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
359 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
360 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
361 battery_charger_counter = 127;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
362 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
363
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
364 GPIO_InitStructure.Pin = CHARGE_OUT_PIN;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
365 GPIO_InitStructure.Mode = GPIO_MODE_ANALOG;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
366 GPIO_InitStructure.Pull = GPIO_NOPULL;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
367 GPIO_InitStructure.Speed = GPIO_SPEED_LOW;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
368 HAL_GPIO_Init(CHARGE_OUT_GPIO_PORT, &GPIO_InitStructure);
643
5149cd644fbc Reimplemented charger status generation (deactivated):
Ideenmodellierer
parents: 38
diff changeset
369 #endif
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
370 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
371
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
372 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/