mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-14 11:59:58 +03:00
Moved bus_spi parameter group to pg/
.
This commit is contained in:
parent
9184401c45
commit
b38738894c
8 changed files with 122 additions and 72 deletions
|
@ -64,6 +64,7 @@ COMMON_SRC = \
|
|||
pg/beeper.c \
|
||||
pg/beeper_dev.c \
|
||||
pg/bus_i2c.c \
|
||||
pg/bus_spi.c \
|
||||
pg/flash.c \
|
||||
pg/max7456.c \
|
||||
pg/pg.c \
|
||||
|
|
|
@ -108,10 +108,5 @@ bool spiBusReadRegisterBuffer(const busDevice_t *bus, uint8_t reg, uint8_t *data
|
|||
uint8_t spiBusReadRegister(const busDevice_t *bus, uint8_t reg);
|
||||
void spiBusSetInstance(busDevice_t *bus, SPI_TypeDef *instance);
|
||||
|
||||
typedef struct spiPinConfig_s {
|
||||
ioTag_t ioTagSck[SPIDEV_COUNT];
|
||||
ioTag_t ioTagMiso[SPIDEV_COUNT];
|
||||
ioTag_t ioTagMosi[SPIDEV_COUNT];
|
||||
} spiPinConfig_t;
|
||||
|
||||
void spiPinConfigure(void);
|
||||
struct spiPinConfig_s;
|
||||
void spiPinConfigure(const struct spiPinConfig_s *pConfig);
|
||||
|
|
|
@ -32,64 +32,7 @@
|
|||
#include "drivers/io.h"
|
||||
#include "drivers/rcc.h"
|
||||
|
||||
#include "pg/pg.h"
|
||||
#include "pg/pg_ids.h"
|
||||
|
||||
// Pin defaults for backward compatibility
|
||||
#ifndef SPI1_SCK_PIN
|
||||
#define SPI1_SCK_PIN PA5
|
||||
#define SPI1_MISO_PIN PA6
|
||||
#define SPI1_MOSI_PIN PA7
|
||||
#endif
|
||||
|
||||
#ifndef SPI2_SCK_PIN
|
||||
#define SPI2_SCK_PIN PB13
|
||||
#define SPI2_MISO_PIN PB14
|
||||
#define SPI2_MOSI_PIN PB15
|
||||
#endif
|
||||
|
||||
#ifndef SPI3_SCK_PIN
|
||||
#define SPI3_SCK_PIN PB3
|
||||
#define SPI3_MISO_PIN PB4
|
||||
#define SPI3_MOSI_PIN PB5
|
||||
#endif
|
||||
|
||||
PG_DECLARE(spiPinConfig_t, spiPinConfig);
|
||||
|
||||
PG_REGISTER_WITH_RESET_FN(spiPinConfig_t, spiPinConfig, PG_SPI_PIN_CONFIG, 0);
|
||||
|
||||
typedef struct spiDefaultConfig_s {
|
||||
SPIDevice device;
|
||||
ioTag_t sck;
|
||||
ioTag_t miso;
|
||||
ioTag_t mosi;
|
||||
} spiDefaultConfig_t;
|
||||
|
||||
const spiDefaultConfig_t spiDefaultConfig[] = {
|
||||
#ifdef USE_SPI_DEVICE_1
|
||||
{ SPIDEV_1, IO_TAG(SPI1_SCK_PIN), IO_TAG(SPI1_MISO_PIN), IO_TAG(SPI1_MOSI_PIN) },
|
||||
#endif
|
||||
#ifdef USE_SPI_DEVICE_2
|
||||
{ SPIDEV_2, IO_TAG(SPI2_SCK_PIN), IO_TAG(SPI2_MISO_PIN), IO_TAG(SPI2_MOSI_PIN) },
|
||||
#endif
|
||||
#ifdef USE_SPI_DEVICE_3
|
||||
{ SPIDEV_3, IO_TAG(SPI3_SCK_PIN), IO_TAG(SPI3_MISO_PIN), IO_TAG(SPI3_MOSI_PIN) },
|
||||
#endif
|
||||
#ifdef USE_SPI_DEVICE_4
|
||||
{ SPIDEV_4, IO_TAG(SPI4_SCK_PIN), IO_TAG(SPI4_MISO_PIN), IO_TAG(SPI4_MOSI_PIN) },
|
||||
#endif
|
||||
};
|
||||
|
||||
void pgResetFn_spiPinConfig(spiPinConfig_t *spiPinConfig)
|
||||
{
|
||||
for (size_t i = 0 ; i < ARRAYLEN(spiDefaultConfig) ; i++) {
|
||||
const spiDefaultConfig_t *defconf = &spiDefaultConfig[i];
|
||||
spiPinConfig->ioTagSck[defconf->device] = defconf->sck;
|
||||
spiPinConfig->ioTagMiso[defconf->device] = defconf->miso;
|
||||
spiPinConfig->ioTagMosi[defconf->device] = defconf->mosi;
|
||||
}
|
||||
}
|
||||
|
||||
#include "pg/bus_spi.h"
|
||||
|
||||
const spiHardware_t spiHardware[] = {
|
||||
#ifdef STM32F1
|
||||
|
@ -335,10 +278,8 @@ const spiHardware_t spiHardware[] = {
|
|||
#endif
|
||||
};
|
||||
|
||||
void spiPinConfigure(void)
|
||||
void spiPinConfigure(const spiPinConfig_t *pConfig)
|
||||
{
|
||||
const spiPinConfig_t *pConfig = spiPinConfig();
|
||||
|
||||
for (size_t hwindex = 0 ; hwindex < ARRAYLEN(spiHardware) ; hwindex++) {
|
||||
const spiHardware_t *hw = &spiHardware[hwindex];
|
||||
|
||||
|
|
|
@ -80,6 +80,7 @@
|
|||
#include "pg/adc.h"
|
||||
#include "pg/beeper_dev.h"
|
||||
#include "pg/bus_i2c.h"
|
||||
#include "pg/bus_spi.h"
|
||||
#include "pg/flash.h"
|
||||
#include "pg/pg.h"
|
||||
#include "pg/rx_pwm.h"
|
||||
|
@ -422,7 +423,7 @@ void init(void)
|
|||
#else
|
||||
|
||||
#ifdef USE_SPI
|
||||
spiPinConfigure();
|
||||
spiPinConfigure(spiPinConfig());
|
||||
|
||||
// Initialize CS lines and keep them high
|
||||
spiPreInit();
|
||||
|
|
|
@ -115,6 +115,7 @@ extern uint8_t __config_end;
|
|||
#include "pg/beeper.h"
|
||||
#include "pg/beeper_dev.h"
|
||||
#include "pg/bus_i2c.h"
|
||||
#include "pg/bus_spi.h"
|
||||
#include "pg/pg.h"
|
||||
#include "pg/pg_ids.h"
|
||||
#include "pg/rx_pwm.h"
|
||||
|
|
81
src/main/pg/bus_spi.c
Normal file
81
src/main/pg/bus_spi.c
Normal file
|
@ -0,0 +1,81 @@
|
|||
/*
|
||||
* This file is part of Cleanflight.
|
||||
*
|
||||
* Cleanflight 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Cleanflight 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 Cleanflight. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <platform.h>
|
||||
|
||||
#ifdef USE_SPI
|
||||
|
||||
#include "drivers/io.h"
|
||||
|
||||
#include "pg/pg.h"
|
||||
#include "pg/pg_ids.h"
|
||||
|
||||
#include "bus_spi.h"
|
||||
|
||||
// Pin defaults for backward compatibility
|
||||
#ifndef SPI1_SCK_PIN
|
||||
#define SPI1_SCK_PIN PA5
|
||||
#define SPI1_MISO_PIN PA6
|
||||
#define SPI1_MOSI_PIN PA7
|
||||
#endif
|
||||
|
||||
#ifndef SPI2_SCK_PIN
|
||||
#define SPI2_SCK_PIN PB13
|
||||
#define SPI2_MISO_PIN PB14
|
||||
#define SPI2_MOSI_PIN PB15
|
||||
#endif
|
||||
|
||||
#ifndef SPI3_SCK_PIN
|
||||
#define SPI3_SCK_PIN PB3
|
||||
#define SPI3_MISO_PIN PB4
|
||||
#define SPI3_MOSI_PIN PB5
|
||||
#endif
|
||||
|
||||
typedef struct spiDefaultConfig_s {
|
||||
SPIDevice device;
|
||||
ioTag_t sck;
|
||||
ioTag_t miso;
|
||||
ioTag_t mosi;
|
||||
} spiDefaultConfig_t;
|
||||
|
||||
const spiDefaultConfig_t spiDefaultConfig[] = {
|
||||
#ifdef USE_SPI_DEVICE_1
|
||||
{ SPIDEV_1, IO_TAG(SPI1_SCK_PIN), IO_TAG(SPI1_MISO_PIN), IO_TAG(SPI1_MOSI_PIN) },
|
||||
#endif
|
||||
#ifdef USE_SPI_DEVICE_2
|
||||
{ SPIDEV_2, IO_TAG(SPI2_SCK_PIN), IO_TAG(SPI2_MISO_PIN), IO_TAG(SPI2_MOSI_PIN) },
|
||||
#endif
|
||||
#ifdef USE_SPI_DEVICE_3
|
||||
{ SPIDEV_3, IO_TAG(SPI3_SCK_PIN), IO_TAG(SPI3_MISO_PIN), IO_TAG(SPI3_MOSI_PIN) },
|
||||
#endif
|
||||
#ifdef USE_SPI_DEVICE_4
|
||||
{ SPIDEV_4, IO_TAG(SPI4_SCK_PIN), IO_TAG(SPI4_MISO_PIN), IO_TAG(SPI4_MOSI_PIN) },
|
||||
#endif
|
||||
};
|
||||
|
||||
PG_REGISTER_WITH_RESET_FN(spiPinConfig_t, spiPinConfig, PG_SPI_PIN_CONFIG, 0);
|
||||
|
||||
void pgResetFn_spiPinConfig(spiPinConfig_t *spiPinConfig)
|
||||
{
|
||||
for (size_t i = 0 ; i < ARRAYLEN(spiDefaultConfig) ; i++) {
|
||||
const spiDefaultConfig_t *defconf = &spiDefaultConfig[i];
|
||||
spiPinConfig->ioTagSck[defconf->device] = defconf->sck;
|
||||
spiPinConfig->ioTagMiso[defconf->device] = defconf->miso;
|
||||
spiPinConfig->ioTagMosi[defconf->device] = defconf->mosi;
|
||||
}
|
||||
}
|
||||
#endif
|
31
src/main/pg/bus_spi.h
Normal file
31
src/main/pg/bus_spi.h
Normal file
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* This file is part of Cleanflight.
|
||||
*
|
||||
* Cleanflight 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Cleanflight 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 Cleanflight. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "drivers/bus_spi.h"
|
||||
#include "drivers/io_types.h"
|
||||
|
||||
#include "pg/pg.h"
|
||||
|
||||
typedef struct spiPinConfig_s {
|
||||
ioTag_t ioTagSck[SPIDEV_COUNT];
|
||||
ioTag_t ioTagMiso[SPIDEV_COUNT];
|
||||
ioTag_t ioTagMosi[SPIDEV_COUNT];
|
||||
} spiPinConfig_t;
|
||||
|
||||
PG_DECLARE(spiPinConfig_t, spiPinConfig);
|
|
@ -20,14 +20,13 @@
|
|||
|
||||
#include <platform.h>
|
||||
|
||||
#include "drivers/bus_i2c.h"
|
||||
#include "drivers/bus_spi.h"
|
||||
#include "drivers/io.h"
|
||||
#include "drivers/dma.h"
|
||||
#include "drivers/timer.h"
|
||||
#include "drivers/timer_def.h"
|
||||
|
||||
#include "pg/bus_i2c.h"
|
||||
#include "pg/bus_spi.h"
|
||||
|
||||
#ifdef USE_BST
|
||||
#include "bus_bst.h"
|
||||
|
@ -57,7 +56,7 @@ const timerHardware_t timerHardware[USABLE_TIMER_CHANNEL_COUNT] = {
|
|||
void targetBusInit(void)
|
||||
{
|
||||
#ifdef USE_SPI
|
||||
spiPinConfigure();
|
||||
spiPinConfigure(spiPinConfig());
|
||||
#ifdef USE_SPI_DEVICE_1
|
||||
spiInit(SPIDEV_1);
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue