├── .github └── FUNDING.yml ├── KeyPad.c ├── KeyPad.h ├── KeyPadConfig.h ├── LICENSE.TXT └── README.md /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: [nimaltd] 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: nimaltd 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: #nimaltd 10 | issuehunt: #nimaltd 11 | otechie: # Replace with a single Otechie username 12 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 13 | -------------------------------------------------------------------------------- /KeyPad.c: -------------------------------------------------------------------------------- 1 | #include "KeyPad.h" 2 | #include "KeyPadConfig.h" 3 | #include "gpio.h" 4 | #if (_KEYPAD_USE_FREERTOS==1) 5 | #include "cmsis_os.h" 6 | #define _KEYPAD_DELAY(x) osDelay(x) 7 | #else 8 | #define _KEYPAD_DELAY(x) HAL_Delay(x) 9 | #endif 10 | 11 | KeyPad_t KeyPad; 12 | 13 | //############################################################################################# 14 | void KeyPad_Init(void) 15 | { 16 | GPIO_InitTypeDef gpio; 17 | KeyPad.ColumnSize = sizeof(_KEYPAD_COLUMN_GPIO_PIN) / 2; 18 | KeyPad.RowSize = sizeof(_KEYPAD_ROW_GPIO_PIN) / 2; 19 | for(uint8_t i=0 ; i 5 | #include 6 | 7 | 8 | /* 9 | Author: Nima Askari 10 | WebSite: http://www.github.com/NimaLTD 11 | Instagram: http://instagram.com/github.NimaLTD 12 | Youtube: https://www.youtube.com/channel/UCUhY7qY1klJm1d2kulr9ckw 13 | 14 | Version: 1.0.0 15 | 16 | 17 | Reversion History: 18 | 19 | (1.0.0) 20 | First Release. 21 | */ 22 | 23 | typedef struct 24 | { 25 | uint8_t ColumnSize; 26 | uint8_t RowSize; 27 | uint16_t LastKey; 28 | 29 | }KeyPad_t; 30 | 31 | void KeyPad_Init(void); 32 | uint16_t KeyPad_WaitForKey(uint32_t Timeout_ms); 33 | char KeyPad_WaitForKeyGetChar(uint32_t Timeout_ms); 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /KeyPadConfig.h: -------------------------------------------------------------------------------- 1 | #ifndef _KEYPADCONFIG_H 2 | #define _KEYPADCONFIG_H 3 | #include "gpio.h" 4 | 5 | #define _KEYPAD_DEBOUNCE_TIME_MS 20 6 | #define _KEYPAD_USE_FREERTOS 0 7 | 8 | const GPIO_TypeDef* _KEYPAD_COLUMN_GPIO_PORT[] = 9 | { 10 | GPIOD, 11 | GPIOG, 12 | GPIOG, 13 | GPIOG 14 | }; 15 | 16 | const uint16_t _KEYPAD_COLUMN_GPIO_PIN[] = 17 | { 18 | GPIO_PIN_6, 19 | GPIO_PIN_9, 20 | GPIO_PIN_11, 21 | GPIO_PIN_13 22 | }; 23 | 24 | const GPIO_TypeDef* _KEYPAD_ROW_GPIO_PORT[] = 25 | { 26 | GPIOG, 27 | GPIOB, 28 | GPIOB, 29 | GPIOB 30 | }; 31 | 32 | const uint16_t _KEYPAD_ROW_GPIO_PIN[] = 33 | { 34 | GPIO_PIN_15, 35 | GPIO_PIN_4, 36 | GPIO_PIN_6, 37 | GPIO_PIN_8 38 | }; 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /LICENSE.TXT: -------------------------------------------------------------------------------- 1 | Software License Terms 2 | 3 | This software is dual-licensed: 4 | 5 | 1. GNU General Public License v2 (GPLv2): 6 | - You may redistribute and/or modify this software under the terms of GPLv2 as published by the Free Software Foundation. 7 | - This license does not provide any warranty of any kind, including but not limited to MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 8 | - See for details. 9 | 10 | 2. Commercial License: 11 | - The commercial license removes all GPLv2 restrictions and allows you to redistribute your closed-source products with the Library embedded. 12 | - This license includes access to software maintenance, such as updates and upgrades. Customers who purchase this license are eligible to receive updates whenever 13 | they are released. However, the software provider is not obligated to release updates on a specific schedule. 14 | - The commercial license is available in two models: 15 | - Single-Product License: Allows usage in one specific product. 16 | - Company-Wide License: Allows usage across all products of the company. 17 | - No Warranty: The software is provided "AS IS" without any warranties, express or implied, including but not limited to the implied warranties of MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, or NON-INFRINGEMENT. 18 | - Liability Disclaimer: In no event shall the copyright holder or contributors be liable for any claim, damages, or other liability, whether in an action of contract, tort, or otherwise, arising from, out of, or in connection with the software or the use or other dealings in the software. 19 | 20 | By using this software under the commercial license, you agree to these terms and acknowledge that no additional guarantees or obligations are provided beyond what is explicitly stated in this document. 21 | 22 | --- 23 | 24 | Copyright © Nima Askari, 2025. All rights reserved. 25 | For inquiries, contact: nima.askari@gmail.com All rights reserved 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Matrix Keypad library 2 | [![ko-fi](https://www.ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/O5O4221XY) 3 | * http://www.github.com/NimaLTD 4 | * https://www.instagram.com/github.nimaltd/ 5 | * https://www.youtube.com/channel/UCUhY7qY1klJm1d2kulr9ckw 6 | 7 | I hope use it and enjoy. 8 |
9 | I use Stm32f103vc and Keil Compiler and Stm32CubeMX wizard. 10 |
11 | Please Do This ... 12 | 1) Select "General peripheral Initalizion as a pair of '.c/.h' file per peripheral" on project settings. 13 | 2) Select your Column Pins as pushpull output and Row Pins as pullup input. 14 | 3) Config your KeyPadConfig.h. 15 | 4) Call KeyPad_Init() function after sturtup. 16 | 5) You can use read keyPad with KeyPad_WaitForKey(timeout) function. 17 | 6) if Timeout==0, Wait forever to pressed a key. 18 | 7) Returned value : 0x0101,0x0201,0x0401,0x0102 and ... .High Byte is Row value,Low Byte is Column Value. 19 | --------------------------------------------------------------------------------