Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Staging/max32670 #2238

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions drivers/platform/maxim/max32670/maxim_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,38 @@
/************************ Functions Definitions *******************************/
/******************************************************************************/

/**
* @brief Configure the VDDIO level for a SPI interface
* @param desc - the SPI descriptor
* @return 0 in case of success, -EINVAL otherwise
*/
static int32_t _max_spi_config_pins(struct no_os_spi_desc *desc)
{
struct max_spi_init_param *eparam;
mxc_gpio_cfg_t spi_pins;

eparam = desc->extra;

switch(desc->device_id) {
case 0:
spi_pins = gpio_cfg_spi0;
break;
case 1:
spi_pins = gpio_cfg_spi1;
break;
case 2:
spi_pins = gpio_cfg_spi2;
break;
default:
return -EINVAL;
}

spi_pins.vssel = eparam->vssel;
MXC_GPIO_Config(&spi_pins);

return 0;
}
Comment on lines +65 to +90
Copy link
Contributor

@CiprianRegus CiprianRegus Jul 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be worth mentioning in the commit message that MAX32670 only has 1 CS per SPI instance (which is already included in the gpio_cfg_spi pin config structs), so we don't need to configure it independently, as for the other Maxim drivers.


static int _max_spi_config(struct no_os_spi_desc *desc)
{
int32_t ret;
Expand All @@ -72,6 +104,10 @@ static int _max_spi_config(struct no_os_spi_desc *desc)
goto err_init;
}

ret = _max_spi_config_pins(desc);
if (ret)
return ret;

ret = MXC_SPI_SetMode(MXC_SPI_GET_SPI(desc->device_id),
(mxc_spi_mode_t)desc->mode);
if (ret) {
Expand Down
1 change: 1 addition & 0 deletions drivers/platform/maxim/max32670/maxim_spi.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ enum spi_ss_polarity {
struct max_spi_init_param {
uint32_t num_slaves;
enum spi_ss_polarity polarity;
mxc_gpio_vssel_t vssel;
};

#endif
41 changes: 39 additions & 2 deletions drivers/platform/maxim/max32670/maxim_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,39 @@ void uart_rx_callback(void *context)
max_uart_read_nonblocking(d, &c, 1);
}

/**
* @brief Configure the VDDIO for the UART pins.
* @param device_id - the interface number.
* @param vssel - the voltage level of the interface.
* @return 0 in case of success, -EINVAL otherwise.
*/
static int32_t _max_uart_pins_config(uint32_t device_id, mxc_gpio_vssel_t vssel)
{
mxc_gpio_cfg_t uart_pins;

switch (device_id) {
case 0:
uart_pins = gpio_cfg_uart0;
break;
case 1:
uart_pins = gpio_cfg_uart1;
break;
case 2:
uart_pins = gpio_cfg_uart2;
break;
case 3:
uart_pins = gpio_cfg_uart3;
break;
default:
return -EINVAL;
}

uart_pins.vssel = vssel;
MXC_GPIO_Config(&uart_pins);

return 0;
}

/**
* @brief Initialize the UART communication peripheral.
* @param desc - The UART descriptor.
Expand Down Expand Up @@ -302,10 +335,10 @@ static int32_t max_uart_init(struct no_os_uart_desc **desc,
}

switch (eparam->flow) {
case MAX_UART_FLOW_DIS:
case UART_FLOW_DIS:
flow = MXC_UART_FLOW_DIS;
break;
case MAX_UART_FLOW_EN:
case UART_FLOW_EN:
flow = MXC_UART_FLOW_EN;
break;
default:
Expand All @@ -319,6 +352,10 @@ static int32_t max_uart_init(struct no_os_uart_desc **desc,
goto error;
}

ret = _max_uart_pins_config(descriptor->device_id, eparam->vssel);
if (ret)
goto error;

ret = MXC_UART_SetDataSize(uart_regs, size);
if (ret != E_NO_ERROR) {
ret = -EINVAL;
Expand Down
5 changes: 3 additions & 2 deletions drivers/platform/maxim/max32670/maxim_uart.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,16 @@
* @brief UART flow control
*/
enum max_uart_flow_ctrl {
MAX_UART_FLOW_DIS,
MAX_UART_FLOW_EN
UART_FLOW_DIS,
UART_FLOW_EN
};

/**
* @brief Aditional UART config parameters
*/
struct max_uart_init_param {
enum max_uart_flow_ctrl flow;
mxc_gpio_vssel_t vssel;
};

/**
Expand Down