Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AP_ICEngine : Fuel pump implementation and cleanup #267

Open
wants to merge 3 commits into
base: CxPilot-7
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions libraries/AP_ICEngine/AP_ICEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,10 @@ void AP_ICEngine::set_ignition(bool on)
}
#endif // AP_RELAY_ENABLED

#if AP_ICENGINE_TCA9554_STARTER_ENABLED
tca9554_starter.set_ignition(on);
#endif

}

/*
Expand Down
35 changes: 24 additions & 11 deletions libraries/AP_ICEngine/AP_ICEngine_TCA9554.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,31 @@ extern const AP_HAL::HAL& hal;

/*
* TCA9554 output register mapping for PMB Rev E
* P0 = PMU_EN - PMU output ON/OFF (CN6 pin 2)
* P1 = ECU_EN - Unused (previously Engine Kill Switch)
* (Net labels in the schematic are out of date, but shown for reference)
* P0 = PMU_EN - Unused
* P1 = ECU_EN - Fuel Pump MOSFET (CN5 pin 3)
* P2 = I2C_P2 - Unused
* P3 = LED (active low)
* P4 = PMU_START - Crank Direction (CN6 pin 5)
* P5 = PMU_ARM - Crank Signal (CN6 pin 6)
* P5 = PMU_ARM - Crank Signal (CN6 pin 6) (active low)
* P6 = PMU_STAT_IN - Unused
* P7 = PMU_STAT - Unused
*/
enum PIN_MASK {
FUEL_PUMP = 1 << 1,
LED_OFF = 1 << 3,
REVERSE = 1 << 4,
STOP_CRANKING = 1 << 5,
};

#define TCA9554_I2C_BUS 1
#define TCA9554_I2C_ADDR 0x20
#define TCA9554_OUTPUT 0x01 // Output Port register address. Outgoing logic levels
#define TCA9554_OUT_DEFAULT 0x30 // 0011 0000
#define TCA9554_OUT_DEFAULT (LED_OFF | STOP_CRANKING)
#define TCA9554_CONF 0x03 // Configuration Port register address [0 = Output]
#define TCA9554_PINS 0xC2 // Set all used ports to outputs = 1100 0010
#define TCA9554_PINS (~(FUEL_PUMP | LED_OFF | REVERSE | STOP_CRANKING)) // Set all used ports to outputs

#define FUEL_PUMP_PRIMING_TIME_MS 30000

/*
initialise TCA9554
Expand Down Expand Up @@ -60,7 +70,7 @@ bool AP_ICEngine_TCA9554::TCA9554_init()
/*
set the state of the i2c controller
*/
void AP_ICEngine_TCA9554::TCA9554_set(TCA9554_state_t value)
void AP_ICEngine_TCA9554::TCA9554_set(uint8_t value)
{
const uint32_t now_ms = AP_HAL::millis();
if (now_ms - last_reg_check_ms > 100) {
Expand All @@ -76,7 +86,7 @@ void AP_ICEngine_TCA9554::TCA9554_set(TCA9554_state_t value)
if (value != last_state) {
WITH_SEMAPHORE(dev_TCA9554->get_semaphore());
// set outputs and status leds
if (dev_TCA9554->write_register(TCA9554_OUTPUT, (~(value<<2) & 0x0C) | value)) {
if (dev_TCA9554->write_register(TCA9554_OUTPUT, value)) {
last_state = value;
}
}
Expand All @@ -91,11 +101,14 @@ void AP_ICEngine_TCA9554::set_starter(bool on, AP_Int8 crank_direction)
return;
}
}
if (!crank_direction) {
TCA9554_set(on? STARTER_FORWARD : STARTER_OFF);
} else {
TCA9554_set(on? STARTER_REVERSE : STARTER_OFF);
uint8_t value = on ? 0 : STOP_CRANKING | LED_OFF;
if (crank_direction) {
value |= REVERSE;
}
if (ignition_on || AP_HAL::millis64() < FUEL_PUMP_PRIMING_TIME_MS) {
value |= FUEL_PUMP;
}
TCA9554_set(value);
}

#endif // AP_ICENGINE_TCA9554_STARTER_ENABLED
11 changes: 4 additions & 7 deletions libraries/AP_ICEngine/AP_ICEngine_TCA9554.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,19 @@

class AP_ICEngine_TCA9554 {
public:
void set_ignition(bool on) { ignition_on = on; }
void set_starter(bool on, AP_Int8 crank_direction);

private:
AP_HAL::OwnPtr<AP_HAL::I2CDevice> dev_TCA9554;

enum TCA9554_state_t {
STARTER_OFF = 0x30, // output register - 0011 0000
STARTER_FORWARD = 0x11, // output register - 0001 0001 - Forward direction
STARTER_REVERSE = 0x01, // output register - 0000 0001 - Reverse direction
};
TCA9554_state_t last_state;
uint8_t last_state;

bool initialised;
bool ignition_on;

bool TCA9554_init();
void TCA9554_set(TCA9554_state_t value);
void TCA9554_set(uint8_t value);
uint32_t last_reg_check_ms;
};

Expand Down
Loading