qmk_firmware

QMK firmware for my keyboards (Corne, Sweep Ferris) and trackball (Ploopy Adept)
Log | Files | Refs | Submodules | LICENSE

eeprom_spi.h (2903B)


      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     Default device configurations:
     21 
     22     For the Adafruit SPI Non-Volatile FRAM Breakout: https://www.adafruit.com/product/1897
     23         #define EEPROM_SPI_MB85RS64V
     24 */
     25 #if defined(EEPROM_SPI_MB85RS64V)
     26 #    define EXTERNAL_EEPROM_BYTE_COUNT 8192
     27 #    define EXTERNAL_EEPROM_PAGE_SIZE 64 // it's FRAM, so it doesn't actually matter, this just sets the RAM buffer
     28 #    define EXTERNAL_EEPROM_ADDRESS_SIZE 2
     29 #endif
     30 
     31 /*
     32     The slave select pin of the EEPROM.
     33     This needs to be a normal GPIO pin_t value, such as A7.
     34 */
     35 #ifndef EXTERNAL_EEPROM_SPI_SLAVE_SELECT_PIN
     36 #    error "No chip select pin defined -- missing EXTERNAL_EEPROM_SPI_SLAVE_SELECT_PIN"
     37 #endif
     38 
     39 /*
     40     The clock divisor for SPI to ensure that the MCU is within the
     41     specifications of the EEPROM chip. Generally this will be PCLK divided by
     42     the intended divisor -- check your clock settings and the datasheet of
     43     your EEPROM.
     44 */
     45 #ifndef EXTERNAL_EEPROM_SPI_CLOCK_DIVISOR
     46 #    ifdef __AVR__
     47 #        define EXTERNAL_EEPROM_SPI_CLOCK_DIVISOR 8
     48 #    else
     49 #        define EXTERNAL_EEPROM_SPI_CLOCK_DIVISOR 64
     50 #    endif
     51 #endif
     52 
     53 /*
     54     The SPI mode to communicate with the EEPROM.
     55 */
     56 #ifndef EXTERNAL_EEPROM_SPI_MODE
     57 #    define EXTERNAL_EEPROM_SPI_MODE 0
     58 #endif
     59 
     60 /*
     61     Whether or not the SPI communication between the MCU and EEPROM should be
     62     LSB-first.
     63 */
     64 #ifndef EXTERNAL_EEPROM_SPI_LSBFIRST
     65 #    define EXTERNAL_EEPROM_SPI_LSBFIRST false
     66 #endif
     67 
     68 /*
     69     The total size of the EEPROM, in bytes. The EEPROM datasheet will usually
     70     specify this value in kbits, and will require conversion to bytes.
     71 */
     72 #ifndef EXTERNAL_EEPROM_BYTE_COUNT
     73 #    define EXTERNAL_EEPROM_BYTE_COUNT 8192
     74 #endif
     75 
     76 /*
     77     The page size in bytes of the EEPROM, as specified in the datasheet.
     78 */
     79 #ifndef EXTERNAL_EEPROM_PAGE_SIZE
     80 #    define EXTERNAL_EEPROM_PAGE_SIZE 32
     81 #endif
     82 
     83 /*
     84     The address size in bytes of the EEPROM. For EEPROMs with <=256 bytes, this
     85     will likely be 1. For EEPROMs >256 and <=65536, this will be 2. For EEPROMs
     86     >65536, this will likely need to be 4.
     87 
     88     As expected, consult the datasheet for specifics of your EEPROM.
     89 */
     90 #ifndef EXTERNAL_EEPROM_ADDRESS_SIZE
     91 #    define EXTERNAL_EEPROM_ADDRESS_SIZE 2
     92 #endif