mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-04 18:29:48 +02:00
Merge branch 'dalathegreat:main' into main
This commit is contained in:
commit
a961a5d8d5
8 changed files with 197 additions and 188 deletions
|
@ -16,6 +16,7 @@ static unsigned long previousMillis10s = 0; // will store last time a 1s CAN Me
|
|||
static uint8_t mprun10r = 0; //counter 0-20 for 0x1F2 message
|
||||
static uint8_t mprun10 = 0; //counter 0-3
|
||||
static uint8_t mprun100 = 0; //counter 0-3
|
||||
static bool can_bus_alive = false;
|
||||
|
||||
CAN_frame_t LEAF_1F2 = {.FIR = {.B =
|
||||
{
|
||||
|
@ -337,6 +338,7 @@ void update_values_battery() { /* This function maps all the values fetched via
|
|||
void receive_can_battery(CAN_frame_t rx_frame) {
|
||||
switch (rx_frame.MsgID) {
|
||||
case 0x1DB:
|
||||
can_bus_alive = true;
|
||||
if (is_message_corrupt(rx_frame)) {
|
||||
datalayer.battery.status.CAN_error_counter++;
|
||||
break; //Message content malformed, abort reading data from it
|
||||
|
@ -585,189 +587,192 @@ void receive_can_battery(CAN_frame_t rx_frame) {
|
|||
}
|
||||
}
|
||||
void send_can_battery() {
|
||||
unsigned long currentMillis = millis();
|
||||
if (can_bus_alive) {
|
||||
|
||||
//Send 10ms message
|
||||
if (currentMillis - previousMillis10 >= INTERVAL_10_MS) {
|
||||
// Check if sending of CAN messages has been delayed too much.
|
||||
if ((currentMillis - previousMillis10 >= INTERVAL_10_MS_DELAYED) && (currentMillis > BOOTUP_TIME)) {
|
||||
set_event(EVENT_CAN_OVERRUN, (currentMillis - previousMillis10));
|
||||
}
|
||||
previousMillis10 = currentMillis;
|
||||
unsigned long currentMillis = millis();
|
||||
|
||||
switch (mprun10) {
|
||||
case 0:
|
||||
LEAF_1D4.data.u8[4] = 0x07;
|
||||
LEAF_1D4.data.u8[7] = 0x12;
|
||||
break;
|
||||
case 1:
|
||||
LEAF_1D4.data.u8[4] = 0x47;
|
||||
LEAF_1D4.data.u8[7] = 0xD5;
|
||||
break;
|
||||
case 2:
|
||||
LEAF_1D4.data.u8[4] = 0x87;
|
||||
LEAF_1D4.data.u8[7] = 0x19;
|
||||
break;
|
||||
case 3:
|
||||
LEAF_1D4.data.u8[4] = 0xC7;
|
||||
LEAF_1D4.data.u8[7] = 0xDE;
|
||||
break;
|
||||
}
|
||||
ESP32Can.CANWriteFrame(&LEAF_1D4);
|
||||
//Send 10ms message
|
||||
if (currentMillis - previousMillis10 >= INTERVAL_10_MS) {
|
||||
// Check if sending of CAN messages has been delayed too much.
|
||||
if ((currentMillis - previousMillis10 >= INTERVAL_10_MS_DELAYED) && (currentMillis > BOOTUP_TIME)) {
|
||||
set_event(EVENT_CAN_OVERRUN, (currentMillis - previousMillis10));
|
||||
}
|
||||
previousMillis10 = currentMillis;
|
||||
|
||||
switch (mprun10r) {
|
||||
case (0):
|
||||
LEAF_1F2.data.u8[3] = 0xB0;
|
||||
LEAF_1F2.data.u8[6] = 0x00;
|
||||
LEAF_1F2.data.u8[7] = 0x8F;
|
||||
break;
|
||||
case (1):
|
||||
LEAF_1F2.data.u8[6] = 0x01;
|
||||
LEAF_1F2.data.u8[7] = 0x80;
|
||||
break;
|
||||
case (2):
|
||||
LEAF_1F2.data.u8[6] = 0x02;
|
||||
LEAF_1F2.data.u8[7] = 0x81;
|
||||
break;
|
||||
case (3):
|
||||
LEAF_1F2.data.u8[6] = 0x03;
|
||||
LEAF_1F2.data.u8[7] = 0x82;
|
||||
break;
|
||||
case (4):
|
||||
LEAF_1F2.data.u8[6] = 0x00;
|
||||
LEAF_1F2.data.u8[7] = 0x8F;
|
||||
break;
|
||||
case (5): // Set 2
|
||||
LEAF_1F2.data.u8[3] = 0xB4;
|
||||
LEAF_1F2.data.u8[6] = 0x01;
|
||||
LEAF_1F2.data.u8[7] = 0x84;
|
||||
break;
|
||||
case (6):
|
||||
LEAF_1F2.data.u8[6] = 0x02;
|
||||
LEAF_1F2.data.u8[7] = 0x85;
|
||||
break;
|
||||
case (7):
|
||||
LEAF_1F2.data.u8[6] = 0x03;
|
||||
LEAF_1F2.data.u8[7] = 0x86;
|
||||
break;
|
||||
case (8):
|
||||
LEAF_1F2.data.u8[6] = 0x00;
|
||||
LEAF_1F2.data.u8[7] = 0x83;
|
||||
break;
|
||||
case (9):
|
||||
LEAF_1F2.data.u8[6] = 0x01;
|
||||
LEAF_1F2.data.u8[7] = 0x84;
|
||||
break;
|
||||
case (10): // Set 3
|
||||
LEAF_1F2.data.u8[3] = 0xB0;
|
||||
LEAF_1F2.data.u8[6] = 0x02;
|
||||
LEAF_1F2.data.u8[7] = 0x81;
|
||||
break;
|
||||
case (11):
|
||||
LEAF_1F2.data.u8[6] = 0x03;
|
||||
LEAF_1F2.data.u8[7] = 0x82;
|
||||
break;
|
||||
case (12):
|
||||
LEAF_1F2.data.u8[6] = 0x00;
|
||||
LEAF_1F2.data.u8[7] = 0x8F;
|
||||
break;
|
||||
case (13):
|
||||
LEAF_1F2.data.u8[6] = 0x01;
|
||||
LEAF_1F2.data.u8[7] = 0x80;
|
||||
break;
|
||||
case (14):
|
||||
LEAF_1F2.data.u8[6] = 0x02;
|
||||
LEAF_1F2.data.u8[7] = 0x81;
|
||||
break;
|
||||
case (15): // Set 4
|
||||
LEAF_1F2.data.u8[3] = 0xB4;
|
||||
LEAF_1F2.data.u8[6] = 0x03;
|
||||
LEAF_1F2.data.u8[7] = 0x86;
|
||||
break;
|
||||
case (16):
|
||||
LEAF_1F2.data.u8[6] = 0x00;
|
||||
LEAF_1F2.data.u8[7] = 0x83;
|
||||
break;
|
||||
case (17):
|
||||
LEAF_1F2.data.u8[6] = 0x01;
|
||||
LEAF_1F2.data.u8[7] = 0x84;
|
||||
break;
|
||||
case (18):
|
||||
LEAF_1F2.data.u8[6] = 0x02;
|
||||
LEAF_1F2.data.u8[7] = 0x85;
|
||||
break;
|
||||
case (19):
|
||||
LEAF_1F2.data.u8[6] = 0x03;
|
||||
LEAF_1F2.data.u8[7] = 0x86;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
switch (mprun10) {
|
||||
case 0:
|
||||
LEAF_1D4.data.u8[4] = 0x07;
|
||||
LEAF_1D4.data.u8[7] = 0x12;
|
||||
break;
|
||||
case 1:
|
||||
LEAF_1D4.data.u8[4] = 0x47;
|
||||
LEAF_1D4.data.u8[7] = 0xD5;
|
||||
break;
|
||||
case 2:
|
||||
LEAF_1D4.data.u8[4] = 0x87;
|
||||
LEAF_1D4.data.u8[7] = 0x19;
|
||||
break;
|
||||
case 3:
|
||||
LEAF_1D4.data.u8[4] = 0xC7;
|
||||
LEAF_1D4.data.u8[7] = 0xDE;
|
||||
break;
|
||||
}
|
||||
ESP32Can.CANWriteFrame(&LEAF_1D4);
|
||||
|
||||
switch (mprun10r) {
|
||||
case (0):
|
||||
LEAF_1F2.data.u8[3] = 0xB0;
|
||||
LEAF_1F2.data.u8[6] = 0x00;
|
||||
LEAF_1F2.data.u8[7] = 0x8F;
|
||||
break;
|
||||
case (1):
|
||||
LEAF_1F2.data.u8[6] = 0x01;
|
||||
LEAF_1F2.data.u8[7] = 0x80;
|
||||
break;
|
||||
case (2):
|
||||
LEAF_1F2.data.u8[6] = 0x02;
|
||||
LEAF_1F2.data.u8[7] = 0x81;
|
||||
break;
|
||||
case (3):
|
||||
LEAF_1F2.data.u8[6] = 0x03;
|
||||
LEAF_1F2.data.u8[7] = 0x82;
|
||||
break;
|
||||
case (4):
|
||||
LEAF_1F2.data.u8[6] = 0x00;
|
||||
LEAF_1F2.data.u8[7] = 0x8F;
|
||||
break;
|
||||
case (5): // Set 2
|
||||
LEAF_1F2.data.u8[3] = 0xB4;
|
||||
LEAF_1F2.data.u8[6] = 0x01;
|
||||
LEAF_1F2.data.u8[7] = 0x84;
|
||||
break;
|
||||
case (6):
|
||||
LEAF_1F2.data.u8[6] = 0x02;
|
||||
LEAF_1F2.data.u8[7] = 0x85;
|
||||
break;
|
||||
case (7):
|
||||
LEAF_1F2.data.u8[6] = 0x03;
|
||||
LEAF_1F2.data.u8[7] = 0x86;
|
||||
break;
|
||||
case (8):
|
||||
LEAF_1F2.data.u8[6] = 0x00;
|
||||
LEAF_1F2.data.u8[7] = 0x83;
|
||||
break;
|
||||
case (9):
|
||||
LEAF_1F2.data.u8[6] = 0x01;
|
||||
LEAF_1F2.data.u8[7] = 0x84;
|
||||
break;
|
||||
case (10): // Set 3
|
||||
LEAF_1F2.data.u8[3] = 0xB0;
|
||||
LEAF_1F2.data.u8[6] = 0x02;
|
||||
LEAF_1F2.data.u8[7] = 0x81;
|
||||
break;
|
||||
case (11):
|
||||
LEAF_1F2.data.u8[6] = 0x03;
|
||||
LEAF_1F2.data.u8[7] = 0x82;
|
||||
break;
|
||||
case (12):
|
||||
LEAF_1F2.data.u8[6] = 0x00;
|
||||
LEAF_1F2.data.u8[7] = 0x8F;
|
||||
break;
|
||||
case (13):
|
||||
LEAF_1F2.data.u8[6] = 0x01;
|
||||
LEAF_1F2.data.u8[7] = 0x80;
|
||||
break;
|
||||
case (14):
|
||||
LEAF_1F2.data.u8[6] = 0x02;
|
||||
LEAF_1F2.data.u8[7] = 0x81;
|
||||
break;
|
||||
case (15): // Set 4
|
||||
LEAF_1F2.data.u8[3] = 0xB4;
|
||||
LEAF_1F2.data.u8[6] = 0x03;
|
||||
LEAF_1F2.data.u8[7] = 0x86;
|
||||
break;
|
||||
case (16):
|
||||
LEAF_1F2.data.u8[6] = 0x00;
|
||||
LEAF_1F2.data.u8[7] = 0x83;
|
||||
break;
|
||||
case (17):
|
||||
LEAF_1F2.data.u8[6] = 0x01;
|
||||
LEAF_1F2.data.u8[7] = 0x84;
|
||||
break;
|
||||
case (18):
|
||||
LEAF_1F2.data.u8[6] = 0x02;
|
||||
LEAF_1F2.data.u8[7] = 0x85;
|
||||
break;
|
||||
case (19):
|
||||
LEAF_1F2.data.u8[6] = 0x03;
|
||||
LEAF_1F2.data.u8[7] = 0x86;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
//Only send this message when NISSANLEAF_CHARGER is not defined (otherwise it will collide!)
|
||||
#ifndef NISSANLEAF_CHARGER
|
||||
ESP32Can.CANWriteFrame(&LEAF_1F2); //Contains (CHG_STA_RQ == 1 == Normal Charge)
|
||||
ESP32Can.CANWriteFrame(&LEAF_1F2); //Contains (CHG_STA_RQ == 1 == Normal Charge)
|
||||
#endif
|
||||
|
||||
mprun10r = (mprun10r + 1) % 20; // 0x1F2 patter repeats after 20 messages. 0-1..19-0
|
||||
mprun10r = (mprun10r + 1) % 20; // 0x1F2 patter repeats after 20 messages. 0-1..19-0
|
||||
|
||||
mprun10 = (mprun10 + 1) % 4; // mprun10 cycles between 0-1-2-3-0-1...
|
||||
}
|
||||
|
||||
// Send 100ms CAN Message
|
||||
if (currentMillis - previousMillis100 >= INTERVAL_100_MS) {
|
||||
previousMillis100 = currentMillis;
|
||||
|
||||
//When battery requests heating pack status change, ack this
|
||||
if (Batt_Heater_Mail_Send_Request) {
|
||||
LEAF_50B.data.u8[6] = 0x20; //Batt_Heater_Mail_Send_OK
|
||||
} else {
|
||||
LEAF_50B.data.u8[6] = 0x00; //Batt_Heater_Mail_Send_NG
|
||||
mprun10 = (mprun10 + 1) % 4; // mprun10 cycles between 0-1-2-3-0-1...
|
||||
}
|
||||
|
||||
// VCM message, containing info if battery should sleep or stay awake
|
||||
ESP32Can.CANWriteFrame(&LEAF_50B); // HCM_WakeUpSleepCommand == 11b == WakeUp, and CANMASK = 1
|
||||
// Send 100ms CAN Message
|
||||
if (currentMillis - previousMillis100 >= INTERVAL_100_MS) {
|
||||
previousMillis100 = currentMillis;
|
||||
|
||||
LEAF_50C.data.u8[3] = mprun100;
|
||||
switch (mprun100) {
|
||||
case 0:
|
||||
LEAF_50C.data.u8[4] = 0x5D;
|
||||
LEAF_50C.data.u8[5] = 0xC8;
|
||||
break;
|
||||
case 1:
|
||||
LEAF_50C.data.u8[4] = 0xB2;
|
||||
LEAF_50C.data.u8[5] = 0x31;
|
||||
break;
|
||||
case 2:
|
||||
LEAF_50C.data.u8[4] = 0x5D;
|
||||
LEAF_50C.data.u8[5] = 0x63;
|
||||
break;
|
||||
case 3:
|
||||
LEAF_50C.data.u8[4] = 0xB2;
|
||||
LEAF_50C.data.u8[5] = 0x9A;
|
||||
break;
|
||||
}
|
||||
ESP32Can.CANWriteFrame(&LEAF_50C);
|
||||
//When battery requests heating pack status change, ack this
|
||||
if (Batt_Heater_Mail_Send_Request) {
|
||||
LEAF_50B.data.u8[6] = 0x20; //Batt_Heater_Mail_Send_OK
|
||||
} else {
|
||||
LEAF_50B.data.u8[6] = 0x00; //Batt_Heater_Mail_Send_NG
|
||||
}
|
||||
|
||||
mprun100 = (mprun100 + 1) % 4; // mprun100 cycles between 0-1-2-3-0-1...
|
||||
}
|
||||
// VCM message, containing info if battery should sleep or stay awake
|
||||
ESP32Can.CANWriteFrame(&LEAF_50B); // HCM_WakeUpSleepCommand == 11b == WakeUp, and CANMASK = 1
|
||||
|
||||
//Send 10s CAN messages
|
||||
if (currentMillis - previousMillis10s >= INTERVAL_10_S) {
|
||||
previousMillis10s = currentMillis;
|
||||
LEAF_50C.data.u8[3] = mprun100;
|
||||
switch (mprun100) {
|
||||
case 0:
|
||||
LEAF_50C.data.u8[4] = 0x5D;
|
||||
LEAF_50C.data.u8[5] = 0xC8;
|
||||
break;
|
||||
case 1:
|
||||
LEAF_50C.data.u8[4] = 0xB2;
|
||||
LEAF_50C.data.u8[5] = 0x31;
|
||||
break;
|
||||
case 2:
|
||||
LEAF_50C.data.u8[4] = 0x5D;
|
||||
LEAF_50C.data.u8[5] = 0x63;
|
||||
break;
|
||||
case 3:
|
||||
LEAF_50C.data.u8[4] = 0xB2;
|
||||
LEAF_50C.data.u8[5] = 0x9A;
|
||||
break;
|
||||
}
|
||||
ESP32Can.CANWriteFrame(&LEAF_50C);
|
||||
|
||||
//Every 10s, ask diagnostic data from the battery. Don't ask if someone is already polling on the bus (Leafspy?)
|
||||
if (!stop_battery_query) {
|
||||
group = (group == 1) ? 2 : (group == 2) ? 4 : 1;
|
||||
// Cycle between group 1, 2, and 4 using ternary operation
|
||||
LEAF_GROUP_REQUEST.data.u8[2] = group;
|
||||
ESP32Can.CANWriteFrame(&LEAF_GROUP_REQUEST);
|
||||
mprun100 = (mprun100 + 1) % 4; // mprun100 cycles between 0-1-2-3-0-1...
|
||||
}
|
||||
|
||||
if (hold_off_with_polling_10seconds > 0) {
|
||||
hold_off_with_polling_10seconds--;
|
||||
} else {
|
||||
stop_battery_query = false;
|
||||
//Send 10s CAN messages
|
||||
if (currentMillis - previousMillis10s >= INTERVAL_10_S) {
|
||||
previousMillis10s = currentMillis;
|
||||
|
||||
//Every 10s, ask diagnostic data from the battery. Don't ask if someone is already polling on the bus (Leafspy?)
|
||||
if (!stop_battery_query) {
|
||||
group = (group == 1) ? 2 : (group == 2) ? 4 : 1;
|
||||
// Cycle between group 1, 2, and 4 using ternary operation
|
||||
LEAF_GROUP_REQUEST.data.u8[2] = group;
|
||||
ESP32Can.CANWriteFrame(&LEAF_GROUP_REQUEST);
|
||||
}
|
||||
|
||||
if (hold_off_with_polling_10seconds > 0) {
|
||||
hold_off_with_polling_10seconds--;
|
||||
} else {
|
||||
stop_battery_query = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ void handle_static_data_modbus_byd() {
|
|||
}
|
||||
|
||||
void handle_update_data_modbusp201_byd() {
|
||||
mbPV[202] = std::min(datalayer.battery.info.total_capacity_Wh, 60000u); //Cap capacity to 60kWh if needed
|
||||
mbPV[202] = std::min(datalayer.battery.info.total_capacity_Wh, static_cast<uint32_t>(60000u)); //Cap to 60kWh
|
||||
mbPV[205] = (datalayer.battery.info.max_design_voltage_dV); // Max Voltage, if higher Gen24 forces discharge
|
||||
mbPV[206] = (datalayer.battery.info.min_design_voltage_dV); // Min Voltage, if lower Gen24 disables battery
|
||||
}
|
||||
|
@ -83,10 +83,10 @@ void handle_update_data_modbusp301_byd() {
|
|||
mbPV[300] = datalayer.battery.status.bms_status;
|
||||
mbPV[302] = 128 + bms_char_dis_status;
|
||||
mbPV[303] = datalayer.battery.status.reported_soc;
|
||||
mbPV[304] = std::min(datalayer.battery.info.total_capacity_Wh, 60000u); //Cap capacity to 60kWh if needed
|
||||
mbPV[305] = std::min(datalayer.battery.status.remaining_capacity_Wh, 60000u); //Cap capacity to 60kWh if needed
|
||||
mbPV[306] = std::min(max_discharge_W, 30000u); //Cap to 30000 if exceeding
|
||||
mbPV[307] = std::min(max_charge_W, 30000u); //Cap to 30000 if exceeding
|
||||
mbPV[304] = std::min(datalayer.battery.info.total_capacity_Wh, static_cast<uint32_t>(60000u)); //Cap to 60kWh
|
||||
mbPV[305] = std::min(datalayer.battery.status.remaining_capacity_Wh, static_cast<uint32_t>(60000u)); //Cap to 60kWh
|
||||
mbPV[306] = std::min(max_discharge_W, static_cast<uint32_t>(30000u)); //Cap to 30000 if exceeding
|
||||
mbPV[307] = std::min(max_charge_W, static_cast<uint32_t>(30000u)); //Cap to 30000 if exceeding
|
||||
mbPV[310] = datalayer.battery.status.voltage_dV;
|
||||
mbPV[312] = datalayer.battery.status.temperature_min_dC;
|
||||
mbPV[313] = datalayer.battery.status.temperature_max_dC;
|
||||
|
|
|
@ -185,7 +185,7 @@ void AsyncEventSourceClient::_queueMessage(AsyncEventSourceMessage *dataMessage)
|
|||
return;
|
||||
}
|
||||
if(_messageQueue.length() >= SSE_MAX_QUEUED_MESSAGES){
|
||||
ets_printf("ERROR: Too many messages queued\n");
|
||||
//ets_printf("ERROR: Too many messages queued\n");
|
||||
delete dataMessage;
|
||||
} else {
|
||||
_messageQueue.add(dataMessage);
|
||||
|
|
|
@ -548,7 +548,7 @@ void AsyncWebSocketClient::_queueMessage(AsyncWebSocketMessage *dataMessage){
|
|||
return;
|
||||
}
|
||||
if(_messageQueue.length() >= WS_MAX_QUEUED_MESSAGES){
|
||||
ets_printf("ERROR: Too many messages queued\n");
|
||||
//ets_printf("ERROR: Too many messages queued\n");
|
||||
delete dataMessage;
|
||||
} else {
|
||||
_messageQueue.add(dataMessage);
|
||||
|
@ -829,7 +829,7 @@ void AsyncWebSocketClient::binary(AsyncWebSocketMessageBuffer * buffer)
|
|||
|
||||
IPAddress AsyncWebSocketClient::remoteIP() {
|
||||
if(!_client) {
|
||||
return IPAddress(0U);
|
||||
return IPAddress(static_cast<uint32_t>(0U));
|
||||
}
|
||||
return _client->remoteIP();
|
||||
}
|
||||
|
@ -1259,9 +1259,9 @@ AsyncWebSocketResponse::AsyncWebSocketResponse(const String& key, AsyncWebSocket
|
|||
(String&)key += WS_STR_UUID;
|
||||
mbedtls_sha1_context ctx;
|
||||
mbedtls_sha1_init(&ctx);
|
||||
mbedtls_sha1_starts_ret(&ctx);
|
||||
mbedtls_sha1_update_ret(&ctx, (const unsigned char*)key.c_str(), key.length());
|
||||
mbedtls_sha1_finish_ret(&ctx, hash);
|
||||
mbedtls_sha1_starts(&ctx);
|
||||
mbedtls_sha1_update(&ctx, (const unsigned char*)key.c_str(), key.length());
|
||||
mbedtls_sha1_finish(&ctx, hash);
|
||||
mbedtls_sha1_free(&ctx);
|
||||
#endif
|
||||
base64_encodestate _state;
|
||||
|
|
|
@ -71,9 +71,9 @@ static bool getMD5(uint8_t * data, uint16_t len, char * output){//33 bytes or mo
|
|||
memset(_buf, 0x00, 16);
|
||||
#ifdef ESP32
|
||||
mbedtls_md5_init(&_ctx);
|
||||
mbedtls_md5_starts_ret(&_ctx);
|
||||
mbedtls_md5_update_ret(&_ctx, data, len);
|
||||
mbedtls_md5_finish_ret(&_ctx, _buf);
|
||||
mbedtls_md5_starts(&_ctx);
|
||||
mbedtls_md5_update(&_ctx, data, len);
|
||||
mbedtls_md5_finish(&_ctx, _buf);
|
||||
#else
|
||||
MD5Init(&_ctx);
|
||||
MD5Update(&_ctx, data, len);
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/queue.h"
|
||||
|
||||
#include "esp_intr.h"
|
||||
#include "esp_intr_alloc.h" // Renamed when migrating ESP32 2.x -> 3.x
|
||||
#include "soc/dport_reg.h"
|
||||
#include <math.h>
|
||||
|
||||
|
@ -43,6 +43,10 @@
|
|||
#include "can_regdef.h"
|
||||
#include "CAN_config.h"
|
||||
|
||||
#define TWAI_TX_IDX 123 // TODO: Are these OK?
|
||||
// not sure what file is needed now, maybe "soc/gpio_sig_map.h" but using hard coded values for now
|
||||
#define TWAI_RX_IDX 94 // TODO: Are these OK?
|
||||
|
||||
// CAN Filter - no acceptance filter
|
||||
static CAN_filter_t __filter = { Dual_Mode, 0, 0, 0, 0, 0Xff, 0Xff, 0Xff, 0Xff };
|
||||
|
||||
|
@ -177,12 +181,12 @@ int CAN_init() {
|
|||
// configure TX pin
|
||||
gpio_set_level(CAN_cfg.tx_pin_id, 1);
|
||||
gpio_set_direction(CAN_cfg.tx_pin_id, GPIO_MODE_OUTPUT);
|
||||
gpio_matrix_out(CAN_cfg.tx_pin_id, CAN_TX_IDX, 0, 0);
|
||||
gpio_matrix_out(CAN_cfg.tx_pin_id, TWAI_TX_IDX, 0, 0);
|
||||
gpio_pad_select_gpio(CAN_cfg.tx_pin_id);
|
||||
|
||||
// configure RX pin
|
||||
gpio_set_direction(CAN_cfg.rx_pin_id, GPIO_MODE_INPUT);
|
||||
gpio_matrix_in(CAN_cfg.rx_pin_id, CAN_RX_IDX, 0);
|
||||
gpio_matrix_in(CAN_cfg.rx_pin_id, TWAI_RX_IDX, 0);
|
||||
gpio_pad_select_gpio(CAN_cfg.rx_pin_id);
|
||||
|
||||
// set to PELICAN mode
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue