Commit 0adad37b authored by Margit Haspel's avatar Margit Haspel
Browse files

choose lever row pins

parent 056604a9
......@@ -4,6 +4,7 @@
#define LEVER_UP 1
#define LEVER_NEUTRAL 0
#define LEVER_DOWN -1
#ifdef __cplusplus
extern "C" {
......
......@@ -150,19 +150,19 @@ void main_thread(cyg_addrword_t arg) {
//check if solved
if(levers_solved || button_pressed) {
ezs_printf("CONGRATULATIONS! YOU FINALLY MADE IT!\n");
servo_set(SERVO_0, 255);
//servo_set(SERVO_0, 255);
dc_set(0,0);
break;
}
button_pressed = button_get();
print_levers();
//print_levers();
get_all_levers(levers);
ezs_printf("Leverz: 0: %d, 1: %d, 2: %d, 3: %d\n", levers[0], levers[1], levers[2], levers[3]);
//ezs_printf("Leverz: 0: %d, 1: %d, 2: %d, 3: %d\n", levers[0], levers[1], levers[2], levers[3]);
//if (levers[1] == levers[2]) levers_solved = true;
}
......
......@@ -3,11 +3,11 @@
#include <cyg/hal/hal_arch.h>
extern "C" void button_init() {
CYGHWR_HAL_STM32_GPIO_SET(CYGHWR_HAL_STM32_PIN_IN(D, 11, PULLUP));
CYGHWR_HAL_STM32_GPIO_SET(CYGHWR_HAL_STM32_PIN_IN(D, 15, PULLUP));
}
extern "C" int button_get() {
int button;
CYGHWR_HAL_STM32_GPIO_IN(CYGHWR_HAL_STM32_PIN_IN(D, 11, PULLUP), &button);
CYGHWR_HAL_STM32_GPIO_IN(CYGHWR_HAL_STM32_PIN_IN(D, 15, PULLUP), &button);
return !button;
}
#include "LeverKey.h"
#include <stdio.h>
#include <cyg/hal/hal_arch.h>
#define do3 CYGHWR_HAL_STM32_PIN_IN(D, 12, PULLUP)
#define up3 CYGHWR_HAL_STM32_PIN_IN(D, 11, PULLUP)
#define do2 CYGHWR_HAL_STM32_PIN_IN(D, 10, PULLUP)
#define up2 CYGHWR_HAL_STM32_PIN_IN(D, 9, PULLUP)
#define do1 CYGHWR_HAL_STM32_PIN_IN(D, 8, PULLUP)
#define up1 CYGHWR_HAL_STM32_PIN_IN(B, 15, PULLUP)
#define do0 CYGHWR_HAL_STM32_PIN_IN(B, 14, PULLUP)
#define up0 CYGHWR_HAL_STM32_PIN_IN(B, 13, PULLUP)
extern "C" void lever_init() {
//3
CYGHWR_HAL_STM32_GPIO_SET(CYGHWR_HAL_STM32_PIN_IN(E, 7, PULLUP)); // lever down
CYGHWR_HAL_STM32_GPIO_SET(CYGHWR_HAL_STM32_PIN_IN(E, 8, PULLUP)); // lever up
CYGHWR_HAL_STM32_GPIO_SET(do3); // lever down
CYGHWR_HAL_STM32_GPIO_SET(up3); // lever up
//2
CYGHWR_HAL_STM32_GPIO_SET(CYGHWR_HAL_STM32_PIN_IN(E, 9, PULLUP));
CYGHWR_HAL_STM32_GPIO_SET(CYGHWR_HAL_STM32_PIN_IN(E, 10, PULLUP));
CYGHWR_HAL_STM32_GPIO_SET(do2);
CYGHWR_HAL_STM32_GPIO_SET(up2);
//1
CYGHWR_HAL_STM32_GPIO_SET(CYGHWR_HAL_STM32_PIN_IN(E, 11, PULLUP));
CYGHWR_HAL_STM32_GPIO_SET(CYGHWR_HAL_STM32_PIN_IN(E, 12, PULLUP));
CYGHWR_HAL_STM32_GPIO_SET(do1);
CYGHWR_HAL_STM32_GPIO_SET(up1);
//0
CYGHWR_HAL_STM32_GPIO_SET(CYGHWR_HAL_STM32_PIN_IN(E, 13, PULLUP));
CYGHWR_HAL_STM32_GPIO_SET(CYGHWR_HAL_STM32_PIN_IN(E, 14, PULLUP));
CYGHWR_HAL_STM32_GPIO_SET(do0);
CYGHWR_HAL_STM32_GPIO_SET(up0);
}
extern "C" int lever_get(int id) {
int lever;
switch (id){
/*switch (id){
case 3:
CYGHWR_HAL_STM32_GPIO_IN(CYGHWR_HAL_STM32_PIN_IN(E, 7, PULLUP), &lever);
if (!lever) return -2;
printf("3: %d", lever);
//if (!lever) return -1;
CYGHWR_HAL_STM32_GPIO_IN(CYGHWR_HAL_STM32_PIN_IN(E, 8, PULLUP), &lever);
if (!lever) return 2;
break;
printf(" - %d\n", lever);
if (!lever) return 1;
break;
case 2:
CYGHWR_HAL_STM32_GPIO_IN(CYGHWR_HAL_STM32_PIN_IN(E, 9, PULLUP), &lever);
if (!lever) return -2;
printf("2: %d", lever);
//if (!lever) return -1;
CYGHWR_HAL_STM32_GPIO_IN(CYGHWR_HAL_STM32_PIN_IN(E, 10, PULLUP), &lever);
if (!lever) return 2;
break;
printf(" - %d\n", lever);
if (!lever) return 1;
break;
case 1:
CYGHWR_HAL_STM32_GPIO_IN(CYGHWR_HAL_STM32_PIN_IN(E, 11, PULLUP), &lever);
if (!lever) return -2;
printf("1: %d", lever);
//if (!lever) return -1;
CYGHWR_HAL_STM32_GPIO_IN(CYGHWR_HAL_STM32_PIN_IN(E, 12, PULLUP), &lever);
if (!lever) return 2;
break;
printf(" - %d\n", lever);
if (!lever) return 1;
break;
case 0:
CYGHWR_HAL_STM32_GPIO_IN(CYGHWR_HAL_STM32_PIN_IN(E, 13, PULLUP), &lever);
if (!lever) return -2;
printf("0: %d", lever);
//if (!lever) return -1;
CYGHWR_HAL_STM32_GPIO_IN(CYGHWR_HAL_STM32_PIN_IN(E, 14, PULLUP), &lever);
if (!lever) return 2;
printf(" - %d\n", lever);
if (!lever) return 1;
break;
default:
return 0;
break;
}
}*/
CYGHWR_HAL_STM32_GPIO_IN(do3, &lever);
printf("3: %d", lever);
CYGHWR_HAL_STM32_GPIO_IN(up3, &lever);
printf(" %d - ", lever);
CYGHWR_HAL_STM32_GPIO_IN(do2, &lever);
printf("2: %d", lever);
CYGHWR_HAL_STM32_GPIO_IN(up2, &lever);
printf(" %d - ", lever);
CYGHWR_HAL_STM32_GPIO_IN(do1, &lever);
printf("1: %d", lever);
CYGHWR_HAL_STM32_GPIO_IN(up1, &lever);
printf(" %d - ", lever);
CYGHWR_HAL_STM32_GPIO_IN(do0, &lever);
printf("0: %d", lever);
CYGHWR_HAL_STM32_GPIO_IN(up0, &lever);
printf(" %d\n", lever);
return 0;
}
......@@ -100,19 +100,19 @@ static void pwm_setup(void) {
rcc_peripheral_enable_clock(&RCC_AHB1ENR, RCC_AHB1ENR_IOPDEN);
// AF = alternate function
gpio_mode_setup(GPIOD, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO12 | GPIO13 | GPIO14 | GPIO15);
gpio_mode_setup(GPIOD, GPIO_MODE_AF, GPIO_PUPD_NONE, /*GPIO12 |*/ GPIO13 | GPIO14 /*| GPIO15*/);
// AF2 = TIM4_CH1..4
gpio_set_af(GPIOD, GPIO_AF2, GPIO12 | GPIO13 | GPIO14 | GPIO15);
gpio_set_af(GPIOD, GPIO_AF2, /*GPIO12 |*/ GPIO13 | GPIO14 /*| GPIO15*/);
timer_enable_counter(TIM4);
}
extern "C" void servo_init() {
pwm_setup();
CYGHWR_HAL_STM32_GPIO_SET(GPIO_D12);
//CYGHWR_HAL_STM32_GPIO_SET(GPIO_D12);
CYGHWR_HAL_STM32_GPIO_SET(GPIO_D13);
CYGHWR_HAL_STM32_GPIO_SET(GPIO_D14);
CYGHWR_HAL_STM32_GPIO_SET(GPIO_D15);
//CYGHWR_HAL_STM32_GPIO_SET(GPIO_D15);
}
extern "C" void servo_set(uint8_t servo, uint8_t position) {
......
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