From 5da1df37de950fd41377a558c2dc78d484b22da3 Mon Sep 17 00:00:00 2001 From: "e.gavrin" Date: Fri, 25 Jul 2014 16:29:12 +0400 Subject: [PATCH] add led_on, led_off, led_toggle, led_blink_one to lib --- src/generated.h | 3 ++ src/libperipherals/actuators.c | 67 +++++++++++++++++++--------------- src/libperipherals/actuators.h | 2 +- src/main.c | 4 -- 4 files changed, 42 insertions(+), 34 deletions(-) diff --git a/src/generated.h b/src/generated.h index 68e831091..24d92e696 100644 --- a/src/generated.h +++ b/src/generated.h @@ -16,5 +16,8 @@ #include "globals.h" static const char* generated_source = "" +"LEDToggle (12);\n" +"LEDToggle (13);\n" "LEDToggle (14);\n" +"LEDToggle (15);\n" ; diff --git a/src/libperipherals/actuators.c b/src/libperipherals/actuators.c index de0a29593..fcbb5af97 100644 --- a/src/libperipherals/actuators.c +++ b/src/libperipherals/actuators.c @@ -24,24 +24,51 @@ #endif #include "actuators.h" +#include "common-io.h" #include "jerry-libc.h" void led_toggle (uint32_t led_id) { +#ifdef __HOST __printf ("led_toggle: %d\n", led_id); +#endif + + +#ifdef __TARGET_MCU + init_led (led_id); + + GPIOD->ODR ^= (uint16_t) (1 << led_id); +#endif } void led_on (uint32_t led_id) { +#ifdef __HOST __printf ("led_on: %d\n", led_id); +#endif + + +#ifdef __TARGET_MCU + init_led (led_id); + + GPIOD->BSRRH = (uint16_t) (1 << led_id); +#endif } void led_off (uint32_t led_id) { +#ifdef __HOST __printf ("led_off: %d\n", led_id); +#endif + +#ifdef __TARGET_MCU + init_led (led_id); + + GPIOD->BSRRH = (uint16_t) (1 << led_id); +#endif } void @@ -52,16 +79,23 @@ led_blink_once (uint32_t led_id) #endif #ifdef __TARGET_MCU - blink_once (led_id); + init_led (led_id); + + uint32_t dot = 600000 * 3; + + GPIOD->BSRRL = (uint16_t) (1 << led_id); + wait_ms (dot); + + GPIOD->BSRRH = (uint16_t) (1 << led_id); + wait_ms (dot); #endif } #ifdef __TARGET_MCU - void -blink_once (uint32_t led) +init_led (uint32_t led_id) { - uint32_t pin = led; + uint32_t pin = led_id; uint32_t mode = (uint32_t) GPIO_Mode_OUT << (pin * 2); uint32_t speed = (uint32_t) GPIO_Speed_100MHz << (pin * 2); uint32_t type = (uint32_t) GPIO_OType_PP << pin; @@ -79,30 +113,5 @@ blink_once (uint32_t led) gpio->OSPEEDR |= speed; gpio->OTYPER |= type; gpio->PUPDR |= pullup; - // - // Toggle the selected LED indefinitely. - // - volatile int index; - - int dot = 600000; - int dash = dot * 3; - - while (1) - { - gpio->BSRRL = (uint16_t) (1 << pin); - for (index = 0; index < dot; index++); - gpio->BSRRH = (uint16_t) (1 << pin); - for (index = 0; index < dash; index++); - gpio->BSRRL = (uint16_t) (1 << pin); - for (index = 0; index < dot; index++); - gpio->BSRRH = (uint16_t) (1 << pin); - for (index = 0; index < dash; index++); - gpio->BSRRL = (uint16_t) (1 << pin); - for (index = 0; index < dot; index++); - gpio->BSRRH = (uint16_t) (1 << pin); - for (index = 0; index < dash; index++); - - for (index = 0; index < dash * 7; index++); - } } #endif \ No newline at end of file diff --git a/src/libperipherals/actuators.h b/src/libperipherals/actuators.h index e5532ce6d..fb911f338 100644 --- a/src/libperipherals/actuators.h +++ b/src/libperipherals/actuators.h @@ -24,7 +24,7 @@ void led_off(uint32_t); void led_blink_once(uint32_t); #ifdef __TARGET_MCU -void blink_once (uint32_t); +void init_led (uint32_t); #endif #endif /* ACTUATORS_H */ diff --git a/src/main.c b/src/main.c index 21ce0a07e..969e74763 100644 --- a/src/main.c +++ b/src/main.c @@ -157,9 +157,5 @@ main(void) jerry_run( source_p, source_size); - - fake_exit(); - - JERRY_UNREACHABLE(); } #endif