mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-11-07 08:39:40 +08:00
add the driver of gpio
This commit is contained in:
1 parent
c0f8330811
commit
8ac935aeaf
5 files changed
+233
-69
No files matched your search
@@ -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;
|
||||
}
|
||||
@@ -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))
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* 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__ */
|
||||
|
||||
@@ -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);
|
||||
Reference in new issue
Block a user