PushToGo on STM32F429-Disco Board
Dependencies: BSP_DISCO_F429ZI LCD_DISCO_F429ZI pushtogo usb
LCDConsole.h@0:084d1dae2ea1, 2018-08-19 (annotated)
- Committer:
- caoyuan9642
- Date:
- Sun Aug 19 05:20:21 2018 +0000
- Revision:
- 0:084d1dae2ea1
v0.1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
caoyuan9642 | 0:084d1dae2ea1 | 1 | /* |
caoyuan9642 | 0:084d1dae2ea1 | 2 | * LCDStreamHandle.h |
caoyuan9642 | 0:084d1dae2ea1 | 3 | * |
caoyuan9642 | 0:084d1dae2ea1 | 4 | * Created on: 2018Äê2ÔÂ25ÈÕ |
caoyuan9642 | 0:084d1dae2ea1 | 5 | * Author: caoyuan9642 |
caoyuan9642 | 0:084d1dae2ea1 | 6 | */ |
caoyuan9642 | 0:084d1dae2ea1 | 7 | |
caoyuan9642 | 0:084d1dae2ea1 | 8 | #ifndef LCDCONSOLE_H_ |
caoyuan9642 | 0:084d1dae2ea1 | 9 | #define LCDSTREAMHANDLE_H_ |
caoyuan9642 | 0:084d1dae2ea1 | 10 | |
caoyuan9642 | 0:084d1dae2ea1 | 11 | #include "mbed.h" |
caoyuan9642 | 0:084d1dae2ea1 | 12 | #include "LCD_DISCO_F429ZI.h" |
caoyuan9642 | 0:084d1dae2ea1 | 13 | |
caoyuan9642 | 0:084d1dae2ea1 | 14 | class LCDConsole: public FileLike |
caoyuan9642 | 0:084d1dae2ea1 | 15 | { |
caoyuan9642 | 0:084d1dae2ea1 | 16 | protected: |
caoyuan9642 | 0:084d1dae2ea1 | 17 | |
caoyuan9642 | 0:084d1dae2ea1 | 18 | static int* buffer; // The first 3 byets of each int contain its color, and last byte contain the content |
caoyuan9642 | 0:084d1dae2ea1 | 19 | static int *head, *tail; |
caoyuan9642 | 0:084d1dae2ea1 | 20 | static Mutex mutex; |
caoyuan9642 | 0:084d1dae2ea1 | 21 | static LCD_DISCO_F429ZI lcd; |
caoyuan9642 | 0:084d1dae2ea1 | 22 | static Thread thread; |
caoyuan9642 | 0:084d1dae2ea1 | 23 | static bool inited; |
caoyuan9642 | 0:084d1dae2ea1 | 24 | static int x0, y0, width, height; |
caoyuan9642 | 0:084d1dae2ea1 | 25 | static int textwidth, textheight, buffersize; |
caoyuan9642 | 0:084d1dae2ea1 | 26 | static Semaphore sem_update; |
caoyuan9642 | 0:084d1dae2ea1 | 27 | |
caoyuan9642 | 0:084d1dae2ea1 | 28 | uint32_t color; |
caoyuan9642 | 0:084d1dae2ea1 | 29 | |
caoyuan9642 | 0:084d1dae2ea1 | 30 | static void task_thread(); |
caoyuan9642 | 0:084d1dae2ea1 | 31 | public: |
caoyuan9642 | 0:084d1dae2ea1 | 32 | |
caoyuan9642 | 0:084d1dae2ea1 | 33 | static void init(int x0, int y0, int width, int height); |
caoyuan9642 | 0:084d1dae2ea1 | 34 | /** Redirects the stdout the stderr |
caoyuan9642 | 0:084d1dae2ea1 | 35 | * @param tolcd If true, stdout and stderr will be redirected to the console. |
caoyuan9642 | 0:084d1dae2ea1 | 36 | * If false, it will be redirected back to serial |
caoyuan9642 | 0:084d1dae2ea1 | 37 | */ |
caoyuan9642 | 0:084d1dae2ea1 | 38 | static void redirect(bool tolcd); |
caoyuan9642 | 0:084d1dae2ea1 | 39 | |
caoyuan9642 | 0:084d1dae2ea1 | 40 | static LCD_DISCO_F429ZI &getLCD() |
caoyuan9642 | 0:084d1dae2ea1 | 41 | { |
caoyuan9642 | 0:084d1dae2ea1 | 42 | return lcd; |
caoyuan9642 | 0:084d1dae2ea1 | 43 | } |
caoyuan9642 | 0:084d1dae2ea1 | 44 | |
caoyuan9642 | 0:084d1dae2ea1 | 45 | // Can initialize multiple instances |
caoyuan9642 | 0:084d1dae2ea1 | 46 | LCDConsole(const char *name, uint32_t color); |
caoyuan9642 | 0:084d1dae2ea1 | 47 | virtual ~LCDConsole() |
caoyuan9642 | 0:084d1dae2ea1 | 48 | { |
caoyuan9642 | 0:084d1dae2ea1 | 49 | } |
caoyuan9642 | 0:084d1dae2ea1 | 50 | |
caoyuan9642 | 0:084d1dae2ea1 | 51 | /** Read the contents of a file into a buffer |
caoyuan9642 | 0:084d1dae2ea1 | 52 | * |
caoyuan9642 | 0:084d1dae2ea1 | 53 | * Devices acting as FileHandles should follow POSIX semantics: |
caoyuan9642 | 0:084d1dae2ea1 | 54 | * |
caoyuan9642 | 0:084d1dae2ea1 | 55 | * * if no data is available, and non-blocking set return -EAGAIN |
caoyuan9642 | 0:084d1dae2ea1 | 56 | * * if no data is available, and blocking set, wait until some data is available |
caoyuan9642 | 0:084d1dae2ea1 | 57 | * * If any data is available, call returns immediately |
caoyuan9642 | 0:084d1dae2ea1 | 58 | * |
caoyuan9642 | 0:084d1dae2ea1 | 59 | * @param buffer The buffer to read in to |
caoyuan9642 | 0:084d1dae2ea1 | 60 | * @param size The number of bytes to read |
caoyuan9642 | 0:084d1dae2ea1 | 61 | * @return The number of bytes read, 0 at end of file, negative error on failure |
caoyuan9642 | 0:084d1dae2ea1 | 62 | */ |
caoyuan9642 | 0:084d1dae2ea1 | 63 | virtual ssize_t read(void *buffer, size_t size); |
caoyuan9642 | 0:084d1dae2ea1 | 64 | |
caoyuan9642 | 0:084d1dae2ea1 | 65 | /** Write the contents of a buffer to a file |
caoyuan9642 | 0:084d1dae2ea1 | 66 | * |
caoyuan9642 | 0:084d1dae2ea1 | 67 | * Devices acting as FileHandles should follow POSIX semantics: |
caoyuan9642 | 0:084d1dae2ea1 | 68 | * |
caoyuan9642 | 0:084d1dae2ea1 | 69 | * * if blocking, block until all data is written |
caoyuan9642 | 0:084d1dae2ea1 | 70 | * * if no data can be written, and non-blocking set, return -EAGAIN |
caoyuan9642 | 0:084d1dae2ea1 | 71 | * * if some data can be written, and non-blocking set, write partial |
caoyuan9642 | 0:084d1dae2ea1 | 72 | * |
caoyuan9642 | 0:084d1dae2ea1 | 73 | * @param buffer The buffer to write from |
caoyuan9642 | 0:084d1dae2ea1 | 74 | * @param size The number of bytes to write |
caoyuan9642 | 0:084d1dae2ea1 | 75 | * @return The number of bytes written, negative error on failure |
caoyuan9642 | 0:084d1dae2ea1 | 76 | */ |
caoyuan9642 | 0:084d1dae2ea1 | 77 | virtual ssize_t write(const void *buffer, size_t size); |
caoyuan9642 | 0:084d1dae2ea1 | 78 | |
caoyuan9642 | 0:084d1dae2ea1 | 79 | /** Move the file position to a given offset from from a given location |
caoyuan9642 | 0:084d1dae2ea1 | 80 | * |
caoyuan9642 | 0:084d1dae2ea1 | 81 | * @param offset The offset from whence to move to |
caoyuan9642 | 0:084d1dae2ea1 | 82 | * @param whence The start of where to seek |
caoyuan9642 | 0:084d1dae2ea1 | 83 | * SEEK_SET to start from beginning of file, |
caoyuan9642 | 0:084d1dae2ea1 | 84 | * SEEK_CUR to start from current position in file, |
caoyuan9642 | 0:084d1dae2ea1 | 85 | * SEEK_END to start from end of file |
caoyuan9642 | 0:084d1dae2ea1 | 86 | * @return The new offset of the file, negative error code on failure |
caoyuan9642 | 0:084d1dae2ea1 | 87 | */ |
caoyuan9642 | 0:084d1dae2ea1 | 88 | virtual off_t seek(off_t offset, int whence = SEEK_SET); |
caoyuan9642 | 0:084d1dae2ea1 | 89 | |
caoyuan9642 | 0:084d1dae2ea1 | 90 | /** Close a file |
caoyuan9642 | 0:084d1dae2ea1 | 91 | * |
caoyuan9642 | 0:084d1dae2ea1 | 92 | * @return 0 on success, negative error code on failure |
caoyuan9642 | 0:084d1dae2ea1 | 93 | */ |
caoyuan9642 | 0:084d1dae2ea1 | 94 | virtual int close(); |
caoyuan9642 | 0:084d1dae2ea1 | 95 | /** Check for poll event flags |
caoyuan9642 | 0:084d1dae2ea1 | 96 | * The input parameter can be used or ignored - the could always return all events, |
caoyuan9642 | 0:084d1dae2ea1 | 97 | * or could check just the events listed in events. |
caoyuan9642 | 0:084d1dae2ea1 | 98 | * Call is non-blocking - returns instantaneous state of events. |
caoyuan9642 | 0:084d1dae2ea1 | 99 | * Whenever an event occurs, the derived class should call the sigio() callback). |
caoyuan9642 | 0:084d1dae2ea1 | 100 | * |
caoyuan9642 | 0:084d1dae2ea1 | 101 | * @param events bitmask of poll events we're interested in - POLLIN/POLLOUT etc. |
caoyuan9642 | 0:084d1dae2ea1 | 102 | * |
caoyuan9642 | 0:084d1dae2ea1 | 103 | * @returns bitmask of poll events that have occurred. |
caoyuan9642 | 0:084d1dae2ea1 | 104 | */ |
caoyuan9642 | 0:084d1dae2ea1 | 105 | virtual short poll(short events) const |
caoyuan9642 | 0:084d1dae2ea1 | 106 | { |
caoyuan9642 | 0:084d1dae2ea1 | 107 | // Possible default for real files |
caoyuan9642 | 0:084d1dae2ea1 | 108 | return POLLOUT; |
caoyuan9642 | 0:084d1dae2ea1 | 109 | } |
caoyuan9642 | 0:084d1dae2ea1 | 110 | /** Check if the file in an interactive terminal device |
caoyuan9642 | 0:084d1dae2ea1 | 111 | * |
caoyuan9642 | 0:084d1dae2ea1 | 112 | * @return True if the file is a terminal |
caoyuan9642 | 0:084d1dae2ea1 | 113 | * @return False if the file is not a terminal |
caoyuan9642 | 0:084d1dae2ea1 | 114 | * @return Negative error code on failure |
caoyuan9642 | 0:084d1dae2ea1 | 115 | */ |
caoyuan9642 | 0:084d1dae2ea1 | 116 | virtual int isatty() |
caoyuan9642 | 0:084d1dae2ea1 | 117 | { |
caoyuan9642 | 0:084d1dae2ea1 | 118 | return true; |
caoyuan9642 | 0:084d1dae2ea1 | 119 | } |
caoyuan9642 | 0:084d1dae2ea1 | 120 | }; |
caoyuan9642 | 0:084d1dae2ea1 | 121 | |
caoyuan9642 | 0:084d1dae2ea1 | 122 | #endif /* LCDCONSOLE_H_ */ |
caoyuan9642 | 0:084d1dae2ea1 | 123 |