diff options
author | Martijn Coenen <maco@google.com> | 2011-11-02 16:09:37 -0700 |
---|---|---|
committer | Martijn Coenen <maco@google.com> | 2011-11-04 09:05:22 -0700 |
commit | 44ae5b24766f8ce4b6b5de01f1deb296d99efd57 (patch) | |
tree | ab068b7523ac3f71d625c0eeed8996ac6fd2c6a3 | |
parent | cf209523884350a3ad6af5840f1b0ae2dde9b98b (diff) | |
download | hardware_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
-rw-r--r-- | include/hardware/nfc.h | 96 | ||||
-rw-r--r-- | modules/Android.mk | 2 | ||||
-rw-r--r-- | modules/nfc/Android.mk | 25 | ||||
-rw-r--r-- | modules/nfc/nfc_hw_example.c | 70 |
4 files changed, 192 insertions, 1 deletions
diff --git a/include/hardware/nfc.h b/include/hardware/nfc.h new file mode 100644 index 0000000..ca3683b --- /dev/null +++ b/include/hardware/nfc.h @@ -0,0 +1,96 @@ +/* + * 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. + */ + + +#ifndef ANDROID_NFC_HAL_INTERFACE_H +#define ANDROID_NFC_HAL_INTERFACE_H + +#include <stdint.h> +#include <strings.h> +#include <sys/cdefs.h> +#include <sys/types.h> + +#include <hardware/hardware.h> + +__BEGIN_DECLS + +#define NFC_HARDWARE_MODULE_ID "nfc" + +/* + * Begin PN544 specific HAL + */ +#define NFC_PN544_CONTROLLER "pn544" + +typedef struct nfc_module_t { + struct hw_module_t common; +} nfc_module_t; + +/* + * PN544 linktypes. + * UART + * I2C + * USB (uses UART DAL) + */ +typedef enum { + PN544_LINK_TYPE_UART, + PN544_LINK_TYPE_I2C, + PN544_LINK_TYPE_USB, + PN544_LINK_TYPE_INVALID, +} nfc_pn544_linktype; + +typedef struct { + struct hw_device_t common; + + /* The number of EEPROM registers to write */ + uint32_t num_eeprom_settings; + + /* The actual EEPROM settings + * For PN544, each EEPROM setting is a 4-byte entry, + * of the format [0x00, addr_msb, addr_lsb, value]. + */ + uint8_t* eeprom_settings; + + /* The link type to which the PN544 is connected */ + nfc_pn544_linktype linktype; + + /* The device node to which the PN544 is connected */ + const char* device_node; + + /* On Crespo we had an I2C issue that would cause us to sometimes read + * the I2C slave address (0x57) over the bus. libnfc contains + * a hack to ignore this byte and try to read the length byte + * again. + * Set to 0 to disable the workaround, 1 to enable it. + */ + uint8_t enable_i2c_workaround; +} nfc_pn544_device_t; + +static inline int nfc_pn544_open(const struct hw_module_t* module, + nfc_pn544_device_t** dev) { + return module->methods->open(module, NFC_PN544_CONTROLLER, + (struct hw_device_t**) dev); +} + +static inline int nfc_pn544_close(nfc_pn544_device_t* dev) { + return dev->common.close(&dev->common); +} +/* + * End PN544 specific HAL + */ + +__END_DECLS + +#endif // ANDROID_NFC_HAL_INTERFACE_H diff --git a/modules/Android.mk b/modules/Android.mk index 04b9140..6231e78 100644 --- a/modules/Android.mk +++ b/modules/Android.mk @@ -1,2 +1,2 @@ -hardware_modules := gralloc hwcomposer audio +hardware_modules := gralloc hwcomposer audio nfc include $(call all-named-subdir-makefiles,$(hardware_modules)) 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, + }, +}; |