projects
/
fw
/
altos
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
drivers: Add real i2c support to mmc5983
[fw/altos]
/
src
/
drivers
/
ao_mma655x.c
diff --git
a/src/drivers/ao_mma655x.c
b/src/drivers/ao_mma655x.c
index c36858add00bd4eb83711665b233d43111857486..3fd8e064602bc092f00319c2a3878c3b65f0fc80 100644
(file)
--- a/
src/drivers/ao_mma655x.c
+++ b/
src/drivers/ao_mma655x.c
@@
-3,7
+3,8
@@
*
* 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
*
* 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; version 2 of the License.
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
@@
-24,39
+25,37
@@
#define DEBUG_LOW 1
#define DEBUG_HIGH 2
#if 1
#define DEBUG_LOW 1
#define DEBUG_HIGH 2
#if 1
-#define PRINTD(l, ...) do { if (DEBUG & (l)) { printf ("\r%5
u %s: ",
ao_tick_count, __func__); printf(__VA_ARGS__); flush(); } } while(0)
+#define PRINTD(l, ...) do { if (DEBUG & (l)) { printf ("\r%5
lu %s: ", (unsigned long)
ao_tick_count, __func__); printf(__VA_ARGS__); flush(); } } while(0)
#else
#define PRINTD(l,...)
#endif
#else
#define PRINTD(l,...)
#endif
-uint8_t ao_mma655x_spi_index = AO_MMA655X_SPI_INDEX;
+#define AO_MMA655X_SPI_SPEED ao_spi_speed(8333333) /* 120ns clock period */
static void
ao_mma655x_start(void) {
ao_spi_get_bit(AO_MMA655X_CS_PORT,
AO_MMA655X_CS_PIN,
static void
ao_mma655x_start(void) {
ao_spi_get_bit(AO_MMA655X_CS_PORT,
AO_MMA655X_CS_PIN,
- AO_MMA655X_CS,
AO_MMA655X_SPI_INDEX,
AO_MMA655X_SPI_INDEX,
- AO_
SPI_SPEED_FAST
);
+ AO_
MMA655X_SPI_SPEED
);
}
static void
ao_mma655x_stop(void) {
ao_spi_put_bit(AO_MMA655X_CS_PORT,
AO_MMA655X_CS_PIN,
}
static void
ao_mma655x_stop(void) {
ao_spi_put_bit(AO_MMA655X_CS_PORT,
AO_MMA655X_CS_PIN,
- AO_MMA655X_CS,
AO_MMA655X_SPI_INDEX);
}
static void
ao_mma655x_restart(void) {
uint8_t i;
AO_MMA655X_SPI_INDEX);
}
static void
ao_mma655x_restart(void) {
uint8_t i;
- ao_gpio_set(AO_MMA655X_CS_PORT, AO_MMA655X_CS_PIN,
AO_MMA655X_CS,
1);
+ ao_gpio_set(AO_MMA655X_CS_PORT, AO_MMA655X_CS_PIN, 1);
/* Emperical testing on STM32L151 at 32MHz for this delay amount */
for (i = 0; i < 10; i++)
ao_arch_nop();
/* Emperical testing on STM32L151 at 32MHz for this delay amount */
for (i = 0; i < 10; i++)
ao_arch_nop();
- ao_gpio_set(AO_MMA655X_CS_PORT, AO_MMA655X_CS_PIN,
AO_MMA655X_CS,
0);
+ ao_gpio_set(AO_MMA655X_CS_PORT, AO_MMA655X_CS_PIN, 0);
}
static uint8_t
}
static uint8_t
@@
-90,7
+89,7
@@
ao_mma655x_reg_read(uint8_t addr)
{
uint8_t d[2];
ao_mma655x_start();
{
uint8_t d[2];
ao_mma655x_start();
- d[0] =
addr | (ao_parity(addr) << 7
);
+ d[0] =
(uint8_t) (addr | (ao_parity(addr) << 7)
);
d[1] = 0;
ao_spi_send(&d, 2, AO_MMA655X_SPI_INDEX);
ao_mma655x_restart();
d[1] = 0;
ao_spi_send(&d, 2, AO_MMA655X_SPI_INDEX);
ao_mma655x_restart();
@@
-111,13
+110,11
@@
ao_mma655x_reg_write(uint8_t addr, uint8_t value)
PRINTD(DEBUG_LOW, "write %x %x\n", addr, value);
addr |= (1 << 6); /* write mode */
PRINTD(DEBUG_LOW, "write %x %x\n", addr, value);
addr |= (1 << 6); /* write mode */
- d[0] =
addr | (ao_parity(addr^value) << 7
);
+ d[0] =
(uint8_t) (addr | (ao_parity(addr^value) << 7)
);
d[1] = value;
ao_mma655x_start();
ao_spi_send(d, 2, AO_MMA655X_SPI_INDEX);
ao_mma655x_stop();
d[1] = value;
ao_mma655x_start();
ao_spi_send(d, 2, AO_MMA655X_SPI_INDEX);
ao_mma655x_stop();
-
- addr &= ~(1 << 6);
}
static uint16_t
}
static uint16_t
@@
-144,8
+141,8
@@
ao_mma655x_value(void)
PRINTD(DEBUG_LOW, "value RECV %02x %02x\n", d[0], d[1]);
v = (uint16_t) d[1] << 2;
PRINTD(DEBUG_LOW, "value RECV %02x %02x\n", d[0], d[1]);
v = (uint16_t) d[1] << 2;
- v
|= d[0] >> 6
;
- v
|= (uint16_t) (d[0] & 3) << 10
;
+ v
= (uint16_t) (v | (d[0] >> 6))
;
+ v
= (uint16_t) (v | ((d[0] & 3) << 10))
;
return v;
}
return v;
}
@@
-226,7
+223,7
@@
ao_mma655x_setup(void)
a = ao_mma655x_value();
a = ao_mma655x_value();
- st_change =
a_st - a
;
+ st_change =
(int16_t) (a_st - a)
;
PRINTD(DEBUG_HIGH, "self test %d normal %d change %d\n", a_st, a, st_change);
PRINTD(DEBUG_HIGH, "self test %d normal %d change %d\n", a_st, a, st_change);
@@
-235,7
+232,7
@@
ao_mma655x_setup(void)
ao_delay(AO_ST_DELAY);
}
if (tries == AO_ST_TRIES)
ao_delay(AO_ST_DELAY);
}
if (tries == AO_ST_TRIES)
-
ao_sensor_errors = 1
;
+
AO_SENSOR_ERROR(AO_DATA_MMA655X)
;
ao_mma655x_reg_write(AO_MMA655X_DEVCFG,
DEVCFG_VALUE | (1 << AO_MMA655X_DEVCFG_ENDINIT));
ao_mma655x_reg_write(AO_MMA655X_DEVCFG,
DEVCFG_VALUE | (1 << AO_MMA655X_DEVCFG_ENDINIT));
@@
-260,7
+257,7
@@
ao_mma655x_dump(void)
printf ("MMA655X value %d\n", ao_mma655x_current);
}
printf ("MMA655X value %d\n", ao_mma655x_current);
}
-
__code
struct ao_cmds ao_mma655x_cmds[] = {
+
const
struct ao_cmds ao_mma655x_cmds[] = {
{ ao_mma655x_dump, "A\0Display MMA655X data" },
{ 0, NULL },
};
{ ao_mma655x_dump, "A\0Display MMA655X data" },
{ 0, NULL },
};
@@
-278,7
+275,7
@@
ao_mma655x(void)
}
}
}
}
-static
__xdata
struct ao_task ao_mma655x_task;
+static struct ao_task ao_mma655x_task;
void
ao_mma655x_init(void)
void
ao_mma655x_init(void)