Started work on using TWAI instead of external CAN bus
This commit is contained in:
parent
2a727b66b0
commit
4bb95d2208
|
@ -1,3 +1,3 @@
|
|||
idf_component_register(SRCS "src/main.cpp" "src/helper.cpp" "src/wav.cpp" "src/storage.cpp" "src/i2s.cpp" "src/bluetooth.cpp" "src/avrcp.cpp" "src/a2dp.cpp" "src/can.cpp"
|
||||
idf_component_register(SRCS "src/main.cpp" "src/helper.cpp" "src/wav.cpp" "src/storage.cpp" "src/i2s.cpp" "src/bluetooth.cpp" "src/avrcp.cpp" "src/a2dp.cpp" "src/can.cpp" "src/twai.cpp"
|
||||
INCLUDE_DIRS "include"
|
||||
EMBED_FILES "assets/connect.wav" "assets/disconnect.wav")
|
||||
|
|
6
software/main/include/twai.h
Normal file
6
software/main/include/twai.h
Normal file
|
@ -0,0 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
namespace twai {
|
||||
void init();
|
||||
}
|
||||
|
|
@ -12,6 +12,7 @@
|
|||
#include "avrcp.h"
|
||||
#include "a2dp.h"
|
||||
#include "can.h"
|
||||
#include "twai.h"
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
|
@ -22,11 +23,12 @@ void task(void*) {
|
|||
for (;;) {
|
||||
vTaskDelay(5000 / portTICK_PERIOD_MS);
|
||||
|
||||
static uint8_t volume = 0;
|
||||
volume = (volume + 1) % 31;
|
||||
|
||||
ESP_LOGI(APP_TAG, "Emulation radio with volume: %i", volume);
|
||||
avrcp::set_volume(ceil(volume * 4.2f));
|
||||
avrcp::seek_forward();
|
||||
avrcp::seek_forward();
|
||||
avrcp::seek_forward();
|
||||
avrcp::seek_forward();
|
||||
avrcp::seek_forward();
|
||||
avrcp::seek_forward();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -45,6 +47,7 @@ extern "C" void app_main() {
|
|||
|
||||
/* xTaskCreate(task, "Task", 2048, nullptr, 0, nullptr); */
|
||||
|
||||
can::init();
|
||||
/* can::init(); */
|
||||
twai::init();
|
||||
}
|
||||
|
||||
|
|
49
software/main/src/twai.cpp
Normal file
49
software/main/src/twai.cpp
Normal file
|
@ -0,0 +1,49 @@
|
|||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "driver/twai.h"
|
||||
|
||||
#include "esp_log.h"
|
||||
#include "twai.h"
|
||||
|
||||
#define TWAI_TAG "APP_TWAI"
|
||||
|
||||
static void listen(void*) {
|
||||
for (;;) {
|
||||
twai_message_t message;
|
||||
if (twai_receive(&message, portMAX_DELAY) == ESP_OK) {
|
||||
ESP_LOGI(TWAI_TAG, "Message received");
|
||||
} else {
|
||||
ESP_LOGI(TWAI_TAG, "Failed to receive message");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (message.extd) {
|
||||
ESP_LOGI(TWAI_TAG, "Message is in Extended Format");
|
||||
} else {
|
||||
ESP_LOGI(TWAI_TAG, "Message is in Standard Format");
|
||||
}
|
||||
|
||||
ESP_LOGI(TWAI_TAG, "ID=%d, Length=%d", message.identifier, message.data_length_code);
|
||||
}
|
||||
}
|
||||
|
||||
void twai::init() {
|
||||
twai_general_config_t g_config = TWAI_GENERAL_CONFIG_DEFAULT(GPIO_NUM_5, GPIO_NUM_19, TWAI_MODE_LISTEN_ONLY);
|
||||
twai_timing_config_t t_config = TWAI_TIMING_CONFIG_125KBITS();
|
||||
twai_filter_config_t f_config = TWAI_FILTER_CONFIG_ACCEPT_ALL();
|
||||
|
||||
if (twai_driver_install(&g_config, &t_config, &f_config) == ESP_OK) {
|
||||
ESP_LOGI(TWAI_TAG, "Driver installed");
|
||||
} else {
|
||||
ESP_LOGI(TWAI_TAG, "Failed to install the driver");
|
||||
return;
|
||||
}
|
||||
|
||||
if (twai_start() == ESP_OK) {
|
||||
ESP_LOGI(TWAI_TAG, "Driver started");
|
||||
} else {
|
||||
ESP_LOGI(TWAI_TAG, "Failed to start driver");
|
||||
}
|
||||
|
||||
xTaskCreate(listen, "TWAI Listener", 2048, nullptr, 0, nullptr);
|
||||
}
|
Loading…
Reference in New Issue
Block a user