mirror of
https://github.com/openharmony/device_board_hpmicro.git
synced 2026-07-01 21:54:00 -04:00
Enable GPIO all features
Signed-off-by: Hongpeng HUO <hongpeng.huo@hpmicro.com>
This commit is contained in:
@@ -17,6 +17,7 @@ module_name = get_path_info(rebase_path("."), "name")
|
||||
module_group(module_name) {
|
||||
modules = [
|
||||
"watchdog",
|
||||
"gpio",
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,18 @@ menu "Applications for HPMicro"
|
||||
config WDT_DRIVER_TEST
|
||||
bool "watchdog driver test"
|
||||
default n
|
||||
|
||||
config GPIO_DRIVER_IN_TEST
|
||||
bool "gpio driver input test"
|
||||
default n
|
||||
|
||||
config GPIO_DRIVER_OUT_TEST
|
||||
bool "gpio driver output test"
|
||||
default n
|
||||
|
||||
config GPIO_DRIVER_IRQ_TEST
|
||||
bool "gpio driver interrupt test"
|
||||
default n
|
||||
endmenu
|
||||
|
||||
endif #BOARD_COMPANY_HPMCIRO
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
# Copyright (c) 2022 HPMicro.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//kernel/liteos_m/liteos.gni")
|
||||
import("//drivers/hdf_core/adapter/khdf/liteos_m/hdf.gni")
|
||||
|
||||
module_name = get_path_info(rebase_path("."), "name")
|
||||
module_switch = true
|
||||
|
||||
hdf_driver(module_name) {
|
||||
include_dirs = [
|
||||
"//base/hiviewdfx/hilog_lite/interfaces/native/kits/hilog_lite"
|
||||
]
|
||||
|
||||
sources = []
|
||||
if (defined(LOSCFG_GPIO_DRIVER_IN_TEST)) {
|
||||
sources += [
|
||||
"app_gpio_in.c",
|
||||
]
|
||||
}
|
||||
|
||||
if (defined(LOSCFG_GPIO_DRIVER_OUT_TEST)) {
|
||||
sources += [
|
||||
"app_gpio_out.c",
|
||||
]
|
||||
}
|
||||
|
||||
if (defined(LOSCFG_GPIO_DRIVER_IRQ_TEST)) {
|
||||
sources += [
|
||||
"app_gpio_irq.c",
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Copyright (c) 2022 HPMicro.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <ohos_init.h>
|
||||
#include <stdio.h>
|
||||
#include <los_task.h>
|
||||
#include <stdint.h>
|
||||
#include <log.h>
|
||||
#include <gpio_if.h>
|
||||
#include <hpm_soc.h>
|
||||
#include <hpm_clock_drv.h>
|
||||
|
||||
#define LOG_TAG "HPM_GPIO_OUT"
|
||||
|
||||
#define GPIOA(pin) (pin)
|
||||
#define GPIOB(pin) (pin + 32)
|
||||
#define GPIOC(pin) (pin + 32 * 2)
|
||||
#define GPIOD(pin) (pin + 32 * 3)
|
||||
#define GPIOE(pin) (pin + 32 * 4)
|
||||
#define GPIOF(pin) (pin + 32 * 5)
|
||||
#define GPIOY(pin) (pin + 32 * 14)
|
||||
#define GPIOZ(pin) (pin + 32 * 15)
|
||||
|
||||
static void GpioDriverInTestTask(uint32_t arg)
|
||||
{
|
||||
HILOG_INFO(HILOG_MODULE_APP, "GpioDriverInTestTask");
|
||||
|
||||
HPM_BIOC->PAD[IOC_PAD_PZ02].FUNC_CTL = IOC_PZ02_FUNC_CTL_SOC_PZ_02;
|
||||
HPM_BIOC->PAD[IOC_PAD_PZ02].PAD_CTL = IOC_PAD_PAD_CTL_PE_SET(1) | IOC_PAD_PAD_CTL_PS_SET(1) | IOC_PAD_PAD_CTL_SMT_SET(1);
|
||||
HPM_BIOC->PAD[IOC_PAD_PZ03].FUNC_CTL = IOC_PZ03_FUNC_CTL_SOC_PZ_03;
|
||||
HPM_BIOC->PAD[IOC_PAD_PZ03].PAD_CTL = IOC_PAD_PAD_CTL_PE_SET(1) | IOC_PAD_PAD_CTL_PS_SET(1) | IOC_PAD_PAD_CTL_SMT_SET(1);
|
||||
|
||||
HPM_IOC->PAD[IOC_PAD_PZ02].FUNC_CTL = 0;
|
||||
HPM_IOC->PAD[IOC_PAD_PZ02].PAD_CTL = IOC_PAD_PAD_CTL_PE_SET(1) | IOC_PAD_PAD_CTL_PS_SET(1) | IOC_PAD_PAD_CTL_SMT_SET(1);
|
||||
|
||||
HPM_IOC->PAD[IOC_PAD_PZ03].FUNC_CTL = 0;
|
||||
HPM_IOC->PAD[IOC_PAD_PZ03].PAD_CTL = IOC_PAD_PAD_CTL_PE_SET(1) | IOC_PAD_PAD_CTL_PS_SET(1) | IOC_PAD_PAD_CTL_SMT_SET(1);
|
||||
|
||||
GpioSetDir(GPIOZ(2), GPIO_DIR_IN);
|
||||
GpioSetDir(GPIOZ(3), GPIO_DIR_IN);
|
||||
|
||||
uint32_t pz02_flag = GPIO_VAL_HIGH;
|
||||
uint32_t pz03_flag = GPIO_VAL_HIGH;
|
||||
|
||||
while (1) {
|
||||
uint16_t val;
|
||||
GpioRead(GPIOZ(2), &val);
|
||||
if (val == GPIO_VAL_LOW && pz02_flag == GPIO_VAL_HIGH) {
|
||||
pz02_flag = GPIO_VAL_LOW;
|
||||
HILOG_INFO(HILOG_MODULE_APP, "GPIOZ(2) DOWN");
|
||||
} else if (val == GPIO_VAL_HIGH && pz02_flag == GPIO_VAL_LOW) {
|
||||
pz02_flag = GPIO_VAL_HIGH;
|
||||
HILOG_INFO(HILOG_MODULE_APP, "GPIOZ(2) UP");
|
||||
}
|
||||
|
||||
GpioRead(GPIOZ(3), &val);
|
||||
if (val == GPIO_VAL_LOW && pz03_flag == GPIO_VAL_HIGH) {
|
||||
pz03_flag = GPIO_VAL_LOW;
|
||||
HILOG_INFO(HILOG_MODULE_APP, "GPIOZ(3) DOWN");
|
||||
} else if (val == GPIO_VAL_HIGH && pz03_flag == GPIO_VAL_LOW) {
|
||||
pz03_flag = GPIO_VAL_HIGH;
|
||||
HILOG_INFO(HILOG_MODULE_APP, "GPIOZ(3) UP");
|
||||
}
|
||||
|
||||
LOS_TaskDelay(50);
|
||||
}
|
||||
}
|
||||
|
||||
static void GpioDriverTest(void)
|
||||
{
|
||||
TSK_INIT_PARAM_S taskInitParam = {0};
|
||||
|
||||
taskInitParam.pcName = "gpio_in_test";
|
||||
taskInitParam.pfnTaskEntry = GpioDriverInTestTask;
|
||||
taskInitParam.stackAddr = 0;
|
||||
taskInitParam.uwStackSize = 4096;
|
||||
taskInitParam.usTaskPrio = 20;
|
||||
taskInitParam.uwArg = 0x66;
|
||||
uint32_t taskID;
|
||||
LOS_TaskCreate(&taskID, &taskInitParam);
|
||||
}
|
||||
|
||||
APP_FEATURE_INIT(GpioDriverTest);
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (c) 2022 HPMicro.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <ohos_init.h>
|
||||
#include <stdio.h>
|
||||
#include <los_task.h>
|
||||
#include <stdint.h>
|
||||
#include <log.h>
|
||||
#include <gpio_if.h>
|
||||
#include <hpm_soc.h>
|
||||
#include <hpm_clock_drv.h>
|
||||
|
||||
#define LOG_TAG "HPM_GPIO_OUT"
|
||||
|
||||
#define GPIOA(pin) (pin)
|
||||
#define GPIOB(pin) (pin + 32)
|
||||
#define GPIOC(pin) (pin + 32 * 2)
|
||||
#define GPIOD(pin) (pin + 32 * 3)
|
||||
#define GPIOE(pin) (pin + 32 * 4)
|
||||
#define GPIOF(pin) (pin + 32 * 5)
|
||||
#define GPIOY(pin) (pin + 32 * 14)
|
||||
#define GPIOZ(pin) (pin + 32 * 15)
|
||||
|
||||
|
||||
static int32_t GpioIrq(uint16_t gpio, void *data)
|
||||
{
|
||||
HILOG_INFO(HILOG_MODULE_APP, "gpio: %u", gpio);
|
||||
}
|
||||
|
||||
static void GpioDriverInTestTask(void)
|
||||
{
|
||||
HILOG_INFO(HILOG_MODULE_APP, "GpioDriverIrqTest");
|
||||
|
||||
HPM_BIOC->PAD[IOC_PAD_PZ02].FUNC_CTL = IOC_PZ02_FUNC_CTL_SOC_PZ_02;
|
||||
HPM_BIOC->PAD[IOC_PAD_PZ02].PAD_CTL = IOC_PAD_PAD_CTL_PE_SET(1) | IOC_PAD_PAD_CTL_PS_SET(1) | IOC_PAD_PAD_CTL_SMT_SET(1);
|
||||
HPM_BIOC->PAD[IOC_PAD_PZ03].FUNC_CTL = IOC_PZ03_FUNC_CTL_SOC_PZ_03;
|
||||
HPM_BIOC->PAD[IOC_PAD_PZ03].PAD_CTL = IOC_PAD_PAD_CTL_PE_SET(1) | IOC_PAD_PAD_CTL_PS_SET(1) | IOC_PAD_PAD_CTL_SMT_SET(1);
|
||||
|
||||
HPM_IOC->PAD[IOC_PAD_PZ02].FUNC_CTL = 0;
|
||||
HPM_IOC->PAD[IOC_PAD_PZ02].PAD_CTL = IOC_PAD_PAD_CTL_PE_SET(1) | IOC_PAD_PAD_CTL_PS_SET(1) | IOC_PAD_PAD_CTL_SMT_SET(1);
|
||||
|
||||
HPM_IOC->PAD[IOC_PAD_PZ03].FUNC_CTL = 0;
|
||||
HPM_IOC->PAD[IOC_PAD_PZ03].PAD_CTL = IOC_PAD_PAD_CTL_PE_SET(1) | IOC_PAD_PAD_CTL_PS_SET(1) | IOC_PAD_PAD_CTL_SMT_SET(1);
|
||||
|
||||
GpioSetDir(GPIOZ(2), GPIO_DIR_IN);
|
||||
GpioSetDir(GPIOZ(3), GPIO_DIR_IN);
|
||||
|
||||
GpioSetIrq(GPIOZ(2), GPIO_IRQ_TRIGGER_RISING, GpioIrq, NULL);
|
||||
GpioSetIrq(GPIOZ(3), GPIO_IRQ_TRIGGER_FALLING, GpioIrq, NULL);
|
||||
|
||||
GpioEnableIrq(GPIOZ(2));
|
||||
GpioEnableIrq(GPIOZ(3));
|
||||
}
|
||||
|
||||
APP_FEATURE_INIT(GpioDriverInTestTask);
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright (c) 2022 HPMicro.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <ohos_init.h>
|
||||
#include <stdio.h>
|
||||
#include <los_task.h>
|
||||
#include <stdint.h>
|
||||
#include <log.h>
|
||||
#include <gpio_if.h>
|
||||
#include <hpm_soc.h>
|
||||
#include <hpm_clock_drv.h>
|
||||
|
||||
#define LOG_TAG "HPM_GPIO_OUT"
|
||||
|
||||
#define GPIOA(pin) (pin)
|
||||
#define GPIOB(pin) (pin + 32)
|
||||
#define GPIOC(pin) (pin + 32 * 2)
|
||||
#define GPIOD(pin) (pin + 32 * 3)
|
||||
#define GPIOE(pin) (pin + 32 * 4)
|
||||
#define GPIOF(pin) (pin + 32 * 5)
|
||||
#define GPIOY(pin) (pin + 32 * 14)
|
||||
#define GPIOZ(pin) (pin + 32 * 15)
|
||||
|
||||
static void GpioDriverOutTestTask(uint32_t arg)
|
||||
{
|
||||
HILOG_INFO(HILOG_MODULE_APP, "GpioDriverOutTestTask");
|
||||
|
||||
HPM_IOC->PAD[IOC_PAD_PB11].FUNC_CTL = 0;
|
||||
HPM_IOC->PAD[IOC_PAD_PB11].PAD_CTL = IOC_PAD_PAD_CTL_PE_SET(1) | IOC_PAD_PAD_CTL_PS_SET(1);
|
||||
|
||||
HPM_IOC->PAD[IOC_PAD_PB12].FUNC_CTL = 0;
|
||||
HPM_IOC->PAD[IOC_PAD_PB12].PAD_CTL = IOC_PAD_PAD_CTL_PE_SET(1) | IOC_PAD_PAD_CTL_PS_SET(1);
|
||||
|
||||
HPM_IOC->PAD[IOC_PAD_PB13].FUNC_CTL = 0;
|
||||
HPM_IOC->PAD[IOC_PAD_PB13].PAD_CTL = IOC_PAD_PAD_CTL_PE_SET(1) | IOC_PAD_PAD_CTL_PS_SET(1);
|
||||
|
||||
GpioSetDir(GPIOB(11), GPIO_DIR_OUT);
|
||||
GpioSetDir(GPIOB(12), GPIO_DIR_OUT);
|
||||
GpioSetDir(GPIOB(13), GPIO_DIR_OUT);
|
||||
|
||||
while (1) {
|
||||
GpioWrite(GPIOB(11), GPIO_VAL_LOW);
|
||||
LOS_TaskDelay(500);
|
||||
GpioWrite(GPIOB(11), GPIO_VAL_HIGH);
|
||||
LOS_TaskDelay(500);
|
||||
GpioWrite(GPIOB(12), GPIO_VAL_LOW);
|
||||
LOS_TaskDelay(500);
|
||||
GpioWrite(GPIOB(12), GPIO_VAL_HIGH);
|
||||
LOS_TaskDelay(500);
|
||||
GpioWrite(GPIOB(13), GPIO_VAL_LOW);
|
||||
LOS_TaskDelay(500);
|
||||
GpioWrite(GPIOB(13), GPIO_VAL_HIGH);
|
||||
LOS_TaskDelay(500);
|
||||
}
|
||||
}
|
||||
|
||||
static void GpioDriverTest(void)
|
||||
{
|
||||
TSK_INIT_PARAM_S taskInitParam = {0};
|
||||
|
||||
taskInitParam.pcName = "gpio_out_test";
|
||||
taskInitParam.pfnTaskEntry = GpioDriverOutTestTask;
|
||||
taskInitParam.stackAddr = 0;
|
||||
taskInitParam.uwStackSize = 4096;
|
||||
taskInitParam.usTaskPrio = 20;
|
||||
taskInitParam.uwArg = 0x66;
|
||||
uint32_t taskID;
|
||||
LOS_TaskCreate(&taskID, &taskInitParam);
|
||||
}
|
||||
|
||||
APP_FEATURE_INIT(GpioDriverTest);
|
||||
@@ -6,7 +6,7 @@
|
||||
ENTRY(_start)
|
||||
|
||||
STACK_SIZE = DEFINED(_stack_size) ? _stack_size : 0x4000;
|
||||
HEAP_SIZE = DEFINED(_heap_size) ? _heap_size : 0x10000;
|
||||
HEAP_SIZE = DEFINED(_heap_size) ? _heap_size : 0x40000;
|
||||
|
||||
MEMORY
|
||||
{
|
||||
@@ -50,11 +50,6 @@ SECTIONS
|
||||
*(.rodata*)
|
||||
*(.srodata)
|
||||
*(.srodata*)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
*(.hash)
|
||||
*(.dyn*)
|
||||
*(.gnu*)
|
||||
|
||||
Reference in New Issue
Block a user