Skip to content

Commit

Permalink
projects:ad4170_iio: Update no-OS drivers
Browse files Browse the repository at this point in the history
Sync up with no-OS changes

Apply Astyle

Reduce SPI frequency to a realistic value

Signed-off-by: Janani Sunil <[email protected]>
  • Loading branch information
jansunil committed Nov 21, 2024
1 parent 2ca7262 commit 08a8053
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 36 deletions.
32 changes: 7 additions & 25 deletions projects/ad4170_iio/app/ad4170_iio.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "no_os_delay.h"
#include "common.h"
#include "iio_trigger.h"
#include "no_os_gpio.h"

#if (INTERFACE_MODE == TDM_MODE)
#include "stm32_tdm_support.h"
Expand Down Expand Up @@ -376,12 +377,6 @@ struct pl_gui_desc *pocket_lab_gui_desc;
/* STM32 SPI Init params */
struct stm32_spi_init_param* spi_init_param;

/* Rx DMA channel descriptor */
struct no_os_dma_ch* rxch;

/* Tx DMA channel descriptor */
struct no_os_dma_ch* txch;

/* Global Pointer for IIO Device Data */
volatile struct iio_device_data* iio_dev_data_g;

Expand Down Expand Up @@ -1535,7 +1530,7 @@ int32_t debug_reg_write(void *dev, uint32_t reg, uint32_t writeval)
uint32_t reg_addr_offset; // Offset of input register address from its base
uint32_t data; // Register data

if (!dev || (reg > MAX_REGISTER_ADDRESS)) {
if(!dev || (reg > MAX_REGISTER_ADDRESS)) {
return -EINVAL;
}

Expand Down Expand Up @@ -1986,7 +1981,7 @@ static int32_t ad4170_read_burst_data_spi_dma(uint32_t nb_of_samples,
};

ret = no_os_spi_transfer_dma_async(p_ad4170_dev_inst->spi_desc, &ad4170_spi_msg,
1, ad4170_spi_dma_rx_cplt_callback, NULL);
1, NULL, NULL);
if (ret) {
return ret;
}
Expand Down Expand Up @@ -2282,7 +2277,7 @@ static int32_t iio_ad4170_prepare_transfer(void *dev_instance,
/* Ignore num_of_active_channels-1 samples if more than
* one channel is enabled */
if (num_of_active_channels > 2) {
num_samples_ignore = num_of_active_channels - 2;
num_samples_ignore = num_of_active_channels-2;
} else {
num_samples_ignore = 2;
}
Expand Down Expand Up @@ -2327,22 +2322,9 @@ static int32_t iio_ad4170_prepare_transfer(void *dev_instance,
spi_init_param = ad4170_user_config_params.spi_init.extra;
spi_init_param->dma_init = &ad4170_dma_init_param;

rxch = (struct no_os_dma_ch*)no_os_calloc(1, sizeof(*rxch));
if (!rxch) {
return -ENOMEM;
}

txch = (struct no_os_dma_ch*)no_os_calloc(1, sizeof(*txch));
if (!txch) {
return -ENOMEM;
}

rxch->irq_num = Rx_DMA_IRQ_ID;
rxch->extra = &rxdma_channel;
txch->extra = &txdma_channel;

spi_init_param->rxdma_ch = rxch;
spi_init_param->txdma_ch = txch;
spi_init_param->irq_num = Rx_DMA_IRQ_ID;
spi_init_param->rxdma_ch = &rxdma_channel;
spi_init_param->txdma_ch = &txdma_channel;

/* Init SPI interface in DMA Mode */
ret = no_os_spi_init(&p_ad4170_dev_inst->spi_desc,
Expand Down
2 changes: 1 addition & 1 deletion projects/ad4170_iio/app/ad4170_loadcell_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ struct ad4170_init_param ad4170_loadcell_config_params = {
* configurations on it such as setup, pin mapping, etc)
**/
#if defined(FOUR_WIRE_LOAD_CELL)
.channel_en = AD4170_CHANNEL(0) | AD4170_CHANNEL(1) | \
.channel_en = AD4170_CHANNEL(0) | AD4170_CHANNEL(1) |\
AD4170_CHANNEL(2) | AD4170_CHANNEL(3),
#else
.channel_en = AD4170_CHANNEL(0) | AD4170_CHANNEL(1),
Expand Down
2 changes: 1 addition & 1 deletion projects/ad4170_iio/app/ad4170_thermistor_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ struct ad4170_init_param ad4170_thermistor_config_params = {
/* Enabled Channel0 (channel must be enabled to apply init
* configurations on it such as setup, pin mapping, etc)
**/
.channel_en = AD4170_CHANNEL(0) | AD4170_CHANNEL(1) | \
.channel_en = AD4170_CHANNEL(0) | AD4170_CHANNEL(1) |\
AD4170_CHANNEL(2) | AD4170_CHANNEL(3),

/* Channel setup */
Expand Down
2 changes: 1 addition & 1 deletion projects/ad4170_iio/app/ad4170_user_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ static int32_t fir_coefficients[AD4170_FIR_LENGTH] = {
734, -1046, -1562, 1080, 2798, -646, -4404, -586, 6192, 2968,
-7754, -6788, 8454, 12154, -7434, -18858, 3696, 26242, 3752,
-33122, -15692, 37742, 32442, -37850, -53622, 30836, 77916, -13954
- 102932, -15458, 125088, 59824, - 139536, -121452, 139872, 203270,
-102932, -15458, 125088, 59824, - 139536, -121452, 139872, 203270,
-117090, -311224, 55864, 462102, 80366, -717918, -437946, 1492796, 3494708
};

Expand Down
11 changes: 8 additions & 3 deletions projects/ad4170_iio/app/app_config_stm32.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,11 @@ struct stm32_pwm_init_param stm32_tx_trigger_extra_init_params = {
.timer_chn = TIMER_CHANNEL_1,
.complementary_channel = false,
.get_timer_clock = HAL_RCC_GetPCLK1Freq,
.clock_divider = TIMER_8_CLK_DIVIDER
.clock_divider = TIMER_8_CLK_DIVIDER,
.trigger_output = PWM_TRGO_UPDATE,
.dma_enable = true,
.repetitions = BYTES_PER_SAMPLE-1,
.onepulse_enable = true
};

/* Value of RXDMA NDTR Reg */
Expand Down Expand Up @@ -255,7 +259,7 @@ void ad4170_spi_dma_rx_cplt_callback(DMA_HandleTypeDef* hdma)
#if (DATA_CAPTURE_MODE == BURST_DATA_CAPTURE)
if (dma_cycle_count) {
/* Copy second half of the data to the IIO buffer */
memcpy((void*)iio_buf_current_idx, dma_buf_current_idx, rxdma_ndtr / 2);
memcpy((void*)iio_buf_current_idx, dma_buf_current_idx, rxdma_ndtr/2);

dma_buf_current_idx = dma_buf_start_idx;
iio_buf_current_idx += rxdma_ndtr / 2;
Expand Down Expand Up @@ -389,6 +393,7 @@ void tim8_init(struct no_os_pwm_desc *pwm_desc)

struct stm32_pwm_desc *spwm_desc = pwm_desc->extra;

spwm_desc->htimer.Instance->RCR = BYTES_PER_SAMPLE - 1;
TIM8->SMCR = TIM_SMCR_ETP | TIM_MASTERSLAVEMODE_ENABLE | TIM_SLAVEMODE_TRIGGER|
TIM_TS_ETRF;
#endif
}
3 changes: 1 addition & 2 deletions projects/ad4170_iio/app/app_config_stm32.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
/******************************************************************************/
/***************************** Include Files **********************************/
/******************************************************************************/

#include "main.h"
#include "stm32_spi.h"
#include "stm32_i2c.h"
Expand Down Expand Up @@ -149,7 +148,7 @@
#define TICKER_INTERRUPT_PERIOD_uSEC (0) // unused

/* Max SPI Speed */
#define AD4170_MAX_SPI_SPEED 22500000
#define AD4170_MAX_SPI_SPEED 11250000

/******************************************************************************/
/********************** Public/Extern Declarations ****************************/
Expand Down
2 changes: 1 addition & 1 deletion projects/ad4170_iio/app/stm32_gpio_irq_generated.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ int stm32_get_exti_irq_id_from_pin(uint8_t pin_nb, IRQn_Type *irq_id)
/* Note: The irq_id number used here are specific to STM32H563ZIT6 MCU
* on the Nucleo-H563ZI Board.
* The below parameters will change depending on the controller used. */
switch (pin_nb) {
switch(pin_nb) {
case 8:
*irq_id = EXTI8_IRQn;
break;
Expand Down
4 changes: 2 additions & 2 deletions projects/ad4170_iio/app/stm32_tdm_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ int32_t start_tdm_dma_to_cb_transfer(struct no_os_tdm_desc *tdm_desc,
/* Prepare Circular Buffer for a write operation- retrieve the
* pointer to the circular buffer */
ret = no_os_cb_prepare_async_write(iio_dev_data->buffer->buf,
buffer_size * bytes_per_sample,
buffer_size*bytes_per_sample,
&dma_buff, &buff_available_size);
if (ret) {
return ret;
Expand Down Expand Up @@ -108,7 +108,7 @@ int32_t end_tdm_dma_to_cb_transfer(struct no_os_tdm_desc *tdm_desc,
* updated pointer to the circular buffer post one cycle of buffer
* write overflow */
ret = no_os_cb_prepare_async_write(iio_dev_data->buffer->buf,
buffer_size * bytes_per_sample,
buffer_size*bytes_per_sample,
&dma_buff, &buff_available_size);
if (ret) {
return ret;
Expand Down

0 comments on commit 08a8053

Please sign in to comment.