From 44bf853e6e71071abfc7d115875a51a046f6d508 Mon Sep 17 00:00:00 2001 From: Uwe Hermann Date: Thu, 3 Nov 2011 00:57:46 +0100 Subject: stm32-h103 examples: Cosmetic and coding style fixes. --- .../stm32/f1/stm32-h103/led_stripe/led_stripe.c | 68 +++++++++++----------- 1 file changed, 35 insertions(+), 33 deletions(-) (limited to 'examples/stm32/f1/stm32-h103/led_stripe/led_stripe.c') diff --git a/examples/stm32/f1/stm32-h103/led_stripe/led_stripe.c b/examples/stm32/f1/stm32-h103/led_stripe/led_stripe.c index 1576866..ea1ad48 100644 --- a/examples/stm32/f1/stm32-h103/led_stripe/led_stripe.c +++ b/examples/stm32/f1/stm32-h103/led_stripe/led_stripe.c @@ -18,14 +18,13 @@ */ /* - * This example is implementing the protocol of ZJ168 addressable led + * This example is implementing the protocol of ZJ168 addressable LED * strips. These strips use the LPD6803 controller. You may be able to * find the datasheet here: * http://www.adafruit.com/datasheets/LPD6803.pdf */ #include - #include #include @@ -68,10 +67,9 @@ void clock_setup(void) { rcc_clock_setup_in_hse_8mhz_out_72mhz(); - /* Enable GPIOC clock. */ + /* Enable GPIOB and GPIOC clock. */ rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPCEN); rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPBEN); - } void gpio_setup(void) @@ -79,28 +77,33 @@ void gpio_setup(void) /* Set GPIO12 (in GPIO port C) to 'output push-pull'. */ gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO12); + + /* Set GPIO13 (in GPIO port B) to 'output push-pull'. */ gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO13); + + /* Set GPIO15 (in GPIO port B) to 'output push-pull'. */ gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO15); } -void send_colors(struct color *colors, int count) { +void send_colors(struct color *colors, int count) +{ int i, k; - /* initialize spi pins */ + /* Initialize SPI pins. */ SCLK(0); MOSI(0); - /* start frame */ - for (i=0; i<32; i++) { + /* Start frame */ + for (i = 0; i < 32; i++) { SCLK(1); SMALL_DELAY(); SCLK(0); SMALL_DELAY(); } - /* color cell output */ + /* Color cell output */ for (k = 0; k < count; k++) { /* Start bit */ MOSI(1); @@ -110,7 +113,7 @@ void send_colors(struct color *colors, int count) { SMALL_DELAY(); /* Blue */ - for (i=0; i<5; i++) { + for (i = 0; i < 5; i++) { MOSI(((colors[k].b & ((1 << 4) >> i)) != 0)); SCLK(1); SMALL_DELAY(); @@ -118,7 +121,7 @@ void send_colors(struct color *colors, int count) { SMALL_DELAY(); } /* Red */ - for (i=0; i<5; i++) { + for (i = 0; i < 5; i++) { MOSI(((colors[k].r & ((1 << 4) >> i)) != 0)); SCLK(1); SMALL_DELAY(); @@ -126,7 +129,7 @@ void send_colors(struct color *colors, int count) { SMALL_DELAY(); } /* Green */ - for (i=0; i<5; i++) { + for (i = 0; i < 5; i++) { MOSI(((colors[k].g & ((1 << 4) >> i)) != 0)); SCLK(1); SMALL_DELAY(); @@ -137,7 +140,7 @@ void send_colors(struct color *colors, int count) { /* End frame */ MOSI(0); - for (k=0; k < count; k++) { + for (k = 0; k < count; k++) { SCLK(1); SMALL_DELAY(); SCLK(0); @@ -145,18 +148,19 @@ void send_colors(struct color *colors, int count) { } } -void reset_colors(struct color *colors, int count) { +void reset_colors(struct color *colors, int count) +{ int i; - for (i=0; i