Merge pull request #4465 from mysterywolf/nrf5152

[nrf5x] auto formatted
This commit is contained in:
Bernard Xiong 2021-03-17 17:55:53 +08:00 committed by GitHub
commit 95c0569b33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
28 changed files with 235 additions and 235 deletions

View File

@ -14,9 +14,9 @@
// <o> Internal SRAM memory size[Kbytes] <16 or 32>
// <i>Default: 16
#define NRF_SRAM_BEGIN (0x20000000)
#define NRF_SRAM_SIZE (16 * 1024)
#define NRF_SRAM_END (NRF_SRAM_BEGIN + NRF_SRAM_SIZE)
#define NRF_SRAM_BEGIN (0x20000000)
#define NRF_SRAM_SIZE (16 * 1024)
#define NRF_SRAM_END (NRF_SRAM_BEGIN + NRF_SRAM_SIZE)
//#endif

View File

@ -189,10 +189,10 @@ void rt_hw_uart_init(void)
rt_ringbuffer_init(&(uart->rx_rb), rx_buffer, sizeof(rx_buffer));
/* device interface */
uart->parent.init = rt_uart_init;
uart->parent.open = rt_uart_open;
uart->parent.init = rt_uart_init;
uart->parent.open = rt_uart_open;
uart->parent.close = rt_uart_close;
uart->parent.read = rt_uart_read;
uart->parent.read = rt_uart_read;
uart->parent.write = rt_uart_write;
uart->parent.control = RT_NULL;
uart->parent.user_data = RT_NULL;

View File

@ -3,16 +3,16 @@
#define __RTTHREAD_CFG_H__
/* RT_NAME_MAX*/
#define RT_NAME_MAX 6
#define RT_NAME_MAX 6
/* RT_ALIGN_SIZE*/
#define RT_ALIGN_SIZE 4
#define RT_ALIGN_SIZE 4
/* PRIORITY_MAX */
#define RT_THREAD_PRIORITY_MAX 8
#define RT_THREAD_PRIORITY_MAX 8
/* Tick per Second */
#define RT_TICK_PER_SECOND 100
#define RT_TICK_PER_SECOND 100
/* SECTION: RT_DEBUG */
/* Thread Debug */
@ -24,13 +24,13 @@
/* Using Hook */
#define RT_USING_HOOK
#define IDLE_THREAD_STACK_SIZE 512
#define IDLE_THREAD_STACK_SIZE 512
/* Using Software Timer */
/* #define RT_USING_TIMER_SOFT */
#define RT_TIMER_THREAD_PRIO 4
#define RT_TIMER_THREAD_STACK_SIZE 512
#define RT_TIMER_TICK_PER_SECOND 100
#define RT_TIMER_THREAD_PRIO 4
#define RT_TIMER_THREAD_STACK_SIZE 512
#define RT_TIMER_TICK_PER_SECOND 100
/* SECTION: IPC */
/* Using Semaphore*/
@ -74,9 +74,9 @@
/* SECTION: Console options */
#define RT_USING_CONSOLE
/* the buffer size of console*/
#define RT_CONSOLEBUF_SIZE 128
#define RT_CONSOLEBUF_SIZE 128
// <string name="RT_CONSOLE_DEVICE_NAME" description="The device name for console" default="uart1" />
#define RT_CONSOLE_DEVICE_NAME "uart0"
#define RT_CONSOLE_DEVICE_NAME "uart0"
@ -84,8 +84,8 @@
#define RT_USING_FINSH
/* configure finsh parameters */
#define FINSH_THREAD_PRIORITY 6
#define FINSH_THREAD_STACK_SIZE 512
#define FINSH_HISTORY_LINES 1
#define FINSH_THREAD_STACK_SIZE 512
#define FINSH_HISTORY_LINES 1
/* Using symbol table */
#define FINSH_USING_SYMTAB
#define FINSH_USING_DESCRIPTION

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2020, RT-Thread Development Team
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@ -31,7 +31,7 @@ static void nrf5x_saadc_event_hdr(nrfx_saadc_evt_t const * p_event)
j ++;
}
}
results.done = 1;
results.done = 1;
}
}
@ -72,22 +72,22 @@ static void set_channels(drv_nrfx_saadc_channel_t * channel)
/* channel: 0-7 */
static rt_err_t nrf5x_adc_enabled(struct rt_adc_device *device, rt_uint32_t channel, rt_bool_t enabled)
{
nrfx_err_t err_code = NRFX_SUCCESS;
{
nrfx_err_t err_code = NRFX_SUCCESS;
uint8_t i,j;
if (enabled)
{
{
RT_ASSERT(device != RT_NULL);
RT_ASSERT(device->parent.user_data != RT_NULL);
drv_nrfx_saadc_channel_t * drv_channel_config = NULL;
drv_channel_config = (drv_nrfx_saadc_channel_t *)device->parent.user_data;
drv_channel_config = (drv_nrfx_saadc_channel_t *)device->parent.user_data;
set_channels(drv_channel_config);
nrfx_saadc_channel_t channels_cache[results.channel_count];
j = 0;
for(i = 0; i < 8; i++)
{
@ -97,20 +97,20 @@ static rt_err_t nrf5x_adc_enabled(struct rt_adc_device *device, rt_uint32_t chan
j ++;
}
}
err_code = nrfx_saadc_channels_config(channels_cache,results.channel_count);
err_code = nrfx_saadc_simple_mode_set(get_channels_mask(),
NRF_SAADC_RESOLUTION_12BIT,
NRF_SAADC_OVERSAMPLE_DISABLED,
nrf5x_saadc_event_hdr);
err_code = nrfx_saadc_buffer_set(result_buff_cache, results.channel_count);
err_code = nrfx_saadc_buffer_set(result_buff_cache, results.channel_count);
}
else
{
results.channels[channel].channel_index = 0xff;
results.channel_count = 0;
for(i = 0; i < 8; i++)
{
@ -119,7 +119,7 @@ static rt_err_t nrf5x_adc_enabled(struct rt_adc_device *device, rt_uint32_t chan
results.channel_count ++;
}
}
if(results.channel_count == 0)
{
nrfx_saadc_channel_t channels_cache[1];
@ -129,7 +129,7 @@ static rt_err_t nrf5x_adc_enabled(struct rt_adc_device *device, rt_uint32_t chan
else
{
nrfx_saadc_channel_t channels_cache[results.channel_count];
j = 0;
for(i = 0; i < 8; i++)
{
@ -139,25 +139,25 @@ static rt_err_t nrf5x_adc_enabled(struct rt_adc_device *device, rt_uint32_t chan
j ++;
}
}
err_code = nrfx_saadc_channels_config(channels_cache,results.channel_count);
err_code = nrfx_saadc_simple_mode_set(get_channels_mask(),
NRF_SAADC_RESOLUTION_12BIT,
NRF_SAADC_OVERSAMPLE_DISABLED,
nrf5x_saadc_event_hdr);
err_code = nrfx_saadc_buffer_set(result_buff_cache, results.channel_count);
}
}
return err_code;
return err_code;
}
static rt_err_t nrf5x_get_adc_value(struct rt_adc_device *device, rt_uint32_t channel, rt_uint32_t *value)
{
nrfx_err_t err_code = NRFX_SUCCESS;
nrfx_err_t err_code = NRFX_SUCCESS;
if (results.channels[channel].channel_index != 0xff)
{
results.done = 0;
@ -169,7 +169,7 @@ static rt_err_t nrf5x_get_adc_value(struct rt_adc_device *device, rt_uint32_t ch
* value = results.result_buffer[channel];
results.done = 0;
}
return err_code;
}
@ -184,7 +184,7 @@ int rt_hw_adc_init(void)
int result = RT_EOK;
uint8_t i;
char name_buf[6] = ADC_NAME;
for(i = 0; i < 8; i++)
{
results.channels[i].channel_index = 0xff;
@ -192,7 +192,7 @@ int rt_hw_adc_init(void)
results.channel_count = 0;
results.done = 0;
}
/* initializing SAADC interrupt priority */
if (nrfx_saadc_init(NRFX_SAADC_CONFIG_IRQ_PRIORITY) != NRFX_SUCCESS)
{
@ -236,43 +236,43 @@ INIT_BOARD_EXPORT(rt_hw_adc_init);
void saadc_sample(void)
{
drv_nrfx_saadc_channel_t channel_config;
rt_uint32_t result;
rt_uint32_t result;
rt_adc_device_t adc_dev;
adc_dev = (rt_adc_device_t)rt_device_find(ADC_NAME);
adc_dev->parent.user_data = &channel_config;
channel_config = (drv_nrfx_saadc_channel_t){.mode = SAMPLE_ADC_MODE_SINGLE_ENDED,
.pin_p = SAMPLE_ADC_AIN1,
.pin_n = SAMPLE_ADC_AIN_NC,
channel_config = (drv_nrfx_saadc_channel_t){.mode = SAMPLE_ADC_MODE_SINGLE_ENDED,
.pin_p = SAMPLE_ADC_AIN1,
.pin_n = SAMPLE_ADC_AIN_NC,
.channel_num = SAMPLE_ADC_CHANNEL_0};
rt_adc_enable(adc_dev, channel_config.channel_num);
channel_config = (drv_nrfx_saadc_channel_t){.mode = SAMPLE_ADC_MODE_SINGLE_ENDED,
.pin_p = SAMPLE_ADC_AIN2,
.pin_n = SAMPLE_ADC_AIN_NC,
channel_config = (drv_nrfx_saadc_channel_t){.mode = SAMPLE_ADC_MODE_SINGLE_ENDED,
.pin_p = SAMPLE_ADC_AIN2,
.pin_n = SAMPLE_ADC_AIN_NC,
.channel_num = SAMPLE_ADC_CHANNEL_1};
rt_adc_enable(adc_dev, channel_config.channel_num);
channel_config = (drv_nrfx_saadc_channel_t){.mode = SAMPLE_ADC_MODE_SINGLE_ENDED,
.pin_p = SAMPLE_ADC_AIN7,
.pin_n = SAMPLE_ADC_AIN_NC,
channel_config = (drv_nrfx_saadc_channel_t){.mode = SAMPLE_ADC_MODE_SINGLE_ENDED,
.pin_p = SAMPLE_ADC_AIN7,
.pin_n = SAMPLE_ADC_AIN_NC,
.channel_num = SAMPLE_ADC_CHANNEL_5};
rt_adc_enable(adc_dev, channel_config.channel_num);
int count = 1;
int count = 1;
while(count++)
{
result = rt_adc_read(adc_dev, 0);
rt_kprintf("saadc channel 0 value = %d, ",result);
result = rt_adc_read(adc_dev, 1);
rt_kprintf("saadc channel 1 value = %d, ",result);
result = rt_adc_read(adc_dev, 5);
rt_kprintf("saadc channel 5 value = %d",result);
rt_kprintf("\r\n");
rt_kprintf("saadc channel 5 value = %d",result);
rt_kprintf("\r\n");
rt_thread_mdelay(1000);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2020, RT-Thread Development Team
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@ -7,7 +7,7 @@
* Date Author Notes
* 2020-08-18 guohp1128 the first version
*/
#ifndef __DRV_ADC_H__
#define __DRV_ADC_H__
@ -18,12 +18,12 @@
#define ADC_NAME "adc"
/*
/*
previous definition in application
set single-ended mode or differential mode.
selection ADC input pin, and config the number of Channel.
mode: 0 single-ended mode,1 differential mode
pin_p: 0-7
pin_n: 0-7,if single-ended mode, pin_n invalid
@ -40,9 +40,9 @@ typedef struct
typedef struct
{
nrfx_saadc_channel_t channels[8];
uint8_t channel_count;
nrf_saadc_value_t result_buffer[8];
uint8_t done;
uint8_t channel_count;
nrf_saadc_value_t result_buffer[8];
uint8_t done;
} drv_nrfx_saadc_result_t;
#endif /* __DRV_ADC_H__ */

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@ -12,7 +12,7 @@
#ifdef RT_USING_PIN
static const struct pin_index pins[] =
static const struct pin_index pins[] =
{
__NRF5X_PIN(0 , 0, 0 ),
__NRF5X_PIN(1 , 0, 1 ),
@ -46,7 +46,7 @@ static const struct pin_index pins[] =
__NRF5X_PIN(29, 0, 29),
__NRF5X_PIN(30, 0, 30),
__NRF5X_PIN(31, 0, 31),
#ifdef SOC_NRF52840
#ifdef SOC_NRF52840
__NRF5X_PIN(32, 1, 0 ),
__NRF5X_PIN(33, 1, 1 ),
__NRF5X_PIN(34, 1, 2 ),
@ -110,7 +110,7 @@ static void nrf5x_pin_write(rt_device_t dev, rt_base_t pin, rt_base_t value)
{
return;
}
nrf_gpio_pin_write(pin, value);
}
@ -179,7 +179,7 @@ static void pin_irq_hdr(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
{
int i;
int irq_quantity;
irq_quantity = ITEM_NUM(pin_irq_hdr_tab);
for(i = 0; i < irq_quantity; i++)
{
@ -202,13 +202,13 @@ static rt_err_t nrf5x_pin_attach_irq(struct rt_device *device, rt_int32_t pin,
nrfx_err_t err_code;
int i;
int irq_quantity;
index = get_pin(pin);
if (index == RT_NULL)
{
return RT_ENOSYS;
}
irq_quantity = ITEM_NUM(pin_irq_hdr_tab);
for(i = 0; i < irq_quantity; i++)
{
@ -227,37 +227,37 @@ static rt_err_t nrf5x_pin_attach_irq(struct rt_device *device, rt_int32_t pin,
{
return RT_ENOMEM;
}
level = rt_hw_interrupt_disable();
level = rt_hw_interrupt_disable();
pin_irq_hdr_tab[irqindex].pin = pin;
pin_irq_hdr_tab[irqindex].hdr = hdr;
pin_irq_hdr_tab[irqindex].mode = mode;
pin_irq_hdr_tab[irqindex].args = args;
if(mode == PIN_IRQ_MODE_RISING)
{
nrfx_gpiote_in_config_t inConfig = NRFX_GPIOTE_CONFIG_IN_SENSE_LOTOHI(args);
inConfig.pull = NRF_GPIO_PIN_PULLDOWN;
inConfig.pull = NRF_GPIO_PIN_PULLDOWN;
err_code = nrfx_gpiote_in_init(pin, &inConfig, pin_irq_hdr);
}
else if(mode == PIN_IRQ_MODE_FALLING)
{
nrfx_gpiote_in_config_t inConfig = NRFX_GPIOTE_CONFIG_IN_SENSE_HITOLO(args);
inConfig.pull = NRF_GPIO_PIN_PULLUP;
inConfig.pull = NRF_GPIO_PIN_PULLUP;
err_code = nrfx_gpiote_in_init(pin, &inConfig, pin_irq_hdr);
}
else if(mode == PIN_IRQ_MODE_RISING_FALLING)
{
nrfx_gpiote_in_config_t inConfig = NRFX_GPIOTE_CONFIG_IN_SENSE_TOGGLE(args);
inConfig.pull = NRF_GPIO_PIN_PULLUP;
err_code = nrfx_gpiote_in_init(pin, &inConfig, pin_irq_hdr);
}
rt_hw_interrupt_enable(level);
switch(err_code)
switch(err_code)
{
case NRFX_ERROR_BUSY:
return RT_EBUSY;
@ -282,7 +282,7 @@ static rt_err_t nrf5x_pin_dettach_irq(struct rt_device *device, rt_int32_t pin)
{
return RT_ENOSYS;
}
irq_quantity = ITEM_NUM(pin_irq_hdr_tab);
for(i = 0; i < irq_quantity; i++)
{
@ -308,7 +308,7 @@ static rt_err_t nrf5x_pin_dettach_irq(struct rt_device *device, rt_int32_t pin)
static rt_err_t nrf5x_pin_irq_enable(struct rt_device *device, rt_base_t pin,
rt_uint32_t enabled)
{
const struct pin_index *index;
const struct pin_index *index;
rt_base_t level;
int i;
int irq_quantity;
@ -337,7 +337,7 @@ static rt_err_t nrf5x_pin_irq_enable(struct rt_device *device, rt_base_t pin,
break;
}
}
if(i >= irq_quantity)
{
return RT_ENOSYS;
@ -362,8 +362,8 @@ int rt_hw_pin_init(void)
err_code = (nrfx_err_t)rt_device_pin_register("pin", &_nrf5x_pin_ops, RT_NULL);
err_code = nrfx_gpiote_init(NRFX_GPIOTE_CONFIG_IRQ_PRIORITY);
switch(err_code)
switch(err_code)
{
case NRFX_ERROR_INVALID_STATE:
return RT_EINVAL;
@ -372,7 +372,7 @@ int rt_hw_pin_init(void)
default:
return RT_ERROR;;
}
}
INIT_BOARD_EXPORT(rt_hw_pin_init);
@ -389,90 +389,90 @@ INIT_BOARD_EXPORT(rt_hw_pin_init);
void button_1_callback(void *args)
{
static int flag1 = 0;
if(flag1 == 0)
{
flag1 = 1;
rt_pin_write(DK_BOARD_LED_1, PIN_LOW);
}
else
{
flag1 = 0;
rt_pin_write(DK_BOARD_LED_1, PIN_HIGH);
}
static int flag1 = 0;
if(flag1 == 0)
{
flag1 = 1;
rt_pin_write(DK_BOARD_LED_1, PIN_LOW);
}
else
{
flag1 = 0;
rt_pin_write(DK_BOARD_LED_1, PIN_HIGH);
}
}
void button_2_callback(void *args)
{
static int flag2 = 0;
if(flag2 == 0)
{
flag2 = 1;
rt_pin_write(DK_BOARD_LED_2, PIN_LOW);
}
else
{
flag2 = 0;
rt_pin_write(DK_BOARD_LED_2, PIN_HIGH);
}
static int flag2 = 0;
if(flag2 == 0)
{
flag2 = 1;
rt_pin_write(DK_BOARD_LED_2, PIN_LOW);
}
else
{
flag2 = 0;
rt_pin_write(DK_BOARD_LED_2, PIN_HIGH);
}
}
void button_3_callback(void *args)
{
static int flag3 = 0;
if(flag3 == 0)
{
flag3 = 1;
rt_pin_write(DK_BOARD_LED_3, PIN_LOW);
}
else
{
flag3 = 0;
rt_pin_write(DK_BOARD_LED_3, PIN_HIGH);
}
static int flag3 = 0;
if(flag3 == 0)
{
flag3 = 1;
rt_pin_write(DK_BOARD_LED_3, PIN_LOW);
}
else
{
flag3 = 0;
rt_pin_write(DK_BOARD_LED_3, PIN_HIGH);
}
}
void button_4_callback(void *args)
{
static int flag4 = 0;
if(flag4 == 0)
{
flag4 = 1;
rt_pin_write(DK_BOARD_LED_4, PIN_LOW);
}
else
{
flag4 = 0;
rt_pin_write(DK_BOARD_LED_4, PIN_HIGH);
}
static int flag4 = 0;
if(flag4 == 0)
{
flag4 = 1;
rt_pin_write(DK_BOARD_LED_4, PIN_LOW);
}
else
{
flag4 = 0;
rt_pin_write(DK_BOARD_LED_4, PIN_HIGH);
}
}
void gpio_sample(void)
{
rt_err_t err_code;
rt_pin_mode(DK_BOARD_LED_1, PIN_MODE_OUTPUT);
rt_pin_mode(DK_BOARD_LED_2, PIN_MODE_OUTPUT);
rt_pin_mode(DK_BOARD_LED_3, PIN_MODE_OUTPUT);
rt_pin_mode(DK_BOARD_LED_4, PIN_MODE_OUTPUT);
rt_err_t err_code;
rt_pin_write(DK_BOARD_LED_1, PIN_HIGH);
rt_pin_write(DK_BOARD_LED_2, PIN_HIGH);
rt_pin_write(DK_BOARD_LED_3, PIN_HIGH);
rt_pin_write(DK_BOARD_LED_4, PIN_HIGH);
err_code = rt_pin_attach_irq(DK_BOARD_BUTTON_1, PIN_IRQ_MODE_FALLING,
rt_pin_mode(DK_BOARD_LED_1, PIN_MODE_OUTPUT);
rt_pin_mode(DK_BOARD_LED_2, PIN_MODE_OUTPUT);
rt_pin_mode(DK_BOARD_LED_3, PIN_MODE_OUTPUT);
rt_pin_mode(DK_BOARD_LED_4, PIN_MODE_OUTPUT);
rt_pin_write(DK_BOARD_LED_1, PIN_HIGH);
rt_pin_write(DK_BOARD_LED_2, PIN_HIGH);
rt_pin_write(DK_BOARD_LED_3, PIN_HIGH);
rt_pin_write(DK_BOARD_LED_4, PIN_HIGH);
err_code = rt_pin_attach_irq(DK_BOARD_BUTTON_1, PIN_IRQ_MODE_FALLING,
button_1_callback, (void*) true); //true: hi_accuracy(IN_EVENT),false: lo_accuracy(PORT_EVENT)
rt_pin_irq_enable(DK_BOARD_BUTTON_1, PIN_IRQ_ENABLE);
err_code = rt_pin_attach_irq(DK_BOARD_BUTTON_2, PIN_IRQ_MODE_FALLING,
rt_pin_irq_enable(DK_BOARD_BUTTON_1, PIN_IRQ_ENABLE);
err_code = rt_pin_attach_irq(DK_BOARD_BUTTON_2, PIN_IRQ_MODE_FALLING,
button_2_callback, (void*) true); //true: hi_accuracy(IN_EVENT),false: lo_accuracy(PORT_EVENT)
rt_pin_irq_enable(DK_BOARD_BUTTON_2, PIN_IRQ_ENABLE);
err_code = rt_pin_attach_irq(DK_BOARD_BUTTON_3, PIN_IRQ_MODE_FALLING,
rt_pin_irq_enable(DK_BOARD_BUTTON_2, PIN_IRQ_ENABLE);
err_code = rt_pin_attach_irq(DK_BOARD_BUTTON_3, PIN_IRQ_MODE_FALLING,
button_3_callback, (void*) true); //true: hi_accuracy(IN_EVENT),false: lo_accuracy(PORT_EVENT)
rt_pin_irq_enable(DK_BOARD_BUTTON_3, PIN_IRQ_ENABLE);
err_code = rt_pin_attach_irq(DK_BOARD_BUTTON_4, PIN_IRQ_MODE_FALLING,
rt_pin_irq_enable(DK_BOARD_BUTTON_3, PIN_IRQ_ENABLE);
err_code = rt_pin_attach_irq(DK_BOARD_BUTTON_4, PIN_IRQ_MODE_FALLING,
button_4_callback, (void*) false); //true: hi_accuracy(IN_EVENT),false: lo_accuracy(PORT_EVENT)
rt_pin_irq_enable(DK_BOARD_BUTTON_4, PIN_IRQ_ENABLE);
rt_pin_irq_enable(DK_BOARD_BUTTON_4, PIN_IRQ_ENABLE);
}
MSH_CMD_EXPORT(gpio_sample, gpio sample);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2020, RT-Thread Development Team
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@ -8,7 +8,7 @@
* 2020-11-15 xckhmf First Verison
*
*/
#include <rtdevice.h>
#include <nrfx_twi_twim.h>
#include <nrfx_twim.h>
@ -23,7 +23,7 @@ typedef struct
}drv_i2c_cfg_t;
#ifdef BSP_USING_I2C0
static drv_i2c_cfg_t drv_i2c_0 =
static drv_i2c_cfg_t drv_i2c_0 =
{
.freq = NRF_TWIM_FREQ_400K,
.scl_pin = BSP_I2C0_SCL_PIN,
@ -33,7 +33,7 @@ static drv_i2c_cfg_t drv_i2c_0 =
static struct rt_i2c_bus_device i2c0_bus;
#endif
#ifdef BSP_USING_I2C1
static drv_i2c_cfg_t drv_i2c_1 =
static drv_i2c_cfg_t drv_i2c_1 =
{
.freq = NRF_TWIM_FREQ_400K,
.scl_pin = BSP_I2C1_SCL_PIN,
@ -42,17 +42,17 @@ static drv_i2c_cfg_t drv_i2c_1 =
};
static struct rt_i2c_bus_device i2c1_bus;
#endif
static int twi_master_init(struct rt_i2c_bus_device *bus)
static int twi_master_init(struct rt_i2c_bus_device *bus)
{
nrfx_err_t rtn;
nrfx_twim_config_t config = NRFX_TWIM_DEFAULT_CONFIG(0,0);
drv_i2c_cfg_t *p_cfg = bus->priv;
nrfx_twim_t const * p_instance = &p_cfg->twi_instance;
config.frequency = p_cfg->freq;
config.scl = p_cfg->scl_pin;
config.sda = p_cfg->sda_pin;
nrfx_twi_twim_bus_recover(config.scl,config.sda);
rtn = nrfx_twim_init(p_instance,&config,NULL,NULL);
@ -67,8 +67,8 @@ static rt_size_t _master_xfer(struct rt_i2c_bus_device *bus,
nrfx_twim_t const * p_instance = &((drv_i2c_cfg_t *)bus->priv)->twi_instance;
nrfx_err_t ret = NRFX_ERROR_INTERNAL;
uint32_t no_stop_flag = 0;
nrfx_twim_xfer_desc_t xfer = NRFX_TWIM_XFER_DESC_TX(msgs->addr,msgs->buf, msgs->len);
nrfx_twim_xfer_desc_t xfer = NRFX_TWIM_XFER_DESC_TX(msgs->addr,msgs->buf, msgs->len);
if((msgs->flags & 0x01) == RT_I2C_WR)
{
xfer.type = NRFX_TWIM_XFER_TX;
@ -83,7 +83,7 @@ static rt_size_t _master_xfer(struct rt_i2c_bus_device *bus,
}
ret = nrfx_twim_xfer(p_instance,&xfer,no_stop_flag);
return (ret == NRFX_SUCCESS) ? msgs->len : 0;
}
static const struct rt_i2c_bus_device_ops _i2c_ops =
@ -94,23 +94,23 @@ static const struct rt_i2c_bus_device_ops _i2c_ops =
};
int rt_hw_i2c_init(void)
{
{
#ifdef BSP_USING_I2C0
i2c0_bus.ops= &_i2c_ops;
i2c0_bus.timeout = 0;
i2c0_bus.priv = (void *)&drv_i2c_0;
twi_master_init(&i2c0_bus);
rt_i2c_bus_device_register(&i2c0_bus, "i2c0");
rt_i2c_bus_device_register(&i2c0_bus, "i2c0");
#endif
#ifdef BSP_USING_I2C1
i2c1_bus.ops= &_i2c_ops;
i2c1_bus.timeout = 0;
i2c1_bus.priv = (void *)&drv_i2c_1;
twi_master_init(&i2c1_bus);
rt_i2c_bus_device_register(&i2c1_bus, "i2c1");
rt_i2c_bus_device_register(&i2c1_bus, "i2c1");
#endif
return 0;
}
INIT_BOARD_EXPORT(rt_hw_i2c_init);
INIT_BOARD_EXPORT(rt_hw_i2c_init);
#endif /* defined(BSP_USING_I2C0) || defined(BSP_USING_I2C1) */

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2020, RT-Thread Development Team
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2020, RT-Thread Development Team
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@ -21,7 +21,7 @@
struct mcu_pwm
{
struct rt_device_pwm pwm_device;
nrfx_pwm_t *pwm_handle;
nrf_pwm_values_individual_t m_demo1_seq_values;
nrf_pwm_sequence_t m_demo1_seq;
@ -429,4 +429,4 @@ static int pwm_led_sample(int argc, char *argv[])
}
MSH_CMD_EXPORT(pwm_led_sample, pwm sample);
#endif
#endif

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2020, RT-Thread Development Team
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@ -42,7 +42,7 @@ static uint32_t tick = 0;
static void rtc_callback(nrfx_rtc_int_type_t int_type)
{
static uint32_t count = 0;
if (int_type == NRFX_RTC_INT_TICK)
{
count++;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@ -40,7 +40,7 @@ static struct nrfx_drv_spi_config spi_config[] =
static struct nrfx_drv_spi spi_bus_obj[sizeof(spi_config) / sizeof(spi_config[0])];
//Configure SPI bus pins using the menuconfig
static struct nrfx_drv_spi_pin_config bsp_spi_pin[] =
static struct nrfx_drv_spi_pin_config bsp_spi_pin[] =
{
#ifdef BSP_USING_SPI0
{
@ -102,7 +102,7 @@ nrfx_spi_evt_handler_t spi_handler[] = {spi0_handler, spi1_handler, spi2_handler
/**
* @brief This function config spi bus
* @param device
* @param device
* @param configuration
* @retval RT_EOK / RT_ERROR
*/
@ -118,7 +118,7 @@ static rt_err_t spi_configure(struct rt_spi_device *device,
RT_ASSERT(index != 0xFF);
nrfx_spi_t spi = spi_bus_obj[index].spi;
nrfx_spi_config_t config = NRFX_SPI_DEFAULT_CONFIG(bsp_spi_pin[index].sck_pin,
nrfx_spi_config_t config = NRFX_SPI_DEFAULT_CONFIG(bsp_spi_pin[index].sck_pin,
bsp_spi_pin[index].mosi_pin, bsp_spi_pin[index].miso_pin, NRFX_SPI_PIN_NOT_USED);
/* spi config ss pin */
@ -211,7 +211,7 @@ static rt_uint32_t spixfer(struct rt_spi_device *device, struct rt_spi_message *
nrf_gpio_pin_clear((uint32_t)device->parent.user_data);
}
p_xfer_desc.p_rx_buffer = message->recv_buf;
p_xfer_desc.rx_length = message->length;
p_xfer_desc.rx_length = message->length;
p_xfer_desc.p_tx_buffer = message->send_buf;
p_xfer_desc.tx_length = message->length ;
if(message->send_buf == RT_NULL)
@ -220,7 +220,7 @@ static rt_uint32_t spixfer(struct rt_spi_device *device, struct rt_spi_message *
}
if(message->recv_buf == RT_NULL)
{
p_xfer_desc.rx_length = 0;
p_xfer_desc.rx_length = 0;
}
nrf_ret = nrfx_spi_xfer(p_instance, &p_xfer_desc, 0);
@ -228,14 +228,14 @@ static rt_uint32_t spixfer(struct rt_spi_device *device, struct rt_spi_message *
{
nrf_gpio_pin_set((uint32_t)device->parent.user_data);
}
if( NRFX_SUCCESS != nrf_ret)
{
return 0;
}
else
{
return message->length;
return message->length;
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@ -57,7 +57,7 @@ struct nrfx_drv_spi_config
nrfx_spi_t spi;
};
struct nrfx_drv_spi
struct nrfx_drv_spi
{
nrfx_spi_t spi; /* nrfx spi driver instance. */
nrfx_spi_config_t spi_config; /* nrfx spi config Configuration */

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2020, RT-Thread Development Team
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@ -44,16 +44,16 @@ drv_uart_cfg_t m_uart0_cfg = {
#ifdef BSP_USING_UART0
static void uart0_event_hander(nrfx_uart_event_t const *p_event,void *p_context)
{
{
if (p_event->type == NRFX_UART_EVT_RX_DONE)
{
if(p_event->data.rxtx.bytes == 1)
{
m_uart0_cfg.rx_length = p_event->data.rxtx.bytes;
/* rx_byte equal p_data */
//m_uart0_cfg.rx_byte = *(p_event->data.rxtx.p_data);
//m_uart0_cfg.rx_byte = *(p_event->data.rxtx.p_data);
rt_hw_serial_isr(m_uart0_cfg.serial, RT_SERIAL_EVENT_RX_IND);
}
nrfx_uart_rx(&(m_uart0_cfg.uart),&m_uart0_cfg.rx_byte,1);
@ -72,7 +72,7 @@ static rt_err_t _uart_cfg(struct rt_serial_device *serial, struct serial_configu
RT_ASSERT(serial != RT_NULL);
RT_ASSERT(cfg != RT_NULL);
if (serial->parent.user_data == RT_NULL)
{
return -RT_ERROR;
@ -107,7 +107,7 @@ static rt_err_t _uart_cfg(struct rt_serial_device *serial, struct serial_configu
config.hal_cfg.hwfc = NRF_UART_HWFC_DISABLED;
config.pselrxd = instance->rx_pin;
config.pseltxd = instance->tx_pin;
nrfx_uart_init(&(instance->uart), &config, instance->event_handler);
nrfx_uart_rx(&(instance->uart),&(instance->rx_byte),1);
nrf_uart_int_disable(instance->uart.p_reg, NRF_UART_INT_MASK_TXDRDY);
@ -187,7 +187,7 @@ static int _uart_putc(struct rt_serial_device *serial, char c)
while (!nrf_uart_event_check(instance->uart.p_reg, NRF_UART_EVENT_TXDRDY))
{
//wait for TXD send
}
}
return rtn;
}
@ -205,7 +205,7 @@ static int _uart_getc(struct rt_serial_device *serial)
if (serial->parent.user_data != RT_NULL)
{
instance = (drv_uart_cfg_t*)serial->parent.user_data;
}
}
if(instance->rx_length)
{
ch = instance->rx_byte;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2020, RT-Thread Development Team
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@ -68,7 +68,7 @@ static void uarte_evt_handler(nrfx_uarte_event_t const * p_event,
case NRFX_UARTE_EVT_ERROR:
(void)nrfx_uarte_rx(&(p_cb->uarte_instance), p_cb->rx_buffer, 1);
break;
case NRFX_UARTE_EVT_TX_DONE:
if(p_cb->serial->parent.open_flag&RT_DEVICE_FLAG_INT_TX)
{
@ -90,7 +90,7 @@ static rt_err_t _uart_cfg(struct rt_serial_device *serial, struct serial_configu
RT_ASSERT(serial != RT_NULL);
RT_ASSERT(cfg != RT_NULL);
if (serial->parent.user_data == RT_NULL)
{
return -RT_ERROR;
@ -145,11 +145,11 @@ static rt_err_t _uart_cfg(struct rt_serial_device *serial, struct serial_configu
NRF_UARTE_PARITY_EXCLUDED:NRF_UARTE_PARITY_INCLUDED;
config.hal_cfg.hwfc = NRF_UARTE_HWFC_DISABLED;
config.pselrxd = p_cb->rx_pin;
config.pseltxd = p_cb->tx_pin;
config.pseltxd = p_cb->tx_pin;
config.p_context = (void *)p_cb;
nrfx_uarte_init(&(p_cb->uarte_instance),(nrfx_uarte_config_t const *)&config,uarte_evt_handler);
nrfx_uarte_rx(&(p_cb->uarte_instance),p_cb->rx_buffer,1);
nrfx_uarte_rx(&(p_cb->uarte_instance),p_cb->rx_buffer,1);
p_cb->isInit = true;
return RT_EOK;
}
@ -227,7 +227,7 @@ static int _uart_putc(struct rt_serial_device *serial, char c)
while(nrfx_uarte_tx_in_progress(&(p_cb->uarte_instance)))
{
}
}
}
return rtn;
}
@ -240,7 +240,7 @@ static int _uart_getc(struct rt_serial_device *serial)
if (serial->parent.user_data != RT_NULL)
{
p_cb = (drv_uart_cb_t*)serial->parent.user_data;
}
}
if(p_cb->rx_length)
{
ch = p_cb->rx_buffer[0];
@ -260,15 +260,15 @@ void rt_hw_uart_init(void)
{
struct serial_configure config = RT_SERIAL_CONFIG_DEFAULT;
#ifdef BSP_USING_UART0
#ifdef BSP_USING_UART0
m_serial_0.config = config;
m_serial_0.ops = &_uart_ops;
m_uarte0_cb.serial = &m_serial_0;
rt_hw_serial_register(&m_serial_0, "uart0", \
RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX , &m_uarte0_cb);
#endif /* BSP_USING_UART0 */
#ifdef BSP_USING_UART1
#ifdef BSP_USING_UART1
m_serial_1.config = config;
m_serial_1.ops = &_uart_ops;
m_uarte1_cb.serial = &m_serial_1;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2020, RT-Thread Development Team
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*

View File

@ -603,12 +603,12 @@ static void _stack_thread(void *parameter)
result = rt_event_recv(stack_event, STACK_EV_DISCON | STACK_EV_DISPATCH | STACK_EV_KEY,
RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, next_timeout, &event);
if (result == -RT_ETIMEOUT)
if (result == -RT_ETIMEOUT)
{
LOG_E("wait completed timeout");
continue;
}
else if (result == -RT_ERROR)
else if (result == -RT_ERROR)
{
LOG_E("event received error");
continue;

View File

@ -64,7 +64,7 @@ void OSTick_Handler( void )
{
uint32_t diff;
/* enter interrupt */
/* enter interrupt */
rt_interrupt_enter();
diff = _tick_distance();
@ -92,7 +92,7 @@ static void _wakeup_tick_adjust(void)
if (rt_thread_self() != RT_NULL)
{
struct rt_thread *thread;
struct rt_thread *thread;
/* check time slice */
thread = rt_thread_self();

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2020, RT-Thread Development Team
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@ -16,16 +16,16 @@
int main(void)
{
int count = 1;
int count = 1;
rt_pin_mode(DK_BOARD_LED_1, PIN_MODE_OUTPUT);
while (count++)
{
{
rt_pin_write(DK_BOARD_LED_1, PIN_HIGH);
rt_thread_mdelay(500);
rt_pin_write(DK_BOARD_LED_1, PIN_LOW);
rt_thread_mdelay(500);
rt_thread_mdelay(500);
}
return RT_EOK;
}

View File

@ -1,4 +1,4 @@
#ifndef APP_CONFIG_H
#define APP_CONFIG_H
#endif //APP_CONFIG_H
#endif //APP_CONFIG_H

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2020, RT-Thread Development Team
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2020, RT-Thread Development Team
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@ -16,16 +16,16 @@
int main(void)
{
int count = 1;
int count = 1;
rt_pin_mode(DK_BOARD_LED_1, PIN_MODE_OUTPUT);
while (count++)
{
{
rt_pin_write(DK_BOARD_LED_1, PIN_HIGH);
rt_thread_mdelay(500);
rt_pin_write(DK_BOARD_LED_1, PIN_LOW);
rt_thread_mdelay(500);
rt_thread_mdelay(500);
}
return RT_EOK;
}

View File

@ -1,4 +1,4 @@
#ifndef APP_CONFIG_H
#define APP_CONFIG_H
#endif //APP_CONFIG_H
#endif //APP_CONFIG_H

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2020, RT-Thread Development Team
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2020, RT-Thread Development Team
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*