Prof. Zhou Ligong's new book "Programming for AMetal Frameworks and Interfaces (Part 1)" introduces the AMetal framework in detail. By reading this book, you can learn highly multiplexed software design principles and development ideas for interface programming. Focus on your own "core domain", change your own programming thinking, and achieve common progress between the company and the individual.
The seventh chapter is for general-purpose interface programming . The content of this article is 7.7 digital tube and matrix keyboard combined, 7.8 ZLG72128 - digital tube and keyboard management, 7.9 thermostat.
7.7 Digital tube combined with matrix keyboard
The bit selection pins of the digital tube are PIO0_17 and PIO0_23, and the column line pins of the matrix keyboard are also PIO0_17 and PIO0_23. When the digital tube and the matrix keyboard are used at the same time, the bit selection pins of the digital tube and the column line of the matrix keyboard are cited. The feet are multiplexed, which is a common hardware circuit design that can save pins.
AMetal provides a combination of digital tube and matrix keyboard driver, which is essentially a simple integration of digital tube driver and matrix keyboard driver, which avoids providing some of the same information in multiple instance information, such as bits in digital tube instance information. The select pin is exactly the same as the column line pin in the matrix keyboard instance information.
There are two types of digital tube drivers: GPIO output segment code, which is used separately for MiniPort-View; HC595 output segment code, corresponding to MiniPort-View + MiniPort-595. When used in conjunction with the matrix keyboard, there are two corresponding cases: the GPIO output segment code digital tube and the matrix keyboard are used in combination, corresponding to the MiniPort-View + MiniPort-Key; the HC595 output segment code digital tube and the matrix keyboard are used in combination. , corresponding to MiniPort-View + MiniPort-595 +
MiniPort-Key.
> > > 7.7.1 Digital Tube, Keyboard and I/O Driver
When the MiniPort-View and MiniPort-Key are used in combination, the corresponding driver initialization function prototype (am_miniport_view_key.h) is:
P_dev is a pointer to an instance of type am_miniport_view_key_dev_t;
P_info is a pointer to the instance information of the am_miniport_view_key_info_t type.
Instance
The am_miniport_view_key_dev_t type (am_miniport_view_key.h) instance is defined as follows:
Among them, miniport_view_key is a user-defined instance whose address is passed as an argument to p_dev.
2. Instance information
The definition of the type of instance information associated with the digital tube, matrix keyboard, am_miniport_view_key_info_t (am_miniport_view_key.h) is as follows:
Among them, scan_info is the digital tube instance information of the am_digitron_scan_gpio_info_t type (GPIO output segment code), and its corresponding definition is only related to the digital tube related information. See Listing 7.49 for details, without any changes.
Key_info is the basic information of the matrix keyboard of type am_key_matrix_base_info_t, which is defined in the instance information of the matrix keyboard. See Listing 7.35 for details.
In the definition of the previous matrix keyboard instance information, in addition to the basic information of the am_key_matrix_base_info_t type, the row line pin information specified by p_pins_row and the column line pin information specified by p_pins_col are included, but when the digital tube and the matrix keyboard are used simultaneously, The column line pins of the matrix keyboard are the same as the bit selection pins of the nixie tube. Therefore, it is no longer necessary to specify the column line pins of the matrix keyboard. You only need to use p_pins_row to specify the row line pins, combined with the previously defined digital For instance information and matrix keyboard information, you can define the instance information corresponding to the MiniPort-View+MiniPort-Key device as follows:
Based on the instance and instance information, the initialization of the digital tube instance can be completed:
It will complete the initialization of the digital tube and buttons at the same time. When the initialization is completed, the digital tube and buttons can be operated using the universal digital tube interface and the universal button interface. Based on the modular programming idea, the definitions of initialization related instances and instance information are stored in the configuration file of the digital tube. See Listing 7.25 and Listing 7.56 for details.
Listing 7.25 Digital tube, button joint use instance initialization function implementation (am_hwconf_miniport_view_key.c)
Listing 7.56 Digital tube, button joint use instance initialization function declaration (am_hwconf_miniport_view_key.h)
Subsequently just use the parameterless instance initialization function, you can execute the following statement to complete the initialization of the MiniPort-View + MiniPort-Key instance:
When the initialization is completed, the digital tube and buttons can be operated using the universal digital tube interface and the universal button interface.
> > > 7.7.2 Digital Tube, Keyboard and HC595 Driver
When the MiniPort-View, MiniPort-Key, and MiniPort-595 are used in combination, the corresponding driver initialization function prototype (am_miniport_view_key_595.h) is:
P_dev is a pointer to an instance of type am_miniport_view_key_595_dev_t;
P_info is a pointer to the instance information of the am_miniport_view_key_595_info_t type.
Instance
The am_miniport_view_key_595_dev_t type (am_miniport_view_key_595.h) instance is defined as follows:
Among them, miniport_view_key_595 is a user-defined instance whose address is passed as an argument to p_dev.
2. Instance information
The definition of the type am_miniport_view_key_595_info_t (am_miniport_view_key_595.h) describing the instance information associated with the nixie and matrix keyboards is as follows:
The only difference is that the type of the scan_info member of the digital tube information has changed from am_digitron_scan_gpio_info_t to am_digitron_scan_hc595_gpio_info_t, and the rest of the information remains unchanged. Because their hardware difference is only one using GPIO output segment code, one using 595 output segment code, so the instance information is only a little difference in digital tube information.
The instance information corresponding to the MiniPort-View + MiniPort-Key + MiniPort-595 device is defined as follows:
3. HC595 handle handle
If you use the Miniport-595 output code segment, you should obtain the handle of the HC595 through the instance initialization function of MiniPort-595. which is:
The HC595 handle can be passed directly as an argument to the handle.
The initialization of the MiniPort-View + MiniPort-Key + MiniPort-595 device instance can be completed based on the instance, instance information, and HC595 handle. such as:
When the initialization is complete, you can use the universal digital tube and button interface to operate the digital tube and buttons. Based on the modular programming idea, the definitions of initialization related instances and instance information are stored in the configuration file of the digital tube, and the related content is added to the am_hwconf_miniport_view_key.c file. At the same time, the declaration of the instance initialization function is added to the am_hwconf_miniport_view_key.h file, as shown in Listing 7.57 and Listing 7.58.
Listing 7.57 Instance initialization function implementation (am_hwconf_miniport_view_key.c)
Listing 7.58 am_hwconf_miniport_view_key.h file update
Subsequently, just use the parameterless instance initialization function, you can execute the following statement to complete the initialization of the MiniPort-View + MiniPort-Key + MiniPort-595 device instance:
When the initialization is complete, you can use the universal digital tube and button interface to operate the digital tube and buttons.
The introduction of the Miniport series of boards in various combinations shows that the MiniPort series of boards can be used flexibly. For the user, for different matching methods, only need to use the corresponding instance initialization function, without concern for the underlying details, the application programming using the digital tube and the button universal interface can always remain unchanged. For ease of querying, Table 7.9 lists the instance initialization functions that MiniPort-View, MiniPort-Key, and MiniPort-595 boards should use in various combinations.
Table 7.9 Instance initialization functions that should be used in various combinations
Table 7.9 shows a total of 5 ways to use, each method corresponds to one line. If the corresponding cell content of the board is “â—â€, it means that the board will be used in this mode, if only one board is selected. , means that the method uses the board alone.
7.8 ZLG72128 - Digital Tube and Keyboard Management
> > > 7.8.1 Introduction to ZLG72128
When the matrix keyboard and digital tube are expanded to a certain number, it will occupy the I/O resources of the system. At the same time, it also needs the software to execute the button and digital tube scanning. The cost of CPU resources can not be ignored. In practical applications, all 32 buttons or 12 digital tubes may not be used, and can be tailored according to actual conditions. The ZLG has designed the corresponding MiniPort-ZLG72128 board, which can be directly connected to the AM824-Core. As an example, the MiniPort-ZLG72128 board uses only 2 digital tubes and 4 buttons (2 rows and 2 columns) when the MiniProt-ZLG72128 is used. When connected to the AM824-Core, the equivalent circuit is shown in Figure 7.2.
Figure 7.2 MiniPort-ZLG72128 circuit diagram
Only two of the digital tubes are used. The buttons use the 0th line and the 3rd line (function buttons). There are 4 buttons in each row and two columns. The pin connections of ZLG72128 and LPC824 are shown in Table 7.10.
Table 7.10 Pin Connections of ZLG72128 and LPC824
> > > 7.8.2 ZLG72128 driver
When using the ZLG72128, although the underlying drive mode (I2C bus interface) is completely different from the previous method of using GPIO driver buttons and digital tubes, since AMetal already provides the ZLG72128 driver, the user can ignore the underlying differences. Sex, write applications directly using the universal keyboard interface and the universal digital tube interface.
ZLG has designed the corresponding MiniPort-ZLG72128 board, which can be directly connected to the AM824-Core. Before using the universal interface and using the digital tube and buttons, you need to use the initialization function to complete the initialization of the device instance. The prototype of its function (am_zlg72128_std.h) is:
This function is used to initialize the ZLG72128 to a standard digital tube and button function. After initialization, the digital tube and button can be operated using the common button and digital tube interface. P_dev is a pointer to an instance of type am_zlg72128_std_dev_t, p_info is a pointer to the instance information of type am_zlg72128_std_devinfo_t, and i2c_handle is an I2C instance handle that communicates with ZLG72128.
(1) Example
An example of defining the am_zlg72128_std_dev_t type (am_zlg72128_std.h) is as follows:
Where g_miniport_zlg72128 is a user-defined instance whose address is passed as an argument to p_dev.
(2) Instance information
The example information mainly describes the information related to ZLG72128, keyboard and digital tube, such as the key code corresponding to the button, the ID of the digital tube display and so on. The definition of its type am_zlg72128_std_devinfo_t(am_zlg72128_std.h) is as follows:
Base_info is the basic information of ZLG72128, and its type (am_zlg72128.h) is defined as follows:
It mainly specifies the pin information associated with ZLG72128, where rst_pin is the reset pin. If the reset pin is not used (fixed to RC power-on reset circuit, no master control is required), the value can be set to - 1. Use_int_pin indicates whether to use the interrupt output pin (KEY_INT) of ZLG72128. If the value is AM_TRUE, it indicates that the interrupt pin is used. At this time, int_pin specifies the pin number connected to the main controller (such as LPC824). The key value of the button will be Obtained in the pin interrupt; if the value is AM_FALSE, it means that the interrupt pin is not used. At this time, interval_ms specifies the time interval for querying the key value. When using the query mode, one pin resource can be saved, but it will also cost extra. CPU resources. When the AM824-Core is connected to the MiniPort-ZLG72128, the corresponding pin connections are shown in Table 7.10. Based on this, each member can be assigned: PIO0_6, AM_TRUE, PIO0_1, 0. Id_info is information about a standard Nixie device that only contains the display ID number. The type definition (am_digitron_dev.h) is as follows:
In the previous driver configuration, set the ID number corresponding to the MiniPort-View to 0. Here, if the MiniPort-ZLG72128 is not used with the MiniPort-View, you can set the ID to 0. In this case, use MiniPort- The ZLG72128 can directly replace the MiniPort-View palette as a new monitor, but the application can continue to use the ID 0 display without any changes. Blink_on_time and blink_off_time respectively specify the time when the digital tube is lit and the time when the digital tube is blinking, so that the flicker effect can be adjusted. Normally, the digital tube flashes at 1 Hz, and the time to turn on and off is set to 500 ms, respectively.
The key_use_row_flags flag specifies which lines are used. The ZLG72128 can support up to 4 lines of buttons, corresponding to COM8~COM11. This value consists of the macro values ​​shown in Table 7.11. When using multiple lines, multiple macro values ​​should be ORed. For the MiniPort-ZLG72128, it uses lines 0 and 3, so the value of key_use_row_flags is:
AM_ZLG72128_STD_KEY_ROW_0| AM_ZLG72128_STD_KEY_ROW_3
Table 7.11 Lines Using Macro Flags
The key_use_col_flags flag specifies which columns are used. The ZLG72128 can support up to 8 columns of buttons, corresponding to COM0 ~ COM7. This value consists of the macro values ​​shown in Table 7.12. When using multiple columns, multiple macro values ​​should be ORed. For the MiniPort-ZLG72128, it uses column 0 and column 1, so the value of key_use_col_flags is:
AM_ZLG72128_STD_KEY_COL_0 | AM_ZLG72128_STD_KEY_COL_1
Table 7.12 Columns Using Macro Flags
P_key_codes points to the array of codes corresponding to the keys of the matrix keyboard. The number of codes is the same as the number of buttons actually used. The MiniPort-ZLG72128 has a total of 2×2 buttons.
When configuring MiniPort-key, set the key code corresponding to MiniPort-key to KEY0 ~ KEY3. If the MiniPort-ZLG72128 is not used with the MiniPort-Key, the key code corresponding to the MiniPort-ZLG72128 is also set to KEY0~KEY3, and the MiniPort-ZLG72128 is used to replace the MiniPort-Key board, but the application does not need to be changed. Num_digitron specifies the number of digital tubes. The MiniPort-ZLG72128 uses only 2 digital tubes, so the value of num_digitron is 2. Based on the above information, the instance information can be defined as follows:
(3) I2C handle i2c_handle
If the I2C1 of the LPC824 is used to communicate with the ZLG72128, the I2C handle can be obtained by the I2C1 instance initialization function am_lpc82x_i2c1_inst_init() of the LPC82x. which is:
The obtained I2C handle can be passed directly as an argument to i2c_handle.
The initialization of the MiniPort-ZLG72128 can be done based on the instance, instance information, and I2C handle. such as:
When the initialization is complete, the universal digital tube interface and the universal button processing interface can be used. Because the standard button processing interface does not distinguish the button according to the normal button and the function button, the third line function button corresponding to the ZLG72128 will also be treated as a general button, and the button press and release will trigger the corresponding button. Processing function. In addition, since the ZLG72128 does not report the release event of the normal button, when the normal button is released, the corresponding button processing function is not triggered. In order to facilitate the configuration of the matrix keyboard (modify instance information). Based on the modular programming idea, the definitions of initialization related instances, instance information, etc. are stored in the corresponding configuration file, and the instance initialization function interface is extracted through the header file. The program examples of the source file and the header file are respectively shown in the program list 7.59 and the program. Listing 7.60.
Listing 7.59 Standalone keyboard instance initialization function implementation (am_hwconf_miniport_zlg72128.c)
Listing 7.60 Standalone keyboard instance initialization function declaration (am_hwconf_miniport_zlg72128.h)
Subsequently only need to use the parameterless instance initialization function to complete the initialization of the MiniPort-ZLG72128 instance, that is, execute the following statement:
Since the key code and the ID number of the digital tube are the same as those of the MiniPort-Key and Miport-View in the configuration information, you can directly replace the MiniPort-Key and MiniPort-View with the MiniPort-ZLG72128, and the application does not need to be modified. For example, you can use the previously written button application and digital tube application to test buttons and digital tubes, as detailed in Listing 7.61.
Listing 7.61 Main program for running buttons and digital tube applications
As you can see, the application does not need to be modified.
7.9 Thermostat
Previously, a simple thermostat was implemented using a custom digital tube, LED, temperature interface, etc. It will now be upgraded, all using a common interface. Modifications are easier, the basic logic remains the same, and only the non-generic interfaces are modified to use the generic interface. See Listing 7.62 for details.
Listing 7.62 implements the thermostat code using a generic interface
Since the universal interface is used, the digital tube and the button are automatically scanned, and it is not necessary to scan at regular intervals. Therefore, the digital tube and the key scan are not executed in the main program.
AL/CU Universal Terminal Block
Cable Terminal Block,Universal Terminal Block,Waterproof Terminal Block,Low Voltage Terminal Block
ZHEJIANG QIANNA ELECTRIC CO.,LTD , https://www.traner-elec.com