@@ -0,0 +1,22 | |||||
|
1 | TEMPLATE = app | |||
|
2 | ||||
|
3 | DEFINES += CPUFREQ=40000000 | |||
|
4 | ||||
|
5 | LIBS += -ldac | |||
|
6 | ||||
|
7 | eval(UCMODEL = simulator) { | |||
|
8 | BSP = SIMULATOR | |||
|
9 | } | |||
|
10 | eval(UCMODEL = stm32f4) { | |||
|
11 | BSP = STM32F4Eval | |||
|
12 | } | |||
|
13 | ||||
|
14 | SOURCES += \ | |||
|
15 | main.c | |||
|
16 | ||||
|
17 | ||||
|
18 | ||||
|
19 | ||||
|
20 | ||||
|
21 | ||||
|
22 |
@@ -0,0 +1,56 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the libuc, microcontroler library | |||
|
3 | -- Copyright (C) 2013, Alexis Jeandet | |||
|
4 | -- | |||
|
5 | -- This program is free software; you can redistribute it and/or modify | |||
|
6 | -- it under the terms of the GNU General Public License as published by | |||
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
15 | -- You should have received a copy of the GNU General Public License | |||
|
16 | -- along with this program; if not, write to the Free Software | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | -------------------------------------------------------------------------------*/ | |||
|
19 | /** @author Alexis Jeandet alexis.jeandet@member.fsf.org | |||
|
20 | -------------------------------------------------------------------------------*/ | |||
|
21 | /** | |||
|
22 | * This file is a simple example for the DAC library. | |||
|
23 | * | |||
|
24 | */ | |||
|
25 | ||||
|
26 | #include <stdio.h> | |||
|
27 | #include <uhandle.h> | |||
|
28 | #include <dac.h> | |||
|
29 | #include <timer.h> | |||
|
30 | #include <gpio.h> | |||
|
31 | #include <math.h> | |||
|
32 | int16_t __attribute__ ((aligned (4))) data[512]; | |||
|
33 | int libuc_main() | |||
|
34 | { | |||
|
35 | /** | |||
|
36 | Depending on the board the printf can be directed on one uart or LCD screen or | |||
|
37 | any other stream device. | |||
|
38 | */ | |||
|
39 | printf("DAC example\n\r"); | |||
|
40 | for(int i=0;i<512;i++) | |||
|
41 | { | |||
|
42 | data[i]=(int16_t)(2000.0*cos(i/10.0))+2000.0; | |||
|
43 | } | |||
|
44 | dacopen(PA4); | |||
|
45 | dacsetconfig(timer8, 512, DAC1,DAC1_12bit_right_align , 100000,(void*)data); | |||
|
46 | return 0; | |||
|
47 | } | |||
|
48 | ||||
|
49 | ||||
|
50 | ||||
|
51 | ||||
|
52 | ||||
|
53 | ||||
|
54 | ||||
|
55 | ||||
|
56 |
@@ -0,0 +1,18 | |||||
|
1 | TEMPLATE = app | |||
|
2 | ||||
|
3 | eval(UCMODEL = simulator) { | |||
|
4 | BSP = SIMULATOR | |||
|
5 | } | |||
|
6 | eval(UCMODEL = stm32f4) { | |||
|
7 | BSP = STM32F4Eval | |||
|
8 | } | |||
|
9 | ||||
|
10 | SOURCES += \ | |||
|
11 | main.c | |||
|
12 | ||||
|
13 | ||||
|
14 | ||||
|
15 | ||||
|
16 | ||||
|
17 | ||||
|
18 |
@@ -0,0 +1,45 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the libuc, microcontroler library | |||
|
3 | -- Copyright (C) 2013, Alexis Jeandet | |||
|
4 | -- | |||
|
5 | -- This program is free software; you can redistribute it and/or modify | |||
|
6 | -- it under the terms of the GNU General Public License as published by | |||
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
15 | -- You should have received a copy of the GNU General Public License | |||
|
16 | -- along with this program; if not, write to the Free Software | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | -------------------------------------------------------------------------------*/ | |||
|
19 | /** @author Alexis Jeandet alexis.jeandet@member.fsf.org | |||
|
20 | -------------------------------------------------------------------------------*/ | |||
|
21 | /** | |||
|
22 | * This file is a simple hello world example it should run on any supported | |||
|
23 | * board/architecture couple. To change target board and architecture modify | |||
|
24 | * the project file. The value BSP contains the board name, and UCMODEL contain | |||
|
25 | * the target architecture. | |||
|
26 | */ | |||
|
27 | ||||
|
28 | int libuc_main() | |||
|
29 | { | |||
|
30 | /** | |||
|
31 | Depending on the board the printf can be directed on one uart or LCD screen or | |||
|
32 | any other stream device. | |||
|
33 | */ | |||
|
34 | printf("hello world\n\r"); | |||
|
35 | return 0; | |||
|
36 | } | |||
|
37 | ||||
|
38 | ||||
|
39 | ||||
|
40 | ||||
|
41 | ||||
|
42 | ||||
|
43 | ||||
|
44 | ||||
|
45 |
@@ -0,0 +1,65 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the libuc, microcontroler library | |||
|
3 | -- Copyright (C) 2014, Kaveh Mohamadabadi | |||
|
4 | -- | |||
|
5 | -- This program is free software; you can redistribute it and/or modify | |||
|
6 | -- it under the terms of the GNU General Public License as published by | |||
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
15 | -- You should have received a copy of the GNU General Public License | |||
|
16 | -- along with this program; if not, write to the Free Software | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | ------------------------------------------------------------------------------- | |||
|
19 | -- Author : Kaveh Mohamadabadi | |||
|
20 | -- Mail : kaveh.mohamadabadi@gmail.com | |||
|
21 | -------------------------------------------------------------------------------*/ | |||
|
22 | /// \defgroup TIMER | |||
|
23 | /*! \file timer.h | |||
|
24 | \brief TIMER api. | |||
|
25 | ||||
|
26 | ||||
|
27 | \ingroup TIMER | |||
|
28 | ||||
|
29 | */ | |||
|
30 | #ifndef TIMER_H | |||
|
31 | #define TIMER_H | |||
|
32 | ||||
|
33 | #include <stdint.h> | |||
|
34 | #ifdef __cplusplus | |||
|
35 | extern "C" { | |||
|
36 | #endif | |||
|
37 | ||||
|
38 | ||||
|
39 | #ifdef __cplusplus | |||
|
40 | } | |||
|
41 | #endif | |||
|
42 | ||||
|
43 | #ifndef DOXYGEN_SHOULD_SKIP_THIS | |||
|
44 | ||||
|
45 | #define timer1 0 | |||
|
46 | #define timer2 1 | |||
|
47 | #define timer3 2 | |||
|
48 | #define timer4 3 | |||
|
49 | #define timer5 4 | |||
|
50 | #define timer6 5 | |||
|
51 | #define timer7 6 | |||
|
52 | #define timer8 7 | |||
|
53 | #define timer9 8 | |||
|
54 | #define timer10 9 | |||
|
55 | #define timer11 10 | |||
|
56 | #define timer12 11 | |||
|
57 | #define timer13 12 | |||
|
58 | #define timer14 13 | |||
|
59 | #define timer15 14 | |||
|
60 | #define timer16 15 | |||
|
61 | ||||
|
62 | ||||
|
63 | ||||
|
64 | #endif | |||
|
65 | #endif // TIMER_H |
@@ -0,0 +1,13 | |||||
|
1 | TEMPLATE = lib | |||
|
2 | CONFIG += libuc2lib | |||
|
3 | ||||
|
4 | SOURCES += timer.c | |||
|
5 | ||||
|
6 | ||||
|
7 | UCMODEL=stm32f4 | |||
|
8 | ||||
|
9 | HEADERS += \ | |||
|
10 | ../../../include/PERIPHERALS/timer.h | |||
|
11 | ||||
|
12 | ||||
|
13 |
@@ -1,31 +1,21 | |||||
1 | TEMPLATE = subdirs |
|
1 | TEMPLATE = subdirs | |
2 | CONFIG += ordered |
|
2 | CONFIG += ordered | |
3 |
|
3 | |||
4 |
|
4 | |||
5 | !isEmpty( UCMODEL ) { |
|
5 | !isEmpty( UCMODEL ) { | |
6 | contains( UCMODEL, stm32f4 ){ |
|
6 | contains( UCMODEL, stm32f4 ){ | |
7 | SUBDIRS += \ |
|
7 | SUBDIRS += \ | |
8 |
|
|
8 | helloWorld \ | |
9 | SOLAR_PSU_HELLO/hello.pro \ |
|
9 | DAC \ | |
10 |
|
|
10 | PWM | |
11 | STM32F4IT \ |
|
|||
12 | M4StickV2 \ |
|
|||
13 | lcdHello \ |
|
|||
14 | BeagleSynthHello \ |
|
|||
15 | lcdTerminal \ |
|
|||
16 | BeagleSynthHelloSupMon \ |
|
|||
17 | TEST_CMSIS_FFT \ |
|
|||
18 | N25Q128_test \ |
|
|||
19 | ssd2119Tests |
|
|||
20 | } |
|
11 | } | |
21 | contains( UCMODEL, simulator ){ |
|
12 | contains( UCMODEL, simulator ){ | |
22 | SUBDIRS += \ |
|
13 | SUBDIRS += \ | |
23 | TEST_SIMULATOR \ |
|
|||
24 | helloWorld |
|
14 | helloWorld | |
25 | } |
|
15 | } | |
26 | } |
|
16 | } | |
27 |
|
17 | |||
28 |
|
18 | |||
29 |
|
19 | |||
30 |
|
20 | |||
31 |
|
21 |
@@ -1,16 +1,19 | |||||
1 | UCMODEL=simulator |
|
|||
2 |
|
||||
3 |
|
|
1 | TEMPLATE = app | |
4 |
|
2 | |||
|
3 | eval(UCMODEL = simulator) { | |||
5 | BSP = SIMULATOR |
|
4 | BSP = SIMULATOR | |
6 |
|
5 | } | ||
|
6 | eval(UCMODEL = stm32f4) { | |||
|
7 | BSP = STM32F4Eval | |||
|
8 | } | |||
7 |
|
9 | |||
8 | SOURCES += \ |
|
10 | SOURCES += \ | |
9 | main.c |
|
11 | main.c | |
10 |
|
12 | |||
11 |
|
13 | |||
12 |
|
14 | |||
13 |
|
15 | |||
14 |
|
16 | |||
15 |
|
17 | |||
16 |
|
18 | |||
|
19 |
@@ -1,45 +1,46 | |||||
1 | /*------------------------------------------------------------------------------ |
|
1 | /*------------------------------------------------------------------------------ | |
2 | -- This file is a part of the libuc, microcontroler library |
|
2 | -- This file is a part of the libuc, microcontroler library | |
3 | -- Copyright (C) 2013, Alexis Jeandet |
|
3 | -- Copyright (C) 2013, Alexis Jeandet | |
4 | -- |
|
4 | -- | |
5 | -- This program is free software; you can redistribute it and/or modify |
|
5 | -- This program is free software; you can redistribute it and/or modify | |
6 | -- it under the terms of the GNU General Public License as published by |
|
6 | -- it under the terms of the GNU General Public License as published by | |
7 | -- the Free Software Foundation; either version 3 of the License, or |
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |
8 | -- (at your option) any later version. |
|
8 | -- (at your option) any later version. | |
9 | -- |
|
9 | -- | |
10 | -- This program is distributed in the hope that it will be useful, |
|
10 | -- This program is distributed in the hope that it will be useful, | |
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | -- GNU General Public License for more details. |
|
13 | -- GNU General Public License for more details. | |
14 | -- |
|
14 | -- | |
15 | -- You should have received a copy of the GNU General Public License |
|
15 | -- You should have received a copy of the GNU General Public License | |
16 | -- along with this program; if not, write to the Free Software |
|
16 | -- along with this program; if not, write to the Free Software | |
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | -------------------------------------------------------------------------------*/ |
|
18 | -------------------------------------------------------------------------------*/ | |
19 | /** @author Alexis Jeandet alexis.jeandet@member.fsf.org |
|
19 | /** @author Alexis Jeandet alexis.jeandet@member.fsf.org | |
20 | -------------------------------------------------------------------------------*/ |
|
20 | -------------------------------------------------------------------------------*/ | |
21 | /** |
|
21 | /** | |
22 | * This file is a simple hello world example it should run on any supported |
|
22 | * This file is a simple hello world example it should run on any supported | |
23 | * board/architecture couple. To change target board and architecture modify |
|
23 | * board/architecture couple. To change target board and architecture modify | |
24 | * the project file. The value BSP contains the board name, and UCMODEL contain |
|
24 | * the project file. The value BSP contains the board name, and UCMODEL contain | |
25 | * the target architecture. |
|
25 | * the target architecture. | |
26 | */ |
|
26 | */ | |
|
27 | #include <stdio.h> | |||
27 |
|
28 | |||
28 | int libuc_main() |
|
29 | int libuc_main() | |
29 | { |
|
30 | { | |
30 | /** |
|
31 | /** | |
31 | Depending on the board the printf can be directed on one uart or LCD screen or |
|
32 | Depending on the board the printf can be directed on one uart or LCD screen or | |
32 | any other stream device. |
|
33 | any other stream device. | |
33 | */ |
|
34 | */ | |
34 | printf("hello world\n\r"); |
|
35 | printf("hello world\n\r"); | |
35 | return 0; |
|
36 | return 0; | |
36 | } |
|
37 | } | |
37 |
|
38 | |||
38 |
|
39 | |||
39 |
|
40 | |||
40 |
|
41 | |||
41 |
|
42 | |||
42 |
|
43 | |||
43 |
|
44 | |||
44 |
|
45 | |||
45 |
|
46 |
@@ -1,33 +1,26 | |||||
1 | #ifndef DAC_LIB_H |
|
1 | #ifndef DAC_LIB_H | |
2 | #define DAC_LIB_H |
|
2 | #define DAC_LIB_H | |
3 |
|
3 | |||
4 | #define DAC1_12bit_right_align 0x40007408 |
|
4 | #define DAC1_12bit_right_align 0x40007408 | |
5 | #define DAC1_12bit_left_align 0x4000740C |
|
5 | #define DAC1_12bit_left_align 0x4000740C | |
6 | #define DAC1_8bit_right_align 0x40007410 |
|
6 | #define DAC1_8bit_right_align 0x40007410 | |
7 | #define DAC2_12bit_right_align 0x40007414 |
|
7 | #define DAC2_12bit_right_align 0x40007414 | |
8 | #define DAC2_12bit_left_align 0x40007418 |
|
8 | #define DAC2_12bit_left_align 0x40007418 | |
9 | #define DAC2_8bit_right_align 0x4000741C |
|
9 | #define DAC2_8bit_right_align 0x4000741C | |
10 | #define DAC_Dual_12bit_right_align 0x40007420 |
|
10 | #define DAC_Dual_12bit_right_align 0x40007420 | |
11 | #define DAC_Dual_12bit_left_align 0x40007424 |
|
11 | #define DAC_Dual_12bit_left_align 0x40007424 | |
12 | #define DAC_Dual_8bit_right_align 0x40007428 |
|
12 | #define DAC_Dual_8bit_right_align 0x40007428 | |
13 | #define DAC_Dual_8bit_left_align 0x4000742C |
|
13 | #define DAC_Dual_8bit_left_align 0x4000742C | |
14 |
|
14 | |||
15 | #define DAC1 0 |
|
15 | #define DAC1 0 | |
16 | #define DAC2 1 |
|
16 | #define DAC2 1 | |
17 |
|
17 | |||
18 | #define timer2 1 |
|
|||
19 | #define timer3 2 |
|
|||
20 | #define timer4 3 |
|
|||
21 | #define timer5 4 |
|
|||
22 | #define timer6 5 |
|
|||
23 | #define timer7 6 |
|
|||
24 | #define timer8 7 |
|
|||
25 |
|
18 | |||
26 |
|
19 | |||
27 | extern int dacopen(uint32_t pin); |
|
20 | extern int dacopen(uint32_t pin); | |
28 |
extern int dacsetconfig(int timer, int buffer_size, int dac,uint32_t dac_type, uint32_t |
|
21 | extern int dacsetconfig(int timer, int buffer_size, int dac, uint32_t dac_type, uint32_t samplingFreq, void* data); | |
29 |
|
22 | |||
30 |
|
23 | |||
31 |
|
24 | |||
32 |
|
25 | |||
33 | #endif // DAC_LIB_H |
|
26 | #endif // DAC_LIB_H |
@@ -1,349 +1,346 | |||||
1 | /*------------------------------------------------------------------------------ |
|
1 | /*------------------------------------------------------------------------------ | |
2 | -- This file is a part of the libuc, microcontroler library |
|
2 | -- This file is a part of the libuc, microcontroler library | |
3 | -- Copyright (C) 2014, Kaveh Mohamadabadi |
|
3 | -- Copyright (C) 2014, Kaveh Mohamadabadi | |
4 | -- |
|
4 | -- | |
5 | -- This program is free software; you can redistribute it and/or modify |
|
5 | -- This program is free software; you can redistribute it and/or modify | |
6 | -- it under the terms of the GNU General Public License as published by |
|
6 | -- it under the terms of the GNU General Public License as published by | |
7 | -- the Free Software Foundation; either version 3 of the License, or |
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |
8 | -- (at your option) any later version. |
|
8 | -- (at your option) any later version. | |
9 | -- |
|
9 | -- | |
10 | -- This program is distributed in the hope that it will be useful, |
|
10 | -- This program is distributed in the hope that it will be useful, | |
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | -- GNU General Public License for more details. |
|
13 | -- GNU General Public License for more details. | |
14 | -- |
|
14 | -- | |
15 | -- You should have received a copy of the GNU General Public License |
|
15 | -- You should have received a copy of the GNU General Public License | |
16 | -- along with this program; if not, write to the Free Software |
|
16 | -- along with this program; if not, write to the Free Software | |
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | ------------------------------------------------------------------------------- |
|
18 | ------------------------------------------------------------------------------- | |
19 | -- Author : Kaveh Mohamadabadi |
|
19 | -- Author : Kaveh Mohamadabadi | |
20 | -- Mail : kaveh.mohamadabadi@gmail.com |
|
20 | -- Mail : kaveh.mohamadabadi@gmail.com | |
21 | -------------------------------------------------------------------------------*/ |
|
21 | -------------------------------------------------------------------------------*/ | |
22 | /// \defgroup PWM |
|
22 | /// \defgroup PWM | |
23 | /*! \file pwm.h |
|
23 | /*! \file pwm.h | |
24 | \brief PWM api. |
|
24 | \brief PWM api. | |
25 |
|
25 | |||
26 | The pwm api gives you a standard way to drive any pwm pin on any processor. |
|
26 | The pwm api gives you a standard way to drive any pwm pin on any processor. | |
27 | With this api you will be able to open and configure your PWM module, define the |
|
27 | With this api you will be able to open and configure your PWM module, define the | |
28 | associated pins when applicable and set the duty cycle and frequency. Note that depending |
|
28 | associated pins when applicable and set the duty cycle and frequency. Note that depending | |
29 | on the target architecture you can have soft or hard PWM. |
|
29 | on the target architecture you can have soft or hard PWM. | |
30 |
|
30 | |||
31 | A simple example to configure and use PWM4_CH4 on STM32 discovery for example. |
|
31 | A simple example to configure and use PWM4_CH4 on STM32 discovery for example. | |
32 | \code |
|
32 | \code | |
33 | // lets open PWM4_CH4 |
|
33 | // lets open PWM4_CH4 | |
34 | //config : |
|
34 | //config : | |
35 | // -TIMER = TIMER4 (PWM4=TIMER4) |
|
35 | // -TIMER = TIMER4 (PWM4=TIMER4) | |
36 | // -PWM channel = 4 |
|
36 | // -PWM channel = 4 | |
37 | // -PWM output = PD15 |
|
37 | // -PWM output = PD15 | |
38 | // -PWM frequency = 1kHz |
|
38 | // -PWM frequency = 1kHz | |
39 | // -PWM duty cycle = 40.5% |
|
39 | // -PWM duty cycle = 40.5% | |
40 | pwmopen(PWM4_CH4,PD15); |
|
40 | pwmopen(PWM4_CH4,PD15); | |
41 | int error = pwmsetconfig(PWM4_CH4,1000,40.5); |
|
41 | int error = pwmsetconfig(PWM4_CH4,1000,40.5); | |
42 | //check that everything is ok |
|
42 | //check that everything is ok | |
43 | if(error!=-1) //=> no error |
|
43 | if(error!=-1) //=> no error | |
44 | { |
|
44 | { | |
45 | //to change duty cycle to 15% for example: |
|
45 | //to change duty cycle to 15% for example: | |
46 | pwmsetdutycycle(PWM4_CH4,15.0); |
|
46 | pwmsetdutycycle(PWM4_CH4,15.0); | |
47 | //you can also change the frequency: |
|
47 | //you can also change the frequency: | |
48 | pwmsetfrequency(PWM4_CH4,455000); |
|
48 | pwmsetfrequency(PWM4_CH4,455000); | |
49 | } |
|
49 | } | |
50 |
|
50 | |||
51 | \endcode |
|
51 | \endcode | |
52 | \ingroup PWM |
|
52 | \ingroup PWM | |
53 |
|
53 | |||
54 | */ |
|
54 | */ | |
55 | #ifndef PWM_H |
|
55 | #ifndef PWM_H | |
56 | #define PWM_H |
|
56 | #define PWM_H | |
57 |
|
57 | |||
58 | #include <stdint.h> |
|
58 | #include <stdint.h> | |
59 | #ifdef __cplusplus |
|
59 | #ifdef __cplusplus | |
60 | extern "C" { |
|
60 | extern "C" { | |
61 | #endif |
|
61 | #endif | |
62 | /** |
|
62 | /** | |
63 | * @brief PWM open function |
|
63 | * @brief PWM open function | |
64 | * |
|
64 | * | |
65 | * This function opens the given PWM, it should turn it ON iff needed and enable it. |
|
65 | * This function opens the given PWM, it should turn it ON iff needed and enable it. | |
66 | * @param PWM The PWM module and channel PWM1_CH6 for example |
|
66 | * @param PWM The PWM module and channel PWM1_CH6 for example | |
67 | * @return The 0 on success or -1 if it fails. |
|
67 | * @return The 0 on success or -1 if it fails. | |
68 | * @ingroup PWM |
|
68 | * @ingroup PWM | |
69 | */ |
|
69 | */ | |
70 | extern int pwmopen(int PWM,uint32_t pin); |
|
70 | extern int pwmopen(int PWM,uint32_t pin); | |
71 | extern int pwmsetconfig(int PWM,uint32_t freq,float dutyCycle); |
|
71 | extern int pwmsetconfig(int PWM,uint32_t freq,float dutyCycle); | |
72 | extern int pwmsetdutycycle(int PWM,float dutyCycle); |
|
72 | extern int pwmsetdutycycle(int PWM,float dutyCycle); | |
73 | extern int pwmsetfrequency(int PWM,uint32_t freq); |
|
73 | extern int pwmsetfrequency(int PWM,uint32_t freq); | |
74 |
|
74 | |||
75 | #ifdef __cplusplus |
|
75 | #ifdef __cplusplus | |
76 | } |
|
76 | } | |
77 | #endif |
|
77 | #endif | |
78 |
|
78 | |||
79 | #ifndef DOXYGEN_SHOULD_SKIP_THIS |
|
79 | #ifndef DOXYGEN_SHOULD_SKIP_THIS | |
80 | #define UARTPARITYMASK 0x3 |
|
|||
81 | #define UARTBITSMASK 0xC |
|
|||
82 | #define UARTSTOPBITSMASK 0x70 |
|
|||
83 |
|
80 | |||
84 | typedef enum |
|
81 | typedef enum | |
85 | { |
|
82 | { | |
86 | channel1 = 0, |
|
83 | channel1 = 0, | |
87 | channel2 = 1, |
|
84 | channel2 = 1, | |
88 | channel3 = 2, |
|
85 | channel3 = 2, | |
89 | channel4 = 3, |
|
86 | channel4 = 3, | |
90 | }channelx; |
|
87 | }channelx; | |
91 |
|
88 | |||
92 | #define PWM1_CH1 ((0 << 8) + 0 ) |
|
89 | #define PWM1_CH1 ((0 << 8) + 0 ) | |
93 | #define PWM1_CH2 ((0 << 8) + 1 ) |
|
90 | #define PWM1_CH2 ((0 << 8) + 1 ) | |
94 | #define PWM1_CH3 ((0 << 8) + 2 ) |
|
91 | #define PWM1_CH3 ((0 << 8) + 2 ) | |
95 | #define PWM1_CH4 ((0 << 8) + 3 ) |
|
92 | #define PWM1_CH4 ((0 << 8) + 3 ) | |
96 | #define PWM1_CH5 ((0 << 8) + 4 ) |
|
93 | #define PWM1_CH5 ((0 << 8) + 4 ) | |
97 | #define PWM1_CH6 ((0 << 8) + 5 ) |
|
94 | #define PWM1_CH6 ((0 << 8) + 5 ) | |
98 | #define PWM1_CH7 ((0 << 8) + 6 ) |
|
95 | #define PWM1_CH7 ((0 << 8) + 6 ) | |
99 | #define PWM1_CH8 ((0 << 8) + 7 ) |
|
96 | #define PWM1_CH8 ((0 << 8) + 7 ) | |
100 | #define PWM1_CH9 ((0 << 8) + 8 ) |
|
97 | #define PWM1_CH9 ((0 << 8) + 8 ) | |
101 | #define PWM1_CH10 ((0 << 8) + 9 ) |
|
98 | #define PWM1_CH10 ((0 << 8) + 9 ) | |
102 | #define PWM1_CH11 ((0 << 8) + 10 ) |
|
99 | #define PWM1_CH11 ((0 << 8) + 10 ) | |
103 | #define PWM1_CH12 ((0 << 8) + 11 ) |
|
100 | #define PWM1_CH12 ((0 << 8) + 11 ) | |
104 | #define PWM1_CH13 ((0 << 8) + 12 ) |
|
101 | #define PWM1_CH13 ((0 << 8) + 12 ) | |
105 | #define PWM1_CH14 ((0 << 8) + 13 ) |
|
102 | #define PWM1_CH14 ((0 << 8) + 13 ) | |
106 | #define PWM1_CH15 ((0 << 8) + 14 ) |
|
103 | #define PWM1_CH15 ((0 << 8) + 14 ) | |
107 | #define PWM1_CH16 ((0 << 8) + 15 ) |
|
104 | #define PWM1_CH16 ((0 << 8) + 15 ) | |
108 | #define PWM2_CH1 ((1 << 8) + 0 ) |
|
105 | #define PWM2_CH1 ((1 << 8) + 0 ) | |
109 | #define PWM2_CH2 ((1 << 8) + 1 ) |
|
106 | #define PWM2_CH2 ((1 << 8) + 1 ) | |
110 | #define PWM2_CH3 ((1 << 8) + 2 ) |
|
107 | #define PWM2_CH3 ((1 << 8) + 2 ) | |
111 | #define PWM2_CH4 ((1 << 8) + 3 ) |
|
108 | #define PWM2_CH4 ((1 << 8) + 3 ) | |
112 | #define PWM2_CH5 ((1 << 8) + 4 ) |
|
109 | #define PWM2_CH5 ((1 << 8) + 4 ) | |
113 | #define PWM2_CH6 ((1 << 8) + 5 ) |
|
110 | #define PWM2_CH6 ((1 << 8) + 5 ) | |
114 | #define PWM2_CH7 ((1 << 8) + 6 ) |
|
111 | #define PWM2_CH7 ((1 << 8) + 6 ) | |
115 | #define PWM2_CH8 ((1 << 8) + 7 ) |
|
112 | #define PWM2_CH8 ((1 << 8) + 7 ) | |
116 | #define PWM2_CH9 ((1 << 8) + 8 ) |
|
113 | #define PWM2_CH9 ((1 << 8) + 8 ) | |
117 | #define PWM2_CH10 ((1 << 8) + 9 ) |
|
114 | #define PWM2_CH10 ((1 << 8) + 9 ) | |
118 | #define PWM2_CH11 ((1 << 8) + 10 ) |
|
115 | #define PWM2_CH11 ((1 << 8) + 10 ) | |
119 | #define PWM2_CH12 ((1 << 8) + 11 ) |
|
116 | #define PWM2_CH12 ((1 << 8) + 11 ) | |
120 | #define PWM2_CH13 ((1 << 8) + 12 ) |
|
117 | #define PWM2_CH13 ((1 << 8) + 12 ) | |
121 | #define PWM2_CH14 ((1 << 8) + 13 ) |
|
118 | #define PWM2_CH14 ((1 << 8) + 13 ) | |
122 | #define PWM2_CH15 ((1 << 8) + 14 ) |
|
119 | #define PWM2_CH15 ((1 << 8) + 14 ) | |
123 | #define PWM2_CH16 ((1 << 8) + 15 ) |
|
120 | #define PWM2_CH16 ((1 << 8) + 15 ) | |
124 | #define PWM3_CH1 ((2 << 8) + 0 ) |
|
121 | #define PWM3_CH1 ((2 << 8) + 0 ) | |
125 | #define PWM3_CH2 ((2 << 8) + 1 ) |
|
122 | #define PWM3_CH2 ((2 << 8) + 1 ) | |
126 | #define PWM3_CH3 ((2 << 8) + 2 ) |
|
123 | #define PWM3_CH3 ((2 << 8) + 2 ) | |
127 | #define PWM3_CH4 ((2 << 8) + 3 ) |
|
124 | #define PWM3_CH4 ((2 << 8) + 3 ) | |
128 | #define PWM3_CH5 ((2 << 8) + 4 ) |
|
125 | #define PWM3_CH5 ((2 << 8) + 4 ) | |
129 | #define PWM3_CH6 ((2 << 8) + 5 ) |
|
126 | #define PWM3_CH6 ((2 << 8) + 5 ) | |
130 | #define PWM3_CH7 ((2 << 8) + 6 ) |
|
127 | #define PWM3_CH7 ((2 << 8) + 6 ) | |
131 | #define PWM3_CH8 ((2 << 8) + 7 ) |
|
128 | #define PWM3_CH8 ((2 << 8) + 7 ) | |
132 | #define PWM3_CH9 ((2 << 8) + 8 ) |
|
129 | #define PWM3_CH9 ((2 << 8) + 8 ) | |
133 | #define PWM3_CH10 ((2 << 8) + 9 ) |
|
130 | #define PWM3_CH10 ((2 << 8) + 9 ) | |
134 | #define PWM3_CH11 ((2 << 8) + 10 ) |
|
131 | #define PWM3_CH11 ((2 << 8) + 10 ) | |
135 | #define PWM3_CH12 ((2 << 8) + 11 ) |
|
132 | #define PWM3_CH12 ((2 << 8) + 11 ) | |
136 | #define PWM3_CH13 ((2 << 8) + 12 ) |
|
133 | #define PWM3_CH13 ((2 << 8) + 12 ) | |
137 | #define PWM3_CH14 ((2 << 8) + 13 ) |
|
134 | #define PWM3_CH14 ((2 << 8) + 13 ) | |
138 | #define PWM3_CH15 ((2 << 8) + 14 ) |
|
135 | #define PWM3_CH15 ((2 << 8) + 14 ) | |
139 | #define PWM3_CH16 ((2 << 8) + 15 ) |
|
136 | #define PWM3_CH16 ((2 << 8) + 15 ) | |
140 | #define PWM4_CH1 ((3 << 8) + 0 ) |
|
137 | #define PWM4_CH1 ((3 << 8) + 0 ) | |
141 | #define PWM4_CH2 ((3 << 8) + 1 ) |
|
138 | #define PWM4_CH2 ((3 << 8) + 1 ) | |
142 | #define PWM4_CH3 ((3 << 8) + 2 ) |
|
139 | #define PWM4_CH3 ((3 << 8) + 2 ) | |
143 | #define PWM4_CH4 ((3 << 8) + 3 ) |
|
140 | #define PWM4_CH4 ((3 << 8) + 3 ) | |
144 | #define PWM4_CH5 ((3 << 8) + 4 ) |
|
141 | #define PWM4_CH5 ((3 << 8) + 4 ) | |
145 | #define PWM4_CH6 ((3 << 8) + 5 ) |
|
142 | #define PWM4_CH6 ((3 << 8) + 5 ) | |
146 | #define PWM4_CH7 ((3 << 8) + 6 ) |
|
143 | #define PWM4_CH7 ((3 << 8) + 6 ) | |
147 | #define PWM4_CH8 ((3 << 8) + 7 ) |
|
144 | #define PWM4_CH8 ((3 << 8) + 7 ) | |
148 | #define PWM4_CH9 ((3 << 8) + 8 ) |
|
145 | #define PWM4_CH9 ((3 << 8) + 8 ) | |
149 | #define PWM4_CH10 ((3 << 8) + 9 ) |
|
146 | #define PWM4_CH10 ((3 << 8) + 9 ) | |
150 | #define PWM4_CH11 ((3 << 8) + 10 ) |
|
147 | #define PWM4_CH11 ((3 << 8) + 10 ) | |
151 | #define PWM4_CH12 ((3 << 8) + 11 ) |
|
148 | #define PWM4_CH12 ((3 << 8) + 11 ) | |
152 | #define PWM4_CH13 ((3 << 8) + 12 ) |
|
149 | #define PWM4_CH13 ((3 << 8) + 12 ) | |
153 | #define PWM4_CH14 ((3 << 8) + 13 ) |
|
150 | #define PWM4_CH14 ((3 << 8) + 13 ) | |
154 | #define PWM4_CH15 ((3 << 8) + 14 ) |
|
151 | #define PWM4_CH15 ((3 << 8) + 14 ) | |
155 | #define PWM4_CH16 ((3 << 8) + 15 ) |
|
152 | #define PWM4_CH16 ((3 << 8) + 15 ) | |
156 | #define PWM5_CH1 ((4 << 8) + 0 ) |
|
153 | #define PWM5_CH1 ((4 << 8) + 0 ) | |
157 | #define PWM5_CH2 ((4 << 8) + 1 ) |
|
154 | #define PWM5_CH2 ((4 << 8) + 1 ) | |
158 | #define PWM5_CH3 ((4 << 8) + 2 ) |
|
155 | #define PWM5_CH3 ((4 << 8) + 2 ) | |
159 | #define PWM5_CH4 ((4 << 8) + 3 ) |
|
156 | #define PWM5_CH4 ((4 << 8) + 3 ) | |
160 | #define PWM5_CH5 ((4 << 8) + 4 ) |
|
157 | #define PWM5_CH5 ((4 << 8) + 4 ) | |
161 | #define PWM5_CH6 ((4 << 8) + 5 ) |
|
158 | #define PWM5_CH6 ((4 << 8) + 5 ) | |
162 | #define PWM5_CH7 ((4 << 8) + 6 ) |
|
159 | #define PWM5_CH7 ((4 << 8) + 6 ) | |
163 | #define PWM5_CH8 ((4 << 8) + 7 ) |
|
160 | #define PWM5_CH8 ((4 << 8) + 7 ) | |
164 | #define PWM5_CH9 ((4 << 8) + 8 ) |
|
161 | #define PWM5_CH9 ((4 << 8) + 8 ) | |
165 | #define PWM5_CH10 ((4 << 8) + 9 ) |
|
162 | #define PWM5_CH10 ((4 << 8) + 9 ) | |
166 | #define PWM5_CH11 ((4 << 8) + 10 ) |
|
163 | #define PWM5_CH11 ((4 << 8) + 10 ) | |
167 | #define PWM5_CH12 ((4 << 8) + 11 ) |
|
164 | #define PWM5_CH12 ((4 << 8) + 11 ) | |
168 | #define PWM5_CH13 ((4 << 8) + 12 ) |
|
165 | #define PWM5_CH13 ((4 << 8) + 12 ) | |
169 | #define PWM5_CH14 ((4 << 8) + 13 ) |
|
166 | #define PWM5_CH14 ((4 << 8) + 13 ) | |
170 | #define PWM5_CH15 ((4 << 8) + 14 ) |
|
167 | #define PWM5_CH15 ((4 << 8) + 14 ) | |
171 | #define PWM5_CH16 ((4 << 8) + 15 ) |
|
168 | #define PWM5_CH16 ((4 << 8) + 15 ) | |
172 | #define PWM6_CH1 ((5 << 8) + 0 ) |
|
169 | #define PWM6_CH1 ((5 << 8) + 0 ) | |
173 | #define PWM6_CH2 ((5 << 8) + 1 ) |
|
170 | #define PWM6_CH2 ((5 << 8) + 1 ) | |
174 | #define PWM6_CH3 ((5 << 8) + 2 ) |
|
171 | #define PWM6_CH3 ((5 << 8) + 2 ) | |
175 | #define PWM6_CH4 ((5 << 8) + 3 ) |
|
172 | #define PWM6_CH4 ((5 << 8) + 3 ) | |
176 | #define PWM6_CH5 ((5 << 8) + 4 ) |
|
173 | #define PWM6_CH5 ((5 << 8) + 4 ) | |
177 | #define PWM6_CH6 ((5 << 8) + 5 ) |
|
174 | #define PWM6_CH6 ((5 << 8) + 5 ) | |
178 | #define PWM6_CH7 ((5 << 8) + 6 ) |
|
175 | #define PWM6_CH7 ((5 << 8) + 6 ) | |
179 | #define PWM6_CH8 ((5 << 8) + 7 ) |
|
176 | #define PWM6_CH8 ((5 << 8) + 7 ) | |
180 | #define PWM6_CH9 ((5 << 8) + 8 ) |
|
177 | #define PWM6_CH9 ((5 << 8) + 8 ) | |
181 | #define PWM6_CH10 ((5 << 8) + 9 ) |
|
178 | #define PWM6_CH10 ((5 << 8) + 9 ) | |
182 | #define PWM6_CH11 ((5 << 8) + 10 ) |
|
179 | #define PWM6_CH11 ((5 << 8) + 10 ) | |
183 | #define PWM6_CH12 ((5 << 8) + 11 ) |
|
180 | #define PWM6_CH12 ((5 << 8) + 11 ) | |
184 | #define PWM6_CH13 ((5 << 8) + 12 ) |
|
181 | #define PWM6_CH13 ((5 << 8) + 12 ) | |
185 | #define PWM6_CH14 ((5 << 8) + 13 ) |
|
182 | #define PWM6_CH14 ((5 << 8) + 13 ) | |
186 | #define PWM6_CH15 ((5 << 8) + 14 ) |
|
183 | #define PWM6_CH15 ((5 << 8) + 14 ) | |
187 | #define PWM6_CH16 ((5 << 8) + 15 ) |
|
184 | #define PWM6_CH16 ((5 << 8) + 15 ) | |
188 | #define PWM7_CH1 ((6 << 8) + 0 ) |
|
185 | #define PWM7_CH1 ((6 << 8) + 0 ) | |
189 | #define PWM7_CH2 ((6 << 8) + 1 ) |
|
186 | #define PWM7_CH2 ((6 << 8) + 1 ) | |
190 | #define PWM7_CH3 ((6 << 8) + 2 ) |
|
187 | #define PWM7_CH3 ((6 << 8) + 2 ) | |
191 | #define PWM7_CH4 ((6 << 8) + 3 ) |
|
188 | #define PWM7_CH4 ((6 << 8) + 3 ) | |
192 | #define PWM7_CH5 ((6 << 8) + 4 ) |
|
189 | #define PWM7_CH5 ((6 << 8) + 4 ) | |
193 | #define PWM7_CH6 ((6 << 8) + 5 ) |
|
190 | #define PWM7_CH6 ((6 << 8) + 5 ) | |
194 | #define PWM7_CH7 ((6 << 8) + 6 ) |
|
191 | #define PWM7_CH7 ((6 << 8) + 6 ) | |
195 | #define PWM7_CH8 ((6 << 8) + 7 ) |
|
192 | #define PWM7_CH8 ((6 << 8) + 7 ) | |
196 | #define PWM7_CH9 ((6 << 8) + 8 ) |
|
193 | #define PWM7_CH9 ((6 << 8) + 8 ) | |
197 | #define PWM7_CH10 ((6 << 8) + 9 ) |
|
194 | #define PWM7_CH10 ((6 << 8) + 9 ) | |
198 | #define PWM7_CH11 ((6 << 8) + 10 ) |
|
195 | #define PWM7_CH11 ((6 << 8) + 10 ) | |
199 | #define PWM7_CH12 ((6 << 8) + 11 ) |
|
196 | #define PWM7_CH12 ((6 << 8) + 11 ) | |
200 | #define PWM7_CH13 ((6 << 8) + 12 ) |
|
197 | #define PWM7_CH13 ((6 << 8) + 12 ) | |
201 | #define PWM7_CH14 ((6 << 8) + 13 ) |
|
198 | #define PWM7_CH14 ((6 << 8) + 13 ) | |
202 | #define PWM7_CH15 ((6 << 8) + 14 ) |
|
199 | #define PWM7_CH15 ((6 << 8) + 14 ) | |
203 | #define PWM7_CH16 ((6 << 8) + 15 ) |
|
200 | #define PWM7_CH16 ((6 << 8) + 15 ) | |
204 | #define PWM8_CH1 ((7 << 8) + 0 ) |
|
201 | #define PWM8_CH1 ((7 << 8) + 0 ) | |
205 | #define PWM8_CH2 ((7 << 8) + 1 ) |
|
202 | #define PWM8_CH2 ((7 << 8) + 1 ) | |
206 | #define PWM8_CH3 ((7 << 8) + 2 ) |
|
203 | #define PWM8_CH3 ((7 << 8) + 2 ) | |
207 | #define PWM8_CH4 ((7 << 8) + 3 ) |
|
204 | #define PWM8_CH4 ((7 << 8) + 3 ) | |
208 | #define PWM8_CH5 ((7 << 8) + 4 ) |
|
205 | #define PWM8_CH5 ((7 << 8) + 4 ) | |
209 | #define PWM8_CH6 ((7 << 8) + 5 ) |
|
206 | #define PWM8_CH6 ((7 << 8) + 5 ) | |
210 | #define PWM8_CH7 ((7 << 8) + 6 ) |
|
207 | #define PWM8_CH7 ((7 << 8) + 6 ) | |
211 | #define PWM8_CH8 ((7 << 8) + 7 ) |
|
208 | #define PWM8_CH8 ((7 << 8) + 7 ) | |
212 | #define PWM8_CH9 ((7 << 8) + 8 ) |
|
209 | #define PWM8_CH9 ((7 << 8) + 8 ) | |
213 | #define PWM8_CH10 ((7 << 8) + 9 ) |
|
210 | #define PWM8_CH10 ((7 << 8) + 9 ) | |
214 | #define PWM8_CH11 ((7 << 8) + 10 ) |
|
211 | #define PWM8_CH11 ((7 << 8) + 10 ) | |
215 | #define PWM8_CH12 ((7 << 8) + 11 ) |
|
212 | #define PWM8_CH12 ((7 << 8) + 11 ) | |
216 | #define PWM8_CH13 ((7 << 8) + 12 ) |
|
213 | #define PWM8_CH13 ((7 << 8) + 12 ) | |
217 | #define PWM8_CH14 ((7 << 8) + 13 ) |
|
214 | #define PWM8_CH14 ((7 << 8) + 13 ) | |
218 | #define PWM8_CH15 ((7 << 8) + 14 ) |
|
215 | #define PWM8_CH15 ((7 << 8) + 14 ) | |
219 | #define PWM8_CH16 ((7 << 8) + 15 ) |
|
216 | #define PWM8_CH16 ((7 << 8) + 15 ) | |
220 | #define PWM9_CH1 ((8 << 8) + 0 ) |
|
217 | #define PWM9_CH1 ((8 << 8) + 0 ) | |
221 | #define PWM9_CH2 ((8 << 8) + 1 ) |
|
218 | #define PWM9_CH2 ((8 << 8) + 1 ) | |
222 | #define PWM9_CH3 ((8 << 8) + 2 ) |
|
219 | #define PWM9_CH3 ((8 << 8) + 2 ) | |
223 | #define PWM9_CH4 ((8 << 8) + 3 ) |
|
220 | #define PWM9_CH4 ((8 << 8) + 3 ) | |
224 | #define PWM9_CH5 ((8 << 8) + 4 ) |
|
221 | #define PWM9_CH5 ((8 << 8) + 4 ) | |
225 | #define PWM9_CH6 ((8 << 8) + 5 ) |
|
222 | #define PWM9_CH6 ((8 << 8) + 5 ) | |
226 | #define PWM9_CH7 ((8 << 8) + 6 ) |
|
223 | #define PWM9_CH7 ((8 << 8) + 6 ) | |
227 | #define PWM9_CH8 ((8 << 8) + 7 ) |
|
224 | #define PWM9_CH8 ((8 << 8) + 7 ) | |
228 | #define PWM9_CH9 ((8 << 8) + 8 ) |
|
225 | #define PWM9_CH9 ((8 << 8) + 8 ) | |
229 | #define PWM9_CH10 ((8 << 8) + 9 ) |
|
226 | #define PWM9_CH10 ((8 << 8) + 9 ) | |
230 | #define PWM9_CH11 ((8 << 8) + 10 ) |
|
227 | #define PWM9_CH11 ((8 << 8) + 10 ) | |
231 | #define PWM9_CH12 ((8 << 8) + 11 ) |
|
228 | #define PWM9_CH12 ((8 << 8) + 11 ) | |
232 | #define PWM9_CH13 ((8 << 8) + 12 ) |
|
229 | #define PWM9_CH13 ((8 << 8) + 12 ) | |
233 | #define PWM9_CH14 ((8 << 8) + 13 ) |
|
230 | #define PWM9_CH14 ((8 << 8) + 13 ) | |
234 | #define PWM9_CH15 ((8 << 8) + 14 ) |
|
231 | #define PWM9_CH15 ((8 << 8) + 14 ) | |
235 | #define PWM9_CH16 ((8 << 8) + 15 ) |
|
232 | #define PWM9_CH16 ((8 << 8) + 15 ) | |
236 | #define PWM10_CH1 ((9 << 8) + 0 ) |
|
233 | #define PWM10_CH1 ((9 << 8) + 0 ) | |
237 | #define PWM10_CH2 ((9 << 8) + 1 ) |
|
234 | #define PWM10_CH2 ((9 << 8) + 1 ) | |
238 | #define PWM10_CH3 ((9 << 8) + 2 ) |
|
235 | #define PWM10_CH3 ((9 << 8) + 2 ) | |
239 | #define PWM10_CH4 ((9 << 8) + 3 ) |
|
236 | #define PWM10_CH4 ((9 << 8) + 3 ) | |
240 | #define PWM10_CH5 ((9 << 8) + 4 ) |
|
237 | #define PWM10_CH5 ((9 << 8) + 4 ) | |
241 | #define PWM10_CH6 ((9 << 8) + 5 ) |
|
238 | #define PWM10_CH6 ((9 << 8) + 5 ) | |
242 | #define PWM10_CH7 ((9 << 8) + 6 ) |
|
239 | #define PWM10_CH7 ((9 << 8) + 6 ) | |
243 | #define PWM10_CH8 ((9 << 8) + 7 ) |
|
240 | #define PWM10_CH8 ((9 << 8) + 7 ) | |
244 | #define PWM10_CH9 ((9 << 8) + 8 ) |
|
241 | #define PWM10_CH9 ((9 << 8) + 8 ) | |
245 | #define PWM10_CH10 ((9 << 8) + 9 ) |
|
242 | #define PWM10_CH10 ((9 << 8) + 9 ) | |
246 | #define PWM10_CH11 ((9 << 8) + 10 ) |
|
243 | #define PWM10_CH11 ((9 << 8) + 10 ) | |
247 | #define PWM10_CH12 ((9 << 8) + 11 ) |
|
244 | #define PWM10_CH12 ((9 << 8) + 11 ) | |
248 | #define PWM10_CH13 ((9 << 8) + 12 ) |
|
245 | #define PWM10_CH13 ((9 << 8) + 12 ) | |
249 | #define PWM10_CH14 ((9 << 8) + 13 ) |
|
246 | #define PWM10_CH14 ((9 << 8) + 13 ) | |
250 | #define PWM10_CH15 ((9 << 8) + 14 ) |
|
247 | #define PWM10_CH15 ((9 << 8) + 14 ) | |
251 | #define PWM10_CH16 ((9 << 8) + 15 ) |
|
248 | #define PWM10_CH16 ((9 << 8) + 15 ) | |
252 | #define PWM11_CH1 ((10 << 8) + 0 ) |
|
249 | #define PWM11_CH1 ((10 << 8) + 0 ) | |
253 | #define PWM11_CH2 ((10 << 8) + 1 ) |
|
250 | #define PWM11_CH2 ((10 << 8) + 1 ) | |
254 | #define PWM11_CH3 ((10 << 8) + 2 ) |
|
251 | #define PWM11_CH3 ((10 << 8) + 2 ) | |
255 | #define PWM11_CH4 ((10 << 8) + 3 ) |
|
252 | #define PWM11_CH4 ((10 << 8) + 3 ) | |
256 | #define PWM11_CH5 ((10 << 8) + 4 ) |
|
253 | #define PWM11_CH5 ((10 << 8) + 4 ) | |
257 | #define PWM11_CH6 ((10 << 8) + 5 ) |
|
254 | #define PWM11_CH6 ((10 << 8) + 5 ) | |
258 | #define PWM11_CH7 ((10 << 8) + 6 ) |
|
255 | #define PWM11_CH7 ((10 << 8) + 6 ) | |
259 | #define PWM11_CH8 ((10 << 8) + 7 ) |
|
256 | #define PWM11_CH8 ((10 << 8) + 7 ) | |
260 | #define PWM11_CH9 ((10 << 8) + 8 ) |
|
257 | #define PWM11_CH9 ((10 << 8) + 8 ) | |
261 | #define PWM11_CH10 ((10 << 8) + 9 ) |
|
258 | #define PWM11_CH10 ((10 << 8) + 9 ) | |
262 | #define PWM11_CH11 ((10 << 8) + 10 ) |
|
259 | #define PWM11_CH11 ((10 << 8) + 10 ) | |
263 | #define PWM11_CH12 ((10 << 8) + 11 ) |
|
260 | #define PWM11_CH12 ((10 << 8) + 11 ) | |
264 | #define PWM11_CH13 ((10 << 8) + 12 ) |
|
261 | #define PWM11_CH13 ((10 << 8) + 12 ) | |
265 | #define PWM11_CH14 ((10 << 8) + 13 ) |
|
262 | #define PWM11_CH14 ((10 << 8) + 13 ) | |
266 | #define PWM11_CH15 ((10 << 8) + 14 ) |
|
263 | #define PWM11_CH15 ((10 << 8) + 14 ) | |
267 | #define PWM11_CH16 ((10 << 8) + 15 ) |
|
264 | #define PWM11_CH16 ((10 << 8) + 15 ) | |
268 | #define PWM12_CH1 ((11 << 8) + 0 ) |
|
265 | #define PWM12_CH1 ((11 << 8) + 0 ) | |
269 | #define PWM12_CH2 ((11 << 8) + 1 ) |
|
266 | #define PWM12_CH2 ((11 << 8) + 1 ) | |
270 | #define PWM12_CH3 ((11 << 8) + 2 ) |
|
267 | #define PWM12_CH3 ((11 << 8) + 2 ) | |
271 | #define PWM12_CH4 ((11 << 8) + 3 ) |
|
268 | #define PWM12_CH4 ((11 << 8) + 3 ) | |
272 | #define PWM12_CH5 ((11 << 8) + 4 ) |
|
269 | #define PWM12_CH5 ((11 << 8) + 4 ) | |
273 | #define PWM12_CH6 ((11 << 8) + 5 ) |
|
270 | #define PWM12_CH6 ((11 << 8) + 5 ) | |
274 | #define PWM12_CH7 ((11 << 8) + 6 ) |
|
271 | #define PWM12_CH7 ((11 << 8) + 6 ) | |
275 | #define PWM12_CH8 ((11 << 8) + 7 ) |
|
272 | #define PWM12_CH8 ((11 << 8) + 7 ) | |
276 | #define PWM12_CH9 ((11 << 8) + 8 ) |
|
273 | #define PWM12_CH9 ((11 << 8) + 8 ) | |
277 | #define PWM12_CH10 ((11 << 8) + 9 ) |
|
274 | #define PWM12_CH10 ((11 << 8) + 9 ) | |
278 | #define PWM12_CH11 ((11 << 8) + 10 ) |
|
275 | #define PWM12_CH11 ((11 << 8) + 10 ) | |
279 | #define PWM12_CH12 ((11 << 8) + 11 ) |
|
276 | #define PWM12_CH12 ((11 << 8) + 11 ) | |
280 | #define PWM12_CH13 ((11 << 8) + 12 ) |
|
277 | #define PWM12_CH13 ((11 << 8) + 12 ) | |
281 | #define PWM12_CH14 ((11 << 8) + 13 ) |
|
278 | #define PWM12_CH14 ((11 << 8) + 13 ) | |
282 | #define PWM12_CH15 ((11 << 8) + 14 ) |
|
279 | #define PWM12_CH15 ((11 << 8) + 14 ) | |
283 | #define PWM12_CH16 ((11 << 8) + 15 ) |
|
280 | #define PWM12_CH16 ((11 << 8) + 15 ) | |
284 | #define PWM13_CH1 ((12 << 8) + 0 ) |
|
281 | #define PWM13_CH1 ((12 << 8) + 0 ) | |
285 | #define PWM13_CH2 ((12 << 8) + 1 ) |
|
282 | #define PWM13_CH2 ((12 << 8) + 1 ) | |
286 | #define PWM13_CH3 ((12 << 8) + 2 ) |
|
283 | #define PWM13_CH3 ((12 << 8) + 2 ) | |
287 | #define PWM13_CH4 ((12 << 8) + 3 ) |
|
284 | #define PWM13_CH4 ((12 << 8) + 3 ) | |
288 | #define PWM13_CH5 ((12 << 8) + 4 ) |
|
285 | #define PWM13_CH5 ((12 << 8) + 4 ) | |
289 | #define PWM13_CH6 ((12 << 8) + 5 ) |
|
286 | #define PWM13_CH6 ((12 << 8) + 5 ) | |
290 | #define PWM13_CH7 ((12 << 8) + 6 ) |
|
287 | #define PWM13_CH7 ((12 << 8) + 6 ) | |
291 | #define PWM13_CH8 ((12 << 8) + 7 ) |
|
288 | #define PWM13_CH8 ((12 << 8) + 7 ) | |
292 | #define PWM13_CH9 ((12 << 8) + 8 ) |
|
289 | #define PWM13_CH9 ((12 << 8) + 8 ) | |
293 | #define PWM13_CH10 ((12 << 8) + 9 ) |
|
290 | #define PWM13_CH10 ((12 << 8) + 9 ) | |
294 | #define PWM13_CH11 ((12 << 8) + 10 ) |
|
291 | #define PWM13_CH11 ((12 << 8) + 10 ) | |
295 | #define PWM13_CH12 ((12 << 8) + 11 ) |
|
292 | #define PWM13_CH12 ((12 << 8) + 11 ) | |
296 | #define PWM13_CH13 ((12 << 8) + 12 ) |
|
293 | #define PWM13_CH13 ((12 << 8) + 12 ) | |
297 | #define PWM13_CH14 ((12 << 8) + 13 ) |
|
294 | #define PWM13_CH14 ((12 << 8) + 13 ) | |
298 | #define PWM13_CH15 ((12 << 8) + 14 ) |
|
295 | #define PWM13_CH15 ((12 << 8) + 14 ) | |
299 | #define PWM13_CH16 ((12 << 8) + 15 ) |
|
296 | #define PWM13_CH16 ((12 << 8) + 15 ) | |
300 | #define PWM14_CH1 ((13 << 8) + 0 ) |
|
297 | #define PWM14_CH1 ((13 << 8) + 0 ) | |
301 | #define PWM14_CH2 ((13 << 8) + 1 ) |
|
298 | #define PWM14_CH2 ((13 << 8) + 1 ) | |
302 | #define PWM14_CH3 ((13 << 8) + 2 ) |
|
299 | #define PWM14_CH3 ((13 << 8) + 2 ) | |
303 | #define PWM14_CH4 ((13 << 8) + 3 ) |
|
300 | #define PWM14_CH4 ((13 << 8) + 3 ) | |
304 | #define PWM14_CH5 ((13 << 8) + 4 ) |
|
301 | #define PWM14_CH5 ((13 << 8) + 4 ) | |
305 | #define PWM14_CH6 ((13 << 8) + 5 ) |
|
302 | #define PWM14_CH6 ((13 << 8) + 5 ) | |
306 | #define PWM14_CH7 ((13 << 8) + 6 ) |
|
303 | #define PWM14_CH7 ((13 << 8) + 6 ) | |
307 | #define PWM14_CH8 ((13 << 8) + 7 ) |
|
304 | #define PWM14_CH8 ((13 << 8) + 7 ) | |
308 | #define PWM14_CH9 ((13 << 8) + 8 ) |
|
305 | #define PWM14_CH9 ((13 << 8) + 8 ) | |
309 | #define PWM14_CH10 ((13 << 8) + 9 ) |
|
306 | #define PWM14_CH10 ((13 << 8) + 9 ) | |
310 | #define PWM14_CH11 ((13 << 8) + 10 ) |
|
307 | #define PWM14_CH11 ((13 << 8) + 10 ) | |
311 | #define PWM14_CH12 ((13 << 8) + 11 ) |
|
308 | #define PWM14_CH12 ((13 << 8) + 11 ) | |
312 | #define PWM14_CH13 ((13 << 8) + 12 ) |
|
309 | #define PWM14_CH13 ((13 << 8) + 12 ) | |
313 | #define PWM14_CH14 ((13 << 8) + 13 ) |
|
310 | #define PWM14_CH14 ((13 << 8) + 13 ) | |
314 | #define PWM14_CH15 ((13 << 8) + 14 ) |
|
311 | #define PWM14_CH15 ((13 << 8) + 14 ) | |
315 | #define PWM14_CH16 ((13 << 8) + 15 ) |
|
312 | #define PWM14_CH16 ((13 << 8) + 15 ) | |
316 | #define PWM15_CH1 ((14 << 8) + 0 ) |
|
313 | #define PWM15_CH1 ((14 << 8) + 0 ) | |
317 | #define PWM15_CH2 ((14 << 8) + 1 ) |
|
314 | #define PWM15_CH2 ((14 << 8) + 1 ) | |
318 | #define PWM15_CH3 ((14 << 8) + 2 ) |
|
315 | #define PWM15_CH3 ((14 << 8) + 2 ) | |
319 | #define PWM15_CH4 ((14 << 8) + 3 ) |
|
316 | #define PWM15_CH4 ((14 << 8) + 3 ) | |
320 | #define PWM15_CH5 ((14 << 8) + 4 ) |
|
317 | #define PWM15_CH5 ((14 << 8) + 4 ) | |
321 | #define PWM15_CH6 ((14 << 8) + 5 ) |
|
318 | #define PWM15_CH6 ((14 << 8) + 5 ) | |
322 | #define PWM15_CH7 ((14 << 8) + 6 ) |
|
319 | #define PWM15_CH7 ((14 << 8) + 6 ) | |
323 | #define PWM15_CH8 ((14 << 8) + 7 ) |
|
320 | #define PWM15_CH8 ((14 << 8) + 7 ) | |
324 | #define PWM15_CH9 ((14 << 8) + 8 ) |
|
321 | #define PWM15_CH9 ((14 << 8) + 8 ) | |
325 | #define PWM15_CH10 ((14 << 8) + 9 ) |
|
322 | #define PWM15_CH10 ((14 << 8) + 9 ) | |
326 | #define PWM15_CH11 ((14 << 8) + 10 ) |
|
323 | #define PWM15_CH11 ((14 << 8) + 10 ) | |
327 | #define PWM15_CH12 ((14 << 8) + 11 ) |
|
324 | #define PWM15_CH12 ((14 << 8) + 11 ) | |
328 | #define PWM15_CH13 ((14 << 8) + 12 ) |
|
325 | #define PWM15_CH13 ((14 << 8) + 12 ) | |
329 | #define PWM15_CH14 ((14 << 8) + 13 ) |
|
326 | #define PWM15_CH14 ((14 << 8) + 13 ) | |
330 | #define PWM15_CH15 ((14 << 8) + 14 ) |
|
327 | #define PWM15_CH15 ((14 << 8) + 14 ) | |
331 | #define PWM15_CH16 ((14 << 8) + 15 ) |
|
328 | #define PWM15_CH16 ((14 << 8) + 15 ) | |
332 | #define PWM16_CH1 ((15 << 8) + 0 ) |
|
329 | #define PWM16_CH1 ((15 << 8) + 0 ) | |
333 | #define PWM16_CH2 ((15 << 8) + 1 ) |
|
330 | #define PWM16_CH2 ((15 << 8) + 1 ) | |
334 | #define PWM16_CH3 ((15 << 8) + 2 ) |
|
331 | #define PWM16_CH3 ((15 << 8) + 2 ) | |
335 | #define PWM16_CH4 ((15 << 8) + 3 ) |
|
332 | #define PWM16_CH4 ((15 << 8) + 3 ) | |
336 | #define PWM16_CH5 ((15 << 8) + 4 ) |
|
333 | #define PWM16_CH5 ((15 << 8) + 4 ) | |
337 | #define PWM16_CH6 ((15 << 8) + 5 ) |
|
334 | #define PWM16_CH6 ((15 << 8) + 5 ) | |
338 | #define PWM16_CH7 ((15 << 8) + 6 ) |
|
335 | #define PWM16_CH7 ((15 << 8) + 6 ) | |
339 | #define PWM16_CH8 ((15 << 8) + 7 ) |
|
336 | #define PWM16_CH8 ((15 << 8) + 7 ) | |
340 | #define PWM16_CH9 ((15 << 8) + 8 ) |
|
337 | #define PWM16_CH9 ((15 << 8) + 8 ) | |
341 | #define PWM16_CH10 ((15 << 8) + 9 ) |
|
338 | #define PWM16_CH10 ((15 << 8) + 9 ) | |
342 | #define PWM16_CH11 ((15 << 8) + 10 ) |
|
339 | #define PWM16_CH11 ((15 << 8) + 10 ) | |
343 | #define PWM16_CH12 ((15 << 8) + 11 ) |
|
340 | #define PWM16_CH12 ((15 << 8) + 11 ) | |
344 | #define PWM16_CH13 ((15 << 8) + 12 ) |
|
341 | #define PWM16_CH13 ((15 << 8) + 12 ) | |
345 | #define PWM16_CH14 ((15 << 8) + 13 ) |
|
342 | #define PWM16_CH14 ((15 << 8) + 13 ) | |
346 | #define PWM16_CH15 ((15 << 8) + 14 ) |
|
343 | #define PWM16_CH15 ((15 << 8) + 14 ) | |
347 | #define PWM16_CH16 ((15 << 8) + 15 ) |
|
344 | #define PWM16_CH16 ((15 << 8) + 15 ) | |
348 | #endif |
|
345 | #endif | |
349 | #endif // PWM_H |
|
346 | #endif // PWM_H |
@@ -1,281 +1,282 | |||||
1 | #include <stdlib.h> |
|
1 | #include <stdlib.h> | |
2 | #include <errno.h> |
|
2 | #include <errno.h> | |
3 | #include <string.h> |
|
3 | #include <string.h> | |
4 | #include <sys/stat.h> |
|
4 | #include <sys/stat.h> | |
5 | #include <sys/types.h> |
|
5 | #include <sys/types.h> | |
6 | #include <sys/times.h> |
|
6 | #include <sys/times.h> | |
7 | #include <streamdevices.h> |
|
7 | #include <streamdevices.h> | |
8 | #include <string.h> |
|
8 | #include <string.h> | |
9 | #include <stdio.h> |
|
9 | #include <stdio.h> | |
10 | #include <gpio.h> |
|
10 | #include <gpio.h> | |
11 | #include <uart.h> |
|
11 | #include <uart.h> | |
12 | #include <stdint.h> |
|
12 | #include <stdint.h> | |
13 | #include <bsp.h> |
|
13 | #include <bsp.h> | |
|
14 | #include <core.h> | |||
14 |
|
15 | |||
15 | #undef errno |
|
16 | #undef errno | |
16 |
|
17 | |||
17 |
|
18 | |||
18 | #ifdef __cplusplus |
|
19 | #ifdef __cplusplus | |
19 | extern "C" { |
|
20 | extern "C" { | |
20 | #endif |
|
21 | #endif | |
21 | extern int errno; |
|
22 | extern int errno; | |
22 | extern int32_t __max_opened_files__; |
|
23 | extern int32_t __max_opened_files__; | |
23 | extern streamdevice* __opnfiles__[]; |
|
24 | extern streamdevice* __opnfiles__[]; | |
24 | extern int32_t* __fs_root__; |
|
25 | extern int32_t* __fs_root__; | |
25 | extern int32_t __fs_root_size__; |
|
26 | extern int32_t __fs_root_size__; | |
26 |
|
27 | |||
27 | char *__env[1] = { 0 }; |
|
28 | char *__env[1] = { 0 }; | |
28 | char **environ = __env; |
|
29 | char **environ = __env; | |
29 |
|
30 | |||
30 | int _exit() |
|
31 | int _exit() | |
31 | { |
|
32 | { | |
32 | while(1) |
|
33 | while(1) | |
33 | { |
|
34 | { | |
34 | delay_100us(10000); |
|
35 | delay_100us(10000); | |
35 | gpioset(LED2); |
|
36 | gpioset(LED2); | |
36 | delay_100us(10000); |
|
37 | delay_100us(10000); | |
37 | gpioclr(LED2); |
|
38 | gpioclr(LED2); | |
38 | } |
|
39 | } | |
39 | } |
|
40 | } | |
40 |
|
41 | |||
41 | int _close(int file) |
|
42 | int _close(int file) | |
42 | { |
|
43 | { | |
43 | if(file<__max_opened_files__ && __opnfiles__[file]!=NULL) |
|
44 | if(file<__max_opened_files__ && __opnfiles__[file]!=NULL) | |
44 | { |
|
45 | { | |
45 | return __opnfiles__[file]->ops->close( __opnfiles__[file]); |
|
46 | return __opnfiles__[file]->ops->close( __opnfiles__[file]); | |
46 | } |
|
47 | } | |
47 | return 0; |
|
48 | return 0; | |
48 | } |
|
49 | } | |
49 |
|
50 | |||
50 |
|
51 | |||
51 | int _write(int file, char *ptr, int len) |
|
52 | int _write(int file, char *ptr, int len) | |
52 | { |
|
53 | { | |
53 | if(file<__max_opened_files__ && __opnfiles__[file]!=NULL) |
|
54 | if(file<__max_opened_files__ && __opnfiles__[file]!=NULL) | |
54 | { |
|
55 | { | |
55 | if(__opnfiles__[file]->ops->write(__opnfiles__[file],ptr,1,len)) return len; |
|
56 | if(__opnfiles__[file]->ops->write(__opnfiles__[file],ptr,1,len)) return len; | |
56 | } |
|
57 | } | |
57 | return len; |
|
58 | return len; | |
58 | } |
|
59 | } | |
59 |
|
60 | |||
60 | int _execve(char *name, char **argv, char **env) { |
|
61 | int _execve(char *name, char **argv, char **env) { | |
61 | errno = ENOMEM; |
|
62 | errno = ENOMEM; | |
62 | return -1; |
|
63 | return -1; | |
63 | } |
|
64 | } | |
64 |
|
65 | |||
65 |
|
66 | |||
66 | int _fork(void) { |
|
67 | int _fork(void) { | |
67 | errno = EAGAIN; |
|
68 | errno = EAGAIN; | |
68 | return -1; |
|
69 | return -1; | |
69 | } |
|
70 | } | |
70 |
|
71 | |||
71 | int _fstat(int file, struct stat *st) { |
|
72 | int _fstat(int file, struct stat *st) { | |
72 | st->st_mode = S_IFCHR; |
|
73 | st->st_mode = S_IFCHR; | |
73 | return 0; |
|
74 | return 0; | |
74 | } |
|
75 | } | |
75 |
|
76 | |||
76 |
|
77 | |||
77 | int _getpid(void) { |
|
78 | int _getpid(void) { | |
78 | return 1; |
|
79 | return 1; | |
79 | } |
|
80 | } | |
80 |
|
81 | |||
81 |
|
82 | |||
82 | int _isatty(int file) { |
|
83 | int _isatty(int file) { | |
83 | return 1; |
|
84 | return 1; | |
84 | } |
|
85 | } | |
85 |
|
86 | |||
86 |
|
87 | |||
87 | int _kill(int pid, int sig) { |
|
88 | int _kill(int pid, int sig) { | |
88 | errno = EINVAL; |
|
89 | errno = EINVAL; | |
89 | return -1; |
|
90 | return -1; | |
90 | } |
|
91 | } | |
91 |
|
92 | |||
92 |
|
93 | |||
93 | int _link(char *old, char *_new) { |
|
94 | int _link(char *old, char *_new) { | |
94 | errno = EMLINK; |
|
95 | errno = EMLINK; | |
95 | return -1; |
|
96 | return -1; | |
96 | } |
|
97 | } | |
97 |
|
98 | |||
98 |
|
99 | |||
99 | int _lseek(int file, int ptr, int dir) { |
|
100 | int _lseek(int file, int ptr, int dir) { | |
100 | return 0; |
|
101 | return 0; | |
101 | } |
|
102 | } | |
102 |
|
103 | |||
103 | #include <gpio.h> |
|
104 | #include <gpio.h> | |
104 |
|
105 | |||
105 | int _open(const char *name, int flags, int mode) |
|
106 | int _open(const char *name, int flags, int mode) | |
106 | { |
|
107 | { | |
107 | if(!strncmp("UART", name, 4) && ((name[4] & 0x30)==0x30)) |
|
108 | if(!strncmp("UART", name, 4) && ((name[4] & 0x30)==0x30)) | |
108 | { |
|
109 | { | |
109 | //uart_t* uart1 = malloc(sizeof(uart_t)); |
|
110 | //uart_t* uart1 = malloc(sizeof(uart_t)); | |
110 | streamdevice* fd1 = malloc(sizeof(streamdevice)); |
|
111 | streamdevice* fd1 = malloc(sizeof(streamdevice)); | |
111 | uart_t uart=uartopen((name[4] & 0xF)-1); |
|
112 | uart_t uart=uartopen((name[4] & 0xF)-1); | |
112 | if(uart!=-1); |
|
113 | if(uart!=-1); | |
113 | { |
|
114 | { | |
114 | uartmkstreamdev(uart,fd1); |
|
115 | uartmkstreamdev(uart,fd1); | |
115 | int i=2; |
|
116 | int i=2; | |
116 | while((i<__max_opened_files__) && (__opnfiles__[i]!=NULL))i++; |
|
117 | while((i<__max_opened_files__) && (__opnfiles__[i]!=NULL))i++; | |
117 | if(i!=__max_opened_files__) |
|
118 | if(i!=__max_opened_files__) | |
118 | { |
|
119 | { | |
119 | __opnfiles__[i] = fd1; |
|
120 | __opnfiles__[i] = fd1; | |
120 | return i; |
|
121 | return i; | |
121 | } |
|
122 | } | |
122 | else printf("Too much files opened\n\r"); |
|
123 | else printf("Too much files opened\n\r"); | |
123 | } |
|
124 | } | |
124 | } |
|
125 | } | |
125 | return -1; |
|
126 | return -1; | |
126 | } |
|
127 | } | |
127 |
|
128 | |||
128 | int _read(int file, char *ptr, int len) { |
|
129 | int _read(int file, char *ptr, int len) { | |
129 | if(file<__max_opened_files__ && __opnfiles__[file]!=NULL) |
|
130 | if(file<__max_opened_files__ && __opnfiles__[file]!=NULL) | |
130 | { |
|
131 | { | |
131 | if(__opnfiles__[file]->ops->read(__opnfiles__[file],ptr,1,len)) return len; |
|
132 | if(__opnfiles__[file]->ops->read(__opnfiles__[file],ptr,1,len)) return len; | |
132 | } |
|
133 | } | |
133 | return 0; |
|
134 | return 0; | |
134 | } |
|
135 | } | |
135 |
|
136 | |||
136 |
|
137 | |||
137 |
|
138 | |||
138 | caddr_t _sbrk(int incr) { |
|
139 | caddr_t _sbrk(int incr) { | |
139 | register char * stack_ptr __asm__ ("sp"); |
|
140 | register char * stack_ptr __asm__ ("sp"); | |
140 | extern char end; /* Defined by the linker */ |
|
141 | extern char end; /* Defined by the linker */ | |
141 | static char *heap_end; |
|
142 | static char *heap_end; | |
142 | char *prev_heap_end; |
|
143 | char *prev_heap_end; | |
143 | if (heap_end == 0) { |
|
144 | if (heap_end == 0) { | |
144 | heap_end = &end; |
|
145 | heap_end = &end; | |
145 | } |
|
146 | } | |
146 | prev_heap_end = heap_end; |
|
147 | prev_heap_end = heap_end; | |
147 | if (heap_end + incr > stack_ptr) { |
|
148 | if (heap_end + incr > stack_ptr) { | |
148 | printf("Heap and stack collision\n"); |
|
149 | printf("Heap and stack collision\n"); | |
149 | //abort (); |
|
150 | //abort (); | |
150 | while(1) |
|
151 | while(1) | |
151 | { |
|
152 | { | |
152 | delay_100us(10000); |
|
153 | delay_100us(10000); | |
153 | gpioset(LED2); |
|
154 | gpioset(LED2); | |
154 | delay_100us(10000); |
|
155 | delay_100us(10000); | |
155 | gpioclr(LED2); |
|
156 | gpioclr(LED2); | |
156 | } |
|
157 | } | |
157 | } |
|
158 | } | |
158 | heap_end += incr; |
|
159 | heap_end += incr; | |
159 | return (caddr_t) prev_heap_end; |
|
160 | return (caddr_t) prev_heap_end; | |
160 | } |
|
161 | } | |
161 |
|
162 | |||
162 |
|
163 | |||
163 |
|
164 | |||
164 | int _stat(char *file, struct stat *st) { |
|
165 | int _stat(char *file, struct stat *st) { | |
165 | st->st_mode = S_IFCHR; |
|
166 | st->st_mode = S_IFCHR; | |
166 | return 0; |
|
167 | return 0; | |
167 | } |
|
168 | } | |
168 |
|
169 | |||
169 |
|
170 | |||
170 | int _times(struct tms *buf) { |
|
171 | int _times(struct tms *buf) { | |
171 | return -1; |
|
172 | return -1; | |
172 | } |
|
173 | } | |
173 |
|
174 | |||
174 |
|
175 | |||
175 | int _unlink(char *name) { |
|
176 | int _unlink(char *name) { | |
176 | errno = ENOENT; |
|
177 | errno = ENOENT; | |
177 | return -1; |
|
178 | return -1; | |
178 | } |
|
179 | } | |
179 |
|
180 | |||
180 | int _wait(int *status) { |
|
181 | int _wait(int *status) { | |
181 | errno = ECHILD; |
|
182 | errno = ECHILD; | |
182 | return -1; |
|
183 | return -1; | |
183 | } |
|
184 | } | |
184 |
|
185 | |||
185 |
|
186 | |||
186 | int _read_r (struct _reent *r, int file, char * ptr, int len) |
|
187 | int _read_r (struct _reent *r, int file, char * ptr, int len) | |
187 | { |
|
188 | { | |
188 | r = r; |
|
189 | r = r; | |
189 | file = file; |
|
190 | file = file; | |
190 | ptr = ptr; |
|
191 | ptr = ptr; | |
191 | len = len; |
|
192 | len = len; | |
192 | _read(file,ptr,len); |
|
193 | _read(file,ptr,len); | |
193 | errno = EINVAL; |
|
194 | errno = EINVAL; | |
194 | return -1; |
|
195 | return -1; | |
195 | } |
|
196 | } | |
196 |
|
197 | |||
197 | /***************************************************************************/ |
|
198 | /***************************************************************************/ | |
198 |
|
199 | |||
199 | int _lseek_r (struct _reent *r, int file, int ptr, int dir) |
|
200 | int _lseek_r (struct _reent *r, int file, int ptr, int dir) | |
200 | { |
|
201 | { | |
201 | r = r; |
|
202 | r = r; | |
202 | file = file; |
|
203 | file = file; | |
203 | ptr = ptr; |
|
204 | ptr = ptr; | |
204 | dir = dir; |
|
205 | dir = dir; | |
205 |
|
206 | |||
206 | return 0; |
|
207 | return 0; | |
207 | } |
|
208 | } | |
208 |
|
209 | |||
209 | /***************************************************************************/ |
|
210 | /***************************************************************************/ | |
210 |
|
211 | |||
211 | int _write_r (struct _reent *r, int file, char * ptr, int len) |
|
212 | int _write_r (struct _reent *r, int file, char * ptr, int len) | |
212 | { |
|
213 | { | |
213 | return _write(file, ptr, len); |
|
214 | return _write(file, ptr, len); | |
214 | } |
|
215 | } | |
215 |
|
216 | |||
216 | /***************************************************************************/ |
|
217 | /***************************************************************************/ | |
217 |
|
218 | |||
218 | int _close_r (struct _reent *r, int file) |
|
219 | int _close_r (struct _reent *r, int file) | |
219 | { |
|
220 | { | |
220 | return 0; |
|
221 | return 0; | |
221 | } |
|
222 | } | |
222 |
|
223 | |||
223 | /***************************************************************************/ |
|
224 | /***************************************************************************/ | |
224 |
|
225 | |||
225 | caddr_t _sbrk_r (struct _reent *r, int incr) |
|
226 | caddr_t _sbrk_r (struct _reent *r, int incr) | |
226 | { |
|
227 | { | |
227 | register char * stack_ptr __asm__ ("sp"); |
|
228 | register char * stack_ptr __asm__ ("sp"); | |
228 | extern char end; /* Defined by the linker */ |
|
229 | extern char end; /* Defined by the linker */ | |
229 | static char *heap_end; |
|
230 | static char *heap_end; | |
230 | char *prev_heap_end; |
|
231 | char *prev_heap_end; | |
231 | if (heap_end == 0) { |
|
232 | if (heap_end == 0) { | |
232 | heap_end = &end; |
|
233 | heap_end = &end; | |
233 | } |
|
234 | } | |
234 | prev_heap_end = heap_end; |
|
235 | prev_heap_end = heap_end; | |
235 | if (heap_end + incr > stack_ptr) { |
|
236 | if (heap_end + incr > stack_ptr) { | |
236 | printf( "Heap and stack collision\n"); |
|
237 | printf( "Heap and stack collision\n"); | |
237 | //abort (); |
|
238 | //abort (); | |
238 | while(1) |
|
239 | while(1) | |
239 | { |
|
240 | { | |
240 | delay_100us(10000); |
|
241 | delay_100us(10000); | |
241 | gpioset(LED2); |
|
242 | gpioset(LED2); | |
242 | delay_100us(10000); |
|
243 | delay_100us(10000); | |
243 | gpioclr(LED2); |
|
244 | gpioclr(LED2); | |
244 | } |
|
245 | } | |
245 | } |
|
246 | } | |
246 | heap_end += incr; |
|
247 | heap_end += incr; | |
247 | return (caddr_t) prev_heap_end; |
|
248 | return (caddr_t) prev_heap_end; | |
248 | } |
|
249 | } | |
249 |
|
250 | |||
250 | /***************************************************************************/ |
|
251 | /***************************************************************************/ | |
251 |
|
252 | |||
252 | int _fstat_r (struct _reent *r, int file, struct stat * st) |
|
253 | int _fstat_r (struct _reent *r, int file, struct stat * st) | |
253 | { |
|
254 | { | |
254 | r = r; |
|
255 | r = r; | |
255 | file = file; |
|
256 | file = file; | |
256 |
|
257 | |||
257 | memset (st, 0, sizeof (* st)); |
|
258 | memset (st, 0, sizeof (* st)); | |
258 | st->st_mode = S_IFCHR; |
|
259 | st->st_mode = S_IFCHR; | |
259 | return 0; |
|
260 | return 0; | |
260 | } |
|
261 | } | |
261 |
|
262 | |||
262 | /***************************************************************************/ |
|
263 | /***************************************************************************/ | |
263 | int _open_r(struct _reent *r,const char *name, int flags, int mode) |
|
264 | int _open_r(struct _reent *r,const char *name, int flags, int mode) | |
264 | { |
|
265 | { | |
265 | return _open(name, flags, mode); |
|
266 | return _open(name, flags, mode); | |
266 | } |
|
267 | } | |
267 |
|
268 | |||
268 | int _isatty_r(struct _reent *r, int fd) |
|
269 | int _isatty_r(struct _reent *r, int fd) | |
269 | { |
|
270 | { | |
270 | r = r; |
|
271 | r = r; | |
271 | fd = fd; |
|
272 | fd = fd; | |
272 |
|
273 | |||
273 | return 1; |
|
274 | return 1; | |
274 | } |
|
275 | } | |
275 |
|
276 | |||
276 |
|
277 | |||
277 | #ifdef __cplusplus |
|
278 | #ifdef __cplusplus | |
278 | } |
|
279 | } | |
279 | #endif |
|
280 | #endif | |
280 |
|
281 | |||
281 |
|
282 |
@@ -1,127 +1,118 | |||||
1 | #include <stdio.h> |
|
1 | #include <stdio.h> | |
2 |
|
|
2 | #include <timer.h> | |
3 | #include <stm32f4xx_rcc.h> |
|
3 | #include <stm32f4xx_rcc.h> | |
4 | #include <stm32f4xx_tim.h> |
|
4 | #include <stm32f4xx_tim.h> | |
5 | #include <stm32f4xx_dac.h> |
|
5 | #include <stm32f4xx_dac.h> | |
6 | #include <stm32f4xx_gpio.h> |
|
6 | #include <stm32f4xx_gpio.h> | |
7 | #include <stm32f4xx_dma.h> |
|
7 | #include <stm32f4xx_dma.h> | |
8 | #include <stm32f4xx.h> |
|
8 | #include <stm32f4xx.h> | |
9 | #include <gpio.h> |
|
9 | #include <gpio.h> | |
10 | #include <stm32f4xx.h> |
|
10 | #include <stm32f4xx.h> | |
|
11 | #include <dac.h> | |||
11 |
|
12 | |||
12 |
|
13 | |||
13 | #define DAC_DHR12R2_ADDRESS 0x40007414 |
|
14 | #define DAC_DHR12R2_ADDRESS 0x40007414 | |
14 | #define DAC_DHR8R1_ADDRESS 0x40007410 |
|
15 | #define DAC_DHR8R1_ADDRESS 0x40007410 | |
15 |
|
16 | |||
16 | #define DAC1_12bit_right_align 0x40007408 |
|
|||
17 | #define DAC1_12bit_left_align 0x4000740C |
|
|||
18 | #define DAC1_8bit_right_align 0x40007410 |
|
|||
19 | #define DAC2_12bit_right_align 0x40007414 |
|
|||
20 | #define DAC2_12bit_left_align 0x40007418 |
|
|||
21 | #define DAC2_8bit_right_align 0x4000741C |
|
|||
22 | #define DAC_Dual_12bit_right_align 0x40007420 |
|
|||
23 | #define DAC_Dual_12bit_left_align 0x40007424 |
|
|||
24 | #define DAC_Dual_8bit_right_align 0x40007428 |
|
|||
25 | #define DAC_Dual_8bit_left_align 0x4000742C |
|
|||
26 |
|
||||
27 |
|
||||
28 |
|
17 | |||
29 | const TIM_TypeDef* _timer_dev_table[14]={TIM1,TIM2,TIM3,TIM4,TIM5,TIM6,TIM7, |
|
18 | const TIM_TypeDef* _timer_dev_table[14]={TIM1,TIM2,TIM3,TIM4,TIM5,TIM6,TIM7, | |
30 | TIM8,TIM9,TIM10,TIM11,TIM12,TIM13,TIM14}; |
|
19 | TIM8,TIM9,TIM10,TIM11,TIM12,TIM13,TIM14}; | |
31 | #define DAC1 0 |
|
|||
32 | #define DAC2 1 |
|
|||
33 |
|
20 | |||
34 | #define timer2 1 |
|
|||
35 | #define timer3 2 |
|
|||
36 | #define timer4 3 |
|
|||
37 | #define timer5 4 |
|
|||
38 | #define timer6 5 |
|
|||
39 | #define timer7 6 |
|
|||
40 | #define timer8 7 |
|
|||
41 |
|
21 | |||
42 | DAC_InitTypeDef DAC_InitStructure; |
|
|||
43 |
|
22 | |||
44 | int dacopen(uint32_t pin) |
|
23 | int dacopen(uint32_t pin) | |
45 | { |
|
24 | { | |
46 | #define GPIOGETPORT(gpio) ((GPIO_TypeDef*)(((((uint32_t)gpio) & (uint32_t)0x0000FF00)*(uint32_t)4) + (uint32_t)GPIOA)) |
|
25 | #define GPIOGETPORT(gpio) ((GPIO_TypeDef*)(((((uint32_t)gpio) & (uint32_t)0x0000FF00)*(uint32_t)4) + (uint32_t)GPIOA)) | |
47 | #define GPIOPORTNUM(gpio) (((uint32_t)(gpio) & (uint32_t)0x0000FF00)>>(uint32_t)8) |
|
26 | #define GPIOPORTNUM(gpio) (((uint32_t)(gpio) & (uint32_t)0x0000FF00)>>(uint32_t)8) | |
48 | RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1 , ENABLE); |
|
27 | RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1 , ENABLE); | |
49 | RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE); |
|
28 | RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE); | |
50 | gpio_t DACOUT; |
|
29 | gpio_t DACOUT; | |
51 | DACOUT = gpioopen(pin); |
|
30 | DACOUT = gpioopen(pin); | |
52 | DACOUT |= gpioan | gpionopulltype; |
|
31 | DACOUT |= gpioan | gpionopulltype; | |
53 | gpiosetconfig(&DACOUT); |
|
32 | gpiosetconfig(&DACOUT); | |
54 | return 0; |
|
33 | return 0; | |
55 | } |
|
34 | } | |
56 |
|
35 | |||
57 |
int dacsetconfig(int timer, int buffer_size, int dac,uint32_t dac_type, uint32_t |
|
36 | int dacsetconfig(int timer, int buffer_size, int dac, uint32_t dac_type, uint32_t samplingFreq, void *data) | |
58 | { |
|
37 | { | |
59 | TIM_TypeDef* tim = _timer_dev_table[timer]; |
|
38 | #include <core.h> | |
|
39 | DAC_InitTypeDef DAC_InitStructure; | |||
|
40 | TIM_TypeDef* tim = (TIM_TypeDef*)_timer_dev_table[timer]; | |||
60 | TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; |
|
41 | TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; | |
|
42 | DMA_InitTypeDef DMA_InitStructure; | |||
61 | if(timer>=timer2 && timer <= timer7)RCC_APB1PeriphClockCmd((1<<(timer-1)), ENABLE); |
|
43 | if(timer>=timer2 && timer <= timer7)RCC_APB1PeriphClockCmd((1<<(timer-1)), ENABLE); | |
62 | if(timer==timer8)RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM8, ENABLE); |
|
44 | if(timer==timer8)RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM8, ENABLE); | |
63 |
uint32_t timfreq = ( |
|
45 | uint32_t timfreq = getCpuFreq()/2; | |
|
46 | uint32_t period = timfreq/samplingFreq - 1; | |||
|
47 | uint16_t PrescalerValue=0; | |||
|
48 | while (period>=0x0FFFF) | |||
|
49 | { | |||
|
50 | PrescalerValue++; | |||
|
51 | timfreq = getCpuFreq()/(2*(PrescalerValue+1)); | |||
|
52 | period = (timfreq/samplingFreq) - 1; | |||
|
53 | } | |||
|
54 | printf("period = %d \n\r prescaler = %d \n\r",period,PrescalerValue); | |||
64 | TIM_TimeBaseStructInit(&TIM_TimeBaseStructure); |
|
55 | TIM_TimeBaseStructInit(&TIM_TimeBaseStructure); | |
65 |
TIM_TimeBaseStructure.TIM_Period = |
|
56 | TIM_TimeBaseStructure.TIM_Period = 10; | |
66 | TIM_TimeBaseStructure.TIM_Prescaler = 0; |
|
57 | TIM_TimeBaseStructure.TIM_Prescaler = 0; | |
67 |
TIM_TimeBaseStructure.TIM_ClockDivision = |
|
58 | TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; | |
68 | TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; |
|
59 | TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; | |
69 | TIM_TimeBaseInit(tim, &TIM_TimeBaseStructure); |
|
60 | TIM_TimeBaseInit(tim, &TIM_TimeBaseStructure); | |
70 | TIM_SelectOutputTrigger(tim, TIM_TRGOSource_Update); |
|
61 | TIM_SelectOutputTrigger(tim, TIM_TRGOSource_Update); | |
|
62 | TIM_ARRPreloadConfig(tim, ENABLE); | |||
71 | TIM_Cmd(tim, ENABLE); |
|
63 | TIM_Cmd(tim, ENABLE); | |
72 |
|
64 | |||
73 | DMA_InitTypeDef DMA_InitStructure; |
|
|||
74 | if (timer == timer2)DAC_InitStructure.DAC_Trigger = DAC_Trigger_T2_TRGO; |
|
65 | if (timer == timer2)DAC_InitStructure.DAC_Trigger = DAC_Trigger_T2_TRGO; | |
75 | if (timer == timer4)DAC_InitStructure.DAC_Trigger = DAC_Trigger_T4_TRGO; |
|
66 | if (timer == timer4)DAC_InitStructure.DAC_Trigger = DAC_Trigger_T4_TRGO; | |
76 | if (timer == timer5)DAC_InitStructure.DAC_Trigger = DAC_Trigger_T5_TRGO; |
|
67 | if (timer == timer5)DAC_InitStructure.DAC_Trigger = DAC_Trigger_T5_TRGO; | |
77 | if (timer == timer6)DAC_InitStructure.DAC_Trigger = DAC_Trigger_T6_TRGO; |
|
68 | if (timer == timer6)DAC_InitStructure.DAC_Trigger = DAC_Trigger_T6_TRGO; | |
78 | if (timer == timer7)DAC_InitStructure.DAC_Trigger = DAC_Trigger_T7_TRGO; |
|
69 | if (timer == timer7)DAC_InitStructure.DAC_Trigger = DAC_Trigger_T7_TRGO; | |
79 | if (timer == timer8)DAC_InitStructure.DAC_Trigger = DAC_Trigger_T8_TRGO; |
|
70 | if (timer == timer8)DAC_InitStructure.DAC_Trigger = DAC_Trigger_T8_TRGO; | |
80 | DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None; |
|
71 | DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None; | |
81 | DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable; |
|
72 | DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable; | |
82 | if (dac == DAC1){ |
|
73 | if (dac == DAC1){ | |
83 | DAC_Init(DAC_Channel_1, &DAC_InitStructure); |
|
74 | DAC_Init(DAC_Channel_1, &DAC_InitStructure); | |
84 | DMA_DeInit(DMA1_Stream5); |
|
75 | DMA_DeInit(DMA1_Stream5); | |
85 | } |
|
76 | } | |
86 |
|
77 | |||
87 | if (dac == DAC2){ |
|
78 | if (dac == DAC2){ | |
88 | DAC_Init(DAC_Channel_2, &DAC_InitStructure); |
|
79 | DAC_Init(DAC_Channel_2, &DAC_InitStructure); | |
89 | DMA_DeInit(DMA1_Stream6); |
|
80 | DMA_DeInit(DMA1_Stream6); | |
90 | } |
|
81 | } | |
91 |
|
82 | |||
92 | DMA_InitStructure.DMA_Channel = DMA_Channel_7; |
|
83 | DMA_InitStructure.DMA_Channel = DMA_Channel_7; | |
93 | DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)dac_type; |
|
84 | DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)dac_type; | |
94 | DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)data; |
|
85 | DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)data; | |
95 | DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral; |
|
86 | DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral; | |
96 | DMA_InitStructure.DMA_BufferSize = buffer_size; |
|
87 | DMA_InitStructure.DMA_BufferSize = buffer_size; | |
97 | DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; |
|
88 | DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; | |
98 | DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral; |
|
89 | DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral; | |
99 | DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; |
|
90 | DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; | |
100 | DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord; |
|
91 | DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord; | |
101 | DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord; |
|
92 | DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord; | |
102 | DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; |
|
93 | DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; | |
103 | DMA_InitStructure.DMA_Priority = DMA_Priority_High; |
|
94 | DMA_InitStructure.DMA_Priority = DMA_Priority_High; | |
104 | DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable; |
|
95 | DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable; | |
105 | DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull; |
|
96 | DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull; | |
106 | DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single; |
|
97 | DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single; | |
107 | DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single; |
|
98 | DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single; | |
108 |
|
99 | |||
109 | if (dac == DAC1){ |
|
100 | if (dac == DAC1){ | |
110 | DMA_Init(DMA1_Stream5, &DMA_InitStructure); |
|
101 | DMA_Init(DMA1_Stream5, &DMA_InitStructure); | |
111 | DMA_Cmd(DMA1_Stream5, ENABLE); |
|
102 | DMA_Cmd(DMA1_Stream5, ENABLE); | |
112 | DAC_DMACmd(DAC_Channel_1, ENABLE); |
|
103 | DAC_DMACmd(DAC_Channel_1, ENABLE); | |
113 | DAC_Cmd(DAC_Channel_1, ENABLE); |
|
104 | DAC_Cmd(DAC_Channel_1, ENABLE); | |
114 |
|
105 | |||
115 | } |
|
106 | } | |
116 | if (dac == DAC2){ |
|
107 | if (dac == DAC2){ | |
117 | DMA_Init(DMA1_Stream6, &DMA_InitStructure); |
|
108 | DMA_Init(DMA1_Stream6, &DMA_InitStructure); | |
118 | DMA_Cmd(DMA1_Stream6, ENABLE); |
|
109 | DMA_Cmd(DMA1_Stream6, ENABLE); | |
119 | DAC_DMACmd(DAC_Channel_2, ENABLE); |
|
110 | DAC_DMACmd(DAC_Channel_2, ENABLE); | |
120 | DAC_Cmd(DAC_Channel_2, ENABLE); |
|
111 | DAC_Cmd(DAC_Channel_2, ENABLE); | |
121 |
|
112 | |||
122 | } |
|
113 | } | |
123 | return 0; |
|
114 | return 0; | |
124 |
|
115 | |||
125 | } |
|
116 | } | |
126 |
|
117 | |||
127 |
|
118 |
@@ -1,222 +1,208 | |||||
1 | #include <pwm.h> |
|
1 | #include <pwm.h> | |
2 | #include <stm32f4xx_tim.h> |
|
2 | #include <stm32f4xx_tim.h> | |
3 | #include <stm32f4xx_gpio.h> |
|
3 | #include <stm32f4xx_gpio.h> | |
4 | #include <stm32f4xx_rcc.h> |
|
4 | #include <stm32f4xx_rcc.h> | |
5 | #include <stm32f4xx_tim.h> |
|
5 | #include <stm32f4xx_tim.h> | |
6 | #include <core.h> |
|
6 | #include <core.h> | |
7 | #include <gpio.h> |
|
7 | #include <gpio.h> | |
|
8 | #include <timer.h> | |||
|
9 | ||||
8 | const TIM_TypeDef* _timer_dev_table[14]={TIM1,TIM2,TIM3,TIM4,TIM5,TIM6,TIM7, |
|
10 | const TIM_TypeDef* _timer_dev_table[14]={TIM1,TIM2,TIM3,TIM4,TIM5,TIM6,TIM7, | |
9 | TIM8,TIM9,TIM10,TIM11,TIM12,TIM13,TIM14}; |
|
11 | TIM8,TIM9,TIM10,TIM11,TIM12,TIM13,TIM14}; | |
10 |
|
12 | |||
11 | #define timer1 0 |
|
|||
12 | #define timer2 1 |
|
|||
13 | #define timer3 2 |
|
|||
14 | #define timer4 3 |
|
|||
15 | #define timer5 4 |
|
|||
16 | #define timer6 5 |
|
|||
17 | #define timer7 6 |
|
|||
18 | #define timer8 7 |
|
|||
19 | #define timer9 8 |
|
|||
20 | #define timer10 9 |
|
|||
21 | #define timer11 10 |
|
|||
22 | #define timer12 11 |
|
|||
23 | #define timer13 12 |
|
|||
24 | #define timer14 13 |
|
|||
25 | #define timer15 14 |
|
|||
26 | #define timer16 15 |
|
|||
27 |
|
13 | |||
28 | #define PWMGETTIMNUMBER(PWM) (((uint32_t)(PWM) & (uint32_t)0x0000FF00)>>(uint32_t)8) |
|
14 | #define PWMGETTIMNUMBER(PWM) (((uint32_t)(PWM) & (uint32_t)0x0000FF00)>>(uint32_t)8) | |
29 |
|
15 | |||
30 | int pwmopen(int PWM,uint32_t pin) |
|
16 | int pwmopen(int PWM,uint32_t pin) | |
31 | { |
|
17 | { | |
32 | #define GPIOGETPORT(gpio) ((GPIO_TypeDef*)(((((uint32_t)gpio) & (uint32_t)0x0000FF00)*(uint32_t)4) + (uint32_t)GPIOA)) |
|
18 | #define GPIOGETPORT(gpio) ((GPIO_TypeDef*)(((((uint32_t)gpio) & (uint32_t)0x0000FF00)*(uint32_t)4) + (uint32_t)GPIOA)) | |
33 | #define GPIOPORTNUM(gpio) (((uint32_t)(gpio) & (uint32_t)0x0000FF00)>>(uint32_t)8) |
|
19 | #define GPIOPORTNUM(gpio) (((uint32_t)(gpio) & (uint32_t)0x0000FF00)>>(uint32_t)8) | |
34 | int timer = PWMGETTIMNUMBER(PWM); |
|
20 | int timer = PWMGETTIMNUMBER(PWM); | |
35 | gpio_t PWMOUT; |
|
21 | gpio_t PWMOUT; | |
36 | PWMOUT = gpioopen(pin); |
|
22 | PWMOUT = gpioopen(pin); | |
37 | PWMOUT |= gpiohighspeed | gpioaf | gpiopushpulltype | gpionopulltype; |
|
23 | PWMOUT |= gpiohighspeed | gpioaf | gpiopushpulltype | gpionopulltype; | |
38 | gpiosetconfig(&PWMOUT); |
|
24 | gpiosetconfig(&PWMOUT); | |
39 | uint8_t GPIO_AF = -1; |
|
25 | uint8_t GPIO_AF = -1; | |
40 | if(timer==timer1 || timer==timer2)GPIO_AF=1; |
|
26 | if(timer==timer1 || timer==timer2)GPIO_AF=1; | |
41 | if(timer==timer3 || timer==timer4 || timer==timer5)GPIO_AF=2; |
|
27 | if(timer==timer3 || timer==timer4 || timer==timer5)GPIO_AF=2; | |
42 | if(timer==timer8 || timer==timer9 || timer==timer10 || timer==timer11)GPIO_AF=3; |
|
28 | if(timer==timer8 || timer==timer9 || timer==timer10 || timer==timer11)GPIO_AF=3; | |
43 | if(timer==timer12 || timer==timer13 || timer==timer14)GPIO_AF=9; |
|
29 | if(timer==timer12 || timer==timer13 || timer==timer14)GPIO_AF=9; | |
44 |
|
30 | |||
45 | if(timer>=timer2 && timer <= timer7)RCC_APB1PeriphClockCmd((1<<(timer-1)), ENABLE); |
|
31 | if(timer>=timer2 && timer <= timer7)RCC_APB1PeriphClockCmd((1<<(timer-1)), ENABLE); | |
46 | if(timer>=timer12 && timer <= timer14)RCC_APB1PeriphClockCmd((1<<(timer-5)), ENABLE); |
|
32 | if(timer>=timer12 && timer <= timer14)RCC_APB1PeriphClockCmd((1<<(timer-5)), ENABLE); | |
47 | if(timer==timer1)RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE); |
|
33 | if(timer==timer1)RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE); | |
48 | if(timer==timer8)RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM8, ENABLE); |
|
34 | if(timer==timer8)RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM8, ENABLE); | |
49 | if(timer==timer9)RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM9, ENABLE); |
|
35 | if(timer==timer9)RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM9, ENABLE); | |
50 | if(timer==timer10)RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM10, ENABLE); |
|
36 | if(timer==timer10)RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM10, ENABLE); | |
51 | if(timer==timer11)RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM11, ENABLE); |
|
37 | if(timer==timer11)RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM11, ENABLE); | |
52 |
|
38 | |||
53 | if(GPIO_AF!=-1)GPIO_PinAFConfig(GPIOGETPORT(PWMOUT), (uint8_t)(PWMOUT & 0xF), GPIO_AF); |
|
39 | if(GPIO_AF!=-1)GPIO_PinAFConfig(GPIOGETPORT(PWMOUT), (uint8_t)(PWMOUT & 0xF), GPIO_AF); | |
54 |
|
40 | |||
55 | return 0; |
|
41 | return 0; | |
56 | } |
|
42 | } | |
57 |
|
43 | |||
58 | int pwmsetconfig(int PWM,uint32_t freq,float dutyCycle) |
|
44 | int pwmsetconfig(int PWM,uint32_t freq,float dutyCycle) | |
59 | { |
|
45 | { | |
60 | TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; |
|
46 | TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; | |
61 | TIM_OCInitTypeDef TIM_OCInitStructure; |
|
47 | TIM_OCInitTypeDef TIM_OCInitStructure; | |
62 | if(PWM==-1) return -1; |
|
48 | if(PWM==-1) return -1; | |
63 | int timer = PWMGETTIMNUMBER(PWM); |
|
49 | int timer = PWMGETTIMNUMBER(PWM); | |
64 | TIM_TypeDef* tim = _timer_dev_table[timer]; |
|
50 | TIM_TypeDef* tim = _timer_dev_table[timer]; | |
65 | uint32_t timfreq = getCpuFreq()/2; |
|
51 | uint32_t timfreq = getCpuFreq()/2; | |
66 | uint32_t period = timfreq/freq - 1; |
|
52 | uint32_t period = timfreq/freq - 1; | |
67 | uint16_t PrescalerValue=0; |
|
53 | uint16_t PrescalerValue=0; | |
68 |
|
54 | |||
69 | while (period>=0x0FFFF) |
|
55 | while (period>=0x0FFFF) | |
70 | { |
|
56 | { | |
71 | PrescalerValue++; |
|
57 | PrescalerValue++; | |
72 | timfreq = getCpuFreq()/(2*(PrescalerValue+1)); |
|
58 | timfreq = getCpuFreq()/(2*(PrescalerValue+1)); | |
73 | period = (timfreq/freq) - 1; |
|
59 | period = (timfreq/freq) - 1; | |
74 | } |
|
60 | } | |
75 |
|
61 | |||
76 | TIM_TimeBaseStructure.TIM_Period = period; |
|
62 | TIM_TimeBaseStructure.TIM_Period = period; | |
77 | TIM_TimeBaseStructure.TIM_Prescaler = PrescalerValue; |
|
63 | TIM_TimeBaseStructure.TIM_Prescaler = PrescalerValue; | |
78 | TIM_TimeBaseStructure.TIM_ClockDivision = 0; |
|
64 | TIM_TimeBaseStructure.TIM_ClockDivision = 0; | |
79 | TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; |
|
65 | TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; | |
80 | TIM_TimeBaseInit(tim, &TIM_TimeBaseStructure); |
|
66 | TIM_TimeBaseInit(tim, &TIM_TimeBaseStructure); | |
81 |
|
67 | |||
82 | TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; |
|
68 | TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; | |
83 | TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; |
|
69 | TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; | |
84 | TIM_OCInitStructure.TIM_Pulse = (uint32_t)((period * dutyCycle)/100); |
|
70 | TIM_OCInitStructure.TIM_Pulse = (uint32_t)((period * dutyCycle)/100); | |
85 | TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; |
|
71 | TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; | |
86 |
|
72 | |||
87 | switch (PWM&0x0FF) { |
|
73 | switch (PWM&0x0FF) { | |
88 | case 0: |
|
74 | case 0: | |
89 | TIM_OC1Init(tim, &TIM_OCInitStructure); |
|
75 | TIM_OC1Init(tim, &TIM_OCInitStructure); | |
90 | TIM_OC1PreloadConfig(tim, TIM_OCPreload_Enable); |
|
76 | TIM_OC1PreloadConfig(tim, TIM_OCPreload_Enable); | |
91 | TIM_ARRPreloadConfig(tim, ENABLE); |
|
77 | TIM_ARRPreloadConfig(tim, ENABLE); | |
92 | TIM_Cmd(tim, ENABLE); |
|
78 | TIM_Cmd(tim, ENABLE); | |
93 | break; |
|
79 | break; | |
94 | case 1: |
|
80 | case 1: | |
95 | TIM_OC2Init(tim, &TIM_OCInitStructure); |
|
81 | TIM_OC2Init(tim, &TIM_OCInitStructure); | |
96 | TIM_OC2PreloadConfig(tim, TIM_OCPreload_Enable); |
|
82 | TIM_OC2PreloadConfig(tim, TIM_OCPreload_Enable); | |
97 | TIM_ARRPreloadConfig(tim, ENABLE); |
|
83 | TIM_ARRPreloadConfig(tim, ENABLE); | |
98 | TIM_Cmd(tim, ENABLE); |
|
84 | TIM_Cmd(tim, ENABLE); | |
99 | break; |
|
85 | break; | |
100 | case 2: |
|
86 | case 2: | |
101 | TIM_OC3Init(tim, &TIM_OCInitStructure); |
|
87 | TIM_OC3Init(tim, &TIM_OCInitStructure); | |
102 | TIM_OC3PreloadConfig(tim, TIM_OCPreload_Enable); |
|
88 | TIM_OC3PreloadConfig(tim, TIM_OCPreload_Enable); | |
103 | TIM_ARRPreloadConfig(tim, ENABLE); |
|
89 | TIM_ARRPreloadConfig(tim, ENABLE); | |
104 | TIM_Cmd(tim, ENABLE); |
|
90 | TIM_Cmd(tim, ENABLE); | |
105 | break; |
|
91 | break; | |
106 | case 3: |
|
92 | case 3: | |
107 | TIM_OC4Init(tim, &TIM_OCInitStructure); |
|
93 | TIM_OC4Init(tim, &TIM_OCInitStructure); | |
108 | TIM_OC4PreloadConfig(tim, TIM_OCPreload_Enable); |
|
94 | TIM_OC4PreloadConfig(tim, TIM_OCPreload_Enable); | |
109 | TIM_ARRPreloadConfig(tim, ENABLE); |
|
95 | TIM_ARRPreloadConfig(tim, ENABLE); | |
110 | TIM_Cmd(tim, ENABLE); |
|
96 | TIM_Cmd(tim, ENABLE); | |
111 | break; |
|
97 | break; | |
112 | default: |
|
98 | default: | |
113 | return -1; |
|
99 | return -1; | |
114 | break; |
|
100 | break; | |
115 | } |
|
101 | } | |
116 | return 0; |
|
102 | return 0; | |
117 | } |
|
103 | } | |
118 |
|
104 | |||
119 |
|
105 | |||
120 |
|
106 | |||
121 |
|
107 | |||
122 |
|
108 | |||
123 | int pwmsetdutycycle(int PWM,float dutyCycle) |
|
109 | int pwmsetdutycycle(int PWM,float dutyCycle) | |
124 | { |
|
110 | { | |
125 | if(PWM==-1) return -1; |
|
111 | if(PWM==-1) return -1; | |
126 | int timer = PWMGETTIMNUMBER(PWM); |
|
112 | int timer = PWMGETTIMNUMBER(PWM); | |
127 | TIM_TypeDef* tim = _timer_dev_table[timer]; |
|
113 | TIM_TypeDef* tim = _timer_dev_table[timer]; | |
128 | switch (PWM&0x0FF) { |
|
114 | switch (PWM&0x0FF) { | |
129 | case 0: |
|
115 | case 0: | |
130 | tim->CCR1 = (uint32_t)((tim->ARR * dutyCycle)/100); |
|
116 | tim->CCR1 = (uint32_t)((tim->ARR * dutyCycle)/100); | |
131 | break; |
|
117 | break; | |
132 | case 1: |
|
118 | case 1: | |
133 | tim->CCR2 = (uint32_t)((tim->ARR * dutyCycle)/100); |
|
119 | tim->CCR2 = (uint32_t)((tim->ARR * dutyCycle)/100); | |
134 | break; |
|
120 | break; | |
135 | case 2: |
|
121 | case 2: | |
136 | tim->CCR3 = (uint32_t)((tim->ARR * dutyCycle)/100); |
|
122 | tim->CCR3 = (uint32_t)((tim->ARR * dutyCycle)/100); | |
137 | break; |
|
123 | break; | |
138 | case 3: |
|
124 | case 3: | |
139 | tim->CCR4 = (uint32_t)((tim->ARR * dutyCycle)/100); |
|
125 | tim->CCR4 = (uint32_t)((tim->ARR * dutyCycle)/100); | |
140 | break; |
|
126 | break; | |
141 | default: |
|
127 | default: | |
142 | return -1; |
|
128 | return -1; | |
143 | break; |
|
129 | break; | |
144 | } |
|
130 | } | |
145 | return 0; |
|
131 | return 0; | |
146 | } |
|
132 | } | |
147 |
|
133 | |||
148 | float pwmgetdutycycle(int PWM) |
|
134 | float pwmgetdutycycle(int PWM) | |
149 | { |
|
135 | { | |
150 | if(PWM==-1) return -1; |
|
136 | if(PWM==-1) return -1; | |
151 | int timer = PWMGETTIMNUMBER(PWM); |
|
137 | int timer = PWMGETTIMNUMBER(PWM); | |
152 | TIM_TypeDef* tim = _timer_dev_table[timer]; |
|
138 | TIM_TypeDef* tim = _timer_dev_table[timer]; | |
153 | switch (PWM&0x0FF) { |
|
139 | switch (PWM&0x0FF) { | |
154 | case 0: |
|
140 | case 0: | |
155 | return (float)((tim->CCR1*100)/tim->ARR); |
|
141 | return (float)((tim->CCR1*100)/tim->ARR); | |
156 | break; |
|
142 | break; | |
157 | case 1: |
|
143 | case 1: | |
158 | return (float)((tim->CCR2*100)/tim->ARR); |
|
144 | return (float)((tim->CCR2*100)/tim->ARR); | |
159 | break; |
|
145 | break; | |
160 | case 2: |
|
146 | case 2: | |
161 | return (float)((tim->CCR3*100)/tim->ARR); |
|
147 | return (float)((tim->CCR3*100)/tim->ARR); | |
162 | break; |
|
148 | break; | |
163 | case 3: |
|
149 | case 3: | |
164 | return (float)((tim->CCR4*100)/tim->ARR); |
|
150 | return (float)((tim->CCR4*100)/tim->ARR); | |
165 | break; |
|
151 | break; | |
166 | default: |
|
152 | default: | |
167 | return -1; |
|
153 | return -1; | |
168 | break; |
|
154 | break; | |
169 | } |
|
155 | } | |
170 | return 0; |
|
156 | return 0; | |
171 | } |
|
157 | } | |
172 |
|
158 | |||
173 |
|
159 | |||
174 | int pwmsetfrequency(int PWM,uint32_t freq) |
|
160 | int pwmsetfrequency(int PWM,uint32_t freq) | |
175 | { |
|
161 | { | |
176 | TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; |
|
162 | TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; | |
177 | if(PWM==-1) return -1; |
|
163 | if(PWM==-1) return -1; | |
178 | int timer = PWMGETTIMNUMBER(PWM); |
|
164 | int timer = PWMGETTIMNUMBER(PWM); | |
179 | TIM_TypeDef* tim = _timer_dev_table[timer]; |
|
165 | TIM_TypeDef* tim = _timer_dev_table[timer]; | |
180 | uint32_t timfreq = getCpuFreq()/2; |
|
166 | uint32_t timfreq = getCpuFreq()/2; | |
181 | uint32_t period = timfreq/freq - 1; |
|
167 | uint32_t period = timfreq/freq - 1; | |
182 | uint16_t PrescalerValue=0; |
|
168 | uint16_t PrescalerValue=0; | |
183 | float dutyCycle = pwmgetdutycycle(PWM); |
|
169 | float dutyCycle = pwmgetdutycycle(PWM); | |
184 | while (period>=0x0FFFF) |
|
170 | while (period>=0x0FFFF) | |
185 | { |
|
171 | { | |
186 | PrescalerValue++; |
|
172 | PrescalerValue++; | |
187 | timfreq = getCpuFreq()/(2*(PrescalerValue+1)); |
|
173 | timfreq = getCpuFreq()/(2*(PrescalerValue+1)); | |
188 | period = (timfreq/freq) - 1; |
|
174 | period = (timfreq/freq) - 1; | |
189 | } |
|
175 | } | |
190 |
|
176 | |||
191 | TIM_TimeBaseStructure.TIM_Period = period; |
|
177 | TIM_TimeBaseStructure.TIM_Period = period; | |
192 | TIM_TimeBaseStructure.TIM_Prescaler = PrescalerValue; |
|
178 | TIM_TimeBaseStructure.TIM_Prescaler = PrescalerValue; | |
193 | TIM_TimeBaseStructure.TIM_ClockDivision = 0; |
|
179 | TIM_TimeBaseStructure.TIM_ClockDivision = 0; | |
194 | TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; |
|
180 | TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; | |
195 | TIM_TimeBaseInit(tim, &TIM_TimeBaseStructure); |
|
181 | TIM_TimeBaseInit(tim, &TIM_TimeBaseStructure); | |
196 |
|
182 | |||
197 | switch (PWM&0x0FF) { |
|
183 | switch (PWM&0x0FF) { | |
198 | case 0: |
|
184 | case 0: | |
199 | tim->CCR1 = (uint32_t)((tim->ARR * dutyCycle)/100); |
|
185 | tim->CCR1 = (uint32_t)((tim->ARR * dutyCycle)/100); | |
200 | TIM_ARRPreloadConfig(tim, ENABLE); |
|
186 | TIM_ARRPreloadConfig(tim, ENABLE); | |
201 | break; |
|
187 | break; | |
202 | case 1: |
|
188 | case 1: | |
203 | tim->CCR2 = (uint32_t)((tim->ARR * dutyCycle)/100); |
|
189 | tim->CCR2 = (uint32_t)((tim->ARR * dutyCycle)/100); | |
204 | TIM_ARRPreloadConfig(tim, ENABLE); |
|
190 | TIM_ARRPreloadConfig(tim, ENABLE); | |
205 | break; |
|
191 | break; | |
206 | case 2: |
|
192 | case 2: | |
207 | tim->CCR3 = (uint32_t)((tim->ARR * dutyCycle)/100); |
|
193 | tim->CCR3 = (uint32_t)((tim->ARR * dutyCycle)/100); | |
208 | TIM_ARRPreloadConfig(tim, ENABLE); |
|
194 | TIM_ARRPreloadConfig(tim, ENABLE); | |
209 | break; |
|
195 | break; | |
210 | case 3: |
|
196 | case 3: | |
211 | tim->CCR4 = (uint32_t)((tim->ARR * dutyCycle)/100); |
|
197 | tim->CCR4 = (uint32_t)((tim->ARR * dutyCycle)/100); | |
212 | TIM_ARRPreloadConfig(tim, ENABLE); |
|
198 | TIM_ARRPreloadConfig(tim, ENABLE); | |
213 | break; |
|
199 | break; | |
214 | default: |
|
200 | default: | |
215 | return -1; |
|
201 | return -1; | |
216 | break; |
|
202 | break; | |
217 | } |
|
203 | } | |
218 | return 0; |
|
204 | return 0; | |
219 | } |
|
205 | } | |
220 |
|
206 | |||
221 |
|
207 | |||
222 |
|
208 |
@@ -1,16 +1,17 | |||||
1 | TEMPLATE = subdirs |
|
1 | TEMPLATE = subdirs | |
2 | CONFIG += ordered |
|
2 | CONFIG += ordered | |
3 |
|
3 | |||
4 | SUBDIRS = CORE/core.pro \ |
|
4 | SUBDIRS = CORE/core.pro \ | |
5 | CPU/cpu.pro \ |
|
5 | CPU/cpu.pro \ | |
6 | GPIO/gpio.pro \ |
|
6 | GPIO/gpio.pro \ | |
|
7 | TIMER/timer.pro \ | |||
7 | UART/uart.pro \ |
|
8 | UART/uart.pro \ | |
8 | SPI/spi.pro \ |
|
9 | SPI/spi.pro \ | |
9 | I2C/i2c.pro \ |
|
10 | I2C/i2c.pro \ | |
10 | PWM/pwm.pro \ |
|
11 | PWM/pwm.pro \ | |
11 | DAC/dac.pro\ |
|
12 | DAC/dac.pro\ | |
12 | SDCARD-SDIO/sdcard-sdio.pro |
|
13 | SDCARD-SDIO/sdcard-sdio.pro | |
13 |
|
14 | |||
14 |
|
15 | |||
15 |
|
16 | |||
16 |
|
17 |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed, binary diff hidden |
|
NO CONTENT: file was removed, binary diff hidden |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed, binary diff hidden |
|
NO CONTENT: file was removed, binary diff hidden |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed, binary diff hidden |
|
NO CONTENT: file was removed, binary diff hidden |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed | ||
This diff has been collapsed as it changes many lines, (509 lines changed) Show them Hide them |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed | ||
This diff has been collapsed as it changes many lines, (566 lines changed) Show them Hide them |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed, binary diff hidden |
|
NO CONTENT: file was removed, binary diff hidden |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed, binary diff hidden |
|
NO CONTENT: file was removed, binary diff hidden |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed, binary diff hidden |
|
NO CONTENT: file was removed, binary diff hidden |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed | ||
This diff has been collapsed as it changes many lines, (808 lines changed) Show them Hide them |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed | ||
This diff has been collapsed as it changes many lines, (509 lines changed) Show them Hide them |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed | ||
This diff has been collapsed as it changes many lines, (1651 lines changed) Show them Hide them |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed | ||
This diff has been collapsed as it changes many lines, (504 lines changed) Show them Hide them |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed | ||
This diff has been collapsed as it changes many lines, (772 lines changed) Show them Hide them |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed | ||
This diff has been collapsed as it changes many lines, (566 lines changed) Show them Hide them |
1 | NO CONTENT: file was removed, binary diff hidden |
|
NO CONTENT: file was removed, binary diff hidden |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
General Comments 0
You need to be logged in to leave comments.
Login now