Compare commits

...

7 Commits

Author SHA1 Message Date
yuquanjun 1d5fe8073d Auto-select Cortex-M4 on flash/capture so J-Link never prompts for device.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-30 20:11:17 +08:00
yuquanjun f3774b069b Add J-Link RTT LCD capture and fix mode-select MiSans glyphs.
Keep AT32F403ARCT7 RAM at 96KB, soft-CS GRAM readback over RTT, and add missing 普/通/业 to CHS16 so mode labels render fully.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-30 19:50:01 +08:00
yuquanjun 43083fd3f1 Switch LCD UI to MiSans bitmap fonts and align typography/colors with 0819 UI spec.
Regenerate Chinese/English font tables, extend LCD driver for new sizes, and update screen layouts; add gen_misans_font.py for reproducible font builds.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-28 11:24:06 +08:00
yuquanjun d0568a1b00 Increase preset buffer size to 40KB.
Raise PRESET_BUFFER_SIZE from 20KB to 40KB to accommodate larger preset data in AutoBand.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-28 10:34:55 +08:00
yuquanjun 745d097178 Fix status bar battery icon display and percent text.
Keep the battery white in the status bar, center it vertically, and use 16px ASCII font so the percentage renders correctly instead of garbled characters.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-28 10:34:27 +08:00
yuquanjun aabef28918 Align status bar battery icon with UI spec.
Use a rounded battery shell with proportional fill and smaller centered percentage text to match the design reference.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-28 10:09:22 +08:00
yuquanjun 37242f108a Align status bar volume icon with UI spec.
Replace the old volume bars with 5 rounded-top bars using a left-to-right brightness gradient, synced from the ADC volume pot.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-28 10:07:48 +08:00
39 changed files with 9128 additions and 1276 deletions

View File

@ -277,14 +277,14 @@ static void app_adc_volume_process(void)
if(abs((int16_t)vol_last - (int16_t)val) > 2) if(abs((int16_t)vol_last - (int16_t)val) > 2)
{ {
vol_last = val; vol_last = val;
/* <EFBFBD><EFBFBD> 6 <20><> */ /* 5 格状态栏音量条0=静音5=最大 */
if (val <= 5) level = 0; if (val <= 5) level = 0;
else if (val <= 35) level = 1; else if (val <= 35) level = 1;
else if (val <= 65) level = 2; else if (val <= 65) level = 2;
else if (val <= 95) level = 3; else if (val <= 95) level = 3;
else if (val <= 115) level = 4; else if (val <= 115) level = 4;
else level = 5; else level = 5;
MainTask_Sendmsg(MSG_ID_EC_VOL, val, level, 0); MainTask_Sendmsg(MSG_ID_EC_VOL, val, level, 0);
} }
} }

View File

@ -57,6 +57,16 @@
#define WHITE 0xFFFF #define WHITE 0xFFFF
#define BLACK 0x0000 #define BLACK 0x0000
#define BLUE 0x001F #define BLUE 0x001F
#define COLOR_PRIMARY 0x1B9F // #1D73FF MiSans UI 主色
#define COLOR_GRAD_START 0x039D // #003AEE
#define COLOR_GRAD_MID 0x2A5A // #354FD6
#define COLOR_GRAD_END 0x4B1F // #5561F8
#define COLOR_BG_START 0x0849 // #0E1537
#define COLOR_BG_END 0x3189 // #2F3647
#define COLOR_MIXER_RED 0xFB2D // #F85E4B
#define COLOR_MIXER_ORANGE 0xFD26 // #F59C2C
#define COLOR_MIXER_YELLOW 0xFF6E // #F3D939
#define COLOR_MIXER_GREEN 0x071F // #13E17F
#define BRED 0XF81F #define BRED 0XF81F
#define GRED 0XFFE0 #define GRED 0XFFE0
#define GBLUE 0X07FF #define GBLUE 0X07FF
@ -79,9 +89,9 @@
#define DARKLGRAY 0x5AEB/*0x2988*//*0x1926*//*0x252E*//*0X2B12*/ #define DARKLGRAY 0x5AEB/*0x2988*//*0x1926*//*0x252E*//*0X2B12*/
#define BUTTON_COLOR /*0x5AEB*/BLACK #define BUTTON_COLOR /*0x5AEB*/BLACK
#define START_COLOR /*0x5AEB*/ 0x2988 #define START_COLOR COLOR_GRAD_START
#define END_COLOR 0x2022/*0x5066*/ #define END_COLOR COLOR_GRAD_END
extern void LCD_GPIO_Init(void); //初始化GPIO extern void LCD_GPIO_Init(void); //初始化GPIO
extern void LCD_WR_DATA8(uint8_t data); //写入一个字节 extern void LCD_WR_DATA8(uint8_t data); //写入一个字节
extern void LCD_WR_DATA16(uint16_t data); //写入两个字节 extern void LCD_WR_DATA16(uint16_t data); //写入两个字节

View File

@ -33,11 +33,11 @@ GUI_SWITCH ParamGuiData[] =
const LEBEL_UI UI_Label[] = { const LEBEL_UI UI_Label[] = {
{5, 115, 30, 60, (const uint8_t*)"\xD2\xC6\xB5\xF7", LCD_ALIGN_CENTER, WHITE,BLACK,11, LCD_ALIGN_CENTER,WHITE,BLACK,24, GUI_TRANSPOSE}, {5, 115, 30, 60, (const uint8_t*)"\xD2\xC6\xB5\xF7", LCD_ALIGN_CENTER, WHITE,BLACK,11, LCD_ALIGN_CENTER,WHITE,BLACK,11, GUI_TRANSPOSE},
{125,110, 30, 60, (const uint8_t*)"\xCB\xD9\xB6\xC8", LCD_ALIGN_CENTER, WHITE,BLACK,11, LCD_ALIGN_CENTER,WHITE,BLACK,24, GUI_SPEED}, {125,110, 30, 60, (const uint8_t*)"\xCB\xD9\xB6\xC8", LCD_ALIGN_CENTER, WHITE,BLACK,11, LCD_ALIGN_CENTER,WHITE,BLACK,11, GUI_SPEED},
{5, 230, 95, 55, (const uint8_t*)"\xB8\xE8\xC7\xFA\xD1\xA1\xD2\xE9", LCD_ALIGN_LEFT,WHITE,BLACK,11,LCD_ALIGN_CENTER,WHITE,BLACK,13,GUI_MODE_PARAM}, {5, 230, 95, 55, (const uint8_t*)"\xB8\xE8\xC7\xFA\xD1\xA1\xD2\xE9", LCD_ALIGN_LEFT,WHITE,BLACK,11,LCD_ALIGN_CENTER,WHITE,BLACK,13,GUI_MODE_PARAM},
{5, 230, 155,55, (const uint8_t*)"\xCF\xD2\xD2\xF4\xC9\xAB\xD1\xA1\xD2\xE9",LCD_ALIGN_LEFT,WHITE,BLACK,11,LCD_ALIGN_CENTER,WHITE,BLACK,13,GUI_TIMBRE_SELECT}, {5, 230, 155,55, (const uint8_t*)"\xCF\xD2\xD2\xF4\xC9\xAB\xD1\xA1\xD2\xE9",LCD_ALIGN_LEFT,WHITE,BLACK,11,LCD_ALIGN_CENTER,WHITE,BLACK,13,GUI_TIMBRE_SELECT},
{5, 230, 210,55, (const uint8_t*)"\xD1\xDD\xD7\xE0\xB6\xCE\xC2\xE4",LCD_ALIGN_LEFT,WHITE,BLACK,11,LCD_ALIGN_CENTER,WHITE,BLACK,24,GUI_PLAY_SECTION}, {5, 230, 210,55, (const uint8_t*)"\xD1\xDD\xD7\xE0\xB6\xCE\xC2\xE4",LCD_ALIGN_LEFT,WHITE,BLACK,11,LCD_ALIGN_CENTER,WHITE,BLACK,13,GUI_PLAY_SECTION},
}; };

View File

@ -13,7 +13,7 @@
#include <stdlib.h> #include <stdlib.h>
#include "includes.h" #include "includes.h"
MidiFifoSeq_t m_MidiSendFifo; MidiFifoSeq_t m_MidiSendFifo;
#define PRESET_BUFFER_SIZE (1024*20) #define PRESET_BUFFER_SIZE (1024*40)
static int m_presetCount = 0; static int m_presetCount = 0;
static uint8_t pStoreBuffer[PRESET_BUFFER_SIZE]; static uint8_t pStoreBuffer[PRESET_BUFFER_SIZE];
//static uint8_t* pStoreBuffer; //static uint8_t* pStoreBuffer;

View File

@ -22,7 +22,7 @@ void RGB_Y_TO_G()
#define UI_MODE_BG_COLOR 0x1925 #define UI_MODE_BG_COLOR 0x1925
#define UI_MODE_LINE_COLOR DARKBLUE #define UI_MODE_LINE_COLOR DARKBLUE
#define UI_MODE_TEXT_COLOR 0xFFFF #define UI_MODE_TEXT_COLOR 0xFFFF
#define UI_MODE_FONT_SIZE 24 #define UI_MODE_FONT_SIZE 16
void UI_DrawModeSelectScreen(void) void UI_DrawModeSelectScreen(void)
{ {
@ -57,43 +57,43 @@ void UI_DrawModeSelectScreen(void)
uint16_t x1 = LCD_ShowChinese_AutoAlign_Gradient( uint16_t x1 = LCD_ShowChinese_AutoAlign_Gradient(
btn_x, btn_x + btn_w, btn_x, btn_x + btn_w,
40 + (btn_h - 24) / 2, 40 + (btn_h - UI_MODE_FONT_SIZE) / 2,
(uint8_t*)"\xCD\xF2\xC4\xDC\xC4\xA3\xCA\xBD", //<2F><><EFBFBD><EFBFBD>ģʽ (uint8_t*)"\xCD\xF2\xC4\xDC\xC4\xA3\xCA\xBD", //<2F><><EFBFBD><EFBFBD>ģʽ
LCD_ALIGN_CENTER, LCD_ALIGN_CENTER,
UI_MODE_TEXT_COLOR, UI_MODE_TEXT_COLOR,
START_COLOR, END_COLOR, START_COLOR, END_COLOR,
24 UI_MODE_FONT_SIZE
); );
LCD_WR_PIC(x1-45, 40 + (btn_h - 24) / 2-5,40,30,gImage_FreeMode_Icon_40_30); LCD_WR_PIC(x1-45, 40 + (btn_h - UI_MODE_FONT_SIZE) / 2-5,40,30,gImage_FreeMode_Icon_40_30);
// ר???ģʽ<C4A3><CABD>Y=132??????? // ר???ģʽ<C4A3><CABD>Y=132???????
// LCD_FillRoundRect(btn_x, 132, btn_w, btn_h, btn_r, btn_color); // LCD_FillRoundRect(btn_x, 132, btn_w, btn_h, btn_r, btn_color);
LCD_FillRoundRectGradient(btn_x, 132, btn_w, btn_h, btn_r, START_COLOR, END_COLOR); LCD_FillRoundRectGradient(btn_x, 132, btn_w, btn_h, btn_r, START_COLOR, END_COLOR);
uint16_t x2 = LCD_ShowChinese_AutoAlign_Gradient( uint16_t x2 = LCD_ShowChinese_AutoAlign_Gradient(
btn_x, btn_x + btn_w, btn_x, btn_x + btn_w,
132 + (btn_h - 24) / 2, 132 + (btn_h - UI_MODE_FONT_SIZE) / 2,
(uint8_t *)"\xC6\xD5\xCD\xA8\xC4\xA3\xCA\xBD", // <20><>ͨģʽ (uint8_t *)"\xC6\xD5\xCD\xA8\xC4\xA3\xCA\xBD", // <20><>ͨģʽ
LCD_ALIGN_CENTER, LCD_ALIGN_CENTER,
UI_MODE_TEXT_COLOR, UI_MODE_TEXT_COLOR,
START_COLOR, END_COLOR, START_COLOR, END_COLOR,
24 UI_MODE_FONT_SIZE
); );
LCD_WR_PIC(x2-45, 132 + (btn_h - 24) / 2-5,40,30,gImage_NormalMode_Icon_40_30); LCD_WR_PIC(x2-45, 132 + (btn_h - UI_MODE_FONT_SIZE) / 2-5,40,30,gImage_NormalMode_Icon_40_30);
// <20><><EFBFBD><EFBFBD>ģʽ<C4A3><CABD>Y=224??????? // <20><><EFBFBD><EFBFBD>ģʽ<C4A3><CABD>Y=224???????
// LCD_FillRoundRect(btn_x, 224, btn_w, btn_h, btn_r, btn_color); // LCD_FillRoundRect(btn_x, 224, btn_w, btn_h, btn_r, btn_color);
LCD_FillRoundRectGradient(btn_x, 224, btn_w, btn_h, btn_r, START_COLOR, END_COLOR); LCD_FillRoundRectGradient(btn_x, 224, btn_w, btn_h, btn_r, START_COLOR, END_COLOR);
uint16_t x3 = LCD_ShowChinese_AutoAlign_Gradient( uint16_t x3 = LCD_ShowChinese_AutoAlign_Gradient(
btn_x, btn_x + btn_w, btn_x, btn_x + btn_w,
224 + (btn_h - 24) / 2, 224 + (btn_h - UI_MODE_FONT_SIZE) / 2,
(const uint8_t *)"\xD7\xA8\xD2\xB5\xC4\xA3\xCA\xBD", // רҵģʽ (const uint8_t *)"\xD7\xA8\xD2\xB5\xC4\xA3\xCA\xBD", // רҵģʽ
LCD_ALIGN_CENTER, LCD_ALIGN_CENTER,
UI_MODE_TEXT_COLOR, UI_MODE_TEXT_COLOR,
START_COLOR, END_COLOR, START_COLOR, END_COLOR,
24 UI_MODE_FONT_SIZE
); );
LCD_WR_PIC(x3-45, 224 + (btn_h - 24) / 2-5,40,30,gImage_ExpressMode_Icon_40_30); LCD_WR_PIC(x3-45, 224 + (btn_h - UI_MODE_FONT_SIZE) / 2-5,40,30,gImage_ExpressMode_Icon_40_30);
} }
const Touch_AreaTypeDef Touch_ModeSelect_Areas[] = { const Touch_AreaTypeDef Touch_ModeSelect_Areas[] = {
@ -234,13 +234,7 @@ void IdleProcess(DisplayTaskMessage_Type msg)
break; break;
case MSG_ID_BATTERY_VALUE: case MSG_ID_BATTERY_VALUE:
if(usb_charging_state) Draw_Status_Battery_Icon(msg.ID);
{
Draw_Battery_Icon(180, 5, msg.ID, 1, GREEN, BLACK, GREEN);
}else
{
Draw_Battery_Icon(180, 5, msg.ID, 1, WHITE, BLACK, WHITE);
}
break; break;
case MSG_ID_POWOFF_CHARG: case MSG_ID_POWOFF_CHARG:
@ -259,7 +253,7 @@ void IdleProcess(DisplayTaskMessage_Type msg)
{ {
uint8_t Info[10] = {0,}; uint8_t Info[10] = {0,};
sprintf ((char*)Info, "%d%%", msg.ID); sprintf ((char*)Info, "%d%%", msg.ID);
LCD_ShowString_AutoAlign(0,240,250,Info,LCD_ALIGN_CENTER,WHITE,BLACK,0,24); LCD_ShowString_AutoAlign(0,240,250,Info,LCD_ALIGN_CENTER,WHITE,BLACK,0,28);
} }
//else //else
//BSP_MainPowerEnable(0); //BSP_MainPowerEnable(0);
@ -270,7 +264,6 @@ void IdleProcess(DisplayTaskMessage_Type msg)
{ {
//LCD_ShowString(200, 0, Num_To_String(msg.DataU16[1],buff,3), RED, WHITE, 16, 0); //LCD_ShowString(200, 0, Num_To_String(msg.DataU16[1],buff,3), RED, WHITE, 16, 0);
uint8_t vol = msg.ID; uint8_t vol = msg.ID;
// uint8_t level;
if (vol <= 5) level = 0; if (vol <= 5) level = 0;
else if (vol <= 35) level = 1; else if (vol <= 35) level = 1;
else if (vol <= 65) level = 2; else if (vol <= 65) level = 2;

View File

@ -34,7 +34,7 @@ void DrawFader(Fader_t *f)
} }
// 底部文字 // 底部文字
LCD_ShowChinese_AutoAlign(x + 10, x + (w / 2) - 8, y + h + 20, LCD_ShowChinese_AutoAlign(x + 10, x + (w / 2) - 8, y + h + 20,
(uint8_t*)f->name, LCD_ALIGN_CENTER, FADER_TEXT, BLACK, 0, 16); (uint8_t*)f->name, LCD_ALIGN_CENTER, FADER_TEXT, BLACK, 0, 12);
// 画滑块并记录位置 // 画滑块并记录位置
uint16_t slider_y = CalcSliderY(f); uint16_t slider_y = CalcSliderY(f);
DrawFaderSlider(f, slider_y); DrawFaderSlider(f, slider_y);
@ -126,9 +126,9 @@ static void DrawFaderSlider(Fader_t *f, uint16_t slider_y)
{ {
uint16_t x = f->x, w = f->w, slider_h = 20; uint16_t x = f->x, w = f->w, slider_h = 20;
char buf[8]; char buf[8];
LCD_FillRoundRect(x+5, slider_y, w-10, slider_h, 5, BLUE); LCD_FillRoundRect(x+5, slider_y, w-10, slider_h, 5, COLOR_PRIMARY);
sprintf(buf, "%d", f->val); sprintf(buf, "%d", f->val);
LCD_ShowString_AutoAlign(x, x + w, slider_y, (uint8_t*)buf, LCD_ALIGN_CENTER, FADER_TEXT, BLUE, 0, 16); LCD_ShowString_AutoAlign(x, x + w, slider_y, (uint8_t*)buf, LCD_ALIGN_CENTER, FADER_TEXT, COLOR_PRIMARY, 0, 15);
} }
// ============================================================ // ============================================================
// 完整重绘滑块(槽背景 + 刻度线 + 滑块) // 完整重绘滑块(槽背景 + 刻度线 + 滑块)

View File

@ -77,7 +77,7 @@ void UI_Draw_Buttons(void)
#define TOP_TITLE_Y2 35 #define TOP_TITLE_Y2 35
#define TOP_TITLE_BG_COLOR BLACK // <20><><EFBFBD><EFBFBD>ɫ #define TOP_TITLE_BG_COLOR BLACK // <20><><EFBFBD><EFBFBD>ɫ
#define TOP_TITLE_TEXT_COLOR WHITE // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ #define TOP_TITLE_TEXT_COLOR WHITE // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ
#define TOP_TITLE_FONT_SIZE 16 // <20><><EFBFBD><EFBFBD><EFBFBD>С #define TOP_TITLE_FONT_SIZE 13 // 标题字号
#define TOP_TITLE_ALIGN LCD_ALIGN_CENTER // <20><><EFBFBD><EFBFBD> #define TOP_TITLE_ALIGN LCD_ALIGN_CENTER // <20><><EFBFBD><EFBFBD>
// ============================== // ==============================

View File

@ -43,10 +43,10 @@ GUI_SWITCH mGuiData_SystemSETTING[] = {
LEBEL_UI SystemSetting[] = LEBEL_UI SystemSetting[] =
{ {
{15, 230,35+10,60, (const uint8_t*)"\xB9\xCC\xBC\xFE\xB0\xE6\xB1\xBE", LCD_ALIGN_LEFT, WHITE, BLACK, 12, LCD_ALIGN_CENTER, WHITE, BLACK, 24, GUI_VERSION}, {15, 230,35+10,60, (const uint8_t*)"\xB9\xCC\xBC\xFE\xB0\xE6\xB1\xBE", LCD_ALIGN_LEFT, WHITE, BLACK, 13, LCD_ALIGN_CENTER, WHITE, BLACK, 11, GUI_VERSION},
{15, 230,95+10+5,60, (const uint8_t*)"\xC0\xB6\xD1\xC0\xC1\xB4\xBD\xD3", LCD_ALIGN_LEFT, WHITE, BLACK, 12, LCD_ALIGN_CENTER, WHITE, BLACK, 24, GUI_BLUETOOTH_SW}, {15, 230,95+10+5,60, (const uint8_t*)"\xC0\xB6\xD1\xC0\xC1\xB4\xBD\xD3", LCD_ALIGN_LEFT, WHITE, BLACK, 13, LCD_ALIGN_CENTER, WHITE, BLACK, 11, GUI_BLUETOOTH_SW},
{15, 230,160+10+5,60,(const uint8_t*)"\xD7\xD4\xB6\xAF\xB9\xD8\xBB\xFA", LCD_ALIGN_LEFT, WHITE, BLACK, 12, LCD_ALIGN_CENTER, WHITE, BLACK, 24, GUI_AUTOCLOSE}, {15, 230,160+10+5,60,(const uint8_t*)"\xD7\xD4\xB6\xAF\xB9\xD8\xBB\xFA", LCD_ALIGN_LEFT, WHITE, BLACK, 13, LCD_ALIGN_CENTER, WHITE, BLACK, 11, GUI_AUTOCLOSE},
{15, 230,225+10+5,60,(const uint8_t*)"\xBB\xD6\xB8\xB4\xB3\xF6\xB3\xA7\xC9\xE8\xD6\xC3", LCD_ALIGN_LEFT, WHITE, BLACK, 12, LCD_ALIGN_CENTER, WHITE, BLACK, 24, GUI_RESTORE}, {15, 230,225+10+5,60,(const uint8_t*)"\xBB\xD6\xB8\xB4\xB3\xF6\xB3\xA7\xC9\xE8\xD6\xC3", LCD_ALIGN_LEFT, WHITE, BLACK, 13, LCD_ALIGN_CENTER, WHITE, BLACK, 11, GUI_RESTORE},
}; };
// ============================== // ==============================

View File

@ -17,7 +17,7 @@ void Draw_Tab_Mode_Menu(const LEBEL_UI *UI, GUI_SWITCH *Group)
const uint16_t text_y = UI->y + 2; // 鏂囧<E98F82>????Y const uint16_t text_y = UI->y + 2; // 鏂囧<E98F82>????Y
// ===================== 棰滆壊瀹氫<E780B9>???? ===================== // ===================== 棰滆壊瀹氫<E780B9>???? =====================
uint16_t color_sel_bg = BLUE; // <20>????変腑鑳屾<E991B3>???? uint16_t color_sel_bg = COLOR_PRIMARY; // 选中背景
uint16_t color_unsel_bg = DARKLGRAY; // 鏈<E98F88>????変腑鑳屾<E991B3>???? uint16_t color_unsel_bg = DARKLGRAY; // 鏈<E98F88>????変腑鑳屾<E991B3>????
uint16_t color_text = UI->Text_fc; // 鏂囧瓧棰滆<E6A3B0>?? uint16_t color_text = UI->Text_fc; // 鏂囧瓧棰滆<E6A3B0>??
@ -386,13 +386,7 @@ void UI_SongMode_Process(DisplayTaskMessage_Type msg)
break; break;
case MSG_ID_BATTERY_VALUE: case MSG_ID_BATTERY_VALUE:
if(usb_charging_state) Draw_Status_Battery_Icon(percentage);
{
Draw_Battery_Icon(180, 5,percentage, 1, GREEN, BLACK, GREEN);
}else
{
Draw_Battery_Icon(180, 5, percentage, 1, WHITE, BLACK, WHITE);
}
break; break;
case MSG_ID_EC_VOL: case MSG_ID_EC_VOL:

View File

@ -6,7 +6,7 @@
#define UI_MODE_BG_COLOR 0x1925 // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԭͼ<D4AD><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ #define UI_MODE_BG_COLOR 0x1925 // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԭͼ<D4AD><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ
#define UI_MODE_LINE_COLOR DARKBLUE // <20>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD>ɫ<EFBFBD><C9AB><EFBFBD>ȱ<EFBFBD><C8B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> #define UI_MODE_LINE_COLOR DARKBLUE // <20>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD>ɫ<EFBFBD><C9AB><EFBFBD>ȱ<EFBFBD><C8B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
#define UI_MODE_TEXT_COLOR 0xFFFF // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD>ɫ #define UI_MODE_TEXT_COLOR 0xFFFF // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD>ɫ
#define UI_MODE_FONT_SIZE 24 // <20><><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֿ<EFBFBD><D6BF>޸<EFBFBD> #define UI_MODE_FONT_SIZE 16 // 模式按钮字号MiSans 16
// ============================== // ==============================
// <20><><EFBFBD>ɵ<EFBFBD><C9B5><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD> // <20><><EFBFBD>ɵ<EFBFBD><C9B5><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>

View File

@ -1,6 +1,6 @@
#include "includes.h" #include "includes.h"
extern uint8_t level;
// ============================================== // ==============================================
// <20><><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EBB6A8> // <20><><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EBB6A8>
@ -78,7 +78,7 @@ void label_top()
const uint16_t btn_color = /*DARKLGRAY*/0x2988; // 深灰<E6B7B1>????? const uint16_t btn_color = /*DARKLGRAY*/0x2988; // 深灰<E6B7B1>?????
//LCD_FillByColor(0,0,240,25,BLACK); //LCD_FillByColor(0,0,240,25,BLACK);
//LCD_WR_PIC(5,0,12,20,gImage_bar); //LCD_WR_PIC(5,0,12,20,gImage_bar);
Draw_Volume_Bar(5, 5, 3,1, WHITE,GRAY); Draw_Volume_Bar(5, 5, level, 1, WHITE, GRAY);
LCD_DrawLine(0, 26, 240, 26, btn_color); LCD_DrawLine(0, 26, 240, 26, btn_color);
Show_BL_Icon(mGuiData[GUI_BL_SW].Current); Show_BL_Icon(mGuiData[GUI_BL_SW].Current);
Show_Battery_Icon(usb_charging_state); Show_Battery_Icon(usb_charging_state);
@ -124,15 +124,17 @@ void Show_BL_Icon(uint8_t value)
BSP_BlueToothPowerEnable (value); BSP_BlueToothPowerEnable (value);
} }
void Draw_Status_Battery_Icon(uint8_t battery_percent)
{
/* 需求图:状态栏电池始终为白色(含 USB 充电连接时) */
Draw_Battery_Icon(UI_STATUS_BATTERY_X, UI_STATUS_BATTERY_Y,
battery_percent, 1, WHITE, BLACK, WHITE);
}
void Show_Battery_Icon(uint8_t flag) void Show_Battery_Icon(uint8_t flag)
{ {
if(flag) (void)flag;
{ Draw_Status_Battery_Icon(percentage);
Draw_Battery_Icon(180, 5, percentage, 1, GREEN, BLACK, GREEN);
}else
{
Draw_Battery_Icon(180, 5, percentage, 1, WHITE, BLACK, WHITE);
}
} }
@ -552,7 +554,7 @@ void label_Tab_Select_ui(const LEBEL_UI *UI,GUI_SWITCH * Group)
uint16_t x2 = 10+40+20; uint16_t x2 = 10+40+20;
uint16_t x3 = 10+40+20+40+20; uint16_t x3 = 10+40+20+40+20;
uint16_t x4 = 10+40+20+40+20+40+20; uint16_t x4 = 10+40+20+40+20+40+20;
uint8_t TextSize = 12; uint8_t TextSize = 8;
char *str1 = "\xCD\xF2\xC4\xDC\xC4\xA3\xCA\xBD\x00"; //FreeMode char *str1 = "\xCD\xF2\xC4\xDC\xC4\xA3\xCA\xBD\x00"; //FreeMode
char *str2 = "\xC6\xD5\xCD\xA8\xC4\xA3\xCA\xBD\x00"; //NormalMode char *str2 = "\xC6\xD5\xCD\xA8\xC4\xA3\xCA\xBD\x00"; //NormalMode
char *str3 = "\xD7\xA8\xD2\xB5\xC4\xA3\xCA\xBD\x00"; //ExpressMode char *str3 = "\xD7\xA8\xD2\xB5\xC4\xA3\xCA\xBD\x00"; //ExpressMode
@ -571,7 +573,7 @@ void label_Tab_Select_ui(const LEBEL_UI *UI,GUI_SWITCH * Group)
// 文字:选中=蓝色,未选中=白色 // 文字:选中=蓝色,未选中=白色
LCD_ShowChinese_AutoAlign(x1, x1+30-1, Text_Y, (const uint8_t *)str1,LCD_ALIGN_CENTER, WHITE, BLACK,0,TextSize); LCD_ShowChinese_AutoAlign(x1, x1+30-1, Text_Y, (const uint8_t *)str1,LCD_ALIGN_CENTER, WHITE, BLACK,0,TextSize);
LCD_ShowChinese_AutoAlign(x2, x2+30-1, Text_Y, (const uint8_t *)str2,LCD_ALIGN_CENTER, BLUE, BLACK,0,TextSize); LCD_ShowChinese_AutoAlign(x2, x2+30-1, Text_Y, (const uint8_t *)str2,LCD_ALIGN_CENTER, COLOR_PRIMARY, BLACK,0,TextSize);
LCD_ShowChinese_AutoAlign(x3, x3+30-1, Text_Y, (const uint8_t *)str3,LCD_ALIGN_CENTER, WHITE, BLACK,0,TextSize); LCD_ShowChinese_AutoAlign(x3, x3+30-1, Text_Y, (const uint8_t *)str3,LCD_ALIGN_CENTER, WHITE, BLACK,0,TextSize);
LCD_ShowChinese_AutoAlign(x4, x4+30-1, Text_Y, (const uint8_t *)str4,LCD_ALIGN_CENTER, WHITE, BLACK,0,TextSize); LCD_ShowChinese_AutoAlign(x4, x4+30-1, Text_Y, (const uint8_t *)str4,LCD_ALIGN_CENTER, WHITE, BLACK,0,TextSize);
break; break;
@ -583,7 +585,7 @@ void label_Tab_Select_ui(const LEBEL_UI *UI,GUI_SWITCH * Group)
LCD_WR_PIC(x4, Icon_Y,30,24,gImage_Setting_notSelect); LCD_WR_PIC(x4, Icon_Y,30,24,gImage_Setting_notSelect);
LCD_ShowChinese_AutoAlign(x1, x1+30-1, Text_Y, (const uint8_t *)str1,LCD_ALIGN_CENTER, WHITE, BLACK,0,TextSize); LCD_ShowChinese_AutoAlign(x1, x1+30-1, Text_Y, (const uint8_t *)str1,LCD_ALIGN_CENTER, WHITE, BLACK,0,TextSize);
LCD_ShowChinese_AutoAlign(x2, x2+30-1, Text_Y, (const uint8_t *)str2,LCD_ALIGN_CENTER, WHITE, BLACK,0,TextSize); LCD_ShowChinese_AutoAlign(x2, x2+30-1, Text_Y, (const uint8_t *)str2,LCD_ALIGN_CENTER, WHITE, BLACK,0,TextSize);
LCD_ShowChinese_AutoAlign(x3, x3+30-1, Text_Y, (const uint8_t *)str3,LCD_ALIGN_CENTER, BLUE, BLACK,0,TextSize); LCD_ShowChinese_AutoAlign(x3, x3+30-1, Text_Y, (const uint8_t *)str3,LCD_ALIGN_CENTER, COLOR_PRIMARY, BLACK,0,TextSize);
LCD_ShowChinese_AutoAlign(x4, x4+30-1, Text_Y, (const uint8_t *)str4,LCD_ALIGN_CENTER, WHITE, BLACK,0,TextSize); LCD_ShowChinese_AutoAlign(x4, x4+30-1, Text_Y, (const uint8_t *)str4,LCD_ALIGN_CENTER, WHITE, BLACK,0,TextSize);
break; break;
case 2: // 万能选中 case 2: // 万能选中
@ -591,7 +593,7 @@ void label_Tab_Select_ui(const LEBEL_UI *UI,GUI_SWITCH * Group)
LCD_WR_PIC(x2, Icon_Y,30,22,gImage_NormalMode_notSelect); LCD_WR_PIC(x2, Icon_Y,30,22,gImage_NormalMode_notSelect);
LCD_WR_PIC(x3, Icon_Y,30,22,gImage_ExpressMode_notSelect); LCD_WR_PIC(x3, Icon_Y,30,22,gImage_ExpressMode_notSelect);
LCD_WR_PIC(x4, Icon_Y,30,24,gImage_Setting_notSelect); LCD_WR_PIC(x4, Icon_Y,30,24,gImage_Setting_notSelect);
LCD_ShowChinese_AutoAlign(x1, x1+30-1, Text_Y, (const uint8_t *)str1,LCD_ALIGN_CENTER, BLUE, BLACK,0,TextSize); LCD_ShowChinese_AutoAlign(x1, x1+30-1, Text_Y, (const uint8_t *)str1,LCD_ALIGN_CENTER, COLOR_PRIMARY, BLACK,0,TextSize);
LCD_ShowChinese_AutoAlign(x2, x2+30-1, Text_Y, (const uint8_t *)str2,LCD_ALIGN_CENTER, WHITE, BLACK,0,TextSize); LCD_ShowChinese_AutoAlign(x2, x2+30-1, Text_Y, (const uint8_t *)str2,LCD_ALIGN_CENTER, WHITE, BLACK,0,TextSize);
LCD_ShowChinese_AutoAlign(x3, x3+30-1, Text_Y, (const uint8_t *)str3,LCD_ALIGN_CENTER, WHITE, BLACK,0,TextSize); LCD_ShowChinese_AutoAlign(x3, x3+30-1, Text_Y, (const uint8_t *)str3,LCD_ALIGN_CENTER, WHITE, BLACK,0,TextSize);
LCD_ShowChinese_AutoAlign(x4, x4+30-1, Text_Y, (const uint8_t *)str4,LCD_ALIGN_CENTER, WHITE, BLACK,0,TextSize); LCD_ShowChinese_AutoAlign(x4, x4+30-1, Text_Y, (const uint8_t *)str4,LCD_ALIGN_CENTER, WHITE, BLACK,0,TextSize);
@ -605,7 +607,7 @@ void label_Tab_Select_ui(const LEBEL_UI *UI,GUI_SWITCH * Group)
LCD_ShowChinese_AutoAlign(x1, x1+30-1, Text_Y, (const uint8_t *)str1,LCD_ALIGN_CENTER, WHITE, BLACK,0,TextSize); LCD_ShowChinese_AutoAlign(x1, x1+30-1, Text_Y, (const uint8_t *)str1,LCD_ALIGN_CENTER, WHITE, BLACK,0,TextSize);
LCD_ShowChinese_AutoAlign(x2, x2+30-1, Text_Y, (const uint8_t *)str2,LCD_ALIGN_CENTER, WHITE, BLACK,0,TextSize); LCD_ShowChinese_AutoAlign(x2, x2+30-1, Text_Y, (const uint8_t *)str2,LCD_ALIGN_CENTER, WHITE, BLACK,0,TextSize);
LCD_ShowChinese_AutoAlign(x3, x3+30-1, Text_Y, (const uint8_t *)str3,LCD_ALIGN_CENTER, WHITE, BLACK,0,TextSize); LCD_ShowChinese_AutoAlign(x3, x3+30-1, Text_Y, (const uint8_t *)str3,LCD_ALIGN_CENTER, WHITE, BLACK,0,TextSize);
LCD_ShowChinese_AutoAlign(x4, x4+30-1, Text_Y, (const uint8_t *)str4,LCD_ALIGN_CENTER, BLUE, BLACK,0,TextSize); LCD_ShowChinese_AutoAlign(x4, x4+30-1, Text_Y, (const uint8_t *)str4,LCD_ALIGN_CENTER, COLOR_PRIMARY, BLACK,0,TextSize);
break; break;
} }
} }
@ -622,7 +624,7 @@ void Draw_Tab_Section_Menu(const LEBEL_UI *UI, TAB_SECTION_INDEX select_tab)
const uint16_t start_y = UI->y + 28 - 6; // 起<>?<3F>Y const uint16_t start_y = UI->y + 28 - 6; // 起<>?<3F>Y
const uint16_t text_y = UI->y + 28 - 3; // 文字Y const uint16_t text_y = UI->y + 28 - 3; // 文字Y
// ===================== 颜色定义 ===================== // ===================== 颜色定义 =====================
uint16_t color_sel_bg = BLUE; // 选中背景 uint16_t color_sel_bg = COLOR_PRIMARY; // 选中背景
// uint16_t color_unsel_bg = BLACK; // <20>?选中背景 // uint16_t color_unsel_bg = BLACK; // <20>?选中背景
uint16_t color_text = UI->Text_fc; // 文字颜色 uint16_t color_text = UI->Text_fc; // 文字颜色
@ -982,7 +984,7 @@ void Draw_System_Item_List(const LEBEL_UI *UI, GUI_SWITCH *Group)
case GUI_VERSION: case GUI_VERSION:
LCD_WR_PIC(UI->x+10, UI->y+18,20,20,gImage_FimewareVection); LCD_WR_PIC(UI->x+10, UI->y+18,20,20,gImage_FimewareVection);
sprintf (Info, "%d.%d.%d", Version[0], Version[1],Version[2]); sprintf (Info, "%d.%d.%d", Version[0], Version[1],Version[2]);
LCD_ShowString_AutoAlign_Gradient(UI->x+100,UI->x+100+110, UI->y+UI->h/2-8-5,(const uint8_t*)Info,LCD_ALIGN_CENTER, UI->Text_fc,START_COLOR, END_COLOR,24); LCD_ShowString_AutoAlign_Gradient(UI->x+100,UI->x+100+110, UI->y+UI->h/2-8-5,(const uint8_t*)Info,LCD_ALIGN_CENTER, UI->Text_fc,START_COLOR, END_COLOR,11);
break; break;
case GUI_BLUETOOTH_SW: case GUI_BLUETOOTH_SW:
LCD_WR_PIC(UI->x+10, UI->y+18,20,20,gImage_BlueTooth); LCD_WR_PIC(UI->x+10, UI->y+18,20,20,gImage_BlueTooth);
@ -990,10 +992,10 @@ void Draw_System_Item_List(const LEBEL_UI *UI, GUI_SWITCH *Group)
LCD_DrawArrow_Right(UI->x+100+95, UI->y+UI->h/2-8+12-5, 12, WHITE, GRAY); LCD_DrawArrow_Right(UI->x+100+95, UI->y+UI->h/2-8+12-5, 12, WHITE, GRAY);
if(Group->Current) if(Group->Current)
{ {
LCD_ShowChinese_AutoAlign_Gradient(UI->x+100,UI->x+100+110, UI->y+UI->h/2-8-5,(const uint8_t*)"\xBF\xAA",LCD_ALIGN_CENTER, UI->Text_fc,START_COLOR, END_COLOR,24); LCD_ShowChinese_AutoAlign_Gradient(UI->x+100,UI->x+100+110, UI->y+UI->h/2-8-5,(const uint8_t*)"\xBF\xAA",LCD_ALIGN_CENTER, UI->Text_fc,START_COLOR, END_COLOR,11);
}else }else
{ {
LCD_ShowChinese_AutoAlign_Gradient(UI->x+100,UI->x+100+110, UI->y+UI->h/2-8-5,(const uint8_t*)"\xB9\xD8",LCD_ALIGN_CENTER, UI->Text_fc,START_COLOR, END_COLOR,24); LCD_ShowChinese_AutoAlign_Gradient(UI->x+100,UI->x+100+110, UI->y+UI->h/2-8-5,(const uint8_t*)"\xB9\xD8",LCD_ALIGN_CENTER, UI->Text_fc,START_COLOR, END_COLOR,11);
} }
BSP_BlueToothPowerEnable (Group->Current); BSP_BlueToothPowerEnable (Group->Current);
mGuiData[GUI_BL_SW].Current = Group->Current; mGuiData[GUI_BL_SW].Current = Group->Current;
@ -1014,11 +1016,11 @@ void Draw_System_Item_List(const LEBEL_UI *UI, GUI_SWITCH *Group)
sprintf (Info, "%d",AutoCloseTime); sprintf (Info, "%d",AutoCloseTime);
// uint16_t x = LCD_ShowChinese_AutoAlign(UI->x+100,UI->x+100+110, UI->y+UI->h/2-8-5,(const uint8_t*)"\xB7\xD6\xD6\xD3",LCD_ALIGN_CENTER, UI->Text_fc,UI->Text_bc,0,24); // uint16_t x = LCD_ShowChinese_AutoAlign(UI->x+100,UI->x+100+110, UI->y+UI->h/2-8-5,(const uint8_t*)"\xB7\xD6\xD6\xD3",LCD_ALIGN_CENTER, UI->Text_fc,UI->Text_bc,0,24);
// LCD_ShowString_AutoAlign(UI->x+100,UI->x+100+110, UI->y+UI->h/2-8-5,(const uint8_t*)Info,LCD_ALIGN_CENTER, UI->Text_fc,UI->Text_bc,0,24); // LCD_ShowString_AutoAlign(UI->x+100,UI->x+100+110, UI->y+UI->h/2-8-5,(const uint8_t*)Info,LCD_ALIGN_CENTER, UI->Text_fc,UI->Text_bc,0,24);
LCD_ShowString(UI->x+100+20,UI->y+UI->h/2-8-5, (uint8_t *)Info, UI->Text_fc, UI->Text_bc, 24, 1); LCD_ShowString(UI->x+100+20,UI->y+UI->h/2-8-5, (uint8_t *)Info, UI->Text_fc, UI->Text_bc, 11, 1);
LCD_ShowChineseString(UI->x+100+20+25, UI->y+UI->h/2-8-5,(uint8_t*)"\xB7\xD6\xD6\xD3", UI->Text_fc,UI->Text_bc,24,1); LCD_ShowChineseString(UI->x+100+20+25, UI->y+UI->h/2-8-5,(uint8_t*)"\xB7\xD6\xD6\xD3", UI->Text_fc,UI->Text_bc,11,1);
}else }else
{ {
LCD_ShowChinese_AutoAlign(UI->x+100,UI->x+100+110, UI->y+UI->h/2-8-5,(uint8_t*)"\xB9\xD8",LCD_ALIGN_CENTER, UI->Text_fc,UI->Text_bc,1,24); LCD_ShowChinese_AutoAlign(UI->x+100,UI->x+100+110, UI->y+UI->h/2-8-5,(uint8_t*)"\xB9\xD8",LCD_ALIGN_CENTER, UI->Text_fc,UI->Text_bc,1,11);
} }
if(nvm->param.AutoCloseTime != Group->Current) if(nvm->param.AutoCloseTime != Group->Current)

View File

@ -27,6 +27,12 @@ void CallUI_RestoreSelect(void);
#define UI_STATUS_BAR_H 26
#define UI_STATUS_BATTERY_X 180
#define UI_STATUS_BATTERY_H 11
#define UI_STATUS_BATTERY_Y ((UI_STATUS_BAR_H - UI_STATUS_BATTERY_H) / 2)
void Draw_Status_Battery_Icon(uint8_t battery_percent);
void Show_Battery_Icon(uint8_t flag); void Show_Battery_Icon(uint8_t flag);
void Show_BL_Icon(uint8_t value); void Show_BL_Icon(uint8_t value);

View File

@ -4,6 +4,102 @@
#include "w25q128.h" #include "w25q128.h"
#define PIC_BATCH_SIZE 1024 #define PIC_BATCH_SIZE 1024
static uint8_t LCD_CnFontMetrics(uint8_t sizey, uint8_t *sizex, uint16_t *typeface_num)
{
switch (sizey)
{
case 8: *sizex = 8; *typeface_num = 8; return 1;
case 11: *sizex = 11; *typeface_num = 22; return 1;
case 12: *sizex = 12; *typeface_num = 24; return 1;
case 13: *sizex = 13; *typeface_num = 26; return 1;
case 15: *sizex = 15; *typeface_num = 30; return 1;
case 16: *sizex = 16; *typeface_num = 32; return 1;
case 24: *sizex = 24; *typeface_num = 72; return 1;
case 28: *sizex = 28; *typeface_num = 112; return 1;
default: return 0;
}
}
static uint8_t LCD_GetCnFontByte(uint8_t sizey, uint8_t index, uint16_t i)
{
switch (sizey)
{
case 8: return Chinese_font_8[index][i];
case 11: return Chinese_font_11[index][i];
case 12: return Chinese_font_12[index][i];
case 13: return Chinese_font_13[index][i];
case 15: return Chinese_font_15[index][i];
case 16: return Chinese_font_16[index][i];
case 24: return Chinese_font_24[index][i];
case 28: return Chinese_font_28[index][i];
default: return 0;
}
}
static uint8_t LCD_GetAsciiFontByte(uint8_t sizey, uint8_t num, uint16_t i)
{
switch (sizey)
{
case 8: return ascii_84[num][i];
case 11: return ascii_115[num][i];
case 12: return ascii_126[num][i];
case 13: return ascii_1306[num][i];
case 15: return ascii_157[num][i];
case 16: return ascii_1608[num][i];
case 24: return ascii_2412[num][i];
case 28: return ascii_2814[num][i];
default: return 0;
}
}
static const char (*LCD_GetChsTable(uint8_t sizey))[2]
{
switch (sizey)
{
case 8: return CHS8Table;
case 11: return CHS11Table;
case 12: return CHS12Table;
case 13: return CHS13Table;
case 15: return CHS15Table;
case 16: return CHS16Table;
case 24: return CHS24Table;
case 28: return CHS24Table;
default: return NULL;
}
}
static uint16_t LCD_GetChsTableSize(uint8_t sizey)
{
switch (sizey)
{
case 8: return (uint16_t)(sizeof(CHS8Table) / 2);
case 11: return (uint16_t)(sizeof(CHS11Table) / 2);
case 12: return (uint16_t)(sizeof(CHS12Table) / 2);
case 13: return (uint16_t)(sizeof(CHS13Table) / 2);
case 15: return (uint16_t)(sizeof(CHS15Table) / 2);
case 16: return (uint16_t)(sizeof(CHS16Table) / 2);
case 24: return (uint16_t)(sizeof(CHS24Table) / 2);
case 28: return (uint16_t)(sizeof(CHS24Table) / 2);
default: return 0;
}
}
static uint8_t LCD_GetAsciiMetrics(uint8_t size, uint8_t *char_width, uint8_t *char_height)
{
*char_height = size;
switch (size)
{
case 8: *char_width = 4; return 1;
case 11: *char_width = 5; return 1;
case 12: *char_width = 6; return 1;
case 13: *char_width = 6; return 1;
case 15: *char_width = 7; return 1;
case 16: *char_width = 8; return 1;
case 24: *char_width = 12; return 1;
case 28: *char_width = 14; return 1;
default: return 0;
}
}
//r:0-31 g:0-63 b:0-31 //r:0-31 g:0-63 b:0-31
uint16_t RGB(int r,int g,int b) uint16_t RGB(int r,int g,int b)
@ -407,9 +503,14 @@ void LCD_ShowChar(uint16_t x, uint16_t y, uint8_t num, uint16_t fc, uint16_t bc,
uint16_t i, TypefaceNum; uint16_t i, TypefaceNum;
uint16_t x0 = x; uint16_t x0 = x;
sizex = sizey / 2; uint8_t char_h;
TypefaceNum = (sizex / 8 + ((sizex % 8) ? 1 : 0)) * sizey;
num = num - ' '; num = num - ' ';
if (!LCD_GetAsciiMetrics(sizey, &sizex, &char_h))
{
return;
}
TypefaceNum = (sizex / 8 + ((sizex % 8) ? 1 : 0)) * sizey;
// 一次性设置窗口LCD地址自动递增无需每像素都设 // 一次性设置窗口LCD地址自动递增无需每像素都设
LCD_SetWindow(x, y, x + sizex - 1, y + sizey - 1); LCD_SetWindow(x, y, x + sizex - 1, y + sizey - 1);
@ -425,11 +526,7 @@ void LCD_ShowChar(uint16_t x, uint16_t y, uint8_t num, uint16_t fc, uint16_t bc,
for (i = 0; i < TypefaceNum; i++) for (i = 0; i < TypefaceNum; i++)
{ {
temp = LCD_GetAsciiFontByte(sizey, num, i);
if (sizey == 16) temp = ascii_1608[num][i];
else if (sizey == 13) temp = ascii_1306[num][i];
else if (sizey == 24) temp = ascii_2412[num][i];
else { LCD_DC_Clr(); return; }
for (uint8_t t = 0; t < 8; t++) for (uint8_t t = 0; t < 8; t++)
{ {
@ -456,13 +553,10 @@ void LCD_ShowChar(uint16_t x, uint16_t y, uint8_t num, uint16_t fc, uint16_t bc,
} }
else // 叠加模式(保持逐点画,不改动) else // 叠加模式(保持逐点画,不改动)
{ {
uint8_t temp;
for (i = 0; i < TypefaceNum; i++) for (i = 0; i < TypefaceNum; i++)
{ {
uint8_t temp; temp = LCD_GetAsciiFontByte(sizey, num, i);
if (sizey == 16) temp = ascii_1608[num][i];
else if (sizey == 13) temp = ascii_1306[num][i];
else if (sizey == 24) temp = ascii_2412[num][i];
else { LCD_DC_Clr(); return; }
for (uint8_t t = 0; t < 8; t++) for (uint8_t t = 0; t < 8; t++)
{ {
@ -488,15 +582,8 @@ void LCD_ShowChinese(uint16_t x, uint16_t y, uint8_t index, uint16_t fc, uint16_
uint16_t i, TypefaceNum = 0; uint16_t i, TypefaceNum = 0;
uint16_t x0 = x; uint16_t x0 = x;
switch(sizey) if (!LCD_CnFontMetrics(sizey, &sizex, &TypefaceNum))
{ return;
case 11:sizex = 11;TypefaceNum = 22;break;
case 12:sizex = 12;TypefaceNum = 24;break;
case 13:sizex = 13;TypefaceNum = 26;break;
case 16:sizex = 16;TypefaceNum = 32;break;
case 24:sizex = 24;TypefaceNum = 72;break;
default: return;break;
}
// 一次性设置窗口 // 一次性设置窗口
LCD_SetWindow(x, y, x + sizex - 1, y + sizey - 1); LCD_SetWindow(x, y, x + sizex - 1, y + sizey - 1);
@ -512,14 +599,7 @@ void LCD_ShowChinese(uint16_t x, uint16_t y, uint8_t index, uint16_t fc, uint16_
for (i = 0; i < TypefaceNum; i++) for (i = 0; i < TypefaceNum; i++)
{ {
switch(sizey) temp = LCD_GetCnFontByte(sizey, index, i);
{
case 11:temp = Chinese_font_11[index][i];break;
case 12:temp = Chinese_font_12[index][i];break;
case 13:temp = Chinese_font_13[index][i];break;
case 16:temp = Chinese_font_16[index][i];break;
case 24:temp = Chinese_font_24[index][i];break;
}
for (uint8_t t = 0; t < 8; t++) for (uint8_t t = 0; t < 8; t++)
{ {
@ -546,17 +626,10 @@ void LCD_ShowChinese(uint16_t x, uint16_t y, uint8_t index, uint16_t fc, uint16_
} }
else // 叠加模式(保持逐点画) else // 叠加模式(保持逐点画)
{ {
uint8_t temp;
for (i = 0; i < TypefaceNum; i++) for (i = 0; i < TypefaceNum; i++)
{ {
uint8_t temp; temp = LCD_GetCnFontByte(sizey, index, i);
switch(sizey)
{
case 11:temp = Chinese_font_11[index][i];break;
case 12:temp = Chinese_font_12[index][i];break;
case 13:temp = Chinese_font_13[index][i];break;
case 16:temp = Chinese_font_16[index][i];break;
case 24:temp = Chinese_font_24[index][i];break;
}
for (uint8_t t = 0; t < 8; t++) for (uint8_t t = 0; t < 8; t++)
{ {
@ -830,61 +903,61 @@ void LCD_ShowChineseString(uint16_t x, uint16_t y, uint8_t *str, uint16_t fc, ui
{ {
uint16_t i; uint16_t i;
int slen = GetLength((const char*)str); int slen = GetLength((const char*)str);
char TmpS[2];// 临时存储2字节的缓冲区 char TmpS[2];
const char (*codeTab)[2] = NULL; // 指向字库表的指针每个条目2字节 const char (*codeTab)[2] = NULL;
uint8_t xStep = 0;// 字符水平步进距离 uint8_t xStep = 0;
uint16_t tabSize;
switch (sizey)// 根据字体大小选择对应的字库和步进 codeTab = LCD_GetChsTable(sizey);
if (codeTab == NULL)
{ {
case 11: return;
codeTab = CHS11Table;
xStep = 11;
break;
case 12:
codeTab = CHS12Table;
xStep = 12;
break;
case 13:
codeTab = CHS13Table;
xStep = 13;
break;
case 16:
codeTab = CHS16Table;
xStep = 16;
break;
case 24:
codeTab = CHS24Table;
xStep = 24;
break;
default:
return;
} }
for (i = 0; i < slen; i++)// 遍历字符串中的每个字节 tabSize = LCD_GetChsTableSize(sizey);
if (!LCD_CnFontMetrics(sizey, &xStep, &i))
{ {
memcpy(TmpS, str, 1); // 拷贝1个字节到临时缓冲区 return;
}
/* xStep is character cell width (= sizey for square CN glyphs). */
xStep = sizey;
if ((uint8_t)TmpS[0] > 0x80) // 检查是否为中文字符的第一个字节(GBK编码中>0x80) for (i = 0; i < (uint16_t)slen; )
{
if ((uint8_t)str[0] > 0x80)
{ {
memcpy(TmpS, str, 2); // 拷贝完整的2字节中文字符 uint16_t j;
uint8_t found = 0;
for (uint16_t j = 0; j < 1024; j++)// 在字库中查找该字符 if (i + 1 >= (uint16_t)slen)
{
break;
}
TmpS[0] = (char)str[0];
TmpS[1] = (char)str[1];
for (j = 0; j < tabSize; j++)
{ {
// 比较两个字节是否匹配字库中的字符
if (TmpS[0] == codeTab[j][0] && TmpS[1] == codeTab[j][1]) if (TmpS[0] == codeTab[j][0] && TmpS[1] == codeTab[j][1])
{ {
//F 找到匹配字符,在屏幕上显示 LCD_ShowChinese(x, y, j, fc, bc, sizey, mode);
LCD_ShowChinese(x, y, j, fc, bc, sizey, mode); x += xStep;
x += xStep; // x坐标向右移动一个字符宽度 found = 1;
str += 2; // 字符串指针前进2字节(跳过当前中文字符) break;
i++; // 中文字符占2字节,循环计数器额外+1
break; // 跳出字库查找循环
} }
} }
/* Always advance past this GBK character, even if glyph is missing. */
str += 2;
i += 2;
(void)found;
}
else
{
str += 1;
i += 1;
}
} }
} }
}
/****************************************************************************** /******************************************************************************
******************************************************************************/ ******************************************************************************/
@ -930,14 +1003,9 @@ uint16_t LCD_ShowMixedString(uint16_t x1, uint16_t x2, uint16_t y, uint8_t *str,
uint8_t xStepAscii = sizey / 2; uint8_t xStepAscii = sizey / 2;
uint16_t draw_x; uint16_t draw_x;
switch(sizey) codeTab = LCD_GetChsTable(sizey);
{ if (codeTab == NULL)
case 13: codeTab = CHS13Table; break; return x1;
case 12: codeTab = CHS12Table; break;
case 16: codeTab = CHS16Table; break;
case 24: codeTab = CHS24Table; break;
default: return x1;
}
// 先计算字符串总像素宽度再根据对齐方式确定起始X坐标 // 先计算字符串总像素宽度再根据对齐方式确定起始X坐标
uint16_t total_width = LCD_GetMixedStringWidth(str, sizey); uint16_t total_width = LCD_GetMixedStringWidth(str, sizey);
@ -969,10 +1037,7 @@ uint16_t LCD_ShowMixedString(uint16_t x1, uint16_t x2, uint16_t y, uint8_t *str,
uint8_t ch_low = str[1]; uint8_t ch_low = str[1];
if(ch_low == 0) break; if(ch_low == 0) break;
uint16_t maxIndex = (sizey == 12) ? (sizeof(CHS12Table)/2) : uint16_t maxIndex = LCD_GetChsTableSize(sizey);
(sizey == 13) ? (sizeof(CHS13Table)/2) :
(sizey == 16) ? (sizeof(CHS16Table)/2) :
(sizey == 24) ? (sizeof(CHS24Table)/2) : 0;
for(uint16_t j = 0; j < maxIndex; j++) for(uint16_t j = 0; j < maxIndex; j++)
{ {
@ -1215,29 +1280,8 @@ uint16_t LCD_ShowString_AutoAlign(uint16_t x1, uint16_t x2, uint16_t y, const ui
{ {
uint8_t CHAR_WIDTH, CHAR_HEIGHT; uint8_t CHAR_WIDTH, CHAR_HEIGHT;
switch(size) if (!LCD_GetAsciiMetrics(size, &CHAR_WIDTH, &CHAR_HEIGHT))
{ return 0;
case 12:CHAR_WIDTH = 6; CHAR_HEIGHT = 12;break;
case 16:CHAR_WIDTH = 8; CHAR_HEIGHT = 16;break;
case 24:CHAR_WIDTH = 12; CHAR_HEIGHT = 24;break;
default :return 0; break;
}
// // 根据字体尺寸设置字符宽度
// if(size == 16)
// {
// CHAR_WIDTH = 8;
// CHAR_HEIGHT = 16;
// }
// else if(size == 24)
// {
// CHAR_WIDTH = 12;
// CHAR_HEIGHT = 24;
// }
// else
// {
// return 0;
// }
uint16_t str_len = 0; uint16_t str_len = 0;
uint16_t str_total_width; uint16_t str_total_width;
@ -1420,14 +1464,8 @@ uint16_t LCD_ShowString_AutoAlign_Gradient(uint16_t x1, uint16_t x2, uint16_t y,
{ {
uint8_t CHAR_WIDTH, CHAR_HEIGHT; uint8_t CHAR_WIDTH, CHAR_HEIGHT;
switch(size) if (!LCD_GetAsciiMetrics(size, &CHAR_WIDTH, &CHAR_HEIGHT))
{ return 0;
case 12:CHAR_WIDTH = 6; CHAR_HEIGHT = 12;break;
case 16:CHAR_WIDTH = 8; CHAR_HEIGHT = 16;break;
case 24:CHAR_WIDTH = 12; CHAR_HEIGHT = 24;break;
default :return 0; break;
}
uint16_t str_len = 0; uint16_t str_len = 0;
uint16_t str_total_width; uint16_t str_total_width;
@ -1706,36 +1744,116 @@ void LCD_DrawMinus_RoundBox(uint16_t x, uint16_t y, uint8_t size, uint8_t radius
/** /**
* @brief 5 * @brief
* @param x: X坐标 */
* @param y: Y坐标 static void LCD_FillRoundTopRect(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t r, uint16_t color)
* @param volume_level: (0-50=5=) {
* @param color_on: RGB值WHITE/0xFFFF if(w == 0 || h == 0)
* @param color_off: RGB值BLACK/0x0000 {
return;
}
if(r > (w / 2))
{
r = w / 2;
}
if(r > h)
{
r = h;
}
if(r == 0)
{
LCD_FillByColor(x, y, x + w, y + h, color);
return;
}
LCD_FillRoundRect(x, y, w, h, r, color);
if(h > r)
{
LCD_FillByColor(x, y + h - r, x + w, y + h, color);
}
}
/**
* @brief RGB565
*/
static uint16_t LCD_BlendColor565(uint16_t c0, uint16_t c1, uint8_t num, uint8_t den)
{
uint16_t r0 = (c0 >> 11) & 0x1F;
uint16_t g0 = (c0 >> 5) & 0x3F;
uint16_t b0 = c0 & 0x1F;
uint16_t r1 = (c1 >> 11) & 0x1F;
uint16_t g1 = (c1 >> 5) & 0x3F;
uint16_t b1 = c1 & 0x1F;
uint16_t r;
uint16_t g;
uint16_t b;
if(den == 0)
{
return c1;
}
r = r0 + (uint16_t)(r1 - r0) * num / den;
g = g0 + (uint16_t)(g1 - g0) * num / den;
b = b0 + (uint16_t)(b1 - b0) * num / den;
return (r << 11) | (g << 5) | b;
}
/**
* @brief 5
* @param volume_level: (0-50=5=)
* @note N N ()
*/ */
void Draw_Volume_Bar(uint16_t x, uint16_t y, uint8_t volume_level,uint8_t scale,uint16_t color_on, uint16_t color_off) void Draw_Volume_Bar(uint16_t x, uint16_t y, uint8_t volume_level,uint8_t scale,uint16_t color_on, uint16_t color_off)
{ {
uint8_t i; uint8_t i;
//const uint8_t bar_count = 5; // 音量条总数量5挡 uint8_t bar_count = 5;
uint8_t w = 5 * scale; // 单条宽度(支持缩放) uint8_t w = 3 * scale;
uint8_t gap = 2 * scale; // 条间距(支持缩放) uint8_t gap = 2 * scale;
// 每条约的Y偏移和高度按原始比例缩放 uint8_t radius = 1 * scale;
uint8_t y_offset[5] = {8,6,4,2,0}; uint8_t height[5] = {6, 9, 12, 15, 18};
uint8_t height[5] = {12,14,16,18,20}; uint8_t max_h = height[4];
uint16_t clear_w;
uint16_t dim_color = color_off;
// 限制音量等级范围,避免越界 (void)color_on;
volume_level = (volume_level > 5) ? 5 : volume_level;
// 循环绘制5个音量条按档位控制颜色 if(volume_level > 5)
for(i = 0; i < 5; i++)
{ {
uint16_t curr_x = x + (w + gap) * i; // 当前条的X坐标 volume_level = 5;
uint8_t curr_y = y + y_offset[i] * scale; // 当前条的Y坐标缩放后 }
uint8_t curr_h = height[i] * scale; // 当前条的高度(缩放后)
uint16_t curr_color = (i < volume_level) ? color_on : color_off; // 按档位选颜色
// 绘制圆角矩形音量条 clear_w = (uint16_t)(w + gap) * bar_count - gap;
LCD_FillRoundRect(curr_x, curr_y, w, curr_h, 2 * scale, curr_color); LCD_FillByColor(x, y, x + clear_w, y + max_h * scale, BLACK);
if(volume_level == 0)
{
return;
}
for(i = 0; i < bar_count; i++)
{
uint16_t curr_x = x + (w + gap) * i;
uint8_t curr_h = height[i] * scale;
uint8_t curr_y = y + (max_h * scale - curr_h);
uint16_t bar_color;
if(i >= volume_level)
{
continue;
}
if(volume_level == 1)
{
bar_color = WHITE;
}
else
{
/* 左暗右亮第1格最暗当前档位的最右格为全白 */
bar_color = LCD_BlendColor565(dim_color, WHITE, i, volume_level - 1);
}
LCD_FillRoundTopRect(curr_x, curr_y, w, curr_h, radius, bar_color);
} }
} }
@ -1755,64 +1873,76 @@ void Draw_Volume_Bar(uint16_t x, uint16_t y, uint8_t volume_level,uint8_t scale,
/** /**
* @brief * @brief 线 + +
* @param x: X坐标
* @param y: Y坐标
* @param battery_percent: 0-100
* @param scale: 1=2=2
* @param border_color: RGB值WHITE/0xFFFF
* @param bg_color: BLACK/0x0000
* @param fill_color: WHITE/0xFFFF
*/ */
void Draw_Battery_Icon(uint16_t x, uint16_t y, uint8_t battery_percent,uint8_t scale, uint16_t border_color, uint16_t bg_color, uint16_t fill_color) void Draw_Battery_Icon(uint16_t x, uint16_t y, uint8_t battery_percent,uint8_t scale, uint16_t border_color, uint16_t bg_color, uint16_t fill_color)
{ {
// 1. 基础参数原始尺寸按scale缩放 uint16_t bat_w = 24 * scale;
uint16_t bat_w = 25 * scale; // 电池主体宽度 uint16_t bat_h = 11 * scale;
uint16_t bat_h = 15 * scale; // 电池主体高度 uint8_t round_r = 2 * scale;
uint8_t round_r = 2 * scale; // 电池圆角半径 uint8_t stroke = 1 * scale;
uint16_t inner_gap = 1 * scale; // 内部边框间隙 uint16_t fill_gap = 2 * scale;
uint16_t fill_gap = 2 * scale; // 电量填充区间隙 uint8_t text_size = 16 * scale; /* 16px ASCII 字体渲染可靠13px 位图与驱动不匹配会乱码 */
uint8_t Info[40]; uint8_t status_bar_h = 26 * scale;
uint8_t Info[40];
uint16_t pole_w = 2 * scale;
uint16_t pole_h = 5 * scale;
uint16_t pole_x;
uint16_t pole_y;
uint16_t inner_w;
uint16_t inner_h;
uint16_t fill_w;
uint16_t text_x;
uint16_t text_y;
uint16_t clear_h;
LCD_FillByColor(x,y,240,y+bat_h,BLACK); if(battery_percent > 100)
// 2. 限制电量范围避免负数或超过100%
if(battery_percent > 100) battery_percent = 100;
if(battery_percent == 0) battery_percent = 0;
// 3. 计算电量填充宽度(按百分比)
uint16_t fill_w = (bat_w - 2 * fill_gap) * battery_percent / 100;
// 电量填充高度留1像素间隙和内部区域匹配
uint16_t fill_h = bat_h - 2 * fill_gap;
// 4. 绘制电池外框(带圆角)
LCD_FillRoundRect(x, y, bat_w, bat_h, round_r, border_color);
// 5. 绘制电池内部背景(黑色底)
LCD_FillRoundRect(x + inner_gap, y + inner_gap,
bat_w - 2 * inner_gap, bat_h - 2 * inner_gap,
0, bg_color);
// 6. 绘制电量填充(按百分比动态显示)
if(battery_percent > 0) // 电量>0才绘制填充
{ {
LCD_FillRoundRect(x + fill_gap, y + fill_gap, battery_percent = 100;
fill_w, fill_h,
0, fill_color);
} }
// 7. 绘制电池正极(右上角小矩形,增强视觉效果) clear_h = (bat_h > text_size) ? bat_h : text_size;
uint16_t pole_w = 3 * scale; // 正极宽度 if(status_bar_h > clear_h)
uint16_t pole_h = 7 * scale; // 正极高度 {
uint16_t pole_x = x + bat_w; // 正极X坐标电池右侧 clear_h = status_bar_h;
uint16_t pole_y = y + (bat_h - pole_h) / 2; // 正极垂直居中 }
LCD_FillByColor(x, 0, 240, clear_h, BLACK);
/* 圆角外壳:外框 + 内挖空 */
LCD_FillRoundRect(x, y, bat_w, bat_h, round_r, border_color);
if(bat_w > 2 * stroke && bat_h > 2 * stroke)
{
LCD_FillRoundRect(x + stroke, y + stroke,
bat_w - 2 * stroke, bat_h - 2 * stroke,
(round_r > stroke) ? (round_r - stroke) : 0,
bg_color);
}
inner_w = bat_w - 2 * fill_gap;
inner_h = bat_h - 2 * fill_gap;
fill_w = inner_w * battery_percent / 100;
/* 从左向右实心填充,宽度与百分比一致 */
if(battery_percent > 0 && fill_w > 0)
{
if(fill_w > inner_w)
{
fill_w = inner_w;
}
LCD_FillRoundRect(x + fill_gap, y + fill_gap,
fill_w, inner_h,
1 * scale, fill_color);
}
/* 右侧正极小凸起 */
pole_x = x + bat_w;
pole_y = y + (bat_h - pole_h) / 2;
LCD_FillRoundRect(pole_x, pole_y, pole_w, pole_h, 1 * scale, border_color); LCD_FillRoundRect(pole_x, pole_y, pole_w, pole_h, 1 * scale, border_color);
sprintf ((char*)Info, "%d%%", battery_percent); sprintf((char*)Info, "%d%%", battery_percent);
LCD_ShowString(x+bat_w+pole_w, y, Info, WHITE, BLACK, 16, 0); text_x = pole_x + pole_w + 2 * scale;
text_y = (status_bar_h - text_size) / 2;
LCD_ShowString(text_x, text_y, Info, WHITE, BLACK, text_size, 0);
} }
/****************************************************************************** /******************************************************************************

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,316 @@
#include "Drv_ILI9341_Lcd_Dump.h"
#if DEBUG_LCD_DUMP
#include "SEGGER_RTT.h"
#define LCD_DUMP_RTT_UP_CH 1
#define LCD_DUMP_RTT_DOWN_CH 0
#define LCD_DUMP_CMD "DUMP"
#define LCD_DUMP_MAGIC "SCRN"
#define LCD_DUMP_FMT_RGB565 1
#define LCD_DUMP_CMD_BUF_SIZE 16
#pragma pack(1)
typedef struct {
char magic[4];
uint16_t width;
uint16_t height;
uint16_t format;
uint16_t reserved;
} lcd_dump_header_t;
#pragma pack()
static uint8_t s_dump_busy;
static uint8_t s_rtt_ready;
static char s_rtt_up_buf[1024];
static char s_cmd_buf[LCD_DUMP_CMD_BUF_SIZE];
static uint8_t s_cmd_len;
static uint8_t s_row565[LCD_W * 2U];
static struct rt_thread s_dump_thread;
ALIGN(RT_ALIGN_SIZE) static rt_uint8_t s_dump_stack[1024];
static uint8_t LCD_SPI_Transceive(uint8_t tx)
{
uint32_t timeout = 200000U;
while (!(SPI2->sts & SPI_I2S_TDBE_FLAG) && --timeout) {}
spi_i2s_data_transmit(SPI2, tx);
timeout = 200000U;
while (!(SPI2->sts & SPI_I2S_RDBF_FLAG) && --timeout) {}
if (timeout == 0U) {
return 0xFF;
}
return (uint8_t)spi_i2s_data_receive(SPI2);
}
static void LCD_SPI_FlushRx(void)
{
while (SPI2->sts & SPI_I2S_RDBF_FLAG) {
(void)spi_i2s_data_receive(SPI2);
}
}
static void LCD_SPI_EnableMisoMux(void)
{
gpio_init_type gpio_init_struct;
gpio_default_para_init(&gpio_init_struct);
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
gpio_init_struct.gpio_pins = GPIO_PINS_14;
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
gpio_init(GPIOB, &gpio_init_struct);
}
static void LCD_SPI_CsGpioLow(void)
{
gpio_init_type gpio_init_struct;
gpio_default_para_init(&gpio_init_struct);
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
gpio_init_struct.gpio_mode = GPIO_MODE_OUTPUT;
gpio_init_struct.gpio_pins = GPIO_PINS_12;
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
gpio_init(GPIOB, &gpio_init_struct);
gpio_bits_reset(GPIOB, GPIO_PINS_12);
}
static void LCD_SPI_CsHwRestore(void)
{
gpio_init_type gpio_init_struct;
gpio_bits_set(GPIOB, GPIO_PINS_12);
gpio_default_para_init(&gpio_init_struct);
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
gpio_init_struct.gpio_pins = GPIO_PINS_12;
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
gpio_init(GPIOB, &gpio_init_struct);
}
static void LCD_SPI_SetBaud(spi_mclk_freq_div_type div)
{
spi_enable(SPI2, FALSE);
SPI2->ctrl1 &= ~(0x7U << 3);
/* Standard div 2..256 live in CTRL1[5:3]; AT32 maps enum 0..7 there. */
SPI2->ctrl1 |= (uint16_t)(((uint16_t)div & 0x7U) << 3);
spi_enable(SPI2, TRUE);
}
static uint16_t LCD_RGB888To565(uint8_t r, uint8_t g, uint8_t b)
{
return (uint16_t)(((uint16_t)(r & 0xF8) << 8) |
((uint16_t)(g & 0xFC) << 3) |
(b >> 3));
}
static void LCD_RTT_WriteBlocking(const void *data, uint32_t len)
{
const uint8_t *p = (const uint8_t *)data;
uint32_t sent = 0U;
uint32_t spin = 0U;
while (sent < len) {
unsigned wrote = SEGGER_RTT_Write(LCD_DUMP_RTT_UP_CH, p + sent, len - sent);
if (wrote == 0U) {
if ((++spin & 0x3FU) == 0U) {
rt_thread_mdelay(1);
}
continue;
}
spin = 0U;
sent += wrote;
}
}
/* Soft-CS byte helpers (CS already held low by caller). */
static void LCD_Soft_WR_REG(uint8_t reg)
{
LCD_DC_Clr();
(void)LCD_SPI_Transceive(reg);
}
static void LCD_Soft_WR_DATA16(uint16_t data)
{
LCD_DC_Set();
(void)LCD_SPI_Transceive((uint8_t)(data >> 8));
(void)LCD_SPI_Transceive((uint8_t)(data & 0xFF));
}
/* Set CASET/RASET only — do NOT send 0x2C (memory write). */
static void LCD_Soft_SetAddr(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2)
{
LCD_Soft_WR_REG(0x2A);
LCD_Soft_WR_DATA16(x1);
LCD_Soft_WR_DATA16(x2);
LCD_Soft_WR_REG(0x2B);
LCD_Soft_WR_DATA16(y1);
LCD_Soft_WR_DATA16(y2);
}
static void LCD_ReadFrameRGB565(void)
{
uint16_t x, y;
register rt_base_t level;
LCD_SPI_FlushRx();
LCD_Soft_SetAddr(0, 0, (uint16_t)(LCD_W - 1), (uint16_t)(LCD_H - 1));
LCD_Soft_WR_REG(0x2E);
LCD_DC_Set();
(void)LCD_SPI_Transceive(0xFF); /* dummy */
for (y = 0; y < LCD_H; y++) {
level = rt_hw_interrupt_disable();
for (x = 0; x < LCD_W; x++) {
uint8_t r = LCD_SPI_Transceive(0xFF);
uint8_t g = LCD_SPI_Transceive(0xFF);
uint8_t b = LCD_SPI_Transceive(0xFF);
uint16_t color = LCD_RGB888To565(r, g, b);
s_row565[(x * 2U)] = (uint8_t)(color >> 8);
s_row565[(x * 2U) + 1] = (uint8_t)(color & 0xFF);
}
rt_hw_interrupt_enable(level);
LCD_RTT_WriteBlocking(s_row565, (uint32_t)(LCD_W * 2U));
}
}
static uint8_t LCD_Dump_CommandPending(void)
{
char rx[8];
unsigned read_len;
unsigned i;
read_len = SEGGER_RTT_Read(LCD_DUMP_RTT_DOWN_CH, rx, sizeof(rx));
if (read_len == 0U) {
return 0U;
}
for (i = 0; i < read_len; i++) {
char c = rx[i];
if (c == '\r' || c == '\n' || c == '\0') {
s_cmd_len = 0U;
s_cmd_buf[0] = '\0';
continue;
}
if (s_cmd_len + 1U >= LCD_DUMP_CMD_BUF_SIZE) {
s_cmd_len = 0U;
}
s_cmd_buf[s_cmd_len++] = c;
s_cmd_buf[s_cmd_len] = '\0';
if (c == 0x01 || strstr(s_cmd_buf, LCD_DUMP_CMD) != NULL) {
s_cmd_len = 0U;
s_cmd_buf[0] = '\0';
return 1U;
}
}
return 0U;
}
static void LCD_Dump_ThreadEntry(void *parameter)
{
(void)parameter;
SEGGER_RTT_WriteString(0, "LCDDump ready\n");
while (1) {
LCD_Dump_Poll();
rt_thread_mdelay(5);
}
}
void LCD_Dump_Init(void)
{
if (s_rtt_ready) {
return;
}
SEGGER_RTT_ConfigUpBuffer(LCD_DUMP_RTT_UP_CH,
"LCDDump",
s_rtt_up_buf,
(uint32_t)sizeof(s_rtt_up_buf),
SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL);
s_rtt_ready = 1;
}
void LCD_Dump_StartPoller(void)
{
static uint8_t started;
if (!s_rtt_ready) {
LCD_Dump_Init();
}
if (started) {
return;
}
started = 1;
rt_thread_init(&s_dump_thread,
"lcd_dump",
LCD_Dump_ThreadEntry,
RT_NULL,
s_dump_stack,
sizeof(s_dump_stack),
8,
10);
rt_thread_startup(&s_dump_thread);
}
void LCD_DumpScreen_RTT(void)
{
lcd_dump_header_t header;
if (!s_rtt_ready) {
LCD_Dump_Init();
}
SEGGER_RTT_WriteString(0, "LCDDump start\n");
LCD_SPI_EnableMisoMux();
header.magic[0] = LCD_DUMP_MAGIC[0];
header.magic[1] = LCD_DUMP_MAGIC[1];
header.magic[2] = LCD_DUMP_MAGIC[2];
header.magic[3] = LCD_DUMP_MAGIC[3];
header.width = LCD_W;
header.height = LCD_H;
header.format = LCD_DUMP_FMT_RGB565;
header.reserved = 0;
LCD_RTT_WriteBlocking(&header, (uint32_t)sizeof(header));
/* Slow clock; hold CS for one full-frame RAMRD burst. */
LCD_SPI_SetBaud(SPI_MCLK_DIV_64);
LCD_SPI_CsGpioLow();
LCD_ReadFrameRGB565();
LCD_SPI_CsHwRestore();
LCD_SPI_SetBaud(SPI_MCLK_DIV_4);
SEGGER_RTT_WriteString(LCD_DUMP_RTT_UP_CH, "DONE");
SEGGER_RTT_WriteString(0, "LCDDump done\n");
}
void LCD_Dump_Poll(void)
{
if (s_dump_busy) {
return;
}
if (!LCD_Dump_CommandPending()) {
return;
}
s_dump_busy = 1;
LCD_DumpScreen_RTT();
s_dump_busy = 0;
}
#endif /* DEBUG_LCD_DUMP */

View File

@ -0,0 +1,26 @@
#ifndef __DRV_ILI9341_LCD_DUMP_H
#define __DRV_ILI9341_LCD_DUMP_H
#include "includes.h"
#ifndef DEBUG_LCD_DUMP
#define DEBUG_LCD_DUMP 1
#endif
#if DEBUG_LCD_DUMP
void LCD_Dump_Init(void);
void LCD_Dump_StartPoller(void);
void LCD_Dump_Poll(void);
void LCD_DumpScreen_RTT(void);
#else
#define LCD_Dump_Init() ((void)0)
#define LCD_Dump_StartPoller() ((void)0)
#define LCD_Dump_Poll() ((void)0)
#define LCD_DumpScreen_RTT() ((void)0)
#endif
#endif

File diff suppressed because it is too large Load Diff

View File

@ -57,6 +57,16 @@
#define WHITE 0xFFFF #define WHITE 0xFFFF
#define BLACK 0x0000 #define BLACK 0x0000
#define BLUE 0x001F #define BLUE 0x001F
#define COLOR_PRIMARY 0x1B9F // #1D73FF MiSans UI 主色
#define COLOR_GRAD_START 0x039D // #003AEE
#define COLOR_GRAD_MID 0x2A5A // #354FD6
#define COLOR_GRAD_END 0x4B1F // #5561F8
#define COLOR_BG_START 0x0849 // #0E1537
#define COLOR_BG_END 0x3189 // #2F3647
#define COLOR_MIXER_RED 0xFB2D // #F85E4B
#define COLOR_MIXER_ORANGE 0xFD26 // #F59C2C
#define COLOR_MIXER_YELLOW 0xFF6E // #F3D939
#define COLOR_MIXER_GREEN 0x071F // #13E17F
#define BRED 0XF81F #define BRED 0XF81F
#define GRED 0XFFE0 #define GRED 0XFFE0
#define GBLUE 0X07FF #define GBLUE 0X07FF
@ -80,8 +90,8 @@
#define DARKLGRAY 0x5AEB/*0x2988*//*0x1926*//*0x252E*//*0X2B12*/ #define DARKLGRAY 0x5AEB/*0x2988*//*0x1926*//*0x252E*//*0X2B12*/
#define BUTTON_COLOR /*0x5AEB*/BLACK #define BUTTON_COLOR /*0x5AEB*/BLACK
#define START_COLOR 0x10E6/*0x5AEB*/ /*0x2988*/ #define START_COLOR COLOR_GRAD_START
#define END_COLOR 0x10E6/*0x2022*//*0x5066*/ #define END_COLOR COLOR_GRAD_END
extern void LCD_GPIO_Init(void); //初始化GPIO extern void LCD_GPIO_Init(void); //初始化GPIO
extern void LCD_WR_DATA8(uint8_t data); //写入一个字节 extern void LCD_WR_DATA8(uint8_t data); //写入一个字节
extern void LCD_WR_DATA16(uint16_t data); //写入两个字节 extern void LCD_WR_DATA16(uint16_t data); //写入两个字节

View File

@ -7,7 +7,8 @@ define symbol __ICFEDIT_intvec_start__ = 0x08008000;
define symbol __ICFEDIT_region_ROM_start__ = 0x08008000; define symbol __ICFEDIT_region_ROM_start__ = 0x08008000;
define symbol __ICFEDIT_region_ROM_end__ = 0x0803FFFF; define symbol __ICFEDIT_region_ROM_end__ = 0x0803FFFF;
define symbol __ICFEDIT_region_RAM_start__ = 0x20000000; define symbol __ICFEDIT_region_RAM_start__ = 0x20000000;
define symbol __ICFEDIT_region_RAM_end__ = 0x20037FFF; /* AT32F403ARCT7: 96KB SRAM (0x20000000-0x20017FFF). Do NOT use 224KB. */
define symbol __ICFEDIT_region_RAM_end__ = 0x20017FFF;
/*-Sizes-*/ /*-Sizes-*/
define symbol __ICFEDIT_size_cstack__ = 0x400; define symbol __ICFEDIT_size_cstack__ = 0x400;
define symbol __ICFEDIT_size_heap__ = 0x200; define symbol __ICFEDIT_size_heap__ = 0x200;

View File

@ -185,6 +185,7 @@
<state>USE_STDPERIPH_DRIVER</state> <state>USE_STDPERIPH_DRIVER</state>
<state>AT_START_F403A_V1</state> <state>AT_START_F403A_V1</state>
<state>autoband</state> <state>autoband</state>
<state>DEBUG_LCD_DUMP=1</state>
</option> </option>
<option> <option>
<name>CCPreprocFile</name> <name>CCPreprocFile</name>
@ -334,6 +335,7 @@
<state>$PROJ_DIR$\..\..\APP</state> <state>$PROJ_DIR$\..\..\APP</state>
<state>$PROJ_DIR$\..\..\midi</state> <state>$PROJ_DIR$\..\..\midi</state>
<state>$PROJ_DIR$\..\..\protocol</state> <state>$PROJ_DIR$\..\..\protocol</state>
<state>$PROJ_DIR$\..\..\third_party\segger_rtt</state>
<state>$PROJ_DIR$\..\..\driver</state> <state>$PROJ_DIR$\..\..\driver</state>
<state>$PROJ_DIR$\..\..\MyCode</state> <state>$PROJ_DIR$\..\..\MyCode</state>
</option> </option>
@ -1170,6 +1172,7 @@
<state>AT_START_F403A_V1</state> <state>AT_START_F403A_V1</state>
<state>BOOT</state> <state>BOOT</state>
<state>autoband</state> <state>autoband</state>
<state>DEBUG_LCD_DUMP=1</state>
</option> </option>
<option> <option>
<name>CCPreprocFile</name> <name>CCPreprocFile</name>
@ -1319,6 +1322,7 @@
<state>$PROJ_DIR$\..\..\APP</state> <state>$PROJ_DIR$\..\..\APP</state>
<state>$PROJ_DIR$\..\..\midi</state> <state>$PROJ_DIR$\..\..\midi</state>
<state>$PROJ_DIR$\..\..\protocol</state> <state>$PROJ_DIR$\..\..\protocol</state>
<state>$PROJ_DIR$\..\..\third_party\segger_rtt</state>
<state>$PROJ_DIR$\..\..\driver</state> <state>$PROJ_DIR$\..\..\driver</state>
<state>$PROJ_DIR$\..\..\MyCode</state> <state>$PROJ_DIR$\..\..\MyCode</state>
</option> </option>
@ -2083,6 +2087,12 @@
<file> <file>
<name>$PROJ_DIR$\..\..\device\LCD_ILI9341\Drv_ILI9341_Lcd_Init.h</name> <name>$PROJ_DIR$\..\..\device\LCD_ILI9341\Drv_ILI9341_Lcd_Init.h</name>
</file> </file>
<file>
<name>$PROJ_DIR$\..\..\device\LCD_ILI9341\Drv_ILI9341_Lcd_Dump.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\device\LCD_ILI9341\Drv_ILI9341_Lcd_Dump.h</name>
</file>
<file> <file>
<name>$PROJ_DIR$\..\..\device\LCD_ILI9341\Drv_XPT2046_Touch.c</name> <name>$PROJ_DIR$\..\..\device\LCD_ILI9341\Drv_XPT2046_Touch.c</name>
</file> </file>
@ -2090,6 +2100,18 @@
<name>$PROJ_DIR$\..\..\device\LCD_ILI9341\Drv_XPT2046_Touch.h</name> <name>$PROJ_DIR$\..\..\device\LCD_ILI9341\Drv_XPT2046_Touch.h</name>
</file> </file>
</group> </group>
<group>
<name>third_party</name>
<file>
<name>$PROJ_DIR$\..\..\third_party\segger_rtt\SEGGER_RTT.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\third_party\segger_rtt\SEGGER_RTT.h</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\third_party\segger_rtt\SEGGER_RTT_Conf.h</name>
</file>
</group>
<group> <group>
<name>middleware</name> <name>middleware</name>
<file> <file>

View File

@ -28,13 +28,14 @@
#include "drv_flash.h" #include "drv_flash.h"
#include "drv_nvm.h" #include "drv_nvm.h"
#include "GlobalEnum.h" //公共枚举 #include "GlobalEnum.h" //<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ö<EFBFBD><EFBFBD>
#include "GlobalStruct.h" //公共结构体 #include "GlobalStruct.h" //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
#include "Common_Head.h" //公共头文件声明 #include "Common_Head.h" //<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
#include "Drv_ILI9341_Lcd_Init.h" #include "Drv_ILI9341_Lcd_Init.h"
#include "Drv_ILI9341_Lcd_App.h" #include "Drv_ILI9341_Lcd_App.h"
#include "Drv_ILI9341_Lcd_Image.h" #include "Drv_ILI9341_Lcd_Image.h"
#include "Drv_ILI9341_Lcd_Dump.h"
#include "Drv_XPT2046_Touch.h" #include "Drv_XPT2046_Touch.h"

View File

@ -82,6 +82,7 @@ int main(void)
bsp_init(); bsp_init();
LCD_Init(); LCD_Init();
LCD_Dump_Init();
drv_nvm_init(); drv_nvm_init();
TaskInit(); TaskInit();
timer_init(); timer_init();
@ -100,6 +101,7 @@ int main(void)
} }
/* add user code begin 3 */ /* add user code begin 3 */
Power_Key_Scan(); Power_Key_Scan();
LCD_Dump_Poll();
rt_thread_delay(1); rt_thread_delay(1);
/* add user code end 3 */ /* add user code end 3 */

View File

@ -132,10 +132,10 @@ void wk_spi2_init(void)
gpio_init_struct.gpio_pull = GPIO_PULL_NONE; gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
gpio_init(GPIOB, &gpio_init_struct); gpio_init(GPIOB, &gpio_init_struct);
/* configure the MISO pin */ /* configure the MISO pin (SPI2 AF, not plain input) */
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE; gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL; gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
gpio_init_struct.gpio_mode = GPIO_MODE_INPUT; gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
gpio_init_struct.gpio_pins = GPIO_PINS_14; gpio_init_struct.gpio_pins = GPIO_PINS_14;
gpio_init_struct.gpio_pull = GPIO_PULL_NONE; gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
gpio_init(GPIOB, &gpio_init_struct); gpio_init(GPIOB, &gpio_init_struct);

View File

@ -27,6 +27,18 @@ $jlink = Test-Command "J-Link" "JLink"
if (-not $jlink) { if (-not $jlink) {
Write-Host " Install: winget install NordicSemiconductor.JLink" -ForegroundColor Yellow Write-Host " Install: winget install NordicSemiconductor.JLink" -ForegroundColor Yellow
Write-Host " Or download: https://www.segger.com/downloads/jlink/" -ForegroundColor Yellow Write-Host " Or download: https://www.segger.com/downloads/jlink/" -ForegroundColor Yellow
} else {
$jlinkDev = Get-PnpDevice -ErrorAction SilentlyContinue | Where-Object { $_.InstanceId -match 'VID_1366' }
if ($jlinkDev) {
$online = $jlinkDev | Where-Object { $_.Present -eq $true }
if ($online) {
Write-Host "[OK] J-Link USB device present" -ForegroundColor Green
} else {
Write-Host "[FAIL] J-Link ghost device only (Present=False). Run scripts\repair-jlink.ps1" -ForegroundColor Red
}
} else {
Write-Host "[FAIL] J-Link not detected on USB (plug in debugger)" -ForegroundColor Red
}
} }
$iarPaths = @( $iarPaths = @(

64
scripts/flash-app.ps1 Normal file
View File

@ -0,0 +1,64 @@
#Requires -Version 5.1
<#
.SYNOPSIS
Build (optional) and flash YNGJ-GT1-M app via IAR cspybat + J-Link.
Auto-selects Cortex-M4 and suppresses J-Link device-selection dialogs.
#>
param(
[switch]$NoBuild
)
$ErrorActionPreference = "Stop"
$Root = Split-Path -Parent $PSScriptRoot
$Ewp = Join-Path $Root "project\IAR_V7.4\YNGJ-GT1-M.ewp"
$ExeDir = Join-Path $Root "project\IAR_V7.4\YNGJ-GT1-M\Exe"
$Out = Join-Path $ExeDir "YNGJ-GT1-M.out"
$Bin = Join-Path $ExeDir "YNGJ-GT1-M.bin"
$ToolsDir = Join-Path $Root "tools"
$SettingsSrc = Join-Path $ToolsDir "JLinkSettings.ini"
$JlinkScript = Join-Path $ToolsDir "jlink_hidedevid.jlink"
$GeneralXcl = Join-Path $Root "project\IAR_V7.4\settings\YNGJ-GT1-M.YNGJ-GT1-M.general.xcl"
$DriverXcl = Join-Path $Root "project\IAR_V7.4\settings\YNGJ-GT1-M.YNGJ-GT1-M.driver.xcl"
$IarBuild = "C:\Program Files (x86)\IAR Systems\Embedded Workbench 7.3\common\bin\IarBuild.exe"
$CspyBat = "C:\Program Files (x86)\IAR Systems\Embedded Workbench 7.3\common\bin\cspybat.exe"
$TempFlash = "C:\Temp\k1flash"
# Suppress J-Link unknown-device popup (cwd / AppData / ASCII path for script).
New-Item -ItemType Directory -Force -Path $ExeDir, $TempFlash | Out-Null
Copy-Item -Force $SettingsSrc (Join-Path $ExeDir "JLinkSettings.ini")
Copy-Item -Force $SettingsSrc (Join-Path $TempFlash "JLinkSettings.ini")
Copy-Item -Force $JlinkScript (Join-Path $TempFlash "jlink_hidedevid.jlink")
$Roaming = Join-Path $env:APPDATA "SEGGER"
New-Item -ItemType Directory -Force -Path $Roaming | Out-Null
Copy-Item -Force $SettingsSrc (Join-Path $Roaming "JLinkSettings.ini")
# Stop leftover debug servers that hold the probe.
Get-Process -Name CSpyBat, JLinkGUIServer, JLink -ErrorAction SilentlyContinue |
Where-Object { $_.ProcessName -match 'CSpyBat|JLinkGUIServer' } |
Stop-Process -Force -ErrorAction SilentlyContinue
if (-not $NoBuild) {
Write-Host "Building..."
& $IarBuild $Ewp -make YNGJ-GT1-M
if ($LASTEXITCODE -ne 0) { throw "IarBuild failed: $LASTEXITCODE" }
}
if (-not (Test-Path $Out)) { throw "Missing $Out" }
if (Test-Path $Bin) {
Copy-Item -Force $Bin (Join-Path $TempFlash "YNGJ-GT1-M.bin")
}
Write-Host "Flashing (Cortex-M4, no device dialog)..."
Push-Location $ExeDir
try {
# HideDeviceSelection comes from JLinkSettings.ini + driver.xcl jlink script.
& $CspyBat -f $GeneralXcl --download_only --silent --backend -f $DriverXcl
$code = $LASTEXITCODE
} finally {
Pop-Location
}
if ($code -ne 0) { throw "Flash failed: $code" }
Write-Host "Flash OK"
exit 0

95
scripts/repair-jlink.ps1 Normal file
View File

@ -0,0 +1,95 @@
#Requires -Version 5.1
<#
.SYNOPSIS
Diagnose and repair SEGGER J-Link USB connection on Windows.
.NOTES
Run PowerShell as Administrator for driver reinstall / phantom device removal.
Close IAR and J-Link Commander before running.
#>
$ErrorActionPreference = "Continue"
$JLinkExe = "C:\Program Files\SEGGER\JLink_V818\JLink.exe"
$DriverInf = "C:\Program Files\SEGGER\JLink_V818\USBDriver\x64\JLink.inf"
function Write-Step($text) {
Write-Host "`n=== $text ===" -ForegroundColor Cyan
}
Write-Step "1. J-Link process check"
$procs = Get-Process -ErrorAction SilentlyContinue | Where-Object {
$_.ProcessName -match '^(JLink|IarIdePm|cspybat|IAR)$'
}
if ($procs) {
Write-Host "[WARN] These may lock J-Link:" -ForegroundColor Yellow
$procs | Format-Table ProcessName, Id -AutoSize
Write-Host "Close IAR / J-Link Commander windows, then run:" -ForegroundColor Yellow
Write-Host ' Stop-Process -Name JLink,IarIdePm -Force -ErrorAction SilentlyContinue' -ForegroundColor Gray
} else {
Write-Host "[OK] No J-Link / IAR debugger processes" -ForegroundColor Green
}
Write-Step "2. USB device status (VID 1366 = SEGGER)"
$all = Get-PnpDevice -ErrorAction SilentlyContinue | Where-Object {
$_.InstanceId -match 'VID_1366'
}
if (-not $all) {
Write-Host "[FAIL] No J-Link entries in PnP (not plugged in or bad cable/port)" -ForegroundColor Red
} else {
$all | Format-Table FriendlyName, Status, Present, Problem -AutoSize
$present = $all | Where-Object { $_.Present -eq $true }
if (-not $present) {
Write-Host "[FAIL] J-Link entries exist but Present=False (ghost device, Code 45)" -ForegroundColor Red
Write-Host " Unplug USB, uninstall hidden 'J-Link driver', replug." -ForegroundColor Yellow
} else {
Write-Host "[OK] J-Link is present on USB" -ForegroundColor Green
}
}
Write-Step "3. Installed SEGGER drivers"
driverquery | Select-String -Pattern 'jlink' -CaseSensitive:$false
Write-Step "4. J-Link Commander probe test"
if (Test-Path $JLinkExe) {
$out = cmd /c "echo exit| `"$JLinkExe`"" 2>&1 | Out-String
if ($out -match 'O\.K\.|Found .* J-Link') {
Write-Host "[OK] $out.Trim()" -ForegroundColor Green
} else {
Write-Host "[FAIL] $out.Trim()" -ForegroundColor Red
}
} else {
Write-Host "[MISS] $JLinkExe" -ForegroundColor Red
}
Write-Step "5. Repair actions (Administrator)"
$isAdmin = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(
[Security.Principal.WindowsBuiltInRole]::Administrator)
if (-not $isAdmin) {
Write-Host "[INFO] Re-run this script as Administrator to auto-repair drivers." -ForegroundColor Yellow
Write-Host " Right-click PowerShell -> Run as administrator" -ForegroundColor Yellow
exit 0
}
Write-Host "Stopping J-Link / IAR helper processes..."
Stop-Process -Name JLink -Force -ErrorAction SilentlyContinue
Stop-Process -Name IarIdePm -Force -ErrorAction SilentlyContinue
Start-Sleep -Seconds 2
Write-Host "Removing phantom J-Link PnP devices..."
Get-PnpDevice -ErrorAction SilentlyContinue | Where-Object {
$_.InstanceId -match 'VID_1366'
} | ForEach-Object {
Write-Host " Removing $($_.InstanceId)"
pnputil /remove-device $_.InstanceId 2>&1 | Out-Null
}
if (Test-Path $DriverInf) {
Write-Host "Reinstalling J-Link USB driver from JLink_V818..."
pnputil /add-driver $DriverInf /install 2>&1
Write-Host "[DONE] Now unplug J-Link USB, wait 5s, plug back in." -ForegroundColor Green
Write-Host " Then verify: echo exit | `"$JLinkExe`"" -ForegroundColor Gray
} else {
Write-Host "[MISS] Driver INF: $DriverInf" -ForegroundColor Red
}

View File

@ -10,7 +10,7 @@ static struct rt_thread TaskAutobandThread;
ALIGN(RT_ALIGN_SIZE) static rt_uint8_t TaskScanThread_Stack[512]; ALIGN(RT_ALIGN_SIZE) static rt_uint8_t TaskScanThread_Stack[512];
ALIGN(RT_ALIGN_SIZE) static rt_uint8_t TaskUIThread_Stack[1024]; ALIGN(RT_ALIGN_SIZE) static rt_uint8_t TaskUIThread_Stack[1024];
ALIGN(RT_ALIGN_SIZE) static rt_uint8_t TaskTouchThread_Stack[512]; ALIGN(RT_ALIGN_SIZE) static rt_uint8_t TaskTouchThread_Stack[1536];
ALIGN(RT_ALIGN_SIZE) static rt_uint8_t TaskMainThread_Stack[512]; ALIGN(RT_ALIGN_SIZE) static rt_uint8_t TaskMainThread_Stack[512];
ALIGN(RT_ALIGN_SIZE) static rt_uint8_t TaskBTTHandlehread_Stack[512]; ALIGN(RT_ALIGN_SIZE) static rt_uint8_t TaskBTTHandlehread_Stack[512];
ALIGN(RT_ALIGN_SIZE) static rt_uint8_t TaskBTRecvThread_Stack[512]; ALIGN(RT_ALIGN_SIZE) static rt_uint8_t TaskBTRecvThread_Stack[512];
@ -47,7 +47,8 @@ void TaskTouchThread_entry(void* parameter)
while(1) while(1)
{ {
TP_Point tp = TP_Read(); /* 读 XPT2046 触摸坐标 */ TP_Point tp = TP_Read(); /* 读 XPT2046 触摸坐标 */
app_touch_process(240-tp.x, tp.y, tp.pressed); /* 触摸识别 */ app_touch_process(240-tp.x, tp.y, tp.pressed);
LCD_Dump_Poll();
Read_Cur_Measure(); Read_Cur_Measure();
rt_thread_mdelay(10); rt_thread_mdelay(10);
} }
@ -212,6 +213,8 @@ rt_err_t TaskInit(void)
20); 20);
rt_thread_startup(&TaskMainThread); rt_thread_startup(&TaskMainThread);
rt_thread_startup(&TaskUIThread); rt_thread_startup(&TaskUIThread);
/* RTT LCD dump poller must run even before power-on / StartTouchTask. */
LCD_Dump_StartPoller();
return ret; return ret;
} }

2057
third_party/segger_rtt/SEGGER_RTT.c vendored Normal file

File diff suppressed because it is too large Load Diff

486
third_party/segger_rtt/SEGGER_RTT.h vendored Normal file
View File

@ -0,0 +1,486 @@
/*********************************************************************
* (c) SEGGER Microcontroller GmbH *
* The Embedded Experts *
* www.segger.com *
**********************************************************************
* *
* SEGGER RTT * Real Time Transfer for embedded targets *
* https://github.com/SEGGERMicro/RTT *
* *
**********************************************************************
---------------------------END-OF-HEADER------------------------------
Purpose : Implementation of SEGGER real-time transfer which allows
real-time communication on targets which support debugger
memory accesses while the CPU is running.
SEGGER strongly recommends to not make any changes to or
modify the source code of this software in order to stay
compatible with the RTT protocol and J-Link.
----------------------------------------------------------------------
*/
#ifndef SEGGER_RTT_H
#define SEGGER_RTT_H
#include "SEGGER_RTT_ConfDefaults.h"
/*********************************************************************
*
* Defines, defaults
*
**********************************************************************
*/
#ifndef RTT_USE_ASM
//
// Some cores support out-of-order memory accesses (reordering of memory accesses in the core)
// For such cores, we need to define a memory barrier to guarantee the order of certain accesses to the RTT ring buffers.
// Needed for:
// Cortex-M7 (ARMv7-M)
// Cortex-M23 (ARM-v8M)
// Cortex-M33 (ARM-v8M)
// Cortex-A/R (ARM-v7A/R)
//
// We do not explicitly check for "Embedded Studio" as the compiler in use determines what we support.
// You can use an external toolchain like IAR inside ES. So there is no point in checking for "Embedded Studio"
//
#if (defined __CROSSWORKS_ARM) // Rowley Crossworks
#define _CC_HAS_RTT_ASM_SUPPORT 1
#if (defined __ARM_ARCH_7M__) // Cortex-M3
#define _CORE_HAS_RTT_ASM_SUPPORT 1
#elif (defined __ARM_ARCH_7EM__) // Cortex-M4/M7
#define _CORE_HAS_RTT_ASM_SUPPORT 1
#define _CORE_NEEDS_DMB 1
#define RTT__DMB() __asm volatile ("dmb\n" : : :);
#elif (defined __ARM_ARCH_8M_BASE__) // Cortex-M23
#define _CORE_HAS_RTT_ASM_SUPPORT 0
#define _CORE_NEEDS_DMB 1
#define RTT__DMB() __asm volatile ("dmb\n" : : :);
#elif (defined __ARM_ARCH_8M_MAIN__) // Cortex-M33
#define _CORE_HAS_RTT_ASM_SUPPORT 1
#define _CORE_NEEDS_DMB 1
#define RTT__DMB() __asm volatile ("dmb\n" : : :);
#elif (defined(__ARM_ARCH_8_1M_MAIN__)) // Cortex-M85
#define _CORE_HAS_RTT_ASM_SUPPORT 1
#define _CORE_NEEDS_DMB 1
#define RTT__DMB() __asm volatile ("dmb\n" : : :);
#else
#define _CORE_HAS_RTT_ASM_SUPPORT 0
#endif
#elif (defined __ARMCC_VERSION)
//
// ARM compiler
// ARM compiler V6.0 and later is clang based.
// Our ASM part is compatible to clang.
//
#if (__ARMCC_VERSION >= 6000000)
#define _CC_HAS_RTT_ASM_SUPPORT 1
#else
#define _CC_HAS_RTT_ASM_SUPPORT 0
#endif
#if (defined __ARM_ARCH_6M__) // Cortex-M0 / M1
#define _CORE_HAS_RTT_ASM_SUPPORT 0 // No ASM support for this architecture
#elif (defined __ARM_ARCH_7M__) // Cortex-M3
#define _CORE_HAS_RTT_ASM_SUPPORT 1
#elif (defined __ARM_ARCH_7EM__) // Cortex-M4/M7
#define _CORE_HAS_RTT_ASM_SUPPORT 1
#define _CORE_NEEDS_DMB 1
#define RTT__DMB() __asm volatile ("dmb\n" : : :);
#elif (defined __ARM_ARCH_8M_BASE__) // Cortex-M23
#define _CORE_HAS_RTT_ASM_SUPPORT 0
#define _CORE_NEEDS_DMB 1
#define RTT__DMB() __asm volatile ("dmb\n" : : :);
#elif (defined __ARM_ARCH_8M_MAIN__) // Cortex-M33
#define _CORE_HAS_RTT_ASM_SUPPORT 1
#define _CORE_NEEDS_DMB 1
#define RTT__DMB() __asm volatile ("dmb\n" : : :);
#elif (defined __ARM_ARCH_8_1M_MAIN__) // Cortex-M85
#define _CORE_HAS_RTT_ASM_SUPPORT 1
#define _CORE_NEEDS_DMB 1
#define RTT__DMB() __asm volatile ("dmb\n" : : :);
#elif \
((defined __ARM_ARCH_7A__) || (defined __ARM_ARCH_7R__)) || \
((defined __ARM_ARCH_8A__) || (defined __ARM_ARCH_8R__))
//
// Cortex-A/R ARMv7-A/R & ARMv8-A/R
//
#define _CORE_NEEDS_DMB 1
#define RTT__DMB() __asm volatile ("dmb\n" : : :);
#else
#define _CORE_HAS_RTT_ASM_SUPPORT 0
#endif
#elif ((defined __GNUC__) || (defined __clang__))
//
// GCC / Clang
//
#define _CC_HAS_RTT_ASM_SUPPORT 1
// ARM 7/9: __ARM_ARCH_5__ / __ARM_ARCH_5E__ / __ARM_ARCH_5T__ / __ARM_ARCH_5T__ / __ARM_ARCH_5TE__
#if (defined __ARM_ARCH_7M__) // Cortex-M3
#define _CORE_HAS_RTT_ASM_SUPPORT 1
#elif (defined __ARM_ARCH_7EM__) // Cortex-M4/M7
#define _CORE_HAS_RTT_ASM_SUPPORT 1
#define _CORE_NEEDS_DMB 1 // Only Cortex-M7 needs a DMB but we cannot distinguish M4 and M7 here...
#define RTT__DMB() __asm volatile ("dmb\n" : : :);
#elif (defined __ARM_ARCH_8M_BASE__) // Cortex-M23
#define _CORE_HAS_RTT_ASM_SUPPORT 0
#define _CORE_NEEDS_DMB 1
#define RTT__DMB() __asm volatile ("dmb\n" : : :);
#elif (defined __ARM_ARCH_8M_MAIN__) // Cortex-M33
#define _CORE_HAS_RTT_ASM_SUPPORT 1
#define _CORE_NEEDS_DMB 1
#define RTT__DMB() __asm volatile ("dmb\n" : : :);
#elif (defined __ARM_ARCH_8_1M_MAIN__) // Cortex-M85
#define _CORE_HAS_RTT_ASM_SUPPORT 1
#define _CORE_NEEDS_DMB 1
#define RTT__DMB() __asm volatile ("dmb\n" : : :);
#elif \
(defined __ARM_ARCH_7A__) || (defined __ARM_ARCH_7R__) || \
(defined __ARM_ARCH_8A__) || (defined __ARM_ARCH_8R__)
//
// Cortex-A/R ARMv7-A/R & ARMv8-A/R
//
#define _CORE_NEEDS_DMB 1
#define RTT__DMB() __asm volatile ("dmb\n" : : :);
#else
#define _CORE_HAS_RTT_ASM_SUPPORT 0
#endif
#elif ((defined __IASMARM__) || (defined __ICCARM__))
//
// IAR assembler/compiler
//
#define _CC_HAS_RTT_ASM_SUPPORT 1
#if (__VER__ < 6300000)
#define VOLATILE
#else
#define VOLATILE volatile
#endif
#if (defined __ARM7M__) // Needed for old versions that do not know the define yet
#if (__CORE__ == __ARM7M__) // Cortex-M3
#define _CORE_HAS_RTT_ASM_SUPPORT 1
#endif
#endif
#if (defined __ARM7EM__)
#if (__CORE__ == __ARM7EM__) // Cortex-M4/M7
#define _CORE_HAS_RTT_ASM_SUPPORT 1
#define _CORE_NEEDS_DMB 1
#define RTT__DMB() asm VOLATILE ("DMB");
#endif
#endif
#if (defined __ARM8M_BASELINE__)
#if (__CORE__ == __ARM8M_BASELINE__) // Cortex-M23
#define _CORE_HAS_RTT_ASM_SUPPORT 0
#define _CORE_NEEDS_DMB 1
#define RTT__DMB() asm VOLATILE ("DMB");
#endif
#endif
#if (defined __ARM8M_MAINLINE__)
#if (__CORE__ == __ARM8M_MAINLINE__) // Cortex-M33
#define _CORE_HAS_RTT_ASM_SUPPORT 1
#define _CORE_NEEDS_DMB 1
#define RTT__DMB() asm VOLATILE ("DMB");
#endif
#endif
#if (defined __ARM8EM_MAINLINE__)
#if (__CORE__ == __ARM8EM_MAINLINE__) // Cortex-???
#define _CORE_HAS_RTT_ASM_SUPPORT 1
#define _CORE_NEEDS_DMB 1
#define RTT__DMB() asm VOLATILE ("DMB");
#endif
#endif
#if\
((defined __ARM7A__) && (__CORE__ == __ARM7A__)) || \
((defined __ARM7R__) && (__CORE__ == __ARM7R__)) || \
((defined __ARM8A__) && (__CORE__ == __ARM8A__)) || \
((defined __ARM8R__) && (__CORE__ == __ARM8R__))
//
// Cortex-A/R ARMv7-A/R & ARMv8-A/R
//
#define _CORE_NEEDS_DMB 1
#define RTT__DMB() asm VOLATILE ("DMB");
#endif
#else
//
// Other compilers
//
#define _CC_HAS_RTT_ASM_SUPPORT 0
#define _CORE_HAS_RTT_ASM_SUPPORT 0
#endif
//
// If IDE and core support the ASM version, enable ASM version by default
//
#ifndef _CORE_HAS_RTT_ASM_SUPPORT
#define _CORE_HAS_RTT_ASM_SUPPORT 0 // Default for unknown cores
#endif
#if (_CC_HAS_RTT_ASM_SUPPORT && _CORE_HAS_RTT_ASM_SUPPORT)
#define RTT_USE_ASM (1)
#else
#define RTT_USE_ASM (0)
#endif
#endif
#ifndef _CORE_NEEDS_DMB
#define _CORE_NEEDS_DMB 0
#endif
#ifndef RTT__DMB
#if _CORE_NEEDS_DMB
#error "Don't know how to place inline assembly for DMB"
#else
#define RTT__DMB()
#endif
#endif
#ifndef SEGGER_RTT_CPU_CACHE_LINE_SIZE
#define SEGGER_RTT_CPU_CACHE_LINE_SIZE (0) // On most target systems where RTT is used, we do not have a CPU cache, therefore 0 is a good default here
#endif
#ifndef SEGGER_RTT_UNCACHED_OFF
#if SEGGER_RTT_CPU_CACHE_LINE_SIZE
#error "SEGGER_RTT_UNCACHED_OFF must be defined when setting SEGGER_RTT_CPU_CACHE_LINE_SIZE != 0"
#else
#define SEGGER_RTT_UNCACHED_OFF (0)
#endif
#endif
#if RTT_USE_ASM
#if SEGGER_RTT_CPU_CACHE_LINE_SIZE
#error "RTT_USE_ASM is not available if SEGGER_RTT_CPU_CACHE_LINE_SIZE != 0"
#endif
#endif
#ifndef SEGGER_RTT_ASM // defined when SEGGER_RTT.h is included from assembly file
#include <stdlib.h>
#include <stdarg.h>
#include <stdint.h>
/*********************************************************************
*
* Defines, fixed
*
**********************************************************************
*/
//
// Determine how much we must pad the control block to make it a multiple of a cache line in size
// Assuming: U8 = 1B
// U16 = 2B
// U32 = 4B
// U8/U16/U32* = 4B
//
#if SEGGER_RTT_CPU_CACHE_LINE_SIZE // Avoid division by zero in case we do not have any cache
#define SEGGER_RTT__ROUND_UP_2_CACHE_LINE_SIZE(NumBytes) (((NumBytes + SEGGER_RTT_CPU_CACHE_LINE_SIZE - 1) / SEGGER_RTT_CPU_CACHE_LINE_SIZE) * SEGGER_RTT_CPU_CACHE_LINE_SIZE)
#else
#define SEGGER_RTT__ROUND_UP_2_CACHE_LINE_SIZE(NumBytes) (NumBytes)
#endif
#define SEGGER_RTT__CB_SIZE (16 + 4 + 4 + (SEGGER_RTT_MAX_NUM_UP_BUFFERS * 24) + (SEGGER_RTT_MAX_NUM_DOWN_BUFFERS * 24))
#define SEGGER_RTT__CB_PADDING (SEGGER_RTT__ROUND_UP_2_CACHE_LINE_SIZE(SEGGER_RTT__CB_SIZE) - SEGGER_RTT__CB_SIZE)
/*********************************************************************
*
* Types
*
**********************************************************************
*/
//
// Description for a circular buffer (also called "ring buffer")
// which is used as up-buffer (T->H)
//
typedef struct {
const char* sName; // Optional name. Standard names so far are: "Terminal", "SysView", "J-Scope_t4i4"
char* pBuffer; // Pointer to start of buffer
unsigned SizeOfBuffer; // Buffer size in bytes. Note that one byte is lost, as this implementation does not fill up the buffer in order to avoid the problem of being unable to distinguish between full and empty.
unsigned WrOff; // Position of next item to be written by either target.
volatile unsigned RdOff; // Position of next item to be read by host. Must be volatile since it may be modified by host.
unsigned Flags; // Contains configuration flags. Flags[31:24] are used for validity check and must be zero. Flags[23:2] are reserved for future use. Flags[1:0] = RTT operating mode.
} SEGGER_RTT_BUFFER_UP;
//
// Description for a circular buffer (also called "ring buffer")
// which is used as down-buffer (H->T)
//
typedef struct {
const char* sName; // Optional name. Standard names so far are: "Terminal", "SysView", "J-Scope_t4i4"
char* pBuffer; // Pointer to start of buffer
unsigned SizeOfBuffer; // Buffer size in bytes. Note that one byte is lost, as this implementation does not fill up the buffer in order to avoid the problem of being unable to distinguish between full and empty.
volatile unsigned WrOff; // Position of next item to be written by host. Must be volatile since it may be modified by host.
unsigned RdOff; // Position of next item to be read by target (down-buffer).
unsigned Flags; // Contains configuration flags. Flags[31:24] are used for validity check and must be zero. Flags[23:2] are reserved for future use. Flags[1:0] = RTT operating mode.
} SEGGER_RTT_BUFFER_DOWN;
//
// RTT control block which describes the number of buffers available
// as well as the configuration for each buffer
//
//
typedef struct {
char acID[16]; // Initialized to "SEGGER RTT"
int MaxNumUpBuffers; // Initialized to SEGGER_RTT_MAX_NUM_UP_BUFFERS (type. 2)
int MaxNumDownBuffers; // Initialized to SEGGER_RTT_MAX_NUM_DOWN_BUFFERS (type. 2)
SEGGER_RTT_BUFFER_UP aUp[SEGGER_RTT_MAX_NUM_UP_BUFFERS]; // Up buffers, transferring information up from target via debug probe to host
SEGGER_RTT_BUFFER_DOWN aDown[SEGGER_RTT_MAX_NUM_DOWN_BUFFERS]; // Down buffers, transferring information down from host via debug probe to target
#if SEGGER_RTT__CB_PADDING
unsigned char aDummy[SEGGER_RTT__CB_PADDING];
#endif
} SEGGER_RTT_CB;
/*********************************************************************
*
* Global data
*
**********************************************************************
*/
extern SEGGER_RTT_CB _SEGGER_RTT;
/*********************************************************************
*
* RTT API functions
*
**********************************************************************
*/
#ifdef __cplusplus
extern "C" {
#endif
int SEGGER_RTT_AllocDownBuffer (const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags);
int SEGGER_RTT_AllocUpBuffer (const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags);
int SEGGER_RTT_ConfigUpBuffer (unsigned BufferIndex, const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags);
int SEGGER_RTT_ConfigDownBuffer (unsigned BufferIndex, const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags);
int SEGGER_RTT_GetKey (void);
unsigned SEGGER_RTT_HasData (unsigned BufferIndex);
int SEGGER_RTT_HasKey (void);
unsigned SEGGER_RTT_HasDataUp (unsigned BufferIndex);
void SEGGER_RTT_Init (void);
unsigned SEGGER_RTT_Read (unsigned BufferIndex, void* pBuffer, unsigned BufferSize);
unsigned SEGGER_RTT_ReadNoLock (unsigned BufferIndex, void* pData, unsigned BufferSize);
int SEGGER_RTT_SetNameDownBuffer (unsigned BufferIndex, const char* sName);
int SEGGER_RTT_SetNameUpBuffer (unsigned BufferIndex, const char* sName);
int SEGGER_RTT_SetFlagsDownBuffer (unsigned BufferIndex, unsigned Flags);
int SEGGER_RTT_SetFlagsUpBuffer (unsigned BufferIndex, unsigned Flags);
int SEGGER_RTT_WaitKey (void);
unsigned SEGGER_RTT_Write (unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);
unsigned SEGGER_RTT_WriteNoLock (unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);
unsigned SEGGER_RTT_WriteSkipNoLock (unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);
unsigned SEGGER_RTT_ASM_WriteSkipNoLock (unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);
unsigned SEGGER_RTT_WriteString (unsigned BufferIndex, const char* s);
void SEGGER_RTT_WriteWithOverwriteNoLock(unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);
unsigned SEGGER_RTT_PutChar (unsigned BufferIndex, char c);
unsigned SEGGER_RTT_PutCharSkip (unsigned BufferIndex, char c);
unsigned SEGGER_RTT_PutCharSkipNoLock (unsigned BufferIndex, char c);
unsigned SEGGER_RTT_GetAvailWriteSpace (unsigned BufferIndex);
unsigned SEGGER_RTT_GetBytesInBuffer (unsigned BufferIndex);
//
// Function macro for performance optimization
//
#define SEGGER_RTT_HASDATA(n) (((SEGGER_RTT_BUFFER_DOWN*)((uintptr_t)&_SEGGER_RTT.aDown[n] + SEGGER_RTT_UNCACHED_OFF))->WrOff - ((SEGGER_RTT_BUFFER_DOWN*)((uintptr_t)&_SEGGER_RTT.aDown[n] + SEGGER_RTT_UNCACHED_OFF))->RdOff)
#if RTT_USE_ASM
#define SEGGER_RTT_WriteSkipNoLock SEGGER_RTT_ASM_WriteSkipNoLock
#endif
/*********************************************************************
*
* RTT transfer functions to send RTT data via other channels.
*
**********************************************************************
*/
unsigned SEGGER_RTT_ReadUpBuffer (unsigned BufferIndex, void* pBuffer, unsigned BufferSize);
unsigned SEGGER_RTT_ReadUpBufferNoLock (unsigned BufferIndex, void* pData, unsigned BufferSize);
unsigned SEGGER_RTT_WriteDownBuffer (unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);
unsigned SEGGER_RTT_WriteDownBufferNoLock (unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);
#define SEGGER_RTT_HASDATA_UP(n) (((SEGGER_RTT_BUFFER_UP*)((uintptr_t)&_SEGGER_RTT.aUp[n] + SEGGER_RTT_UNCACHED_OFF))->WrOff - ((SEGGER_RTT_BUFFER_UP*)((uintptr_t)&_SEGGER_RTT.aUp[n] + SEGGER_RTT_UNCACHED_OFF))->RdOff) // Access uncached to make sure we see changes made by the J-Link side and all of our changes go into HW directly
/*********************************************************************
*
* RTT "Terminal" API functions
*
**********************************************************************
*/
int SEGGER_RTT_SetTerminal (unsigned char TerminalId);
int SEGGER_RTT_TerminalOut (unsigned char TerminalId, const char* s);
/*********************************************************************
*
* RTT printf functions (require SEGGER_RTT_printf.c)
*
**********************************************************************
*/
int SEGGER_RTT_printf(unsigned BufferIndex, const char * sFormat, ...);
int SEGGER_RTT_vprintf(unsigned BufferIndex, const char * sFormat, va_list * pParamList);
#ifdef __cplusplus
}
#endif
#endif // ifndef(SEGGER_RTT_ASM)
//
// For some environments, NULL may not be defined until certain headers are included
//
#ifndef NULL
#define NULL ((void*)0)
#endif
/*********************************************************************
*
* Defines
*
**********************************************************************
*/
//
// Operating modes. Define behavior if buffer is full (not enough space for entire message)
//
#define SEGGER_RTT_MODE_NO_BLOCK_SKIP (0) // Skip. Do not block, output nothing. (Default)
#define SEGGER_RTT_MODE_NO_BLOCK_TRIM (1) // Trim: Do not block, output as much as fits.
#define SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL (2) // Block: Wait until there is space in the buffer.
#define SEGGER_RTT_MODE_MASK (3)
//
// Control sequences, based on ANSI.
// Can be used to control color, and clear the screen
//
#define RTT_CTRL_RESET "\x1B[0m" // Reset to default colors
#define RTT_CTRL_CLEAR "\x1B[2J" // Clear screen, reposition cursor to top left
#define RTT_CTRL_TEXT_BLACK "\x1B[2;30m"
#define RTT_CTRL_TEXT_RED "\x1B[2;31m"
#define RTT_CTRL_TEXT_GREEN "\x1B[2;32m"
#define RTT_CTRL_TEXT_YELLOW "\x1B[2;33m"
#define RTT_CTRL_TEXT_BLUE "\x1B[2;34m"
#define RTT_CTRL_TEXT_MAGENTA "\x1B[2;35m"
#define RTT_CTRL_TEXT_CYAN "\x1B[2;36m"
#define RTT_CTRL_TEXT_WHITE "\x1B[2;37m"
#define RTT_CTRL_TEXT_BRIGHT_BLACK "\x1B[1;30m"
#define RTT_CTRL_TEXT_BRIGHT_RED "\x1B[1;31m"
#define RTT_CTRL_TEXT_BRIGHT_GREEN "\x1B[1;32m"
#define RTT_CTRL_TEXT_BRIGHT_YELLOW "\x1B[1;33m"
#define RTT_CTRL_TEXT_BRIGHT_BLUE "\x1B[1;34m"
#define RTT_CTRL_TEXT_BRIGHT_MAGENTA "\x1B[1;35m"
#define RTT_CTRL_TEXT_BRIGHT_CYAN "\x1B[1;36m"
#define RTT_CTRL_TEXT_BRIGHT_WHITE "\x1B[1;37m"
#define RTT_CTRL_BG_BLACK "\x1B[24;40m"
#define RTT_CTRL_BG_RED "\x1B[24;41m"
#define RTT_CTRL_BG_GREEN "\x1B[24;42m"
#define RTT_CTRL_BG_YELLOW "\x1B[24;43m"
#define RTT_CTRL_BG_BLUE "\x1B[24;44m"
#define RTT_CTRL_BG_MAGENTA "\x1B[24;45m"
#define RTT_CTRL_BG_CYAN "\x1B[24;46m"
#define RTT_CTRL_BG_WHITE "\x1B[24;47m"
#define RTT_CTRL_BG_BRIGHT_BLACK "\x1B[4;40m"
#define RTT_CTRL_BG_BRIGHT_RED "\x1B[4;41m"
#define RTT_CTRL_BG_BRIGHT_GREEN "\x1B[4;42m"
#define RTT_CTRL_BG_BRIGHT_YELLOW "\x1B[4;43m"
#define RTT_CTRL_BG_BRIGHT_BLUE "\x1B[4;44m"
#define RTT_CTRL_BG_BRIGHT_MAGENTA "\x1B[4;45m"
#define RTT_CTRL_BG_BRIGHT_CYAN "\x1B[4;46m"
#define RTT_CTRL_BG_BRIGHT_WHITE "\x1B[4;47m"
#endif
/*************************** End of file ****************************/

View File

@ -0,0 +1,32 @@
/*********************************************************************
* (c) SEGGER Microcontroller GmbH *
* The Embedded Experts *
* www.segger.com *
**********************************************************************
* *
* SEGGER RTT * Real Time Transfer for embedded targets *
* https://github.com/SEGGERMicro/RTT *
* *
**********************************************************************
---------------------------END-OF-HEADER------------------------------
Purpose : User configuration file for RTT.
For available configuration,
refer to SEGGER_RTT_ConfDefaults.h.
----------------------------------------------------------------------
*/
#ifndef SEGGER_RTT_CONF_H
#define SEGGER_RTT_CONF_H
/*********************************************************************
*
* Defines, configurable
*
**********************************************************************
*/
#endif
/*************************** End of file ****************************/

View File

@ -0,0 +1,476 @@
/*********************************************************************
* (c) SEGGER Microcontroller GmbH *
* The Embedded Experts *
* www.segger.com *
**********************************************************************
* *
* SEGGER RTT * Real Time Transfer for embedded targets *
* https://github.com/SEGGERMicro/RTT *
* *
**********************************************************************
---------------------------END-OF-HEADER------------------------------
Purpose : Default configuration for RTT.
Do not change this file! Use SEGGER_RTT_Conf.h instead.
----------------------------------------------------------------------
*/
#ifndef SEGGER_RTT_CONF_DEFAULTS_H
#define SEGGER_RTT_CONF_DEFAULTS_H
#include "SEGGER_RTT_Conf.h"
/*********************************************************************
*
* Defines, configurable
*
**********************************************************************
*/
//
// Take in and set to correct values for Cortex-A systems with CPU cache
//
//#define SEGGER_RTT_CPU_CACHE_LINE_SIZE (32) // Largest cache line size (in bytes) in the current system
//#define SEGGER_RTT_UNCACHED_OFF (0xFB000000) // Address alias where RTT CB and buffers can be accessed uncached
//
/*********************************************************************
*
* SEGGER_RTT_MAX_NUM_UP_BUFFERS
*
* Description
* Maximum number of RTT up-buffers (Target -> Host).
*
* Additional information
* Common use case:
* Up-buffer channel 0: RTT Terminal I/O.
* Up-buffer channel 1: SystemView.
*/
#ifndef SEGGER_RTT_MAX_NUM_UP_BUFFERS
#define SEGGER_RTT_MAX_NUM_UP_BUFFERS (3)
#endif
/*********************************************************************
*
* SEGGER_RTT_MAX_NUM_DOWN_BUFFERS
*
* Description
* Maximum number of RTT down-buffers (Host -> Target).
*
* Additional information
* Common use case:
* Down-buffer channel 0: RTT Terminal I/O.
* Down-buffer channel 1: SystemView.
*
* The number of up- and down-buffers may differ.
*/
#ifndef SEGGER_RTT_MAX_NUM_DOWN_BUFFERS
#define SEGGER_RTT_MAX_NUM_DOWN_BUFFERS (3)
#endif
/*********************************************************************
*
* BUFFER_SIZE_UP
*
* Description
* Size of (auto-installed) up-buffer channel 0.
*
* Additional information
* Channel 0 is commonly used for Terminal I/O.
* Buffer should be large enough for all terminal (to host) output
* messages.
*/
#ifndef BUFFER_SIZE_UP
#define BUFFER_SIZE_UP (1024)
#endif
/*********************************************************************
*
* BUFFER_SIZE_DOWN
*
* Description
* Size of (auto-installed) down-buffer channel 0.
*
* Additional information
* Channel 0 is commonly used for Terminal I/O.
* Buffer should be large enough to receive all terminal
* (from host) input.
*/
#ifndef BUFFER_SIZE_DOWN
#define BUFFER_SIZE_DOWN (16)
#endif
/*********************************************************************
*
* SEGGER_RTT_MODE_DEFAULT
*
* Description
* RTT Mode for channel 0.
*/
#ifndef SEGGER_RTT_MODE_DEFAULT
#define SEGGER_RTT_MODE_DEFAULT SEGGER_RTT_MODE_NO_BLOCK_SKIP
#endif
/*********************************************************************
*
* SEGGER_RTT_PRINTF_BUFFER_SIZE
*
* Description
* Size of temporary buffer for RTT printf bulk-send.
*/
#ifndef SEGGER_RTT_PRINTF_BUFFER_SIZE
#define SEGGER_RTT_PRINTF_BUFFER_SIZE (64u)
#endif
/*********************************************************************
*
* RTT memcpy configuration
*
* memcpy() is good for large amounts of data,
* but the overhead is big for small amounts, which are usually stored via RTT.
* With SEGGER_RTT_MEMCPY_USE_BYTELOOP a simple byte loop can be used instead.
*
* SEGGER_RTT_MEMCPY() can be used to replace standard memcpy() in RTT functions.
* This is may be required with memory access restrictions,
* such as on Cortex-A devices with MMU.
*/
#ifndef SEGGER_RTT_MEMCPY_USE_BYTELOOP
#define SEGGER_RTT_MEMCPY_USE_BYTELOOP 0 // 0: Use memcpy/SEGGER_RTT_MEMCPY, 1: Use a simple byte-loop
#endif
//
// Example definition of SEGGER_RTT_MEMCPY to external memcpy with GCC toolchains and Cortex-A targets
//
//#if ((defined __SES_ARM) || (defined __CROSSWORKS_ARM) || (defined __GNUC__)) && (defined (__ARM_ARCH_7A__))
// #define SEGGER_RTT_MEMCPY(pDest, pSrc, NumBytes) SEGGER_memcpy((pDest), (pSrc), (NumBytes))
//#endif
//
// Target is not allowed to perform other RTT operations while string still has not been stored completely.
// Otherwise we would probably end up with a mixed string in the buffer.
// If using RTT from within interrupts, multiple tasks or multi processors, define the SEGGER_RTT_LOCK() and SEGGER_RTT_UNLOCK() function here.
//
// SEGGER_RTT_MAX_INTERRUPT_PRIORITY can be used in the sample lock routines on Cortex-M3/4.
// Make sure to mask all interrupts which can send RTT data, i.e. generate SystemView events, or cause task switches.
// When high-priority interrupts must not be masked while sending RTT data, SEGGER_RTT_MAX_INTERRUPT_PRIORITY needs to be adjusted accordingly.
// (Higher priority = lower priority number)
// Default value for embOS: 128u
// Default configuration in FreeRTOS: configMAX_SYSCALL_INTERRUPT_PRIORITY: ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
// In case of doubt mask all interrupts: 1 << (8 - BASEPRI_PRIO_BITS) i.e. 1 << 5 when 3 bits are implemented in NVIC
// or define SEGGER_RTT_LOCK() to completely disable interrupts.
//
#ifndef SEGGER_RTT_MAX_INTERRUPT_PRIORITY
#define SEGGER_RTT_MAX_INTERRUPT_PRIORITY (0x20) // Interrupt priority to lock on SEGGER_RTT_LOCK on Cortex-M3/4 (Default: 0x20)
#endif
/*********************************************************************
*
* RTT lock configuration for SEGGER Embedded Studio,
* Rowley CrossStudio and GCC
*/
#if !defined(SEGGER_RTT_LOCK) || !defined (SEGGER_RTT_UNLOCK)
#if ((defined(__SES_ARM) || defined(__SES_RISCV) || defined(__CROSSWORKS_ARM) || defined(__GNUC__) || defined(__clang__)) && !defined (__CC_ARM) && !defined(WIN32))
#if (defined(__ARM_ARCH_6M__) || defined(__ARM_ARCH_8M_BASE__))
#define SEGGER_RTT_LOCK() { \
unsigned int _SEGGER_RTT__LockState; \
__asm volatile ("mrs %0, primask \n\t" \
"movs r1, #1 \n\t" \
"msr primask, r1 \n\t" \
: "=r" (_SEGGER_RTT__LockState) \
: \
: "r1", "cc" \
);
#define SEGGER_RTT_UNLOCK() __asm volatile ("msr primask, %0 \n\t" \
: \
: "r" (_SEGGER_RTT__LockState) \
: \
); \
}
#elif (defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__) || defined(__ARM_ARCH_8M_MAIN__) || defined(__ARM_ARCH_8_1M_MAIN__))
#ifndef SEGGER_RTT_MAX_INTERRUPT_PRIORITY
#define SEGGER_RTT_MAX_INTERRUPT_PRIORITY (0x20)
#endif
#define SEGGER_RTT_LOCK() { \
unsigned int _SEGGER_RTT__LockState; \
__asm volatile ("mrs %0, basepri \n\t" \
"mov r1, %1 \n\t" \
"msr basepri, r1 \n\t" \
: "=r" (_SEGGER_RTT__LockState) \
: "i"(SEGGER_RTT_MAX_INTERRUPT_PRIORITY) \
: "r1", "cc" \
);
#define SEGGER_RTT_UNLOCK() __asm volatile ("msr basepri, %0 \n\t" \
: \
: "r" (_SEGGER_RTT__LockState) \
: \
); \
}
#elif (defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7R__))
#define SEGGER_RTT_LOCK() { \
unsigned int _SEGGER_RTT__LockState; \
__asm volatile ("mrs r1, CPSR \n\t" \
"mov %0, r1 \n\t" \
"orr r1, r1, #0xC0 \n\t" \
"msr CPSR_c, r1 \n\t" \
: "=r" (_SEGGER_RTT__LockState) \
: \
: "r1", "cc" \
);
#define SEGGER_RTT_UNLOCK() __asm volatile ("mov r0, %0 \n\t" \
"mrs r1, CPSR \n\t" \
"bic r1, r1, #0xC0 \n\t" \
"and r0, r0, #0xC0 \n\t" \
"orr r1, r1, r0 \n\t" \
"msr CPSR_c, r1 \n\t" \
: \
: "r" (_SEGGER_RTT__LockState) \
: "r0", "r1", "cc" \
); \
}
#elif defined(__riscv) || defined(__riscv_xlen)
#define SEGGER_RTT_LOCK() { \
unsigned int _SEGGER_RTT__LockState; \
__asm volatile ("csrr %0, mstatus \n\t" \
"csrci mstatus, 8 \n\t" \
"andi %0, %0, 8 \n\t" \
: "=r" (_SEGGER_RTT__LockState) \
: \
: \
);
#define SEGGER_RTT_UNLOCK() __asm volatile ("csrr a1, mstatus \n\t" \
"or %0, %0, a1 \n\t" \
"csrs mstatus, %0 \n\t" \
: \
: "r" (_SEGGER_RTT__LockState) \
: "a1" \
); \
}
#endif
#endif
#endif
/*********************************************************************
*
* RTT lock configuration for IAR EWARM
*/
#if !defined(SEGGER_RTT_LOCK) || !defined (SEGGER_RTT_UNLOCK)
#ifdef __ICCARM__
#ifdef __IAR_SYSTEMS_ICC__
#include <intrinsics.h>
#endif
#if (defined (__ARM6M__) && (__CORE__ == __ARM6M__)) || \
(defined (__ARM8M_BASELINE__) && (__CORE__ == __ARM8M_BASELINE__))
#define SEGGER_RTT_LOCK() { \
unsigned int _SEGGER_RTT__LockState; \
_SEGGER_RTT__LockState = __get_PRIMASK(); \
__set_PRIMASK(1);
#define SEGGER_RTT_UNLOCK() __set_PRIMASK(_SEGGER_RTT__LockState); \
}
#elif (defined (__ARM7EM__) && (__CORE__ == __ARM7EM__)) || \
(defined (__ARM7M__) && (__CORE__ == __ARM7M__)) || \
(defined (__ARM8M_MAINLINE__) && (__CORE__ == __ARM8M_MAINLINE__)) || \
(defined (__ARM8M_MAINLINE__) && (__CORE__ == __ARM8M_MAINLINE__))
#ifndef SEGGER_RTT_MAX_INTERRUPT_PRIORITY
#define SEGGER_RTT_MAX_INTERRUPT_PRIORITY (0x20)
#endif
#define SEGGER_RTT_LOCK() { \
unsigned int _SEGGER_RTT__LockState; \
_SEGGER_RTT__LockState = __get_BASEPRI(); \
__set_BASEPRI(SEGGER_RTT_MAX_INTERRUPT_PRIORITY);
#define SEGGER_RTT_UNLOCK() __set_BASEPRI(_SEGGER_RTT__LockState); \
}
#elif (defined (__ARM7A__) && (__CORE__ == __ARM7A__)) || \
(defined (__ARM7R__) && (__CORE__ == __ARM7R__))
#define SEGGER_RTT_LOCK() { \
unsigned int _SEGGER_RTT__LockState; \
__asm volatile ("mrs r1, CPSR \n\t" \
"mov %0, r1 \n\t" \
"orr r1, r1, #0xC0 \n\t" \
"msr CPSR_c, r1 \n\t" \
: "=r" (_SEGGER_RTT__LockState) \
: \
: "r1", "cc" \
);
#define SEGGER_RTT_UNLOCK() __asm volatile ("mov r0, %0 \n\t" \
"mrs r1, CPSR \n\t" \
"bic r1, r1, #0xC0 \n\t" \
"and r0, r0, #0xC0 \n\t" \
"orr r1, r1, r0 \n\t" \
"msr CPSR_c, r1 \n\t" \
: \
: "r" (_SEGGER_RTT__LockState) \
: "r0", "r1", "cc" \
); \
}
#endif
#endif
#endif
/*********************************************************************
*
* RTT lock configuration for IAR RX
*/
#if !defined(SEGGER_RTT_LOCK) || !defined (SEGGER_RTT_UNLOCK)
#ifdef __ICCRX__
#ifdef __IAR_SYSTEMS_ICC__
#include <intrinsics.h>
#endif
#define SEGGER_RTT_LOCK() { \
unsigned long _SEGGER_RTT__LockState; \
_SEGGER_RTT__LockState = __get_interrupt_state(); \
__disable_interrupt();
#define SEGGER_RTT_UNLOCK() __set_interrupt_state(_SEGGER_RTT__LockState); \
}
#endif
#endif
/*********************************************************************
*
* RTT lock configuration for IAR RL78
*/
#if !defined(SEGGER_RTT_LOCK) || !defined (SEGGER_RTT_UNLOCK)
#ifdef __ICCRL78__
#ifdef __IAR_SYSTEMS_ICC__
#include <intrinsics.h>
#endif
#define SEGGER_RTT_LOCK() { \
__istate_t _SEGGER_RTT__LockState; \
_SEGGER_RTT__LockState = __get_interrupt_state(); \
__disable_interrupt();
#define SEGGER_RTT_UNLOCK() __set_interrupt_state(_SEGGER_RTT__LockState); \
}
#endif
#endif
/*********************************************************************
*
* RTT lock configuration for KEIL ARM
*/
#if !defined(SEGGER_RTT_LOCK) || !defined (SEGGER_RTT_UNLOCK)
#ifdef __CC_ARM
#if (defined __TARGET_ARCH_6S_M)
#define SEGGER_RTT_LOCK() { \
unsigned int _SEGGER_RTT__LockState; \
register unsigned char _SEGGER_RTT__PRIMASK __asm( "primask"); \
_SEGGER_RTT__LockState = _SEGGER_RTT__PRIMASK; \
_SEGGER_RTT__PRIMASK = 1u; \
__schedule_barrier();
#define SEGGER_RTT_UNLOCK() _SEGGER_RTT__PRIMASK = _SEGGER_RTT__LockState; \
__schedule_barrier(); \
}
#elif (defined(__TARGET_ARCH_7_M) || defined(__TARGET_ARCH_7E_M))
#ifndef SEGGER_RTT_MAX_INTERRUPT_PRIORITY
#define SEGGER_RTT_MAX_INTERRUPT_PRIORITY (0x20)
#endif
#define SEGGER_RTT_LOCK() { \
unsigned int _SEGGER_RTT__LockState; \
register unsigned char BASEPRI __asm( "basepri"); \
_SEGGER_RTT__LockState = BASEPRI; \
BASEPRI = SEGGER_RTT_MAX_INTERRUPT_PRIORITY; \
__schedule_barrier();
#define SEGGER_RTT_UNLOCK() BASEPRI = _SEGGER_RTT__LockState; \
__schedule_barrier(); \
}
#endif
#endif
#endif
/*********************************************************************
*
* RTT lock configuration for TI ARM
*/
#if !defined(SEGGER_RTT_LOCK) || !defined (SEGGER_RTT_UNLOCK)
#ifdef __TI_ARM__
#if defined (__TI_ARM_V6M0__)
#define SEGGER_RTT_LOCK() { \
unsigned int _SEGGER_RTT__LockState; \
_SEGGER_RTT__LockState = __get_PRIMASK(); \
__set_PRIMASK(1);
#define SEGGER_RTT_UNLOCK() __set_PRIMASK(_SEGGER_RTT__LockState); \
}
#elif (defined (__TI_ARM_V7M3__) || defined (__TI_ARM_V7M4__))
#ifndef SEGGER_RTT_MAX_INTERRUPT_PRIORITY
#define SEGGER_RTT_MAX_INTERRUPT_PRIORITY (0x20)
#endif
#define SEGGER_RTT_LOCK() { \
unsigned int _SEGGER_RTT__LockState; \
_SEGGER_RTT__LockState = _set_interrupt_priority(SEGGER_RTT_MAX_INTERRUPT_PRIORITY);
#define SEGGER_RTT_UNLOCK() _set_interrupt_priority(_SEGGER_RTT__LockState); \
}
#endif
#endif
#endif
/*********************************************************************
*
* RTT lock configuration for CCRX
*/
#if !defined(SEGGER_RTT_LOCK) || !defined (SEGGER_RTT_UNLOCK)
#ifdef __RX
#include <machine.h>
#define SEGGER_RTT_LOCK() { \
unsigned long _SEGGER_RTT__LockState; \
_SEGGER_RTT__LockState = get_psw() & 0x010000; \
clrpsw_i();
#define SEGGER_RTT_UNLOCK() set_psw(get_psw() | _SEGGER_RTT__LockState); \
}
#endif
#endif
/*********************************************************************
*
* RTT lock configuration for embOS Simulation on Windows
* (Can also be used for generic RTT locking with embOS)
*/
#if !defined(SEGGER_RTT_LOCK) || !defined (SEGGER_RTT_UNLOCK)
#if defined(WIN32) || defined(SEGGER_RTT_LOCK_EMBOS)
void OS_SIM_EnterCriticalSection(void);
void OS_SIM_LeaveCriticalSection(void);
#define SEGGER_RTT_LOCK() { \
OS_SIM_EnterCriticalSection();
#define SEGGER_RTT_UNLOCK() OS_SIM_LeaveCriticalSection(); \
}
#endif
#endif
/*********************************************************************
*
* RTT lock configuration fallback
*/
#ifndef SEGGER_RTT_LOCK
#define SEGGER_RTT_LOCK() // Lock RTT (nestable) (i.e. disable interrupts)
#endif
#ifndef SEGGER_RTT_UNLOCK
#define SEGGER_RTT_UNLOCK() // Unlock RTT (nestable) (i.e. enable previous interrupt lock state)
#endif
/*********************************************************************
*
* If SEGGER_RTT_SECTION is defined but SEGGER_RTT_BUFFER_SECTION
* is not, use the same section for SEGGER_RTT_BUFFER_SECTION.
*/
#ifndef SEGGER_RTT_BUFFER_SECTION
#if defined(SEGGER_RTT_SECTION)
#define SEGGER_RTT_BUFFER_SECTION SEGGER_RTT_SECTION
#endif
#endif
#endif
/*************************** End of file ****************************/

8
tools/JLinkSettings.ini Normal file
View File

@ -0,0 +1,8 @@
[GENERAL]
HideDeviceSelection = 1
[CPU]
Device="Cortex-M4"
[FLASH]
Device="Cortex-M4"

295
tools/gen_misans_font.py Normal file
View File

@ -0,0 +1,295 @@
#!/usr/bin/env python3
"""Generate MiSans bitmap font C arrays for ILI9341 LCD driver."""
import glob
import math
import os
import re
import sys
from PIL import Image, ImageDraw, ImageFont
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
HEADER_IN = os.path.join(ROOT, "device", "LCD_ILI9341", "Drv_ILI9341_Lcd_ChineseFont.h")
HEADER_OUT = HEADER_IN
ENG_HEADER_IN = os.path.join(ROOT, "device", "LCD_ILI9341", "Drv_ILI9341_Lcd_EnglishFont.h")
ENG_HEADER_OUT = ENG_HEADER_IN
MISANS_DIR = os.path.join(os.path.dirname(ROOT), "..", "Doc", "UI", "MiSans")
MISANS_DIR = os.path.normpath(MISANS_DIR)
def find_ttf(name_part):
for path in glob.glob(os.path.join(MISANS_DIR, "**", "*.ttf"), recursive=True):
if name_part.lower() in os.path.basename(path).lower():
return path
raise FileNotFoundError(f"TTF matching {name_part} not found under {MISANS_DIR}")
def parse_chs_tables(text):
tables = {}
for m in re.finditer(r"const char (CHS\d+Table)\[\]\[2\] = \{(.*?)\};", text, re.S):
name = m.group(1)
body = m.group(2)
entries = []
comments = []
for line in body.splitlines():
cm = re.search(r"\{(0x[0-9A-Fa-f]{2})\s*,\s*(0x[0-9A-Fa-f]{2})\}", line)
if cm:
entries.append((int(cm.group(1), 16), int(cm.group(2), 16)))
cmt = re.search(r"//\s*(.+)", line)
comments.append(cmt.group(1).strip() if cmt else "")
tables[name] = list(zip(entries, comments))
return tables
def gbk_char(h, l):
return bytes([h, l]).decode("gbk", errors="replace")
def render_glyph(ch, size, font, square=True):
if square:
w = h = size
else:
w = size // 2
h = size
img = Image.new("L", (w, h), 0)
draw = ImageDraw.Draw(img)
bbox = draw.textbbox((0, 0), ch, font=font)
tw = bbox[2] - bbox[0]
th = bbox[3] - bbox[1]
x = (w - tw) // 2 - bbox[0]
y = (h - th) // 2 - bbox[1]
draw.text((x, y), ch, fill=255, font=font)
pixels = []
for row in range(h):
for col in range(w):
pixels.append(1 if img.getpixel((col, row)) > 127 else 0)
return pixels, w, h
def cn_to_bytes_msb(pixels, width, height):
row_bytes = (width + 7) // 8
out = []
for row in range(height):
for bi in range(row_bytes):
val = 0
for bit in range(8):
col = bi * 8 + bit
if col < width and pixels[row * width + col]:
val |= (0x80 >> bit)
elif col >= width:
pass
out.append(val)
return out
def ascii_to_bytes_lsb(pixels, width, height):
row_bytes = (width + 7) // 8
out = []
for row in range(height):
for bi in range(row_bytes):
val = 0
for bit in range(8):
col = bi * 8 + bit
if col < width and pixels[row * width + col]:
val |= (0x01 << bit)
out.append(val)
return out
def fmt_bytes(data):
parts = []
for i, b in enumerate(data):
parts.append(f"0x{b:02X}")
lines = []
for i in range(0, len(parts), 16):
lines.append(",".join(parts[i:i + 16]))
return "{" + ",".join(lines) + "}"
def generate_chinese_array(table_name, entries, size, font):
lines = [f"const unsigned char Chinese_font_{size}[][{((size + 7)//8)*size}] = {{"]
for idx, ((h, l), comment) in enumerate(entries):
ch = gbk_char(h, l)
pixels, w, hgt = render_glyph(ch, size, font, square=True)
data = cn_to_bytes_msb(pixels, w, hgt)
cmt = comment or ch
lines.append(f"{fmt_bytes(data)},/*\"{cmt}\",{idx}*/")
lines.append("};")
return "\n".join(lines)
def generate_ascii_array(size, font, array_name=None):
sizex = size // 2
row_bytes = (sizex + 7) // 8
total = row_bytes * size
suffix = f"{size}{sizex}"
name = array_name or f"ascii_{suffix}"
lines = [f"const unsigned char {name}[][{total}]={{"]
for num in range(95):
ch = chr(num + 32)
pixels, w, hgt = render_glyph(ch, size, font, square=False)
data = ascii_to_bytes_lsb(pixels, w, hgt)
lines.append(f"{fmt_bytes(data)},/*\"{ch}\",{num}*/")
lines.append("};")
return name, "\n".join(lines)
def patch_header_chinese(text, tables, fonts_by_size):
# Replace each Chinese_font_XX array
for size, font in fonts_by_size.items():
table_key = {
8: "CHS8Table",
11: "CHS11Table",
12: "CHS12Table",
13: "CHS13Table",
15: "CHS15Table",
16: "CHS16Table",
28: "CHS24Table", # reuse 24 table chars for 28 if no CHS28
}.get(size)
if size == 28:
table_key = "CHS24Table"
if table_key not in tables:
print(f"Skip size {size}: no {table_key}")
continue
entries = tables[table_key]
new_array = generate_chinese_array(table_key, entries, size, font)
pat = rf"const unsigned char Chinese_font_{size}\[\]\[\d+\] = \{{.*?\}};"
if re.search(pat, text, re.S):
text = re.sub(pat, new_array, text, count=1, flags=re.S)
else:
# insert before Chinese_font for next size or at end of tables section
insert_after = f"const char {table_key}"
# add new table for CHS8/CHS15 if missing
pass
return text
def ensure_chs8_table(text, tables):
if "CHS8Table" in tables:
return text, tables
if "CHS12Table" not in tables:
return text, tables
# Insert CHS8Table copy of CHS12Table before CHS11Table
entries = tables["CHS12Table"]
block = "const char CHS8Table[][2] = {\n"
for (h, l), cmt in entries:
block += f" {{0x{h:02X},0x{l:02X}}}, // {cmt}\n"
block += "};\n\n"
text = text.replace("const char CHS11Table", block + "const char CHS11Table", 1)
tables["CHS8Table"] = entries
return text, tables
def ensure_chs15_table(text, tables):
if "CHS15Table" in tables:
return text, tables
if "CHS13Table" not in tables:
return text, tables
entries = tables["CHS13Table"]
block = "const char CHS15Table[][2] = {\n"
for (h, l), cmt in entries:
block += f" {{0x{h:02X},0x{l:02X}}}, // {cmt}\n"
block += "};\n\n"
text = text.replace("const char CHS16Table", block + "const char CHS16Table", 1)
tables["CHS15Table"] = entries
return text, tables
def main():
medium = find_ttf("MiSans-Medium")
semibold = find_ttf("MiSans-Semibold")
print("Medium:", medium)
print("Semibold:", semibold)
with open(HEADER_IN, "r", encoding="utf-8", errors="replace") as f:
text = f.read()
tables = parse_chs_tables(text)
print("Tables:", {k: len(v) for k, v in tables.items()})
text, tables = ensure_chs8_table(text, tables)
text, tables = ensure_chs15_table(text, tables)
# Regenerate all Chinese font arrays
cn_sizes = [8, 11, 12, 13, 15, 16, 24, 28]
for size in cn_sizes:
if size in (24, 28):
table_key = "CHS24Table"
font = ImageFont.truetype(semibold if size == 28 else medium, size - 2)
else:
table_key = {
8: "CHS8Table", 11: "CHS11Table", 12: "CHS12Table",
13: "CHS13Table", 15: "CHS15Table", 16: "CHS16Table",
}[size]
font = ImageFont.truetype(medium, size - 1)
if table_key not in tables:
continue
entries = tables[table_key]
new_array = generate_chinese_array(table_key, entries, size, font)
pat = rf"const unsigned char Chinese_font_{size}\[\]\[\d+\] =[\s\S]*?\}};"
if re.search(pat, text, re.S):
text = re.sub(pat, new_array, text, count=1, flags=re.S)
print(f"Updated Chinese_font_{size} ({len(entries)} glyphs)")
else:
# Insert new array before Chinese_font for next existing or after CHS tables
anchor = "const unsigned char Chinese_font_11"
if size == 8:
anchor = "const unsigned char Chinese_font_11"
elif size == 15:
anchor = "const unsigned char Chinese_font_16"
elif size == 28:
anchor = None
if anchor and anchor in text:
text = text.replace(anchor, new_array + "\n\n" + anchor, 1)
print(f"Inserted Chinese_font_{size}")
elif size == 28:
text = text.rstrip() + "\n\n" + new_array + "\n"
print(f"Appended Chinese_font_{size}")
with open(HEADER_OUT, "w", encoding="utf-8", newline="\n") as f:
f.write(text)
# English / ASCII fonts
with open(ENG_HEADER_IN, "r", encoding="utf-8", errors="replace") as f:
eng = f.read()
ascii_targets = [
(8, medium, None), (11, medium, None), (12, medium, None), (13, medium, "ascii_1306"),
(15, medium, None), (16, medium, "ascii_1608"), (24, medium, "ascii_2412"),
(28, semibold, None),
]
for size, ttf, legacy_name in ascii_targets:
font = ImageFont.truetype(ttf, size - 1)
name, arr = generate_ascii_array(size, font, legacy_name)
pat = rf"const unsigned char {name}\[\]\[\d+\][\s\S]*?\}};"
if re.search(pat, eng, re.S):
eng = re.sub(pat, arr, eng, count=1, flags=re.S)
print(f"Updated {name}")
else:
auto_name, _ = generate_ascii_array(size, font)
pat2 = rf"const unsigned char {auto_name}\[\]\[\d+\][\s\S]*?\}};"
if auto_name != name and re.search(pat2, eng, re.S):
eng = re.sub(pat2, arr, eng, count=1, flags=re.S)
print(f"Updated {auto_name} -> {name}")
else:
eng = eng.rstrip() + "\n\n" + arr + "\n"
print(f"Appended {name}")
with open(ENG_HEADER_OUT, "w", encoding="utf-8", newline="\n") as f:
f.write(eng)
print("Done.")
if __name__ == "__main__":
main()

View File

@ -0,0 +1,2 @@
HideDeviceSelection 1
Device Cortex-M4

View File

@ -0,0 +1,91 @@
#!/usr/bin/env python3
"""Append missing 普/通/业 glyphs to CHS16 MiSans tables."""
import glob
import os
import re
from PIL import Image, ImageDraw, ImageFont
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
HEADER = os.path.join(ROOT, "device", "LCD_ILI9341", "Drv_ILI9341_Lcd_ChineseFont.h")
cands = []
for base in [
os.path.normpath(os.path.join(ROOT, "..", "..", "Doc", "UI")),
r"c:\Users\qjyu\Documents\SoundWalker\一诺国际吉他\Doc\UI",
]:
if os.path.isdir(base):
cands += glob.glob(os.path.join(base, "**", "*.ttf"), recursive=True)
ttf = None
for p in cands:
name = os.path.basename(p).lower()
if "misans" in name and "medium" in name:
ttf = p
break
if not ttf:
for p in cands:
if "misans" in os.path.basename(p).lower():
ttf = p
break
if not ttf:
raise SystemExit(f"MiSans ttf not found, candidates={cands[:10]}")
print("using", ttf)
font = ImageFont.truetype(ttf, 16)
def render(ch, size=16):
img = Image.new("L", (size, size), 0)
draw = ImageDraw.Draw(img)
bbox = draw.textbbox((0, 0), ch, font=font)
tw, th = bbox[2] - bbox[0], bbox[3] - bbox[1]
x = (size - tw) // 2 - bbox[0]
y = (size - th) // 2 - bbox[1]
draw.text((x, y), ch, fill=255, font=font)
out = []
row_bytes = (size + 7) // 8
for row in range(size):
for bi in range(row_bytes):
val = 0
for bit in range(8):
col = bi * 8 + bit
if col < size and img.getpixel((col, row)) > 127:
val |= 0x80 >> bit
out.append(val)
return out
chars = [("", 0xC6, 0xD5), ("", 0xCD, 0xA8), ("", 0xD2, 0xB5)]
glyphs = [(name, h, l, render(name)) for name, h, l in chars]
text = open(HEADER, encoding="utf-8", errors="ignore").read()
m = re.search(r"(const char CHS16Table\[\]\[2\] = \{)(.*?)(\n\};)", text, re.S)
if not m:
raise SystemExit("CHS16Table not found")
body = m.group(2)
for name, h, l, data in glyphs:
needle = "{0x%02X,0x%02X}" % (h, l)
if needle.lower() in body.lower().replace(" ", ""):
print("already in CHS16", name)
else:
body = body.rstrip() + "\n {0x%02X,0x%02X}, // %s\n" % (h, l, name)
print("added to CHS16", name)
text = text[: m.start()] + m.group(1) + body + m.group(3) + text[m.end() :]
m2 = re.search(r"(const unsigned char Chinese_font_16\[\]\[32\] = \{)(.*?)(\n\};)", text, re.S)
if not m2:
raise SystemExit("Chinese_font_16 not found")
fbody = m2.group(2).rstrip()
n = len(re.findall(r"/\*\"", fbody))
print("existing font16 glyphs", n)
for i, (name, h, l, data) in enumerate(glyphs):
# skip if comment already has this char as last additions - check table-driven: always append if we added to table
idx = n + i
arr = ",".join(f"0x{b:02X}" for b in data)
fbody += f"\n{{{arr}}},/*\"{name}\",{idx}*/"
print("added font16", name, "idx", idx)
text = text[: m2.start()] + m2.group(1) + fbody + m2.group(3) + text[m2.end() :]
open(HEADER, "w", encoding="utf-8", newline="\n").write(text)
print("patched OK")

View File

@ -0,0 +1,2 @@
pylink-square>=1.2.0
pillow>=10.0.0

215
tools/rtt_lcd_capture.py Normal file
View File

@ -0,0 +1,215 @@
#!/usr/bin/env python3
"""Capture K1 LCD screen dump from J-Link RTT channel 1 and save as PNG."""
from __future__ import annotations
import argparse
import os
import struct
import sys
import time
MAGIC = b"SCRN"
HEADER_FMT = "<4sHHHH"
HEADER_SIZE = struct.calcsize(HEADER_FMT)
DEFAULT_DEVICES = ("Cortex-M4", "AT32F403AC", "AT32F403A")
def rgb565_bytes_to_rgb(hi: int, lo: int) -> tuple[int, int, int]:
value = (hi << 8) | lo
red = ((value >> 11) & 0x1F) << 3
green = ((value >> 5) & 0x3F) << 2
blue = (value & 0x1F) << 3
return red, green, blue
def import_deps():
try:
import pylink # noqa: F401
except ImportError as exc:
raise SystemExit("Missing dependency: pip install pylink-square") from exc
try:
from PIL import Image # noqa: F401
except ImportError as exc:
raise SystemExit("Missing dependency: pip install pillow") from exc
def connect_jlink(device: str):
import pylink
jlink = pylink.JLink()
jlink.open()
try:
# Avoid interactive "select device" popup for unknown AT32 ID.
jlink.exec_command("HideDeviceSelection = 1")
except Exception:
pass
jlink.set_tif(pylink.enums.JLinkInterfaces.SWD)
last_error = None
for candidate in (device, *DEFAULT_DEVICES):
try:
try:
jlink.exec_command(f"Device = {candidate}")
except Exception:
pass
jlink.connect(candidate)
print(f"Connected as {candidate}")
return jlink
except pylink.errors.JLinkException as exc:
last_error = exc
jlink.close()
raise SystemExit(f"Failed to connect J-Link: {last_error}")
def find_rtt_control_block(jlink, ram_base: int = 0x20000000, ram_size: int = 0x18000) -> int | None:
# AT32F403ARCT7 physical SRAM is 96KB (0x18000).
"""Locate SEGGER RTT CB in SRAM (needed when auto-scan misses high BSS)."""
needle = b"SEGGER RTT"
chunk = 0x1000
was_halted = jlink.halted()
if not was_halted:
jlink.halt()
try:
for off in range(0, ram_size, chunk):
data = bytes(jlink.memory_read8(ram_base + off, min(chunk, ram_size - off)))
idx = data.find(needle)
if idx >= 0:
return ram_base + off + idx
finally:
if not was_halted:
# Resume only — never reset (would wipe the on-screen UI).
if hasattr(jlink, "restart"):
jlink.restart()
else:
jlink.go()
time.sleep(0.1)
return None
def wait_rtt_ready(jlink, timeout_s: float = 15.0) -> None:
deadline = time.time() + timeout_s
while time.time() < deadline:
try:
if jlink.rtt_get_num_up_buffers() > 0:
return
except Exception:
pass
time.sleep(0.2)
raise SystemExit("RTT control block found but buffers not ready")
def capture_rtt_png(out_path: str, device: str, timeout_s: float, do_reset: bool = False) -> None:
import pylink
from PIL import Image
jlink = connect_jlink(device)
try:
if do_reset:
jlink.reset(halt=False)
time.sleep(2.0)
cb = find_rtt_control_block(jlink)
if cb is None:
raise SystemExit("SEGGER RTT control block not found in SRAM")
print(f"RTT CB @ 0x{cb:08X}")
jlink.rtt_start(cb)
wait_rtt_ready(jlink)
# Drain terminal (ch0) and show firmware ACK lines if any.
for _ in range(10):
term = jlink.rtt_read(0, 1024)
if term:
print("RTT0:", bytes(term).decode("utf-8", errors="replace").strip())
time.sleep(0.05)
print("RTT ready. Sending DUMP command...")
wrote = 0
for _ in range(30):
wrote = jlink.rtt_write(0, list(b"DUMP\n"))
if wrote > 0:
break
time.sleep(0.2)
if wrote <= 0:
raise SystemExit("Failed to send DUMP command on RTT down channel 0")
print(f"Sent DUMP ({wrote} bytes). Capturing screen...")
buffer = b""
deadline = time.time() + timeout_s
while time.time() < deadline:
term = jlink.rtt_read(0, 1024)
if term:
print("RTT0:", bytes(term).decode("utf-8", errors="replace").strip())
chunk = jlink.rtt_read(1, 8192)
if chunk:
buffer += bytes(chunk)
if len(buffer) >= HEADER_SIZE and buffer[:4] == MAGIC:
break
time.sleep(0.01)
if len(buffer) < HEADER_SIZE or buffer[:4] != MAGIC:
raise SystemExit("Timeout waiting for SCRN header on RTT channel 1")
_, width, height, fmt, _ = struct.unpack_from(HEADER_FMT, buffer, 0)
if fmt != 1:
raise SystemExit(f"Unsupported pixel format: {fmt}")
pixel_bytes = width * height * 2
buffer = buffer[HEADER_SIZE:]
print(f"Receiving {width}x{height} RGB565 ({pixel_bytes} bytes)...")
while len(buffer) < pixel_bytes and time.time() < deadline:
chunk = jlink.rtt_read(1, 16384)
if chunk:
buffer += bytes(chunk)
else:
time.sleep(0.001)
if len(buffer) < pixel_bytes:
raise SystemExit(f"Incomplete dump: got {len(buffer)} / {pixel_bytes} bytes")
image = Image.new("RGB", (width, height))
pixels = image.load()
offset = 0
for y in range(height):
for x in range(width):
hi = buffer[offset]
lo = buffer[offset + 1]
offset += 2
pixels[x, y] = rgb565_bytes_to_rgb(hi, lo)
image.save(out_path)
print(f"Saved {out_path}")
finally:
try:
jlink.rtt_stop()
except pylink.errors.JLinkException:
pass
jlink.close()
def main() -> None:
parser = argparse.ArgumentParser(description="Capture K1 LCD via J-Link RTT")
parser.add_argument("--out", default="screen.png", help="Output PNG path")
parser.add_argument("--device", default="AT32F403AC", help="J-Link device name")
parser.add_argument("--timeout", type=float, default=60.0, help="Seconds to wait")
parser.add_argument("--open", action="store_true", help="Open PNG after capture")
parser.add_argument(
"--reset",
action="store_true",
help="Reset MCU before capture (default: keep current UI)",
)
args = parser.parse_args()
import_deps()
capture_rtt_png(args.out, args.device, args.timeout, do_reset=args.reset)
if args.open and os.name == "nt":
os.startfile(os.path.abspath(args.out))
if __name__ == "__main__":
main()