Some minor improvements and probably the last ones. (#2602)

* removed "MAX7456_SLAVE_IDX" redefined warnings

 changed <define name="MAX7456_SPI_DEV" value="spi2" /> AND  <define name="MAX7456_SLAVE_IDX" value="SPI_SLAVE1" />
to  <configure name="MAX7456_SPI_DEV" value="spi2" /> AND  <configure name="MAX7456_SLAVE_IDX" value="SPI_SLAVE1" />
otherwise i was getting to many warnings about "MAX7456_SLAVE_IDX" redefined

* improved osd busy flag checks

Removed one static function and the code now checks both the OSD busy flag and the OSD Reset flag.

* Added THE OSD status register bits

Added two more definitions about the OSD busy flag and the OSD reset flag.

* Made the busy flag check a litle more strict.

Removed one static function and the code now checks both the OSD busy flag and the OSD Reset flag.

* Changed the busy flag check

Removed one static function and the code now checks both the OSD busy flag and the OSD Reset flag always after writing to the OSD
The code is also a bit cleaner.

* changed the OSD STATUS register bit positions 

I changed the OSD status register bit positions and names to better blend with the rest of the file.
They weren't used anywhere else except for the busy flag checks.

* STATUS register bit position names and style change

I changed the OSD status register bit positions and names to better blend with the rest of the file and to look better to the eye.
Those and the older ones are only used to check the busy flag.

* Made the BUSY flag check more robust.

The busy flag (actually the NVRAM Busy FLAG) and the Power On Reset flag now is checked every time the code writes something to NVRAM.

* Delete max7456.c
This commit is contained in:
hendrixgr
2020-10-15 23:42:13 +03:00
committed by GitHub
parent 8b56049d21
commit dbff73a054
3 changed files with 63 additions and 114 deletions
+2 -2
View File
@@ -25,8 +25,8 @@
<configure name="BMP280_I2C_DEV" value="i2c1" />
<configure name="BMP280_SLAVE_ADDR" value="BMP280_I2C_ADDR" />
<!-- OSD CONFIGURATION -->
<define name="MAX7456_SPI_DEV" value="spi2" />
<define name="MAX7456_SLAVE_IDX" value="SPI_SLAVE1" />
<configure name="MAX7456_SPI_DEV" value="spi2" />
<configure name="MAX7456_SLAVE_IDX" value="SPI_SLAVE1" />
<define name="USE_MATEK_TYPE_OSD_CHIP" value="1" />
<define name="USE_PAL_FOR_OSD_VIDEO" value="1" />
<define name="OSD_USE_BARO_ALTITUDE" value="0" />
+32 -85
View File
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2013 Chris
* Copyright (C) 2013-2020 Chris Efstathiou hendrixgr@gmail.com
*
* This file is part of paparazzi.
*
@@ -70,7 +70,6 @@ typedef struct {
static void vSubtractVectors(VECTOR *svA, VECTOR svB, VECTOR svC);
static void vMultiplyMatrixByVector(VECTOR *svA, MATRIX smB, VECTOR svC);
static void check_osd_status(void);
static float home_direction(void);
static char ascii_to_osd_c(char c);
static void osd_put_s(char *string, uint8_t attributes, uint8_t char_nb, uint8_t row, uint8_t column);
@@ -114,7 +113,6 @@ uint8_t max7456_osd_status = OSD_UNINIT;
uint8_t osd_enable = true;
uint8_t osd_enable_val = OSD_IMAGE_ENABLE;
uint8_t osd_stat_reg = 0;
bool osd_stat_reg_valid = false;
float home_dir = 0;
@@ -196,10 +194,9 @@ static float home_direction(void)
*
* WHEN home_dir = (float)(atan2(Home_PositionForPlane2.fy, (Home_PositionForPlane2.fx)));
*
* plane front
*
* plane front
* 0˚
^
* ^
* I
* -45˚ I 45˚
* \ I /
@@ -207,7 +204,7 @@ static float home_direction(void)
* -90˚-------I------- 90˚
* /I\
* / I \
* -135˚ I 120˚
* -135˚ I 135˚
* I
* 180
* plane back
@@ -215,33 +212,6 @@ static float home_direction(void)
*
*/
/*
* WHEN home_dir = (float)(atan2(Home_PositionForPlane2.fx, (Home_PositionForPlane2.fy)));
*
*
* plane front
*
* 90˚
^
* I
* 135˚ I 45˚
* \ I /
* \I/
* 180˚-------I------- 0˚
* /I\
* / I \
* -135˚ I -45˚
* I
* -90
* plane back
*
*
*/
/* fPan = 0˚ -> antenna looks along the wing
90˚ -> antenna looks in flight direction
-90˚ -> antenna looks backwards
*/
/* fixed to the plane*/
home_dir = (float)(atan2(Home_PositionForPlane2.fy, (Home_PositionForPlane2.fx)));
home_dir = DegOfRad(home_dir);
@@ -250,28 +220,12 @@ static float home_direction(void)
return (home_dir);
}
static void check_osd_status(void)
{
osd_stat_reg_valid = FALSE;
if (max7456_osd_status == OSD_IDLE) {
max7456_trans.output_length = 1;
max7456_trans.input_length = 1;
max7456_trans.output_buf[0] = OSD_STAT_REG;
max7456_osd_status = OSD_READ_STATUS;
spi_submit(&(MAX7456_SPI_DEV), &max7456_trans);
}
return;
}
static char ascii_to_osd_c(char c)
{
#if defined USE_MATEK_TYPE_OSD_CHIP && USE_MATEK_TYPE_OSD_CHIP == 1
PRINT_CONFIG_MSG("OSD USES THE CUSTOM MATEK TYPE OSD CHIP")
PRINT_CONFIG_MSG("OSD USES THE CUSTOM MATEK TYPE OSD CHIP")
return (c);
#else
@@ -292,7 +246,6 @@ PRINT_CONFIG_MSG("OSD USES THE CUSTOM MATEK TYPE OSD CHIP")
case (';'): c = 0x43; break;
case (':'): c = 0x44; break;
case (','): c = 0x45; break;
//case('''): c = 0x46; break;
case ('/'): c = 0x47; break;
case ('"'): c = 0x48; break;
case ('-'): c = 0x49; break;
@@ -580,11 +533,11 @@ void max7456_periodic(void)
break;
case (30):
#if OSD_USE_MAG_COMPASS && !defined(SITL)
PRINT_CONFIG_MSG("OSD USES THE MAGNETIC HEADING")
temp = DegOfRad(MAG_Heading);
PRINT_CONFIG_MSG("OSD USES THE MAGNETIC HEADING")
temp = DegOfRad(MAG_Heading);
if (temp < 0) { temp += 360; }
#else
PRINT_CONFIG_MSG("OSD USES THE GPS HEADING")
PRINT_CONFIG_MSG("OSD USES THE GPS HEADING")
temp = DegOfRad(state.h_speed_dir_f);
if (temp < 0) { temp += 360; }
#endif
@@ -608,15 +561,15 @@ PRINT_CONFIG_MSG("OSD USES THE GPS HEADING")
break;
case (50):
#if OSD_USE_BARO_ALTITUDE && !defined(SITL)
PRINT_CONFIG_MSG("OSD ALTITUDE IS COMING FROM BAROMETER")
PRINT_CONFIG_MSG("OSD ALTITUDE IS COMING FROM BAROMETER")
#if defined BARO_ALTITUDE_VAR
osd_sprintf(osd_string, "%.0fM", BARO_ALTITUDE_VAR);
#else
PRINT_CONFIG_MSG("OSD USES THE DEFAULT BARO ALTITUDE VARIABLE")
PRINT_CONFIG_MSG("OSD USES THE DEFAULT BARO ALTITUDE VARIABLE")
osd_sprintf(osd_string, "%.0fM", baro_alt);
#endif
#else
PRINT_CONFIG_MSG("ALTITUDE IS COMING FROM GPS")
PRINT_CONFIG_MSG("ALTITUDE IS COMING FROM GPS")
osd_sprintf(osd_string, "%.0fM", GetPosAlt());
#endif
osd_put_s(osd_string, L_JUST, 6, 14, 1); // "FALSE = L_JUST
@@ -687,14 +640,8 @@ PRINT_CONFIG_MSG("ALTITUDE IS COMING FROM GPS")
osd_put_s(osd_string, R_JUST, 5, 8, 13);
} else { osd_put_s(" ", R_JUST, 5, 8, 13); }
step = 120;
break;
case (120):
check_osd_status();
step = 10;
break;
default: step = 10; break;
} // End of switch statement.
} // End of if (max7456_osd_status == OSD_UNINIT)
@@ -731,13 +678,6 @@ void max7456_event(void)
max7456_osd_status = OSD_FINISHED;
spi_submit(&(MAX7456_SPI_DEV), &max7456_trans);
break;
/*
case (OSD_READ_STATUS):
osd_stat_reg = max7456_trans.input_buf[0];
osd_stat_reg_valid = true;
max7456_osd_status = OSD_FINISHED;
break;
*/
case (OSD_S_STEP1):
max7456_trans.output_length = 2;
max7456_trans.output_buf[0] = OSD_DMAL_REG;
@@ -764,23 +704,30 @@ void max7456_event(void)
spi_submit(&(MAX7456_SPI_DEV), &max7456_trans);
}
break;
case (OSD_READ_STATUS):
osd_stat_reg = max7456_trans.input_buf[0];
osd_stat_reg_valid = TRUE;
max7456_trans.status = SPITransDone;
max7456_osd_status = OSD_IDLE;
break;
case (OSD_FINISHED):
osd_attr = 0;
max7456_trans.status = SPITransDone;
max7456_osd_status = OSD_IDLE;
max7456_trans.output_length = 1;
max7456_trans.input_length = 2;
max7456_trans.output_buf[0] = OSD_STAT_REG;
max7456_osd_status = OSD_READ_STATUS;
spi_submit(&(MAX7456_SPI_DEV), &max7456_trans);
break;
case (OSD_READ_STATUS):
osd_stat_reg = max7456_trans.input_buf[1];
if (osd_stat_reg & (OSD_NVRAM_BUSY_FLAG | OSD_RESET_BUSY_FLAG)) {
max7456_trans.output_length = 1;
max7456_trans.input_length = 2;
max7456_trans.output_buf[0] = OSD_STAT_REG;
max7456_osd_status = OSD_READ_STATUS;
spi_submit(&(MAX7456_SPI_DEV), &max7456_trans);
} else {
osd_attr = 0;
max7456_trans.status = SPITransDone;
max7456_osd_status = OSD_IDLE;
}
break;
default: break;
}
}
return;
}
+29 -27
View File
@@ -31,29 +31,39 @@
#define MAX7456_REGS_H
//OSD REGISTER ADDRESSES
#define OSD_VM0_REG 0x00
#define OSD_VM1_REG 0x01
#define OSD_DMM_REG 0x04
#define OSD_DMAH_REG 0x05
#define OSD_DMAL_REG 0x06
#define OSD_DMDI_REG 0x07
#define OSD_OSDBL_REG 0x6C
#define OSD_OSDBL_REG_R 0xEC
#define OSD_STAT_REG 0xA0
#define OSD_VM0_REG 0x00
#define OSD_VM1_REG 0x01
#define OSD_DMM_REG 0x04
#define OSD_DMAH_REG 0x05
#define OSD_DMAL_REG 0x06
#define OSD_DMDI_REG 0x07
#define OSD_OSDBL_REG 0x6C
#define OSD_OSDBL_REG_R 0xEC
#define OSD_STAT_REG 0xA0
//OSD BIT POSITIONS
#define OSD_VIDEO_MODE_PAL (1<<6) // Default = NTSC
#define OSD_SYNC_INTERNAL ((1<<5)|(1<<4)) // Default = AUTO
#define OSD_SYNC_EXTERNAL ((1<<5) // Default = AUTO
#define OSD_IMAGE_ENABLE (1<<3) // Default = OSD OFF
#define OSD_VIDEO_MODE_PAL (1<<6) // Default = NTSC
#define OSD_SYNC_INTERNAL ((1<<5)|(1<<4)) // Default = AUTO
#define OSD_SYNC_EXTERNAL ((1<<5) // Default = AUTO
#define OSD_IMAGE_ENABLE (1<<3) // Default = OSD OFF
#define OSD_REFRESH_ON_NEXT_VSYNC (1<<2) // Default = immediately refresh video
#define OSD_RESET (1<<1) // VM0 reg, hardware set to 0 after reset
#define OSD_VOUT_DISABLE (1<<0) // default= VIDEO OUT ENABLED
#define OSD_8BIT_MODE (1<<6) // default= 16 BIT MODE
#define OSD_BLINK_CHAR (1<<4) // default= No BLINKING
#define OSD_INVERT_PIXELS (1<<3) // default= No INVERSION
#define OSD_RESET (1<<1) // VM0 reg, hardware set to 0 after reset
#define OSD_VOUT_DISABLE (1<<0) // default= VIDEO OUT ENABLED
#define OSD_8BIT_MODE (1<<6) // default= 16 BIT MODE
#define OSD_BLINK_CHAR (1<<4) // default= No BLINKING
#define OSD_INVERT_PIXELS (1<<3) // default= No INVERSION
#define OSD_CLEAR_DISPLAY_MEMORY (1<<2) // DMM reg, default = 0
#define OSD_AUTO_INCREMENT_MODE (1<<0) // default = NO AUTO INCREMENT
#define OSD_AUTO_INCREMENT_MODE (1<<0) // default = NO AUTO INCREMENT
//OSD STATUS REGISTER BIT POSITIONS
#define OSD_UNUSED_FLAG (1<<7) // It is not used.
#define OSD_RESET_BUSY_FLAG (1<<6) // 0=power on reset completed, 1=busy with reset.
#define OSD_NVRAM_BUSY_FLAG (1<<5) // 0=memory available, 1=memory busy
#define OSD_VSYNC_ABSENT_FLAG (1<<4) // 0=vertical sync active, 1= no vsync
#define OSD_HSYNC_ABSENT_FLAG (1<<3) // 0=Horizontal sync active, 1= no Hsync
#define OSD_LOS_ABSENT_FLAG (1<<2) // 0=sync active, 1= no sync
#define OSD_NTSC_PRESENT_FLAG (1<<1) // 0=No NTSC signal detected, 1=NTSC signal detected.
#define OSD_PAL_PRESENT_FLAG (1<<0) // 0=No PAL signal detected, 1=PAL signal detected.
// MAX7456 VIDEO_MODE_0 register
#define VIDEO_MODE_0_WRITE 0x00
@@ -120,14 +130,6 @@
// MAX7456 FM_DATA_OUT register
#define FM_DATA_OUT_READ 0xC0
// MAX7456 STATUS register
#define STATUS_READ 0xA0
#define STATUS_40_RESET_BUSY 0x40
#define STATUS_20_NVRAM_BUSY 0x20
#define STATUS_04_LOSS_OF_SYNC 0x04
#define STATUS_02_PAL_DETECTED 0x02
#define STATUS_01_NTSC_DETECTED 0x01
// MAX7456 requires clearing OSD Black Level register bit 0x10 after reset
#define OSDBL_WR 0x6C
#define OSDBL_RD 0xEC