vrmay23 commented on code in PR #18397: URL: https://github.com/apache/nuttx/pull/18397#discussion_r2809982479
########## boards/arm/stm32h7/nucleo-h753zi/src/stm32_spi.c: ########## @@ -0,0 +1,1037 @@ +/**************************************************************************** + * boards/arm/stm32h7/nucleo-h753zi/src/stm32_spi.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> +#include <stddef.h> +#include <stdbool.h> +#include <string.h> +#include <stdlib.h> +#include <errno.h> +#include <debug.h> +#include <nuttx/spi/spi.h> +#include <arch/board/board.h> +#include "stm32_gpio.h" +#include "stm32_spi.h" +#include "nucleo-h753zi.h" +#include <nuttx/spi/spi_transfer.h> + +#ifdef CONFIG_STM32H7_SPI + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define MAX_CS_DEVICES_PER_SPI 16 +#define INVALID_CS_PIN 0 + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/* CS pin registration structure */ + +struct spi_cs_device_s +{ + uint32_t gpio_config; /* GPIO configuration for CS pin */ + bool active_low; /* true = active low, false = active high */ + bool in_use; /* true = slot occupied */ +}; + +/* DC pin registration structure */ + +#ifdef CONFIG_SPI_CMDDATA +struct spi_dc_device_s +{ + uint32_t gpio_config; /* GPIO configuration for DC pin */ + bool in_use; /* true = slot occupied */ +}; +#endif + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/* CS device registrations for each SPI bus */ + +#ifdef CONFIG_STM32H7_SPI1 +static struct spi_cs_device_s g_spi1_cs_devices[MAX_CS_DEVICES_PER_SPI]; +#ifdef CONFIG_SPI_CMDDATA +static struct spi_dc_device_s g_spi1_dc_devices[MAX_CS_DEVICES_PER_SPI]; +#endif +#endif + +#ifdef CONFIG_STM32H7_SPI2 +static struct spi_cs_device_s g_spi2_cs_devices[MAX_CS_DEVICES_PER_SPI]; +#ifdef CONFIG_SPI_CMDDATA +static struct spi_dc_device_s g_spi2_dc_devices[MAX_CS_DEVICES_PER_SPI]; +#endif +#endif + +#ifdef CONFIG_STM32H7_SPI3 +static struct spi_cs_device_s g_spi3_cs_devices[MAX_CS_DEVICES_PER_SPI]; +#ifdef CONFIG_SPI_CMDDATA +static struct spi_dc_device_s g_spi3_dc_devices[MAX_CS_DEVICES_PER_SPI]; +#endif +#endif + +#ifdef CONFIG_STM32H7_SPI4 +static struct spi_cs_device_s g_spi4_cs_devices[MAX_CS_DEVICES_PER_SPI]; +#ifdef CONFIG_SPI_CMDDATA +static struct spi_dc_device_s g_spi4_dc_devices[MAX_CS_DEVICES_PER_SPI]; +#endif +#endif + +#ifdef CONFIG_STM32H7_SPI5 +static struct spi_cs_device_s g_spi5_cs_devices[MAX_CS_DEVICES_PER_SPI]; +#ifdef CONFIG_SPI_CMDDATA +static struct spi_dc_device_s g_spi5_dc_devices[MAX_CS_DEVICES_PER_SPI]; +#endif +#endif + +#ifdef CONFIG_STM32H7_SPI6 +static struct spi_cs_device_s g_spi6_cs_devices[MAX_CS_DEVICES_PER_SPI]; +#ifdef CONFIG_SPI_CMDDATA +static struct spi_dc_device_s g_spi6_dc_devices[MAX_CS_DEVICES_PER_SPI]; +#endif +#endif + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: parse_gpio_pin + * + * Description: + * Parse GPIO pin string like "PA0" into STM32 GPIO configuration. + * + * Input Parameters: + * pin_str - GPIO pin string (e.g., "PA0", "PF15", "PC13") + * error - Pointer to error code storage + * + * Returned Value: + * STM32 GPIO configuration value on success, 0 on error + * + ****************************************************************************/ + +static uint32_t parse_gpio_pin(FAR const char *pin_str, FAR int *error) Review Comment: The same question; why not? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
