Skip to content
Closed

Fatfs #5467

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions content/components/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,7 @@ Often known as "tag" or "card" readers within the community.
"Resol VBus","components/vbus","resol_deltasol_bs_plus.jpg",""
"Tuya Binary Sensor","components/binary_sensor/tuya","tuya.png",""
"WireGuard","components/wireguard","wireguard_custom_logo.svg","dark-invert"
"Fatfs","components/fatfs",fatfs.svg","dark-invert"
{{< /imgtable >}}

## Alarm Control Panel Components
Expand Down Expand Up @@ -1053,6 +1054,7 @@ ESPHome to cellular networks. **Does not encompass Wi-Fi.**
"Sun","components/sun","weather-sunny.svg","dark-invert"
"Tuya MCU","components/tuya","tuya.png",""
"Z-Wave Proxy","components/zwave_proxy","z-wave.svg",""
"Fatfs","components/fatfs/","fatfs.svg",""
{{< /imgtable >}}

## Cookbook
Expand Down
98 changes: 98 additions & 0 deletions content/components/fatfs/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
---
description: "Information about the base representation of all FATfs devices."
title: "Fatfs Component"
params:
seo:
description: Information about the base representation of all FATfs devices.
image: fatfs.svg
---
{{< anchor "platforms-fatfs" >}}

FATFS is the API for files and directory access storage devices with FAT filesystems. API contains methods for accessing and control files and directory. API will the same on any platforms even with another FAT library.

{{< anchor "fatfs-base-config" >}}

## Base fatfs Configuration

Each FATFS device represented by the platform component with coresponding type. Each platform type inherits parameters from fatfs configuration schema.

```yaml

fatfs:
- platform: ...
...
- platform: ...
...

```

**Configuration variables:**

- **platform** (**Required**, [platform](#platforms-canbus)): One of the supported fatfs [Platforms](#platforms-fatfs).
- **id** (*Optional*, [ID](#config-id)): Manually specify the ID used for code generation.
- **drive_id** (*Optional*, string): Manually specify the mounted ID in range: 0-10
- **cd_pin** (*Optional*, [Pin Schema](#config-pin_schema)): The pin used for storage media detect in case it removasle media like sdcard. CD pin used in some card holders.

{{< anchor "fatfs-exist_condition" >}}

## Exist Condition

This is an condition for checking if file or directory by are present. File pointed by its path path.

```yaml

- if:
condition:
- sdfs.is_exist:
id: fatfs_id
path: "/"
then:
...

```

Configuration variables:

- **id** (**Required**, [ID](#config-id)): The ID of the fatfs device.
- **path** (*Required*, string, [templatable](#config-templatable)): path for fs object to check for existing

{{< anchor "fatfs-lambda-calls" >}}

### lambda calls

From [lambdas](#config-lambda), you can call several methods on all fatfs objects to do some
advanced stuff.

- Attributes: All atfs devices have attributes to get access to filea and directory

```cpp
// Check if FS mounted
id(my_fatfs).is_mount()
// Get Filesystems object info
id(my_fatfs).get_info(path)
// if path exist
id(my_fatfs).is_exist(path)
// Open file by path
id(my_fatfs).open_file(path,mode)
// open file by fs info object
id(my_fatfs).open_file(obj,mode)
// open dir for contents listing by path
id(my_fatfs).open_dir(path)
// open dir for contents listing by info object
id(my_fatfs).open_dir(obj)
// create directory
id(my_fatfs).mk_dir(path)
// create directory as child for file info object
id(my_fatfs).mk_dir(obj,name)
// delete file
id(my_fatfs).del(path)
// rename fs objects
id(my_fatfs).rename(path_from,path_to)

```

## See Also

- {{< apiref "Component" "esphome/core/component.h" >}}
- {{< apiref "api" "content/components/api.md">}}
- {{< apiref "fatfs" "esphome/components/fatfs/fatfs.h" "fatfs/fatfs.h" >}}
50 changes: 50 additions & 0 deletions content/components/fatfs/fatfs_esp32_sdspi
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
description: "Component for accessing files on sdcard with FAT filesystems"
title: "Fatfs_esp32_sdspi Component"
params:
seo:
description: Information about the base representation of all FATfs devices.
image: fatfs.svg
---

The fatfs_esp32_sdspi platform component mount sdcard device connected via SPI interface.
fatfs_esp32 itself provide methods for accessing files and directory on FAT filesystems thought esp32 implementation of fatfs library. Fatfs library suport FAT16, FAT32 and ExFat.

{{< anchor "fatfs-esp32-sdspi" >}}

## Base fatfs Configuration

Each FATFS device represented by the platform component with coresponding type. Each platform type inherits parameters from fatfs configuration schema.
fatfs_esp32_sdspi component also inherit paramiters from polling component for checking if card steel present.
This function is useful in case your card holder does not prifide card detect pin.

```yaml

spi:
id: spi1
# ...

fatfs:
- platform: fatfs_esp32_sdspi
spi_id: spi1
cs_pin: GPIOXX

```

**Configuration variables:**

- **spi_id** (**Required**, [SPI](#spi)): SPI bus id for connecting with sdcard.
- **cs_pin** (*Required*, [Pin Schema](#config-pin_schema)): Card select pin as part of spi interface
- **update_interval** (*Optional*, [Time](#config-time)): The interval to check the
sensor. Defaults to `10s`.
- All other options from [fatfs](#fatfs-base-config).

{{< anchor "fatfs-exist_condition" >}}


## See Also

- {{< docref "fatfs/" >}}
- {{< apiref "Component" "esphome/core/component.h" >}}
- {{< apiref "api" "content/components/api.md">}}
- {{< apiref "fatfs" "esphome/components/fatfs/fatfs.h" "fatfs/fatfs.h" >}}
1 change: 1 addition & 0 deletions static/images/fatfs.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.