總覽
本節介紹captouch驅動程序API,包括術語和首字母縮寫詞,支持的功能,軟件體系結構,有關如何使用此驅動程序的詳細信息,枚舉,結構和功能。
術語和首字母縮寫詞
條款 | 細節 |
---|---|
通用輸入輸出 | 有關通用輸入輸出的介紹,請參考HAL中的GPIO模塊。 |
Captouch | 電容式觸摸控制器用於人機界面。當人的手指觸摸傳感部分(通常是系統硬件的一部分)時,會形成電容,其中一塊板是導電層,另一塊板是人的手指。 |
支持的功能
該模塊提供了通用設計來獲取外部觸摸事件。captouch通過自動校準用法的詳細說明提供了兩種使用方法,如下所示的正常用法。
- 正常 使用。
在這種用法中,每當按下或釋放打擊墊時都會觸發一箇中斷。可以爲該中斷註冊回調函數。每當按下或釋放打擊墊時,都會調用回調函數。hal_captouch_get_event()可在回調函數中使用,以獲取鍵事件和鍵位置編號。 - tunning usange。
在這種用法中,用戶可以通過hal_captouch_tune_control()來調整粗略上限。
如何使用此驅動程序
- 使用 了 正常。
要在正常模式下使用catpouch驅動程序,請參考GPIO數據表,確定應選擇將GPIO複用到captouch引腳的GPIO。然後調用hal_captouch_init()手動設置通道位圖,註冊回調函數,默認粗略上限和閾值。調用hal_captouch_init()之後,驅動程序即可工作。如果按下或釋放了鍵盤上的某個鍵,則鍵盤將觸發中斷以調用回調函數。用戶應使用hal_captouch_get_event()在回調函數中獲取鍵事件和鍵位置編號。爲確保可靠的鍵掃描,請勿重載回調函數。讓回調儘快返回。- 步驟1。調用hal_captouch_init()初始化captouch模塊。
- 第2步。如果不再使用captouch模塊,則調用hal_captouch_deinit()取消初始化。
- 樣例代碼:
hal_captouch_config_t config; hal_captouch_tune_data_t tune_data; uint32_t i; config.callback.callbck = user_captouch_callback; // Register callback config.callback.userdata = NULL; // User's callback parameter pointer config.channel_bit_map = 0xff; // Sets the channel0~7 enable for(i=0;i<8;i++) { config.high_thr[i] = 210; // Sets the high threshold value config.low_thr[i] = 100; // Sets the low threshold value config.coarse_cap[i] = 2; // Sets the coarse cap value } hal_captouch_init(&config); ... hal_captouch_deinit(); // De-initialize the captouch module if it is no longer in use. // Callback function. This function should be registered with #hal_captouch_init(). void user_captouch_callback (void *user_data) { // Get the key press or release event. hal_captouch_event_t key_event; uint32_t key_symbol; hal_captouch_status_t ret; while(1) { ret = hal_captouch_get_event(&key_event); if (ret == HAL_CAPTOUCH_STATUS_NO_EVENT) { break; } } }
- 使用 該 tunning 使用。
然後調整用法是按通道查找適當的粗略上限值。- 步驟1。調用hal_captouch_init()初始化captouch模塊。第2步。調用hal_captouch_tune_control()來找到適當的粗略上限值。
-
hal_captouch_config_t config; hal_captouch_tune_data_t tune_data; uint32_t i; config.callback.callbck = user_captouch_callback; // Register callback config.callback.userdata = NULL; // User's callback parameter pointer config.channel_bit_map = 0xff; // Sets the channel0~7 enable for(i=0;i<8;i++) { config.high_thr[i] = 210; // Sets the high threshold value config.low_thr[i] = 100; // Sets the low threshold value config.coarse_cap[i] = 2; // Sets the coarse cap value } hal_captouch_init(&config); for(i=0;i<8;i++) { // The tune_data can be stored in memory, and filled by #hal_captouch_init(). hal_captouch_tune_control(i,HAL_CAPTOUCH_TUNE_SW_AUTO,&tune_data); // If tuning the 8 channels. } ... hal_captouch_deinit(); // De-initialize the captouch module if it is no longer in use.
功能文件
◆ hal_captouch_channel_disable()
hal_captouch_status_t hal_captouch_channel_disable | ( | hal_captouch_channel_t | 渠道 | ) |
此功能禁用通道。它將禁用檢測,通道中斷和通道喚醒中斷。此API和hal_captouch_channel_enable()是獨立的,如有必要,必須在hal_captouch_init()之後調用。
參量
[在] | 渠道 | 是頻道號。有關更多詳細信息,請參考hal_captouch_channel_t。 |
退貨
HAL_CAPTOUCH_STATUS_OK,如果操作成功。
也可以看看
◆ hal_captouch_channel_enable()
hal_captouch_status_t hal_captouch_channel_enable | ( | hal_captouch_channel_t | 渠道 | ) |
此功能啓用通道。它將啓用對通道中斷和通道喚醒中斷的檢測。此API和hal_captouch_channel_disable()是相互依賴的。如有必要,必須在hal_captouch_init()之後調用它。
參量
[在] | 渠道 | 是頻道號。有關更多詳細信息,請參考hal_captouch_channel_t。 |
退貨
HAL_CAPTOUCH_STATUS_OK,如果操作成功。
也可以看看
◆ hal_captouch_deinit()
hal_captouch_status_t hal_captouch_deinit | ( | 虛空 | ) |
◆ hal_captouch_get_event()
hal_captouch_status_t hal_captouch_get_event | ( | hal_captouch_event_t * | 事件 | ) |
此函數獲取關鍵事件數據。
參量
[出] | 事件 | 是指向關鍵事件數據的指針。有關更多詳細信息,請參考hal_captouch_event_t。 |
退貨
HAL_CAPTOUCH_STATUS_OK,如果操作成功。
◆ hal_captouch_init()
hal_captouch_status_t hal_captouch_init | ( | 虛空 | ) |
◆ hal_captouch_lowpower_control()
hal_captouch_status_t hal_captouch_lowpower_control | ( | hal_captouch_lowpower_type_t | lowpower_type | ) |
此功能控制captouch何時進入正常或低功耗模式。可以在hal_captouch_init()之後使用。
參量
[在] | lowpower_type | 是類型值。有關更多詳細信息,請參考hal_captouch_lowpower_type_t。 |
退貨
HAL_CAPTOUCH_STATUS_OK,如果操作成功。
◆ hal_captouch_set_avg()
hal_captouch_status_t hal_captouch_set_avg | ( | U16 | mavg_val, |
U16 | avg_val | ||
) |
此功能更改粗毛細度上限值。
參量
[在] | mavg_val | 是觸控移動平均時間。 |
[在] | avg_val | 是平均時間的觸摸控制ADC。 |
退貨
HAL_CAPTOUCH_STATUS_OK,如果操作成功。
◆ hal_captouch_set_coarse_cap()
hal_captouch_status_t hal_captouch_set_coarse_cap | ( | hal_captouch_channel_t | 通道, |
uint32_t | 粗 | ||
) |
此功能更改粗毛細度上限值。
參量
[在] | 渠道 | 是頻道號。有關更多詳細信息,請參考hal_captouch_channel_t。 |
[在] | 粗 | 是corase封頂值。如果在相同的精細上限值中,粗略上限值較大,則平均值和VACD將較小。值的範圍應爲0 <= coarse <= 7。 |
退貨
HAL_CAPTOUCH_STATUS_OK,如果操作成功。
◆ hal_captouch_set_fine_cap()
hal_captouch_status_t hal_captouch_set_fine_cap | ( | hal_captouch_channel_t | 通道, |
S16 | 精細 | ||
) |
此功能更改細上限值。此API僅可以在手動模式下使用。
參量
[在] | 渠道 | 是頻道號。有關更多詳細信息,請參考hal_captouch_channel_t。 |
[在] | 精細 | 是上限金額。如果在相同的粗略上限值中,精細上限值較大,則平均值和VACD將較小。值的範圍應爲-64 <= fine <= 63。 |
退貨
HAL_CAPTOUCH_STATUS_OK,如果操作成功。
◆ hal_captouch_set_threshold()
hal_captouch_status_t hal_captouch_set_threshold | ( | hal_captouch_channel_t | 通道, |
S16 | high_thr, | ||
S16 | low_thr | ||
) |
此功能按通道更改高閾值和低閾值。
參量
[在] | 渠道 | 是頻道號。有關更多詳細信息,請參考hal_captouch_channel_t。 |
[在] | high_thr | 是高閾值。當平均adc值大於此值時,它將觸發按下事件。值的範圍應爲-256 <= high_thr <= 255。 |
[在] | low_thr | 是低閾值。當平均adc值小於此值時,它將觸發釋放事件。值的範圍應爲-256 <= high_thr <= 255。 |
退貨
HAL_CAPTOUCH_STATUS_OK,如果操作成功。
◆ hal_captouch_tune_control()
hal_captouch_status_t hal_captouch_tune_control | ( | hal_captouch_channel_t | 通道, |
hal_captouch_tune_type_t | tune_type, | ||
hal_captouch_tune_data_t * | 數據 | ||
) |
此功能按通道調整校準值。
參量
[在] | 渠道 | 是頻道號。有關更多詳細信息,請參考hal_captouch_channel_t。 |
[在] | tune_type | 是音調類型模式。有關更多詳細信息,請參考hal_captouch_tune_type_t。 |
[出] | 數據 | 是指針調整結果。 |
退貨
HAL_CAPTOUCH_STATUS_OK,如果操作成功。
Struct
Overview
Data Structures |
|
struct | hal_captouch_callback_context_t |
This structure defines callback parameter. More... | |
struct | hal_captouch_config_t |
This structure defines configuration parameter. More... | |
struct | hal_captouch_tune_data_t |
This structure defines tune data. More... | |
struct | hal_captouch_event_t |
This structure defines key event data. More... | |
Enumerations |
|
enum | hal_captouch_tune_type_t { HAL_CAPTOUCH_TUNE_SW_AUTO = 0 } |
This structure defines tune type. More... | |
enum | hal_captouch_lowpower_type_t { HAL_CAPTOUCH_MODE_NORMAL = 0, HAL_CAPTOUCH_MODE_LOWPOWER = 1 } |
This structure defines power mode type. More... | |
enum | hal_captouch_channel_t { HAL_CAPTOUCH_CHANNEL_0 = 0, HAL_CAPTOUCH_CHANNEL_1 = 1, HAL_CAPTOUCH_CHANNEL_2 = 2, HAL_CAPTOUCH_CHANNEL_3 = 3, HAL_CAPTOUCH_CHANNEL_4 = 4, HAL_CAPTOUCH_CHANNEL_5 = 5, HAL_CAPTOUCH_CHANNEL_6 = 6, HAL_CAPTOUCH_CHANNEL_7 = 7, HAL_CAPTOUCH_CHANNEL_MAX = 8 } |
This structure defines channel. More... | |
Enumeration Type Documentation
◆ hal_captouch_channel_t
enum hal_captouch_channel_t |
This structure defines channel.
◆ hal_captouch_lowpower_type_t
enum hal_captouch_lowpower_type_t |
This structure defines power mode type.
Enumerator | |
---|---|
HAL_CAPTOUCH_MODE_NORMAL |
Specify the normal mode |
HAL_CAPTOUCH_MODE_LOWPOWER |
Specify the low-power mode |
◆ hal_captouch_tune_type_t
enum hal_captouch_tune_type_t |
This structure defines tune type.
Enumerator | |
---|---|
HAL_CAPTOUCH_TUNE_SW_AUTO |
Specify the software automatic tune mode. |
Typedef
Overview
Typedefs |
|
typedef void(* | hal_captouch_callback_t) (void *user_data) |
This function registers a callback function when in a normal usage. This function is called after the key is pressed or released in the captouch ISR routine. More... | |
Typedef Documentation
◆ hal_captouch_callback_t
typedef void(* hal_captouch_callback_t) (void *user_data) |
This function registers a callback function when in a normal usage. This function is called after the key is pressed or released in the captouch ISR routine.
Parameters
[in] | user_data | This variable pointer is defined by the user to record the data. |