#define st(x) do { x } while (__LINE__ == -1)

本文详细解析了C语言中预处理宏__LINE__的使用技巧及其如何与do...while(0)结合,避免宏展开时的语法错误。通过具体例子说明了如何正确地定义宏来确保代码的健壮性。
#define st(x)      do { x } while (__LINE__ == -1)

1, __LINE__ 是个宏,它代表当前代码在源文件的行号,它是大于0的,所以__LINE__ == -1 等同于0,化简为:
#define st(x) do { x } while (0)

2,do {} while (0)通常用于宏中, 为的是避免如下情况:

#define st(x) x

那么我们在调用 if (0) st(a = b; b = c;) 时会被解释成

if(0)
a = b;
b = c;

可见 if 只对a = b;起作用。
#define GPIOB0_PORT GPIOB #define GPIOB0_PIN GPIO_PIN_0 #define GPIOB0 GPIOB0_PORT,GPIOB0_PIN #define GPIOB1_PORT GPIOB #define GPIOB1_PIN GPIO_PIN_1 #define GPIOB1 GPIOB1_PORT,GPIOB1_PIN #define GPIOB2_PORT GPIOB #define GPIOB2_PIN GPIO_PIN_2 #define GPIOB2 GPIOB2_PORT,GPIOB2_PIN #define GPIOB3_PORT GPIOB #define GPIOB3_PIN GPIO_PIN_3 #define GPIOB3 GPIOB3_PORT,GPIOB3_PIN #define GPIOB4_PORT GPIOB #define GPIOB4_PIN GPIO_PIN_4 #define GPIOB4 GPIOB4_PORT,GPIOB4_PIN #define GPIOB5_PORT GPIOB #define GPIOB5_PIN GPIO_PIN_5 #define GPIOB5 GPIOB5_PORT,GPIOB5_PIN #define GPIOB6_PORT GPIOB #define GPIOB6_PIN GPIO_PIN_6 #define GPIOB6 GPIOB6_PORT,GPIOB6_PIN #define GPIOB7_PORT GPIOB #define GPIOB7_PIN GPIO_PIN_7 #define GPIOB7 GPIOB7_PORT,GPIOB7_PIN #define GPIOB8_PORT GPIOB #define GPIOB8_PIN GPIO_PIN_8 #define GPIOB8 GPIOB8_PORT,GPIOB8_PIN #define GPIOB9_PORT GPIOB #define GPIOB9_PIN GPIO_PIN_9 #define GPIOB9 GPIOB9_PORT,GPIOB9_PIN #define GPIOB10_PORT GPIOB #define GPIOB10_PIN GPIO_PIN_10 #define GPIOB10 GPIOB10_PORT,GPIOB10_PIN #define GPIOB11_PORT GPIOB #define GPIOB11_PIN GPIO_PIN_11 #define GPIOB11 GPIOB11_PORT,GPIOB11_PIN #define GPIOB12_PORT GPIOB #define GPIOB12_PIN GPIO_PIN_12 #define GPIOB12 GPIOB12_PORT,GPIOB12_PIN #define GPIOB13_PORT GPIOB #define GPIOB13_PIN GPIO_PIN_13 #define GPIOB13 GPIOB13_PORT,GPIOB13_PIN #define GPIOB14_PORT GPIOB #define GPIOB14_PIN GPIO_PIN_14 #define GPIOB14 GPIOB14_PORT,GPIOB14_PIN #define GPIOB15_PORT GPIOB #define GPIOB15_PIN GPIO_PIN_15 #define GPIOB15 GPIOB15_PORT,GPIOB15_PIN #define GPIOC0_PORT GPIOC #define GPIOC0_PIN GPIO_PIN_0 #define GPIOC0 GPIOC0_PORT,GPIOC0_PIN #define GPIOC1_PORT GPIOC #define GPIOC1_PIN GPIO_PIN_1 #define GPIOC1 GPIOC1_PORT,GPIOC1_PIN #define GPIOC2_PORT GPIOC #define GPIOC2_PIN GPIO_PIN_2 #define GPIOC2 GPIOC2_PORT,GPIOC2_PIN #define GPIOC3_PORT GPIOC #define GPIOC3_PIN GPIO_PIN_3 #define GPIOC3 GPIOC3_PORT,GPIOC3_PIN #define GPIOC4_PORT GPIOC #define GPIOC4_PIN GPIO_PIN_4 #define GPIOC4 GPIOC4_PORT,GPIOC4_PIN #define GPIOC5_PORT GPIOC #define GPIOC5_PIN GPIO_PIN_5 #define GPIOC5 GPIOC5_PORT,GPIOC5_PIN #define GPIOC6_PORT GPIOC #define GPIOC6_PIN GPIO_PIN_6 #define GPIOC6 GPIOC6_PORT,GPIOC6_PIN #define GPIOC7_PORT GPIOC #define GPIOC7_PIN GPIO_PIN_7 #define GPIOC7 GPIOC7_PORT,GPIOC7_PIN #define GPIOC8_PORT GPIOC #define GPIOC8_PIN GPIO_PIN_8 #define GPIOC8 GPIOC8_PORT,GPIOC8_PIN #define GPIOC9_PORT GPIOC #define GPIOC9_PIN GPIO_PIN_9 #define GPIOC9 GPIOC9_PORT,GPIOC9_PIN #define GPIOC10_PORT GPIOC #define GPIOC10_PIN GPIO_PIN_10 #define GPIOC10 GPIOC10_PORT,GPIOC10_PIN #define GPIOC11_PORT GPIOC #define GPIOC11_PIN GPIO_PIN_11 #define GPIOC11 GPIOC11_PORT,GPIOC11_PIN #define GPIOC12_PORT GPIOC #define GPIOC12_PIN GPIO_PIN_12 #define GPIOC12 GPIOC12_PORT,GPIOC12_PIN #define GPIOC13_PORT GPIOC #define GPIOC13_PIN GPIO_PIN_13 #define GPIOC13 GPIOC13_PORT,GPIOC13_PIN #define GPIOC14_PORT GPIOC #define GPIOC14_PIN GPIO_PIN_14 #define GPIOC14 GPIOC14_PORT,GPIOC14_PIN #define GPIOC15_PORT GPIOC #define GPIOC15_PIN GPIO_PIN_15 #define GPIOC15 GPIOC15_PORT,GPIOC15_PIN //debug uart 注释
最新发布
11-01
这是user_setup.h里的文件,你帮我修改,把完整代码发我// USER DEFINED SETTINGS // Set driver type, fonts to be loaded, pins used and SPI control method etc. // // See the User_Setup_Select.h file if you wish to be able to define multiple // setups and then easily select which setup file is used by the compiler. // // If this file is edited correctly then all the library example sketches should // run without the need to make any more changes for a particular hardware setup! // Note that some sketches are designed for a particular TFT pixel width/height // User defined information reported by "Read_User_Setup" test & diagnostics example #define USER_SETUP_INFO "User_Setup" // Define to disable all #warnings in library (can be put in User_Setup_Select.h) //#define DISABLE_ALL_LIBRARY_WARNINGS // ################################################################################## // // Section 1. Call up the right driver file and any options for it // // ################################################################################## // Define STM32 to invoke optimised processor support (only for STM32) //#define STM32 // Defining the STM32 board allows the library to optimise the performance // for UNO compatible "MCUfriend" style shields //#define NUCLEO_64_TFT //#define NUCLEO_144_TFT // STM32 8-bit parallel only: // If STN32 Port A or B pins 0-7 are used for 8-bit parallel data bus bits 0-7 // then this will improve rendering performance by a factor of ~8x //#define STM_PORTA_DATA_BUS //#define STM_PORTB_DATA_BUS // Tell the library to use parallel mode (otherwise SPI is assumed) //#define TFT_PARALLEL_8_BIT //#defined TFT_PARALLEL_16_BIT // **** 16-bit parallel ONLY for RP2040 processor **** // Display type - only define if RPi display //#define RPI_DISPLAY_TYPE // 20MHz maximum SPI // Only define one driver, the other ones must be commented out #define ILI9341_DRIVER // Generic driver for common displays //#define ILI9341_2_DRIVER // Alternative ILI9341 driver, see https://github.com/Bodmer/TFT_eSPI/issues/1172 //#define ST7735_DRIVER // Define additional parameters below for this display //#define ILI9163_DRIVER // Define additional parameters below for this display //#define S6D02A1_DRIVER //#define RPI_ILI9486_DRIVER // 20MHz maximum SPI //#define HX8357D_DRIVER //#define ILI9481_DRIVER //#define ILI9486_DRIVER //#define ILI9488_DRIVER // WARNING: Do not connect ILI9488 display SDO to MISO if other devices share the SPI bus (TFT SDO does NOT tristate when CS is high) //#define ST7789_DRIVER // Full configuration option, define additional parameters below for this display //#define ST7789_2_DRIVER // Minimal configuration option, define additional parameters below for this display //#define R61581_DRIVER //#define RM68140_DRIVER //#define ST7796_DRIVER //#define SSD1351_DRIVER //#define SSD1963_480_DRIVER //#define SSD1963_800_DRIVER //#define SSD1963_800ALT_DRIVER //#define ILI9225_DRIVER #define GC9A01_DRIVER // Some displays support SPI reads via the MISO pin, other displays have a single // bi-directional SDA pin and the library will try to read this via the MOSI line. // To use the SDA line for reading data from the TFT uncomment the following line: // #define TFT_SDA_READ // This option is for ESP32 ONLY, tested with ST7789 and GC9A01 display only // For ST7735, ST7789 and ILI9341 ONLY, define the colour order IF the blue and red are swapped on your display // Try ONE option at a time to find the correct colour order for your display // #define TFT_RGB_ORDER TFT_RGB // Colour order Red-Green-Blue // #define TFT_RGB_ORDER TFT_BGR // Colour order Blue-Green-Red // For M5Stack ESP32 module with integrated ILI9341 display ONLY, remove // in line below // #define M5STACK // For ST7789, ST7735, ILI9163 and GC9A01 ONLY, define the pixel width and height in portrait orientation // #define TFT_WIDTH 80 // #define TFT_WIDTH 128 // #define TFT_WIDTH 172 // ST7789 172 x 320 // #define TFT_WIDTH 170 // ST7789 170 x 320 // #define TFT_WIDTH 240 // ST7789 240 x 240 and 240 x 320 // #define TFT_HEIGHT 160 // #define TFT_HEIGHT 128 // #define TFT_HEIGHT 240 // ST7789 240 x 240 // #define TFT_HEIGHT 320 // ST7789 240 x 320 // #define TFT_HEIGHT 240 // GC9A01 240 x 240 // For ST7735 ONLY, define the type of display, originally this was based on the // colour of the tab on the screen protector film but this is not always true, so try // out the different options below if the screen does not display graphics correctly, // e.g. colours wrong, mirror images, or stray pixels at the edges. // Comment out ALL BUT ONE of these options for a ST7735 display driver, save this // this User_Setup file, then rebuild and upload the sketch to the board again: // #define ST7735_INITB // #define ST7735_GREENTAB // #define ST7735_GREENTAB2 // #define ST7735_GREENTAB3 // #define ST7735_GREENTAB128 // For 128 x 128 display // #define ST7735_GREENTAB160x80 // For 160 x 80 display (BGR, inverted, 26 offset) // #define ST7735_ROBOTLCD // For some RobotLCD Arduino shields (128x160, BGR, https://docs.arduino.cc/retired/getting-started-guides/TFT) // #define ST7735_REDTAB // #define ST7735_BLACKTAB // #define ST7735_REDTAB160x80 // For 160 x 80 display with 24 pixel offset // If colours are inverted (white shows as black) then uncomment one of the next // 2 lines try both options, one of the options should correct the inversion. // #define TFT_INVERSION_ON // #define TFT_INVERSION_OFF // ################################################################################## // // Section 2. Define the pins that are used to interface with the display here // // ################################################################################## // If a backlight control signal is available then define the TFT_BL pin in Section 2 // below. The backlight will be turned ON when tft.begin() is called, but the library // needs to know if the LEDs are ON with the pin HIGH or LOW. If the LEDs are to be // driven with a PWM signal or turned OFF/ON then this must be handled by the user // sketch. e.g. with digitalWrite(TFT_BL, LOW); // #define TFT_BL 32 // LED back-light control pin // #define TFT_BACKLIGHT_ON HIGH // Level to turn ON back-light (HIGH or LOW) // We must use hardware SPI, a minimum of 3 GPIO pins is needed. // Typical setup for ESP8266 NodeMCU ESP-12 is : // // Display SDO/MISO to NodeMCU pin D6 (or leave disconnected if not reading TFT) // Display LED to NodeMCU pin VIN (or 5V, see below) // Display SCK to NodeMCU pin D5 // Display SDI/MOSI to NodeMCU pin D7 // Display DC (RS/AO)to NodeMCU pin D3 // Display RESET to NodeMCU pin D4 (or RST, see below) // Display CS to NodeMCU pin D8 (or GND, see below) // Display GND to NodeMCU pin GND (0V) // Display VCC to NodeMCU 5V or 3.3V // // The TFT RESET pin can be connected to the NodeMCU RST pin or 3.3V to free up a control pin // // The DC (Data Command) pin may be labelled AO or RS (Register Select) // // With some displays such as the ILI9341 the TFT CS pin can be connected to GND if no more // SPI devices (e.g. an SD Card) are connected, in this case comment out the #define TFT_CS // line below so it is NOT defined. Other displays such at the ST7735 require the TFT CS pin // to be toggled during setup, so in these cases the TFT_CS line must be defined and connected. // // The NodeMCU D0 pin can be used for RST // // // Note: only some versions of the NodeMCU provide the USB 5V on the VIN pin // If 5V is not available at a pin you can use 3.3V but backlight brightness // will be lower. // ###### EDIT THE PIN NUMBERS IN THE LINES FOLLOWING TO SUIT YOUR ESP8266 SETUP ###### // For NodeMCU - use pin numbers in the form PIN_Dx where Dx is the NodeMCU pin designation /*#define TFT_MISO PIN_D6 // Automatically assigned with ESP8266 if not defined #define TFT_MOSI PIN_D7 // Automatically assigned with ESP8266 if not defined #define TFT_SCLK PIN_D5 // Automatically assigned with ESP8266 if not defined #define TFT_CS PIN_D8 // Chip select control pin D8 #define TFT_DC PIN_D3 // Data Command control pin #define TFT_RST PIN_D4 // Reset pin (could connect to NodeMCU RST, see next line)*/ //#define TFT_RST -1 // Set TFT_RST to -1 if the display RESET is connected to NodeMCU RST or 3.3V //#define TFT_BL PIN_D1 // LED back-light (only for ST7789 with backlight control pin) //#define TOUCH_CS PIN_D2 // Chip select pin (T_CS) of touch screen //#define TFT_WR PIN_D2 // Write strobe for modified Raspberry Pi TFT only // ###### FOR ESP8266 OVERLAP MODE EDIT THE PIN NUMBERS IN THE FOLLOWING LINES ###### // Overlap mode shares the ESP8266 FLASH SPI bus with the TFT so has a performance impact // but saves pins for other functions. It is best not to connect MISO as some displays // do not tristate that line when chip select is high! // Note: Only one SPI device can share the FLASH SPI lines, so a SPI touch controller // cannot be connected as well to the same SPI signals. // On NodeMCU 1.0 SD0=MISO, SD1=MOSI, CLK=SCLK to connect to TFT in overlap mode // On NodeMCU V3 S0 =MISO, S1 =MOSI, S2 =SCLK // In ESP8266 overlap mode the following must be defined //#define TFT_SPI_OVERLAP // In ESP8266 overlap mode the TFT chip select MUST connect to pin D3 //#define TFT_CS PIN_D3 //#define TFT_DC PIN_D5 // Data Command control pin //#define TFT_RST PIN_D4 // Reset pin (could connect to NodeMCU RST, see next line) //#define TFT_RST -1 // Set TFT_RST to -1 if the display RESET is connected to NodeMCU RST or 3.3V // ###### EDIT THE PIN NUMBERS IN THE LINES FOLLOWING TO SUIT YOUR ESP32 SETUP ###### // For ESP32 Dev board (only tested with ILI9341 display) // The hardware SPI can be mapped to any pins //#define TFT_MISO 19 //#define TFT_MOSI 23 //#define TFT_SCLK 18 //#define TFT_CS 15 // Chip select control pin //#define TFT_DC 2 // Data Command control pin //#define TFT_RST 4 // Reset pin (could connect to RST pin) //#define TFT_RST -1 // Set TFT_RST to -1 if display RESET is connected to ESP32 board RST // For ESP32 Dev board (only tested with GC9A01 display) // The hardware SPI can be mapped to any pins #define TFT_MOSI 3 // In some display driver board, it might be written as "SDA" and so on. #define TFT_SCLK 2 #define TFT_CS 6 // Chip select control pin #define TFT_DC 10 // Data Command control pin #define TFT_RST 7 // Reset pin (could connect to Arduino RESET pin) //#define TFT_BL 22 // LED back-light //#define TOUCH_CS 21 // Chip select pin (T_CS) of touch screen //#define TFT_WR 22 // Write strobe for modified Raspberry Pi TFT only // For the M5Stack module use these #define lines //#define TFT_MISO 19 //#define TFT_MOSI 23 //#define TFT_SCLK 18 //#define TFT_CS 14 // Chip select control pin //#define TFT_DC 27 // Data Command control pin //#define TFT_RST 33 // Reset pin (could connect to Arduino RESET pin) //#define TFT_BL 32 // LED back-light (required for M5Stack) // ###### EDIT THE PINs BELOW TO SUIT YOUR ESP32 PARALLEL TFT SETUP ###### // The library supports 8-bit parallel TFTs with the ESP32, the pin // selection below is compatible with ESP32 boards in UNO format. // Wemos D32 boards need to be modified, see diagram in Tools folder. // Only ILI9481 and ILI9341 based displays have been tested! // Parallel bus is only supported for the STM32 and ESP32 // Example below is for ESP32 Parallel interface with UNO displays // Tell the library to use 8-bit parallel mode (otherwise SPI is assumed) //#define TFT_PARALLEL_8_BIT // The ESP32 and TFT the pins used for testing are: //#define TFT_CS 33 // Chip select control pin (library pulls permanently low //#define TFT_DC 15 // Data Command control pin - must use a pin in the range 0-31 //#define TFT_RST 32 // Reset pin, toggles on startup //#define TFT_WR 4 // Write strobe control pin - must use a pin in the range 0-31 //#define TFT_RD 2 // Read strobe control pin //#define TFT_D0 12 // Must use pins in the range 0-31 for the data bus //#define TFT_D1 13 // so a single register write sets/clears all bits. //#define TFT_D2 26 // Pins can be randomly assigned, this does not affect //#define TFT_D3 25 // TFT screen update performance. //#define TFT_D4 17 //#define TFT_D5 16 //#define TFT_D6 27 //#define TFT_D7 14 // ###### EDIT THE PINs BELOW TO SUIT YOUR STM32 SPI TFT SETUP ###### // The TFT can be connected to SPI port 1 or 2 //#define TFT_SPI_PORT 1 // SPI port 1 maximum clock rate is 55MHz //#define TFT_MOSI PA7 //#define TFT_MISO PA6 //#define TFT_SCLK PA5 //#define TFT_SPI_PORT 2 // SPI port 2 maximum clock rate is 27MHz //#define TFT_MOSI PB15 //#define TFT_MISO PB14 //#define TFT_SCLK PB13 // Can use Ardiuno pin references, arbitrary allocation, TFT_eSPI controls chip select //#define TFT_CS D5 // Chip select control pin to TFT CS //#define TFT_DC D6 // Data Command control pin to TFT DC (may be labelled RS = Register Select) //#define TFT_RST D7 // Reset pin to TFT RST (or RESET) // OR alternatively, we can use STM32 port reference names PXnn //#define TFT_CS PE11 // Nucleo-F767ZI equivalent of D5 //#define TFT_DC PE9 // Nucleo-F767ZI equivalent of D6 //#define TFT_RST PF13 // Nucleo-F767ZI equivalent of D7 //#define TFT_RST -1 // Set TFT_RST to -1 if the display RESET is connected to processor reset // Use an Arduino pin for initial testing as connecting to processor reset // may not work (pulse too short at power up?) // ################################################################################## // // Section 3. Define the fonts that are to be used here // // ################################################################################## // Comment out the #defines below with // to stop that font being loaded // The ESP8366 and ESP32 have plenty of memory so commenting out fonts is not // normally necessary. If all fonts are loaded the extra FLASH space required is // about 17Kbytes. To save FLASH space only enable the fonts you need! #define LOAD_GLCD // Font 1. Original Adafruit 8 pixel font needs ~1820 bytes in FLASH #define LOAD_FONT2 // Font 2. Small 16 pixel high font, needs ~3534 bytes in FLASH, 96 characters #define LOAD_FONT4 // Font 4. Medium 26 pixel high font, needs ~5848 bytes in FLASH, 96 characters #define LOAD_FONT6 // Font 6. Large 48 pixel font, needs ~2666 bytes in FLASH, only characters 1234567890:-.apm #define LOAD_FONT7 // Font 7. 7 segment 48 pixel font, needs ~2438 bytes in FLASH, only characters 1234567890:-. #define LOAD_FONT8 // Font 8. Large 75 pixel font needs ~3256 bytes in FLASH, only characters 1234567890:-. //#define LOAD_FONT8N // Font 8. Alternative to Font 8 above, slightly narrower, so 3 digits fit a 160 pixel TFT #define LOAD_GFXFF // FreeFonts. Include access to the 48 Adafruit_GFX free fonts FF1 to FF48 and custom fonts // Comment out the #define below to stop the SPIFFS filing system and smooth font code being loaded // this will save ~20kbytes of FLASH #define SMOOTH_FONT // ################################################################################## // // Section 4. Other options // // ################################################################################## // For RP2040 processor and SPI displays, uncomment the following line to use the PIO interface. //#define RP2040_PIO_SPI // Leave commented out to use standard RP2040 SPI port interface // For RP2040 processor and 8 or 16-bit parallel displays: // The parallel interface write cycle period is derived from a division of the CPU clock // speed so scales with the processor clock. This means that the divider ratio may need // to be increased when overclocking. It may also need to be adjusted dependant on the // display controller type (ILI94341, HX8357C etc.). If RP2040_PIO_CLK_DIV is not defined // the library will set default values which may not suit your display. // The display controller data sheet will specify the minimum write cycle period. The // controllers often work reliably for shorter periods, however if the period is too short // the display may not initialise or graphics will become corrupted. // PIO write cycle frequency = (CPU clock/(4 * RP2040_PIO_CLK_DIV)) //#define RP2040_PIO_CLK_DIV 1 // 32ns write cycle at 125MHz CPU clock //#define RP2040_PIO_CLK_DIV 2 // 64ns write cycle at 125MHz CPU clock //#define RP2040_PIO_CLK_DIV 3 // 96ns write cycle at 125MHz CPU clock // For the RP2040 processor define the SPI port channel used (default 0 if undefined) //#define TFT_SPI_PORT 1 // Set to 0 if SPI0 pins are used, or 1 if spi1 pins used // For the STM32 processor define the SPI port channel used (default 1 if undefined) //#define TFT_SPI_PORT 2 // Set to 1 for SPI port 1, or 2 for SPI port 2 // Define the SPI clock frequency, this affects the graphics rendering speed. Too // fast and the TFT driver will not keep up and display corruption appears. // With an ILI9341 display 40MHz works OK, 80MHz sometimes fails // With a ST7735 display more than 27MHz may not work (spurious pixels and lines) // With an ILI9163 display 27 MHz works OK. // #define SPI_FREQUENCY 1000000 // #define SPI_FREQUENCY 5000000 // #define SPI_FREQUENCY 10000000 // #define SPI_FREQUENCY 20000000 #define SPI_FREQUENCY 27000000 // #define SPI_FREQUENCY 40000000 // #define SPI_FREQUENCY 55000000 // STM32 SPI1 only (SPI2 maximum is 27MHz) // #define SPI_FREQUENCY 80000000 // Optional reduced SPI frequency for reading TFT #define SPI_READ_FREQUENCY 20000000 // The XPT2046 requires a lower SPI clock rate of 2.5MHz so we define that here: #define SPI_TOUCH_FREQUENCY 2500000 // The ESP32 has 2 free SPI ports i.e. VSPI and HSPI, the VSPI is the default. // If the VSPI port is in use and pins are not accessible (e.g. TTGO T-Beam) // then uncomment the following line: //#define USE_HSPI_PORT // Comment out the following #define if "SPI Transactions" do not need to be // supported. When commented out the code size will be smaller and sketches will // run slightly faster, so leave it commented out unless you need it! // Transaction support is needed to work with SD library but not needed with TFT_SdFat // Transaction support is required if other SPI devices are connected. // Transactions are automatically enabled by the library for an ESP32 (to use HAL mutex) // so changing it here has no effect // #define SUPPORT_TRANSACTIONS
09-26
#include <windows.h> #include <shlobj.h> #include <stdio.h> #include <time.h> #include "aip_common.h" #define BTN_BROWSE_FOLDER (101) #define BTN_SAVE_SYMBOLS (102) #define BTN_GENERATE_DATA (103) #define BTN_PROCESS_DATA (104) #define EDIT_FOLDER_PATH (105) #define EDIT_USER_SYMBOLS (106) #define ZERO (0) #define ONE (1) #define TWO (2) #define MAX_FOLDER_LENGTH (260) #define MAX_SYMBOL_INPUT (10000) #define MAX_LINE_CONTENT (10000) #define MAX_SYMBOL_PAIRS (10) #define MAX_LINE_COUNT (100) #define MAX_LINE_LENGTH (50) #define DIGIT_START L'0' #define DIGIT_END L'9' #define UPPERCASE_START L'A' #define UPPERCASE_END L'Z' #define LOWERCASE_START L'a' #define LOWERCASE_END L'z' #define STACK_INIT -ONE #define STACK_EMPTY -ONE #define LINE_CONTENT_ELEMENTS (MAX_LINE_CONTENT) typedef struct { U2 u2_t_SYMBOL_open; U2 u2_t_SYMBOL_close; } ST_SYMBOL_PAIR; ST_SYMBOL_PAIR st_g_SYMBOL_pairs_p[MAX_SYMBOL_PAIRS]; U4 u4_g_SYMBOL_num_pairs = ZERO; // 符号对数量 U2 u2p_g_FILE_folder_path_p[MAX_FOLDER_LENGTH ]; // 文件夹路径 U2 u2p_g_SYMBOL_user_symbols_p[MAX_SYMBOL_INPUT ]; // 用户输入的符号对 // 函数声明 void v_g_SYMBOL_saveFile(const U2 *u2p_g_FILE_folder_path_p, const U2 *u2p_a_SYMBOL_user_input) ; U4 u4_g_SYMBOL_loadFile(const U2 *u2p_g_FILE_folder_path_p) ; U4 u4_g_SYMBOL_isOpening(U2 u2_t_SYMBOL_ch); U4 u4_g_SYMBOL_isClosing(U2 u2_t_SYMBOL_ch); U4 u4_g_SYMBOL_matches(U2 u2_t_SYMBOL_open, U2 u2_t_SYMBOL_close); void v_g_SYMBOL_generateRandomData(const U2 *u2p_g_FILE_folder_path_p); void v_g_SYMBOL_validateDataFile(const U2 *u2p_g_FILE_folder_path_p); void v_g_FILE_browseFolder(HWND hwnd); void v_g_SYMBOL_saveFile(const U2 *u2p_g_FILE_folder_path_p, const U2 *u2p_a_SYMBOL_user_input) { U2 u2_t_FILE_file_path_p[(U4)MAX_FOLDER_LENGTH ]; swprintf(u2_t_FILE_file_path_p, (U4)MAX_FOLDER_LENGTH , L"%ls\\Symbol.txt", u2p_g_FILE_folder_path_p); // 检查输入的字符是否包含数字或字母 for (U4 u4_t_LOOP_index = ZERO; u2p_a_SYMBOL_user_input[u4_t_LOOP_index] != L'\0'; u4_t_LOOP_index++) { if ((u2p_a_SYMBOL_user_input[u4_t_LOOP_index] >= DIGIT_START && u2p_a_SYMBOL_user_input[u4_t_LOOP_index] <= DIGIT_END) || // 检测到数字 (u2p_a_SYMBOL_user_input[u4_t_LOOP_index] >= UPPERCASE_START && u2p_a_SYMBOL_user_input[u4_t_LOOP_index] <= UPPERCASE_END) || // 检测到大写字母 (u2p_a_SYMBOL_user_input[u4_t_LOOP_index] >= LOWERCASE_START && u2p_a_SYMBOL_user_input[u4_t_LOOP_index] <= LOWERCASE_END)) { // 检测到小写字母 U2 u2_t_ERROR_message_p[(U4)MAX_FOLDER_LENGTH ]; swprintf(u2_t_ERROR_message_p, (U4)MAX_FOLDER_LENGTH , L"错误:输入包含无效字符:'%lc'。请重新输入合法的符号。", u2p_a_SYMBOL_user_input[u4_t_LOOP_index]); MessageBoxW(NULL, u2_t_ERROR_message_p, L"错误", MB_OK | MB_ICONERROR); return; // 立即停止处理 } } FILE *vdp_t_FILE_file = _wfopen(u2_t_FILE_file_path_p, L"w, ccs=UTF-8"); // 使用 UTF-8 编码写入文件 if (!vdp_t_FILE_file) { MessageBoxW(NULL, L"无法创建 Symbol.txt 文件。", L"错误", MB_OK | MB_ICONERROR); return; } U4 u4_t_SYMBOL_pair_count = (U4)ZERO; for (U4 u4_t_LOOP_index = (U4)ZERO; u2p_a_SYMBOL_user_input[u4_t_LOOP_index] != L'\0'; u4_t_LOOP_index++) { // 跳过无效字符 if ((u2p_a_SYMBOL_user_input[u4_t_LOOP_index] == L' ') || (u2p_a_SYMBOL_user_input[u4_t_LOOP_index] == L'\t') || (u2p_a_SYMBOL_user_input[u4_t_LOOP_index] == L'\n')) { continue; // 跳过空格、制表符、换行符 } // 确保符号对有效 if ((u2p_a_SYMBOL_user_input[u4_t_LOOP_index + (U4)ONE] != L'\0')&& (u2p_a_SYMBOL_user_input[u4_t_LOOP_index + (U4)ONE] != L'\n')&& (u2p_a_SYMBOL_user_input[u4_t_LOOP_index + (U4)ONE] != L' ') && (u2p_a_SYMBOL_user_input[u4_t_LOOP_index + (U4)ONE] != L'\t')) { fwprintf(vdp_t_FILE_file, L"%lc%lc\n", u2p_a_SYMBOL_user_input[u4_t_LOOP_index], u2p_a_SYMBOL_user_input[u4_t_LOOP_index + ONE]); // 写入符号对到文件 u4_t_LOOP_index++; // 跳过第二个符号 u4_t_SYMBOL_pair_count++; } } fclose(vdp_t_FILE_file); if (u4_t_SYMBOL_pair_count > ZERO) { MessageBoxW(NULL, L"符号已成功保存到 Symbol.txt 文件!", L"成功", MB_OK | MB_ICONINFORMATION); } else { MessageBoxW(NULL, L"输入中未发现有效符号对。", L"错误", MB_OK | MB_ICONERROR); } } U4 u4_g_SYMBOL_loadFile(const U2 *u2p_g_FILE_folder_path_p) { U2 u2_t_FILE_file_path_p[(U4)MAX_FOLDER_LENGTH ]; swprintf(u2_t_FILE_file_path_p, (U4)MAX_FOLDER_LENGTH , L"%ls\\Symbol.txt", u2p_g_FILE_folder_path_p); FILE *vdp_t_FILE_input_file = _wfopen(u2_t_FILE_file_path_p, L"r, ccs=UTF-8"); // 读取 UTF-8 编码内容 if (!vdp_t_FILE_input_file ) { MessageBoxW(NULL, L"错误:无法打开 Symbol.txt 文件。", L"错误", MB_OK | MB_ICONERROR); return 0; } u4_g_SYMBOL_num_pairs = (U4)ZERO; U2 u2_t_FILE_line_p[(U4)MAX_LINE_CONTENT]; while (fgetws(u2_t_FILE_line_p, (U4)(U4)LINE_CONTENT_ELEMENTS, vdp_t_FILE_input_file ) && u4_g_SYMBOL_num_pairs < MAX_SYMBOL_PAIRS) { U4 u4_t_SYMBOL_line_length = wcslen(u2_t_FILE_line_p); // 去掉行末的换行符 if (u4_t_SYMBOL_line_length > (U4)ZERO && u2_t_FILE_line_p[u4_t_SYMBOL_line_length - (U4)ONE] == L'\n') { u2_t_FILE_line_p[u4_t_SYMBOL_line_length - (U4)ONE] = L'\0'; u4_t_SYMBOL_line_length--; } // 跳过空行 if (u4_t_SYMBOL_line_length == (U4)ZERO) { continue; } // 检查符号对格式 U2 u2_t_SYMBOL_open, u2_t_SYMBOL_close; if (swscanf(u2_t_FILE_line_p, L"%lc%lc", &u2_t_SYMBOL_open, &u2_t_SYMBOL_close) == (U4)TWO) { // 检测数字或字母,直接跳过 if ((u2_t_SYMBOL_open >= DIGIT_START && u2_t_SYMBOL_open <= DIGIT_END) || (u2_t_SYMBOL_open >= UPPERCASE_START && u2_t_SYMBOL_open <= UPPERCASE_END) || (u2_t_SYMBOL_open >= LOWERCASE_START && u2_t_SYMBOL_open <= LOWERCASE_END) || (u2_t_SYMBOL_close >= DIGIT_START && u2_t_SYMBOL_close <= DIGIT_END) || (u2_t_SYMBOL_close >= UPPERCASE_START && u2_t_SYMBOL_close <= UPPERCASE_END) || (u2_t_SYMBOL_close >= LOWERCASE_START && u2_t_SYMBOL_close <= LOWERCASE_END)) { continue; // 跳过该行 } // 如果符号合法,加入符号对数组 st_g_SYMBOL_pairs_p[u4_g_SYMBOL_num_pairs].u2_t_SYMBOL_open = u2_t_SYMBOL_open; st_g_SYMBOL_pairs_p[u4_g_SYMBOL_num_pairs].u2_t_SYMBOL_close = u2_t_SYMBOL_close; u4_g_SYMBOL_num_pairs++; } } fclose(vdp_t_FILE_input_file ); U2 u2_t_ERROR_message_p[256]; swprintf(u2_t_ERROR_message_p, sizeof(u2_t_ERROR_message_p) / sizeof(U2), L"从 Symbol.txt 文件中加载了 %d 个有效符号对。", u4_g_SYMBOL_num_pairs); MessageBoxW(NULL, u2_t_ERROR_message_p, L"成功", MB_OK | MB_ICONINFORMATION); return u4_g_SYMBOL_num_pairs > ZERO; } // 随机生成 Data.txt 文件 void v_g_SYMBOL_generateRandomData(const U2 *u2p_g_FILE_folder_path_p) { if (u4_g_SYMBOL_num_pairs == (U4)ZERO) { MessageBoxW(NULL, L"错误:未加载任何符号对。请先加载 Symbol.txt 文件!", L"错误", MB_OK | MB_ICONERROR); return; } U2 u2_t_FILE_data_path_p[MAX_FOLDER_LENGTH ]; swprintf(u2_t_FILE_data_path_p, MAX_FOLDER_LENGTH , L"%ls\\Data.txt", u2p_g_FILE_folder_path_p); FILE *vdp_t_FILE_input_file = _wfopen(u2_t_FILE_data_path_p, L"w, ccs=UTF-8"); if (!vdp_t_FILE_input_file ) { MessageBoxW(NULL, L"错误:无法创建 Data.txt 文件。", L"错误", MB_OK | MB_ICONERROR); return; } srand((U4)time(NULL)); U4 u4_t_DATA_num_lines = rand() % MAX_LINE_COUNT + ONE; // 随机生成 1100 行 for (U4 u4_t_DATA_line_index = (U4)ZERO; u4_t_DATA_line_index < u4_t_DATA_num_lines; u4_t_DATA_line_index++) { U4 u4_t_FILE_length = rand() % MAX_LINE_LENGTH + (U4)ONE; // 每行随机长度 1 到 50 for (U4 u4_t_SYMBOL_char_index = (U4)ZERO; u4_t_SYMBOL_char_index < u4_t_FILE_length; u4_t_SYMBOL_char_index++) { U4 u4_t_SYMBOL_pair_index = rand() % u4_g_SYMBOL_num_pairs; // 随机选择一个符号对 if (rand() % TWO == (U4)ZERO) { fputwc(st_g_SYMBOL_pairs_p[u4_t_SYMBOL_pair_index].u2_t_SYMBOL_open, vdp_t_FILE_input_file ); // 写入开符号 } else { fputwc(st_g_SYMBOL_pairs_p[u4_t_SYMBOL_pair_index].u2_t_SYMBOL_close, vdp_t_FILE_input_file ); // 写入闭符号 } } fputwc(L'\n', vdp_t_FILE_input_file ); // 换行符 } fclose(vdp_t_FILE_input_file ); MessageBoxW(NULL, L"Data.txt 文件已成功生成!", L"成功", MB_OK | MB_ICONINFORMATION); } // 检查符号是否匹配 U4 u4_g_SYMBOL_matches(U2 u2_t_SYMBOL_open, U2 u2_t_SYMBOL_close) { U4 u4_t_SYMBOL_match_flag = (U4)FALSE; // 匹配结果 for (U4 u4_t_SYMBOL_pair_index = (U4)ZERO; u4_t_SYMBOL_pair_index < u4_g_SYMBOL_num_pairs; u4_t_SYMBOL_pair_index++) { if (st_g_SYMBOL_pairs_p[u4_t_SYMBOL_pair_index].u2_t_SYMBOL_open == u2_t_SYMBOL_open && st_g_SYMBOL_pairs_p[u4_t_SYMBOL_pair_index].u2_t_SYMBOL_close == u2_t_SYMBOL_close) { u4_t_SYMBOL_match_flag = (U4)TRUE; // 匹配成功 break; // 找到结果后退出 } } return u4_t_SYMBOL_match_flag; } // 检查是否是开符号 U4 u4_g_SYMBOL_isOpening(U2 u2_t_SYMBOL_ch) { U4 u4_t_SYMBOL_is_open_flag = (U4)FALSE; // 是否是开符号 for (U4 u4_t_SYMBOL_pair_index = (U4)ZERO; u4_t_SYMBOL_pair_index < u4_g_SYMBOL_num_pairs; u4_t_SYMBOL_pair_index++) { if (st_g_SYMBOL_pairs_p[u4_t_SYMBOL_pair_index].u2_t_SYMBOL_open == u2_t_SYMBOL_ch) { u4_t_SYMBOL_is_open_flag = (U4)TRUE; // 是开符号 break; // 提前退出 } } return u4_t_SYMBOL_is_open_flag; } // 检查是否是闭符号 U4 u4_g_SYMBOL_isClosing(U2 u2_t_SYMBOL_ch) { U4 u4_t_SYMBOL_is_close_flag = (U4)FALSE; // 是否是闭符号 for (U4 u4_t_SYMBOL_pair_index = (U4)ZERO; u4_t_SYMBOL_pair_index < u4_g_SYMBOL_num_pairs; u4_t_SYMBOL_pair_index++) { if (st_g_SYMBOL_pairs_p[u4_t_SYMBOL_pair_index].u2_t_SYMBOL_close == u2_t_SYMBOL_ch) { u4_t_SYMBOL_is_close_flag = (U4)TRUE; // 是闭符号 break; // 提前退出 } } return u4_t_SYMBOL_is_close_flag; } // 验证 Data.txt 文件符号对并保存结果到 Result.txt 文件 void v_g_SYMBOL_validateDataFile(const U2 *u2p_g_FILE_folder_path_p) { // 定义文件路径变量 U2 u2_t_FILE_data_path_p[(U4)MAX_FOLDER_LENGTH]; // Data.txt 文件路径 U2 u2_t_FILE_result_path_p[(U4)MAX_FOLDER_LENGTH]; // Result.txt 文件路径 swprintf(u2_t_FILE_data_path_p, MAX_FOLDER_LENGTH, L"%ls\\Data.txt", u2p_g_FILE_folder_path_p); swprintf(u2_t_FILE_result_path_p, MAX_FOLDER_LENGTH, L"%ls\\Result.txt", u2p_g_FILE_folder_path_p); // 打开 Data.txt 文件 VDP vdp_t_FILE_data_file = _wfopen(u2_t_FILE_data_path_p, L"r, ccs=UTF-8"); if (!vdp_t_FILE_data_file) { MessageBoxW(NULL, L"错误:无法打开 Data.txt 文件。", L"错误", MB_OK | MB_ICONERROR); return; } // 打开 Result.txt 文件 VDP vdp_t_FILE_result_file = _wfopen(u2_t_FILE_result_path_p, L"w, ccs=UTF-8"); if (!vdp_t_FILE_result_file) { MessageBoxW(NULL, L"错误:无法创建 Result.txt 文件。", L"错误", MB_OK | MB_ICONERROR); fclose(vdp_t_FILE_data_file); return; } // 读取 Data.txt 的每一行并处理 U2 u2_t_FILE_line_p[(U4)MAX_LINE_CONTENT]; // 保存单行输入的缓冲区 while (fgetws(u2_t_FILE_line_p, (U4)MAX_LINE_CONTENT, vdp_t_FILE_data_file)) { U4 u4_t_SYMBOL_line_length = wcslen(u2_t_FILE_line_p); // 去掉换行符 if (u4_t_SYMBOL_line_length > ZERO && u2_t_FILE_line_p[u4_t_SYMBOL_line_length - ONE] == L'\n') { u2_t_FILE_line_p[u4_t_SYMBOL_line_length - ONE] = L'\0'; u4_t_SYMBOL_line_length -= ONE; } // 空行直接跳过 if (u4_t_SYMBOL_line_length == ZERO) { continue; } // 定义符号校验栈 U2 u2_t_SYMBOL_validation_stack_p[(U4)MAX_LINE_CONTENT]; // 用于符号校验的栈 U4 u4_t_SYMBOL_stack_top_index = (U4)STACK_INIT; // 栈顶初始索引 U4 u4_t_SYMBOL_matched_flag = (U4)TRUE; // 记录当前行是否匹配 // 遍历字符并进行校验 for (U4 u4_t_SYMBOL_char_index = (U4)ZERO; u4_t_SYMBOL_char_index < u4_t_SYMBOL_line_length; u4_t_SYMBOL_char_index++) { U2 u2_t_SYMBOL_current_char = u2_t_FILE_line_p[u4_t_SYMBOL_char_index]; // 处理开符号 if (u4_g_SYMBOL_isOpening(u2_t_SYMBOL_current_char)) { u2_t_SYMBOL_validation_stack_p[++u4_t_SYMBOL_stack_top_index] = u2_t_SYMBOL_current_char; } // 处理闭符号 else if (u4_g_SYMBOL_isClosing(u2_t_SYMBOL_current_char)) { if (u4_t_SYMBOL_stack_top_index == (U4)STACK_EMPTY || !u4_g_SYMBOL_matches(u2_t_SYMBOL_validation_stack_p[u4_t_SYMBOL_stack_top_index], u2_t_SYMBOL_current_char)) { u4_t_SYMBOL_matched_flag = (U4)FALSE; // 栈空或不匹配 break; } u4_t_SYMBOL_stack_top_index--; // 弹出栈 } } // 栈非空说明有未匹配的符号 if (u4_t_SYMBOL_stack_top_index != (U4)STACK_EMPTY) { u4_t_SYMBOL_matched_flag = (U4)FALSE; } // 写入匹配结果 fwprintf(vdp_t_FILE_result_file, L"%s\n", u4_t_SYMBOL_matched_flag ? L"YES" : L"NO"); } // 关闭文件 fclose(vdp_t_FILE_data_file); fclose(vdp_t_FILE_result_file); MessageBoxW(NULL, L"Result.txt 文件已成功生成!", L"成功", MB_OK | MB_ICONINFORMATION); } // 文件夹选择对话框 void v_g_FILE_browseFolder(HWND hwnd) { BROWSEINFOW st_t_UI_folder_dialog_p = {(U4)ZERO}; // 初始化选择文件夹对话框结构体 st_t_UI_folder_dialog_p.lpszTitle = L"Select Folder"; // 设置标题 st_t_UI_folder_dialog_p.ulFlags = BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE; // 设置对话框样式 LPITEMIDLIST stp_t_UI_folder_item_p = SHBrowseForFolderW(&st_t_UI_folder_dialog_p); // 显示对话框 if (stp_t_UI_folder_item_p != NULL) { SHGetPathFromIDListW(stp_t_UI_folder_item_p, u2p_g_FILE_folder_path_p); // 获取选择的文件夹路径 SetDlgItemTextW(hwnd, EDIT_FOLDER_PATH, u2p_g_FILE_folder_path_p); // 设置路径到窗口控件 } } // 窗口消息处理过程 LRESULT CALLBACK g_UI_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_CREATE: { RECT st_t_UI_window_rect; // 定义窗口矩形结构体 GetClientRect(hwnd, &st_t_UI_window_rect); // 获取客户区矩形 U4 u4_t_UI_spacing = 20; // 定义控件间隔距离 CreateWindowW(L"BUTTON", L"浏览文件夹", WS_VISIBLE | WS_CHILD, 20, 50, 120, 30, hwnd, (HMENU)BTN_BROWSE_FOLDER, NULL, NULL); CreateWindowW(L"EDIT", L"", WS_VISIBLE | WS_CHILD | WS_BORDER, 150, 50, 430, 30, hwnd, (HMENU)EDIT_FOLDER_PATH, NULL, NULL); CreateWindowW(L"EDIT", L"", WS_VISIBLE | WS_CHILD | WS_BORDER, 20, 90, 400, 30, hwnd, (HMENU)EDIT_USER_SYMBOLS, NULL, NULL); CreateWindowW(L"BUTTON", L"保存符号到Symbol.txt", WS_VISIBLE | WS_CHILD, 430, 90, 150, 30, hwnd, (HMENU)BTN_SAVE_SYMBOLS, NULL, NULL); CreateWindowW(L"BUTTON", L"随机生成Data.txt", WS_VISIBLE | WS_CHILD, 20, 130, 130, 30, hwnd, (HMENU)BTN_GENERATE_DATA, NULL, NULL); CreateWindowW(L"BUTTON", L"开始处理", WS_VISIBLE | WS_CHILD, 230, 170, 120, 40, hwnd, (HMENU)BTN_PROCESS_DATA, NULL, NULL); break; } case WM_COMMAND: switch (LOWORD(wParam)) { case BTN_BROWSE_FOLDER: v_g_FILE_browseFolder(hwnd); // 文件夹选择对话框 break; case BTN_SAVE_SYMBOLS: GetDlgItemTextW(hwnd, EDIT_FOLDER_PATH, u2p_g_FILE_folder_path_p, MAX_FOLDER_LENGTH); GetDlgItemTextW(hwnd, EDIT_USER_SYMBOLS, u2p_g_SYMBOL_user_symbols_p, MAX_SYMBOL_INPUT); v_g_SYMBOL_saveFile(u2p_g_FILE_folder_path_p, u2p_g_SYMBOL_user_symbols_p); // 保存符号 break; case BTN_GENERATE_DATA: GetDlgItemTextW(hwnd, EDIT_FOLDER_PATH, u2p_g_FILE_folder_path_p, MAX_FOLDER_LENGTH); if (u4_g_SYMBOL_loadFile(u2p_g_FILE_folder_path_p)) { v_g_SYMBOL_generateRandomData(u2p_g_FILE_folder_path_p); // 生成随机数据 } break; case BTN_PROCESS_DATA: GetDlgItemTextW(hwnd, EDIT_FOLDER_PATH, u2p_g_FILE_folder_path_p, MAX_FOLDER_LENGTH); v_g_SYMBOL_validateDataFile(u2p_g_FILE_folder_path_p); // 验证数据文件 break; } break; case WM_DESTROY: PostQuitMessage(ZERO); // 退出消息 break; default: return DefWindowProcW(hwnd, msg, wParam, lParam); // 默认处理 } return ZERO; // 默认返回值 } int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow) { const U2 u2_g_UI_class_name_p[] = L"符号匹配"; // 定义窗口类名 WNDCLASSW st_t_UI_window_class = {(U4)ZERO}; // 定义窗口类结构体 st_t_UI_window_class.lpfnWndProc = g_UI_WindowProc; // 指定消息处理过程 st_t_UI_window_class.hInstance = hInstance; // 指定实例句柄 st_t_UI_window_class.lpszClassName = u2_g_UI_class_name_p; // 指定窗口类名 RegisterClassW(&st_t_UI_window_class); // 注册窗口类 HWND vdp_t_UI_main_window = CreateWindowW(u2_g_UI_class_name_p, L"符号匹配", WS_OVERLAPPEDWINDOW | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 610, 280, NULL, NULL, hInstance, NULL); // 创建窗口 MSG st_t_UI_message; // 定义消息结构体 while (GetMessageW(&st_t_UI_message, NULL, ZERO, ZERO)) { TranslateMessage(&st_t_UI_message); // 翻译消息 DispatchMessageW(&st_t_UI_message); // 分派消息 } return ZERO; // 返回退出状态码 } 注释改成全英文的,每个函数前面加一段介绍,形如: /*===================================================================================================================================*/ /* Function Name: u4_s_main_processing_task */ /* --------------------------------------------------------------------------------------------------------------------------------- */ /* Description: Processes input file: searches for prefix, extracts/modifies addresses, writes results */ /* Arguments: U1* u1p_a_search_string : Prefix string to search */ /* Return: U4 : SUCCESS if found and processed, WRONG otherwise */ /*===================================================================================================================================*/ 每个if后面都要接else,没有操作就: else { /*do nothing*/ }
08-22
xj@xj-virtual-machine:~/linux/kernel_code/uboot$ make V=1 ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabihf- DEVICE_TREE=stm32mp157d-atk all make -f ./Makefile syncconfig make -f ./scripts/Makefile.build obj=scripts/basic rm -f .tmp_quiet_recordmcount make -f ./scripts/Makefile.build obj=scripts/kconfig syncconfig mkdir -p include/config include/generated scripts/kconfig/conf --syncconfig Kconfig make -f ./scripts/Makefile.autoconf || \ { rm -f include/config/auto.conf; false; } if [ -d arch/arm/mach-stm32mp/include/mach ]; then \ dest=../../mach-stm32mp/include/mach; \ else \ dest=arch-stm32mp; \ fi; \ ln -fsn $dest arch/arm/include/asm/arch set -e; : ' CHK include/config.h'; mkdir -p include/; (echo "/* Automatically generated - do not edit */"; for i in $(echo "" | sed 's/,/ /g'); do echo \#define CONFIG_$i | sed '/=/ {s/=/ /;q; } ; { s/$/ 1/; }'; done; echo \#define CONFIG_BOARDDIR board/st/stm32mp1; echo \#include \<config_defaults.h\>; echo \#include \<config_uncmd_spl.h\>; echo \#include \<configs/"stm32mp1".h\>; echo \#include \<asm/config.h\>; echo \#include \<linux/kconfig.h\>; echo \#include \<config_fallbacks.h\>;) < scripts/Makefile.autoconf > include/config.h.tmp; if [ -r include/config.h ] && cmp -s include/config.h include/config.h.tmp; then rm -f include/config.h.tmp; else : ' UPD include/config.h'; mv -f include/config.h.tmp include/config.h; fi arm-none-linux-gnueabihf-gcc -E -Wall -Wstrict-prototypes -Wno-format-security -fno-builtin -ffreestanding -std=gnu11 -fshort-wchar -fno-strict-aliasing -fno-PIE -O2 -fno-stack-protector -fno-delete-null-pointer-checks -fmacro-prefix-map=./= -g -fstack-usage -Wno-format-nonliteral -Werror=date-time -D__KERNEL__ -D__UBOOT__ -D__ARM__ -Wa,-mimplicit-it=always -mthumb -mthumb-interwork -mabi=aapcs-linux -mword-relocations -fno-pic -mno-unaligned-access -ffunction-sections -fdata-sections -fno-common -ffixed-r9 -msoft-float -pipe -Iinclude -I./arch/arm/include -include ./include/linux/kconfig.h -nostdinc -isystem /usr/local/arm/gcc-arm-9.2-2019.12-x86_64-arm-none-linux-gnueabihf/bin/../lib/gcc/arm-none-linux-gnueabihf/9.2.1/include -DDO_DEPS_ONLY -dM ./include/common.h > u-boot.cfg.tmp && { grep 'define CONFIG_' u-boot.cfg.tmp > u-boot.cfg; rm u-boot.cfg.tmp; } || { rm u-boot.cfg.tmp; false; } sed -n -f ./tools/scripts/define2mk.sed u-boot.cfg | while read line; do if [ -n "" ] || ! grep -q "${line%=*}=" include/config/auto.conf; then echo "$line"; fi done > include/autoconf.mk arm-none-linux-gnueabihf-gcc -x c -DDO_DEPS_ONLY -M -MP -Wall -Wstrict-prototypes -Wno-format-security -fno-builtin -ffreestanding -std=gnu11 -fshort-wchar -fno-strict-aliasing -fno-PIE -O2 -fno-stack-protector -fno-delete-null-pointer-checks -fmacro-prefix-map=./= -g -fstack-usage -Wno-format-nonliteral -Werror=date-time -D__KERNEL__ -D__UBOOT__ -D__ARM__ -Wa,-mimplicit-it=always -mthumb -mthumb-interwork -mabi=aapcs-linux -mword-relocations -fno-pic -mno-unaligned-access -ffunction-sections -fdata-sections -fno-common -ffixed-r9 -msoft-float -pipe -Iinclude -I./arch/arm/include -include ./include/linux/kconfig.h -nostdinc -isystem /usr/local/arm/gcc-arm-9.2-2019.12-x86_64-arm-none-linux-gnueabihf/bin/../lib/gcc/arm-none-linux-gnueabihf/9.2.1/include -MQ include/config/auto.conf ./include/common.h > include/autoconf.mk.dep || { rm include/autoconf.mk.dep; false; } touch include/config/auto.conf set -e; : ' CHK include/config/uboot.release'; mkdir -p include/config/; echo "2020.01-stm32mp-r1$(/bin/bash ./scripts/setlocalversion .)" < include/config/auto.conf > include/config/uboot.release.tmp; if [ -r include/config/uboot.release ] && cmp -s include/config/uboot.release include/config/uboot.release.tmp; then rm -f include/config/uboot.release.tmp; else : ' UPD include/config/uboot.release'; mv -f include/config/uboot.release.tmp include/config/uboot.release; fi set -e; : ' CHK include/generated/version_autogenerated.h'; mkdir -p include/generated/; (echo \#define PLAIN_VERSION \"2020.01-stm32mp-r1""\"; echo \#define U_BOOT_VERSION \"U-Boot \" PLAIN_VERSION; echo \#define CC_VERSION_STRING \"$(LC_ALL=C arm-none-linux-gnueabihf-gcc --version | head -n 1)\"; echo \#define LD_VERSION_STRING \"$(LC_ALL=C arm-none-linux-gnueabihf-ld.bfd --version | head -n 1)\"; ) < include/config/uboot.release > include/generated/version_autogenerated.h.tmp; if [ -r include/generated/version_autogenerated.h ] && cmp -s include/generated/version_autogenerated.h include/generated/version_autogenerated.h.tmp; then rm -f include/generated/version_autogenerated.h.tmp; else : ' UPD include/generated/version_autogenerated.h'; mv -f include/generated/version_autogenerated.h.tmp include/generated/version_autogenerated.h; fi set -e; : ' CHK include/generated/timestamp_autogenerated.h'; mkdir -p include/generated/; (if test -n "${SOURCE_DATE_EPOCH}"; then SOURCE_DATE="@${SOURCE_DATE_EPOCH}"; DATE=""; for date in gdate date.gnu date; do ${date} -u -d "${SOURCE_DATE}" >/dev/null 2>&1 && DATE="${date}"; done; if test -n "${DATE}"; then LC_ALL=C ${DATE} -u -d "${SOURCE_DATE}" +'#define U_BOOT_DATE "%b %d %C%y"'; LC_ALL=C ${DATE} -u -d "${SOURCE_DATE}" +'#define U_BOOT_TIME "%T"'; LC_ALL=C ${DATE} -u -d "${SOURCE_DATE}" +'#define U_BOOT_TZ "%z"'; LC_ALL=C ${DATE} -u -d "${SOURCE_DATE}" +'#define U_BOOT_DMI_DATE "%m/%d/%Y"'; LC_ALL=C ${DATE} -u -d "${SOURCE_DATE}" +'#define U_BOOT_BUILD_DATE 0x%Y%m%d'; else return 42; fi; else LC_ALL=C date +'#define U_BOOT_DATE "%b %d %C%y"'; LC_ALL=C date +'#define U_BOOT_TIME "%T"'; LC_ALL=C date +'#define U_BOOT_TZ "%z"'; LC_ALL=C date +'#define U_BOOT_DMI_DATE "%m/%d/%Y"'; LC_ALL=C date +'#define U_BOOT_BUILD_DATE 0x%Y%m%d'; fi) < Makefile > include/generated/timestamp_autogenerated.h.tmp; if [ -r include/generated/timestamp_autogenerated.h ] && cmp -s include/generated/timestamp_autogenerated.h include/generated/timestamp_autogenerated.h.tmp; then rm -f include/generated/timestamp_autogenerated.h.tmp; else : ' UPD include/generated/timestamp_autogenerated.h'; mv -f include/generated/timestamp_autogenerated.h.tmp include/generated/timestamp_autogenerated.h; fi make -f ./scripts/Makefile.build obj=scripts/basic rm -f .tmp_quiet_recordmcount make -f ./scripts/Makefile.build obj=. mkdir -p lib/ arm-none-linux-gnueabihf-gcc -Wp,-MD,lib/.asm-offsets.s.d -nostdinc -isystem /usr/local/arm/gcc-arm-9.2-2019.12-x86_64-arm-none-linux-gnueabihf/bin/../lib/gcc/arm-none-linux-gnueabihf/9.2.1/include -Iinclude -I./arch/arm/include -include ./include/linux/kconfig.h -D__KERNEL__ -D__UBOOT__ -Wall -Wstrict-prototypes -Wno-format-security -fno-builtin -ffreestanding -std=gnu11 -fshort-wchar -fno-strict-aliasing -fno-PIE -Os -fno-stack-protector -fno-delete-null-pointer-checks -fmacro-prefix-map=./= -g -fstack-usage -Wno-format-nonliteral -Werror=date-time -D__ARM__ -Wa,-mimplicit-it=always -mthumb -mthumb-interwork -mabi=aapcs-linux -mword-relocations -fno-pic -mno-unaligned-access -ffunction-sections -fdata-sections -fno-common -ffixed-r9 -msoft-float -pipe -march=armv7-a -D__LINUX_ARM_ARCH__=7 -mtune=generic-armv7-a -I./arch/arm/mach-stm32mp/include -DDO_DEPS_ONLY -D"KBUILD_STR(s)=#s" -D"KBUILD_BASENAME=KBUILD_STR(asm_offsets)" -D"KBUILD_MODNAME=KBUILD_STR(asm_offsets)" -fverbose-asm -S -o lib/asm-offsets.s lib/asm-offsets.c set -e; : ' CHK include/generated/generic-asm-offsets.h'; mkdir -p include/generated/; (set -e; echo "#ifndef __GENERIC_ASM_OFFSETS_H__"; echo "#define __GENERIC_ASM_OFFSETS_H__"; echo "/*"; echo " * DO NOT MODIFY."; echo " *"; echo " * This file was generated by Kbuild"; echo " */"; echo ""; sed -ne "s:[[:space:]]*\.ascii[[:space:]]*\"\(.*\)\":\1:; /^->/{s:->#\(.*\):/* \1 */:; s:^->\([^ ]*\) [\$#]*\([-0-9]*\) \(.*\):#define \1 \2 /* \3 */:; s:^->\([^ ]*\) [\$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; s:->::; p;}"; echo ""; echo "#endif" ) < lib/asm-offsets.s > include/generated/generic-asm-offsets.h.tmp; if [ -r include/generated/generic-asm-offsets.h ] && cmp -s include/generated/generic-asm-offsets.h include/generated/generic-asm-offsets.h.tmp; then rm -f include/generated/generic-asm-offsets.h.tmp; else : ' UPD include/generated/generic-asm-offsets.h'; mv -f include/generated/generic-asm-offsets.h.tmp include/generated/generic-asm-offsets.h; fi mkdir -p arch/arm/lib/ arm-none-linux-gnueabihf-gcc -Wp,-MD,arch/arm/lib/.asm-offsets.s.d -nostdinc -isystem /usr/local/arm/gcc-arm-9.2-2019.12-x86_64-arm-none-linux-gnueabihf/bin/../lib/gcc/arm-none-linux-gnueabihf/9.2.1/include -Iinclude -I./arch/arm/include -include ./include/linux/kconfig.h -D__KERNEL__ -D__UBOOT__ -Wall -Wstrict-prototypes -Wno-format-security -fno-builtin -ffreestanding -std=gnu11 -fshort-wchar -fno-strict-aliasing -fno-PIE -Os -fno-stack-protector -fno-delete-null-pointer-checks -fmacro-prefix-map=./= -g -fstack-usage -Wno-format-nonliteral -Werror=date-time -D__ARM__ -Wa,-mimplicit-it=always -mthumb -mthumb-interwork -mabi=aapcs-linux -mword-relocations -fno-pic -mno-unaligned-access -ffunction-sections -fdata-sections -fno-common -ffixed-r9 -msoft-float -pipe -march=armv7-a -D__LINUX_ARM_ARCH__=7 -mtune=generic-armv7-a -I./arch/arm/mach-stm32mp/include -DDO_DEPS_ONLY -D"KBUILD_STR(s)=#s" -D"KBUILD_BASENAME=KBUILD_STR(asm_offsets)" -D"KBUILD_MODNAME=KBUILD_STR(asm_offsets)" -fverbose-asm -S -o arch/arm/lib/asm-offsets.s arch/arm/lib/asm-offsets.c set -e; : ' CHK include/generated/asm-offsets.h'; mkdir -p include/generated/; (set -e; echo "#ifndef __ASM_OFFSETS_H__"; echo "#define __ASM_OFFSETS_H__"; echo "/*"; echo " * DO NOT MODIFY."; echo " *"; echo " * This file was generated by Kbuild"; echo " */"; echo ""; sed -ne "s:[[:space:]]*\.ascii[[:space:]]*\"\(.*\)\":\1:; /^->/{s:->#\(.*\):/* \1 */:; s:^->\([^ ]*\) [\$#]*\([-0-9]*\) \(.*\):#define \1 \2 /* \3 */:; s:^->\([^ ]*\) [\$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; s:->::; p;}"; echo ""; echo "#endif" ) < arch/arm/lib/asm-offsets.s > include/generated/asm-offsets.h.tmp; if [ -r include/generated/asm-offsets.h ] && cmp -s include/generated/asm-offsets.h include/generated/asm-offsets.h.tmp; then rm -f include/generated/asm-offsets.h.tmp; else : ' UPD include/generated/asm-offsets.h'; mv -f include/generated/asm-offsets.h.tmp include/generated/asm-offsets.h; fi
06-13
/** ****************************************************************************** * @file stm32f4xx_hal_pwr.h * @author MCD Application Team * @brief Header file of PWR HAL module. ****************************************************************************** * @attention * * <h2><center>© Copyright (c) 2017 STMicroelectronics. * All rights reserved.</center></h2> * * This software component is licensed by ST under BSD 3-Clause license, * the "License"; You may not use this file except in compliance with the * License. You may obtain a copy of the License at: * opensource.org/licenses/BSD-3-Clause * ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __STM32F4xx_HAL_PWR_H #define __STM32F4xx_HAL_PWR_H #ifdef __cplusplus extern "C" { #endif /* Includes ------------------------------------------------------------------*/ #include "stm32f4xx_hal_def.h" /** @addtogroup STM32F4xx_HAL_Driver * @{ */ /** @addtogroup PWR * @{ */ /* Exported types ------------------------------------------------------------*/ /** @defgroup PWR_Exported_Types PWR Exported Types * @{ */ /** * @brief PWR PVD configuration structure definition */ typedef struct { uint32_t PVDLevel; /*!< PVDLevel: Specifies the PVD detection level. This parameter can be a value of @ref PWR_PVD_detection_level */ uint32_t Mode; /*!< Mode: Specifies the operating mode for the selected pins. This parameter can be a value of @ref PWR_PVD_Mode */ }PWR_PVDTypeDef; /** * @} */ /* Exported constants --------------------------------------------------------*/ /** @defgroup PWR_Exported_Constants PWR Exported Constants * @{ */ /** @defgroup PWR_WakeUp_Pins PWR WakeUp Pins * @{ */ #define PWR_WAKEUP_PIN1 0x00000100U /** * @} */ /** @defgroup PWR_PVD_detection_level PWR PVD detection level * @{ */ #define PWR_PVDLEVEL_0 PWR_CR_PLS_LEV0 #define PWR_PVDLEVEL_1 PWR_CR_PLS_LEV1 #define PWR_PVDLEVEL_2 PWR_CR_PLS_LEV2 #define PWR_PVDLEVEL_3 PWR_CR_PLS_LEV3 #define PWR_PVDLEVEL_4 PWR_CR_PLS_LEV4 #define PWR_PVDLEVEL_5 PWR_CR_PLS_LEV5 #define PWR_PVDLEVEL_6 PWR_CR_PLS_LEV6 #define PWR_PVDLEVEL_7 PWR_CR_PLS_LEV7/* External input analog voltage (Compare internally to VREFINT) */ /** * @} */ /** @defgroup PWR_PVD_Mode PWR PVD Mode * @{ */ #define PWR_PVD_MODE_NORMAL 0x00000000U /*!< basic mode is used */ #define PWR_PVD_MODE_IT_RISING 0x00010001U /*!< External Interrupt Mode with Rising edge trigger detection */ #define PWR_PVD_MODE_IT_FALLING 0x00010002U /*!< External Interrupt Mode with Falling edge trigger detection */ #define PWR_PVD_MODE_IT_RISING_FALLING 0x00010003U /*!< External Interrupt Mode with Rising/Falling edge trigger detection */ #define PWR_PVD_MODE_EVENT_RISING 0x00020001U /*!< Event Mode with Rising edge trigger detection */ #define PWR_PVD_MODE_EVENT_FALLING 0x00020002U /*!< Event Mode with Falling edge trigger detection */ #define PWR_PVD_MODE_EVENT_RISING_FALLING 0x00020003U /*!< Event Mode with Rising/Falling edge trigger detection */ /** * @} */ /** @defgroup PWR_Regulator_state_in_STOP_mode PWR Regulator state in SLEEP/STOP mode * @{ */ #define PWR_MAINREGULATOR_ON 0x00000000U #define PWR_LOWPOWERREGULATOR_ON PWR_CR_LPDS /** * @} */ /** @defgroup PWR_SLEEP_mode_entry PWR SLEEP mode entry * @{ */ #define PWR_SLEEPENTRY_WFI ((uint8_t)0x01) #define PWR_SLEEPENTRY_WFE ((uint8_t)0x02) /** * @} */ /** @defgroup PWR_STOP_mode_entry PWR STOP mode entry * @{ */ #define PWR_STOPENTRY_WFI ((uint8_t)0x01) #define PWR_STOPENTRY_WFE ((uint8_t)0x02) /** * @} */ /** @defgroup PWR_Flag PWR Flag * @{ */ #define PWR_FLAG_WU PWR_CSR_WUF #define PWR_FLAG_SB PWR_CSR_SBF #define PWR_FLAG_PVDO PWR_CSR_PVDO #define PWR_FLAG_BRR PWR_CSR_BRR #define PWR_FLAG_VOSRDY PWR_CSR_VOSRDY /** * @} */ /** * @} */ /* Exported macro ------------------------------------------------------------*/ /** @defgroup PWR_Exported_Macro PWR Exported Macro * @{ */ /** @brief Check PWR flag is set or not. * @param __FLAG__ specifies the flag to check. * This parameter can be one of the following values: * @arg PWR_FLAG_WU: Wake Up flag. This flag indicates that a wakeup event * was received from the WKUP pin or from the RTC alarm (Alarm A * or Alarm B), RTC Tamper event, RTC TimeStamp event or RTC Wakeup. * An additional wakeup event is detected if the WKUP pin is enabled * (by setting the EWUP bit) when the WKUP pin level is already high. * @arg PWR_FLAG_SB: StandBy flag. This flag indicates that the system was * resumed from StandBy mode. * @arg PWR_FLAG_PVDO: PVD Output. This flag is valid only if PVD is enabled * by the HAL_PWR_EnablePVD() function. The PVD is stopped by Standby mode * For this reason, this bit is equal to 0 after Standby or reset * until the PVDE bit is set. * @arg PWR_FLAG_BRR: Backup regulator ready flag. This bit is not reset * when the device wakes up from Standby mode or by a system reset * or power reset. * @arg PWR_FLAG_VOSRDY: This flag indicates that the Regulator voltage * scaling output selection is ready. * @retval The new state of __FLAG__ (TRUE or FALSE). */ #define __HAL_PWR_GET_FLAG(__FLAG__) ((PWR->CSR & (__FLAG__)) == (__FLAG__)) /** @brief Clear the PWR's pending flags. * @param __FLAG__ specifies the flag to clear. * This parameter can be one of the following values: * @arg PWR_FLAG_WU: Wake Up flag * @arg PWR_FLAG_SB: StandBy flag */ #define __HAL_PWR_CLEAR_FLAG(__FLAG__) (PWR->CR |= (__FLAG__) << 2U) /** * @brief Enable the PVD Exti Line 16. * @retval None. */ #define __HAL_PWR_PVD_EXTI_ENABLE_IT() (EXTI->IMR |= (PWR_EXTI_LINE_PVD)) /** * @brief Disable the PVD EXTI Line 16. * @retval None. */ #define __HAL_PWR_PVD_EXTI_DISABLE_IT() (EXTI->IMR &= ~(PWR_EXTI_LINE_PVD)) /** * @brief Enable event on PVD Exti Line 16. * @retval None. */ #define __HAL_PWR_PVD_EXTI_ENABLE_EVENT() (EXTI->EMR |= (PWR_EXTI_LINE_PVD)) /** * @brief Disable event on PVD Exti Line 16. * @retval None. */ #define __HAL_PWR_PVD_EXTI_DISABLE_EVENT() (EXTI->EMR &= ~(PWR_EXTI_LINE_PVD)) /** * @brief Enable the PVD Extended Interrupt Rising Trigger. * @retval None. */ #define __HAL_PWR_PVD_EXTI_ENABLE_RISING_EDGE() SET_BIT(EXTI->RTSR, PWR_EXTI_LINE_PVD) /** * @brief Disable the PVD Extended Interrupt Rising Trigger. * @retval None. */ #define __HAL_PWR_PVD_EXTI_DISABLE_RISING_EDGE() CLEAR_BIT(EXTI->RTSR, PWR_EXTI_LINE_PVD) /** * @brief Enable the PVD Extended Interrupt Falling Trigger. * @retval None. */ #define __HAL_PWR_PVD_EXTI_ENABLE_FALLING_EDGE() SET_BIT(EXTI->FTSR, PWR_EXTI_LINE_PVD) /** * @brief Disable the PVD Extended Interrupt Falling Trigger. * @retval None. */ #define __HAL_PWR_PVD_EXTI_DISABLE_FALLING_EDGE() CLEAR_BIT(EXTI->FTSR, PWR_EXTI_LINE_PVD) /** * @brief PVD EXTI line configuration: set rising & falling edge trigger. * @retval None. */ #define __HAL_PWR_PVD_EXTI_ENABLE_RISING_FALLING_EDGE() do{__HAL_PWR_PVD_EXTI_ENABLE_RISING_EDGE();\ __HAL_PWR_PVD_EXTI_ENABLE_FALLING_EDGE();\ }while(0U) /** * @brief Disable the PVD Extended Interrupt Rising & Falling Trigger. * This parameter can be: * @retval None. */ #define __HAL_PWR_PVD_EXTI_DISABLE_RISING_FALLING_EDGE() do{__HAL_PWR_PVD_EXTI_DISABLE_RISING_EDGE();\ __HAL_PWR_PVD_EXTI_DISABLE_FALLING_EDGE();\ }while(0U) /** * @brief checks whether the specified PVD Exti interrupt flag is set or not. * @retval EXTI PVD Line Status. */ #define __HAL_PWR_PVD_EXTI_GET_FLAG() (EXTI->PR & (PWR_EXTI_LINE_PVD)) /** * @brief Clear the PVD Exti flag. * @retval None. */ #define __HAL_PWR_PVD_EXTI_CLEAR_FLAG() (EXTI->PR = (PWR_EXTI_LINE_PVD)) /** * @brief Generates a Software interrupt on PVD EXTI line. * @retval None */ #define __HAL_PWR_PVD_EXTI_GENERATE_SWIT() (EXTI->SWIER |= (PWR_EXTI_LINE_PVD)) /** * @} */ /* Include PWR HAL Extension module */ #include "stm32f4xx_hal_pwr_ex.h" /* Exported functions --------------------------------------------------------*/ /** @addtogroup PWR_Exported_Functions PWR Exported Functions * @{ */ /** @addtogroup PWR_Exported_Functions_Group1 Initialization and de-initialization functions * @{ */ /* Initialization and de-initialization functions *****************************/ void HAL_PWR_DeInit(void); void HAL_PWR_EnableBkUpAccess(void); void HAL_PWR_DisableBkUpAccess(void); /** * @} */ /** @addtogroup PWR_Exported_Functions_Group2 Peripheral Control functions * @{ */ /* Peripheral Control functions **********************************************/ /* PVD configuration */ void HAL_PWR_ConfigPVD(PWR_PVDTypeDef *sConfigPVD); void HAL_PWR_EnablePVD(void); void HAL_PWR_DisablePVD(void); /* WakeUp pins configuration */ void HAL_PWR_EnableWakeUpPin(uint32_t WakeUpPinx); void HAL_PWR_DisableWakeUpPin(uint32_t WakeUpPinx); /* Low Power modes entry */ void HAL_PWR_EnterSTOPMode(uint32_t Regulator, uint8_t STOPEntry); void HAL_PWR_EnterSLEEPMode(uint32_t Regulator, uint8_t SLEEPEntry); void HAL_PWR_EnterSTANDBYMode(void); /* Power PVD IRQ Handler */ void HAL_PWR_PVD_IRQHandler(void); void HAL_PWR_PVDCallback(void); /* Cortex System Control functions *******************************************/ void HAL_PWR_EnableSleepOnExit(void); void HAL_PWR_DisableSleepOnExit(void); void HAL_PWR_EnableSEVOnPend(void); void HAL_PWR_DisableSEVOnPend(void); /** * @} */ /** * @} */ /* Private types -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ /* Private constants ---------------------------------------------------------*/ /** @defgroup PWR_Private_Constants PWR Private Constants * @{ */ /** @defgroup PWR_PVD_EXTI_Line PWR PVD EXTI Line * @{ */ #define PWR_EXTI_LINE_PVD ((uint32_t)EXTI_IMR_MR16) /*!< External interrupt line 16 Connected to the PVD EXTI Line */ /** * @} */ /** @defgroup PWR_register_alias_address PWR Register alias address * @{ */ /* ------------- PWR registers bit address in the alias region ---------------*/ #define PWR_OFFSET (PWR_BASE - PERIPH_BASE) #define PWR_CR_OFFSET 0x00U #define PWR_CSR_OFFSET 0x04U #define PWR_CR_OFFSET_BB (PWR_OFFSET + PWR_CR_OFFSET) #define PWR_CSR_OFFSET_BB (PWR_OFFSET + PWR_CSR_OFFSET) /** * @} */ /** @defgroup PWR_CR_register_alias PWR CR Register alias address * @{ */ /* --- CR Register ---*/ /* Alias word address of DBP bit */ #define DBP_BIT_NUMBER PWR_CR_DBP_Pos #define CR_DBP_BB (uint32_t)(PERIPH_BB_BASE + (PWR_CR_OFFSET_BB * 32U) + (DBP_BIT_NUMBER * 4U)) /* Alias word address of PVDE bit */ #define PVDE_BIT_NUMBER PWR_CR_PVDE_Pos #define CR_PVDE_BB (uint32_t)(PERIPH_BB_BASE + (PWR_CR_OFFSET_BB * 32U) + (PVDE_BIT_NUMBER * 4U)) /* Alias word address of VOS bit */ #define VOS_BIT_NUMBER PWR_CR_VOS_Pos #define CR_VOS_BB (uint32_t)(PERIPH_BB_BASE + (PWR_CR_OFFSET_BB * 32U) + (VOS_BIT_NUMBER * 4U)) /** * @} */ /** @defgroup PWR_CSR_register_alias PWR CSR Register alias address * @{ */ /* --- CSR Register ---*/ /* Alias word address of EWUP bit */ #define EWUP_BIT_NUMBER PWR_CSR_EWUP_Pos #define CSR_EWUP_BB (PERIPH_BB_BASE + (PWR_CSR_OFFSET_BB * 32U) + (EWUP_BIT_NUMBER * 4U)) /** * @} */ /** * @} */ /* Private macros ------------------------------------------------------------*/ /** @defgroup PWR_Private_Macros PWR Private Macros * @{ */ /** @defgroup PWR_IS_PWR_Definitions PWR Private macros to check input parameters * @{ */ #define IS_PWR_PVD_LEVEL(LEVEL) (((LEVEL) == PWR_PVDLEVEL_0) || ((LEVEL) == PWR_PVDLEVEL_1)|| \ ((LEVEL) == PWR_PVDLEVEL_2) || ((LEVEL) == PWR_PVDLEVEL_3)|| \ ((LEVEL) == PWR_PVDLEVEL_4) || ((LEVEL) == PWR_PVDLEVEL_5)|| \ ((LEVEL) == PWR_PVDLEVEL_6) || ((LEVEL) == PWR_PVDLEVEL_7)) #define IS_PWR_PVD_MODE(MODE) (((MODE) == PWR_PVD_MODE_IT_RISING)|| ((MODE) == PWR_PVD_MODE_IT_FALLING) || \ ((MODE) == PWR_PVD_MODE_IT_RISING_FALLING) || ((MODE) == PWR_PVD_MODE_EVENT_RISING) || \ ((MODE) == PWR_PVD_MODE_EVENT_FALLING) || ((MODE) == PWR_PVD_MODE_EVENT_RISING_FALLING) || \ ((MODE) == PWR_PVD_MODE_NORMAL)) #define IS_PWR_REGULATOR(REGULATOR) (((REGULATOR) == PWR_MAINREGULATOR_ON) || \ ((REGULATOR) == PWR_LOWPOWERREGULATOR_ON)) #define IS_PWR_SLEEP_ENTRY(ENTRY) (((ENTRY) == PWR_SLEEPENTRY_WFI) || ((ENTRY) == PWR_SLEEPENTRY_WFE)) #define IS_PWR_STOP_ENTRY(ENTRY) (((ENTRY) == PWR_STOPENTRY_WFI) || ((ENTRY) == PWR_STOPENTRY_WFE)) /** * @} */ /** * @} */ /** * @} */ /** * @} */ #ifdef __cplusplus } #endif #endif /* __STM32F4xx_HAL_PWR_H */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
08-23
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值