2014-04-29 12:26:51 +00:00
|
|
|
/*
|
2017-11-05 16:46:34 +00:00
|
|
|
* This file is part of the TREZOR project, https://trezor.io/
|
2014-04-29 12:26:51 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2014 Pavol Rusnak <stick@satoshilabs.com>
|
|
|
|
*
|
|
|
|
* This library is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "pinmatrix.h"
|
2017-11-03 17:54:02 +00:00
|
|
|
#include "layout2.h"
|
2014-04-29 12:26:51 +00:00
|
|
|
#include "oled.h"
|
|
|
|
#include "rng.h"
|
|
|
|
|
|
|
|
static char pinmatrix_perm[10] = "XXXXXXXXX";
|
|
|
|
|
|
|
|
void pinmatrix_draw(const char *text)
|
|
|
|
{
|
|
|
|
const BITMAP *bmp_digits[10] = {
|
|
|
|
&bmp_digit0, &bmp_digit1, &bmp_digit2, &bmp_digit3, &bmp_digit4,
|
|
|
|
&bmp_digit5, &bmp_digit6, &bmp_digit7, &bmp_digit8, &bmp_digit9,
|
|
|
|
};
|
2017-11-03 17:54:02 +00:00
|
|
|
layoutSwipe();
|
2014-04-29 12:26:51 +00:00
|
|
|
const int w = bmp_digit0.width, h = bmp_digit0.height, pad = 2;
|
2017-07-23 20:20:51 +00:00
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
for (int j = 0; j < 3; j++) {
|
2014-04-29 12:26:51 +00:00
|
|
|
// use (2 - j) instead of j to achieve 789456123 layout
|
2017-07-23 20:20:51 +00:00
|
|
|
int k = pinmatrix_perm[i + (2 - j) * 3] - '0';
|
2014-04-29 12:26:51 +00:00
|
|
|
if (text) {
|
2018-02-06 21:29:33 +00:00
|
|
|
oledDrawStringCenter(0, text, FONT_STANDARD);
|
2014-04-29 12:26:51 +00:00
|
|
|
}
|
|
|
|
oledDrawBitmap((OLED_WIDTH - 3 * w - 2 * pad) / 2 + i * (w + pad), OLED_HEIGHT - 3 * h - 2 * pad + j * (h + pad), bmp_digits[k]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
oledRefresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
void pinmatrix_start(const char *text)
|
|
|
|
{
|
2017-07-23 20:20:51 +00:00
|
|
|
for (int i = 0; i < 9; i++) {
|
2014-04-29 12:26:51 +00:00
|
|
|
pinmatrix_perm[i] = '1' + i;
|
|
|
|
}
|
|
|
|
pinmatrix_perm[9] = 0;
|
2015-02-13 19:49:53 +00:00
|
|
|
random_permute(pinmatrix_perm, 9);
|
2014-04-29 12:26:51 +00:00
|
|
|
pinmatrix_draw(text);
|
|
|
|
}
|
|
|
|
|
|
|
|
void pinmatrix_done(char *pin)
|
|
|
|
{
|
|
|
|
int k, i = 0;
|
|
|
|
while (pin && pin[i]) {
|
|
|
|
k = pin[i] - '1';
|
|
|
|
if (k >= 0 && k <= 8) {
|
|
|
|
pin[i] = pinmatrix_perm[k];
|
|
|
|
} else {
|
|
|
|
pin[i] = 'X';
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
2018-03-23 16:19:30 +00:00
|
|
|
memset(pinmatrix_perm, 'X', sizeof(pinmatrix_perm) - 1);
|
2014-04-29 12:26:51 +00:00
|
|
|
}
|
|
|
|
|
2015-08-24 12:42:11 +00:00
|
|
|
#if DEBUG_LINK
|
|
|
|
|
2014-04-29 12:26:51 +00:00
|
|
|
const char *pinmatrix_get(void)
|
|
|
|
{
|
|
|
|
return pinmatrix_perm;
|
|
|
|
}
|
2015-08-24 12:42:11 +00:00
|
|
|
|
|
|
|
#endif
|