2020-11-22 14:20:16 +01:00
|
|
|
/****************************************************************************
|
2019-08-19 17:16:08 +02:00
|
|
|
* boards/arm/stm32/stm32butterfly2/src/stm32_spi.c
|
2016-08-15 17:34:43 +02:00
|
|
|
*
|
2021-06-11 06:47:35 +02:00
|
|
|
* 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
|
2016-08-15 17:34:43 +02:00
|
|
|
*
|
2021-06-11 06:47:35 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2016-08-15 17:34:43 +02:00
|
|
|
*
|
2021-06-11 06:47:35 +02:00
|
|
|
* 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.
|
2016-08-15 17:34:43 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-11-22 14:20:16 +01:00
|
|
|
/****************************************************************************
|
2016-08-15 17:34:43 +02:00
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-11-22 14:21:08 +01:00
|
|
|
#include <inttypes.h>
|
2016-08-17 21:53:04 +02:00
|
|
|
#include <debug.h>
|
2016-08-15 17:34:43 +02:00
|
|
|
#include <nuttx/spi/spi.h>
|
|
|
|
|
|
|
|
#include "stm32_butterfly2.h"
|
|
|
|
#include "stm32_gpio.h"
|
|
|
|
#include "stm32_spi.h"
|
|
|
|
|
2020-11-22 14:20:16 +01:00
|
|
|
/****************************************************************************
|
2016-08-15 17:34:43 +02:00
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-11-22 14:20:16 +01:00
|
|
|
/****************************************************************************
|
2016-08-15 17:34:43 +02:00
|
|
|
* Name: stm32_spidev_initialize
|
|
|
|
*
|
|
|
|
* Description:
|
2016-08-17 21:34:51 +02:00
|
|
|
* Called to configure SPI chip select GPIO pins.
|
2016-08-15 17:34:43 +02:00
|
|
|
*
|
|
|
|
* Note:
|
2016-08-17 21:34:51 +02:00
|
|
|
* Here only CS pins are configured as SPI pins are configured by driver
|
|
|
|
* itself.
|
2016-08-15 17:34:43 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void stm32_spidev_initialize(void)
|
|
|
|
{
|
2016-08-17 21:53:04 +02:00
|
|
|
spiinfo("INFO: Initializing spi gpio pins\n");
|
2016-08-18 19:29:48 +02:00
|
|
|
|
2016-08-15 17:34:43 +02:00
|
|
|
stm32_configgpio(GPIO_SD_CS);
|
|
|
|
stm32_configgpio(GPIO_SD_CD);
|
|
|
|
}
|
|
|
|
|
2020-11-22 14:20:16 +01:00
|
|
|
/****************************************************************************
|
2016-08-15 17:34:43 +02:00
|
|
|
* Name: stm32_spi1select
|
|
|
|
*
|
|
|
|
* Description:
|
2016-08-17 21:34:51 +02:00
|
|
|
* Function asserts given devid based on select
|
2016-08-15 17:34:43 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
2017-04-28 18:26:05 +02:00
|
|
|
void stm32_spi1select(struct spi_dev_s *dev, uint32_t devid,
|
2016-08-17 22:07:10 +02:00
|
|
|
bool select)
|
2016-08-15 17:34:43 +02:00
|
|
|
{
|
2020-11-22 14:21:08 +01:00
|
|
|
spiinfo("INFO: Selecting spi dev: %" PRId32 ", state: %d\n",
|
|
|
|
devid, select);
|
2016-08-18 19:29:48 +02:00
|
|
|
|
2017-04-29 20:26:52 +02:00
|
|
|
if (devid == SPIDEV_MMCSD(0))
|
2016-08-15 17:34:43 +02:00
|
|
|
{
|
|
|
|
stm32_gpiowrite(GPIO_SD_CS, !select);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-22 14:20:16 +01:00
|
|
|
/****************************************************************************
|
2016-08-15 17:34:43 +02:00
|
|
|
* Name: stm32_spi1status
|
|
|
|
*
|
|
|
|
* Description:
|
2016-08-17 21:34:51 +02:00
|
|
|
* Return status of devid
|
2016-08-15 17:34:43 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
2017-04-28 18:26:05 +02:00
|
|
|
uint8_t stm32_spi1status(struct spi_dev_s *dev, uint32_t devid)
|
2016-08-15 17:34:43 +02:00
|
|
|
{
|
2020-11-22 14:21:08 +01:00
|
|
|
spiinfo("INFO: Requesting info from spi dev: %" PRId32 "\n", devid);
|
2016-08-18 19:29:48 +02:00
|
|
|
|
2017-04-29 20:26:52 +02:00
|
|
|
if (devid == SPIDEV_MMCSD(0))
|
2016-08-15 17:34:43 +02:00
|
|
|
{
|
|
|
|
if (stm32_gpioread(GPIO_SD_CD) == 0)
|
|
|
|
{
|
|
|
|
return SPI_STATUS_PRESENT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-18 19:29:48 +02:00
|
|
|
return 0;
|
2016-08-15 17:34:43 +02:00
|
|
|
}
|