Remove new-ing from radio instance handling
This commit is contained in:
parent
798d529b20
commit
94368b458a
20
main.cpp
20
main.cpp
@ -1,6 +1,7 @@
|
||||
#include <atmel_start.h>
|
||||
|
||||
#include <utility_logging.hpp>
|
||||
#include <utility_assert.hpp>
|
||||
|
||||
#include "radio_hw_instance.hpp"
|
||||
#include "app_logging.hpp"
|
||||
@ -11,25 +12,36 @@ namespace Hal = Peripherals::Hal::Samd;
|
||||
namespace
|
||||
{
|
||||
|
||||
[[noreturn]] void m_faultHandler(const char* file, const int line)
|
||||
{
|
||||
SKULLC_LOG_FATAL("Fault: %s:%d", file, line);
|
||||
|
||||
__asm__("BKPT");
|
||||
|
||||
while (true);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
/* Initializes MCU, drivers and middleware */
|
||||
atmel_start_init();
|
||||
|
||||
Utility::Assert::setHandler(m_faultHandler);
|
||||
|
||||
gpio_set_pin_level(OUT_LED_TX, false);
|
||||
|
||||
App::Logging::setup();
|
||||
|
||||
radio::HwInstance* radio_hw = radio::HwInstance::create_instance();
|
||||
radio::HwInstance radio_hw;
|
||||
|
||||
/* Replace with your application code */
|
||||
while (1)
|
||||
while (true)
|
||||
{
|
||||
gpio_toggle_pin_level(OUT_LED_RX);
|
||||
|
||||
const int16_t radio_num = radio_hw->register_read(0x1C);
|
||||
const int16_t radio_num = radio_hw.register_read(0x1C);
|
||||
|
||||
SKULLC_LOG_INFO("Reg 0x1C: %d", radio_num);
|
||||
|
||||
|
||||
@ -12,7 +12,11 @@ namespace radio
|
||||
|
||||
struct HwInstance
|
||||
{
|
||||
static HwInstance* create_instance();
|
||||
HwInstance();
|
||||
HwInstance(const HwInstance&) = delete;
|
||||
HwInstance(HwInstance&&) = delete;
|
||||
HwInstance& operator=(const HwInstance&) = delete;
|
||||
HwInstance& operator=(HwInstance&&) = delete;
|
||||
|
||||
void irq_handler();
|
||||
|
||||
@ -21,8 +25,6 @@ struct HwInstance
|
||||
private:
|
||||
spi_m_sync_descriptor* m_spi = nullptr;
|
||||
io_descriptor* m_spi_io = nullptr;
|
||||
|
||||
HwInstance();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -10,6 +10,7 @@
|
||||
|
||||
#include <hal_delay.h>
|
||||
#include <hal_ext_irq.h>
|
||||
#include <utility_assert.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
@ -39,9 +40,19 @@ void _startup()
|
||||
namespace radio
|
||||
{
|
||||
|
||||
HwInstance* HwInstance::create_instance()
|
||||
HwInstance::HwInstance()
|
||||
{
|
||||
return new HwInstance{};
|
||||
SKULLC_ASSERT_SAFE(!_INSTANCE);
|
||||
|
||||
radio_gpio_init();
|
||||
|
||||
m_spi = radio_spi_init();
|
||||
spi_m_sync_get_io_descriptor(m_spi, &m_spi_io);
|
||||
spi_m_sync_enable(m_spi);
|
||||
|
||||
_INSTANCE = this;
|
||||
|
||||
_startup();
|
||||
}
|
||||
|
||||
void HwInstance::irq_handler()
|
||||
@ -78,15 +89,4 @@ void HwInstance::register_write(const uint8_t address, const uint8_t value)
|
||||
gpio_set_pin_level(OUT_RADIO_CS, true);
|
||||
}
|
||||
|
||||
HwInstance::HwInstance()
|
||||
{
|
||||
radio_gpio_init();
|
||||
|
||||
m_spi = radio_spi_init();
|
||||
spi_m_sync_get_io_descriptor(m_spi, &m_spi_io);
|
||||
spi_m_sync_enable(m_spi);
|
||||
|
||||
_startup();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user