Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
rt-thread
提交
8ac935ae
R
rt-thread
项目概览
BaiXuePrincess
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rt-thread
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
8ac935ae
编写于
2月 16, 2021
作者:
Thomas_Fly
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add the driver of gpio
上级
c0f83308
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
233 addition
and
69 deletion
+233
-69
bsp/maxim/MAX32660_EVSYS/applications/application.c
bsp/maxim/MAX32660_EVSYS/applications/application.c
+0
-9
bsp/maxim/MAX32660_EVSYS/board/board.h
bsp/maxim/MAX32660_EVSYS/board/board.h
+4
-0
bsp/maxim/libraries/HAL_Drivers/drv_gpio.c
bsp/maxim/libraries/HAL_Drivers/drv_gpio.c
+208
-0
bsp/maxim/libraries/HAL_Drivers/drv_gpio.h
bsp/maxim/libraries/HAL_Drivers/drv_gpio.h
+21
-0
bsp/maxim/libraries/HAL_Drivers/drv_spi.c
bsp/maxim/libraries/HAL_Drivers/drv_spi.c
+0
-60
未找到文件。
bsp/maxim/MAX32660_EVSYS/applications/application.c
浏览文件 @
8ac935ae
...
...
@@ -11,22 +11,13 @@
#include <rtthread.h>
#include <rtdevice.h>
#include "gpio.h"
const
gpio_cfg_t
led_pin
[]
=
{
{
PORT_0
,
PIN_13
,
GPIO_FUNC_OUT
,
GPIO_PAD_NONE
},
};
int
main
(
void
)
{
int
count
=
1
;
GPIO_Config
(
&
led_pin
[
0
]);
GPIO_OutSet
(
&
led_pin
[
0
]);
while
(
count
++
)
{
rt_thread_mdelay
(
500
);
GPIO_OutToggle
(
&
led_pin
[
0
]);
}
return
RT_EOK
;
}
bsp/maxim/MAX32660_EVSYS/board/board.h
浏览文件 @
8ac935ae
...
...
@@ -14,6 +14,10 @@
#include <rtthread.h>
#include <rthw.h>
#include "mxc_config.h"
#include "mxc_assert.h"
#define MCU_FLASH_START_ADRESS ((uint32_t)0x0)
#define MCU_FLASH_SIZE_KB (256)
#define MCU_FLASH_END_ADDRESS ((uint32_t)(MCU_FLASH_START_ADRESS + MCU_FLASH_SIZE*1024))
...
...
bsp/maxim/libraries/HAL_Drivers/drv_gpio.c
0 → 100644
浏览文件 @
8ac935ae
/*
* Copyright (c) 2006-2020, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2021-02-11 supperthomas first version
*
*/
#include "drv_gpio.h"
#include <stdbool.h>
#include "gpio.h"
#ifdef RT_USING_PIN
#define DBG_LEVEL DBG_LOG
#include <rtdbg.h>
#define LOG_TAG "drv.gpio"
#define PIN_PORT_OFFSET 4
#define PIN_NUM(port, no) ((((((port) & 0xFu) << PIN_PORT_OFFSET) | ((no) & 0xFu)))
#define PIN_PORT(pin) ((uint8_t)(((pin) >> PIN_PORT_OFFSET) & 0xFu))
#define PIN_NO(pin) ((uint8_t)((pin) & 0xFu))
#define PIN_MCU_PORT(pin) PIN_PORT(pin)
#define PIN_MCU_PIN(pin) ((uint32_t)(1u << PIN_NO(pin)))
static
void
mcu_pin_write
(
rt_device_t
dev
,
rt_base_t
pin
,
rt_base_t
value
)
{
gpio_cfg_t
tmp_gpio_cfg
;
tmp_gpio_cfg
.
port
=
PIN_PORT
(
pin
);
tmp_gpio_cfg
.
mask
=
PIN_MCU_PIN
(
pin
);
if
(
value
)
{
GPIO_OutSet
(
&
tmp_gpio_cfg
);
}
else
{
GPIO_OutClr
(
&
tmp_gpio_cfg
);
}
}
static
int
mcu_pin_read
(
rt_device_t
dev
,
rt_base_t
pin
)
{
int
value
;
gpio_cfg_t
tmp_gpio_cfg
;
tmp_gpio_cfg
.
port
=
PIN_PORT
(
pin
);
tmp_gpio_cfg
.
mask
=
PIN_MCU_PIN
(
pin
);
if
(
GPIO_InGet
(
&
tmp_gpio_cfg
))
{
value
=
1
;
}
else
{
value
=
0
;
}
return
value
;
}
static
void
mcu_pin_mode
(
rt_device_t
dev
,
rt_base_t
pin
,
rt_base_t
mode
)
{
gpio_cfg_t
tmp_gpio_cfg
;
int
ret
=
0
;
tmp_gpio_cfg
.
port
=
PIN_PORT
(
pin
);
tmp_gpio_cfg
.
mask
=
PIN_MCU_PIN
(
pin
);
switch
(
mode
)
{
case
PIN_MODE_OUTPUT
:
tmp_gpio_cfg
.
func
=
GPIO_FUNC_OUT
;
tmp_gpio_cfg
.
pad
=
GPIO_PAD_NONE
;
break
;
case
PIN_MODE_INPUT
:
tmp_gpio_cfg
.
func
=
GPIO_FUNC_IN
;
tmp_gpio_cfg
.
pad
=
GPIO_PAD_NONE
;
break
;
case
PIN_MODE_INPUT_PULLUP
:
tmp_gpio_cfg
.
func
=
GPIO_FUNC_IN
;
tmp_gpio_cfg
.
pad
=
GPIO_PAD_PULL_UP
;
break
;
case
PIN_MODE_INPUT_PULLDOWN
:
tmp_gpio_cfg
.
func
=
GPIO_FUNC_IN
;
tmp_gpio_cfg
.
pad
=
GPIO_PAD_PULL_DOWN
;
break
;
case
PIN_MODE_OUTPUT_OD
:
//not support
LOG_E
(
"NOT SUPPORT"
);
break
;
}
ret
=
GPIO_Config
(
&
tmp_gpio_cfg
);
if
(
E_NO_ERROR
!=
ret
)
{
LOG_E
(
"GPIO_Config error :%d"
,
ret
);
}
}
static
rt_err_t
mcu_pin_attach_irq
(
struct
rt_device
*
device
,
rt_int32_t
pin
,
rt_uint32_t
irq_mode
,
void
(
*
hdr
)(
void
*
args
),
void
*
args
)
{
gpio_cfg_t
tmp_gpio_cfg
;
tmp_gpio_cfg
.
port
=
PIN_MCU_PORT
(
pin
);
tmp_gpio_cfg
.
mask
=
PIN_MCU_PIN
(
pin
);
tmp_gpio_cfg
.
pad
=
GPIO_PAD_PULL_UP
;
tmp_gpio_cfg
.
func
=
GPIO_FUNC_IN
;
GPIO_Config
(
&
tmp_gpio_cfg
);
GPIO_RegisterCallback
(
&
tmp_gpio_cfg
,
hdr
,
args
);
gpio_int_mode_t
mcu_mode
;
gpio_int_pol_t
mcu_pol
;
switch
(
irq_mode
)
{
case
PIN_IRQ_MODE_RISING
:
mcu_mode
=
GPIO_INT_EDGE
;
mcu_pol
=
GPIO_INT_RISING
;
break
;
case
PIN_IRQ_MODE_FALLING
:
mcu_mode
=
GPIO_INT_EDGE
;
mcu_pol
=
GPIO_INT_FALLING
;
break
;
case
PIN_IRQ_MODE_RISING_FALLING
:
mcu_mode
=
GPIO_INT_EDGE
;
mcu_pol
=
GPIO_INT_BOTH
;
break
;
case
PIN_IRQ_MODE_HIGH_LEVEL
:
mcu_mode
=
GPIO_INT_LEVEL
;
mcu_pol
=
GPIO_INT_HIGH
;
break
;
case
PIN_IRQ_MODE_LOW_LEVEL
:
mcu_mode
=
GPIO_INT_LEVEL
;
mcu_pol
=
GPIO_INT_LOW
;
break
;
}
GPIO_IntConfig
(
&
tmp_gpio_cfg
,
mcu_mode
,
mcu_pol
);
return
RT_EOK
;
}
static
rt_err_t
mcu_pin_dettach_irq
(
struct
rt_device
*
device
,
rt_int32_t
pin
)
{
gpio_cfg_t
tmp_gpio_cfg
;
tmp_gpio_cfg
.
port
=
PIN_MCU_PORT
(
pin
);
tmp_gpio_cfg
.
mask
=
PIN_MCU_PIN
(
pin
);
tmp_gpio_cfg
.
pad
=
GPIO_PAD_PULL_UP
;
tmp_gpio_cfg
.
func
=
GPIO_FUNC_IN
;
GPIO_Config
(
&
tmp_gpio_cfg
);
GPIO_IntDisable
(
&
tmp_gpio_cfg
);
GPIO_RegisterCallback
(
&
tmp_gpio_cfg
,
NULL
,
NULL
);
return
RT_EOK
;
}
static
rt_err_t
mcu_pin_irq_enable
(
struct
rt_device
*
device
,
rt_base_t
pin
,
rt_uint32_t
enabled
)
{
gpio_cfg_t
tmp_gpio_cfg
;
tmp_gpio_cfg
.
port
=
PIN_MCU_PORT
(
pin
);
tmp_gpio_cfg
.
mask
=
PIN_MCU_PIN
(
pin
);
if
(
enabled
)
{
GPIO_IntEnable
(
&
tmp_gpio_cfg
);
NVIC_EnableIRQ
((
IRQn_Type
)
MXC_GPIO_GET_IRQ
(
PIN_MCU_PORT
(
pin
)));
}
else
{
GPIO_IntDisable
(
&
tmp_gpio_cfg
);
NVIC_DisableIRQ
((
IRQn_Type
)
MXC_GPIO_GET_IRQ
(
PIN_MCU_PORT
(
pin
)));
}
return
RT_EOK
;
}
const
static
struct
rt_pin_ops
_mcu_pin_ops
=
{
mcu_pin_mode
,
mcu_pin_write
,
mcu_pin_read
,
mcu_pin_attach_irq
,
mcu_pin_dettach_irq
,
mcu_pin_irq_enable
,
NULL
,
};
int
rt_hw_pin_init
(
void
)
{
GPIO_Init
();
return
rt_device_pin_register
(
"pin"
,
&
_mcu_pin_ops
,
RT_NULL
);
}
INIT_BOARD_EXPORT
(
rt_hw_pin_init
);
void
GPIO0_IRQHandler
(
void
)
{
GPIO_Handler
(
PORT_0
);
}
#endif
/* RT_USING_PIN */
bsp/maxim/libraries/HAL_Drivers/drv_gpio.h
0 → 100644
浏览文件 @
8ac935ae
/*
* Copyright (c) 2006-2020, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2021-02-11 supperthomas first version
*
*/
#ifndef __DRV_GPIO_H__
#define __DRV_GPIO_H__
#include <board.h>
#include <rtdevice.h>
int
rt_hw_pin_init
(
void
);
#endif
/* __DRV_GPIO_H__ */
bsp/maxim/libraries/HAL_Drivers/drv_spi.c
浏览文件 @
8ac935ae
...
...
@@ -166,64 +166,4 @@ rt_err_t rt_hw_spi_device_attach(const char *bus_name, const char *device_name,
#endif
/* BSP_USING_SPI0 || BSP_USING_SPI1 || BSP_USING_SPI2 */
#endif
/*BSP_USING_SPI*/
#define SPI_DEVICE_BUS "spi0"
#define SPI_DEVICE_NAME "spi01"
#define TEST_LEN 10
uint8_t
rx_data
[
TEST_LEN
];
uint8_t
tx_data
[
TEST_LEN
];
static
void
spi_sample
(
int
argc
,
char
*
argv
[])
{
struct
rt_spi_device
*
spi_dev
;
char
name
[
RT_NAME_MAX
];
spi_dev
=
(
struct
rt_spi_device
*
)
rt_device_find
(
SPI_DEVICE_NAME
);
if
(
RT_NULL
==
spi_dev
)
{
rt_hw_spi_device_attach
(
SPI_DEVICE_BUS
,
SPI_DEVICE_NAME
,
PIN_0
);
spi_dev
=
(
struct
rt_spi_device
*
)
rt_device_find
(
SPI_DEVICE_NAME
);
}
struct
rt_spi_configuration
spi_cfg
=
{
.
mode
=
0
,
.
data_width
=
8
,
.
max_hz
=
1000000
,
};
rt_spi_configure
(
spi_dev
,
&
spi_cfg
);
rt_kprintf
(
"
\n
************** SPI Loopback Demo ****************
\n
"
);
rt_kprintf
(
"This example configures the SPI to send data between the MISO (P0.4) and
\n
"
);
rt_kprintf
(
"MOSI (P0.5) pins. Connect these two pins together.
\n
"
);
for
(
int
j
=
0
;
j
<
TEST_LEN
;
j
++
)
{
tx_data
[
j
]
=
j
;
}
if
(
argc
==
2
)
{
rt_strncpy
(
name
,
argv
[
1
],
RT_NAME_MAX
);
}
else
{
rt_strncpy
(
name
,
SPI_DEVICE_NAME
,
RT_NAME_MAX
);
}
/* ?? spi ???????? */
spi_dev
=
(
struct
rt_spi_device
*
)
rt_device_find
(
name
);
if
(
!
spi_dev
)
{
rt_kprintf
(
"spi sample run failed! can't find %s device!
\n
"
,
name
);
}
else
{
rt_spi_transfer
(
spi_dev
,
tx_data
,
rx_data
,
TEST_LEN
);
for
(
int
i
=
0
;
i
<
TEST_LEN
;
i
++
)
{
rt_kprintf
(
" 0x%02x, "
,
rx_data
[
i
]);
}
}
}
MSH_CMD_EXPORT
(
spi_sample
,
spi
sample
);
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录