Commit cb1ba646 authored by Werner Sembach's avatar Werner Sembach
Browse files

Add lib for external button

parent bc4810a2
......@@ -131,6 +131,7 @@ ECOS_EZS_ADDLIB("${OPENCM3_PATH}/lib/libopencm3_stm32f4.a")
SET(SRC_LIST
main.c
src/DCMotor.cpp
src/ExternButton.cpp
src/ServoMotor.cpp
${LIBEZS_SOURCES}
)
......
#pragma once
#include <stdint.h>
#define BUTTON_PUSHED 1
#define BUTTON_RELEASED 0
#ifdef __cplusplus
extern "C" {
#endif
void button_init();
int button_get();
#ifdef __cplusplus
}
#endif
......@@ -11,7 +11,7 @@
extern "C" {
#endif
void servo_init(void);
void servo_init();
void servo_set(uint8_t servo, uint8_t position);
......
......@@ -10,8 +10,9 @@
#include "stm32f411e_discovery_gyroscope.h"
#include "stm32f411e_discovery_accelerometer.h"
#include "ezs_io.h"
#include "ServoMotor.h"
#include "DCMotor.h"
#include "ExternButton.h"
#include "ServoMotor.h"
/* Thread-Stack */
#define STACKSIZE CYGNUM_HAL_STACK_SIZE_MINIMUM+1024
......@@ -107,17 +108,23 @@ void get_degree() {
void test_thread(cyg_addrword_t arg) {
test_init();
int i;
button_init();
int i = 0;
while (!BSP_PB_GetState(BUTTON_KEY)) {
for (i = 0; i < 255; i += 5) {
ezs_printf("Iteration up: %d\n", i);
dc_set(DC_RIGHT, i);
servo_set(SERVO_0, i);
ezs_printf("Button state: %d\n", button_get());
servo_set(SERVO_0, button_get()*255);
cyg_thread_delay(250);
}
for (i = 255; i > 0; i -= 5) {
ezs_printf("Iteration down: %d\n", i);
dc_set(DC_RIGHT, i);
servo_set(SERVO_0, i);
ezs_printf("Button state: %d\n", button_get());
servo_set(SERVO_0, button_get()*255);
cyg_thread_delay(250);
}
}
......
#include "ExternButton.h"
#include <cyg/hal/hal_arch.h>
extern "C" void button_init() {
CYGHWR_HAL_STM32_GPIO_SET(CYGHWR_HAL_STM32_PIN_IN(D, 11, PULLUP));
}
extern "C" int button_get() {
int button;
CYGHWR_HAL_STM32_GPIO_IN(CYGHWR_HAL_STM32_PIN_IN(D, 11, PULLUP), &button);
return !button;
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment