diff --git a/boards/obelix_dvt/defconfig b/boards/obelix_dvt/defconfig index c47ff8cc4..287f34f04 100644 --- a/boards/obelix_dvt/defconfig +++ b/boards/obelix_dvt/defconfig @@ -80,6 +80,9 @@ CONFIG_RNG_SF32LB=y CONFIG_CPUMODE=y CONFIG_CPUMODE_SF32LB=y +CONFIG_DMA=y +CONFIG_DMA_SF32LB=y + CONFIG_DYNAMIC_BACKLIGHT=y CONFIG_ACCEL_SENSITIVITY=y CONFIG_APP_SCALING=y diff --git a/boards/obelix_pvt/defconfig b/boards/obelix_pvt/defconfig index aed68942c..bd37a190b 100644 --- a/boards/obelix_pvt/defconfig +++ b/boards/obelix_pvt/defconfig @@ -80,6 +80,9 @@ CONFIG_RNG_SF32LB=y CONFIG_CPUMODE=y CONFIG_CPUMODE_SF32LB=y +CONFIG_DMA=y +CONFIG_DMA_SF32LB=y + CONFIG_DYNAMIC_BACKLIGHT=y CONFIG_ACCEL_SENSITIVITY=y CONFIG_APP_SCALING=y diff --git a/src/fw/drivers/Kconfig b/src/fw/drivers/Kconfig index 623a8627d..2c10e4527 100644 --- a/src/fw/drivers/Kconfig +++ b/src/fw/drivers/Kconfig @@ -7,6 +7,7 @@ rsource "ambient/Kconfig" rsource "backlight/Kconfig" rsource "battery/Kconfig" rsource "cpumode/Kconfig" +rsource "dma/Kconfig" rsource "display/Kconfig" rsource "exti/Kconfig" rsource "flash/Kconfig" diff --git a/src/fw/drivers/dma/Kconfig b/src/fw/drivers/dma/Kconfig new file mode 100644 index 000000000..c01571335 --- /dev/null +++ b/src/fw/drivers/dma/Kconfig @@ -0,0 +1,21 @@ +# SPDX-FileCopyrightText: 2026 Core Devices LLC +# SPDX-License-Identifier: Apache-2.0 + +menuconfig DMA + bool "DMA" + help + DMA Drivers + +if DMA + +config DMA_NRF5 + bool "Nordic nRF5 DMA Controller" + help + Support for the Nordic nRF5 DMA controller. + +config DMA_SF32LB + bool "SiFli SF32LB DMA Controller" + help + Support for the SiFli SF32LB DMA controller. + +endif # DMA \ No newline at end of file diff --git a/src/fw/drivers/dma/sf32lb.c b/src/fw/drivers/dma/sf32lb.c new file mode 100644 index 000000000..022345387 --- /dev/null +++ b/src/fw/drivers/dma/sf32lb.c @@ -0,0 +1,75 @@ +/* SPDX-FileCopyrightText: 2026 Core Devices LLC */ +/* SPDX-License-Identifier: Apache-2.0 */ + +#include +#include + +#include "board/board.h" + +#include + +#include "sf32lb.h" + +#define DMA_CHANNEL_NUM 8U + +struct DMARequest { + DMA_HandleTypeDef *handle; +}; + +static DMADirectRequestHandler handlers[DMA_CHANNEL_NUM]; +static DMACircularRequestHandler circular_handlers[DMA_CHANNEL_NUM]; + +static void dma_cplt_callback(DMA_HandleTypeDef *hdma) +{ + DMARequest *this = (DMARequest *)hdma->Parent; //container_of? + + if (handlers[hdma->ChannelIndex] != NULL) + handlers[hdma->ChannelIndex](this, NULL); +} + +void dma_request_init(DMARequest *this) +{ + HAL_DMA_Init(this->handle); +} + +void dma_request_start_direct(DMARequest *this, void *dst, const void *src, uint32_t length, + DMADirectRequestHandler handler, void *context) +{ + HAL_DMA_RegisterCallback(this->handle, HAL_DMA_XFER_CPLT_CB_ID, dma_cplt_callback); + handlers[this->handle->ChannelIndex] = handler; + HAL_DMA_Start_IT(this->handle, (uint32_t)src, (uint32_t)dst, length); +} + +void dma_request_start_circular(DMARequest *this, void *dst, const void *src, uint32_t length, + DMACircularRequestHandler handler, void *context) +{ + HAL_DMA_RegisterCallback(this->handle, HAL_DMA_XFER_CPLT_CB_ID, dma_cplt_callback); + circular_handlers[this->handle->ChannelIndex] = handler; + HAL_DMA_Start_IT(this->handle, (uint32_t)src, (uint32_t)dst, length); +} + +void dma_request_stop(DMARequest *this) +{ + HAL_DMA_Abort(this->handle); +} + +bool dma_request_in_progress(DMARequest *this) +{ + return (HAL_DMA_GetState(this->handle) == HAL_DMA_STATE_BUSY); +} + +uint32_t dma_request_get_current_data_counter(DMARequest *this) +{ + return 0; +// return HAL_DMA_GetCurrentDataCounter(this->handle); +} + +bool dma_request_get_and_clear_transfer_error(DMARequest *this) +{ + return false; +} + +void dma_request_set_memory_increment_disabled(DMARequest *this, bool disabled) +{ + +} diff --git a/src/fw/drivers/dma/sf32lb.h b/src/fw/drivers/dma/sf32lb.h new file mode 100644 index 000000000..d2851d812 --- /dev/null +++ b/src/fw/drivers/dma/sf32lb.h @@ -0,0 +1,6 @@ +/* SPDX-FileCopyrightText: 2026 Core Devices LLC */ +/* SPDX-License-Identifier: Apache-2.0 */ + + + + diff --git a/src/fw/drivers/dma/wscript_build b/src/fw/drivers/dma/wscript_build new file mode 100644 index 000000000..312168b91 --- /dev/null +++ b/src/fw/drivers/dma/wscript_build @@ -0,0 +1,19 @@ +# SPDX-FileCopyrightText: 2026 Core Devices LLC +# SPDX-License-Identifier: Apache-2.0 + +use = ['freertos', 'fw_includes'] + +if bld.env.CONFIG_DMA_NRF5: + use.append('hal_nordic') + sources.append('nrf5.c') +elif bld.env.CONFIG_DMA_SF32LB: + use.append('hal_sifli') + sources.append('sf32lb.c') + +bld.objects( + name='driver_dma', + source=sources, + use=use, +) + +bld.env.DRIVERS.append('driver_dma') \ No newline at end of file diff --git a/src/fw/drivers/stubs/dma.c b/src/fw/drivers/stubs/dma.c new file mode 100644 index 000000000..0ae33d6b7 --- /dev/null +++ b/src/fw/drivers/stubs/dma.c @@ -0,0 +1,56 @@ +/* SPDX-FileCopyrightText: 2026 Core Devices LLC */ +/* SPDX-License-Identifier: Apache-2.0 */ + +#include +#include + +#include "drivers/dma.h" + +T_STATIC DMADirectRequestHandler handlers[DMA_CHANNEL_NUM]; + +static void dma_cplt_callback(DMA_HandleTypeDef *hdma) +{ + +} + +void dma_request_init(DMARequest *this) +{ + +} + +void dma_request_start_direct(DMARequest *this, void *dst, const void *src, uint32_t length, + DMADirectRequestHandler handler, void *context) +{ + +} + +void dma_request_start_circular(DMARequest *this, void *dst, const void *src, uint32_t length, + DMACircularRequestHandler handler, void *context) +{ + +} + +void dma_request_stop(DMARequest *this) +{ + +} + +bool dma_request_in_progress(DMARequest *this) +{ + return true; +} + +uint32_t dma_request_get_current_data_counter(DMARequest *this) +{ + return 0; +} + +bool dma_request_get_and_clear_transfer_error(DMARequest *this); +{ + return true; +} + +void dma_request_set_memory_increment_disabled(DMARequest *this, bool disabled) +{ + +} diff --git a/src/fw/drivers/wscript_build b/src/fw/drivers/wscript_build index 017c72aee..b438a5e16 100644 --- a/src/fw/drivers/wscript_build +++ b/src/fw/drivers/wscript_build @@ -381,4 +381,7 @@ bld( use=bld.env.DRIVERS, ) +if bld.env.CONFIG_DMA: + bld.recurse('dma') + # vim:filetype=python