Cosmetics, whitespace, coding style.
This commit is contained in:
parent
2c404f962a
commit
0a0be96d12
@ -2,7 +2,7 @@
|
||||
README
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
This is a PWM based led fading example using libopenstm32.
|
||||
This is a PWM based LED fading example using libopenstm32.
|
||||
|
||||
It's intended for the ST STM32-based MB525 eval board (see
|
||||
http://www.st.com/stonline/products/literature/um/13472.htm for details). It
|
||||
|
@ -17,13 +17,14 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <libopenstm32/common.h>
|
||||
#include <libopenstm32/rcc.h>
|
||||
#include <libopenstm32/gpio.h>
|
||||
#include <libopenstm32/timer.h>
|
||||
|
||||
//#define COMPARE
|
||||
#define COMPARE
|
||||
//#define MOVING_FADE
|
||||
#define KITT
|
||||
// #define KITT
|
||||
|
||||
#ifdef COMPARE
|
||||
#define GAMMA_LINEAR
|
||||
@ -49,7 +50,7 @@
|
||||
* Iout = Iin ** gamma
|
||||
*/
|
||||
#ifdef GAMMA_LINEAR
|
||||
static const uint16_t gamma_table_linear[] = {
|
||||
static const u16 gamma_table_linear[] = {
|
||||
1, 4, 9, 17, 26, 37, 51, 67,
|
||||
84, 104, 126, 149, 175, 203, 233, 265,
|
||||
299, 334, 372, 412, 454, 499, 545, 593,
|
||||
@ -81,13 +82,13 @@ static const uint16_t gamma_table_linear[] = {
|
||||
50705, 51154, 51604, 52057, 52512, 52969, 53428, 53888,
|
||||
54351, 54816, 55282, 55751, 56222, 56694, 57169, 57645,
|
||||
58123, 58604, 59086, 59570, 60057, 60545, 61035, 61527,
|
||||
62021, 62517, 63016, 63516, 64018, 64521, 65027, 65535
|
||||
62021, 62517, 63016, 63516, 64018, 64521, 65027, 65535,
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef GAMMA_1_3
|
||||
static const uint16_t gamma_table_1_3[] = {
|
||||
// Gamma 1.3
|
||||
static const u16 gamma_table_1_3[] = {
|
||||
/* Gamma 1.3 */
|
||||
0, 49, 120, 203, 296, 395, 501, 612,
|
||||
728, 848, 973, 1101, 1233, 1368, 1506, 1648,
|
||||
1792, 1939, 2088, 2241, 2395, 2552, 2711, 2872,
|
||||
@ -119,13 +120,13 @@ static const uint16_t gamma_table_1_3[] = {
|
||||
55373, 55694, 56016, 56339, 56662, 56985, 57309, 57633,
|
||||
57957, 58282, 58608, 58933, 59260, 59586, 59913, 60241,
|
||||
60569, 60897, 61226, 61555, 61884, 62214, 62545, 62875,
|
||||
63206, 63538, 63870, 64202, 64535, 64868, 65201, 65535
|
||||
63206, 63538, 63870, 64202, 64535, 64868, 65201, 65535,
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef GAMMA_2_5
|
||||
static const uint16_t gamma_table_2_5[] = {
|
||||
// gamma = 2.5
|
||||
static const u16 gamma_table_2_5[] = {
|
||||
/* gamma = 2.5 */
|
||||
0, 0, 0, 1, 2, 4, 6, 8,
|
||||
11, 15, 20, 25, 31, 38, 46, 55,
|
||||
65, 75, 87, 99, 113, 128, 143, 160,
|
||||
@ -157,13 +158,13 @@ static const uint16_t gamma_table_2_5[] = {
|
||||
47396, 47927, 48461, 48999, 49540, 50085, 50634, 51186,
|
||||
51742, 52301, 52864, 53431, 54001, 54575, 55153, 55734,
|
||||
56318, 56907, 57499, 58095, 58695, 59298, 59905, 60515,
|
||||
61130, 61748, 62370, 62995, 63624, 64258, 64894, 65535
|
||||
61130, 61748, 62370, 62995, 63624, 64258, 64894, 65535,
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef GAMMA_3_0
|
||||
static const uint16_t gamma_table_3_0[] = {
|
||||
// gamma = 3.0
|
||||
static const u16 gamma_table_3_0[] = {
|
||||
/* gamma = 3.0 */
|
||||
0, 0, 0, 0, 0, 0, 1, 1,
|
||||
2, 3, 4, 5, 7, 9, 11, 13,
|
||||
16, 19, 23, 27, 32, 37, 42, 48,
|
||||
@ -195,7 +196,7 @@ static const uint16_t gamma_table_3_0[] = {
|
||||
44422, 45019, 45622, 46231, 46844, 47463, 48088, 48718,
|
||||
49353, 49994, 50641, 51293, 51950, 52614, 53282, 53957,
|
||||
54637, 55323, 56014, 56712, 57415, 58123, 58838, 59558,
|
||||
60285, 61017, 61755, 62499, 63249, 64005, 64767, 65535
|
||||
60285, 61017, 61755, 62499, 63249, 64005, 64767, 65535,
|
||||
};
|
||||
#endif
|
||||
|
||||
@ -225,20 +226,17 @@ void clock_setup(void)
|
||||
|
||||
/* Enable GPIOC, Alternate Function clocks. */
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, IOPCEN | AFIOEN);
|
||||
|
||||
}
|
||||
|
||||
void gpio_setup(void)
|
||||
{
|
||||
|
||||
/* Set GPIO6 (in GPIO port C) to
|
||||
/*
|
||||
* Set GPIO6 (in GPIO port C) to
|
||||
* 'output alternate function push-pull'.
|
||||
*/
|
||||
gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ,
|
||||
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO6 |
|
||||
GPIO7 |
|
||||
GPIO8 |
|
||||
GPIO9);
|
||||
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL,
|
||||
GPIO6 | GPIO7 | GPIO8 | GPIO9);
|
||||
|
||||
/* Remap TIM3:
|
||||
* CH1 -> PC6
|
||||
@ -308,7 +306,6 @@ void tim_setup(void)
|
||||
|
||||
/* Counter enable */
|
||||
TIM3_CR1 |= TIM_CR1_CEN;
|
||||
|
||||
}
|
||||
|
||||
int main(void)
|
||||
@ -328,25 +325,32 @@ int main(void)
|
||||
d2 = 1;
|
||||
j3 = 0;
|
||||
d3 = 1;
|
||||
while (1)
|
||||
{
|
||||
while (1) {
|
||||
TIM3_CCR1 = gamma_table_linear[j0];
|
||||
j0 += d0;
|
||||
if(j0==255) d0=-1;
|
||||
if(j0==0) d0=1;
|
||||
if (j0 == 255)
|
||||
d0 =- 1;
|
||||
if (j0 == 0)
|
||||
d0 = 1;
|
||||
TIM3_CCR2 = gamma_table_1_3[j1];
|
||||
j1 += d1;
|
||||
if(j1==255) d1=-1;
|
||||
if(j1==0) d1=1;
|
||||
if (j1 == 255)
|
||||
d1 =- 1;
|
||||
if (j1 == 0)
|
||||
d1 = 1;
|
||||
TIM3_CCR3 = gamma_table_2_5[j2];
|
||||
j2 += d2;
|
||||
if(j2==255) d2=-1;
|
||||
if(j2==0) d2=1;
|
||||
if (j2 == 255)
|
||||
d2 =- 1;
|
||||
if (j2 == 0)
|
||||
d2 = 1;
|
||||
TIM3_CCR4= gamma_table_3_0[j3];
|
||||
j3 += d3;
|
||||
if(j3==255) d3=-1;
|
||||
if(j3==0) d3=1;
|
||||
for(i=0; i< 50000; i++){}
|
||||
if (j3 == 255)
|
||||
d3 =- 1;
|
||||
if (j3 == 0)
|
||||
d3 = 1;
|
||||
for (i = 0; i < 50000; i++);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -359,25 +363,32 @@ int main(void)
|
||||
d2 = -1;
|
||||
j3 = 128;
|
||||
d3 = -1;
|
||||
while (1)
|
||||
{
|
||||
while (1) {
|
||||
TIM3_CCR1 = GAMMA_TABLE[j0];
|
||||
j0 += d0;
|
||||
if(j0==255) d0=-1;
|
||||
if(j0==0) d0=1;
|
||||
if (j0 == 255)
|
||||
d0 =- 1;
|
||||
if (j0 == 0)
|
||||
d0 = 1;
|
||||
TIM3_CCR2 = GAMMA_TABLE[j1];
|
||||
j1 += d1;
|
||||
if(j1==255) d1=-1;
|
||||
if(j1==0) d1=1;
|
||||
if (j1 == 255)
|
||||
d1 =- 1;
|
||||
if (j1 == 0)
|
||||
d1 = 1;
|
||||
TIM3_CCR3 = GAMMA_TABLE[j2];
|
||||
j2 += d2;
|
||||
if(j2==255) d2=-1;
|
||||
if(j2==0) d2=1;
|
||||
if (j2 == 255)
|
||||
d2 =- 1;
|
||||
if (j2 == 0)
|
||||
d2 = 1;
|
||||
TIM3_CCR4 = GAMMA_TABLE[j3];
|
||||
j3 += d3;
|
||||
if(j3==255) d3=-1;
|
||||
if(j3==0) d3=1;
|
||||
for(i=0; i< 10000; i++){}
|
||||
if (j3 == 255)
|
||||
d3 =- 1;
|
||||
if (j3 == 0)
|
||||
d3 = 1;
|
||||
for (i = 0; i < 10000; i++);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -393,25 +404,32 @@ int main(void)
|
||||
j = 0;
|
||||
k = 0;
|
||||
kd = 1;
|
||||
while (1)
|
||||
{
|
||||
while (1) {
|
||||
TIM3_CCR1 = GAMMA_TABLE[j0];
|
||||
j0 += d0;
|
||||
if(j0==255) d0=-1;
|
||||
if(j0==19) j0=20;
|
||||
if (j0 == 255)
|
||||
d0 =- 1;
|
||||
if (j0 == 19)
|
||||
j0 = 20;
|
||||
TIM3_CCR2 = GAMMA_TABLE[j1];
|
||||
j1 += d1;
|
||||
if(j1==255) d1=-1;
|
||||
if(j1==19) j1=20;
|
||||
if (j1 == 255)
|
||||
d1 =- 1;
|
||||
if (j1 == 19)
|
||||
j1 = 20;
|
||||
TIM3_CCR3 = GAMMA_TABLE[j2];
|
||||
j2 += d2;
|
||||
if(j2==255) d2=-1;
|
||||
if(j2==19) j2=20;
|
||||
if (j2 == 255)
|
||||
d2 =- 1;
|
||||
if (j2 == 19)
|
||||
j2 = 20;
|
||||
TIM3_CCR4 = GAMMA_TABLE[j3];
|
||||
j3 += d3;
|
||||
if(j3==255) d3=-1;
|
||||
if(j3==19) j3=20;
|
||||
for(i=0; i< 5000; i++){}
|
||||
if (j3 == 255)
|
||||
d3 =- 1;
|
||||
if (j3 == 19)
|
||||
j3 = 20;
|
||||
for (i = 0; i < 5000; i++);
|
||||
j++;
|
||||
if (j == 100) {
|
||||
j = 0;
|
||||
@ -429,8 +447,10 @@ int main(void)
|
||||
j3 = 255;
|
||||
break;
|
||||
}
|
||||
if(k==3) kd=-1;
|
||||
if(k==0) kd=1;
|
||||
if (k == 3)
|
||||
kd =- 1;
|
||||
if (k == 0)
|
||||
kd = 1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user