Adding ability to configure Can Addon frequency in common image

This commit is contained in:
Matt Holmes 2025-08-22 11:23:32 +01:00
parent eb047badfd
commit 4e0ea84fad
5 changed files with 20 additions and 1 deletions

View file

@ -41,7 +41,8 @@ void register_can_receiver(CanReceiver* receiver, CAN_Interface interface, CAN_S
ACAN_ESP32_Settings* settingsespcan;
static const uint32_t QUARTZ_FREQUENCY = CRYSTAL_FREQUENCY_MHZ * 1000000UL; //MHZ configured in USER_SETTINGS.h
uint8_t user_selected_can_addon_crystal_frequency_mhz = 0;
static uint32_t QUARTZ_FREQUENCY;
SPIClass SPI2515;
ACAN2515* can2515;
@ -59,6 +60,12 @@ bool native_can_initialized = false;
bool init_CAN() {
if(user_selected_can_addon_crystal_frequency_mhz > 0){
QUARTZ_FREQUENCY = user_selected_can_addon_crystal_frequency_mhz * 1000000UL;
} else {
QUARTZ_FREQUENCY = CRYSTAL_FREQUENCY_MHZ * 1000000UL;
}
auto nativeIt = can_receivers.find(CAN_NATIVE);
if (nativeIt != can_receivers.end()) {
auto se_pin = esp32hal->CAN_SE_PIN();

View file

@ -4,6 +4,7 @@
#include "../../devboard/utils/types.h"
extern bool use_canfd_as_can;
extern uint8_t user_selected_can_addon_crystal_frequency_mhz;
void dump_can_frame(CAN_frame& frame, frameDirection msgDir);
void transmit_can_frame_to_interface(const CAN_frame* tx_frame, int interface);

View file

@ -103,6 +103,7 @@ void init_stored_settings() {
user_selected_inverter_ah_capacity = settings.getUInt("INVAHCAPACITY", 0);
user_selected_inverter_battery_type = settings.getUInt("INVBTYPE", 0);
user_selected_inverter_ignore_contactors = settings.getBool("INVICNT", false);
user_selected_can_addon_crystal_frequency_mhz = settings.getUInt("CANFREQ", 8);
auto readIf = [](const char* settingName) {
auto batt1If = (comm_interface)settings.getUInt(settingName, (int)comm_interface::CanNative);

View file

@ -500,6 +500,10 @@ String settings_processor(const String& var, BatteryEmulatorSettingsStore& setti
return settings.getBool("INVICNT") ? "checked" : "";
}
if (var == "CANFREQ") {
return String(settings.getUInt("CANFREQ", 8));
}
return String();
}
@ -823,6 +827,9 @@ const char* getCANInterfaceName(CAN_Interface interface) {
</select>
</div>
<label>Can Addon Frequency: </label>
<input name='CANFREQ' type='text' value="%CANFREQ%" pattern="^[0-9]+$" />
<label>Equipment stop button: </label><select name='EQSTOP'>
%EQSTOP%
</select>

View file

@ -515,6 +515,9 @@ void init_webserver() {
} else if (p->name() == "INVBTYPE") {
auto type = atoi(p->value().c_str());
settings.saveUInt("INVBTYPE", (int)type);
} else if (p->name() == "CANFREQ"){
auto type = atoi(p->value().c_str());
settings.saveUInt("CANFREQ", type);
}
for (auto& boolSetting : boolSettings) {