From 729ce9fa727464bc3bddebc73796edc07753f4ed Mon Sep 17 00:00:00 2001 From: Matteo Pignataro <matteo.pignataro@skywarder.eu> Date: Mon, 20 Feb 2023 11:16:10 +0100 Subject: [PATCH] [RIG] Added relays and radio --- .../interfaces-impl/bsp.cpp | 30 +++ .../interfaces-impl/hwmapping.h | 233 +++++++++++------- 2 files changed, 168 insertions(+), 95 deletions(-) diff --git a/miosix/arch/cortexM4_stm32f4/stm32f429zi_skyward_rig/interfaces-impl/bsp.cpp b/miosix/arch/cortexM4_stm32f4/stm32f429zi_skyward_rig/interfaces-impl/bsp.cpp index 62ef208b..f8736729 100644 --- a/miosix/arch/cortexM4_stm32f4/stm32f429zi_skyward_rig/interfaces-impl/bsp.cpp +++ b/miosix/arch/cortexM4_stm32f4/stm32f429zi_skyward_rig/interfaces-impl/bsp.cpp @@ -200,6 +200,7 @@ namespace miosix #endif //__ENABLE_XRAM RCC->APB2ENR |= RCC_APB2ENR_SPI1EN; + RCC->APB1ENR |= RCC_APB1ENR_SPI2EN; RCC->APB2ENR |= RCC_APB2ENR_SPI4EN; RCC->APB2ENR |= RCC_APB2ENR_SPI5EN; RCC->APB2ENR |= RCC_APB2ENR_SPI6EN; @@ -225,6 +226,13 @@ namespace miosix spi1::mosi::mode(Mode::ALTERNATE); spi1::mosi::alternateFunction(5); + spi2::sck::mode(Mode::ALTERNATE); + spi2::sck::alternateFunction(5); + spi2::miso::mode(Mode::ALTERNATE); + spi2::miso::alternateFunction(5); + spi2::mosi::mode(Mode::ALTERNATE); + spi2::mosi::alternateFunction(5); + spi4::sck::mode(Mode::ALTERNATE); spi4::sck::alternateFunction(5); spi4::miso::mode(Mode::ALTERNATE); @@ -273,6 +281,28 @@ namespace miosix MAX31855::cs::mode(Mode::OUTPUT); MAX31855::cs::high(); + using namespace relays; + relay1::mode(Mode::OUTPUT); + relay2::mode(Mode::OUTPUT); + relay3::mode(Mode::OUTPUT); + relay4::mode(Mode::OUTPUT); + + relay1::high(); + relay2::high(); + relay3::high(); + relay4::high(); + + using namespace radio; + cs::mode(Mode::OUTPUT); + dio0::mode(Mode::INPUT_PULL_UP); + dio1::mode(Mode::INPUT_PULL_UP); + dio3::mode(Mode::INPUT_PULL_UP); + txEn::mode(Mode::OUTPUT); + rxEn::mode(Mode::OUTPUT); + nrst::mode(Mode::OUTPUT); + + //TODO define default configs + using namespace ui; button::mode(Mode::INPUT); diff --git a/miosix/arch/cortexM4_stm32f4/stm32f429zi_skyward_rig/interfaces-impl/hwmapping.h b/miosix/arch/cortexM4_stm32f4/stm32f429zi_skyward_rig/interfaces-impl/hwmapping.h index b47729c2..09cf4ed7 100644 --- a/miosix/arch/cortexM4_stm32f4/stm32f429zi_skyward_rig/interfaces-impl/hwmapping.h +++ b/miosix/arch/cortexM4_stm32f4/stm32f429zi_skyward_rig/interfaces-impl/hwmapping.h @@ -32,98 +32,141 @@ namespace miosix { - namespace interfaces - { - - namespace spi1 - { - using sck = Gpio<GPIOA_BASE, 5>; - using miso = Gpio<GPIOA_BASE, 6>; - using mosi = Gpio<GPIOA_BASE, 7>; - } // namespace spi1 - - namespace spi4 - { - using sck = Gpio<GPIOE_BASE, 2>; - using miso = Gpio<GPIOE_BASE, 5>; - using mosi = Gpio<GPIOE_BASE, 6>; - } // namespace spi4 - - namespace spi5 - { - using sck = Gpio<GPIOF_BASE, 7>; - using miso = Gpio<GPIOF_BASE, 8>; - using mosi = Gpio<GPIOF_BASE, 9>; - } // namespace spi5 - - namespace spi6 - { - using sck = Gpio<GPIOG_BASE, 13>; - using miso = Gpio<GPIOG_BASE, 12>; - using mosi = Gpio<GPIOG_BASE, 14>; - } // namespace spi6 - - // USB UART - namespace uart1 - { - using tx = Gpio<GPIOA_BASE, 9>; - using rx = Gpio<GPIOA_BASE, 10>; - } // namespace uart1 - - namespace timers - { - using tim4ch2 = Gpio<GPIOB_BASE, 7>; // Servo 1 - using tim11ch1 = Gpio<GPIOB_BASE, 9>; // Servo 2 - using tim3ch1 = Gpio<GPIOB_BASE, 4>; // Servo 3 - using tim10ch1 = Gpio<GPIOB_BASE, 8>; // Servo 4 - using tim9ch2 = Gpio<GPIOE_BASE, 6>; // Servo 5 - } // namespace timers - - } // namespace interfaces - - namespace sensors - { - - namespace ADS131_1 - { - using cs = Gpio<GPIOB_BASE, 1>; - using sck = interfaces::spi1::sck; - using miso = interfaces::spi1::miso; - using mosi = interfaces::spi1::mosi; - } - - namespace ADS131_2 - { - using cs = Gpio<GPIOA_BASE, 4>; - using sck = interfaces::spi1::sck; - using miso = interfaces::spi1::miso; - using mosi = interfaces::spi1::mosi; - } - - namespace MAX31855 - { - using cs = Gpio<GPIOF_BASE, 9>; - using sck = interfaces::spi1::sck; - using miso = interfaces::spi1::miso; - using mosi = interfaces::spi1::mosi; - } - - } // namespace sensors - - namespace servos - { - using servo1 = interfaces::timers::tim4ch2; - using servo2 = interfaces::timers::tim11ch1; - using servo3 = interfaces::timers::tim3ch1; - using servo4 = interfaces::timers::tim10ch1; - using servo5 = interfaces::timers::tim9ch2; - } // namespace servos - - namespace ui - { - using button = Gpio<GPIOA_BASE, 0>; // User button - using greenLed = Gpio<GPIOG_BASE, 13>; // Green LED - using redLed = Gpio<GPIOG_BASE, 14>; // Red LED - } // namespace ui - -} // namespace miosix +namespace interfaces +{ + +namespace spi1 +{ +using sck = Gpio<GPIOA_BASE, 5>; +using miso = Gpio<GPIOA_BASE, 6>; +using mosi = Gpio<GPIOA_BASE, 7>; +} // namespace spi1 + +namespace spi2 +{ +using sck = Gpio<GPIOD_BASE, 3>; +using miso = Gpio<GPIOC_BASE, 2>; +using mosi = Gpio<GPIOC_BASE, 3>; +} // namespace spi2 + +namespace spi4 +{ +using sck = Gpio<GPIOE_BASE, 2>; +using miso = Gpio<GPIOE_BASE, 5>; +using mosi = Gpio<GPIOE_BASE, 6>; +} // namespace spi4 + +namespace spi5 +{ +using sck = Gpio<GPIOF_BASE, 7>; +using miso = Gpio<GPIOF_BASE, 8>; +using mosi = Gpio<GPIOF_BASE, 9>; +} // namespace spi5 + +namespace spi6 +{ +using sck = Gpio<GPIOG_BASE, 13>; +using miso = Gpio<GPIOG_BASE, 12>; +using mosi = Gpio<GPIOG_BASE, 14>; +} // namespace spi6 + +// USB UART +namespace uart1 +{ +using tx = Gpio<GPIOA_BASE, 9>; +using rx = Gpio<GPIOA_BASE, 10>; +} // namespace uart1 + +namespace timers +{ +using tim4ch2 = Gpio<GPIOB_BASE, 7>; // Servo 1 +using tim11ch1 = Gpio<GPIOB_BASE, 9>; // Servo 2 +using tim3ch1 = Gpio<GPIOB_BASE, 4>; // Servo 3 +using tim10ch1 = Gpio<GPIOB_BASE, 8>; // Servo 4 +using tim9ch2 = Gpio<GPIOE_BASE, 6>; // Servo 5 +} // namespace timers + +} // namespace interfaces + +namespace sensors +{ + +namespace ADS131_1 +{ +using cs = Gpio<GPIOB_BASE, 1>; +using sck = interfaces::spi1::sck; +using miso = interfaces::spi1::miso; +using mosi = interfaces::spi1::mosi; +} // namespace ADS131_1 + +namespace ADS131_2 +{ +using cs = Gpio<GPIOE_BASE, 4>; +using sck = interfaces::spi1::sck; +using miso = interfaces::spi1::miso; +using mosi = interfaces::spi1::mosi; +} // namespace ADS131_2 + +namespace MAX31855 +{ +using cs = Gpio<GPIOF_BASE, 9>; +using sck = interfaces::spi1::sck; +using miso = interfaces::spi1::miso; +using mosi = interfaces::spi1::mosi; +} // namespace MAX31855 + +namespace HX711_1 +{ +using sck = interfaces::spi2::sck; +} +namespace HX711_2 +{ +using sck = interfaces::spi6::sck; +} + +namespace HX711_3 +{ +using sck = interfaces::spi4::sck; +} + +} // namespace sensors + +namespace servos +{ +using servo1 = interfaces::timers::tim4ch2; +using servo2 = interfaces::timers::tim11ch1; +using servo3 = interfaces::timers::tim3ch1; +using servo4 = interfaces::timers::tim10ch1; +using servo5 = interfaces::timers::tim9ch2; +} // namespace servos + +namespace relays +{ +using relay1 = Gpio<GPIOC_BASE, 14>; // Ignition +using relay2 = Gpio<GPIOE_BASE, 3>; // Faro LED +using relay3 = Gpio<GPIOC_BASE, 13>; // Nitrogen +using relay4 = Gpio<GPIOA_BASE, 15>; +} // namespace relays + +namespace radio +{ +using cs = Gpio<GPIOF_BASE, 6>; +using sck = interfaces::spi1::sck; +using miso = interfaces::spi1::miso; +using mosi = interfaces::spi1::mosi; +using dio0 = Gpio<GPIOD_BASE, 11>; +using dio1 = Gpio<GPIOD_BASE, 12>; +using dio3 = Gpio<GPIOD_BASE, 13>; +using txEn = Gpio<GPIOG_BASE, 2>; +using rxEn = Gpio<GPIOG_BASE, 3>; +using nrst = Gpio<GPIOB_BASE, 0>; +} // namespace radio + +namespace ui +{ +using button = Gpio<GPIOA_BASE, 0>; // User button +using greenLed = Gpio<GPIOG_BASE, 13>; // Green LED +using redLed = Gpio<GPIOG_BASE, 14>; // Red LED +} // namespace ui + +} // namespace miosix -- GitLab