Skip to content

Commit 9714718

Browse files
committed
nRF5x: Leave digital input disconnected for analog read (saves power)
nRF5x: Return 'analog' as pin mode for any pin where input is disconnected
1 parent 621368d commit 9714718

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

ChangeLog

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
Fix Array.fill crash if used to fill up all available memory (fix #1668)
44
Fix NRF.requestDevice regression (clearInterval error) (fix #1669)
55
Smartibot devices now advertise on BLE as 'Smartibot abcd'
6+
nRF5x: Leave digital input disconnected for analog read (saves power)
7+
nRF5x: Return 'analog' as pin mode for any pin where input is disconnected
68

79
2v03 : nRF5x: Fix issue when calling NRF.setAdvertising while connected via BLE (fix #1659)
810
nRF5x: 'dump()' not outputs `NRF.setSecurity` line if it has been called.

targets/nrf5x/jshardware.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,7 @@ void jshPinSetState(Pin pin, JshPinState state) {
696696
#endif
697697
switch (state) {
698698
case JSHPINSTATE_UNDEFINED :
699+
case JSHPINSTATE_ADC_IN :
699700
reg->PIN_CNF[ipin] = (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos)
700701
| (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos)
701702
| (GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos)
@@ -728,7 +729,6 @@ void jshPinSetState(Pin pin, JshPinState state) {
728729
| (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos);
729730
break;
730731
case JSHPINSTATE_GPIO_IN :
731-
case JSHPINSTATE_ADC_IN :
732732
case JSHPINSTATE_USART_IN :
733733
nrf_gpio_cfg_input(ipin, NRF_GPIO_PIN_NOPULL);
734734
break;
@@ -784,13 +784,14 @@ JshPinState jshPinGetState(Pin pin) {
784784
return JSHPINSTATE_GPIO_OUT|hi;
785785
}
786786
} else {
787+
bool pinConnected = ((p&GPIO_PIN_CNF_INPUT_Msk)>>GPIO_PIN_CNF_INPUT_Pos) == GPIO_PIN_CNF_INPUT_Connect;
787788
// Input
788789
if ((p&GPIO_PIN_CNF_PULL_Msk)==(GPIO_PIN_CNF_PULL_Pullup<<GPIO_PIN_CNF_PULL_Pos)) {
789790
return negated ? JSHPINSTATE_GPIO_IN_PULLDOWN : JSHPINSTATE_GPIO_IN_PULLUP;
790791
} else if ((p&GPIO_PIN_CNF_PULL_Msk)==(GPIO_PIN_CNF_PULL_Pulldown<<GPIO_PIN_CNF_PULL_Pos)) {
791792
return negated ? JSHPINSTATE_GPIO_IN_PULLUP : JSHPINSTATE_GPIO_IN_PULLDOWN;
792793
} else {
793-
return JSHPINSTATE_GPIO_IN;
794+
return pinConnected ? JSHPINSTATE_GPIO_IN : JSHPINSTATE_ADC_IN;
794795
}
795796
}
796797
}

0 commit comments

Comments
 (0)