Skip to content
Snippets Groups Projects
Commit d6e77f04 authored by Federico's avatar Federico
Browse files

Improved Leds class: removed the need for init(), added comments, used array instead of vector

parent e99ff0ad
No related branches found
No related tags found
No related merge requests found
...@@ -352,7 +352,6 @@ int main() { ...@@ -352,7 +352,6 @@ int main() {
int ignore_ctr = 100; int ignore_ctr = 100;
int led_status = 0x200; int led_status = 0x200;
Leds::init();
while(1) { while(1) {
sDemoBoard->update(); sDemoBoard->update();
Thread::sleep(20); Thread::sleep(20);
......
...@@ -60,7 +60,6 @@ void fifoQueueSz(void *arg) ...@@ -60,7 +60,6 @@ void fifoQueueSz(void *arg)
int main() int main()
{ {
printf("\n"); printf("\n");
Leds::init();
Leds::set(0); Leds::set(0);
Log::getInstance(); Log::getInstance();
sBoard->init(); sBoard->init();
......
/* Copyright (c) 2016-2017 Skyward Experimental Rocketry /* 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
...@@ -22,4 +22,10 @@ ...@@ -22,4 +22,10 @@
#include "Leds.h" #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
/* Copyright (c) 2016 Skyward Experimental Rocketry /* 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
...@@ -24,21 +24,22 @@ ...@@ -24,21 +24,22 @@
#define LEDS_H #define LEDS_H
#include <Common.h> #include <Common.h>
#include <array>
using namespace std;
using namespace miosix;
class Leds { class Leds {
public: public:
/**
/** Every bit of the param leds is the value for the n-th led. * Turn on/off all leds using a bitmask
* For example leds = 0x201 means (only) first and last led on. * \param leds bitmask specifing which led has to be turned on
*/ */
static void set(uint16_t leds) { static void set(uint16_t leds) {
for(int i=0;i<10;i++) for(int i=0;i<10;i++)
set(i, (leds & (1 << i)) != 0); set(i, (leds & (1 << i)) != 0);
} }
/** Param id should be in range [0,10). */ /**
* \param id should be in range [0,10).
*/
static void set(uint8_t id, bool enable) { static void set(uint8_t id, bool enable) {
if(id >= pins.size()) if(id >= pins.size())
return; return;
...@@ -49,21 +50,13 @@ public: ...@@ -49,21 +50,13 @@ public:
pins[id].low(); 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: private:
static vector<GpioPin> pins; static const int numLeds=10;
Leds() {} static std::array<miosix::GpioPin,numLeds> pins;
Leds()=delete;
Leds(const Leds&)=delete;
Leds& operator=(const Leds&)=delete;
}; };
#endif #endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment