diff --git a/firmware/keyboard/ergodox/layout/common/keys.c.h b/firmware/keyboard/ergodox/layout/common/keys.c.h index 380ddd4..da98312 100644 --- a/firmware/keyboard/ergodox/layout/common/keys.c.h +++ b/firmware/keyboard/ergodox/layout/common/keys.c.h @@ -156,7 +156,7 @@ // ---------------------------------------------------------------------------- -/** functions/KF(2_keys_caps)/description +/** functions/KF(2_keys_capslock)/description * Press the given keycode, and also press "capslock" if this is the second * consecutive time this function has been called with `pressed == true`. * diff --git a/firmware/keyboard/ergodox/layout/templates/kinesis-mod.c.h b/firmware/keyboard/ergodox/layout/templates/kinesis-mod.c.h index 70d372f..99a6fb5 100644 --- a/firmware/keyboard/ergodox/layout/templates/kinesis-mod.c.h +++ b/firmware/keyboard/ergodox/layout/templates/kinesis-mod.c.h @@ -70,6 +70,13 @@ void kb__led__logical_off(char led) { KEYS__LAYER__NUM_PUSH(10, 3); KEYS__LAYER__NUM_POP(10); +// TODO dbg +void P(test)(void){ + KF(dump_progmem_ihex)(); +} +void R(test)(void){} +// TODO /dbg + // ---------------------------------------------------------------------------- // layout @@ -143,7 +150,9 @@ shL2kcap, T_z, T_x, T_c, T_v, T_b, lpupo1l1, nop, nop, nop, nop, nop, nop, // right hand ..... ......... ......... ......... ......... ......... ......... - nop, nop, nop, nop, nop, nop, nop, + nop, nop, nop, nop, nop, nop, test, +// TODO dbg +// nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, diff --git a/firmware/lib/eeprom.h b/firmware/lib/eeprom.h index 0b49dee..d3781b1 100644 --- a/firmware/lib/eeprom.h +++ b/firmware/lib/eeprom.h @@ -67,10 +67,14 @@ uint8_t eeprom__block_read (void * to, void * from, uint8_t length); // === eeprom__read() === /** functions/eeprom__read/description - * Read and return the data at `address` in the EEPROM memory space + * Read and return the data at `from` in the EEPROM memory space * * Arguments: - * - `from: The address of (i.e. a pointer to) the location to read from + * - `from`: The address of (i.e. a pointer to) the location from which to read + * + * Returns: + * - success: The data stored at `from` in the EEPROM memory space + * - failure: `0` */ // === eeprom__write() === diff --git a/firmware/lib/layout/key-functions.h b/firmware/lib/layout/key-functions.h index 32821e6..4dbfb12 100644 --- a/firmware/lib/layout/key-functions.h +++ b/firmware/lib/layout/key-functions.h @@ -27,6 +27,9 @@ void key_functions__toggle (uint8_t keycode); // device void key_functions__jump_to_bootloader (void); +void key_functions__dump_sram_ihex (void); // TODO: documentation +void key_functions__dump_progmem_ihex (void); // TODO: documentation +void key_functions__dump_eeprom_ihex (void); // TODO: documentation // special void key_functions__toggle_capslock (void); diff --git a/firmware/lib/layout/key-functions/device/atmega32u4.c b/firmware/lib/layout/key-functions/device/atmega32u4.c index 53dbc72..e96b09f 100644 --- a/firmware/lib/layout/key-functions/device/atmega32u4.c +++ b/firmware/lib/layout/key-functions/device/atmega32u4.c @@ -12,13 +12,103 @@ #include #include +#include #include +#include "../../../../../firmware/lib/eeprom.h" #include "../../key-functions.h" // ---------------------------------------------------------------------------- -// from PJRC (slightly modified) -// +/** functions/sram_read/description + * A tiny little helper function to let `key_functions__dump_sram_ihex()` work + * the same way as the other `...dump...ihex()` functions. + * + * Arguments: + * - `from`: The address of (i.e. a pointer to) the location from which to read + * + * Returns: + * - success: The data stored at `pointer` in the SRAM memory space + */ +static uint8_t sram_read(void * from) { + return *(uint8_t *)from; +} + +/** functions/progmem_read/description + * A tiny little helper function to let `key_functions__dump_progmem_ihex()` + * work the same way as the other `...dump...ihex()` functions. + * + * Arguments: + * - `from`: The address of (i.e. a pointer to) the location from which to read + * + * Returns: + * - success: The data stored at `pointer` in the PROGMEM memory space + */ +static uint8_t progmem_read(void * from) { + return pgm_read_byte(from); +} + +/** functions/dump_ihex/description + * TODO: documentation + * + * Arguments: + * + * Returns: + * + * Notes: + * - See [the Wikipedia article] (http://en.wikipedia.org/wiki/Intel_HEX) on + * the Intel hex (ihex) format. + */ +static void dump_ihex( uint8_t (*read)(void *), + void * from, + void * last ) { + + const uint8_t record_type = 0x00; // data + uint8_t line_width = 0x10; // 16 bytes of data per line, by default + + // TODO: from might equal `0`, and last might equal `UINT16_MAX`; need to + // work thing out so that that won't make problems; maybe just use bigger + // counters, and then not have to worry about it + // + // i could use `length` instead of `last`, like i originally wanted to, if + // i used a `uint32_t`. part of me wants to make it work without the + // bigger variable, lol. part of me wants to just get it finished. the + // extra 2 bytes of stack ram probably won't hurt anything anyway. + do { + if (from != last+1 && last-from+1 < line_width) + line_width = last-from+1; + + uint8_t checksum = line_width + record_type + + ((uint16_t)(from) >> 8) + + ((uint16_t)(from) & 0xFF); + + key_functions__type_string( PSTR(":") ); + key_functions__type_byte_hex( line_width ); + key_functions__type_byte_hex( (uint16_t)(from) >> 8 ); + key_functions__type_byte_hex( (uint16_t)(from) & 0xFF ); + key_functions__type_byte_hex( record_type ); + + for (uint8_t l=0; l. + * + */ void key_functions__jump_to_bootloader(void) { // --- for all Teensy boards --- @@ -40,3 +130,15 @@ void key_functions__jump_to_bootloader(void) { asm volatile("jmp 0x7E00"); } +void key_functions__dump_sram_ihex(void) { + dump_ihex(&sram_read, 0, (void *)RAMEND); +} + +void key_functions__dump_progmem_ihex(void) { + dump_ihex(&progmem_read, 0, (void *)FLASHEND); +} + +void key_functions__dump_eeprom_ihex(void) { + dump_ihex(&eeprom__read, 0, (void *)E2END); +} + diff --git a/firmware/lib/layout/key-functions/special.c b/firmware/lib/layout/key-functions/special.c index a1a87fc..3fcca81 100644 --- a/firmware/lib/layout/key-functions/special.c +++ b/firmware/lib/layout/key-functions/special.c @@ -71,10 +71,18 @@ void key_functions__toggle_capslock(void) { // usb__kb__set_key(true, KEYPAD__NumLock_Clear); // usb__kb__send_report(); // usb__kb__set_key(false, KEYPAD__NumLock_Clear); +// usb__kb__send_report(); // } // // usb__kb__send_report(); // } +/** functions/key_functions__type_byte_hex/description + * Implementation notes: + * + * - We have to call `usb__kb__send_report()` after each call to + * `usb__kb__set_key()`; otherwise, if the high 4 bits is the same as the low + * 4 bits, only one character will be typed. + */ void key_functions__type_byte_hex(uint8_t byte) { uint8_t c[2] = { byte >> 4, byte & 0xF }; @@ -86,6 +94,7 @@ void key_functions__type_byte_hex(uint8_t byte) { usb__kb__set_key(true, c[i]); usb__kb__send_report(); usb__kb__set_key(false, c[i]); + usb__kb__send_report(); } usb__kb__send_report();