Skip to content

Commit

Permalink
ports/psoc6: Read API enablement.
Browse files Browse the repository at this point in the history
Signed-off-by: NikhitaR-IFX <[email protected]>
  • Loading branch information
NikhitaR-IFX committed Oct 7, 2024
1 parent cfc284c commit 23e42cb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
17 changes: 16 additions & 1 deletion ports/psoc6/machine_pdm_pcm.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
cyhal_clock_t pdm_pcm_audio_clock;

#if MICROPY_PY_MACHINE_PDM_PCM_RING_BUF

static void ringbuf_init(ring_buf_t *rbuf, uint8_t *buffer, size_t size) {
rbuf->buffer = buffer;
rbuf->size = size;
Expand Down Expand Up @@ -113,7 +114,6 @@ static uint32_t fill_appbuf_from_ringbuf(machine_pdm_pcm_obj_t *self, mp_buffer_
}
app_p += appbuf_sample_size_in_bytes;
}
exit:
return num_bytes_copied_to_appbuf;
}

Expand Down Expand Up @@ -339,6 +339,21 @@ static void pdm_pcm_start_rx(machine_pdm_pcm_obj_t *self) {
pdm_pcm_assert_raise_val("PDM_PCM start failed with return code %lx !", result);
}

int8_t get_frame_mapping_index(int8_t bits, format_t format) {
if ((format == MONO_LEFT) | (format == MONO_RIGHT)) {
if (bits == 16) {
return 0;
} else { // 32 bits
return 1;
}
} else { // STEREO
if (bits == 16) {
return 2;
} else { // 32 bits
return 3;
}
}
}
// =======================================================================================
// MPY bindings for PDM_PCM (ports/psoc6)

Expand Down
9 changes: 9 additions & 0 deletions ports/psoc6/machine_pdm_pcm.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,13 @@ static machine_pdm_pcm_obj_t *mp_machine_pdm_pcm_make_new_instance(mp_int_t pdm_
static void mp_machine_pdm_pcm_init(machine_pdm_pcm_obj_t *self);
static void mp_machine_pdm_pcm_deinit(machine_pdm_pcm_obj_t *self);


static const int8_t pdm_pcm_frame_map[4][PDM_PCM_RX_FRAME_SIZE_IN_BYTES] = {
{ 0, 1, -1, -1, -1, -1, -1, -1 }, // Mono, 16-bits
{ 0, 1, 2, 3, -1, -1, -1, -1 }, // Mono, 32-bits
{ 0, 1, -1, -1, 2, 3, -1, -1 }, // Stereo, 16-bits
{ 0, 1, 2, 3, 4, 5, 6, 7 }, // Stereo, 32-bits
};
int8_t get_frame_mapping_index(int8_t bits, format_t format);

#endif // MICROPY_PY_MACHINE_PDM_PCM

0 comments on commit 23e42cb

Please sign in to comment.