diff --git a/src/entrypoints/anakin-demo-board.cpp b/src/entrypoints/anakin-demo-board.cpp index 6333b1fa100dd3c54f8a540dde3e0c3bfefed56c..7ee1603c436d6c5733e922439ad52f189a0487b7 100644 --- a/src/entrypoints/anakin-demo-board.cpp +++ b/src/entrypoints/anakin-demo-board.cpp @@ -352,7 +352,6 @@ int main() { int ignore_ctr = 100; int led_status = 0x200; - Leds::init(); while(1) { sDemoBoard->update(); Thread::sleep(20); diff --git a/src/entrypoints/anakin-test-dma.cpp b/src/entrypoints/anakin-test-dma.cpp index 8242bfaee52a0918ea52c037d6348866f1c19ac4..820023085ebb0e78fea33f1f2e85179c9b067d89 100644 --- a/src/entrypoints/anakin-test-dma.cpp +++ b/src/entrypoints/anakin-test-dma.cpp @@ -60,7 +60,6 @@ void fifoQueueSz(void *arg) int main() { printf("\n"); - Leds::init(); Leds::set(0); Log::getInstance(); sBoard->init(); diff --git a/src/shared/Leds.cpp b/src/shared/Leds.cpp index c05ea860bb080ace7ff16633c1362cda316c991c..7141a4f69360413c4c17eb93938c5710fc7cd5c9 100644 --- a/src/shared/Leds.cpp +++ b/src/shared/Leds.cpp @@ -1,5 +1,5 @@ /* Copyright (c) 2016-2017 Skyward Experimental Rocketry - * Authors: Alain Carlucci + * Authors: Alain Carlucci, Federico Terraneo * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -22,4 +22,10 @@ #include "Leds.h" -std::vector<GpioPin> Leds::pins; +//Relying on the BSP to provide leds and configure them as output +#define LED(x) miosix::leds::led##x::getPin() +std::array<miosix::GpioPin,Leds::numLeds> Leds::pins{{ + LED(0), LED(1), LED(2), LED(3), LED(4), + LED(5), LED(6), LED(7), LED(8), LED(9) +}}; +#undef LED diff --git a/src/shared/Leds.h b/src/shared/Leds.h index e2d841c25c66babe02056a4fea91e7377f756854..fc69af1651668f1d6777cd18320619413836b39d 100644 --- a/src/shared/Leds.h +++ b/src/shared/Leds.h @@ -1,5 +1,5 @@ /* Copyright (c) 2016 Skyward Experimental Rocketry - * Authors: Alain Carlucci, Matteo Michele Piazzolla + * Authors: Alain Carlucci, Matteo Michele Piazzolla, Federico Terraneo * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -24,22 +24,23 @@ #define LEDS_H #include <Common.h> +#include <array> -using namespace std; -using namespace miosix; class Leds { public: - - /** Every bit of the param leds is the value for the n-th led. - * For example leds = 0x201 means (only) first and last led on. + /** + * Turn on/off all leds using a bitmask + * \param leds bitmask specifing which led has to be turned on */ static void set(uint16_t leds) { for(int i=0;i<10;i++) set(i, (leds & (1 << i)) != 0); } - /** Param id should be in range [0,10). */ - static void set(uint8_t id, bool enable) { + /** + * \param id should be in range [0,10). + */ + static void set(uint8_t id, bool enable) { if(id >= pins.size()) return; @@ -49,21 +50,13 @@ public: pins[id].low(); } - /** Call this function on board startup, before the first set() call. */ - inline static void init() { - #define PIN(x,y) Gpio<GPIO##x##_BASE, y>::getPin() - pins = { - PIN(B, 0), PIN(A,15), PIN(B, 4), PIN(C, 4), PIN(C, 5), - PIN(F, 6), PIN(D, 3), PIN(D, 4), PIN(G, 2), PIN(G, 3) - }; - #undef PIN - for(auto& pin : pins) - pin.mode(Mode::OUTPUT); - } - private: - static vector<GpioPin> pins; - Leds() {} + static const int numLeds=10; + static std::array<miosix::GpioPin,numLeds> pins; + + Leds()=delete; + Leds(const Leds&)=delete; + Leds& operator=(const Leds&)=delete; }; #endif