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;
216 for (i = 0; i < 9; i++) {
217 rectArea.x0 += NORMAL_KEY_WIDTH;
223 rectArea.y0 += KEYBOARD_KEY_HEIGHT;
225 for (i = 10; i < 19; i++) {
226 rectArea.x0 += NORMAL_KEY_WIDTH;
234 uint8_t nbLines, firstShift;
236 if (keyboard->lettersOnly) {
238 firstShift = NORMAL_KEY_WIDTH;
249 rectArea.x0 = keyboard->obj.area.x0 + firstShift;
250 rectArea.y0 += KEYBOARD_KEY_HEIGHT;
251 for (i = 0; i < nbLines; i++) {
253 rectArea.x0 += NORMAL_KEY_WIDTH;
257 if (!keyboard->lettersOnly || (keyboard->mode !=
MODE_LETTERS)) {
259 rectArea.y0 += KEYBOARD_KEY_HEIGHT;
263 rectArea.height -= 2;
277 keys = kbd_chars_upper;
283 rectArea.backgroundColor = keyboard->obj.area.backgroundColor;
284 rectArea.y0 = keyboard->obj.area.y0 + LETTER_OFFSET_Y;
286 rectArea.height = KEYBOARD_KEY_HEIGHT * 3;
287 rectArea.x0 = keyboard->obj.area.x0;
290 for (i = 0; i < 10; i++) {
291 rectArea.x0 = keyboard->obj.area.x0 + i * NORMAL_KEY_WIDTH;
294 += (NORMAL_KEY_WIDTH -
nbgl_getCharWidth(SMALL_REGULAR_1BPP_FONT, &keys[i])) / 2;
299 rectArea.y0 += KEYBOARD_KEY_HEIGHT;
300 for (i = 10; i < 19; i++) {
301 rectArea.x0 = keyboard->obj.area.x0 +
SECOND_LINE_OFFSET + (i - 10) * NORMAL_KEY_WIDTH;
303 += (NORMAL_KEY_WIDTH -
nbgl_getCharWidth(SMALL_REGULAR_1BPP_FONT, &keys[i])) / 2;
308 rectArea.y0 += KEYBOARD_KEY_HEIGHT;
310 if (!keyboard->lettersOnly) {
312#if defined(TARGET_STAX)
314 rectArea.height = KEYBOARD_KEY_HEIGHT;
316#elif defined(TARGET_FLEX)
318 rectArea.height = KEYBOARD_KEY_HEIGHT;
320#elif defined(TARGET_APEX)
327 rectArea.height = KEYBOARD_KEY_HEIGHT + 1;
331 rectArea.y0 = keyboard->obj.area.y0 + KEYBOARD_KEY_HEIGHT * 2;
343 rectArea.y0 = keyboard->obj.area.y0 + KEYBOARD_KEY_HEIGHT * 2;
346 rectArea.y0 += KEYBOARD_KEY_HEIGHT;
347 rectArea.backgroundColor =
WHITE;
351 rectArea.width = SHIFT_ICON.width;
352 rectArea.height = SHIFT_ICON.height;
354 rectArea.y0 = (keyboard->obj.area.y0 + KEYBOARD_KEY_HEIGHT * 2
355 + (KEYBOARD_KEY_HEIGHT - rectArea.height) / 2);
358 rectArea.backgroundColor =
WHITE;
368 rectArea.backgroundColor =
WHITE;
375 rectArea.y0 = keyboard->obj.area.y0 + KEYBOARD_KEY_HEIGHT * 2 + LETTER_OFFSET_Y;
376 for (i = 19; i < 26; i++) {
377 rectArea.x0 = offsetX + (i - 19) * NORMAL_KEY_WIDTH;
379 += (NORMAL_KEY_WIDTH -
nbgl_getCharWidth(SMALL_REGULAR_1BPP_FONT, &keys[i])) / 2;
384 rectArea.width = BACKSPACE_ICON.width;
385 rectArea.height = BACKSPACE_ICON.height;
387 rectArea.x0 = offsetX + 7 * NORMAL_KEY_WIDTH;
388 rectArea.y0 = (keyboard->obj.area.y0 + KEYBOARD_KEY_HEIGHT * 2
389 + (KEYBOARD_KEY_HEIGHT - rectArea.height) / 2);
390 if (!keyboard->lettersOnly) {
402 if (!keyboard->lettersOnly) {
404 rectArea.y0 = keyboard->obj.area.y0 + KEYBOARD_KEY_HEIGHT * 3 + LETTER_OFFSET_Y;
408 SMALL_REGULAR_1BPP_FONT,
433 rectArea.backgroundColor = keyboard->obj.area.backgroundColor;
434 rectArea.y0 = keyboard->obj.area.y0 + LETTER_OFFSET_Y;
436 rectArea.height = KEYBOARD_KEY_HEIGHT * 3;
437 rectArea.x0 = keyboard->obj.area.x0;
440 for (i = 0; i < 10; i++) {
441 rectArea.x0 = keyboard->obj.area.x0 + i * NORMAL_KEY_WIDTH;
443 += (NORMAL_KEY_WIDTH -
nbgl_getCharWidth(SMALL_REGULAR_1BPP_FONT, &keys[i])) / 2;
448 rectArea.y0 += KEYBOARD_KEY_HEIGHT;
449 for (i = 10; i < 19; i++) {
450 rectArea.x0 = keyboard->obj.area.x0 + (i - 10) * NORMAL_KEY_WIDTH +
SECOND_LINE_OFFSET;
452 += (NORMAL_KEY_WIDTH -
nbgl_getCharWidth(SMALL_REGULAR_1BPP_FONT, &keys[i])) / 2;
462 rectArea.y0 = keyboard->obj.area.y0 + KEYBOARD_KEY_HEIGHT * 2 + LETTER_OFFSET_Y;
468 rectArea.y0 = keyboard->obj.area.y0 + KEYBOARD_KEY_HEIGHT * 2 + LETTER_OFFSET_Y;
472 for (i = 19; i < 24; i++) {
475 += (NORMAL_KEY_WIDTH -
nbgl_getCharWidth(SMALL_REGULAR_1BPP_FONT, &keys[i])) / 2;
480 rectArea.width = BACKSPACE_ICON.width;
481 rectArea.height = BACKSPACE_ICON.height;
484 rectArea.y0 = keyboard->obj.area.y0 + KEYBOARD_KEY_HEIGHT * 2
485 + ((KEYBOARD_KEY_HEIGHT - rectArea.height) / 2);
491 rectArea.y0 = keyboard->obj.area.y0 + KEYBOARD_KEY_HEIGHT * 3 + LETTER_OFFSET_Y;
504 keyboardDrawGrid(keyboard);
507 keyboardDrawLetters(keyboard);
511 keyboardDrawDigits(keyboard);
528 uint8_t firstIndex, lastIndex;
540 firstPosition->
x -= obj->area.x0;
541 firstPosition->
y -= obj->area.y0;
542 lastPosition->
x -= obj->area.x0;
543 lastPosition->
y -= obj->area.y0;
545 firstIndex = getKeyboardIndex(keyboard, firstPosition);
549 lastIndex = getKeyboardIndex(keyboard, lastPosition);
554 if (lastIndex != firstIndex) {
566 keyboard->needsRefresh =
true;
568 if ((firstIndex < 26) && ((
IS_KEY_MASKED(firstIndex)) == 0)) {
569 keyboard->callback((cur_casing !=
LOWER_CASE) ? kbd_chars_upper[firstIndex]
570 : kbd_chars[firstIndex]);
573 switch (keyboard->casing) {
595 if (firstIndex < 26) {
611 if (firstIndex < 26) {
612 keyboard->callback(kbd_specials[firstIndex]);
630 keyboard->callback(
' ');
646 uint8_t charIndex = 0;
648 while (charIndex < 26) {
649 if (index == kbd_chars[charIndex]) {
657 *x = kbd->obj.area.x0 + charIndex * NORMAL_KEY_WIDTH;
658 *y = kbd->obj.area.y0;
663 *y = kbd->obj.area.y0 + KEYBOARD_KEY_HEIGHT;
665 else if (charIndex <
sizeof(kbd_chars)) {
667 *x = kbd->obj.area.x0
670 if (!kbd->lettersOnly) {
675 *x = kbd->obj.area.x0
679 *y = kbd->obj.area.y0 + 2 * KEYBOARD_KEY_HEIGHT;
694 kbd->obj.touchMask = (1 <<
TOUCHED);
696 kbd->needsRefresh =
false;
703 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)