SD card v7 BSP (#361)
* Outdated apps: add api-light-usage * Gpio: update SD card CS pin settings * API-power: added fns to disable/enable external 3v3 dc-dc * API-gpio: separated SD card detect routines * Resources: removed sd cs pin * SD card: low level init now resets card power supply * App SD-filesystem: use new card detect fns * SD card: fix low level init headers * SD card: more realilable low level init, power reset, exit from command read cycle conditionally * App SD-filesystem: led notifiers, init cycling * SD card: backport to F4 * SD card: handle eject in init sequence * SD card: api to set level on detect gpio * SPI: api to set state on bus pins * SD card: set low state on bus pins while power reset Co-authored-by: coreglitch <mail@s3f.ru>
This commit is contained in:
		@@ -20,33 +20,6 @@ void hal_gpio_init(
 | 
			
		||||
    HAL_GPIO_Init(gpio->port, &GPIO_InitStruct);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool hal_gpio_read_sd_detect(void) {
 | 
			
		||||
    bool result = false;
 | 
			
		||||
 | 
			
		||||
    // TODO open record
 | 
			
		||||
    const GpioPin* sd_cs_record = &sd_cs_gpio;
 | 
			
		||||
 | 
			
		||||
    // TODO: SPI manager
 | 
			
		||||
    api_hal_spi_lock(sd_fast_spi.spi);
 | 
			
		||||
 | 
			
		||||
    // configure pin as input
 | 
			
		||||
    gpio_init_ex(sd_cs_record, GpioModeInput, GpioPullUp, GpioSpeedVeryHigh);
 | 
			
		||||
    delay(1);
 | 
			
		||||
 | 
			
		||||
    // 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);
 | 
			
		||||
    gpio_write(sd_cs_record, 1);
 | 
			
		||||
    delay(1);
 | 
			
		||||
 | 
			
		||||
    // TODO: SPI manager
 | 
			
		||||
    api_hal_spi_unlock(sd_fast_spi.spi);
 | 
			
		||||
 | 
			
		||||
    return result;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void enable_cc1101_irq() {
 | 
			
		||||
    HAL_NVIC_SetPriority(EXTI4_IRQn, 5, 0);
 | 
			
		||||
    HAL_NVIC_EnableIRQ(EXTI4_IRQn);
 | 
			
		||||
 
 | 
			
		||||
@@ -68,8 +68,6 @@ static inline bool hal_gpio_read(const GpioPin* gpio) {
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool hal_gpio_read_sd_detect(void);
 | 
			
		||||
 | 
			
		||||
void enable_cc1101_irq();
 | 
			
		||||
 | 
			
		||||
#ifdef __cplusplus
 | 
			
		||||
 
 | 
			
		||||
@@ -6,6 +6,7 @@
 | 
			
		||||
#include <stm32wbxx_ll_pwr.h>
 | 
			
		||||
#include <stm32wbxx_ll_hsem.h>
 | 
			
		||||
#include <stm32wbxx_ll_cortex.h>
 | 
			
		||||
#include <stm32wbxx_ll_gpio.h>
 | 
			
		||||
 | 
			
		||||
#include <main.h>
 | 
			
		||||
#include <hw_conf.h>
 | 
			
		||||
@@ -195,3 +196,11 @@ void api_hal_power_dump_state(string_t buffer) {
 | 
			
		||||
        bq25896_get_ntc_mpct()
 | 
			
		||||
    );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void api_hal_power_enable_external_3_3v(){
 | 
			
		||||
    LL_GPIO_SetOutputPin(PERIPH_POWER_GPIO_Port, PERIPH_POWER_Pin);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void api_hal_power_disable_external_3_3v(){
 | 
			
		||||
    LL_GPIO_ResetOutputPin(PERIPH_POWER_GPIO_Port, PERIPH_POWER_Pin);
 | 
			
		||||
}
 | 
			
		||||
@@ -25,7 +25,6 @@ const InputPin input_pins[] = {
 | 
			
		||||
 | 
			
		||||
const size_t input_pins_count = sizeof(input_pins) / sizeof(InputPin);
 | 
			
		||||
 | 
			
		||||
const GpioPin sd_cs_gpio = {SD_CS_GPIO_Port, SD_CS_Pin};
 | 
			
		||||
const GpioPin vibro_gpio = {VIBRO_GPIO_Port, VIBRO_Pin};
 | 
			
		||||
const GpioPin ibutton_gpio = {iBTN_GPIO_Port, iBTN_Pin};
 | 
			
		||||
const GpioPin cc1101_g0_gpio = {CC1101_G0_GPIO_Port, CC1101_G0_Pin};
 | 
			
		||||
 
 | 
			
		||||
@@ -53,7 +53,6 @@ typedef struct {
 | 
			
		||||
extern const InputPin input_pins[];
 | 
			
		||||
extern const size_t input_pins_count;
 | 
			
		||||
 | 
			
		||||
extern const GpioPin sd_cs_gpio;
 | 
			
		||||
extern const GpioPin vibro_gpio;
 | 
			
		||||
extern const GpioPin ibutton_gpio;
 | 
			
		||||
extern const GpioPin cc1101_g0_gpio;
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										22
									
								
								firmware/targets/f5/api-hal/api-hal-sd.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								firmware/targets/f5/api-hal/api-hal-sd.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,22 @@
 | 
			
		||||
#include "api-hal-sd.h"
 | 
			
		||||
#include <stm32wbxx_ll_gpio.h>
 | 
			
		||||
#include <furi.h>
 | 
			
		||||
 | 
			
		||||
void hal_sd_detect_init(void) {
 | 
			
		||||
    // low speed input with pullup
 | 
			
		||||
    LL_GPIO_SetPinMode(SD_CD_GPIO_Port, SD_CD_Pin, LL_GPIO_MODE_INPUT);
 | 
			
		||||
    LL_GPIO_SetPinSpeed(SD_CD_GPIO_Port, SD_CD_Pin, LL_GPIO_SPEED_FREQ_LOW);
 | 
			
		||||
    LL_GPIO_SetPinPull(SD_CD_GPIO_Port, SD_CD_Pin, LL_GPIO_PULL_UP);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void hal_sd_detect_set_low(void) {
 | 
			
		||||
    // low speed input with pullup
 | 
			
		||||
    LL_GPIO_SetPinMode(SD_CD_GPIO_Port, SD_CD_Pin, LL_GPIO_MODE_OUTPUT);
 | 
			
		||||
    LL_GPIO_SetPinOutputType(SD_CD_GPIO_Port, SD_CD_Pin, LL_GPIO_OUTPUT_OPENDRAIN);
 | 
			
		||||
    LL_GPIO_ResetOutputPin(SD_CD_GPIO_Port, SD_CD_Pin);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool hal_sd_detect(void) {
 | 
			
		||||
    bool result = !(LL_GPIO_IsInputPinSet(SD_CD_GPIO_Port, SD_CD_Pin));
 | 
			
		||||
    return result;
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user