/*------------------------------------------------------------------------------ -- This file is a part of the libuc, microcontroler library -- Copyright (C) 2013, Alexis Jeandet -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 3 of the License, or -- (at your option) any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; if not, write to the Free Software -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ------------------------------------------------------------------------------- -- Author : Alexis Jeandet -- Mail : alexis.jeandet@member.fsf.org -------------------------------------------------------------------------------*/ #include "bsp.h" #include #include #include #include #include #include #include #include #include #include #define GPIOGETPORT(gpio) ((GPIO_TypeDef*)(((((uint32_t)gpio) & (uint32_t)0x0000FF00)*(uint32_t)4) + (uint32_t)GPIOA)) #define GPIOPORTNUM(gpio) (((uint32_t)(gpio) & (uint32_t)0x0000FF00)>>(uint32_t)8) void bsp_spi_init() { gpio_t VSSPI_DBxList[]={VS1053SCK,VS1053MOSI,VS1053MISO}; for(int i=0;i<3;i++) { gpio_t SPI_DBx = gpioopen(VSSPI_DBxList[i]); SPI_DBx |= gpiohighspeed | gpioaf | gpiopushpulltype | gpionopulltype; gpiosetconfig(&SPI_DBx); GPIO_PinAFConfig(GPIOGETPORT(SPI_DBx), (uint8_t)(SPI_DBx & 0xF), GPIO_AF_SPI1); } spiopenandconfig(VS1053SPI,spi8bits|spimaster|spimsbfirst,2*1000*1000,VS1053MOSI,VS1053MISO,VS1053SCK,-1); gpio_t SDSPI_DBxList[]={SDCARD2SCK,SDCARD2MOSI,SDCARD2MISO}; for(int i=0;i<3;i++) { gpio_t SPI_DBx = gpioopen(SDSPI_DBxList[i]); SPI_DBx |= gpiohighspeed | gpioaf | gpiopushpulltype | gpionopulltype; gpiosetconfig(&SPI_DBx); GPIO_PinAFConfig(GPIOGETPORT(SPI_DBx), (uint8_t)(SPI_DBx & 0xF), GPIO_AF_SPI3); } spiopenandconfig(SDCARD2SPI,spi8bits|spimaster|spimsbfirst,400*1000,SDCARD2MOSI,SDCARD2MISO,SDCARD2SCK,-1); gpio_t TCSPI_DBxList[]={TC_CLK,TC_DIN,TC_DOUT}; for(int i=0;i<3;i++) { gpio_t SPI_DBx = gpioopen(TCSPI_DBxList[i]); SPI_DBx |= gpiohighspeed | gpioaf | gpiopushpulltype | gpionopulltype; gpiosetconfig(&SPI_DBx); GPIO_PinAFConfig(GPIOGETPORT(SPI_DBx), (uint8_t)(SPI_DBx & 0xF), GPIO_AF_SPI2); } spiopenandconfig(TC_SPI,spi8bits|spimaster|spimsbfirst,500*1000,TC_DIN,TC_DOUT,TC_CLK,-1); }