1
0
mirror of https://github.com/elua/elua.git synced 2025-01-25 01:02:54 +08:00

Bugfixes for SPI module.

This commit is contained in:
James Snyder 2009-06-23 23:22:45 +00:00
parent 852c64a61f
commit 863673898a

View File

@ -490,13 +490,17 @@ static void spis_init()
RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE);
}
#define SPI_GET_BASE_CLK( id ) ( ( id ) == 2 ? ( HCLK / PCLK2_DIV ) : ( HCLK / PCLK1_DIV ) )
#define SPI_GET_BASE_CLK( id ) ( ( id ) == 1 ? ( HCLK / PCLK2_DIV ) : ( HCLK / PCLK1_DIV ) )
u32 platform_spi_setup( unsigned id, int mode, u32 clock, unsigned cpol, unsigned cpha, unsigned databits )
{
SPI_InitTypeDef SPI_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
u8 prescaler_idx = intlog2( ( unsigned ) ( SPI_GET_BASE_CLK( id ) / clock ) ) - 1;
u8 prescaler_idx = intlog2( ( unsigned ) ( SPI_GET_BASE_CLK( id ) / clock ) ) - 2;
if ( prescaler_idx < 0 )
prescaler_idx = 0;
if ( prescaler_idx > 7 )
prescaler_idx = 7;
/* Configure SPI pins */
GPIO_InitStructure.GPIO_Pin = spi_gpio_pins[ id ];