diff --git a/software/main/CMakeLists.txt b/software/main/CMakeLists.txt index 5eef017..a2edbd5 100644 --- a/software/main/CMakeLists.txt +++ b/software/main/CMakeLists.txt @@ -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") diff --git a/software/main/include/twai.h b/software/main/include/twai.h new file mode 100644 index 0000000..fd6462c --- /dev/null +++ b/software/main/include/twai.h @@ -0,0 +1,6 @@ +#pragma once + +namespace twai { + void init(); +} + diff --git a/software/main/src/main.cpp b/software/main/src/main.cpp index d67ef7d..1581a5c 100644 --- a/software/main/src/main.cpp +++ b/software/main/src/main.cpp @@ -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(); } diff --git a/software/main/src/twai.cpp b/software/main/src/twai.cpp new file mode 100644 index 0000000..7941064 --- /dev/null +++ b/software/main/src/twai.cpp @@ -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); +}