summaryrefslogtreecommitdiff
authorJerry Cao <jerry.cao@amlogic.com>2010-11-03 17:34:00 (GMT)
committer Jerry Cao <jerry.cao@amlogic.com>2010-11-03 17:34:00 (GMT)
commit54798f72599d0b5c68606078efba02fa8ef004ad (patch)
tree701ce27cda2456909bf50e0c9865fea63c7e29e2
downloadlights-54798f72599d0b5c68606078efba02fa8ef004ad.zip
lights-54798f72599d0b5c68606078efba02fa8ef004ad.tar.gz
lights-54798f72599d0b5c68606078efba02fa8ef004ad.tar.bz2
Backlight initial import
Diffstat
-rw-r--r--Android.mk8
-rw-r--r--lights.c70
2 files changed, 78 insertions, 0 deletions
diff --git a/Android.mk b/Android.mk
new file mode 100644
index 0000000..8a5cf53
--- a/dev/null
+++ b/Android.mk
@@ -0,0 +1,8 @@
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+LOCAL_SRC_FILES := lights.c
+LOCAL_PRELINK_MODULE := false
+LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
+LOCAL_SHARED_LIBRARIES := liblog
+LOCAL_MODULE := lights.amlogic
+include $(BUILD_SHARED_LIBRARY) \ No newline at end of file
diff --git a/lights.c b/lights.c
new file mode 100644
index 0000000..522bf61
--- a/dev/null
+++ b/lights.c
@@ -0,0 +1,70 @@
+#include <stdio.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <hardware/lights.h>
+#include <hardware/hardware.h>
+
+
+#define BACKLIGHT "/sys/class/backlight/aml-bl/brightness"
+static int set_light_backlight(struct light_device_t* dev,
+ struct light_state_t const* state)
+{
+ int nwr, ret, fd;
+ char value[20];
+ int light_level;
+ light_level = 15 - (state->color&0xff)/20;
+
+ fd = open(BACKLIGHT, O_RDWR);
+ nwr = sprintf(value, "%d\n", light_level);
+ ret = write(fd, value, nwr);
+ close(fd);
+
+ return ret;
+}
+
+static int open_lights(const struct hw_module_t* module, char const* name,
+ struct hw_device_t** device)
+{
+ int res = -EINVAL;
+ int (*set_light)(struct light_device_t* dev,
+ struct light_state_t const* state);
+
+ if (strcmp(LIGHT_ID_BACKLIGHT, name) == 0) {
+ struct light_device_t *dev = malloc(sizeof(struct light_device_t));
+ if (!dev) {
+ return res;
+ }
+
+ set_light = set_light_backlight;
+
+ memset(dev, 0, sizeof(*dev));
+ dev->common.tag = HARDWARE_DEVICE_TAG;
+ dev->common.version = 0;
+ dev->common.module = (struct hw_module_t*)module;
+ dev->common.close = NULL;
+ dev->set_light = set_light;
+
+ *device = (struct hw_device_t*)dev;
+ res = 0;
+ }
+ return res;
+}
+
+
+
+
+static struct hw_module_methods_t lights_module_methods = {
+ .open = open_lights,
+};
+const struct hw_module_t HAL_MODULE_INFO_SYM = {
+ .tag = HARDWARE_MODULE_TAG,
+ .version_major = 1,
+ .version_minor = 0,
+ .id = LIGHTS_HARDWARE_MODULE_ID,
+ .name = "lights Module",
+ .author = "",
+ .methods = &lights_module_methods,
+};
+
+