aboutsummaryrefslogtreecommitdiff
path: root/drivers/eeprom/eeprom_spi.h
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/eeprom/eeprom_spi.h')
-rw-r--r--drivers/eeprom/eeprom_spi.h80
1 files changed, 80 insertions, 0 deletions
diff --git a/drivers/eeprom/eeprom_spi.h b/drivers/eeprom/eeprom_spi.h
new file mode 100644
index 000000000..282c60356
--- /dev/null
+++ b/drivers/eeprom/eeprom_spi.h
@@ -0,0 +1,80 @@
1/* Copyright 2020 Nick Brassel (tzarc)
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#pragma once
18
19/*
20 The slave select pin of the EEPROM.
21 This needs to be a normal GPIO pin_t value, such as A7.
22*/
23#ifndef EXTERNAL_EEPROM_SPI_SLAVE_SELECT_PIN
24# error "No chip select pin defined -- missing EXTERNAL_EEPROM_SPI_SLAVE_SELECT_PIN"
25#endif
26
27/*
28 The clock divisor for SPI to ensure that the MCU is within the
29 specifications of the EEPROM chip. Generally this will be PCLK divided by
30 the intended divisor -- check your clock settings and the datasheet of
31 your EEPROM.
32*/
33#ifndef EXTERNAL_EEPROM_SPI_CLOCK_DIVISOR
34# ifdef __AVR__
35# define EXTERNAL_EEPROM_SPI_CLOCK_DIVISOR 8
36# else
37# define EXTERNAL_EEPROM_SPI_CLOCK_DIVISOR 64
38# endif
39#endif
40
41/*
42 The SPI mode to communicate with the EEPROM.
43*/
44#ifndef EXTERNAL_EEPROM_SPI_MODE
45# define EXTERNAL_EEPROM_SPI_MODE 0
46#endif
47
48/*
49 Whether or not the SPI communication between the MCU and EEPROM should be
50 LSB-first.
51*/
52#ifndef EXTERNAL_EEPROM_SPI_LSBFIRST
53# define EXTERNAL_EEPROM_SPI_LSBFIRST false
54#endif
55
56/*
57 The total size of the EEPROM, in bytes. The EEPROM datasheet will usually
58 specify this value in kbits, and will require conversion to bytes.
59*/
60#ifndef EXTERNAL_EEPROM_BYTE_COUNT
61# define EXTERNAL_EEPROM_BYTE_COUNT 8192
62#endif
63
64/*
65 The page size in bytes of the EEPROM, as specified in the datasheet.
66*/
67#ifndef EXTERNAL_EEPROM_PAGE_SIZE
68# define EXTERNAL_EEPROM_PAGE_SIZE 32
69#endif
70
71/*
72 The address size in bytes of the EEPROM. For EEPROMs with <=256 bytes, this
73 will likely be 1. For EEPROMs >256 and <=65536, this will be 2. For EEPROMs
74 >65536, this will likely need to be 4.
75
76 As expected, consult the datasheet for specifics of your EEPROM.
77*/
78#ifndef EXTERNAL_EEPROM_ADDRESS_SIZE
79# define EXTERNAL_EEPROM_ADDRESS_SIZE 2
80#endif