small changes; and working on the `...dump...ihex()` functions
parent
d5ae5e003b
commit
90f6b2c867
|
@ -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`.
|
||||
*
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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() ===
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -12,13 +12,103 @@
|
|||
|
||||
#include <stdint.h>
|
||||
#include <avr/interrupt.h>
|
||||
#include <avr/pgmspace.h>
|
||||
#include <util/delay.h>
|
||||
#include "../../../../../firmware/lib/eeprom.h"
|
||||
#include "../../key-functions.h"
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// from PJRC (slightly modified)
|
||||
// <http://www.pjrc.com/teensy/jump_to_bootloader.html>
|
||||
/** 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<line_width; l++) {
|
||||
uint8_t byte = (*read)(++from);
|
||||
checksum += byte;
|
||||
key_functions__type_byte_hex(byte);
|
||||
}
|
||||
|
||||
key_functions__type_byte_hex( 0x100 - checksum ); // 2's compliment
|
||||
key_functions__type_string( PSTR("\n") );
|
||||
|
||||
} while (from != last);
|
||||
|
||||
key_functions__type_string( PSTR(":00000001FF\n") ); // ihex EOF record
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
/** functions/key_functions__jump_to_bootloader/description
|
||||
* Implementation notes:
|
||||
* - This code is from PJRC (slightly modified)
|
||||
* <http://www.pjrc.com/teensy/jump_to_bootloader.html>.
|
||||
*
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue