1 /* 2 * Copyright (c) 2022 Shenzhen Kaihong Digital Industry Development Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include "events/key_event.h" 17 #include "gfx_utils/graphic_log.h" 18 #include "key_input_gd32f450.h" 19 #include "key_input.h" 20 21 namespace OHOS { 22 namespace { 23 static uint16_t g_lastKeyId = 0; 24 } // namespace 25 KeyInput()26 KeyInput::KeyInput() 27 { 28 Gd32f450KeyInputInit(); 29 } 30 GetInstance()31 KeyInput *KeyInput::GetInstance() 32 { 33 static KeyInput keyInput; 34 return &keyInput; 35 } 36 Read(DeviceData & data)37 bool KeyInput::Read(DeviceData &data) 38 { 39 data.keyId = g_lastKeyId; 40 data.state = (uint16_t)Gd32f450SingleKeyInputRead((KEY_TYPE)g_lastKeyId); 41 42 if (g_lastKeyId < MAX_KEY_NUM - 1) { 43 g_lastKeyId++; 44 return true; 45 } else { 46 g_lastKeyId = 0; 47 return false; 48 } 49 50 return false; 51 } 52 } // namespace OHOS 53