|
@@ -4,12 +4,12 @@
|
|
#include "Wire.h"
|
|
#include "Wire.h"
|
|
|
|
|
|
/* Private Defines */
|
|
/* Private Defines */
|
|
-#define TM1650_ADDR_SYS 0x48
|
|
|
|
-#define TM1650_ADDR_BTN 0x4F
|
|
|
|
-#define TM1650_ADDR_DIG1 0x68
|
|
|
|
-#define TM1650_ADDR_DIG2 0x6A
|
|
|
|
-#define TM1650_ADDR_DIG3 0x6C
|
|
|
|
-#define TM1650_ADDR_DIG4 0x6E
|
|
|
|
|
|
+#define TM1650_ADDR_SYS (uint8_t)(0x48 >> 1)
|
|
|
|
+#define TM1650_ADDR_BTN (uint8_t)(0x4F >> 1)
|
|
|
|
+#define TM1650_ADDR_DIG1 (uint8_t)(0x68 >> 1)
|
|
|
|
+#define TM1650_ADDR_DIG2 (uint8_t)(0x6A >> 1)
|
|
|
|
+#define TM1650_ADDR_DIG3 (uint8_t)(0x6C >> 1)
|
|
|
|
+#define TM1650_ADDR_DIG4 (uint8_t)(0x6E >> 1)
|
|
|
|
|
|
/* Private Variables */
|
|
/* Private Variables */
|
|
static const uint8_t Digits[16] = {
|
|
static const uint8_t Digits[16] = {
|
|
@@ -19,16 +19,22 @@ static const uint8_t Digits[16] = {
|
|
static const uint8_t Addr[LED_NUM] = {
|
|
static const uint8_t Addr[LED_NUM] = {
|
|
TM1650_ADDR_DIG1, TM1650_ADDR_DIG2, TM1650_ADDR_DIG3, TM1650_ADDR_DIG4
|
|
TM1650_ADDR_DIG1, TM1650_ADDR_DIG2, TM1650_ADDR_DIG3, TM1650_ADDR_DIG4
|
|
};
|
|
};
|
|
|
|
+static bool isPresent;
|
|
static uint8 Buffer[LED_NUM] = {0};
|
|
static uint8 Buffer[LED_NUM] = {0};
|
|
|
|
|
|
/* Private Fuctions */
|
|
/* Private Fuctions */
|
|
-bool I2CWriteTo(uint8_t addr, uint8_t data);
|
|
|
|
|
|
+static bool I2CWriteTo(uint8_t addr, uint8_t data);
|
|
|
|
|
|
/**
|
|
/**
|
|
* @brief Initialization
|
|
* @brief Initialization
|
|
*/
|
|
*/
|
|
void TM1650_Init(void) {
|
|
void TM1650_Init(void) {
|
|
- I2CWriteTo(TM1650_ADDR_SYS, 0x79);
|
|
|
|
|
|
+ if (I2CWriteTo(TM1650_ADDR_SYS, 0x79)) {
|
|
|
|
+ Serial.println("TM1650 not respond!");
|
|
|
|
+ isPresent = false;
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ isPresent = true;
|
|
TM1650_Out(Sym_Minus, Sym_Minus, Sym_Minus, Sym_Minus);
|
|
TM1650_Out(Sym_Minus, Sym_Minus, Sym_Minus, Sym_Minus);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -41,6 +47,8 @@ void TM1650_Init(void) {
|
|
* @param i4 Value in range 0..F
|
|
* @param i4 Value in range 0..F
|
|
*/
|
|
*/
|
|
void TM1650_Out(uint8_t i1, uint8_t i2, uint8_t i3, uint8_t i4) {
|
|
void TM1650_Out(uint8_t i1, uint8_t i2, uint8_t i3, uint8_t i4) {
|
|
|
|
+ if (!isPresent) { return; }
|
|
|
|
+
|
|
Buffer[0] = Digits[i1];
|
|
Buffer[0] = Digits[i1];
|
|
Buffer[1] = Digits[i2];
|
|
Buffer[1] = Digits[i2];
|
|
Buffer[2] = Digits[i3];
|
|
Buffer[2] = Digits[i3];
|
|
@@ -58,6 +66,7 @@ void TM1650_Out(uint8_t i1, uint8_t i2, uint8_t i3, uint8_t i4) {
|
|
* @param value Segment code.
|
|
* @param value Segment code.
|
|
*/
|
|
*/
|
|
void TM1650_Out1(tm1650_sym_t value) {
|
|
void TM1650_Out1(tm1650_sym_t value) {
|
|
|
|
+ if (!isPresent) { return; }
|
|
Buffer[0] = value;
|
|
Buffer[0] = value;
|
|
I2CWriteTo(TM1650_ADDR_DIG1, value);
|
|
I2CWriteTo(TM1650_ADDR_DIG1, value);
|
|
}
|
|
}
|
|
@@ -68,6 +77,7 @@ void TM1650_Out1(tm1650_sym_t value) {
|
|
* @param value Segment code.
|
|
* @param value Segment code.
|
|
*/
|
|
*/
|
|
void TM1650_Out2(tm1650_sym_t value) {
|
|
void TM1650_Out2(tm1650_sym_t value) {
|
|
|
|
+ if (!isPresent) { return; }
|
|
Buffer[1] = value;
|
|
Buffer[1] = value;
|
|
I2CWriteTo(TM1650_ADDR_DIG2, value);
|
|
I2CWriteTo(TM1650_ADDR_DIG2, value);
|
|
}
|
|
}
|
|
@@ -78,6 +88,7 @@ void TM1650_Out2(tm1650_sym_t value) {
|
|
* @param value Segment code.
|
|
* @param value Segment code.
|
|
*/
|
|
*/
|
|
void TM1650_Out3(tm1650_sym_t value) {
|
|
void TM1650_Out3(tm1650_sym_t value) {
|
|
|
|
+ if (!isPresent) { return; }
|
|
Buffer[2] = value;
|
|
Buffer[2] = value;
|
|
I2CWriteTo(TM1650_ADDR_DIG3, value);
|
|
I2CWriteTo(TM1650_ADDR_DIG3, value);
|
|
}
|
|
}
|
|
@@ -88,6 +99,7 @@ void TM1650_Out3(tm1650_sym_t value) {
|
|
* @param value Segment code.
|
|
* @param value Segment code.
|
|
*/
|
|
*/
|
|
void TM1650_Out4(tm1650_sym_t value) {
|
|
void TM1650_Out4(tm1650_sym_t value) {
|
|
|
|
+ if (!isPresent) { return; }
|
|
Buffer[3] = value;
|
|
Buffer[3] = value;
|
|
I2CWriteTo(TM1650_ADDR_DIG4, value);
|
|
I2CWriteTo(TM1650_ADDR_DIG4, value);
|
|
}
|
|
}
|
|
@@ -98,6 +110,7 @@ void TM1650_Out4(tm1650_sym_t value) {
|
|
* @param pos Led 0..3
|
|
* @param pos Led 0..3
|
|
*/
|
|
*/
|
|
void TM1650_DotSet(tm1650_pos_t pos) {
|
|
void TM1650_DotSet(tm1650_pos_t pos) {
|
|
|
|
+ if (!isPresent) { return; }
|
|
if (pos > LED_NUM-1) {
|
|
if (pos > LED_NUM-1) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
@@ -110,6 +123,7 @@ void TM1650_DotSet(tm1650_pos_t pos) {
|
|
* @param pos Led 0..3
|
|
* @param pos Led 0..3
|
|
*/
|
|
*/
|
|
void TM1650_DotRes(tm1650_pos_t pos) {
|
|
void TM1650_DotRes(tm1650_pos_t pos) {
|
|
|
|
+ if (!isPresent) { return; }
|
|
if (pos > LED_NUM-1) {
|
|
if (pos > LED_NUM-1) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
@@ -122,6 +136,7 @@ void TM1650_DotRes(tm1650_pos_t pos) {
|
|
* @param bright Brgiht level 0..7
|
|
* @param bright Brgiht level 0..7
|
|
*/
|
|
*/
|
|
void TM1650_Bright(uint8_t bright) {
|
|
void TM1650_Bright(uint8_t bright) {
|
|
|
|
+ if (!isPresent) { return; }
|
|
if (bright > LedBrightMax) {
|
|
if (bright > LedBrightMax) {
|
|
bright = LedBrightMax;
|
|
bright = LedBrightMax;
|
|
}
|
|
}
|
|
@@ -130,7 +145,7 @@ void TM1650_Bright(uint8_t bright) {
|
|
I2CWriteTo(TM1650_ADDR_SYS, bright);
|
|
I2CWriteTo(TM1650_ADDR_SYS, bright);
|
|
}
|
|
}
|
|
|
|
|
|
-bool I2CWriteTo(uint8_t addr, uint8_t data) {
|
|
|
|
|
|
+static bool I2CWriteTo(uint8_t addr, uint8_t data) {
|
|
Wire.beginTransmission(addr);
|
|
Wire.beginTransmission(addr);
|
|
Wire.write(data);
|
|
Wire.write(data);
|
|
return Wire.endTransmission();
|
|
return Wire.endTransmission();
|