Example of using the LVGL (8.3.4) with the MbedOS (6.16 - bare metal) on the Disco-F746NG board

Dependencies:   BSP_DISCO_F746NG

Committer:
JohnnyK
Date:
Tue Apr 07 08:06:45 2020 +0000
Revision:
2:afc050526249
Parent:
0:10c4b83c458d
add link to a Notebook page

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JohnnyK 0:10c4b83c458d 1 /**
JohnnyK 0:10c4b83c458d 2 * @file lv_port_indev_templ.c
JohnnyK 0:10c4b83c458d 3 *
JohnnyK 0:10c4b83c458d 4 */
JohnnyK 0:10c4b83c458d 5
JohnnyK 0:10c4b83c458d 6 /*Copy this file as "lv_port_indev.c" and set this value to "1" to enable content*/
JohnnyK 0:10c4b83c458d 7 #if 1
JohnnyK 0:10c4b83c458d 8
JohnnyK 0:10c4b83c458d 9 /*********************
JohnnyK 0:10c4b83c458d 10 * INCLUDES
JohnnyK 0:10c4b83c458d 11 *********************/
JohnnyK 0:10c4b83c458d 12 #include "lv_port_indev.h"
JohnnyK 0:10c4b83c458d 13 #include "../lv_core/lv_indev.h"
JohnnyK 0:10c4b83c458d 14 #include "stm32746g_discovery.h"
JohnnyK 0:10c4b83c458d 15 #include "stm32746g_discovery_lcd.h"
JohnnyK 0:10c4b83c458d 16 #include "stm32746g_discovery_ts.h"
JohnnyK 0:10c4b83c458d 17
JohnnyK 0:10c4b83c458d 18 /*********************
JohnnyK 0:10c4b83c458d 19 * DEFINES
JohnnyK 0:10c4b83c458d 20 *********************/
JohnnyK 0:10c4b83c458d 21 #define TOUCHPAD 1
JohnnyK 0:10c4b83c458d 22 #define KEYBOARD 0
JohnnyK 0:10c4b83c458d 23 #define MOUSE 0
JohnnyK 0:10c4b83c458d 24 #define ENCODER 0
JohnnyK 0:10c4b83c458d 25 #define BUTTON 0
JohnnyK 0:10c4b83c458d 26
JohnnyK 0:10c4b83c458d 27
JohnnyK 0:10c4b83c458d 28 /**********************
JohnnyK 0:10c4b83c458d 29 * TYPEDEFS
JohnnyK 0:10c4b83c458d 30 **********************/
JohnnyK 0:10c4b83c458d 31 TS_StateTypeDef TS_State;
JohnnyK 0:10c4b83c458d 32 /**********************
JohnnyK 0:10c4b83c458d 33 * STATIC PROTOTYPES
JohnnyK 0:10c4b83c458d 34 **********************/
JohnnyK 0:10c4b83c458d 35 #if TOUCHPAD ==1
JohnnyK 0:10c4b83c458d 36 static void touchpad_init(void);
JohnnyK 0:10c4b83c458d 37 static bool touchpad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
JohnnyK 0:10c4b83c458d 38 static bool touchpad_is_pressed(void);
JohnnyK 0:10c4b83c458d 39 static void touchpad_get_xy(lv_coord_t * x, lv_coord_t * y);
JohnnyK 0:10c4b83c458d 40 #endif
JohnnyK 0:10c4b83c458d 41 #if MOUSE == 1
JohnnyK 0:10c4b83c458d 42 static void mouse_init(void);
JohnnyK 0:10c4b83c458d 43 static bool mouse_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
JohnnyK 0:10c4b83c458d 44 static bool mouse_is_pressed(void);
JohnnyK 0:10c4b83c458d 45 static void mouse_get_xy(lv_coord_t * x, lv_coord_t * y);
JohnnyK 0:10c4b83c458d 46 #endif
JohnnyK 0:10c4b83c458d 47 #if KEYBOARD == 1
JohnnyK 0:10c4b83c458d 48 static void keypad_init(void);
JohnnyK 0:10c4b83c458d 49 static bool keypad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
JohnnyK 0:10c4b83c458d 50 static uint32_t keypad_get_key(void);
JohnnyK 0:10c4b83c458d 51 #endif
JohnnyK 0:10c4b83c458d 52 #if ENCODER == 1
JohnnyK 0:10c4b83c458d 53 static void encoder_init(void);
JohnnyK 0:10c4b83c458d 54 static bool encoder_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
JohnnyK 0:10c4b83c458d 55 static void encoder_handler(void);
JohnnyK 0:10c4b83c458d 56 #endif
JohnnyK 0:10c4b83c458d 57 #if BUTTON == 1
JohnnyK 0:10c4b83c458d 58 static void button_init(void);
JohnnyK 0:10c4b83c458d 59 static bool button_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
JohnnyK 0:10c4b83c458d 60 static int8_t button_get_pressed_id(void);
JohnnyK 0:10c4b83c458d 61 static bool button_is_pressed(uint8_t id);
JohnnyK 0:10c4b83c458d 62 #endif
JohnnyK 0:10c4b83c458d 63
JohnnyK 0:10c4b83c458d 64 /**********************
JohnnyK 0:10c4b83c458d 65 * STATIC VARIABLES
JohnnyK 0:10c4b83c458d 66 **********************/
JohnnyK 0:10c4b83c458d 67 #if TOUCHPAD == 1
JohnnyK 0:10c4b83c458d 68 lv_indev_t * indev_touchpad;
JohnnyK 0:10c4b83c458d 69 #endif
JohnnyK 0:10c4b83c458d 70 #if MOUSE == 1
JohnnyK 0:10c4b83c458d 71 lv_indev_t * indev_mouse;
JohnnyK 0:10c4b83c458d 72 #endif
JohnnyK 0:10c4b83c458d 73 #if KEYBOARD == 1
JohnnyK 0:10c4b83c458d 74 lv_indev_t * indev_keypad;
JohnnyK 0:10c4b83c458d 75 #endif
JohnnyK 0:10c4b83c458d 76 #if ENCODER == 1
JohnnyK 0:10c4b83c458d 77 lv_indev_t * indev_encoder;
JohnnyK 0:10c4b83c458d 78 #endif
JohnnyK 0:10c4b83c458d 79 #if BUTTON == 1
JohnnyK 0:10c4b83c458d 80 lv_indev_t * indev_button;
JohnnyK 0:10c4b83c458d 81 #endif
JohnnyK 0:10c4b83c458d 82
JohnnyK 0:10c4b83c458d 83 #if ENCODER == 1
JohnnyK 0:10c4b83c458d 84 static int32_t encoder_diff;
JohnnyK 0:10c4b83c458d 85 static lv_indev_state_t encoder_state;
JohnnyK 0:10c4b83c458d 86 #endif
JohnnyK 0:10c4b83c458d 87 /**********************
JohnnyK 0:10c4b83c458d 88 * MACROS
JohnnyK 0:10c4b83c458d 89 **********************/
JohnnyK 0:10c4b83c458d 90
JohnnyK 0:10c4b83c458d 91 /**********************
JohnnyK 0:10c4b83c458d 92 * GLOBAL FUNCTIONS
JohnnyK 0:10c4b83c458d 93 **********************/
JohnnyK 0:10c4b83c458d 94
JohnnyK 0:10c4b83c458d 95 void lv_port_indev_init(void)
JohnnyK 0:10c4b83c458d 96 {
JohnnyK 0:10c4b83c458d 97 /* Here you will find example implementation of input devices supported by LittelvGL:
JohnnyK 0:10c4b83c458d 98 * - Touchpad
JohnnyK 0:10c4b83c458d 99 * - Mouse (with cursor support)
JohnnyK 0:10c4b83c458d 100 * - Keypad (supports GUI usage only with key)
JohnnyK 0:10c4b83c458d 101 * - Encoder (supports GUI usage only with: left, right, push)
JohnnyK 0:10c4b83c458d 102 * - Button (external buttons to press points on the screen)
JohnnyK 0:10c4b83c458d 103 *
JohnnyK 0:10c4b83c458d 104 * The `..._read()` function are only examples.
JohnnyK 0:10c4b83c458d 105 * You should shape them according to your hardware
JohnnyK 0:10c4b83c458d 106 */
JohnnyK 0:10c4b83c458d 107
JohnnyK 0:10c4b83c458d 108 lv_indev_drv_t indev_drv;
JohnnyK 0:10c4b83c458d 109 #if TOUCHPAD ==1
JohnnyK 0:10c4b83c458d 110 /*------------------
JohnnyK 0:10c4b83c458d 111 * Touchpad
JohnnyK 0:10c4b83c458d 112 * -----------------*/
JohnnyK 0:10c4b83c458d 113
JohnnyK 0:10c4b83c458d 114 /*Initialize your touchpad if you have*/
JohnnyK 0:10c4b83c458d 115 touchpad_init();
JohnnyK 0:10c4b83c458d 116
JohnnyK 0:10c4b83c458d 117 /*Register a touchpad input device*/
JohnnyK 0:10c4b83c458d 118 lv_indev_drv_init(&indev_drv);
JohnnyK 0:10c4b83c458d 119 indev_drv.type = LV_INDEV_TYPE_POINTER;
JohnnyK 0:10c4b83c458d 120 indev_drv.read_cb = touchpad_read;
JohnnyK 0:10c4b83c458d 121 indev_touchpad = lv_indev_drv_register(&indev_drv);
JohnnyK 0:10c4b83c458d 122
JohnnyK 0:10c4b83c458d 123 #endif
JohnnyK 0:10c4b83c458d 124 #if MOUSE == 1
JohnnyK 0:10c4b83c458d 125
JohnnyK 0:10c4b83c458d 126 /*------------------
JohnnyK 0:10c4b83c458d 127 * Mouse
JohnnyK 0:10c4b83c458d 128 * -----------------*/
JohnnyK 0:10c4b83c458d 129
JohnnyK 0:10c4b83c458d 130 /*Initialize your touchpad if you have*/
JohnnyK 0:10c4b83c458d 131 mouse_init();
JohnnyK 0:10c4b83c458d 132
JohnnyK 0:10c4b83c458d 133 /*Register a mouse input device*/
JohnnyK 0:10c4b83c458d 134 lv_indev_drv_init(&indev_drv);
JohnnyK 0:10c4b83c458d 135 indev_drv.type = LV_INDEV_TYPE_POINTER;
JohnnyK 0:10c4b83c458d 136 indev_drv.read_cb = mouse_read;
JohnnyK 0:10c4b83c458d 137 indev_mouse = lv_indev_drv_register(&indev_drv);
JohnnyK 0:10c4b83c458d 138
JohnnyK 0:10c4b83c458d 139 /*Set cursor. For simplicity set a HOME symbol now.*/
JohnnyK 0:10c4b83c458d 140 lv_obj_t * mouse_cursor = lv_img_create(lv_disp_get_scr_act(NULL), NULL);
JohnnyK 0:10c4b83c458d 141 lv_img_set_src(mouse_cursor, LV_SYMBOL_HOME);
JohnnyK 0:10c4b83c458d 142 lv_indev_set_cursor(indev_mouse, mouse_cursor);
JohnnyK 0:10c4b83c458d 143
JohnnyK 0:10c4b83c458d 144 #endif
JohnnyK 0:10c4b83c458d 145 #if KEYBOARD == 1
JohnnyK 0:10c4b83c458d 146
JohnnyK 0:10c4b83c458d 147 /*------------------
JohnnyK 0:10c4b83c458d 148 * Keypad
JohnnyK 0:10c4b83c458d 149 * -----------------*/
JohnnyK 0:10c4b83c458d 150
JohnnyK 0:10c4b83c458d 151 /*Initialize your keypad or keyboard if you have*/
JohnnyK 0:10c4b83c458d 152 keypad_init();
JohnnyK 0:10c4b83c458d 153
JohnnyK 0:10c4b83c458d 154 /*Register a keypad input device*/
JohnnyK 0:10c4b83c458d 155 lv_indev_drv_init(&indev_drv);
JohnnyK 0:10c4b83c458d 156 indev_drv.type = LV_INDEV_TYPE_KEYPAD;
JohnnyK 0:10c4b83c458d 157 indev_drv.read_cb = keypad_read;
JohnnyK 0:10c4b83c458d 158 indev_keypad = lv_indev_drv_register(&indev_drv);
JohnnyK 0:10c4b83c458d 159
JohnnyK 0:10c4b83c458d 160 /* Later you should create group(s) with `lv_group_t * group = lv_group_create()`,
JohnnyK 0:10c4b83c458d 161 * add objects to the group with `lv_group_add_obj(group, obj)`
JohnnyK 0:10c4b83c458d 162 * and assign this input device to group to navigate in it:
JohnnyK 0:10c4b83c458d 163 * `lv_indev_set_group(indev_keypad, group);` */
JohnnyK 0:10c4b83c458d 164
JohnnyK 0:10c4b83c458d 165 #endif
JohnnyK 0:10c4b83c458d 166 #if ENCODER == 1
JohnnyK 0:10c4b83c458d 167
JohnnyK 0:10c4b83c458d 168 /*------------------
JohnnyK 0:10c4b83c458d 169 * Encoder
JohnnyK 0:10c4b83c458d 170 * -----------------*/
JohnnyK 0:10c4b83c458d 171
JohnnyK 0:10c4b83c458d 172 /*Initialize your encoder if you have*/
JohnnyK 0:10c4b83c458d 173 encoder_init();
JohnnyK 0:10c4b83c458d 174
JohnnyK 0:10c4b83c458d 175 /*Register a encoder input device*/
JohnnyK 0:10c4b83c458d 176 lv_indev_drv_init(&indev_drv);
JohnnyK 0:10c4b83c458d 177 indev_drv.type = LV_INDEV_TYPE_KEYPAD;
JohnnyK 0:10c4b83c458d 178 indev_drv.read_cb = encoder_read;
JohnnyK 0:10c4b83c458d 179 indev_encoder = lv_indev_drv_register(&indev_drv);
JohnnyK 0:10c4b83c458d 180
JohnnyK 0:10c4b83c458d 181 /* Later you should create group(s) with `lv_group_t * group = lv_group_create()`,
JohnnyK 0:10c4b83c458d 182 * add objects to the group with `lv_group_add_obj(group, obj)`
JohnnyK 0:10c4b83c458d 183 * and assign this input device to group to navigate in it:
JohnnyK 0:10c4b83c458d 184 * `lv_indev_set_group(indev_keypad, group);` */
JohnnyK 0:10c4b83c458d 185
JohnnyK 0:10c4b83c458d 186 #endif
JohnnyK 0:10c4b83c458d 187 #if BUTTON == 1
JohnnyK 0:10c4b83c458d 188
JohnnyK 0:10c4b83c458d 189 /*------------------
JohnnyK 0:10c4b83c458d 190 * Button
JohnnyK 0:10c4b83c458d 191 * -----------------*/
JohnnyK 0:10c4b83c458d 192
JohnnyK 0:10c4b83c458d 193 /*Initialize your button if you have*/
JohnnyK 0:10c4b83c458d 194 button_init();
JohnnyK 0:10c4b83c458d 195
JohnnyK 0:10c4b83c458d 196 /*Register a button input device*/
JohnnyK 0:10c4b83c458d 197 lv_indev_drv_init(&indev_drv);
JohnnyK 0:10c4b83c458d 198 indev_drv.type = LV_INDEV_TYPE_BUTTON;
JohnnyK 0:10c4b83c458d 199 indev_drv.read_cb = button_read;
JohnnyK 0:10c4b83c458d 200 indev_button = lv_indev_drv_register(&indev_drv);
JohnnyK 0:10c4b83c458d 201
JohnnyK 0:10c4b83c458d 202 /*Assign buttons to points on the screen*/
JohnnyK 0:10c4b83c458d 203 static const lv_point_t btn_points[2] = {
JohnnyK 0:10c4b83c458d 204 {10, 10}, /*Button 0 -> x:10; y:10*/
JohnnyK 0:10c4b83c458d 205 {40, 100}, /*Button 1 -> x:40; y:100*/
JohnnyK 0:10c4b83c458d 206 };
JohnnyK 0:10c4b83c458d 207 lv_indev_set_button_points(indev_button, btn_points);
JohnnyK 0:10c4b83c458d 208
JohnnyK 0:10c4b83c458d 209 #endif
JohnnyK 0:10c4b83c458d 210 }
JohnnyK 0:10c4b83c458d 211
JohnnyK 0:10c4b83c458d 212 /**********************
JohnnyK 0:10c4b83c458d 213 * STATIC FUNCTIONS
JohnnyK 0:10c4b83c458d 214 **********************/
JohnnyK 0:10c4b83c458d 215
JohnnyK 0:10c4b83c458d 216
JohnnyK 0:10c4b83c458d 217 #if TOUCHPAD ==1
JohnnyK 0:10c4b83c458d 218 /*------------------
JohnnyK 0:10c4b83c458d 219 * Touchpad
JohnnyK 0:10c4b83c458d 220 * -----------------*/
JohnnyK 0:10c4b83c458d 221
JohnnyK 0:10c4b83c458d 222 /*Initialize your touchpad*/
JohnnyK 0:10c4b83c458d 223 static void touchpad_init(void)
JohnnyK 0:10c4b83c458d 224 {
JohnnyK 0:10c4b83c458d 225 /*Your code comes here*/
JohnnyK 0:10c4b83c458d 226 BSP_TS_Init(BSP_LCD_GetXSize(),BSP_LCD_GetYSize());
JohnnyK 0:10c4b83c458d 227 }
JohnnyK 0:10c4b83c458d 228
JohnnyK 0:10c4b83c458d 229 /* Will be called by the library to read the touchpad */
JohnnyK 0:10c4b83c458d 230 static bool touchpad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
JohnnyK 0:10c4b83c458d 231 {
JohnnyK 0:10c4b83c458d 232 static lv_coord_t last_x = 0;
JohnnyK 0:10c4b83c458d 233 static lv_coord_t last_y = 0;
JohnnyK 0:10c4b83c458d 234
JohnnyK 0:10c4b83c458d 235 /*Save the pressed coordinates and the state*/
JohnnyK 0:10c4b83c458d 236 BSP_TS_GetState(&TS_State);
JohnnyK 0:10c4b83c458d 237 if(touchpad_is_pressed()) {
JohnnyK 0:10c4b83c458d 238 touchpad_get_xy(&last_x, &last_y);
JohnnyK 0:10c4b83c458d 239 data->state = LV_INDEV_STATE_PR;
JohnnyK 0:10c4b83c458d 240 } else {
JohnnyK 0:10c4b83c458d 241 data->state = LV_INDEV_STATE_REL;
JohnnyK 0:10c4b83c458d 242 }
JohnnyK 0:10c4b83c458d 243
JohnnyK 0:10c4b83c458d 244 /*Set the last pressed coordinates*/
JohnnyK 0:10c4b83c458d 245 data->point.x = last_x;
JohnnyK 0:10c4b83c458d 246 data->point.y = last_y;
JohnnyK 0:10c4b83c458d 247
JohnnyK 0:10c4b83c458d 248 /*Return `false` because we are not buffering and no more data to read*/
JohnnyK 0:10c4b83c458d 249 return false;
JohnnyK 0:10c4b83c458d 250 }
JohnnyK 0:10c4b83c458d 251
JohnnyK 0:10c4b83c458d 252 /*Return true is the touchpad is pressed*/
JohnnyK 0:10c4b83c458d 253 static bool touchpad_is_pressed(void)
JohnnyK 0:10c4b83c458d 254 {
JohnnyK 0:10c4b83c458d 255 /*Your code comes here*/
JohnnyK 0:10c4b83c458d 256 return TS_State.touchDetected;
JohnnyK 0:10c4b83c458d 257 }
JohnnyK 0:10c4b83c458d 258
JohnnyK 0:10c4b83c458d 259 /*Get the x and y coordinates if the touchpad is pressed*/
JohnnyK 0:10c4b83c458d 260 static void touchpad_get_xy(lv_coord_t * x, lv_coord_t * y)
JohnnyK 0:10c4b83c458d 261 {
JohnnyK 0:10c4b83c458d 262 /*Your code comes here*/
JohnnyK 0:10c4b83c458d 263 (*x) = TS_State.touchX[0];
JohnnyK 0:10c4b83c458d 264 (*y) = TS_State.touchY[0];
JohnnyK 0:10c4b83c458d 265 }
JohnnyK 0:10c4b83c458d 266
JohnnyK 0:10c4b83c458d 267 #endif
JohnnyK 0:10c4b83c458d 268 #if MOUSE == 1
JohnnyK 0:10c4b83c458d 269
JohnnyK 0:10c4b83c458d 270 /*------------------
JohnnyK 0:10c4b83c458d 271 * Mouse
JohnnyK 0:10c4b83c458d 272 * -----------------*/
JohnnyK 0:10c4b83c458d 273
JohnnyK 0:10c4b83c458d 274 /* Initialize your mouse */
JohnnyK 0:10c4b83c458d 275 static void mouse_init(void)
JohnnyK 0:10c4b83c458d 276 {
JohnnyK 0:10c4b83c458d 277 /*Your code comes here*/
JohnnyK 0:10c4b83c458d 278 }
JohnnyK 0:10c4b83c458d 279
JohnnyK 0:10c4b83c458d 280 /* Will be called by the library to read the mouse */
JohnnyK 0:10c4b83c458d 281 static bool mouse_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
JohnnyK 0:10c4b83c458d 282 {
JohnnyK 0:10c4b83c458d 283 /*Get the current x and y coordinates*/
JohnnyK 0:10c4b83c458d 284 mouse_get_xy(&data->point.x, &data->point.y);
JohnnyK 0:10c4b83c458d 285
JohnnyK 0:10c4b83c458d 286 /*Get whether the mouse button is pressed or released*/
JohnnyK 0:10c4b83c458d 287 if(mouse_is_pressed()) {
JohnnyK 0:10c4b83c458d 288 data->state = LV_INDEV_STATE_PR;
JohnnyK 0:10c4b83c458d 289 } else {
JohnnyK 0:10c4b83c458d 290 data->state = LV_INDEV_STATE_REL;
JohnnyK 0:10c4b83c458d 291 }
JohnnyK 0:10c4b83c458d 292
JohnnyK 0:10c4b83c458d 293 /*Return `false` because we are not buffering and no more data to read*/
JohnnyK 0:10c4b83c458d 294 return false;
JohnnyK 0:10c4b83c458d 295 }
JohnnyK 0:10c4b83c458d 296
JohnnyK 0:10c4b83c458d 297 /*Return true is the mouse button is pressed*/
JohnnyK 0:10c4b83c458d 298 static bool mouse_is_pressed(void)
JohnnyK 0:10c4b83c458d 299 {
JohnnyK 0:10c4b83c458d 300 /*Your code comes here*/
JohnnyK 0:10c4b83c458d 301
JohnnyK 0:10c4b83c458d 302 return false;
JohnnyK 0:10c4b83c458d 303 }
JohnnyK 0:10c4b83c458d 304
JohnnyK 0:10c4b83c458d 305 /*Get the x and y coordinates if the mouse is pressed*/
JohnnyK 0:10c4b83c458d 306 static void mouse_get_xy(lv_coord_t * x, lv_coord_t * y)
JohnnyK 0:10c4b83c458d 307 {
JohnnyK 0:10c4b83c458d 308 /*Your code comes here*/
JohnnyK 0:10c4b83c458d 309
JohnnyK 0:10c4b83c458d 310 (*x) = 0;
JohnnyK 0:10c4b83c458d 311 (*y) = 0;
JohnnyK 0:10c4b83c458d 312 }
JohnnyK 0:10c4b83c458d 313
JohnnyK 0:10c4b83c458d 314 #endif
JohnnyK 0:10c4b83c458d 315 #if KEYBOARD == 1
JohnnyK 0:10c4b83c458d 316
JohnnyK 0:10c4b83c458d 317 /*------------------
JohnnyK 0:10c4b83c458d 318 * Keypad
JohnnyK 0:10c4b83c458d 319 * -----------------*/
JohnnyK 0:10c4b83c458d 320
JohnnyK 0:10c4b83c458d 321 /* Initialize your keypad */
JohnnyK 0:10c4b83c458d 322 static void keypad_init(void)
JohnnyK 0:10c4b83c458d 323 {
JohnnyK 0:10c4b83c458d 324 /*Your code comes here*/
JohnnyK 0:10c4b83c458d 325 }
JohnnyK 0:10c4b83c458d 326
JohnnyK 0:10c4b83c458d 327 /* Will be called by the library to read the mouse */
JohnnyK 0:10c4b83c458d 328 static bool keypad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
JohnnyK 0:10c4b83c458d 329 {
JohnnyK 0:10c4b83c458d 330 static uint32_t last_key = 0;
JohnnyK 0:10c4b83c458d 331
JohnnyK 0:10c4b83c458d 332 /*Get the current x and y coordinates*/
JohnnyK 0:10c4b83c458d 333 mouse_get_xy(&data->point.x, &data->point.y);
JohnnyK 0:10c4b83c458d 334
JohnnyK 0:10c4b83c458d 335 /*Get whether the a key is pressed and save the pressed key*/
JohnnyK 0:10c4b83c458d 336 uint32_t act_key = keypad_get_key();
JohnnyK 0:10c4b83c458d 337 if(act_key != 0) {
JohnnyK 0:10c4b83c458d 338 data->state = LV_INDEV_STATE_PR;
JohnnyK 0:10c4b83c458d 339
JohnnyK 0:10c4b83c458d 340 /*Translate the keys to LittlevGL control characters according to your key definitions*/
JohnnyK 0:10c4b83c458d 341 switch(act_key) {
JohnnyK 0:10c4b83c458d 342 case 1:
JohnnyK 0:10c4b83c458d 343 act_key = LV_KEY_NEXT;
JohnnyK 0:10c4b83c458d 344 break;
JohnnyK 0:10c4b83c458d 345 case 2:
JohnnyK 0:10c4b83c458d 346 act_key = LV_KEY_PREV;
JohnnyK 0:10c4b83c458d 347 break;
JohnnyK 0:10c4b83c458d 348 case 3:
JohnnyK 0:10c4b83c458d 349 act_key = LV_KEY_LEFT;
JohnnyK 0:10c4b83c458d 350 break;
JohnnyK 0:10c4b83c458d 351 case 4:
JohnnyK 0:10c4b83c458d 352 act_key = LV_KEY_RIGHT;
JohnnyK 0:10c4b83c458d 353 break;
JohnnyK 0:10c4b83c458d 354 case 5:
JohnnyK 0:10c4b83c458d 355 act_key = LV_KEY_ENTER;
JohnnyK 0:10c4b83c458d 356 break;
JohnnyK 0:10c4b83c458d 357 }
JohnnyK 0:10c4b83c458d 358
JohnnyK 0:10c4b83c458d 359 last_key = act_key;
JohnnyK 0:10c4b83c458d 360 } else {
JohnnyK 0:10c4b83c458d 361 data->state = LV_INDEV_STATE_REL;
JohnnyK 0:10c4b83c458d 362 }
JohnnyK 0:10c4b83c458d 363
JohnnyK 0:10c4b83c458d 364 data->key = last_key;
JohnnyK 0:10c4b83c458d 365
JohnnyK 0:10c4b83c458d 366 /*Return `false` because we are not buffering and no more data to read*/
JohnnyK 0:10c4b83c458d 367 return false;
JohnnyK 0:10c4b83c458d 368 }
JohnnyK 0:10c4b83c458d 369
JohnnyK 0:10c4b83c458d 370 /*Get the currently being pressed key. 0 if no key is pressed*/
JohnnyK 0:10c4b83c458d 371 static uint32_t keypad_get_key(void)
JohnnyK 0:10c4b83c458d 372 {
JohnnyK 0:10c4b83c458d 373 /*Your code comes here*/
JohnnyK 0:10c4b83c458d 374
JohnnyK 0:10c4b83c458d 375 return 0;
JohnnyK 0:10c4b83c458d 376 }
JohnnyK 0:10c4b83c458d 377
JohnnyK 0:10c4b83c458d 378 #endif
JohnnyK 0:10c4b83c458d 379 #if ENCODER == 1
JohnnyK 0:10c4b83c458d 380
JohnnyK 0:10c4b83c458d 381 /*------------------
JohnnyK 0:10c4b83c458d 382 * Encoder
JohnnyK 0:10c4b83c458d 383 * -----------------*/
JohnnyK 0:10c4b83c458d 384
JohnnyK 0:10c4b83c458d 385 /* Initialize your keypad */
JohnnyK 0:10c4b83c458d 386 static void encoder_init(void)
JohnnyK 0:10c4b83c458d 387 {
JohnnyK 0:10c4b83c458d 388 /*Your code comes here*/
JohnnyK 0:10c4b83c458d 389 }
JohnnyK 0:10c4b83c458d 390
JohnnyK 0:10c4b83c458d 391 /* Will be called by the library to read the encoder */
JohnnyK 0:10c4b83c458d 392 static bool encoder_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
JohnnyK 0:10c4b83c458d 393 {
JohnnyK 0:10c4b83c458d 394
JohnnyK 0:10c4b83c458d 395 data->enc_diff = encoder_diff;
JohnnyK 0:10c4b83c458d 396 data->state = encoder_state;
JohnnyK 0:10c4b83c458d 397
JohnnyK 0:10c4b83c458d 398 /*Return `false` because we are not buffering and no more data to read*/
JohnnyK 0:10c4b83c458d 399 return false;
JohnnyK 0:10c4b83c458d 400 }
JohnnyK 0:10c4b83c458d 401
JohnnyK 0:10c4b83c458d 402 /*Call this function in an interrupt to process encoder events (turn, press)*/
JohnnyK 0:10c4b83c458d 403 static void encoder_handler(void)
JohnnyK 0:10c4b83c458d 404 {
JohnnyK 0:10c4b83c458d 405 /*Your code comes here*/
JohnnyK 0:10c4b83c458d 406
JohnnyK 0:10c4b83c458d 407 encoder_diff += 0;
JohnnyK 0:10c4b83c458d 408 encoder_state = LV_INDEV_STATE_REL;
JohnnyK 0:10c4b83c458d 409 }
JohnnyK 0:10c4b83c458d 410
JohnnyK 0:10c4b83c458d 411 #endif
JohnnyK 0:10c4b83c458d 412 #if BUTTON == 1
JohnnyK 0:10c4b83c458d 413
JohnnyK 0:10c4b83c458d 414 /*------------------
JohnnyK 0:10c4b83c458d 415 * Button
JohnnyK 0:10c4b83c458d 416 * -----------------*/
JohnnyK 0:10c4b83c458d 417
JohnnyK 0:10c4b83c458d 418 /* Initialize your buttons */
JohnnyK 0:10c4b83c458d 419 static void button_init(void)
JohnnyK 0:10c4b83c458d 420 {
JohnnyK 0:10c4b83c458d 421 /*Your code comes here*/
JohnnyK 0:10c4b83c458d 422 }
JohnnyK 0:10c4b83c458d 423
JohnnyK 0:10c4b83c458d 424 /* Will be called by the library to read the button */
JohnnyK 0:10c4b83c458d 425 static bool button_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
JohnnyK 0:10c4b83c458d 426 {
JohnnyK 0:10c4b83c458d 427
JohnnyK 0:10c4b83c458d 428 static uint8_t last_btn = 0;
JohnnyK 0:10c4b83c458d 429
JohnnyK 0:10c4b83c458d 430 /*Get the pressed button's ID*/
JohnnyK 0:10c4b83c458d 431 int8_t btn_act = button_get_pressed_id();
JohnnyK 0:10c4b83c458d 432
JohnnyK 0:10c4b83c458d 433 if(btn_act >= 0) {
JohnnyK 0:10c4b83c458d 434 data->state = LV_INDEV_STATE_PR;
JohnnyK 0:10c4b83c458d 435 last_btn = btn_act;
JohnnyK 0:10c4b83c458d 436 } else {
JohnnyK 0:10c4b83c458d 437 data->state = LV_INDEV_STATE_REL;
JohnnyK 0:10c4b83c458d 438 }
JohnnyK 0:10c4b83c458d 439
JohnnyK 0:10c4b83c458d 440 /*Save the last pressed button's ID*/
JohnnyK 0:10c4b83c458d 441 data->btn_id = last_btn;
JohnnyK 0:10c4b83c458d 442
JohnnyK 0:10c4b83c458d 443 /*Return `false` because we are not buffering and no more data to read*/
JohnnyK 0:10c4b83c458d 444 return false;
JohnnyK 0:10c4b83c458d 445 }
JohnnyK 0:10c4b83c458d 446
JohnnyK 0:10c4b83c458d 447 /*Get ID (0, 1, 2 ..) of the pressed button*/
JohnnyK 0:10c4b83c458d 448 static int8_t button_get_pressed_id(void)
JohnnyK 0:10c4b83c458d 449 {
JohnnyK 0:10c4b83c458d 450 uint8_t i;
JohnnyK 0:10c4b83c458d 451
JohnnyK 0:10c4b83c458d 452 /*Check to buttons see which is being pressed (assume there are 2 buttons)*/
JohnnyK 0:10c4b83c458d 453 for(i = 0; i < 2; i++) {
JohnnyK 0:10c4b83c458d 454 /*Return the pressed button's ID*/
JohnnyK 0:10c4b83c458d 455 if(button_is_pressed(i)) {
JohnnyK 0:10c4b83c458d 456 return i;
JohnnyK 0:10c4b83c458d 457 }
JohnnyK 0:10c4b83c458d 458 }
JohnnyK 0:10c4b83c458d 459
JohnnyK 0:10c4b83c458d 460 /*No button pressed*/
JohnnyK 0:10c4b83c458d 461 return -1;
JohnnyK 0:10c4b83c458d 462 }
JohnnyK 0:10c4b83c458d 463
JohnnyK 0:10c4b83c458d 464 /*Test if `id` button is pressed or not*/
JohnnyK 0:10c4b83c458d 465 static bool button_is_pressed(uint8_t id)
JohnnyK 0:10c4b83c458d 466 {
JohnnyK 0:10c4b83c458d 467
JohnnyK 0:10c4b83c458d 468 /*Your code comes here*/
JohnnyK 0:10c4b83c458d 469
JohnnyK 0:10c4b83c458d 470 return false;
JohnnyK 0:10c4b83c458d 471 }
JohnnyK 0:10c4b83c458d 472 #endif
JohnnyK 0:10c4b83c458d 473
JohnnyK 0:10c4b83c458d 474
JohnnyK 0:10c4b83c458d 475 #else /* Enable this file at the top */
JohnnyK 0:10c4b83c458d 476
JohnnyK 0:10c4b83c458d 477 /* This dummy typedef exists purely to silence -Wpedantic. */
JohnnyK 0:10c4b83c458d 478 typedef int keep_pedantic_happy;
JohnnyK 0:10c4b83c458d 479 #endif
JohnnyK 0:10c4b83c458d 480