-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* spi device config * fix api_interrupt_call warning * added configs for spi2 bus devices * simplified spi bus api * use new spi device api
- Loading branch information
Showing
10 changed files
with
172 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#include "main.h" | ||
#include "api-hal-spi-config.h" | ||
|
||
extern SPI_HandleTypeDef SPI_R; | ||
extern SPI_HandleTypeDef SPI_D; | ||
|
||
/** | ||
* SD Card in fast mode (after init) | ||
*/ | ||
const SPIDevice sd_fast_spi = { | ||
.spi = &SPI_D, | ||
.config = { | ||
.Mode = SPI_MODE_MASTER, | ||
.Direction = SPI_DIRECTION_2LINES, | ||
.DataSize = SPI_DATASIZE_8BIT, | ||
.CLKPolarity = SPI_POLARITY_LOW, | ||
.CLKPhase = SPI_PHASE_1EDGE, | ||
.NSS = SPI_NSS_SOFT, | ||
.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2, | ||
.FirstBit = SPI_FIRSTBIT_MSB, | ||
.TIMode = SPI_TIMODE_DISABLE, | ||
.CRCCalculation = SPI_CRCCALCULATION_DISABLE, | ||
.CRCPolynomial = 7, | ||
.CRCLength = SPI_CRC_LENGTH_DATASIZE, | ||
.NSSPMode = SPI_NSS_PULSE_ENABLE, | ||
}}; | ||
|
||
/** | ||
* SD Card in slow mode (before init) | ||
*/ | ||
const SPIDevice sd_slow_spi = { | ||
.spi = &SPI_D, | ||
.config = { | ||
.Mode = SPI_MODE_MASTER, | ||
.Direction = SPI_DIRECTION_2LINES, | ||
.DataSize = SPI_DATASIZE_8BIT, | ||
.CLKPolarity = SPI_POLARITY_LOW, | ||
.CLKPhase = SPI_PHASE_1EDGE, | ||
.NSS = SPI_NSS_SOFT, | ||
.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_256, | ||
.FirstBit = SPI_FIRSTBIT_MSB, | ||
.TIMode = SPI_TIMODE_DISABLE, | ||
.CRCCalculation = SPI_CRCCALCULATION_DISABLE, | ||
.CRCPolynomial = 7, | ||
.CRCLength = SPI_CRC_LENGTH_DATASIZE, | ||
.NSSPMode = SPI_NSS_PULSE_ENABLE, | ||
}}; | ||
|
||
/** | ||
* Display | ||
*/ | ||
const SPIDevice display_spi = { | ||
.spi = &SPI_D, | ||
.config = { | ||
.Mode = SPI_MODE_MASTER, | ||
.Direction = SPI_DIRECTION_2LINES, | ||
.DataSize = SPI_DATASIZE_8BIT, | ||
.CLKPolarity = SPI_POLARITY_LOW, | ||
.CLKPhase = SPI_PHASE_1EDGE, | ||
.NSS = SPI_NSS_SOFT, | ||
.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16, | ||
.FirstBit = SPI_FIRSTBIT_MSB, | ||
.TIMode = SPI_TIMODE_DISABLE, | ||
.CRCCalculation = SPI_CRCCALCULATION_DISABLE, | ||
.CRCPolynomial = 7, | ||
.CRCLength = SPI_CRC_LENGTH_DATASIZE, | ||
.NSSPMode = SPI_NSS_PULSE_ENABLE, | ||
}}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#pragma once | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
typedef struct { | ||
SPI_HandleTypeDef* spi; | ||
const SPI_InitTypeDef config; | ||
} SPIDevice; | ||
|
||
extern const SPIDevice sd_fast_spi; | ||
extern const SPIDevice sd_slow_spi; | ||
extern const SPIDevice display_spi; | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,36 @@ | ||
#pragma once | ||
#include "main.h" | ||
#include <cmsis_os.h> | ||
#include "api-hal-spi-config.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
/** | ||
* Init SPI API | ||
*/ | ||
void api_hal_spi_init(); | ||
|
||
/** | ||
* Lock SPI bus | ||
*/ | ||
void api_hal_spi_lock(SPI_HandleTypeDef* spi); | ||
void api_hal_spi_unlock(SPI_HandleTypeDef* spi); | ||
|
||
/** | ||
* Unlock SPI bus | ||
*/ | ||
void api_hal_spi_unlock(SPI_HandleTypeDef* spi); | ||
|
||
/** | ||
* Lock SPI device bus and apply config if needed | ||
*/ | ||
void api_hal_spi_lock_device(const SPIDevice* device); | ||
|
||
/** | ||
* Unlock SPI device bus | ||
*/ | ||
void api_hal_spi_unlock_device(const SPIDevice* device); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |