[f80c36]: init.c  Maximize  Restore  History

Download this file

62 lines (50 with data), 2.1 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
Copyright (C) 2011 Georg Ottinger
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 2
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "includes.h"
void InitGPIO()
{
VS1053_GPIO_SPI->DDR |= VS1053_PIN_CS;
VS1053_GPIO_SPI->CR1 |= VS1053_PIN_CS; //Push Pull
VS1053_GPIO_CTRL->DDR |= VS1053_PIN_RESET;
VS1053_GPIO_CTRL->CR1 |= VS1053_PIN_RESET;
VS1053_GPIO_CTRL->CR2 |= VS1053_PIN_DREQ | VS1053_PIN_BSYNC; //pullups
GPIOB->DDR = 0xff; // Led Left
GPIOE->DDR |= 0x0f; // Led Right 0-3
GPIOG->DDR |= 0x03; // Led Right 4-5
GPIOE->DDR |= 0x20; // Led Right 6
GPIOD->DDR |= 0x01; // Led Right 7
GPIOA->CR2 |= GPIO_PIN_5; //Xport RTS
// GPIOA->DDR |= GPIO_PIN_6;
// GPIOA->CR1 |= GPIO_PIN_6; //Xport CTS
// GPIOA->ODR |= GPIO_PIN_6;
VS1053_SPI_CS_OFF;
//All other Pins are Input by default
}
void InitCPUSpeed()
{
CLK->SWCR |= CLK_SWCR_SWEN; //finalize clock source change
CLK->SWR = (u8)CLK_SOURCE_HSE; //choose external Oszilator
while(!(CLK->SWCR & CLK_SWCR_SWIF)) //wait for Clock to settle
// CLK->SWCR |= CLK_SWCR_SWEN; //finalize clock source change
CLK->CKDIVR = 0; // prescaler for Internal Clock and CPU Clock is 1
//the internal Bus and the CPU should now run at the speed of the external Oszillator
}
void InitSPI(SPI_BaudRatePrescaler_TypeDef prescaler)
{
SPI->CR1 = SPI_FIRSTBIT_MSB|(u8)prescaler|SPI_MODE_MASTER|SPI_CLOCKPOLARITY_LOW|SPI_CLOCKPHASE_1EDGE;
SPI->CR2 = 0x03; //SSM and SSI
SPI->CR1 |= 0x40; //Enable SPI;
SPI->DR = 0;
}