Boilerplate library to get started with LvGL on STM DISCO F746NG board. Adapted from https://os.mbed.com/users/JohnnyK/code/DISCO-F746NG_MbedOs_LvGL_example/

Dependencies:   BSP_DISCO_F746NG

Dependents:   LvGL_F746NG_test

Committer:
elelthvd
Date:
Thu Sep 10 09:24:23 2020 +0000
Revision:
1:a23fffad1321
Parent:
0:cffa136e7f8f
Add usage for Mbed Thread

Who changed what in which revision?

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