Library used during 1 day workshops presented by Skool and ARM Hungary in 2015.

Fork of Skool_wkshp_lib2015 by Laszlo Vagasi

Files at this revision

API Documentation at this revision

Comitter:
lvagasi
Date:
Thu Oct 01 19:17:25 2015 +0000
Parent:
0:3ad0af8abf43
Commit message:
Almost complete version. Functionally working. Sometimes some keys are repeated. There is no value check.

Changed in this revision

keypad.cpp Show annotated file Show diff for this revision Revisions of this file
menu.cpp Show annotated file Show diff for this revision Revisions of this file
rtc.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/keypad.cpp	Fri Sep 25 13:48:39 2015 +0000
+++ b/keypad.cpp	Thu Oct 01 19:17:25 2015 +0000
@@ -98,13 +98,15 @@
         HAL_GPIO_WritePin(GPIOC, cols[0] | cols[1] | cols[2], GPIO_PIN_SET);
         HAL_GPIO_WritePin(GPIOC, cols[1], GPIO_PIN_RESET);
         wait_ms(25);
-        temp = (GPIOC->IDR & 0x0160);
+        temp = (GPIOC->IDR & 0x0360);
         switch (temp) {
-            case 0x0140: retval = 0x01;
+            case 0x0340: retval = 0x01;
                          break;
-            case 0x0120: retval = 0x05;
+            case 0x0320: retval = 0x05;
                          break;
-            case 0x0060: retval = 0x09;
+            case 0x0260: retval = 0x09;
+                         break;
+            case 0x0160: retval = 0x0D;
                          break;
             default:     retval = 0xFF;
                          break;
@@ -112,7 +114,8 @@
         HAL_GPIO_WritePin(GPIOC, cols[0] | cols[1] | cols[2], GPIO_PIN_SET);
         HAL_GPIO_WritePin(GPIOC, cols[2], GPIO_PIN_RESET);
         wait_ms(25);
-        if ((GPIOC->IDR & 0x0200) == 0x0000) retval = 0x0E;
+        temp = (GPIOC->IDR & 0x0360);
+        if (temp == 0x0160) {retval = 0x0E;}
     }
     // Wait for the release of the key
     HAL_GPIO_WritePin(GPIOC, cols[0] | cols[1] | cols[2], GPIO_PIN_SET);
--- a/menu.cpp	Fri Sep 25 13:48:39 2015 +0000
+++ b/menu.cpp	Thu Oct 01 19:17:25 2015 +0000
@@ -53,7 +53,7 @@
 
     MainMenu_CurrentItem = 0;
     ShowMainMenuItem(MainMenu_CurrentItem);
-    while ((isexit == 0) | (Main_FSM_States != FINISH)) {
+    while ((isexit == 0) & (Main_FSM_States != FINISH)) {
         keypress = Poll_keypad_vert();
         switch (keypress) {
             case 0x01:  MainMenu_CurrentItem = ((MainMenu_CurrentItem == 0) ? 0 : MainMenu_CurrentItem - 1);
@@ -66,6 +66,7 @@
                         ShowMainMenuItem(MainMenu_CurrentItem);
                         break;
             case 0x0E:  isexit = 1;
+                        Main_FSM_States = FINISH;
                         break;
             default:    break;
         }
--- a/rtc.cpp	Fri Sep 25 13:48:39 2015 +0000
+++ b/rtc.cpp	Thu Oct 01 19:17:25 2015 +0000
@@ -17,7 +17,7 @@
 extern FSM_State Main_FSM_States;
 
 const char BCD2HEX[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
-const char DOW[7][3] = { {'H',' ',' '}, {'K',' ',' '}, {'S','z','e'}, {'C','s',' '}, {'P',' ',' '}, {'S','z','o'}, {'V',' ',' '} };
+const char DOW[8][3] = { {' ',' ',' '}, {'H',' ',' '}, {'K',' ',' '}, {'S','z','e'}, {'C','s',' '}, {'P',' ',' '}, {'S','z','o'}, {'V',' ',' '} };
 const char Yes_No[16] = {'*',':','O','K',' ',' ',' ',' ',' ','#',':','M',0x82,'g','s','e'};//"*:OK     #:Mégse"};
 
 void RTC_AlarmAEventCallback(void) {
@@ -61,9 +61,9 @@
     tt[6] = BCD2HEX[((rtc_alarm.AlarmTime.Seconds & 0xF0) >> 4)];
     tt[7] = BCD2HEX[(rtc_alarm.AlarmTime.Seconds & 0x0F)];
     tt[8] = ' ';
-    tt[9] = DOW[rtc_alarm.AlarmDateWeekDay - 1][0];
-    tt[10] = DOW[rtc_alarm.AlarmDateWeekDay - 1][1];
-    tt[11] = DOW[rtc_alarm.AlarmDateWeekDay - 1][2];
+    tt[9] = DOW[rtc_alarm.AlarmDateWeekDay][0];
+    tt[10] = DOW[rtc_alarm.AlarmDateWeekDay][1];
+    tt[11] = DOW[rtc_alarm.AlarmDateWeekDay][2];
     write_ser_text(tt, 12);
     write_ser_lcd(0xC0, false);
     wait_us(30);
@@ -109,9 +109,9 @@
     tt[10] = '.';
     tmp_date = rtc_date.Date;
     tt[11] = ' ';
-    tt[12] = DOW[rtc_date.WeekDay - 1][0];
-    tt[13] = DOW[rtc_date.WeekDay - 1][1];
-    tt[14] = DOW[rtc_date.WeekDay - 1][2];
+    tt[12] = DOW[rtc_date.WeekDay][0];
+    tt[13] = DOW[rtc_date.WeekDay][1];
+    tt[14] = DOW[rtc_date.WeekDay][2];
     write_ser_text(tt,15);
 }
 
@@ -152,9 +152,9 @@
     tt[6] = BCD2HEX[((rtc_alarm.AlarmTime.Seconds & 0xF0) >> 4)];
     tt[7] = BCD2HEX[(rtc_alarm.AlarmTime.Seconds & 0x0F)];
     tt[8] = ' ';
-    tt[9] = DOW[rtc_date.WeekDay - 1][0];
-    tt[10] = DOW[rtc_date.WeekDay - 1][1];
-    tt[11] = DOW[rtc_date.WeekDay - 1][2];
+    tt[9] = DOW[rtc_date.WeekDay][0];
+    tt[10] = DOW[rtc_date.WeekDay][1];
+    tt[11] = DOW[rtc_date.WeekDay][2];
     write_ser_text(tt, 8);
     write_ser_lcd(0x80, false);     // set DDRAM addr to 0x00, beginning of 1st line
 }
@@ -179,9 +179,9 @@
     tt[9] = BCD2HEX[(rtc_date.Date & 0x0F)];
     tt[10] = '.';
     tt[11] = ' ';
-    tt[12] = DOW[rtc_date.WeekDay - 1][0];
-    tt[13] = DOW[rtc_date.WeekDay - 1][1];
-    tt[14] = DOW[rtc_date.WeekDay - 1][2];
+    tt[12] = DOW[rtc_date.WeekDay][0];
+    tt[13] = DOW[rtc_date.WeekDay][1];
+    tt[14] = DOW[rtc_date.WeekDay][2];
     write_ser_text(tt,15);
     write_ser_lcd(0x82, false);     // set DDRAM addr to 0x00, beginning of 1st line
 }
@@ -237,7 +237,7 @@
     int keypress;
     
     HAL_RTC_GetAlarm(&rtch, &rtc_alarm, RTC_ALARM_A, FORMAT_BCD);
-    if (rtc_alarm.AlarmDateWeekDay == 0) { rtc_alarm.AlarmDateWeekDay = 1;}     // There was no alarm set yet
+    //if (rtc_alarm.AlarmDateWeekDay == 0) { rtc_alarm.AlarmDateWeekDay = 1;}     // There was no alarm set yet
     ShowAlarm();
     keypress = Poll_keypad_yesno();
     if (keypress == 0x0C) {
@@ -347,7 +347,11 @@
     rtc_alarm.AlarmTime.Minutes = ((TT[3] - 0x30) << 4) + (TT[4] - 0x30);
     rtc_alarm.AlarmTime.Seconds = ((TT[6] - 0x30) << 4) + (TT[7] - 0x30);
     rtc_alarm.AlarmDateWeekDay = DoW;
-    rtc_alarm.AlarmMask = RTC_ALARMMASK_NONE;               // Alarm is triggered when everything match
+    if (DoW == 0x00) {
+        rtc_alarm.AlarmMask = RTC_ALARMMASK_DATEWEEKDAY;        // Alarm is triggered every day, no date or weekday match
+    } else {
+        rtc_alarm.AlarmMask = RTC_ALARMMASK_NONE;               // Alarm is triggered when everything match
+    }
     HAL_RTC_DeactivateAlarm(&rtch, RTC_ALARM_A);
     HAL_RTC_SetAlarm_IT(&rtch, &rtc_alarm, FORMAT_BCD);
     NVIC_SetVector(RTC_Alarm_IRQn, (uint32_t)RTC_AlarmIRQHandler);
@@ -397,7 +401,7 @@
         }
         write_ser_lcd(0x80, false);
         wait_us(30);
-        write_ser_text(TT,8);
+        write_ser_text(TT,15);
         write_ser_lcd(0x80 + index, false);
     }
     rtc_date.Year = ((TT[2] - 0x30) << 4) + (TT[3] - 0x30);