Skip to content

Commit adf15c8

Browse files
committed
CR of AnalogIn
1 parent 9d137c8 commit adf15c8

File tree

1 file changed

+5
-16
lines changed
  • hal/targets/hal/TARGET_NORDIC/TARGET_NRF5/TARGET_MCU_NRF52832

1 file changed

+5
-16
lines changed

hal/targets/hal/TARGET_NORDIC/TARGET_NRF5/TARGET_MCU_NRF52832/analogin_api.c

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
#include "mbed_assert.h"
1718
#include "analogin_api.h"
1819
#include "cmsis.h"
@@ -57,27 +58,15 @@ void analogin_init(analogin_t *obj, PinName pin)
5758
MBED_ASSERT(ret_code == NRF_SUCCESS);
5859
}
5960

60-
/**
61-
* NRF52 SAR ADC module provides measurement with sign.
62-
* Already mbed API dosn't support readout of signed integer value.
63-
*/
64-
static int16_t analogin_read_i16(analogin_t *obj)
61+
62+
uint16_t analogin_read_u16(analogin_t *obj)
6563
{
66-
nrf_saadc_value_t adc_value;
64+
int16_t adc_value;
6765
ret_code_t ret_code;
6866

6967
ret_code = nrf_drv_saadc_sample_convert(obj->adc_pin, &adc_value);
7068
MBED_ASSERT(ret_code == NRF_SUCCESS);
7169

72-
return adc_value;
73-
}
74-
75-
uint16_t analogin_read_u16(analogin_t *obj)
76-
{
77-
int16_t adc_value;
78-
79-
adc_value = analogin_read_i16(obj);
80-
8170
if (adc_value < 0)
8271
{
8372
// Even in the single ended mode measured value can be {-0}. Saturation for avoid casting to a big integer.
@@ -91,7 +80,7 @@ uint16_t analogin_read_u16(analogin_t *obj)
9180

9281
float analogin_read(analogin_t *obj)
9382
{
94-
int16_t value = analogin_read_i16(obj);
83+
uint16_t value = analogin_read_u16(obj);
9584
return (float)value * (1.0f / (float)ADC_RANGE);
9685
}
9786

0 commit comments

Comments
 (0)