summaryrefslogtreecommitdiffstats
path: root/modules/nfc
diff options
context:
space:
mode:
authorMartijn Coenen <maco@google.com>2011-11-02 16:09:37 -0700
committerMartijn Coenen <maco@google.com>2011-11-04 09:05:22 -0700
commit44ae5b24766f8ce4b6b5de01f1deb296d99efd57 (patch)
treeab068b7523ac3f71d625c0eeed8996ac6fd2c6a3 /modules/nfc
parentcf209523884350a3ad6af5840f1b0ae2dde9b98b (diff)
downloadhardware_libhardware-44ae5b24766f8ce4b6b5de01f1deb296d99efd57.zip
hardware_libhardware-44ae5b24766f8ce4b6b5de01f1deb296d99efd57.tar.gz
hardware_libhardware-44ae5b24766f8ce4b6b5de01f1deb296d99efd57.tar.bz2
New NFC HAL.
First implementation of a NFC HAL. This implementation doesn't offer a generic NFC device HAL (yet), but offers typed interfaces for different NFC controllers. Currently only the PN544 is supported. Change-Id: I3ac04dcd767fb12a433edbe88ec7068eb1930a57
Diffstat (limited to 'modules/nfc')
-rw-r--r--modules/nfc/Android.mk25
-rw-r--r--modules/nfc/nfc_hw_example.c70
2 files changed, 95 insertions, 0 deletions
diff --git a/modules/nfc/Android.mk b/modules/nfc/Android.mk
new file mode 100644
index 0000000..d541b21
--- /dev/null
+++ b/modules/nfc/Android.mk
@@ -0,0 +1,25 @@
+# Copyright (C) 2011 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+
+LOCAL_MODULE := nfc.default
+LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
+LOCAL_SRC_FILES := nfc_hw_example.c
+LOCAL_SHARED_LIBRARIES := liblog libcutils
+LOCAL_MODULE_TAGS := optional
+
+include $(BUILD_SHARED_LIBRARY)
diff --git a/modules/nfc/nfc_hw_example.c b/modules/nfc/nfc_hw_example.c
new file mode 100644
index 0000000..9769282
--- /dev/null
+++ b/modules/nfc/nfc_hw_example.c
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <errno.h>
+#include <string.h>
+
+#include <hardware/hardware.h>
+#include <hardware/nfc.h>
+
+/* Close an opened pn544 device instance */
+static int pn544_close(hw_device_t *dev) {
+ free(dev);
+ return 0;
+}
+
+/*
+ * Generic device handling
+ */
+static int nfc_open(const hw_module_t* module, const char* name,
+ hw_device_t** device) {
+ if (strcmp(name, NFC_PN544_CONTROLLER) == 0) {
+ nfc_pn544_device_t *dev = calloc(1, sizeof(nfc_pn544_device_t));
+
+ dev->common.tag = HARDWARE_DEVICE_TAG;
+ dev->common.version = 0;
+ dev->common.module = (struct hw_module_t*) module;
+ dev->common.close = pn544_close;
+
+ /* Example settings */
+ dev->num_eeprom_settings = 0;
+ dev->eeprom_settings = NULL;
+ dev->linktype = PN544_LINK_TYPE_INVALID;
+ dev->device_node = NULL;
+ dev->enable_i2c_workaround = 0;
+
+ *device = (hw_device_t*) dev;
+ return 0;
+ } else {
+ return -EINVAL;
+ }
+}
+
+
+static struct hw_module_methods_t nfc_module_methods = {
+ .open = nfc_open,
+};
+
+struct nfc_module_t HAL_MODULE_INFO_SYM = {
+ .common = {
+ .tag = HARDWARE_MODULE_TAG,
+ .version_major = 1,
+ .version_minor = 0,
+ .id = NFC_HARDWARE_MODULE_ID,
+ .name = "Default NFC HW HAL",
+ .author = "The Android Open Source Project",
+ .methods = &nfc_module_methods,
+ },
+};