pure sdk for main

This commit is contained in:
divadiow
2025-08-27 09:51:58 +01:00
parent f0d033f1c9
commit 0571416e7c
3283 changed files with 1577720 additions and 1 deletions
+61
View File
@@ -0,0 +1,61 @@
#ifndef _HGADC_V0_H
#define _HGADC_V0_H
#include "hal/adc.h"
#ifdef __cplusplus
extern "C" {
#endif
struct hgadc_v0;
typedef struct _adc_channel_data {
/* pointer of config function */
int32 (*func)(struct hgadc_v0 *dev, uint32 channel, uint32 enable);
/* channel */
uint16 channel;
}adc_channel_data;
typedef struct _adc_channel_node {
/* data type */
adc_channel_data data;
/* for list opreation */
struct _adc_channel_node *next;
/* channel amount */
uint8 channel_amount;
}adc_channel_node;
struct hgadc_v0 {
struct adc_device dev;
uint32 hw;
adc_irq_hdl irq_hdl;
uint32 irq_data;
uint32 irq_num;
struct os_mutex adc_lock;
struct os_semaphore adc_done;
adc_channel_node head_node;
uint32 refer_vddi;
uint32 refer_vddi_adc_data;
uint32 refer_tsensor;
uint32 refer_adda_vref;
uint32 rf_vddi_en:1,
opened :1,
irq_en :1;
};
int32 hgadc_v0_attach(uint32 dev_id, struct hgadc_v0 *adc);
#ifdef __cplusplus
}
#endif
#endif
@@ -0,0 +1,181 @@
#ifndef _AUALAW_H
#define _AUALAW_H
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief AUALAW irq_flag type
*/
enum aualaw_irq_flag {
/*!
* @brief:
*
*/
AUALAW_IRQ_FLAG_HALF = BIT(0),
/*!
* @brief:
*
*/
AUALAW_IRQ_FLAG_FULL = BIT(1),
};
/**
* @brief AUALAW ioctl_cmd type
*/
enum aualaw_ioctl_cmd {
/*!
* @brief:
*
*/
AUALAW_IOCTL_CMD_NONE,
};
/* User interrupt handle */
typedef void (*aualaw_irq_hdl)(uint32 irq, uint32 irq_data);
/* AUALAW api for user */
struct aualaw_device {
struct dev_obj dev;
};
struct aualaw_hal_ops {
struct devobj_ops ops;
int32(*open)(struct aualaw_device *aualaw);
int32(*close)(struct aualaw_device *aualaw);
int32(*encode)(struct aualaw_device *aualaw, void* dat_buf, uint32 bytes, void* result_buf);
int32(*decode)(struct aualaw_device *aualaw, void* dat_buf, uint32 bytes, void* result_buf);
int32(*ioctl)(struct aualaw_device *aualaw, enum aualaw_ioctl_cmd ioctl_cmd, uint32 param1, uint32 param2);
int32(*request_irq)(struct aualaw_device *aualaw, enum aualaw_irq_flag irq_flag, aualaw_irq_hdl irq_hdl, uint32 irq_data);
int32(*release_irq)(struct aualaw_device *aualaw, enum aualaw_irq_flag irq_flag);
};
/* AUALAW API functions */
/**
* @brief aualaw_open
*
*
* @note .
*
* @param aualaw The address of aualaw device in the RTOS.
* @param .
* @param .
*
* @return
* - RET_OK Success
* - RET_ERR Fail
*/
int32 aualaw_open(struct aualaw_device *aualaw);
/**
* @brief aualaw_close
*
*
* @note .
*
* @param aualaw The address of aualaw device in the RTOS.
* @param .
* @param .
*
* @return
* - RET_OK Success
* - RET_ERR Fail
*/
int32 aualaw_close(struct aualaw_device *aualaw);
/**
* @brief aualaw_encode
*
*
* @note .
*
* @param aualaw The address of aualaw device in the RTOS.
* @param .
* @param .
*
* @return
* - RET_OK Success
* - RET_ERR Fail
*/
int32 aualaw_encode(struct aualaw_device *aualaw, void* dat_buf, uint32 bytes, void* result_buf);
/**
* @brief aualaw_decode
*
*
* @note .
*
* @param aualaw The address of aualaw device in the RTOS.
* @param .
* @param .
*
* @return
* - RET_OK Success
* - RET_ERR Fail
*/
int32 aualaw_decode(struct aualaw_device *aualaw, void* dat_buf, uint32 bytes, void* result_buf);
/**
* @brief aualaw_ioctl
*
*
* @note .
*
* @param aualaw The address of aualaw device in the RTOS.
* @param .
* @param .
*
* @return
* - RET_OK Success
* - RET_ERR Fail
*/
int32 aualaw_ioctl(struct aualaw_device *aualaw, enum aualaw_ioctl_cmd ioctl_cmd, uint32 param1, uint32 param2);
/**
* @brief aualaw_request_irq
*
*
* @note .
*
* @param aualaw The address of aualaw device in the RTOS.
* @param .
* @param .
*
* @return
* - RET_OK Success
* - RET_ERR Fail
*/
int32 aualaw_request_irq(struct aualaw_device *aualaw, enum aualaw_irq_flag irq_flag, aualaw_irq_hdl irq_hdl, uint32 irq_data);
/**
* @brief aualaw_release_irq
*
*
* @note .
*
* @param aualaw The address of aualaw device in the RTOS.
* @param .
* @param .
*
* @return
* - RET_OK Success
* - RET_ERR Fail
*/
int32 aualaw_release_irq(struct aualaw_device *aualaw, enum aualaw_irq_flag irq_flag);
#ifdef __cplusplus
}
#endif
#endif
@@ -0,0 +1,22 @@
#ifndef _HG_AUALAW_V0_H_
#define _HG_AUALAW_V0_H_
#ifdef __cplusplus
extern "C" {
#endif
int32 hg_aualaw_v0_init(void);
int32 hg_aualaw_v0_open(struct aualaw_device *aualaw);
int32 hg_aualaw_v0_close(struct aualaw_device *aualaw);
int32 hg_aualaw_v0_encode(struct aualaw_device *aualaw, void* dat_buf, uint32 bytes, void* result_buf);
int32 hg_aualaw_v0_decode(struct aualaw_device *aualaw, void* dat_buf, uint32 bytes, void* result_buf);
int32 hg_aualaw_v0_ioctl(struct aualaw_device *aualaw, enum aualaw_ioctl_cmd ioctl_cmd, uint32 param1, uint32 param2);
int32 hg_aualaw_v0_request_irq(struct aualaw_device *aualaw, enum aualaw_irq_flag irq_flag, aualaw_irq_hdl irq_hdl, uint32 irq_data);
int32 hg_aualaw_v0_release_irq(struct aualaw_device *aualaw, enum aualaw_irq_flag irq_flag);
#ifdef __cplusplus
}
#endif
#endif /* _HGI2S_V0_H_ */
+126
View File
@@ -0,0 +1,126 @@
#ifndef _AUEQ_H
#define _AUEQ_H
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief AUEQ ioctl_cmd type
*/
enum aueq_ioctl_cmd {
/*!
* @brief:
*
*/
AUEQ_IOCTL_CMD_NONE,
};
/*!
* @brief coefficient configuration
* @note
* a example of coefficient for 5 band:
* struct aueq_cfg cfg[5];
* cfg[0].b[0] = 0.1;
* cfg[0].b[1] = 0.3;
* ...
* cfg[1].b[1] = 0.6;
*/
struct aueq_cfg{
double b[3];
double a[2];
};
/* AUEQ api for user */
struct aueq_device {
struct dev_obj dev;
};
struct aueq_hal_ops {
struct devobj_ops ops;
int32(*open)(struct aueq_device *aueq, struct aueq_cfg *p_cfg);
int32(*close)(struct aueq_device *aueq);
int32(*run)(struct aueq_device *aueq, void* dat_buf, uint32 bytes);
int32(*ioctl)(struct aueq_device *aueq, enum aueq_ioctl_cmd ioctl_cmd, uint32 param1, uint32 param2);
};
/* AUEQ API functions */
/**
* @brief aueq_open
*
*
* @note .
*
* @param aueq The address of aueq device in the RTOS.
* @param .
* @param .
*
* @return
* - RET_OK Success
* - RET_ERR Fail
*/
int32 aueq_open(struct aueq_device *aueq, struct aueq_cfg *p_cfg);
/**
* @brief aueq_close
*
*
* @note .
*
* @param aueq The address of aueq device in the RTOS.
* @param .
* @param .
*
* @return
* - RET_OK Success
* - RET_ERR Fail
*/
int32 aueq_close(struct aueq_device *aueq);
/**
* @brief aueq_encode
*
*
* @note .
*
* @param aueq The address of aueq device in the RTOS.
* @param .
* @param .
*
* @return
* - RET_OK Success
* - RET_ERR Fail
*/
int32 aueq_run(struct aueq_device *aueq, void* dat_buf, uint32 bytes);
/**
* @brief aueq_ioctl
*
*
* @note .
*
* @param aueq The address of aueq device in the RTOS.
* @param .
* @param .
*
* @return
* - RET_OK Success
* - RET_ERR Fail
*/
int32 aueq_ioctl(struct aueq_device *aueq, enum aueq_ioctl_cmd ioctl_cmd, uint32 param1, uint32 param2);
#ifdef __cplusplus
}
#endif
#endif
@@ -0,0 +1,59 @@
#ifndef BIQUAD_FILTER_H
#define BIQUAD_FILTER_H
typedef int s32, S32;
typedef unsigned int u32, U32, uint;
typedef long long int s64, S64;
typedef unsigned long long u64, U64;
typedef short int s16, S16;
typedef unsigned short int u16, U16;
typedef signed char s8, S8;
typedef unsigned char u8, U8;
//模拟64bit芯片运算
int CLIP_INT24(int in);
int CLIP_INT16(int in);
void ML0(s32 x, s32 y);
void MLA(s32 x, s32 y);
void MSB(s32 x, s32 y);
s32 MLZ(s32 n);
s32 MLZ_QUICK(s32 n);
s32 MLZ_FIX(s32 n);
u32 get_acc_64_high_32(void);
u32 get_acc_64_low_32(void);
typedef struct {
int b[3];
int a[2];
int x[2];
int y[2];
int fixed_point_num;
} TYPE_BIQUAD_FILTER;
int biquad_filter_calc(TYPE_BIQUAD_FILTER *filter_ctl, int x);
//void biquad_filter_ctl_init(TYPE_BIQUAD_FILTER *filter_ctl, int fixed_point_num);
#if 0
void eq_lpf_coeff_calc(TYPE_BIQUAD_FILTER *filter_ctl,
double fs, double f0, double q);
void eq_hpf_coeff_calc(TYPE_BIQUAD_FILTER *filter_ctl,
double fs, double f0, double q);
void eq_bpf_coeff_calc(TYPE_BIQUAD_FILTER *filter_ctl,
double fs, double f0, double q);
void eq_notch_coeff_calc(TYPE_BIQUAD_FILTER *filter_ctl,
double fs, double f0, double q);
void eq_apf_coeff_calc(TYPE_BIQUAD_FILTER *filter_ctl,
double fs, double f0, double q);
void eq_peaking_coeff_calc(TYPE_BIQUAD_FILTER *filter_ctl,
double fs, double f0, double gain, double q);
void eq_low_shelf_coeff_calc(TYPE_BIQUAD_FILTER *filter_ctl,
double fs, double f0, double gain, double q);
void eq_high_shelf_coeff_calc(TYPE_BIQUAD_FILTER *filter_ctl,
double fs, double f0, double gain, double q);
#endif
#endif /* BIQUAD_FILTER_H */
@@ -0,0 +1,19 @@
#ifndef _HG_AUEQ_V0_H_
#define _HG_AUEQ_V0_H_
#ifdef __cplusplus
extern "C" {
#endif
int32 hg_aueq_v0_init(void);
int32 hg_aueq_v0_open(struct aueq_device *aueq, struct aueq_cfg *p_cfg);
int32 hg_aueq_v0_close(struct aueq_device *aueq);
int32 hg_aueq_v0_run(struct aueq_device *aueq, void* dat_buf, uint32 bytes);
int32 hg_aueq_v0_ioctl(struct aueq_device *aueq, enum aueq_ioctl_cmd ioctl_cmd, uint32 param1, uint32 param2);
#ifdef __cplusplus
}
#endif
#endif /* _HG_AUEQ_V0_H_ */
@@ -0,0 +1,192 @@
#ifndef _AUFADE_H
#define _AUFADE_H
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief AUFADE calculate mode types
*/
enum aufade_mode {
AUFADE_IN = BIT(0),
AUFADE_OUT = BIT(1),
};
/**
* @brief AUFADE step types
*/
enum aufade_step {
AUFADE_STEP_1,
AUFADE_STEP_2,
AUFADE_STEP_4,
AUFADE_STEP_8,
};
/**
* @brief AUFADE sample types
*/
enum aufade_sample {
AUFADE_SAMPLE_1,
AUFADE_SAMPLE_2,
AUFADE_SAMPLE_3,
AUFADE_SAMPLE_4,
};
/**
* @brief AUFADE irq_flag type
*/
enum aufade_irq_flag {
/*!
* @brief:
*
*/
AUFADE_IRQ_FLAG_NONE = BIT(0),
};
/**
* @brief AUFADE ioctl_cmd type
*/
enum aufade_ioctl_cmd {
AUFADE_IOCTL_CMD_SET_STEP = BIT(0),
AUFADE_IOCTL_CMD_SET_SAMPLE = BIT(1),
};
/* User interrupt handle */
typedef void (*aufade_irq_hdl)(uint32 irq, uint32 irq_data);
/* AUFADE api for user */
struct aufade_device {
struct dev_obj dev;
};
struct aufade_hal_ops {
struct devobj_ops ops;
int32(*open)(struct aufade_device *aufade);
int32(*close)(struct aufade_device *aufade);
int32(*start)(struct aufade_device *aufade, enum aufade_mode mode);
int32(*ioctl)(struct aufade_device *aufade, enum aufade_ioctl_cmd ioctl_cmd, uint32 param1, uint32 param2);
int32(*request_irq)(struct aufade_device *aufade, enum aufade_irq_flag irq_flag, aufade_irq_hdl irq_hdl, uint32 irq_data);
int32(*release_irq)(struct aufade_device *aufade, enum aufade_irq_flag irq_flag);
};
/* AUFADE API functions */
/**
* @brief aufade_open
*
*
* @note .
*
* @param aufade The address of aufade device in the RTOS.
* @param .
* @param .
*
* @return
* - RET_OK Success
* - RET_ERR Fail
*/
int32 aufade_open(struct aufade_device *aufade);
/**
* @brief aufade_close
*
*
* @note .
*
* @param aufade The address of aufade device in the RTOS.
* @param .
* @param .
*
* @return
* - RET_OK Success
* - RET_ERR Fail
*/
int32 aufade_close(struct aufade_device *aufade);
/**
* @brief aufade_start
*
*
* @note .
*
* @param aufade The address of aufade device in the RTOS.
* @param .
* @param .
*
* @return
* - RET_OK Success
* - RET_ERR Fail
*/
int32 aufade_start(struct aufade_device *aufade, enum aufade_mode mode);
/**
* @brief aufade_ioctl
*
*
* @note .
*
* @param aufade The address of aufade device in the RTOS.
* @param .
* @param .
*
* @return
* - RET_OK Success
* - RET_ERR Fail
*/
int32 aufade_ioctl(struct aufade_device *aufade, enum aufade_ioctl_cmd ioctl_cmd, uint32 param1, uint32 param2);
/**
* @brief aufade_request_irq
*
*
* @note .
*
* @param aufade The address of aufade device in the RTOS.
* @param .
* @param .
*
* @return
* - RET_OK Success
* - RET_ERR Fail
*/
int32 aufade_request_irq(struct aufade_device *aufade, enum aufade_irq_flag irq_flag, aufade_irq_hdl irq_hdl, uint32 irq_data);
/**
* @brief aufade_release_irq
*
*
* @note .
*
* @param aufade The address of aufade device in the RTOS.
* @param .
* @param .
*
* @return
* - RET_OK Success
* - RET_ERR Fail
*/
int32 aufade_release_irq(struct aufade_device *aufade, enum aufade_irq_flag irq_flag);
#ifdef __cplusplus
}
#endif
#endif
@@ -0,0 +1,23 @@
#ifndef _HG_AUFADE_V0_H_
#define _HG_AUFADE_V0_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "dev/audio/components/fade/aufade.h"
#include "hg_audio_v0_hw.h"
int32 hg_aufade_v0_init(void);
int32 hg_aufade_v0_open(struct aufade_device *aufade);
int32 hg_aufade_v0_close(struct aufade_device *aufade);
int32 hg_aufade_v0_start(struct aufade_device *aufade, enum aufade_mode mode);
int32 hg_aufade_v0_ioctl(struct aufade_device *aufade, enum aufade_ioctl_cmd ioctl_cmd, uint32 param1, uint32 param2);
int32 hg_aufade_v0_request_irq(struct aufade_device *aufade, enum aufade_irq_flag irq_flag, aufade_irq_hdl irq_hdl, uint32 irq_data);
int32 hg_aufade_v0_release_irq(struct aufade_device *aufade, enum aufade_irq_flag irq_flag);
int32 hg_aufade_v0_set_gain(struct hg_audio_hw_v0 *audio_hw, uint32 gain);
#ifdef __cplusplus
}
#endif
#endif /* _HG_AUFADE_V0_H_ */
@@ -0,0 +1,203 @@
#ifndef _AUVAD_H
#define _AUVAD_H
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief AUVAD calculate mode types
*/
enum auvad_calc_mode {
AUVAD_CALC_MODE_ENERGY = BIT(0),
AUVAD_CALC_MODE_ZCR = BIT(1),
};
/**
* @brief AUVAD irq_flag type
*/
enum auvad_irq_flag {
/*!
* @brief:
*
*/
NONE = BIT(0),
};
/**
* @brief AUVAD ioctl_cmd type
*/
enum auvad_ioctl_cmd {
/*!
* @brief:
*
*/
AUVAD_IOCTL_CMD_SET_CALC_MODE,
/*!
* @brief:
*
*/
AUVAD_IOCTL_CMD_SET_THRESHOLD_TH0,
/*!
* @brief:
*
*/
AUVAD_IOCTL_CMD_SET_THRESHOLD_TH1,
/*!
* @brief:
*
*/
AUVAD_IOCTL_CMD_SET_THRESHOLD_ZCR,
};
/* User interrupt handle */
typedef void (*auvad_irq_hdl)(uint32 irq, uint32 irq_data);
/* AUVAD api for user */
struct auvad_device {
struct dev_obj dev;
};
struct auvad_hal_ops {
struct devobj_ops ops;
int32(*open)(struct auvad_device *auvad, enum auvad_calc_mode mode);
int32(*close)(struct auvad_device *auvad);
int32(*calc)(struct auvad_device *auvad, void* dat_buf, uint32 bytes, uint32 calc_type, void* result_buf);
int32(*ioctl)(struct auvad_device *auvad, enum auvad_ioctl_cmd ioctl_cmd, uint32 param1, uint32 param2);
int32(*request_irq)(struct auvad_device *auvad, enum auvad_irq_flag irq_flag, auvad_irq_hdl irq_hdl, uint32 irq_data);
int32(*release_irq)(struct auvad_device *auvad, enum auvad_irq_flag irq_flag);
};
/* AUVAD API functions */
/**
* @brief auvad_open
*
*
* @note .
*
* @param auvad The address of auvad device in the RTOS.
* @param .
* @param .
*
* @return
* - RET_OK Success
* - RET_ERR Fail
*/
int32 auvad_open(struct auvad_device *auvad, enum auvad_calc_mode mode);
/**
* @brief auvad_close
*
*
* @note .
*
* @param auvad The address of auvad device in the RTOS.
* @param .
* @param .
*
* @return
* - RET_OK Success
* - RET_ERR Fail
*/
int32 auvad_close(struct auvad_device *auvad);
/**
* @brief auvad_encode
*
*
* @note .
*
* @param auvad The address of auvad device in the RTOS.
* @param .
* @param .
*
* @return
* - RET_OK Success
* - RET_ERR Fail
*/
int32 auvad_encode(struct auvad_device *auvad, void* dat_buf, uint32 bytes, void* result_buf);
/**
* @brief auvad_decode
*
*
* @note .
*
* @param auvad The address of auvad device in the RTOS.
* @param .
* @param .
*
* @return
* - RET_OK Success
* - RET_ERR Fail
*/
int32 auvad_calc(struct auvad_device *auvad, void* dat_buf, uint32 bytes, uint32 calc_type, void* result_buf);
/**
* @brief auvad_ioctl
*
*
* @note .
*
* @param auvad The address of auvad device in the RTOS.
* @param .
* @param .
*
* @return
* - RET_OK Success
* - RET_ERR Fail
*/
int32 auvad_ioctl(struct auvad_device *auvad, enum auvad_ioctl_cmd ioctl_cmd, uint32 param1, uint32 param2);
/**
* @brief auvad_request_irq
*
*
* @note .
*
* @param auvad The address of auvad device in the RTOS.
* @param .
* @param .
*
* @return
* - RET_OK Success
* - RET_ERR Fail
*/
int32 auvad_request_irq(struct auvad_device *auvad, enum auvad_irq_flag irq_flag, auvad_irq_hdl irq_hdl, uint32 irq_data);
/**
* @brief auvad_release_irq
*
*
* @note .
*
* @param auvad The address of auvad device in the RTOS.
* @param .
* @param .
*
* @return
* - RET_OK Success
* - RET_ERR Fail
*/
int32 auvad_release_irq(struct auvad_device *auvad, enum auvad_irq_flag irq_flag);
#ifdef __cplusplus
}
#endif
#endif
@@ -0,0 +1,21 @@
#ifndef _HG_AUVAD_V0_H_
#define _HG_AUVAD_V0_H_
#ifdef __cplusplus
extern "C" {
#endif
int32 hg_auvad_v0_init(void);
int32 hg_auvad_v0_open(struct auvad_device *auvad, enum auvad_calc_mode mode);
int32 hg_auvad_v0_close(struct auvad_device *auvad);
int32 hg_auvad_v0_calc(struct auvad_device *auvad, void* dat_buf, uint32 bytes, uint32 calc_type, void* result_buf);
int32 hg_auvad_v0_ioctl(struct auvad_device *auvad, enum auvad_ioctl_cmd ioctl_cmd, uint32 param1, uint32 param2);
int32 hg_auvad_v0_request_irq(struct auvad_device *auvad, enum auvad_irq_flag irq_flag, auvad_irq_hdl irq_hdl, uint32 irq_data);
int32 hg_auvad_v0_release_irq(struct auvad_device *auvad, enum auvad_irq_flag irq_flag);
#ifdef __cplusplus
}
#endif
#endif /* _HG_AUVAD_V0_H_ */
+21
View File
@@ -0,0 +1,21 @@
#ifndef _HG_AUADC_V0_H_
#define _HG_AUADC_V0_H_
#ifdef __cplusplus
extern "C" {
#endif
int32 hg_auadc_v0_init(struct auadc_device *auadc);
int32 hg_auadc_v0_open(struct auadc_device *auadc, enum auadc_sample_rate sample_rate);
int32 hg_auadc_v0_close(struct auadc_device *auadc);
int32 hg_auadc_v0_read(struct auadc_device *auadc, void* buf, uint32 bytes);
int32 hg_auadc_v0_ioctl(struct auadc_device *auadc, enum auadc_ioctl_cmd ioctl_cmd, uint32 param1, uint32 param2);
int32 hg_auadc_v0_request_irq(struct auadc_device *auadc, enum auadc_irq_flag irq_flag, auadc_irq_hdl irq_hdl, uint32 irq_data);
int32 hg_auadc_v0_release_irq(struct auadc_device *auadc, enum auadc_irq_flag irq_flag);
#ifdef __cplusplus
}
#endif
#endif /* _HGI2S_V0_H_ */
+22
View File
@@ -0,0 +1,22 @@
#ifndef _HG_AUDAC_V0_H_
#define _HG_AUDAC_V0_H_
#ifdef __cplusplus
extern "C" {
#endif
int32 hg_audac_v0_init(struct audac_device *audac);
int32 hg_audac_v0_open(struct audac_device *audac, enum audac_sample_rate sample_rate);
int32 hg_audac_v0_close(struct audac_device *audac);
int32 hg_audac_v0_write(struct audac_device *audac, void* buf, uint32 bytes);
int32 hg_audac_v0_ioctl(struct audac_device *audac, enum audac_ioctl_cmd ioctl_cmd, uint32 param1, uint32 param2);
int32 hg_audac_v0_request_irq(struct audac_device *audac, enum audac_irq_flag irq_flag, audac_irq_hdl irq_hdl, uint32 irq_data);
int32 hg_audac_v0_release_irq(struct audac_device *audac, enum audac_irq_flag irq_flag);
#ifdef __cplusplus
}
#endif
#endif /* _HGI2S_V0_H_ */
+73
View File
@@ -0,0 +1,73 @@
#ifndef _HG_AUDIO_V0_H_
#define _HG_AUDIO_V0_H_
#ifdef __cplusplus
extern "C" {
#endif
/*!
* Type of device
*/
#define AUDIO_TYPE_AUADC BIT(0)
#define AUDIO_TYPE_AUDAC BIT(1)
#define AUDIO_TYPE_AUHS BIT(2)
#define AUDIO_TYPE_AUVAD BIT(3)
#define AUDIO_TYPE_AUALAW BIT(4)
#define AUDIO_TYPE_AUFADE BIT(5)
#define AUDIO_TYPE_AUEQ BIT(6)
/** @brief AUDIO operating handle structure
* @{
*/
/*!
* Common dat areas struct
*/
union __comm_dat{
uint32 comm;
struct {
uint32 adc_en :1,
dac_en :1,
hs_en :1,
alaw_en :1,
vad_en :1,
aufade_en :1,
eq_en :1,
ana_power_on :1,
ana_power_adc_on :1,
ana_power_dac_on :1;
} comm_bits;
};
struct hg_audio_v0 {
/* Pointer of device */
struct dev_obj dev;
uint32 hw;
/* common areas */
union __comm_dat comm_dat;
/* Pointer of common areas */
void *p_comm;
void *irq_hdl;
uint32 irq_data;
uint16 irq_num;
/* Type of device */
uint16 dev_type;
};
int32 hg_audio_v0_attach(uint32 dev_id, struct hg_audio_v0 *audio);
#ifdef __cplusplus
}
#endif
#endif /* _HGI2S_V0_H_ */
+53
View File
@@ -0,0 +1,53 @@
#ifndef _HGCAPTURE_V0_H
#define _HGCAPTURE_V0_H
#include "hal/capture.h"
#ifdef __cplusplus
extern "C" {
#endif
#define HGCAPTURE_MAX_CAPTURE_CHANNEL 4
enum hgcapture_v0_func_cmd {
HGCAPTURE_V0_FUNC_CMD_MASK = BIT(7),
HGCAPTURE_V0_FUNC_CMD_INIT = HGCAPTURE_V0_FUNC_CMD_MASK | 1,
HGCAPTURE_V0_FUNC_CMD_DEINIT = HGCAPTURE_V0_FUNC_CMD_MASK | 2,
HGCAPTURE_V0_FUNC_CMD_START = HGCAPTURE_V0_FUNC_CMD_MASK | 3,
HGCAPTURE_V0_FUNC_CMD_STOP = HGCAPTURE_V0_FUNC_CMD_MASK | 4,
/* IOCTL CMD */
/* IRQ_FLAG */
HGCAPTURE_V0_FUNC_CMD_REQUEST_IRQ_CAPTURE = HGCAPTURE_V0_FUNC_CMD_MASK | 5,
HGCAPTURE_V0_FUNC_CMD_REQUEST_IRQ_OVERFLOW = HGCAPTURE_V0_FUNC_CMD_MASK | 6,
HGCAPTURE_V0_FUNC_CMD_RELEASE_IRQ = HGCAPTURE_V0_FUNC_CMD_MASK | 7,
HGCAPTURE_V0_FUNC_CMD_SUSPEND = HGCAPTURE_V0_FUNC_CMD_MASK | 8,
HGCAPTURE_V0_FUNC_CMD_RESUME = HGCAPTURE_V0_FUNC_CMD_MASK | 9,
};
struct hgcapture_v0_config {
uint32 irq_data;
capture_irq_hdl irq_hdl;
uint16 func_cmd;
/* Only for config REG in lower layer code */
uint16 cap_sel:1,
cap_pol:1;
};
struct hgcapture_v0 {
struct capture_device dev;
void *channel[HGCAPTURE_MAX_CAPTURE_CHANNEL];
uint8 opened[HGCAPTURE_MAX_CAPTURE_CHANNEL];
};
int32 hgcapture_v0_attach(uint32 dev_id, struct hgcapture_v0 *capture);
#ifdef __cplusplus
}
#endif
#endif
+30
View File
@@ -0,0 +1,30 @@
#ifndef _HG_CRC_H_
#define _HG_CRC_H_
#include "hal/crc.h"
#ifdef __cplusplus
extern "C" {
#endif
struct hg_crc {
struct crc_dev dev;
void *hw;
struct os_mutex lock;
struct os_semaphore done;
uint32 irq_num;
uint32 flags;
#ifdef CONFIG_SLEEP
uint32 *regs;
#endif
};
int32 hg_crc_attach(uint32 dev_id, struct hg_crc *crc_c);
#ifdef __cplusplus
}
#endif
#endif /* _HG_CRC_H_ */
+46
View File
@@ -0,0 +1,46 @@
#ifndef HG_DVP_H
#define HG_DVP_H
#include "tx_platform.h"
#include "list.h"
#include "dev.h"
#include "hal/dvp.h"
#ifdef TXW80X
typedef enum {
HSIE_ISR = 0,
VSIE_ISR,
SSCIE_EIGHT_ISR,
FHFIE_ISR,
FOVIE_ISR,
SIP_ISR,
JPEG_DONE,
DVP_IRQ_NUM
}DVP_IRQ_E;
#endif
#ifdef TXW81X
typedef enum {
FOVIE_ISR = 0,
SII_ISR,
DVP_IRQ_NUM
}DVP_IRQ_E;
#endif
struct hgdvp {
struct dvp_device dev;
//struct hgdvp_hw *hw;
uint32 hw;
dvp_irq_hdl irq_hdl;
uint32 irq_data;
uint32 irq_num;
uint32 opened:1, use_dma:1, dsleep:1;
uint32 *cfg_backup;
};
int32 hgdvp_attach(uint32 dev_id, struct hgdvp *dvp);
#endif
+387
View File
@@ -0,0 +1,387 @@
#ifndef _DW_DMAC_H_
#define _DW_DMAC_H_
#include "hal/dma.h"
#ifdef __cplusplus
extern "C" {
#endif
/*! max dmac hardware channel
*/
#define DW_DMAC_MAX_DMAC_CHN 4
/*! max dmac hardware channel mask
*/
#define DW_DMAC_MAX_DMAC_CHN_MASK 0xF
/**
* @brief DMAC controller (IP)
*/
struct dw_dmac_hw_ch {
__IO uint32 SARL;
__IO uint32 SARH;
__IO uint32 DARL;
__IO uint32 DARH;
__IO uint32 FIFO0[2]; //LLPL,LLPH, NO USE
__IO uint32 CTLL;
__IO uint32 CTLH;
__IO uint32 FIFO1[8]; //SSTATL,SSTATH,DSTATL,DSTATH,SSTATARL,SSTATARH,DSTATARL,DSTATARH
__IO uint32 CFGL;
__IO uint32 CFGH;
__IO uint32 SGRL;
__IO uint32 SGRH;
__IO uint32 DSRL;
__IO uint32 DSRH;
};
/**
* @brief DMAC
*/
struct hgdma_dw_hw {
struct dw_dmac_hw_ch CH[4];
__IO uint32 FIFO0[22*4];
__IO uint32 RawTfrL;
__IO uint32 RawTfrH;
__IO uint32 RawBlockL;
__IO uint32 RawBlockH;
__IO uint32 RawSrcTranL;
__IO uint32 RawSrcTranH;
__IO uint32 RawDstTranL;
__IO uint32 RawDstTranH;
__IO uint32 RawErrL;
__IO uint32 RawErrH;
__IO uint32 FIFO1[5*2];
__IO uint32 MaskTfrL;
__IO uint32 MaskTfrH;
__IO uint32 MaskBlockL;
__IO uint32 MaskBlockH;
__IO uint32 MaskSrcTranL;
__IO uint32 MaskSrcTranH;
__IO uint32 MaskDstTranL;
__IO uint32 MaskDstTranH;
__IO uint32 MaskErrL;
__IO uint32 MaskErrH;
__IO uint32 ClearTfrL;
__IO uint32 ClearTfrH;
__IO uint32 ClearBlockL;
__IO uint32 ClearBlockH;
__IO uint32 ClearSrcTranL;
__IO uint32 ClearSrcTranH;
__IO uint32 ClearDstTranL;
__IO uint32 ClearDstTranH;
__IO uint32 ClearErrL;
__IO uint32 ClearErrH;
__IO uint32 FIFO2[2];
__IO uint32 ReqSrcRegL;
__IO uint32 ReqSrcRegH;
__IO uint32 ReqDstRegL;
__IO uint32 ReqDstRegH;
__IO uint32 SglReqSrcRegL;
__IO uint32 SglReqSrcRegH;
__IO uint32 SglReqDstRegL;
__IO uint32 SglReqDstRegH;
__IO uint32 LstSrcRegL;
__IO uint32 LstSrcRegH;
__IO uint32 LstDstRegL;
__IO uint32 LstDstRegH;
__IO uint32 DmaCfgRegL;
__IO uint32 DmaCfgRegH;
__IO uint32 ChEnRegL;
__IO uint32 ChEnRegH;
__IO uint32 FIFO3[2];
__IO uint32 DmaTestRegL;
__IO uint32 DmaTestRegH;
};
struct hgdma_dw {
struct dma_device dev;
struct hgdma_dw_hw *hw;
uint32 irq_num;
uint32 opened;
struct os_semaphore mem_chn;
struct os_semaphore dev_chn;
struct os_mutex dev_mutex;
dma_irq_hdl irq_hdl[DW_DMAC_MAX_DMAC_CHN];
uint32 irq_data[DW_DMAC_MAX_DMAC_CHN];
uint32 state[DW_DMAC_MAX_DMAC_CHN];
uint32 chn_used_flag;
};
/** @brief DW DMAC register constant table definition
* @{
*/
/***** DW_PARAMS Register *****/
/*! number of channels
*/
#define DW_DMAC_PARAMS_NR_CHAN 4
/*! number of AHB masters
*/
#define DW_DMAC_PARAMS_NR_MASTER 2
/***** DWC_PARAMS Register *****/
/*! multi block transfer
*/
#define DW_DMACC_PARAMS_MBLK_EN 11
/***** CTLx Register *****/
/*! irqs enabled
*/
#define DW_DMAC_CTLL_INT_EN (1UL << 0)
/*! The size of each element of destination transmission.
*/
#define DW_DMAC_CTLL_DST_WIDTH(n) (((n)&0x7) << 1)
/*! The size of each element of source transmission.
*/
#define DW_DMAC_CTLL_SRC_WIDTH(n) (((n)&0x7) << 4)
/*! Indicates destination address how to change on every source transfer.
*/
#define DW_DMAC_CTLL_DST_DIR(n) (((n)&0x3) << 7)
/*! Indicates source address how to change on every source transfer.
*/
#define DW_DMAC_CTLL_SRC_DIR(n) (((n)&0x3) << 9)
/*! Number of data items to be written to de destination every time.
*/
#define DW_DMAC_CTLL_DST_MSIZE(n) (((n)&0x7) << 11)
/*! Number of data items to be read from the source every time.
*/
#define DW_DMAC_CTLL_SRC_MSIZE(n) (((n)&0x7) << 14)
/*! src gather
*/
#define DW_DMAC_CTLL_S_GATH_EN (1UL << 17)
/* dst scatter
*/
//#define DW_DMAC_CTLL_D_SCAT_EN (1UL << 18)
/*! Transfer type and flow control.
*/
#define DW_DMAC_CTLL_FC(n) (((n)&0x7) << 20)
/*! dst master select : 1 for memory, 0 for peripherals
*/
#define DW_DMAC_CTLL_DMS(n) (((n)&0x3) << 23)
/*! src master select : 1 for memory, 0 for peripherals
*/
#define DW_DMAC_CTLL_SMS(n) (((n)&0x3) << 25)
/* dest block chain
*/
//#define DW_DMAC_CTLL_LLP_D_EN (1UL << 27)
/* src block chain
*/
//#define DW_DMAC_CTLL_LLP_S_EN (1UL << 28)
/***** CTL_HI Register *****/
/*! Block transfer done
*/
#define DW_DMAC_CTLH_DONE (0x00001000)
/*! Block transfer size. The max block size is 4095.
*/
#define DW_DMAC_CTLH_BLOCK_TS_MASK (0x00000FFF)
/***** CFG_LO Register *****/
/*! Channel priority mask
*/
#define DW_DMAC_CFGL_CH_PRIOR_MASK (0x7UL << 5)
/*! Channel priority
*/
#define DW_DMAC_CFGL_CH_PRIOR(n) (((n)&0x7) << 5)
/*! Channle Suspend. Suspends all DMA data transfers from the source until this
* bit is cleared.
*/
#define DW_DMAC_CFGL_CH_SUSP (1UL << 8)
/*! Indicates if there is data left in the channel FIFO.
*/
#define DW_DMAC_CFGL_FIFO_EMPTY (1UL << 9)
/*! Destination software or hardware handshaking select.
*/
#define DW_DMAC_CFGL_HS_DST (1UL << 10)
/*! Source software or hardware handshaking select.
*/
#define DW_DMAC_CFGL_HS_SRC (1UL << 11)
//#define DW_DMAC_CFGL_LOCK_CH_LEVEL(n) (((n)&0x3) << 12)
//#define DW_DMAC_CFGL_LOCK_BUS_LEVEL(n) (((n)&0x3) << 14)
//#define DW_DMAC_CFGL_LOCK_CH (1UL << 16)
//#define DW_DMAC_CFGL_LOCK_BUS (1UL << 17)
/*! Destination handshaking interface polarity.
*/
#define DW_DMAC_CFGL_HS_DST_POL (1UL << 18)
/*! Source handshaking interface polarity.
*/
#define DW_DMAC_CFGL_HS_SRC_POL (1UL << 19)
/*! Maximum AMBA burst length that is used for DMA transfers on this channel.
*/
#define DW_DMAC_CFGL_MAX_BURST(n) (((n)&0x2FF) << 20)
/*! Automatic source reload.
*/
#define DW_DMAC_CFGL_RELOAD_SAR (1UL << 30)
/*! Automatic desination reload.
*/
#define DW_DMAC_CFGL_RELOAD_DAR (1UL << 31)
/***** CFG_HI Register *****/
/*! Flow control mode.
*/
#define DW_DMAC_CFGH_FCMODE (1UL << 0)
/*! FIFO mode select.
*/
#define DW_DMAC_CFGH_FIFO_MODE (1UL << 1)
/*! Protection control.
*/
#define DW_DMAC_CFGH_PROTCTL(n) (((n)&0x7) << 2)
//#define DW_DMAC_CFGH_DS_UPD_EN (1UL << 5)
//#define DW_DMAC_CFGH_SS_UPD_EN (1UL << 6)
/*! Assigns a hardware handshaking interface to the source of channel.
*/
#define DW_DMAC_CFGH_SRC_PER(n) (((n)&0xF) << 7)
/*! Assigns a hardware handshaking interface to the destination of channel.
*/
#define DW_DMAC_CFGH_DST_PER(n) (((n)&0xF) << 11)
/***** SGR Register *****/
/*! Source gather interval.
*/
#define DW_DMAC_SGR_SGI(n) (((n)&0xFFFFF) << 0)
/*! Source gather count.
*/
#define DW_DMAC_SGR_SGC(n) (((n)&0xF) << 20)
/***** DSR Register *****/
//#define DW_DMAC_DSR_DSI(x) (((n)&0xFFFFF) << 0)
//#define DW_DMAC_DSR_DSC(x) (((n)&0xF) << 20)
/***** DmaCfgReg Register *****/
/*! dmac enable.
*/
#define DW_DMAC_CFG_DMA_EN (1UL << 0)
/***** ChEnRegL/MaskTfrL/MaskErrL/MaskDstTranL/MaskSrcTranL/MaskBlockL/ Register *****/
/*! Source gather count.
*/
#define DW_DMAC_WRITE_EN(n) ((1 << (n+8)) | (1 << n))
/*! Source gather count.
*/
#define DW_DMAC_WRITE_DIS(n) (1 << (n+8))
#define DW_DMAC_XFER_DONE(n) (1 << (n))
#define DW_DMAC_XFER_ERR(n) (1 << (n+8))
/**
* @}
*/
/** @brief DW DMAC external constant definition
* @{
*/
/**
* @breif Number of data items to be transferred(of width TR_WIDTH)
*/
enum dw_dmac_msize {
/*! damc data width : 1 TR_WIDTH
*/
DW_DMAC_MSIZE_1,
/*! damc data width : 4 TR_WIDTH
*/
DW_DMAC_MSIZE_4,
/*! damc data width : 8 TR_WIDTH
*/
DW_DMAC_MSIZE_8,
// The following MSIZE is not supported.
// DW_DMAC_MSIZE_16,
// DW_DMAC_MSIZE_32,
// DW_DMAC_MSIZE_64,
// DW_DMAC_MSIZE_128,
// DW_DMAC_MSIZE_256,
};
/**
* @brief The size of each element of destination transmission. The unit is bit.
*/
enum dw_dmac_tr_width {
/*! damc xfer width : 8 bit
*/
DW_DMAC_TR_8,
/*! damc xfer width : 16bit
*/
DW_DMAC_TR_16,
/*! damc xfer width : 32bit
*/
DW_DMAC_TR_32,
// The following TR_WIDTH is not supported.0
// DW_DMAC_TR_64,
// DW_DMAC_TR_128,
// DW_DMAC_TR_256,
};
/**
* @brief Indicates destination address how to change on every source transfer.
*/
enum dw_dmac_addr_dir {
/*! Increment
*/
DW_DMAC_ADDR_INC,
/*! Decrement
*/
DW_DMAC_ADDR_DEC,
/*! No change
*/
DW_DMAC_ADDR_NO_CHANGE,
};
/**
* @breif flow controller
@verbatim
-------------------------------------------------------------------------------
CTLL.TT_FC Field Transfer Type Flow Controller
-------------------------------------------------------------------------------
000 Memory to Memory DW_anb_dmac
001 Memory to Peripheral DW_anb_dmac
010 Peripheral to Memory DW_anb_dmac
011 Peripheral to Peripheral DW_anb_dmac
100 Peripheral to Memory Peripheral
101 Peripheral to Peripheral Source Peripheral
110 Memory to Peripheral Peripheral
111 Peripheral to Peripheral Destination Peripheral
@endverbatim
*/
enum dw_dmac_fc {
/*! Memory to Memory
*/
DW_DMAC_FC_D_M2M,
/*! Memory to Peripheral
*/
DW_DMAC_FC_D_M2P,
/*! Peripheral to Memory
*/
DW_DMAC_FC_D_P2M,
/*! Peripheral to Peripheral
*/
DW_DMAC_FC_D_P2P,
// The following flow control is not supported.
// DW_DMAC_FC_P_P2M,
// DW_DMAC_FC_SP_P2P,
// DW_DMAC_FC_P_M2P,
// DW_DMAC_FC_DP_P2P,
};
/**
* @}
*/
int32 dw_dmac_search_src_id(uint32 addr);
int32 dw_dmac_search_dest_id(uint32 addr);
int32 dw_dmac_attach(uint32 dev_id, struct hgdma_dw *dmac);
#ifdef __cplusplus
}
#endif
#endif
+78
View File
@@ -0,0 +1,78 @@
#ifndef _HG_M2M_DMA_H_
#define _HG_M2M_DMA_H_
#ifdef __cplusplus
extern "C" {
#endif
#define HG_M2M_DMA_NUM 2
/**
* @brief M2M_DMA
*/
struct mem_dma_ch {
__IO uint32 DMA_CON;
__IO uint32 DMA_SAIE;
__IO uint32 DMA_DATA;
__IO uint32 DMA_SADR;
__IO uint32 DMA_TADR;
__IO uint32 DMA_DLEN;
#ifdef TXW81X
__IO uint32 DMA_ISIZE;
#endif
};
struct mem_dma_hw {
struct mem_dma_ch dma_ch[HG_M2M_DMA_NUM];
};
struct mem_dma_dev {
struct dma_device dev;
struct mem_dma_hw *hw;
uint32 irq_num;
uint32 busy_flag : 8,
dma1_status : 1,
dma1_mutex : 1,
suspend : 1,
reserved : 21;
struct os_semaphore done[HG_M2M_DMA_NUM];
};
/** @brief M2M DMA register constant table definition
* @{
*/
/***** DMA_CON *****/
#define HG_M2M_DMA_CON_ENDIAN_SET(n) ((n) << 3)
#define HG_M2M_DMA_CON_ENDIAN_RES (3UL << 3)
#define HG_M2M_DMA_CON_BLKCPY (2UL << 1)
#define HG_M2M_DMA_CON_MEMSET (1UL << 1)
#define HG_M2M_DMA_CON_MEMCPY (0UL << 1)
#define HG_M2M_DMA_CON_DTE (1UL << 0)
/***** DMA_SAIE *****/
#define HG_M2M_DMA_SAIE_TCIE (1UL << 16)
#define HG_M2M_DMA_SAIE_TCP_PENDING (1UL << 0)
/***** DMA_ISIZE *****/
#define HG_M2M_DMA_ISZIE_DST_WIDTH(n) ((n) << 16)
#define HG_M2M_DMA_ISZIE_SRC_WIDTH(n) ((n) << 0)
/***** DMA_DLEN *****/
#define HG_M2M_DMA_DLEN_BLK_HEIGHT(n) ((n) << 20)
#define HG_M2M_DMA_DLEN_BLK_WIDTH(n) ((n) << 0)
/**
* @}
*/
int32 hg_m2m_dma_dev_attach(uint32 dev_id, struct mem_dma_dev *p_dma);
#ifdef __cplusplus
}
#endif
#endif
+92
View File
@@ -0,0 +1,92 @@
#ifndef _HG_GMAC_EVA_V2_H_
#define _HG_GMAC_EVA_V2_H_
#include "osal/task.h"
#include "lib/net/ethphy/eth_phy.h"
#include "hal/netdev.h"
#ifdef __cplusplus
extern "C" {
#endif
#define gmac_v2_dbg(fmt, ...) os_printf(fmt, ##__VA_ARGS__)
struct hg_gmac_data_v2 {
struct hg_gmac_v2_rx_descriptor volatile *p_rx_des;
struct hg_gmac_v2_tx_descriptor volatile *p_tx_des;
uint8 *p_rx_malloc;
uint8 *p_tx_malloc;
/*! In order not to splicing buf, the buf of the last RX descriptor
* should be able to fill one frame.
*/
/*!
* struct hg_gmac_v2_tx_descriptor rx_des[rx_des_num];
* uint8 rx_buf[rx_des_num-1][HG_GMAC_V2_RX_PER_BUF_SIZE];
* uint8 last_rx_buf[HG_GMAC_V2_RX_FRAME_MAX_SIZE];
*/
uint32 rx_des_num;
struct hg_gmac_v2_rx_descriptor *p_rx_des_buf;
uint8 *p_rx_buf;
/*!
* struct hg_gmac_v2_tx_descriptor tx_des[tx_des_num];
* uint8 tx_buf[tx_des_num][HG_GMAC_V2_TX_PER_BUF_SIZE];
*/
uint32 tx_des_num;
struct hg_gmac_v2_tx_descriptor *p_tx_des_buf;
uint8 *p_tx_buf;
};
struct hg_gmac_eva_v2_statistics {
uint32 tx_cnt;
uint32 rx_cnt;
uint32 ru_pending_cnt;
uint32 rx_err_cnt;
};
struct hg_gmac_eva_v2 {
struct netdev dev;
uint32 hw;
uint32 modbus_devid,
phy_devid,
crc_devid;
struct crc_dev *crcdev;
uint32 mdio_pin;
uint32 mdc_pin;
uint32 irq_num;
uint32 opened;
uint32 rgmii_en;
struct hg_gmac_data_v2 ctrl_data;
uint8 mac_addr[6];
netdev_input_cb input_cb;
void *input_priv;
uint32 tx_buf_size;
uint32 rx_buf_size;
struct os_task receive_task;
struct ethernet_phy_device *phydev;
struct ethernet_mdio_bus *mdio_bus;
/* Save link information */
int32 speed;
int32 duplex;
int32 link_status;
struct os_semaphore receive_sema;
struct os_mutex mdio_mutex;
struct os_mutex send_mutex;
struct hg_gmac_eva_v2_statistics statistics;
};
int32 hg_gmac_v2_attach(uint32 dev_id, struct hg_gmac_eva_v2 *gmac);
int32 hg_gmac_v2_has_received_frame(struct netdev *ndev);
int32 hg_gmac_v2_receive_data(struct netdev *emac_dev);
#ifdef __cplusplus
}
#endif
#endif
+28
View File
@@ -0,0 +1,28 @@
#ifndef _HUGEIC_GPIO_V3_H_
#define _HUGEIC_GPIO_V3_H_
#include "hal/gpio.h"
#ifdef __cplusplus
extern "C" {
#endif
#define HGGPIO_V3_MAX_PINS (16)
struct hggpio_v3 {
struct gpio_device dev;
uint32 hw;
int32 pin_id[HGGPIO_V3_MAX_PINS];
gpio_irq_hdl irq_hdl[HGGPIO_V3_MAX_PINS];
uint32 pin_num[2];
uint8 irq_num;
};
int32 hggpio_v3_attach(uint32 dev_id, struct hggpio_v3 *gpio);
#ifdef __cplusplus
}
#endif
#endif
+57
View File
@@ -0,0 +1,57 @@
#ifndef _HUGEIC_GPIO_V4_H_
#define _HUGEIC_GPIO_V4_H_
#include "hal/gpio.h"
#ifdef __cplusplus
extern "C" {
#endif
#define HGGPIO_V4_MAX_PINS (16)
struct gpio_bk{
__IO uint32_t MODE;
__IO uint32_t OTYPE;
__IO uint32_t OSPEEDL;
__IO uint32_t OSPEEDH;
__IO uint32_t PUPL;
__IO uint32_t PUPH;
__IO uint32_t PUDL;
__IO uint32_t PUDH;
__IO uint32_t ODAT;
__IO uint32_t AFRL;
__IO uint32_t AFRH;
__IO uint32_t IMK;
__IO uint32_t DEBEN;
__IO uint32_t AIOEN;
__IO uint32_t TRG0;
__IO uint32_t IEEN;
__IO uint32_t IOFUNCOUTCON0;
__IO uint32_t IOFUNCOUTCON1;
__IO uint32_t IOFUNCOUTCON2;
__IO uint32_t IOFUNCOUTCON3;
};
struct hggpio_v4 {
struct gpio_device dev;
uint32 hw;
uint32 comm_irq_num;
int32 pin_id[HGGPIO_V4_MAX_PINS];
gpio_irq_hdl irq_hdl[HGGPIO_V4_MAX_PINS];
uint32 pin_num[2];
uint8 irq_num;
uint32_t flag;
#ifdef CONFIG_SLEEP
struct gpio_bk bk;
#endif
};
int32 hggpio_v4_attach(uint32 dev_id, struct hggpio_v4 *gpio);
#ifdef __cplusplus
}
#endif
#endif
+59
View File
@@ -0,0 +1,59 @@
/**
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __HGI2C_H
#define __HGI2C_H
#ifdef __cplusplus
extern "C" {
#endif
struct hgi2c {
struct i2c_device dev;
uint32 hw;
i2c_irq_hdl irq_hdl;
uint32 irq_data;
uint32 irq_num;
struct os_mutex i2c_lock;
struct os_semaphore i2c_done;
uint32 irq_tx_done_en: 1,
irq_rx_done_en: 1,
flag_tx_done : 1,
flag_rx_done : 1,
opened : 1,
dsleep : 1;
#ifdef CONFIG_SLEEP
struct {
uint32 con0;
uint32 con1;
uint32 baud;
uint32 tdmalen;
uint32 rdmalen;
uint32 tstadr;
uint32 rstadr;
uint32 slavesta;
uint32 ssp_dly;
}bp_regs;
uint32 bp_irq_flags;
i2c_irq_hdl bp_irq_hdl;
uint32 bp_irq_data;
struct os_mutex bp_suspend_lock;
struct os_mutex bp_resume_lock;
#endif
};
int32 hgi2c_attach(uint32 dev_id, struct hgi2c *hgi2c_s);
#ifdef __cplusplus
}
#endif
#endif //__HGI2C_H
/*************************** (C) COPYRIGHT 2018 HUGE-IC ***** END OF FILE *****/
+64
View File
@@ -0,0 +1,64 @@
/**
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __HGI2C_V1_H
#define __HGI2C_V1_H
#ifdef __cplusplus
extern "C" {
#endif
struct hgi2c_v1 {
struct i2c_device dev;
uint32 hw;
i2c_irq_hdl irq_hdl;
uint32 irq_data;
uint32 irq_num;
struct os_mutex i2c_lock;
struct os_semaphore i2c_done;
uint32 irq_tx_done_en: 1,
irq_rx_done_en: 1,
flag_tx_done : 1,
flag_rx_done : 1,
opened : 1,
dsleep : 1;
#ifdef CONFIG_SLEEP
struct {
__IO uint32_t con0;
__IO uint32_t con1;
__IO uint32_t timecon;
__IO uint32_t tdmalen;
__IO uint32_t rdmalen;
__IO uint32_t tstadr;
__IO uint32_t rstadr;
__IO uint32_t slavesta;
__IO uint32_t ownadrcon;
__IO uint32_t timeoutcon;
__IO uint32_t rxtimeoutcon;
__IO uint32_t rstadr1;
__IO uint32_t vsync_tcon;
__IO uint32_t hsync_tcon;
}bp_regs;
uint32 bp_irq_flags;
i2c_irq_hdl bp_irq_hdl;
uint32 bp_irq_data;
struct os_mutex bp_suspend_lock;
struct os_mutex bp_resume_lock;
#endif
};
int32 hgi2c_v1_attach(uint32 dev_id, struct hgi2c_v1 *hgi2c_s);
#ifdef __cplusplus
}
#endif
#endif //__HGI2C_V1_H
/*************************** (C) COPYRIGHT 2018 HUGE-IC ***** END OF FILE *****/
+49
View File
@@ -0,0 +1,49 @@
#ifndef _HGI2S_V0_H_
#define _HGI2S_V0_H_
#include "hal/i2s.h"
#ifdef __cplusplus
extern "C" {
#endif
/** @brief I2S operating handle structure
* @{
*/
struct hgi2s_v0 {
struct i2s_device dev ;
uint32 hw ;
i2s_irq_hdl irq_hdl ;
uint32 irq_data ;
uint16 irq_num ;
uint16 opened :1,
dsleep :1,
duplex_en:1;
#ifdef CONFIG_SLEEP
struct {
uint32 con;
uint32 bit_set;
uint32 baud;
uint32 ws_con;
uint32 dma_stadr;
uint32 dma_len;
}bp_regs;
uint32 bp_irq_flags;
i2s_irq_hdl bp_irq_hdl;
uint32 bp_irq_data;
struct os_mutex bp_suspend_lock;
struct os_mutex bp_resume_lock;
#endif
};
int32 hgi2s_v0_attach(uint32 dev_id, struct hgi2s_v0 *i2s);
#ifdef __cplusplus
}
#endif
#endif /* _HGI2S_V0_H_ */
+67
View File
@@ -0,0 +1,67 @@
#ifndef HG_JPG_H
#define HG_JPG_H
#include "hal/jpeg.h"
//typedef int (*jgp_isr_func)(uint32);
//typedef int32 (*jpg_irq_hdl)(uint32 irq, uint32 irq_data, uint32 param);
#ifdef TXW80X
typedef enum {
DONE_IRQ,
JPG_OUTBUF_FULL,
JPG_BUF_ERR,
// JPG_READ_EMPTY,
// JPG_WRITE_FULL,
JPG_IRQ_NUM
}JPG_IRQ_E;
#endif
#ifdef TXW81X
typedef enum {
DONE_IRQ,
JPG_OUTBUF_FULL,
JPG_BUF_ERR,
JPG_PIXEL_DONE,
// JPG_READ_EMPTY,
// JPG_WRITE_FULL,
JPG_IRQ_NUM
}JPG_IRQ_E;
#endif
struct hgjpg {
struct jpg_device dev;
uint32 hw;
uint32 thw;
//jpg_irq_hdl irq_hdl;
uint32 irq_num;
uint32 opened :1,
init :1,
dsleep: 1;
int32 addr_count;
uint32 *cfg_backup;
};
//int32 jpg_open(struct jpg_device *p_jpg);
//int32 jpg_close(struct jpg_device *p_jpg);
//int32 jpg_init(struct jpg_device *p_jpg,uint32 table_index,uint32 qt,uint32 buflen,uint32 head_reserver);
//int32 jpg_set_size(struct jpg_device *p_jpg,uint32 h,uint32 w);
//int32 jpg_set_len(struct jpg_device *p_jpg,uint32 buflen,uint32 head_reserver);
//int32 jpg_updata_dqt(struct jpg_device *p_jpg,uint32* dqtbuf);
//int32 jpg_set_addr(struct jpg_device *p_jpg,uint32 addr);
//int32 jpg_set_qt(struct jpg_device *p_jpg,uint32 qt);
//int32 jpg_get_len(struct jpg_device *p_jpg);
//int32 jpg_get_outbuf_num(struct jpg_device *p_jpg);
//int32 jpg_request_irq(struct jpg_device *p_jpg,uint32 irq, jgp_isr_func isr, void *dev_id);
//int32 jpg_release_irq(struct jpg_device *p_jpg,uint32 irq);
void hgjpg_attach(uint32 dev_id, struct hgjpg *jpg);
#endif
+29
View File
@@ -0,0 +1,29 @@
#ifndef HG_LCDC_H
#define HG_LCDC_H
#include "tx_platform.h"
#include "list.h"
#include "dev.h"
#include "hal/lcdc.h"
typedef enum {
LCD_DONE_IRQ,
LCD_TE_IRQ,
OSD_EN_IRQ,
TIMEOUT_IRQ,
LCD_IRQ_NUM
}LCD_IRQ_E;
struct hglcdc {
struct lcdc_device dev;
uint32 hw;
lcdc_irq_hdl irq_hdl;
uint32 irq_data;
uint32 irq_num;
uint32 opened:1, use_dma:1, dsleep:1;
uint32 *cfg_backup;
};
int32 hglcdc_attach(uint32 dev_id, struct hglcdc *lcdc);
#endif
+28
View File
@@ -0,0 +1,28 @@
#ifndef _HGLED_V0_H
#define _HGLED_V0_H
#include "hal/led.h"
#ifdef __cplusplus
extern "C" {
#endif
struct hgled_v0 {
struct led_device dev;
uint32 hw;
led_irq_hdl irq_hdl;
uint32 irq_data;
uint32 irq_num;
uint16 seg_cnt;
uint16 com_cnt;
uint32 tube_type;
uint32 opened;
};
int32 hgled_v0_attach(uint32 dev_id, struct hgled_v0 *led);
#ifdef __cplusplus
}
#endif
#endif
+18
View File
@@ -0,0 +1,18 @@
#ifndef HG_OF_H
#define HG_OF_H
#include "tx_platform.h"
#include "list.h"
#include "dev.h"
#include "hal/of.h"
struct hgof {
struct of_device dev;
uint32 hw;
uint32 irq_data;
uint32 irq_num;
uint32 opened:1, use_dma:1;
};
void hgof_attach(uint32 dev_id, struct hgof *of);
#endif
+41
View File
@@ -0,0 +1,41 @@
#ifndef _HGPDM_V0_H_
#define _HGPDM_V0_H_
#include "hal/pdm.h"
#ifdef __cplusplus
extern "C" {
#endif
struct hgpdm_v0 {
struct pdm_device dev;
uint32 hw;
pdm_irq_hdl irq_hdl;
uint32 irq_data;
uint16 irq_num;
uint16 opened:1,
dsleep:1;
#ifdef CONFIG_SLEEP
struct {
uint32 con;
uint32 dmacon;
uint32 dmastadr;
uint32 dmalen;
}bp_regs;
uint32 bp_irq_flags;
pdm_irq_hdl bp_irq_hdl;
uint32 bp_irq_data;
struct os_mutex bp_suspend_lock;
struct os_mutex bp_resume_lock;
#endif
};
int32 hgpdm_v0_attach(uint32 dev_id, struct hgpdm_v0 *pdm);
#ifdef __cplusplus
}
#endif
#endif
+29
View File
@@ -0,0 +1,29 @@
#ifndef HG_PRC_H
#define HG_PRC_H
#include "tx_platform.h"
#include "list.h"
#include "dev.h"
#include "hal/prc.h"
typedef enum {
PRC_ISR = 0,
PRC_IRQ_NUM,
}PRC_IRQ_E;
struct hgprc {
struct prc_device dev;
//struct hgdvp_hw *hw;
uint32 hw;
prc_irq_hdl irq_hdl;
uint32 irq_data;
uint32 irq_num;
uint32 opened:1, use_dma:1, dsleep:1;
uint32 *cfg_backup;
};
void hgprc_attach(uint32 dev_id, struct hgprc *prc);
#endif
+58
View File
@@ -0,0 +1,58 @@
#ifndef _HGPWM_V0_H
#define _HGPWM_V0_H
#include "hal/pwm.h"
#ifdef __cplusplus
extern "C" {
#endif
#define HGPWM_MAX_PWM_CHANNEL 6
enum hgpwm_v0_func_cmd {
HGPWM_V0_FUNC_CMD_MASK = BIT(6),
HGPWM_V0_FUNC_CMD_INIT = HGPWM_V0_FUNC_CMD_MASK | 1,
HGPWM_V0_FUNC_CMD_DEINIT = HGPWM_V0_FUNC_CMD_MASK | 2,
HGPWM_V0_FUNC_CMD_START = HGPWM_V0_FUNC_CMD_MASK | 3,
HGPWM_V0_FUNC_CMD_STOP = HGPWM_V0_FUNC_CMD_MASK | 4,
/* IOCTL CMD */
HGPWM_V0_FUNC_CMD_IOCTL_SET_PERIOD_DUTY = HGPWM_V0_FUNC_CMD_MASK | 5,
HGPWM_V0_FUNC_CMD_IOCTL_GET_PERIOD_DUTY = HGPWM_V0_FUNC_CMD_MASK | 6,
HGPWM_V0_FUNC_CMD_IOCTL_SET_SINGLE_INCREAM = HGPWM_V0_FUNC_CMD_MASK | 7,
HGPWM_V0_FUNC_CMD_IOCTL_SET_INCREAM_DECREASE = HGPWM_V0_FUNC_CMD_MASK | 8,
HGPWM_V0_FUNC_CMD_IOCTL_SET_PRESCALER = HGPWM_V0_FUNC_CMD_MASK | 14,
HGPWM_V0_FUNC_CMD_IOCTL_SET_PERIOD_DUTY_IMMEDIATELY = HGPWM_V0_FUNC_CMD_MASK | 15,
/* IRQ_FLAG */
HGPWM_V0_FUNC_CMD_REQUEST_IRQ_COMPARE = HGPWM_V0_FUNC_CMD_MASK | 9,
HGPWM_V0_FUNC_CMD_REQUEST_IRQ_PERIOD = HGPWM_V0_FUNC_CMD_MASK | 10,
HGPWM_V0_FUNC_CMD_RELEASE_IRQ = HGPWM_V0_FUNC_CMD_MASK | 11,
HGPWM_V0_FUNC_CMD_SUSPEND = HGPWM_V0_FUNC_CMD_MASK | 12,
HGPWM_V0_FUNC_CMD_RESUME = HGPWM_V0_FUNC_CMD_MASK | 13,
};
struct hgpwm_v0_config {
uint32 period;
uint32 duty;
pwm_irq_hdl irq_hdl;
uint32 irq_data;
uint32 func_cmd;
uint32 param1;
uint32 param2;
};
struct hgpwm_v0 {
struct pwm_device dev;
void *channel[HGPWM_MAX_PWM_CHANNEL];
uint8 opened[HGPWM_MAX_PWM_CHANNEL];
};
int32 hgpwm_v0_attach(uint32 dev_id, struct hgpwm_v0 *pwm);
#ifdef __cplusplus
}
#endif
#endif
+38
View File
@@ -0,0 +1,38 @@
#ifndef _HGRTC_V1_H
#define _HGRTC_V1_H
#include "hal/rtc.h"
#ifdef __cplusplus
extern "C" {
#endif
struct hgrtc_v0 {
struct rtc_device dev;
uint32 hw;
rtc_irq_hdl irq_hdl;
uint32 irq_data;
uint32 irq_num;
struct os_mutex os_lock_set_time;
struct os_mutex os_lock_get_time;
struct rtc_time_type time;
struct {
//1:闰年;0:平年
uint8 leap_year;
}time_ctrl;
uint8 irq_second:1,
opened :1;
};
int32 hgrtc_v0_attach(uint32 dev_id, struct hgrtc_v0 *rtc);
#ifdef __cplusplus
}
#endif
#endif
+30
View File
@@ -0,0 +1,30 @@
#ifndef HG_SCALE_H
#define HG_SCALE_H
#include "tx_platform.h"
#include "list.h"
#include "dev.h"
#include "hal/scale.h"
typedef enum {
FRAME_END,
INBUF_OV,
SCALE_IRQ_NUM
}SCALE_IRQ_E;
struct hgscale {
struct scale_device dev;
uint32 hw;
scale_irq_hdl irq_hdl;
uint32 irq_data;
uint32 irq_num;
uint32 opened:1, use_dma:1, dsleep:1;
uint32 *cfg_backup;
};
int32 hgscale1_attach(uint32 dev_id, struct hgscale *scale);
int32 hgscale2_attach(uint32 dev_id, struct hgscale *scale);
int32 hgscale3_attach(uint32 dev_id, struct hgscale *scale);
#endif
+36
View File
@@ -0,0 +1,36 @@
#ifndef _HGSDIO20_SLAVE_H_
#define _HGSDIO20_SLAVE_H_
#include "hal/sdio_slave.h"
#ifdef __cplusplus
extern "C" {
#endif
struct hgsdio20_slave {
struct sdio_slave dev;
void *hw;
sdio_slave_irq_hdl irq_hdl;
uint32 irq_data;
struct os_mutex tx_lock;
struct os_semaphore tx_done;
uint8 *rx_buff;
uint8 irq_num;
uint8 rst_irq_num;
uint8 flags;
uint8 opened: 1, rev: 7;
uint16 rx_len;
uint8 speed, rev2;
uint8 func0_cis[17];
uint8 func1_cis[53];
};
int32 hgsdio20_slave_attach(uint32 dev_id, struct hgsdio20_slave *slave);
#ifdef __cplusplus
}
#endif
#endif /* _HGSDIO20_SLAVE_H_ */
+43
View File
@@ -0,0 +1,43 @@
#ifndef _HGSHA_V0_H_
#define _HGSHA_V0_H_
#include "hal/sha.h"
#ifdef __cplusplus
extern "C" {
#endif
struct hgsha_v0 {
struct sha_dev dev;
void *hw;
struct os_mutex lock;
struct os_semaphore done;
uint32 irq_hw_num;
uint32 irq_num;
uint32 alg_type;
uint8 buf[64];
unsigned long long bit_len;
uint32 buf_cnt;
uint32 blk_size;
void * task;
void * usr_p;
volatile uint32 flags_intr_busy :1,
flags_intr_handing :1,
flags_intr_revs :30;
volatile uint32 flags_mod_started :1,
flags_got_result :1,
flags_redir_result :1,
flags_revs :29;
#ifdef CONFIG_SLEEP
uint32 hash[8];
#endif
// volatile uint32 ;
void (*sha_irq_func)(void *args);
void *irq_func_data;
};
int32 hgsha_v0_attach(uint32 dev_id, struct hgsha_v0 *sha);
#endif /* _hgsha256_H_ */
+15
View File
@@ -0,0 +1,15 @@
#ifndef _HGIC_SDSPI_H_
#define _HGIC_SDSPI_H_
#ifdef __cplusplus
extern "C" {
#endif
int32 hgic_sdspi_attach(uint32 dev_id, uint32 spi_dev);
#ifdef __cplusplus
}
#endif
#endif
+57
View File
@@ -0,0 +1,57 @@
#ifndef _HGSPI_V1_H_
#define _HGSPI_V1_H_
#include "hal/spi.h"
#ifdef __cplusplus
extern "C" {
#endif
struct hgspi_v1 {
struct spi_device dev;
uint32 hw;
uint32 irq_num;
spi_irq_hdl irq_hdl;
uint32 irq_data;
//struct os_mutex os_spi_tx_lock;
//struct os_mutex os_spi_rx_lock;
struct os_mutex os_spi_lock;
struct os_semaphore os_spi_tx_done;
struct os_semaphore os_spi_rx_done;
uint32 timeout;
uint16 len_threshold;
uint16 spi_tx_done :1,
spi_rx_done :1,
spi_irq_flag_tx_done :1,
spi_irq_flag_rx_done :1,
spi_tx_async :1,
spi_rx_async :1,
opened :1,
dsleep :1;
#ifdef CONFIG_SLEEP
struct {
uint32 con0;
uint32 con1;
uint32 baud;
uint32 tdmalen;
uint32 rdmalen;
uint32 tstadr;
uint32 rstadr;
uint32 slavesta;
uint32 ssp_dly;
}bp_regs;
uint32 bp_irq_flags;
spi_irq_hdl bp_irq_hdl;
uint32 bp_irq_data;
struct os_mutex bp_suspend_lock;
struct os_mutex bp_resume_lock;
#endif
};
int32 hgspi_v1_attach(uint32 dev_id, struct hgspi_v1 *p_spi);
#ifdef __cplusplus
}
#endif
#endif /* _HGSPI_V1_H_ */
+28
View File
@@ -0,0 +1,28 @@
#ifndef _HGSPI_V2_H
#define _HGSPI_V2_H
#ifdef __cplusplus
extern "C" {
#endif
struct hgspi_v2 {
struct spi_device dev;
uint32 hw ;
spi_irq_hdl irq_hdl ;
uint32 irq_data;
uint32 irq_num ;
uint16 opened ;
uint16 spi_irq_flag_tx_done: 1,
spi_irq_flag_rx_done: 1;
};
int32 hgspi_v2_attach(uint32 dev_id, struct hgspi_v2 *spi);
#ifdef __cplusplus
}
#endif
#endif
+69
View File
@@ -0,0 +1,69 @@
#ifndef _HGSPI_V3_H_
#define _HGSPI_V3_H_
#include "hal/spi.h"
#ifdef __cplusplus
extern "C" {
#endif
struct hgspi_v3 {
struct spi_device dev;
uint32 hw;
uint32 irq_num;
spi_irq_hdl irq_hdl;
uint32 irq_data;
//struct os_mutex os_spi_tx_lock;
//struct os_mutex os_spi_rx_lock;
struct os_mutex os_spi_lock;
struct os_semaphore os_spi_tx_done;
struct os_semaphore os_spi_rx_done;
uint32 timeout;
uint16 len_threshold;
uint16 spi_tx_done :1,
spi_rx_done :1,
spi_irq_flag_tx_done :1,
spi_irq_flag_rx_done :1,
spi_tx_async :1,
spi_rx_async :1,
opened :1,
dsleep :1;
#ifdef CONFIG_SLEEP
struct {
uint32 con0;
uint32 con1;
uint32 cmd_data;
uint32 timecon;
uint32 tdmalen;
uint32 rdmalen;
uint32 tdmacnt;
uint32 rdmacnt;
uint32 tstadr;
uint32 rstadr;
uint32 sta1;
uint32 sta2;
uint32 slavesta;
uint32 ownadrcon;
uint32 rbuf;
uint32 timeoutcon;
uint32 rxtimeoutcon;
uint32 rstadr1;
uint32 vsync_tcon;
uint32 hsync_tcon;
}bp_regs;
uint32 bp_irq_flags;
spi_irq_hdl bp_irq_hdl;
uint32 bp_irq_data;
struct os_mutex bp_suspend_lock;
struct os_mutex bp_resume_lock;
#endif
};
int32 hgspi_v3_attach(uint32 dev_id, struct hgspi_v3 *p_spi);
#ifdef __cplusplus
}
#endif
#endif /* _HGSPI_V3_H_ */
+90
View File
@@ -0,0 +1,90 @@
#ifndef _HGSPI_XIP_H_
#define _HGSPI_XIP_H_
#include "hal/spi.h"
#ifdef __cplusplus
extern "C" {
#endif
enum hgspi_xip_flags {
hgspi_xip_flags_ready,
hgspi_xip_flags_suspend,
hgspi_xip_flags_suspend_pasr,
hgspi_xip_flags_suspend_ulp,
hgspi_xip_flags_suspend_pd,
hgspi_xip_flags_xip,
};
struct hgspi_xip {
struct spi_device dev;
// struct os_mutex xip_lock;
uint32 hw;
uint32 flags;
#ifdef CONFIG_SLEEP
uint32 regs[30];
#endif
};
struct hgcqspi {
//struct qspi_device dev;
void *hw;
uint32 irq_num;
//qspi_irq_hdl irq_hdl;
uint32 irq_data;
uint32 opened;
uint32 flags;
};
struct hgxip_flash_custom_read
{
uint8_t dummys; //最大31,内部默认有24个dummys
uint8_t cmd;
uint16_t size;
uint32_t addr;
uint8_t *buf;
};
struct hgxip_flash_reg_opt_param
{
uint8_t cmd;
/* write opt when pre_cmd is valid(0xFF != pre_cmd); e.g.: 0x06/0x50 */
uint8_t pre_cmd;
uint8_t len;
uint8_t *buf;
};
enum MSROM_FUNC
{
MSROM_MEMSET,
MSROM_MEMCPY,
MSROM_MEMCMP,
MSROM_STRCASECMP,
MSROM_QSPI_CMD_BUSY_WAIT = MSROM_STRCASECMP,
MSROM_STRNCASECMP,
MSROM_HIGHPASS_FILTER_100HZ_ASM = MSROM_STRNCASECMP,
MSROM_QSPI_XIP_ERASE,
MSROM_QSPI_XIP_READ,
MSROM_QSPI_XIP_WRITE,
MSROM_QSPI_XIP_OPT_ENTER,
MSROM_QSPI_XIP_OPT_EXIT,
MSROM_QSPI_ENTER_XIP_MODE,
MSROM_QSPI_EXIT_XIP_MODE,
MSROM_QSPI_STIG,
MSROM_OSPI_PSRAM_MRR,
MSROM_OSPI_PSRAM_MRW,
MSROM_OSPI_STIG,
};
int32 hgspi_xip_attach(uint32 dev_id, struct hgspi_xip *p_spi);
uint32_t get_msrom_func(uint32_t func_code);
#ifdef __cplusplus
}
#endif
#endif /* _HGSPI_V1_H_ */
+23
View File
@@ -0,0 +1,23 @@
#ifndef _HG_SYSAES_V2_H_
#define _HG_SYSAES_V2_H_
#include "hal/sysaes.h"
#ifdef __cplusplus
extern "C" {
#endif
struct hg_sysaes_v2 {
struct sysaes_dev dev;
void *hw;
struct os_mutex lock;
struct os_semaphore done;
uint32 irq_num;
uint32 flags;
#ifdef CONFIG_SLEEP
uint32 *regs;
#endif
};
int32 hg_sysaes_v2_attach(uint32 dev_id, struct hg_sysaes_v2 *sysaes);
#endif /* _HG_SYSAES_V2_H_ */
+23
View File
@@ -0,0 +1,23 @@
#ifndef _HG_SYSAES_V3_H_
#define _HG_SYSAES_V3_H_
#include "hal/sysaes.h"
#ifdef __cplusplus
extern "C" {
#endif
struct hg_sysaes_v3 {
struct sysaes_dev dev;
void *hw;
struct os_mutex lock;
struct os_semaphore done;
uint32 irq_num;
uint32 flags;
#ifdef CONFIG_SLEEP
uint32 *regs;
#endif
};
int32 hg_sysaes_v3_attach(uint32 dev_id, struct hg_sysaes_v3 *sysaes);
#endif /* _HG_SYSAES_V3_H_ */
+494
View File
@@ -0,0 +1,494 @@
#ifndef _HGTIMER_V3_H_
#define _HGTIMER_V3_H_
#include "hal/timer_device.h"
#ifdef __cplusplus
extern "C" {
#endif
/** @brief TIMER register structure
* @{
*/
struct hgtimer_hw {
__IO uint32_t TMR_CON;
__IO uint32_t TMR_EN;
__IO uint32_t TMR_IE;
__IO uint32_t TMR_CNT;
__IO uint32_t TMR_FLG;
__IO uint32_t TMR_CLR;
__IO uint32_t TMR_CAP1;
__IO uint32_t TMR_CAP2;
__IO uint32_t TMR_CAP3;
__IO uint32_t TMR_CAP4;
__IO uint32_t TMR_DCTL;
__IO uint32_t TMR_DADR;
__IO uint32_t TMR_DLEN;
__IO uint32_t TMR_DCNT;
__IO uint32_t TMR_IR_BCNT;
};
struct hgtimer {
struct timer_device dev;
struct hgtimer_hw *hw;
uint32 irq_num;
timer_cb_hdl cb;
uint32 cb_data;
enum timer_type mode;
uint32 flags;
uint32 opened;
};
struct hgtimer_all {
__IO uint32_t TMR_ALLCON;
};
/**
* @}
*/
/** @defgroup TIMER_Register_Constants TIMER Register Constants
* @ingroup TIMER_Driver
* @brief TIMER register constant table definition
* @{
*/
/***** TIMERx CON Register *****/
/*! Timer IR selection from TIMER0, TIMER2~7
*/
#define LL_TIMER_CON_IR_FIRST_LSB (1UL << 29)
/*! Timer IR function logic 0 PWM polarity selection (for TIMER1 only)
*/
#define LL_TIMER_CON_IR_ZERO_PWMPOL (1UL << 28)
/*! Timer IR function logic 1 PWM polarity selection (for TIMER1 only)
*/
#define LL_TIMER_CON_IR_ONE_PWMPOL (1UL << 27)
/*! Timer IR function enable (for TIMER1 only)
*/
#define LL_TIMER_CON_IR_EN (1UL << 26)
/*! PWM polarity selection in TIMER module
*/
#define LL_TIMER_CON_PWMPOL (1UL << 25)
/*! The polarity of capture event 4 is selected: 0 = rising edge, 1 = falling edge.
*/
#define LL_TIMER_CON_CAP4POL (1UL << 24)
/*! The polarity of capture event 3 is selected: 0 = rising edge, 1 = falling edge.
*/
#define LL_TIMER_CON_CAP3POL (1UL << 23)
/*! The polarity of capture event 2 is selected: 0 = rising edge, 1 = falling edge.
*/
#define LL_TIMER_CON_CAP2POL (1UL << 22)
/*! The polarity of capture event 1 is selected: 0 = rising edge, 1 = falling edge.
*/
#define LL_TIMER_CON_CAP1POL (1UL << 21)
/*! When the capture event 4 occurs, the value of the CNT is automatically cleared.
*/
#define LL_TIMER_CON_CTRRST4 (1UL << 20)
/*! When the capture event 3 occurs, the value of the CNT is automatically cleared.
*/
#define LL_TIMER_CON_CTRRST3 (1UL << 19)
/*! When the capture event 2 occurs, the value of the CNT is automatically cleared.
*/
#define LL_TIMER_CON_CTRRST2 (1UL << 18)
/*! When the capture event 1 occurs, the value of the CNT is automatically cleared.
*/
#define LL_TIMER_CON_CTRRST1 (1UL << 17)
/*! The number of the Capture register:
* 00 : Capture data store in CAP1
* 01 : Capture data store in CAP1 CAP2
* 10 : Capture data store in CAP1 CAP2 CAP3
* 11 : Capture data store in CAP1 CAP2 CAP3 CAP4
*/
#define LL_TIMER_CON_CAP_CNT(n) (((n)&0x3) << 15)
/*! Capture selection:
* 00 : GPIO
* 01 : GPIO OR
* 10 : compare0 output
* 11 : compare1 output
*/
#define LL_TIMER_CON_CAP_SEL(n) (((n)&0x3) << 13)
/*! Output sync signal selection:
* 00 : CNT value = PRD value
* 01 : CNT value = CMP value
* 10 : Output SYNCI value to SYNCO
* 11 : PWM output is assigned to SYNCO
*/
#define LL_TIMER_CON_SYNCO_SEL(n) (((n)&0x3) << 11)
/*! Synci polarity inversion:
* 1 : Invert
* 0 : not reversed
*/
#define LL_TIMER_CON_SYNCI_POL (1UL << 10)
/*! Synci function selection
* 00 : disable
* 01 : kick start
* 10 : reset
* 11 : gating
*/
#define LL_TIMER_CON_SLAVE_MODE(n) (((n)&0x3) << 8)
/*! Timer prescaler settings:
* 000 : 0 frequency division
* 001 : 2 frequency division
* 010 : 4 frequency division
* 011 : 8 frequency division
* 100 : 16 frequency division
* 101 : 32 frequency division
* 110 : 64 frequency division
* 111 : 128 frequency division
*/
#define LL_TIMER_CON_PSC(n) (((n)&0x7) << 5)
/*! Timer counter source select bits:
* 001 : Internal high speed RC
* 010 : Internal low speed RC
* 011 : External crystal oscillator divided by 2 clocks
* 100 : timer inc pin rising
* 101 : timer inc pin falling
* 110 : timer inc pin rising and falling
* Others : system clock
*/
#define LL_TIMER_CON_INC_SRC_SEL(n) (((n)&0x7) << 2)
/*! Timer mode select bits:
* 00 : timer counter mode
* 01 : timer pwm mode
* 10 : timer capture mode
* Others : reservation
*/
#define LL_TIMER_CON_MODE_SEL(n) (((n)&0x3) << 0)
/***** TIMERx EN Register *****/
/*! TMR enable signal, active high.
*/
#define LL_TIMER_EN_TMREN (1UL << 0)
/***** TIMERx IE Register *****/
/*! Timer IR TX word done interrupt enable (for TIMER1 only)
*/
#define LL_TIMER_IE_IR_TX_WORD_DONE_IE (1UL << 11)
/*! Timer IR TX done interrupt enable (for TIMER1 only)
*/
#define LL_TIMER_IE_IR_TX_DONE_IE (1UL << 10)
/*! Dma buffer full interrupt enable.
*/
#define LL_TIMER_IE_DMA_FL_IE (1UL << 9)
/*! Dma buffer half full interrupt enable.
*/
#define LL_TIMER_IE_DMA_HF_IE (1UL << 8)
/*! The slave mode trigger mode or reset mode interrupt enable.
*/
#define LL_TIMER_IE_SLAVE_IE (1UL << 7)
/*! When the CNT value is equal to the CMP value, the interrupt is enabled and is valid only in pwm mode.
*/
#define LL_TIMER_IE_CMP_IE (1UL << 6)
/*! When the CNT value is equal to the PRD value, the interrupt is enabled and is valid only in the counter mode/PWM mode.
*/
#define LL_TIMER_IE_PRD_IE (1UL << 5)
/*! When the CNT value overflows (16'hffff), the interrupt is enabled.
*/
#define LL_TIMER_IE_OVF_IE (1UL << 4)
/*! When the capture event 4 occurs, the interrupt is enabled.
*/
#define LL_TIMER_IE_CAP4_IE (1UL << 3)
/*! When the capture event 3 occurs, the interrupt is enabled.
*/
#define LL_TIMER_IE_CAP3_IE (1UL << 2)
/*! When the capture event 2 occurs, the interrupt is enabled.
*/
#define LL_TIMER_IE_CAP2_IE (1UL << 1)
/*! When the capture event 1 occurs, the interrupt is enabled.
*/
#define LL_TIMER_IE_CAP1_IE (1UL << 0)
/***** TIMERx CNT Register *****/
/*! Count register.
*/
#define LL_TIMER_CNT(n) (((n)&0xFFFFFFFF) << 0)
/***** TIMERx FLG Register *****/
/*! Timer IR TX word done interrupt flag (for TIMER1 only)
*/
#define LL_TIMER_IE_IR_TX_WORD_DONE_FLG (1UL << 11)
/*! Timer IR TX done interrupt flag (for TIMER1 only)
*/
#define LL_TIMER_IE_IR_TX_DONE_FLG (1UL << 10)
/*! Dma buffer full sign.
*/
#define LL_TIMER_IE_DMA_FL_FLG (1UL << 9)
/*! Dma buffer half full sign.
*/
#define LL_TIMER_IE_DMA_HF_FLG (1UL << 8)
/*! The slave mode flag (reset or trigger only).
*/
#define LL_TIMER_IE_SLAVE_FLG (1UL << 7)
/*! The CNT value is equal to the CMP value flag and is valid only in pwm mode.
*/
#define LL_TIMER_IE_CMP_FLG (1UL << 6)
/*! The CNT value is equal to the PRD value flag and is valid only in counter mode/PWM mode.
*/
#define LL_TIMER_IE_PRD_FLG (1UL << 5)
/*! CNT value overflow (16'hffff) flag.
*/
#define LL_TIMER_IE_OVF_FLG (1UL << 4)
/*! Capture event 4 occurs.
*/
#define LL_TIMER_IE_CAP4_FLG (1UL << 3)
/*! Capture event 3 occurs.
*/
#define LL_TIMER_IE_CAP3_FLG (1UL << 2)
/*! Capture event 2 occurs.
*/
#define LL_TIMER_IE_CAP2_FLG (1UL << 1)
/*! Capture event 1 occurs.
*/
#define LL_TIMER_IE_CAP1_FLG (1UL << 0)
/***** TIMERx CLR Register *****/
/*! Timer IR TX word done interrupt clear (for TIMER1 only)
*/
#define LL_TIMER_IE_IR_TX_WORD_DONE_CLR (1UL << 11)
/*! Timer IR TX done interrupt clear (for TIMER1 only)
*/
#define LL_TIMER_IE_IR_TX_DONE_CLR (1UL << 10)
/*! Dma buffer full sign clear.
*/
#define LL_TIMER_IE_DMA_FL_CLR (1UL << 9)
/*! Dma buffer half full sign clear.
*/
#define LL_TIMER_IE_DMA_HF_CLR (1UL << 8)
/*! The slave mode flag (reset or trigger only) clear.
*/
#define LL_TIMER_IE_SLAVE_CLR (1UL << 7)
/*! The CNT value is equal to the CMP value flag clear.
*/
#define LL_TIMER_IE_CMP_CLR (1UL << 6)
/*! The CNT value is equal to the PRD value flag clear.
*/
#define LL_TIMER_IE_PRD_CLR (1UL << 5)
/*! The CNT value overflow (16'hffff) flag is cleared.
*/
#define LL_TIMER_IE_OVF_CLR (1UL << 4)
/*! Capture event 4 occurs flag clear.
*/
#define LL_TIMER_IE_CAP4_CLR (1UL << 3)
/*! Capture event 3 occurs flag clear.
*/
#define LL_TIMER_IE_CAP3_CLR (1UL << 2)
/*! Capture event 2 occurs flag clear.
*/
#define LL_TIMER_IE_CAP2_CLR (1UL << 1)
/*! Capture event 1 occurs flag clear.
*/
#define LL_TIMER_IE_CAP1_CLR (1UL << 0)
/***** TIMERx CAP1/PR Register *****/
/*! Capture mode : capture register 1
* Timing mode/PWM mode: Count period register
*/
#define LL_TIMER_CMP1_PR(n) (((n)&0xFFFFFFFF) << 0)
/***** TIMERx CAP2/CMP Register *****/
/*! Capture mode : capture register 2
* Timing mode/PWM mode: compare register
*/
#define LL_TIMER_CMP2_CMP(n) (((n)&0xFFFFFFFF) << 0)
/***** TIMERx CAP3/PR_SD Register *****/
/*! Capture mode : capture register 3
* Timing mode/PWM mode: counting period shadow register
*/
#define LL_TIMER_CMP3_PR_SD(n) (((n)&0xFFFFFFFF) << 0)
/***** TIMERx CAP4/CMP_SD Register *****/
/*! Capture mode : capture register 4
* Timing mode/PWM mode: Compare shadow registers
*/
#define LL_TIMER_CMP4_CMP_SD(n) (((n)&0xFFFFFFFF) << 0)
/***** TIMERx DCCTL Register *****/
/*! Dma mode selection
* 0 : Single mode, after the specified dma length is completed, disable TMR.
* 1 : Loop mode, after the dma length is specified, restart from the start address.
*/
#define LL_TIMER_DMA_LPBK (1UL << 1)
/*! Dma enabled.
*/
#define LL_TIMER_DMA_EN (1UL << 0)
/***** TIMERx DADR Register *****/
/*! Dma starting address.
*/
#define LL_TIMER_DADR_STADR(n) (((n)&0xFFFF) << 0)
/***** TIMERx DLEN Register *****/
/*! Dma buffer length (32bit), if the buffer is n, the configuration is n-1;
*/
#define LL_TIMER_DLEN_LEN(n) (((n)&0xFFFF) << 0)
/***** TIMERx DCNT Register *****/
/*! The number of dma data is valid.
*/
#define LL_TIMER_DCNT_CNT(n) (((n)&0xFFFF) << 0)
/***** TIMER ALLCON Register *****/
/*! The timer sync count value is cleared.
*/
#define LL_TIMER_ALLCON_TMR5_SYNC (1UL << 13)
/*! The timer3 sync count value is cleared.
*/
#define LL_TIMER_ALLCON_TMR3_SYNC (1UL << 11)
/*! The timer2 sync count value is cleared.
*/
#define LL_TIMER_ALLCON_TMR2_SYNC (1UL << 10)
/*! The timer1 sync count value is cleared.
*/
#define LL_TIMER_ALLCON_TMR1_SYNC (1UL << 9)
/*! The timer0 sync count value is cleared.
*/
#define LL_TIMER_ALLCON_TMR0_SYNC (1UL << 8)
/*! Timer5 starts counting.
*/
#define LL_TIMER_ALLCON_TMR5_KICK (1UL << 5)
/*! Timer3 starts counting.
*/
#define LL_TIMER_ALLCON_TMR3_KICK (1UL << 3)
/*! Timer2 starts counting.
*/
#define LL_TIMER_ALLCON_TMR2_KICK (1UL << 2)
/*! Timer1 starts counting.
*/
#define LL_TIMER_ALLCON_TMR1_KICK (1UL << 1)
/*! Timer0 starts counting.
*/
#define LL_TIMER_ALLCON_TMR0_KICK (1UL << 0)
/*! Configure the trigger path for the sync count of TIMER.
*/
#define LL_TIMER_ALLCON_SYNC_COUNT_ALL(n) (((n)&0x3F) << 8)
/*! Configure the synchronous trigger path of TIMER.
*/
#define LL_TIMER_ALLCON_KICK_ALL(n) (((n)&0x3F) << 0)
/**
* @}
*/
/** @defgroup TIMER_Exported_Constants TIMER Exported Constants
* @ingroup TIMER_Driver
* @brief TIMER external constant definition
* @{
*/
/**
* @brief Enumeration constant for low layer TIMER Prescaler for timer
*/
enum hgtimer_psc {
/*! Timer clock source 0 prescaler
*/
HGTIMER_PSC_0 = 0,
/*! Timer clock source 2 prescaler
*/
HGTIMER_PSC_2,
/*! Timer clock source 4 prescaler
*/
HGTIMER_PSC_4,
/*! Timer clock source 8 prescaler
*/
HGTIMER_PSC_8,
/*! Timer clock source 16 prescaler
*/
HGTIMER_PSC_16,
/*! Timer clock source 32 prescaler
*/
HGTIMER_PSC_32,
/*! Timer clock source 64 prescaler
*/
HGTIMER_PSC_64,
/*! Timer clock source 128 prescaler
*/
HGTIMER_PSC_128,
};
/**
* @brief Enumeration constant for low layer TIMER clock source
*/
enum hgtimer_src_sel {
/*! Select the internal high speed RC clock.
*/
HGTIMER_SOURCE_INTER_HIGH_SPEED_RC = 0x1,
/*! Select the internal low speed RC clock.
*/
HGTIMER_SOURCE_INTER_LOW_SPEED_RC,
/*! Select the external crystal and divide by 2.
*/
HGTIMER_SOURCE_EXTER_CRYSTAL_DIV_2,
/*! Select the pin input from the outside and on the rising edge.
*/
HGTIMER_SOURCE_INC_PIN_RISING,
/*! Select the pin input from the outside and on the falling edge.
*/
HGTIMER_SOURCE_INC_PIN_FALLING,
/*! Select the pin input from the outside and on both the rising edge and the falling edge.
*/
HGTIMER_SOURCE_INC_PIN_RISING_FALLING,
/*! Select the system clock.
*/
HGTIMER_SOURCE_SYS_CLK,
};
/**
* @brief Enumeration constant for low layer TIMER the pattern of the timer
*/
enum hgtimer_mode {
/*! Timer mode selection: counter mode
*/
HGTIMER_MODE_COUNTER,
/*! Timer mode selection: PWM mode
*/
HGTIMER_MODE_PWM,
/*! Timer mode selection: capture mode
*/
HGTIMER_MODE_CAPTURE,
};
/**
* @brief Enum constants, Mode selection in slave mode in TIMER.
*/
typedef enum {
/*! Disable.
*/
HGTIMER_SLAVE_MODE_DISABLE = 0,
/*! Select the trigger mode.
*/
HGTIMER_SLAVE_MODE_KICK_START,
/*! Select the reset mode.
*/
HGTIMER_SLAVE_MODE_RESET,
/*! Select the gate mode.
*/
HGTIMER_SLAVE_MODE_GATING,
} TYEP_ENUM_LL_TIMER_SLAVE_MODE;
/**
* @}
*/
int32 hgtimer_attach(uint32 dev_id, struct hgtimer *timer);
#ifdef __cplusplus
}
#endif
#endif /* _HGTIMER_V3_H_ */
+114
View File
@@ -0,0 +1,114 @@
#ifndef _HGTIMER_V4_H
#define _HGTIMER_V4_H
#include "hal/timer_device.h"
#ifdef __cplusplus
extern "C" {
#endif
/*-----timer lower layer: counter mode-----*/
#define HGTIMER_V4_TYPE_ONCE BIT(0)
#define HGTIMER_V4_TYPE_PERIODIC BIT(1)
#define HGTIMER_V4_TYPE_COUNTER BIT(2)
/*----timer lower layer: PWM function cmd----*/
#define HGTIMER_V4_PWM_FUNC_CMD_INIT HGPWM_V0_FUNC_CMD_INIT
#define HGTIMER_V4_PWM_FUNC_CMD_DEINIT HGPWM_V0_FUNC_CMD_DEINIT
#define HGTIMER_V4_PWM_FUNC_CMD_START HGPWM_V0_FUNC_CMD_START
#define HGTIMER_V4_PWM_FUNC_CMD_STOP HGPWM_V0_FUNC_CMD_STOP
/* IOCTL CMD */
#define HGTIMER_V4_PWM_FUNC_CMD_IOCTL_SET_PERIOD_DUTY HGPWM_V0_FUNC_CMD_IOCTL_SET_PERIOD_DUTY
#define HGTIMER_V4_PWM_FUNC_CMD_IOCTL_GET_PERIOD_DUTY HGPWM_V0_FUNC_CMD_IOCTL_GET_PERIOD_DUTY
#define HGTIMER_V4_PWM_FUNC_CMD_IOCTL_SET_PRESCALER HGPWM_V0_FUNC_CMD_IOCTL_SET_PRESCALER
#define HGTIMER_V4_PWM_FUNC_CMD_IOCTL_SET_PERIOD_DUTY_IMMEDIATELY HGPWM_V0_FUNC_CMD_IOCTL_SET_PERIOD_DUTY_IMMEDIATELY
/* IRQ_FLAG */
#define HGTIMER_V4_PWM_FUNC_CMD_REQUEST_IRQ_COMPARE HGPWM_V0_FUNC_CMD_REQUEST_IRQ_COMPARE
#define HGTIMER_V4_PWM_FUNC_CMD_REQUEST_IRQ_PERIOD HGPWM_V0_FUNC_CMD_REQUEST_IRQ_PERIOD
#define HGTIMER_V4_PWM_FUNC_CMD_RELEASE_IRQ HGPWM_V0_FUNC_CMD_RELEASE_IRQ
#define HGTIMER_V4_PWM_FUNC_CMD_SUSPEND HGPWM_V0_FUNC_CMD_SUSPEND
#define HGTIMER_V4_PWM_FUNC_CMD_RESUME HGPWM_V0_FUNC_CMD_RESUME
/*----timer lower layer: cap function cmd----*/
#define HGTIMER_V4_CAPTURE_FUNC_CMD_INIT HGCAPTURE_V0_FUNC_CMD_INIT
#define HGTIMER_V4_CAPTURE_FUNC_CMD_DEINIT HGCAPTURE_V0_FUNC_CMD_DEINIT
#define HGTIMER_V4_CAPTURE_FUNC_CMD_START HGCAPTURE_V0_FUNC_CMD_START
#define HGTIMER_V4_CAPTURE_FUNC_CMD_STOP HGCAPTURE_V0_FUNC_CMD_STOP
/* IOCTL CMD */
/* IRQ_FLAG */
#define HGTIMER_V4_CAPTURE_FUNC_CMD_REQUEST_IRQ_CAPTURE HGCAPTURE_V0_FUNC_CMD_REQUEST_IRQ_CAPTURE
#define HGTIMER_V4_CAPTURE_FUNC_CMD_REQUEST_IRQ_OVERFLOW HGCAPTURE_V0_FUNC_CMD_REQUEST_IRQ_OVERFLOW
#define HGTIMER_V4_CAPTURE_FUNC_CMD_RELEASE_IRQ HGCAPTURE_V0_FUNC_CMD_RELEASE_IRQ
#define HGTIMER_V4_CAPTURE_FUNC_CMD_SUSPEND HGCAPTURE_V0_FUNC_CMD_SUSPEND
#define HGTIMER_V4_CAPTURE_FUNC_CMD_RESUME HGCAPTURE_V0_FUNC_CMD_RESUME
struct hgtimer_v4 {
struct timer_device dev;
uint32 hw;
timer_cb_hdl _counter_irq_hdl;
pwm_irq_hdl _pwm_irq_hdl;
capture_irq_hdl _capture_irq_hdl;
uint32 irq_data;
uint32 irq_num;
uint16 type;
uint16 counter_once_en :1,
counter_period_en:1,
counter_en :1,
pwm_en :1,
cap_en :1,
ir_en :1,
opened :1,
dsleep :1;
#ifdef CONFIG_SLEEP
struct {
uint32 tmr_con;
uint32 tmr_en;
uint32 tmr_ie;
uint32 tmr_cap1;
uint32 tmr_cap2;
uint32 tmr_cap3;
uint32 tmr_cap4;
/* The following registers only for timer1 & timer2 */
uint32 tmr_dctl;
uint32 tmr_dadr;
uint32 tmr_dlen;
uint32 tmr_dcnt;
uint32 tmr_ir_bcnt;
}bp_regs;
uint32 bp_irq_flags;
timer_cb_hdl bp_irq_hdl_timer;
pwm_irq_hdl bp_irq_hdl_pwm;
capture_irq_hdl bp_irq_hdl_capture;
uint32 bp_irq_data_timer;
uint32 bp_irq_data_pwm;
uint32 bp_irq_data_capture;
struct os_mutex bp_suspend_lock;
struct os_mutex bp_resume_lock;
#endif
};
int32 hgtimer_v4_attach(uint32 dev_id, struct hgtimer_v4 *timer);
#ifdef __cplusplus
}
#endif
#endif
+84
View File
@@ -0,0 +1,84 @@
#ifndef _HGTIMER_V5_H
#define _HGTIMER_V5_H
#include "hal/timer_device.h"
#ifdef __cplusplus
extern "C" {
#endif
/*-----timer lower layer: counter mode-----*/
#define HGTIMER_V5_TYPE_ONCE BIT(0)
#define HGTIMER_V5_TYPE_PERIODIC BIT(1)
#define HGTIMER_V5_TYPE_COUNTER BIT(2)
/*----timer lower layer: PWM function cmd----*/
#define HGTIMER_V5_PWM_FUNC_CMD_INIT HGPWM_V0_FUNC_CMD_INIT
#define HGTIMER_V5_PWM_FUNC_CMD_DEINIT HGPWM_V0_FUNC_CMD_DEINIT
#define HGTIMER_V5_PWM_FUNC_CMD_START HGPWM_V0_FUNC_CMD_START
#define HGTIMER_V5_PWM_FUNC_CMD_STOP HGPWM_V0_FUNC_CMD_STOP
/* IOCTL CMD */
#define HGTIMER_V5_PWM_FUNC_CMD_IOCTL_SET_PERIOD_DUTY HGPWM_V0_FUNC_CMD_IOCTL_SET_PERIOD_DUTY
#define HGTIMER_V5_PWM_FUNC_CMD_IOCTL_GET_PERIOD_DUTY HGPWM_V0_FUNC_CMD_IOCTL_GET_PERIOD_DUTY
#define HGTIMER_V5_PWM_FUNC_CMD_IOCTL_SET_SINGLE_INCREAM HGPWM_V0_FUNC_CMD_IOCTL_SET_SINGLE_INCREAM
#define HGTIMER_V5_PWM_FUNC_CMD_IOCTL_SET_INCREAM_DECREASE HGPWM_V0_FUNC_CMD_IOCTL_SET_INCREAM_DECREASE
#define HGTIMER_V5_PWM_FUNC_CMD_IOCTL_SET_PRESCALER HGPWM_V0_FUNC_CMD_IOCTL_SET_PRESCALER
#define HGTIMER_V5_PWM_FUNC_CMD_IOCTL_SET_PERIOD_DUTY_IMMEDIATELY HGPWM_V0_FUNC_CMD_IOCTL_SET_PERIOD_DUTY_IMMEDIATELY
/* IRQ_FLAG */
#define HGTIMER_V5_PWM_FUNC_CMD_REQUEST_IRQ_COMPARE HGPWM_V0_FUNC_CMD_REQUEST_IRQ_COMPARE
#define HGTIMER_V5_PWM_FUNC_CMD_REQUEST_IRQ_PERIOD HGPWM_V0_FUNC_CMD_REQUEST_IRQ_PERIOD
#define HGTIMER_V5_PWM_FUNC_CMD_RELEASE_IRQ HGPWM_V0_FUNC_CMD_RELEASE_IRQ
#define HGTIMER_V5_PWM_FUNC_CMD_SUSPEND HGPWM_V0_FUNC_CMD_SUSPEND
#define HGTIMER_V5_PWM_FUNC_CMD_RESUME HGPWM_V0_FUNC_CMD_RESUME
/*----timer lower layer: cap function cmd----*/
//#define HGTIMER_V5_CAPTURE_FUNC_CMD_INIT BIT(30) | 1
//#define HGTIMER_V5_CAPTURE_FUNC_CMD_DEINIT BIT(30) | 2
//#define HGTIMER_V5_CAPTURE_FUNC_CMD_START BIT(30) | 3
//#define HGTIMER_V5_CAPTURE_FUNC_CMD_STOP BIT(30) | 4
///* IOCTL CMD */
//
///* IRQ_FLAG */
//#define HGTIMER_V5_CAPTURE_FUNC_CMD_REQUEST_IRQ_CAPTURE BIT(30) | 7
//#define HGTIMER_V5_CAPTURE_FUNC_CMD_REQUEST_IRQ_OVERFLOW BIT(30) | 8
//
//#define HGTIMER_V5_CAPTURE_FUNC_CMD_RELEASE_IRQ BIT(30) | 9
struct hgtimer_v5 {
struct timer_device dev;
uint32 hw;
timer_cb_hdl _counter_irq_hdl;
pwm_irq_hdl _pwm_irq_hdl;
//capture_irq_hdl _capture_irq_hdl;
uint32 irq_data;
uint32 irq_num;
uint16 type;
uint16 counter_once_en :1,
counter_period_en:1,
counter_en :1,
pwm_en :1,
cap_en :1,
ir_en :1,
opened :1;
};
int32 hgtimer_v5_attach(uint32 dev_id, struct hgtimer_v5 *timer);
#ifdef __cplusplus
}
#endif
#endif
+82
View File
@@ -0,0 +1,82 @@
#ifndef _HGTIMER_V6_H
#define _HGTIMER_V6_H
#include "hal/timer_device.h"
#ifdef __cplusplus
extern "C" {
#endif
/*-----timer lower layer: counter mode-----*/
#define HGTIMER_V6_TYPE_ONCE BIT(0)
#define HGTIMER_V6_TYPE_PERIODIC BIT(1)
#define HGTIMER_V6_TYPE_COUNTER BIT(2)
/*----timer lower layer: PWM function cmd----*/
#define HGTIMER_V6_PWM_FUNC_CMD_INIT HGPWM_V0_FUNC_CMD_INIT
#define HGTIMER_V6_PWM_FUNC_CMD_DEINIT HGPWM_V0_FUNC_CMD_DEINIT
#define HGTIMER_V6_PWM_FUNC_CMD_START HGPWM_V0_FUNC_CMD_START
#define HGTIMER_V6_PWM_FUNC_CMD_STOP HGPWM_V0_FUNC_CMD_STOP
/* IOCTL CMD */
#define HGTIMER_V6_PWM_FUNC_CMD_IOCTL_SET_PERIOD_DUTY HGPWM_V0_FUNC_CMD_IOCTL_SET_PERIOD_DUTY
#define HGTIMER_V6_PWM_FUNC_CMD_IOCTL_GET_PERIOD_DUTY HGPWM_V0_FUNC_CMD_IOCTL_GET_PERIOD_DUTY
#define HGTIMER_V6_PWM_FUNC_CMD_IOCTL_SET_PRESCALER HGPWM_V0_FUNC_CMD_IOCTL_SET_PRESCALER
#define HGTIMER_V6_PWM_FUNC_CMD_IOCTL_SET_PERIOD_DUTY_IMMEDIATELY HGPWM_V0_FUNC_CMD_IOCTL_SET_PERIOD_DUTY_IMMEDIATELY
/* IRQ_FLAG */
#define HGTIMER_V6_PWM_FUNC_CMD_REQUEST_IRQ_COMPARE HGPWM_V0_FUNC_CMD_REQUEST_IRQ_COMPARE
#define HGTIMER_V6_PWM_FUNC_CMD_REQUEST_IRQ_PERIOD HGPWM_V0_FUNC_CMD_REQUEST_IRQ_PERIOD
#define HGTIMER_V6_PWM_FUNC_CMD_RELEASE_IRQ HGPWM_V0_FUNC_CMD_RELEASE_IRQ
#define HGTIMER_V6_PWM_FUNC_CMD_SUSPEND HGPWM_V0_FUNC_CMD_SUSPEND
#define HGTIMER_V6_PWM_FUNC_CMD_RESUME HGPWM_V0_FUNC_CMD_RESUME
/*----timer lower layer: cap function cmd----*/
//#define HGTIMER_V6_CAPTURE_FUNC_CMD_INIT BIT(30) | 1
//#define HGTIMER_V6_CAPTURE_FUNC_CMD_DEINIT BIT(30) | 2
//#define HGTIMER_V6_CAPTURE_FUNC_CMD_START BIT(30) | 3
//#define HGTIMER_V6_CAPTURE_FUNC_CMD_STOP BIT(30) | 4
///* IOCTL CMD */
//
///* IRQ_FLAG */
//#define HGTIMER_V6_CAPTURE_FUNC_CMD_REQUEST_IRQ_CAPTURE BIT(30) | 7
//#define HGTIMER_V6_CAPTURE_FUNC_CMD_REQUEST_IRQ_OVERFLOW BIT(30) | 8
//
//#define HGTIMER_V6_CAPTURE_FUNC_CMD_RELEASE_IRQ BIT(30) | 9
struct hgtimer_v6 {
struct timer_device dev;
uint32 hw_comm;
uint32 hw_suptmrx;
timer_cb_hdl _counter_irq_hdl;
pwm_irq_hdl _pwm_irq_hdl;
//capture_irq_hdl _capture_irq_hdl;
uint32 irq_data;
uint32 irq_num;
uint16 type;
uint16 counter_once_en :1,
counter_period_en:1,
counter_en :1,
pwm_en :1,
cap_en :1,
ir_en :1,
opened :1;
};
int32 hgtimer_v6_attach(uint32 dev_id, struct hgtimer_v6 *timer);
#ifdef __cplusplus
}
#endif
#endif
+106
View File
@@ -0,0 +1,106 @@
#ifndef _HGTIMER_V7_H
#define _HGTIMER_V7_H
#include "hal/timer_device.h"
#ifdef __cplusplus
extern "C" {
#endif
/*-----timer lower layer: counter mode-----*/
#define HGTIMER_V7_TYPE_ONCE BIT(0)
#define HGTIMER_V7_TYPE_PERIODIC BIT(1)
#define HGTIMER_V7_TYPE_COUNTER BIT(2)
/*----timer lower layer: PWM function cmd----*/
#define HGTIMER_V7_PWM_FUNC_CMD_INIT HGPWM_V0_FUNC_CMD_INIT
#define HGTIMER_V7_PWM_FUNC_CMD_DEINIT HGPWM_V0_FUNC_CMD_DEINIT
#define HGTIMER_V7_PWM_FUNC_CMD_START HGPWM_V0_FUNC_CMD_START
#define HGTIMER_V7_PWM_FUNC_CMD_STOP HGPWM_V0_FUNC_CMD_STOP
/* IOCTL CMD */
#define HGTIMER_V7_PWM_FUNC_CMD_IOCTL_SET_PERIOD_DUTY HGPWM_V0_FUNC_CMD_IOCTL_SET_PERIOD_DUTY
#define HGTIMER_V7_PWM_FUNC_CMD_IOCTL_GET_PERIOD_DUTY HGPWM_V0_FUNC_CMD_IOCTL_GET_PERIOD_DUTY
#define HGTIMER_V7_PWM_FUNC_CMD_IOCTL_SET_PRESCALER HGPWM_V0_FUNC_CMD_IOCTL_SET_PRESCALER
#define HGTIMER_V7_PWM_FUNC_CMD_IOCTL_SET_PERIOD_DUTY_IMMEDIATELY HGPWM_V0_FUNC_CMD_IOCTL_SET_PERIOD_DUTY_IMMEDIATELY
/* IRQ_FLAG */
#define HGTIMER_V7_PWM_FUNC_CMD_REQUEST_IRQ_COMPARE HGPWM_V0_FUNC_CMD_REQUEST_IRQ_COMPARE
#define HGTIMER_V7_PWM_FUNC_CMD_REQUEST_IRQ_PERIOD HGPWM_V0_FUNC_CMD_REQUEST_IRQ_PERIOD
#define HGTIMER_V7_PWM_FUNC_CMD_RELEASE_IRQ HGPWM_V0_FUNC_CMD_RELEASE_IRQ
#define HGTIMER_V7_PWM_FUNC_CMD_SUSPEND HGPWM_V0_FUNC_CMD_SUSPEND
#define HGTIMER_V7_PWM_FUNC_CMD_RESUME HGPWM_V0_FUNC_CMD_RESUME
/*----timer lower layer: cap function cmd----*/
#define HGTIMER_V7_CAPTURE_FUNC_CMD_INIT HGCAPTURE_V0_FUNC_CMD_INIT
#define HGTIMER_V7_CAPTURE_FUNC_CMD_DEINIT HGCAPTURE_V0_FUNC_CMD_DEINIT
#define HGTIMER_V7_CAPTURE_FUNC_CMD_START HGCAPTURE_V0_FUNC_CMD_START
#define HGTIMER_V7_CAPTURE_FUNC_CMD_STOP HGCAPTURE_V0_FUNC_CMD_STOP
/* IOCTL CMD */
/* IRQ_FLAG */
#define HGTIMER_V7_CAPTURE_FUNC_CMD_REQUEST_IRQ_CAPTURE HGCAPTURE_V0_FUNC_CMD_REQUEST_IRQ_CAPTURE
#define HGTIMER_V7_CAPTURE_FUNC_CMD_REQUEST_IRQ_OVERFLOW HGCAPTURE_V0_FUNC_CMD_REQUEST_IRQ_OVERFLOW
#define HGTIMER_V7_CAPTURE_FUNC_CMD_RELEASE_IRQ HGCAPTURE_V0_FUNC_CMD_RELEASE_IRQ
#define HGTIMER_V7_CAPTURE_FUNC_CMD_SUSPEND HGCAPTURE_V0_FUNC_CMD_SUSPEND
#define HGTIMER_V7_CAPTURE_FUNC_CMD_RESUME HGCAPTURE_V0_FUNC_CMD_RESUME
struct hgtimer_v7 {
struct timer_device dev;
uint32 hw;
timer_cb_hdl _counter_irq_hdl;
pwm_irq_hdl _pwm_irq_hdl;
capture_irq_hdl _capture_irq_hdl;
uint32 irq_data;
uint32 irq_num;
uint16 type;
uint16 counter_once_en :1,
counter_period_en:1,
counter_en :1,
pwm_en :1,
cap_en :1,
ir_en :1,
opened :1,
dsleep :1;
#ifdef CONFIG_SLEEP
struct {
uint32 tmr_ctl;
uint32 tmr_cnt;
uint32 tmr_pr;
uint32 tmr_pwm;
}bp_regs;
uint32 bp_irq_flags;
timer_cb_hdl bp_irq_hdl_timer;
pwm_irq_hdl bp_irq_hdl_pwm;
capture_irq_hdl bp_irq_hdl_capture;
uint32 bp_irq_data_timer;
uint32 bp_irq_data_pwm;
uint32 bp_irq_data_capture;
struct os_mutex bp_suspend_lock;
struct os_mutex bp_resume_lock;
#endif
};
int32 hgtimer_v7_attach(uint32 dev_id, struct hgtimer_v7 *timer);
#ifdef __cplusplus
}
#endif
#endif
+99
View File
@@ -0,0 +1,99 @@
#ifndef __HG_TOUCHKEY_H
#define __HG_TOUCHKEY_H
enum tk_ioctl_cmd
{
//硬件寄存器配置
TK_IOCTL_CSRST_SET,
TK_IOCTL_CMPEN_SET,
TK_IOCTL_CMPRB_SET,
TK_IOCTL_RES_SET,
TK_IOCTL_CURR_SET,
TK_IOCTL_ANA_TEN_SET,
TK_IOCTL_VOLT_REF_SET,
TK_IOCTL_PSR_CNT_SET,
TK_IOCTL_PRE_CHARGE_TIME,
TK_IOCTL_PRE_DISCHARGE_TIME,
TK_IOCTL_CONV_TIME,
TK_IOCTL_CHANNLE_MODE,
TK_IOCTL_CHARGE_FRE_DIV,
TK_IOCTL_CHARGE_FRE0_DIV,
TK_IOCTL_CHARGE_FRE1_DIV,
TK_IOCTL_CHARGE_FRE2_DIV,
TK_IOCTL_CHARGE_FRE3_DIV,
TK_IOCTL_SHIELD_SET,
TK_IOCTL_SSC_BW,
TK_IOCTL_SSC_TYPE_SEL,
TK_IOCTL_AUTO_SCAN_EN,
TK_IOCTL_ADDR_SET,
TK_IOCTL_KICK,
//算法参数配置
TK_IOCTL_ADJUST_TIME,
TK_IOCTL_LONG_KEY_TIME,
TK_IOCTL_ADJUST_LINE,
TK_IOCTL_ADJUST_DIFF_VALU,
TK_IOCTL_USE_NUM,
TK_IOCTL_WATER_MODE,
TK_IOCTL_NM_NUM,
TK_IOCTL_NM_LEAVE_CNT,
TK_IOCTL_TP_EN,
TK_IOCTL_NOISE_VALUE,
TK_IOCTL_NM_CM_CNT,
TK_IOCTL_NM_CM_VALUE,
//系统级别的配置(类似信号量,timer等等)
TK_SCAN_SEM_HANDL,
TK_TIMER_HANDL,
};
enum tk_irq_flag
{
TK_SG_CONV_FLAG = BIT(0),
TK_CH_DONE_FLAG = BIT(1),
TK_SCAN_DONE_FLAG = BIT(2),
TK_DMA_FLAG = BIT(3),
TK_DMA_ERR_FLAG = BIT(4),
};
typedef int32 (*tk_irq_hdl)(uint32 irq, uint32 irq_data, uint32 param1, uint32 param2);
struct tk_device {
struct dev_obj dev;
int32(*open)(struct tk_device *tk);
int32(*close)(struct tk_device *tk);
int32(*ioctl)(struct tk_device *tk, uint32 cmd, uint32 param1, uint32 param2);
int32(*request_irq)(struct tk_device *tk, enum tk_irq_flag irq_flag, tk_irq_hdl irq_hdl, uint32 data);
int32(*release_irq)(struct tk_device *tk, enum tk_irq_flag irq_flag);
};
//tk算法私有结构体
struct hgtk_algorithm
{
uint16 __tk_adjust_time;
uint16 __tk_valid_time;
uint16 __tk_adjust_line;
uint16 __tk_adjust_diff_valu;
uint16 __tk_use_num;
uint16 __tk_water_mode;
uint16 __tk_nm_num;
uint16 __tk_nm_leave_cnt;
uint16 __tk_tp_en;
uint16 __tk_noise_value;
uint16 __tk_nm_cm_cnt;
uint16 __tk_nm_cm_value;
};
struct hgtk_device {
struct tk_device dev ;
uint32 hw ;
tk_irq_hdl irq_hdl ;
uint32 irq_data;
uint32 irq_num ;
uint32 opened ;
void* timer;
void* sem;
struct hgtk_algorithm tk_pri;
};
#endif
+123
View File
@@ -0,0 +1,123 @@
#ifndef _HGTOUCHKEY_V2_H
#define _HGTOUCHKEY_V2_H
#include "hal/tk.h"
#include "osal/work.h"
//#include "../driver/tk/hg_touchkey_v2_hw.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef union _u_16 {
uint16 w;
struct {
uint8 h;
uint8 l;
} b;
} TYPE_U16;
typedef union _s_16 {
int16 w;
struct {
uint8 h;
uint8 l;
} b;
} TYPE_S16;
typedef struct _DW {
TYPE_S16 MSW;
TYPE_U16 LSW;
} TYPE_DW;
typedef union _u_32 {
uint32 w;
struct {
uint8 h_32;
uint8 h_24;
uint8 l_16;
uint8 l_8;
} b;
} TYPE_u32;
typedef union _u_32_bit {
uint32 w;
struct {
uint16 count;
uint16 scan_done_pend : 1,
data_normal_flag : 1,
baseline_int_flag :1,
cal_finsh_flag : 1,
adjust_done_peng : 1,
reserved : 11;
} b;
} TYPE_U32_BIT;
typedef enum {
TK_INIT = 0,
ADJUST_DONE,
DATA_INIT_DONE,
SCAN_DONE,
RE_ADJUST_DONE,
} TYPE_ENUM_STA;
typedef struct {
int16 b[3]; // 分子多项式的系数Numerator
int16 a[2]; // 分母多项式的系数Denominator
int16 fixed_point_num; // 移位bit数
} TYPE_BIQUAD_FILTER;
struct hgtk_algor{
uint8 __tk_long_key_flag;
uint8 __tk_ch_inc_flag;
uint8 __tk_mult_confirm_cnt;
uint8 __tk_noise_confirm_cnt;
uint8 __tk_next;
uint8 __tk_cm_cnt;
uint8 __tk_muli_key_cnt;
uint8 __tk_mult_noise_cnt;
int16 __tk_data_temp;
uint16 __tk_ms_cnt;
uint32 __tk_ch_en;
uint32 __tk_key_debug_flag;
uint32 __tk_key_flag;
uint32 __tk_key_flag_temp;
uint32 __tk_key_data;
TYPE_DW MUL_RES_1 ; // 4byte
TYPE_DW MUL_RES_2 ;
TYPE_DW MUL_RES_3 ;
TYPE_u32 UNION_ADDR;
TYPE_BIQUAD_FILTER iir_param;
TYPE_ENUM_STA __tk_run_sta;
TYPE_U32_BIT __tk_flag;
};
struct hgtouchkey_v2 {
struct tk_device dev;
uint32 hw;
uint32 alg;
tk_irq_hdl irq_hdl;
uint32 irq_data;
uint32 irq_num;
uint32 opened:1, dsleep:1, printf_flag:1;
uint32 tk_config;
struct os_work tk_kick_work;
struct os_work tk_scan_work;
struct hgtk_algor tk_algori;
#ifdef CONFIG_SLEEP
uint32 *bp_regs;
uint32 bp_irq_flags;
struct os_mutex bp_suspend_lock;
struct os_mutex bp_resume_lock;
#endif
};
int32 hgtouchkey_v2_attach(uint32 dev_id, struct hgtouchkey_v2 *touchkey);
#ifdef __cplusplus
}
#endif
#endif
@@ -0,0 +1,52 @@
/**
******************************************************************************
* @file tk_simplify_algorithm.h
* @author TAIXIN-IC Application Team
* @version V1.0.0
* @date 01-05-2021
* @brief This file contains all the GPIO LL firmware functions.
******************************************************************************
* @attention
*
* 用户不允许修改
*
*
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __LIB_TK_ALGORITHM_H
#define __LIB_TK_ALGORITHM_H
#ifdef __cplusplus
extern "C" {
#endif
#include "dev/tk/hg_touchkey_v2.h"
/* Includes ------------------------------------------------------------------*/
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
// 用户不允许修改
extern void __tk_lib_init(struct hgtouchkey_v2 *tk);
extern int32 __tk_scan(struct os_work *work);
extern int32 __tk_ms_handler(struct os_work *work);
#define __CPU_NOP() {__NOP(); __NOP(); __NOP(); __NOP();}
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
#ifdef __cplusplus
}
#endif
#endif // __LIB_TK_ALGORITHM_H__
/**
* @}
*/
/**
* @}
*/
/*************************** (C) COPYRIGHT 2021 TAIXIN-IC ***** END OF FILE ****/
+48
View File
@@ -0,0 +1,48 @@
#ifndef _HGUART_V2_H
#define _HGUART_V2_H
#include "hal/uart.h"
#ifdef __cplusplus
extern "C" {
#endif
#define __PSRAM_ADDR_START (0x18800000)
#define __PSRAM_ADDR_END (0x18800000 + (8*1024*1024))
struct hguart_v2 {
struct uart_device dev;
uint32 hw;
uart_irq_hdl irq_hdl;
uint32 irq_data;
uint16 irq_num;
uint16 opened:1, dsleep:1, use_dma:1;
uint32 flag;
#ifdef CONFIG_SLEEP
struct {
uint32 con;
uint32 baud;
uint32 tstadr;
uint32 rstadr;
uint32 tdmalen;
uint32 rdmalen;
uint32 dmacon;
uint32 rs485_con;
uint32 rs485_det;
uint32 rs485_tat;
uint32 tocon;
}bp_regs;
uint32 bp_irq_flags;
uart_irq_hdl bp_irq_hdl;
uint32 bp_irq_data;
#endif
};
int32 hguart_v2_attach(uint32 dev_id, struct hguart_v2 *uart);
#ifdef __cplusplus
}
#endif
#endif
+29
View File
@@ -0,0 +1,29 @@
#ifndef _HGUART_V3_H
#define _HGUART_V3_H
#ifdef __cplusplus
extern "C" {
#endif
/** @brief Simple uart operating handle structure
* @{
*/
struct hguart_v3 {
struct uart_device dev ;
uint32 hw ;
uart_irq_hdl irq_hdl ;
uint32 irq_data;
uint16 irq_num ;
uint16 opened ;
};
int32 hguart_v3_attach(uint32 dev_id, struct hguart_v3 *uart);
#ifdef __cplusplus
}
#endif
#endif
+57
View File
@@ -0,0 +1,57 @@
#ifndef _HGUART_V4_H
#define _HGUART_V4_H
#ifdef __cplusplus
extern "C" {
#endif
/** @brief Simple uart operating handle structure
* @{
*/
struct hguart_v4 {
struct uart_device dev;
uint32 hw;
uart_irq_hdl irq_hdl;
uint32 irq_data;
uint32 tx_total_byte;
uint32 tx_cur_byte;
uint8 *p_tx_buf;
struct os_semaphore sema_tx;
struct os_mutex mutex_tx;
struct os_mutex mutex_rx;
uint16 irq_num;
uint16 comm_irq_num;
uint16 opened :1,
use_dma :1,
irq_dma_tx:1,
irq_dma_rx:1,
debug_uart:1,
rs485_set :1,
dsleep :1;
#ifdef CONFIG_SLEEP
struct {
uint32_t con;
uint32_t baud;
uint32_t tocon;
uint32_t dmaadr;
uint32_t dmalen;
uint32_t dmacon;
}bp_regs;
uint32 bp_irq_flags;
uart_irq_hdl bp_irq_hdl;
uint32 bp_irq_data;
struct os_mutex bp_suspend_lock;
struct os_mutex bp_resume_lock;
#endif
};
int32 hguart_v4_attach(uint32 dev_id, struct hguart_v4 *uart);
#ifdef __cplusplus
}
#endif
#endif
+267
View File
@@ -0,0 +1,267 @@
/*****************************************************************************
* Module : usb
* File : usb.c
* Author :
* Function : USB驱动的一些公用模块
*****************************************************************************/
#ifndef USB_H
#define USB_H
#ifdef __cplusplus
extern "C" {
#endif
//typedef int8 bool;
#define MAX_EP 2 //最大的EP号
//in IC, in latest FPGA
#define USB_FIX_BUG_0 0 //=0, =1
#define USB_FIX_BUG_1 0 //=1, =1
#define USB_FIX_BUG_2 0 //=0, =1
#define USB_FIX_BUG_3 0 //=0, =1
#define USB_FIX_BUG_4 0 //=0, =1
#define UCFG2_CNT 0x2000
//USB SIE REG(common)
#define M_FADDR 0x00
#define M_POWER 0x01
#define M_INTRTX1 0x02
#define M_INTRTX2 0x03
#define M_INTRRX1 0x04
#define M_INTRRX2 0x05
#define M_INTRUSB 0x06
#define M_INTRTX1E 0x07
#define M_INTRTX2E 0x08
#define M_INTRRX1E 0x09
#define M_INTRRX2E 0x0A
#define M_INTRUSBE 0x0B
#define M_FRAMENUM1 0x0C
#define M_FRAMENUM2 0x0D
#define M_INDEX 0x0E
#define M_DEVCTL 0x0F
//USB SIE REG(host & slave)
#define M_TXMAXP 0x10
#define M_CSR0 0x11
#define M_TXCSR1 0x11
#define M_TXCSR2 0x12
#define M_RXMAXP 0x13
#define M_RXCSR1 0x14
#define M_RXCSR2 0x15
#define M_COUNT0 0x16
#define M_RXCOUNT1 0x16
#define M_RXCOUNT2 0x17
#define M_TXTYPE 0x18
#define M_TXINTERVAL 0x19
#define M_RXTYPE 0x1A
#define M_RXINTERVAL 0x1B
#define M_FIFOSIZE 0x1F
#define M_FIFO0 0x20 //FIFOS for endpoint0
#define M_FIFO1 0x24 //FIFOS for endpoint1
#define M_FIFO2 0x28 //FIFOS for endpoint2
/* Interrupt register bit */
#define M_INTR_SUSPEND 0x01
#define M_INTR_RESUME 0x02
#define M_INTR_RESET 0x04
#define M_INTR_SOF 0x08
#define M_INTR_CONNECT 0x10
#define M_INTR_DIS_CONNECT 0x20
#define M_INTR_SESS_REQ 0x40
#define M_INTR_VBUS_ERR 0x80
///USB DMA1_CTL/DMA2_CTL
#define UDC_BUS_ERR (1<<15)
#define UDC_MAXPKT_8BYTE(n) (((n)&0x7F)<<8)
#define UDC_EP(n) (((n)&0xF)<<4)
#define UDC_IE (1<<3)
#define UDC_MODE(n) (((n)&0x1)<<2)
#define UDC_DIR_RX ((0)<<1)
#define UDC_DIR_TX ((1)<<1)
#define UDC_EN ((1)<<0)
///UCFG1
#define DMA4_MASK (1<<22)
#define DMA3_MASK (1<<21)
#define DMA2_MASK (1<<20)
#define DMA1_MASK (1<<19)
#define VBUS_Error_MASK (1<<18)
#define Sess_Req_MASK (1<<17)
#define Discon_MASK (1<<16)
#define Conn_MASK (1<<15)
#define Reset_MASK (1<<14)
#define Resume_MASK (1<<13)
#define Suspend_MASK (1<<12)
#define EP2TX_MASK (1<<11)
#define EP1TX_MASK (1<<10)
#define EP0_MASK (1<<9)
#define EP2RX_MASK (1<<8)
#define EP1RX_MASK (1<<7)
#define SOF_MASK (1<<6)
#define USB_DIF (1<<3)
#define USB_DIM (1<<2)
#define USB_DIP (1<<1)
#define USB_TM1 (1<<0) ///0: normal mode 1:testmode, shorter time for simulation
#define USBIE_EN() //NVIC_EnableIRQ(USB_CTL_IRQn);
#define USBIE_DIS() //NVIC_DisableIRQ(USB_CTL_IRQn);
#define USB_REG_CRITICAL_ENTER() //osMutexWait(usb_reg_lock_id, osWaitForever);
#define USB_REG_CRITICAL_EXIT() //osMutexRelease(usb_reg_lock_id);
//写USB SIE寄存器
#define write_usb_reg(reg_addr, reg_data) do {p_dev->usb_hw->SIE##reg_addr = reg_data;} while(0)
//void write_usb_reg_index(uint8_t index, uint32_t reg_addr, uint8_t reg_data);
#define write_usb_reg_index(index, reg_addr, reg_data)\
do {\
USB_REG_CRITICAL_ENTER();\
p_dev->usb_hw->SIEM_INDEX = index;\
*((volatile uint8_t *)((uint32_t)&p_dev->usb_hw->SIEM_FADDR + reg_addr)) = reg_data;\
USB_REG_CRITICAL_EXIT();\
} while(0)
//读USB SIE寄存器
#define read_usb_reg(reg_addr) (p_dev->usb_hw->SIE##reg_addr)
//uint8_t read_usb_reg_index(uint8_t index, uint32_t reg_addr);
#define read_usb_reg_index(index, reg_addr, reg_data)\
do {\
USB_REG_CRITICAL_ENTER();\
p_dev->usb_hw->SIEM_INDEX = index;\
reg_data = *((volatile uint8_t *)((uint32_t)&p_dev->usb_hw->SIEM_FADDR + reg_addr));\
USB_REG_CRITICAL_EXIT();\
} while(0)
//USB当前状态机
enum {
USB_DEFAULT_STATE,
USB_ADDRESS_STATE,
USB_CONFIG_STATE
};
//EP0状态机
enum {
IDLE_STATE,
TRANSER_OVER_STATE,
TRANSFERING_STATE,
RECEIVING_STATE
};
//接收者
enum {
REQUEST_TO_DEVICE,
REQUEST_TO_INTERFACE,
REQUEST_TO_ENDPOINT
};
//设备描述符
enum {
DEVICE_DESCRIPTOR = 1,
CONFIGURATION_DESCRIPTOR,
STRING_DESCRIPTOR,
INTERFACE_DESCRIPTOR,
ENDPOINT_DESCRIPTOR,
DEVICE_QUALIFIER_DESCRIPTOR,
// OTHER_SPEED_CONFIG_DESCRIPTOR, USB 1.1没有该选项
HID_REPORT = 0x22,
};
//Feature Selector
enum {
ENDPOINT_STALL,
REMOTE_WAKEUP,
TEST_MODE
};
//检测模式
enum {
USB_CHECK_HOST, //尝试主机检测
USB_CHECK_OTG, //尝试OTG检测,是否连接PC
USB_STABLE_HOST, //已成功检测为USB主机
USB_STABLE_DEVICE, //已成功检测为USB设备
};
//返回值
enum {
USB_CONNECTED_NONE, //未连接
USB_CONNECTED_PC, //连接PC,当Device
USB_CONNECTED_DEVICE, //外接U盘,当Host
};
//USB控制结构体
struct hgusb11_dev_ctrl {
uint8_t error; //USB通信错误
struct {
uint16_t vid; //VID
uint16_t pid; //PID
uint16_t ver; //Version
} info;
//EP0接收的命令
struct {
uint8_t rtype;
uint8_t request;
uint16_t value;
uint16_t index;
uint16_t length;
} cmd;
uint8_t reserved[2];
};
struct hgusb11_dev_chk {
uint8_t check_mode;
uint8_t check_cnt;
uint8_t check_delay;
} ;
#define BYTE0(n) ((uint8_t)((uint16_t)(n)))
#define BYTE1(n) ((uint8_t)(((uint16_t)(n))>>8))
#define BYTE2(n) ((uint8_t)(((uint16_t)(((uint32_t)(n))>>8))>>8))
#define BYTE3(n) ((uint8_t)(((uint16_t)(((uint32_t)(n))>>16))>>8))
#define LOAD_U32B(p) ((((volatile uint8_t *)(p))[0]<<24) | (((volatile uint8_t *)(p))[1]<<16) | (((volatile uint8_t *)(p))[2]<<8) | (((volatile uint8_t *)(p))[3]<<0))
#define LOAD_U32L(p) ((((volatile uint8_t *)(p))[0]<<0) | (((volatile uint8_t *)(p))[1]<<8) | (((volatile uint8_t *)(p))[2]<<16)| (((volatile uint8_t *)(p))[3]<<24))
#define LOAD_U16B(p) ((((volatile uint8_t *)(p))[0]<<8) | (((volatile uint8_t *)(p))[1]<<0))
#define LOAD_U16L(p) ((((volatile uint8_t *)(p))[0]<<0) | (((volatile uint8_t *)(p))[1]<<8))
#define SAVE_U32B(p, num) do { \
((volatile uint8_t *)(p))[0] = BYTE3(num); \
((volatile uint8_t *)(p))[1] = BYTE2(num); \
((volatile uint8_t *)(p))[2] = BYTE1(num); \
((volatile uint8_t *)(p))[3] = BYTE0(num); \
} while(0)
#define SAVE_U32L(p, num) do { \
((volatile uint8_t *)(p))[0] = BYTE0(num); \
((volatile uint8_t *)(p))[1] = BYTE1(num); \
((volatile uint8_t *)(p))[2] = BYTE2(num); \
((volatile uint8_t *)(p))[3] = BYTE3(num); \
} while(0)
#define SAVE_U16B(p, num) do { \
((volatile uint8_t *)(p))[0] = BYTE1(num); \
((volatile uint8_t *)(p))[1] = BYTE0(num); \
} while(0)
#define SAVE_U16L(p, num) do { \
((volatile uint8_t *)(p))[0] = BYTE0(num); \
((volatile uint8_t *)(p))[1] = BYTE1(num); \
} while(0)
#ifdef __cplusplus
}
#endif
#endif
+229
View File
@@ -0,0 +1,229 @@
#ifndef USB_DEV_API_H
#define USB_DEV_API_H
/// include & define here
#include "hal/usb_device.h"
#include "dev/usb/hgusb11_base.h"
#include "dev/usb/hgusb11_dev_ep0.h"
#define USB_DEV_DEBUG_ERR_ENABLE 0
#if USB_DEV_DEBUG_ERR_ENABLE
#define USB_DEV_ERR_PRINTF(fmt, args...) os_printf(fmt, ##args)
#else
#define USB_DEV_ERR_PRINTF(fmt, args...)
#endif
#ifdef __cplusplus
extern "C" {
#endif
/// extern declare functions here
enum hgusb11_flags {
HGUSB11_FLAGS_READY,
};
struct hgusb11_hw_dma_st {
__IO uint32_t EP_TXSTARTADR;
__IO uint32_t EP_RXSTARTADR;
__IO uint32_t EP_TXLEN;
__IO uint32_t EP_RXLEN;
} ;
struct hgusb11_hw_dma_end {
__I uint32_t EP_TXADR;
__I uint32_t EP_RXADR;
} ;
/**
* @brief USB2.0
*/
struct hgusb11_dev_hw {
/* SIE common reg : 0x0 ~ 0xf */
__IO uint8_t SIEM_FADDR;
__IO uint8_t SIEM_POWER;
__IO uint8_t SIEM_INTRTX1;
__IO uint8_t SIEM_INTRTX2;
__IO uint8_t SIEM_INTRRX1;
__IO uint8_t SIEM_INTRRX2;
__IO uint8_t SIEM_INTRUSB;
__IO uint8_t SIEM_INTRTX1E;
__IO uint8_t SIEM_INTRTX2E;
__IO uint8_t SIEM_INTRRX1E;
__IO uint8_t SIEM_INTRRX2E;
__IO uint8_t SIEM_INTRUSBE;
__IO uint8_t SIEM_FRAMENUM1;
__IO uint8_t SIEM_FRAMENUM2;
__IO uint8_t SIEM_INDEX;
__IO uint8_t SIEM_DEVCTL;
/* SIE indexed reg : 0x10 ~ 0x1f */
__IO uint8_t SIEM_TXMAXP;
__IO uint8_t SIEM_TXCSR1;
__IO uint8_t SIEM_TXCSR2;
__IO uint8_t SIEM_RXMAXP;
__IO uint8_t SIEM_RXCSR1;
__IO uint8_t SIEM_RXCSR2;
__IO uint8_t SIEM_RXCOUNT1;
__IO uint8_t SIEM_RXCOUNT2;
__IO uint8_t SIEM_TXTYPE;
__IO uint8_t SIEM_TXINTERVAL;
__IO uint8_t SIEM_RXTYPE;
__IO uint8_t SIEM_RXINTERVAL;
uint8_t SIEreserved0[3];
__IO uint8_t SIEM_FIFOSIZE;
/* SIE common reg : 0x20 ~ 0x2f */
__IO uint8_t SIEM_FIFO0;
uint8_t SIEreserved1[3];
__IO uint8_t SIEM_FIFO1;
uint8_t SIEreserved2[3];
__IO uint8_t SIEM_FIFO2;
uint8_t SIEreserved3[3 + 4];
uint8_t rsv0[0x200 - 0x30];
/* DMA common reg */
__IO uint32_t DMA_INT; ///0x200
__IO uint32_t DMA1_CTL;
__IO uint32_t DMA1_ADDR;
__IO uint32_t DMA1_CNT;
uint32_t rsv1;
__IO uint32_t DMA2_CTL;
__IO uint32_t DMA2_ADDR;
__IO uint32_t DMA2_CNT;
uint32_t rsv2;
__IO uint32_t DMA3_CTL;
__IO uint32_t DMA3_ADDR;
__IO uint32_t DMA3_CNT;
uint32_t rsv3;
__IO uint32_t DMA4_CTL;
__IO uint32_t DMA4_ADDR;
__IO uint32_t DMA4_CNT;
uint32_t rsv4[0x100 / 4 - 16];
/* CPU common reg */
__IO uint32_t UCFG0; ///0x300
__IO uint32_t UCFG1;
__IO uint32_t UCFG2;
__IO uint32_t UCFG3;
__IO uint32_t EP_STATUS;
__IO uint32_t EP_KICK;
__IO uint32_t EP_CTL;
uint32_t rsv5;
__IO uint32_t EP0_TXSTARTADR;
__IO uint32_t EP0_RXSTARTADR;
__IO uint32_t EP0_TXLEN;
uint32_t rsv6;
__IO uint32_t EP1_TXSTARTADR;
__IO uint32_t EP1_RXSTARTADR;
__IO uint32_t EP1_TXLEN;
__IO uint32_t EP1_RXLEN;
__IO uint32_t EP2_TXSTARTADR;
__IO uint32_t EP2_RXSTARTADR;
__IO uint32_t EP2_TXLEN;
__IO uint32_t EP2_RXLEN;
__I uint32_t EP0_TXADR;
__I uint32_t EP0_RXADR;
__I uint32_t EP1_TXADR;
__I uint32_t EP1_RXADR;
__I uint32_t EP2_TXADR;
__I uint32_t EP2_RXADR;
} ;
struct hgusb11_dev {
struct usb_device dev;
struct hgusb11_dev_hw *usb_hw;
long flags;
usbdev_irq_hdl irq_hdl;
struct os_mutex tx_lock;
struct os_semaphore tx_done;
uint32 irq_num;
uint32 sof_irq_num;
uint8 *rx_buff;
uint32 rx_len;
uint32 opened;
uint32 irq_data;
struct usb_device_cfg cfg;
struct os_task ep0_task;
struct os_semaphore ep0_sema;
/* basic */
struct hgusb11_dev_chk usb_chk;
struct hgusb11_dev_ctrl usb_ctrl;
struct hgusb11_dev_info usb_dev;
struct hgusb11_audio_ctrl usb_audio_ctl;
uint32_t usb_dma_int;
uint8_t dev_type;
uint8_t usb_exit ;
uint8_t usb_dev_flag ;
uint8_t usb_ep0buf[66];
uint8_t usb_ep0_rxbuf[66];
uint8_t usb_device_descriptor[18];
uint8_t usb_device_qualifier[10];
uint8_t usb_config_all_descriptor[512];
uint16_t usb_vid; /* */
uint16_t usb_pid; /* */
};
/* hgusb11_base */
void hgusb11_switch_otg(struct hgusb11_dev *p_dev);
void hgusb11_switch_host(struct hgusb11_dev *p_dev);
void hgusb11_switch_stable_host(struct hgusb11_dev *p_dev);
void hgusb11_switch_stable_device(struct hgusb11_dev *p_dev);
void hgusb11_switch_stable_otg(struct hgusb11_dev *p_dev);
uint8_t hgusb11_connected(struct hgusb11_dev *p_dev);
uint8_t hgusb11_connected_do(struct hgusb11_dev *p_dev);
void hgusb11_intr_dis(struct hgusb11_dev *p_dev);
void hgusb11_suspend(struct hgusb11_dev *p_dev);
void hgusb11_resume(struct hgusb11_dev *p_dev);
void hgusb11_init_globle(struct hgusb11_dev *p_dev);
void hgusb11_dev_remote_wakeup(struct hgusb11_dev *p_dev);
/* hgusb11_dev_ep0 */
uint8_t hgusb11_dev_init(struct hgusb11_dev *p_dev);
void hgusb11_dev_ep0_func(struct hgusb11_dev *p_dev);
void hgusb11_dev_intr_init_b(struct hgusb11_dev *p_dev);
void hgusb11_dev_exit(struct hgusb11_dev *p_dev);
void hgusb11_dev_reset(struct hgusb11_dev *p_dev);
/* hgusb11_dev_api */
int32 hgusb11_dev_attach(uint32 dev_id, struct hgusb11_dev *p_dev);
void hgusb11_dev_irq(struct hgusb11_dev *p_dev);
bool hgusb11_dev_ep_rx_kick(struct hgusb11_dev *p_dev, uint8_t ep, uint32_t addr, uint32_t len);
bool hgusb11_dev_ep_tx_kick(struct hgusb11_dev *p_dev, uint8_t ep, uint32_t addr, uint32_t len);
void hgusb11_dev_ep_set_rxrdy(struct hgusb11_dev *p_dev, uint8_t ep);
void hgusb11_dev_ep_set_txrdy(struct hgusb11_dev *p_dev, uint8_t ep);
void hgusb11_dev_hw_init(struct hgusb11_dev *p_dev);
uint32_t hgusb11_dev_ep_get_rx_len(struct hgusb11_dev *p_dev, uint8_t ep);
uint32_t hgusb11_dev_ep_get_tx_len(struct hgusb11_dev *p_dev, uint8_t ep);
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* USB_DEV_API_H */
+66
View File
@@ -0,0 +1,66 @@
/*****************************************************************************
* Module : usb
* File : usb_dev.h
* Author :
* Function : USB Device驱动的一些定义
*****************************************************************************/
#ifndef USB_DEV_H
#define USB_DEV_H
#include "typesdef.h"
#ifdef __cplusplus
extern "C" {
#endif
#define USB_REQUEST_DIRECTION (p_dev->usb_ctrl.cmd.rtype & 0x80)
#define USB_REQUEST_TYPE (p_dev->usb_ctrl.cmd.rtype & 0x60)
#define USB_REQUEST_RECIPIENT (p_dev->usb_ctrl.cmd.rtype & 0x1f)
#define USB_REQUEST_ENDPOINT BYTE0(p_dev->usb_ctrl.cmd.index)
#define USB_REQUEST_FEATURE_SELECTOR (p_dev->usb_ctrl.cmd.value)
#define USB_REQUEST_DESCRIPTOR_TYPE BYTE1(p_dev->usb_ctrl.cmd.value)
#define USB_REQUEST_DESCRIPTOR_INDEX BYTE0(p_dev->usb_ctrl.cmd.value)
#define USB_REQUEST_LENGTH (p_dev->usb_ctrl.cmd.length)
struct hgusb11_dev_info {
uint8_t type; //设备类型
uint8_t set_addr; //设地址
uint8_t cfg_value; //Config Value, 用于Set Config与Get Config
uint8_t cur_state; //USB当前状态机
uint8_t ep0_state; //EP0的状态机
uint8_t ep0_pkt; //EP0包大小
uint8_t *ep0_ptr; //当前发送指针
uint16_t ep0_len; //当前发送剩余
uint8_t isoc_tx_interface; //ISOC,MIC发送的接口
uint8_t isoc_tx_enable; //ISOC使能
uint8_t isoc_tx_enable_int; //在中断中配置ISOC使能
volatile uint8_t ep1_tx_stall; //ep1 tx stall标志
volatile uint8_t ep1_rx_stall; //ep1 rx stall标志
volatile uint8_t ep1_pipe_stall; //ep1 Stall的标志
volatile uint8_t ep2_tx_stall; //ep1 tx stall标志
volatile uint8_t ep2_rx_stall; //ep1 rx stall标志
volatile uint8_t ep2_pipe_stall; //ep1 Stall的标志
} ;
struct hgusb11_audio_ctrl {
uint8_t speaker_mute;
uint8_t mic_mute;
uint8_t volume;
/*
uint8_t *adc_root;
uint8_t *adc_end;
uint8_t *adc_ptr;
int16_t adc_cnt;
int16_t adc_total;
int8_t mic_speed;
*/
} ;
#ifdef __cplusplus
}
#endif
#endif
+37
View File
@@ -0,0 +1,37 @@
/*****************************************************************************
* Module : usb
* File : usb_dev_tbl.h
* Author :
* Function : USB驱动的一些常量表的申明
*****************************************************************************/
#ifndef USB_DEV_TBL_H
#define USB_DEV_TBL_H
#ifdef __cplusplus
extern "C" {
#endif
extern const uint8_t tbl_usb_device_descriptor[18];
extern const uint8_t tbl_usb_config_all_descriptor_gen[9];
extern const uint8_t tbl_usb_config_all_descriptor_wifi[23];
extern const uint8_t tbl_usb_config_all_descriptor_mass[23];
extern const uint8_t tbl_usb_config_all_descriptor_audio_ctrl_head[19];
extern const uint8_t tbl_usb_config_all_descriptor_audio_ctrl_speaker[31];
extern const uint8_t tbl_usb_config_all_descriptor_audio_ctrl_mic[30];
extern const uint8_t tbl_usb_config_all_descriptor_speaker_stream[52];
extern const uint8_t tbl_usb_config_all_descriptor_mic_stream[52];
extern const uint8_t tbl_usb_config_all_descriptor_hid[25];
extern const uint8_t tbl_usb_hid_report_descriptor[33];
extern const uint8_t tbl_usb_language_id[4];
extern const uint8_t tbl_usb_str_manufacturer[16];
extern const uint8_t tbl_usb_str_product[28];
extern const uint8_t tbl_usb_str_serial_number[30];
extern const uint8_t tbl_scsi_inquiry_data[36];
#ifdef __cplusplus
}
#endif
#endif
+179
View File
@@ -0,0 +1,179 @@
/*****************************************************************************
* Module : usb
* File : usb.c
* Author :
* Function : USB驱动的一些公用模块
*****************************************************************************/
#ifndef USB20_H
#define USB20_H
#ifdef __cplusplus
extern "C" {
#endif
//typedef int8 bool;
#define USBIE_EN() //NVIC_EnableIRQ(USB_CTL_IRQn);
#define USBIE_DIS() //NVIC_DisableIRQ(USB_CTL_IRQn);
#define USB_REG_CRITICAL_ENTER() int32 ie = disable_irq();
#define USB_REG_CRITICAL_EXIT() enable_irq(ie);
//USB当前状态机
enum {
USB_DEFAULT_STATE,
USB_ADDRESS_STATE,
USB_CONFIG_STATE
};
//EP0状态机
enum {
IDLE_STATE,
TRANSER_OVER_STATE,
TRANSFERING_STATE,
RECEIVING_STATE,
RECEIV_OVER_STATE,
};
//接收者
enum {
REQUEST_TO_DEVICE,
REQUEST_TO_INTERFACE,
REQUEST_TO_ENDPOINT
};
//设备描述符
enum {
DEVICE_DESCRIPTOR = 1,
CONFIGURATION_DESCRIPTOR,
STRING_DESCRIPTOR,
INTERFACE_DESCRIPTOR,
ENDPOINT_DESCRIPTOR,
DEVICE_QUALIFIER_DESCRIPTOR,
// OTHER_SPEED_CONFIG_DESCRIPTOR, USB 1.1没有该选项
INTERFACE_ASSOCIATION_DESCRIPTOR = 11,
HID_REPORT = 0x22,
BOS_DEVICE_DESCRIPTOR = 0xF,
WCID_DEVICE_DESCRIPTOR = 0xEE,
};
//Feature Selector
enum {
ENDPOINT_STALL,
REMOTE_WAKEUP,
TEST_MODE
};
//检测模式
enum {
USB_CHECK_HOST, //尝试主机检测
USB_CHECK_OTG, //尝试OTG检测,是否连接PC
USB_STABLE_HOST, //已成功检测为USB主机
USB_STABLE_DEVICE, //已成功检测为USB设备
};
//返回值
enum {
USB_CONNECTED_NONE, //未连接
USB_CONNECTED_PC, //连接PC,当Device
USB_CONNECTED_DEVICE, //外接U盘,当Host
};
//USB控制结构体
struct hgusb20_dev_ctrl {
//EP0接收的命令
struct {
uint8_t rtype;
uint8_t request;
uint16_t value;
uint16_t index;
uint16_t length;
} cmd;
uint8_t bus_high_speed : 1,
auto_tx_null_pkt : 1, //ep1 tx null packet for non-potocol xfer
reserved_bit0 : 1,
error : 1,
reserved_bit : 4;
uint8_t test_mode;
uint8_t reg_usb_csr0;
uint8_t set_addr;
// struct {
// uint16_t vid; //VID
// uint16_t pid; //PID
// uint16_t ver; //Version
// } info;
};
struct hgusb20_dev_chk {
uint8_t check_mode;
uint8_t check_cnt;
uint8_t check_delay;
} ;
#define BYTE0(n) ((uint8_t)((uint16_t)(n)))
#define BYTE1(n) ((uint8_t)(((uint16_t)(n))>>8))
#define BYTE2(n) ((uint8_t)(((uint16_t)(((uint32_t)(n))>>8))>>8))
#define BYTE3(n) ((uint8_t)(((uint16_t)(((uint32_t)(n))>>16))>>8))
#define LOAD_U32B(p) ((((volatile uint8_t *)(p))[0]<<24) | (((volatile uint8_t *)(p))[1]<<16) | (((volatile uint8_t *)(p))[2]<<8) | (((volatile uint8_t *)(p))[3]<<0))
#define LOAD_U32L(p) ((((volatile uint8_t *)(p))[0]<<0) | (((volatile uint8_t *)(p))[1]<<8) | (((volatile uint8_t *)(p))[2]<<16)| (((volatile uint8_t *)(p))[3]<<24))
#define LOAD_U16B(p) ((((volatile uint8_t *)(p))[0]<<8) | (((volatile uint8_t *)(p))[1]<<0))
#define LOAD_U16L(p) ((((volatile uint8_t *)(p))[0]<<0) | (((volatile uint8_t *)(p))[1]<<8))
#define SAVE_U32B(p, num) do { \
((volatile uint8_t *)(p))[0] = BYTE3(num); \
((volatile uint8_t *)(p))[1] = BYTE2(num); \
((volatile uint8_t *)(p))[2] = BYTE1(num); \
((volatile uint8_t *)(p))[3] = BYTE0(num); \
} while(0)
#define SAVE_U32L(p, num) do { \
((volatile uint8_t *)(p))[0] = BYTE0(num); \
((volatile uint8_t *)(p))[1] = BYTE1(num); \
((volatile uint8_t *)(p))[2] = BYTE2(num); \
((volatile uint8_t *)(p))[3] = BYTE3(num); \
} while(0)
#define SAVE_U16B(p, num) do { \
((volatile uint8_t *)(p))[0] = BYTE1(num); \
((volatile uint8_t *)(p))[1] = BYTE0(num); \
} while(0)
#define SAVE_U16L(p, num) do { \
((volatile uint8_t *)(p))[0] = BYTE0(num); \
((volatile uint8_t *)(p))[1] = BYTE1(num); \
} while(0)
void hgusb20_write_usb_reg_index(uint32_t usb_dev_hw,uint32_t index,uint32_t reg_addr,uint32_t reg_data);
void hgusb20_read_usb_reg_index(uint32_t usb_dev_hw,uint32_t index,uint32_t reg_addr,uint32_t *reg_data);
uint32_t hgusb20_write_usb_reg(uint32_t usb_dev_hw,uint8_t reg_addr,uint8_t reg_data);
uint32_t hgusb20_read_usb_reg(uint32_t usb_dev_hw,uint32_t reg_addr);
void hgusb20_send_empty_packet(uint32_t usb_dev_hw);
#ifdef __cplusplus
}
#endif
#endif
+657
View File
@@ -0,0 +1,657 @@
#ifndef USB20_DEV_API_H
#define USB20_DEV_API_H
/// include & define here
#include "sys_config.h"
#include "hal/usb_device.h"
#include "dev/usb/hgusb20_v1_base.h"
#include "dev/usb/hgusb20_v1_dev_ep0.h"
#include "osal/work.h"
#include "osal/event.h"
#include "lib/common/rbuffer.h"
#define USB_DEV_DEBUG_ERR_ENABLE 0
#if USB_DEV_DEBUG_ERR_ENABLE
#define USB_DEV_ERR_PRINTF(fmt, args...) os_printf(fmt, ##args)
#else
#define USB_DEV_ERR_PRINTF(fmt, args...)
#endif
#ifdef __cplusplus
extern "C" {
#endif
/* speed flags only host */
#define HGUSB20_FLAGS_HIGH_SPEED (0)
#define HGUSB20_FLAGS_FULL_SPEED (30)
#define USBDMA_RX_FLAG_RXING BIT(0)
#define USBDMA_RX_FLAG_OVERFLOW BIT(1)
#define USBDMA_RX_FLAG_FIFOFULL BIT(2)
#define USBDMA_TX_FLAG_TXING BIT(0)
#define USBDMA_TX_FLAG_NULLPACKET BIT(1)
#define USBDMA_TX_FLAG_MODE1 BIT(2)
typedef struct {
uint8 ep0_pkt;
uint8 max_lun;
uint8 bulk_rx;
uint8 bulk_tx;
uint16 time_out;
uint8 stall;
uint8 if_mass;
uint8 res;
uint16 rx_pkt_size;
uint16 tx_pkt_size;
} type_usb_host;
typedef struct {
uint8 offset;
uint8 rx_len;
uint16 rx_total;
} type_ep0_ptr;
struct hgusb20_os_dev {
struct os_task ep0_task __attribute__((aligned(4)));
struct os_task ep0_hub_task __attribute__((aligned(4)));
struct os_task ep0_usb_connect_task __attribute__((aligned(4)));
struct os_semaphore ep0_sema __attribute__((aligned(4)));
struct os_mutex tx_lock __attribute__((aligned(4)));
struct os_semaphore tx_done __attribute__((aligned(4)));
struct os_semaphore hub_sema __attribute__((aligned(4)));
struct os_semaphore hub_finish_sema __attribute__((aligned(4)));
uint32 dev_type; //device mode 1:udisk 2:uvc
};
typedef enum {
UDISK_DEV = 1,
UVC_DEV
}USB_DEV_TYPE;
struct hgusb20_dev {
struct usb_device dev;
void *usb_hw;
struct hgusb20_os_dev *usb_os_msg;
long flags;
usbdev_irq_hdl irq_hdl;
uint8 *rx_buff;
uint32 rx_len;
uint32 irq_data;
struct usb_device_cfg *cfg;
uint8 *p_com_desc; /* usb descriptor */
uint8 *p_config_desc; /* usb descriptor */
uint16 vid; /* usb device VID */
uint16 pid; /* usb device PID */
/* basic */
struct hgusb20_dev_chk usb_chk;
struct hgusb20_dev_ctrl usb_ctrl;
struct hgusb20_dev_info usb_dev;
type_ep0_ptr ep0_ptr;
type_usb_host usb_host;
volatile uint32 usb_dma_int; /* dma intr status reg value */
// volatile uint32 usb_rxdma_addr; /* rx dma start addr */
// volatile uint32 usb_rx_len_limit; /* rx req len */
// volatile uint16_t usb_rxdma_len; /* latest packet len */
volatile uint8 usb_rxdma_flag;
volatile uint8 usb_txdma_flag;
volatile uint16_t usb_tx_total_len; /* */
uint8 ep_irq_num;
uint8 dma_irq_num;
uint16_t usb_dev_flag;
uint8 usb_ep0_sbuf[8] __attribute__((aligned(4)));
/* case : usb continue send 64byte data, 2nd data NAK */
uint8 usb_ep0_rxbuf[68 + 68] __attribute__((aligned(4)));
uint8 usb_ep0_sta[8];
RBUFFER_DEF_R(rb, uint8);
struct os_work ep0_work;
/* trx_lock[00:15] for EP_IN */
/* trx_lock[15:31] for EP_OUT */
struct os_event trx_lock;
struct os_event trx_done;
#ifdef CONFIG_SLEEP
uint32 sys_regs[2];
#endif
};
/* hgusb20_base */
/**
* @brief read usb register
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
* @param ep :
* @param addr : register address offset
* @param data : data return
* @return : TRUE or FLASE
* @note
*/
bool hgusb20_read_reg(struct hgusb20_dev *p_dev, uint8 ep, uint32 addr, uint32 *data);
/**
* @brief write usb register
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
* @param ep :
* @param addr : register address offset
* @param data : data return
* @return : TRUE or FLASE
* @note
*/
bool hgusb20_write_reg(struct hgusb20_dev *p_dev, uint8 ep, uint32 addr, uint32 data);
void hgusb20_switch_otg(struct hgusb20_dev *p_dev);
void hgusb20_switch_host(struct hgusb20_dev *p_dev);
void hgusb20_switch_stable_host(struct hgusb20_dev *p_dev);
void hgusb20_switch_stable_device(struct hgusb20_dev *p_dev);
void hgusb20_switch_stable_otg(struct hgusb20_dev *p_dev);
void hgusb20_intr_dis(struct hgusb20_dev *p_dev);
uint8_t hgusb20_connected(struct hgusb20_dev * p_dev);
uint32 hgusb20_get_rx_crc_error_cnt(struct hgusb20_dev *p_dev);
/**
* @brief usb ep rx data kick
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
* @param ep : [1,2]
* @param addr : data address
* @param len : data length
* @return : TRUE or FLASE
* @note use for host & device
*/
bool hgusb20_ep_rx_kick(struct hgusb20_dev *p_dev, uint8 ep, uint32 addr, uint32 len);
/**
* @brief usb ep tx data kick
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
* @param ep : [1,2]
* @param addr : data address
* @param len : data length
* @return : TRUE or FLASE
* @note use for host & device
*/
bool hgusb20_ep_tx_kick(struct hgusb20_dev *p_dev, uint8 ep, uint32 addr, uint32 len);
bool hgusb20_ep_rx_abort(struct hgusb20_dev *p_dev, uint8 ep);
bool hgusb20_ep_tx_abort(struct hgusb20_dev *p_dev, uint8 ep);
/**
* @brief usb ep get rx data length from dma
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
* @param ep : [1,2]
* @return : rx data length
* @note use for host & device
*/
uint32 hgusb20_ep_get_dma_rx_len(struct hgusb20_dev *p_dev, uint8 ep);
/**
* @brief usb ep get rx data length from sie
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
* @param ep : [1,2]
* @return : rx data length
* @note use for host & device
*/
uint32 hgusb20_ep_get_sie_rx_len(struct hgusb20_dev *p_dev, uint8 ep);
/**
* @brief usb ep get tx data length
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
* @param ep : [1,2]
* @return : tx data length (same with len in hgusb20_ep_tx_kick)
* @note use for host & device
*/
uint32 hgusb20_ep_get_tx_len(struct hgusb20_dev *p_dev, uint8 ep);
/**
* @brief check if usb device online
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
* @return
* - TRUE : online.
* - FALSE : not online.
* @note : For USB Host
*/
bool hgusb20_is_device_online(struct hgusb20_dev *p_dev);
/**
* @brief check if usb host online
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
* @return
* - TRUE : online.
* - FALSE : not online.
* @note : For USB Device
*/
bool hgusb20_is_host_online(struct hgusb20_dev *p_dev);
int32 hgusb20_is_host_mode(struct hgusb20_dev *p_dev);
/**
* @brief suspend usb device .
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
* @return :
* @note : For USB Host
*/
void hgusb20_host_suspend(struct hgusb20_dev *p_dev);
/**
* @brief resume usb device .
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
* @return :
* @note : For USB Host
*/
void hgusb20_host_resume(struct hgusb20_dev *p_dev);
/**
* @brief usb host set address(host address)
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
* @param addr :
* @return
* @note use after usb_host_set_address(device address) cmd
*/
void hgusb20_set_address(struct hgusb20_dev *p_dev, uint8 addr);
/**
* @brief usb host bus reset request
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
* @return
* @note
*/
uint8 hgusb20_host_reset(struct hgusb20_dev *p_dev);
/**
* @brief remote_wakeup usb host .
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
* @return :
* @note : For USB Device
*/
void hgusb20_dev_remote_wakeup(struct hgusb20_dev *p_dev);
/* hgusb20_dev_api */
/**
* @brief attach usb device
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
* @param dev_id :
* @return : err_code
* @note
*/
int32 hgusb20_dev_attach(uint32 dev_id, struct hgusb20_dev *p_dev);
/**
* @brief init usb to device mode .
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
* @return
* - RET_OK : Successfully.
* - RET_ERR : Failed.
* @note
*/
uint8 hgusb20_dev_init(struct hgusb20_dev *p_dev);
/**
* @brief exit usb to device mode .
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
* @return
* - RET_OK : Successfully.
* - RET_ERR : Failed.
* @note
*/
void hgusb20_dev_exit(struct hgusb20_dev *p_dev);
/**
* @brief usb device ep0 tx data stage handle:
* addr = p_dev->ep0_ptr; len = p_dev->ep0_len;
* 1、if buf is not NULL(first packet), update p_dev->ep0_ptr & p_dev->ep0_len
* 2、TX one packet
* 3、data end if len != ep0_pkt
* 4、auto called repeat when last tx data done while (p_dev->usb_dev.ep0_state == TRANSER_OVER_STATE)
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
* @param buf : valid when first packet, set NULL when other packet
* @param len : valid when first packet, set 0 when other packet.
* @return
* - RET_OK : Successfully.
* - RET_ERR : Failed.
* @note : weak function, Users can use a strong statement function replace the weak statement function.
*/
bool hgusb20_dev_ep0_tx(struct hgusb20_dev *p_dev, void *buf, uint16_t len);
/**
* @brief usb device ep0 tx one packet only
*/
bool hgusb20_dev_ep0_tx_rtt(struct hgusb20_dev *p_dev, void *buf, uint16_t len);
bool hgusb20_dev_ep0_tx_abort(struct hgusb20_dev *p_dev);
/**
* @brief usb ep rx data stage handle
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
* @param ep : [1,2]
* @param addr : data address
* @param len : data length
* @return : TRUE or FLASE
* @note use for host & device
*/
bool hgusb20_dev_ep0_rx(struct hgusb20_dev *p_dev, void *buf, uint16_t len);
/**
* @brief usb device ep0 rx one packet only
*/
bool hgusb20_dev_ep0_rx_rtt(struct hgusb20_dev *p_dev, void *buf, uint16_t len);
bool hgusb20_dev_ep0_rx_abort(struct hgusb20_dev *p_dev);
/**
* @brief usb device clear_stall_flag
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
* @return
* @note
*/
void hgusb20_dev_clear_stall_flag(struct hgusb20_dev *p_dev);
/**
* @brief usb device tx zero-packet & rx packet to usb_ep0_rxbuf
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
* @return
* @note
*/
bool hgusb20_dev_ep0_clrrx_pkt0(struct hgusb20_dev *p_dev);
/**
* @brief usb device bus reset
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
* @return
* @note
*/
void hgusb20_dev_reset(struct hgusb20_dev *p_dev);
/**
* @brief usb device stall_ep
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
* @param epnum : epnum, set BIT(7) when tx endpiont.
* @return
* @note
*/
void hgusb20_dev_stall_ep(struct hgusb20_dev *p_dev, uint8 epnum);
/**
* @brief usb device clear stall_ep
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
* @param epnum : epnum, set BIT(7) when tx endpiont.
* @return
* @note
*/
void hgusb20_dev_clear_ep(struct hgusb20_dev *p_dev, uint8 epnum);
/**
* @brief usb device ep reset all endpiont in ep_cfg
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
* @return
* @note
*/
void hgusb20_dev_bot_reset(struct hgusb20_dev *p_dev);
/**
* @brief usb device cmd handle :get descriptor
* 1、kick next rx to p_dev->usb_ep0_rxbuf
* 2、tx data(addr = buf, length = len)
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
* @return : TRUE or FLASE
* @note
*/
bool hgusb20_dev_ep0_descriptor(struct hgusb20_dev *p_dev, void *buf, uint16_t len);
/**
* @brief usb device standard cmd handle
* 1、
* 2、handle DATA(IN or OUT)
* 3、STATUS(zero-len packet)
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
* @return
* @note : weak function, Users can use a strong statement function replace the weak statement function.
* these function is called by func "hgusb20_dev_ep0_standard"
*/
uint8 hgusb20_dev_cfg_desc_prepare(struct hgusb20_dev *p_dev);
__weak bool hgusb20_dev_ep0_get_descriptor(struct hgusb20_dev *p_dev);
__weak bool hgusb20_dev_ep0_get_configuration(struct hgusb20_dev *p_dev);
__weak bool hgusb20_dev_ep0_set_configuration(struct hgusb20_dev *p_dev);
__weak bool hgusb20_dev_ep0_get_interface(struct hgusb20_dev *p_dev);
__weak bool hgusb20_dev_ep0_set_interface(struct hgusb20_dev *p_dev);
__weak bool hgusb20_dev_ep0_set_address(struct hgusb20_dev *p_dev, uint8_t address);
__weak bool hgusb20_dev_ep0_get_status(struct hgusb20_dev *p_dev);
__weak bool hgusb20_dev_ep0_clr_feature(struct hgusb20_dev *p_dev);
__weak bool hgusb20_dev_ep0_set_feature(struct hgusb20_dev *p_dev);
/**
* @brief usb device ep0 setup handle (standard cmd)
* 1、
* 2、handle DATA(IN or OUT)
* 3、STATUS(zero-len packet)
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
* @return : TRUE or FLASE
* @note : weak function, Users can use a strong statement function replace the weak statement function.
* the function is called by func "hgusb20_dev_ep0_request"
*/
__weak bool hgusb20_dev_ep0_standard(struct hgusb20_dev *p_dev);
//__weak bool hgusb20_dev_ep0_class_reset(struct hgusb20_dev *p_dev);
//__weak bool hgusb20_dev_ep0_class_get_lun(struct hgusb20_dev *p_dev);
//__weak bool hgusb20_dev_ep0_audio_sample_ctrl(struct hgusb20_dev *p_dev);
//__weak bool hgusb20_dev_ep0_audio_mute_ctrl(struct hgusb20_dev *p_dev);
//__weak bool hgusb20_dev_ep0_audio_volume_ctrl(struct hgusb20_dev *p_dev);
/**
* @brief usb device ep0 setup handle (class cmd)
* 1、
* 2、handle DATA(IN or OUT)
* 3、STATUS(zero-len packet)
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
* @return : TRUE or FLASE
* @note : weak function, Users can use a strong statement function replace the weak statement function.
* the function is called by func "hgusb20_dev_ep0_request"
*/
__weak bool hgusb20_dev_ep0_class(struct hgusb20_dev *p_dev);
/**
* @brief usb device ep0 setup handle (vendor cmd)
* 1、
* 2、handle DATA(IN or OUT)
* 3、STATUS(zero-len packet)
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
* @return : TRUE or FLASE
* @note : weak function, Users can use a strong statement function replace the weak statement function.
* the function is called by func "hgusb20_dev_ep0_request"
*/
__weak bool hgusb20_vendor_cmd(struct hgusb20_dev *p_dev);
/**
* @brief usb device ep0 setup handle
* 1、
* 2、handle DATA(IN or OUT)
* 3、STATUS(zero-len packet)
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
* @return : TRUE or FLASE
* @note : weak function, Users can use a strong statement function replace the weak statement function.
*
*/
__weak bool hgusb20_dev_ep0_request(struct hgusb20_dev *p_dev);
/**
* @brief usb device config state indication
* 1、 p_dev->usb_dev.cur_state = USB_CONFIG_STATE;
* 2、p_dev->flags |= BIT(HGUSB20_FLAGS_READY);
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
* @return :
* @note : weak function, Users can use a strong statement function replace the weak statement function.
*
*/
__weak void hgusb20_dev_state_config(struct hgusb20_dev *p_dev);
///**
// * @brief usb device ep0 interrupt handle
// * @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
// * @return
// * @note : weak function, Users can use a strong statement function replace the weak statement function.
// * !! Don't recommend a strong statement function
// */
//__weak void hgusb20_dev_ep0_func(struct hgusb20_dev *p_dev);
/**
* @brief usb device endpoint init & deinit
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
* @param ep_addr : ep->ep_desc->bEndpointAddress
* @param max_pkt_size :ep->ep_desc->wMaxPacketSize
* @param attributes : ep->ep_desc->bmAttributes.
* @return :
* @note : weak function, Users can use a strong statement function replace the weak statement function.
*/
void hgusb20_dev_ep_init(struct hgusb20_dev *p_dev, uint8 ep_addr, uint16 max_pkt_size, uint8 attributes);
void hgusb20_dev_ep_deinit(struct hgusb20_dev *p_dev, uint8 ep_addr);
/**
* @brief usb device IN data kick ( tx data )
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
* @param ep : ep_num = ep->ep_desc->bEndpointAddress & 0x7F
* @param buff : word aligned
* @param len :
* @param sync : 1: sync(recommand) 0: async
* @return : error code
* @note : weak function, Users can use a strong statement function replace the weak statement function.
*/
int32 hgusb20_dev_write(struct usb_device *usb, uint8 ep, uint8 *buff, uint32 len, uint8 sync);
int32 hgusb20_dev_read(struct usb_device *p_usb_d, uint8 ep, uint8 *buff, uint32 len, uint8 sync);
int32 hgusb20_dev_close(struct usb_device *p_usb_d);
/* hgusb20_host_api */
/**
* @brief attach usb host
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
* @param dev_id :
* @return : err_code
* @note
*/
int32 hgusb20_host_attach(uint32 dev_id, struct hgusb20_dev *p_dev);
/**
* @brief init usb to host mode .
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
* @return
* - RET_OK : Successfully.
* - RET_ERR : Failed.
* @note
*/
bool hgusb20_host_init(struct hgusb20_dev *p_dev);
/**
* @brief usb host ep0 cmd request
* 1. SETUP: send setup packet , addr = p_dev->usb_ctrl.cmd, len = 8
* 2. DATA : addr = p_buf, len = p_dev->usb_ctrl.cmd.length for rx/tx(p_dev->usb_ctrl.cmd.rtype & USB_DIR_IN)
3. STA : if DATA tx null packet else rx null packet
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
* @param p_buf : data buffer.
* @return : TRUE or FLASE
* @note Another choice user can realize function by calling "hgusb20_host_ep0_setup" & "hgusb20_host_ep0_rx" & "hgusb20_host_ep0_tx"
*/
bool usb_host_ep0_request(struct hgusb20_dev *p_dev, uint8 *pBuf);
/**
* @brief usb host ep0 send SETUP packet
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
* @return
* @note
*/
uint32_t hgusb20_host_ep0_setup(struct hgusb20_dev *p_dev);
/**
* @brief usb host ep0 send IN packet & request a data packet
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
* @return
* @note addr = p_dev->usb_ep0_buf, len = p_dev->ep0_ptr.rx_len
*/
uint32_t hgusb20_host_ep0_rx(struct hgusb20_dev *p_dev, uint8 *pBuf, bool first_pkt);
/**
* @brief usb host ep0 send IN packet & request a data packet
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
* @param len :
* @return
* @note addr = p_dev->usb_ep0_buf, len = p_dev->ep0_ptr.rx_len
*/
uint32_t hgusb20_host_ep0_tx(struct hgusb20_dev *p_dev, uint8 *pBuf, uint8 len);
/**
* @brief usb host endpiont init
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
* @param ep_host : ep pipe of host
* @param ep_dev : ep pipe of device
* @param ep_type : USB_ENDPOINT_XFERTYPE_MASK @ref usb_ch9.h
* @param max_pkt_size :
* @return
* @note
*/
void hgusb20_host_tx_ep_init(struct hgusb20_dev *p_dev, uint8 ep_host, uint8 ep_dev, uint8 ep_type, uint16 max_pkt_size);
void hgusb20_host_rx_ep_init(struct hgusb20_dev *p_dev, uint8 ep_host, uint8 ep_dev, uint8 ep_type, uint16 max_pkt_size);
/**
* @brief hgusb20_host_clear_data_toggle
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
* @param ep_num : [1,2]
* @param ep_type : EndpointDir BIT[7]:IN = 1, OUT = 0
* @return :
* @note
*/
void hgusb20_host_clear_data_toggle(struct hgusb20_dev *p_dev, uint8 ep_num, uint8 ep_type);
/**
* @brief hgusb20_host_flush_fifo
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
* @param ep_num : [1,2]
* @param ep_type : EndpointDir BIT[7]:IN = 1, OUT = 0
* @return :
* @note
*/
void hgusb20_host_flush_fifo(struct hgusb20_dev *p_dev, uint8 ep_num, uint8 ep_type);
/**
* @brief usb host get stall status
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
* @param ep_num : [0,2]
* @param ep_type : EndpointDir BIT[7]:IN = 1, OUT = 0
* @return : TRUE or FLASE
* @note
*/
bool hgusb20_host_is_rx_stall(struct hgusb20_dev *p_dev, uint8 ep_num, uint8 ep_type);
/**
* @brief usb host get xact error status (continous no response three times)
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
* @param ep_num : [0,2]
* @param ep_type : EndpointDir BIT[7]:IN = 1, OUT = 0
* @return : TRUE or FLASE
* @note
*/
bool hgusb20_host_is_xact_err(struct hgusb20_dev *p_dev, uint8 ep_num, uint8 ep_type);
/**
* @brief usb host get nak timeout status
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
* @param ep_num : [0,2]
* @param ep_type : EndpointDir BIT[7]:IN = 1, OUT = 0
* @return : TRUE or FLASE
* @note
*/
bool hgusb20_host_is_nak_timeout(struct hgusb20_dev *p_dev, uint8 ep_num, uint8 ep_type);
/**
* @brief usb host get rx crc status
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
* @param ep_num : [0,2]
* @return : TRUE or FLASE
* @note
*/
bool hgusb20_host_is_crc_err(struct hgusb20_dev *p_dev, uint8 ep_num);
void hgusb20_host_reset_phy(struct hgusb20_dev * p_dev);
int32 hgusb20_host_set_interval(struct hgusb20_dev *p_dev, uint8_t ep_host, uint8_t mode, uint32_t interval);
void hgusb20_host_reset_ep_rxcsr(struct hgusb20_dev *p_dev, uint8 ep_num);
void hgusb20_host_reset_ep_txcsr(struct hgusb20_dev *p_dev, uint8 ep_num);
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* USB_DEV_API_H */
+69
View File
@@ -0,0 +1,69 @@
/*****************************************************************************
* Module : usb
* File : usb_dev.h
* Author :
* Function : USB Device驱动的一些定义
*****************************************************************************/
#ifndef USB20_DEV_H
#define USB20_DEV_H
#include "typesdef.h"
#ifdef __cplusplus
extern "C" {
#endif
#define USB_REQUEST_DIRECTION (p_dev->usb_ctrl.cmd.rtype & 0x80)
#define USB_REQUEST_TYPE (p_dev->usb_ctrl.cmd.rtype & 0x60)
#define USB_REQUEST_RECIPIENT (p_dev->usb_ctrl.cmd.rtype & 0x1f)
#define USB_REQUEST_ENDPOINT BYTE0(p_dev->usb_ctrl.cmd.index)
#define USB_REQUEST_TEST_INDEX BYTE1(p_dev->usb_ctrl.cmd.index)
#define USB_REQUEST_FEATURE_SELECTOR (p_dev->usb_ctrl.cmd.value)
#define USB_REQUEST_DESCRIPTOR_TYPE BYTE1(p_dev->usb_ctrl.cmd.value)
#define USB_REQUEST_DESCRIPTOR_INDEX BYTE0(p_dev->usb_ctrl.cmd.value)
#define USB_REQUEST_LENGTH (p_dev->usb_ctrl.cmd.length)
struct hgusb20_dev_info {
//uint8_t type; //设备类型
//uint8_t set_addr; //设地址
//uint8_t cfg_value; //Config Value, 用于Set Config与Get Config
uint8_t cur_state : 4, //USB当前状态机
ep0_state : 4; //EP0的状态机
uint8_t ep0_pkt; //EP0包大小
uint8_t *ep0_ptr; //当前发送指针
uint16_t ep0_len; //当前发送剩余
uint8_t *ep0_ptr_rx; //当前发送指针
uint16_t ep0_len_rx; //当前发送剩余
volatile uint8_t ep_tx_stall; //ep1 tx stall标志
volatile uint8_t ep_rx_stall; //ep1 rx stall标志
// uint8_t ep_num_rx;
// uint8_t ep_num_tx;
// uint8_t ep_rx_type;
// uint8_t ep_tx_type;
// uint16_t max_pkt_rx[MAX_EP];
// uint16_t max_pkt_tx[MAX_EP];
} ;
struct hgusb20_audio_ctrl {
uint8_t speaker_mute;
uint8_t mic_mute;
uint8_t volume;
/*
uint8_t *adc_root;
uint8_t *adc_end;
uint8_t *adc_ptr;
int16_t adc_cnt;
int16_t adc_total;
int8_t mic_speed;
*/
} ;
#ifdef __cplusplus
}
#endif
#endif
+51
View File
@@ -0,0 +1,51 @@
/*****************************************************************************
* Module : usb
* File : usb_dev_tbl.h
* Author :
* Function : USB驱动的一些常量表的申明
*****************************************************************************/
#ifndef USB_DEV_TBL_H
#define USB_DEV_TBL_H
#define WCID_VENDOR_CODE 0xA0
#ifdef __cplusplus
extern "C" {
#endif
extern const uint8_t tbl_usb_device_descriptor[18];
extern const uint8_t tbl_usb_config_all_descriptor_gen[9];
extern const uint8_t tbl_usb_config_all_descriptor_wifi[23];
extern const uint8_t tbl_usb_config_all_descriptor_mass[23];
extern const uint8_t tbl_usb_config_all_descriptor_audio_ctrl_head[19];
extern const uint8_t tbl_usb_config_all_descriptor_audio_ctrl_speaker[31];
extern const uint8_t tbl_usb_config_all_descriptor_audio_ctrl_mic[30];
extern const uint8_t tbl_usb_config_all_descriptor_speaker_stream[52];
extern const uint8_t tbl_usb_config_all_descriptor_mic_stream[52];
extern const uint8_t tbl_usb_config_all_descriptor_hid[25];
extern const uint8_t tbl_usb_hid_report_descriptor[33];
extern const uint8_t tbl_usb_language_id[4];
extern const uint8_t tbl_usb_str_manufacturer[16];
extern const uint8_t tbl_usb_str_product[28];
extern const uint8_t tbl_usb_str_serial_number[30];
extern const uint8_t tbl_scsi_inquiry_data[36];
/* bcdUSB = 2.0 */
extern const uint8_t tbl_winusb_device_descriptor[18];
extern const uint8_t tbl_winusb_compatible_id_feature_descriptor[40];
extern const uint8_t tbl_winncm_compatible_id_feature_descriptor[40];
extern const uint8_t tbl_rndis_compatible_id_feature_descriptor[40];
extern const uint8_t tbl_winusb_device_interface_guids[142];
extern const uint8_t tbl_net_device_interface_guids[142];
extern const uint8_t tbl_winncm_class_request_get_ntb_params[28];
extern const uint8_t tbl_winusb20_wcid_descriptor_set[162];
/* bcdUSB >= 2.01 , best 2.1 */
extern const uint8_t tbl_winusb20_wcidbos[33];
#ifdef __cplusplus
}
#endif
#endif
+619
View File
@@ -0,0 +1,619 @@
#ifndef _UVC_HOST_H
#define _UVC_HOST_H
#include "typesdef.h"
#include "list.h"
typedef enum
{
UVC_DESCRIPTOR_UNDEFINED=0,
UVC_HEADER,
UVC_INPUT_TERMINAL,
UVC_OUTPUT_TERMINAL,
UVC_SELECTOR_UNIT,
UVC_PROCESSING_UNIT,
UVC_EXTENSION_UNIT,
UVC_ENCODING_UNIT
}VC_Subtype;
typedef enum
{
VS_UNDEFINED=0,
VS_INPUT_HEADER,
VS_OUTPUT_HEADER,
VS_STILL_IMAGE_FRAME,
VS_FORMAT_UNCOMPRESSED,
VS_FRAME_UNCOMPRESSED,
VS_FORMAT_MJPEG,
VS_FRAME_MJPEG,
Reserved,
Reserved1,
VS_FORMAT_MPEG2TS,
Reserved2,
VS_FORMAT_DV,
VS_COLORFORMAT,
Reserved3,
Reserved4,
VS_FORMAT_FRAME_BASED,
VS_FRAME_FRAME_BASED,
VS_FORMAT_STREAM_BASED,
VS_FORMAT_H264,
VS_FRAME_H264,
VS_FORMAT_H264_SIMULCAST
}VS_Subtype;
// Standard Configuration Descriptor
typedef struct
{
uint8 length; // Size of descriptor in uint8
uint8 type; // Configuration
uint16 t_length; // Total length
uint8 num_intf; // Number of interface
uint8 cv; // bConfigurationValue
uint8 index; // iConfiguration
uint8 attr; // Configuration Characteristic
uint8 max_power; // Power config
} SCFG_DESC, *P_SCFG_DESC;
// Standard Interface Descriptor
typedef struct
{
uint8 length;
uint8 type;
uint8 num;
uint8 alt_tring;
uint8 end_points;
uint8 iclass;
uint8 sub;
uint8 proto;
uint8 index;
} SINTF_DESC, *P_INTF_DESC;
// Standard Device Descriptor
typedef struct
{
uint8 length;
uint8 descriptor_type;
uint16 bcd_usb;
uint8 device_class;
uint8 device_subclass;
uint8 device_protocol;
uint8 maxpacket_size0;
uint16 id_vendor;
uint16 id_product;
uint16 bcd_device;
uint8 manufacturer;
uint8 product;
uint8 serial_number;
uint8 num_configurations;
} SDEV_DESC, *P_DEV_DESC;
// Standard EndPoint Descriptor
typedef struct
{
uint8 length;
uint8 type;
uint8 ep_addr;
uint8 attr;
uint16 pay_load; // low-speed this must be 0x08
uint8 interval;
} SEP_DESC, *P_EP_DESC;
struct VC_PROCESS{
uint8 bLength;
uint8 bDescriptorType;
uint8 bDescriptorSubtype;
uint8 bUnitID;
uint8 bSourceID;
uint16 wMaxMultiplier;
uint8 bControlSize;
uint32 bmControls;
uint8 iProcessing;
}__attribute__((packed));
typedef struct{
uint8 bLength;
uint8 bDescriptorType;
uint8 bDescriptorSubtype;
uint8 bFrameIndex;
uint8 bmCapabilities;
uint16 wWidth;
uint16 wHeight;
}VS_FRAME;
typedef struct{
uint8 bLength;
uint8 bDescriptorType;
uint8 bDescriptorSubtype;
uint8 bFrameIndex;
uint8 bNumFrameDescriptors;
}VS_FORMAT;
typedef struct{
uint8 bLength;
uint8 bDescriptorType;
uint8 bDescriptorSubtype;
uint8 bNumFormats;
}VS_HEAD;
#define INTERFACE_Type 0x24
#define STRAME_O_CONTORL 0x04
#define ENDPOINT_DESC 0x05
#define VS_FAME_TYPE_MAXNUM 20
#define VS_FORMAT_TYPE_MAXNUM 2
#define __INTFS_STACK__ 32
#define IS_UVC_JPEG 1
#define USB_DEV_UVC_CLASS 0xef
#define USB_DEV_HUB_CLASS 0X09
#define UVC_SET_REQ 0x21
#define UVC_GET_REQ 0xA1
#define UVC_SET_CUR 0x01
#define UVC_GET_CUR 0x81
#define UVC_GET_MIN 0x82
#define UVC_GET_MAX 0x83
#define UVC_GET_RES 0x84
#define UVC_GET_LEN 0x85
#define UVC_GET_INFO 0x86
#define UVC_GET_DEF 0x87
#define UVC_CLASS 0x0e
#define UAC_CLASS 0x01
#define UVC_VGA 1
#define UVC_720P 2
typedef struct{
uint8 DesLen;
uint8 DescriptorType;
uint8 Subtype;
uint8 control_endpoint;
VS_HEAD vs_head;
VS_FRAME vs_frame[VS_FAME_TYPE_MAXNUM];
VS_FORMAT vs_format[VS_FORMAT_TYPE_MAXNUM];
uint8 vs_frame_num;
uint8 vs_format_num;
uint32 intfs_count;
uint32 edpt_count;
SINTF_DESC intfs[__INTFS_STACK__];
SEP_DESC edpt[__INTFS_STACK__];
struct VC_PROCESS vc_process;
uint8 control_intfs;
}UVC_DES;
typedef struct{
uint8 ep;
uint8 eptpye;
uint16 len;
}EP_DES;
typedef struct
{
uint8 ctyp;
uint8 cv;
uint8 epctl;
uint8 ctl_intfs;
uint8 ctl_altset;
uint8 ctl_pload;
uint8 ctl_ttyp;
uint8 ctl_interval;
uint8 epstrm;
uint8 strm_intfs;
uint8 strm_altset;
uint16 strm_pload;
uint8 strm_ttyp;
uint8 strm_interval;
}UVCDEV;
typedef struct{
uint8 ctl_intfs;
uint32 process_ctl;
uint8 process_unitID;
}UVC_PROCESS;
typedef struct {
uint8 ctl_val;
int16 info;
int16 max;
int16 min;
uint16 res;
int16 cur;
}UVC_PROC_REQ;
typedef struct{
UVC_PROC_REQ brightness;
UVC_PROC_REQ contrast;
UVC_PROC_REQ hue;
UVC_PROC_REQ saturation;
UVC_PROC_REQ sharpness;
UVC_PROC_REQ gamma;
UVC_PROC_REQ white_bal_temp;
UVC_PROC_REQ white_bal_comp;
UVC_PROC_REQ backlight_comp;
UVC_PROC_REQ gain;
UVC_PROC_REQ power_line_fre;
UVC_PROC_REQ hue_auto;
UVC_PROC_REQ white_bal_temp_auto;
UVC_PROC_REQ white_bal_comp_auto;
UVC_PROC_REQ digital_mult;
UVC_PROC_REQ digital_mult_limit;
UVC_PROC_REQ ana_video_stan;
UVC_PROC_REQ ana_lock_sta;
UVC_PROC_REQ contrast_auto;
}UVC_PROCESS_INFO;
typedef enum {
BRIGHTNESS,
CONTRAST,
HUE,
SATURATION,
SHARPNESS,
GAMMA,
WHITE_BAL_TEMP,
WHITE_BAL_COMP,
BACKLIGHT_COMP,
GAIN,
POWER_LINE_FRE,
HUE_AUTO,
WHITE_BAL_TEMP_AUTO,
WHITE_BAL_COMP_AUTO,
DIGITAL_MULT,
DIGITAL_MULT_LIMIT,
ANA_VIDEO_STAN,
ANA_LOCK_STA,
AONTRAST_AUTO
}UVC_PROCESS_ENUM;
typedef struct{
VS_FRAME vs_frame;
VS_FORMAT vs_format;
}UVC_SLEST;
struct VIDEO_COMMIT
{
uint16 bmhint;
uint8 bFormatIndex;
uint8 bFrameIndex;
uint32 dwFrameInterval;
uint16 wKeyFrameRate;
uint16 wPFrameRate;
uint16 wCompQuality;
uint16 wCompWindowSize;
uint16 wDelay;
uint32 dwMaxVideoFrameSize;
uint32 dwMaxPayloadTSize;
}__attribute__((packed));
typedef struct {
struct list_head list;
uint8 *cpbuff; //当前写入数据的地址
uint8 uvc_head[16];//one pack head data
uint8 frame_end; //frame结束标志,表示USB获取数据结束 0:进行中 1:正常结束 2:异常结束
uint32 tgl;
uint32 sta;
uint32 state; //frame状态,0:空闲 1:正在填充 2:可用 3:应用正在使用
uint32 frame_len; //帧长度
uint32 data_len;//one packe data len
uint32 head_len;//one packe head len
uint32 re_space;//当前所写的buff剩余空间
uint32 frame_counter;
}UVC_MANAGE;
typedef struct {
struct list_head list; //BLANK块节点互连
uint32 frame_counter; //此数据块代表的frame号
uint32 blank_len; //blank可使用的数据长度,最后一个数据块非满外,其他都满
uint32 re_space; //当前blank剩下多少空间可填
uint8 blank_loop; //blank计数,每一帧都从0开始增加,便于后面重组
uint8 *buf_ptr; //数据块指针
uint8 busy; //blank块状态,0:空闲 1:正在填充或者发送 2:可用
}UVC_BLANK;
typedef struct{
uint8 addr;
uint8 int_endpoint;
uint8 port_num;
uint8 connect_port;
}HUB_manage;
enum usb_host_io_cmd {
USB_HOST_IO_CMD_RESET, //usb复位
USB_HOST_IO_CMD_SET_CUR,
USB_HOST_IO_CMD_GET_CUR,
USB_HOST_IO_CMD_SET_IDX, //1:VGA, 2:720
};
struct uvc_user_arg
{
void *usb_dev;
uint32_t state; //0:可以创建任务 1:正在运行 2:等待任务删除
uint32_t uvc_format;
};
/****************uac****************/
typedef enum
{
AC_UNDEFINED=0,
AC_HEADER_DES,
AC_INPUT_DES,
AC_OUTPUT_DES,
AC_MIXER_DES,
AC_SELECTOR_DES,
AC_FEATURE_DES
}AC_Subtype;
typedef enum
{
AS_UNDEFINED=0,
AS_General_Des,
AS_Format_Des
}AS_Subtype;
typedef enum
{
USB_Undefined = 0x0100,
USB_streaming = 0x0101,
USB_vendor_specific = 0x01FF,
Input_Undefined = 0x0200,
Microphone = 0x0201,
Desktop_microphone = 0x0202,
Output_Undefined = 0x0300,
Speaker = 0x0301,
Headphones = 0x0302
}AC_Terminal_Types;
typedef struct{
uint8 bLength;
uint8 bDescriptorType;
uint8 bDescriptorSubtype;
uint8 bTerminalID;
uint16 wTerminalType;
uint8 bAssocTerminal;
uint8 bNrChannels;
uint16 wChannelConfig;
uint8 iChannelNames;
uint8 iTerminal;
}AC_INPUT;
typedef struct{
uint8 bLength;
uint8 bDescriptorType;
uint8 bDescriptorSubtype;
uint8 bUnitID;
uint8 bSourceID;
uint8 bControlSize;
uint8 bmaControls[2];
}AC_FEATURE;
typedef struct{
uint8 bLength;
uint8 bDescriptorType;
uint8 bDescriptorSubtype;
uint8 bTerminalID;
uint16 wTerminalType;
uint8 bAssocTerminal;
uint8 bSourceID;
uint8 iTerminal;
}AC_OUTPUT;
typedef struct{
uint8 bLength;
uint8 bDescriptorType;
uint8 bInterfaceNumber;
uint8 bAlternateSetting;
uint8 bNumEndpoints;
uint8 bInterfaceClass;
uint8 bInterfaceSubClass;
uint8 bInterfaceProtocol;
uint8 iInterface;
}AS_INTERFACE;
typedef struct{
uint8 bLength;
uint8 bDescriptorType;
uint8 bDescriptorSubtype;
uint8 bTerminalLink;
uint8 bDelay;
uint16 wFormatTag;
}AS_GENERAL;
typedef struct{
uint8 bLength;
uint8 bDescriptorType;
uint8 bDescriptorSubtype;
uint8 bFormatType;
uint8 bNrChannels;
uint8 bSubframeSize;
uint8 bBitResolution;
uint8 bSamFreqType;
uint32 tSamFreq[4];
}AS_FORMAT;
typedef struct{
uint8 bLength;
uint8 bDescriptorType;
uint8 bEndpointAddress;
uint8 bmAttributes;
uint16 wMaxPacketSize;
uint8 bInterval;
uint8 bRefresh;
uint8 bSynchAddress;
}AS_ENDPOINT;
#define AS_GENERAL_TYPE_MAXNUM 10
#define AS_FORMAT_TYPE_MAXNUM 10
typedef struct{
uint8 DesLen;
uint8 DescriptorType;
uint8 Subtype;
uint8 control_endpoint;
uint8 control_interface;
AC_INPUT ac_input[3];
AC_OUTPUT ac_output[3];
AC_FEATURE ac_feature[3];
AS_INTERFACE as_interface[4];
AS_GENERAL as_general[AS_GENERAL_TYPE_MAXNUM];
AS_FORMAT as_format[AS_FORMAT_TYPE_MAXNUM];
AS_ENDPOINT as_endpoint[10];
uint8 ac_input_num;
uint8 ac_feature_num;
uint8 ac_output_num;
uint8 as_interface_num;
uint8 as_general_num;
uint8 as_format_num;
uint8 as_endpoint_num;
}UAC_DES;
typedef struct{
uint16 spk_type;
uint8 spk_strm_intfs;
uint8 spk_strm_altset[4];
uint16 spk_fmttag[4];
uint8 spk_fmttype[4];
uint8 spk_nrchl[4];
uint8 spk_fmsize[4];
uint8 spk_bitres[4];
uint8 spk_samfretype[4];
uint8 spk_samfre[4][4];
uint8 spk_epstrm[4];
uint8 spk_eptype[4];
uint16 spk_strm_pload[4];
uint8 spk_feaunitID;
uint8 spk_feaunit_ctl[2];
int16 spk_max_vol;
int16 spk_min_vol;
uint16 mic_type;
uint8 mic_strm_intfs;
uint8 mic_strm_altset[4];
uint16 mic_fmttag[4];
uint16 mic_fmttype[4];
uint8 mic_nrchl[4];
uint8 mic_fmsize[4];
uint8 mic_bitres[4];
uint8 mic_samfretype[4];
uint8 mic_samfre[4][4];
uint8 mic_epstrm[4];
uint8 mic_eptype[4];
uint16 mic_strm_pload[4];
uint8 mic_feaunitID;
uint8 mic_feaunit_ctl[2];
int16 mic_max_vol;
int16 mic_min_vol;
uint8 ctl_intfs;
}UACDEV;
typedef struct{
uint8 strm_intfs;
uint8 strm_altset;
uint8 epstrm;
uint8 eptype;
uint16 strm_pload;
}MICDEV;
typedef struct{
uint8 strm_intfs;
uint8 strm_altset;
uint8 epstrm;
uint8 eptype;
uint16 strm_pload;
}SPKDEV;
typedef struct{
struct list_head list;
uint8 *data_addr; //当前写入数据的地址
uint32 data_len;
uint32 respace_len;
uint32 offset;
uint8 sta;
}UAC_MANAGE;
/**********uac************/
#define HUB_STATU_CONNECT (BIT(1))
#define HUB_STATU_RESTEND (BIT(1))
/**hub clear feature **/
#define PORT_CONNECT 0x10
#define PORT_ENABLE 0X01
#define CLEAR_PORT_REST 0x14
/**hub set feature **/
#define PORT_POWER 0X08
#define PORT_REST 0x04
#define UVC_EP 2
#define HUB_EP 1
#define UAC_EP 3
#define UVC2_EP 1
#define ISO_HEAD 0
#define BULK_HEAD 12
#define UVC_HEAD BULK_HEAD
#define UVC_HOST_NUM 2
void uvc_room_init(void *p_dev);
void usb_dma_irq(void * dev, uint8_t* uvc_rx_buff, uint8_t uvc_head_res, uint8_t ep_type);
//void usb_host_irq(typedef_usb_t *usb_sw);
void uvc_user();
void uvc_room_init_mjpeg();
void uvc_room_deinit_mjpeg();
void uvc_room_init_h264();
void uvc_room_deinit_h264(void);
void uvc_reset_dev(uint8_t en);
void uvc_reset_dev_mjpeg(uint8_t en);
void uvc_reset_dev_h264(uint8_t en);
void uvc_sema_init();
void uvc_sema_down(int32 tmo_ms);
void uvc_sema_up();
void uvc_app_user_init();
void force_reset_uvc_frame();
UVC_MANAGE* get_uvc_message_gloal();
uint32 get_uvc_frame_len();
uint8* get_uvc_buf();
uint8 free_uvc_blank(UVC_BLANK* uvc_b);
UVC_BLANK* get_uvc_blank();
extern void del_usbmic_frame(UAC_MANAGE *uac_manage);
extern UAC_MANAGE *get_usbmic_frame(void);
extern uint32 get_uac_frame_datalen(UAC_MANAGE *uac_manage);
extern uint8 *get_uac_frame_data(UAC_MANAGE *uac_manage);
extern void set_uac_frame_datalen(UAC_MANAGE *uac_manage, uint32 len);
extern UAC_MANAGE *get_usbspk_new_frame(uint8 grab);
extern void put_usbspk_frame_to_use(UAC_MANAGE *uac_manage);
extern void set_uac_frame_sta(UAC_MANAGE *uac_manage, uint8 sta);
extern void usbspk_room_init(uint32_t empty_buf_len);
extern void usbmic_room_init(void);
extern void usbmic_dma_irq(void *dev, uint8_t* mic_rx_buff);
extern void usbspk_dma_irq(void *dev);
extern void uac_stop(void);
extern void uac_start(void *dev, uint8_t* mic_rx_buff);
extern int uvc_ep_bulk_or_isoc();
extern void force_reset_usbmic_frame();
extern void force_reset_usbspk_frame();
#endif
+36
View File
@@ -0,0 +1,36 @@
#ifndef HG_VPP_H
#define HG_VPP_H
#include "tx_platform.h"
#include "list.h"
#include "dev.h"
#include "hal/vpp.h"
typedef enum {
HSIE_ISR = 0,
VSIE_ISR,
SCIE_ISR,
LOVIE_ISR,
IPF_OV_ISR,
MDPIE_ISR,
ITP_OV_ISR,
ITP_DONE_ISR,
VPP_IRQ_NUM,
}VPP_IRQ_E;
struct hgvpp {
struct vpp_device dev;
//struct hgdvp_hw *hw;
uint32 hw;
vpp_irq_hdl irq_hdl;
uint32 irq_data;
uint32 irq_num;
uint32 opened:1, use_dma:1, dsleep:1;
uint32 *cfg_backup;
};
int32 hgvpp_attach(uint32 dev_id, struct hgvpp *vpp);
#endif
+31
View File
@@ -0,0 +1,31 @@
#ifndef _FMAC_DEV_H_
#define _FMAC_DEV_H_
#ifdef __cplusplus
extern "C" {
#endif
int32 hgic_fmac_attach(uint32 dev_id, int32 bus_type, const char *fw_data, uint8 reset_io);
int32 fmac_dev_open(struct netdev *ndev);
int32 fmac_dev_close(struct netdev *ndev);
int32 fmac_dev_set_work_mode(struct netdev *ndev, char *mode);
int32 fmac_dev_get_work_mode(struct netdev *ndev, char *buff);//buff size >= 12
int32 fmac_dev_set_ssid(struct netdev *ndev, char *ssid);
int32 fmac_dev_get_ssid(struct netdev *ndev, char *buff);//buff size >= 32
int32 fmac_dev_set_key_mgmt(struct netdev *ndev, char *key_mgmt);
int32 fmac_dev_get_key_mgmt(struct netdev *ndev, char *buff);//buff size >= 12
int32 fmac_dev_set_wpa_psk(struct netdev *ndev, char *psk);
int32 fmac_dev_get_wpa_psk(struct netdev *ndev, char *buff);//buff size >= 64
int32 fmac_dev_set_bss_bw(struct netdev *ndev, uint8 bss_bw);
int32 fmac_dev_set_chan_list(struct netdev *ndev, uint16 *chan_list, uint32 count);
int32 fmac_dev_set_paired_stas(struct netdev *ndev, uint8 *mac_list, uint32 count);
int32 fmac_dev_enter_sleep(struct netdev *ndev, uint16 sleep, uint32 sleep_ms);
int32 fmac_dev_ota(struct netdev *ndev);
#ifdef __cplusplus
}
#endif
#endif
+39
View File
@@ -0,0 +1,39 @@
#ifndef _HG_XSPI_H_
#define _HG_XSPI_H_
#include "hal/spi.h"
#ifdef __cplusplus
extern "C" {
#endif
enum hg_xspi_flags {
hg_xspi_flags_ready,
hg_xspi_flags_suspend,
};
struct hg_xspi {
struct dev_obj dev;
void *hw;
uint32 irq_num;
//qspi_irq_hdl irq_hdl;
uint32 irq_data;
uint32 opened;
uint32 flags;
#ifdef CONFIG_SLEEP
uint32 sys_regs[6];
uint32 ospi_regs[256/4];
#endif
};
extern struct hg_xspi xspi;
int32 hg_xspi_attach(uint32 dev_id, struct hg_xspi *p_spi);
void hg_xspi_sample_offset(uint32 ospi_base, int8 rx_offset, int8 tx_offset);
#ifdef __cplusplus
}
#endif
#endif
+158
View File
@@ -0,0 +1,158 @@
/**
******************************************************************************
* @file Libraries/Driver/include/LL/tx_peg_ll_qspi.h
* @author HUGE-IC Application Team
* @version V1.0.0
* @date 01-07-2019
* @brief This file contains all the QSPI LL firmware functions.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT 2019 HUGE-IC</center></h2>
*
*
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef _HG_XSPI_PSRAM_H_
#define _HG_XSPI_PSRAM_H_
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
/** @addtogroup TX_PEG_StdPeriph_Driver CanesVenatici Driver
* @{
*/
/** @addtogroup qspi_interface_gr QSPI Driver
* @ingroup TX_PEG_StdPeriph_Driver
* @{
*/
/** @addtogroup QSPI_LL_Driver QSPI LL Driver
* @ingroup qspi_interface_gr
* @brief Mainly the driver part of the QSPI module, which includes \b QSPI \b Register
* \b Constants, \b QSPI \b Exported \b Constants, \b QSPI \b Exported \b Struct, \b QSPI
* \b Data \b transfers \b functions, \b QSPI \b Initialization \b and \b QSPI \b Configuration
* \b And \b Interrupt \b Handle \b function.
* @{
*/
/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
struct psram_attr {
uint32 read_mem_opc : 8,
write_mem_opc : 8,
read_reg_opc : 8,
write_reg_opc : 8;
uint32 read_lc : 4,
write_lc : 4,
lc_type : 1,
driver : 2,
rbx_en : 1,
slow_refresh_en : 1,
/* 0/1/2/3 for sigle\dual\quad\octal */
wire_mode : 3,
ddr_mode : 1,
reserved1 : 7;
uint32 burst_type : 1,
burst_len : 15,
density_mbyte: 16;
uint8 psram_mr[8];
/* read-only attr */
uint32 vid : 5,
did : 2,
is_good_die : 1,
/* 0 :1.8V, 1:3.3V */
voltage_range: 1,
refresh_range: 3,
/* 0 :
* 1 :half-sleep
* 2 :deep sleep
*/
ulp_mode : 4,
/* 0 :slow, 1:fast */
self_refresh_speed : 1,
ulp_half_sleep_support : 1,
rbx_support : 1,
reserved3 : 1,
voltage_gear : 4,
reserved2 : 8;
uint32 page_size : 16,
clk_mhz : 16;
};
struct stig_req {
uint32 is_read : 1,
addr_len: 3,
data_len: 4,
cmd : 8,
dummy : 8,
reserved: 8;
uint32 addr;
void *p_buf;
};
enum psram_type {
APS1604M_3SQR,
APS1604M_DQRA,
APS3208K_OKUD,
APS6408L_OBMx,
APS1604M_3SQR_TXW817_812,
SCKW18X128800,
SCKM18X032800,
PSRAM_TYPE_END,
};
/***** DRIVER API *****/
/***** LL API *****/
/***** LL API AND DRIVER API *****/
uint8_t psram_init(enum psram_type pt, uint32 clk_hz,uint32 check_size);
int psram_auto_init();
void psram_deinit(enum psram_type pt) ;
#ifdef __cplusplus
}
#endif
/**
* @}
*/
/**
* @}
*/
#endif
/*************************** (C) COPYRIGHT 2023 HUGE-IC ***** END OF FILE *****/