summaryrefslogtreecommitdiff
path: root/src/stm/ao_arch_funcs.h
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2012-06-26 23:01:58 -0700
committerKeith Packard <keithp@keithp.com>2012-06-26 23:01:58 -0700
commit03dc80d15a2f8fe9d7340351226dadd8bc3cfdb9 (patch)
treec7b1e429181961dbdc5f2e701b22b6950abaa860 /src/stm/ao_arch_funcs.h
parentf11f05c5d634de2a80c34d0d3dc93925980f52e6 (diff)
altos: Clean up usage of port parameters
Make stm port parameters always be pointers; this avoids the confusion where some macros took '&port' and others took a bare 'port', and also unifies code to run on other processors in a consistent fashion. Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'src/stm/ao_arch_funcs.h')
-rw-r--r--src/stm/ao_arch_funcs.h36
1 files changed, 27 insertions, 9 deletions
diff --git a/src/stm/ao_arch_funcs.h b/src/stm/ao_arch_funcs.h
index 447042dd..62b10063 100644
--- a/src/stm/ao_arch_funcs.h
+++ b/src/stm/ao_arch_funcs.h
@@ -40,36 +40,54 @@ ao_spi_recv(void *block, uint16_t len, uint8_t spi_index);
void
ao_spi_duplex(void *out, void *in, uint16_t len, uint8_t spi_index);
+#define AO_SPI_SPEED_FAST STM_SPI_CR1_BR_PCLK_16
+#define AO_SPI_SPEED_200kHz STM_SPI_CR1_BR_PCLK_256
+
+extern uint16_t ao_spi_speed[STM_NUM_SPI];
+
+#define ao_spi_slow(bus) (ao_spi_speed[bus] = AO_SPI_SPEED_200kHz)
+
+#define ao_spi_fast(bus) (ao_spi_speed[bus] = AO_SPI_SPEED_FAST)
+
void
ao_spi_init(void);
#define ao_spi_get_mask(reg,mask,bus) do { \
ao_spi_get(bus); \
- (reg).bsrr = ((uint32_t) mask) << 16; \
+ (reg)->bsrr = ((uint32_t) mask) << 16; \
} while (0)
#define ao_spi_put_mask(reg,mask,bus) do { \
- (reg).bsrr = mask; \
+ (reg)->bsrr = mask; \
ao_spi_put(bus); \
} while (0)
+#define ao_spi_get_bit(reg,bit,pin,bus) ao_spi_get_mask(reg,(1<<bit),bus)
+#define ao_spi_put_bit(reg,bit,pin,bus) ao_spi_put_mask(reg,(1<<bit),bus)
+
#define ao_enable_port(port) do { \
- if (&(port) == &stm_gpioa) \
+ if ((port) == &stm_gpioa) \
stm_rcc.ahbenr |= (1 << STM_RCC_AHBENR_GPIOAEN); \
- else if (&(port) == &stm_gpiob) \
+ else if ((port) == &stm_gpiob) \
stm_rcc.ahbenr |= (1 << STM_RCC_AHBENR_GPIOBEN); \
- else if (&(port) == &stm_gpioc) \
+ else if ((port) == &stm_gpioc) \
stm_rcc.ahbenr |= (1 << STM_RCC_AHBENR_GPIOCEN); \
- else if (&(port) == &stm_gpiod) \
+ else if ((port) == &stm_gpiod) \
stm_rcc.ahbenr |= (1 << STM_RCC_AHBENR_GPIODEN); \
- else if (&(port) == &stm_gpioe) \
+ else if ((port) == &stm_gpioe) \
stm_rcc.ahbenr |= (1 << STM_RCC_AHBENR_GPIOEEN); \
} while (0)
+#define ao_enable_output(port,pin,v) do { \
+ ao_enable_port(port); \
+ stm_gpio_set(port, pin, v); \
+ stm_moder_set(port, pin, STM_MODER_OUTPUT); \
+ } while (0)
+
#define ao_enable_cs(port,bit) do { \
- stm_gpio_set(&(port), bit, 1); \
- stm_moder_set(&(port), bit, STM_MODER_OUTPUT); \
+ stm_gpio_set((port), bit, 1); \
+ stm_moder_set((port), bit, STM_MODER_OUTPUT); \
} while (0)
#define ao_spi_init_cs(port, mask) do { \