IHS1.1-STM32F303K8
CLED.cpp@1:62baf2ea5573, 2020-10-23 (annotated)
- Committer:
- maro
- Date:
- Fri Oct 23 06:37:09 2020 +0000
- Revision:
- 1:62baf2ea5573
- Parent:
- 0:0fcc82d7750c
Blinking indicator added
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
maro | 0:0fcc82d7750c | 1 | #include "mbed.h" |
maro | 0:0fcc82d7750c | 2 | #include "CLED.h" |
maro | 0:0fcc82d7750c | 3 | // *************************** CLED ******************************** |
maro | 0:0fcc82d7750c | 4 | const byte CLED::c10[7] = {0, 4, 5, 1, 3, 2, 6};//IHS10:none, red, yellow, green, lightBlue, bule, purple |
maro | 0:0fcc82d7750c | 5 | const byte CLED::c11[7] = {0, 1, 3, 2, 6, 4, 5};//IHS11:none, red, yellow, green, lightBlue, bule, purple |
maro | 0:0fcc82d7750c | 6 | const byte CLED::INDI_COLOR = 12; |
maro | 0:0fcc82d7750c | 7 | // *************************** SPI ******************************** |
maro | 0:0fcc82d7750c | 8 | extern SPI spi; |
maro | 0:0fcc82d7750c | 9 | extern DigitalOut ss; |
maro | 0:0fcc82d7750c | 10 | extern Serial uart; |
maro | 0:0fcc82d7750c | 11 | // *************************** GPIO ******************************** |
maro | 0:0fcc82d7750c | 12 | extern DigitalOut sel_sen; |
maro | 0:0fcc82d7750c | 13 | extern DigitalOut fix_cled; |
maro | 0:0fcc82d7750c | 14 | extern DigitalOut oe_cled; |
maro | 0:0fcc82d7750c | 15 | // ************************* object ******************************** |
maro | 0:0fcc82d7750c | 16 | Ticker indiTic; |
maro | 0:0fcc82d7750c | 17 | |
maro | 1:62baf2ea5573 | 18 | CLED::CLED(int ver) : inOn(false) { |
maro | 0:0fcc82d7750c | 19 | if (ver == 10) color = c10; |
maro | 0:0fcc82d7750c | 20 | if (ver == 11) color = c11; |
maro | 0:0fcc82d7750c | 21 | indiTic.attach(callback(this, &CLED::indiBlink), 400e-3); |
maro | 0:0fcc82d7750c | 22 | |
maro | 0:0fcc82d7750c | 23 | } |
maro | 0:0fcc82d7750c | 24 | |
maro | 1:62baf2ea5573 | 25 | void CLED::set(byte* ary12, bool indiRow) { // 1-12[8]:{7, 3,..} |
maro | 0:0fcc82d7750c | 26 | int val24 = 0; |
maro | 0:0fcc82d7750c | 27 | for (int col = 0; col < COL_LEN; col++) { // LED number is opposit direction |
maro | 1:62baf2ea5573 | 28 | bool isIndi = inOn && indiRow && (col == COL_LEN - 1) && (ary12[col] == 0); |
maro | 1:62baf2ea5573 | 29 | byte cVal = (isIndi ? INDI_COLOR : ary12[col]) >> 1; |
maro | 0:0fcc82d7750c | 30 | val24 += color[cVal] << col * 3; |
maro | 0:0fcc82d7750c | 31 | } |
maro | 0:0fcc82d7750c | 32 | sel_sen = 0; //digitalWrite(sel_sen, LOW); |
maro | 0:0fcc82d7750c | 33 | oe_cled = 0; //digitalWrite(oe_cled, LOW); |
maro | 0:0fcc82d7750c | 34 | ss = 0; //digitalWrite(ss, LOW); |
maro | 0:0fcc82d7750c | 35 | for (int b = 2; b>=0; b--) { |
maro | 0:0fcc82d7750c | 36 | spi.write((val24 >> b * COL_LEN) & 0xff); |
maro | 0:0fcc82d7750c | 37 | } |
maro | 0:0fcc82d7750c | 38 | fix_cled = 1; //digitalWrite(FIX_LED, HIGH); |
maro | 0:0fcc82d7750c | 39 | fix_cled = 0; //digitalWrite(FIX_LED, LOW); |
maro | 0:0fcc82d7750c | 40 | ss = 1; //digitalWrite(ss, HIGH); |
maro | 0:0fcc82d7750c | 41 | oe_cled = 1; //digitalWrite(oe_cled, HIGH); |
maro | 0:0fcc82d7750c | 42 | } |
maro | 0:0fcc82d7750c | 43 | |
maro | 0:0fcc82d7750c | 44 | void CLED::set(byte val12) { |
maro | 0:0fcc82d7750c | 45 | byte ary[COL_LEN]; |
maro | 0:0fcc82d7750c | 46 | for (int i=0; i<COL_LEN; i++) |
maro | 0:0fcc82d7750c | 47 | ary[i] = val12; |
maro | 0:0fcc82d7750c | 48 | set(ary); |
maro | 0:0fcc82d7750c | 49 | } |
maro | 0:0fcc82d7750c | 50 | |
maro | 0:0fcc82d7750c | 51 | // *************** PWM callback function **************** |
maro | 0:0fcc82d7750c | 52 | void CLED::indiBlink() { // indicator blink |
maro | 1:62baf2ea5573 | 53 | inOn = !inOn; |
maro | 0:0fcc82d7750c | 54 | } |