summaryrefslogtreecommitdiff
path: root/src/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'src/drivers')
-rw-r--r--src/drivers/ao_25lc1024.c11
-rw-r--r--src/drivers/ao_at45db161d.c4
-rw-r--r--src/drivers/ao_companion.c49
-rw-r--r--src/drivers/ao_hmc5883.c6
-rw-r--r--src/drivers/ao_ms5607.c14
5 files changed, 48 insertions, 36 deletions
diff --git a/src/drivers/ao_25lc1024.c b/src/drivers/ao_25lc1024.c
index f0fb13c9..b25d52c4 100644
--- a/src/drivers/ao_25lc1024.c
+++ b/src/drivers/ao_25lc1024.c
@@ -38,8 +38,9 @@ __pdata uint16_t ao_storage_unit;
* Using SPI on USART 0, with P1_2 as the chip select
*/
+#define EE_CS_PORT P1
#define EE_CS P1_2
-#define EE_CS_INDEX 2
+#define EE_CS_PIN 2
static __xdata uint8_t ao_ee_mutex;
@@ -49,9 +50,9 @@ static __xdata uint8_t ao_ee_mutex;
_asm nop _endasm; \
} while(0)
-#define ao_ee_cs_low() ao_spi_get_bit(EE_CS, AO_EE_SPI_BUS)
+#define ao_ee_cs_low() ao_spi_get_bit(EE_CS_PORT, EE_CS_PIN, EE_CS, AO_EE_SPI_BUS)
-#define ao_ee_cs_high() ao_spi_put_bit(EE_CS, AO_EE_SPI_BUS)
+#define ao_ee_cs_high() ao_spi_put_bit(EE_CS_PORT, EE_CS_PIN, EE_CS, AO_EE_SPI_BUS)
struct ao_ee_instruction {
uint8_t instruction;
@@ -235,7 +236,5 @@ void
ao_storage_device_init(void)
{
/* set up CS */
- EE_CS = 1;
- P1DIR |= (1 << EE_CS_INDEX);
- P1SEL &= ~(1 << EE_CS_INDEX);
+ ao_enable_output(EE_CS_PORT, EE_CS_PIN,1);
}
diff --git a/src/drivers/ao_at45db161d.c b/src/drivers/ao_at45db161d.c
index afe0080b..5eb25acf 100644
--- a/src/drivers/ao_at45db161d.c
+++ b/src/drivers/ao_at45db161d.c
@@ -43,9 +43,9 @@ __xdata uint8_t ao_flash_mutex;
_asm nop _endasm; \
} while(0)
-#define ao_flash_cs_low() ao_spi_get_bit(FLASH_CS, AO_FLASH_SPI_BUS)
+#define ao_flash_cs_low() ao_spi_get_bit(FLASH_CS_PORT, FLASH_CS_PIN, FLASH_CS, AO_FLASH_SPI_BUS)
-#define ao_flash_cs_high() ao_spi_put_bit(FLASH_CS, AO_FLASH_SPI_BUS)
+#define ao_flash_cs_high() ao_spi_put_bit(FLASH_CS_PORT, FLASH_CS_PIN, FLASH_CS, AO_FLASH_SPI_BUS)
struct ao_flash_instruction {
uint8_t instruction;
diff --git a/src/drivers/ao_companion.c b/src/drivers/ao_companion.c
index fe88e998..a31cc2ea 100644
--- a/src/drivers/ao_companion.c
+++ b/src/drivers/ao_companion.c
@@ -15,20 +15,36 @@
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
-#include "ao.h"
-
-#define ao_spi_slow() (U0GCR = (UxGCR_CPOL_NEGATIVE | \
- UxGCR_CPHA_FIRST_EDGE | \
- UxGCR_ORDER_MSB | \
- (13 << UxGCR_BAUD_E_SHIFT)))
-
-#define ao_spi_fast() (U0GCR = (UxGCR_CPOL_NEGATIVE | \
- UxGCR_CPHA_FIRST_EDGE | \
- UxGCR_ORDER_MSB | \
- (17 << UxGCR_BAUD_E_SHIFT)))
-
-#define COMPANION_SELECT() do { ao_spi_get_bit(COMPANION_CS, AO_COMPANION_BUS); ao_spi_slow(); } while (0)
-#define COMPANION_DESELECT() do { ao_spi_fast(); ao_spi_put_bit(COMPANION_CS, AO_COMPANION_BUS); } while (0)
+#include <ao.h>
+#include <ao_companion.h>
+
+#ifndef ao_spi_slow
+#define ao_spi_slow(bus) (U0GCR = (UxGCR_CPOL_NEGATIVE | \
+ UxGCR_CPHA_FIRST_EDGE | \
+ UxGCR_ORDER_MSB | \
+ (13 << UxGCR_BAUD_E_SHIFT)))
+
+#define ao_spi_fast(bus) (U0GCR = (UxGCR_CPOL_NEGATIVE | \
+ UxGCR_CPHA_FIRST_EDGE | \
+ UxGCR_ORDER_MSB | \
+ (17 << UxGCR_BAUD_E_SHIFT)))
+#endif
+
+#define COMPANION_SELECT() do { \
+ ao_spi_get_bit(AO_COMPANION_CS_PORT, \
+ AO_COMPANION_CS_PIN, \
+ AO_COMPANION_CS, \
+ AO_COMPANION_SPI_BUS); \
+ ao_spi_slow(AO_COMPANION_SPI_BUS); \
+ } while (0)
+
+#define COMPANION_DESELECT() do { \
+ ao_spi_fast(AO_COMPANION_SPI_BUS); \
+ ao_spi_put_bit(AO_COMPANION_CS_PORT, \
+ AO_COMPANION_CS_PIN, \
+ AO_COMPANION_CS, \
+ AO_COMPANION_SPI_BUS); \
+ } while (0)
__xdata struct ao_companion_command ao_companion_command;
__xdata struct ao_companion_setup ao_companion_setup;
@@ -123,10 +139,7 @@ static __xdata struct ao_task ao_companion_task;
void
ao_companion_init(void)
{
- COMPANION_CS_PORT |= COMPANION_CS_MASK; /* raise all CS pins */
- COMPANION_CS_DIR |= COMPANION_CS_MASK; /* set CS pins as outputs */
- COMPANION_CS_SEL &= ~COMPANION_CS_MASK; /* set CS pins as GPIO */
-
+ ao_enable_output(AO_COMPANION_CS_PORT, AO_COMPANION_CS_PIN, 1);
ao_cmd_register(&ao_companion_cmds[0]);
ao_add_task(&ao_companion_task, ao_companion, "companion");
}
diff --git a/src/drivers/ao_hmc5883.c b/src/drivers/ao_hmc5883.c
index 1bc914e6..64663ea6 100644
--- a/src/drivers/ao_hmc5883.c
+++ b/src/drivers/ao_hmc5883.c
@@ -58,7 +58,7 @@ static uint8_t ao_hmc5883_done;
static void
ao_hmc5883_isr(void)
{
- ao_exti_disable(&AO_HMC5883_INT_PORT, AO_HMC5883_INT_PIN);
+ ao_exti_disable(AO_HMC5883_INT_PORT, AO_HMC5883_INT_PIN);
ao_hmc5883_done = 1;
ao_wakeup(&ao_hmc5883_done);
}
@@ -71,7 +71,7 @@ ao_hmc5883_sample(struct ao_hmc5883_sample *sample)
uint8_t single = HMC5883_MODE_SINGLE;
ao_hmc5883_done = 0;
- ao_exti_enable(&AO_HMC5883_INT_PORT, AO_HMC5883_INT_PIN);
+ ao_exti_enable(AO_HMC5883_INT_PORT, AO_HMC5883_INT_PIN);
ao_hmc5883_reg_write(HMC5883_MODE, HMC5883_MODE_SINGLE);
cli();
@@ -159,7 +159,7 @@ ao_hmc5883_init(void)
ao_hmc5883_valid = 0;
ao_enable_port(AO_HMC5883_INT_PORT);
- ao_exti_setup(&AO_HMC5883_INT_PORT,
+ ao_exti_setup(AO_HMC5883_INT_PORT,
AO_HMC5883_INT_PIN,
AO_EXTI_MODE_FALLING | AO_EXTI_MODE_PULL_UP,
ao_hmc5883_isr);
diff --git a/src/drivers/ao_ms5607.c b/src/drivers/ao_ms5607.c
index 0f0625d0..e08f4d40 100644
--- a/src/drivers/ao_ms5607.c
+++ b/src/drivers/ao_ms5607.c
@@ -25,12 +25,12 @@ static uint8_t ms5607_configured;
static void
ao_ms5607_start(void) {
ao_spi_get(AO_MS5607_SPI_INDEX);
- stm_gpio_set(&AO_MS5607_CS_GPIO, AO_MS5607_CS, 0);
+ stm_gpio_set(AO_MS5607_CS_GPIO, AO_MS5607_CS, 0);
}
static void
ao_ms5607_stop(void) {
- stm_gpio_set(&AO_MS5607_CS_GPIO, AO_MS5607_CS, 1);
+ stm_gpio_set(AO_MS5607_CS_GPIO, AO_MS5607_CS, 1);
ao_spi_put(AO_MS5607_SPI_INDEX);
}
@@ -132,12 +132,12 @@ ao_ms5607_get_sample(uint8_t cmd) {
ao_ms5607_start();
ao_spi_send(&cmd, 1, AO_MS5607_SPI_INDEX);
- ao_exti_enable(&AO_MS5607_MISO_GPIO, AO_MS5607_MISO);
+ ao_exti_enable(AO_MS5607_MISO_GPIO, AO_MS5607_MISO);
cli();
while (!ao_ms5607_done)
ao_sleep(&ao_ms5607_done);
sei();
- ao_exti_disable(&AO_MS5607_MISO_GPIO, AO_MS5607_MISO);
+ ao_exti_disable(AO_MS5607_MISO_GPIO, AO_MS5607_MISO);
ao_ms5607_stop();
ao_ms5607_start();
@@ -203,7 +203,7 @@ ao_ms5607(void)
ao_ms5607_setup();
for (;;)
{
- struct ao_ms5607_sample ao_ms5607_next;
+ static struct ao_ms5607_sample ao_ms5607_next;
ao_ms5607_sample(&ao_ms5607_next);
ao_arch_critical(
ao_ms5607_current = ao_ms5607_next;
@@ -260,7 +260,7 @@ ao_ms5607_init(void)
* conversion is complete, the MS5607 will raise this
* pin as a signal
*/
- ao_exti_setup(&AO_MS5607_MISO_GPIO,
+ ao_exti_setup(AO_MS5607_MISO_GPIO,
AO_MS5607_MISO,
AO_EXTI_MODE_RISING,
ao_ms5607_isr);
@@ -268,7 +268,7 @@ ao_ms5607_init(void)
/* Reset the pin from INPUT to ALTERNATE so that SPI works
* This needs an abstraction at some point...
*/
- stm_moder_set(&AO_MS5607_MISO_GPIO,
+ stm_moder_set(AO_MS5607_MISO_GPIO,
AO_MS5607_MISO,
STM_MODER_ALTERNATE);
}