Skip to content

Commit cd142d5

Browse files
Chris Nourseclaude
andcommitted
ports/stm: reuse existing translations and shared deinit guard in audioio
Address review feedback on PR #10976: - Replace 11 audioio-specific MP_ERROR_TEXT strings with existing pot entries via %q substitution (Invalid %q pin, %q init failed) or by reusing analogio/AnalogOut's "DAC Device/Channel Init Error". - Drop the redundant in-driver deinit check in common_hal_audioio_audioout_play(); the shared-bindings layer already guards every entry point with check_for_deinit -> raise_deinited_error. - Net result: zero new entries in locale/circuitpython.pot. - Also remove tests/circuitpython-manual/audioio/results.md (committed in a prior commit; the test scripts stay, the captured run output shouldn't live in the repo). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 0f28c94 commit cd142d5

3 files changed

Lines changed: 15 additions & 553 deletions

File tree

locale/circuitpython.pot

Lines changed: 3 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ msgid "%q indices must be integers, not %s"
140140
msgstr ""
141141

142142
#: ports/analog/common-hal/busio/SPI.c ports/analog/common-hal/busio/UART.c
143+
#: ports/stm/common-hal/audioio/AudioOut.c
143144
#: shared-bindings/digitalio/DigitalInOutProtocol.c
144145
#: shared-module/busdisplay/BusDisplay.c
145146
msgid "%q init failed"
@@ -630,18 +631,6 @@ msgstr ""
630631
msgid "Audio source error"
631632
msgstr ""
632633

633-
#: ports/stm/common-hal/audioio/AudioOut.c
634-
msgid "AudioOut is deinited"
635-
msgstr ""
636-
637-
#: ports/stm/common-hal/audioio/AudioOut.c
638-
msgid "AudioOut requires pin A0 (PA04)"
639-
msgstr ""
640-
641-
#: ports/stm/common-hal/audioio/AudioOut.c
642-
msgid "AudioOut right channel requires pin A1 (PA05)"
643-
msgstr ""
644-
645634
#: shared-bindings/wifi/Radio.c
646635
msgid "AuthMode.OPEN is not used with password"
647636
msgstr ""
@@ -901,41 +890,19 @@ msgid "Critical ROS failure during soft reboot, reset required: %d"
901890
msgstr ""
902891

903892
#: ports/stm/common-hal/analogio/AnalogOut.c
904-
msgid "DAC Channel Init Error"
905-
msgstr ""
906-
907893
#: ports/stm/common-hal/audioio/AudioOut.c
908-
msgid "DAC DMA start failed"
909-
msgstr ""
910-
911-
#: ports/stm/common-hal/audioio/AudioOut.c
912-
msgid "DAC DMA start failed (right channel)"
894+
msgid "DAC Channel Init Error"
913895
msgstr ""
914896

915897
#: ports/stm/common-hal/analogio/AnalogOut.c
898+
#: ports/stm/common-hal/audioio/AudioOut.c
916899
msgid "DAC Device Init Error"
917900
msgstr ""
918901

919902
#: ports/atmel-samd/common-hal/audioio/AudioOut.c
920903
msgid "DAC already in use"
921904
msgstr ""
922905

923-
#: ports/stm/common-hal/audioio/AudioOut.c
924-
msgid "DAC channel config error"
925-
msgstr ""
926-
927-
#: ports/stm/common-hal/audioio/AudioOut.c
928-
msgid "DAC init error"
929-
msgstr ""
930-
931-
#: ports/stm/common-hal/audioio/AudioOut.c
932-
msgid "DMA init failed"
933-
msgstr ""
934-
935-
#: ports/stm/common-hal/audioio/AudioOut.c
936-
msgid "DMA init failed (right)"
937-
msgstr ""
938-
939906
#: ports/atmel-samd/common-hal/paralleldisplaybus/ParallelBus.c
940907
#: ports/nordic/common-hal/paralleldisplaybus/ParallelBus.c
941908
msgid "Data 0 pin must be byte aligned"
@@ -2146,14 +2113,6 @@ msgstr ""
21462113
msgid "System entry must be gnss.SatelliteSystem"
21472114
msgstr ""
21482115

2149-
#: ports/stm/common-hal/audioio/AudioOut.c
2150-
msgid "TIM6 init failed"
2151-
msgstr ""
2152-
2153-
#: ports/stm/common-hal/audioio/AudioOut.c
2154-
msgid "TIM6 master cfg failed"
2155-
msgstr ""
2156-
21572116
#: ports/stm/common-hal/microcontroller/Processor.c
21582117
msgid "Temperature read timed out"
21592118
msgstr ""

ports/stm/common-hal/audioio/AudioOut.c

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -339,12 +339,12 @@ void common_hal_audioio_audioout_construct(audioio_audioout_obj_t *self,
339339

340340
// Only PA04 (DAC_CH1) is supported as left channel.
341341
if (left_channel != &pin_PA04) {
342-
mp_raise_ValueError(MP_ERROR_TEXT("AudioOut requires pin A0 (PA04)"));
342+
raise_ValueError_invalid_pin_name(MP_QSTR_left_channel);
343343
}
344344

345345
// Right channel must be PA05 (DAC_CH2 / A1) if provided.
346346
if (right_channel != NULL && right_channel != &pin_PA05) {
347-
mp_raise_ValueError(MP_ERROR_TEXT("AudioOut right channel requires pin A1 (PA05)"));
347+
raise_ValueError_invalid_pin_name(MP_QSTR_right_channel);
348348
}
349349

350350
// Claim pins first. The pin-claim system is what serialises this driver
@@ -393,7 +393,7 @@ void common_hal_audioio_audioout_construct(audioio_audioout_obj_t *self,
393393
__HAL_RCC_DAC_CLK_ENABLE();
394394
handle.Instance = DAC;
395395
if (HAL_DAC_Init(&handle) != HAL_OK) {
396-
mp_raise_ValueError(MP_ERROR_TEXT("DAC init error"));
396+
mp_raise_ValueError(MP_ERROR_TEXT("DAC Device Init Error"));
397397
}
398398
}
399399

@@ -403,7 +403,7 @@ void common_hal_audioio_audioout_construct(audioio_audioout_obj_t *self,
403403
ch_cfg.DAC_Trigger = DAC_TRIGGER_NONE;
404404
ch_cfg.DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE;
405405
if (HAL_DAC_ConfigChannel(&handle, &ch_cfg, DAC_CHANNEL_1) != HAL_OK) {
406-
mp_raise_ValueError(MP_ERROR_TEXT("DAC channel config error"));
406+
mp_raise_ValueError(MP_ERROR_TEXT("DAC Channel Init Error"));
407407
}
408408

409409
// Ramp DAC output up to quiescent value to prevent an audible pop.
@@ -447,9 +447,8 @@ void common_hal_audioio_audioout_deinit(audioio_audioout_obj_t *self) {
447447

448448
void common_hal_audioio_audioout_play(audioio_audioout_obj_t *self,
449449
mp_obj_t sample, bool loop) {
450-
if (common_hal_audioio_audioout_deinited(self)) {
451-
mp_raise_ValueError(MP_ERROR_TEXT("AudioOut is deinited"));
452-
}
450+
// The shared-bindings layer guards every entry point with
451+
// check_for_deinit, so a deinited self can't reach this function.
453452
common_hal_audioio_audioout_stop(self);
454453

455454
// Extract sample format metadata via the canonical accessors so the
@@ -536,15 +535,15 @@ void common_hal_audioio_audioout_play(audioio_audioout_obj_t *self,
536535
tim6_handle.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
537536
tim6_handle.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
538537
if (HAL_TIM_Base_Init(&tim6_handle) != HAL_OK) {
539-
mp_raise_RuntimeError(MP_ERROR_TEXT("TIM6 init failed"));
538+
mp_raise_RuntimeError_varg(MP_ERROR_TEXT("%q init failed"), MP_QSTR_TIM6);
540539
}
541540

542541
// TRGO = Update event → triggers DAC conversion each period.
543542
TIM_MasterConfigTypeDef master_cfg = {0};
544543
master_cfg.MasterOutputTrigger = TIM_TRGO_UPDATE;
545544
master_cfg.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
546545
if (HAL_TIMEx_MasterConfigSynchronization(&tim6_handle, &master_cfg) != HAL_OK) {
547-
mp_raise_RuntimeError(MP_ERROR_TEXT("TIM6 master cfg failed"));
546+
mp_raise_RuntimeError_varg(MP_ERROR_TEXT("%q init failed"), MP_QSTR_TIM6);
548547
}
549548
// NOTE: ports/atmel-samd's audio_dma_setup_playback handles AUDIO_DMA_OK
550549
// and two specific error codes but lets any other non-OK return fall
@@ -582,7 +581,7 @@ void common_hal_audioio_audioout_play(audioio_audioout_obj_t *self,
582581
hdma->Init.Priority = DMA_PRIORITY_VERY_HIGH;
583582
hdma->Init.FIFOMode = DMA_FIFOMODE_DISABLE;
584583
if (HAL_DMA_Init(hdma) != HAL_OK) {
585-
mp_raise_RuntimeError(MP_ERROR_TEXT("DMA init failed"));
584+
mp_raise_RuntimeError_varg(MP_ERROR_TEXT("%q init failed"), MP_QSTR_DMA);
586585
}
587586
__HAL_LINKDMA(&handle, DMA_Handle1, *hdma);
588587

@@ -605,7 +604,7 @@ void common_hal_audioio_audioout_play(audioio_audioout_obj_t *self,
605604
hdma_r->Init.Priority = DMA_PRIORITY_VERY_HIGH;
606605
hdma_r->Init.FIFOMode = DMA_FIFOMODE_DISABLE;
607606
if (HAL_DMA_Init(hdma_r) != HAL_OK) {
608-
mp_raise_RuntimeError(MP_ERROR_TEXT("DMA init failed (right)"));
607+
mp_raise_RuntimeError_varg(MP_ERROR_TEXT("%q init failed"), MP_QSTR_DMA);
609608
}
610609
__HAL_LINKDMA(&handle, DMA_Handle2, *hdma_r);
611610

@@ -630,7 +629,7 @@ void common_hal_audioio_audioout_play(audioio_audioout_obj_t *self,
630629
}
631630
m_free(self->dma_buffer);
632631
self->dma_buffer = NULL;
633-
mp_raise_RuntimeError(MP_ERROR_TEXT("DAC DMA start failed"));
632+
mp_raise_RuntimeError_varg(MP_ERROR_TEXT("%q init failed"), MP_QSTR_DAC);
634633
}
635634

636635
if (self->right_channel != NULL) {
@@ -646,7 +645,7 @@ void common_hal_audioio_audioout_play(audioio_audioout_obj_t *self,
646645
self->dma_buffer = NULL;
647646
m_free(self->dma_buffer_r);
648647
self->dma_buffer_r = NULL;
649-
mp_raise_RuntimeError(MP_ERROR_TEXT("DAC DMA start failed (right channel)"));
648+
mp_raise_RuntimeError_varg(MP_ERROR_TEXT("%q init failed"), MP_QSTR_DAC);
650649
}
651650
}
652651

0 commit comments

Comments
 (0)