IHS1.1-STM32F303K8
Revision 0:0fcc82d7750c, committed 2020-07-16
- Comitter:
- maro
- Date:
- Thu Jul 16 08:20:57 2020 +0000
- Child:
- 1:62baf2ea5573
- Commit message:
- IHS1.1-STM32F303K8
Changed in this revision
| CLED.cpp | Show annotated file Show diff for this revision Revisions of this file |
| CLED.h | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/CLED.cpp Thu Jul 16 08:20:57 2020 +0000
@@ -0,0 +1,53 @@
+#include "mbed.h"
+#include "CLED.h"
+// *************************** CLED ********************************
+const byte CLED::c10[7] = {0, 4, 5, 1, 3, 2, 6};//IHS10:none, red, yellow, green, lightBlue, bule, purple
+const byte CLED::c11[7] = {0, 1, 3, 2, 6, 4, 5};//IHS11:none, red, yellow, green, lightBlue, bule, purple
+const byte CLED::INDI_COLOR = 12;
+// *************************** SPI ********************************
+extern SPI spi;
+extern DigitalOut ss;
+extern Serial uart;
+// *************************** GPIO ********************************
+extern DigitalOut sel_sen;
+extern DigitalOut fix_cled;
+extern DigitalOut oe_cled;
+// ************************* object ********************************
+Ticker indiTic;
+
+CLED::CLED(int ver) : indVal(0) {
+ if (ver == 10) color = c10;
+ if (ver == 11) color = c11;
+ indiTic.attach(callback(this, &CLED::indiBlink), 400e-3);
+
+}
+
+void CLED::set(byte* ary12, bool indi) { // 1-12[8]:{7, 3,..}
+ int val24 = 0;
+ for (int col = 0; col < COL_LEN; col++) { // LED number is opposit direction
+ byte cVal = (indi && (col == COL_LEN - 1) ? indVal : ary12[col]) >> 1;
+ val24 += color[cVal] << col * 3;
+ }
+ sel_sen = 0; //digitalWrite(sel_sen, LOW);
+ oe_cled = 0; //digitalWrite(oe_cled, LOW);
+ ss = 0; //digitalWrite(ss, LOW);
+ for (int b = 2; b>=0; b--) {
+ spi.write((val24 >> b * COL_LEN) & 0xff);
+ }
+ fix_cled = 1; //digitalWrite(FIX_LED, HIGH);
+ fix_cled = 0; //digitalWrite(FIX_LED, LOW);
+ ss = 1; //digitalWrite(ss, HIGH);
+ oe_cled = 1; //digitalWrite(oe_cled, HIGH);
+}
+
+void CLED::set(byte val12) {
+ byte ary[COL_LEN];
+ for (int i=0; i<COL_LEN; i++)
+ ary[i] = val12;
+ set(ary);
+}
+
+// *************** PWM callback function ****************
+void CLED::indiBlink() { // indicator blink
+ indVal = (indVal > 0) ? 0 : INDI_COLOR;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/CLED.h Thu Jul 16 08:20:57 2020 +0000
@@ -0,0 +1,21 @@
+#ifndef CLED_H
+#define CLED_H
+#include "Sensor.h"
+
+// *************************** CLED ********************************
+class CLED {
+ public:
+ CLED(int ver=10);
+ void set(byte* ary12, bool indi = false);
+ void set(byte val12);
+
+ private:
+ void indiBlink();
+ const byte* color;
+ static const byte c10[7];
+ static const byte c11[7];
+ static const byte INDI_COLOR;
+ byte indVal;
+};
+
+#endif