Mistake on this page?
Report an issue in GitHub or email us
pal_twi.h
Go to the documentation of this file.
1 /*************************************************************************************************/
2 /*!
3  * \file
4  *
5  * \brief TWI driver definition.
6  *
7  * Copyright (c) 2018 ARM Ltd. All Rights Reserved.
8  *
9  * Copyright (c) 2019-2020 Packetcraft, Inc.
10  *
11  * Licensed under the Apache License, Version 2.0 (the "License");
12  * you may not use this file except in compliance with the License.
13  * You may obtain a copy of the License at
14  *
15  * http://www.apache.org/licenses/LICENSE-2.0
16  *
17  * Unless required by applicable law or agreed to in writing, software
18  * distributed under the License is distributed on an "AS IS" BASIS,
19  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  * See the License for the specific language governing permissions and
21  * limitations under the License.
22  */
23 /*************************************************************************************************/
24 
25 #ifndef PAL_TWI_H
26 #define PAL_TWI_H
27 
28 #include "pal_types.h"
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 /*! \addtogroup PAL_TWI
35  * \{ */
36 
37 /**************************************************************************************************
38  Macros
39 **************************************************************************************************/
40 
41 /*! \brief Invalid device ID. */
42 #define PAL_TWI_INVALID_ID 0xFF
43 
44 /**************************************************************************************************
45  Data Types
46 **************************************************************************************************/
47 
48 /*! \brief Operation ready callback. */
49 typedef void (*PalTwiOpReadyCback_t)(uint8_t id);
50 
51 /*! \brief Completion callback (success=TRUE if ACK received, FALSE otherwise). */
52 typedef void (*PalTwiCompCback_t)(uint8_t id, bool_t success);
53 
54 /*! \brief TWI device configuration. */
55 typedef struct
56 {
57  uint8_t devAddr; /*!< Device address. */
58  PalTwiOpReadyCback_t opReadyCback; /*!< Operation ready callback. */
59  PalTwiCompCback_t rdCback; /*!< Read data completion callback. */
60  PalTwiCompCback_t wrCback; /*!< Write data completion callback. */
62 
63 /*! \brief Operational states. */
64 typedef enum
65 {
66  PAL_TWI_STATE_UNINIT = 0, /*!< Uninitialized state. */
67  PAL_TWI_STATE_ERROR = 0, /*!< Error state. */
68  PAL_TWI_STATE_READY, /*!< Ready state. */
69  PAL_TWI_STATE_BUSY_DATA_PEND, /*!< Busy state (operation in progress), Data pending substate. */
70  PAL_TWI_STATE_BUSY_DATA_XFER /*!< Busy state (operation in progress), Data transfer substate. */
72 
73 /**************************************************************************************************
74  Function Declarations
75 **************************************************************************************************/
76 
77 /* Initialization */
78 void PalTwiInit(void);
79 void PalTwiDeInit(void);
80 uint8_t PalTwiRegisterDevice(PalTwiDevConfig_t *pDevCfg);
81 
82 /* Control and Status */
83 PalTwiState_t PalTwiGetState(void);
84 
85 /* Data Transfer */
86 void PalTwiStartOperation(uint8_t id);
87 void PalTwiStopOperation(uint8_t id);
88 void PalTwiReadData(uint8_t id, uint8_t *pData, uint8_t len);
89 void PalTwiWriteData(uint8_t id, const uint8_t *pData, uint8_t len);
90 
91 /*! \} */ /* PAL_TWI */
92 
93 #ifdef __cplusplus
94 };
95 #endif
96 
97 #endif /* PAL_TWI_H */
TWI device configuration.
Definition: pal_twi.h:55
PalTwiCompCback_t rdCback
Definition: pal_twi.h:59
void(* PalTwiOpReadyCback_t)(uint8_t id)
Operation ready callback.
Definition: pal_twi.h:49
PalTwiOpReadyCback_t opReadyCback
Definition: pal_twi.h:58
PalTwiState_t
Operational states.
Definition: pal_twi.h:64
PalTwiCompCback_t wrCback
Definition: pal_twi.h:60
uint8_t devAddr
Definition: pal_twi.h:57
Platform-independent data types.
void(* PalTwiCompCback_t)(uint8_t id, uint8_t success)
Completion callback (success=TRUE if ACK received, FALSE otherwise).
Definition: pal_twi.h:52
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.