-
Notifications
You must be signed in to change notification settings - Fork 17.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AP_BattMonitor_SMBus_TIBQ: Added new TIBQ battery monitor
- Loading branch information
1 parent
275699d
commit d07049c
Showing
7 changed files
with
96 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#include "AP_BattMonitor_config.h" | ||
|
||
#if AP_BATTERY_SMBUS_TIBQ_ENABLED | ||
|
||
#include "AP_BattMonitor_SMBus_TIBQ.h" | ||
|
||
#include <AP_HAL/AP_HAL.h> | ||
#include <GCS_MAVLink/GCS.h> | ||
|
||
|
||
// Extention of AP_BattMonitor_SMBus_Generic to include TI's BQ40Z chip shutdown mechanism | ||
AP_BattMonitor_SMBus_TIBQ::AP_BattMonitor_SMBus_TIBQ(AP_BattMonitor &mon, | ||
AP_BattMonitor::BattMonitor_State &mon_state, | ||
AP_BattMonitor_Params ¶ms) | ||
: AP_BattMonitor_SMBus_Generic(mon, mon_state, params) | ||
{ | ||
_exit_emshut = true; | ||
} | ||
|
||
|
||
void AP_BattMonitor_SMBus_TIBQ::timer() | ||
{ | ||
if (_exit_emshut) { | ||
// Exit EMERGENCY SHUTDOWN state in case it was engaged on the last poweroff: | ||
uint8_t cmd[] = {0x00, 0xA7, 0x23}; | ||
if (_dev->transfer(cmd, 3, nullptr, 0)) { | ||
GCS_SEND_TEXT(MAV_SEVERITY_INFO, "BQ40Z bms exited shutdown"); | ||
_exit_emshut = false; | ||
} | ||
} | ||
|
||
AP_BattMonitor_SMBus_Generic::timer(); | ||
} | ||
|
||
|
||
void AP_BattMonitor_SMBus_TIBQ::shutdown(){ | ||
// Semaphore is needed in case this is called from another thread | ||
WITH_SEMAPHORE(_dev->get_semaphore()); | ||
|
||
uint8_t cmd[] = {0x00, 0x10, 0x00}; | ||
if (!_dev->transfer(cmd, 3, nullptr, 0)) { | ||
gcs().send_text(MAV_SEVERITY_ERROR, "Failed to shutdown TIBQ"); | ||
} else { | ||
_state.is_powering_off = true; | ||
} | ||
} | ||
|
||
#endif // AP_BATTERY_SMBUS_TIBQ_ENABLED |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#pragma once | ||
|
||
#include "AP_BattMonitor_config.h" | ||
|
||
#if AP_BATTERY_SMBUS_TIBQ_ENABLED | ||
|
||
#include "AP_BattMonitor_SMBus_Generic.h" | ||
|
||
class AP_BattMonitor_SMBus_TIBQ : public AP_BattMonitor_SMBus_Generic | ||
{ | ||
public: | ||
// Constructor | ||
AP_BattMonitor_SMBus_TIBQ(AP_BattMonitor &mon, | ||
AP_BattMonitor::BattMonitor_State &mon_state, | ||
AP_BattMonitor_Params ¶ms); | ||
|
||
private: | ||
void timer(void) override; | ||
|
||
// returns true if the battery can be shutdown with shutdown() | ||
bool can_shutdown() override { return true; }; | ||
// shuts the battery down if supported | ||
void shutdown() override; | ||
|
||
bool _exit_emshut; | ||
}; | ||
|
||
#endif // AP_BATTERY_SMBUS_TIBQ_ENABLED |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters