Adafruit-RGB_matrix_Panel(32*16)
RGBmatrixPanel.h@12:e632883f319f, 2014-05-25 (annotated)
- Committer:
- lelect
- Date:
- Sun May 25 13:41:34 2014 +0000
- Revision:
- 12:e632883f319f
- Parent:
- 10:db4941188812
- Child:
- 13:0ceb1b8893e9
add oxygen & method(convert HSV in float value)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lelect | 0:06d9443a018f | 1 | #include "mbed.h" |
lelect | 0:06d9443a018f | 2 | #include "Adafruit_GFX.h" |
lelect | 0:06d9443a018f | 3 | |
lelect | 2:6136465ffd3a | 4 | #ifndef _BV |
lelect | 2:6136465ffd3a | 5 | #define _BV(bit) (1<<(bit)) |
lelect | 2:6136465ffd3a | 6 | #endif |
lelect | 2:6136465ffd3a | 7 | |
lelect | 2:6136465ffd3a | 8 | #ifdef DEBUG |
lelect | 3:aa3762e0dfee | 9 | #define log_debug(format,...) std::printf(format,##__VA_ARGS__) |
lelect | 2:6136465ffd3a | 10 | #else |
lelect | 2:6136465ffd3a | 11 | #define log_debug(...) |
lelect | 2:6136465ffd3a | 12 | #endif |
lelect | 2:6136465ffd3a | 13 | |
lelect | 12:e632883f319f | 14 | /** RGBmatrixPanel is class for full color LED matrix |
lelect | 12:e632883f319f | 15 | * |
lelect | 12:e632883f319f | 16 | */ |
lelect | 0:06d9443a018f | 17 | class RGBmatrixPanel : public Adafruit_GFX |
lelect | 0:06d9443a018f | 18 | { |
lelect | 0:06d9443a018f | 19 | |
lelect | 0:06d9443a018f | 20 | public: |
lelect | 0:06d9443a018f | 21 | // Constructor for 16x32 panel: |
lelect | 9:349baf041171 | 22 | RGBmatrixPanel(PinName r1,PinName g1,PinName b1,PinName r2,PinName g2,PinName b2,PinName a,PinName b,PinName c,PinName sclk,PinName latch,PinName oe, bool dbuf); |
lelect | 0:06d9443a018f | 23 | |
lelect | 0:06d9443a018f | 24 | // Constructor for 32x32 panel (adds 'd' pin): |
lelect | 12:e632883f319f | 25 | RGBmatrixPanel(PinName r1,PinName r2,PinName g1,PinName g2,PinName b1,PinName b2,PinName a,PinName b,PinName c,PinName d,PinName sclk, PinName latch,PinName oe,bool dbuf); |
lelect | 0:06d9443a018f | 26 | |
lelect | 12:e632883f319f | 27 | /** Attach a updateDisplay() to be called by the Ticker(every 100us) |
lelect | 12:e632883f319f | 28 | * |
lelect | 12:e632883f319f | 29 | */ |
lelect | 0:06d9443a018f | 30 | void begin(void); |
lelect | 12:e632883f319f | 31 | /** @fn void RGBmatrixPanel::drawPixel(int16_t x, int16_t y, uint16_t c) |
lelect | 12:e632883f319f | 32 | * @bref drawPixel |
lelect | 12:e632883f319f | 33 | */ |
lelect | 12:e632883f319f | 34 | virtual void drawPixel(int16_t x,int16_t y,uint16_t c); |
lelect | 12:e632883f319f | 35 | /** @fn void RGBmatrixPanel::fillScreen(uint16_t c) |
lelect | 12:e632883f319f | 36 | * @bref fillScreen |
lelect | 12:e632883f319f | 37 | * @param c fill screen 16bit color 0x0000 ~ 0xFFFF |
lelect | 12:e632883f319f | 38 | */ |
lelect | 0:06d9443a018f | 39 | virtual void fillScreen(uint16_t c); |
lelect | 12:e632883f319f | 40 | /** @fn void RGBmatrixPanel::updateDisplay(void) |
lelect | 12:e632883f319f | 41 | * @param c updateDisplay\\ |
lelect | 12:e632883f319f | 42 | * This method is called by the interrupt start at begin(). |
lelect | 12:e632883f319f | 43 | */ |
lelect | 0:06d9443a018f | 44 | void updateDisplay(void); |
lelect | 12:e632883f319f | 45 | /** @fn void RGBmatrixPanel::swapBuffers(bool copy) |
lelect | 12:e632883f319f | 46 | * @param copy swap buffer (if you use double-buffer) |
lelect | 12:e632883f319f | 47 | */ |
lelect | 12:e632883f319f | 48 | void swapBuffers(bool copy); |
lelect | 12:e632883f319f | 49 | /** @fn void RGBmatrixPanel::dumpMatrix(void) |
lelect | 12:e632883f319f | 50 | * @bref dump to default USB Serial\\ |
lelect | 12:e632883f319f | 51 | * Declaration is required to use.(#define DEBUG) |
lelect | 12:e632883f319f | 52 | */ |
lelect | 0:06d9443a018f | 53 | void dumpMatrix(void); |
lelect | 0:06d9443a018f | 54 | |
lelect | 0:06d9443a018f | 55 | uint8_t *backBuffer(void); |
lelect | 0:06d9443a018f | 56 | |
lelect | 12:e632883f319f | 57 | /** @fn void RGBmatrixPanel::Color333(uint8_t r, uint8_t g, uint8_t b) |
lelect | 12:e632883f319f | 58 | * @bref up convert to 16bit color from 9bit color. |
lelect | 12:e632883f319f | 59 | * @return 16bit(uint16_t) color value |
lelect | 12:e632883f319f | 60 | */ |
lelect | 0:06d9443a018f | 61 | uint16_t Color333(uint8_t r, uint8_t g, uint8_t b); |
lelect | 12:e632883f319f | 62 | /** @fn void RGBmatrixPanel::Color444(uint8_t r, uint8_t g, uint8_t b) |
lelect | 12:e632883f319f | 63 | * @bref up convert to 16bit color from 12bit color. |
lelect | 12:e632883f319f | 64 | * @return 16bit(uint16_t) color value |
lelect | 12:e632883f319f | 65 | */ |
lelect | 0:06d9443a018f | 66 | uint16_t Color444(uint8_t r, uint8_t g, uint8_t b); |
lelect | 12:e632883f319f | 67 | /** @fn void RGBmatrixPanel::Color888(uint8_t r, uint8_t g, uint8_t b) |
lelect | 12:e632883f319f | 68 | * @bref down convert to 16bit color from 24bit color. |
lelect | 12:e632883f319f | 69 | * @return 16bit(uint16_t) color value |
lelect | 12:e632883f319f | 70 | */ |
lelect | 0:06d9443a018f | 71 | uint16_t Color888(uint8_t r, uint8_t g, uint8_t b); |
lelect | 12:e632883f319f | 72 | /** @fn void RGBmatrixPanel::Color888(uint8_t r, uint8_t g, uint8_t b, bool gflag) |
lelect | 12:e632883f319f | 73 | * @bref down convert to 16bit color from 24bit color using the gamma value table. |
lelect | 12:e632883f319f | 74 | * @return 16bit(uint16_t) color value |
lelect | 12:e632883f319f | 75 | */ |
lelect | 0:06d9443a018f | 76 | uint16_t Color888(uint8_t r, uint8_t g, uint8_t b, bool gflag); |
lelect | 12:e632883f319f | 77 | /** @fn void RGBmatrixPanel::ColorHSV(long hue, uint8_t sat, uint8_t val, bool gflag) |
lelect | 12:e632883f319f | 78 | * @bref convert to 16bit color from (unsigned integer)HSV color using the gamma value table. |
lelect | 12:e632883f319f | 79 | * @param hue 0~1536(decimal value) |
lelect | 12:e632883f319f | 80 | * @param sat 0~255(decimal value) Does not make sense that it is not a multiple of 32. |
lelect | 12:e632883f319f | 81 | * @param val 0~255(decimal value) Does not make sense that it is not a multiple of 32. |
lelect | 12:e632883f319f | 82 | * @return 16bit(uint16_t) color value |
lelect | 12:e632883f319f | 83 | */ |
lelect | 12:e632883f319f | 84 | uint16_t ColorHSV(long hue, uint8_t sat, uint8_t val, bool gflag) |
lelect | 12:e632883f319f | 85 | ; |
lelect | 12:e632883f319f | 86 | /** @fn void RGBmatrixPanel::ColorHSV(float hue, float sat, float val, bool gflag) |
lelect | 12:e632883f319f | 87 | * @bref convert to 16bit color from (float)HSV color using the gamma value table. |
lelect | 12:e632883f319f | 88 | * @param hue Normalized value from 0.0 to 1.0 |
lelect | 12:e632883f319f | 89 | * @param sat Normalized value from 0.0 to 1.0 |
lelect | 12:e632883f319f | 90 | * @param val Normalized value from 0.0 to 1.0 |
lelect | 12:e632883f319f | 91 | * @return 16bit(uint16_t) color value |
lelect | 12:e632883f319f | 92 | */ |
lelect | 12:e632883f319f | 93 | uint16_t ColorHSV(float hue, float sat, float val, bool gflag); |
lelect | 0:06d9443a018f | 94 | private: |
lelect | 4:0ff6053c4bb2 | 95 | uint8_t *matrixbuff[2]; |
lelect | 4:0ff6053c4bb2 | 96 | uint8_t nRows; |
lelect | 4:0ff6053c4bb2 | 97 | uint8_t backindex; |
lelect | 4:0ff6053c4bb2 | 98 | bool swapflag; |
lelect | 0:06d9443a018f | 99 | |
lelect | 0:06d9443a018f | 100 | // Init/alloc code common to both constructors: |
lelect | 2:6136465ffd3a | 101 | void init(uint8_t rows, bool dbuf); |
lelect | 0:06d9443a018f | 102 | |
lelect | 5:1f8409ee8850 | 103 | BusOut _dataBus; |
lelect | 5:1f8409ee8850 | 104 | BusOut _rowBus; |
lelect | 5:1f8409ee8850 | 105 | DigitalOut _d,_sclk, _latch, _oe; |
lelect | 3:aa3762e0dfee | 106 | Ticker _refresh; |
lelect | 0:06d9443a018f | 107 | // Counters/pointers for interrupt handler: |
lelect | 10:db4941188812 | 108 | uint8_t row, plane; |
lelect | 10:db4941188812 | 109 | uint8_t *buffptr; |
lelect | 0:06d9443a018f | 110 | }; |