diff options
author | Travis Geiselbrecht <geist@foobox.com> | 2016-01-05 16:29:26 -0800 |
---|---|---|
committer | Travis Geiselbrecht <geist@foobox.com> | 2016-01-05 16:39:00 -0800 |
commit | 75a8ce0f63ac583304425d6fd253a00d4b0dad54 (patch) | |
tree | c5731d7e1890c54c6f097686ea269424bc7d96ae | |
parent | f2430462b6adc5ccabb85614b1d680ad85fba120 (diff) | |
parent | 94e182585445130a56ef98df9968d48878113644 (diff) | |
download | common-75a8ce0f63ac583304425d6fd253a00d4b0dad54.tar.gz |
[merge] merge dartuino sensor development branch
-rw-r--r-- | app/accelerometer/accelerometer.c | 54 | ||||
-rw-r--r-- | app/accelerometer/rules.mk | 10 | ||||
-rw-r--r-- | include/dev/accelerometer.h | 34 | ||||
-rw-r--r-- | target/dartuinoP0/include/target/bmi055.h | 150 | ||||
-rw-r--r-- | target/dartuinoP0/include/target/gpioconfig.h | 22 | ||||
-rw-r--r-- | target/dartuinoP0/include/target/sensor_bus.h | 38 | ||||
-rw-r--r-- | target/dartuinoP0/init.c | 11 | ||||
-rw-r--r-- | target/dartuinoP0/rules.mk | 4 | ||||
-rw-r--r-- | target/dartuinoP0/sensor_bus.c | 121 |
9 files changed, 443 insertions, 1 deletions
diff --git a/app/accelerometer/accelerometer.c b/app/accelerometer/accelerometer.c new file mode 100644 index 00000000..8ae3f73b --- /dev/null +++ b/app/accelerometer/accelerometer.c @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2008 Travis Geiselbrecht + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +#include <app.h> +#include <debug.h> +#include <stdio.h> +#include <dev/accelerometer.h> +#include <compiler.h> + + +#if defined(WITH_LIB_CONSOLE) +#include <lib/console.h> + +void read_xyz(void); + +STATIC_COMMAND_START +STATIC_COMMAND("read_xyz", "read xyz vectors", (console_cmd)&read_xyz) +STATIC_COMMAND_END(accelerometer); + +#endif + +void read_xyz(void) +{ + position_vector_t pos_vector; + acc_read_xyz(&pos_vector); + printf("X value = %f\n",pos_vector.x); + printf("Y value = %f\n",pos_vector.y); + printf("Z value = %f\n",pos_vector.z); + +} + +APP_START(accelerometer) + .flags = 0, +APP_END + diff --git a/app/accelerometer/rules.mk b/app/accelerometer/rules.mk new file mode 100644 index 00000000..2a717b68 --- /dev/null +++ b/app/accelerometer/rules.mk @@ -0,0 +1,10 @@ +LOCAL_DIR := $(GET_LOCAL_DIR) + +MODULE := $(LOCAL_DIR) + +MODULE_SRCS += \ + $(LOCAL_DIR)/accelerometer.c \ + +MODULE_ARM_OVERRIDE_SRCS := \ + +include make/module.mk diff --git a/include/dev/accelerometer.h b/include/dev/accelerometer.h new file mode 100644 index 00000000..343a68c3 --- /dev/null +++ b/include/dev/accelerometer.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2015 Eric Holland + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +#ifndef __DEV_ACCELEROMETER_H +#define __DEV_ACCELEROMETER_H +typedef struct +{ + double x; + double y; + double z; +} position_vector_t; + +status_t acc_read_xyz(position_vector_t * pos_vector); + +#endif diff --git a/target/dartuinoP0/include/target/bmi055.h b/target/dartuinoP0/include/target/bmi055.h new file mode 100644 index 00000000..7fd75ffe --- /dev/null +++ b/target/dartuinoP0/include/target/bmi055.h @@ -0,0 +1,150 @@ +/* + * Copyright (c) 2015 Eric Holland + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +#ifndef __SENSOR_BMI055_H +#define __SENSOR_BMI055_H + +#include <sys/types.h> + +#define BMI055_ADDRESS_READ(x) (x | 0x80) +#define BMI055_ADDERSS_WRITE(x) (x & 0x7F) + +/** +* definitions for accelerometer IC +*/ +#define BMI055_ACC_BGW_CHPID 0x00 +#define BMI055_ACC_ACCD_X_LSB 0X02 +#define BMI055_ACC_ACCD_X_MSB 0X03 +#define BMI055_ACC_ACCD_Y_LSB 0X04 +#define BMI055_ACC_ACCD_Y_MSB 0X05 +#define BMI055_ACC_ACCD_Z_LSB 0X06 +#define BMI055_ACC_ACCD_Z_MSB 0X07 +#define BMI055_ACC_ACCD_TEMP 0X08 +#define BMI055_ACC_INT_STATUS_0 0X09 +#define BMI055_ACC_INT_STATUS_1 0X0a +#define BMI055_ACC_INT_STATUS_2 0x0b +#define BMI055_ACC_INT_STATUS_3 0x0c +#define BMI055_ACC_FIFO_STATUS 0x0e +#define BMI055_ACC_PMU_RANGE 0x0f +#define BMI055_ACC_PMU_BW 0x10 +#define BMI055_ACC_PMU_LPW 0x11 +#define BMI055_ACC_PMU_LOW_POWER 0x12 +#define BMI055_ACC_ACCD_HBW 0x13 +#define BMI055_ACC_BGW_SOFTRESET 0x14 +#define BMI055_ACC_INT_EN_0 0x16 +#define BMI055_ACC_INT_EN_1 0x17 +#define BMI055_ACC_INT_EN_2 0x18 +#define BMI055_ACC_INT_MAP_0 0x19 +#define BMI055_ACC_INT_MAP_1 0x1A +#define BMI055_ACC_INT_MAP_2 0x1B +#define BMI055_ACC_INT_SRC 0x1E +#define BMI055_ACC_INT_OUT_CTRL 0x20 +#define BMI055_ACC_INT_RST_LATCH 0x21 +#define BMI055_ACC_INT_0 0x22 +#define BMI055_ACC_INT_1 0x23 +#define BMI055_ACC_INT_2 0x24 +#define BMI055_ACC_INT_3 0x25 +#define BMI055_ACC_INT_4 0x26 +#define BMI055_ACC_INT_5 0x27 +#define BMI055_ACC_INT_6 0x28 +#define BMI055_ACC_INT_7 0x29 +#define BMI055_ACC_INT_8 0x2a +#define BMI055_ACC_INT_9 0x2b +#define BMI055_ACC_INT_A 0x2c +#define BMI055_ACC_INT_B 0x2d +#define BMI055_ACC_INT_C 0x2e +#define BMI055_ACC_INT_D 0x2f +#define BMI055_ACC_FIFO_CONFIG_0 0x30 +#define BMI055_ACC_PMU_SELF_TEST 0x32 +#define BMI055_ACC_TRIM_NVM_CTRL 0x33 +#define BMI055_ACC_BGW_SPI3_WDT 0x34 +#define BMI055_ACC_OFC_CTRL 0x36 +#define BMI055_ACC_OFC_SETTING 0x37 +#define BMI055_ACC_OFC_OFFSET_X 0x38 +#define BMI055_ACC_OFC_OFFSET_Y 0x39 +#define BMI055_ACC_OFC_OFFSET_Z 0x3A +#define BMI055_ACC_TRIM_GP0 0x3B +#define BMI055_ACC_TRIM_GP1 0x3C +#define BMI055_ACC_FIFO_CONFIG_1 0x3E +#define BMI055_ACC_FIFO_DATA 0x3F + + +/** +* definitions for gyro IC +*/ +#define BMI055_GYRO_CHIP_ID 0x00 +#define BMI055_GYRO_RATE_X_LSB 0X02 +#define BMI055_GYRO_RATE_X_MSB 0X03 +#define BMI055_GYRO_RATE_Y_LSB 0X04 +#define BMI055_GYRO_RATE_Y_MSB 0X05 +#define BMI055_GYRO_RATE_Z_LSB 0X06 +#define BMI055_GYRO_RATE_Z_MSB 0X07 +#define BMI055_GYRO_INT_STATUS_0 0X09 +#define BMI055_GYRO_INT_STATUS_1 0X0a +#define BMI055_GYRO_INT_STATUS_2 0x0b +#define BMI055_GYRO_INT_STATUS_3 0x0c +#define BMI055_GYRO_FIFO_STATUS 0x0e +#define BMI055_GYRO_RANGE 0x0f +#define BMI055_GYRO_BW 0x10 +#define BMI055_GYRO_LPM1 0x11 +#define BMI055_GYRO_LPM2 0x12 +#define BMI055_GYRO_RATE_HBW 0x13 +#define BMI055_GYRO_BGW_SOFTRESET 0x14 +#define BMI055_GYRO_INT_EN_0 0x15 +#define BMI055_GYRO_INT_EN_1 0x16 +#define BMI055_GYRO_INT_MAP_0 0x17 +#define BMI055_GYRO_INT_MAP_1 0x18 +#define BMI055_GYRO_INT_MAP_2 0x19 +#define BMI055_GYRO_0X1A 0x1A +#define BMI055_GYRO_0X1B 0x1B +#define BMI055_GYRO_0X1C 0x1C +#define BMI055_GYRO_0X1E 0x1E +#define BMI055_GYRO_INT_RST_LATCH 0x21 +#define BMI055_GYRO_HIGH_TH_X 0x22 +#define BMI055_GYRO_HIGH_DUR_X 0x23 +#define BMI055_GYRO_HIGH_TH_Y 0x24 +#define BMI055_GYRO_HIGH_DUR_Y 0x25 +#define BMI055_GYRO_HIGH_TH_Z 0x26 +#define BMI055_GYRO_HIGH_DUR_Z 0x27 +#define BMI055_GYRO_SOC 0x31 +#define BMI055_GYRO_A_FOC 0x32 +#define BMI055_GYRO_TRIM_NVM_CTRL 0x33 +#define BMI055_GYRO_BGW_SPI3_WDT 0x34 +#define BMI055_GYRO_OFC1 0x36 +#define BMI055_GYRO_OFC2 0x37 +#define BMI055_GYRO_OFC3 0x38 +#define BMI055_GYRO_OFC4 0x39 +#define BMI055_GYRO_TRIM_GP0 0x3A +#define BMI055_GYRO_TRIM_GP1 0x3B +#define BMI055_GYRO_BIST 0x3C +#define BMI055_GYRO_FIFO_CONFIG_0 0x3D +#define BMI055_GYRO_FIFO_CONFIG_1 0x3E + + + + + + + + +#endif + diff --git a/target/dartuinoP0/include/target/gpioconfig.h b/target/dartuinoP0/include/target/gpioconfig.h index c07bb5f0..0a1a5cfc 100644 --- a/target/dartuinoP0/include/target/gpioconfig.h +++ b/target/dartuinoP0/include/target/gpioconfig.h @@ -24,6 +24,7 @@ #define __TARGET_GPIOCONFIG_H #include <platform/gpio.h> +#include <platform/stm32.h> #define GPIO_LED_ON GPIO_PIN_RESET #define GPIO_LED_OFF GPIO_PIN_SET @@ -68,4 +69,25 @@ #define GPIO_SW102 GPIO(GPIO_PORT_J, 14) #define GPIO_SW103 GPIO(GPIO_PORT_J, 15) +/** + * Definitions for sensor bus signals. Includes + * nrf51, accelerometer, and gyroscope + */ + +#define __HAL_SENSOR_BUS_GPIO_CLK_ENABLE() \ + __HAL_RCC_GPIOK_CLK_ENABLE(); \ + __HAL_RCC_GPIOF_CLK_ENABLE() + +#define GPIO_NRF_CS GPIO(GPIO_PORT_K, 0) +#define GPIO_NRF_INT GPIO(GPIO_PORT_K, 1) +#define GPIO_GYRO_nCS GPIO(GPIO_PORT_K, 4) +#define GPIO_GYRO_INT GPIO(GPIO_PORT_K, 5) +#define GPIO_ACC_nCS GPIO(GPIO_PORT_K, 2) +#define GPIO_ACC_INT GPIO(GPIO_PORT_K, 3) +#define GPIO_SPI5_SCK GPIO(GPIO_PORT_F, 7) +#define GPIO_SPI5_MISO GPIO(GPIO_PORT_F, 8) +#define GPIO_SPI5_MOSI GPIO(GPIO_PORT_F, 9) + + + #endif diff --git a/target/dartuinoP0/include/target/sensor_bus.h b/target/dartuinoP0/include/target/sensor_bus.h new file mode 100644 index 00000000..97b0a4c8 --- /dev/null +++ b/target/dartuinoP0/include/target/sensor_bus.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2015 Eric Holland + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +#ifndef __SENSOR_BUS_H +#define __SENSOR_BUS_H + +#include <sys/types.h> +#include <dev/accelerometer.h> + +status_t sensor_bus_init_early(void); + +void sensor_bus_init(void); + +status_t acc_read(uint8_t address, uint8_t *data); + +status_t acc_flush(uint8_t * tbuff, uint8_t * rbuff, uint8_t numbytes); + + +#endif diff --git a/target/dartuinoP0/init.c b/target/dartuinoP0/init.c index 6f04c3a0..0d3d08dd 100644 --- a/target/dartuinoP0/init.c +++ b/target/dartuinoP0/init.c @@ -28,15 +28,18 @@ #include <compiler.h> #include <dev/gpio.h> #include <dev/usb.h> +#include <dev/accelerometer.h> #include <platform/stm32.h> #include <platform/sdram.h> #include <platform/gpio.h> #include <platform/eth.h> #include <platform/qspi.h> #include <platform/n25q128a.h> +#include <target/bmi055.h> #include <target/debugconfig.h> #include <target/gpioconfig.h> #include <target/memory_lcd.h> +#include <target/sensor_bus.h> #include <reg.h> #if WITH_LIB_MINIP @@ -86,7 +89,7 @@ void target_early_init(void) gpio_init.Pin = GPIO_TO_PIN_MASK(GPIO_LED114) | GPIO_TO_PIN_MASK(GPIO_LED115); HAL_GPIO_Init(GPIOJ, &gpio_init); - // Initialize to a pattern just so we know we have something. + // Initialize to a pattern just so we know we have something gpio_set(GPIO_LED108, GPIO_LED_ON); gpio_set(GPIO_LED109, GPIO_LED_ON); gpio_set(GPIO_LED110, GPIO_LED_ON); @@ -108,6 +111,9 @@ void target_early_init(void) GPIO_TO_PIN_MASK(GPIO_SW102) | GPIO_TO_PIN_MASK(GPIO_SW103); HAL_GPIO_Init(GPIOJ, &gpio_init); + // Initialize Sensor bus (accelerometer / gyroscope / nrf51 spi bus + sensor_bus_init_early(); + // now that the uart gpios are configured, enable the debug uart. stm32_debug_early_init(); @@ -118,6 +124,7 @@ void target_early_init(void) target_set_debug_led(3, false); } + void target_init(void) { stm32_debug_init(); @@ -154,6 +161,8 @@ void target_init(void) // start usb target_usb_setup(); + + sensor_bus_init(); } void HAL_SPI_MspInit(SPI_HandleTypeDef *hspi) diff --git a/target/dartuinoP0/rules.mk b/target/dartuinoP0/rules.mk index 7c569abe..5271f9e5 100644 --- a/target/dartuinoP0/rules.mk +++ b/target/dartuinoP0/rules.mk @@ -25,10 +25,14 @@ GLOBAL_DEFINES += \ \ TARGET_HAS_DEBUG_LED=1 +MODULE_DEPS += \ + app/accelerometer \ + GLOBAL_INCLUDES += $(LOCAL_DIR)/include MODULE_SRCS += \ $(LOCAL_DIR)/init.c \ + $(LOCAL_DIR)/sensor_bus.c \ $(LOCAL_DIR)/usb.c \ ifneq ($(DISPLAY_PANEL_TYPE),) diff --git a/target/dartuinoP0/sensor_bus.c b/target/dartuinoP0/sensor_bus.c new file mode 100644 index 00000000..82f608a4 --- /dev/null +++ b/target/dartuinoP0/sensor_bus.c @@ -0,0 +1,121 @@ +/* + * Copyright (c) 2015 Eric Holland + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +#include <err.h> +#include <kernel/mutex.h> +#include <platform/gpio.h> +#include <target/gpioconfig.h> +#include <target/bmi055.h> +#include <target/sensor_bus.h> +#include <dev/accelerometer.h> + +static mutex_t sensorbus_mutex; +static SPI_HandleTypeDef spi_handle; + +static uint8_t tx_buff[16]; +static uint8_t rx_buff[16]; + +status_t acc_read_xyz(position_vector_t * pos_vector_p) +{ + tx_buff[0] = BMI055_ADDRESS_READ( BMI055_ACC_ACCD_X_LSB ); + if ( acc_flush(tx_buff, rx_buff, 7) == NO_ERROR ) + { + pos_vector_p->x = 0.001*(((int8_t)rx_buff[2] << 4) | ( (rx_buff[1] >> 4) & 0x0F)); + pos_vector_p->y = 0.001*(((int8_t)rx_buff[4] << 4) | ( (rx_buff[3] >> 4) & 0x0F)); + pos_vector_p->z = 0.001*(((int8_t)rx_buff[6] << 4) | ( (rx_buff[5] >> 4) & 0x0F)); + return NO_ERROR; + } + else { + return ERR_GENERIC; + } +} + +status_t acc_flush(uint8_t * tbuff, uint8_t * rbuff, uint8_t numbytes) +{ + status_t ret_status; + + mutex_acquire(&sensorbus_mutex); + + gpio_set(GPIO_ACC_nCS,GPIO_PIN_RESET); + + ret_status = HAL_SPI_TransmitReceive(&spi_handle, tbuff, rbuff, numbytes, 5000); + + gpio_set(GPIO_ACC_nCS,GPIO_PIN_SET); + + mutex_release(&sensorbus_mutex); + + return ret_status; +} + +/** + * @brief Initiale SPI5 module and IO for control of spi bus linking nrf51, accelerometer, and gyroscope. + * + */ +status_t sensor_bus_init_early(void) +{ + __HAL_SENSOR_BUS_GPIO_CLK_ENABLE(); + __HAL_RCC_SPI5_CLK_ENABLE(); + + gpio_config(GPIO_SPI5_SCK, GPIO_STM32_AF | GPIO_STM32_AFn(GPIO_AF5_SPI5) | GPIO_PULLUP); + gpio_config(GPIO_SPI5_MISO, GPIO_STM32_AF | GPIO_STM32_AFn(GPIO_AF5_SPI5) | GPIO_PULLUP); + gpio_config(GPIO_SPI5_MOSI, GPIO_STM32_AF | GPIO_STM32_AFn(GPIO_AF5_SPI5) | GPIO_PULLUP); + + gpio_config(GPIO_NRF_CS, GPIO_OUTPUT ); + gpio_config(GPIO_NRF_INT, GPIO_INPUT | GPIO_PULLUP); + + gpio_config(GPIO_GYRO_nCS, GPIO_OUTPUT ); + gpio_config(GPIO_GYRO_INT, GPIO_INPUT | GPIO_PULLUP); + + gpio_config(GPIO_ACC_nCS, GPIO_OUTPUT ); + gpio_config(GPIO_ACC_INT, GPIO_INPUT | GPIO_PULLUP); + + gpio_set(GPIO_NRF_CS, GPIO_PIN_RESET); + gpio_set(GPIO_GYRO_nCS, GPIO_PIN_SET); + gpio_set(GPIO_ACC_nCS, GPIO_PIN_SET); + + spi_handle.Instance = SPI5; + spi_handle.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_128; + spi_handle.Init.Direction = SPI_DIRECTION_2LINES; + spi_handle.Init.CLKPhase = SPI_PHASE_1EDGE; + spi_handle.Init.CLKPolarity = SPI_POLARITY_LOW; + spi_handle.Init.DataSize = SPI_DATASIZE_8BIT; + spi_handle.Init.FirstBit = SPI_FIRSTBIT_MSB; + spi_handle.Init.TIMode = SPI_TIMODE_DISABLE; + spi_handle.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; + spi_handle.Init.CRCPolynomial = 7; + spi_handle.Init.NSS = SPI_NSS_SOFT; + spi_handle.Init.Mode = SPI_MODE_MASTER; + + if (HAL_SPI_Init(&spi_handle) != HAL_OK) { + return ERR_GENERIC; + } + return NO_ERROR; +} + + + +void sensor_bus_init(void) +{ + mutex_init(&sensorbus_mutex); +} + + |