# HG changeset patch # User jeandet # Date 2013-05-28 18:18:02 # Node ID 8299696715f87a9a25dc9a0ca4f38af72f0f35ef # Parent 04dbc44ec5706335595951c87524c51f34d50da1 added 25Q128 eeprom driver fixed bug on spi driver diff --git a/bsp/src/SOLAR_LFR_PSU/bsp.h b/bsp/src/SOLAR_LFR_PSU/bsp.h --- a/bsp/src/SOLAR_LFR_PSU/bsp.h +++ b/bsp/src/SOLAR_LFR_PSU/bsp.h @@ -26,8 +26,8 @@ #include #include -#define __MAX_OPENED_FILES__ 4 -#define __FS_ROOT_SIZE__ 4 +#define __MAX_OPENED_FILES__ 32 +#define __FS_ROOT_SIZE__ 32 /* #ifndef PD8 #define PD8 @@ -42,15 +42,6 @@ #define LED3 PD14 #define LED4 PD15 - -#define LED3ON GPIOB->BSRRH = GPIO_Pin_15 -#define LED2ON GPIOD->BSRRH = GPIO_Pin_8 -#define LED1ON GPIOD->BSRRH = GPIO_Pin_9 - -#define LED3OFF GPIOB->BSRRL = GPIO_Pin_15 -#define LED2OFF GPIOD->BSRRL = GPIO_Pin_8 -#define LED1OFF GPIOD->BSRRL = GPIO_Pin_9 - extern float VREF0; extern uint32_t currentCpuFreq; diff --git a/examples/N25Q128_test/N25Q128_test.pro b/examples/N25Q128_test/N25Q128_test.pro new file mode 100644 --- /dev/null +++ b/examples/N25Q128_test/N25Q128_test.pro @@ -0,0 +1,12 @@ +TEMPLATE = app +CONFIG += cpu + + +UCMODEL=stm32f4 +BSP = SOLAR_LFR_PSU + +LIBS += -lN25Q128 + +SOURCES += \ + main.c + diff --git a/examples/N25Q128_test/main.c b/examples/N25Q128_test/main.c new file mode 100644 --- /dev/null +++ b/examples/N25Q128_test/main.c @@ -0,0 +1,93 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern streamdevice* __opnfiles__[]; + +/* + N25Q128 pinout: + MISO => PB14 + MOSI => PB15 + SCK => PB13 + CS => PB12 + WP => PC1 + RESET/HOLD => PC2 +*/ +void cs(int csstate) +{ + gpiosetval(PB12,csstate); +} + +void wp(int wpstate) +{ + gpiosetval(PC1,wpstate); +} + +void resetHold(int rhstate) +{ + gpiosetval(PC2,rhstate); +} + +int main() +{ + spiopenandconfig(spi2,spiclkfirstedge|spimaster|spimsbfirst|spi8bits,10000,PB15,PB14,PB13,(uint32_t)NULL); + //spiopenandconfig(spi2,spiclkfirstedge|spimaster|spimsbfirst|spi8bits,10000,PB15,PB14,PB13,PB12); + gpio_t PC1pin= gpioopen(PC1); + gpiosetdir(&PC1pin,gpiooutdir); + gpio_t PC2pin= gpioopen(PC2); + gpiosetdir(&PC2pin,gpiooutdir); + gpio_t PB12pin= gpioopen(PB12); + gpiosetdir(&PB12pin,gpiooutdir); + gpioset(PC1); + gpioset(PB12); + gpioclr(PC2); + eepromN25Q128Dev eeprom; + eepromN25Q128open(&eeprom,spi2,&cs,&wp,&resetHold); + //eepromN25Q128open(&eeprom,spi2,NULL,&wp,&resetHold); + delay_100us(10); + gpioset(PC2); + gpioclr(PB12); + spiputw(spi2,0x9E); + char res[22]; + spigetnc(spi2,res,22); + gpioset(PB12); + for(int i=0;i<22;i++) + { + printf("res[%d] = 0x%x\n\r",i,(int)res[i]); + } + eepromN25Q128enablewrite(&eeprom); + delay_100us(10); + eepromN25Q128writen(&eeprom,0,"hello World",11); + delay_100us(10); + eepromN25Q128readn(&eeprom,0,res,11); + res[11]='\n'; + res[12]='\r'; + res[13]=0; + //printf("read: %s",res); + //printf("\n"); + for(int i=0;i<11;i++) + { + printf("res[%d] = 0x%x\n\r",i,(int)res[i]); + } + while(1) + { + gpioset(LED3); + delay_100us(10000); + gpioclr(LED3); + delay_100us(10000); + } + printf("hello world\n\r"); + return 0; +} + + + + + + diff --git a/examples/TEST_CMSIS_FFT/TEST_CMSIS_FFT.pro b/examples/TEST_CMSIS_FFT/TEST_CMSIS_FFT.pro new file mode 100644 --- /dev/null +++ b/examples/TEST_CMSIS_FFT/TEST_CMSIS_FFT.pro @@ -0,0 +1,15 @@ +TEMPLATE = app +CONFIG += cpu + + +UCMODEL=stm32f4 +DEFINES += CPUFREQ=160000000 + +#BSP = BEAGLESYNTH +#BSP = SOLAR_LFR_PSU + +BSP = STM32F4Eval + +SOURCES += \ + main.c + diff --git a/examples/TEST_CMSIS_FFT/main.c b/examples/TEST_CMSIS_FFT/main.c new file mode 100644 --- /dev/null +++ b/examples/TEST_CMSIS_FFT/main.c @@ -0,0 +1,106 @@ +/* ---------------------------------------------------------------------- +* Copyright (C) 2010 ARM Limited. All rights reserved. +* +* $Date: 29. November 2010 +* $Revision: V1.0.3 +* +* Project: CMSIS DSP Library +* Title: arm_convolution_example_f32.c +* +* Description: Example code demonstrating Convolution of two input signals using fft. +* +* Target Processor: Cortex-M4/Cortex-M3 +* +* +* Version 1.0.3 2010/11/29 +* Re-organized the CMSIS folders and updated documentation. +* +* Version 1.0.1 2010/10/05 KK +* Production release and review comments incorporated. +* +* Version 1.0.0 2010/09/20 KK +* Production release and review comments incorporated. +* ------------------------------------------------------------------- */ + +#include +#include +#include +#include +#include +//#include "math_helper.h" +#include + +/* ---------------------------------------------------------------------- +* Defines each of the tests performed +* ------------------------------------------------------------------- */ +//#define MAX_BLOCKSIZE 1024 +#define MAX_BLOCKSIZE 16 + +/* ---------------------------------------------------------------------- +* Declare I/O buffers +* ------------------------------------------------------------------- */ +float32_t Ak[MAX_BLOCKSIZE*2]; /* Input A */ + +#define LCD_COLOR_WHITE 0xFFFF +#define LCD_COLOR_BLACK 0x0000 +#define LCD_COLOR_GREY 0xF7DE +#define LCD_COLOR_BLUE 0x001F +#define LCD_COLOR_BLUE2 0x051F +#define LCD_COLOR_RED 0xF800 +#define LCD_COLOR_MAGENTA 0xF81F +#define LCD_COLOR_GREEN 0x07E0 +#define LCD_COLOR_CYAN 0x7FFF +#define LCD_COLOR_YELLOW 0xFFE0 +extern streamdevice* __opnfiles__[__MAX_OPENED_FILES__]; + + +int main() +{ + + arm_status status; /* Status of the example */ + arm_cfft_radix4_instance_f32 cfft_instance; /* CFFT Structure instance */ + + /* CFFT Structure instance pointer */ + arm_cfft_radix4_instance_f32 *cfft_instance_ptr = + (arm_cfft_radix4_instance_f32*) &cfft_instance; + + /* Initialise the fft input buffers with all zeros */ + arm_fill_f32(0.0, Ak, MAX_BLOCKSIZE); + for(int i =0;i<(MAX_BLOCKSIZE);i++) + { + Ak[2*i] = sin(4.0*PI*(float32_t)i/MAX_BLOCKSIZE); + printf("%f\n\r",Ak[i]); + } + + //gpioclr(LED1); + + /* Initialize the CFFT function to compute 64 point fft */ + status = arm_cfft_radix4_init_f32(cfft_instance_ptr, MAX_BLOCKSIZE, 0, 1); + + /* Transform input a[n] from time domain to frequency domain A[k] */ + arm_cfft_radix4_f32(cfft_instance_ptr, Ak); + + //gpioset(LED1); + + /* Initialize the CIFFT function to compute 64 point ifft */ + //status = arm_cfft_radix4_init_f32(cfft_instance_ptr, 16, 1, 1); + + /* Transform the multiplication output from frequency domain to time domain, + that gives the convolved output */ + //arm_cfft_radix4_f32(cfft_instance_ptr, AxB); + + /* SNR Calculation */ + //snr = arm_snr_f32((float32_t *)testRefOutput_f32, AxB, srcALen + srcBLen - 1); + + /* Compare the SNR with threshold to test whether the + computed output is matched with the reference output values. */ + printf("FFT Done!\n\r"); + for(int i =0;i<(MAX_BLOCKSIZE*2);i++) + { + printf("%f %f\n\r",Ak[2*i],Ak[(2*i)+1]); + } + + + while(1); /* main function does not return */ +} + diff --git a/examples/examples.pro b/examples/examples.pro --- a/examples/examples.pro +++ b/examples/examples.pro @@ -9,7 +9,8 @@ SUBDIRS += QtTest/test.pro \ BeagleSynthHello \ lcdTerminal \ BeagleSynthHelloSupMon \ - TEST_CMSIS_FFT + TEST_CMSIS_FFT \ + N25Q128_test diff --git a/lib/src/common/24LCXX/24LC0X/24LC0X.c b/lib/src/common/24LCXX/24LC0X/24LC0X.c deleted file mode 100644 --- a/lib/src/common/24LCXX/24LC0X/24LC0X.c +++ /dev/null @@ -1,102 +0,0 @@ -/*------------------------------------------------------------------------------ --- This file is a part of the libuc, microcontroler library --- Copyright (C) 2011, Alexis Jeandet --- --- 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 3 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -------------------------------------------------------------------------------- --- Author : Alexis Jeandet --- Mail : alexis.jeandet@gmail.com --------------------------------------------------------------------------------*/ -#include "24LC0X.h" -#include "iic.h" -#include "core.h" -/* -struct 24LC0X_str -{ - i2cDev iicdev; - unsigned char devAddress; - unsigned char size; -}; -*/ - - -void eeprom24lc0xopen(eeprom24lc0xDev* dev,i2cDev iicdev,unsigned char A0_A1_A2_val,unsigned int size) -{ - dev->iicdev = iicdev; - dev->devAddress = 0x50 | (A0_A1_A2_val & 0x7); - if(size == 2048) dev->size = 2; - if(size == 1024) dev->size = 1; -} - -void eeprom24lc0xpagewrite(eeprom24lc0xDev dev,unsigned char address,unsigned char* page) -{ - int cmdcnt=1,datacnt=8; - i2cwrite2(dev.iicdev,dev.devAddress,&address,&cmdcnt,page,&datacnt); -} - - -void eeprom24lc0xpageread(eeprom24lc0xDev dev,unsigned char address,unsigned char* page) -{ - int cmdcnt=1,datacnt=8; - i2cwrite(dev.iicdev,dev.devAddress,&address,&cmdcnt); - i2cread(dev.iicdev,dev.devAddress,page,&datacnt); -} - -void eeprom24lc0xbytewrite(eeprom24lc0xDev dev,unsigned char address,unsigned char data) -{ - int cmdcnt=1,datacnt=1; - i2cwrite2(dev.iicdev,dev.devAddress,&address,&cmdcnt,&data,&datacnt); -} - - -unsigned char eeprom24lc0xbyteread(eeprom24lc0xDev dev,unsigned char address) -{ - int cmdcnt=1,datacnt=1; - unsigned char data = 0; - i2cwrite(dev.iicdev,dev.devAddress,&address,&cmdcnt); - i2cread(dev.iicdev,dev.devAddress,&data,&datacnt); - return data; -} - - -void eeprom24lc0xreadn(eeprom24lc0xDev dev,unsigned char address,unsigned char* data, unsigned int count) -{ - int cmdcnt=1,datacnt=count; - i2cwrite(dev.iicdev,dev.devAddress,&address,&cmdcnt); - i2cread(dev.iicdev,dev.devAddress,data,&datacnt); - -} - -void eeprom24lc0xwriten(eeprom24lc0xDev dev,unsigned char address,unsigned char* data, unsigned int count) -{ - int cmdcnt=1,datacnt=8; - while(count >8) - { - cmdcnt=1;datacnt=8; - while(i2noerr!=i2cwrite2(dev.iicdev,dev.devAddress,&address,&cmdcnt,data,&datacnt)){cmdcnt=1;datacnt=8;} - count-=8; - address+=8; - data+=8; - } - cmdcnt=1;datacnt=count; - while(i2noerr!=i2cwrite2(dev.iicdev,dev.devAddress,&address,&cmdcnt,data,&datacnt)){cmdcnt=1;datacnt=count;} -} - - - - - - - diff --git a/lib/src/common/24LCXX/24LC0X/24LC0X.pro b/lib/src/common/24LCXX/24LC0X/24LC0X.pro deleted file mode 100644 --- a/lib/src/common/24LCXX/24LC0X/24LC0X.pro +++ /dev/null @@ -1,14 +0,0 @@ -TEMPLATE = lib -OBJECTS_DIR = obj - -SOURCES += 24LC0X.c - -INCLUDEPATH += ../../includes \ - ../CPU/STM32F4xx_StdPeriph_Driver/inc \ - ../CPU/CMSIS/Include - - -UCMODEL=stm32f4 - -target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL -INSTALLS += target diff --git a/lib/src/common/24LCXX/24LCXX.pro b/lib/src/common/24LCXX/24LCXX.pro deleted file mode 100644 --- a/lib/src/common/24LCXX/24LCXX.pro +++ /dev/null @@ -1,2 +0,0 @@ -TEMPLATE = dir -SUBDIRS += 24LC0X diff --git a/lib/src/common/AUDIO/AUDIO.pro b/lib/src/common/AUDIO/AUDIO.pro --- a/lib/src/common/AUDIO/AUDIO.pro +++ b/lib/src/common/AUDIO/AUDIO.pro @@ -1,5 +1,5 @@ TEMPLATE = subdirs CONFIG += ordered -SUBDIRS += CS43L22 #\ -# VS10XX +SUBDIRS += CS43L22 \ + VS10XX diff --git a/lib/src/common/AUDIO/VS10XX/VS10XX.c b/lib/src/common/AUDIO/VS10XX/VS10XX.c new file mode 100644 --- /dev/null +++ b/lib/src/common/AUDIO/VS10XX/VS10XX.c @@ -0,0 +1,56 @@ +/*------------------------------------------------------------------------------ +#-- This file is a part of the libuc, microcontroler library +#-- Copyright (C) 2011, Alexis Jeandet +#-- +#-- 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 3 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +#------------------------------------------------------------------------------- +#-- Author : Alexis Jeandet +#-- Mail : alexis.jeandet@gmail.com +#-------------------------------------------------------------------------------*/ +#include "spi.h" +#include "VS10XX.h" +//#include + +void vs10XXopen(vs10XXDev* codec,spi_t dev){ + codec->SPIdev = dev; + +} + +void vs10XXsoftreset(vs10XXDev* dev) +{ + vs10XXcmdwrite(dev,VSMODE,(1<<2)); +} + +int vs10XXcmdread(vs10XXDev* dev,char address) +{ + int result; + while(!vs10XXDREQ()); + vs10XXclearXCS(); + spiputw(dev->SPIdev,(3<<8)+address); + result = spigetw(dev->SPIdev); + vs10XXsetXCS(); + return result; +} + + +void vs10XXcmdwrite(vs10XXDev* dev,char address,int value) +{ + while(!vs10XXDREQ()); + vs10XXclearXCS(); + spiputw(dev->SPIdev,(2<<8)+address); + spiputw(dev->SPIdev,value); + vs10XXsetXCS(); +} + diff --git a/lib/src/common/AUDIO/VS10XX/VS10XX.pro b/lib/src/common/AUDIO/VS10XX/VS10XX.pro new file mode 100644 --- /dev/null +++ b/lib/src/common/AUDIO/VS10XX/VS10XX.pro @@ -0,0 +1,14 @@ +TEMPLATE = lib +OBJECTS_DIR = obj +TARGET = vs10XX + +SOURCES += VS10XX.c + + +HEADERS += ../../../includes/VS10XX.h + +UCMODEL=stm32f4 + +target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL +INSTALLS += target + diff --git a/lib/src/common/AUDIO/VS10XX/vs1053.c b/lib/src/common/AUDIO/VS10XX/vs1053.c deleted file mode 100644 --- a/lib/src/common/AUDIO/VS10XX/vs1053.c +++ /dev/null @@ -1,56 +0,0 @@ -#/*------------------------------------------------------------------------------ -#-- This file is a part of the libuc, microcontroler library -#-- Copyright (C) 2011, Alexis Jeandet -#-- -#-- 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 3 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -#------------------------------------------------------------------------------- -#-- Author : Alexis Jeandet -#-- Mail : alexis.jeandet@gmail.com -#-------------------------------------------------------------------------------*/ -#include "ssp.h" -#include "vs1053.h" -//#include - -void vs1053open(vs1053Dev* codec,sspDev dev){ - codec->SSP_device = dev; - -} - -void vs1053softreset(vs1053Dev* dev) -{ - vs1053cmdwrite(dev,VSMODE,(1<<2)); -} - -int vs1053cmdread(vs1053Dev* dev,char address) -{ - int result; - while(!vs10XXDREQ()); - vs10XXclearXCS(); - sspputw(dev->SSP_device,(3<<8)+address); - result = sspgetw(dev->SSP_device); - vs10XXsetXCS(); - return result; -} - - -void vs1053cmdwrite(vs1053Dev* dev,char address,int value) -{ - while(!vs10XXDREQ()); - vs10XXclearXCS(); - sspputw(dev->SSP_device,(2<<8)+address); - sspputw(dev->SSP_device,value); - vs10XXsetXCS(); -} - diff --git a/lib/src/common/AUDIO/VS10XX/vs1053.pro b/lib/src/common/AUDIO/VS10XX/vs1053.pro deleted file mode 100644 --- a/lib/src/common/AUDIO/VS10XX/vs1053.pro +++ /dev/null @@ -1,16 +0,0 @@ -TEMPLATE = lib -OBJECTS_DIR = obj -TARGET = vs10XX - -SOURCES += vs1053.c - -INCLUDEPATH += ../../includes \ - ../CPU/STM32F4xx_StdPeriph_Driver/inc \ - ../CPU/CMSIS/Include - - -UCMODEL=stm32f4 - -target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL -INSTALLS += target - diff --git a/lib/src/common/EEPROMS/24LCXX/24LC0X/24LC0X.c b/lib/src/common/EEPROMS/24LCXX/24LC0X/24LC0X.c new file mode 100644 --- /dev/null +++ b/lib/src/common/EEPROMS/24LCXX/24LC0X/24LC0X.c @@ -0,0 +1,103 @@ +/*------------------------------------------------------------------------------ +-- This file is a part of the libuc, microcontroler library +-- Copyright (C) 2011, Alexis Jeandet +-- +-- 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 3 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +------------------------------------------------------------------------------- +-- Author : Alexis Jeandet +-- Mail : alexis.jeandet@gmail.com +-------------------------------------------------------------------------------*/ +#include <24LC0X.h> +#include +#include +/* +struct 24LC0X_str +{ + i2cDev iicdev; + unsigned char devAddress; + unsigned char size; +}; +*/ + + +void eeprom24lc0xopen(eeprom24lc0xDev* dev, i2c_t iicdev, unsigned char A0_A1_A2_val, unsigned int size) +{ + dev->iicdev = iicdev; + dev->devAddress = 0x50 | (A0_A1_A2_val & 0x7); + if(size == 2048) dev->size = 2; + if(size == 1024) dev->size = 1; +} + +void eeprom24lc0xpagewrite(eeprom24lc0xDev dev,unsigned char address,unsigned char* page) +{ + int cmdcnt=1,datacnt=8; + //i2cwrite(dev.iicdev,address,page) + //i2cwrite2(dev.iicdev,dev.devAddress,&address,&cmdcnt,page,&datacnt); +} + + +void eeprom24lc0xpageread(eeprom24lc0xDev dev,unsigned char address,unsigned char* page) +{ + int cmdcnt=1,datacnt=8; + /*i2cwrite(dev.iicdev,dev.devAddress,&address,&cmdcnt); + i2cread(dev.iicdev,dev.devAddress,page,&datacnt);*/ +} + +void eeprom24lc0xbytewrite(eeprom24lc0xDev dev,unsigned char address,unsigned char data) +{ + int cmdcnt=1,datacnt=1; + //i2cwrite2(dev.iicdev,dev.devAddress,&address,&cmdcnt,&data,&datacnt); +} + + +unsigned char eeprom24lc0xbyteread(eeprom24lc0xDev dev,unsigned char address) +{ + int cmdcnt=1,datacnt=1; + unsigned char data = 0; +/* i2cwrite(dev.iicdev,dev.devAddress,&address,&cmdcnt); + i2cread(dev.iicdev,dev.devAddress,&data,&datacnt);*/ + return data; +} + + +void eeprom24lc0xreadn(eeprom24lc0xDev dev,unsigned char address,unsigned char* data, unsigned int count) +{ + int cmdcnt=1,datacnt=count; +/* i2cwrite(dev.iicdev,dev.devAddress,&address,&cmdcnt); + i2cread(dev.iicdev,dev.devAddress,data,&datacnt);*/ + +} + +void eeprom24lc0xwriten(eeprom24lc0xDev dev,unsigned char address,unsigned char* data, unsigned int count) +{ + int cmdcnt=1,datacnt=8; + while(count >8) + { + cmdcnt=1;datacnt=8; +// while(i2noerr!=i2cwrite2(dev.iicdev,dev.devAddress,&address,&cmdcnt,data,&datacnt)){cmdcnt=1;datacnt=8;} + count-=8; + address+=8; + data+=8; + } + cmdcnt=1;datacnt=count; +// while(i2noerr!=i2cwrite2(dev.iicdev,dev.devAddress,&address,&cmdcnt,data,&datacnt)){cmdcnt=1;datacnt=count;} +} + + + + + + + diff --git a/lib/src/common/EEPROMS/24LCXX/24LC0X/24LC0X.pro b/lib/src/common/EEPROMS/24LCXX/24LC0X/24LC0X.pro new file mode 100644 --- /dev/null +++ b/lib/src/common/EEPROMS/24LCXX/24LC0X/24LC0X.pro @@ -0,0 +1,15 @@ +TEMPLATE = lib +OBJECTS_DIR = obj + +SOURCES += 24LC0X.c +HEADERS += ../../../includes/24LC0X.h + +INCLUDEPATH += ../../../includes \ + ../../CPU/STM32F4xx_StdPeriph_Driver/inc \ + ../../CPU/CMSIS/Include + + +UCMODEL=stm32f4 + +target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL +INSTALLS += target diff --git a/lib/src/common/EEPROMS/24LCXX/24LCXX.pro b/lib/src/common/EEPROMS/24LCXX/24LCXX.pro new file mode 100644 --- /dev/null +++ b/lib/src/common/EEPROMS/24LCXX/24LCXX.pro @@ -0,0 +1,2 @@ +TEMPLATE = subdirs +SUBDIRS += 24LC0X diff --git a/lib/src/common/EEPROMS/EEPROMS.pro b/lib/src/common/EEPROMS/EEPROMS.pro new file mode 100644 --- /dev/null +++ b/lib/src/common/EEPROMS/EEPROMS.pro @@ -0,0 +1,4 @@ +TEMPLATE = subdirs +SUBDIRS += \ + 24LCXX \ + N25Q128 diff --git a/lib/src/common/EEPROMS/N25Q128/N25Q128.c b/lib/src/common/EEPROMS/N25Q128/N25Q128.c new file mode 100644 --- /dev/null +++ b/lib/src/common/EEPROMS/N25Q128/N25Q128.c @@ -0,0 +1,136 @@ +/*------------------------------------------------------------------------------ +-- This file is a part of the libuc, microcontroler library +-- Copyright (C) 2013, Alexis Jeandet +-- +-- 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 3 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +------------------------------------------------------------------------------- +-- Author : Alexis Jeandet +-- Mail : alexis.jeandet@gmail.com +-------------------------------------------------------------------------------*/ +#include +#include +#include + + + +void eepromN25Q128open(eepromN25Q128Dev *dev, spi_t spidev, void (*select)(int), void (*writeprotect)(int), void (*holdreset)(int)) +{ + dev->spidev = spidev; + dev->holdreset = holdreset; + dev->select = select; + dev->writeprotect = writeprotect; +} + +void eepromN25Q128pagewrite(eepromN25Q128Dev* dev,uint32_t address,unsigned char* page) +{ + int cmdcnt=1,datacnt=8; +} + + +void eepromN25Q128pageread(eepromN25Q128Dev* dev,uint32_t address,unsigned char* page) +{ + int cmdcnt=1,datacnt=8; +} + +void eepromN25Q128bytewrite(eepromN25Q128Dev* dev,uint32_t address,unsigned char data) +{ + int cmdcnt=1,datacnt=1; +} + + +unsigned char eepromN25Q128byteread(eepromN25Q128Dev* dev,uint32_t address) +{ + int cmdcnt=1,datacnt=1; + unsigned char data = 0; + return data; +} + + +void eepromN25Q128readn(eepromN25Q128Dev* dev,uint32_t address,unsigned char* data, unsigned int count) +{ + + char baddress[3]; + baddress[0]=(char)0xFF&((address)>>16); + baddress[1]=(char)0xFF&((address)>>8); + baddress[2]=(char)0xFF&((address)); + printf("about to read %d bytes\n\r",count); + if(dev->select!=NULL)dev->select(0); + spiputw(dev->spidev,N25Q128_READ); + spiputnc(dev->spidev,baddress,3); + spigetnc(dev->spidev,data,count); + if(dev->select!=NULL)dev->select(1); + +} + +void eepromN25Q128writen(eepromN25Q128Dev* dev,uint32_t address,unsigned char* data, unsigned int count) +{ + char baddress[3]; + if(dev->select!=NULL)dev->select(0); + for(int i=0;i<(count/N25Q128_PAGE_SZ);i++) + { + printf("about to send %d bytes\n\r",N25Q128_PAGE_SZ); + int index =i*N25Q128_PAGE_SZ; + baddress[0]=(char)0xFF&((address+index)>>16); + baddress[1]=(char)0xFF&((address+index)>>8); + baddress[2]=(char)0xFF&((address+index)); + if(dev->select!=NULL)dev->select(0); + spiputw(dev->spidev,N25Q128_PP); + spiputnc(dev->spidev,baddress,3); + spiputnc(dev->spidev,data+(index),count); + if(dev->select!=NULL) + { + dev->select(1); + } + else { + while (!spitransactionfinished(dev->spidev)); + } + } + int mod = count%N25Q128_PAGE_SZ; + if(mod) + { + baddress[0]=(char)0xFF&((address+(count-mod))>>16); + baddress[1]=(char)0xFF&((address+(count-mod))>>8); + baddress[2]=(char)0xFF&((address+(count-mod))); + printf("about to send %d bytes\n\r",mod); + if(dev->select!=NULL)dev->select(0); + spiputw(dev->spidev,N25Q128_PP); + spiputnc(dev->spidev,baddress,3); + spiputnc(dev->spidev,data+(count-mod),mod); + if(dev->select!=NULL) + { + dev->select(1); + } + else { + while (!spitransactionfinished(dev->spidev)); + } + + } + +} + + +void eepromN25Q128enablewrite(eepromN25Q128Dev *dev) +{ + if(dev->select!=NULL)dev->select(0); + spiputw(dev->spidev,N25Q128_WREN); + if(dev->select!=NULL)dev->select(1); + +} + + + + + + diff --git a/lib/src/common/EEPROMS/N25Q128/N25Q128.pro b/lib/src/common/EEPROMS/N25Q128/N25Q128.pro new file mode 100644 --- /dev/null +++ b/lib/src/common/EEPROMS/N25Q128/N25Q128.pro @@ -0,0 +1,15 @@ +TEMPLATE = lib +OBJECTS_DIR = obj + +SOURCES += N25Q128.c +HEADERS += ../../../includes/N25Q128.h + +INCLUDEPATH += ../../../includes \ + ../../CPU/STM32F4xx_StdPeriph_Driver/inc \ + ../../CPU/CMSIS/Include + + +UCMODEL=stm32f4 + +target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL +INSTALLS += target diff --git a/lib/src/common/common.pro b/lib/src/common/common.pro --- a/lib/src/common/common.pro +++ b/lib/src/common/common.pro @@ -4,7 +4,8 @@ SUBDIRS += FILE_SYSTEM \ AUDIO \ POWER \ GRAPHIC \ - Threading + Threading \ + EEPROMS @@ -12,3 +13,4 @@ SUBDIRS += FILE_SYSTEM \ + diff --git a/lib/src/includes/24LC0X.h b/lib/src/includes/24LC0X.h --- a/lib/src/includes/24LC0X.h +++ b/lib/src/includes/24LC0X.h @@ -22,20 +22,19 @@ #ifndef B24LC0X_H #define B24LC0X_H -#include "iic.h" +#include #include -struct eeprom24LC0X_str +typedef struct eeprom24lc0xDev { - i2cDev iicdev; + i2c_t iicdev; unsigned char devAddress; unsigned char size; -}; - -typedef struct eeprom24LC0X_str eeprom24lc0xDev; +}eeprom24lc0xDev; -extern void eeprom24lc0xopen(eeprom24lc0xDev* dev,i2cDev iicdev,unsigned char A0_A1_A2_val,unsigned int size); + +extern void eeprom24lc0xopen(eeprom24lc0xDev* dev,i2c_t iicdev,unsigned char A0_A1_A2_val,unsigned int size); extern void eeprom24lc0xpagewrite(eeprom24lc0xDev dev,unsigned char address,unsigned char* page); extern void eeprom24lc0xpageread(eeprom24lc0xDev dev,unsigned char address,unsigned char* page); diff --git a/lib/src/includes/N25Q128.h b/lib/src/includes/N25Q128.h new file mode 100644 --- /dev/null +++ b/lib/src/includes/N25Q128.h @@ -0,0 +1,74 @@ +/*------------------------------------------------------------------------------ +-- This file is a part of the libuc, microcontroler library +-- Copyright (C) 2013, Alexis Jeandet +-- +-- 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 3 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +------------------------------------------------------------------------------- +-- Author : Alexis Jeandet +-- Mail : alexis.jeandet@gmail.com +-------------------------------------------------------------------------------*/ +#ifndef N25Q128_H +#define N25Q128_H + +#include +#include +#include + +typedef struct eepromN25Q128Dev +{ + spi_t spidev; + void (*select)(int sel); + void (*writeprotect)(int wp); + void (*holdreset)(int hr); +}eepromN25Q128Dev; + +#define N25Q128_PAGE_SZ 256 + +#define N25Q128_READID 0x9E +#define N25Q128_READ 0x03 +#define N25Q128_FASTREAD 0x0B +#define N25Q128_DOFR 0x3B +#define N25Q128_DIOFR 0xBB +#define N25Q128_QOFR 0x6B +#define N25Q128_QIOFR 0xEB +#define N25Q128_ROTP 0x4B +#define N25Q128_WREN 0x06 +#define N25Q128_WRDI 0x04 +#define N25Q128_PP 0x02 + + + + + +extern void eepromN25Q128open(eepromN25Q128Dev* dev,spi_t spidev,void (*select)(int sel),void (*writeprotect)(int wp),void (*holdreset)(int hr)); +extern void eepromN25Q128pagewrite(eepromN25Q128Dev* dev,uint32_t address,unsigned char* page); +extern void eepromN25Q128pageread(eepromN25Q128Dev* dev,uint32_t address,unsigned char* page); +extern void eepromN25Q128bytewrite(eepromN25Q128Dev* dev,uint32_t address,unsigned char data); +extern unsigned char eepromN25Q128byteread(eepromN25Q128Dev* dev,uint32_t address); +extern void eepromN25Q128readn(eepromN25Q128Dev* dev,uint32_t address,unsigned char* data, unsigned int count); +extern void eepromN25Q128writen(eepromN25Q128Dev* dev,uint32_t address,unsigned char* data, unsigned int count); +extern void eepromN25Q128enablewrite(eepromN25Q128Dev* dev); + + + + +#endif + + + + + + + diff --git a/lib/src/includes/VS10XX.h b/lib/src/includes/VS10XX.h new file mode 100644 --- /dev/null +++ b/lib/src/includes/VS10XX.h @@ -0,0 +1,78 @@ +/*------------------------------------------------------------------------------ +#-- This file is a part of the libuc, microcontroler library +#-- Copyright (C) 2011, Alexis Jeandet +#-- +#-- 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 3 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +#------------------------------------------------------------------------------- +#-- Author : Alexis Jeandet +#-- Mail : alexis.jeandet@gmail.com +#-------------------------------------------------------------------------------*/ +#ifndef VS10XX_H +#define VS10XX_H +#include +#include + +#define VSMODE 0 +#define VSSTATUS 1 +#define VSBASS 2 +#define VSCLOCKF 3 +#define VSDECODE_TIME 4 +#define VSAUDATA 5 +#define VSWRAM 6 +#define VSWRAMADDR 7 +#define VSHDAT0 8 +#define VSHDAT1 9 +#define VSAIADDR 0xA +#define VSVOL 0xB +#define VSAICTRL0 0xC +#define VSAICTRL1 0xD +#define VSAICTRL2 0xE +#define VSAICTRL3 0xF + +typedef struct vs10XXDev +{ + spi_t SPIdev; + int a; +}vs10XXDev; + + +void vs10XXopen(vs10XXDev* codec,spi_t dev); +void vs10XXsoftreset(vs10XXDev* dev); +int vs10XXcmdread(vs10XXDev* dev,char address); +void vs10XXcmdwrite(vs10XXDev* dev,char address,int value); + +extern void vs10XXclearXCS(); +extern void vs10XXsetXCS(); +extern int vs10XXDREQ(); + +#endif //VS10XX_H + + + + + + + + + + + + + + + + + + diff --git a/lib/src/includes/spi.h b/lib/src/includes/spi.h --- a/lib/src/includes/spi.h +++ b/lib/src/includes/spi.h @@ -44,15 +44,15 @@ typedef struct spi_t typedef int spi_t; - #define spi1 0 - #define spi2 1 - #define spi3 2 - #define spi4 3 - #define spi5 4 - #define spi6 5 - #define spi7 6 - #define spi8 7 - #define spi9 8 + #define spi1 ((spi_t)0) + #define spi2 ((spi_t)1) + #define spi3 ((spi_t)2) + #define spi4 ((spi_t)3) + #define spi5 ((spi_t)4) + #define spi6 ((spi_t)5) + #define spi7 ((spi_t)6) + #define spi8 ((spi_t)7) + #define spi9 ((spi_t)8) typedef enum @@ -114,6 +114,7 @@ extern int spiclose(spi_t spidev); extern int spisetpins(spi_t spidev,uint32_t MOSIpin,uint32_t MISOpin,uint32_t SCKpin,uint32_t SCSpin); extern int spienable(spi_t spidev); extern int spidisable(spi_t spidev); +extern int spitransactionfinished(spi_t spidev); extern int spisetconfig(spi_t spidev,uint32_t config,uint32_t speed); extern int spisetspeed(spi_t spidev, uint32_t speed); extern int spisetbitorder(spi_t spidev,spibitorder_t order); diff --git a/lib/src/includes/vs1053.h b/lib/src/includes/vs1053.h deleted file mode 100644 --- a/lib/src/includes/vs1053.h +++ /dev/null @@ -1,78 +0,0 @@ -/*------------------------------------------------------------------------------ -#-- This file is a part of the libuc, microcontroler library -#-- Copyright (C) 2011, Alexis Jeandet -#-- -#-- 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 3 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -#------------------------------------------------------------------------------- -#-- Author : Alexis Jeandet -#-- Mail : alexis.jeandet@gmail.com -#-------------------------------------------------------------------------------*/ -#ifndef VS1053_H -#define VS1053_H -#include - -#define VSMODE 0 -#define VSSTATUS 1 -#define VSBASS 2 -#define VSCLOCKF 3 -#define VSDECODE_TIME 4 -#define VSAUDATA 5 -#define VSWRAM 6 -#define VSWRAMADDR 7 -#define VSHDAT0 8 -#define VSHDAT1 9 -#define VSAIADDR 0xA -#define VSVOL 0xB -#define VSAICTRL0 0xC -#define VSAICTRL1 0xD -#define VSAICTRL2 0xE -#define VSAICTRL3 0xF - -struct vs1053Regs -{ - sspDev SSP_device; - int a; -}; - -typedef struct vs1053Regs vs1053Dev; - -void vs1053open(vs1053Dev* codec,sspDev dev); -void vs1053softreset(vs1053Dev* dev); -int vs1053cmdread(vs1053Dev* dev,char address); -void vs1053cmdwrite(vs1053Dev* dev,char address,int value); - -extern void vs10XXclearXCS(); -extern void vs10XXsetXCS(); -extern int vs10XXDREQ(); - -#endif - - - - - - - - - - - - - - - - - - diff --git a/lib/src/stm32f4/SPI/spi.c b/lib/src/stm32f4/SPI/spi.c --- a/lib/src/stm32f4/SPI/spi.c +++ b/lib/src/stm32f4/SPI/spi.c @@ -352,7 +352,7 @@ uint16_t spigetw(spi_t spidev) SPI_TypeDef* _dev_ = _spi_dev_table[(int)spidev]; while((_dev_->SR & (1<<7)) == (1<<7)); _dev_->DR = 0xFFFF; - while((_dev_->SR & (1<<0)) == 0); + while(((_dev_->SR & (1<<0)) == 0) || (_dev_->SR & (1<<7)) == (1<<7)); return _dev_->DR; } return -1; @@ -420,6 +420,15 @@ int spiavailiabledata(spi_t spidev) } +int spitransactionfinished(spi_t spidev) +{ + SPI_TypeDef* _dev_ = _spi_dev_table[(int)spidev]; + if((spidev<3)&&(spidev>=0)) + { + if((_dev_->SR & (1<<7)) == (1<<7))return 1; + } + return 0; +} @@ -435,3 +444,5 @@ int spiavailiabledata(spi_t spidev) + + diff --git a/lib/src/stm32f4/SPI/spi.pro b/lib/src/stm32f4/SPI/spi.pro --- a/lib/src/stm32f4/SPI/spi.pro +++ b/lib/src/stm32f4/SPI/spi.pro @@ -3,6 +3,8 @@ OBJECTS_DIR = obj SOURCES += spi.c +HEADERS += ../../includes/spi.h + INCLUDEPATH += ../../includes \ ../CPU/STM32F4xx_StdPeriph_Driver/inc \ ../CPU/CMSIS/Include