t

Dependencies:   DM_FATFileSystem DM_HttpServer DM_USBHost EthernetInterface USBDevice mbed-rpc mbed-rtos

Fork of DMSupport by Embedded Artists

Revision:
0:6b68dac0d986
Child:
9:a33326afd686
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Display/Display.h	Fri Nov 21 11:42:51 2014 +0000
@@ -0,0 +1,124 @@
+/*
+ *  Copyright 2014 Embedded Artists AB
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+#ifndef DISPLAY_H
+#define DISPLAY_H
+
+#include "mbed.h"
+
+class Display {
+public:
+    enum Constants {
+        NumLEDs       =  4,
+    };
+  
+    enum DisplayError {
+        Ok            =       0,
+        ConfigError   =       1,
+        WrongBPP      =       2,
+        InvalidParam  =       3,
+        NoInit        =       4,
+    };
+    
+    enum Resolution {
+        Resolution_16bit_rgb565 = 16,
+        Resolution_18bit_rgb666 = 18,
+        Resolution_24bit_rgb888 = 24,
+    };
+    
+    static Display& instance()
+    {
+        static Display singleton;
+        return singleton;
+    }
+  
+
+    /** Initializes the wanted features
+     *
+     *  @returns
+     *       Ok on success
+     *       An error code on failure
+     */
+    DisplayError init();
+  
+    /** Initializes the wanted features
+     *
+     *  @returns
+     *       Ok on success
+     *       An error code on failure
+     */
+    DisplayError powerUp(void* framebuffer, Resolution wanted = Resolution_16bit_rgb565);
+  
+    /** Initializes the wanted features
+     *
+     *  @returns
+     *       Ok on success
+     *       An error code on failure
+     */
+    DisplayError powerDown();
+  
+    /** Sets the backlight level. 0% is off and 100% is fully on
+     *
+     *  @returns
+     *       Ok on success
+     *       An error code on failure
+     */
+    DisplayError backlight(int percent);
+  
+    uint16_t width() { return _width; }
+    uint16_t height() { return _height; }
+    uint16_t bpp() { return _bpp; }
+    uint32_t fbSize() { return _fbSize; }
+    bool landscape() { return _landscape; }
+    bool isSupported(Resolution res);
+    void setFramebuffer(void* buff);
+    void* swapFramebuffer(void* buff);
+    void* allocateFramebuffer(Resolution res=Resolution_16bit_rgb565);
+
+private:
+
+    bool _initialized;
+    bool _poweredOn;
+    DigitalOut _pinWP;
+    DigitalOut _pin3v3;
+    DigitalOut _pin5v;
+    DigitalOut _pinDE;
+    DigitalOut _pinColDepth;
+    PwmOut _pinBacklight;
+
+    uint16_t _width;
+    uint16_t _height;
+    uint16_t _bpp;
+    uint32_t _fbSize;
+    bool _landscape;
+
+    explicit Display();
+    // hide copy constructor
+    Display(const Display&);
+    // hide assign operator
+    Display& operator=(const Display&);
+    ~Display();
+    
+    void pinInit(bool powerOn, Resolution res=Resolution_16bit_rgb565);
+    DisplayError regInit(void* info, Resolution res);
+    uint32_t getClockDivisor(uint32_t clock);
+    void set3v3(bool on);
+    void set5v(bool on);
+    void setDisplayEnable(bool enable);    
+};
+
+#endif
+