From b388ef6fdc40adef85288ffe6f498ce5c495e50f Mon Sep 17 00:00:00 2001 From: "ionsurdu@github.com" Date: Tue, 13 Aug 2024 14:49:51 +0300 Subject: [PATCH] minor cleanup and optimizations --- include/DFRobot_OSD.h | 340 ++++++++++++++++++++---------------------- src/DFRobot_OSD.cpp | 6 +- src/main.cpp | 22 +-- 3 files changed, 176 insertions(+), 192 deletions(-) diff --git a/include/DFRobot_OSD.h b/include/DFRobot_OSD.h index 4b07007..8c7720f 100644 --- a/include/DFRobot_OSD.h +++ b/include/DFRobot_OSD.h @@ -15,101 +15,111 @@ #include - // #define ENABLE_DBG //!< Open this macro and you can see the details of the program #ifdef ENABLE_DBG - #define DBG(...) {Serial.print("[");Serial.print(__FUNCTION__); Serial.print("(): "); Serial.print(__LINE__); Serial.print(" ] "); Serial.println(__VA_ARGS__);} +#define DBG(...) \ + { \ + Serial.print("["); \ + Serial.print(__FUNCTION__); \ + Serial.print("(): "); \ + Serial.print(__LINE__); \ + Serial.print(" ] "); \ + Serial.println(__VA_ARGS__); \ + } #else - #define DBG(...) +#define DBG(...) #endif - /* at7456 */ -#define VM0 0x00 ///< Video Mode0 -#define VM1 0x01 ///< Video Mode1 -#define HOS 0x02 ///< Horizontal Offset -#define VOS 0x03 ///< Vertical Offset -#define DMM 0x04 ///< Display Memory Mode -#define DMAH 0x05 ///< Display Memory Address High -#define DMAL 0x06 ///< Display Memory Address Low -#define DMDI 0x07 ///< Display Memory Data In -#define CMM 0x08 ///< Character Memory Mode -#define CMAH 0x09 ///< Character Memory Address High -#define CMAL 0x0a ///< Character Memory Address Low -#define CMDI 0x0b ///< Character Memory Data In -#define OSDM 0x0c ///< OSD Insertion Mux -#define RB0 0x10 ///< Row 0 Brightness -#define RB1 0x11 ///< Row 1 Brightness -#define RB2 0x12 ///< Row 2 Brightness -#define RB3 0x13 ///< Row 3 Brightness -#define RB4 0x14 ///< Row 4 Brightness -#define RB5 0x15 ///< Row 5 Brightness -#define RB6 0x16 ///< Row 6 Brightness -#define RB7 0x17 ///< Row 7 Brightness -#define RB8 0x18 ///< Row 8 Brightness -#define RB9 0x19 ///< Row 9 Brightness -#define RB10 0x1a ///< Row 10 Brightness -#define RB11 0x1b ///< Row 11 Brightness -#define RB12 0x1c ///< Row 12 Brightness -#define RB13 0x1d ///< Row 13 Brightness -#define RB14 0x1e ///< Row 14 Brightness -#define RB15 0x1f ///< Row 15 Brightness -#define OSDBL 0x6c ///< OSD Black Level -#define STAT 0x20 ///< Status -#define DMDO 0x30 ///< Display Memory Data Out -#define CMDO 0x40 ///< Character Memory Data Out -#define NVM_RAM 0x50 ///< Read the fonts in the NVM into the mirror RAM -#define RAM_NVM 0xa0 ///< Write the database data in the mirror RAM to the NVM +#define VM0 0x00 ///< Video Mode0 +#define VM1 0x01 ///< Video Mode1 +#define HOS 0x02 ///< Horizontal Offset +#define VOS 0x03 ///< Vertical Offset +#define DMM 0x04 ///< Display Memory Mode +#define DMAH 0x05 ///< Display Memory Address High +#define DMAL 0x06 ///< Display Memory Address Low +#define DMDI 0x07 ///< Display Memory Data In +#define CMM 0x08 ///< Character Memory Mode +#define CMAH 0x09 ///< Character Memory Address High +#define CMAL 0x0a ///< Character Memory Address Low +#define CMDI 0x0b ///< Character Memory Data In +#define OSDM 0x0c ///< OSD Insertion Mux +#define RB0 0x10 ///< Row 0 Brightness +#define RB1 0x11 ///< Row 1 Brightness +#define RB2 0x12 ///< Row 2 Brightness +#define RB3 0x13 ///< Row 3 Brightness +#define RB4 0x14 ///< Row 4 Brightness +#define RB5 0x15 ///< Row 5 Brightness +#define RB6 0x16 ///< Row 6 Brightness +#define RB7 0x17 ///< Row 7 Brightness +#define RB8 0x18 ///< Row 8 Brightness +#define RB9 0x19 ///< Row 9 Brightness +#define RB10 0x1a ///< Row 10 Brightness +#define RB11 0x1b ///< Row 11 Brightness +#define RB12 0x1c ///< Row 12 Brightness +#define RB13 0x1d ///< Row 13 Brightness +#define RB14 0x1e ///< Row 14 Brightness +#define RB15 0x1f ///< Row 15 Brightness +#define OSDBL 0x6c ///< OSD Black Level +#define STAT 0x20 ///< Status +#define DMDO 0x30 ///< Display Memory Data Out +#define CMDO 0x40 ///< Character Memory Data Out +#define NVM_RAM 0x50 ///< Read the fonts in the NVM into the mirror RAM +#define RAM_NVM 0xa0 ///< Write the database data in the mirror RAM to the NVM /* VM0 */ -#define NTSC (0 << 6) ///< D6 --- Vidoe Standard Select -#define PAL (1 << 6) -#define SYNC_AUTO (0 << 4) ///< D5,D4 --- Sync Select Mode -#define SYNC_EXTERNAL (2 << 4) -#define SYNC_INTERNAL (3 << 4) -#define OSD_ENABLE (1 << 3) ///< D3 --- Enable Display of OSD image -#define OSD_DISABLE (0 << 3) -#define SOFT_RESET (1 << 1) ///< D1 --- Software Reset -#define VOUT_ENABLE (0 << 0) -#define VOUT_DISABLE (1 << 0) +#define NTSC (0 << 6) ///< D6 --- Vidoe Standard Select +#define PAL (1 << 6) +#define SYNC_AUTO (0 << 4) ///< D5,D4 --- Sync Select Mode +#define SYNC_EXTERNAL (2 << 4) +#define SYNC_INTERNAL (3 << 4) +#define OSD_ENABLE (1 << 3) ///< D3 --- Enable Display of OSD image +#define OSD_DISABLE (0 << 3) +#define SOFT_RESET (1 << 1) ///< D1 --- Software Reset +#define VOUT_ENABLE (0 << 0) +#define VOUT_DISABLE (1 << 0) /* VM1 */ -#define BACKGND_0 (0 << 4) ///< Background level WHT% -#define BACKGND_7 (1 << 4) -#define BACKGND_14 (2 << 4) -#define BACKGND_21 (3 << 4) -#define BACKGND_28 (4 << 4) -#define BACKGND_35 (5 << 4) -#define BACKGND_42 (6 << 4) -#define BACKGND_49 (7 << 4) -#define BLINK_TIME40 (0 << 2) ///< Blink cycle, ms -#define BLINK_TIME80 (1 << 2) -#define BLINK_TIME120 (2 << 2) -#define BLINK_TIME160 (3 << 2) ///< Scintillation ratio(ON : OFF) -#define BLINK_DUTY_1_1 0 ///< BT : BT -#define BLINK_DUTY_1_2 1 ///< BT : 2BT -#define BLINK_DUTY_1_3 2 ///< BT : 3BT -#define BLINK_DUTY_3_1 3 ///< 3BT : BT // DMM -#define SPI_BIT16 (0 << 6) ///< use 16bit When writing characters, and the character attribute is from the DMM[5:3] -#define SPI_BIT8 (1 << 6) ///< Write characters in 8bit, and character attributes are written separately -#define CHAR_LBC (1 << 5) ///< The local background -#define CHAR_BLK (1 << 4) ///< blinking display -#define CHAR_INV (1 << 3) ///< display negative image -#define CLEAR_SRAM (1 << 2) ///< clear,20us -#define VETICAL_SYNC (1 << 1) ///< The command is in sync with the action -#define AUTO_INC (1 << 0) ///< The character address automatically increases +#define BACKGND_0 (0 << 4) ///< Background level WHT% +#define BACKGND_7 (1 << 4) +#define BACKGND_14 (2 << 4) +#define BACKGND_21 (3 << 4) +#define BACKGND_28 (4 << 4) +#define BACKGND_35 (5 << 4) +#define BACKGND_42 (6 << 4) +#define BACKGND_49 (7 << 4) +#define BLINK_TIME40 (0 << 2) ///< Blink cycle, ms +#define BLINK_TIME80 (1 << 2) +#define BLINK_TIME120 (2 << 2) +#define BLINK_TIME160 (3 << 2) ///< Scintillation ratio(ON : OFF) +#define BLINK_DUTY_1_1 0 ///< BT : BT +#define BLINK_DUTY_1_2 1 ///< BT : 2BT +#define BLINK_DUTY_1_3 2 ///< BT : 3BT +#define BLINK_DUTY_3_1 3 ///< 3BT : BT // DMM +#define SPI_BIT16 \ + (0 << 6) ///< use 16bit When writing characters, and the character attribute is from + ///< the DMM[5:3] +#define SPI_BIT8 \ + (1 << 6) ///< Write characters in 8bit, and character attributes are written + ///< separately +#define CHAR_LBC (1 << 5) ///< The local background +#define CHAR_BLK (1 << 4) ///< blinking display +#define CHAR_INV (1 << 3) ///< display negative image +#define CLEAR_SRAM (1 << 2) ///< clear,20us +#define VETICAL_SYNC (1 << 1) ///< The command is in sync with the action +#define AUTO_INC (1 << 0) ///< The character address automatically increases /* RBi */ -#define BLACK_LEVEL_0 (0 << 2) ///< 0% white level -#define BLACK_LEVEL_10 (1 << 2) ///< 10% white level -#define BLACK_LEVEL_20 (2 << 2) ///< 20% white level -#define BLACK_LEVEL_30 (3 << 2) ///< 30% white level -#define WHITE_LEVEL_120 (0 << 0) ///< 120% white level -#define WHITE_LEVEL_100 (1 << 0) ///< 110% white level -#define WHITE_LEVEL_90 (2 << 0) ///< 90% white level -#define WHITE_LEVEL_80 (3 << 0) ///< 80% white level +#define BLACK_LEVEL_0 (0 << 2) ///< 0% white level +#define BLACK_LEVEL_10 (1 << 2) ///< 10% white level +#define BLACK_LEVEL_20 (2 << 2) ///< 20% white level +#define BLACK_LEVEL_30 (3 << 2) ///< 30% white level +#define WHITE_LEVEL_120 (0 << 0) ///< 120% white level +#define WHITE_LEVEL_100 (1 << 0) ///< 110% white level +#define WHITE_LEVEL_90 (2 << 0) ///< 90% white level +#define WHITE_LEVEL_80 (3 << 0) ///< 80% white level /* STAT */ -#define PAL_DETECT (1 << 0) ///< Check the PAL signal -#define NTSC_DETECT (1 << 1) ///< Check the NTSC signal -#define LOS_DETECT (1 << 2) ///< Check the LOS signal -#define VSYNC (1 << 4) ///< synchronous +#define PAL_DETECT (1 << 0) ///< Check the PAL signal +#define NTSC_DETECT (1 << 1) ///< Check the NTSC signal +#define LOS_DETECT (1 << 2) ///< Check the LOS signal +#define VSYNC (1 << 4) ///< synchronous /** * @struct AsciiAddr @@ -117,112 +127,84 @@ */ typedef struct { - char ascii; - short addr; -}AsciiAddr; + char ascii; + short addr; +} AsciiAddr; -const AsciiAddr tAsciiAddr[]={ - {' ',0x00}, - {'(',0x3f}, - {')',0x40}, - {'.',0x41}, - {'?',0x42}, - {';',0x43}, - {':',0x44}, - {',',0x45}, - {'\'',0x46}, - {'/',0x47}, - {'"',0x48}, - {'-',0x49}, - {'<',0x4a}, - {'>',0x4b}, - {'@',0x4c}, - {'!',0x121}, - {'#',0x123}, - {'$',0x124}, - {'%',0x125}, - {'&',0x126}, - {'(',0x128}, - {')',0x129}, - {'*',0x12a}, - {'+',0x12b}, - {'_',0x12d}, - {'=',0x13d}, - {'[',0x15b}, - {']',0x15d}, - {'^',0x15e}, - {'`',0x160}, - {'{',0x17b}, - {'|',0x17c}, - {'}',0x17d}, - {'~',0x17e}, +const AsciiAddr tAsciiAddr[] = { + {' ', 0x00}, {'(', 0x3f}, {')', 0x40}, {'.', 0x41}, {'?', 0x42}, {';', 0x43}, + {':', 0x44}, {',', 0x45}, {'\'', 0x46}, {'/', 0x47}, {'"', 0x48}, {'-', 0x49}, + {'<', 0x4a}, {'>', 0x4b}, {'@', 0x4c}, {'!', 0x121}, {'#', 0x123}, {'$', 0x124}, + {'%', 0x125}, {'&', 0x126}, {'(', 0x128}, {')', 0x129}, {'*', 0x12a}, {'+', 0x12b}, + {'_', 0x12d}, {'=', 0x13d}, {'[', 0x15b}, {']', 0x15d}, {'^', 0x15e}, {'`', 0x160}, + {'{', 0x17b}, {'|', 0x17c}, {'}', 0x17d}, {'~', 0x17e}, }; class DFRobot_OSD { -public: - /** - * @fn DFRobot_OSD - * @brief Constructor - * @param CS - CS selection pin - * @return None - */ - DFRobot_OSD(int CS); - ~DFRobot_OSD(); + public: + /** + * @fn DFRobot_OSD + * @brief Constructor + * @param CS - CS selection pin + * @return None + */ + DFRobot_OSD(int CS); + ~DFRobot_OSD(); - /** - * @fn init - * @brief Init function - * @return None - */ - void init(int a, int b, int c); + /** + * @fn init + * @brief Init function + * @return None + */ + void init(int a, int b, int c); - /** - * @fn displayChar - * @brief display char - * @param row - Horizontal coordinate, range(0,15) - * @param col - Vertical coordinate, range(0,29) - * @param value - addr of char in eeprom - * @return None - */ - void displayChar(unsigned char row, unsigned char col, unsigned short addr); + /** + * @fn displayChar + * @brief display char + * @param row - Horizontal coordinate, range(0,15) + * @param col - Vertical coordinate, range(0,29) + * @param value - addr of char in eeprom + * @return None + */ + void displayChar(unsigned char row, unsigned char col, unsigned short addr); - /** - * @fn displayChar - * @brief display string - * @param row - Horizontal coordinate, range(0,15) - * @param col - Vertical coordinate, range(0,29) - * @param s - String - * @return None - */ - void displayString(unsigned char row, unsigned char col, const char *s); - void displayString(unsigned char row, unsigned char col, String s); + /** + * @fn displayChar + * @brief display string + * @param row - Horizontal coordinate, range(0,15) + * @param col - Vertical coordinate, range(0,29) + * @param s - String + * @return None + */ + void displayString(unsigned char row, unsigned char col, const char *s); + void displayString(unsigned char row, unsigned char col, String s); - /** - * @fn clear - * @brief Clear screen - * @return None - */ - void clear(void); + /** + * @fn clear + * @brief Clear screen + * @return None + */ + void clear(void); - /** - * @fn storeChar - * @brief Write the custom character to the OSD, replacing the original character - * @param addr - Address of the stored character - * @param dt - Array generated through the tool - * @return None - */ - void storeChar(unsigned short addr,int dt[]); + /** + * @fn storeChar + * @brief Write the custom character to the OSD, replacing the original character + * @param addr - Address of the stored character + * @param dt - Array generated through the tool + * @return None + */ + void storeChar(unsigned short addr, const int dt[]); -private: - void writeAddrData(unsigned char addr, unsigned char dat); - void writeAT7456E(unsigned short addr, int *dt); - void writeData(unsigned char dat); - int * extend(int src); - int unified(int src); + private: + void writeAddrData(unsigned char addr, unsigned char dat); + void writeAT7456E(unsigned short addr, int *dt); + void writeData(unsigned char dat); + int *extend(int src); + int unified(int src); -private: - int nCS; + private: + int nCS; }; #endif diff --git a/src/DFRobot_OSD.cpp b/src/DFRobot_OSD.cpp index 66a1941..ccdc284 100644 --- a/src/DFRobot_OSD.cpp +++ b/src/DFRobot_OSD.cpp @@ -52,7 +52,7 @@ void DFRobot_OSD::displayChar(unsigned char row, unsigned char col, unsigned sho writeAddrData(DMM, 0x40); writeAddrData(DMAH, addrH | 0x2); writeAddrData(DMAL, k); - j = CHAR_LBC << 5; + j = CHAR_LBC; if ((addr >> 8) != 0) j |= 0x10; writeAddrData(DMDI, j); @@ -100,7 +100,7 @@ void DFRobot_OSD::displayString(unsigned char row, unsigned char col, const char writeAddrData(DMM, 0x40); writeAddrData(DMAH, addrH | 0x2); writeAddrData(DMAL, k); - j = CHAR_LBC << 5; + j = CHAR_LBC; if ((value >> 8) != 0) j |= 0x10; writeAddrData(DMDI, j); @@ -157,7 +157,7 @@ void DFRobot_OSD::writeAT7456E(unsigned short addr, int *dt) writeAddrData(VM0, 0x01 << 3); } -void DFRobot_OSD::storeChar(unsigned short addr, int temp[]) +void DFRobot_OSD::storeChar(unsigned short addr, const int temp[]) { int buf[54] = {0}; int dt[54] = {0}; diff --git a/src/main.cpp b/src/main.cpp index ca1ff05..ef370dc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -37,19 +37,21 @@ #define OSD_X_START 1 #define OSD_Y_START 16 -int osd_chart_buffer[OSD_CHART_WIDTH]; - DFRobot_OSD osd(CS); /*Define Chinese characters*/ -int buf0[36] = {0x02, 0x80, 0x02, 0x40, 0x7F, 0xE0, 0x42, 0x00, 0x42, 0x00, 0x7A, 0x40, - 0x4A, 0x40, 0x4A, 0x80, 0x49, 0x20, 0x5A, 0xA0, 0x44, 0x60, 0x88, 0x20}; -int buf1[36] = {0x20, 0x00, 0x25, 0xE0, 0x75, 0x20, 0x29, 0x20, 0xFD, 0x40, 0x21, 0x40, - 0x7D, 0x20, 0xC5, 0x20, 0x7D, 0x20, 0x45, 0xC0, 0x7D, 0x00, 0x45, 0x00}; -int buf2[36] = {0x20, 0x00, 0x2F, 0xC0, 0x24, 0x40, 0xF4, 0x40, 0x24, 0x80, 0x64, 0xE0, - 0x74, 0x20, 0xA6, 0x20, 0x25, 0x40, 0x28, 0x80, 0x29, 0x40, 0x32, 0x20}; -int buf3[36] = {0x3F, 0x00, 0x2A, 0xE0, 0xFA, 0x20, 0x2E, 0xA0, 0x2A, 0xA0, 0xFE, 0xA0, - 0x2A, 0x40, 0xAB, 0x40, 0xBE, 0xA0, 0xA3, 0x20, 0xE2, 0x00, 0xBF, 0xE0}; +static const int buf0[36] = {0x02, 0x80, 0x02, 0x40, 0x7F, 0xE0, 0x42, 0x00, + 0x42, 0x00, 0x7A, 0x40, 0x4A, 0x40, 0x4A, 0x80, + 0x49, 0x20, 0x5A, 0xA0, 0x44, 0x60, 0x88, 0x20}; +static const int buf1[36] = {0x20, 0x00, 0x25, 0xE0, 0x75, 0x20, 0x29, 0x20, + 0xFD, 0x40, 0x21, 0x40, 0x7D, 0x20, 0xC5, 0x20, + 0x7D, 0x20, 0x45, 0xC0, 0x7D, 0x00, 0x45, 0x00}; +static const int buf2[36] = {0x20, 0x00, 0x2F, 0xC0, 0x24, 0x40, 0xF4, 0x40, + 0x24, 0x80, 0x64, 0xE0, 0x74, 0x20, 0xA6, 0x20, + 0x25, 0x40, 0x28, 0x80, 0x29, 0x40, 0x32, 0x20}; +static const int buf3[36] = {0x3F, 0x00, 0x2A, 0xE0, 0xFA, 0x20, 0x2E, 0xA0, + 0x2A, 0xA0, 0xFE, 0xA0, 0x2A, 0x40, 0xAB, 0x40, + 0xBE, 0xA0, 0xA3, 0x20, 0xE2, 0x00, 0xBF, 0xE0}; // SPI pins // .pio/libdeps/heltec_wifi_lora_32_V3/Heltec_ESP32_LoRa_v3/src/heltec_unofficial.h#L34-L35