Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stm32f10x.h>
- #include <stdio.h>
- #include <string.h>
- #include "DWLOS_config.h"
- #include "DWLOS.h"
- #define __zKeyPad
- #include "main.h"
- #include "z_KeyPad.h"
- #include "z_LSM.h"
- #include "z_S65.h"
- //==============================================================================
- // KeyPad manager
- //==============================================================================
- void KeyPad_Scan (void)
- {
- uint8_t b1, b2, b3, i;
- uint32_t tmp_reg_H, tmp_reg_L;
- // LOG_ADD('K');
- tmp_reg_L = GPIOB -> CRL;
- tmp_reg_H = GPIOB -> CRH;
- tmp_reg_L &= ~(GPIO_CRL_MODE0_1 | GPIO_CRL_MODE0_0 | GPIO_CRL_MODE1_1 | GPIO_CRL_MODE1_0);
- tmp_reg_H &= ~(GPIO_CRH_MODE10_1 | GPIO_CRH_MODE10_0);
- i = 0;
- i = BTN_BASE;
- b1 = 0;
- b2 = 0;
- b3 = 0;
- GPIOB -> CRL = tmp_reg_L;
- GPIOB -> CRH = tmp_reg_H;
- while (i < 255)
- {
- if (GPIOB -> IDR & GPIO_IDR_IDR0 && !b1) b1 = i;
- if (GPIOB -> IDR & GPIO_IDR_IDR1 && !b2) b2 = i;
- if (GPIOB -> IDR & GPIO_IDR_IDR10 && !b3) b3 = i;
- i ++;
- }
- if (!b1) b1 = 250;
- if (!b2) b2 = 250;
- if (!b3) b3 = 250;
- if (b1 > BTN1_CLICK_LEVEL) BTN1 ++;
- if (b2 > BTN2_CLICK_LEVEL) BTN2 ++;
- if (b3 > BTN3_CLICK_LEVEL) BTN3 ++;
- GPIOB -> CRL |= GPIO_CRL_MODE0_1 | GPIO_CRL_MODE0_0 | GPIO_CRL_MODE1_1 | GPIO_CRL_MODE1_0;
- GPIOB -> CRH |= GPIO_CRH_MODE10_1 | GPIO_CRH_MODE10_0;
- GPIOB -> BSRR |= GPIO_BSRR_BR0 | GPIO_BSRR_BR1 | GPIO_BSRR_BR10;
- Set_Timer (KeyPad_Scan, 80);
- }
- void KeyPad_Watcher (void)
- {
- uint8_t tmp = 0;
- static uint8_t uptime_view = 0;
- Set_Timer (KeyPad_Watcher, 170);
- LOG_ADD('W');
- if (BTN1 >= BTN_REAL_CLICK)
- tmp |= BTN1_ON;
- if (BTN2 >= BTN_REAL_CLICK)
- tmp |= BTN2_ON;
- if (BTN3 >= BTN_REAL_CLICK)
- tmp |= BTN3_ON;
- BTN1 = 0;
- BTN2 = 0;
- BTN3 = 0;
- if (tmp)
- {
- Key_live = Key_live << 3;
- Key_live = Key_live | ((uint64_t) tmp);
- if ((Key_live & 0x07) == BTN1_ON)
- {
- if (GPIOA -> ODR & GPIO_ODR_ODR15)
- {
- LED1_OFF;
- }
- else
- {
- LED1_ON;
- }
- }
- else if ((Key_live & 0x07) == BTN1_ON)
- {
- uptime_view = ~uptime_view;
- }
- else if ((Key_live & 0x07) == (BTN1_ON | BTN2_ON))
- {
- if (LSM_init_arr [17] & (3 << 4) == (1 << 4))
- {
- LSM_init_arr [17] = (1<<7)|(0<<4);
- }
- else
- {
- LSM_init_arr [17] = (1<<7)|(1<<4);
- }
- LSM_step = 0;
- Set_Task (LSM_init);
- }
- else if ((Key_live & 0x07) == BTN3_ON && (Key_live & (0x07 << 3)) != (BTN3_ON << 3))
- {
- LED1_ON;
- LED2_ON;
- Set_Timer (MAG_read, 1000);
- }
- else if ((Key_live & ((0x07) | ((0x07) << 3))) == ((BTN1_ON | BTN3_ON) | ((BTN1_ON | BTN3_ON) << 3)) && S65_IS_ON())
- {
- Set_Task (S65_off);
- }
- else if ((Key_live & ((0x07) | ((0x07) << 3))) == ((BTN1_ON | BTN2_ON) | ((BTN1_ON | BTN2_ON) << 3)))
- {
- LED1_OFF;
- LED2_OFF;
- LSM_TEST_OFF;
- }
- }
- switch (bsd_symbol_i)
- {
- case 0: S65 -> txt [0] = '|'; break;
- case 1: S65 -> txt [0] = '/'; break;
- case 2: S65 -> txt [0] = '-'; break;
- case 3: S65 -> txt [0] = '\\'; break;
- case 4: S65 -> txt [0] = '|'; break;
- case 5: S65 -> txt [0] = '/'; break;
- case 6: S65 -> txt [0] = '-'; break;
- case 7: S65 -> txt [0] = '\\'; break;
- default: S65 -> txt [0] = ' '; break;
- }
- bsd_symbol_i = (bsd_symbol_i == 7) ? 0 : (bsd_symbol_i + 1);
- S65 -> x = 62;
- S65 -> y = 110;
- S65 -> len = 1;
- S65_puts_n();
- if (uptime_view)
- {
- sprintf (S65 -> txt, "%2dh %2dm %2ds", uptime_h, uptime_m, uptime_s);
- S65 -> x = 1;
- S65 -> y = 176;
- S65 -> len = 11;
- S65_puts_n();
- }
- else
- {
- S65 -> txt [ 0] = ' ';
- S65 -> txt [ 1] = ' ';
- S65 -> txt [ 2] = ' ';
- S65 -> txt [ 3] = ' ';
- S65 -> txt [ 4] = ' ';
- S65 -> txt [ 5] = ' ';
- S65 -> txt [ 6] = ((tmp & (1 << 0)) ? 'x' : ' ');
- S65 -> txt [ 7] = ' ';
- S65 -> txt [ 8] = ((tmp & (1 << 1)) ? 'x' : ' ');
- S65 -> txt [ 9] = ' ';
- S65 -> txt [10] = ((tmp & (1 << 2)) ? 'x' : ' ');
- S65 -> txt [11] = ' ';
- S65 -> txt [12] = ' ';
- S65 -> txt [13] = ' ';
- S65 -> txt [14] = ' ';
- S65 -> txt [15] = ' ';
- S65 -> txt [16] = ' ';
- S65 -> x = 1;
- S65 -> y = 176;
- S65 -> len = 17;
- S65_puts_n();
- }
- /* S65 -> txt [0] = 'w';
- S65 -> txt [1] = (LSM_TEST_IS_OFF()) ? '0' : '1';
- S65 -> x = 3;
- S65 -> y = 15;
- S65 -> len = 6;
- // Set_Task (S65_puts_n);
- // S65_puts_n();
- // S65_puts_n (3, 155, S65_txt, 3);// */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement