diff --git a/CMakeLists.txt b/CMakeLists.txt index 261b1d4..ea01580 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,6 +49,7 @@ add_executable(skl_tunnel radio/src/radio_gpio.c radio/src/radio_hw_instance.cpp + app/src/app_logging.cpp main.cpp ) @@ -74,7 +75,7 @@ target_include_directories(skl_tunnel CMSIS/Core/Include samd21a/include radio/include - skullc_interface/include + app/include ) target_link_libraries(skl_tunnel diff --git a/app/include/app_logging.hpp b/app/include/app_logging.hpp new file mode 100644 index 0000000..f65a993 --- /dev/null +++ b/app/include/app_logging.hpp @@ -0,0 +1,15 @@ +// +// Created by erki on 28.06.22. +// + +#ifndef SKL_TUNNEL_APP_LOGGING_HPP +#define SKL_TUNNEL_APP_LOGGING_HPP + +namespace App::Logging +{ + +void setup(); + +} + +#endif //SKL_TUNNEL_APP_LOGGING_HPP diff --git a/skullc_interface/include/samd21_hal.hpp b/app/include/skullc_samd21_hal.hpp similarity index 83% rename from skullc_interface/include/samd21_hal.hpp rename to app/include/skullc_samd21_hal.hpp index dfce182..3963f3e 100644 --- a/skullc_interface/include/samd21_hal.hpp +++ b/app/include/skullc_samd21_hal.hpp @@ -2,8 +2,8 @@ // Created by erki on 26.06.22. // -#ifndef SKL_TUNNEL_SAMD21_HAL_HPP -#define SKL_TUNNEL_SAMD21_HAL_HPP +#ifndef SKL_TUNNEL_SKULLC_SAMD21_HAL_HPP +#define SKL_TUNNEL_SKULLC_SAMD21_HAL_HPP #include #include @@ -107,17 +107,25 @@ struct SerialInterfaceAsync void registerRxCallback(Utility::IFunction* rx_cb) { assert(rx_cb); - m_rx_cb = rx_cb; - handle_wrapper::registerRxCallback(handle, m_rx_cb->template toStaticFunction()); + handle_wrapper::registerRxCallback(handle, rx_cb->template toStaticFunction()); + } + + void registerRxCallback(Detail::async_io_callback rx_cb) + { + handle_wrapper::registerRxCallback(handle, rx_cb); } void registerTxCallback(Utility::IFunction* tx_cb) { assert(tx_cb); - m_tx_cb = tx_cb; - handle_wrapper::registerRxCallback(handle, m_tx_cb->template toStaticFunction()); + handle_wrapper::registerTxCallback(handle, tx_cb->template toStaticFunction()); + } + + void registerTxCallback(Detail::async_io_callback tx_cb) + { + handle_wrapper::registerTxCallback(handle, tx_cb); } bool transmit(std::uint8_t* data, const std::uint32_t data_len) @@ -145,14 +153,10 @@ struct SerialInterfaceAsync return receive(reinterpret_cast(array.data()), std::uint32_t(N)); } - -private: - Utility::IFunction* m_rx_cb = nullptr; - Utility::IFunction* m_tx_cb = nullptr; }; } } } -#endif //SKL_TUNNEL_SAMD21_HAL_HPP +#endif //SKL_TUNNEL_SKULLC_SAMD21_HAL_HPP diff --git a/app/src/app_logging.cpp b/app/src/app_logging.cpp new file mode 100644 index 0000000..09257a1 --- /dev/null +++ b/app/src/app_logging.cpp @@ -0,0 +1,43 @@ +// +// Created by erki on 28.06.22. +// + +#include "app_logging.hpp" + +#include "driver_init.h" + +#include +#include +#include + +#include "skullc_samd21_hal.hpp" + +namespace Hal = Peripherals::Hal::Samd; + +using Logger = Utility::AsyncLogger, Hal::StaticHal, 5, 255>; + +namespace +{ + +Utility::StaticPointer m_logger; + +void m_txCompleteCb(const usart_async_descriptor* const) +{ + m_logger->txCompleteCallback(); +} + +} + +namespace App::Logging +{ + +void setup() +{ + Hal::SerialInterfaceAsync usart0{&USART_0}; + usart0.registerTxCallback(m_txCompleteCb); + + m_logger.setup(usart0); + Utility::setLogger(*m_logger); +} + +} diff --git a/main.cpp b/main.cpp index 2799dab..3857541 100644 --- a/main.cpp +++ b/main.cpp @@ -1,22 +1,16 @@ #include -#include - -#include -#include +#include #include "radio_hw_instance.hpp" +#include "app_logging.hpp" +#include "skullc_samd21_hal.hpp" + +namespace Hal = Peripherals::Hal::Samd; namespace { -volatile bool can_send_uart = true; - -void tx_cb_USART_0(const struct usart_async_descriptor* const io_descr) -{ - can_send_uart = true; -} - } int main(void) @@ -26,18 +20,7 @@ int main(void) gpio_set_pin_level(OUT_LED_TX, false); - struct io_descriptor* usart_io = NULL; - - Utility::Function callback{tx_cb_USART_0}; - Peripherals::Hal::Samd::SerialInterfaceAsync usart0{&USART_0}; - - usart0.registerTxCallback(&callback); - -#if 0 - usart_async_register_callback(&USART_0, USART_ASYNC_TXC_CB, tx_cb_USART_0); - usart_async_get_io_descriptor(&USART_0, &usart_io); - usart_async_enable(&USART_0); -#endif + App::Logging::setup(); radio::HwInstance* radio_hw = radio::HwInstance::create_instance(); @@ -46,20 +29,11 @@ int main(void) { gpio_toggle_pin_level(OUT_LED_RX); - uint8_t uart_data[12] = { 0 }; + const int16_t radio_num = radio_hw->register_read(0x1C); - if (can_send_uart) - { - can_send_uart = false; - const int16_t radio_num = radio_hw->register_read(0x1C); + SKULLC_LOG_INFO("Reg 0x1C: %d", radio_num); - std::sprintf((char*)uart_data, "%d\n\r", radio_num); - usart0.transmit(uart_data, 12); -#if 0 - io_write(usart_io, uart_data, 12); -#endif - gpio_toggle_pin_level(OUT_LED_TX); - } + gpio_toggle_pin_level(OUT_LED_TX); delay_ms(1000); }