From 393a5e929b530d9ee4f78cd01faa4dd90c95fe3a Mon Sep 17 00:00:00 2001 From: Bdale Garbee Date: Fri, 12 Oct 2018 23:32:57 -0600 Subject: altos: first cut at easymega v2.0 support .. nothing working yet --- src/easymega-v2.0/Makefile | 139 ++++++++++++ src/easymega-v2.0/ao_easymega.c | 97 +++++++++ src/easymega-v2.0/ao_pins.h | 351 +++++++++++++++++++++++++++++++ src/easymega-v2.0/flash-loader/Makefile | 8 + src/easymega-v2.0/flash-loader/ao_pins.h | 35 +++ 5 files changed, 630 insertions(+) create mode 100644 src/easymega-v2.0/Makefile create mode 100644 src/easymega-v2.0/ao_easymega.c create mode 100644 src/easymega-v2.0/ao_pins.h create mode 100644 src/easymega-v2.0/flash-loader/Makefile create mode 100644 src/easymega-v2.0/flash-loader/ao_pins.h (limited to 'src/easymega-v2.0') diff --git a/src/easymega-v2.0/Makefile b/src/easymega-v2.0/Makefile new file mode 100644 index 00000000..9d490d0f --- /dev/null +++ b/src/easymega-v2.0/Makefile @@ -0,0 +1,139 @@ +# +# AltOS build +# +# + +include ../stm/Makefile.defs + +INC = \ + ao.h \ + ao_arch.h \ + ao_arch_funcs.h \ + ao_boot.h \ + ao_companion.h \ + ao_data.h \ + ao_sample.h \ + ao_pins.h \ + altitude-pa.h \ + ao_kalman.h \ + ao_product.h \ + ao_ms5607.h \ + ao_mpu9250.h \ + ao_profile.h \ + ao_task.h \ + ao_whiten.h \ + ao_sample_profile.h \ + ao_quaternion.h \ + math.h \ + ao_mpu.h \ + stm32l.h \ + math.h \ + Makefile + +# +# Common AltOS sources +# + +#PROFILE=ao_profile.c +#PROFILE_DEF=-DAO_PROFILE=1 + +#SAMPLE_PROFILE=ao_sample_profile.c \ +# ao_sample_profile_timer.c +#SAMPLE_PROFILE_DEF=-DHAS_SAMPLE_PROFILE=1 + +#STACK_GUARD=ao_mpu_stm.c +#STACK_GUARD_DEF=-DHAS_STACK_GUARD=1 + +MATH_SRC=\ + ef_acos.c \ + ef_sqrt.c \ + ef_rem_pio2.c \ + kf_cos.c \ + kf_sin.c \ + kf_rem_pio2.c \ + sf_copysign.c \ + sf_cos.c \ + sf_fabs.c \ + sf_floor.c \ + sf_scalbn.c \ + sf_sin.c \ + ef_log.c + +ALTOS_SRC = \ + ao_boot_chain.c \ + ao_interrupt.c \ + ao_product.c \ + ao_romconfig.c \ + ao_cmd.c \ + ao_config.c \ + ao_task.c \ + ao_led.c \ + ao_stdio.c \ + ao_panic.c \ + ao_timer.c \ + ao_mutex.c \ + ao_ignite.c \ + ao_freq.c \ + ao_dma_stm.c \ + ao_spi_stm.c \ + ao_data.c \ + ao_ms5607.c \ + ao_mpu9250.c \ + ao_adc_stm.c \ + ao_beep_stm.c \ + ao_eeprom_stm.c \ + ao_storage.c \ + ao_m25.c \ + ao_usb_stm.c \ + ao_exti_stm.c \ + ao_report.c \ + ao_i2c_stm.c \ + ao_convert_pa.c \ + ao_convert_volt.c \ + ao_log.c \ + ao_log_mega.c \ + ao_sample.c \ + ao_kalman.c \ + ao_flight.c \ + ao_companion.c \ + ao_pyro.c \ + $(MATH_SRC) \ + $(PROFILE) \ + $(SAMPLE_PROFILE) \ + $(STACK_GUARD) + +PRODUCT=EasyMega-v2.0 +PRODUCT_DEF=-DEASYMEGA +IDPRODUCT=0x0028 + +CFLAGS = $(PRODUCT_DEF) $(STM_CFLAGS) $(PROFILE_DEF) $(SAMPLE_PROFILE_DEF) $(STACK_GUARD_DEF) -Os -g + +PROGNAME=easymega-v1.0 +PROG=$(PROGNAME)-$(VERSION).elf +HEX=$(PROGNAME)-$(VERSION).ihx + +SRC=$(ALTOS_SRC) ao_easymega.c +OBJ=$(SRC:.c=.o) + +all: $(PROG) $(HEX) + +$(PROG): Makefile $(OBJ) altos.ld + $(call quiet,CC) $(LDFLAGS) $(CFLAGS) -o $(PROG) $(OBJ) $(LIBS) + +../altitude-pa.h: make-altitude-pa + nickle $< > $@ + +$(OBJ): $(INC) + +ao_product.h: ao-make-product.5c ../Version + $(call quiet,NICKLE,$<) $< -m altusmetrum.org -i $(IDPRODUCT) -p $(PRODUCT) -v $(VERSION) > $@ + +distclean: clean + +clean: + rm -f *.o $(PROGNAME)-*.elf $(PROGNAME)-*.ihx + rm -f ao_product.h + +install: + +uninstall: diff --git a/src/easymega-v2.0/ao_easymega.c b/src/easymega-v2.0/ao_easymega.c new file mode 100644 index 00000000..9848c367 --- /dev/null +++ b/src/easymega-v2.0/ao_easymega.c @@ -0,0 +1,97 @@ +/* + * Copyright © 2014 Bdale Garbee + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#if HAS_SAMPLE_PROFILE +#include +#endif +#include +#if HAS_STACK_GUARD +#include +#endif + +int +main(void) +{ + ao_clock_init(); + +#if HAS_STACK_GUARD + ao_mpu_init(); +#endif + + ao_task_init(); + ao_led_init(LEDS_AVAILABLE); + ao_led_on(LEDS_AVAILABLE); + ao_timer_init(); + + ao_i2c_init(); + ao_spi_init(); + ao_dma_init(); + ao_exti_init(); + + ao_adc_init(); +#if HAS_BEEP + ao_beep_init(); +#endif + ao_cmd_init(); + +#if HAS_MS5607 + ao_ms5607_init(); +#endif +#if HAS_HMC5883 + ao_hmc5883_init(); +#endif +#if HAS_MPU6000 + ao_mpu6000_init(); +#endif +#if HAS_MMA655X + ao_mma655x_init(); +#endif + + ao_eeprom_init(); + ao_storage_init(); + + ao_flight_init(); + ao_log_init(); + ao_report_init(); + + ao_usb_init(); + ao_igniter_init(); + ao_companion_init(); + ao_pyro_init(); + + ao_config_init(); +#if AO_PROFILE + ao_profile_init(); +#endif +#if HAS_SAMPLE_PROFILE + ao_sample_profile_init(); +#endif + + ao_led_off(LEDS_AVAILABLE); + ao_start_scheduler(); + return 0; +} diff --git a/src/easymega-v2.0/ao_pins.h b/src/easymega-v2.0/ao_pins.h new file mode 100644 index 00000000..aff06cdd --- /dev/null +++ b/src/easymega-v2.0/ao_pins.h @@ -0,0 +1,351 @@ +/* + * Copyright © 2014 Bdale Garbee + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +#ifndef _AO_PINS_H_ +#define _AO_PINS_H_ + +#define HAS_TASK_QUEUE 1 + +/* 16MHz High speed external crystal */ +#define AO_HSE 16000000 + +/* PLLVCO = 96MHz (so that USB will work) */ +#define AO_PLLMUL 12 +#define AO_RCC_CFGR_PLLMUL (STM_RCC_CFGR_PLLMUL_12) + +/* SYSCLK = 32MHz (no need to go faster than CPU) */ +#define AO_PLLDIV 3 +#define AO_RCC_CFGR_PLLDIV (STM_RCC_CFGR_PLLDIV_3) + +/* HCLK = 32MHz (CPU clock) */ +#define AO_AHB_PRESCALER 1 +#define AO_RCC_CFGR_HPRE_DIV STM_RCC_CFGR_HPRE_DIV_1 + +/* Run APB1 at 16MHz (HCLK/2) */ +#define AO_APB1_PRESCALER 2 +#define AO_RCC_CFGR_PPRE1_DIV STM_RCC_CFGR_PPRE2_DIV_2 + +/* Run APB2 at 16MHz (HCLK/2) */ +#define AO_APB2_PRESCALER 2 +#define AO_RCC_CFGR_PPRE2_DIV STM_RCC_CFGR_PPRE2_DIV_2 + +#define HAS_SERIAL_1 0 +#define USE_SERIAL_1_STDIN 0 +#define SERIAL_1_PB6_PB7 0 +#define SERIAL_1_PA9_PA10 0 + +#define HAS_SERIAL_2 0 +#define USE_SERIAL_2_STDIN 0 +#define SERIAL_2_PA2_PA3 0 +#define SERIAL_2_PD5_PD6 0 + +#define HAS_SERIAL_3 0 +#define USE_SERIAL_3_STDIN 0 +#define SERIAL_3_PB10_PB11 0 +#define SERIAL_3_PC10_PC11 0 +#define SERIAL_3_PD8_PD9 0 + +#define ao_gps_getchar ao_serial1_getchar +#define ao_gps_putchar ao_serial1_putchar +#define ao_gps_set_speed ao_serial1_set_speed +#define ao_gps_fifo (ao_stm_usart1.rx_fifo) + +#define AO_CONFIG_DEFAULT_FLIGHT_LOG_MAX (1024 * 1024) +#define AO_CONFIG_MAX_SIZE 1024 +#define LOG_ERASE_MARK 0x55 +#define LOG_MAX_ERASE 128 +#define AO_LOG_FORMAT AO_LOG_FORMAT_TELEMEGA + +#define HAS_EEPROM 1 +#define USE_INTERNAL_FLASH 0 +#define USE_EEPROM_CONFIG 1 +#define USE_STORAGE_CONFIG 0 +#define HAS_USB 1 +#define HAS_BEEP 1 +#define HAS_BATTERY_REPORT 1 +#define HAS_RADIO 0 +#define HAS_TELEMETRY 0 +#define HAS_APRS 0 +#define HAS_COMPANION 1 + +#define HAS_SPI_1 1 +#define SPI_1_PA5_PA6_PA7 1 /* Barometer */ +#define SPI_1_PB3_PB4_PB5 1 /* Accelerometer, Gyro */ +#define SPI_1_PE13_PE14_PE15 0 +#define SPI_1_OSPEEDR STM_OSPEEDR_10MHz + +#define HAS_SPI_2 1 +#define SPI_2_PB13_PB14_PB15 1 /* Flash, Companion */ +#define SPI_2_PD1_PD3_PD4 0 +#define SPI_2_OSPEEDR STM_OSPEEDR_10MHz + +#define SPI_2_PORT (&stm_gpiob) +#define SPI_2_SCK_PIN 13 +#define SPI_2_MISO_PIN 14 +#define SPI_2_MOSI_PIN 15 + +#define HAS_I2C_1 1 +#define I2C_1_PB8_PB9 1 + +#define HAS_I2C_2 0 +#define I2C_2_PB10_PB11 0 + +#define PACKET_HAS_SLAVE 0 +#define PACKET_HAS_MASTER 0 + +#define LOW_LEVEL_DEBUG 0 + +#define LED_PORT_ENABLE STM_RCC_AHBENR_GPIOAEN +#define LED_PORT (&stm_gpioa) +#define LED_PIN_RED 9 +#define LED_PIN_GREEN 10 +#define AO_LED_RED (1 << LED_PIN_RED) +#define AO_LED_GREEN (1 << LED_PIN_GREEN) + +#define LEDS_AVAILABLE (AO_LED_RED | AO_LED_GREEN) + +#define HAS_GPS 0 +#define HAS_FLIGHT 1 +#define HAS_ADC 1 +#define HAS_ADC_TEMP 1 +#define HAS_LOG 1 + +/* + * Igniter + */ + +#define HAS_IGNITE 1 +#define HAS_IGNITE_REPORT 1 + +#define AO_SENSE_PYRO(p,n) ((p)->adc.sense[n]) +#define AO_SENSE_DROGUE(p) ((p)->adc.sense[4]) +#define AO_SENSE_MAIN(p) ((p)->adc.sense[5]) +#define AO_IGNITER_CLOSED 400 +#define AO_IGNITER_OPEN 60 + +/* Pyro A */ +#define AO_PYRO_PORT_0 (&stm_gpioa) +#define AO_PYRO_PIN_0 15 + +/* Pyro B */ +#define AO_PYRO_PORT_1 (&stm_gpioc) +#define AO_PYRO_PIN_1 10 + +/* Pyro C */ +#define AO_PYRO_PORT_2 (&stm_gpiob) +#define AO_PYRO_PIN_2 11 + +/* Pyro D */ +#define AO_PYRO_PORT_3 (&stm_gpiob) +#define AO_PYRO_PIN_3 10 + +/* Drogue */ +#define AO_IGNITER_DROGUE_PORT (&stm_gpioa) +#define AO_IGNITER_DROGUE_PIN 0 + +/* Main */ +#define AO_IGNITER_MAIN_PORT (&stm_gpioa) +#define AO_IGNITER_MAIN_PIN 1 + +/* Number of general purpose pyro channels available */ +#define AO_PYRO_NUM 4 + +#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 + +struct ao_adc { + int16_t sense[AO_ADC_NUM_SENSE]; + int16_t v_batt; + int16_t v_pbatt; + int16_t temp; +}; + +#define AO_ADC_DUMP(p) \ + printf("tick: %5u A: %5d B: %5d C: %5d D: %5d drogue: %5d main: %5d batt: %5d pbatt: %5d temp: %5d\n", \ + (p)->tick, \ + (p)->adc.sense[0], (p)->adc.sense[1], (p)->adc.sense[2], \ + (p)->adc.sense[3], (p)->adc.sense[4], (p)->adc.sense[5], \ + (p)->adc.v_batt, (p)->adc.v_pbatt, (p)->adc.temp) + +#define AO_ADC_SENSE_A 14 +#define AO_ADC_SENSE_A_PORT (&stm_gpioc) +#define AO_ADC_SENSE_A_PIN 4 + +#define AO_ADC_SENSE_B 15 +#define AO_ADC_SENSE_B_PORT (&stm_gpioc) +#define AO_ADC_SENSE_B_PIN 5 + +#define AO_ADC_SENSE_C 13 +#define AO_ADC_SENSE_C_PORT (&stm_gpioc) +#define AO_ADC_SENSE_C_PIN 3 + +#define AO_ADC_SENSE_D 12 +#define AO_ADC_SENSE_D_PORT (&stm_gpioc) +#define AO_ADC_SENSE_D_PIN 2 + +#define AO_ADC_SENSE_DROGUE 11 +#define AO_ADC_SENSE_DROGUE_PORT (&stm_gpioc) +#define AO_ADC_SENSE_DROGUE_PIN 1 + +#define AO_ADC_SENSE_MAIN 10 +#define AO_ADC_SENSE_MAIN_PORT (&stm_gpioc) +#define AO_ADC_SENSE_MAIN_PIN 0 + +#define AO_ADC_V_BATT 8 +#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_PIN 1 + +#define AO_ADC_TEMP 16 + +#define AO_ADC_RCC_AHBENR ((1 << STM_RCC_AHBENR_GPIOAEN) | \ + (1 << STM_RCC_AHBENR_GPIOEEN) | \ + (1 << STM_RCC_AHBENR_GPIOBEN)) + +#define AO_NUM_ADC_PIN (AO_ADC_NUM_SENSE + 2) + +#define AO_ADC_PIN0_PORT AO_ADC_SENSE_A_PORT +#define AO_ADC_PIN0_PIN AO_ADC_SENSE_A_PIN +#define AO_ADC_PIN1_PORT AO_ADC_SENSE_B_PORT +#define AO_ADC_PIN1_PIN AO_ADC_SENSE_B_PIN +#define AO_ADC_PIN2_PORT AO_ADC_SENSE_C_PORT +#define AO_ADC_PIN2_PIN AO_ADC_SENSE_C_PIN +#define AO_ADC_PIN3_PORT AO_ADC_SENSE_D_PORT +#define AO_ADC_PIN3_PIN AO_ADC_SENSE_D_PIN +#define AO_ADC_PIN4_PORT AO_ADC_SENSE_DROGUE_PORT +#define AO_ADC_PIN4_PIN AO_ADC_SENSE_DROGUE_PIN +#define AO_ADC_PIN5_PORT AO_ADC_SENSE_MAIN_PORT +#define AO_ADC_PIN5_PIN AO_ADC_SENSE_MAIN_PIN +#define AO_ADC_PIN6_PORT AO_ADC_V_BATT_PORT +#define AO_ADC_PIN6_PIN AO_ADC_V_BATT_PIN +#define AO_ADC_PIN7_PORT AO_ADC_V_PBATT_PORT +#define AO_ADC_PIN7_PIN AO_ADC_V_PBATT_PIN + +#define AO_NUM_ADC (AO_ADC_NUM_SENSE + 3) + +#define AO_ADC_SQ1 AO_ADC_SENSE_A +#define AO_ADC_SQ2 AO_ADC_SENSE_B +#define AO_ADC_SQ3 AO_ADC_SENSE_C +#define AO_ADC_SQ4 AO_ADC_SENSE_D +#define AO_ADC_SQ5 AO_ADC_SENSE_DROGUE +#define AO_ADC_SQ6 AO_ADC_SENSE_MAIN +#define AO_ADC_SQ7 AO_ADC_V_BATT +#define AO_ADC_SQ8 AO_ADC_V_PBATT +#define AO_ADC_SQ9 AO_ADC_TEMP + +/* + * Voltage divider on ADC battery sampler + */ +#define AO_BATTERY_DIV_PLUS 56 /* 5.6k */ +#define AO_BATTERY_DIV_MINUS 100 /* 10k */ + +/* + * Voltage divider on ADC igniter samplers + */ +#define AO_IGNITE_DIV_PLUS 100 /* 100k */ +#define AO_IGNITE_DIV_MINUS 27 /* 27k */ + +/* + * ADC reference in decivolts + */ +#define AO_ADC_REFERENCE_DV 33 + +/* + * Pressure sensor settings + */ +#define HAS_MS5607 1 +#define HAS_MS5611 0 +#define AO_MS5607_PRIVATE_PINS 1 +#define AO_MS5607_CS_PORT (&stm_gpioa) +#define AO_MS5607_CS_PIN 3 +#define AO_MS5607_CS_MASK (1 << AO_MS5607_CS_PIN) +#define AO_MS5607_MISO_PORT (&stm_gpioa) +#define AO_MS5607_MISO_PIN 6 +#define AO_MS5607_MISO_MASK (1 << AO_MS5607_MISO_PIN) +#define AO_MS5607_SPI_INDEX AO_SPI_1_PA5_PA6_PA7 + +/* + * SPI Flash memory + */ + +#define M25_MAX_CHIPS 1 +#define AO_M25_SPI_CS_PORT (&stm_gpiob) +#define AO_M25_SPI_CS_PIN 12 +#define AO_M25_SPI_CS_MASK (1 << AO_M25_SPI_CS_PIN) +#define AO_M25_SPI_BUS AO_SPI_2_PB13_PB14_PB15 + +/* + * mpu9250 + */ + +#define HAS_MPU9250 1 +#define AO_MPU9250_INT_PORT (&stm_gpioe) +#define AO_MPU9250_INT_PIN 0 +#define AO_MPU9250_SPI_BUS AO_SPI_1_PE13_PE14_PE15 +#define AO_MPU9250_SPI_CS_PORT (&stm_gpiod) +#define AO_MPU9250_SPI_CS_PIN 2 +#define HAS_IMU 1 + +/* + * mma655x + */ + +#define HAS_MMA655X 0 +#define AO_MMA655X_INVERT 0 +#define AO_MMA655X_SPI_INDEX AO_SPI_1_PB3_PB4_PB5 +#define AO_MMA655X_CS_PORT (&stm_gpioc) +#define AO_MMA655X_CS_PIN 12 + +#define NUM_CMDS 16 + +/* + * Companion + */ + +#define AO_COMPANION_CS_PORT (&stm_gpiob) +#define AO_COMPANION_CS_PIN (6) +#define AO_COMPANION_SPI_BUS AO_SPI_2_PB13_PB14_PB15 + +/* + * Monitor + */ + +#define HAS_MONITOR 0 +#define LEGACY_MONITOR 0 +#define HAS_MONITOR_PUT 0 +#define AO_MONITOR_LED 0 +#define HAS_RSSI 0 + +/* + * Profiling Viterbi decoding + */ + +#ifndef AO_PROFILE +#define AO_PROFILE 0 +#endif + +#endif /* _AO_PINS_H_ */ diff --git a/src/easymega-v2.0/flash-loader/Makefile b/src/easymega-v2.0/flash-loader/Makefile new file mode 100644 index 00000000..a5594006 --- /dev/null +++ b/src/easymega-v2.0/flash-loader/Makefile @@ -0,0 +1,8 @@ +# +# AltOS flash loader build +# +# + +TOPDIR=../.. +HARDWARE=easymega-v2.0 +include $(TOPDIR)/stm/Makefile-flash.defs diff --git a/src/easymega-v2.0/flash-loader/ao_pins.h b/src/easymega-v2.0/flash-loader/ao_pins.h new file mode 100644 index 00000000..324b0eb9 --- /dev/null +++ b/src/easymega-v2.0/flash-loader/ao_pins.h @@ -0,0 +1,35 @@ +/* + * Copyright © 2018 Bdale Garbee + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +#ifndef _AO_PINS_H_ +#define _AO_PINS_H_ + +/* External crystal at 16MHz */ +#define AO_HSE 16000000 + +#include + +/* Companion port cs_companion0 PB6 */ + +#define AO_BOOT_PIN 1 +#define AO_BOOT_APPLICATION_GPIO stm_gpiob +#define AO_BOOT_APPLICATION_PIN 6 +#define AO_BOOT_APPLICATION_VALUE 1 +#define AO_BOOT_APPLICATION_MODE AO_EXTI_MODE_PULL_UP + +#endif /* _AO_PINS_H_ */ -- cgit v1.2.3 From dbc52686c6d9808275c35e0c9c987cbbd9f7859d Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 13 Oct 2018 13:42:34 -0700 Subject: altos/stm: Make beeper driver support all possible tim234 configs And update all users to be explicit about the desired config. Signed-off-by: Keith Packard --- src/easymega-v1.0/ao_pins.h | 4 + src/easymega-v2.0/ao_pins.h | 4 + src/stm/ao_beep_stm.c | 166 +++++++++++++++++++------------------- src/stm/stm32l.h | 15 ++-- src/teleballoon-v2.0/ao_pins.h | 3 + src/telefireeight-v1.0/ao_pins.h | 4 + src/telefireone-v1.0/ao_pins.h | 1 + src/telefiretwo-v0.2/ao_pins.h | 1 + src/telelco-v0.2-cc1200/ao_pins.h | 4 + src/telelco-v0.2/ao_pins.h | 4 + src/telelco-v0.3/ao_pins.h | 4 + src/telelco-v2.0/ao_pins.h | 4 + src/telelcotwo-v0.1/ao_pins.h | 3 + src/telemega-v0.1/ao_pins.h | 4 + src/telemega-v1.0/ao_pins.h | 4 + src/telemega-v2.0/ao_pins.h | 4 + src/telemega-v3.0/ao_pins.h | 4 + src/telemetrum-v2.0/ao_pins.h | 3 + src/telemetrum-v3.0/ao_pins.h | 3 + src/telemini-v3.0/ao_pins.h | 4 +- 20 files changed, 150 insertions(+), 93 deletions(-) (limited to 'src/easymega-v2.0') diff --git a/src/easymega-v1.0/ao_pins.h b/src/easymega-v1.0/ao_pins.h index e7382e4b..bfa777c6 100644 --- a/src/easymega-v1.0/ao_pins.h +++ b/src/easymega-v1.0/ao_pins.h @@ -77,6 +77,10 @@ #define USE_STORAGE_CONFIG 0 #define HAS_USB 1 #define HAS_BEEP 1 +#define BEEPER_TIMER 3 +#define BEEPER_CHANNEL 1 +#define BEEPER_PORT (&stm_gpioc) +#define BEEPER_PIN 6 #define HAS_BATTERY_REPORT 1 #define HAS_RADIO 0 #define HAS_TELEMETRY 0 diff --git a/src/easymega-v2.0/ao_pins.h b/src/easymega-v2.0/ao_pins.h index aff06cdd..508c043c 100644 --- a/src/easymega-v2.0/ao_pins.h +++ b/src/easymega-v2.0/ao_pins.h @@ -77,6 +77,10 @@ #define USE_STORAGE_CONFIG 0 #define HAS_USB 1 #define HAS_BEEP 1 +#define BEEPER_TIMER 2 +#define BEEPER_CHANNEL 3 +#define BEEPER_PORT (&stm_gpioa) +#define BEEPER_PIN 2 #define HAS_BATTERY_REPORT 1 #define HAS_RADIO 0 #define HAS_TELEMETRY 0 diff --git a/src/stm/ao_beep_stm.c b/src/stm/ao_beep_stm.c index f9fa14c2..2746d7f8 100644 --- a/src/stm/ao_beep_stm.c +++ b/src/stm/ao_beep_stm.c @@ -18,37 +18,59 @@ #include "ao.h" -#ifndef BEEPER_CHANNEL -#define BEEPER_CHANNEL 1 +#if BEEPER_TIMER == 2 +#define stm_beeper stm_tim2 +#define RCC_BEEPER STM_RCC_APB1ENR_TIM2EN +#define BEEPER_AFR STM_AFR_AF1 +#elif BEEPER_TIMER == 3 +#define stm_beeper stm_tim3 +#define RCC_BEEPER STM_RCC_APB1ENR_TIM3EN +#define BEEPER_AFR STM_AFR_AF2 +#elif BEEPER_TIMER == 4 +#define stm_beeper stm_tim4 +#define RCC_BEEPER STM_RCC_APB1ENR_TIM4EN +#define BEEPER_AFR STM_AFR_AF2 +#else +#error BEEPER_TIMER must be 2, 3 or 4 #endif void ao_beep(uint8_t beep) { if (beep == 0) { - stm_tim3.cr1 = 0; - stm_rcc.apb1enr &= ~(1 << STM_RCC_APB1ENR_TIM3EN); + stm_beeper.cr1 = 0; + stm_rcc.apb1enr &= ~(1 << RCC_BEEPER); } else { - stm_rcc.apb1enr |= (1 << STM_RCC_APB1ENR_TIM3EN); + stm_rcc.apb1enr |= (1 << RCC_BEEPER); - stm_tim3.cr2 = ((0 << STM_TIM234_CR2_TI1S) | + stm_beeper.cr2 = ((0 << STM_TIM234_CR2_TI1S) | (STM_TIM234_CR2_MMS_RESET << STM_TIM234_CR2_MMS) | (0 << STM_TIM234_CR2_CCDS)); /* Set prescaler to match cc1111 clocks */ - stm_tim3.psc = AO_TIM23467_CLK / 750000; + stm_beeper.psc = AO_TIM23467_CLK / 750000; /* 1. Select the counter clock (internal, external, prescaler). * * Setting SMCR to zero means use the internal clock */ - stm_tim3.smcr = 0; + stm_beeper.smcr = 0; /* 2. Write the desired data in the TIMx_ARR and TIMx_CCRx registers. */ - stm_tim3.arr = beep; - stm_tim3.ccr1 = beep; + stm_beeper.arr = beep; +#if BEEPER_CHANNEL == 1 + stm_beeper.ccr1 = beep; +#elif BEEPER_CHANNEL == 2 + stm_beeper.ccr2 = beep; +#elif BEEPER_CHANNEL == 3 + stm_beeper.ccr3 = beep; +#elif BEEPER_CHANNEL == 4 + stm_beeper.ccr4 = beep; +#else +#error invalid BEEPER_CHANNEL +#endif /* 3. Set the CCxIE and/or CCxDE bits if an interrupt and/or a * DMA request is to be generated. @@ -61,63 +83,56 @@ ao_beep(uint8_t beep) * is enabled and active high. */ -#if BEEPER_CHANNEL == 1 - stm_tim3.ccmr1 = ((0 << STM_TIM234_CCMR1_OC2CE) | - (STM_TIM234_CCMR1_OC2M_FROZEN << STM_TIM234_CCMR1_OC2M) | - (0 << STM_TIM234_CCMR1_OC2PE) | - (0 << STM_TIM234_CCMR1_OC2FE) | - (STM_TIM234_CCMR1_CC2S_OUTPUT << STM_TIM234_CCMR1_CC2S) | - - (0 << STM_TIM234_CCMR1_OC1CE) | - (STM_TIM234_CCMR1_OC1M_TOGGLE << STM_TIM234_CCMR1_OC1M) | - (0 << STM_TIM234_CCMR1_OC1PE) | - (0 << STM_TIM234_CCMR1_OC1FE) | - (STM_TIM234_CCMR1_CC1S_OUTPUT << STM_TIM234_CCMR1_CC1S)); - - stm_tim3.ccer = ((0 << STM_TIM234_CCER_CC4NP) | - (0 << STM_TIM234_CCER_CC4P) | - (0 << STM_TIM234_CCER_CC4E) | - (0 << STM_TIM234_CCER_CC3NP) | - (0 << STM_TIM234_CCER_CC3P) | - (0 << STM_TIM234_CCER_CC3E) | - (0 << STM_TIM234_CCER_CC2NP) | - (0 << STM_TIM234_CCER_CC2P) | - (0 << STM_TIM234_CCER_CC2E) | - (0 << STM_TIM234_CCER_CC1NP) | - (0 << STM_TIM234_CCER_CC1P) | - (1 << STM_TIM234_CCER_CC1E)); +#define OC1M (BEEPER_CHANNEL == 1 ? STM_TIM234_CCMR1_OC1M_TOGGLE : STM_TIM234_CCMR1_OC1M_FROZEN) +#define OC2M (BEEPER_CHANNEL == 2 ? STM_TIM234_CCMR1_OC2M_TOGGLE : STM_TIM234_CCMR1_OC2M_FROZEN) +#define OC3M (BEEPER_CHANNEL == 3 ? STM_TIM234_CCMR2_OC3M_TOGGLE : STM_TIM234_CCMR2_OC3M_FROZEN) +#define OC4M (BEEPER_CHANNEL == 4 ? STM_TIM234_CCMR2_OC4M_TOGGLE : STM_TIM234_CCMR2_OC4M_FROZEN) + +#define CCER(n) (BEEPER_CHANNEL == (n) ? 1 : 0) + +#if BEEPER_CHANNEL == 1 || BEEPER_CHANNEL == 2 + stm_beeper.ccmr1 = ((0 << STM_TIM234_CCMR1_OC2CE) | + (OC2M << STM_TIM234_CCMR1_OC2M) | + (0 << STM_TIM234_CCMR1_OC2PE) | + (0 << STM_TIM234_CCMR1_OC2FE) | + (STM_TIM234_CCMR1_CC2S_OUTPUT << STM_TIM234_CCMR1_CC2S) | + + (0 << STM_TIM234_CCMR1_OC1CE) | + (OC1M << STM_TIM234_CCMR1_OC1M) | + (0 << STM_TIM234_CCMR1_OC1PE) | + (0 << STM_TIM234_CCMR1_OC1FE) | + (STM_TIM234_CCMR1_CC1S_OUTPUT << STM_TIM234_CCMR1_CC1S)); +#elif BEEPER_CHANNEL == 3 || BEEPER_CHANNEL == 4 + stm_beeper.ccmr2 = ((0 << STM_TIM234_CCMR2_OC4CE) | + (OC4M << STM_TIM234_CCMR2_OC4M) | + (0 << STM_TIM234_CCMR2_OC4PE) | + (0 << STM_TIM234_CCMR2_OC4FE) | + (STM_TIM234_CCMR2_CC4S_OUTPUT << STM_TIM234_CCMR2_CC4S) | + + (0 << STM_TIM234_CCMR2_OC3CE) | + (OC3M << STM_TIM234_CCMR2_OC3M) | + (0 << STM_TIM234_CCMR2_OC3PE) | + (0 << STM_TIM234_CCMR2_OC3FE) | + (STM_TIM234_CCMR2_CC3S_OUTPUT << STM_TIM234_CCMR2_CC3S)); +#else +#error invalid BEEPER_CHANNEL #endif -#if BEEPER_CHANNEL == 4 - stm_tim3.ccmr2 = ((0 << STM_TIM234_CCMR2_OC4CE) | - (STM_TIM234_CCMR2_OC4M_TOGGLE << STM_TIM234_CCMR2_OC4M) | - (0 << STM_TIM234_CCMR2_OC4PE) | - (0 << STM_TIM234_CCMR2_OC4FE) | - (STM_TIM234_CCMR2_CC4S_OUTPUT << STM_TIM234_CCMR2_CC4S) | - - (0 << STM_TIM234_CCMR2_OC3CE) | - (STM_TIM234_CCMR2_OC3M_FROZEN << STM_TIM234_CCMR2_OC3M) | - (0 << STM_TIM234_CCMR2_OC3PE) | - (0 << STM_TIM234_CCMR2_OC3FE) | - (STM_TIM234_CCMR2_CC3S_OUTPUT << STM_TIM234_CCMR2_CC3S)); - - stm_tim3.ccer = ((0 << STM_TIM234_CCER_CC4NP) | - (0 << STM_TIM234_CCER_CC4P) | - (1 << STM_TIM234_CCER_CC4E) | - (0 << STM_TIM234_CCER_CC3NP) | - (0 << STM_TIM234_CCER_CC3P) | - (0 << STM_TIM234_CCER_CC3E) | - (0 << STM_TIM234_CCER_CC2NP) | - (0 << STM_TIM234_CCER_CC2P) | - (0 << STM_TIM234_CCER_CC2E) | - (0 << STM_TIM234_CCER_CC1NP) | - (0 << STM_TIM234_CCER_CC1P) | - (0 << STM_TIM234_CCER_CC1E)); -#endif - + stm_beeper.ccer = ((0 << STM_TIM234_CCER_CC4NP) | + (0 << STM_TIM234_CCER_CC4P) | + (CCER(4) << STM_TIM234_CCER_CC4E) | + (0 << STM_TIM234_CCER_CC3NP) | + (0 << STM_TIM234_CCER_CC3P) | + (CCER(3) << STM_TIM234_CCER_CC3E) | + (0 << STM_TIM234_CCER_CC2NP) | + (0 << STM_TIM234_CCER_CC2P) | + (CCER(2) << STM_TIM234_CCER_CC2E) | + (0 << STM_TIM234_CCER_CC1NP) | + (0 << STM_TIM234_CCER_CC1P) | + (CCER(1) << STM_TIM234_CCER_CC1E)); /* 5. Enable the counter by setting the CEN bit in the TIMx_CR1 register. */ - stm_tim3.cr1 = ((STM_TIM234_CR1_CKD_1 << STM_TIM234_CR1_CKD) | + stm_beeper.cr1 = ((STM_TIM234_CR1_CKD_1 << STM_TIM234_CR1_CKD) | (0 << STM_TIM234_CR1_ARPE) | (STM_TIM234_CR1_CMS_EDGE << STM_TIM234_CR1_CMS) | (0 << STM_TIM234_CR1_DIR) | @@ -127,12 +142,12 @@ ao_beep(uint8_t beep) (1 << STM_TIM234_CR1_CEN)); /* Update the values */ - stm_tim3.egr = (1 << STM_TIM234_EGR_UG); + stm_beeper.egr = (1 << STM_TIM234_EGR_UG); } } void -ao_beep_for(uint8_t beep, uint16_t ticks) +ao_beep_for(uint8_t beep, uint16_t ticks) { ao_beep(beep); ao_delay(ticks); @@ -142,24 +157,9 @@ ao_beep_for(uint8_t beep, uint16_t ticks) void ao_beep_init(void) { -#if BEEPER_CHANNEL == 1 - - /* Our beeper is on PC6, which is hooked to TIM3_CH1. - */ - stm_rcc.ahbenr |= (1 << STM_RCC_AHBENR_GPIOCEN); - - stm_afr_set(&stm_gpioc, 6, STM_AFR_AF2); -#endif -#if BEEPER_CHANNEL == 4 - - /* Our beeper is on PB1, which is hooked to TIM3_CH4. - */ - stm_rcc.ahbenr |= (1 << STM_RCC_AHBENR_GPIOBEN); - - stm_afr_set(&stm_gpiob, 1, STM_AFR_AF2); -#endif + ao_enable_port(BEEPER_PORT); + stm_afr_set(BEEPER_PORT, BEEPER_PIN, BEEPER_AFR); /* Leave the timer off until requested */ - - stm_rcc.apb1enr &= ~(1 << STM_RCC_APB1ENR_TIM3EN); + stm_rcc.apb1enr &= ~(1 << RCC_BEEPER); } diff --git a/src/stm/stm32l.h b/src/stm/stm32l.h index 1da817e7..0109ec81 100644 --- a/src/stm/stm32l.h +++ b/src/stm/stm32l.h @@ -241,15 +241,14 @@ stm_gpio_get_all(struct stm_gpio *gpio) { * ao_enable_gpio macro will expand into a huge pile of code * as the compiler won't do correct constant folding and * dead-code elimination + */ - extern struct stm_gpio stm_gpioa; - extern struct stm_gpio stm_gpiob; - extern struct stm_gpio stm_gpioc; - extern struct stm_gpio stm_gpiod; - extern struct stm_gpio stm_gpioe; - extern struct stm_gpio stm_gpioh; - -*/ +extern struct stm_gpio stm_gpioa; +extern struct stm_gpio stm_gpiob; +extern struct stm_gpio stm_gpioc; +extern struct stm_gpio stm_gpiod; +extern struct stm_gpio stm_gpioe; +extern struct stm_gpio stm_gpioh; #define stm_gpioh (*((struct stm_gpio *) 0x40021400)) #define stm_gpioe (*((struct stm_gpio *) 0x40021000)) diff --git a/src/teleballoon-v2.0/ao_pins.h b/src/teleballoon-v2.0/ao_pins.h index 4f27bad6..cb0ec838 100644 --- a/src/teleballoon-v2.0/ao_pins.h +++ b/src/teleballoon-v2.0/ao_pins.h @@ -74,6 +74,9 @@ #define HAS_BEEP 1 #define HAS_BATTERY_REPORT 1 #define BEEPER_CHANNEL 4 +#define BEEPER_TIMER 3 +#define BEEPER_PORT (&stm_gpiob) +#define BEEPER_PIN 1 #define HAS_RADIO 1 #define HAS_TELEMETRY 1 #define HAS_APRS 1 diff --git a/src/telefireeight-v1.0/ao_pins.h b/src/telefireeight-v1.0/ao_pins.h index ef533b36..c15e06bf 100644 --- a/src/telefireeight-v1.0/ao_pins.h +++ b/src/telefireeight-v1.0/ao_pins.h @@ -25,6 +25,10 @@ #define HAS_FLIGHT 0 #define HAS_USB 1 #define HAS_BEEP 0 +#define BEEPER_TIMER 3 +#define BEEPER_CHANNEL 1 +#define BEEPER_PORT (&stm_gpioc) +#define BEEPER_PIN 6 #define HAS_GPS 0 #define HAS_SERIAL_1 0 #define HAS_ADC 1 diff --git a/src/telefireone-v1.0/ao_pins.h b/src/telefireone-v1.0/ao_pins.h index d36d9d82..15b158ef 100644 --- a/src/telefireone-v1.0/ao_pins.h +++ b/src/telefireone-v1.0/ao_pins.h @@ -27,6 +27,7 @@ #define HAS_USB 1 #define HAS_BEEP 1 #define BEEPER_CHANNEL 4 +#define BEEPER_TIMER 3 #define HAS_GPS 0 #define HAS_SERIAL_1 0 #define HAS_ADC 1 diff --git a/src/telefiretwo-v0.2/ao_pins.h b/src/telefiretwo-v0.2/ao_pins.h index 469e9937..01faace2 100644 --- a/src/telefiretwo-v0.2/ao_pins.h +++ b/src/telefiretwo-v0.2/ao_pins.h @@ -27,6 +27,7 @@ #define HAS_USB 1 #define HAS_BEEP 1 #define BEEPER_CHANNEL 4 +#define BEEPER_TIMER 3 #define HAS_GPS 0 #define HAS_SERIAL_1 0 #define HAS_ADC 1 diff --git a/src/telelco-v0.2-cc1200/ao_pins.h b/src/telelco-v0.2-cc1200/ao_pins.h index bc325e06..f3850ebd 100644 --- a/src/telelco-v0.2-cc1200/ao_pins.h +++ b/src/telelco-v0.2-cc1200/ao_pins.h @@ -50,6 +50,10 @@ #define USE_STORAGE_CONFIG 0 #define HAS_USB 1 #define HAS_BEEP 1 +#define BEEPER_TIMER 3 +#define BEEPER_CHANNEL 1 +#define BEEPER_PORT (&stm_gpioc) +#define BEEPER_PIN 6 #define HAS_RADIO 1 #define HAS_RADIO_RATE 1 #define HAS_TELEMETRY 0 diff --git a/src/telelco-v0.2/ao_pins.h b/src/telelco-v0.2/ao_pins.h index f0da4fe4..3d06a647 100644 --- a/src/telelco-v0.2/ao_pins.h +++ b/src/telelco-v0.2/ao_pins.h @@ -48,6 +48,10 @@ #define USE_STORAGE_CONFIG 0 #define HAS_USB 1 #define HAS_BEEP 1 +#define BEEPER_TIMER 3 +#define BEEPER_CHANNEL 1 +#define BEEPER_PORT (&stm_gpioc) +#define BEEPER_PIN 6 #define HAS_RADIO 1 #define HAS_RADIO_RATE 1 #define HAS_TELEMETRY 0 diff --git a/src/telelco-v0.3/ao_pins.h b/src/telelco-v0.3/ao_pins.h index 6023739c..c806268f 100644 --- a/src/telelco-v0.3/ao_pins.h +++ b/src/telelco-v0.3/ao_pins.h @@ -50,6 +50,10 @@ #define USE_STORAGE_CONFIG 0 #define HAS_USB 1 #define HAS_BEEP 1 +#define BEEPER_TIMER 3 +#define BEEPER_CHANNEL 1 +#define BEEPER_PORT (&stm_gpioc) +#define BEEPER_PIN 6 #define HAS_RADIO 1 #define HAS_RADIO_RATE 1 #define HAS_TELEMETRY 0 diff --git a/src/telelco-v2.0/ao_pins.h b/src/telelco-v2.0/ao_pins.h index ea709c1d..e0663314 100644 --- a/src/telelco-v2.0/ao_pins.h +++ b/src/telelco-v2.0/ao_pins.h @@ -50,6 +50,10 @@ #define USE_STORAGE_CONFIG 0 #define HAS_USB 1 #define HAS_BEEP 1 +#define BEEPER_TIMER 3 +#define BEEPER_CHANNEL 1 +#define BEEPER_PORT (&stm_gpioc) +#define BEEPER_PIN 6 #define HAS_RADIO 1 #define HAS_RADIO_RATE 1 #define HAS_TELEMETRY 0 diff --git a/src/telelcotwo-v0.1/ao_pins.h b/src/telelcotwo-v0.1/ao_pins.h index 1941e03d..3ef88c74 100644 --- a/src/telelcotwo-v0.1/ao_pins.h +++ b/src/telelcotwo-v0.1/ao_pins.h @@ -51,6 +51,9 @@ #define HAS_USB 1 #define HAS_BEEP 1 #define BEEPER_CHANNEL 4 +#define BEEPER_TIMER 3 +#define BEEPER_PORT (&stm_gpiob) +#define BEEPER_PIN 1 #define HAS_RADIO 1 #define HAS_RADIO_RATE 1 #define HAS_TELEMETRY 0 diff --git a/src/telemega-v0.1/ao_pins.h b/src/telemega-v0.1/ao_pins.h index 64535c30..0208fafa 100644 --- a/src/telemega-v0.1/ao_pins.h +++ b/src/telemega-v0.1/ao_pins.h @@ -77,6 +77,10 @@ #define USE_STORAGE_CONFIG 0 #define HAS_USB 1 #define HAS_BEEP 1 +#define BEEPER_TIMER 3 +#define BEEPER_CHANNEL 1 +#define BEEPER_PORT (&stm_gpioc) +#define BEEPER_PIN 6 #define HAS_BATTERY_REPORT 1 #define HAS_RADIO 1 #define HAS_TELEMETRY 1 diff --git a/src/telemega-v1.0/ao_pins.h b/src/telemega-v1.0/ao_pins.h index 354da6a4..a154225e 100644 --- a/src/telemega-v1.0/ao_pins.h +++ b/src/telemega-v1.0/ao_pins.h @@ -77,6 +77,10 @@ #define USE_STORAGE_CONFIG 0 #define HAS_USB 1 #define HAS_BEEP 1 +#define BEEPER_TIMER 3 +#define BEEPER_CHANNEL 1 +#define BEEPER_PORT (&stm_gpioc) +#define BEEPER_PIN 6 #define HAS_BATTERY_REPORT 1 #define HAS_RADIO 1 #define HAS_TELEMETRY 1 diff --git a/src/telemega-v2.0/ao_pins.h b/src/telemega-v2.0/ao_pins.h index 46207884..ba302c74 100644 --- a/src/telemega-v2.0/ao_pins.h +++ b/src/telemega-v2.0/ao_pins.h @@ -77,6 +77,10 @@ #define USE_STORAGE_CONFIG 0 #define HAS_USB 1 #define HAS_BEEP 1 +#define BEEPER_TIMER 3 +#define BEEPER_CHANNEL 1 +#define BEEPER_PORT (&stm_gpioc) +#define BEEPER_PIN 6 #define HAS_BATTERY_REPORT 1 #define HAS_RADIO 1 #define HAS_TELEMETRY 1 diff --git a/src/telemega-v3.0/ao_pins.h b/src/telemega-v3.0/ao_pins.h index ddcd0eb9..ce223907 100644 --- a/src/telemega-v3.0/ao_pins.h +++ b/src/telemega-v3.0/ao_pins.h @@ -77,6 +77,10 @@ #define USE_STORAGE_CONFIG 0 #define HAS_USB 1 #define HAS_BEEP 1 +#define BEEPER_TIMER 3 +#define BEEPER_CHANNEL 1 +#define BEEPER_PORT (&stm_gpioc) +#define BEEPER_PIN 6 #define HAS_BATTERY_REPORT 1 #define HAS_RADIO 1 #define HAS_TELEMETRY 1 diff --git a/src/telemetrum-v2.0/ao_pins.h b/src/telemetrum-v2.0/ao_pins.h index 47f6dd2a..e8c97ff4 100644 --- a/src/telemetrum-v2.0/ao_pins.h +++ b/src/telemetrum-v2.0/ao_pins.h @@ -74,6 +74,9 @@ #define HAS_BEEP 1 #define HAS_BATTERY_REPORT 1 #define BEEPER_CHANNEL 4 +#define BEEPER_TIMER 3 +#define BEEPER_PORT (&stm_gpiob) +#define BEEPER_PIN 1 #define HAS_RADIO 1 #define HAS_TELEMETRY 1 #define HAS_APRS 1 diff --git a/src/telemetrum-v3.0/ao_pins.h b/src/telemetrum-v3.0/ao_pins.h index a8043bba..f4ccc9f3 100644 --- a/src/telemetrum-v3.0/ao_pins.h +++ b/src/telemetrum-v3.0/ao_pins.h @@ -74,6 +74,9 @@ #define HAS_BEEP 1 #define HAS_BATTERY_REPORT 1 #define BEEPER_CHANNEL 4 +#define BEEPER_TIMER 3 +#define BEEPER_PORT (&stm_gpiob) +#define BEEPER_PIN 1 #define HAS_RADIO 1 #define HAS_TELEMETRY 1 #define HAS_APRS 1 diff --git a/src/telemini-v3.0/ao_pins.h b/src/telemini-v3.0/ao_pins.h index 546d91e0..d91b1d21 100644 --- a/src/telemini-v3.0/ao_pins.h +++ b/src/telemini-v3.0/ao_pins.h @@ -74,9 +74,9 @@ #define AO_RECOVERY_VALUE 0 #define AO_RECOVERY_MODE AO_EXTI_MODE_PULL_UP -/* Beeper is on Tim1 CH3 */ +/* Beeper is on Tim3 CH4 */ #define BEEPER_CHANNEL 4 -#define BEEPER_TIMER 2 +#define BEEPER_TIMER 3 #define BEEPER_PORT (&stm_gpioa) #define BEEPER_PIN 3 -- cgit v1.2.3 From 6fdc392ef1b624c06e26e7a053c3579435c455d5 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 13 Oct 2018 09:46:01 -0700 Subject: altos/easymega-v2.0: Change binary to easymega-v2.0 instead of easymega-v1.0 Signed-off-by: Keith Packard --- src/easymega-v2.0/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/easymega-v2.0') diff --git a/src/easymega-v2.0/Makefile b/src/easymega-v2.0/Makefile index 9d490d0f..ece4e9bb 100644 --- a/src/easymega-v2.0/Makefile +++ b/src/easymega-v2.0/Makefile @@ -108,7 +108,7 @@ IDPRODUCT=0x0028 CFLAGS = $(PRODUCT_DEF) $(STM_CFLAGS) $(PROFILE_DEF) $(SAMPLE_PROFILE_DEF) $(STACK_GUARD_DEF) -Os -g -PROGNAME=easymega-v1.0 +PROGNAME=easymega-v2.0 PROG=$(PROGNAME)-$(VERSION).elf HEX=$(PROGNAME)-$(VERSION).ihx -- cgit v1.2.3 From f49763bf4a6cd8b2a47abfbec7ef3d8c8c029b8f Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 13 Oct 2018 09:43:25 -0700 Subject: altos/easymega-v2.0: Add adxl375, replace mpu6000 with 9250 [v2] Should reflect current hardware design now. v2: Use SPI mode 3 for ADXL375 Invert ADXL375 values Signed-off-by: Keith Packard --- src/easymega-v2.0/Makefile | 22 +++--------------- src/easymega-v2.0/ao_easymega.c | 23 +++++-------------- src/easymega-v2.0/ao_pins.h | 49 ++++++++++++++++++++--------------------- 3 files changed, 33 insertions(+), 61 deletions(-) (limited to 'src/easymega-v2.0') diff --git a/src/easymega-v2.0/Makefile b/src/easymega-v2.0/Makefile index ece4e9bb..bfe8a849 100644 --- a/src/easymega-v2.0/Makefile +++ b/src/easymega-v2.0/Makefile @@ -19,15 +19,14 @@ INC = \ ao_product.h \ ao_ms5607.h \ ao_mpu9250.h \ + ao_adxl375.h \ ao_profile.h \ ao_task.h \ ao_whiten.h \ ao_sample_profile.h \ ao_quaternion.h \ - math.h \ ao_mpu.h \ stm32l.h \ - math.h \ Makefile # @@ -44,21 +43,6 @@ INC = \ #STACK_GUARD=ao_mpu_stm.c #STACK_GUARD_DEF=-DHAS_STACK_GUARD=1 -MATH_SRC=\ - ef_acos.c \ - ef_sqrt.c \ - ef_rem_pio2.c \ - kf_cos.c \ - kf_sin.c \ - kf_rem_pio2.c \ - sf_copysign.c \ - sf_cos.c \ - sf_fabs.c \ - sf_floor.c \ - sf_scalbn.c \ - sf_sin.c \ - ef_log.c - ALTOS_SRC = \ ao_boot_chain.c \ ao_interrupt.c \ @@ -67,7 +51,7 @@ ALTOS_SRC = \ ao_cmd.c \ ao_config.c \ ao_task.c \ - ao_led.c \ + ao_led_stm.c \ ao_stdio.c \ ao_panic.c \ ao_timer.c \ @@ -79,6 +63,7 @@ ALTOS_SRC = \ ao_data.c \ ao_ms5607.c \ ao_mpu9250.c \ + ao_adxl375.c \ ao_adc_stm.c \ ao_beep_stm.c \ ao_eeprom_stm.c \ @@ -97,7 +82,6 @@ ALTOS_SRC = \ ao_flight.c \ ao_companion.c \ ao_pyro.c \ - $(MATH_SRC) \ $(PROFILE) \ $(SAMPLE_PROFILE) \ $(STACK_GUARD) diff --git a/src/easymega-v2.0/ao_easymega.c b/src/easymega-v2.0/ao_easymega.c index 9848c367..bb2e7cfd 100644 --- a/src/easymega-v2.0/ao_easymega.c +++ b/src/easymega-v2.0/ao_easymega.c @@ -17,9 +17,9 @@ */ #include -#include -#include -#include +#include +#include +#include #include #include #include @@ -43,7 +43,7 @@ main(void) #endif ao_task_init(); - ao_led_init(LEDS_AVAILABLE); + ao_led_init(); ao_led_on(LEDS_AVAILABLE); ao_timer_init(); @@ -53,23 +53,12 @@ main(void) ao_exti_init(); ao_adc_init(); -#if HAS_BEEP ao_beep_init(); -#endif ao_cmd_init(); -#if HAS_MS5607 ao_ms5607_init(); -#endif -#if HAS_HMC5883 - ao_hmc5883_init(); -#endif -#if HAS_MPU6000 - ao_mpu6000_init(); -#endif -#if HAS_MMA655X - ao_mma655x_init(); -#endif + ao_mpu9250_init(); + ao_adxl375_init(); ao_eeprom_init(); ao_storage_init(); diff --git a/src/easymega-v2.0/ao_pins.h b/src/easymega-v2.0/ao_pins.h index 508c043c..6217b5d2 100644 --- a/src/easymega-v2.0/ao_pins.h +++ b/src/easymega-v2.0/ao_pins.h @@ -25,8 +25,8 @@ #define AO_HSE 16000000 /* PLLVCO = 96MHz (so that USB will work) */ -#define AO_PLLMUL 12 -#define AO_RCC_CFGR_PLLMUL (STM_RCC_CFGR_PLLMUL_12) +#define AO_PLLMUL 6 +#define AO_RCC_CFGR_PLLMUL (STM_RCC_CFGR_PLLMUL_6) /* SYSCLK = 32MHz (no need to go faster than CPU) */ #define AO_PLLDIV 3 @@ -89,20 +89,15 @@ #define HAS_SPI_1 1 #define SPI_1_PA5_PA6_PA7 1 /* Barometer */ -#define SPI_1_PB3_PB4_PB5 1 /* Accelerometer, Gyro */ +#define SPI_1_PB3_PB4_PB5 1 /* Accelerometer */ #define SPI_1_PE13_PE14_PE15 0 #define SPI_1_OSPEEDR STM_OSPEEDR_10MHz #define HAS_SPI_2 1 -#define SPI_2_PB13_PB14_PB15 1 /* Flash, Companion */ +#define SPI_2_PB13_PB14_PB15 1 /* Flash, IMU, Companion */ #define SPI_2_PD1_PD3_PD4 0 #define SPI_2_OSPEEDR STM_OSPEEDR_10MHz -#define SPI_2_PORT (&stm_gpiob) -#define SPI_2_SCK_PIN 13 -#define SPI_2_MISO_PIN 14 -#define SPI_2_MOSI_PIN 15 - #define HAS_I2C_1 1 #define I2C_1_PB8_PB9 1 @@ -169,9 +164,6 @@ /* Number of general purpose pyro channels available */ #define AO_PYRO_NUM 4 -#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 */ @@ -307,22 +299,29 @@ struct ao_adc { */ #define HAS_MPU9250 1 -#define AO_MPU9250_INT_PORT (&stm_gpioe) -#define AO_MPU9250_INT_PIN 0 -#define AO_MPU9250_SPI_BUS AO_SPI_1_PE13_PE14_PE15 -#define AO_MPU9250_SPI_CS_PORT (&stm_gpiod) -#define AO_MPU9250_SPI_CS_PIN 2 +#define AO_MPU9250_INT_PORT (&stm_gpioc) +#define AO_MPU9250_INT_PIN 15 +#define AO_MPU9250_SPI_BUS (AO_SPI_2_PB13_PB14_PB15 | AO_SPI_MODE_0) +#define AO_MPU9250_SPI_CS_PORT (&stm_gpioc) +#define AO_MPU9250_SPI_CS_PIN 13 #define HAS_IMU 1 -/* - * mma655x - */ +/* ADXL375 */ + +#define HAS_ADXL375 1 +#define AO_ADXL375_SPI_INDEX (AO_SPI_1_PB3_PB4_PB5 | AO_SPI_MODE_3) +#define AO_ADXL375_CS_PORT (&stm_gpioc) +#define AO_ADXL375_CS_PIN 12 +#define AO_ADXL375_SPI_SPEED AO_SPI_SPEED_4MHz + +#define AO_ADXL375_INT1_PORT (&stm_gpiob) +#define AO_ADXL375_INT1_PIN 8 + +#define AO_ADXL375_INT2_PORT (&stm_gpiob) +#define AO_ADXL375_INT2_PIN 9 -#define HAS_MMA655X 0 -#define AO_MMA655X_INVERT 0 -#define AO_MMA655X_SPI_INDEX AO_SPI_1_PB3_PB4_PB5 -#define AO_MMA655X_CS_PORT (&stm_gpioc) -#define AO_MMA655X_CS_PIN 12 +#define AO_ADXL375_AXIS x +#define AO_ADXL375_INVERT 1 #define NUM_CMDS 16 -- cgit v1.2.3