Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions include/keepkey/emulator/libkkemu.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,25 @@
extern "C" {
#endif

#define KKEMU_FLASH_SIZE (1024 * 1024) /* 1 MB */
#define KKEMU_PACKET_SIZE 64 /* HID report size */
#define KKEMU_IFACE_MAIN 0
#define KKEMU_IFACE_DEBUG 1
#define KKEMU_FLASH_SIZE (1024 * 1024) /* 1 MB */
#define KKEMU_PACKET_SIZE 64 /* HID report size */
#define KKEMU_IFACE_MAIN 0
#define KKEMU_IFACE_DEBUG 1

/**
* Initialize the emulator with a host-provided flash buffer.
*
* @param flash_buf Pointer to 1MB buffer (host-owned, must remain valid).
* If contents are all 0xFF, treated as fresh/erased device.
* If contents are from a previous session, device state is restored.
* If contents are from a previous session, device state is
* restored.
* @param flash_len Must be KKEMU_FLASH_SIZE (1048576).
* @return 0 on success, -1 on error.
*
* After this call, the emulator is ready to process messages via
* kkemu_write() + kkemu_poll() + kkemu_read().
*/
int kkemu_init(uint8_t *flash_buf, size_t flash_len);
int kkemu_init(uint8_t* flash_buf, size_t flash_len);

/**
* Shut down the emulator. Flushes pending storage writes to the
Expand All @@ -49,7 +50,7 @@ void kkemu_shutdown(void);
* @param iface KKEMU_IFACE_MAIN (0) or KKEMU_IFACE_DEBUG (1).
* @return 0 on success, -1 if queue is full.
*/
int kkemu_write(const uint8_t *data, size_t len, int iface);
int kkemu_write(const uint8_t* data, size_t len, int iface);

/**
* Read a 64-byte HID report from the emulator's output queue.
Expand All @@ -61,7 +62,7 @@ int kkemu_write(const uint8_t *data, size_t len, int iface);
* @param iface KKEMU_IFACE_MAIN (0) or KKEMU_IFACE_DEBUG (1).
* @return Number of bytes read (64), or 0 if queue is empty.
*/
int kkemu_read(uint8_t *buf, size_t len, int iface);
int kkemu_read(uint8_t* buf, size_t len, int iface);

/**
* Run one iteration of the firmware event loop.
Expand All @@ -83,7 +84,7 @@ int kkemu_poll(void);
* @return Pointer to framebuffer (valid until next kkemu_poll).
* Returns NULL if emulator is not initialized.
*/
const uint8_t *kkemu_get_display(int *width, int *height);
const uint8_t* kkemu_get_display(int* width, int* height);

/**
* Check if the emulator has been initialized.
Expand Down
2 changes: 1 addition & 1 deletion include/keepkey/emulator/setup.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
#define KEEPKEY_EMULATOR_SETUP_H

void setup(void);
void setup_urandom_only(void); /* For libkkemu: init RNG without flash mmap */
void setup_urandom_only(void); /* For libkkemu: init RNG without flash mmap */

#endif
11 changes: 5 additions & 6 deletions include/keepkey/firmware/coins.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,15 @@ enum {
CONCAT(CoinIndex, __COUNTER__),
#include "keepkey/firmware/coins.def"

#ifdef BITCOIN_ONLY
// For full-featured keepkey, this is defined in ethereum_tokens.h. For bitcoin
// only keepkey, need to define it here because ethereum_tokens.h is not
// included in any file
#define TOKENS_COUNT 0
#else
#ifndef BITCOIN_ONLY
#define X(INDEX, NAME, SYMBOL, DECIMALS, CONTRACT_ADDRESS) \
CONCAT(CoinIndex, __COUNTER__),
#include "keepkey/firmware/tokens.def"
#endif
/* TOKENS_COUNT is owned by ethereum_tokens.h. The BTC-only override that
* used to live here was based on a stale invariant — ethereum_tokens.h is
* actually pulled in transitively in BTC-only builds, so the override
* collided with the real define. */
CoinIndexLast,
CoinIndexFirst = 0
};
Expand Down
2 changes: 1 addition & 1 deletion lib/emulator/libkkemu.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ const uint8_t *kkemu_get_display(int *width, int *height) {

if (!libkkemu_initialized) { if (width) *width = 0; if (height) *height = 0; return NULL; }

Canvas *c = display_canvas();
const Canvas *c = display_canvas();
if (!c || !c->buffer) { if (width) *width = 0; if (height) *height = 0; return NULL; }

memset(packed, 0, sizeof(packed));
Expand Down
Loading