mirror of
https://github.com/tillitis/tillitis-key1.git
synced 2025-08-03 12:16:24 -04:00
tkey-libs: Copy files from tkey-libs repo
Taken from main-branch, commit b4bbaad.
This commit is contained in:
parent
056f2363b4
commit
72a2ea9cd3
5 changed files with 27 additions and 27 deletions
|
@ -9,8 +9,8 @@ NOTE WELL! Rewritten I/O functions with new semantics!
|
|||
The Castor TKey hardware supports more USB endpoints:
|
||||
|
||||
- CDC - the same thing as older versions.
|
||||
- HID security token, for FIDO-like apps.
|
||||
- CTRL, a HID debug port.
|
||||
- FIDO security token, for FIDO-like apps.
|
||||
- DEBUG, a HID debug port.
|
||||
|
||||
The communication is still over a single UART. To differ between the
|
||||
endpoints we use an internal USB Mode Protocol between programs
|
||||
|
@ -18,7 +18,7 @@ running on the PicoRV32 and the CH552 USB Controller.
|
|||
|
||||
The I/O functions has changed accordingly. Please use:
|
||||
|
||||
- `readselect()` with appropriate bitmask (e.g. `IO_CDC|IO_HID`) to
|
||||
- `readselect()` with appropriate bitmask (e.g. `IO_CDC|IO_FIDO`) to
|
||||
see if there's anything to read in the endpoints you are interested
|
||||
in. Data from endpoints not mentioned in the bitmask will be
|
||||
discarded.
|
||||
|
@ -48,7 +48,7 @@ The optionally built debug prints have changed. You now use
|
|||
|
||||
You define the debug output endpoint when you compile your program by
|
||||
including `debug.h` and defining `QEMU_DEBUG` for the qemu debug port
|
||||
or `TKEY_DEBUG` for output on the CTRL HID endpoint. If you don't
|
||||
or `TKEY_DEBUG` for output on the DEBUG HID endpoint. If you don't
|
||||
define either, they won't appear in your code.
|
||||
|
||||
Similiarly, `assert()` now also follows `QEMU_DEBUG` or `TKEY_DEBUG`,
|
||||
|
|
|
@ -14,9 +14,8 @@
|
|||
#elif defined(TKEY_DEBUG)
|
||||
|
||||
#define assert(expr) \
|
||||
((expr) \
|
||||
? (void)(0) \
|
||||
: assert_fail(IO_TKEYCTRL, #expr, __FILE__, __LINE__, __func__))
|
||||
((expr) ? (void)(0) \
|
||||
: assert_fail(IO_DEBUG, #expr, __FILE__, __LINE__, __func__))
|
||||
|
||||
#else
|
||||
|
||||
|
|
|
@ -18,12 +18,12 @@
|
|||
|
||||
#elif defined(TKEY_DEBUG)
|
||||
|
||||
#define debug_putchar(ch) putchar(IO_TKEYCTRL, ch)
|
||||
#define debug_lf() putchar(IO_TKEYCTRL, '\n')
|
||||
#define debug_putinthex(ch) putinthex(IO_TKEYCTRL, ch)
|
||||
#define debug_puts(s) puts(IO_TKEYCTRL, s)
|
||||
#define debug_puthex(ch) puthex(IO_TKEYCTRL, ch)
|
||||
#define debug_hexdump(buf, len) hexdump(IO_TKEYCTRL, buf, len)
|
||||
#define debug_putchar(ch) putchar(IO_DEBUG, ch)
|
||||
#define debug_lf() putchar(IO_DEBUG, '\n')
|
||||
#define debug_putinthex(ch) putinthex(IO_DEBUG, ch)
|
||||
#define debug_puts(s) puts(IO_DEBUG, s)
|
||||
#define debug_puthex(ch) puthex(IO_DEBUG, ch)
|
||||
#define debug_hexdump(buf, len) hexdump(IO_DEBUG, buf, len)
|
||||
|
||||
#else
|
||||
|
||||
|
|
|
@ -10,15 +10,16 @@
|
|||
// I/O endpoints. Keep it as bits possible to use in a bitmask in
|
||||
// readselect().
|
||||
//
|
||||
// Note that the the TKEYCTRL, CDC, and HID should be kept the same on
|
||||
// Note that the DEBUG, CDC, and FIDO should be kept the same on
|
||||
// the CH552 side.
|
||||
enum ioend {
|
||||
IO_NONE = 0x00, // No endpoint
|
||||
IO_UART = 0x01, // Only destination, raw UART access
|
||||
IO_QEMU = 0x10, // Only destination, QEMU debug port
|
||||
IO_TKEYCTRL = 0x20, // HID debug port
|
||||
IO_CDC = 0x40, // CDC "serial port"
|
||||
IO_HID = 0x80, // HID security token
|
||||
IO_NONE = 0x00, // No endpoint
|
||||
IO_UART = 0x01, // Only destination, raw UART access
|
||||
IO_QEMU = 0x02, // Only destination, QEMU debug port
|
||||
IO_CH552 = 0x10, // Internal CH552 control port
|
||||
IO_DEBUG = 0x20, // HID debug port
|
||||
IO_CDC = 0x40, // CDC "serial port"
|
||||
IO_FIDO = 0x80, // FIDO security token port
|
||||
};
|
||||
|
||||
void write(enum ioend dest, const uint8_t *buf, size_t nbytes);
|
||||
|
|
|
@ -80,9 +80,9 @@ static void write_with_header(enum ioend dest, const uint8_t *buf,
|
|||
//
|
||||
// - IO_CDC: Through the UART for the CDC endpoint, with header.
|
||||
//
|
||||
// - IO_HID: Through the UART for the HID endpoint, with header.
|
||||
// - IO_FIDO: Through the UART for the FIDO endpoint, with header.
|
||||
//
|
||||
// - IO_TKEYCTRL: Through the UART for the debug HID endpoint, with
|
||||
// - IO_DEBUG: Through the UART for the DEBUG HID endpoint, with
|
||||
// header.
|
||||
void write(enum ioend dest, const uint8_t *buf, size_t nbytes)
|
||||
{
|
||||
|
@ -194,18 +194,18 @@ static int discard(size_t nbytes)
|
|||
//
|
||||
// Use like this:
|
||||
//
|
||||
// readselect(IO_CDC|IO_HID, &endpoint, &len)
|
||||
// readselect(IO_CDC|IO_FIDO, &endpoint, &len)
|
||||
//
|
||||
// to wait for some data from either the CDC or the HID endpoint.
|
||||
// to wait for some data from either the CDC or the FIDO endpoint.
|
||||
//
|
||||
// NOTE WELL: You need to call readselect() first, before doing any
|
||||
// calls to read().
|
||||
//
|
||||
// Only endpoints available for read are:
|
||||
//
|
||||
// - IO_TKEYCTRL
|
||||
// - IO_DEBUG
|
||||
// - IO_CDC
|
||||
// - IO_HID
|
||||
// - IO_FIDO
|
||||
//
|
||||
// If you need blocking low-level UART reads, use uart_read() instead.
|
||||
//
|
||||
|
@ -215,7 +215,7 @@ static int discard(size_t nbytes)
|
|||
// Returns non-zero on error.
|
||||
int readselect(int bitmask, enum ioend *endpoint, uint8_t *len)
|
||||
{
|
||||
if (bitmask & IO_UART || bitmask & IO_QEMU) {
|
||||
if ((bitmask & IO_UART) || (bitmask & IO_QEMU)) {
|
||||
// Not possible to use readselect() on these
|
||||
// endpoints.
|
||||
return -1;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue