diff options
Diffstat (limited to 'tmk_core/common')
| -rw-r--r-- | tmk_core/common/arm_atsam/bootloader.c | 19 | ||||
| -rw-r--r-- | tmk_core/common/arm_atsam/eeprom.c | 98 | ||||
| -rw-r--r-- | tmk_core/common/arm_atsam/printf.h | 8 | ||||
| -rw-r--r-- | tmk_core/common/arm_atsam/suspend.c | 17 | ||||
| -rw-r--r-- | tmk_core/common/arm_atsam/timer.c | 59 | ||||
| -rw-r--r-- | tmk_core/common/print.h | 30 | ||||
| -rw-r--r-- | tmk_core/common/report.h | 5 |
7 files changed, 235 insertions, 1 deletions
diff --git a/tmk_core/common/arm_atsam/bootloader.c b/tmk_core/common/arm_atsam/bootloader.c new file mode 100644 index 000000000..5155d9ff0 --- /dev/null +++ b/tmk_core/common/arm_atsam/bootloader.c | |||
| @@ -0,0 +1,19 @@ | |||
| 1 | /* Copyright 2017 Fred Sundvik | ||
| 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 | #include "bootloader.h" | ||
| 18 | |||
| 19 | void bootloader_jump(void) {} | ||
diff --git a/tmk_core/common/arm_atsam/eeprom.c b/tmk_core/common/arm_atsam/eeprom.c new file mode 100644 index 000000000..61cc039ef --- /dev/null +++ b/tmk_core/common/arm_atsam/eeprom.c | |||
| @@ -0,0 +1,98 @@ | |||
| 1 | /* Copyright 2017 Fred Sundvik | ||
| 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 | #include "eeprom.h" | ||
| 18 | |||
| 19 | #define EEPROM_SIZE 32 | ||
| 20 | |||
| 21 | static uint8_t buffer[EEPROM_SIZE]; | ||
| 22 | |||
| 23 | uint8_t eeprom_read_byte(const uint8_t *addr) { | ||
| 24 | uintptr_t offset = (uintptr_t)addr; | ||
| 25 | return buffer[offset]; | ||
| 26 | } | ||
| 27 | |||
| 28 | void eeprom_write_byte(uint8_t *addr, uint8_t value) { | ||
| 29 | uintptr_t offset = (uintptr_t)addr; | ||
| 30 | buffer[offset] = value; | ||
| 31 | } | ||
| 32 | |||
| 33 | uint16_t eeprom_read_word(const uint16_t *addr) { | ||
| 34 | const uint8_t *p = (const uint8_t *)addr; | ||
| 35 | return eeprom_read_byte(p) | (eeprom_read_byte(p+1) << 8); | ||
| 36 | } | ||
| 37 | |||
| 38 | uint32_t eeprom_read_dword(const uint32_t *addr) { | ||
| 39 | const uint8_t *p = (const uint8_t *)addr; | ||
| 40 | return eeprom_read_byte(p) | (eeprom_read_byte(p+1) << 8) | ||
| 41 | | (eeprom_read_byte(p+2) << 16) | (eeprom_read_byte(p+3) << 24); | ||
| 42 | } | ||
| 43 | |||
| 44 | void eeprom_read_block(void *buf, const void *addr, uint32_t len) { | ||
| 45 | const uint8_t *p = (const uint8_t *)addr; | ||
| 46 | uint8_t *dest = (uint8_t *)buf; | ||
| 47 | while (len--) { | ||
| 48 | *dest++ = eeprom_read_byte(p++); | ||
| 49 | } | ||
| 50 | } | ||
| 51 | |||
| 52 | void eeprom_write_word(uint16_t *addr, uint16_t value) { | ||
| 53 | uint8_t *p = (uint8_t *)addr; | ||
| 54 | eeprom_write_byte(p++, value); | ||
| 55 | eeprom_write_byte(p, value >> 8); | ||
| 56 | } | ||
| 57 | |||
| 58 | void eeprom_write_dword(uint32_t *addr, uint32_t value) { | ||
| 59 | uint8_t *p = (uint8_t *)addr; | ||
| 60 | eeprom_write_byte(p++, value); | ||
| 61 | eeprom_write_byte(p++, value >> 8); | ||
| 62 | eeprom_write_byte(p++, value >> 16); | ||
| 63 | eeprom_write_byte(p, value >> 24); | ||
| 64 | } | ||
| 65 | |||
| 66 | void eeprom_write_block(const void *buf, void *addr, uint32_t len) { | ||
| 67 | uint8_t *p = (uint8_t *)addr; | ||
| 68 | const uint8_t *src = (const uint8_t *)buf; | ||
| 69 | while (len--) { | ||
| 70 | eeprom_write_byte(p++, *src++); | ||
| 71 | } | ||
| 72 | } | ||
| 73 | |||
| 74 | void eeprom_update_byte(uint8_t *addr, uint8_t value) { | ||
| 75 | eeprom_write_byte(addr, value); | ||
| 76 | } | ||
| 77 | |||
| 78 | void eeprom_update_word(uint16_t *addr, uint16_t value) { | ||
| 79 | uint8_t *p = (uint8_t *)addr; | ||
| 80 | eeprom_write_byte(p++, value); | ||
| 81 | eeprom_write_byte(p, value >> 8); | ||
| 82 | } | ||
| 83 | |||
| 84 | void eeprom_update_dword(uint32_t *addr, uint32_t value) { | ||
| 85 | uint8_t *p = (uint8_t *)addr; | ||
| 86 | eeprom_write_byte(p++, value); | ||
| 87 | eeprom_write_byte(p++, value >> 8); | ||
| 88 | eeprom_write_byte(p++, value >> 16); | ||
| 89 | eeprom_write_byte(p, value >> 24); | ||
| 90 | } | ||
| 91 | |||
| 92 | void eeprom_update_block(const void *buf, void *addr, uint32_t len) { | ||
| 93 | uint8_t *p = (uint8_t *)addr; | ||
| 94 | const uint8_t *src = (const uint8_t *)buf; | ||
| 95 | while (len--) { | ||
| 96 | eeprom_write_byte(p++, *src++); | ||
| 97 | } | ||
| 98 | } | ||
diff --git a/tmk_core/common/arm_atsam/printf.h b/tmk_core/common/arm_atsam/printf.h new file mode 100644 index 000000000..582c83bf5 --- /dev/null +++ b/tmk_core/common/arm_atsam/printf.h | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | #ifndef _PRINTF_H_ | ||
| 2 | #define _PRINTF_H_ | ||
| 3 | |||
| 4 | #define __xprintf dpf | ||
| 5 | int dpf(const char *_Format, ...); | ||
| 6 | |||
| 7 | #endif //_PRINTF_H_ | ||
| 8 | |||
diff --git a/tmk_core/common/arm_atsam/suspend.c b/tmk_core/common/arm_atsam/suspend.c new file mode 100644 index 000000000..01d1930ea --- /dev/null +++ b/tmk_core/common/arm_atsam/suspend.c | |||
| @@ -0,0 +1,17 @@ | |||
| 1 | /* Copyright 2017 Fred Sundvik | ||
| 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 | |||
diff --git a/tmk_core/common/arm_atsam/timer.c b/tmk_core/common/arm_atsam/timer.c new file mode 100644 index 000000000..bcfe5002c --- /dev/null +++ b/tmk_core/common/arm_atsam/timer.c | |||
| @@ -0,0 +1,59 @@ | |||
| 1 | #include "samd51j18a.h" | ||
| 2 | #include "timer.h" | ||
| 3 | #include "tmk_core/protocol/arm_atsam/clks.h" | ||
| 4 | |||
| 5 | void set_time(uint64_t tset) | ||
| 6 | { | ||
| 7 | ms_clk = tset; | ||
| 8 | } | ||
| 9 | |||
| 10 | void timer_init(void) | ||
| 11 | { | ||
| 12 | ms_clk = 0; | ||
| 13 | } | ||
| 14 | |||
| 15 | uint16_t timer_read(void) | ||
| 16 | { | ||
| 17 | return (uint16_t)ms_clk; | ||
| 18 | } | ||
| 19 | |||
| 20 | uint32_t timer_read32(void) | ||
| 21 | { | ||
| 22 | return (uint32_t)ms_clk; | ||
| 23 | } | ||
| 24 | |||
| 25 | uint64_t timer_read64(void) | ||
| 26 | { | ||
| 27 | return ms_clk; | ||
| 28 | } | ||
| 29 | |||
| 30 | uint16_t timer_elapsed(uint16_t tlast) | ||
| 31 | { | ||
| 32 | return TIMER_DIFF_16(timer_read(), tlast); | ||
| 33 | } | ||
| 34 | |||
| 35 | uint32_t timer_elapsed32(uint32_t tlast) | ||
| 36 | { | ||
| 37 | return TIMER_DIFF_32(timer_read32(), tlast); | ||
| 38 | } | ||
| 39 | |||
| 40 | uint32_t timer_elapsed64(uint32_t tlast) | ||
| 41 | { | ||
| 42 | uint64_t tnow = timer_read64(); | ||
| 43 | return (tnow >= tlast ? tnow - tlast : UINT64_MAX - tlast + tnow); | ||
| 44 | } | ||
| 45 | |||
| 46 | void timer_clear(void) | ||
| 47 | { | ||
| 48 | ms_clk = 0; | ||
| 49 | } | ||
| 50 | |||
| 51 | void wait_ms(uint64_t msec) | ||
| 52 | { | ||
| 53 | CLK_delay_ms(msec); | ||
| 54 | } | ||
| 55 | |||
| 56 | void wait_us(uint16_t usec) | ||
| 57 | { | ||
| 58 | CLK_delay_us(usec); | ||
| 59 | } | ||
diff --git a/tmk_core/common/print.h b/tmk_core/common/print.h index 8836c0fc7..9cbe67bad 100644 --- a/tmk_core/common/print.h +++ b/tmk_core/common/print.h | |||
| @@ -99,6 +99,34 @@ void print_set_sendchar(int8_t (*print_sendchar_func)(uint8_t)); | |||
| 99 | 99 | ||
| 100 | # endif /* USER_PRINT / NORMAL PRINT */ | 100 | # endif /* USER_PRINT / NORMAL PRINT */ |
| 101 | 101 | ||
| 102 | #elif defined(PROTOCOL_ARM_ATSAM) /* PROTOCOL_ARM_ATSAM */ | ||
| 103 | |||
| 104 | # include "arm_atsam/printf.h" | ||
| 105 | |||
| 106 | # ifdef USER_PRINT /* USER_PRINT */ | ||
| 107 | |||
| 108 | // Remove normal print defines | ||
| 109 | # define print(s) | ||
| 110 | # define println(s) | ||
| 111 | # define xprintf(fmt, ...) | ||
| 112 | |||
| 113 | // Create user print defines | ||
| 114 | # define uprintf(fmt, ...) __xprintf(fmt, ##__VA_ARGS__) | ||
| 115 | # define uprint(s) xprintf(s) | ||
| 116 | # define uprintln(s) xprintf(s "\r\n") | ||
| 117 | |||
| 118 | # else /* NORMAL PRINT */ | ||
| 119 | |||
| 120 | // Create user & normal print defines | ||
| 121 | # define xprintf(fmt, ...) __xprintf(fmt, ##__VA_ARGS__) | ||
| 122 | # define print(s) xprintf(s) | ||
| 123 | # define println(s) xprintf(s "\r\n") | ||
| 124 | # define uprint(s) print(s) | ||
| 125 | # define uprintln(s) println(s) | ||
| 126 | # define uprintf(fmt, ...) xprintf(fmt, ...) | ||
| 127 | |||
| 128 | # endif /* USER_PRINT / NORMAL PRINT */ | ||
| 129 | |||
| 102 | #elif defined(__arm__) /* __arm__ */ | 130 | #elif defined(__arm__) /* __arm__ */ |
| 103 | 131 | ||
| 104 | # include "mbed/xprintf.h" | 132 | # include "mbed/xprintf.h" |
| @@ -130,7 +158,7 @@ void print_set_sendchar(int8_t (*print_sendchar_func)(uint8_t)); | |||
| 130 | /* TODO: to select output destinations: UART/USBSerial */ | 158 | /* TODO: to select output destinations: UART/USBSerial */ |
| 131 | # define print_set_sendchar(func) | 159 | # define print_set_sendchar(func) |
| 132 | 160 | ||
| 133 | #endif /* __AVR__ / PROTOCOL_CHIBIOS / __arm__ */ | 161 | #endif /* __AVR__ / PROTOCOL_CHIBIOS / PROTOCOL_ARM_ATSAM / __arm__ */ |
| 134 | 162 | ||
| 135 | // User print disables the normal print messages in the body of QMK/TMK code and | 163 | // User print disables the normal print messages in the body of QMK/TMK code and |
| 136 | // is meant as a lightweight alternative to NOPRINT. Use it when you only want to do | 164 | // is meant as a lightweight alternative to NOPRINT. Use it when you only want to do |
diff --git a/tmk_core/common/report.h b/tmk_core/common/report.h index 6c27eb9dc..167f38275 100644 --- a/tmk_core/common/report.h +++ b/tmk_core/common/report.h | |||
| @@ -84,6 +84,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 84 | #define KEYBOARD_REPORT_SIZE NKRO_EPSIZE | 84 | #define KEYBOARD_REPORT_SIZE NKRO_EPSIZE |
| 85 | #define KEYBOARD_REPORT_KEYS (NKRO_EPSIZE - 2) | 85 | #define KEYBOARD_REPORT_KEYS (NKRO_EPSIZE - 2) |
| 86 | #define KEYBOARD_REPORT_BITS (NKRO_EPSIZE - 1) | 86 | #define KEYBOARD_REPORT_BITS (NKRO_EPSIZE - 1) |
| 87 | #elif defined(PROTOCOL_ARM_ATSAM) | ||
| 88 | #include "protocol/arm_atsam/usb/udi_device_epsize.h" | ||
| 89 | #define KEYBOARD_REPORT_SIZE NKRO_EPSIZE | ||
| 90 | #define KEYBOARD_REPORT_KEYS (NKRO_EPSIZE - 2) | ||
| 91 | #define KEYBOARD_REPORT_BITS (NKRO_EPSIZE - 1) | ||
| 87 | #else | 92 | #else |
| 88 | #error "NKRO not supported with this protocol" | 93 | #error "NKRO not supported with this protocol" |
| 89 | #endif | 94 | #endif |
