From 49fdb288713e9c49512b276ef1f4753f6f7cc577 Mon Sep 17 00:00:00 2001 From: DrZlo13 Date: Wed, 11 Nov 2020 09:17:53 +0300 Subject: [PATCH] sd detect pin feature (#222) * test sd detect pin * sd detect support for f2 board --- applications/examples/fatfs_list.c | 7 ++++++ bootloader/Makefile | 1 + firmware/Makefile | 1 + firmware/targets/f2/api-hal/api-hal-gpio.c | 4 ++++ firmware/targets/f2/api-hal/api-hal-gpio.h | 4 +++- firmware/targets/f3/api-hal/api-hal-gpio.c | 22 +++++++++++++++++++ firmware/targets/f3/api-hal/api-hal-gpio.h | 4 +++- .../targets/f3/api-hal/api-hal-resources.c | 3 ++- .../targets/f3/api-hal/api-hal-resources.h | 3 ++- make/git.mk | 2 +- 10 files changed, 46 insertions(+), 5 deletions(-) diff --git a/applications/examples/fatfs_list.c b/applications/examples/fatfs_list.c index 04c6fd69..60361f51 100644 --- a/applications/examples/fatfs_list.c +++ b/applications/examples/fatfs_list.c @@ -51,6 +51,13 @@ void fatfs_list(void* p) { furi_log = get_default_log(); fuprintf(furi_log, "[fatfs_list] app start\n"); + fuprintf(furi_log, "[fatfs_list] wait for sd insert\n"); + + while(!hal_gpio_read_sd_detect()) { + delay(100); + } + + fuprintf(furi_log, "[fatfs_list] sd inserted\n"); FuriRecordSubscriber* fb_record = furi_open_deprecated("u8g2_fb", false, false, NULL, NULL, NULL); diff --git a/bootloader/Makefile b/bootloader/Makefile index 06e42627..83fba710 100644 --- a/bootloader/Makefile +++ b/bootloader/Makefile @@ -2,6 +2,7 @@ PROJECT_ROOT = $(abspath $(dir $(abspath $(firstword $(MAKEFILE_LIST))))..) PROJECT = bootloader include $(PROJECT_ROOT)/make/base.mk +include $(PROJECT_ROOT)/make/git.mk CFLAGS += -Itargets/include ASM_SOURCES += $(wildcard src/*.s) diff --git a/firmware/Makefile b/firmware/Makefile index 3e23684c..926972d7 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -7,6 +7,7 @@ CPPFLAGS += -Werror include $(PROJECT_ROOT)/make/base.mk include $(PROJECT_ROOT)/assets/assets.mk include $(PROJECT_ROOT)/core/core.mk +include $(PROJECT_ROOT)/make/git.mk include $(PROJECT_ROOT)/applications/applications.mk include $(PROJECT_ROOT)/lib/lib.mk diff --git a/firmware/targets/f2/api-hal/api-hal-gpio.c b/firmware/targets/f2/api-hal/api-hal-gpio.c index cf886353..91eeef25 100644 --- a/firmware/targets/f2/api-hal/api-hal-gpio.c +++ b/firmware/targets/f2/api-hal/api-hal-gpio.c @@ -12,3 +12,7 @@ void hal_gpio_init(GpioPin* gpio, GpioMode mode, GpioPull pull, GpioSpeed speed) HAL_GPIO_Init(gpio->port, &GPIO_InitStruct); } + +bool hal_gpio_read_sd_detect(void) { + return true; +} \ No newline at end of file diff --git a/firmware/targets/f2/api-hal/api-hal-gpio.h b/firmware/targets/f2/api-hal/api-hal-gpio.h index b125a445..f1b77711 100644 --- a/firmware/targets/f2/api-hal/api-hal-gpio.h +++ b/firmware/targets/f2/api-hal/api-hal-gpio.h @@ -58,4 +58,6 @@ static inline bool hal_gpio_read(const GpioPin* gpio) { } else { return false; } -} \ No newline at end of file +} + +bool hal_gpio_read_sd_detect(void); \ No newline at end of file diff --git a/firmware/targets/f3/api-hal/api-hal-gpio.c b/firmware/targets/f3/api-hal/api-hal-gpio.c index cf886353..a3bfd0e5 100644 --- a/firmware/targets/f3/api-hal/api-hal-gpio.c +++ b/firmware/targets/f3/api-hal/api-hal-gpio.c @@ -1,4 +1,5 @@ #include "api-hal-gpio.h" +#include "api-hal-resources.h" // init GPIO void hal_gpio_init(GpioPin* gpio, GpioMode mode, GpioPull pull, GpioSpeed speed) { @@ -12,3 +13,24 @@ void hal_gpio_init(GpioPin* gpio, GpioMode mode, GpioPull pull, GpioSpeed speed) HAL_GPIO_Init(gpio->port, &GPIO_InitStruct); } + +bool hal_gpio_read_sd_detect(void) { + bool result = false; + // create pin + GpioPin sd_cs_pin = sd_cs_gpio; + // TODO open record + GpioPin* sd_cs_record = &sd_cs_pin; + + // configure pin as input + gpio_init_ex(sd_cs_record, GpioModeInput, GpioPullUp, GpioSpeedVeryHigh); + delay(50); + + // if gpio_read == 0 return true else return false + result = !gpio_read(sd_cs_record); + + // configure pin back + gpio_init_ex(sd_cs_record, GpioModeOutputPushPull, GpioPullNo, GpioSpeedVeryHigh); + delay(50); + + return result; +} \ No newline at end of file diff --git a/firmware/targets/f3/api-hal/api-hal-gpio.h b/firmware/targets/f3/api-hal/api-hal-gpio.h index b125a445..f1b77711 100644 --- a/firmware/targets/f3/api-hal/api-hal-gpio.h +++ b/firmware/targets/f3/api-hal/api-hal-gpio.h @@ -58,4 +58,6 @@ static inline bool hal_gpio_read(const GpioPin* gpio) { } else { return false; } -} \ No newline at end of file +} + +bool hal_gpio_read_sd_detect(void); \ No newline at end of file diff --git a/firmware/targets/f3/api-hal/api-hal-resources.c b/firmware/targets/f3/api-hal/api-hal-resources.c index 65e69635..07647ee4 100644 --- a/firmware/targets/f3/api-hal/api-hal-resources.c +++ b/firmware/targets/f3/api-hal/api-hal-resources.c @@ -24,4 +24,5 @@ const GpioPin led_gpio[3] = { {LED_GREEN_GPIO_Port, LED_GREEN_Pin}, {LED_BLUE_GPIO_Port, LED_BLUE_Pin}}; -const GpioPin backlight_gpio = {DISPLAY_BACKLIGHT_GPIO_Port, DISPLAY_BACKLIGHT_Pin}; \ No newline at end of file +const GpioPin backlight_gpio = {DISPLAY_BACKLIGHT_GPIO_Port, DISPLAY_BACKLIGHT_Pin}; +const GpioPin sd_cs_gpio = {SD_CS_GPIO_Port, SD_CS_Pin}; diff --git a/firmware/targets/f3/api-hal/api-hal-resources.h b/firmware/targets/f3/api-hal/api-hal-resources.h index bed91abc..40c99b41 100644 --- a/firmware/targets/f3/api-hal/api-hal-resources.h +++ b/firmware/targets/f3/api-hal/api-hal-resources.h @@ -9,4 +9,5 @@ extern const GpioPin input_gpio[GPIO_INPUT_PINS_COUNT]; extern const bool input_invert[GPIO_INPUT_PINS_COUNT]; extern const GpioPin led_gpio[3]; -extern const GpioPin backlight_gpio; \ No newline at end of file +extern const GpioPin backlight_gpio; +extern const GpioPin sd_cs_gpio; diff --git a/make/git.mk b/make/git.mk index ff49e48a..8f5c9bb4 100644 --- a/make/git.mk +++ b/make/git.mk @@ -4,4 +4,4 @@ GIT_BRANCH_NUM = $(shell git rev-list --count $(GIT_BRANCH) || echo 'nan') BUILD_DATE = $(shell date '+%d-%m-%Y' || echo 'unknown') CFLAGS += -DGIT_COMMIT="\"$(GIT_COMMIT)\"" -DGIT_BRANCH="\"$(GIT_BRANCH)\"" -DGIT_BRANCH_NUM="\"$(GIT_BRANCH_NUM)\"" -CFLAGS += -DBUILD_DATE="\"$(BUILD_DATE)\"" -DTARGET="\"$(TARGET)\"" \ No newline at end of file +CFLAGS += -DBUILD_DATE="\"$(BUILD_DATE)\"" -DTARGET="\"$(TARGET)\""