Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: fll mbed-rtos mbed
Diff: fll.cpp
- Revision:
- 33:cc84b10e6c67
- Parent:
- 26:08387521c994
- Parent:
- 32:fdf9f6fca8a2
- Child:
- 34:422d4d6ae5ea
--- a/fll.cpp Tue Feb 17 02:29:57 2015 +0000
+++ b/fll.cpp Tue Feb 17 03:22:36 2015 +0000
@@ -3,8 +3,11 @@
#include "mbed.h"
#include "rtos.h"
+#include "fll.h"
+
#include <stdint.h>
-#include "fll.h"
+
+void invoke_sinkrun(const void *p);
// if you want to debug by `printf`, uncomment next line and put `pc.printf("...", ...);` into certain position.
// Serial pc(USBTX, USBRX);
@@ -69,9 +72,10 @@
// ------
// Output
// ------
-Output::Output(rtos::Mail<button_t, MAIL_BOX_SIZE>* box)
+Output::Output(rtos::Mail<button_t, MAIL_BOX_SIZE>* box, FLL *f)
{
mail_box = box;
+ fll = f;
}
void Output::run()
@@ -80,85 +84,50 @@
if (e.status == osEventMail) { // getting is success
button_t b = *(button_t*)(e.value.p);
mail_box->free((button_t*)e.value.p);
- press(b);
+ fll->press(b);
} else {
- press(0); // if mail box is empty
+ fll->press(0); // if mail box is empty
}
}
-// --------------------
-// button_t -> mbed pin
-// --------------------
-typedef struct _table {
- button_t mask; // 0000 0000 0000 0001 ~ 0010 0000 0000 0000
- DigitalOut *pin; // pin5~pin19
- int on; // 1 or 0
-} table;
+FLL::FLL(Producer* p)
+{
+ producer = p;
+
+ // button_no -> pin (R1 to L1)
+ PinName ps[] = {
+ p10, p5, p6, p7, p8, p9,
+ p11, p12, p13, p18, p16, p17, p15,
+ p19, p14,
+ };
+
+ for(int i = 0; i < BUTTON_NUM; i++) {
+ off[i] = new int(1);
+ pin[i] = new DigitalOut(ps[i], *off[i]);
+ }
+}
-DigitalOut pinR2(p10);
-DigitalOut pinR1(p5);
-DigitalOut pinTriangle(p6);
-DigitalOut pinCircle(p7);
-DigitalOut pinCross(p8);
-DigitalOut pinSquare(p9);
-DigitalOut pinStart(p11);
-DigitalOut pinAnalog(p12);
-DigitalOut pinSelect(p13);
-DigitalOut pinRight(p18);
-DigitalOut pinDown(p16);
-DigitalOut pinLeft(p17);
-DigitalOut pinUp(p15);
-DigitalOut pinL1(p19);
-DigitalOut pinL2(p14);
+FLL::~FLL()
+{
+ for(int i = 0; i < BUTTON_NUM; i++) {
+ delete off[i];
+ delete pin[i];
+ }
+}
// button-pin mapping table
-table tables[] = {
- { R1, &pinR1, 0 },
- { TRIANGLE, &pinTriangle, 0 },
- { CIRCLE, &pinCircle, 0 },
- { CROSS, &pinCross, 0 },
- { SQUARE, &pinSquare, 0 },
- { R2, &pinR2, 0 },
- { START, &pinStart, 0 },
- { ANALOG, &pinAnalog, 0 },
- { SELECT, &pinSelect, 0 },
- { L2, &pinL2, 0 },
- { UP, &pinUp, 0 },
- { DOWN, &pinDown, 0 },
- { LEFT, &pinLeft, 0 },
- { RIGHT, &pinRight, 0 },
- { L1, &pinL1, 0 }
-};
-
-void press(button_t btn)
+void FLL::press(button_t btn)
{
- table t;
- for (int i = 0; i < sizeof(tables)/sizeof(table); i++) {
- t = tables[i];
- if (btn & t.mask) {
- t.pin->write(t.on);
+ for(int i = 0; i < BUTTON_NUM; i++) {
+ if ((btn >> i) & 0x1) {
+ pin[i]->write(!(*off[i]));
} else {
- t.pin->write(1 - t.on);
+ pin[i]->write(*off[i]);
}
}
}
-// ----
-// main
-// ----
-void fll_init()
-{
- press(0);
-}
-
-void invoke_sinkrun(const void *p)
-{
- ((Sink*)p)->run();
-}
-
-Serial pc(USBTX, USBRX);
-
-void fll_run(Producer* producer)
+void FLL::run()
{
Mail<button_t, MAIL_BOX_SIZE>* mail_box = new Mail<button_t, MAIL_BOX_SIZE>();
Mutex* mutex = new Mutex();
@@ -168,11 +137,15 @@
reset_pin.fall(sink, &Sink::reset);
Ticker ticker;
- Output* output = new Output(mail_box);
+ Output* output = new Output(mail_box, this);
Thread th(invoke_sinkrun, (void *)sink);
-
ticker.attach(output, &Output::run, FRAME);
Thread::wait(osWaitForever);
+}
+
+static void invoke_sinkrun(const void *p)
+{
+ ((Sink*)p)->run();
}
\ No newline at end of file
