mirror of
git://projects.qi-hardware.com/antorcha.git
synced 2024-12-23 03:53:00 +02:00
fw/: added image sweep (completely untested)
This commit is contained in:
parent
2ecd291ca5
commit
7003c9c35b
@ -30,7 +30,7 @@ OBJCOPY = $(AVR_PREFIX)objcopy
|
||||
#OBJDUMP = $(AVR_PREFIX)objdump
|
||||
SIZE = $(AVR_PREFIX)size
|
||||
|
||||
OBJS = $(NAME).o dispatch.o hash.o reset.o $(COMMON_OBJS)
|
||||
OBJS = $(NAME).o dispatch.o hash.o reset.o sweep.o $(COMMON_OBJS)
|
||||
BOOT_OBJS = boot.o flash.o fw.o $(COMMON_OBJS)
|
||||
COMMON_OBJS = rf.o spi.o
|
||||
|
||||
|
@ -14,13 +14,9 @@
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <avr/io.h>
|
||||
#define F_CPU 8000000UL
|
||||
#include <util/delay.h>
|
||||
|
||||
#include "io.h"
|
||||
#include "rf.h"
|
||||
#include "dispatch.h"
|
||||
#include "sweep.h"
|
||||
|
||||
|
||||
static const struct handler *protos[] = {
|
||||
@ -39,6 +35,8 @@ int main(void)
|
||||
* It has also brought up RF and the underlying SPI.
|
||||
*/
|
||||
|
||||
sweep_init();
|
||||
|
||||
while (1) {
|
||||
got = rf_recv(buf, sizeof(buf));
|
||||
if (got > 2)
|
||||
|
14
fw/io.h
14
fw/io.h
@ -16,6 +16,20 @@
|
||||
#include <avr/io.h>
|
||||
|
||||
|
||||
#define LED_A1 C, 0
|
||||
#define LED_A2 C, 1
|
||||
#define LED_A3 C, 2
|
||||
#define LED_A4 C, 3
|
||||
#define LED_A5 C, 4
|
||||
#define LED_A6 C, 5
|
||||
#define LED_A7 D, 0
|
||||
#define LED_A8 D, 1
|
||||
|
||||
#define LED_B1 D, 2
|
||||
#define LED_B2 D, 3
|
||||
#define LED_B3 D, 4
|
||||
#define LED_B4 B, 6
|
||||
#define LED_B5 B, 7
|
||||
#define LED_B6 D, 5
|
||||
#define LED_B7 D, 6
|
||||
#define LED_B8 D, 7
|
||||
|
34
fw/proto.h
34
fw/proto.h
@ -13,6 +13,9 @@
|
||||
#ifndef PROTO_H
|
||||
#define PROTO_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
#define PAYLOAD 64 /* most messages use a fixed 64 bytes payload */
|
||||
|
||||
enum pck_type {
|
||||
@ -27,4 +30,35 @@ enum pck_type {
|
||||
PARAM_ACK = 9, /* parameter upload acknowledgement */
|
||||
};
|
||||
|
||||
|
||||
struct params {
|
||||
/* Timer ticks */
|
||||
|
||||
uint16_t clkT_period; /* Timer period */
|
||||
|
||||
/* Accelerator thresholds */
|
||||
|
||||
uint16_t xa_high; /* X acceleration high threshold */
|
||||
uint16_t xa_low; /* X acceleration low threshold */
|
||||
|
||||
/* Pixel offsets (in image) */
|
||||
|
||||
uint8_t px_fwd_img_first; /* first column in forward move */
|
||||
uint8_t px_fwd_img_end; /* last column in forward move */
|
||||
uint8_t px_bwd_img_first; /* first (high) col. in backward move */
|
||||
uint8_t px_bwd_img_end; /* last (low) column in backward move */
|
||||
|
||||
/* Timer periods, for imaging */
|
||||
|
||||
uint16_t tp_fwd_start; /* forward image start */
|
||||
uint16_t tp_bwd_start; /* backward image start */
|
||||
uint8_t tp_fwd_pix; /* pixel size in forward move */
|
||||
uint8_t tp_bwd_pix; /* pixel size in backward move */
|
||||
|
||||
/* Timer periods, for estimation */
|
||||
|
||||
uint16_t tp_fwd; /* forward half-period */
|
||||
uint16_t tp_bwd; /* backward half-period */
|
||||
};
|
||||
|
||||
#endif /* !PROTO_H */
|
||||
|
145
fw/sweep.c
Normal file
145
fw/sweep.c
Normal file
@ -0,0 +1,145 @@
|
||||
/*
|
||||
* fw/image.c - Image sweep
|
||||
*
|
||||
* Written 2012 by Werner Almesberger
|
||||
* Copyright 2012 Werner Almesberger
|
||||
*
|
||||
* This program 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 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*/
|
||||
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <avr/io.h>
|
||||
#include <avr/interrupt.h>
|
||||
|
||||
#include "sweep.h"
|
||||
|
||||
|
||||
struct line image[MAX_LINES];
|
||||
|
||||
static uint32_t t_sw; /* cumulative number of timer ticks in sweep */
|
||||
|
||||
static uint16_t wait_periods; /* number of periods to wait before image */
|
||||
static uint16_t wait_period; /* ticks in wait period */
|
||||
static uint16_t wait_short; /* ticks to wait after periods */
|
||||
|
||||
static uint16_t pixel_ticks; /* number of ticks per pixel */
|
||||
static const struct line *curr_line;
|
||||
static const struct line *end_line;
|
||||
static bool forward;
|
||||
|
||||
|
||||
ISR(TIMER1_OVF_vect)
|
||||
{
|
||||
/* update the sweep time */
|
||||
|
||||
t_sw += OCR1A;
|
||||
|
||||
/* if at the end of the image, only update the time */
|
||||
|
||||
if (curr_line == end_line)
|
||||
return;
|
||||
|
||||
/* wait before starting the image */
|
||||
|
||||
if (wait_periods) {
|
||||
if (!--wait_periods)
|
||||
OCR1A = wait_short;
|
||||
return;
|
||||
}
|
||||
|
||||
/* output the next line */
|
||||
|
||||
PORTB = (PORTB & 0x3f) | (curr_line->cb & 0xc0);
|
||||
PORTC = curr_line->cb;
|
||||
PORTD = curr_line->d;
|
||||
|
||||
/* move to the next line */
|
||||
|
||||
if (forward)
|
||||
curr_line++;
|
||||
else
|
||||
curr_line--;
|
||||
|
||||
/* wait until the next pixel (or slow down if we're done) */
|
||||
|
||||
if (curr_line == end_line)
|
||||
OCR1A = 0xffff;
|
||||
else
|
||||
OCR1A = pixel_ticks;
|
||||
}
|
||||
|
||||
|
||||
void image_sweep(const struct sweep *sweep)
|
||||
{
|
||||
TCCR1B = 0; /* stop the timer */
|
||||
|
||||
cli();
|
||||
|
||||
/* shut down all the LEDs, in case we're still in a sweep */
|
||||
|
||||
PORTB &= 0x3f;
|
||||
PORTC = 0;
|
||||
PORTD = 0;
|
||||
|
||||
/* image pointers and sweep direction */
|
||||
|
||||
forward = sweep->forward;
|
||||
if (forward) {
|
||||
curr_line = image+sweep->left;
|
||||
end_line = image+sweep->right+1;
|
||||
} else {
|
||||
curr_line = image+sweep->right;
|
||||
end_line = image+sweep->left-1;
|
||||
}
|
||||
|
||||
/* timing parameters */
|
||||
|
||||
wait_periods = sweep->wait_ticks >> 16;
|
||||
if (wait_periods) {
|
||||
wait_short = sweep->wait_ticks;
|
||||
wait_period = 0xffff;
|
||||
|
||||
/*
|
||||
* Make sure we have plenty of time to update OCR1A after an
|
||||
* interrupt.
|
||||
*/
|
||||
if (wait_short < 256) {
|
||||
wait_period -= 128;
|
||||
wait_short += wait_periods << 7;
|
||||
}
|
||||
OCR1A = wait_period;
|
||||
} else {
|
||||
OCR1A = sweep->wait_ticks;
|
||||
}
|
||||
|
||||
/* prepare the hardware timer */
|
||||
|
||||
t_sw = 0; /* reset the time */
|
||||
TCNT1 = 0;
|
||||
TIFR1 = 1 << TOV1; /* clear interrupt */
|
||||
|
||||
/* start the timer */
|
||||
|
||||
TCCR1B =
|
||||
1 << WGM13 | /* WG Mode 15, continued */
|
||||
1 << WGM12 |
|
||||
1 << CS11; /* clkIO/8 */
|
||||
}
|
||||
|
||||
|
||||
void sweep_init(void)
|
||||
{
|
||||
TCCR1A =
|
||||
1 << WGM11 | /* WG Mode 15 (Fast PWM to OCR1A) */
|
||||
1 << WGM10;
|
||||
|
||||
TCNT1 = 0;
|
||||
|
||||
TIMSK1 = 1 << TOIE1; /* enable timer interrupts */
|
||||
}
|
45
fw/sweep.h
Normal file
45
fw/sweep.h
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* fw/sweep.h - Image sweep
|
||||
*
|
||||
* Written 2012 by Werner Almesberger
|
||||
* Copyright 2012 Werner Almesberger
|
||||
*
|
||||
* This program 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 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef SWEEP_H
|
||||
#define SWEEP_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
#define MAX_LINES 100
|
||||
|
||||
|
||||
struct line {
|
||||
uint8_t d; /* port D0-D7 */
|
||||
uint8_t cb; /* port C0-C5, B6-B7 */
|
||||
};
|
||||
|
||||
|
||||
struct sweep {
|
||||
uint32_t wait_ticks; /* number of ticks to wait before image */
|
||||
uint16_t pixel_ticks; /* number of ticks per pixel */
|
||||
uint8_t left; /* leftmost line of image */
|
||||
uint8_t right; /* rightmost line of image */
|
||||
bool forward; /* direction of movement */
|
||||
};
|
||||
|
||||
|
||||
extern struct line image[MAX_LINES];
|
||||
|
||||
|
||||
void image_sweep(const struct sweep *sweep);
|
||||
void sweep_init(void);
|
||||
|
||||
#endif /* !SWEEP_H */
|
Loading…
Reference in New Issue
Block a user