/* ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ /** * @file mmc_spi.h * @brief MMC over SPI driver header. * * @addtogroup MMC_SPI * @{ */ #ifndef _MMC_SPI_H_ #define _MMC_SPI_H_ #if (HAL_USE_MMC_SPI == TRUE) || defined(__DOXYGEN__) /*===========================================================================*/ /* Driver constants. */ /*===========================================================================*/ #define MMC_CMD0_RETRY 10U #define MMC_CMD1_RETRY 100U #define MMC_ACMD41_RETRY 100U #define MMC_WAIT_DATA 10000U /*===========================================================================*/ /* Driver pre-compile time settings. */ /*===========================================================================*/ /** * @name MMC_SPI configuration options * @{ */ /** * @brief Delays insertions. * @details If enabled this options inserts delays into the MMC waiting * routines releasing some extra CPU time for the threads with * lower priority, this may slow down the driver a bit however. * This option is recommended also if the SPI driver does not * use a DMA channel and heavily loads the CPU. */ #if !defined(MMC_NICE_WAITING) || defined(__DOXYGEN__) #define MMC_NICE_WAITING TRUE #endif /** @} */ /*===========================================================================*/ /* Derived constants and error checks. */ /*===========================================================================*/ #if (HAL_USE_SPI == FALSE) || (SPI_USE_WAIT == FALSE) #error "MMC_SPI driver requires HAL_USE_SPI and SPI_USE_WAIT" #endif /*===========================================================================*/ /* Driver data structures and types. */ /*===========================================================================*/ /** * @brief MMC/SD over SPI driver configuration structure. */ typedef struct { /** * @brief SPI driver associated to this MMC driver. */ SPIDriver *spip; /** * @brief SPI low speed configuration used during initialization. */ const SPIConfig *lscfg; /** * @brief SPI high speed configuration used during transfers. */ const SPIConfig *hscfg; } MMCConfig; /** * @brief @p MMCDriver specific methods. */ #define _mmc_driver_methods \ _mmcsd_block_device_methods /** * @extends MMCSDBlockDeviceVMT * * @brief @p MMCDriver virtual methods table. */ struct MMCDriverVMT { _mmc_driver_methods }; /** * @extends MMCSDBlockDevice * * @brief Structure representing a MMC/SD over SPI driver. */ typedef struct { /** * @brief Virtual Methods Table. */ const struct MMCDriverVMT *vmt; _mmcsd_block_device_data /** * @brief Current configuration data. */ const MMCConfig *config; /*** * @brief Addresses use blocks instead of bytes. */ bool block_addresses; } MMCDriver; /*===========================================================================*/ /* Driver macros. */ /*===========================================================================*/ /** * @name Macro Functions * @{ */ /** * @brief Returns the card insertion status. * @note This macro wraps a low level function named * @p sdc_lld_is_card_inserted(), this function must be * provided by the application because it is not part of the * SDC driver. * * @param[in] mmcp pointer to the @p MMCDriver object * @return The card state. * @retval FALSE card not inserted. * @retval TRUE card inserted. * * @api */ #define mmcIsCardInserted(mmcp) mmc_lld_is_card_inserted(mmcp) /** * @brief Returns the write protect status. * * @param[in] mmcp pointer to the @p MMCDriver object * @return The card state. * @retval FALSE card not inserted. * @retval TRUE card inserted. * * @api */ #define mmcIsWriteProtected(mmcp) mmc_lld_is_write_protected(mmcp) /** @} */ /*===========================================================================*/ /* External declarations. */ /*===========================================================================*/ #ifdef __cplusplus extern "C" { #endif void mmcInit(void); void mmcObjectInit(MMCDriver *mmcp); void mmcStart(MMCDriver *mmcp, const MMCConfig *config); void mmcStop(MMCDriver *mmcp); bool mmcConnect(MMCDriver *mmcp); bool mmcDisconnect(MMCDriver *mmcp); bool mmcStartSequentialRead(MMCDriver *mmcp, uint32_t startblk); bool mmcSequentialRead(MMCDriver *mmcp, uint8_t *buffer); bool mmcStopSequentialRead(MMCDriver *mmcp); bool mmcStartSequentialWrite(MMCDriver *mmcp, uint32_t startblk); bool mmcSequentialWrite(MMCDriver *mmcp, const uint8_t *buffer); bool mmcStopSequentialWrite(MMCDriver *mmcp); bool mmcSync(MMCDriver *mmcp); bool mmcGetInfo(MMCDriver *mmcp, BlockDeviceInfo *bdip); bool mmcErase(MMCDriver *mmcp, uint32_t startblk, uint32_t endblk); bool mmc_lld_is_card_inserted(MMCDriver *mmcp); bool mmc_lld_is_write_protected(MMCDriver *mmcp); #ifdef __cplusplus } #endif #endif /* HAL_USE_MMC_SPI == TRUE */ #endif /* _MMC_SPI_H_ */ /** @} */ lor: #a61717; background-color: #e3d2d2 } /* Error */ .highlight .k { color: #008800; font-weight: bold } /* Keyword */ .highlight .ch { color: #888888 } /* Comment.Hashbang */ .highlight .cm { color: #888888 } /* Comment.Multiline */ .highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */ .highlight .cpf { color: #888888 } /* Comment.PreprocFile */ .highlight .c1 { color: #888888 } /* Comment.Single */ .highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */ .highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */ .highlight .ge { font-style: italic } /* Generic.Emph */ .highlight .gr { color: #aa0000 } /* Generic.Error */ .highlight .gh { color: #333333 } /* Generic.Heading */ .highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */ .highlight .go { color: #888888 } /* Generic.Output */ .highlight .gp { color: #555555 } /* Generic.Prompt */ .highlight .gs { font-weight: bold } /* Generic.Strong */ .highlight .gu { color: #666666 } /* Generic.Subheading */ .highlight .gt { color: #aa0000 } /* Generic.Traceback */ .highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
# Bootmagic and Magic Keycodes

There are 3 separate but related features that allow you to change the behavior of your keyboard without reflashing. While each of them have similar functionality you access that functionality in different ways depending on how your keyboard is configured.

Bootmagic is a system for configuring your keyboard while it initializes. To trigger a Bootmagic command you hold down the bootmagic key (`KC_SPACE` on most keyboards) and one or more command keys.

Bootmagic Keycodes allow you to access the Bootmagic functionality after your keyboard has initialized. To use Bootmagic Keycodes you assign keycodes starting with `MAGIC_`, much in the same way you define any other key.

Command is a feature that allows you to control different aspects of your keyboard. Command used to be called Magic. Command is typically accessed by holding Left and Right Shift at the same time, although that can be customized. While it shares some functionality with Bootmagic it also allows you to access functionality that Bootmagic does not. For more information see the (Command)[feature_command.md) documentation page.

## Enabling Bootmagic

Bootmagic is disabled by default. To use Bootmagic you need to enable it in your `rules.mk` file:

    BOOTMAGIC_ENABLE = yes

## Bootmagic Hotkeys and Keycodes

This table describes the default Hotkeys for Bootmagic and the Keycodes for Magic. These may be overriden at the Keyboard or Keymap level. Some functionality is not available in both methods.

To use the Hotkey hold down `BOOTMAGIC_KEY_SALT` (`KC_SPACE` by default) and the Hotkey while plugging in your keyboard. To use the Keycode assign that keycode to a layer. For example, if you hold down Space+B while plugging in most keyboards, you will enter bootloader mode.

|Hotkey     |Keycode                           |Description                                             |
|-----------|----------------------------------|--------------------------------------------------------|
|`ESC`      |                                  |Skip bootmagic and saved eeprom configuration           |
|`B`        |`RESET`                           |Enter bootloader instead of firmware                    |
|`D`        |`DEBUG`                           |Enable debugging (writes messages to serial)            |
|`X`        |                                  |Enable matrix debugging                                 |
|`K`        |                                  |Enable keyboard debugging                               |
|`M`        |                                  |Enable mouse debugging                                  |
|`BACKSPACE`|                                  |Clear the saved settings from flash                     |
|`CAPSLOCK` |`MAGIC_CAPSLOCK_TO_CONTROL`       |Treat `Capslock` as `Control`                           |
|           |`MAGIC_UNCAPSLOCK_TO_CONTROL`     |Stop treating CapsLock as Control                       |
|`LCTRL`    |`MAGIC_SWAP_CONTROL_CAPSLOCK`     |Swap `Control` and `Capslock`                           |
|           |`MAGIC_UNSWAP_CONTROL_CAPSLOCK`   |Unswap Left Control and Caps Lock                       |
|           |`MAGIC_SWAP_ALT_GUI`              |Swap Alt and GUI on both sides                          |
|           |`MAGIC_UNSWAP_ALT_GUI`            |Unswap Left Alt and GUI                                 |
|`LALT`     |`MAGIC_SWAP_LALT_LGUI`            |Swap Left `Alt` and `GUI`, e.g. for OSX Opt and Cmd     |
|           |`MAGIC_UNSWAP_LALT_LGUI`          |Unswap Left Alt and GUI                                 |
|`RALT`     |`MAGIC_SWAP_RALT_RGUI`            |Swap Right `Alt` and `GUI`                              |
|           |`MAGIC_UNSWAP_RALT_RGUI`          |Unswap Right Alt and GUI                                |
|`LGUI`     |`MAGIC_NO_GUI`                    |Disable GUI key - e.g. disable Windows key during gaming|
|           |`MAGIC_UNNO_GUI`                  |Enable the GUI key                                      |
|`GRAVE`    |`MAGIC_SWAP_GRAVE_ESC`            |Swap `\`~` and `ESC`                                    |
|           |`MAGIC_UNSWAP_GRAVE_ESC`          |Unswap `\`~` and Escape                                 |
|`BACKSLASH`|`MAGIC_SWAP_BACKSLASH_BACKSPACE`  |Swap Blackslash and Backspace                           |
|           |`MAGIC_UNSWAP_BACKSLASH_BACKSPACE`|Unswap Backslash and Backspace                          |
|`N`        |`MAGIC_HOST_NKRO`                 |Force N-Key Rollover (NKRO) on                          |
|           |`MAGIC_UNHOST_NKRO`               |Force NKRO off                                          |
|           |`MAGIC_TOGGLE_NKRO`               |Toggle NKRO on or off                                   |
|`0`        |`DF(0)`                           |Make Layer 0 the default layer at bootup                |
|`1`        |`DF(1)`                           |Make Layer 1 the default layer at bootup                |
|`2`        |`DF(2)`                           |Make Layer 2 the default layer at bootup                |
|`3`        |`DF(3)`                           |Make Layer 3 the default layer at bootup                |
|`4`        |`DF(4)`                           |Make Layer 4 the default layer at bootup                |
|`5`        |`DF(5)`                           |Make Layer 5 the default layer at bootup                |
|`6`        |`DF(6)`                           |Make Layer 6 the default layer at bootup                |
|`7`        |`DF(7)`                           |Make Layer 7 the default layer at bootup                |

## Bootmagic Configuration

When setting up your keyboard and/or keymap there are a number of `#define`s that control the behavior of Bootmagic. To use these put them in your `config.h`, either at the keyboard or keymap level.

|Define |Default|Description |
|-------|-------|------------|
|`BOOTMAGIC_KEY_SALT`|`KC_SPACE`|The key to hold down to trigger Bootmagic during initialization.|
|`BOOTMAGIC_KEY_SKIP`|`KC_ESC`|The Hotkey to ignore saved eeprom configuration.|
|`BOOTMAGIC_KEY_EEPROM_CLEAR`|`KC_BSPACE`|The hotkey to clear the saved eeprom configuration.|
|`BOOTMAGIC_KEY_BOOTLOADER`|`KC_B`|The hotkey to enter the bootloader.|
|`BOOTMAGIC_KEY_DEBUG_ENABLE`|`KC_D`|The hotkey to enable debug mode.|
|`BOOTMAGIC_KEY_DEBUG_MATRIX`|`KC_X`|The hotkey to enable matrix debugging mode.|
|`BOOTMAGIC_KEY_DEBUG_KEYBOARD`|`KC_K`|The hotkey to enable keyboard debugging mode.|
|`BOOTMAGIC_KEY_DEBUG_MOUSE`|`KC_M`|The hotkey to enable mouse debugging mode.|
|`BOOTMAGIC_KEY_SWAP_CONTROL_CAPSLOCK`|`KC_LCTRL`||
|`BOOTMAGIC_KEY_CAPSLOCK_TO_CONTROL`|`KC_CAPSLOCK`||
|`BOOTMAGIC_KEY_SWAP_LALT_LGUI`|`KC_LALT`||
|`BOOTMAGIC_KEY_SWAP_RALT_RGUI`|`KC_RALT`||
|`BOOTMAGIC_KEY_NO_GUI`|`KC_LGUI`||
|`BOOTMAGIC_KEY_SWAP_GRAVE_ESC`|`KC_GRAVE`||
|`BOOTMAGIC_KEY_SWAP_BACKSLASH_BACKSPACE`|`KC_BSLASH`||
|`BOOTMAGIC_HOST_NKRO`|`KC_N`||
|`BOOTMAGIC_KEY_DEFAULT_LAYER_0`|`KC_0`|Hotkey to set Layer 0 as the default layer|
|`BOOTMAGIC_KEY_DEFAULT_LAYER_1`|`KC_1`|Hotkey to set Layer 1 as the default layer|
|`BOOTMAGIC_KEY_DEFAULT_LAYER_2`|`KC_2`|Hotkey to set Layer 2 as the default layer|
|`BOOTMAGIC_KEY_DEFAULT_LAYER_3`|`KC_3`|Hotkey to set Layer 3 as the default layer|
|`BOOTMAGIC_KEY_DEFAULT_LAYER_4`|`KC_4`|Hotkey to set Layer 4 as the default layer|
|`BOOTMAGIC_KEY_DEFAULT_LAYER_5`|`KC_5`|Hotkey to set Layer 5 as the default layer|
|`BOOTMAGIC_KEY_DEFAULT_LAYER_6`|`KC_6`|Hotkey to set Layer 6 as the default layer|
|`BOOTMAGIC_KEY_DEFAULT_LAYER_7`|`KC_7`|Hotkey to set Layer 7 as the default layer|