File tree 1 file changed +12
-0
lines changed
1 file changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -114,10 +114,22 @@ int microbit_hal_pin_get_pull(int pin) {
114
114
}
115
115
116
116
int microbit_hal_pin_set_analog_period_us (int pin, int period) {
117
+ // Change the audio virtual-pin period if the pin is the special mixer pin.
117
118
if (pin == MICROBIT_HAL_PIN_MIXER) {
118
119
uBit.audio .virtualOutputPin .setAnalogPeriodUs (period);
119
120
return 0 ;
120
121
}
122
+
123
+ // Calling setAnalogPeriodUs requires the pin to be in analog-out mode. So
124
+ // test for this mode by first calling getAnalogPeriodUs, and if it fails then
125
+ // attempt to configure the pin in analog-out mode by calling setAnalogValue.
126
+ if ((ErrorCode)pin_obj[pin]->getAnalogPeriodUs () == DEVICE_NOT_SUPPORTED) {
127
+ if (pin_obj[pin]->setAnalogValue (0 ) != DEVICE_OK) {
128
+ return -1 ;
129
+ }
130
+ }
131
+
132
+ // Set the analog period.
121
133
if (pin_obj[pin]->setAnalogPeriodUs (period) == DEVICE_OK) {
122
134
return 0 ;
123
135
} else {
You can’t perform that action at this time.
0 commit comments