mirror of
git://projects.qi-hardware.com/antorcha.git
synced 2024-11-24 23:00:37 +02:00
fw/: sample the acceleration sensor (untested)
This commit is contained in:
parent
7045109090
commit
eaa11b110c
@ -30,7 +30,8 @@ OBJCOPY = $(AVR_PREFIX)objcopy
|
||||
#OBJDUMP = $(AVR_PREFIX)objdump
|
||||
SIZE = $(AVR_PREFIX)size
|
||||
|
||||
OBJS = $(NAME).o dispatch.o hash.o image.o reset.o sweep.o $(COMMON_OBJS)
|
||||
OBJS = $(NAME).o accel.o dispatch.o hash.o image.o reset.o sweep.o \
|
||||
$(COMMON_OBJS)
|
||||
BOOT_OBJS = boot.o flash.o fw.o $(COMMON_OBJS)
|
||||
COMMON_OBJS = rf.o spi.o
|
||||
|
||||
|
68
fw/accel.c
Normal file
68
fw/accel.c
Normal file
@ -0,0 +1,68 @@
|
||||
/*
|
||||
* fw/accel.c - Acceleration sensor
|
||||
*
|
||||
* 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 <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <avr/io.h>
|
||||
#include <avr/interrupt.h>
|
||||
|
||||
#include "io.h"
|
||||
#include "accel.h"
|
||||
|
||||
|
||||
void (*sample)(bool x, uint16_t v) = NULL;
|
||||
|
||||
|
||||
static bool chan_x;
|
||||
|
||||
|
||||
static inline void admux(bool x)
|
||||
{
|
||||
ADMUX =
|
||||
1 << REFS0 | /* Vref is AVcc */
|
||||
(x ? ADC_X : ADC_Y);
|
||||
}
|
||||
|
||||
|
||||
static inline void adcsra(bool start)
|
||||
{
|
||||
ADCSRA =
|
||||
1 << ADEN | /* enable ADC */
|
||||
(start ? 1 << ADSC : 0) |
|
||||
1 << ADIE | /* enable ADC interrupts */
|
||||
7; /* clkADC = clk/128 -> 62.5 kHz */
|
||||
}
|
||||
|
||||
|
||||
ISR(ADC_vect)
|
||||
{
|
||||
uint16_t v;
|
||||
|
||||
v = ADC;
|
||||
if (sample)
|
||||
sample(chan_x, v);
|
||||
|
||||
chan_x = !chan_x;
|
||||
admux(chan_x);
|
||||
adcsra(1);
|
||||
}
|
||||
|
||||
|
||||
void accel_start(void)
|
||||
{
|
||||
adcsra(0);
|
||||
admux(1);
|
||||
chan_x = 1;
|
||||
}
|
26
fw/accel.h
Normal file
26
fw/accel.h
Normal file
@ -0,0 +1,26 @@
|
||||
/*
|
||||
* fw/accel.h - Acceleration sensor
|
||||
*
|
||||
* 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 ACCEL_H
|
||||
#define ACCEL_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
extern void (*sample)(bool x, uint16_t v);
|
||||
|
||||
|
||||
void accel_start(void);
|
||||
|
||||
#endif /* !ACCEL_H */
|
@ -17,6 +17,7 @@
|
||||
#include "rf.h"
|
||||
#include "dispatch.h"
|
||||
#include "sweep.h"
|
||||
#include "accel.h"
|
||||
#include "image.h"
|
||||
|
||||
|
||||
@ -47,6 +48,7 @@ int main(void)
|
||||
*/
|
||||
|
||||
sweep_init();
|
||||
accel_start();
|
||||
|
||||
while (1) {
|
||||
got = rf_recv(buf, sizeof(buf));
|
||||
|
Loading…
Reference in New Issue
Block a user