aboutsummaryrefslogtreecommitdiff
path: root/accel.c
diff options
context:
space:
mode:
authorLars-Dominik Braun <lars@6xq.net>2014-03-31 11:18:32 +0200
committerLars-Dominik Braun <lars@6xq.net>2014-04-22 16:51:13 +0200
commite3897565c342bee4765f921240b7ca91cd9b23f1 (patch)
treee7e328ee9452d54db9cfe66cccdb031cb704030f /accel.c
parent24d11d4976062e965fb64861808548c39f53714b (diff)
downloadhourglass-e3897565c342bee4765f921240b7ca91cd9b23f1.tar.gz
hourglass-e3897565c342bee4765f921240b7ca91cd9b23f1.tar.bz2
hourglass-e3897565c342bee4765f921240b7ca91cd9b23f1.zip
Activate accel + timer
Diffstat (limited to 'accel.c')
-rw-r--r--accel.c27
1 files changed, 15 insertions, 12 deletions
diff --git a/accel.c b/accel.c
index a178fa3..670121e 100644
--- a/accel.c
+++ b/accel.c
@@ -23,7 +23,6 @@ static volatile int8_t val[6] = {0, 0, 0, 0, 0, 0};
/* currently reading from i2c */
static bool reading = false;
-#warning "wrong interrupt"
/* data ready interrupt
*/
ISR(PCINT1_vect) {
@@ -31,13 +30,13 @@ ISR(PCINT1_vect) {
}
void accelInit () {
- /* set PB1 to input, with pull-up */
- //DDRB = (DDRB & ~((1 << PB1)));
- //PORTB = (PORTB | (1 << PB1));
- /* enable interrupt PCI0 */
- //PCICR = (1 << PCIE0);
- /* enable interrupts on PB1/PCINT1 */
- //PCMSK0 = (1 << 1);
+ /* set interrupt lines to input with pull-up */
+ DDRC = DDRC & ~((1 << PC0) | (1 << PC1));
+ PORTC = PORTC | (1 << PC0) | (1 << PC1);
+ /* enable interrupt PCI1 for PCINT8/9 */
+ PCICR = PCICR | (1 << PCIE1);
+ /* enable interrupts from port PC0/PC1 aka PCINT8/PCINT9 */
+ PCMSK1 = (1 << PCINT9) | (1 << PCINT8);
}
/* XXX: make nonblocking */
@@ -45,9 +44,9 @@ void accelStart () {
/* configuration:
* disable power-down-mode
* defaults
- * data ready interrupt on int2
+ * low active, data ready interrupt on int2
*/
- uint8_t data[] = {0b01000111, 0b0, 0b00100000};
+ uint8_t data[] = {0b01000111, 0b0, 0b10100000};
if (!twRequest (TWM_WRITE, LIS302DL, LIS302DL_CTRLREG1, data,
sizeof (data)/sizeof (*data))) {
@@ -64,11 +63,11 @@ bool accelProcess () {
reading = false;
return true;
} else if (twr.status == TWST_ERR) {
- printf ("accel i2c error\n");
+ printf ("accel i2c error %x at step %i\n", twr.error, twr.step);
reading = false;
}
} else {
- if (drdy && twr.status != TWST_WAIT) {
+ if (/*drdy &&*/ twr.status != TWST_WAIT) {
/* new data available in device buffer and bus is free, we are
* reading the registers inbetween out_x/y/z and ignore them */
if (!twRequest (TWM_READ, LIS302DL, LIS302DL_UNUSED1, (uint8_t *) val, 6)) {
@@ -83,3 +82,7 @@ bool accelProcess () {
return false;
}
+volatile const int8_t *accelGet () {
+ return val;
+}
+