diff options
Diffstat (limited to 'src/stm')
-rw-r--r-- | src/stm/ao_adc_stm.c | 30 | ||||
-rw-r--r-- | src/stm/ao_arch_funcs.h | 36 | ||||
-rw-r--r-- | src/stm/ao_led.c | 17 |
3 files changed, 53 insertions, 30 deletions
diff --git a/src/stm/ao_adc_stm.c b/src/stm/ao_adc_stm.c index ed1d20c9..7564c7fa 100644 --- a/src/stm/ao_adc_stm.c +++ b/src/stm/ao_adc_stm.c @@ -156,43 +156,43 @@ ao_adc_init(void) #endif #ifdef AO_ADC_PIN0_PORT - stm_moder_set(&AO_ADC_PIN0_PORT, AO_ADC_PIN0_PIN, STM_MODER_ANALOG); + stm_moder_set(AO_ADC_PIN0_PORT, AO_ADC_PIN0_PIN, STM_MODER_ANALOG); #endif #ifdef AO_ADC_PIN1_PORT - stm_moder_set(&AO_ADC_PIN1_PORT, AO_ADC_PIN1_PIN, STM_MODER_ANALOG); + stm_moder_set(AO_ADC_PIN1_PORT, AO_ADC_PIN1_PIN, STM_MODER_ANALOG); #endif #ifdef AO_ADC_PIN2_PORT - stm_moder_set(&AO_ADC_PIN2_PORT, AO_ADC_PIN2_PIN, STM_MODER_ANALOG); + stm_moder_set(AO_ADC_PIN2_PORT, AO_ADC_PIN2_PIN, STM_MODER_ANALOG); #endif #ifdef AO_ADC_PIN3_PORT - stm_moder_set(&AO_ADC_PIN3_PORT, AO_ADC_PIN3_PIN, STM_MODER_ANALOG); + stm_moder_set(AO_ADC_PIN3_PORT, AO_ADC_PIN3_PIN, STM_MODER_ANALOG); #endif #ifdef AO_ADC_PIN4_PORT - stm_moder_set(&AO_ADC_PIN4_PORT, AO_ADC_PIN4_PIN, STM_MODER_ANALOG); + stm_moder_set(AO_ADC_PIN4_PORT, AO_ADC_PIN4_PIN, STM_MODER_ANALOG); #endif #ifdef AO_ADC_PIN5_PORT - stm_moder_set(&AO_ADC_PIN5_PORT, AO_ADC_PIN5_PIN, STM_MODER_ANALOG); + stm_moder_set(AO_ADC_PIN5_PORT, AO_ADC_PIN5_PIN, STM_MODER_ANALOG); #endif #ifdef AO_ADC_PIN6_PORT - stm_moder_set(&AO_ADC_PIN6_PORT, AO_ADC_PIN6_PIN, STM_MODER_ANALOG); + stm_moder_set(AO_ADC_PIN6_PORT, AO_ADC_PIN6_PIN, STM_MODER_ANALOG); #endif #ifdef AO_ADC_PIN7_PORT - stm_moder_set(&AO_ADC_PIN7_PORT, AO_ADC_PIN7_PIN, STM_MODER_ANALOG); + stm_moder_set(AO_ADC_PIN7_PORT, AO_ADC_PIN7_PIN, STM_MODER_ANALOG); #endif #ifdef AO_ADC_PIN8_PORT - stm_moder_set(&AO_ADC_PIN8_PORT, AO_ADC_PIN8_PIN, STM_MODER_ANALOG); + stm_moder_set(AO_ADC_PIN8_PORT, AO_ADC_PIN8_PIN, STM_MODER_ANALOG); #endif #ifdef AO_ADC_PIN9_PORT - stm_moder_set(&AO_ADC_PIN9_PORT, AO_ADC_PIN9_PIN, STM_MODER_ANALOG); + stm_moder_set(AO_ADC_PIN9_PORT, AO_ADC_PIN9_PIN, STM_MODER_ANALOG); #endif #ifdef AO_ADC_PIN10_PORT - stm_moder_set(&AO_ADC_PIN10_PORT, AO_ADC_PIN10_PIN, STM_MODER_ANALOG); + stm_moder_set(AO_ADC_PIN10_PORT, AO_ADC_PIN10_PIN, STM_MODER_ANALOG); #endif #ifdef AO_ADC_PIN11_PORT - stm_moder_set(&AO_ADC_PIN11_PORT, AO_ADC_PIN11_PIN, STM_MODER_ANALOG); + stm_moder_set(AO_ADC_PIN11_PORT, AO_ADC_PIN11_PIN, STM_MODER_ANALOG); #endif #ifdef AO_ADC_PIN12_PORT - stm_moder_set(&AO_ADC_PIN12_PORT, AO_ADC_PIN12_PIN, STM_MODER_ANALOG); + stm_moder_set(AO_ADC_PIN12_PORT, AO_ADC_PIN12_PIN, STM_MODER_ANALOG); #endif stm_rcc.apb2enr |= (1 << STM_RCC_APB2ENR_ADC1EN); @@ -281,8 +281,10 @@ ao_adc_init(void) #endif /* Clear any stale status bits */ stm_adc.sr = 0; - ao_adc_ready = 1; ao_dma_alloc(STM_DMA_INDEX(STM_DMA_CHANNEL_ADC1)); + ao_cmd_register(&ao_adc_cmds[0]); + + ao_adc_ready = 1; } 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 { \ diff --git a/src/stm/ao_led.c b/src/stm/ao_led.c index d649f3d7..ee313b6f 100644 --- a/src/stm/ao_led.c +++ b/src/stm/ao_led.c @@ -22,25 +22,28 @@ __pdata uint16_t ao_led_enable; void ao_led_on(uint16_t colors) { - LED_PORT.odr |= (colors & ao_led_enable); + LED_PORT->bsrr = (colors & ao_led_enable); } void ao_led_off(uint16_t colors) { - LED_PORT.odr &= ~(colors & ao_led_enable); + LED_PORT->bsrr = (uint32_t) (colors & ao_led_enable) << 16; } void ao_led_set(uint16_t colors) { - LED_PORT.odr = (LED_PORT.odr & ~(ao_led_enable)) | (colors & ao_led_enable); + uint16_t on = colors & ao_led_enable; + uint16_t off = ~colors & ao_led_enable; + + LED_PORT->bsrr = off << 16 | on; } void ao_led_toggle(uint16_t colors) { - LED_PORT.odr ^= (colors & ao_led_enable); + LED_PORT->odr ^= (colors & ao_led_enable); } void @@ -58,11 +61,11 @@ ao_led_init(uint16_t enable) stm_rcc.ahbenr |= (1 << LED_PORT_ENABLE); ao_led_enable = enable; - LED_PORT.odr &= ~enable; + LED_PORT->odr &= ~enable; for (bit = 0; bit < 16; bit++) { if (enable & (1 << bit)) { - stm_moder_set(&LED_PORT, bit, STM_MODER_OUTPUT); - stm_otyper_set(&LED_PORT, bit, STM_OTYPER_PUSH_PULL); + stm_moder_set(LED_PORT, bit, STM_MODER_OUTPUT); + stm_otyper_set(LED_PORT, bit, STM_OTYPER_PUSH_PULL); } } } |