mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-23 08:15:30 +03:00
efactor MAX7456 driver code
This commit is contained in:
parent
0892c4786b
commit
171b03bfb7
4 changed files with 208 additions and 191 deletions
|
@ -128,7 +128,7 @@ statistic_t stats;
|
|||
|
||||
#define LEFT_MENU_COLUMN 1
|
||||
#define RIGHT_MENU_COLUMN 23
|
||||
#define MAX_MENU_ITEMS (max7456_get_rows_count() - 2)
|
||||
#define MAX_MENU_ITEMS (max7456GetRowsCount() - 2)
|
||||
|
||||
uint8_t osdRows;
|
||||
|
||||
|
@ -628,25 +628,25 @@ void osdInit(void)
|
|||
|
||||
armState = ARMING_FLAG(ARMED);
|
||||
|
||||
max7456_init(masterConfig.osdProfile.video_system);
|
||||
max7456Init(masterConfig.osdProfile.video_system);
|
||||
|
||||
max7456_clear_screen();
|
||||
max7456ClearScreen();
|
||||
|
||||
// display logo and help
|
||||
x = 160;
|
||||
for (int i = 1; i < 5; i++) {
|
||||
for (int j = 3; j < 27; j++) {
|
||||
if (x != 255)
|
||||
max7456_write_char(j, i, x++);
|
||||
max7456WriteChar(j, i, x++);
|
||||
}
|
||||
}
|
||||
|
||||
sprintf(string_buffer, "BF VERSION: %s", FC_VERSION_STRING);
|
||||
max7456_write(5, 6, string_buffer);
|
||||
max7456_write(7, 7, "MENU: THRT MID");
|
||||
max7456_write(13, 8, "YAW RIGHT");
|
||||
max7456_write(13, 9, "PITCH UP");
|
||||
max7456_refresh_all();
|
||||
max7456Write(5, 6, string_buffer);
|
||||
max7456Write(7, 7, "MENU: THRT MID");
|
||||
max7456Write(13, 8, "YAW RIGHT");
|
||||
max7456Write(13, 9, "PITCH UP");
|
||||
max7456RefreshAll();
|
||||
|
||||
refreshTimeout = 4 * REFRESH_1S;
|
||||
}
|
||||
|
@ -720,7 +720,7 @@ uint8_t osdHandleKey(uint8_t key)
|
|||
else {
|
||||
if (nextPage) // we have more pages
|
||||
{
|
||||
max7456_clear_screen();
|
||||
max7456ClearScreen();
|
||||
p = nextPage;
|
||||
nextPage = currentMenu;
|
||||
currentMenu = (OSD_Entry *)p;
|
||||
|
@ -739,7 +739,7 @@ uint8_t osdHandleKey(uint8_t key)
|
|||
|
||||
if (currentMenuPos == -1 || (currentMenu + currentMenuPos)->type == OME_Label) {
|
||||
if (nextPage) {
|
||||
max7456_clear_screen();
|
||||
max7456ClearScreen();
|
||||
p = nextPage;
|
||||
nextPage = currentMenu;
|
||||
currentMenu = (OSD_Entry *)p;
|
||||
|
@ -911,7 +911,7 @@ void osdMenuBack(void)
|
|||
memcpy(&masterConfig.profile[masterConfig.current_profile_index].controlRateProfile[masterConfig.profile[masterConfig.current_profile_index].activeRateProfile], &rateProfile, sizeof(controlRateConfig_t));
|
||||
|
||||
if (menuStackIdx) {
|
||||
max7456_clear_screen();
|
||||
max7456ClearScreen();
|
||||
menuStackIdx--;
|
||||
nextPage = NULL;
|
||||
currentMenu = menuStack[menuStackIdx];
|
||||
|
@ -963,10 +963,10 @@ void osdDrawMenu(void)
|
|||
|
||||
for (p = currentMenu; p->type != OME_END; p++) {
|
||||
if (currentMenuPos == i)
|
||||
max7456_write(LEFT_MENU_COLUMN, i + top, " >");
|
||||
max7456Write(LEFT_MENU_COLUMN, i + top, " >");
|
||||
else
|
||||
max7456_write(LEFT_MENU_COLUMN, i + top, " ");
|
||||
max7456_write(LEFT_MENU_COLUMN + 2, i + top, p->text);
|
||||
max7456Write(LEFT_MENU_COLUMN, i + top, " ");
|
||||
max7456Write(LEFT_MENU_COLUMN + 2, i + top, p->text);
|
||||
|
||||
switch (p->type) {
|
||||
case OME_POS: {
|
||||
|
@ -978,19 +978,19 @@ void osdDrawMenu(void)
|
|||
break;
|
||||
}
|
||||
case OME_Submenu:
|
||||
max7456_write(RIGHT_MENU_COLUMN, i + top, ">");
|
||||
max7456Write(RIGHT_MENU_COLUMN, i + top, ">");
|
||||
break;
|
||||
case OME_Bool:
|
||||
if (p->data) {
|
||||
if (*((uint8_t *)(p->data)))
|
||||
max7456_write(RIGHT_MENU_COLUMN, i + top, "YES");
|
||||
max7456Write(RIGHT_MENU_COLUMN, i + top, "YES");
|
||||
else
|
||||
max7456_write(RIGHT_MENU_COLUMN, i + top, "NO ");
|
||||
max7456Write(RIGHT_MENU_COLUMN, i + top, "NO ");
|
||||
}
|
||||
break;
|
||||
case OME_TAB: {
|
||||
OSD_TAB_t *ptr = p->data;
|
||||
max7456_write(RIGHT_MENU_COLUMN - 5, i + top, (char *)ptr->names[*ptr->val]);
|
||||
max7456Write(RIGHT_MENU_COLUMN - 5, i + top, (char *)ptr->names[*ptr->val]);
|
||||
break;
|
||||
}
|
||||
case OME_VISIBLE:
|
||||
|
@ -1001,49 +1001,49 @@ void osdDrawMenu(void)
|
|||
val = (uint16_t *)address;
|
||||
|
||||
if (VISIBLE(*val))
|
||||
max7456_write(RIGHT_MENU_COLUMN, i + top, "YES");
|
||||
max7456Write(RIGHT_MENU_COLUMN, i + top, "YES");
|
||||
else
|
||||
max7456_write(RIGHT_MENU_COLUMN, i + top, "NO ");
|
||||
max7456Write(RIGHT_MENU_COLUMN, i + top, "NO ");
|
||||
}
|
||||
break;
|
||||
case OME_UINT8:
|
||||
if (p->data) {
|
||||
OSD_UINT8_t *ptr = p->data;
|
||||
itoa(*ptr->val, buff, 10);
|
||||
max7456_write(RIGHT_MENU_COLUMN, i + top, " ");
|
||||
max7456_write(RIGHT_MENU_COLUMN, i + top, buff);
|
||||
max7456Write(RIGHT_MENU_COLUMN, i + top, " ");
|
||||
max7456Write(RIGHT_MENU_COLUMN, i + top, buff);
|
||||
}
|
||||
break;
|
||||
case OME_INT8:
|
||||
if (p->data) {
|
||||
OSD_INT8_t *ptr = p->data;
|
||||
itoa(*ptr->val, buff, 10);
|
||||
max7456_write(RIGHT_MENU_COLUMN, i + top, " ");
|
||||
max7456_write(RIGHT_MENU_COLUMN, i + top, buff);
|
||||
max7456Write(RIGHT_MENU_COLUMN, i + top, " ");
|
||||
max7456Write(RIGHT_MENU_COLUMN, i + top, buff);
|
||||
}
|
||||
break;
|
||||
case OME_UINT16:
|
||||
if (p->data) {
|
||||
OSD_UINT16_t *ptr = p->data;
|
||||
itoa(*ptr->val, buff, 10);
|
||||
max7456_write(RIGHT_MENU_COLUMN, i + top, " ");
|
||||
max7456_write(RIGHT_MENU_COLUMN, i + top, buff);
|
||||
max7456Write(RIGHT_MENU_COLUMN, i + top, " ");
|
||||
max7456Write(RIGHT_MENU_COLUMN, i + top, buff);
|
||||
}
|
||||
break;
|
||||
case OME_INT16:
|
||||
if (p->data) {
|
||||
OSD_UINT16_t *ptr = p->data;
|
||||
itoa(*ptr->val, buff, 10);
|
||||
max7456_write(RIGHT_MENU_COLUMN, i + top, " ");
|
||||
max7456_write(RIGHT_MENU_COLUMN, i + top, buff);
|
||||
max7456Write(RIGHT_MENU_COLUMN, i + top, " ");
|
||||
max7456Write(RIGHT_MENU_COLUMN, i + top, buff);
|
||||
}
|
||||
break;
|
||||
case OME_FLOAT:
|
||||
if (p->data) {
|
||||
OSD_FLOAT_t *ptr = p->data;
|
||||
simple_ftoa(*ptr->val * ptr->multipler, buff);
|
||||
max7456_write(RIGHT_MENU_COLUMN - 1, i + top, " ");
|
||||
max7456_write(RIGHT_MENU_COLUMN - 1, i + top, buff);
|
||||
max7456Write(RIGHT_MENU_COLUMN - 1, i + top, " ");
|
||||
max7456Write(RIGHT_MENU_COLUMN - 1, i + top, buff);
|
||||
}
|
||||
break;
|
||||
case OME_OSD_Exit:
|
||||
|
@ -1097,34 +1097,34 @@ void osdShowStats(void)
|
|||
uint8_t top = 2;
|
||||
char buff[10];
|
||||
|
||||
max7456_clear_screen();
|
||||
max7456_write(2, top++, " --- STATS ---");
|
||||
max7456ClearScreen();
|
||||
max7456Write(2, top++, " --- STATS ---");
|
||||
|
||||
if (STATE(GPS_FIX)) {
|
||||
max7456_write(2, top, "MAX SPEED :");
|
||||
max7456Write(2, top, "MAX SPEED :");
|
||||
itoa(stats.max_speed, buff, 10);
|
||||
max7456_write(22, top++, buff);
|
||||
max7456Write(22, top++, buff);
|
||||
}
|
||||
|
||||
max7456_write(2, top, "MIN BATTERY :");
|
||||
max7456Write(2, top, "MIN BATTERY :");
|
||||
sprintf(buff, "%d.%1dV", stats.min_voltage / 10, stats.min_voltage % 10);
|
||||
max7456_write(22, top++, buff);
|
||||
max7456Write(22, top++, buff);
|
||||
|
||||
max7456_write(2, top, "MIN RSSI :");
|
||||
max7456Write(2, top, "MIN RSSI :");
|
||||
itoa(stats.min_rssi, buff, 10);
|
||||
strcat(buff, "%");
|
||||
max7456_write(22, top++, buff);
|
||||
max7456Write(22, top++, buff);
|
||||
|
||||
if (feature(FEATURE_CURRENT_METER)) {
|
||||
max7456_write(2, top, "MAX CURRENT :");
|
||||
max7456Write(2, top, "MAX CURRENT :");
|
||||
itoa(stats.max_current, buff, 10);
|
||||
strcat(buff, "A");
|
||||
max7456_write(22, top++, buff);
|
||||
max7456Write(22, top++, buff);
|
||||
|
||||
max7456_write(2, top, "USED MAH :");
|
||||
max7456Write(2, top, "USED MAH :");
|
||||
itoa(mAhDrawn, buff, 10);
|
||||
strcat(buff, "\x07");
|
||||
max7456_write(22, top++, buff);
|
||||
max7456Write(22, top++, buff);
|
||||
}
|
||||
refreshTimeout = 60 * REFRESH_1S;
|
||||
}
|
||||
|
@ -1132,8 +1132,8 @@ void osdShowStats(void)
|
|||
// called when motors armed
|
||||
void osdArmMotors(void)
|
||||
{
|
||||
max7456_clear_screen();
|
||||
max7456_write(12, 7, "ARMED");
|
||||
max7456ClearScreen();
|
||||
max7456Write(12, 7, "ARMED");
|
||||
refreshTimeout = REFRESH_1S / 2;
|
||||
osdResetStats();
|
||||
}
|
||||
|
@ -1151,7 +1151,7 @@ void updateOsd(void)
|
|||
if (counter++ % 5 == 0)
|
||||
osdUpdate(0);
|
||||
else // rest of time redraw screen 10 chars per idle to don't lock the main idle
|
||||
max7456_draw_screen();
|
||||
max7456DrawScreen();
|
||||
|
||||
// do not allow ARM if we are in menu
|
||||
if (inMenu)
|
||||
|
@ -1192,7 +1192,7 @@ void osdUpdate(uint8_t guiKey)
|
|||
refreshTimeout = 1;
|
||||
refreshTimeout--;
|
||||
if (!refreshTimeout)
|
||||
max7456_clear_screen();
|
||||
max7456ClearScreen();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1263,7 +1263,7 @@ void osdUpdate(uint8_t guiKey)
|
|||
|
||||
*currentElement &= 0xFC00;
|
||||
*currentElement |= OSD_POS(x, y);
|
||||
max7456_clear_screen();
|
||||
max7456ClearScreen();
|
||||
}
|
||||
}
|
||||
osdDrawElements();
|
||||
|
@ -1281,7 +1281,7 @@ void osdChangeScreen(void *ptr)
|
|||
{
|
||||
uint8_t i;
|
||||
if (ptr) {
|
||||
max7456_clear_screen();
|
||||
max7456ClearScreen();
|
||||
// hack - save profile to temp
|
||||
if (ptr == &menuPid[0]) {
|
||||
for (i = 0; i < 3; i++) {
|
||||
|
@ -1312,16 +1312,16 @@ void osdEraseFlash(void *ptr)
|
|||
{
|
||||
UNUSED(ptr);
|
||||
|
||||
max7456_clear_screen();
|
||||
max7456_write(5, 3, "ERASING FLASH...");
|
||||
max7456_refresh_all();
|
||||
max7456ClearScreen();
|
||||
max7456Write(5, 3, "ERASING FLASH...");
|
||||
max7456RefreshAll();
|
||||
|
||||
flashfsEraseCompletely();
|
||||
while (!flashfsIsReady()) {
|
||||
delay(100);
|
||||
}
|
||||
max7456_clear_screen();
|
||||
max7456_refresh_all();
|
||||
max7456ClearScreen();
|
||||
max7456RefreshAll();
|
||||
}
|
||||
#endif // USE_FLASHFS
|
||||
|
||||
|
@ -1337,14 +1337,14 @@ void osdEditElement(void *ptr)
|
|||
currentElement = (uint16_t *)address;
|
||||
|
||||
*currentElement |= BLINK_FLAG;
|
||||
max7456_clear_screen();
|
||||
max7456ClearScreen();
|
||||
}
|
||||
|
||||
void osdExitMenu(void *ptr)
|
||||
{
|
||||
max7456_clear_screen();
|
||||
max7456_write(5, 3, "RESTARTING IMU...");
|
||||
max7456_refresh_all();
|
||||
max7456ClearScreen();
|
||||
max7456Write(5, 3, "RESTARTING IMU...");
|
||||
max7456RefreshAll();
|
||||
stopMotors();
|
||||
stopPwmAllMotors();
|
||||
delay(200);
|
||||
|
@ -1403,10 +1403,10 @@ void osdOpenMenu(void)
|
|||
vtxChannel = masterConfig.vtxChannel % 8 + 1;
|
||||
#endif // USE_RTC6705
|
||||
|
||||
osdRows = max7456_get_rows_count();
|
||||
osdRows = max7456GetRowsCount();
|
||||
inMenu = true;
|
||||
refreshTimeout = 0;
|
||||
max7456_clear_screen();
|
||||
max7456ClearScreen();
|
||||
currentMenu = &menuMain[0];
|
||||
osdResetAlarms();
|
||||
osdChangeScreen(currentMenu);
|
||||
|
@ -1417,16 +1417,16 @@ void osdOpenMenu(void)
|
|||
|
||||
void osdDrawElementPositioningHelp(void)
|
||||
{
|
||||
max7456_write(OSD_X(OSD_cfg.item_pos[OSD_ARTIFICIAL_HORIZON]), OSD_Y(OSD_cfg.item_pos[OSD_ARTIFICIAL_HORIZON]), "--- HELP --- ");
|
||||
max7456_write(OSD_X(OSD_cfg.item_pos[OSD_ARTIFICIAL_HORIZON]), OSD_Y(OSD_cfg.item_pos[OSD_ARTIFICIAL_HORIZON]) + 1, "USE ROLL/PITCH");
|
||||
max7456_write(OSD_X(OSD_cfg.item_pos[OSD_ARTIFICIAL_HORIZON]), OSD_Y(OSD_cfg.item_pos[OSD_ARTIFICIAL_HORIZON]) + 2, "TO MOVE ELEM. ");
|
||||
max7456_write(OSD_X(OSD_cfg.item_pos[OSD_ARTIFICIAL_HORIZON]), OSD_Y(OSD_cfg.item_pos[OSD_ARTIFICIAL_HORIZON]) + 3, " ");
|
||||
max7456_write(OSD_X(OSD_cfg.item_pos[OSD_ARTIFICIAL_HORIZON]), OSD_Y(OSD_cfg.item_pos[OSD_ARTIFICIAL_HORIZON]) + 4, "YAW - EXIT ");
|
||||
max7456Write(OSD_X(OSD_cfg.item_pos[OSD_ARTIFICIAL_HORIZON]), OSD_Y(OSD_cfg.item_pos[OSD_ARTIFICIAL_HORIZON]), "--- HELP --- ");
|
||||
max7456Write(OSD_X(OSD_cfg.item_pos[OSD_ARTIFICIAL_HORIZON]), OSD_Y(OSD_cfg.item_pos[OSD_ARTIFICIAL_HORIZON]) + 1, "USE ROLL/PITCH");
|
||||
max7456Write(OSD_X(OSD_cfg.item_pos[OSD_ARTIFICIAL_HORIZON]), OSD_Y(OSD_cfg.item_pos[OSD_ARTIFICIAL_HORIZON]) + 2, "TO MOVE ELEM. ");
|
||||
max7456Write(OSD_X(OSD_cfg.item_pos[OSD_ARTIFICIAL_HORIZON]), OSD_Y(OSD_cfg.item_pos[OSD_ARTIFICIAL_HORIZON]) + 3, " ");
|
||||
max7456Write(OSD_X(OSD_cfg.item_pos[OSD_ARTIFICIAL_HORIZON]), OSD_Y(OSD_cfg.item_pos[OSD_ARTIFICIAL_HORIZON]) + 4, "YAW - EXIT ");
|
||||
}
|
||||
|
||||
void osdDrawElements(void)
|
||||
{
|
||||
max7456_clear_screen();
|
||||
max7456ClearScreen();
|
||||
|
||||
if (currentElement)
|
||||
osdDrawElementPositioningHelp();
|
||||
|
@ -1562,7 +1562,7 @@ void osdDrawSingleElement(uint8_t item)
|
|||
else if (FLIGHT_MODE(HORIZON_MODE))
|
||||
p = "HOR";
|
||||
|
||||
max7456_write(elemPosX, elemPosY, p);
|
||||
max7456Write(elemPosX, elemPosY, p);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1599,7 +1599,7 @@ void osdDrawSingleElement(uint8_t item)
|
|||
|
||||
case OSD_ARTIFICIAL_HORIZON:
|
||||
{
|
||||
uint8_t *screenBuffer = max7456_get_screen_buffer();
|
||||
uint8_t *screenBuffer = max7456GetScreenBuffer();
|
||||
uint16_t position = 194;
|
||||
|
||||
int rollAngle = attitude.values.roll;
|
||||
|
@ -1640,7 +1640,7 @@ void osdDrawSingleElement(uint8_t item)
|
|||
|
||||
case OSD_HORIZON_SIDEBARS:
|
||||
{
|
||||
uint8_t *screenBuffer = max7456_get_screen_buffer();
|
||||
uint8_t *screenBuffer = max7456GetScreenBuffer();
|
||||
uint16_t position = 194;
|
||||
|
||||
if (maxScreenSize == VIDEO_BUFFER_CHARS_PAL)
|
||||
|
@ -1665,5 +1665,5 @@ void osdDrawSingleElement(uint8_t item)
|
|||
return;
|
||||
}
|
||||
|
||||
max7456_write(elemPosX, elemPosY, buff);
|
||||
max7456Write(elemPosX, elemPosY, buff);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue