Skip to content

Commit a079985

Browse files
author
scpcom
committed
TF_CARD: move SD_CS pin defines to pins_arduino.h
1 parent dcf9c9e commit a079985

3 files changed

Lines changed: 23 additions & 5 deletions

File tree

libraries/TF_CARD/src/tf_card.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
1+
#include "pins_arduino.h"
12
#include "tf_card.h"
23

4+
#ifndef SD_CS_GPIO_PIN
5+
#define SD_CS_GPIO_PIN GPIO_PIN_12
6+
#define SD_CS_GPIO_PORT GPIOB
7+
#define SD_CS_GPIO_CLK RCU_GPIOB
8+
#endif
9+
310
#define FCLK_SLOW() { SPI_CTL0(SPI1) = (SPI_CTL0(SPI1) & ~0x38) | SPI_PSC_64; } /* Set SCLK = PCLK2 / 64 */
411
#define FCLK_FAST() { SPI_CTL0(SPI1) = (SPI_CTL0(SPI1) & ~0x38) | SPI_PSC_4; } /* Set SCLK = PCLK2 / 4 */
512

613
// #define FCLK_SLOW()
714
// #define FCLK_FAST()
815

9-
#define CS_HIGH() PB_OUT(12,1)
10-
#define CS_LOW() PB_OUT(12,0)
16+
#define CS_HIGH() gpio_bit_set(SD_CS_GPIO_PORT, SD_CS_GPIO_PIN)
17+
#define CS_LOW() gpio_bit_reset(SD_CS_GPIO_PORT, SD_CS_GPIO_PIN)
1118

1219
/*--------------------------------------------------------------------------
1320
@@ -59,14 +66,16 @@ void init_spi(void)
5966
{
6067
spi_parameter_struct spi_init_struct;
6168

62-
rcu_periph_clock_enable(RCU_GPIOB);
6369
rcu_periph_clock_enable(RCU_SPI1);
6470

6571
/* SPI1_SCK(PB13), SPI1_MISO(PB14) and SPI1_MOSI(PB15) GPIO pin configuration */
72+
rcu_periph_clock_enable(RCU_GPIOB);
6673
gpio_init(GPIOB, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_13 | GPIO_PIN_15);
6774
gpio_init(GPIOB, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, GPIO_PIN_14);
68-
/* SPI1_CS(PB12) GPIO pin configuration */
69-
gpio_init(GPIOB, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_12);
75+
76+
/* SD_CS(PB12) GPIO pin configuration (PB1 on Wio Lite Risc-V) */
77+
rcu_periph_clock_enable(SD_CS_GPIO_CLK);
78+
gpio_init( SD_CS_GPIO_PORT, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, SD_CS_GPIO_PIN);
7079

7180
/* chip _select invalid*/
7281
CS_HIGH();

variants/sipeed-longan-nano/pins_arduino.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@
7575

7676
/* SD card chip select */
7777
#define SDCARD_SS_PIN PB12
78+
79+
#define SD_CS_GPIO_PIN GPIO_PIN_12
80+
#define SD_CS_GPIO_PORT GPIOB
81+
#define SD_CS_GPIO_CLK RCU_GPIOB
82+
7883
/* LCD chip select */
7984
#define LCD_SS_PIN PB2
8085

variants/wio_lite_risc-v/pins_arduino.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
/* SD card chip select */
1919
#define SDCARD_SS_PIN PB1
2020

21+
#define SD_CS_GPIO_PIN GPIO_PIN_1
22+
#define SD_CS_GPIO_PORT GPIOB
23+
#define SD_CS_GPIO_CLK RCU_GPIOB
24+
2125
#ifdef __cplusplus
2226
extern "C" {
2327
#endif

0 commit comments

Comments
 (0)