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) & 0xFFC)
34#elif (SCREEN_WIDTH == 480)
35#define NORMAL_KEY_WIDTH 48
36#define LETTER_OFFSET_Y (((KEYBOARD_KEY_HEIGHT - 36) / 2) & 0xFFC)
38#define SHIFT_KEY_WIDTH (NORMAL_KEY_WIDTH + SECOND_LINE_OFFSET)
39#define SECOND_LINE_OFFSET ((SCREEN_WIDTH - (SECOND_LINE_CHAR_COUNT * NORMAL_KEY_WIDTH)) / 2)
40#if defined(TARGET_STAX)
41#define SPACE_KEY_WIDTH 276
42#elif defined(TARGET_FLEX)
43#define SPACE_KEY_WIDTH 336
45#define SWITCH_KEY_WIDTH (SCREEN_WIDTH - SPACE_KEY_WIDTH)
46#define SPECIAL_CHARS_KEY_WIDTH (NORMAL_KEY_WIDTH * 2 + SECOND_LINE_OFFSET)
47#define BACKSPACE_KEY_WIDTH_FULL SHIFT_KEY_WIDTH
48#define BACKSPACE_KEY_WIDTH_DIGITS SPECIAL_CHARS_KEY_WIDTH
49#define BACKSPACE_KEY_WIDTH_LETTERS_ONLY (SCREEN_WIDTH - 7 * NORMAL_KEY_WIDTH)
51#define IS_KEY_MASKED(_index) (keyboard->keyMask & (1 << _index))
64static const char kbd_chars[] =
"qwertyuiopasdfghjklzxcvbnm";
65static const char kbd_chars_upper[] =
"QWERTYUIOPASDFGHJKLZXCVBNM";
67static const char kbd_specials[] =
"[]{}#%^*+=_\\|~<>$`\".,?!\'";
80 if (position->
y < KEYBOARD_KEY_HEIGHT) {
82 i = position->
x / NORMAL_KEY_WIDTH;
84 else if (position->
y < (2 * KEYBOARD_KEY_HEIGHT)) {
91 else if (position->
y < (3 * KEYBOARD_KEY_HEIGHT)) {
95 if (!keyboard->lettersOnly) {
130 else if (!keyboard->lettersOnly && (position->
y < (4 * KEYBOARD_KEY_HEIGHT))) {
148 rectArea.backgroundColor = keyboard->obj.area.backgroundColor;
149 rectArea.x0 = keyboard->obj.area.x0;
150 rectArea.y0 = keyboard->obj.area.y0;
151 rectArea.width = keyboard->obj.area.width;
152 rectArea.height = keyboard->obj.area.height;
156 rectArea.backgroundColor = keyboard->obj.area.backgroundColor;
157 rectArea.x0 = keyboard->obj.area.x0;
158 rectArea.y0 = keyboard->obj.area.y0;
159 rectArea.width = keyboard->obj.area.width;
160 rectArea.height = VERTICAL_ALIGNMENT;
162 rectArea.y0 += KEYBOARD_KEY_HEIGHT;
164 rectArea.y0 += KEYBOARD_KEY_HEIGHT;
167 if ((keyboard->obj.alignmentMarginY > 0) || (!keyboard->lettersOnly)) {
168 rectArea.y0 += KEYBOARD_KEY_HEIGHT;
172 if ((keyboard->obj.alignmentMarginY > 0) && (!keyboard->lettersOnly)) {
173 rectArea.y0 += KEYBOARD_KEY_HEIGHT;
177 rectArea.backgroundColor = keyboard->borderColor;
178 rectArea.x0 = keyboard->obj.area.x0;
179 rectArea.y0 = keyboard->obj.area.y0;
181 rectArea.height = KEYBOARD_KEY_HEIGHT * 3;
182 if (!keyboard->lettersOnly) {
183 rectArea.height += KEYBOARD_KEY_HEIGHT;
195 keyboardDrawCommonLines(keyboard);
198 rectArea.backgroundColor = keyboard->borderColor;
199 rectArea.x0 = keyboard->obj.area.x0;
200 rectArea.y0 = keyboard->obj.area.y0;
202 rectArea.height = KEYBOARD_KEY_HEIGHT;
204 for (i = 0; i < 9; i++) {
205 rectArea.x0 += NORMAL_KEY_WIDTH;
211 rectArea.y0 += KEYBOARD_KEY_HEIGHT;
213 for (i = 10; i < 19; i++) {
214 rectArea.x0 += NORMAL_KEY_WIDTH;
219 rectArea.y0 += KEYBOARD_KEY_HEIGHT;
220 if (!keyboard->lettersOnly) {
224 rectArea.x0 = NORMAL_KEY_WIDTH;
226 for (i = 0; i < 6; i++) {
228 rectArea.x0 += NORMAL_KEY_WIDTH;
230 if (!keyboard->lettersOnly) {
232 rectArea.x0 += NORMAL_KEY_WIDTH;
237 if (!keyboard->lettersOnly) {
238 rectArea.y0 += KEYBOARD_KEY_HEIGHT;
251 keyboardDrawCommonLines(keyboard);
254 rectArea.backgroundColor = keyboard->borderColor;
255 rectArea.x0 = keyboard->obj.area.x0;
256 rectArea.y0 = keyboard->obj.area.y0;
258 rectArea.height = KEYBOARD_KEY_HEIGHT;
260 for (i = 0; i < 9; i++) {
261 rectArea.x0 += NORMAL_KEY_WIDTH;
267 rectArea.y0 += KEYBOARD_KEY_HEIGHT;
269 for (i = 10; i < 19; i++) {
270 rectArea.x0 += NORMAL_KEY_WIDTH;
275 rectArea.y0 += KEYBOARD_KEY_HEIGHT;
277 for (i = 0; i < 5; i++) {
278 rectArea.x0 += NORMAL_KEY_WIDTH;
283 rectArea.y0 += KEYBOARD_KEY_HEIGHT;
296 keys = kbd_chars_upper;
302 rectArea.backgroundColor = keyboard->obj.area.backgroundColor;
303 rectArea.y0 = keyboard->obj.area.y0 + LETTER_OFFSET_Y;
305 rectArea.height = KEYBOARD_KEY_HEIGHT * 3;
306 rectArea.x0 = keyboard->obj.area.x0;
309 for (i = 0; i < 10; i++) {
310 rectArea.x0 = keyboard->obj.area.x0 + i * NORMAL_KEY_WIDTH;
313 += (NORMAL_KEY_WIDTH -
nbgl_getCharWidth(SMALL_REGULAR_1BPP_FONT, &keys[i])) / 2;
318 rectArea.y0 += KEYBOARD_KEY_HEIGHT;
319 for (i = 10; i < 19; i++) {
320 rectArea.x0 = keyboard->obj.area.x0 +
SECOND_LINE_OFFSET + (i - 10) * NORMAL_KEY_WIDTH;
322 += (NORMAL_KEY_WIDTH -
nbgl_getCharWidth(SMALL_REGULAR_1BPP_FONT, &keys[i])) / 2;
327 rectArea.y0 += KEYBOARD_KEY_HEIGHT;
329 if (!keyboard->lettersOnly) {
332 rectArea.height = KEYBOARD_KEY_HEIGHT;
334 rectArea.y0 = keyboard->obj.area.y0 + KEYBOARD_KEY_HEIGHT * 2;
340 rectArea.height = VERTICAL_ALIGNMENT;
342 rectArea.y0 = keyboard->obj.area.y0 + KEYBOARD_KEY_HEIGHT * 2;
346 rectArea.width = SHIFT_ICON.width;
347 rectArea.height = SHIFT_ICON.height;
349 rectArea.y0 = (keyboard->obj.area.y0 + KEYBOARD_KEY_HEIGHT * 2
350 + (KEYBOARD_KEY_HEIGHT - rectArea.height) / 2)
354 rectArea.backgroundColor =
WHITE;
364 rectArea.backgroundColor =
WHITE;
371 rectArea.y0 = keyboard->obj.area.y0 + KEYBOARD_KEY_HEIGHT * 2 + LETTER_OFFSET_Y;
372 for (i = 19; i < 26; i++) {
373 rectArea.x0 = offsetX + (i - 19) * NORMAL_KEY_WIDTH;
375 += (NORMAL_KEY_WIDTH -
nbgl_getCharWidth(SMALL_REGULAR_1BPP_FONT, &keys[i])) / 2;
380 rectArea.width = BACKSPACE_ICON.width;
381 rectArea.height = BACKSPACE_ICON.height;
383 rectArea.x0 = offsetX + 7 * NORMAL_KEY_WIDTH;
384 rectArea.y0 = (keyboard->obj.area.y0 + KEYBOARD_KEY_HEIGHT * 2
385 + (KEYBOARD_KEY_HEIGHT - rectArea.height) / 2)
387 if (!keyboard->lettersOnly) {
399 if (!keyboard->lettersOnly) {
401 rectArea.y0 = keyboard->obj.area.y0 + KEYBOARD_KEY_HEIGHT * 3 + LETTER_OFFSET_Y;
405 SMALL_REGULAR_1BPP_FONT,
430 rectArea.backgroundColor = keyboard->obj.area.backgroundColor;
431 rectArea.y0 = keyboard->obj.area.y0 + LETTER_OFFSET_Y;
433 rectArea.height = KEYBOARD_KEY_HEIGHT * 3;
434 rectArea.x0 = keyboard->obj.area.x0;
437 for (i = 0; i < 10; i++) {
438 rectArea.x0 = keyboard->obj.area.x0 + i * NORMAL_KEY_WIDTH;
440 += (NORMAL_KEY_WIDTH -
nbgl_getCharWidth(SMALL_REGULAR_1BPP_FONT, &keys[i])) / 2;
445 rectArea.y0 += KEYBOARD_KEY_HEIGHT;
446 for (i = 10; i < 19; i++) {
447 rectArea.x0 = keyboard->obj.area.x0 + (i - 10) * NORMAL_KEY_WIDTH +
SECOND_LINE_OFFSET;
449 += (NORMAL_KEY_WIDTH -
nbgl_getCharWidth(SMALL_REGULAR_1BPP_FONT, &keys[i])) / 2;
459 rectArea.y0 = keyboard->obj.area.y0 + KEYBOARD_KEY_HEIGHT * 2 + LETTER_OFFSET_Y;
465 rectArea.y0 = keyboard->obj.area.y0 + KEYBOARD_KEY_HEIGHT * 2 + LETTER_OFFSET_Y;
469 for (i = 19; i < 24; i++) {
472 += (NORMAL_KEY_WIDTH -
nbgl_getCharWidth(SMALL_REGULAR_1BPP_FONT, &keys[i])) / 2;
477 rectArea.width = BACKSPACE_ICON.width;
478 rectArea.height = BACKSPACE_ICON.height;
481 rectArea.y0 = keyboard->obj.area.y0 + KEYBOARD_KEY_HEIGHT * 2
482 + (((KEYBOARD_KEY_HEIGHT - rectArea.height) / 2) & 0xFFC);
488 rectArea.y0 = keyboard->obj.area.y0 + KEYBOARD_KEY_HEIGHT * 3 + LETTER_OFFSET_Y;
502 keyboardDrawLetterGrid(keyboard);
505 keyboardDrawLetters(keyboard);
509 keyboardDrawDigitsGrid(keyboard);
512 keyboardDrawDigits(keyboard);
529 uint8_t firstIndex, lastIndex;
541 firstPosition->
x -= obj->area.x0;
542 firstPosition->
y -= obj->area.y0;
543 lastPosition->
x -= obj->area.x0;
544 lastPosition->
y -= obj->area.y0;
546 firstIndex = getKeyboardIndex(keyboard, firstPosition);
550 lastIndex = getKeyboardIndex(keyboard, lastPosition);
555 if (lastIndex != firstIndex) {
567 keyboard->needsRefresh =
true;
569 if ((firstIndex < 26) && ((
IS_KEY_MASKED(firstIndex)) == 0)) {
570 keyboard->callback((cur_casing !=
LOWER_CASE) ? kbd_chars_upper[firstIndex]
571 : kbd_chars[firstIndex]);
574 switch (keyboard->casing) {
596 if (firstIndex < 26) {
612 if (firstIndex < 26) {
613 keyboard->callback(kbd_specials[firstIndex]);
631 keyboard->callback(
' ');
647 uint8_t charIndex = 0;
649 while (charIndex < 26) {
650 if (index == kbd_chars[charIndex]) {
658 *x = kbd->obj.area.x0 + charIndex * NORMAL_KEY_WIDTH;
659 *y = kbd->obj.area.y0;
664 *y = kbd->obj.area.y0 + KEYBOARD_KEY_HEIGHT;
666 else if (charIndex <
sizeof(kbd_chars)) {
668 *x = kbd->obj.area.x0
671 if (!kbd->lettersOnly) {
676 *x = kbd->obj.area.x0
680 *y = kbd->obj.area.y0 + 2 * KEYBOARD_KEY_HEIGHT;
695 kbd->obj.touchMask = (1 <<
TOUCHED);
697 kbd->needsRefresh =
false;
704 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_frontDrawHorizontalLine(const nbgl_area_t *area, uint8_t mask, 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)