Skip to content

Commit

Permalink
[CH32] micro-SD, OLED display and BMP280 sensor are doing good
Browse files Browse the repository at this point in the history
  • Loading branch information
lyusupov committed Nov 4, 2024
1 parent aea8c1b commit 4e0d200
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 9 deletions.
Binary file added documents/images/Card-2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added documents/images/Card-3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added documents/images/Card-4.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added documents/images/Card-5.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 9 additions & 8 deletions software/firmware/source/SoftRF/src/platform/CH32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,14 @@ static void CH32_msc_flush_cb (void)
#if defined(ENABLE_RECORDER)
#include <SdFat.h>

#if defined(USE_SOFTSPI)
SoftSPI uSD_SPI(SOC_GPIO_YD_SD_CMD, SOC_GPIO_YD_SD_D0, SOC_GPIO_YD_SD_CLK);
#else
SPIClass uSD_SPI;
#endif /* USE_SOFTSPI */
SoftSpiDriver<SOC_GPIO_YD_SD_D0, SOC_GPIO_YD_SD_CMD, SOC_GPIO_YD_SD_CLK> uSD_SPI;

// Speed argument is ignored for software SPI.
#if ENABLE_DEDICATED_SPI
#define SD_CONFIG SdSpiConfig(uSD_SS_pin, DEDICATED_SPI, SD_SCK_MHZ(8), &uSD_SPI)
#else // ENABLE_DEDICATED_SPI
#define SD_CONFIG SdSpiConfig(uSD_SS_pin, SHARED_SPI, SD_SCK_MHZ(8), &uSD_SPI)
#endif // ENABLE_DEDICATED_SPI

SdFat uSD;

Expand Down Expand Up @@ -251,7 +252,7 @@ static void CH32_setup()
{
int uSD_SS_pin = SOC_GPIO_YD_SD_D3;

#if !defined(USE_SOFTSPI)
#if !defined(USE_SOFTSPI) && SPI_DRIVER_SELECT != 2
uSD_SPI.setMISO(SOC_GPIO_YD_SD_D0);
uSD_SPI.setMOSI(SOC_GPIO_YD_SD_CMD);
uSD_SPI.setSCLK(SOC_GPIO_YD_SD_CLK);
Expand Down Expand Up @@ -790,7 +791,7 @@ static void CH32_Button_setup()
int button_pin = SOC_GPIO_PIN_BUTTON;

// Button(s) uses external pull up resistor.
pinMode(button_pin, INPUT);
pinMode(button_pin, CH32_board == CH32_YD_V307VCT6 ? INPUT_PULLUP : INPUT);

button_1.init(button_pin);

Expand Down Expand Up @@ -830,7 +831,7 @@ static void CH32_Button_fini()
if (hw_info.model == SOFTRF_MODEL_ACADEMY) {
// detachInterrupt(digitalPinToInterrupt(SOC_GPIO_PIN_BUTTON));
while (digitalRead(SOC_GPIO_PIN_BUTTON) == LOW);
pinMode(SOC_GPIO_PIN_BUTTON, ANALOG);
pinMode(SOC_GPIO_PIN_BUTTON, INPUT);
}
#endif /* SOC_GPIO_PIN_BUTTON != SOC_UNUSED_PIN */
}
Expand Down
32 changes: 31 additions & 1 deletion software/firmware/source/SoftRF/src/platform/CH32.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,11 @@ struct rst_info {
#define SOC_GPIO_PIN_GNSS_RX PA10
#define SOC_GPIO_PIN_GNSS_TX PA9

#if defined(PB4)
#define SOC_GPIO_PIN_STATUS SOC_UNUSED_PIN /* PA15 PB4 */
#else
#define SOC_GPIO_PIN_STATUS PB4
#endif
#define SOC_GPIO_PIN_BUZZER SOC_UNUSED_PIN

#define SOC_GPIO_PIN_RX3 SOC_UNUSED_PIN
Expand Down Expand Up @@ -143,18 +147,44 @@ struct rst_info {
#define SOC_GPIO_PIN_LED SOC_UNUSED_PIN
#define SOC_GPIO_PIN_GNSS_PPS PA3
#define SOC_GPIO_PIN_BATTERY SOC_UNUSED_PIN /* PA0 TBD */
#if defined(PB3)
#define SOC_GPIO_PIN_BUTTON PB3
#else
#define SOC_GPIO_PIN_BUTTON SOC_UNUSED_PIN
#endif

#define SOC_GPIO_RADIO_LED_RX SOC_UNUSED_PIN
#define SOC_GPIO_RADIO_LED_TX SOC_UNUSED_PIN

/* SPI3 */
#if defined(PB5)
#define SOC_GPIO_PIN_MOSI3 PB5
#else
#define SOC_GPIO_PIN_MOSI3 PB_5
#endif
#if defined(PB4)
#define SOC_GPIO_PIN_MISO3 PB4
#else
#define SOC_GPIO_PIN_MISO3 PB_4
#endif
#if defined(PB3)
#define SOC_GPIO_PIN_SCK3 PB3
#else
#define SOC_GPIO_PIN_SCK3 PB_3
#endif
#if defined(PA15)
#define SOC_GPIO_PIN_SS3 PA15
#else
#define SOC_GPIO_PIN_SS3 PA_15
#endif

/* YD-CH32V307VCT6 */
#define SOC_GPIO_YD_LED_BLUE PB_4
#define SOC_GPIO_YD_LED_RED PA_15

#define SOC_GPIO_YD_BUTTON PB_3

// uSD
// SDIO
#if defined(PC8)
#define SOC_GPIO_YD_SD_D0 PC8
#else
Expand Down
4 changes: 4 additions & 0 deletions software/firmware/source/libraries/SdFat/src/SdFatConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
#define USE_UTF8_LONG_NAMES 1
#endif

#if defined(ARDUINO_ARCH_CH32)
#define SPI_DRIVER_SELECT 2
#endif // ARDUINO_ARCH_CH32

// Backward-compatible define
#define ENABLE_EXTENDED_TRANSFER_CLASS USE_BLOCK_DEVICE_INTERFACE
#define BaseBlockDriver FsBlockDeviceInterface
Expand Down

1 comment on commit 4e0d200

@lyusupov
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image

Please sign in to comment.