altos/telemega-v5.0: Fix config for MMC5983
authorKeith Packard <keithp@keithp.com>
Sun, 19 Sep 2021 05:45:33 +0000 (22:45 -0700)
committerKeith Packard <keithp@keithp.com>
Sun, 19 Sep 2021 06:17:41 +0000 (23:17 -0700)
SPI mode 3

Signed-off-by: Keith Packard <keithp@keithp.com>
src/telemega-v5.0/Makefile
src/telemega-v5.0/ao_pins.h
src/telemega-v5.0/ao_telemega.c

index 809573ba95b41d6eedf6a0b9a5a9de5812f60ad3..eeadb073442d2c0bfcb90528cc55235043d9a339 100644 (file)
@@ -46,6 +46,9 @@ INC = \
 #STACK_GUARD=ao_mpu_stm.c
 #STACK_GUARD_DEF=-DHAS_STACK_GUARD=1
 
+# Bit-bang MMC5983 chip needs this
+#      ao_i2c_bit.c
+
 ALTOS_SRC = \
        ao_boot_chain.c \
        ao_interrupt.c \
index 9d65684df490b29f6d33dc43a066bec7c031ce22..0c89ff6a5ecde57c53cd20dd99899e76800a0ba1 100644 (file)
 #define SPI_1_PE13_PE14_PE15   1       /* MPU6000 */
 #define SPI_1_OSPEEDR          STM_OSPEEDR_10MHz
 
+//#define MMC5983_I2C          1
+
 #define HAS_SPI_2              1
 #define SPI_2_PB13_PB14_PB15   1       /* Flash, Companion */
+#ifndef MMC5983_I2C
 #define SPI_2_PD1_PD3_PD4      1       /* MMC5983 */
+#endif
 #define SPI_2_OSPEEDR          STM_OSPEEDR_10MHz
 
 #define HAS_I2C_1              0
@@ -342,15 +346,28 @@ struct ao_adc {
 #define ao_data_pitch(packet)  (-(packet)->mpu6000.gyro_y)
 #define ao_data_yaw(packet)    ((packet)->mpu6000.gyro_z)
 
+/* Bit-banging i2c */
+#define AO_I2C_SCL_PORT                (&stm_gpiod)
+#define AO_I2C_SCL_PIN         1
+#define AO_I2C_SDA_PORT                (&stm_gpiod)
+#define AO_I2C_SDA_PIN         4
+
 /* MMC5983 */
 
 #define HAS_MMC5983            1
 #define AO_MMC5983_INT_PORT    (&stm_gpiod)
 #define AO_MMC5983_INT_PIN     5
-#define AO_MMC5983_SPI_INDEX   AO_SPI_2_PD1_PD3_PD4
+#define AO_MMC5983_SPI_CLK_PORT        (&stm_gpiod)
+#define AO_MMC5983_SPI_CLK_PIN 1
+#define AO_MMC5983_SPI_MISO_PORT       (&stm_gpiod)
+#define AO_MMC5983_SPI_MISO_PIN        3
+#define AO_MMC5983_SPI_MOSI_PORT       (&stm_gpiod)
+#define AO_MMC5983_SPI_MOSI_PIN        4
+#define AO_MMC5983_SPI_INDEX   (AO_SPI_2_PD1_PD3_PD4 | AO_SPI_MODE_3)
 #define AO_MMC5983_SPI_CS_PORT (&stm_gpioa)
 #define AO_MMC5983_SPI_CS_PIN  15
 
+
 #define ao_data_mag_along(packet)      ((packet)->mmc5983.x)
 #define ao_data_mag_across(packet)     ((packet)->mmc5983.y)
 #define ao_data_mag_through(packet)    ((packet)->mmc5983.z)
index 11ce9c5dc77467a944c452d7a2476e1492720def..4e85c390f852b5d517105bd958ff5a7356f0f615 100644 (file)
@@ -26,6 +26,7 @@
 #include <ao_companion.h>
 #include <ao_profile.h>
 #include <ao_eeprom.h>
+#include <ao_i2c_bit.h>
 #if HAS_SAMPLE_PROFILE
 #include <ao_sample_profile.h>
 #endif
@@ -51,6 +52,9 @@ main(void)
        ao_timer_init();
 
        ao_spi_init();
+#ifdef MMC5983_I2C
+       ao_i2c_bit_init();
+#endif
        ao_dma_init();
        ao_exti_init();