• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 
18 #ifndef ANDROID_NFC_HAL_INTERFACE_H
19 #define ANDROID_NFC_HAL_INTERFACE_H
20 
21 #include <stdint.h>
22 #include <strings.h>
23 #include <sys/cdefs.h>
24 #include <sys/types.h>
25 
26 #include <hardware/hardware.h>
27 
28 __BEGIN_DECLS
29 
30 #define NFC_HARDWARE_MODULE_ID "nfc"
31 
32 /*
33  * Begin PN544 specific HAL
34  */
35 #define NFC_PN544_CONTROLLER "pn544"
36 
37 typedef struct nfc_module_t {
38     struct hw_module_t common;
39 } nfc_module_t;
40 
41 /*
42  * PN544 linktypes.
43  * UART
44  * I2C
45  * USB (uses UART DAL)
46  */
47 typedef enum {
48     PN544_LINK_TYPE_UART,
49     PN544_LINK_TYPE_I2C,
50     PN544_LINK_TYPE_USB,
51     PN544_LINK_TYPE_INVALID,
52 } nfc_pn544_linktype;
53 
54 typedef struct {
55     struct hw_device_t common;
56 
57     /* The number of EEPROM registers to write */
58     uint32_t num_eeprom_settings;
59 
60     /* The actual EEPROM settings
61      * For PN544, each EEPROM setting is a 4-byte entry,
62      * of the format [0x00, addr_msb, addr_lsb, value].
63      */
64     uint8_t* eeprom_settings;
65 
66     /* The link type to which the PN544 is connected */
67     nfc_pn544_linktype linktype;
68 
69     /* The device node to which the PN544 is connected */
70     const char* device_node;
71 
72     /* On Crespo we had an I2C issue that would cause us to sometimes read
73      * the I2C slave address (0x57) over the bus. libnfc contains
74      * a hack to ignore this byte and try to read the length byte
75      * again.
76      * Set to 0 to disable the workaround, 1 to enable it.
77      */
78     uint8_t enable_i2c_workaround;
79     /* I2C slave address. Multiple I2C addresses are
80      * possible for PN544 module. Configure address according to
81      * board design.
82      */
83     uint8_t i2c_device_address;
84 } nfc_pn544_device_t;
85 
nfc_pn544_open(const struct hw_module_t * module,nfc_pn544_device_t ** dev)86 static inline int nfc_pn544_open(const struct hw_module_t* module,
87         nfc_pn544_device_t** dev) {
88     return module->methods->open(module, NFC_PN544_CONTROLLER,
89         (struct hw_device_t**) dev);
90 }
91 
nfc_pn544_close(nfc_pn544_device_t * dev)92 static inline int nfc_pn544_close(nfc_pn544_device_t* dev) {
93     return dev->common.close(&dev->common);
94 }
95 /*
96  * End PN544 specific HAL
97  */
98 
99 __END_DECLS
100 
101 #endif // ANDROID_NFC_HAL_INTERFACE_H
102