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)
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)
#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)
#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)
#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)
#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
* 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;
_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;
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);
}
_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;
* 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;
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");
}
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);
}
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();
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);
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);
}
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();
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;
* 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);
/* 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);
}
#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
#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)
#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
};
#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
* 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))
*/
#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)
* 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)
*/
#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)
#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_ */
#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)
};
#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))
#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);
#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;
}
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 { \
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
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);
}
}
}