add led_on, led_off, led_toggle, led_blink_one to lib
This commit is contained in:
@@ -16,5 +16,8 @@
|
|||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
|
|
||||||
static const char* generated_source = ""
|
static const char* generated_source = ""
|
||||||
|
"LEDToggle (12);\n"
|
||||||
|
"LEDToggle (13);\n"
|
||||||
"LEDToggle (14);\n"
|
"LEDToggle (14);\n"
|
||||||
|
"LEDToggle (15);\n"
|
||||||
;
|
;
|
||||||
|
|||||||
@@ -24,24 +24,51 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "actuators.h"
|
#include "actuators.h"
|
||||||
|
#include "common-io.h"
|
||||||
#include "jerry-libc.h"
|
#include "jerry-libc.h"
|
||||||
|
|
||||||
void
|
void
|
||||||
led_toggle (uint32_t led_id)
|
led_toggle (uint32_t led_id)
|
||||||
{
|
{
|
||||||
|
#ifdef __HOST
|
||||||
__printf ("led_toggle: %d\n", led_id);
|
__printf ("led_toggle: %d\n", led_id);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __TARGET_MCU
|
||||||
|
init_led (led_id);
|
||||||
|
|
||||||
|
GPIOD->ODR ^= (uint16_t) (1 << led_id);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
led_on (uint32_t led_id)
|
led_on (uint32_t led_id)
|
||||||
{
|
{
|
||||||
|
#ifdef __HOST
|
||||||
__printf ("led_on: %d\n", led_id);
|
__printf ("led_on: %d\n", led_id);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __TARGET_MCU
|
||||||
|
init_led (led_id);
|
||||||
|
|
||||||
|
GPIOD->BSRRH = (uint16_t) (1 << led_id);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
led_off (uint32_t led_id)
|
led_off (uint32_t led_id)
|
||||||
{
|
{
|
||||||
|
#ifdef __HOST
|
||||||
__printf ("led_off: %d\n", led_id);
|
__printf ("led_off: %d\n", led_id);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __TARGET_MCU
|
||||||
|
init_led (led_id);
|
||||||
|
|
||||||
|
GPIOD->BSRRH = (uint16_t) (1 << led_id);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -52,16 +79,23 @@ led_blink_once (uint32_t led_id)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __TARGET_MCU
|
#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
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __TARGET_MCU
|
#ifdef __TARGET_MCU
|
||||||
|
|
||||||
void
|
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 mode = (uint32_t) GPIO_Mode_OUT << (pin * 2);
|
||||||
uint32_t speed = (uint32_t) GPIO_Speed_100MHz << (pin * 2);
|
uint32_t speed = (uint32_t) GPIO_Speed_100MHz << (pin * 2);
|
||||||
uint32_t type = (uint32_t) GPIO_OType_PP << pin;
|
uint32_t type = (uint32_t) GPIO_OType_PP << pin;
|
||||||
@@ -79,30 +113,5 @@ blink_once (uint32_t led)
|
|||||||
gpio->OSPEEDR |= speed;
|
gpio->OSPEEDR |= speed;
|
||||||
gpio->OTYPER |= type;
|
gpio->OTYPER |= type;
|
||||||
gpio->PUPDR |= pullup;
|
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
|
#endif
|
||||||
@@ -24,7 +24,7 @@ void led_off(uint32_t);
|
|||||||
void led_blink_once(uint32_t);
|
void led_blink_once(uint32_t);
|
||||||
|
|
||||||
#ifdef __TARGET_MCU
|
#ifdef __TARGET_MCU
|
||||||
void blink_once (uint32_t);
|
void init_led (uint32_t);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* ACTUATORS_H */
|
#endif /* ACTUATORS_H */
|
||||||
|
|||||||
@@ -157,9 +157,5 @@ main(void)
|
|||||||
|
|
||||||
jerry_run( source_p,
|
jerry_run( source_p,
|
||||||
source_size);
|
source_size);
|
||||||
|
|
||||||
fake_exit();
|
|
||||||
|
|
||||||
JERRY_UNREACHABLE();
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user