http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a1481cb2/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/config/nrf_drv_config.h ---------------------------------------------------------------------- diff --git a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/config/nrf_drv_config.h b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/config/nrf_drv_config.h deleted file mode 100644 index e823d6c..0000000 --- a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/config/nrf_drv_config.h +++ /dev/null @@ -1,472 +0,0 @@ -/* Copyright (c) 2015 Nordic Semiconductor. All Rights Reserved. - * - * The information contained herein is property of Nordic Semiconductor ASA. - * Terms and conditions of usage are described in detail in NORDIC - * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. - * - * Licensees are granted free, non-transferable use of the information. NO - * WARRANTY of ANY KIND is provided. This heading must NOT be removed from - * the file. - * - */ - -#ifndef NRF_DRV_CONFIG_H -#define NRF_DRV_CONFIG_H - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * Provide a non-zero value here in applications that need to use several - * peripherals with the same ID that are sharing certain resources - * (for example, SPI0 and TWI0). Obviously, such peripherals cannot be used - * simultaneously. Therefore, this definition allows to initialize the driver - * for another peripheral from a given group only after the previously used one - * is uninitialized. Normally, this is not possible, because interrupt handlers - * are implemented in individual drivers. - * This functionality requires a more complicated interrupt handling and driver - * initialization, hence it is not always desirable to use it. - */ -#define PERIPHERAL_RESOURCE_SHARING_ENABLED 0 - -/* CLOCK */ -#define CLOCK_ENABLED 0 - -#if (CLOCK_ENABLED == 1) -#define CLOCK_CONFIG_XTAL_FREQ NRF_CLOCK_XTALFREQ_Default -#define CLOCK_CONFIG_LF_SRC NRF_CLOCK_LFCLK_Xtal -#define CLOCK_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW -#endif - -/* GPIOTE */ -#define GPIOTE_ENABLED 0 - -#if (GPIOTE_ENABLED == 1) -#define GPIOTE_CONFIG_USE_SWI_EGU false -#define GPIOTE_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW -#define GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS 1 -#endif - -/* TIMER */ -#define TIMER0_ENABLED 0 - -#if (TIMER0_ENABLED == 1) -#define TIMER0_CONFIG_FREQUENCY NRF_TIMER_FREQ_16MHz -#define TIMER0_CONFIG_MODE TIMER_MODE_MODE_Timer -#define TIMER0_CONFIG_BIT_WIDTH TIMER_BITMODE_BITMODE_32Bit -#define TIMER0_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW - -#define TIMER0_INSTANCE_INDEX 0 -#endif - -#define TIMER1_ENABLED 0 - -#if (TIMER1_ENABLED == 1) -#define TIMER1_CONFIG_FREQUENCY NRF_TIMER_FREQ_16MHz -#define TIMER1_CONFIG_MODE TIMER_MODE_MODE_Timer -#define TIMER1_CONFIG_BIT_WIDTH TIMER_BITMODE_BITMODE_16Bit -#define TIMER1_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW - -#define TIMER1_INSTANCE_INDEX (TIMER0_ENABLED) -#endif - -#define TIMER2_ENABLED 0 - -#if (TIMER2_ENABLED == 1) -#define TIMER2_CONFIG_FREQUENCY NRF_TIMER_FREQ_16MHz -#define TIMER2_CONFIG_MODE TIMER_MODE_MODE_Timer -#define TIMER2_CONFIG_BIT_WIDTH TIMER_BITMODE_BITMODE_16Bit -#define TIMER2_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW - -#define TIMER2_INSTANCE_INDEX (TIMER1_ENABLED+TIMER0_ENABLED) -#endif - -#define TIMER3_ENABLED 0 - -#if (TIMER3_ENABLED == 1) -#define TIMER3_CONFIG_FREQUENCY NRF_TIMER_FREQ_16MHz -#define TIMER3_CONFIG_MODE TIMER_MODE_MODE_Timer -#define TIMER3_CONFIG_BIT_WIDTH TIMER_BITMODE_BITMODE_16Bit -#define TIMER3_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW - -#define TIMER3_INSTANCE_INDEX (TIMER2_ENABLED+TIMER1_ENABLED+TIMER0_ENABLED) -#endif - -#define TIMER4_ENABLED 0 - -#if (TIMER4_ENABLED == 1) -#define TIMER4_CONFIG_FREQUENCY NRF_TIMER_FREQ_16MHz -#define TIMER4_CONFIG_MODE TIMER_MODE_MODE_Timer -#define TIMER4_CONFIG_BIT_WIDTH TIMER_BITMODE_BITMODE_16Bit -#define TIMER4_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW - -#define TIMER4_INSTANCE_INDEX (TIMER3_ENABLED+TIMER2_ENABLED+TIMER1_ENABLED+TIMER0_ENABLED) -#endif - - -#define TIMER_COUNT (TIMER0_ENABLED + TIMER1_ENABLED + TIMER2_ENABLED + TIMER3_ENABLED + TIMER4_ENABLED) - -/* RTC */ -#define RTC0_ENABLED 0 - -#if (RTC0_ENABLED == 1) -#define RTC0_CONFIG_FREQUENCY 32678 -#define RTC0_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW -#define RTC0_CONFIG_RELIABLE false - -#define RTC0_INSTANCE_INDEX 0 -#endif - -#define RTC1_ENABLED 0 - -#if (RTC1_ENABLED == 1) -#define RTC1_CONFIG_FREQUENCY 32768 -#define RTC1_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW -#define RTC1_CONFIG_RELIABLE false - -#define RTC1_INSTANCE_INDEX (RTC0_ENABLED) -#endif - -#define RTC2_ENABLED 0 - -#if (RTC2_ENABLED == 1) -#define RTC2_CONFIG_FREQUENCY 32768 -#define RTC2_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW -#define RTC2_CONFIG_RELIABLE false - -#define RTC2_INSTANCE_INDEX (RTC0_ENABLED+RTC1_ENABLED) -#endif - - -#define RTC_COUNT (RTC0_ENABLED+RTC1_ENABLED+RTC2_ENABLED) - -#define NRF_MAXIMUM_LATENCY_US 2000 - -/* RNG */ -#define RNG_ENABLED 0 - -#if (RNG_ENABLED == 1) -#define RNG_CONFIG_ERROR_CORRECTION true -#define RNG_CONFIG_POOL_SIZE 8 -#define RNG_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW -#endif - -/* PWM */ - -#define PWM0_ENABLED 0 - -#if (PWM0_ENABLED == 1) -#define PWM0_CONFIG_OUT0_PIN 2 -#define PWM0_CONFIG_OUT1_PIN 3 -#define PWM0_CONFIG_OUT2_PIN 4 -#define PWM0_CONFIG_OUT3_PIN 5 -#define PWM0_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW -#define PWM0_CONFIG_BASE_CLOCK NRF_PWM_CLK_1MHz -#define PWM0_CONFIG_COUNT_MODE NRF_PWM_MODE_UP -#define PWM0_CONFIG_TOP_VALUE 1000 -#define PWM0_CONFIG_LOAD_MODE NRF_PWM_LOAD_COMMON -#define PWM0_CONFIG_STEP_MODE NRF_PWM_STEP_AUTO - -#define PWM0_INSTANCE_INDEX 0 -#endif - -#define PWM1_ENABLED 0 - -#if (PWM1_ENABLED == 1) -#define PWM1_CONFIG_OUT0_PIN 2 -#define PWM1_CONFIG_OUT1_PIN 3 -#define PWM1_CONFIG_OUT2_PIN 4 -#define PWM1_CONFIG_OUT3_PIN 5 -#define PWM1_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW -#define PWM1_CONFIG_BASE_CLOCK NRF_PWM_CLK_1MHz -#define PWM1_CONFIG_COUNT_MODE NRF_PWM_MODE_UP -#define PWM1_CONFIG_TOP_VALUE 1000 -#define PWM1_CONFIG_LOAD_MODE NRF_PWM_LOAD_COMMON -#define PWM1_CONFIG_STEP_MODE NRF_PWM_STEP_AUTO - -#define PWM1_INSTANCE_INDEX (PWM0_ENABLED) -#endif - -#define PWM2_ENABLED 0 - -#if (PWM2_ENABLED == 1) -#define PWM2_CONFIG_OUT0_PIN 2 -#define PWM2_CONFIG_OUT1_PIN 3 -#define PWM2_CONFIG_OUT2_PIN 4 -#define PWM2_CONFIG_OUT3_PIN 5 -#define PWM2_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW -#define PWM2_CONFIG_BASE_CLOCK NRF_PWM_CLK_1MHz -#define PWM2_CONFIG_COUNT_MODE NRF_PWM_MODE_UP -#define PWM2_CONFIG_TOP_VALUE 1000 -#define PWM2_CONFIG_LOAD_MODE NRF_PWM_LOAD_COMMON -#define PWM2_CONFIG_STEP_MODE NRF_PWM_STEP_AUTO - -#define PWM2_INSTANCE_INDEX (PWM0_ENABLED + PWM1_ENABLED) -#endif - -#define PWM_COUNT (PWM0_ENABLED + PWM1_ENABLED + PWM2_ENABLED) - -/* SPI */ -#define SPI0_ENABLED 0 - -#if (SPI0_ENABLED == 1) -#define SPI0_USE_EASY_DMA 0 - -#define SPI0_CONFIG_SCK_PIN 2 -#define SPI0_CONFIG_MOSI_PIN 3 -#define SPI0_CONFIG_MISO_PIN 4 -#define SPI0_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW - -#define SPI0_INSTANCE_INDEX 0 -#endif - -#define SPI1_ENABLED 0 - -#if (SPI1_ENABLED == 1) -#define SPI1_USE_EASY_DMA 0 - -#define SPI1_CONFIG_SCK_PIN 2 -#define SPI1_CONFIG_MOSI_PIN 3 -#define SPI1_CONFIG_MISO_PIN 4 -#define SPI1_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW - -#define SPI1_INSTANCE_INDEX (SPI0_ENABLED) -#endif - -#define SPI2_ENABLED 0 - -#if (SPI2_ENABLED == 1) -#define SPI2_USE_EASY_DMA 0 - -#define SPI2_CONFIG_SCK_PIN 2 -#define SPI2_CONFIG_MOSI_PIN 3 -#define SPI2_CONFIG_MISO_PIN 4 -#define SPI2_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW - -#define SPI2_INSTANCE_INDEX (SPI0_ENABLED + SPI1_ENABLED) -#endif - -#define SPI_COUNT (SPI0_ENABLED + SPI1_ENABLED + SPI2_ENABLED) - -/* SPIS */ -#define SPIS0_ENABLED 0 - -#if (SPIS0_ENABLED == 1) -#define SPIS0_CONFIG_SCK_PIN 2 -#define SPIS0_CONFIG_MOSI_PIN 3 -#define SPIS0_CONFIG_MISO_PIN 4 -#define SPIS0_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW - -#define SPIS0_INSTANCE_INDEX 0 -#endif - -#define SPIS1_ENABLED 0 - -#if (SPIS1_ENABLED == 1) -#define SPIS1_CONFIG_SCK_PIN 2 -#define SPIS1_CONFIG_MOSI_PIN 3 -#define SPIS1_CONFIG_MISO_PIN 4 -#define SPIS1_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW - -#define SPIS1_INSTANCE_INDEX SPIS0_ENABLED -#endif - -#define SPIS2_ENABLED 0 - -#if (SPIS2_ENABLED == 1) -#define SPIS2_CONFIG_SCK_PIN 2 -#define SPIS2_CONFIG_MOSI_PIN 3 -#define SPIS2_CONFIG_MISO_PIN 4 -#define SPIS2_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW - -#define SPIS2_INSTANCE_INDEX (SPIS0_ENABLED + SPIS1_ENABLED) -#endif - -#define SPIS_COUNT (SPIS0_ENABLED + SPIS1_ENABLED + SPIS2_ENABLED) - -/* UART */ -#define UART0_ENABLED 0 - -#if (UART0_ENABLED == 1) -#define UART0_CONFIG_HWFC NRF_UART_HWFC_DISABLED -#define UART0_CONFIG_PARITY NRF_UART_PARITY_EXCLUDED -#define UART0_CONFIG_BAUDRATE NRF_UART_BAUDRATE_115200 -#define UART0_CONFIG_PSEL_TXD 0 -#define UART0_CONFIG_PSEL_RXD 0 -#define UART0_CONFIG_PSEL_CTS 0 -#define UART0_CONFIG_PSEL_RTS 0 -#define UART0_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW -#ifdef NRF52 -#define UART0_CONFIG_USE_EASY_DMA false -//Compile time flag -#define UART_EASY_DMA_SUPPORT 1 -#define UART_LEGACY_SUPPORT 1 -#endif //NRF52 -#endif - -#define TWI0_ENABLED 0 - -#if (TWI0_ENABLED == 1) -#define TWI0_USE_EASY_DMA 0 - -#define TWI0_CONFIG_FREQUENCY NRF_TWI_FREQ_100K -#define TWI0_CONFIG_SCL 0 -#define TWI0_CONFIG_SDA 1 -#define TWI0_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW - -#define TWI0_INSTANCE_INDEX 0 -#endif - -#define TWI1_ENABLED 0 - -#if (TWI1_ENABLED == 1) -#define TWI1_USE_EASY_DMA 0 - -#define TWI1_CONFIG_FREQUENCY NRF_TWI_FREQ_100K -#define TWI1_CONFIG_SCL 0 -#define TWI1_CONFIG_SDA 1 -#define TWI1_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW - -#define TWI1_INSTANCE_INDEX (TWI0_ENABLED) -#endif - -#define TWI_COUNT (TWI0_ENABLED + TWI1_ENABLED) - -/* TWIS */ -#define TWIS0_ENABLED 0 - -#if (TWIS0_ENABLED == 1) - #define TWIS0_CONFIG_ADDR0 0 - #define TWIS0_CONFIG_ADDR1 0 /* 0: Disabled */ - #define TWIS0_CONFIG_SCL 0 - #define TWIS0_CONFIG_SDA 1 - #define TWIS0_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW - - #define TWIS0_INSTANCE_INDEX 0 -#endif - -#define TWIS1_ENABLED 0 - -#if (TWIS1_ENABLED == 1) - #define TWIS1_CONFIG_ADDR0 0 - #define TWIS1_CONFIG_ADDR1 0 /* 0: Disabled */ - #define TWIS1_CONFIG_SCL 0 - #define TWIS1_CONFIG_SDA 1 - #define TWIS1_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW - - #define TWIS1_INSTANCE_INDEX (TWIS0_ENABLED) -#endif - -#define TWIS_COUNT (TWIS0_ENABLED + TWIS1_ENABLED) -/* For more documentation see nrf_drv_twis.h file */ -#define TWIS_ASSUME_INIT_AFTER_RESET_ONLY 0 -/* For more documentation see nrf_drv_twis.h file */ -#define TWIS_NO_SYNC_MODE 0 - -/* QDEC */ -#define QDEC_ENABLED 0 - -#if (QDEC_ENABLED == 1) -#define QDEC_CONFIG_REPORTPER NRF_QDEC_REPORTPER_10 -#define QDEC_CONFIG_SAMPLEPER NRF_QDEC_SAMPLEPER_16384us -#define QDEC_CONFIG_PIO_A 1 -#define QDEC_CONFIG_PIO_B 2 -#define QDEC_CONFIG_PIO_LED 3 -#define QDEC_CONFIG_LEDPRE 511 -#define QDEC_CONFIG_LEDPOL NRF_QDEC_LEPOL_ACTIVE_HIGH -#define QDEC_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW -#define QDEC_CONFIG_DBFEN false -#define QDEC_CONFIG_SAMPLE_INTEN false -#endif - -/* ADC */ -#define ADC_ENABLED 0 - -#if (ADC_ENABLED == 1) -#define ADC_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW -#endif - - -/* SAADC */ -#define SAADC_ENABLED 0 - -#if (SAADC_ENABLED == 1) -#define SAADC_CONFIG_RESOLUTION NRF_SAADC_RESOLUTION_10BIT -#define SAADC_CONFIG_OVERSAMPLE NRF_SAADC_OVERSAMPLE_DISABLED -#define SAADC_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW -#endif - -/* PDM */ -#define PDM_ENABLED 0 - -#if (PDM_ENABLED == 1) -#define PDM_CONFIG_MODE NRF_PDM_MODE_MONO -#define PDM_CONFIG_EDGE NRF_PDM_EDGE_LEFTFALLING -#define PDM_CONFIG_CLOCK_FREQ NRF_PDM_FREQ_1032K -#define PDM_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW -#endif - -/* COMP */ -#define COMP_ENABLED 0 - -#if (COMP_ENABLED == 1) -#define COMP_CONFIG_REF NRF_COMP_REF_Int1V8 -#define COMP_CONFIG_MAIN_MODE NRF_COMP_MAIN_MODE_SE -#define COMP_CONFIG_SPEED_MODE NRF_COMP_SP_MODE_High -#define COMP_CONFIG_HYST NRF_COMP_HYST_NoHyst -#define COMP_CONFIG_ISOURCE NRF_COMP_ISOURCE_Off -#define COMP_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW -#define COMP_CONFIG_INPUT NRF_COMP_INPUT_0 -#endif - -/* LPCOMP */ -#define LPCOMP_ENABLED 0 - -#if (LPCOMP_ENABLED == 1) -#define LPCOMP_CONFIG_REFERENCE NRF_LPCOMP_REF_SUPPLY_4_8 -#define LPCOMP_CONFIG_DETECTION NRF_LPCOMP_DETECT_DOWN -#define LPCOMP_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW -#define LPCOMP_CONFIG_INPUT NRF_LPCOMP_INPUT_0 -#endif - -/* WDT */ -#define WDT_ENABLED 0 - -#if (WDT_ENABLED == 1) -#define WDT_CONFIG_BEHAVIOUR NRF_WDT_BEHAVIOUR_RUN_SLEEP -#define WDT_CONFIG_RELOAD_VALUE 2000 -#define WDT_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_HIGH -#endif - -/* SWI EGU */ -#ifdef NRF52 - #define EGU_ENABLED 0 -#endif - -/* I2S */ -#define I2S_ENABLED 0 - -#if (I2S_ENABLED == 1) -#define I2S_CONFIG_SCK_PIN 22 -#define I2S_CONFIG_LRCK_PIN 23 -#define I2S_CONFIG_MCK_PIN NRF_DRV_I2S_PIN_NOT_USED -#define I2S_CONFIG_SDOUT_PIN 24 -#define I2S_CONFIG_SDIN_PIN 25 -#define I2S_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_HIGH -#define I2S_CONFIG_MASTER NRF_I2S_MODE_MASTER -#define I2S_CONFIG_FORMAT NRF_I2S_FORMAT_I2S -#define I2S_CONFIG_ALIGN NRF_I2S_ALIGN_LEFT -#define I2S_CONFIG_SWIDTH NRF_I2S_SWIDTH_16BIT -#define I2S_CONFIG_CHANNELS NRF_I2S_CHANNELS_STEREO -#define I2S_CONFIG_MCK_SETUP NRF_I2S_MCK_32MDIV8 -#define I2S_CONFIG_RATIO NRF_I2S_RATIO_256X -#endif - -#include "nrf_drv_config_validation.h" - -#ifdef __cplusplus -} -#endif - -#endif // NRF_DRV_CONFIG_H
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a1481cb2/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/config/nrf_drv_config_validation.h ---------------------------------------------------------------------- diff --git a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/config/nrf_drv_config_validation.h b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/config/nrf_drv_config_validation.h deleted file mode 100644 index fa1bb8f..0000000 --- a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/config/nrf_drv_config_validation.h +++ /dev/null @@ -1,91 +0,0 @@ -/* Copyright (c) 2015 Nordic Semiconductor. All Rights Reserved. - * - * The information contained herein is property of Nordic Semiconductor ASA. - * Terms and conditions of usage are described in detail in NORDIC - * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. - * - * Licensees are granted free, non-transferable use of the information. NO - * WARRANTY of ANY KIND is provided. This heading must NOT be removed from - * the file. - * - */ - -#ifndef NRF_DRV_CONFIG_VALIDATION_H -#define NRF_DRV_CONFIG_VALIDATION_H - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef NRF52 - -#if (!PERIPHERAL_RESOURCE_SHARING_ENABLED) && \ - ((SPI0_ENABLED + SPIS0_ENABLED + TWI0_ENABLED + TWIS0_ENABLED) > 1) -#error "Peripherals overlap. SPI0, SPIS0, TWI0, TWIS0 - only one of these can be enabled." -#endif - -#if (!PERIPHERAL_RESOURCE_SHARING_ENABLED) && \ - ((SPI1_ENABLED + SPIS1_ENABLED + TWI1_ENABLED + TWIS1_ENABLED) > 1) -#error "Peripherals overlap. SPI1, SPIS1, TWI1, TWIS1 - only one of these can be enabled." -#endif - -#if (!PERIPHERAL_RESOURCE_SHARING_ENABLED) && \ - ((SPI2_ENABLED + SPIS2_ENABLED) > 1) -#error "Peripherals overlap. SPI2, SPIS2 - only one of these can be enabled." -#endif - -#if (!PERIPHERAL_RESOURCE_SHARING_ENABLED) && \ - ((COMP_ENABLED + LPCOMP_ENABLED) > 1) -#error "COMP and LPCOMP cannot be enabled together. Peripherals overlap." -#endif - -#else //NRF51 - -#if (TWIS0_ENABLED + TWIS1_ENABLED) > 0 -#error "TWIS not present in nRF51." -#endif - -#if SPIS0_ENABLED > 0 -#error "SPIS0 instance not present in nRF51." -#endif - -#if (SPI2_ENABLED + SPIS2_ENABLED) > 0 -#error "SPI2/SPIS2 instance not present in nRF51." -#endif - -#if RTC2_ENABLED -#error "RTC2 not present in NRF51." -#endif - -#if (TIMER3_ENABLED + TIMER4_ENABLED) > 0 -#error "TIMER3 and TIMER4 not present in nRF51." -#endif - -#if (!PERIPHERAL_RESOURCE_SHARING_ENABLED) && \ - ((SPI0_ENABLED + TWI0_ENABLED) > 1) -#error "Peripherals overlap. SPI0, TWI0 - only one of these can be enabled." -#endif - -#if (!PERIPHERAL_RESOURCE_SHARING_ENABLED) && \ - ((SPI1_ENABLED + SPIS1_ENABLED + TWI1_ENABLED) > 1) -#error "Peripherals overlap. SPI1, SPIS1, TWI1 - only one of these can be enabled." -#endif - -#if SAADC_ENABLED > 0 -#error "SAADC not present in nRF51." -#endif - -#if I2S_ENABLED > 0 -#error "I2S not present in nRF51." -#endif -#if COMP_ENABLED > 0 -#error "COMP not present in nRF51." -#endif - -#endif //NRF51 - -#ifdef __cplusplus -} -#endif - -#endif // NRF_DRV_CONFIG_VALIDATION_H http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a1481cb2/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/delay/nrf_delay.c ---------------------------------------------------------------------- diff --git a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/delay/nrf_delay.c b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/delay/nrf_delay.c deleted file mode 100644 index a77e641..0000000 --- a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/delay/nrf_delay.c +++ /dev/null @@ -1,26 +0,0 @@ -/* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved. - * - * The information contained herein is property of Nordic Semiconductor ASA. - * Terms and conditions of usage are described in detail in NORDIC - * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. - * - * Licensees are granted free, non-transferable use of the information. NO - * WARRANTY of ANY KIND is provided. This heading must NOT be removed from - * the file. - * - */ - -#include <stdio.h> -#include "compiler_abstraction.h" -#include "nrf.h" -#include "nrf_delay.h" - -/*lint --e{438} "Variable not used" */ -void nrf_delay_ms(uint32_t volatile number_of_ms) -{ - while(number_of_ms != 0) - { - number_of_ms--; - nrf_delay_us(999); - } -} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a1481cb2/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/delay/nrf_delay.h ---------------------------------------------------------------------- diff --git a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/delay/nrf_delay.h b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/delay/nrf_delay.h deleted file mode 100644 index 5114df7..0000000 --- a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/delay/nrf_delay.h +++ /dev/null @@ -1,250 +0,0 @@ -#ifndef _NRF_DELAY_H -#define _NRF_DELAY_H - -#include "nrf.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief Function for delaying execution for number of microseconds. - * - * @note NRF52 has instruction cache and because of that delay is not precise. - * - * @param number_of_ms - */ -/*lint --e{438, 522} "Variable not used" "Function lacks side-effects" */ -#if defined ( __CC_ARM ) - -static __ASM void __INLINE nrf_delay_us(uint32_t volatile number_of_us) -{ -loop - SUBS R0, R0, #1 - NOP - NOP - NOP - NOP - NOP - NOP - NOP - NOP - NOP - NOP - NOP - NOP -#ifdef NRF52 - NOP - NOP - NOP - NOP - NOP - NOP - NOP - NOP - NOP - NOP - NOP - NOP - NOP - NOP - NOP - NOP - NOP - NOP - NOP - NOP - NOP - NOP - NOP - NOP - NOP - NOP - NOP - NOP - NOP - NOP - NOP - NOP - NOP - NOP - NOP - NOP - NOP - NOP - NOP - NOP - NOP - NOP - NOP - NOP -#endif - BNE loop - BX LR -} - -#elif defined ( __ICCARM__ ) - -static void __INLINE nrf_delay_us(uint32_t volatile number_of_us) -{ -__ASM ( -"loop:\n\t" - " SUBS R0, R0, #1\n\t" - " NOP\n\t" - " NOP\n\t" - " NOP\n\t" - " NOP\n\t" - " NOP\n\t" - " NOP\n\t" - " NOP\n\t" - " NOP\n\t" - " NOP\n\t" - " NOP\n\t" - " NOP\n\t" - " NOP\n\t" -#ifdef NRF52 - " NOP\n\t" - " NOP\n\t" - " NOP\n\t" - " NOP\n\t" - " NOP\n\t" - " NOP\n\t" - " NOP\n\t" - " NOP\n\t" - " NOP\n\t" - " NOP\n\t" - " NOP\n\t" - " NOP\n\t" - " NOP\n\t" - " NOP\n\t" - " NOP\n\t" - " NOP\n\t" - " NOP\n\t" - " NOP\n\t" - " NOP\n\t" - " NOP\n\t" - " NOP\n\t" - " NOP\n\t" - " NOP\n\t" - " NOP\n\t" - " NOP\n\t" - " NOP\n\t" - " NOP\n\t" - " NOP\n\t" - " NOP\n\t" - " NOP\n\t" - " NOP\n\t" - " NOP\n\t" - " NOP\n\t" - " NOP\n\t" - " NOP\n\t" - " NOP\n\t" - " NOP\n\t" - " NOP\n\t" - " NOP\n\t" - " NOP\n\t" - " NOP\n\t" - " NOP\n\t" - " NOP\n\t" - " NOP\n\t" - " NOP\n\t" -#endif - " BNE.n loop\n\t"); -} - -#elif defined ( _WIN32 ) || defined ( __unix ) || defined( __APPLE__ ) - -__STATIC_INLINE void nrf_delay_us(uint32_t volatile number_of_us); - -#ifndef CUSTOM_NRF_DELAY_US -__STATIC_INLINE void nrf_delay_us(uint32_t volatile number_of_us) -{} -#endif - -#elif defined ( __GNUC__ ) - -static void __INLINE nrf_delay_us(uint32_t volatile number_of_us) __attribute__((always_inline)); -static void __INLINE nrf_delay_us(uint32_t volatile number_of_us) -{ -register uint32_t delay __ASM ("r0") = number_of_us; -__ASM volatile ( -#ifdef NRF51 - ".syntax unified\n" -#endif - "1:\n" - " SUBS %0, %0, #1\n" - " NOP\n" - " NOP\n" - " NOP\n" - " NOP\n" - " NOP\n" - " NOP\n" - " NOP\n" - " NOP\n" - " NOP\n" - " NOP\n" - " NOP\n" - " NOP\n" -#ifdef NRF52 - " NOP\n" - " NOP\n" - " NOP\n" - " NOP\n" - " NOP\n" - " NOP\n" - " NOP\n" - " NOP\n" - " NOP\n" - " NOP\n" - " NOP\n" - " NOP\n" - " NOP\n" - " NOP\n" - " NOP\n" - " NOP\n" - " NOP\n" - " NOP\n" - " NOP\n" - " NOP\n" - " NOP\n" - " NOP\n" - " NOP\n" - " NOP\n" - " NOP\n" - " NOP\n" - " NOP\n" - " NOP\n" - " NOP\n" - " NOP\n" - " NOP\n" - " NOP\n" - " NOP\n" - " NOP\n" - " NOP\n" - " NOP\n" - " NOP\n" - " NOP\n" - " NOP\n" - " NOP\n" - " NOP\n" - " NOP\n" - " NOP\n" - " NOP\n" - " NOP\n" - " NOP\n" -#endif - " BNE 1b\n" -#ifdef NRF51 - ".syntax divided\n" -#endif - : "+r" (delay)); -} -#endif - -void nrf_delay_ms(uint32_t volatile number_of_ms); - -#ifdef __cplusplus -} -#endif - -#endif http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a1481cb2/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/gpiote/nrf_drv_gpiote.c ---------------------------------------------------------------------- diff --git a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/gpiote/nrf_drv_gpiote.c b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/gpiote/nrf_drv_gpiote.c deleted file mode 100644 index 2a665c8..0000000 --- a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/gpiote/nrf_drv_gpiote.c +++ /dev/null @@ -1,580 +0,0 @@ -/* Copyright (c) 2015 Nordic Semiconductor. All Rights Reserved. - * - * The information contained herein is property of Nordic Semiconductor ASA. - * Terms and conditions of usage are described in detail in NORDIC - * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. - * - * Licensees are granted free, non-transferable use of the information. NO - * WARRANTY of ANY KIND is provided. This heading must NOT be removed from - * the file. - * - */ - -#include "nrf_drv_gpiote.h" -#include "nrf_drv_common.h" -#include "nrf_drv_config.h" -#include "app_util_platform.h" -#include "nrf_assert.h" - -#define FORBIDDEN_HANDLER_ADDRESS ((nrf_drv_gpiote_evt_handler_t)UINT32_MAX) -#define PIN_NOT_USED (-1) -#define PIN_USED (-2) -#define NO_CHANNELS (-1) -#define SENSE_FIELD_POS (6) -#define SENSE_FIELD_MASK (0xC0) - -/** - * @brief Macro for conveting task-event index to an address of an event register. - * - * Macro utilizes the fact that registers are grouped together in ascending order. - */ -#define TE_IDX_TO_EVENT_ADDR(idx) (nrf_gpiote_events_t)((uint32_t)NRF_GPIOTE_EVENTS_IN_0+(sizeof(uint32_t)*(idx))) - -/** - * @brief Macro for conveting task-event index to an address of a task register. - * - * Macro utilizes the fact that registers are grouped together in ascending order. - */ -#define TE_IDX_TO_TASK_ADDR(idx) (nrf_gpiote_tasks_t)((uint32_t)NRF_GPIOTE_TASKS_OUT_0+(sizeof(uint32_t)*(idx))) - -//lint -save -e661 -typedef struct -{ - nrf_drv_gpiote_evt_handler_t handlers[NUMBER_OF_GPIO_TE+GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS]; - int8_t pin_assignments[NUMBER_OF_PINS]; - int8_t port_handlers_pins[GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS]; - nrf_drv_state_t state; -} gpiote_control_block_t; - -static gpiote_control_block_t m_cb; - -__STATIC_INLINE bool pin_in_use(uint32_t pin) -{ - return (m_cb.pin_assignments[pin] != PIN_NOT_USED); -} - -__STATIC_INLINE bool pin_in_use_as_non_task_out(uint32_t pin) -{ - return (m_cb.pin_assignments[pin] == PIN_USED); -} - -__STATIC_INLINE bool pin_in_use_by_te(uint32_t pin) -{ - return (m_cb.pin_assignments[pin] >= 0 && m_cb.pin_assignments[pin] < NUMBER_OF_GPIO_TE) ? true : false; -} - -__STATIC_INLINE bool pin_in_use_by_port(uint32_t pin) -{ - return (m_cb.pin_assignments[pin] >= NUMBER_OF_GPIO_TE); -} - -__STATIC_INLINE bool pin_in_use_by_gpiote(uint32_t pin) -{ - return (m_cb.pin_assignments[pin] >= 0); -} - -__STATIC_INLINE void pin_in_use_by_te_set(uint32_t pin, - uint32_t channel_id, - nrf_drv_gpiote_evt_handler_t handler, - bool is_channel) -{ - m_cb.pin_assignments[pin] = channel_id; - m_cb.handlers[channel_id] = handler; - if (!is_channel) - { - m_cb.port_handlers_pins[channel_id-NUMBER_OF_GPIO_TE] = (int8_t)pin; - } -} - -__STATIC_INLINE void pin_in_use_set(uint32_t pin) -{ - m_cb.pin_assignments[pin] = PIN_USED; -} - -__STATIC_INLINE void pin_in_use_clear(uint32_t pin) -{ - m_cb.pin_assignments[pin] = PIN_NOT_USED; -} - -__STATIC_INLINE int8_t channel_port_get(uint32_t pin) -{ - return m_cb.pin_assignments[pin]; -} - -__STATIC_INLINE nrf_drv_gpiote_evt_handler_t channel_handler_get(uint32_t channel) -{ - return m_cb.handlers[channel]; -} - -static int8_t channel_port_alloc(uint32_t pin,nrf_drv_gpiote_evt_handler_t handler, bool channel) -{ - int8_t channel_id = NO_CHANNELS; - uint32_t i; - - uint32_t start_idx = channel ? 0 : NUMBER_OF_GPIO_TE; - uint32_t end_idx = channel ? NUMBER_OF_GPIO_TE : (NUMBER_OF_GPIO_TE+GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS); - //critical section - - for (i = start_idx; i < end_idx; i++) - { - if (m_cb.handlers[i] == FORBIDDEN_HANDLER_ADDRESS) - { - pin_in_use_by_te_set(pin, i, handler, channel); - channel_id = i; - break; - } - } - //critical section - return channel_id; -} - -static void channel_free(uint8_t channel_id) -{ - m_cb.handlers[channel_id] = FORBIDDEN_HANDLER_ADDRESS; - if (channel_id >= NUMBER_OF_GPIO_TE) - { - m_cb.port_handlers_pins[channel_id-NUMBER_OF_GPIO_TE] = (int8_t)PIN_NOT_USED; - } -} - -ret_code_t nrf_drv_gpiote_init(void) -{ - if (m_cb.state != NRF_DRV_STATE_UNINITIALIZED) - { - return NRF_ERROR_INVALID_STATE; - } - - uint8_t i; - for (i = 0; i < NUMBER_OF_PINS; i++) - { - pin_in_use_clear(i); - } - for (i = 0; i < (NUMBER_OF_GPIO_TE+GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS); i++) - { - channel_free(i); - } - - nrf_drv_common_irq_enable(GPIOTE_IRQn, GPIOTE_CONFIG_IRQ_PRIORITY); - nrf_gpiote_int_enable(GPIOTE_INTENSET_PORT_Msk); - m_cb.state = NRF_DRV_STATE_INITIALIZED; - - return NRF_SUCCESS; -} - -bool nrf_drv_gpiote_is_init(void) -{ - return (m_cb.state != NRF_DRV_STATE_UNINITIALIZED) ? true : false; -} - -void nrf_drv_gpiote_uninit(void) -{ - ASSERT(m_cb.state!=NRF_DRV_STATE_UNINITIALIZED); - - uint32_t i; - for (i = 0; i < NUMBER_OF_PINS; i++) - { - if (pin_in_use_as_non_task_out(i)) - { - nrf_drv_gpiote_out_uninit(i); - } - else if( pin_in_use_by_gpiote(i)) - { - /* Disable gpiote_in is having the same effect on out pin as gpiote_out_uninit on - * so it can be called on all pins used by GPIOTE. - */ - nrf_drv_gpiote_in_uninit(i); - } - } - m_cb.state = NRF_DRV_STATE_UNINITIALIZED; -} - -ret_code_t nrf_drv_gpiote_out_init(nrf_drv_gpiote_pin_t pin, - nrf_drv_gpiote_out_config_t const * p_config) -{ - ASSERT(pin < NUMBER_OF_PINS); - ASSERT(m_cb.state == NRF_DRV_STATE_INITIALIZED); - ASSERT(p_config); - - ret_code_t result = NRF_SUCCESS; - - if (pin_in_use(pin)) - { - result = NRF_ERROR_INVALID_STATE; - } - else - { - if (p_config->task_pin) - { - int8_t channel = channel_port_alloc(pin, NULL, true); - - if (channel != NO_CHANNELS) - { - nrf_gpiote_task_configure(channel, pin, p_config->action, p_config->init_state); - } - else - { - result = NRF_ERROR_NO_MEM; - } - } - else - { - pin_in_use_set(pin); - } - - if (result == NRF_SUCCESS) - { - if (p_config->init_state == NRF_GPIOTE_INITIAL_VALUE_HIGH) - { - nrf_gpio_pin_set(pin); - } - else - { - nrf_gpio_pin_clear(pin); - } - - nrf_gpio_cfg_output(pin); - } - } - - return result; -} - -void nrf_drv_gpiote_out_uninit(nrf_drv_gpiote_pin_t pin) -{ - ASSERT(pin < NUMBER_OF_PINS); - ASSERT(pin_in_use(pin)); - - if (pin_in_use_by_te(pin)) - { - channel_free((uint8_t)channel_port_get(pin)); - nrf_gpiote_te_default(channel_port_get(pin)); - } - pin_in_use_clear(pin); - - nrf_gpio_cfg_default(pin); -} - -void nrf_drv_gpiote_out_set(nrf_drv_gpiote_pin_t pin) -{ - ASSERT(pin < NUMBER_OF_PINS); - ASSERT(pin_in_use(pin)); - ASSERT(!pin_in_use_by_te(pin)) - - nrf_gpio_pin_set(pin); -} - -void nrf_drv_gpiote_out_clear(nrf_drv_gpiote_pin_t pin) -{ - ASSERT(pin < NUMBER_OF_PINS); - ASSERT(pin_in_use(pin)); - ASSERT(!pin_in_use_by_te(pin)) - - nrf_gpio_pin_clear(pin); -} - -void nrf_drv_gpiote_out_toggle(nrf_drv_gpiote_pin_t pin) -{ - ASSERT(pin < NUMBER_OF_PINS); - ASSERT(pin_in_use(pin)); - ASSERT(!pin_in_use_by_te(pin)) - - nrf_gpio_pin_toggle(pin); -} - -void nrf_drv_gpiote_out_task_enable(nrf_drv_gpiote_pin_t pin) -{ - ASSERT(pin < NUMBER_OF_PINS); - ASSERT(pin_in_use(pin)); - ASSERT(pin_in_use_by_te(pin)) - - nrf_gpiote_task_enable(m_cb.pin_assignments[pin]); -} - -void nrf_drv_gpiote_out_task_disable(nrf_drv_gpiote_pin_t pin) -{ - ASSERT(pin < NUMBER_OF_PINS); - ASSERT(pin_in_use(pin)); - ASSERT(pin_in_use_by_te(pin)) - - nrf_gpiote_task_disable(m_cb.pin_assignments[pin]); -} - -uint32_t nrf_drv_gpiote_out_task_addr_get(nrf_drv_gpiote_pin_t pin) -{ - ASSERT(pin < NUMBER_OF_PINS); - ASSERT(pin_in_use_by_te(pin)); - - nrf_gpiote_tasks_t task = TE_IDX_TO_TASK_ADDR(channel_port_get(pin)); - return nrf_gpiote_task_addr_get(task); -} - -void nrf_drv_gpiote_out_task_force(nrf_drv_gpiote_pin_t pin, uint8_t state) -{ - ASSERT(pin < NUMBER_OF_PINS); - ASSERT(pin_in_use(pin)); - ASSERT(pin_in_use_by_te(pin)); - - nrf_gpiote_outinit_t init_val = state ? NRF_GPIOTE_INITIAL_VALUE_HIGH : NRF_GPIOTE_INITIAL_VALUE_LOW; - nrf_gpiote_task_force(m_cb.pin_assignments[pin], init_val); -} - -void nrf_drv_gpiote_out_task_trigger(nrf_drv_gpiote_pin_t pin) -{ - ASSERT(pin < NUMBER_OF_PINS); - ASSERT(pin_in_use(pin)); - ASSERT(pin_in_use_by_te(pin)); - - nrf_gpiote_tasks_t task = TE_IDX_TO_TASK_ADDR(channel_port_get(pin));; - nrf_gpiote_task_set(task); -} - -ret_code_t nrf_drv_gpiote_in_init(nrf_drv_gpiote_pin_t pin, - nrf_drv_gpiote_in_config_t const * p_config, - nrf_drv_gpiote_evt_handler_t evt_handler) -{ - ASSERT(pin < NUMBER_OF_PINS); - ret_code_t result = NRF_SUCCESS; - /* Only one GPIOTE channel can be assigned to one physical pin. */ - if (pin_in_use_by_gpiote(pin)) - { - result = NRF_ERROR_INVALID_STATE; - } - else - { - int8_t channel = channel_port_alloc(pin, evt_handler, p_config->hi_accuracy); - if (channel != NO_CHANNELS) - { - if (p_config->is_watcher) - { - nrf_gpio_cfg_watcher(pin); - } - else - { - nrf_gpio_cfg_input(pin,p_config->pull); - } - - if (p_config->hi_accuracy) - { - nrf_gpiote_event_configure(channel, pin,p_config->sense); - } - else - { - m_cb.port_handlers_pins[channel-NUMBER_OF_GPIO_TE] |= (p_config->sense)<< SENSE_FIELD_POS; - } - } - else - { - result = NRF_ERROR_NO_MEM; - } - } - return result; -} - -void nrf_drv_gpiote_in_event_enable(nrf_drv_gpiote_pin_t pin, bool int_enable) -{ - ASSERT(pin < NUMBER_OF_PINS); - ASSERT(pin_in_use_by_gpiote(pin)); - if (pin_in_use_by_port(pin)) - { - uint8_t pin_and_sense = m_cb.port_handlers_pins[channel_port_get(pin)-NUMBER_OF_GPIO_TE]; - nrf_gpiote_polarity_t polarity = (nrf_gpiote_polarity_t)(pin_and_sense >> SENSE_FIELD_POS); - nrf_gpio_pin_sense_t sense; - if (polarity == NRF_GPIOTE_POLARITY_TOGGLE) - { - /* read current pin state and set for next sense to oposit */ - sense = (nrf_gpio_pins_read() & (1 << pin)) ? - NRF_GPIO_PIN_SENSE_LOW : NRF_GPIO_PIN_SENSE_HIGH; - } - else - { - sense = (polarity == NRF_GPIOTE_POLARITY_LOTOHI) ? - NRF_GPIO_PIN_SENSE_HIGH : NRF_GPIO_PIN_SENSE_LOW; - } - nrf_gpio_cfg_sense_set(pin,sense); - } - else if(pin_in_use_by_te(pin)) - { - int32_t channel = (int32_t)channel_port_get(pin); - nrf_gpiote_events_t event = TE_IDX_TO_EVENT_ADDR(channel); - - nrf_gpiote_event_enable(channel); - - nrf_gpiote_event_clear(event); - if (int_enable) - { - nrf_drv_gpiote_evt_handler_t handler = channel_handler_get(channel_port_get(pin)); - // Enable the interrupt only if event handler was provided. - if (handler) - { - nrf_gpiote_int_enable(1 << channel); - } - } - } -} - -void nrf_drv_gpiote_in_event_disable(nrf_drv_gpiote_pin_t pin) -{ - ASSERT(pin < NUMBER_OF_PINS); - ASSERT(pin_in_use_by_gpiote(pin)); - if (pin_in_use_by_port(pin)) - { - nrf_gpio_cfg_sense_set(pin,NRF_GPIO_PIN_NOSENSE); - } - else if(pin_in_use_by_te(pin)) - { - int32_t channel = (int32_t)channel_port_get(pin); - nrf_gpiote_event_disable(channel); - nrf_gpiote_int_disable(1 << channel); - } -} - -void nrf_drv_gpiote_in_uninit(nrf_drv_gpiote_pin_t pin) -{ - ASSERT(pin < NUMBER_OF_PINS); - ASSERT(pin_in_use_by_gpiote(pin)); - nrf_drv_gpiote_in_event_disable(pin); - if(pin_in_use_by_te(pin)) - { - nrf_gpiote_te_default(channel_port_get(pin)); - } - nrf_gpio_cfg_default(pin); - channel_free((uint8_t)channel_port_get(pin)); - pin_in_use_clear(pin); -} - -bool nrf_drv_gpiote_in_is_set(nrf_drv_gpiote_pin_t pin) -{ - ASSERT(pin < NUMBER_OF_PINS); - return nrf_gpio_pin_read(pin) ? true : false; -} - -uint32_t nrf_drv_gpiote_in_event_addr_get(nrf_drv_gpiote_pin_t pin) -{ - ASSERT(pin < NUMBER_OF_PINS); - ASSERT(pin_in_use_by_te(pin)); - - nrf_gpiote_events_t event = TE_IDX_TO_EVENT_ADDR(channel_port_get(pin)); - return nrf_gpiote_event_addr_get(event); -} - -void GPIOTE_IRQHandler(void) -{ - uint32_t status = 0; - uint32_t input = 0; - - /* collect status of all GPIOTE pin events. Processing is done once all are collected and cleared.*/ - uint32_t i; - nrf_gpiote_events_t event = NRF_GPIOTE_EVENTS_IN_0; - uint32_t mask = (uint32_t)NRF_GPIOTE_INT_IN0_MASK; - for (i = 0; i < NUMBER_OF_GPIO_TE; i++) - { - if (nrf_gpiote_event_is_set(event) && nrf_gpiote_int_is_enabled(mask)) - { - nrf_gpiote_event_clear(event); - status |= mask; - } - mask <<= 1; - /* Incrementing to next event, utilizing the fact that events are grouped together - * in ascending order. */ - event = (nrf_gpiote_events_t)((uint32_t)event + sizeof(uint32_t)); - } - - /* collect PORT status event, if event is set read pins state. Processing is postponed to the - * end of interrupt. */ - if (nrf_gpiote_event_is_set(NRF_GPIOTE_EVENTS_PORT)) - { - nrf_gpiote_event_clear(NRF_GPIOTE_EVENTS_PORT); - status |= (uint32_t)NRF_GPIOTE_INT_PORT_MASK; - input = nrf_gpio_pins_read(); - } - - /* Process pin events. */ - if (status & NRF_GPIOTE_INT_IN_MASK) - { - mask = (uint32_t)NRF_GPIOTE_INT_IN0_MASK; - for (i = 0; i < NUMBER_OF_GPIO_TE; i++) - { - if (mask & status) - { - nrf_drv_gpiote_pin_t pin = nrf_gpiote_event_pin_get(i); - nrf_gpiote_polarity_t polarity = nrf_gpiote_event_polarity_get(i); - nrf_drv_gpiote_evt_handler_t handler = channel_handler_get(i); - handler(pin,polarity); - } - mask <<= 1; - } - } - - if (status & (uint32_t)NRF_GPIOTE_INT_PORT_MASK) - { - /* Process port event. */ - uint8_t repeat = 0; - uint32_t toggle_mask = 0; - uint32_t pins_to_check = 0xFFFFFFFFuL; - - do - { - repeat = 0; - for (i = 0; i < GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS; i++) - { - uint8_t pin_and_sense = m_cb.port_handlers_pins[i]; - nrf_drv_gpiote_pin_t pin = (pin_and_sense & ~SENSE_FIELD_MASK); - - if ((m_cb.port_handlers_pins[i] != PIN_NOT_USED) - && ((1UL << pin) & pins_to_check)) - { - nrf_gpiote_polarity_t polarity = - (nrf_gpiote_polarity_t)((pin_and_sense & SENSE_FIELD_MASK) >> SENSE_FIELD_POS); - nrf_drv_gpiote_evt_handler_t handler = channel_handler_get(channel_port_get(pin)); - if (handler || polarity == NRF_GPIOTE_POLARITY_TOGGLE) - { - mask = 1 << pin; - if (polarity == NRF_GPIOTE_POLARITY_TOGGLE) - { - toggle_mask |= mask; - } - nrf_gpio_pin_sense_t sense = nrf_gpio_pin_sense_get(pin); - - if (((mask & input) && (sense==NRF_GPIO_PIN_SENSE_HIGH)) || - (!(mask & input) && (sense==NRF_GPIO_PIN_SENSE_LOW)) ) - { - if (polarity == NRF_GPIOTE_POLARITY_TOGGLE) - { - nrf_gpio_pin_sense_t next_sense = (sense == NRF_GPIO_PIN_SENSE_HIGH) ? - NRF_GPIO_PIN_SENSE_LOW : NRF_GPIO_PIN_SENSE_HIGH; - nrf_gpio_cfg_sense_set(pin, next_sense); - ++repeat; - } - if (handler) - { - handler(pin, polarity); - } - } - } - } - } - - if (repeat) - { - // When one of the pins in low-accuracy and toggle mode becomes active, - // it's sense mode is inverted to clear the internal SENSE signal. - // State of any other enabled low-accuracy input in toggle mode must be checked - // explicitly, because it does not trigger the interrput when SENSE signal is active. - // For more information about SENSE functionality, refer to Product Specification. - uint32_t new_input = nrf_gpio_pins_read(); - if (new_input == input) - { - //No change. - repeat = 0; - } - else - { - input = new_input; - pins_to_check = toggle_mask; - } - } - } - while (repeat); - } -} -//lint -restore http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a1481cb2/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/gpiote/nrf_drv_gpiote.h ---------------------------------------------------------------------- diff --git a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/gpiote/nrf_drv_gpiote.h b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/gpiote/nrf_drv_gpiote.h deleted file mode 100644 index efb8bb8..0000000 --- a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/gpiote/nrf_drv_gpiote.h +++ /dev/null @@ -1,317 +0,0 @@ -/* Copyright (c) 2015 Nordic Semiconductor. All Rights Reserved. - * - * The information contained herein is property of Nordic Semiconductor ASA. - * Terms and conditions of usage are described in detail in NORDIC - * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. - * - * Licensees are granted free, non-transferable use of the information. NO - * WARRANTY of ANY KIND is provided. This heading must NOT be removed from - * the file. - * - */ - -#ifndef NRF_DRV_GPIOTE__ -#define NRF_DRV_GPIOTE__ - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @addtogroup nrf_gpiote GPIOTE abstraction and driver - * @ingroup nrf_drivers - * @brief GPIOTE APIs. - * @defgroup nrf_drv_gpiote GPIOTE driver - * @{ - * @ingroup nrf_gpiote - * @brief GPIOTE driver for managing input and output pins. - */ - -#include "nrf_gpiote.h" -#include "nrf_gpio.h" -#include "nrf_drv_config.h" -#include "sdk_errors.h" -#include <stdint.h> -#include <stdbool.h> - -/**@brief Input pin configuration. */ -typedef struct -{ - nrf_gpiote_polarity_t sense; /**< Transition that triggers interrupt. */ - nrf_gpio_pin_pull_t pull; /**< Pulling mode. */ - bool is_watcher; /**< True when the input pin is tracking an output pin. */ - bool hi_accuracy;/**< True when high accuracy (IN_EVENT) is used. */ -} nrf_drv_gpiote_in_config_t; - -/**@brief Macro for configuring a pin to use a GPIO IN or PORT EVENT to detect low-to-high transition. - * @details Set hi_accu to true to use IN_EVENT. */ -#define GPIOTE_CONFIG_IN_SENSE_LOTOHI(hi_accu) \ - { \ - .is_watcher = false, \ - .hi_accuracy = hi_accu, \ - .pull = NRF_GPIO_PIN_NOPULL, \ - .sense = NRF_GPIOTE_POLARITY_LOTOHI, \ - } - -/**@brief Macro for configuring a pin to use a GPIO IN or PORT EVENT to detect high-to-low transition. - * @details Set hi_accu to true to use IN_EVENT. */ -#define GPIOTE_CONFIG_IN_SENSE_HITOLO(hi_accu) \ - { \ - .is_watcher = false, \ - .hi_accuracy = hi_accu, \ - .pull = NRF_GPIO_PIN_NOPULL, \ - .sense = NRF_GPIOTE_POLARITY_HITOLO, \ - } - -/**@brief Macro for configuring a pin to use a GPIO IN or PORT EVENT to detect any change on the pin. - * @details Set hi_accu to true to use IN_EVENT.*/ -#define GPIOTE_CONFIG_IN_SENSE_TOGGLE(hi_accu) \ - { \ - .is_watcher = false, \ - .hi_accuracy = hi_accu, \ - .pull = NRF_GPIO_PIN_NOPULL, \ - .sense = NRF_GPIOTE_POLARITY_TOGGLE, \ - } - -/**@brief Output pin configuration. */ -typedef struct -{ - nrf_gpiote_polarity_t action; /**< Configuration of the pin task. */ - nrf_gpiote_outinit_t init_state; /**< Initial state of the output pin. */ - bool task_pin; /**< True if the pin is controlled by a GPIOTE task. */ -} nrf_drv_gpiote_out_config_t; - -/**@brief Macro for configuring a pin to use as output. GPIOTE is not used for the pin. */ -#define GPIOTE_CONFIG_OUT_SIMPLE(init_high) \ - { \ - .init_state = init_high ? NRF_GPIOTE_INITIAL_VALUE_HIGH : NRF_GPIOTE_INITIAL_VALUE_LOW, \ - .task_pin = false, \ - } - -/**@brief Macro for configuring a pin to use the GPIO OUT TASK to change the state from high to low. - * @details The task will clear the pin. Therefore, the pin is set initially. */ -#define GPIOTE_CONFIG_OUT_TASK_LOW \ - { \ - .init_state = NRF_GPIOTE_INITIAL_VALUE_HIGH, \ - .task_pin = true, \ - .action = NRF_GPIOTE_POLARITY_HITOLO, \ - } - -/**@brief Macro for configuring a pin to use the GPIO OUT TASK to change the state from low to high. - * @details The task will set the pin. Therefore, the pin is cleared initially. */ -#define GPIOTE_CONFIG_OUT_TASK_HIGH \ - { \ - .init_state = NRF_GPIOTE_INITIAL_VALUE_LOW, \ - .task_pin = true, \ - .action = NRF_GPIOTE_POLARITY_LOTOHI, \ - } - -/**@brief Macro for configuring a pin to use the GPIO OUT TASK to toggle the pin state. - * @details The initial pin state must be provided. */ -#define GPIOTE_CONFIG_OUT_TASK_TOGGLE(init_high) \ - { \ - .init_state = init_high ? NRF_GPIOTE_INITIAL_VALUE_HIGH : NRF_GPIOTE_INITIAL_VALUE_LOW, \ - .task_pin = true, \ - .action = NRF_GPIOTE_POLARITY_TOGGLE, \ - } - -/** @brief Pin. */ -typedef uint32_t nrf_drv_gpiote_pin_t; - -/** - * @brief Pin event handler prototype. - * @param pin Pin that triggered this event. - * @param action Action that lead to triggering this event. - */ -typedef void (*nrf_drv_gpiote_evt_handler_t)(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action); - -/** - * @brief Function for initializing the GPIOTE module. - * - * @details Only static configuration is supported to prevent the shared - * resource being customized by the initiator. - * - * @retval NRF_SUCCESS If initialization was successful. - * @retval NRF_ERROR_INVALID_STATE If the driver was already initialized. - */ -ret_code_t nrf_drv_gpiote_init(void); - -/** - * @brief Function for checking if the GPIOTE module is initialized. - * - * @details The GPIOTE module is a shared module. Therefore, you should check if - * the module is already initialized and skip initialization if it is. - * - * @retval true If the module is already initialized. - * @retval false If the module is not initialized. - */ -bool nrf_drv_gpiote_is_init(void); - -/** - * @brief Function for uninitializing the GPIOTE module. - */ -void nrf_drv_gpiote_uninit(void); - -/** - * @brief Function for initializing a GPIOTE output pin. - * @details The output pin can be controlled by the CPU or by PPI. The initial - * configuration specifies which mode is used. If PPI mode is used, the driver - * attempts to allocate one of the available GPIOTE channels. If no channel is - * available, an error is returned. - * - * @param[in] pin Pin. - * @param[in] p_config Initial configuration. - * - * @retval NRF_SUCCESS If initialization was successful. - * @retval NRF_ERROR_INVALID_STATE If the driver is not initialized or the pin is already used. - * @retval NRF_ERROR_NO_MEM If no GPIOTE channel is available. - */ -ret_code_t nrf_drv_gpiote_out_init(nrf_drv_gpiote_pin_t pin, - nrf_drv_gpiote_out_config_t const * p_config); - -/** - * @brief Function for uninitializing a GPIOTE output pin. - * @details The driver frees the GPIOTE channel if the output pin was using one. - * - * @param[in] pin Pin. - */ -void nrf_drv_gpiote_out_uninit(nrf_drv_gpiote_pin_t pin); - -/** - * @brief Function for setting a GPIOTE output pin. - * - * @param[in] pin Pin. - */ -void nrf_drv_gpiote_out_set(nrf_drv_gpiote_pin_t pin); - -/** - * @brief Function for clearing a GPIOTE output pin. - * - * @param[in] pin Pin. - */ -void nrf_drv_gpiote_out_clear(nrf_drv_gpiote_pin_t pin); - -/** - * @brief Function for toggling a GPIOTE output pin. - * - * @param[in] pin Pin. - */ -void nrf_drv_gpiote_out_toggle(nrf_drv_gpiote_pin_t pin); - -/** - * @brief Function for enabling a GPIOTE output pin task. - * - * @param[in] pin Pin. - */ -void nrf_drv_gpiote_out_task_enable(nrf_drv_gpiote_pin_t pin); - -/** - * @brief Function for disabling a GPIOTE output pin task. - * - * @param[in] pin Pin. - */ -void nrf_drv_gpiote_out_task_disable(nrf_drv_gpiote_pin_t pin); - -/** - * @brief Function for getting the address of a configurable GPIOTE task. - * - * @param[in] pin Pin. - */ -uint32_t nrf_drv_gpiote_out_task_addr_get(nrf_drv_gpiote_pin_t pin); - -/** - * @brief Function for initializing a GPIOTE input pin. - * @details The input pin can act in two ways: - * - lower accuracy but low power (high frequency clock not needed) - * - higher accuracy (high frequency clock required) - * - * The initial configuration specifies which mode is used. - * If high-accuracy mode is used, the driver attempts to allocate one - * of the available GPIOTE channels. If no channel is - * available, an error is returned. - * In low accuracy mode SENSE feature is used. In this case only one active pin - * can be detected at a time. It can be worked around by setting all of the used - * low accuracy pins to toggle mode. - * For more information about SENSE functionality, refer to Product Specification. - * - * @param[in] pin Pin. - * @param[in] p_config Initial configuration. - * @param[in] evt_handler User function to be called when the configured transition occurs. - * - * @retval NRF_SUCCESS If initialization was successful. - * @retval NRF_ERROR_INVALID_STATE If the driver is not initialized or the pin is already used. - * @retval NRF_ERROR_NO_MEM If no GPIOTE channel is available. - */ -ret_code_t nrf_drv_gpiote_in_init(nrf_drv_gpiote_pin_t pin, - nrf_drv_gpiote_in_config_t const * p_config, - nrf_drv_gpiote_evt_handler_t evt_handler); - -/** - * @brief Function for uninitializing a GPIOTE input pin. - * @details The driver frees the GPIOTE channel if the input pin was using one. - * - * @param[in] pin Pin. - */ -void nrf_drv_gpiote_in_uninit(nrf_drv_gpiote_pin_t pin); - -/** - * @brief Function for enabling sensing of a GPIOTE input pin. - * - * @details If the input pin is configured as high-accuracy pin, the function - * enables an IN_EVENT. Otherwise, the function enables the GPIO sense mechanism. - * Note that a PORT event is shared between multiple pins, therefore the - * interrupt is always enabled. - * - * @param[in] pin Pin. - * @param[in] int_enable True to enable the interrupt. Always valid for a high-accuracy pin. - */ -void nrf_drv_gpiote_in_event_enable(nrf_drv_gpiote_pin_t pin, bool int_enable); - -/** - * @brief Function for disabling a GPIOTE input pin. - * - * @param[in] pin Pin. - */ -void nrf_drv_gpiote_in_event_disable(nrf_drv_gpiote_pin_t pin); - -/** - * @brief Function for checking if a GPIOTE input pin is set. - * - * @param[in] pin Pin. - * @retval true If the input pin is set. - * @retval false If the input pin is not set. - */ -bool nrf_drv_gpiote_in_is_set(nrf_drv_gpiote_pin_t pin); - -/** - * @brief Function for getting the address of a GPIOTE input pin event. - * @details If the pin is configured to use low-accuracy mode, the address of the PORT event is returned. - * - * @param[in] pin Pin. - */ -uint32_t nrf_drv_gpiote_in_event_addr_get(nrf_drv_gpiote_pin_t pin); - -/** - * @brief Function for forcing a specific state on the pin configured as task. - * - * @param[in] pin Pin. - * @param[in] state Pin state. - */ -void nrf_drv_gpiote_out_task_force(nrf_drv_gpiote_pin_t pin, uint8_t state); - -/** - * @brief Function for triggering the task manually. - * - * @param[in] pin Pin. - */ -void nrf_drv_gpiote_out_task_trigger(nrf_drv_gpiote_pin_t pin); - -/** - *@} - **/ - -#ifdef __cplusplus -} -#endif - -#endif //NRF_DRV_GPIOTE__ http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a1481cb2/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/hal/nrf_adc.c ---------------------------------------------------------------------- diff --git a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/hal/nrf_adc.c b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/hal/nrf_adc.c deleted file mode 100644 index 259db2c..0000000 --- a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/hal/nrf_adc.c +++ /dev/null @@ -1,78 +0,0 @@ -/* Copyright (c) 2014 Nordic Semiconductor. All Rights Reserved. - * - * The information contained herein is property of Nordic Semiconductor ASA. - * Terms and conditions of usage are described in detail in NORDIC - * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. - * - * Licensees are granted free, non-transferable use of the information. NO - * WARRANTY of ANY KIND is provided. This heading must NOT be removed from - * the file. - * - */ - -/** - * @file - * @brief ADC HAL implementation - */ - -#include "nrf_adc.h" - -#ifndef NRF52 - -/** - * @brief Function for configuring ADC. - * - * This function powers on ADC and configures it. ADC is in DISABLE state after configuration, - * so it should be enabled before using it. - * - * @param[in] config Requested configuration. - */ -void nrf_adc_configure(nrf_adc_config_t * config) -{ - uint32_t config_reg = 0; - - config_reg |= ((uint32_t)config->resolution << ADC_CONFIG_RES_Pos) & ADC_CONFIG_RES_Msk; - config_reg |= ((uint32_t)config->scaling << ADC_CONFIG_INPSEL_Pos) & ADC_CONFIG_INPSEL_Msk; - config_reg |= ((uint32_t)config->reference << ADC_CONFIG_REFSEL_Pos) & ADC_CONFIG_REFSEL_Msk; - - if (config->reference & ADC_CONFIG_EXTREFSEL_Msk) - { - config_reg |= config->reference & ADC_CONFIG_EXTREFSEL_Msk; - } - - /* select input */ - nrf_adc_input_select(NRF_ADC_CONFIG_INPUT_DISABLED); - - /* set new configuration keeping selected input */ - NRF_ADC->CONFIG = config_reg | (NRF_ADC->CONFIG & ADC_CONFIG_PSEL_Msk); -} - - -/** - * @brief Blocking function for executing single ADC conversion. - * - * This function selects the desired input, starts a single conversion, - * waits for it to finish, and returns the result. - * ADC is left in STOP state, the given input is selected. - * This function does not check if ADC is initialized and powered. - * - * @param[in] input Requested input to be selected. - * - * @return Conversion result - */ -int32_t nrf_adc_convert_single(nrf_adc_config_input_t input) -{ - int32_t val; - - nrf_adc_input_select(input); - nrf_adc_start(); - - while (!nrf_adc_conversion_finished()) - { - } - nrf_adc_conversion_event_clean(); - val = nrf_adc_result_get(); - nrf_adc_stop(); - return val; -} -#endif http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a1481cb2/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/hal/nrf_adc.h ---------------------------------------------------------------------- diff --git a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/hal/nrf_adc.h b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/hal/nrf_adc.h deleted file mode 100644 index 56fce31..0000000 --- a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/hal/nrf_adc.h +++ /dev/null @@ -1,424 +0,0 @@ -/* Copyright (c) 2014 Nordic Semiconductor. All Rights Reserved. - * - * The information contained herein is property of Nordic Semiconductor ASA. - * Terms and conditions of usage are described in detail in NORDIC - * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. - * - * Licensees are granted free, non-transferable use of the information. NO - * WARRANTY of ANY KIND is provided. This heading must NOT be removed from - * the file. - * - */ - -#ifndef NRF_ADC_H_ -#define NRF_ADC_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @defgroup nrf_adc_hal ADC HAL - * @{ - * @ingroup nrf_adc - * @brief @tagAPI51 Hardware access layer for managing the analog-to-digital converter (ADC). - */ - -#include <stdbool.h> -#include <stddef.h> - -#include "nrf.h" - -#ifndef NRF52 -/** - * @enum nrf_adc_config_resolution_t - * @brief Resolution of the analog-to-digital converter. - */ - -/** - * @brief ADC interrupts. - */ -typedef enum -{ - NRF_ADC_INT_END_MASK = ADC_INTENSET_END_Msk, /**< ADC interrupt on END event. */ -} nrf_adc_int_mask_t; - -typedef enum -{ - NRF_ADC_CONFIG_RES_8BIT = ADC_CONFIG_RES_8bit, /**< 8 bit resolution. */ - NRF_ADC_CONFIG_RES_9BIT = ADC_CONFIG_RES_9bit, /**< 9 bit resolution. */ - NRF_ADC_CONFIG_RES_10BIT = ADC_CONFIG_RES_10bit, /**< 10 bit resolution. */ -} nrf_adc_config_resolution_t; - - -/** - * @enum nrf_adc_config_scaling_t - * @brief Scaling factor of the analog-to-digital conversion. - */ -typedef enum -{ - NRF_ADC_CONFIG_SCALING_INPUT_FULL_SCALE = ADC_CONFIG_INPSEL_AnalogInputNoPrescaling, /**< Full scale input. */ - NRF_ADC_CONFIG_SCALING_INPUT_TWO_THIRDS = ADC_CONFIG_INPSEL_AnalogInputTwoThirdsPrescaling, /**< 2/3 scale input. */ - NRF_ADC_CONFIG_SCALING_INPUT_ONE_THIRD = ADC_CONFIG_INPSEL_AnalogInputOneThirdPrescaling, /**< 1/3 scale input. */ - NRF_ADC_CONFIG_SCALING_SUPPLY_TWO_THIRDS = ADC_CONFIG_INPSEL_SupplyTwoThirdsPrescaling, /**< 2/3 of supply. */ - NRF_ADC_CONFIG_SCALING_SUPPLY_ONE_THIRD = ADC_CONFIG_INPSEL_SupplyOneThirdPrescaling /**< 1/3 of supply. */ -} nrf_adc_config_scaling_t; - -/** - * @enum nrf_adc_config_reference_t - * @brief Reference selection of the analog-to-digital converter. - */ -typedef enum -{ - NRF_ADC_CONFIG_REF_VBG = ADC_CONFIG_REFSEL_VBG, /**< 1.2 V reference. */ - NRF_ADC_CONFIG_REF_SUPPLY_ONE_HALF = ADC_CONFIG_REFSEL_SupplyOneHalfPrescaling, /**< 1/2 of power supply. */ - NRF_ADC_CONFIG_REF_SUPPLY_ONE_THIRD = ADC_CONFIG_REFSEL_SupplyOneThirdPrescaling, /**< 1/3 of power supply. */ - NRF_ADC_CONFIG_REF_EXT_REF0 = ADC_CONFIG_REFSEL_External | - ADC_CONFIG_EXTREFSEL_AnalogReference0 << - ADC_CONFIG_EXTREFSEL_Pos, /**< External reference 0. */ - NRF_ADC_CONFIG_REF_EXT_REF1 = ADC_CONFIG_REFSEL_External | - ADC_CONFIG_EXTREFSEL_AnalogReference1 << ADC_CONFIG_EXTREFSEL_Pos, /**< External reference 0. */ -} nrf_adc_config_reference_t; - -/** - * @enum nrf_adc_config_input_t - * @brief Input selection of the analog-to-digital converter. - */ -typedef enum -{ - NRF_ADC_CONFIG_INPUT_DISABLED = ADC_CONFIG_PSEL_Disabled, /**< No input selected. */ - NRF_ADC_CONFIG_INPUT_0 = ADC_CONFIG_PSEL_AnalogInput0, /**< Input 0. */ - NRF_ADC_CONFIG_INPUT_1 = ADC_CONFIG_PSEL_AnalogInput1, /**< Input 1. */ - NRF_ADC_CONFIG_INPUT_2 = ADC_CONFIG_PSEL_AnalogInput2, /**< Input 2. */ - NRF_ADC_CONFIG_INPUT_3 = ADC_CONFIG_PSEL_AnalogInput3, /**< Input 3. */ - NRF_ADC_CONFIG_INPUT_4 = ADC_CONFIG_PSEL_AnalogInput4, /**< Input 4. */ - NRF_ADC_CONFIG_INPUT_5 = ADC_CONFIG_PSEL_AnalogInput5, /**< Input 5. */ - NRF_ADC_CONFIG_INPUT_6 = ADC_CONFIG_PSEL_AnalogInput6, /**< Input 6. */ - NRF_ADC_CONFIG_INPUT_7 = ADC_CONFIG_PSEL_AnalogInput7, /**< Input 7. */ -} nrf_adc_config_input_t; - -/** - * @enum nrf_adc_task_t - * @brief Analog-to-digital converter tasks. - */ -typedef enum -{ - /*lint -save -e30*/ - NRF_ADC_TASK_START = offsetof(NRF_ADC_Type, TASKS_START), /**< ADC start sampling task. */ - NRF_ADC_TASK_STOP = offsetof(NRF_ADC_Type, TASKS_STOP) /**< ADC stop sampling task. */ - /*lint -restore*/ -} nrf_adc_task_t; - -/** - * @enum nrf_adc_event_t - * @brief Analog-to-digital converter events. - */ -typedef enum /*lint -save -e30 -esym(628,__INTADDR__) */ -{ - /*lint -save -e30*/ - NRF_ADC_EVENT_END = offsetof(NRF_ADC_Type, EVENTS_END) /**< End of conversion event. */ - /*lint -restore*/ -} nrf_adc_event_t; - -/**@brief Analog-to-digital converter configuration. */ -typedef struct -{ - nrf_adc_config_resolution_t resolution; /**< ADC resolution. */ - nrf_adc_config_scaling_t scaling; /**< ADC scaling factor. */ - nrf_adc_config_reference_t reference; /**< ADC reference. */ -} nrf_adc_config_t; - -/** Default ADC configuration. */ -#define NRF_ADC_CONFIG_DEFAULT { NRF_ADC_CONFIG_RES_10BIT, \ - NRF_ADC_CONFIG_SCALING_INPUT_ONE_THIRD, \ - NRF_ADC_CONFIG_REF_VBG } - -/** - * @brief Function for configuring ADC. - * - * This function powers on the analog-to-digital converter and configures it. - * After the configuration, the ADC is in DISABLE state and must be - * enabled before using it. - * - * @param[in] config Configuration parameters. - */ -void nrf_adc_configure(nrf_adc_config_t * config); - -/** - * @brief Blocking function for executing a single ADC conversion. - * - * This function selects the desired input, starts a single conversion, - * waits for it to finish, and returns the result. - * After the input is selected, the analog-to-digital converter - * is left in STOP state. - * The function does not check if the ADC is initialized and powered. - * - * @param[in] input Input to be selected. - * - * @return Conversion result. - */ -int32_t nrf_adc_convert_single(nrf_adc_config_input_t input); - -/** - * @brief Function for selecting ADC input. - * - * This function selects the active input of ADC. Ensure that - * the ADC is powered on and in IDLE state before calling this function. - * - * @param[in] input Input to be selected. - */ -__STATIC_INLINE void nrf_adc_input_select(nrf_adc_config_input_t input) -{ - NRF_ADC->CONFIG = - ((uint32_t)input << ADC_CONFIG_PSEL_Pos) | (NRF_ADC->CONFIG & ~ADC_CONFIG_PSEL_Msk); - - if (input != NRF_ADC_CONFIG_INPUT_DISABLED) - { - NRF_ADC->ENABLE = ADC_ENABLE_ENABLE_Enabled << ADC_ENABLE_ENABLE_Pos; - } - else - { - NRF_ADC->ENABLE = ADC_ENABLE_ENABLE_Disabled << ADC_ENABLE_ENABLE_Pos; - } -} - - -/** - * @brief Function for retrieving the ADC conversion result. - * - * This function retrieves and returns the last analog-to-digital conversion result. - * - * @return Last conversion result. - */ -__STATIC_INLINE int32_t nrf_adc_result_get(void) -{ - return (int32_t)NRF_ADC->RESULT; -} - - -/** - * @brief Function for checking whether the ADC is busy. - * - * This function checks whether the analog-to-digital converter is busy with a conversion. - * - * @retval true If the ADC is busy. - * @retval false If the ADC is not busy. - */ -__STATIC_INLINE bool nrf_adc_is_busy(void) -{ - return ( (NRF_ADC->BUSY & ADC_BUSY_BUSY_Msk) == ADC_BUSY_BUSY_Msk); -} - -/** - * @brief Function for getting the ADC's enabled interrupts. - * - * @param[in] mask Mask of interrupts to check. - * - * @return State of the interrupts selected by the mask. - * - * @sa nrf_adc_int_enable() - * @sa nrf_adc_int_disable() - */ -__STATIC_INLINE uint32_t nrf_adc_int_get(uint32_t mask) -{ - return (NRF_ADC->INTENSET & mask); // when read this register will return the value of INTEN. -} - - -/** - * @brief Function for starting conversion. - * - * @sa nrf_adc_stop() - * - */ -__STATIC_INLINE void nrf_adc_start(void) -{ - NRF_ADC->TASKS_START = 1; -} - - -/** - * @brief Function for stopping conversion. - * - * If the analog-to-digital converter is in inactive state, power consumption is reduced. - * - * @sa nrf_adc_start() - * - */ -__STATIC_INLINE void nrf_adc_stop(void) -{ - NRF_ADC->TASKS_STOP = 1; -} - - -/** - * @brief Function for checking if the requested ADC conversion has ended. - * - * @retval true If the task has finished. - * @retval false If the task is still running. - */ -__STATIC_INLINE bool nrf_adc_conversion_finished(void) -{ - return ((bool)NRF_ADC->EVENTS_END); -} - -/** - * @brief Function for clearing the conversion END event. - */ -__STATIC_INLINE void nrf_adc_conversion_event_clean(void) -{ - NRF_ADC->EVENTS_END = 0; -} - -/** - * @brief Function for getting the address of an ADC task register. - * - * @param[in] adc_task ADC task. - * - * @return Address of the specified ADC task. - */ -__STATIC_INLINE uint32_t nrf_adc_task_address_get(nrf_adc_task_t adc_task); - -/** - * @brief Function for getting the address of a specific ADC event register. - * - * @param[in] adc_event ADC event. - * - * @return Address of the specified ADC event. - */ -__STATIC_INLINE uint32_t nrf_adc_event_address_get(nrf_adc_event_t adc_event); - -/** - * @brief Function for setting the CONFIG register in ADC. - * - * @param[in] configuration Value to be written to the CONFIG register. - */ -__STATIC_INLINE void nrf_adc_config_set(uint32_t configuration); - -/** - * @brief Function for clearing an ADC event. - * - * @param[in] event Event to clear. - */ -__STATIC_INLINE void nrf_adc_event_clear(nrf_adc_event_t event); - -/** - * @brief Function for checking state of an ADC event. - * - * @param[in] event Event to check. - * - * @retval true If the event is set. - * @retval false If the event is not set. - */ -__STATIC_INLINE bool nrf_adc_event_check(nrf_adc_event_t event); - -/** - * @brief Function for enabling specified interrupts. - * - * @param[in] int_mask Interrupts to enable. - */ -__STATIC_INLINE void nrf_adc_int_enable(uint32_t int_mask); - -/** - * @brief Function for disabling specified interrupts. - * - * @param[in] int_mask Interrupts to disable. - */ -__STATIC_INLINE void nrf_adc_int_disable(uint32_t int_mask); - -/** - * @brief Function for retrieving the state of a given interrupt. - * - * @param[in] int_mask Interrupt to check. - * - * @retval true If the interrupt is enabled. - * @retval false If the interrupt is not enabled. - */ -__STATIC_INLINE bool nrf_adc_int_enable_check(nrf_adc_int_mask_t int_mask); - -/** - * @brief Function for activating a specific ADC task. - * - * @param[in] task Task to activate. - */ -__STATIC_INLINE void nrf_adc_task_trigger(nrf_adc_task_t task); - -/** - * @brief Function for enabling ADC. - * - */ -__STATIC_INLINE void nrf_adc_enable(void); - -/** - * @brief Function for disabling ADC. - * - */ -__STATIC_INLINE void nrf_adc_disable(void); - -#ifndef SUPPRESS_INLINE_IMPLEMENTATION - -__STATIC_INLINE uint32_t nrf_adc_task_address_get(nrf_adc_task_t adc_task) -{ - return (uint32_t)((uint8_t *)NRF_ADC + adc_task); -} - -__STATIC_INLINE uint32_t nrf_adc_event_address_get(nrf_adc_event_t adc_event) -{ - return (uint32_t)((uint8_t *)NRF_ADC + adc_event); -} - -__STATIC_INLINE void nrf_adc_config_set(uint32_t configuration) -{ - NRF_ADC->CONFIG = configuration; -} - -__STATIC_INLINE void nrf_adc_event_clear(nrf_adc_event_t event) -{ - *((volatile uint32_t *)((uint8_t *)NRF_ADC + (uint32_t)event)) = 0x0UL; -} - -__STATIC_INLINE bool nrf_adc_event_check(nrf_adc_event_t event) -{ - return (bool)*(volatile uint32_t *)((uint8_t *)NRF_ADC + (uint32_t)event); -} - -__STATIC_INLINE void nrf_adc_int_enable(uint32_t int_mask) -{ - NRF_ADC->INTENSET = int_mask; -} - -__STATIC_INLINE void nrf_adc_int_disable(uint32_t int_mask) -{ - NRF_ADC->INTENCLR = int_mask; -} - -__STATIC_INLINE bool nrf_adc_int_enable_check(nrf_adc_int_mask_t int_mask) -{ - return (bool)(NRF_ADC->INTENSET & int_mask); -} - -__STATIC_INLINE void nrf_adc_task_trigger(nrf_adc_task_t task) -{ - *((volatile uint32_t *)((uint8_t *)NRF_ADC + (uint32_t)task)) = 0x1UL; -} - -__STATIC_INLINE void nrf_adc_enable(void) -{ - NRF_ADC->ENABLE = 1; -} - -__STATIC_INLINE void nrf_adc_disable(void) -{ - NRF_ADC->ENABLE = 0; -} -#endif -#endif /* NRF52 */ -/** - *@} - **/ - -#ifdef __cplusplus -} -#endif - -#endif /* NRF_ADC_H_ */