Rest of the HALs

This commit is contained in:
Jaakko Haakana 2025-06-24 21:35:14 +03:00
parent 12b402f994
commit 49fb79f35e
15 changed files with 286 additions and 267 deletions

View file

@ -21,6 +21,19 @@ std::vector<BatteryType> supported_battery_types() {
return types;
}
extern const char* name_for_chemistry(battery_chemistry_enum chem) {
switch (chem) {
case battery_chemistry_enum::LFP:
return "LFP";
case battery_chemistry_enum::NCA:
return "NCA";
case battery_chemistry_enum::NMC:
return "NMC";
default:
return nullptr;
}
}
extern const char* name_for_battery_type(BatteryType type) {
switch (type) {
case BatteryType::None:
@ -100,6 +113,14 @@ extern const char* name_for_battery_type(BatteryType type) {
}
}
#ifdef LFP_CHEMISTRY
const battery_chemistry_enum battery_chemistry_default = battery_chemistry_enum::LFP;
#else
const battery_chemistry_enum battery_chemistry_default = battery_chemistry_enum::NMC;
#endif
extern battery_chemistry_enum user_selected_battery_chemistry;
#ifdef COMMON_IMAGE
#ifdef SELECTED_BATTERY_CLASS
#error "Compile time SELECTED_BATTERY_CLASS should not be defined with COMMON_IMAGE"
@ -173,7 +194,7 @@ Battery* create_battery(BatteryType type) {
case BatteryType::SimpBms:
return new SimpBmsBattery();
case BatteryType::TeslaModel3Y:
return new TeslaModel3YBattery();
return new TeslaModel3YBattery(user_selected_battery_chemistry);
case BatteryType::TeslaModelSX:
return new TeslaModelSXBattery();
case BatteryType::TestFake:
@ -230,7 +251,11 @@ void setup_battery() {
void setup_battery() {
// Instantiate the battery only once just in case this function gets called multiple times.
if (battery == nullptr) {
#ifdef TESLA_MODEL_3Y_BATTERY
battery = new SELECTED_BATTERY_CLASS(user_selected_battery_chemistry);
#else
battery = new SELECTED_BATTERY_CLASS();
#endif
}
battery->setup();

View file

@ -47,10 +47,13 @@ enum class BatteryType {
extern std::vector<BatteryType> supported_battery_types();
extern const char* name_for_battery_type(BatteryType type);
extern const char* name_for_chemistry(battery_chemistry_enum chem);
extern BatteryType user_selected_battery_type;
extern bool user_selected_second_battery;
extern battery_chemistry_enum user_selected_battery_chemistry;
// Abstract base class for next-generation battery implementations.
// Defines the interface to call battery specific functionality.
class Battery {

View file

@ -1765,20 +1765,20 @@ void TeslaModel3YBattery::setup(void) { // Performs one time setup at startup
strncpy(datalayer.system.info.battery_protocol, Name, 63);
datalayer.system.info.battery_protocol[63] = '\0';
#ifdef LFP_CHEMISTRY
datalayer.battery.info.chemistry = battery_chemistry_enum::LFP;
datalayer.battery.info.max_design_voltage_dV = MAX_PACK_VOLTAGE_3Y_LFP;
datalayer.battery.info.min_design_voltage_dV = MIN_PACK_VOLTAGE_3Y_LFP;
datalayer.battery.info.max_cell_voltage_mV = MAX_CELL_VOLTAGE_LFP;
datalayer.battery.info.min_cell_voltage_mV = MIN_CELL_VOLTAGE_LFP;
datalayer.battery.info.max_cell_voltage_deviation_mV = MAX_CELL_DEVIATION_LFP;
#else // Startup in NCM/A mode
datalayer.battery.info.max_design_voltage_dV = MAX_PACK_VOLTAGE_3Y_NCMA;
datalayer.battery.info.min_design_voltage_dV = MIN_PACK_VOLTAGE_3Y_NCMA;
datalayer.battery.info.max_cell_voltage_mV = MAX_CELL_VOLTAGE_NCA_NCM;
datalayer.battery.info.min_cell_voltage_mV = MIN_CELL_VOLTAGE_NCA_NCM;
datalayer.battery.info.max_cell_voltage_deviation_mV = MAX_CELL_DEVIATION_NCA_NCM;
#endif // !LFP_CHEMISTRY
if (datalayer.battery.info.chemistry == battery_chemistry_enum::LFP) {
datalayer.battery.info.max_design_voltage_dV = MAX_PACK_VOLTAGE_3Y_LFP;
datalayer.battery.info.min_design_voltage_dV = MIN_PACK_VOLTAGE_3Y_LFP;
datalayer.battery.info.max_cell_voltage_mV = MAX_CELL_VOLTAGE_LFP;
datalayer.battery.info.min_cell_voltage_mV = MIN_CELL_VOLTAGE_LFP;
datalayer.battery.info.max_cell_voltage_deviation_mV = MAX_CELL_DEVIATION_LFP;
} else {
datalayer.battery.info.max_design_voltage_dV = MAX_PACK_VOLTAGE_3Y_NCMA;
datalayer.battery.info.min_design_voltage_dV = MIN_PACK_VOLTAGE_3Y_NCMA;
datalayer.battery.info.max_cell_voltage_mV = MAX_CELL_VOLTAGE_NCA_NCM;
datalayer.battery.info.min_cell_voltage_mV = MIN_CELL_VOLTAGE_NCA_NCM;
datalayer.battery.info.max_cell_voltage_deviation_mV = MAX_CELL_DEVIATION_NCA_NCM;
}
}
void TeslaModelSXBattery::setup(void) {

View file

@ -508,7 +508,8 @@ class TeslaBattery : public CanBattery {
class TeslaModel3YBattery : public TeslaBattery {
public:
TeslaModel3YBattery() {
TeslaModel3YBattery(battery_chemistry_enum chemistry) {
datalayer.battery.info.chemistry = chemistry;
#ifdef EXP_TESLA_BMS_DIGITAL_HVIL
operate_contactors = true;
#endif

View file

@ -32,13 +32,13 @@ static const uint32_t QUARTZ_FREQUENCY = CRYSTAL_FREQUENCY_MHZ * 1000000UL; //M
SPIClass SPI2515;
ACAN2515* can2515;
ACAN2515Settings* settings2515;
//ACAN2515 can(MCP2515_CS, SPI2515, MCP2515_INT);
static ACAN2515_Buffer16 gBuffer;
SPIClass SPI2517;
//ACAN2517FD canfd(MCP2517_CS, SPI2517, MCP2517_INT);
ACAN2517FD* canfd;
ACAN2517FDSettings* settings2517;
// Initialization functions
@ -92,9 +92,9 @@ bool init_CAN() {
can2515 = new ACAN2515(cs_pin, SPI2515, int_pin);
SPI2515.begin(sck_pin, miso_pin, mosi_pin);
ACAN2515Settings settings2515(QUARTZ_FREQUENCY, 500UL * 1000UL); // CAN bit rate 500 kb/s
settings2515.mRequestedMode = ACAN2515Settings::NormalMode;
const uint16_t errorCode2515 = can2515->begin(settings2515, [] { can2515->isr(); });
settings2515 = new ACAN2515Settings(QUARTZ_FREQUENCY, 500UL * 1000UL); // CAN bit rate 500 kb/s
settings2515->mRequestedMode = ACAN2515Settings::NormalMode;
const uint16_t errorCode2515 = can2515->begin(*settings2515, [] { can2515->isr(); });
if (errorCode2515 == 0) {
#ifdef DEBUG_LOG
logging.println("Can ok");
@ -127,32 +127,32 @@ bool init_CAN() {
logging.println("CAN FD add-on (ESP32+MCP2517) selected");
#endif // DEBUG_LOG
SPI2517.begin(sck_pin, sdo_pin, sdi_pin);
ACAN2517FDSettings settings2517(
CANFD_ADDON_CRYSTAL_FREQUENCY_MHZ, 500 * 1000,
DataBitRateFactor::x4); // Arbitration bit rate: 500 kbit/s, data bit rate: 2 Mbit/s
settings2517 =
new ACAN2517FDSettings(CANFD_ADDON_CRYSTAL_FREQUENCY_MHZ, 500 * 1000,
DataBitRateFactor::x4); // Arbitration bit rate: 500 kbit/s, data bit rate: 2 Mbit/s
// ListenOnly / Normal20B / NormalFD
settings2517.mRequestedMode = use_canfd_as_can ? ACAN2517FDSettings::Normal20B : ACAN2517FDSettings::NormalFD;
settings2517->mRequestedMode = use_canfd_as_can ? ACAN2517FDSettings::Normal20B : ACAN2517FDSettings::NormalFD;
const uint32_t errorCode2517 = canfd->begin(settings2517, [] { canfd->isr(); });
const uint32_t errorCode2517 = canfd->begin(*settings2517, [] { canfd->isr(); });
canfd->poll();
if (errorCode2517 == 0) {
#ifdef DEBUG_LOG
logging.print("Bit Rate prescaler: ");
logging.println(settings2517.mBitRatePrescaler);
logging.println(settings2517->mBitRatePrescaler);
logging.print("Arbitration Phase segment 1: ");
logging.print(settings2517.mArbitrationPhaseSegment1);
logging.print(settings2517->mArbitrationPhaseSegment1);
logging.print(" segment 2: ");
logging.print(settings2517.mArbitrationPhaseSegment2);
logging.print(settings2517->mArbitrationPhaseSegment2);
logging.print(" SJW: ");
logging.println(settings2517.mArbitrationSJW);
logging.println(settings2517->mArbitrationSJW);
logging.print("Actual Arbitration Bit Rate: ");
logging.print(settings2517.actualArbitrationBitRate());
logging.print(settings2517->actualArbitrationBitRate());
logging.print(" bit/s");
logging.print(" (Exact:");
logging.println(settings2517.exactArbitrationBitRate() ? "yes)" : "no)");
logging.println(settings2517->exactArbitrationBitRate() ? "yes)" : "no)");
logging.print("Arbitration Sample point: ");
logging.print(settings2517.arbitrationSamplePointFromBitStart());
logging.print(settings2517->arbitrationSamplePointFromBitStart());
logging.println("%");
#endif // DEBUG_LOG
} else {
@ -384,3 +384,35 @@ void dump_can_frame(CAN_frame& frame, frameDirection msgDir) {
datalayer.system.info.logged_can_messages_offset = offset; // Update offset in buffer
}
void stop_can() {
if (can_receivers.find(CAN_NATIVE) != can_receivers.end()) {
ESP32Can.CANStop();
}
if (can2515) {
can2515->end();
SPI2515.end();
}
if (canfd) {
canfd->end();
SPI2517.end();
}
}
void restart_can() {
if (can_receivers.find(CAN_NATIVE) != can_receivers.end()) {
ESP32Can.CANInit();
}
if (can2515) {
SPI2515.begin();
can2515->begin(*settings2515, [] { can2515->isr(); });
}
if (canfd) {
SPI2517.begin();
canfd->begin(*settings2517, [] { can2515->isr(); });
}
}

View file

@ -14,6 +14,8 @@ extern bool use_canfd_as_can;
void dump_can_frame(CAN_frame& frame, frameDirection msgDir);
void transmit_can_frame(CAN_frame* tx_frame, int interface);
class CanReceiver;
// Register a receiver object for a given CAN interface
void register_can_receiver(CanReceiver* receiver, CAN_Interface interface);
@ -71,4 +73,10 @@ void receive_frame_canfd_addon();
*/
void print_can_frame(CAN_frame frame, frameDirection msgDir);
// Stop/pause CAN communication for all interfaces
void stop_can();
// Restart CAN communication for all interfaces
void restart_can();
#endif

View file

@ -74,8 +74,11 @@ void init_stored_settings() {
#ifdef COMMON_IMAGE
user_selected_battery_type = (BatteryType)settings.getUInt("BATTTYPE", (int)BatteryType::None);
user_selected_battery_chemistry =
(battery_chemistry_enum)settings.getUInt("BATTCHEM", (int)battery_chemistry_enum::NCA);
user_selected_inverter_protocol = (InverterProtocolType)settings.getUInt("INVTYPE", (int)InverterProtocolType::None);
user_selected_charger_type = (ChargerType)settings.getUInt("CHGTYPE", (int)ChargerType::None);
equipment_stop_behavior = (STOP_BUTTON_BEHAVIOR)settings.getUInt("EQSTOP", (int)STOP_BUTTON_BEHAVIOR::NOT_CONNECTED);
user_selected_second_battery = settings.getBool("DBLBTR", false);
contactor_control_enabled = settings.getBool("CNTCTRL", false);

View file

@ -5,6 +5,9 @@
#include <chrono>
#include "../../../src/devboard/utils/types.h"
// Hardware Abstraction Layer base class.
// Derive a class to define board-specific parameters such as GPIO pin numbers
// This base class implements a mechanism for allocating GPIOs.
class Esp32Hal {
public:
virtual const char* name() = 0;

View file

@ -8,97 +8,70 @@ class ThreeLBHal : public Esp32Hal {
const char* name() { return "3LB board"; }
// Board boot-up time
duration BOOTUP_TIME() { return milliseconds(1000); }
virtual gpio_num_t RS485_TX_PIN() { return GPIO_NUM_1; }
virtual gpio_num_t RS485_RX_PIN() { return GPIO_NUM_3; }
virtual gpio_num_t CAN_TX_PIN() { return GPIO_NUM_27; }
virtual gpio_num_t CAN_RX_PIN() { return GPIO_NUM_26; }
// CAN_ADDON
// SCK input of MCP2515
virtual gpio_num_t MCP2515_SCK() { return GPIO_NUM_12; }
// SDI input of MCP2515
virtual gpio_num_t MCP2515_MOSI() { return GPIO_NUM_5; }
// SDO output of MCP2515
virtual gpio_num_t MCP2515_MISO() { return GPIO_NUM_34; }
// CS input of MCP2515
virtual gpio_num_t MCP2515_CS() { return GPIO_NUM_18; }
// INT output of MCP2515
virtual gpio_num_t MCP2515_INT() { return GPIO_NUM_35; }
// CANFD_ADDON defines for MCP2517
virtual gpio_num_t MCP2517_SCK() { return GPIO_NUM_17; }
virtual gpio_num_t MCP2517_SDI() { return GPIO_NUM_23; }
virtual gpio_num_t MCP2517_SDO() { return GPIO_NUM_39; }
virtual gpio_num_t MCP2517_CS() { return GPIO_NUM_21; }
virtual gpio_num_t MCP2517_INT() { return GPIO_NUM_34; }
// CHAdeMO support pin dependencies
virtual gpio_num_t CHADEMO_PIN_2() { return GPIO_NUM_12; }
virtual gpio_num_t CHADEMO_PIN_10() { return GPIO_NUM_5; }
virtual gpio_num_t CHADEMO_PIN_7() { return GPIO_NUM_34; }
virtual gpio_num_t CHADEMO_PIN_4() { return GPIO_NUM_35; }
virtual gpio_num_t CHADEMO_LOCK() { return GPIO_NUM_18; }
// Contactor handling
virtual gpio_num_t POSITIVE_CONTACTOR_PIN() { return GPIO_NUM_32; }
virtual gpio_num_t NEGATIVE_CONTACTOR_PIN() { return GPIO_NUM_33; }
virtual gpio_num_t PRECHARGE_PIN() { return GPIO_NUM_25; }
virtual gpio_num_t BMS_POWER() { return GPIO_NUM_2; }
virtual gpio_num_t SECOND_BATTERY_CONTACTORS_PIN() { return GPIO_NUM_13; }
// Automatic precharging
virtual gpio_num_t HIA4V1_PIN() { return GPIO_NUM_25; }
virtual gpio_num_t INVERTER_DISCONNECT_CONTACTOR_PIN() { return GPIO_NUM_32; }
// SMA CAN contactor pins
virtual gpio_num_t INVERTER_CONTACTOR_ENABLE_PIN() { return GPIO_NUM_36; }
virtual gpio_num_t INVERTER_CONTACTOR_ENABLE_LED_PIN() { return GPIO_NUM_NC; }
// SD card
virtual gpio_num_t SD_MISO_PIN() { return GPIO_NUM_2; }
virtual gpio_num_t SD_MOSI_PIN() { return GPIO_NUM_15; }
virtual gpio_num_t SD_SCLK_PIN() { return GPIO_NUM_14; }
virtual gpio_num_t SD_CS_PIN() { return GPIO_NUM_13; }
// LED
virtual gpio_num_t LED_PIN() { return GPIO_NUM_4; }
virtual uint8_t LED_MAX_BRIGHTNESS() { return 40; }
// Equipment stop pin
virtual gpio_num_t EQUIPMENT_STOP_PIN() { return GPIO_NUM_35; }
// Battery wake up pins
virtual gpio_num_t WUP_PIN1() { return GPIO_NUM_25; }
virtual gpio_num_t WUP_PIN2() { return GPIO_NUM_32; }
};
/*// RS485
//#define PIN_5V_EN 16
//#define RS485_EN_PIN 17 // 17 /RE
#define RS485_TX_PIN 1 // 21
#define RS485_RX_PIN 3 // 22
//#define RS485_SE_PIN 19 // 22 /SHDN
// CAN settings. CAN_2 is not defined as it can be either MCP2515 or MCP2517, defined by the user settings
#define CAN_1_TYPE ESP32CAN
// CAN1 PIN mappings, do not change these unless you are adding on extra hardware to the PCB
#define CAN_TX_PIN GPIO_NUM_27
#define CAN_RX_PIN GPIO_NUM_26
//#define CAN_SE_PIN 23
// CAN2 defines below
// CAN_ADDON defines
#define MCP2515_SCK 12 // SCK input of MCP2515
#define MCP2515_MOSI 5 // SDI input of MCP2515
#define MCP2515_MISO 34 // SDO output of MCP2515 | Pin 34 is input only, without pullup/down resistors
#define MCP2515_CS 18 // CS input of MCP2515
#define MCP2515_INT 35 // INT output of MCP2515 | | Pin 35 is input only, without pullup/down resistors
// CANFD_ADDON defines
#define MCP2517_SCK 17 // SCK input of MCP2517
#define MCP2517_SDI 23 // SDI input of MCP2517
#define MCP2517_SDO 39 // SDO output of MCP2517
#define MCP2517_CS 21 // CS input of MCP2517 //21 or 22
#define MCP2517_INT 34 // INT output of MCP2517 //34 or 35
// CHAdeMO support pin dependencies
#define CHADEMO_PIN_2 12
#define CHADEMO_PIN_10 5
#define CHADEMO_PIN_7 34
#define CHADEMO_PIN_4 35
#define CHADEMO_LOCK 18
// Contactor handling
#define POSITIVE_CONTACTOR_PIN 32
#define NEGATIVE_CONTACTOR_PIN 33
#define PRECHARGE_PIN 25
#define BMS_POWER 2
#define SECOND_BATTERY_CONTACTORS_PIN 13
// SMA CAN contactor pins
#define INVERTER_CONTACTOR_ENABLE_PIN 36
// Automatic precharging
#define HIA4V1_PIN 25
#define INVERTER_DISCONNECT_CONTACTOR_PIN 32
// SD card
//#define SD_MISO_PIN 2
//#define SD_MOSI_PIN 15
//#define SD_SCLK_PIN 14
//#define SD_CS_PIN 13
// LED
#define LED_PIN 4
#define LED_MAX_BRIGHTNESS 40
// Equipment stop pin
#define EQUIPMENT_STOP_PIN 35
// BMW_I3_BATTERY wake up pin
#define WUP_PIN1 GPIO_NUM_25 // Wake up pin for battery 1
#define WUP_PIN2 GPIO_NUM_32 // Wake up pin for battery 2
// ----- Error checks below, don't change (can't be moved to separate file) -----
#ifndef HW_CONFIGURED
#define HW_CONFIGURED
#else
#error Multiple HW defined! Please select a single HW
#endif
#ifdef CHADEMO_BATTERY
#ifdef CAN_ADDON
#error CHADEMO and CAN_ADDON cannot coexist due to overlapping GPIO pin usage
#endif
#endif
#ifdef BMW_I3_BATTERY
#if defined(CONTACTOR_CONTROL) && defined(WUP_PIN1)
#error GPIO PIN 25 cannot be used for both BMWi3 Wakeup and contactor control. Disable CONTACTOR_CONTROL
#endif
#if defined(CONTACTOR_CONTROL) && defined(WUP_PIN2)
#error GPIO PIN 32 cannot be used for both BMWi3 Wakeup and contactor control. Disable CONTACTOR_CONTROL
#endif
#endif
*/
#endif

View file

@ -11,84 +11,61 @@ The pin layout below supports the following:
- 1x CANFD (via MCP2518FD (SPI))
*/
// Board boot-up time
#define BOOTUP_TIME 1000 // Time in ms it takes before system is considered fully started up
class DevKitHal : public Esp32Hal {
public:
const char* name() { return "ESP32 DevKit V1"; }
duration BOOTUP_TIME() { return milliseconds(1000); }
virtual gpio_num_t RS485_TX_PIN() { return GPIO_NUM_1; }
virtual gpio_num_t RS485_RX_PIN() { return GPIO_NUM_3; }
virtual gpio_num_t CAN_TX_PIN() { return GPIO_NUM_27; }
virtual gpio_num_t CAN_RX_PIN() { return GPIO_NUM_26; }
// CAN_ADDON
// SCK input of MCP2515
virtual gpio_num_t MCP2515_SCK() { return GPIO_NUM_22; }
// SDI input of MCP2515
virtual gpio_num_t MCP2515_MOSI() { return GPIO_NUM_21; }
// SDO output of MCP2515
virtual gpio_num_t MCP2515_MISO() { return GPIO_NUM_19; }
// CS input of MCP2515
virtual gpio_num_t MCP2515_CS() { return GPIO_NUM_18; }
// INT output of MCP2515
virtual gpio_num_t MCP2515_INT() { return GPIO_NUM_23; }
// CANFD_ADDON defines for MCP2517
virtual gpio_num_t MCP2517_SCK() { return GPIO_NUM_33; }
virtual gpio_num_t MCP2517_SDI() { return GPIO_NUM_32; }
virtual gpio_num_t MCP2517_SDO() { return GPIO_NUM_35; }
virtual gpio_num_t MCP2517_CS() { return GPIO_NUM_25; }
virtual gpio_num_t MCP2517_INT() { return GPIO_NUM_34; }
// Contactor handling
virtual gpio_num_t POSITIVE_CONTACTOR_PIN() { return GPIO_NUM_5; }
virtual gpio_num_t NEGATIVE_CONTACTOR_PIN() { return GPIO_NUM_16; }
virtual gpio_num_t PRECHARGE_PIN() { return GPIO_NUM_17; }
virtual gpio_num_t SECOND_BATTERY_CONTACTORS_PIN() { return GPIO_NUM_32; }
// Automatic precharging
virtual gpio_num_t HIA4V1_PIN() { return GPIO_NUM_4; }
virtual gpio_num_t INVERTER_DISCONNECT_CONTACTOR_PIN() { return GPIO_NUM_5; }
// SMA CAN contactor pins
virtual gpio_num_t INVERTER_CONTACTOR_ENABLE_PIN() { return GPIO_NUM_14; }
virtual gpio_num_t INVERTER_CONTACTOR_ENABLE_LED_PIN() { return GPIO_NUM_2; }
// LED
virtual gpio_num_t LED_PIN() { return GPIO_NUM_4; }
virtual uint8_t LED_MAX_BRIGHTNESS() { return 40; }
// Equipment stop pin
virtual gpio_num_t EQUIPMENT_STOP_PIN() { return GPIO_NUM_12; }
// Battery wake up pins
virtual gpio_num_t WUP_PIN1() { return GPIO_NUM_25; }
virtual gpio_num_t WUP_PIN2() { return GPIO_NUM_32; }
};
// RS485
#define RS485_TX_PIN GPIO_NUM_1
#define RS485_RX_PIN GPIO_NUM_3
// CAN settings
#define CAN_1_TYPE ESP32CAN
//#define CAN_2_TYPE MCP2515
//#define CAN_3_TYPE MCP2518FD
// CAN1 PIN mappings, do not change these unless you are adding on extra hardware to the PCB
#define CAN_TX_PIN GPIO_NUM_27
#define CAN_RX_PIN GPIO_NUM_26
// CAN_ADDON defines
#define MCP2515_SCK GPIO_NUM_22 // SCK input of MCP2515
#define MCP2515_MOSI GPIO_NUM_21 // SDI input of MCP2515
#define MCP2515_MISO GPIO_NUM_19 // SDO output of MCP2515
#define MCP2515_CS GPIO_NUM_18 // CS input of MCP2515
#define MCP2515_INT GPIO_NUM_23 // INT output of MCP2515
// CANFD_ADDON defines
#define MCP2517_SCK GPIO_NUM_33 // SCK input of MCP2517
#define MCP2517_SDI GPIO_NUM_32 // SDI input of MCP2517
#define MCP2517_SDO GPIO_NUM_35 // SDO output of MCP2517 | Pin 35 is input only, without pullup/down resistors
#define MCP2517_CS GPIO_NUM_25 // CS input of MCP2517
#define MCP2517_INT GPIO_NUM_34 // INT output of MCP2517 | Pin 34 is input only, without pullup/down resistors
// Contactor handling
#define POSITIVE_CONTACTOR_PIN GPIO_NUM_5
#define NEGATIVE_CONTACTOR_PIN GPIO_NUM_16
#define PRECHARGE_PIN GPIO_NUM_17
#define SECOND_BATTERY_CONTACTORS_PIN GPIO_NUM_32
// SMA CAN contactor pins
#define INVERTER_CONTACTOR_ENABLE_PIN GPIO_NUM_14
// LED
#define LED_PIN GPIO_NUM_4
#define LED_MAX_BRIGHTNESS 40
#define INVERTER_CONTACTOR_ENABLE_LED_PIN GPIO_NUM_2
// Equipment stop pin
#define EQUIPMENT_STOP_PIN GPIO_NUM_12
// Automatic precharging
#define HIA4V1_PIN GPIO_NUM_17
#define INVERTER_DISCONNECT_CONTACTOR_PIN GPIO_NUM_5
// BMW_I3_BATTERY wake up pin
#define WUP_PIN1 GPIO_NUM_25 // Wake up pin for battery 1
#define WUP_PIN2 GPIO_NUM_32 // Wake up pin for battery 2
/* ----- Error checks below, don't change (can't be moved to separate file) ----- */
#ifndef HW_CONFIGURED
#define HW_CONFIGURED
#else
#error Multiple HW defined! Please select a single HW
#endif // HW_CONFIGURED
#ifdef CHADEMO_BATTERY
#error CHADEMO pins are not defined for this hardware.
#endif // CHADEMO_BATTERY
#ifdef BMW_I3_BATTERY
#if defined(WUP_PIN1) && defined(CANFD_ADDON)
#error GPIO PIN 25 cannot be used for both BMWi3 Wakeup and a CANFD addon board using these pins. Choose between BMW_I3_BATTERY and CANFD_ADDON
#endif // defined(WUP_PIN1) && defined(CANFD_ADDON)
#if defined(WUP_PIN2) && defined(CANFD_ADDON)
#error GPIO PIN 32 cannot be used for both BMWi3 Wakeup and a CANFD addon board using these pins. Choose between BMW_I3_BATTERY and CANFD_ADDON
#endif // defined(WUP_PIN2) && defined(CANFD_ADDON)
#endif // BMW_I3_BATTERY
#endif // __HW_DEVKIT_H__

View file

@ -21,70 +21,54 @@ class StarkHal : public Esp32Hal {
public:
const char* name() { return "Stark CMR Module"; }
duration BOOTUP_TIME() { return milliseconds(5000); }
// Not needed, GPIO 16 has hardware pullup for PSRAM compatibility
virtual gpio_num_t PIN_5V_EN() { return GPIO_NUM_NC; }
// Not needed, GPIO 17 is used as SCK input of MCP2517
virtual gpio_num_t RS485_EN_PIN() { return GPIO_NUM_NC; }
virtual gpio_num_t RS485_TX_PIN() { return GPIO_NUM_22; }
virtual gpio_num_t RS485_RX_PIN() { return GPIO_NUM_21; }
// Not needed, GPIO 19 is available as extra GPIO via pin header
virtual gpio_num_t RS485_SE_PIN() { return GPIO_NUM_NC; }
virtual gpio_num_t CAN_TX_PIN() { return GPIO_NUM_27; }
virtual gpio_num_t CAN_RX_PIN() { return GPIO_NUM_26; }
// (No function, GPIO 23 used instead as MCP_SCK)
virtual gpio_num_t CAN_SE_PIN() { return GPIO_NUM_NC; }
// CANFD_ADDON defines for MCP2517
virtual gpio_num_t MCP2517_SCK() { return GPIO_NUM_17; }
virtual gpio_num_t MCP2517_SDI() { return GPIO_NUM_5; }
virtual gpio_num_t MCP2517_SDO() { return GPIO_NUM_34; }
virtual gpio_num_t MCP2517_CS() { return GPIO_NUM_18; }
virtual gpio_num_t MCP2517_INT() { return GPIO_NUM_35; }
// Contactor handling
virtual gpio_num_t POSITIVE_CONTACTOR_PIN() { return GPIO_NUM_32; }
virtual gpio_num_t NEGATIVE_CONTACTOR_PIN() { return GPIO_NUM_33; }
virtual gpio_num_t PRECHARGE_PIN() { return GPIO_NUM_25; }
virtual gpio_num_t BMS_POWER() { return GPIO_NUM_23; }
virtual gpio_num_t SECOND_BATTERY_CONTACTORS_PIN() { return GPIO_NUM_19; }
// Automatic precharging
virtual gpio_num_t HIA4V1_PIN() { return GPIO_NUM_19; }
virtual gpio_num_t INVERTER_DISCONNECT_CONTACTOR_PIN() { return GPIO_NUM_25; }
// SMA CAN contactor pins
virtual gpio_num_t INVERTER_CONTACTOR_ENABLE_PIN() { return GPIO_NUM_2; }
// LED
virtual gpio_num_t LED_PIN() { return GPIO_NUM_4; }
virtual uint8_t LED_MAX_BRIGHTNESS() { return 40; }
// Equipment stop pin
virtual gpio_num_t EQUIPMENT_STOP_PIN() { return GPIO_NUM_2; }
// Battery wake up pins
virtual gpio_num_t WUP_PIN1() { return GPIO_NUM_25; }
virtual gpio_num_t WUP_PIN2() { return GPIO_NUM_32; }
};
/*// RS485
// #define PIN_5V_EN 16 // Not needed, GPIO 16 has hardware pullup for PSRAM compatibility
// #define RS485_EN_PIN 17 // Not needed, GPIO 17 is used as SCK input of MCP2517
#define RS485_TX_PIN 22
#define RS485_RX_PIN 21
// #define RS485_SE_PIN 19 // Not needed, GPIO 19 is available as extra GPIO via pin header
// CAN settings
#define CAN_1_TYPE ESP32CAN
// CAN1 PIN mappings, do not change these unless you are adding on extra hardware to the PCB
#define CAN_TX_PIN GPIO_NUM_27
#define CAN_RX_PIN GPIO_NUM_26
// #define CAN_SE_PIN 23 // (No function, GPIO 23 used instead as MCP_SCK)
// CANFD_ADDON defines
#define MCP2517_SCK 17 // SCK input of MCP2517
#define MCP2517_SDI 5 // SDI input of MCP2517
#define MCP2517_SDO 34 // SDO output of MCP2517
#define MCP2517_CS 18 // CS input of MCP2517
#define MCP2517_INT 35 // INT output of MCP2517
// Contactor handling
#define POSITIVE_CONTACTOR_PIN 32
#define NEGATIVE_CONTACTOR_PIN 33
#define PRECHARGE_PIN 25
#define BMS_POWER 23
#define SECOND_BATTERY_CONTACTORS_PIN 19 //Available as extra GPIO via pin header
// Automatic precharging
#define HIA4V1_PIN 19 //Available as extra GPIO via pin header
#define INVERTER_DISCONNECT_CONTACTOR_PIN 25
// SMA CAN contactor pins
#define INVERTER_CONTACTOR_ENABLE_PIN 2
// LED
#define LED_PIN 4
#define LED_MAX_BRIGHTNESS 40
// Equipment stop pin
#define EQUIPMENT_STOP_PIN 2
// BMW_I3_BATTERY wake up pin
#define WUP_PIN1 GPIO_NUM_25 // Wake up pin for battery 1
#define WUP_PIN2 GPIO_NUM_32 // Wake up pin for battery 2
// ----- Error checks below, don't change (can't be moved to separate file) -----
#ifndef HW_CONFIGURED
#define HW_CONFIGURED
#else
#error Multiple HW defined! Please select a single HW
#endif // HW_CONFIGURED
#ifdef BMW_I3_BATTERY
#if defined(CONTACTOR_CONTROL) && defined(WUP_PIN1)
#error GPIO PIN 25 cannot be used for both BMWi3 Wakeup and contactor control. Disable CONTACTOR_CONTROL
#endif
#if defined(CONTACTOR_CONTROL) && defined(WUP_PIN2)
#error GPIO PIN 32 cannot be used for both BMWi3 Wakeup and contactor control. Disable CONTACTOR_CONTROL
#endif
#endif // BMW_I3_BATTERY
*/
#endif // __HW_STARK_H__

View file

@ -398,13 +398,13 @@ void update_pause_state() {
logging.printf("Safety: Pausing CAN sending\n");
#endif
//completely force stop the CAN communication
ESP32Can.CANStop(); //Note: This only stops the NATIVE_CAN port, it will no longer ACK messages
stop_can();
} else if (!previous_allowed_to_send_CAN && allowed_to_send_CAN) {
//resume CAN communication
#ifdef DEBUG_LOG
logging.printf("Safety: Resuming CAN sending\n");
#endif
ESP32Can.CANInit(); //Note: This only resumes the NATIVE_CAN port
restart_can();
}
}

View file

@ -116,15 +116,22 @@ String settings_processor(const String& var) {
content +=
"<form action='saveSettings' method='post' style='display: grid; grid-template-columns: 1fr 2fr; gap: 10px; "
"align-items: center;'>";
content += "<label>Battery: </label><select style='max-width: 250px;' name='battery'>";
content += "<label>Battery: </label><select style='max-width: 250px;' name='battery'>";
content +=
options_for_enum((BatteryType)settings.getUInt("BATTTYPE", (int)BatteryType::None), name_for_battery_type);
content += "</select>";
content += "<label>Battery chemistry: </label><select style='max-width: 250px;' name='battery'>";
content += options_for_enum((battery_chemistry_enum)settings.getUInt("BATTCHEM", (int)battery_chemistry_enum::NCA),
name_for_chemistry);
content += "</select>";
content += "<label>Inverter protocol: </label><select style='max-width: 250px;' name='inverter'>";
content += options_for_enum((InverterProtocolType)settings.getUInt("INVTYPE", (int)InverterProtocolType::None),
name_for_inverter_type);
content += "</select>";
content += "<label>Charger: </label><select style='max-width: 250px;' name='charger'>";
content +=
options_for_enum((ChargerType)settings.getUInt("CHGTYPE", (int)ChargerType::None), name_for_charger_type);

View file

@ -1257,9 +1257,11 @@ String processor(const String& var) {
content += " Cont. Pos.: ";
content += "<span style='color: red;'>&#10005;</span>";
}
} else { // No PWM_CONTACTOR_CONTROL , we can read the pin and see feedback. Helpful if channel overloaded
} else if (
esp32hal->SECOND_BATTERY_CONTACTORS_PIN() !=
GPIO_NUM_NC) { // No PWM_CONTACTOR_CONTROL , we can read the pin and see feedback. Helpful if channel overloaded
content += "<h4>Cont. Neg.: ";
if (digitalRead(SECOND_BATTERY_CONTACTORS_PIN) == HIGH) {
if (digitalRead(esp32hal->SECOND_BATTERY_CONTACTORS_PIN()) == HIGH) {
content += "<span style='color: green;'>&#10003;</span>";
} else {
content += "<span style='color: red;'>&#10005;</span>";

View file

@ -4,6 +4,7 @@
#include "InverterProtocol.h"
#include "src/communication/can/CanReceiver.h"
#include "src/communication/can/comm_can.h"
#include "src/devboard/utils/types.h"
class CanInverterProtocol : public InverterProtocol, Transmitter, CanReceiver {