From db11bd8c0fa1857286e9ff2f1799387a7bfed555 Mon Sep 17 00:00:00 2001
From: Alberto Nidasio <alberto.nidasio@skywarder.eu>
Date: Tue, 26 Jul 2022 10:37:45 +0000
Subject: [PATCH] [Pyxis] Updated death stack v2

---
 .../interfaces-impl/bsp.cpp                   | 16 +++----
 .../interfaces-impl/bsp_impl.h                | 19 ++++----
 .../interfaces-impl/hwmapping.h               | 43 +++++++++++--------
 3 files changed, 45 insertions(+), 33 deletions(-)

diff --git a/miosix/arch/cortexM4_stm32f4/stm32f429zi_skyward_death_stack_x/interfaces-impl/bsp.cpp b/miosix/arch/cortexM4_stm32f4/stm32f429zi_skyward_death_stack_x/interfaces-impl/bsp.cpp
index 45beb99b..34eb213a 100644
--- a/miosix/arch/cortexM4_stm32f4/stm32f429zi_skyward_death_stack_x/interfaces-impl/bsp.cpp
+++ b/miosix/arch/cortexM4_stm32f4/stm32f429zi_skyward_death_stack_x/interfaces-impl/bsp.cpp
@@ -376,6 +376,13 @@ void IRQbspInit()
     can::tx::mode(Mode::ALTERNATE);
     can::tx::alternateFunction(9);
 
+    timers::tim4ch1::mode(Mode::ALTERNATE);
+    timers::tim4ch1::alternateFunction(2);
+    timers::tim8ch2::mode(Mode::ALTERNATE);
+    timers::tim8ch2::alternateFunction(3);
+
+    camMosfet::mode(Mode::OUTPUT);
+
     using namespace sensors;
 
     ads1118::cs::mode(Mode::OUTPUT);
@@ -400,14 +407,10 @@ void IRQbspInit()
     using namespace inputs;
 
     vbat::mode(Mode::INPUT_ANALOG);
-    launchpad::mode(Mode::INPUT);
-    nosecone_detach::mode(Mode::INPUT);
     expulsion::mode(Mode::INPUT);
 
     using namespace actuators;
 
-    nosecone::servo::mode(Mode::ALTERNATE);
-    nosecone::servo::alternateFunction(2);
     nosecone::th_cut_input::mode(Mode::OUTPUT);
 
     nosecone::thermal_cutter_1::enable::mode(Mode::OUTPUT);
@@ -418,13 +421,9 @@ void IRQbspInit()
     nosecone::thermal_cutter_2::enable::low();
     nosecone::thermal_cutter_2::cutter_sens::mode(Mode::INPUT_ANALOG);
 
-    airbrakes::servo::mode(Mode::ALTERNATE);
-    airbrakes::servo::alternateFunction(3);
-
     using namespace aux;
 
     sense_aux_1::mode(Mode::INPUT);
-    sense_aux_2::mode(Mode::INPUT);
     aux_pd_pu::mode(Mode::OUTPUT);
     aux_spi1_cs::mode(Mode::OUTPUT);
 
@@ -433,6 +432,7 @@ void IRQbspInit()
     led_red1::mode(Mode::OUTPUT);
     led_red2::mode(Mode::OUTPUT);
     led_blue1::mode(Mode::OUTPUT);
+    led_ring::mode(Mode::OUTPUT);
 
     using namespace xbee;
 
diff --git a/miosix/arch/cortexM4_stm32f4/stm32f429zi_skyward_death_stack_x/interfaces-impl/bsp_impl.h b/miosix/arch/cortexM4_stm32f4/stm32f429zi_skyward_death_stack_x/interfaces-impl/bsp_impl.h
index a2610bfa..bff22d95 100644
--- a/miosix/arch/cortexM4_stm32f4/stm32f429zi_skyward_death_stack_x/interfaces-impl/bsp_impl.h
+++ b/miosix/arch/cortexM4_stm32f4/stm32f429zi_skyward_death_stack_x/interfaces-impl/bsp_impl.h
@@ -23,22 +23,23 @@
  *                                                                         *
  *   You should have received a copy of the GNU General Public License     *
  *   along with this program; if not, see <http://www.gnu.org/licenses/>   *
- ***************************************************************************/ 
+ ***************************************************************************/
 
 /***********************************************************************
-* bsp_impl.h Part of the Miosix Embedded OS.
-* Board support package, this file initializes hardware.
-************************************************************************/
+ * bsp_impl.h Part of the Miosix Embedded OS.
+ * Board support package, this file initializes hardware.
+ ************************************************************************/
 
 #ifndef BSP_IMPL_H
 #define BSP_IMPL_H
 
 #include "config/miosix_settings.h"
-#include "interfaces/gpio.h"
 #include "drivers/stm32_hardware_rng.h"
 #include "hwmapping.h"
+#include "interfaces/gpio.h"
 
-namespace miosix {
+namespace miosix
+{
 
 /**
 \addtogroup Hardware
@@ -60,17 +61,19 @@ void configureSdram();
 inline void ledOn()
 {
     leds::led_blue1::high();
+    leds::led_ring::high();
 }
 
 inline void ledOff()
 {
     leds::led_blue1::low();
+    leds::led_ring::low();
 }
 
 /**
 \}
 */
 
-} //namespace miosix
+}  // namespace miosix
 
-#endif //BSP_IMPL_H
+#endif  // BSP_IMPL_H
diff --git a/miosix/arch/cortexM4_stm32f4/stm32f429zi_skyward_death_stack_x/interfaces-impl/hwmapping.h b/miosix/arch/cortexM4_stm32f4/stm32f429zi_skyward_death_stack_x/interfaces-impl/hwmapping.h
index 538693af..c191b138 100644
--- a/miosix/arch/cortexM4_stm32f4/stm32f429zi_skyward_death_stack_x/interfaces-impl/hwmapping.h
+++ b/miosix/arch/cortexM4_stm32f4/stm32f429zi_skyward_death_stack_x/interfaces-impl/hwmapping.h
@@ -76,12 +76,22 @@ using tx = Gpio<GPIOA_BASE, 0>;
 using rx = Gpio<GPIOA_BASE, 1>;
 }  // namespace uart4
 
+// CAN1
 namespace can
-{  // CAN1
+{
 using rx = Gpio<GPIOA_BASE, 11>;
 using tx = Gpio<GPIOA_BASE, 12>;
 }  // namespace can
 
+// Servo motors timers
+namespace timers
+{
+using tim4ch1 = Gpio<GPIOD_BASE, 12>;  // Servo 1
+using tim8ch2 = Gpio<GPIOC_BASE, 7>;   // Servo 2
+}  // namespace timers
+
+using camMosfet = Gpio<GPIOC_BASE, 14>;
+
 }  // namespace interfaces
 
 namespace sensors
@@ -119,19 +129,23 @@ using cs = Gpio<GPIOD_BASE, 7>;
 
 namespace inputs
 {
-using vbat            = Gpio<GPIOF_BASE, 7>;
-using launchpad       = Gpio<GPIOE_BASE, 4>;   // launchpad detach
-using nosecone_detach = Gpio<GPIOC_BASE, 14>;  // nosecone detach
-using expulsion       = Gpio<GPIOB_BASE, 7>;   // expulsion sensor
+using vbat      = Gpio<GPIOF_BASE, 7>;
+using expulsion = Gpio<GPIOE_BASE, 4>;
 }  // namespace inputs
 
 namespace actuators
 {
 
+namespace servos
+{
+using servo1 = interfaces::timers::tim4ch1;
+using servo2 = interfaces::timers::tim8ch2;
+}  // namespace servos
+
 namespace nosecone
 {
-using servo        = Gpio<GPIOD_BASE, 12>;  // Pwm expulsion servo, TIM4_CH1
-using th_cut_input = Gpio<GPIOE_BASE, 6>;   // Input thermal cutters
+
+using th_cut_input = Gpio<GPIOE_BASE, 6>;  // Input thermal cutters
 
 namespace thermal_cutter_1
 {
@@ -147,17 +161,11 @@ using cutter_sens = Gpio<GPIOF_BASE, 8>;  // ADC3 CH6
 
 }  // namespace nosecone
 
-namespace airbrakes
-{
-using servo = Gpio<GPIOC_BASE, 7>;  // Airbrakes PWM, TIM8_CH2
-}  // namespace airbrakes
-
 }  // namespace actuators
 
 namespace aux
 {
 using sense_aux_1 = Gpio<GPIOE_BASE, 2>;
-using sense_aux_2 = Gpio<GPIOE_BASE, 3>;
 using aux_pd_pu   = Gpio<GPIOC_BASE, 5>;
 using aux_spi1_cs = Gpio<GPIOG_BASE, 7>;
 }  // namespace aux
@@ -167,14 +175,15 @@ namespace leds
 using led_red1  = Gpio<GPIOG_BASE, 7>;
 using led_red2  = Gpio<GPIOG_BASE, 10>;
 using led_blue1 = Gpio<GPIOG_BASE, 14>;
+using led_ring  = Gpio<GPIOE_BASE, 3>;
 
 /**
- * These are conencted to the enable pin of the thermal cutters and the cs of
+ * These are connected to the enable pin of the thermal cutters and the cs of
  * the lis3mdl magnetometer.
  */
-using led_blue2  = Gpio<GPIOG_BASE, 2>;
-using led_green1 = Gpio<GPIOG_BASE, 6>;
-using led_green2 = Gpio<GPIOD_BASE, 11>;
+// using led_blue2  = Gpio<GPIOG_BASE, 2>;
+// using led_green1 = Gpio<GPIOG_BASE, 6>;
+// using led_green2 = Gpio<GPIOD_BASE, 11>;
 }  // namespace leds
 
 namespace xbee
-- 
GitLab