From 65906a6df773c8ff5b657d95b8620d5d5a82a26e Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Sun, 18 May 2014 02:06:16 +0200 Subject: added tube-rotator project --- tube-rotator/Makefile | 46 +++++++++++++++++++++++ tube-rotator/stepper.c | 92 +++++++++++++++++++++++++++++++++++++++++++++ tube-rotator/stepper.h | 30 +++++++++++++++ tube-rotator/tube-rotator.c | 75 ++++++++++++++++++++++++++++++++++++ 4 files changed, 243 insertions(+) create mode 100644 tube-rotator/Makefile create mode 100644 tube-rotator/stepper.c create mode 100644 tube-rotator/stepper.h create mode 100644 tube-rotator/tube-rotator.c diff --git a/tube-rotator/Makefile b/tube-rotator/Makefile new file mode 100644 index 0000000..c75c022 --- /dev/null +++ b/tube-rotator/Makefile @@ -0,0 +1,46 @@ +## +## spreadspace avr utils +## +## +## Copyright (C) 2014 Christian Pointner +## +## This file is part of spreadspace avr utils. +## +## spreadspace avr utils is free software: you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation, either version 3 of the License, or +## any later version. +## +## spreadspace avr utils is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with spreadspace avr utils. If not, see . +## + +NAME := tube-rotator +BOARD_TYPE := teenstep +OBJ := $(NAME).o stepper.o +LIBS := util led lufa-descriptor-usbserial anyio +EXTERNAL_LIBS := lufa +RESET_FUNC := ../tools/reset_lufa_cdc +RESET_PARAM := '!' + +LUFA_PATH := ../contrib/LUFA-120219 +LUFA_OPTS = -D USB_DEVICE_ONLY +LUFA_OPTS += -D DEVICE_STATE_AS_GPIOR=0 +LUFA_OPTS += -D ORDERED_EP_CONFIG +LUFA_OPTS += -D FIXED_CONTROL_ENDPOINT_SIZE=8 +LUFA_OPTS += -D FIXED_NUM_CONFIGURATIONS=1 +LUFA_OPTS += -D USE_FLASH_DESCRIPTORS +LUFA_OPTS += -D USE_STATIC_OPTIONS="(USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)" +LUFA_OPTS += -D INTERRUPT_CONTROL_ENDPOINT + +LUFA_OPTS += -D USB_MANUFACTURER="L\"equinox\"" -D USB_MANUFACTURER_LEN=7 +LUFA_OPTS += -D USB_PRODUCT="L\"realraum tube rotator\"" -D USB_PRODUCT_LEN=21 + +LUFA_COMPONENTS := USB USBCLASS SERIAL + +include ../include.mk diff --git a/tube-rotator/stepper.c b/tube-rotator/stepper.c new file mode 100644 index 0000000..1bb9cae --- /dev/null +++ b/tube-rotator/stepper.c @@ -0,0 +1,92 @@ +/* + * spreadspace avr utils + * + * + * Copyright (C) 2014 Christian Pointner + * + * This file is part of spreadspace avr utils. + * + * spreadspace avr utils is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * spreadspace avr utils is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with spreadspace avr utils. If not, see . + */ + +#include +#include + +#include "stepper.h" + +uint8_t step_table [] = +{ + /* full steps */ + /* 6, // 0110 */ + /* 5, // 0101 */ + /* 9, // 1001 */ + /* 10, // 1010 */ + + /* half steps */ + 2, // 0010 + 6, // 0110 + 4, // 0100 + 5, // 0101 + 1, // 0001 + 9, // 1001 + 8, // 1000 + 10, // 1010 +}; + +#define STEPPER_PORT PORTF +#define STEPPER_DDR DDRF +#define STEPPER_FIRST_BIT 4 +#define STEPPER_ENABLE_A_BIT 0 +#define STEPPER_ENABLE_B_BIT 1 +#define LENGTH_STEP_TABLE (sizeof(step_table)/sizeof(uint8_t)) +#define STEPPER_OUTPUT_BITMASK (~(0xF << STEPPER_FIRST_BIT )) + +void stepper_init(void) +{ + STEPPER_PORT &= ~(0xF << STEPPER_FIRST_BIT | 1< + * + * This file is part of spreadspace avr utils. + * + * spreadspace avr utils is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * spreadspace avr utils is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with spreadspace avr utils. If not, see . + */ + +#ifndef R3TUBE_stepper_h_INCLUDED +#define R3TUBE_stepper_h_INCLUDED + +void stepper_init(void); +void stepper_start(void); +void stepper_stop(void); + +#endif diff --git a/tube-rotator/tube-rotator.c b/tube-rotator/tube-rotator.c new file mode 100644 index 0000000..7a0e2ec --- /dev/null +++ b/tube-rotator/tube-rotator.c @@ -0,0 +1,75 @@ +/* + * spreadspace avr utils + * + * + * Copyright (C) 2014 Christian Pointner + * + * This file is part of spreadspace avr utils. + * + * spreadspace avr utils is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * spreadspace avr utils is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with spreadspace avr utils. If not, see . + */ + +#include +#include +#include +#include + +#include +#include + +#include "util.h" +#include "led.h" +#include "anyio.h" + +#include "stepper.h" + +void handle_cmd(uint8_t cmd) +{ + switch(cmd) { + case '!': + reset2bootloader(); + break; + case 'r': + led_on(); + stepper_start(); + break; + case 's': + stepper_stop(); + led_off(); + break; + default: printf("Error(cmd): unknown command %02X '%c'\r\n", cmd, cmd); return; + } +} + +int main(void) +{ + MCUSR &= ~(1 << WDRF); + wdt_disable(); + + cpu_init(); + jtag_disable(); + led_init(); + anyio_init(115200, 0); + + stepper_init(); + sei(); + + for(;;) { + anyio_task(); + + int16_t bytes_received = anyio_bytes_received(); + if(bytes_received > 0) + handle_cmd(fgetc(stdin)); + } +} -- cgit v1.2.3