Temperature acquisition interface and keyboard knowledge sharing for general-purpose interface programming

The seventh chapter focuses on programming for the general interface. The content of this section includes 7.4 Temperature Acquisition Interface and 7.5 Keyboard.

7.4 Temperature Acquisition Interface

> > > 7.4.1 Universal Temperature Sensor Interface

AMetal provides a universal interface for temperature acquisition, which includes only one function for reading the current temperature value. The function prototype is (am_temp.h):

In this function, handle represents the handle of the temperature sensor, which can be obtained by initializing a specific sensor like LM75. p_temp is an output parameter that returns the current temperature value. To avoid dealing with fractional operations, a signed 32-bit integer is used. The temperature value is 1000 times the actual value, providing a resolution of 0.001°C. A sample program for reading temperatures is detailed in Listing 7.25.

Listing 7.25 am_temp_read() Sample Program

To use the universal interface for reading temperature, an application must first obtain the handle of the temperature sensor, which requires a driver for the specific sensor.

> > > 7.4.2 LM75B Driver

The LM75B is a digital temperature sensor with an I2C interface from NXP. AMetal provides its corresponding driver, which includes only one initialization function. The function prototype (am_temp_lm75.h) is:

This function initializes the LM75 temperature sensor instance and uses the universal interface to read the temperature. Here, p_lm75 is a pointer to an instance of type am_temp_lm75_t, and p_devinfo is a pointer to the instance information of type am_temp_lm75_info_t.

Instance

An example of defining the am_temp_lm75_t type (am_temp_lm75.h) is as follows:

Where g_temp_lm75 is a user-defined instance whose address is passed to p_lm75.

2. Instance Information

The instance information mainly describes the details of the LM75, such as the I2C slave address. The definition of its type am_temp_lm75_info_t (am_temp_lm75.h) is as follows:

Among them, i2c_addr specifies the 7-bit slave address of the LM75. On the AM824-Core, the onboard LM75 has an address of 0x48. Its instance information is defined as follows:

Once the instance and instance information are set up, the LM75 can be initialized. For example:

After initialization, the general temperature reading interface can be used to get the current temperature value. A sample program for reading and printing the current temperature via the serial port is shown in Listing 7.28.

Listing 7.28 Sample Program for Detecting Current Temperature Using the LM75

7.5 Keyboard

> > > 7.5.1 Universal Keyboard Interface

AMetal provides a universal keyboard interface to decouple button processing from the specific MCU and keyboard configuration. Its function prototype is:

Where p_handler is a pointer to the key event handler, pfn_cb is a pointer to the user-defined key handler, and p_arg is the user parameter.

P_Handler

Am_input_key_handler_t is the type of the button event handler, which is a structure defined using typedef in am_input.h. It is used to define a key event handler instance, which is then passed to the function.

2. Pfn_Cb

Am_input_cb_key_t is the pointer type of the key handler, which is called when a button event occurs. The key code and state are passed to the handler, and the user can define custom actions based on these values.

3. P_Arg

The p_arg parameter is used to pass additional information to the key handler. If not needed, it can be set to NULL.

After registering the key handler, the callback function will be called when a button is pressed or released. Multiple handlers can be registered for different keys, enabling flexible handling of various input events.

> > > 7.5.2 Independent Keyboard Driver

The driver for the independent keyboard provides an initialization function that can be used with the generic interface. Its function prototype is:

The instance information defines the GPIO pins and other parameters for the independent keyboard. By defining the instance and instance information, the keyboard can be initialized and used with the generic interface.

> > > 7.5.3 Matrix Keyboard Driver

Similarly, the matrix keyboard driver provides an initialization function that can be used with the generic interface. Its function prototype is:

The instance information defines the row and column pins, scanning interval, and other parameters for the matrix keyboard. Once initialized, the generic keyboard interface can be used to process the keys.

In practical applications, various types of keyboards exist, including standalone buttons, matrix keyboards, and I2C-based keyboards. AMetal provides drivers for common keyboards, allowing users to focus on application logic without worrying about low-level details.

Automation Light Curtain

This Automation curtain is specially designed for automation industry. SDKELI LSC2 light curtain is designed for automation field, with small size, compact structure and strong anti-interference ability, and the product meets IEC 61496-2 standards. The automatic light curtain is with reliable quality and very competitive price. It has been used in many factories and has replaced curtains from Omron, Banner, Keyence, etc.

Automatic Light Curtain,Laser Light Curtain,Automation Light Beam Sensor,Automatic Infrared Beam Sensor,Infrared Beam Curttain Sensor,Infrared Beam Sensor

Jining Keli Photoelectronic Industrial Co.,Ltd , https://www.sdkelien.com