2026-08-26 07:26:58 +08:00
|
|
|
|
#include "includes.h"
|
|
|
|
|
|
|
|
|
|
|
|
static uint8_t key_last = KEY_NONE;
|
|
|
|
|
|
|
|
|
|
|
|
|
2026-09-11 14:59:23 +08:00
|
|
|
|
/* LED <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ<EFBFBD><C9AB><EFBFBD>棺<EFBFBD><E6A3BA><EFBFBD><EFBFBD> = LedNum_TypeDef<65><66>0~7<><37><EFBFBD><EFBFBD>COLOR_OTHER <20><>ʾ<EFBFBD><CABE> */
|
2026-08-26 07:26:58 +08:00
|
|
|
|
//static LedColor_TypeDef led_cache[8] = {
|
|
|
|
|
|
// COLOR_OTHER, COLOR_OTHER, COLOR_OTHER, COLOR_OTHER,
|
|
|
|
|
|
// COLOR_OTHER, COLOR_OTHER, COLOR_OTHER, COLOR_OTHER
|
|
|
|
|
|
//};
|
|
|
|
|
|
|
|
|
|
|
|
void app_tm1629_init(void)
|
|
|
|
|
|
{
|
|
|
|
|
|
rt_mutex_take(TM1629_Mutex, RT_WAITING_FOREVER);
|
|
|
|
|
|
TM1629D_Key_LED_Init();
|
|
|
|
|
|
TM1629D_AllLedOff();
|
|
|
|
|
|
TM1629D_UpdateDisplay(0);
|
|
|
|
|
|
rt_mutex_release(TM1629_Mutex);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uint8_t app_tm1629_Scan_Key(void)
|
|
|
|
|
|
{
|
|
|
|
|
|
uint8_t key = 0;
|
|
|
|
|
|
|
|
|
|
|
|
//static uint8_t Last_Tm1926D_Key = 0;
|
|
|
|
|
|
|
|
|
|
|
|
rt_mutex_take(TM1629_Mutex, RT_WAITING_FOREVER);
|
|
|
|
|
|
key = TM1629D_GetKey();
|
|
|
|
|
|
rt_mutex_release(TM1629_Mutex);
|
|
|
|
|
|
|
|
|
|
|
|
if(key != key_last)
|
|
|
|
|
|
{
|
|
|
|
|
|
key_last = key;
|
2026-09-11 14:59:23 +08:00
|
|
|
|
LOG_I("KEY", "tm1629 key=%u", (unsigned)key);
|
2026-08-26 07:26:58 +08:00
|
|
|
|
TM1629_Handle(key);
|
2026-09-11 14:59:23 +08:00
|
|
|
|
return key;
|
2026-08-26 07:26:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
return KEY_NONE;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-09-13 21:21:11 +08:00
|
|
|
|
void app_tm1629_inject_key(uint8_t key)
|
|
|
|
|
|
{
|
|
|
|
|
|
key_last = key;
|
|
|
|
|
|
LOG_I("KEY", "inject key=%u", (unsigned)key);
|
|
|
|
|
|
TM1629_Handle(key);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-08-26 07:26:58 +08:00
|
|
|
|
|
|
|
|
|
|
static void app_tm1629_led_set(LedNum_TypeDef led, LedColor_TypeDef color, uint8_t on)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(on)
|
|
|
|
|
|
{
|
|
|
|
|
|
//if(led_cache[led] == color) return;
|
|
|
|
|
|
//led_cache[led] = color;
|
|
|
|
|
|
TM1629D_ControlLed(led, color, 1);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
//if(led_cache[led] == color) return;
|
|
|
|
|
|
//led_cache[led] = COLOR_OTHER;
|
|
|
|
|
|
TM1629D_ControlLed(led, COLOR_OTHER, 1);
|
|
|
|
|
|
}
|
|
|
|
|
|
TM1629D_UpdateDisplay(0);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void app_tm1629_set_chord_led(uint8_t key_idx, LedColor_TypeDef color)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(key_idx < 1 || key_idx > 21) return;
|
|
|
|
|
|
|
|
|
|
|
|
LedNum_TypeDef led = (LedNum_TypeDef)((key_idx - 1) / 3); //L1-L7
|
|
|
|
|
|
|
|
|
|
|
|
rt_mutex_take(TM1629_Mutex, RT_WAITING_FOREVER);
|
|
|
|
|
|
app_tm1629_led_set(led,color,1);
|
|
|
|
|
|
rt_mutex_release(TM1629_Mutex);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void app_tm1629_set_led(LedNum_TypeDef led, LedColor_TypeDef color)
|
|
|
|
|
|
{
|
|
|
|
|
|
rt_mutex_take(TM1629_Mutex, RT_WAITING_FOREVER);
|
|
|
|
|
|
TM1629D_AllLedOff();
|
|
|
|
|
|
app_tm1629_led_set(led,color,1);
|
|
|
|
|
|
rt_mutex_release(TM1629_Mutex);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void app_tm1629_all_off(void)
|
|
|
|
|
|
{
|
|
|
|
|
|
rt_mutex_take(TM1629_Mutex, RT_WAITING_FOREVER);
|
|
|
|
|
|
TM1629D_AllLedOff();
|
|
|
|
|
|
TM1629D_UpdateDisplay(0);
|
|
|
|
|
|
rt_mutex_release(TM1629_Mutex);
|
|
|
|
|
|
|
|
|
|
|
|
// for (int i = 0; i < 8; i++)
|
|
|
|
|
|
// led_cache[i] = COLOR_OTHER;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void app_tm1629_all_on(LedColor_TypeDef color)
|
|
|
|
|
|
{
|
|
|
|
|
|
rt_mutex_take(TM1629_Mutex, RT_WAITING_FOREVER);
|
|
|
|
|
|
TM1629D_AllLedOff();
|
|
|
|
|
|
TM1629D_AllLedOn(color);
|
|
|
|
|
|
TM1629D_UpdateDisplay(0);
|
|
|
|
|
|
rt_mutex_release(TM1629_Mutex);
|
|
|
|
|
|
|
|
|
|
|
|
// for (int i = 0; i < 8; i++)
|
|
|
|
|
|
// led_cache[i] = color;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|