21#include "os_io_seph_cmd.h"
22#include "os_io_seph_ux.h"
28#define FIRST_LINE_CHAR_COUNT 10
29#define SECOND_LINE_CHAR_COUNT 9
31#if (SCREEN_WIDTH == 400)
32#define NORMAL_KEY_WIDTH 40
33#define LETTER_OFFSET_Y ((KEYBOARD_KEY_HEIGHT - 32) / 2)
34#elif (SCREEN_WIDTH == 480)
35#define NORMAL_KEY_WIDTH 48
36#define LETTER_OFFSET_Y ((KEYBOARD_KEY_HEIGHT - 36) / 2)
37#elif (SCREEN_WIDTH == 300)
38#define NORMAL_KEY_WIDTH 30
39#define LETTER_OFFSET_Y ((KEYBOARD_KEY_HEIGHT - 22) / 2)
41#define SHIFT_KEY_WIDTH (NORMAL_KEY_WIDTH + SECOND_LINE_OFFSET)
42#define SECOND_LINE_OFFSET ((SCREEN_WIDTH - (SECOND_LINE_CHAR_COUNT * NORMAL_KEY_WIDTH)) / 2)
43#if defined(TARGET_STAX)
44#define SPACE_KEY_WIDTH 276
45#elif defined(TARGET_FLEX)
46#define SPACE_KEY_WIDTH 336
47#elif defined(TARGET_APEX)
48#define SPACE_KEY_WIDTH 209
50#define SWITCH_KEY_WIDTH (SCREEN_WIDTH - SPACE_KEY_WIDTH)
51#define SPECIAL_CHARS_KEY_WIDTH (NORMAL_KEY_WIDTH * 2 + SECOND_LINE_OFFSET)
52#define BACKSPACE_KEY_WIDTH_FULL SHIFT_KEY_WIDTH
53#define BACKSPACE_KEY_WIDTH_DIGITS SPECIAL_CHARS_KEY_WIDTH
54#define BACKSPACE_KEY_WIDTH_LETTERS_ONLY (SCREEN_WIDTH - 7 * NORMAL_KEY_WIDTH)
56#define IS_KEY_MASKED(_index) (keyboard->keyMask & (1 << _index))
69static const char kbd_chars[] =
"qwertyuiopasdfghjklzxcvbnm";
70static const char kbd_chars_upper[] =
"QWERTYUIOPASDFGHJKLZXCVBNM";
72static const char kbd_specials[] =
"[]{}#%^*+=_\\|~<>$`\".,?!\'";
85 if (position->
y < KEYBOARD_KEY_HEIGHT) {
87 i = position->
x / NORMAL_KEY_WIDTH;
89 else if (position->
y < (2 * KEYBOARD_KEY_HEIGHT)) {
96 else if (position->
y < (3 * KEYBOARD_KEY_HEIGHT)) {
100 if (!keyboard->lettersOnly) {
135 else if (!keyboard->lettersOnly && (position->
y < (4 * KEYBOARD_KEY_HEIGHT))) {
153 rectArea.backgroundColor = keyboard->obj.area.backgroundColor;
154 rectArea.x0 = keyboard->obj.area.x0;
155 rectArea.y0 = keyboard->obj.area.y0;
156 rectArea.width = keyboard->obj.area.width;
157 rectArea.height = keyboard->obj.area.height;
161 rectArea.backgroundColor = keyboard->obj.area.backgroundColor;
162 rectArea.x0 = keyboard->obj.area.x0;
163 rectArea.y0 = keyboard->obj.area.y0;
164 rectArea.width = keyboard->obj.area.width;
167 rectArea.y0 += KEYBOARD_KEY_HEIGHT;
169 rectArea.y0 += KEYBOARD_KEY_HEIGHT;
172 if ((keyboard->obj.alignmentMarginY > 0) || (!keyboard->lettersOnly)) {
173 rectArea.y0 += KEYBOARD_KEY_HEIGHT;
177 if ((keyboard->obj.alignmentMarginY > 0) && (!keyboard->lettersOnly)) {
178 rectArea.y0 += KEYBOARD_KEY_HEIGHT;
183 rectArea.x0 = keyboard->obj.area.x0;
184 rectArea.y0 = keyboard->obj.area.y0;
186 rectArea.height = KEYBOARD_KEY_HEIGHT * 3;
187 if (!keyboard->lettersOnly) {
188 rectArea.height += KEYBOARD_KEY_HEIGHT;
201 keyboardDrawCommonLines(keyboard);
204 rectArea.backgroundColor = keyboard->obj.area.backgroundColor;
205 rectArea.x0 = keyboard->obj.area.x0;
206 rectArea.y0 = keyboard->obj.area.y0;
208 rectArea.height = KEYBOARD_KEY_HEIGHT;
210 for (i = 0; i < 9; i++) {
211 rectArea.x0 += NORMAL_KEY_WIDTH;
217 rectArea.y0 += KEYBOARD_KEY_HEIGHT;
219 for (i = 10; i < 19; i++) {
220 rectArea.x0 += NORMAL_KEY_WIDTH;
225 rectArea.y0 += KEYBOARD_KEY_HEIGHT;
226 if (!keyboard->lettersOnly) {
230 rectArea.x0 = NORMAL_KEY_WIDTH;
232 for (i = 0; i < 6; i++) {
234 rectArea.x0 += NORMAL_KEY_WIDTH;
236 if (!keyboard->lettersOnly) {
238 rectArea.x0 += NORMAL_KEY_WIDTH;
243 if (!keyboard->lettersOnly) {
244 rectArea.y0 += KEYBOARD_KEY_HEIGHT;
257 keyboardDrawCommonLines(keyboard);
260 rectArea.backgroundColor = keyboard->obj.area.backgroundColor;
261 rectArea.x0 = keyboard->obj.area.x0;
262 rectArea.y0 = keyboard->obj.area.y0;
264 rectArea.height = KEYBOARD_KEY_HEIGHT;
266 for (i = 0; i < 9; i++) {
267 rectArea.x0 += NORMAL_KEY_WIDTH;
273 rectArea.y0 += KEYBOARD_KEY_HEIGHT;
275 for (i = 10; i < 19; i++) {
276 rectArea.x0 += NORMAL_KEY_WIDTH;
281 rectArea.y0 += KEYBOARD_KEY_HEIGHT;
283 for (i = 0; i < 5; i++) {
284 rectArea.x0 += NORMAL_KEY_WIDTH;
289 rectArea.y0 += KEYBOARD_KEY_HEIGHT;
302 keys = kbd_chars_upper;
308 rectArea.backgroundColor = keyboard->obj.area.backgroundColor;
309 rectArea.y0 = keyboard->obj.area.y0 + LETTER_OFFSET_Y;
311 rectArea.height = KEYBOARD_KEY_HEIGHT * 3;
312 rectArea.x0 = keyboard->obj.area.x0;
315 for (i = 0; i < 10; i++) {
316 rectArea.x0 = keyboard->obj.area.x0 + i * NORMAL_KEY_WIDTH;
319 += (NORMAL_KEY_WIDTH -
nbgl_getCharWidth(SMALL_REGULAR_1BPP_FONT, &keys[i])) / 2;
324 rectArea.y0 += KEYBOARD_KEY_HEIGHT;
325 for (i = 10; i < 19; i++) {
326 rectArea.x0 = keyboard->obj.area.x0 +
SECOND_LINE_OFFSET + (i - 10) * NORMAL_KEY_WIDTH;
328 += (NORMAL_KEY_WIDTH -
nbgl_getCharWidth(SMALL_REGULAR_1BPP_FONT, &keys[i])) / 2;
333 rectArea.y0 += KEYBOARD_KEY_HEIGHT;
335 if (!keyboard->lettersOnly) {
337#if defined(TARGET_STAX)
339 rectArea.height = KEYBOARD_KEY_HEIGHT;
341#elif defined(TARGET_FLEX)
343 rectArea.height = KEYBOARD_KEY_HEIGHT;
345#elif defined(TARGET_APEX)
352 rectArea.height = KEYBOARD_KEY_HEIGHT + 1;
356 rectArea.y0 = keyboard->obj.area.y0 + KEYBOARD_KEY_HEIGHT * 2;
368 rectArea.y0 = keyboard->obj.area.y0 + KEYBOARD_KEY_HEIGHT * 2;
371 rectArea.y0 += KEYBOARD_KEY_HEIGHT;
372 rectArea.backgroundColor =
WHITE;
376 rectArea.width = SHIFT_ICON.width;
377 rectArea.height = SHIFT_ICON.height;
379 rectArea.y0 = (keyboard->obj.area.y0 + KEYBOARD_KEY_HEIGHT * 2
380 + (KEYBOARD_KEY_HEIGHT - rectArea.height) / 2);
383 rectArea.backgroundColor =
WHITE;
393 rectArea.backgroundColor =
WHITE;
400 rectArea.y0 = keyboard->obj.area.y0 + KEYBOARD_KEY_HEIGHT * 2 + LETTER_OFFSET_Y;
401 for (i = 19; i < 26; i++) {
402 rectArea.x0 = offsetX + (i - 19) * NORMAL_KEY_WIDTH;
404 += (NORMAL_KEY_WIDTH -
nbgl_getCharWidth(SMALL_REGULAR_1BPP_FONT, &keys[i])) / 2;
409 rectArea.width = BACKSPACE_ICON.width;
410 rectArea.height = BACKSPACE_ICON.height;
412 rectArea.x0 = offsetX + 7 * NORMAL_KEY_WIDTH;
413 rectArea.y0 = (keyboard->obj.area.y0 + KEYBOARD_KEY_HEIGHT * 2
414 + (KEYBOARD_KEY_HEIGHT - rectArea.height) / 2);
415 if (!keyboard->lettersOnly) {
427 if (!keyboard->lettersOnly) {
429 rectArea.y0 = keyboard->obj.area.y0 + KEYBOARD_KEY_HEIGHT * 3 + LETTER_OFFSET_Y;
433 SMALL_REGULAR_1BPP_FONT,
458 rectArea.backgroundColor = keyboard->obj.area.backgroundColor;
459 rectArea.y0 = keyboard->obj.area.y0 + LETTER_OFFSET_Y;
461 rectArea.height = KEYBOARD_KEY_HEIGHT * 3;
462 rectArea.x0 = keyboard->obj.area.x0;
465 for (i = 0; i < 10; i++) {
466 rectArea.x0 = keyboard->obj.area.x0 + i * NORMAL_KEY_WIDTH;
468 += (NORMAL_KEY_WIDTH -
nbgl_getCharWidth(SMALL_REGULAR_1BPP_FONT, &keys[i])) / 2;
473 rectArea.y0 += KEYBOARD_KEY_HEIGHT;
474 for (i = 10; i < 19; i++) {
475 rectArea.x0 = keyboard->obj.area.x0 + (i - 10) * NORMAL_KEY_WIDTH +
SECOND_LINE_OFFSET;
477 += (NORMAL_KEY_WIDTH -
nbgl_getCharWidth(SMALL_REGULAR_1BPP_FONT, &keys[i])) / 2;
487 rectArea.y0 = keyboard->obj.area.y0 + KEYBOARD_KEY_HEIGHT * 2 + LETTER_OFFSET_Y;
493 rectArea.y0 = keyboard->obj.area.y0 + KEYBOARD_KEY_HEIGHT * 2 + LETTER_OFFSET_Y;
497 for (i = 19; i < 24; i++) {
500 += (NORMAL_KEY_WIDTH -
nbgl_getCharWidth(SMALL_REGULAR_1BPP_FONT, &keys[i])) / 2;
505 rectArea.width = BACKSPACE_ICON.width;
506 rectArea.height = BACKSPACE_ICON.height;
509 rectArea.y0 = keyboard->obj.area.y0 + KEYBOARD_KEY_HEIGHT * 2
510 + ((KEYBOARD_KEY_HEIGHT - rectArea.height) / 2);
516 rectArea.y0 = keyboard->obj.area.y0 + KEYBOARD_KEY_HEIGHT * 3 + LETTER_OFFSET_Y;
530 keyboardDrawLetterGrid(keyboard);
533 keyboardDrawLetters(keyboard);
537 keyboardDrawDigitsGrid(keyboard);
540 keyboardDrawDigits(keyboard);
557 uint8_t firstIndex, lastIndex;
569 firstPosition->
x -= obj->area.x0;
570 firstPosition->
y -= obj->area.y0;
571 lastPosition->
x -= obj->area.x0;
572 lastPosition->
y -= obj->area.y0;
574 firstIndex = getKeyboardIndex(keyboard, firstPosition);
578 lastIndex = getKeyboardIndex(keyboard, lastPosition);
583 if (lastIndex != firstIndex) {
595 keyboard->needsRefresh =
true;
597 if ((firstIndex < 26) && ((
IS_KEY_MASKED(firstIndex)) == 0)) {
598 keyboard->callback((cur_casing !=
LOWER_CASE) ? kbd_chars_upper[firstIndex]
599 : kbd_chars[firstIndex]);
602 switch (keyboard->casing) {
624 if (firstIndex < 26) {
640 if (firstIndex < 26) {
641 keyboard->callback(kbd_specials[firstIndex]);
659 keyboard->callback(
' ');
675 uint8_t charIndex = 0;
677 while (charIndex < 26) {
678 if (index == kbd_chars[charIndex]) {
686 *x = kbd->obj.area.x0 + charIndex * NORMAL_KEY_WIDTH;
687 *y = kbd->obj.area.y0;
692 *y = kbd->obj.area.y0 + KEYBOARD_KEY_HEIGHT;
694 else if (charIndex <
sizeof(kbd_chars)) {
696 *x = kbd->obj.area.x0
699 if (!kbd->lettersOnly) {
704 *x = kbd->obj.area.x0
708 *y = kbd->obj.area.y0 + 2 * KEYBOARD_KEY_HEIGHT;
723 kbd->obj.touchMask = (1 <<
TOUCHED);
725 kbd->needsRefresh =
false;
732 touch_exclude_borders(0);
#define LOG_DEBUG(__logger,...)
Middle Level API of the new BOLOS Graphical Library.
void nbgl_drawIcon(nbgl_area_t *area, nbgl_transformation_t transformation, nbgl_color_map_t color_map, const nbgl_icon_details_t *icon)
Helper function to render an icon directly from its nbgl_icon_details_t structure.
nbgl_font_id_e nbgl_drawText(const nbgl_area_t *area, const char *text, uint16_t textLen, nbgl_font_id_e fontId, color_t fontColor)
This function draws the given single-line text, with the given parameters.
uint8_t nbgl_getCharWidth(nbgl_font_id_e fontId, const char *text)
return the width in pixels of the given UTF-8 character
uint16_t nbgl_getTextWidth(nbgl_font_id_e fontId, const char *text)
return the max width in pixels of the given text (can be multiline)
Font screen low-Level driver API, to draw elementary forms.
void nbgl_frontDrawLine(const nbgl_area_t *area, uint8_t dotStartIdx, color_t lineColor)
void nbgl_frontDrawRect(const nbgl_area_t *area)
API to draw all basic graphic objects.
#define BACKSPACE_KEY_INDEX
void nbgl_objDraw(nbgl_obj_t *obj)
This function draws or redraws the given object and its children (recursive version)
keyboardCase_t
Letters casing in which to open/set the keyboard.
@ LOCKED_UPPER_CASE
locked upper case mode
@ LOWER_CASE
lower case mode
@ UPPER_CASE
upper case mode for one character
struct PACKED__ nbgl_keyboard_s nbgl_keyboard_t
struct to represent a keyboard (KEYBOARD type)
#define DIGITS_SWITCH_KEY_INDEX
@ MODE_SPECIAL
extended special characters mode
@ MODE_DIGITS
digits and some special characters mode
@ MODE_LETTERS
letters mode
void nbgl_refreshSpecialWithPostRefresh(nbgl_refresh_mode_t mode, nbgl_post_refresh_t post_refresh)
#define SPECIAL_KEYS_INDEX
struct PACKED__ nbgl_obj_s nbgl_obj_t
Common structure for all graphical objects.
#define BACKSPACE_KEY_WIDTH_LETTERS_ONLY
void nbgl_keyboardTouchCallback(nbgl_obj_t *obj, nbgl_touchType_t eventType)
function to be called when the keyboard object is touched
#define BACKSPACE_KEY_WIDTH_DIGITS
bool nbgl_keyboardGetPosition(nbgl_keyboard_t *kbd, char index, uint16_t *x, uint16_t *y)
This function gets the position (top-left corner) of the key at the given index. (to be used for Test...
#define SECOND_LINE_OFFSET
void nbgl_objDrawKeyboard(nbgl_keyboard_t *kbd)
This function draws a keyboard object.
#define SPECIAL_CHARS_KEY_WIDTH
#define FIRST_LINE_CHAR_COUNT
#define BACKSPACE_KEY_WIDTH_FULL
#define SECOND_LINE_CHAR_COUNT
#define IS_KEY_MASKED(_index)
bool nbgl_touchGetTouchedPosition(nbgl_obj_t *obj, nbgl_touchStatePosition_t **firstPos, nbgl_touchStatePosition_t **lastPos)
@ POST_REFRESH_FORCE_POWER_ON
Force screen power on after refresh.
nbgl_touchType_t
The different types of Touchscreen events.
#define NO_TRANSFORMATION
@ NBGL_BPP_1
1 bit per pixel
struct PACKED__ nbgl_area_s nbgl_area_t
Represents a rectangle area of the screen.
@ BLACK_AND_WHITE_REFRESH
to be used for pure B&W area, when contrast is important
@ FULL_COLOR_REFRESH
to be used for normal refresh
The low level Touchscreen event, coming from driver.
int16_t y
vertical position of the touch (or for a RELEASED the last touched point)
int16_t x
horizontal position of the touch (or for a RELEASED the last touched point)