This commit is contained in:
huxi
2025-12-03 11:12:34 +08:00
parent c23ae4f24c
commit bc195654bf
8163 changed files with 3799544 additions and 92 deletions
+142
View File
@@ -0,0 +1,142 @@
#ifndef _DEBUG_H_
#define _DEBUG_H_
#include "asm/cpu.h"
#include "generic/typedef.h"
#define LOG_ASSERT_ENABLE
void printf_buf(u8 *buf, u32 len);
#define PRINTF(format, ...) printf(format, ## __VA_ARGS__)
#define LOG_VERBOSE v
#define LOG_INFO i
#define LOG_DEBUG d
#define LOG_WARN w
#define LOG_ERROR e
#define LOG_CHAR c
#define _STR(x) #x
#define STR(x) "["_STR(x)"]"
#define _LOG_TAG_CONST_DECLARE(level, name) extern const char log_tag_const_##level##_##name
#define LOG_TAG_CONST_DECLARE(level, name) _LOG_TAG_CONST_DECLARE(level, name)
#define ___LOG_IS_ENABLE(level, name) (log_tag_const_##level##_##name)
#define __LOG_IS_ENABLE(level, name) ___LOG_IS_ENABLE(level, name)
#define _LOG_IS_ENABLE(level) __LOG_IS_ENABLE(level, LOG_TAG_CONST)
#ifdef LOG_TAG_CONST
LOG_TAG_CONST_DECLARE(LOG_VERBOSE, LOG_TAG_CONST);
LOG_TAG_CONST_DECLARE(LOG_INFO, LOG_TAG_CONST);
LOG_TAG_CONST_DECLARE(LOG_DEBUG, LOG_TAG_CONST);
LOG_TAG_CONST_DECLARE(LOG_WARN, LOG_TAG_CONST);
LOG_TAG_CONST_DECLARE(LOG_ERROR, LOG_TAG_CONST);
LOG_TAG_CONST_DECLARE(LOG_CHAR, LOG_TAG_CONST);
#define _LOG_TAG STR(LOG_TAG_CONST)
#define LOG_IS_ENABLE(level) _LOG_IS_ENABLE(level)
#else
#define _LOG_TAG LOG_TAG
#define LOG_IS_ENABLE(x) 1
#endif
#define LOG_BY_MACRO 1
#define LOG_BY_CONST 2
// #define LOG_MODE LOG_BY_MACRO
#define LOG_MODE LOG_BY_CONST
/*
* LOG 通过宏控制
*/
#if (LOG_MODE == LOG_BY_MACRO)
#ifdef LOG_INFO_ENABLE
#define log_info(format, ...) PRINTF("[Info] :" _LOG_TAG format "\r\n", ## __VA_ARGS__)
#else
#define log_info(...)
#endif
#ifdef LOG_DEBUG_ENABLE
#define log_debug(format, ...) PRINTF("[Debug] :" _LOG_TAG format "\r\n", ## __VA_ARGS__)
#define log_debug_hexdump(x, y) printf_buf(x, y)
#else
#define log_debug(...)
#define log_debug_hexdump(x, y)
#endif
#ifdef LOG_ERROR_ENABLE
#define log_error(format, ...) PRINTF("<Error> :" _LOG_TAG format "\r\n", ## __VA_ARGS__)
#define log_error_hexdump(x, y) printf_buf(x, y)
#else
#define log_error(...)
#define log_error_hexdump(...)
#endif
#ifdef LOG_DUMP_ENABLE
#define log_info_hexdump(x,y) printf_buf(x,y)
#else
#define log_info_hexdump(...)
#endif
#ifdef LOG_CHAR_ENABLE
#define log_char(x) putchar(x)
#else
#define log_char(x)
#endif
/*
* LOG 通过常量控制
*/
#elif (LOG_MODE == LOG_BY_CONST)
#define log_info(format, ...) \
if (LOG_IS_ENABLE(LOG_INFO)) \
log_print(__LOG_INFO,NULL,"[Info]: " _LOG_TAG format "\r\n", ## __VA_ARGS__)
#define log_info_hexdump(x, y) \
if (LOG_IS_ENABLE(LOG_INFO)) \
printf_buf(x, y)
#define log_debug(format, ...) \
if (LOG_IS_ENABLE(LOG_DEBUG)) \
log_print(__LOG_DEBUG,NULL,"[Debug]: " _LOG_TAG format "\r\n", ## __VA_ARGS__)
#define log_debug_hexdump(x, y) \
if (LOG_IS_ENABLE(LOG_DEBUG)) \
printf_buf(x, y)
#define log_error(format, ...) \
if (LOG_IS_ENABLE(LOG_ERROR)) \
log_print(__LOG_ERROR,NULL,"<Error>: " _LOG_TAG format "\r\n", ## __VA_ARGS__)
#define log_error_hexdump(x, y) \
if (LOG_IS_ENABLE(LOG_ERROR)) \
printf_buf(x, y)
#define log_char(x) \
if (LOG_IS_ENABLE(LOG_CHAR)) \
putchar(x)
#endif
#define traceSUPER_MODE() \
/*{int icfg, rets, reti; \
__asm__ volatile("%0 = icfg" : "=r"(icfg)); \
__asm__ volatile("%0 = rets" :"=r"(rets)); \
__asm__ volatile("%0 = reti" :"=r"(reti)); \
ASSERT(icfg & BIT(10), "icfg 0x%x/ rets 0x%x / reti 0x%x", icfg, rets, reti)}*/
void watchdog_close(void);
#endif//__DEBUG_LOG_H_
@@ -0,0 +1,83 @@
#ifndef CHRDEV_H
#define CHRDEV_H
#include "generic/typedef.h"
#include "generic/list.h"
//#include "generic/ioctl.h"
#include "generic/atomic.h"
//#include "sys/task.h"
#include "device/ioctl_cmds.h"
struct dev_node;
struct device;
/**@struct device_operations
* @brief device_operations结构体 \n
* otg设备执行哪种类型的操作
*/
struct device_operations {
bool (*online)(const struct dev_node *node); ///<设备在线状态查询
int (*init)(const struct dev_node *node, void *); ///<设备初始化
int (*open)(const char *name, struct device **device, void *arg); ///<设备开启
int (*read)(struct device *device, void *buf, u32 len, u32); ///<读操作
int (*write)(struct device *device, void *buf, u32 len, u32); ///<写操作
int (*seek)(struct device *device, u32 offset, int orig); ///<设备搜索
int (*ioctl)(struct device *device, u32 cmd, u32 arg); ///<I/O控制
int (*close)(struct device *device); ///<设备关闭
};
struct dev_node {
const char *name;
const struct device_operations *ops;
void *priv_data;
};
struct device {
atomic_t ref;
void *private_data;
const struct device_operations *ops;
void *platform_data;
void *driver_data;
};
#define REGISTER_DEVICE(node) \
const struct dev_node node sec(.device)
#define REGISTER_DEVICES(node) \
const struct dev_node node[] sec(.device)
int devices_init();
bool dev_online(const char *name);
void *dev_open(const char *name, void *arg);
int dev_read(void *device, void *buf, u32 len);
int dev_write(void *device, void *buf, u32 len);
int dev_seek(void *device, u32 offset, int orig);
int dev_ioctl(void *device, int cmd, u32 arg);
int dev_close(void *device);
int dev_bulk_read(void *_device, void *buf, u32 offset, u32 len);
int dev_bulk_write(void *_device, void *buf, u32 offset, u32 len);
#endif
@@ -0,0 +1,86 @@
#ifndef IOCTL_INF_H
#define IOCTL_INF_H
#define IOCTL_SET_IRQ_NUM 1
#define IOCTL_SET_PRIORITY 2
#define IOCTL_SET_DATA_WIDTH 3
#define IOCTL_SET_SPEED 4
#define IOCTL_SET_DETECT_MODE 5
#define IOCTL_SET_DETECT_FUNC 6
#define IOCTL_SET_DETECT_TIME_INTERVAL 7
#define IOCTL_SET_PORT 8
#define IOCTL_SET_PORT_FUNC 9
#define IOCTL_SET_CS_PORT_FUNC 10
#define IOCTL_SET_READ_MODE 11
#define IOCTL_SET_WRITE_MODE 12
#define IOCTL_SET_WRITE_PROTECT 13
#define IOCTL_SET_START_BIT 14
#define IOCTL_SET_STOP_BIT 15
#define IOCTL_FLUSH 16
#define IOCTL_REGISTER_IRQ_HANDLER 17
#define IOCTL_UNREGISTER_IRQ_HANDLER 18
#define IOCTL_GET_SYS_TIME 19
#define IOCTL_SET_SYS_TIME 20
#define IOCTL_GET_ALARM 21
#define IOCTL_SET_ALARM 22
#define IOCTL_SET_CAP_LOWSPEED_CARD 23
#define IOCTL_SET_VDD50_EN 30
#define IOCTL_GET_WEEKDAY 32
#define IOCTL_CLR_READ_MODE 33
#define IOCTL_SET_READ_CRC 34
#define IOCTL_GET_READ_CRC 35
#define IOCTL_GET_VOLUME 36
#define IOCTL_SET_VOLUME 37
#define IOCTL_SET_ALARM_ENABLE 38
#define IOCTL_CMD_RESUME 39
#define IOCTL_CMD_SUSPEND 40
#define IOCTL_SET_BASE_ADDR 41
#define IOCTL_SET_ASYNC_MODE 42
#define IOCTL_GET_SPEED 43
#define IOCTL_SET_ACTIVE_STATUS 44
#define IOCTL_POWER_RESUME 45
#define IOCTL_POWER_SUSPEND 46
#define IOCTL_GET_ID 100
#define IOCTL_GET_SECTOR_SIZE 101
#define IOCTL_GET_BLOCK_SIZE 102
#define IOCTL_GET_CAPACITY 103
#define IOCTL_GET_WIDTH 104
#define IOCTL_GET_HEIGHT 105
#define IOCTL_GET_BLOCK_NUMBER 106
#define IOCTL_CHECK_WRITE_PROTECT 107
#define IOCTL_GET_STATUS 108
#define IOCTL_GET_TYPE 109
#define IOCTL_GET_MAX_LUN 110
#define IOCTL_GET_CUR_LUN 111
#define IOCTL_SET_CUR_LUN 112
#define IOCTL_SET_FORCE_RESET 113
#define IOCTL_SET_CAPACITY 114
#define IOCTL_ENTER_4BYTE_ADDR_MODE 115
#define IOCTL_EXIT_4BYTE_ADDR_MODE 116
#define IOCTL_ERASE_SECTOR 200
#define IOCTL_ERASE_BLOCK 201
#define IOCTL_ERASE_CHIP 202
#define IOCTL_SET_ENC_END 203
#define IOCTL_ERASE_PAGE 204
#define IOCTL_SET_DATA_CALLBACK 301
#define IOCTL_GET_PART_INFO 320
struct ioctl_irq_handler {
void *priv;
void *handler;
};
#endif
+352
View File
@@ -0,0 +1,352 @@
#ifndef SYS_EVENT_H
#define SYS_EVENT_H
#include "generic/typedef.h"
#include "generic/list.h"
#include "generic/rect.h"
#define KEY_POWER_START 0
#define KEY_POWER 1
#define KEY_PREV 2
#define KEY_NEXT 3
#define KEY_OK 4
#define KEY_CANCLE 5
#define KEY_MENU 6
#define KEY_MODE 7
#define KEY_PHOTO 8
#define KEY_ENC 9
#define KEY_VOLUME_DEC 10
#define KEY_VOLUME_INC 11
#define KEY_PHONE 12
#define KEY_LEFT 37
#define KEY_UP 38
#define KEY_RIGHT 39
#define KEY_DOWN 40
#define KEY_0 48
#define KEY_1 49
#define KEY_2 50
#define KEY_3 51
#define KEY_4 52
#define KEY_5 53
#define KEY_6 54
#define KEY_7 55
#define KEY_8 56
#define KEY_9 57
#define KEY_F1 60
#define SYS_ALL_EVENT 0xffff
#define SYS_KEY_EVENT 0x0001
#define SYS_TOUCH_EVENT 0x0002
#define SYS_DEVICE_EVENT 0x0004
#define SYS_NET_EVENT 0x0008
#define SYS_BT_EVENT 0x0010
#define SYS_IR_EVENT 0x0020
#define SYS_PBG_EVENT 0x0040
#define SYS_BT_AI_EVENT 0x0080
#define SYS_AI_EVENT 0x0100
#define SYS_MATRIX_KEY_EVENT 0x0200
#define SYS_TOUCHPAD_EVENT 0x0400
#define DEVICE_EVENT_FROM_AT_UART (('A' << 24) | ('T' << 16) | ('U' << 8) | '\0')
#define DEVICE_EVENT_FROM_CHARGE (('C' << 24) | ('H' << 16) | ('G' << 8) | '\0')
#define DEVICE_EVENT_FROM_POWER (('P' << 24) | ('O' << 16) | ('W' << 8) | '\0')
#define DEVICE_EVENT_FROM_CI_UART (('C' << 24) | ('I' << 16) | ('U' << 8) | '\0')
#define DEVICE_EVENT_FROM_CI_TWS (('C' << 24) | ('I' << 16) | ('T' << 8) | '\0')
#define DEVICE_EVENT_CHARGE_STORE (('S' << 24) | ('T' << 16) | ('O' << 8) | '\0')
#define DEVICE_EVENT_FROM_TONE (('T' << 24) | ('N' << 16) | ('E' << 8) | '\0')
#define DEVICE_EVENT_FROM_FM (('F' << 24) | ('M' << 16) | ('\0'<< 8) | '\0')
#define KEY_EVENT_FROM_TWS (('T' << 24) | ('W' << 16) | ('S' << 8) | '\0')
#define SYS_BT_EVENT_FROM_TWS (('T' << 24) | ('W' << 16) | ('S' << 8) | '\0')
#define DEVICE_EVENT_FROM_LINEIN (('A' << 24) | ('U' << 16) | ('X' << 8) | '\0')
#define DRIVER_EVENT_FROM_SD0 (('S' << 24) | ('D' << 16) | ('0' << 8) | '\0')
#define DRIVER_EVENT_FROM_SD1 (('S' << 24) | ('D' << 16) | ('1' << 8) | '\0')
#define DRIVER_EVENT_FROM_SD2 (('S' << 24) | ('D' << 16) | ('2' << 8) | '\0')
#define DEVICE_EVENT_FROM_MUSIC (('M' << 24) | ('S' << 16) | ('C' << 8) | '\0')
#define DEVICE_EVENT_FROM_USB_HOST (('U' << 24) | ('H' << 16) | '\0' | '\0')
#define DEVICE_EVENT_FROM_OTG (('O' << 24) | ('T' << 16) | ('G' << 8) | '\0')
#define DEVICE_EVENT_FROM_PC (('P' << 24) | ('C' << 16) | '\0' | '\0')
#define DEVICE_EVENT_FROM_UAC (('U' << 24) | ('A' << 16) | ('C' << 8) | '\0')
#define DEVICE_EVENT_FROM_ALM (('A' << 24) | ('L' << 16) | ('M' << 8) | '\0')
#define SYS_BT_EVENT_TYPE_CON_STATUS (('C' << 24) | ('O' << 16) | ('N' << 8) | '\0')
#define SYS_BT_EVENT_TYPE_HCI_STATUS (('H' << 24) | ('C' << 16) | ('I' << 8) | '\0')
#define SYS_BT_EVENT_BLE_STATUS (('B' << 24) | ('L' << 16) | ('E' << 8) | '\0')
#define DEVICE_EVENT_FROM_KEY (('K' << 24) | ('E' << 16) | ('Y' << 8) | '\0')
#define SYS_BT_AI_EVENT_TYPE_STATUS (('B' << 24) | ('A' << 16) | ('I' << 8) | '\0')
#define DEVICE_EVENT_FROM_UART_RX_OVERFLOW (('U' << 24) | ('R' << 16) | ('F' << 8) | '\0')
#define DEVICE_EVENT_FROM_UART_RX_OUTTIME (('U' << 24) | ('R' << 16) | ('T' << 8) | '\0')
#define DEVICE_EVENT_FROM_DAC (('D' << 24) | ('A' << 16) | ('C' << 8) | '\0')
#define SYS_EVENT_FROM_CTRLER (('C' << 24) | ('T' << 16) | ('R' << 8) | '\0')
#define SYS_EVENT_FROM_RECORD (('R' << 24) | ('E' << 16) | ('C' << 8) | '\0')
#define DEVICE_EVENT_FROM_ENDLESS_LOOP_DEBUG (('E' << 24) | ('L' << 16) | ('D' << 8) | '\0')
#define DEVICE_EVENT_FROM_EARTCH (('E' << 24) | ('T' << 16) | ('H' << 8) | '\0')
#define DEVICE_EVENT_ONLINE_DATA (('O' << 24) | ('L' << 16) | ('D' << 8) | '\0')
#define SYS_BT_EVENT_FROM_KEY (('K' << 24) | ('E' << 16) | ('Y' << 8) | '\0')
#define SYS_BT_EVENT_FORM_SELF (('S' << 24) | ('E' << 16) | ('F' << 8) | '\0')
#define DEVICE_EVENT_FROM_ANC (('A' << 24) | ('N' << 16) | ('C' << 8) | '\0')
enum {
KEY_EVENT_CLICK,
KEY_EVENT_LONG,
KEY_EVENT_HOLD,
KEY_EVENT_UP,
KEY_EVENT_DOUBLE_CLICK,
KEY_EVENT_TRIPLE_CLICK,
KEY_EVENT_FOURTH_CLICK,
KEY_EVENT_FIRTH_CLICK,
KEY_EVENT_USER,
KEY_EVENT_MAX,
};
enum {
DEVICE_EVENT_IN,
DEVICE_EVENT_OUT,
DEVICE_EVENT_ONLINE,
DEVICE_EVENT_OFFLINE,
DEVICE_EVENT_CHANGE,
};
enum {
TOUCH_EVENT_DOWN,
TOUCH_EVENT_MOVE,
TOUCH_EVENT_HOLD,
TOUCH_EVENT_UP,
TOUCH_EVENT_CLICK,
TOUCH_EVENT_DOUBLE_CLICK,
};
enum {
NET_EVENT_CMD,
NET_EVENT_DATA,
NET_EVENT_CONNECTED,
NET_EVENT_DISCONNECTED,
NET_EVENT_SMP_CFG_TIMEOUT,
};
struct key_event {
u8 init;
u8 type;
u16 event;
u32 value;
u32 tmr;
};
struct ir_event {
u8 event;
};
struct msg_event {
u8 event;
u8 value;
};
#if EVENT_TOUCH_ENABLE_CONFIG
struct touch_event {
u8 event;
struct position pos;
};
#endif
struct device_event {
u8 event;
int value;
};
struct chargestore_event {
u8 event;
u8 *packet ;
u8 size;
};
struct ancbox_event {
u8 event;
u32 value;
};
struct net_event {
u8 event;
u8 value;
};
struct bt_event {
u8 event;
u8 args[7];
u32 value;
};
struct axis_event {
u8 event;
s16 x;
s16 y;
};
struct codesw_event {
u8 event;
s8 value;
};
struct pbg_event {
u8 event;
u8 args[3];
};
struct uart_event {
void *ut_bus;
};
struct uart_cmd_event {
u8 type;
u8 cmd;
};
struct ai_event {
u32 value;
};
struct ear_event {
u8 value;
};
struct rcsp_event {
u8 event;
u8 args[6];
u8 size;
};
struct chargebox_event {
u8 event;
};
struct matrix_key_event {
u16 args[6]; //最多推6个按键出来,如果需要推多个按键需要自行修改,每个u16 低八位标识row 高八位标识col
u8 *map;
};
struct touchpad_event {
u8 gesture_event; //手势事件
s8 x;
s8 y;
};
struct sys_event {
u16 type;
u8 consumed;
void *arg;
union {
struct key_event key;
struct axis_event axis;
struct codesw_event codesw;
#if EVENT_TOUCH_ENABLE_CONFIG
struct touch_event touch;
#endif
struct device_event dev;
struct net_event net;
struct bt_event bt;
struct msg_event msg;
struct chargestore_event chargestore;
struct ir_event ir;
struct pbg_event pbg;
struct uart_event uart;
struct uart_cmd_event uart_cmd;
struct ai_event ai;
struct ear_event ear;
struct rcsp_event rcsp;
struct chargebox_event chargebox;
struct ancbox_event ancbox;
struct matrix_key_event matrix_key;
struct touchpad_event touchpad;
} u;
};
struct static_event_handler {
int event_type;
void (*handler)(struct sys_event *);
};
#define SYS_EVENT_HANDLER(type, fn, pri) \
const struct static_event_handler __event_handler_##fn sec(.sys_event.pri.handler) = { \
.event_type = type, \
.handler = fn, \
}
extern struct static_event_handler sys_event_handler_begin[];
extern struct static_event_handler sys_event_handler_end[];
#define list_for_each_static_event_handler(p) \
for (p = sys_event_handler_begin; p < sys_event_handler_end; p++)
u16 register_sys_event_handler(int event_type, u8 priority, void *priv,
void (*handler)(struct sys_event *, void *));
void unregister_sys_event_handler(u16 id);
/*
* 事件通知函数,系统有事件发生时调用此函数
*/
void sys_event_notify(struct sys_event *e);
void sys_event_clear(struct sys_event *e);
void sys_key_event_disable();
void sys_key_event_enable();
void sys_key_event_filter_disable();
void sys_key_event_filter_enable();
void sys_touch_event_disable();
void sys_touch_event_enable();
/*
*下面四个为系统事件消耗函数,调用此函数后则对应的事件不在分发给其它任务
*
*/
void sys_event_consume(struct sys_event *e);
void sys_key_event_consume(struct key_event *e);
#if EVENT_TOUCH_ENABLE_CONFIG
void sys_touch_event_consume(struct touch_event *e);
#endif
void sys_device_event_consume(struct device_event *e);
/*
* 下面两个函数为按键和触摸事件接管函数,调用此函数后则对应的事件只发到当前任务
*
* on=true: 开始接管, on=false: 取消接管
*
* once: on = false 时有效,当前这次不接管, 事件可以继续发送到其它任务
*
*/
void sys_key_event_takeover(bool on, bool once);
void sys_touch_event_takeover(bool on, bool once);
int sys_key_event_map(struct key_event *org, struct key_event *new);
int sys_key_event_unmap(struct key_event *org, struct key_event *new);
#endif
@@ -0,0 +1,19 @@
#ifndef __FS_H__
#define __FS_H__
typedef struct {
void *private_data;
} FILE;
#endif /* VFS_ENABLE */
@@ -0,0 +1,44 @@
#ifndef ASCII_LIB_H
#define ASCII_LIB_H
#ifdef __cplusplus
extern "C" {
#endif
#include "typedef.h"
void ASCII_ToLower(void *buf, u32 len);
void ASCII_ToUpper(void *buf, u32 len);
u32 ASCII_StrCmp(const char *src, const char *dst, u32 len);
int ASCII_StrCmpNoCase(const char *src, const char *dst, int len);
void ASCII_IntToStr(void *pStr, u32 intNum, u32 strLen, u32 bufLen);
u32 ASCII_StrToInt(const void *pStr, u32 *pRint, u32 strLen);
u32 ASCII_StrLen(void *str, u32 len);
u32 ASCII_WStrLen(void *str, u32 len);
#ifdef __cplusplus
}
#endif
#endif
@@ -0,0 +1,81 @@
#ifndef ATOMIC_H
#define ATOMIC_H
#include "cpu.h"
#include "irq.h"
typedef struct {
int counter;
} atomic_t;
static inline int atomic_add_return(int i, atomic_t *v)
{
int val;
CPU_SR_ALLOC();
CPU_CRITICAL_ENTER();
val = v->counter;
v->counter = val += i;
CPU_CRITICAL_EXIT();
return val;
}
static inline int atomic_sub_return(int i, atomic_t *v)
{
int val;
CPU_SR_ALLOC();
CPU_CRITICAL_ENTER();
val = v->counter;
v->counter = val -= i;
CPU_CRITICAL_EXIT();
return val;
}
static inline int atomic_set(atomic_t *v, int i)
{
int val = 0;
CPU_SR_ALLOC();
CPU_CRITICAL_ENTER();
v->counter = i;
CPU_CRITICAL_EXIT();
return val;
}
#define DEFINE_ATOMIC(x) \
atomic_t x = {.counter = 0}
#define atomic_add(i, v) atomic_add_return(i, v)
#define atomic_sub(i, v) atomic_sub_return(i, v)
#define atomic_read(v) arch_atomic_read(v)
/*#define atomic_set(v,i) (((v)->counter) = (i))*/
#define atomic_inc(v) atomic_add(1, v)
#define atomic_dec(v) atomic_sub(1, v)
#define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
#define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
#define atomic_inc_return(v) (atomic_add_return(1, v))
#define atomic_dec_return(v) (atomic_sub_return(1, v))
#define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
#define atomic_add_negative(i,v) (atomic_add_return(i, v) < 0)
#endif
@@ -0,0 +1,65 @@
#ifndef CIRCULAR_BUF_INTERFACE_H
#define CIRCULAR_BUF_INTERFACE_H
#include "typedef.h"
//#include "system/spinlock.h"
typedef struct _cbuffer {
u8 *begin;
u8 *end;
u8 *read_ptr;
u8 *write_ptr;
u8 *tmp_ptr ;
u32 tmp_len;
u32 data_len;
u32 total_len;
//spinlock_t lock;
} cbuffer_t;
extern void cbuf_init(cbuffer_t *cbuffer, void *buf, u32 size);
extern u32 cbuf_read(cbuffer_t *cbuffer, void *buf, u32 len);
extern u32 cbuf_write(cbuffer_t *cbuffer, void *buf, u32 len);
extern u32 cbuf_is_write_able(cbuffer_t *cbuffer, u32 len);
extern void *cbuf_write_alloc(cbuffer_t *cbuffer, u32 *len);
extern void cbuf_write_updata(cbuffer_t *cbuffer, u32 len);
extern void *cbuf_read_alloc(cbuffer_t *cbuffer, u32 *len);
extern void cbuf_read_updata(cbuffer_t *cbuffer, u32 len);
extern void cbuf_clear(cbuffer_t *cbuffer);
extern u32 cbuf_rewrite(cbuffer_t *cbuffer, void *begin, void *buf, u32 len);
extern void cbuf_discard_prewrite(cbuffer_t *cbuffer);
extern void cbuf_updata_prewrite(cbuffer_t *cbuffer);
extern u32 cbuf_prewrite(cbuffer_t *cbuffer, void *buf, u32 len);
extern void *cbuf_get_writeptr(cbuffer_t *cbuffer);
extern u32 cbuf_get_data_size(cbuffer_t *cbuffer);
extern void *cbuf_get_readptr(cbuffer_t *cbuffer);
extern u32 cbuf_read_goback(cbuffer_t *cbuffer, u32 len);
extern u32 cbuf_get_data_len(cbuffer_t *cbuffer);
extern u32 cbuf_read_alloc_len(cbuffer_t *cbuffer, void *buf, u32 len);
extern void cbuf_read_alloc_len_updata(cbuffer_t *cbuffer, u32 len);
#endif
@@ -0,0 +1,22 @@
#ifndef GENERIC_CPU_H
#define GENERIC_CPU_H
#include <asm/cpu.h>
#endif
@@ -0,0 +1,10 @@
#ifndef _LITE_DEBUG_H_
#define _LITE_DEBUG_H_
extern void puts_lite(const char *out);
extern void put_buf_lite(void *_buf, u32 len);
extern int printf_lite(const char *format, ...);
#endif /* #ifdef _LITE_DEBUG_H_ */
@@ -0,0 +1,40 @@
#ifndef _ASM_GENERIC_ERRNO_BASE_H
#define _ASM_GENERIC_ERRNO_BASE_H
#define EPERM 1 /* Operation not permitted */
#define ENOENT 2 /* No such file or directory */
#define ESRCH 3 /* No such process */
#define EINTR 4 /* Interrupted system call */
#define EIO 5 /* I/O error */
#define ENXIO 6 /* No such device or address */
#define E2BIG 7 /* Argument list too long */
#define ENOEXEC 8 /* Exec format error */
#define EBADF 9 /* Bad file number */
#define ECHILD 10 /* No child processes */
#define EAGAIN 11 /* Try again */
#define ENOMEM 12 /* Out of memory */
#define EACCES 13 /* Permission denied */
#define EFAULT 14 /* Bad address */
#define ENOTBLK 15 /* Block device required */
#define EBUSY 16 /* Device or resource busy */
#define EEXIST 17 /* File exists */
#define EXDEV 18 /* Cross-device link */
#define ENODEV 19 /* No such device */
#define ENOTDIR 20 /* Not a directory */
#define EISDIR 21 /* Is a directory */
#define EINVAL 22 /* Invalid argument */
#define ENFILE 23 /* File table overflow */
#define EMFILE 24 /* Too many open files */
#define ENOTTY 25 /* Not a typewriter */
#define ETXTBSY 26 /* Text file busy */
#define EFBIG 27 /* File too large */
#define ENOSPC 28 /* No space left on device */
#define ESPIPE 29 /* Illegal seek */
#define EROFS 30 /* Read-only file system */
#define EMLINK 31 /* Too many links */
#define EPIPE 32 /* Broken pipe */
#define EDOM 33 /* Math argument out of domain of func */
#define ERANGE 34 /* Math result not representable */
#define ETIMEDOUT 35 /* Connection timed out */
#endif
@@ -0,0 +1,48 @@
#ifndef ASM_GPIO_H
#define ASM_GPIO_H
#include "asm/gpio.h"
#define GPIO2PORT(gpio) (gpio / IO_GROUP_NUM)
#if 0
void gpio_port_lock(unsigned int port);
void gpio_port_unlock(unsigned int port);
int __gpio_direction_input(unsigned int gpio);
int gpio_direction_input(unsigned int gpio);
int __gpio_direction_output(unsigned int gpio, int value);
int gpio_direction_output(unsigned int gpio, int value);
int __gpio_set_pull_up(unsigned int gpio, int value);
int gpio_set_pull_up(unsigned int gpio, int value);
int __gpio_set_pull_down(unsigned int gpio, int value);
int gpio_set_pull_down(unsigned int gpio, int value);
int __gpio_set_hd(unsigned int gpio, int value);
int gpio_set_hd(unsigned int gpio, int value);
int __gpio_set_die(unsigned int gpio, int value);
int gpio_set_die(unsigned int gpio, int value);
int __gpio_set_output_clk(unsigned int gpio, int clk);
int gpio_set_output_clk(unsigned int gpio, int clk);
int __gpio_read(unsigned int gpio);
int gpio_read(unsigned int gpio);
#else
#define gpio_set_die(gpio, value) gpio_hw_set_die(IO_PORT_SPILT(gpio), value)
#define gpio_direction_output(gpio, value) gpio_hw_direction_output(IO_PORT_SPILT(gpio), value)
#define gpio_direction_input(gpio) gpio_hw_direction_input(IO_PORT_SPILT(gpio))
#define gpio_set_pull_up(gpio, value) gpio_hw_set_pull_up(IO_PORT_SPILT(gpio), value)
#define gpio_set_pull_down(gpio, value) gpio_hw_set_pull_down(IO_PORT_SPILT(gpio), value)
#define gpio_set_direction(gpio, value) gpio_hw_set_direction(IO_PORT_SPILT(gpio), value)
#endif
#endif
@@ -0,0 +1,36 @@
#ifndef GENERIC_INCLUDES_H
#define GENERIC_INCLUDES_H
#include "errno-base.h"
#include "typedef.h"
#include "ascii.h"
#include "atomic.h"
#include "ioctl.h"
#include "cpu.h"
#include "gpio.h"
#include "irq.h"
#include "jiffies.h"
#include "list.h"
#include "printf.h"
#include "rect.h"
#include "version.h"
#include "lbuf.h"
#include "lbuf_lite.h"
#include "circular_buf.h"
#include "index.h"
#include "debug_lite.h"
#endif
@@ -0,0 +1,22 @@
#ifndef INDEX_H
#define INDEX_H
#include "typedef.h"
#define TABLE(t) t, ARRAY_SIZE(t)
int index_of_table8(u8 value, const u8 *table, int table_size);
int index_of_table16(u16 value, const u16 *table, int table_size);
int index_of_table32(u32 value, const u32 *table, int table_size);
#endif
@@ -0,0 +1,106 @@
#ifndef _ASM_GENERIC_IOCTL_H
#define _ASM_GENERIC_IOCTL_H
/* ioctl command encoding: 32 bits total, command in lower 16 bits,
* size of the parameter structure in the lower 14 bits of the
* upper 16 bits.
* Encoding the size of the parameter structure in the ioctl request
* is useful for catching programs compiled with old versions
* and to avoid overwriting user space outside the user buffer area.
* The highest 2 bits are reserved for indicating the ``access mode''.
* NOTE: This limits the max parameter size to 16kB -1 !
*/
/*
* The following is for compatibility across the various Linux
* platforms. The generic ioctl numbering scheme doesn't really enforce
* a type field. De facto, however, the top 8 bits of the lower 16
* bits are indeed used as a type field, so we might just as well make
* this explicit here. Please be sure to use the decoding macros
* below from now on.
*/
#define _IOC_NRBITS 8
#define _IOC_TYPEBITS 8
/*
* Let any architecture override either of the following before
* including this file.
*/
#ifndef _IOC_SIZEBITS
# define _IOC_SIZEBITS 14
#endif
#ifndef _IOC_DIRBITS
# define _IOC_DIRBITS 2
#endif
#define _IOC_NRMASK ((1 << _IOC_NRBITS)-1)
#define _IOC_TYPEMASK ((1 << _IOC_TYPEBITS)-1)
#define _IOC_SIZEMASK ((1 << _IOC_SIZEBITS)-1)
#define _IOC_DIRMASK ((1 << _IOC_DIRBITS)-1)
#define _IOC_NRSHIFT 0
#define _IOC_TYPESHIFT (_IOC_NRSHIFT+_IOC_NRBITS)
#define _IOC_SIZESHIFT (_IOC_TYPESHIFT+_IOC_TYPEBITS)
#define _IOC_DIRSHIFT (_IOC_SIZESHIFT+_IOC_SIZEBITS)
/*
* Direction bits, which any architecture can choose to override
* before including this file.
*/
#ifndef _IOC_NONE
# define _IOC_NONE 0U
#endif
#ifndef _IOC_WRITE
# define _IOC_WRITE 1U
#endif
#ifndef _IOC_READ
# define _IOC_READ 2U
#endif
#define _IOC(dir,type,nr,size) \
(((dir) << _IOC_DIRSHIFT) | \
((type) << _IOC_TYPESHIFT) | \
((nr) << _IOC_NRSHIFT) | \
((size) << _IOC_SIZESHIFT))
#ifdef __KERNEL__
/* provoke compile error for invalid uses of size argument */
extern unsigned int __invalid_size_argument_for_IOC;
#define _IOC_TYPECHECK(t) \
((sizeof(t) == sizeof(t[1]) && \
sizeof(t) < (1 << _IOC_SIZEBITS)) ? \
sizeof(t) : __invalid_size_argument_for_IOC)
#else
#define _IOC_TYPECHECK(t) (sizeof(t))
#endif
/* used to create numbers */
#define _IO(type,nr) _IOC(_IOC_NONE,(type),(nr),0)
#define _IOR(type,nr,size) _IOC(_IOC_READ,(type),(nr),(_IOC_TYPECHECK(size)))
#define _IOW(type,nr,size) _IOC(_IOC_WRITE,(type),(nr),(_IOC_TYPECHECK(size)))
#define _IOWR(type,nr,size) _IOC(_IOC_READ|_IOC_WRITE,(type),(nr),(_IOC_TYPECHECK(size)))
#define _IOR_BAD(type,nr,size) _IOC(_IOC_READ,(type),(nr),sizeof(size))
#define _IOW_BAD(type,nr,size) _IOC(_IOC_WRITE,(type),(nr),sizeof(size))
#define _IOWR_BAD(type,nr,size) _IOC(_IOC_READ|_IOC_WRITE,(type),(nr),sizeof(size))
/* used to decode ioctl numbers.. */
#define _IOC_DIR(nr) (((nr) >> _IOC_DIRSHIFT) & _IOC_DIRMASK)
#define _IOC_TYPE(nr) (((nr) >> _IOC_TYPESHIFT) & _IOC_TYPEMASK)
#define _IOC_NR(nr) (((nr) >> _IOC_NRSHIFT) & _IOC_NRMASK)
#define _IOC_SIZE(nr) (((nr) >> _IOC_SIZESHIFT) & _IOC_SIZEMASK)
/* ...and for the drivers/sound files... */
#define IOC_IN (_IOC_WRITE << _IOC_DIRSHIFT)
#define IOC_OUT (_IOC_READ << _IOC_DIRSHIFT)
#define IOC_INOUT ((_IOC_WRITE|_IOC_READ) << _IOC_DIRSHIFT)
#define IOCSIZE_MASK (_IOC_SIZEMASK << _IOC_SIZESHIFT)
#define IOCSIZE_SHIFT (_IOC_SIZESHIFT)
#endif /* _ASM_GENERIC_IOCTL_H */
@@ -0,0 +1,23 @@
#ifndef __IRQ_H_
#define __IRQ_H_
#include "asm/irq.h"
#endif
@@ -0,0 +1,34 @@
#ifndef JIFFIES_H
#define JIFFIES_H
/* timer interface */
/* Parameters used to convert the timespec values: */
#define HZ 100L
#define MSEC_PER_SEC 1000L
#define USEC_PER_MSEC 1000L
#define NSEC_PER_USEC 1000L
#define NSEC_PER_MSEC 1000000L
#define USEC_PER_SEC 1000000L
#define NSEC_PER_SEC 1000000000L
#define FSEC_PER_SEC 1000000000000000LL
#ifndef __ASSEMBLY__
extern volatile unsigned long jiffies;
extern unsigned long jiffies_msec();
extern unsigned long jiffies_half_msec();
#endif
#define time_after(a,b) ((long)(b) - (long)(a) < 0)
#define time_before(a,b) time_after(b,a)
extern unsigned char jiffies_unit;
#define msecs_to_jiffies(msec) ((msec)/jiffies_unit)
#define jiffies_to_msecs(j) ((j)*jiffies_unit)
#endif
@@ -0,0 +1,68 @@
#ifndef LBUF_H
#define LBUF_H
#include "typedef.h"
#include "list.h"
//#include "system/spinlock.h"
struct lbuff_head {
int magic_a;
struct list_head head;
struct list_head free;
//spinlock_t lock;
u8 align;
u16 priv_len;
u32 total_size;
u32 last_addr;
void *priv;
int magic_b;
};
struct lbuff_state {
u32 avaliable;
u32 fragment;
u32 max_continue_len;
int num;
};
struct lbuff_head *lbuf_init(void *buf, u32 len, int align, int priv_head_len);
void *lbuf_alloc(struct lbuff_head *head, u32 len);
void *lbuf_realloc(void *lbuf, int size);
int lbuf_empty(struct lbuff_head *head);
void lbuf_clear(struct lbuff_head *head);
void lbuf_push(void *lbuf, u8 channel_map);
void *lbuf_pop(struct lbuff_head *head, u8 channel);
int lbuf_free(void *lbuf);
void lbuf_free_check(void *lbuf, u32 rets);
u32 lbuf_free_space(struct lbuff_head *head);
void lbuf_state(struct lbuff_head *head, struct lbuff_state *state);
void lbuf_dump(struct lbuff_head *head);
int lbuf_traversal(struct lbuff_head *head);
int lbuf_avaliable(struct lbuff_head *head, int size);
int lbuf_real_size(void *lbuf);
int lbuf_remain_space(struct lbuff_head *head);
void lbuf_inc_ref(void *lbuf);
#endif
@@ -0,0 +1,50 @@
#ifndef LBUF_LITE_H
#define LBUF_LITE_H
#include "typedef.h"
#include "list.h"
//#include "system/spinlock.h"
struct lbuff_lite_head {
int magic_a;
struct list_head head;
struct list_head free;
//spinlock_t lock;
u8 align;
u16 priv_len;
u32 total_size;
u32 last_addr;
void *priv;
int magic_b;
};
struct lbuff_lite_state {
u32 avaliable;
u32 fragment;
u32 max_continue_len;
int num;
};
struct lbuff_lite_head *lbuf_lite_init(void *buf, u32 len, int align, int priv_head_len);
void *lbuf_lite_alloc(struct lbuff_lite_head *head, u32 len);
void *lbuf_lite_realloc(void *lbuf, int size);
void lbuf_lite_free(void *lbuf);
u32 lbuf_lite_free_space(struct lbuff_lite_head *head);
void lbuf_lite_state(struct lbuff_lite_head *head, struct lbuff_lite_state *state);
void lbuf_lite_dump(struct lbuff_lite_head *head);
int lbuf_lite_avaliable(struct lbuff_lite_head *head, int size);
#endif
@@ -0,0 +1,291 @@
#ifndef LIST_H
#define LIST_H
/**
* container_of - cast a member of a structure out to the containing structure
* @ptr: the pointer to the member.
* @type: the type of the container struct this is embedded in.
* @member: the name of the member within the struct.
*
*/
#ifdef list_offsetof
#undef list_offsetof
#endif
#ifdef container_of
#undef container_of
#endif
#define list_offsetof(type, memb) \
((unsigned long)(&((type *)0)->memb))
#define container_of(ptr, type, memb) \
((type *)((char *)(ptr) - list_offsetof(type, memb)))
struct list_head {
struct list_head *next, *prev;
};
#define LIST_HEAD_INIT(name) { &(name), &(name) }
#define LIST_HEAD(name) \
struct list_head name = LIST_HEAD_INIT(name)
/**
* list_entry - get the struct for this entry
* @ptr: the &struct list_head pointer.
* @type: the type of the struct this is embedded in.
* @member: the name of the list_struct within the struct.
*/
#define list_entry(ptr, type, member) \
container_of(ptr, type, member)
/**
* list_first_entry - get the first element from a list
* @ptr: the list head to take the element from.
* @type: the type of the struct this is embedded in.
* @member: the name of the list_struct within the struct.
*
* Note, that list is expected to be not empty.
*/
/* REF_LIST: spi.c */
#define list_first_entry(ptr, type, member) \
list_entry((ptr)->next, type, member)
/**
* list_for_each - iterate over a list
* @pos: the &struct list_head to use as a loop cursor.
* @head: the head for your list.
*/
#define list_for_each(pos, head) \
for (pos = (head)->next; pos != (head); \
pos = pos->next)
/**
* list_for_each_safe - iterate over a list safe against removal of list entry
* @pos: the &struct list_head to use as a loop counter.
* @n: another &struct list_head to use as temporary storage
* @head: the head for your list.
*/
#define list_for_each_safe(pos, n, head) \
for (pos = (head)->next, n = pos->next; pos != (head); \
pos = n, n = pos->next)
/**
* list_for_each_entry - iterate over list of given type
* @pos: the type * to use as a loop cursor.
* @head: the head for your list.
* @member: the name of the list_struct within the struct.
*/
#define list_for_each_entry(pos, head, member) \
for (pos = list_entry((head)->next, typeof(*pos), member); \
&pos->member != (head); \
pos = list_entry(pos->member.next, typeof(*pos), member))
/**
* list_for_each_entry_reverse - iterate backwards over list of given type.
* @pos: the type * to use as a loop cursor.
* @head: the head for your list.
* @member: the name of the list_struct within the struct.
*/
#define list_for_each_entry_reverse(pos, head, member) \
for (pos = list_entry((head)->prev, typeof(*pos), member); \
&pos->member != (head); \
pos = list_entry(pos->member.prev, typeof(*pos), member))
/**
* list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
* @pos: the type * to use as a loop cursor.
* @n: another type * to use as temporary storage
* @head: the head for your list.
* @member: the name of the list_struct within the struct.
*/
#define list_for_each_entry_safe(pos, n, head, member) \
for (pos = list_entry((head)->next, typeof(*pos), member), \
n = list_entry(pos->member.next, typeof(*pos), member); \
&pos->member != (head); \
pos = n, n = list_entry(n->member.next, typeof(*n), member))
#define list_for_each_entry_reverse_safe(pos, n, head, member) \
for (pos = list_entry((head)->prev, typeof(*pos), member), \
n = list_entry(pos->member.prev, typeof(*pos), member); \
&pos->member != (head); \
pos = n, n = list_entry(n->member.prev, typeof(*n), member))
/**
* list_empty - tests whether a list is empty
* @head: the list to test.
*/
/* REF_LIST: spi.c */
static inline int list_empty(const struct list_head *head)
{
return head->next == head;
}
/*
* Insert a new entry between two known consecutive entries.
*
* This is only for internal list manipulation where we know
* the prev/next entries already!
*/
static inline void __list_add(struct list_head *_new,
struct list_head *prev,
struct list_head *next)
{
next->prev = _new;
_new->next = next;
_new->prev = prev;
prev->next = _new;
}
/**
* list_add_tail - add a new entry
* @new: new entry to be added
* @head: list head to add it before
*
* Insert a new entry before the specified head.
* This is useful for implementing queues.
*/
/* REF_LIST: spi.c */
static inline void list_add_tail(struct list_head *_new, struct list_head *head)
{
__list_add(_new, head->prev, head);
}
static inline void __list_del(struct list_head *prev, struct list_head *next)
{
next->prev = prev;
prev->next = next;
}
static inline void __list_del_entry(struct list_head *entry)
{
__list_del(entry->prev, entry->next);
}
/* REF_LIST: spi.c */
static inline void list_del(struct list_head *entry) //Ð޸ĹýµÄlist_del£¬ÕâÀïÓëlist_del_initÒ»Ñù
{
__list_del(entry->prev, entry->next);
entry->next = entry;
entry->prev = entry;
}
/*
* Simple doubly linked list implementation.
*
* Some of the internal functions ("__xxx") are useful when
* manipulating whole lists rather than single entries, as
* sometimes we already know the next/prev entries and we can
* generate better code by using them directly rather than
* using the generic single-entry routines.
*/
static inline void INIT_LIST_HEAD(struct list_head *list)
{
list->next = list;
list->prev = list;
}
static inline void list_del_init(struct list_head *entry)
{
__list_del_entry(entry);
INIT_LIST_HEAD(entry);
}
/**
* list_move_tail - delete from one list and add as another's tail
* @list: the entry to move
* @head: the head that will follow our entry
*/
static inline void list_move_tail(struct list_head *list,
struct list_head *head)
{
__list_del(list->prev, list->next);
list_add_tail(list, head);
}
/**
* list_add - add a new entry
* @new: new entry to be added
* @head: list head to add it after
*
* Insert a new entry after the specified head.
* This is good for implementing stacks.
*/
static inline void list_add(struct list_head *new, struct list_head *head)
{
__list_add(new, head, head->next);
}
static inline int list_is_head(struct list_head *head, struct list_head *member)
{
return head->next == member;
}
#if 0
static inline void __list_splice(const struct list_head *list,
struct list_head *prev,
struct list_head *next)
{
struct list_head *first = list->next;
struct list_head *last = list->prev;
first->prev = prev;
prev->next = first;
last->next = next;
next->prev = last;
}
/**
* list_splice_tail_init - join two lists and reinitialise the emptied list
* @list: the new list to add.
* @head: the place to add it in the first list.
*
* Each of the lists is a queue.
* The list at @list is reinitialised
*/
static inline void list_splice_tail_init(struct list_head *list,
struct list_head *head)
{
if (!list_empty(list)) {
__list_splice(list, head->prev, head);
INIT_LIST_HEAD(list);
}
}
/**
* list_is_singular - tests whether a list has just one entry.
* @head: the list to test.
*/
static inline int list_is_singular(const struct list_head *head)
{
return !list_empty(head) && (head->next == head->prev);
}
/**
* list_splice_tail - join two lists, each list being a queue
* @list: the new list to add.
* @head: the place to add it in the first list.
*/
static inline void list_splice_tail(struct list_head *list,
struct list_head *head)
{
if (!list_empty(list)) {
__list_splice(list, head->prev, head);
}
}
#endif
#define list_for_each_entry_from(pos, head, member) \
for (; &pos->member != (head); \
pos = list_entry(pos->member.next, typeof(*pos), member))
#define list_for_each_entry_from_reverse(pos, head, member) \
for (; &pos->member != (head); \
pos = list_entry(pos->member.prev, typeof(*pos), member))
#endif
@@ -0,0 +1,118 @@
#ifndef __LOG_H
#define __LOG_H
#include "system/generic/printf.h"
#define __LOG_VERBOSE 0
#define __LOG_DEBUG 1
#define __LOG_INFO 2
#define __LOG_WARN 3
#define __LOG_ERROR 4
#define __LOG_CHAR 5
struct logbuf {
u16 len;
u16 buf_len;
char buf[0];
};
//#define __LOG_ENABLE
#undef __LOG_LEVEL
#define __LOG_LEVEL 0xff
#if __LOG_LEVEL > __LOG_VERBOSE
#define log_v(...) do {} while (0)
#elif defined __LOG_ENABLE
#define log_v(...) log_print(__LOG_VERBOSE, NULL, __VA_ARGS__)
#else
#define log_v(...) printf(__VA_ARGS__)
#endif
#if __LOG_LEVEL > __LOG_DEBUG
#define log_d(...) do {} while (0)
#elif defined __LOG_ENABLE
#define log_d(...) log_print(__LOG_DEBUG, NULL, __VA_ARGS__);
#else
#define log_d(...) printf(__VA_ARGS__)
#endif
#if __LOG_LEVEL > __LOG_INFO
#define log_i(...) do {} while (0)
#elif defined __LOG_ENABLE
#define log_i(...) log_print(__LOG_INFO, NULL, __VA_ARGS__);
#else
#define log_i(...) printf(__VA_ARGS__)
#endif
#if __LOG_LEVEL > __LOG_WARN
#define log_w(...) do {} while (0)
#elif defined __LOG_ENABLE
#define log_w(...) log_print(__LOG_WARN, NULL, __VA_ARGS__);
#else
#define log_w(...) printf(__VA_ARGS__)
#endif
#if __LOG_LEVEL > __LOG_ERROR
#define log_e(...) do {} while (0)
#elif defined __LOG_ENABLE
#define log_e(...) log_print(__LOG_ERROR, NULL, __VA_ARGS__);
#else
#define log_e(...) printf(__VA_ARGS__)
#endif
#if __LOG_LEVEL > __LOG_CHAR
#define log_c(x) do {} while (0)
#elif defined __LOG_ENABLE
#define log_c(x) putchar(x)
#else
#define log_c(x)
#endif
#define r_printf(x, ...) log_i("\e[31m\e[1m" x "\e[0m", ## __VA_ARGS__)
#define g_printf(x, ...) log_i("\e[32m\e[1m" x "\e[0m", ## __VA_ARGS__)
#define y_printf(x, ...) log_i("\e[33m\e[1m" x "\e[0m", ## __VA_ARGS__)
#define r_f_printf(x, ...) log_i("\e[31m\e[5m\e[1m" x "\e[0m", ## __VA_ARGS__)
#define g_f_printf(x, ...) log_i("\e[32m\e[5m\e[1m" x "\e[0m", ## __VA_ARGS__)
#define y_f_printf(x, ...) log_i("\e[33m\e[5m\e[1m" x "\e[0m", ## __VA_ARGS__)
#ifndef __LOG_ENABLE
#define log_dump(a, b) do {} while(0)
#define log_putchar() do {} while(0)
#define log_early_init(a) do {} while(0)
#define log_level(a) do {} while(0)
#else
int log_output_lock();
void log_output_unlock();
void log_print_time();
void log_early_init(int buf_size);
void log_level(int level);
void log_print(int level, const char *tag, const char *format, ...);
void log_dump(const u8 *buf, int len);
struct logbuf *log_output_start(int len);
void log_output_end(struct logbuf *);
void log_putchar(struct logbuf *lb, char c);
void log_put_u8hex(struct logbuf *lb, unsigned char dat);
void log_putbyte(char);
#endif
void log_flush();
#endif
@@ -0,0 +1,28 @@
#ifndef _PRINTF_H_
#define _PRINTF_H_
#define line_inf printf("%s %s %d \r\n" ,__FILE__, __func__ , __LINE__) ;
#include <stdarg.h>
#include "typedef.h"
//#define NOFLOAT
extern int putchar(int a);
extern int puts(const char *out);
//void put_u4hex(unsigned char dat);
//void put_u8hex(unsigned char dat);
//void put_u16hex(unsigned short dat);
// void put_u32hex(unsigned int dat);
void put_buf(const u8 *buf, u32 len);
int printf(const char *format, ...);
int assert_printf(const char *format, ...);
int sprintf(char *out, const char *format, ...);
int vprintf(const char *fmt, __builtin_va_list va);
int vsnprintf(char *, unsigned long, const char *, __builtin_va_list);
int snprintf(char *buf, unsigned long size, const char *fmt, ...);
//int print(char **out, char *end, const char *format, va_list args);
//int snprintf(char *, unsigned long, const char *, ...);
int sscanf(const char *buf, const char *fmt, ...); //BUG: ¶à¸ö²ÎÊý? ×îºóÓÖ¿Õ¸ñ?
//int perror(const char *fmt, ...);
#endif
@@ -0,0 +1,134 @@
#ifndef RECT_H
#define RECT_H
#include "typedef.h"
#define AT_UI_RAM //AT(.ui_ram)
struct position {
int x;
int y;
};
struct rect {
int left;
int top;
int width;
int height;
};
#define rect_left(r) ((r)->left)
#define rect_top(r) ((r)->top)
#define rect_right(r) ((r)->left + (r)->width)
#define rect_bottom(r) ((r)->top + (r)->height)
//#define rect_height(v) ((v)->bottom - (v)->top)
//#define rect_width(v) ((v)->right - (v)->left)
static inline int in_rect(const struct rect *rect, struct position *pos)
{
if (rect->left <= pos->x && rect_right(rect) > pos->x) {
if (rect->top <= pos->y && rect_bottom(rect) > pos->y) {
return true;
}
}
return false;
}
AT_UI_RAM
static inline bool get_rect_cover(const struct rect *a, const struct rect *b, struct rect *c)
{
int right, bottom;
c->top = MAX(a->top, b->top);
c->left = MAX(a->left, b->left);
right = MIN(rect_right(a), rect_right(b));
bottom = MIN(rect_bottom(a), rect_bottom(b));
if ((c->top < bottom) && (c->left < right)) {
c->width = right - c->left;
c->height = bottom - c->top;
return true;
}
return false;
}
static inline bool get_rect_nocover_l(const struct rect *a, const struct rect *b, struct rect *c)
{
int right, bottom;
c->left = MIN(rect_left(a), rect_left(b));
c->top = MIN(rect_top(a), rect_top(b));
right = MAX(rect_left(a), rect_left(b));
bottom = MAX(rect_bottom(a), rect_bottom(b));
if ((c->top < bottom) && (c->left < right)) {
c->width = right - c->left;
c->height = bottom - c->top;
return true;
}
return false;
}
static inline bool get_rect_nocover_r(const struct rect *a, const struct rect *b, struct rect *c)
{
int right, bottom;
c->left = MIN(rect_right(a), rect_right(b));
c->top = MIN(rect_top(a), rect_top(b));
right = MAX(rect_right(a), rect_right(b));
bottom = MAX(rect_bottom(a), rect_bottom(b));
if ((c->top < bottom) && (c->left < right)) {
c->width = right - c->left;
c->height = bottom - c->top;
return true;
}
return false;
}
static inline bool get_rect_nocover_t(const struct rect *a, const struct rect *b, struct rect *c)
{
int right, bottom;
c->left = MIN(rect_left(a), rect_left(b));
c->top = MIN(rect_top(a), rect_top(b));
right = MAX(rect_right(a), rect_right(b));
bottom = MAX(rect_top(a), rect_top(b));
if ((c->top < bottom) && (c->left < right)) {
c->width = right - c->left;
c->height = bottom - c->top;
return true;
}
return false;
}
static inline bool get_rect_nocover_b(const struct rect *a, const struct rect *b, struct rect *c)
{
int right, bottom;
c->left = MIN(rect_left(a), rect_left(b));
c->top = MIN(rect_bottom(a), rect_bottom(b));
right = MAX(rect_right(a), rect_right(b));
bottom = MAX(rect_bottom(a), rect_bottom(b));
if ((c->top < bottom) && (c->left < right)) {
c->width = right - c->left;
c->height = bottom - c->top;
return true;
}
return false;
}
#endif
@@ -0,0 +1,166 @@
/*************************************************************
File: typedef.h
Author:Juntham
Discriptor:
Êý¾ÝÀàÐÍÖØ¶¨Òå
Version:
Date£º
*************************************************************/
#ifndef _typedef_h_
#define _typedef_h_
#include "asm/cpu.h"
#if defined(__GNUC__)
///<locate code to x segment ever exist
#define SEC_USED(x) __attribute__((section(#x),used))
///<locate code to x segment optimized by dependency
#define SEC(x) __attribute__((section(#x)))
#define sec(x) __attribute__((section(#x),used))
///<locate data to x segment
#define AT(x) __attribute__((section(#x)))
#define SET(x) __attribute__((x))
#define ALIGNED(x) __attribute__((aligned(x)))
#define _GNU_PACKED_ __attribute__((packed))
#define _NOINLINE_ __attribute__((noinline))
#define _INLINE_ __attribute__((always_inline))
#define _WEAK_ __attribute__((weak))
#define _WEAKREF_ __attribute__((weakref))
#define _NORETURN_ __attribute__((noreturn))
#define _NAKED_ __attribute__((naked))
#else
#define SEC_USED(x)
#define SEC(x)
#define AT(x)
#define SET(x)
#define ALIGNED(x)
#define _GNU_PACKED_
#define _NOINLINE_
#define _INLINE_
#define _WEAK_
#define _WEAKREF_
#define _NORETURN_
#define _NAKED_
#endif
#define AT_VOLATILE_RAM_CODE
#if CPU_ENDIAN == LITTLE_ENDIAN
//#define ntohl(x) (u32)((x>>24)|((x>>8)&0xff00)|(x<<24)|((x&0xff00)<<8))
//#define ntoh(x) (u16)((x>>8&0x00ff)|x<<8&0xff00)
//#define ntohl(x) (u32)((((u32)(x))>>24) | ((((u32)(x))>>8)&0xff00) | (((u32)(x))<<24) | ((((u32)(x))&0xff00)<<8))
//#define ntoh(x) (u16)((((u32)(x))>>8&0x00ff) | (((u32)(x))<<8&0xff00))
//#define NTOH(x) (x) = ntoh(x)
//#define NTOHL(x) (x) = ntohl(x)
#define LD_WORD(ptr) (u16)(*(u16*)(u8*)(ptr))
#define LD_DWORD(ptr) (u32)(*(u32*)(u8*)(ptr))
#define ST_WORD(ptr,val) *(u16*)(u8*)(ptr)=(u16)(val)
#define ST_DWORD(ptr,val) *(u32*)(u8*)(ptr)=(u32)(val)
#else
#define ntohl(x) (x)
#define ntoh(x) (x)
#define NTOH(x) (x) = ntoh(x)
#define NTOHL(x) (x) = ntohl(x)
#endif
#undef FALSE
#define FALSE 0
#undef TRUE
#define TRUE 1
#define false 0
#define true 1
#ifndef NULL
#define NULL (void *)0
#endif
#define BIT(n) (1UL << (n))
#define BitSET(REG,POS) ((REG) |= (1L << (POS)))
#define BitCLR(REG,POS) ((REG) &= (~(1L<< (POS))))
#define BitXOR(REG,POS) ((REG) ^= (~(1L << (POS))))
#define BitCHK_1(REG,POS) (((REG) & (1L << (POS))) == (1L << (POS)))
#define BitCHK_0(REG,POS) (((REG) & (1L << (POS))) == 0x00)
#define testBit(REG,POS) ((REG) & (1L << (POS)))
#define clrBit(x,y) (x) &= ~(1L << (y))
#define setBit(x,y) (x) |= (1L << (y))
#define readb(addr) *((volatile unsigned char*)(addr))
#define readw(addr) *((volatile unsigned short *)(addr))
#define readl(addr) *((volatile unsigned long*)(addr))
#define writeb(addr, val) *((volatile unsigned char*)(addr)) = (u8)(val)
#define writew(addr, val) *((volatile unsigned short *)(addr)) = (u16)(val)
#define writel(addr, val) *((volatile unsigned long*)(addr)) = (u32)(val)
#define ALIGN_4BYTE(size) ((size+3)&0xfffffffc)
#if CPU_ENDIAN == BIG_ENDIAN
#define __cpu_u16(lo, hi) ((lo)|((hi)<<8))
#elif CPU_ENDIAN == LITTLE_ENDIAN
#define __cpu_u16(lo, hi) ((hi)|((lo)<<8))
#else
#error "undefine cpu eadin"
#endif
#ifndef MIN
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#endif
#ifndef MAX
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#endif
#define ARRAY_SIZE(array) (sizeof(array)/sizeof(array[0]))
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
#define SFR(sfr, start, len, dat) \
(sfr = (sfr & ~((~(0xffffffff << (len))) << (start))) | \
(((dat) & (~(0xffffffff << (len)))) << (start)))
#include "generic/errno-base.h"
#include "string.h"
#include "strings.h"
#ifdef offsetof
#undef offsetof
#endif
#ifdef container_of
#undef container_of
#endif
#define offsetof(type, memb) \
((unsigned long)(&((type *)0)->memb))
#define container_of(ptr, type, memb) \
((type *)((char *)(ptr) - offsetof(type, memb)))
void delay(unsigned int);
void delay_us(unsigned int);
#endif
@@ -0,0 +1,133 @@
#ifndef VERSION_H
#define VERSION_H
#include "typedef.h"
typedef int (*version_t)(int);
//定义模块的版本号,由主版本号和次版本号组成
//如果两个模块的主版本号相同即表示兼容
#define VERSION(major, minor) (((major)<<8) | (minor))
#define MAJOR(v) ((v) >> 16)
#define MINOR(v) (((v) >> 8) & 0xff)
#define version_match(module_a, module_b) \
({ \
extern int module_a##_version(int ); \
extern int module_b##_version(int ); \
int version_a = module_a##_version(0); \
int version_b = module_b##_version(0); \
MAJOR(version_a) == MAJOR(version_b);\
})
#define __MODULE_VERSION_EXPORT_BEGIN(module, version) \
int module##_version(int prt) \
{ \
if (prt) { \
log_i(#module": %d.%d.%d build at: %s\n", (version)>>16, \
((version) >> 8) & 0xff, (version) & 0xff, __DATE__); \
} \
#define __MODULE_VERSION_EXPORT_END(module, version) \
return version; \
} \
const version_t __version_##module \
__attribute__((section(".lib_version"),used)) = module##_version
#define __MODULE_VERSION_EXPORT(module, version) \
__MODULE_VERSION_EXPORT_BEGIN(module, version) \
__MODULE_VERSION_EXPORT_END(module, version);
#define __MODULE_VERSION_EXPORT_SECTION(module, version, section) \
__MODULE_VERSION_EXPORT_BEGIN(module, version) \
(void *)&section; \
__MODULE_VERSION_EXPORT_END(module, version)
#define __MODULE_DEPEND_BEGIN(module) \
int module##_version_check() \
{ \
#define _MODULE_DEPEND_BEGIN(module) \
__MODULE_DEPEND_BEGIN(module)
#define __VERSION_CHECK(module, version) \
do { \
int module##_version(int prt); \
int v = module##_version(0); \
if (MAJOR(version) != MAJOR(v) || MINOR(version) > MINOR(v)) { \
log_i("=======version not match=======\n"); \
module##_version(1); \
log_i("==================================\n"); \
while(1); \
} \
} while(0)
/*-------------------上面的宏请勿调用------------------------------------*/
//定义当前模块的版本检测函数
#define MODULE_VERSION_EXPORT(module, version) \
__MODULE_VERSION_EXPORT(module, version)
#define MODULE_VERSION_EXPORT_SECTION(module, version, section) \
__MODULE_VERSION_EXPORT_SECTION(module, version, section)
#define MODULE_VERSION_EXPORT_BEGIN(module, version) \
__MODULE_VERSION_EXPORT_BEGIN(module, version)
#define MODULE_VERSION_EXPORT_END(module, version) \
__MODULE_VERSION_EXPORT_END(module, version)
//以下3个宏定义当前模块依赖的其它模块列表
#define MODULE_DEPEND_BEGIN() \
_MODULE_DEPEND_BEGIN(THIS_MODULE)
#define MODULE_DEPEND(module_d, version) \
__VERSION_CHECK(module_d, version)
#define MODULE_DEPEND_END() \
return 0; \
}
#define VERSION_CHECK(module, version) \
__VERSION_CHECK(module, version)
//通过调用版本检测函数使的模块的代码能够被链接
#define load_module(module) \
({ \
int ret; \
extern int module##_version_check(); \
ret = module##_version_check();\
ret; \
})
extern version_t lib_version_begin[], lib_version_end[];
#define lib_version_check() \
do { \
version_t *version; \
log_i("=========version check===========\n"); \
for (version = lib_version_begin; version < lib_version_end; version++) { \
(*version)(1); \
}; \
log_i("==================================\n\n"); \
} while (0)
#endif
@@ -0,0 +1,49 @@
#ifndef SYS_INIT_H
#define SYS_INIT_H
typedef int (*initcall_t)(void);
#define __initcall(fn) \
const initcall_t __initcall_##fn sec(.initcall) = fn
#define early_initcall(fn) \
const initcall_t __initcall_##fn sec(.early.initcall) = fn
#define late_initcall(fn) \
const initcall_t __initcall_##fn sec(.late.initcall) = fn
#define platform_initcall(fn) \
const initcall_t __initcall_##fn sec(.platform.initcall) = fn
#define module_initcall(fn) \
const initcall_t __initcall_##fn sec(.module.initcall) = fn
#define __do_initcall(prefix) \
do { \
initcall_t *init; \
extern initcall_t prefix##_begin[], prefix##_end[]; \
for (init=prefix##_begin; init<prefix##_end; init++) { \
(*init)(); \
} \
}while(0)
#endif
@@ -0,0 +1,50 @@
#ifndef MATH_FAST_FUNCTION
#define MATH_FAST_FUNCTION
struct data_q_struct {
long data;
char q;
};
extern long cos_fix(long x);
extern float cos_float(float x);
extern long sin_fix(long x);
extern float sin_float(float x);
extern struct data_q_struct complex_abs_fix(long x, long y);
extern struct data_q_struct complex_dqdt_fix(long x, long y);
extern float complex_abs_float(float x, float y);
extern float complex_dqdt_float(float x, float y);
extern struct data_q_struct root_fix(struct data_q_struct x);
extern float root_float(float x);
extern struct data_q_struct mul_fix(long x, long y);
extern float mul_float(float x, float y);
extern struct data_q_struct div_fix(long x, long y);
extern float div_float(float x, float y);
extern struct data_q_struct exp_fix(long x);
extern float exp_float(float x);
extern struct data_q_struct ln_fix(struct data_q_struct x);
extern float ln_float(float x);
extern struct data_q_struct atan_fix(long x, long y);
extern float atan_float(float x, float y);
extern struct data_q_struct atanh_fix(long x, long y);
extern float atanh_float(float x, float y);
extern long cosh_fix(long x);
extern float cosh_float(float x);
extern long sinh_fix(long x);
extern float sinh_float(float x);
extern struct data_q_struct log10_fix(struct data_q_struct x);
extern float log10_float(float x);
extern struct data_q_struct sigmoid_fix(float x);
extern float sigmoid_float(float x);
extern struct data_q_struct tanh_fix(float x);
extern float tanh_float(float x);
float dB_Convert_Mag(float x);
#endif
@@ -0,0 +1,117 @@
/***********************************Jieli tech************************************************
File : os_cpu.h
By : Juntham
date : 2014-07-03 09:06
********************************************************************************************/
#ifndef _OS_CPU_H
#define _OS_CPU_H
#include "asm/cpu.h"
#include "jiffies.h"
#ifndef __ASSEMBLY__
typedef unsigned short QS;
typedef unsigned int OS_STK; /* Each stack entry is 32-bit wide*/
typedef unsigned int OS_CPU_SR; /* Unsigned 32 bit quantity */
typedef unsigned int OS_CPU_DATA; /* Unsigned 32 bit quantity */
#endif
#define OS_CPU_EXT extern
#define OS_CPU_CORE CPU_CORE_NUM
#define OS_CPU_ID current_cpu_id()
#define OS_STK_GROWTH 1 /* Stack grows from HIGH to LOW memory*/
#define OS_CPU_MMU 0
#define OS_CPU_VIRTUAL_MEM 1 //临时定义:区别于OS_CPU_MMU
#ifndef OS_CORE_AFFINITY_ENABLE
#define OS_CORE_AFFINITY_ENABLE 0
#endif
#define OS_TASK_CLR(a) CPU_TASK_CLR(a)
#define OS_TASK_SW(a) CPU_TASK_SW(a) /* 任务级任务切换函数*/
#define OS_INT_NESTING CPU_INT_NESTING
#define CPU_SR_ALLOC()
#define OS_SR_ALLOC()
#define OS_ENTER_CRITICAL() \
CPU_CRITICAL_ENTER(); \
#define OS_EXIT_CRITICAL() \
CPU_CRITICAL_EXIT()
#ifndef __ASSEMBLY__
/*#include "system/spinlock.h"
extern spinlock_t os_lock;
#define OS_ENTER_CRITICAL() \
spin_lock(&os_lock)
#define OS_EXIT_CRITICAL() \
spin_unlock(&os_lock)*/
void OSCtxSw(void);
extern void EnableOtherCpu(void) ;
#define os_ctx_sw OSCtxSw
void OSInitTick(u32 hz);
void InstallOSISR(void);
void os_task_dead(const char *task_name);
//=======================================================//
// 系统进临界区多核同步类型 //
//=======================================================//
enum CPU_SUSPEND_TYPE {
CPU_SUSPEND_TYPE_NONE = 0,
CPU_SUSPEND_TYPE_SFC = 0x55, //操作Flash
CPU_SUSPEND_TYPE_PDOWN, //系统进低功耗Pdown
CPU_SUSPEND_TYPE_POFF, //系统进低功耗Pdown
CPU_SUSPEND_TYPE_SOFF,
};
/* ---------------------------------------------------------------------------- */
/**
* @brief 系统进入临界区用于多核同步
*/
/* ---------------------------------------------------------------------------- */
void cpu_suspend_other_core(enum CPU_SUSPEND_TYPE type);
/* ---------------------------------------------------------------------------- */
/**
* @brief 系统退出临界区用于多核同步
*/
/* ---------------------------------------------------------------------------- */
void cpu_resume_other_core(enum CPU_SUSPEND_TYPE type);
#endif
/*
*********************************************************************************************************
* DATA TYPES
* (Compiler Specific)
*********************************************************************************************************
*/
#define OS_CRITICAL_METHOD 3
#if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
//#define CPU_SR_ALLOC() OS_CPU_SR cpu_sr
#endif
#endif /*_OS_CPU_H */
@@ -0,0 +1,145 @@
#ifndef SYS_SPINLOCK_H
#define SYS_SPINLOCK_H
#include "typedef.h"
#include "cpu.h"
#include "irq.h"
struct __spinlock {
volatile u32 rwlock;
};
typedef struct __spinlock spinlock_t;
#if CPU_CORE_NUM > 1
#define preempt_disable() \
__local_irq_disable()
#define preempt_enable() \
__local_irq_enable()
#else
#define preempt_disable() \
local_irq_disable()
#define preempt_enable() \
local_irq_enable()
#endif
#if CPU_CORE_NUM > 1
#define spin_acquire(lock) \
do { \
arch_spin_lock(lock); \
}while(0)
#define spin_release(lock) \
do { \
arch_spin_unlock(lock); \
}while(0)
#else
#define spin_acquire(lock) \
do { \
}while(0)
#define spin_release(lock) \
do { \
}while(0)
#endif
#define DEFINE_SPINLOCK(x) \
spinlock_t x = { .rwlock = 0 }
static inline void spin_lock_init(spinlock_t *lock)
{
lock->rwlock = 0;
}
extern u32 spin_lock_cnt[];
#if 1
static inline void spin_lock(spinlock_t *lock)
{
preempt_disable();
/*ASSERT(spin_lock_cnt[current_cpu_id()] == 0);
spin_lock_cnt[current_cpu_id()] = 1;*/
spin_acquire(lock);
}
static inline void spin_unlock(spinlock_t *lock)
{
/*spin_lock_cnt[current_cpu_id()] = 0;*/
spin_release(lock);
preempt_enable();
}
#else
#define spin_lock(lock) \
do { \
preempt_disable(); \
if (!(T2_CON & (1<<0))) { \
T2_CNT = 0; \
T2_PRD = 120000000 / 10; \
T2_CON = 1; \
} \
spin_lock_cnt[current_cpu_id()] = T2_CNT; \
spin_acquire(lock); \
} while (0)
#define spin_unlock(lock) \
do { \
u32 t = T2_CNT;\
if(t < spin_lock_cnt[current_cpu_id()]) \
t += T2_PRD - spin_lock_cnt[current_cpu_id()]; \
else \
t -= spin_lock_cnt[current_cpu_id()]; \
spin_release(lock); \
preempt_enable(); \
if (t > 100000) { /*120000 == 1ms*/ \
printf("???????spinlock: %d, %s\n", t, __func__); \
} \
} while(0)
#endif
/*#define spin_lock_irqsave(lock, flags) \
do { \
local_irq_save(flags); \
spin_acquire((lock)); \
}while(0)
#define spin_unlock_irqrestore(lock, flags) \
do { \
spin_release((lock)); \
local_irq_restore(flags); \
}while(0) */
#endif
@@ -0,0 +1,50 @@
#ifndef SYS_TIME_H
#define SYS_TIME_H
#include "typedef.h"
struct sys_time {
u16 year;
u8 month;
u8 day;
u8 hour;
u8 min;
u8 sec;
};
#if 0
struct tm {
int tm_sec; /* Seconds. [0-60] (1 leap second) */
int tm_min; /* Minutes. [0-59] */
int tm_hour; /* Hours. [0-23] */
int tm_mday; /* Day. [1-31] */
int tm_mon; /* Month. [0-11] */
int tm_year; /* Year - 1900. */
int tm_wday; /* Day of week. [0-6] */
int tm_yday; /* Days in year.[0-365] */
int tm_isdst; /* DST. [-1/0/1]*/
# ifdef __USE_MISC
long int tm_gmtoff; /* Seconds east of UTC. */
const char *tm_zone; /* Timezone abbreviation. */
# else
long int __tm_gmtoff; /* Seconds east of UTC. */
const char *__tm_zone; /* Timezone abbreviation. */
# endif
};
#endif
#endif
@@ -0,0 +1,81 @@
#ifndef __FONT_ALL_H__
#define __FONT_ALL_H__
#include "generic/typedef.h"
#include "font/font_sdfs.h"
typedef struct {
u8 width;
u8 size;
u16 addr;
} ASCSTRUCT;
//标志位
#define FONT_GET_WIDTH 0x01
#define FONT_SHOW_PIXEL 0x02
#define FONT_SHOW_MULTI_LINE 0x04 /* 显示多行文本(默认显示一行) */
#define FONT_SHOW_SCROLL 0x08 /* 滚动显示*/
#define FONT_DEFAULT (FONT_SHOW_PIXEL)
#define FONT_ENCODE_ANSI 0x00
#define FONT_ENCODE_UNICODE 0x01
#define FONT_ENCODE_UTF8 0x02
#define FONT_ENDIAN_BIG 0x00
#define FONT_ENDIAN_SMALL 0x01
struct font_file {
char *name;
FILE *fd;
};
struct font {
struct font_file file;
u16 nbytes;
u8 size;
u8 *pixelbuf;
};
struct dispbuf {
int format;
u32 color;
void *rect;
void *map;
};
enum FONT_STATUS {
FT_ERROR_NONE,
FT_ERROR_NOPIXFILE = 0x01, //没有字模文件
FT_ERROR_NOASCPIXFILE = 0x02, //没有ASCII字模文件
FT_ERROR_NOTABFILE = 0x04, //没有TAB文件
FT_ERROR_NOMEM = 0x08, //内存不足
FT_ERROR_CODEPAGE = 0x10, //代码页错误
};
struct font_info {
struct font ascpixel; //ASCII像素
struct font pixel; //像素
struct font_file tabfile; //UNICODE转内码文件
u8 sta; //状态
u8 ratio; //放大倍数,默认为1
u8 language_id; //语言ID
u8 bigendian; //大端模式(unicode编码)
u8 isgb2312; //是否GB2312,用以区分GBK以及GB2312字库
u8 codepage; //代码页
u16 x;
u16 y;
u16 text_width; //文本宽度
u16 text_height; //文本高度
u16 string_width; //字符串宽度
u16 offset; //显示偏移
u32 flags; //标志位
struct dispbuf disp; //显示相关信息
void (*putchar)(struct font_info *info, u8 *pixel, u16 width, u16 height, u16 x, u16 y);
void *dc;
};
#define font_ntohl(x) (unsigned long)((x>>24)|((x>>8)&0xff00)|(x<<24)|((x&0xff00)<<8))
#define font_ntoh(x) (unsigned short int )((x>>8&0x00ff)|x<<8&0xff00)
extern struct font_info font_info_table[];
#endif
@@ -0,0 +1,22 @@
#ifndef __UI_SDFS_H__
#define __UI_SDFS_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "generic/typedef.h"
#include "fs/fs.h"
#define SD_SEEK_SET 0x00
#define SD_SEEK_CUR 0x01
FILE *font_sd_fopen(const char *filename, void *arg);
int font_sd_fread(FILE *fp, void *buf, u32 len);
int font_sd_fseek(FILE *fp, u8 seek_mode, u32 offset);
#ifdef __cplusplus
}
#endif
#endif
@@ -0,0 +1,103 @@
#ifndef __FONT_OUT_H__
#define __FONT_OUT_H__
#include "generic/typedef.h"
#include "font/font_all.h"
/**
* @brief 打开字库
*
* @param info:字库信息
* @param language:语言
*
* @returns TRUE:打开成功 FALSE:打开失败
*/
struct font_info *font_open(struct font_info *info, u8 language);
/**
* @brief 获取字符宽度
*
* @param info
* @param str
* @param strlen
*
* @returns
*/
u16 font_text_width(struct font_info *info, u8 *str, u16 strlen);
u16 font_textw_width(struct font_info *info, u8 *str, u16 strlen);
u16 font_textu_width(struct font_info *info, u8 *str, u16 strlen);
/**
* @brief 字库内码显示接口
*
* @param info
* @param str
* @param strlen
*
* @returns
*/
u16 font_textout(struct font_info *info, u8 *str, u16 strlen, u16 x, u16 y);
/**
* @brief 字库unicode显示接口
*
* @param info
* @param str
* @param strlen
* @param x
* @param y
*
* @returns
*/
u16 font_textout_unicode(struct font_info *info, u8 *str, u16 strlen, u16 x, u16 y);
/**
* @brief 字库utf8显示接口
*
* @param info
* @param str
* @param strlen
* @param x
* @param y
*
* @returns
*/
u16 font_textout_utf8(struct font_info *info, u8 *str, u16 strlen, u16 x, u16 y);
/**
* @brief utf8转内码
*
* @param info
* @param utf8
* @param utf8len
* @param ansi
*
* @returns
*/
u16 font_utf8toansi(struct font_info *info, u8 *utf8, u16 utf8len, u8 *ansi);
/**
* @brief utf16转内码
*
* @param info
* @param utf
* @param len
* @param ansi
*
* @returns
*/
u16 font_utf16toansi(struct font_info *info, u8 *utf, u16 len, u8 *ansi);
/**
* @brief utf8转utf16
*
* @param info
* @param utf8
* @param utf8len
* @param utf16
*
* @returns
*/
u16 font_utf8toutf16(struct font_info *info, u8 *utf8, u16 utf8len, u16 *utf16);
/**
* @brief 字库关闭
*
* @param info
*/
void font_close(struct font_info *info);
#endif
@@ -0,0 +1,28 @@
#ifndef __LANGUAGE_LIST_H__
#define __LANGUAGE_LIST_H__
#define Chinese_Simplified 1 //简体中文
#define Chinese_Traditional 2 //繁体中文
#define Japanese 3 //日语
#define Korean 4 //韩语
#define English 5 //英语
#define French 6 //法语
#define German 7 //德语
#define Italian 8 //意大利语
#define Dutch 9 //荷兰语
#define Portuguese 10 //葡萄牙语
#define Spanish 11 //西班牙语
#define Swedish 12 //瑞典语
#define Czech 13 //捷克语
#define Danish 14 //丹麦语
#define Polish 15 //波兰语
#define Russian 16 //俄语
#define Turkey 17 //土耳其语
#define Hebrew 18 //希伯来语
#define Thai 19 //泰语
#define Hungarian 20 //匈牙利语
#define Romanian 21 //罗马尼亚语
#define Arabic 22 //阿拉伯语
#define Vietnam 23 //越南语
#endif
@@ -0,0 +1,26 @@
#ifndef UI_INCLUDES_H
#define UI_INCLUDES_H
#include "ui/ui.h"
#include "res/resfile.h"
#include "res/font_ascii.h"
#define UI_TOUCH_DEBUG 1
#if (UI_TOUCH_DEBUG == 1)
#define UI_ONTOUCH_DEBUG log_d
#else
#define UI_ONTOUCH_DEBUG(...)
#endif
#endif
@@ -0,0 +1,23 @@
#ifndef FONT_ASCII_H
#define FONT_ASCII_H
#include "typedef.h"
int font_ascii_get_pix(char code, u8 *pixbuf, int buflen, int *height, int *width);
int font_ascii_width_check(const char *str);
#endif
@@ -0,0 +1,48 @@
#ifndef RESFILE_H
#define RESFILE_H
#include "typedef.h"
//#include "fs/fs.h"
#define FILE_TYPE_JPEG 5
#define AT_UI_RAM //AT(.ui_ram)
struct image_file {
u8 format;
u8 compress;
u16 data_crc;
u16 width;
u16 height;
u32 offset;
u32 len;
};
int open_resfile(const char *name);
void close_resfile();
int res_file_version_compare(int res_ver);
int open_str_file(const char *name);
void close_str_file();
int str_file_version_compare(int str_ver);
int open_style_file(const char *name);
int font_ascii_init(const char *name);
int open_image_by_id(struct image_file *f, int id, int page);
int read_image_data(struct image_file *f, u8 *data, int len);
int br23_read_image_data(struct image_file *f, u8 *data, int len, int offset);
u32 image_decode(const void *pSour, void *pDest, u32 SourLen, u32 DestLen, u8 compress);
int open_string_pic(struct image_file *file, int id);
int read_str_data(struct image_file *f, u8 *data, int len);
int br23_read_str_data(struct image_file *f, u8 *data, int len, int offset);
int load_pallet_table(int id, u32 *data);
int ui_language_set(int language);
int ui_language_get();
FILE *res_fopen(const char *path, const char *mode);
int res_fread(FILE *_file, void *buf, u32 len);
int res_fseek(FILE *_file, int offset, int fromwhere);
int res_fclose(FILE *file);
#endif
@@ -0,0 +1,19 @@
#ifndef __RLE_H__
#define __RLE_H__
//#include "system/includes.h"
struct rle_header {
u32 addr: 22; //max 4M
u32 len: 10; //max 1024 bytes
};
struct rle_line {
u32 addr: 23;
u32 num: 9;
u16 len[0];
};
int Rle_Decode(u8 *inbuf, int inSize, u8 *outbuf, int onuBufSize, int offset, int len);
#endif
@@ -0,0 +1,339 @@
#ifndef UI_CONTROL_H
#define UI_CONTROL_H
#include "ui/ui_core.h"
union ui_control_info;
struct layout_info;
#define CTRL_TYPE_WINDOW 2
#define CTRL_TYPE_LAYOUT 3
#define CTRL_TYPE_LAYER 4
#define CTRL_TYPE_GRID 5
#define CTRL_TYPE_LIST 6
#define CTRL_TYPE_BUTTON 7
#define CTRL_TYPE_PIC 8
#define CTRL_TYPE_BATTERY 9
#define CTRL_TYPE_TIME 10
#define CTRL_TYPE_CAMERA_VIEW 11
#define CTRL_TYPE_TEXT 12
#define CTRL_TYPE_ANIMATION 13
#define CTRL_TYPE_PLAYER 14
#define CTRL_TYPE_NUMBER 15
#define CTRL_TYPE_PROGRESS 30
#define CTRL_PROGRESS_CHILD_BEGIN (CTRL_TYPE_PROGRESS + 1)
#define CTRL_PROGRESS_CHILD_HIGHLIGHT (CTRL_PROGRESS_CHILD_BEGIN)
#define CTRL_PROGRESS_CHILD_END (CTRL_PROGRESS_CHILD_BEGIN + 1)
#define CTRL_TYPE_MULTIPROGRESS 32
#define CTRL_MULTIPROGRESS_CHILD_BEGIN (CTRL_TYPE_MULTIPROGRESS + 1)
#define CTRL_MULTIPROGRESS_CHILD_HIGHLIGHT (CTRL_MULTIPROGRESS_CHILD_BEGIN)
#define CTRL_MULTIPROGRESS_CHILD_END (CTRL_MULTIPROGRESS_CHILD_BEGIN + 1)
#define CTRL_TYPE_WATCH 40
#define CTRL_WATCH_CHILD_BEGIN (CTRL_TYPE_WATCH + 1)
#define CTRL_WATCH_CHILD_HOUR (CTRL_WATCH_CHILD_BEGIN)
#define CTRL_WATCH_CHILD_MIN (CTRL_WATCH_CHILD_BEGIN+1)
#define CTRL_WATCH_CHILD_SEC (CTRL_WATCH_CHILD_BEGIN+2)
#define CTRL_WATCH_CHILD_END (CTRL_WATCH_CHILD_BEGIN+3)
#define CTRL_TYPE_SLIDER 50
#define SLIDER_CHILD_BEGIN (CTRL_TYPE_SLIDER+1)
#define SLIDER_CHILD_UNSELECT_PIC (SLIDER_CHILD_BEGIN)
#define SLIDER_CHILD_SELECTED_PIC (SLIDER_CHILD_BEGIN+1)
#define SLIDER_CHILD_SLIDER_PIC (SLIDER_CHILD_BEGIN+2)
#define SLIDER_CHILD_PERSENT_TEXT (SLIDER_CHILD_BEGIN+3)
#define SLIDER_CHILD_END (SLIDER_CHILD_BEGIN+4)
#define CTRL_TYPE_BROWSER 60
#define CTRL_TYPE_BROWSER_ITEM 61
#define CTRL_TYPE_FILE_ATTRS 70
#define CTRL_TYPE_FILE_PREVIEW 71
#define CTRL_TYPE_FILE_TYPE_ICON 72
#define CTRL_TYPE_FILE_RW_PIC 73
#define CTRL_TYPE_FILE_FILM_LEN 74
#define CTRL_TYPE_FILE_NAME 75
#define CTRL_TYPE_FILE_SIZE 76
#define CTRL_TYPE_FILE_CREATE_TIME 77
struct ui_ctrl_info_head {
u8 type;
u8 ctrl_num;
u8 css_num;
u8 len;
u8 page;
u8 rev[3];
int id;
struct element_css1 *css;
};
struct ui_image_list {
u16 num;
u16 image[0];
};
struct ui_text_list {
u16 num;
char str[0];
};
struct ui_image_list_t {
u16 num;
u16 image[16];
};
struct ui_text_list_t {
u16 num;
char str[4];
};
struct ui_button_info {
struct ui_ctrl_info_head head;
struct element_event_action *action;
};
struct ui_camera_info {
struct ui_ctrl_info_head head;
char device[8];
struct element_event_action *action;
};
struct ui_player_info {
struct ui_ctrl_info_head head;
char device[8];
struct element_event_action *action;
};
struct ui_time_info {
struct ui_ctrl_info_head head;
u8 auto_cnt;
u8 rev[3];
char format[16];
int color;
int hi_color;
u16 number[10];
u16 delimiter[10];
struct element_event_action *action;
};
struct ui_number_info {
struct ui_ctrl_info_head head;
char format[16];
int color;
int hi_color;
u16 number[10];
u16 delimiter[10];
u16 space[2];
struct element_event_action *action;
};
struct ui_pic_info {
struct ui_ctrl_info_head head;
u8 highlight;
u16 cent_x;
u16 cent_y;
struct ui_image_list *normal_img;
struct ui_image_list *highlight_img;
struct element_event_action *action;
};
struct ui_battery_info {
struct ui_ctrl_info_head head;
struct ui_image_list *normal_image;
struct ui_image_list *charge_image;
struct element_event_action *action;
};
struct ui_text_info {
struct ui_ctrl_info_head head;
char code[8];
int color;
int highlight_color;
struct ui_text_list *str;
struct element_event_action *action;
};
struct ui_grid_info {
struct ui_ctrl_info_head head;
u8 page_mode;
char highlight_index;
struct element_event_action *action;
struct layout_info *info;
};
struct ui_animation_info {
struct ui_ctrl_info_head head;
u16 loop_num;
u32 interval;
struct ui_image_list *img;
struct element_event_action *action;
};
struct ui_slider_info {
struct ui_ctrl_info_head head;
u8 step;
struct ui_ctrl_info_head *ctrl;
struct element_event_action *action;
};
struct ui_watch_info {
struct ui_ctrl_info_head head;
struct element_event_action *action;
struct ui_ctrl_info_head *ctrl;
};
struct ui_progress_info {
struct ui_ctrl_info_head head;
struct element_event_action *action;
struct ui_ctrl_info_head *ctrl;
};
struct ui_multiprogress_info {
struct ui_ctrl_info_head head;
struct element_event_action *action;
struct ui_ctrl_info_head *ctrl;
};
struct ui_browser_info {
struct ui_ctrl_info_head head;
u8 row;
u8 column;
u8 interval;
u8 scroll;
u8 auto_highlight;
struct element_event_action *action;
struct ui_ctrl_info_head *ctrl;
};
struct ui_fattrs_info {
struct ui_ctrl_info_head head;
struct element_event_action *action;
struct ui_ctrl_info_head *ctrl;
};
union ui_control_info {
struct ui_ctrl_info_head head;
struct ui_button_info button;
struct ui_camera_info camera;
struct ui_time_info time;
struct ui_number_info number;
struct ui_pic_info pic;
struct ui_battery_info battery;
struct ui_text_info text;
struct ui_grid_info grid;
};
struct layout_info {
struct ui_ctrl_info_head head;
struct element_event_action *action;
union ui_control_info *ctrl;
};
struct layer_info {
struct ui_ctrl_info_head head;
u8 format;
struct element_event_action *action;
struct layout_info *layout;
};
struct window_info {
u8 type;
u8 ctrl_num;
u8 css_num;
u8 len;
u8 rev[4];
struct rect rect;
struct layer_info *layer;
// struct element_event_action *action;
};
struct control_ops {
int type;
void *(*new)(const void *, struct element *);
/*int (*delete)(void *);*/
};
extern const struct control_ops control_ops_begin[];
extern const struct control_ops control_ops_end[];
#define REGISTER_CONTROL_OPS(_type) \
static const struct control_ops control_ops_##_type sec(.control_ops) __attribute__((used)) = { \
.type = _type,
#define get_control_ops_by_type(_type) \
({ \
const struct control_ops *ops, *ret=NULL; \
for (ops = control_ops_begin; ops < control_ops_end; ops++) { \
if (ops->type == _type) { \
ret = ops; \
break; \
} \
}\
ret; \
})
#if 0
struct control_event_header {
int id;
int len;
};
extern struct control_event_header control_event_handler_begin[];
extern struct control_event_header control_event_handler_end[];
#define REGISTER_CONTROL_EVENT_HANDLER(control, _id) \
static const struct control##_event_handler __##control##_event_handler_##_id \
sec(.control_event_handler) = { \
.header = { \
.id = _id, \
.len = sizeof(struct control##_event_handler), \
}, \
static inline void *control_event_handler_for_id(int id)
{
struct control_event_header *p;
for (p = control_event_handler_begin; p < control_event_handler_end;) {
if (p->id == id) {
return p;
}
p = (u8 *)p + p->len;
}
return NULL;
}
#endif
#endif
@@ -0,0 +1,53 @@
#ifndef LAYER_H
#define LAYER_H
#include "ui/layout.h"
#include "ui/control.h"
struct layer {
struct element elm; //must be first
u8 hide;
u8 inited;
u8 highlight;
u8 ctrl_num;
u8 css_num;
u16 css[2];
struct draw_context dc;
struct layout *layout;
const struct layer_info *info;
const struct element_event_handler *handler;
};
#define layer_for_id(id) \
(struct layer *)ui_core_get_element_by_id(id);
struct layer *layer_new(struct layer_info *info, int num, struct element *parent);
void layer_delete_probe(struct layer *layer, int num);
void layer_delete(struct layer *layer, int num);
int layer_show(int id);
int layer_hide(int id);
int layer_toggle(int id);
#endif
@@ -0,0 +1,54 @@
#ifndef LAYOUT_H
#define LAYOUT_H
#include "ui/ui_core.h"
#include "ui/control.h"
struct layout {
struct element elm; //must be first
u8 hide: 1;
u8 inited: 1;
u8 release: 1;
u8 css_num: 5;
u16 css[2];
struct layout *layout;
const struct layout_info *info;
const struct element_event_handler *handler;
};
#define layout_for_id(id) \
(struct layout *)ui_core_get_element_by_id(id);
struct layout *layout_new(struct layout_info *, int, struct element *);
void layout_delete_probe(struct layout *layout, int num);
void layout_delete(struct layout *layout, int num);
int layout_show(int id);
int layout_hide(int id);
int layout_toggle(int id);
void layout_on_focus(struct layout *layout);
void layout_lose_focus(struct layout *layout);
/*int layout_current_highlight(int id);*/
/*int layout_onkey(struct layout *layout, struct element_key_event *e);*/
#endif
@@ -0,0 +1,110 @@
#ifndef _LYRICS_H_
#define _LYRICS_H_
#include "typedef.h"
#include "system/fs/fs.h"
#define LRC_SIZEOF_ALIN(var, al) ((((var)+(al)-1)/(al))*(al))
//类型声明区
typedef struct _TIME_LABEL { /*时间标签信息[mm:ss.ms]*/
u16 dbtime_s; //time of label,unit:s
u8 btime_100ms; //time of label,unit:ms
u8 btext_len; //the length of lrc content, 占用的实际字节数
u32 wline_pos; //for record next (byte addr) after the (real label of time)
} TIME_LABEL;
typedef struct __LRC_FILE_IO {
u32(*seek)(FILE *file, int offset, int orig);
u32(*read)(FILE *file, void *buf, u32 len);
} LRC_FILE_IO;
typedef struct _LABEL_INFO { /*标签处理后信息*/
u16 dbtime_base; //first of time
u16 dbtime_limit; //end of time
u8 base_100ms; //first of time
u8 limit_100ms; //first of time
u16 dblabel_cnt; //(real label of time) count
TIME_LABEL *g_plabel_buf; //解析过程中时间标签存储buf
u8 *plabel_buf_tmp;
u16 plabel_buf_len; //解析过程中时间标签存储buf长度
} LABEL_INFO;
typedef struct _SORTING_INFO { /*文件解析信息*/
u16 dbnow_fp_addr;//current addr of file pointer
u8 bdata_len; //the length of lrc content
u8 bis_next_file;//jump to next file
} SORTING_INFO;
typedef struct __LRC_FILE {
void *hdl;
LRC_FILE_IO *_io;
} LRC_FILE;
typedef struct _LRC_INFO { ///</*lrc显示信息*/
u8 coding_type; ///<歌词unicode编码格式
///<显示相关的
u8 bis_lrc_update; ///<lrc显示歌词更新标志
u8 broll_speed_control; ///<lrc显示滚动速度控制标志
u8 blcd_roll_speed; ///<lcd显示歌词内容滚动速度
u8 content_len; ///<当前歌词内容长度
u8 lrc_data_len; ///<实际歌词显示内容长度
//CFG
u16 blrc_buf_len; ///<lrc显示内容buf长度,配置
u8 *blrc_buf; ///<lrc显示内容buf地址
///<file相关的,CFG
u8 *lrc_read_buf; ///<lrc读取数据buffer
LRC_FILE file; ///lrc文件操作控制
/* void *lrc_file_hdl; ///<lrc文件句柄 */
u32 cur_faddr; ///当前文件文件位置
u16 once_read_len; ///<一次读取的长度,需要配置
u16 real_len; ///<真实一次读取到的数据长度
u16 data_len_count; ///<缓存中已分析的数据offset
u16 label_id; ///<时间标签读取id0~
u16 lrc_label_len; ///<解析后标签数据长度
bool bfirst_lable; ///<第一个时间标签标记
bool blast_lable; ///<最后一个时间标签标记
u8 lrc_text_id; ///text id
u8 read_next_lrc_flag; ///是否预读下一条歌词lrc
u8 save_flash;
SORTING_INFO *sorting; ///<歌词文件解析信息
LABEL_INFO *lab_info; ///<标签处理后信息
void (*roll_speed_ctrl_cb)(u8 lrc_len, u32 time_gap, u8 *roll_speed);///翻页速度控制
void (*clr_lrc_disp_cb)(void);
} LRC_INFO;
typedef struct __LRC_CFG {
u16 once_read_len;///一次读取长度配置
u16 once_disp_len;///一次显示缓存长度配置
u16 label_temp_buf_len;///时间标签缓存总长度配置
u8 lrc_text_id; ///text id
u8 read_next_lrc_flag; ///是否预读下一条歌词lrc
u8 enable_save_lable_to_flash;//使能保存时间标签到flash,主要是解决长歌词文件不支持问题
void (*roll_speed_ctrl_cb)(u8 lrc_len, u32 time_gap, u8 *roll_speed);///速度控制配置
void (*clr_lrc_disp_cb)(void);///清屏回调
} LRC_CFG;
extern void lrc_destroy(void);
extern int lrc_param_init(LRC_CFG *cfg, u8 *lrc_info_buf);
extern bool lrc_analysis(void *lrc_handle, const LRC_FILE_IO *file_io);
extern bool lrc_get(u16 dbtime_s, u8 btime_100ms);
extern bool lrc_show(int text_id, u16 dbtime_s, u8 btime_100ms);
extern void lrc_label_save_to_flash_init(u32 addr, u32 len, u32 base_addr);
#endif
@@ -0,0 +1,39 @@
#ifndef UI_P_H
#define UI_P_H
#include "ui/ui_core.h"
struct ui_str {
const char *format;
char *str;
};
struct element_text {
struct element elm; //must be first
char *str;
const char *format;
void *priv;
int color;
const struct element_event_handler *handler;
};
void text_element_set_text(struct element_text *text, char *str,
const char *format, int color);
void text_element_init(struct element_text *text, int id,
const struct element_css1 *css,
const struct element_event_action *action);
void text_element_set_event_handler(struct element_text *text, void *priv,
const struct element_event_handler *handler);
#endif
@@ -0,0 +1,72 @@
#ifndef UI_CORE_H
#define UI_CORE_H
#include "window.h"
#include "ui_button.h"
#include "ui_grid.h"
#include "ui_time.h"
#include "ui_camera.h"
#include "ui_pic.h"
#include "ui_text.h"
#include "ui_battery.h"
#include "ui_browser.h"
#include "ui_slider.h"
#include "ui_number.h"
#include "ui_watch.h"
#include "ui_progress.h"
#include "ui_progress_multi.h"
#include <stdarg.h>
struct uimsg_handl {
const char *msg;
int (*handler)(const char *type, u32 args);
};
int ui_framework_init(void *);
int ui_set_style_file(struct ui_style *style);
int ui_style_file_version_compare(int version);
int ui_show(int id);
int ui_hide(int id);
int ui_set_call(int (*func)(int), int param);
int ui_event_onkey(struct element_key_event *e);
int ui_event_ontouch(struct element_touch_event *e);
struct element *ui_get_highlight_child_by_id(int id);
int ui_invert_element_by_id(int id);
int ui_no_highlight_element(struct element *elm);
int ui_no_highlight_element_by_id(int id);
int ui_highlight_element(struct element *elm);
int ui_highlight_element_by_id(int id);
int ui_get_current_window_id();
int ui_register_msg_handler(int id, const struct uimsg_handl *handl);
int ui_message_handler(int id, const char *msg, va_list);
const char *str_substr_iter(const char *str, char delim, int *iter);
/*
* 锁定元素elm之外的区域,所有的触摸消息都发给elm
*/
void ui_ontouch_lock(void *elm);
void ui_ontouch_unlock(void *elm);
/*
* 锁定控件的夫图层,先不推向imb显示
*/
int ui_lock_layer(int id);
int ui_unlock_layer(int id);
int ui_get_disp_status_by_id(int id);
#endif
@@ -0,0 +1,71 @@
lcd_interface_begin = .;
KEEP(*(.lcd_if_info))
lcd_interface_end = .;
ui_style_begin = .;
KEEP(*(.ui_style))
ui_style_end = .;
elm_event_handler_begin_UPGRADE = .;
KEEP(*(.elm_event_handler_UPGRADE))
elm_event_handler_end_UPGRADE = .;
elm_event_handler_begin_JL = .;
KEEP(*(.elm_event_handler_JL))
elm_event_handler_end_JL = .;
elm_event_handler_begin_JL_01 = .;
KEEP(*(.elm_event_handler_JL_01))
elm_event_handler_end_JL_01 = .;
elm_event_handler_begin_JL_02 = .;
KEEP(*(.elm_event_handler_JL_02))
elm_event_handler_end_JL_02 = .;
elm_event_handler_begin_JL_03 = .;
KEEP(*(.elm_event_handler_JL_03))
elm_event_handler_end_JL_03 = .;
control_event_handler_begin = .;
KEEP(*(.control_event_handler))
control_event_handler_end = .;
control_ops_begin = .;
KEEP(*(.control_ops))
control_ops_end = .;
vg_event_handler_begin = .;
*(.vg_event_handler)
vg_event_handler_end = .;
on_show_map_begin = .;
*(.on_show_map)
on_show_map_end = .;
on_click_map_begin = .;
*(.on_click_map)
on_click_map_end = .;
on_touch_map_begin = .;
*(.on_touch_map)
on_touch_map_end = .;
on_change_map_begin = .;
*(.on_change_map)
on_change_map_end = .;
on_key_map_begin = .;
*(.on_key_map)
on_key_map_end = .;
img_loader_begin = .;
*(.img_loader)
img_loader_end = .;
battery_notify_begin = .;
*(.battery_notify)
battery_notify_end = .;
@@ -0,0 +1,29 @@
#ifndef UI_BATTERY_H
#define UI_BATTERY_H
#include "ui/control.h"
#include "list.h"
struct ui_battery {
struct element elm;
int src;
u8 index;
u16 charge_image;
u16 normal_image;
struct list_head entry;
const struct ui_battery_info *info;
const struct element_event_handler *handler;
};
void ui_battery_enable();
void ui_battery_level_change(int persent, int incharge);//改变所有电池控件
int ui_battery_set_level_by_id(int id, int persent, int incharge);//修改指定id
int ui_battery_set_level(struct ui_battery *battery, int persent, int incharge);//初始化使用
#endif
@@ -0,0 +1,92 @@
#ifndef UI_BROWSER_H
#define UI_BROWSER_H
#include "ui/ui_core.h"
#include "ui/control.h"
struct ui_browser {
struct element elm;
struct ui_file_browser *hdl;
char order; // 1 ±íʾ ÕýÐò£¬ ·Ç1 ±íʾ·´Ðò
u8 inited;
u8 hide_byself;
u8 item_num;
u8 highlight;
u8 show_mode;
u16 cur_number;
u16 file_number;
struct ui_grid *grid;
const char *path;
const char *ftype;
const struct ui_browser_info *info;
const struct element_event_handler *handler;
};
#define ui_file_browser_cur_item(bro) ui_grid_cur_item(((struct ui_browser *)bro)->grid)
int ui_file_browser_page_num(struct ui_browser *bro);
int ui_file_browser_cur_page(struct ui_browser *bro, int *file_num);
int ui_file_browser_set_page(struct ui_browser *bro, int page);
int ui_file_browser_set_page_by_id(int id, int page);
int ui_file_browser_next_page(struct ui_browser *bro);
int ui_file_browser_next_page_by_id(int id);
int ui_file_browser_prev_page(struct ui_browser *bro);
int ui_file_browser_prev_page_by_id(int id);
int ui_file_browser_set_dir(struct ui_browser *bro, const char *path, const char *ftype);
int ui_file_browser_set_dir_by_id(int id, const char *path, const char *ftype);
int ui_file_browser_get_file_attrs(struct ui_browser *bro, int item,
struct ui_file_attrs *attrs);
int ui_file_browser_set_file_attrs(struct ui_browser *bro, int item,
struct ui_file_attrs *attrs);
void *ui_file_browser_open_file(struct ui_browser *bro, int item);
int ui_file_browser_del_file(struct ui_browser *bro, int item);
int ui_file_browser_highlight_item(struct ui_browser *bro, int item, bool yes);
void *ui_file_browser_get_child_by_id(struct ui_browser *bro, int item, int id);
#endif
@@ -0,0 +1,20 @@
#ifndef UI_BUTTON_H
#define UI_BUTTON_H
#include "ui/control.h"
#include "ui/ui_core.h"
struct button {
struct element elm;
u8 image_index;
u8 css_num;
u16 css[2];
const struct ui_button_info *info;
const struct element_event_handler *handler;
};
void ui_button_enable();
#endif
@@ -0,0 +1,34 @@
#ifndef UI_CAMERA_H
#define UI_CAMERA_H
#include "ui/control.h"
#include "ui/ui_core.h"
struct ui_camera {
struct element elm; //must be first
int fd;
const struct ui_camera_info *info;
const struct element_event_handler *handler;
};
#define ui_camera_for_id(id) \
(struct ui_camera*)ui_core_get_element_by_id(id)
void register_ui_camera_handler(const struct element_event_handler *handler);
int ui_camera_set_rect(int id, struct rect *r);
#endif
@@ -0,0 +1,537 @@
#ifndef UI_ELEMENT_CORE_H
#define UI_ELEMENT_CORE_H
#include "typedef.h"
#include "rect.h"
#include "system/event.h"
//#include "fs/fs.h"
#define UI_CTRL_BUTTON 0
struct element;
#ifdef offsetof
#undef offsetof
#endif
#ifdef container_of
#undef container_of
#endif
#define offsetof(type, memb) \
((unsigned long)(&((type *)0)->memb))
#define container_of(ptr, type, memb) \
((type *)((char *)ptr - offsetof(type, memb)))
enum ui_direction {
UI_DIR_UP,
UI_DIR_DOWN,
UI_DIR_LEFT,
UI_DIR_RIGHT,
};
enum ui_align {
UI_ALIGN_LEFT = 0,
UI_ALIGN_CENTER,
UI_ALIGN_RIGHT,
};
enum {
POSITION_ABSOLUTE = 0,
POSITION_RELATIVE = 1,
};
enum {
ELM_EVENT_TOUCH_DOWN,
ELM_EVENT_TOUCH_MOVE,
ELM_EVENT_TOUCH_R_MOVE,
ELM_EVENT_TOUCH_L_MOVE,
ELM_EVENT_TOUCH_D_MOVE,
ELM_EVENT_TOUCH_U_MOVE,
ELM_EVENT_TOUCH_HOLD,
ELM_EVENT_TOUCH_UP,
};
enum {
ELM_EVENT_KEY_CLICK,
ELM_EVENT_KEY_LONG,
ELM_EVENT_KEY_HOLD,
};
enum {
ELM_STA_INITED,
//ELM_STA_SHOW_PROBE,
//ELM_STA_SHOW_POST,
ELM_STA_HIDE,
ELM_STA_SHOW,
ELM_STA_PAUSE,
};
enum {
ELM_FLAG_NORMAL,
ELM_FLAG_HEAD,
};
enum {
DC_DATA_FORMAT_OSD8 = 0,
DC_DATA_FORMAT_YUV420 = 1,
DC_DATA_FORMAT_OSD16 = 2,
DC_DATA_FORMAT_OSD8A = 3,
DC_DATA_FORMAT_MONO = 4,
};
struct element_touch_event {
int event;
int xoffset;
int yoffset;
u8 hold_up;
u8 onfocus;
u8 move_dir;
struct position pos;
struct position mov;
void *private_data;
};
struct element_key_event {
u8 event;
u8 value;
void *private_data;
};
#define ELM_KEY_EVENT(e) (0x0000 | (e->event) | (e->value << 8))
#define ELM_TOUCH_EVENT(e) (0x1000 | (e->event))
#define ELM_CHANGE_EVENT(e) (0x2000 | (e->event))
enum element_change_event {
ON_CHANGE_INIT_PROBE,
ON_CHANGE_INIT,
ON_CHANGE_TRY_OPEN_DC,
ON_CHANGE_FIRST_SHOW,
ON_CHANGE_SHOW_PROBE,
ON_CHANGE_SHOW,
ON_CHANGE_SHOW_POST,
ON_CHANGE_HIDE,
ON_CHANGE_HIGHLIGHT,
ON_CHANGE_RELEASE_PROBE,
ON_CHANGE_RELEASE,
ON_CHANGE_ANIMATION_END,
ON_CHANGE_SHOW_COMPLETED,
};
struct element_event_handler {
int id;
int (*ontouch)(void *, struct element_touch_event *);
int (*onkey)(void *, struct element_key_event *);
int (*onchange)(void *, enum element_change_event, void *);
};
struct jaction {
u32 show;
u32 hide;
};
enum {
ELM_ACTION_HIDE = 0,
ELM_ACTION_SHOW,
ELM_ACTION_TOGGLE,
ELM_ACTION_HIGHLIGHT,
};
struct event_action {
u16 event;
u16 action;
int id;
u8 argc;
char argv[];
};
struct element_event_action {
u16 num;
struct event_action action[0];
};
struct draw_context {
u8 ref;
u8 alpha;
u8 align;
u8 data_format;
u8 page;
u8 buf_num;
u32 background_color;
void *handl;
struct element *elm;
struct rect rect;
struct rect draw;
void *dc;
struct rect need_draw;
struct rect disp;
u16 width;
u16 height;
u8 *fbuf;
u32 fbuf_len;
u8 *buf;
u8 *buf0;
u8 *buf1;
u32 len;
u16 lines;
u8 col_align;
u8 row_align;
u8 *mask;
};
struct css_border {
u16 left: 4;
u16 top: 4;
u16 right: 4;
u16 bottom: 4;
u16 color: 16;
};
struct css_border1 {
u8 left;
u8 top;
u8 right;
u8 bottom;
int color: 24;
};
struct element_css {
u8 align: 2;
u8 invisible: 1;
u8 z_order: 5;
int left/* : 16 */;
int top/* : 16 */;
int width/* : 16 */;
int height/* : 16 */;
u32 background_color: 24;
u32 alpha: 8;
int background_image: 24;
int image_quadrant: 8;
struct css_border border;
};
struct element_css1 {
u8 align;
u8 invisible;
u8 z_order;
int left;
int top;
int width;
int height;
u32 background_color: 24;
u32 alpha: 8;
int background_image: 24;
int image_quadrant: 8;
struct css_border1 border;
};
struct element_ops {
int (*show)(struct element *);
int (*redraw)(struct element *, struct rect *);
};
struct element {
u8 highlight: 1;
u8 state: 2;
u8 ref: 6;
// u32 alive;
int id;
struct element *parent;
struct list_head sibling;
struct list_head child;
struct element *focus;
struct element_css css;
struct draw_context *dc;
// const struct element_ops *ops;
const struct element_event_handler *handler;
// const struct element_event_action *action;
};
struct ui_style {
const char *file;
u32 version;
};
enum {
UI_FTYPE_VIDEO = 0,
UI_FTYPE_IMAGE,
UI_FTYPE_AUDIO,
UI_FTYPE_DIR,
UI_FTYPE_UNKNOW = 0xff,
};
struct ui_file_attrs {
char *format;
char fname[128];
// struct vfs_attr attr;
u8 ftype;
u16 file_num;
u32 film_len;
};
struct ui_image_attrs {
u16 width;
u16 height;
};
struct ui_text_attrs {
const char *str;
const char *format;
int color;
u16 strlen;
u16 offset;
u8 encode: 2;
u8 endian: 1;
u8 flags: 5;
// u16 offset;
u8 displen;
};
struct ui_file_browser {
int file_number;
u8 dev_num;
void *private_data;
};
#define ELEMENT_ALIVE 0x53547a7b
#define element_born(elm) \
elm->alive = ELEMENT_ALIVE
#define element_alive(elm) \
(elm->alive == ELEMENT_ALIVE)
#define list_for_each_child_element(p, elm) \
list_for_each_entry(p, &(elm)->child, sibling)
#define list_for_each_child_element_reverse(p, n, elm) \
list_for_each_entry_reverse_safe(p, n, &(elm)->child, sibling)
#define list_for_each_child_element_safe(p, n, elm) \
list_for_each_entry_safe(p, n, &(elm)->child, sibling)
struct ui_platform_api {
void *(*malloc)(int);
void (*free)(void *);
int (*load_style)(struct ui_style *);
void *(*load_window)(int id);
void (*unload_window)(void *);
int (*open_draw_context)(struct draw_context *);
int (*get_draw_context)(struct draw_context *);
int (*put_draw_context)(struct draw_context *);
int (*set_draw_context)(struct draw_context *);
int (*close_draw_context)(struct draw_context *);
int (*fill_rect)(struct draw_context *, u32 color);
int (*draw_rect)(struct draw_context *, struct css_border *border);
int (*draw_image)(struct draw_context *, u32 src, u8 quadrant, u8 *mask);
int (*draw_point)(struct draw_context *, u16 x, u16 y, u32 color);
u32(*read_point)(struct draw_context *dc, u16 x, u16 y);
int (*invert_rect)(struct draw_context *, u32 color);
void *(*load_widget_info)(void *_head, u8 page);
void *(*load_css)(void *_css);
void *(*load_image_list)(void *_list);
void *(*load_text_list)(void *__list);
//int (*highlight)(struct draw_context *);
int (*show_text)(struct draw_context *, struct ui_text_attrs *);
int (*read_image_info)(struct draw_context *, u32, u8, struct ui_image_attrs *);
int (*open_device)(struct draw_context *, const char *device);
int (*close_device)(int);
void *(*set_timer)(void *, void (*callback)(void *), u32 msec);
int (*del_timer)(void *);
struct ui_file_browser *(*file_browser_open)(struct rect *r,
const char *path, const char *ftype, int show_mode);
int (*get_file_attrs)(struct ui_file_browser *, struct ui_file_attrs *attrs);
int (*set_file_attrs)(struct ui_file_browser *, struct ui_file_attrs *attrs);
int (*clear_file_preview)(struct ui_file_browser *, struct rect *r);
int (*show_file_preview)(struct ui_file_browser *, struct rect *r, struct ui_file_attrs *attrs);
int (*flush_file_preview)(struct ui_file_browser *);
void *(*open_file)(struct ui_file_browser *, struct ui_file_attrs *attrs);
int (*delete_file)(struct ui_file_browser *, struct ui_file_attrs *attrs);
int (*move_file_preview)(struct ui_file_browser *_bro, struct rect *dst, struct rect *src);
void (*file_browser_close)(struct ui_file_browser *);
};
extern /* const */ struct ui_platform_api *platform_api;
extern const struct element_event_handler dumy_handler;
struct janimation {
u8 persent[5];
u8 direction;
u8 play_state;
u8 iteration_count;
u16 delay;
u16 duration;
struct element_css css[0];
};
extern struct element_event_handler *elm_event_handler_begin;
extern struct element_event_handler *elm_event_handler_end;
#define ___REGISTER_UI_EVENT_HANDLER(style, _id) \
static const struct element_event_handler element_event_handler_##_id \
sec(.elm_event_handler_##style) __attribute__((used)) = { \
.id = _id,
#define __REGISTER_UI_EVENT_HANDLER(style, _id) \
___REGISTER_UI_EVENT_HANDLER(style, _id)
#define REGISTER_UI_EVENT_HANDLER(id) \
__REGISTER_UI_EVENT_HANDLER(STYLE_NAME, id)
struct ui_style_info {
const char *name;
struct element_event_handler *begin;
struct element_event_handler *end;
};
extern struct ui_style_info ui_style_begin[];
extern struct ui_style_info ui_style_end[];
#define __REGISTER_UI_STYLE(style_name) \
extern struct element_event_handler elm_event_handler_begin_##style_name[]; \
extern struct element_event_handler elm_event_handler_end_##style_name[]; \
static const struct ui_style_info ui_style_##style_name sec(.ui_style) __attribute__((used)) = { \
.name = #style_name, \
.begin = elm_event_handler_begin_##style_name, \
.end = elm_event_handler_end_##style_name, \
};
#define REGISTER_UI_STYLE(style_name) \
__REGISTER_UI_STYLE(style_name)
static inline struct element_event_handler *element_event_handler_for_id(u32 id)
{
struct element_event_handler *p;
for (p = elm_event_handler_begin; p < elm_event_handler_end; p++) {
if (p->id == id) {
return p;
}
}
return NULL;
}
#define ui_core_get_element_css(elm) \
&((struct element *)(elm))->css
#define ui_core_element_invisable(elm, i) \
((struct element *)(elm))->css.invisible = i
int ui_core_init(const struct ui_platform_api *api, struct rect *rect);
int ui_core_set_style(const char *style);
void ui_core_set_rotate(int _rotate);
int ui_core_get_rotate();
void *ui_core_malloc(int size);
void ui_core_free(void *buf);
void ui_core_element_init(struct element *, u32 id,
struct element_css1 *,
const struct element_event_handler *,
const struct element_event_action *);
void ui_core_get_element_abs_rect(struct element *elm, struct rect *rect);
void ui_core_append_child(void *_child);
struct element *ui_core_get_first_child();
void ui_core_remove_element(void *_child);
int ui_core_open_draw_context(struct draw_context *dc, struct element *elm);
int ui_core_close_draw_context(struct draw_context *dc);
int ui_core_show(void *_elm, int init);
int ui_core_hide(void *_elm);
struct element *get_element_by_id(struct element *elm, u32 id);
struct element *ui_core_get_element_by_id(u32 id);
int ui_core_get_disp_status_by_id(u32 id);
struct element *ui_core_get_up_element(struct element *elm);
struct element *ui_core_get_down_element(struct element *elm);
struct element *ui_core_get_left_element(struct element *elm);
struct element *ui_core_get_right_element(struct element *elm);
int ui_core_element_ontouch(struct element *, struct element_touch_event *e);
int ui_core_ontouch(struct element_touch_event *e);
int ui_core_element_onkey(struct element *elm, struct element_key_event *e);
int ui_core_onkey(struct element_key_event *e);
void ui_core_element_append_child(struct element *parent, struct element *child);
struct element_css *ui_core_set_element_css(void *_elm, const struct element_css1 *css);
int ui_core_invert_rect(struct draw_context *dc);
void ui_core_release_child_probe(struct element *elm);
void ui_core_release_child(struct element *elm);
int ui_core_redraw(void *_elm);
int ui_core_highlight_element(struct element *elm, int yes);
void ui_core_element_on_focus(struct element *elm, int yes);
void ui_core_ontouch_lock(struct element *elm);
void ui_core_ontouch_unlock(struct element *elm);
int ui_core_get_draw_context(struct draw_context *dc, struct element *elm, struct rect *draw);
#endif
@@ -0,0 +1,81 @@
#ifndef UI_GRID_H
#define UI_GRID_H
#include "ui/ui_core.h"
#include "ui/control.h"
enum {
GRID_SCROLL_MODE,
GRID_PAGE_MODE,
};
struct ui_grid_item_info {
u8 row;
u8 col;
u8 page_mode;
u8 highlight_index;
u16 interval;
struct layout_info *info;
};
struct ui_grid {
struct element elm;
char hi_num;
char hi_index;
char touch_index;
char onfocus;
u8 page_mode;
u8 col_num;
u8 row_num;
u8 show_row;
u8 show_col;
u8 avail_item_num;
u8 pix_scroll;
u8 rotate;
int x_interval;
int y_interval;
int max_show_left;
int max_show_top;
int min_show_left;
int min_show_top;
int max_left;
int max_top;
int min_left;
int min_top;
int scroll_step;
u8 ctrl_num;
struct layout *item;
struct layout_info *item_info;
struct element elm2;
struct position pos;
struct draw_context dc;
const struct ui_grid_info *info;
const struct element_event_handler *handler;
};
extern const struct element_event_handler grid_elm_handler;
static inline int ui_grid_cur_item(struct ui_grid *grid)
{
if (grid->touch_index >= 0) {
return grid->touch_index;
}
return grid->hi_index;
}
#define ui_grid_set_item(grid, index) (grid)->hi_index = index
void ui_grid_enable();
void ui_grid_on_focus(struct ui_grid *grid);
void ui_grid_lose_focus(struct ui_grid *grid);
void ui_grid_state_reset(struct ui_grid *grid, int highlight_item);
int ui_grid_highlight_item(struct ui_grid *grid, int item, bool yes);
int ui_grid_highlight_item_by_id(int id, int item, bool yes);
struct ui_grid *__ui_grid_new(struct element_css1 *css, int id,
struct ui_grid_item_info *info, struct element *parent);
#endif
@@ -0,0 +1,44 @@
#ifndef UI_NUMBER_H
#define UI_NUMBER_H
#include "ui/control.h"
#include "ui/ui_core.h"
#include "ui/p.h"
enum {
TYPE_NUM,
TYPE_STRING,
};
struct unumber {
u8 numbs;
u8 type;
u32 number[2];
u8 *num_str;
};
struct ui_number {
struct element_text text;
u16 number[2];
u16 buf[20];
int color;
int hi_color;
u8 css_num;
u8 nums: 6;
u8 type: 2;
u16 css[2];
u8 *num_str;
const struct ui_number_info *info;
const struct element_event_handler *handler;
};
void ui_number_enable();
void *new_ui_number(const void *_info, struct element *parent);
int ui_number_update_by_id(int id, struct unumber *n);
#endif
@@ -0,0 +1,25 @@
#ifndef UI_PIC_H
#define UI_PIC_H
#include "ui/ui_core.h"
struct ui_pic {
struct element elm;
char index;
u8 css_num;
u16 css[2];
u16 highlight_img;
u16 normal_img;
const struct ui_pic_info *info;
const struct element_event_handler *handler;
};
void ui_pic_enable();
void *new_ui_pic(const void *_info, struct element *parent);
int ui_pic_show_image_by_id(int id, int index);
int ui_pic_set_image_index(struct ui_pic *pic, int index);
#endif
@@ -0,0 +1,47 @@
#ifndef UI_PROGRESS_H
#define UI_PROGRESS_H
#include "ui/control.h"
#include "ui/ui_core.h"
#define PROGRESS_CHILD_NUM (CTRL_PROGRESS_CHILD_END - CTRL_PROGRESS_CHILD_BEGIN)
struct progress_highlight_info {
struct ui_ctrl_info_head head;
u16 center_x;
u16 center_y;
u16 radius_big;
u16 radius_small;
u16 angle_begin;
u16 angle_end;
struct ui_image_list *img;
};
struct ui_progress {
struct element elm;
struct element child_elm[PROGRESS_CHILD_NUM];
u16 center_x;
u16 center_y;
u16 radius;
u16 angle_begin;
u16 angle_end;
u8 ctrl_num;
char percent;
u8 *mask;
u16 mask_len;
void *timer;
const struct layout_info *info;
const struct progress_highlight_info *pic_info[PROGRESS_CHILD_NUM];
const struct element_event_handler *handler;
};
void ui_progress_enable();
void ui_progress_enable();
int ui_progress_set_persent_by_id(int id, int persent);
#endif
@@ -0,0 +1,54 @@
#ifndef UI_PROGRESS_MULTI_H
#define UI_PROGRESS_MULTI_H
#include "ui/control.h"
#include "ui/ui_core.h"
#define MULTIPROGRESS_CHILD_NUM (CTRL_MULTIPROGRESS_CHILD_END - CTRL_MULTIPROGRESS_CHILD_BEGIN)
struct multiprogress_highlight_info {
struct ui_ctrl_info_head head;
u16 number;
u16 center_x;
u16 center_y;
u16 radius0_big;
u16 radius0_small;
u16 radius1_big;
u16 radius1_small;
u16 radius2_big;
u16 radius2_small;
u16 angle_begin;
u16 angle_end;
struct ui_image_list *img;
};
struct ui_multiprogress {
struct element elm;
struct element child_elm[MULTIPROGRESS_CHILD_NUM];
u16 center_x;
u16 center_y;
u16 radius;
u16 angle_begin;
u16 angle_end;
u8 ctrl_num;
char percent[3];
u8 circle_num;
u8 index;
u8 *mask;
u16 mask_len;
void *timer;
const struct layout_info *info;
const struct multiprogress_highlight_info *pic_info[MULTIPROGRESS_CHILD_NUM];
const struct element_event_handler *handler;
};
void ui_multiprogress_enable();
int ui_multiprogress_set_persent_by_id(int id, int persent);
int ui_multiprogress_set_second_persent_by_id(int id, int percent);
int ui_multiprogress_set_third_persent_by_id(int id, int percent);
#endif
@@ -0,0 +1,38 @@
#ifndef UI_SLIDER_H
#define UI_SLIDER_H
#include "ui/ui_core.h"
#include "ui/control.h"
#define SLIDER_CHILD_NUM (SLIDER_CHILD_END - SLIDER_CHILD_BEGIN)
struct slider_text_info {
u8 move;
int min_value;
int max_value;
int text_color;
};
struct ui_slider {
struct element elm;
struct element child_elm[SLIDER_CHILD_NUM];
u8 step;
char persent;
s16 left;
s16 width;
s16 min_value;
s16 max_value;
u16 text_color;
const struct ui_slider_info *info;
const struct slider_text_info *text_info;
const struct element_event_handler *handler;
};
void ui_slider_enable();
int ui_slider_set_persent_by_id(int id, int persent);
#endif
@@ -0,0 +1,38 @@
#ifndef UI_TEXT_H
#define UI_TEXT_H
#include "ui/ui_core.h"
#include "ui/control.h"
#include "font/font_all.h"
struct ui_text {
struct element elm;
struct ui_text_attrs attrs;
void *timer;
char _str[4];
char _format[7];
u8 str_num: 4;
u8 css_num: 4;
u16 css[2];
int attr_color;
int attr_highlight_color;
// const struct ui_text_info *info;
const struct element_event_handler *handler;
};
void ui_text_enable();
void *new_ui_text(const void *_info, struct element *parent);
int ui_text_show_index_by_id(int id, int index);
int ui_text_set_index(struct ui_text *text, int index);
int ui_text_set_str(struct ui_text *text, const char *format, const char *str, int strlen, u32 flags);
int ui_text_set_str_by_id(int id, const char *format, const char *str);
int ui_text_set_text_by_id(int id, const char *str, int strlen, u32 flags);
int ui_text_set_textw_by_id(int id, const char *str, int strlen, int endian, u32 flags);
int ui_text_set_textu_by_id(int id, const char *str, int strlen, u32 flags);
void ui_text_set_text_attrs(struct ui_text *text, const char *str, int strlen, u8 encode, u8 endian, u32 flags);
void text_release(struct ui_text *text);
#endif
@@ -0,0 +1,41 @@
#ifndef UI_TIME_H
#define UI_TIME_H
#include "ui/control.h"
#include "ui/ui_core.h"
#include "ui/p.h"
struct utime {
u16 year;
u8 month;
u8 day;
u8 hour;
u8 min;
u8 sec;
};
struct ui_time {
struct element_text text;
u16 year: 12;
u16 month: 4;
u8 day;
u8 hour;
u8 min;
u8 sec;
u8 css_num;
u8 auto_cnt;
u16 css[2];
int color;
int hi_color;
u16 buf[20];
void *timer;
const struct ui_time_info *info;
const struct element_event_handler *handler;
};
void ui_time_enable();
void *new_ui_time(const void *_info, struct element *parent);
int ui_time_update_by_id(int id, struct utime *time);
#endif
@@ -0,0 +1,45 @@
#ifndef UI_WATCH_H
#define UI_WATCH_H
#include "ui/control.h"
#include "ui/ui_core.h"
#define WATCH_CHILD_NUM (CTRL_WATCH_CHILD_END - CTRL_WATCH_CHILD_BEGIN)
struct watch_pic_info {
struct ui_ctrl_info_head head;
u16 cent_x;
u16 cent_y;
struct ui_image_list *img;
};
struct watch_css_info {
int left: 16;
int top: 16;
};
struct ui_watch {
struct element elm;
struct element child_elm[WATCH_CHILD_NUM];
struct watch_css_info child_css[WATCH_CHILD_NUM];
u8 hour;
u8 min;
u8 sec;
u8 updata;
u8 ctrl_num;
void *timer;
const struct layout_info *info;
const struct watch_pic_info *pic_info[WATCH_CHILD_NUM];
const struct element_event_handler *handler;
};
void ui_watch_enable();
int ui_watch_set_time_by_id(int id, int hour, int min, int sec);
#endif
@@ -0,0 +1,48 @@
#ifndef UI_WINDOW_H
#define UI_WINDOW_H
#include "ui/layer.h"
#include "ui/ui_core.h"
#include "ui/control.h"
#include "list.h"
struct window {
struct element elm; //must be first
u8 busy;
u8 hide;
u8 ctrl_num;
struct list_head entry;
struct layer *layer;
const struct window_info *info;
const struct element_event_handler *handler;
void *private_data;
};
extern const struct window_info *window_table;
#define REGISTER_WINDOW_EVENT_HANDLER(id) \
REGISTER_UI_EVENT_HANDLER(id)
int window_show(int);
int window_hide(int id);
int window_toggle(int id);
int window_ontouch(struct element_touch_event *e);
int window_onkey(struct element_key_event *e);
#endif
@@ -0,0 +1,434 @@
/* Copyright(C)
* not free
* All right reserved
*
* @file dbi.h
* @brief DBI模块驱动API头文件。DBI模块为专门用于推屏的独立硬件模块,与硬件SPI无关。其配置仅在屏幕驱动的结构体中,推屏时钟的频率为内部通过推屏帧率计算而得,但时钟是由PLL进行分频而来,因此实际时钟频率仅会在分频组合允许的前提下尽可能接近所需的目标频率(实际测量的推屏时钟与计算并非绝对一致)。
* @author zhuhaifang@zh-jieli.com
* @version V201
* @date 2023-01-10
*/
#ifndef __DBI_H__
#define __DBI_H__
#include "generic/typedef.h"
//#include "os/os_api.h"
#include "gpio.h"
//#include "dbi_sfr.h"
enum OUTPUT_FORMAT {
/* 0 */OUTPUT_FORMAT_RGB888,
/* 1 */OUTPUT_FORMAT_RGB565,
};
/* ------------------------------------------------------------------------------------*/
/**
* @brief DBI模块私有变量。注意:该变量内部使用,外部禁止操作,否则会导致不可预测的问题。
*/
/* ------------------------------------------------------------------------------------*/
extern struct dbi_variable dbi_var;
/* ------------------------------------------------------------------------------------*/
/**
* @brief 模块驱动接口组,DBI模块下管理了SPI, MCU, RGB三组驱动接口,具体驱动接口在这里
* 注册给DBI模块管理使用。注意:该变量内部使用,外部无需修改,否则会导致不可预测的问题。
*/
/* ------------------------------------------------------------------------------------*/
struct dbi_driver {
void (*init)(struct dbi_variable *priv);
void (*write)(u32, u8 *, u8);
void (*read)(u32, u8 *, u8);
void (*set_draw_area)(int, int, int, int);
void (*clear)(u32, int, int, int, int);
void (*draw)(u8 *, int, int, int, int);
void (*draw_continue)(u8 *, int, int, int, int);
};
//[DBI接口IO定义]
#define DBI_CSX_VSYNC IO_PORTA_07
#define DBI_DCX_HSYNC IO_PORTA_13
#define DBI_SCL_WRX IO_PORTA_12
#define DBI_D0 IO_PORTA_08
#define DBI_D1 IO_PORTA_09
#define DBI_D2 IO_PORTA_10
#define DBI_D3 IO_PORTA_11
#define DBI_D4 IO_PORTC_00
#define DBI_D5 IO_PORTC_01
#define DBI_D6 IO_PORTC_02
#define DBI_D7 IO_PORTC_03
#define DBI_RDX_DEN IO_PORTC_10
// <<<[lcd接口配置]>>>
#define SPI_MODE (0<<4)
#define DSPI_MODE (1<<4)
#define QSPI_MODE (2<<4)
// SPI线数标志(clk + dat)
#define SPI_WIRE3 0
#define SPI_WIRE4 1
// QSPI的子模式标志(除SUBMODE0为1 dat线之外,其余模式都为4 dat线)
#define QSPI_SUBMODE0 0//0x02
#define QSPI_SUBMODE1 1//0x32
#define QSPI_SUBMODE2 2//0x12
#define QSPI_ST77903 3//0xde
#define QSPI_FT2388 4//0x32 1ch cmd + 4ch data
// LCD时序标志(根据LCD数据手册配置,常用时序均已组合到LCD_DRIVE_CONFIG宏,在LCD驱动文件配置)
#define PIXEL_1P1T (0<<5)
#define PIXEL_1P2T (1<<5)
#define PIXEL_1P3T (2<<5)
#define PIXEL_2P3T (3<<5)
#define PIXEL_1T2B 1
#define PIXEL_1T6B 5
#define PIXEL_1T8B 7
#define PIXEL_1T9B 8
#define PIXEL_1T12B 11
#define PIXEL_1T16B 15
#define PIXEL_1T18B 17
#define PIXEL_1T24B 23
#define FORMAT_RGB565 1//0//1P2T
#define FORMAT_RGB666 2//1//1P3T
#define FORMAT_RGB888 0//2//1P3T
#define SPI_MODE_UNIDIR 0//半双工,d0分时发送接收
#define SPI_MODE_BIDIR 1//全双工,d0发送、d1接收
enum {
CMD_MODE,
};
enum {
CMD_8BIT,
CMD_16BIT,
CMD_24BIT,
};
/*
** dbi私有全局变量定义
*/
struct dbi_variable {
volatile u8 dbi_busy; // dbi忙碌标志
u8 clock_init: 1; // dbi时钟初始化标志
u8 clock_div_sel: 7; // dbi时钟
u8 sfr_save; // 寄存器保存标志
u8 row_align; // 行对齐
u8 column_align;// 列对齐
int (*te_stat)(); // TE 信号检测,返回值为TE脚电平,使用内部等待TE信号时,这个函数须注册
void (*te_wait)(); // TE 信号等待,如果使用外部TE等待函数,注册这个回调,则等TE时会调用这
struct dbi_param *param;
void (*dbi_callback)(int err);//dbi回调
u8 cmd_mode;
volatile s8 draw_sem;
u8 *frameBuffer;
u32 frameBufferSize;
int xstart;
int xend;
int ystart;
int yend;
};
/* ------------------------------------------------------------------------------------*/
/**
* @brief 屏幕驱动接口类型定义,根据屏幕的接口类型在屏驱内配置使用
*/
/* ------------------------------------------------------------------------------------*/
typedef enum lcd_type_cfg {
LCD_TYPE_SPI, // SPI屏
LCD_TYPE_SPI_RAMLESS, // SPI RAMLESS屏
LCD_TYPE_MCU, // MCU屏
LCD_TYPE_RGB, // RGB屏
LCD_TYPE_MAX,
} LCD_TYPE;
struct dbi_param {
// 显示区域相关(用于配置推屏区域,可不推全屏)
int scr_x;
int scr_y;
int scr_w;
int scr_h;
// lcd配置
int lcd_width;
int lcd_height;
LCD_TYPE lcd_type; // LCD接口类型:SPI, SPI Ramless, MCU, RGB
// 显存配置
int buffer_num;
int buffer_size;
int buffer_total_size;
u8 *buffer;
// dbi模块的输入,与imb模块一起用时,也是imb模块的输出
int in_width;
int in_height;
int in_format;
int in_stride;
// debug模式(推新屏时,可使能debug模式,先推纯色测试)
int debug_mode_en;
int debug_mode_color;
// 帧率配置(用于计算DBI模块时钟频率,但实际推屏帧率仅会接近配置,并非100%一致)
int fps;
float actual_fps;//当前时钟计算出来的实际fps
// 以下为三种屏驱动相关配置,out_format为屏幕的像素格式类型
struct spi_param {
int spi_mode;
int pixel_type;
int out_format;
int spi_dat_mode;
int dc_pin_select; //若选择SPI_4WIRE_RGB888_1T8B/SPI_4WIRE_RGB888_1T24B/SPI_4WIRE_RGB666_1T18B/SPI_4WIRE_RGB565_1T8B/SPI_4WIRE_RGB565_1T16B时序,
//dc_pin_select = 1, dc信号从PA13输出
//dc_pin_select = 0, dc信号从PA9输出
struct qspi_cmd {
u8 write_cmd;
u8 read_cmd;
u8 submode0_cmd;//0x2c/0x3c/数据单线, default value 0x02
u8 submode1_cmd;//0x2c/0x3c单线,数据四线,default value 0x32
u8 submode2_cmd;//0x2c/0x3c/数据四线, default value 0x12
} qspi_cmd;
struct ramless {
u32 frame_sync_cmd;//ramless cmd
u32 porch_sync_cmd;//ramless cmd
u32 line_sync_cmd;//ramless cmd
u16 hbp;//hori back porch
u16 hfp;//hori front porch
u16 vbp;//vert back porch
u16 vfp;//vert front porch
} ramless;
u8 caset_cmd;//Column Address Set, default value 0x2a
u8 paset_cmd;//Page Address Set, default value 0x2b
u8 ramwr_cmd;//Memory Write Start, default value 0x2c
u8 ramwrc_cmd;//Memory Write Continue, default valus 0x3c
} spi;
struct pap_param {
int out_format;
} pap;
struct rgb_param {
int use_spi;
int out_format;
int continue_frames;
int hpw_prd;
int hbw_prd;
int hfw_prd;
int hact_prd;
int vpw_prd;
int vbw_prd;
int vfw_prd;
int vact_prd;
} rgb;
};
/* ------------------------------------------------------------------------------------*/
/**
* @brief lcd_init DBI模块初始化(注意:需要操作DBI或从DBI获取信息时,必须先初始化)
*
* @param param DBI配置句柄
*
* @return 0
*/
/* ------------------------------------------------------------------------------------*/
int lcd_init(struct dbi_param *param);
/* ------------------------------------------------------------------------------------*/
/**
* @brief lcd_write_cmd DBI模块向LCD指定地址写数据
*
* @param cmd 待操作的LCD命令地址
* @param buf 数据缓存buf(如果不需要写数据,可传入NULL)
* @param len 数据缓存长度(如果不写数据,需将len配置为0)
*/
/* ------------------------------------------------------------------------------------*/
void lcd_write_cmd(u32 cmd, u8 *buf, u8 len);
/* ------------------------------------------------------------------------------------*/
/**
* @brief lcd_read_cmd DBI模块从LCD指定地址读数据
*
* @param cmd 待操作的LCD命令地址
* @param buf 数据缓存buf(输出)
* @param len 读取的数据长度(需与buf匹配,不可超过buf大小)
*/
/* ------------------------------------------------------------------------------------*/
void lcd_read_cmd(u32 cmd, u8 *buf, u8 len);
/* ------------------------------------------------------------------------------------*/
/**
* @brief lcd_set_draw_area 设置LCD显示区域(2A, 2B命令)
*
* @param xstart X起始像素坐标
* @param xend X结束像素坐标
* @param ystart Y起始像素坐标
* @param yend Y结束像素坐标
*/
/* ------------------------------------------------------------------------------------*/
void lcd_set_draw_area(int xstart, int xend, int ystart, int yend);
/* ------------------------------------------------------------------------------------*/
/**
* @brief lcd_draw DBI硬件写显示数据到LCD, 非阻塞接口,与lcd_set_draw_area配合使用
*
* @param buf 待写出数据
* @param xstart X起始像素坐标
* @param xend X结束像素坐标
* @param ystart Y起始像素坐标
* @param yend Y结束像素坐标
*/
/* ------------------------------------------------------------------------------------*/
void lcd_draw(u8 *buf, int xstart, int xend, int ystart, int yend);
/* ------------------------------------------------------------------------------------*/
/**
* @brief lcd_draw_continue DBI硬件以续传方式写显示数据到LCD, 非阻塞接口,与lcd_set_draw_area、lcd_draw配合使用
*
* @param buf 待写出数据
* @param xstart X起始像素坐标
* @param xend X结束像素坐标
* @param ystart Y起始像素坐标
* @param yend Y结束像素坐标
*/
/* ------------------------------------------------------------------------------------*/
void lcd_draw_continue(u8 *buf, int xstart, int xend, int ystart, int yend);
/* ------------------------------------------------------------------------------------*/
/**
* @brief lcd_clear 纯色填充LCD指定区域
*
* @param color 待填充的RGB888颜色值
* @param xstart 待填充的X起始像素坐标
* @param xend 待填充的X结束像素坐标
* @param ystart 待填充的Y起始像素坐标
* @param yend 待填充的Y结束像素坐标
*/
/* ------------------------------------------------------------------------------------*/
void lcd_clear(u32 color, int xstart, int xend, int ystart, int yend);
/* ------------------------------------------------------------------------------------*/
/**
* @brief lcd_set_ctrl_pin_func 配置LCD控制脚操作函数
*
* @param te_stat TE脚控制函数
*/
/* ------------------------------------------------------------------------------------*/
void lcd_set_ctrl_pin_func(int (*te_stat)());
/* ------------------------------------------------------------------------------------*/
/**
* @brief lcd_set_te_wait_cb 配置TE信号等待回调函数,如果注册,等待TE时将调用回调进行等待
*
* @Params te_wait 应用层实现的TE等待函数
*/
/* ------------------------------------------------------------------------------------*/
void lcd_set_te_wait_cb(void (*te_wait)());
/* ------------------------------------------------------------------------------------*/
/**
* @brief lcd_set_align 设置LCD对齐参数
*
* @param row_align 设置行对齐参数
* @param column_align 设置列对齐参数
*/
/* ------------------------------------------------------------------------------------*/
void lcd_set_align(u8 row_align, u8 column_align);
/* ------------------------------------------------------------------------------------*/
/**
* @brief lcd_get_align 设置LCD对齐参数
*
* @param row_align 获取行对齐参数
* @param column_align 获取列对齐参数
*/
/* ------------------------------------------------------------------------------------*/
void lcd_get_align(u8 *row_align, u8 *column_align);
/* ------------------------------------------------------------------------------------*/
/**
* @brief lcd_check_align 检查LCD刷屏区域参数是否对齐
*
* @param xstart X起始像素坐标
* @param xend X结束像素坐标
* @param ystart Y起始像素坐标
* @param yend Y结束像素坐标
*/
/* ------------------------------------------------------------------------------------*/
int lcd_check_align(int xstart, int xend, int ystart, int yend);
/* ------------------------------------------------------------------------------------*/
/**
* @brief lcd_wait_busy 等待lcd空闲
* 注意:本函数一般在推屏buffer释放前调用,等待推屏结束
*/
/* ------------------------------------------------------------------------------------*/
void lcd_wait_busy();
/* ------------------------------------------------------------------------------------*/
/* ------------------------------------------------------------------------------------*/
/**
* @brief lcd_draw_kistart 无等待推屏接口
*/
/* ------------------------------------------------------------------------------------*/
void lcd_draw_kistart(uint8_t *buf, int xstart, int xend, int ystart, int yend);
/* ------------------------------------------------------------------------------------*/
/**
* @brief lcd_draw_set_callback 设置推屏结束回调, lcd_draw、lcd_draw_continue推屏结束时调用该回调
*/
/* ------------------------------------------------------------------------------------*/
int lcd_draw_set_callback(void (*callback)(int err));
/* ------------------------------------------------------------------------------------*/
/**
* @brief lcd_te_trig_kistart_set_busy 设置LCD繁忙状态,需TE中断调用lcd_draw_kistart接口推屏,推屏结束后会自动消除繁忙状态,
* 另外附加作用是打印调试接口,如果是kistart是由TE来引导的,那么wait lcd busy就是正常的, 不用打印出来
*/
/* ------------------------------------------------------------------------------------*/
void lcd_te_trig_kistart_set_busy(void);
/* ------------------------------------------------------------------------------------*/
/**
* @brief lcd_set_param 设置LCD模式
*/
/* ------------------------------------------------------------------------------------*/
void lcd_set_param(u8 mode, int priv);
/* ------------------------------------------------------------------------------------*/
/**
* @brief lcd_get_param 获取LCD模式
*/
/* ------------------------------------------------------------------------------------*/
int lcd_get_param(u8 mode);
#endif
@@ -0,0 +1,36 @@
#ifndef __LCD_BUFFER_MANAGER_H__
#define __LCD_BUFFER_MANAGER_H__
#include "generic/list.h"
struct lcd_buffer_head {
struct list_head head;
u8 *pre_buf;
};
// 缓存buf的状态
typedef enum lcd_buf_status {
LCD_BUFFER_INIT, // 初始状态,防止还没写数据就推屏
LCD_BUFFER_IDLE, // 空闲
LCD_BUFFER_LOCK, // 锁定
LCD_BUFFER_PENDING, // 等待
LCD_BUFFER_INUSED, // 使用
} BUF_STATUS;
// lcd buffer
struct lcd_buffer {
struct list_head entry;
BUF_STATUS status;
u8 *baddr;
};
u8 *lcd_buffer_init(u8 index, u8 *baddr, u32 size);
void lcd_buffer_release(u8 index);
u8 *lcd_buffer_get(u8 index, u8 *pre_baddr);
u8 lcd_buffer_pending(u8 index, u8 *buffer);
void lcd_buffer_idle(u8 index);
u8 *lcd_buffer_next(u8 index);
u8 *lcd_buffer_check(u8 index, u8 *lcd_buf);
#endif