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@8:d16a0fcc2735, 2015-02-14 (annotated)
- Committer:
- amutake
- Date:
- Sat Feb 14 16:51:25 2015 +0000
- Revision:
- 8:d16a0fcc2735
- Parent:
- 7:61b4825304e2
- Child:
- 9:0d6631edfc32
fll_run
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| amutake | 0:c80e972b4c59 | 1 | // Frame Level Language |
| amutake | 7:61b4825304e2 | 2 | // interface |
| 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 | |
| amutake | 7:61b4825304e2 | 8 | // buttons represented by 16 bit |
| amutake | 0:c80e972b4c59 | 9 | #define R1 0x0001 |
| amutake | 7:61b4825304e2 | 10 | #define TRIANGLE 0x0002 |
| amutake | 7:61b4825304e2 | 11 | #define CIRCLE 0x0004 |
| amutake | 7:61b4825304e2 | 12 | #define CROSS 0x0008 |
| amutake | 7:61b4825304e2 | 13 | #define SQUARE 0x0010 |
| amutake | 7:61b4825304e2 | 14 | #define R2 0x0020 |
| amutake | 7:61b4825304e2 | 15 | #define START 0x0040 |
| amutake | 7:61b4825304e2 | 16 | #define ANALOG 0x0080 |
| amutake | 7:61b4825304e2 | 17 | #define SELECT 0x0100 |
| amutake | 7:61b4825304e2 | 18 | #define L2 0x0200 |
| amutake | 7:61b4825304e2 | 19 | #define UP 0x0400 |
| amutake | 7:61b4825304e2 | 20 | #define DOWN 0x0800 |
| amutake | 7:61b4825304e2 | 21 | #define LEFT 0x1000 |
| amutake | 7:61b4825304e2 | 22 | #define RIGHT 0x2000 |
| amutake | 7:61b4825304e2 | 23 | #define L1 0x4000 |
| amutake | 0:c80e972b4c59 | 24 | |
| amutake | 2:165723d41023 | 25 | #define MAIL_BOX_SIZE 16 |
| amutake | 0:c80e972b4c59 | 26 | |
| amutake | 8:d16a0fcc2735 | 27 | #define FRAME (1.0 / 60) // 1 frame (sec) |
| amutake | 8:d16a0fcc2735 | 28 | |
| sierra | 3:edbf31a8589f | 29 | typedef uint16_t button_t; |
| amutake | 0:c80e972b4c59 | 30 | |
| sierra | 6:d0348b7a2f05 | 31 | // Base object for stream network |
| amutake | 7:61b4825304e2 | 32 | class Producer |
| amutake | 7:61b4825304e2 | 33 | { |
| sierra | 6:d0348b7a2f05 | 34 | public: |
| sierra | 6:d0348b7a2f05 | 35 | virtual button_t await() = 0; |
| sierra | 6:d0348b7a2f05 | 36 | }; |
| sierra | 6:d0348b7a2f05 | 37 | |
| amutake | 7:61b4825304e2 | 38 | // 0 input and repeat given button sequence |
| amutake | 7:61b4825304e2 | 39 | class RepeaterSource : public Producer |
| amutake | 7:61b4825304e2 | 40 | { |
| amutake | 0:c80e972b4c59 | 41 | private: |
| amutake | 0:c80e972b4c59 | 42 | int i; |
| sierra | 6:d0348b7a2f05 | 43 | button_t* button_seq; |
| sierra | 1:1abcd83947bf | 44 | int size; |
| amutake | 0:c80e972b4c59 | 45 | public: |
| sierra | 6:d0348b7a2f05 | 46 | RepeaterSource(button_t *bs, int s); |
| sierra | 3:edbf31a8589f | 47 | virtual button_t await(); |
| amutake | 0:c80e972b4c59 | 48 | }; |
| amutake | 0:c80e972b4c59 | 49 | |
| sierra | 6:d0348b7a2f05 | 50 | // N inputs |
| amutake | 7:61b4825304e2 | 51 | class FoldFlow : public Producer |
| amutake | 7:61b4825304e2 | 52 | { |
| amutake | 0:c80e972b4c59 | 53 | private: |
| sierra | 6:d0348b7a2f05 | 54 | Producer** sources; |
| sierra | 5:130721ce29f7 | 55 | int sources_size; |
| amutake | 0:c80e972b4c59 | 56 | public: |
| sierra | 6:d0348b7a2f05 | 57 | FoldFlow(Producer **srcs, int srcs_size); |
| sierra | 5:130721ce29f7 | 58 | virtual button_t fold(button_t *bs, int bs_size) = 0; |
| sierra | 3:edbf31a8589f | 59 | virtual button_t await(); |
| amutake | 0:c80e972b4c59 | 60 | }; |
| amutake | 0:c80e972b4c59 | 61 | |
| amutake | 7:61b4825304e2 | 62 | // Sink is the end of button stream network |
| amutake | 7:61b4825304e2 | 63 | // It sends next button to Output object through rtos::Mail |
| amutake | 0:c80e972b4c59 | 64 | class Sink |
| amutake | 0:c80e972b4c59 | 65 | { |
| amutake | 0:c80e972b4c59 | 66 | private: |
| sierra | 6:d0348b7a2f05 | 67 | Producer* source; |
| sierra | 3:edbf31a8589f | 68 | rtos::Mail<button_t, MAIL_BOX_SIZE>* mail_box; |
| amutake | 2:165723d41023 | 69 | Mutex* mutex; |
| amutake | 0:c80e972b4c59 | 70 | public: |
| sierra | 6:d0348b7a2f05 | 71 | Sink(Producer* src, rtos::Mail<button_t, MAIL_BOX_SIZE>* box, Mutex* mut); |
| amutake | 0:c80e972b4c59 | 72 | void run(); |
| sierra | 6:d0348b7a2f05 | 73 | void reset(Producer* src); |
| amutake | 0:c80e972b4c59 | 74 | }; |
| amutake | 0:c80e972b4c59 | 75 | |
| amutake | 7:61b4825304e2 | 76 | // Output reads the next button from mail box and press the button |
| amutake | 7:61b4825304e2 | 77 | // It must be run per 1/60 sec |
| amutake | 0:c80e972b4c59 | 78 | class Output |
| amutake | 0:c80e972b4c59 | 79 | { |
| amutake | 0:c80e972b4c59 | 80 | private: |
| sierra | 3:edbf31a8589f | 81 | rtos::Mail<button_t, MAIL_BOX_SIZE>* mail_box; |
| amutake | 0:c80e972b4c59 | 82 | public: |
| sierra | 3:edbf31a8589f | 83 | Output(rtos::Mail<button_t, MAIL_BOX_SIZE>* box); |
| amutake | 0:c80e972b4c59 | 84 | void run(); |
| amutake | 0:c80e972b4c59 | 85 | }; |
| amutake | 0:c80e972b4c59 | 86 | |
| amutake | 7:61b4825304e2 | 87 | // tells dualshock2 circuit which button is pressed |
| amutake | 8:d16a0fcc2735 | 88 | void press(button_t btn); |
| amutake | 8:d16a0fcc2735 | 89 | |
| amutake | 8:d16a0fcc2735 | 90 | // main function |
| amutake | 8:d16a0fcc2735 | 91 | void fll_run(Producer* producer); |
