Custom Driver Example
Demonstrates adding a custom thermometer sensor driver to the sensor library.
- SDK directory:
apps/sensors/custom_driver
API Features Demonstrated
Platforms
This app works on:
- AMW004 - Zentri Mackerel evaluation board
- AMW106 - Zentri Moray evaluation board
- NXP-SCCK - NXP Secure Cloud Connectivity Kit
Additional hardware required.
Requirements and Prerequisites
This app requires a ZentriOS device, such as an AMW106-E03 (Moray), connected via the I2C interface to a thermometer sensor.
Description
This app demonstrates adding a custom thermometer sensor driver to the sensor library.
The sensor library provides a standard interface to sensors.
Note the main.c file is the same as for the apps/sensors/thermometer app. The underlying hardware drivers may change but the sensor library API remains the same. This allows for easily adding new hardware without restructuring the software.
The custom driver functionality is implemented in:
- drivers/thermo123/thermo123.c: the dummy hardware driver
- drivers/thermo123/sensor_api.c: the hardware driver sensor library interface
- drivers/thermo123/thermo123.mk: the driver library specification
The custom driver is included to the app's build process by adding:
$(NAME)_COMPONENTS := drivers/thermo123
To the project makefile: custom_driver.mk.
Periodically read thermometer sensor data and display on a ZentriOS terminal.
Usage Instructions
Open a ZentriOS serial terminal to the device. See Getting Started, Opening a ZentriOS Terminal.
This app requires no interaction.
Output to the ZentriOS terminal is similar to:
> Starting Custom Thermometer Driver App
Initialisation successful!
Getting data....
Temperature: 25.26 deg C
Getting data....
Temperature: 25.27 deg C
Getting data....
Temperature: 25.26 deg C
Getting data....
Temperature: 25.25 deg C
Getting data....
Temperature: 25.28 deg C
Implementation
zn_app_init
The call to sensor_init configures the sensor.
The call to zn_event_register_periodic registers the periodic event read_data
.
read_data
The call to sensor_has_new_data determines whether new data is ready.
If data is available, sensor_get_data reads the data. The data is formatted and logged to the ZentriOS terminal.
Source Code
See: