Skip to content

Commit 57b261c

Browse files
author
Marcus Chang
committed
Update analogin_api.c for NRF52 SDK 14.2
Use new SDK API and fixed return value to be normalized to 16 bit as per the Mbed HAL specification.
1 parent a6dba4d commit 57b261c

File tree

7 files changed

+290
-96
lines changed

7 files changed

+290
-96
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright (c) 2018 Nordic Semiconductor ASA
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without modification,
6+
* are permitted provided that the following conditions are met:
7+
*
8+
* 1. Redistributions of source code must retain the above copyright notice, this list
9+
* of conditions and the following disclaimer.
10+
*
11+
* 2. Redistributions in binary form, except as embedded into a Nordic Semiconductor ASA
12+
* integrated circuit in a product or a software update for such product, must reproduce
13+
* the above copyright notice, this list of conditions and the following disclaimer in
14+
* the documentation and/or other materials provided with the distribution.
15+
*
16+
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its contributors may be
17+
* used to endorse or promote products derived from this software without specific prior
18+
* written permission.
19+
*
20+
* 4. This software, with or without modification, must only be used with a
21+
* Nordic Semiconductor ASA integrated circuit.
22+
*
23+
* 5. Any software provided in binary or object form under this license must not be reverse
24+
* engineered, decompiled, modified and/or disassembled.
25+
*
26+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
27+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
28+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
30+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
31+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
33+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36+
*
37+
*/
38+
39+
#ifndef MBED_PERIPHERALPINS_H
40+
#define MBED_PERIPHERALPINS_H
41+
42+
#include "pinmap.h"
43+
#include "PeripheralNames.h"
44+
45+
#if DEVICE_ANALOGIN
46+
/************ADC***************/
47+
extern const PinMap PinMap_ADC[];
48+
#endif
49+
50+
#endif // MBED_PERIPHERALPINS_H
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright (c) 2018 Nordic Semiconductor ASA
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without modification,
6+
* are permitted provided that the following conditions are met:
7+
*
8+
* 1. Redistributions of source code must retain the above copyright notice, this list
9+
* of conditions and the following disclaimer.
10+
*
11+
* 2. Redistributions in binary form, except as embedded into a Nordic Semiconductor ASA
12+
* integrated circuit in a product or a software update for such product, must reproduce
13+
* the above copyright notice, this list of conditions and the following disclaimer in
14+
* the documentation and/or other materials provided with the distribution.
15+
*
16+
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its contributors may be
17+
* used to endorse or promote products derived from this software without specific prior
18+
* written permission.
19+
*
20+
* 4. This software, with or without modification, must only be used with a
21+
* Nordic Semiconductor ASA integrated circuit.
22+
*
23+
* 5. Any software provided in binary or object form under this license must not be reverse
24+
* engineered, decompiled, modified and/or disassembled.
25+
*
26+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
27+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
28+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
30+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
31+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
33+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36+
*
37+
*/
38+
39+
#include "PeripheralPins.h"
40+
41+
typedef enum {
42+
NRF_SAADC_CHANNEL_0 = 0,
43+
NRF_SAADC_CHANNEL_1 = 1,
44+
NRF_SAADC_CHANNEL_2 = 2,
45+
NRF_SAADC_CHANNEL_3 = 3,
46+
NRF_SAADC_CHANNEL_4 = 4,
47+
NRF_SAADC_CHANNEL_5 = 5,
48+
NRF_SAADC_CHANNEL_6 = 6,
49+
NRF_SAADC_CHANNEL_7 = 7,
50+
} nrf_saadc_channel_t;
51+
52+
/************ADC***************/
53+
/* The third "function" value is used to select the correct ADC channel */
54+
#if DEVICE_ANALOGIN
55+
const PinMap PinMap_ADC[] = {
56+
{ p2, ADC0_0, NRF_SAADC_CHANNEL_0 },
57+
{ p3, ADC0_0, NRF_SAADC_CHANNEL_1 },
58+
{ p4, ADC0_0, NRF_SAADC_CHANNEL_2 },
59+
{ p5, ADC0_0, NRF_SAADC_CHANNEL_3 },
60+
{ p28, ADC0_0, NRF_SAADC_CHANNEL_4 },
61+
{ p29, ADC0_0, NRF_SAADC_CHANNEL_5 },
62+
{ p30, ADC0_0, NRF_SAADC_CHANNEL_6 },
63+
{ p31, ADC0_0, NRF_SAADC_CHANNEL_7 },
64+
{ NC, NC, NC }
65+
};
66+
#endif

targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52832/config/sdk_config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2501,7 +2501,7 @@
25012501
// <3=> 14 bit
25022502

25032503
#ifndef SAADC_CONFIG_RESOLUTION
2504-
#define SAADC_CONFIG_RESOLUTION 1
2504+
#define SAADC_CONFIG_RESOLUTION 2
25052505
#endif
25062506

25072507
// <o> SAADC_CONFIG_OVERSAMPLE - Sample period
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright (c) 2018 Nordic Semiconductor ASA
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without modification,
6+
* are permitted provided that the following conditions are met:
7+
*
8+
* 1. Redistributions of source code must retain the above copyright notice, this list
9+
* of conditions and the following disclaimer.
10+
*
11+
* 2. Redistributions in binary form, except as embedded into a Nordic Semiconductor ASA
12+
* integrated circuit in a product or a software update for such product, must reproduce
13+
* the above copyright notice, this list of conditions and the following disclaimer in
14+
* the documentation and/or other materials provided with the distribution.
15+
*
16+
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its contributors may be
17+
* used to endorse or promote products derived from this software without specific prior
18+
* written permission.
19+
*
20+
* 4. This software, with or without modification, must only be used with a
21+
* Nordic Semiconductor ASA integrated circuit.
22+
*
23+
* 5. Any software provided in binary or object form under this license must not be reverse
24+
* engineered, decompiled, modified and/or disassembled.
25+
*
26+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
27+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
28+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
30+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
31+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
33+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36+
*
37+
*/
38+
39+
#include "PeripheralPins.h"
40+
41+
typedef enum {
42+
NRF_SAADC_CHANNEL_0 = 0,
43+
NRF_SAADC_CHANNEL_1 = 1,
44+
NRF_SAADC_CHANNEL_2 = 2,
45+
NRF_SAADC_CHANNEL_3 = 3,
46+
NRF_SAADC_CHANNEL_4 = 4,
47+
NRF_SAADC_CHANNEL_5 = 5,
48+
NRF_SAADC_CHANNEL_6 = 6,
49+
NRF_SAADC_CHANNEL_7 = 7,
50+
} nrf_saadc_channel_t;
51+
52+
/************ADC***************/
53+
/* The third "function" value is used to select the correct ADC channel */
54+
#if DEVICE_ANALOGIN
55+
const PinMap PinMap_ADC[] = {
56+
{ p2, ADC0_0, NRF_SAADC_CHANNEL_0 },
57+
{ p3, ADC0_0, NRF_SAADC_CHANNEL_1 },
58+
{ p4, ADC0_0, NRF_SAADC_CHANNEL_2 },
59+
{ p5, ADC0_0, NRF_SAADC_CHANNEL_3 },
60+
{ p28, ADC0_0, NRF_SAADC_CHANNEL_4 },
61+
{ p29, ADC0_0, NRF_SAADC_CHANNEL_5 },
62+
{ p30, ADC0_0, NRF_SAADC_CHANNEL_6 },
63+
{ p31, ADC0_0, NRF_SAADC_CHANNEL_7 },
64+
{ NC, NC, NC }
65+
};
66+
#endif

targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52840/config/sdk_config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2501,7 +2501,7 @@
25012501
// <3=> 14 bit
25022502

25032503
#ifndef SAADC_CONFIG_RESOLUTION
2504-
#define SAADC_CONFIG_RESOLUTION 1
2504+
#define SAADC_CONFIG_RESOLUTION 2
25052505
#endif
25062506

25072507
// <o> SAADC_CONFIG_OVERSAMPLE - Sample period

0 commit comments

Comments
 (0)