diff --git a/src/Makefile b/src/Makefile index 129da7e02..651291345 100644 --- a/src/Makefile +++ b/src/Makefile @@ -494,7 +494,7 @@ ifeq ($(PCB), X9D) EEPROMSRC = eeprom_avr.cpp # TODO later eeprom_conversions.cpp PULSESSRC = pulses_arm.cpp CPPSRC += sky9x/audio.cpp - CPPSRC += x9d/pwr_driver.cpp x9d/eeprom_driver.cpp x9d/pulses_driver.cpp x9d/keys_driver.cpp x9d/audio_driver.cpp + CPPSRC += x9d/pwr_driver.cpp x9d/eeprom_driver.cpp x9d/pulses_driver.cpp x9d/keys_driver.cpp x9d/audio_driver.cpp x9d/delays.cpp CPPSRC += bmp.cpp monitors_views.cpp SRC += x9d/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/CMSIS/Device/ST/STM32F2xx/Source/Templates/system_stm32f2xx.c SRC += x9d/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/src/stm32f2xx_gpio.c diff --git a/src/x9d/board_x9d.cpp b/src/x9d/board_x9d.cpp index 9bfa3d591..dc33f317b 100644 --- a/src/x9d/board_x9d.cpp +++ b/src/x9d/board_x9d.cpp @@ -46,6 +46,7 @@ extern uint32_t Peri2_frequency ; void keysInit(); void pwrInit(); void eepromInit(); // TODO check it's not in another include +void delaysInit(); uint8_t getTemperature() { @@ -126,6 +127,7 @@ void boardInit() __enable_irq() ; eepromInit(); + delaysInit(); } #endif diff --git a/src/x9d/board_x9d.h b/src/x9d/board_x9d.h index b6c8db54c..b39dbd1bb 100644 --- a/src/x9d/board_x9d.h +++ b/src/x9d/board_x9d.h @@ -44,6 +44,7 @@ #include "aspi.h" #include "i2c_ee.h" #include "audio_driver.h" +#include "delays.h" // TODO elsewhere #if !defined(SIMU) @@ -111,7 +112,7 @@ uint32_t check_soft_power(); #define IS_BACKLIGHT_ON() GPIO_IsSet(GPIOB, GPIO_Pin_BL) #define udelay(x) do { uint32_t temp; temp=((x+0)<<3); while(--temp); } while (0) -#define delayUsec(x) udelay(x) +#define delayUsec(x) CoTickDelay(1); #if !defined(SIMU) #define eeprom_read_block I2C_EE_BufferRead diff --git a/src/x9d/delays.cpp b/src/x9d/delays.cpp new file mode 100644 index 000000000..670f0061b --- /dev/null +++ b/src/x9d/delays.cpp @@ -0,0 +1,54 @@ +/* + * Authors (alphabetical order) + * - Bertrand Songis + * - Bryan J. Rentoul (Gruvin) + * - Cameron Weeks + * - Erez Raviv + * - Jean-Pierre Parisy + * - Karl Szmutny + * - Michael Blandford + * - Michal Hlavinka + * - Pat Mackenzie + * - Philip Moss + * - Rob Thomson + * - Romolo Manfredini + * - Thomas Husterer + * + * open9x is based on code named + * gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/, + * er9x by Erez Raviv: http://code.google.com/p/er9x/, + * and the original (and ongoing) project by + * Thomas Husterer, th9x: http://code.google.com/p/th9x/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * 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. + * + */ + +#include "../open9x.h" + +void delaysInit(void) { + + // Timer13 + RCC->APB1ENR |= RCC_APB1ENR_TIM13EN; // Enable clock + //TIM14->ARR = 4999; // 5mS + TIM13->PSC = Peri1_frequency / 100000; // 0.1uS from 30MHz + TIM13->CCER = 0; + TIM13->CCMR1 = 0; + TIM13->EGR = 0; + TIM13->CR1 = 0x03; + TIM13->DIER = 0; + //NVIC_EnableIRQ(TIM8_TRG_COM_TIM14_IRQn) ; +} + + +void delay_01us(uint32_t nb){ + TIM13->CNT = 0; + while(TIM13->CNT < nb); +} diff --git a/src/x9d/delays.h b/src/x9d/delays.h new file mode 100644 index 000000000..97fcc83b5 --- /dev/null +++ b/src/x9d/delays.h @@ -0,0 +1,41 @@ +/* + * Authors (alphabetical order) + * - Bertrand Songis + * - Bryan J. Rentoul (Gruvin) + * - Cameron Weeks + * - Erez Raviv + * - Jean-Pierre Parisy + * - Karl Szmutny + * - Michael Blandford + * - Michal Hlavinka + * - Pat Mackenzie + * - Philip Moss + * - Rob Thomson + * - Romolo Manfredini + * - Thomas Husterer + * + * open9x is based on code named + * gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/, + * er9x by Erez Raviv: http://code.google.com/p/er9x/, + * and the original (and ongoing) project by + * Thomas Husterer, th9x: http://code.google.com/p/th9x/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * 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. + * + */ + +#ifndef __DELAYS_H +#define __DELAYS_H + +void delaysInit(void); +void delay_01us(uint32_t us); + + +#endif //__DELAYS_H \ No newline at end of file diff --git a/src/x9d/i2c_ee.c b/src/x9d/i2c_ee.c index 8b075b5eb..6ff1981f9 100644 --- a/src/x9d/i2c_ee.c +++ b/src/x9d/i2c_ee.c @@ -12,6 +12,8 @@ #include "../open9x.h" +#define I2C_delay() delay_01us(15); + /** * @brief Configure the used I/O ports pin * @param None @@ -255,6 +257,7 @@ void I2C_EE_BufferWrite(uint8_t* pBuffer, uint16_t WriteAddr, uint16_t NumByteTo /* If NumByteToWrite < I2C_FLASH_PAGESIZE */ if (NumOfPage == 0) { I2C_EE_PageWrite(pBuffer, WriteAddr, NumOfSingle); + I2C_EE_WaitEepromStandbyState(); } /* If NumByteToWrite > I2C_FLASH_PAGESIZE */ diff --git a/src/x9d/i2c_ee.h b/src/x9d/i2c_ee.h index c7a9af93f..16053290d 100644 --- a/src/x9d/i2c_ee.h +++ b/src/x9d/i2c_ee.h @@ -24,7 +24,7 @@ #define EE_CMD_WRITE (0) #define EE_CMD_READ (1) -#define I2C_delay() do { delayUsec(5); } while(0) +//#define I2C_delay() //do { delayUsec(5); } while(0) #define SCL_H do{I2C_EE_GPIO->BSRRL = I2C_EE_SCL;}while(0) #define SCL_L do{I2C_EE_GPIO->BSRRH = I2C_EE_SCL;}while(0)