diff options
Diffstat (limited to 'tmk_core/common')
| -rw-r--r-- | tmk_core/common/arm_atsam/eeprom.c | 94 | ||||
| -rw-r--r-- | tmk_core/common/avr/suspend.c | 98 | ||||
| -rw-r--r-- | tmk_core/common/chibios/_wait.h | 2 | ||||
| -rw-r--r-- | tmk_core/common/chibios/chibios_config.h | 41 | ||||
| -rw-r--r-- | tmk_core/common/chibios/eeprom_stm32.c | 57 | ||||
| -rw-r--r-- | tmk_core/common/chibios/eeprom_stm32_defs.h | 19 | ||||
| -rw-r--r-- | tmk_core/common/chibios/flash_stm32.c | 41 | ||||
| -rw-r--r-- | tmk_core/common/chibios/suspend.c | 89 | ||||
| -rw-r--r-- | tmk_core/common/host.c | 15 | ||||
| -rw-r--r-- | tmk_core/common/host.h | 2 | ||||
| -rw-r--r-- | tmk_core/common/host_driver.h | 1 | ||||
| -rw-r--r-- | tmk_core/common/report.h | 6 | ||||
| -rw-r--r-- | tmk_core/common/suspend.h | 2 | ||||
| -rw-r--r-- | tmk_core/common/sync_timer.c | 2 | ||||
| -rw-r--r-- | tmk_core/common/sync_timer.h | 2 | ||||
| -rw-r--r-- | tmk_core/common/test/rules.mk | 1 | 
16 files changed, 215 insertions, 257 deletions
| diff --git a/tmk_core/common/arm_atsam/eeprom.c b/tmk_core/common/arm_atsam/eeprom.c index ccd5d15a54..ff1a692623 100644 --- a/tmk_core/common/arm_atsam/eeprom.c +++ b/tmk_core/common/arm_atsam/eeprom.c @@ -13,24 +13,110 @@   * You should have received a copy of the GNU General Public License   * along with this program.  If not, see <http://www.gnu.org/licenses/>.   */ -  #include "eeprom.h" +#include "debug.h" +#include "samd51j18a.h" +#include "core_cm4.h" +#include "component/nvmctrl.h"  #ifndef EEPROM_SIZE  #    include "eeconfig.h"  #    define EEPROM_SIZE (((EECONFIG_SIZE + 3) / 4) * 4)  // based off eeconfig's current usage, aligned to 4-byte sizes, to deal with LTO  #endif -__attribute__((aligned(4))) static uint8_t buffer[EEPROM_SIZE]; +#ifndef MAX +#    define MAX(X, Y) ((X) > (Y) ? (X) : (Y)) +#endif + +#ifndef BUSY_RETRIES +#    define BUSY_RETRIES 10000 +#endif + +// #define DEBUG_EEPROM_OUTPUT + +/* + * Debug print utils + */ +#if defined(DEBUG_EEPROM_OUTPUT) +#    define eeprom_printf(fmt, ...) xprintf(fmt, ##__VA_ARGS__); +#else /* NO_DEBUG */ +#    define eeprom_printf(fmt, ...) +#endif /* NO_DEBUG */ + +__attribute__((aligned(4))) static uint8_t buffer[EEPROM_SIZE] = {0}; +volatile uint8_t *                         SmartEEPROM8        = (uint8_t *)SEEPROM_ADDR; + +static inline bool eeprom_is_busy(void) { +    int timeout = BUSY_RETRIES; +    while (NVMCTRL->SEESTAT.bit.BUSY && timeout-- > 0) +        ; + +    return NVMCTRL->SEESTAT.bit.BUSY; +} + +static uint32_t get_virtual_eeprom_size(void) { +    // clang-format off +    static const uint32_t VIRTUAL_EEPROM_MAP[11][8] = { +    /*          4    8    16    32    64    128    256    512 */ +    /* 0*/ {   0,    0,    0,    0,    0,     0,     0,     0 }, +    /* 1*/ { 512, 1024, 2048, 4096, 4096,  4096,  4096,  4096 }, +    /* 2*/ { 512, 1024, 2048, 4096, 8192,  8192,  8192,  8192 }, +    /* 3*/ { 512, 1024, 2048, 4096, 8192, 16384, 16384, 16384 }, +    /* 4*/ { 512, 1024, 2048, 4096, 8192, 16384, 16384, 16384 }, +    /* 5*/ { 512, 1024, 2048, 4096, 8192, 16384, 32768, 32768 }, +    /* 6*/ { 512, 1024, 2048, 4096, 8192, 16384, 32768, 32768 }, +    /* 7*/ { 512, 1024, 2048, 4096, 8192, 16384, 32768, 32768 }, +    /* 8*/ { 512, 1024, 2048, 4096, 8192, 16384, 32768, 32768 }, +    /* 9*/ { 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536 }, +    /*10*/ { 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536 }, +    }; +    // clang-format on + +    static uint32_t virtual_eeprom_size = UINT32_MAX; +    if (virtual_eeprom_size == UINT32_MAX) { +        virtual_eeprom_size = VIRTUAL_EEPROM_MAP[NVMCTRL->SEESTAT.bit.PSZ][NVMCTRL->SEESTAT.bit.SBLK]; +    } +    // eeprom_printf("get_virtual_eeprom_size:: %d:%d:%d\n", NVMCTRL->SEESTAT.bit.PSZ, NVMCTRL->SEESTAT.bit.SBLK, virtual_eeprom_size); +    return virtual_eeprom_size; +}  uint8_t eeprom_read_byte(const uint8_t *addr) {      uintptr_t offset = (uintptr_t)addr; -    return buffer[offset]; +    if (offset >= MAX(EEPROM_SIZE, get_virtual_eeprom_size())) { +        eeprom_printf("eeprom_read_byte:: out of bounds\n"); +        return 0x0; +    } + +    if (get_virtual_eeprom_size() == 0) { +        return buffer[offset]; +    } + +    if (eeprom_is_busy()) { +        eeprom_printf("eeprom_write_byte:: timeout\n"); +        return 0x0; +    } + +    return SmartEEPROM8[offset];  }  void eeprom_write_byte(uint8_t *addr, uint8_t value) {      uintptr_t offset = (uintptr_t)addr; -    buffer[offset]   = value; +    if (offset >= MAX(EEPROM_SIZE, get_virtual_eeprom_size())) { +        eeprom_printf("eeprom_write_byte:: out of bounds\n"); +        return; +    } + +    if (get_virtual_eeprom_size() == 0) { +        buffer[offset] = value; +        return; +    } + +    if (eeprom_is_busy()) { +        eeprom_printf("eeprom_write_byte:: timeout\n"); +        return; +    } + +    SmartEEPROM8[offset] = value;  }  uint16_t eeprom_read_word(const uint16_t *addr) { diff --git a/tmk_core/common/avr/suspend.c b/tmk_core/common/avr/suspend.c index 690d7f38ca..b614746e6c 100644 --- a/tmk_core/common/avr/suspend.c +++ b/tmk_core/common/avr/suspend.c @@ -16,25 +16,6 @@  #    include "vusb.h"  #endif -#ifdef BACKLIGHT_ENABLE -#    include "backlight.h" -#endif - -#ifdef AUDIO_ENABLE -#    include "audio.h" -#endif /* AUDIO_ENABLE */ - -#if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE) -#    include "rgblight.h" -#endif - -#ifdef LED_MATRIX_ENABLE -#    include "led_matrix.h" -#endif -#ifdef RGB_MATRIX_ENABLE -#    include "rgb_matrix.h" -#endif -  /** \brief Suspend idle   *   * FIXME: needs doc @@ -50,17 +31,6 @@ void suspend_idle(uint8_t time) {  // TODO: This needs some cleanup -/** \brief Run keyboard level Power down - * - * FIXME: needs doc - */ -__attribute__((weak)) void suspend_power_down_user(void) {} -/** \brief Run keyboard level Power down - * - * FIXME: needs doc - */ -__attribute__((weak)) void suspend_power_down_kb(void) { suspend_power_down_user(); } -  #if !defined(NO_SUSPEND_POWER_DOWN) && defined(WDT_vect)  // clang-format off @@ -135,41 +105,9 @@ void suspend_power_down(void) {      if (!vusb_suspended) return;  #endif -    suspend_power_down_kb(); +    suspend_power_down_quantum();  #ifndef NO_SUSPEND_POWER_DOWN -    // Turn off backlight -#    ifdef BACKLIGHT_ENABLE -    backlight_set(0); -#    endif - -    // Turn off LED indicators -    uint8_t leds_off = 0; -#    if defined(BACKLIGHT_CAPS_LOCK) && defined(BACKLIGHT_ENABLE) -    if (is_backlight_enabled()) { -        // Don't try to turn off Caps Lock indicator as it is backlight and backlight is already off -        leds_off |= (1 << USB_LED_CAPS_LOCK); -    } -#    endif -    led_set(leds_off); - -    // Turn off audio -#    ifdef AUDIO_ENABLE -    stop_all_notes(); -#    endif - -    // Turn off underglow -#    if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE) -    rgblight_suspend(); -#    endif - -#    if defined(LED_MATRIX_ENABLE) -    led_matrix_set_suspend_state(true); -#    endif -#    if defined(RGB_MATRIX_ENABLE) -    rgb_matrix_set_suspend_state(true); -#    endif -      // Enter sleep state if possible (ie, the MCU has a watchdog timeout interrupt)  #    if defined(WDT_vect)      power_down(WDTO_15MS); @@ -189,18 +127,6 @@ bool                       suspend_wakeup_condition(void) {      return false;  } -/** \brief run user level code immediately after wakeup - * - * FIXME: needs doc - */ -__attribute__((weak)) void suspend_wakeup_init_user(void) {} - -/** \brief run keyboard level code immediately after wakeup - * - * FIXME: needs doc - */ -__attribute__((weak)) void suspend_wakeup_init_kb(void) { suspend_wakeup_init_user(); } -  /** \brief run immediately after wakeup   *   * FIXME: needs doc @@ -209,27 +135,7 @@ void suspend_wakeup_init(void) {      // clear keyboard state      clear_keyboard(); -    // Turn on backlight -#ifdef BACKLIGHT_ENABLE -    backlight_init(); -#endif - -    // Restore LED indicators -    led_set(host_keyboard_leds()); - -    // Wake up underglow -#if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE) -    rgblight_wakeup(); -#endif - -#if defined(LED_MATRIX_ENABLE) -    led_matrix_set_suspend_state(false); -#endif -#if defined(RGB_MATRIX_ENABLE) -    rgb_matrix_set_suspend_state(false); -#endif - -    suspend_wakeup_init_kb(); +    suspend_wakeup_init_quantum();  }  #if !defined(NO_SUSPEND_POWER_DOWN) && defined(WDT_vect) diff --git a/tmk_core/common/chibios/_wait.h b/tmk_core/common/chibios/_wait.h index b740afbd24..2f36c64a2e 100644 --- a/tmk_core/common/chibios/_wait.h +++ b/tmk_core/common/chibios/_wait.h @@ -43,8 +43,6 @@ void wait_us(uint16_t duration);  #include "_wait.c" -#define CPU_CLOCK STM32_SYSCLK -  /* For GPIOs on ARM-based MCUs, the input pins are sampled by the clock of the bus   * to which the GPIO is connected.   * The connected buses differ depending on the various series of MCUs. diff --git a/tmk_core/common/chibios/chibios_config.h b/tmk_core/common/chibios/chibios_config.h index 23c65f9428..c35f589557 100644 --- a/tmk_core/common/chibios/chibios_config.h +++ b/tmk_core/common/chibios/chibios_config.h @@ -19,22 +19,33 @@  #    define SPLIT_USB_DETECT  // Force this on when dedicated pin is not used  #endif -#if defined(STM32F1XX) -#    define USE_GPIOV1 -#endif +// STM32 compatibility +#if defined(MCU_STM32) +#    define CPU_CLOCK STM32_SYSCLK -#if defined(STM32F1XX) || defined(STM32F2XX) || defined(STM32F4XX) || defined(STM32L1XX) -#    define USE_I2CV1 -#endif +#    if defined(STM32F1XX) +#        define USE_GPIOV1 +#        define PAL_MODE_ALTERNATE_OPENDRAIN PAL_MODE_STM32_ALTERNATE_OPENDRAIN +#        define PAL_MODE_ALTERNATE_PUSHPULL PAL_MODE_STM32_ALTERNATE_PUSHPULL +#    else +#        define PAL_OUTPUT_TYPE_OPENDRAIN PAL_STM32_OTYPE_OPENDRAIN +#        define PAL_OUTPUT_TYPE_PUSHPULL PAL_STM32_OTYPE_PUSHPULL +#        define PAL_OUTPUT_SPEED_HIGHEST PAL_STM32_OSPEED_HIGHEST +#        define PAL_PUPDR_FLOATING PAL_STM32_PUPDR_FLOATING +#    endif -// teensy -#if defined(K20x) || defined(KL2x) -#    define USE_I2CV1 -#    define USE_I2CV1_CONTRIB  // for some reason a bunch of ChibiOS-Contrib boards only have clock_speed -#    define USE_GPIOV1 -#    define STM32_SYSCLK KINETIS_SYSCLK_FREQUENCY +#    if defined(STM32F1XX) || defined(STM32F2XX) || defined(STM32F4XX) || defined(STM32L1XX) +#        define USE_I2CV1 +#    endif  #endif -#if defined(MK66F18) -#    define STM32_SYSCLK KINETIS_SYSCLK_FREQUENCY -#endif +// teensy compatibility +#if defined(MCU_KINETIS) +#    define CPU_CLOCK KINETIS_SYSCLK_FREQUENCY + +#    if defined(K20x) || defined(KL2x) +#        define USE_I2CV1 +#        define USE_I2CV1_CONTRIB  // for some reason a bunch of ChibiOS-Contrib boards only have clock_speed +#        define USE_GPIOV1 +#    endif +#endif
\ No newline at end of file diff --git a/tmk_core/common/chibios/eeprom_stm32.c b/tmk_core/common/chibios/eeprom_stm32.c index 1fdf8c1e29..acc6a48516 100644 --- a/tmk_core/common/chibios/eeprom_stm32.c +++ b/tmk_core/common/chibios/eeprom_stm32.c @@ -620,48 +620,11 @@ uint16_t EEPROM_ReadDataWord(uint16_t Address) {  }  /***************************************************************************** - *  Wrap library in AVR style functions. + *  Bind to eeprom_driver.c   *******************************************************************************/ -uint8_t eeprom_read_byte(const uint8_t *Address) { return EEPROM_ReadDataByte((const uintptr_t)Address); } +void eeprom_driver_init(void) { EEPROM_Init(); } -void eeprom_write_byte(uint8_t *Address, uint8_t Value) { EEPROM_WriteDataByte((uintptr_t)Address, Value); } - -void eeprom_update_byte(uint8_t *Address, uint8_t Value) { EEPROM_WriteDataByte((uintptr_t)Address, Value); } - -uint16_t eeprom_read_word(const uint16_t *Address) { return EEPROM_ReadDataWord((const uintptr_t)Address); } - -void eeprom_write_word(uint16_t *Address, uint16_t Value) { EEPROM_WriteDataWord((uintptr_t)Address, Value); } - -void eeprom_update_word(uint16_t *Address, uint16_t Value) { EEPROM_WriteDataWord((uintptr_t)Address, Value); } - -uint32_t eeprom_read_dword(const uint32_t *Address) { -    const uint16_t p = (const uintptr_t)Address; -    /* Check word alignment */ -    if (p % 2) { -        /* Not aligned */ -        return (uint32_t)EEPROM_ReadDataByte(p) | (uint32_t)(EEPROM_ReadDataWord(p + 1) << 8) | (uint32_t)(EEPROM_ReadDataByte(p + 3) << 24); -    } else { -        /* Aligned */ -        return EEPROM_ReadDataWord(p) | (EEPROM_ReadDataWord(p + 2) << 16); -    } -} - -void eeprom_write_dword(uint32_t *Address, uint32_t Value) { -    uint16_t p = (const uintptr_t)Address; -    /* Check word alignment */ -    if (p % 2) { -        /* Not aligned */ -        EEPROM_WriteDataByte(p, (uint8_t)Value); -        EEPROM_WriteDataWord(p + 1, (uint16_t)(Value >> 8)); -        EEPROM_WriteDataByte(p + 3, (uint8_t)(Value >> 24)); -    } else { -        /* Aligned */ -        EEPROM_WriteDataWord(p, (uint16_t)Value); -        EEPROM_WriteDataWord(p + 2, (uint16_t)(Value >> 16)); -    } -} - -void eeprom_update_dword(uint32_t *Address, uint32_t Value) { eeprom_write_dword(Address, Value); } +void eeprom_driver_erase(void) { EEPROM_Erase(); }  void eeprom_read_block(void *buf, const void *addr, size_t len) {      const uint8_t *src  = (const uint8_t *)addr; @@ -670,14 +633,14 @@ void eeprom_read_block(void *buf, const void *addr, size_t len) {      /* Check word alignment */      if (len && (uintptr_t)src % 2) {          /* Read the unaligned first byte */ -        *dest++ = eeprom_read_byte(src++); +        *dest++ = EEPROM_ReadDataByte((const uintptr_t)src++);          --len;      }      uint16_t value;      bool     aligned = ((uintptr_t)dest % 2 == 0);      while (len > 1) { -        value = eeprom_read_word((uint16_t *)src); +        value = EEPROM_ReadDataWord((const uintptr_t)((uint16_t *)src));          if (aligned) {              *(uint16_t *)dest = value;              dest += 2; @@ -689,7 +652,7 @@ void eeprom_read_block(void *buf, const void *addr, size_t len) {          len -= 2;      }      if (len) { -        *dest = eeprom_read_byte(src); +        *dest = EEPROM_ReadDataByte((const uintptr_t)src);      }  } @@ -700,7 +663,7 @@ void eeprom_write_block(const void *buf, void *addr, size_t len) {      /* Check word alignment */      if (len && (uintptr_t)dest % 2) {          /* Write the unaligned first byte */ -        eeprom_write_byte(dest++, *src++); +        EEPROM_WriteDataByte((uintptr_t)dest++, *src++);          --len;      } @@ -712,15 +675,13 @@ void eeprom_write_block(const void *buf, void *addr, size_t len) {          } else {              value = *(uint8_t *)src | (*(uint8_t *)(src + 1) << 8);          } -        eeprom_write_word((uint16_t *)dest, value); +        EEPROM_WriteDataWord((uintptr_t)((uint16_t *)dest), value);          dest += 2;          src += 2;          len -= 2;      }      if (len) { -        eeprom_write_byte(dest, *src); +        EEPROM_WriteDataByte((uintptr_t)dest, *src);      }  } - -void eeprom_update_block(const void *buf, void *addr, size_t len) { eeprom_write_block(buf, addr, len); } diff --git a/tmk_core/common/chibios/eeprom_stm32_defs.h b/tmk_core/common/chibios/eeprom_stm32_defs.h index 22b4ab858e..3499796264 100644 --- a/tmk_core/common/chibios/eeprom_stm32_defs.h +++ b/tmk_core/common/chibios/eeprom_stm32_defs.h @@ -32,6 +32,13 @@  #        ifndef FEE_PAGE_COUNT  #            define FEE_PAGE_COUNT 4  // How many pages are used  #        endif +#    elif defined(STM32F401xC) || defined(STM32F401xE) || defined(STM32F405xG) || defined(STM32F411xE) +#        ifndef FEE_PAGE_SIZE +#            define FEE_PAGE_SIZE 0x4000  // Page size = 16KByte +#        endif +#        ifndef FEE_PAGE_COUNT +#            define FEE_PAGE_COUNT 1  // How many pages are used +#        endif  #    endif  #endif @@ -40,17 +47,21 @@  #        define FEE_MCU_FLASH_SIZE 32  // Size in Kb  #    elif defined(STM32F103xB) || defined(STM32F072xB) || defined(STM32F070xB)  #        define FEE_MCU_FLASH_SIZE 128  // Size in Kb -#    elif defined(STM32F303xC) +#    elif defined(STM32F303xC) || defined(STM32F401xC)  #        define FEE_MCU_FLASH_SIZE 256  // Size in Kb -#    elif defined(STM32F103xE) +#    elif defined(STM32F103xE) || defined(STM32F401xE) || defined(STM32F411xE)  #        define FEE_MCU_FLASH_SIZE 512  // Size in Kb +#    elif defined(STM32F405xG) +#        define FEE_MCU_FLASH_SIZE 1024  // Size in Kb  #    endif  #endif  /* Start of the emulated eeprom */  #if !defined(FEE_PAGE_BASE_ADDRESS) -#    if 0 -/* TODO: Add support for F4 */ +#    if defined(STM32F401xC) || defined(STM32F401xE) || defined(STM32F405xG) || defined(STM32F411xE) +#        ifndef FEE_PAGE_BASE_ADDRESS +#            define FEE_PAGE_BASE_ADDRESS 0x08004000  // bodge to force 2nd 16k page +#        endif  #    else  #        ifndef FEE_FLASH_BASE  #            define FEE_FLASH_BASE 0x8000000 diff --git a/tmk_core/common/chibios/flash_stm32.c b/tmk_core/common/chibios/flash_stm32.c index 6b80ff71c3..8f10903d3d 100644 --- a/tmk_core/common/chibios/flash_stm32.c +++ b/tmk_core/common/chibios/flash_stm32.c @@ -23,6 +23,29 @@  #    define FLASH_SR_WRPERR FLASH_SR_WRPRTERR  #endif +#if defined(EEPROM_EMU_STM32F401xC) +#    define FLASH_SR_PGERR (FLASH_SR_PGSERR | FLASH_SR_PGPERR | FLASH_SR_PGAERR) + +#    define FLASH_KEY1 0x45670123U +#    define FLASH_KEY2 0xCDEF89ABU + +static uint8_t ADDR2PAGE(uint32_t Page_Address) { +    switch (Page_Address) { +        case 0x08000000 ... 0x08003FFF: +            return 0; +        case 0x08004000 ... 0x08007FFF: +            return 1; +        case 0x08008000 ... 0x0800BFFF: +            return 2; +        case 0x0800C000 ... 0x0800FFFF: +            return 3; +    } + +    // TODO: bad times... +    return 7; +} +#endif +  /* Delay definition */  #define EraseTimeout ((uint32_t)0x00000FFF)  #define ProgramTimeout ((uint32_t)0x0000001F) @@ -53,7 +76,9 @@ FLASH_Status FLASH_GetStatus(void) {      if ((FLASH->SR & FLASH_SR_WRPERR) != 0) return FLASH_ERROR_WRP; +#if defined(FLASH_OBR_OPTERR)      if ((FLASH->SR & FLASH_OBR_OPTERR) != 0) return FLASH_ERROR_OPT; +#endif      return FLASH_COMPLETE;  } @@ -95,15 +120,24 @@ FLASH_Status FLASH_ErasePage(uint32_t Page_Address) {      if (status == FLASH_COMPLETE) {          /* if the previous operation is completed, proceed to erase the page */ +#if defined(FLASH_CR_SNB) +        FLASH->CR &= ~FLASH_CR_SNB; +        FLASH->CR |= FLASH_CR_SER | (ADDR2PAGE(Page_Address) << FLASH_CR_SNB_Pos); +#else          FLASH->CR |= FLASH_CR_PER;          FLASH->AR = Page_Address; +#endif          FLASH->CR |= FLASH_CR_STRT;          /* Wait for last operation to be completed */          status = FLASH_WaitForLastOperation(EraseTimeout);          if (status != FLASH_TIMEOUT) { -            /* if the erase operation is completed, disable the PER Bit */ +            /* if the erase operation is completed, disable the configured Bits */ +#if defined(FLASH_CR_SNB) +            FLASH->CR &= ~(FLASH_CR_SER | FLASH_CR_SNB); +#else              FLASH->CR &= ~FLASH_CR_PER; +#endif          }          FLASH->SR = (FLASH_SR_EOP | FLASH_SR_PGERR | FLASH_SR_WRPERR);      } @@ -126,6 +160,11 @@ FLASH_Status FLASH_ProgramHalfWord(uint32_t Address, uint16_t Data) {          status = FLASH_WaitForLastOperation(ProgramTimeout);          if (status == FLASH_COMPLETE) {              /* if the previous operation is completed, proceed to program the new data */ + +#if defined(FLASH_CR_PSIZE) +            FLASH->CR &= ~FLASH_CR_PSIZE; +            FLASH->CR |= FLASH_CR_PSIZE_0; +#endif              FLASH->CR |= FLASH_CR_PG;              *(__IO uint16_t*)Address = Data;              /* Wait for last operation to be completed */ diff --git a/tmk_core/common/chibios/suspend.c b/tmk_core/common/chibios/suspend.c index 38517e06f0..9310a99920 100644 --- a/tmk_core/common/chibios/suspend.c +++ b/tmk_core/common/chibios/suspend.c @@ -7,30 +7,12 @@  #include "action.h"  #include "action_util.h"  #include "mousekey.h" +#include "programmable_button.h"  #include "host.h"  #include "suspend.h"  #include "led.h"  #include "wait.h" -#ifdef AUDIO_ENABLE -#    include "audio.h" -#endif /* AUDIO_ENABLE */ - -#ifdef BACKLIGHT_ENABLE -#    include "backlight.h" -#endif - -#if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE) -#    include "rgblight.h" -#endif - -#ifdef LED_MATRIX_ENABLE -#    include "led_matrix.h" -#endif -#ifdef RGB_MATRIX_ENABLE -#    include "rgb_matrix.h" -#endif -  /** \brief suspend idle   *   * FIXME: needs doc @@ -40,61 +22,12 @@ void suspend_idle(uint8_t time) {      wait_ms(time);  } -/** \brief Run keyboard level Power down - * - * FIXME: needs doc - */ -__attribute__((weak)) void suspend_power_down_user(void) {} -/** \brief Run keyboard level Power down - * - * FIXME: needs doc - */ -__attribute__((weak)) void suspend_power_down_kb(void) { suspend_power_down_user(); } -  /** \brief suspend power down   *   * FIXME: needs doc   */  void suspend_power_down(void) { -#ifdef BACKLIGHT_ENABLE -    backlight_set(0); -#endif - -#ifdef LED_MATRIX_ENABLE -    led_matrix_task(); -#endif -#ifdef RGB_MATRIX_ENABLE -    rgb_matrix_task(); -#endif - -    // Turn off LED indicators -    uint8_t leds_off = 0; -#if defined(BACKLIGHT_CAPS_LOCK) && defined(BACKLIGHT_ENABLE) -    if (is_backlight_enabled()) { -        // Don't try to turn off Caps Lock indicator as it is backlight and backlight is already off -        leds_off |= (1 << USB_LED_CAPS_LOCK); -    } -#endif -    led_set(leds_off); - -    // TODO: figure out what to power down and how -    // shouldn't power down TPM/FTM if we want a breathing LED -    // also shouldn't power down USB -#if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE) -    rgblight_suspend(); -#endif - -#if defined(LED_MATRIX_ENABLE) -    led_matrix_set_suspend_state(true); -#endif -#if defined(RGB_MATRIX_ENABLE) -    rgb_matrix_set_suspend_state(true); -#endif -#ifdef AUDIO_ENABLE -    stop_all_notes(); -#endif /* AUDIO_ENABLE */ - -    suspend_power_down_kb(); +    suspend_power_down_quantum();      // on AVR, this enables the watchdog for 15ms (max), and goes to      // SLEEP_MODE_PWR_DOWN @@ -147,23 +80,13 @@ void suspend_wakeup_init(void) {  #ifdef MOUSEKEY_ENABLE      mousekey_clear();  #endif /* MOUSEKEY_ENABLE */ +#ifdef PROGRAMMABLE_BUTTON_ENABLE +    programmable_button_clear(); +#endif /* PROGRAMMABLE_BUTTON_ENABLE */  #ifdef EXTRAKEY_ENABLE      host_system_send(0);      host_consumer_send(0);  #endif /* EXTRAKEY_ENABLE */ -#ifdef BACKLIGHT_ENABLE -    backlight_init(); -#endif /* BACKLIGHT_ENABLE */ -    led_set(host_keyboard_leds()); -#if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE) -    rgblight_wakeup(); -#endif -#if defined(LED_MATRIX_ENABLE) -    led_matrix_set_suspend_state(false); -#endif -#if defined(RGB_MATRIX_ENABLE) -    rgb_matrix_set_suspend_state(false); -#endif -    suspend_wakeup_init_kb(); +    suspend_wakeup_init_quantum();  } diff --git a/tmk_core/common/host.c b/tmk_core/common/host.c index f0c396b189..56d4bb0847 100644 --- a/tmk_core/common/host.c +++ b/tmk_core/common/host.c @@ -30,8 +30,9 @@ extern keymap_config_t keymap_config;  #endif  static host_driver_t *driver; -static uint16_t       last_system_report   = 0; -static uint16_t       last_consumer_report = 0; +static uint16_t       last_system_report              = 0; +static uint16_t       last_consumer_report            = 0; +static uint32_t       last_programmable_button_report = 0;  void host_set_driver(host_driver_t *d) { driver = d; } @@ -122,6 +123,16 @@ void host_digitizer_send(digitizer_t *digitizer) {  __attribute__((weak)) void send_digitizer(report_digitizer_t *report) {} +void host_programmable_button_send(uint32_t report) { +    if (report == last_programmable_button_report) return; +    last_programmable_button_report = report; + +    if (!driver) return; +    (*driver->send_programmable_button)(report); +} +  uint16_t host_last_system_report(void) { return last_system_report; }  uint16_t host_last_consumer_report(void) { return last_consumer_report; } + +uint32_t host_last_programmable_button_report(void) { return last_programmable_button_report; } diff --git a/tmk_core/common/host.h b/tmk_core/common/host.h index 2cffef6e15..6b15f0d0c1 100644 --- a/tmk_core/common/host.h +++ b/tmk_core/common/host.h @@ -47,9 +47,11 @@ void    host_keyboard_send(report_keyboard_t *report);  void    host_mouse_send(report_mouse_t *report);  void    host_system_send(uint16_t data);  void    host_consumer_send(uint16_t data); +void    host_programmable_button_send(uint32_t data);  uint16_t host_last_system_report(void);  uint16_t host_last_consumer_report(void); +uint32_t host_last_programmable_button_report(void);  #ifdef __cplusplus  } diff --git a/tmk_core/common/host_driver.h b/tmk_core/common/host_driver.h index 2aebca043d..affd0dcb34 100644 --- a/tmk_core/common/host_driver.h +++ b/tmk_core/common/host_driver.h @@ -29,6 +29,7 @@ typedef struct {      void (*send_mouse)(report_mouse_t *);      void (*send_system)(uint16_t);      void (*send_consumer)(uint16_t); +    void (*send_programmable_button)(uint32_t);  } host_driver_t;  void send_digitizer(report_digitizer_t *report);
\ No newline at end of file diff --git a/tmk_core/common/report.h b/tmk_core/common/report.h index f2223e8063..1adc892f3b 100644 --- a/tmk_core/common/report.h +++ b/tmk_core/common/report.h @@ -29,6 +29,7 @@ enum hid_report_ids {      REPORT_ID_MOUSE,      REPORT_ID_SYSTEM,      REPORT_ID_CONSUMER, +    REPORT_ID_PROGRAMMABLE_BUTTON,      REPORT_ID_NKRO,      REPORT_ID_JOYSTICK,      REPORT_ID_DIGITIZER @@ -196,6 +197,11 @@ typedef struct {  } __attribute__((packed)) report_extra_t;  typedef struct { +    uint8_t  report_id; +    uint32_t usage; +} __attribute__((packed)) report_programmable_button_t; + +typedef struct {  #ifdef MOUSE_SHARED_EP      uint8_t report_id;  #endif diff --git a/tmk_core/common/suspend.h b/tmk_core/common/suspend.h index 95845e4b63..081735f90e 100644 --- a/tmk_core/common/suspend.h +++ b/tmk_core/common/suspend.h @@ -10,8 +10,10 @@ void suspend_wakeup_init(void);  void suspend_wakeup_init_user(void);  void suspend_wakeup_init_kb(void); +void suspend_wakeup_init_quantum(void);  void suspend_power_down_user(void);  void suspend_power_down_kb(void); +void suspend_power_down_quantum(void);  #ifndef USB_SUSPEND_WAKEUP_DELAY  #    define USB_SUSPEND_WAKEUP_DELAY 0 diff --git a/tmk_core/common/sync_timer.c b/tmk_core/common/sync_timer.c index 68b92d8b43..de24b463b6 100644 --- a/tmk_core/common/sync_timer.c +++ b/tmk_core/common/sync_timer.c @@ -26,7 +26,7 @@ SOFTWARE.  #include "sync_timer.h"  #include "keyboard.h" -#if (defined(SPLIT_KEYBOARD) || defined(SERIAL_LINK_ENABLE)) && !defined(DISABLE_SYNC_TIMER) +#if defined(SPLIT_KEYBOARD) && !defined(DISABLE_SYNC_TIMER)  volatile int32_t sync_timer_ms;  void sync_timer_init(void) { sync_timer_ms = 0; } diff --git a/tmk_core/common/sync_timer.h b/tmk_core/common/sync_timer.h index 744e2b50d5..9ddef45bb2 100644 --- a/tmk_core/common/sync_timer.h +++ b/tmk_core/common/sync_timer.h @@ -32,7 +32,7 @@ SOFTWARE.  extern "C" {  #endif -#if (defined(SPLIT_KEYBOARD) || defined(SERIAL_LINK_ENABLE)) && !defined(DISABLE_SYNC_TIMER) +#if defined(SPLIT_KEYBOARD) && !defined(DISABLE_SYNC_TIMER)  void     sync_timer_init(void);  void     sync_timer_update(uint32_t time);  uint16_t sync_timer_read(void); diff --git a/tmk_core/common/test/rules.mk b/tmk_core/common/test/rules.mk index 48632a095b..73d2302da7 100644 --- a/tmk_core/common/test/rules.mk +++ b/tmk_core/common/test/rules.mk @@ -16,6 +16,7 @@ eeprom_stm32_tiny_INC := $(eeprom_stm32_INC)  eeprom_stm32_large_INC := $(eeprom_stm32_INC)  eeprom_stm32_SRC := \ +	$(TOP_DIR)/drivers/eeprom/eeprom_driver.c \  	$(TMK_PATH)/common/test/eeprom_stm32_tests.cpp \  	$(TMK_PATH)/common/test/flash_stm32_mock.c \  	$(TMK_PATH)/common/chibios/eeprom_stm32.c | 
