Included spi driver.

This commit is contained in:
Daniele Lacamera 2019-11-02 14:45:27 +01:00
parent 1c02765920
commit eb1a572eff
2 changed files with 38 additions and 2 deletions

4
.gitignore vendored
View file

@ -1,6 +1,6 @@
*.o
*.bin
test/test
test/test.bin
image.elf
image.map
tags
core

36
usecfs_dev_spi.c Normal file
View file

@ -0,0 +1,36 @@
#include <stdint.h>
#include "usecfs_dev.h"
#include "spi_flash.h"
static uint32_t part_base = 0xFFFFFFFF;
static uint32_t part_size = 0;
void *block_open(void *args_ptr)
{
uint32_t *args = (uint32_t *)args_ptr;
part_base = args[0];
part_size = args[1];
return &part_base;
}
int block_read(void *dev, void *_buf, uint32_t lba)
{
if (part_size == 0)
return -1;
return spi_flash_read(part_base + (lba * BLOCK_SIZE), _buf, BLOCK_SIZE);
}
int block_write(void *dev, const void *_buf, uint32_t lba)
{
if (part_size == 0)
return -1;
spi_flash_sector_erase(part_base + lba * BLOCK_SIZE);
return spi_flash_write(part_base + lba * BLOCK_SIZE, _buf, BLOCK_SIZE);
}
void block_close(void *dev)
{
(void)dev;
part_base = 0xFFFFFFFF;
part_size = 0;
}