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
fll.h@0:c80e972b4c59, 2015-02-13 (annotated)
- Committer:
- amutake
- Date:
- Fri Feb 13 13:19:29 2015 +0000
- Revision:
- 0:c80e972b4c59
- Child:
- 1:1abcd83947bf
initial
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| amutake | 0:c80e972b4c59 | 1 | // Frame Level Language |
| amutake | 0:c80e972b4c59 | 2 | // header |
| amutake | 0:c80e972b4c59 | 3 | |
| amutake | 0:c80e972b4c59 | 4 | #include "mbed.h" |
| amutake | 0:c80e972b4c59 | 5 | #include "rtos.h" |
| amutake | 0:c80e972b4c59 | 6 | #include <stdint.h> |
| amutake | 0:c80e972b4c59 | 7 | #include <vector> |
| amutake | 0:c80e972b4c59 | 8 | |
| amutake | 0:c80e972b4c59 | 9 | #define R1 0x0001 |
| amutake | 0:c80e972b4c59 | 10 | #define B_TRIANGLE 0x0002 |
| amutake | 0:c80e972b4c59 | 11 | #define B_CIRCLE 0x0004 |
| amutake | 0:c80e972b4c59 | 12 | #define B_CROSS 0x0008 |
| amutake | 0:c80e972b4c59 | 13 | #define B_SQUARE 0x0010 |
| amutake | 0:c80e972b4c59 | 14 | #define B_R2 0x0020 |
| amutake | 0:c80e972b4c59 | 15 | #define B_START 0x0040 |
| amutake | 0:c80e972b4c59 | 16 | #define B_ANALOG 0x0080 |
| amutake | 0:c80e972b4c59 | 17 | #define B_SELECT 0x0100 |
| amutake | 0:c80e972b4c59 | 18 | #define B_L2 0x0200 |
| amutake | 0:c80e972b4c59 | 19 | #define B_UP 0x0400 |
| amutake | 0:c80e972b4c59 | 20 | #define B_DOWN 0x0800 |
| amutake | 0:c80e972b4c59 | 21 | #define B_LEFT 0x1000 |
| amutake | 0:c80e972b4c59 | 22 | #define B_RIGHT 0x2000 |
| amutake | 0:c80e972b4c59 | 23 | #define B_L1 0x4000 |
| amutake | 0:c80e972b4c59 | 24 | |
| amutake | 0:c80e972b4c59 | 25 | #define QUEUE_SIZE 5 |
| amutake | 0:c80e972b4c59 | 26 | |
| amutake | 0:c80e972b4c59 | 27 | typedef uint16_t button; |
| amutake | 0:c80e972b4c59 | 28 | |
| amutake | 0:c80e972b4c59 | 29 | class Source |
| amutake | 0:c80e972b4c59 | 30 | { |
| amutake | 0:c80e972b4c59 | 31 | private: |
| amutake | 0:c80e972b4c59 | 32 | int i; |
| amutake | 0:c80e972b4c59 | 33 | vector<button>* button_seq; |
| amutake | 0:c80e972b4c59 | 34 | bool loop; |
| amutake | 0:c80e972b4c59 | 35 | public: |
| amutake | 0:c80e972b4c59 | 36 | Source(vector<button>* bs, bool l); |
| amutake | 0:c80e972b4c59 | 37 | virtual button await(); |
| amutake | 0:c80e972b4c59 | 38 | }; |
| amutake | 0:c80e972b4c59 | 39 | |
| amutake | 0:c80e972b4c59 | 40 | class Flow : Source |
| amutake | 0:c80e972b4c59 | 41 | { |
| amutake | 0:c80e972b4c59 | 42 | private: |
| amutake | 0:c80e972b4c59 | 43 | vector<Source*>& sources; |
| amutake | 0:c80e972b4c59 | 44 | public: |
| amutake | 0:c80e972b4c59 | 45 | Flow(vector<Source*> &srcs); |
| amutake | 0:c80e972b4c59 | 46 | virtual button fold(vector<button> &bs); |
| amutake | 0:c80e972b4c59 | 47 | virtual button await(); |
| amutake | 0:c80e972b4c59 | 48 | }; |
| amutake | 0:c80e972b4c59 | 49 | |
| amutake | 0:c80e972b4c59 | 50 | // Sink で使う。次に持ち越すキーのクラス。Option[Key] みたいな感じ |
| amutake | 0:c80e972b4c59 | 51 | class Carry |
| amutake | 0:c80e972b4c59 | 52 | { |
| amutake | 0:c80e972b4c59 | 53 | private: |
| amutake | 0:c80e972b4c59 | 54 | button btn; |
| amutake | 0:c80e972b4c59 | 55 | static const button none = 0x8000; // 1000 0000 0000 0000 |
| amutake | 0:c80e972b4c59 | 56 | public: |
| amutake | 0:c80e972b4c59 | 57 | Carry(); |
| amutake | 0:c80e972b4c59 | 58 | bool is_empty(); |
| amutake | 0:c80e972b4c59 | 59 | button get(); |
| amutake | 0:c80e972b4c59 | 60 | void set(button b); |
| amutake | 0:c80e972b4c59 | 61 | void empty(); |
| amutake | 0:c80e972b4c59 | 62 | }; |
| amutake | 0:c80e972b4c59 | 63 | |
| amutake | 0:c80e972b4c59 | 64 | // ストリームの終端になっていて、キー入力をするスレッドに向けてキーを送る |
| amutake | 0:c80e972b4c59 | 65 | class Sink |
| amutake | 0:c80e972b4c59 | 66 | { |
| amutake | 0:c80e972b4c59 | 67 | private: |
| amutake | 0:c80e972b4c59 | 68 | Source* source; |
| amutake | 0:c80e972b4c59 | 69 | Carry* carry; |
| amutake | 0:c80e972b4c59 | 70 | rtos::Mail<button, QUEUE_SIZE>* queue; |
| amutake | 0:c80e972b4c59 | 71 | Mutex* queueMutex; // Main Thread と同じ Mutex でなければいけない |
| amutake | 0:c80e972b4c59 | 72 | public: |
| amutake | 0:c80e972b4c59 | 73 | Sink(Source* src, rtos::Mail<button, QUEUE_SIZE>* q, Mutex* mut); |
| amutake | 0:c80e972b4c59 | 74 | void run(); |
| amutake | 0:c80e972b4c59 | 75 | void reset(Source* src); |
| amutake | 0:c80e972b4c59 | 76 | }; |
| amutake | 0:c80e972b4c59 | 77 | |
| amutake | 0:c80e972b4c59 | 78 | |
| amutake | 0:c80e972b4c59 | 79 | class Output |
| amutake | 0:c80e972b4c59 | 80 | { |
| amutake | 0:c80e972b4c59 | 81 | private: |
| amutake | 0:c80e972b4c59 | 82 | rtos::Mail<button, QUEUE_SIZE>* queue; |
| amutake | 0:c80e972b4c59 | 83 | public: |
| amutake | 0:c80e972b4c59 | 84 | Output(rtos::Mail<button, QUEUE_SIZE>* q); |
| amutake | 0:c80e972b4c59 | 85 | void run(); |
| amutake | 0:c80e972b4c59 | 86 | }; |
| amutake | 0:c80e972b4c59 | 87 | |
| amutake | 0:c80e972b4c59 | 88 | void press(button btn); |
