summaryrefslogtreecommitdiff
path: root/platforms/arm_atsam
diff options
context:
space:
mode:
Diffstat (limited to 'platforms/arm_atsam')
-rw-r--r--platforms/arm_atsam/bootloader.c57
-rw-r--r--platforms/arm_atsam/bootloaders/md_boot.c65
-rw-r--r--platforms/arm_atsam/eeprom_samd.c (renamed from platforms/arm_atsam/eeprom.c)10
-rw-r--r--platforms/arm_atsam/eeprom_samd.h8
-rw-r--r--platforms/arm_atsam/gpio.h12
-rw-r--r--platforms/arm_atsam/suspend.c45
-rw-r--r--platforms/arm_atsam/timer.c32
7 files changed, 110 insertions, 119 deletions
diff --git a/platforms/arm_atsam/bootloader.c b/platforms/arm_atsam/bootloader.c
deleted file mode 100644
index 9015b00aab..0000000000
--- a/platforms/arm_atsam/bootloader.c
+++ /dev/null
@@ -1,57 +0,0 @@
-/* Copyright 2017 Fred Sundvik
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * 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 "bootloader.h"
-#include "samd51j18a.h"
-#include "md_bootloader.h"
-
-// Set watchdog timer to reset. Directs the bootloader to stay in programming mode.
-void bootloader_jump(void) {
-#ifdef KEYBOARD_massdrop_ctrl
- // CTRL keyboards released with bootloader version below must use RAM method. Otherwise use WDT method.
- uint8_t ver_ram_method[] = "v2.18Jun 22 2018 17:28:08"; // The version to match (NULL terminated by compiler)
- uint8_t *ver_check = ver_ram_method; // Pointer to version match string for traversal
- uint8_t *ver_rom = (uint8_t *)0x21A0; // Pointer to address in ROM where this specific bootloader version would exist
-
- while (*ver_check && *ver_rom == *ver_check) { // While there are check version characters to match and bootloader's version matches check's version
- ver_check++; // Move check version pointer to next character
- ver_rom++; // Move ROM version pointer to next character
- }
-
- if (!*ver_check) { // If check version pointer is NULL, all characters have matched
- *MAGIC_ADDR = BOOTLOADER_MAGIC; // Set magic number into RAM
- NVIC_SystemReset(); // Perform system reset
- while (1) {
- } // Won't get here
- }
-#endif
-
- WDT->CTRLA.bit.ENABLE = 0;
- while (WDT->SYNCBUSY.bit.ENABLE) {
- }
- while (WDT->CTRLA.bit.ENABLE) {
- }
- WDT->CONFIG.bit.WINDOW = 0;
- WDT->CONFIG.bit.PER = 0;
- WDT->EWCTRL.bit.EWOFFSET = 0;
- WDT->CTRLA.bit.ENABLE = 1;
- while (WDT->SYNCBUSY.bit.ENABLE) {
- }
- while (!WDT->CTRLA.bit.ENABLE) {
- }
- while (1) {
- } // Wait on timeout
-}
diff --git a/platforms/arm_atsam/bootloaders/md_boot.c b/platforms/arm_atsam/bootloaders/md_boot.c
new file mode 100644
index 0000000000..32cf850448
--- /dev/null
+++ b/platforms/arm_atsam/bootloaders/md_boot.c
@@ -0,0 +1,65 @@
+/* Copyright 2017 Fred Sundvik
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * 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 "bootloader.h"
+
+#include "samd51j18a.h"
+
+// WARNING: These are only for CTRL bootloader release "v2.18Jun 22 2018 17:28:08" for bootloader_jump support
+extern uint32_t _eram;
+#define BOOTLOADER_MAGIC 0x3B9ACA00
+#define MAGIC_ADDR (uint32_t *)((intptr_t)(&_eram) - 4)
+
+// CTRL keyboards released with bootloader version below must use RAM method. Otherwise use WDT method.
+void bootloader_jump(void) {
+#ifdef KEYBOARD_massdrop_ctrl
+ uint8_t ver_ram_method[] = "v2.18Jun 22 2018 17:28:08"; // The version to match (NULL terminated by compiler)
+ uint8_t *ver_check = ver_ram_method; // Pointer to version match string for traversal
+ uint8_t *ver_rom = (uint8_t *)0x21A0; // Pointer to address in ROM where this specific bootloader version would exist
+
+ while (*ver_check && *ver_rom == *ver_check) { // While there are check version characters to match and bootloader's version matches check's version
+ ver_check++; // Move check version pointer to next character
+ ver_rom++; // Move ROM version pointer to next character
+ }
+
+ if (!*ver_check) { // If check version pointer is NULL, all characters have matched
+ *MAGIC_ADDR = BOOTLOADER_MAGIC; // Set magic number into RAM
+ NVIC_SystemReset(); // Perform system reset
+ while (1)
+ ; // Won't get here
+ }
+#endif
+
+ // Set watchdog timer to reset. Directs the bootloader to stay in programming mode.
+ WDT->CTRLA.bit.ENABLE = 0;
+
+ while (WDT->SYNCBUSY.bit.ENABLE)
+ ;
+ while (WDT->CTRLA.bit.ENABLE)
+ ;
+
+ WDT->CONFIG.bit.WINDOW = 0;
+ WDT->CONFIG.bit.PER = 0;
+ WDT->EWCTRL.bit.EWOFFSET = 0;
+ WDT->CTRLA.bit.ENABLE = 1;
+
+ while (WDT->SYNCBUSY.bit.ENABLE)
+ ;
+ while (!WDT->CTRLA.bit.ENABLE)
+ ;
+ while (1)
+ ; // Wait on timeout
+}
diff --git a/platforms/arm_atsam/eeprom.c b/platforms/arm_atsam/eeprom_samd.c
index ff1a692623..1c1e031e5d 100644
--- a/platforms/arm_atsam/eeprom.c
+++ b/platforms/arm_atsam/eeprom_samd.c
@@ -18,11 +18,7 @@
#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
+#include "eeprom_samd.h"
#ifndef MAX
# define MAX(X, Y) ((X) > (Y) ? (X) : (Y))
@@ -159,7 +155,9 @@ void eeprom_write_block(const void *buf, void *addr, size_t len) {
}
}
-void eeprom_update_byte(uint8_t *addr, uint8_t value) { eeprom_write_byte(addr, value); }
+void eeprom_update_byte(uint8_t *addr, uint8_t value) {
+ eeprom_write_byte(addr, value);
+}
void eeprom_update_word(uint16_t *addr, uint16_t value) {
uint8_t *p = (uint8_t *)addr;
diff --git a/platforms/arm_atsam/eeprom_samd.h b/platforms/arm_atsam/eeprom_samd.h
new file mode 100644
index 0000000000..878e72865c
--- /dev/null
+++ b/platforms/arm_atsam/eeprom_samd.h
@@ -0,0 +1,8 @@
+// Copyright 2022 Nick Brassel (@tzarc)
+// SPDX-License-Identifier: GPL-2.0-or-later
+#pragma once
+
+#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
diff --git a/platforms/arm_atsam/gpio.h b/platforms/arm_atsam/gpio.h
index 915ed0ef4f..a42aaff54d 100644
--- a/platforms/arm_atsam/gpio.h
+++ b/platforms/arm_atsam/gpio.h
@@ -22,9 +22,9 @@
typedef uint8_t pin_t;
-#define SAMD_PORT(pin) ((pin & 0x20) >> 5)
-#define SAMD_PIN(pin) (pin & 0x1f)
-#define SAMD_PIN_MASK(pin) (1 << (pin & 0x1f))
+#define SAMD_PORT(pin) (((pin)&0x20) >> 5)
+#define SAMD_PIN(pin) ((pin)&0x1f)
+#define SAMD_PIN_MASK(pin) (1 << ((pin)&0x1f))
#define setPinInput(pin) \
do { \
@@ -48,12 +48,16 @@ typedef uint8_t pin_t;
PORT->Group[SAMD_PORT(pin)].PINCFG[SAMD_PIN(pin)].bit.PULLEN = 1; \
} while (0)
-#define setPinOutput(pin) \
+#define setPinOutputPushPull(pin) \
do { \
PORT->Group[SAMD_PORT(pin)].DIRSET.reg = SAMD_PIN_MASK(pin); \
PORT->Group[SAMD_PORT(pin)].OUTCLR.reg = SAMD_PIN_MASK(pin); \
} while (0)
+#define setPinOutputOpenDrain(pin) _Static_assert(0, "arm_atsam platform does not implement an open-drain output")
+
+#define setPinOutput(pin) setPinOutputPushPull(pin)
+
#define writePinHigh(pin) \
do { \
PORT->Group[SAMD_PORT(pin)].OUTSET.reg = SAMD_PIN_MASK(pin); \
diff --git a/platforms/arm_atsam/suspend.c b/platforms/arm_atsam/suspend.c
index e51426128d..242e9c91a2 100644
--- a/platforms/arm_atsam/suspend.c
+++ b/platforms/arm_atsam/suspend.c
@@ -3,61 +3,18 @@
#include "md_rgb_matrix.h"
#include "suspend.h"
-/** \brief Suspend idle
- *
- * FIXME: needs doc
- */
-void suspend_idle(uint8_t time) { /* Note: Not used anywhere currently */
-}
-
-/** \brief Run user 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 RGB_MATRIX_ENABLE
- I2C3733_Control_Set(0); // Disable LED driver
+ I2C3733_Control_Set(0); // Disable LED driver
#endif
suspend_power_down_kb();
}
-__attribute__((weak)) void matrix_power_up(void) {}
-__attribute__((weak)) void matrix_power_down(void) {}
-bool suspend_wakeup_condition(void) {
- matrix_power_up();
- matrix_scan();
- matrix_power_down();
- for (uint8_t r = 0; r < MATRIX_ROWS; r++) {
- if (matrix_get_row(r)) return true;
- }
- 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
diff --git a/platforms/arm_atsam/timer.c b/platforms/arm_atsam/timer.c
index b835dd5e75..cf01e3625e 100644
--- a/platforms/arm_atsam/timer.c
+++ b/platforms/arm_atsam/timer.c
@@ -2,18 +2,34 @@
#include "timer.h"
#include "tmk_core/protocol/arm_atsam/clks.h"
-void set_time(uint64_t tset) { ms_clk = tset; }
+void set_time(uint64_t tset) {
+ ms_clk = tset;
+}
-void timer_init(void) { timer_clear(); }
+void timer_init(void) {
+ timer_clear();
+}
-uint16_t timer_read(void) { return (uint16_t)ms_clk; }
+uint16_t timer_read(void) {
+ return (uint16_t)ms_clk;
+}
-uint32_t timer_read32(void) { return (uint32_t)ms_clk; }
+uint32_t timer_read32(void) {
+ return (uint32_t)ms_clk;
+}
-uint64_t timer_read64(void) { return ms_clk; }
+uint64_t timer_read64(void) {
+ return ms_clk;
+}
-uint16_t timer_elapsed(uint16_t tlast) { return TIMER_DIFF_16(timer_read(), tlast); }
+uint16_t timer_elapsed(uint16_t tlast) {
+ return TIMER_DIFF_16(timer_read(), tlast);
+}
-uint32_t timer_elapsed32(uint32_t tlast) { return TIMER_DIFF_32(timer_read32(), tlast); }
+uint32_t timer_elapsed32(uint32_t tlast) {
+ return TIMER_DIFF_32(timer_read32(), tlast);
+}
-void timer_clear(void) { set_time(0); }
+void timer_clear(void) {
+ set_time(0);
+}