From: Keith Packard Date: Wed, 27 Jun 2012 06:01:58 +0000 (-0700) Subject: altos: Clean up usage of port parameters X-Git-Tag: 1.0.9.6~32 X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=commitdiff_plain;h=03dc80d15a2f8fe9d7340351226dadd8bc3cfdb9 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 --- diff --git a/src/cc1111/ao_arch_funcs.h b/src/cc1111/ao_arch_funcs.h index d9f5955a..728f1f76 100644 --- a/src/cc1111/ao_arch_funcs.h +++ b/src/cc1111/ao_arch_funcs.h @@ -31,14 +31,14 @@ extern __xdata uint8_t ao_spi_mutex; ao_mutex_put(&ao_spi_mutex); \ } while (0) -#define ao_spi_get_bit(bit,bus) do { \ - ao_mutex_get(&ao_spi_mutex); \ - (bit) = 0; \ +#define ao_spi_get_bit(reg,bit,pin,bus) do { \ + ao_mutex_get(&ao_spi_mutex); \ + pin = 0; \ } while (0) -#define ao_spi_put_bit(bit,bus) do { \ - (bit) = 1; \ - ao_mutex_put(&ao_spi_mutex); \ +#define ao_spi_put_bit(reg,bit,pin,bus) do { \ + pin = 1; \ + ao_mutex_put(&ao_spi_mutex); \ } while (0) @@ -65,3 +65,15 @@ ao_spi_init(void); SPI_CS_DIR |= mask; \ SPI_CS_SEL &= ~mask; \ } while (0) + +#define cc1111_enable_output(port,dir,sel,mask,v) do { \ + port = port & ~(mask) | v; \ + dir |= mask; \ + sel &= ~mask; \ +} while (0) + +#define disable_unreachable _Pragma("disable_warning 126") + +#define token_paster(x,y) x ## y +#define token_evaluator(x,y) token_paster(x,y) +#define ao_enable_output(port,pin,v) cc1111_enable_output(port,token_evaluator(port,DIR), token_evaluator(port,SEL), 1 << pin, 1 << v) diff --git a/src/cc1111/ao_pins.h b/src/cc1111/ao_pins.h index 0923e75d..e28a7b65 100644 --- a/src/cc1111/ao_pins.h +++ b/src/cc1111/ao_pins.h @@ -41,8 +41,9 @@ #define HAS_COMPANION 1 #define COMPANION_CS_ON_P1 1 - #define COMPANION_CS_MASK 0x4 /* CS1 is P1_2 */ - #define COMPANION_CS P1_2 + #define AO_COMPANION_CS_PORT P1 + #define AO_COMPANION_CS_PIN 2 + #define AO_COMPANION_CS P1_2 #define AO_LED_RED 1 #define LEDS_AVAILABLE (AO_LED_RED) @@ -72,9 +73,9 @@ #define PACKET_HAS_SLAVE 1 #define HAS_COMPANION 1 - #define COMPANION_CS_ON_P1 1 - #define COMPANION_CS_MASK 0x4 /* CS1 is P1_2 */ - #define COMPANION_CS P1_2 + #define AO_COMPANION_CS_PORT P1 + #define AO_COMPANION_CS_PIN 2 + #define AO_COMPANION_CS P1_2 #define AO_LED_RED 1 #define LEDS_AVAILABLE (AO_LED_RED) @@ -108,9 +109,9 @@ #define PACKET_HAS_SLAVE 1 #define HAS_COMPANION 1 - #define COMPANION_CS_ON_P1 1 - #define COMPANION_CS_MASK 0x4 /* CS1 is P1_2 */ - #define COMPANION_CS P1_2 + #define AO_COMPANION_CS_PORT P1 + #define AO_COMPANION_CS_PIN 2 + #define AO_COMPANION_CS P1_2 #define AO_LED_RED 1 #define LEDS_AVAILABLE (AO_LED_RED) @@ -527,21 +528,31 @@ #endif /* HAS_ADC */ #if IGNITE_ON_P2 +#define AO_IGNITER_PORT P2 +#define AO_IGNITER_DROGUE_PORT AO_IGNITER_PORT #define AO_IGNITER_DROGUE P2_3 #define AO_IGNITER_MAIN P2_4 #define AO_IGNITER_DIR P2DIR #define AO_IGNITER_DROGUE_BIT (1 << 3) #define AO_IGNITER_MAIN_BIT (1 << 4) +#define AO_IGNITER_DROGUE_PIN 3 +#define AO_IGNITER_MAIN_PIN 4 #endif #if IGNITE_ON_P0 +#define AO_IGNITER_PORT P0 #define AO_IGNITER_DROGUE P0_5 #define AO_IGNITER_MAIN P0_4 #define AO_IGNITER_DIR P0DIR #define AO_IGNITER_DROGUE_BIT (1 << 5) #define AO_IGNITER_MAIN_BIT (1 << 4) +#define AO_IGNITER_DROGUE_PIN 5 +#define AO_IGNITER_MAIN_PIN 4 #endif +#define AO_IGNITER_DROGUE_PORT AO_IGNITER_PORT +#define AO_IGNITER_MAIN_PORT AO_IGNITER_PORT + /* test these values with real igniters */ #define AO_IGNITER_OPEN 1000 #define AO_IGNITER_CLOSED 7000 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 +#include + +#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); } diff --git a/src/megametrum-v0.1/ao_pins.h b/src/megametrum-v0.1/ao_pins.h index 9d9113c8..f5bd3e0d 100644 --- a/src/megametrum-v0.1/ao_pins.h +++ b/src/megametrum-v0.1/ao_pins.h @@ -76,7 +76,7 @@ #define HAS_SPI_2 1 #define SPI_2_PB13_PB14_PB15 1 #define SPI_2_PD1_PD3_PD4 0 -#define SPI_2_GPIO stm_gpiob +#define SPI_2_GPIO (&stm_gpiob) #define SPI_2_SCK 13 #define SPI_2_MISO 14 #define SPI_2_MOSI 15 @@ -87,12 +87,13 @@ #define HAS_I2C_2 1 #define I2C_2_PB10_PB11 1 -#define PACKET_HAS_SLAVE 0 +#define PACKET_HAS_SLAVE 1 +#define PACKET_HAS_MASTER 0 -#define LOW_LEVEL_DEBUG 1 +#define LOW_LEVEL_DEBUG 0 #define LED_PORT_ENABLE STM_RCC_AHBENR_GPIOCEN -#define LED_PORT stm_gpioc +#define LED_PORT (&stm_gpioc) #define LED_PIN_RED 8 #define LED_PIN_GREEN 9 #define AO_LED_RED (1 << LED_PIN_RED) @@ -107,6 +108,48 @@ #define HAS_ACCEL_REF 1 #define HAS_LOG 1 +/* + * Igniter + */ + +#define HAS_IGNITE 1 +#define HAS_IGNITE_REPORT 1 + +#define AO_SENSE_DROGUE(p) ((p)->adc.sense[0]) +#define AO_SENSE_MAIN(p) ((p)->adc.sense[1]) +#define AO_IGNITER_CLOSED 400 +#define AO_IGNITER_OPEN 60 + +#define AO_IGNITER_PORT_A (&stm_gpiod) +#define AO_IGNITER_PIN_A 6 + +#define AO_IGNITER_PORT_B (&stm_gpiod) +#define AO_IGNITER_PIN_B 7 + +#define AO_IGNITER_PORT_C (&stm_gpiob) +#define AO_IGNITER_PIN_C 5 + +#define AO_IGNITER_PORT_D (&stm_gpioe) +#define AO_IGNITER_PIN_D 4 + +#define AO_IGNITER_PORT_E (&stm_gpioe) +#define AO_IGNITER_PIN_E 6 + +#define AO_IGNITER_PORT_F (&stm_gpioe) +#define AO_IGNITER_PIN_F 5 + +#define AO_IGNITER_DROGUE_PORT AO_IGNITER_PORT_A +#define AO_IGNITER_DROGUE_PIN AO_IGNITER_PIN_A + +#define AO_IGNITER_MAIN_PORT AO_IGNITER_PORT_B +#define AO_IGNITER_MAIN_PIN AO_IGNITER_PIN_B + +#define AO_IGNITER_SET_DROGUE(v) stm_gpio_set(AO_IGNITER_DROGUE_PORT, AO_IGNITER_DROGUE_PIN, v) +#define AO_IGNITER_SET_MAIN(v) stm_gpio_set(AO_IGNITER_MAIN_PORT, AO_IGNITER_MAIN_PIN, v) + +/* + * ADC + */ #define AO_DATA_RING 32 #define AO_ADC_NUM_SENSE 6 @@ -120,43 +163,43 @@ struct ao_adc { }; #define AO_ADC_SENSE_A 0 -#define AO_ADC_SENSE_A_PORT stm_gpioa +#define AO_ADC_SENSE_A_PORT (&stm_gpioa) #define AO_ADC_SENSE_A_PIN 0 #define AO_ADC_SENSE_B 1 -#define AO_ADC_SENSE_B_PORT stm_gpioa +#define AO_ADC_SENSE_B_PORT (&stm_gpioa) #define AO_ADC_SENSE_B_PIN 1 #define AO_ADC_SENSE_C 2 -#define AO_ADC_SENSE_C_PORT stm_gpioa +#define AO_ADC_SENSE_C_PORT (&stm_gpioa) #define AO_ADC_SENSE_C_PIN 2 #define AO_ADC_SENSE_D 3 -#define AO_ADC_SENSE_D_PORT stm_gpioa +#define AO_ADC_SENSE_D_PORT (&stm_gpioa) #define AO_ADC_SENSE_D_PIN 3 #define AO_ADC_SENSE_E 4 -#define AO_ADC_SENSE_E_PORT stm_gpioa +#define AO_ADC_SENSE_E_PORT (&stm_gpioa) #define AO_ADC_SENSE_E_PIN 4 #define AO_ADC_SENSE_F 22 -#define AO_ADC_SENSE_F_PORT stm_gpioe +#define AO_ADC_SENSE_F_PORT (&stm_gpioe) #define AO_ADC_SENSE_F_PIN 7 #define AO_ADC_V_BATT 8 -#define AO_ADC_V_BATT_PORT stm_gpiob +#define AO_ADC_V_BATT_PORT (&stm_gpiob) #define AO_ADC_V_BATT_PIN 0 #define AO_ADC_V_PBATT 9 -#define AO_ADC_V_PBATT_PORT stm_gpiob +#define AO_ADC_V_PBATT_PORT (&stm_gpiob) #define AO_ADC_V_PBATT_PIN 1 #define AO_ADC_ACCEL_REF 10 -#define AO_ADC_ACCEL_REF_PORT stm_gpioc +#define AO_ADC_ACCEL_REF_PORT (&stm_gpioc) #define AO_ADC_ACCEL_REF_PIN 0 #define AO_ADC_ACCEL 11 -#define AO_ADC_ACCEL_PORT stm_gpioc +#define AO_ADC_ACCEL_PORT (&stm_gpioc) #define AO_ADC_ACCEL_PIN 1 #define AO_ADC_TEMP 16 @@ -207,10 +250,10 @@ struct ao_adc { * Pressure sensor settings */ #define HAS_MS5607 1 -#define AO_MS5607_CS_GPIO stm_gpioc +#define AO_MS5607_CS_GPIO (&stm_gpioc) #define AO_MS5607_CS 4 #define AO_MS5607_CS_MASK (1 << AO_MS5607_CS) -#define AO_MS5607_MISO_GPIO stm_gpioa +#define AO_MS5607_MISO_GPIO (&stm_gpioa) #define AO_MS5607_MISO 6 #define AO_MS5607_MISO_MASK (1 << AO_MS5607_MISO) #define AO_MS5607_SPI_INDEX (STM_SPI_INDEX(1)) @@ -220,7 +263,7 @@ struct ao_adc { */ #define M25_MAX_CHIPS 1 -#define AO_M25_SPI_CS_PORT stm_gpiod +#define AO_M25_SPI_CS_PORT (&stm_gpiod) #define AO_M25_SPI_CS_MASK (1 << 3) #define AO_M25_SPI_BUS STM_SPI_INDEX(2) @@ -228,21 +271,23 @@ struct ao_adc { * Radio (cc1120) */ -#define AO_CC1120_SPI_CS_PORT stm_gpioc +#define AO_FEC_DEBUG 1 +#define AO_CC1120_SPI_CS_PORT (&stm_gpioc) #define AO_CC1120_SPI_CS_PIN 5 #define AO_CC1120_SPI_BUS STM_SPI_INDEX(2) -#define AO_CC1120_INT_PORT stm_gpioc +#define AO_CC1120_INT_PORT (&stm_gpioc) #define AO_CC1120_INT_PIN 14 #define AO_CC1120_INT_GPIO 2 +#define HAS_BOOT_RADIO 1 /* * Mag sensor (hmc5883) */ #define HAS_HMC5883 1 -#define AO_HMC5883_INT_PORT stm_gpioc +#define AO_HMC5883_INT_PORT (&stm_gpioc) #define AO_HMC5883_INT_PIN 12 #define AO_HMC5883_I2C_INDEX STM_I2C_INDEX(1) @@ -251,7 +296,7 @@ struct ao_adc { */ #define HAS_MPU6000 1 -#define AO_MPU6000_INT_PORT stm_gpioc +#define AO_MPU6000_INT_PORT (&stm_gpioc) #define AO_MPU6000_INT_PIN 13 #define AO_MPU6000_I2C_INDEX STM_I2C_INDEX(1) @@ -259,4 +304,28 @@ struct ao_adc { #define NUM_CMDS 16 +/* + * Companion + */ + +#define AO_COMPANION_CS_PORT (&stm_gpiod) +#define AO_COMPANION_CS_PIN (0) +#define AO_COMPANION_SPI_BUS STM_SPI_INDEX(2) + +/* + * Monitor + */ + +#define HAS_MONITOR 0 +#define LEGACY_MONITOR 0 +#define HAS_MONITOR_PUT 1 +#define AO_MONITOR_LED 0 +#define HAS_RSSI 0 + +/* + * Profiling Viterbi decoding + */ + +#define AO_PROFILE 0 + #endif /* _AO_PINS_H_ */ diff --git a/src/stm-demo/ao_pins.h b/src/stm-demo/ao_pins.h index d02c071c..7e222122 100644 --- a/src/stm-demo/ao_pins.h +++ b/src/stm-demo/ao_pins.h @@ -70,7 +70,7 @@ #define LOW_LEVEL_DEBUG 1 #define LED_PORT_ENABLE STM_RCC_AHBENR_GPIOBEN -#define LED_PORT stm_gpiob +#define LED_PORT (&stm_gpiob) #define LED_PIN_GREEN 7 #define LED_PIN_BLUE 6 #define AO_LED_GREEN (1 << LED_PIN_GREEN) @@ -147,7 +147,7 @@ struct ao_adc { }; #define AO_ADC_IDD 4 -#define AO_ADC_PIN0_PORT stm_gpioa +#define AO_ADC_PIN0_PORT (&stm_gpioa) #define AO_ADC_PIN0_PIN 4 #define AO_ADC_RCC_AHBENR ((1 << STM_RCC_AHBENR_GPIOAEN)) 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<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); } } }