wip sram driver

This commit is contained in:
Nero 2019-12-31 23:09:11 +00:00
parent 4c9558852a
commit 1c8e8805d8
2 changed files with 38 additions and 0 deletions

32
drivers/sram.c Normal file
View File

@ -0,0 +1,32 @@
#include "sram.h"
// 23LCV512 64kB SPI SRAM
uint8_t sram_status() {
uint8_t v;
PORTB &= ~(1 << 2);
spi_transfer(0x05);
v = spi_transfer(0x00);
PORTB |= (1 << 2);
return v;
}
uint8_t sram_read(uint16_t addr) {
uint8_t v;
PORTB &= ~(1 << 2);
spi_transfer(0x03);
spi_transfer(addr & 0xFF);
spi_transfer(addr > 8);
v = spi_transfer(0x00);
PORTB |= (1 << 2);
return v;
}
void sram_write(uint16_t addr, uint8_t v) {
PORTB &= ~(1 << 2);
spi_transfer(0x02);
spi_transfer(addr & 0xFF);
spi_transfer(addr > 8);
spi_transfer(v);
PORTB |= (1 << 2);
}

6
drivers/sram.h Normal file
View File

@ -0,0 +1,6 @@
#include <stdint.h>
#include <avr/io.h>
uint8_t sram_status();
uint8_t sram_read(uint16_t addr);
void sram_write(uint16_t addr, uint8_t v);