From 22f02cb460d25f1271612de505ab81a068fdbae7 Mon Sep 17 00:00:00 2001 From: gussy Date: Sun, 28 Feb 2010 06:57:59 +0000 Subject: [PATCH] PIOS_I2C now non-application specific. git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@204 ebee16cc-31ac-478f-84a7-5cbb03baadba --- flight/OpenPilot/System/inc/pios_board.h | 16 ++++++++-------- flight/PiOS/STM32F10x/pios_i2c.c | 20 ++++++++++---------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/flight/OpenPilot/System/inc/pios_board.h b/flight/OpenPilot/System/inc/pios_board.h index 892a18d6d..2fd2f1b03 100644 --- a/flight/OpenPilot/System/inc/pios_board.h +++ b/flight/OpenPilot/System/inc/pios_board.h @@ -61,14 +61,14 @@ //------------------------ // I2C //------------------------ -#define I2C_GPIO_PORT GPIOB -#define I2C_SDA_PIN GPIO_Pin_11 -#define I2C_SCL_PIN GPIO_Pin_10 -#define I2C_DUTY_CYCLE I2C_DutyCycle_2 -#define I2C_BUS_FREQUENCY 400000 -#define I2C_TIMEOUT_VALUE 5000 -#define IRQ_I2C_EV_PRIORITY 2 -#define IRQ_I2C_ER_PRIORITY 2 +#define PIOS_I2C_GPIO_PORT GPIOB +#define PIOS_I2C_SDA_PIN GPIO_Pin_11 +#define PIOS_I2C_SCL_PIN GPIO_Pin_10 +#define PIOS_I2C_DUTY_CYCLE I2C_DutyCycle_2 +#define PIOS_I2C_BUS_FREQ 400000 +#define PIOS_I2C_TIMEOUT_VALUE 5000 +#define PIOS_I2C_IRQ_EV_PRIORITY 2 +#define PIOS_I2C_IRQ_ER_PRIORITY 2 //------------------------ // Onboard Pressure sensor diff --git a/flight/PiOS/STM32F10x/pios_i2c.c b/flight/PiOS/STM32F10x/pios_i2c.c index 27fcdc430..07fb10c1f 100644 --- a/flight/PiOS/STM32F10x/pios_i2c.c +++ b/flight/PiOS/STM32F10x/pios_i2c.c @@ -86,11 +86,11 @@ int32_t PIOS_I2C_Init(void) GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD; - GPIO_InitStructure.GPIO_Pin = I2C_SCL_PIN; - GPIO_Init(I2C_GPIO_PORT, &GPIO_InitStructure); + GPIO_InitStructure.GPIO_Pin = PIOS_I2C_SCL_PIN; + GPIO_Init(PIOS_I2C_GPIO_PORT, &GPIO_InitStructure); - GPIO_InitStructure.GPIO_Pin = I2C_SDA_PIN; - GPIO_Init(I2C_GPIO_PORT, &GPIO_InitStructure); + GPIO_InitStructure.GPIO_Pin = PIOS_I2C_SDA_PIN; + GPIO_Init(PIOS_I2C_GPIO_PORT, &GPIO_InitStructure); PIOS_I2C_InitPeripheral(); @@ -101,13 +101,13 @@ int32_t PIOS_I2C_Init(void) /* Configure and enable I2C2 interrupts */ NVIC_InitTypeDef NVIC_InitStructure; NVIC_InitStructure.NVIC_IRQChannel = I2C2_EV_IRQn; - NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = IRQ_I2C_EV_PRIORITY; + NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = PIOS_I2C_IRQ_EV_PRIORITY; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); NVIC_InitStructure.NVIC_IRQChannel = I2C2_ER_IRQn; - NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = IRQ_I2C_ER_PRIORITY; + NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = PIOS_I2C_IRQ_ER_PRIORITY; NVIC_Init(&NVIC_InitStructure); /* No error */ @@ -139,8 +139,8 @@ static void PIOS_I2C_InitPeripheral(void) /* Set I2C clock bus clock params */ /* Note that the STM32 driver handles value <= 100kHz differently! (duty cycle always 1:1) */ /* Important: bus frequencies > 400kHz don't work stable */ - I2C_InitStructure.I2C_DutyCycle = I2C_DUTY_CYCLE; - I2C_InitStructure.I2C_ClockSpeed = I2C_BUS_FREQUENCY; + I2C_InitStructure.I2C_DutyCycle = PIOS_I2C_DUTY_CYCLE; + I2C_InitStructure.I2C_ClockSpeed = PIOS_I2C_BUS_FREQ; /* Trigger software reset via I2C_DeInit */ I2C_DeInit(i2cx->base); @@ -253,13 +253,13 @@ int32_t PIOS_I2C_TransferWait(void) { I2CRecTypeDef *i2cx = &I2CRec; - uint32_t repeat_ctr = I2C_TIMEOUT_VALUE; + uint32_t repeat_ctr = PIOS_I2C_TIMEOUT_VALUE; uint16_t last_buffer_ix = i2cx->buffer_ix; while(--repeat_ctr > 0) { /* Check if buffer index has changed - if so, reload repeat counter */ if(i2cx->buffer_ix != last_buffer_ix) { - repeat_ctr = I2C_TIMEOUT_VALUE; + repeat_ctr = PIOS_I2C_TIMEOUT_VALUE; last_buffer_ix = i2cx->buffer_ix; }