Просмотр исходного кода

[dm][include] fixup loss' header

Signed-off-by: GuEe-GUI <2991707448@qq.com>
GuEe-GUI 3 недель назад
Родитель
Сommit
9370f81ad7

+ 73 - 0
components/drivers/include/drivers/backlight.h

@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2006-2023, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2023-02-25     GuEe-GUI     the first version
+ */
+
+#ifndef __BACKLIGHT_H__
+#define __BACKLIGHT_H__
+
+#include <rthw.h>
+#include <rtdef.h>
+
+struct rt_backlight_ops;
+
+enum rt_backlight_power
+{
+    RT_BACKLIGHT_POWER_UNBLANK,
+    RT_BACKLIGHT_POWER_NORMAL,
+    RT_BACKLIGHT_POWER_SUSPEND,
+    RT_BACKLIGHT_POWER_POWERDOWN,
+
+    RT_BACKLIGHT_POWER_NR,
+};
+
+struct rt_backlight_properties
+{
+    rt_uint32_t brightness;
+    rt_uint32_t max_brightness;
+
+    enum rt_backlight_power power;
+};
+
+struct rt_backlight_device
+{
+    struct rt_device parent;
+
+    struct rt_backlight_properties props;
+
+    const struct rt_backlight_ops *ops;
+
+    struct rt_mutex lock;
+    void *priv;
+};
+
+struct rt_backlight_ops
+{
+    rt_err_t (*update_status)(struct rt_backlight_device *);
+    rt_err_t (*get_brightness)(struct rt_backlight_device *, rt_uint32_t *out_brightness);
+};
+
+rt_err_t rt_backlight_register(struct rt_backlight_device *bl);
+rt_err_t rt_backlight_unregister(struct rt_backlight_device *bl);
+
+rt_err_t rt_backlight_set_power(struct rt_backlight_device *bl, enum rt_backlight_power power);
+rt_err_t rt_backlight_get_power(struct rt_backlight_device *bl, enum rt_backlight_power *out_power);
+rt_err_t rt_backlight_set_brightness(struct rt_backlight_device *bl, rt_uint32_t brightness);
+rt_err_t rt_backlight_get_brightness(struct rt_backlight_device *bl, rt_uint32_t *out_brightness);
+
+rt_inline rt_uint32_t rt_backlight_power_brightness(struct rt_backlight_device *bl)
+{
+    if (bl->props.power != RT_BACKLIGHT_POWER_UNBLANK)
+    {
+        return 0;
+    }
+
+    return bl->props.brightness;
+}
+
+#endif /* __BACKLIGHT_H__ */

+ 153 - 0
components/drivers/include/drivers/input.h

@@ -0,0 +1,153 @@
+/*
+ * Copyright (c) 2006-2022, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2022-3-08      GuEe-GUI     the first version
+ */
+
+#ifndef __INPUT_H__
+#define __INPUT_H__
+
+#include <rtthread.h>
+
+#include <bitmap.h>
+#include <drivers/dev_touch.h>
+#include <dt-bindings/input/event-codes.h>
+
+struct rt_input_poller;
+struct rt_input_absinfo;
+
+struct rt_input_event
+{
+    rt_tick_t tick;
+
+    rt_uint16_t type;
+    rt_uint16_t code;
+    rt_int32_t value;
+};
+
+struct rt_input_device
+{
+    struct rt_device parent;
+
+    RT_BITMAP_DECLARE(cap, EV_CNT);
+    RT_BITMAP_DECLARE(key_map, KEY_CNT);
+    RT_BITMAP_DECLARE(rel_map, REL_CNT);
+    RT_BITMAP_DECLARE(abs_map, ABS_CNT);
+
+    rt_list_t list;
+    rt_list_t handler_nodes;
+    struct rt_spinlock lock;
+
+    rt_err_t (*trigger)(struct rt_input_device *idev,
+            rt_uint16_t type, rt_uint16_t code, rt_int32_t value);
+
+    struct rt_input_poller *poller;
+    struct rt_input_absinfo *absinfo;
+#ifdef RT_INPUT_TOUCHSCREEN
+    void *touch;
+#endif
+#ifdef RT_INPUT_UAPI
+    void *uapi;
+#endif
+};
+
+struct rt_input_handler
+{
+    rt_list_t list;
+    struct rt_input_device *idev;
+
+    rt_bool_t (*identify)(struct rt_input_handler *handler, struct rt_input_device *idev);
+    rt_bool_t (*callback)(struct rt_input_handler *handler, struct rt_input_event *ev);
+
+    void *priv;
+};
+
+struct rt_input_poller
+{
+#define RT_INPUT_POLL_INTERVAL_DEFAULT  17  /* 60fps */
+    rt_uint32_t interval;
+    struct rt_timer timer;
+
+    void (*poll)(struct rt_input_device *idev);
+};
+
+struct rt_input_absinfo
+{
+    rt_int32_t value;
+    rt_int32_t minimum;
+    rt_int32_t maximum;
+    rt_int32_t fuzz;
+    rt_int32_t flat;
+    rt_int32_t resolution;
+};
+
+rt_err_t rt_input_device_register(struct rt_input_device *idev);
+rt_err_t rt_input_device_unregister(struct rt_input_device *idev);
+
+rt_err_t rt_input_set_capability(struct rt_input_device *idev,
+        rt_uint16_t type, rt_uint16_t code);
+
+rt_err_t rt_input_set_absinfo(struct rt_input_device *idev, rt_uint32_t axis,
+        rt_int32_t min, rt_int32_t max, rt_int32_t fuzz, rt_int32_t flat);
+
+rt_err_t rt_input_setup_touch(struct rt_input_device *idev,
+        rt_uint32_t num_slots, struct rt_touch_info *info);
+rt_err_t rt_input_parse_touch_position(struct rt_input_device *idev,
+        rt_uint32_t *out_x, rt_uint32_t *out_y);
+
+rt_err_t rt_input_setup_polling(struct rt_input_device *idev,
+        void (*work)(struct rt_input_device *idev));
+rt_err_t rt_input_set_poll_interval(struct rt_input_device *idev,
+        rt_uint32_t interval_ms);
+
+void rt_input_remove_config(struct rt_input_device *idev);
+
+rt_err_t rt_input_trigger(struct rt_input_device *idev,
+        rt_uint16_t type, rt_uint16_t code, rt_int32_t value);
+
+void rt_input_event(struct rt_input_device *idev,
+        rt_uint16_t type, rt_uint16_t code, rt_int32_t value);
+
+rt_inline void rt_input_report_key(struct rt_input_device *idev,
+        rt_uint16_t code, rt_int32_t value)
+{
+    rt_input_event(idev, EV_KEY, code, !!value);
+}
+
+rt_inline void rt_input_report_rel(struct rt_input_device *idev,
+        rt_uint16_t code, rt_int32_t value)
+{
+    rt_input_event(idev, EV_REL, code, value);
+}
+
+rt_inline void rt_input_report_abs(struct rt_input_device *idev,
+        rt_uint16_t code, rt_int32_t value)
+{
+    rt_input_event(idev, EV_ABS, code, value);
+}
+
+rt_inline void rt_input_report_touch_slot(struct rt_input_device *idev,
+        rt_uint32_t slot)
+{
+    rt_input_event(idev, EV_ABS, ABS_MT_SLOT, slot);
+}
+
+rt_bool_t rt_input_report_touch_inactive(struct rt_input_device *idev,
+        rt_bool_t active);
+
+void rt_input_report_touch_position(struct rt_input_device *idev,
+        rt_uint32_t x, rt_uint32_t y, rt_bool_t multitouch);
+
+rt_inline void rt_input_sync(struct rt_input_device *idev)
+{
+    rt_input_event(idev, EV_SYN, SYN_REPORT, 0);
+}
+
+rt_err_t rt_input_add_handler(struct rt_input_handler *handler);
+rt_err_t rt_input_del_handler(struct rt_input_handler *handler);
+
+#endif /* __INPUT_H__ */

+ 67 - 0
components/drivers/include/drivers/input_uapi.h

@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2006-2022, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2022-3-08      GuEe-GUI     the first version
+ */
+
+#ifndef __INPUT_UAPI_H__
+#define __INPUT_UAPI_H__
+
+#include <stdint.h>
+#include <sys/time.h>
+#include <sys/ioctl.h>
+
+#include <dt-bindings/input/event-codes.h>
+
+struct input_event
+{
+    struct timeval time;
+    uint16_t type;
+    uint16_t code;
+    int32_t value;
+};
+
+#define EV_VERSION  0x010001
+
+struct input_id
+{
+    uint16_t bustype;
+    uint16_t vendor;
+    uint16_t product;
+    uint16_t version;
+};
+
+struct input_absinfo
+{
+    int32_t value;
+    int32_t minimum;
+    int32_t maximum;
+    int32_t fuzz;
+    int32_t flat;
+    int32_t resolution;
+};
+
+/* Get driver version */
+#define EVIOCGVERSION           _IOR('E', 0x01, int)
+/* Get device ID */
+#define EVIOCGID                _IOR('E', 0x02, struct input_id)
+
+/* Get device name */
+#define EVIOCGNAME(len)         _IOC(_IOC_READ, 'E', 0x06, len)
+/* Get device properties */
+#define EVIOCGPROP(len)         _IOC(_IOC_READ, 'E', 0x09, len)
+
+/* Get event bits */
+#define EVIOCGBIT(ev, len)      _IOC(_IOC_READ, 'E', 0x20 + (ev), len)
+
+/* Get abs value/limits */
+#define EVIOCGABS(abs)          _IOR('E', 0x40 + (abs), struct input_absinfo)
+
+/* Grab/Release device */
+#define EVIOCGRAB               _IOW('E', 0x90, int)
+
+#endif /* __INPUT_UAPI_H__ */

+ 7 - 0
components/drivers/include/rtdevice.h

@@ -46,6 +46,13 @@ extern "C" {
 #include "drivers/core/power_domain.h"
 #include "drivers/platform.h"
 
+#ifdef RT_USING_GRAPHIC
+#include "drivers/graphic.h"
+#ifdef RT_GRAPHIC_BACKLIGHT
+#include "drivers/backlight.h"
+#endif /* RT_GRAPHIC_BACKLIGHT */
+#endif /* RT_USING_GRAPHIC */
+
 #ifdef RT_USING_ATA
 #ifdef RT_ATA_AHCI
 #include "drivers/ahci.h"