From a85240d66572ecbdf7c4ba2eb33ee926a3f6c760 Mon Sep 17 00:00:00 2001 From: bsongis Date: Sun, 26 Apr 2015 13:25:15 +0200 Subject: [PATCH] Boyscout changes --- radio/src/Makefile | 2 +- radio/src/eeprom_raw.cpp | 6 +- radio/src/eeprom_rlc.cpp | 28 ++++----- .../src/gui/Taranis/menu_general_version.cpp | 2 +- radio/src/targets/simu/simpgmspace.cpp | 14 ++--- radio/src/targets/simu/simpgmspace.h | 10 +--- radio/src/targets/taranis/audio_driver.h | 5 +- radio/src/targets/taranis/board_taranis.h | 12 +--- radio/src/targets/taranis/bootloader/boot.cpp | 4 +- radio/src/targets/taranis/i2c.h | 58 ------------------- .../targets/taranis/{i2c.c => i2c_driver.cpp} | 31 ++++++++-- .../src/targets/taranis/usbd_storage_msd.cpp | 4 +- 12 files changed, 59 insertions(+), 117 deletions(-) delete mode 100644 radio/src/targets/taranis/i2c.h rename radio/src/targets/taranis/{i2c.c => i2c_driver.cpp} (84%) diff --git a/radio/src/Makefile b/radio/src/Makefile index 947711b65..f0cb074fb 100644 --- a/radio/src/Makefile +++ b/radio/src/Makefile @@ -877,7 +877,7 @@ ifeq ($(PCB), TARANIS) EXTRAINCDIRS += $(STM32USBPATH)/STM32_USB_Device_Library/Class/msc/inc $(STM32USBPATH)/STM32_USB_Device_Library/Class/hid/inc GUIGENERALSRC += gui/$(GUIDIRECTORY)/menu_general_hardware.cpp BOARDSRC = main_arm.cpp targets/taranis/board_taranis.cpp - EXTRABOARDSRC += targets/taranis/configure_pins.cpp targets/taranis/lcd_driver.cpp targets/taranis/flash_driver.cpp targets/taranis/aspi.c targets/taranis/i2c.c targets/taranis/delays.c + EXTRABOARDSRC += targets/taranis/configure_pins.cpp targets/taranis/lcd_driver.cpp targets/taranis/flash_driver.cpp targets/taranis/i2c_driver.cpp targets/taranis/aspi.c targets/taranis/delays.c SRC += $(COOSDIR)/kernel/core.c $(COOSDIR)/kernel/hook.c $(COOSDIR)/kernel/task.c $(COOSDIR)/kernel/event.c $(COOSDIR)/kernel/time.c $(COOSDIR)/kernel/timer.c $(COOSDIR)/kernel/flag.c $(COOSDIR)/kernel/mutex.c $(COOSDIR)/kernel/serviceReq.c $(COOSDIR)/portable/GCC/port.c $(COOSDIR)/portable/arch.c SRC += targets/taranis/pwr_driver.c targets/taranis/usb_driver.c EEPROMSRC = eeprom_common.cpp eeprom_rlc.cpp eeprom_conversions.cpp diff --git a/radio/src/eeprom_raw.cpp b/radio/src/eeprom_raw.cpp index cd13b76a9..31a2612b8 100644 --- a/radio/src/eeprom_raw.cpp +++ b/radio/src/eeprom_raw.cpp @@ -101,7 +101,7 @@ void eepromEraseBlock(uint32_t address, bool blocking=true) #if defined(SIMU) static uint8_t erasedBlock[EEPROM_BLOCK_SIZE] = { 0xff }; eeprom_pointer = address; - eeprom_buffer_data = (char *)erasedBlock; + eeprom_buffer_data = erasedBlock; eeprom_buffer_size = EEPROM_BLOCK_SIZE; eeprom_read_operation = false; Spi_complete = false; @@ -124,7 +124,7 @@ void eepromRead(uint32_t address, uint8_t * buffer, uint32_t size, bool blocking #if defined(SIMU) assert(size); eeprom_pointer = address; - eeprom_buffer_data = (char*)buffer; + eeprom_buffer_data = buffer; eeprom_buffer_size = size; eeprom_read_operation = true; Spi_complete = false; @@ -145,7 +145,7 @@ void eepromWrite(uint32_t address, uint8_t * buffer, uint32_t size, bool blockin #if defined(SIMU) assert(size); eeprom_pointer = address; - eeprom_buffer_data = (char*)buffer; + eeprom_buffer_data = buffer; eeprom_buffer_size = size+1; eeprom_read_operation = false; Spi_complete = false; diff --git a/radio/src/eeprom_rlc.cpp b/radio/src/eeprom_rlc.cpp index 83958b63b..1c85c2dc5 100644 --- a/radio/src/eeprom_rlc.cpp +++ b/radio/src/eeprom_rlc.cpp @@ -51,7 +51,7 @@ uint8_t s_sync_write = false; #if !defined(CPUARM) uint16_t eeprom_pointer; -const char * eeprom_buffer_data; +uint8_t * eeprom_buffer_data; volatile int8_t eeprom_buffer_size = 0; #if !defined(SIMU) @@ -86,12 +86,12 @@ ISR(EE_READY_vect) } #endif -void eeWriteBlockCmp(const void *i_pointer_ram, uint16_t i_pointer_eeprom, size_t size) +void eepromWriteBlock(uint8_t * i_pointer_ram, uint16_t i_pointer_eeprom, size_t size) { assert(!eeprom_buffer_size); eeprom_pointer = i_pointer_eeprom; - eeprom_buffer_data = (const char*)i_pointer_ram; + eeprom_buffer_data = i_pointer_ram; eeprom_buffer_size = size+1; #if defined(SIMU) @@ -111,13 +111,7 @@ void eeWriteBlockCmp(const void *i_pointer_ram, uint16_t i_pointer_eeprom, size_ static uint8_t EeFsRead(blkid_t blk, uint8_t ofs) { uint8_t ret; -#if defined(CPUARM) - eeprom_read_block(&ret, (uint16_t)(blk*BS+ofs+BLOCKS_OFFSET), 1); -#elif defined(SIMU) - eeprom_read_block(&ret, (const void*)(uint64_t)(blk*BS+ofs+BLOCKS_OFFSET), 1); -#else - eeprom_read_block(&ret, (const void*)(blk*BS+ofs+BLOCKS_OFFSET), 1); -#endif + eepromReadBlock(&ret, (uint16_t)(blk*BS+ofs+BLOCKS_OFFSET), 1); return ret; } @@ -125,7 +119,7 @@ static blkid_t EeFsGetLink(blkid_t blk) { #if defined(CPUARM) blkid_t ret; - eeprom_read_block((uint8_t *)&ret, blk*BS+BLOCKS_OFFSET, sizeof(blkid_t)); + eepromReadBlock((uint8_t *)&ret, blk*BS+BLOCKS_OFFSET, sizeof(blkid_t)); return ret; #else return EeFsRead(blk, 0); @@ -136,7 +130,7 @@ static void EeFsSetLink(blkid_t blk, blkid_t val) { static blkid_t s_link; // we write asynchronously, then nothing on the stack! s_link = val; - eeWriteBlockCmp((uint8_t *)&s_link, (blk*BS)+BLOCKS_OFFSET, sizeof(blkid_t)); + eepromWriteBlock((uint8_t *)&s_link, (blk*BS)+BLOCKS_OFFSET, sizeof(blkid_t)); } static uint8_t EeFsGetDat(blkid_t blk, uint8_t ofs) @@ -146,22 +140,22 @@ static uint8_t EeFsGetDat(blkid_t blk, uint8_t ofs) static void EeFsSetDat(blkid_t blk, uint8_t ofs, uint8_t *buf, uint8_t len) { - eeWriteBlockCmp(buf, (blk*BS)+ofs+sizeof(blkid_t)+BLOCKS_OFFSET, len); + eepromWriteBlock(buf, (blk*BS)+ofs+sizeof(blkid_t)+BLOCKS_OFFSET, len); } static void EeFsFlushFreelist() { - eeWriteBlockCmp((uint8_t *)&eeFs.freeList, offsetof(EeFs, freeList), sizeof(eeFs.freeList)); + eepromWriteBlock((uint8_t *)&eeFs.freeList, offsetof(EeFs, freeList), sizeof(eeFs.freeList)); } static void EeFsFlushDirEnt(uint8_t i_fileId) { - eeWriteBlockCmp((uint8_t *)&eeFs.files[i_fileId], offsetof(EeFs, files) + sizeof(DirEnt)*i_fileId, sizeof(DirEnt)); + eepromWriteBlock((uint8_t *)&eeFs.files[i_fileId], offsetof(EeFs, files) + sizeof(DirEnt)*i_fileId, sizeof(DirEnt)); } static void EeFsFlush() { - eeWriteBlockCmp((uint8_t *)&eeFs, 0, sizeof(eeFs)); + eepromWriteBlock((uint8_t *)&eeFs, 0, sizeof(eeFs)); } uint16_t EeFsGetFree() @@ -288,7 +282,7 @@ void eepromFormat() bool eepromOpen() { - eeprom_read_block((uint8_t *)&eeFs, 0, sizeof(eeFs)); + eepromReadBlock((uint8_t *)&eeFs, 0, sizeof(eeFs)); #ifdef SIMU if (eeFs.version != EEFS_VERS) { diff --git a/radio/src/gui/Taranis/menu_general_version.cpp b/radio/src/gui/Taranis/menu_general_version.cpp index 99a7c0c7b..2aea29b2b 100755 --- a/radio/src/gui/Taranis/menu_general_version.cpp +++ b/radio/src/gui/Taranis/menu_general_version.cpp @@ -72,7 +72,7 @@ void backupEeprom() for (int i=0; i(v, VOLUME_LEVEL_MAX)]) -#else + void setVolume(uint8_t volume); -#endif #endif diff --git a/radio/src/targets/taranis/board_taranis.h b/radio/src/targets/taranis/board_taranis.h index 49b838d42..ff0d54f8a 100644 --- a/radio/src/targets/taranis/board_taranis.h +++ b/radio/src/targets/taranis/board_taranis.h @@ -80,7 +80,6 @@ extern "C" { #include "hal.h" #include "aspi.h" -#include "i2c.h" #if defined(__cplusplus) && !defined(SIMU) } @@ -294,14 +293,9 @@ void usbStop(void); #endif // EEPROM driver -#if !defined(SIMU) -#define eepromInit() I2C_EE_Init() -#define eeprom_read_block I2C_EE_BufferRead -#define eeWriteBlockCmp I2C_EE_BufferWrite -#else -#define eepromInit() -void eeWriteBlockCmp(const void *pointer_ram, uint16_t pointer_eeprom, size_t size); -#endif +void eepromInit(); +void eepromReadBlock(uint8_t * buffer, uint16_t address, uint16_t size); +void eepromWriteBlock(uint8_t * buffer, uint16_t address, uint16_t size); // Debug driver void debugPutc(const char c); diff --git a/radio/src/targets/taranis/bootloader/boot.cpp b/radio/src/targets/taranis/bootloader/boot.cpp index 8a43784e1..173db2afa 100755 --- a/radio/src/targets/taranis/bootloader/boot.cpp +++ b/radio/src/targets/taranis/bootloader/boot.cpp @@ -453,7 +453,7 @@ void writeFlashBlock() void writeEepromBlock() { - eeWriteBlockCmp((uint8_t *)Block_buffer, eepromAddress, BlockCount); + eepromWriteBlock((uint8_t *)Block_buffer, eepromAddress, BlockCount); eepromAddress += BlockCount; } @@ -507,7 +507,7 @@ int main() turnBacklightOn(0, 0); #endif keysInit(); - I2C_EE_Init(); + eepromInit(); #endif __enable_irq(); diff --git a/radio/src/targets/taranis/i2c.h b/radio/src/targets/taranis/i2c.h deleted file mode 100644 index bd3a79ce6..000000000 --- a/radio/src/targets/taranis/i2c.h +++ /dev/null @@ -1,58 +0,0 @@ -/** - ****************************************************************************** - * @file Project/ee_drivers/i2c_ee.h - * @author FrSky Application Team - * @version V 0.2 - * @date 12-JLY-2012 - * @brief Header for i2c.c module - ****************************************************************************** - * @copy - * - * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS - * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE - * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY - * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING - * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE - * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. - * - *

© COPYRIGHT 2009 STMicroelectronics

- */ - -#ifndef __I2C_H -#define __I2C_H - -#define EE_CMD_WRITE (0) -#define EE_CMD_READ (1) - -#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) -#define SDA_H do{I2C_EE_GPIO->BSRRL = I2C_EE_SDA;}while(0) -#define SDA_L do{I2C_EE_GPIO->BSRRH = I2C_EE_SDA;}while(0) -#define SCL_read (I2C_EE_GPIO->IDR & I2C_EE_SCL) -#define SDA_read (I2C_EE_GPIO->IDR & I2C_EE_SDA) -#define WP_H do{I2C_EE_WP_GPIO->BSRRL = I2C_EE_WP;}while(0) -#define WP_L do{I2C_EE_WP_GPIO->BSRRH = I2C_EE_WP;}while(0) - -#if defined(__cplusplus) && !defined(SIMU) -extern "C" { -#endif - -/* Exported functions ------------------------------------------------------- */ -void I2C_EE_Init(void); -void I2C_EE_ByteWrite(uint8_t* pBuffer, uint16_t WriteAddr); -void I2C_EE_PageWrite(uint8_t* pBuffer, uint16_t WriteAddr, uint8_t NumByteToWrite); -void I2C_EE_BufferWrite(uint8_t* pBuffer, uint16_t WriteAddr, uint16_t NumByteToWrite); -void I2C_EE_BufferRead(uint8_t* pBuffer, uint16_t ReadAddr, uint16_t NumByteToRead); -void I2C_EE_WaitEepromStandbyState(void); - -void I2C_set_volume(register uint8_t volume); -uint8_t I2C_read_volume(void); - -#if defined(__cplusplus) && !defined(SIMU) -} -#endif - -#endif /* __I2C_EE_H */ - -/******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/ - diff --git a/radio/src/targets/taranis/i2c.c b/radio/src/targets/taranis/i2c_driver.cpp similarity index 84% rename from radio/src/targets/taranis/i2c.c rename to radio/src/targets/taranis/i2c_driver.cpp index 91bd70cbe..0344b5619 100644 --- a/radio/src/targets/taranis/i2c.c +++ b/radio/src/targets/taranis/i2c_driver.cpp @@ -12,6 +12,26 @@ #include "board_taranis.h" +#define EE_CMD_WRITE (0) +#define EE_CMD_READ (1) + +#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) +#define SDA_H do{I2C_EE_GPIO->BSRRL = I2C_EE_SDA;}while(0) +#define SDA_L do{I2C_EE_GPIO->BSRRH = I2C_EE_SDA;}while(0) +#define SCL_read (I2C_EE_GPIO->IDR & I2C_EE_SCL) +#define SDA_read (I2C_EE_GPIO->IDR & I2C_EE_SDA) +#define WP_H do{I2C_EE_WP_GPIO->BSRRL = I2C_EE_WP;}while(0) +#define WP_L do{I2C_EE_WP_GPIO->BSRRH = I2C_EE_WP;}while(0) + +/* Exported functions ------------------------------------------------------- */ +void I2C_EE_ByteWrite(uint8_t* pBuffer, uint16_t WriteAddr); +void I2C_EE_PageWrite(uint8_t* pBuffer, uint16_t WriteAddr, uint8_t NumByteToWrite); +void I2C_EE_WaitEepromStandbyState(void); + +void I2C_set_volume(register uint8_t volume); +uint8_t I2C_read_volume(void); + #define I2C_delay() delay_01us(100); /** @@ -159,7 +179,7 @@ char I2C_READ(void) return ReceiveByte; } -void I2C_EE_Init(void) +void eepromInit(void) { /* GPIO Periph clock enable */ RCC_AHB1PeriphClockCmd(I2C_EE_GPIO_CLK, ENABLE); @@ -202,7 +222,7 @@ void I2C_EE_ByteWrite(uint8_t* pBuffer, uint16_t WriteAddr) * @param NumByteToRead : number of bytes to read from the EEPROM. * @retval None */ -void I2C_EE_BufferRead(uint8_t* pBuffer, uint16_t ReadAddr, uint16_t NumByteToRead) +void eepromReadBlock(uint8_t* pBuffer, uint16_t ReadAddr, uint16_t NumByteToRead) { I2C_START(); I2C_SEND_DATA(I2C_EEPROM_ADDRESS|EE_CMD_WRITE); @@ -243,7 +263,7 @@ void I2C_EE_BufferRead(uint8_t* pBuffer, uint16_t ReadAddr, uint16_t NumByteToRe * @param NumByteToWrite : number of bytes to write to the EEPROM. * @retval None */ -void I2C_EE_BufferWrite(uint8_t* pBuffer, uint16_t WriteAddr, uint16_t NumByteToWrite) +void eepromWriteBlock(uint8_t* pBuffer, uint16_t WriteAddr, uint16_t NumByteToWrite) { uint8_t NumOfPage = 0, NumOfSingle = 0, count = 0; uint16_t Addr = 0; @@ -372,8 +392,11 @@ void I2C_EE_WaitEepromStandbyState(void) I2C_STOP(); } -void I2C_set_volume( register uint8_t volume ) +void setVolume(uint8_t volume) { + if (volume > VOLUME_LEVEL_MAX) + volume = VOLUME_LEVEL_MAX; + I2C_START(); I2C_SEND_DATA(I2C_CAT5137_ADDRESS|EE_CMD_WRITE); I2C_WAIT_ACK(); diff --git a/radio/src/targets/taranis/usbd_storage_msd.cpp b/radio/src/targets/taranis/usbd_storage_msd.cpp index c4ba7f3e8..51cccc788 100644 --- a/radio/src/targets/taranis/usbd_storage_msd.cpp +++ b/radio/src/targets/taranis/usbd_storage_msd.cpp @@ -728,7 +728,7 @@ int32_t fat12Read( uint8_t *buffer, uint16_t sector, uint16_t count ) memcpy(buffer, g_DIRroot, BLOCKSIZE ) ; } else if (sector < 3 + (EESIZE/BLOCKSIZE)) { - eeprom_read_block(buffer, (sector-3)*BLOCKSIZE, BLOCKSIZE); + eepromReadBlock(buffer, (sector-3)*BLOCKSIZE, BLOCKSIZE); } else if (sector < 3 + (EESIZE/BLOCKSIZE) + (FLASHSIZE/BLOCKSIZE)) { uint32_t address; @@ -767,7 +767,7 @@ int32_t fat12Write(const uint8_t *buffer, uint16_t sector, uint16_t count) operation = FATWRITE_EEPROM; } if (operation == FATWRITE_EEPROM) { - eeWriteBlockCmp((uint8_t *)buffer, (sector-3)*BLOCKSIZE, BLOCKSIZE); + eepromWriteBlock((uint8_t *)buffer, (sector-3)*BLOCKSIZE, BLOCKSIZE); } buffer += BLOCKSIZE; sector++;