1 /*
2  * Copyright (c) 2016, Freescale Semiconductor, Inc.
3  * Copyright 2016-2017 NXP
4  * All rights reserved.
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  */
8 
9 /**
10  * @file sensor_drv.h
11  * @brief The sensor_drv.h file contains sensor state and error definitions.
12  */
13 
14 #ifndef _SENSOR_DRV_H
15 #define _SENSOR_DRV_H
16 
17 #include <stddef.h>
18 #include <stdint.h>
19 #include <stdbool.h>
20 /*******************************************************************************
21  * Definitions
22  ******************************************************************************/
23 /* @brief This enum defines Write flag for the Register Write. */
24 typedef enum EWriteFlags
25 {
26     WRITE_OVERWRITE = 0, /* Overwrite the Register Value.*/
27     WRITE_MASK = 1       /* Read and Mask and OR it with Register content.*/
28 } EWriteFlags_t;
29 
30 /* @brief This enum defines Sensor State. */
31 enum ESensorErrors
32 {
33     SENSOR_ERROR_NONE = 0,
34     SENSOR_ERROR_INVALID_PARAM,
35     SENSOR_ERROR_BAD_ADDRESS,
36     SENSOR_ERROR_INIT,
37     SENSOR_ERROR_WRITE,
38     SENSOR_ERROR_READ,
39 };
40 
41 /* The MAXIMUM number of Sensor Registers possible. */
42 #define SENSOR_MAX_REGISTER_COUNT 128 /* As per 7-Bit address. */
43 
44 /* Used with the RegisterWriteList types as a list terminator */
45 #define __END_WRITE_DATA__            \
46     {                                 \
47         .writeTo = 0xFFFF, .value = 0 \
48     }
49 
50 /* Used with the RegisterReadList types as a list terminator */
51 #define __END_READ_DATA__                 \
52     {                                     \
53         .readFrom = 0xFFFF, .numBytes = 0 \
54     }
55 
56 /* Used with the Sensor Command List types as a list terminator */
57 #define __END_WRITE_CMD__                \
58     {                                    \
59         .writeTo = 0xFFFF, .numBytes = 0 \
60     }
61 
62 /*******************************************************************************
63  * Types
64  ******************************************************************************/
65 /*!
66  * @brief This structure defines the Write command List.
67  */
68 typedef struct
69 {
70     uint16_t writeTo; /* Address where the value is writes to.*/
71     uint8_t value;    /* value. Note that value should be shifted based on the bit position.*/
72     uint8_t mask;     /* mask of the field to be set with given value.*/
73 } registerwritelist_t;
74 
75 /*!
76  * @brief This structure defines the Read command List.
77  */
78 typedef struct
79 {
80     uint16_t readFrom; /* Address where the value is read from .*/
81     uint8_t numBytes;  /* Number of bytes to read.*/
82 } registerreadlist_t;
83 
84 /*!
85  * @brief This structure defines the Block command List.
86  */
87 typedef struct
88 {
89     const uint8_t *pWriteBuffer; /* Buffer containing the bytes to be written. */
90     uint16_t writeTo;            /* Register Address where the bytes are to be written. */
91     uint8_t numBytes;            /* Number of bytes to be written. */
92 } registercommandlist_t;
93 
94 /*!
95  * @brief This is the register idle function type.
96  */
97 typedef void (*registeridlefunction_t)(void *userParam);
98 
99 /*!
100  * @brief This structure defines the device specific info required by register I/O.
101  */
102 typedef struct
103 {
104     registeridlefunction_t idleFunction;
105     void *functionParam;
106     uint8_t deviceInstance;
107 } registerDeviceInfo_t;
108 
109 #endif //_SENSOR_DRV_H
110