mirror of
https://github.com/openharmony/device_soc_st.git
synced 2026-07-19 19:13:35 -04:00
add:hdf_adapter
Signed-off-by: TongFangJia <tongfangjia@h-partners.com>
This commit is contained in:
@@ -38,6 +38,9 @@ static_library("board_config") {
|
||||
"common:stm32_config",
|
||||
"driver:driver_config",
|
||||
]
|
||||
if (defined(DRIVERS_HDF)) {
|
||||
configs += [ "//drivers/hdf_core/adapter/khdf/uniproton:hdf_config" ]
|
||||
}
|
||||
}
|
||||
|
||||
group("board") {
|
||||
@@ -63,6 +66,10 @@ config("public") {
|
||||
"--specs=nosys.specs",
|
||||
]
|
||||
|
||||
if (defined(LOSCFG_DRIVERS_HDF_TESTS_ENABLE)) {
|
||||
include_dirs +=
|
||||
[ "//drivers/hdf_core/framework/core/common/include/manager" ]
|
||||
}
|
||||
product_cfg = read_file("${product_config_path}/config.json", "json")
|
||||
foreach(product_config, product_cfg.bin_list) {
|
||||
ldflags += [ "-Wl,--whole-archive" ]
|
||||
|
||||
@@ -28,22 +28,45 @@
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "lwip.h"
|
||||
#include "prt_task.h"
|
||||
#include "prt_config.h"
|
||||
|
||||
#ifndef DRIVERS_HDF
|
||||
#include "lwip/netif.h"
|
||||
#include "lwip.h"
|
||||
#endif
|
||||
|
||||
#include "securec.h"
|
||||
|
||||
#ifdef DRIVERS_HDF
|
||||
#include "devmgr_service_start.h"
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_DRIVERS_HDF_TESTS_ENABLE
|
||||
#include "file_test.h"
|
||||
#include "hdf_test_suit.h"
|
||||
#include "osal_all_test.h"
|
||||
#include "gpio_test.h"
|
||||
#include "i2c_test.h"
|
||||
#endif
|
||||
|
||||
#define BAUDRATE 115200
|
||||
#define DELAY_TIME 1000
|
||||
|
||||
#ifndef DRIVERS_HDF
|
||||
extern struct netif lwip_netif;
|
||||
#endif
|
||||
|
||||
extern unsigned long g_data_start;
|
||||
extern unsigned long g_data_end;
|
||||
extern unsigned long data_load_start;
|
||||
|
||||
extern void SystemInit(void);
|
||||
|
||||
#ifndef DRIVERS_HDF
|
||||
extern u8 LwipInit(void);
|
||||
#endif
|
||||
|
||||
extern S32 LfsLowLevelInit(void);
|
||||
extern void OHOS_SystemInit(void);
|
||||
|
||||
@@ -106,6 +129,18 @@ static void ShowTaskInfo(void)
|
||||
static void OsTskUser1(void)
|
||||
{
|
||||
printf("OsTskUser:\n\r");
|
||||
#ifdef LOSCFG_DRIVERS_HDF_TESTS_ENABLE
|
||||
OsaTestBegin();
|
||||
OsaTestEnd();
|
||||
OsaTestALLResult();
|
||||
HdfPlatformEntryTest();
|
||||
HdfPlatformDeviceTest();
|
||||
HdfPlatformDriverTest();
|
||||
HdfPlatformManagerTest();
|
||||
LfsTest();
|
||||
HdfI2cTestAllEntry();
|
||||
HdfGpioTestAllEntry();
|
||||
#endif
|
||||
while (TRUE) {
|
||||
printf("OsTskUser1 loop\n\r");
|
||||
printf("LWIP_DHCP = %d\n\r", LWIP_DHCP);
|
||||
@@ -167,8 +202,9 @@ void TestTask(void)
|
||||
if (ret != OS_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifndef DRIVERS_HDF
|
||||
ret = PRT_TaskResume(taskId2);
|
||||
#endif
|
||||
if (ret != OS_OK) {
|
||||
return ret;
|
||||
}
|
||||
@@ -177,11 +213,13 @@ void TestTask(void)
|
||||
U32 PRT_AppInit(void)
|
||||
{
|
||||
printf("PRT_AppInit!\n");
|
||||
|
||||
#ifdef DRIVERS_HDF
|
||||
DeviceManagerStart();
|
||||
#else
|
||||
FsInit();
|
||||
|
||||
LwipInit();
|
||||
|
||||
#endif
|
||||
OHOS_SystemInit();
|
||||
return OS_OK;
|
||||
}
|
||||
|
||||
@@ -108,7 +108,9 @@
|
||||
In this case, these drivers will not be included and the application code will
|
||||
be based on direct access to peripherals registers
|
||||
*/
|
||||
/*#define USE_STDPERIPH_DRIVER */
|
||||
#ifdef DRIVERS_HDF
|
||||
#define USE_STDPERIPH_DRIVER
|
||||
#endif
|
||||
#endif /* USE_STDPERIPH_DRIVER */
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
# Copyright (c) 2022 Huawei Device Co., Ltd. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
# are permitted provided that the following conditions are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
# conditions and the following disclaimer.
|
||||
#
|
||||
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
# of conditions and the following disclaimer in the documentation and/or other materials
|
||||
# provided with the distribution.
|
||||
#
|
||||
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
# to endorse or promote products derived from this software without specific prior written
|
||||
# permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
import("//drivers/hdf_core/adapter/khdf/uniproton/hdf.gni")
|
||||
|
||||
macro_switch = defined(LOSCFG_DRIVERS_HDF_CONFIG_MACRO)
|
||||
|
||||
module_name = get_path_info(rebase_path("."), "name")
|
||||
|
||||
config("public") {
|
||||
include_dirs = [ "$target_gen_dir" ]
|
||||
}
|
||||
|
||||
hdf_driver(module_name) {
|
||||
hcs_sources = [ "default.hcs" ]
|
||||
special_visibility = [ "//device/soc/st/stm32f407zg/uniproton/board/*" ]
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
#include "default_device_info.hcs"
|
||||
|
||||
root {
|
||||
platform {
|
||||
gpio_config {
|
||||
match_attr = "gpio_config";
|
||||
pin = [0, 1, 2, 3, 4, 5, 6, 7, 8]; // pin index when register to hdf framework 0-3 spi flash gpio 4-5 uart1 7-8 i2c test
|
||||
realPin = [9, 10, 8, 2, 3, 4, 0, 8, 9]; // pin number in stm32 led2 pe5, led3 pe6,
|
||||
group = [5, 5, 5, 4, 4, 4, 0, 1, 1]; // group of gpio 0:GPIOA 1:GPIOB 2:GPIOC 3:GPIOD 4:GPIOE 5:GPIOF 6:GPIOG 7:GPIOH 8:GPIOI
|
||||
mode = [1, 1, 1, 0, 0, 0, 0, 2, 2]; // 0: input 1: output 2:alternate 3:analog
|
||||
speed = [3, 3, 3, 3, 3, 3, 3, 3, 3]; // 0: low 1: middle 2:high 3:very_high
|
||||
type = [0, 0, 0, 0, 0, 0, 0, 1, 1]; // 0: pp 1:od
|
||||
pinNum = 9;
|
||||
pupd = [1, 1, 1, 1, 1, 1, 2, 0, 0]; // 0: nopull 1:up 2:down
|
||||
alternate = [0, 0, 0, 0, 0, 0, 0, 4, 4];
|
||||
}
|
||||
i2c_config {
|
||||
i2c1_config {
|
||||
match_attr = "i2c1_config";
|
||||
port = 1;
|
||||
devMode = 0; //0 = master, 1 = slave
|
||||
devAddr = 0;
|
||||
speed = 100000;
|
||||
}
|
||||
}
|
||||
}
|
||||
misc {
|
||||
test_config {
|
||||
match_attr = "test_config";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
root {
|
||||
module = "alientek,stm32f407";
|
||||
device_info {
|
||||
match_attr = "hdf_manager";
|
||||
template host {
|
||||
hostName = "";
|
||||
priority = 100;
|
||||
template device {
|
||||
template deviceNode {
|
||||
policy = 0;
|
||||
priority = 100;
|
||||
preload = 0;
|
||||
permission = 0664;
|
||||
moduleName = "";
|
||||
serviceName = "";
|
||||
deviceMatchAttr = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
platform :: host {
|
||||
hostName = "platform_host";
|
||||
priority = 50;
|
||||
device_gpio :: device {
|
||||
gpio0 :: deviceNode {
|
||||
policy = 0;
|
||||
priority = 60;
|
||||
moduleName = "ST_GPIO_MODULE_HDF";
|
||||
serviceName = "HDF_PLATFORM_GPIO";
|
||||
deviceMatchAttr = "gpio_config";
|
||||
}
|
||||
}
|
||||
device_i2c :: device {
|
||||
i2c_manager :: deviceNode {
|
||||
policy = 2;
|
||||
priority = 50;
|
||||
moduleName = "HDF_PLATFORM_I2C_MANAGER";
|
||||
serviceName = "HDF_PLATFORM_I2C_MANAGER";
|
||||
}
|
||||
|
||||
i2c1 :: deviceNode {
|
||||
policy = 0;
|
||||
priority = 100;
|
||||
moduleName = "ST_I2C_MODULE_HDF";
|
||||
serviceName = "HDF_PLATFORM_I2C_1";
|
||||
deviceMatchAttr = "i2c1_config";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
misc :: host {
|
||||
hostName = "misc_host";
|
||||
priority = 100;
|
||||
fs :: device {
|
||||
littlefs :: deviceNode {
|
||||
policy = 0;
|
||||
priority = 100;
|
||||
moduleName = "HDF_FS_LITTLEFS";
|
||||
deviceMatchAttr = "littlefs_config";
|
||||
}
|
||||
}
|
||||
ethernet :: device {
|
||||
ethernet0 :: deviceNode {
|
||||
policy = 0;
|
||||
priority = 60;//priority优先级越低的越先被加载
|
||||
moduleName = "HDF_NET_ETHERNET";
|
||||
deviceMatchAttr = "ethernet_config";
|
||||
}
|
||||
}
|
||||
test :: device {
|
||||
test0 :: deviceNode {
|
||||
policy = 0;
|
||||
priority = 30;//priority优先级越低的越先被加载
|
||||
moduleName = "PLATFORM_TEST_DRIVER";
|
||||
deviceMatchAttr = "test_config";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
# Copyright (c) 2022 Huawei Device Co., Ltd. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
# are permitted provided that the following conditions are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
# conditions and the following disclaimer.
|
||||
#
|
||||
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
# of conditions and the following disclaimer in the documentation and/or other materials
|
||||
# provided with the distribution.
|
||||
#
|
||||
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
# to endorse or promote products derived from this software without specific prior written
|
||||
# permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
import("//drivers/hdf_core/adapter/khdf/uniproton/hdf.gni")
|
||||
|
||||
module_switch = defined(LOSCFG_DRIVERS_HDF_PLATFORM_GPIO)
|
||||
module_name = get_path_info(rebase_path("."), "name")
|
||||
|
||||
hdf_driver(module_name) {
|
||||
sources = [
|
||||
"src/ethernet_init.c",
|
||||
"src/fs_init.c",
|
||||
"src/gpio_stm32f407.c",
|
||||
"src/i2c_stm32f407.c",
|
||||
]
|
||||
|
||||
include_dirs = [
|
||||
"include",
|
||||
"//device/soc/st/stm32f407zg/uniproton/board/common",
|
||||
]
|
||||
|
||||
deps = [ "//device/soc/st/stm32f407zg/uniproton/board/hdf_config" ]
|
||||
configs += [
|
||||
"//device/soc/st/stm32f407zg/uniproton/board/common:stm32_config",
|
||||
"//device/soc/st/stm32f407zg/uniproton/board/lwip:lwip_config",
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2022 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef __HAL_GPIO_H
|
||||
#define __HAL_GPIO_H
|
||||
|
||||
#include "stm32f4xx.h"
|
||||
#include "stm32f4xx_gpio.h"
|
||||
#include "stm32f4xx_rcc.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
STM32_GPIO_PIN_0 = 0, /* Pin 0 selected */
|
||||
STM32_GPIO_PIN_1, /* Pin 1 selected */
|
||||
STM32_GPIO_PIN_2, /* Pin 2 selected */
|
||||
STM32_GPIO_PIN_3, /* Pin 3 selected */
|
||||
STM32_GPIO_PIN_4, /* Pin 4 selected */
|
||||
STM32_GPIO_PIN_5, /* Pin 5 selected */
|
||||
STM32_GPIO_PIN_6, /* Pin 6 selected */
|
||||
STM32_GPIO_PIN_7, /* Pin 7 selected */
|
||||
STM32_GPIO_PIN_8, /* Pin 8 selected */
|
||||
STM32_GPIO_PIN_9, /* Pin 9 selected */
|
||||
STM32_GPIO_PIN_10, /* Pin 10 selected */
|
||||
STM32_GPIO_PIN_11, /* Pin 11 selected */
|
||||
STM32_GPIO_PIN_12, /* Pin 12 selected */
|
||||
STM32_GPIO_PIN_13, /* Pin 13 selected */
|
||||
STM32_GPIO_PIN_14, /* Pin 14 selected */
|
||||
STM32_GPIO_PIN_15, /* Pin 15 selected */
|
||||
STM32_GPIO_PIN_MAX, /* Pin Max */
|
||||
} STM32_GPIO_PIN;
|
||||
|
||||
typedef enum {
|
||||
STM32_GPIO_GROUP_A = 0,
|
||||
STM32_GPIO_GROUP_B,
|
||||
STM32_GPIO_GROUP_C,
|
||||
STM32_GPIO_GROUP_D,
|
||||
STM32_GPIO_GROUP_E,
|
||||
STM32_GPIO_GROUP_F,
|
||||
STM32_GPIO_GROUP_G,
|
||||
STM32_GPIO_GROUP_H,
|
||||
STM32_GPIO_GROUP_I,
|
||||
STM32_GPIO_GROUP_MAX,
|
||||
} STM32_GPIO_GROUP;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __HAL_GPIO_H */
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2022 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "hdf_device_desc.h"
|
||||
#include "lwip.h"
|
||||
|
||||
static int32_t EthernetInit(struct HdfDeviceObject *deviceObject)
|
||||
{
|
||||
return LwipInit();
|
||||
}
|
||||
|
||||
static void EthernetRelease(struct HdfDeviceObject *device)
|
||||
{
|
||||
(void)device;
|
||||
}
|
||||
|
||||
static struct HdfDriverEntry g_ethDriverEntry = {
|
||||
.moduleVersion = 1,
|
||||
.moduleName = "HDF_NET_ETHERNET",
|
||||
.Init = EthernetInit,
|
||||
.Release = EthernetRelease,
|
||||
};
|
||||
HDF_INIT(g_ethDriverEntry);
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2022 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "hdf_device_desc.h"
|
||||
|
||||
static int32_t FsDriverInit(struct HdfDeviceObject *object)
|
||||
{
|
||||
return FsInit();
|
||||
}
|
||||
|
||||
static void FsDriverRelease(struct HdfDeviceObject *device)
|
||||
{
|
||||
(void)device;
|
||||
}
|
||||
|
||||
static struct HdfDriverEntry g_fsDriverEntry = {
|
||||
.moduleVersion = 1,
|
||||
.moduleName = "HDF_FS_LITTLEFS",
|
||||
.Init = FsDriverInit,
|
||||
.Release = FsDriverRelease,
|
||||
};
|
||||
|
||||
HDF_INIT(g_fsDriverEntry);
|
||||
@@ -0,0 +1,550 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2022 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "hal_gpio.h"
|
||||
#include "hcs_macro.h"
|
||||
#include "hdf_config_macro.h"
|
||||
#include "gpio_core.h"
|
||||
#include "hdf_log.h"
|
||||
#include "prt_hwi.h"
|
||||
#include "os_cpu_armv7_m_external.h"
|
||||
#include "stm32f4xx_exti.h"
|
||||
#include "stm32f4xx_syscfg.h"
|
||||
|
||||
#define HDF_LOG_TAG gpio_stm_c
|
||||
|
||||
static EXTI_InitTypeDef g_gpioExitCfg[STM32_GPIO_PIN_MAX * STM32_GPIO_GROUP_MAX] = {0};
|
||||
static const uint16_t g_stmRealPinMaps[STM32_GPIO_PIN_MAX] = {
|
||||
GPIO_Pin_0,
|
||||
GPIO_Pin_1,
|
||||
GPIO_Pin_2,
|
||||
GPIO_Pin_3,
|
||||
GPIO_Pin_4,
|
||||
GPIO_Pin_5,
|
||||
GPIO_Pin_6,
|
||||
GPIO_Pin_7,
|
||||
GPIO_Pin_8,
|
||||
GPIO_Pin_9,
|
||||
GPIO_Pin_10,
|
||||
GPIO_Pin_11,
|
||||
GPIO_Pin_12,
|
||||
GPIO_Pin_13,
|
||||
GPIO_Pin_14,
|
||||
GPIO_Pin_15,
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
uint32_t group;
|
||||
uint32_t realPin;
|
||||
uint32_t pin;
|
||||
uint32_t mode;
|
||||
} GpioInflectInfo;
|
||||
|
||||
GpioInflectInfo g_gpioPinsMap[STM32_GPIO_PIN_MAX * STM32_GPIO_GROUP_MAX] = {0};
|
||||
|
||||
static GPIO_TypeDef *g_gpioxMaps[STM32_GPIO_GROUP_MAX] = {
|
||||
GPIOA,
|
||||
GPIOB,
|
||||
GPIOC,
|
||||
GPIOD,
|
||||
GPIOE,
|
||||
GPIOF,
|
||||
GPIOG,
|
||||
GPIOH,
|
||||
GPIOI,
|
||||
};
|
||||
#define EXTI_GROUP_MAX 11
|
||||
static const uint8_t g_extiGpioxMaps[EXTI_GROUP_MAX] = {
|
||||
EXTI_PortSourceGPIOA,
|
||||
EXTI_PortSourceGPIOB,
|
||||
EXTI_PortSourceGPIOC,
|
||||
EXTI_PortSourceGPIOD,
|
||||
EXTI_PortSourceGPIOE,
|
||||
EXTI_PortSourceGPIOF,
|
||||
EXTI_PortSourceGPIOG,
|
||||
EXTI_PortSourceGPIOH,
|
||||
EXTI_PortSourceGPIOI,
|
||||
EXTI_PortSourceGPIOJ,
|
||||
EXTI_PortSourceGPIOK,
|
||||
};
|
||||
#define EXTI_PINSOURCE_MAX 16
|
||||
static const uint8_t g_extiPinSourceMaps[EXTI_PINSOURCE_MAX] = {
|
||||
EXTI_PinSource0,
|
||||
EXTI_PinSource1,
|
||||
EXTI_PinSource2,
|
||||
EXTI_PinSource3,
|
||||
EXTI_PinSource4,
|
||||
EXTI_PinSource5,
|
||||
EXTI_PinSource6,
|
||||
EXTI_PinSource7,
|
||||
EXTI_PinSource8,
|
||||
EXTI_PinSource9,
|
||||
EXTI_PinSource10,
|
||||
EXTI_PinSource11,
|
||||
EXTI_PinSource12,
|
||||
EXTI_PinSource13,
|
||||
EXTI_PinSource14,
|
||||
EXTI_PinSource15,
|
||||
};
|
||||
#define EXTI_LINE_MAX 16
|
||||
static const uint32_t g_extiLineMaps[EXTI_LINE_MAX] = {
|
||||
EXTI_Line0,
|
||||
EXTI_Line1,
|
||||
EXTI_Line2,
|
||||
EXTI_Line3,
|
||||
EXTI_Line4,
|
||||
EXTI_Line5,
|
||||
EXTI_Line6,
|
||||
EXTI_Line7,
|
||||
EXTI_Line8,
|
||||
EXTI_Line9,
|
||||
EXTI_Line10,
|
||||
EXTI_Line11,
|
||||
EXTI_Line12,
|
||||
EXTI_Line13,
|
||||
EXTI_Line14,
|
||||
EXTI_Line15,
|
||||
};
|
||||
#define NVIC_IRQ_CHANNEL_MAX 5
|
||||
static const int32_t g_nvicIrqChannel[NVIC_IRQ_CHANNEL_MAX] = {
|
||||
EXTI0_IRQn,
|
||||
EXTI1_IRQn,
|
||||
EXTI2_IRQn,
|
||||
EXTI3_IRQn,
|
||||
EXTI4_IRQn,
|
||||
};
|
||||
EXTI_InitTypeDef g_extiInitStructure;
|
||||
typedef struct {
|
||||
uint32_t realPin;
|
||||
uint32_t group;
|
||||
uint32_t pin;
|
||||
uint32_t mode;
|
||||
uint32_t speed;
|
||||
uint32_t type;
|
||||
uint32_t pupd;
|
||||
uint32_t alternate;
|
||||
} GpioResource;
|
||||
|
||||
enum GpioDeviceState {
|
||||
GPIO_DEVICE_UNINITIALIZED = 0x0u,
|
||||
GPIO_DEVICE_INITIALIZED = 0x1u,
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
uint32_t pinNums;
|
||||
GpioResource resource;
|
||||
STM32_GPIO_GROUP group; /* gpio config */
|
||||
} GpioDevice;
|
||||
|
||||
/* GpioMethod method definitions */
|
||||
static int32_t GpioDevWrite(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t val);
|
||||
static int32_t GpioDevRead(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t *val);
|
||||
static int32_t GpioDevSetDir(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t dir);
|
||||
static int32_t GpioDevGetDir(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t *dir);
|
||||
static int32_t GpioDevSetIrq(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t mode);
|
||||
static int32_t GpioDevUnSetIrq(struct GpioCntlr *cntlr, uint16_t gpio);
|
||||
static int32_t GpioDevEnableIrq(struct GpioCntlr *cntlr, uint16_t gpio);
|
||||
static int32_t GpioDevDisableIrq(struct GpioCntlr *cntlr, uint16_t gpio);
|
||||
static int32_t AttachGpioDevice(struct GpioCntlr *gpioCntlr, struct HdfDeviceObject *device);
|
||||
|
||||
/* GpioMethod definitions */
|
||||
struct GpioMethod g_GpioCntlrMethod = {
|
||||
.request = NULL,
|
||||
.release = NULL,
|
||||
.write = GpioDevWrite,
|
||||
.read = GpioDevRead,
|
||||
.setDir = GpioDevSetDir,
|
||||
.getDir = GpioDevGetDir,
|
||||
.toIrq = NULL,
|
||||
.setIrq = GpioDevSetIrq,
|
||||
.unsetIrq = GpioDevUnSetIrq,
|
||||
.enableIrq = GpioDevEnableIrq,
|
||||
.disableIrq = GpioDevDisableIrq,
|
||||
};
|
||||
|
||||
static struct GpioCntlr g_stmGpioCntlr;
|
||||
|
||||
static int32_t GpioDevWrite(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t val)
|
||||
{
|
||||
uint16_t realPin = g_gpioPinsMap[gpio].realPin;
|
||||
uint32_t pinReg = g_stmRealPinMaps[realPin];
|
||||
if (pinReg > GPIO_Pin_15 || pinReg < GPIO_Pin_0) {
|
||||
HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, realPin);
|
||||
return HDF_ERR_NOT_SUPPORT;
|
||||
}
|
||||
HDF_LOGI("%s %d ,write pin num %d", __func__, __LINE__, realPin);
|
||||
HDF_LOGI("pingReg is %d", pinReg);
|
||||
GPIO_TypeDef *gpiox = g_gpioxMaps[g_gpioPinsMap[gpio].group];
|
||||
if (val) {
|
||||
GPIO_SetBits(gpiox, pinReg);
|
||||
} else {
|
||||
GPIO_ResetBits(gpiox, pinReg);
|
||||
}
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static void OemGpioIrqHdl(uint32_t pin)
|
||||
{
|
||||
HDF_LOGI("Gpio irq pin : %d\r\n", pin);
|
||||
GpioCntlrIrqCallback(&g_stmGpioCntlr, pin);
|
||||
return;
|
||||
}
|
||||
|
||||
static int32_t GpioDevRead(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t *val)
|
||||
{
|
||||
HDF_LOGI("entering GpioDevRead.\r\n");
|
||||
uint16_t realPin = g_gpioPinsMap[gpio].realPin;
|
||||
uint32_t pinReg = g_stmRealPinMaps[realPin];
|
||||
uint16_t value = 0;
|
||||
if (pinReg > GPIO_Pin_15 || pinReg < GPIO_Pin_0) {
|
||||
HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, realPin);
|
||||
return HDF_ERR_NOT_SUPPORT;
|
||||
}
|
||||
HDF_LOGI("%s %d ,read pin num %d", __func__, __LINE__, realPin);
|
||||
HDF_LOGI("pingReg is %d", pinReg);
|
||||
GPIO_TypeDef *gpiox = g_gpioxMaps[g_gpioPinsMap[gpio].group];
|
||||
value = GPIO_ReadInputDataBit(gpiox, pinReg);
|
||||
*val = value;
|
||||
HDF_LOGI("read value is %d", value);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
/* HdfDriverEntry method definitions */
|
||||
static int32_t GpioDriverInit(struct HdfDeviceObject *device);
|
||||
static void GpioDriverRelease(struct HdfDeviceObject *device);
|
||||
|
||||
/* HdfDriverEntry definitions */
|
||||
struct HdfDriverEntry g_GpioDriverEntry = {
|
||||
.moduleVersion = 1,
|
||||
.moduleName = "ST_GPIO_MODULE_HDF",
|
||||
.Init = GpioDriverInit,
|
||||
.Release = GpioDriverRelease,
|
||||
};
|
||||
HDF_INIT(g_GpioDriverEntry);
|
||||
|
||||
static void InitGpioClock(STM32_GPIO_GROUP group)
|
||||
{
|
||||
switch (group) {
|
||||
case STM32_GPIO_GROUP_A:
|
||||
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
|
||||
break;
|
||||
case STM32_GPIO_GROUP_B:
|
||||
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
|
||||
break;
|
||||
case STM32_GPIO_GROUP_C:
|
||||
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
|
||||
break;
|
||||
case STM32_GPIO_GROUP_D:
|
||||
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
|
||||
break;
|
||||
case STM32_GPIO_GROUP_E:
|
||||
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE, ENABLE);
|
||||
break;
|
||||
case STM32_GPIO_GROUP_F:
|
||||
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF, ENABLE);
|
||||
break;
|
||||
case STM32_GPIO_GROUP_G:
|
||||
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOG, ENABLE);
|
||||
break;
|
||||
case STM32_GPIO_GROUP_H:
|
||||
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOH, ENABLE);
|
||||
break;
|
||||
case STM32_GPIO_GROUP_I:
|
||||
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOI, ENABLE);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t InitGpioDevice(GpioDevice *device)
|
||||
{
|
||||
GPIO_InitTypeDef gpioInitStruct = {0};
|
||||
|
||||
if (device == NULL) {
|
||||
HDF_LOGE("%s: device is NULL", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
uint32_t halGpio = g_stmRealPinMaps[device->resource.realPin];
|
||||
if (halGpio > GPIO_Pin_15 || halGpio < GPIO_Pin_0) {
|
||||
HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, halGpio);
|
||||
return HDF_ERR_NOT_SUPPORT;
|
||||
}
|
||||
/* init clock */
|
||||
InitGpioClock(device->resource.group);
|
||||
|
||||
GPIO_TypeDef *goiox = g_gpioxMaps[device->resource.group];
|
||||
|
||||
if (device->resource.mode == GPIO_Mode_AF) {
|
||||
GPIO_PinAFConfig(goiox, device->resource.realPin, device->resource.alternate);
|
||||
}
|
||||
|
||||
gpioInitStruct.GPIO_Pin = halGpio;
|
||||
gpioInitStruct.GPIO_Mode = device->resource.mode;
|
||||
gpioInitStruct.GPIO_PuPd = device->resource.pupd;
|
||||
gpioInitStruct.GPIO_Speed = device->resource.speed;
|
||||
gpioInitStruct.GPIO_OType = device->resource.type;
|
||||
|
||||
GPIO_Init(goiox, &gpioInitStruct);
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
#define PLATFORM_GPIO_CONFIG HCS_NODE(HCS_NODE(HCS_ROOT, platform), gpio_config)
|
||||
static uint32_t GetGpioDeviceResource(GpioDevice *device)
|
||||
{
|
||||
if (device == NULL) {
|
||||
HDF_LOGE("%s: device is NULL", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
GpioResource *resource = &device->resource;
|
||||
if (resource == NULL) {
|
||||
HDF_LOGE("%s: resource is NULL", __func__);
|
||||
return HDF_ERR_INVALID_OBJECT;
|
||||
}
|
||||
device->pinNums = HCS_PROP(PLATFORM_GPIO_CONFIG, pinNum);
|
||||
uint32_t pins[] = HCS_ARRAYS(HCS_NODE(PLATFORM_GPIO_CONFIG, pin));
|
||||
uint32_t realPins[] = HCS_ARRAYS(HCS_NODE(PLATFORM_GPIO_CONFIG, realPin));
|
||||
uint32_t groups[] = HCS_ARRAYS(HCS_NODE(PLATFORM_GPIO_CONFIG, group));
|
||||
uint32_t modes[] = HCS_ARRAYS(HCS_NODE(PLATFORM_GPIO_CONFIG, mode));
|
||||
uint32_t speeds[] = HCS_ARRAYS(HCS_NODE(PLATFORM_GPIO_CONFIG, speed));
|
||||
uint32_t Types[] = HCS_ARRAYS(HCS_NODE(PLATFORM_GPIO_CONFIG, type));
|
||||
uint32_t pupds[] = HCS_ARRAYS(HCS_NODE(PLATFORM_GPIO_CONFIG, pupd));
|
||||
uint32_t alternate[] = HCS_ARRAYS(HCS_NODE(PLATFORM_GPIO_CONFIG, alternate));
|
||||
|
||||
for (size_t i = 0; i < device->pinNums; i++) {
|
||||
resource->pin = pins[i];
|
||||
resource->realPin = realPins[i];
|
||||
resource->group = groups[i];
|
||||
resource->mode = modes[i];
|
||||
resource->speed = speeds[i];
|
||||
resource->type = Types[i];
|
||||
resource->pupd = pupds[i];
|
||||
resource->alternate = alternate[i];
|
||||
|
||||
g_gpioPinsMap[resource->pin].group = resource->group;
|
||||
g_gpioPinsMap[resource->pin].realPin = resource->realPin;
|
||||
g_gpioPinsMap[resource->pin].pin = resource->pin;
|
||||
g_gpioPinsMap[resource->pin].mode = resource->mode;
|
||||
|
||||
if (InitGpioDevice(device) != HDF_SUCCESS) {
|
||||
HDF_LOGE("InitGpioDevice FAIL\r\n");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t AttachGpioDevice(struct GpioCntlr *gpioCntlr, struct HdfDeviceObject *device)
|
||||
{
|
||||
int32_t ret;
|
||||
|
||||
GpioDevice *gpioDevice = NULL;
|
||||
if (device == NULL) {
|
||||
HDF_LOGE("%s: property is NULL", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
gpioDevice = (GpioDevice *)OsalMemAlloc(sizeof(GpioDevice));
|
||||
if (gpioDevice == NULL) {
|
||||
HDF_LOGE("%s: OsalMemAlloc gpioDevice error", __func__);
|
||||
return HDF_ERR_MALLOC_FAIL;
|
||||
}
|
||||
|
||||
ret = GetGpioDeviceResource(gpioDevice);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
(void)OsalMemFree(gpioDevice);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
gpioCntlr->priv = gpioDevice;
|
||||
gpioCntlr->count = gpioDevice->pinNums;
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t GpioDriverInit(struct HdfDeviceObject *device)
|
||||
{
|
||||
int32_t ret;
|
||||
struct GpioCntlr *gpioCntlr = NULL;
|
||||
|
||||
if (device == NULL) {
|
||||
HDF_LOGE("%s: device is NULL", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
ret = PlatformDeviceBind(&g_stmGpioCntlr.device, device);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: bind hdf device failed:%d", __func__, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
gpioCntlr = GpioCntlrFromHdfDev(device);
|
||||
if (gpioCntlr == NULL) {
|
||||
HDF_LOGE("GpioCntlrFromHdfDev fail\r\n");
|
||||
return HDF_DEV_ERR_NO_DEVICE_SERVICE;
|
||||
}
|
||||
|
||||
ret = AttachGpioDevice(gpioCntlr, device); /* GpioCntlr add GpioDevice to priv */
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("AttachGpioDevice fail\r\n");
|
||||
return HDF_DEV_ERR_ATTACHDEV_FAIL;
|
||||
}
|
||||
|
||||
gpioCntlr->ops = &g_GpioCntlrMethod; /* register callback */
|
||||
|
||||
ret = GpioCntlrAdd(gpioCntlr);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("GpioCntlrAdd fail %d\r\n", gpioCntlr->start);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static void GpioDriverRelease(struct HdfDeviceObject *device)
|
||||
{
|
||||
struct GpioCntlr *gpioCntlr = NULL;
|
||||
|
||||
if (device == NULL) {
|
||||
HDF_LOGE("%s: device is NULL", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
gpioCntlr = GpioCntlrFromHdfDev(device);
|
||||
if (gpioCntlr == NULL) {
|
||||
HDF_LOGE("%s: host is NULL", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
gpioCntlr->count = 0;
|
||||
}
|
||||
|
||||
static int32_t GpioDevSetDir(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t dir)
|
||||
{
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t GpioDevGetDir(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t *dir)
|
||||
{
|
||||
(void)cntlr;
|
||||
uint16_t realPin = g_gpioPinsMap[gpio].realPin;
|
||||
uint32_t pinReg = g_stmRealPinMaps[realPin];
|
||||
if (pinReg > GPIO_Pin_15 || pinReg < GPIO_Pin_0) {
|
||||
HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, realPin);
|
||||
return HDF_ERR_NOT_SUPPORT;
|
||||
}
|
||||
|
||||
*dir = g_gpioPinsMap[gpio].mode;
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t GpioDevSetIrq(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t mode)
|
||||
{
|
||||
(void)cntlr;
|
||||
uint16_t realPin = g_gpioPinsMap[gpio].realPin;
|
||||
uint32_t pinReg = g_stmRealPinMaps[realPin];
|
||||
if (pinReg > GPIO_Pin_15 || pinReg < GPIO_Pin_0) {
|
||||
HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, realPin);
|
||||
return HDF_ERR_NOT_SUPPORT;
|
||||
}
|
||||
|
||||
if (mode == EXTI_Trigger_Rising) {
|
||||
g_gpioExitCfg[gpio].EXTI_Trigger = EXTI_Trigger_Rising;
|
||||
} else if (mode == EXTI_Trigger_Falling) {
|
||||
g_gpioExitCfg[gpio].EXTI_Trigger = EXTI_Trigger_Falling;
|
||||
} else {
|
||||
HDF_LOGE("%s %d, error mode:%d", __func__, __LINE__, mode);
|
||||
return HDF_ERR_NOT_SUPPORT;
|
||||
}
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t GpioDevUnSetIrq(struct GpioCntlr *cntlr, uint16_t gpio)
|
||||
{
|
||||
(void)cntlr;
|
||||
uint16_t realPin = g_gpioPinsMap[gpio].realPin;
|
||||
uint32_t pinReg = g_stmRealPinMaps[realPin];
|
||||
if (pinReg > GPIO_Pin_15 || pinReg < GPIO_Pin_0) {
|
||||
HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, realPin);
|
||||
return HDF_ERR_NOT_SUPPORT;
|
||||
}
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t GpioDevEnableIrq(struct GpioCntlr *cntlr, uint16_t gpio)
|
||||
{
|
||||
uintptr_t intSave;
|
||||
(void)cntlr;
|
||||
EXTI_InitTypeDef exitInitConfig = {0};
|
||||
uint16_t realPin = g_gpioPinsMap[gpio].realPin;
|
||||
uint32_t pinReg = g_stmRealPinMaps[realPin];
|
||||
if (pinReg > GPIO_Pin_15 || pinReg < GPIO_Pin_0) {
|
||||
HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, realPin);
|
||||
return HDF_ERR_NOT_SUPPORT;
|
||||
}
|
||||
SYSCFG_EXTILineConfig(g_extiGpioxMaps[g_gpioPinsMap[gpio].group], g_extiPinSourceMaps[realPin]);
|
||||
exitInitConfig.EXTI_Line = g_extiLineMaps[realPin];
|
||||
exitInitConfig.EXTI_Mode = EXTI_Mode_Interrupt;
|
||||
exitInitConfig.EXTI_Trigger = g_gpioExitCfg[gpio].EXTI_Trigger;
|
||||
exitInitConfig.EXTI_LineCmd = ENABLE;
|
||||
EXTI_Init(&exitInitConfig);
|
||||
if (pinReg > GPIO_Pin_4) {
|
||||
HDF_LOGE("%s %d, this pin out of range can not be set to irq mode.\r\n", __func__, __LINE__);
|
||||
return HDF_ERR_NOT_SUPPORT;
|
||||
}
|
||||
intSave = PRT_HwiSetAttr(g_nvicIrqChannel[realPin], OS_HWI_PRI_HIGHEST, OS_HWI_MODE_ENGROSS);
|
||||
if (intSave != OS_OK) {
|
||||
HDF_LOGE("%s %d, PRT_HwiSetAttr failed!!!\n\r", __func__, __LINE__);
|
||||
}
|
||||
intSave = PRT_HwiCreate(g_nvicIrqChannel[realPin], OemGpioIrqHdl, gpio);
|
||||
if (intSave != OS_OK) {
|
||||
HDF_LOGE("%s %d, PRT_HwiCreate failed!!!\n\r", __func__, __LINE__);
|
||||
}
|
||||
PRT_HwiEnable(g_nvicIrqChannel[realPin]);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t GpioDevDisableIrq(struct GpioCntlr *cntlr, uint16_t gpio)
|
||||
{
|
||||
uint16_t realPin = g_gpioPinsMap[gpio].realPin;
|
||||
uint32_t pinReg = g_stmRealPinMaps[realPin];
|
||||
if (pinReg > GPIO_Pin_15 || pinReg < GPIO_Pin_0) {
|
||||
HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, realPin);
|
||||
return HDF_ERR_NOT_SUPPORT;
|
||||
}
|
||||
PRT_HwiDisable(g_nvicIrqChannel[realPin]);
|
||||
PRT_HwiDelete(g_nvicIrqChannel[realPin]);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
@@ -0,0 +1,416 @@
|
||||
/*
|
||||
* Copyright (c) Huawei Technologies Co., Ltd. 2022-2022. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "hcs_macro.h"
|
||||
#include "hdf_config_macro.h"
|
||||
#include "hdf_device_desc.h"
|
||||
#include "hdf_log.h"
|
||||
#include "i2c_core.h"
|
||||
#include "i2c_if.h"
|
||||
#include "osal_mutex.h"
|
||||
#include "stm32f4xx_i2c.h"
|
||||
|
||||
#define HDF_LOG_TAG "hdf_i2c"
|
||||
|
||||
typedef enum {
|
||||
I2C_HANDLE_NULL = 0,
|
||||
I2C_HANDLE_1 = 1,
|
||||
I2C_HANDLE_2 = 2,
|
||||
I2C_HANDLE_3 = 3,
|
||||
I2C_HANDLE_MAX = I2C_HANDLE_3
|
||||
} I2C_HANDLE;
|
||||
|
||||
struct RealI2cResource {
|
||||
uint8_t port;
|
||||
uint8_t devMode;
|
||||
uint32_t devAddr;
|
||||
uint32_t speed;
|
||||
struct OsalMutex mutex;
|
||||
};
|
||||
|
||||
#define I2CT_FLAG_TIMEOUT ((uint32_t)0x1000)
|
||||
#define I2CT_LONG_TIMEOUT ((uint32_t)(10 * I2CT_FLAG_TIMEOUT))
|
||||
static uint32_t I2CTimeout = I2CT_LONG_TIMEOUT;
|
||||
|
||||
static int32_t I2C_TIMEOUT_UserCallback(void);
|
||||
|
||||
static bool g_I2cEnableFlg[I2C_HANDLE_MAX] = {0};
|
||||
|
||||
static void HdfI2cInit(I2C_HANDLE i2cx, unsigned int i2cRate, unsigned int addr);
|
||||
static int32_t HdfI2cWrite(I2C_HANDLE i2cx, unsigned char devAddr, const unsigned char *buf, unsigned int len);
|
||||
static int32_t HdfI2cRead(I2C_HANDLE i2cx, unsigned char devAddr, unsigned char *buf, unsigned int len);
|
||||
|
||||
static int32_t I2cDriverBind(struct HdfDeviceObject *device);
|
||||
static int32_t I2cDriverInit(struct HdfDeviceObject *device);
|
||||
static void I2cDriverRelease(struct HdfDeviceObject *device);
|
||||
static int32_t I2cDataTransfer(struct I2cCntlr *cntlr, struct I2cMsg *msgs, int16_t count);
|
||||
|
||||
struct HdfDriverEntry gI2cHdfDriverEntry = {
|
||||
.moduleVersion = 1,
|
||||
.moduleName = "ST_I2C_MODULE_HDF",
|
||||
.Bind = I2cDriverBind,
|
||||
.Init = I2cDriverInit,
|
||||
.Release = I2cDriverRelease,
|
||||
};
|
||||
HDF_INIT(gI2cHdfDriverEntry);
|
||||
|
||||
struct I2cMethod gI2cHostMethod = {
|
||||
.transfer = I2cDataTransfer,
|
||||
};
|
||||
|
||||
#define I2C_FIND_CONFIG(node, name, resource) \
|
||||
do { \
|
||||
if (strcmp(HCS_PROP(node, match_attr), name) == 0) { \
|
||||
(resource)->port = HCS_PROP(node, port); \
|
||||
(resource)->devMode = HCS_PROP(node, devMode); \
|
||||
(resource)->devAddr = HCS_PROP(node, devAddr); \
|
||||
(resource)->speed = HCS_PROP(node, speed); \
|
||||
result = HDF_SUCCESS; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define PLATFORM_I2C_CONFIG HCS_NODE(HCS_NODE(HCS_ROOT, platform), i2c_config)
|
||||
static uint32_t GetI2cDeviceResource(struct RealI2cResource *i2cResource, const char *deviceMatchAttr)
|
||||
{
|
||||
int32_t result = HDF_FAILURE;
|
||||
struct RealI2cResource *resource = NULL;
|
||||
if (i2cResource == NULL || deviceMatchAttr == NULL) {
|
||||
HDF_LOGE("device or deviceMatchAttr is NULL\r\n");
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
resource = i2cResource;
|
||||
#if HCS_NODE_HAS_PROP(HCS_NODE(HCS_ROOT, platform), i2c_config)
|
||||
HCS_FOREACH_CHILD_VARGS(PLATFORM_I2C_CONFIG, I2C_FIND_CONFIG, deviceMatchAttr, resource);
|
||||
#endif
|
||||
if (result != HDF_SUCCESS) {
|
||||
HDF_LOGE("resourceNode %s is NULL\r\n", deviceMatchAttr);
|
||||
} else {
|
||||
HdfI2cInit(i2cResource->port, i2cResource->speed, i2cResource->devAddr);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static int32_t AttachI2cDevice(struct I2cCntlr *host, const struct HdfDeviceObject *device)
|
||||
{
|
||||
int32_t ret = HDF_FAILURE;
|
||||
|
||||
if (host == NULL || device == NULL) {
|
||||
HDF_LOGE("[%s]: param is NULL\r\n", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
struct RealI2cResource *i2cResource = (struct RealI2cResource *)OsalMemAlloc(sizeof(struct RealI2cResource));
|
||||
if (i2cResource == NULL) {
|
||||
HDF_LOGE("[%s]: OsalMemAlloc RealI2cResource fail\r\n", __func__);
|
||||
return HDF_ERR_MALLOC_FAIL;
|
||||
}
|
||||
(void)memset_s(i2cResource, sizeof(struct RealI2cResource), 0, sizeof(struct RealI2cResource));
|
||||
|
||||
ret = GetI2cDeviceResource(i2cResource, device->deviceMatchAttr);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
OsalMemFree(i2cResource);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
host->busId = i2cResource->port;
|
||||
host->priv = i2cResource;
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t I2cDataTransfer(struct I2cCntlr *cntlr, struct I2cMsg *msgs, int16_t count)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (cntlr == NULL || msgs == NULL || cntlr->priv == NULL) {
|
||||
HDF_LOGE("[%s]: I2cDataTransfer param is NULL\r\n", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (count <= 0) {
|
||||
HDF_LOGE("[%s]: I2cDataTransfer count err\r\n", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
struct RealI2cResource *device = (struct I2cDevice *)cntlr->priv;
|
||||
struct I2cMsg *msg = NULL;
|
||||
if (HDF_SUCCESS != OsalMutexLock(&device->mutex)) {
|
||||
HDF_LOGE("[%s]: OsalMutexLock fail\r\n", __func__);
|
||||
return HDF_ERR_TIMEOUT;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < count; i++) {
|
||||
msg = &msgs[i];
|
||||
if (msg->flags == I2C_FLAG_READ) {
|
||||
ret = HdfI2cRead(device->port, msg->addr, msg->buf, msg->len);
|
||||
} else {
|
||||
ret = HdfI2cWrite(device->port, msg->addr, msg->buf, msg->len);
|
||||
}
|
||||
|
||||
if (ret != HDF_SUCCESS) {
|
||||
OsalMutexUnlock(&device->mutex);
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
OsalMutexUnlock(&device->mutex);
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
static int32_t I2cDriverBind(struct HdfDeviceObject *device)
|
||||
{
|
||||
if (device == NULL) {
|
||||
HDF_LOGE("[%s]: I2c device is NULL\r\n", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t I2cDriverInit(struct HdfDeviceObject *device)
|
||||
{
|
||||
int32_t ret = HDF_FAILURE;
|
||||
struct I2cCntlr *host = NULL;
|
||||
if (device == NULL) {
|
||||
HDF_LOGE("[%s]: I2c device is NULL\r\n", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
host = (struct I2cCntlr *)OsalMemAlloc(sizeof(struct I2cCntlr));
|
||||
if (host == NULL) {
|
||||
HDF_LOGE("[%s]: malloc host is NULL\r\n", __func__);
|
||||
return HDF_ERR_MALLOC_FAIL;
|
||||
}
|
||||
|
||||
(void)memset_s(host, sizeof(struct I2cCntlr), 0, sizeof(struct I2cCntlr));
|
||||
host->ops = &gI2cHostMethod;
|
||||
device->priv = (void *)host;
|
||||
|
||||
ret = AttachI2cDevice(host, device);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("[%s]: AttachI2cDevice error, ret = %d\r\n", __func__, ret);
|
||||
I2cDriverRelease(device);
|
||||
return HDF_DEV_ERR_ATTACHDEV_FAIL;
|
||||
}
|
||||
|
||||
ret = I2cCntlrAdd(host);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
I2cDriverRelease(device);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static void I2cDriverRelease(struct HdfDeviceObject *device)
|
||||
{
|
||||
if (device == NULL) {
|
||||
HDF_LOGE("%s: device is NULL\r\n", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
struct I2cCntlr *i2cCntrl = device->priv;
|
||||
if (i2cCntrl == NULL || i2cCntrl->priv == NULL) {
|
||||
HDF_LOGE("%s: i2cCntrl is NULL\r\n", __func__);
|
||||
return;
|
||||
}
|
||||
i2cCntrl->ops = NULL;
|
||||
struct RealI2cResource *i2cDevice = (struct I2cDevice *)i2cCntrl->priv;
|
||||
OsalMemFree(i2cCntrl);
|
||||
|
||||
if (i2cDevice != NULL) {
|
||||
OsalMutexDestroy(&i2cDevice->mutex);
|
||||
OsalMemFree(i2cDevice);
|
||||
}
|
||||
}
|
||||
|
||||
static I2C_TypeDef *GetI2cHandlerMatch(I2C_HANDLE i2cx)
|
||||
{
|
||||
if (i2cx > I2C_HANDLE_MAX) {
|
||||
printf("ERR: GetLLI2cClkMatch fail, param match fail\r\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
switch (i2cx) {
|
||||
case I2C_HANDLE_1:
|
||||
return (I2C_TypeDef *)I2C1;
|
||||
case I2C_HANDLE_2:
|
||||
return (I2C_TypeDef *)I2C2;
|
||||
case I2C_HANDLE_3:
|
||||
return (I2C_TypeDef *)I2C3;
|
||||
default:
|
||||
printf("ERR: GetI2cClkMatch fail, handler match fail\r\n");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static bool EnableI2cClock(const I2C_TypeDef *i2cx)
|
||||
{
|
||||
if (i2cx == I2C1) {
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE);
|
||||
return true;
|
||||
} else if (i2cx == I2C2) {
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C2, ENABLE);
|
||||
return true;
|
||||
} else if (i2cx == I2C3) {
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C3, ENABLE);
|
||||
return true;
|
||||
} else {
|
||||
printf("EnableI2cClock fail, i2cx match fail\r\n");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static void HdfI2cInit(I2C_HANDLE i2cx, unsigned int i2cRate, unsigned int addr)
|
||||
{
|
||||
I2C_InitTypeDef I2C_InitStructure = {0};
|
||||
I2C_TypeDef *myI2c = GetI2cHandlerMatch(i2cx);
|
||||
if (myI2c == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
EnableI2cClock(myI2c);
|
||||
I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
|
||||
I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;
|
||||
I2C_InitStructure.I2C_OwnAddress1 = addr;
|
||||
I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
|
||||
I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
|
||||
I2C_InitStructure.I2C_ClockSpeed = i2cRate;
|
||||
I2C_Init(myI2c, &I2C_InitStructure);
|
||||
I2C_Cmd(myI2c, ENABLE);
|
||||
I2C_AcknowledgeConfig(myI2c, ENABLE);
|
||||
|
||||
g_I2cEnableFlg[i2cx] = true;
|
||||
}
|
||||
|
||||
static int32_t I2C_TIMEOUT_UserCallback(void)
|
||||
{
|
||||
/* Block communication and all processes */
|
||||
printf("I2C timeout!\r\n");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
static int32_t HdfI2cWrite(I2C_HANDLE i2cx, unsigned char devAddr, const unsigned char *buf, unsigned int len)
|
||||
{
|
||||
if (g_I2cEnableFlg[i2cx] != true) {
|
||||
printf("I2C_WriteByte err, Please initialize first!");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
I2C_TypeDef *myI2c = GetI2cHandlerMatch(i2cx);
|
||||
if (myI2c == NULL) {
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
I2CTimeout = I2CT_LONG_TIMEOUT;
|
||||
while (I2C_GetFlagStatus(myI2c, I2C_FLAG_BUSY) == SET) {
|
||||
if ((I2CTimeout--) == 0) return I2C_TIMEOUT_UserCallback();
|
||||
}
|
||||
|
||||
I2C_GenerateSTART(myI2c, ENABLE);
|
||||
|
||||
I2CTimeout = I2CT_FLAG_TIMEOUT;
|
||||
while (I2C_CheckEvent(myI2c, I2C_EVENT_MASTER_MODE_SELECT) == 0) {
|
||||
if ((I2CTimeout--) == 0) return I2C_TIMEOUT_UserCallback();
|
||||
}
|
||||
|
||||
I2C_Send7bitAddress(myI2c, devAddr, I2C_Direction_Transmitter);
|
||||
|
||||
I2CTimeout = I2CT_FLAG_TIMEOUT;
|
||||
while (I2C_CheckEvent(myI2c, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED) == 0) {
|
||||
if ((I2CTimeout--) == 0) return I2C_TIMEOUT_UserCallback();
|
||||
}
|
||||
|
||||
I2C_GetLastEvent(myI2c);
|
||||
|
||||
for (unsigned int i = 0; i < len; i++) {
|
||||
I2C_SendData(myI2c, buf[i]);
|
||||
|
||||
I2CTimeout = I2CT_FLAG_TIMEOUT;
|
||||
while (I2C_CheckEvent(myI2c, I2C_EVENT_MASTER_BYTE_TRANSMITTED) == 0) {
|
||||
if ((I2CTimeout--) == 0) return I2C_TIMEOUT_UserCallback();
|
||||
}
|
||||
}
|
||||
|
||||
I2C_GenerateSTOP(myI2c, ENABLE);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t HdfI2cRead(I2C_HANDLE i2cx, unsigned char devAddr, unsigned char *buf, unsigned int len)
|
||||
{
|
||||
if (g_I2cEnableFlg[i2cx] != true) {
|
||||
printf("I2C_ReadByte err, Please initialize first!");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
I2C_TypeDef *myI2c = GetI2cHandlerMatch(i2cx);
|
||||
if (myI2c == NULL) {
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
I2CTimeout = I2CT_LONG_TIMEOUT;
|
||||
|
||||
while (I2C_GetFlagStatus(myI2c, I2C_FLAG_BUSY) == SET) {
|
||||
if ((I2CTimeout--) == 0) return I2C_TIMEOUT_UserCallback();
|
||||
}
|
||||
|
||||
I2C_GenerateSTART(myI2c, ENABLE);
|
||||
|
||||
I2CTimeout = I2CT_FLAG_TIMEOUT;
|
||||
while (I2C_CheckEvent(myI2c, I2C_EVENT_MASTER_MODE_SELECT) == 0) {
|
||||
if ((I2CTimeout--) ==0) return I2C_TIMEOUT_UserCallback();
|
||||
}
|
||||
|
||||
I2C_Send7bitAddress(myI2c, devAddr, I2C_Direction_Receiver);
|
||||
|
||||
I2CTimeout = I2CT_FLAG_TIMEOUT;
|
||||
while (I2C_CheckEvent(myI2c, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED) == 0) {
|
||||
if ((I2CTimeout--) == 0) return I2C_TIMEOUT_UserCallback();
|
||||
}
|
||||
|
||||
for (unsigned int i = 0; i < len; i++) {
|
||||
if (i == len - 1) {
|
||||
I2C_AcknowledgeConfig(myI2c, DISABLE);
|
||||
I2C_GenerateSTOP(myI2c, ENABLE);
|
||||
}
|
||||
|
||||
I2CTimeout = I2CT_LONG_TIMEOUT;
|
||||
while (I2C_CheckEvent(myI2c, I2C_EVENT_MASTER_BYTE_RECEIVED) == 0) {
|
||||
if ((I2CTimeout--) == 0) return I2C_TIMEOUT_UserCallback();
|
||||
}
|
||||
|
||||
buf[i] = I2C_ReceiveData(myI2c);
|
||||
}
|
||||
|
||||
I2C_AcknowledgeConfig(myI2c, ENABLE);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
@@ -100,8 +100,13 @@ extern unsigned int __heap_size;
|
||||
#define OS_INCLUDE_SEM YES
|
||||
|
||||
/* 最大支持的信号量数 */
|
||||
#ifdef LOSCFG_DRIVERS_HDF_TESTS_ENABLE
|
||||
#define OS_SEM_MAX_SUPPORT_NUM 80
|
||||
#elif defined DRIVERS_HDF
|
||||
#define OS_SEM_MAX_SUPPORT_NUM 50
|
||||
#else
|
||||
#define OS_SEM_MAX_SUPPORT_NUM 20
|
||||
|
||||
#endif
|
||||
/* ***************************** 配置队列模块 ******************************* */
|
||||
/* 队列模块裁剪开关 */
|
||||
#define OS_INCLUDE_QUEUE YES
|
||||
|
||||
@@ -157,11 +157,15 @@ SECTIONS
|
||||
.data : {
|
||||
__data_start = . ;
|
||||
g_data_start = . ;
|
||||
KEEP (*(SORT_NONE(VECTOR)))
|
||||
|
||||
*(.data .data.* .gnu.linkonce.d.*)
|
||||
|
||||
. = ALIGN(0x80);
|
||||
KEEP (*(SORT_NONE(VECTOR)))
|
||||
. = ALIGN(0x4);
|
||||
_hdf_drivers_start = .;
|
||||
KEEP(*(.hdf.driver))
|
||||
_hdf_drivers_end = .; /* define a section for hdf driver */
|
||||
|
||||
__data_end = . ;
|
||||
g_data_end = . ;
|
||||
} > ram AT > flash
|
||||
|
||||
Reference in New Issue
Block a user