add led_on, led_off, led_toggle, led_blink_one to lib

This commit is contained in:
e.gavrin 2014-07-25 16:29:12 +04:00
parent 8745c47192
commit 5da1df37de
4 changed files with 42 additions and 34 deletions

View File

@ -16,5 +16,8 @@
#include "globals.h"
static const char* generated_source = ""
"LEDToggle (12);\n"
"LEDToggle (13);\n"
"LEDToggle (14);\n"
"LEDToggle (15);\n"
;

View File

@ -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

View File

@ -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 */

View File

@ -157,9 +157,5 @@ main(void)
jerry_run( source_p,
source_size);
fake_exit();
JERRY_UNREACHABLE();
}
#endif