Component Library:Sensor Driver for NMH1000  v1.0
Platform agnostic sensor driver interfaces for NMH1000 sensor
nmh1000_driver.c
Go to the documentation of this file.
1 /*
2  * Copyright 2021 NXP
3  * All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  */
7 
8 /**
9  * @file nmh1000_driver.c
10  * @brief The nmh1000_driver.c file implements the sensor driver interface for nmh1000 sensors.
11 
12  */
13 
14 //-----------------------------------------------------------------------
15 // Includes
16 //-----------------------------------------------------------------------
17 #include "sensor_comm.h"
18 #include "nmh1000_driver.h"
19 
20 #include "sensor_comm.h"
21 #include "sensor_common.h"
22 
23 //-----------------------------------------------------------------------
24 // Global Variables
25 //-----------------------------------------------------------------------
26 
27 //-----------------------------------------------------------------------
28 // Typedefs and macros
29 //-----------------------------------------------------------------------
30 
31 //-----------------------------------------------------------------------
32 // Functions
33 //-----------------------------------------------------------------------
34 
35 /*
36  nmh1000_init
37  */
38 uint8_t nmh1000_init(nmh1000_driver_t *pDriver)
39 {
40  // Initial the sensor driver handler and interfaces
41  if(NULL == pDriver){
42  return SENSOR_INVALIDPARAM_ERR;
43  }
44  uint8_t status = SENSOR_SUCCESS;
45  // initialize the communication channel
46  status = sensor_comm_init(&pDriver->comHandle);
47  if(status != SENSOR_SUCCESS){
48  return status;
49  }
50 
51  status = sensor_comm_read(&pDriver->comHandle, NMH1000_WHO_AM_I, 1 , &pDriver->whoAMI);
52 
53  return status;
54 }
55 /*
56  nmh1000_read_reg
57  */
58 uint8_t nmh1000_read_reg(nmh1000_driver_t *pDriver, uint16_t address, uint8_t *pReadBuffer)
59 {
60 
61  if((NULL == pDriver) || (NULL == pReadBuffer))
62  {
63  return SENSOR_INVALIDPARAM_ERR;
64  }
65  uint8_t status = SENSOR_SUCCESS;
66 
67  status = sensor_comm_read(&pDriver->comHandle, address, 1, pReadBuffer);
68 
69  return status;
70 }
71 /*
72  nmh1000_write_reg
73  */
74 uint8_t nmh1000_write_reg(nmh1000_driver_t *pDriver, uint16_t address, uint8_t data)
75 {
76  if(NULL == pDriver)
77  {
78  return SENSOR_INVALIDPARAM_ERR;
79  }
80  uint8_t status = SENSOR_SUCCESS;
81 
82  status = sensor_comm_write(&pDriver->comHandle, address, 1, &data);
83 
84  return status;
85 }
86 
87 /*
88  nmh1000_get_magnetic_data
89  */
90 uint8_t nmh1000_get_magnetic_data(nmh1000_driver_t *pDriver, uint8_t *pMagData)
91 {
92  if(NULL == pDriver)
93  {
94  return SENSOR_INVALIDPARAM_ERR;
95  }
96  uint8_t status = SENSOR_SUCCESS;
97 
98  status = sensor_comm_read(&pDriver->comHandle, NMH1000_OUT_M_REG, 1, pMagData);
99 
100  return status;
101 }
102 
sensor_comm_handle_t comHandle
uint8_t nmh1000_init(nmh1000_driver_t *pDriver)
The interface function to initialize the nmh1000 sensor.
uint8_t nmh1000_read_reg(nmh1000_driver_t *pDriver, uint16_t address, uint8_t *pReadBuffer)
The interface function read from the nmh1000 sensor register.
uint8_t nmh1000_get_magnetic_data(nmh1000_driver_t *pDriver, uint8_t *pMagData)
The interface function to get magnetic data.
This header contains definitions and interface for the nmh1000 sensor driver.
uint8_t nmh1000_write_reg(nmh1000_driver_t *pDriver, uint16_t address, uint8_t data)
The interface function write to a nmh1000 sensor register.