From b63c840b3f1b2ac34862f2d77ad20e92c050b88a Mon Sep 17 00:00:00 2001 From: codeworkx Date: Mon, 25 Jul 2011 10:51:57 -0700 Subject: [PATCH] custom vibrator implementation --- ueventd.smdkv310.rc | 2 +- vibrator/tspdrv.c | 60 +++++++++++++++++++++++++++++++++++++++++++++ vibrator/tspdrv.h | 30 +++++++++++++++++++++++ 3 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 vibrator/tspdrv.c create mode 100644 vibrator/tspdrv.h diff --git a/ueventd.smdkv310.rc b/ueventd.smdkv310.rc index 25bdde2..e1fe818 100644 --- a/ueventd.smdkv310.rc +++ b/ueventd.smdkv310.rc @@ -31,7 +31,7 @@ # for gps /dev/s3c2410_serial1 0660 root system -/dev/tspdrv 0660 shell shell +/dev/tspdrv 0660 system system # for MTP /dev/usb_mtp_gadget 0660 system system diff --git a/vibrator/tspdrv.c b/vibrator/tspdrv.c new file mode 100644 index 0000000..6f218d3 --- /dev/null +++ b/vibrator/tspdrv.c @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2011 CyanogenMod Project + * Copyright (C) 2011 Daniel Hillenbrand + * + * 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 +#include +#include +#include + +#define LOG_NDEBUG 0 +#define LOG_TAG "tspdrv" +#include + +#include "tspdrv.h" + +int sendit(int timeout_ms) +{ + int nwr, ret, fd, tspd, tspret; + char value[20]; + + tspd = open(TSPDRV_DEVICE, O_RDWR); + if(tspd < 0) + LOGE("failed on opening /dev/tspdrv"); + + /* send tspdrv magic number */ + tspret = ioctl(tspd, TSPDRV_MAGIC_NUMBER); + if(tspret != 0) + LOGE("TSPDRV_MAGIC_NUMBER error"); + + /* enable tspdrv amp */ + tspret = ioctl(tspd, TSPDRV_ENABLE_AMP); + if(tspret != 0) + LOGE("failed on enabling AMP"); + + close(tspd); + + fd = open(THE_DEVICE, O_RDWR); + if(fd < 0) + return errno; + + nwr = sprintf(value, "%d\n", timeout_ms); + ret = write(fd, value, nwr); + + close(fd); + + return (ret == nwr) ? 0 : -1; +} diff --git a/vibrator/tspdrv.h b/vibrator/tspdrv.h new file mode 100644 index 0000000..29fdb47 --- /dev/null +++ b/vibrator/tspdrv.h @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2011 CyanogenMod Project + * Copyright (C) 2011 Daniel Hillenbrand + * + * 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 __TSPDRV_H +#define __TSPDRV_H __FILE__ + +#define THE_DEVICE "/sys/class/timed_output/vibrator/enable" +#define TSPDRV_DEVICE "/dev/tspdrv" + +#define TSPDRV_MAGIC_NUMBER 0x494D4D52 +#define TSPDRV_STOP_KERNEL_TIMER _IO(TSPDRV_MAGIC_NUMBER & 0xFF, 1) +#define TSPDRV_ENABLE_AMP _IO(TSPDRV_MAGIC_NUMBER & 0xFF, 3) +#define TSPDRV_DISABLE_AMP _IO(TSPDRV_MAGIC_NUMBER & 0xFF, 4) +#define TSPDRV_GET_NUM_ACTUATORS _IO(TSPDRV_MAGIC_NUMBER & 0xFF, 5) + +#endif /* __TSPDRV_H */